Skip to content

Commit

Permalink
Add referred facility to discharge serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashesh3 committed Aug 3, 2023
1 parent 19b63d2 commit 880cf3f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions care/facility/api/serializers/patient_consultation.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,12 @@ class PatientConsultationDischargeSerializer(serializers.ModelSerializer):
death_datetime = serializers.DateTimeField(required=False, allow_null=True)
death_confirmed_doctor = serializers.CharField(required=False, allow_null=True)

referred_to = ExternalIdSerializerField(
queryset=Facility.objects.all(),
required=False,
)
referred_to_external = serializers.CharField(required=False, allow_blank=True)

def get_discharge_prescription(self, consultation):
return Prescription.objects.filter(
consultation=consultation,
Expand All @@ -420,6 +426,7 @@ class Meta:
model = PatientConsultation
fields = (
"discharge_reason",
"referred_to",
"referred_to_external",
"discharge_notes",
"discharge_date",
Expand All @@ -430,6 +437,18 @@ class Meta:
)

def validate(self, attrs):
if attrs.get("referred_to") and attrs.get("referred_to_external"):
raise ValidationError(
{
"referred_to": [
"Only one of referred_to and referred_to_external can be set"
],
"referred_to_external": [
"Only one of referred_to and referred_to_external can be set"
],
}
)

if attrs.get("discharge_reason") == "EXP":
if not attrs.get("death_datetime"):
raise ValidationError({"death_datetime": "This field is required"})
Expand Down

0 comments on commit 880cf3f

Please sign in to comment.