Search in sources :

Example 1 with EnketoCredentials

use of org.akaza.openclinica.service.crfdata.xform.EnketoCredentials 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 EnketoCredentials

use of org.akaza.openclinica.service.crfdata.xform.EnketoCredentials in project OpenClinica by OpenClinica.

the class ParticipantFormServlet method getCredentials.

private EnketoCredentials getCredentials() throws Exception {
    EnketoCredentials credentials = null;
    Map<String, EnketoCredentials> credentialsMap = (Map<String, EnketoCredentials>) session.getAttribute("EnketoCredentialsMap");
    if (credentialsMap == null) {
        credentialsMap = new HashMap<String, EnketoCredentials>();
        credentials = EnketoCredentials.getInstance(currentStudy.getOid());
        credentialsMap.put(currentStudy.getOid(), credentials);
        session.setAttribute("EnketoCredentialsMap", credentialsMap);
    } else if (credentialsMap.get(currentStudy.getOid()) == null) {
        credentials = EnketoCredentials.getInstance(currentStudy.getOid());
        credentialsMap.put(currentStudy.getOid(), credentials);
    } else
        credentials = credentialsMap.get(currentStudy.getOid());
    return credentials;
}
Also used : EnketoCredentials(org.akaza.openclinica.service.crfdata.xform.EnketoCredentials) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with EnketoCredentials

use of org.akaza.openclinica.service.crfdata.xform.EnketoCredentials in project OpenClinica by OpenClinica.

the class ParticipantFormServlet method processRequest.

@Override
protected void processRequest() throws Exception {
    String crf_oid = request.getParameter(CRF_ID);
    String formURL = null;
    // Build Enketo URL for CRF version.
    if (currentStudy.getStudyParameterConfig().getParticipantPortal().equals("enabled")) {
        EnketoCredentials credentials = getCredentials();
        EnketoAPI enketo = new EnketoAPI(credentials);
        formURL = enketo.getFormPreviewURL(crf_oid);
        if (!formURL.equals("")) {
            response.sendRedirect(formURL);
        } else {
            if (credentials.getServerUrl() == null) {
                addPageMessage(respage.getString("pform_preview_missing_url"));
            } else {
                if ((credentials.getApiKey() != null) && (credentials.getOcInstanceUrl() != null)) {
                    addPageMessage(respage.getString("pform_preview_forbidden"));
                } else {
                    addPageMessage(respage.getString("participate_not_available"));
                }
            }
            forwardPage(Page.MENU_SERVLET);
        }
    }
}
Also used : EnketoAPI(org.akaza.openclinica.service.crfdata.xform.EnketoAPI) EnketoCredentials(org.akaza.openclinica.service.crfdata.xform.EnketoCredentials)

Aggregations

EnketoCredentials (org.akaza.openclinica.service.crfdata.xform.EnketoCredentials)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 FormLayoutDao (org.akaza.openclinica.dao.hibernate.FormLayoutDao)1 StudyEventDao (org.akaza.openclinica.dao.hibernate.StudyEventDao)1 FormLayout (org.akaza.openclinica.domain.datamap.FormLayout)1 Study (org.akaza.openclinica.domain.datamap.Study)1 StudyEvent (org.akaza.openclinica.domain.datamap.StudyEvent)1 EnketoUrlService (org.akaza.openclinica.service.crfdata.EnketoUrlService)1 EnketoAPI (org.akaza.openclinica.service.crfdata.xform.EnketoAPI)1 PFormCacheSubjectContextEntry (org.akaza.openclinica.service.crfdata.xform.PFormCacheSubjectContextEntry)1 PFormCache (org.akaza.openclinica.web.pform.PFormCache)1