I need to display region specific option set

I need to provide patient the facility of selecting a region and display region specific provinces. I have created option set accordingly. I need an option → User selects a region and on the next choice user chooses only the provinces that fall under that specific region. How do i do it?

1 Like

Interesting use of option sets! Could you share more about the use case? Maybe there’s also another approach to the same thing.

Are you on Aggregate or Tracker? If you’re using Tracker, you have the option to use a program rule that will show/hide the provinces option sets but depending on how many regions it might be a long task to perform.

hello @Gassim I have two dropdown lists, one for region and another for provinces. It should work like this —> if I select one region, the next dropdown should show only 2 provinces out of 8 provinces and same for other regions as well.

region —> region 1
provinces —> province 1
province 2

it should work like this.

Dear @riwaj.amakomaya
This sounds like a “cascading drop down”. There are many examples of questions about this on the CoP. Short answer is that it is not natively supported by DHIS2 in most cases. You might be able to achieve this to some extent with a program rule, but my feeling is that you would likely need to implement a custom control (maybe using jquery).

Best regards
Jason

1 Like

Hi there,

Basically create 2 optionSets. One for Regions and for Provinces. Then create optionGroups. Name each optionGroups for the respective Region and insert inside all Provinces which belongs to that Region.
Then create a program rule variable for the Region with tick on Use code for optionSet. Then create program rule for each Region so it will run respective program rule for the region and show respective optionGroup.

Regards,

1 Like

@Ulanbek I have already created the option group and the only problem is creating a program rule. Can you help me with the code to apply on the program rule ?

Sure @riwaj.amakomaya.
Could you share the screen shots of what you have done? And then we will move further

  1. Create program rule variable:
    give a name without spaces. Use _ instead of space symbol.


Tick USE CODE FOR OPTION SET

  1. Create a program rule: as a condition use a program rule variable, crated in the step 1 above. compare it with the given Region’s code

  1. Create an action
    select DataElement where to show that province name, and option group with the list of Provinces to be shown.

  2. Repeat the steps above for each Region

Should you have any further questions, feel free to ask
Regards,

1 Like

these are the regions and I have grouped the districts(regions) with their respcetive provinces



now how do i use program rule function to to show/hide the districts and only show districts of selected province ?

@riwaj.amakomaya hi, is it something like this you wish to implement?
1.
image
2.
image
3.
image

1 Like

@e4eDHIS2 yes I am confused with the program rule , can you share me how do you do it?

@riwaj.amakomaya Sure. Firstly I created a data element “Select your region”, and gave it an option set with all the regions as options, then went further to create three additional data elements - one for each of my regions so I can assign them the provinces as option sets :

  • Select Region 1 Province

  • Select Region 2 Province

  • Select Region 3 Province

Secondly, I created a program rule variable next with the source type “data element from the newest event in the current program” and data element “select your region”, and tick “use option code”.

Thirdly, for the program rule, I created 3 program rules. One for each province. The expression is: #{program_rule_variable} != ‘1’, while the program rule is to hide the field select region 1 province. Do the same thing to create the two other program rules for the remaining two data elements.

You can also find the program on https://play.dhis2.org as Program “1. Test”

I hope our response is able to solve the issue you were facing.
With :heavy_heart_exclamation: from the Dhistance Team.
DHISTANCE.com: The Easiest DHIS2 Setup. Up and running in 5 minutes!
No technical knowledge needed! Great Support with Data Security/Confidentiality.

1 Like

@riwaj.amakomaya done on DHIS 2 Demo - Sierra Leone

program Test1

DHIS2.38.3 - Metadata file attached below
metadata.json (44.7 KB)

2 Likes

Hello @Ulanbek Metadata is not working and I am unable to find it in DHIS 2 Demo, could you please share the link of Demo ?

This is what I have done till now






Hi @riwaj.amakomaya ,

Everyday the play-demo servers are reset to the initial state. Therefore you wouldn’t be able to find anything previously created. I have recreated for you a demo tracker: Region-Province Demo on DHIS 2 Demo - Sierra Leone

Metadata file is attached below.

Region-Proince-Demo-metadata.json (19.8 KB)

2 Likes

@Ulanbek It worked fine.

1 Like