Skip to content

Commit

Permalink
Merge pull request #688 from coronasafe/daily_round_alias
Browse files Browse the repository at this point in the history
Switch Serializer in LastConsultation AssignedTo
  • Loading branch information
gigincg authored Feb 26, 2022
2 parents 2af02af + 189f996 commit d4a9888
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions care/facility/api/serializers/patient_consultation.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
from datetime import timedelta

from django.utils.timezone import localtime, now
from care.facility.api.serializers.daily_round import DailyRoundSerializer
from rest_framework import serializers
from rest_framework.exceptions import ValidationError

from care.facility.api.serializers import TIMESTAMP_FIELDS
from care.facility.api.serializers.daily_round import DailyRoundSerializer
from care.facility.api.serializers.facility import FacilityBasicInfoSerializer
from care.facility.models import CATEGORY_CHOICES, Facility, PatientRegistration
from care.facility.models.notification import Notification
from care.facility.models.patient_base import (
ADMIT_CHOICES,
SYMPTOM_CHOICES,
SuggestionChoices,
)
from care.facility.models.patient_base import ADMIT_CHOICES, SYMPTOM_CHOICES, SuggestionChoices
from care.facility.models.patient_consultation import PatientConsultation
from care.users.api.serializers.user import UserBaseMinimumSerializer
from care.users.api.serializers.user import UserAssignedSerializer, UserBaseMinimumSerializer
from care.users.models import User
from care.utils.notification_handler import NotificationGenerator
from care.utils.serializer.external_id_field import ExternalIdSerializerField
Expand All @@ -25,7 +21,11 @@
class PatientConsultationSerializer(serializers.ModelSerializer):
id = serializers.CharField(source="external_id", read_only=True)
facility_name = serializers.CharField(source="facility.name", read_only=True)
suggestion_text = ChoiceField(choices=PatientConsultation.SUGGESTION_CHOICES, read_only=True, source="suggestion",)
suggestion_text = ChoiceField(
choices=PatientConsultation.SUGGESTION_CHOICES,
read_only=True,
source="suggestion",
)

symptoms = serializers.MultipleChoiceField(choices=SYMPTOM_CHOICES)
category = ChoiceField(choices=CATEGORY_CHOICES, required=False)
Expand All @@ -36,7 +36,7 @@ class PatientConsultationSerializer(serializers.ModelSerializer):
patient = ExternalIdSerializerField(queryset=PatientRegistration.objects.all())
facility = ExternalIdSerializerField(queryset=Facility.objects.all())

assigned_to_object = UserBaseMinimumSerializer(source="assigned_to", read_only=True)
assigned_to_object = UserAssignedSerializer(source="assigned_to", read_only=True)

assigned_to = serializers.PrimaryKeyRelatedField(queryset=User.objects.all(), required=False, allow_null=True)

Expand Down Expand Up @@ -107,7 +107,10 @@ def update(self, instance, validated_data):
caused_by=self.context["request"].user,
caused_object=instance,
facility=instance.patient.facility,
notification_mediums=[Notification.Medium.SYSTEM, Notification.Medium.WHATSAPP],
notification_mediums=[
Notification.Medium.SYSTEM,
Notification.Medium.WHATSAPP,
],
).generate()

NotificationGenerator(
Expand Down Expand Up @@ -174,7 +177,10 @@ def create(self, validated_data):
caused_by=self.context["request"].user,
caused_object=consultation,
facility=consultation.patient.facility,
notification_mediums=[Notification.Medium.SYSTEM, Notification.Medium.WHATSAPP],
notification_mediums=[
Notification.Medium.SYSTEM,
Notification.Medium.WHATSAPP,
],
).generate()

return consultation
Expand All @@ -191,9 +197,7 @@ def validate(self, obj):
and validated.get("admitted")
and not validated.get("admission_date")
):
raise ValidationError(
{"admission_date": [f"This field is required as the patient has been admitted."]}
)
raise ValidationError({"admission_date": [f"This field is required as the patient has been admitted."]})

if "action" in validated:
if validated["action"] == PatientRegistration.ActionEnum.REVIEW:
Expand Down

0 comments on commit d4a9888

Please sign in to comment.