Search in sources :

Example 6 with EntityBean

use of org.akaza.openclinica.bean.core.EntityBean in project OpenClinica by OpenClinica.

the class EntityDAO method executeFindByPKQuery.

/**
     * This method executes a "findByPK-style" query. Such a query has two characteristics:
     * <ol>
     * <li>The columns SELECTed by the SQL are all of the columns in the table relevant to the DAO, and only those columns. (e.g., in StudyDAO, the columns
     * SELECTed are all of the columns in the study table, and only those columns.)
     * <li>It returns at most one EntityBean.
     * <ul>
     * <li>Typically this means that the WHERE clause includes the columns in a candidate key with "=" criteria.
     * <li>e.g., "WHERE item_id = ?" when selecting from item
     * <li>e.g., "WHERE item_id = ? AND event_crf_id=?" when selecting from item_data
     * </ol>
     *
     * Note that queries which join two tables may be included in the definition of "findByPK-style" query, as long as the first criterion is met.
     *
     * @param queryName
     *            The name of the query which should be executed.
     * @param variables
     *            The set of variables used to populate the PreparedStatement; should be empty if none are needed.
     * @return The EntityBean selected by the query.
     */
public EntityBean executeFindByPKQuery(String queryName, HashMap variables) {
    EntityBean answer = new EntityBean();
    String sql = digester.getQuery(queryName);
    logMe("query:" + queryName + "variables:" + variables);
    ArrayList rows;
    if (variables == null || variables.isEmpty()) {
        rows = this.select(sql);
    } else {
        rows = this.select(sql, variables);
    }
    Iterator it = rows.iterator();
    if (it.hasNext()) {
        answer = (EntityBean) this.getEntityFromHashMap((HashMap) it.next());
    }
    return answer;
}
Also used : EntityBean(org.akaza.openclinica.bean.core.EntityBean) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Example 7 with EntityBean

use of org.akaza.openclinica.bean.core.EntityBean in project OpenClinica by OpenClinica.

the class StudyEventDAO method getEventsAndMultipleCRFVersionInformation.

/**
     * Using the HashMaps returned from a <code>select</code> call in
     * findCRFsByStudy, prepare a HashMap whose keys are study event definitions
     * and whose values are ArrayLists of CRF versions included in those
     * definitions.
     *
     * @param rows
     *            The HashMaps retured by the <code>select</code> call in
     *            findCRFsByStudy.
     * @return a HashMap whose keys are study event definitions and whose values
     *         are ArrayLists of CRF versions included in those definitions.
     *         Both the keys of the HashMap and the elements of the ArrayLists
     *         are actually EntitBeans.
     */
public HashMap getEventsAndMultipleCRFVersionInformation(ArrayList rows) {
    HashMap returnMe = new HashMap();
    Iterator it = rows.iterator();
    EntityBean event = new EntityBean();
    EntityBean crf = new EntityBean();
    EntityBean version = new EntityBean();
    while (it.hasNext()) {
        HashMap answers = (HashMap) it.next();
        // removed setActive since the setId calls automatically result in
        // setActive calls
        event = new EntityBean();
        event.setName((String) answers.get("sed_name"));
        event.setId(((Integer) answers.get("study_event_definition_id")).intValue());
        crf = new EntityBean();
        crf.setName((String) answers.get("crf_name") + " " + (String) answers.get("ver_name"));
        crf.setId(((Integer) answers.get("crf_version_id")).intValue());
        ArrayList crfs = new ArrayList();
        if (this.findDouble(returnMe, event)) {
            // (returnMe.containsKey(event))
            // {
            // TODO create custom checker, this does not work
            // logger.warn("putting a crf into an OLD event: " +
            // crf.getName() + " into "
            // + event.getName());
            // logger.warn("just entered the if statement");
            // (ArrayList)
            crfs = this.returnDouble(returnMe, event);
            // returnMe.get(event);
            // logger.warn("just got the array list from the hashmap");
            crfs.add(crf);
            // logger.warn("just added the crf to the array list");
            returnMe = this.removeDouble(returnMe, event);
            // .remove(event);
            // not sure the above will work, tbh
            returnMe.put(event, crfs);
        } else {
            crfs = new ArrayList();
            logger.warn("put a crf into a NEW event: " + crf.getName() + " into " + event.getName());
            crfs.add(crf);
            // maybe combine the two crf +
            returnMe.put(event, crfs);
        // version?
        }
    }
    return returnMe;
}
Also used : HashMap(java.util.HashMap) EntityBean(org.akaza.openclinica.bean.core.EntityBean) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList)

