diff --git a/care/facility/api/serializers/daily_round.py b/care/facility/api/serializers/daily_round.py index 340962d86d..94f1297977 100644 --- a/care/facility/api/serializers/daily_round.py +++ b/care/facility/api/serializers/daily_round.py @@ -211,7 +211,6 @@ def create(self, validated_data): "other_symptoms", "physical_examination_info", "other_details", - "recommend_discharge", "bp", "pulse", "resp", @@ -291,8 +290,8 @@ def create(self, validated_data): self.update_last_daily_round(daily_round_obj) return daily_round_obj - def validate(self, obj): - validated = super().validate(obj) + def validate(self, attrs): + validated = super().validate(attrs) if validated["consultation"].discharge_date: raise ValidationError( diff --git a/care/facility/migrations/0388_alter_historicalpatientregistration_action_and_more.py b/care/facility/migrations/0388_alter_historicalpatientregistration_action_and_more.py new file mode 100644 index 0000000000..c8324749b6 --- /dev/null +++ b/care/facility/migrations/0388_alter_historicalpatientregistration_action_and_more.py @@ -0,0 +1,62 @@ +from django.db import migrations, models + + +def update_recommend_discharge(apps, schema_editor): + patient_model = apps.get_model("facility", "PatientRegistration") + patient_model.objects.filter( + last_consultation__last_daily_round__recommend_discharge=True + ).update(action=90) + + +class Migration(migrations.Migration): + dependencies = [ + ("facility", "0387_merge_20230911_2303"), + ] + + operations = [ + migrations.AlterField( + model_name="historicalpatientregistration", + name="action", + field=models.IntegerField( + blank=True, + choices=[ + (10, "NO_ACTION"), + (20, "PENDING"), + (30, "SPECIALIST_REQUIRED"), + (40, "PLAN_FOR_HOME_CARE"), + (50, "FOLLOW_UP_NOT_REQUIRED"), + (60, "COMPLETE"), + (70, "REVIEW"), + (80, "NOT_REACHABLE"), + (90, "DISCHARGE_RECOMMENDED"), + ], + default=10, + null=True, + ), + ), + migrations.AlterField( + model_name="patientregistration", + name="action", + field=models.IntegerField( + blank=True, + choices=[ + (10, "NO_ACTION"), + (20, "PENDING"), + (30, "SPECIALIST_REQUIRED"), + (40, "PLAN_FOR_HOME_CARE"), + (50, "FOLLOW_UP_NOT_REQUIRED"), + (60, "COMPLETE"), + (70, "REVIEW"), + (80, "NOT_REACHABLE"), + (90, "DISCHARGE_RECOMMENDED"), + ], + default=10, + null=True, + ), + ), + migrations.RunPython(update_recommend_discharge), + migrations.RemoveField( + model_name="dailyround", + name="recommend_discharge", + ), + ] diff --git a/care/facility/migrations/0389_merge_20231002_1802.py b/care/facility/migrations/0389_merge_20231002_1802.py new file mode 100644 index 0000000000..17a11528c7 --- /dev/null +++ b/care/facility/migrations/0389_merge_20231002_1802.py @@ -0,0 +1,12 @@ +# Generated by Django 4.2.5 on 2023-10-02 12:32 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("facility", "0388_alter_historicalpatientregistration_action_and_more"), + ("facility", "0388_goal_goalentry_goalproperty_goalpropertyentry"), + ] + + operations = [] diff --git a/care/facility/models/daily_round.py b/care/facility/models/daily_round.py index 89575f5058..83b6f02f18 100644 --- a/care/facility/models/daily_round.py +++ b/care/facility/models/daily_round.py @@ -122,7 +122,9 @@ class InsulinIntakeFrequencyType(enum.Enum): ] consultation = models.ForeignKey( - PatientConsultation, on_delete=models.PROTECT, related_name="daily_rounds" + PatientConsultation, + on_delete=models.PROTECT, + related_name="daily_rounds", ) temperature = models.DecimalField( decimal_places=2, @@ -158,9 +160,6 @@ class InsulinIntakeFrequencyType(enum.Enum): current_health = models.IntegerField( default=0, choices=CURRENT_HEALTH_CHOICES, blank=True ) - recommend_discharge = models.BooleanField( - default=False, verbose_name="Recommend Discharging Patient" - ) other_details = models.TextField(null=True, blank=True) medication_given = JSONField(default=dict) # To be Used Later on @@ -168,7 +167,10 @@ class InsulinIntakeFrequencyType(enum.Enum): created_by_telemedicine = models.BooleanField(default=False) created_by = models.ForeignKey( - User, on_delete=models.SET_NULL, null=True, related_name="update_created_user" + User, + on_delete=models.SET_NULL, + null=True, + related_name="update_created_user", ) last_edited_by = models.ForeignKey( @@ -265,7 +267,8 @@ class InsulinIntakeFrequencyType(enum.Enum): rhythm = models.IntegerField(choices=RythmnChoice, default=RythmnType.UNKNOWN.value) rhythm_detail = models.TextField(default=None, null=True, blank=True) ventilator_interface = models.IntegerField( - choices=VentilatorInterfaceChoice, default=VentilatorInterfaceType.UNKNOWN.value + choices=VentilatorInterfaceChoice, + default=VentilatorInterfaceType.UNKNOWN.value, ) ventilator_mode = models.IntegerField( choices=VentilatorModeChoice, default=VentilatorModeType.UNKNOWN.value @@ -339,7 +342,8 @@ class InsulinIntakeFrequencyType(enum.Enum): validators=[MinValueValidator(0), MaxValueValidator(10)], ) pain_scale_enhanced = JSONField( - default=list, validators=[JSONFieldSchemaValidator(PAIN_SCALE_ENHANCED)] + default=list, + validators=[JSONFieldSchemaValidator(PAIN_SCALE_ENHANCED)], ) ph = models.DecimalField( decimal_places=2, @@ -457,9 +461,26 @@ def cztn(self, value): return value def update_pressure_sore(self): - area_interval_points = [0.1, 0.3, 0.7, 1.1, 2.1, 3.1, 4.1, 8.1, 12.1, 25] + area_interval_points = [ + 0.1, + 0.3, + 0.7, + 1.1, + 2.1, + 3.1, + 4.1, + 8.1, + 12.1, + 25, + ] exudate_amounts = ["None", "Light", "Moderate", "Heavy"] - tissue_types = ["Closed", "Epithelial", "Granulation", "Slough", "Necrotic"] + tissue_types = [ + "Closed", + "Epithelial", + "Granulation", + "Slough", + "Necrotic", + ] def cal_push_score(item): push_score = item.get("base_score", 0.0) diff --git a/care/facility/models/patient.py b/care/facility/models/patient.py index 44fe0ee1a6..cd14e5fcfa 100644 --- a/care/facility/models/patient.py +++ b/care/facility/models/patient.py @@ -77,6 +77,7 @@ class ActionEnum(enum.Enum): COMPLETE = 60 REVIEW = 70 NOT_REACHABLE = 80 + DISCHARGE_RECOMMENDED = 90 ActionChoices = [(e.value, e.name) for e in ActionEnum] diff --git a/care/facility/tests/test_patient_daily_rounds_api.py b/care/facility/tests/test_patient_daily_rounds_api.py index cd5a1eb56b..f53562db9a 100644 --- a/care/facility/tests/test_patient_daily_rounds_api.py +++ b/care/facility/tests/test_patient_daily_rounds_api.py @@ -1,6 +1,9 @@ +import datetime + from rest_framework import status from rest_framework.test import APITestCase +from care.facility.models import PatientRegistration from care.utils.tests.test_utils import TestUtils @@ -13,6 +16,10 @@ def setUpTestData(cls) -> None: cls.super_user = cls.create_super_user("su", cls.district) cls.facility = cls.create_facility(cls.super_user, cls.district, cls.local_body) cls.user = cls.create_user("staff1", cls.district, home_facility=cls.facility) + cls.patient = cls.create_patient(district=cls.district, facility=cls.facility) + cls.consultation = cls.create_consultation( + facility=cls.facility, patient=cls.patient + ) def get_url(self, external_consultation_id=None): return f"/api/v1/consultation/{external_consultation_id}/daily_rounds/analyse/" @@ -21,3 +28,26 @@ def test_external_consultation_does_not_exists_returns_404(self): sample_uuid = "e4a3d84a-d678-4992-9287-114f029046d8" response = self.client.get(self.get_url(sample_uuid)) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + + def test_action_in_log_update( + self, + ): + log_update = { + "clone_last": False, + "rounds_type": "NORMAL", + "patient_category": "Comfort", + "action": "DISCHARGE_RECOMMENDED", + "taken_at": datetime.datetime.now().isoformat(), + } + response = self.client.post( + f"/api/v1/consultation/{self.consultation.external_id}/daily_rounds/", + data=log_update, + format="json", + ) + self.assertEqual(response.status_code, status.HTTP_201_CREATED) + self.assertEqual(response.data["patient_category"], "Comfort Care") + self.assertEqual(response.data["rounds_type"], "NORMAL") + patient = PatientRegistration.objects.get(id=self.consultation.patient_id) + self.assertEqual( + patient.action, PatientRegistration.ActionEnum.DISCHARGE_RECOMMENDED.value + ) diff --git a/care/utils/tests/test_utils.py b/care/utils/tests/test_utils.py index 0c884afba2..2ba4412dd7 100644 --- a/care/utils/tests/test_utils.py +++ b/care/utils/tests/test_utils.py @@ -220,7 +220,8 @@ def create_facility( "created_by": user, } data.update(kwargs) - return Facility.objects.create(**data) + facility = Facility.objects.create(**data) + return facility @classmethod def get_patient_data(cls, district, state) -> dict: