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

Block expired patients from being transfered #2293

Merged
merged 6 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions care/facility/api/serializers/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ class Meta:
"facility",
"allow_transfer",
"is_active",
"is_expired",
)


Expand Down
8 changes: 8 additions & 0 deletions care/facility/api/viewsets/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,14 @@
patient = PatientRegistration.objects.get(external_id=kwargs["external_id"])
facility = Facility.objects.get(external_id=request.data["facility"])

if patient.is_expired:
return Response(

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L569 was not covered by tests
{
"Patient": "Patient transfer cannot be completed because the patient is expired"
},
status=status.HTTP_406_NOT_ACCEPTABLE,
)

if patient.is_active and facility == patient.facility:
return Response(
{
Expand Down
9 changes: 9 additions & 0 deletions care/facility/models/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
REVERSE_CATEGORY_CHOICES,
REVERSE_NEW_DISCHARGE_REASON_CHOICES,
REVERSE_ROUTE_TO_FACILITY_CHOICES,
NewDischargeReasonEnum,
)
from care.facility.models.patient_consultation import PatientConsultation
from care.facility.static_data.icd11 import get_icd11_diagnoses_objects_by_ids
Expand Down Expand Up @@ -436,6 +437,14 @@ class TestTypeEnum(enum.Enum):

objects = BaseManager()

@property
def is_expired(self) -> bool:
return (
self.last_consultation.new_discharge_reason
== NewDischargeReasonEnum.EXPIRED.value
or self.last_consultation.discharge_reason == "EXP"
)
khavinshankar marked this conversation as resolved.
Show resolved Hide resolved

def __str__(self):
return f"{self.name} - {self.year_of_birth} - {self.get_gender_display()}"

Expand Down