← Back to team overview

dhis2-users team mailing list archive

Re: Help with a program rule

 

Hi there Georgi!
Thanks for the feedback.

It seems you got it almost right except for one little detail on the usage of the substring function. 

To get the fifth character you would have to change your expression to:
 d2:substring(A{Client ID}, 5, 6) == '2'

There was an error in the doc, so a small update is on the way here:
19.5.6. Reference information: Operators and functions to use in program rule expression <https://docs.dhis2.org/master/en/user/html/dhis2_user_manual_en_full.html#program_rules_operators_functions>

Hope this helps!

Best regards
Markus

> 4. aug. 2017 kl. 17.58 skrev Georgi Chakarov <georgi@xxxxxxxxxxxxxxxxxxx>:
> 
> Hi all (again)! J
>  
> I have a challenging task for whoever is interested. I find it quite difficult working with the functions in program rules expression, especially learning from the user manual.
>  
> I am trying to execute the following rule:
> If the fifth character of Client ID (text attribute) is equal to ‘2’, the Sex (Option set attribute) should be equal to ‘Female’. This is an example of client ID: 111121111.
>  
> This is what I think:
> 1)      I need to extract the fifth character and evaluate whether it equals ‘2’. I am using d2:substring(text, start-char-num, end-char-num)
> This is my expression d2:substring(A{Client ID}, 5, 5) == '2'
>  
> 2)      I need to push ‘Female’ option to the Sex attribute. I am not sure how to do that from the program rule actions. I tried:
> a)       Assign value to Sex attribute – expression is ‘Female’
> b)      Assign value to Sex attribute – expression is A{Sex} == 'Female'
>  
> None of the combinations 1) + 2a) OR 1) + 2b) worked, regretfully.
>  
> Does any of you know or can figure out how this might work?
>  
> Regards,
>  
> Georgi 
>  
>  
>   
> Georgi Chakarov, CIA | georgi@xxxxxxxxxxxxxxxxxxx <mailto:georgi@xxxxxxxxxxxxxxxxxxx> | +1-647-478-5634 x 104 | LogicalOutcomes c/o Centre for Social Innovation, 720 Bathurst Street, Toronto Canada M5S 2R4 | You may unsubscribe from receiving commercial electronic messages from LogicalOutcomes by emailing info@xxxxxxxxxxxxxxxxxxx <mailto:info@xxxxxxxxxxxxxxxxxxx>
>  
> _______________________________________________
> Mailing list: https://launchpad.net/~dhis2-users <https://launchpad.net/~dhis2-users>
> Post to     : dhis2-users@xxxxxxxxxxxxxxxxxxx <mailto:dhis2-users@xxxxxxxxxxxxxxxxxxx>
> Unsubscribe : https://launchpad.net/~dhis2-users <https://launchpad.net/~dhis2-users>
> More help   : https://help.launchpad.net/ListHelp <https://help.launchpad.net/ListHelp>

Follow ups

References