Skip to content

Commit

Permalink
Merge branch 'master' into issue#5345
Browse files Browse the repository at this point in the history
  • Loading branch information
aeswibon authored Aug 21, 2023
2 parents 7ffff98 + 4767a27 commit 6a60b34
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions care/facility/api/serializers/bed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -224,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:
Expand Down Expand Up @@ -262,8 +267,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)
Expand Down

0 comments on commit 6a60b34

Please sign in to comment.