Search in sources :

Example 31 with StudyBean

use of org.akaza.openclinica.bean.managestudy.StudyBean in project OpenClinica by OpenClinica.

the class RuleRunner method prepareEmailContents.

HashMap<String, String> prepareEmailContents(RuleSetBean ruleSet, RuleSetRuleBean ruleSetRule, StudyBean currentStudy, RuleActionBean ruleAction) {
    // get the Study Event
    StudyEventBean studyEvent = (StudyEventBean) getStudyEventDao().findByPK(Integer.valueOf(getExpressionService().getStudyEventDefenitionOrdninalCurated(ruleSet.getTarget().getValue())));
    // get the Study Subject
    StudySubjectBean studySubject = (StudySubjectBean) getStudySubjectDao().findByPK(studyEvent.getStudySubjectId());
    // get Study/Site Associated with Subject
    StudyBean theStudy = (StudyBean) getStudyDao().findByPK(studySubject.getStudyId());
    String theStudyName, theSiteName = "";
    if (theStudy.getParentStudyId() > 0) {
        StudyBean theParentStudy = (StudyBean) getStudyDao().findByPK(theStudy.getParentStudyId());
        theStudyName = theParentStudy.getName() + " / " + theParentStudy.getIdentifier();
        theSiteName = theStudy.getName() + " / " + theStudy.getIdentifier();
    } else {
        theStudyName = theStudy.getName() + " / " + theStudy.getIdentifier();
    }
    // get the eventCrf & subsequently the CRF Version
    //EventCRFBean eventCrf = (EventCRFBean) getEventCrfDao().findAllByStudyEvent(studyEvent).get(0);
    EventCRFBean eventCrf = (EventCRFBean) getEventCrfDao().findAllByStudyEventAndCrfOrCrfVersionOid(studyEvent, getExpressionService().getCrfOid(ruleSet.getTarget().getValue())).get(0);
    CRFVersionBean crfVersion = (CRFVersionBean) getCrfVersionDao().findByPK(eventCrf.getCRFVersionId());
    CRFBean crf = (CRFBean) getCrfDao().findByPK(crfVersion.getCrfId());
    String studyEventDefinitionName = getExpressionService().getStudyEventDefinitionFromExpression(ruleSet.getTarget().getValue(), currentStudy).getName();
    studyEventDefinitionName += " [" + studyEvent.getSampleOrdinal() + "]";
    String itemGroupName = getExpressionService().getItemGroupNameAndOrdinal(ruleSet.getTarget().getValue());
    ItemGroupBean itemGroupBean = getExpressionService().getItemGroupExpression(ruleSet.getTarget().getValue());
    ItemBean itemBean = getExpressionService().getItemExpression(ruleSet.getTarget().getValue(), itemGroupBean);
    String itemName = itemBean.getName();
    SectionBean section = (SectionBean) getSectionDAO().findByPK(getItemFormMetadataDAO().findByItemIdAndCRFVersionId(itemBean.getId(), crfVersion.getId()).getSectionId());
    StringBuffer sb = new StringBuffer();
    ResourceBundle respage = ResourceBundleProvider.getPageMessagesBundle();
    sb.append(respage.getString("email_header_1"));
    sb.append(" " + contextPath + " ");
    sb.append(respage.getString("email_header_2"));
    sb.append(" '" + currentStudy.getName() + "' ");
    sb.append(respage.getString("email_header_3"));
    sb.append(" \n\n ");
    sb.append(respage.getString("email_body_1") + " " + theStudyName + " \n ");
    sb.append(respage.getString("email_body_1_a") + " " + theSiteName + " \n ");
    sb.append(respage.getString("email_body_2") + " " + studySubject.getName() + " \n ");
    sb.append(respage.getString("email_body_3") + " " + studyEventDefinitionName + " \n ");
    sb.append(respage.getString("email_body_4") + " " + crf.getName() + " " + crfVersion.getName() + " \n ");
    sb.append(respage.getString("email_body_5") + " " + section.getTitle() + " \n ");
    sb.append(respage.getString("email_body_6") + " " + itemGroupName + " \n ");
    sb.append(respage.getString("email_body_7") + " " + itemName + " \n ");
    sb.append(respage.getString("email_body_8") + " " + ruleAction.getCuratedMessage() + " \n ");
    sb.append(" \n\n ");
    sb.append(respage.getString("email_body_9"));
    sb.append(" " + contextPath + " ");
    sb.append(respage.getString("email_body_10"));
    sb.append(" \n");
    requestURLMinusServletPath = requestURLMinusServletPath == null ? "" : requestURLMinusServletPath;
    sb.append(requestURLMinusServletPath + "/ViewSectionDataEntry?ecId=" + eventCrf.getId() + "&sectionId=" + section.getId() + "&tabId=" + section.getOrdinal());
    // &eventId="+ studyEvent.getId());
    sb.append("\n\n");
    sb.append(respage.getString("email_footer"));
    String subject = contextPath + " - [" + currentStudy.getName() + "] ";
    String ruleSummary = ruleAction.getSummary() != null ? ruleAction.getSummary() : "";
    String message = ruleSummary.length() < 20 ? ruleSummary : ruleSummary.substring(0, 20) + " ... ";
    subject += message;
    HashMap<String, String> emailContents = new HashMap<String, String>();
    emailContents.put("body", sb.toString());
    emailContents.put("subject", subject);
    return emailContents;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) HashMap(java.util.HashMap) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) ResourceBundle(java.util.ResourceBundle) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean)

