Search in sources :

Example 46 with ModelMap

use of org.springframework.ui.ModelMap in project OpenClinica by OpenClinica.

the class SDVController method viewSubjectAggregateHandler.

@RequestMapping("/viewSubjectAggregate")
public ModelMap viewSubjectAggregateHandler(HttpServletRequest request, HttpServletResponse response, @RequestParam("studyId") int studyId) {
    if (!mayProceed(request)) {
        try {
            response.sendRedirect(request.getContextPath() + "/MainMenu?message=authentication_failed");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    ModelMap gridMap = new ModelMap();
    HttpSession session = request.getSession();
    boolean showMoreLink = false;
    if (session.getAttribute("sSdvRestore") != null && session.getAttribute("sSdvRestore") == "false") {
        session.setAttribute("sSdvRestore", "true");
        showMoreLink = true;
    } else if (request.getParameter("showMoreLink") != null) {
        showMoreLink = Boolean.parseBoolean(request.getParameter("showMoreLink").toString());
    } else if (session.getAttribute("s_sdv_showMoreLink") != null) {
        showMoreLink = Boolean.parseBoolean(session.getAttribute("s_sdv_showMoreLink") + "");
    } else {
        showMoreLink = true;
    }
    request.setAttribute("showMoreLink", showMoreLink + "");
    session.setAttribute("s_sdv_showMoreLink", showMoreLink + "");
    request.setAttribute("studyId", studyId);
    String restore = (String) request.getAttribute("s_sdv_restore");
    restore = restore != null && restore.length() > 0 ? restore : "false";
    request.setAttribute("s_sdv_restore", restore);
    // request.setAttribute("studySubjectId",studySubjectId);
    /*SubjectIdSDVFactory tableFactory = new SubjectIdSDVFactory();
        * @RequestParam("studySubjectId") int studySubjectId,*/
    request.setAttribute("imagePathPrefix", "../");
    ArrayList<String> pageMessages = (ArrayList<String>) request.getAttribute("pageMessages");
    if (pageMessages == null) {
        pageMessages = new ArrayList<String>();
    }
    request.setAttribute("pageMessages", pageMessages);
    sdvFactory.showMoreLink = showMoreLink;
    TableFacade facade = sdvFactory.createTable(request, response);
    String sdvMatrix = facade.render();
    gridMap.addAttribute(SUBJECT_SDV_TABLE_ATTRIBUTE, sdvMatrix);
    return gridMap;
}
Also used : TableFacadeFactory.createTableFacade(org.jmesa.facade.TableFacadeFactory.createTableFacade) TableFacade(org.jmesa.facade.TableFacade) HttpSession(javax.servlet.http.HttpSession) ModelMap(org.springframework.ui.ModelMap) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 47 with ModelMap

use of org.springframework.ui.ModelMap in project OpenClinica by OpenClinica.

the class ChangeCRFVersionController method chooseCRFVersion.

/*
     * Allows user to select new CRF version
     * 
     */
// @RequestMapping(value="/managestudy/chooseCRFVersion", method = RequestMethod.GET)
@RequestMapping(value = "/managestudy/chooseCRFVersion", method = RequestMethod.GET)
public ModelMap chooseCRFVersion(HttpServletRequest request, HttpServletResponse response, @RequestParam("crfId") int crfId, @RequestParam("crfName") String crfName, @RequestParam("formLayoutId") int formLayoutId, @RequestParam("formLayoutName") String formLayoutName, @RequestParam("studySubjectLabel") String studySubjectLabel, @RequestParam("studySubjectId") int studySubjectId, @RequestParam("eventCRFId") int eventCRFId, @RequestParam("eventDefinitionCRFId") int eventDefinitionCRFId) {
    // to be removed for aquamarine
    if (!mayProceed(request)) {
        try {
            response.sendRedirect(request.getContextPath() + "/MainMenu?message=authentication_failed");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    resetPanel(request);
    ModelMap gridMap = new ModelMap();
    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());
    ArrayList<String> pageMessages = initPageMessages(request);
    Object errorMessage = request.getParameter("errorMessage");
    if (errorMessage != null) {
        pageMessages.add((String) errorMessage);
    }
    // get CRF by ID with all versions
    // create List of all versions (label + value)
    // set default CRF version label
    setupResource(request);
    // from event_crf get
    StudyBean study = (StudyBean) request.getSession().getAttribute("study");
    CRFDAO cdao = new CRFDAO(dataSource);
    CRFBean crfBean = (CRFBean) cdao.findByPK(crfId);
    FormLayoutDAO formLayoutDao = new FormLayoutDAO(dataSource);
    ArrayList<FormLayoutBean> formLayouts = (ArrayList<FormLayoutBean>) formLayoutDao.findAllActiveByCRF(crfId);
    StudyEventDefinitionDAO sfed = new StudyEventDefinitionDAO(dataSource);
    StudyEventDefinitionBean sedb = sfed.findByEventDefinitionCRFId(eventDefinitionCRFId);
    request.setAttribute("eventName", sedb.getName());
    EventCRFDAO ecdao = new EventCRFDAO(dataSource);
    EventCRFBean ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
    StudyEventDAO sedao = new StudyEventDAO(dataSource);
    StudyEventBean seb = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
    request.setAttribute("eventCreateDate", formatDate(seb.getCreatedDate()));
    if (sedb.isRepeating()) {
        request.setAttribute("eventOrdinal", seb.getSampleOrdinal());
    }
    if (study.getParentStudyId() > 0) {
        EventDefinitionCRFDAO edfdao = new EventDefinitionCRFDAO(dataSource);
        EventDefinitionCRFBean edf = (EventDefinitionCRFBean) edfdao.findByPK(eventDefinitionCRFId);
        if (!edf.getSelectedVersionIds().equals("")) {
            String[] version_ids = edf.getSelectedVersionIds().split(",");
            HashMap<String, String> tmp = new HashMap<String, String>(version_ids.length);
            for (String vs : version_ids) {
                tmp.put(vs, vs);
            }
            ArrayList<FormLayoutBean> site_versions = new ArrayList<FormLayoutBean>(formLayouts.size());
            for (FormLayoutBean vs : formLayouts) {
                if (tmp.get(String.valueOf(vs.getId())) != null) {
                    site_versions.add(vs);
                }
            }
            formLayouts = site_versions;
        }
    }
    crfBean.setVersions(formLayouts);
    gridMap.addAttribute("numberOfVersions", crfBean.getVersions().size() + 1);
    gridMap.addAttribute("crfBean", crfBean);
    return gridMap;
}
Also used : EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) HashMap(java.util.HashMap) ModelMap(org.springframework.ui.ModelMap) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) HttpSessionRequiredException(org.springframework.web.HttpSessionRequiredException) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) FormLayoutDAO(org.akaza.openclinica.dao.submit.FormLayoutDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 48 with ModelMap

use of org.springframework.ui.ModelMap 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

ModelMap (org.springframework.ui.ModelMap)48 Test (org.junit.Test)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)18 ModelAndView (org.springframework.web.servlet.ModelAndView)11 RedirectAttributesModelMap (org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)5 Map (java.util.Map)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 IOException (java.io.IOException)3 Date (java.util.Date)3 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)3 HttpSessionRequiredException (org.springframework.web.HttpSessionRequiredException)3 RedirectAttributes (org.springframework.web.servlet.mvc.support.RedirectAttributes)3 NimbusClient (backtype.storm.utils.NimbusClient)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HttpSession (javax.servlet.http.HttpSession)2