Skip to content

Commit

Permalink
Update hospital_doctor.py
Browse files Browse the repository at this point in the history
  • Loading branch information
shauryag2002 authored Dec 7, 2024
1 parent bfd4f75 commit fa6f6bd
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions care/facility/api/serializers/hospital_doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,22 @@
class HospitalDoctorSerializer(serializers.ModelSerializer):
area_text = ChoiceField(choices=DOCTOR_TYPES, read_only=True, source="area")
id = serializers.UUIDField(source="external_id", read_only=True)
total_doctors = serializers.IntegerField(read_only=True)

class Meta:
model = HospitalDoctors
read_only_fields = (
"id",
"area_text",
"total_doctors"
)
exclude = (*TIMESTAMP_FIELDS, "facility", "external_id")

def to_representation(self, instance):
representation = super().to_representation(instance)
representation["total_doctors"] = (
HospitalDoctors.objects.filter(facility=instance.facility)
.aggregate(total_doctors=Sum("count"))["total_doctors"]
or 0
)
return representation

0 comments on commit fa6f6bd

Please sign in to comment.