From 30395b69926c13ccda4b60b88dd8fbed53d00708 Mon Sep 17 00:00:00 2001
From: Aakash Singh <mail@singhaakash.dev>
Date: Thu, 19 Sep 2024 23:15:08 +0530
Subject: [PATCH] lint all files (#2468)

---
 care/abdm/utils/fhir.py                       | 146 ++++++++++--------
 .../0003_set_site_domain_and_name.py          |   1 +
 .../api/serializers/patient_sample.py         |   8 +-
 .../migrations/0439_encounter_symptoms.py     |  16 +-
 care/facility/models/patient_external_test.py |   2 +-
 .../utils/summarisation/facility_capacity.py  |   6 +-
 .../utils/summarisation/tests_summary.py      |   6 +-
 care/hcx/utils/hcx/__init__.py                |   6 +-
 .../commands/populate_investigations.py       |  16 +-
 config/asgi.py                                |   1 +
 config/wsgi.py                                |   1 +
 locale/hi/LC_MESSAGES/django.po               |   1 -
 locale/kn/LC_MESSAGES/django.po               |   1 -
 locale/ml/LC_MESSAGES/django.po               |   1 -
 locale/ta/LC_MESSAGES/django.po               |   1 -
 15 files changed, 120 insertions(+), 93 deletions(-)

diff --git a/care/abdm/utils/fhir.py b/care/abdm/utils/fhir.py
index d862f079fe..c0eaa47a57 100644
--- a/care/abdm/utils/fhir.py
+++ b/care/abdm/utils/fhir.py
@@ -190,12 +190,12 @@ def _procedure(self, procedure):
                 text=procedure["procedure"],
             ),
             subject=self._reference(self._patient()),
-            performedDateTime=f"{procedure['time']}:00+05:30"
-            if not procedure["repetitive"]
-            else None,
-            performedString=f"Every {procedure['frequency']}"
-            if procedure["repetitive"]
-            else None,
+            performedDateTime=(
+                f"{procedure['time']}:00+05:30" if not procedure["repetitive"] else None
+            ),
+            performedString=(
+                f"Every {procedure['frequency']}" if procedure["repetitive"] else None
+            ),
         )
 
         self._procedure_profiles.append(procedure_profile)
@@ -213,9 +213,11 @@ def _careplan(self):
             description="This includes Treatment Summary, Prescribed Medication, General Notes and Special Instructions",
             period=Period(
                 start=self.consultation.encounter_date.isoformat(),
-                end=self.consultation.discharge_date.isoformat()
-                if self.consultation.discharge_date
-                else None,
+                end=(
+                    self.consultation.discharge_date.isoformat()
+                    if self.consultation.discharge_date
+                    else None
+                ),
             ),
             note=[
                 Annotation(text=self.consultation.treatment_plan),
@@ -260,36 +262,46 @@ def _diagnostic_report(self):
         return self._diagnostic_report_profile
 
     def _observation(self, title, value, id, date):
-        if not value or (type(value) == dict and not value["value"]):
+        if not value or (isinstance(value, dict) and not value["value"]):
             return
 
         return Observation(
-            id=f"{id}.{title.replace(' ', '').replace('_', '-')}"
-            if id and title
-            else str(uuid()),
+            id=(
+                f"{id}.{title.replace(' ', '').replace('_', '-')}"
+                if id and title
+                else str(uuid())
+            ),
             status="final",
             effectiveDateTime=date if date else None,
             code=CodeableConcept(text=title),
-            valueQuantity=Quantity(value=str(value["value"]), unit=value["unit"])
-            if type(value) == dict
-            else None,
-            valueString=value if type(value) == str else None,
-            component=list(
-                map(
-                    lambda component: ObservationComponent(
-                        code=CodeableConcept(text=component["title"]),
-                        valueQuantity=Quantity(
-                            value=component["value"], unit=component["unit"]
-                        )
-                        if type(component) == dict
-                        else None,
-                        valueString=component if type(component) == str else None,
-                    ),
-                    value,
+            valueQuantity=(
+                Quantity(value=str(value["value"]), unit=value["unit"])
+                if isinstance(value, dict)
+                else None
+            ),
+            valueString=value if isinstance(value, str) else None,
+            component=(
+                list(
+                    map(
+                        lambda component: ObservationComponent(
+                            code=CodeableConcept(text=component["title"]),
+                            valueQuantity=(
+                                Quantity(
+                                    value=component["value"], unit=component["unit"]
+                                )
+                                if isinstance(component, dict)
+                                else None
+                            ),
+                            valueString=(
+                                component if isinstance(component, str) else None
+                            ),
+                        ),
+                        value,
+                    )
                 )
-            )
-            if type(value) == list
-            else None,
+                if isinstance(value, list)
+                else None
+            ),
         )
 
     def _observations_from_daily_round(self, daily_round):
@@ -322,20 +334,22 @@ def _observations_from_daily_round(self, daily_round):
             ),
             self._observation(
                 "Blood Pressure",
-                [
-                    {
-                        "title": "Systolic Blood Pressure",
-                        "value": daily_round.bp["systolic"],
-                        "unit": "mmHg",
-                    },
-                    {
-                        "title": "Diastolic Blood Pressure",
-                        "value": daily_round.bp["diastolic"],
-                        "unit": "mmHg",
-                    },
-                ]
-                if "systolic" in daily_round.bp and "diastolic" in daily_round.bp
-                else None,
+                (
+                    [
+                        {
+                            "title": "Systolic Blood Pressure",
+                            "value": daily_round.bp["systolic"],
+                            "unit": "mmHg",
+                        },
+                        {
+                            "title": "Diastolic Blood Pressure",
+                            "value": daily_round.bp["diastolic"],
+                            "unit": "mmHg",
+                        },
+                    ]
+                    if "systolic" in daily_round.bp and "diastolic" in daily_round.bp
+                    else None
+                ),
                 id,
                 date,
             ),
@@ -369,21 +383,23 @@ def _encounter(self, include_diagnosis=False):
                 "class": Coding(code="IMP", display="Inpatient Encounter"),
                 "subject": self._reference(self._patient()),
                 "period": Period(start=period_start, end=period_end),
-                "diagnosis": list(
-                    map(
-                        lambda consultation_diagnosis: EncounterDiagnosis(
-                            condition=self._reference(
-                                self._condition(
-                                    consultation_diagnosis.diagnosis_id,
-                                    consultation_diagnosis.verification_status,
-                                ),
-                            )
-                        ),
-                        self.consultation.diagnoses.all(),
+                "diagnosis": (
+                    list(
+                        map(
+                            lambda consultation_diagnosis: EncounterDiagnosis(
+                                condition=self._reference(
+                                    self._condition(
+                                        consultation_diagnosis.diagnosis_id,
+                                        consultation_diagnosis.verification_status,
+                                    ),
+                                )
+                            ),
+                            self.consultation.diagnoses.all(),
+                        )
                     )
-                )
-                if include_diagnosis
-                else None,
+                    if include_diagnosis
+                    else None
+                ),
             }
         )
 
