Skip to content

Commit

Permalink
add patient_category ShiftingSerializer
Browse files Browse the repository at this point in the history
partial revert from #1280
  • Loading branch information
sainak committed Jul 19, 2023
1 parent 9f84bd4 commit 1728ab6
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions care/facility/api/serializers/shifting.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
)
from care.facility.models import (
BREATHLESSNESS_CHOICES,
CATEGORY_CHOICES,
FACILITY_TYPES,
SHIFTING_STATUS_CHOICES,
VEHICLE_CHOICES,
Expand Down Expand Up @@ -217,6 +218,7 @@ class ShiftingSerializer(serializers.ModelSerializer):
last_edited_by_object = UserBaseMinimumSerializer(
source="last_edited_by", read_only=True
)
patient_category = ChoiceField(choices=CATEGORY_CHOICES, required=False)
ambulance_driver_name = serializers.CharField(
required=False, allow_null=True, allow_blank=True
)
Expand Down Expand Up @@ -327,8 +329,10 @@ def update(self, instance, validated_data):
new_instance = super().update(instance, validated_data)

patient = new_instance.patient
patient.last_consultation.category = self.initial_data["patient_category"]
patient.last_consultation.save()
patient_category = self.validated_data.pop("patient_category")
if patient.last_consultation and patient_category is not None:
patient.last_consultation.category = patient_category
patient.last_consultation.save(update_fields=["category"])

if (
"status" in validated_data
Expand Down Expand Up @@ -390,9 +394,10 @@ def create(self, validated_data):
patient.allow_transfer = True
patient.save()

if patient.last_consultation:
patient.last_consultation.category = self.initial_data["patient_category"]
patient.last_consultation.save()
patient_category = self.validated_data.pop("patient_category")
if patient.last_consultation and patient_category is not None:
patient.last_consultation.category = patient_category
patient.last_consultation.save(update_fields=["category"])

validated_data["origin_facility"] = patient.facility

Expand Down

0 comments on commit 1728ab6

Please sign in to comment.