Search in sources :

Example 6 with ItemGroupMetadata

use of org.akaza.openclinica.domain.datamap.ItemGroupMetadata in project OpenClinica by OpenClinica.

the class ItemGroupMetadataDao method findByItemCrfVersion.

public ItemGroupMetadata findByItemCrfVersion(int itemId, int crfVersionId) {
    Query q = getCurrentSession().createQuery(findByItemCrfVersionQuery);
    q.setParameter("itemid", itemId);
    q.setParameter("crfversionid", crfVersionId);
    return (ItemGroupMetadata) q.uniqueResult();
}
Also used : Query(org.hibernate.query.Query) ItemGroupMetadata(org.akaza.openclinica.domain.datamap.ItemGroupMetadata)

Example 7 with ItemGroupMetadata

use of org.akaza.openclinica.domain.datamap.ItemGroupMetadata in project OpenClinica by OpenClinica.

the class XformMetaDataService method createGroups.

private void createGroups(XformContainer container, CrfBean crf, CrfVersion crfVersion, FormLayout formLayout, Section section, UserAccountBean ub, Errors errors) throws Exception {
    Integer itemOrdinal = 1;
    ArrayList<String> usedGroupOids = new ArrayList<String>();
    ArrayList<String> usedItemOids = new ArrayList<String>();
    // for (Group htmlGroup : htmlGroups) {
    for (XformGroup xformGroup : container.getGroups()) {
        // XformGroup xformGroup = container.findGroupByRef(htmlGroup.getRef());
        ItemGroup itemGroup = itemGroupDao.findByNameCrfId(xformGroup.getGroupName(), crf);
        if (itemGroup == null) {
            itemGroup = new ItemGroup();
            itemGroup.setName(xformGroup.getGroupName());
            itemGroup.setLayoutGroupPath(xformGroup.getGroupPath());
            itemGroup.setCrf(crf);
            itemGroup.setStatus(org.akaza.openclinica.domain.Status.AVAILABLE);
            itemGroup.setUserAccount(userDao.findById(ub.getId()));
            itemGroup.setOcOid(xformGroup.getGroupOid());
            usedGroupOids.add(itemGroup.getOcOid());
            itemGroup = itemGroupDao.saveOrUpdate(itemGroup);
        } else {
            itemGroup.setName(xformGroup.getGroupName());
            itemGroup = itemGroupDao.saveOrUpdate(itemGroup);
        }
        boolean isRepeating = xformGroup.isRepeating();
        for (XformItem xformItem : xformGroup.getItems()) {
            Item item = createItem(xformGroup, xformItem, crf, ub, usedItemOids, errors);
            if (item != null) {
                ResponseType responseType = getResponseType(xformItem);
                ResponseSet responseSet = responseSetService.getResponseSet(xformItem, crfVersion, responseType, item, errors);
                // add if statement
                ItemFormMetadata ifmd = itemFormMetadataDao.findByItemCrfVersion(item.getItemId(), crfVersion.getCrfVersionId());
                if (ifmd == null) {
                    ifmd = createItemFormMetadata(xformItem, item, responseSet, section, crfVersion, itemOrdinal);
                } else {
                    ifmd.setRequired(xformItem.isRequired());
                    ifmd.setLeftItemText(xformItem.getLeftItemText());
                    ifmd.setItem(item);
                    ifmd.setResponseSet(responseSet);
                    ifmd = itemFormMetadataDao.saveOrUpdate(ifmd);
                }
                ArrayList<VersioningMap> vm = versioningMapDao.findByVersionIdFormLayoutIdAndItemId(crfVersion.getCrfVersionId(), formLayout.getFormLayoutId(), item.getItemId(), itemOrdinal);
                if (vm.size() == 0) {
                    createVersioningMap(crfVersion, item, formLayout, xformItem.getItemOrderInForm());
                }
                //
                ItemGroupMetadata igmd = itemGroupMetadataDao.findByItemCrfVersion(item.getItemId(), crfVersion.getCrfVersionId());
                if (igmd == null) {
                    igmd = createItemGroupMetadata(item, crfVersion, itemGroup, isRepeating, itemOrdinal);
                }
                itemOrdinal++;
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) XformGroup(org.akaza.openclinica.domain.xform.XformGroup) ResponseSet(org.akaza.openclinica.domain.datamap.ResponseSet) ItemFormMetadata(org.akaza.openclinica.domain.datamap.ItemFormMetadata) VersioningMap(org.akaza.openclinica.domain.datamap.VersioningMap) ResponseType(org.akaza.openclinica.domain.datamap.ResponseType) Item(org.akaza.openclinica.domain.datamap.Item) XformItem(org.akaza.openclinica.domain.xform.XformItem) FileItem(org.apache.commons.fileupload.FileItem) DiskFileItem(org.apache.commons.fileupload.disk.DiskFileItem) XformItem(org.akaza.openclinica.domain.xform.XformItem) ItemGroup(org.akaza.openclinica.domain.datamap.ItemGroup) ItemGroupMetadata(org.akaza.openclinica.domain.datamap.ItemGroupMetadata)

Aggregations

ItemGroupMetadata (org.akaza.openclinica.domain.datamap.ItemGroupMetadata)7 ItemData (org.akaza.openclinica.domain.datamap.ItemData)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Item (org.akaza.openclinica.domain.datamap.Item)3 ItemFormMetadata (org.akaza.openclinica.domain.datamap.ItemFormMetadata)3 Date (java.util.Date)2 ItemGroup (org.akaza.openclinica.domain.datamap.ItemGroup)2 Errors (org.springframework.validation.Errors)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Configuration (freemarker.template.Configuration)1 Template (freemarker.template.Template)1 File (java.io.File)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 QueriesBean (org.akaza.openclinica.core.form.xform.QueriesBean)1 CrfBean (org.akaza.openclinica.domain.datamap.CrfBean)1 CrfVersion (org.akaza.openclinica.domain.datamap.CrfVersion)1