[SOLVED] Validation of HTML Form Entry forms against target setup?

We are building custom forms, however I would like to run automated validation tests for these forms using HTML Form Entry.

What I am looking to validate:

  1. Concepts exist
  2. Encounters, Identifiers and Provider tags are valid
  3. Required values are entered (driven by test data)

Are there examples of such tests and how would I approach this?

@mogoodrich @darius @dkayiwa @wyclif @arbaughj any suggestions?

Hi Musoke,

For the first 2, I think you can register a custom validator for your forms which will get invoked every time any of the forms is getting saved, you can take a look at any validator in core for an example.

As for the required values, you might want to use client side validation in the UI to enforce required values, I believe html form entry supports javascript validation for form fields.

@wyclif I am looking to test this within my development environment as a sanity check, rather than being used by a user

Do you mean for all the 3 bullets? If yes, for the first 2, there is a validation module that you can run against metadata, this typically will invoke registered validators against the forms, I believe unit unit tests can work too.

@wyclif Is there any example of code or API used by the validation module for runtime checking during the build process?

The validation module has a UI that you can use to run the validation, you can see how to do this from the module’s documentation page I include in my previous response, no need to write any code except for the validator itself that you can add via a custom module.

Yes, what @wyclif suggests, to create a custom validator for an HtmForm object makes sense.

Although it wasn’t intended for this use case, the HtmlFormExporter class might be helpful. It is used with Metadatasharing to gather up all metadata associated with a form. Right now it looks like it fails silently if a piece of metadata isn’t found, but it’s possible that the calculateDependencies class could be factored out into a common utility method and given a “fail hard” option if a dependency isn’t found, so therefore acting like a validator. If that approach does seem appealing, let me know your design plans, and I can review.

Take care, Mark

Find what you need here https://wiki.openmrs.org/display/projects/Distro+Tools+Maven+Plugin You need such a plugin added in your omod file https://github.com/I-TECH/openmrs-module-kenyaemr/blob/master/omod/pom.xml#L159-L174

1 Like