use of org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean in project OpenClinica by OpenClinica.
the class SignStudySubjectServlet method getDisplayStudyEventsForStudySubject.
public static ArrayList getDisplayStudyEventsForStudySubject(StudyBean study, StudySubjectBean studySub, DataSource ds, UserAccountBean ub, StudyUserRoleBean currentRole) {
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(ds);
StudyEventDAO sedao = new StudyEventDAO(ds);
EventCRFDAO ecdao = new EventCRFDAO(ds);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(ds);
StudySubjectDAO ssdao = new StudySubjectDAO(ds);
ArrayList events = sedao.findAllByStudySubject(studySub);
ArrayList displayEvents = new ArrayList();
for (int i = 0; i < events.size(); i++) {
StudyEventBean event = (StudyEventBean) events.get(i);
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(event.getStudyEventDefinitionId());
event.setStudyEventDefinition(sed);
// find all active crfs in the definition
ArrayList eventDefinitionCRFs = (ArrayList) edcdao.findAllActiveByEventDefinitionId(study, sed.getId());
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
// construct info needed on view study event page
DisplayStudyEventBean de = new DisplayStudyEventBean();
de.setStudyEvent(event);
de.setDisplayEventCRFs(getDisplayEventCRFs(study, ds, eventCRFs, ub, currentRole, event.getSubjectEventStatus()));
ArrayList al = getUncompletedCRFs(ds, eventDefinitionCRFs, eventCRFs, event.getSubjectEventStatus());
populateUncompletedCRFsWithCRFAndVersions(ds, al);
de.setUncompletedCRFs(al);
StudySubjectBean studySubject = (StudySubjectBean) ssdao.findByPK(event.getStudySubjectId());
de.setMaximumSampleOrdinal(sedao.getMaxSampleOrdinal(sed, studySubject));
displayEvents.add(de);
// event.setEventCRFs(createAllEventCRFs(eventCRFs,
// eventDefinitionCRFs));
}
return displayEvents;
}
use of org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean in project OpenClinica by OpenClinica.
the class SignStudySubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
String action = fp.getString("action");
// studySubjectId
int studySubId = fp.getInt("id", true);
String module = fp.getString(MODULE);
request.setAttribute(MODULE, module);
if (studySubId == 0) {
addPageMessage(respage.getString("please_choose_a_subject_to_view"));
forwardPage(Page.LIST_STUDY_SUBJECTS);
return;
}
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
if (!permitSign(studySub, sm.getDataSource())) {
addPageMessage(respage.getString("subject_event_cannot_signed"));
// forwardPage(Page.SUBMIT_DATA_SERVLET);
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
// >> changed tbh, 06/2009
return;
}
if (action.equalsIgnoreCase("confirm")) {
String username = request.getParameter("j_user");
String password = request.getParameter("j_pass");
SecurityManager securityManager = ((SecurityManager) SpringServletAccess.getApplicationContext(context).getBean("securityManager"));
// String encodedUserPass =
// org.akaza.openclinica.core.SecurityManager
// .getInstance().encrytPassword(password);
UserAccountBean ub = (UserAccountBean) session.getAttribute("userBean");
if (securityManager.verifyPassword(password, getUserDetails()) && ub.getName().equals(username)) {
if (signSubjectEvents(studySub, sm.getDataSource(), ub)) {
// Making the StudySubject signed as all the events have
// become signed.
studySub.setStatus(Status.SIGNED);
studySub.setUpdater(ub);
subdao.update(studySub);
addPageMessage(respage.getString("subject_event_signed"));
// forwardPage(Page.SUBMIT_DATA_SERVLET);
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
// >> changed tbh, 06/2009
return;
} else {
addPageMessage(respage.getString("errors_in_submission_see_below"));
forwardPage(Page.LIST_STUDY_SUBJECTS);
return;
}
} else {
request.setAttribute("id", new Integer(studySubId).toString());
addPageMessage(restext.getString("password_match"));
forwardPage(Page.LIST_STUDY_SUBJECTS);
return;
}
}
request.setAttribute("studySub", studySub);
int studyId = studySub.getStudyId();
int subjectId = studySub.getSubjectId();
SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId);
if (currentStudy.getStudyParameterConfig().getCollectDob().equals("2")) {
Date dob = subject.getDateOfBirth();
if (dob != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(dob);
int year = cal.get(Calendar.YEAR);
request.setAttribute("yearOfBirth", new Integer(year));
} else {
request.setAttribute("yearOfBirth", "");
}
}
request.setAttribute("subject", subject);
StudyDAO studydao = new StudyDAO(sm.getDataSource());
StudyBean study = (StudyBean) studydao.findByPK(studyId);
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
study.getStudyParameterConfig().setCollectDob(spvdao.findByHandleAndStudy(studyId, "collectDob").getValue());
if (study.getParentStudyId() > 0) {
// this is a site,find parent
StudyBean parentStudy = (StudyBean) studydao.findByPK(study.getParentStudyId());
request.setAttribute("parentStudy", parentStudy);
} else {
request.setAttribute("parentStudy", new StudyBean());
}
ArrayList children = (ArrayList) sdao.findAllChildrenByPK(subjectId);
request.setAttribute("children", children);
// find study events
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
// find all eventcrfs for each event
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ArrayList<DisplayStudyEventBean> displayEvents = getDisplayStudyEventsForStudySubject(study, studySub, sm.getDataSource(), ub, currentRole);
DiscrepancyNoteUtil discNoteUtil = new DiscrepancyNoteUtil();
// Don't filter for now; disc note beans are returned with eventCRFId
// set
discNoteUtil.injectParentDiscNotesIntoDisplayStudyEvents(displayEvents, new HashSet(), sm.getDataSource(), 0);
// All the displaystudyevents for one subject
request.setAttribute("displayStudyEvents", displayEvents);
// Set up a Map for the JSP view, mapping the eventCRFId to another Map:
// the
// inner Map maps the resolution status name to the number of notes for
// that
// eventCRF id, as in New --> 2
Map discNoteByEventCRFid = discNoteUtil.createDiscNoteMapByEventCRF(displayEvents);
request.setAttribute("discNoteByEventCRFid", discNoteByEventCRFid);
EntityBeanTable table = fp.getEntityBeanTable();
// sort by start date,
table.setSortingIfNotExplicitlySet(1, false);
// desc
ArrayList allEventRows = DisplayStudyEventRow.generateRowsFromBeans(displayEvents);
String[] columns = { resword.getString("event") + " (" + resword.getString("occurrence_number") + ")", resword.getString("start_date1"), resword.getString("location"), resword.getString("status"), resword.getString("actions"), resword.getString("CRFs_atrib") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.hideColumnLink(4);
table.hideColumnLink(5);
if (!"removed".equalsIgnoreCase(studySub.getStatus().getName()) && !"auto-removed".equalsIgnoreCase(studySub.getStatus().getName())) {
table.addLink(resword.getString("add_new_event"), "CreateNewStudyEvent?" + CreateNewStudyEventServlet.INPUT_STUDY_SUBJECT_ID_FROM_VIEWSUBJECT + "=" + studySub.getId());
}
HashMap args = new HashMap();
args.put("id", new Integer(studySubId).toString());
table.setQuery("ViewStudySubject", args);
table.setRows(allEventRows);
table.computeDisplay();
request.setAttribute("table", table);
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
ArrayList groupMaps = (ArrayList) sgmdao.findAllByStudySubject(studySubId);
request.setAttribute("groups", groupMaps);
AuditEventDAO aedao = new AuditEventDAO(sm.getDataSource());
ArrayList logs = aedao.findEventStatusLogByStudySubject(studySubId);
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
ArrayList eventLogs = new ArrayList();
for (int i = 0; i < logs.size(); i++) {
AuditEventBean avb = (AuditEventBean) logs.get(i);
StudyEventAuditBean sea = new StudyEventAuditBean();
sea.setAuditEvent(avb);
StudyEventBean se = (StudyEventBean) sedao.findByPK(avb.getEntityId());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
sea.setDefinition(sed);
String old = avb.getOldValue().trim();
try {
if (!StringUtil.isBlank(old)) {
SubjectEventStatus oldStatus = SubjectEventStatus.get(new Integer(old).intValue());
sea.setOldSubjectEventStatus(oldStatus);
}
String newValue = avb.getNewValue().trim();
if (!StringUtil.isBlank(newValue)) {
SubjectEventStatus newStatus = SubjectEventStatus.get(new Integer(newValue).intValue());
sea.setNewSubjectEventStatus(newStatus);
}
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
// logger.warning("^^^ caught NFE");
}
UserAccountBean updater = (UserAccountBean) udao.findByPK(avb.getUserId());
sea.setUpdater(updater);
eventLogs.add(sea);
}
// logger.warning("^^^ finished iteration");
request.setAttribute("eventLogs", eventLogs);
forwardPage(Page.SIGN_STUDY_SUBJECT);
}
use of org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean in project OpenClinica by OpenClinica.
the class DiscrepancyNoteUtil method injectDiscNotesIntoDisplayStudyEvents.
/**
* This method is an overloaded version of the previous method, with the
* only difference being the resolutionStatusIds parameter in this method.
* This method adds the associated discrepancy notes to the appropriate
* StudyEventBean (contained by DisplayStudyBeans).
*
* @param displayStudyBeans
* A List of DisplayStudyEventBeans.
* @param resolutionStatusIds
* A HashSet object consisting of resolution status ids (i.e.,
* 1,2,3).
* @param dataSource
* A DataSource object, for use with the DAO methods.
* @param discNoteType
* An int discrepancy note type, for filtering the discrepancy
* notes that
* @param discrepancyNoteThreads
* A List of DiscrepancyNoteThreads
*/
public void injectDiscNotesIntoDisplayStudyEvents(List<DisplayStudyEventBean> displayStudyBeans, Set<Integer> resolutionStatusIds, DataSource dataSource, int discNoteType, List<DiscrepancyNoteThread> discrepancyNoteThreads) {
if (displayStudyBeans == null) {
return;
}
// booleans representing whether this method should only get
// DiscrepancyNoteBeans with
// certain resolution status or discrepancyNoteTypeId number.
boolean hasResolutionStatus = this.checkResolutionStatus(resolutionStatusIds);
boolean hasDiscNoteType = discNoteType >= 1 && discNoteType <= 4;
EventCRFDAO eventCRFDAO = new EventCRFDAO(dataSource);
DiscrepancyNoteDAO discrepancyNoteDAO = new DiscrepancyNoteDAO(dataSource);
StudyEventBean studyEventBean;
List<EventCRFBean> eventCRFBeans = new ArrayList<EventCRFBean>();
List<DiscrepancyNoteBean> foundDiscNotes = new ArrayList<DiscrepancyNoteBean>();
for (DisplayStudyEventBean dStudyEventBean : displayStudyBeans) {
studyEventBean = dStudyEventBean.getStudyEvent();
// All EventCRFs for a study event
eventCRFBeans = eventCRFDAO.findAllByStudyEvent(studyEventBean);
for (EventCRFBean eventCrfBean : eventCRFBeans) {
// Find ItemData type notes associated with an event crf
foundDiscNotes = discrepancyNoteDAO.findItemDataDNotesFromEventCRF(eventCrfBean);
// return only parent beans
foundDiscNotes = filterDiscNotesForOnlyParents(foundDiscNotes, discrepancyNoteThreads);
// update the resolution status of these parent discrepancy
// notes
updateStatusUsingThread(foundDiscNotes, discrepancyNoteThreads);
// filter for any specified disc note type
if (!foundDiscNotes.isEmpty() && hasDiscNoteType) {
// only include disc notes that have the specified disc note
// type id
foundDiscNotes = filterforDiscNoteType(foundDiscNotes, discNoteType);
}
if (!foundDiscNotes.isEmpty()) {
if (!hasResolutionStatus) {
studyEventBean.getDiscBeanList().addAll(foundDiscNotes);
} else {
// session variable
for (DiscrepancyNoteBean discBean : foundDiscNotes) {
for (int statusId : resolutionStatusIds) {
if (discBean.getResolutionStatusId() == statusId) {
studyEventBean.getDiscBeanList().add(discBean);
}
}
}
}
}
// 3014: Not for now; Find EventCRF type notes
/*
* foundDiscNotes =
* discrepancyNoteDAO.findEventCRFDNotesFromEventCRF(eventCrfBean);
* //filter for any specified disc note type if((!
* foundDiscNotes.isEmpty()) && hasDiscNoteType){ foundDiscNotes =
* filterforDiscNoteType(foundDiscNotes,discNoteType); }
*
* if(! foundDiscNotes.isEmpty()){ if(! hasResolutionStatus) {
* studyEventBean.getDiscBeanList().addAll(foundDiscNotes); }
* else { //Only include disc notes with a particular resolution
* status, specified by //the parameter passed to the servlet
* for(DiscrepancyNoteBean discBean : foundDiscNotes) { for(int
* statusId : resolutionStatusIds){
* if(discBean.getResolutionStatusId() == statusId){
* studyEventBean.getDiscBeanList().add(discBean); } } } } }
*/
// end if(! foundDiscNotes.isEmpty()){
}
// end for(EventCRFBean...
}
// end for (DisplayStudyEventBean
}
use of org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean in project OpenClinica by OpenClinica.
the class DiscrepancyNoteUtil method getDiscNoteCountFromDisplayEvents.
private Map<String, Integer> getDiscNoteCountFromDisplayEvents(List<DisplayStudyEventBean> disBeans, int eventCRFId) {
Map<String, Integer> discNoteMap = new HashMap<String, Integer>();
if (eventCRFId == 0 || disBeans == null) {
return discNoteMap;
}
List<DiscrepancyNoteBean> dnBeans;
for (DisplayStudyEventBean eventBean : disBeans) {
dnBeans = eventBean.getStudyEvent().getDiscBeanList();
for (String statusName : RESOLUTION_STATUS.keySet()) {
discNoteMap.put(statusName, getDiscNoteCountByStatusEventCRFId(dnBeans, RESOLUTION_STATUS.get(statusName), eventCRFId));
}
}
return discNoteMap;
}
use of org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean in project OpenClinica by OpenClinica.
the class DiscrepancyNoteUtil method getEventCRFIdsFromDisplayEvents.
private SortedSet<Integer> getEventCRFIdsFromDisplayEvents(List<DisplayStudyEventBean> displayEvents) {
SortedSet<Integer> treeSet = new TreeSet<Integer>();
if (displayEvents == null || displayEvents.isEmpty()) {
return treeSet;
}
StudyEventBean studyEventBean = null;
List<DisplayEventCRFBean> displayEventCRFBeans = null;
List<EventCRFBean> eventCRFBeans = null;
for (DisplayStudyEventBean displayStudyEventBean : displayEvents) {
displayEventCRFBeans = displayStudyEventBean.getDisplayEventCRFs();
if (displayEventCRFBeans.isEmpty()) {
eventCRFBeans = displayStudyEventBean.getStudyEvent().getEventCRFs();
for (EventCRFBean evBean : eventCRFBeans) {
treeSet.add(evBean.getId());
}
// move on to the next DisplayStudyEventBean
continue;
}
for (DisplayEventCRFBean disBean : displayEventCRFBeans) {
treeSet.add(disBean.getEventCRF().getId());
}
}
return treeSet;
}
Aggregations