Search in sources :

Example 26 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class AnonymousFormControllerV2 method getEnketoForm.

/**
 * @api {post} /pages/api/v2/anonymousform/form Retrieve anonymous form URL
 * @apiName getEnketoForm
 * @apiPermission Module participate - enabled
 * @apiVersion 3.8.0
 * @apiParam {String} studyOid Study Oid
 * @apiParam {String} submissionUri Submission Url
 * @apiGroup Form
 * @apiDescription Retrieve anonymous form url.
 * @apiParamExample {json} Request-Example:
 *                  {
 *                  "studyOid": "S_BL101",
 *                  "submissionUri": "abcde"
 *                  }
 * @apiSuccessExample {json} Success-Response:
 *                    HTTP/1.1 200 OK
 *                    {
 *                    "url": "http://localhost:8006/::YYYi?iframe=true&ecid=abb764d026830e98b895ece6d9dcaf3c5e817983cc00a4ebfaabcb6c3700b4d5",
 *                    "offline": "false"
 *                    }
 */
@RequestMapping(value = "/form", method = RequestMethod.POST)
public ResponseEntity<AnonymousUrlResponse> getEnketoForm(@RequestBody HashMap<String, String> map) throws Exception {
    ResourceBundleProvider.updateLocale(new Locale("en_US"));
    EventDefinitionCrfTagService tagService = (EventDefinitionCrfTagService) SpringServletAccess.getApplicationContext(context).getBean("eventDefinitionCrfTagService");
    String formUrl = null;
    String studyOid = map.get("studyOid");
    if (!mayProceed(studyOid))
        return new ResponseEntity<AnonymousUrlResponse>(org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    String submissionUri = map.get("submissionUri");
    if (submissionUri != "" && submissionUri != null) {
        StudyBean study = getStudy(studyOid);
        EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(dataSource);
        ArrayList<EventDefinitionCRFBean> edcBeans = edcdao.findAllSubmissionUriAndStudyId(submissionUri, study.getId());
        if (edcBeans.size() != 0) {
            EventDefinitionCRFBean edcBean = edcBeans.get(0);
            CRFDAO crfdao = new CRFDAO(dataSource);
            CRFVersionDAO cvdao = new CRFVersionDAO(dataSource);
            StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(dataSource);
            CRFVersionBean crfVersionBean = (CRFVersionBean) cvdao.findByPK(edcBean.getDefaultVersionId());
            CRFBean crf = (CRFBean) crfdao.findByPK(crfVersionBean.getCrfId());
            StudyBean sBean = (StudyBean) sdao.findByPK(edcBean.getStudyId());
            StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) seddao.findByPK(edcBean.getStudyEventDefinitionId());
            String tagPath = sedBean.getOid() + "." + crf.getOid();
            boolean isOffline = tagService.getEventDefnCrfOfflineStatus(2, tagPath, true);
            String offline = null;
            if (isOffline)
                offline = "true";
            else
                offline = "false";
            formUrl = createAnonymousEnketoUrl(sBean.getOid(), crfVersionBean, edcBean, isOffline);
            AnonymousUrlResponse anonResponse = new AnonymousUrlResponse(formUrl, offline, crf.getName(), crfVersionBean.getDescription());
            return new ResponseEntity<AnonymousUrlResponse>(anonResponse, org.springframework.http.HttpStatus.OK);
        } else {
            return new ResponseEntity<AnonymousUrlResponse>(org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
        }
    } else {
        return new ResponseEntity<AnonymousUrlResponse>(org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    }
}
Also used : Locale(java.util.Locale) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventDefinitionCrfTagService(org.akaza.openclinica.service.managestudy.EventDefinitionCrfTagService) ResponseEntity(org.springframework.http.ResponseEntity) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 27 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class SDVUtil method getCRFName.

public String getCRFName(int crfVersionId) {
    CRFVersionDAO cRFVersionDAO = new CRFVersionDAO(dataSource);
    CRFDAO cRFDAO = new CRFDAO(dataSource);
    CRFVersionBean versionBean = (CRFVersionBean) cRFVersionDAO.findByPK(crfVersionId);
    if (versionBean != null) {
        CRFBean crfBean = (CRFBean) cRFDAO.findByPK(versionBean.getCrfId());
        if (crfBean != null)
            return crfBean.getName();
    }
    return "";
}
Also used : EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean)

Example 28 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class OpenRosaServices method getFormList.

/**
 * @api {get} /rest2/openrosa/:studyOID/formList Get Form List
 * @apiName getFormList
 * @apiPermission admin
 * @apiVersion 3.8.0
 * @apiParam {String} studyOID Study Oid.
 * @apiGroup Form
 * @apiDescription Retrieves a listing of the available OpenClinica forms.
 * @apiParamExample {json} Request-Example:
 *                  {
 *                  "studyOid": "S_SAMPLTE",
 *                  }
 * @apiSuccessExample {xml} Success-Response:
 *                    HTTP/1.1 200 OK
 *                    {
 *                    <xforms xmlns="http://openrosa.org/xforms/xformsList">
 *                    <xform>
 *                    <formID>F_FIRSTFORM_1</formID>
 *                    <name>First Form</name>
 *                    <majorMinorVersion>1</majorMinorVersion>
 *                    <version>1</version>
 *                    <hash>8678370cd92814d4e3216d58d821403f</hash>
 *                    <downloadUrl>http://oc1.openclinica.com/OpenClinica-web/rest2/openrosa/S_SAMPLTE/formXml?
 *                    formId=F_FIRSTFORM_1</downloadUrl>
 *                    </xform>
 *                    <xform>
 *                    <formID>F_SECONDFORM_1</formID>
 *                    <name>Second Form</name>
 *                    <majorMinorVersion>1</majorMinorVersion>
 *                    <version>1</version>
 *                    <hash>7ee60d1c6516b730bbe9bdbd7cad942f</hash>
 *                    <downloadUrl>http://oc1.openclinica.com/OpenClinica-web/rest2/openrosa/S_SAMPLTE/formXml?
 *                    formId=F_SECONDFORM_1</downloadUrl>
 *                    </xform>
 *                    </xforms>
 */
@GET
@Path("/{studyOID}/formList")
@Produces(MediaType.TEXT_XML)
public String getFormList(@Context HttpServletRequest request, @Context HttpServletResponse response, @PathParam("studyOID") String studyOID, @QueryParam("formID") String crfOID, @RequestHeader("Authorization") String authorization, @Context ServletContext context) throws Exception {
    if (!mayProceedPreview(studyOID))
        return null;
    StudyDAO sdao = new StudyDAO(getDataSource());
    StudyBean study = sdao.findByOid(studyOID);
    CRFDAO cdao = new CRFDAO(getDataSource());
    Collection<CRFBean> crfs = cdao.findAll();
    CRFVersionDAO cVersionDao = new CRFVersionDAO(getDataSource());
    Collection<CRFVersionBean> crfVersions = cVersionDao.findAll();
    CrfVersionMediaDao mediaDao = (CrfVersionMediaDao) SpringServletAccess.getApplicationContext(context).getBean("crfVersionMediaDao");
    try {
        XFormList formList = new XFormList();
        for (CRFBean crf : crfs) {
            for (CRFVersionBean version : crfVersions) {
                if (version.getCrfId() == crf.getId()) {
                    XForm form = new XForm(crf, version);
                    // TODO: them.
                    if (version.getXformName() != null) {
                        form.setHash(DigestUtils.md5Hex(version.getXform()));
                    } else {
                        Calendar cal = Calendar.getInstance();
                        cal.setTime(new Date());
                        form.setHash(DigestUtils.md5Hex(String.valueOf(cal.getTimeInMillis())));
                    }
                    String urlBase = getCoreResources().getDataInfo().getProperty("sysURL").split("/MainMenu")[0];
                    form.setDownloadURL(urlBase + "/rest2/openrosa/" + studyOID + "/formXml?formId=" + version.getOid());
                    List<CrfVersionMedia> mediaList = mediaDao.findByCrfVersionId(version.getId());
                    if (mediaList != null && mediaList.size() > 0) {
                        form.setManifestURL(urlBase + "/rest2/openrosa/" + studyOID + "/manifest?formId=" + version.getOid());
                    }
                    formList.add(form);
                }
            }
        }
        // Create the XML formList using a Castor mapping file.
        XMLContext xmlContext = new XMLContext();
        Mapping mapping = xmlContext.createMapping();
        mapping.loadMapping(getCoreResources().getURL("openRosaFormListMapping.xml"));
        xmlContext.addMapping(mapping);
        Marshaller marshaller = xmlContext.createMarshaller();
        StringWriter writer = new StringWriter();
        marshaller.setWriter(writer);
        marshaller.marshal(formList);
        // Set response headers
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
        Date currentDate = new Date();
        cal.setTime(currentDate);
        SimpleDateFormat format = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss zz");
        format.setCalendar(cal);
        response.setHeader("Content-Type", "text/xml; charset=UTF-8");
        response.setHeader("Date", format.format(currentDate));
        response.setHeader("X-OpenRosa-Version", "1.0");
        return writer.toString();
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
        LOGGER.error(ExceptionUtils.getStackTrace(e));
        return "<Error>" + e.getMessage() + "</Error>";
    }
}
Also used : CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) XFormList(org.akaza.openclinica.web.pform.formlist.XFormList) Marshaller(org.exolab.castor.xml.Marshaller) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) XForm(org.akaza.openclinica.web.pform.formlist.XForm) XMLContext(org.exolab.castor.xml.XMLContext) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) Calendar(java.util.Calendar) Mapping(org.exolab.castor.mapping.Mapping) CrfVersionMediaDao(org.akaza.openclinica.dao.hibernate.CrfVersionMediaDao) Date(java.util.Date) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) CrfVersionMedia(org.akaza.openclinica.domain.datamap.CrfVersionMedia) StringWriter(java.io.StringWriter) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) SimpleDateFormat(java.text.SimpleDateFormat) Path(javax.ws.rs.Path) XPath(javax.xml.xpath.XPath) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 29 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class OpenRosaXmlGenerator method buildForm.

