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

fix: removed patient_category from the shifting model #1280

Merged
merged 2 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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