opensrp / fhircore

FHIR Core / OpenSRP 2 is a Kotlin application for delivering offline-capable, mobile-first healthcare project implementations from local community to national and international scale using FHIR and WHO Smart Guidelines on Android.
https://smartregister.org
Apache License 2.0
50 stars 39 forks source link

Update Event Management configs to specify resource type in the filter expression and values to update #3149

Closed Rkareko closed 3 months ago

Rkareko commented 3 months ago

Describe the feature request. The current event management configuration has a list of UpdateWorkflowValueConfigs (a list of values to update) and resourceFilterExpression (used to filter resources that will be updated).

Both the updateValues and resourceFilterExpression will be applied to all the resources defined in the eventWorkFlow config. This is an issue since one eventWorkFlow can be used to define multiple resources for closure e.g a Careplan with related Tasks and Conditions.

The current configs need to be updated so that it's clear which resource type the updateValues and resourceFilterExpression are referencing.

Acceptance criteria

Implementation plan (For Engineers)

Sample of the updated values

 "updateValues": [
                  {
                    "jsonPathExpression": "Task.status",
                    "value": "cancelled",
                    "resourceType": "Task"
                  },
                  {
                    "jsonPathExpression": "CarePlan.status",
                    "value": "completed",
                    "resourceType": "CarePlan"
                  },
                  {
                    "jsonPathExpression": "ServiceRequest.status",
                    "value": "revoked",
                    "resourceType": "ServiceRequest"
                  },
                  {
                    "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"
                  },
                  {
                    "conditionalFhirPathExpressions": [
                      "ServiceRequest.status != 'completed'"
                    ],
                    "resourceType": "ServiceRequest"
                  }
                ]

Here is a sample of a complete eventWorkFlow config

{"eventWorkflows": [
              {
                "eventType": "RESOURCE_CLOSURE",
                "triggerConditions": [
                  {
                    "eventResourceId": "carePlanToBeClosed",
                    "conditionalFhirPathExpressions": [
                      "true"
                    ]
                  },
                  {
                    "eventResourceId": "referralServiceRequestToBeClosed",
                    "conditionalFhirPathExpressions": [
                      "%resource.entry.where(resource is QuestionnaireResponse).resource.where(questionnaire = 'Questionnaire/dc-remove-patient').exists() and %resource.entry.where(resource is QuestionnaireResponse).resource.repeat(item).where(linkId = 'reason-for-removal' and (answer.value.code = 'died' or answer.value.code = 'moved-away')).exists()"
                    ]
                  }
                ],
                "eventResources": [
                  {
                    "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"
                      }
                    ]
                  },
                  {
                    "id": "referralServiceRequestToBeClosed",
                    "resource": "ServiceRequest",
                    "configRules": [
                      {
                        "name": "patientId",
                        "condition": "true",
                        "actions": [
                          "data.put('patientId', fhirPath.extractValue(Patient, 'Patient.id'))"
                        ]
                      }
                    ],
                    "dataQueries": [
                      {
                        "paramName": "code",
                        "filterCriteria": [
                          {
                            "dataType": "CODEABLECONCEPT",
                            "value": {
                              "system": "http://snomed.info/sct",
                              "code": "44383000"
                            }
                          }
                        ]
                      },
                      {
                        "paramName": "subject",
                        "filterCriteria": [
                          {
                            "dataType": "REFERENCE",
                            "computedRule": "patientId"
                          }
                        ]
                      }
                    ]
                  }
                ],
                "updateValues": [
                  {
                    "jsonPathExpression": "Task.status",
                    "value": "cancelled",
                    "resourceType": "Task"
                  },
                  {
                    "jsonPathExpression": "CarePlan.status",
                    "value": "completed",
                    "resourceType": "CarePlan"
                  },
                  {
                    "jsonPathExpression": "ServiceRequest.status",
                    "value": "revoked",
                    "resourceType": "ServiceRequest"
                  },
                  {
                      "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"
                  },
                  {
                    "conditionalFhirPathExpressions": [
                      "ServiceRequest.status != 'completed'"
                    ],
                    "resourceType": "ServiceRequest"
                  }
                ]
              }
            ]
}