Search in sources :

Example 51 with StudySubjectDAO

use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.

the class RandomizeService method getRandomizationCode.

// Rest Call to OCUI to get Randomization
public String getRandomizationCode(EventCRFBean eventCrfBean, List<StratificationFactorBean> stratificationFactorBeans, RuleSetBean ruleSet) throws JSONException {
    StudySubjectDAO ssdao = new StudySubjectDAO<>(ds);
    StudySubjectBean ssBean = (StudySubjectBean) ssdao.findByPK(eventCrfBean.getStudySubjectId());
    // study subject oid
    String identifier = ssBean.getOid();
    StudyDAO sdao = new StudyDAO<>(ds);
    StudyBean sBean = (StudyBean) sdao.findByPK(ssBean.getStudyId());
    // site or study oid
    String siteIdentifier = sBean.getOid();
    // site or study name
    String name = sBean.getName();
    UserAccountDAO udao = new UserAccountDAO(ds);
    int userId = 0;
    if (eventCrfBean.getUpdaterId() == 0) {
        userId = eventCrfBean.getOwnerId();
    } else {
        userId = eventCrfBean.getUpdaterId();
    }
    UserAccountBean uBean = (UserAccountBean) udao.findByPK(userId);
    String user = uBean.getName();
    // sBean should be parent study
    // put randomization object in cache
    StudyBean study = getParentStudy(sBean.getOid());
    SeRandomizationDTO randomization = null;
    try {
        randomization = getCachedRandomizationDTOObject(study.getOid(), false);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    String randomiseUrl = randomization.getUrl();
    String username = randomization.getUsername();
    String password = randomization.getPassword();
    String timezone = "America/New_York";
    // String randomiseUrl = "https://evaluation.sealedenvelope.com/redpill/seti2";
    // String username = "oc";
    // String password = "secret";
    HttpHeaders headers = createHeaders(username, password);
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    // retrieve json object if Randomization exist ,otherwise return a null object
    JSONObject jsonRandObject = retrieveARandomisation(randomiseUrl, ssBean, headers);
    if (jsonRandObject != null) {
        return (String) jsonRandObject.get("code");
    } else {
        // if Site identifier exists ,then update otherwise create new Site identifier
        addOrUpdateASite(randomiseUrl, sBean, headers, timezone);
        // send for Randomization
        JSONObject jsonRandomisedObject = randomiseSubject(randomiseUrl, ssBean, sBean, headers, user, stratificationFactorBeans, eventCrfBean, ruleSet);
        if (jsonRandomisedObject != null)
            return (String) jsonRandomisedObject.get("code");
        else
            return "";
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) JSONObject(org.json.JSONObject) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) SeRandomizationDTO(org.akaza.openclinica.service.pmanage.SeRandomizationDTO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) JSONException(org.json.JSONException)

Example 52 with StudySubjectDAO

use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.

the class DiscrepancyNoteUtil method getStudySubjectIdForDiscNote.

public int getStudySubjectIdForDiscNote(DiscrepancyNoteBean discrepancyNoteBean, DataSource dataSource, int studyId) {
    if (discrepancyNoteBean == null)
        return 0;
    StudySubjectDAO studySubjectDAO = new StudySubjectDAO(dataSource);
    List<StudySubjectBean> studySubjectBeans = new ArrayList<StudySubjectBean>();
    if ("subject".equalsIgnoreCase(discrepancyNoteBean.getEntityType())) {
        studySubjectBeans = studySubjectDAO.findAllBySubjectId(discrepancyNoteBean.getEntityId());
        for (StudySubjectBean bean : studySubjectBeans) {
            if (bean.getStudyId() == studyId) {
                return bean.getId();
            } else {
                if (((StudyBean) new StudyDAO(dataSource).findByPK(bean.getStudyId())).getParentStudyId() == studyId) {
                    return bean.getId();
                }
            }
        }
    } else if ("studySub".equalsIgnoreCase(discrepancyNoteBean.getEntityType())) {
        return discrepancyNoteBean.getEntityId();
    }
    return 0;
}
Also used : StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) ArrayList(java.util.ArrayList) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Example 53 with StudySubjectDAO

use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.

the class DiscrepancyNoteUtil method injectDiscNotesIntoStudyEvents.

/**
     * This method links discrepancy notes to the study event and study subject
     * associated with those notes
     *
     * @param studyBeans
     *            A List of StudyEventBeans.
     * @param allDiscNotes
     *            A List of DiscrepancyNoteBeans associated with a single study.
     * @param dataSource
     *            A DataSource used to get from the database a study subject
     *            associated with a study event.
     */
public void injectDiscNotesIntoStudyEvents(List<StudyEventBean> studyBeans, List<DiscrepancyNoteBean> allDiscNotes, DataSource dataSource) {
    if (studyBeans == null || allDiscNotes == null) {
        return;
    }
    StudySubjectDAO studySubjDAO = new StudySubjectDAO(dataSource);
    StudySubjectBean studySubjBean = new StudySubjectBean();
    for (StudyEventBean sbean : studyBeans) {
        // Get the StudySubjectBean associated with the study event
        studySubjBean = (StudySubjectBean) studySubjDAO.findByPK(sbean.getStudySubjectId());
        // equals the StudySubjectBean's name
        for (DiscrepancyNoteBean discBean : allDiscNotes) {
            if (sbean.getStudyEventDefinition().getName().equalsIgnoreCase(discBean.getEventName()) && studySubjBean.getLabel().equalsIgnoreCase(discBean.getSubjectName())) {
                // add discrepancy note to the study event list of notes
                // Each study bean has a List property containing its
                // associated
                // DiscrepancyNoteBeans
                sbean.getDiscBeanList().add(discBean);
            }
        }
    }
}
Also used : StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO)

