use of org.akaza.openclinica.bean.submit.SectionBean in project OpenClinica by OpenClinica.
the class PrintAllEventCRFServlet method processRequest.
@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
FormProcessor fp = new FormProcessor(request);
SessionManager sm = (SessionManager) request.getSession().getAttribute("sm");
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
ArrayList<SectionBean> allSectionBeans;
// The PrintDataEntry servlet handles this parameter
boolean isSubmitted = false;
StudyEventDefinitionDAO sedao = new StudyEventDefinitionDAO(sm.getDataSource());
EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(sm.getDataSource());
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
StudyDAO studyDao = new StudyDAO(sm.getDataSource());
StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
ArrayList<StudyEventDefinitionBean> seds = new ArrayList<StudyEventDefinitionBean>();
seds = sedao.findAllByStudy(currentStudy);
// ArrayList eventDefinitionCRFs = (ArrayList) edao.findAllByStudy(site);
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
ArrayList<EventDefinitionCRFBean> edcs = new ArrayList();
for (StudyEventDefinitionBean sed : seds) {
int defId = sed.getId();
edcs.addAll(edcdao.findAllByDefinition(currentStudy, defId));
}
Map eventDefinitionDefaultVersions = new LinkedHashMap();
for (int i = 0; i < edcs.size(); i++) {
EventDefinitionCRFBean edc = edcs.get(i);
ArrayList versions = (ArrayList) cvdao.findAllByCRF(edc.getCrfId());
edc.setVersions(versions);
CRFBean crf = (CRFBean) cdao.findByPK(edc.getCrfId());
// edc.setCrfLabel(crf.getLabel());
edc.setCrfName(crf.getName());
// to show/hide edit action on jsp page
if (crf.getStatus().equals(Status.AVAILABLE)) {
edc.setOwner(crf.getOwner());
}
CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(edc.getDefaultVersionId());
StudyEventDefinitionBean studyEventDefinitionBean = (StudyEventDefinitionBean) sedao.findByPK(edc.getStudyEventDefinitionId());
edc.setDefaultVersionName(defaultVersion.getName());
if (defaultVersion.getStatus().isAvailable()) {
List list = (ArrayList) eventDefinitionDefaultVersions.get(studyEventDefinitionBean);
if (list == null)
list = new ArrayList();
list.add(defaultVersion);
eventDefinitionDefaultVersions.put(studyEventDefinitionBean, list);
}
}
// Whether IE6 or IE7 is involved
String isIE = fp.getString("ie");
if ("y".equalsIgnoreCase(isIE)) {
request.setAttribute("isInternetExplorer", "true");
}
SectionDAO sdao = new SectionDAO(sm.getDataSource());
CRFVersionDAO crfVersionDAO = new CRFVersionDAO(sm.getDataSource());
CRFDAO crfDao = new CRFDAO(sm.getDataSource());
Map sedCrfBeans = null;
for (Iterator it = eventDefinitionDefaultVersions.keySet().iterator(); it.hasNext(); ) {
if (sedCrfBeans == null)
sedCrfBeans = new LinkedHashMap();
StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) it.next();
List crfVersions = (ArrayList) eventDefinitionDefaultVersions.get(sedBean);
for (Iterator crfIt = crfVersions.iterator(); crfIt.hasNext(); ) {
CRFVersionBean crfVersionBean = (CRFVersionBean) crfIt.next();
allSectionBeans = new ArrayList<SectionBean>();
ArrayList sectionBeans = new ArrayList();
ItemGroupDAO itemGroupDao = new ItemGroupDAO(sm.getDataSource());
// Find truely grouped tables, not groups with a name of 'Ungrouped'
List<ItemGroupBean> itemGroupBeans = itemGroupDao.findOnlyGroupsByCRFVersionID(crfVersionBean.getId());
CRFBean crfBean = crfDao.findByVersionId(crfVersionBean.getId());
if (itemGroupBeans.size() > 0) {
// get a DisplaySectionBean for each section of the CRF, sort
// them, then
// dispatch the request to a print JSP. The constructor for this
// handler takes
// a boolean value depending on whether data is involved or not
// ('false' in terms of this
// servlet; see PrintDataEntryServlet).
DisplaySectionBeanHandler handler = new DisplaySectionBeanHandler(false, getDataSource(), getServletContext());
handler.setCrfVersionId(crfVersionBean.getId());
//handler.setEventCRFId(eventCRFId);
List<DisplaySectionBean> displaySectionBeans = handler.getDisplaySectionBeans();
request.setAttribute("listOfDisplaySectionBeans", displaySectionBeans);
// Make available the CRF names and versions for
// the web page's header
CRFVersionBean crfverBean = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionBean.getId());
request.setAttribute("crfVersionBean", crfverBean);
request.setAttribute("crfBean", crfBean);
// Set an attribute signaling that data is not involved
request.setAttribute("dataInvolved", "false");
PrintCRFBean printCrfBean = new PrintCRFBean();
printCrfBean.setDisplaySectionBeans(displaySectionBeans);
printCrfBean.setCrfVersionBean(crfVersionBean);
printCrfBean.setCrfBean(crfBean);
printCrfBean.setEventCrfBean(ecb);
printCrfBean.setGrouped(true);
List list = (ArrayList) sedCrfBeans.get(sedBean);
if (list == null)
list = new ArrayList();
list.add(printCrfBean);
sedCrfBeans.put(sedBean, list);
continue;
}
ecb = new EventCRFBean();
ecb.setCRFVersionId(crfVersionBean.getId());
CRFVersionBean version = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionBean.getId());
ArrayList sects = (ArrayList) sdao.findByVersionId(version.getId());
for (int i = 0; i < sects.size(); i++) {
sb = (SectionBean) sects.get(i);
// super.sb = sb;
int sectId = sb.getId();
if (sectId > 0) {
allSectionBeans.add((SectionBean) sdao.findByPK(sectId));
}
}
request.setAttribute(INPUT_EVENT_CRF, ecb);
request.setAttribute(SECTION_BEAN, sb);
request.setAttribute(ALL_SECTION_BEANS, allSectionBeans);
sectionBeans = super.getAllDisplayBeans(request);
DisplaySectionBean dsb = super.getDisplayBean(false, false, request, isSubmitted);
PrintCRFBean printCrfBean = new PrintCRFBean();
printCrfBean.setAllSections(sectionBeans);
printCrfBean.setDisplaySectionBean(dsb);
printCrfBean.setEventCrfBean(ecb);
printCrfBean.setCrfVersionBean(crfVersionBean);
printCrfBean.setCrfBean(crfBean);
printCrfBean.setGrouped(false);
List list = (ArrayList) sedCrfBeans.get(sedBean);
if (list == null)
list = new ArrayList();
list.add(printCrfBean);
sedCrfBeans.put(sedBean, list);
}
}
request.setAttribute("sedCrfBeans", sedCrfBeans);
request.setAttribute("studyName", currentStudy.getName());
forwardPage(Page.VIEW_ALL_DEFAULT_CRF_VERSIONS_PRINT, request, response);
}
use of org.akaza.openclinica.bean.submit.SectionBean in project OpenClinica by OpenClinica.
the class ViewSectionDataEntryRESTUrlServlet method processRequest.
@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
FormProcessor fp = new FormProcessor(request);
StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
boolean isSubmitted = false;
EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) request.getAttribute(EVENT_DEF_CRF_BEAN);
if (!fp.getString("exitTo").equals("")) {
request.setAttribute("exitTo", request.getContextPath() + "/" + fp.getString("exitTo"));
}
int crfVersionId = fp.getInt("crfVersionId", true);
Integer sectionId = (Integer) request.getAttribute("sectionId");
if (sectionId == null || sectionId == 0) {
sectionId = new Integer(1);
}
int eventCRFId = fp.getInt(EVENT_CRF_ID, true);
int studySubjectId = fp.getInt("studySubjectId", true);
String action = fp.getString("action");
HttpSession session = request.getSession();
String fromResolvingNotes = fp.getString("fromResolvingNotes", true);
if (StringUtil.isBlank(fromResolvingNotes)) {
session.removeAttribute(ViewNotesServlet.WIN_LOCATION);
session.removeAttribute(ViewNotesServlet.NOTES_TABLE);
}
// Added for
request.setAttribute("studySubjectId", studySubjectId + "");
// Mantis
// Issue
// 2268
// Added
request.setAttribute("crfListPage", fp.getString("crfListPage"));
// for
// Mantis
// Issue
// 2268
// Added for
request.setAttribute("eventId", fp.getString("eventId"));
// Mantis
// Issue
// 2268
// YW <<
int sedId = fp.getInt("sedId");
request.setAttribute("sedId", sedId + "");
int crfId = fp.getInt("crfId");
// BWP>> ... try to get crfId from crfVersionId
if (crfId == 0 && crfVersionId > 0) {
CRFVersionDAO crfVDao = new CRFVersionDAO(getDataSource());
CRFVersionBean crvVBean = (CRFVersionBean) crfVDao.findByPK(crfVersionId);
if (crvVBean != null) {
crfId = crvVBean.getCrfId();
}
}
// YW >>
// int eventDefinitionCRFId = fp.getInt("eventDefinitionCRFId");
Integer eventDefinitionCRFId = (Integer) (request.getAttribute("eventDefinitionCRFId"));
EventDefinitionCRFDAO eventCrfDao = new EventDefinitionCRFDAO(getDataSource());
edcb = (EventDefinitionCRFBean) eventCrfDao.findByPK(eventDefinitionCRFId);
if (eventCRFId == 0 && edcb.getStudyId() != currentStudy.getParentStudyId() && edcb.getStudyId() != currentStudy.getId()) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_study_contact_sysadmin"), request);
throw new InsufficientPermissionException(Page.MENU_SERVLET, resexception.getString("not_director"), "1");
}
if (crfId == 0 && eventDefinitionCRFId > 0) {
// eventCrfDao.findByPK(eventDefinitionCRFId);
if (edcb != null) {
crfId = edcb.getCrfId();
}
}
request.setAttribute("crfId", crfId + "");
request.setAttribute("eventDefinitionCRFId", eventDefinitionCRFId + "");
String printVersion = fp.getString("print");
// BWP>> this has to be removed for CRFs that do not display an
// interviewdate
// for a particular event
session.removeAttribute("presetValues");
EventCRFDAO ecdao = new EventCRFDAO(getDataSource());
SectionDAO sdao = new SectionDAO(getDataSource());
String age = "";
if (sectionId == 0 && crfVersionId == 0 && eventCRFId == 0) {
addPageMessage(respage.getString("please_choose_a_CRF_to_view"), request);
// forwardPage(Page.SUBMIT_DATA_SERVLET);
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET, request, response);
// >> changed tbh, 06/2009
return;
}
if (studySubjectId > 0) {
StudySubjectDAO ssdao = new StudySubjectDAO(getDataSource());
StudySubjectBean sub = (StudySubjectBean) ssdao.findByPK(studySubjectId);
request.setAttribute("studySubject", sub);
}
if (eventCRFId > 0) {
// for event crf, the input crfVersionId from url =0
ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
StudyEventDAO sedao = new StudyEventDAO(getDataSource());
StudyEventBean event = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
// event.getSubjectEventStatus().getName());
if (event.getSubjectEventStatus().equals(SubjectEventStatus.LOCKED)) {
request.setAttribute("isLocked", "yes");
// System.out.println("this event crf is locked");
} else // @pgawade 28-Aug-2012 Reverted the change no. 2 in
// https://issuetracker.openclinica.com/view.php?id=12343#c56722
{
request.setAttribute("isLocked", "no");
}
if (studySubjectId <= 0) {
studySubjectId = event.getStudySubjectId();
request.setAttribute("studySubjectId", studySubjectId + "");
}
// Get the status/number of item discrepancy notes
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(getDataSource());
ArrayList<DiscrepancyNoteBean> allNotes = new ArrayList<DiscrepancyNoteBean>();
List<DiscrepancyNoteBean> eventCrfNotes = new ArrayList<DiscrepancyNoteBean>();
List<DiscrepancyNoteThread> noteThreads = new ArrayList<DiscrepancyNoteThread>();
// if (eventCRFId > 0) {
// this method finds only parent notes
allNotes = dndao.findAllTopNotesByEventCRF(eventCRFId);
// add interviewer.jsp related notes to this Collection
eventCrfNotes = dndao.findOnlyParentEventCRFDNotesFromEventCRF(ecb);
if (!eventCrfNotes.isEmpty()) {
allNotes.addAll(eventCrfNotes);
// make sure a necessary request attribute "hasNameNote" is set
// properly
this.setAttributeForInterviewerDNotes(eventCrfNotes, request);
}
// }
// Create disc note threads out of the various notes
DiscrepancyNoteUtil dNoteUtil = new DiscrepancyNoteUtil();
noteThreads = dNoteUtil.createThreadsOfParents(allNotes, getDataSource(), currentStudy, null, -1, true);
// variables that provide values for the CRF discrepancy note header
int updatedNum = 0;
int openNum = 0;
int closedNum = 0;
int resolvedNum = 0;
int notAppNum = 0;
DiscrepancyNoteBean tempBean;
for (DiscrepancyNoteThread dnThread : noteThreads) {
/*
* 3014: do not count parent beans, only the last child disc
* note of the thread.
*/
tempBean = dnThread.getLinkedNoteList().getLast();
if (tempBean != null) {
if (ResolutionStatus.UPDATED.equals(tempBean.getResStatus())) {
updatedNum++;
} else if (ResolutionStatus.OPEN.equals(tempBean.getResStatus())) {
openNum++;
} else if (ResolutionStatus.CLOSED.equals(tempBean.getResStatus())) {
// if (dn.getParentDnId() > 0){
closedNum++;
// }
} else if (ResolutionStatus.RESOLVED.equals(tempBean.getResStatus())) {
// if (dn.getParentDnId() > 0){
resolvedNum++;
// }
} else if (ResolutionStatus.NOT_APPLICABLE.equals(tempBean.getResStatus())) {
notAppNum++;
}
}
}
request.setAttribute("updatedNum", updatedNum + "");
request.setAttribute("openNum", openNum + "");
request.setAttribute("closedNum", closedNum + "");
request.setAttribute("resolvedNum", resolvedNum + "");
request.setAttribute("notAppNum", notAppNum + "");
DisplayTableOfContentsBean displayBean = TableOfContentsServlet.getDisplayBean(ecb, getDataSource(), currentStudy);
// Make sure that the interviewDate in the eventCRF is properly
// formatted
// for viewSectionDataEntry.jsp --> interviewer.jsp
// int studyEventId = (Integer)request.getAttribute("studyEvent");
// SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
//
Date tmpDate = displayBean.getEventCRF().getDateInterviewed();
String formattedInterviewerDate;
try {
DateFormat local_df = new SimpleDateFormat(resformat.getString("date_format_string"), ResourceBundleProvider.getLocale());
formattedInterviewerDate = local_df.format(tmpDate);
} catch (Exception e) {
formattedInterviewerDate = "";
}
HashMap presetVals = (HashMap) session.getAttribute("presetValues");
if (presetVals == null) {
presetVals = new HashMap();
session.setAttribute("presetValues", presetVals);
}
presetVals.put("interviewDate", formattedInterviewerDate);
request.setAttribute("toc", displayBean);
ArrayList sections = displayBean.getSections();
request.setAttribute("sectionNum", sections.size() + "");
if (!sections.isEmpty()) {
if (sectionId == 0) {
SectionBean firstSec = (SectionBean) sections.get(0);
sectionId = firstSec.getId();
}
} else {
addPageMessage(respage.getString("there_are_no_sections_ins_this_CRF"), request);
// forwardPage(Page.SUBMIT_DATA_SERVLET);
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET, request, response);
// >> changed tbh, 06/2009
return;
}
} else if (crfVersionId > 0) {
// for viewing blank CRF
DisplayTableOfContentsBean displayBean = ViewTableOfContentServlet.getDisplayBean(getDataSource(), crfVersionId);
request.setAttribute("toc", displayBean);
ArrayList sections = displayBean.getSections();
request.setAttribute("sectionNum", sections.size() + "");
if (!sections.isEmpty()) {
if (sectionId == 0) {
SectionBean firstSec = (SectionBean) sections.get(0);
sectionId = firstSec.getId();
}
} else {
addPageMessage(respage.getString("there_are_no_sections_ins_this_CRF_version"), request);
if (eventCRFId == 0) {
forwardPage(Page.CRF_LIST_SERVLET, request, response);
} else {
// forwardPage(Page.SUBMIT_DATA_SERVLET);
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET, request, response);
// >> changed tbh, 06/2009
}
return;
}
}
sb = (SectionBean) sdao.findByPK(sectionId);
if (eventCRFId == 0) {
ecb = new EventCRFBean();
ecb.setCRFVersionId(sb.getCRFVersionId());
if (currentStudy.getParentStudyId() > 0) {
// this is a site,find parent
StudyDAO studydao = new StudyDAO(getDataSource());
StudyBean parentStudy = (StudyBean) studydao.findByPK(currentStudy.getParentStudyId());
request.setAttribute("studyTitle", parentStudy.getName());
request.setAttribute("siteTitle", currentStudy.getName());
} else {
request.setAttribute("studyTitle", currentStudy.getName());
}
} else {
ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
request.setAttribute(INPUT_EVENT_CRF, ecb);
request.setAttribute(SECTION_BEAN, sb);
// This is the StudySubjectBean
StudySubjectDAO ssdao = new StudySubjectDAO(getDataSource());
StudySubjectBean sub = (StudySubjectBean) ssdao.findByPK(ecb.getStudySubjectId());
// This is the SubjectBean
SubjectDAO subjectDao = new SubjectDAO(getDataSource());
int subjectId = sub.getSubjectId();
int studyId = sub.getStudyId();
SubjectBean subject = (SubjectBean) subjectDao.findByPK(subjectId);
// Let us process the age
if (currentStudy.getStudyParameterConfig().getCollectDob().equals("1")) {
StudyEventDAO sedao = new StudyEventDAO(getDataSource());
StudyEventBean se = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
se.setStudyEventDefinition(sed);
request.setAttribute("studyEvent", se);
// YW 11-16-2007 enrollment-date is used for computing age
age = Utils.getInstacne().processAge(sub.getEnrollmentDate(), subject.getDateOfBirth());
}
// Get the study then the parent study
StudyDAO studydao = new StudyDAO(getDataSource());
StudyBean study = (StudyBean) studydao.findByPK(studyId);
if (study.getParentStudyId() > 0) {
// this is a site,find parent
StudyBean parentStudy = (StudyBean) studydao.findByPK(study.getParentStudyId());
request.setAttribute("studyTitle", parentStudy.getName());
request.setAttribute("siteTitle", study.getName());
} else {
request.setAttribute("studyTitle", study.getName());
}
request.setAttribute("studySubject", sub);
request.setAttribute("subject", subject);
request.setAttribute("age", age);
}
// FormBeanUtil formUtil = new FormBeanUtil();
// DisplaySectionBean newDisplayBean = new DisplaySectionBean();
boolean hasItemGroup = false;
// we will look into db to see if any repeating items for this CRF
// section
ItemGroupDAO igdao = new ItemGroupDAO(getDataSource());
List<ItemGroupBean> itemGroups = igdao.findLegitGroupBySectionId(sectionId);
if (!itemGroups.isEmpty()) {
hasItemGroup = true;
}
// if the List of DisplayFormGroups is empty, then the servlet defers to
// the prior method
// of generating a DisplaySectionBean for the application
DisplaySectionBean dsb;
// want to get displayBean with grouped and ungrouped items
request.setAttribute(EVENT_DEF_CRF_BEAN, edcb);
request.setAttribute(INPUT_EVENT_CRF, ecb);
request.setAttribute(SECTION_BEAN, sb);
dsb = super.getDisplayBean(hasItemGroup, false, request, isSubmitted);
FormDiscrepancyNotes discNotes = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
if (discNotes == null) {
discNotes = new FormDiscrepancyNotes();
session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes);
}
/*
* if (hasItemGroup) { //
* dsb.setDisplayItemGroups(newDisplayBean.getDisplayItemGroups());
* request.setAttribute("new_table", true); }
*/
// If the Horizontal type table will be used, then set the
// DisplaySectionBean's
// DisplayFormGroups List to the ones we have just generated
// @pgawade 30-May-2012 Fix for issue 13963 - added an extra parameter
// 'isSubmitted' to method createItemWithGroups
List<DisplayItemWithGroupBean> displayItemWithGroups = super.createItemWithGroups(dsb, hasItemGroup, eventDefinitionCRFId, request, isSubmitted);
dsb.setDisplayItemGroups(displayItemWithGroups);
super.populateNotesWithDBNoteCounts(discNotes, dsb, request);
if (fp.getString("fromViewNotes") != null && "1".equals(fp.getString("fromViewNotes"))) {
request.setAttribute("fromViewNotes", fp.getString("fromViewNotes"));
} else {
session.removeAttribute("viewNotesURL");
}
if ("saveNotes".equalsIgnoreCase(action)) {
LOGGER.info("33333how many group rows:" + dsb.getDisplayItemGroups().size());
// let's save notes for the blank items
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(getDataSource());
discNotes = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
for (int i = 0; i < dsb.getDisplayItemGroups().size(); i++) {
DisplayItemWithGroupBean diwb = dsb.getDisplayItemGroups().get(i);
if (diwb.isInGroup()) {
List<DisplayItemGroupBean> dgbs = diwb.getItemGroups();
LOGGER.info("dgbs size: " + dgbs.size());
for (int j = 0; j < dgbs.size(); j++) {
DisplayItemGroupBean displayGroup = dgbs.get(j);
List<DisplayItemBean> items = displayGroup.getItems();
LOGGER.info("item size: " + items.size());
for (DisplayItemBean displayItem : items) {
String inputName = getGroupItemInputName(displayGroup, j, displayItem);
LOGGER.info("inputName:" + inputName);
LOGGER.info("item data id:" + displayItem.getData().getId());
AddNewSubjectServlet.saveFieldNotes(inputName, discNotes, dndao, displayItem.getData().getId(), "itemData", currentStudy);
}
}
} else {
DisplayItemBean dib = diwb.getSingleItem();
// TODO work on this line
String inputName = getInputName(dib);
AddNewSubjectServlet.saveFieldNotes(inputName, discNotes, dndao, dib.getData().getId(), DiscrepancyNoteBean.ITEM_DATA, currentStudy);
ArrayList childItems = dib.getChildren();
for (int j = 0; j < childItems.size(); j++) {
DisplayItemBean child = (DisplayItemBean) childItems.get(j);
inputName = getInputName(child);
AddNewSubjectServlet.saveFieldNotes(inputName, discNotes, dndao, dib.getData().getId(), DiscrepancyNoteBean.ITEM_DATA, currentStudy);
}
}
}
addPageMessage("Discrepancy notes are saved successfully.", request);
request.setAttribute("id", studySubjectId + "");
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET, request, response);
// "ViewStudySubject?id=" + studySubjectId));
return;
} else {
request.setAttribute(BEAN_DISPLAY, dsb);
request.setAttribute(BEAN_ANNOTATIONS, ecb.getAnnotations());
request.setAttribute("sec", sb);
request.setAttribute("EventCRFBean", ecb);
int tabNum = 1;
if ("".equalsIgnoreCase(fp.getString("tabId"))) {
tabNum = 1;
} else {
tabNum = fp.getInt("tabId");
}
request.setAttribute("tabId", new Integer(tabNum).toString());
// 2808: Signal interviewer.jsp that the containing page is
// viewSectionData,
// for the purpose of suppressing discrepancy note icons for the
// interview date and name fields
request.setAttribute(ENCLOSING_PAGE, "viewSectionData");
if ("yes".equalsIgnoreCase(printVersion)) {
forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PRINT, request, response);
} else {
forwardPage(Page.VIEW_SECTION_DATA_ENTRY, request, response);
}
}
}
use of org.akaza.openclinica.bean.submit.SectionBean in project OpenClinica by OpenClinica.
the class ViewEventCRFServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
int eventCRFId = fp.getInt("id", true);
int studySubId = fp.getInt("studySubId", true);
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
ItemDAO idao = new ItemDAO(sm.getDataSource());
ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
SectionDAO secdao = new SectionDAO(sm.getDataSource());
if (eventCRFId == 0) {
addPageMessage(respage.getString("please_choose_an_event_CRF_to_view"));
forwardPage(Page.LIST_STUDY_SUBJECTS);
} else {
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
request.setAttribute("studySub", studySub);
EventCRFBean eventCRF = (EventCRFBean) ecdao.findByPK(eventCRFId);
CRFBean crf = cdao.findByVersionId(eventCRF.getCRFVersionId());
request.setAttribute("crf", crf);
ArrayList sections = secdao.findAllByCRFVersionId(eventCRF.getCRFVersionId());
for (int j = 0; j < sections.size(); j++) {
SectionBean section = (SectionBean) sections.get(j);
ArrayList itemData = iddao.findAllByEventCRFId(eventCRFId);
ArrayList displayItemData = new ArrayList();
for (int i = 0; i < itemData.size(); i++) {
ItemDataBean id = (ItemDataBean) itemData.get(i);
DisplayItemBean dib = new DisplayItemBean();
ItemBean item = (ItemBean) idao.findByPK(id.getItemId());
ItemFormMetadataBean ifm = ifmdao.findByItemIdAndCRFVersionId(item.getId(), eventCRF.getCRFVersionId());
item.setItemMeta(ifm);
dib.setItem(item);
dib.setData(id);
dib.setMetadata(ifm);
displayItemData.add(dib);
}
section.setItems(displayItemData);
}
request.setAttribute("sections", sections);
request.setAttribute("studySubId", new Integer(studySubId).toString());
forwardPage(Page.VIEW_EVENT_CRF);
}
}
use of org.akaza.openclinica.bean.submit.SectionBean in project OpenClinica by OpenClinica.
the class DataEntryServlet method createItemWithGroups.
//@pgawade 30-May-2012 Fix for issue 13963 - added an extra parameter 'isSubmitted' to method createItemWithGroups
protected List<DisplayItemWithGroupBean> createItemWithGroups(DisplaySectionBean dsb, boolean hasItemGroup, int eventCRFDefId, HttpServletRequest request, boolean isSubmitted) {
HttpSession session = request.getSession();
List<DisplayItemWithGroupBean> displayItemWithGroups = new ArrayList<DisplayItemWithGroupBean>();
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
ItemDAO idao = new ItemDAO(getDataSource());
SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) request.getAttribute(EVENT_DEF_CRF_BEAN);
// BWP>> Get a List<String> of any null values such as NA or NI
// method returns null values as a List<String>
// >>BWP
ArrayList items = dsb.getItems();
// For adding null values to display items
FormBeanUtil formBeanUtil = new FormBeanUtil();
List<String> nullValuesList = formBeanUtil.getNullValuesByEventCRFDefId(eventCRFDefId, getDataSource());
LOGGER.trace("single items size: " + items.size());
for (int i = 0; i < items.size(); i++) {
DisplayItemBean item = (DisplayItemBean) items.get(i);
DisplayItemWithGroupBean newOne = new DisplayItemWithGroupBean();
newOne.setSingleItem(runDynamicsItemCheck(item, null, request));
newOne.setOrdinal(item.getMetadata().getOrdinal());
newOne.setInGroup(false);
newOne.setPageNumberLabel(item.getMetadata().getPageNumberLabel());
displayItemWithGroups.add(newOne);
// logger.trace("just added on line 1979:
// "+newOne.getSingleItem().getData().getValue());
}
if (hasItemGroup) {
ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
ArrayList<ItemDataBean> data = iddao.findAllBySectionIdAndEventCRFId(sb.getId(), ecb.getId());
HashMap<String, ItemDataBean> dataMap = (HashMap<String, ItemDataBean>) getAllActive(data);
if (data != null && data.size() > 0) {
session.setAttribute(HAS_DATA_FLAG, true);
}
LOGGER.trace("found data: " + data.size());
LOGGER.trace("data.toString: " + data.toString());
for (DisplayItemGroupBean itemGroup : dsb.getDisplayFormGroups()) {
LOGGER.debug("found one itemGroup");
DisplayItemWithGroupBean newOne = new DisplayItemWithGroupBean();
// to arrange item groups and other single items, the ordinal of
// a item group will be the ordinal of the first item in this
// group
DisplayItemBean firstItem = itemGroup.getItems().get(0);
// so we are either checking the first or the last item, BUT ONLY ONCE
newOne.setPageNumberLabel(firstItem.getMetadata().getPageNumberLabel());
newOne.setItemGroup(itemGroup);
newOne.setInGroup(true);
newOne.setOrdinal(itemGroup.getGroupMetaBean().getOrdinal());
List<ItemBean> itBeans = idao.findAllItemsByGroupIdOrdered(itemGroup.getItemGroupBean().getId(), sb.getCRFVersionId());
List<DisplayItemBean> dibs = new ArrayList();
boolean hasData = false;
int checkAllColumns = 0;
if (data.size() > 0)
hasData = true;
//@pgawade 30-May-2012 Fix for issue 13963 - added an extra parameter 'isSubmitted' to method buildMatrixForRepeatingGroups
newOne = buildMatrixForRepeatingGroups(newOne, itemGroup, ecb, sb, itBeans, dataMap, nullValuesList, isSubmitted);
if (hasData) {
//TODO: fix the group_has_data flag on bean not on session
session.setAttribute(GROUP_HAS_DATA, Boolean.TRUE);
} else {
session.setAttribute(GROUP_HAS_DATA, Boolean.FALSE);
// no data, still add a blank row for displaying
if (nullValuesList != null && nullValuesList.size() > 0) {
LOGGER.trace("set with nullValuesList of : " + nullValuesList);
}
dibs = FormBeanUtil.getDisplayBeansFromItems(itBeans, getDataSource(), ecb, sb.getId(), nullValuesList, getServletContext());
DisplayItemGroupBean digb2 = new DisplayItemGroupBean();
digb2.setItems(dibs);
digb2.setEditFlag("initial");
}
displayItemWithGroups.add(newOne);
}
}
// if hasItemGroup
Collections.sort(displayItemWithGroups);
return displayItemWithGroups;
}
use of org.akaza.openclinica.bean.submit.SectionBean in project OpenClinica by OpenClinica.
the class DataEntryServlet method loadFormValueForItemGroup.
/**
* This methods will create an array of DisplayItemGroupBean, which contains multiple rows for an item group on the data entry form.
*
* @param digb
* The Item group which has multiple data rows
* @param dbGroups
* The original array got from DB which contains multiple data rows
* @param formGroups
* The new array got from front end which contains multiple data rows
* @param request TODO
* @return new constructed formGroups, compare to dbGroups, some rows are update, some new ones are added and some are removed
*/
protected List<DisplayItemGroupBean> loadFormValueForItemGroup(DisplayItemGroupBean digb, List<DisplayItemGroupBean> dbGroups, List<DisplayItemGroupBean> formGroups, int eventDefCRFId, HttpServletRequest request) {
SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
int repeatMax = digb.getGroupMetaBean().getRepeatMax();
FormProcessor fp = new FormProcessor(request);
ItemDAO idao = new ItemDAO(getDataSource());
List<ItemBean> itBeans = idao.findAllItemsByGroupId(digb.getItemGroupBean().getId(), sb.getCRFVersionId());
LOGGER.debug("+++ starting to review groups: " + repeatMax);
long timeCheck = System.currentTimeMillis();
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
// adding this code from below, since we want to pass a null values list
// in all cases of getDisplayBeansFromItems().
// For adding null values to display items
FormBeanUtil formBeanUtil = new FormBeanUtil();
List<String> nullValuesList = new ArrayList<String>();
// BWP>> Get a List<String> of any null values such as NA or NI
// method returns null values as a List<String>
nullValuesList = formBeanUtil.getNullValuesByEventCRFDefId(eventDefCRFId, getDataSource());
// >>BWP
// logger.trace("+++ starting to review groups 2: " + repeatMax);
long two = System.currentTimeMillis() - timeCheck;
// logger.trace("time 2: " + two + "ms");
// >>TBH below dual for loops need a breaker to avoid a performance hit
int firstLoopBreak = 0;
int secondLoopBreak = 0;
ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
int maxOrdinal = iddao.getMaxOrdinalForGroup(ecb, sb, digb.getItemGroupBean());
repeatMax = (repeatMax < maxOrdinal) ? maxOrdinal : repeatMax;
for (int i = 0; i < repeatMax; i++) {
DisplayItemGroupBean formGroup = new DisplayItemGroupBean();
formGroup.setItemGroupBean(digb.getItemGroupBean());
formGroup.setGroupMetaBean(runDynamicsCheck(digb.getGroupMetaBean(), request));
ItemGroupBean igb = digb.getItemGroupBean();
// want to do deep copy here, so always get a fresh copy for items,
// may use other better way to do, like clone
List<DisplayItemBean> dibs = FormBeanUtil.getDisplayBeansFromItems(itBeans, getDataSource(), ecb, sb.getId(), nullValuesList, getServletContext());
// and then get newly created rows later, tbh 01/2010
if (fp.getStartsWith(igb.getOid() + "_manual" + i + "input")) {
formGroup.setOrdinal(i);
formGroup.setFormInputOrdinal(i);
formGroup.setAuto(false);
formGroup.setInputId(igb.getOid() + "_manual" + i);
LOGGER.debug("1: set auto to false for " + igb.getOid() + " " + i);
dibs = processInputForGroupItem(fp, dibs, i, digb, false);
formGroup.setItems(dibs);
formGroups.add(formGroup);
} else if (!StringUtil.isBlank(fp.getString(igb.getOid() + "_manual" + i + ".newRow"))) {
// ||
// (fp.getStartsWith(igb.getOid() + "_manual" + i + "input"))) {
// the ordinal is the number got from [ ] and submitted by
// repetition javascript
formGroup.setOrdinal(i);
formGroup.setFormInputOrdinal(i);
formGroup.setInputId(igb.getOid() + "_manual" + i + ".newRow");
formGroup.setAuto(false);
LOGGER.debug("2: set auto to false for " + igb.getOid() + " " + i);
dibs = processInputForGroupItem(fp, dibs, i, digb, false);
formGroup.setItems(dibs);
formGroups.add(formGroup);
} else {
firstLoopBreak++;
}
if (firstLoopBreak > 14) {
LOGGER.debug("break first loop");
break;
}
}
// end of for (int i = 0; i < repeatMax; i++)
// >>TBH remove the above eventually, repeat some work here?
LOGGER.trace("+++ starting to review groups 3: " + repeatMax);
two = System.currentTimeMillis() - timeCheck;
LOGGER.trace("time 3: " + two + "ms");
// had the call to form bean utils here, tbh
for (int i = 0; i < repeatMax; i++) {
DisplayItemGroupBean formGroup = new DisplayItemGroupBean();
formGroup.setItemGroupBean(digb.getItemGroupBean());
// try {
// // set isShown here, tbh 04/2010
// boolean showGroup = getItemMetadataService().isGroupShown(digb.getGroupMetaBean().getId(), ecb);
// logger.debug("found show group for group meta bean " + digb.getGroupMetaBean().getId() + ": " + showGroup);
// if (showGroup) {
// digb.getGroupMetaBean().setShowGroup(showGroup);
// // we are only hiding, not showing (for now) tbh
// }
// // << tbh 04/2010
// } catch (OpenClinicaException oce) {
// // do nothing for right now, just store the bean
// logger.debug("throws an OCE for " + digb.getGroupMetaBean().getId());
// }
formGroup.setGroupMetaBean(runDynamicsCheck(digb.getGroupMetaBean(), request));
ItemGroupBean igb = digb.getItemGroupBean();
// adding this code from below, since we want to pass a null values
// list
// in all cases of getDisplayBeansFromItems().
// For adding null values to display items
// FormBeanUtil formBeanUtil = new FormBeanUtil();
// List<String> nullValuesList = new ArrayList<String>();
// BWP>> Get a List<String> of any null values such as NA or NI
// method returns null values as a List<String>
// >>BWP
// want to do deep copy here, so always get a fresh copy for items,
// may use other better way to do, like clone
// moved it back down here to fix another bug, tbh 12-3-2007
List<DisplayItemBean> dibs = FormBeanUtil.getDisplayBeansFromItems(itBeans, getDataSource(), ecb, sb.getId(), nullValuesList, getServletContext());
LOGGER.trace("+++count for dibs after deep copy: " + dibs.size());
two = System.currentTimeMillis() - timeCheck;
// created by rep model(add button)
if (fp.getStartsWith(igb.getOid() + "_" + i + "input")) {
formGroup.setInputId(igb.getOid() + "_" + i);
if (i == 0) {
// ordinal that will be saved into
formGroup.setOrdinal(i);
// DB
} else {
// from 0 again, the
formGroup.setFormInputOrdinal(i);
// ordinal from front
// end page, needs to be
// reprocessed
}
formGroup.setAuto(true);
LOGGER.debug("1: set auto to TRUE for " + igb.getOid() + " " + i);
dibs = processInputForGroupItem(fp, dibs, i, digb, true);
LOGGER.trace("+++ group ordinal: " + i + " igb name " + igb.getName());
formGroup.setItems(dibs);
formGroups.add(formGroup);
} else if (!StringUtil.isBlank(fp.getString(igb.getOid() + "_" + i + ".newRow"))) {
// || (fp.getStartsWith(igb.getOid() + "_" + i + "input"))) {
// the ordinal is the number got from [ ] and submitted by
// repetition javascript
formGroup.setInputId(igb.getOid() + "_" + i);
if (i == 0) {
// ordinal that will be saved into
formGroup.setOrdinal(i);
// DB
} else {
// from 0 again, the
formGroup.setFormInputOrdinal(i);
// ordinal from front
// end page, needs to be
// reprocessed
}
// String fieldName = igb.getOid() + "_" + i + this.getInputName(dib);
// if (!StringUtil.isBlank(fp.getString(fieldName))) {
// if (i != repeatMax) {
// formGroup.setAuto(false);
// logger.debug("set auto to false for " + igb.getOid() + " " + i);
// } else {
formGroup.setAuto(true);
LOGGER.debug("2: set auto to TRUE for " + igb.getOid() + " " + i);
dibs = processInputForGroupItem(fp, dibs, i, digb, true);
LOGGER.trace("+++ group ordinal: " + i + " igb name " + igb.getName());
formGroup.setItems(dibs);
formGroups.add(formGroup);
} else {
secondLoopBreak++;
}
if (secondLoopBreak > 14) {
LOGGER.debug("break second loop");
break;
}
}
// end of for (int i = 0; i < repeatMax; i++)
LOGGER.debug("first loop: " + firstLoopBreak);
LOGGER.debug("second loop: " + secondLoopBreak);
LOGGER.trace("+++ starting to review groups 4: " + repeatMax);
two = System.currentTimeMillis() - timeCheck;
LOGGER.trace("time 4: " + two + "ms");
// checks how many rows are manually created, not added by repetition
// model
int manualRows = getManualRows(formGroups);
// for (int j = 0; j < formGroups.size(); j++) {
// DisplayItemGroupBean formItemGroup = formGroups.get(j);
// // logger.trace("begin formGroup Ordinal:" +
// // formItemGroup.getOrdinal());
// if (formItemGroup.isAuto() == false) {
// manualRows = manualRows + 1;
// }
// }
LOGGER.debug(" manual rows " + manualRows + " formGroup size " + formGroups.size());
request.setAttribute("manualRows", new Integer(manualRows));
// reset ordinal for the auto-created rows except for the first row
for (int j = 0; j < formGroups.size(); j++) {
DisplayItemGroupBean formItemGroup = formGroups.get(j);
if (formItemGroup.isAuto() && formItemGroup.getFormInputOrdinal() > 0) {
LOGGER.trace("+++ formInputOrdinal() " + formItemGroup.getFormInputOrdinal());
// rows included in the model: first row, last existing row and
// new rows
// the rows in between are manually added
// set the correct ordinal that will be saved into DB
// the rows generated by model starts from 0, need to add the
// number of manual rows to
// get the correct ordinals, otherwise, we will have duplicate
// ordinals like two ordinal 0
formItemGroup.setOrdinal(formItemGroup.getFormInputOrdinal() + manualRows);
}
}
LOGGER.trace("+++ starting to review groups 5: " + repeatMax);
two = System.currentTimeMillis() - timeCheck;
LOGGER.trace("time 5: " + two + "ms");
// sort all the rows by ordinal
Collections.sort(formGroups);
LOGGER.trace("group row size:" + formGroups.size());
// suppose we have 3 rows of data from db, the orginal order is 0,1,2,
// repetition model will submit row number in [ ] like the following:
// 0,1,2.. consecutive numbers, means no row removed in between
// 0,1,3,4.. the 2rd row is removed, 3 and 4 are new rows
int previous = -1;
for (int j = 0; j < formGroups.size(); j++) {
DisplayItemGroupBean formItemGroup = formGroups.get(j);
LOGGER.trace("formGroup Ordinal:" + formItemGroup.getOrdinal());
// tbh 08/2009
if (formItemGroup.getOrdinal() == previous) {
LOGGER.debug("found a match btw previous and ordinal");
formItemGroup.setEditFlag("edit");
formItemGroup.setOrdinal(previous + 1);
// dbGroups.get(j).setEditFlag("edit");
}
// << tbh 08/2009
if (formItemGroup.getOrdinal() > dbGroups.size() - 1) {
formItemGroup.setEditFlag("add");
} else {
for (int i = 0; i < dbGroups.size(); i++) {
DisplayItemGroupBean dbItemGroup = dbGroups.get(i);
if (formItemGroup.getOrdinal() == i) {
// display, so need to insert this row, not update
if ("initial".equalsIgnoreCase(dbItemGroup.getEditFlag())) {
formItemGroup.setEditFlag("add");
} else {
dbItemGroup.setEditFlag("edit");
// need to set up item data id in order to update
for (DisplayItemBean dib : dbItemGroup.getItems()) {
ItemDataBean data = dib.getData();
for (DisplayItemBean formDib : formItemGroup.getItems()) {
if (formDib.getItem().getId() == dib.getItem().getId()) {
formDib.getData().setId(data.getId());
// this will save the data from IDE
// complete, used only for DDE
formDib.setDbData(dib.getData());
// tbh removed below line so as not to
// log so much, 112007
LOGGER.debug("+++ +++ form dib get data set id " + data.getId());
break;
}
}
}
formItemGroup.setEditFlag("edit");
}
// else
break;
}
}
}
// else
previous = formItemGroup.getOrdinal();
}
LOGGER.trace("+++ === DB group row:" + dbGroups.size());
LOGGER.trace("+++ === DB group contents: " + dbGroups.toString());
// cannot get it.-jxu
for (int i = 0; i < dbGroups.size(); i++) {
DisplayItemGroupBean dbItemGroup = dbGroups.get(i);
LOGGER.trace("+++ found edit flag of " + dbItemGroup.getEditFlag() + " for #" + dbItemGroup.getOrdinal());
// logger.debug("+++ found edit flag of " + dbItemGroup.getEditFlag() + " for #" + dbItemGroup.getOrdinal() + ": " + i);
if (!"edit".equalsIgnoreCase(dbItemGroup.getEditFlag()) && !"initial".equalsIgnoreCase(dbItemGroup.getEditFlag())) {
// >> tbh if the group is not shown, we should not touch it 05/2010
if (dbItemGroup.getGroupMetaBean().isShowGroup()) {
LOGGER.trace("+++ one row removed, edit flag was " + dbItemGroup.getEditFlag());
LOGGER.debug("+++ one row removed, edit flag was " + dbItemGroup.getEditFlag());
dbItemGroup.setEditFlag("remove");
}
// << tbh
}
}
LOGGER.debug("+++ about to return form groups: " + formGroups.toString());
for (int j = 0; j < formGroups.size(); j++) {
DisplayItemGroupBean formGroup = formGroups.get(j);
formGroup.setIndex(j);
}
return formGroups;
}
Aggregations