Package org.openmrs

Examples of org.openmrs.ConceptDatatype


   * @return the created Obs instance
   */
  public static Obs createObs(Concept concept, Object value, Date datetime, String accessionNumber) {
    Obs obs = new Obs();
    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;
        obs.setValueText(location.getId().toString() + " - " + location.getName());
      } else if (value instanceof Person) {
        Person person = (Person) value;
        obs.setValueText(person.getId().toString() + " - " + person.getPersonName().toString());
      } else {
        obs.setValueText(value.toString());
      }
    } else if (dt.isCoded()) {
            if (value instanceof Drug) {
                obs.setValueDrug((Drug) value);
                obs.setValueCoded(((Drug) value).getConcept());
            } else if (value instanceof ConceptName) {
                obs.setValueCodedName((ConceptName) value);
                obs.setValueCoded(obs.getValueCodedName().getConcept());
            } else if (value instanceof Concept) {
        obs.setValueCoded((Concept) value);
            } else {
        obs.setValueCoded((Concept) convertToType(value.toString(), Concept.class));
            }
    } else if (dt.isBoolean()) {
      if (value != null) {
        try {
          obs.setValueAsString(value.toString());
        }
        catch (ParseException e) {
          throw new IllegalArgumentException("Unable to convert " + value + " to a Boolean Obs value", e);
        }
      }
    } 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())) {
      // don't set a value
    } else {
      throw new IllegalArgumentException("concept datatype not yet implemented: " + dt.getName()
              + " with Hl7 Abbreviation: " + dt.getHl7Abbreviation());
    }
    if (datetime != null)
      obs.setObsDatetime(datetime);
    if (accessionNumber != null)
      obs.setAccessionNumber(accessionNumber);
View Full Code Here


        when(context.getTranslator()).thenReturn(translator);
    }

    @Test
    public void testShowUnitsUsingTrue() {
        ConceptDatatype numeric = new ConceptDatatype();
        numeric.setUuid(ConceptDatatype.NUMERIC_UUID);

        ConceptNumeric weight = new ConceptNumeric();
        String units = "kg";
        weight.setUnits(units);
        weight.setDatatype(numeric);
View Full Code Here

    }

    @Test
  @Ignore
    public void testShowUnitsUsingCode() {
        ConceptDatatype numeric = new ConceptDatatype();
        numeric.setUuid(ConceptDatatype.NUMERIC_UUID);

        ConceptNumeric weight = new ConceptNumeric();
        weight.setUnits("kg");
        weight.setDatatype(numeric);
View Full Code Here

    /**
     * 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());
        }
    }
View Full Code Here

  @Verifies(value="shouldSetTheValueComplexOfObsIfConceptIsComplex",method="createObs(Concept concept, Object value, Date datetime, String accessionNumber)")
  public void createObs_shouldSetTheValueComplexOfObsIfConceptIsComplex(){
   
    ComplexData complexData=new ComplexData("test", null);
    Concept c=new Concept();
    ConceptDatatype cd=new ConceptDatatype();
    cd.setUuid(HtmlFormEntryConstants.COMPLEX_UUID);
    c.setDatatype(cd);
    Obs o=HtmlFormEntryUtil.createObs(c, complexData, null, null);
      Assert.assertEquals(o.getValueComplex(),complexData.getTitle());
   
  }
View Full Code Here

TOP

Related Classes of org.openmrs.ConceptDatatype

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.