...
Prior to OpenMRS version 1.8, the search widgets were written with dojo which involved writing a separate javascript file where you would have to extended the parent OpenmrsSearch for each Openmrs Object if it were to be searchable in the webapp. The widgets would fetch all hits in one ajax query which would take a while to return all the hits in case there are many making the widgets slow. In 1.8, this was changed by introducing a single and more generic search widget written with jquery, the widget is expected to be faster from a user's stand point in that it fetches just the exact amount of results to display on the first page and then continue to query the server for the rest in the background while updating the table until all results are returned. The reason behind this is that it should take way less time to display the first N results to display on the first page rather waiting for all the hits to be returned in one call in case there are many. The objective is to increase the perceived speed from a user's point of view since they get some results returned in a nick of time even if it isn't all.
...
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; } |
...