Search in sources :

Example 21 with StudyDAO

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

the class RandomizeActionProcessor method getStudy.

private StudyBean getStudy(String oid) {
    sdao = new StudyDAO(ds);
    StudyBean studyBean = (StudyBean) sdao.findByOid(oid);
    return studyBean;
}
Also used : StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Example 22 with StudyDAO

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

the class OdmDataCollector method populateCompletedStudyBaseMap.

/**
 * Populate a HashMap<String, OdmStudyBase> of a study and its sites if
 * appliable, the key is study/site oc_oid.
 *
 * @param parentStudyId
 * @return
 */
public LinkedHashMap<String, OdmStudyBase> populateCompletedStudyBaseMap(int parentStudyId) {
    LinkedHashMap<String, OdmStudyBase> Bases = new LinkedHashMap<String, OdmStudyBase>();
    StudyDAO sdao = new StudyDAO(this.ds);
    for (StudyBean s : (ArrayList<StudyBean>) sdao.findAllByParentStudyIdOrderedByIdAsc(parentStudyId)) {
        Bases.put(s.getOid(), new OdmStudyBase(ds, s));
    }
    return Bases;
}
Also used : StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) LinkedHashMap(java.util.LinkedHashMap)

Example 23 with StudyDAO

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

the class ImportDataHelper method createEventCRF.

