Skip to content

Commit

Permalink
Merge pull request #2377 from coronasafe/develop
Browse files Browse the repository at this point in the history
Staging release v24.34.2
  • Loading branch information
gigincg authored Aug 21, 2024
2 parents 6de8d3c + 68a3a82 commit f249fb2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
7 changes: 5 additions & 2 deletions care/facility/api/serializers/patient_consultation.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ def create(self, validated_data):
if validated_data["is_kasp"]:
validated_data["kasp_enabled_date"] = now()

bed = validated_data.pop("bed", None)

# Coercing facility as the patient's facility
validated_data["facility_id"] = patient.facility_id

Expand Down Expand Up @@ -440,7 +442,6 @@ def create(self, validated_data):
for obj in create_symptoms
)

bed = validated_data.pop("bed", None)
if bed and consultation.suggestion == SuggestionChoices.A:
consultation_bed = ConsultationBed(
bed=bed,
Expand Down Expand Up @@ -555,7 +556,9 @@ def validate_create_symptoms(self, value):
if item in counter:
# Reject if duplicate symptoms are provided
raise ValidationError("Duplicate symptoms are not allowed")
counter.add(item)
if not obj.get("cure_date"):
# skip duplicate symptom check for ones that has cure date
counter.add(item)

current_time = now()
for obj in value:
Expand Down
31 changes: 31 additions & 0 deletions care/facility/tests/test_encounter_symptom_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,37 @@ def test_create_consultation_with_duplicate_symptoms(self):
{"create_symptoms": ["Duplicate symptoms are not allowed"]},
)

def test_create_consultation_with_duplicate_cured_symptoms(self):
data = self.consultation_data.copy()
data["create_symptoms"] = [
{
"symptom": Symptom.FEVER,
"onset_date": now(),
"cure_date": now(),
},
{
"symptom": Symptom.FEVER,
"onset_date": now(),
},
{
"symptom": Symptom.OTHERS,
"other_symptom": "Other Symptom",
"onset_date": now(),
"cure_date": now(),
},
{
"symptom": Symptom.OTHERS,
"other_symptom": "Other Symptom",
"onset_date": now(),
},
]
response = self.client.post(
"/api/v1/consultation/",
data,
format="json",
)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)

def test_create_consultation_with_no_symptom(self):
data = self.consultation_data.copy()

Expand Down
15 changes: 15 additions & 0 deletions care/facility/tests/test_patient_consultation_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from rest_framework.test import APITestCase

from care.facility.api.serializers.patient_consultation import MIN_ENCOUNTER_DATE
from care.facility.models.bed import Bed
from care.facility.models.encounter_symptom import Symptom
from care.facility.models.file_upload import FileUpload
from care.facility.models.icd11_diagnosis import (
Expand Down Expand Up @@ -641,3 +642,17 @@ def test_allow_empty_op_no(self):
)
res = self.client.post(self.get_url(), data, format="json")
self.assertEqual(res.status_code, status.HTTP_201_CREATED)

def test_create_consultation_with_bed(self):
asset_location = self.create_asset_location(self.facility)
bed = Bed.objects.create(
name="bed", location=asset_location, facility=self.facility
)

consultation: PatientConsultation = self.create_admission_consultation(
suggestion=SuggestionChoices.A,
encounter_date=make_aware(datetime.datetime(2020, 4, 1, 15, 30, 00)),
bed=bed.external_id,
)

self.assertEqual(consultation.current_bed.bed, bed)

0 comments on commit f249fb2

Please sign in to comment.