private DiscrepancyNote createQuery(QueryServiceHelperBean helperBean, QueryBean queryBean)
      throws Exception {
    DiscrepancyNote dn = new DiscrepancyNote();
    dn.setStudy(helperBean.getContainer().getStudy());
    dn.setEntityType("itemData");
    dn.setDescription("description");

    dn.setDetailedNotes(queryBean.getComment());
    dn.setDiscrepancyNoteType(new DiscrepancyNoteType(3));

    if (queryBean.getStatus().equals("new")) {
      dn.setResolutionStatus(resolutionStatusDao.findById(1));
    } else if (queryBean.getStatus().equals("updated")) {
      dn.setResolutionStatus(resolutionStatusDao.findById(2));
    } else if (queryBean.getStatus().equals("closed")) {
      dn.setResolutionStatus(resolutionStatusDao.findById(4));
    }

    String assignedTo = queryBean.getAssigned_to();
    if (!StringUtils.isEmpty(assignedTo)) {
      int endIndex = assignedTo.indexOf(")");
      int begIndex = assignedTo.indexOf("(");
      String userName = assignedTo.substring(begIndex + 1, endIndex);
      UserAccount userAccount = userAccountDao.findByUserName(userName);
      helperBean.setUserAccount(userAccount);
      dn.setUserAccount(userAccount);
    }
    dn.setUserAccountByOwnerId(helperBean.getContainer().getUser());
    // create itemData when a query is created without an autosaved itemdata
    if (helperBean.getItemData() == null) {
      helperBean.setItemData(createBlankItemData(helperBean));
    }
    dn.setDateCreated(new Date());
    return dn;
  }
  private void updateParentQuery(QueryServiceHelperBean helperBean) {
    if (helperBean.getDn().getParentDiscrepancyNote() == null) return;

    DiscrepancyNote itemParentNote =
        discrepancyNoteDao.findByDiscrepancyNoteId(
            helperBean.getDn().getParentDiscrepancyNote().getDiscrepancyNoteId());
    itemParentNote.setResolutionStatus(helperBean.getResStatus());
    discrepancyNoteDao.saveOrUpdate(itemParentNote);
  }