Wiki Spaces

Documentation
Projects
Resources

Get Help from Others

Q&A: Ask OpenMRS
Discussion: OpenMRS Talk
Real-Time: IRC Chat | Slack

Documentation

Page tree
Skip to end of metadata
Go to start of metadata

OpenMRS uses dwr for AJAX. In a sentence, dwr converts java objects to javascript and vice versa.

DWR in core openmrs

Using DWR in a JSP page

<script src="<openmrs:contextPath/>/dwr/interface/DWRPatientService.js"></script>
<script>

DWRPatientService.findPatients("John", false, objectsFound);

function objectsFound(patients) {
  alert("There are " + patients.length + " patients named john");
}

</script>

Adding DWR into your module

Add to config.xml:

<dwr>
		<allow>
			<create creator="new" javascript="DWRMyModuleService">
				<param name="class" value="@MODULE_PACKAGE@.web.DWRMyModuleService"/>
				<include method="getAllLocations"/>
			</create>
		</allow>

		<signatures>
			<![CDATA[
			import @MODULE_PACKAGE@.web.DWRMyModuleService;
			DWRMyModuleService.getAllLocations();
			]]>
		</signatures>
	</dwr>

Create this class:

public class DWRMyModuleService {

 public List<String> getAllLocations() {
     List<String> locationNames = new Vector<String>();
     for (Location loc : Context.getAllLocations()) {
           locationNames.add(loc.getName());
     }
     return locationNames;
}

1 Comment

  1. I had a  similar problem when using Maven archetype to create my module.. The issue is the referencing..(${project.parent.groupId}.${project.parent.artifactId} )here is what i ended up with in my config.xml 

    <dwr>

            <allow>

                <create creator="new" javascript="DWRRadiologyOrdersService">

                    <param name="class" value="${project.parent.groupId}.${project.parent.artifactId}.web.dwr.DWRRadiologyOrdersService"/>

                    <include method="getAllLocations"/>

                </create>

            </allow>

            <signatures>

                <![CDATA[

                import $

    Unknown macro: {project.parent.groupId}

    .$

    Unknown macro: {project.parent.artifactId}

    .web.dwr.DWRRadiologyOrdersService;

                DWRRadiologyOrdersService.getAllLocations();

                ]]>

            </signatures>

        </dwr>