Search in sources :

Example 1 with StudyEventDefinition

use of org.akaza.openclinica.domain.datamap.StudyEventDefinition 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 2 with StudyEventDefinition

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

the class GenerateClinicalDataServiceImpl method getClinicalDatas.

private OdmClinicalDataBean getClinicalDatas(String studyOID, String studySubjectOID, String studyEventOID, String formVersionOID) {
    int seOrdinal = 0;
    String temp = studyEventOID;
    List<StudyEvent> studyEvents = new ArrayList<StudyEvent>();
    StudyEventDefinition sed = null;
    Study study = getStudyDao().findByColumnName(studyOID, "oc_oid");
    List<StudySubject> ss = listStudySubjects(studySubjectOID);
    int idx = studyEventOID.indexOf(OPEN_ORDINAL_DELIMITER);
    LOGGER.info("study event oridinal is.." + idx);
    if (idx > 0) {
        studyEventOID = studyEventOID.substring(0, idx);
        seOrdinal = new Integer(temp.substring(idx + 1, temp.indexOf(CLOSE_ORDINAL_DELIMITER))).intValue();
    }
    sed = getStudyEventDefDao().findByColumnName(studyEventOID, "oc_oid");
    LOGGER.info("study event ordinal.." + seOrdinal);
    if (seOrdinal > 0) {
        studyEvents = fetchSE(seOrdinal, sed.getStudyEvents(), studySubjectOID);
    } else {
        studyEvents = fetchSE(sed.getStudyEvents(), studySubjectOID);
    }
    return constructClinicalDataStudy(ss, study, studyEvents, formVersionOID);
}
Also used : Study(org.akaza.openclinica.domain.datamap.Study) StudyEventDefinition(org.akaza.openclinica.domain.datamap.StudyEventDefinition) StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) ArrayList(java.util.ArrayList) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent)

Example 3 with StudyEventDefinition

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

the class BeanPropertyService method executeAction.

/**
 * The Event action runs based on the values set in the rules.
 * @param result
 * @param propertyBean
 * @param eow
 * @param eventAction
 */
private void executeAction(Object result, PropertyBean propertyBean, ExpressionBeanObjectWrapper eow, EventActionBean eventAction, Integer userId, boolean isTransaction) {
    String oid = eventAction.getOc_oid_reference();
    String eventOID = null;
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    int ordinal = 1;
    if (oid.startsWith(ExpressionService.STUDY_EVENT_OID_START_KEY)) {
        StudyEvent studyEvent = null;
        if (oid.contains("[")) {
            int leftBracketIndex = oid.indexOf("[");
            int rightBracketIndex = oid.indexOf("]");
            ordinal = Integer.valueOf(oid.substring(leftBracketIndex + 1, rightBracketIndex));
            eventOID = oid.substring(0, leftBracketIndex);
            studyEvent = getStudyEventDAO().fetchByStudyEventDefOIDAndOrdinal(eventOID, ordinal, eow.getStudySubjectBeanId());
        } else {
            eventOID = oid;
            studyEvent = getStudyEventDAO().fetchByStudyEventDefOIDAndOrdinal(oid, ordinal, eow.getStudySubjectBeanId());
        }
        StudyEventChangeDetails changeDetails = new StudyEventChangeDetails();
        if (studyEvent == null) {
            // the studyevent may not have been created.
            studyEvent = new StudyEvent();
            StudySubject ss = getStudySubjectDao().findById(eow.getStudySubjectBeanId());
            StudyEventDefinition sed = getStudyEventDefinitionDao().findByColumnName(eventOID, "oc_oid");
            studyEvent.setStudyEventDefinition(sed);
            studyEvent.setStudySubject(ss);
            studyEvent.setStatusId(1);
            studyEvent.setSampleOrdinal(getNewEventOrdinal(eventOID, eow.getStudySubjectBeanId(), sed));
            // The status is changed to started when it doesnt exist. In other cases, the status remains the same. The case of Signed and locked are prevented from validator and are not again checked here.
            studyEvent.setSubjectEventStatusId(new Integer(1));
            studyEvent.setStartTimeFlag(false);
            studyEvent.setEndTimeFlag(false);
            studyEvent.setDateCreated(new Date());
            studyEvent.setUserAccount(getUserAccountDao().findById(userId));
            changeDetails.setStartDateChanged(true);
            changeDetails.setStatusChanged(true);
        } else {
            studyEvent.setUpdateId(userId);
            studyEvent.setDateUpdated(new Date());
            changeDetails.setStatusChanged(false);
        }
        try {
            if (studyEvent.getDateStart() == null || studyEvent.getDateStart().compareTo(df.parse((String) result)) != 0)
                changeDetails.setStartDateChanged(true);
            studyEvent.setDateStart(df.parse((String) result));
        } catch (ParseException e) {
            e.printStackTrace();
            LOGGER.info(e.getMessage());
        }
        changeDetails.setRunningInTransaction(isTransaction);
        StudyEventContainer container = new StudyEventContainer(studyEvent, changeDetails);
        if (isTransaction)
            getStudyEventDAO().saveOrUpdateTransactional(container);
        else
            getStudyEventDAO().saveOrUpdate(container);
    }
}
Also used : StudyEventDefinition(org.akaza.openclinica.domain.datamap.StudyEventDefinition) StudyEventChangeDetails(org.akaza.openclinica.patterns.ocobserver.StudyEventChangeDetails) StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent) ParseException(java.text.ParseException) StudyEventContainer(org.akaza.openclinica.patterns.ocobserver.StudyEventContainer) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 4 with StudyEventDefinition

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

