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 consultation create with bed #2375

Merged
merged 1 commit into from
Aug 21, 2024
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
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)