protected ActionForward performAction(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    String forward = FWD_SUCCESS;
    BaseActionForm dynaForm = (BaseActionForm) form;
    ActionMessages errors = null;

    request.setAttribute(ALLOW_EDITS_KEY, "false");
    request.setAttribute(PREVIOUS_DISABLED, "true");
    request.setAttribute(NEXT_DISABLED, "true");

    String accessionNumber = (String) dynaForm.getString("accessionNumber");
    SampleXmlHelper sampleXmlHelper = new SampleXmlHelper();

    if (!StringUtil.isNullorNill(accessionNumber)) {
      Sample sample = new Sample();
      SampleDAO sampleDAO = new SampleDAOImpl();
      sample.setAccessionNumber(accessionNumber);

      List testTestAnalytes = new ArrayList();
      try {
        sampleDAO.getSampleByAccessionNumber(sample);

        if (!StringUtil.isNullorNill(sample.getStatus())
            && sample
                .getStatus()
                .equals(SystemConfiguration.getInstance().getSampleStatusLabelPrinted())) {
          dynaForm.set("accessionNumber", accessionNumber);
          request.setAttribute(ALLOW_EDITS_KEY, "false");
          return mapping.findForward(FWD_FAIL);
        }

      } catch (LIMSRuntimeException lre) {

        LogEvent.logError(
            "AuditTrailReportBySampleProcessAction", "performAction()", lre.toString());
        errors = new ActionMessages();
        ActionError error = null;
        error = new ActionError("errors.GetException", null, null);
        errors.add(ActionMessages.GLOBAL_MESSAGE, error);
        saveErrors(request, errors);
        request.setAttribute(Globals.ERROR_KEY, errors);
        request.setAttribute(ALLOW_EDITS_KEY, "false");
        return mapping.findForward(FWD_FAIL);
      }

      String domain = sample.getDomain();

      String humanDomain = SystemConfiguration.getInstance().getHumanDomain();

      String animalDomain = SystemConfiguration.getInstance().getAnimalDomain();

      if (domain != null && domain.equals(humanDomain)) {
        // go to human view

        Patient patient = new Patient();
        Person patientPerson = new Person();
        Provider provider = new Provider();
        Person providerPerson = new Person();
        SampleHuman sampleHuman = new SampleHuman();
        SampleOrganization sampleOrganization = new SampleOrganization();
        Organization organization = new Organization();
        List sampleProjects = new ArrayList();
        Project project = new Project();
        Project project2 = new Project();
        SampleItem sampleItem = new SampleItem();

        try {

          PatientDAO patientDAO = new PatientDAOImpl();
          ProviderDAO providerDAO = new ProviderDAOImpl();
          SampleItemDAO sampleItemDAO = new SampleItemDAOImpl();
          SampleHumanDAO sampleHumanDAO = new SampleHumanDAOImpl();
          SampleOrganizationDAO sampleOrganizationDAO = new SampleOrganizationDAOImpl();
          AuditTrailDAO auditTrailDAO = new AuditTrailDAOImpl();
          SystemUserDAO systemUserDAO = new SystemUserDAOImpl();

          if (!StringUtil.isNullorNill(sample.getId())) {
            sampleHuman.setSampleId(sample.getId());
            sampleHumanDAO.getDataBySample(sampleHuman);
            sampleOrganization.setSampleId(sample.getId());
            sampleOrganizationDAO.getDataBySample(sampleOrganization);
            sampleItem.setSample(sample);
            sampleItemDAO.getDataBySample(sampleItem);

            if (sampleHuman != null) {
              if (sampleHuman.getPatientId() != null) {
                patient.setId(sampleHuman.getPatientId());
                patientDAO.getData(patient);
                patientPerson = patient.getPerson();
                provider.setId(sampleHuman.getProviderId());
                providerDAO.getData(provider);
                providerPerson = provider.getPerson();
              }
            }
          }
          organization = (Organization) sampleOrganization.getOrganization();
          sampleProjects = sample.getSampleProjects();

          if (sampleProjects != null && sampleProjects.size() > 0) {
            SampleProject sampleProject = (SampleProject) sampleProjects.get(0);
            project = sampleProject.getProject();
            if (sampleProjects.size() > 1) {
              SampleProject sampleProject2 = (SampleProject) sampleProjects.get(1);
              project2 = sampleProject2.getProject();
            }
          }

          String tableName = "SAMPLE";
          ReferenceTablesDAO referenceTablesDAO = new ReferenceTablesDAOImpl();
          ReferenceTables referenceTables = new ReferenceTables();
          referenceTables.setTableName(tableName);
          ReferenceTables rt = referenceTablesDAO.getReferenceTableByName(referenceTables);

          PropertyUtils.copyProperties(sampleXmlHelper, sample);

          // String data = auditTrailDAO.retrieveBlobData(sample.getId());
          // String data = auditTrailDAO.retrieveBlobData("9446");
          History history = new History();
          history.setReferenceId(sample.getId());
          history.setReferenceTable(rt.getId());
          List historyRecords = auditTrailDAO.getHistoryByRefIdAndRefTableId(history);

          List sampleHistoryRecords =
              populateHistoryList(request, historyRecords, "sample", "sampleHistoryMapping.xsl");
          sampleXmlHelper.setHistoryRecords((ArrayList) sampleHistoryRecords);

          tableName = "SAMPLE_ITEM";
          referenceTables = new ReferenceTables();
          referenceTables.setTableName(tableName);
          rt = referenceTablesDAO.getReferenceTableByName(referenceTables);
          history = new History();
          history.setReferenceId(sampleItem.getId());
          history.setReferenceTable(rt.getId());
          historyRecords = auditTrailDAO.getHistoryByRefIdAndRefTableId(history);

          List sampleItemHistoryRecords =
              populateHistoryList(
                  request, historyRecords, "sampleItem", "sampleItemHistoryMapping.xsl");
          sampleXmlHelper.addHistoryRecords((ArrayList) sampleItemHistoryRecords);

          tableName = "PATIENT";
          referenceTables = new ReferenceTables();
          referenceTables.setTableName(tableName);
          rt = referenceTablesDAO.getReferenceTableByName(referenceTables);
          history = new History();
          history.setReferenceId(patient.getId());
          history.setReferenceTable(rt.getId());
          historyRecords = auditTrailDAO.getHistoryByRefIdAndRefTableId(history);

          List patientHistoryRecords =
              populateHistoryList(request, historyRecords, "patient", "patientHistoryMapping.xsl");
          sampleXmlHelper.addHistoryRecords((ArrayList) patientHistoryRecords);

          tableName = "PERSON";
          referenceTables = new ReferenceTables();
          referenceTables.setTableName(tableName);
          rt = referenceTablesDAO.getReferenceTableByName(referenceTables);
          history = new History();
          history.setReferenceId(patientPerson.getId());
          history.setReferenceTable(rt.getId());
          historyRecords = auditTrailDAO.getHistoryByRefIdAndRefTableId(history);

          // List patientPersonHistoryRecords = populateHistoryList(request, historyRecords,
          // "person", "personHistoryMapping.xsl");
          // sampleXmlHelper.addHistoryRecords((ArrayList)patientPersonHistoryRecords);

          tableName = "PERSON";
          referenceTables = new ReferenceTables();
          referenceTables.setTableName(tableName);
          rt = referenceTablesDAO.getReferenceTableByName(referenceTables);
          history = new History();
          history.setReferenceId(providerPerson.getId());
          history.setReferenceTable(rt.getId());
          historyRecords = auditTrailDAO.getHistoryByRefIdAndRefTableId(history);

          // List providerPersonHistoryRecords = populateHistoryList(request, historyRecords,
          // "person", "personHistoryMapping.xsl");
          // sampleXmlHelper.addHistoryRecords((ArrayList)providerPersonHistoryRecords);

          tableName = "SAMPLE_PROJECTS";
          referenceTables = new ReferenceTables();
          referenceTables.setTableName(tableName);
          rt = referenceTablesDAO.getReferenceTableByName(referenceTables);
          history = new History();
          history.setReferenceId(providerPerson.getId());
          history.setReferenceTable(rt.getId());
          historyRecords = auditTrailDAO.getHistoryByRefIdAndRefTableId(history);

          List sampleProjectHistoryRecords =
              populateHistoryList(
                  request, historyRecords, "sampleProject", "sampleProjectHistoryMapping.xsl");
          sampleXmlHelper.addHistoryRecords((ArrayList) sampleProjectHistoryRecords);

          // initialize the form
          dynaForm.initialize(mapping);

          tableName = "SAMPLE_ORGANIZATION";
          referenceTables = new ReferenceTables();
          referenceTables.setTableName(tableName);
          rt = referenceTablesDAO.getReferenceTableByName(referenceTables);
          history = new History();
          history.setReferenceId(sampleOrganization.getId());
          history.setReferenceTable(rt.getId());
          historyRecords = auditTrailDAO.getHistoryByRefIdAndRefTableId(history);

          List sampleOrganizationHistoryRecords =
              populateHistoryList(
                  request,
                  historyRecords,
                  "sampleOrganization",
                  "sampleOrganizationHistoryMapping.xsl");
          sampleXmlHelper.addHistoryRecords((ArrayList) sampleOrganizationHistoryRecords);

          List historyRecordsForSorting = sampleXmlHelper.getHistoryRecords();

          Collections.sort(historyRecordsForSorting, HistoryComparator.NAME_COMPARATOR);

          String savedUserName = "";
          List dateSortList = new ArrayList();
          List finalList = new ArrayList();
          // now within name sort by date desc
          for (int i = 0; i < historyRecordsForSorting.size(); i++) {
            // break down into chunks by name
            HistoryXmlHelper hist = (HistoryXmlHelper) historyRecordsForSorting.get(i);

            if (i > 0 && !hist.getUserName().equals(savedUserName)) {
              // now sort chunk so far
              Collections.sort(dateSortList, HistoryComparator.DATE_COMPARATOR);
              finalList.addAll(dateSortList);
              dateSortList.clear();
            }
            dateSortList.add(hist);
            savedUserName = hist.getUserName();
          }

          if (dateSortList != null && dateSortList.size() > 0) {
            Collections.sort(dateSortList, HistoryComparator.DATE_COMPARATOR);
            finalList.addAll(dateSortList);
            dateSortList.clear();
          }

          sampleXmlHelper.setHistoryRecords((ArrayList) finalList);

          // initialize the form
          dynaForm.initialize(mapping);

        } catch (LIMSRuntimeException lre) {
          // if error then forward to fail and don't update to blank
          // page
          // = false
          // bugzilla 2154
          LogEvent.logError("ResultsEntryViewAction", "performAction()", lre.toString());
          errors = new ActionMessages();
          ActionError error = null;
          error = new ActionError("errors.GetException", null, null);
          errors.add(ActionMessages.GLOBAL_MESSAGE, error);
          saveErrors(request, errors);
          request.setAttribute(Globals.ERROR_KEY, errors);
          request.setAttribute(ALLOW_EDITS_KEY, "false");
          return mapping.findForward(FWD_FAIL);
        }

        // populate form from valueholder
        // PropertyUtils.setProperty(dynaForm, "sampleLastupdated", sample
        // .getLastupdated());
        PropertyUtils.setProperty(dynaForm, "patientFirstName", patientPerson.getFirstName());
        PropertyUtils.setProperty(dynaForm, "patientLastName", patientPerson.getLastName());
        PropertyUtils.setProperty(dynaForm, "patientId", patient.getExternalId());

        PropertyUtils.setProperty(dynaForm, "gender", patient.getGender());

        PropertyUtils.setProperty(dynaForm, "chartNumber", patient.getChartNumber());

        PropertyUtils.setProperty(
            dynaForm, "birthDateForDisplay", (String) patient.getBirthDateForDisplay());
        TypeOfSample typeOfSample = sampleItem.getTypeOfSample();
        SourceOfSample sourceOfSample = sampleItem.getSourceOfSample();
        if (typeOfSample == null) {
          PropertyUtils.setProperty(dynaForm, "typeOfSample", new TypeOfSample());
        } else {
          PropertyUtils.setProperty(dynaForm, "typeOfSample", typeOfSample);
        }
        if (sourceOfSample == null) {
          PropertyUtils.setProperty(dynaForm, "sourceOfSample", new SourceOfSample());
        } else {
          PropertyUtils.setProperty(dynaForm, "sourceOfSample", sourceOfSample);
        }

        PropertyUtils.setProperty(dynaForm, "sourceOther", sampleItem.getSourceOther());
        PropertyUtils.setProperty(
            dynaForm, "receivedDateForDisplay", (String) sample.getReceivedDateForDisplay());
        PropertyUtils.setProperty(
            dynaForm, "collectionDateForDisplay", (String) sample.getCollectionDateForDisplay());

        PropertyUtils.setProperty(
            dynaForm, "collectionTimeForDisplay", (String) sample.getCollectionTimeForDisplay());

        PropertyUtils.setProperty(
            dynaForm, "referredCultureFlag", (String) sample.getReferredCultureFlag());

        PropertyUtils.setProperty(
            dynaForm, "stickerReceivedFlag", (String) sample.getStickerReceivedFlag());

        if (organization == null) {
          PropertyUtils.setProperty(dynaForm, "organization", new Organization());
        } else {
          PropertyUtils.setProperty(dynaForm, "organization", organization);
        }

        if (project == null) {
          PropertyUtils.setProperty(dynaForm, "project", new Project());
        } else {
          PropertyUtils.setProperty(dynaForm, "project", project);
        }

        if (project2 == null) {
          PropertyUtils.setProperty(dynaForm, "project2", new Project());
        } else {
          PropertyUtils.setProperty(dynaForm, "project2", project2);
        }

        // reload accession number
        PropertyUtils.setProperty(dynaForm, "accessionNumber", accessionNumber);
        PropertyUtils.setProperty(dynaForm, "domain", domain);

        PropertyUtils.setProperty(dynaForm, "sampleXmlHelper", sampleXmlHelper);

        forward = FWD_SUCCESS_HUMAN;
      } else if (domain != null && domain.equals(animalDomain)) {
        // go to animal view
        // System.out.println("Going to animal view");
        forward = FWD_SUCCESS_ANIMAL;
      } else {
        forward = FWD_SUCCESS;
      }
    }

    return mapping.findForward(forward);
  }
  private HashMap populateHumanSampleOneMap(
      Patient patient,
      Person person,
      Provider provider,
      Person providerPerson,
      Sample sample,
      SampleHuman sampleHuman,
      SampleOrganization sampleOrganization,
      SampleItem sampleItem,
      List analyses) {
    HashMap humanSampleOneMap = new HashMap();

    List sampleProjects = new ArrayList();
    SampleProject sampleProject = null;
    SampleProject sampleProject2 = null;

    sampleProjects = sample.getSampleProjects();

    if (sampleProjects != null && sampleProjects.size() > 0) {
      sampleProject = (SampleProject) sampleProjects.get(0);
      if (sampleProjects.size() > 1) {
        sampleProject2 = (SampleProject) sampleProjects.get(1);
      }
    }

    if (sample.getAccessionNumber() != null) {
      humanSampleOneMap.put("accessionNumber", sample.getAccessionNumber());
    } else {
      humanSampleOneMap.put("accessionNumber", "");
    }

    if (patient.getBirthDateForDisplay() != null) {
      humanSampleOneMap.put("birthDateForDisplay", patient.getBirthDateForDisplay());
    } else {
      humanSampleOneMap.put("birthDateForDisplay", "");
    }

    if (sample.getCollectionDateForDisplay() != null) {
      humanSampleOneMap.put("collectionDateForDisplay", sample.getCollectionDateForDisplay());
    } else {
      humanSampleOneMap.put("collectionDateForDisplay", "");
    }

    if (sample.getCollectionTimeForDisplay() != null) {
      humanSampleOneMap.put("collectionTimeForDisplay", sample.getCollectionTimeForDisplay());
    } else {
      // bugzilla 1894
      humanSampleOneMap.put(
          "collectionTimeForDisplay",
          SystemConfiguration.getInstance().getHumanSampleOneDefaultCollectionTimeForDisplay());
    }

    // bugzilla 1904
    if (patient.getChartNumber() != null) {
      humanSampleOneMap.put("chartNumber", patient.getChartNumber());
    } else {
      humanSampleOneMap.put("chartNumber", "");
    }

    if (person.getCity() != null) {
      // bugzilla 1766
      humanSampleOneMap.put("city", person.getCity().toUpperCase().trim());
    } else {
      humanSampleOneMap.put("city", "");
    }

    if (sample.getClientReference() != null) {
      humanSampleOneMap.put("clientReference", sample.getClientReference());
    } else {
      humanSampleOneMap.put("clientReference", "");
    }

    if (patient.getExternalId() != null) {
      humanSampleOneMap.put("externalId", patient.getExternalId());
    } else {
      humanSampleOneMap.put("externalId", "");
    }

    if (person.getFirstName() != null) {
      humanSampleOneMap.put("firstName", person.getFirstName());
    } else {
      humanSampleOneMap.put("firstName", "");
    }

    if (patient.getGender() != null) {
      humanSampleOneMap.put("gender", patient.getGender());
    } else {
      humanSampleOneMap.put("gender", "");
    }

    if (person.getLastName() != null) {
      humanSampleOneMap.put("lastName", person.getLastName());
    } else {
      humanSampleOneMap.put("lastName", "");
    }

    if (person.getMiddleName() != null) {
      humanSampleOneMap.put("middleName", person.getMiddleName());
    } else {
      humanSampleOneMap.put("middleName", "");
    }

    if (person.getMultipleUnit() != null) {
      humanSampleOneMap.put("multipleUnit", person.getMultipleUnit());
    } else {
      humanSampleOneMap.put("multipleUnit", "");
    }

    if (sampleOrganization != null && sampleOrganization.getOrganization() != null) {
      // bugzilla 2069
      humanSampleOneMap.put(
          "organizationLocalAbbreviation",
          sampleOrganization.getOrganization().getOrganizationLocalAbbreviation());
      humanSampleOneMap.put(
          "organizationNameForDisplay", sampleOrganization.getOrganization().getOrganizationName());
    } else {
      humanSampleOneMap.put("organizationLocalAbbreviation", "");
      humanSampleOneMap.put("organizationNameForDisplay", "");
    }
    if (sampleProject != null && sampleProject.getProject() != null) {
      // bugzilla 2438
      humanSampleOneMap.put("projectId", sampleProject.getProject().getLocalAbbreviation());
      // bugzilla 1766 since we capitolize project name do this here
      // for comparison purposes
      humanSampleOneMap.put(
          "projectName", sampleProject.getProject().getProjectName().toUpperCase().trim());
    } else {
      humanSampleOneMap.put("projectId", "");
      humanSampleOneMap.put("projectName", "");
    }

    if (sampleProject2 != null && sampleProject2.getProject() != null) {
      // bugzilla 2438
      humanSampleOneMap.put("projectId2", sampleProject2.getProject().getLocalAbbreviation());
      // bugzilla 1766 since we capitolize project name do this here
      // for comparison purposes
      humanSampleOneMap.put(
          "projectName2", sampleProject2.getProject().getProjectName().toUpperCase().trim());
    } else {
      humanSampleOneMap.put("projectId2", "");
      humanSampleOneMap.put("projectName2", "");
    }

    if (providerPerson.getFirstName() != null) {
      humanSampleOneMap.put("providerFirstName", providerPerson.getFirstName());
    } else {
      humanSampleOneMap.put("providerFirstName", "");
    }

    if (providerPerson.getLastName() != null) {
      humanSampleOneMap.put("providerLastName", providerPerson.getLastName());
    } else {
      humanSampleOneMap.put("providerLastName", "");
    }

    if (providerPerson.getWorkPhone() != null) {
      String storedResult = providerPerson.getWorkPhone();
      humanSampleOneMap.put("providerWorkPhone", StringUtil.formatPhoneForDisplay(storedResult));
    } else {
      humanSampleOneMap.put("providerWorkPhone", "");
    }

    if (providerPerson.getWorkPhone() != null) {
      String storedResult = providerPerson.getWorkPhone();
      // bugzilla 2442
      String extension = StringUtil.formatExtensionForDisplay(storedResult);
      humanSampleOneMap.put("providerWorkPhoneExtension", StringUtil.trim(extension));
    } else {
      humanSampleOneMap.put("providerWorkPhoneExtension", "");
    }

    if (sample.getReceivedDateForDisplay() != null) {
      humanSampleOneMap.put("receivedDateForDisplay", sample.getReceivedDateForDisplay());
    } else {
      humanSampleOneMap.put("receivedDateForDisplay", "");
    }

    if (sample.getReferredCultureFlag() != null) {
      humanSampleOneMap.put("referredCultureFlag", sample.getReferredCultureFlag());
    } else {
      humanSampleOneMap.put("referredCultureFlag", "");
    }

    if (sampleItem.getSourceOfSample() != null) {
      SourceOfSample sos = (SourceOfSample) sampleItem.getSourceOfSample();
      // bugzilla 1766
      humanSampleOneMap.put("sourceOfSampleDesc", sos.getDescription().toUpperCase().trim());
      // bugzilla 1465
      humanSampleOneMap.put("sourceOfSampleId", sos.getId());
    } else {
      humanSampleOneMap.put("sourceOfSampleDesc", "");
      // bugzilla 1465
      humanSampleOneMap.put("sourceOfSampleId", "");
    }

    if (sampleItem.getSourceOther() != null) {
      humanSampleOneMap.put("sourceOther", sampleItem.getSourceOther().trim());
    } else {
      humanSampleOneMap.put("sourceOther", "");
    }

    if (person.getState() != null) {
      humanSampleOneMap.put("state", person.getState());
    } else {
      humanSampleOneMap.put("state", "");
    }

    if (sample.getStickerReceivedFlag() != null) {
      humanSampleOneMap.put("stickerReceivedFlag", sample.getStickerReceivedFlag());
    } else {
      humanSampleOneMap.put("stickerReceivedFlag", "");
    }

    if (person.getStreetAddress() != null) {
      humanSampleOneMap.put("streetAddress", person.getStreetAddress().trim());
    } else {
      humanSampleOneMap.put("streetAddress", "");
    }

    if (sampleItem.getTypeOfSample() != null) {
      TypeOfSample tos = (TypeOfSample) sampleItem.getTypeOfSample();
      // bugzilla 1766
      humanSampleOneMap.put("typeOfSampleDesc", tos.getDescription().toUpperCase().trim());
      // bugzilla 1465
      humanSampleOneMap.put("typeOfSampleId", tos.getId());
    } else {
      humanSampleOneMap.put("typeOfSampleDesc", "");
      // bugzilla 1465
      humanSampleOneMap.put("typeOfSampleId", "");
    }

    if (person.getZipCode() != null) {
      humanSampleOneMap.put("zipCode", person.getZipCode().trim());
    } else {
      humanSampleOneMap.put("zipCode", "");
    }

    return humanSampleOneMap;
  }