Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This can be relatively simple if the domain objects to search already have the required methods in the API. Currently the required methods have been added for Concepts, Encounters, Patients, Users, Locations, Providers, Drugs and ConceptReferenceTerms. Let's assume you wish to add an encounter search widget to your jsp, below is how you can do itadd the snippet below to your jsp (you leave out the javascript or css files that you already have in the parent jsp).

Code Block
<openmrs:htmlInclude file="/dwr/interface/DWREncounterService.js"/>
<openmrs:htmlInclude file="/scripts/jquery/dataTables/css/dataTables_jui.css"/>
<openmrs:htmlInclude file="/scripts/jquery/dataTables/js/jquery.dataTables.min.js"/>
<openmrs:htmlInclude file="/scripts/jquery-ui/js/openmrsSearch.js" />

<script type="text/javascript">
	var lastSearch;
	$j(document).ready(function() {
		new OpenmrsSearch("findEncounter", true, doEncounterSearch, doSelectionHandler,
				[	{fieldName:"personName", header:"Patient Name"},
					{fieldName:"encounterType", header:"Encounter Type"},
					{fieldName:"formName", header:"Encounter Form"},
					{fieldName:"providerName", header:"Encounter Provider"},
					{fieldName:"location", header:"Encounter Location"},
					{fieldName:"encounterDateString", header:"Encounter Date"}
				],
                {
                    searchLabel: '<spring:message code="Encounter.search" javaScriptEscape="true"/>',
                    searchPlaceholder:'<spring:message code="Encounter.search.placeholder" javaScriptEscape="true"/>'
                });
	});

        //The action to take when the user selects an item from the hits in the widget
	function doSelectionHandler(index, data) {
		document.location = "encounter.form?encounterId=" + data.encounterId + "&phrase=" + lastSearch;
	}

	//Contains the logic that fetches the results from the server
	function doEncounterSearch(text, resultHandler, getMatchCount, opts) {
		lastSearch = text;
		DWREncounterService.findCountAndEncounters(text, opts.includeVoided, opts.start, opts.length, getMatchCount, resultHandler);
	}
</script>

...