diff --git a/care/facility/api/serializers/patient.py b/care/facility/api/serializers/patient.py index 3b5633b1f8..ba233adc8f 100644 --- a/care/facility/api/serializers/patient.py +++ b/care/facility/api/serializers/patient.py @@ -169,7 +169,7 @@ class MedicalHistorySerializer(serializers.Serializer): last_edited = UserBaseMinimumSerializer(read_only=True) created_by = UserBaseMinimumSerializer(read_only=True) vaccine_name = serializers.ChoiceField( - choices=PatientRegistration.vaccineChoices, required=False, allow_null=True + choices=PatientRegistration.VaccineChoices, required=False, allow_null=True ) assigned_to_object = UserBaseMinimumSerializer(source="assigned_to", read_only=True) diff --git a/care/facility/models/ambulance.py b/care/facility/models/ambulance.py index e0b7a07751..90040ddc00 100644 --- a/care/facility/models/ambulance.py +++ b/care/facility/models/ambulance.py @@ -32,10 +32,6 @@ class Ambulance(FacilityBaseModel): ) owner_is_smart_phone = models.BooleanField(default=True) - # primary_district = models.IntegerField(choices=DISTRICT_CHOICES, blank=False) - # secondary_district = models.IntegerField(choices=DISTRICT_CHOICES, blank=True, null=True) - # third_district = models.IntegerField(choices=DISTRICT_CHOICES, blank=True, null=True) - primary_district = models.ForeignKey( District, on_delete=models.PROTECT, @@ -122,15 +118,6 @@ def has_object_update_permission(self, request): ) ) - # class Meta: - # constraints = [ - # models.CheckConstraint( - # name="ambulance_free_or_price", - # check=models.Q(price_per_km__isnull=False) - # | models.Q(has_free_service=True), - # ) - # ] - class AmbulanceDriver(FacilityBaseModel): ambulance = models.ForeignKey(Ambulance, on_delete=models.CASCADE) diff --git a/care/facility/models/asset.py b/care/facility/models/asset.py index 7cb027283d..bf2ab5e317 100644 --- a/care/facility/models/asset.py +++ b/care/facility/models/asset.py @@ -62,7 +62,7 @@ class AssetType(enum.Enum): AssetTypeChoices = [(e.value, e.name) for e in AssetType] -AssetClassChoices = [(e.name, e.value._name) for e in AssetClasses] +AssetClassChoices = [(e.name, e.value._name) for e in AssetClasses] # noqa: SLF001 class Status(enum.Enum): @@ -162,6 +162,7 @@ def resolved_middleware(self): "hostname": hostname, "source": "facility", } + return None class Meta: constraints = [ @@ -312,3 +313,6 @@ class AssetServiceEdit(models.Model): class Meta: ordering = ["-edited_on"] + + def __str__(self): + return f"{self.asset_service.asset.name} - {self.serviced_on}" diff --git a/care/facility/models/daily_round.py b/care/facility/models/daily_round.py index 718b75d058..edc11a8954 100644 --- a/care/facility/models/daily_round.py +++ b/care/facility/models/daily_round.py @@ -571,7 +571,7 @@ def save(self, *args, **kwargs): if self.output is not None: self.total_output_calculated = sum([x["quantity"] for x in self.output]) - super(DailyRound, self).save(*args, **kwargs) + super().save(*args, **kwargs) @staticmethod def has_read_permission(request): @@ -585,8 +585,8 @@ def has_read_permission(request): return request.user.is_superuser or ( (request.user in consultation.patient.facility.users.all()) or ( - request.user == consultation.assigned_to - or request.user == consultation.patient.assigned_to + request.user + in (consultation.assigned_to, consultation.patient.assigned_to) ) or ( request.user.user_type >= User.TYPE_VALUE_MAP["DistrictLabAdmin"] @@ -620,8 +620,11 @@ def has_object_read_permission(self, request): and request.user in self.consultation.patient.facility.users.all() ) or ( - self.consultation.assigned_to == request.user - or request.user == self.consultation.patient.assigned_to + request.user + in ( + self.consultation.assigned_to, + self.consultation.patient.assigned_to, + ) ) or ( request.user.user_type >= User.TYPE_VALUE_MAP["DistrictLabAdmin"] diff --git a/care/facility/models/encounter_symptom.py b/care/facility/models/encounter_symptom.py index 9412927aff..f7b1d6dd63 100644 --- a/care/facility/models/encounter_symptom.py +++ b/care/facility/models/encounter_symptom.py @@ -83,7 +83,8 @@ class EncounterSymptom(BaseModel, ConsultationRelatedPermissionMixin): def save(self, *args, **kwargs): if self.other_symptom and self.symptom != Symptom.OTHERS: - raise ValueError("Other Symptom should be empty when Symptom is not OTHERS") + msg = "Other Symptom should be empty when Symptom is not OTHERS" + raise ValueError(msg) if self.clinical_impression_status != ClinicalImpressionStatus.ENTERED_IN_ERROR: if self.onset_date and self.cure_date: diff --git a/care/facility/models/events.py b/care/facility/models/events.py index 9b7fbfc56a..7499837138 100644 --- a/care/facility/models/events.py +++ b/care/facility/models/events.py @@ -31,19 +31,19 @@ class EventType(models.Model): created_date = models.DateTimeField(auto_now_add=True) is_active = models.BooleanField(default=True) - def get_descendants(self): - descendants = list(self.children.all()) - for child in self.children.all(): - descendants.extend(child.get_descendants()) - return descendants + def __str__(self) -> str: + return f"{self.model} - {self.name}" def save(self, *args, **kwargs): if self.description is not None and not self.description.strip(): self.description = None return super().save(*args, **kwargs) - def __str__(self) -> str: - return f"{self.model} - {self.name}" + def get_descendants(self): + descendants = list(self.children.all()) + for child in self.children.all(): + descendants.extend(child.get_descendants()) + return descendants class PatientConsultationEvent(models.Model): @@ -68,16 +68,9 @@ class PatientConsultationEvent(models.Model): max_length=10, choices=ChangeType, default=ChangeType.CREATED ) - def __str__(self) -> str: - return f"{self.id} - {self.consultation_id} - {self.event_type} - {self.change_type}" - class Meta: ordering = ["-created_date"] indexes = [models.Index(fields=["consultation", "is_latest"])] - # constraints = [ - # models.UniqueConstraint( - # fields=["consultation", "event_type", "is_latest"], - # condition=models.Q(is_latest=True), - # name="unique_consultation_event_type_is_latest", - # ) - # ] + + def __str__(self) -> str: + return f"{self.id} - {self.consultation_id} - {self.event_type} - {self.change_type}" diff --git a/care/facility/models/facility.py b/care/facility/models/facility.py index fcc2408114..e3593871b7 100644 --- a/care/facility/models/facility.py +++ b/care/facility/models/facility.py @@ -90,27 +90,27 @@ class FacilityFeature(models.IntegerChoices): (5, "Hotel"), (6, "Lodge"), (7, "TeleMedicine"), - # (8, "Govt Hospital"), # Change from "Govt Hospital" to "Govt Medical College Hospitals" + # 8, "Govt Hospital" # Change from "Govt Hospital" to "Govt Medical College Hospitals" (9, "Govt Labs"), (10, "Private Labs"), # Use 8xx for Govt owned hospitals and health centres (800, "Primary Health Centres"), - # (801, "24x7 Public Health Centres"), # Change from "24x7 Public Health Centres" to "Primary Health Centres" + # 801, "24x7 Public Health Centres" # Change from "24x7 Public Health Centres" to "Primary Health Centres" (802, "Family Health Centres"), (803, "Community Health Centres"), - # (820, "Urban Primary Health Center"), # Change from "Urban Primary Health Center" to "Primary Health Centres" + # 820, "Urban Primary Health Center" # Change from "Urban Primary Health Center" to "Primary Health Centres" (830, "Taluk Hospitals"), - # (831, "Taluk Headquarters Hospitals"), # Change from "Taluk Headquarters Hospitals" to "Taluk Hospitals" + # 831, "Taluk Headquarters Hospitals" # Change from "Taluk Headquarters Hospitals" to "Taluk Hospitals" (840, "Women and Child Health Centres"), - # (850, "General hospitals"), # Change from "General hospitals" to "District Hospitals" + # 850, "General hospitals" # Change from "General hospitals" to "District Hospitals" (860, "District Hospitals"), (870, "Govt Medical College Hospitals"), (900, "Co-operative hospitals"), (910, "Autonomous healthcare facility"), # Use 9xx for Labs - # (950, "Corona Testing Labs"), # Change from "Corona Testing Labs" to "Govt Labs" + # 950, "Corona Testing Labs" # Change from "Corona Testing Labs" to "Govt Labs" # Use 10xx for Corona Care Center - # (1000, "Corona Care Centre"), # Change from "Corona Care Centre" to "Other" + # 1000, "Corona Care Centre" # Change from "Corona Care Centre" to "Other" (1010, "COVID-19 Domiciliary Care Center"), # Use 11xx for First Line Treatment Centre (1100, "First Line Treatment Centre"), @@ -207,7 +207,8 @@ def check_if_spoke_is_not_ancestor(base_id: int, spoke_id: int): "hub_id", flat=True ) if spoke_id in ancestors_of_base: - raise serializers.ValidationError("This facility is already an ancestor hub") + msg = "This facility is already an ancestor hub" + raise serializers.ValidationError(msg) for ancestor in ancestors_of_base: check_if_spoke_is_not_ancestor(ancestor, spoke_id) diff --git a/care/facility/models/file_upload.py b/care/facility/models/file_upload.py index 4093e15e53..1176044635 100644 --- a/care/facility/models/file_upload.py +++ b/care/facility/models/file_upload.py @@ -46,10 +46,6 @@ class FileCategory(models.TextChoices): class Meta: abstract = True - def delete(self, *args): - self.deleted = True - self.save(update_fields=["deleted"]) - def save(self, *args, **kwargs): if "force_insert" in kwargs or (not self.internal_name): internal_name = str(uuid4()) + str(int(time.time())) @@ -60,6 +56,10 @@ def save(self, *args, **kwargs): self.internal_name = internal_name return super().save(*args, **kwargs) + def delete(self, *args): + self.deleted = True + self.save(update_fields=["deleted"]) + def get_extension(self): parts = self.internal_name.split(".") return f".{parts[-1]}" if len(parts) > 1 else "" @@ -67,7 +67,7 @@ def get_extension(self): def signed_url( self, duration=60 * 60, mime_type=None, bucket_type=BucketType.PATIENT ): - config, bucket_name = get_client_config(bucket_type, True) + config, bucket_name = get_client_config(bucket_type, external=True) s3 = boto3.client("s3", **config) params = { "Bucket": bucket_name, @@ -82,7 +82,7 @@ def signed_url( ) def read_signed_url(self, duration=60 * 60, bucket_type=BucketType.PATIENT): - config, bucket_name = get_client_config(bucket_type, True) + config, bucket_name = get_client_config(bucket_type, external=True) s3 = boto3.client("s3", **config) return s3.generate_presigned_url( "get_object", @@ -128,8 +128,6 @@ class FileUpload(BaseFileUpload): all data will be private and file access will be given on a NEED TO BASIS ONLY """ - # TODO : Periodic tasks that removes files that were never uploaded - class FileType(models.IntegerChoices): OTHER = 0, "OTHER" PATIENT = 1, "PATIENT" @@ -164,6 +162,9 @@ class FileType(models.IntegerChoices): FileTypeChoices = [(x.value, x.name) for x in FileType] FileCategoryChoices = [(x.value, x.name) for x in BaseFileUpload.FileCategory] + def __str__(self): + return f"{self.FileTypeChoices[self.file_type][1]} - {self.name}{' (Archived)' if self.is_archived else ''}" + def save(self, *args, **kwargs): from care.facility.models import PatientConsent @@ -192,7 +193,7 @@ def save(self, *args, **kwargs): ).exclude(pk=self.pk if self.is_archived else None) ) if not new_consent - else models.Value(True) + else models.Value(value=True) ) ) .filter(has_files=True) @@ -203,6 +204,3 @@ def save(self, *args, **kwargs): consultation.save() return super().save(*args, **kwargs) - - def __str__(self): - return f"{self.FileTypeChoices[self.file_type][1]} - {self.name}{' (Archived)' if self.is_archived else ''}" diff --git a/care/facility/models/json_schema/__init__.py b/care/facility/models/json_schema/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/care/facility/models/mixins/permissions/patient.py b/care/facility/models/mixins/permissions/patient.py index b814cde15a..82410aabf3 100644 --- a/care/facility/models/mixins/permissions/patient.py +++ b/care/facility/models/mixins/permissions/patient.py @@ -19,9 +19,9 @@ def has_object_read_permission(self, request): doctor_allowed = False if self.last_consultation: - doctor_allowed = ( - self.last_consultation.assigned_to == request.user - or request.user == self.assigned_to + doctor_allowed = request.user in ( + self.last_consultation.assigned_to, + self.assigned_to, ) return request.user.is_superuser or ( (hasattr(self, "created_by") and request.user == self.created_by) @@ -60,9 +60,9 @@ def has_object_write_permission(self, request): doctor_allowed = False if self.last_consultation: - doctor_allowed = ( - self.last_consultation.assigned_to == request.user - or request.user == self.assigned_to + doctor_allowed = request.user in ( + self.last_consultation.assigned_to, + self.assigned_to, ) return request.user.is_superuser or ( @@ -99,9 +99,9 @@ def has_object_update_permission(self, request): doctor_allowed = False if self.last_consultation: - doctor_allowed = ( - self.last_consultation.assigned_to == request.user - or request.user == self.assigned_to + doctor_allowed = request.user in ( + self.last_consultation.assigned_to, + self.assigned_to, ) return ( diff --git a/care/facility/models/patient.py b/care/facility/models/patient.py index f635a773d4..4f8d54c971 100644 --- a/care/facility/models/patient.py +++ b/care/facility/models/patient.py @@ -69,7 +69,7 @@ class SourceEnum(enum.Enum): SourceChoices = [(e.value, e.name) for e in SourceEnum] - class vaccineEnum(enum.Enum): + class VaccineEnum(enum.Enum): COVISHIELD = "CoviShield" COVAXIN = "Covaxin" SPUTNIK = "Sputnik" @@ -78,7 +78,7 @@ class vaccineEnum(enum.Enum): JANSSEN = "Janssen" SINOVAC = "Sinovac" - vaccineChoices = [(e.value, e.name) for e in vaccineEnum] + VaccineChoices = [(e.value, e.name) for e in VaccineEnum] class ActionEnum(enum.Enum): NO_ACTION = 10 @@ -116,12 +116,10 @@ class TestTypeEnum(enum.Enum): "PatientMetaInfo", on_delete=models.SET_NULL, null=True ) - # name_old = EncryptedCharField(max_length=200, default="") name = models.CharField(max_length=200, default="") gender = models.IntegerField(choices=GENDER_CHOICES, blank=False) - # phone_number_old = EncryptedCharField(max_length=14, validators=[phone_number_regex], default="") phone_number = models.CharField( max_length=14, validators=[mobile_or_landline_number_validator], default="" ) @@ -130,7 +128,6 @@ class TestTypeEnum(enum.Enum): max_length=14, validators=[mobile_or_landline_number_validator], default="" ) - # address_old = EncryptedTextField(default="") address = models.TextField(default="") permanent_address = models.TextField(default="") @@ -205,7 +202,7 @@ class TestTypeEnum(enum.Enum): blank=True, verbose_name="Already pescribed medication if any", ) - has_SARI = models.BooleanField( + has_SARI = models.BooleanField( # noqa: N815 default=False, verbose_name="Does the Patient Suffer from SARI" ) @@ -383,7 +380,7 @@ class TestTypeEnum(enum.Enum): validators=[MinValueValidator(0), MaxValueValidator(3)], ) vaccine_name = models.CharField( - choices=vaccineChoices, + choices=VaccineChoices, default=None, null=True, blank=False, @@ -487,19 +484,17 @@ def get_age(self) -> str: year_str = f"{delta.years} year{pluralize(delta.years)}" return f"{year_str}" - elif delta.months > 0: + if delta.months > 0: month_str = f"{delta.months} month{pluralize(delta.months)}" day_str = ( f" {delta.days} day{pluralize(delta.days)}" if delta.days > 0 else "" ) return f"{month_str}{day_str}" - elif delta.days > 0: - day_str = f"{delta.days} day{pluralize(delta.days)}" - return day_str + if delta.days > 0: + return f"{delta.days} day{pluralize(delta.days)}" - else: - return "0 days" + return "0 days" def annotate_diagnosis_ids(*args, **kwargs): return ArrayAgg( @@ -552,14 +547,14 @@ def annotate_diagnosis_ids(*args, **kwargs): "last_consultation__discharge_date__time": "Time of discharge", } - def format_as_date(date): - return date.strftime("%d/%m/%Y") + def format_as_date(self): + return self.strftime("%d/%m/%Y") - def format_as_time(time): - return time.strftime("%H:%M") + def format_as_time(self): + return self.strftime("%H:%M") - def format_diagnoses(diagnosis_ids): - diagnoses = get_icd11_diagnoses_objects_by_ids(diagnosis_ids) + def format_diagnoses(self): + diagnoses = get_icd11_diagnoses_objects_by_ids(self) return ", ".join([diagnosis["label"] for diagnosis in diagnoses]) CSV_MAKE_PRETTY = { @@ -645,6 +640,9 @@ class DomesticHealthcareSupport(models.IntegerChoices): ) head_of_household = models.BooleanField(blank=True, null=True) + def __str__(self): + return f"PatientMetaInfo - {self.id}" + class PatientContactDetails(models.Model): class RelationEnum(enum.IntEnum): @@ -660,25 +658,23 @@ class RelationEnum(enum.IntEnum): OTHERS = 10 class ModeOfContactEnum(enum.IntEnum): - # "1. Touched body fluids of the patient (respiratory tract secretions/blood/vomit/saliva/urine/faces)" + # Touched body fluids of the patient (respiratory tract secretions/blood/vomit/saliva/urine/faces) TOUCHED_BODY_FLUIDS = 1 - # "2. Had direct physical contact with the body of the patient - # including physical examination without full precautions." + # Had direct physical contact with the body of the patient including physical examination without full precautions. DIRECT_PHYSICAL_CONTACT = 2 - # "3. Touched or cleaned the linens/clothes/or dishes of the patient" + # Touched or cleaned the linens/clothes/or dishes of the patient CLEANED_USED_ITEMS = 3 - # "4. Lives in the same household as the patient." + # Lives in the same household as the patient. LIVE_IN_SAME_HOUSEHOLD = 4 - # "5. Close contact within 3ft (1m) of the confirmed case without precautions." + # Close contact within 3ft (1m) of the confirmed case without precautions. CLOSE_CONTACT_WITHOUT_PRECAUTION = 5 - # "6. Passenger of the aeroplane with a confirmed COVID -19 passenger for more than 6 hours." + # Passenger of the aeroplane with a confirmed COVID -19 passenger for more than 6 hours. CO_PASSENGER_AEROPLANE = 6 - # "7. Health care workers and other contacts who had full PPE while handling the +ve case" + # Health care workers and other contacts who had full PPE while handling the +ve case HEALTH_CARE_WITH_PPE = 7 - # "8. Shared the same space(same class for school/worked in - # same room/similar and not having a high risk exposure" + # Shared the same space(same class for school/worked in same room/similar and not having a high risk exposure SHARED_SAME_SPACE_WITHOUT_HIGH_EXPOSURE = 8 - # "9. Travel in the same environment (bus/train/Flight) but not having a high-risk exposure as cited above." + # Travel in the same environment (bus/train/Flight) but not having a high-risk exposure as cited above. TRAVELLED_TOGETHER_WITHOUT_HIGH_EXPOSURE = 9 RelationChoices = [(item.value, item.name) for item in RelationEnum] @@ -709,6 +705,9 @@ class ModeOfContactEnum(enum.IntEnum): objects = BaseManager() + def __str__(self): + return f"{self.patient.name} - {self.patient_in_contact.name} - {self.get_relation_with_patient_display()}" + class Disease(models.Model): patient = models.ForeignKey( @@ -833,6 +832,9 @@ class PatientNotesEdit(models.Model): class Meta: ordering = ["-edited_date"] + def __str__(self): + return f"PatientNotesEdit {self.patient_note} - {self.edited_by}" + class PatientAgeFunc(Func): """ diff --git a/care/facility/models/patient_consultation.py b/care/facility/models/patient_consultation.py index bf241779a0..f21d4f6a4d 100644 --- a/care/facility/models/patient_consultation.py +++ b/care/facility/models/patient_consultation.py @@ -247,15 +247,6 @@ def get_related_consultation(self): ), } - # CSV_DATATYPE_DEFAULT_MAPPING = { - # "encounter_date": (None, models.DateTimeField(),), - # "deprecated_symptoms_onset_date": (None, models.DateTimeField(),), - # "deprecated_symptoms": ("-", models.CharField(),), - # "category": ("-", models.CharField(),), - # "examination_details": ("-", models.CharField(),), - # "suggestion": ("-", models.CharField(),), - # } - def __str__(self): return f"{self.patient.name}<>{self.facility.name}" @@ -271,7 +262,7 @@ def save(self, *args, **kwargs): if self.death_datetime and self.patient.death_datetime != self.death_datetime: self.patient.death_datetime = self.death_datetime self.patient.save(update_fields=["death_datetime"]) - super(PatientConsultation, self).save(*args, **kwargs) + super().save(*args, **kwargs) class Meta: constraints = [ @@ -299,10 +290,7 @@ def has_object_read_permission(self, request): self.patient.facility and request.user in self.patient.facility.users.all() ) - or ( - self.assigned_to == request.user - or request.user == self.patient.assigned_to - ) + or (request.user in (self.assigned_to, self.patient.assigned_to)) or ( request.user.user_type >= User.TYPE_VALUE_MAP["DistrictLabAdmin"] and ( @@ -352,6 +340,9 @@ class ConsultationClinician(models.Model): on_delete=models.PROTECT, ) + def __str__(self): + return f"ConsultationClinician {self.consultation} - {self.clinician}" + class PatientConsent(BaseModel, ConsultationRelatedPermissionMixin): consultation = models.ForeignKey( @@ -433,8 +424,11 @@ def has_object_read_permission(self, request): and request.user in self.consultation.patient.facility.users.all() ) or ( - self.consultation.assigned_to == request.user - or request.user == self.consultation.patient.assigned_to + request.user + in ( + self.consultation.assigned_to, + self.consultation.patient.assigned_to, + ) ) or ( request.user.user_type >= User.TYPE_VALUE_MAP["DistrictLabAdmin"] diff --git a/care/facility/models/patient_external_test.py b/care/facility/models/patient_external_test.py index 297ccbfd63..3d7ebfb292 100644 --- a/care/facility/models/patient_external_test.py +++ b/care/facility/models/patient_external_test.py @@ -79,7 +79,6 @@ class PatientExternalTest(FacilityBaseModel): "result": "Final Result", "sample_collection_date": "Sample Collection Date", "source": "Source", - # "result_date": "", } def __str__(self): diff --git a/care/facility/models/patient_icmr.py b/care/facility/models/patient_icmr.py index e6f06da451..23c78a7f4e 100644 --- a/care/facility/models/patient_icmr.py +++ b/care/facility/models/patient_icmr.py @@ -1,7 +1,6 @@ -import datetime - from dateutil.relativedelta import relativedelta from django.utils import timezone +from django.utils.timezone import now from care.facility.models import ( DISEASE_CHOICES_MAP, @@ -18,35 +17,6 @@ class PatientIcmr(PatientRegistration): class Meta: proxy = True - # @property - # def personal_details(self): - # return self - - # @property - # def specimen_details(self): - # instance = self.patientsample_set.last() - # if instance is not None: - # instance.__class__ = PatientSampleICMR - # return instance - - # @property - # def patient_category(self): - # instance = self.consultations.last() - # if instance: - # instance.__class__ = PatientConsultationICMR - # return instance - - # @property - # def exposure_history(self): - # return self - - # @property - # def medical_conditions(self): - # instance = self.patientsample_set.last() - # if instance is not None: - # instance.__class__ = PatientSampleICMR - # return instance - def get_age_delta(self): start = self.date_of_birth or timezone.datetime(self.year_of_birth, 1, 1).date() end = (self.death_datetime or timezone.now()).date() @@ -78,12 +48,14 @@ def state_name(self): @property def has_travel_to_foreign_last_14_days(self): + unsafe_travel_days = 14 if self.countries_travelled: return len(self.countries_travelled) != 0 and ( self.date_of_return - and (self.date_of_return.date() - datetime.datetime.now().date()).days - <= 14 + and (self.date_of_return.date() - now().date()).days + <= unsafe_travel_days ) + return None @property def travel_end_date(self): @@ -201,6 +173,7 @@ def symptoms(self): def date_of_onset_of_symptoms(self): if symptom := self.consultation.symptoms.first(): return symptom.onset_date.date() + return None class PatientConsultationICMR(PatientConsultation): @@ -208,26 +181,22 @@ class Meta: proxy = True def is_symptomatic(self): - if ( - SYMPTOM_CHOICES[0][0] not in self.symptoms.choices.keys() + return bool( + SYMPTOM_CHOICES[0][0] not in self.symptoms.choices or self.symptoms_onset_date is not None - ): - return True - else: - return False + ) def symptomatic_international_traveller( self, ): + unsafe_travel_days = 14 return bool( self.patient.countries_travelled and len(self.patient.countries_travelled) != 0 and ( self.patient.date_of_return - and ( - self.patient.date_of_return.date() - datetime.datetime.now().date() - ).days - <= 14 + and (self.patient.date_of_return.date() - now().date()).days + <= unsafe_travel_days ) and self.is_symptomatic() ) diff --git a/care/facility/models/summary.py b/care/facility/models/summary.py index 5579bc564d..2cd1071bad 100644 --- a/care/facility/models/summary.py +++ b/care/facility/models/summary.py @@ -44,6 +44,9 @@ class Meta: models.Index(fields=["-created_date", "s_type"]), ] + def __str__(self): + return f"FacilityRelatedSummary - {self.facility} - {self.s_type}" + DISTRICT_SUMMARY_CHOICES = (("PatientSummary", "PatientSummary"),) @@ -78,6 +81,9 @@ class Meta: models.Index(fields=["-created_date", "s_type"]), ] + def __str__(self): + return f"DistrictScopedSummary - {self.district} - {self.s_type}" + LSG_SUMMARY_CHOICES = (("PatientSummary", "PatientSummary"),) @@ -109,3 +115,6 @@ class Meta: ), models.Index(fields=["-created_date", "s_type"]), ] + + def __str__(self): + return f"LocalBodyScopedSummary - {self.lsg} - {self.s_type}" diff --git a/care/facility/models/tests/__init__.py b/care/facility/models/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2