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

Add Medico-Legal Case Toggle and Filter #1669

Merged
merged 3 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 10 additions & 3 deletions care/facility/api/serializers/patient_consultation.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@
read_only=True
)

medico_legal_case = serializers.BooleanField(default=False, required=False)

def get_discharge_prescription(self, consultation):
return Prescription.objects.filter(
consultation=consultation,
Expand Down Expand Up @@ -153,9 +155,14 @@
instance.last_edited_by = self.context["request"].user

if instance.discharge_date:
raise ValidationError(
{"consultation": ["Discharged Consultation data cannot be updated"]}
)
if "medico_legal_case" not in validated_data:
raise ValidationError(

Check warning on line 159 in care/facility/api/serializers/patient_consultation.py

View check run for this annotation

Codecov / codecov/patch

care/facility/api/serializers/patient_consultation.py#L159

Added line #L159 was not covered by tests
{"consultation": ["Discharged Consultation data cannot be updated"]}
)
else:
instance.medico_legal_case = validated_data.pop("medico_legal_case")
instance.save()
return instance

if instance.suggestion == SuggestionChoices.OP:
instance.discharge_date = localtime(now())
Expand Down
3 changes: 3 additions & 0 deletions care/facility/api/viewsets/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ def filter_by_category(self, queryset, name, value):
last_consultation_admitted_bed_type_list = MultiSelectFilter(
method="filter_by_bed_type",
)
last_consultation_medico_legal_case = filters.BooleanFilter(
field_name="last_consultation__medico_legal_case"
)

def filter_by_bed_type(self, queryset, name, value):
if not value:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.6 on 2023-10-11 06:31

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("facility", "0389_merge_20231005_2247"),
]

operations = [
migrations.AddField(
model_name="patientconsultation",
name="medico_legal_case",
field=models.BooleanField(default=False),
),
]
2 changes: 2 additions & 0 deletions care/facility/models/patient_consultation.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ class PatientConsultation(PatientBaseModel, PatientRelatedPermissionMixin):
related_name="patient_assigned_to",
)

medico_legal_case = models.BooleanField(default=False)

deprecated_verified_by = models.TextField(default="", null=True, blank=True)
verified_by = models.ForeignKey(
User, on_delete=models.SET_NULL, null=True, blank=True
Expand Down
51 changes: 51 additions & 0 deletions care/facility/tests/test_patient_consultation_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,54 @@ def test_referred_to_external_valid_value(self):
referred_to_external=referred_to_external,
)
self.assertEqual(res.status_code, status.HTTP_200_OK)

def test_medico_legal_case(self):
consultation = self.create_admission_consultation(
medico_legal_case=True,
)
url = self.get_url(consultation)

data = self.client.get(url)
self.assertEqual(data.status_code, status.HTTP_200_OK)
self.assertEqual(data.data["medico_legal_case"], True)

# Test Patch
response = self.update_consultation(consultation, medico_legal_case=False)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data["medico_legal_case"], False)

# Test Patch after discharge
response = self.discharge(
consultation,
discharge_reason="REC",
discharge_date="2023-07-01T12:00:00Z",
discharge_notes="Discharged with valid referred_to_external",
medico_legal_case=False,
)
self.assertEqual(response.status_code, status.HTTP_200_OK)

data = self.client.get(url)
self.assertEqual(data.status_code, status.HTTP_200_OK)
self.assertEqual(data.data["medico_legal_case"], False)

response = self.update_consultation(consultation, medico_legal_case=True)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data["medico_legal_case"], True)

def test_update_consultation_after_discharge(self):
consultation = self.create_admission_consultation(
suggestion="A",
admission_date=make_aware(datetime.datetime(2020, 4, 1, 15, 30, 00)),
)
res = self.discharge(
consultation,
discharge_reason="REC",
discharge_date="2020-04-02T15:30:00Z",
discharge_notes="Discharge as recovered after admission before future",
)
self.assertEqual(res.status_code, status.HTTP_200_OK)

res = self.update_consultation(
consultation, symptoms=[1, 2], category="MILD", suggestion="A"
)
self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST)
Loading