Example 8 with EntityBean

use of org.akaza.openclinica.bean.core.EntityBean in project OpenClinica by OpenClinica.

the class StudyEventDAO method getEventAndCRFVersionInformation.

// TODO: decide whether to use getEventsAndMultipleCRFVersionInformation
// instead of this method
public HashMap getEventAndCRFVersionInformation(ArrayList al) {
    HashMap returnMe = new HashMap();
    Iterator it = al.iterator();
    EntityBean event = new EntityBean();
    EntityBean crf = new EntityBean();
    EntityBean version = new EntityBean();
    while (it.hasNext()) {
        HashMap answers = (HashMap) it.next();
        logger.warn("***Study Event Def ID: " + answers.get("study_event_definition_id"));
        logger.warn("***CRF ID: " + answers.get("crf_id"));
        logger.warn("***CRFVersion ID: " + answers.get("crf_version_id"));
        event = new EntityBean();
        event.setActive(true);
        event.setName((String) answers.get("sed_name"));
        event.setId(((Integer) answers.get("study_event_definition_id")).intValue());
        crf = new EntityBean();
        crf.setActive(true);
        crf.setName((String) answers.get("crf_name") + " " + (String) answers.get("ver_name"));
        crf.setId(((Integer) answers.get("crf_version_id")).intValue());
        // maybe combine the two crf + version?
        returnMe.put(event, crf);
    }
    return returnMe;
}
Also used : HashMap(java.util.HashMap) EntityBean(org.akaza.openclinica.bean.core.EntityBean) Iterator(java.util.Iterator)

Example 9 with EntityBean

use of org.akaza.openclinica.bean.core.EntityBean in project OpenClinica by OpenClinica.

the class DataEntryServlet method createEventCRF.

/**
     * Creates a new Event CRF or update the exsiting one, that is, an event CRF can be created but not item data yet, in this case, still consider it is not
     * started(called uncompleted before)
     * @param request TODO
     * @param fp TODO
     *
     * @return
     * @throws Exception
     */
