Search in sources :

Example 51 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class ViewDiscrepancyNoteServlet method processRequest.

@Override
@SuppressWarnings("unchecked")
protected void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    int eventCRFId = fp.getInt(CreateDiscrepancyNoteServlet.EVENT_CRF_ID);
    request.setAttribute(CreateDiscrepancyNoteServlet.EVENT_CRF_ID, new Integer(eventCRFId));
    request.setAttribute(DIS_TYPES, DiscrepancyNoteType.list);
    if (currentRole.getRole().equals(Role.RESEARCHASSISTANT) || currentRole.getRole().equals(Role.RESEARCHASSISTANT2) || currentRole.getRole().equals(Role.INVESTIGATOR)) {
        ArrayList<ResolutionStatus> resStatuses = new ArrayList();
        resStatuses.add(ResolutionStatus.UPDATED);
        resStatuses.add(ResolutionStatus.RESOLVED);
        request.setAttribute(RES_STATUSES, resStatuses);
        // it's for parentDNId is null or 0
        request.setAttribute(WHICH_RES_STATUSES, "22");
        ArrayList<ResolutionStatus> resStatuses2 = new ArrayList<ResolutionStatus>();
        resStatuses2.add(ResolutionStatus.OPEN);
        resStatuses2.add(ResolutionStatus.RESOLVED);
        request.setAttribute(RES_STATUSES2, resStatuses2);
        List<DiscrepancyNoteType> types2 = new ArrayList<DiscrepancyNoteType>(DiscrepancyNoteType.list);
        types2.remove(DiscrepancyNoteType.QUERY);
        request.setAttribute(DIS_TYPES2, types2);
    } else if (currentRole.getRole().equals(Role.MONITOR)) {
        ArrayList<ResolutionStatus> resStatuses = new ArrayList();
        resStatuses.add(ResolutionStatus.OPEN);
        resStatuses.add(ResolutionStatus.UPDATED);
        resStatuses.add(ResolutionStatus.CLOSED);
        request.setAttribute(RES_STATUSES, resStatuses);
        request.setAttribute(WHICH_RES_STATUSES, "1");
        ArrayList<DiscrepancyNoteType> types2 = new ArrayList<DiscrepancyNoteType>();
        types2.add(DiscrepancyNoteType.QUERY);
        request.setAttribute(DIS_TYPES2, types2);
    } else {
        // Role.STUDYDIRECTOR Role.COORDINATOR
        List<ResolutionStatus> resStatuses = new ArrayList<ResolutionStatus>(ResolutionStatus.list);
        resStatuses.remove(ResolutionStatus.NOT_APPLICABLE);
        request.setAttribute(RES_STATUSES, resStatuses);
        ;
        // it's for parentDNId is null or 0 and FVC
        request.setAttribute(WHICH_RES_STATUSES, "2");
        ArrayList<ResolutionStatus> resStatuses2 = new ArrayList<ResolutionStatus>();
        resStatuses2.add(ResolutionStatus.OPEN);
        resStatuses2.add(ResolutionStatus.RESOLVED);
        request.setAttribute(RES_STATUSES2, resStatuses2);
    }
    // logic from CreateDiscrepancyNoteServlet
    request.setAttribute("unlock", "0");
    fp.getBoolean(IS_REASON_FOR_CHANGE);
    fp.getBoolean(ERROR_FLAG);
    String monitor = fp.getString("monitor");
    // } else if ("1".equalsIgnoreCase(monitor)) {// change to allow user to
    if ("1".equalsIgnoreCase(monitor)) {
        // change to allow user to
        // enter note for all items,
        // not just blank items
        request.setAttribute(CAN_MONITOR, "1");
        request.setAttribute("monitor", monitor);
    } else {
        request.setAttribute(CAN_MONITOR, "0");
    }
    Boolean fromBox = fp.getBoolean(FROM_BOX);
    if (fromBox == null || !fromBox) {
        session.removeAttribute(BOX_TO_SHOW);
        session.removeAttribute(BOX_DN_MAP);
        session.removeAttribute(AUTOVIEWS);
    }
    Boolean refresh = fp.getBoolean("refresh");
    request.setAttribute("refresh", refresh + "");
    String ypos = fp.getString("y");
    if (ypos == null || ypos.length() == 0) {
        ypos = "0";
    }
    request.setAttribute("y", ypos);
    DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
    int entityId = fp.getInt(ENTITY_ID, true);
    String name = fp.getString(ENTITY_TYPE, true);
    String column = fp.getString(ENTITY_COLUMN, true);
    String field = fp.getString(ENTITY_FIELD, true);
    String isLocked = fp.getString(LOCKED_FLAG);
    if (!StringUtil.isBlank(isLocked) && "yes".equalsIgnoreCase(isLocked)) {
        request.setAttribute(LOCKED_FLAG, "yes");
    } else {
        request.setAttribute(LOCKED_FLAG, "no");
    }
    DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
    int subjectId = fp.getInt(CreateDiscrepancyNoteServlet.SUBJECT_ID, true);
    int itemId = fp.getInt(CreateDiscrepancyNoteServlet.ITEM_ID, true);
    StudySubjectBean ssub = new StudySubjectBean();
    if (subjectId > 0) {
        StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
        ssub = (StudySubjectBean) ssdao.findByPK(subjectId);
        request.setAttribute("noteSubject", ssub);
    }
    ItemBean item = new ItemBean();
    if (itemId > 0) {
        ItemDAO idao = new ItemDAO(sm.getDataSource());
        item = (ItemBean) idao.findByPK(itemId);
        request.setAttribute("item", item);
        request.setAttribute("entityName", item.getName());
    }
    ItemDataBean itemData = new ItemDataBean();
    SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
    int preUserId = 0;
    if (!StringUtil.isBlank(name)) {
        if ("itemData".equalsIgnoreCase(name)) {
            ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
            itemData = (ItemDataBean) iddao.findByPK(entityId);
            request.setAttribute("entityValue", itemData.getValue());
            request.setAttribute("entityName", item.getName());
            EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
            EventCRFBean ec = (EventCRFBean) ecdao.findByPK(itemData.getEventCRFId());
            preUserId = ec.getOwnerId() > 0 ? ec.getOwnerId() : 0;
            request.setAttribute("entityCreatedDate", sdf.format(ec.getCreatedDate()));
            StudyEventDAO sed = new StudyEventDAO(sm.getDataSource());
            StudyEventBean se = (StudyEventBean) sed.findByPK(ec.getStudyEventId());
            StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
            StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
            se.setName(sedb.getName());
            request.setAttribute("studyEvent", se);
            CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
            CRFVersionBean cv = (CRFVersionBean) cvdao.findByPK(ec.getCRFVersionId());
            CRFDAO cdao = new CRFDAO(sm.getDataSource());
            CRFBean crf = (CRFBean) cdao.findByPK(cv.getCrfId());
            request.setAttribute("crf", crf);
        } else if ("studySub".equalsIgnoreCase(name)) {
            StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
            ssub = (StudySubjectBean) ssdao.findByPK(entityId);
            SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
            SubjectBean sub = (SubjectBean) sdao.findByPK(ssub.getSubjectId());
            request.setAttribute("noteSubject", ssub);
            if (!StringUtil.isBlank(column)) {
                if ("enrollment_date".equalsIgnoreCase(column)) {
                    if (ssub.getEnrollmentDate() != null) {
                        request.setAttribute("entityValue", dateFormatter.format(ssub.getEnrollmentDate()));
                    }
                    request.setAttribute("entityName", resword.getString("enrollment_date"));
                } else if ("gender".equalsIgnoreCase(column)) {
                    request.setAttribute("entityValue", sub.getGender() + "");
                    request.setAttribute("entityName", resword.getString("gender"));
                } else if ("date_of_birth".equalsIgnoreCase(column)) {
                    if (sub.getDateOfBirth() != null) {
                        request.setAttribute("entityValue", dateFormatter.format(sub.getDateOfBirth()));
                    }
                    request.setAttribute("entityName", resword.getString("date_of_birth"));
                } else if ("unique_identifier".equalsIgnoreCase(column)) {
                    if (sub.getUniqueIdentifier() != null) {
                        request.setAttribute("entityValue", sub.getUniqueIdentifier());
                    }
                    request.setAttribute("entityName", resword.getString("unique_identifier"));
                }
            }
            preUserId = ssub.getOwnerId() > 0 ? ssub.getOwnerId() : 0;
            request.setAttribute("entityCreatedDate", sdf.format(ssub.getCreatedDate()));
        } else if ("subject".equalsIgnoreCase(name)) {
            SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
            SubjectBean sub = (SubjectBean) sdao.findByPK(entityId);
            // be caution: here for subject, noteSubject is SubjectBean and
            // label is unique_identifier
            sub.setLabel(sub.getUniqueIdentifier());
            request.setAttribute("noteSubject", sub);
            if (!StringUtil.isBlank(column)) {
                if ("gender".equalsIgnoreCase(column)) {
                    request.setAttribute("entityValue", ssub.getGender() + "");
                    request.setAttribute("entityName", resword.getString("gender"));
                } else if ("date_of_birth".equalsIgnoreCase(column)) {
                    if (sub.getDateOfBirth() != null) {
                        request.setAttribute("entityValue", dateFormatter.format(sub.getDateOfBirth()));
                    }
                    request.setAttribute("entityName", resword.getString("date_of_birth"));
                } else if ("unique_identifier".equalsIgnoreCase(column)) {
                    request.setAttribute("entityValue", sub.getUniqueIdentifier());
                    request.setAttribute("entityName", resword.getString("unique_identifier"));
                }
            }
            preUserId = sub.getOwnerId() > 0 ? sub.getOwnerId() : 0;
            request.setAttribute("entityCreatedDate", sdf.format(sub.getCreatedDate()));
        } else if ("studyEvent".equalsIgnoreCase(name)) {
            StudyEventDAO sed = new StudyEventDAO(sm.getDataSource());
            StudyEventBean se = (StudyEventBean) sed.findByPK(entityId);
            StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
            StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
            se.setName(sedb.getName());
            request.setAttribute("studyEvent", se);
            request.setAttribute("noteSubject", new StudySubjectDAO(sm.getDataSource()).findByPK(se.getStudySubjectId()));
            if (!StringUtil.isBlank(column)) {
                if ("location".equalsIgnoreCase(column)) {
                    request.setAttribute("entityValue", se.getLocation());
                    request.setAttribute("entityName", resword.getString("location"));
                } else if ("start_date".equalsIgnoreCase(column)) {
                    if (se.getDateStarted() != null) {
                        request.setAttribute("entityValue", dateFormatter.format(se.getDateStarted()));
                    }
                    request.setAttribute("entityName", resword.getString("start_date"));
                } else if ("end_date".equalsIgnoreCase(column)) {
                    if (se.getDateEnded() != null) {
                        request.setAttribute("entityValue", dateFormatter.format(se.getDateEnded()));
                    }
                    request.setAttribute("entityName", resword.getString("end_date"));
                }
            }
            preUserId = se.getOwnerId() > 0 ? se.getOwnerId() : 0;
            request.setAttribute("entityCreatedDate", sdf.format(se.getCreatedDate()));
        } else if ("eventCrf".equalsIgnoreCase(name)) {
            EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
            EventCRFBean ec = (EventCRFBean) ecdao.findByPK(entityId);
            if (!StringUtil.isBlank(column)) {
                if ("date_interviewed".equals(column)) {
                    if (ec.getDateInterviewed() != null) {
                        request.setAttribute("entityValue", dateFormatter.format(ec.getDateInterviewed()));
                    }
                    request.setAttribute("entityName", resword.getString("date_interviewed"));
                } else if ("interviewer_name".equals(column)) {
                    request.setAttribute("entityValue", ec.getInterviewerName());
                    request.setAttribute("entityName", resword.getString("interviewer_name"));
                }
            }
            setupStudyEventCRFAttributes(ec);
            preUserId = ec.getOwnerId() > 0 ? ec.getOwnerId() : 0;
            request.setAttribute("entityCreatedDate", sdf.format(ec.getCreatedDate()));
        }
    }
    boolean writeToDB = fp.getBoolean(CreateDiscrepancyNoteServlet.WRITE_TO_DB, true);
    HashMap<Integer, Integer> autoviews = (HashMap<Integer, Integer>) session.getAttribute(AUTOVIEWS);
    autoviews = autoviews == null ? new HashMap<Integer, Integer>() : autoviews;
    HashMap<Integer, DiscrepancyNoteBean> boxDNMap = (HashMap<Integer, DiscrepancyNoteBean>) session.getAttribute(BOX_DN_MAP);
    if (boxDNMap == null || !boxDNMap.containsKey(0)) {
        boxDNMap = new HashMap<Integer, DiscrepancyNoteBean>();
        // initialize dn for a new thread
        DiscrepancyNoteBean dnb = new DiscrepancyNoteBean();
        if (currentRole.getRole().equals(Role.RESEARCHASSISTANT) || currentRole.getRole().equals(Role.RESEARCHASSISTANT2) || currentRole.getRole().equals(Role.INVESTIGATOR)) {
            dnb.setDiscrepancyNoteTypeId(DiscrepancyNoteType.ANNOTATION.getId());
            dnb.setResolutionStatusId(ResolutionStatus.NOT_APPLICABLE.getId());
            autoviews.put(0, 0);
        // request.setAttribute("autoView", "0");
        } else {
            dnb.setDiscrepancyNoteTypeId(DiscrepancyNoteType.QUERY.getId());
            dnb.setAssignedUserId(preUserId);
            autoviews.put(0, 1);
        // request.setAttribute("autoView", "1");
        }
        boxDNMap.put(0, dnb);
    } else if (boxDNMap.containsKey(0)) {
        int dnTypeId = boxDNMap.get(0).getDiscrepancyNoteTypeId();
        autoviews.put(0, dnTypeId == 3 ? 1 : 0);
    }
    if (boxDNMap.containsKey(0)) {
        int dnTypeId0 = boxDNMap.get(0).getDiscrepancyNoteTypeId();
        if (dnTypeId0 == 2 || dnTypeId0 == 4) {
            request.setAttribute("typeID0", dnTypeId0 + "");
        }
    }
    // request.setAttribute("enterData", enterData);
    request.setAttribute("monitor", monitor);
    request.setAttribute(ENTITY_ID, entityId + "");
    request.setAttribute(ENTITY_TYPE, name);
    request.setAttribute(ENTITY_FIELD, field);
    request.setAttribute(ENTITY_COLUMN, column);
    request.setAttribute(CreateDiscrepancyNoteServlet.WRITE_TO_DB, writeToDB ? "1" : "0");
    ArrayList notes = (ArrayList) dndao.findAllByEntityAndColumn(name, entityId, column);
    if (notes.size() > 0) {
        notes.get(0);
        // @pgawade 21-May-2011 Corrected the condition to throw no access
        // error
        StudyDAO studyDAO = new StudyDAO(sm.getDataSource());
        int parentStudyForNoteSub = 0;
        // @pgawade #9801: 07-June-2011 corrected the way to get study
        // subject id associated with discrepancy note
        // int noteSubId = note.getOwnerId();
        StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
        // StudySubjectBean notessub = (StudySubjectBean)
        // ssdao.findByPK(noteSubId);
        StudySubjectBean notessub = (StudySubjectBean) ssdao.findByPK(subjectId);
        StudyBean studyBeanSub = (StudyBean) studyDAO.findByPK(notessub.getStudyId());
        if (null != studyBeanSub) {
            parentStudyForNoteSub = studyBeanSub.getParentStudyId();
        }
        if (notessub.getStudyId() != currentStudy.getId() && currentStudy.getId() != parentStudyForNoteSub) {
            addPageMessage(noAccessMessage);
            throw new InsufficientPermissionException(Page.MENU_SERVLET, exceptionName, "1");
        }
    }
    FormDiscrepancyNotes newNotes = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
    Map<Integer, DiscrepancyNoteBean> noteTree = new LinkedHashMap<Integer, DiscrepancyNoteBean>();
    String session_key = eventCRFId + "_" + field;
    ArrayList newFieldNotes = null;
    if (newNotes != null && (!newNotes.getNotes(field).isEmpty() || !newNotes.getNotes(session_key).isEmpty())) {
        newFieldNotes = newNotes.getNotes(field);
        if (newFieldNotes == null || newFieldNotes.size() == 0) {
            newFieldNotes = newNotes.getNotes(session_key);
        }
        // System.out.println("how many notes:" + newFieldNotes.size());
        for (int i = 0; i < newFieldNotes.size(); i++) {
            DiscrepancyNoteBean note = (DiscrepancyNoteBean) newFieldNotes.get(i);
            note.setLastUpdator(ub);
            note.setLastDateUpdated(new Date());
            note.setDisType(DiscrepancyNoteType.get(note.getDiscrepancyNoteTypeId()));
            note.setResStatus(ResolutionStatus.get(note.getResolutionStatusId()));
            note.setSaved(false);
            if (itemId > 0) {
                note.setEntityName(item.getName());
                note.setEntityValue(itemData.getValue());
            }
            note.setSubjectName(ssub.getName());
            note.setEntityType(name);
            int pId = note.getParentDnId();
            if (pId == 0) {
                // we can only keep one unsaved note because
                // note.id == 0
                noteTree.put(note.getId(), note);
            }
        }
        for (int i = 0; i < newFieldNotes.size(); i++) {
            DiscrepancyNoteBean note = (DiscrepancyNoteBean) newFieldNotes.get(i);
            int pId = note.getParentDnId();
            if (pId > 0) {
                note.setSaved(false);
                note.setLastUpdator(ub);
                note.setLastDateUpdated(new Date());
                note.setEntityName(item.getName());
                note.setSubjectName(ssub.getName());
                note.setEntityType(name);
                note.setDisType(DiscrepancyNoteType.get(note.getDiscrepancyNoteTypeId()));
                note.setResStatus(ResolutionStatus.get(note.getResolutionStatusId()));
                DiscrepancyNoteBean parent = noteTree.get(new Integer(pId));
                if (parent != null) {
                    parent.getChildren().add(note);
                }
            }
        }
    }
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    HashMap<Integer, String> fvcInitAssigns = new HashMap<Integer, String>();
    for (int i = 0; i < notes.size(); i++) {
        DiscrepancyNoteBean note = (DiscrepancyNoteBean) notes.get(i);
        note.setColumn(column);
        note.setEntityId(entityId);
        note.setEntityType(name);
        note.setField(field);
        Date lastUpdatedDate = note.getCreatedDate();
        UserAccountBean lastUpdator = (UserAccountBean) udao.findByPK(note.getOwnerId());
        note.setLastUpdator(lastUpdator);
        note.setLastDateUpdated(lastUpdatedDate);
        int pId = note.getParentDnId();
        note.setDisType(DiscrepancyNoteType.get(note.getDiscrepancyNoteTypeId()));
        note.setResStatus(ResolutionStatus.get(note.getResolutionStatusId()));
        if (pId == 0) {
            noteTree.put(new Integer(note.getId()), note);
        }
    }
    for (int i = 0; i < notes.size(); i++) {
        DiscrepancyNoteBean note = (DiscrepancyNoteBean) notes.get(i);
        int pId = note.getParentDnId();
        if (itemId > 0) {
            note.setEntityName(item.getName());
            note.setEntityValue(itemData.getValue());
        }
        note.setSubjectName(ssub.getName());
        note.setEntityType(name);
        Date lastUpdatedDate = note.getCreatedDate();
        UserAccountBean lastUpdator = (UserAccountBean) udao.findByPK(note.getOwnerId());
        note.setLastUpdator(lastUpdator);
        note.setLastDateUpdated(lastUpdatedDate);
        note.setDisType(DiscrepancyNoteType.get(note.getDiscrepancyNoteTypeId()));
        note.setResStatus(ResolutionStatus.get(note.getResolutionStatusId()));
        if (pId > 0) {
            DiscrepancyNoteBean parent = noteTree.get(new Integer(pId));
            if (parent != null) {
                parent.getChildren().add(note);
                if (!note.getCreatedDate().before(parent.getLastDateUpdated())) {
                    parent.setLastDateUpdated(note.getCreatedDate());
                }
                if (note.getDiscrepancyNoteTypeId() == 1 && note.getAssignedUserId() > 0) {
                    int ownerId = note.getOwnerId();
                    if (fvcInitAssigns.containsKey(pId)) {
                        String f = fvcInitAssigns.get(pId);
                        String fn = note.getId() + "." + ownerId;
                        if (fn.compareTo(f) < 0) {
                            fvcInitAssigns.put(pId, fn);
                        }
                    } else {
                        fvcInitAssigns.put(pId, note.getId() + "." + ownerId);
                    }
                }
            }
        }
    }
    Set parents = noteTree.keySet();
    Iterator it = parents.iterator();
    while (it.hasNext()) {
        Integer key = (Integer) it.next();
        DiscrepancyNoteBean note = noteTree.get(key);
        note.setNumChildren(note.getChildren().size());
        note.setEntityType(name);
        if (!boxDNMap.containsKey(key)) {
            DiscrepancyNoteBean dn = new DiscrepancyNoteBean();
            dn.setId(key);
            int dnTypeId = note.getDiscrepancyNoteTypeId();
            dn.setDiscrepancyNoteTypeId(dnTypeId);
            if (dnTypeId == 3) {
                // Query
                dn.setAssignedUserId(note.getOwnerId());
            } else if (dnTypeId == 1) {
                // FVC
                if (fvcInitAssigns.containsKey(key)) {
                    String[] s = fvcInitAssigns.get(key).split("\\.");
                    int i = Integer.parseInt(s.length == 2 ? s[1].trim() : "0");
                    dn.setAssignedUserId(i);
                }
            }
            Role r = currentRole.getRole();
            // currentStudy.getId() != currentStudy.getParentStudyId()) {
            if (r.equals(Role.RESEARCHASSISTANT) || r.equals(Role.RESEARCHASSISTANT2) || r.equals(Role.INVESTIGATOR)) {
                if (dn.getDiscrepancyNoteTypeId() == DiscrepancyNoteType.QUERY.getId() && note.getResStatus().getId() == ResolutionStatus.UPDATED.getId()) {
                    dn.setResolutionStatusId(ResolutionStatus.UPDATED.getId());
                } else {
                    dn.setResolutionStatusId(ResolutionStatus.RESOLVED.getId());
                }
                if (dn.getAssignedUserId() > 0) {
                    autoviews.put(key, 1);
                } else {
                    autoviews.put(key, 0);
                }
            // copied from CreateDiscrepancyNoteServlet
            // request.setAttribute("autoView", "0");
            // hide the panel, tbh
            } else {
                if (note.getResStatus().getId() == ResolutionStatus.RESOLVED.getId()) {
                    dn.setResolutionStatusId(ResolutionStatus.CLOSED.getId());
                } else if (note.getResStatus().getId() == ResolutionStatus.CLOSED.getId()) {
                    dn.setResolutionStatusId(ResolutionStatus.UPDATED.getId());
                } else if (r.equals(Role.MONITOR)) {
                    dn.setResolutionStatusId(ResolutionStatus.UPDATED.getId());
                } else if (dn.getDiscrepancyNoteTypeId() == 1) {
                    dn.setResolutionStatusId(ResolutionStatus.RESOLVED.getId());
                } else {
                    dn.setResolutionStatusId(ResolutionStatus.UPDATED.getId());
                }
                autoviews.put(key, 1);
                if (dn.getAssignedUserId() > 0) {
                } else {
                    dn.setAssignedUserId(preUserId);
                }
            }
            boxDNMap.put(key, dn);
        }
    }
    session.setAttribute(BOX_DN_MAP, boxDNMap);
    session.setAttribute(AUTOVIEWS, autoviews);
    // noteTree is a Hashmap mapping note id to a parent note, with all the
    // child notes
    // stored in the children List.
    // BWP 3029>>make sure the parent note has an updated resolution status
    // and
    // updated date
    fixStatusUpdatedDate(noteTree);
    request.setAttribute(DIS_NOTES, noteTree);
    // copied from CreatediscrepancyNoteServlet generateUserAccounts
    StudyDAO studyDAO = new StudyDAO(sm.getDataSource());
    StudyBean subjectStudy = studyDAO.findByStudySubjectId(subjectId);
    int studyId = currentStudy.getId();
    ArrayList<UserAccountBean> userAccounts = new ArrayList();
    if (currentStudy.getParentStudyId() > 0) {
        userAccounts = udao.findAllUsersByStudyOrSite(studyId, currentStudy.getParentStudyId(), subjectId);
    } else if (subjectStudy.getParentStudyId() > 0) {
        userAccounts = udao.findAllUsersByStudyOrSite(subjectStudy.getId(), subjectStudy.getParentStudyId(), subjectId);
    } else {
        userAccounts = udao.findAllUsersByStudyOrSite(studyId, 0, subjectId);
    }
    request.setAttribute(USER_ACCOUNTS, userAccounts);
    request.setAttribute(VIEW_DN_LINK, this.getPageServletFileName());
    // audit log items (from ViewItemAuditLogServlet.java)
    AuditDAO adao = new AuditDAO(sm.getDataSource());
    if (name.equalsIgnoreCase("studysub")) {
        name = "study_subject";
    } else if (name.equalsIgnoreCase("eventcrf")) {
        name = "event_crf";
    } else if (name.equalsIgnoreCase("studyevent")) {
        name = "study_event";
    } else if (name.equalsIgnoreCase("itemdata")) {
        name = "item_data";
    }
    ArrayList itemAuditEvents = adao.findItemAuditEvents(entityId, name);
    request.setAttribute("itemAudits", itemAuditEvents);
    forwardPage(Page.VIEW_DISCREPANCY_NOTE);
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) LinkedHashMap(java.util.LinkedHashMap) ResolutionStatus(org.akaza.openclinica.bean.core.ResolutionStatus) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) ArrayList(java.util.ArrayList) List(java.util.List) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormDiscrepancyNotes(org.akaza.openclinica.control.form.FormDiscrepancyNotes) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) Role(org.akaza.openclinica.bean.core.Role) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) Set(java.util.Set) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) AuditDAO(org.akaza.openclinica.dao.admin.AuditDAO) DiscrepancyNoteType(org.akaza.openclinica.bean.core.DiscrepancyNoteType) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) Iterator(java.util.Iterator) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) SimpleDateFormat(java.text.SimpleDateFormat)