/**
 * @param formId
 * @return
 * @throws Exception
 */
public String buildForm(String formId) throws Exception {
    try {
        CRFVersionDAO versionDAO = new CRFVersionDAO(dataSource);
        CRFVersionBean crfVersion = versionDAO.findByOid(formId);
        CRFDAO crfDAO = new CRFDAO(dataSource);
        CRFBean crf = (CRFBean) crfDAO.findByPK(crfVersion.getCrfId());
        CRFVersionMetadataUtil metadataUtil = new CRFVersionMetadataUtil(dataSource);
        ArrayList<SectionBean> crfSections = metadataUtil.retrieveFormMetadata(crfVersion);
        StringWriter writer = new StringWriter();
        IOUtils.copy(getClass().getResourceAsStream("/properties/xform_template.xml"), writer, "UTF-8");
        String xform = writer.toString();
        Html html = buildJavaXForm(xform);
        int sectionCount = mapBeansToDTO(html, crf, crfVersion, crfSections);
        if (sectionCount > 1)
            setFormPaging(html);
        String xformMinusInstance = buildStringXForm(html);
        String preInstance = xformMinusInstance.substring(0, xformMinusInstance.indexOf("<instance>"));
        String instance = buildInstance(html.getHead().getModel(), crfVersion, crfSections);
        String nodeset = xformMinusInstance.substring(xformMinusInstance.indexOf("</instance>") + "</instance>".length());
        // add nodeset for instanceId
        String postInstance = "<bind calculate=\"concat('uuid:', uuid())\" nodeset=\"/" + crfVersion.getOid() + "/meta/instanceID\" readonly=\"true()\" type=\"string\"/>" + nodeset;
        logger.debug(preInstance + "<instance>\n" + instance + "\n</instance>" + postInstance);
        System.out.println(preInstance + "<instance>\n" + instance + "\n</instance>" + postInstance);
        return preInstance + "<instance>\n" + instance + "\n</instance>" + postInstance;
    } catch (Exception e) {
        log.error(e.getMessage());
        log.error(ExceptionUtils.getStackTrace(e));
        throw new Exception(e);
    }
}
Also used : SectionBean(org.akaza.openclinica.bean.submit.SectionBean) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) StringWriter(java.io.StringWriter) Html(org.akaza.openclinica.web.pform.dto.Html) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) CRFVersionMetadataUtil(org.akaza.openclinica.control.managestudy.CRFVersionMetadataUtil)

