Conditionally displaying Apps and Extensions

Several places in the Reference Application allow you to provide a logical expression that determines whether an App or Extension is displayed. (For example, require under Manage Apps, or Show If on Manage Forms.)

These allow the administrator to provide a snippet of JavaScript that will be evaluated against a given ContextModel that reflects the state of the app at that given time.

Where Conditional Includes are Supported

Home Page Apps

When adding an App to the home screen (see System Administration: Manage Apps) you have access to a require property, whose ContextModel contains sessionContext.

Example: (only shows this app if the user logged in with the Outpatient Clinic session location)

sessionLocation.uuid == '58c57d25-8d39-41ab-8422-108a0c277d98'

Hardcoding a specific uuid is not a good approach if you want your code to work across multiple OpenMRS implementations. A better approach would be to do this based on location tags, e.g. this app would only be available if the user logged in with a session location that has the "Admission Location" tag (on our demo server this would be Inpatient Ward or Isolation Ward).

hasMemberWithProperty(sessionLocation.tags, 'display', 'Admission Location')

To show a form if the logged in user has the Organizational: Nurse role, you would use the expression below: 

hasMemberWithProperty (user.roles, 'display', 'Organizational: Nurse')

Patient Summary and Visit Dashboard

The Patient screen has two list of available actions: one for General Actions, another for Current Visit Actions (if there is an active visit). When viewing a specific visit, you have access to Visit Actions. When you add a custom form (see Configure Metadata: Manage Forms) this is added as a Visit Action.

General Actions have patient available in the context.

Current Visit Actions and Visit Actions have patient and visit available in the context.

Example: (only show this form for inpatients)


Helper Functions

hasMemberWithProperty(list, propertyName, valueToLookFor) ... true if any item in list has item[propertyName] == valueToLookFor

See this code for full details.

Available Properties


Properties available:

  • currentUser
  • currentProvider
  • sessionLocation

See this code for full details.


Properties available:

  • uuid
  • person (see below)

See this code for full details.


Properties available:

  • uuid
  • birthdate
  • birthdateEstimated
  • gender
  • dead
  • deathdate

See this code for full details.


Properties available:

  • uuid
  • active
  • admitted
  • startDatetimeInMilliseconds
  • stopDatetimeInMilliseconds
  • stopDatetime

See this code for full details.

More details for how this is put together.