Skip to content

Commit

Permalink
Allow nullable expressions in library evaluator (google#2409)
Browse files Browse the repository at this point in the history
* Niullable expressions in library evaluator

* Add kdoc for changes in param

---------

Co-authored-by: Peter Lubell-Doughtie <[email protected]>
  • Loading branch information
maimoonak and pld authored Jan 19, 2024
1 parent 45c687e commit 9d41e1b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Google LLC
* Copyright 2022-2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -132,4 +132,27 @@ class FhirOperatorLibraryEvaluateTest {

assertThat(results.getParameterBool("CompletedImmunization")).isTrue()
}

@Test
fun evaluateImmunityCheck_shouldReturn_allEvaluatedVariables() = 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"))

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

assertThat(results.hasParameter("CompletedImmunization")).isTrue()
assertThat(results.hasParameter("GetFinalDose")).isTrue()
assertThat(results.hasParameter("Patient")).isTrue()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,14 @@ internal constructor(
* from a worker thread or it may throw [BlockingMainThreadException] exception.
*
* @param libraryUrl the url of the Library to evaluate
* @param expressions names of expressions in the Library to evaluate.
* @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(libraryUrl: String, expressions: Set<String>): IBaseParameters {
fun evaluateLibrary(libraryUrl: String, expressions: Set<String>?): IBaseParameters {
return evaluateLibrary(libraryUrl, null, null, expressions)
}

Expand All @@ -94,14 +97,17 @@ internal constructor(
*
* @param libraryUrl the url of the Library to evaluate
* @param patientId the Id of the patient to be evaluated
* @param expressions names of expressions in the Library to evaluate.
* @return a Parameters resource that contains an evaluation result for each expression requested
* @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(
libraryUrl: String,
patientId: String,
expressions: Set<String>,
expressions: Set<String>?,
): IBaseParameters {
return evaluateLibrary(libraryUrl, patientId, null, expressions)
}
Expand All @@ -114,14 +120,17 @@ internal constructor(
*
* @param libraryUrl the url of the Library to evaluate
* @param parameters list of parameters to be passed to the CQL library
* @param expressions names of expressions in the Library to evaluate.
* @return a Parameters resource that contains an evaluation result for each expression requested
* @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(
libraryUrl: String,
parameters: Parameters,
expressions: Set<String>,
expressions: Set<String>?,
): IBaseParameters {
return evaluateLibrary(libraryUrl, null, parameters, expressions)
}
Expand All @@ -135,15 +144,18 @@ internal constructor(
* @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 expressions names of expressions in the Library to evaluate.
* @return a Parameters resource that contains an evaluation result for each expression requested
* @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(
libraryUrl: String,
patientId: String?,
parameters: Parameters?,
expressions: Set<String>,
expressions: Set<String>?,
): IBaseParameters {
return libraryProcessor.evaluate(
/* url = */ libraryUrl,
Expand Down

0 comments on commit 9d41e1b

Please sign in to comment.