Previously, I could access values of a data element with option sets (that only allowed select_one), as below in program rule expressions:
#{cities}='Accra'
and then the rule action follows.
but now these data elements store multiple values. For example the data element ‘Cities’ could store values: ‘Accra’, ‘Cape Town’, ‘Nairobi’.
Which I believe will be comma-seperated (not really sure).
So I’m looking through the d2 functions to see if there’s a d2 command as ‘contains’ or something similar that could tell if the multiselect value contains for example ‘accra’. But I’ve not found a supportive function for this yet.
Great to see you posting, and thanks for the further clarification. Yes, you have clearly explained. I also need to search more and test on play.
Thanks!
Update:
@Quoda, I believe I found the answer to your question.
You can use d2:validatePattern to get the value from the multiselect option set. For example, d2:validatePattern(ProgramRuleVariable,'.*\\bAccra\\b.*') will look for the word in the string and if it’s true, it will return true.
Here’s a quick and short tutorial with more details:
I hope you like it!
Please mark as solved if it solves your question or feel free to ask for more details if it doesn’t work on your side.
I just tried it on a program we have with mutli options (this was a pending question on our side) and i confim your solution works for us.
Thanks for this.
@Gassim I’m just seeing the response. This has escaped me, apologies!
Firstly, the community is thankful to you for making this video. I really appreciate your effort in putting this together. d2:validatePattern does the magic!
I’m trying this out to see how it solves my problem, I’ll surely come with a feedback.
I tested your solution, and it works just fine …
But what about using “contains” or “containsItem”, i tried it and it didn’t work.
even its provided from the DHIS2 documentation, see below youtube video.
@ataallah , in the video you shared it’s mentioning for version 41 and the expression is for program indicators, so if you test in version 41+ in a program indicator the contains() or containsItems() and it’s not working, please create a new topic and I’ll test/triage.