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

Fixed: Added occupation field for text support #1058

Closed
wants to merge 2 commits into from
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
2 changes: 0 additions & 2 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
60 changes: 60 additions & 0 deletions care/facility/migrations/0373_alter_patientmetainfo_occupation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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 = ""

if patient.meta_info and patient.meta_info.occupation:
occupation = OccupationChoices[patient.meta_info.occupation]

occupation_list.append(
{
"patient": patient,
"occupation": 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", "0372_assetavailabilityrecord"),
]

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


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