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.openmrs.module.hl7query.HL7OBXORUR01TemplateTest.java
@Test public void shouldEvaluateOBXORUR01TemplateForCodedConcept() throws Exception { //given//w ww .ja va 2s. co m 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)); ConceptSource source = new ConceptSource(); source.setName("PIH"); ConceptMap map = new ConceptMap(); map.setSourceCode("100"); map.setSource(source); Concept conceptValue = new Concept(2); conceptValue.addName(new ConceptName("AnswerConcept", Locale.ENGLISH)); conceptValue.addConceptMapping(map); 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>100</CE.1><CE.2>AnswerConcept</CE.2><CE.3>PIH</CE.3></OBX.5>" + "<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.HL7PatientORUR01TemplateTest.java
@Test public void shouldEvaluatePatientORUR01Template() throws Exception { //given// www. j a v a2 s .c o m PatientIdentifierType patientIdentifierType = new PatientIdentifierType(); patientIdentifierType.setName("IDENTIFIER TYPE"); PatientIdentifier patientIdentifier = new PatientIdentifier(); patientIdentifier.setIdentifier("PATIENT IDENTIFIER"); patientIdentifier.setPreferred(true); patientIdentifier.setIdentifierType(patientIdentifierType); PatientIdentifier patientIdentifier2 = new PatientIdentifier(); patientIdentifier2.setIdentifier("PATIENT IDENTIFIER2"); patientIdentifier2.setPreferred(true); patientIdentifier2.setIdentifierType(patientIdentifierType); PersonName personName = new PersonName("PATIENT GIVENNAME", "PATIENT MIDDLENAME", "PATIENT FAMILYNAME"); personName.setPreferred(true); PersonName personName2 = new PersonName("PATIENT GIVENNAME2", "PATIENT MIDDLENAME2", "PATIENT FAMILYNAME2"); personName2.setPreferred(false); Patient patient = new Patient(); patient.addIdentifier(patientIdentifier); patient.addIdentifier(patientIdentifier2); patient.addName(personName); patient.addName(personName2); String locationUUID = "3d8bb0d6-6b5b-4f6d-92a3-d9b8e4972d48"; Location location = new Location(); location.setUuid(locationUUID); location.setName("locationName"); Date encounterDatetime = new Date(213231421890234L); Encounter encounter = new Encounter(); encounter.setLocation(location); encounter.setEncounterType(new EncounterType("encounterTypeName", "")); encounter.setEncounterDatetime(encounterDatetime); encounter.setPatient(patient); Map<String, Object> bindings = new HashMap<String, Object>(); bindings.put("encounter", encounter); //when HL7Template hl7Template = hl7QueryService.getHL7TemplateByName("Generic Patient"); String evaluatedTemplate = hl7QueryService.evaluateTemplate(hl7Template, bindings); evaluatedTemplate = StringUtils.deleteWhitespace(evaluatedTemplate); //then Assert.assertEquals("<ORU_R01.PATIENT><PID><PID.1>1</PID.1><PID.3><CX.1>PATIENTIDENTIFIER</CX.1>" + "<CX.5>IDENTIFIERTYPE</CX.5></PID.3><PID.3><CX.1>PATIENTIDENTIFIER2</CX.1>" + "<CX.5>IDENTIFIERTYPE</CX.5></PID.3><PID.5><XPN.1><FN.1>PATIENTFAMILYNAME</FN.1></XPN.1>" + "<XPN.2>PATIENTGIVENNAME</XPN.2><XPN.3>PATIENTMIDDLENAME</XPN.3></PID.5></PID>" + "<ORU_R01.VISIT><PV1><PV1.2>0</PV1.2><PV1.3><PL.1>3d8bb0d6-6b5b-4f6d-92a3-d9b8e4972d48</PL.1>" + "<PL.4><HD.1>locationName</HD.1></PL.4></PV1.3><PV1.4>encounterTypeName</PV1.4><PV1.7>" + "<XCN.1>null</XCN.1><XCN.2><FN.1>null</FN.1></XCN.2><XCN.3>null</XCN.3><XCN.13>NID</XCN.13></PV1.7>" + "<PV1.44><TS.1>" + new HL7TemplateFunctions().formatDate(encounterDatetime, null) + "</TS.1></PV1.44></PV1></ORU_R01.VISIT></ORU_R01.PATIENT>", evaluatedTemplate); System.out.print(UUID.randomUUID().toString()); }
From source file:org.openmrs.module.hl7query.web.controller.HL7QueryControllerTest.java
/** * @see {@link HL7QueryController#getEncounters(String,String,String,Date,Date,HttpServletRequest)} *//* w w w . ja v a 2s. c o m*/ @Test @Verifies(value = "should return the expected hl7 output as xml if the xml header exists", method = "getEncounters(String,String,String,Date,Date,HttpServletRequest)") public void getEncounters_shouldReturnTheExpectedHl7OutputAsXmlIfTheXmlHeaderExists() throws Exception { //TODO Add the ORU_R01.ORDER_OBSERVATION tags(obs) to the test file 'expectedORUR01Output.xml' //When https://tickets.openmrs.org/browse/HLQRY-38 is completed String expectedOutput = IOUtils .toString(getClass().getClassLoader().getResourceAsStream("expectedORUR01XmlOutput.xml")); expectedOutput = StringUtils.deleteWhitespace(expectedOutput); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); request.addHeader("Accept", "text/xml"); String hl7Output = new HL7QueryController() .getEncounters(null, null, ENCOUNTER_1_UUID, null, null, request, response).toString(); hl7Output = StringUtils.deleteWhitespace(hl7Output); //Ignore timestamp by removing it hl7Output = StringUtils.replace(hl7Output, StringUtils.substringBetween(hl7Output, "<TS.1>", "</TS.1>"), ""); //Ignore the uuid of the message hl7Output = StringUtils.replace(hl7Output, StringUtils.substringBetween(hl7Output, "<MSH.10>", "</MSH.10>"), ""); Assert.assertEquals(expectedOutput, hl7Output); }
From source file:org.openmrs.module.hl7query.web.controller.HL7QueryControllerTest.java
/** * @see {@link HL7QueryController#getEncounters(String,String,String,Date,Date,HttpServletRequest)} *//*ww w .j a v a 2s.co m*/ @Test @Verifies(value = "should return the expected hl7 in the format that matches the accept header value", method = "getEncounters(String,String,String,Date,Date,HttpServletRequest)") public void getEncounters_shouldReturnTheExpectedHl7InTheFormatThatMatchesTheAcceptHeaderValue() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); String hl7Output = new HL7QueryController() .getEncounters(null, null, ENCOUNTER_1_UUID, null, null, request, response).toString(); hl7Output = StringUtils.deleteWhitespace(hl7Output); //Test if constant values exist in pipe delimited format Assert.assertTrue(hl7Output.contains("||ORU^R01^ORU_R01|")); Assert.assertTrue(hl7Output.contains("|D^C|2.5^RWA|||||||||CLSM_V0.83PID|1PV1||0|")); Assert.assertFalse(hl7Output.contains("<ORU_R01 xmlns=\"urn:hl7-org:v2xml\">")); Assert.assertFalse(hl7Output.contains("</ORU_R01>")); }
From source file:org.openmrs.module.hl7query.web.controller.HL7QueryControllerTest.java
/** * @see {@link HL7QueryController#getEncounters(String,String,String,Date,Date,HttpServletRequest)} *//*from w w w . j a va 2s .c o m*/ @Test @Verifies(value = "should return the patient encounters given the patient identifier and id type", method = "getEncounters(String,String,String,Date,Date,HttpServletRequest)") public void getEncounters_shouldReturnThePatientEncountersGivenThePatientIdentifierAndIdType() throws Exception { //TODO Add the ORU_R01.ORDER_OBSERVATION tags(obs) to the test file 'expectedOutput_encountersByPatient.xml' //When https://tickets.openmrs.org/browse/HLQRY-38 is completed String expectedOutput = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("expectedOutput_encountersByPatient.xml")); expectedOutput = StringUtils.deleteWhitespace(expectedOutput); final String identifier = "6TS-4"; final String identifierTypeUuid = "1a339fe9-38bc-4ab3-b180-320988c0b968"; final int expectedEncounterCount = 3; Patient patient = Context.getPatientService().getPatient(7); //sanity checks Assert.assertEquals(identifier, patient.getPatientIdentifier().getIdentifier()); Assert.assertEquals(identifierTypeUuid, patient.getPatientIdentifier().getIdentifierType().getUuid()); Assert.assertEquals(expectedEncounterCount, Context.getEncounterService().getEncountersByPatient(patient).size()); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); request.addHeader("Accept", "text/xml"); String hl7Output = new HL7QueryController() .getEncounters(identifier, identifierTypeUuid, null, null, null, request, response).toString(); hl7Output = StringUtils.deleteWhitespace(hl7Output); //Ignore timestamp by removing it hl7Output = StringUtils.replace(hl7Output, StringUtils.substringBetween(hl7Output, "<TS.1>", "</TS.1>"), ""); //Ignore the uuid of the message hl7Output = StringUtils.replace(hl7Output, StringUtils.substringBetween(hl7Output, "<MSH.10>", "</MSH.10>"), ""); Assert.assertEquals(expectedOutput, hl7Output); }
From source file:org.openmrs.module.hl7query.web.controller.HL7QueryControllerTest.java
/** * @see {@link HL7QueryController#getEncounters(String,String,String,Date,Date,HttpServletRequest)} *///from w w w. ja va 2s .c o m @Test @Verifies(value = "should return the patient encounters matching specified start and end encounter dates", method = "getEncounters(String,String,String,Date,Date,HttpServletRequest)") public void getEncounters_shouldReturnThePatientEncountersMatchingSpecifiedStartAndEndEncounterDates() throws Exception { //TODO Add the ORU_R01.ORDER_OBSERVATION tags(obs) to the test file 'expectedOutput_encountersByStartAndEndDate.xml' //When https://tickets.openmrs.org/browse/HLQRY-38 is completed String expectedOutput = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("expectedOutput_encountersByStartAndEndDate.xml")); expectedOutput = StringUtils.deleteWhitespace(expectedOutput); final String identifier = "6TS-4"; final String identifierTypeUuid = "1a339fe9-38bc-4ab3-b180-320988c0b968"; Patient patient = Context.getPatientService().getPatient(7); //sanity checks Assert.assertEquals(identifier, patient.getPatientIdentifier().getIdentifier()); Assert.assertEquals(identifierTypeUuid, patient.getPatientIdentifier().getIdentifierType().getUuid()); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); request.addHeader("Accept", "text/xml"); Encounter expectedEncounter = Context.getEncounterService().getEncounter(4); String hl7Output = new HL7QueryController() .getEncounters(identifier, identifierTypeUuid, null, expectedEncounter.getEncounterDatetime(), expectedEncounter.getEncounterDatetime(), request, response) .toString(); hl7Output = StringUtils.deleteWhitespace(hl7Output); //Ignore timestamp by removing it hl7Output = StringUtils.replace(hl7Output, StringUtils.substringBetween(hl7Output, "<TS.1>", "</TS.1>"), ""); //Ignore the uuid of the message hl7Output = StringUtils.replace(hl7Output, StringUtils.substringBetween(hl7Output, "<MSH.10>", "</MSH.10>"), ""); Assert.assertEquals(expectedOutput, hl7Output); }
From source file:org.openmrs.module.hl7query.web.controller.HL7QueryControllerTest.java
@Test @Verifies(value = "should return appopriately formed error message if patient id and encounter uuid are null", method = "getEncounters(String,String,String,Date,Date,HttpServletRequest)") public void getEncounters_shouldReturnAppopriatelyFormedErrorMessageIfPatientIdAndEncounterUuidAreNull() throws Exception { //Test the xml formatted error message String expectedOutput = IOUtils .toString(getClass().getClassLoader().getResourceAsStream("missingIdentifiersXmlError.xml")); expectedOutput = StringUtils.deleteWhitespace(expectedOutput); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); request.addHeader("Accept", "text/xml"); String hl7Output = new HL7QueryController().getEncounters(null, null, null, null, null, request, response) .toString();/*from w w w . j ava2s . c o m*/ hl7Output = StringUtils.deleteWhitespace(hl7Output); Assert.assertEquals(hl7Output, expectedOutput); //Test the json error message String expectedPipeOutput = IOUtils .toString(getClass().getClassLoader().getResourceAsStream("missingIdentifiersJsonError.json")); expectedPipeOutput = StringUtils.deleteWhitespace(expectedPipeOutput); MockHttpServletRequest pipeRequest = new MockHttpServletRequest(); MockHttpServletResponse pipeResponse = new MockHttpServletResponse(); String hl7PipeOutput = new HL7QueryController() .getEncounters(null, null, null, null, null, pipeRequest, pipeResponse).toString(); hl7Output = StringUtils.deleteWhitespace(hl7PipeOutput); Assert.assertEquals(hl7PipeOutput, expectedPipeOutput); }
From source file:org.openmrs.module.hl7query.web.controller.HL7QueryControllerTest.java
@Test @Verifies(value = "should return appopriately formed error message if encounter uuid is not found", method = "getEncounters(String,String,String,Date,Date,HttpServletRequest)") public void getEncounters_shouldReturnAppopriatelyFormedErrorMessageIfEncounterUuidIsNotFound() throws Exception { //Test the xml formatted error message String expectedOutput = IOUtils .toString(getClass().getClassLoader().getResourceAsStream("missingEncounterUuidXmlError.xml")); expectedOutput = StringUtils.deleteWhitespace(expectedOutput); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); request.addHeader("Accept", "text/xml"); String hl7Output = new HL7QueryController().getEncounters(null, null, "0", null, null, request, response) .toString();//from ww w . j a v a2 s.c o m hl7Output = StringUtils.deleteWhitespace(hl7Output); Assert.assertEquals(hl7Output, expectedOutput); //Test the json error message String expectedPipeOutput = IOUtils .toString(getClass().getClassLoader().getResourceAsStream("missingEncounterUuidJsonError.json")); MockHttpServletRequest pipeRequest = new MockHttpServletRequest(); MockHttpServletResponse pipeResponse = new MockHttpServletResponse(); String hl7PipeOutput = new HL7QueryController() .getEncounters(null, null, "0", null, null, pipeRequest, pipeResponse).toString(); Assert.assertEquals(hl7PipeOutput, expectedPipeOutput); }
From source file:org.openmrs.module.patientsummary.PatientSummaryTestUtil.java
/** * Utility method that tests that the results of evaluating a particular template, * for a particular report definition, produces a particular result *//*from www . j ava2s . co m*/ public static void testGroovyTemplate(PatientSummaryReportDefinition rd, Integer patientId, String templatePrefix) throws Exception { PatientSummaryTemplate template = createGroovyTemplate("Test", rd, "templates/" + templatePrefix + "Template.txt"); String expectedResults = PatientSummaryTestUtil .getResourceAsString("templates/" + templatePrefix + "Output.txt"); PatientSummaryService pss = Context.getService(PatientSummaryService.class); PatientSummaryResult result = pss.evaluatePatientSummaryTemplate(template, patientId, new HashMap<String, Object>()); Assert.assertNull(result.getErrorDetails()); String actualResult = new String(result.getRawContents(), "UTF-8"); Assert.assertEquals(StringUtils.deleteWhitespace(expectedResults), StringUtils.deleteWhitespace(actualResult)); }
From source file:org.openmrs.module.patientsummary.web.PatientSummaryWebConfiguration.java
public static void saveEnableTemplateOnPatientDashboard(PatientSummaryTemplate template, boolean enableOnPatientDashboard) { PatientSummaryService service = Context.getService(PatientSummaryService.class); String templateUuid = template.getUuid(); GlobalProperty gp = Context.getAdministrationService() .getGlobalPropertyObject(GP_PATIENT_DASHBOARD_SUMMARIES); if (gp == null) { gp = new GlobalProperty(GP_PATIENT_DASHBOARD_SUMMARIES); }/*from w w w.j ava 2 s . c om*/ String uuids = gp.getPropertyValue(); if (uuids == null) { uuids = ""; } uuids = StringUtils.deleteWhitespace(uuids); String[] uuidArray = uuids.split(","); List<String> uuidList = new ArrayList<String>(); for (int index = 0; index < uuidArray.length; index++) { String uuid = uuidArray[index]; if (StringUtils.isBlank(uuid)) { continue; } //Add only if uuid references an existing template. if (service.getPatientSummaryTemplateByUuid(uuid) != null) { uuidList.add(uuid); } } if (enableOnPatientDashboard) { //Add this template uuid if not already part of the global property value. if (!uuidList.contains(templateUuid)) { uuidList.add(templateUuid); } } else { //Remove this template uuid if already part of the global property value. if (uuidList.contains(templateUuid)) { uuidList.remove(templateUuid); } } uuids = StringUtils.join(uuidList, ","); gp.setPropertyValue(uuids); Context.getAdministrationService().saveGlobalProperty(gp); }