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: added recommend_discharge as action #1260

Merged
merged 6 commits into from
Oct 16, 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
5 changes: 2 additions & 3 deletions care/facility/api/serializers/daily_round.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ def create(self, validated_data):
"other_symptoms",
"physical_examination_info",
"other_details",
"recommend_discharge",
"bp",
"pulse",
"resp",
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
),
]
12 changes: 12 additions & 0 deletions care/facility/migrations/0389_merge_20231002_1802.py
Original file line number Diff line number Diff line change
@@ -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 = []
39 changes: 30 additions & 9 deletions care/facility/models/daily_round.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@
]

consultation = models.ForeignKey(
PatientConsultation, on_delete=models.PROTECT, related_name="daily_rounds"
PatientConsultation,
on_delete=models.PROTECT,
related_name="daily_rounds",
aeswibon marked this conversation as resolved.
Show resolved Hide resolved
)
temperature = models.DecimalField(
decimal_places=2,
Expand Down Expand Up @@ -158,17 +160,17 @@
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

last_updated_by_telemedicine = models.BooleanField(default=False)
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(
Expand Down Expand Up @@ -265,7 +267,8 @@
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
Expand Down Expand Up @@ -339,7 +342,8 @@
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,
Expand Down Expand Up @@ -457,9 +461,26 @@
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 = [

Check warning on line 464 in care/facility/models/daily_round.py

View check run for this annotation

Codecov / codecov/patch

care/facility/models/daily_round.py#L464

Added line #L464 was not covered by tests
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 = [

Check warning on line 477 in care/facility/models/daily_round.py

View check run for this annotation

Codecov / codecov/patch

care/facility/models/daily_round.py#L477

Added line #L477 was not covered by tests
"Closed",
"Epithelial",
"Granulation",
"Slough",
"Necrotic",
]

def cal_push_score(item):
push_score = item.get("base_score", 0.0)
Expand Down
1 change: 1 addition & 0 deletions care/facility/models/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
30 changes: 30 additions & 0 deletions care/facility/tests/test_patient_daily_rounds_api.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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/"
Expand All @@ -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
)
3 changes: 2 additions & 1 deletion care/utils/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down