Example 32 with StudyBean

use of org.akaza.openclinica.bean.managestudy.StudyBean in project OpenClinica by OpenClinica.

the class DiscrepancyNoteUtil method createThreads.

public List<DiscrepancyNoteThread> createThreads(List<DiscrepancyNoteBean> allDiscNotes, DataSource dataSource, StudyBean currentStudy) {
    List<DiscrepancyNoteThread> dnThreads = new ArrayList<DiscrepancyNoteThread>();
    if (allDiscNotes == null || allDiscNotes.isEmpty()) {
        return dnThreads;
    }
    if (currentStudy == null) {
        currentStudy = new StudyBean();
    }
    List<DiscrepancyNoteBean> childDiscBeans = new ArrayList<DiscrepancyNoteBean>();
    List<DiscrepancyNoteBean> eventCRFChildDiscBeans = new ArrayList<DiscrepancyNoteBean>();
    DiscrepancyNoteDAO discrepancyNoteDAO = new DiscrepancyNoteDAO(dataSource);
    DiscrepancyNoteThread tempDNThread = null;
    int resolutionStatusId = 0;
    for (DiscrepancyNoteBean discBean : allDiscNotes) {
        tempDNThread = new DiscrepancyNoteThread();
        tempDNThread.setStudyId(currentStudy.getId());
        tempDNThread.getLinkedNoteList().addFirst(discBean);
        // childDiscBeans should be empty here
        if (!childDiscBeans.isEmpty()) {
            childDiscBeans.clear();
        }
        childDiscBeans = discBean.getChildren();
        Collections.sort(childDiscBeans);
        resolutionStatusId = discBean.getResolutionStatusId();
        // the thread's status id is the parent's in this case, when there
        // are no children
        tempDNThread.setLatestResolutionStatus(this.getResolutionStatusName(resolutionStatusId));
        if (!childDiscBeans.isEmpty()) {
            for (DiscrepancyNoteBean childBean : childDiscBeans) {
                /*
                    if (childBean.getResolutionStatusId() != resolutionStatusId) {
                        // BWP issue 3468 WHO 5/2009: this local variable needs
                        // to be updated>>
                        resolutionStatusId = childBean.getResolutionStatusId();
                        // <<
                        tempDNThread.setLatestResolutionStatus(this.getResolutionStatusName(childBean.getResolutionStatusId()));
                    }
                    */
                tempDNThread.getLinkedNoteList().offer(childBean);
            }
        }
        dnThreads.add(tempDNThread);
    }
    /*
                // Do the filtering here; remove any DN threads that do not have any
                // notes
                LinkedList<DiscrepancyNoteBean> linkedList = null;

                if (resolutionStatusIds != null && !resolutionStatusIds.isEmpty()) {

                    for (DiscrepancyNoteThread dnThread : dnThreads) {
                        linkedList = new LinkedList<DiscrepancyNoteBean>();
                        for (DiscrepancyNoteBean discBean : dnThread.getLinkedNoteList()) {
                            for (int statusId : resolutionStatusIds) {
                                if (discBean.getResolutionStatusId() == statusId) {
                                    linkedList.offer(discBean);
                                }
                            }
                        }
                        dnThread.setLinkedNoteList(linkedList);
                    }
                    dnThreads = removeEmptyDNThreads(dnThreads);
                }
                if (discNoteType >= 1 && discNoteType <= 5) {

                    for (DiscrepancyNoteThread dnThread : dnThreads) {
                        linkedList = new LinkedList<DiscrepancyNoteBean>();
                        for (DiscrepancyNoteBean discBean : dnThread.getLinkedNoteList()) {
                            if (discBean.getDiscrepancyNoteTypeId() == discNoteType) {
                                linkedList.offer(discBean);
                            }
                        }
                        dnThread.setLinkedNoteList(linkedList);
                    }
                    dnThreads = removeEmptyDNThreads(dnThreads);
                }
        */
    return dnThreads;
}
Also used : DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList)

