Skip to content

Commit

Permalink
fix(daily_rounds): migrated all fields that has zero values to null
Browse files Browse the repository at this point in the history
  • Loading branch information
aeswibon committed Jan 22, 2024
1 parent a538bca commit 869c019
Show file tree
Hide file tree
Showing 2 changed files with 260 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
# Generated by Django 4.2.8 on 2024-01-20 10:02

from django.db import migrations, models


def forwards_func(apps, schema_editor):
DailyRound = apps.get_model("facility", "DailyRound")
daily_round_objects = DailyRound.objects.all()
objects = []
for obj in daily_round_objects:
if obj.consciousness_level == 0:
obj.consciousness_level = None
if obj.left_pupil_light_reaction == 0:
obj.left_pupil_light_reaction = None
if obj.right_pupil_light_reaction == 0:
obj.right_pupil_light_reaction = None
if obj.limb_response_upper_extremity_left == 0:
obj.limb_response_upper_extremity_left = None
if obj.limb_response_upper_extremity_right == 0:
obj.limb_response_upper_extremity_right = None
if obj.limb_response_lower_extremity_left == 0:
obj.limb_response_lower_extremity_left = None
if obj.limb_response_lower_extremity_right == 0:
obj.limb_response_lower_extremity_right = None
if obj.rhythm == 0:
obj.rhythm = None
if obj.ventilator_mode == 0:
obj.ventilator_mode = None
if obj.ventilator_interface == 0:
obj.ventilator_interface = None
if obj.ventilator_oxygen_modality == 0:
obj.ventilator_oxygen_modality = None
if obj.insulin_intake_frequency == 0:
obj.insulin_intake_frequency = None

objects.append(obj)

DailyRound.objects.bulk_update(
objects,
[
"consciousness_level",
"left_pupil_light_reaction",
"right_pupil_light_reaction",
"limb_response_upper_extremity_left",
"limb_response_upper_extremity_right",
"limb_response_lower_extremity_left",
"limb_response_lower_extremity_right",
"rhythm",
"ventilator_mode",
"ventilator_interface",
"ventilator_oxygen_modality",
"insulin_intake_frequency",
],
)


class Migration(migrations.Migration):
dependencies = [
("facility", "0407_alter_dailyround_additional_symptoms_and_more"),
]

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),
]
27 changes: 14 additions & 13 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(70)],
)
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

0 comments on commit 869c019

Please sign in to comment.