use of org.akaza.openclinica.service.crfdata.xform.PFormCacheSubjectContextEntry 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);
}
Aggregations