use of org.akaza.openclinica.bean.submit.SubjectGroupMapBean in project OpenClinica by OpenClinica.
the class SubjectGroupMapDAO method findByPK.
public EntityBean findByPK(int ID) {
SubjectGroupMapBean eb = new SubjectGroupMapBean();
this.setTypesExpected();
HashMap variables = new HashMap();
variables.put(new Integer(1), new Integer(ID));
String sql = digester.getQuery("findByPK");
ArrayList alist = this.select(sql, variables);
Iterator it = alist.iterator();
if (it.hasNext()) {
eb = (SubjectGroupMapBean) this.getEntityFromHashMap((HashMap) it.next());
}
return eb;
}
use of org.akaza.openclinica.bean.submit.SubjectGroupMapBean in project OpenClinica by OpenClinica.
the class RestoreStudyServlet 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_restore"));
forwardPage(Page.STUDY_LIST_SERVLET);
} else {
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute("studyToRestore", study);
request.setAttribute("sitesToRestore", sites);
request.setAttribute("userRolesToRestore", userRoles);
request.setAttribute("subjectsToRestore", subjects);
request.setAttribute("definitionsToRRestore", definitions);
forwardPage(Page.RESTORE_STUDY);
} else {
logger.info("submit to restore the study");
// change all statuses to unavailable
StudyDAO studao = new StudyDAO(sm.getDataSource());
study.setStatus(study.getOldStatus());
study.setUpdater(ub);
study.setUpdatedDate(new Date());
studao.update(study);
// YW 09-27-2007 << restore auto-removed sites
for (int i = 0; i < sites.size(); i++) {
StudyBean site = (StudyBean) sites.get(i);
if (site.getStatus() == Status.AUTO_DELETED) {
site.setStatus(site.getOldStatus());
site.setUpdater(ub);
site.setUpdatedDate(new Date());
sdao.update(site);
}
}
// restore all users and roles
for (int i = 0; i < userRoles.size(); i++) {
StudyUserRoleBean role = (StudyUserRoleBean) userRoles.get(i);
if (role.getStatus().equals(Status.AUTO_DELETED)) {
role.setStatus(Status.AVAILABLE);
role.setUpdater(ub);
role.setUpdatedDate(new Date());
udao.updateStudyUserRole(role, role.getUserName());
}
}
// is current active study
if (study.getId() == currentStudy.getId()) {
currentStudy.setStatus(Status.AVAILABLE);
StudyUserRoleBean r = (new UserAccountDAO(sm.getDataSource())).findRoleByUserNameAndStudyId(ub.getName(), currentStudy.getId());
currentRole.setRole(r.getRole());
} else // active site will be restored as well if it was auto-removed
if (currentStudy.getParentStudyId() == study.getId() && currentStudy.getStatus() == Status.AUTO_DELETED) {
currentStudy.setStatus(Status.AVAILABLE);
StudyUserRoleBean r = (new UserAccountDAO(sm.getDataSource())).findRoleByUserNameAndStudyId(ub.getName(), currentStudy.getId());
StudyUserRoleBean rInParent = (new UserAccountDAO(sm.getDataSource())).findRoleByUserNameAndStudyId(ub.getName(), currentStudy.getParentStudyId());
// according to logic in SecureController.java: inherited
// role from parent study, pick the higher role
currentRole.setRole(Role.get(Role.max(r.getRole(), rInParent.getRole()).getId()));
}
// restore all subjects
for (int i = 0; i < subjects.size(); i++) {
StudySubjectBean subject = (StudySubjectBean) subjects.get(i);
if (subject.getStatus().equals(Status.AUTO_DELETED)) {
subject.setStatus(Status.AVAILABLE);
subject.setUpdater(ub);
subject.setUpdatedDate(new Date());
ssdao.update(subject);
}
}
// restore all study_group
StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
ArrayList groups = sgcdao.findAllByStudy(study);
for (int i = 0; i < groups.size(); i++) {
StudyGroupClassBean group = (StudyGroupClassBean) groups.get(i);
if (group.getStatus().equals(Status.AUTO_DELETED)) {
group.setStatus(Status.AVAILABLE);
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.AUTO_DELETED)) {
sgMap.setStatus(Status.AVAILABLE);
sgMap.setUpdater(ub);
sgMap.setUpdatedDate(new Date());
sgmdao.update(sgMap);
}
}
}
}
// restore 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.AUTO_DELETED)) {
definition.setStatus(Status.AVAILABLE);
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.AUTO_DELETED)) {
edc.setStatus(Status.AVAILABLE);
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.AUTO_DELETED)) {
event.setStatus(Status.AVAILABLE);
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.AUTO_DELETED)) {
eventCRF.setStatus(eventCRF.getOldStatus());
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.AUTO_DELETED)) {
item.setStatus(item.getOldStatus());
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.AUTO_DELETED)) {
data.setStatus(Status.AVAILABLE);
data.setUpdater(ub);
data.setUpdatedDate(new Date());
datadao.update(data);
}
}
addPageMessage(respage.getString("this_study_has_been_restored_succesfully"));
forwardPage(Page.STUDY_LIST_SERVLET);
}
}
}
use of org.akaza.openclinica.bean.submit.SubjectGroupMapBean in project OpenClinica by OpenClinica.
the class ListEventsForSubjectTableFactory method setDataAndLimitVariables.
@SuppressWarnings("unchecked")
@Override
public void setDataAndLimitVariables(TableFacade tableFacade) {
Limit limit = tableFacade.getLimit();
ListEventsForSubjectFilter eventsForSubjectFilter = getListEventsForSubjectFilter(limit);
// Used on Initial sort without filters
if (!limit.isComplete()) {
int totalRows = getStudySubjectDAO().getCountWithFilter(eventsForSubjectFilter, getStudyBean());
tableFacade.setTotalRows(totalRows);
}
// Preprocess the studysubjectbean list to find subjects with crf status
ListEventsForSubjectSort eventsForSubjectSort = getListEventsForSubjectSort(limit);
int rowStart = limit.getRowSelect().getRowStart();
int rowEnd = limit.getRowSelect().getRowEnd();
Collection<StudySubjectBean> items = getStudySubjectDAO().getWithFilterAndSort(getStudyBean(), eventsForSubjectFilter, eventsForSubjectSort, rowStart, rowEnd);
Collection<HashMap<Object, Object>> theItems = new ArrayList<HashMap<Object, Object>>();
for (StudySubjectBean studySubjectBean : items) {
HashMap<Object, Object> theItem = new HashMap<Object, Object>();
theItem.put("studySubject", studySubjectBean);
theItem.put("studySubject.label", studySubjectBean.getLabel());
theItem.put("studySubject.status", studySubjectBean.getStatus());
theItem.put("enrolledAt", ((StudyBean) getStudyDAO().findByPK(studySubjectBean.getStudyId())).getIdentifier());
SubjectBean subjectBean = (SubjectBean) getSubjectDAO().findByPK(studySubjectBean.getSubjectId());
theItem.put("subject", subjectBean);
theItem.put("subject.charGender", subjectBean.getGender());
// study group classes
SubjectGroupMapBean subjectGroupMapBean = new SubjectGroupMapBean();
for (StudyGroupClassBean studyGroupClass : getStudyGroupClasses()) {
subjectGroupMapBean = getSubjectGroupMapDAO().findAllByStudySubjectAndStudyGroupClass(studySubjectBean.getId(), studyGroupClass.getId());
if (null != subjectGroupMapBean) {
theItem.put("sgc_" + studyGroupClass.getId(), subjectGroupMapBean.getStudyGroupId());
theItem.put("grpName_sgc_" + studyGroupClass.getId(), subjectGroupMapBean.getStudyGroupName());
}
}
subjectGroupMapBean = null;
HashMap<String, EventCRFBean> crfAsKeyEventCrfAsValue = getEventsCrfsForStudySubject(studySubjectBean);
// Get the event Status
List<StudyEventBean> eventsForStudySubjectAndEventDefinitions = getStudyEventDAO().findAllByDefinitionAndSubject(selectedStudyEventDefinition, studySubjectBean);
List<DisplayBean> events = new ArrayList<DisplayBean>();
// study event size < 1
if (eventsForStudySubjectAndEventDefinitions.size() < 1) {
DisplayBean d = new DisplayBean();
d.getProps().put("event", null);
d.getProps().put("event.status", SubjectEventStatus.NOT_SCHEDULED);
d.getProps().put("studySubject.createdDate", null);
for (int i = 0; i < getCrfs(selectedStudyEventDefinition).size(); i++) {
CRFBean crf = getCrfs(selectedStudyEventDefinition).get(i);
d.getProps().put("crf_" + crf.getId(), DataEntryStage.UNCOMPLETED);
d.getProps().put("crf_" + crf.getId() + "_eventCrf", null);
d.getProps().put("crf_" + crf.getId() + "_crf", crf);
// d.getProps().put("crf_" + crf.getId() + "_eventDefinitionCrf", eventDefinitionCrfs.get(i));
d.getProps().put("crf_" + crf.getId() + "_eventDefinitionCrf", getEventDefinitionCRFBean(selectedStudyEventDefinition.getId(), crf, studySubjectBean));
theItem.put("crf_" + crf.getId(), "");
}
events.add(d);
}
// study event size >0
for (StudyEventBean studyEventBean : eventsForStudySubjectAndEventDefinitions) {
DisplayBean d = new DisplayBean();
d.getProps().put("event", studyEventBean);
d.getProps().put("event.status", studyEventBean.getSubjectEventStatus());
d.getProps().put("studySubject.createdDate", studyEventBean.getDateStarted());
for (int i = 0; i < getCrfs(selectedStudyEventDefinition).size(); i++) {
CRFBean crf = getCrfs(selectedStudyEventDefinition).get(i);
EventCRFBean eventCRFBean = crfAsKeyEventCrfAsValue.get(crf.getId() + "_" + studyEventBean.getId());
if (eventCRFBean != null) {
d.getProps().put("crf_" + crf.getId(), eventCRFBean.getStage());
d.getProps().put("crf_" + crf.getId() + "_eventCrf", eventCRFBean);
} else {
d.getProps().put("crf_" + crf.getId(), DataEntryStage.UNCOMPLETED);
d.getProps().put("crf_" + crf.getId() + "_eventCrf", null);
}
d.getProps().put("crf_" + crf.getId() + "_crf", crf);
// d.getProps().put("crf_" + crf.getId() + "_eventDefinitionCrf", eventDefinitionCrfs.get(i));
d.getProps().put("crf_" + crf.getId() + "_eventDefinitionCrf", getEventDefinitionCRFBean(selectedStudyEventDefinition.getId(), crf, studySubjectBean));
theItem.put("crf_" + crf.getId(), "");
}
events.add(d);
}
theItem.put("events", events);
theItem.put("event.status", "");
theItem.put("studySubject.createdDate", "");
theItem.put("webappContext", tableFacade.getWebContext().getContextPath());
theItems.add(theItem);
}
// Do not forget to set the items back on the tableFacade.
tableFacade.setItems(theItems);
}
use of org.akaza.openclinica.bean.submit.SubjectGroupMapBean in project OpenClinica by OpenClinica.
the class ListEventsForSubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
// checks which module the requests are from
String module = fp.getString(MODULE);
request.setAttribute(MODULE, module);
String pageNumber = fp.getString(ListStudySubjectServlet.SUBJECT_PAGE_NUMBER);
String filterKeyword = fp.getString(ListStudySubjectServlet.FILTER_KEYWORD);
String tmpSearch = fp.getString(ListStudySubjectServlet.SEARCH_SUBMITTED);
boolean searchSubmitted = !(tmpSearch == null || "".equalsIgnoreCase(tmpSearch)) && !"".equalsIgnoreCase(filterKeyword);
SubjectMatrixUtil matrixUtil = new SubjectMatrixUtil();
String query = matrixUtil.createPaginatingQuery(pageNumber);
StringBuilder extendedQuery = new StringBuilder(query);
// 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) {
extendedQuery.append("&ebl_sortColumnInd=0&submitted=1&ebl_sortAscending=1&ebl_filtered=1");
extendedQuery.append("&").append(ListStudySubjectServlet.FILTER_KEYWORD).append("=").append(filterKeywordURLEncode);
}
request.setAttribute(ListStudySubjectServlet.PAGINATING_QUERY, extendedQuery.toString());
int definitionId = fp.getInt("defId");
int tabId = fp.getInt("tab");
if (definitionId <= 0) {
addPageMessage(respage.getString("please_choose_an_ED_ta_to_vies_details"));
forwardPage(Page.LIST_STUDY_SUBJECTS);
return;
}
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(definitionId);
StudySubjectDAO sdao = new StudySubjectDAO(sm.getDataSource());
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
CRFDAO crfdao = new CRFDAO(sm.getDataSource());
// find all the groups in the current study
ArrayList studyGroupClasses = sgcdao.findAllActiveByStudy(currentStudy);
// information for the event tabs
ArrayList allDefs = seddao.findAllActiveByStudy(currentStudy);
boolean isASite = false;
if (currentStudy.getParentStudyId() > 0) {
StudyDAO stdao = new StudyDAO(sm.getDataSource());
StudyBean parent = (StudyBean) stdao.findByPK(currentStudy.getParentStudyId());
allDefs = seddao.findAllActiveByStudy(parent);
}
ArrayList eventDefinitionCRFs = (ArrayList) edcdao.findAllActiveByEventDefinitionId(this.currentStudy, definitionId);
for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
CRFBean crf = (CRFBean) crfdao.findByPK(edc.getCrfId());
edc.setCrf(crf);
}
request.setAttribute("studyGroupClasses", studyGroupClasses);
request.setAttribute("allDefsArray", allDefs);
request.setAttribute("allDefsNumber", new Integer(allDefs.size()));
request.setAttribute("groupSize", new Integer(studyGroupClasses.size()));
request.setAttribute("eventDefCRFSize", new Integer(eventDefinitionCRFs.size()));
request.setAttribute("tabId", new Integer(tabId));
request.setAttribute("studyEventDef", sed);
request.setAttribute("eventDefCRFs", eventDefinitionCRFs);
// find all the subjects in current study
ArrayList subjects = sdao.findAllByStudyId(currentStudy.getId());
ArrayList displayStudySubs = new ArrayList();
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());
}
}
// find all eventcrfs for each event, for each event tab
ArrayList displaySubjectEvents = new ArrayList();
ArrayList<DisplayStudyEventBean> displayEvents = new ArrayList<DisplayStudyEventBean>();
ArrayList events = sedao.findAllByStudySubjectAndDefinition(studySub, sed);
for (int k = 0; k < events.size(); k++) {
StudyEventBean seb = (StudyEventBean) events.get(k);
DisplayStudyEventBean dseb = ListStudySubjectServlet.getDisplayStudyEventsForStudySubject(studySub, seb, sm.getDataSource(), ub, currentRole, this.currentStudy);
// ArrayList eventCRFs = ecdao.findAllByStudyEvent(seb);
// ArrayList al =
// ViewStudySubjectServlet.getUncompletedCRFs(sm.getDataSource(),
// eventDefinitionCRFs, eventCRFs);
// dseb.getUncompletedCRFs().add(al);
displayEvents.add(dseb);
}
ArrayList al = new ArrayList();
for (int k = 0; k < displayEvents.size(); k++) {
DisplayStudyEventBean dseb = displayEvents.get(k);
ArrayList eventCRFs = dseb.getDisplayEventCRFs();
for (int a = 0; a < eventDefinitionCRFs.size(); a++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(a);
int crfId = edc.getCrfId();
boolean hasCRF = false;
for (int b = 0; b < eventCRFs.size(); b++) {
DisplayEventCRFBean decb = (DisplayEventCRFBean) eventCRFs.get(b);
// decb.getStage().getName() );
if (decb.getEventCRF().getCrf().getId() == crfId) {
dseb.getAllEventCRFs().add(decb);
// logger.info("hasCRf" + crfId +
// decb.getEventCRF().getCrf().getName());
hasCRF = true;
break;
}
}
if (hasCRF == false) {
DisplayEventCRFBean db = new DisplayEventCRFBean();
db.setEventDefinitionCRF(edc);
db.getEventDefinitionCRF().setCrf(edc.getCrf());
dseb.getAllEventCRFs().add(db);
// logger.info("noCRf" + crfId);
}
}
// Issue 3212 BWP <<
if (currentStudy.getParentStudyId() > 0) {
// check each eventDefCRFBean and set its isHidden property
// to true, if its
// persistent/database-derived hideCrf is true (domain rule:
// hide the CRF from users logged into a site)
HideCRFManager hideCRFManager = HideCRFManager.createHideCRFManager();
hideCRFManager.optionallyCheckHideCRFProperty(dseb);
// remove a DisplayEventCRFBean from a DisplayStudyEventBean
// in the list
// if it contains a hidden CRF in its event definition
hideCRFManager.removeHiddenEventCRF(dseb);
// generate a boolean request attribute indicating whether
// any of the CRFs
// should be hidden
boolean hideCRFs = hideCRFManager.studyEventHasAHideCRFProperty(dseb);
request.setAttribute("hideCRFs", hideCRFs);
}
// >>
}
DisplayStudySubjectBean dssb = new DisplayStudySubjectBean();
dssb.setStudySubject(studySub);
dssb.setStudyGroups(subGClasses);
dssb.setStudyEvents(displayEvents);
if (definitionId > 0) {
dssb.setSedId(definitionId);
} else {
dssb.setSedId(-1);
}
displayStudySubs.add(dssb);
}
EntityBeanTable table = fp.getEntityBeanTable();
ArrayList allStudyRows = DisplayStudySubjectEventsRow.generateRowsFromBeans(displayStudySubs);
ArrayList columnArray = new ArrayList();
columnArray.add(resword.getString("ID"));
columnArray.add(resword.getString("subject_status"));
columnArray.add(resword.getString("gender"));
for (int i = 0; i < studyGroupClasses.size(); i++) {
StudyGroupClassBean sgc = (StudyGroupClassBean) studyGroupClasses.get(i);
columnArray.add(sgc.getName());
}
// columnArray.add("Event Sequence");
columnArray.add(resword.getString("event_status"));
columnArray.add(resword.getString("event_date"));
// Issue 3212 BWP <<
HideCRFManager hideCRFMgr = HideCRFManager.createHideCRFManager();
hideCRFMgr.hideSpecifiedEventCRFDefBeans(eventDefinitionCRFs);
for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
// Issue 3212 BWP <<
if (!(currentStudy.getParentStudyId() > 0)) {
columnArray.add(edc.getCrf().getName());
} else {
if (!edc.isHideCrf()) {
columnArray.add(edc.getCrf().getName());
}
}
// >>
}
columnArray.add(resword.getString("actions"));
String[] columns = new String[columnArray.size()];
columnArray.toArray(columns);
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.setQuery("ListEventsForSubject?module=" + module + "&defId=" + definitionId + "&tab=" + tabId, new HashMap());
table.hideColumnLink(columnArray.size() - 1);
// if(currentStudy.getStatus().isAvailable()){
// table.addLink(resword.getString("add_new_subject"), "AddNewSubject");
// }
table.setRows(allStudyRows);
if (filterKeyword != null && !"".equalsIgnoreCase(filterKeyword)) {
table.setKeywordFilter(filterKeyword);
}
table.computeDisplay();
request.setAttribute("table", table);
forwardPage(Page.LIST_EVENTS_FOR_SUBJECT);
}
use of org.akaza.openclinica.bean.submit.SubjectGroupMapBean in project OpenClinica by OpenClinica.
the class UpdateStudySubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormDiscrepancyNotes discNotes = null;
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
String fromResolvingNotes = fp.getString("fromResolvingNotes", true);
if (StringUtil.isBlank(fromResolvingNotes)) {
session.removeAttribute(ViewNotesServlet.WIN_LOCATION);
session.removeAttribute(ViewNotesServlet.NOTES_TABLE);
checkStudyLocked(Page.LIST_STUDY_SUBJECTS_SERVLET, respage.getString("current_study_locked"));
checkStudyFrozen(Page.LIST_STUDY_SUBJECTS_SERVLET, respage.getString("current_study_frozen"));
}
// studySubjectId
int studySubId = fp.getInt("id", true);
if (studySubId == 0) {
addPageMessage(respage.getString("please_choose_study_subject_to_edit"));
forwardPage(Page.LIST_STUDY_SUBJECTS);
} else {
String action = fp.getString("action", true);
if (StringUtil.isBlank(action)) {
addPageMessage(respage.getString("no_action_specified"));
forwardPage(Page.LIST_STUDY_SUBJECTS);
return;
}
StudySubjectBean sub = (StudySubjectBean) subdao.findByPK(studySubId);
StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
ArrayList groupMaps = (ArrayList) sgmdao.findAllByStudySubject(studySubId);
HashMap gMaps = new HashMap();
for (int i = 0; i < groupMaps.size(); i++) {
SubjectGroupMapBean groupMap = (SubjectGroupMapBean) groupMaps.get(i);
gMaps.put(new Integer(groupMap.getStudyGroupClassId()), groupMap);
}
StudyDAO stdao = new StudyDAO(sm.getDataSource());
ArrayList classes = new ArrayList();
if (!"submit".equalsIgnoreCase(action)) {
// YW <<
int parentStudyId = currentStudy.getParentStudyId();
if (parentStudyId > 0) {
StudyBean parentStudy = (StudyBean) stdao.findByPK(parentStudyId);
classes = sgcdao.findAllActiveByStudy(parentStudy);
} else {
classes = sgcdao.findAllActiveByStudy(currentStudy);
}
// YW >>
for (int i = 0; i < classes.size(); i++) {
StudyGroupClassBean group = (StudyGroupClassBean) classes.get(i);
ArrayList studyGroups = sgdao.findAllByGroupClass(group);
group.setStudyGroups(studyGroups);
SubjectGroupMapBean gMap = (SubjectGroupMapBean) gMaps.get(new Integer(group.getId()));
if (gMap != null) {
group.setStudyGroupId(gMap.getStudyGroupId());
group.setGroupNotes(gMap.getNotes());
}
}
session.setAttribute("groups", classes);
}
if ("show".equalsIgnoreCase(action)) {
session.setAttribute("studySub", sub);
// below added tbh 092007
String enrollDateStr = sub.getEnrollmentDate() != null ? local_df.format(sub.getEnrollmentDate()) : "";
session.setAttribute("enrollDateStr", enrollDateStr);
// above added tbh 092007
discNotes = new FormDiscrepancyNotes();
session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes);
forwardPage(Page.UPDATE_STUDY_SUBJECT);
} else if ("confirm".equalsIgnoreCase(action)) {
confirm(sgdao);
} else if ("submit".equalsIgnoreCase(action)) {
// submit to DB
StudySubjectBean subject = (StudySubjectBean) session.getAttribute("studySub");
subject.setUpdater(ub);
subdao.update(subject);
// save discrepancy notes into DB
FormDiscrepancyNotes fdn = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
AddNewSubjectServlet.saveFieldNotes("enrollmentDate", fdn, dndao, subject.getId(), "studySub", currentStudy);
ArrayList groups = (ArrayList) session.getAttribute("groups");
if (!groups.isEmpty()) {
for (int i = 0; i < groups.size(); i++) {
StudyGroupClassBean sgc = (StudyGroupClassBean) groups.get(i);
/*We will be allowing users to remove a subject from all groups. Issue-4524*/
if (sgc.getStudyGroupId() == 0) {
Collection subjectGroups = sgmdao.findAllByStudySubject(subject.getId());
for (Iterator it = subjectGroups.iterator(); it.hasNext(); ) {
sgmdao.deleteTestGroupMap(((SubjectGroupMapBean) it.next()).getId());
}
} else {
SubjectGroupMapBean sgm = new SubjectGroupMapBean();
SubjectGroupMapBean gMap = (SubjectGroupMapBean) gMaps.get(new Integer(sgc.getId()));
sgm.setStudyGroupId(sgc.getStudyGroupId());
sgm.setNotes(sgc.getGroupNotes());
sgm.setStudyGroupClassId(sgc.getId());
sgm.setStudySubjectId(subject.getId());
sgm.setStatus(Status.AVAILABLE);
if (sgm.getStudyGroupId() > 0) {
if (gMap != null && gMap.getId() > 0) {
sgm.setUpdater(ub);
sgm.setId(gMap.getId());
sgmdao.update(sgm);
} else {
sgm.setOwner(ub);
sgmdao.create(sgm);
}
}
}
}
}
addPageMessage(respage.getString("study_subject_updated_succesfully"));
session.removeAttribute("studySub");
session.removeAttribute("groups");
session.removeAttribute("enrollDateStr");
session.removeAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
} else {
addPageMessage(respage.getString("no_action_specified"));
forwardPage(Page.LIST_STUDY_SUBJECTS);
return;
}
}
}
Aggregations