/*
   * (non-Javadoc)
   * @see org.openhds.service.IndividualMergeService#mergeIndividuals(org.openhds.model.Individual, org.openhds.model.Individual)
   */
  @Transactional(rollbackFor = {ConstraintViolations.class, SQLException.class})
  public int mergeIndividuals(Individual primary, Individual toMergeFrom, List<MergeEvents> events)
      throws ConstraintViolations, SQLException {
    // this is a naive implementation and will most likely be extended/specialized in the future
    // currently, only in migrations and memberships can be merged/copied from 2 individuals
    int eventsMerged = 0;

    // grab the in migrations first
    if (events.contains(MergeEvents.IN_MIGRATION)) {
      List<InMigration> inMigs = getInMigrationEvents(primary, toMergeFrom);
      eventsMerged += inMigs.size();

      for (InMigration inMig : inMigs) {
        inMigrationService.evaluateInMigration(inMig);
        entityService.create(inMig);
      }
    }

    if (events.contains(MergeEvents.MEMBERSHIP)) {
      // now the memberships
      List<Membership> memberships = getMembershipEvents(primary, toMergeFrom);
      eventsMerged += memberships.size();

      for (Membership mem : memberships) {
        membershipService.evaluateMembership(mem);
        entityService.create(mem);
      }
    }

    return eventsMerged;
  }
示例#2
0
  @Override
  @Transactional(rollbackFor = Exception.class)
  public void createPregnancyObservation(PregnancyObservation pregObs) throws ConstraintViolations {
    evaluatePregnancyObservation(pregObs);

    try {
      entityService.create(pregObs);
    } catch (IllegalArgumentException e) {
    } catch (SQLException e) {
      throw new ConstraintViolations(
          "There was a problem saving the pregnancy observation to the database");
    }
  }
示例#3
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");
      }
    }
  }