Search in sources :

Example 36 with CRFVersionBean

use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.

the class OpenRosaXmlGenerator method buildForm.

/**
     * @param formId
     * @return
     * @throws Exception
     */
public String buildForm(String formId) throws Exception {
    try {
        CRFVersionDAO versionDAO = new CRFVersionDAO(dataSource);
        FormLayoutDAO fldao = new FormLayoutDAO<>(dataSource);
        FormLayoutBean formLayout = fldao.findByOid(formId);
        CRFDAO crfDAO = new CRFDAO(dataSource);
        CRFBean crf = (CRFBean) crfDAO.findByPK(formLayout.getCrfId());
        CRFVersionMetadataUtil metadataUtil = new CRFVersionMetadataUtil(dataSource);
        ArrayList<SectionBean> crfSections = metadataUtil.retrieveFormMetadata(formLayout);
        ArrayList<CRFVersionBean> crfVersions = versionDAO.findAllByCRFId(crf.getId());
        CRFVersionBean crfVersion = crfVersions.get(0);
        StringWriter writer = new StringWriter();
        IOUtils.copy(getClass().getResourceAsStream("/properties/xform_template.xml"), writer, "UTF-8");
        String xform = writer.toString();
        Html html = buildJavaXForm(xform);
        int sectionCount = mapBeansToDTO(html, crf, crfVersion, crfSections);
        if (sectionCount > 1)
            setFormPaging(html);
        String xformMinusInstance = buildStringXForm(html);
        String preInstance = xformMinusInstance.substring(0, xformMinusInstance.indexOf("<instance>"));
        String instance = buildInstance(html.getHead().getModel(), formLayout, crfVersion, crfSections);
        String nodeset = xformMinusInstance.substring(xformMinusInstance.indexOf("</instance>") + "</instance>".length());
        // add nodeset for instanceId
        String postInstance = "<bind calculate=\"concat('uuid:', uuid())\" nodeset=\"/" + formLayout.getOid() + "/meta/instanceID\" readonly=\"true()\" type=\"string\"/>" + nodeset;
        logger.debug(preInstance + "<instance>\n" + instance + "\n</instance>" + postInstance);
        System.out.println(preInstance + "<instance>\n" + instance + "\n</instance>" + postInstance);
        return preInstance + "<instance>\n" + instance + "\n</instance>" + postInstance;
    } catch (Exception e) {
        log.error(e.getMessage());
        log.error(ExceptionUtils.getStackTrace(e));
        throw new Exception(e);
    }
}
Also used : CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean) Html(org.akaza.openclinica.web.pform.dto.Html) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) StringWriter(java.io.StringWriter) FormLayoutDAO(org.akaza.openclinica.dao.submit.FormLayoutDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) CRFVersionMetadataUtil(org.akaza.openclinica.control.managestudy.CRFVersionMetadataUtil)

Example 37 with CRFVersionBean

use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.

the class SDVUtil method getCRFVersionName.

public String getCRFVersionName(int crfVersionId) {
    CRFVersionDAO cRFVersionDAO = new CRFVersionDAO(dataSource);
    CRFVersionBean versionBean = (CRFVersionBean) cRFVersionDAO.findByPK(crfVersionId);
    if (versionBean != null) {
        return versionBean.getName();
    }
    return "";
}
Also used : CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean)

Example 38 with CRFVersionBean

use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.

the class SDVUtil method getCRFName.

public String getCRFName(int crfVersionId) {
    CRFVersionDAO cRFVersionDAO = new CRFVersionDAO(dataSource);
    CRFDAO cRFDAO = new CRFDAO(dataSource);
    CRFVersionBean versionBean = (CRFVersionBean) cRFVersionDAO.findByPK(crfVersionId);
    if (versionBean != null) {
        CRFBean crfBean = (CRFBean) cRFDAO.findByPK(versionBean.getCrfId());
        if (crfBean != null)
            return crfBean.getName();
    }
    return "";
}
Also used : EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean)

Example 39 with CRFVersionBean

use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.

the class ImportCRFDataService method eventCRFStatusesValid.

/*
     * purpose: returns false if any of the forms/EventCRFs fail the UpsertOnBean rules.
     */
