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