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

Workflow: Optional Encounter ID and Search By URL expansion #1741

Merged
merged 12 commits into from
Dec 5, 2022
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ 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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -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"
}]
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@

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
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

class FhirEngineDal(private val fhirEngine: FhirEngine) : FhirDal {
Expand All @@ -50,18 +50,21 @@ class FhirEngineDal(private val fhirEngine: FhirEngine) : FhirDal {
}

override fun search(resourceType: String): Iterable<IBaseResource> = runBlocking {
val search = Search(type = ResourceType.fromCode(resourceType))
when (resourceType) {
"Patient" -> fhirEngine.search<Patient> {}.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<IBaseResource> =
runBlocking {
val search = Search(type = ResourceType.fromCode(resourceType))
search.filter(UriClientParam("url"), { value = url })

when (resourceType) {
"Measure" -> fhirEngine.search<Measure> { 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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,15 @@ class FhirOperator(fhirContext: FhirContext, fhirEngine: FhirEngine) {
)
}

fun generateCarePlan(planDefinitionId: String, patientId: String, encounterId: String): CarePlan {
fun generateCarePlan(planDefinitionId: String, patientId: String): CarePlan {
vitorpamplona marked this conversation as resolved.
Show resolved Hide resolved
return generateCarePlan(planDefinitionId, patientId, encounterId = null)
}

fun generateCarePlan(
planDefinitionId: String,
patientId: String,
encounterId: String?
): CarePlan {
return planDefinitionProcessor.apply(
IdType("PlanDefinition", planDefinitionId),
patientId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,26 @@ 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,12 @@ 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")
}