use of org.akaza.openclinica.domain.datamap.Section in project OpenClinica by OpenClinica.
the class XformMetaDataService method createCRFMetaData.
@Transactional
public FormLayout createCRFMetaData(CrfMetaDataObject cmdObject) throws Exception {
CrfVersion crfVersion = null;
FormLayout formLayout = null;
CrfBean crfBean = null;
Section section = null;
crfBean = (CrfBean) crfDao.findByOcOID(cmdObject.crf.getOcoid());
if (crfBean != null) {
crfBean.setUpdateId(cmdObject.ub.getId());
crfBean.setDateUpdated(new Date());
crfBean = crfDao.saveOrUpdate(crfBean);
formLayout = formLayoutDao.findByOcOID(cmdObject.version.getOcoid());
if (formLayout == null) {
formLayout = new FormLayout();
formLayout = populateFormLayout(formLayout, crfBean, cmdObject);
formLayout = formLayoutDao.saveOrUpdate(formLayout);
}
crfVersion = crfVersionDao.findAllByCrfId(crfBean.getCrfId()).get(0);
section = sectionDao.findByCrfVersionOrdinal(crfVersion.getCrfVersionId(), 1);
} else {
crfBean = new CrfBean();
crfBean = populateCrf(crfBean, cmdObject);
Integer crfId = (Integer) crfDao.save(crfBean);
crfBean.setCrfId(crfId);
// Create new Form Layout
formLayout = new FormLayout();
formLayout = populateFormLayout(formLayout, crfBean, cmdObject);
formLayout = formLayoutDao.saveOrUpdate(formLayout);
// Create new CRF Version
crfVersion = new CrfVersion();
crfVersion = populateCrfVersion(crfBean, crfVersion, cmdObject);
crfVersion = crfVersionDao.saveOrUpdate(crfVersion);
// Create Section
section = sectionDao.findByCrfVersionOrdinal(crfVersion.getCrfVersionId(), 1);
if (section == null) {
section = new Section();
section = populateCrfVersion(section, crfVersion, cmdObject);
sectionDao.saveOrUpdate(section);
section = sectionDao.findByCrfVersionOrdinal(crfVersion.getCrfVersionId(), 1);
}
}
createGroups(cmdObject.container, crfBean, crfVersion, formLayout, section, cmdObject.ub, cmdObject.errors);
if (cmdObject.errors.hasErrors()) {
logger.error("Encounter validation errors while saving CRF. Rolling back transaction.");
throw new RuntimeException("Encountered validation errors while saving CRF.");
}
return formLayout;
}
Aggregations