Obs newObs = new Obs(obsToCopy.getPerson(), obsToCopy.getConcept(), obsToCopy.getObsDatetime(), obsToCopy.getLocation()); newObs.setObsGroup(obsToCopy.getObsGroup()); newObs.setAccessionNumber(obsToCopy.getAccessionNumber()); newObs.setValueCoded(obsToCopy.getValueCoded()); newObs.setValueDrug(obsToCopy.getValueDrug()); newObs.setValueGroupId(obsToCopy.getValueGroupId()); newObs.setValueDatetime(obsToCopy.getValueDatetime()); newObs.setValueNumeric(obsToCopy.getValueNumeric()); newObs.setValueModifier(obsToCopy.getValueModifier()); newObs.setValueText(obsToCopy.getValueText()); newObs.setComment(obsToCopy.getComment()); newObs.setEncounter(obsToCopy.getEncounter()); newObs.setCreator(obsToCopy.getCreator()); newObs.setDateCreated(obsToCopy.getDateCreated()); newObs.setVoided(obsToCopy.getVoided()); newObs.setVoidedBy(obsToCopy.getVoidedBy()); newObs.setDateVoided(obsToCopy.getDateVoided()); newObs.setVoidReason(obsToCopy.getVoidReason()); newObs.setStatus(obsToCopy.getStatus()); newObs.setInterpretation(obsToCopy.getInterpretation()); newObs.setValueComplex(obsToCopy.getValueComplex()); newObs.setComplexData(obsToCopy.getComplexData()); newObs.setFormField(obsToCopy.getFormFieldNamespace(),obsToCopy.getFormFieldPath()); if (obsToCopy.hasGroupMembers(true)) { for (Obs member : obsToCopy.getGroupMembers(true)) {
obsExit = new Obs(); obsExit.setPerson(patient); obsExit.setConcept(reasonForExit); obsExit.setLocation(loc); } else { log.error("Could not find a suitable location for which to create this new Obs"); obsExit.setValueCoded(cause); obsExit.setValueCodedName(cause.getName()); // ABKTODO: presume current locale? obsExit.setObsDatetime(exitDate); Context.getObsService().saveObs(obsExit, "updated by PatientService.saveReasonForExit");
log.debug("getConcept() == " + getConcept()); if (getConcept() != null && !StringUtils.isBlank(s)) { String abbrev = getConcept().getDatatype().getHl7Abbreviation(); if ("BIT".equals(abbrev)) { setValueBoolean(Boolean.valueOf(s)); } else if ("CWE".equals(abbrev)) { throw new RuntimeException("Not Yet Implemented"); } else if ("NM".equals(abbrev) || "SN".equals(abbrev)) { setValueNumeric(Double.valueOf(s)); } else if ("DT".equals(abbrev)) { DateFormat dateFormat = new SimpleDateFormat(DATE_PATTERN); setValueDatetime(dateFormat.parse(s)); } else if ("TM".equals(abbrev)) { DateFormat timeFormat = new SimpleDateFormat(TIME_PATTERN); setValueDatetime(timeFormat.parse(s)); } else if ("TS".equals(abbrev)) { DateFormat datetimeFormat = new SimpleDateFormat(DATE_TIME_PATTERN); setValueDatetime(datetimeFormat.parse(s)); } else if ("ST".equals(abbrev)) { setValueText(s); } else { throw new RuntimeException("Don't know how to handle " + abbrev);
this(obs.getObsDatetime(), null, obs.getValueAsBoolean(), obs.getValueCoded(), obs.getValueDatetime(), obs .getValueNumeric(), obs.getValueText(), obs); Concept concept = obs.getConcept(); ConceptDatatype conceptDatatype;
Obs obs = new Obs(); obs.setOrder(order); obs.setConcept(concept); obs.setPerson(patient); obs.setEncounter(encounter); obs.setObsDatetime(datetime); obs.setLocation(location); obs.setValueGroupId(valueGroupId); obs.setValueDatetime(valueDatetime); obs.setValueCoded(valueCoded); obs.setValueNumeric(valueNumeric); obs.setValueModifier(valueModifier); obs.setValueText(valueText); obs.setComment(comment); assertEquals(order, saved.getOrder()); assertEquals(patient, saved.getPerson()); assertEquals(comment, saved.getComment()); assertEquals(concept, saved.getConcept()); assertEquals(encounter, saved.getEncounter()); assertEquals(DateUtil.truncateToSeconds(datetime), saved.getObsDatetime()); assertEquals(location, saved.getLocation()); assertEquals(valueGroupId, saved.getValueGroupId()); assertEquals(DateUtil.truncateToSeconds(valueDatetime), saved.getValueDatetime()); assertEquals(valueCoded, saved.getValueCoded()); assertEquals(valueNumeric, saved.getValueNumeric()); assertEquals(valueModifier, saved.getValueModifier()); assertEquals(valueText, saved.getValueText());
Obs obs = new Obs(); obs.setPerson(encounter.getPatient()); obs.setConcept(concept); obs.setEncounter(encounter); obs.setObsDatetime(datetime); obs.setLocation(encounter.getLocation()); obs.setCreator(encounter.getCreator()); obs.setDateCreated(encounter.getDateCreated()); obs.setComment(comments.toString()); } else if ("0".equals(value) || "1".equals(value)) { concept = concept.hydrate(concept.getConceptId().toString()); obs.setConcept(concept); if (concept.getDatatype().isBoolean()) { obs.setValueBoolean("1".equals(value)); } else if (concept.getDatatype().isNumeric()) { try { obs.setValueNumeric(Double.valueOf(value)); for (ConceptAnswer conceptAnswer : conceptAnswers) { if (conceptAnswer.getAnswerConcept().getId().equals(answer.getId())) { obs.setValueCoded(answer); isValidAnswer = true; break; new Object[] { obs.getConcept().getConceptId() }, null)); obs.setValueNumeric(Double.valueOf(value));
/** * @see ObsValidator#validate(java.lang.Object, org.springframework.validation.Errors) */ @Test public void validate_shouldPassValidationIfAllValuesPresent() { Obs obs = new Obs(); obs.setPerson(Context.getPersonService().getPerson(2)); obs.setConcept(Context.getConceptService().getConcept(5089)); obs.setObsDatetime(new Date()); obs.setValueNumeric(1.0); Errors errors = new BindException(obs, "obs"); obsValidator.validate(obs, errors); assertFalse(errors.hasErrors()); }
Obs o = new Obs(); o.setConcept(cs.getConcept(3)); o.setDateCreated(new Date()); o.setCreator(Context.getAuthenticatedUser()); o.setLocation(new Location(1)); o.setObsDatetime(new Date()); o.setPerson(new Patient(2)); o.setValueText("original obs value text"); Obs o2 = new Obs(); o2.setConcept(cs.getConcept(3)); o2.setDateCreated(new Date()); o2.setCreator(Context.getAuthenticatedUser()); o2.setLocation(new Location(1)); o2.setObsDatetime(new Date()); o2.setValueText("second obs value text"); o2.setPerson(new Patient(2)); Obs oParent = new Obs(); oParent.setConcept(cs.getConcept(23)); //in the concept set table as a set oParent.setDateCreated(new Date()); oParent.setCreator(Context.getAuthenticatedUser()); oParent.setLocation(new Location(1)); oParent.setObsDatetime(new Date()); oParent.setPerson(new Patient(2)); oParent.addGroupMember(o2); oParent.addGroupMember(o);
if (obs.getPersonId() == null) { errors.rejectValue("person", "error.null"); if (obs.getObsDatetime() == null) { errors.rejectValue("obsDatetime", "error.null"); if (obs.hasGroupMembers()) { if (obs.getValueCoded() != null) { errors.rejectValue("valueCoded", "error.not.null"); if (obs.getValueDrug() != null) { errors.rejectValue("valueDrug", "error.not.null"); if (obs.getValueDatetime() != null) { errors.rejectValue("valueDatetime", "error.not.null"); if (obs.getValueNumeric() != null) { errors.rejectValue("valueNumeric", "error.not.null"); if (obs.getValueModifier() != null) { errors.rejectValue("valueModifier", "error.not.null"); if (obs.getValueText() != null) { errors.rejectValue("valueText", "error.not.null"); if (obs.getValueBoolean() != null) { errors.rejectValue("valueBoolean", "error.not.null"); if (obs.getValueComplex() != null) {
if (getConcept() != null) { String abbrev = getConcept().getDatatype().getHl7Abbreviation(); if ("BIT".equals(abbrev)) { return getValueAsBoolean() == null ? "" : getValueAsBoolean().toString(); } else if ("CWE".equals(abbrev)) { if (getValueCoded() == null) { return ""; if (getValueDrug() != null) { return getValueDrug().getFullName(locale); } else { ConceptName codedName = getValueCodedName(); if (codedName != null) { return getValueCoded().getName(locale, false).getName(); } else { ConceptName fallbackName = getValueCoded().getName(); if (fallbackName != null) { return fallbackName.getName(); if (getValueNumeric() == null) { return ""; } else { if (getConcept() instanceof ConceptNumeric) { ConceptNumeric cn = (ConceptNumeric) getConcept(); if (!cn.getAllowDecimal()) { double d = getValueNumeric(); int i = (int) d; return Integer.toString(i); } else {
obs.setObsDatetime(new Date()); Obs child = null; for(Obs member : obs.getGroupMembers()) { member.setObsDatetime(newDate); if(member.getId() == 17) { child = member; Obs child1 = child.getGroupMembers().iterator().next(); child1.setObsDatetime(newDate); Obs o1 = new Obs(); o1.setConcept(cs.getConcept(3)); o1.setDateCreated(newDate); o1.setCreator(Context.getAuthenticatedUser()); o1.setLocation(new Location(1)); o1.setObsDatetime(newDate); o1.setValueText("NewObs Value"); o1.setPerson(new Patient(2)); child.addGroupMember(o1); Assert.assertEquals(newObs.getObsDatetime().toString(), newDate.toString()); for(Obs member : newObs.getGroupMembers()) { Assert.assertEquals(member.getObsDatetime().toString(), newDate.toString()); if(member.getGroupMembers()!= null) { for (Obs memberChild : member.getGroupMembers()) { Assert.assertEquals(memberChild.getObsDatetime().toString(), newDate.toString()); if (memberChild.getValueText()!= null && memberChild.getValueText().equals("NewObs Value")) {
public void validate_shouldFailIfParentObshasValues() { Obs obs = new Obs(); obs.setPerson(Context.getPersonService().getPerson(2)); obs.setConcept(Context.getConceptService().getConcept(18)); obs.setValueBoolean(false); obs.setValueCoded(Context.getConceptService().getConcept(18)); obs.setValueComplex("test"); obs.setValueDatetime(new Date()); obs.setValueDrug(Context.getConceptService().getDrug(3)); obs.setValueGroupId(getLoadCount()); obs.setValueModifier("test"); obs.setValueNumeric(1212.0); obs.setValueText("test"); obs.setGroupMembers(group);
@Test public void saveEncounter_shouldUpdateExistingEncounterWhenNewObsIsAddedToParentObs() { executeDataSet(ENC_OBS_HIERARCHY_DATA_XML); ConceptService cs = Context.getConceptService(); EncounterService es = Context.getEncounterService(); ObsService os = Context.getObsService(); Encounter enc = es.getEncounter(100); Obs o3 = new Obs(); o3.setConcept(cs.getConcept(3)); o3.setDateCreated(new Date()); o3.setCreator(Context.getAuthenticatedUser()); o3.setLocation(new Location(1)); o3.setObsDatetime(new Date()); o3.setPerson(Context.getPersonService().getPerson(3)); o3.setValueText("third obs value text"); o3.setEncounter(enc); Obs oParent = os.getObs(100); oParent.addGroupMember(o3); es.saveEncounter(enc); Context.flushSession(); Context.clearSession(); enc = es.getEncounter(100); Set<Obs> obsAtTopLevelUpdated = enc.getObsAtTopLevel(true); assertEquals(1,obsAtTopLevelUpdated.size()); assertEquals(3, obsAtTopLevelUpdated.iterator().next().getGroupMembers(true).size()); oParent = os.getObs(100); assertTrue(oParent.getGroupMembers(true).contains(os.getObs(101))); assertTrue(oParent.getGroupMembers(true).contains(os.getObs(102))); assertTrue(oParent.getGroupMembers(true).contains(os.getObs(o3.getObsId()))); }
@Test public void newInstance_shouldCopyMostFields() throws Exception { Obs obs = new Obs(); obs.setStatus(Obs.Status.PRELIMINARY); obs.setInterpretation(Obs.Interpretation.LOW); obs.setConcept(new Concept()); obs.setValueNumeric(1.2); Obs copy = Obs.newInstance(obs); // these fields are not copied assertThat(copy.getObsId(), nullValue()); assertThat(copy.getUuid(), not(obs.getUuid())); // other fields are copied assertThat(copy.getConcept(), is(obs.getConcept())); assertThat(copy.getValueNumeric(), is(obs.getValueNumeric())); assertThat(copy.getStatus(), is(obs.getStatus())); assertThat(copy.getInterpretation(), is(obs.getInterpretation())); // TODO test that the rest of the fields are set }
Obs ob = new Obs(); ob.setEncounter(cp.getEncounter()); ob.setConcept(cp.getObsConcept()); ob.setValueCoded(cp.getMappedConcept()); if (cp.getState().equals(OpenmrsConstants.CONCEPT_PROPOSAL_SYNONYM)) { ob.setValueCodedName(conceptName); ob.setCreator(Context.getAuthenticatedUser()); ob.setDateCreated(new Date()); ob.setObsDatetime(cp.getEncounter().getEncounterDatetime()); ob.setLocation(cp.getEncounter().getLocation()); ob.setPerson(cp.getEncounter().getPatient()); if (ob.getUuid() == null) { ob.setUuid(UUID.randomUUID().toString());
/** * @see ObsService#saveObs(Obs,String) */ @Test public void saveObs_shouldSetCreatorAndDateCreatedOnNewObs() { Obs o = new Obs(); o.setConcept(Context.getConceptService().getConcept(3)); o.setPerson(new Patient(2)); o.setEncounter(new Encounter(3)); o.setObsDatetime(new Date()); o.setLocation(new Location(1)); o.setValueNumeric(50d); Context.getObsService().saveObs(o, null); assertNotNull(o.getDateCreated()); assertNotNull(o.getCreator()); }
/** * @see ObsValidator#validate(Object,Errors) */ @Test public void validate_shouldPassIfAnswerConceptAndConceptOfValueDrugMatch() { Obs obs = new Obs(); obs.setPerson(new Person(7)); obs.setObsDatetime(new Date()); Concept questionConcept = new Concept(100); ConceptDatatype dt = new ConceptDatatype(1); dt.setUuid(ConceptDatatype.CODED_UUID); questionConcept.setDatatype(dt); obs.setConcept(questionConcept); Concept answerConcept = new Concept(101); obs.setValueCoded(answerConcept); Drug drug = new Drug(); drug.setConcept(answerConcept); obs.setValueDrug(drug); Errors errors = new BindException(obs, "obs"); obsValidator.validate(obs, errors); assertFalse(errors.hasFieldErrors()); }
/** * @see ObsService#saveObs(Obs,String) */ @Test public void saveObs_shouldCreateVeryBasicObsAndAddNewObsId() { Obs o = new Obs(); o.setConcept(Context.getConceptService().getConcept(3)); o.setPerson(new Patient(2)); o.setEncounter(new Encounter(3)); o.setObsDatetime(new Date()); o.setLocation(new Location(1)); o.setValueNumeric(50d); Obs oSaved = Context.getObsService().saveObs(o, null); // make sure the returned Obs and the passed in obs // now both have primary key obsIds assertTrue(oSaved.getObsId().equals(o.getObsId())); }
/** * @see Obs#getValueAsString(Locale) */ @Test public void getValueAsString_shouldUseCommasOrDecimalPlacesDependingOnLocale() throws Exception { Obs obs = new Obs(); obs.setValueNumeric(123456789.3); String str = "123456789,3"; Assert.assertEquals(str, obs.getValueAsString(Locale.GERMAN)); }
ConceptDatatype datatype = field.getQuestion().getDatatype(); if (datatype.isDateTime()) { value = field.getExistingObs().getValueDate() != null ? datetimeFormat.format(field.getExistingObs().getValueDate()) : ""; } else if (datatype.isDate()) { value = field.getExistingObs().getValueDate() != null ? dateFormat.format(field.getExistingObs().getValueDate()) : ""; } else if (datatype.isTime()) { value = field.getExistingObs().getValueDate() != null ? timeFormat.format(field.getExistingObs().getValueDate()) : ""; } else if (datatype.isNumeric()) { value = field.getExistingObs().getValueNumeric() != null ? field.getExistingObs().getValueNumeric().toString() : ""; } else if (datatype.isBoolean()) { value = field.getExistingObs().getValueBoolean() != null ? field.getExistingObs().getValueBoolean().toString() : ""; } else if (datatype.isText()) { if ("org.openmrs.Location".equals(field.getExistingObs().getComment())) { value = locationService.getLocation(new Integer(field.getExistingObs().getValueText())).getName(); value = field.getExistingObs().getValueText(); value = field.getExistingObs().getValueCodedName() != null ? field.getExistingObs().getValueCodedName().getName() : field.getExistingObs().getValueCoded() != null ? field.getExistingObs().getValueCoded().getName().getName() : "";