/**
   * Determines if a discrepancy note is closed or not. The note is closed if it has status closed,
   * or any of its children have closed status.
   *
   * @param note The discrepancy note. The children should already be set.
   * @return <code>true</code> if the note is closed, <code>false</code> otherwise.
   */
  public static boolean noteIsClosed(DiscrepancyNoteBean note) {
    if (note.getResolutionStatusId() == ResolutionStatus.CLOSED.getId()) {
      return true;
    }

    ArrayList children = note.getChildren();
    for (int i = 0; i < children.size(); i++) {
      DiscrepancyNoteBean child = (DiscrepancyNoteBean) children.get(i);
      if (child.getResolutionStatusId() == ResolutionStatus.CLOSED.getId()) {
        return true;
      }
    }

    return false;
  }
  private void createDiscrepancyNoteBean(
      String description,
      String detailedNotes,
      int itemDataId,
      StudyBean studyBean,
      UserAccountBean ub,
      DiscrepancyNoteBean parentDiscrepancyNote) {
    DiscrepancyNoteBean dnb = new DiscrepancyNoteBean();
    dnb.setEntityId(itemDataId); // this is needed for DN Map object
    dnb.setStudyId(studyBean.getId());
    dnb.setEntityType(DiscrepancyNoteBean.ITEM_DATA);
    dnb.setDescription(description);
    dnb.setDetailedNotes(detailedNotes);
    dnb.setDiscrepancyNoteTypeId(
        parentDiscrepancyNote.getDiscrepancyNoteTypeId()); // set to parent DN Type Id
    dnb.setResolutionStatusId(4); // set to closed
    dnb.setColumn("value"); // this is needed for DN Map object
    dnb.setAssignedUserId(ub.getId());
    dnb.setOwner(ub);
    dnb.setParentDnId(parentDiscrepancyNote.getId());
    dnb.setActivated(false);
    dnb = (DiscrepancyNoteBean) getDnDao().create(dnb); // create child DN
    getDnDao().createMapping(dnb); // create DN mapping

    DiscrepancyNoteBean itemParentNote =
        (DiscrepancyNoteBean) getDnDao().findByPK(dnb.getParentDnId());
    itemParentNote.setResolutionStatusId(ResolutionStatus.CLOSED.getId());
    itemParentNote.setAssignedUserId(ub.getId());
    getDnDao().update(itemParentNote); // update parent DN
    getDnDao().updateAssignedUser(itemParentNote); // update parent DN assigned user
  }
 public static boolean parentNoteIsClosed(DiscrepancyNoteBean parentNote) {
   if (parentNote.getResolutionStatusId() == ResolutionStatus.CLOSED.getId()) {
     return true;
   }
   return false;
 }