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

Add referred facility to discharge serializer #1506

Merged
merged 5 commits into from
Aug 8, 2023
Merged
Changes from 1 commit
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
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
Loading