use of org.akaza.openclinica.dao.managestudy.StudyGroupDAO 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());
}
use of org.akaza.openclinica.dao.managestudy.StudyGroupDAO in project OpenClinica by OpenClinica.
the class ListSubjectGroupClassServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
// YW <<
StudyDAO stdao = new StudyDAO(sm.getDataSource());
int parentStudyId = currentStudy.getParentStudyId();
ArrayList groups = new ArrayList();
if (parentStudyId > 0) {
StudyBean parentStudy = (StudyBean) stdao.findByPK(parentStudyId);
groups = sgcdao.findAllByStudy(parentStudy);
} else {
groups = sgcdao.findAllByStudy(currentStudy);
}
// YW >>
String isReadOnly = request.getParameter("read");
StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
for (int i = 0; i < groups.size(); i++) {
StudyGroupClassBean group = (StudyGroupClassBean) groups.get(i);
ArrayList studyGroups = sgdao.findAllByGroupClass(group);
group.setStudyGroups(studyGroups);
}
EntityBeanTable table = fp.getEntityBeanTable();
ArrayList allGroupRows = StudyGroupClassRow.generateRowsFromBeans(groups);
boolean isParentStudy = currentStudy.getParentStudyId() > 0 ? false : true;
request.setAttribute("isParentStudy", isParentStudy);
String[] columns = { resword.getString("subject_group_class"), resword.getString("type"), resword.getString("subject_assignment"), resword.getString("study_name"), resword.getString("subject_groups"), resword.getString("status"), resword.getString("actions") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.hideColumnLink(4);
table.hideColumnLink(6);
table.setQuery("ListSubjectGroupClass", new HashMap());
// if (isParentStudy && (!currentStudy.getStatus().isLocked())) {
// table.addLink(resword.getString("create_a_subject_group_class"),
// "CreateSubjectGroupClass");
// }
table.setRows(allGroupRows);
table.computeDisplay();
request.setAttribute("table", table);
if (request.getParameter("read") != null && request.getParameter("read").equals("true")) {
request.setAttribute("readOnly", true);
}
forwardPage(Page.SUBJECT_GROUP_CLASS_LIST);
}
use of org.akaza.openclinica.dao.managestudy.StudyGroupDAO in project OpenClinica by OpenClinica.
the class ViewSubjectGroupClassServlet method processRequest.
@Override
public void processRequest() throws Exception {
String action = request.getParameter("action");
FormProcessor fp = new FormProcessor(request);
int classId = fp.getInt("id");
if (classId == 0) {
addPageMessage(respage.getString("please_choose_a_subject_group_class_to_view"));
forwardPage(Page.SUBJECT_GROUP_CLASS_LIST_SERVLET);
} else {
StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
StudyDAO studyDao = new StudyDAO(sm.getDataSource());
StudyGroupClassBean sgcb = (StudyGroupClassBean) sgcdao.findByPK(classId);
StudyBean study = (StudyBean) studyDao.findByPK(sgcb.getStudyId());
checkRoleByUserAndStudy(ub, sgcb.getStudyId(), study.getParentStudyId());
// YW 09-19-2007 <<
sgcb.setGroupClassTypeName(GroupClassType.get(sgcb.getGroupClassTypeId()).getName());
// YW >>
ArrayList groups = sgdao.findAllByGroupClass(sgcb);
ArrayList studyGroups = new ArrayList();
for (int i = 0; i < groups.size(); i++) {
StudyGroupBean sg = (StudyGroupBean) groups.get(i);
ArrayList subjectMaps = sgmdao.findAllByStudyGroupClassAndGroup(sgcb.getId(), sg.getId());
sg.setSubjectMaps(subjectMaps);
// YW<<
studyGroups.add(sg);
// YW>>
}
request.setAttribute("group", sgcb);
// request.setAttribute("studyGroups", groups);
request.setAttribute("studyGroups", studyGroups);
forwardPage(Page.VIEW_SUBJECT_GROUP_CLASS);
}
}
use of org.akaza.openclinica.dao.managestudy.StudyGroupDAO in project OpenClinica by OpenClinica.
the class SubjectIdSDVFactory method getRow.
private SubjectAggregateContainer getRow(StudySubjectBean studySubjectBean) {
SubjectAggregateContainer row = new SubjectAggregateContainer();
EventCRFDAO eventCRFDAO = new EventCRFDAO(dataSource);
StudyDAO studyDAO = new StudyDAO(dataSource);
StudySubjectDAO studySubjectDAO = new StudySubjectDAO(dataSource);
StudyGroupDAO studyGroupDAO = new StudyGroupDAO(dataSource);
row.setStudySubjectId(studySubjectBean.getLabel());
row.setPersonId(studySubjectBean.getUniqueIdentifier());
row.setStudySubjectStatus(studySubjectBean.getStatus().getName());
int numberEventCRFs = eventCRFDAO.countEventCRFsByStudySubject(studySubjectBean.getId(), studySubjectBean.getStudyId(), studySubjectBean.getStudyId());
row.setTotalEventCRF(numberEventCRFs + "");
StudyBean studyBean = (StudyBean) studyDAO.findByPK(studySubjectBean.getStudyId());
row.setSiteId(studyBean.getIdentifier());
List<EventCRFBean> eventCRFBeans = eventCRFDAO.getEventCRFsByStudySubject(studySubjectBean.getId(), studySubjectBean.getStudyId(), studySubjectBean.getStudyId());
HashMap<String, Integer> stats = getEventCRFStats(eventCRFBeans, studySubjectBean);
// int numberCRFComplete = getNumberCompletedEventCRFs(eventCRFBeans);
// row.setNumberCRFComplete(numberCRFComplete + "");
row.setNumberCRFComplete(stats.get("numberOfCompletedEventCRFs") + "");
row.setNumberOfCRFsSDV(stats.get("numberOfSDVdEventCRFs") + "");
// row.setNumberOfCRFsSDV(getNumberSDVdEventCRFs(eventCRFBeans) + "");
// boolean studySubjectSDVd =
// eventCRFDAO.countEventCRFsByByStudySubjectCompleteOrLockedAndNotSDVd(studySubjectBean.getId()) == 0 &&
// numberCRFComplete > 0;
boolean studySubjectSDVd = stats.get("areEventCRFsSDVd") == -1 || stats.get("areEventCRFsSDVd") == 1 ? false : true;
StringBuilder sdvStatus = new StringBuilder("");
if (stats.get("shouldDisplaySDVButton") == 0) {
sdvStatus.append("");
} else if (studySubjectSDVd) {
sdvStatus.append("<center><a href='javascript:void(0)' onclick='prompt(document.sdvForm,");
sdvStatus.append(studySubjectBean.getId());
sdvStatus.append(")'>");
sdvStatus.append(getIconForCrfStatusPrefix()).append("DoubleCheck").append(ICON_FORCRFSTATUS_SUFFIX).append("</a></center>");
} else {
sdvStatus.append("<center><input style='margin-right: 5px' type='checkbox' ").append("class='sdvCheck'").append(" name='").append("sdvCheck_").append(studySubjectBean.getId()).append("' /></center>");
}
row.setSdvStatus(sdvStatus.toString());
List<StudyGroupBean> studyGroupBeans = studyGroupDAO.getGroupByStudySubject(studySubjectBean.getId(), studySubjectBean.getStudyId(), studySubjectBean.getStudyId());
if (studyGroupBeans != null && !studyGroupBeans.isEmpty()) {
row.setGroup(studyGroupBeans.get(0).getName());
}
StringBuilder actions = new StringBuilder("<table><tr><td>");
StringBuilder urlPrefix = new StringBuilder("<a href=\"");
StringBuilder path = new StringBuilder(contextPath).append("/pages/viewAllSubjectSDVtmp?studyId=").append(studyId).append("&sdv_f_studySubjectId=");
path.append(studySubjectBean.getLabel());
urlPrefix.append(path).append("\">");
actions.append(urlPrefix).append(SDVUtil.VIEW_ICON_HTML).append("</a></td>");
if (!studySubjectSDVd && stats.get("shouldDisplaySDVButton") == 1) {
StringBuilder jsCodeString = new StringBuilder("this.form.method='GET'; this.form.action='").append(contextPath).append("/pages/sdvStudySubject").append("';").append("this.form.theStudySubjectId.value='").append(studySubjectBean.getId()).append("';").append("this.form.submit();");
if (!studyBean.getStatus().isLocked()) {
actions.append("<td><input type=\"submit\" class=\"button\" value=\"SDV\" name=\"sdvSubmit\" ").append("onclick=\"").append(jsCodeString.toString()).append("\" /></td>");
}
} else if (!studySubjectSDVd) {
actions.append("<td> SDV N/A</td>");
}
actions.append("</tr></table>");
row.setActions(actions.toString());
return row;
}
use of org.akaza.openclinica.dao.managestudy.StudyGroupDAO 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);
}
}
}
Aggregations