use of org.akaza.openclinica.bean.submit.DisplayTableOfContentsBean in project OpenClinica by OpenClinica.
the class ViewSectionDataEntryPreview method processRequest.
@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
FormProcessor fp = new FormProcessor(request);
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
// These numbers will be zero if the
// params are not present in the URL
int crfid = fp.getInt("crfId");
int tabNum = fp.getInt("tabId");
HttpSession session = request.getSession();
request.setAttribute("crfId", crfid);
String crfName = "";
String verNumber = "";
// All the data on the uploaded Excel file
// see org.akaza.openclinica.control.admin.SpreadsheetPreview
// createCrfMetaObject() method
Map<String, Map> crfMap = (Map) session.getAttribute("preview_crf");
if (crfMap == null) {
// addPageMessage
String msg = respage.getString("preview_data_has_timed_out");
this.addPageMessage(msg, request);
LOGGER.debug("The session attribute \"preview_crf\" has expired or gone out of scope in: " + this.getClass().getName());
this.forwardPage(Page.CRF_LIST_SERVLET, request, response);
}
Map<String, String> crfIdnameInfo = null;
if (crfMap != null) {
crfIdnameInfo = crfMap.get("crf_info");
}
// Get the CRF name and version String
if (crfIdnameInfo != null) {
Map.Entry mapEnt = null;
for (Object element : crfIdnameInfo.entrySet()) {
mapEnt = (Map.Entry) element;
if (((String) mapEnt.getKey()).equalsIgnoreCase("crf_name")) {
crfName = (String) mapEnt.getValue();
}
if (((String) mapEnt.getKey()).equalsIgnoreCase("version")) {
verNumber = (String) mapEnt.getValue();
}
}
}
// Set up the beans that DisplaySectionBean and the preview
// depend on
EventCRFBean ebean = new EventCRFBean();
CRFVersionBean crfverBean = new CRFVersionBean();
crfverBean.setName(verNumber);
CRFBean crfbean = new CRFBean();
crfbean.setId(crfid);
crfbean.setName(crfName);
ebean.setCrf(crfbean);
// This happens in ViewSectionDataEntry
// It's an assumption that it has to happen here as well
ecb = ebean;
// All the groups data, if it's present in the CRF
Map<Integer, Map<String, String>> groupsMap = null;
if (crfMap != null)
groupsMap = crfMap.get("groups");
// Find out whether this CRF involves groups
// At least one group is involved if the groups Map is not null or
// empty, and the first group entry (there may be only one) has a
// valid group label
boolean hasGroups = false;
/*
* if(groupsMap != null && (! groupsMap.isEmpty()) &&
* groupsMap.get(1).get("group_label").length() > 0) hasGroups = true;
*/
// A SortedMap containing the row number as the key, and the
// section headers/values (contained in a Map) as the value
Map<Integer, Map<String, String>> sectionsMap = null;
if (crfMap != null)
sectionsMap = crfMap.get("sections");
// The itemsMap contains the spreadsheet table items row number as a
// key,
// followed by a map of the column names/values; it contains values for
// display
// such as 'left item text'
Map<Integer, Map<String, String>> itemsMap = null;
if (crfMap != null)
itemsMap = crfMap.get("items");
// Create a list of FormGroupBeans from Maps of groups,
// items, and sections
BeanFactory beanFactory = new BeanFactory();
// FormBeanUtil formUtil = new FormBeanUtil();
// Set up sections for the preview
Map.Entry me = null;
SectionBean secbean = null;
ArrayList<SectionBean> allSectionBeans = new ArrayList<SectionBean>();
String name_str = "";
String pageNum = "";
Map secMap = null;
// SpreadsheetPreviewNw returns doubles (via the
// HSSFCell API, which parses Excel files)
// as Strings (such as "1.0") for "1" in a spreadsheet cell,
// so make sure only "1" is displayed using
// this NumberFormat object
NumberFormat numFormatter = NumberFormat.getInstance();
numFormatter.setMaximumFractionDigits(0);
if (sectionsMap != null) {
for (Object element : sectionsMap.entrySet()) {
secbean = new SectionBean();
me = (Map.Entry) element;
secMap = (Map) me.getValue();
name_str = (String) secMap.get("section_label");
secbean.setName(name_str);
secbean.setTitle((String) secMap.get("section_title"));
secbean.setInstructions((String) secMap.get("instructions"));
secbean.setSubtitle((String) secMap.get("subtitle"));
pageNum = (String) secMap.get("page_number");
// type a number in that Spreadsheet cell
try {
pageNum = numFormatter.format(Double.parseDouble(pageNum));
} catch (NumberFormatException nfe) {
pageNum = "";
}
secbean.setPageNumberLabel(pageNum);
// Sift through the items to see if their section label matches
// the section's section_label column
secbean.setNumItems(this.getNumberOfItems(itemsMap, secbean.getName()));
allSectionBeans.add(secbean);
}
}
DisplayTableOfContentsBean dtocBean = new DisplayTableOfContentsBean();
// Methods should just take Lists, the interface, not
// ArrayList only!
dtocBean.setSections(allSectionBeans);
request.setAttribute("toc", dtocBean);
request.setAttribute("sectionNum", allSectionBeans.size() + "");
// Assuming that the super class' SectionBean sb variable must be
// initialized,
// since it happens in ViewSectionDataEntryServlet. TODO: verify this
sb = allSectionBeans.get(0);
// This is the StudySubjectBean
// Not sure if this is needed for a Preview, but leaving
// it in for safety/consisitency reasons
request.setAttribute(INPUT_EVENT_CRF, ecb);
request.setAttribute(SECTION_BEAN, sb);
setupStudyBean(request);
// Create a DisplaySectionBean for the SectionBean specified by the
// tab number.
tabNum = tabNum == 0 ? 1 : tabNum;
String sectionTitle = getSectionColumnBySecNum(sectionsMap, tabNum, SECTION_TITLE);
String secLabel = getSectionColumnBySecNum(sectionsMap, tabNum, SECTION_LABEL);
String secSubtitle = getSectionColumnBySecNum(sectionsMap, tabNum, SECTION_SUBTITLE);
String instructions = getSectionColumnBySecNum(sectionsMap, tabNum, INSTRUCTIONS);
int secBorders = getSectionBordersBySecNum(sectionsMap, tabNum, BORDERS);
DisplaySectionBean displaySection = beanFactory.createDisplaySectionBean(itemsMap, sectionTitle, secLabel, secSubtitle, instructions, crfName, secBorders);
//
// the variable hasGroups should only be true if the group appears in
// this section
List<DisplayItemBean> disBeans = displaySection.getItems();
ItemFormMetadataBean metaBean;
String groupLabel;
hasGroups = false;
for (DisplayItemBean diBean : disBeans) {
metaBean = diBean.getMetadata();
groupLabel = metaBean.getGroupLabel();
if (groupLabel != null && groupLabel.length() > 0) {
hasGroups = true;
break;
}
}
// Create groups associated with this section
List<DisplayItemGroupBean> disFormGroupBeans = null;
if (hasGroups) {
disFormGroupBeans = beanFactory.createGroupBeans(itemsMap, groupsMap, secLabel, crfName);
displaySection.setDisplayFormGroups(disFormGroupBeans);
}
/*
* DisplaySectionBean displaySection =
* beanFactory.createDisplaySectionBean (itemsMap, sectionTitle,
* secLabel, secSubtitle, instructions, crfName);
*/
displaySection.setCrfVersion(crfverBean);
displaySection.setCrf(crfbean);
displaySection.setEventCRF(ebean);
// Not sure if this is needed? The JSPs pull it out
// as a request attribute
SectionBean aSecBean = new SectionBean();
request.setAttribute(BEAN_DISPLAY, displaySection);
// TODO: verify these attributes, from the original servlet, are
// necessary
request.setAttribute("sec", aSecBean);
request.setAttribute("EventCRFBean", ebean);
try {
request.setAttribute("tabId", Integer.toString(tabNum));
} catch (NumberFormatException nfe) {
request.setAttribute("tabId", new Integer("1"));
}
if (hasGroups) {
LOGGER.debug("has group, new_table is true");
request.setAttribute("new_table", true);
}
// YW 07-23-2007 << for issue 0000937
forwardPage(Page.CREATE_CRF_VERSION_CONFIRM, request, response);
// YW >>
}
use of org.akaza.openclinica.bean.submit.DisplayTableOfContentsBean in project OpenClinica by OpenClinica.
the class ViewTableOfContentServlet method getDisplayBean.
public static DisplayTableOfContentsBean getDisplayBean(DataSource ds, int crfVersionId) {
DisplayTableOfContentsBean answer = new DisplayTableOfContentsBean();
SectionDAO sdao = new SectionDAO(ds);
ArrayList sections = getSections(crfVersionId, ds);
answer.setSections(sections);
CRFVersionDAO cvdao = new CRFVersionDAO(ds);
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(crfVersionId);
answer.setCrfVersion(cvb);
CRFDAO cdao = new CRFDAO(ds);
CRFBean cb = (CRFBean) cdao.findByPK(cvb.getCrfId());
answer.setCrf(cb);
answer.setEventCRF(new EventCRFBean());
answer.setStudyEventDefinition(new StudyEventDefinitionBean());
return answer;
}
use of org.akaza.openclinica.bean.submit.DisplayTableOfContentsBean in project OpenClinica by OpenClinica.
the class ViewTableOfContentServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
int crfVersionId = fp.getInt("crfVersionId");
// YW <<
int sedId = fp.getInt("sedId");
request.setAttribute("sedId", new Integer(sedId) + "");
// YW >>
DisplayTableOfContentsBean displayBean = getDisplayBean(sm.getDataSource(), crfVersionId);
request.setAttribute("toc", displayBean);
forwardPage(Page.VIEW_TABLE_OF_CONTENT);
}
use of org.akaza.openclinica.bean.submit.DisplayTableOfContentsBean in project OpenClinica by OpenClinica.
the class DataEntryServlet method getInputBeans.
/**
* Get the input beans - the EventCRFBean and the SectionBean. For both beans, look first in the request attributes to see if the bean has been stored
* there. If not, look in the parameters for the bean id, and then retrieve the bean from the database. The beans are stored as protected class members.
* @param request TODO
*/
protected void getInputBeans(HttpServletRequest request) throws InsufficientPermissionException {
HttpSession session = request.getSession();
StudyBean currentStudy = (StudyBean) session.getAttribute("study");
// BWP >>we should have the correct crfVersionId, in order to acquire
// the correct
// section IDs
FormProcessor fp = new FormProcessor(request);
EventCRFDAO ecdao = new EventCRFDAO(getDataSource());
SectionDAO sdao = new SectionDAO(getDataSource());
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
//JN:Happening when drilling down?
if (ecb == null) {
int eventCRFId = fp.getInt(INPUT_EVENT_CRF_ID, true);
LOGGER.debug("found event crf id: " + eventCRFId);
if (eventCRFId > 0) {
LOGGER.debug("***NOTE*** that we didnt have to create an event crf because we already have one: " + eventCRFId);
// there is an event CRF already, only need to update
ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
// ecb.setUpdatedDate(new Date());
// ecb.setUpdater(ub);
// ecb = (EventCRFBean) ecdao.update(ecb);
// logger.trace("found an event crf id "+eventCRFId);
// YW 11-12-2007 << if interviewer or/and interview date
// has/have been updated for study/site from "blank" to
// "pre-populated"
// But at this point, this update only shows on web page and
// will not be updated to database.
int studyEventId = fp.getInt(INPUT_STUDY_EVENT_ID);
request.setAttribute(INPUT_EVENT_CRF, ecb);
if (studyEventId > 0) {
StudyEventDAO sedao = new StudyEventDAO(getDataSource());
StudyEventBean sEvent = (StudyEventBean) sedao.findByPK(studyEventId);
ecb = updateECB(sEvent, request);
}
request.setAttribute(INPUT_EVENT_CRF, ecb);
// YW >>
} else {
// CRF id <=0, so we need to create a new CRF
// use toCreateCRF as a flag to prevent user to submit event CRF
// more than once
// for example, user reloads the page
String toCreateCRF = (String) session.getAttribute("to_create_crf");
if (StringUtil.isBlank(toCreateCRF) || "0".equals(toCreateCRF)) {
session.setAttribute("to_create_crf", "1");
}
try {
// if (ecb.getInterviewerName() != null) {
LOGGER.debug("Initial: to create an event CRF.");
String toCreateCRF1 = (String) session.getAttribute("to_create_crf");
if (!StringUtil.isBlank(toCreateCRF1) && "1".equals(toCreateCRF1)) {
ecb = createEventCRF(request, fp);
session.setAttribute("ecb", ecb);
request.setAttribute(INPUT_EVENT_CRF, ecb);
session.setAttribute("to_create_crf", "0");
} else {
ecb = (EventCRFBean) session.getAttribute("ecb");
}
// }
} catch (InconsistentStateException ie) {
ie.printStackTrace();
addPageMessage(ie.getOpenClinicaMessage(), request);
throw new InsufficientPermissionException(Page.LIST_STUDY_SUBJECTS_SERVLET, ie.getOpenClinicaMessage(), "1");
} catch (NullPointerException ne) {
ne.printStackTrace();
addPageMessage(ne.getMessage(), request);
throw new InsufficientPermissionException(Page.LIST_STUDY_SUBJECTS_SERVLET, ne.getMessage(), "1");
}
}
}
// added to allow sections shown on this page
DisplayTableOfContentsBean displayBean = new DisplayTableOfContentsBean();
displayBean = TableOfContentsServlet.getDisplayBean(ecb, getDataSource(), currentStudy);
// escape apostrophe in event name
displayBean.getStudyEventDefinition().setName(StringEscapeUtils.escapeJavaScript(displayBean.getStudyEventDefinition().getName()));
request.setAttribute(TOC_DISPLAY, displayBean);
int sectionId = fp.getInt(INPUT_SECTION_ID, true);
ArrayList sections;
if (sectionId <= 0) {
StudyEventDAO studyEventDao = new StudyEventDAO(getDataSource());
int maximumSampleOrdinal = studyEventDao.getMaxSampleOrdinal(displayBean.getStudyEventDefinition(), displayBean.getStudySubject());
request.setAttribute("maximumSampleOrdinal", maximumSampleOrdinal);
sections = sdao.findAllByCRFVersionId(ecb.getCRFVersionId());
for (int i = 0; i < sections.size(); i++) {
SectionBean sb = (SectionBean) sections.get(i);
// find the first section of this CRF
sectionId = sb.getId();
break;
}
}
SectionBean sb = new SectionBean();
if (sectionId > 0) {
// int sectionId = fp.getInt(INPUT_SECTION_ID, true);
//synchronized(this)
{
sb = (SectionBean) sdao.findByPK(sectionId);
}
}
int tabId = fp.getInt("tab", true);
if (tabId <= 0) {
tabId = 1;
}
request.setAttribute(INPUT_TAB, new Integer(tabId));
request.setAttribute(SECTION_BEAN, sb);
}
use of org.akaza.openclinica.bean.submit.DisplayTableOfContentsBean in project OpenClinica by OpenClinica.
the class TableOfContentsServlet method processRequest.
/*
* (non-Javadoc)
*
* @see org.akaza.openclinica.control.core.SecureController#processRequest()
*/
@Override
protected void processRequest() throws Exception {
FormDiscrepancyNotes discNotes;
if (action.equals(ACTION_START_INITIAL_DATA_ENTRY)) {
ecb = createEventCRF();
} else {
validateEventCRFAndAction();
}
updatePresetValues(ecb);
Boolean b = (Boolean) request.getAttribute(DataEntryServlet.INPUT_IGNORE_PARAMETERS);
if (fp.isSubmitted() && b == null) {
discNotes = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
if (discNotes == null) {
discNotes = new FormDiscrepancyNotes();
session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes);
}
DiscrepancyValidator v = new DiscrepancyValidator(request, discNotes);
v.addValidation(INPUT_INTERVIEWER, Validator.NO_BLANKS);
v.addValidation(INPUT_INTERVIEW_DATE, Validator.IS_A_DATE);
v.alwaysExecuteLastValidation(INPUT_INTERVIEW_DATE);
errors = v.validate();
if (errors.isEmpty()) {
ecb.setInterviewerName(fp.getString(INPUT_INTERVIEWER));
ecb.setDateInterviewed(fp.getDate(INPUT_INTERVIEW_DATE));
if (ecdao == null) {
ecdao = new EventCRFDAO(sm.getDataSource());
}
ecb = (EventCRFBean) ecdao.update(ecb);
// save discrepancy notes into DB
FormDiscrepancyNotes fdn = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
AddNewSubjectServlet.saveFieldNotes(INPUT_INTERVIEWER, fdn, dndao, ecb.getId(), "EventCRF", currentStudy);
AddNewSubjectServlet.saveFieldNotes(INPUT_INTERVIEW_DATE, fdn, dndao, ecb.getId(), "EventCRF", currentStudy);
if (ecdao.isQuerySuccessful()) {
updatePresetValues(ecb);
if (!fp.getBoolean("editInterview", true)) {
// editing completed
addPageMessage(respage.getString("interviewer_name_date_updated"));
}
} else {
addPageMessage(respage.getString("database_error_interviewer_name_date_not_updated"));
}
} else {
String[] textFields = { INPUT_INTERVIEWER, INPUT_INTERVIEW_DATE };
fp.setCurrentStringValuesAsPreset(textFields);
setInputMessages(errors);
setPresetValues(fp.getPresetValues());
}
} else {
discNotes = new FormDiscrepancyNotes();
session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes);
}
DisplayTableOfContentsBean displayBean = getDisplayBean(ecb, sm.getDataSource(), currentStudy);
// this is for generating side info panel
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean ssb = (StudySubjectBean) ssdao.findByPK(ecb.getStudySubjectId());
ArrayList beans = ViewStudySubjectServlet.getDisplayStudyEventsForStudySubject(ssb, sm.getDataSource(), ub, currentRole);
request.setAttribute("studySubject", ssb);
request.setAttribute("beans", beans);
request.setAttribute("eventCRF", ecb);
request.setAttribute(BEAN_DISPLAY, displayBean);
boolean allowEnterData = true;
if (StringUtil.isBlank(ecb.getInterviewerName())) {
if (discNotes == null || discNotes.getNotes(TableOfContentsServlet.INPUT_INTERVIEWER).isEmpty()) {
allowEnterData = false;
}
}
if (ecb.getDateInterviewed() == null) {
if (discNotes == null || discNotes.getNotes(TableOfContentsServlet.INPUT_INTERVIEW_DATE).isEmpty()) {
allowEnterData = false;
}
}
if (!allowEnterData) {
request.setAttribute("allowEnterData", "no");
// forwardPage(Page.INTERVIEWER);
/*
* BWP 2966 >> the original Page.INTERVIEWER jsp is not a complete
* web page and did not provide a body tag for producing a popup
* window for discrepancy notes. So I changed it to create a
* complete web page.
*/
forwardPage(Page.INTERVIEWER_ENTIRE_PAGE);
} else {
if (fp.getBoolean("editInterview", true)) {
// user wants to edit interview info
request.setAttribute("allowEnterData", "yes");
forwardPage(Page.INTERVIEWER);
} else {
if (fp.isSubmitted() && !errors.isEmpty()) {
// interview form submitted, but has blank field or
// validation error
request.setAttribute("allowEnterData", "no");
forwardPage(Page.INTERVIEWER);
} else {
request.setAttribute("allowEnterData", "yes");
forwardPage(Page.TABLE_OF_CONTENTS);
}
}
}
}
Aggregations