Search in sources :

Example 1 with PFormCache

use of org.akaza.openclinica.web.pform.PFormCache 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 2 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, FormLayoutBean formLayout, EventDefinitionCRFBean edcBean, boolean isOffline) throws Exception {
    StudyBean parentStudyBean = getParentStudy(studyOID);
    PFormCache cache = PFormCache.getInstance(context);
    String enketoURL = cache.getPFormURL(parentStudyBean.getOid(), formLayout.getOid(), isOffline);
    String contextHash = cache.putAnonymousFormContext(studyOID, formLayout.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 " + formLayout.getName() + "= " + url);
    return url;
}
Also used : StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) PFormCache(org.akaza.openclinica.web.pform.PFormCache)

Example 3 with PFormCache

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

the class OdmController method createEditUrl.

private String createEditUrl(String studyOID, FormLayoutBean formLayout, StudyEventBean nextEvent, String ssoid) throws Exception {
    PFormCache cache = PFormCache.getInstance(context);
    String contextHash = cache.putSubjectContext(ssoid, String.valueOf(nextEvent.getStudyEventDefinitionId()), String.valueOf(nextEvent.getSampleOrdinal()), formLayout.getOid());
    String editURL = CoreResources.getField("sysURL.base") + "pages/api/v1/editform/" + studyOID + "/url";
    String url = editURL + "?" + FORM_CONTEXT + "=" + contextHash;
    logger.debug("Edit URL for " + formLayout.getName() + "= " + url);
    return url;
}
Also used : PFormCache(org.akaza.openclinica.web.pform.PFormCache)

Example 4 with PFormCache

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

the class EditFormController method fetchEditUrl.

private String fetchEditUrl(String studyOID, CRFVersionBean crfVersion, int studyEventDefinitionId) throws Exception {
    StudyBean parentStudyBean = getParentStudy(studyOID);
    PFormCache cache = PFormCache.getInstance(context);
    String enketoURL = cache.getPFormURL(parentStudyBean.getOid(), crfVersion.getOid());
    String contextHash = cache.putAnonymousFormContext(studyOID, crfVersion.getOid(), studyEventDefinitionId);
    String 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 5 with PFormCache

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

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