From 57a2e666f277ee6b4f5b5c87d96909e97920fac7 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 11 Feb 2024 16:15:34 +0530 Subject: [PATCH] track occupation --- care/facility/api/serializers/patient.py | 15 +++++---- ...ientmetainfo_head_of_household_and_more.py | 33 +++++++++++++++++++ care/facility/models/patient.py | 15 ++++----- 3 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 care/facility/migrations/0410_alter_patientmetainfo_head_of_household_and_more.py diff --git a/care/facility/api/serializers/patient.py b/care/facility/api/serializers/patient.py index ac70f90052..dd5fa5962f 100644 --- a/care/facility/api/serializers/patient.py +++ b/care/facility/api/serializers/patient.py @@ -55,7 +55,7 @@ class PatientMetaInfoSerializer(serializers.ModelSerializer): - occupation = ChoiceField(choices=PatientMetaInfo.OccupationChoices) + occupation = ChoiceField(choices=PatientMetaInfo.OccupationChoices, allow_null=True) class Meta: model = PatientMetaInfo @@ -311,9 +311,8 @@ def create(self, validated_data): Disease.objects.bulk_create(diseases, ignore_conflicts=True) if meta_info: - meta_info_obj = PatientMetaInfo.objects.create(**meta_info) - patient.meta_info = meta_info_obj - patient.save() + patient.meta_info = PatientMetaInfo.objects.create(**meta_info) + patient.meta_info.save() if contacted_patients: contacted_patient_objs = [ @@ -360,8 +359,12 @@ def update(self, instance, validated_data): Disease.objects.bulk_create(diseases, ignore_conflicts=True) if meta_info: - for key, value in meta_info.items(): - setattr(patient.meta_info, key, value) + if patient.meta_info is None: + meta_info_obj = PatientMetaInfo.objects.create(**meta_info) + patient.meta_info = meta_info_obj + else: + for key, value in meta_info.items(): + setattr(patient.meta_info, key, value) patient.meta_info.save() if self.partial is not True: # clear the list and enter details if PUT diff --git a/care/facility/migrations/0410_alter_patientmetainfo_head_of_household_and_more.py b/care/facility/migrations/0410_alter_patientmetainfo_head_of_household_and_more.py new file mode 100644 index 0000000000..12294faf4c --- /dev/null +++ b/care/facility/migrations/0410_alter_patientmetainfo_head_of_household_and_more.py @@ -0,0 +1,33 @@ +# Generated by Django 4.2.8 on 2024-02-11 10:40 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("facility", "0409_merge_20240210_1510"), + ] + + operations = [ + migrations.AlterField( + model_name="patientmetainfo", + name="head_of_household", + field=models.BooleanField(blank=True, null=True), + ), + migrations.AlterField( + model_name="patientmetainfo", + name="occupation", + field=models.IntegerField( + blank=True, + choices=[ + (1, "STUDENT"), + (2, "BUSINESSMAN"), + (3, "HEALTH_CARE_WORKER"), + (4, "HEALTH_CARE_LAB_WORKER"), + (5, "ANIMAL_HANDLER"), + (6, "OTHERS"), + ], + null=True, + ), + ), + ] diff --git a/care/facility/models/patient.py b/care/facility/models/patient.py index 9078392e28..28ce987d4f 100644 --- a/care/facility/models/patient.py +++ b/care/facility/models/patient.py @@ -577,17 +577,16 @@ def format_diagnoses(diagnosis_ids): 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 + BUSINESSMAN = 2 + HEALTH_CARE_WORKER = 3 + HEALTH_CARE_LAB_WORKER = 4 + ANIMAL_HANDLER = 5 + OTHERS = 6 OccupationChoices = [(item.value, item.name) for item in OccupationEnum] - occupation = models.IntegerField(choices=OccupationChoices) - head_of_household = models.BooleanField() + occupation = models.IntegerField(choices=OccupationChoices, blank=True, null=True) + head_of_household = models.BooleanField(blank=True, null=True) class PatientContactDetails(models.Model):