Example 33 with StudyBean

use of org.akaza.openclinica.bean.managestudy.StudyBean in project OpenClinica by OpenClinica.

the class JobTriggerService method triggerJob.

public void triggerJob() {
    ResourceBundleProvider.updateLocale(new Locale("en_US"));
    ArrayList<RuleSetBean> ruleSets = ruleSetDao.findAllRunOnSchedules(true);
    for (RuleSetBean ruleSet : ruleSets) {
        if (ruleSet.getStatus().AVAILABLE != null && ruleSet.isRunSchedule()) {
            if (ruleSet.getItemId() != null) {
                // item Specific Rule
                System.out.println("*** Item Specific Rule ***");
                ArrayList<RuleSetBean> ruleSetBeans = new ArrayList<>();
                StudyBean currentStudy = (StudyBean) getStudyDao().findByPK(ruleSet.getStudyId());
                ResourceBundleProvider.updateLocale(Locale.getDefault());
                UserAccountBean ub = (UserAccountBean) getUserAccountDao().findByPK(1);
                ruleSetBeans.add(ruleSet);
                ruleSetService.runRulesInBulk(ruleSetBeans, false, currentStudy, ub, true);
            } else {
                // Event Specific Rule		
                System.out.println("*** Event Specific Rule ***");
                StudyEventChangeDetails studyEventChangeDetails = new StudyEventChangeDetails(true, true);
                ArrayList<RuleSetBean> ruleSetBeans = new ArrayList<>();
                ExpressionBean eBean = new ExpressionBean();
                eBean.setValue(ruleSet.getTarget().getValue() + ".A.B");
                ruleSet.setTarget(eBean);
                ruleSetBeans.add(ruleSet);
                ruleSetService.runRulesInBeanProperty(ruleSetBeans, 1, studyEventChangeDetails);
            }
        }
    }
}
Also used : Locale(java.util.Locale) StudyEventChangeDetails(org.akaza.openclinica.patterns.ocobserver.StudyEventChangeDetails) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean)

Example 34 with StudyBean

use of org.akaza.openclinica.bean.managestudy.StudyBean in project OpenClinica by OpenClinica.

the class DiscrepancyNoteUtil method createThreadsOfParents.

public List<DiscrepancyNoteThread> createThreadsOfParents(List<DiscrepancyNoteBean> allDiscNotes, DataSource dataSource, StudyBean currentStudy, Set<Integer> resolutionStatusIds, int discNoteType, boolean includeEventCRFNotes) {
    List<DiscrepancyNoteThread> dnThreads = new ArrayList<DiscrepancyNoteThread>();
    if (allDiscNotes == null || allDiscNotes.isEmpty()) {
        return dnThreads;
    }
    if (currentStudy == null) {
        currentStudy = new StudyBean();
    }
    List<DiscrepancyNoteBean> childDiscBeans = new ArrayList<DiscrepancyNoteBean>();
    List<DiscrepancyNoteBean> eventCRFChildDiscBeans = new ArrayList<DiscrepancyNoteBean>();
    DiscrepancyNoteDAO discrepancyNoteDAO = new DiscrepancyNoteDAO(dataSource);
    DiscrepancyNoteThread tempDNThread = null;
    int resolutionStatusId = 0;
    for (DiscrepancyNoteBean discBean : allDiscNotes) {
        tempDNThread = new DiscrepancyNoteThread();
        tempDNThread.setStudyId(currentStudy.getId());
        tempDNThread.getLinkedNoteList().addFirst(discBean);
        // childDiscBeans should be empty here
        if (!childDiscBeans.isEmpty()) {
            childDiscBeans.clear();
        }
        childDiscBeans = discrepancyNoteDAO.findAllItemDataByStudyAndParent(currentStudy, discBean);
        if (includeEventCRFNotes) {
            eventCRFChildDiscBeans = discrepancyNoteDAO.findAllEventCRFByStudyAndParent(currentStudy, discBean);
        }
        if (!eventCRFChildDiscBeans.isEmpty()) {
            childDiscBeans.addAll(eventCRFChildDiscBeans);
            // sort the discnote beans, because we have eventCRF and
            // ItemDate types mixed here.
            Collections.sort(childDiscBeans);
        }
        resolutionStatusId = discBean.getResolutionStatusId();
        // the thread's status id is the parent's in this case, when there
        // are no children
        tempDNThread.setLatestResolutionStatus(this.getResolutionStatusName(resolutionStatusId));
        /*
            if (!childDiscBeans.isEmpty()) {

                for (DiscrepancyNoteBean childBean : childDiscBeans) {
                    if (childBean.getResolutionStatusId() != resolutionStatusId) {
                        // BWP issue 3468 WHO 5/2009: this local variable needs
                        // to be updated>>
                        resolutionStatusId = childBean.getResolutionStatusId();
                        // <<
                        tempDNThread.setLatestResolutionStatus(this.getResolutionStatusName(childBean.getResolutionStatusId()));
                    }
                    tempDNThread.getLinkedNoteList().offer(childBean);
                }
            }*/
        dnThreads.add(tempDNThread);
    }
    // Do the filtering here; remove any DN threads that do not have any
    // notes
    LinkedList<DiscrepancyNoteBean> linkedList = null;
    if (resolutionStatusIds != null && !resolutionStatusIds.isEmpty()) {
        for (DiscrepancyNoteThread dnThread : dnThreads) {
            linkedList = new LinkedList<DiscrepancyNoteBean>();
            for (DiscrepancyNoteBean discBean : dnThread.getLinkedNoteList()) {
                for (int statusId : resolutionStatusIds) {
                    if (discBean.getResolutionStatusId() == statusId) {
                        linkedList.offer(discBean);
                    }
                }
            }
            dnThread.setLinkedNoteList(linkedList);
        }
        dnThreads = removeEmptyDNThreads(dnThreads);
    }
    if (discNoteType >= 1 && discNoteType <= 5) {
        for (DiscrepancyNoteThread dnThread : dnThreads) {
            linkedList = new LinkedList<DiscrepancyNoteBean>();
            for (DiscrepancyNoteBean discBean : dnThread.getLinkedNoteList()) {
                if (discBean.getDiscrepancyNoteTypeId() == discNoteType) {
                    linkedList.offer(discBean);
                }
            }
            dnThread.setLinkedNoteList(linkedList);
        }
        dnThreads = removeEmptyDNThreads(dnThreads);
    }
    return dnThreads;
}
Also used : DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList)