public boolean eventCRFStatusesValid(ODMContainer odmContainer, UserAccountBean ub) {
    ArrayList<EventCRFBean> eventCRFBeans = new ArrayList<EventCRFBean>();
    ArrayList<Integer> eventCRFBeanIds = new ArrayList<Integer>();
    EventCRFDAO eventCrfDAO = new EventCRFDAO(ds);
    StudySubjectDAO studySubjectDAO = new StudySubjectDAO(ds);
    StudyEventDefinitionDAO studyEventDefinitionDAO = new StudyEventDefinitionDAO(ds);
    StudyDAO studyDAO = new StudyDAO(ds);
    StudyEventDAO studyEventDAO = new StudyEventDAO(ds);
    UpsertOnBean upsert = odmContainer.getCrfDataPostImportContainer().getUpsertOn();
    // If Upsert bean is not present, create one with default settings
    if (upsert == null)
        upsert = new UpsertOnBean();
    String studyOID = odmContainer.getCrfDataPostImportContainer().getStudyOID();
    StudyBean studyBean = studyDAO.findByOid(studyOID);
    ArrayList<SubjectDataBean> subjectDataBeans = odmContainer.getCrfDataPostImportContainer().getSubjectData();
    for (SubjectDataBean subjectDataBean : subjectDataBeans) {
        ArrayList<StudyEventDataBean> studyEventDataBeans = subjectDataBean.getStudyEventData();
        StudySubjectBean studySubjectBean = studySubjectDAO.findByOidAndStudy(subjectDataBean.getSubjectOID(), studyBean.getId());
        for (StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
            ArrayList<FormDataBean> formDataBeans = studyEventDataBean.getFormData();
            String sampleOrdinal = studyEventDataBean.getStudyEventRepeatKey() == null ? "1" : studyEventDataBean.getStudyEventRepeatKey();
            StudyEventDefinitionBean studyEventDefinitionBean = studyEventDefinitionDAO.findByOidAndStudy(studyEventDataBean.getStudyEventOID(), studyBean.getId(), studyBean.getParentStudyId());
            logger.info("find all by def and subject " + studyEventDefinitionBean.getName() + " study subject " + studySubjectBean.getName());
            StudyEventBean studyEventBean = (StudyEventBean) studyEventDAO.findByStudySubjectIdAndDefinitionIdAndOrdinal(studySubjectBean.getId(), studyEventDefinitionBean.getId(), Integer.parseInt(sampleOrdinal));
            // locked
            if (studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.LOCKED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.SIGNED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.STOPPED)) {
                return true;
            }
            for (FormDataBean formDataBean : formDataBeans) {
                CRFVersionDAO crfVersionDAO = new CRFVersionDAO(ds);
                ArrayList<CRFVersionBean> crfVersionBeans = crfVersionDAO.findAllByOid(formDataBean.getFormOID());
                for (CRFVersionBean crfVersionBean : crfVersionBeans) {
                    ArrayList<EventCRFBean> eventCrfBeans = eventCrfDAO.findByEventSubjectVersion(studyEventBean, studySubjectBean, crfVersionBean);
                    // event crf, yet.
                    if (eventCrfBeans.isEmpty()) {
                        logger.debug("   found no event crfs from Study Event id " + studyEventBean.getId() + ", location " + studyEventBean.getLocation());
                        if ((studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.SCHEDULED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.DATA_ENTRY_STARTED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.COMPLETED))) {
                            if (!upsert.isNotStarted())
                                return false;
                        }
                    }
                    for (EventCRFBean ecb : eventCrfBeans) {
                        Integer ecbId = new Integer(ecb.getId());
                        if (!(ecb.getStage().equals(DataEntryStage.INITIAL_DATA_ENTRY) && upsert.isDataEntryStarted()) && !(ecb.getStage().equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) && upsert.isDataEntryComplete()))
                            return false;
                    }
                }
            }
        }
    }
    return true;
}
Also used : UpsertOnBean(org.akaza.openclinica.bean.submit.crfdata.UpsertOnBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyEventDataBean(org.akaza.openclinica.bean.submit.crfdata.StudyEventDataBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) SubjectDataBean(org.akaza.openclinica.bean.submit.crfdata.SubjectDataBean) FormDataBean(org.akaza.openclinica.bean.submit.crfdata.FormDataBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean)

Example 40 with CRFVersionBean

use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.

the class ImportCRFDataService method fetchEventCRFBeans.

/*
     * purpose: look up EventCRFBeans by the following: Study Subject, Study Event, CRF Version, using the
     * findByEventSubjectVersion method in EventCRFDAO. May return more than one, hmm.
     */
public List<EventCRFBean> fetchEventCRFBeans(ODMContainer odmContainer, UserAccountBean ub) {
    ArrayList<EventCRFBean> eventCRFBeans = new ArrayList<EventCRFBean>();
    ArrayList<Integer> eventCRFBeanIds = new ArrayList<Integer>();
    EventCRFDAO eventCrfDAO = new EventCRFDAO(ds);
    StudySubjectDAO studySubjectDAO = new StudySubjectDAO(ds);
    StudyEventDefinitionDAO studyEventDefinitionDAO = new StudyEventDefinitionDAO(ds);
    StudyDAO studyDAO = new StudyDAO(ds);
    StudyEventDAO studyEventDAO = new StudyEventDAO(ds);
    UpsertOnBean upsert = odmContainer.getCrfDataPostImportContainer().getUpsertOn();
    // If Upsert bean is not present, create one with default settings
    if (upsert == null)
        upsert = new UpsertOnBean();
    String studyOID = odmContainer.getCrfDataPostImportContainer().getStudyOID();
    StudyBean studyBean = studyDAO.findByOid(studyOID);
    ArrayList<SubjectDataBean> subjectDataBeans = odmContainer.getCrfDataPostImportContainer().getSubjectData();
    for (SubjectDataBean subjectDataBean : subjectDataBeans) {
        ArrayList<StudyEventDataBean> studyEventDataBeans = subjectDataBean.getStudyEventData();
        StudySubjectBean studySubjectBean = studySubjectDAO.findByOidAndStudy(subjectDataBean.getSubjectOID(), studyBean.getId());
        for (StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
            ArrayList<FormDataBean> formDataBeans = studyEventDataBean.getFormData();
            String sampleOrdinal = studyEventDataBean.getStudyEventRepeatKey() == null ? "1" : studyEventDataBean.getStudyEventRepeatKey();
            StudyEventDefinitionBean studyEventDefinitionBean = studyEventDefinitionDAO.findByOidAndStudy(studyEventDataBean.getStudyEventOID(), studyBean.getId(), studyBean.getParentStudyId());
            logger.info("find all by def and subject " + studyEventDefinitionBean.getName() + " study subject " + studySubjectBean.getName());
            for (FormDataBean formDataBean : formDataBeans) {
                CRFVersionDAO crfVersionDAO = new CRFVersionDAO(ds);
                ArrayList<CRFVersionBean> crfVersionBeans = crfVersionDAO.findAllByOid(formDataBean.getFormOID());
                // studySubjectBean.getId(),Integer.parseInt(sampleOrdinal));
                for (CRFVersionBean crfVersionBean : crfVersionBeans) {
                    // iterate the studyeventbeans here
                    // for (StudyEventBean studyEventBean : studyEventBeans) {
                    StudyEventBean studyEventBean = (StudyEventBean) studyEventDAO.findByStudySubjectIdAndDefinitionIdAndOrdinal(studySubjectBean.getId(), studyEventDefinitionBean.getId(), Integer.parseInt(sampleOrdinal));
                    // locked
                    if (studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.LOCKED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.SIGNED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.STOPPED)) {
                        return null;
                    }
                    ArrayList<EventCRFBean> eventCrfBeans = eventCrfDAO.findByEventSubjectVersion(studyEventBean, studySubjectBean, crfVersionBean);
                    // event crf, yet.
                    if (eventCrfBeans.isEmpty()) {
                        logger.debug("   found no event crfs from Study Event id " + studyEventBean.getId() + ", location " + studyEventBean.getLocation());
                        // necessary, avoiding false-positives
                        if ((studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.SCHEDULED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.DATA_ENTRY_STARTED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.COMPLETED)) && upsert.isNotStarted()) {
                            EventCRFBean newEventCrfBean = new EventCRFBean();
                            newEventCrfBean.setStudyEventId(studyEventBean.getId());
                            newEventCrfBean.setStudySubjectId(studySubjectBean.getId());
                            newEventCrfBean.setCRFVersionId(crfVersionBean.getId());
                            newEventCrfBean.setDateInterviewed(new Date());
                            newEventCrfBean.setOwner(ub);
                            newEventCrfBean.setInterviewerName(ub.getName());
                            // place
                            newEventCrfBean.setCompletionStatusId(1);
                            // filler
                            newEventCrfBean.setStatus(Status.AVAILABLE);
                            newEventCrfBean.setStage(DataEntryStage.INITIAL_DATA_ENTRY);
                            // these will be updated later in the
                            // workflow
                            newEventCrfBean = (EventCRFBean) eventCrfDAO.create(newEventCrfBean);
                            // eventCrfBeans.add(newEventCrfBean);
                            logger.debug("   created and added new event crf");
                            if (!eventCRFBeanIds.contains(newEventCrfBean.getId())) {
                                eventCRFBeans.add(newEventCrfBean);
                                eventCRFBeanIds.add(newEventCrfBean.getId());
                            }
                        }
                    } else {
                    }
                    for (EventCRFBean ecb : eventCrfBeans) {
                        Integer ecbId = new Integer(ecb.getId());
                        if ((upsert.isDataEntryStarted() && ecb.getStage().equals(DataEntryStage.INITIAL_DATA_ENTRY)) || (upsert.isDataEntryComplete() && ecb.getStage().equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE)))
                            if (!eventCRFBeanIds.contains(ecbId)) {
                                eventCRFBeans.add(ecb);
                                eventCRFBeanIds.add(ecbId);
                            }
                    }
                }
            }
        }
    }
    // iteration one
    return eventCRFBeans;
}
Also used : UpsertOnBean(org.akaza.openclinica.bean.submit.crfdata.UpsertOnBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyEventDataBean(org.akaza.openclinica.bean.submit.crfdata.StudyEventDataBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) Date(java.util.Date) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) SubjectDataBean(org.akaza.openclinica.bean.submit.crfdata.SubjectDataBean) FormDataBean(org.akaza.openclinica.bean.submit.crfdata.FormDataBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean)

Aggregations

CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)100 ArrayList (java.util.ArrayList)70 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)61 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)54 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)53 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)46 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)44 HashMap (java.util.HashMap)38 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)37 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)36 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)36 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)33 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)32 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)30 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)30 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)29 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)25 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)22 Iterator (java.util.Iterator)20 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)20