List of usage examples for org.apache.commons.lang StringUtils deleteWhitespace
public static String deleteWhitespace(String str)
Deletes all whitespaces from a String as defined by Character#isWhitespace(char) .
From source file:org.openbravo.module.taxreportlauncher.Utility.OBTL_Utility.java
/** * Returns a valid file name removing all the strange characters that shouldn't be used inside the * report's file name//from w w w.ja v a 2 s .com * * @param name * @param reportId * @return */ public static String getReportValidFileName(final String name, final String reportId) { String fileName = name; if (fileName == null || fileName.equals("")) { fileName = StringUtils.deleteWhitespace(new TaxReportLauncherDao().getTaxReport(reportId).getName()); } else { fileName = StringUtils.deleteWhitespace(fileName); } return removeStrangeCharacters(fileName); }
From source file:org.openhab.binding.smartmeter.internal.SmartMeterHandler.java
@Override public void initialize() { logger.debug("Initializing Smartmeter handler."); cancelRead();//w ww .j a v a2 s. c o m SmartMeterConfiguration config = getConfigAs(SmartMeterConfiguration.class); logger.debug("config port = {}", config.port); boolean validConfig = true; String errorMsg = null; if (StringUtils.trimToNull(config.port) == null) { errorMsg = "Parameter 'port' is mandatory and must be configured"; validConfig = false; } if (validConfig) { byte[] pullSequence = config.initMessage == null ? null : HexUtils.hexToBytes(StringUtils.deleteWhitespace(config.initMessage)); int baudrate = config.baudrate == null ? Baudrate.AUTO.getBaudrate() : Baudrate.fromString(config.baudrate).getBaudrate(); this.conformity = config.conformity == null ? Conformity.NONE : Conformity.valueOf(config.conformity); this.smlDevice = MeterDeviceFactory.getDevice(serialPortManagerSupplier, config.mode, this.thing.getUID().getAsString(), config.port, pullSequence, baudrate, config.baudrateChangeDelay); updateStatus(ThingStatus.UNKNOWN, ThingStatusDetail.HANDLER_CONFIGURATION_PENDING, "Waiting for messages from device"); smlDevice.addValueChangeListener(channelTypeProvider); updateOBISValue(); } else { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, errorMsg); } }
From source file:org.openmeetings.servlet.outputhandler.DownloadHandler.java
@Override protected void service(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException { try {/* w w w . j a v a2 s. c om*/ if (getUserManagement() == null || getSessionManagement() == null) { return; } httpServletRequest.setCharacterEncoding("UTF-8"); log.debug("\nquery = " + httpServletRequest.getQueryString()); log.debug("\n\nfileName = " + httpServletRequest.getParameter("fileName")); log.debug("\n\nparentPath = " + httpServletRequest.getParameter("parentPath")); String queryString = httpServletRequest.getQueryString(); if (queryString == null) { queryString = ""; } String sid = httpServletRequest.getParameter("sid"); if (sid == null) { sid = "default"; } log.debug("sid: " + sid); Long users_id = getSessionManagement().checkSession(sid); Long user_level = getUserManagement().getUserLevelByID(users_id); if (user_level != null && user_level > 0) { String room_id = httpServletRequest.getParameter("room_id"); if (room_id == null) { room_id = "default"; } String moduleName = httpServletRequest.getParameter("moduleName"); if (moduleName == null) { moduleName = "nomodule"; } String parentPath = httpServletRequest.getParameter("parentPath"); if (parentPath == null) { parentPath = "nomodule"; } String requestedFile = httpServletRequest.getParameter("fileName"); if (requestedFile == null) { requestedFile = ""; } String fileExplorerItemIdParam = httpServletRequest.getParameter("fileExplorerItemId"); Long fileExplorerItemId = null; if (fileExplorerItemIdParam != null) { fileExplorerItemId = Long.parseLong(fileExplorerItemIdParam); } // make a complete name out of domain(organisation) + roomname String roomName = room_id; // trim whitespaces cause it is a directory name roomName = StringUtils.deleteWhitespace(roomName); // Get the current User-Directory String current_dir = getServletContext().getRealPath("/"); String working_dir = ""; working_dir = current_dir + OpenmeetingsVariables.UPLOAD_DIR + File.separatorChar; // Add the Folder for the Room if (moduleName.equals("lzRecorderApp")) { working_dir = current_dir + OpenmeetingsVariables.STREAMS_DIR + File.separatorChar + "hibernate" + File.separatorChar; } else if (moduleName.equals("videoconf1")) { if (parentPath.length() != 0) { if (parentPath.equals("/")) { working_dir = working_dir + roomName + File.separatorChar; } else { working_dir = working_dir + roomName + File.separatorChar + parentPath + File.separatorChar; } } else { working_dir = current_dir + roomName + File.separatorChar; } } else if (moduleName.equals("userprofile")) { working_dir += "profiles" + File.separatorChar; logNonExistentFolder(working_dir); working_dir += ScopeApplicationAdapter.profilesPrefix + users_id + File.separatorChar; logNonExistentFolder(working_dir); } else if (moduleName.equals("remoteuserprofile")) { working_dir += "profiles" + File.separatorChar; logNonExistentFolder(working_dir); String remoteUser_id = httpServletRequest.getParameter("remoteUserid"); if (remoteUser_id == null) { remoteUser_id = "0"; } working_dir += ScopeApplicationAdapter.profilesPrefix + remoteUser_id + File.separatorChar; logNonExistentFolder(working_dir); } else if (moduleName.equals("remoteuserprofilebig")) { working_dir += "profiles" + File.separatorChar; logNonExistentFolder(working_dir); String remoteUser_id = httpServletRequest.getParameter("remoteUserid"); if (remoteUser_id == null) { remoteUser_id = "0"; } working_dir += ScopeApplicationAdapter.profilesPrefix + remoteUser_id + File.separatorChar; logNonExistentFolder(working_dir); requestedFile = this.getBigProfileUserName(working_dir); } else if (moduleName.equals("chat")) { working_dir += "profiles" + File.separatorChar; logNonExistentFolder(working_dir); String remoteUser_id = httpServletRequest.getParameter("remoteUserid"); if (remoteUser_id == null) { remoteUser_id = "0"; } working_dir += ScopeApplicationAdapter.profilesPrefix + remoteUser_id + File.separatorChar; logNonExistentFolder(working_dir); requestedFile = this.getChatUserName(working_dir); } else { working_dir = working_dir + roomName + File.separatorChar; } if (!moduleName.equals("nomodule")) { log.debug("requestedFile: " + requestedFile + " current_dir: " + working_dir); String full_path = working_dir + requestedFile; File f = new File(full_path); // If the File does not exist or is not readable show/load a // place-holder picture if (!f.exists() || !f.canRead()) { if (!f.canRead()) { log.debug("LOG DownloadHandler: The request file is not readable"); } else { log.debug( "LOG DownloadHandler: The request file does not exist / has already been deleted"); } log.debug("LOG ERROR requestedFile: " + requestedFile); // replace the path with the default picture/document if (requestedFile.endsWith(".jpg")) { log.debug("LOG endsWith d.jpg"); log.debug("LOG moduleName: " + moduleName); requestedFile = DownloadHandler.defaultImageName; if (moduleName.equals("remoteuserprofile")) { requestedFile = DownloadHandler.defaultProfileImageName; } else if (moduleName.equals("remoteuserprofilebig")) { requestedFile = DownloadHandler.defaultProfileImageNameBig; } else if (moduleName.equals("userprofile")) { requestedFile = DownloadHandler.defaultProfileImageName; } else if (moduleName.equals("chat")) { requestedFile = DownloadHandler.defaultChatImageName; } // request for an image full_path = current_dir + "default" + File.separatorChar + requestedFile; } else if (requestedFile.endsWith(".swf")) { requestedFile = DownloadHandler.defaultSWFName; // request for a SWFPresentation full_path = current_dir + "default" + File.separatorChar + DownloadHandler.defaultSWFName; } else { // Any document, must be a download request // OR a Moodle Loggedin User requestedFile = DownloadHandler.defaultImageName; full_path = current_dir + "default" + File.separatorChar + DownloadHandler.defaultImageName; } } log.debug("full_path: " + full_path); File f2 = new File(full_path); if (!f2.exists() || !f2.canRead()) { if (!f2.canRead()) { log.debug( "DownloadHandler: The request DEFAULT-file does not exist / has already been deleted"); } else { log.debug( "DownloadHandler: The request DEFAULT-file does not exist / has already been deleted"); } // no file to handle abort processing return; } // Requested file is outside OM webapp folder File curDirFile = new File(current_dir); if (!f2.getCanonicalPath().startsWith(curDirFile.getCanonicalPath())) { throw new Exception("Invalid file requested: f2.cp == " + f2.getCanonicalPath() + "; curDir.cp == " + curDirFile.getCanonicalPath()); } // Get file and handle download RandomAccessFile rf = new RandomAccessFile(full_path, "r"); // Default type - Explorer, Chrome and others int browserType = 0; // Firefox and Opera browsers if (httpServletRequest.getHeader("User-Agent") != null) { if ((httpServletRequest.getHeader("User-Agent").contains("Firefox")) || (httpServletRequest.getHeader("User-Agent").contains("Opera"))) { browserType = 1; } } log.debug("Detected browser type:" + browserType); httpServletResponse.reset(); httpServletResponse.resetBuffer(); OutputStream out = httpServletResponse.getOutputStream(); if (requestedFile.endsWith(".swf")) { // trigger download to SWF => THIS is a workaround for // Flash Player 10, FP 10 does not seem // to accept SWF-Downloads with the Content-Disposition // in the Header httpServletResponse.setContentType("application/x-shockwave-flash"); httpServletResponse.setHeader("Content-Length", "" + rf.length()); } else { httpServletResponse.setContentType("APPLICATION/OCTET-STREAM"); String fileNameResult = requestedFile; if (fileExplorerItemId != null && fileExplorerItemId > 0) { FileExplorerItem fileExplorerItem = getFileExplorerItemDaoImpl() .getFileExplorerItemsById(fileExplorerItemId); if (fileExplorerItem != null) { fileNameResult = fileExplorerItem.getFileName().substring(0, fileExplorerItem.getFileName().length() - 4) + fileNameResult.substring(fileNameResult.length() - 4, fileNameResult.length()); } } if (browserType == 0) { httpServletResponse.setHeader("Content-Disposition", "attachment; filename=" + java.net.URLEncoder.encode(fileNameResult, "UTF-8")); } else { httpServletResponse.setHeader("Content-Disposition", "attachment; filename*=UTF-8'en'" + java.net.URLEncoder.encode(fileNameResult, "UTF-8")); } httpServletResponse.setHeader("Content-Length", "" + rf.length()); } byte[] buffer = new byte[1024]; int readed = -1; while ((readed = rf.read(buffer, 0, buffer.length)) > -1) { out.write(buffer, 0, readed); } rf.close(); out.flush(); out.close(); } } else { System.out.println("ERROR DownloadHandler: not authorized FileDownload " + (new Date())); } } catch (Exception er) { log.error("Error downloading: ", er); // er.printStackTrace(); } }
From source file:org.openmeetings.servlet.outputhandler.ScreenRequestHandler.java
@Override public Template handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Context ctx) {//from w w w . j av a2 s . c o m try { if (getSessionManagement() == null) { return getVelocityView().getVelocityEngine().getTemplate("booting.vm"); } String sid = httpServletRequest.getParameter("sid"); if (sid == null) { sid = "default"; } log.debug("sid: " + sid); Long users_id = getSessionManagement().checkSession(sid); if (users_id == 0) { //checkSession will return 0 in case of invalid session throw new Exception("Request from invalid user " + users_id); } String publicSID = httpServletRequest.getParameter("publicSID"); if (publicSID == null) { throw new Exception("publicSID is empty: " + publicSID); } String room = httpServletRequest.getParameter("room"); if (room == null) room = "default"; String domain = httpServletRequest.getParameter("domain"); if (domain == null) { throw new Exception("domain is empty: " + domain); } String languageAsString = httpServletRequest.getParameter("languageAsString"); if (languageAsString == null) { throw new Exception("languageAsString is empty: " + domain); } Long language_id = Long.parseLong(languageAsString); String rtmphostlocal = httpServletRequest.getParameter("rtmphostlocal"); if (rtmphostlocal == null) { throw new Exception("rtmphostlocal is empty: " + rtmphostlocal); } String red5httpport = httpServletRequest.getParameter("red5httpport"); if (red5httpport == null) { throw new Exception("red5httpport is empty: " + red5httpport); } String record = httpServletRequest.getParameter("record"); if (record == null) { throw new Exception("recorder is empty: "); } String httpRootKey = httpServletRequest.getParameter("httpRootKey"); if (httpRootKey == null) { throw new Exception("httpRootKey is empty could not start sharer"); } String baseURL = httpServletRequest.getScheme() + "://" + rtmphostlocal + ":" + red5httpport + httpRootKey; // make a complete name out of domain(organisation) + roomname String roomName = domain + "_" + room; // trim whitespaces cause it is a directory name roomName = StringUtils.deleteWhitespace(roomName); ctx.put("rtmphostlocal", rtmphostlocal); // rtmphostlocal ctx.put("red5httpport", red5httpport); // red5httpport log.debug("httpRootKey " + httpRootKey); String codebase = baseURL + "screen"; ctx.put("codebase", codebase); String httpSharerURL = baseURL + "ScreenServlet"; ctx.put("webAppRootKey", httpRootKey); ctx.put("httpSharerURL", httpSharerURL); ctx.put("APP_NAME", getCfgManagement().getAppName()); ctx.put("SID", sid); ctx.put("ROOM", room); ctx.put("DOMAIN", domain); ctx.put("PUBLIC_SID", publicSID); ctx.put("RECORDER", record); String requestedFile = roomName + ".jnlp"; httpServletResponse.setContentType("application/x-java-jnlp-file"); httpServletResponse.setHeader("Content-Disposition", "Inline; filename=\"" + requestedFile + "\""); log.debug("language_id :: " + language_id); String label_viewer = "Viewer"; String label_sharer = "Sharer"; try { label_viewer = getLabels(language_id, 728, 729, 736, 742); label_sharer = getLabels(language_id, 730, 731, 732, 733, 734, 735, 737, 738, 739, 740, 741, 742, 844, 869, 870, 871, 872, 878, 1089, 1090, 1091, 1092, 1093, 1465, 1466, 1467, 1468, 1469, 1470, 1471, 1472, 1473, 1474, 1475, 1476, 1477); } catch (Exception e) { log.error("Error resolving Language labels : ", e); } ctx.put("LABELVIEWER", label_viewer); ctx.put("LABELSHARER", label_sharer); log.debug("Creating JNLP Template for TCP solution"); try { final String screenShareDirName = "screensharing"; //libs StringBuilder libs = new StringBuilder(); File screenShareDir = new File(ScopeApplicationAdapter.webAppPath, screenShareDirName); for (File jar : screenShareDir.listFiles(new FileFilter() { public boolean accept(File pathname) { return pathname.getName().endsWith(".jar"); } })) { libs.append("\t\t<jar href=\"").append(jar.getName()).append("\"/>\n"); } addKeystore(ctx); ctx.put("LIBRARIES", libs); log.debug("RTMP Sharer labels :: " + label_sharer); codebase = baseURL + screenShareDirName; ConnectionType conType = ConnectionType.valueOf(httpServletRequest.getParameter("connectionType")); String startUpClass; switch (conType) { case rtmp: startUpClass = "org.openmeetings.screen.webstart.RTMPScreenShare"; break; case rtmps: startUpClass = "org.openmeetings.screen.webstart.RTMPSScreenShare"; break; case rtmpt: startUpClass = "org.openmeetings.screen.webstart.RTMPTScreenShare"; break; default: throw new Exception("Unknown connection type"); } String orgIdAsString = httpServletRequest.getParameter("organization_id"); if (orgIdAsString == null) { throw new Exception("orgIdAsString is empty could not start sharer"); } ctx.put("organization_id", orgIdAsString); ctx.put("startUpClass", startUpClass); ctx.put("codebase", codebase); ctx.put("red5-host", rtmphostlocal); ctx.put("red5-app", OpenmeetingsVariables.webAppRootKey + "/" + room); Configuration configuration = getCfgManagement().getConfKey(3L, "default.quality.screensharing"); String default_quality_screensharing = "1"; if (configuration != null) { default_quality_screensharing = configuration.getConf_value(); } ctx.put("default_quality_screensharing", default_quality_screensharing); //invited guest does not have valid user_id (have user_id == -1) ctx.put("user_id", users_id); String port = httpServletRequest.getParameter("port"); if (port == null) { throw new Exception("port is empty: "); } ctx.put("port", port); String allowRecording = httpServletRequest.getParameter("allowRecording"); if (allowRecording == null) { throw new Exception("allowRecording is empty: "); } ctx.put("allowRecording", allowRecording); } catch (Exception e) { log.error("invalid configuration value for key screen_viewer!"); } String template = "screenshare.vm"; return getVelocityView().getVelocityEngine().getTemplate(template); } catch (Exception er) { log.error("[ScreenRequestHandler]", er); System.out.println("Error downloading: " + er); } return null; }
From source file:org.openmeetings.servlet.outputhandler.UploadController.java
@RequestMapping(value = "/upload.upload", method = RequestMethod.POST) public void handleFormUpload(HttpServletRequest request, HttpServletResponse response) throws ServletException { try {/* w w w . ja v a 2s . co m*/ UploadInfo info = validate(request, false); LinkedHashMap<String, Object> hs = prepareMessage(info); String room_id = request.getParameter("room_id"); if (room_id == null) { room_id = "default"; } String roomName = StringUtils.deleteWhitespace(room_id); String moduleName = request.getParameter("moduleName"); if (moduleName == null) { moduleName = "nomodule"; } if (moduleName.equals("nomodule")) { log.debug("module name missed"); return; } boolean userProfile = moduleName.equals("userprofile"); MultipartFile multipartFile = info.file; InputStream is = multipartFile.getInputStream(); String fileSystemName = info.filename; fileSystemName = StringUtils.deleteWhitespace(fileSystemName); // Flash cannot read the response of an upload // httpServletResponse.getWriter().print(returnError); uploadFile(request, userProfile, info.userId, roomName, is, fileSystemName, hs); sendMessage(info, hs); } catch (ServletException e) { throw e; } catch (Exception e) { log.error("Exception during upload: ", e); throw new ServletException(e); } }
From source file:org.openmrs.module.hl7query.HL7CompleteORUR01TemplateTest.java
@Test public void shouldEvaluateCompleteORUR01Template() throws Exception { //given/*from w w w. ja va 2 s . co m*/ Patient patient = new Patient(); List<Encounter> encounters = new ArrayList<Encounter>(); String locationUUID = "8bf21a4b-dc7e-4bd2-92f6-fac5eedf7db9"; Location location = new Location(); location.setUuid(locationUUID); location.setName("locationName"); Date encounterDatetime = new Date(); Encounter encounter = new Encounter(); encounter.setPatient(patient); encounter.setLocation(location); encounter.setEncounterType(new EncounterType("encounterTypeName", "")); encounter.setEncounterDatetime(encounterDatetime); encounters.add(encounter); Date encounter2Datetime = new Date(); Encounter encounter2 = new Encounter(); encounter2.setPatient(patient); encounter2.setLocation(location); encounter2.setEncounterType(new EncounterType("encounter2TypeName", "")); encounter2.setEncounterDatetime(encounter2Datetime); encounters.add(encounter2); Map<String, Object> bindings = new HashMap<String, Object>(); bindings.put("patient", patient); bindings.put("encounters", encounters); //when HL7Template hl7Template = hl7QueryService.getHL7TemplateByName("Generic ORUR01"); String evaluatedTemplate = hl7QueryService.evaluateTemplate(hl7Template, bindings); evaluatedTemplate = StringUtils.deleteWhitespace(evaluatedTemplate); //TODO update the expectedORUR01Output.xml file with valid concept names and Id numbers. String expectedOutput = IOUtils .toString(getClass().getClassLoader().getResourceAsStream("expectedORUR01Output.xml")); GenericParser parser = new GenericParser(); Message message; try { message = parser.parse(expectedOutput); } catch (EncodingNotSupportedException e) { Assert.assertTrue(e instanceof EncodingNotSupportedException); } catch (HL7Exception e) { Assert.assertTrue(e instanceof HL7Exception); } expectedOutput = StringUtils.deleteWhitespace(expectedOutput); HL7TemplateFunctions func = new HL7TemplateFunctions(); //replace the encounter datetime place holders with the actual dates /* expectedOutput = StringUtils.replace(expectedOutput, "${ENCOUNTER_1_DATETIME}", func.formatDate(encounterDatetime, null)); expectedOutput = StringUtils.replace(expectedOutput, "${ENCOUNTER_2_DATETIME}", func.formatDate(encounter2Datetime, null));*/ evaluatedTemplate = expectedOutput; //check for for the text in the MSH tag Assert.assertTrue(evaluatedTemplate.contains("<MSH.4><HD.1>OPENMRS</HD.1></MSH.4>")); //MSH-4: Source Assert.assertTrue(evaluatedTemplate.contains("<MSH.6><HD.1></HD.1></MSH.6>")); //MSH-6: Facility Assert.assertTrue(evaluatedTemplate.matches(".*<MSH\\.7><TS\\.1>\\d{12}\\d{2}?</TS\\.1></MSH\\.7>.*")); //MSH-7: Date/Time Assert.assertTrue(evaluatedTemplate .contains("<MSH.9><MSG.1>ORU</MSG.1><MSG.2>R01</MSG.2><MSG.3>ORU_R01</MSG.3></MSH.9>")); //MSH-9: Message Type Assert.assertTrue(evaluatedTemplate .matches(".*<MSH\\.10>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}</MSH\\.10>.*")); //MSH-10: Message ID Assert.assertTrue(evaluatedTemplate.contains("<MSH.11><PT.1>D</PT.1><PT.2>C</PT.2></MSH.11>")); //MSH-11: Processing Info Assert.assertTrue( evaluatedTemplate.contains("<MSH.12><VID.1>2.5</VID.1><VID.2><CE.1>RWA</CE.1></VID.2></MSH.12>")); //MSH-12: Version and I18N Code Assert.assertTrue(evaluatedTemplate.contains("<MSH.21><EI.1>CLSM_V0.83</EI.1></MSH.21></MSH>")); //MSH-21: Profile //Check that the rest of the text from the other templates exists, i.e after '</MSH>' tag Assert.assertEquals(expectedOutput.substring(expectedOutput.indexOf("</MSH>") + 6), evaluatedTemplate.substring(evaluatedTemplate.indexOf("</MSH>") + 6)); }
From source file:org.openmrs.module.hl7query.HL7OBRORUR01TemplateTest.java
@Test public void shouldEvaluateOBRORUR01TemplateForOBSGroup() throws Exception { //given//from w w w . j a v a2s. c o m Encounter encounter = new Encounter(); Date date = new Date(); encounter.setEncounterDatetime(date); encounter.setUuid("ENCOUNTER UUID"); EncounterType encounterType = new EncounterType(); encounterType.setName("ENCOUNTER TYPE NAME"); encounter.setEncounterType(encounterType); Location location = new Location(1); location.setUuid("LOCATION UUID"); location.setName("LOCATION NAME"); encounter.setLocation(location); Person provider = new Person(1); provider.setUuid("PROVIDER UUID"); provider.addName(new PersonName("PROVIDER GIVENNAME", "PROVIDER MIDDLENAME", "PROVIDER FAMILYNAME")); encounter.setProvider(provider); ConceptSource source = new ConceptSource(); source.setName("AMPATH"); ConceptMap map = new ConceptMap(); map.setSourceCode("200"); map.setSource(source); ConceptDatatype datatype = new ConceptDatatype(); datatype.setUuid(ConceptDatatype.NUMERIC_UUID); datatype.setHl7Abbreviation(ConceptDatatype.NUMERIC); ConceptNumeric concept = new ConceptNumeric(); concept.setDatatype(datatype); concept.addConceptMapping(map); concept.addName(new ConceptName("NumericConcept", Locale.ENGLISH)); concept.setUnits("mg"); Date dateCreated = new Date(213231421890234L); Obs obs = new Obs(2); obs.setConcept(concept); obs.setDateCreated(dateCreated); obs.setValueNumeric(10d); obs.setObsGroup(getObsGroup()); obs.getObsGroup().addGroupMember(obs); encounter.addObs(obs); obs = new Obs(3); obs.setConcept(concept); obs.setDateCreated(dateCreated); obs.setValueNumeric(23d); encounter.addObs(obs); Map<String, Object> bindings = new HashMap<String, Object>(); bindings.put("encounter", encounter); //when HL7Template hl7Template = hl7QueryService.getHL7TemplateByName("Generic Obs Group"); String evaluatedTemplate = hl7QueryService.evaluateTemplate(hl7Template, bindings); //then evaluatedTemplate = StringUtils.deleteWhitespace(evaluatedTemplate); Assert.assertEquals("<ORU_R01.ORDER_OBSERVATION><OBR><OBR.1>0</OBR.1><OBR.4><CE.1>100</CE.1>" + "<CE.2>MEDICALRECORDOBSERVATIONS</CE.2><CE.3>LOCAL</CE.3></OBR.4><OBR.18>0</OBR.18>" + "<OBR.29><EIP.2><EI.3>ENCOUNTERUUID</EI.3></EIP.2></OBR.29></OBR><ORU_R01.OBSERVATION>" + "<OBX><OBX.1>1</OBX.1><OBX.2>NM</OBX.2><OBX.3><CE.1>200</CE.1><CE.2>NumericConcept</CE.2>" + "<CE.3>AMPATH</CE.3></OBX.3><OBX.5>23.0</OBX.5><OBX.6><CE.1>mg</CE.1><CE.3>UCUM</CE.3></OBX.6>" + "<OBX.14><TS.1>" + new HL7TemplateFunctions().formatDate(dateCreated, null) + "</TS.1>" + "</OBX.14></OBX></ORU_R01.OBSERVATION></ORU_R01.ORDER_OBSERVATION>" + "<ORU_R01.ORDER_OBSERVATION><OBR><OBR.1>2</OBR.1><OBR.4><CE.1>100</CE.1><CE.2>MedSet</CE.2>" + "<CE.3>LOCAL</CE.3></OBR.4><OBR.18>0</OBR.18><OBR.29><EIP.2><EI.3>ENCOUNTERUUID</EI.3></EIP.2></OBR.29" + "></OBR><ORU_R01.OBSERVATION><OBX><OBX.1>2</OBX.1><OBX.2>NM</OBX.2><OBX.3><CE.1>200</CE.1>" + "<CE.2>NumericConcept</CE.2><CE.3>AMPATH</CE.3></OBX.3><OBX.5>10.0</OBX.5><OBX.6><CE.1>mg</CE.1>" + "<CE.3>UCUM</CE.3></OBX.6><OBX.14><TS.1>" + new HL7TemplateFunctions().formatDate(dateCreated, null) + "</TS.1></OBX.14></OBX></ORU_R01.OBSERVATION></ORU_R01.ORDER_OBSERVATION>", evaluatedTemplate); }
From source file:org.openmrs.module.hl7query.HL7OBXORUR01TemplateTest.java
@Test public void shouldEvaluateOBXORUR01TemplateForNumericConcept() throws Exception { //given//from w w w . j a va2 s . c om ConceptSource source = new ConceptSource(); source.setName("PIH"); ConceptMap map = new ConceptMap(); map.setSourceCode("100"); map.setSource(source); ConceptDatatype datatype = new ConceptDatatype(); datatype.setUuid(ConceptDatatype.NUMERIC_UUID); datatype.setHl7Abbreviation(ConceptDatatype.NUMERIC); ConceptNumeric concept = new ConceptNumeric(); concept.setDatatype(datatype); concept.addConceptMapping(map); concept.addName(new ConceptName("NumericConcept", Locale.ENGLISH)); concept.setUnits("mg"); Date dateCreated = new Date(); Obs obs = new Obs(); obs.setConcept(concept); obs.setDateCreated(dateCreated); obs.setValueNumeric(10d); Map<String, Object> bindings = new HashMap<String, Object>(); bindings.put("obsIndex", 0); bindings.put("obs", obs); bindings.put("implementationId", "MVP"); //when HL7Template hl7Template = hl7QueryService.getHL7TemplateByName("Generic OBX"); String evaluatedTemplate = hl7QueryService.evaluateTemplate(hl7Template, bindings); //then evaluatedTemplate = StringUtils.deleteWhitespace(evaluatedTemplate); Assert.assertEquals("<ORU_R01.OBSERVATION><OBX>" + "<OBX.1>0</OBX.1><OBX.2>NM</OBX.2>" + "<OBX.3><CE.1>100</CE.1><CE.2>NumericConcept</CE.2><CE.3>PIH</CE.3></OBX.3>" + "<OBX.5>10.0</OBX.5>" + "<OBX.6><CE.1>mg</CE.1><CE.3>UCUM</CE.3></OBX.6>" + "<OBX.14><TS.1>" + StringUtils.deleteWhitespace(new HL7TemplateFunctions().formatDate(dateCreated, null)) + "</TS.1></OBX.14>" + "</OBX></ORU_R01.OBSERVATION>", evaluatedTemplate); }
From source file:org.openmrs.module.hl7query.HL7OBXORUR01TemplateTest.java
@Test public void shouldEvaluateOBXORUR01TemplateForNumericConceptWithoutMapping() throws Exception { //given//from w w w . ja v a 2s. c o m ConceptDatatype datatype = new ConceptDatatype(); datatype.setUuid(ConceptDatatype.NUMERIC_UUID); datatype.setHl7Abbreviation(ConceptDatatype.NUMERIC); ConceptNumeric concept = new ConceptNumeric(); concept.setId(1); concept.setDatatype(datatype); concept.addName(new ConceptName("NumericConcept", Locale.ENGLISH)); concept.setUnits("mg"); Date dateCreated = new Date(); Obs obs = new Obs(); obs.setConcept(concept); obs.setDateCreated(dateCreated); obs.setValueNumeric(10d); Map<String, Object> bindings = new HashMap<String, Object>(); bindings.put("obsIndex", 0); bindings.put("obs", obs); bindings.put("implementationId", "MVP"); //when HL7Template hl7Template = hl7QueryService.getHL7TemplateByName("Generic OBX"); String evaluatedTemplate = hl7QueryService.evaluateTemplate(hl7Template, bindings); evaluatedTemplate = StringUtils.deleteWhitespace(evaluatedTemplate); //then Assert.assertEquals("<ORU_R01.OBSERVATION><OBX>" + "<OBX.1>0</OBX.1><OBX.2>NM</OBX.2>" + "<OBX.3><CE.1>1</CE.1><CE.2>NumericConcept</CE.2><CE.3>MVP</CE.3></OBX.3>" + "<OBX.5>10.0</OBX.5>" + "<OBX.6><CE.1>mg</CE.1><CE.3>UCUM</CE.3></OBX.6>" + "<OBX.14><TS.1>" + StringUtils.deleteWhitespace(new HL7TemplateFunctions().formatDate(dateCreated, null)) + "</TS.1></OBX.14>" + "</OBX></ORU_R01.OBSERVATION>", evaluatedTemplate); }
From source file:org.openmrs.module.hl7query.HL7OBXORUR01TemplateTest.java
@Test public void shouldEvaluateOBXORUR01TemplateForCodedConceptWithoutMappings() throws Exception { //given/*from w ww.ja v a 2 s. c om*/ ConceptDatatype datatype = new ConceptDatatype(); datatype.setUuid(ConceptDatatype.CODED_UUID); datatype.setHl7Abbreviation(ConceptDatatype.CODED); Concept concept = new Concept(1); concept.setDatatype(datatype); concept.addName(new ConceptName("CodedConcept", Locale.ENGLISH)); Concept conceptValue = new Concept(2); conceptValue.addName(new ConceptName("AnswerConcept", Locale.ENGLISH)); Date dateCreated = new Date(); Obs obs = new Obs(); obs.setConcept(concept); obs.setDateCreated(dateCreated); obs.setValueCoded(conceptValue); Map<String, Object> bindings = new HashMap<String, Object>(); bindings.put("obsIndex", 0); bindings.put("obs", obs); bindings.put("implementationId", "MVP"); //when HL7Template hl7Template = hl7QueryService.getHL7TemplateByName("Generic OBX"); String evaluatedTemplate = hl7QueryService.evaluateTemplate(hl7Template, bindings); evaluatedTemplate = StringUtils.deleteWhitespace(evaluatedTemplate); //then Assert.assertEquals("<ORU_R01.OBSERVATION><OBX>" + "<OBX.1>0</OBX.1><OBX.2>CWE</OBX.2>" + "<OBX.3><CE.1>1</CE.1><CE.2>CodedConcept</CE.2><CE.3>MVP</CE.3></OBX.3>" + "<OBX.5><CE.1>2</CE.1><CE.2>AnswerConcept</CE.2><CE.3>MVP</CE.3></OBX.5>" + "<OBX.14><TS.1>" + StringUtils.deleteWhitespace(new HL7TemplateFunctions().formatDate(dateCreated, null)) + "</TS.1></OBX.14>" + "</OBX></ORU_R01.OBSERVATION>", evaluatedTemplate); }