public EventCRFBean createEventCRF(HashMap<String, String> importedObject) {
    EventCRFBean eventCrfBean = null;
    int studyEventId = importedObject.get("study_event_id") == null ? -1 : Integer.parseInt(importedObject.get("study_event_id"));
    String crfVersionName = importedObject.get("crf_version_name") == null ? "" : importedObject.get("crf_version_name").toString();
    String crfName = importedObject.get("crf_name") == null ? "" : importedObject.get("crf_name").toString();
    String eventDefinitionCRFName = importedObject.get("event_definition_crf_name") == null ? "" : importedObject.get("event_definition_crf_name").toString();
    String subjectName = importedObject.get("subject_name") == null ? "" : importedObject.get("subject_name").toString();
    String studyName = importedObject.get("study_name") == null ? "" : importedObject.get("study_name").toString();
    logger.info("found the following: study event id " + studyEventId + ", crf version name " + crfVersionName + ", crf name " + crfName + ", event def crf name " + eventDefinitionCRFName + ", subject name " + subjectName + ", study name " + studyName);
    // << tbh
    int eventCRFId = 0;
    EventCRFDAO eventCrfDao = new EventCRFDAO(sm.getDataSource());
    StudyDAO studyDao = new StudyDAO(sm.getDataSource());
    StudySubjectDAO studySubjectDao = new StudySubjectDAO(sm.getDataSource());
    StudyEventDefinitionDAO studyEventDefinistionDao = new StudyEventDefinitionDAO(sm.getDataSource());
    CRFVersionDAO crfVersionDao = new CRFVersionDAO(sm.getDataSource());
    StudyEventDAO studyEventDao = new StudyEventDAO(sm.getDataSource());
    CRFDAO crfdao = new CRFDAO(sm.getDataSource());
    SubjectDAO subjectDao = new SubjectDAO(sm.getDataSource());
    StudyBean studyBean = (StudyBean) studyDao.findByName(studyName);
    // .findByPK(studyId);
    // generate the subject bean first, so that we can have the subject id
    // below...
    SubjectBean subjectBean = // .findByUniqueIdentifierAndStudy(subjectName,
    subjectDao.findByUniqueIdentifier(subjectName);
    StudySubjectBean studySubjectBean = studySubjectDao.findBySubjectIdAndStudy(subjectBean.getId(), studyBean);
    // .findByLabelAndStudy(subjectName, studyBean);
    logger.info("::: found study subject id here: " + studySubjectBean.getId() + " with the following: subject ID " + subjectBean.getId() + " study bean name " + studyBean.getName());
    StudyEventBean studyEventBean = (StudyEventBean) studyEventDao.findByPK(studyEventId);
    // TODO need to replace, can't really replace
    logger.info("found study event status: " + studyEventBean.getStatus().getName());
    // [study] event should be scheduled, event crf should be not started
    CRFVersionBean crfVersion = (CRFVersionBean) crfVersionDao.findByFullName(crfVersionName, crfName);
    // .findByPK(crfVersionId);
    // replaced by findByName(name, version)
    logger.info("found crf version name here: " + crfVersion.getName());
    EntityBean crf = crfdao.findByPK(crfVersion.getCrfId());
    logger.info("found crf name here: " + crf.getName());
    // trying it again up here since down there doesn't seem to work, tbh
    StudyEventDefinitionBean studyEventDefinitionBean = (StudyEventDefinitionBean) studyEventDefinistionDao.findByName(eventDefinitionCRFName);
    if (studySubjectBean.getId() <= 0 && studyEventBean.getId() <= 0 && crfVersion.getId() <= 0 && studyBean.getId() <= 0 && studyEventDefinitionBean.getId() <= 0) {
        logger.info("Throw an Exception, One of the provided ids is not valid");
    }
    // >> tbh repeating items:
    ArrayList eventCrfBeans = eventCrfDao.findByEventSubjectVersion(studyEventBean, studySubjectBean, crfVersion);
    // TODO repeating items here? not yet
    if (eventCrfBeans.size() > 1) {
        logger.info("found more than one");
    }
    if (!eventCrfBeans.isEmpty() && eventCrfBeans.size() == 1) {
        eventCrfBean = (EventCRFBean) eventCrfBeans.get(0);
        logger.info("This EventCrfBean was found");
    }
    if (!eventCrfBeans.isEmpty() && eventCrfBeans.size() > 1) {
        logger.info("Throw a System exception , result should either be 0 or 1");
    }
    if (eventCrfBean == null) {
        StudyBean studyWithSED = studyBean;
        if (studyBean.getParentStudyId() > 0) {
            studyWithSED = new StudyBean();
            studyWithSED.setId(studyBean.getParentStudyId());
        }
        AuditableEntityBean studyEvent = studyEventDao.findByPKAndStudy(studyEventId, studyWithSED);
        if (studyEvent.getId() <= 0) {
            logger.info("Hello Exception");
        }
        eventCrfBean = new EventCRFBean();
        // eventCrfBean.setCrfVersion(crfVersion);
        if (eventCRFId == 0) {
            // ???
            if (studyBean.getStudyParameterConfig().getInterviewerNameDefault().equals("blank")) {
                eventCrfBean.setInterviewerName("");
            } else {
                // default will be event's owner name
                eventCrfBean.setInterviewerName(studyEventBean.getOwner().getName());
            }
            if (!studyBean.getStudyParameterConfig().getInterviewDateDefault().equals("blank")) {
                if (studyEventBean.getDateStarted() != null) {
                    // default
                    eventCrfBean.setDateInterviewed(studyEventBean.getDateStarted());
                // date
                } else {
                    // logger.info("evnet start date is null, so date
                    // interviewed is null");
                    eventCrfBean.setDateInterviewed(null);
                }
            } else {
                eventCrfBean.setDateInterviewed(null);
            }
            eventCrfBean.setAnnotations("");
            eventCrfBean.setCreatedDate(new Date());
            eventCrfBean.setCRFVersionId(crfVersion.getId());
            // eventCrfBean.setCrfVersion((CRFVersionBean)crfVersion);
            eventCrfBean.setOwner(ub);
            // eventCrfBean.setCrf((CRFBean)crf);
            eventCrfBean.setStatus(Status.AVAILABLE);
            eventCrfBean.setCompletionStatusId(1);
            // problem with the line below
            eventCrfBean.setStudySubjectId(studySubjectBean.getId());
            eventCrfBean.setStudyEventId(studyEventId);
            eventCrfBean.setValidateString("");
            eventCrfBean.setValidatorAnnotations("");
            try {
                eventCrfBean = (EventCRFBean) eventCrfDao.create(eventCrfBean);
            // TODO review
            // eventCrfBean.setCrfVersion((CRFVersionBean)crfVersion);
            // eventCrfBean.setCrf((CRFBean)crf);
            } catch (Exception ee) {
                logger.info(ee.getMessage());
                logger.info("throws with crf version id " + crfVersion.getId() + " and study event id " + studyEventId + " study subject id " + studySubjectBean.getId());
            }
        // note that you need to catch an exception if the numbers are
        // bogus, ie you can throw an error here
        // however, putting the try catch allows you to pass which is
        // also bad
        // logger.info("CREATED EVENT CRF");
        } else {
            // there is an event CRF already, only need to update
            // is the status not started???
            logger.info("*** already-started event CRF with msg: " + eventCrfBean.getStatus().getName());
            if (eventCrfBean.getStatus().equals(Status.PENDING)) {
                logger.info("Not Started???");
            }
            eventCrfBean = (EventCRFBean) eventCrfDao.findByPK(eventCRFId);
            eventCrfBean.setCRFVersionId(crfVersion.getId());
            eventCrfBean.setUpdatedDate(new Date());
            eventCrfBean.setUpdater(ub);
            eventCrfBean = (EventCRFBean) eventCrfDao.update(eventCrfBean);
        // eventCrfBean.setCrfVersion((CRFVersionBean)crfVersion);
        // eventCrfBean.setCrf((CRFBean)crf);
        }
        if (eventCrfBean.getId() <= 0) {
            logger.info("error");
        } else {
            // TODO change status here, tbh
            // 2/08 this part seems to work, tbh
            studyEventBean.setSubjectEventStatus(SubjectEventStatus.DATA_ENTRY_STARTED);
            studyEventBean.setUpdater(ub);
            studyEventBean.setUpdatedDate(new Date());
            studyEventDao.update(studyEventBean);
        }
    }
    eventCrfBean.setCrfVersion(crfVersion);
    eventCrfBean.setCrf((CRFBean) crf);
    // repeating?
    return eventCrfBean;
}
Also used : EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) AuditableEntityBean(org.akaza.openclinica.bean.core.AuditableEntityBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) 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) Date(java.util.Date) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) EntityBean(org.akaza.openclinica.bean.core.EntityBean) AuditableEntityBean(org.akaza.openclinica.bean.core.AuditableEntityBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 24 with StudyDAO

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

the class DiscrepancyNoteUtil method getThreadedDNotesForStudy.

/**
 * Get all discrepancy notes for a study, including "threads" of parent and
 * child discrepancy notes.
 *
 * @param currentStudy
 *            A StudyBean object.
 * @param resolutionStatusIds
 *            A HashSet object consisting of resolution status ids (i.e.,
 *            1,2,3).
 * @param dataSource
 *            A DataSource used for various DAO methods.
 * @param discNoteType
 *            An int discrepancy note type id; only DiscrepancyNoteBeans
 *            will be returned if they have this discrepancyNoteTypeId.
 * @param updateStatusOfParents
 * @return A List of DiscrepancyNoteBeans.
 */
public List<DiscrepancyNoteBean> getThreadedDNotesForStudy(StudyBean currentStudy, Set<Integer> resolutionStatusIds, DataSource dataSource, int discNoteType, boolean updateStatusOfParents) {
    List<DiscrepancyNoteBean> allDiscNotes = new ArrayList<DiscrepancyNoteBean>();
    if (currentStudy == null)
        return allDiscNotes;
    // Do the returned DN's have to be filtered? A valid resolution status
    // has to be between 1 and 5; 0 is "invalid";
    // -1 means that no resolutionStatus parameter was passed into the
    // servlet
    boolean filterDiscNotes = checkResolutionStatus(resolutionStatusIds);
    boolean filterforDiscNoteType = discNoteType >= 1 && discNoteType <= 4;
    DiscrepancyNoteDAO discrepancyNoteDAO = new DiscrepancyNoteDAO(dataSource);
    StudyDAO studyDAO = new StudyDAO(dataSource);
    // what is the purpose of this data member?
    discrepancyNoteDAO.setFetchMapping(true);
    int parentStudyId = currentStudy.getParentStudyId();
    Set<String> hiddenCrfNames = new TreeSet<String>();
    if (parentStudyId > 0) {
        hiddenCrfNames = new EventDefinitionCRFDAO(dataSource).findHiddenCrfNamesBySite(currentStudy);
    }
    allDiscNotes = discrepancyNoteDAO.findAllDiscrepancyNotesDataByStudy(currentStudy);
    if (filterDiscNotes) {
        // filter for the resolution status
        allDiscNotes = filterDiscNotes(allDiscNotes, resolutionStatusIds);
    }
    if (filterforDiscNoteType) {
        // filter for the ddiscrepancyNoteTypeId
        allDiscNotes = filterforDiscNoteType(allDiscNotes, discNoteType);
    }
    return allDiscNotes;
}
Also used : DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Example 25 with StudyDAO

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

the class RandomizeService method getStudySubjectAttrValue.

private String getStudySubjectAttrValue(String expr, EventCRFBean eventCrfBean, RuleSetBean ruleSet) {
    String value = "";
    StudySubjectDAO<String, ArrayList> ssdao = new StudySubjectDAO<>(ds);
    SubjectDAO subdao = new SubjectDAO(ds);
    StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(ds);
    StudyGroupDAO sgdao = new StudyGroupDAO(ds);
    StudyDAO<String, ArrayList> sdao = new StudyDAO<>(ds);
    StudySubjectBean ssBean = (StudySubjectBean) ssdao.findByPK(eventCrfBean.getStudySubjectId());
    SubjectBean subjectBean = (SubjectBean) subdao.findByPK(ssBean.getSubjectId());
    String prefix = "STUDYGROUPCLASSLIST";
    String param = expr.split("\\.", -1)[1].trim();
    if (param.equalsIgnoreCase("BIRTHDATE")) {
        value = subjectBean.getDateOfBirth().toString();
    } else if (param.equalsIgnoreCase("SEX")) {
        if (String.valueOf(subjectBean.getGender()).equals("m"))
            value = "Male";
        else
            value = "Female";
    // value =String.valueOf(ssBean.getGender());
    } else if (param.startsWith(prefix)) {
        String gcName = param.substring(21, param.indexOf("\"]"));
        StudyGroupBean sgBean = sgdao.findSubjectStudyGroup(ssBean.getId(), gcName);
        if (sgBean != null)
            value = sgBean.getName();
    }
    return value;
}
Also used : SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) StudyGroupClassDAO(org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO) ArrayList(java.util.ArrayList) StudyGroupDAO(org.akaza.openclinica.dao.managestudy.StudyGroupDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) StudyGroupBean(org.akaza.openclinica.bean.managestudy.StudyGroupBean)

Aggregations

StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)205 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)184 ArrayList (java.util.ArrayList)116 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)73 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)59 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)57 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)50 Date (java.util.Date)49 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)49 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)47 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)46 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)45 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)43 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)43 HashMap (java.util.HashMap)42 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)39 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)37 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)35 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)34 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)30