Skip to content

Commit

Permalink
feat(patient): added occupation CharField
Browse files Browse the repository at this point in the history
  • Loading branch information
aeswibon committed Oct 28, 2022
1 parent 5bde4b6 commit d4f3716
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 20 deletions.
16 changes: 8 additions & 8 deletions care/facility/api/serializers/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@


class PatientMetaInfoSerializer(serializers.ModelSerializer):
occupation = ChoiceField(choices=PatientMetaInfo.OccupationChoices)

class Meta:
model = PatientMetaInfo
fields = "__all__"
Expand Down Expand Up @@ -132,7 +130,9 @@ class Meta:

phone_number = PhoneNumberIsPossibleField()

facility = ExternalIdSerializerField(queryset=Facility.objects.all(), required=False)
facility = ExternalIdSerializerField(
queryset=Facility.objects.all(), required=False
)
medical_history = serializers.ListSerializer(
child=MedicalHistorySerializer(), required=False
)
Expand Down Expand Up @@ -386,11 +386,11 @@ class PatientSearchSerializer(serializers.ModelSerializer):
class Meta:
model = PatientSearch
exclude = (
"date_of_birth",
"year_of_birth",
"external_id",
"id",
) + TIMESTAMP_FIELDS
"date_of_birth",
"year_of_birth",
"external_id",
"id",
) + TIMESTAMP_FIELDS


class PatientTransferSerializer(serializers.ModelSerializer):
Expand Down
57 changes: 57 additions & 0 deletions care/facility/migrations/0315_auto_20220905_1008.py
Original file line number Diff line number Diff line change
@@ -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),
]
14 changes: 14 additions & 0 deletions care/facility/migrations/0324_merge_20221009_1013.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 2.2.11 on 2022-10-09 04:43

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('facility', '0323_fileupload_archive_reason'),
('facility', '0315_auto_20220905_1008'),
]

operations = [
]
13 changes: 1 addition & 12 deletions care/facility/models/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,18 +619,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()


Expand Down

0 comments on commit d4f3716

Please sign in to comment.