Skip to content

Commit 509a419

Browse files
committed
refact:mapped all fields under the standalone context builder
1 parent c6ca8ef commit 509a419

3 files changed

Lines changed: 53 additions & 60 deletions

File tree

care/emr/reports/context_builder/data_points/account.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
AccountChargeItemContextBuilder,
1010
)
1111
from care.emr.reports.context_builder.data_points.encounter import (
12-
MinimumEncounterReportContext,
12+
EncounterReportContext,
1313
)
1414
from care.emr.reports.context_builder.data_points.facility import FacilityContextBuilder
1515
from care.emr.reports.context_builder.data_points.invoice import (
@@ -19,7 +19,7 @@
1919
MonetaryComponentContextBuilder,
2020
)
2121
from care.emr.reports.context_builder.data_points.patient import (
22-
PatientMinimumContextBuilder,
22+
PatientContextBuilder,
2323
)
2424
from care.emr.reports.context_builder.data_points.payment_reconciliation import (
2525
PaymentReconciliationContextBuilder,
@@ -42,7 +42,17 @@
4242
}
4343

4444

45-
class BaseAccountContextBuilder(SingleObjectContextBuilder):
45+
class AccountContextBuilder(SingleObjectContextBuilder):
46+
standalone_context = True
47+
__slug__ = "account_base"
48+
__associating_model__ = Account
49+
__display_name__ = "Account Report"
50+
__description__ = "Report context for account-based reports"
51+
context_key = "account"
52+
53+
def get_context(self):
54+
return getattr(self.parent_context, self.parent_attribute)
55+
4656
external_id = Field(
4757
display="Account External ID",
4858
preview_value="beff3ce1-e1be-41bc-8fb9-07ce2ebe42a6",
@@ -139,22 +149,13 @@ class BaseAccountContextBuilder(SingleObjectContextBuilder):
139149
primary_encounter = Field(
140150
display="Primary Encounter",
141151
preview_value="",
142-
target_context=MinimumEncounterReportContext,
152+
target_context=EncounterReportContext,
143153
description="Primary encounter associated with the account",
144154
)
145155

146-
147-
class AccountContextBuilder(BaseAccountContextBuilder):
148-
standalone_context = True
149-
__slug__ = "account_base"
150-
__associating_model__ = Account
151-
__display_name__ = "Account Report"
152-
__description__ = "Report context for account-based reports"
153-
context_key = "account"
154-
155156
patient = Field(
156157
display="Patient Details",
157-
target_context=PatientMinimumContextBuilder,
158+
target_context=PatientContextBuilder,
158159
preview_value="",
159160
description="Details of the patient associated with the account",
160161
)

care/emr/reports/context_builder/data_points/encounter.py

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
)
2626
from care.emr.reports.context_builder.data_points.patient import (
2727
IdentifiersContextBuilder,
28-
PatientMinimumContextBuilder,
28+
PatientContextBuilder,
2929
PatientTagContextBuilder,
3030
TagFilter,
3131
)
@@ -226,7 +226,24 @@ def get_context(self):
226226
)
227227

228228

