Skip to main content

Resource closure using configured questionnaires

Event management implementation provides the ability to configure a questionnaire so that we can state which resources to close when it is submitted.

Some use cases would be -

  • Closing CarePlans and Tasks for a patient/family when they are removed.
  • Closing child-related CarePlans and Tasks if a patient's age is updated to more than 5 years.
  • Closing ANC CarePlan and Tasks when a pregnancy outcome form is submitted.

This is achieved by use of the EventWorkFlow config.

Sample event workflow configuration


{
"eventWorkflows": [
{
"eventType": "RESOURCE_CLOSURE",
"eventResources": [
{
"id": "sickChildConditionToBeClosed",
"resource": "Condition",
"configRules": [
{
"name": "patientId",
"condition": "true",
"actions": [
"data.put('patientId', fhirPath.extractValue(CarePlan, 'CarePlan.subject.reference'))"
]
}
],
"dataQueries": [
{
"paramName": "code",
"filterCriteria": [
{
"dataType": "CODEABLECONCEPT",
"value": {
"system": "http://snomed.info/sct",
"code": "275142008"
}
}
]
},
{
"paramName": "subject",
"filterCriteria": [
{
"dataType": "REFERENCE",
"computedRule": "patientId"
}
]
}
]
},
{
"id": "carePlanToBeClosed",
"resource": "CarePlan",
"configRules": [
{
"name": "patientId",
"condition": "true",
"actions": [
"data.put('patientId', fhirPath.extractValue(Patient, 'Patient.id').contains('Patient') ? fhirPath.extractValue(Patient, 'Patient.id') : 'Patient/' + fhirPath.extractValue(Patient, 'Patient.id'))"
]
}
],
"dataQueries": [
{
"paramName": "instantiates-canonical",
"filterCriteria": [
{
"dataType": "REFERENCE",
"value": "PlanDefinition/dc-diabetes-screening-intervention"
}
]
},
{
"paramName": "subject",
"filterCriteria": [
{
"dataType": "REFERENCE",
"computedRule": "patientId"
}
]
}
],
"relatedResources": [
{
"resource": "Task",
"searchParameter": "based-on"
}
]
}
],
"updateValues": [
{
"jsonPathExpression": "Task.status",
"value": "cancelled",
"resourceType": "Task"
},
{
"jsonPathExpression": "CarePlan.status",
"value": "completed",
"resourceType": "CarePlan"
},
{
"jsonPathExpression": "Condition.clinicalStatus.coding[0].code",
"value": "370996005",
"resourceType": "Condition"
},
{
"jsonPathExpression": "Condition.clinicalStatus.coding[0].system",
"value": "http://www.snomed.org/",
"resourceType": "Condition"
},
{
"jsonPathExpression": "Condition.clinicalStatus.coding[0].display",
"value": "resolved",
"resourceType": "Condition"
}
],
"resourceFilterExpressions": [
{
"conditionalFhirPathExpressions": [
"Task.status != 'completed'"
],
"resourceType": "Task"
}
]
}
]
}

The current implementation eventWorkflow config only handle closure of resources, hence the event type defaults to RESOURCE_CLOSURE. This implementation can be expanded in future to handle other types of events.

The trigger conditions determine whether to close resources depending on the the result of evaluating the fhirpath expressions. The fhirpath expressions can be run against

  1. The subject of the questionnaire e.g Patient.active
  2. The Bundle resource which contains the QuestionnaireResponse, the subject as well as additional resources. An example expression would be %resource.entry.where(resource is QuestionnaireResponse).resource.where(questionnaire = 'Questionnaire/450cb100-0c5b-47c6-9f33-2830a79be726').exists()
  3. A combination of both the subject and Bundle e.g Patient.active AND %resource.entry.where(resource is QuestionnaireResponse).resource.where(questionnaire = 'Questionnaire/450cb100-0c5b-47c6-9f33-2830a79be726').exists()

The event resources define which resource is eligible for closure as well as any related resources.

The data queries define how to search for and filter the resources from the database.

Once the resources have been retrieved from the database, the next step is to close the resources by updating the values of certain fields. For the current implementation this has been done in the code. This is not configurable at this point. Closure of any resource that has not been handled will need an update to the code that performs resource closure.

The following table contains the values for each field that is required to close a resource.field

ResourceFieldValue
CareplanstatusCompleted
Taskstatuscancelled
lastModifiedcurrent date
ConditionCondition.clinicalStatuscode:370996005, display:resolved, system: http://www.snomed.org/
ProcedureProcedure.statusstopped
ServiceRequeststatusrevoked

EventWorkflows properties

PropertyDescriptionRequiredDefault
eventTypeThe intention of the eventWorkflow. E.g close resourcesyesRESOURCE_CLOSURE is supported for now
triggerConditionsThis defines an array of condition for to be met for the event to runnonull
eventResourceIduniqueId of resource id to be closedyes
eventResourcesA list of resources to close(Type of ResourceConfig)yes
updateValuesDefines a list of jsonPath expressions for the fields to update as well as the values to useyes
resourceFilterExpressionsA list of FhirPath expressions used to filter which resources to closeno

Trigger condition properties

PropertyDescriptionRequiredDefault
eventResourceIdUniqueId of resource that the trigger conditions are applied toyesRESOURCE_CLOSURE is supported for now
conditionalFhirPathExpressionscriteria to ensure we only close the intended resourcesyes
matchAllDetermines whether all conditional fhirpath expressions should evaluate to truenoTrue
True - Close resources only when all fhirpath expressions evaluate to true
False - Close resources when one or more fhirpath expressions evaluate to true

Event Resource Properties

PropertyDescriptionRequiredDefault
iduniqueId of resource id to be closedyes
resourceThe type of resourceyes
configRulesRules to be that are executed to populate dynamic values such as a patient idno
dataQueriesConfigs used to represent how resources to be closed are retrieved from the databaseyes
relatedResourcesConfigs that represent how to fetch related resources e.g Tasks linked to a CarePlanno

DataQuery properties

PropertyDescriptionRequiredDefault
paramNameString representation of the resource field to search onyes
operationLogical SQL operation to perform i.e AND, ORyesAND
filterCriteriaConfigs that represent the datatype and value for filtering datayes

UpdateValue properties

PropertyDescriptionRequiredDefault
jsonPathExpressionJsonPath representation of the resource field to updateyes
valueThe value to update the resource field withyes
resourceTypeThe name of the resource type to be updatedyes

Resource Filter Expression properties

PropertyDescriptionRequiredDefault
conditionalFhirPathExpressionsCriteria to filter which resources when only a subset of the fetched resources need to be updated e.g only update tasks whose status is not completedyes
matchAllDetermines whether all conditional FhirPath expressions should evaluate to truenotrue
resourceTypeThe name of the resource type to be updatedyes