use of org.akaza.openclinica.dao.submit.EventCRFDAO in project OpenClinica by OpenClinica.
the class LockCRFVersionServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
int crfVersionId = fp.getInt("id", true);
String action = fp.getString("action");
// checks which module the requests are from
String module = fp.getString(MODULE);
request.setAttribute(MODULE, module);
if (crfVersionId == 0) {
addPageMessage(respage.getString("choose_valid_crf_version"));
forwardPage(Page.CRF_LIST_SERVLET);
return;
}
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFVersionBean version = (CRFVersionBean) cvdao.findByPK(crfVersionId);
//System.out.println("crf version found:" + version.getName());
CRFBean crf = (CRFBean) cdao.findByPK(version.getCrfId());
if (!ub.isSysAdmin() && (version.getOwnerId() != ub.getId())) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
forwardPage(Page.MENU_SERVLET);
return;
}
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ArrayList eventCRFs = ecdao.findAllStudySubjectByCRFVersion(crfVersionId);
if (StringUtil.isBlank(action)) {
request.setAttribute("crfVersionToLock", version);
request.setAttribute("crf", crf);
request.setAttribute("eventSubjectsUsingVersion", eventCRFs);
forwardPage(Page.CONFIRM_LOCKING_CRF_VERSION);
} else if ("confirm".equalsIgnoreCase(action)) {
version.setStatus(Status.LOCKED);
version.setUpdater(ub);
cvdao.update(version);
ArrayList versionList = (ArrayList) cvdao.findAllByCRF(version.getCrfId());
if (versionList.size() > 0) {
EventDefinitionCRFDAO edCRFDao = new EventDefinitionCRFDAO(sm.getDataSource());
ArrayList edcList = (ArrayList) edCRFDao.findAllByCRF(version.getCrfId());
for (int i = 0; i < edcList.size(); i++) {
EventDefinitionCRFBean edcBean = (EventDefinitionCRFBean) edcList.get(i);
// @pgawade 18-May-2011 #5414 - Changes for setting the correct
// default crf version Id to event
// when existing default version is locked
// RemoveCRFVersionServlet.updateEventDef(edcBean, edCRFDao,
// versionList);
RemoveCRFVersionServlet.updateEventDef(edcBean, edCRFDao, versionList, crfVersionId);
}
}
addPageMessage(respage.getString("crf_version_archived_successfully"));
forwardPage(Page.CRF_LIST_SERVLET);
}
}
use of org.akaza.openclinica.dao.submit.EventCRFDAO in project OpenClinica by OpenClinica.
the class RestoreSiteServlet method processRequest.
@Override
public void processRequest() throws Exception {
StudyDAO sdao = new StudyDAO(sm.getDataSource());
String idString = request.getParameter("id");
logger.info("site id:" + idString);
int siteId = Integer.valueOf(idString.trim()).intValue();
StudyBean study = (StudyBean) sdao.findByPK(siteId);
// find all user and roles
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
ArrayList userRoles = udao.findAllByStudyId(siteId);
// find all subjects
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ArrayList subjects = ssdao.findAllByStudy(study);
// find all events
StudyEventDefinitionDAO sefdao = new StudyEventDefinitionDAO(sm.getDataSource());
ArrayList definitions = sefdao.findAllByStudy(study);
String action = request.getParameter("action");
if (StringUtil.isBlank(idString)) {
addPageMessage(respage.getString("please_choose_a_site_to_restore"));
forwardPage(Page.SITE_LIST_SERVLET);
} else {
if ("confirm".equalsIgnoreCase(action)) {
// site can be restored when its parent study is not "removed"
// -- YW -6-21-2007
StudyBean parentstudy = (StudyBean) sdao.findByPK(study.getParentStudyId());
if (!"removed".equals(parentstudy.getStatus().getName())) {
request.setAttribute("siteToRestore", study);
request.setAttribute("userRolesToRestore", userRoles);
request.setAttribute("subjectsToRestore", subjects);
// request.setAttribute("definitionsToRestore",
// definitions);
} else {
MessageFormat mf = new MessageFormat("");
mf.applyPattern(respage.getString("choosen_site_cannot_restored"));
Object[] arguments = { study.getName(), parentstudy.getName() };
addPageMessage(mf.format(arguments));
forwardPage(Page.STUDY_LIST_SERVLET);
}
forwardPage(Page.RESTORE_SITE);
} else {
logger.info("submit to restore the site");
// 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);
// 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());
// YW << So study_user_role table status_id field can be
// updated
udao.updateStudyUserRole(role, role.getUserName());
}
// YW 06-18-2007 >>
}
// study
if (study.getId() == currentStudy.getId()) {
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.max(r.getRole(), rInParent.getRole()));
}
// YW >>
// restore all study_group
StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
ArrayList groups = sgdao.findAllByStudy(study);
for (int i = 0; i < groups.size(); i++) {
StudyGroupBean group = (StudyGroupBean) groups.get(i);
if (group.getStatus().equals(Status.AUTO_DELETED)) {
group.setStatus(Status.AVAILABLE);
group.setUpdater(ub);
group.setUpdatedDate(new Date());
sgdao.update(group);
// all subject_group_map
ArrayList subjectGroupMaps = sgmdao.findAllByStudyGroupId(group.getId());
for (int j = 0; j < subjectGroupMaps.size(); j++) {
SubjectGroupMapBean sgMap = (SubjectGroupMapBean) subjectGroupMaps.get(j);
if (sgMap.getStatus().equals(Status.AUTO_DELETED)) {
sgMap.setStatus(Status.AVAILABLE);
sgMap.setUpdater(ub);
sgMap.setUpdatedDate(new Date());
sgmdao.update(sgMap);
}
}
}
}
// restore all events with subjects
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
for (int i = 0; i < subjects.size(); i++) {
StudySubjectBean subject = (StudySubjectBean) subjects.get(i);
if (subject.getStatus().equals(Status.AUTO_DELETED)) {
subject.setStatus(Status.AVAILABLE);
subject.setUpdater(ub);
subject.setUpdatedDate(new Date());
ssdao.update(subject);
ArrayList events = sedao.findAllByStudySubject(subject);
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
for (int j = 0; j < events.size(); j++) {
StudyEventBean event = (StudyEventBean) events.get(j);
if (event.getStatus().equals(Status.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++) {
// YW << fix broken page for storing site
EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
// >> YW
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 subjects
DatasetDAO datadao = new DatasetDAO(sm.getDataSource());
ArrayList dataset = datadao.findAllByStudyId(study.getId());
for (int i = 0; i < dataset.size(); i++) {
DatasetBean data = (DatasetBean) dataset.get(i);
data.setStatus(Status.AVAILABLE);
data.setUpdater(ub);
data.setUpdatedDate(new Date());
datadao.update(data);
}
addPageMessage(respage.getString("this_site_has_been_restored_succesfully"));
String fromListSite = (String) session.getAttribute("fromListSite");
if (fromListSite != null && fromListSite.equals("yes") && currentRole.getRole().equals(Role.STUDYDIRECTOR)) {
session.removeAttribute("fromListSite");
forwardPage(Page.SITE_LIST_SERVLET);
} else {
session.removeAttribute("fromListSite");
if (currentRole.getRole().equals(Role.ADMIN)) {
forwardPage(Page.STUDY_LIST_SERVLET);
} else {
forwardPage(Page.SITE_LIST_SERVLET);
}
}
}
}
}
use of org.akaza.openclinica.dao.submit.EventCRFDAO in project OpenClinica by OpenClinica.
the class ViewStudySubjectAuditLogServlet 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());
FormProcessor fp = new FormProcessor(request);
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());
FormLayoutDAO fldao = new FormLayoutDAO(sm.getDataSource());
ArrayList studySubjectAudits = new ArrayList();
ArrayList eventCRFAudits = new ArrayList();
ArrayList studyEventAudits = new ArrayList();
ArrayList allDeletedEventCRFs = new ArrayList();
String attachedFilePath = Utils.getAttachedFilePath(currentStudy);
// studySubjectId
int studySubId = fp.getInt("id", true);
request.setAttribute("id", studySubId);
if (studySubId == 0) {
addPageMessage(respage.getString("please_choose_a_subject_to_view"));
forwardPage(Page.LIST_STUDY_SUBJECTS);
} else {
StudySubjectBean 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;
}
}
}
request.setAttribute("studySub", studySubject);
SubjectBean subject = (SubjectBean) sdao.findByPK(studySubject.getSubjectId());
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
study.getStudyParameterConfig().setCollectDob(spvdao.findByHandleAndStudy(study.getId(), "collectDob").getValue());
String collectdob = "used";
if (study.getStudyParameterConfig().getCollectDob().equals("2")) {
collectdob = "yearOnly";
} else if (study.getStudyParameterConfig().getCollectDob().equals("3")) {
collectdob = "notUsed";
} else if (study.getStudyParameterConfig().getCollectDob().equals("1")) {
collectdob = "used";
}
request.setAttribute("collectdob", collectdob);
request.setAttribute("subject", subject);
request.setAttribute("study", study);
/* 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()));
request.setAttribute("studySubjectAudits", studySubjectAudits);
// Get the list of events
ArrayList 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.findDeletedEventCRFsFromAuditEventByEventCRFStatus(studyEvent.getId());
allDeletedEventCRFs.addAll(deletedEventCRFs);
logger.info("deletedEventCRFs size[" + deletedEventCRFs.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.setFormLayout((FormLayoutBean) fldao.findByPK(eventCRF.getFormLayoutId()));
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());
}
}
request.setAttribute("events", events);
request.setAttribute("eventCRFAudits", eventCRFAudits);
request.setAttribute("studyEventAudits", studyEventAudits);
request.setAttribute("allDeletedEventCRFs", allDeletedEventCRFs);
request.setAttribute("attachedFilePath", attachedFilePath);
forwardPage(Page.VIEW_STUDY_SUBJECT_AUDIT);
}
}
use of org.akaza.openclinica.dao.submit.EventCRFDAO in project OpenClinica by OpenClinica.
the class ViewStudySubjectServlet method getDisplayStudyEventsForStudySubject.
public static ArrayList<DisplayStudyEventBean> getDisplayStudyEventsForStudySubject(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);
StudyDAO sdao = new StudyDAO(ds);
ArrayList events = sedao.findAllByStudySubject(studySub);
ArrayList displayEvents = new ArrayList();
for (int i = 0; i < events.size(); i++) {
StudyEventBean event = (StudyEventBean) events.get(i);
StudySubjectBean studySubject = (StudySubjectBean) ssdao.findByPK(event.getStudySubjectId());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(event.getStudyEventDefinitionId());
event.setStudyEventDefinition(sed);
// find all active crfs in the definition
StudyBean study = (StudyBean) sdao.findByPK(studySubject.getStudyId());
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(ds, eventCRFs, eventDefinitionCRFs, ub, currentRole, event.getSubjectEventStatus(), study));
ArrayList al = getUncompletedCRFs(ds, eventDefinitionCRFs, eventCRFs, event.getSubjectEventStatus());
populateUncompletedCRFsWithCRFAndVersions(ds, al);
de.setUncompletedCRFs(al);
de.setMaximumSampleOrdinal(sedao.getMaxSampleOrdinal(sed, studySubject));
displayEvents.add(de);
// event.setEventCRFs(createAllEventCRFs(eventCRFs,
// eventDefinitionCRFs));
}
return displayEvents;
}
use of org.akaza.openclinica.dao.submit.EventCRFDAO in project OpenClinica by OpenClinica.
the class ViewSectionDataEntryRESTUrlServlet method processRequest.
@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
FormProcessor fp = new FormProcessor(request);
StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
boolean isSubmitted = false;
EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) request.getAttribute(EVENT_DEF_CRF_BEAN);
if (!fp.getString("exitTo").equals("")) {
request.setAttribute("exitTo", request.getContextPath() + "/" + fp.getString("exitTo"));
}
int crfVersionId = fp.getInt("crfVersionId", true);
Integer sectionId = (Integer) request.getAttribute("sectionId");
if (sectionId == null || sectionId == 0) {
sectionId = new Integer(1);
}
int eventCRFId = fp.getInt(EVENT_CRF_ID, true);
int studySubjectId = fp.getInt("studySubjectId", true);
String action = fp.getString("action");
HttpSession session = request.getSession();
String fromResolvingNotes = fp.getString("fromResolvingNotes", true);
if (StringUtil.isBlank(fromResolvingNotes)) {
session.removeAttribute(ViewNotesServlet.WIN_LOCATION);
session.removeAttribute(ViewNotesServlet.NOTES_TABLE);
}
// Added for
request.setAttribute("studySubjectId", studySubjectId + "");
// Mantis
// Issue
// 2268
// Added
request.setAttribute("crfListPage", fp.getString("crfListPage"));
// for
// Mantis
// Issue
// 2268
// Added for
request.setAttribute("eventId", fp.getString("eventId"));
// Mantis
// Issue
// 2268
// YW <<
int sedId = fp.getInt("sedId");
request.setAttribute("sedId", sedId + "");
int crfId = fp.getInt("crfId");
// BWP>> ... try to get crfId from crfVersionId
if (crfId == 0 && crfVersionId > 0) {
CRFVersionDAO crfVDao = new CRFVersionDAO(getDataSource());
CRFVersionBean crvVBean = (CRFVersionBean) crfVDao.findByPK(crfVersionId);
if (crvVBean != null) {
crfId = crvVBean.getCrfId();
}
}
// YW >>
// int eventDefinitionCRFId = fp.getInt("eventDefinitionCRFId");
Integer eventDefinitionCRFId = (Integer) (request.getAttribute("eventDefinitionCRFId"));
EventDefinitionCRFDAO eventCrfDao = new EventDefinitionCRFDAO(getDataSource());
edcb = (EventDefinitionCRFBean) eventCrfDao.findByPK(eventDefinitionCRFId);
if (eventCRFId == 0 && edcb.getStudyId() != currentStudy.getParentStudyId() && edcb.getStudyId() != currentStudy.getId()) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_study_contact_sysadmin"), request);
throw new InsufficientPermissionException(Page.MENU_SERVLET, resexception.getString("not_director"), "1");
}
if (crfId == 0 && eventDefinitionCRFId > 0) {
// eventCrfDao.findByPK(eventDefinitionCRFId);
if (edcb != null) {
crfId = edcb.getCrfId();
}
}
request.setAttribute("crfId", crfId + "");
request.setAttribute("eventDefinitionCRFId", eventDefinitionCRFId + "");
String printVersion = fp.getString("print");
// BWP>> this has to be removed for CRFs that do not display an
// interviewdate
// for a particular event
session.removeAttribute("presetValues");
EventCRFDAO ecdao = new EventCRFDAO(getDataSource());
SectionDAO sdao = new SectionDAO(getDataSource());
String age = "";
if (sectionId == 0 && crfVersionId == 0 && eventCRFId == 0) {
addPageMessage(respage.getString("please_choose_a_CRF_to_view"), request);
// forwardPage(Page.SUBMIT_DATA_SERVLET);
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET, request, response);
// >> changed tbh, 06/2009
return;
}
if (studySubjectId > 0) {
StudySubjectDAO ssdao = new StudySubjectDAO(getDataSource());
StudySubjectBean sub = (StudySubjectBean) ssdao.findByPK(studySubjectId);
request.setAttribute("studySubject", sub);
}
if (eventCRFId > 0) {
// for event crf, the input crfVersionId from url =0
ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
StudyEventDAO sedao = new StudyEventDAO(getDataSource());
StudyEventBean event = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
// event.getSubjectEventStatus().getName());
if (event.getSubjectEventStatus().equals(SubjectEventStatus.LOCKED)) {
request.setAttribute("isLocked", "yes");
// System.out.println("this event crf is locked");
} else // @pgawade 28-Aug-2012 Reverted the change no. 2 in
// https://issuetracker.openclinica.com/view.php?id=12343#c56722
{
request.setAttribute("isLocked", "no");
}
if (studySubjectId <= 0) {
studySubjectId = event.getStudySubjectId();
request.setAttribute("studySubjectId", studySubjectId + "");
}
// Get the status/number of item discrepancy notes
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(getDataSource());
ArrayList<DiscrepancyNoteBean> allNotes = new ArrayList<DiscrepancyNoteBean>();
List<DiscrepancyNoteBean> eventCrfNotes = new ArrayList<DiscrepancyNoteBean>();
List<DiscrepancyNoteThread> noteThreads = new ArrayList<DiscrepancyNoteThread>();
// if (eventCRFId > 0) {
// this method finds only parent notes
allNotes = dndao.findAllTopNotesByEventCRF(eventCRFId);
// add interviewer.jsp related notes to this Collection
eventCrfNotes = dndao.findOnlyParentEventCRFDNotesFromEventCRF(ecb);
if (!eventCrfNotes.isEmpty()) {
allNotes.addAll(eventCrfNotes);
// make sure a necessary request attribute "hasNameNote" is set
// properly
this.setAttributeForInterviewerDNotes(eventCrfNotes, request);
}
// }
// Create disc note threads out of the various notes
DiscrepancyNoteUtil dNoteUtil = new DiscrepancyNoteUtil();
noteThreads = dNoteUtil.createThreadsOfParents(allNotes, getDataSource(), currentStudy, null, -1, true);
// variables that provide values for the CRF discrepancy note header
int updatedNum = 0;
int openNum = 0;
int closedNum = 0;
int resolvedNum = 0;
int notAppNum = 0;
DiscrepancyNoteBean tempBean;
for (DiscrepancyNoteThread dnThread : noteThreads) {
/*
* 3014: do not count parent beans, only the last child disc
* note of the thread.
*/
tempBean = dnThread.getLinkedNoteList().getLast();
if (tempBean != null) {
if (ResolutionStatus.UPDATED.equals(tempBean.getResStatus())) {
updatedNum++;
} else if (ResolutionStatus.OPEN.equals(tempBean.getResStatus())) {
openNum++;
} else if (ResolutionStatus.CLOSED.equals(tempBean.getResStatus())) {
// if (dn.getParentDnId() > 0){
closedNum++;
// }
} else if (ResolutionStatus.RESOLVED.equals(tempBean.getResStatus())) {
// if (dn.getParentDnId() > 0){
resolvedNum++;
// }
} else if (ResolutionStatus.NOT_APPLICABLE.equals(tempBean.getResStatus())) {
notAppNum++;
}
}
}
request.setAttribute("updatedNum", updatedNum + "");
request.setAttribute("openNum", openNum + "");
request.setAttribute("closedNum", closedNum + "");
request.setAttribute("resolvedNum", resolvedNum + "");
request.setAttribute("notAppNum", notAppNum + "");
DisplayTableOfContentsBean displayBean = TableOfContentsServlet.getDisplayBean(ecb, getDataSource(), currentStudy);
// Make sure that the interviewDate in the eventCRF is properly
// formatted
// for viewSectionDataEntry.jsp --> interviewer.jsp
// int studyEventId = (Integer)request.getAttribute("studyEvent");
// SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
//
Date tmpDate = displayBean.getEventCRF().getDateInterviewed();
String formattedInterviewerDate;
try {
DateFormat local_df = new SimpleDateFormat(resformat.getString("date_format_string"), ResourceBundleProvider.getLocale());
formattedInterviewerDate = local_df.format(tmpDate);
} catch (Exception e) {
formattedInterviewerDate = "";
}
HashMap presetVals = (HashMap) session.getAttribute("presetValues");
if (presetVals == null) {
presetVals = new HashMap();
session.setAttribute("presetValues", presetVals);
}
presetVals.put("interviewDate", formattedInterviewerDate);
request.setAttribute("toc", displayBean);
ArrayList sections = displayBean.getSections();
request.setAttribute("sectionNum", sections.size() + "");
if (!sections.isEmpty()) {
if (sectionId == 0) {
SectionBean firstSec = (SectionBean) sections.get(0);
sectionId = firstSec.getId();
}
} else {
addPageMessage(respage.getString("there_are_no_sections_ins_this_CRF"), request);
// forwardPage(Page.SUBMIT_DATA_SERVLET);
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET, request, response);
// >> changed tbh, 06/2009
return;
}
} else if (crfVersionId > 0) {
// for viewing blank CRF
DisplayTableOfContentsBean displayBean = ViewTableOfContentServlet.getDisplayBean(getDataSource(), crfVersionId);
request.setAttribute("toc", displayBean);
ArrayList sections = displayBean.getSections();
request.setAttribute("sectionNum", sections.size() + "");
if (!sections.isEmpty()) {
if (sectionId == 0) {
SectionBean firstSec = (SectionBean) sections.get(0);
sectionId = firstSec.getId();
}
} else {
addPageMessage(respage.getString("there_are_no_sections_ins_this_CRF_version"), request);
if (eventCRFId == 0) {
forwardPage(Page.CRF_LIST_SERVLET, request, response);
} else {
// forwardPage(Page.SUBMIT_DATA_SERVLET);
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET, request, response);
// >> changed tbh, 06/2009
}
return;
}
}
sb = (SectionBean) sdao.findByPK(sectionId);
if (eventCRFId == 0) {
ecb = new EventCRFBean();
ecb.setCRFVersionId(sb.getCRFVersionId());
if (currentStudy.getParentStudyId() > 0) {
// this is a site,find parent
StudyDAO studydao = new StudyDAO(getDataSource());
StudyBean parentStudy = (StudyBean) studydao.findByPK(currentStudy.getParentStudyId());
request.setAttribute("studyTitle", parentStudy.getName());
request.setAttribute("siteTitle", currentStudy.getName());
} else {
request.setAttribute("studyTitle", currentStudy.getName());
}
} else {
ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
request.setAttribute(INPUT_EVENT_CRF, ecb);
request.setAttribute(SECTION_BEAN, sb);
// This is the StudySubjectBean
StudySubjectDAO ssdao = new StudySubjectDAO(getDataSource());
StudySubjectBean sub = (StudySubjectBean) ssdao.findByPK(ecb.getStudySubjectId());
// This is the SubjectBean
SubjectDAO subjectDao = new SubjectDAO(getDataSource());
int subjectId = sub.getSubjectId();
int studyId = sub.getStudyId();
SubjectBean subject = (SubjectBean) subjectDao.findByPK(subjectId);
// Let us process the age
if (currentStudy.getStudyParameterConfig().getCollectDob().equals("1")) {
StudyEventDAO sedao = new StudyEventDAO(getDataSource());
StudyEventBean se = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
se.setStudyEventDefinition(sed);
request.setAttribute("studyEvent", se);
// YW 11-16-2007 enrollment-date is used for computing age
age = Utils.getInstacne().processAge(sub.getEnrollmentDate(), subject.getDateOfBirth());
}
// Get the study then the parent study
StudyDAO studydao = new StudyDAO(getDataSource());
StudyBean study = (StudyBean) studydao.findByPK(studyId);
if (study.getParentStudyId() > 0) {
// this is a site,find parent
StudyBean parentStudy = (StudyBean) studydao.findByPK(study.getParentStudyId());
request.setAttribute("studyTitle", parentStudy.getName());
request.setAttribute("siteTitle", study.getName());
} else {
request.setAttribute("studyTitle", study.getName());
}
request.setAttribute("studySubject", sub);
request.setAttribute("subject", subject);
request.setAttribute("age", age);
}
// FormBeanUtil formUtil = new FormBeanUtil();
// DisplaySectionBean newDisplayBean = new DisplaySectionBean();
boolean hasItemGroup = false;
// we will look into db to see if any repeating items for this CRF
// section
ItemGroupDAO igdao = new ItemGroupDAO(getDataSource());
List<ItemGroupBean> itemGroups = igdao.findLegitGroupBySectionId(sectionId);
if (!itemGroups.isEmpty()) {
hasItemGroup = true;
}
// if the List of DisplayFormGroups is empty, then the servlet defers to
// the prior method
// of generating a DisplaySectionBean for the application
DisplaySectionBean dsb;
// want to get displayBean with grouped and ungrouped items
request.setAttribute(EVENT_DEF_CRF_BEAN, edcb);
request.setAttribute(INPUT_EVENT_CRF, ecb);
request.setAttribute(SECTION_BEAN, sb);
dsb = super.getDisplayBean(hasItemGroup, false, request, isSubmitted);
FormDiscrepancyNotes discNotes = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
if (discNotes == null) {
discNotes = new FormDiscrepancyNotes();
session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes);
}
/*
* if (hasItemGroup) { //
* dsb.setDisplayItemGroups(newDisplayBean.getDisplayItemGroups());
* request.setAttribute("new_table", true); }
*/
// If the Horizontal type table will be used, then set the
// DisplaySectionBean's
// DisplayFormGroups List to the ones we have just generated
// @pgawade 30-May-2012 Fix for issue 13963 - added an extra parameter
// 'isSubmitted' to method createItemWithGroups
List<DisplayItemWithGroupBean> displayItemWithGroups = super.createItemWithGroups(dsb, hasItemGroup, eventDefinitionCRFId, request, isSubmitted);
dsb.setDisplayItemGroups(displayItemWithGroups);
super.populateNotesWithDBNoteCounts(discNotes, dsb, request);
if (fp.getString("fromViewNotes") != null && "1".equals(fp.getString("fromViewNotes"))) {
request.setAttribute("fromViewNotes", fp.getString("fromViewNotes"));
} else {
session.removeAttribute("viewNotesURL");
}
if ("saveNotes".equalsIgnoreCase(action)) {
LOGGER.info("33333how many group rows:" + dsb.getDisplayItemGroups().size());
// let's save notes for the blank items
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(getDataSource());
discNotes = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
for (int i = 0; i < dsb.getDisplayItemGroups().size(); i++) {
DisplayItemWithGroupBean diwb = dsb.getDisplayItemGroups().get(i);
if (diwb.isInGroup()) {
List<DisplayItemGroupBean> dgbs = diwb.getItemGroups();
LOGGER.info("dgbs size: " + dgbs.size());
for (int j = 0; j < dgbs.size(); j++) {
DisplayItemGroupBean displayGroup = dgbs.get(j);
List<DisplayItemBean> items = displayGroup.getItems();
LOGGER.info("item size: " + items.size());
for (DisplayItemBean displayItem : items) {
String inputName = getGroupItemInputName(displayGroup, j, displayItem);
LOGGER.info("inputName:" + inputName);
LOGGER.info("item data id:" + displayItem.getData().getId());
AddNewSubjectServlet.saveFieldNotes(inputName, discNotes, dndao, displayItem.getData().getId(), "itemData", currentStudy);
}
}
} else {
DisplayItemBean dib = diwb.getSingleItem();
// TODO work on this line
String inputName = getInputName(dib);
AddNewSubjectServlet.saveFieldNotes(inputName, discNotes, dndao, dib.getData().getId(), DiscrepancyNoteBean.ITEM_DATA, currentStudy);
ArrayList childItems = dib.getChildren();
for (int j = 0; j < childItems.size(); j++) {
DisplayItemBean child = (DisplayItemBean) childItems.get(j);
inputName = getInputName(child);
AddNewSubjectServlet.saveFieldNotes(inputName, discNotes, dndao, dib.getData().getId(), DiscrepancyNoteBean.ITEM_DATA, currentStudy);
}
}
}
addPageMessage("Discrepancy notes are saved successfully.", request);
request.setAttribute("id", studySubjectId + "");
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET, request, response);
// "ViewStudySubject?id=" + studySubjectId));
return;
} else {
request.setAttribute(BEAN_DISPLAY, dsb);
request.setAttribute(BEAN_ANNOTATIONS, ecb.getAnnotations());
request.setAttribute("sec", sb);
request.setAttribute("EventCRFBean", ecb);
int tabNum = 1;
if ("".equalsIgnoreCase(fp.getString("tabId"))) {
tabNum = 1;
} else {
tabNum = fp.getInt("tabId");
}
request.setAttribute("tabId", new Integer(tabNum).toString());
// 2808: Signal interviewer.jsp that the containing page is
// viewSectionData,
// for the purpose of suppressing discrepancy note icons for the
// interview date and name fields
request.setAttribute(ENCLOSING_PAGE, "viewSectionData");
if ("yes".equalsIgnoreCase(printVersion)) {
forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PRINT, request, response);
} else {
forwardPage(Page.VIEW_SECTION_DATA_ENTRY, request, response);
}
}
}
Aggregations