Search in sources :

Example 11 with StudyEvent

use of org.akaza.openclinica.domain.datamap.StudyEvent in project OpenClinica by OpenClinica.

the class ExpressionService method getStudyEventFromOID.

public StudyEvent getStudyEventFromOID(String oid) {
    Integer subjectId = expressionWrapper.getStudySubjectId();
    StudyEvent studyEvent = null;
    if (oid.contains("[")) {
        int leftBracketIndex = oid.indexOf("[");
        int rightBracketIndex = oid.indexOf("]");
        int ordinal = Integer.valueOf(oid.substring(leftBracketIndex + 1, rightBracketIndex));
        studyEvent = getStudyEventFromDb(oid.substring(0, leftBracketIndex), ordinal, subjectId);
    } else
        studyEvent = getStudyEventFromDb(oid, 1, subjectId);
    return studyEvent;
}
Also used : StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent)

Example 12 with StudyEvent

use of org.akaza.openclinica.domain.datamap.StudyEvent in project OpenClinica by OpenClinica.

the class EnketoFormServlet method processRequest.

@Override
protected void processRequest() throws Exception {
    FormLayoutDao formLayoutDao = (FormLayoutDao) SpringServletAccess.getApplicationContext(context).getBean("formLayoutDao");
    StudyEventDao studyEventDao = (StudyEventDao) SpringServletAccess.getApplicationContext(context).getBean("studyEventDaoDomain");
    EnketoUrlService enketoUrlService = (EnketoUrlService) SpringServletAccess.getApplicationContext(context).getBean("enketoUrlService");
    EnketoCredentials enketoCredentials = (EnketoCredentials) SpringServletAccess.getApplicationContext(context).getBean("enketoCredentials");
    String originatingPage = request.getParameter(ORIGINATING_PAGE);
    String formLayoutId = request.getParameter(FORM_LAYOUT_ID);
    String studyEventId = request.getParameter(STUDY_EVENT_ID);
    String eventCrfId = request.getParameterValues(EVENT_CRF_ID)[0];
    String formUrl = null;
    StudyEvent studyEvent = studyEventDao.findByStudyEventId(Integer.valueOf(studyEventId));
    FormLayout formLayout = formLayoutDao.findById(Integer.valueOf(formLayoutId));
    // Cache the subject context for use during xform submission
    PFormCache cache = PFormCache.getInstance(context);
    PFormCacheSubjectContextEntry subjectContext = new PFormCacheSubjectContextEntry();
    subjectContext.setStudySubjectOid(studyEvent.getStudySubject().getOcOid());
    subjectContext.setStudyEventDefinitionId(studyEvent.getStudyEventDefinition().getStudyEventDefinitionId());
    subjectContext.setOrdinal(studyEvent.getSampleOrdinal());
    subjectContext.setFormLayoutOid(formLayout.getOcOid());
    subjectContext.setUserAccountId(ub.getId());
    String contextHash = cache.putSubjectContext(subjectContext);
    Study study = enketoCredentials.getParentStudy(currentStudy.getOid());
    if (Integer.valueOf(eventCrfId) > 0) {
        formUrl = enketoUrlService.getEditUrl(contextHash, subjectContext, study.getOc_oid(), formLayout, studyEvent, QUERY_FLAVOR);
    } else {
        formUrl = enketoUrlService.getInitialDataEntryUrl(contextHash, subjectContext, study.getOc_oid(), QUERY_FLAVOR);
    }
    int hashIndex = formUrl.lastIndexOf("#");
    String part1 = formUrl;
    String part2 = "";
    if (hashIndex != -1) {
        part1 = formUrl.substring(0, hashIndex);
        part2 = formUrl.substring(hashIndex);
    }
    request.setAttribute(FORM_URL1, part1);
    request.setAttribute(FORM_URL2, part2);
    // request.setAttribute(FORM_URL, "https://enke.to/i/::widgets?a=b");
    request.setAttribute(ORIGINATING_PAGE, originatingPage);
    forwardPage(Page.ENKETO_FORM_SERVLET);
}
Also used : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) Study(org.akaza.openclinica.domain.datamap.Study) StudyEventDao(org.akaza.openclinica.dao.hibernate.StudyEventDao) FormLayoutDao(org.akaza.openclinica.dao.hibernate.FormLayoutDao) EnketoUrlService(org.akaza.openclinica.service.crfdata.EnketoUrlService) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent) EnketoCredentials(org.akaza.openclinica.service.crfdata.xform.EnketoCredentials) PFormCache(org.akaza.openclinica.web.pform.PFormCache) PFormCacheSubjectContextEntry(org.akaza.openclinica.service.crfdata.xform.PFormCacheSubjectContextEntry)

Example 13 with StudyEvent

use of org.akaza.openclinica.domain.datamap.StudyEvent in project OpenClinica by OpenClinica.

