Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
"resolved": "Resolved",
}

CATEGORY_DISPLAY = {
"food": "Food",
"medication": "Medication",
"environment": "Environment",
"biologic": "Biologic",
}

VERIFICATION_STATUS_DISPLAY = {
"unconfirmed": "Unconfirmed",
"confirmed": "Confirmed",
Expand All @@ -26,6 +33,11 @@
"unable_to_assess": "Unable to Assess",
}

ALLERGY_INTOLERANCE_TYPE_DISPLAY = {
"allergy": "Allergy",
"intolerance": "Intolerance",
}


class AllergyIntoleranceReportFilter(filters.FilterSet):
clinical_status = MultiSelectFilter(field_name="clinical_status")
Expand All @@ -45,29 +57,41 @@ class AllergyIntoleranceContextBuilder(QuerysetContextBuilder):
clinical_status = Field(
display="Clinical Status",
preview_value="Active",
mapping=lambda a: CLINICAL_STATUS_DISPLAY.get(
a.clinical_status, a.clinical_status.title()
)
if a.clinical_status
else "",
mapping=lambda a: (
CLINICAL_STATUS_DISPLAY.get(a.clinical_status, a.clinical_status.title())
if a.clinical_status
else ""
),
description="Clinical status of the allergy or intolerance",
)
category = Field(
display="Category",
preview_value="Food",
mapping=lambda a: (
CATEGORY_DISPLAY.get(a.category, a.category.title()) if a.category else ""
),
description="Category of the allergy or intolerance",
)
verification_status = Field(
display="Verification Status",
preview_value="Confirmed",
mapping=lambda a: VERIFICATION_STATUS_DISPLAY.get(
a.verification_status, a.verification_status.title()
)
if a.verification_status
else "",
mapping=lambda a: (
VERIFICATION_STATUS_DISPLAY.get(
a.verification_status, a.verification_status.title()
)
if a.verification_status
else ""
),
description="Verification status of the allergy or intolerance",
)
criticality = Field(
display="Criticality",
preview_value="High",
mapping=lambda a: CRITICALITY_DISPLAY.get(a.criticality, a.criticality.title())
if a.criticality
else "",
mapping=lambda a: (
CRITICALITY_DISPLAY.get(a.criticality, a.criticality.title())
if a.criticality
else ""
),
description="Criticality of the allergy or intolerance",
)
name = Field(
Expand All @@ -86,6 +110,17 @@ class AllergyIntoleranceContextBuilder(QuerysetContextBuilder):
preview_value="2025-12-03 12:09:13.880000+00:00",
description="The last occurrence date and time of the allergy or intolerance",
)
allergy_intolerance_type = Field(
display="Allergy Intolerance Type",
preview_value="Allergy",
mapping=lambda a: (
ALLERGY_INTOLERANCE_TYPE_DISPLAY.get(
a.allergy_intolerance_type, a.allergy_intolerance_type.title()
)
if a.allergy_intolerance_type
else ""
),
)

def get_context(self):
return AllergyIntolerance.objects.filter(encounter=self.parent_context)
34 changes: 24 additions & 10 deletions care/emr/reports/context_builder/data_points/diagnosis.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
"unknown": "Unknown",
}

SEVERITY_DISPLAY = {
"mild": "Mild",
"moderate": "Moderate",
"severe": "Severe",
}

