Search in sources :

Example 21 with FormLayoutBean

use of org.akaza.openclinica.bean.submit.FormLayoutBean 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);
        FormLayoutDAO fldao = new FormLayoutDAO<>(dataSource);
        FormLayoutBean formLayout = fldao.findByOid(formId);
        CRFDAO crfDAO = new CRFDAO(dataSource);
        CRFBean crf = (CRFBean) crfDAO.findByPK(formLayout.getCrfId());
        CRFVersionMetadataUtil metadataUtil = new CRFVersionMetadataUtil(dataSource);
        ArrayList<SectionBean> crfSections = metadataUtil.retrieveFormMetadata(formLayout);
        ArrayList<CRFVersionBean> crfVersions = versionDAO.findAllByCRFId(crf.getId());
        CRFVersionBean crfVersion = crfVersions.get(0);
        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(), formLayout, crfVersion, crfSections);
        String nodeset = xformMinusInstance.substring(xformMinusInstance.indexOf("</instance>") + "</instance>".length());
        // add nodeset for instanceId
        String postInstance = "<bind calculate=\"concat('uuid:', uuid())\" nodeset=\"/" + formLayout.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 : CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean) Html(org.akaza.openclinica.web.pform.dto.Html) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) StringWriter(java.io.StringWriter) FormLayoutDAO(org.akaza.openclinica.dao.submit.FormLayoutDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) CRFVersionMetadataUtil(org.akaza.openclinica.control.managestudy.CRFVersionMetadataUtil)

Example 22 with FormLayoutBean

use of org.akaza.openclinica.bean.submit.FormLayoutBean in project OpenClinica by OpenClinica.

the class FormLayoutDAO method findByPK.

public EntityBean findByPK(int ID) {
    FormLayoutBean eb = new FormLayoutBean();
    this.setTypesExpected();
    HashMap variables = new HashMap();
    variables.put(new Integer(1), new Integer(ID));
    String sql = digester.getQuery("findByPK");
    ArrayList alist = this.select(sql, variables);
    Iterator it = alist.iterator();
    if (it.hasNext()) {
        eb = (FormLayoutBean) this.getEntityFromHashMap((HashMap) it.next());
    }
    return eb;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean)

Example 23 with FormLayoutBean

use of org.akaza.openclinica.bean.submit.FormLayoutBean in project OpenClinica by OpenClinica.

the class FormLayoutDAO method findAllActiveByCRF.

public Collection findAllActiveByCRF(int crfId) {
    this.setTypesExpected();
    HashMap variables = new HashMap();
    variables.put(new Integer(1), new Integer(crfId));
    String sql = digester.getQuery("findAllActiveByCRF");
    ArrayList alist = this.select(sql, variables);
    ArrayList al = new ArrayList();
    Iterator it = alist.iterator();
    while (it.hasNext()) {
        FormLayoutBean eb = (FormLayoutBean) this.getEntityFromHashMap((HashMap) it.next());
        al.add(eb);
    }
    return al;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean)

Example 24 with FormLayoutBean

use of org.akaza.openclinica.bean.submit.FormLayoutBean in project OpenClinica by OpenClinica.

the class FormLayoutDAO method findByOid.

public FormLayoutBean findByOid(String oid) {
    FormLayoutBean FormLayoutBean = new FormLayoutBean();
    this.unsetTypeExpected();
    setTypesExpected();
    HashMap variables = new HashMap();
    variables.put(new Integer(1), oid);
    String sql = digester.getQuery("findByOID");
    ArrayList rows = this.select(sql, variables);
    Iterator it = rows.iterator();
    if (it.hasNext()) {
        FormLayoutBean = (FormLayoutBean) this.getEntityFromHashMap((HashMap) it.next());
        return FormLayoutBean;
    } else {
        return null;
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean)

Example 25 with FormLayoutBean

use of org.akaza.openclinica.bean.submit.FormLayoutBean in project OpenClinica by OpenClinica.

the class FormLayoutDAO method getEntityFromHashMap.

public Object getEntityFromHashMap(HashMap hm) {
    // CRF_VERSION_ID NAME DESCRIPTION
    // CRF_ID STATUS_ID DATE_CREATED DATE_UPDATED
    // OWNER_ID REVISION_NUMBER UPDATE_ID
    FormLayoutBean eb = new FormLayoutBean();
    super.setEntityAuditInformation(eb, hm);
    eb.setId(((Integer) hm.get("form_layout_id")).intValue());
    eb.setName((String) hm.get("name"));
    eb.setDescription((String) hm.get("description"));
    eb.setCrfId(((Integer) hm.get("crf_id")).intValue());
    eb.setRevisionNotes((String) hm.get("revision_notes"));
    eb.setOid((String) hm.get("oc_oid"));
    eb.setXform((String) hm.get("xform"));
    eb.setXformName((String) hm.get("xform_name"));
    eb.setUrl((String) hm.get("url"));
    return eb;
}
Also used : FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean)

Aggregations

FormLayoutBean (org.akaza.openclinica.bean.submit.FormLayoutBean)41 ArrayList (java.util.ArrayList)32 FormLayoutDAO (org.akaza.openclinica.dao.submit.FormLayoutDAO)23 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)22 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)21 HashMap (java.util.HashMap)20 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)16 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)14 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)13 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)12 Iterator (java.util.Iterator)10 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)10 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)9 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)9 StudyParameterValueDAO (org.akaza.openclinica.dao.service.StudyParameterValueDAO)8 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)8 DisplayEventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean)7 DisplayEventCRFBean (org.akaza.openclinica.bean.submit.DisplayEventCRFBean)7 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)6 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)5