As OpenHMIS team we thought that it would be a good idea to support both types of UIs as they are currently used together in one module rather than creating a separate UI module for the new UI.
Basically what we did to be able to run our module with both types of UIs (“old” one using OpenMRS 1.9.9 and new one using OpenMRS 2.2 (with 1.11.3)) is the following steps:
-
Getting rid of the uiframework bean definition in webModuleApplicationContext.xml. Instead we defined a configuration class that would only create the bean if the uiframework module is loaded.
package org.openmrs.module.openhmis.inventory.uiframwork;
import org.openmrs.annotation.OpenmrsProfile; import org.openmrs.ui.framework.StandardModuleUiConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;
@Configuration @OpenmrsProfile(modules = { “uiframework:.” }) public class UiConfigurationInventory {
@Bean public StandardModuleUiConfiguration createUiConfigurationBean() { StandardModuleUiConfiguration standardModuleUiConfiguration = new StandardModuleUiConfiguration(); standardModuleUiConfiguration.setModuleId("openhmis.inventory"); return standardModuleUiConfiguration; }}
-
adding
@OpenmrsProfile(modules = { "uiframework:*.*" })to our controllers for the new UI to make sure the controller actions are only applied if the uiframework module is present. As our controllers at this stage are pretty basic that looks like this:package org.openmrs.module.openhmis.inventory.page.controller;
import java.io.IOException; import java.util.List;
import org.openmrs.module.appframework.domain.Extension; import org.openmrs.module.appframework.service.AppFrameworkService; import org.openmrs.module.openhmis.inventory.web.ModuleWebConstants; import org.openmrs.ui.framework.UiUtils; import org.openmrs.ui.framework.annotation.SpringBean; import org.openmrs.ui.framework.page.PageModel; import org.openmrs.ui.framework.page.PageRequest; import org.springframework.stereotype.Controller; import org.openmrs.annotation.OpenmrsProfile;
@Controller @OpenmrsProfile(modules = { “uiframework:.” }) public class InventoryLandingPageController {
public void get(PageModel model, @SpringBean("appFrameworkService") AppFrameworkService appFrameworkService, PageRequest request, UiUtils ui) throws IOException { List<Extension> extensions = appFrameworkService.getExtensionsForCurrentUser(ModuleWebConstants.LANDING_PAGE_EXTENSION_POINT_ID); model.addAttribute("extensions", extensions); }}
My question now is if this approach is a good way to go, or if we are violating any rules (if there are any…) concerning best practice to provide the new UI to our modules. As far as I can see pretty much everything concerning the new UI is done in separate modules and I wonder if I might miss something important if I don’t follow that pattern.
Opinions please
Good idea?/bad idea?/missing something important?
Edit: I forgot to mention (as Rafal is pointing out) that we are having the following lines in our config.xml:
<aware_of_module version="3.3.1">org.openmrs.module.uiframework</aware_of_module>
<aware_of_module version="2.3">org.openmrs.module.appframework</aware_of_module>
<aware_of_module version="2.2">org.openmrs.module.providermanagement</aware_of_module>
<aware_of_module version="1.6">org.openmrs.module.uicommons</aware_of_module>
P.S. Here’s a link to the commit that I made to achive running both UI types in one module. Just in case people are interested in details…
