-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Painscale changed from 0 - 5 to 0 - 10 (#1967)
* 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
1 parent
0bf4d1d
commit 52985ad
Showing
2 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters