Ejemplo n.º 1
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;
  }
Ejemplo n.º 2
0
  @Transactional(rollbackFor = Exception.class)
  public void closePregnancyObservation(Individual mother) {
    List<PregnancyObservation> obs =
        genericDao.findListByProperty(PregnancyObservation.class, "mother", mother);

    for (PregnancyObservation ob : obs) {
      if (ob.getStatus().equals(siteProperties.getDataStatusPendingCode())) {
        // found the corresponding pregnancy observation
        // now close it
        ob.setStatus(siteProperties.getDataStatusClosedCode());
        genericDao.update(ob);
        break;
      }
    }
  }
Ejemplo n.º 3
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;
  }
  @RequestMapping("/pregnancy-observ-reconciliation.report")
  public ModelAndView getPregnancyObservReconciliation() {
    ModelAndView mv = new ModelAndView("pregnancyObservReconciliation");
    Collection<PregObservReconciliationBean> beans = new ArrayList<PregObservReconciliationBean>();

    PregObservReconciliationBean bean = new PregObservReconciliationBean();
    bean.setCurrentDate(calendarUtil.formatDate(Calendar.getInstance()));

    // grab all Pregnancy Observations
    List<PregnancyObservation> list =
        genericDao.findListByProperty(
            PregnancyObservation.class, "status", properties.getDataStatusPendingCode());
    Collections.sort(list, new PregnancyObservationComparator());

    for (PregnancyObservation item : list) {

      if (item.getExpectedDeliveryDate().before(Calendar.getInstance())) {
        bean.setDate(calendarUtil.formatDate(item.getRecordedDate()));
        bean.setIndivId(item.getMother().getExtId());
        beans.add(bean);
      }
    }

    if (list.size() == 0) {
      bean.setDate("");
      bean.setIndivId("");
      beans.add(bean);
    }

    mv.addObject("theData", beans);
    return mv;
  }
Ejemplo n.º 5
0
 public boolean checkDuplicatePregnancyObservation(Individual mother) {
   List<PregnancyObservation> list =
       genericDao.findListByProperty(PregnancyObservation.class, "mother", mother);
   for (PregnancyObservation item : list) {
     if (item.getStatus().equals(siteProperties.getDataStatusPendingCode())) return false;
   }
   return true;
 }
Ejemplo n.º 6
0
 public void validateGeneralPregnancyObservation(PregnancyObservation entityItem)
     throws ConstraintViolations {
   List<PregnancyObservation> list =
       genericDao.findListByMultiProperty(
           PregnancyObservation.class,
           getValueProperty("mother", entityItem.getMother()),
           getValueProperty("status", siteProperties.getDataStatusPendingCode()));
   if (list.size() > 1)
     throw new ConstraintViolations(
         "The Mother specified already has a pending Pregnancy Observation.");
 }
Ejemplo n.º 7
0
  public PregnancyObservation evaluatePregnancyObservation(PregnancyObservation entityItem)
      throws ConstraintViolations {

    int age =
        (int)
            (CalendarUtil.daysBetween(
                    entityItem.getMother().getDob(), entityItem.getExpectedDeliveryDate())
                / 365.25);
    if (age < siteProperties.getMinimumAgeOfPregnancy())
      throw new ConstraintViolations(
          "The Mother specified is younger than the minimum age required to have a Pregnancy Observation.");
    if (!checkDuplicatePregnancyObservation(entityItem.getMother()))
      throw new ConstraintViolations(
          "The Mother specified already has a pending Pregnancy Observation.");
    if (individualService.getLatestEvent(entityItem.getMother()).equals("Death"))
      throw new ConstraintViolations(
          "A Pregnancy Observation cannot be created for a Mother who has a Death event.");

    return entityItem;
  }
Ejemplo n.º 8
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;
  }
Ejemplo n.º 9
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");
      }
    }
  }
