Search in sources :

Example 6 with ItemData

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

the class ItemProcessor method removeDeletedRows.

private void removeDeletedRows(HashMap<Integer, Set<Integer>> groupOrdinalMapping, SubmissionContainer container) {
    Iterator<Integer> keys = groupOrdinalMapping.keySet().iterator();
    while (keys.hasNext()) {
        Integer itemGroupId = keys.next();
        List<ItemData> itemDatas = itemDataDao.findByEventCrfGroup(container.getEventCrf().getEventCrfId(), itemGroupId);
        for (ItemData itemData : itemDatas) {
            if (!groupOrdinalMapping.get(itemGroupId).contains(itemData.getOrdinal()) && !itemData.isDeleted()) {
                itemData.setDeleted(true);
                itemData.setValue("");
                itemData.setOldStatus(itemData.getStatus());
                itemData.setUserAccount(container.getUser());
                itemData.setStatus(Status.AVAILABLE);
                itemData.setUpdateId(container.getUser().getUserId());
                itemData.setInstanceId(container.getInstanceId());
                itemData = itemDataDao.saveOrUpdate(itemData);
                // Close discrepancy notes
                closeItemDiscrepancyNotes(container, itemData);
            }
        }
    }
}
Also used : ItemData(org.akaza.openclinica.domain.datamap.ItemData)

Example 7 with ItemData

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

the class QueryServiceImpl method process.

@Override
public void process(QueryServiceHelperBean helperBean, SubmissionContainer container, Node itemNode, int itemOrdinal) throws Exception {
    String node = itemNode.getTextContent();
    if (StringUtils.isEmpty(node))
        return;
    helperBean.setContainer(container);
    helperBean.setItemOrdinal(itemOrdinal);
    helperBean.setItemNode(itemNode);
    ItemData id = getItemData(helperBean);
    if (id == null) {
        helperBean.setItemData(createBlankItemData(helperBean));
    } else {
        helperBean.setItemData(id);
    }
    QueriesBean queries = null;
    try {
        ObjectMapper objectMapper = new ObjectMapper();
        queries = objectMapper.readValue(node, QueriesBean.class);
    } catch (IOException e) {
        logger.error(e.getMessage());
        throw e;
    }
    List<Integer> idList = new ArrayList();
    List<QueryBean> qBeans = queries.getQueries();
    QueryBean queryBean = null;
    DiscrepancyNote childDN = null;
    DiscrepancyNote parentDN = null;
    List<DiscrepancyNote> childDns = null;
    if (qBeans.size() > 0) {
        for (QueryBean qBean : qBeans) {
            idList.add(Integer.valueOf(qBean.getId()));
        }
        Collections.reverse(idList);
        queryBean = qBeans.get(0);
        parentDN = findQueryParent(helperBean);
        if (parentDN == null) {
            parentDN = createQuery(helperBean, queryBean);
            parentDN = discrepancyNoteDao.saveOrUpdate(parentDN);
            helperBean.setDn(parentDN);
            saveQueryItemDatamap(helperBean);
        }
        childDns = findChildQueries(helperBean);
        if (childDns.size() < qBeans.size()) {
            // Enketo passes JSON "id" attribute for unsubmitted queries only
            // if (StringUtils.isEmpty(queryBean.getId())){
            childDN = createQuery(helperBean, queryBean);
            childDN.setParentDiscrepancyNote(parentDN);
            childDN = discrepancyNoteDao.saveOrUpdate(childDN);
            parentDN.setUserAccount(childDN.getUserAccount());
            setResolutionStatus(queryBean, parentDN);
            parentDN.setUserAccountByOwnerId(helperBean.getContainer().getUser());
            parentDN.setDetailedNotes(childDN.getDetailedNotes());
            parentDN.setDiscrepancyNoteType(childDN.getDiscrepancyNoteType());
            parentDN = discrepancyNoteDao.saveOrUpdate(parentDN);
            helperBean.setDn(childDN);
            saveQueryItemDatamap(helperBean);
            handleEmailNotification(helperBean, queryBean);
        }
    }
}
Also used : DiscrepancyNote(org.akaza.openclinica.domain.datamap.DiscrepancyNote) QueriesBean(org.akaza.openclinica.core.form.xform.QueriesBean) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) ItemData(org.akaza.openclinica.domain.datamap.ItemData) QueryBean(org.akaza.openclinica.core.form.xform.QueryBean)

Example 8 with ItemData

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

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

the class GenerateClinicalDataServiceImpl method fetchItemData.

