@Test public void suggestAsJSONWithMorePatientsRequested() throws QueryException { JSONObject response = new JSONObject(this.component.suggestAsJSON("dOe", 200, "view", ID, "asc")); JSONArray suggestions = response.getJSONArray("matchedPatients"); Mockito.verify(this.queryManager).createQuery( "select doc.name from Document doc, doc.object(PhenoTips.PatientClass) as patient" + " where doc.name <> :t" + " and lower(doc.name) like :input or lower(patient.external_id) like :input" + " or lower(patient.first_name) like :input or lower(patient.last_name) like :input" + " order by doc.name asc", Query.XWQL); Mockito.verify(this.query).bindValue("t", "PatientTemplate"); Mockito.verify(this.query).bindValue("input", "%doe%"); Assert.assertEquals(4, suggestions.length()); Assert.assertEquals("readablePatient1", suggestions.getJSONObject(0).getString(ID)); Assert.assertEquals("writablePatient1", suggestions.getJSONObject(1).getString(ID)); Assert.assertEquals("readablePatient2", suggestions.getJSONObject(2).getString(ID)); Assert.assertEquals("writablePatient2", suggestions.getJSONObject(3).getString(ID)); }
@Override public String suggestAsJSON(String input, int maxResults, String requiredPermission, String orderField, String order) { if (StringUtils.isEmpty(input)) { throw new WebApplicationException(Response.Status.BAD_REQUEST); } List<Patient> patients = getMatchingPatients(input.toLowerCase(), orderField, order, maxResults, Right.toRight(requiredPermission)); JSONArray results = new JSONArray(); for (Patient patient : patients) { results.put(getPatientJSON(patient)); } JSONObject jsonResult = new JSONObject(); jsonResult.put("matchedPatients", results); return jsonResult.toString(); }
DefaultPatientsSuggestionsResourceImpl extends XWikiResource implements PatientsSuggestionsResource { @Override public String suggestAsJSON(String input, int maxResults, String requiredPermission, String orderField, String order) { if (StringUtils.isEmpty(input)) { throw new WebApplicationException(Response.Status.BAD_REQUEST); } List<Patient> patients = getMatchingPatients(input.toLowerCase(), orderField, order, maxResults, Right.toRight(requiredPermission)); JSONArray results = new JSONArray(); for (Patient patient : patients) { results.put(getPatientJSON(patient)); } JSONObject jsonResult = new JSONObject(); jsonResult.put("matchedPatients", results); return jsonResult.toString(); } }
DefaultPatientsSuggestionsResourceImpl extends XWikiResource implements PatientsSuggestionsResource { @Override public String suggestAsJSON(String input, int maxResults, String requiredPermission, String orderField, String order) { if (StringUtils.isEmpty(input)) { throw new WebApplicationException(Response.Status.BAD_REQUEST); } List<Patient> patients = getMatchingPatients(input.toLowerCase(), orderField, order, maxResults, Right.toRight(requiredPermission)); JSONArray results = new JSONArray(); for (Patient patient : patients) { results.put(getPatientJSON(patient)); } JSONObject jsonResult = new JSONObject(); jsonResult.put("matchedPatients", results); return jsonResult.toString(); }  }
DefaultPatientsSuggestionsResourceImpl extends XWikiResource implements PatientsSuggestionsResource { @Override public String suggestAsJSON(String input, int maxResults, String requiredPermission, String orderField, String order) { if (StringUtils.isEmpty(input)) { throw new WebApplicationException(Response.Status.BAD_REQUEST); } List<Patient> patients = getMatchingPatients(input.toLowerCase(), orderField, order, maxResults, Right.toRight(requiredPermission)); JSONArray results = new JSONArray(); for (Patient patient : patients) { results.put(getPatientJSON(patient)); } JSONObject jsonResult = new JSONObject(); jsonResult.put("matchedPatients", results); return jsonResult.toString(); }  @Override String suggestAsJSON(String input, int maxResults, String requiredPermission, String orderField,
        String order); @Override String suggestAsXML(String input, int maxResults, String requiredPermission, String orderField, String order); }
DefaultPatientsSuggestionsResourceImpl extends XWikiResource implements PatientsSuggestionsResource { @Override public String suggestAsJSON(String input, int maxResults, String requiredPermission, String orderField, String order) { if (StringUtils.isEmpty(input)) { throw new WebApplicationException(Response.Status.BAD_REQUEST); } List<Patient> patients = getMatchingPatients(input.toLowerCase(), orderField, order, maxResults, Right.toRight(requiredPermission)); JSONArray results = new JSONArray(); for (Patient patient : patients) { results.put(getPatientJSON(patient)); } JSONObject jsonResult = new JSONObject(); jsonResult.put("matchedPatients", results); return jsonResult.toString(); }  @Override String suggestAsJSON(String input, int maxResults, String requiredPermission, String orderField,
        String order); @Override String suggestAsXML(String input, int maxResults, String requiredPermission, String orderField, String order);  }