Search in sources :

Example 1 with Item

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

the class XformMetaDataService method createItem.

private Item createItem(XformGroup xformGroup, XformItem xformItem, CrfBean crf, UserAccountBean ub, ArrayList<String> usedItemOids, Errors errors) throws Exception {
    ItemDataType newDataType = getItemDataType(xformItem);
    Item item = itemDao.findByNameCrfId(xformItem.getItemName(), crf.getCrfId());
    if (item != null) {
        item.setDescription(xformItem.getItemDescription());
        item = itemDao.saveOrUpdate(item);
    } else {
        item = new Item();
        item.setName(xformItem.getItemName());
        item.setDescription(xformItem.getItemDescription());
        item.setUnits("");
        item.setPhiStatus(false);
        item.setItemDataType(newDataType);
        item.setItemReferenceType(itemRefTypeDao.findByItemReferenceTypeId(1));
        item.setStatus(org.akaza.openclinica.domain.Status.AVAILABLE);
        item.setUserAccount(userDao.findById(ub.getId()));
        item.setOcOid(xformItem.getItemOid());
        usedItemOids.add(item.getOcOid());
        item = itemDao.saveOrUpdate(item);
    }
    return item;
}
Also used : 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) ItemDataType(org.akaza.openclinica.domain.datamap.ItemDataType)

Example 2 with Item

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

the class FSItemProcessor method processFieldSubmissionGroupItems.

private void processFieldSubmissionGroupItems(ArrayList<HashMap> listOfUploadFilePaths, Node repeatNode, Node itemNode, SubmissionContainer container, ItemGroup itemGroup) throws Exception {
    String itemName;
    Integer itemOrdinal = 1;
    String itemValue;
    // Node repeatGroupNode = itemNode.getParentNode();
    if (repeatNode != null) {
        final NamedNodeMap attributes = repeatNode.getAttributes();
        // check to see if groupNode has any enketo attributes
        for (int attrIndex = 0; attrIndex < attributes.getLength(); attrIndex++) {
            if (attributes.item(attrIndex).getNodeName().equals(ENKETO_ORDINAL)) {
                logger.debug("found enketo attribute");
                logger.debug(attributes.item(attrIndex).getNodeName());
                logger.debug(attributes.item(attrIndex).getNodeValue());
                itemOrdinal = new Integer(attributes.item(attrIndex).getNodeValue());
            }
        }
    } else {
        itemOrdinal = 1;
    }
    FormLayout formLayout = container.getFormLayout();
    CrfVersion crfVersion = crfVersionDao.findAllByCrfId(formLayout.getCrf().getCrfId()).get(0);
    container.setCrfVersion(crfVersion);
    Item item = null;
    ItemGroupMetadata igm = null;
    if (container.getRequestType() == FieldRequestTypeEnum.DELETE_FIELD) {
        List<ItemGroupMetadata> igms = itemGroupMetadataDao.findByItemGroupCrfVersion(itemGroup.getItemGroupId(), crfVersion.getCrfVersionId());
        for (ItemGroupMetadata ig : igms) {
            ItemData existingItemData = itemDataDao.findByItemEventCrfOrdinal(ig.getItem().getItemId(), container.getEventCrf().getEventCrfId(), itemOrdinal);
            // ItemData existingItemData = lookupFieldItemData(itemGroup, itemOrdinal, container);
            if (existingItemData != null) {
                existingItemData.setDeleted(true);
                existingItemData.setValue("");
                existingItemData.setOldStatus(existingItemData.getStatus());
                existingItemData.setUserAccount(container.getUser());
                existingItemData.setStatus(Status.AVAILABLE);
                existingItemData.setUpdateId(container.getUser().getUserId());
                existingItemData.setInstanceId(container.getInstanceId());
                existingItemData = itemDataDao.saveOrUpdate(existingItemData);
                resetSdvStatus(container);
                // Close discrepancy notes
                closeItemDiscrepancyNotes(container, existingItemData);
            }
        }
        return;
    }
    // igm = itemGroupMetadataDao.findByItemCrfVersion(item.getItemId(), crfVersion.getCrfVersionId());
    // Item loop
    QueryServiceHelperBean helperBean = new QueryServiceHelperBean();
    if (queryService.getQueryAttribute(helperBean, itemNode) != null) {
        queryService.process(helperBean, container, itemNode, itemOrdinal);
    } else if (shouldProcessItemNode(itemNode)) {
        itemName = itemNode.getNodeName().trim();
        itemValue = itemNode.getTextContent();
        item = itemDao.findByNameCrfId(itemNode.getNodeName(), crfVersion.getCrf().getCrfId());
        if (item == null) {
            logger.error("Failed to lookup item: '" + itemName + "'.  Continuing with submission.");
        }
        ItemFormMetadata itemFormMetadata = itemFormMetadataDao.findByItemCrfVersion(item.getItemId(), crfVersion.getCrfVersionId());
        // 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;
                 * }
                 * }
                 */
            FormLayoutMedia media = formLayoutMediaDao.findByEventCrfIdAndFileName(container.getEventCrf().getEventCrfId(), itemValue);
            if (media == null) {
                media = new FormLayoutMedia();
            }
            media.setName(itemValue);
            media.setFormLayout(formLayout);
            media.setEventCrfId(container.getEventCrf().getEventCrfId());
            media.setPath("/" + container.getStudy().getOc_oid() + "/");
            formLayoutMediaDao.saveOrUpdate(media);
        }
        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.");
        }
        ItemData existingItemData = itemDataDao.findByItemEventCrfOrdinal(item.getItemId(), container.getEventCrf().getEventCrfId(), itemOrdinal);
        if (existingItemData == null) {
            newItemData.setStatus(Status.UNAVAILABLE);
            itemDataDao.saveOrUpdate(newItemData);
            resetSdvStatus(container);
        } else if (existingItemData.getValue().equals(newItemData.getValue())) {
        } else {
            // Existing item. Value changed. Update existing value.
            existingItemData.setInstanceId(container.getInstanceId());
            existingItemData.setValue(newItemData.getValue());
            existingItemData.setUpdateId(container.getUser().getUserId());
            existingItemData.setDateUpdated(new Date());
            itemDataDao.saveOrUpdate(existingItemData);
            resetSdvStatus(container);
        }
    }
}
Also used : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) NamedNodeMap(org.w3c.dom.NamedNodeMap) FormLayoutMedia(org.akaza.openclinica.domain.datamap.FormLayoutMedia) ItemFormMetadata(org.akaza.openclinica.domain.datamap.ItemFormMetadata) Date(java.util.Date) Item(org.akaza.openclinica.domain.datamap.Item) Errors(org.springframework.validation.Errors) CrfVersion(org.akaza.openclinica.domain.datamap.CrfVersion) ItemGroupMetadata(org.akaza.openclinica.domain.datamap.ItemGroupMetadata) ItemData(org.akaza.openclinica.domain.datamap.ItemData)

Example 3 with Item

use of org.akaza.openclinica.domain.datamap.Item 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 4 with Item

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

the class QueryServiceImpl method createBlankItemData.

private ItemData createBlankItemData(QueryServiceHelperBean helperBean) {
    Item item = itemDao.findByNameCrfId(helperBean.getParentElementName(), helperBean.getContainer().getCrfVersion().getCrf().getCrfId());
    ItemData itemData = new ItemData();
    itemData.setItem(item);
    itemData.setEventCrf(helperBean.getContainer().getEventCrf());
    itemData.setValue("");
    itemData.setDateCreated(new Date());
    itemData.setStatus(Status.AVAILABLE);
    // TODO this value should change once you have an ordinal attribute specified in the query
    itemData.setOrdinal(helperBean.getItemOrdinal());
    itemData.setUserAccount(helperBean.getUserAccount());
    itemData.setDeleted(false);
    itemData.setInstanceId(helperBean.getContainer().getInstanceId());
    itemDataDao.saveOrUpdate(itemData);
    return itemData;
}
Also used : Item(org.akaza.openclinica.domain.datamap.Item) Date(java.util.Date) ItemData(org.akaza.openclinica.domain.datamap.ItemData)

Example 5 with Item

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

the class ItemDao method findByOcOID.

public Item findByOcOID(String OCOID) {
    String query = "from " + getDomainClassName() + " item  where item.ocOid = :ocoid ";
    org.hibernate.Query q = getCurrentSession().createQuery(query);
    q.setString("ocoid", OCOID);
    return (Item) q.uniqueResult();
}
Also used : Item(org.akaza.openclinica.domain.datamap.Item) Query(org.hibernate.Query)

Aggregations

Item (org.akaza.openclinica.domain.datamap.Item)12 Date (java.util.Date)5 ItemData (org.akaza.openclinica.domain.datamap.ItemData)5 ItemFormMetadata (org.akaza.openclinica.domain.datamap.ItemFormMetadata)5 ItemGroupMetadata (org.akaza.openclinica.domain.datamap.ItemGroupMetadata)5 FileItem (org.apache.commons.fileupload.FileItem)5 ArrayList (java.util.ArrayList)4 ItemGroup (org.akaza.openclinica.domain.datamap.ItemGroup)4 XformItem (org.akaza.openclinica.domain.xform.XformItem)4 Errors (org.springframework.validation.Errors)4 CrfVersion (org.akaza.openclinica.domain.datamap.CrfVersion)3 ResponseType (org.akaza.openclinica.domain.datamap.ResponseType)3 HashMap (java.util.HashMap)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 EventCrf (org.akaza.openclinica.domain.datamap.EventCrf)2 FormLayout (org.akaza.openclinica.domain.datamap.FormLayout)2 ItemDataType (org.akaza.openclinica.domain.datamap.ItemDataType)2 ResponseSet (org.akaza.openclinica.domain.datamap.ResponseSet)2 XformGroup (org.akaza.openclinica.domain.xform.XformGroup)2