private Obs findOrCreateObs(Obs diagnosisObs, Concept concept) {
   for (Obs o : diagnosisObs.getGroupMembers()) {
     if (concept.equals(o.getConcept())) {
       return o;
     }
   }
   Obs obs = new Obs();
   obs.setConcept(concept);
   return obs;
 }
Esempio n. 2
0
  /** @see java.lang.Object#equals(java.lang.Object) */
  @Override
  public boolean equals(Object obj) {
    if (obj == null || !(obj instanceof Result)) {
      return false;
    }
    Result r = (Result) obj;

    if (EmptyResult.class.isAssignableFrom(r.getClass()) && this.isEmpty()) {
      return true;
    }

    if (EmptyResult.class.isAssignableFrom(this.getClass()) && r.isEmpty()) {
      return true;
    }

    if (isSingleResult() && r.isSingleResult()) {

      if (datatype == null) {
        return false;
      }
      // both are single results
      switch (datatype) {
        case BOOLEAN:
          return (valueBoolean.equals(r.valueBoolean));
        case CODED:
          return (valueCoded.equals(r.valueCoded));
        case DATETIME:
          return (valueDatetime.equals(r.valueDatetime));
        case NUMERIC:
          return (valueNumeric.equals(r.valueNumeric));
        case TEXT:
          return (valueText.equals(r.valueText));
        default:
          return false;
      }
    }
    if (isSingleResult() || r.isSingleResult()) {
      // we already know they're not both single results, so if one is
      // single, it's not a match
      return false;
    }
    if (this.size() != r.size()) {
      return false;
    }
    // at this point, we have two results that are lists, so members must
    // match exactly
    for (int i = 0; i < this.size(); i++) {
      if (!this.get(i).equals(r.get(i))) {
        return false;
      }
    }
    return true;
  }
  /**
   * Checks if any of the 'E' risk factors are present in the group obs.
   *
   * @param grp
   * @return
   */
  private boolean anyRiskFactorsTypeE(GroupObs grp) {
    final Concept yes = Functions.trueConcept();

    // check if any of the 'E' risk factors are present
    for (CachedConceptId rfEConceptId :
        new CachedConceptId[] {
          MCMedicalHistoryConcepts.TUBERCULOSIS, //
          MCMedicalHistoryConcepts.HEART_DISEASE, //
          MCMedicalHistoryConcepts.DIABETES, //
          MCMedicalHistoryConcepts.ASTHMA, //
          MCMedicalHistoryConcepts.THYROID
        }) {
      final Obs conditionObs = grp.getMember(rfEConceptId);
      if (conditionObs != null && yes.equals(conditionObs.getValueCoded())) {
        // risk factor 'E' is present
        return true;
      }
    }

    // risk factor 'E' not found in this group observation
    return false;
  }
  /**
   * 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);
    }
  }