Skip to content

Commit

Permalink
fix: Custom Migration to clean no input values as null in Daily Round…
Browse files Browse the repository at this point in the history
…s table (#1839)

* fix(daily_rounds): migrated all fields that has zero values to  null

* fix(daily_rounds): migrated blood pressure field

* fix: resolved comments

* fix: updated migrations

* fix(daily_round): resolved comments
  • Loading branch information
aeswibon authored Mar 17, 2024
1 parent 5545aa4 commit 257abe6
Show file tree
Hide file tree
Showing 2 changed files with 260 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
# Generated by Django 4.2.8 on 2024-01-20 10:02

from django.db import migrations, models
from django.db.models import Q


def forwards_func(apps, schema_editor):
DailyRound = apps.get_model("facility", "DailyRound")
DailyRound.objects.filter(consciousness_level=0).update(consciousness_level=None)
DailyRound.objects.filter(left_pupil_light_reaction=0).update(
left_pupil_light_reaction=None
)
DailyRound.objects.filter(right_pupil_light_reaction=0).update(
right_pupil_light_reaction=None
)
DailyRound.objects.filter(limb_response_upper_extremity_left=0).update(
limb_response_upper_extremity_left=None
)
DailyRound.objects.filter(limb_response_lower_extremity_right=0).update(
limb_response_lower_extremity_right=None
)
DailyRound.objects.filter(rhythm=0).update(rhythm=None)
DailyRound.objects.filter(ventilator_mode=0).update(ventilator_mode=None)
DailyRound.objects.filter(ventilator_interface=0).update(ventilator_interface=None)
DailyRound.objects.filter(ventilator_oxygen_modality=0).update(
ventilator_oxygen_modality=None
)
DailyRound.objects.filter(insulin_intake_frequency=0).update(
insulin_intake_frequency=None
)
DailyRound.objects.filter(Q(bp__systolic__lt=0) | Q(bp__diastolic__lt=0)).update(
bp={"systolic": None, "diastolic": None}
)


class Migration(migrations.Migration):
dependencies = [
("facility", "0414_remove_bed_old_name"),
]

operations = [
migrations.AlterField(
model_name="dailyround",
name="consciousness_level",
field=models.IntegerField(
choices=[
(0, "UNKNOWN"),
(5, "ALERT"),
(10, "RESPONDS_TO_VOICE"),
(15, "RESPONDS_TO_PAIN"),
(20, "UNRESPONSIVE"),
(25, "AGITATED_OR_CONFUSED"),
(30, "ONSET_OF_AGITATION_AND_CONFUSION"),
],
default=None,
null=True,
),
),
migrations.AlterField(
model_name="dailyround",
name="left_pupil_light_reaction",
field=models.IntegerField(
choices=[
(0, "UNKNOWN"),
(5, "BRISK"),
(10, "SLUGGISH"),
(15, "FIXED"),
(20, "CANNOT_BE_ASSESSED"),
],
default=None,
null=True,
),
),
migrations.AlterField(
model_name="dailyround",
name="limb_response_lower_extremity_left",
field=models.IntegerField(
choices=[
(0, "UNKNOWN"),
(5, "STRONG"),
(10, "MODERATE"),
(15, "WEAK"),
(20, "FLEXION"),
(25, "EXTENSION"),
(30, "NONE"),
],
default=None,
null=True,
),
),
migrations.AlterField(
model_name="dailyround",
name="limb_response_lower_extremity_right",
field=models.IntegerField(
choices=[
(0, "UNKNOWN"),
(5, "STRONG"),
(10, "MODERATE"),
(15, "WEAK"),
(20, "FLEXION"),
(25, "EXTENSION"),
(30, "NONE"),
],
default=None,
null=True,
),
),
migrations.AlterField(
model_name="dailyround",
name="limb_response_upper_extremity_left",
field=models.IntegerField(
choices=[
(0, "UNKNOWN"),
(5, "STRONG"),
(10, "MODERATE"),
(15, "WEAK"),
(20, "FLEXION"),
(25, "EXTENSION"),
(30, "NONE"),
],
default=None,
null=True,
),
),
migrations.AlterField(
model_name="dailyround",
name="limb_response_upper_extremity_right",
field=models.IntegerField(
choices=[
(0, "UNKNOWN"),
(5, "STRONG"),
(10, "MODERATE"),
(15, "WEAK"),
(20, "FLEXION"),
(25, "EXTENSION"),
(30, "NONE"),
],
default=None,
null=True,
),
),
migrations.AlterField(
model_name="dailyround",
name="rhythm",
field=models.IntegerField(
choices=[(0, "UNKNOWN"), (5, "REGULAR"), (10, "IRREGULAR")],
default=None,
null=True,
),
),
migrations.AlterField(
model_name="dailyround",
name="right_pupil_light_reaction",
field=models.IntegerField(
choices=[
(0, "UNKNOWN"),
(5, "BRISK"),
(10, "SLUGGISH"),
(15, "FIXED"),
(20, "CANNOT_BE_ASSESSED"),
],
default=None,
null=True,
),
),
migrations.AlterField(
model_name="dailyround",
name="ventilator_interface",
field=models.IntegerField(
choices=[
(0, "UNKNOWN"),
(5, "INVASIVE"),
(10, "NON_INVASIVE"),
(15, "OXYGEN_SUPPORT"),
],
default=None,
null=True,
),
),
migrations.AlterField(
model_name="dailyround",
name="ventilator_mode",
field=models.IntegerField(
choices=[
(0, "UNKNOWN"),
(5, "VCV"),
(10, "PCV"),
(15, "PRVC"),
(20, "APRV"),
(25, "VC_SIMV"),
(30, "PC_SIMV"),
(40, "PRVC_SIMV"),
(45, "ASV"),
(50, "PSV"),
],
default=None,
null=True,
),
),
migrations.AlterField(
model_name="dailyround",
name="ventilator_oxygen_modality",
field=models.IntegerField(
choices=[
(0, "UNKNOWN"),
(5, "NASAL_PRONGS"),
(10, "SIMPLE_FACE_MASK"),
(15, "NON_REBREATHING_MASK"),
(20, "HIGH_FLOW_NASAL_CANNULA"),
],
default=None,
null=True,
),
),
migrations.AlterField(
model_name="dailyround",
name="insulin_intake_frequency",
field=models.IntegerField(
choices=[(0, "UNKNOWN"), (5, "OD"), (10, "BD"), (15, "TD")],
default=None,
null=True,
),
),
migrations.RunPython(forwards_func, migrations.RunPython.noop),
]
60 changes: 35 additions & 25 deletions care/facility/models/daily_round.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class InsulinIntakeFrequencyType(enum.Enum):
# Critical Care Attributes

consciousness_level = models.IntegerField(
choices=ConsciousnessChoice, default=ConsciousnessType.UNKNOWN.value
choices=ConsciousnessChoice, default=None, null=True
)
consciousness_level_detail = models.TextField(default=None, null=True, blank=True)

Expand All @@ -205,7 +205,7 @@ class InsulinIntakeFrequencyType(enum.Enum):
)
left_pupil_size_detail = models.TextField(default=None, null=True, blank=True)
left_pupil_light_reaction = models.IntegerField(
choices=PupilReactionChoice, default=PupilReactionType.UNKNOWN.value
choices=PupilReactionChoice, default=None, null=True
)
left_pupil_light_reaction_detail = models.TextField(
default=None, null=True, blank=True
Expand All @@ -218,7 +218,7 @@ class InsulinIntakeFrequencyType(enum.Enum):
)
right_pupil_size_detail = models.TextField(default=None, null=True, blank=True)
right_pupil_light_reaction = models.IntegerField(
choices=PupilReactionChoice, default=PupilReactionType.UNKNOWN.value
choices=PupilReactionChoice, default=None, null=True
)
right_pupil_light_reaction_detail = models.TextField(
default=None, null=True, blank=True
Expand All @@ -244,16 +244,16 @@ class InsulinIntakeFrequencyType(enum.Enum):
validators=[MinValueValidator(3), MaxValueValidator(15)],
)
limb_response_upper_extremity_right = models.IntegerField(
choices=LimbResponseChoice, default=LimbResponseType.UNKNOWN.value
choices=LimbResponseChoice, default=None, null=True
)
limb_response_upper_extremity_left = models.IntegerField(
choices=LimbResponseChoice, default=LimbResponseType.UNKNOWN.value
choices=LimbResponseChoice, default=None, null=True
)
limb_response_lower_extremity_left = models.IntegerField(
choices=LimbResponseChoice, default=LimbResponseType.UNKNOWN.value
choices=LimbResponseChoice, default=None, null=True
)
limb_response_lower_extremity_right = models.IntegerField(
choices=LimbResponseChoice, default=LimbResponseType.UNKNOWN.value
choices=LimbResponseChoice, default=None, null=True
)
bp = JSONField(default=dict, validators=[JSONFieldSchemaValidator(BLOOD_PRESSURE)])
pulse = models.IntegerField(
Expand All @@ -266,14 +266,15 @@ class InsulinIntakeFrequencyType(enum.Enum):
null=True,
validators=[MinValueValidator(0), MaxValueValidator(150)],
)
rhythm = models.IntegerField(choices=RythmnChoice, default=RythmnType.UNKNOWN.value)
rhythm = models.IntegerField(choices=RythmnChoice, default=None, null=True)
rhythm_detail = models.TextField(default=None, null=True, blank=True)
ventilator_interface = models.IntegerField(
choices=VentilatorInterfaceChoice,
default=VentilatorInterfaceType.UNKNOWN.value,
default=None,
null=True,
)
ventilator_mode = models.IntegerField(
choices=VentilatorModeChoice, default=VentilatorModeType.UNKNOWN.value
choices=VentilatorModeChoice, default=None, null=True
)
ventilator_peep = models.DecimalField(
decimal_places=2,
Expand Down Expand Up @@ -309,8 +310,7 @@ class InsulinIntakeFrequencyType(enum.Enum):
validators=[MinValueValidator(0), MaxValueValidator(1000)],
)
ventilator_oxygen_modality = models.IntegerField(
choices=VentilatorOxygenModalityChoice,
default=VentilatorOxygenModalityType.UNKNOWN.value,
choices=VentilatorOxygenModalityChoice, default=None, null=True
)
ventilator_oxygen_modality_oxygen_rate = models.IntegerField(
default=None,
Expand Down Expand Up @@ -417,7 +417,8 @@ class InsulinIntakeFrequencyType(enum.Enum):
)
insulin_intake_frequency = models.IntegerField(
choices=InsulinIntakeFrequencyChoice,
default=InsulinIntakeFrequencyType.UNKNOWN.value,
default=None,
null=True,
)
infusions = JSONField(
default=list, validators=[JSONFieldSchemaValidator(INFUSIONS)]
Expand Down Expand Up @@ -504,18 +505,27 @@ def set_push_score(item):

def save(self, *args, **kwargs):
# Calculate all automated columns and populate them
self.glasgow_total_calculated = (
self.cztn(self.glasgow_eye_open)
+ self.cztn(self.glasgow_motor_response)
+ self.cztn(self.glasgow_verbal_response)
)
self.total_intake_calculated = sum([x["quantity"] for x in self.infusions])
self.total_intake_calculated += sum([x["quantity"] for x in self.iv_fluids])
self.total_intake_calculated += sum([x["quantity"] for x in self.feeds])

self.total_output_calculated = sum([x["quantity"] for x in self.output])

# self.pressure_sore = self.update_pressure_sore()
if (
self.glasgow_eye_open is not None
and self.glasgow_motor_response is not None
and self.glasgow_verbal_response is not None
):
self.glasgow_total_calculated = (
self.cztn(self.glasgow_eye_open)
+ self.cztn(self.glasgow_motor_response)
+ self.cztn(self.glasgow_verbal_response)
)
if (
self.infusions is not None
and self.iv_fluids is not None
and self.feeds is not None
):
self.total_intake_calculated = sum([x["quantity"] for x in self.infusions])
self.total_intake_calculated += sum([x["quantity"] for x in self.iv_fluids])
self.total_intake_calculated += sum([x["quantity"] for x in self.feeds])

if self.output is not None:
self.total_output_calculated = sum([x["quantity"] for x in self.output])

super(DailyRound, self).save(*args, **kwargs)

Expand Down

0 comments on commit 257abe6

Please sign in to comment.