Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track occupation of patient #1869

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions care/facility/api/serializers/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -311,9 +311,8 @@
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()

Check warning on line 315 in care/facility/api/serializers/patient.py

View check run for this annotation

Codecov / codecov/patch

care/facility/api/serializers/patient.py#L314-L315

Added lines #L314 - L315 were not covered by tests

if contacted_patients:
contacted_patient_objs = [
Expand Down Expand Up @@ -360,8 +359,12 @@
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

Check warning on line 364 in care/facility/api/serializers/patient.py

View check run for this annotation

Codecov / codecov/patch

care/facility/api/serializers/patient.py#L363-L364

Added lines #L363 - L364 were not covered by tests
else:
for key, value in meta_info.items():
setattr(patient.meta_info, key, value)

Check warning on line 367 in care/facility/api/serializers/patient.py

View check run for this annotation

Codecov / codecov/patch

care/facility/api/serializers/patient.py#L367

Added line #L367 was not covered by tests
patient.meta_info.save()

if self.partial is not True: # clear the list and enter details if PUT
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
),
),
]
15 changes: 7 additions & 8 deletions care/facility/models/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
sainak marked this conversation as resolved.
Show resolved Hide resolved
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):
Expand Down
Loading