Skip to content

Commit

Permalink
Reverted the migrations
Browse files Browse the repository at this point in the history
* Added deleted fields with `#deprecated` text
* Reformatted the code
  • Loading branch information
aeswibon committed Sep 21, 2022
1 parent d30d2e2 commit 0a0fe43
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 57 deletions.
116 changes: 64 additions & 52 deletions care/facility/models/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,8 @@ class TestTypeEnum(enum.Enum):

TestTypeChoices = [(e.value, e.name) for e in TestTypeEnum]

source = models.IntegerField(
choices=SourceChoices, default=SourceEnum.CARE.value
)
facility = models.ForeignKey(
"Facility", on_delete=models.SET_NULL, null=True
)
source = models.IntegerField(choices=SourceChoices, default=SourceEnum.CARE.value)
facility = models.ForeignKey("Facility", on_delete=models.SET_NULL, null=True)
nearest_facility = models.ForeignKey(
"Facility",
on_delete=models.SET_NULL,
Expand Down Expand Up @@ -141,6 +137,14 @@ class TestTypeEnum(enum.Enum):
default=False, verbose_name="Is the Patient a Medical Worker"
)

blood_group = models.CharField(
choices=BLOOD_GROUP_CHOICES,
null=True,
blank=False,
max_length=4,
verbose_name="Blood Group of Patient",
) # deprecated

contact_with_confirmed_carrier = models.BooleanField(
default=False, verbose_name="Confirmed Contact with a Covid19 Carrier"
)
Expand Down Expand Up @@ -170,6 +174,24 @@ class TestTypeEnum(enum.Enum):
verbose_name="Return Date from the Last Country if Travelled",
)

allergies = models.TextField(
default="",
blank=True,
verbose_name="Patient's Known Allergies",
) # deprecated

present_health = models.TextField(
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 All @@ -182,18 +204,14 @@ class TestTypeEnum(enum.Enum):
max_length=255, default="", verbose_name="Ward of Patient", blank=False
)

ward = models.ForeignKey(
Ward, on_delete=models.SET_NULL, null=True, blank=True
)
ward = models.ForeignKey(Ward, on_delete=models.SET_NULL, null=True, blank=True)
local_body = models.ForeignKey(
LocalBody, on_delete=models.SET_NULL, null=True, blank=True
)
district = models.ForeignKey(
District, on_delete=models.SET_NULL, null=True, blank=True
)
state = models.ForeignKey(
State, on_delete=models.SET_NULL, null=True, blank=True
)
state = models.ForeignKey(State, on_delete=models.SET_NULL, null=True, blank=True)

is_migrant_worker = models.BooleanField(
default=False,
Expand Down Expand Up @@ -252,9 +270,7 @@ class TestTypeEnum(enum.Enum):
verbose_name="Patient's information received date",
)

test_id = models.CharField(
default="", max_length=100, null=True, blank=True
)
test_id = models.CharField(default="", max_length=100, null=True, blank=True)

# Issue #600 Care_Fe
date_of_test = models.DateTimeField(
Expand Down Expand Up @@ -345,6 +361,21 @@ class TestTypeEnum(enum.Enum):
verbose_name="Is the Patient Vaccinated Against COVID-19",
)

number_of_doses = models.PositiveIntegerField(
default=0,
null=False,
blank=False,
validators=[MinValueValidator(0), MaxValueValidator(3)],
) # deprecated

vaccine_name = models.CharField(
choices=VACCINE_CHOICES,
default=None,
null=True,
blank=False,
max_length=15,
) # deprecated

covin_id = models.CharField(
max_length=15,
default=None,
Expand All @@ -353,6 +384,12 @@ class TestTypeEnum(enum.Enum):
verbose_name="COVID-19 Vaccination ID",
)

last_vaccinated_date = models.DateTimeField(
null=True,
blank=True,
verbose_name="Date Last Vaccinated",
) # deprecated

# Extras
cluster_name = models.CharField(
max_length=255,
Expand Down Expand Up @@ -380,16 +417,12 @@ class TestTypeEnum(enum.Enum):
related_name="root_patient_assigned_to",
)

history = HistoricalRecords(
excluded_fields=["patient_search_id", "meta_info"]
)
history = HistoricalRecords(excluded_fields=["patient_search_id", "meta_info"])

objects = BaseManager()

def __str__(self):
return "{} - {} - {}".format(
self.name, self.age, self.get_gender_display()
)
return "{} - {} - {}".format(self.name, self.age, self.get_gender_display())

