Search in sources :

Example 1 with EnketoAPI

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);
}
Also used : EventCrf(org.akaza.openclinica.domain.datamap.EventCrf) EnketoAPI(org.akaza.openclinica.web.pform.EnketoAPI) StudyEventDefinition(org.akaza.openclinica.domain.datamap.StudyEventDefinition) ResponseEntity(org.springframework.http.ResponseEntity) StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) CrfVersion(org.akaza.openclinica.domain.datamap.CrfVersion) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent) PFormCache(org.akaza.openclinica.web.pform.PFormCache) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with EnketoAPI

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);
        }
    }
}
Also used : EnketoAPI(org.akaza.openclinica.web.pform.EnketoAPI) EnketoCredentials(org.akaza.openclinica.web.pform.EnketoCredentials)

Aggregations

EnketoAPI (org.akaza.openclinica.web.pform.EnketoAPI)2 CrfVersion (org.akaza.openclinica.domain.datamap.CrfVersion)1 EventCrf (org.akaza.openclinica.domain.datamap.EventCrf)1 StudyEvent (org.akaza.openclinica.domain.datamap.StudyEvent)1 StudyEventDefinition (org.akaza.openclinica.domain.datamap.StudyEventDefinition)1 StudySubject (org.akaza.openclinica.domain.datamap.StudySubject)1 EnketoCredentials (org.akaza.openclinica.web.pform.EnketoCredentials)1 PFormCache (org.akaza.openclinica.web.pform.PFormCache)1 ResponseEntity (org.springframework.http.ResponseEntity)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1