From eb4f794fca56dc1ce44cb1f1a07971b0b3632cf0 Mon Sep 17 00:00:00 2001 From: cp-Coder Date: Thu, 22 Sep 2022 19:04:51 +0530 Subject: [PATCH] Updated Migrations * Refactored the migrations * Updated migrations' dependencies * Added function to link health details with patient consultation --- .../migrations/0313_merge_20220831_1553.py | 14 ------------ .../migrations/0315_merge_20220912_1001.py | 14 ------------ ...1_0900.py => 0322_patienthealthdetails.py} | 22 ++++++++++++++----- ...20220912_2244.py => 0323_vaccine_model.py} | 2 +- ...913_2021.py => 0324_notification_model.py} | 2 +- 5 files changed, 19 insertions(+), 35 deletions(-) delete mode 100644 care/facility/migrations/0313_merge_20220831_1553.py delete mode 100644 care/facility/migrations/0315_merge_20220912_1001.py rename care/facility/migrations/{0316_auto_20220831_0900.py => 0322_patienthealthdetails.py} (90%) rename care/facility/migrations/{0317_auto_20220912_2244.py => 0323_vaccine_model.py} (98%) rename care/facility/migrations/{0318_auto_20220913_2021.py => 0324_notification_model.py} (96%) diff --git a/care/facility/migrations/0313_merge_20220831_1553.py b/care/facility/migrations/0313_merge_20220831_1553.py deleted file mode 100644 index 5fa8360c30..0000000000 --- a/care/facility/migrations/0313_merge_20220831_1553.py +++ /dev/null @@ -1,14 +0,0 @@ -# Generated by Django 2.2.11 on 2022-08-31 10:23 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('facility', '0312_patientconsultation_investigation'), - ('facility', '0311_auto_20220831_0900'), - ] - - operations = [ - ] diff --git a/care/facility/migrations/0315_merge_20220912_1001.py b/care/facility/migrations/0315_merge_20220912_1001.py deleted file mode 100644 index f5cb0dbb24..0000000000 --- a/care/facility/migrations/0315_merge_20220912_1001.py +++ /dev/null @@ -1,14 +0,0 @@ -# Generated by Django 2.2.11 on 2022-09-12 04:31 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('facility', '0314_patientconsultation_icd11_diagnoses'), - ('facility', '0313_merge_20220831_1553'), - ] - - operations = [ - ] diff --git a/care/facility/migrations/0316_auto_20220831_0900.py b/care/facility/migrations/0322_patienthealthdetails.py similarity index 90% rename from care/facility/migrations/0316_auto_20220831_0900.py rename to care/facility/migrations/0322_patienthealthdetails.py index daedd55f16..caa7e1f19a 100644 --- a/care/facility/migrations/0316_auto_20220831_0900.py +++ b/care/facility/migrations/0322_patienthealthdetails.py @@ -16,6 +16,7 @@ def populate_data(apps, schema_editor): allergies = "" blood_group = None consultation = None + facility = patient.facility weight = 0.0 height = 0.0 @@ -27,6 +28,7 @@ def populate_data(apps, schema_editor): blood_group = patient.blood_group if patient.last_consultation is not None: + facility = patient.last_consultation.facility consultation = patient.last_consultation if patient.last_consultation.weight is not None: @@ -36,7 +38,7 @@ def populate_data(apps, schema_editor): health_details_obj = health_details( patient=patient, - facility=patient.last_consultation.facility, + facility=facility, weight=weight, height=height, consultation=consultation, @@ -45,18 +47,27 @@ def populate_data(apps, schema_editor): blood_group=blood_group, ) - if patient.last_consultation is not None: - patient.last_consultation.last_health_details = health_details_obj - health_details_objs.append(health_details_obj) health_details.objects.bulk_create(health_details_objs) +def link_data(apps, schema_editor): + patient_consultation = apps.get_model("facility", "PatientConsultation") + health_details = apps.get_model("facility", "PatientHealthDetails") + patient_cons_objs = patient_consultation.objects.all() + + for patient_cons in patient_cons_objs: + patient_cons.last_health_details = health_details.objects.get( + id=patient_cons.patient.id + ) + patient_cons.save(update_fields=["last_health_details"]) + + class Migration(migrations.Migration): dependencies = [ - ("facility", "0315_merge_20220912_1001"), + ("facility", "0321_merge_20220921_2255"), ] operations = [ @@ -196,4 +207,5 @@ class Migration(migrations.Migration): ), ), migrations.RunPython(populate_data, migrations.RunPython.noop), + migrations.RunPython(link_data, migrations.RunPython.noop), ] diff --git a/care/facility/migrations/0317_auto_20220912_2244.py b/care/facility/migrations/0323_vaccine_model.py similarity index 98% rename from care/facility/migrations/0317_auto_20220912_2244.py rename to care/facility/migrations/0323_vaccine_model.py index 70234ed2e8..ce2892cd8c 100644 --- a/care/facility/migrations/0317_auto_20220912_2244.py +++ b/care/facility/migrations/0323_vaccine_model.py @@ -26,7 +26,7 @@ def create_vaccination_data(apps, schema_editor): class Migration(migrations.Migration): dependencies = [ - ("facility", "0315_merge_20220912_1001"), + ("facility", "0322_patienthealthdetails"), ] operations = [ diff --git a/care/facility/migrations/0318_auto_20220913_2021.py b/care/facility/migrations/0324_notification_model.py similarity index 96% rename from care/facility/migrations/0318_auto_20220913_2021.py rename to care/facility/migrations/0324_notification_model.py index c658935744..bcc602a7b4 100644 --- a/care/facility/migrations/0318_auto_20220913_2021.py +++ b/care/facility/migrations/0324_notification_model.py @@ -4,7 +4,7 @@ class Migration(migrations.Migration): dependencies = [ - ("facility", "0317_auto_20220912_2244"), + ("facility", "0323_vaccine_model"), ] operations = [