Example 35 with StudyBean

use of org.akaza.openclinica.bean.managestudy.StudyBean in project OpenClinica by OpenClinica.

the class ParticipantEventService method getEventDefCrfsForStudyEvent.

public List<EventDefinitionCRFBean> getEventDefCrfsForStudyEvent(StudySubjectBean studySubject, StudyEventBean studyEvent) {
    Integer studyId = studySubject.getStudyId();
    StudyBean studyBean = (StudyBean) getStudyDAO().findByPK(studyId);
    ArrayList<EventDefinitionCRFBean> eventDefCrfs = null;
    ArrayList<EventDefinitionCRFBean> parentEventDefCrfs = new ArrayList<EventDefinitionCRFBean>();
    ArrayList<EventDefinitionCRFBean> netEventDefinitionCrfs = new ArrayList<EventDefinitionCRFBean>();
    eventDefCrfs = (ArrayList<EventDefinitionCRFBean>) getEventDefCRFDAO().findAllDefIdandStudyId(studyEvent.getStudyEventDefinitionId(), studyId);
    StudyBean parentStudy = null;
    if (studyBean.getParentStudyId() == 0)
        parentStudy = studyBean;
    else
        parentStudy = (StudyBean) getStudyDAO().findByPK(studyBean.getParentStudyId());
    parentEventDefCrfs = (ArrayList<EventDefinitionCRFBean>) getEventDefCRFDAO().findAllDefIdandStudyId(studyEvent.getStudyEventDefinitionId(), parentStudy.getId());
    boolean found;
    for (EventDefinitionCRFBean parentEventDefinitionCrf : parentEventDefCrfs) {
        found = false;
        for (EventDefinitionCRFBean eventDefinitionCrf : eventDefCrfs) {
            if (parentEventDefinitionCrf.getId() == eventDefinitionCrf.getParentId()) {
                //
                found = true;
                netEventDefinitionCrfs.add(eventDefinitionCrf);
                break;
            }
        }
        if (!found)
            netEventDefinitionCrfs.add(parentEventDefinitionCrf);
    }
    return netEventDefinitionCrfs;
}
Also used : StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Aggregations

StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)350 ArrayList (java.util.ArrayList)183 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)175 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)92 HashMap (java.util.HashMap)84 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)66 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)65 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)62 Date (java.util.Date)59 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)58 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)57 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)56 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)54 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)52 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)52 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)45 Locale (java.util.Locale)39 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)39 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)37 Iterator (java.util.Iterator)36