use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.
the class StudyInfoPanel method setData.
/**
* setData, the external function which creates data for the panel to
* reflect.
*
* @param page
* @param session
* @param request
*/
public void setData(Page page, HttpSession session, HttpServletRequest request) {
Locale locale = request.getLocale();
resword = ResourceBundleProvider.getWordsBundle();
local_sdf = new SimpleDateFormat(ResourceBundleProvider.getFormatBundle(locale).getString("date_format_string"));
try {
// defaults, can be reset by mistake by running through one page,
// tbh
this.setStudyInfoShown(true);
this.setOrderedData(false);
// try to avoid errors, tbh
if (page.equals(Page.CREATE_DATASET_1)) {
this.reset();
// this.setData("Number of Steps", "5");
} else if (page.equals(Page.CREATE_DATASET_2) || page.equals(Page.CREATE_DATASET_EVENT_ATTR) || page.equals(Page.CREATE_DATASET_SUB_ATTR) || page.equals(Page.CREATE_DATASET_CRF_ATTR) || page.equals(Page.CREATE_DATASET_GROUP_ATTR) || page.equals(Page.CREATE_DATASET_VIEW_SELECTED)) {
HashMap eventlist = (HashMap) request.getAttribute("eventlist");
ArrayList displayData = generateEventTree(eventlist);
this.reset();
this.setUserOrderedData(displayData);
this.setStudyInfoShown(false);
this.setOrderedData(true);
this.setCreateDataset(true);
this.setSubmitDataModule(false);
this.setExtractData(false);
} else if (page.equals(Page.CREATE_DATASET_3)) {
this.reset();
this.setStudyInfoShown(false);
this.setOrderedData(false);
this.setCreateDataset(true);
this.setSubmitDataModule(false);
this.setExtractData(false);
DatasetBean dsb = (DatasetBean) session.getAttribute("newDataset");
int ev_count = dsb.getItemIds().size();
this.setData(resword.getString("items_selected"), new Integer(ev_count).toString());
} else if (page.equals(Page.CREATE_DATASET_4)) {
this.reset();
this.setStudyInfoShown(false);
this.setOrderedData(false);
this.setCreateDataset(true);
this.setSubmitDataModule(false);
this.setExtractData(false);
this.removeData(resword.getString("beginning_date"));
this.removeData(resword.getString("ending_date"));
DatasetBean dsb = (DatasetBean) session.getAttribute("newDataset");
int ev_count = dsb.getItemIds().size();
this.setData(resword.getString("items_selected"), new Integer(ev_count).toString());
if ("01/01/1900".equals(english_sdf.format(dsb.getDateStart()))) {
this.setData(resword.getString("beginning_date"), resword.getString("not_specified"));
} else {
this.setData(resword.getString("beginning_date"), local_sdf.format(dsb.getDateStart()));
}
if ("12/31/2100".equals(english_sdf.format(dsb.getDateEnd()))) {
this.setData(resword.getString("ending_date"), resword.getString("not_specified"));
} else {
this.setData(resword.getString("ending_date"), local_sdf.format(dsb.getDateEnd()));
}
FilterBean fb = (FilterBean) session.getAttribute("newFilter");
if (fb != null) {
this.setData("Added Filter", fb.getName());
}
} else if (page.equals(Page.APPLY_FILTER)) {
DatasetBean dsb = (DatasetBean) session.getAttribute("newDataset");
this.setData(resword.getString("beginning_date"), local_sdf.format(dsb.getDateStart()));
this.setData(resword.getString("ending_date"), local_sdf.format(dsb.getDateEnd()));
} else if (page.equals(Page.CONFIRM_DATASET)) {
this.reset();
this.setStudyInfoShown(false);
this.setOrderedData(false);
this.setCreateDataset(true);
this.setSubmitDataModule(false);
this.setExtractData(false);
DatasetBean dsb = (DatasetBean) session.getAttribute("newDataset");
this.setData(resword.getString("dataset_name"), dsb.getName());
this.setData(resword.getString("dataset_description"), dsb.getDescription());
int ev_count = dsb.getItemIds().size();
this.setData(resword.getString("items_selected"), new Integer(ev_count).toString());
if ("01/01/1900".equals(english_sdf.format(dsb.getDateStart()))) {
this.setData(resword.getString("beginning_date"), resword.getString("not_specified"));
} else {
this.setData(resword.getString("beginning_date"), local_sdf.format(dsb.getDateStart()));
}
if ("12/31/2100".equals(english_sdf.format(dsb.getDateEnd()))) {
this.setData(resword.getString("ending_date"), resword.getString("not_specified"));
} else {
this.setData(resword.getString("ending_date"), local_sdf.format(dsb.getDateEnd()));
}
FilterBean fb = (FilterBean) session.getAttribute("newFilter");
if (fb != null) {
this.setData(resword.getString("added_filter"), fb.getName());
}
} else if (page.equals(Page.CREATE_FILTER_SCREEN_3_1)) {
CRFVersionBean cvBean = (CRFVersionBean) session.getAttribute("cvBean");
this.setData(resword.getString("CRF_version_selected"), cvBean.getName());
} else if (page.equals(Page.CREATE_FILTER_SCREEN_3_2)) {
SectionBean secBean = (SectionBean) session.getAttribute("secBean");
this.setData(resword.getString("section_selected"), secBean.getName());
Collection metadatas = (Collection) request.getAttribute("metadatas");
this.setData(resword.getString("number_of_questions"), new Integer(metadatas.size()).toString());
} else if (page.equals(Page.CREATE_FILTER_SCREEN_4)) {
} else if (page.equals(Page.CREATE_FILTER_SCREEN_5)) {
// blank here to prevent data reset, tbh
} else if (page.equals(Page.ADMIN_SYSTEM)) {
// blank here , info set in servlet itself
} else if (page.equals(Page.VIEW_STUDY_SUBJECT) || page.equals(Page.LIST_EVENTS_FOR_SUBJECT)) {
// special case, unlocks study name, subject name, and
// visits
// TODO set all this up, tbh
/*
* set up the side info panel to create the following upon entry
* from the ViewStudyServlet Study X Subject Y StudyEventDef Z1
* StudyEventDef Z2 <status-tag> CRF A1 <status-tag> CRF A2 Z1
* should be collapsible/expandible, etc.
*
* We can pull things from the session and the request:
*/
/*
* StudyBean study = (StudyBean) request.getAttribute("study");
* StudySubjectBean studySubject = (StudySubjectBean)
* request.getAttribute("studySub"); EntityBeanTable table =
* (EntityBeanTable) request.getAttribute("table"); EventCRFBean
* ecb = (EventCRFBean)request.getAttribute("eventCRF");
* this.reset(); ArrayList rows = table.getRows(); ArrayList
* beans = DisplayStudyEventBean.generateBeansFromRows(rows);
*
*
* addStudyEventTree(study, studySubject, beans, ecb);
*/
// this.setIconInfoShown(false);
// this.setManageSubject(true);
this.reset();
this.setStudyInfoShown(true);
this.setOrderedData(true);
this.setExtractData(false);
this.setSubmitDataModule(false);
this.setCreateDataset(false);
this.setIconInfoShown(false);
this.setManageSubject(true);
request.setAttribute("showDDEIcon", Boolean.TRUE);
} else if (page.equals(Page.ENTER_DATA_FOR_STUDY_EVENT) || page.equals(Page.ENTER_DATA_FOR_STUDY_EVENT_SERVLET)) {
StudyBean study = (StudyBean) session.getAttribute("study");
StudySubjectBean studySubject = (StudySubjectBean) request.getAttribute("studySubject");
ArrayList beans = (ArrayList) request.getAttribute("beans");
EventCRFBean ecb = (EventCRFBean) request.getAttribute("eventCRF");
this.reset();
addStudyEventTree(study, studySubject, beans, ecb, true);
this.setStudyInfoShown(false);
this.setOrderedData(true);
this.setSubmitDataModule(true);
this.setExtractData(false);
this.setCreateDataset(false);
this.setIconInfoShown(false);
} else if (page.equals(Page.INTERVIEWER) || page.equals(Page.TABLE_OF_CONTENTS) || page.equals(Page.TABLE_OF_CONTENTS_SERVLET) || page.equals(Page.INITIAL_DATA_ENTRY) || page.equals(Page.INITIAL_DATA_ENTRY_SERVLET) || page.equals(Page.DOUBLE_DATA_ENTRY) || page.equals(Page.DOUBLE_DATA_ENTRY_SERVLET) || page.equals(Page.ADMIN_EDIT) || page.equals(Page.ADMIN_EDIT_SERVLET)) {
/*
* pages designed to also follow the above format; check to see
* if they are in the session already, and does not refresh.
* TODO refine and test
*/
StudyBean study = (StudyBean) session.getAttribute("study");
StudySubjectBean studySubject = (StudySubjectBean) request.getAttribute("studySubject");
ArrayList beans = (ArrayList) request.getAttribute("beans");
EventCRFBean ecb = (EventCRFBean) request.getAttribute("eventCRF");
this.reset();
addStudyEventTree(study, studySubject, beans, ecb, false);
this.setStudyInfoShown(false);
this.setOrderedData(true);
this.setSubmitDataModule(true);
this.setExtractData(false);
this.setCreateDataset(false);
this.setIconInfoShown(true);
} else if (page.equals(Page.EDIT_DATASET)) {
this.reset();
// HashMap eventlist = (HashMap)
// request.getAttribute("eventlist");
HashMap eventlist = (LinkedHashMap) session.getAttribute("eventsForCreateDataset");
ArrayList displayData = generateEventTree(eventlist);
this.setCreateDataset(true);
this.setOrderedData(true);
this.setUserOrderedData(displayData);
this.setStudyInfoShown(true);
this.setSubmitDataModule(false);
this.setExtractData(false);
DatasetBean dsb = (DatasetBean) request.getAttribute("dataset");
this.setData(resword.getString("dataset_name"), dsb.getName());
this.setData(resword.getString("date_created"), local_sdf.format(dsb.getCreatedDate()));
this.setData(resword.getString("dataset_owner"), dsb.getOwner().getName());
this.setData(resword.getString("date_last_run"), local_sdf.format(dsb.getDateLastRun()));
} else if (page.equals(Page.EXPORT_DATASETS)) {
this.setCreateDataset(false);
} else if (page.equals(Page.GENERATE_DATASET_HTML)) {
DatasetBean db = (DatasetBean) request.getAttribute("dataset");
ExtractBean exbean = (ExtractBean) request.getAttribute("extractBean");
this.reset();
ArrayList displayData = new ArrayList();
displayData = generateDatasetTree(exbean, db);
this.setUserOrderedData(displayData);
this.setStudyInfoShown(false);
this.setOrderedData(true);
this.setExtractData(true);
this.setSubmitDataModule(false);
this.setCreateDataset(false);
} else if (page.equals(Page.LIST_STUDY_SUBJECT) || page.equals(Page.LIST_STUDY_SUBJECTS) || page.equals(Page.SUBMIT_DATA) || page.equals(Page.SUBMIT_DATA_SERVLET)) {
this.reset();
this.setStudyInfoShown(true);
this.setOrderedData(true);
this.setExtractData(false);
this.setSubmitDataModule(false);
this.setCreateDataset(false);
this.setIconInfoShown(false);
this.setManageSubject(true);
// don't want to show DDE icon key for subject matrix page
request.setAttribute("showDDEIcon", Boolean.FALSE);
} else if (page.equals(Page.VIEW_SECTION_DATA_ENTRY) || page.equals(Page.VIEW_SECTION_DATA_ENTRY_SERVLET)) {
this.reset();
this.setStudyInfoShown(true);
this.setOrderedData(true);
this.setExtractData(false);
this.setSubmitDataModule(false);
this.setCreateDataset(false);
this.setIconInfoShown(true);
this.setManageSubject(false);
} else if (page.equals(Page.CREATE_SUBJECT_GROUP_CLASS) || page.equals(Page.CREATE_SUBJECT_GROUP_CLASS_CONFIRM) || page.equals(Page.UPDATE_SUBJECT_GROUP_CLASS) || page.equals(Page.UPDATE_SUBJECT_GROUP_CLASS_CONFIRM)) {
this.reset();
this.setStudyInfoShown(true);
this.setOrderedData(true);
this.setExtractData(false);
this.setSubmitDataModule(false);
this.setCreateDataset(false);
this.setIconInfoShown(true);
this.setManageSubject(false);
} else {
// automatically reset if we don't know what's happening
this.reset();
this.setStudyInfoShown(true);
this.setOrderedData(true);
this.setExtractData(false);
this.setSubmitDataModule(false);
this.setCreateDataset(false);
this.setIconInfoShown(true);
this.setManageSubject(false);
}
} catch (Exception e) {
this.reset();
}
}
use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.
the class ViewItemDetailServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
int itemId = fp.getInt(ITEM_ID);
String itemOid = fp.getString(ITEM_OID);
ItemDAO idao = new ItemDAO(sm.getDataSource());
ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(sm.getDataSource());
ItemGroupMetadataDAO igmdao = new ItemGroupMetadataDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
SectionDAO sectionDao = new SectionDAO(sm.getDataSource());
if (itemId == 0 && itemOid == null) {
addPageMessage(respage.getString("please_choose_an_item_first"));
forwardPage(Page.ITEM_DETAIL);
return;
}
ItemBean item = itemId > 0 ? (ItemBean) idao.findByPK(itemId) : (ItemBean) idao.findByOid(itemOid).get(0);
ArrayList versions = idao.findAllVersionsByItemId(item.getId());
ArrayList versionItems = new ArrayList();
CRFBean crf = null;
ItemFormMetadataBean imfBean = null;
// finds each item metadata for each version
for (int i = 0; i < versions.size(); i++) {
Integer versionId = (Integer) versions.get(i);
CRFVersionBean version = (CRFVersionBean) cvdao.findByPK(versionId.intValue());
if (versionId != null && versionId.intValue() > 0) {
// YW 08-22-2007
if (igmdao.versionIncluded(versionId)) {
imfBean = ifmdao.findByItemIdAndCRFVersionId(item.getId(), versionId.intValue());
imfBean.setCrfVersionName(version.getName());
crf = (CRFBean) cdao.findByPK(version.getCrfId());
imfBean.setCrfName(crf.getName());
versionItems.add(imfBean);
} else {
imfBean = ifmdao.findByItemIdAndCRFVersionIdNotInIGM(item.getId(), versionId.intValue());
imfBean.setCrfVersionName(version.getName());
crf = (CRFBean) cdao.findByPK(version.getCrfId());
imfBean.setCrfName(crf.getName());
versionItems.add(imfBean);
}
}
}
SectionBean section = (SectionBean) sectionDao.findByPK(imfBean.getSectionId());
request.setAttribute(VERSION_ITEMS, versionItems);
request.setAttribute(ITEM_BEAN, item);
request.setAttribute("crf", crf);
request.setAttribute("section", section);
request.setAttribute("ifmdBean", imfBean);
forwardPage(Page.ITEM_DETAIL);
}
use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.
the class RemoveEventDefinitionServlet method processRequest.
@Override
public void processRequest() throws Exception {
String idString = request.getParameter("id");
int defId = Integer.valueOf(idString.trim()).intValue();
StudyEventDefinitionDAO sdao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) sdao.findByPK(defId);
// checkRoleByUserAndStudy(ub.getName(), sed.getStudyId(), 0);
if (currentStudy.getId() != sed.getStudyId()) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
forwardPage(Page.MENU_SERVLET);
return;
}
// find all CRFs
EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(sm.getDataSource());
ArrayList eventDefinitionCRFs = (ArrayList) edao.findAllByDefinition(defId);
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
ArrayList versions = (ArrayList) cvdao.findAllByCRF(edc.getCrfId());
edc.setVersions(versions);
CRFBean crf = (CRFBean) cdao.findByPK(edc.getCrfId());
edc.setCrfName(crf.getName());
CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(edc.getDefaultVersionId());
edc.setDefaultVersionName(defaultVersion.getName());
CRFBean cBean = (CRFBean) cdao.findByPK(edc.getCrfId());
String crfPath = sed.getOid() + "." + cBean.getOid();
edc.setOffline(getEventDefinitionCrfTagService().getEventDefnCrfOfflineStatus(2, crfPath, true));
}
// finds all events
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
ArrayList events = (ArrayList) sedao.findAllByDefinition(sed.getId());
String action = request.getParameter("action");
if (StringUtil.isBlank(idString)) {
addPageMessage(respage.getString("please_choose_a_SED_to_remove"));
forwardPage(Page.LIST_DEFINITION_SERVLET);
} else {
if ("confirm".equalsIgnoreCase(action)) {
if (!sed.getStatus().equals(Status.AVAILABLE)) {
addPageMessage(respage.getString("this_SED_is_not_available_for_this_study") + respage.getString("please_contact_sysadmin_for_more_information"));
forwardPage(Page.LIST_DEFINITION_SERVLET);
return;
}
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
if (participateFormStatus.equals("enabled"))
baseUrl();
request.setAttribute("participateFormStatus", participateFormStatus);
request.setAttribute("definitionToRemove", sed);
request.setAttribute("eventDefinitionCRFs", eventDefinitionCRFs);
request.setAttribute("events", events);
forwardPage(Page.REMOVE_DEFINITION);
} else {
logger.info("submit to remove the definition");
// remove definition
sed.setStatus(Status.DELETED);
sed.setUpdater(ub);
sed.setUpdatedDate(new Date());
sdao.update(sed);
// remove all crfs
for (int j = 0; j < eventDefinitionCRFs.size(); j++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(j);
if (!edc.getStatus().equals(Status.DELETED)) {
edc.setStatus(Status.AUTO_DELETED);
edc.setUpdater(ub);
edc.setUpdatedDate(new Date());
edao.update(edc);
}
}
// remove all events
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
for (int j = 0; j < events.size(); j++) {
StudyEventBean event = (StudyEventBean) events.get(j);
if (!event.getStatus().equals(Status.DELETED)) {
event.setStatus(Status.AUTO_DELETED);
event.setUpdater(ub);
event.setUpdatedDate(new Date());
sedao.update(event);
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
// remove all the item data
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
for (int k = 0; k < eventCRFs.size(); k++) {
EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
if (!eventCRF.getStatus().equals(Status.DELETED)) {
eventCRF.setStatus(Status.AUTO_DELETED);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
ArrayList itemDatas = iddao.findAllByEventCRFId(eventCRF.getId());
for (int a = 0; a < itemDatas.size(); a++) {
ItemDataBean item = (ItemDataBean) itemDatas.get(a);
if (!item.getStatus().equals(Status.DELETED)) {
item.setStatus(Status.AUTO_DELETED);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
}
}
String emailBody = respage.getString("the_SED") + sed.getName() + " " + respage.getString("has_been_removed_from_the_study") + currentStudy.getName() + ".";
addPageMessage(emailBody);
// sendEmail(emailBody);
forwardPage(Page.LIST_DEFINITION_SERVLET);
}
}
}
use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.
the class PrintEventCRFServlet method processRequest.
@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
FormProcessor fp = new FormProcessor(request);
StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
// The PrintDataEntry servlet handles this parameter
int eventCRFId = fp.getInt("ecId");
//JN:The following were the the global variables, moved as local.
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
StudyEventDefinitionDAO sedao = new StudyEventDefinitionDAO(getDataSource());
int defId = fp.getInt("id", true);
boolean isSubmitted = false;
ArrayList<SectionBean> allSectionBeans;
if (defId == 0) {
addPageMessage(respage.getString("please_choose_a_definition_to_view"), request);
forwardPage(Page.LIST_DEFINITION_SERVLET, request, response);
} else {
// definition id
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) sedao.findByPK(defId);
EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(getDataSource());
ArrayList eventDefinitionCRFs = (ArrayList) edao.findAllByDefinition(defId);
CRFVersionDAO cvdao = new CRFVersionDAO(getDataSource());
CRFDAO cdao = new CRFDAO(getDataSource());
ArrayList defaultVersions = new ArrayList();
for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.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());
//There could be separate EventDefinitionCRF objects with same default version id.
if (defaultVersions.contains(defaultVersion)) {
continue;
}
edc.setDefaultVersionName(defaultVersion.getName());
if (edc.getStatus().isAvailable()) {
defaultVersions.add(defaultVersion);
}
}
// Whether IE6 or IE7 is involved
String isIE = fp.getString("ie");
if ("y".equalsIgnoreCase(isIE)) {
request.setAttribute("isInternetExplorer", "true");
}
int eventDefinitionCRFId = fp.getInt("eventDefinitionCRFId");
// EventDefinitionCRFDao findByStudyEventIdAndCRFVersionId(int
// studyEventId, int crfVersionId)
SectionDAO sdao = new SectionDAO(getDataSource());
CRFVersionDAO crfVersionDAO = new CRFVersionDAO(getDataSource());
CRFDAO crfDao = new CRFDAO(getDataSource());
ArrayList printCrfBeans = new ArrayList();
for (Iterator it = defaultVersions.iterator(); it.hasNext(); ) {
allSectionBeans = new ArrayList<SectionBean>();
ArrayList sectionBeans = new ArrayList();
CRFVersionBean crfVersionBean = (CRFVersionBean) it.next();
// The existing application doesn't print null values, even if they are
// defined in the event definition
// int crfVersionId = fp.getInt("id");
// BWP 2/7/2008>> Find out if the CRF has grouped tables, and if so,
// use
// that dedicated JSP
ItemGroupDAO itemGroupDao = new ItemGroupDAO(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);
printCrfBeans.add(printCrfBean);
printCrfBean.setGrouped(true);
// IllegalStateException
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(ALL_SECTION_BEANS, allSectionBeans);
request.setAttribute(INPUT_EVENT_CRF, ecb);
sectionBeans = super.getAllDisplayBeans(request);
request.setAttribute(SECTION_BEAN, sb);
DisplaySectionBean dsb = super.getDisplayBean(false, false, request, isSubmitted);
// request.setAttribute("allSections", sectionBeans);
// request.setAttribute("displayAllCRF", "1");
// request.setAttribute(BEAN_DISPLAY, dsb);
// request.setAttribute(BEAN_ANNOTATIONS, ecb.getAnnotations());
// request.setAttribute("sec", sb);
// request.setAttribute("EventCRFBean", super.ecb);
PrintCRFBean printCrfBean = new PrintCRFBean();
printCrfBean.setAllSections(sectionBeans);
printCrfBean.setDisplaySectionBean(dsb);
printCrfBean.setEventCrfBean(ecb);
printCrfBean.setCrfVersionBean(crfVersionBean);
printCrfBean.setCrfBean(crfBean);
printCrfBeans.add(printCrfBean);
printCrfBean.setGrouped(false);
}
String studyName = null;
String siteName = null;
if (currentStudy.getParentStudyId() > 0) {
studyName = currentStudy.getParentStudyName();
siteName = currentStudy.getName();
} else {
studyName = currentStudy.getName();
}
request.setAttribute("printCrfBeans", printCrfBeans);
request.setAttribute("studyName", studyName);
request.setAttribute("site", siteName);
request.setAttribute("eventDefinition", sed.getName());
forwardPage(Page.VIEW_DEFAULT_CRF_VERSIONS_PRINT, request, response);
}
}
use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.
the class RestoreEventCRFServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
// eventCRFId
int eventCRFId = fp.getInt("id");
// studySubjectId
int studySubId = fp.getInt("studySubId");
checkStudyLocked("ViewStudySubject?id" + studySubId, respage.getString("current_study_locked"));
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
StudyDAO sdao = new StudyDAO(sm.getDataSource());
if (eventCRFId == 0) {
addPageMessage(respage.getString("please_choose_an_event_CRF_to_restore"));
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
} else {
EventCRFBean eventCRF = (EventCRFBean) ecdao.findByPK(eventCRFId);
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
// YW 11-07-2007, an event CRF could not be restored if its study
// subject has been removed
Status s = studySub.getStatus();
if ("removed".equalsIgnoreCase(s.getName()) || "auto-removed".equalsIgnoreCase(s.getName())) {
addPageMessage(resword.getString("event_CRF") + resterm.getString("could_not_be") + resterm.getString("restored") + "." + respage.getString("study_subject_has_been_deleted"));
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
}
// YW
request.setAttribute("studySub", studySub);
// construct info needed on view event crf page
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
int crfVersionId = eventCRF.getCRFVersionId();
CRFBean cb = cdao.findByVersionId(crfVersionId);
eventCRF.setCrf(cb);
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(crfVersionId);
eventCRF.setCrfVersion(cvb);
// then get the definition so we can call
// DisplayEventCRFBean.setFlags
int studyEventId = eventCRF.getStudyEventId();
StudyEventBean event = (StudyEventBean) sedao.findByPK(studyEventId);
int studyEventDefinitionId = sedao.getDefinitionIdFromStudyEventId(studyEventId);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(studyEventDefinitionId);
event.setStudyEventDefinition(sed);
request.setAttribute("event", event);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
StudyBean study = (StudyBean) sdao.findByPK(studySub.getStudyId());
EventDefinitionCRFBean edc = edcdao.findByStudyEventDefinitionIdAndCRFId(study, studyEventDefinitionId, cb.getId());
DisplayEventCRFBean dec = new DisplayEventCRFBean();
dec.setEventCRF(eventCRF);
dec.setFlags(eventCRF, ub, currentRole, edc.isDoubleEntry());
// find all item data
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
ArrayList itemData = iddao.findAllByEventCRFId(eventCRF.getId());
request.setAttribute("items", itemData);
String action = request.getParameter("action");
if ("confirm".equalsIgnoreCase(action)) {
if (!eventCRF.getStatus().equals(Status.DELETED) && !eventCRF.getStatus().equals(Status.AUTO_DELETED)) {
addPageMessage(respage.getString("this_event_CRF_avilable_for_study") + " " + " " + respage.getString("please_contact_sysadmin_for_more_information"));
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
return;
}
request.setAttribute("displayEventCRF", dec);
forwardPage(Page.RESTORE_EVENT_CRF);
} else {
logger.info("submit to restore the event CRF from study");
eventCRF.setStatus(Status.AVAILABLE);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
// restore all the item data
for (int a = 0; a < itemData.size(); a++) {
ItemDataBean item = (ItemDataBean) itemData.get(a);
if (item.getStatus().equals(Status.AUTO_DELETED)) {
item.setStatus(Status.AVAILABLE);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
String emailBody = respage.getString("the_event_CRF") + cb.getName() + " " + respage.getString("has_been_restored_to_the_event") + " " + event.getStudyEventDefinition().getName() + ".";
addPageMessage(emailBody);
sendEmail(emailBody);
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
}
}
}
Aggregations