/**
   * Set the DbVitals and DbCase values from the FirstCallInformation form. Creation date:
   * (10/25/2002 11:00:39 AM)
   *
   * @param deceased com.aldorsolutions.webfdms.beans.DbVitalsDeceased
   * @param form fdms.ui.struts.form.FirstCallInformationForm
   * @param errors org.apache.struts.action.ActionErrors
   */
  public void setVitalsDeceased(
      DbVitalsDeceased deceased,
      DbVitalsInformant informant,
      CemAnStatus form,
      ActionErrors errors) {
    try {

      deceased.setDecmrmrs(form.getPrefix());
      deceased.setDecFName(form.getFirstName());
      deceased.setDecMName(form.getMiddleName());
      deceased.setDecLName(form.getLastName());
      deceased.setSuffix(form.getSuffix());
      deceased.setDecFullName(form.getMemorialName());
      deceased.setDecMaiden(form.getMaidenName());
      deceased.setDateOfBirth(FormatDate.convertToDateMMDDYYYY(form.getBirthDate()));
      deceased.setDateOfDeath(FormatDate.convertToDateMMDDYYYY(form.getDeathDate()));
      deceased.setDateOfBurial(FormatDate.convertToDateMMDDYYYY(form.getServiceDate()));

      // if the deceased's residence is the same as the informant's then update the deceased's
      // address
      if (form.getDeceasedSame()) {
        deceased.setDeceasedSame("Y");
        deceased.setDecResStreet(
            form.getInformantStreet()
                + " "
                + form.getInformantStreet2()
                + " "
                + form.getInformantStreet3());
        deceased.setDecResCityTWP(form.getInformantCity());
        deceased.setDecResState(form.getInformantState());
        deceased.setDecResZip(form.getInformantZip());
        deceased.setDecResPhone(form.getInformantPhone());
      } else {
        deceased.setDeceasedSame("N");
      }

    } catch (Exception e) {
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.ui.setData"));
    }

    return;
  }
  private void validateForm(
      DatabaseTransaction t,
      DbUserSession sessionUser,
      fdms.ui.struts.form.CemAnStatus form,
      ActionErrors errors) {

    String checkDate = null;

    // Validate Arrange Date
    if (form.getArrangeDate() != null && form.getArrangeDate().trim().length() > 0) {
      try {
        checkDate = FormatDate.convertToDateMMDDYYYY(form.getArrangeDate());
      } catch (Exception e) {
        errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.ui.arrangedate"));
        formErrors.add("arrangeDate");
      }
    }

    // Chapel is required.
    if (form.getChapel() == null || form.getChapel().trim().length() == 0) {
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.ui.chapel"));
      formErrors.add("chapel");
    }

    // Director is required.
    if (form.getDirector() == null || form.getDirector().trim().length() == 0) {
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.ui.director"));
      formErrors.add("director");
    }

    // Validate PreNeed Date if entered.
    if (form.getPreneedDate() != null && form.getPreneedDate().trim().length() > 0) {
      try {
        checkDate = FormatDate.convertToDateMMDDYYYY(form.getPreneedDate());
      } catch (Exception e) {
        errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.ui.origpndate"));
        formErrors.add("preneedDate");
      }
    }

    // If the user changed the contract number, check for duplicate Contract Numbers.
    if (form.getContractNumber() != null
        && form.getContractNumber().trim().length() > 0
        && (!form.getContractNumber().equals(form.getNextContractNumber()))) {

      DbCase checkCase = new DbCase();
      checkCase.setNew();
      checkCase.setLocale(sessionUser.getRegion());
      if (form.getVitalsId() == null
          || form.getVitalsId().trim().length() == 0
          || form.getVitalsId() == "0") {
        checkCase.setId(0);
      } else {
        checkCase.setId(FormatNumber.parseInteger(form.getVitalsId()));
      }
      checkCase.setContractCode(form.getContractNumber());
      if (FdmsDb.getInstance().checkCaseExists(t, checkCase, DbCasePeer.CONTRACTCODE)) {
        errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.duplicate.contractNumber"));
        formErrors.add("contractNumber");
      }
    }

    // Deceased Memorial Name is required.
    if (form.getMemorialName() == null || form.getMemorialName().trim().length() == 0) {
      if (form.getMiddleName() != null && form.getMiddleName().trim().length() > 0) {
        form.setMemorialName(
            form.getFirstName() + " " + form.getMiddleName() + " " + form.getLastName());
      } else {
        form.setMemorialName(form.getFirstName() + " " + form.getLastName());
      }
      if (form.getMemorialName() == null || form.getMemorialName().trim().length() == 0) {
        errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.memorialName.required"));
        formErrors.add("memorialName");
      }
    }

    // Deceased First Name is required.
    if (form.getFirstName() == null || form.getFirstName().trim().length() == 0) {
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.registration.nullFirstName"));
      formErrors.add("firstName");
    }

    // Deceased Last Name is required.
    if (form.getLastName() == null || form.getLastName().trim().length() == 0) {
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.registration.nullLastName"));
      formErrors.add("lastName");
    }

    // Validate Date of Birth
    if (form.getBirthDate() != null && form.getBirthDate().trim().length() > 0) {
      try {
        checkDate = FormatDate.convertToDateMMDDYYYY(form.getBirthDate());
      } catch (Exception e) {
        errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.ui.birthdate"));
        formErrors.add("birthDate");
      }
    }

    // Validate Date of Death
    if (form.getDeathDate() != null && form.getDeathDate().trim().length() > 0) {
      try {
        checkDate = FormatDate.convertToDateMMDDYYYY(form.getDeathDate());
      } catch (Exception e) {
        errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.ui.deathdate"));
        formErrors.add("deathDate");
      }
    }

    // Validate Service Date
    if (form.getServiceDate() != null && form.getServiceDate().trim().length() > 0) {
      try {
        checkDate = FormatDate.convertToDateMMDDYYYY(form.getServiceDate());
      } catch (Exception e) {
        errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.ui.servicedate"));
        formErrors.add("serviceDate");
      }
    }

    // Validate Disposition Date
    if (form.getDispDate() != null && form.getDispDate().trim().length() > 0) {
      try {
        checkDate = FormatDate.convertToDateMMDDYYYY(form.getDispDate());
      } catch (Exception e) {
        errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.ui.dispdate"));
        formErrors.add("dispDate");
      }
    }

    return;
  }