Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Incorrect Discharge Reasons in Patient Transfers and Readmissions #1712

Merged
merged 8 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions care/facility/api/serializers/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
PatientNotes,
PatientRegistration,
)
from care.facility.models.bed import ConsultationBed
from care.facility.models.notification import Notification
from care.facility.models.patient_base import (
BLOOD_GROUP_CHOICES,
Expand Down Expand Up @@ -453,9 +454,18 @@

def save(self, **kwargs):
self.instance.facility = self.validated_data["facility"]
PatientConsultation.objects.filter(
consultation = PatientConsultation.objects.filter(

Check warning on line 457 in care/facility/api/serializers/patient.py

View check run for this annotation

Codecov / codecov/patch

care/facility/api/serializers/patient.py#L457

Added line #L457 was not covered by tests
Ashesh3 marked this conversation as resolved.
Show resolved Hide resolved
patient=self.instance, discharge_date__isnull=True
).update(discharge_date=localtime(now()))
).first()

Ashesh3 marked this conversation as resolved.
Show resolved Hide resolved
consultation.discharge_date = localtime(now())
Ashesh3 marked this conversation as resolved.
Show resolved Hide resolved
consultation.discharge_reason = "REF"
consultation.current_bed = None
consultation.save()

Check warning on line 464 in care/facility/api/serializers/patient.py

View check run for this annotation

Codecov / codecov/patch

care/facility/api/serializers/patient.py#L461-L464

Added lines #L461 - L464 were not covered by tests

ConsultationBed.objects.filter(

Check warning on line 466 in care/facility/api/serializers/patient.py

View check run for this annotation

Codecov / codecov/patch

care/facility/api/serializers/patient.py#L466

Added line #L466 was not covered by tests
consultation=consultation, end_date__isnull=True
).update(end_date=now())
self.instance.save()


Expand Down
13 changes: 12 additions & 1 deletion care/facility/api/viewsets/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,21 @@
@action(detail=True, methods=["POST"])
def transfer(self, request, *args, **kwargs):
patient = PatientRegistration.objects.get(external_id=kwargs["external_id"])
vigneshhari marked this conversation as resolved.
Show resolved Hide resolved
facility = Facility.objects.get(external_id=request.data["facility"])

Check warning on line 429 in care/facility/api/viewsets/patient.py

View check run for this annotation

Codecov / codecov/patch

care/facility/api/viewsets/patient.py#L429

Added line #L429 was not covered by tests

if patient.is_active and facility == patient.facility:
return Response(

Check warning on line 432 in care/facility/api/viewsets/patient.py

View check run for this annotation

Codecov / codecov/patch

care/facility/api/viewsets/patient.py#L432

Added line #L432 was not covered by tests
{
"Patient": "Patient transfer cannot be completed because the patient has an active consultation in the same facility"
},
status=status.HTTP_406_NOT_ACCEPTABLE,
)

if patient.allow_transfer is False:
return Response(
{"Patient": "Cannot Transfer Patient , Source Facility Does Not Allow"},
{
"Patient": "Patient transfer cannot be completed because the source facility does not permit it"
},
status=status.HTTP_406_NOT_ACCEPTABLE,
)
patient.allow_transfer = False
Expand Down
28 changes: 28 additions & 0 deletions care/facility/migrations/0394_auto_20231114_2219.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.2.6 on 2023-11-14 16:49

from django.db import migrations


def free_discharged_beds(apps, schema_editor):
PatientConsultation = apps.get_model("facility", "PatientConsultation")
ConsultationBed = apps.get_model("facility", "ConsultationBed")

for consultation in PatientConsultation.objects.filter(
discharge_date__isnull=False
):
ConsultationBed.objects.filter(
consultation=consultation, end_date__isnull=True
).update(end_date=consultation.discharge_date)


class Migration(migrations.Migration):
dependencies = [
(
"facility",
"0393_rename_diagnosis_patientconsultation_deprecated_diagnosis_and_more",
),
]

operations = [
migrations.RunPython(free_discharged_beds),
Ashesh3 marked this conversation as resolved.
Show resolved Hide resolved
]
Loading