# How to conditionally display forms

**URL:** <https://talk.openmrs.org/t/how-to-conditionally-display-forms/4197>\
**Category:** Development\
**Tags:** html-form-entry\
**Created:** [January 6, 2016, 8:35pm UTC](https://talk.openmrs.org/t/how-to-conditionally-display-forms/4197 "2016-01-06T20:35:03Z")\
**Posts on this page:** 11\
**Page:** 2

<div class="post-metadata">

**Author:** ![gayanw](https://talk.openmrs.org/letter_avatar/gayanw/32/5_5575768a8748004e209b776fc1b2916d.png) [@gayanw](https://talk.openmrs.org/u/gayanw)\
**Post date:** [April 26, 2017, 4:39am UTC](https://talk.openmrs.org/t/how-to-conditionally-display-forms/4197/22 "2017-04-26T04:39:48Z")

</div>

@darius Hi could you please spare a moment to look into my above post to check whether the followed approached is correct.

@dkayiwa and I were discussing about the issue on [here](https://github.com/openmrs/openmrs-module-coreapps/pull/80#issuecomment-296941086).

---

<div class="post-metadata">

**Author:** ![dkayiwa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/dkayiwa/32/179_2.png) [@dkayiwa](https://talk.openmrs.org/u/dkayiwa)\
**Post date:** [April 26, 2017, 3:06pm UTC](https://talk.openmrs.org/t/how-to-conditionally-display-forms/4197/23 "2017-04-26T15:06:00Z")

</div>

@gayanw did you actually look at that constructor to see that it gets only the id and label but ignore the rest? Is this what you want to happen? 🙂

---

<div class="post-metadata">

**Author:** ![darius](https://talk.openmrs.org/user_avatar/talk.openmrs.org/darius/32/8082_2.png) [@darius](https://talk.openmrs.org/u/darius)\
**Post date:** [April 28, 2017, 12:58am UTC](https://talk.openmrs.org/t/how-to-conditionally-display-forms/4197/24 "2017-04-28T00:58:21Z")

</div>

> [@gayanw](#):
>
> BTW rest.webservices module is not included as a dependency in the coreapps module.

Yes it is. See [here in config.xml](https://github.com/openmrs/openmrs-module-coreapps/blob/1.12.0/omod/src/main/resources/config.xml#L45).

I guess that so far this dependency only used from JS code. So, to use it in Java code you’re going to need to add a maven dependency in pom.xml

And, you have to use the SimpleObject class from webservices.rest, with the convertToRepresentation method. (SimpleObject in uiframework is something completely different.)

---

<div class="post-metadata">

**Author:** ![dkayiwa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/dkayiwa/32/179_2.png) [@dkayiwa](https://talk.openmrs.org/u/dkayiwa)\
**Post date:** [August 20, 2019, 1:36pm UTC](https://talk.openmrs.org/t/how-to-conditionally-display-forms/4197/25 "2019-08-20T13:36:15Z")

</div>

> [@ssmusoke](#):
>
> In Uganda we have an initiation encounter for ART used to collect baseline information for treatment. Once this happens then a patient will have other encounters for counseling and regular visits (monthly - to pick up drugs and get a checkup).
> 
> Limiting forms for counseling and other visits not to display until the initiation encounter has happened will reduce the incidences of missing data.

@ssmusoke Did you get to implement this?

---

<div class="post-metadata">

**Author:** ![dkayiwa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/dkayiwa/32/179_2.png) [@dkayiwa](https://talk.openmrs.org/u/dkayiwa)\
**Post date:** [August 20, 2019, 2:46pm UTC](https://talk.openmrs.org/t/how-to-conditionally-display-forms/4197/26 "2019-08-20T14:46:36Z")

</div>

> [@ssmusoke](#):
>
> Does the app context model also extend to Encounters? I would like to disable some forms if a specific encounter has not happened yet.

@aeze is this one of your other requirements?

---

<div class="post-metadata">

**Author:** ![caniekwe](https://talk.openmrs.org/letter_avatar/caniekwe/32/5_5575768a8748004e209b776fc1b2916d.png) [@caniekwe](https://talk.openmrs.org/u/caniekwe)\
**Post date:** [August 21, 2019, 10:52am UTC](https://talk.openmrs.org/t/how-to-conditionally-display-forms/4197/27 "2019-08-21T10:52:31Z")

</div>

@ssmusoke did you get to implement this? We currently have similar experience in Nigeria and looking to know if you or anyone have done this.

---

<div class="post-metadata">

**Author:** ![ssmusoke](https://talk.openmrs.org/user_avatar/talk.openmrs.org/ssmusoke/32/8020_2.png) [@ssmusoke](https://talk.openmrs.org/u/ssmusoke)\
**Post date:** [August 21, 2019, 11:09am UTC](https://talk.openmrs.org/t/how-to-conditionally-display-forms/4197/28 "2019-08-21T11:09:12Z")

</div>

@caniekwe Please describe in more detail what you are trying to do

---

<div class="post-metadata">

**Author:** ![caniekwe](https://talk.openmrs.org/letter_avatar/caniekwe/32/5_5575768a8748004e209b776fc1b2916d.png) [@caniekwe](https://talk.openmrs.org/u/caniekwe)\
**Post date:** [August 21, 2019, 11:34am UTC](https://talk.openmrs.org/t/how-to-conditionally-display-forms/4197/29 "2019-08-21T11:34:27Z")

</div>

@ssmusoke @dkayiwa In Nigeria, we have forms we expect to be completed before documenting other forms. For example, We have an enrollment form that collects certain patients baseline information, we want to enforce these forms are completed on the initial encounter before any other encounter details or forms can be completed for the patient. we want to be able to do the following:

1. Disable all other forms until this baseline form is completed and
2. Ensure this form is not completed twice

---

<div class="post-metadata">

**Author:** ![ssmusoke](https://talk.openmrs.org/user_avatar/talk.openmrs.org/ssmusoke/32/8020_2.png) [@ssmusoke](https://talk.openmrs.org/u/ssmusoke)\
**Post date:** [August 21, 2019, 12:00pm UTC](https://talk.openmrs.org/t/how-to-conditionally-display-forms/4197/30 "2019-08-21T12:00:20Z")

</div>

1. We have an ART Summary Encounter which is the enrollment encounter, which is only done once - so we use the code here to return the user to the dashboard if this encounter has not been completed

> <https://github.com/METS-Programme/openmrs-module-aijar/blob/master/omod/src/main/webapp/resources/htmlforms/122a-HIVCare_ARTCard-EncounterPage.xml#L12-L13>

1. For the ART Summary page, we check if this encounter has been entered and forward to the edit version of the page, only one version therefore can exist

> <https://github.com/METS-Programme/openmrs-module-aijar/blob/master/omod/src/main/webapp/resources/htmlforms/122a-HIVCare_ARTCard-SummaryPage.xml#L2440-L2451>

These are gleamed from OpenMRS HTML Form Entry module Javascript reference

[https://wiki.openmrs.org/display/docs/HTML+Form+Entry+JavaScript+Reference](https://wiki.openmrs.org/display/docs/HTML+Form+Entry+JavaScript+Reference)

---

<div class="post-metadata">

**Author:** ![caniekwe](https://talk.openmrs.org/letter_avatar/caniekwe/32/5_5575768a8748004e209b776fc1b2916d.png) [@caniekwe](https://talk.openmrs.org/u/caniekwe)\
**Post date:** [August 21, 2019, 12:36pm UTC](https://talk.openmrs.org/t/how-to-conditionally-display-forms/4197/31 "2019-08-21T12:36:35Z")

</div>

Thank you @ssmusoke. we will try this and see if this works for our implementation. @nsanmi

---

<div class="post-metadata">

**Author:** ![ssmusoke](https://talk.openmrs.org/user_avatar/talk.openmrs.org/ssmusoke/32/8020_2.png) [@ssmusoke](https://talk.openmrs.org/u/ssmusoke)\
**Post date:** [August 21, 2019, 12:41pm UTC](https://talk.openmrs.org/t/how-to-conditionally-display-forms/4197/32 "2019-08-21T12:41:41Z")

</div>

@caniekwe remember to change the uuids to what you have and let me know if your run into any issues

[Previous page](https://talk.openmrs.org/t/how-to-conditionally-display-forms/4197.md?page=1)
