-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dropped
age
column from patient registration and annotated age in p…
…atient viewset (#1966) * drop field `age` and compute age on demand * Update filters and related usages * add min value validator for year of birth * remove age from test utils * remove unnecessary default * Add field `death_datetime` in patient registration * annotate age in days * suggestion from code review * revert unintended changes * skip serializing age * rebase migrations * rebase migrations * drop age from dummy data * Revert "drop age from dummy data" This reverts commit 9964b85. * drop patient registration's age from dummy data * select only `last_consultation` in custom migration Co-authored-by: Aakash Singh <mail@singhaakash.dev> * format code * rebase migrations * rebase migrations --------- Co-authored-by: Aakash Singh <mail@singhaakash.dev>
- Loading branch information
1 parent
e97177b
commit 1115a8f
Showing
9 changed files
with
177 additions
and
89 deletions.
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
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
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
65 changes: 65 additions & 0 deletions
65
...rations/0424_remove_patientregistration_age_and_add_patientregistration_death_datetime.py
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,65 @@ | ||
# Generated by Django 4.2.8 on 2024-03-13 07:03 | ||
|
||
import django.core.validators | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("facility", "0423_patientconsultation_consent_records_and_more"), | ||
] | ||
|
||
def populate_patientregistration_death_datetime(apps, schema_editor): | ||
PatientRegistration = apps.get_model("facility", "PatientRegistration") | ||
|
||
patients = ( | ||
PatientRegistration.objects.only("last_consultation") | ||
.filter(last_consultation__death_datetime__isnull=False) | ||
.annotate(new_death_datetime=models.F("last_consultation__death_datetime")) | ||
) | ||
|
||
for patient in patients: | ||
patient.death_datetime = patient.new_death_datetime | ||
|
||
PatientRegistration.objects.bulk_update( | ||
patients, ["death_datetime"], batch_size=1000 | ||
) | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name="historicalpatientregistration", | ||
name="age", | ||
), | ||
migrations.RemoveField( | ||
model_name="patientregistration", | ||
name="age", | ||
), | ||
migrations.AddField( | ||
model_name="historicalpatientregistration", | ||
name="death_datetime", | ||
field=models.DateTimeField(default=None, null=True), | ||
), | ||
migrations.AddField( | ||
model_name="patientregistration", | ||
name="death_datetime", | ||
field=models.DateTimeField(default=None, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name="historicalpatientregistration", | ||
name="year_of_birth", | ||
field=models.IntegerField( | ||
null=True, validators=[django.core.validators.MinValueValidator(1900)] | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="patientregistration", | ||
name="year_of_birth", | ||
field=models.IntegerField( | ||
null=True, validators=[django.core.validators.MinValueValidator(1900)] | ||
), | ||
), | ||
migrations.RunPython( | ||
populate_patientregistration_death_datetime, | ||
migrations.RunPython.noop, | ||
), | ||
] |
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
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
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
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
Oops, something went wrong.