Skip to content

Commit

Permalink
Merge pull request #2375 from coronasafe/sainak/fix/consultation-create
Browse files Browse the repository at this point in the history
fix consultation create with bed
  • Loading branch information
vigneshhari authored Aug 21, 2024
2 parents f3b684f + a0d8563 commit 68a3a82
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion 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
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 68a3a82

Please sign in to comment.