the class BatchCRFMigrationController method executeMigrationAction.

public void executeMigrationAction(HelperObject helperObject, EventCRFBean eventCRFBean) {
    Session session = helperObject.getSession();
    EventCrf eventCrf = helperObject.getEventCrfDao().findById(eventCRFBean.getId());
    StudyEvent studyEvent = helperObject.getStudyEventDao().findById(eventCRFBean.getStudyEventId());
    FormLayout formLayout = helperObject.getFormLayoutDao().findById(helperObject.getTargetCrfVersionBean().getId());
    StudySubject studySubject = helperObject.getStudySubjectDao().findById(eventCRFBean.getStudySubjectId());
    eventCrf.setSdvStatus(false);
    eventCrf.setDateUpdated(new Date());
    eventCrf.setSdvUpdateId(helperObject.getUserAccountBean().getId());
    eventCrf.setUpdateId(helperObject.getUserAccountBean().getId());
    eventCrf.setFormLayout(formLayout);
    session.saveOrUpdate(eventCrf);
    String status_before_update = null;
    SubjectEventStatus eventStatus = null;
    if (studySubject.getStatus() == Status.SIGNED) {
        status_before_update = auditDao().findLastStatus("study_subject", studySubject.getStudySubjectId(), "8");
        if (status_before_update != null && status_before_update.length() == 1) {
            int subject_status = Integer.parseInt(status_before_update);
            Status status = Status.getByCode(subject_status);
            studySubject.setStatus(status);
        }
        studySubject.setUpdateId(helperObject.getUserAccountBean().getId());
        session.saveOrUpdate(studySubject);
    }
    studyEvent.setUpdateId(helperObject.getUserAccountBean().getId());
    studyEvent.setDateUpdated(new Date());
    status_before_update = auditDao().findLastStatus("study_event", studyEvent.getStudyEventId(), "8");
    if (status_before_update != null && status_before_update.length() == 1) {
        int status = Integer.parseInt(status_before_update);
        eventStatus = SubjectEventStatus.get(status);
        studyEvent.setSubjectEventStatusId(eventStatus.getId());
    }
    session.saveOrUpdate(studyEvent);
}
Also used : EventCrf(org.akaza.openclinica.domain.datamap.EventCrf) FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) Status(org.akaza.openclinica.domain.Status) SubjectEventStatus(org.akaza.openclinica.bean.core.SubjectEventStatus) StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent) Date(java.util.Date) Session(org.hibernate.Session) SubjectEventStatus(org.akaza.openclinica.bean.core.SubjectEventStatus)

Example 14 with StudyEvent

use of org.akaza.openclinica.domain.datamap.StudyEvent in project OpenClinica by OpenClinica.

the class EventProcessor method createStudyEvent.

private StudyEvent createStudyEvent(StudySubject studySubject, StudyEventDefinition studyEventDefinition, Integer ordinal, UserAccount user) {
    Date currentDate = new Date();
    StudyEvent studyEvent = new StudyEvent();
    studyEvent.setStudySubject(studySubject);
    studyEvent.setStudyEventDefinition(studyEventDefinition);
    studyEvent.setSampleOrdinal(ordinal);
    studyEvent.setStatusId(Status.AVAILABLE.getCode());
    studyEvent.setUserAccount(user);
    studyEvent.setDateStart(currentDate);
    studyEvent.setSubjectEventStatusId(SubjectEventStatus.SCHEDULED.getCode());
    studyEvent.setStartTimeFlag(false);
    studyEvent.setEndTimeFlag(false);
    studyEvent.setDateCreated(currentDate);
    studyEvent.setLocation("");
    StudyEventChangeDetails changeDetails = new StudyEventChangeDetails(true, true);
    StudyEventContainer container = new StudyEventContainer(studyEvent, changeDetails);
    studyEventDao.saveOrUpdateTransactional(container);
    studyEvent = studyEventDao.fetchByStudyEventDefOIDAndOrdinal(studyEventDefinition.getOc_oid(), ordinal, studySubject.getStudySubjectId());
    return studyEvent;
}
Also used : StudyEventChangeDetails(org.akaza.openclinica.patterns.ocobserver.StudyEventChangeDetails) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent) StudyEventContainer(org.akaza.openclinica.patterns.ocobserver.StudyEventContainer) Date(java.util.Date)

Example 15 with StudyEvent

use of org.akaza.openclinica.domain.datamap.StudyEvent in project OpenClinica by OpenClinica.

the class EventProcessor method processAnonymous.

