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