Example 52 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class UrlRewriteServlet method getOpenClinicaResourceFromURL.

/**
 * Method to parse the request URL parameters and get the respective
 * database identifiers
 *
 * @param URLPath
 *            - example "S_CPCS/320999/SE_CPCS%5B1%5D/F_CPCS_1"
 * @param queryString
 *            - example
 *            "format=html&mode=view&tabId=1&exitTo=ViewStudySubject"
 * @return
 */
public OpenClinicaResource getOpenClinicaResourceFromURL(String URLPath) /*
                                                                            * ,
                                                                            * String
                                                                            * queryString
                                                                            */
{
    OpenClinicaResource openClinicaResource = new OpenClinicaResource();
    if ((null != URLPath) && (!URLPath.equals(""))) {
        if (URLPath.contains("/")) {
            String[] tokens = URLPath.split("/");
            if (tokens.length != 0) {
                String URLParamValue = "";
                StudyDAO stdao = new StudyDAO(getDataSource());
                StudySubjectDAO ssubdao = new StudySubjectDAO(getDataSource());
                StudyEventDefinitionDAO sedefdao = new StudyEventDefinitionDAO(getDataSource());
                CRFDAO crfdao = new CRFDAO(getDataSource());
                CRFVersionDAO crfvdao = new CRFVersionDAO(getDataSource());
                ItemDAO idao = new ItemDAO(getDataSource());
                ItemGroupDAO igdao = new ItemGroupDAO(getDataSource());
                StudyEventDAO sedao = new StudyEventDAO(getDataSource());
                StudyBean study = null;
                StudySubjectBean subject = null;
                StudyEventDefinitionBean sed = null;
                CRFBean c = null;
                CRFVersionBean cv = null;
                ItemBean item = null;
                ItemGroupBean ig = null;
                StudyEventBean studyEvent = null;
                Integer studySubjectId = 0;
                Integer eventDefId = 0;
                Integer eventRepeatKey = 0;
                for (int i = 0; i < tokens.length; i++) {
                    // when interpreting these request URL parameters, the
                    // assumption is that the position of
                    // each type of parameters will be fixed. Meaning, study
                    // OID is always going to be at the start
                    // followed by StudySubjectKey followed by study event
                    // definition OID followed by
                    // study event repeat key followed by form OID followed
                    // by item group OID followed by
                    // item group repeat key followed by item OID
                    // It can also be done based on the start of OID value
                    // (example study OID presently
                    // starts with 'S_' but we will have to change it if we
                    // change the method of generating
                    // oID values in future.
                    URLParamValue = tokens[i].trim();
                    // System.out.println("URLParamValue::"+URLParamValue);
                    logger.info("URLPAramValue::" + URLParamValue);
                    if ((null != URLParamValue) && (!URLParamValue.equals(""))) {
                        switch(i) {
                            case 0:
                                {
                                    // study OID
                                    study = stdao.findByOid(URLParamValue);
                                    // validate study OID
                                    if (study == null) {
                                        openClinicaResource.setInValid(true);
                                        openClinicaResource.getMessages().add(resexception.getString("invalid_study_oid"));
                                        return openClinicaResource;
                                    } else {
                                        openClinicaResource.setStudyOID(URLParamValue);
                                        if (null != study) {
                                            openClinicaResource.setStudyID(study.getId());
                                        }
                                    }
                                    break;
                                }
                            case 1:
                                {
                                    // StudySubjectKey
                                    subject = ssubdao.findByOidAndStudy(URLParamValue, study.getId());
                                    // validate subject OID
                                    if (subject == null) {
                                        openClinicaResource.setInValid(true);
                                        openClinicaResource.getMessages().add(resexception.getString("invalid_subject_oid"));
                                        return openClinicaResource;
                                    } else {
                                        openClinicaResource.setStudySubjectOID(URLParamValue);
                                        if (null != subject) {
                                            studySubjectId = subject.getId();
                                            openClinicaResource.setStudySubjectID(studySubjectId);
                                        }
                                    }
                                    break;
                                }
                            case 2:
                                {
                                    // study event definition OID
                                    // separate study event OID and study event
                                    // repeat key
                                    String seoid = "";
                                    String eventOrdinal = "";
                                    if (URLParamValue.contains("%5B") && URLParamValue.contains("%5D")) {
                                        seoid = URLParamValue.substring(0, URLParamValue.indexOf("%5B"));
                                        openClinicaResource.setStudyEventDefOID(seoid);
                                        eventOrdinal = URLParamValue.substring(URLParamValue.indexOf("%5B") + 3, URLParamValue.indexOf("%5D"));
                                    } else if (URLParamValue.contains("[") && URLParamValue.contains("]")) {
                                        seoid = URLParamValue.substring(0, URLParamValue.indexOf("["));
                                        logger.info("seoid" + seoid);
                                        openClinicaResource.setStudyEventDefOID(seoid);
                                        eventOrdinal = URLParamValue.substring(URLParamValue.indexOf("[") + 1, URLParamValue.indexOf("]"));
                                        logger.info("eventOrdinal::" + eventOrdinal);
                                    } else {
                                        // event ordinal not specified
                                        openClinicaResource.setInValid(true);
                                        openClinicaResource.getMessages().add(resexception.getString("event_ordinal_not_specified"));
                                        return openClinicaResource;
                                    }
                                    if ((null != seoid) && (null != study)) {
                                        sed = sedefdao.findByOidAndStudy(seoid, study.getId(), study.getParentStudyId());
                                        // validate study event oid
                                        if (null == sed) {
                                            openClinicaResource.setInValid(true);
                                            openClinicaResource.getMessages().add(resexception.getString("invalid_event_oid"));
                                            return openClinicaResource;
                                        } else {
                                            eventDefId = sed.getId();
                                            openClinicaResource.setStudyEventDefID(eventDefId);
                                        }
                                    }
                                    if (null != eventRepeatKey) {
                                        eventRepeatKey = Integer.parseInt(eventOrdinal.trim());
                                        // validate the event ordinal specified exists in database
                                        studyEvent = (StudyEventBean) sedao.findByStudySubjectIdAndDefinitionIdAndOrdinal(subject.getId(), sed.getId(), eventRepeatKey);
                                        // this method return new StudyEvent (not null) even if no studyEvent can be found
                                        if (null == studyEvent || studyEvent.getId() == 0) {
                                            openClinicaResource.setInValid(true);
                                            openClinicaResource.getMessages().add(resexception.getString("invalid_event_ordinal"));
                                            return openClinicaResource;
                                        } else {
                                            openClinicaResource.setStudyEventRepeatKey(eventRepeatKey);
                                        }
                                    }
                                    break;
                                }
                            case 3:
                                {
                                    // form OID
                                    openClinicaResource.setFormVersionOID(URLParamValue);
                                    // validate the crf version oid
                                    cv = crfvdao.findByOid(URLParamValue);
                                    if (cv == null) {
                                        openClinicaResource.setInValid(true);
                                        openClinicaResource.getMessages().add(resexception.getString("invalid_crf_oid"));
                                        return openClinicaResource;
                                    } else {
                                        openClinicaResource.setFormVersionID(cv.getId());
                                        // validate if crf is removed
                                        if (cv.getStatus().equals(Status.DELETED)) {
                                            openClinicaResource.setInValid(true);
                                            openClinicaResource.getMessages().add(resexception.getString("removed_crf"));
                                            return openClinicaResource;
                                        } else {
                                            if (null != study) {
                                                // cv =
                                                // crfvdao.findByCrfVersionOidAndStudy(URLParamValue,
                                                // study.getId());
                                                // if (null != cv) {
                                                // openClinicaResource.setFormVersionID(cv.getId());
                                                // openClinicaResource.setFormID(cv.getCrfId());
                                                // }
                                                HashMap studySubjectCRFDataDetails = sedao.getStudySubjectCRFData(study, studySubjectId, eventDefId, URLParamValue, eventRepeatKey);
                                                if ((null != studySubjectCRFDataDetails) && (studySubjectCRFDataDetails.size() != 0)) {
                                                    if (studySubjectCRFDataDetails.containsKey("event_crf_id")) {
                                                        openClinicaResource.setEventCrfId((Integer) studySubjectCRFDataDetails.get("event_crf_id"));
                                                    }
                                                    if (studySubjectCRFDataDetails.containsKey("event_definition_crf_id")) {
                                                        openClinicaResource.setEventDefinitionCrfId((Integer) studySubjectCRFDataDetails.get("event_definition_crf_id"));
                                                    }
                                                    if (studySubjectCRFDataDetails.containsKey("study_event_id")) {
                                                        openClinicaResource.setStudyEventId((Integer) studySubjectCRFDataDetails.get("study_event_id"));
                                                    }
                                                } else {
                                                    // no data was found in the database for the combination of parameters in the RESTful URL. There are 2 possible reasons:
                                                    // a. The data entry is not started yet for this event CRF. As of OpenClinica 3.1.3 we have not implemented the
                                                    // RESTful URL functionality in this case.
                                                    // b. The form version OID entered in the URL could be different than the one used in the data entry
                                                    openClinicaResource.setInValid(true);
                                                    openClinicaResource.getMessages().add(resexception.getString("either_no_data_for_crf_or_data_entry_not_started"));
                                                    return openClinicaResource;
                                                }
                                            }
                                        }
                                    }
                                    break;
                                }
                            case 4:
                                {
                                    // item group OID
                                    // separate item group OID and item group
                                    // repeat key
                                    String igoid = "";
                                    String igRepeatKey = "";
                                    if (URLParamValue.contains("[")) {
                                        igoid = URLParamValue.substring(1, URLParamValue.indexOf("["));
                                        igRepeatKey = URLParamValue.substring(URLParamValue.indexOf("["), URLParamValue.indexOf("}]"));
                                    }
                                    if ((null != igoid) && (null != cv)) {
                                        ig = igdao.findByOidAndCrf(URLParamValue, cv.getCrfId());
                                        if (null != ig) {
                                            openClinicaResource.setItemGroupID(ig.getId());
                                        }
                                    }
                                    if (null != igRepeatKey) {
                                        openClinicaResource.setItemGroupRepeatKey(Integer.parseInt(igRepeatKey));
                                    }
                                    break;
                                }
                            case 5:
                                {
                                    // item = idao.find
                                    break;
                                }
                        }
                    // switch end
                    }
                }
            }
        }
    }
    return openClinicaResource;
}
Also used : CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) HashMap(java.util.HashMap) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ItemGroupDAO(org.akaza.openclinica.dao.submit.ItemGroupDAO) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Example 53 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class AnonymousFormControllerV2 method getEnketoForm.

