How to conditionally display forms

What you’re describing would be the least code, but there’s one thing…

The philosophy is that we want these same extension points to be usable in a server-side Java-rendered page, or in a client-side JS-rendered page. So the philosophy is that we do not want to use the Java domain objects as the context model, but rather in the long run we want to use the JSON REST representation of the visit, rather than the visit. You can see from looking at VisitContextModel that we haven’t actually done things this way yet, because nobody has taken the time to go back and refactor everything that was depending on the current representation.

So, as far as what you should do, one thing would be instead of this:

private VisitType visitType;
...
this.visitType = visit.getVisit().getVisitType();

to instead do this:

private SimpleObject visitType;
...
this.visitType = ConversionUtil.convertToRepresentation(visit.getVisit().getVisitType(), Representation.DEFAULT); // these are from the webservices.rest module

The code will look a bit out of place at this point in time, but it’s going in the direction we want to go. Does that make sense?

Also, the javascript fragment doesn’t need to say “appContextModel”, as in this example here: https://github.com/openmrs/openmrs-module-referenceapplication/blob/master/omod/src/main/resources/apps/visitActions_extension.json#L23