Hi everyone! I am new to creating data validation rules in DHIS2. Are there best practices for writing formulas for data validation rules that can check a set of numbers in a table against one total value (not the sum of all, but each individual number)? The screenshot below describes the example where I need each value in the table to be <= the total value in a data element above.
Is there a way to do this without creating (in my case) 48 individual rules, one to check each value? Any help here is greatly appreciated!!
Hi @SydneyDaniel,
Welcome to the community!
You might find these resources helpful:
- Learner's Guide to Validation Rules (Use) - DHIS2 Documentation
- Learner's Guide to Validation Rules (Config) - DHIS2 Documentation
- Metadata - DHIS2 Documentation
I apologize, as far as I know, I’m not able to find such a feature out of the box. Validation rules need to be created individually. How would a functionality work for your case?
If you are using a data set then maybe it’s possible to create a custom design for the data set and use your own HTML code for validation. See here for more details about using your own custom HTML for data sets: Data Sets and Forms - DHIS2 Documentation
The JavaScript function will collect all the values into an array loop through the array, and checks that each element is less than or equal to the value above it.
Hope this helps!
Update: I also did some research, and thought about another way to approach a solution: it seems that your concern is the number of times you’d need to create the validation rule, so for example if you have 100+ fields, you’d need to create them a 100+ times; however, another way to do this is create the Validation Rules in a spreadsheet software where it’s easy to create a formula that will adjust to the fields as required and then save it as a CSV and import it using the Import / Export app. Make sure the correct CSV template is used https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-master/metadata.html#webapi_csv_validation_rules
I think the easier way to do this would be to simply not collect the total, but rather calculate it as the sum of the disaggregates. In this case, you would not need all of the individual validation rules.
Are there cases where the sum of the individual options (“Gene 1 + Category 1” + “Gene2 + Category 1”+ …) do not add up to the total at the top of your screenshot?
Regards,
Jason