use of org.akaza.openclinica.dao.submit.EventCRFDAO in project OpenClinica by OpenClinica.
the class ExportExcelStudySubjectAuditLogServlet method processRequest.
@Override
public void processRequest() throws Exception {
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
AuditDAO adao = new AuditDAO(sm.getDataSource());
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
StudyDAO studydao = new StudyDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
StudySubjectBean studySubject = null;
SubjectBean subject = null;
ArrayList events = null;
ArrayList studySubjectAudits = new ArrayList();
ArrayList eventCRFAudits = new ArrayList();
ArrayList studyEventAudits = new ArrayList();
ArrayList allDeletedEventCRFs = new ArrayList();
ArrayList allEventCRFs = new ArrayList();
ArrayList allEventCRFItems = new ArrayList();
String attachedFilePath = Utils.getAttachedFilePath(currentStudy);
FormProcessor fp = new FormProcessor(request);
int studySubId = fp.getInt("id", true);
if (studySubId == 0) {
addPageMessage(respage.getString("please_choose_a_subject_to_view"));
forwardPage(Page.LIST_STUDY_SUBJECTS);
} else {
studySubject = (StudySubjectBean) subdao.findByPK(studySubId);
StudyBean study = (StudyBean) studydao.findByPK(studySubject.getStudyId());
// Check if this StudySubject would be accessed from the Current Study
if (studySubject.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;
}
}
}
subject = (SubjectBean) sdao.findByPK(studySubject.getSubjectId());
/* Show both study subject and subject audit events together */
// Study subject value changed
Collection studySubjectAuditEvents = adao.findStudySubjectAuditEvents(studySubject.getId());
// integer values.
for (Iterator iterator = studySubjectAuditEvents.iterator(); iterator.hasNext(); ) {
AuditBean auditBean = (AuditBean) iterator.next();
if (auditBean.getAuditEventTypeId() == 3) {
auditBean.setOldValue(Status.get(Integer.parseInt(auditBean.getOldValue())).getName());
auditBean.setNewValue(Status.get(Integer.parseInt(auditBean.getNewValue())).getName());
}
}
studySubjectAudits.addAll(studySubjectAuditEvents);
// Global subject value changed
studySubjectAudits.addAll(adao.findSubjectAuditEvents(subject.getId()));
studySubjectAudits.addAll(adao.findStudySubjectGroupAssignmentAuditEvents(studySubject.getId()));
// Get the list of events
events = sedao.findAllByStudySubject(studySubject);
for (int i = 0; i < events.size(); i++) {
// Link study event definitions
StudyEventBean studyEvent = (StudyEventBean) events.get(i);
studyEvent.setStudyEventDefinition((StudyEventDefinitionBean) seddao.findByPK(studyEvent.getStudyEventDefinitionId()));
// Link event CRFs
studyEvent.setEventCRFs(ecdao.findAllByStudyEvent(studyEvent));
// Find deleted Event CRFs
List deletedEventCRFs = adao.findDeletedEventCRFsFromAuditEvent(studyEvent.getId());
allDeletedEventCRFs.addAll(deletedEventCRFs);
List eventCRFs = (List) adao.findAllEventCRFAuditEvents(studyEvent.getId());
allEventCRFs.addAll(eventCRFs);
List eventCRFItems = (List) adao.findAllEventCRFAuditEventsWithItemDataType(studyEvent.getId());
allEventCRFItems.addAll(eventCRFItems);
logger.info("deletedEventCRFs size[" + deletedEventCRFs.size() + "]");
logger.info("allEventCRFItems size[" + allEventCRFItems.size() + "]");
}
for (int i = 0; i < events.size(); i++) {
StudyEventBean studyEvent = (StudyEventBean) events.get(i);
studyEventAudits.addAll(adao.findStudyEventAuditEvents(studyEvent.getId()));
ArrayList eventCRFs = studyEvent.getEventCRFs();
for (int j = 0; j < eventCRFs.size(); j++) {
// Link CRF and CRF Versions
EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(j);
eventCRF.setCrfVersion((CRFVersionBean) cvdao.findByPK(eventCRF.getCRFVersionId()));
eventCRF.setCrf(cdao.findByVersionId(eventCRF.getCRFVersionId()));
// Get the event crf audits
eventCRFAudits.addAll(adao.findEventCRFAuditEventsWithItemDataType(eventCRF.getId()));
logger.info("eventCRFAudits size [" + eventCRFAudits.size() + "] eventCRF id [" + eventCRF.getId() + "]");
}
}
ItemDataDAO itemDataDao = new ItemDataDAO(sm.getDataSource());
for (Object o : eventCRFAudits) {
AuditBean ab = (AuditBean) o;
if (ab.getAuditTable().equalsIgnoreCase("item_data")) {
ItemDataBean idBean = (ItemDataBean) itemDataDao.findByPK(ab.getEntityId());
ab.setOrdinal(idBean.getOrdinal());
}
}
}
try {
WritableFont headerFormat = new WritableFont(WritableFont.ARIAL, 8, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLUE2);
WritableCellFormat cellFormat = new WritableCellFormat();
cellFormat.setFont(headerFormat);
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=export.xls");
WorkbookSettings wbSettings = new WorkbookSettings();
wbSettings.setLocale(new Locale("en", "EN"));
WritableWorkbook workbook = Workbook.createWorkbook(response.getOutputStream(), wbSettings);
int row = 0;
// Subject Information
workbook.createSheet("Subject Information", 0);
WritableSheet excelSheet = workbook.getSheet(0);
// Subject Summary
String[] excelRow = new String[] { "study_subject_ID", "secondary_subject_ID", "date_of_birth", "person_ID", "created_by", "status" };
for (int i = 0; i < excelRow.length; i++) {
Label label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
excelSheet.addCell(label);
}
row++;
excelRow = new String[] { studySubject.getLabel(), studySubject.getSecondaryLabel(), dateFormat(subject.getDateOfBirth()), subject.getUniqueIdentifier(), studySubject.getOwner().getName(), studySubject.getStatus().getName() };
for (int i = 0; i < excelRow.length; i++) {
Label label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
excelSheet.addCell(label);
}
row++;
row++;
// Subject Audit Events
excelRow = new String[] { "audit_event", "date_time_of_server", "user", "value_type", "old", "new" };
for (int i = 0; i < excelRow.length; i++) {
Label label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
excelSheet.addCell(label);
}
row++;
for (int j = 0; j < studySubjectAudits.size(); j++) {
AuditBean audit = (AuditBean) studySubjectAudits.get(j);
excelRow = new String[] { audit.getAuditEventTypeName(), dateTimeFormat(audit.getAuditDate()), audit.getUserName(), audit.getEntityName(), audit.getOldValue(), audit.getNewValue() };
for (int i = 0; i < excelRow.length; i++) {
Label label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
excelSheet.addCell(label);
}
row++;
}
row++;
// Study Events
excelRow = new String[] { "study_events", "location", "date", "occurrence_number" };
for (int i = 0; i < excelRow.length; i++) {
Label label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
excelSheet.addCell(label);
}
row++;
for (int j = 0; j < events.size(); j++) {
StudyEventBean event = (StudyEventBean) events.get(j);
if (event.getStartTimeFlag()) {
excelRow = new String[] { event.getStudyEventDefinition().getName(), event.getLocation(), dateTimeFormat(event.getDateStarted()), Integer.toString(event.getSampleOrdinal()) };
} else {
excelRow = new String[] { event.getStudyEventDefinition().getName(), event.getLocation(), dateFormat(event.getDateStarted()), Integer.toString(event.getSampleOrdinal()) };
}
for (int i = 0; i < excelRow.length; i++) {
Label label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
excelSheet.addCell(label);
}
row++;
}
autoSizeColumns(excelSheet);
int sheet = 0;
// Study Event Summary Looper
for (int eventCount = 0; eventCount < events.size(); eventCount++) {
row = 0;
sheet++;
StudyEventBean event = (StudyEventBean) events.get(eventCount);
workbook.createSheet(event.getStudyEventDefinition().getName().replace("/", ".") + "_" + event.getSampleOrdinal(), sheet);
excelSheet = workbook.getSheet(sheet);
Label label = null;
// Header
label = new Label(0, row, ResourceBundleProvider.getResWord("name"), cellFormat);
excelSheet.addCell(label);
label = new Label(1, row, event.getStudyEventDefinition().getName(), cellFormat);
excelSheet.addCell(label);
row++;
label = new Label(0, row, "Location");
excelSheet.addCell(label);
label = new Label(1, row, event.getLocation());
excelSheet.addCell(label);
row++;
label = new Label(0, row, "Start Date");
excelSheet.addCell(label);
if (event.getStartTimeFlag()) {
label = new Label(1, row, dateTimeFormat(event.getDateStarted()));
} else {
label = new Label(1, row, dateFormat(event.getDateStarted()));
}
excelSheet.addCell(label);
row++;
label = new Label(0, row, "Status");
excelSheet.addCell(label);
label = new Label(1, row, event.getSubjectEventStatus().getName());
excelSheet.addCell(label);
row++;
label = new Label(0, row, ResourceBundleProvider.getResWord("occurrence_number"));
excelSheet.addCell(label);
label = new Label(1, row, Integer.toString(event.getSampleOrdinal()));
excelSheet.addCell(label);
row++;
row++;
// End Header
// Audit for Deleted Event CRFs
excelRow = new String[] { "name", "version", "deleted_by", "delete_date" };
for (int i = 0; i < excelRow.length; i++) {
label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
excelSheet.addCell(label);
}
row++;
for (int j = 0; j < allDeletedEventCRFs.size(); j++) {
DeletedEventCRFBean deletedEventCRF = (DeletedEventCRFBean) allDeletedEventCRFs.get(j);
if (deletedEventCRF.getStudyEventId() == event.getId()) {
excelRow = new String[] { deletedEventCRF.getCrfName(), deletedEventCRF.getFormLayout(), deletedEventCRF.getDeletedBy(), dateFormat(deletedEventCRF.getDeletedDate()) };
for (int i = 0; i < excelRow.length; i++) {
label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
excelSheet.addCell(label);
}
row++;
}
}
row++;
row++;
// Audit Events for Study Event
excelRow = new String[] { "audit_event", "date_time_of_server", "user", "value_type", "old", "new" };
for (int i = 0; i < excelRow.length; i++) {
label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
excelSheet.addCell(label);
}
row++;
for (int j = 0; j < studyEventAudits.size(); j++) {
AuditBean studyEvent = (AuditBean) studyEventAudits.get(j);
if (studyEvent.getEntityId() == event.getId()) {
String getOld = studyEvent.getOldValue();
String oldValue = "";
if (getOld.equals("0"))
oldValue = "invalid";
else if (getOld.equals("1"))
oldValue = "scheduled";
else if (getOld.equals("2"))
oldValue = "not_scheduled";
else if (getOld.equals("3"))
oldValue = "data_entry_started";
else if (getOld.equals("4"))
oldValue = "completed";
else if (getOld.equals("5"))
oldValue = "stopped";
else if (getOld.equals("6"))
oldValue = "skipped";
else if (getOld.equals("7"))
oldValue = "locked";
else if (getOld.equals("8"))
oldValue = "signed";
else
oldValue = studyEvent.getOldValue();
String getNew = studyEvent.getNewValue();
String newValue = "";
if (getNew.equals("0"))
newValue = "invalid";
else if (getNew.equals("1"))
newValue = "scheduled";
else if (getNew.equals("2"))
newValue = "not_scheduled";
else if (getNew.equals("3"))
newValue = "data_entry_started";
else if (getNew.equals("4"))
newValue = "completed";
else if (getNew.equals("5"))
newValue = "removed";
else if (getNew.equals("6"))
newValue = "skipped";
else if (getNew.equals("7"))
newValue = "locked";
else if (getNew.equals("8"))
newValue = "signed";
else if (getNew.equals("9"))
newValue = "forzen";
else
newValue = studyEvent.getNewValue();
excelRow = new String[] { studyEvent.getAuditEventTypeName(), dateTimeFormat(studyEvent.getAuditDate()), studyEvent.getUserName(), studyEvent.getEntityName() + "(" + studyEvent.getOrdinal() + ")", oldValue, newValue };
for (int i = 0; i < excelRow.length; i++) {
label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
excelSheet.addCell(label);
}
row++;
}
}
row++;
row++;
// Event CRFs Audit Events
for (int j = 0; j < allEventCRFs.size(); j++) {
AuditBean auditBean = (AuditBean) allEventCRFs.get(j);
if (auditBean.getStudyEventId() == event.getId()) {
// Audit Events for Study Event
excelRow = new String[] { "name", "version", "date_interviewed", "interviewer_name", "owner" };
for (int i = 0; i < excelRow.length; i++) {
label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
excelSheet.addCell(label);
}
row++;
excelRow = new String[] { auditBean.getCrfName(), auditBean.getCrfVersionName(), dateFormat(auditBean.getDateInterviewed()), auditBean.getInterviewerName(), auditBean.getUserName() };
for (int i = 0; i < excelRow.length; i++) {
label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
excelSheet.addCell(label);
}
row++;
row++;
excelRow = new String[] { "audit_event", "date_time_of_server", "user", "value_type", "old", "new" };
for (int i = 0; i < excelRow.length; i++) {
label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
excelSheet.addCell(label);
}
row++;
row++;
for (int k = 0; k < allEventCRFItems.size(); k++) {
row--;
AuditBean eventCrfAudit = (AuditBean) allEventCRFItems.get(k);
if (eventCrfAudit.getStudyEventId() == event.getId() && eventCrfAudit.getEventCrfVersionId() == auditBean.getEventCrfVersionId()) {
String oldValue = "";
String newValue = "";
if (eventCrfAudit.getAuditEventTypeId() == 12 || eventCrfAudit.getEntityName().equals("Status")) {
String getOld = eventCrfAudit.getOldValue();
if (getOld.equals("0"))
oldValue = "invalid";
else if (getOld.equals("1"))
oldValue = "available";
else if (getOld.equals("2"))
oldValue = "unavailable";
else if (getOld.equals("3"))
oldValue = "private";
else if (getOld.equals("4"))
oldValue = "pending";
else if (getOld.equals("5"))
oldValue = "removed";
else if (getOld.equals("6"))
oldValue = "locked";
else if (getOld.equals("7"))
oldValue = "auto-removed";
else {
oldValue = getOld;
}
} else if (eventCrfAudit.getAuditEventTypeId() == 32) {
String getOld = eventCrfAudit.getOldValue();
if (getOld.equals("0"))
oldValue = "FALSE";
else if (getOld.equals("1"))
oldValue = "TRUE";
else {
oldValue = getOld;
}
} else {
oldValue = eventCrfAudit.getOldValue();
}
if (eventCrfAudit.getAuditEventTypeId() == 12 || eventCrfAudit.getEntityName().equals("Status")) {
String getNew = eventCrfAudit.getNewValue();
if (getNew.equals("0"))
newValue = "invalid";
else if (getNew.equals("1"))
newValue = "available";
else if (getNew.equals("2"))
newValue = "unavailable";
else if (getNew.equals("3"))
newValue = "private";
else if (getNew.equals("4"))
newValue = "pending";
else if (getNew.equals("5"))
newValue = "removed";
else if (getNew.equals("6"))
newValue = "locked";
else if (getNew.equals("7"))
newValue = "auto-removed";
else {
newValue = getNew;
}
} else if (eventCrfAudit.getAuditEventTypeId() == 32) {
String getNew = eventCrfAudit.getNewValue();
if (getNew.equals("0"))
newValue = "FALSE";
else if (getNew.equals("1"))
newValue = "TRUE";
else {
newValue = getNew;
}
} else {
newValue = eventCrfAudit.getNewValue();
}
String ordinal = "";
if (eventCrfAudit.getOrdinal() != 0) {
ordinal = "(" + eventCrfAudit.getOrdinal() + ")";
} else if (eventCrfAudit.getOrdinal() == 0 && eventCrfAudit.getItemDataRepeatKey() != 0) {
ordinal = "(" + eventCrfAudit.getItemDataRepeatKey() + ")";
}
excelRow = new String[] { eventCrfAudit.getAuditEventTypeName(), dateTimeFormat(eventCrfAudit.getAuditDate()), eventCrfAudit.getUserName(), eventCrfAudit.getEntityName() + ordinal, oldValue, newValue };
for (int i = 0; i < excelRow.length; i++) {
label = new Label(i, row, ResourceBundleProvider.getResWord(excelRow[i]), cellFormat);
excelSheet.addCell(label);
}
row++;
row++;
}
row++;
}
row++;
}
autoSizeColumns(excelSheet);
}
}
workbook.write();
workbook.close();
session.setAttribute("subject", null);
session.setAttribute("study", null);
session.setAttribute("studySub", null);
session.setAttribute("studyEventAudits", null);
session.setAttribute("studySubjectAudits", null);
session.setAttribute("events", null);
session.setAttribute("eventCRFAudits", null);
session.setAttribute("allDeletedEventCRFs", null);
} catch (Exception e) {
throw e;
} finally {
// proposed move session attributes here
}
}
use of org.akaza.openclinica.dao.submit.EventCRFDAO in project OpenClinica by OpenClinica.
the class ListStudySubjectServlet method getDisplayStudyEventsForStudySubject.
public static DisplayStudyEventBean getDisplayStudyEventsForStudySubject(StudySubjectBean studySub, StudyEventBean event, DataSource ds, UserAccountBean ub, StudyUserRoleBean currentRole, StudyBean study) {
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(ds);
StudyEventDAO sedao = new StudyEventDAO(ds);
EventCRFDAO ecdao = new EventCRFDAO(ds);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(ds);
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(event.getStudyEventDefinitionId());
event.setStudyEventDefinition(sed);
// find all active crfs in the definition
ArrayList eventDefinitionCRFs = edcdao.findAllActiveByEventDefinitionId(sed.getId());
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
// construct info needed on view study event page
DisplayStudyEventBean de = new DisplayStudyEventBean();
de.setStudyEvent(event);
de.setDisplayEventCRFs(ViewStudySubjectServlet.getDisplayEventCRFs(ds, eventCRFs, eventDefinitionCRFs, ub, currentRole, event.getSubjectEventStatus(), study));
ArrayList al = ViewStudySubjectServlet.getUncompletedCRFs(ds, eventDefinitionCRFs, eventCRFs, event.getSubjectEventStatus());
// ViewStudySubjectServlet.populateUncompletedCRFsWithCRFAndVersions(ds,
// al);
de.setUncompletedCRFs(al);
return de;
}
use of org.akaza.openclinica.dao.submit.EventCRFDAO in project OpenClinica by OpenClinica.
the class ListEventDefinitionServlet method processRequest.
/**
* Processes the request
*/
@Override
public void processRequest() throws Exception {
StudyEventDefinitionDAO edao = new StudyEventDefinitionDAO(sm.getDataSource());
UserAccountDAO sdao = new UserAccountDAO(sm.getDataSource());
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
CRFDAO crfDao = new CRFDAO(sm.getDataSource());
CRFVersionDAO crfVersionDao = new CRFVersionDAO(sm.getDataSource());
ArrayList seds = edao.findAllByStudy(currentStudy);
// request.setAttribute("seds", seds);
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
for (int i = 0; i < seds.size(); i++) {
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seds.get(i);
Collection eventDefinitionCRFlist = edcdao.findAllParentsByDefinition(sed.getId());
Map crfWithDefaultVersion = new LinkedHashMap();
for (Iterator it = eventDefinitionCRFlist.iterator(); it.hasNext(); ) {
EventDefinitionCRFBean edcBean = (EventDefinitionCRFBean) it.next();
CRFBean crfBean = (CRFBean) crfDao.findByPK(edcBean.getCrfId());
CRFVersionBean crfVersionBean = (CRFVersionBean) crfVersionDao.findByPK(edcBean.getDefaultVersionId());
logger.info("ED[" + sed.getName() + "]crf[" + crfBean.getName() + "]dv[" + crfVersionBean.getName() + "]");
crfWithDefaultVersion.put(crfBean.getName(), crfVersionBean.getName());
}
sed.setCrfsWithDefaultVersion(crfWithDefaultVersion);
logger.info("CRF size [" + sed.getCrfs().size() + "]");
if (sed.getUpdater().getId() == 0) {
sed.setUpdater(sed.getOwner());
sed.setUpdatedDate(sed.getCreatedDate());
}
if (isPopulated(sed, sedao)) {
sed.setPopulated(true);
}
}
FormProcessor fp = new FormProcessor(request);
EntityBeanTable table = fp.getEntityBeanTable();
ArrayList allStudyRows = StudyEventDefinitionRow.generateRowsFromBeans(seds);
String[] columns = { resword.getString("order"), resword.getString("name"), resword.getString("OID"), resword.getString("repeating"), resword.getString("type"), resword.getString("category"), resword.getString("populated"), resword.getString("date_created"), resword.getString("date_updated"), resword.getString("CRFs"), resword.getString("default_version"), resword.getString("actions") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
// >> tbh #4169 09/2009
table.hideColumnLink(2);
table.hideColumnLink(3);
table.hideColumnLink(4);
table.hideColumnLink(6);
table.hideColumnLink(7);
table.hideColumnLink(8);
table.hideColumnLink(9);
// crfs, tbh
table.hideColumnLink(10);
table.hideColumnLink(11);
table.hideColumnLink(12);
// << tbh 09/2009
table.setQuery("ListEventDefinition", new HashMap());
// if (!currentStudy.getStatus().isLocked()) {
// table.addLink(resworkflow.getString(
// "create_a_new_study_event_definition"), "DefineStudyEvent");
// }
table.setRows(allStudyRows);
table.setPaginated(false);
table.computeDisplay();
request.setAttribute("table", table);
request.setAttribute("defSize", new Integer(seds.size()));
if (request.getParameter("read") != null && request.getParameter("read").equals("true")) {
request.setAttribute("readOnly", true);
}
forwardPage(Page.STUDY_EVENT_DEFINITION_LIST);
}
use of org.akaza.openclinica.dao.submit.EventCRFDAO in project OpenClinica by OpenClinica.
the class RemoveSiteServlet method processRequest.
@Override
public void processRequest() throws Exception {
StudyDAO sdao = new StudyDAO(sm.getDataSource());
String idString = request.getParameter("id");
logger.info("site id:" + idString);
int siteId = Integer.valueOf(idString.trim()).intValue();
StudyBean study = (StudyBean) sdao.findByPK(siteId);
if (currentStudy.getId() != study.getParentStudyId()) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
forwardPage(Page.MENU_SERVLET);
return;
}
// find all user and roles
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
ArrayList userRoles = udao.findAllByStudyId(siteId);
// find all subjects
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ArrayList subjects = ssdao.findAllByStudy(study);
// find all events
StudyEventDefinitionDAO sefdao = new StudyEventDefinitionDAO(sm.getDataSource());
ArrayList definitions = sefdao.findAllByStudy(study);
String action = request.getParameter("action");
if (StringUtil.isBlank(idString)) {
addPageMessage(respage.getString("please_choose_a_site_to_remove"));
forwardPage(Page.SITE_LIST_SERVLET);
} else {
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute("siteToRemove", study);
request.setAttribute("userRolesToRemove", userRoles);
request.setAttribute("subjectsToRemove", subjects);
forwardPage(Page.REMOVE_SITE);
} else {
logger.info("submit to remove the site");
// change all statuses to unavailable
StudyDAO studao = new StudyDAO(sm.getDataSource());
study.setOldStatus(study.getStatus());
study.setStatus(Status.DELETED);
study.setUpdater(ub);
study.setUpdatedDate(new Date());
studao.update(study);
// remove all users and roles
for (int i = 0; i < userRoles.size(); i++) {
StudyUserRoleBean role = (StudyUserRoleBean) userRoles.get(i);
if (!role.getStatus().equals(Status.DELETED)) {
role.setStatus(Status.AUTO_DELETED);
role.setUpdater(ub);
role.setUpdatedDate(new Date());
// YW << So study_user_role table status_id field can be
// updated
udao.updateStudyUserRole(role, role.getUserName());
}
// YW 06-18-2007 >>
}
// YW << bug fix that current active study has been deleted
if (study.getId() == currentStudy.getId()) {
currentStudy.setStatus(Status.DELETED);
// currentRole.setRole(Role.INVALID);
currentRole.setStatus(Status.DELETED);
}
// remove all subjects
for (int i = 0; i < subjects.size(); i++) {
StudySubjectBean subject = (StudySubjectBean) subjects.get(i);
}
// remove all study_group
StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
ArrayList groups = sgdao.findAllByStudy(study);
for (int i = 0; i < groups.size(); i++) {
StudyGroupBean group = (StudyGroupBean) groups.get(i);
if (!group.getStatus().equals(Status.DELETED)) {
group.setStatus(Status.AUTO_DELETED);
group.setUpdater(ub);
group.setUpdatedDate(new Date());
sgdao.update(group);
// all subject_group_map
ArrayList subjectGroupMaps = sgmdao.findAllByStudyGroupId(group.getId());
for (int j = 0; j < subjectGroupMaps.size(); j++) {
SubjectGroupMapBean sgMap = (SubjectGroupMapBean) subjectGroupMaps.get(j);
if (!sgMap.getStatus().equals(Status.DELETED)) {
sgMap.setStatus(Status.AUTO_DELETED);
sgMap.setUpdater(ub);
sgMap.setUpdatedDate(new Date());
sgmdao.update(sgMap);
}
}
}
}
// remove all events
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
for (int i = 0; i < subjects.size(); i++) {
StudySubjectBean subject = (StudySubjectBean) subjects.get(i);
if (!subject.getStatus().equals(Status.DELETED)) {
subject.setStatus(Status.AUTO_DELETED);
subject.setUpdater(ub);
subject.setUpdatedDate(new Date());
ssdao.update(subject);
ArrayList events = sedao.findAllByStudySubject(subject);
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);
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.setOldStatus(eventCRF.getStatus());
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.setOldStatus(item.getStatus());
item.setStatus(Status.AUTO_DELETED);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
}
}
}
}
// for subjects
DatasetDAO datadao = new DatasetDAO(sm.getDataSource());
ArrayList dataset = datadao.findAllByStudyId(study.getId());
for (int i = 0; i < dataset.size(); i++) {
DatasetBean data = (DatasetBean) dataset.get(i);
if (!data.getStatus().equals(Status.DELETED)) {
data.setStatus(Status.AUTO_DELETED);
data.setUpdater(ub);
data.setUpdatedDate(new Date());
datadao.update(data);
}
}
addPageMessage(respage.getString("this_site_has_been_removed_succesfully"));
String fromListSite = (String) session.getAttribute("fromListSite");
if (fromListSite != null && fromListSite.equals("yes") && currentRole.getRole().equals(Role.STUDYDIRECTOR)) {
session.removeAttribute("fromListSite");
forwardPage(Page.SITE_LIST_SERVLET);
} else {
session.removeAttribute("fromListSite");
if (currentRole.getRole().equals(Role.ADMIN)) {
forwardPage(Page.STUDY_LIST_SERVLET);
} else {
forwardPage(Page.SITE_LIST_SERVLET);
}
}
}
}
}
use of org.akaza.openclinica.dao.submit.EventCRFDAO in project OpenClinica by OpenClinica.
the class RemoveEventCRFServlet 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_remove"));
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);
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_is_removed_for_this_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.REMOVE_EVENT_CRF);
} else {
logger.info("submit to remove the event CRF from study");
eventCRF.setStatus(Status.DELETED);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
// remove all the item data
for (int a = 0; a < itemData.size(); a++) {
ItemDataBean item = (ItemDataBean) itemData.get(a);
if (!item.getStatus().equals(Status.DELETED)) {
item.setStatus(Status.AUTO_DELETED);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
DiscrepancyNoteDAO dnDao = new DiscrepancyNoteDAO(sm.getDataSource());
List dnNotesOfRemovedItem = dnDao.findExistingNotesForItemData(item.getId());
if (!dnNotesOfRemovedItem.isEmpty()) {
DiscrepancyNoteBean itemParentNote = null;
for (Object obj : dnNotesOfRemovedItem) {
if (((DiscrepancyNoteBean) obj).getParentDnId() == 0) {
itemParentNote = (DiscrepancyNoteBean) obj;
}
}
DiscrepancyNoteBean dnb = new DiscrepancyNoteBean();
if (itemParentNote != null) {
dnb.setParentDnId(itemParentNote.getId());
dnb.setDiscrepancyNoteTypeId(itemParentNote.getDiscrepancyNoteTypeId());
}
dnb.setResolutionStatusId(ResolutionStatus.CLOSED.getId());
dnb.setStudyId(currentStudy.getId());
dnb.setAssignedUserId(ub.getId());
dnb.setOwner(ub);
dnb.setEntityType(DiscrepancyNoteBean.ITEM_DATA);
dnb.setEntityId(item.getId());
dnb.setColumn("value");
dnb.setCreatedDate(new Date());
dnb.setDescription("The item has been removed, this Discrepancy Note has been Closed.");
dnDao.create(dnb);
dnDao.createMapping(dnb);
itemParentNote.setResolutionStatusId(ResolutionStatus.CLOSED.getId());
dnDao.update(itemParentNote);
}
}
}
String emailBody = respage.getString("the_event_CRF") + " " + cb.getName() + " " + respage.getString("has_been_removed_from_the_event") + event.getStudyEventDefinition().getName() + ". " + respage.getString("has_been_removed_from_the_event_cont");
addPageMessage(emailBody);
sendEmail(emailBody);
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
}
}
}
Aggregations