Skip to content

Commit

Permalink
add summary classes, update bundle digest extractor to return summaries
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-h-wang committed Jan 22, 2025
1 parent 0c5e0b0 commit 187c99d
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package gov.cdc.prime.router.azure.observability.bundleDigest

import gov.cdc.prime.router.azure.observability.event.ObservationSummary
import gov.cdc.prime.router.azure.observability.event.OrderingFacilitySummary
import gov.cdc.prime.router.azure.observability.event.PerformerSummary
import org.hl7.fhir.r4.model.Bundle

class BundleDigestExtractor(private val strategy: BundleDigestExtractorStrategy) {
Expand All @@ -20,7 +22,7 @@ interface BundleDigest {
data class BundleDigestLabResult(
val observationSummaries: List<ObservationSummary>,
val patientState: List<String>,
val performerState: List<String>,
val orderingFacilityState: List<String>,
val performerState: List<PerformerSummary>,
val orderingFacilityState: List<OrderingFacilitySummary>,
override val eventType: String,
) : BundleDigest
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package gov.cdc.prime.router.azure.observability.bundleDigest

import gov.cdc.prime.router.azure.observability.event.AzureEventUtils
import gov.cdc.prime.router.azure.observability.event.OrderingFacilitySummary
import gov.cdc.prime.router.azure.observability.event.PerformerSummary
import gov.cdc.prime.router.fhirengine.translation.hl7.utils.CustomContext
import gov.cdc.prime.router.fhirengine.translation.hl7.utils.FhirPathUtils
import org.hl7.fhir.r4.model.Bundle
Expand All @@ -11,24 +13,41 @@ class FhirPathBundleDigestLabResultExtractorStrategy(

private val eventCodePath = "Bundle.entry.resource.ofType(MessageHeader).event.display"
private val patientStatePath = "Bundle.entry.resource.ofType(Patient).address.state"
private val performerStatePath =
"Bundle.entry.resource.ofType(ServiceRequest)[0].performer.resolve().address.state"
private val orderingFacilityStatePath =
"Bundle.entry.resource.ofType(ServiceRequest)[0].requester.resolve().organization.resolve().address.state"

// The original strategy to collect the performerStates and orderingFacilityStates was to collect an
// aggregate list using the fhirpath below. This strategy needs to change when retrieving the associated
// names and CLIA as well. Instead, we will collect a list of performer and requester references, resolve
// them to DomainResource objects, and use those to build lists of PerformerSummary and OrderingFacilitySummary
// objects.

//private val performerStatePath =
// "Bundle.entry.resource.ofType(ServiceRequest)[0].performer.resolve().address.state"
//private val orderingFacilityStatePath =
// "Bundle.entry.resource.ofType(ServiceRequest)[0].requester.resolve().organization.resolve().address.state"
private val performerPath =
"Bundle.entry.resource.ofType(ServiceRequest)[0].performer.resolve()"
private val orderingFacilityPath =
"Bundle.entry.resource.ofType(ServiceRequest)[0].requester.resolve().organization.resolve()"

override fun extract(bundle: Bundle): BundleDigest {
val patientStates = getListOfFHIRValues(bundle, patientStatePath)
val performerStates = getListOfFHIRValues(bundle, performerStatePath)
val orderingFacilityState = getListOfFHIRValues(bundle, orderingFacilityStatePath)
//val performerStates = getListOfFHIRValues(bundle, performerStatePath)
//val orderingFacilityState = getListOfFHIRValues(bundle, orderingFacilityStatePath)
val performerSummaries = FhirPathUtils.evaluate(context, bundle, bundle, performerPath)
.map { PerformerSummary.fromPerformer(it) }
val orderingFacilitySummaries = FhirPathUtils.evaluate(context, bundle, bundle, orderingFacilityPath)
.map { OrderingFacilitySummary.fromOrganization(it) }
val eventCode = FhirPathUtils.evaluateString(context, bundle, bundle, eventCodePath)

val observationSummaries = AzureEventUtils.getObservationSummaries(bundle)

return BundleDigestLabResult(
observationSummaries,
patientStates,
performerStates,
orderingFacilityState,
//performerStates,
//orderingFacilityState,
performerSummaries,
orderingFacilitySummaries,
eventCode
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package gov.cdc.prime.router.azure.observability.event

import org.hl7.fhir.r4.model.Base
import org.hl7.fhir.r4.model.Organization

data class OrderingFacilitySummary (
val orderingFacilityName: String = UNKNOWN,
val orderingFacilityState: String = UNKNOWN,
) {
companion object {
const val UNKNOWN = "Unknown"
const val orderingFacilityNamePath = "Bundle.entry.resource.name"
const val orderingFacilityStatePath = "Bundle.entry.resource.address.state"

/**
* Create an instance of [OrderingFacilitySummary] from a [Organization]
*/
fun fromOrganization(requester: Base): OrderingFacilitySummary {
// For a given organization, return a OrderingFacilitySummary object from the paths listed above.
val organizationName = requester.getNamedProperty(orderingFacilityNamePath)
val organizationState = requester.getNamedProperty(orderingFacilityStatePath)

return OrderingFacilitySummary(
(organizationName ?: PerformerSummary.UNKNOWN).toString(),
(organizationState ?: PerformerSummary.UNKNOWN).toString(),
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package gov.cdc.prime.router.azure.observability.event

import org.hl7.fhir.r4.model.Base
import org.hl7.fhir.r4.model.DomainResource

data class PerformerSummary (
val performerName: String = UNKNOWN,
val performerState: String = UNKNOWN,
val performerCLIA: String = UNKNOWN,
) {
companion object {
const val UNKNOWN = "Unknown"
const val performerNamePath = "Bundle.entry.resource.name"
const val performerStatePath = "Bundle.entry.resource.address.state"
const val performerCLIAPath = "Bundle.entry.resource.identifier.value.getIdType() = 'CLIA'"

/**
* Create an instance of [PerformerSummary] from a [DomainResource]
*/
fun fromPerformer(performer: Base): PerformerSummary {
// For a given reference, resolve the object. This can reference many differing FHIR resource types
// (Practitioner, Organization, etc). Return a PerformerSummary object from the paths listed above.
val performerName = performer.getNamedProperty(performerNamePath)
val performerState = performer.getNamedProperty(performerStatePath)
val performerCLIA = performer.getNamedProperty(performerCLIAPath)

return PerformerSummary(
(performerName ?: PerformerSummary.UNKNOWN).toString(),
(performerState ?: PerformerSummary.UNKNOWN).toString(),
(performerCLIA ?: PerformerSummary.UNKNOWN).toString(),
)
}
}
}

0 comments on commit 187c99d

Please sign in to comment.