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

Add support for additional data during CQL evaluation #2420

Merged
merged 20 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
"doseNumberPositiveInt": 2,
"seriesDosesPositiveInt": 2
}
]
],
"location": {
"reference": "Location/nairobi-047"
}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import kotlinx.coroutines.runBlocking
import org.hl7.fhir.instance.model.api.IBaseResource
import org.hl7.fhir.r4.model.Bundle
import org.hl7.fhir.r4.model.Library
import org.hl7.fhir.r4.model.Location
import org.hl7.fhir.r4.model.Parameters
import org.junit.Before
import org.junit.Rule
Expand Down Expand Up @@ -133,6 +134,58 @@ class FhirOperatorLibraryEvaluateTest {
assertThat(results.getParameterBool("CompletedImmunization")).isTrue()
}

@Test
fun evaluateImmunityCheckWithAdditionalData() = runBlocking {
val patientImmunizationHistory = load("/immunity-check/ImmunizationHistory.json") as Bundle
for (entry in patientImmunizationHistory.entry) {
fhirEngine.create(entry.resource)
}

// Load Library that checks if Patient has taken a vaccine
knowledgeManager.install(copy("/immunity-check/ImmunityCheck.json"))
knowledgeManager.install(copy("/immunity-check/FhirHelpers.json"))

val location =
"""
{
"resourceType": "Location",
"id": "nairobi-047",
"status": "active",
"name": "Arundel mobile clinic",
"mode": "instance",
"physicalType": {
"coding": [ {
"system": "http://terminology.hl7.org/CodeSystem/location-physical-type",
"code": "bu",
"display": "Arundel mobile clinic"
} ]
}
}
"""
.trimIndent()

val additionalDataBundle =
Bundle().apply {
addEntry(
Bundle.BundleEntryComponent().apply {
resource = jsonParser.parseResource(location) as Location
},
)
}

// Evaluates a specific Patient
val results =
fhirOperator.evaluateLibrary(
"http://localhost/Library/ImmunityCheck|1.0.0",
"d4d35004-24f8-40e4-8084-1ad75924514f",
null,
additionalDataBundle,
null,
) as Parameters

assertThat(results.hasParameter("GetFinalDoseWithLocationData")).isTrue()
}

@Test
fun evaluateImmunityCheck_shouldReturn_allEvaluatedVariables() = runBlocking {
val patientImmunizationHistory = load("/immunity-check/ImmunizationHistory.json") as Bundle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,46 @@ internal constructor(
patientId: String?,
parameters: Parameters?,
expressions: Set<String>?,
): IBaseParameters {
return evaluateLibrary(
libraryUrl,
patientId,
parameters,
null,
expressions,
)
}

/**
* The function evaluates a FHIR library against the database.
*
* NOTE: The API may internally result in a blocking IO operation. The user should call the API
* from a worker thread or it may throw [BlockingMainThreadException] exception.
*
* @param libraryUrl the url of the Library to evaluate
* @param patientId the Id of the patient to be evaluated, if applicable
* @param parameters list of parameters to be passed to the CQL library, if applicable
* @param additionalData Bundle of additional resources to be passed to the CQL library, if
* applicable
* @param expressions names of expressions in the Library to evaluate. If null the result contains
* all evaluations or variables in library.
* @return a Parameters resource that contains an evaluation result for each expression requested.
* Or if expressions param is null then result contains all evaluations or variables in given
* library.
*/
@WorkerThread
fun evaluateLibrary(
jingtang10 marked this conversation as resolved.
Show resolved Hide resolved
libraryUrl: String,
patientId: String?,
parameters: Parameters?,
additionalData: IBaseBundle?,
expressions: Set<String>?,
): IBaseParameters {
return libraryProcessor.evaluate(
/* url = */ libraryUrl,
/* patientId = */ patientId,
/* parameters = */ parameters,
/* additionalData = */ null,
/* additionalData = */ additionalData,
/* expressions = */ expressions,
)
}
Expand Down
Loading