예제 #1
0
  public PregnancyOutcome evaluatePregnancyOutcome(PregnancyOutcome entityItem)
      throws ConstraintViolations {

    int age;

    if (entityItem.getOutcomeDate() == null) {
      age =
          (int)
              (CalendarUtil.daysBetween(
                      entityItem.getMother().getDob(), entityItem.getVisit().getVisitDate())
                  / 365.25);
    } else {
      age =
          (int)
              (CalendarUtil.daysBetween(
                      entityItem.getMother().getDob(), entityItem.getOutcomeDate())
                  / 365.25);
    }
    if (age < siteProperties.getMinimumAgeOfPregnancy())
      throw new ConstraintViolations(
          "The Mother specified is younger than the minimum age required to have a Pregnancy Outcome.");
    if (individualService.getLatestEvent(entityItem.getMother()).equals("Death"))
      throw new ConstraintViolations(
          "A Pregnancy Outcome cannot be created for a Mother who has a Death event.");
    if (entityItem.getOutcomes().size() == 0)
      throw new ConstraintViolations(
          "A Pregnancy Outcome cannot be created unless it has at least 1 outcome.");
    if (entityItem.getMother().getCurrentResidency() == null)
      throw new ConstraintViolations(
          "A Pregnancy Outcome cannot be created because a Residency record cannot be found for the mother.");

    return entityItem;
  }
예제 #2
0
  public int findAllBirthsBetweenIntervalByGender(Calendar startDate, Calendar endDate, int flag) {

    int count = 0;
    List<PregnancyOutcome> outcomes = genericDao.findAll(PregnancyOutcome.class, true);

    for (PregnancyOutcome outcome : outcomes) {
      Calendar outcomeDate = outcome.getOutcomeDate();
      if ((outcomeDate.after(startDate) || outcomeDate.equals(startDate))
          && (outcomeDate.before(endDate))) {

        List<Outcome> allOutcomes = outcome.getOutcomes();
        for (Outcome o : allOutcomes) {
          if (o.getType().equals(siteProperties.getLiveBirthCode())) {
            // male
            if (flag == 0) {
              if (o.getChild().getGender().equals(siteProperties.getMaleCode())) {
                if (o.getType().equals(siteProperties.getLiveBirthCode())) {
                  count++;
                }
              }
            }
            // female
            else {
              if (o.getChild().getGender().equals(siteProperties.getFemaleCode())) {
                if (o.getType().equals(siteProperties.getLiveBirthCode())) {
                  count++;
                }
              }
            }
          }
        }
      }
    }
    return count;
  }
예제 #3
0
  public List<PregnancyOutcome> findAllLiveBirthsBetweenInterval(
      Calendar startDate, Calendar endDate) {

    List<PregnancyOutcome> output = new ArrayList<PregnancyOutcome>();
    List<PregnancyOutcome> outcomes = genericDao.findAll(PregnancyOutcome.class, true);

    for (PregnancyOutcome outcome : outcomes) {
      Calendar outcomeDate = outcome.getOutcomeDate();
      if ((outcomeDate.after(startDate) || outcomeDate.equals(startDate))
          && (outcomeDate.before(endDate))) {

        List<Outcome> allOutcomes = outcome.getOutcomes();
        for (Outcome o : allOutcomes)
          if (o.getType().equals(siteProperties.getLiveBirthCode())) {
            output.add(outcome);
          }
      }
    }
    return output;
  }
예제 #4
0
  @Transactional(rollbackFor = Exception.class)
  public void createPregnancyOutcome(PregnancyOutcome pregOutcome) throws ConstraintViolations {
    Location motherLocation = pregOutcome.getMother().getCurrentResidency().getLocation();

    int totalEverBorn = 0;
    int liveBirths = 0;

    int numberOfOutcomes = pregOutcome.getOutcomes().size();
    for (int i = 0; i < numberOfOutcomes; i++) {

      Outcome outcome = pregOutcome.getOutcomes().get(i);

      totalEverBorn++;
      if (!outcome.getType().equals(siteProperties.getLiveBirthCode())) {
        // not a live birth so individual, residency and membership not needed
        continue;
      }

      liveBirths++;
      // create individual
      try {
        outcome.getChild().setDob(pregOutcome.getOutcomeDate());
        entityService.create(outcome.getChild());
      } catch (IllegalArgumentException e) {
        throw new ConstraintViolations(
            "IllegalArgumentException creating child individual in the database");
      } catch (SQLException e) {
        throw new ConstraintViolations("SQLException creating child individual in the database");
      }

      // use mothers location for the residency
      Residency residency = new Residency();
      residency.setStartDate(pregOutcome.getOutcomeDate());
      residency.setIndividual(outcome.getChild());
      residency.setStartType(siteProperties.getBirthCode());
      residency.setLocation(motherLocation);
      residency.setCollectedBy(pregOutcome.getCollectedBy());
      residency.setEndType(siteProperties.getNotApplicableCode());

      try {
        entityService.create(residency);
      } catch (IllegalArgumentException e) {
        throw new ConstraintViolations(
            "IllegalArgumentException creating residency for child in database");
      } catch (SQLException e) {
        throw new ConstraintViolations("SQLException creating residency for child in database");
      }

      // persist membership
      try {
        entityService.create(outcome.getChildMembership());
      } catch (IllegalArgumentException e) {
        throw new ConstraintViolations(
            "IllegalArgumentException creating membership for child in database");
      } catch (SQLException e) {
        throw new ConstraintViolations("SQLException creating membership for child in database");
      }
    }

    pregOutcome.setChildEverBorn(totalEverBorn);
    pregOutcome.setNumberOfLiveBirths(liveBirths);

    // close any pregnancy observation
    closePregnancyObservation(pregOutcome.getMother());

    PregnancyOutcome persistedPregnancyOutcome = getPregnancyOutcomeByUuid(pregOutcome.getUuid());

    if (null == persistedPregnancyOutcome) {
      try {
        entityService.create(pregOutcome);
      } catch (SQLException e) {
        throw new ConstraintViolations("Problem creating pregnancy outcome to database");
      }
    } else {
      try {
        entityService.save(pregOutcome);
      } catch (IllegalArgumentException e) {
        throw new ConstraintViolations(
            "IllegalArgumentException saving pregnancy outcome in the database");
      } catch (SQLException e) {
        throw new ConstraintViolations("SQLException saving pregnancy outcome in the database");
      }
    }
  }