229-
class BaseEncounterReportContext(SingleObjectContextBuilder):
229+
class PatientFacilityIdentifiersContextBuilder(IdentifiersContextBuilder):
230+
def get_context(self):
231+
return self.parent_context.patient.facility_identifiers.get(
232+
str(self.parent_context.facility.id), []
233+
)
234+
235+
236+
class EncounterReportContext(SingleObjectContextBuilder):
237+
standalone_context = True
238+
__slug__ = "encounter_base"
239+
__associating_model__ = Encounter
240+
__display_name__ = "Encounter Report"
241+
__description__ = "Report context for encounter-based reports"
242+
context_key = "encounter"
243+
244+
def get_context(self):
245+
return getattr(self.parent_context, self.parent_attribute)
246+
230247
status = Field(
231248
display="Encounter Status",
232249
mapping=lambda e: STATUS_DISPLAY.get(
@@ -284,12 +301,6 @@ class BaseEncounterReportContext(SingleObjectContextBuilder):
284301
preview_value="Patient is advised to follow up in 2 weeks.",
285302
description="Discharge summary advice for the encounter",
286303
)
287-
patient_facility_tags = Field(
288-
target_context=EncounterPatientFacilityTagContextBuilder,
289-
display="Patient Facility Tags",
290-
preview_value="",
291-
description="Facility-specific tags associated with the patient for the encounter",
292-
)
293304
encounter_tags = Field(
294305
target_context=EncounterTagContextBuilder,
295306
display="Encounter Tags",
@@ -327,30 +338,9 @@ class BaseEncounterReportContext(SingleObjectContextBuilder):
327338
description="Encounter extensions as JSON (e.g. encounter.extensions.encounter_attender)",
328339
)
329340

330-
331-
class MinimumEncounterReportContext(BaseEncounterReportContext):
332-
def get_context(self):
333-
return getattr(self.parent_context, self.parent_attribute)
334-
335-
336-
class PatientFacilityIdentifiersContextBuilder(IdentifiersContextBuilder):
337-
def get_context(self):
338-
return self.parent_context.patient.facility_identifiers.get(
339-
str(self.parent_context.facility.id), []
340-
)
341-
342-
343-
class EncounterReportContext(BaseEncounterReportContext):
344-
standalone_context = True
345-
__slug__ = "encounter_base"
346-
__associating_model__ = Encounter
347-
__display_name__ = "Encounter Report"
348-
__description__ = "Report context for encounter-based reports"
349-
context_key = "encounter"
350-
351341
patient = Field(
352342
display="Patient Details",
353-
target_context=PatientMinimumContextBuilder,
343+
target_context=PatientContextBuilder,
354344
preview_value="",
355345
description="Details of the patient associated with the encounter",
356346
)
@@ -414,6 +404,12 @@ class EncounterReportContext(BaseEncounterReportContext):
414404
preview_value="",
415405
description="Facility identifiers associated with the encounter",
416406
)
407+
patient_facility_tags = Field(
408+
target_context=EncounterPatientFacilityTagContextBuilder,
409+
display="Patient Facility Tags",
410+
preview_value="",
411+
description="Facility-specific tags associated with the patient for the encounter",
412+
)
417413

418414

419415
DataPointRegistry.register(EncounterReportContext)

care/emr/reports/context_builder/data_points/patient.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,17 @@ def get_context(self):
103103
return TagConfig.objects.filter(id__in=self.parent_context.instance_tags)
104104

105105

106-
class BasePatientContextBuilder(SingleObjectContextBuilder):
106+
class PatientContextBuilder(SingleObjectContextBuilder):
107+
standalone_context = True
108+
__slug__ = "patient_base"
109+
__associating_model__ = Patient
110+
__display_name__ = "Patient Report"
111+
__description__ = "Report context for patient-based reports"
112+
context_key = "patient"
113+
114+
def get_context(self):
115+
return getattr(self.parent_context, self.parent_attribute)
116+
107117
name = Field(
108118
display="Patient Name",
109119
preview_value="John Doe",
@@ -181,18 +191,4 @@ class BasePatientContextBuilder(SingleObjectContextBuilder):
181191
)
182192

183193

184-
class PatientMinimumContextBuilder(BasePatientContextBuilder):
185-
def get_context(self):
186-
return getattr(self.parent_context, self.parent_attribute)
187-
188-
189-
class PatientContextBuilderBase(BasePatientContextBuilder):
190-
standalone_context = True
191-
__slug__ = "patient_base"
192-
__associating_model__ = Patient
193-
__display_name__ = "Patient Report"
194-
__description__ = "Report context for patient-based reports"
195-
context_key = "patient"
196-
197-
198-
DataPointRegistry.register(PatientContextBuilderBase)
194+
DataPointRegistry.register(PatientContextBuilder)

0 commit comments

Comments
 (0)