...
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> |
...
Code Block |
---|
public Map<String, Object> findCountAndEncounters(String phrase, boolean includeVoided, Integer start, Integer length,
boolean getMatchCount) throws APIException {
//Map to return
Map<String, Object> resultsMap = new HashMap<String, Object>();
Vector<Object> objectList = new Vector<Object>();
try {
EncounterService es = Context.getEncounterService();
int encounterCount = 0;
if (getMatchCount)
encounterCount += es.getCountOfEncounters(phrase, includeVoided);
//If we have any matches, fetch them or if this is not the first ajax call
//for displaying the results on the first page, the getMatchCount is expected to be zero
if (encounterCount > 0 || !getMatchCount)
objectList = findBatchOfEncounters(phrase, includeVoided, start, length);
resultsMap.put("count", encounterCount);
resultsMap.put("objectList", objectList);
}
catch (Exception e) {
objectList.clear();
objectList.add("Error while searching for encounters");
resultsMap.put("count", 0);
resultsMap.put("objectList", objectList);
//you can opt to pass in a new phrase which will tell the core search widget to rerun the
// search but for your new phrase and this will lead to ignoring the results you send back
resultsMap.put("searchAgain", "newphrase");
}
return resultsMap;
}
|
...