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 mangement logic to factor in resource type when closing resources #3152

Closed Rkareko closed 3 months ago

Rkareko commented 3 months ago

IMPORTANT: Where possible all PRs must be linked to a Github issue

Fixes #3149

Engineer Checklist

Code Reviewer Checklist

Rkareko commented 3 months ago

Sample of the updated values

    {
      "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"
                  }
                ]
              }
            ]
}
codecov[bot] commented 3 months ago

Codecov Report

Attention: Patch coverage is 77.14286% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 29.8%. Comparing base (ac82739) to head (8e28d73). Report is 7 commits behind head on main.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/opensrp/fhircore/pull/3152/graphs/tree.svg?width=650&height=150&src=pr&token=IJUTHZUGGH&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensrp)](https://app.codecov.io/gh/opensrp/fhircore/pull/3152?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensrp) ```diff @@ Coverage Diff @@ ## main #3152 +/- ## ========================================= + Coverage 29.6% 29.8% +0.1% - Complexity 658 660 +2 ========================================= Files 239 239 Lines 11204 11208 +4 Branches 1948 1944 -4 ========================================= + Hits 3323 3344 +21 + Misses 7447 7427 -20 - Partials 434 437 +3 ``` | [Flag](https://app.codecov.io/gh/opensrp/fhircore/pull/3152/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensrp) | Coverage Δ | | |---|---|---| | [engine](https://app.codecov.io/gh/opensrp/fhircore/pull/3152/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensrp) | `66.5% <77.1%> (+0.3%)` | :arrow_up: | | [geowidget](https://app.codecov.io/gh/opensrp/fhircore/pull/3152/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensrp) | `47.2% <ø> (ø)` | | | [quest](https://app.codecov.io/gh/opensrp/fhircore/pull/3152/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensrp) | `5.4% <ø> (+<0.1%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensrp#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files](https://app.codecov.io/gh/opensrp/fhircore/pull/3152?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensrp) | Coverage Δ | | |---|---|---| | [...ircore/engine/configuration/event/EventWorkflow.kt](https://app.codecov.io/gh/opensrp/fhircore/pull/3152?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensrp#diff-YW5kcm9pZC9lbmdpbmUvc3JjL21haW4vamF2YS9vcmcvc21hcnRyZWdpc3Rlci9maGlyY29yZS9lbmdpbmUvY29uZmlndXJhdGlvbi9ldmVudC9FdmVudFdvcmtmbG93Lmt0) | `80.0% <100.0%> (-4.7%)` | :arrow_down: | | [...re/engine/domain/model/ResourceFilterExpression.kt](https://app.codecov.io/gh/opensrp/fhircore/pull/3152?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensrp#diff-YW5kcm9pZC9lbmdpbmUvc3JjL21haW4vamF2YS9vcmcvc21hcnRyZWdpc3Rlci9maGlyY29yZS9lbmdpbmUvZG9tYWluL21vZGVsL1Jlc291cmNlRmlsdGVyRXhwcmVzc2lvbi5rdA==) | `83.3% <100.0%> (+3.3%)` | :arrow_up: | | [...er/fhircore/engine/data/local/DefaultRepository.kt](https://app.codecov.io/gh/opensrp/fhircore/pull/3152?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensrp#diff-YW5kcm9pZC9lbmdpbmUvc3JjL21haW4vamF2YS9vcmcvc21hcnRyZWdpc3Rlci9maGlyY29yZS9lbmdpbmUvZGF0YS9sb2NhbC9EZWZhdWx0UmVwb3NpdG9yeS5rdA==) | `68.2% <72.4%> (+0.2%)` | :arrow_up: |
Rkareko commented 3 months ago

App crashes when loading Profile screen. Do not merge till this is fixed.

ellykits commented 3 months ago

App crashes when loading Profile screen. Do not merge till this is fixed.

@Rkareko This could be related to the updated configs. The existing configs need to be updated for the rest of the apps using this feature.

ellykits commented 3 months ago

Update the docs, then we can have this merged.