From 0a0fe43767daa399975625efcd11f87d3af661ee Mon Sep 17 00:00:00 2001 From: cp-Coder Date: Wed, 21 Sep 2022 23:50:47 +0530 Subject: [PATCH] Reverted the migrations * Added deleted fields with `#deprecated` text * Reformatted the code --- care/facility/models/patient.py | 116 ++++++++++--------- care/facility/models/patient_consultation.py | 38 +++++- 2 files changed, 97 insertions(+), 57 deletions(-) diff --git a/care/facility/models/patient.py b/care/facility/models/patient.py index 55542713b0..54d65a6cab 100644 --- a/care/facility/models/patient.py +++ b/care/facility/models/patient.py @@ -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, @@ -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" ) @@ -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" ) @@ -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, @@ -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( @@ -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, @@ -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, @@ -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): @@ -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": ( @@ -587,9 +616,7 @@ 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) @@ -597,9 +624,7 @@ class PatientSearch(PatientBaseModel): 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"]), ] @@ -607,8 +632,7 @@ class Meta: 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 ( @@ -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, @@ -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" ) @@ -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) @@ -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) @@ -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] diff --git a/care/facility/models/patient_consultation.py b/care/facility/models/patient_consultation.py index 631885fc14..b2dae4df96 100644 --- a/care/facility/models/patient_consultation.py +++ b/care/facility/models/patient_consultation.py @@ -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) @@ -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) @@ -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( @@ -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,