/** * Creates a new person stub. * * @param given * @param middle * @param family * @param birthdate * @param dateformat * @param age * @param gender * @return PersonListItem person stub created */ public Object createPerson( String given, String middle, String family, String birthdate, String dateformat, String age, String gender) { log.error( given + " " + middle + " " + family + " " + birthdate + " " + dateformat + " " + age + " " + gender); User user = Context.getAuthenticatedUser(); Person p = new Person(); p.setPersonCreator(user); p.setPersonDateCreated(new Date()); p.setPersonChangedBy(user); p.setPersonDateChanged(new Date()); if (StringUtils.isEmpty(gender)) { log.error("Gender cannot be null."); return String.valueOf("Gender cannot be null."); } else if (gender.toUpperCase().contains("M")) { p.setGender("M"); } else if (gender.toUpperCase().contains("F")) { p.setGender("F"); } else { log.error("Gender must be 'M' or 'F'."); return new String("Gender must be 'M' or 'F'."); } if ("".equals(given) || "".equals(family)) { log.error("Given name and family name cannot be null."); return new String("Given name and family name cannot be null."); } PersonName name = new PersonName(given, middle, family); name.setCreator(user); name.setDateCreated(new Date()); name.setChangedBy(user); name.setDateChanged(new Date()); p.addName(name); try { Date d = updateAge(birthdate, dateformat, age); p.setBirthdate(d); } catch (java.text.ParseException pe) { log.error(pe); return new String("Birthdate cannot be parsed."); } p.setGender(gender); Person person = Context.getPersonService().savePerson(p); return PersonListItem.createBestMatch(person); }
@Test public void shouldEvaluateOBRORUR01TemplateForOBSGroup() throws Exception { // given 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); bindings.put("implementationId", "MVP"); // 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); }