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 fa6f6bd commit 80aefde
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions care/facility/api/serializers/hospital_doctor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from rest_framework import serializers
from django.db.models import Sum

from care.facility.api.serializers import TIMESTAMP_FIELDS
from care.facility.models import DOCTOR_TYPES, HospitalDoctors
Expand All @@ -19,11 +20,14 @@ class Meta:
)
exclude = (*TIMESTAMP_FIELDS, "facility", "external_id")

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

0 comments on commit 80aefde

Please sign in to comment.