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);
}
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;
}
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);
}
}
}
Aggregations