the class OpenRosaSubmissionController method markComplete.

// @RequestMapping(value = "/{studyOID}/fieldsubmission/complete", method = RequestMethod.POST)
public ResponseEntity<String> markComplete(HttpServletRequest request, HttpServletResponse response, @PathVariable("studyOID") String studyOID, @RequestParam(FORM_CONTEXT) String ecid) throws Exception {
    HashMap<String, String> subjectContext = null;
    PFormCache cache = PFormCache.getInstance(context);
    subjectContext = cache.getSubjectContext(ecid);
    int studyEventDefinitionID = Integer.valueOf(subjectContext.get("studyEventDefinitionID"));
    int userAccountID = Integer.valueOf(subjectContext.get("userAccountID"));
    String studySubjectOID = subjectContext.get("studySubjectOID");
    String formLayoutOID = subjectContext.get("formLayoutOID");
    int studyEventOrdinal = Integer.valueOf(subjectContext.get("studyEventOrdinal"));
    UserAccount userAccount = userAccountDao.findById(userAccountID);
    StudySubject studySubject = studySubjectDao.findByOcOID(studySubjectOID);
    Study study = studyDao.findByOcOID(studyOID);
    StudyEventDefinition sed = studyEventDefinitionDao.findById(studyEventDefinitionID);
    FormLayout formLayout = formLayoutDao.findByOcOID(formLayoutOID);
    CrfVersion crfVersion = crfVersionDao.findAllByCrfId(formLayout.getCrf().getCrfId()).get(0);
    StudyEvent studyEvent = studyEventDao.fetchByStudyEventDefOIDAndOrdinalTransactional(sed.getOc_oid(), studyEventOrdinal, studySubject.getStudySubjectId());
    EventCrf eventCrf = eventCrfDao.findByStudyEventIdStudySubjectIdFormLayoutId(studyEvent.getStudyEventId(), studySubject.getStudySubjectId(), formLayout.getFormLayoutId());
    if (eventCrf == null) {
        eventCrf = createEventCrf(formLayout, studyEvent, studySubject, userAccount);
        List<Item> items = itemDao.findAllByCrfVersion(crfVersion.getCrfVersionId());
        createItemData(items.get(0), "", eventCrf, userAccount);
    }
    eventCrf.setStatusId(org.akaza.openclinica.domain.Status.UNAVAILABLE.getCode());
    eventCrf.setUserAccount(userAccount);
    eventCrf.setUpdateId(userAccount.getUserId());
    eventCrf.setDateUpdated(new Date());
    eventCrfDao.saveOrUpdate(eventCrf);
    List<EventCrf> eventCrfs = eventCrfDao.findByStudyEventIdStudySubjectId(studyEvent.getStudyEventId(), studySubject.getOcOid());
    List<EventDefinitionCrf> eventDefinitionCrfs = eventDefinitionCrfDao.findAvailableByStudyEventDefStudy(sed.getStudyEventDefinitionId(), study.getStudyId());
    int count = 0;
    for (EventCrf evCrf : eventCrfs) {
        if (evCrf.getStatusId() == org.akaza.openclinica.domain.Status.UNAVAILABLE.getCode() || evCrf.getStatusId() == org.akaza.openclinica.domain.Status.DELETED.getCode() || evCrf.getStatusId() == org.akaza.openclinica.domain.Status.AUTO_DELETED.getCode()) {
            for (EventDefinitionCrf eventDefinitionCrf : eventDefinitionCrfs) {
                if (eventDefinitionCrf.getCrf().getCrfId() == evCrf.getFormLayout().getCrf().getCrfId()) {
                    count++;
                    break;
                }
            }
        }
    }
    if (count == eventDefinitionCrfs.size()) {
        studyEvent.setSubjectEventStatusId(SubjectEventStatus.COMPLETED.getCode());
        studyEvent.setUserAccount(userAccount);
        studyEventDao.saveOrUpdate(studyEvent);
    } else if (studyEvent.getSubjectEventStatusId() == SubjectEventStatus.SCHEDULED.getCode()) {
        studyEvent.setSubjectEventStatusId(SubjectEventStatus.DATA_ENTRY_STARTED.getCode());
        studyEvent.setUserAccount(userAccount);
        studyEventDao.saveOrUpdate(studyEvent);
    }
    String responseMessage = "<OpenRosaResponse xmlns=\"http://openrosa.org/http/response\">" + "<message>success</message>" + "</OpenRosaResponse>";
    return new ResponseEntity<String>(responseMessage, HttpStatus.CREATED);
}
Also used : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) Study(org.akaza.openclinica.domain.datamap.Study) StudyEventDefinition(org.akaza.openclinica.domain.datamap.StudyEventDefinition) EventDefinitionCrf(org.akaza.openclinica.domain.datamap.EventDefinitionCrf) Date(java.util.Date) EventCrf(org.akaza.openclinica.domain.datamap.EventCrf) Item(org.akaza.openclinica.domain.datamap.Item) FileItem(org.apache.commons.fileupload.FileItem) 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) UserAccount(org.akaza.openclinica.domain.user.UserAccount) PFormCache(org.akaza.openclinica.web.pform.PFormCache)

