From 60ade09f3d6906a5b06da4a414e466b69f5af6a4 Mon Sep 17 00:00:00 2001 From: Aakash Singh Date: Sat, 19 Aug 2023 13:34:31 +0530 Subject: [PATCH 1/2] fix: asset class check for restricting asset relations (#1527) --- care/facility/api/serializers/bed.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/care/facility/api/serializers/bed.py b/care/facility/api/serializers/bed.py index 8eaa245fc4..16c1cc75fd 100644 --- a/care/facility/api/serializers/bed.py +++ b/care/facility/api/serializers/bed.py @@ -103,7 +103,10 @@ def validate(self, attrs): not facilities.filter(id=asset.current_location.facility.id).exists() ) or (not facilities.filter(id=bed.facility.id).exists()): raise PermissionError() - if asset.asset_class not in [AssetClasses.HL7MONITOR, AssetClasses.ONVIF]: + if asset.asset_class not in [ + AssetClasses.HL7MONITOR.name, + AssetClasses.ONVIF.name, + ]: raise ValidationError({"asset": "Asset is not a monitor or camera"}) attrs["asset"] = asset attrs["bed"] = bed @@ -112,7 +115,7 @@ def validate(self, attrs): {"asset": "Should be in the same facility as the bed"} ) if ( - asset.asset_class in ["HL7MONITOR", "VENTILATOR"] + asset.asset_class == AssetClasses.HL7MONITOR.name and AssetBed.objects.filter( bed=bed, asset__asset_class=asset.asset_class ).exists() @@ -262,8 +265,8 @@ def create(self, validated_data): ) .exclude( asset_class__in=[ - AssetClasses.HL7MONITOR, - AssetClasses.ONVIF, + AssetClasses.HL7MONITOR.name, + AssetClasses.ONVIF.name, ] ) .values_list("external_id", flat=True) From 4767a27c5590badbf8654cfc28bceeaf95caa9fa Mon Sep 17 00:00:00 2001 From: Aakash Singh Date: Sat, 19 Aug 2023 14:01:11 +0530 Subject: [PATCH 2/2] fix bed allocation overlap (#1526) Signed-off-by: Aakash Singh --- care/facility/api/serializers/bed.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/care/facility/api/serializers/bed.py b/care/facility/api/serializers/bed.py index 16c1cc75fd..9a77bfac28 100644 --- a/care/facility/api/serializers/bed.py +++ b/care/facility/api/serializers/bed.py @@ -227,7 +227,9 @@ def validate(self, attrs): ) # Conflict checking logic - existing_qs = ConsultationBed.objects.filter(consultation=consultation) + existing_qs = ConsultationBed.objects.filter(bed=bed).exclude( + consultation=consultation + ) if existing_qs.filter(start_date__gt=start_date).exists(): raise ValidationError({"start_date": "Cannot create conflicting entry"}) if end_date: