Search in sources :

Example 1 with ItemMetadata

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

the class ItemProcessor method processGroupItems.

private void processGroupItems(ArrayList<HashMap> listOfUploadFilePaths, HashMap<Integer, Set<Integer>> groupOrdinalMapping, Node groupNode, ItemGroup itemGroup, SubmissionContainer container) throws Exception {
    String itemName;
    String itemValue;
    if (itemGroup != null && !groupOrdinalMapping.containsKey(itemGroup.getItemGroupId())) {
        groupOrdinalMapping.put(itemGroup.getItemGroupId(), new TreeSet<Integer>());
    }
    NodeList itemNodeList = groupNode.getChildNodes();
    // Item loop
    for (int m = 0; m < itemNodeList.getLength(); m = m + 1) {
        Node itemNode = itemNodeList.item(m);
        if (ShouldProcessItemNode(itemNode)) {
            itemName = itemNode.getNodeName().trim();
            itemValue = itemNode.getTextContent();
            Item item = lookupItem(itemName, container.getCrfVersion());
            if (item == null) {
                logger.error("Failed to lookup item: '" + itemName + "'.  Continuing with submission.");
                continue;
            }
            ItemMetadata im = itemGroupMetadataDao.findMetadataByItemCrfVersion(item.getItemId(), container.getCrfVersion().getCrfVersionId());
            ItemGroupMetadata itemGroupMeta = im.getIgm();
            ItemFormMetadata itemFormMetadata = im.getIfm();
            // ItemFormMetadata itemFormMetadata = itemFormMetadataDao.findByItemCrfVersion(item.getItemId(),
            // crfVersion.getCrfVersionId());
            Integer itemOrdinal = getItemOrdinal(groupNode, itemGroupMeta.isRepeatingGroup(), container.getItems(), item);
            // Convert space separated Enketo multiselect values to comma separated OC multiselect values
            Integer responseTypeId = itemFormMetadata.getResponseSet().getResponseType().getResponseTypeId();
            if (responseTypeId == 3 || responseTypeId == 7) {
                itemValue = itemValue.replaceAll(" ", ",");
            }
            if (responseTypeId == 4) {
                for (HashMap uploadFilePath : listOfUploadFilePaths) {
                    if ((boolean) uploadFilePath.containsKey(itemValue) && itemValue != "") {
                        itemValue = (String) uploadFilePath.get(itemValue);
                        break;
                    }
                }
            }
            // Build set of submitted row numbers to be used to find deleted DB rows later
            Set<Integer> ordinals = groupOrdinalMapping.get(itemGroup.getItemGroupId());
            ordinals.add(itemOrdinal);
            groupOrdinalMapping.put(itemGroup.getItemGroupId(), ordinals);
            ItemData newItemData = createItemData(item, itemValue, itemOrdinal, container);
            Errors itemErrors = validateItemData(newItemData, item, responseTypeId);
            if (itemErrors.hasErrors()) {
                container.getErrors().addAllErrors(itemErrors);
                throw new Exception("Item validation error.  Rolling back submission changes.");
            } else {
                container.getItems().add(newItemData);
            }
            ItemData existingItemData = itemDataDao.findByItemEventCrfOrdinal(item.getItemId(), container.getEventCrf().getEventCrfId(), itemOrdinal);
            if (existingItemData == null) {
                // No existing value, create new item.
                if (newItemData.getOrdinal() < 0) {
                    newItemData.setOrdinal(itemDataDao.getMaxGroupRepeat(container.getEventCrf().getEventCrfId(), item.getItemId()) + 1);
                    groupOrdinalMapping.get(itemGroup.getItemGroupId()).add(newItemData.getOrdinal());
                }
                newItemData.setStatus(Status.UNAVAILABLE);
                newItemData.setInstanceId(container.getInstanceId());
                itemDataDao.saveOrUpdate(newItemData);
            } else if (existingItemData.getValue().equals(newItemData.getValue())) {
            // Existing item. Value unchanged. Do nothing.
            } else {
                // Existing item. Value changed. Update existing value.
                existingItemData.setValue(newItemData.getValue());
                existingItemData.setUpdateId(container.getUser().getUserId());
                existingItemData.setDateUpdated(new Date());
                itemDataDao.saveOrUpdate(existingItemData);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ItemFormMetadata(org.akaza.openclinica.domain.datamap.ItemFormMetadata) Date(java.util.Date) ItemMetadata(org.akaza.openclinica.domain.datamap.ItemMetadata) Item(org.akaza.openclinica.domain.datamap.Item) Errors(org.springframework.validation.Errors) ItemGroupMetadata(org.akaza.openclinica.domain.datamap.ItemGroupMetadata) ItemData(org.akaza.openclinica.domain.datamap.ItemData)

Example 2 with ItemMetadata

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

the class ItemGroupMetadataDao method findMetadataByItemCrfVersion.

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

Aggregations

ItemMetadata (org.akaza.openclinica.domain.datamap.ItemMetadata)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Item (org.akaza.openclinica.domain.datamap.Item)1 ItemData (org.akaza.openclinica.domain.datamap.ItemData)1 ItemFormMetadata (org.akaza.openclinica.domain.datamap.ItemFormMetadata)1 ItemGroupMetadata (org.akaza.openclinica.domain.datamap.ItemGroupMetadata)1 Query (org.hibernate.query.Query)1 Errors (org.springframework.validation.Errors)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1