Defining Order of entry in HTML Forms

I am wondering if it is posisble to define an order in which HTML forms are entered, or a dependency of forms on a specific encounter being entered.

For example I have 2 forms: summary page and patient_encounter. So I would like to ensure that the encounter is only available if a summary page has been entered and the patient_encounter cannot happen before the date on the summary page.

Ideas welcome

@arbaughj @mogoodrich @mseaton any ideas on how to achieve this with HTML form Entry

Hi @ssmusoke,

My first through would be to try the “Show If” field when configuring the form in the Reference Application. In looking at the documentation, it looks like visits are exposed, but not encounters. @darius might be able to confirm this.

My second thought would be to do a check in the second form (using JavaScript) to ensure the first was completed. If it’s not completed do a re-direct to the first form, or just display an error rather than the form. You could probably use the code for “editing a form rather than filling out a new form if it already exists” as a starting point. See the comments on this page where you improved my original script…

Remove the tag and change this line to the UUID of the prerequisite encounter…

#set( $encounter = $fn.latestEncounter('8d5b27bc-c2cc-11de-8d13-0010c6dffd0f'))

And then change what you want it to do if it does/doesn’t find it. For example, you could redirect to the prerequisite form, or you could use the or tag controlled by your velocityTest to see if the form exits to display an error or hide the form contents.

I hope this gives you a starting point.

@arbaughj I went the Javascript route, checking if for ENTER mode and whether the first form encounter (which is different) has been entered, before forwarding to the encounter for the first form.

Thanks a bunch, and in the spirit of sharing

<ifMode mode="ENTER">
    <includeIf velocityTest="$fn.allEncounters('8d5b27bc-c2cc-11de-8d13-0010c6dffd0f').size() == 0">
            jq(function() {
                alert('This patient has no Summary page, you will now be forwarded to the patient dashboard');

                     * queryParameters -> handles the query string parameters
                     * queryString -> the query string without the fist '?' character
                     * re -> the regular expression
                     * m -> holds the string matching the regular expression
                    var queryParameters = {}, queryString =,
                            re = /([^&amp;=]+)=([^&amp;]*)/g, m;

                    // Creates a map with the query string parameters
                    while (m = re.exec(queryString)) {
                        queryParameters[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);

                     * Replace the query portion of the URL.
                     * jQuery.param() -> create a serialized representation of an array or
                     *     object, suitable for use in a URL query string or Ajax request.
                    location.href = window.location.protocol + "//" + +
                                      '/' + OPENMRS_CONTEXT_PATH + '/coreapps/clinicianfacing/'
                    + queryParameters['patientId']; // Causes page to forward to the patient dashboard