Example 30 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class StudyInfoPanel method generateDatasetTree.

private ArrayList generateDatasetTree(ExtractBean eb, DatasetBean db) {
    ArrayList displayData = new ArrayList();
    ArrayList seds = eb.getStudyEvents();
    for (int i = 0; i < seds.size(); i++) {
        // second, iterate through seds
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seds.get(i);
        String repeating = "";
        if (sed.isRepeating()) {
            repeating = " (Repeating) ";
        }
        // if repeating:
        // change string to (Repeating)
        displayData.add(new StudyInfoPanelLine("Study Event Definition", sed.getName() + repeating, true, false));
        ArrayList crfs = sed.getCrfs();
        for (int j = 0; j < crfs.size(); j++) {
            CRFBean cb = (CRFBean) crfs.get(j);
            if (j < crfs.size() - 1 && crfs.size() > 1) {
                displayData.add(new StudyInfoPanelLine("CRF", cb.getName() + " <b>" + ExtractBean.getSEDCRFCode(i + 1, j + 1) + "</b>", false, false));
            } else {
                // last crf
                displayData.add(new StudyInfoPanelLine("CRF", cb.getName() + " <b>" + ExtractBean.getSEDCRFCode(i + 1, j + 1) + "</b>", false, true));
            }
        // third, iterate through crf versions
        }
    }
    return displayData;
}
Also used : ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean)

Aggregations

CRFBean (org.akaza.openclinica.bean.admin.CRFBean)138 ArrayList (java.util.ArrayList)95 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)78 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)78 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)70 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)67 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)63 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)56 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)44 HashMap (java.util.HashMap)43 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)43 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)40 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)37 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)29 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)27 Iterator (java.util.Iterator)26 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)26 DisplayEventCRFBean (org.akaza.openclinica.bean.submit.DisplayEventCRFBean)22 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)21 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)20