public ArrayList findAllItemDataByStudy(StudyBean study) {
    this.setTypesExpected();
    ArrayList alist = new ArrayList();
    this.setTypeExpected(11, TypeNames.STRING); // ss.label
    this.setTypeExpected(12, TypeNames.DATE); // date_start
    this.setTypeExpected(13, TypeNames.STRING); // sed_name
    this.setTypeExpected(14, TypeNames.STRING); // crf_name
    this.setTypeExpected(15, TypeNames.STRING); // item_name
    this.setTypeExpected(16, TypeNames.STRING); // value
    this.setTypeExpected(17, TypeNames.INT); // item_data_id
    this.setTypeExpected(18, TypeNames.INT); // item_id

    HashMap variables = new HashMap();
    variables.put(new Integer(1), new Integer(study.getId()));
    variables.put(new Integer(2), new Integer(study.getId()));
    alist = this.select(digester.getQuery("findAllItemDataByStudy"), variables);

    ArrayList al = new ArrayList();
    Iterator it = alist.iterator();
    while (it.hasNext()) {
      HashMap hm = (HashMap) it.next();
      DiscrepancyNoteBean eb = (DiscrepancyNoteBean) this.getEntityFromHashMap(hm);
      eb.setEventName((String) hm.get("sed_name"));
      eb.setEventStart((Date) hm.get("date_start"));
      eb.setCrfName((String) hm.get("crf_name"));
      eb.setSubjectName((String) hm.get("label"));
      eb.setEntityName((String) hm.get("item_name"));
      eb.setEntityValue((String) hm.get("value"));
      // YW << change EntityId from item_id to item_data_id.
      eb.setEntityId(((Integer) hm.get("item_data_id")).intValue());
      eb.setItemId(((Integer) hm.get("item_id")).intValue());
      // YW >>
      al.add(eb);
    }
    return al;
  }
  public ArrayList findAllEntityByPK(String entityName, int noteId) {
    this.setTypesExpected();
    ArrayList alist = new ArrayList();
    this.setTypeExpected(11, TypeNames.STRING); // ss.label

    HashMap variables = new HashMap();
    variables.put(new Integer(1), new Integer(noteId));
    variables.put(new Integer(2), new Integer(noteId));
    if ("subject".equalsIgnoreCase(entityName)) {
      this.setTypeExpected(12, TypeNames.STRING); // column_name
      alist = this.select(digester.getQuery("findAllSubjectByPK"), variables);
    } else if ("studySub".equalsIgnoreCase(entityName)) {
      this.setTypeExpected(12, TypeNames.STRING); // column_name
      alist = this.select(digester.getQuery("findAllStudySubjectByPK"), variables);
    } else if ("eventCrf".equalsIgnoreCase(entityName)) {
      this.setTypeExpected(12, TypeNames.DATE); // date_start
      this.setTypeExpected(13, TypeNames.STRING); // sed_name
      this.setTypeExpected(14, TypeNames.STRING); // crf_name
      this.setTypeExpected(15, TypeNames.STRING); // column_name
      alist = this.select(digester.getQuery("findAllEventCRFByPK"), variables);
    } else if ("studyEvent".equalsIgnoreCase(entityName)) {
      this.setTypeExpected(12, TypeNames.DATE); // date_start
      this.setTypeExpected(13, TypeNames.STRING); // sed_name
      this.setTypeExpected(14, TypeNames.STRING); // column_name
      alist = this.select(digester.getQuery("findAllStudyEventByPK"), variables);
    } else if ("itemData".equalsIgnoreCase(entityName)) {
      this.setTypeExpected(12, TypeNames.DATE); // date_start
      this.setTypeExpected(13, TypeNames.STRING); // sed_name
      this.setTypeExpected(14, TypeNames.STRING); // crf_name
      this.setTypeExpected(15, TypeNames.STRING); // item_name
      this.setTypeExpected(16, TypeNames.STRING); // value
      // YW <<
      this.setTypeExpected(17, TypeNames.INT); // item_data_id
      this.setTypeExpected(18, TypeNames.INT); // item_id
      // YW >>
      alist = this.select(digester.getQuery("findAllItemDataByPK"), variables);
    }

    ArrayList al = new ArrayList();
    Iterator it = alist.iterator();
    while (it.hasNext()) {
      HashMap hm = (HashMap) it.next();
      DiscrepancyNoteBean eb = (DiscrepancyNoteBean) this.getEntityFromHashMap(hm);
      if ("subject".equalsIgnoreCase(entityName) || "studySub".equalsIgnoreCase(entityName)) {
        eb.setSubjectName((String) hm.get("label"));
        eb.setColumn((String) hm.get("column_name"));
      } else if ("eventCrf".equalsIgnoreCase(entityName)) {
        eb.setSubjectName((String) hm.get("label"));
        eb.setEventName((String) hm.get("sed_name"));
        eb.setEventStart((Date) hm.get("date_start"));
        eb.setCrfName((String) hm.get("crf_name"));
        eb.setColumn((String) hm.get("column_name"));
      } else if ("itemData".equalsIgnoreCase(entityName)) {
        eb.setSubjectName((String) hm.get("label"));
        eb.setEventName((String) hm.get("sed_name"));
        eb.setEventStart((Date) hm.get("date_start"));
        eb.setCrfName((String) hm.get("crf_name"));
        eb.setEntityName((String) hm.get("item_name"));
        eb.setEntityValue((String) hm.get("value"));
        // YW <<
        eb.setEntityId(((Integer) hm.get("item_data_id")).intValue());
        eb.setItemId(((Integer) hm.get("item_id")).intValue());
        // YW >>

      } else if ("studyEvent".equalsIgnoreCase(entityName)) {
        eb.setSubjectName((String) hm.get("label"));
        eb.setEventName((String) hm.get("sed_name"));
        eb.setEventStart((Date) hm.get("date_start"));
        eb.setColumn((String) hm.get("column_name"));
      }
      if (fetchMapping) {
        eb = findSingleMapping(eb);
      }
      al.add(eb);
    }
    return al;
  }
  /*
   * (non-Javadoc)
   *
   * @see org.akaza.openclinica.control.core.SecureController#processRequest()
   */
  @Override
  protected void processRequest() throws Exception {

    FormProcessor fp = new FormProcessor(request);
    int noteId = fp.getInt(INPUT_NOTE_ID);
    String module = (String) session.getAttribute("module");
    // Integer subjectId = (Integer) session.getAttribute("subjectId");

    StudySubjectDAO studySubjectDAO = new StudySubjectDAO(sm.getDataSource());

    DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
    dndao.setFetchMapping(true);

    // check that the note exists
    DiscrepancyNoteBean discrepancyNoteBean = (DiscrepancyNoteBean) dndao.findByPK(noteId);

    if (!discrepancyNoteBean.isActive()) {
      throw new InconsistentStateException(
          Page.MANAGE_STUDY_SERVLET,
          resexception.getString("you_are_trying_resolve_discrepancy_not_exist"));
    }

    // check that the note has not already been closed
    ArrayList children = dndao.findAllByParent(discrepancyNoteBean);
    discrepancyNoteBean.setChildren(children);
    // This logic has been reverted, issue-7459
    //        if (parentNoteIsClosed(discrepancyNoteBean)) {
    //            throw new InconsistentStateException(Page.VIEW_DISCREPANCY_NOTES_IN_STUDY_SERVLET,
    // respage
    //                    .getString("the_discrepancy_choose_has_been_closed_resolved_create_new"));
    //        }

    // all clear, send the user to the resolved screen
    String entityType = discrepancyNoteBean.getEntityType().toLowerCase();
    discrepancyNoteBean.setResStatus(
        ResolutionStatus.get(discrepancyNoteBean.getResolutionStatusId()));
    discrepancyNoteBean.setDisType(
        DiscrepancyNoteType.get(discrepancyNoteBean.getDiscrepancyNoteTypeId()));
    // BWP 03/17/2009 3166: if it's not an ItemData type note, redirect
    // Monitors to View Subject or
    // View Study Events <<
    if (currentRole.getRole().equals(Role.MONITOR)
        && !"itemdata".equalsIgnoreCase(entityType)
        && !"eventcrf".equalsIgnoreCase(entityType)) {
      redirectMonitor(module, discrepancyNoteBean);
      return;
    }
    // >>
    // If Study is Frozen or Locked
    if (currentStudy.getStatus().isFrozen()
        && !"itemdata".equalsIgnoreCase(entityType)
        && !"eventcrf".equalsIgnoreCase(entityType)) {
      redirectMonitor(module, discrepancyNoteBean);
      return;
    }

    boolean toView = false;
    boolean isCompleted = false;
    if ("itemdata".equalsIgnoreCase(entityType)) {
      ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
      ItemDataBean idb = (ItemDataBean) iddao.findByPK(discrepancyNoteBean.getEntityId());

      EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());

      EventCRFBean ecb = (EventCRFBean) ecdao.findByPK(idb.getEventCRFId());
      StudySubjectBean studySubjectBean =
          (StudySubjectBean) studySubjectDAO.findByPK(ecb.getStudySubjectId());

      discrepancyNoteBean.setSubjectId(studySubjectBean.getId());
      discrepancyNoteBean.setItemId(idb.getItemId());

      if (ecb.getStatus().equals(Status.UNAVAILABLE)) {
        isCompleted = true;
      }

      toView = true; // we want to go to view note page if the note is
      // for item data
    }
    // logger.info("set up pop up url: " + createNoteURL);
    // System.out.println("set up pop up url: " + createNoteURL);
    boolean goNext =
        prepareRequestForResolution(
            request, sm.getDataSource(), currentStudy, discrepancyNoteBean, isCompleted);

    Page p = getPageForForwarding(discrepancyNoteBean, isCompleted);

    // logger.info("found page for forwarding: " + p.getFileName());
    if (p == null) {
      throw new InconsistentStateException(
          Page.VIEW_DISCREPANCY_NOTES_IN_STUDY_SERVLET,
          resexception.getString("the_discrepancy_note_triying_resolve_has_invalid_type"));
    } else {
      if (p.getFileName().contains("?")) {
        if (!p.getFileName().contains("fromViewNotes=1")) {
          p.setFileName(p.getFileName() + "&fromViewNotes=1");
        }
      } else {
        p.setFileName(p.getFileName() + "?fromViewNotes=1");
      }
      String createNoteURL =
          CreateDiscrepancyNoteServlet.getAddChildURL(
              discrepancyNoteBean, ResolutionStatus.CLOSED, true);
      setPopUpURL(createNoteURL);
    }

    if (!goNext) {
      setPopUpURL("");
      addPageMessage(
          respage.getString("you_may_not_perform_admin_edit_on_CRF_not_completed_by_user"));
      p = Page.VIEW_DISCREPANCY_NOTES_IN_STUDY_SERVLET;
    }

    forwardPage(p);
  }