use of org.akaza.openclinica.web.bean.EntityBeanTable in project OpenClinica by OpenClinica.
the class ViewStudyEventsServlet method genTables.
/**
*
* @param fp
* @param definitions
* @param startDate
* @param endDate
* @param sedId
* @param definitionId
* @param statusId
* @return
*/
private ArrayList genTables(FormProcessor fp, ArrayList definitions, Date startDate, Date endDate, int sedId, int definitionId, int statusId) {
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ArrayList allEvents = new ArrayList();
definitions = findDefinitionById(definitions, definitionId);
// YW <<
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ArrayList studySubjects = ssdao.findAllByStudyId(currentStudy.getId());
// YW >>
for (int i = 0; i < definitions.size(); i++) {
ViewEventDefinitionBean ved = new ViewEventDefinitionBean();
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) definitions.get(i);
ved.setDefinition(sed);
// YW <<
ArrayList events = new ArrayList();
for (int s = 0; s < studySubjects.size(); ++s) {
StudySubjectBean ssb = (StudySubjectBean) studySubjects.get(s);
ArrayList evts = sedao.findAllWithSubjectLabelByStudySubjectAndDefinition(ssb, sed.getId());
for (int v = 0; v < evts.size(); ++v) {
StudyEventBean seb = (StudyEventBean) evts.get(v);
if (!(currentRole.isDirector() || currentRole.isCoordinator()) && seb.getSubjectEventStatus().isLocked()) {
seb.setEditable(false);
}
events.add(seb);
}
}
int subjectScheduled = 0;
int subjectCompleted = 0;
int subjectDiscontinued = 0;
events = findEventByStatusAndDate(events, statusId, startDate, endDate);
Date firstStartDateForScheduled = null;
Date lastCompletionDate = null;
// find the first firstStartDateForScheduled
for (int k = 0; k < events.size(); k++) {
StudyEventBean se = (StudyEventBean) events.get(k);
if (se.getSubjectEventStatus().equals(SubjectEventStatus.SCHEDULED)) {
firstStartDateForScheduled = se.getDateStarted();
break;
}
}
// find the first lastCompletionDate
for (int k = 0; k < events.size(); k++) {
StudyEventBean se = (StudyEventBean) events.get(k);
if (se.getSubjectEventStatus().equals(SubjectEventStatus.COMPLETED) && se.getDateEnded() != null) {
lastCompletionDate = se.getDateEnded();
break;
}
}
for (int j = 0; j < events.size(); j++) {
StudyEventBean se = (StudyEventBean) events.get(j);
if (se.getSubjectEventStatus().equals(SubjectEventStatus.SCHEDULED)) {
subjectScheduled++;
if (se.getDateStarted().before(new Date())) {
ArrayList eventCRFs = ecdao.findAllByStudyEvent(se);
if (eventCRFs.isEmpty()) {
se.setScheduledDatePast(true);
}
}
if (firstStartDateForScheduled == null) {
firstStartDateForScheduled = se.getDateStarted();
} else if (se.getDateStarted().before(firstStartDateForScheduled)) {
firstStartDateForScheduled = se.getDateStarted();
}
} else if (se.getSubjectEventStatus().equals(SubjectEventStatus.COMPLETED)) {
subjectCompleted++;
if (lastCompletionDate == null) {
lastCompletionDate = se.getDateEnded();
} else if (se.getDateEnded() != null && se.getDateEnded().after(lastCompletionDate)) {
lastCompletionDate = se.getDateEnded();
}
} else if (se.getSubjectEventStatus().getId() > 4) {
// dropped out/stopped/skipped/relapse
subjectDiscontinued++;
}
}
ved.setSubjectCompleted(subjectCompleted);
ved.setSubjectScheduled(subjectScheduled);
ved.setSubjectDiscontinued(subjectDiscontinued);
ved.setFirstScheduledStartDate(firstStartDateForScheduled);
ved.setLastCompletionDate(lastCompletionDate);
EntityBeanTable table;
if (sedId == sed.getId()) {
// apply finding function or ordering
// function
// to a specific table
table = fp.getEntityBeanTable();
} else {
table = new EntityBeanTable();
}
// sort by event
table.setSortingIfNotExplicitlySet(1, false);
// start date,
// desc
ArrayList allEventRows = StudyEventRow.generateRowsFromBeans(events);
String[] columns = { resword.getString("study_subject_ID"), resword.getString("event_date_started"), resword.getString("subject_event_status"), resword.getString("actions") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.hideColumnLink(3);
HashMap args = new HashMap();
args.put("sedId", new Integer(sed.getId()).toString());
args.put("definitionId", new Integer(definitionId).toString());
args.put("statusId", new Integer(statusId).toString());
args.put("startDate", local_df.format(startDate));
args.put("endDate", local_df.format(endDate));
table.setQuery("ViewStudyEvents", args);
table.setRows(allEventRows);
table.computeDisplay();
ved.setStudyEventTable(table);
if (!events.isEmpty()) {
allEvents.add(ved);
}
}
//A. Hamid.
return allEvents;
}
use of org.akaza.openclinica.web.bean.EntityBeanTable in project OpenClinica by OpenClinica.
the class ListCRFServlet method processRequest.
/**
* Finds all the crfs
*
*/
@Override
public void processRequest() throws Exception {
if (currentStudy.getParentStudyId() > 0) {
addPageMessage(respage.getString("no_crf_available_study_is_a_site"));
forwardPage(Page.MENU_SERVLET);
return;
}
session.removeAttribute("version");
FormProcessor fp = new FormProcessor(request);
// checks which module the requests are from
String module = fp.getString(MODULE);
if (module.equalsIgnoreCase("admin") && !(ub.isSysAdmin() || ub.isTechAdmin())) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
forwardPage(Page.MENU_SERVLET);
return;
}
request.setAttribute(MODULE, module);
// if coming from change crf version -> display message
String crfVersionChangeMsg = fp.getString("isFromCRFVersionBatchChange");
if (crfVersionChangeMsg != null && !crfVersionChangeMsg.equals("")) {
addPageMessage(crfVersionChangeMsg);
}
// for
String dir = SQLInitServlet.getField("filePath") + "crf" + File.separator + "new" + File.separator;
// crf
// version
// spreadsheet
logger.debug("found directory: " + dir);
CRFDAO cdao = new CRFDAO(sm.getDataSource());
FormLayoutDAO fldao = new FormLayoutDAO(sm.getDataSource());
ArrayList crfs = (ArrayList) cdao.findAll();
for (int i = 0; i < crfs.size(); i++) {
CRFBean eb = (CRFBean) crfs.get(i);
logger.debug("crf id:" + eb.getId());
ArrayList versions = (ArrayList) fldao.findAllByCRF(eb.getId());
// check whether the speadsheet is available on the server
for (int j = 0; j < versions.size(); j++) {
FormLayoutBean cv = (FormLayoutBean) versions.get(j);
File file = new File(dir + eb.getId() + cv.getOid() + ".xls");
logger.debug("looking in " + dir + eb.getId() + cv.getOid() + ".xls");
if (file.exists()) {
cv.setDownloadable(true);
} else {
File file2 = new File(dir + eb.getId() + cv.getName() + ".xls");
logger.debug("initial failed, looking in " + dir + eb.getId() + cv.getName() + ".xls");
if (file2.exists()) {
cv.setDownloadable(true);
}
}
}
eb.setVersions(versions);
}
EntityBeanTable table = fp.getEntityBeanTable();
ArrayList allRows = ListCRFRow.generateRowsFromBeans(crfs);
String[] columns = { resword.getString("CRF_name"), resword.getString("date_updated"), resword.getString("last_updated_by"), resword.getString("crf_oid"), resword.getString("versions"), resword.getString("date_created"), resword.getString("owner"), resword.getString("status"), resword.getString("download"), resword.getString("actions") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.hideColumnLink(3);
// oid column
table.hideColumnLink(4);
// BWP 3281: make the "owner" column sortable; table.hideColumnLink(7);
table.hideColumnLink(8);
table.setQuery("ListCRF", new HashMap());
table.addLink(resword.getString("blank_CRF_template"), "DownloadVersionSpreadSheet?template=1");
// YW << add "Enterprise CRF Catalog" link
String crfCatalogField = "crfCatalog";
// table.addLink(resword.getString("openclinica_CRF_catalog"),
// SQLInitServlet.getEnterpriseField(crfCatalogField));
// YW >>
// TODO add i18n links to the above, tbh
table.addLink(resword.getString("create_a_new_CRF"), "CreateCRFVersion?module=" + module);
table.setRows(allRows);
table.computeDisplay();
request.setAttribute("table", table);
request.setAttribute("study", currentStudy);
resetPanel();
panel.setStudyInfoShown(false);
panel.setOrderedData(true);
panel.setSubmitDataModule(false);
panel.setExtractData(false);
panel.setCreateDataset(false);
if (crfs.size() > 0) {
setToPanel("CRFs", new Integer(crfs.size()).toString());
}
setToPanel(resword.getString("create_CRF"), respage.getString("br_create_new_CRF_entering"));
setToPanel(resword.getString("create_CRF_version"), respage.getString("br_create_new_CRF_uploading"));
setToPanel(resword.getString("revise_CRF_version"), respage.getString("br_if_you_owner_CRF_version"));
setToPanel(resword.getString("CRF_spreadsheet_template"), respage.getString("br_download_blank_CRF_spreadsheet_from"));
setToPanel(resword.getString("example_CRF_br_spreadsheets"), respage.getString("br_download_example_CRF_instructions_from"));
forwardPage(Page.CRF_LIST);
}
use of org.akaza.openclinica.web.bean.EntityBeanTable in project OpenClinica by OpenClinica.
the class ViewJobServlet method processRequest.
@Override
protected void processRequest() throws Exception {
// TODO single stage servlet where we get the list of jobs
// and push them out to the JSP page
// related classes will be required to generate the table rows
// and eventually links to view and edit the jobs as well
FormProcessor fp = new FormProcessor(request);
// First we must get a reference to a scheduler
scheduler = getScheduler();
XsltTriggerService xsltTriggerSrvc = new XsltTriggerService();
// Scheduler sched = sfb.getScheduler();
Set<TriggerKey> triggerKeys = scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(xsltTriggerSrvc.getTriggerGroupNameForExportJobs()));
String[] triggerNames = triggerKeys.stream().toArray(String[]::new);
// String[] triggerNames = scheduler.getJobNames(XsltTriggerService.TRIGGER_GROUP_NAME);
// logger.info("trigger list: "+triggerNames.length);
// logger.info("trigger names: "+triggerNames.toString());
ArrayList triggerBeans = new ArrayList();
for (String triggerName : triggerNames) {
Trigger trigger = scheduler.getTrigger(TriggerKey.triggerKey(triggerName, xsltTriggerSrvc.getTriggerGroupNameForExportJobs()));
try {
logger.debug("prev fire time " + trigger.getPreviousFireTime().toString());
logger.debug("next fire time " + trigger.getNextFireTime().toString());
logger.debug("final fire time: " + trigger.getFinalFireTime().toString());
} catch (NullPointerException npe) {
// could be nulls in the dates, etc
}
// logger.info(trigger.getDescription());
// logger.info("");//getJobDataMap()
TriggerBean triggerBean = new TriggerBean();
triggerBean.setFullName(trigger.getKey().getName());
triggerBean.setPreviousDate(trigger.getPreviousFireTime());
triggerBean.setNextDate(trigger.getNextFireTime());
if (trigger.getDescription() != null) {
triggerBean.setDescription(trigger.getDescription());
}
// setting: frequency, dataset name
JobDataMap dataMap = new JobDataMap();
DatasetDAO datasetDAO = new DatasetDAO(sm.getDataSource());
StudyDAO studyDao = new StudyDAO(sm.getDataSource());
if (trigger.getJobDataMap().size() > 0) {
dataMap = trigger.getJobDataMap();
int dsId = dataMap.getInt(ExampleSpringJob.DATASET_ID);
String periodToRun = dataMap.getString(ExampleSpringJob.PERIOD);
triggerBean.setPeriodToRun(periodToRun);
DatasetBean dataset = (DatasetBean) datasetDAO.findByPK(dsId);
triggerBean.setDataset(dataset);
triggerBean.setDatasetName(dataset.getName());
StudyBean study = (StudyBean) studyDao.findByPK(dataset.getStudyId());
triggerBean.setStudyName(study.getName());
// triggerBean.setStudyName(dataMap.getString(ExampleSpringJob.STUDY_NAME));
}
logger.debug("Trigger Priority: " + trigger.getKey().getName() + " " + trigger.getPriority());
if (scheduler.getTriggerState(TriggerKey.triggerKey(triggerName, XsltTriggerService.TRIGGER_GROUP_NAME)) == Trigger.TriggerState.PAUSED) {
triggerBean.setActive(false);
logger.debug("setting active to false for trigger: " + trigger.getKey().getName());
} else {
triggerBean.setActive(true);
logger.debug("setting active to TRUE for trigger: " + trigger.getKey().getName());
}
triggerBeans.add(triggerBean);
// our wrapper to show triggers
}
ArrayList allRows = TriggerRow.generateRowsFromBeans(triggerBeans);
EntityBeanTable table = fp.getEntityBeanTable();
String[] columns = { resword.getString("name"), resword.getString("previous_fire_time"), resword.getString("next_fire_time"), resword.getString("description"), resword.getString("period_to_run"), resword.getString("dataset"), resword.getString("study"), resword.getString("actions") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.hideColumnLink(3);
table.hideColumnLink(7);
table.setQuery("ViewJob", new HashMap());
// table.addLink("", "CreateUserAccount");
table.setSortingColumnInd(0);
table.setRows(allRows);
table.computeDisplay();
request.setAttribute("table", table);
// throw new NullPointerException("faking an error here");
forwardPage(Page.VIEW_JOB);
}
use of org.akaza.openclinica.web.bean.EntityBeanTable in project OpenClinica by OpenClinica.
the class ViewSingleJobServlet method processRequest.
@Override
protected void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
// changes to this servlet, we now look at group name too, tbh 05/2009
String triggerName = fp.getString("tname");
String gName = fp.getString("gname");
String groupName = "";
if (gName.equals("") || gName.equals("0")) {
groupName = XsltTriggerService.TRIGGER_GROUP_NAME;
} else {
// if (gName.equals("1")) {
groupName = TRIGGER_IMPORT_GROUP;
}
// << tbh 09/03/2009 #4143
scheduler = getScheduler();
Trigger trigger = scheduler.getTrigger(new TriggerKey(triggerName, groupName));
if (trigger == null) {
groupName = XsltTriggerService.TRIGGER_GROUP_NAME;
trigger = scheduler.getTrigger(new TriggerKey(triggerName.trim(), groupName));
}
// << tbh 09/03/2009 #4143
// above is a hack, if we add more trigger groups this will have
// to be redone
logger.debug("found trigger name: " + triggerName);
logger.debug("found group name: " + groupName);
TriggerBean triggerBean = new TriggerBean();
JobDataMap dataMap = new JobDataMap();
AuditEventDAO auditEventDAO = new AuditEventDAO(sm.getDataSource());
try {
triggerBean.setFullName(trigger.getKey().getName());
triggerBean.setPreviousDate(trigger.getPreviousFireTime());
triggerBean.setNextDate(trigger.getNextFireTime());
// >> set active here, tbh 10/08/2009
if (scheduler.getTriggerState(new TriggerKey(triggerName, groupName)) == Trigger.TriggerState.PAUSED) {
triggerBean.setActive(false);
logger.debug("setting active to false for trigger: " + trigger.getKey().getName());
} else {
triggerBean.setActive(true);
logger.debug("setting active to TRUE for trigger: " + trigger.getKey().getName());
}
// <<
if (trigger.getDescription() != null) {
triggerBean.setDescription(trigger.getDescription());
}
if (trigger.getJobDataMap().size() > 0) {
dataMap = trigger.getJobDataMap();
String contactEmail = dataMap.getString(XsltTriggerService.EMAIL);
logger.debug("found email: " + contactEmail);
// int dsId = new Integer(datasetId).intValue();
if (gName.equals("") || gName.equals("0")) {
String exportFormat = dataMap.getString(XsltTriggerService.EXPORT_FORMAT);
String periodToRun = dataMap.getString(ExampleSpringJob.PERIOD);
// int userId = new Integer(userAcctId).intValue();
int dsId = dataMap.getInt(ExampleSpringJob.DATASET_ID);
triggerBean.setExportFormat(exportFormat);
triggerBean.setPeriodToRun(periodToRun);
DatasetDAO datasetDAO = new DatasetDAO(sm.getDataSource());
DatasetBean dataset = (DatasetBean) datasetDAO.findByPK(dsId);
triggerBean.setDataset(dataset);
}
int userId = dataMap.getInt(ExampleSpringJob.USER_ID);
// need to set information, extract bean, user account bean
UserAccountDAO userAccountDAO = new UserAccountDAO(sm.getDataSource());
triggerBean.setContactEmail(contactEmail);
UserAccountBean userAccount = (UserAccountBean) userAccountDAO.findByPK(userId);
triggerBean.setUserAccount(userAccount);
ArrayList<AuditEventBean> triggerLogs = auditEventDAO.findAllByAuditTable(trigger.getKey().getName());
// set the table for the audit event beans here
ArrayList allRows = AuditEventRow.generateRowsFromBeans(triggerLogs);
EntityBeanTable table = fp.getEntityBeanTable();
String[] columns = { resword.getString("date_and_time"), resword.getString("action_message"), resword.getString("entity_operation"), // resword.getString("study_subject_ID"),
resword.getString("changes_and_additions"), resword.getString("actions") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.setAscendingSort(false);
table.hideColumnLink(1);
table.hideColumnLink(3);
table.hideColumnLink(4);
table.setQuery("ViewSingleJob?tname=" + triggerName + "&gname=" + gName, new HashMap());
table.setRows(allRows);
table.computeDisplay();
request.setAttribute("table", table);
}
} catch (NullPointerException e) {
// TODO Auto-generated catch block
logger.debug(" found NPE " + e.getMessage());
e.printStackTrace();
}
// need to show the extract for which this runs, which files, etc
// in other words the job data map
request.setAttribute("triggerBean", triggerBean);
request.setAttribute("groupName", groupName);
forwardPage(Page.VIEW_SINGLE_JOB);
}
use of org.akaza.openclinica.web.bean.EntityBeanTable in project OpenClinica by OpenClinica.
the class ViewStudySubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
// studySubjectId
int studySubId = fp.getInt("id", true);
String from = fp.getString("from");
String module = fp.getString(MODULE);
request.setAttribute(MODULE, module);
// if coming from change crf version -> display message
String crfVersionChangeMsg = fp.getString("isFromCRFVersionChange");
if (crfVersionChangeMsg != null && !crfVersionChangeMsg.equals("")) {
addPageMessage(crfVersionChangeMsg);
}
if (studySubId == 0) {
addPageMessage(respage.getString("please_choose_a_subject_to_view"));
forwardPage(Page.LIST_STUDY_SUBJECTS);
} else {
if (!StringUtil.isBlank(from)) {
// form ListSubject or
request.setAttribute("from", from);
// ListStudySubject
} else {
request.setAttribute("from", "");
}
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
request.setAttribute("studySub", studySub);
request.setAttribute("originatingPage", URLEncoder.encode("ViewStudySubject?id=" + studySub.getId(), "UTF-8"));
int studyId = studySub.getStudyId();
int subjectId = studySub.getSubjectId();
StudyDAO studydao = new StudyDAO(sm.getDataSource());
StudyBean study = (StudyBean) studydao.findByPK(studyId);
// Check if this StudySubject would be accessed from the Current Study
if (studySub.getStudyId() != currentStudy.getId()) {
if (currentStudy.getParentStudyId() > 0) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
forwardPage(Page.MENU_SERVLET);
return;
} else {
// The SubjectStudy is not belong to currentstudy and current study is not a site.
Collection sites = studydao.findOlnySiteIdsByStudy(currentStudy);
if (!sites.contains(study.getId())) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
forwardPage(Page.MENU_SERVLET);
return;
}
}
}
// If the study subject derives from a site, and is being viewed
// from a parent study,
// then the study IDs will be different. However, since each note is
// saved with the specific
// study ID, then its study ID may be different than the study
// subject's ID.
boolean subjectStudyIsCurrentStudy = studyId == currentStudy.getId();
boolean isParentStudy = study.getParentStudyId() < 1;
// Get any disc notes for this subject : studySubId
DiscrepancyNoteDAO discrepancyNoteDAO = new DiscrepancyNoteDAO(sm.getDataSource());
List<DiscrepancyNoteBean> allNotesforSubject = new ArrayList<DiscrepancyNoteBean>();
// These methods return only parent disc notes
if (subjectStudyIsCurrentStudy && isParentStudy) {
allNotesforSubject = discrepancyNoteDAO.findAllSubjectByStudyAndId(study, subjectId);
allNotesforSubject.addAll(discrepancyNoteDAO.findAllStudySubjectByStudyAndId(study, studySubId));
} else {
if (!isParentStudy) {
StudyBean stParent = (StudyBean) studydao.findByPK(study.getParentStudyId());
allNotesforSubject = discrepancyNoteDAO.findAllSubjectByStudiesAndSubjectId(stParent, study, subjectId);
allNotesforSubject.addAll(discrepancyNoteDAO.findAllStudySubjectByStudiesAndStudySubjectId(stParent, study, studySubId));
} else {
allNotesforSubject = discrepancyNoteDAO.findAllSubjectByStudiesAndSubjectId(currentStudy, study, subjectId);
allNotesforSubject.addAll(discrepancyNoteDAO.findAllStudySubjectByStudiesAndStudySubjectId(currentStudy, study, studySubId));
}
}
if (!allNotesforSubject.isEmpty()) {
setRequestAttributesForNotes(allNotesforSubject);
}
SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId);
if (currentStudy.getStudyParameterConfig().getCollectDob().equals("2")) {
Date dob = subject.getDateOfBirth();
if (dob != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(dob);
int year = cal.get(Calendar.YEAR);
request.setAttribute("yearOfBirth", new Integer(year));
} else {
request.setAttribute("yearOfBirth", "");
}
}
request.setAttribute("subject", subject);
/*
* StudyDAO studydao = new StudyDAO(sm.getDataSource()); StudyBean
* study = (StudyBean) studydao.findByPK(studyId);
*/
// YW 11-26-2007 <<
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
study.getStudyParameterConfig().setCollectDob(spvdao.findByHandleAndStudy(studyId, "collectDob").getValue());
// YW >>
request.setAttribute("subjectStudy", study);
if (study.getParentStudyId() > 0) {
// this is a site,find parent
StudyBean parentStudy2 = (StudyBean) studydao.findByPK(study.getParentStudyId());
request.setAttribute("parentStudy", parentStudy2);
} else {
request.setAttribute("parentStudy", new StudyBean());
}
ArrayList children = (ArrayList) sdao.findAllChildrenByPK(subjectId);
request.setAttribute("children", children);
// find study events
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudySubjectService studySubjectService = (StudySubjectService) WebApplicationContextUtils.getWebApplicationContext(getServletContext()).getBean("studySubjectService");
List<DisplayStudyEventBean> displayEvents = studySubjectService.getDisplayStudyEventsForStudySubject(studySub, ub, currentRole);
for (int i = 0; i < displayEvents.size(); i++) {
DisplayStudyEventBean decb = displayEvents.get(i);
if (!(currentRole.isDirector() || currentRole.isCoordinator()) && decb.getStudyEvent().getSubjectEventStatus().isLocked()) {
decb.getStudyEvent().setEditable(false);
}
}
if (currentStudy.getParentStudyId() > 0) {
HideCRFManager hideCRFManager = HideCRFManager.createHideCRFManager();
for (DisplayStudyEventBean displayStudyEventBean : displayEvents) {
hideCRFManager.removeHiddenEventCRF(displayStudyEventBean);
}
}
EntityBeanTable table = fp.getEntityBeanTable();
// sort by start
table.setSortingIfNotExplicitlySet(1, false);
// date, desc
ArrayList allEventRows = DisplayStudyEventRow.generateRowsFromBeans(displayEvents);
String[] columns = { resword.getString("event") + " (" + resword.getString("occurrence_number") + ")", resword.getString("start_date1"), resword.getString("location"), resword.getString("status"), resword.getString("actions"), resword.getString("CRFs_atrib") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.hideColumnLink(4);
table.hideColumnLink(5);
if (!"removed".equalsIgnoreCase(studySub.getStatus().getName()) && !"auto-removed".equalsIgnoreCase(studySub.getStatus().getName())) {
if (currentStudy.getStatus().isAvailable() && !currentRole.getRole().equals(Role.MONITOR)) {
table.addLink(resword.getString("add_new_event"), "CreateNewStudyEvent?" + CreateNewStudyEventServlet.INPUT_STUDY_SUBJECT_ID_FROM_VIEWSUBJECT + "=" + studySub.getId());
}
}
HashMap args = new HashMap();
args.put("id", new Integer(studySubId).toString());
table.setQuery("ViewStudySubject", args);
table.setRows(allEventRows);
table.computeDisplay();
request.setAttribute("table", table);
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
ArrayList groupMaps = (ArrayList) sgmdao.findAllByStudySubject(studySubId);
request.setAttribute("groups", groupMaps);
// find audit log for events
AuditEventDAO aedao = new AuditEventDAO(sm.getDataSource());
ArrayList logs = aedao.findEventStatusLogByStudySubject(studySubId);
// logger.warning("^^^ retrieved logs");
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
ArrayList eventLogs = new ArrayList();
// logger.warning("^^^ starting to iterate");
for (int i = 0; i < logs.size(); i++) {
AuditEventBean avb = (AuditEventBean) logs.get(i);
StudyEventAuditBean sea = new StudyEventAuditBean();
sea.setAuditEvent(avb);
StudyEventBean se = (StudyEventBean) sedao.findByPK(avb.getEntityId());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
sea.setDefinition(sed);
String old = avb.getOldValue().trim();
try {
if (!StringUtil.isBlank(old)) {
SubjectEventStatus oldStatus = SubjectEventStatus.get(new Integer(old).intValue());
sea.setOldSubjectEventStatus(oldStatus);
}
String newValue = avb.getNewValue().trim();
if (!StringUtil.isBlank(newValue)) {
SubjectEventStatus newStatus = SubjectEventStatus.get(new Integer(newValue).intValue());
sea.setNewSubjectEventStatus(newStatus);
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
UserAccountBean updater = (UserAccountBean) udao.findByPK(avb.getUserId());
sea.setUpdater(updater);
eventLogs.add(sea);
}
request.setAttribute("eventLogs", eventLogs);
forwardPage(Page.VIEW_STUDY_SUBJECT);
}
}
Aggregations