Search in sources :

Example 6 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 7 with StudyEventDefinition

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

the class EventProcessor method process.

public ProcessorEnum process(SubmissionContainer container) throws Exception {
    logger.info("Executing Event Processor.");
    Errors errors = container.getErrors();
    StudySubject studySubject = container.getSubject();
    StudyEventDefinition studyEventDefinition = studyEventDefinitionDao.findByStudyEventDefinitionId(Integer.valueOf(container.getSubjectContext().get("studyEventDefinitionID")));
    FormLayout formLayout = formLayoutDao.findByOcOID(container.getSubjectContext().get("formLayoutOID"));
    container.setFormLayout(formLayout);
    CrfVersion crfVersion = crfVersionDao.findAllByCrfId(formLayout.getCrf().getCrfId()).get(0);
    container.setCrfVersion(crfVersion);
    boolean isAnonymous = false;
    if (container.getSubjectContext().get("studySubjectOID") == null)
        isAnonymous = true;
    // Create study event if it doesn't exist
    if (isAnonymous)
        processAnonymous(container, errors, studySubject, studyEventDefinition);
    else
        processParticipant(container, errors, studySubject, studyEventDefinition);
    // TODO: May need to move this to a new processor that runs at the end
    // Update the EventCrf and StudyEvent to the proper status.
    // Don't do it in the initial save so it will have the expected audit trail entries.
    Study study = null;
    if (container.getSubjectContext().get("studyOID") != null)
        study = studyDao.findByOcOID(container.getSubjectContext().get("studyOID"));
    else
        study = container.getStudy();
    container.setEventCrf(updateEventCrf(container.getEventCrf(), study, studySubject, container.getUser(), isAnonymous));
    container.setStudyEvent(updateStudyEvent(container.getStudyEvent(), studyEventDefinition, study, studySubject, container.getUser(), isAnonymous));
    return ProcessorEnum.PROCEED;
}
Also used : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) Errors(org.springframework.validation.Errors) Study(org.akaza.openclinica.domain.datamap.Study) StudyEventDefinition(org.akaza.openclinica.domain.datamap.StudyEventDefinition) StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) CrfVersion(org.akaza.openclinica.domain.datamap.CrfVersion)

Example 8 with StudyEventDefinition

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

the class StudyEventController method completeParticipantEvent.

/**
	 * @api {put} /pages/auth/api/v1/studyevent/studysubject/{studySubjectOid}/studyevent/{studyEventDefOid}/ordinal/{ordinal}/complete Complete a Participant Event
	 * @apiName completeParticipantEvent
	 * @apiPermission Authenticate using api-key. admin
	 * @apiVersion 1.0.0
	 * @apiParam {String} studySubjectOid Study Subject OID.
	 * @apiParam {String} studyEventDefOid Study Event Definition OID.
	 * @apiParam {Integer} ordinal Ordinal of Study Event Repetition.
	 * @apiGroup Form
	 * @apiHeader {String} api_key Users unique access-key.
	 * @apiDescription Completes a participant study event.
	 * @apiErrorExample {json} Error-Response:
	 *                  HTTP/1.1 403 Forbidden
	 *                  {
	 *                  "code": "403",
	 *                  "message": "Request Denied.  Operation not allowed."
	 *                  }
	 * @apiSuccessExample {json} Success-Response:
	 *                    HTTP/1.1 200 OK
	 *                    {
	 *                    "code": "200",
	 *                    "message": "Success."
	 *                    }
	 */
@RequestMapping(value = "/studysubject/{studySubjectOid}/studyevent/{studyEventDefOid}/ordinal/{ordinal}/complete", method = RequestMethod.PUT)
@ResponseBody
public Map<String, String> completeParticipantEvent(HttpServletRequest request, @PathVariable("studySubjectOid") String studySubjectOid, @PathVariable("studyEventDefOid") String studyEventDefOid, @PathVariable("ordinal") Integer ordinal) throws Exception {
    StudySubject subject = studySubjectDao.findByOcOID(studySubjectOid);
    StudyEvent studyEvent = studyEventDao.fetchByStudyEventDefOIDAndOrdinal(studyEventDefOid, ordinal, subject.getStudySubjectId());
    StudyEventDefinition studyEventDefinition = studyEventDefinitionDao.findByStudyEventDefinitionId(studyEvent.getStudyEventDefinition().getStudyEventDefinitionId());
    Study study = studyEventDefinition.getStudy();
    Map<String, String> response = new HashMap<String, String>();
    // Verify this request is allowed.
    if (!mayProceed(study)) {
        response.put("code", String.valueOf(HttpStatus.FORBIDDEN.value()));
        response.put("message", "Request Denied.  Operation not allowed.");
        return response;
    }
    // Get list of eventCRFs
    // By this point we can assume all Participant forms have been submitted at least once and have an event_crf entry.
    // Non-Participant forms may not have an entry.
    List<EventDefinitionCrf> eventDefCrfs = eventDefinitionCrfDao.findByStudyEventDefinitionId(studyEventDefinition.getStudyEventDefinitionId());
    List<EventCrf> eventCrfs = eventCrfDao.findByStudyEventIdStudySubjectId(studyEvent.getStudyEventId(), studySubjectOid);
    try {
        completeData(studyEvent, eventDefCrfs, eventCrfs);
    } catch (Exception e) {
        // Transaction has been rolled back due to an exception.
        logger.error("Error encountered while completing Study Event: " + e.getMessage());
        logger.error(ExceptionUtils.getStackTrace(e));
        response.put("code", String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR.value()));
        response.put("message", "Error encountered while completing participant event.");
        return response;
    }
    response.put("code", String.valueOf(HttpStatus.OK.value()));
    response.put("message", "Success.");
    return response;
//return new ResponseEntity<String>("<message>Success</message>", org.springframework.http.HttpStatus.OK);
}
Also used : EventCrf(org.akaza.openclinica.domain.datamap.EventCrf) Study(org.akaza.openclinica.domain.datamap.Study) StudyEventDefinition(org.akaza.openclinica.domain.datamap.StudyEventDefinition) StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) HashMap(java.util.HashMap) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent) EventDefinitionCrf(org.akaza.openclinica.domain.datamap.EventDefinitionCrf) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

StudyEventDefinition (org.akaza.openclinica.domain.datamap.StudyEventDefinition)8 Study (org.akaza.openclinica.domain.datamap.Study)6 StudySubject (org.akaza.openclinica.domain.datamap.StudySubject)6 StudyEvent (org.akaza.openclinica.domain.datamap.StudyEvent)4 ArrayList (java.util.ArrayList)3 CrfVersion (org.akaza.openclinica.domain.datamap.CrfVersion)3 EventCrf (org.akaza.openclinica.domain.datamap.EventCrf)3 EventDefinitionCrf (org.akaza.openclinica.domain.datamap.EventDefinitionCrf)3 FormLayout (org.akaza.openclinica.domain.datamap.FormLayout)3 Date (java.util.Date)2 UserAccount (org.akaza.openclinica.domain.user.UserAccount)2 ODMcomplexTypeDefinitionStudyEventDef (org.cdisc.ns.odm.v130.ODMcomplexTypeDefinitionStudyEventDef)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 FormLayoutMedia (org.akaza.openclinica.domain.datamap.FormLayoutMedia)1 Item (org.akaza.openclinica.domain.datamap.Item)1 StudyParameterValue (org.akaza.openclinica.domain.datamap.StudyParameterValue)1