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

Painscale changed from 0 - 5 to 0 - 10 #1967

Merged
merged 16 commits into from
May 8, 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
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(
sainak marked this conversation as resolved.
Show resolved Hide resolved
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
Loading