Package org.openmrs

Examples of org.openmrs.ConceptNumeric


    } else if (obs.getConcept().getDatatype().isComplex()) {
      obs.setValueComplex(value.toString());
    } else {
      if (obs.getConcept().isNumeric()) {
        //get the actual persistent object rather than the hibernate proxy
        ConceptNumeric concept = Context.getConceptService().getConceptNumeric(obs.getConcept().getId());
        String units = concept.getUnits();
        if (StringUtils.isNotBlank(units)) {
          String originalValue = value.toString().trim();
          if (originalValue.endsWith(units))
            value = originalValue.substring(0, originalValue.indexOf(units)).trim();
          else {
View Full Code Here


          catch (Exception ex) {
            throw new RuntimeException("Error in answer list for concept " + concept.getConceptId() + " ("
                    + ex.toString() + "): " + conceptAnswers);
          }
        }
        ConceptNumeric cn;
                if (concept instanceof ConceptNumeric) {
                    cn = (ConceptNumeric) concept;
                } else {
                    cn = Context.getConceptService().getConceptNumeric(concept.getConceptId());
                }
        // added to avoid creating this widget when a checkbox is needed
                if (numericAnswers.size() == 0) {
                    if (!"checkbox".equals(parameters.get("style"))) {
                        valueWidget = new NumberFieldWidget(cn, parameters.get("size"));
                    } else {
                        // render CheckboxWidgets for <obs> tag with numeric datatype;
                        // i.e. <obs conceptId="1234" answer="8" answerLabel="Eight" style="checkbox"/>
                        if (parameters.get("answer") != null) {
                            try {
                                Number number = Double.valueOf(parameters.get("answer"));
                                numericAnswers.add(number);
                                answerLabel = parameters.get("answerLabel");
                                if (number != null) {
                                    valueWidget = new CheckboxWidget(answerLabel, number.toString());
                                }

                            } catch (Exception ex) {
                                throw new RuntimeException("Error in answer for concept " + concept.getConceptId() + " ("
                                        + ex.toString() + "): ");
                            }
                        }
                    }
                } else {
          if ("radio".equals(parameters.get("style"))) {
            valueWidget = new RadioButtonsWidget();
            if (answerSeparator != null) {
              ((RadioButtonsWidget) valueWidget).setAnswerSeparator(answerSeparator);
                        }
          } else { // dropdown
                        valueWidget = buildDropdownWidget(size);
          }
          // need to make sure we have the initialValue too
          Number lookFor = existingObs == null ? null : existingObs.getValueNumeric();
          for (int i = 0; i < numericAnswers.size(); ++i) {
            Number n = numericAnswers.get(i);
            if (lookFor != null && lookFor.equals(n))
              lookFor = null;
            String label = null;
            if (answerLabels != null && i < answerLabels.size()) {
              label = answerLabels.get(i);
            } else {
              label = n.toString();
            }
            ((SingleOptionWidget) valueWidget).addOption(new Option(label, n.toString(), false));
          }
          // if lookFor is still non-null, we need to add it directly as
          // an option:
          if (lookFor != null)
            ((SingleOptionWidget) valueWidget)
                    .addOption(new Option(lookFor.toString(), lookFor.toString(), true));
        }

        if (valueWidget != null) {
          boolean isPrecise = cn != null ? cn.isPrecise() : true; // test data is missing concept numerics
          Number initialValue = null;

          if (existingObs != null && existingObs.getValueNumeric() != null) {
            // for non-precise numeric obs, initial value should be rendered as an integer
            initialValue = isPrecise ? ((Number) existingObs.getValueNumeric()) : existingObs.getValueNumeric().intValue();
View Full Code Here

      }
      String units;
      if (concept instanceof ConceptNumeric) {
        units = ((ConceptNumeric) concept).getUnits();
      } else {
        ConceptNumeric asConceptNumeric = Context.getConceptService().getConceptNumeric(concept.getConceptId());
        if (asConceptNumeric == null) {
          throw new IllegalStateException("Concept " + concept + " (" + concept.getName().getName() + ") has datatype = Numeric, but no row in concept_numeric");
        }
        units = asConceptNumeric.getUnits();
      }
      ret.append("<span class=\"" + unitsCssClass + "\">");
            if (unitsCode != null) {
                ret.append(context.getTranslator().translate(Context.getLocale().toString(), unitsCode));
            } else if (units != null) {
View Full Code Here

    @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);

        mockStatic(HtmlFormEntryUtil.class);
        PowerMockito.when(HtmlFormEntryUtil.getConcept(anyString())).thenReturn(weight);

        params.put("showUnits", "true");
View Full Code Here

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

        ConceptNumeric weight = new ConceptNumeric();
        weight.setUnits("kg");
        weight.setDatatype(numeric);

        mockStatic(HtmlFormEntryUtil.class);
        PowerMockito.when(HtmlFormEntryUtil.getConcept(anyString())).thenReturn(weight);

        String unitsCode = "units.kg";
View Full Code Here

TOP

Related Classes of org.openmrs.ConceptNumeric

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.