/** * @param xmlParentNode * @param xmlNameNode * @param listValues * @return */ private String getResponseXMLString( String xmlParentNode, String xmlIdNode, String xmlNameNode, List<NameValueBean> listValues) { StringBuffer responseXML = new StringBuffer(); NameValueBean bean = null; if ((xmlParentNode != null) && (xmlNameNode != null) && (listValues != null)) { responseXML.append("<node>"); int noOfValues = listValues.size(); for (int i = 0; i < noOfValues; i++) { bean = listValues.get(i); if (bean != null) { responseXML.append("<" + xmlParentNode + ">"); responseXML.append("<" + xmlIdNode + ">"); responseXML.append(bean.getValue()); responseXML.append("</" + xmlIdNode + ">"); responseXML.append("<" + xmlNameNode + ">"); responseXML.append(bean.getName()); responseXML.append("</" + xmlNameNode + ">"); responseXML.append("</" + xmlParentNode + ">"); } } responseXML.append("</node>"); } return responseXML.toString(); }
/** * This method fetches the required number of records from Clinical Diagnosis List and poplulates * in the Combo Box on UI. * * @param limitFetch is the limit to fetch and display the Clinical Diagnosis records in Combo Box * on UI * @param startFetch is the position from where you fetch the Clinical Diagnosis data from the * List * @param query holds the string which the user has typed down in combo box for autocomplete * feature * @return JSONObject which holds the list to eb poplulated on UI front */ public JSONObject getClinicalDiagnosisData( Integer limitFetch, Integer startFetch, String query, Collection<NameValueBean> clinicalDiagnosisBean, String showOption) { JSONObject jsonObject = null; JSONArray jsonArray = null; try { jsonArray = new JSONArray(); jsonObject = new JSONObject(); final List<NameValueBean> clinicalDiagnosisList; boolean showSubset = false; if (!clinicalDiagnosisBean.isEmpty() && Constants.SHOW_ALL_VALUES.equals(showOption)) { showSubset = true; } if (clinicalDiagnosisBean == null || clinicalDiagnosisBean.isEmpty() || Constants.SHOW_ALL_VALUES.equals(showOption)) { clinicalDiagnosisList = this.getClinicalDiagnosisList(query, showSubset); } else { clinicalDiagnosisList = (List<NameValueBean>) clinicalDiagnosisBean; } jsonObject.put("totalCount", new Integer(clinicalDiagnosisList.size())); final ListIterator<NameValueBean> iterator = clinicalDiagnosisList.listIterator(startFetch + 1); final Integer total = limitFetch + startFetch; // 1st record in List has value -1, so startFetch is incremented and // made to fetch data from 2nd element from the List startFetch++; boolean flag = false; while (startFetch < total + 1) { if (iterator.hasNext()) { final NameValueBean nameValueBean = iterator.next(); if (nameValueBean.getName().toLowerCase().contains(query.toLowerCase()) || query == null) { final JSONObject innerJsonObject = new JSONObject(); // nameValueBean = (NameValueBean) iterator.next(); innerJsonObject.put("id", nameValueBean.getName()); innerJsonObject.put("field", nameValueBean.getValue()); jsonArray.put(innerJsonObject); flag = true; } else if (flag) { break; } } startFetch++; } jsonObject.put("row", jsonArray); } catch (final Exception e) { this.logger.error(e.getMessage(), e); e.printStackTrace(); // System.out.println(e); } return jsonObject; }
/** * gets the display name. * * @param nvbList collection of NameValueBean objects. * @param value value to be checked. * @return display name. */ public static Object getDisplayName(Collection<NameValueBean> nvbList, String value) { String displayName = ""; if (nvbList != null && value != null) { for (final NameValueBean nvb : nvbList) { if (nvb.getValue().equals(value)) { displayName = nvb.getName(); break; } } } return displayName; }