Skip to content

Commit

Permalink
Add Dynamic data pass between profiles and questionnaires documentati…
Browse files Browse the repository at this point in the history
…on (#2965)

* ## Dynamic data pass between profiles and questionnaires.mdx

* Update working-with-rules.mdx

* Update application.mdx

* Update questionnaire.mdx

* Update questionnaire.mdx

* Update questionnaire.mdx

* Update questionnaire.mdx

* Update questionnaire.mdx

* Update questionnaire.mdx
  • Loading branch information
Raynafs authored Jan 12, 2024
1 parent 4dc61ff commit 3701a18
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ title: Application
These are app wide configurations used to control the application behaviour globally e.g. application theme, app language etc.

:::note
There can only one instance of application configuration for the entire application. There are instances where the `Event Workflow` is added to the application config. See [here](https://docs.opensrp.io/engineering/android-app/configuring/event-management/resource-closure-by-background-worker)
There can only be one instance of application configuration for the entire application. There are instances where the `Event Workflow` is added to the application config. See [here](https://docs.opensrp.io/engineering/android-app/configuring/event-management/resource-closure-by-background-worker)
:::

## Sample JSON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,104 @@ These are used when generating other tasks, CarePlans and related resources.See
| onSubmitActions | Configurations for actions invoked post Questionnaire submission | no | null |
| extractedResourceUniquePropertyExpressions | Configurations for unique properties used to identify resources during Questionnaire edit | no | null |

## Dynamic data pass between Profiles and Questionnaires

For you to pass data between profiles and questionnaires you can make use of **action config params** which are executed when **LAUNCH_QUESTIONNAIRE** is invoked.

Data extraction happens during rules execution and is persisted in `computedValuesMap` which is later used to interpolate values annotated with `@value`. See [working with rules] (https://docs.opensrp.io/engineering/android-app/configuring/working-with-rules).

For example, in the `underlying_conditions` questionnaire you would like to show or hide the Cancer option based on whether the patient has cancer or not. The solution would be to pass `has-cancer` BOOLEAN from `adult_profile_config` to `underlying_conditions`.

Assuming that the `LAUNCH_QUESTIONAIRE` `onClick` function of `adult_profile_config` takes you to `underlying_conditions` questionnaire screen, below is a practical example of how the data would be passed.

### Cancer LAUNCH_QUESTIONAIRE
#### Sample JSON
1. Write rules to extract the data you need.
``` json
"rules":[
{
"name": "hasCancer",
"condition": "true",
"priority": 1,
"actions": [
"data.put('hasCancer', service.evaluateToBoolean(availableConditions, \"Condition.code.coding.code = '363346000' and Condition.clinicalStatus.coding.code = 'active'\", false))"]
},
]
```

2. add your params at **LAUNCH_QUESTIONNAIRE** section of adult_profile_config.json
#### Sample JSON
``` json
{ "trigger": "ON_CLICK",
"workflow": "LAUNCH_QUESTIONNAIRE",
"questionnaire": {
"id": "54497",
"title": "Record Comorbidity",
"resourceIdentifier": "@{patientId}",
"params": [
{
"key": "familyLogicalId",
"value": "@{familyLogicalId}",
"paramType": "UPDATE_DATE_ON_EDIT"
}
]
},
"params": [
{
"paramType": "PREPOPULATE",
"linkId": "has-cancer",
"dataType": "BOOLEAN",
"key": "hasCancer",
"value": "@{hasCancer}"
}],
}
```

On the `underlying_conditions` questionnaire side, we will then call the `has-cancer` linkId that was declared in the `adult_profile_config`, as shown in the example below.
``` json
{
"extension": [ {
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden",
"valueBoolean": true
} ],
"linkId": "has-cancer",
"definition": "http://hl7.org/fhir/StructureDefinition/Resource#Resource.id",
"type": "boolean"
}, {
"linkId": "e4b02bd1-faa3-415e-84e7-378b8cc84d92",
"text": "Cancer",
"type": "choice",
"enableWhen": [ {
"question": "9f320854-7677-4ecb-9886-d323b7161a2e",
"operator": "=",
"answerCoding": {
"system": "urn:uuid:5fddcabd-9ae1-412a-e591-8fb6089a4f26",
"code": "yes"
}
}, {
"question": "has-cancer",
"operator": "=",
"answerBoolean": false
} ],
"enableBehavior": "all",
"required": false,
"answerOption": [ {
"valueCoding": {
"id": "727795dd-2870-4bc2-e057-4aa8518405dd",
"system": "urn:uuid:5fddcabd-9ae1-412a-e591-8fb6089a4f26",
"code": "yes",
"display": "Yes"
}
}, {
"valueCoding": {
"id": "944752c4-b116-4bca-8bc0-7e2889219565",
"system": "urn:uuid:5fddcabd-9ae1-412a-e591-8fb6089a4f26",
"code": "no",
"display": "No"
}
} ]
}
```


## Sample questionnaire with an event workflow
Expand Down Expand Up @@ -215,3 +313,4 @@ eventType |The intention of the eventWorkflow. E.g close resources | yes | RESOU
triggerConditions | This defines an array of condition for to be met for the event to run | no | null |
eventResourceId | uniqueId of resource id to be closed | yes | |
eventResources | A list of resources to close(Type of ResourceConfig) | yes | | |

Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ priority | Specifies the priority of the component. The priority value determine

## Using the `generateTaskServiceStatus()` rule

This rule is used within the ruels engine or workflow to generate the correct service status when given the `Task.status` . Only one parameter is passed of the type `TaskStatus`. Below is an example:
This rule is used within the rules engine or workflow to generate the correct service status when given the `Task.status` . Only one parameter is passed of the type `TaskStatus`. Below is an example:

```
Expand All @@ -94,8 +94,8 @@ This rule is used within the ruels engine or workflow to generate the correct se
Below is a sample rules config to extract practitioner details from shared preferences. Note, the parameter passed inside extractPractitionerInfoFromSharedPrefs
should be named as shown on the rule. i.e

| ParamName | Description | SharedPrefKey |
|--|--|:--:|:--:|
|ParamName | Description | SharedPrefKey |
|--|--|:--:|
practitionerId | This is the assigned practitioner's ID | PRACTITIONER_ID |
organization | This is the assigned practitioner's Organization | ORGANIZATION |
careTeam | This is the assigned practitioner's Care Team | CARE_TEAM |
Expand Down Expand Up @@ -130,4 +130,4 @@ practitionerLocation | This is the assigned practitioner's Location | PRACTITION
"data.put('practitionerLocation',service.extractPractitionerInfoFromSharedPrefs('PRACTITIONER_LOCATION'))"
]
}
```
```

0 comments on commit 3701a18

Please sign in to comment.