Search in sources :

Example 6 with EventCrf

use of org.akaza.openclinica.domain.datamap.EventCrf 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());
    CrfVersion crfVersion = crfVersionDao.findByOcOID(container.getSubjectContext().get("crfVersionOID"));
    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(crfVersion, 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(), crfVersion.getCrf().getCrfId());
            if (existingEventCrf == null) {
                container.setStudyEvent(existingStudyEvent);
                container.setEventCrf(createEventCrf(crfVersion, 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 : EventCrf(org.akaza.openclinica.domain.datamap.EventCrf) CrfVersion(org.akaza.openclinica.domain.datamap.CrfVersion) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent) List(java.util.List)

Example 7 with EventCrf

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

the class GenerateClinicalDataServiceImpl method getFormDataForClinicalStudy.

private ArrayList<ExportFormDataBean> getFormDataForClinicalStudy(StudySubject ss, StudyEvent se, String formVersionOID) {
    List<ExportFormDataBean> formDataBean = new ArrayList<ExportFormDataBean>();
    boolean formCheck = true;
    if (formVersionOID != null)
        formCheck = false;
    boolean hiddenCrfCheckPassed = true;
    List<CrfBean> hiddenCrfs = new ArrayList<CrfBean>();
    for (EventCrf ecrf : se.getEventCrfs()) {
        List<EventDefinitionCrf> edcs = se.getStudyEventDefinition().getEventDefinitionCrfs();
        hiddenCrfCheckPassed = true;
        int siteId = 0;
        int parentStudyId = 0;
        Study study = ss.getStudy();
        if (study.getStudy() != null && isActiveRoleAtSite) {
            // it is site subject
            siteId = study.getStudyId();
            parentStudyId = study.getStudy().getStudyId();
            hiddenCrfs = listOfHiddenCrfs(siteId, parentStudyId, edcs, ecrf);
            if (hiddenCrfs.contains(ecrf.getCrfVersion().getCrf())) {
                hiddenCrfCheckPassed = false;
            }
        }
        // This logic is to use the same method for both S_OID/SS_OID/*/* and full path
        if (hiddenCrfCheckPassed) {
            if (!formCheck) {
                if (ecrf.getCrfVersion().getOcOid().equals(formVersionOID))
                    formCheck = true;
                else
                    formCheck = false;
            }
            if (formCheck) {
                ExportFormDataBean dataBean = new ExportFormDataBean();
                dataBean.setItemGroupData(fetchItemData(ecrf.getCrfVersion().getItemGroupMetadatas(), ecrf.getEventCrfId(), ecrf.getCrfVersion().getVersioningMaps(), ecrf));
                dataBean.setFormOID(ecrf.getCrfVersion().getOcOid());
                if (ecrf.getDateInterviewed() != null)
                    dataBean.setInterviewDate(ecrf.getDateInterviewed() + "");
                if (ecrf.getInterviewerName() != null)
                    dataBean.setInterviewerName(ecrf.getInterviewerName());
                // dataBean.setStatus(EventCRFStatus.getByCode(Integer.valueOf(ecrf.getStatus().getCode())).getI18nDescription(getLocale()));
                dataBean.setStatus(fetchEventCRFStatus(ecrf));
                if (ecrf.getCrfVersion().getName() != null)
                    dataBean.setCrfVersion(ecrf.getCrfVersion().getName());
                if (collectAudits)
                    dataBean.setAuditLogs(fetchAuditLogs(ecrf.getEventCrfId(), "event_crf", ecrf.getCrfVersion().getOcOid(), null));
                if (collectDns)
                    dataBean.setDiscrepancyNotes(fetchDiscrepancyNotes(ecrf));
                formDataBean.add(dataBean);
                if (formVersionOID != null)
                    formCheck = false;
            }
        }
    }
    return (ArrayList<ExportFormDataBean>) formDataBean;
}
Also used : ExportFormDataBean(org.akaza.openclinica.bean.submit.crfdata.ExportFormDataBean) EventCrf(org.akaza.openclinica.domain.datamap.EventCrf) CrfBean(org.akaza.openclinica.domain.datamap.CrfBean) Study(org.akaza.openclinica.domain.datamap.Study) ArrayList(java.util.ArrayList) EventDefinitionCrf(org.akaza.openclinica.domain.datamap.EventDefinitionCrf)

Example 8 with EventCrf

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

the class EditFormController method getEditUrl.

/**
 * @api {get} /pages/api/v1/editform/:studyOid/url Get Form Edit URL
 * @apiName getEditUrl
 * @apiPermission admin
 * @apiVersion 3.8.0
 * @apiParam {String} studyOid Study Oid.
 * @apiParam {String} ecid Key that will be used by enketo to cache form information.
 * @apiGroup Form
 * @apiDescription This API is used to retrieve a URL for a form with data pre-loaded into it
 * @apiParamExample {json} Request-Example:
 *                  {
 *                  "studyOid": "S_BL101",
 *                  "ecid":"a9f8f3aadea4b67e1f214140ccfdf70bad0b9e9b622a9776a3c85bbf6bb532cd"
 *                  }
 * @apiSuccessExample Success-Response:
 *                    HTTP/1.1 200 OK
 *                    {
 *                    http://ocform.oc.com:8005/edit/::YYYM?instance_id=
 *                    d16bba9200177fad34594e75d8b9565ff92b0bce4297e3b6c27275e531044a59
 *                    &returnUrl=http%3A%2F%2Fstudy1.mystudy.me%3A8080%2F%23%2Fevent%2FSS_SUB001%2Fdashboard&ecid=
 *                    d16bba9200177fad34594e75d8b9565ff92b0bce4297e3b6c27275e531044a59
 *                    }
 */
@RequestMapping(value = "/{studyOid}/url", method = RequestMethod.GET)
public ResponseEntity<String> getEditUrl(@RequestParam(FORM_CONTEXT) String formContext, @PathVariable("studyOid") String studyOID) throws Exception {
    String editURL = null;
    if (!mayProceed(studyOID))
        return new ResponseEntity<String>(editURL, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    // Load context
    PFormCache cache = PFormCache.getInstance(context);
    HashMap<String, String> userContext = cache.getSubjectContext(formContext);
    // Lookup relevant data
    StudyEventDefinition eventDef = studyEventDefinitionDao.findById(Integer.valueOf(userContext.get("studyEventDefinitionID")));
    CrfVersion crfVersion = crfVersionDao.findByOcOID(userContext.get("crfVersionOID"));
    StudySubject subject = studySubjectDao.findByOcOID(userContext.get("studySubjectOID"));
    StudyEvent event = studyEventDao.fetchByStudyEventDefOIDAndOrdinal(eventDef.getOc_oid(), Integer.valueOf(userContext.get("studyEventOrdinal")), subject.getStudySubjectId());
    EventCrf eventCrf = eventCrfDao.findByStudyEventIdStudySubjectIdCrfVersionId(event.getStudyEventId(), subject.getStudySubjectId(), crfVersion.getCrfVersionId());
    // Load populated instance
    String populatedInstance = getPopulatedInstance(crfVersion, eventCrf);
    // Call Enketo api to get edit url
    EnketoAPI enketo = new EnketoAPI(EnketoCredentials.getInstance(studyOID));
    // Build redirect url
    String redirectUrl = getRedirectUrl(subject.getOcOid(), studyOID);
    // Return Enketo URL
    editURL = enketo.getEditURL(crfVersion.getOcOid(), populatedInstance, formContext, redirectUrl).getEdit_url() + "&ecid=" + formContext;
    logger.debug("Generating Enketo edit url for form: " + editURL);
    return new ResponseEntity<String>(editURL, org.springframework.http.HttpStatus.ACCEPTED);
}
Also used : EventCrf(org.akaza.openclinica.domain.datamap.EventCrf) EnketoAPI(org.akaza.openclinica.web.pform.EnketoAPI) StudyEventDefinition(org.akaza.openclinica.domain.datamap.StudyEventDefinition) ResponseEntity(org.springframework.http.ResponseEntity) StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) CrfVersion(org.akaza.openclinica.domain.datamap.CrfVersion) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent) PFormCache(org.akaza.openclinica.web.pform.PFormCache) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with EventCrf

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

the class OdmController method generateFormData.

private ODMcomplexTypeDefinitionFormData generateFormData(CRFVersionBean crfVersionBean, StudyEventBean nextEvent, EventCRFBean eventCRFBean, CRFBean crfBean, String formUrl, boolean itemDataExists) {
    ODMcomplexTypeDefinitionFormData formData = new ODMcomplexTypeDefinitionFormData();
    formData.setFormOID(crfVersionBean.getOid());
    formData.setFormName(crfBean.getName());
    formData.setVersionDescription(crfVersionBean.getDescription());
    formData.setUrl(formUrl);
    if (eventCRFBean == null) {
        formData.setStatus("Not Started");
    } else {
        EventCrf eventCrf = eventCrfDao.findById(eventCRFBean.getId());
        if (!itemDataExists) {
            formData.setStatus("Not Started");
        } else {
            formData.setStatus(eventCRFBean.getStatus().getName());
        }
        if (eventCrf.getDateUpdated() != null) {
            // returns time as UTC
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
            sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
            formData.setStatusChangeTimeStamp(sdf.format(eventCrf.getDateUpdated()));
        }
    }
    return formData;
}
Also used : EventCrf(org.akaza.openclinica.domain.datamap.EventCrf) ODMcomplexTypeDefinitionFormData(org.cdisc.ns.odm.v130_api.ODMcomplexTypeDefinitionFormData) SimpleDateFormat(java.text.SimpleDateFormat)

Example 10 with EventCrf

use of org.akaza.openclinica.domain.datamap.EventCrf 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());
    CrfVersion crfVersion = helperObject.getCrfVersionDao().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.setCrfVersion(crfVersion);
    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) Status(org.akaza.openclinica.domain.Status) SubjectEventStatus(org.akaza.openclinica.bean.core.SubjectEventStatus) StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) CrfVersion(org.akaza.openclinica.domain.datamap.CrfVersion) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent) Date(java.util.Date) Session(org.hibernate.Session) SubjectEventStatus(org.akaza.openclinica.bean.core.SubjectEventStatus)

Aggregations

EventCrf (org.akaza.openclinica.domain.datamap.EventCrf)16 CrfVersion (org.akaza.openclinica.domain.datamap.CrfVersion)9 Date (java.util.Date)6 StudyEvent (org.akaza.openclinica.domain.datamap.StudyEvent)6 StudySubject (org.akaza.openclinica.domain.datamap.StudySubject)5 EventDefinitionCrf (org.akaza.openclinica.domain.datamap.EventDefinitionCrf)4 Study (org.akaza.openclinica.domain.datamap.Study)4 StudyEventDefinition (org.akaza.openclinica.domain.datamap.StudyEventDefinition)4 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Item (org.akaza.openclinica.domain.datamap.Item)2 PFormCache (org.akaza.openclinica.web.pform.PFormCache)2 ResponseEntity (org.springframework.http.ResponseEntity)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 StringReader (java.io.StringReader)1 List (java.util.List)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1