Search in sources :

Example 1 with FormLayoutDao

use of org.akaza.openclinica.dao.hibernate.FormLayoutDao 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)

Aggregations

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 EnketoCredentials (org.akaza.openclinica.service.crfdata.xform.EnketoCredentials)1 PFormCacheSubjectContextEntry (org.akaza.openclinica.service.crfdata.xform.PFormCacheSubjectContextEntry)1 PFormCache (org.akaza.openclinica.web.pform.PFormCache)1