Search in sources :

Example 1 with VersioningMap

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

the class XformMetaDataService method createVersioningMap.

private void createVersioningMap(CrfVersion crfVersion, Item item, FormLayout formLayout, int itemOrderInForm) {
    VersioningMapId versioningMapId = new VersioningMapId();
    versioningMapId.setCrfVersionId(crfVersion.getCrfVersionId());
    versioningMapId.setItemId(item.getItemId());
    versioningMapId.setFormLayoutId(formLayout.getFormLayoutId());
    versioningMapId.setItemOrderInForm(itemOrderInForm);
    VersioningMap versioningMap = new VersioningMap();
    versioningMap.setVersionMapId(versioningMapId);
    versioningMapDao.saveOrUpdate(versioningMap);
}
Also used : VersioningMapId(org.akaza.openclinica.domain.datamap.VersioningMapId) VersioningMap(org.akaza.openclinica.domain.datamap.VersioningMap)

Example 2 with VersioningMap

use of org.akaza.openclinica.domain.datamap.VersioningMap 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)

Example 3 with VersioningMap

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

the class ChangeCRFVersionController method confirmCRFVersionChange.

/*
     * Displays two set of columns for user to confirm his decision to switch to a new version of CRF
     * field name | OID | field value
     */
@RequestMapping(value = "/managestudy/confirmCRFVersionChange", method = RequestMethod.POST)
public // @RequestMapping("/managestudy/confirmCRFVersionChange")
ModelMap confirmCRFVersionChange(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "crfId", required = false) int crfId, @RequestParam(value = "crfName", required = false) String crfName, @RequestParam(value = "formLayoutId", required = false) int formLayoutId, @RequestParam(value = "formLayoutName", required = false) String formLayoutName, @RequestParam(value = "studySubjectLabel", required = false) String studySubjectLabel, @RequestParam(value = "studySubjectId", required = false) int studySubjectId, @RequestParam(value = "eventCRFId", required = false) int eventCRFId, @RequestParam(value = "eventDefinitionCRFId", required = false) int eventDefinitionCRFId, @RequestParam(value = "selectedVersionId", required = false) int selectedVersionId, @RequestParam(value = "selectedVersionName", required = false) String selectedVersionName, @RequestParam(value = "eventName", required = false) String eventName, @RequestParam(value = "eventCreateDate", required = false) String eventCreateDate, @RequestParam(value = "eventOrdinal", required = false) String eventOrdinal, @RequestParam("confirmCRFVersionSubmit") String as) {
    // to be removed for aquamarine
    if (!mayProceed(request)) {
        if (redirect(request, response, "/MainMenu?message=authentication_failed") == null)
            return null;
    }
    FormLayoutDAO formLayoutDao = new FormLayoutDAO(dataSource);
    selectedVersionName = (formLayoutDao.findByPK(selectedVersionId)).getName().trim();
    resetPanel(request);
    request.setAttribute("eventCRFId", eventCRFId);
    request.setAttribute("studySubjectLabel", studySubjectLabel);
    request.setAttribute("eventDefinitionCRFId", eventDefinitionCRFId);
    request.setAttribute("studySubjectId", studySubjectId);
    request.setAttribute("crfId", crfId);
    request.setAttribute("crfName", crfName);
    request.setAttribute("formLayoutId", formLayoutId);
    request.setAttribute("formLayoutName", formLayoutName.trim());
    request.setAttribute("selectedVersionId", selectedVersionId);
    if (selectedVersionName != null) {
        selectedVersionName = selectedVersionName.trim();
    }
    request.setAttribute("selectedVersionName", selectedVersionName);
    request.setAttribute("eventName", eventName);
    request.setAttribute("eventCreateDate", eventCreateDate);
    request.setAttribute("eventOrdinal", eventOrdinal);
    ModelMap gridMap = new ModelMap();
    ArrayList<String> pageMessages = initPageMessages(request);
    setupResource(request);
    if (selectedVersionId == -1) {
        // "Please select CRF
        String errorMessage = resword.getString("confirm_crf_version_em_select_version");
        // version";
        StringBuffer params = new StringBuffer();
        params.append("/pages/managestudy/chooseCRFVersion?crfId=" + crfId);
        params.append("&crfName=" + crfName);
        params.append("&formLayoutId=" + formLayoutId);
        params.append("&formLayoutName=" + formLayoutName);
        params.append("&selectedVersionName=" + selectedVersionName);
        params.append("&studySubjectLabel=" + studySubjectLabel);
        params.append("&studySubjectId=" + studySubjectId);
        params.append("&eventCRFId=" + eventCRFId);
        params.append("&eventDefinitionCRFId=" + eventDefinitionCRFId);
        params.append("&errorMessage=" + errorMessage);
        if (redirect(request, response, params.toString()) == null) {
            return null;
        }
    }
    request.getSession().removeAttribute("pageMessages");
    // get dATa for current crf version display
    // select name, ordinal, oc_oid, item_data_id, i.item_id, value from item_data id, item i
    // where id.item_id=i.item_id and event_crf_id = 171 order by i.item_id,ordinal;
    ArrayList<String[]> rows = new ArrayList<String[]>();
    int cur_counter = 0;
    int new_counter = 0;
    try {
        ItemDAO item_dao = new ItemDAO(dataSource);
        ItemDataBean d_bean = null;
        // get metadata to find repeat group or not
        ItemGroupMetadataDAO dao_item_form_mdata = new ItemGroupMetadataDAO(dataSource);
        HashMap<Integer, ItemGroupMetadataBean> hash_item_form_mdata = new HashMap<Integer, ItemGroupMetadataBean>();
        HashMap<Integer, ItemGroupMetadataBean> hash_new_item_form_mdata = new HashMap<Integer, ItemGroupMetadataBean>();
        List<ItemBean> cur_items = new ArrayList<>();
        List<ItemBean> new_items = new ArrayList<>();
        List<VersioningMap> origFormLayoutItems = versioningMapDao.findByFormLayoutId(formLayoutId);
        for (VersioningMap vm : origFormLayoutItems) {
            ItemGroupMetadataBean beans_item_form_mdata = (ItemGroupMetadataBean) dao_item_form_mdata.findByItemAndCrfVersion(vm.getVersionMapId().getItemId(), vm.getVersionMapId().getCrfVersionId());
            hash_item_form_mdata.put(new Integer(vm.getVersionMapId().getItemId()), beans_item_form_mdata);
            ItemBean itemBean = (ItemBean) item_dao.findByPK(vm.getVersionMapId().getItemId());
            cur_items.add(itemBean);
        }
        List<VersioningMap> newFormLayoutItems = versioningMapDao.findByFormLayoutId(selectedVersionId);
        for (VersioningMap vm : newFormLayoutItems) {
            ItemGroupMetadataBean bn_new_item_form_mdata = (ItemGroupMetadataBean) dao_item_form_mdata.findByItemAndCrfVersion(vm.getVersionMapId().getItemId(), vm.getVersionMapId().getCrfVersionId());
            hash_new_item_form_mdata.put(new Integer(vm.getVersionMapId().getItemId()), bn_new_item_form_mdata);
            ItemBean itemBean = (ItemBean) item_dao.findByPK(vm.getVersionMapId().getItemId());
            new_items.add(itemBean);
        }
        // get items description
        List<ItemBean> cur_items_with_data = item_dao.findAllWithItemDataByFormLayoutId(formLayoutId, eventCRFId);
        HashMap<String, ItemBean> hash_items_with_data = new HashMap<String, ItemBean>(cur_items_with_data.size());
        for (ItemBean item : cur_items_with_data) {
            hash_items_with_data.put(item.getOid(), item);
        }
        ItemBean temp = null;
        for (ItemBean item : cur_items) {
            temp = hash_items_with_data.get(item.getOid());
            if (temp != null) {
                item.setItemDataElements(temp.getItemDataElements());
            }
        }
        List<ItemBean> new_items_with_data = item_dao.findAllWithItemDataByFormLayoutId(selectedVersionId, eventCRFId);
        hash_items_with_data = new HashMap<String, ItemBean>(new_items_with_data.size());
        for (ItemBean item : new_items_with_data) {
            hash_items_with_data.put(item.getOid(), item);
        }
        for (ItemBean item : new_items) {
            temp = hash_items_with_data.get(item.getOid());
            if (temp != null) {
                item.setItemDataElements(temp.getItemDataElements());
            }
        }
        ItemBean cur_element = null;
        ItemBean new_element = null;
        ItemGroupMetadataBean bn_mdata = null;
        ItemGroupMetadataBean bn_new_mdata = null;
        while (cur_counter < cur_items.size() || new_counter < new_items.size()) {
            if (cur_counter < cur_items.size()) {
                cur_element = cur_items.get(cur_counter);
                bn_mdata = hash_item_form_mdata.get(new Integer(cur_element.getId()));
            }
            if (new_counter < new_items.size()) {
                new_element = new_items.get(new_counter);
                bn_new_mdata = hash_new_item_form_mdata.get(new Integer(new_element.getId()));
            }
            if (cur_counter < cur_items.size() && new_counter < new_items.size() && new_element.getId() == cur_element.getId()) {
                buildRecord(cur_element, new_element, bn_mdata, bn_new_mdata, rows);
                cur_counter++;
                new_counter++;
            } else if (cur_counter < cur_items.size() && (new_counter >= new_items.size() || new_element.getId() > cur_element.getId())) {
                buildRecord(cur_element, null, bn_mdata, null, rows);
                cur_counter++;
            } else if (new_counter < new_items.size() && (cur_counter >= cur_items.size() || new_element.getId() < cur_element.getId())) {
                buildRecord(null, new_element, null, bn_new_mdata, rows);
                new_counter++;
            }
        }
    } catch (Exception e) {
        logger.error(cur_counter + " " + new_counter);
        pageMessages.add(resword.getString("confirm_crf_version_em_dataextraction"));
    }
    request.setAttribute("pageMessages", pageMessages);
    gridMap.addAttribute("rows", rows);
    return gridMap;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) HashMap(java.util.HashMap) ModelMap(org.springframework.ui.ModelMap) ArrayList(java.util.ArrayList) ItemGroupMetadataBean(org.akaza.openclinica.bean.submit.ItemGroupMetadataBean) VersioningMap(org.akaza.openclinica.domain.datamap.VersioningMap) HttpSessionRequiredException(org.springframework.web.HttpSessionRequiredException) ItemGroupMetadataDAO(org.akaza.openclinica.dao.submit.ItemGroupMetadataDAO) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) FormLayoutDAO(org.akaza.openclinica.dao.submit.FormLayoutDAO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

VersioningMap (org.akaza.openclinica.domain.datamap.VersioningMap)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)1 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)1 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)1 ItemGroupMetadataBean (org.akaza.openclinica.bean.submit.ItemGroupMetadataBean)1 FormLayoutDAO (org.akaza.openclinica.dao.submit.FormLayoutDAO)1 ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)1 ItemGroupMetadataDAO (org.akaza.openclinica.dao.submit.ItemGroupMetadataDAO)1 Item (org.akaza.openclinica.domain.datamap.Item)1 ItemFormMetadata (org.akaza.openclinica.domain.datamap.ItemFormMetadata)1 ItemGroup (org.akaza.openclinica.domain.datamap.ItemGroup)1 ItemGroupMetadata (org.akaza.openclinica.domain.datamap.ItemGroupMetadata)1 ResponseSet (org.akaza.openclinica.domain.datamap.ResponseSet)1 ResponseType (org.akaza.openclinica.domain.datamap.ResponseType)1 VersioningMapId (org.akaza.openclinica.domain.datamap.VersioningMapId)1 XformGroup (org.akaza.openclinica.domain.xform.XformGroup)1 XformItem (org.akaza.openclinica.domain.xform.XformItem)1 FileItem (org.apache.commons.fileupload.FileItem)1 DiskFileItem (org.apache.commons.fileupload.disk.DiskFileItem)1