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)