Search in sources :

Example 6 with PFormCache

use of org.akaza.openclinica.web.pform.PFormCache in project OpenClinica by OpenClinica.

the class OdmController method createEnketoUrl.

private String createEnketoUrl(String studyOID, CRFVersionBean crfVersion, StudyEventBean nextEvent, String ssoid) throws Exception {
    PFormCache cache = PFormCache.getInstance(context);
    String enketoURL = cache.getPFormURL(studyOID, crfVersion.getOid());
    String contextHash = cache.putSubjectContext(ssoid, String.valueOf(nextEvent.getStudyEventDefinitionId()), String.valueOf(nextEvent.getSampleOrdinal()), crfVersion.getOid());
    String url = enketoURL + "?" + FORM_CONTEXT + "=" + contextHash;
    logger.debug("Enketo URL for " + crfVersion.getName() + "= " + url);
    return url;
}
Also used : PFormCache(org.akaza.openclinica.web.pform.PFormCache)

Example 7 with PFormCache

use of org.akaza.openclinica.web.pform.PFormCache in project OpenClinica by OpenClinica.

the class AnonymousFormControllerV2 method createAnonymousEnketoUrl.

private String createAnonymousEnketoUrl(String studyOID, CRFVersionBean crfVersion, EventDefinitionCRFBean edcBean, boolean isOffline) throws Exception {
    StudyBean parentStudyBean = getParentStudy(studyOID);
    PFormCache cache = PFormCache.getInstance(context);
    String enketoURL = cache.getPFormURL(parentStudyBean.getOid(), crfVersion.getOid(), isOffline);
    String contextHash = cache.putAnonymousFormContext(studyOID, crfVersion.getOid(), edcBean.getStudyEventDefinitionId());
    String url = null;
    if (isOffline)
        url = enketoURL.split("#", 2)[0] + "?" + FORM_CONTEXT + "=" + contextHash + "#" + enketoURL.split("#", 2)[1];
    else
        url = enketoURL + "?" + FORM_CONTEXT + "=" + contextHash;
    logger.debug("Enketo URL for " + crfVersion.getName() + "= " + url);
    return url;
}
Also used : StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) PFormCache(org.akaza.openclinica.web.pform.PFormCache)

Example 8 with PFormCache

use of org.akaza.openclinica.web.pform.PFormCache in project OpenClinica by OpenClinica.

the class OpenRosaSubmissionController method doFieldDeletion.

/**
     * @api {post} /pages/api/v2/editform/:studyOid/fieldsubmission Submit form data
     * @apiName doSubmission
     * @apiPermission admin
     * @apiVersion 3.8.0
     * @apiParam {String} studyOid Study Oid.
     * @apiParam {String} ecid Key that will be used to look up subject context information while processing submission.
     * @apiGroup Form
     * @apiDescription Submits the data from a completed form.
     */
