dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #45882
Re: Program indicators - nested d2:condition()?
Thanks Alex, after a bit more digging I think I’ve identified a bug in d2:condition which might be causing this by messing up the quotes in the SQL that is generated (I might still need the brackets though):
This simple d2:condition():
d2:condition(#{wmSb9TmevMn.FlzVuMSdC2F} == 'MONTHS', true, false)
Is translated into this SQL:
select count(distinct psi) as value,"yearly" from analytics_event_2016_jo4aktbheqq where Yearly in ('2016') and (uidlevel1 = 'M4nRM5O3mH8' ) and (case when (FlzVuMSdC2F" = 'MONTHS) then true else false end) group by "yearly" limit 200001
Which
1) is missing a " before FlzVuMSdC2F, AND
2) has stripped off the ‘ after MONTHS
I’ll report it as a bug.
Regards
Olav
> 8. jul. 2016 kl. 13.07 skrev Alex Tumwesigye <atumwesigye@xxxxxxxxx>:
>
> Olav,
>
> I have not tried it, how about using brackets? e.g d2:condition(x1,(d2:condition(x2,(d2:condition(x3,x3true,x3false),x2false),x1false)
>
> I am not sure if the brackets are supported but it will keep it in the same format.
>
> Alex
>
> On Fri, Jul 8, 2016 at 1:55 PM, Olav Poppe <olav.poppe@xxxxxx <mailto:olav.poppe@xxxxxx>> wrote:
> Hi devs,
> I’m trying to set up a program indicator that counts events within age groups. Age is collected with two different methods:
> - Date of birth and date of death
> - Estimated age (when DoB is not available), using one «periodtype» field and one «period count» field, e.g. 4 and Months in two different data elements.
>
> Based on this, I wanted to calculated a few indicators, including «age in years» for individual events, and counting number of events by age groups (0-4 years etc). I figured I could do this by having multiple d2:condition() functions (see below), but that gives «Illegal arguments, expected 3 arguments: condition, true-value, false-value». Can someone confirm whether or not nesting d2:condition() is supported or not, and advice on alternative approaches?
>
> Regards
> Olav
>
>
> d2:condition(#{wmSb9TmevMn.UoL9vGPT0qF} is not null,
> d2:daysBetween(#{wmSb9TmevMn.UoL9vGPT0qF},V{execution_date}) < 1825,
> d2:condition(#{wmSb9TmevMn.FlzVuMSdC2F} == 'YEARS',
> #{wmSb9TmevMn.Zp1elSUYpwI} < 5,
> d2:condition(#{wmSb9TmevMn.FlzVuMSdC2F} == 'MONTHS',
> #{wmSb9TmevMn.Zp1elSUYpwI} < 60
> d2:condition(#{wmSb9TmevMn.FlzVuMSdC2F} == 'WEEKS',
> #{wmSb9TmevMn.Zp1elSUYpwI} < 260,
> d2:condition(#{wmSb9TmevMn.FlzVuMSdC2F} == 'DAYS',
> #{wmSb9TmevMn.Zp1elSUYpwI} < 1825,
> d2:condition(#{wmSb9TmevMn.FlzVuMSdC2F} == 'DAYS',
> #{wmSb9TmevMn.Zp1elSUYpwI} < 43800,
> false)
> )
> )
> )
> )
> )
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dhis2-devs <https://launchpad.net/~dhis2-devs>
> Post to : dhis2-devs@xxxxxxxxxxxxxxxxxxx <mailto:dhis2-devs@xxxxxxxxxxxxxxxxxxx>
> Unsubscribe : https://launchpad.net/~dhis2-devs <https://launchpad.net/~dhis2-devs>
> More help : https://help.launchpad.net/ListHelp <https://help.launchpad.net/ListHelp>
>
>
>
>
> --
> Alex Tumwesigye
>
> Technical Advisor - DHIS2 (Consultant),
> Ministry of Health/AFENET | HISP Uganda
> Kampala
> Uganda
> +256 774149 775 <>, + 256 759 800161 <>
> Skype ID: talexie
>
> IT Consultant (Servers, Networks and Security, Health Information Systems - DHIS2, Disease Outbreak & Surveillance Systems) & Solar Consultant
>
>
> "I don't want to be anything other than what I have been - one tree hill "
Follow ups
References