From d03da99dd824b5e840be29d1138e96ad8e282a69 Mon Sep 17 00:00:00 2001 From: cp-Coder Date: Mon, 5 Sep 2022 14:54:16 +0530 Subject: [PATCH 1/3] Changed occupation field from IntegerField to CharField --- care/facility/models/patient.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/care/facility/models/patient.py b/care/facility/models/patient.py index 09d76e0f57..fb8ec84959 100644 --- a/care/facility/models/patient.py +++ b/care/facility/models/patient.py @@ -529,18 +529,7 @@ def has_read_permission(request): class PatientMetaInfo(models.Model): - class OccupationEnum(enum.Enum): - STUDENT = 1 - MEDICAL_WORKER = 2 - GOVT_EMPLOYEE = 3 - PRIVATE_EMPLOYEE = 4 - HOME_MAKER = 5 - WORKING_ABROAD = 6 - OTHERS = 7 - - OccupationChoices = [(item.value, item.name) for item in OccupationEnum] - - occupation = models.IntegerField(choices=OccupationChoices) + occupation = models.CharField(max_length=100, null=True, blank=True) head_of_household = models.BooleanField() From e1253f70f3b998a0833772688cf4fc2cbddf8742 Mon Sep 17 00:00:00 2001 From: cp-Coder Date: Mon, 5 Sep 2022 14:55:49 +0530 Subject: [PATCH 2/3] Removed occupation as ChoiceField from PatientMetaInfoSerializer --- care/facility/api/serializers/patient.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/care/facility/api/serializers/patient.py b/care/facility/api/serializers/patient.py index 5a0bdbd7c5..67d2c25ce0 100644 --- a/care/facility/api/serializers/patient.py +++ b/care/facility/api/serializers/patient.py @@ -51,8 +51,6 @@ class PatientMetaInfoSerializer(serializers.ModelSerializer): - occupation = ChoiceField(choices=PatientMetaInfo.OccupationChoices) - class Meta: model = PatientMetaInfo fields = "__all__" From 874b1822897f233d1580588f8aa4ab4bffc0183a Mon Sep 17 00:00:00 2001 From: cp-Coder Date: Mon, 5 Sep 2022 14:56:44 +0530 Subject: [PATCH 3/3] Added migration for altering the occupation field --- .../migrations/0315_auto_20220905_1008.py | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 care/facility/migrations/0315_auto_20220905_1008.py diff --git a/care/facility/migrations/0315_auto_20220905_1008.py b/care/facility/migrations/0315_auto_20220905_1008.py new file mode 100644 index 0000000000..61159f41a5 --- /dev/null +++ b/care/facility/migrations/0315_auto_20220905_1008.py @@ -0,0 +1,57 @@ +# Generated by Django 2.2.11 on 2022-09-05 04:38 + +import enum +from django.db import migrations, models + + +class OccupationEnum(enum.Enum): + STUDENT = 1 + MEDICAL_WORKER = 2 + GOVT_EMPLOYEE = 3 + PRIVATE_EMPLOYEE = 4 + HOME_MAKER = 5 + WORKING_ABROAD = 6 + OTHERS = 7 + + +OccupationChoices = [(item.value, item.name) for item in OccupationEnum] +occupation_list = [] + + +def get_occupation(apps, schema_editor): + PatientRegistration = apps.get_model("facility", "PatientRegistration") + patients = PatientRegistration.objects.all() + + for patient in patients: + occupation_list.append( + { + "patient": patient, + "occupation": OccupationChoices[patient.meta_info.occupation], + } + ) + + +def populate_occupation(apps, schema_editor): + PatientRegistration = apps.get_model("facility", "PatientRegistration") + + for occupation in occupation_list: + patient = PatientRegistration.objects.get(id=occupation["patient"].id) + patient.meta_info.occupation = occupation["occupation"][1] + patient.meta_info.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ("facility", "0314_patientconsultation_icd11_diagnoses"), + ] + + operations = [ + migrations.RunPython(get_occupation, migrations.RunPython.noop), + migrations.AlterField( + model_name="patientmetainfo", + name="occupation", + field=models.CharField(blank=True, max_length=100, null=True), + ), + migrations.RunPython(populate_occupation, migrations.RunPython.noop), + ]