Frameworks for use in rules

Error handling

If something goes wrong during the triage of incoming measurements, it is important to inform the clinicians that they need to manually evaluate the received measurement. Depending on the type of failure, a task should be created to fix the problem.

The following types of exceptional situations have been identified during early testing of rules with clinicians.

Situation

Error

Cause

Handling

Situation

Error

Cause

Handling

Library rule expects Observation or QuestionnaireResponse

Wrong input

Library linked with activity producing Observation where QuestionnaireResponse expected (or vice versa)

  1. Create task to CareTeam that other PlanDefinition related to Library with matching input should be created or used. 

Library for rule requires reference range, none defined.

No reference range

Could be caused by wrong configuration (by PlanDefinition editor) or because CareTeam for particular CarePlan has removed the reference range.

  1. Rule could have fallback

  2. Create task for CareTeam to add reference range of proper type

Library for rule requires relative reference range type, only absolute reference range currently defined.

No reference range of proper type

Could be caused by wrong configuration (by PlanDefinition editor) or because CareTeam for particular CarePlan has removed the proper reference range.

  1. Rule could have fallback

  2. Create task for CareTeam to add reference range of proper type

Library for rule requires reference ranges for components (Observation.component), none or only one defined.

No reference range for particular component (code)

Could be caused by wrong configuration (by PlanDefinition editor) or because CareTeam for particular CarePlan has removed the proper reference range.

  1. Rule could have fallback

  2. Create task for CareTeam to add reference range of proper type

Library for rule requires reference range, wrong unit defined

Unit mismatch

Could be caused by wrong configuration (by PlanDefinition editor) or because CareTeam for particular CarePlan has updated reference range with wrong unit.

  1. Create task for CareTeam to correct unit

Library for rule is relative and requires an active reference base to compare to.

No reference base / Reference base code mismatch

Could be caused by wrong configuration (by PlanDefinition editor) or because CareTeam for particular CarePlan has removed the reference base.

  1. Rule could have fallback

  2. Create task for CareTeam to add reference base in force

Library for rule is relative and requires an active reference base to compare to.

No active reference base

Could be caused by reference base expiry.

  1. Rule could have fallback

  2. Create task for CareTeam to add reference base in force

Library for rule requires reference base, wrong unit defined

Unit mismatch

Could be caused by wrong configuration (by PlanDefinition editor) or because CareTeam for particular CarePlan has updated reference base with wrong unit.

  1. Create task for CareTeam to correct unit

Library for rule is relative and expects historic (previous) Observation within period of time

No historic Observation found

First Observation submitted or no Observation submitted in period.

  1. Rule could have fallback

  2. Create task to CareTeam that other PlanDefinition with other related Library with other period of time should be considered/be applied to Patient

    1. This does not handle first Observation submitted

Library for rule expects QuestionnaireResponse with specific, required question/answer

Question/answer required by rule cannot be found

Either:

  • Rule is requiring answer for a question which is not enabled (or in path) or the question is optional

  • Rule is used with a Questionnaire where the required question/answer has been removed.

  1. Rule could have fallback, alternative handling

  2. Create task to CareTeam that answer required by the rule has not been provided.

Coding error in rule/unforeseen and unhandled error situation

NullPointerException

Missing guards

Log entry

To help handle these situations a number of RuleExecutionExcptions have been defined and made available to the rules:

  • MismatchedInput

  • ReferenceRangeMissing

  • ReferenceRangeError

  • ReferenceBaseMissing

  • ReferenceBaseError

  • QuestionnaireResponseMissing

If the rule throws one of these exceptions, then two tasks will be created:

  • A task telling the clinician to perform a manual evaluation of the incoming measurement:

    • task-category: MeasurementForAssessmentFailureInAutoProcessing

    • priority: routine

    • description: Måling til vurdering (fejl forekommet under automatisk behandling)

  • A task for fixing the problem:

    • task-category: matching the exception

    • priority: routine

    • description: Matching the exception + any addition detailed error message provided by the rule

    • focus: default is the evaluated measurement, but can be overridden by the rule.

Example of error handling in a rule

function void throwMismatchedInputException(String ruleDescription, String focus) { throw new MismatchedInputException(ruleDescription, focus); } rule "COPDQuestionnaireFUTTriageRule" dialect "java" when $qrs : Collection() $listQrs : ArrayList() from collect (QuestionnaireResponse() from $qrs) $questionnaire : Questionnaire() $serviceRequest : ServiceRequest() then if ($listQrs.isEmpty()) { throwMismatchedInputException("Manglende input. Forventede én spørgeskemabesvarelse", $serviceRequest.getId()); }

This rule expects a QuestionnaireResponse as the primary input. If it is not found - for example because an observation was provided instead - then a MismatchedInputException is thrown with a detailed error description and the ServiceRequest as the focus.

DefinedQuestions in rules for QuestionnaireResponses example

This is a map of questions and answers that results in red alerts. The key is the Questionnaire.item.definition URL without business version. A similar map exists for yellow alerts. The rule can be expanded with more questions and answers without changing anything else.

function Map<String, List<String>> getRedTriggerMap() { Map<String, List<String>> result = new HashMap<>(); result.put("http://ehealth.sundhed.dk/DefinedQuestion/f2199b4f-f454-414f-9b27-c1ab80f5ae48", List.of("En del", "Meget")); // S5.b result.put("http://ehealth.sundhed.dk/DefinedQuestion/002efb9b-0efc-49c7-81d5-3f4542a5658f", List.of("En del", "Meget")); // S6.b result.put("http://ehealth.sundhed.dk/DefinedQuestion/b9610f7d-df61-4988-8566-b58c1d3b9b14", List.of("En del", "Meget")); // S7.b result.put("http://ehealth.sundhed.dk/DefinedQuestion/cf55d29c-eabd-4909-9824-69d4690f2332", List.of("Mørkt")); // S9.a result.put("http://ehealth.sundhed.dk/DefinedQuestion/843302ef-6623-42f1-b4e3-95fcb74e3108", List.of("En del", "Meget")); // S10.b return result; }

The business version is stripped from the url by discarding the part after |

function String getVersionlessDefinition(String definition) { if (definition.contains("|")) { return definition.substring(0,definition.indexOf("|")); } return definition; }

The URL is found by using the link from the answer in the QuestionnaireResponse to look at the corresponding question in the Questionnaire

The rule results in a yellow ClinicalImpression finding if any yellow answers are found and a red finding if any red answers are found. If no red or yellow answers are found, then the result is a green finding.

Task priority is determined by the worst finding