Skip to content

Commit

Permalink
Painscale changed from 0 - 5 to 0 - 10 (#1967)
Browse files Browse the repository at this point in the history
* changes to painscale

* reverted pipfile

* optimized

* Update care/facility/migrations/0420_auto_20240312_2318.py

Co-authored-by: Rithvik Nishad <[email protected]>

* Update care/facility/migrations/0420_auto_20240312_2318.py

Co-authored-by: Rithvik Nishad <[email protected]>

* correct indentations

* update migrations

* fix migrations

* merged migrations

* squashed migrations

* Update 0429_double_pain_scale.py

---------

Co-authored-by: Rithvik Nishad <[email protected]>
Co-authored-by: Aakash Singh <[email protected]>
Co-authored-by: Vignesh Hari <[email protected]>
  • Loading branch information
4 people authored May 8, 2024
1 parent 0bf4d1d commit 52985ad
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 1 deletion.
92 changes: 92 additions & 0 deletions care/facility/migrations/0429_double_pain_scale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Generated by Django 4.2.10 on 2024-03-12 17:48

from math import ceil

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

import care.utils.models.validators


def double_pain_scale(apps, schema_editor):
DailyRound = apps.get_model("facility", "DailyRound")

page = Paginator(
DailyRound.objects.only("id", "pain_scale_enhanced")
.exclude(pain_scale_enhanced__exact=[])
.order_by("id"),
2000,
)

for page_num in page.page_range:
records_to_update = []
for daily_round in page.page(page_num):
for obj in daily_round.pain_scale_enhanced:
try:
obj["scale"] *= 2
except KeyError:
pass
records_to_update.append(daily_round)
DailyRound.objects.bulk_update(records_to_update, ["pain_scale_enhanced"])


def halve_pain_scale(apps, schema_editor):
DailyRound = apps.get_model("facility", "DailyRound")
page = Paginator(
DailyRound.objects.only("id", "pain_scale_enhanced")
.exclude(pain_scale_enhanced__exact=[])
.order_by("id"),
2000,
)

for page_num in page.page_range:
records_to_update = []
for daily_round in page.page(page_num):
for obj in daily_round.pain_scale_enhanced:
try:
obj["scale"] = ceil(obj["scale"] / 2)
except KeyError:
pass
records_to_update.append(daily_round)
DailyRound.objects.bulk_update(records_to_update, ["pain_scale_enhanced"])


class Migration(migrations.Migration):
dependencies = [
("facility", "0428_alter_patientmetainfo_occupation"),
]

operations = [
migrations.AlterField(
model_name="dailyround",
name="pain_scale_enhanced",
field=models.JSONField(
default=list,
validators=[
care.utils.models.validators.JSONFieldSchemaValidator(
{
"$schema": "http://json-schema.org/draft-07/schema#",
"items": [
{
"additionalProperties": False,
"properties": {
"description": {"type": "string"},
"region": {"type": "string"},
"scale": {
"maximum": 10,
"minimum": 1,
"type": "number",
},
},
"required": ["region", "scale"],
"type": "object",
}
],
"type": "array",
}
)
],
),
),
migrations.RunPython(double_pain_scale, reverse_code=halve_pain_scale),
]
2 changes: 1 addition & 1 deletion care/facility/models/json_schema/daily_round.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"type": "object",
"properties": {
"region": {"type": "string"},
"scale": {"type": "number", "minimum": 1, "maximum": 5},
"scale": {"type": "number", "minimum": 1, "maximum": 10},
"description": {"type": "string"},
},
"additionalProperties": False,
Expand Down

0 comments on commit 52985ad

Please sign in to comment.