@RequestMapping(value = "/{studyOID}/fieldsubmission", method = RequestMethod.DELETE)
public ResponseEntity<String> doFieldDeletion(HttpServletRequest request, HttpServletResponse response, @PathVariable("studyOID") String studyOID, @RequestParam(FORM_CONTEXT) String ecid) {
    logger.info("Processing xform field deletion.");
    HashMap<String, String> subjectContext = null;
    Locale locale = LocaleResolver.getLocale(request);
    DataBinder dataBinder = new DataBinder(null);
    Errors errors = dataBinder.getBindingResult();
    Study study = studyDao.findByOcOID(studyOID);
    String requestBody = null;
    String instanceId = null;
    HashMap<String, String> map = new HashMap();
    ArrayList<HashMap> listOfUploadFilePaths = new ArrayList();
    try {
        // Verify Study is allowed to submit
        if (!mayProceed(study)) {
            logger.info("Field Deletions to the study not allowed.  Aborting field submission.");
            return new ResponseEntity<String>(HttpStatus.NOT_ACCEPTABLE);
        }
        String dir = getAttachedFilePath(studyOID);
        FileProperties fileProperties = new FileProperties();
        DiskFileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(factory);
        upload.setFileSizeMax(fileProperties.getFileSizeMax());
        List<FileItem> items = upload.parseRequest(request);
        for (FileItem item : items) {
            if (item.getFieldName().equals("instance_id")) {
                instanceId = item.getString();
            } else if (item.getFieldName().equals("xml_submission_fragment_file")) {
                requestBody = item.getString("UTF-8");
            } else if (item.getContentType() != null) {
                if (!new File(dir).exists())
                    new File(dir).mkdirs();
                File file = processUploadedFile(item, dir);
                map.put(item.getFieldName(), file.getPath());
            }
        }
        listOfUploadFilePaths.add(map);
        if (instanceId == null) {
            logger.info("Field Submissions to the study not allowed without a valid instanceId.  Aborting field submission.");
            return new ResponseEntity<String>(HttpStatus.NOT_ACCEPTABLE);
        }
        // Load user context from ecid
        PFormCache cache = PFormCache.getInstance(context);
        subjectContext = cache.getSubjectContext(ecid);
        // Execute save as Hibernate transaction to avoid partial imports
        openRosaSubmissionService.processFieldSubmissionRequest(study, subjectContext, instanceId, requestBody, errors, locale, listOfUploadFilePaths, SubmissionContainer.FieldRequestTypeEnum.DELETE_FIELD);
    } catch (Exception e) {
        logger.error("Exception while processing xform submission.");
        logger.error(e.getMessage());
        logger.error(ExceptionUtils.getStackTrace(e));
        if (!errors.hasErrors()) {
            // Send a failure response
            logger.info("Submission caused internal error.  Sending error response.");
            return new ResponseEntity<String>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }
    if (!errors.hasErrors()) {
        // JsonLog submission with Participate
        if (isParticipantSubmission(subjectContext))
            notifier.notify(studyOID, subjectContext);
        logger.info("Completed xform field submission. Sending successful response");
        String responseMessage = "<OpenRosaResponse xmlns=\"http://openrosa.org/http/response\">" + "<message>success</message>" + "</OpenRosaResponse>";
        return new ResponseEntity<String>(responseMessage, HttpStatus.CREATED);
    } else {
        logger.info("Field Submission contained errors. Sending error response");
        return new ResponseEntity<String>(HttpStatus.NOT_ACCEPTABLE);
    }
}
Also used : Locale(java.util.Locale) Study(org.akaza.openclinica.domain.datamap.Study) FileProperties(org.akaza.openclinica.bean.rule.FileProperties) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) Errors(org.springframework.validation.Errors) FileItem(org.apache.commons.fileupload.FileItem) ResponseEntity(org.springframework.http.ResponseEntity) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) DataBinder(org.springframework.validation.DataBinder) File(java.io.File) PFormCache(org.akaza.openclinica.web.pform.PFormCache) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with PFormCache

use of org.akaza.openclinica.web.pform.PFormCache in project OpenClinica by OpenClinica.

the class OdmController method createEnketoUrl.

private String createEnketoUrl(String studyOID, FormLayoutBean formLayout, StudyEventBean nextEvent, String ssoid) throws Exception {
    PFormCache cache = PFormCache.getInstance(context);
    String enketoURL = cache.getPFormURL(studyOID, formLayout.getOid());
    String contextHash = cache.putSubjectContext(ssoid, String.valueOf(nextEvent.getStudyEventDefinitionId()), String.valueOf(nextEvent.getSampleOrdinal()), formLayout.getOid());
    String url = enketoURL + "?" + FORM_CONTEXT + "=" + contextHash;
    logger.debug("Enketo URL for " + formLayout.getName() + "= " + url);
    return url;
}
Also used : PFormCache(org.akaza.openclinica.web.pform.PFormCache)

Example 10 with PFormCache

use of org.akaza.openclinica.web.pform.PFormCache 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)

Aggregations

PFormCache (org.akaza.openclinica.web.pform.PFormCache)13 Study (org.akaza.openclinica.domain.datamap.Study)5 ResponseEntity (org.springframework.http.ResponseEntity)5 FileItem (org.apache.commons.fileupload.FileItem)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Locale (java.util.Locale)3 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)3 FileProperties (org.akaza.openclinica.bean.rule.FileProperties)3 StudyEvent (org.akaza.openclinica.domain.datamap.StudyEvent)3 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)3 DiskFileItemFactory (org.apache.commons.fileupload.disk.DiskFileItemFactory)3 ServletFileUpload (org.apache.commons.fileupload.servlet.ServletFileUpload)3 DataBinder (org.springframework.validation.DataBinder)3 Errors (org.springframework.validation.Errors)3 CrfVersion (org.akaza.openclinica.domain.datamap.CrfVersion)2 EventCrf (org.akaza.openclinica.domain.datamap.EventCrf)2 FormLayout (org.akaza.openclinica.domain.datamap.FormLayout)2