@@ -655,10 +671,12 @@ def _immunization_composition(self):
                             else []
                         )
                     ],
-                    emptyReason=None
-                    if self._immunization()
-                    else CodeableConcept(
-                        coding=[Coding(code="notasked", display="Not Asked")]
+                    emptyReason=(
+                        None
+                        if self._immunization()
+                        else CodeableConcept(
+                            coding=[Coding(code="notasked", display="Not Asked")]
+                        )
                     ),
                 ),
             ],
diff --git a/care/contrib/sites/migrations/0003_set_site_domain_and_name.py b/care/contrib/sites/migrations/0003_set_site_domain_and_name.py
index d1473c9d6c..2078c433f6 100644
--- a/care/contrib/sites/migrations/0003_set_site_domain_and_name.py
+++ b/care/contrib/sites/migrations/0003_set_site_domain_and_name.py
@@ -3,6 +3,7 @@
 
 http://cookiecutter-django.readthedocs.io/en/latest/faq.html#why-is-there-a-django-contrib-sites-directory-in-cookiecutter-django
 """
+
 from django.conf import settings
 from django.db import migrations
 
diff --git a/care/facility/api/serializers/patient_sample.py b/care/facility/api/serializers/patient_sample.py
index 2308dcac1b..261d4f9ca3 100644
--- a/care/facility/api/serializers/patient_sample.py
+++ b/care/facility/api/serializers/patient_sample.py
@@ -108,9 +108,11 @@ def update(self, instance, validated_data):
             is_completed = validated_data.get("result") in [1, 2]
             new_status = validated_data.get(
                 "status",
-                PatientSample.SAMPLE_TEST_FLOW_MAP["COMPLETED"]
-                if is_completed
-                else None,
+                (
+                    PatientSample.SAMPLE_TEST_FLOW_MAP["COMPLETED"]
+                    if is_completed
+                    else None
+                ),
             )
             choice = PatientSample.SAMPLE_TEST_FLOW_CHOICES[new_status - 1][1]
             if is_completed:
diff --git a/care/facility/migrations/0439_encounter_symptoms.py b/care/facility/migrations/0439_encounter_symptoms.py
index 67f9b17f45..8982cae5d9 100644
--- a/care/facility/migrations/0439_encounter_symptoms.py
+++ b/care/facility/migrations/0439_encounter_symptoms.py
@@ -39,9 +39,11 @@ def backfill_symptoms_table(apps, schema_editor):
                     bulk.append(
                         EncounterSymptom(
                             symptom=symptom_id,
-                            other_symptom=consultation.deprecated_other_symptoms
-                            if symptom_id == 9  # Other symptom
-                            else "",
+                            other_symptom=(
+                                consultation.deprecated_other_symptoms
+                                if symptom_id == 9  # Other symptom
+                                else ""
+                            ),
                             onset_date=consultation.deprecated_symptoms_onset_date
                             or consultation.encounter_date,
                             created_date=consultation.created_date,
@@ -85,9 +87,11 @@ def backfill_symptoms_table(apps, schema_editor):
                         bulk.append(
                             EncounterSymptom(
                                 symptom=symptom_id,
-                                other_symptom=daily_round.deprecated_other_symptoms
-                                if symptom_id == 9  # Other symptom
-                                else "",
+                                other_symptom=(
+                                    daily_round.deprecated_other_symptoms
+                                    if symptom_id == 9  # Other symptom
+                                    else ""
+                                ),
                                 onset_date=daily_round.created_date,
                                 created_date=daily_round.created_date,
                                 created_by=daily_round.created_by,
diff --git a/care/facility/models/patient_external_test.py b/care/facility/models/patient_external_test.py
index 1e13c8f5c2..297ccbfd63 100644
--- a/care/facility/models/patient_external_test.py
+++ b/care/facility/models/patient_external_test.py
@@ -78,7 +78,7 @@ class PatientExternalTest(FacilityBaseModel):
         "sample_type": "Sample Type",
         "result": "Final Result",
         "sample_collection_date": "Sample Collection Date",
-        "source": "Source"
+        "source": "Source",
         # "result_date": "",
     }
 
diff --git a/care/facility/utils/summarisation/facility_capacity.py b/care/facility/utils/summarisation/facility_capacity.py
index 63548b9c3c..a41ef71ec9 100644
--- a/care/facility/utils/summarisation/facility_capacity.py
+++ b/care/facility/utils/summarisation/facility_capacity.py
@@ -30,9 +30,9 @@ def facility_capacity_summary():
         capacity_summary[facility_obj.id]["features"] = list(
             capacity_summary[facility_obj.id]["features"]
         )
-        capacity_summary[facility_obj.id][
-            "actual_live_patients"
-        ] = patients_in_facility.filter(is_active=True).count()
+        capacity_summary[facility_obj.id]["actual_live_patients"] = (
+            patients_in_facility.filter(is_active=True).count()
+        )
         discharge_patients = patients_in_facility.filter(is_active=False)
         capacity_summary[facility_obj.id][
             "actual_discharged_patients"
diff --git a/care/facility/utils/summarisation/tests_summary.py b/care/facility/utils/summarisation/tests_summary.py
index 4854a8fa5d..a9da8c8a61 100644
--- a/care/facility/utils/summarisation/tests_summary.py
+++ b/care/facility/utils/summarisation/tests_summary.py
@@ -48,9 +48,9 @@ def tests_summary():
             if facility_test_summary.data != facility_tests_summarised_data:
                 facility_test_summary.data = facility_tests_summarised_data
                 latest_modification_date = timezone.now()
-                facility_test_summary.data[
-                    "modified_date"
-                ] = latest_modification_date.strftime("%d-%m-%Y %H:%M")
+                facility_test_summary.data["modified_date"] = (
+                    latest_modification_date.strftime("%d-%m-%Y %H:%M")
+                )
                 facility_test_summary.save()
         except ObjectDoesNotExist:
             modified_date = timezone.now()
diff --git a/care/hcx/utils/hcx/__init__.py b/care/hcx/utils/hcx/__init__.py
index 533e0a9bbc..17207ff45d 100644
--- a/care/hcx/utils/hcx/__init__.py
+++ b/care/hcx/utils/hcx/__init__.py
@@ -70,9 +70,9 @@ def createHeaders(self, recipientCode=None, correlationId=None):
             .replace(microsecond=0)
             .isoformat(),
             "x-hcx-sender_code": self.participantCode,
-            "x-hcx-correlation_id": correlationId
-            if correlationId
-            else str(uuid.uuid4()),
+            "x-hcx-correlation_id": (
+                correlationId if correlationId else str(uuid.uuid4())
+            ),
             # "x-hcx-workflow_id": str(uuid.uuid4()),
             "x-hcx-api_call_id": str(uuid.uuid4()),
             # "x-hcx-status": "response.complete",
diff --git a/care/users/management/commands/populate_investigations.py b/care/users/management/commands/populate_investigations.py
index 21847ee190..39b2162913 100644
--- a/care/users/management/commands/populate_investigations.py
+++ b/care/users/management/commands/populate_investigations.py
@@ -47,12 +47,16 @@ def handle(self, *args, **options):
                 "name": investigation["name"],
                 "unit": investigation.get("unit", ""),
                 "ideal_value": investigation.get("ideal_value", ""),
-                "min_value": None
-                if investigation.get("min_value") is None
-                else float(investigation.get("min_value")),
-                "max_value": None
-                if investigation.get("max_value") is None
-                else float(investigation.get("max_value")),
+                "min_value": (
+                    None
+                    if investigation.get("min_value") is None
+                    else float(investigation.get("min_value"))
+                ),
+                "max_value": (
+                    None
+                    if investigation.get("max_value") is None
+                    else float(investigation.get("max_value"))
+                ),
                 "investigation_type": investigation["type"],
                 "choices": investigation.get("choices", ""),
             }
diff --git a/config/asgi.py b/config/asgi.py
index 724751777f..156e6f0e37 100644
--- a/config/asgi.py
+++ b/config/asgi.py
@@ -7,6 +7,7 @@
 https://docs.djangoproject.com/en/dev/howto/deployment/asgi/
 
 """
