/** * This method will <i>always</i> return true for ConceptNumeric objects that have a datatype of * Numeric * * @see org.openmrs.Concept#isNumeric() */ @Override public boolean isNumeric() { return "Numeric".equals(getDatatype().getName()); }
return; if (conceptDatatype.isCoded()) { this.datatype = Datatype.CODED; } else if (conceptDatatype.isNumeric()) { this.datatype = Datatype.NUMERIC; } else if (conceptDatatype.isDate()) { this.datatype = Datatype.DATETIME; } else if (conceptDatatype.isText()) { this.datatype = Datatype.TEXT; } else if (conceptDatatype.isBoolean()) { this.datatype = Datatype.BOOLEAN;
/** * @return <code>true</code> if datatype is representation of date (but NOT a time or * datatime--see containsDate() and containsTime()) */ public boolean isDate() { return DATE_UUID.equals(getUuid()); }
/** * 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"); } } }
/** * @see ConceptDatatypeValidator#validate(Object,Errors) */ @Test public void validate_shouldPassValidationIfFieldLengthsAreCorrect() { ConceptDatatype cd = new ConceptDatatype(); cd.setName("name"); cd.setDescription("some text"); cd.setHl7Abbreviation("hl7"); cd.setRetireReason("retireReason"); Errors errors = new BindException(cd, "cd"); new ConceptDatatypeValidator().validate(cd, errors); Assert.assertFalse(errors.hasErrors()); }
ConceptDatatype dt = c.getDatatype(); if (dt != null) { if (dt.isBoolean() && obs.getValueBoolean() == null) { if (atRootNode) { errors.rejectValue("valueBoolean", "error.null"); } else if (dt.isCoded() && obs.getValueCoded() == null) { if (atRootNode) { errors.rejectValue("valueCoded", "error.null"); } else if ((dt.isDateTime() || dt.isDate() || dt.isTime()) && obs.getValueDatetime() == null) { if (atRootNode) { errors.rejectValue("valueDatetime", "error.null"); } else if (dt.isNumeric() && obs.getValueNumeric() == null) { if (atRootNode) { errors.rejectValue("valueNumeric", "error.null"); } else if (dt.isNumeric()) { ConceptNumeric cn = Context.getConceptService().getConceptNumeric(c.getConceptId()); } else if (dt.isText() && obs.getValueText() == null) { if (atRootNode) { errors.rejectValue("valueText", "error.null"); if (dt.isText() && obs.getValueText() != null && obs.getValueText().length() > VALUE_TEXT_MAX_LENGTH) { if (atRootNode) { errors.rejectValue("valueText", "error.exceededMaxLengthOfField");
obs.setConcept(concept); ConceptDatatype dt = obs.getConcept().getDatatype(); if (dt.isNumeric()) { obs.setValueNumeric(Double.parseDouble(value.toString())); } else if (HtmlFormEntryConstants.COMPLEX_UUID.equals(dt.getUuid())) { obs.setComplexData((ComplexData) value); obs.setValueComplex(obs.getComplexData().getTitle()); } else if (dt.isText()) { if (value instanceof Location) { Location location = (Location) value; } else if (dt.isCoded()) { if (value instanceof Drug) { obs.setValueDrug((Drug) value); } else if (dt.isBoolean()) { if (value != null) { try { } else if (ConceptDatatype.DATE.equals(dt.getHl7Abbreviation()) || ConceptDatatype.TIME.equals(dt.getHl7Abbreviation()) || ConceptDatatype.DATETIME.equals(dt.getHl7Abbreviation())) { Date date = (Date) value; obs.setValueDatetime(date); } else if ("ZZ".equals(dt.getHl7Abbreviation())) { throw new IllegalArgumentException("concept datatype not yet implemented: " + dt.getName() + " with Hl7 Abbreviation: " + dt.getHl7Abbreviation());
/** * Given a FormField, infers the related widget from the ConceptDatatype associated with that FormField. */ public static WidgetTypeHint inferWidgetTypeHint(FormField formField) { ConceptDatatype dt = formField.getField().getConcept().getDatatype(); if (dt.isText()) { return WidgetTypeHint.TEXT; } else if (dt.isNumeric()) { return WidgetTypeHint.NUMBER; } else if (dt.isDate()) { return WidgetTypeHint.DATE; } else if (dt.isCoded()) { if (formField.getField().isSelectMultiple()) return WidgetTypeHint.CHECKBOX_LIST; else if (formField.getField().getDefaultValue() != null) return WidgetTypeHint.CHECKBOX; else return WidgetTypeHint.DROPDOWN; } else if (HtmlFormEntryConstants.COMPLEX_UUID.equals(dt.getUuid())) { return WidgetTypeHint.UPLOAD_WIDGET; } else { throw new IllegalArgumentException( "Autodetecting widget type from concept datatype not yet implemented for " + dt.getName()); } }
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); } }
@Test public void shouldGetAConceptDatatypeByName() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI() + "/Coded"); SimpleObject result = deserialize(handle(req)); ConceptDatatype conceptDataType = service.getConceptDatatypeByName("Coded"); Assert.assertEquals(conceptDataType.getUuid(), PropertyUtils.getProperty(result, "uuid")); Assert.assertEquals(conceptDataType.getName(), PropertyUtils.getProperty(result, "name")); }
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)); new Object[] { value, concept.getConceptId(), conceptName.getName(), uid }, null), e); } else if (concept.getDatatype().isCoded()) { Concept answer = "1".equals(value) ? Context.getConceptService().getTrueConcept() : Context .getConceptService().getFalseConcept();
ConceptDatatype datatype = concept.getDatatype(); if (datatype.isNumeric()) { while (obsIterator.hasNext()) { currentObs = obsIterator.next(); } else if (datatype.isText()) { while (obsIterator.hasNext()) { currentObs = obsIterator.next(); } else if (datatype.isCoded()) { while (obsIterator.hasNext()) { currentObs = obsIterator.next();
@Override public void validateDefaultRepresentation() throws Exception { super.validateDefaultRepresentation(); assertPropEquals("name", getObject().getName()); assertPropEquals("description", getObject().getDescription()); assertPropEquals("hl7Abbreviation", getObject().getHl7Abbreviation()); assertPropEquals("retired", getObject().getRetired()); }
@Test public void validate_shouldPassIfFullySpecifiedNameIsTheSameAsShortName() { ConceptName conceptFullySpecifiedName = new ConceptName("YES", new Locale("pl")); conceptFullySpecifiedName.setConceptNameType(ConceptNameType.FULLY_SPECIFIED); ConceptName conceptShortName = new ConceptName("yes", new Locale("pl")); conceptShortName.setConceptNameType(ConceptNameType.SHORT); concept.addName(conceptFullySpecifiedName); concept.addName(conceptShortName); concept.addDescription(new ConceptDescription("some description",null)); concept.setConceptClass(new ConceptClass()); concept.setDatatype(new ConceptDatatype()); validator.validate(concept, errors); Assert.assertFalse(errors.hasErrors()); }
/** * 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; }
@Test public void setValueBoolean_shouldNotSetValueForNonBooleanConcept() throws Exception { Obs obs = createObs(2); ConceptDatatype dataType = new ConceptDatatype(); dataType.setUuid(ConceptDatatype.CODED_UUID); obs.getConcept().setDatatype(dataType); assertNotNull(obs.getValueCoded()); obs.setValueBoolean(null); assertNotNull(obs.getValueCoded()); } }
/** * @see ConceptDatatypeValidator#validate(Object,Errors) */ @Test public void validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues() { ConceptDatatype cd = new ConceptDatatype(); cd.setName("name"); cd.setDescription("some text"); Errors errors = new BindException(cd, "cd"); new ConceptDatatypeValidator().validate(cd, errors); Assert.assertFalse(errors.hasErrors()); }
@Test public void getValueAsString_shouldReturnDateInCorrectFormat() throws Exception { Obs obs = new Obs(); obs.setValueDatetime(new Date()); Concept cn = new Concept(); ConceptDatatype cdt = new ConceptDatatype(); cdt.setHl7Abbreviation("DT"); cn.setDatatype(cdt); obs.setConcept(cn); Date utilDate = new Date(); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); String dateString = dateFormat.format(utilDate); Assert.assertEquals(dateString, obs.getValueAsString(Locale.US)); }
/** * Overrides parent method and returns true if this Concept.getDatatype() equals "Complex".. * * @see org.openmrs.Concept#isComplex() */ @Override public boolean isComplex() { if (getDatatype() == null || getDatatype().getHl7Abbreviation() == null) { return false; } return "ED".equals(getDatatype().getHl7Abbreviation()); }
ret.append(valueWidget.generateHtml(context)); if (showUnits) { if (concept == null || !concept.getDatatype().isNumeric()) { throw new IllegalArgumentException("Can only show units when the concept is numeric");