Example 54 with StudySubjectDAO

use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.

the class ClinicalDataCollector method collectOdmClinicalDataMap.

public void collectOdmClinicalDataMap() {
    Iterator<OdmStudyBase> it = this.getStudyBaseMap().values().iterator();
    while (it.hasNext()) {
        JobTerminationMonitor.check();
        OdmStudyBase u = it.next();
        ClinicalDataUnit cdata = new ClinicalDataUnit(this.ds, this.dataset, this.getOdmbean(), u.getStudy(), this.getCategory());
        cdata.setCategory(this.getCategory());
        StudySubjectDAO ssdao = new StudySubjectDAO(this.ds);
        cdata.setStudySubjectIds(ssdao.findStudySubjectIdsByStudyIds(u.getStudy().getId() + ""));
        cdata.collectOdmClinicalData();
        odmClinicalDataMap.put(u.getStudy().getOid(), cdata.getOdmClinicalData());
    }
}
Also used : StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO)

Example 55 with StudySubjectDAO

use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.

the class DeleteCRFVersionServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    int versionId = fp.getInt(VERSION_ID, true);
    String action = request.getParameter("action");
    if (versionId == 0) {
        addPageMessage(respage.getString("please_choose_a_CRF_version_to_delete"));
        forwardPage(Page.CRF_LIST_SERVLET);
    } else {
        CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
        CRFDAO cdao = new CRFDAO(sm.getDataSource());
        EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
        StudyEventDefinitionDAO sedDao = new StudyEventDefinitionDAO(sm.getDataSource());
        StudyEventDAO seDao = new StudyEventDAO(sm.getDataSource());
        ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
        EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
        StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
        CRFVersionBean version = (CRFVersionBean) cvdao.findByPK(versionId);
        // find definitions using this version
        ArrayList definitions = edcdao.findByDefaultVersion(version.getId());
        for (Object edcBean : definitions) {
            StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) sedDao.findByPK(((EventDefinitionCRFBean) edcBean).getStudyEventDefinitionId());
            ((EventDefinitionCRFBean) edcBean).setEventName(sedBean.getName());
        }
        // find event crfs using this version
        ArrayList<ItemDataBean> idBeans = iddao.findByCRFVersion(version);
        ArrayList<EventCRFBean> eCRFs = ecdao.findAllByCRF(version.getCrfId());
        for (EventCRFBean eCRF : eCRFs) {
            StudySubjectBean ssBean = (StudySubjectBean) ssdao.findByPK(eCRF.getStudySubjectId());
            eCRF.setStudySubject(ssBean);
            StudyEventBean seBean = (StudyEventBean) seDao.findByPK(eCRF.getStudyEventId());
            StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) sedDao.findByPK(seBean.getStudyEventDefinitionId());
            seBean.setStudyEventDefinition(sedBean);
            eCRF.setStudyEvent(seBean);
        }
        ArrayList eventCRFs = ecdao.findAllByCRFVersion(versionId);
        boolean canDelete = true;
        if (!definitions.isEmpty()) {
            // used in definition
            canDelete = false;
            request.setAttribute("definitions", definitions);
            addPageMessage(respage.getString("this_CRF_version") + " " + version.getName() + respage.getString("has_associated_study_events_definitions_cannot_delete"));
        } else if (!idBeans.isEmpty()) {
            canDelete = false;
            request.setAttribute("eventCRFs", eCRFs);
            request.setAttribute("itemDataForVersion", idBeans);
            addPageMessage(respage.getString("this_CRF_version") + " " + version.getName() + respage.getString("has_associated_item_data_cannot_delete"));
        } else if (!eventCRFs.isEmpty()) {
            canDelete = false;
            request.setAttribute("eventsForVersion", eventCRFs);
            addPageMessage(respage.getString("this_CRF_version") + " " + version.getName() + respage.getString("has_associated_study_events_cannot_delete"));
        }
        if ("confirm".equalsIgnoreCase(action)) {
            request.setAttribute(VERSION_TO_DELETE, version);
            forwardPage(Page.DELETE_CRF_VERSION);
        } else {
            // submit
            if (canDelete) {
                ArrayList items = cvdao.findNotSharedItemsByVersion(versionId);
                NewCRFBean nib = new NewCRFBean(sm.getDataSource(), version.getCrfId());
                nib.setDeleteQueries(cvdao.generateDeleteQueries(versionId, items));
                nib.deleteFromDB();
                addPageMessage(respage.getString("the_CRF_version_has_been_deleted_succesfully"));
            } else {
                addPageMessage(respage.getString("the_CRF_version_cannot_be_deleted"));
            }
            forwardPage(Page.CRF_LIST_SERVLET);
        }
    }
}
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) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) NewCRFBean(org.akaza.openclinica.bean.admin.NewCRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Aggregations

StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)102 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)86 ArrayList (java.util.ArrayList)63 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)62 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)62 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)59 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)58 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)54 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)50 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)47 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)42 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)41 Date (java.util.Date)38 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)32 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)29 SubjectDAO (org.akaza.openclinica.dao.submit.SubjectDAO)27 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)26 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)24 SubjectBean (org.akaza.openclinica.bean.submit.SubjectBean)23 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)23