Skip to content

Commit

Permalink
fix(daily_rounds): added validations to serializer fields
Browse files Browse the repository at this point in the history
  • Loading branch information
aeswibon committed Feb 19, 2024
1 parent 63ff210 commit 30b4b84
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions care/facility/api/serializers/daily_round.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ class DailyRoundSerializer(serializers.ModelSerializer):
deprecated_covid_category = ChoiceField(
choices=COVID_CATEGORY_CHOICES, required=False
) # Deprecated
patient_category = ChoiceField(choices=CATEGORY_CHOICES, required=False)
patient_category = ChoiceField(choices=CATEGORY_CHOICES, required=True)
current_health = ChoiceField(choices=CURRENT_HEALTH_CHOICES, required=False)

action = ChoiceField(
choices=PatientRegistration.ActionChoices, write_only=True, required=False
choices=PatientRegistration.ActionChoices,
write_only=True,
required=False,
)
temperature = serializers.DecimalField(
max_digits=5, decimal_places=2, required=True
)
review_interval = serializers.IntegerField(
source="consultation__review_interval", required=False
Expand Down Expand Up @@ -283,7 +288,10 @@ def create(self, validated_data):
"last_updated_by_telemedicine"
]
daily_round_obj.consultation.save(
update_fields=["last_updated_by_telemedicine", "review_interval"]
update_fields=[
"last_updated_by_telemedicine",
"review_interval",
]
)
daily_round_obj.save(
update_fields=[
Expand Down Expand Up @@ -331,6 +339,12 @@ def validate(self, attrs):
}
)

if "temperature" in validated:
if validated["temperature"] < 95 or validated["temperature"] > 106:
raise ValidationError(
{"temperature": ["This field value must be between 95 and 106."]}
)

if "bed" in validated:
external_id = validated.pop("bed")["external_id"]
if external_id:
Expand Down

0 comments on commit 30b4b84

Please sign in to comment.