Ejemplo n.º 10
0
  @RequestMapping(
      method = RequestMethod.POST,
      produces = "application/xml",
      consumes = "application/xml")
  @Transactional
  public ResponseEntity<? extends Serializable> processForm(
      @RequestBody InMigrationForm inMigrationForm) throws JAXBException {

    try {
      context = JAXBContext.newInstance(InMigrationForm.class);
      marshaller = context.createMarshaller();
      marshaller.setAdapter(adapter);
    } catch (JAXBException e) {
      throw new RuntimeException(
          "Could not create JAXB context and marshaller for InMigrationFormResource");
    }

    InMigration inMigration = new InMigration();

    inMigration.setRecordedDate(inMigrationForm.getMigrationDate());
    inMigration.setReason(inMigrationForm.getMigrationReason());
    inMigration.setOrigin(inMigrationForm.getMigrationOrigin());

    // TODO: determine a consistent configuration plan between siteProperties and MigrationType enum
    // TODO: (question) why use an enum and not the siteproperties?
    if ("internal_inmigration".equals(inMigrationForm.getMigrationType())) {
      inMigration.setMigType(MigrationType.INTERNAL_INMIGRATION);
    } else {
      inMigration.setMigType(MigrationType.EXTERNAL_INMIGRATION);
    }

    FieldWorker fieldWorker = fieldWorkerService.getByUuid(inMigrationForm.getFieldWorkerUuid());
    if (null == fieldWorker) {
      ConstraintViolations cv = new ConstraintViolations();
      cv.addViolations(
          ConstraintViolations.INVALID_FIELD_WORKER_UUID
              + " : "
              + inMigrationForm.getFieldWorkerUuid());
      logError(
          cv,
          fieldWorker,
          createDTOPayload(inMigrationForm),
          InMigrationForm.class.getSimpleName(),
          ConstraintViolations.INVALID_FIELD_WORKER_UUID);
      return requestError(cv);
    }
    inMigration.setCollectedBy(fieldWorker);

    Visit visit = visitService.findVisitByUuid(inMigrationForm.getVisitUuid());
    if (null == visit) {
      ConstraintViolations cv = new ConstraintViolations();
      cv.addViolations(
          ConstraintViolations.INVALID_VISIT_UUID + " : " + inMigrationForm.getVisitUuid());
      logError(
          cv,
          fieldWorker,
          createDTOPayload(inMigrationForm),
          InMigrationForm.class.getSimpleName(),
          ConstraintViolations.INVALID_VISIT_UUID);
      return requestError(cv);
    }
    inMigration.setVisit(visit);

    Individual individual = individualService.getByUuid(inMigrationForm.getIndividualUuid());
    if (null == individual) {
      ConstraintViolations cv = new ConstraintViolations();
      cv.addViolations(
          ConstraintViolations.INVALID_INDIVIDUAL_UUID
              + " : "
              + inMigrationForm.getIndividualUuid());
      logError(
          cv,
          fieldWorker,
          createDTOPayload(inMigrationForm),
          InMigrationForm.class.getSimpleName(),
          ConstraintViolations.INVALID_INDIVIDUAL_UUID);
      return requestError(cv);
    }
    inMigration.setIndividual(individual);

    Location location = locationService.getByUuid(inMigrationForm.getLocationUuid());
    if (null == location) {
      ConstraintViolations cv = new ConstraintViolations();
      cv.addViolations(
          ConstraintViolations.INVALID_LOCATION_UUID + " : " + inMigrationForm.getLocationUuid());
      logError(
          cv,
          fieldWorker,
          createDTOPayload(inMigrationForm),
          InMigrationForm.class.getSimpleName(),
          ConstraintViolations.INVALID_LOCATION_UUID);
      return requestError(cv);
    }

    Residency newResidency = new Residency();

    // TODO: since the InMigration domain model contains a reference to a Residency instead of a
    // Location,
    // we must assemble the Residency at this level to provide a fully-graphed InMigration to the
    // service
    newResidency.setCollectedBy(fieldWorker);

    newResidency.setLocation(location);
    newResidency.setIndividual(individual);
    newResidency.setUuid(UUID.randomUUID().toString().replace("-", ""));
    newResidency.setStartDate(inMigration.getRecordedDate());
    newResidency.setStartType(sitePropertiesService.getInmigrationCode());
    newResidency.setEndType(sitePropertiesService.getNotApplicableCode());

    if (null != currentUser) {
      newResidency.setInsertBy(currentUser.getCurrentUser());
    }

    Calendar insertDate = calendarUtil.convertDateToCalendar(new Date());
    newResidency.setInsertDate(insertDate);

    newResidency.setStatus(sitePropertiesService.getDataStatusPendingCode());

    inMigration.setResidency(newResidency);

    try {
      inMigrationService.create(inMigration);
    } catch (ConstraintViolations cv) {
      logError(
          cv,
          fieldWorker,
          createDTOPayload(inMigrationForm),
          InMigrationForm.class.getSimpleName(),
          ConstraintViolations.INVALID_IN_MIGRATION);
      return requestError(cv);
    }

    return new ResponseEntity<InMigrationForm>(inMigrationForm, HttpStatus.CREATED);
  }