Example 5 with StudyEventDefinition

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

the class OdmImportServiceImpl method saveOrUpdateEvent.

private List<ODMcomplexTypeDefinitionStudyEventDef> saveOrUpdateEvent(UserAccount userAccount, Study study, List<ODMcomplexTypeDefinitionMetaDataVersion> odmMetadataVersions) {
    StudyEventDefinition studyEventDefinition;
    List<ODMcomplexTypeDefinitionStudyEventDef> odmStudyEventDefs = odmMetadataVersions.get(0).getStudyEventDef();
    List<StudyEventDefinition> jsonEventList = new ArrayList<>();
    for (ODMcomplexTypeDefinitionStudyEventDef odmStudyEventDef : odmStudyEventDefs) {
        studyEventDefinition = getStudyEventDefDao().findByOcOID(odmStudyEventDef.getOID());
        if (studyEventDefinition == null || studyEventDefinition.getStudyEventDefinitionId() == 0) {
            studyEventDefinition = new StudyEventDefinition();
            studyEventDefinition.setOc_oid(odmStudyEventDef.getOID());
            studyEventDefinition = getStudyEventDefDao().saveOrUpdate(populateEvent(odmStudyEventDef, userAccount, studyEventDefinition, study));
        } else {
            studyEventDefinition = getStudyEventDefDao().saveOrUpdate(updateEvent(odmStudyEventDef, userAccount, studyEventDefinition, study));
        }
        jsonEventList.add(studyEventDefinition);
    }
    // findAllNonRemovedEvents
    List<StudyEventDefinition> ocEventList = getStudyEventDefDao().findAll();
    for (StudyEventDefinition ocEvent : ocEventList) {
        if (!jsonEventList.contains(ocEvent)) {
            ocEvent.setStatus(Status.DELETED);
            getStudyEventDefDao().saveOrUpdate(ocEvent);
        }
    }
    return odmStudyEventDefs;
}
Also used : StudyEventDefinition(org.akaza.openclinica.domain.datamap.StudyEventDefinition) ODMcomplexTypeDefinitionStudyEventDef(org.cdisc.ns.odm.v130.ODMcomplexTypeDefinitionStudyEventDef) ArrayList(java.util.ArrayList)

Aggregations

StudyEventDefinition (org.akaza.openclinica.domain.datamap.StudyEventDefinition)9 StudySubject (org.akaza.openclinica.domain.datamap.StudySubject)7 Study (org.akaza.openclinica.domain.datamap.Study)6 StudyEvent (org.akaza.openclinica.domain.datamap.StudyEvent)5 EventCrf (org.akaza.openclinica.domain.datamap.EventCrf)4 ArrayList (java.util.ArrayList)3 CrfVersion (org.akaza.openclinica.domain.datamap.CrfVersion)3 EventDefinitionCrf (org.akaza.openclinica.domain.datamap.EventDefinitionCrf)3 Date (java.util.Date)2 FormLayout (org.akaza.openclinica.domain.datamap.FormLayout)2 UserAccount (org.akaza.openclinica.domain.user.UserAccount)2 PFormCache (org.akaza.openclinica.web.pform.PFormCache)2 ODMcomplexTypeDefinitionStudyEventDef (org.cdisc.ns.odm.v130.ODMcomplexTypeDefinitionStudyEventDef)2 ResponseEntity (org.springframework.http.ResponseEntity)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 DateFormat (java.text.DateFormat)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 CrfBean (org.akaza.openclinica.domain.datamap.CrfBean)1