Skip to content

Commit

Permalink
Removed medical history API
Browse files Browse the repository at this point in the history
* Reverted back to medical history used
* Removed new MedicalHistory and Disease model
* Reformatted the code
  • Loading branch information
aeswibon committed Oct 3, 2022
1 parent 9abd57b commit ba0c283
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 61 deletions.
23 changes: 10 additions & 13 deletions care/facility/api/serializers/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
PatientSearch,
)
from care.facility.models.notification import Notification
from care.facility.models.patient_base import (
DISEASE_STATUS_CHOICES,
DiseaseStatusEnum,
)
from care.facility.models.patient_base import DISEASE_STATUS_CHOICES, DiseaseStatusEnum
from care.facility.models.patient_consultation import PatientConsultation
from care.facility.models.patient_external_test import PatientExternalTest
from care.facility.models.patient_tele_consultation import PatientTeleConsultation
Expand Down Expand Up @@ -71,7 +68,8 @@ class PatientListSerializer(serializers.ModelSerializer):
last_consultation = PatientConsultationSerializer(read_only=True)

disease_status = ChoiceField(
choices=DISEASE_STATUS_CHOICES, default=DiseaseStatusEnum.SUSPECTED.value
choices=DISEASE_STATUS_CHOICES,
default=DiseaseStatusEnum.SUSPECTED.value,
)
source = ChoiceField(choices=PatientRegistration.SourceChoices)

Expand Down Expand Up @@ -150,7 +148,8 @@ class Meta:
default=PatientRegistration.SourceEnum.CARE.value,
)
disease_status = ChoiceField(
choices=DISEASE_STATUS_CHOICES, default=DiseaseStatusEnum.SUSPECTED.value
choices=DISEASE_STATUS_CHOICES,
default=DiseaseStatusEnum.SUSPECTED.value,
)

meta_info = PatientMetaInfoSerializer(required=False, allow_null=True)
Expand Down Expand Up @@ -183,7 +182,11 @@ class Meta:
"external_id",
)
include = ("contacted_patients",)
read_only = TIMESTAMP_FIELDS + ("last_edited", "created_by", "is_active")
read_only = TIMESTAMP_FIELDS + (
"last_edited",
"created_by",
"is_active",
)

# def get_last_consultation(self, obj):
# last_consultation = PatientConsultation.objects.filter(patient=obj).last()
Expand Down Expand Up @@ -214,12 +217,6 @@ def validate(self, attrs):
{"non_field_errors": ["Either age or date_of_birth should be passed"]}
)

if validated.get("is_vaccinated"):
if validated.get("number_of_doses") == 0:
raise serializers.ValidationError("Number of doses cannot be 0")
if validated.get("vaccine_name") is None:
raise serializers.ValidationError("Vaccine name cannot be null")

return validated

def check_external_entry(self, srf_id):
Expand Down
80 changes: 32 additions & 48 deletions care/facility/models/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,13 @@ class TestTypeEnum(enum.Enum):
default="",
blank=True,
verbose_name="Patient's Current Health Details",
) # deprecated
)

ongoing_medication = models.TextField(
default="",
blank=True,
verbose_name="Already pescribed medication if any",
) # deprecated
)

has_SARI = models.BooleanField(
default=False, verbose_name="Does the Patient Suffer from SARI"
Expand Down Expand Up @@ -546,8 +546,8 @@ def save(self, *args, **kwargs) -> None:
"countries_travelled": "Countries Patient has Travelled to",
"date_of_return": "Return Date from the Last Country if Travelled",
"is_migrant_worker": "Is the Patient a Migrant Worker",
# "present_health": "Patient's Current Health Details",
# "ongoing_medication": "Already pescribed medication if any",
"present_health": "Patient's Current Health Details",
"ongoing_medication": "Already pescribed medication if any",
"has_SARI": "Does the Patient Suffer from SARI",
"date_of_receipt_of_information": "Patient's information received date",
"will_donate_blood": "Will Patient Donate Blood?",
Expand Down Expand Up @@ -723,6 +723,34 @@ class ModeOfContactEnum(enum.IntEnum):
objects = BaseManager()


class Disease(models.Model):
patient = models.ForeignKey(
PatientRegistration,
on_delete=models.CASCADE,
related_name="medical_history",
)
disease = models.IntegerField(choices=DISEASE_CHOICES)
details = models.TextField(blank=True, null=True)
deleted = models.BooleanField(default=False)

objects = BaseManager()

class Meta:
indexes = [
PartialIndex(
fields=["patient", "disease"],
unique=True,
where=PQ(deleted=False),
)
]

def __str__(self):
return self.patient.name + " - " + self.get_disease_display()

def get_disease_display(self):
return DISEASE_CHOICES[self.disease - 1][1]


class FacilityPatientStatsHistory(FacilityBaseModel, FacilityRelatedPermissionMixin):
facility = models.ForeignKey("Facility", on_delete=models.PROTECT)
entry_date = models.DateField()
Expand Down Expand Up @@ -856,47 +884,3 @@ class Meta:

def __str__(self):
return self.health_details.patient.name + " - " + self.vaccine


class MedicalHistory(PatientBaseModel, PatientRelatedPermissionMixin):
patient = models.ForeignKey(
PatientRegistration,
on_delete=models.CASCADE,
)
present_health = models.TextField(
default="", blank=True, verbose_name="Patient's Current Health Details"
)
ongoing_medication = models.TextField(
default="",
blank=True,
verbose_name="Already pescribed medication if any",
)


class Disease(models.Model):
medical_history = models.ForeignKey(
MedicalHistory,
on_delete=models.CASCADE,
related_name="medical_history",
)
disease_date = models.DateField(verbose_name="Disease Date")
disease = models.IntegerField(choices=DISEASE_CHOICES)
details = models.TextField(blank=True, null=True)
deleted = models.BooleanField(default=False)

objects = BaseManager()

class Meta:
indexes = [
PartialIndex(
fields=["medical_history", "disease"],
unique=True,
where=PQ(deleted=False),
)
]

def __str__(self):
return self.medical_history.patient.name + " - " + self.get_disease_display()

def get_disease_display(self):
return DISEASE_CHOICES[self.disease - 1][1]

0 comments on commit ba0c283

Please sign in to comment.