private ArrayList<ImportItemGroupDataBean> fetchItemData(Set<ItemGroupMetadata> set, int eventCrfId, List<VersioningMap> vms, EventCrf eventCrf) {
    String groupOID, itemOID;
    String itemValue = null;
    String itemDataValue;
    HashMap<String, ArrayList<String>> oidMap = new HashMap<String, ArrayList<String>>();
    HashMap<String, List<ItemData>> oidDNAuditMap = new HashMap<String, List<ItemData>>();
    List<ItemData> itds = eventCrf.getItemDatas();
    // itemOIDs with corresponding values will be created.
    for (ItemData itemData : itds) {
        List<ItemGroupMetadata> igmetadatas = itemData.getItem().getItemGroupMetadatas();
        for (ItemGroupMetadata igGrpMetadata : igmetadatas) {
            groupOID = igGrpMetadata.getItemGroup().getOcOid();
            if (!oidMap.containsKey(groupOID)) {
                String groupOIDOrdnl = groupOID;
                ArrayList<String> itemsValues = new ArrayList<String>();
                ArrayList<ItemData> itemDatas = new ArrayList<ItemData>();
                List<ItemGroupMetadata> allItemsInAGroup = igGrpMetadata.getItemGroup().getItemGroupMetadatas();
                for (ItemGroupMetadata itemGrpMetada : allItemsInAGroup) {
                    itemOID = itemGrpMetada.getItem().getOcOid();
                    itemsValues = new ArrayList<String>();
                    /*
                         * List<ItemData> itds = itemGrpMetada.getItem()
                         * .getItemDatas();
                         */
                    // look for the key
                    // of same group and ordinal and add this item to
                    // that hashmap
                    itemsValues = new ArrayList<String>();
                    itemDataValue = fetchItemDataValue(itemData, itemData.getItem());
                    itemDatas = new ArrayList<ItemData>();
                    itemValue = itemOID + DELIMITER + itemDataValue;
                    itemsValues.add(itemValue);
                    groupOIDOrdnl = groupOID + GROUPOID_ORDINAL_DELIM + itemData.getOrdinal() + GROUPOID_ORDINAL_DELIM + itemData.isDeleted();
                    if (itemData.getItem().getOcOid() == itemOID) {
                        if (oidMap.containsKey(groupOIDOrdnl)) {
                            ArrayList<String> itemgrps = oidMap.get(groupOIDOrdnl);
                            List<ItemData> itemDataTemps = oidDNAuditMap.get(groupOIDOrdnl);
                            if (!itemgrps.contains(itemValue)) {
                                itemgrps.add(itemValue);
                                oidMap.remove(groupOIDOrdnl);
                                itemDataTemps.add(itemData);
                                oidDNAuditMap.remove(groupOIDOrdnl);
                            }
                            oidMap.put(groupOIDOrdnl, itemgrps);
                            oidDNAuditMap.put(groupOIDOrdnl, itemDataTemps);
                        } else {
                            oidMap.put(groupOIDOrdnl, itemsValues);
                            itemDatas.add(itemData);
                            oidDNAuditMap.put(groupOIDOrdnl, itemDatas);
                        }
                    }
                }
            }
        }
    }
    return populateImportItemGrpBean(oidMap, oidDNAuditMap);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ItemGroupMetadata(org.akaza.openclinica.domain.datamap.ItemGroupMetadata) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ItemData(org.akaza.openclinica.domain.datamap.ItemData)

Example 10 with ItemData

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

the class ItemDataDao method findByEventCrfItemName.

public ItemData findByEventCrfItemName(int eventCrfId, String itemName, int ordinal) {
    Query q = getCurrentSession().createQuery(findByEventCrfItemName);
    q.setParameter("eventCrfId", eventCrfId);
    q.setParameter("itemName", itemName);
    q.setParameter("ordinal", ordinal);
    return (ItemData) q.uniqueResult();
}
Also used : Query(org.hibernate.query.Query) ItemData(org.akaza.openclinica.domain.datamap.ItemData)

Aggregations

ItemData (org.akaza.openclinica.domain.datamap.ItemData)12 Date (java.util.Date)5 ItemGroupMetadata (org.akaza.openclinica.domain.datamap.ItemGroupMetadata)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Item (org.akaza.openclinica.domain.datamap.Item)3 QueriesBean (org.akaza.openclinica.core.form.xform.QueriesBean)2 ItemFormMetadata (org.akaza.openclinica.domain.datamap.ItemFormMetadata)2 Query (org.hibernate.query.Query)2 Errors (org.springframework.validation.Errors)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Configuration (freemarker.template.Configuration)1 Template (freemarker.template.Template)1 File (java.io.File)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 LinkedHashMap (java.util.LinkedHashMap)1