How do I create program rule for Age value type?

Hi there,

I’m trying to create a program rule for the value type Age (TEA). I’d like to hide a TEA field during registration if the individual is aged 16 years or over.

I can’t work out the syntax - any help much appreciated!

Thank you
Anna

3 Likes

Hi @adownie,

Great to see you again here!

have you checked out some related posts on the same?

  1. d2: daysbetween AND d2:yearsbetween not working properly in 2.27 build revision b6e8cde
  2. Program rule for Age value type
  3. Using age-type attributes in program indicator calculations
  4. Programme Rules
  5. Storing value type 'Age' in numeric form

Let me know if they help.

Best,
James.

2 Likes

Thanks James, I’ve read all of those links and not found anything that works (or maybe i’ve not understood them- my coding is very very basic). I’ve tried:

d2:yearsBetween(A{Date of Birth}, V{ enrollment _date}) >=16

and

#{age_value_type} >=16

But neither seem to work.

Any other suggestions?

2 Likes

This one should work as it seems correct

@Emma_Kassy / @Calle_Hedberg ; kindly help out here.

Best,
James.

2 Likes

Hi,

I’m not sure about the age value type, haven’t used it since there were some issues with it.

But d2:yearsBetween(A{Date of Birth}, V{ enrollment _date}) >=16 should be working, although I would rather use
d2:hasValue(‘Date of Birth’) && d2:yearsBetween(A{Date of Birth}, V{ enrollment _date}) >=16

Regards
Calle

3 Likes

@adownie

I just noticed that JIRA issue DHIS2-6065 indicates that there has been a problem with using the Age data type in various functions. It was fixed 1-2 weeks ago, but it might affect you if you are using an earlier build.

Also, are you getting any errors in the Chrome Console? (CTRL-SHIFT-J to open the console).

Regards
Calle

3 Likes

Thanks for the update and always coming through @Calle_Hedberg! :smile:

Best,
James.

2 Likes

Thank you so much everyone! I will try out your suggestions and let you know if it works.

3 Likes

I’ve used:

d2:yearsBetween(A{SRHU Age}, V{enrollment_date}) >=16

Weirdly, this now seems to hide the DE regardless of the age of the person

However, i suspect we will need to update our build to see if that solves it as we last updated before the fix was found.

3 Likes

Hi there @Anna!
It seems you are affected by this bug: DHIS2-6336

You can watch the issue to follow its resolution. In the meantime it will probably fix your problem if you change from “Age” to “Date” data types. Although you will loose the auto-calculation features that the Age provides.

Markus

3 Likes