private void processAnonymous(SubmissionContainer container, Errors errors, StudySubject studySubject, StudyEventDefinition studyEventDefinition) throws Exception {
    // Integer.valueOf(container.getSubjectContext().get("studyEventOrdinal"));
    Integer ordinal = 1;
    Integer maxExistingOrdinal = studyEventDao.findMaxOrdinalByStudySubjectStudyEventDefinition(studySubject.getStudySubjectId(), studyEventDefinition.getStudyEventDefinitionId());
    FormLayout formLayout = formLayoutDao.findByOcOID(container.getSubjectContext().get("formLayoutOID"));
    while (ordinal <= maxExistingOrdinal + 1) {
        StudyEvent existingStudyEvent = studyEventDao.fetchByStudyEventDefOIDAndOrdinal(studyEventDefinition.getOc_oid(), ordinal, studySubject.getStudySubjectId());
        if (existingStudyEvent == null) {
            container.setStudyEvent(createStudyEvent(studySubject, studyEventDefinition, ordinal, container.getUser()));
            container.setEventCrf(createEventCrf(formLayout, container.getStudyEvent(), container.getSubject(), container.getUser()));
            break;
        } else if (!existingStudyEvent.getStatusId().equals(Status.AVAILABLE.getCode()) || (!existingStudyEvent.getSubjectEventStatusId().equals(SubjectEventStatus.SCHEDULED.getCode()) && !existingStudyEvent.getSubjectEventStatusId().equals(SubjectEventStatus.NOT_SCHEDULED.getCode()) && !existingStudyEvent.getSubjectEventStatusId().equals(SubjectEventStatus.DATA_ENTRY_STARTED.getCode()))) {
            if (studyEventDefinition.getRepeating()) {
                ordinal++;
                continue;
            } else {
                errors.reject("Existing StudyEvent is not Available and EventDef is not repeating");
                logger.info("***  Existing StudyEvent is not Available and EventDef is not repeating  ***");
                throw new Exception("***  Existing StudyEvent is not Available and EventDef is not repeating  ***");
            }
        } else {
            EventCrf existingEventCrf = eventCrfDao.findByStudyEventIdStudySubjectIdCrfId(existingStudyEvent.getStudyEventId(), container.getSubject().getStudySubjectId(), formLayout.getCrf().getCrfId());
            if (existingEventCrf == null) {
                container.setStudyEvent(existingStudyEvent);
                container.setEventCrf(createEventCrf(formLayout, container.getStudyEvent(), container.getSubject(), container.getUser()));
                break;
            } else {
                List<ItemData> itemDataList = itemDataDao.findByEventCrfId(existingEventCrf.getEventCrfId());
                if (existingEventCrf.getStatusId().equals(Status.AVAILABLE.getCode()) && itemDataList.size() == 0) {
                    container.setStudyEvent(existingStudyEvent);
                    container.setEventCrf(existingEventCrf);
                    break;
                } else if (studyEventDefinition.getRepeating()) {
                    ordinal++;
                    continue;
                } else {
                    errors.reject("Existing EventCRF is not usable and EventDef is not repeating");
                    logger.info("***  Existing EventCRF is not usable and EventDef is not repeating  ***");
                    throw new Exception("***  Existing EventCRF is not usable and EventDef is not repeating  ***");
                }
            }
        }
    }
    if (container.getStudyEvent() == null || container.getEventCrf() == null) {
        errors.reject("Unable to identify StudyEvent or EventCrf.");
        logger.info("***  Unable to identify StudyEvent or EventCrf.  ***");
        throw new Exception("***  Unable to identify StudyEvent or EventCrf.  ***");
    }
}
Also used : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) EventCrf(org.akaza.openclinica.domain.datamap.EventCrf) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent) List(java.util.List)

Aggregations

StudyEvent (org.akaza.openclinica.domain.datamap.StudyEvent)25 StudySubject (org.akaza.openclinica.domain.datamap.StudySubject)6 ArrayList (java.util.ArrayList)5 EventCrf (org.akaza.openclinica.domain.datamap.EventCrf)5 Date (java.util.Date)4 FormLayout (org.akaza.openclinica.domain.datamap.FormLayout)4 Study (org.akaza.openclinica.domain.datamap.Study)4 StudyEventDefinition (org.akaza.openclinica.domain.datamap.StudyEventDefinition)4 Transactional (org.springframework.transaction.annotation.Transactional)4 SimpleDateFormat (java.text.SimpleDateFormat)3 HashMap (java.util.HashMap)2 EventDefinitionCrf (org.akaza.openclinica.domain.datamap.EventDefinitionCrf)2 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)2 EventActionBean (org.akaza.openclinica.domain.rule.action.EventActionBean)2 ExpressionBean (org.akaza.openclinica.domain.rule.expression.ExpressionBean)2 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)2 OpenClinicaExpressionParser (org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser)2 OnStudyEventUpdated (org.akaza.openclinica.patterns.ocobserver.OnStudyEventUpdated)2 StudyEventChangeDetails (org.akaza.openclinica.patterns.ocobserver.StudyEventChangeDetails)2 StudyEventContainer (org.akaza.openclinica.patterns.ocobserver.StudyEventContainer)2