diff --git a/care/facility/api/serializers/shifting.py b/care/facility/api/serializers/shifting.py index 5e648d8ea4..f3f72a24b0 100644 --- a/care/facility/api/serializers/shifting.py +++ b/care/facility/api/serializers/shifting.py @@ -12,7 +12,6 @@ ) from care.facility.models import ( BREATHLESSNESS_CHOICES, - CATEGORY_CHOICES, FACILITY_TYPES, SHIFTING_STATUS_CHOICES, VEHICLE_CHOICES, @@ -221,7 +220,6 @@ 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 ) @@ -333,6 +331,10 @@ def update(self, instance, validated_data): old_status = instance.status new_instance = super().update(instance, validated_data) + patient = new_instance.patient + patient.last_consultation.category = self.initial_data["patient_category"] + patient.last_consultation.save() + if ( "status" in validated_data and validated_data["status"] != old_status @@ -393,6 +395,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() + validated_data["orgin_facility"] = patient.facility validated_data["created_by"] = self.context["request"].user diff --git a/care/facility/migrations/0352_auto_20230428_1539.py b/care/facility/migrations/0352_auto_20230428_1539.py new file mode 100644 index 0000000000..3a91dae64e --- /dev/null +++ b/care/facility/migrations/0352_auto_20230428_1539.py @@ -0,0 +1,14 @@ +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("facility", "0351_auto_20230424_1227"), + ] + + operations = [ + migrations.RemoveField( + model_name="shiftingrequest", + name="patient_category", + ), + ] diff --git a/care/facility/models/shifting.py b/care/facility/models/shifting.py index 385dd7d34c..f36406e3e3 100644 --- a/care/facility/models/shifting.py +++ b/care/facility/models/shifting.py @@ -7,7 +7,6 @@ pretty_boolean, reverse_choices, ) -from care.facility.models.patient_base import CATEGORY_CHOICES from care.users.models import User, phone_number_regex SHIFTING_STATUS_CHOICES = ( @@ -45,9 +44,10 @@ class ShiftingRequest(FacilityBaseModel): - orgin_facility = models.ForeignKey( - "Facility", on_delete=models.PROTECT, related_name="requesting_facility" + "Facility", + on_delete=models.PROTECT, + related_name="requesting_facility", ) shifting_approving_facility = models.ForeignKey( "Facility", @@ -96,9 +96,6 @@ class ShiftingRequest(FacilityBaseModel): null=True, related_name="shifting_assigned_to", ) - patient_category = models.CharField( - choices=CATEGORY_CHOICES, max_length=8, blank=False, null=True - ) ambulance_driver_name = models.TextField(default="", blank=True) ambulance_phone_number = models.CharField( max_length=14, validators=[phone_number_regex], default="", blank=True