/**
 * @api {post} /pages/api/v2/anonymousform/form Retrieve anonymous form URL
 * @apiName getEnketoForm
 * @apiPermission Module participate - enabled
 * @apiVersion 3.8.0
 * @apiParam {String} studyOid Study Oid
 * @apiParam {String} submissionUri Submission Url
 * @apiGroup Form
 * @apiDescription Retrieve anonymous form url.
 * @apiParamExample {json} Request-Example:
 *                  {
 *                  "studyOid": "S_BL101",
 *                  "submissionUri": "abcde"
 *                  }
 * @apiSuccessExample {json} Success-Response:
 *                    HTTP/1.1 200 OK
 *                    {
 *                    "url": "http://localhost:8006/::YYYi?iframe=true&ecid=abb764d026830e98b895ece6d9dcaf3c5e817983cc00a4ebfaabcb6c3700b4d5",
 *                    "offline": "false"
 *                    }
 */
@RequestMapping(value = "/form", method = RequestMethod.POST)
public ResponseEntity<AnonymousUrlResponse> getEnketoForm(@RequestBody HashMap<String, String> map) throws Exception {
    ResourceBundleProvider.updateLocale(new Locale("en_US"));
    EventDefinitionCrfTagService tagService = (EventDefinitionCrfTagService) SpringServletAccess.getApplicationContext(context).getBean("eventDefinitionCrfTagService");
    String formUrl = null;
    String studyOid = map.get("studyOid");
    if (!mayProceed(studyOid))
        return new ResponseEntity<AnonymousUrlResponse>(org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    String submissionUri = map.get("submissionUri");
    if (submissionUri != "" && submissionUri != null) {
        StudyBean study = getStudy(studyOid);
        EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(dataSource);
        ArrayList<EventDefinitionCRFBean> edcBeans = edcdao.findAllSubmissionUriAndStudyId(submissionUri, study.getId());
        if (edcBeans.size() != 0) {
            EventDefinitionCRFBean edcBean = edcBeans.get(0);
            CRFDAO crfdao = new CRFDAO(dataSource);
            CRFVersionDAO cvdao = new CRFVersionDAO(dataSource);
            StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(dataSource);
            CRFVersionBean crfVersionBean = (CRFVersionBean) cvdao.findByPK(edcBean.getDefaultVersionId());
            CRFBean crf = (CRFBean) crfdao.findByPK(crfVersionBean.getCrfId());
            StudyBean sBean = (StudyBean) sdao.findByPK(edcBean.getStudyId());
            StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) seddao.findByPK(edcBean.getStudyEventDefinitionId());
            String tagPath = sedBean.getOid() + "." + crf.getOid();
            boolean isOffline = tagService.getEventDefnCrfOfflineStatus(2, tagPath, true);
            String offline = null;
            if (isOffline)
                offline = "true";
            else
                offline = "false";
            formUrl = createAnonymousEnketoUrl(sBean.getOid(), crfVersionBean, edcBean, isOffline);
            AnonymousUrlResponse anonResponse = new AnonymousUrlResponse(formUrl, offline, crf.getName(), crfVersionBean.getDescription());
            return new ResponseEntity<AnonymousUrlResponse>(anonResponse, org.springframework.http.HttpStatus.OK);
        } else {
            return new ResponseEntity<AnonymousUrlResponse>(org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
        }
    } else {
        return new ResponseEntity<AnonymousUrlResponse>(org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    }
}
Also used : Locale(java.util.Locale) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventDefinitionCrfTagService(org.akaza.openclinica.service.managestudy.EventDefinitionCrfTagService) ResponseEntity(org.springframework.http.ResponseEntity) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 54 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class ExtractBean method getMetadata.

/**
 * Implements the Column algorithm in "Dataset Export Algorithms" Must be
 * called after DatasetDAO.getDatasetData();
 */
public void getMetadata() {
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(ds);
    CRFDAO cdao = new CRFDAO(ds);
    CRFVersionDAO cvdao = new CRFVersionDAO(ds);
    ItemDAO idao = new ItemDAO(ds);
    ItemFormMetadataDAO ifmDAO = new ItemFormMetadataDAO(this.ds);
    StudyGroupDAO studygroupDAO = new StudyGroupDAO(ds);
    StudyGroupClassDAO studygroupclassDAO = new StudyGroupClassDAO(ds);
    // SubjectGroupMapDAO subjectGroupMapDAO = new SubjectGroupMapDAO(ds);
    studyGroupClasses = new ArrayList();
    studyGroupMap = new HashMap();
    studyGroupMaps = new HashMap<Integer, ArrayList>();
    sedCrfColumns = new HashMap();
    displayed = new HashMap();
    sedCrfItemFormMetadataBeans = new HashMap();
    studyEvents = seddao.findAllByStudy(study);
    ArrayList finalStudyEvents = new ArrayList();
    if (dataset.isShowSubjectGroupInformation()) {
        // logger.info("found study id for maps: "+study.getId());
        studyGroupMaps = studygroupDAO.findSubjectGroupMaps(study.getId());
        // below is for a given subject; we need a data structure for
        // all subjects
        // studyGroupMap = studygroupDAO.findByStudySubject(currentSubject);
        // problem: can't use currentSubject here, since it's not 'set up'
        // properly
        // how to get the current subject?
        logger.info("found subject group ids: " + dataset.getSubjectGroupIds().toString());
        // studyGroupClasses = dataset.getSubjectGroupIds();
        for (int h = 0; h < dataset.getSubjectGroupIds().size(); h++) {
            Integer groupId = (Integer) dataset.getSubjectGroupIds().get(h);
            StudyGroupClassBean sgclass = (StudyGroupClassBean) studygroupclassDAO.findByPK(groupId.intValue());
            // logger.info();
            // hmm how to link groups to subjects though? only through
            // subject group map
            logger.info("found a studygroupclass bean: " + sgclass.getName());
            studyGroupClasses.add(sgclass);
        }
    }
    for (int i = 0; i < studyEvents.size(); i++) {
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) studyEvents.get(i);
        if (!selectedSED(sed)) {
            continue;
        }
        ArrayList CRFs = (ArrayList) cdao.findAllActiveByDefinition(sed);
        ArrayList CRFsDisplayedInThisSED = new ArrayList();
        for (int j = 0; j < CRFs.size(); j++) {
            CRFBean cb = (CRFBean) CRFs.get(j);
            if (!selectedSEDCRF(sed, cb)) {
                continue;
            } else {
                CRFsDisplayedInThisSED.add(cb);
                ArrayList CRFVersions = cvdao.findAllByCRFId(cb.getId());
                for (int k = 0; k < CRFVersions.size(); k++) {
                    CRFVersionBean cvb = (CRFVersionBean) CRFVersions.get(k);
                    ArrayList Items = idao.findAllItemsByVersionId(cvb.getId());
                    // sort by ordinal/name
                    Collections.sort(Items);
                    for (int l = 0; l < Items.size(); l++) {
                        ItemBean ib = (ItemBean) Items.get(l);
                        if (selected(ib) && !getDisplayed(sed, cb, ib)) {
                            // logger.info("found at
                            // itemformmetadatadao: "+ib.getId()+",
                            // "+cvb.getId());
                            ItemFormMetadataBean ifmb = ifmDAO.findByItemIdAndCRFVersionId(ib.getId(), cvb.getId());
                            addColumn(sed, cb, ib);
                            addItemFormMetadataBeans(sed, cb, ifmb);
                            markDisplayed(sed, cb, ib);
                        }
                    }
                }
            }
        // else
        }
        // for
        sed.setCrfs(CRFsDisplayedInThisSED);
        // make the setCrfs call "stick"
        finalStudyEvents.add(sed);
    }
    this.studyEvents = finalStudyEvents;
}
Also used : CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) HashMap(java.util.HashMap) StudyGroupClassDAO(org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyGroupDAO(org.akaza.openclinica.dao.managestudy.StudyGroupDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudyGroupClassBean(org.akaza.openclinica.bean.managestudy.StudyGroupClassBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 55 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class CRFDAO method findByOid.

public CRFBean findByOid(String oid) {
    CRFBean crf = new CRFBean();
    this.unsetTypeExpected();
    setTypesExpected();
    HashMap variables = new HashMap();
    variables.put(Integer.valueOf(1), oid);
    String sql = digester.getQuery("findByOID");
    ArrayList rows = this.select(sql, variables);
    Iterator it = rows.iterator();
    if (it.hasNext()) {
        crf = (CRFBean) this.getEntityFromHashMap((HashMap) it.next());
        return crf;
    } else {
        return null;
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) CRFBean(org.akaza.openclinica.bean.admin.CRFBean)

Aggregations

CRFBean (org.akaza.openclinica.bean.admin.CRFBean)138 ArrayList (java.util.ArrayList)95 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)78 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)78 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)70 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)67 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)63 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)56 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)44 HashMap (java.util.HashMap)43 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)43 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)40 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)37 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)29 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)27 Iterator (java.util.Iterator)26 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)26 DisplayEventCRFBean (org.akaza.openclinica.bean.submit.DisplayEventCRFBean)22 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)21 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)20