/** * Returns the boolean value if the concept of this obs is of boolean datatype * * @return true or false if value is set otherwise null * @should return true if value coded answer concept is true concept * @should return false if value coded answer concept is false concept */ public Boolean getValueBoolean() { if (getConcept() != null && valueCoded != null && getConcept().getDatatype().isBoolean()) { Concept trueConcept = Context.getConceptService().getTrueConcept(); return trueConcept != null && valueCoded.getId().equals(trueConcept.getId()); } return null; }
/** * Utility method to check if the concept is already attached to an observation (including * voided ones) and if the datatype of the concept has changed, an exception indicating that the * datatype cannot be modified will be reported if the concept is attached to an observation. * This method will only allow changing boolean concepts to coded. * * @param concept * @throws ConceptInUseException */ private void checkIfDatatypeCanBeChanged(Concept concept) { if (concept.getId() != null && hasAnyObservation(concept) && hasDatatypeChanged(concept)) { // allow boolean concepts to be converted to coded if (!(dao.getSavedConceptDatatype(concept).isBoolean() && concept.getDatatype().isCoded())) { throw new ConceptInUseException(); } if (log.isDebugEnabled()) { log.debug("Converting datatype of concept with id " + concept.getConceptId() + " from Boolean to Coded"); } } }
/** * Sets the value of this obs to the specified valueBoolean if this obs has a boolean concept. * * @param valueBoolean the boolean value matching the boolean coded concept to set to */ public void setValueBoolean(Boolean valueBoolean) { if (getConcept() != null && getConcept().getDatatype() != null && getConcept().getDatatype().isBoolean()) { if (valueBoolean != null) { setValueCoded(valueBoolean ? Context.getConceptService().getTrueConcept() : Context .getConceptService().getFalseConcept()); } else { setValueCoded(null); } } }
/** * @see org.openmrs.api.ConceptService#convertBooleanConceptToCoded(org.openmrs.Concept) */ @Override public void convertBooleanConceptToCoded(Concept conceptToChange) throws APIException { if (conceptToChange != null) { if (!conceptToChange.getDatatype().isBoolean()) { throw new APIException("Concept.datatype.invalid", (Object[]) null); } conceptToChange.setDatatype(getConceptDatatypeByName("Coded")); conceptToChange.addAnswer(new ConceptAnswer(getTrueConcept())); conceptToChange.addAnswer(new ConceptAnswer(getFalseConcept())); Context.getConceptService().saveConcept(conceptToChange); } }
concept = concept.hydrate(concept.getConceptId().toString()); obs.setConcept(concept); if (concept.getDatatype().isBoolean()) { obs.setValueBoolean("1".equals(value)); } else if (concept.getDatatype().isNumeric()) {
} else if (conceptDatatype.isText()) { this.datatype = Datatype.TEXT; } else if (conceptDatatype.isBoolean()) { this.datatype = Datatype.BOOLEAN;
ConceptDatatype dt = c.getDatatype(); if (dt != null) { if (dt.isBoolean() && obs.getValueBoolean() == null) { if (atRootNode) { errors.rejectValue("valueBoolean", "error.null");
} else if (obs.getConcept().getDatatype().isBoolean()) { if (value instanceof Concept) { value = ((Concept) value).getUuid();
existingObs = context.getObsFromCurrentGroup(concept, answerConcept); } else if (concept != null) { if (concept.getDatatype().isBoolean() && "checkbox".equals(parameters.get("style"))) { } else if (concept.getDatatype().isBoolean()) { String noStr = parameters.get("noLabel"); if (StringUtils.isEmpty(noStr)) {
obs.setValueCoded((Concept) convertToType(value.toString(), Concept.class)); } else if (dt.isBoolean()) { if (value != null) { try {
ConceptDatatype datatype5 = mock(ConceptDatatype.class); when(datatype5.getName()).thenReturn("boolean"); when(datatype5.isBoolean()).thenReturn(true); when(concept5.getDatatype()).thenReturn(datatype5); field5.setQuestion(concept5);
value = field.getExistingObs().getValueNumeric() != null ? field.getExistingObs().getValueNumeric().toString() : ""; } else if (datatype.isBoolean()) { value = field.getExistingObs().getValueBoolean() != null ? field.getExistingObs().getValueBoolean().toString() : "";
MRSObservation convertOpenMRSToMRSObservation(Obs obs) { ConceptDatatype datatype = obs.getConcept().getDatatype(); if (datatype.isAnswerOnly()) { return createMRSObservation(obs, null); } else if (datatype.isBoolean()) { return createMRSObservation(obs, obs.getValueAsBoolean()); } else if (datatype.isDateTime()) { return createMRSObservation(obs, obs.getValueDatetime()); } else if (datatype.isNumeric()) { return createMRSObservation(obs, obs.getValueNumeric()); } else if (datatype.isText()) { return createMRSObservation(obs, obs.getValueText()); } else if (datatype.isCoded()) { return createMRSObservation(obs, new OpenMRSConcept(new OpenMRSConceptName(obs.getValueCoded().getName().getName()))); } else { throw new IllegalArgumentException("Invalid value of the createMRSObservation from DB-" + obs); } }