How to conditionally display forms

Thanks for this detailed explanation. That’s very clear indeed.

I’ll create a ticket for that task

Ticket now created

I am working on the ticket now. @darius and @mksrom thanks for making it so clear.


@mksrom Kindly let us know when you are done working on this ticket. Am also looking using this option.

Hi @jmpango, Sure thing. Will let you know soon.


@darius Does the app context model also extend to Encounters? I would like to disable some forms if a specific encounter has not happened yet.

I don’t think it’s currently there. I would be wary of bloating the visit context model, but I guess having a list of encounter type that have happened already in the visit might be worthwhile.

Can you give some real examples?

-Darius (by phone)

@darius 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 @mksrom

i get this error from travis after pushing changes to my repo.

and the detailed travis log is

I have looked at the problems and they are

1:Could not find Symbol SimpleObject 2:Could not find Symbol ConversionUtil

was wondering how to get ConversionUtil into VisitTypeContextModel from module… Any way i can rectify this

@tendomart The SimpleObject class is not imported in the VisitContextModel class. Did you run an mvn clean install before pushing your commit?

Why are you using the SimpleObject and not a String for the name of the visit type?

@ssmusoke no i did not run mvn clean install,the directions or atleast the hint given earlier in this post seem to point in that direction.I had earlier used visit type but refactored because of what i read from this thread… Consider what darius said earlier in this post here is the link to github

i refactored as at

and running a mvn clean install before committing throws this

i read through the lines but am stuck on what to do…a little help here

@tendomart your class does not import the external classes referred to. I do think that the visitType has to be a String - but I am not an expert on the context models.

@ssmusoke thanks i appreciate,that insight

Hi I did start working on this. I think that onversionUtil.convertToRepresentation() is in the artifact

However adding it as a dependency to coreapps pom causes my mvn tests to fail:

Running org.openmrs.module.coreapps.htmlformentry.EncounterDispositionTagHandlerComponentTest
ERROR - TestContextManager.prepareTestInstance(309) |2017-03-26 14:30:33,571| Caught exception while allowing TestExecutionListener [] to prepare test instance [org.openmrs.module.coreapps.htmlformentry.EncounterDispositionTagHandlerComponentTest@69339b3b]
java.lang.IllegalStateException: Failed to load ApplicationContext
	at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(
	at org.springframework.test.context.TestContext.getApplicationContext(
	at org.springframework.test.context.TestContextManager.prepareTestInstance(
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(
	at org.junit.runners.ParentRunner$
	at org.junit.runners.ParentRunner$1.schedule(
	at org.junit.runners.ParentRunner.runChildren(
	at org.junit.runners.ParentRunner.access$000(
	at org.junit.runners.ParentRunner$2.evaluate(
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(
	at org.junit.internal.runners.statements.RunAfters.evaluate(
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(
	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(
	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(
	at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(
	at org.apache.maven.surefire.booter.ForkedBooter.main(
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mainResourceController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field:; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(
	at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(
	at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(
	... 26 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field:; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(
	... 42 more

I add these in the parent pom:



and in coreapps/api/pom.xml:


Any insights on what I’m doing wrong?

I see two SimpleObject classes, and org.openmr.ui.framework.SimpleObject

And the one from the rest module does not include any constructors that accepts other object types, but one in the UI module does have a constructor that accepts OpenmrsMetadata for constructing a SimpleObject.

And visitType also implements OpenmrsMetada

So can’t we use:

this.visitType = new org.openmrs.ui.framework.SimpleObject(visitType);

instead of using ConversionUtil from the rest module. BTW rest.webservices module is not included as a dependency in the coreapps module.


@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.

@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? :slight_smile:

Yes it is. See here in config.xml.

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, with the convertToRepresentation method. (SimpleObject in uiframework is something completely different.)

@ssmusoke Did you get to implement this?