From e5ba88070d03b2393e01d6d79d0e5a756eada7b8 Mon Sep 17 00:00:00 2001 From: Ashesh <3626859+Ashesh3@users.noreply.github.com> Date: Sat, 13 Jan 2024 10:01:39 +0530 Subject: [PATCH] Fix patient discharge_reason filter and add it to export (#1820) --- care/facility/api/serializers/patient.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/care/facility/api/serializers/patient.py b/care/facility/api/serializers/patient.py index 58f1cd7e55..ac70f90052 100644 --- a/care/facility/api/serializers/patient.py +++ b/care/facility/api/serializers/patient.py @@ -453,12 +453,12 @@ def validate_date_of_birth(self, value): def create(self, validated_data): raise NotImplementedError - def save(self, **kwargs): - self.instance.facility = self.validated_data["facility"] + def update(self, instance, validated_data): + instance.facility = validated_data["facility"] with transaction.atomic(): consultation = PatientConsultation.objects.filter( - patient=self.instance, discharge_date__isnull=True + patient=instance, discharge_date__isnull=True ).first() if consultation: @@ -470,7 +470,9 @@ def save(self, **kwargs): ConsultationBed.objects.filter( consultation=consultation, end_date__isnull=True ).update(end_date=now()) - self.instance.save() + + instance.save() + return instance class PatientNotesSerializer(serializers.ModelSerializer):