@property
def tele_consultation_history(self):
Expand Down Expand Up @@ -562,13 +595,9 @@ def save(self, *args, **kwargs) -> None:
"last_consultation__deprecated_covid_category": (
lambda x: REVERSE_COVID_CATEGORY_CHOICES.get(x, "-")
),
"last_consultation__category": lambda x: REVERSE_CATEGORY_CHOICES.get(
x, "-"
),
"last_consultation__category": lambda x: REVERSE_CATEGORY_CHOICES.get(x, "-"),
"last_consultation__suggestion": (
lambda x: PatientConsultation.REVERSE_SUGGESTION_CHOICES.get(
x, "-"
)
lambda x: PatientConsultation.REVERSE_SUGGESTION_CHOICES.get(x, "-")
),
"last_consultation__admitted": pretty_boolean,
"last_consultation__current_bed__bed__bed_type": (
Expand All @@ -587,28 +616,23 @@ class PatientSearch(PatientBaseModel):
year_of_birth = models.IntegerField()
state_id = models.IntegerField()

facility = models.ForeignKey(
"Facility", on_delete=models.SET_NULL, null=True
)
facility = models.ForeignKey("Facility", on_delete=models.SET_NULL, null=True)
patient_external_id = EncryptedCharField(max_length=100, default="")

allow_transfer = models.BooleanField(default=True)
is_active = models.BooleanField(default=True)

class Meta:
indexes = [
models.Index(
fields=["year_of_birth", "date_of_birth", "phone_number"]
),
models.Index(fields=["year_of_birth", "date_of_birth", "phone_number"]),
models.Index(fields=["year_of_birth", "phone_number"]),
]

@staticmethod
def has_read_permission(request):
if (
request.user.is_superuser
or request.user.user_type
>= User.TYPE_VALUE_MAP["DistrictLabAdmin"]
or request.user.user_type >= User.TYPE_VALUE_MAP["DistrictLabAdmin"]
):
return True
elif (
Expand Down Expand Up @@ -671,9 +695,7 @@ class ModeOfContactEnum(enum.IntEnum):
TRAVELLED_TOGETHER_WITHOUT_HIGH_EXPOSURE = 9

RelationChoices = [(item.value, item.name) for item in RelationEnum]
ModeOfContactChoices = [
(item.value, item.name) for item in ModeOfContactEnum
]
ModeOfContactChoices = [(item.value, item.name) for item in ModeOfContactEnum]

patient = models.ForeignKey(
PatientRegistration,
Expand All @@ -691,9 +713,7 @@ class ModeOfContactEnum(enum.IntEnum):
date_of_first_contact = models.DateField(null=True)
date_of_last_contact = models.DateField(null=True)

is_primary = models.BooleanField(
help_text="If false, then secondary contact"
)
is_primary = models.BooleanField(help_text="If false, then secondary contact")
condition_of_contact_is_symptomatic = models.BooleanField(
help_text="While in contact, did the patient showing symptoms"
)
Expand All @@ -703,9 +723,7 @@ class ModeOfContactEnum(enum.IntEnum):
objects = BaseManager()


class FacilityPatientStatsHistory(
FacilityBaseModel, FacilityRelatedPermissionMixin
):
class FacilityPatientStatsHistory(FacilityBaseModel, FacilityRelatedPermissionMixin):
facility = models.ForeignKey("Facility", on_delete=models.PROTECT)
entry_date = models.DateField()
num_patients_visited = models.IntegerField(default=0)
Expand Down Expand Up @@ -734,9 +752,7 @@ class Meta:

class PatientMobileOTP(BaseModel):
is_used = models.BooleanField(default=False)
phone_number = models.CharField(
max_length=14, validators=[phone_number_regex]
)
phone_number = models.CharField(max_length=14, validators=[phone_number_regex])
otp = models.CharField(max_length=10)


Expand Down Expand Up @@ -880,11 +896,7 @@ class Meta:
]

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

def get_disease_display(self):
return DISEASE_CHOICES[self.disease - 1][1]
38 changes: 33 additions & 5 deletions care/facility/models/patient_consultation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class PatientConsultation(PatientBaseModel, PatientRelatedPermissionMixin):
REVERSE_SUGGESTION_CHOICES = reverse_choices(SUGGESTION_CHOICES)

patient = models.ForeignKey(
"PatientRegistration", on_delete=models.CASCADE, related_name="consultations"
"PatientRegistration",
on_delete=models.CASCADE,
related_name="consultations",
)

ip_no = models.CharField(max_length=100, default="", null=True, blank=True)
Expand Down Expand Up @@ -101,7 +103,10 @@ class PatientConsultation(PatientBaseModel, PatientRelatedPermissionMixin):
last_updated_by_telemedicine = models.BooleanField(default=False) # Deprecated

assigned_to = models.ForeignKey(
User, on_delete=models.SET_NULL, null=True, related_name="patient_assigned_to"
User,
on_delete=models.SET_NULL,
null=True,
related_name="patient_assigned_to",
)

verified_by = models.TextField(default="", null=True, blank=True)
Expand All @@ -111,11 +116,17 @@ class PatientConsultation(PatientBaseModel, PatientRelatedPermissionMixin):
)

last_edited_by = models.ForeignKey(
User, on_delete=models.SET_NULL, null=True, related_name="last_edited_user"
User,
on_delete=models.SET_NULL,
null=True,
related_name="last_edited_user",
)

last_daily_round = models.ForeignKey(
"facility.DailyRound", on_delete=models.SET_NULL, null=True, default=None
"facility.DailyRound",
on_delete=models.SET_NULL,
null=True,
default=None,
)

current_bed = models.ForeignKey(
Expand All @@ -127,10 +138,27 @@ class PatientConsultation(PatientBaseModel, PatientRelatedPermissionMixin):
)

last_health_details = models.ForeignKey(
"PatientHealthDetails", on_delete=models.SET_NULL, null=True, default=None
"PatientHealthDetails",
on_delete=models.SET_NULL,
null=True,
default=None,
)
# Physical Information

height = models.FloatField(
default=None,
null=True,
verbose_name="Patient's Height in CM",
validators=[MinValueValidator(0)],
) # deprecated

weight = models.FloatField(
default=None,
null=True,
verbose_name="Patient's Weight in KG",
validators=[MinValueValidator(0)],
) # deprecated

HBA1C = models.FloatField(
default=None,
null=True,
Expand Down

0 comments on commit 0a0fe43

Please sign in to comment.