From 9f9614f2109fc7dce916a797f74ddec7237801a6 Mon Sep 17 00:00:00 2001 From: Khavin Shankar Date: Sun, 23 Apr 2023 21:58:52 +0530 Subject: [PATCH] Unassign consultation beds while shifting is completed (#1266) unassign consultation beds while shifting is completed --- care/facility/api/viewsets/shifting.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/care/facility/api/viewsets/shifting.py b/care/facility/api/viewsets/shifting.py index a1b14fdabc..cd4cdd8113 100644 --- a/care/facility/api/viewsets/shifting.py +++ b/care/facility/api/viewsets/shifting.py @@ -22,6 +22,7 @@ BREATHLESSNESS_CHOICES, SHIFTING_STATUS_CHOICES, PatientConsultation, + ConsultationBed, ShiftingRequest, ShiftingRequestComment, User, @@ -136,8 +137,12 @@ def transfer(self, request, *args, **kwargs): shifting_obj.save(update_fields=["status"]) # Discharge from all other active consultations PatientConsultation.objects.filter(patient=patient, discharge_date__isnull=True).update( - discharge_date=localtime(now()) + discharge_date=localtime(now()), discharge_reason="REF" ) + ConsultationBed.objects.filter( + consultation=patient.last_consultation, end_date__isnull=True + ).update(end_date=localtime(now())) + return Response({"transfer": "completed"}, status=status.HTTP_200_OK) return Response({"error": "Invalid Request"}, status=status.HTTP_400_BAD_REQUEST)