-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workflow Library: Implementing Library.evaluate and first androidTest…
… suite (#1326) * Operator.evaluateLibrary function Generalization of FhirEngineRetrieveProvider * Fixes from spotlessApply * Moving COVID tests to its own directory. * Removing redundant (contextPath != "id") * Using Truth library and clearing up the logs * BugFix on assetPath and Organization ID * Fixing the JSON structure of the test to become a Bundle instead of a Composite. * Updating LibraryEvaluate Tests to the new FhirEngineProviderTestRule * Update workflow/src/main/java/com/google/android/fhir/workflow/FhirOperator.kt Improving documentation as suggested by the reviewer. Co-authored-by: Jing Tang <[email protected]> * Adding a new line before the function definition. * Adding a new line before the function for consistency. * deleting unnecessary test files * Simplifying Test Case * Removing new line * Fixing Documentation of evaluateLibrary * Improving the explanation of the test case for Library Evaluate * Improving documentation of the Library Evaluate test case by describing the CQLEvaluator steps being tested * Running spotless check * update to trigger github actions after OutOfMemory exception * removing spaces to pass spotless * Improving documentation * Use a cached version of R4 Co-authored-by: Jing Tang <[email protected]>
- Loading branch information
1 parent
d806535
commit e8bd02a
Showing
6 changed files
with
293 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
.../src/androidTest/java/com/google/android/fhir/workflow/FhirOperatorLibraryEvaluateTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.android.fhir.workflow | ||
|
||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import ca.uhn.fhir.context.FhirContext | ||
import ca.uhn.fhir.context.FhirVersionEnum | ||
import com.google.android.fhir.FhirEngine | ||
import com.google.android.fhir.FhirEngineProvider | ||
import com.google.android.fhir.testing.FhirEngineProviderTestRule | ||
import com.google.common.truth.Truth.assertThat | ||
import java.io.InputStream | ||
import kotlinx.coroutines.runBlocking | ||
import org.hl7.fhir.r4.model.Bundle | ||
import org.hl7.fhir.r4.model.Parameters | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class FhirOperatorLibraryEvaluateTest { | ||
|
||
@get:Rule val fhirEngineProviderRule = FhirEngineProviderTestRule() | ||
|
||
private lateinit var fhirEngine: FhirEngine | ||
private lateinit var fhirOperator: FhirOperator | ||
|
||
private val fhirContext = FhirContext.forCached(FhirVersionEnum.R4) | ||
private val jsonParser = fhirContext.newJsonParser() | ||
|
||
private fun open(asset: String): InputStream? { | ||
return javaClass.getResourceAsStream(asset) | ||
} | ||
|
||
private fun load(asset: String): Bundle { | ||
return jsonParser.parseResource(open(asset)) as Bundle | ||
} | ||
|
||
@Before | ||
fun setUp() = runBlocking { | ||
fhirEngine = FhirEngineProvider.getInstance(ApplicationProvider.getApplicationContext()) | ||
fhirOperator = FhirOperator(fhirContext, fhirEngine) | ||
} | ||
|
||
/** | ||
* Evaluates a compiled CQL that was exported to Jxson and included inside a FHIRLibrary Json. The | ||
* compiled CQL file is encoded in Base64 and placed inside the JSON Library. The expression | ||
* `CompletedImmunization` simply checks if a vaccination protocol has been finished as below. | ||
* | ||
* This test requires the CQLEvaluator to | ||
* 1. load the patient using a `FhirEngineRetrieveProvider`, | ||
* 2. load the Immunization records of that patient, | ||
* 3. load the CQL Library using a `FhirEngineLibraryContentProvider` | ||
* 4. evaluate if the immunization record presents a Protocol where the number of doses taken | ||
* matches the number of required doses or if the number of required doses is null. | ||
* | ||
* ``` | ||
* library ImmunityCheck version '1.0.0' | ||
* | ||
* using FHIR version '4.0.0' | ||
* include "FHIRHelpers" version '4.0.0' called FHIRHelpers | ||
* context Immunization | ||
* | ||
* define "CompletedImmunization": | ||
* exists(GetFinalDose) or exists(GetSingleDose) | ||
* | ||
* define "GetFinalDose": | ||
* [Immunization] I | ||
* where exists(I.protocolApplied) | ||
* and I.protocolApplied.doseNumber.value = I.protocolApplied.seriesDoses.value | ||
* | ||
* define "GetSingleDose": | ||
* [Immunization] I | ||
* where exists(I.protocolApplied) | ||
* and exists(I.protocolApplied.doseNumber.value) | ||
* and not exists(I.protocolApplied.seriesDoses.value) | ||
* ``` | ||
*/ | ||
@Test | ||
fun evaluateImmunityCheck() = runBlocking { | ||
// Load patient | ||
val patientImmunizationHistory = load("/immunity-check/ImmunizationHistory.json") | ||
for (entry in patientImmunizationHistory.entry) { | ||
fhirEngine.create(entry.resource) | ||
} | ||
|
||
// Load Library that checks if Patient has taken a vaccine | ||
fhirOperator.loadLibs(load("/immunity-check/ImmunityCheck.json")) | ||
|
||
// Evaluates a specific Patient | ||
val results = | ||
fhirOperator.evaluateLibrary( | ||
"http://localhost/Library/ImmunityCheck|1.0.0", | ||
"d4d35004-24f8-40e4-8084-1ad75924514f", | ||
setOf("CompletedImmunization") | ||
) as | ||
Parameters | ||
|
||
assertThat(results.getParameterBool("CompletedImmunization")).isTrue() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.