use of org.akaza.openclinica.dao.managestudy.StudyEventDAO in project OpenClinica by OpenClinica.
the class RemoveStudyServlet method processRequest.
@Override
public void processRequest() throws Exception {
StudyDAO sdao = new StudyDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
int studyId = fp.getInt("id");
StudyBean study = (StudyBean) sdao.findByPK(studyId);
// find all sites
ArrayList sites = (ArrayList) sdao.findAllByParent(studyId);
// find all user and roles in the study, include ones in sites
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
ArrayList userRoles = udao.findAllByStudyId(studyId);
// find all subjects in the study, include ones in sites
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ArrayList subjects = ssdao.findAllByStudy(study);
// find all events in the study, include ones in sites
StudyEventDefinitionDAO sefdao = new StudyEventDefinitionDAO(sm.getDataSource());
ArrayList definitions = sefdao.findAllByStudy(study);
String action = request.getParameter("action");
if (studyId == 0) {
addPageMessage(respage.getString("please_choose_a_study_to_remove"));
forwardPage(Page.STUDY_LIST_SERVLET);
} else {
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute("studyToRemove", study);
request.setAttribute("sitesToRemove", sites);
request.setAttribute("userRolesToRemove", userRoles);
request.setAttribute("subjectsToRemove", subjects);
request.setAttribute("definitionsToRemove", definitions);
forwardPage(Page.REMOVE_STUDY);
} else {
logger.info("submit to remove the study");
// 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 sites
for (int i = 0; i < sites.size(); i++) {
StudyBean site = (StudyBean) sites.get(i);
if (!site.getStatus().equals(Status.DELETED)) {
site.setOldStatus(site.getStatus());
site.setStatus(Status.AUTO_DELETED);
site.setUpdater(ub);
site.setUpdatedDate(new Date());
sdao.update(site);
}
}
// remove all users and roles
for (int i = 0; i < userRoles.size(); i++) {
StudyUserRoleBean role = (StudyUserRoleBean) userRoles.get(i);
logger.info("remove user role" + role.getName());
if (!role.getStatus().equals(Status.DELETED)) {
role.setStatus(Status.AUTO_DELETED);
role.setUpdater(ub);
role.setUpdatedDate(new Date());
udao.updateStudyUserRole(role, role.getUserName());
}
}
// YW << bug fix for that current active study has been deleted
if (study.getId() == currentStudy.getId()) {
currentStudy.setStatus(Status.DELETED);
currentRole.setStatus(Status.DELETED);
} else // (auto-removed)
if (currentStudy.getParentStudyId() == study.getId()) {
currentStudy.setStatus(Status.AUTO_DELETED);
// we may need handle this later?
currentRole.setStatus(Status.DELETED);
}
// remove all subjects
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);
}
}
// remove all study_group_class
// changed by jxu on 08-31-06, to fix the problem of no study_id
// in study_group table
StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
// YW 09-27-2007, enable status updating for StudyGroupClassBean
ArrayList groups = sgcdao.findAllByStudy(study);
for (int i = 0; i < groups.size(); i++) {
StudyGroupClassBean group = (StudyGroupClassBean) groups.get(i);
if (!group.getStatus().equals(Status.DELETED)) {
group.setStatus(Status.AUTO_DELETED);
group.setUpdater(ub);
group.setUpdatedDate(new Date());
sgcdao.update(group);
// all subject_group_map
ArrayList subjectGroupMaps = sgmdao.findAllByStudyGroupClassId(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);
}
}
}
}
ArrayList groupClasses = sgcdao.findAllActiveByStudy(study);
for (int i = 0; i < groupClasses.size(); i++) {
StudyGroupClassBean gc = (StudyGroupClassBean) groupClasses.get(i);
if (!gc.getStatus().equals(Status.DELETED)) {
gc.setStatus(Status.AUTO_DELETED);
gc.setUpdater(ub);
gc.setUpdatedDate(new Date());
sgcdao.update(gc);
}
}
// remove all event definitions and event
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
for (int i = 0; i < definitions.size(); i++) {
StudyEventDefinitionBean definition = (StudyEventDefinitionBean) definitions.get(i);
if (!definition.getStatus().equals(Status.DELETED)) {
definition.setStatus(Status.AUTO_DELETED);
definition.setUpdater(ub);
definition.setUpdatedDate(new Date());
sefdao.update(definition);
ArrayList edcs = (ArrayList) edcdao.findAllByDefinition(definition.getId());
for (int j = 0; j < edcs.size(); j++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) edcs.get(j);
if (!edc.getStatus().equals(Status.DELETED)) {
edc.setStatus(Status.AUTO_DELETED);
edc.setUpdater(ub);
edc.setUpdatedDate(new Date());
edcdao.update(edc);
}
}
ArrayList events = (ArrayList) sedao.findAllByDefinition(definition.getId());
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 definitions
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(resexception.getString("this_study_has_been_removed_succesfully"));
forwardPage(Page.STUDY_LIST_SERVLET);
}
}
}
use of org.akaza.openclinica.dao.managestudy.StudyEventDAO in project OpenClinica by OpenClinica.
the class RemoveSubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
int subjectId = fp.getInt("id");
String action = fp.getString("action");
if (subjectId == 0 || StringUtil.isBlank(action)) {
addPageMessage(respage.getString("please_choose_a_subject_to_remove"));
forwardPage(Page.SUBJECT_LIST_SERVLET);
} else {
SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId);
// find all study subjects
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ArrayList studySubs = ssdao.findAllBySubjectId(subjectId);
// find study events
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
ArrayList events = sedao.findAllBySubjectId(subjectId);
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute("subjectToRemove", subject);
request.setAttribute("studySubs", studySubs);
request.setAttribute("events", events);
forwardPage(Page.REMOVE_SUBJECT);
} else {
logger.info("submit to remove the subject");
// change all statuses to deleted
subject.setStatus(Status.DELETED);
subject.setUpdater(ub);
subject.setUpdatedDate(new Date());
sdao.update(subject);
// remove subject references from study
for (int i = 0; i < studySubs.size(); i++) {
StudySubjectBean studySub = (StudySubjectBean) studySubs.get(i);
if (!studySub.getStatus().equals(Status.DELETED)) {
studySub.setStatus(Status.AUTO_DELETED);
studySub.setUpdater(ub);
studySub.setUpdatedDate(new Date());
ssdao.update(studySub);
}
}
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.setStatus(Status.AUTO_DELETED);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
// remove all the item data
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_subject") + " " + subject.getUniqueIdentifier() + " " + respage.getString("has_been_removed_succesfully");
addPageMessage(emailBody);
// sendEmail(emailBody);
forwardPage(Page.SUBJECT_LIST_SERVLET);
}
}
}
use of org.akaza.openclinica.dao.managestudy.StudyEventDAO in project OpenClinica by OpenClinica.
the class CreateDatasetServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
String action = fp.getString("action");
if (StringUtil.isBlank(action)) {
// step 1 -- instructions, and continue button
session.setAttribute("newDataset", new DatasetBean());
session.setAttribute("allItems", new ArrayList());
session.setAttribute("crf", new CRFBean());
session.setAttribute("allSelectedItems", new ArrayList());
forwardPage(Page.CREATE_DATASET_1);
} else {
StudyBean studyWithEventDefs = currentStudy;
if (currentStudy.getParentStudyId() > 0) {
studyWithEventDefs = new StudyBean();
studyWithEventDefs.setId(currentStudy.getParentStudyId());
}
if ("begin".equalsIgnoreCase(action)) {
// step 2 -- select study events/crfs
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
StudyBean studyWithEventDefinitions = currentStudy;
if (currentStudy.getParentStudyId() > 0) {
studyWithEventDefinitions = new StudyBean();
studyWithEventDefinitions.setId(currentStudy.getParentStudyId());
}
ArrayList seds = seddao.findAllActiveByStudy(studyWithEventDefinitions);
CRFDAO crfdao = new CRFDAO(sm.getDataSource());
HashMap events = new LinkedHashMap();
for (int i = 0; i < seds.size(); i++) {
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seds.get(i);
ArrayList<CRFBean> crfs = (ArrayList<CRFBean>) crfdao.findAllActiveByDefinition(sed);
if (currentStudy.getParentStudyId() > 0) {
// sift through these CRFs and see which ones are hidden
HideCRFManager hideCRFs = HideCRFManager.createHideCRFManager();
crfs = hideCRFs.removeHiddenCRFBeans(studyWithEventDefinitions, sed, crfs, sm.getDataSource());
}
if (!crfs.isEmpty()) {
events.put(sed, crfs);
}
}
// datasets
if (events.isEmpty()) {
addPageMessage(respage.getString("not_have_study_definitions_assigned"));
forwardPage(Page.CREATE_DATASET_1);
} else {
crfdao = new CRFDAO(sm.getDataSource());
ItemDAO idao = new ItemDAO(sm.getDataSource());
ArrayList sedItemIds = CreateDatasetServlet.allSedItemIdsInStudy(events, crfdao, idao);
session.setAttribute("numberOfStudyItems", Integer.toString(sedItemIds.size()));
request.setAttribute("eventlist", events);
session.setAttribute(EVENTS_FOR_CREATE_DATASET, events);
session.setAttribute("newDataset", new DatasetBean());
session.setAttribute("allItems", new ArrayList());
session.setAttribute("crf", new CRFBean());
forwardPage(Page.CREATE_DATASET_2);
}
} else if ("beginsubmit".equalsIgnoreCase(action)) {
String saveItems = fp.getString(SAVE_BUTTON);
String saveContinue = fp.getString(SAVE_CONTINUE_BUTTON);
DatasetBean db = (DatasetBean) session.getAttribute("newDataset");
if (db == null) {
db = new DatasetBean();
}
extractIdsFromForm(db);
extractEventIds(db);
session.setAttribute("newDataset", db);
// +"");
if (!StringUtil.isBlank(saveItems)) {
request.setAttribute("eventlist", session.getAttribute(EVENTS_FOR_CREATE_DATASET));
// BWP 3095>>
String summary = respage.getString("you_have_selected") + " " + db.getItemIds().size() + " " + respage.getString("items_so_far");
summary += genAttMsg(db);
addPageMessage(summary);
int crfId = fp.getInt("crfId");
if (crfId > 0) {
// user choose a crf and select items
forwardPage(Page.CREATE_DATASET_2);
} else {
ArrayList sgclasses = (ArrayList) session.getAttribute("allSelectedGroups");
if (sgclasses == null || sgclasses.size() == 0) {
sgclasses = setUpStudyGroups();
}
session.setAttribute("allSelectedGroups", sgclasses);
request.setAttribute("allSelectedGroups", sgclasses);
// TODO push out list of subject groups here???
// form submitted from "view selected item ' or
// attribute page, so
// forward back to "view selected item " page
forwardPage(Page.CREATE_DATASET_VIEW_SELECTED);
}
} else {
if (db.getItemIds().size() == 0) {
request.setAttribute("eventlist", session.getAttribute(EVENTS_FOR_CREATE_DATASET));
addPageMessage(respage.getString("should_select_one_item_to_create_dataset"));
forwardPage(Page.CREATE_DATASET_2);
} else {
String summary = respage.getString("you_have_selected") + " " + db.getItemIds().size() + " " + respage.getString("items_totally_for_this_dataset");
summary += genAttMsg(db);
addPageMessage(summary);
// 0 means using
fp.addPresetValue("firstmonth", 0);
// default month
fp.addPresetValue("firstyear", 1900);
fp.addPresetValue("lastmonth", 0);
fp.addPresetValue("lastyear", 2100);
setPresetValues(fp.getPresetValues());
logger.warn("found preset values while setting date: " + fp.getPresetValues().toString());
request.setAttribute(BEAN_MONTHS, getMonths());
request.setAttribute(BEAN_YEARS, getYears());
forwardPage(Page.CREATE_DATASET_3);
}
}
} else if ("scopesubmit".equalsIgnoreCase(action)) {
ArrayList months = getMonths();
ArrayList years = getYears();
int firstMonth = fp.getInt("firstmonth");
int firstYear = fp.getInt("firstyear");
int lastMonth = fp.getInt("lastmonth");
int lastYear = fp.getInt("lastyear");
if (fp.getInt("firstmonth") == 0) {
// default value
firstMonth = 1;
}
if (fp.getInt("lastmonth") == 0) {
// default value
lastMonth = 12;
}
errors = new HashMap();
if (fp.getInt("firstmonth") > 0 && firstYear == 1900) {
Validator.addError(errors, "firstmonth", restext.getString("if_specify_month_also_specify_year"));
}
if (fp.getInt("lastmonth") > 0 && lastYear == 2100) {
Validator.addError(errors, "lastmonth", restext.getString("if_specify_month_also_specify_year"));
}
Date dateStart = getFirstDayOfMonth(firstYear, firstMonth);
Date dateEnd = getLastDayOfMonth(lastYear, lastMonth);
if (dateEnd.compareTo(dateStart) < 0) {
Validator.addError(errors, "firstmonth", restext.getString("the_from_should_be_come_before_to"));
}
if (!errors.isEmpty()) {
String[] fieldNames = { "firstmonth", "firstyear", "lastmonth", "lastyear" };
fp.setCurrentIntValuesAsPreset(fieldNames);
setInputMessages(errors);
addPageMessage(respage.getString("errors_in_submission_see_below"));
setPresetValues(fp.getPresetValues());
request.setAttribute(BEAN_MONTHS, getMonths());
request.setAttribute(BEAN_YEARS, getYears());
forwardPage(Page.CREATE_DATASET_3);
} else {
DatasetBean dsb = (DatasetBean) session.getAttribute("newDataset");
dsb.setDateStart(dateStart);
dsb.setDateEnd(dateEnd);
session.setAttribute("newDataset", dsb);
if (fp.getString("submit").equals(resword.getString("continue_to_apply_filter"))) {
// FilterDAO fdao = new FilterDAO(sm.getDataSource());
// Collection filters = fdao.findAll();
// TODO make findAllByProject
// request.setAttribute("filters",filters);
EntityBeanTable table = getFilterTable();
session.setAttribute("partOfCreateDataset", new Integer(1));
// to be used in createFiltersThree servlet, tbh
request.setAttribute("table", table);
forwardPage(Page.APPLY_FILTER);
} else {
request.setAttribute("statuses", Status.toActiveArrayList());
// YW, 2-20-2008 <<these attributes will show on the
// CREATE_DATASET_4
String temp = dsb.getODMMetaDataVersionOid();
request.setAttribute("mdvOID", temp != null && temp.length() > 0 ? temp : "v1.0.0");
temp = dsb.getODMMetaDataVersionName();
request.setAttribute("mdvName", temp != null && temp.length() > 0 ? temp : "MetaDataVersion_v1.0.0");
request.setAttribute("mdvPrevStudy", dsb.getODMPriorStudyOid());
request.setAttribute("mdvPrevOID", dsb.getODMPriorMetaDataVersionOid());
// YW >>
forwardPage(Page.CREATE_DATASET_4);
}
}
} else if ("specifysubmit".equalsIgnoreCase(action)) {
Validator v = new Validator(request);
v.addValidation("dsName", Validator.NO_BLANKS);
v.addValidation("dsName", Validator.NO_SEMI_COLONS_OR_COLONS);
v.addValidation("dsDesc", Validator.NO_BLANKS);
v.addValidation("dsStatus", Validator.IS_VALID_TERM, TermType.STATUS);
v.addValidation("dsName", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
v.addValidation("dsDesc", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 2000);
String mdvOID = fp.getString("mdvOID");
String mdvName = fp.getString("mdvName");
String mdvPrevStudy = fp.getString("mdvPrevStudy");
if (mdvPrevStudy != null && mdvPrevStudy.length() > 0) {
v.addValidation("mdvPrevOID", Validator.NO_BLANKS);
}
String mdvPrevOID = fp.getString("mdvPrevOID");
errors = v.validate();
String dsName = fp.getString("dsName");
if (!StringUtil.isBlank(dsName)) {
// YW, << 3-19-2008
if (dsName.contains("/") || dsName.contains("\\")) {
v.addError(errors, "dsName", restext.getString("slash_not_allowed"));
}
// 2-20-2008, no check for editing dataset
if (((DatasetBean) session.getAttribute("newDataset")).getId() <= 0) {
// YW >>
// logger.info("dsName" + fp.getString("dsName"));
DatasetDAO dsdao = new DatasetDAO(sm.getDataSource());
DatasetBean dsBean = (DatasetBean) dsdao.findByNameAndStudy(fp.getString("dsName").trim(), currentStudy);
if (dsBean.getId() > 0) {
Validator.addError(errors, "dsName", restext.getString("dataset_name_used_by_another_choose_unique"));
}
}
}
if (!errors.isEmpty()) {
String[] fieldNames = { "dsName", "dsDesc" };
fp.setCurrentStringValuesAsPreset(fieldNames);
fp.addPresetValue("dsStatusId", fp.getInt("dsStatus"));
fp.addPresetValue("mdvOID", mdvOID);
fp.addPresetValue("mdvName", mdvName);
fp.addPresetValue("mdvPrevStudy", mdvPrevStudy);
fp.addPresetValue("mdvPrevOID", mdvPrevOID);
addPageMessage(respage.getString("errors_in_submission_see_below"));
setInputMessages(errors);
setPresetValues(fp.getPresetValues());
request.setAttribute("statuses", Status.toActiveArrayList());
forwardPage(Page.CREATE_DATASET_4);
} else {
session.setAttribute("mdvOID", mdvOID);
session.setAttribute("mdvName", mdvName);
session.setAttribute("mdvPrevStudy", mdvPrevStudy);
session.setAttribute("mdvPrevOID", mdvPrevOID);
if (mdvPrevOID != null && mdvPrevOID.length() > 0 && (mdvPrevStudy == null || mdvPrevStudy.length() <= 0)) {
mdvPrevStudy = currentStudy.getId() + "";
}
DatasetBean dsb = (DatasetBean) session.getAttribute("newDataset");
dsb.setSQLStatement(dsb.generateQuery());
String dbName = SQLInitServlet.getField("dataBase");
if ("oracle".equals(dbName)) {
dsb.setSQLStatement(dsb.generateOracleQuery());
}
// TODO set up oracle syntax for the query, grab the
// database
// from the session manager and feed it to the dataset bean
// possibly done, tbh 1/4/2005
// TODO look for the filter here, re-create the sql
// statement
// and put it in here
// possibly done need to test, tbh 1/7/2005
FilterBean fb = (FilterBean) session.getAttribute("newFilter");
if (fb != null) {
// FilterDAO fDAO = new FilterDAO(sm.getDataSource());
dsb.setSQLStatement(dsb.getSQLStatement() + " " + fb.getSQLStatement());
}
// dataset if dataset name has been changed.
if (dsb.getId() > 0 && !dsb.getName().equals(fp.getString("dsName"))) {
dsb.setId(0);
}
// YW >>
dsb.setODMMetaDataVersionName(mdvName);
dsb.setODMMetaDataVersionOid(mdvOID);
dsb.setODMPriorMetaDataVersionOid(mdvPrevOID);
dsb.setODMPriorStudyOid(mdvPrevStudy);
dsb.setName(fp.getString("dsName"));
dsb.setDescription(fp.getString("dsDesc"));
dsb.setStatus(Status.get(fp.getInt("dsStatus")));
dsb.setDatasetItemStatus(DatasetItemStatus.get(fp.getInt("itemStatus")));
session.removeAttribute("partOfCreateDataset");
Date ddate = new SimpleDateFormat("MM/dd/yyyy").parse("01/01/1900");
// done to remove the set up of going to get the filter, tbh
// set up dataset here, grab primary key???!!!???
// added by jxu
request.setAttribute("defaultStart", local_df.parse(local_df.format(ddate)));
request.setAttribute("defaultEnd", getLastDayOfMonth(2100, 12));
session.setAttribute("newDataset", dsb);
forwardPage(Page.CONFIRM_DATASET);
}
} else if ("confirmall".equalsIgnoreCase(action)) {
String submit = fp.getString("btnSubmit");
logger.info("reached confirm all");
if (!resword.getString("confirm_and_save").equalsIgnoreCase(submit)) {
// we're going back, so we should not destroy the
// data we've created, tbh
// session.removeAttribute("newDataset");
// session.removeAttribute("newFilter");
forwardPage(Page.CREATE_DATASET_4);
} else {
DatasetDAO ddao = new DatasetDAO(sm.getDataSource());
DatasetBean dsb = (DatasetBean) session.getAttribute("newDataset");
dsb.setStudyId(this.currentStudy.getId());
dsb.setOwner(ub);
// dsb.setOwnerId(ub.getId());
//
// at this point, dataset itemId will still be kept
// uniquely.
dsb = finalUpateDatasetBean(dsb);
if (dsb.getId() == 0) {
// if the bean hasn't been created already that is...
logger.info("*** about to create the dataset bean");
dsb = (DatasetBean) ddao.create(dsb);
logger.info("created dataset bean: " + dsb.getId() + ", name: " + dsb.getName());
if (!dsb.isActive()) {
addPageMessage(restext.getString("problem_creating_dataset_try_again"));
forwardPage(Page.EXTRACT_DATASETS_MAIN);
}
} else // YW, 2-20-2008 << for editing existing dataset
if (dsb.getId() > 0) {
dsb = (DatasetBean) ddao.updateAll(dsb);
if (!dsb.isActive()) {
addPageMessage(restext.getString("problem_creating_dataset_try_again"));
forwardPage(Page.EXTRACT_DATASETS_MAIN);
}
dsb = (DatasetBean) ddao.updateGroupMap(dsb);
if (!dsb.isActive()) {
addPageMessage(restext.getString("problem_updating_subject_group_class_when_updating_dataset"));
forwardPage(Page.EXTRACT_DATASETS_MAIN);
}
}
// YW >>
logger.info("setting data set id here");
// may be easier to just set the dataset bean
// back into the session?
request.setAttribute("dataset", dsb);
forwardPage(Page.EXPORT_DATASETS);
}
} else {
// refine this bit to catch errors, hopefully
addPageMessage(restext.getString("creating_new_dataset_cancelled"));
forwardPage(Page.CREATE_DATASET_1);
}
}
}
use of org.akaza.openclinica.dao.managestudy.StudyEventDAO 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.managestudy.StudyEventDAO in project OpenClinica by OpenClinica.
the class ListStudySubjectServlet method processRequest.
// >>
// < ResourceBundleresword;
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
locale = LocaleResolver.getLocale(request);
// < resword =
// ResourceBundle.getBundle("org.akaza.openclinica.i18n.words",locale);
// BWP 3098 << close the info side panel and show icons
request.setAttribute("closeInfoShowIcons", true);
// >>
// BWP 3195, 3330 : designed to address pagination issues
String pageNumber = fp.getString(SUBJECT_PAGE_NUMBER);
StringBuilder paginatingQuery = new StringBuilder("");
String filterKeyword = fp.getString(FILTER_KEYWORD);
String tmpSearch = fp.getString(SEARCH_SUBMITTED);
boolean searchSubmitted = !(tmpSearch == null || "".equalsIgnoreCase(tmpSearch)) && !"".equalsIgnoreCase(filterKeyword) && !"+".equalsIgnoreCase(filterKeyword);
if (pageNumber != null && !"".equalsIgnoreCase(pageNumber)) {
int tempNum = 0;
try {
tempNum = Integer.parseInt(pageNumber);
} catch (NumberFormatException nfe) {
// tempNum is already initialized to 0
}
if (tempNum > 0) {
paginatingQuery = new StringBuilder(SUBJECT_PAGE_NUMBER).append("=").append(pageNumber);
paginatingQuery.append("&ebl_paginated=1");
}
}
// URL encode the search keyword, since it will be a parameter in the
// URL
String filterKeywordURLEncode = java.net.URLEncoder.encode(filterKeyword, "UTF-8");
if (searchSubmitted) {
paginatingQuery.append("&ebl_sortColumnInd=0&submitted=1&ebl_sortAscending=1&ebl_filtered=1");
paginatingQuery.append("&").append(FILTER_KEYWORD).append("=").append(filterKeywordURLEncode);
}
request.setAttribute(PAGINATING_QUERY, paginatingQuery.toString());
StudyDAO stdao = new StudyDAO(sm.getDataSource());
StudySubjectDAO sdao = new StudySubjectDAO(sm.getDataSource());
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
// YW << update study parameters of current study.
// "collectDob" and "genderRequired" are set as the same as the parent
// study
// tbh, also add the params "subjectPersonIdRequired",
// "subjectIdGeneration", "subjectIdPrefixSuffix"
int parentStudyId = currentStudy.getParentStudyId();
ArrayList studyGroupClasses = new ArrayList();
ArrayList allDefs = new ArrayList();
// tbh
if (parentStudyId > 0) {
StudyBean parentStudy = (StudyBean) stdao.findByPK(parentStudyId);
studyGroupClasses = sgcdao.findAllActiveByStudy(parentStudy);
allDefs = seddao.findAllActiveByStudy(parentStudy);
} else {
parentStudyId = currentStudy.getId();
studyGroupClasses = sgcdao.findAllActiveByStudy(currentStudy);
allDefs = seddao.findAllActiveByStudy(currentStudy);
}
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
StudyParameterValueBean parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "collectDob");
currentStudy.getStudyParameterConfig().setCollectDob(parentSPV.getValue());
parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "genderRequired");
currentStudy.getStudyParameterConfig().setGenderRequired(parentSPV.getValue());
parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "subjectPersonIdRequired");
currentStudy.getStudyParameterConfig().setSubjectPersonIdRequired(parentSPV.getValue());
parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "subjectIdGeneration");
currentStudy.getStudyParameterConfig().setSubjectIdGeneration(parentSPV.getValue());
parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "subjectIdPrefixSuffix");
currentStudy.getStudyParameterConfig().setSubjectIdPrefixSuffix(parentSPV.getValue());
// for all the study groups for each group class
for (int i = 0; i < studyGroupClasses.size(); i++) {
StudyGroupClassBean sgc = (StudyGroupClassBean) studyGroupClasses.get(i);
ArrayList groups = sgdao.findAllByGroupClass(sgc);
sgc.setStudyGroups(groups);
}
request.setAttribute("studyGroupClasses", studyGroupClasses);
// information for the event tabs
session.setAttribute("allDefsArray", allDefs);
session.setAttribute("allDefsNumber", new Integer(allDefs.size()));
session.setAttribute("groupSize", new Integer(studyGroupClasses.size()));
// find all the subjects in current study
ArrayList subjects = sdao.findAllByStudyId(currentStudy.getId());
ArrayList<DisplayStudySubjectBean> displayStudySubs = new ArrayList<DisplayStudySubjectBean>();
// BEGIN LOOPING THROUGH SUBJECTS
for (int i = 0; i < subjects.size(); i++) {
StudySubjectBean studySub = (StudySubjectBean) subjects.get(i);
ArrayList groups = (ArrayList) sgmdao.findAllByStudySubject(studySub.getId());
ArrayList subGClasses = new ArrayList();
for (int j = 0; j < studyGroupClasses.size(); j++) {
StudyGroupClassBean sgc = (StudyGroupClassBean) studyGroupClasses.get(j);
boolean hasClass = false;
for (int k = 0; k < groups.size(); k++) {
SubjectGroupMapBean sgmb = (SubjectGroupMapBean) groups.get(k);
if (sgmb.getGroupClassName().equalsIgnoreCase(sgc.getName())) {
subGClasses.add(sgmb);
hasClass = true;
break;
}
}
if (!hasClass) {
subGClasses.add(new SubjectGroupMapBean());
}
}
ArrayList subEvents = new ArrayList();
// find all events order by definition ordinal
ArrayList events = sedao.findAllByStudySubject(studySub);
for (int j = 0; j < allDefs.size(); j++) {
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) allDefs.get(j);
boolean hasDef = false;
// logger.info("...set blank to "+blankid);
for (int k = 0; k < events.size(); k++) {
StudyEventBean se = (StudyEventBean) events.get(k);
if (se.getStudyEventDefinitionId() == sed.getId()) {
se.setStudyEventDefinition(sed);
// logger.info(">>>found assigned id "+sed.getId()+" sed
// name: "+sed.getName()+" "+se.getId());
subEvents.add(se);
hasDef = true;
}
}
if (!hasDef) {
StudyEventBean blank = new StudyEventBean();
blank.setSubjectEventStatus(SubjectEventStatus.NOT_SCHEDULED);
blank.setStudyEventDefinitionId(sed.getId());
// how can we set the following:
// logger.info("...resetting blank id: "+blank.getId()+" to
// "+blankid);
// blank.setId(blankid);
blank.setStudyEventDefinition(sed);
// logger.info(">>>blank id: "+blank.getId());
// logger.info(">>>found unassigned id "+sed.getId()+" sed
// name: "+sed.getName()+" ");
subEvents.add(blank);
}
}
// logger.info("subevents size after all adds: "+subEvents.size());
// reorganize the events and find the repeating ones
// subEvents:[aa bbb cc d ee]
// finalEvents:[a(2) b(3) c(2) d e(2)]
int prevDefId = 0;
int currDefId = 0;
ArrayList finalEvents = new ArrayList();
int repeatingNum = 1;
int count = 0;
StudyEventBean event = new StudyEventBean();
// begin looping through subject events
for (int j = 0; j < subEvents.size(); j++) {
StudyEventBean se = (StudyEventBean) subEvents.get(j);
currDefId = se.getStudyEventDefinitionId();
if (currDefId != prevDefId) {
// find a new event
if (repeatingNum > 1) {
event.setRepeatingNum(repeatingNum);
repeatingNum = 1;
}
// add current event to final
finalEvents.add(se);
event = se;
count++;
// logger.info("event id? "+event.getId());
} else {
// repeating event
repeatingNum++;
event.getRepeatEvents().add(se);
// event.getRepeatEvents().size());
if (j == subEvents.size() - 1) {
event.setRepeatingNum(repeatingNum);
repeatingNum = 1;
}
}
prevDefId = currDefId;
}
// end looping through subject events
DisplayStudySubjectBean dssb = new DisplayStudySubjectBean();
// logger.info("final events size: "+finalEvents.size());
dssb.setStudyEvents(finalEvents);
dssb.setStudySubject(studySub);
dssb.setStudyGroups(subGClasses);
displayStudySubs.add(dssb);
}
// END LOOPING THROUGH SUBJECTS
// Set a subject property to determine whether to show a signed-type
// icon (electronic signature)
// in the JSP view or not
// Get all event crfs by studyevent id; then use
// EventDefinitionCRFDAO.isRequired to
// determine whether any uncompleted CRFs are required.
boolean isRequiredUncomplete = false;
for (DisplayStudySubjectBean subject : displayStudySubs) {
for (Iterator it = subject.getStudyEvents().iterator(); it.hasNext(); ) {
StudyEventBean event = (StudyEventBean) it.next();
if (event.getSubjectEventStatus() != null && event.getSubjectEventStatus().getId() == 3) {
// disallow the subject from signing any studies
subject.setStudySignable(false);
break;
} else {
// determine whether the subject has any required,
// uncompleted event CRFs
isRequiredUncomplete = eventHasRequiredUncompleteCRFs(event);
if (isRequiredUncomplete) {
subject.setStudySignable(false);
break;
}
}
}
}
fp = new FormProcessor(request);
EntityBeanTable table = fp.getEntityBeanTable();
ArrayList allStudyRows = DisplayStudySubjectRow.generateRowsFromBeans(displayStudySubs);
ArrayList columnArray = new ArrayList();
columnArray.add(resword.getString("study_subject_ID"));
columnArray.add(resword.getString("subject_status"));
columnArray.add(resword.getString("OID"));
columnArray.add(resword.getString("gender"));
// new
columnArray.add(resword.getString("secondary_ID"));
for (int i = 0; i < studyGroupClasses.size(); i++) {
StudyGroupClassBean sgc = (StudyGroupClassBean) studyGroupClasses.get(i);
columnArray.add(sgc.getName());
}
for (int i = 0; i < allDefs.size(); i++) {
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) allDefs.get(i);
columnArray.add(sed.getName());
}
columnArray.add(resword.getString("actions"));
String[] columns = new String[columnArray.size()];
columnArray.toArray(columns);
// String[] columns = {"ID", "Subject Status", "Gender", "Enrollment
// Date",
// "Study Events", "Actions" };
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.setQuery(getBaseURL(), new HashMap());
table.hideColumnLink(columnArray.size() - 1);
// table.addLink("Enroll a new subject",
// "javascript:leftnavExpand('addSubjectRowExpress');");
table.setRows(allStudyRows);
if (filterKeyword != null && !"".equalsIgnoreCase(filterKeyword)) {
table.setKeywordFilter(filterKeyword);
}
table.computeDisplay();
request.setAttribute("table", table);
// request.setAttribute("subjects", subjects);
String idSetting = currentStudy.getStudyParameterConfig().getSubjectIdGeneration();
// set up auto study subject id
if (idSetting.equals("auto editable") || idSetting.equals("auto non-editable")) {
//Shaoyu Su
//int nextLabel = ssdao.findTheGreatestLabel() + 1;
//request.setAttribute("label", new Integer(nextLabel).toString());
request.setAttribute("label", resword.getString("id_generated_Save_Add"));
}
FormDiscrepancyNotes discNotes = new FormDiscrepancyNotes();
session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes);
forwardPage(getJSP());
}
Aggregations