From b0eb29e0399957ef80f9d90cb361a83a752f3eb2 Mon Sep 17 00:00:00 2001 From: Prafful Date: Sat, 28 Dec 2024 22:53:17 +0530 Subject: [PATCH] updates for assetbed boundary --- care/facility/api/serializers/asset.py | 3 ++- care/facility/api/serializers/bed.py | 2 +- care/utils/assetintegration/base.py | 10 ++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/care/facility/api/serializers/asset.py b/care/facility/api/serializers/asset.py index a4007607fe..a2cea274cb 100644 --- a/care/facility/api/serializers/asset.py +++ b/care/facility/api/serializers/asset.py @@ -425,9 +425,10 @@ class AssetActionSerializer(Serializer): required=True, ) data = JSONField(required=False) + options = JSONField(required=False) class Meta: - fields = ("type", "data") + fields = ("type", "data", "options") class DummyAssetOperateSerializer(Serializer): diff --git a/care/facility/api/serializers/bed.py b/care/facility/api/serializers/bed.py index 6ffc8808e8..7a332078f1 100644 --- a/care/facility/api/serializers/bed.py +++ b/care/facility/api/serializers/bed.py @@ -125,7 +125,7 @@ def validate(self, attrs): valid_asset_classes = [ member.name for member in AssetClasses.all() - if member.value.can_be_linked_to_asset_bed() + if member.name == "HL7MONITOR" ] if asset.asset_class not in valid_asset_classes: raise ValidationError( diff --git a/care/utils/assetintegration/base.py b/care/utils/assetintegration/base.py index a7d23d3fa3..c1fb61a184 100644 --- a/care/utils/assetintegration/base.py +++ b/care/utils/assetintegration/base.py @@ -54,16 +54,18 @@ def get_headers(self): def _validate_response(self, response: requests.Response): try: - if response.status_code >= status.HTTP_400_BAD_REQUEST: - raise APIException(response.text, response.status_code) + if response.status_code == status.HTTP_400_BAD_REQUEST: + raise ValidationError(response.text) + if response.status_code > status.HTTP_400_BAD_REQUEST: + raise APIException(response.text, str(response.status_code)) return response.json() except requests.Timeout as e: - raise APIException({"error": "Request Timeout"}, 504) from e + raise APIException({"error": "Request Timeout"}, "504") from e except json.decoder.JSONDecodeError as e: raise APIException( - {"error": "Invalid Response"}, response.status_code + {"error": "Invalid Response"}, str(response.status_code) ) from e def api_post(self, url, data=None, timeout=None):