avniproject / avniproject/rules-config
Rule condition not working for repeatable question group
- Dominant language
- JavaScript
- Stars
- 0
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
**Usecase:**
In LAHI alumini profile encounter, want to calculate some of the statuses(Employed and Higher Technical Education) of "LAHI alumini status" based on value in a repeatable question group.
**Issues:**
The below doesn't work:
`const condition15 = new imports.rulesConfig.RuleCondition({programEncounter, formElement}).when.valueInEncounter(childConceptUuid, parentConceptUuidOfQuestionGroup).containsAnswerConceptName(answerConceptValue).matches();` and
`const condition12 = new imports.rulesConfig.RuleCondition({programEncounter, formElement}).when.valueInEncounter("07b7866f-1318-48f1-9cde-3720131575c1","a284be97-2fb7-44e7-9891-b90f166aa532").containsAnswerConceptName("f69d34d8-0316-43b7-b211-653b38ba69d8").matches();`
**Analysis:**
- The above didn't work since findObservation in avni-models, AbstractEncounter.js didn't handle for repeatable question group.
Hence currently, function like below is done:
```
const isObservationPresentInParentConcept = (valueConceptUuid, childConceptUuid, parentConceptUuidOrName) => {
const obs = programEncounter.findObservation(parentConceptUuidOrName);
const repeatableObservations = obs && obs.getValueWrapper() && obs.getValueWrapper().repeatableObservations;
const condition12 = repeatableObservations && _.some(repeatableObservations, (repeatableObservation) => {
const observation = repeatableObservation && repeatableObservation.findObservationByConceptUUID(childConceptUuid);
const obsValue = observation && observation.getValue();
return (obsValue === valueConceptUuid);
});
return condition12;
}
const condition25 = _.some(["a06c3964-c2de-4ec4-ac12-5dda94122ade","9fee1da4-9002-49b0-a343-05490c073fb8"],
(valueConceptUuid) => isObservationPresentInParentConcept(valueConceptUuid, "30843b2e-37d8-459d-b0ae-f1feaa744cb0", "edb38ea2-9547-49ba-9d74-a84db74e4a4a"));
```
- The below also cannot be done:
`const condition12 = new imports.rulesConfig.RuleCondition({programEncounter, formElement}).when.questionGroupValueInEncounter("07b7866f-1318-48f1-9cde-3720131575c1","a284be97-2fb7-44e7-9891-b90f166aa532", questionGroupIndex).containsAnswerConceptName("f69d34d8-0316-43b7-b211-653b38ba69d8").matches();` since need to iterate for each value(questionGroupIndex) in repeatable observations.
- Need to Handle all cases where the values of repeatable question group could be multiple or empty
**Significance of fixing this issue:**
- For projects that self-manage like LAHI, fixing this will make their work easier.
- Code duplication in implementations
- Slows down work of implementation
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading RuleCondition and the mentioned findObservation implementation in avni-models' AbstractEncounter.js, then trace how valueInEncounter handles question-group observations. Done means rule conditions can check values across repeatable groups, including multiple and empty groups, without callers duplicating iteration logic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100