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

Fixes check for no treating physician and not mandate for Domicialiary Care #2382

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
20 changes: 9 additions & 11 deletions care/facility/api/serializers/patient_consultation.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,22 +609,20 @@ def validate(self, attrs):
{"patient_no": "This field is required for admission."}
)

if (
"suggestion" in validated
and validated["suggestion"] != SuggestionChoices.DD
):
if "treating_physician" not in validated:
if "suggestion" in validated and validated["suggestion"] not in [
SuggestionChoices.DD,
SuggestionChoices.DC,
]:
treating_physician = validated.get("treating_physician")
if not treating_physician:
raise ValidationError(
{
"treating_physician": [
"This field is required as the suggestion is not 'Declared Death'"
]
}
)
if (
not validated["treating_physician"].user_type
== User.TYPE_VALUE_MAP["Doctor"]
):
if not treating_physician.user_type == User.TYPE_VALUE_MAP["Doctor"]:
raise ValidationError("Only Doctors can verify a Consultation")

facility = (
Expand All @@ -633,8 +631,8 @@ def validate(self, attrs):
or validated["patient"].facility
)
if (
validated["treating_physician"].home_facility
and validated["treating_physician"].home_facility != facility
treating_physician.home_facility
and treating_physician.home_facility != facility
):
raise ValidationError(
"Home Facility of the Doctor must be the same as the Consultation Facility"
Expand Down
13 changes: 11 additions & 2 deletions care/facility/tests/test_patient_consultation_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def create_route_to_facility_consultation(
data.update(kwargs)
return self.client.post(self.get_url(), data, format="json")

def create_admission_consultation(self, patient=None, **kwargs):
def call_create_admission_consultation_api(self, patient=None, **kwargs):
patient = patient or self.create_patient(self.district, self.facility)
data = self.get_default_data().copy()
kwargs.update(
Expand All @@ -97,7 +97,10 @@ def create_admission_consultation(self, patient=None, **kwargs):
}
)
data.update(kwargs)
res = self.client.post(self.get_url(), data, format="json")
return self.client.post(self.get_url(), data, format="json")

def create_admission_consultation(self, patient=None, **kwargs):
res = self.call_create_admission_consultation_api(patient, **kwargs)
return PatientConsultation.objects.get(external_id=res.data["id"])

def update_consultation(self, consultation, **kwargs):
Expand Down Expand Up @@ -132,6 +135,12 @@ def test_encounter_date_less_than_minimum(self):
res = self.client.post(self.get_url(), data, format="json")
self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST)

def test_create_admission_consultation_without_treating_physician(self):
res = self.call_create_admission_consultation_api(
suggestion="A", treating_physician=None
)
self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST)

def test_create_consultation_treating_physician_invalid_user(self):
consultation = self.create_admission_consultation(suggestion="A")
res = self.update_consultation(
Expand Down