use of org.akaza.openclinica.web.pform.EnketoAPI 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);
}
use of org.akaza.openclinica.web.pform.EnketoAPI 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