From a9ba529e83e939eb40a248f2ae4a2023eea8b53a Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Thu, 1 Dec 2022 18:48:19 -0500 Subject: [PATCH 1/8] Encounter ID is not required. --- .../java/com/google/android/fhir/workflow/FhirOperator.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/workflow/src/main/java/com/google/android/fhir/workflow/FhirOperator.kt b/workflow/src/main/java/com/google/android/fhir/workflow/FhirOperator.kt index 01c3b441fd..28d7602b0a 100644 --- a/workflow/src/main/java/com/google/android/fhir/workflow/FhirOperator.kt +++ b/workflow/src/main/java/com/google/android/fhir/workflow/FhirOperator.kt @@ -237,7 +237,11 @@ class FhirOperator(fhirContext: FhirContext, fhirEngine: FhirEngine) { ) } - fun generateCarePlan(planDefinitionId: String, patientId: String, encounterId: String): CarePlan { + fun generateCarePlan(planDefinitionId: String, patientId: String): CarePlan { + return generateCarePlan(planDefinitionId, patientId, encounterId = null) + } + + fun generateCarePlan(planDefinitionId: String, patientId: String, encounterId: String?): CarePlan { return planDefinitionProcessor.apply( IdType("PlanDefinition", planDefinitionId), patientId, From a6a84be62e4734c09a0458ee37158ed771768fff Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Thu, 1 Dec 2022 20:24:49 -0500 Subject: [PATCH 2/8] spotless apply --- .../java/com/google/android/fhir/workflow/FhirOperator.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/workflow/src/main/java/com/google/android/fhir/workflow/FhirOperator.kt b/workflow/src/main/java/com/google/android/fhir/workflow/FhirOperator.kt index 28d7602b0a..cf7e52dc83 100644 --- a/workflow/src/main/java/com/google/android/fhir/workflow/FhirOperator.kt +++ b/workflow/src/main/java/com/google/android/fhir/workflow/FhirOperator.kt @@ -241,7 +241,11 @@ class FhirOperator(fhirContext: FhirContext, fhirEngine: FhirEngine) { return generateCarePlan(planDefinitionId, patientId, encounterId = null) } - fun generateCarePlan(planDefinitionId: String, patientId: String, encounterId: String?): CarePlan { + fun generateCarePlan( + planDefinitionId: String, + patientId: String, + encounterId: String? + ): CarePlan { return planDefinitionProcessor.apply( IdType("PlanDefinition", planDefinitionId), patientId, From c5b541ccb78cb1edf22eb77b17ced7cc0d4b3c90 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 2 Dec 2022 11:51:43 -0500 Subject: [PATCH 3/8] Allowing test cases without encounterID --- .../com/google/android/fhir/workflow/testing/PlanDefinition.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/workflow-testing/src/main/java/com/google/android/fhir/workflow/testing/PlanDefinition.kt b/workflow-testing/src/main/java/com/google/android/fhir/workflow/testing/PlanDefinition.kt index 50bc1ce8dd..4707ad8aa6 100644 --- a/workflow-testing/src/main/java/com/google/android/fhir/workflow/testing/PlanDefinition.kt +++ b/workflow-testing/src/main/java/com/google/android/fhir/workflow/testing/PlanDefinition.kt @@ -156,6 +156,9 @@ object PlanDefinition : Loadable() { object Assert { fun that(planDefinitionID: String, patientID: String, encounterID: String?) = Apply(planDefinitionID, patientID, encounterID) + + fun that(planDefinitionID: String, patientID: String) = + Apply(planDefinitionID, patientID, null) } class Apply( From 29e61d1fcf1f9e5f18e62df729cbbb514a5f1e13 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 2 Dec 2022 11:53:57 -0500 Subject: [PATCH 4/8] Adding a test case that does not use Encounter. --- .../med-request/med_request_careplan.json | 43 +++++++++++++++++++ .../med-request/med_request_patient.json | 22 ++++++++++ .../med_request_plan_definition.json | 30 +++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 workflow-testing/src/main/resources/plan-definition/med-request/med_request_careplan.json create mode 100644 workflow-testing/src/main/resources/plan-definition/med-request/med_request_patient.json create mode 100644 workflow-testing/src/main/resources/plan-definition/med-request/med_request_plan_definition.json diff --git a/workflow-testing/src/main/resources/plan-definition/med-request/med_request_careplan.json b/workflow-testing/src/main/resources/plan-definition/med-request/med_request_careplan.json new file mode 100644 index 0000000000..0d08995d54 --- /dev/null +++ b/workflow-testing/src/main/resources/plan-definition/med-request/med_request_careplan.json @@ -0,0 +1,43 @@ +{ + "resourceType": "CarePlan", + "contained": [ + { + "resourceType": "RequestGroup", + "id": "1", + "status": "draft", + "intent": "proposal", + "action": [ + { + "resource": { + "reference": "#2" + } + } + ] + }, + { + "resourceType": "MedicationRequest", + "id": "2", + "intent": "order", + "medicationCodeableConcept": { + "text": "Medication 1" + }, + "subject": { + "reference": "Patient/Patient-Example" + } + } + ], + "instantiatesCanonical": [ + "MedRequest-Example" + ], + "status": "draft", + "subject": { + "reference": "Patient/Patient-Example" + }, + "activity": [ + { + "reference": { + "reference": "#1" + } + } + ] +} \ No newline at end of file diff --git a/workflow-testing/src/main/resources/plan-definition/med-request/med_request_patient.json b/workflow-testing/src/main/resources/plan-definition/med-request/med_request_patient.json new file mode 100644 index 0000000000..07dc977c06 --- /dev/null +++ b/workflow-testing/src/main/resources/plan-definition/med-request/med_request_patient.json @@ -0,0 +1,22 @@ +{ + "resourceType": "Bundle", + "entry": [ + { + "resource": { + "resourceType": "Patient", + "id": "Patient-Example", + "active": true, + "name": [ + { + "family": "Hadi", + "given": [ + "Bareera" + ] + } + ], + "gender": "female", + "birthDate": "1999-01-14" + } + } + ] +} \ No newline at end of file diff --git a/workflow-testing/src/main/resources/plan-definition/med-request/med_request_plan_definition.json b/workflow-testing/src/main/resources/plan-definition/med-request/med_request_plan_definition.json new file mode 100644 index 0000000000..bb87937c6f --- /dev/null +++ b/workflow-testing/src/main/resources/plan-definition/med-request/med_request_plan_definition.json @@ -0,0 +1,30 @@ +{ + "resourceType": "Bundle", + "type": "transaction", + "entry": [ + { + "resource": { + "resourceType" : "ActivityDefinition", + "id" : "MedicationRequest-1", + "url" : "http://localhost/ActivityDefinition/MedicationRequest-1", + "status": "active", + "kind" : "MedicationRequest", + "productCodeableConcept" : { + "text" : "Medication 1" + } + } + },{ + "resource": { + "resourceType" : "PlanDefinition", + "id" : "MedRequest-Example", + "title" : "This example illustrates a medication request", + "status" : "active", + "action" : [{ + "id" : "medication-action-1", + "title" : "Administer Medication 1", + "definitionCanonical" : "http://localhost/ActivityDefinition/MedicationRequest-1" + }] + } + } + ] +} \ No newline at end of file From 80fda64ce6349bcf92bcb66d802d0790f30699b1 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 2 Dec 2022 11:54:47 -0500 Subject: [PATCH 5/8] Creating the test case call through the FhirOperator and without it. --- .../android/fhir/workflow/FhirOperatorTest.kt | 19 +++++++++++++++++++ .../PlanDefinitionProcessorJavaTest.kt | 12 ++++++++++++ 2 files changed, 31 insertions(+) diff --git a/workflow/src/test/java/com/google/android/fhir/workflow/FhirOperatorTest.kt b/workflow/src/test/java/com/google/android/fhir/workflow/FhirOperatorTest.kt index e6c4ef786a..98aea4a3aa 100644 --- a/workflow/src/test/java/com/google/android/fhir/workflow/FhirOperatorTest.kt +++ b/workflow/src/test/java/com/google/android/fhir/workflow/FhirOperatorTest.kt @@ -94,6 +94,25 @@ class FhirOperatorTest { .isNotNull() } + @Test + fun generateCarePlanWithoutEncounter() = runBlocking { + loadBundle(parseJson("/plan-definition/med-request/med_request_patient.json")) + loadBundle(parseJson("/plan-definition/med-request/med_request_plan_definition.json")) + + val carePlan = fhirOperator.generateCarePlan( + planDefinitionId = "MedRequest-Example", + patientId = "Patient/Patient-Example" + ) + + println(jsonParser.encodeResourceToString(carePlan)) + + JSONAssert.assertEquals( + readResourceAsString("/plan-definition/med-request/med_request_careplan.json"), + jsonParser.encodeResourceToString(carePlan), + true + ) + } + @Test fun evaluatePopulationMeasure() = runBlocking { loadBundle(libraryBundle) diff --git a/workflow/src/test/java/com/google/android/fhir/workflow/PlanDefinitionProcessorJavaTest.kt b/workflow/src/test/java/com/google/android/fhir/workflow/PlanDefinitionProcessorJavaTest.kt index a9f6a33e91..21ca8e6275 100644 --- a/workflow/src/test/java/com/google/android/fhir/workflow/PlanDefinitionProcessorJavaTest.kt +++ b/workflow/src/test/java/com/google/android/fhir/workflow/PlanDefinitionProcessorJavaTest.kt @@ -88,4 +88,16 @@ class PlanDefinitionProcessorJavaTest { .withLibrary("/plan-definition/rule-filters/RuleFilters-1.0.0-bundle.json") .apply() .isEqualsTo("/plan-definition/rule-filters/ReportableCarePlan.json") + + @Test + fun testAncVisitContainedActivityDefinition() = + PlanDefinition.Assert.that( + "MedRequest-Example", + "Patient/Patient-Example" + ) + .withData("/plan-definition/med-request/med_request_patient.json") + .withLibrary("/plan-definition/med-request/med_request_plan_definition.json") + .apply() + .isEqualsTo("/plan-definition/med-request/med_request_careplan.json") + } From f56ca50cc4ae7ca6e28536ee2c7c9fdbc58ccc18 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 2 Dec 2022 11:55:08 -0500 Subject: [PATCH 6/8] Enabling searchByUrl for all Resource types. --- .../android/fhir/workflow/FhirEngineDal.kt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/workflow/src/main/java/com/google/android/fhir/workflow/FhirEngineDal.kt b/workflow/src/main/java/com/google/android/fhir/workflow/FhirEngineDal.kt index 0a83d55e18..313057664f 100644 --- a/workflow/src/main/java/com/google/android/fhir/workflow/FhirEngineDal.kt +++ b/workflow/src/main/java/com/google/android/fhir/workflow/FhirEngineDal.kt @@ -16,8 +16,10 @@ package com.google.android.fhir.workflow +import ca.uhn.fhir.rest.gclient.UriClientParam import com.google.android.fhir.FhirEngine import com.google.android.fhir.getResourceType +import com.google.android.fhir.search.Search import com.google.android.fhir.search.search import kotlinx.coroutines.runBlocking import org.hl7.fhir.instance.model.api.IBaseResource @@ -26,6 +28,7 @@ import org.hl7.fhir.r4.model.Library import org.hl7.fhir.r4.model.Measure import org.hl7.fhir.r4.model.Patient import org.hl7.fhir.r4.model.Resource +import org.hl7.fhir.r4.model.ResourceType import org.opencds.cqf.cql.evaluator.fhir.dal.FhirDal class FhirEngineDal(private val fhirEngine: FhirEngine) : FhirDal { @@ -50,18 +53,21 @@ class FhirEngineDal(private val fhirEngine: FhirEngine) : FhirDal { } override fun search(resourceType: String): Iterable = runBlocking { + val search = Search(type = ResourceType.fromCode(resourceType)) when (resourceType) { - "Patient" -> fhirEngine.search {}.toMutableList() - else -> throw NotImplementedError("Not yet implemented") - } + "Library" -> libs.values.plus(fhirEngine.search(search)) + else -> fhirEngine.search(search) + }.toMutableList() } override fun searchByUrl(resourceType: String, url: String): Iterable = runBlocking { + val search = Search(type = ResourceType.fromCode(resourceType)) + search.filter(UriClientParam("url"), { value = url }) + when (resourceType) { - "Measure" -> fhirEngine.search { filter(Measure.URL, { value = url }) } - "Library" -> listOf(libs[url] as Library) - else -> listOf() + "Library" -> listOfNotNull(libs[url]).plus(fhirEngine.search(search)) + else -> fhirEngine.search(search) }.toMutableList() } From ab58782e976064c4bf6b4f874754b01721e3d05d Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 2 Dec 2022 11:56:21 -0500 Subject: [PATCH 7/8] Spotless check --- .../android/fhir/workflow/testing/PlanDefinition.kt | 3 +-- .../com/google/android/fhir/workflow/FhirEngineDal.kt | 2 -- .../com/google/android/fhir/workflow/FhirOperatorTest.kt | 9 +++++---- .../fhir/workflow/PlanDefinitionProcessorJavaTest.kt | 6 +----- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/workflow-testing/src/main/java/com/google/android/fhir/workflow/testing/PlanDefinition.kt b/workflow-testing/src/main/java/com/google/android/fhir/workflow/testing/PlanDefinition.kt index 4707ad8aa6..b7c521076a 100644 --- a/workflow-testing/src/main/java/com/google/android/fhir/workflow/testing/PlanDefinition.kt +++ b/workflow-testing/src/main/java/com/google/android/fhir/workflow/testing/PlanDefinition.kt @@ -157,8 +157,7 @@ object PlanDefinition : Loadable() { fun that(planDefinitionID: String, patientID: String, encounterID: String?) = Apply(planDefinitionID, patientID, encounterID) - fun that(planDefinitionID: String, patientID: String) = - Apply(planDefinitionID, patientID, null) + fun that(planDefinitionID: String, patientID: String) = Apply(planDefinitionID, patientID, null) } class Apply( diff --git a/workflow/src/main/java/com/google/android/fhir/workflow/FhirEngineDal.kt b/workflow/src/main/java/com/google/android/fhir/workflow/FhirEngineDal.kt index 313057664f..07133597e1 100644 --- a/workflow/src/main/java/com/google/android/fhir/workflow/FhirEngineDal.kt +++ b/workflow/src/main/java/com/google/android/fhir/workflow/FhirEngineDal.kt @@ -25,8 +25,6 @@ import kotlinx.coroutines.runBlocking import org.hl7.fhir.instance.model.api.IBaseResource import org.hl7.fhir.instance.model.api.IIdType import org.hl7.fhir.r4.model.Library -import org.hl7.fhir.r4.model.Measure -import org.hl7.fhir.r4.model.Patient import org.hl7.fhir.r4.model.Resource import org.hl7.fhir.r4.model.ResourceType import org.opencds.cqf.cql.evaluator.fhir.dal.FhirDal diff --git a/workflow/src/test/java/com/google/android/fhir/workflow/FhirOperatorTest.kt b/workflow/src/test/java/com/google/android/fhir/workflow/FhirOperatorTest.kt index 98aea4a3aa..2f1af532a5 100644 --- a/workflow/src/test/java/com/google/android/fhir/workflow/FhirOperatorTest.kt +++ b/workflow/src/test/java/com/google/android/fhir/workflow/FhirOperatorTest.kt @@ -99,10 +99,11 @@ class FhirOperatorTest { loadBundle(parseJson("/plan-definition/med-request/med_request_patient.json")) loadBundle(parseJson("/plan-definition/med-request/med_request_plan_definition.json")) - val carePlan = fhirOperator.generateCarePlan( - planDefinitionId = "MedRequest-Example", - patientId = "Patient/Patient-Example" - ) + val carePlan = + fhirOperator.generateCarePlan( + planDefinitionId = "MedRequest-Example", + patientId = "Patient/Patient-Example" + ) println(jsonParser.encodeResourceToString(carePlan)) diff --git a/workflow/src/test/java/com/google/android/fhir/workflow/PlanDefinitionProcessorJavaTest.kt b/workflow/src/test/java/com/google/android/fhir/workflow/PlanDefinitionProcessorJavaTest.kt index 21ca8e6275..5c969f6623 100644 --- a/workflow/src/test/java/com/google/android/fhir/workflow/PlanDefinitionProcessorJavaTest.kt +++ b/workflow/src/test/java/com/google/android/fhir/workflow/PlanDefinitionProcessorJavaTest.kt @@ -91,13 +91,9 @@ class PlanDefinitionProcessorJavaTest { @Test fun testAncVisitContainedActivityDefinition() = - PlanDefinition.Assert.that( - "MedRequest-Example", - "Patient/Patient-Example" - ) + PlanDefinition.Assert.that("MedRequest-Example", "Patient/Patient-Example") .withData("/plan-definition/med-request/med_request_patient.json") .withLibrary("/plan-definition/med-request/med_request_plan_definition.json") .apply() .isEqualsTo("/plan-definition/med-request/med_request_careplan.json") - } From be2942100cc158a35a8ed13b876f7919b04a0dea Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 2 Dec 2022 12:55:49 -0500 Subject: [PATCH 8/8] Removing unnecessary import. --- .../main/java/com/google/android/fhir/workflow/FhirEngineDal.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/workflow/src/main/java/com/google/android/fhir/workflow/FhirEngineDal.kt b/workflow/src/main/java/com/google/android/fhir/workflow/FhirEngineDal.kt index 07133597e1..c30bf12910 100644 --- a/workflow/src/main/java/com/google/android/fhir/workflow/FhirEngineDal.kt +++ b/workflow/src/main/java/com/google/android/fhir/workflow/FhirEngineDal.kt @@ -20,7 +20,6 @@ import ca.uhn.fhir.rest.gclient.UriClientParam import com.google.android.fhir.FhirEngine import com.google.android.fhir.getResourceType import com.google.android.fhir.search.Search -import com.google.android.fhir.search.search import kotlinx.coroutines.runBlocking import org.hl7.fhir.instance.model.api.IBaseResource import org.hl7.fhir.instance.model.api.IIdType