VERIFICATION_STATUS_DISPLAY = {
"unconfirmed": "Unconfirmed",
"provisional": "Provisional",
Expand Down Expand Up @@ -46,21 +52,29 @@ class DiagnosisContextBuilder(QuerysetContextBuilder):
clinical_status = Field(
display="Clinical Status",
preview_value="Active",
mapping=lambda c: CLINICAL_STATUS_DISPLAY.get(
c.clinical_status, c.clinical_status.title()
)
if c.clinical_status
else "",
mapping=lambda c: (
CLINICAL_STATUS_DISPLAY.get(c.clinical_status, c.clinical_status.title())
if c.clinical_status
else ""
),
description="Clinical status of the condition",
)
severity = Field(
display="Severity",
preview_value="Mild",
mapping=lambda c: SEVERITY_DISPLAY.get(c.severity, c.severity.title()),
description="Severity of the diagnosis",
Comment thread
rithviknishad marked this conversation as resolved.
Outdated
Comment thread
coderabbitai[bot] marked this conversation as resolved.
)
verification_status = Field(
display="Verification Status",
preview_value="Confirmed",
mapping=lambda c: VERIFICATION_STATUS_DISPLAY.get(
c.verification_status, c.verification_status.title()
)
if c.verification_status
else "",
mapping=lambda c: (
VERIFICATION_STATUS_DISPLAY.get(
c.verification_status, c.verification_status.title()
)
if c.verification_status
else ""
),
description="Verification status of the condition",
)
name = Field(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ def get_context(self):
)


STATUS_DISPLAY = {
"registered": "Registered",
"partial": "Partial",
"preliminary": "Preliminary",
"modified": "Modified",
"final": "Final",
}


class DiagnosticReportFilter(filters.FilterSet):
status = filters.CharFilter(lookup_expr="iexact")

Expand All @@ -40,9 +49,23 @@ def get_context(self):
display="Title",
preview_value="Chest X-Ray Report",
description="Title of the diagnostic report",
mapping=lambda dr: dr.code.get("display")
if dr.code and dr.code.get("display")
else "",
mapping=lambda dr: (
dr.code.get("display") if dr.code and dr.code.get("display") else ""
),
)
status = Field(
display="Status",
mapping=lambda e: STATUS_DISPLAY.get(
e.status, e.status.title() if e.status else ""
),
preview_value="In Progress",
description="Current status of the Diagnostic Report",
)
category = Field(
display="Category",
mapping=lambda c: c.code.get("display") if c.code else "",
preview_value="Audiology",
description="Service category of the report",
)
Comment thread
rithviknishad marked this conversation as resolved.
observations = Field(
display="Observations",
Expand Down
47 changes: 46 additions & 1 deletion care/emr/reports/context_builder/data_points/medication.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

from django_filters import rest_framework as filters

from care.emr.models import TagConfig
from care.emr.models.medication_request import (
MedicationRequest,
MedicationRequestPrescription,
)
from care.emr.reports.context_builder import TagFilter
from care.emr.reports.context_builder.data_points.base import (
Field,
QuerysetContextBuilder,
Expand Down Expand Up @@ -182,10 +184,42 @@ def get_context(self):
return MedicationRequest.objects.filter(prescription=self.parent_context)


class MedicationPrescriptionTagContextBuilder(QuerysetContextBuilder):
filterset_class = TagFilter
__filterset_backends__ = [filters.DjangoFilterBackend]

display = Field(
display="Tag Display",
preview_value="Preparing",
mapping=lambda t: t.display if t else None,
description="Display of the medication prescription tag",
)

def get_context(self):
return TagConfig.objects.filter(id__in=self.parent_context.tags)


MEDICATION_PRESCRIPTION_STATUS_DISPLAY = {
"active": "Active",
"on_hold": "On Hold",
"ended": "Ended",
"stopped": "Stopped",
"completed": "Completed",
"cancelled": "Cancelled",
"entered_in_error": "Entered in Error",
"draft": "Draft",
}


class MedicationPrescriptionContextBuilder(QuerysetContextBuilder):
filterset_class = MedicationPrescriptionReportFilter
__filterset_backends__ = [filters.DjangoFilterBackend]

name = Field(
display="Name",
preview_value="",
description="Name of the medication prescription",
)
medications = Field(
display="Medication",
preview_value="",
Expand All @@ -194,15 +228,26 @@ class MedicationPrescriptionContextBuilder(QuerysetContextBuilder):
)
status = Field(
display="Status",
preview_value="active",
preview_value="Active",
description="Status of the medication prescription",
mapping=lambda m: (
MEDICATION_PRESCRIPTION_STATUS_DISPLAY.get(m.status, m.status.title())
if m.status
else ""
),
)
prescribed_by = Field(
display="Prescribed By",
preview_value="",
target_context=SingleUserRelatedContextBuilder,
description="Details of the prescriber",
)
tags = Field(
display="Prescription Tags",
target_context=MedicationPrescriptionTagContextBuilder,
preview_value="",
description="Tags associated with the prescription",
)
note = Field(
display="Note",
preview_value="",
Expand Down
62 changes: 50 additions & 12 deletions care/emr/reports/context_builder/data_points/service_request.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django_filters import rest_framework as filters

from care.emr.models import TagConfig
from care.emr.models.service_request import ServiceRequest
from care.emr.reports.context_builder import TagFilter
from care.emr.reports.context_builder.data_points.base import (
Field,
QuerysetContextBuilder,
Expand Down Expand Up @@ -42,6 +44,21 @@
}


class ServiceRequestTagContextBuilder(QuerysetContextBuilder):
filterset_class = TagFilter
__filterset_backends__ = [filters.DjangoFilterBackend]
Comment thread
rithviknishad marked this conversation as resolved.

display = Field(
display="Tag Display",
preview_value="Preparing",
mapping=lambda t: t.display if t else None,
description="Display of the service request tag",
)

def get_context(self):
return TagConfig.objects.filter(id__in=self.parent_context.tags)

Comment thread
rithviknishad marked this conversation as resolved.

class ServiceRequestReportFilterSet(filters.FilterSet):
status = MultiSelectFilter(field_name="status")
intent = filters.CharFilter(field_name="intent", lookup_expr="iexact")
Expand All @@ -61,34 +78,34 @@ class ServiceRequestBaseContextBuilder(QuerysetContextBuilder):
status = Field(
display="Status",
preview_value="Active",
mapping=lambda sr: STATUS_CHOICE.get(sr.status, sr.status.title())
if sr.status
else "",
mapping=lambda sr: (
STATUS_CHOICE.get(sr.status, sr.status.title()) if sr.status else ""
),
description="Current status of the service request",
)
intent = Field(
display="Intent",
preview_value="Order",
mapping=lambda sr: INTENT_CHOICE.get(sr.intent, sr.intent.title())
if sr.intent
else "",
mapping=lambda sr: (
INTENT_CHOICE.get(sr.intent, sr.intent.title()) if sr.intent else ""
),
description="Intent of the service request",
)
category = Field(
display="Category",
preview_value="Laboratory",
mapping=lambda sr: CATEGORY_CHOICE.get(sr.category, sr.category.title())
if sr.category
else "",
mapping=lambda sr: (
CATEGORY_CHOICE.get(sr.category, sr.category.title()) if sr.category else ""
),
description="Category of the service request",
)

priority = Field(
display="Priority",
preview_value="Routine",
mapping=lambda sr: PRIORITY_CHOICE.get(sr.priority, sr.priority.title())
if sr.priority
else "",
mapping=lambda sr: (
PRIORITY_CHOICE.get(sr.priority, sr.priority.title()) if sr.priority else ""
),
description="Priority level of the service request",
)

Expand All @@ -98,6 +115,27 @@ class ServiceRequestBaseContextBuilder(QuerysetContextBuilder):
preview_value="",
description="User who requested the service",
)
occurance = Field(
display="Occurance",
Comment thread
rithviknishad marked this conversation as resolved.
Outdated
Comment thread
rithviknishad marked this conversation as resolved.
Outdated
preview_value="2023-01-01",
description="Date and time when service should occur",
)
patient_instruction = Field(
display="Patient Instruction",
preview_value="Follow up on blood count",
description="Patient or consumer-oriented instructions",
)
tags = Field(
display="Service Request Tags",
target_context=ServiceRequestTagContextBuilder,
preview_value="",
description="Tags associated with the service request",
)
note = Field(
display="Note",
preview_value="Sample note",
description="Additional notes about the service request",
)

def get_context(self):
return ServiceRequest.objects.filter(encounter=self.parent_context)
Loading
Loading