Exemplo n.º 1
0
  /**
   * This is an equivalent to a copy constructor. Creates a new copy of the given <code>obsToCopy
   * </code> with a null obs id
   *
   * @param obsToCopy The Obs that is going to be copied
   * @return a new Obs object with all the same attributes as the given obs
   */
  public static Obs newInstance(Obs obsToCopy) {
    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.setOrder(obsToCopy.getOrder());
    newObs.setEncounter(obsToCopy.getEncounter());
    newObs.setDateStarted(obsToCopy.getDateStarted());
    newObs.setDateStopped(obsToCopy.getDateStopped());
    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.setValueComplex(obsToCopy.getValueComplex());
    newObs.setComplexData(obsToCopy.getComplexData());

    if (obsToCopy.getGroupMembers() != null)
      for (Obs member : obsToCopy.getGroupMembers()) {
        // if the obs hasn't been saved yet, no need to duplicate it
        if (member.getObsId() == null) newObs.addGroupMember(member);
        else newObs.addGroupMember(Obs.newInstance(member));
      }

    return newObs;
  }
Exemplo n.º 2
0
 /**
  * Creates an OpenMRS Obs instance
  *
  * @param concept concept associated with the Obs
  * @param value value associated with the Obs
  * @param datetime date/time associated with the Obs (may be null)
  * @param accessionNumber accession number associatd with the Obs (may be null)
  * @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 (dt.isText()) {
     if (value instanceof Location) {
       obs.setValueText(((Location) value).getLocationId().toString());
     } else {
       obs.setValueText(value.toString());
     }
   } else if (dt.isCoded()) {
     if (value instanceof Concept) obs.setValueCoded((Concept) value);
     else obs.setValueCoded((Concept) convertToType(value.toString(), Concept.class));
   } else if (dt.isBoolean()) {
     boolean booleanValue =
         value != null && !Boolean.FALSE.equals(value) && !"false".equals(value);
     obs.setValueNumeric(booleanValue ? 1.0 : 0.0);
   } else if (dt.isDate()) {
     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);
   return obs;
 }