Пример #1
0
  @Before
  public void setUp() {

    jsfServiceMock = (JsfServiceMock) jsfService;
    currentUser.setProxyUser("admin", "test", new String[] {"VIEW_ENTITY", "CREATE_ENTITY"});

    mother = genericDao.findByProperty(Individual.class, "extId", "NBAS1I", false);
    fieldWorker = genericDao.findByProperty(FieldWorker.class, "extId", "FWEK1D");
    visit = genericDao.findByProperty(Visit.class, "extId", "VLOCMBI11J");
  }
Пример #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;
      }
    }
  }
Пример #3
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;
  }
  @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;
  }
Пример #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;
 }
Пример #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.");
 }
  /**
   * Lookup and copy all memberships from one individual to another individual
   *
   * @param primary the individual who will receive the copied events
   * @param toMergeFrom the individual to lookup events on
   * @return a copy of any membership events from the toMergeFrom individual
   */
  private List<Membership> getMembershipEvents(Individual primary, Individual toMergeFrom) {
    List<Membership> events = new ArrayList<Membership>();

    List<Membership> memberships =
        genericDao.findListByProperty(Membership.class, "individual", toMergeFrom);

    for (Membership mem : memberships) {
      Membership membership = copyMembership(primary, mem);
      events.add(membership);
    }

    return events;
  }
 /**
  * Parses through SQL INSERT query, looking for certain keyword, extracts FOREIGN KEY references
  * according to the values found and returns them in a Map for further processing.
  *
  * <p>Will look for these keywords: - OPENHDS_VISIT_ID - OPENHDS_INDIVIDUAL_ID -
  * OPENHDS_HOUSEHOLD_ID - OPENHDS_LOCATION_ID If one of these is found, gets the appropriate extId
  * from the extraform object and puts the value into a map for further processing.
  *
  * @param extraForm Object that contains the extra-form submission information that should be
  *     inserted into the extra-form table
  * @param query SQL INSERT statement with placeholders for FK data and VALUES
  * @return A Map<String, String> containing the UUID of the references found
  * @throws ConstraintViolations If an object could not be found with the given extId
  */
 private Map<String, String> getForeignKeyData(ExtraForm extraForm, String query)
     throws ConstraintViolations {
   Map<String, String> foreignKeyData = new HashMap<String, String>();
   if (query.contains("OPENHDS_VISIT_ID")) {
     Visit visit = genericDao.findByProperty(Visit.class, "extId", extraForm.getVisitId());
     if (visit == null)
       throw new ConstraintViolations("Could not find visit with extId " + extraForm.getVisitId());
     foreignKeyData.put("VISIT_UUID", "'" + visit.getUuid() + "'");
   }
   if (query.contains("OPENHDS_INDIVIDUAL_ID")
       || query.contains("INDIVIDUAL_INFO_INDIVIDUAL_ID")) {
     Individual individual =
         genericDao.findByProperty(Individual.class, "extId", extraForm.getIndividualId());
     if (individual == null)
       throw new ConstraintViolations(
           "Could not find individual with extId " + extraForm.getIndividualId());
     foreignKeyData.put("INDIVIDUAL_UUID", "'" + individual.getUuid() + "'");
   }
   if (query.contains("OPENHDS_HOUSEHOLD_ID")) {
     SocialGroup socialGroup =
         genericDao.findByProperty(SocialGroup.class, "extId", extraForm.getSocialGroupId());
     if (socialGroup == null)
       throw new ConstraintViolations(
           "Could not find socialGroup with extId " + extraForm.getSocialGroupId());
     foreignKeyData.put("HOUSEHOLD_UUID", "'" + socialGroup.getUuid() + "'");
   }
   if (query.contains("OPENHDS_LOCATION_ID")) {
     Location location =
         genericDao.findByProperty(Location.class, "extId", extraForm.getLocationId());
     if (location == null)
       throw new ConstraintViolations(
           "Could not find location with extId " + extraForm.getLocationId());
     foreignKeyData.put("LOCATION_UUID", "'" + location.getUuid() + "'");
   }
   return foreignKeyData;
 }
  /**
   * Lookup and copy all in migration events from one individual to another
   *
   * @param primary the individual who will receive the copied events
   * @param toMergeFrom the individual to lookup events on
   * @return a copy of any in migrations from the toMergeFrom individual
   */
  private List<InMigration> getInMigrationEvents(Individual primary, Individual toMergeFrom) {

    List<InMigration> events = new ArrayList<InMigration>();

    // first attempt to merge any in migration events
    List<InMigration> inMigrations =
        genericDao.findListByProperty(InMigration.class, "individual", toMergeFrom);

    for (InMigration inMig : inMigrations) {
      // make a copy of the in migration & residency
      InMigration inMigNew = copyInMigration(primary, inMig);
      Residency residencyNew = copyResidency(primary, inMig.getResidency());
      inMigNew.setResidency(residencyNew);
      events.add(inMigNew);
    }

    return events;
  }
Пример #10
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;
  }
Пример #11
0
 public PregnancyOutcome getPregnancyOutcomeByUuid(String uuid) {
   return genericDao.findByProperty(PregnancyOutcome.class, "uuid", uuid);
 }
Пример #12
0
 public List<PregnancyObservation> getPregnancyObservationByIndividual(Individual individual) {
   return genericDao.findListByProperty(PregnancyObservation.class, "mother", individual, true);
 }
Пример #13
0
 public List<PregnancyOutcome> getPregnancyOutcomesByIndividual(Individual individual) {
   return genericDao.findListByProperty(PregnancyOutcome.class, "mother", individual, true);
 }
 /**
  * Checks if the supplied key exists in the OpenHDS form table.
  *
  * @param key UUID of an extra-form
  * @return boolean true if the specified UUID exists in the openHDS form table
  * @throws ConstraintViolations if there is no Form with this UUID
  * @see ConstraintViolations
  * @see GenericDao
  */
 @Override
 public boolean isValidKey(String key) throws ConstraintViolations {
   Form form = genericDao.findByProperty(Form.class, "uuid", key);
   if (form == null) throw new ConstraintViolations("Form key not valid.");
   else return true;
 }