private EventCRFBean createEventCRF(HttpServletRequest request, FormProcessor fp) throws InconsistentStateException {
    locale = LocaleResolver.getLocale(request);
    // < resmessage =
    // ResourceBundle.getBundle("org.akaza.openclinica.i18n.page_messages",
    // locale);
    // < restext =
    // ResourceBundle.getBundle("org.akaza.openclinica.i18n.notes",locale);
    // <
    // resexception=ResourceBundle.getBundle(
    // "org.akaza.openclinica.i18n.exceptions",locale);
    UserAccountBean ub = (UserAccountBean) request.getSession().getAttribute(USER_BEAN_NAME);
    StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
    EventCRFBean ecb;
    EventCRFDAO ecdao = new EventCRFDAO(getDataSource());
    int crfVersionId = fp.getInt(INPUT_CRF_VERSION_ID);
    LOGGER.trace("***FOUND*** crfversionid: " + crfVersionId);
    int studyEventId = fp.getInt(INPUT_STUDY_EVENT_ID);
    int eventDefinitionCRFId = fp.getInt(INPUT_EVENT_DEFINITION_CRF_ID);
    int subjectId = fp.getInt(INPUT_SUBJECT_ID);
    int eventCRFId = fp.getInt(INPUT_EVENT_CRF_ID);
    LOGGER.trace("look specifically wrt event crf id: " + eventCRFId);
    LOGGER.trace("Creating event CRF.  Study id: " + currentStudy.getId() + "; CRF Version id: " + crfVersionId + "; Study Event id: " + studyEventId + "; Event Definition CRF id: " + eventDefinitionCRFId + "; Subject: " + subjectId);
    StudySubjectDAO ssdao = new StudySubjectDAO(getDataSource());
    StudySubjectBean ssb = ssdao.findBySubjectIdAndStudy(subjectId, currentStudy);
    if (ssb.getId() <= 0) {
        LOGGER.trace("throwing ISE with study subject bean id of " + ssb.getId());
        // "begin_data_entry_without_event_but_subject"));
        throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("begin_data_entry_without_event_but_subject"));
    }
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(getDataSource());
    StudyEventDefinitionBean sedb = seddao.findByEventDefinitionCRFId(eventDefinitionCRFId);
    // logger.trace("study event definition:" + sedb.getId());
    if (sedb.getId() <= 0) {
        addPageMessage(resexception.getString("begin_data_entry_without_event_but_study"), request);
        throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("begin_data_entry_without_event_but_study"));
    }
    CRFVersionDAO cvdao = new CRFVersionDAO(getDataSource());
    EntityBean eb = cvdao.findByPK(crfVersionId);
    if (eb.getId() <= 0) {
        //addPageMessage(resexception.getString("begin_data_entry_without_event_but_CRF"));
        throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("begin_data_entry_without_event_but_CRF"));
    }
    StudyEventDAO sedao = new StudyEventDAO(getDataSource());
    StudyEventBean sEvent = (StudyEventBean) sedao.findByPK(studyEventId);
    StudyBean studyWithSED = currentStudy;
    if (currentStudy.getParentStudyId() > 0) {
        studyWithSED = new StudyBean();
        studyWithSED.setId(currentStudy.getParentStudyId());
    }
    AuditableEntityBean aeb = sedao.findByPKAndStudy(studyEventId, studyWithSED);
    if (aeb.getId() <= 0) {
        addPageMessage(resexception.getString("begin_data_entry_without_event_but_especified_event"), request);
        throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("begin_data_entry_without_event_but_especified_event"));
    }
    ecb = new EventCRFBean();
    if (eventCRFId == 0) {
        // no event CRF created yet
        ArrayList ecList = ecdao.findByEventSubjectVersion(sEvent, ssb, (CRFVersionBean) eb);
        if (ecList.size() > 0) {
            ecb = (EventCRFBean) ecList.get(0);
        } else {
            ecb.setAnnotations("");
            ecb.setCreatedDate(new Date());
            ecb.setCRFVersionId(crfVersionId);
            if (currentStudy.getStudyParameterConfig().getInterviewerNameDefault().equals("blank")) {
                ecb.setInterviewerName("");
            } else {
                // default will be event's owner name
                ecb.setInterviewerName(sEvent.getOwner().getName());
            }
            if (!currentStudy.getStudyParameterConfig().getInterviewDateDefault().equals("blank")) {
                if (sEvent.getDateStarted() != null) {
                    // default
                    ecb.setDateInterviewed(sEvent.getDateStarted());
                // date
                } else {
                    // logger.trace("evnet start date is null, so date
                    // interviewed is null");
                    ecb.setDateInterviewed(null);
                }
            } else {
                ecb.setDateInterviewed(null);
            // logger.trace("date interviewed is
            // null,getInterviewDateDefault() is blank");
            }
            // ecb.setOwnerId(ub.getId());
            // above depreciated, try without it, tbh
            ecb.setOwner(ub);
            ecb.setStatus(Status.AVAILABLE);
            ecb.setCompletionStatusId(1);
            ecb.setStudySubjectId(ssb.getId());
            ecb.setStudyEventId(studyEventId);
            ecb.setValidateString("");
            ecb.setValidatorAnnotations("");
            ecb = (EventCRFBean) ecdao.create(ecb);
            LOGGER.debug("*********CREATED EVENT CRF");
        }
    } else {
        // there is an event CRF already, only need to update
        ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
        ecb.setCRFVersionId(crfVersionId);
        ecb.setUpdatedDate(new Date());
        ecb.setUpdater(ub);
        ecb = updateECB(sEvent, request);
        ecb = (EventCRFBean) ecdao.update(ecb);
    }
    if (ecb.getId() <= 0) {
        addPageMessage(resexception.getString("new_event_CRF_not_created"), request);
        throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("new_event_CRF_not_created"));
    } else {
        if (sEvent.getSubjectEventStatus().equals(SubjectEventStatus.SIGNED)) {
            sEvent.setSubjectEventStatus(SubjectEventStatus.COMPLETED);
            sEvent.setUpdater(ub);
            sEvent.setUpdatedDate(new Date());
            sedao.update(sEvent);
        } else {
            sEvent.setSubjectEventStatus(SubjectEventStatus.DATA_ENTRY_STARTED);
            sEvent.setUpdater(ub);
            sEvent.setUpdatedDate(new Date());
            sedao.update(sEvent);
        }
    }
    return ecb;
}
Also used : CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) AuditableEntityBean(org.akaza.openclinica.bean.core.AuditableEntityBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) InconsistentStateException(org.akaza.openclinica.web.InconsistentStateException) Date(java.util.Date) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) EntityBean(org.akaza.openclinica.bean.core.EntityBean) AuditableEntityBean(org.akaza.openclinica.bean.core.AuditableEntityBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 10 with EntityBean

use of org.akaza.openclinica.bean.core.EntityBean in project OpenClinica by OpenClinica.

the class TableOfContentsServlet method createEventCRF.

/**
     * Creates a new Event CRF or update the exsiting one, that is, an event CRF
     * can be created but not item data yet, in this case, still consider it is
     * not started(called uncompleted before)
     * 
     * @return
     * @throws Exception
     */
private EventCRFBean createEventCRF() throws Exception {
    EventCRFBean ecb;
    ecdao = new EventCRFDAO(sm.getDataSource());
    int crfVersionId = fp.getInt(INPUT_CRF_VERSION_ID);
    int studyEventId = fp.getInt(INPUT_STUDY_EVENT_ID);
    int eventDefinitionCRFId = fp.getInt(INPUT_EVENT_DEFINITION_CRF_ID);
    int subjectId = fp.getInt(INPUT_SUBJECT_ID);
    int eventCRFId = fp.getInt(INPUT_EVENT_CRF_ID);
    logger.info("Creating event CRF within Table of Contents.  Study id: " + currentStudy.getId() + "; CRF Version id: " + crfVersionId + "; Study Event id: " + studyEventId + "; Event Definition CRF id: " + eventDefinitionCRFId + "; Subject: " + subjectId);
    StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
    StudySubjectBean ssb = ssdao.findBySubjectIdAndStudy(subjectId, currentStudy);
    if (!ssb.isActive()) {
        throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("trying_to_begin_DE1"));
    }
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
    StudyEventDefinitionBean sedb = seddao.findByEventDefinitionCRFId(eventDefinitionCRFId);
    if (!ssb.isActive() || !sedb.isActive()) {
        throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("trying_to_begin_DE2"));
    }
    CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
    EntityBean eb = cvdao.findByPK(crfVersionId);
    if (!eb.isActive()) {
        throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("trying_to_begin_DE3"));
    }
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    StudyEventBean sEvent = (StudyEventBean) sedao.findByPK(studyEventId);
    StudyBean studyWithSED = currentStudy;
    if (currentStudy.getParentStudyId() > 0) {
        studyWithSED = new StudyBean();
        studyWithSED.setId(currentStudy.getParentStudyId());
    }
    AuditableEntityBean aeb = sedao.findByPKAndStudy(studyEventId, studyWithSED);
    if (!aeb.isActive()) {
        throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("trying_to_begin_DE4"));
    }
    ecb = new EventCRFBean();
    if (eventCRFId == 0) {
        // no event CRF created yet
        ecb.setAnnotations("");
        ecb.setCreatedDate(new Date());
        ecb.setCRFVersionId(crfVersionId);
        ecb.setInterviewerName("");
        if (sEvent.getDateStarted() != null) {
            // default date
            ecb.setDateInterviewed(sEvent.getDateStarted());
        } else {
            ecb.setDateInterviewed(null);
        }
        ecb.setOwnerId(ub.getId());
        ecb.setStatus(Status.AVAILABLE);
        ecb.setCompletionStatusId(1);
        ecb.setStudySubjectId(ssb.getId());
        ecb.setStudyEventId(studyEventId);
        ecb.setValidateString("");
        ecb.setValidatorAnnotations("");
        ecb = (EventCRFBean) ecdao.create(ecb);
        logger.info("CREATED EVENT CRF");
    } else {
        // there is an event CRF already, only need to update
        ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
        ecb.setCRFVersionId(crfVersionId);
        ecb.setUpdatedDate(new Date());
        ecb.setUpdater(ub);
        ecb = (EventCRFBean) ecdao.update(ecb);
    }
    if (!ecb.isActive()) {
        throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("new_event_CRF_not_created_database_error"));
    } else {
        sEvent.setSubjectEventStatus(SubjectEventStatus.DATA_ENTRY_STARTED);
        sEvent.setUpdater(ub);
        sEvent.setUpdatedDate(new Date());
        sedao.update(sEvent);
    }
    return ecb;
}
Also used : CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) AuditableEntityBean(org.akaza.openclinica.bean.core.AuditableEntityBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) InconsistentStateException(org.akaza.openclinica.web.InconsistentStateException) Date(java.util.Date) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) EntityBean(org.akaza.openclinica.bean.core.EntityBean) AuditableEntityBean(org.akaza.openclinica.bean.core.AuditableEntityBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Aggregations

EntityBean (org.akaza.openclinica.bean.core.EntityBean)20 HashMap (java.util.HashMap)10 ArrayList (java.util.ArrayList)7 Iterator (java.util.Iterator)7 AuditableEntityBean (org.akaza.openclinica.bean.core.AuditableEntityBean)4 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)4 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)4 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)4 Date (java.util.Date)3 Map (java.util.Map)3 Set (java.util.Set)3 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)3 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)3 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)3 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)3 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)3 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)3 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)3 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)3 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)2