Search in sources :

Example 1 with Section

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;
}
Also used : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) CrfBean(org.akaza.openclinica.domain.datamap.CrfBean) CrfVersion(org.akaza.openclinica.domain.datamap.CrfVersion) Section(org.akaza.openclinica.domain.datamap.Section) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Date (java.util.Date)1 CrfBean (org.akaza.openclinica.domain.datamap.CrfBean)1 CrfVersion (org.akaza.openclinica.domain.datamap.CrfVersion)1 FormLayout (org.akaza.openclinica.domain.datamap.FormLayout)1 Section (org.akaza.openclinica.domain.datamap.Section)1 Transactional (org.springframework.transaction.annotation.Transactional)1