Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

archived spo2 field to archived_spo2 #2397

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 81 additions & 65 deletions care/abdm/utils/fhir.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
),
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved
)

self._procedure_profiles.append(procedure_profile)
Expand All @@ -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),
Expand Down Expand Up @@ -260,36 +262,44 @@ 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 (type(value) is 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 type(value) is dict
else None
),
valueString=value if type(value) is 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) is dict
else None
),
valueString=component if type(component) is str else None,
),
value,
)
)
)
if type(value) == list
else None,
if type(value) is list
else None
),
)

def _observations_from_daily_round(self, daily_round):
Expand All @@ -304,7 +314,7 @@ def _observations_from_daily_round(self, daily_round):
),
self._observation(
"SpO2",
{"value": daily_round.spo2, "unit": "%"},
{"value": daily_round.archived_spo2, "unit": "%"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{"value": daily_round.archived_spo2, "unit": "%"},
{"value": daily_round.ventilator_spo2, "unit": "%"},

we should use ventilator_spo2 in place of the unused field

cc: @khavinshankar

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes 👍

id,
date,
),
Expand All @@ -322,20 +332,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,
),
Expand Down Expand Up @@ -369,21 +381,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
),
}
)

Expand Down Expand Up @@ -655,10 +669,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")]
)
),
),
],
Expand Down
2 changes: 1 addition & 1 deletion care/facility/management/commands/load_event_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Command(BaseCommand):
"name": "VITALS",
"children": (
{"name": "TEMPERATURE", "fields": ("temperature",)},
{"name": "SPO2", "fields": ("spo2",)},
{"name": "SPO2", "fields": ("archived_spo2",)},
Copy link
Member

@sainak sainak Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{"name": "SPO2", "fields": ("archived_spo2",)},

we can drop this category, add it to the inactive types list

{"name": "PULSE", "fields": ("pulse",)},
{"name": "BLOOD_PRESSURE", "fields": ("bp",)},
{"name": "RESPIRATORY_RATE", "fields": ("resp",)},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.10 on 2024-08-26 06:54

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("facility", "0453_merge_20240824_2040"),
]

operations = [
migrations.RenameField(
model_name="dailyround",
old_name="spo2",
new_name="archived_spo2",
),
]
4 changes: 2 additions & 2 deletions care/facility/models/daily_round.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ class InsulinIntakeFrequencyType(enum.Enum):
null=True,
validators=[MinValueValidator(95), MaxValueValidator(106)],
)
spo2 = models.DecimalField(
archived_spo2 = models.DecimalField(
max_digits=4, decimal_places=2, blank=True, null=True, default=None
)
) # Deprecated
physical_examination_info = models.TextField(null=True, blank=True)
deprecated_covid_category = models.CharField(
choices=COVID_CATEGORY_CHOICES,
Expand Down