diff --git a/workflow-testing/src/main/resources/plan-definition/cql-applicability-condition/care_plan.json b/workflow-testing/src/main/resources/plan-definition/cql-applicability-condition/care_plan.json new file mode 100644 index 0000000000..187572f303 --- /dev/null +++ b/workflow-testing/src/main/resources/plan-definition/cql-applicability-condition/care_plan.json @@ -0,0 +1,60 @@ +{ + "resourceType": "CarePlan", + "contained": [ + { + "resourceType": "RequestGroup", + "id": "Plan-Definition-Example", + "instantiatesCanonical": [ + "http://example.com/PlanDefinition/Plan-Definition-Example" + ], + "status": "draft", + "intent": "proposal", + "subject": { + "reference": "Patient/Female-Patient-Example" + }, + "action": [ + { + "resource": { + "reference": "Task" + } + } + ] + }, + { + "resourceType": "Task", + "id": "Task", + "extension": [ + { + "url": "http://hl7.org/fhir/aphl/StructureDefinition/condition", + "valueExpression": { + "language": "text/cql.identifier", + "expression": "Patient is Female" + } + } + ], + "basedOn": [ + { + "reference": "#RequestGroup/Plan-Definition-Example", + "type": "RequestGroup" + } + ], + "status": "draft", + "description": "Example Task" + } + ], + "instantiatesCanonical": [ + "http://example.com/PlanDefinition/Plan-Definition-Example" + ], + "status": "draft", + "intent": "proposal", + "subject": { + "reference": "Patient/Female-Patient-Example" + }, + "activity": [ + { + "reference": { + "reference": "#Plan-Definition-Example" + } + } + ] +} \ No newline at end of file diff --git a/workflow-testing/src/main/resources/plan-definition/cql-applicability-condition/example-1.0.0.cql b/workflow-testing/src/main/resources/plan-definition/cql-applicability-condition/example-1.0.0.cql new file mode 100644 index 0000000000..f25064efa8 --- /dev/null +++ b/workflow-testing/src/main/resources/plan-definition/cql-applicability-condition/example-1.0.0.cql @@ -0,0 +1,9 @@ +library example version '1.0.0' +using FHIR version '4.0.1' +include FHIRHelpers version '4.0.1' + +context Patient + +define "Patient is Female": Patient.gender = 'female' + +define "Get Task Description": 'Example Task' diff --git a/workflow-testing/src/main/resources/plan-definition/cql-applicability-condition/patient.json b/workflow-testing/src/main/resources/plan-definition/cql-applicability-condition/patient.json new file mode 100644 index 0000000000..95c2325113 --- /dev/null +++ b/workflow-testing/src/main/resources/plan-definition/cql-applicability-condition/patient.json @@ -0,0 +1,24 @@ +{ + "resourceType": "Bundle", + "entry": [ + { + "resource": { + "resourceType": "Patient", + "id": "Female-Patient-Example", + "active": true, + "name": [ + { + "use": "official", + "family": "Kensington", + "given": [ + "Amelia" + ] + } + ], + "gender": "female", + "birthDate": "1986-03-18", + "deceasedBoolean": false + } + } + ] +} diff --git a/workflow-testing/src/main/resources/plan-definition/cql-applicability-condition/plan_definition.json b/workflow-testing/src/main/resources/plan-definition/cql-applicability-condition/plan_definition.json new file mode 100644 index 0000000000..45ac9a3851 --- /dev/null +++ b/workflow-testing/src/main/resources/plan-definition/cql-applicability-condition/plan_definition.json @@ -0,0 +1,54 @@ +{ + "resourceType": "Bundle", + "type": "transaction", + "entry": [ + { + "resource": { + "resourceType": "ActivityDefinition", + "id": "Activity-Example", + "url": "http://example.com/ActivityDefinition/Activity-Example", + "status": "active", + "kind": "Task", + "library": [ + "http://example.com/Library/example|1.0.0" + ], + "dynamicValue": [ + { + "path": "description", + "expression": { + "language": "text/cql.identifier", + "expression": "Get Task Description" + } + } + ] + } + }, + { + "resource": { + "resourceType": "PlanDefinition", + "id": "Plan-Definition-Example", + "url" : "http://example.com/PlanDefinition/Plan-Definition-Example", + "status": "active", + "type": "workflow-definition", + "library": [ + "http://example.com/Library/example|1.0.0" + ], + "action": [ + { + "title": "Test for Female Patient", + "definitionCanonical": "http://example.com/ActivityDefinition/Activity-Example", + "condition": [ + { + "kind": "applicability", + "expression": { + "language": "text/cql.identifier", + "expression": "Patient is Female" + } + } + ] + } + ] + } + } + ] +} \ No newline at end of file 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 b1cea04224..9dd1624af7 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 @@ -337,7 +337,9 @@ internal constructor( /* useServerData= */ null, /* bundle= */ null, /* prefetchData= */ null, - /* dataEndpoint= */ null, + /* dataEndpoint= */ Endpoint() + .setAddress("localhost") + .setConnectionType(Coding().setCode(Constants.HL7_FHIR_FILES)), /* contentEndpoint*/ null, /* terminologyEndpoint= */ null ) as IBaseResource 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 1494b70e13..928960a6e6 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 @@ -131,6 +131,28 @@ class FhirOperatorTest { ) } + @Test + fun generateCarePlanWithCqlApplicabilityCondition() = runBlockingOnWorkerThread { + loadFile("/plan-definition/cql-applicability-condition/patient.json", ::importToFhirEngine) + loadFile( + "/plan-definition/cql-applicability-condition/plan_definition.json", + ::installToIgManager + ) + loadFile("/plan-definition/cql-applicability-condition/example-1.0.0.cql", ::installToIgManager) + + val carePlan = + fhirOperator.generateCarePlan( + planDefinitionId = "Plan-Definition-Example", + patientId = "Patient/Female-Patient-Example" + ) + + assertEquals( + readResourceAsString("/plan-definition/cql-applicability-condition/care_plan.json"), + jsonParser.encodeResourceToString(carePlan), + true + ) + } + @Test fun evaluatePopulationMeasure() = runBlockingOnWorkerThread { loadFile("/first-contact/01-registration/patient-charity-otala-1.json", ::importToFhirEngine)