Skip to content

Commit

Permalink
fix: removed patient_category from the shifting model (#1280)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeswibon authored Apr 28, 2023
1 parent 11d291b commit 79618c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
10 changes: 8 additions & 2 deletions care/facility/api/serializers/shifting.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
)
from care.facility.models import (
BREATHLESSNESS_CHOICES,
CATEGORY_CHOICES,
FACILITY_TYPES,
SHIFTING_STATUS_CHOICES,
VEHICLE_CHOICES,
Expand Down Expand Up @@ -221,7 +220,6 @@ class ShiftingSerializer(serializers.ModelSerializer):
last_edited_by_object = UserBaseMinimumSerializer(
source="last_edited_by", read_only=True
)
patient_category = ChoiceField(choices=CATEGORY_CHOICES, required=False)
ambulance_driver_name = serializers.CharField(
required=False, allow_null=True, allow_blank=True
)
Expand Down Expand Up @@ -333,6 +331,10 @@ def update(self, instance, validated_data):
old_status = instance.status
new_instance = super().update(instance, validated_data)

patient = new_instance.patient
patient.last_consultation.category = self.initial_data["patient_category"]
patient.last_consultation.save()

if (
"status" in validated_data
and validated_data["status"] != old_status
Expand Down Expand Up @@ -393,6 +395,10 @@ def create(self, validated_data):
patient.allow_transfer = True
patient.save()

if patient.last_consultation:
patient.last_consultation.category = self.initial_data["patient_category"]
patient.last_consultation.save()

validated_data["orgin_facility"] = patient.facility

validated_data["created_by"] = self.context["request"].user
Expand Down
14 changes: 14 additions & 0 deletions care/facility/migrations/0352_auto_20230428_1539.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("facility", "0351_auto_20230424_1227"),
]

operations = [
migrations.RemoveField(
model_name="shiftingrequest",
name="patient_category",
),
]
9 changes: 3 additions & 6 deletions care/facility/models/shifting.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
pretty_boolean,
reverse_choices,
)
from care.facility.models.patient_base import CATEGORY_CHOICES
from care.users.models import User, phone_number_regex

SHIFTING_STATUS_CHOICES = (
Expand Down Expand Up @@ -45,9 +44,10 @@


class ShiftingRequest(FacilityBaseModel):

orgin_facility = models.ForeignKey(
"Facility", on_delete=models.PROTECT, related_name="requesting_facility"
"Facility",
on_delete=models.PROTECT,
related_name="requesting_facility",
)
shifting_approving_facility = models.ForeignKey(
"Facility",
Expand Down Expand Up @@ -96,9 +96,6 @@ class ShiftingRequest(FacilityBaseModel):
null=True,
related_name="shifting_assigned_to",
)
patient_category = models.CharField(
choices=CATEGORY_CHOICES, max_length=8, blank=False, null=True
)
ambulance_driver_name = models.TextField(default="", blank=True)
ambulance_phone_number = models.CharField(
max_length=14, validators=[phone_number_regex], default="", blank=True
Expand Down

0 comments on commit 79618c8

Please sign in to comment.