+
 import os
 import sys
 from pathlib import Path
diff --git a/config/wsgi.py b/config/wsgi.py
index 835d5c2ece..c9f43409b4 100644
--- a/config/wsgi.py
+++ b/config/wsgi.py
@@ -13,6 +13,7 @@
 framework.
 
 """
+
 import os
 import sys
 from pathlib import Path
diff --git a/locale/hi/LC_MESSAGES/django.po b/locale/hi/LC_MESSAGES/django.po
index a63e6bcfa7..5117bd02bc 100644
--- a/locale/hi/LC_MESSAGES/django.po
+++ b/locale/hi/LC_MESSAGES/django.po
@@ -230,4 +230,3 @@ msgstr "आपके पासवर्ड में कम से कम 1 प
 #: config/validators.py:66
 msgid "The domain name is invalid. It should not start with scheme and should not end with a trailing slash."
 msgstr "डोमेन नाम अमान्य है। इसे स्कीम से शुरू नहीं करना चाहिए और अंत में स्लैश से नहीं होना चाहिए।"
-
diff --git a/locale/kn/LC_MESSAGES/django.po b/locale/kn/LC_MESSAGES/django.po
index 39aa3fc1df..46a9b390b2 100644
--- a/locale/kn/LC_MESSAGES/django.po
+++ b/locale/kn/LC_MESSAGES/django.po
@@ -230,4 +230,3 @@ msgstr "ನಿಮ್ಮ ಪಾಸ್‌ವರ್ಡ್ ಕನಿಷ್ಠ 1 ಚ
 #: config/validators.py:66
 msgid "The domain name is invalid. It should not start with scheme and should not end with a trailing slash."
 msgstr "ಡೊಮೇನ್ ಹೆಸರು ಅಮಾನ್ಯವಾಗಿದೆ. ಇದು ಸ್ಕೀಮ್‌ನೊಂದಿಗೆ ಪ್ರಾರಂಭವಾಗಬಾರದು ಮತ್ತು ಟ್ರೇಲಿಂಗ್ ಸ್ಲ್ಯಾಷ್‌ನೊಂದಿಗೆ ಕೊನೆಗೊಳ್ಳಬಾರದು."
-
diff --git a/locale/ml/LC_MESSAGES/django.po b/locale/ml/LC_MESSAGES/django.po
index 5b0e3c8386..048485bd7b 100644
--- a/locale/ml/LC_MESSAGES/django.po
+++ b/locale/ml/LC_MESSAGES/django.po
@@ -230,4 +230,3 @@ msgstr "നിങ്ങളുടെ പാസ്‌വേഡിൽ കുറഞ
 #: config/validators.py:66
 msgid "The domain name is invalid. It should not start with scheme and should not end with a trailing slash."
 msgstr "ഡൊമെയ്ൻ നാമം അസാധുവാണ്. ഇത് സ്കീമിൽ ആരംഭിക്കരുത്, ഒരു ട്രെയിലിംഗ് സ്ലാഷിൽ അവസാനിക്കരുത്."
-
diff --git a/locale/ta/LC_MESSAGES/django.po b/locale/ta/LC_MESSAGES/django.po
index e1ff832ea4..60e1f4946f 100644
--- a/locale/ta/LC_MESSAGES/django.po
+++ b/locale/ta/LC_MESSAGES/django.po
@@ -230,4 +230,3 @@ msgstr "உங்கள் கடவுச்சொல்லில் குற
 #: config/validators.py:66
 msgid "The domain name is invalid. It should not start with scheme and should not end with a trailing slash."
 msgstr "டொமைன் பெயர் தவறானது. இது திட்டத்துடன் தொடங்கக்கூடாது மற்றும் பின்னோக்கி சாய்வுடன் முடிவடையக்கூடாது."
-