/**
     * Fails if there isn't an obs group with these exact characteristics
     *
     * @param groupingConceptId the concept id of the grouping obs
     * @param conceptIdsAndValues these parameters must be given in pairs, the first element of
     *     which is the conceptId of a child obs (Integer) and the second element of which is the
     *     value of the child obs
     */
    public void assertObsGroupCreated(int groupingConceptId, Object... conceptIdsAndValues) {
      // quick checks
      Assert.assertNotNull(encounterCreated);
      Collection<Obs> temp = encounterCreated.getAllObs();
      Assert.assertNotNull(temp);

      List<ObsValue> expected = new ArrayList<ObsValue>();
      for (int i = 0; i < conceptIdsAndValues.length; i += 2) {
        int conceptId = (Integer) conceptIdsAndValues[i];
        Object value = conceptIdsAndValues[i + 1];
        expected.add(new ObsValue(conceptId, value));
      }

      for (Obs o : temp) {
        if (o.getConcept().getConceptId() == groupingConceptId) {
          if (o.getValueCoded() != null
              || o.getValueComplex() != null
              || o.getValueDatetime() != null
              || o.getValueDrug() != null
              || o.getValueNumeric() != null
              || o.getValueText() != null) {
            Assert.fail(
                "Obs group with groupingConceptId "
                    + groupingConceptId
                    + " should has a non-null value");
          }
          if (TestUtil.isMatchingObsGroup(o, expected)) {
            return;
          }
        }
      }
      Assert.fail("Cannot find an obs group matching " + expected);
    }
예제 #2
0
  /**
   * Builds a coded result from an observation
   *
   * @param obs
   */
  public Result(Obs obs) {
    this(
        obs.getObsDatetime(),
        null,
        obs.getValueAsBoolean(),
        obs.getValueCoded(),
        obs.getValueDatetime(),
        obs.getValueNumeric(),
        obs.getValueText(),
        obs);

    Concept concept = obs.getConcept();
    ConceptDatatype conceptDatatype = null;

    if (concept != null) {
      conceptDatatype = concept.getDatatype();

      if (conceptDatatype == null) {
        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;
      }
    }
  }
  /**
   * Calculates the postpartum end date as 6 months past the delivery date.
   *
   * <p>NOTE: In the absence of a delivery date, the EDC is used.
   *
   * @return The end date of the postpartum stage
   */
  public Date getPostpartumStageEndDate() {
    Date deliveryDate = null;
    if (Functions.observation(mcProgramObs.getObs(), MCDeliveryReportConcepts.DELIVERY_REPORT)
        != null) {
      final Obs deliveryDateObs =
          mcProgramObs.getDeliveryReport().getMember(MCDeliveryReportConcepts.DELIVERY_DATE);
      if (deliveryDateObs != null) {
        deliveryDate = deliveryDateObs.getValueDatetime();
      }
    }

    if (deliveryDate == null) {
      // use EDC
      deliveryDate = mcProgramObs.getEstimatedDateOfConfinement();
    }

    if (deliveryDate != null) {
      final Calendar sixMonthsAfterDeliveryDate = Calendar.getInstance();
      sixMonthsAfterDeliveryDate.setTime(DateUtil.stripTime(deliveryDate));
      sixMonthsAfterDeliveryDate.add(Calendar.MONTH, 6);

      // return the calculated postpartum stage end date
      return sixMonthsAfterDeliveryDate.getTime();
    }

    // postpartum stage end date is not available
    return null;
  }
  public String getValue() {

    if (obs != null) {
      String resultValue = obs.getValueAsString(Context.getLocale());
      if (resultFilter != null) {
        return (String) resultFilter.filter(resultValue);
      }

      if (obs.getValueDatetime() != null) {
        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
        return sdf.format(obs.getValueDatetime());
      }
      return obs.getValueAsString(Context.getLocale());
    }

    return null;
  }
예제 #5
0
파일: Obs.java 프로젝트: sapna-m/openmrs
  /**
   * 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;
  }
  /**
   * Calculates the risk factors based on the maternal care observation in the form.
   *
   * @return A comma-delimited list of risk factors (from A to E)
   */
  public String getRiskFactors() {
    // store risk factors in a list
    final List<String> riskFactors = new ArrayList<String>();

    if (getPatient() != null && mcProgramObs != null) {
      // check for risk factor 'a' using age at LMP
      final Obs lmpObs =
          mcProgramObs
              .getObstetricHistory()
              .getMember(MCObstetricHistoryConcepts.LAST_MENSTRUAL_PERIOD);
      if (lmpObs != null
          && lmpObs.getValueDatetime() != null
          && getPatient().getBirthdate() != null) {
        final int age =
            DateUtil.yearsBetween(getPatient().getBirthdate(), lmpObs.getValueDatetime());
        if (age < 18 || age > 35) {
          riskFactors.add("A");
        }
      }

      // check for risk factor 'b' using patient's height
      final Obs heightObs = Functions.observation(getPatient(), VisitConcepts.HEIGHT_CM);
      if (heightObs != null && heightObs.getValueNumeric() != null) {
        if (heightObs.getValueNumeric() < 145) {
          riskFactors.add("B");
        }
      }

      // check for risk factor 'c' using patient obstetric history
      final ObstetricHistory obHistory = mcProgramObs.getObstetricHistory();
      final Obs gravidaObs =
          obHistory.getMember(MCObstetricHistoryConcepts.OBSTETRIC_SCORE_GRAVIDA);
      if (gravidaObs != null && gravidaObs.getValueNumeric() != null) {
        if (gravidaObs.getValueNumeric() >= 4) {
          riskFactors.add("C");
        }
      }

      // check for risk factors 'd' using registration data
      final Concept yes = Functions.trueConcept();
      if (yes.equals(
              obHistory.getMember(MCObstetricHistoryConcepts.HISTORY_PREV_CSECTION).getValueCoded())
          || yes.equals(
              obHistory
                  .getMember(MCObstetricHistoryConcepts.HISTORY_3OR_MORE_MISCARRIAGES)
                  .getValueCoded())
          || yes.equals(
              obHistory
                  .getMember(MCObstetricHistoryConcepts.HISTORY_OF_POSTPARTUM_HEMORRHAGE)
                  .getValueCoded())) {
        riskFactors.add("D");
      }

      if (anyRiskFactorsTypeE(mcProgramObs.getPatientMedicalHistory())) {
        // check 'past' medical history
        riskFactors.add("E");
      } else {
        // check medical history observed during this pregnancy
        for (PrenatalVisitRecord visit : mcProgramObs.getPrenatalVisits()) {
          if (anyRiskFactorsTypeE(visit.getNewMedicalConditions())) {
            riskFactors.add("E");
            break;
          }
        }
      }
    }

    if (riskFactors.isEmpty()) {
      return "none";
    } else {
      final String riskFactorsText = riskFactors.toString();
      return riskFactorsText.substring(1, riskFactorsText.length() - 1);
    }
  }