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

Rename field ventilator_fi02 to ventilator_fio2 #2356

Merged
merged 4 commits into from
Aug 21, 2024
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
2 changes: 1 addition & 1 deletion care/facility/management/commands/load_event_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class Command(BaseCommand):
"fields": (
"bilateral_air_entry",
"etco2",
"ventilator_fi02",
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved
"ventilator_fio2",
"ventilator_interface",
"ventilator_mean_airway_pressure",
"ventilator_mode",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Generated by Django 4.2.10 on 2024-08-13 10:36

from django.core.paginator import Paginator
from django.db import migrations


class Migration(migrations.Migration):
def forward_rename_dailyround_events(apps, schema_editor):
EventType = apps.get_model("facility", "EventType")
PatientConsultationEvent = apps.get_model(
"facility", "PatientConsultationEvent"
)

event_type = EventType.objects.filter(name="RESPIRATORY_SUPPORT")
if not event_type.exists():
return
event_type_id = event_type.first().id

paginator = Paginator(
PatientConsultationEvent.objects.filter(
object_model="DailyRound",
event_type_id=event_type_id,
value__has_key="ventilator_fi02",
).order_by("id"),
1000,
)

for page_number in paginator.page_range:
bulk = []
for instance in paginator.page(page_number).object_list:
instance.value["ventilator_fio2"] = instance.value.pop(
"ventilator_fi02"
)
bulk.append(instance)
PatientConsultationEvent.objects.bulk_update(bulk, ["value"])

def reverse_rename_dailyround_events(apps, schema_editor):
EventType = apps.get_model("facility", "EventType")
PatientConsultationEvent = apps.get_model(
"facility", "PatientConsultationEvent"
)

event_type = EventType.objects.filter(name="RESPIRATORY_SUPPORT")
if not event_type.exists():
return
event_type_id = event_type.first().id

paginator = Paginator(
PatientConsultationEvent.objects.filter(
object_model="DailyRound",
event_type_id=event_type_id,
value__has_key="ventilator_fio2",
).order_by("id"),
1000,
)

for page_number in paginator.page_range:
bulk = []
for instance in paginator.page(page_number).object_list:
instance.value["ventilator_fi02"] = instance.value.pop(
"ventilator_fio2"
)
bulk.append(instance)
PatientConsultationEvent.objects.bulk_update(bulk, ["value"])

dependencies = [
("facility", "0447_patientconsultationevent_taken_at"),
]

operations = [
migrations.RenameField(
model_name="dailyround",
old_name="ventilator_fi02",
new_name="ventilator_fio2",
),
migrations.RunPython(
forward_rename_dailyround_events,
reverse_code=reverse_rename_dailyround_events,
),
]
2 changes: 1 addition & 1 deletion care/facility/models/daily_round.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class InsulinIntakeFrequencyType(enum.Enum):
null=True,
validators=[MinValueValidator(0), MaxValueValidator(70)],
)
ventilator_fi02 = models.IntegerField(
ventilator_fio2 = models.IntegerField(
default=None,
null=True,
validators=[MinValueValidator(21), MaxValueValidator(100)],
Expand Down
Loading