How to conditionally display forms

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

@aeze is this one of your other requirements?

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

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

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

These are gleamed from OpenMRS HTML Form Entry module Javascript reference

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

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