use of org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean in project OpenClinica by OpenClinica.
the class DiscrepancyNoteDAO method findByPK.
@Override
public EntityBean findByPK(int ID) {
DiscrepancyNoteBean eb = new DiscrepancyNoteBean();
this.setTypesExpected();
HashMap variables = new HashMap();
variables.put(Integer.valueOf(1), Integer.valueOf(ID));
String sql = digester.getQuery("findByPK");
ArrayList alist = this.select(sql, variables);
Iterator it = alist.iterator();
if (it.hasNext()) {
eb = (DiscrepancyNoteBean) this.getEntityFromHashMap((HashMap) it.next());
}
if (fetchMapping) {
eb = findSingleMapping(eb);
}
return eb;
}
use of org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean in project OpenClinica by OpenClinica.
the class ViewSectionDataEntryRESTUrlServlet method setAttributeForInterviewerDNotes.
/**
* Current User may access a requested event CRF in the current user's
* studies
*
* @author ywang 10-18-2007
* @param request
* TODO
*/
private void setAttributeForInterviewerDNotes(List<DiscrepancyNoteBean> eventCrfNotes, HttpServletRequest request) {
for (DiscrepancyNoteBean dnBean : eventCrfNotes) {
if (INTERVIEWER_NAME.equalsIgnoreCase(dnBean.getColumn())) {
request.setAttribute("hasNameNote", "yes");
request.setAttribute(INTERVIEWER_NAME_NOTE, dnBean);
}
if (DATE_INTERVIEWED.equalsIgnoreCase(dnBean.getColumn())) {
request.setAttribute("hasDateNote", "yes");
request.setAttribute(INTERVIEWER_DATE_NOTE, dnBean);
}
}
}
use of org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean in project OpenClinica by OpenClinica.
the class ViewSectionDataEntryServlet method processRequest.
// BWP 01/08>>
@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", fp.getString("exitTo"));
}
int crfVersionId = fp.getInt("crfVersionId", true);
int sectionId = fp.getInt("sectionId");
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");
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 {
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);
StudySubjectDAO studySubjectDAO = new StudySubjectDAO(getDataSource());
StudyEventDefinitionDAO studyEventDefinitionDAO = new StudyEventDefinitionDAO(getDataSource());
StudyEventDAO studyEventDAO = new StudyEventDAO(getDataSource());
StudyEventDefinitionBean studyEventDefinition = (StudyEventDefinitionBean) studyEventDefinitionDAO.findByPK(edcb.getStudyEventDefinitionId());
StudyEventBean studyEvent = (StudyEventBean) studyEventDAO.findByPK(ecb.getStudyEventId());
VariableSubstitutionHelper.replaceVariables(dsb, currentStudy, (StudySubjectBean) studySubjectDAO.findByPK(studySubjectId), studyEventDefinition, studyEvent, getDataSource());
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);
}
}
}
use of org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean in project OpenClinica by OpenClinica.
the class ViewStudySubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
// studySubjectId
int studySubId = fp.getInt("id", true);
String from = fp.getString("from");
String module = fp.getString(MODULE);
request.setAttribute(MODULE, module);
// if coming from change crf version -> display message
String crfVersionChangeMsg = fp.getString("isFromCRFVersionChange");
if (crfVersionChangeMsg != null && !crfVersionChangeMsg.equals("")) {
addPageMessage(crfVersionChangeMsg);
}
if (studySubId == 0) {
addPageMessage(respage.getString("please_choose_a_subject_to_view"));
forwardPage(Page.LIST_STUDY_SUBJECTS);
} else {
if (!StringUtil.isBlank(from)) {
// form ListSubject or
request.setAttribute("from", from);
// ListStudySubject
} else {
request.setAttribute("from", "");
}
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
request.setAttribute("studySub", studySub);
request.setAttribute("originatingPage", URLEncoder.encode("ViewStudySubject?id=" + studySub.getId(), "UTF-8"));
int studyId = studySub.getStudyId();
int subjectId = studySub.getSubjectId();
StudyDAO studydao = new StudyDAO(sm.getDataSource());
StudyBean study = (StudyBean) studydao.findByPK(studyId);
// Check if this StudySubject would be accessed from the Current Study
if (studySub.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;
}
}
}
// If the study subject derives from a site, and is being viewed
// from a parent study,
// then the study IDs will be different. However, since each note is
// saved with the specific
// study ID, then its study ID may be different than the study
// subject's ID.
boolean subjectStudyIsCurrentStudy = studyId == currentStudy.getId();
boolean isParentStudy = study.getParentStudyId() < 1;
// Get any disc notes for this subject : studySubId
DiscrepancyNoteDAO discrepancyNoteDAO = new DiscrepancyNoteDAO(sm.getDataSource());
List<DiscrepancyNoteBean> allNotesforSubject = new ArrayList<DiscrepancyNoteBean>();
// These methods return only parent disc notes
if (subjectStudyIsCurrentStudy && isParentStudy) {
allNotesforSubject = discrepancyNoteDAO.findAllSubjectByStudyAndId(study, subjectId);
allNotesforSubject.addAll(discrepancyNoteDAO.findAllStudySubjectByStudyAndId(study, studySubId));
} else {
if (!isParentStudy) {
StudyBean stParent = (StudyBean) studydao.findByPK(study.getParentStudyId());
allNotesforSubject = discrepancyNoteDAO.findAllSubjectByStudiesAndSubjectId(stParent, study, subjectId);
allNotesforSubject.addAll(discrepancyNoteDAO.findAllStudySubjectByStudiesAndStudySubjectId(stParent, study, studySubId));
} else {
allNotesforSubject = discrepancyNoteDAO.findAllSubjectByStudiesAndSubjectId(currentStudy, study, subjectId);
allNotesforSubject.addAll(discrepancyNoteDAO.findAllStudySubjectByStudiesAndStudySubjectId(currentStudy, study, studySubId));
}
}
if (!allNotesforSubject.isEmpty()) {
setRequestAttributesForNotes(allNotesforSubject);
}
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);
*/
// YW 11-26-2007 <<
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
study.getStudyParameterConfig().setCollectDob(spvdao.findByHandleAndStudy(studyId, "collectDob").getValue());
// YW >>
request.setAttribute("subjectStudy", study);
if (study.getParentStudyId() > 0) {
// this is a site,find parent
StudyBean parentStudy2 = (StudyBean) studydao.findByPK(study.getParentStudyId());
request.setAttribute("parentStudy", parentStudy2);
} 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());
StudySubjectService studySubjectService = (StudySubjectService) WebApplicationContextUtils.getWebApplicationContext(getServletContext()).getBean("studySubjectService");
List<DisplayStudyEventBean> displayEvents = studySubjectService.getDisplayStudyEventsForStudySubject(studySub, ub, currentRole);
for (int i = 0; i < displayEvents.size(); i++) {
DisplayStudyEventBean decb = displayEvents.get(i);
if (!(currentRole.isDirector() || currentRole.isCoordinator()) && decb.getStudyEvent().getSubjectEventStatus().isLocked()) {
decb.getStudyEvent().setEditable(false);
}
}
if (currentStudy.getParentStudyId() > 0) {
HideCRFManager hideCRFManager = HideCRFManager.createHideCRFManager();
for (DisplayStudyEventBean displayStudyEventBean : displayEvents) {
hideCRFManager.removeHiddenEventCRF(displayStudyEventBean);
}
}
EntityBeanTable table = fp.getEntityBeanTable();
// sort by start
table.setSortingIfNotExplicitlySet(1, false);
// date, 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())) {
if (currentStudy.getStatus().isAvailable() && !currentRole.getRole().equals(Role.MONITOR)) {
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);
// find audit log for events
AuditEventDAO aedao = new AuditEventDAO(sm.getDataSource());
ArrayList logs = aedao.findEventStatusLogByStudySubject(studySubId);
// logger.warning("^^^ retrieved logs");
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
ArrayList eventLogs = new ArrayList();
// logger.warning("^^^ starting to iterate");
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) {
e.printStackTrace();
}
UserAccountBean updater = (UserAccountBean) udao.findByPK(avb.getUserId());
sea.setUpdater(updater);
eventLogs.add(sea);
}
request.setAttribute("eventLogs", eventLogs);
forwardPage(Page.VIEW_STUDY_SUBJECT);
}
}
use of org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean in project OpenClinica by OpenClinica.
the class ViewNoteServlet method processRequest.
@Override
protected void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
Locale locale = LocaleResolver.getLocale(request);
DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
dndao.setFetchMapping(true);
int noteId = fp.getInt(NOTE_ID, true);
DiscrepancyNoteBean note = (DiscrepancyNoteBean) dndao.findByPK(noteId);
String entityType = note.getEntityType();
if (note.getEntityId() > 0 && !entityType.equals("")) {
if (!StringUtil.isBlank(entityType)) {
if ("itemData".equalsIgnoreCase(entityType)) {
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
ItemDataBean itemData = (ItemDataBean) iddao.findByPK(note.getEntityId());
ItemDAO idao = new ItemDAO(sm.getDataSource());
ItemBean item = (ItemBean) idao.findByPK(itemData.getItemId());
note.setEntityValue(itemData.getValue());
note.setEntityName(item.getName());
//Mantis Issue 5165. It should be itemData.getId() instead of item.getId()
note.setEntityId(itemData.getId());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
EventCRFBean ec = (EventCRFBean) ecdao.findByPK(itemData.getEventCRFId());
StudyEventDAO sed = new StudyEventDAO(sm.getDataSource());
StudyEventBean se = (StudyEventBean) sed.findByPK(ec.getStudyEventId());
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean ssub = (StudySubjectBean) ssdao.findByPK(se.getStudySubjectId());
note.setStudySub(ssub);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
se.setName(sedb.getName());
note.setEvent(se);
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFVersionBean cv = (CRFVersionBean) cvdao.findByPK(ec.getCRFVersionId());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFBean crf = (CRFBean) cdao.findByPK(cv.getCrfId());
note.setCrfName(crf.getName());
} else if ("studySub".equalsIgnoreCase(entityType)) {
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean ssub = (StudySubjectBean) ssdao.findByPK(note.getEntityId());
note.setStudySub(ssub);
// System.out.println("column" + note.getColumn());
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
SubjectBean sub = (SubjectBean) sdao.findByPK(ssub.getSubjectId());
if (!StringUtil.isBlank(note.getColumn())) {
if ("enrollment_date".equalsIgnoreCase(note.getColumn())) {
if (ssub.getEnrollmentDate() != null) {
note.setEntityValue(dateFormatter.format(ssub.getEnrollmentDate()));
}
note.setEntityName(resword.getString("enrollment_date"));
} else if ("gender".equalsIgnoreCase(note.getColumn())) {
note.setEntityValue(sub.getGender() + "");
note.setEntityName(resword.getString("gender"));
} else if ("date_of_birth".equalsIgnoreCase(note.getColumn())) {
if (sub.getDateOfBirth() != null) {
note.setEntityValue(dateFormatter.format(sub.getDateOfBirth()));
}
note.setEntityName(resword.getString("date_of_birth"));
}
}
} else if ("subject".equalsIgnoreCase(entityType)) {
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
SubjectBean sub = (SubjectBean) sdao.findByPK(note.getEntityId());
StudySubjectBean ssub = new StudySubjectBean();
ssub.setLabel(sub.getUniqueIdentifier());
note.setStudySub(ssub);
if (!StringUtil.isBlank(note.getColumn())) {
if ("gender".equalsIgnoreCase(note.getColumn())) {
note.setEntityValue(sub.getGender() + "");
note.setEntityName(resword.getString("gender"));
} else if ("date_of_birth".equalsIgnoreCase(note.getColumn())) {
if (sub.getDateOfBirth() != null) {
note.setEntityValue(dateFormatter.format(sub.getDateOfBirth()));
}
note.setEntityName(resword.getString("date_of_birth"));
} else if ("unique_identifier".equalsIgnoreCase(note.getColumn())) {
note.setEntityName(resword.getString("unique_identifier"));
note.setEntityValue(sub.getUniqueIdentifier());
}
}
} else if ("studyEvent".equalsIgnoreCase(entityType)) {
StudyEventDAO sed = new StudyEventDAO(sm.getDataSource());
StudyEventBean se = (StudyEventBean) sed.findByPK(note.getEntityId());
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean ssub = (StudySubjectBean) ssdao.findByPK(se.getStudySubjectId());
note.setStudySub(ssub);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
se.setName(sedb.getName());
note.setEvent(se);
if (!StringUtil.isBlank(note.getColumn())) {
if ("location".equalsIgnoreCase(note.getColumn())) {
request.setAttribute("entityValue", se.getLocation());
request.setAttribute("entityName", resword.getString("location"));
note.setEntityName(resword.getString("location"));
note.setEntityValue(se.getLocation());
} else if ("date_start".equalsIgnoreCase(note.getColumn())) {
if (se.getDateStarted() != null) {
note.setEntityValue(dateFormatter.format(se.getDateStarted()));
}
note.setEntityName(resword.getString("start_date"));
} else if ("date_end".equalsIgnoreCase(note.getColumn())) {
if (se.getDateEnded() != null) {
note.setEntityValue(dateFormatter.format(se.getDateEnded()));
}
note.setEntityName(resword.getString("end_date"));
}
}
} else if ("eventCrf".equalsIgnoreCase(entityType)) {
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
EventCRFBean ec = (EventCRFBean) ecdao.findByPK(note.getEntityId());
StudySubjectBean ssub = (StudySubjectBean) new StudySubjectDAO(sm.getDataSource()).findByPK(ec.getStudySubjectId());
note.setStudySub(ssub);
StudyEventBean event = (StudyEventBean) new StudyEventDAO(sm.getDataSource()).findByPK(ec.getStudyEventId());
note.setEvent(event);
if (!StringUtil.isBlank(note.getColumn())) {
if ("date_interviewed".equals(note.getColumn())) {
if (ec.getDateInterviewed() != null) {
note.setEntityValue(dateFormatter.format(ec.getDateInterviewed()));
}
note.setEntityName(resword.getString("date_interviewed"));
} else if ("interviewer_name".equals(note.getColumn())) {
note.setEntityValue(ec.getInterviewerName());
note.setEntityName(resword.getString("interviewer_name"));
}
}
}
}
}
// Mantis Issue 8495.
if (note.getStudyId() != currentStudy.getId()) {
if (currentStudy.getParentStudyId() > 0) {
if (currentStudy.getId() != note.getStudySub().getStudyId()) {
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.
StudyDAO studydao = new StudyDAO(sm.getDataSource());
Collection sites;
sites = studydao.findOlnySiteIdsByStudy(currentStudy);
if (!sites.contains(note.getStudySub().getStudyId())) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
forwardPage(Page.MENU_SERVLET);
return;
}
}
}
// Check end
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
ArrayList<DiscrepancyNoteBean> notes = dndao.findAllEntityByPK(note.getEntityType(), noteId);
Date lastUpdatedDate = note.getCreatedDate();
UserAccountBean lastUpdator = (UserAccountBean) udao.findByPK(note.getOwnerId());
/*
* for (int i = 0; i < notes.size(); i++) { DiscrepancyNoteBean n =
* (DiscrepancyNoteBean) notes.get(i); int pId = n.getParentDnId(); if
* (pId == 0) { note = n; note.setLastUpdator((UserAccountBean)
* udao.findByPK(n.getOwnerId()));
* note.setLastDateUpdated(n.getCreatedDate()); lastUpdatedDate =
* note.getLastDateUpdated(); lastUpdator = note.getLastUpdator(); } }
*/
// BWP 3029 >> This algorithm needs to be changed to properly set
// the parent note's status and updated date
// First sort the notes on their ID; this will put the parent note
// first; and
// the note with the latest status and updated date last
java.util.Collections.sort(notes);
DiscrepancyNoteBean lastChild = notes.get(notes.size() - 1);
lastUpdatedDate = lastChild.getCreatedDate();
lastUpdator = (UserAccountBean) udao.findByPK(lastChild.getOwnerId());
note.setLastUpdator(lastUpdator);
note.setLastDateUpdated(lastUpdatedDate);
note.setUpdatedDate(lastUpdatedDate);
for (DiscrepancyNoteBean dnBean : notes) {
if (dnBean.getParentDnId() > 0) {
note.getChildren().add(dnBean);
}
}
/*
* for (int i = 0; i < notes.size(); i++) { DiscrepancyNoteBean n =
* (DiscrepancyNoteBean) notes.get(i); int pId = n.getParentDnId(); if
* (pId > 0) { note.getChildren().add(n);
*
* if (!n.getCreatedDate().before(lastUpdatedDate)) { lastUpdatedDate =
* n.getCreatedDate(); lastUpdator = (UserAccountBean)
* udao.findByPK(n.getOwnerId()); note.setLastUpdator(lastUpdator);
* note.setLastDateUpdated(lastUpdatedDate);
* note.setResolutionStatusId(n.getResolutionStatusId());
* note.setResStatus(ResolutionStatus.get(n.getResolutionStatusId())); } } }
*/
note.setNumChildren(note.getChildren().size());
note.setDisType(DiscrepancyNoteType.get(note.getDiscrepancyNoteTypeId()));
request.setAttribute(DIS_NOTE, note);
forwardPage(Page.VIEW_SINGLE_NOTE);
}
Aggregations