use of org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO in project OpenClinica by OpenClinica.
the class ListDiscNotesSubjectServlet method processRequest.
// < ResourceBundleresexception,respage;
@Override
protected void processRequest() throws Exception {
String module = request.getParameter("module");
String moduleStr = "manage";
if (module != null && module.trim().length() > 0) {
if ("submit".equals(module)) {
request.setAttribute("module", "submit");
moduleStr = "submit";
} else if ("admin".equals(module)) {
request.setAttribute("module", "admin");
moduleStr = "admin";
} else {
request.setAttribute("module", "manage");
}
}
// << tbh 02/2010 filter out the entire module parameter to catch injections
// BWP 3098>> close the info side panel and show icons
request.setAttribute("closeInfoShowIcons", true);
// <<
// Determine whether to limit the displayed DN's to a certain DN type
int resolutionStatus = 0;
try {
resolutionStatus = Integer.parseInt(request.getParameter("resolutionStatus"));
} catch (NumberFormatException nfe) {
// Show all DN's
resolutionStatus = -1;
}
// Determine whether we already have a collection of resolutionStatus
// Ids, and if not
// create a new attribute. If there is no resolution status, then the
// Set object should be cleared,
// because we do not have to save a set of filter IDs.
boolean hasAResolutionStatus = resolutionStatus >= 1 && resolutionStatus <= 5;
Set<Integer> resolutionStatusIds = (HashSet) session.getAttribute(RESOLUTION_STATUS);
// remove the session if there is no resolution status
if (!hasAResolutionStatus && resolutionStatusIds != null) {
session.removeAttribute(RESOLUTION_STATUS);
resolutionStatusIds = null;
}
if (hasAResolutionStatus) {
if (resolutionStatusIds == null) {
resolutionStatusIds = new HashSet<Integer>();
}
resolutionStatusIds.add(resolutionStatus);
session.setAttribute(RESOLUTION_STATUS, resolutionStatusIds);
}
int discNoteType = 0;
try {
discNoteType = Integer.parseInt(request.getParameter("type"));
} catch (NumberFormatException nfe) {
// Show all DN's
discNoteType = -1;
}
request.setAttribute(DISCREPANCY_NOTE_TYPE, discNoteType);
DiscrepancyNoteUtil discNoteUtil = new DiscrepancyNoteUtil();
// Generate a summary of how we are filtering;
Map<String, List<String>> filterSummary = discNoteUtil.generateFilterSummary(discNoteType, resolutionStatusIds);
if (!filterSummary.isEmpty()) {
request.setAttribute(FILTER_SUMMARY, filterSummary);
}
locale = LocaleResolver.getLocale(request);
StudyBean sbean = (StudyBean) session.getAttribute("study");
//List<DiscrepancyNoteBean> allDiscNotes = discNoteUtil.getThreadedDNotesForStudy(sbean, resolutionStatusIds, sm.getDataSource(), discNoteType, true);
//Map stats = discNoteUtil.generateDiscNoteSummary(allDiscNotes);
Map stats = discNoteUtil.generateDiscNoteSummaryRefactored(sm.getDataSource(), currentStudy, resolutionStatusIds, discNoteType);
request.setAttribute("summaryMap", stats);
Set mapKeys = stats.keySet();
request.setAttribute("mapKeys", mapKeys);
// < resword =
// ResourceBundle.getBundle("org.akaza.openclinica.i18n.words",locale);
StudyDAO studyDAO = new StudyDAO(sm.getDataSource());
StudySubjectDAO sdao = new StudySubjectDAO(sm.getDataSource());
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
EventCRFDAO edao = new EventCRFDAO(sm.getDataSource());
EventDefinitionCRFDAO eddao = new EventDefinitionCRFDAO(sm.getDataSource());
SubjectDAO subdao = new SubjectDAO(sm.getDataSource());
DiscrepancyNoteDAO dnDAO = new DiscrepancyNoteDAO(sm.getDataSource());
ListDiscNotesSubjectTableFactory factory = new ListDiscNotesSubjectTableFactory(ResourceBundleProvider.getTermsBundle(locale));
factory.setStudyEventDefinitionDao(seddao);
factory.setSubjectDAO(subdao);
factory.setStudySubjectDAO(sdao);
factory.setStudyEventDAO(sedao);
factory.setStudyBean(currentStudy);
factory.setStudyGroupClassDAO(sgcdao);
factory.setSubjectGroupMapDAO(sgmdao);
factory.setStudyDAO(studyDAO);
factory.setCurrentRole(currentRole);
factory.setCurrentUser(ub);
factory.setEventCRFDAO(edao);
factory.setEventDefintionCRFDAO(eddao);
factory.setStudyGroupDAO(sgdao);
factory.setDiscrepancyNoteDAO(dnDAO);
factory.setModule(moduleStr);
factory.setDiscNoteType(discNoteType);
// factory.setStudyHasDiscNotes(allDiscNotes != null &&
// !allDiscNotes.isEmpty());
factory.setResolutionStatus(resolutionStatus);
factory.setResolutionStatusIds(resolutionStatusIds);
factory.setResword(ResourceBundleProvider.getWordsBundle(locale));
String listDiscNotesHtml = factory.createTable(request, response).render();
request.setAttribute("listDiscNotesHtml", listDiscNotesHtml);
forwardPage(getJSP());
}
use of org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO in project OpenClinica by OpenClinica.
the class DiscrepancyNoteController method buidDiscrepancyNote.
@RequestMapping(value = "/dnote", method = RequestMethod.POST)
public ResponseEntity buidDiscrepancyNote(@RequestBody HashMap<String, String> map, HttpServletRequest request) throws Exception {
ResourceBundleProvider.updateLocale(new Locale("en_US"));
System.out.println("I'm in EnketoForm DN Rest Method");
org.springframework.http.HttpStatus httpStatus = null;
String se_oid = map.get("EntityID");
String ordinal = map.get("Ordinal");
// start_date , end_date , location
String entityName = map.get("EntityName");
String studySubjectOid = map.get("SS_OID");
String noteType = map.get("NoteType");
String resolutionStatus = map.get("Status");
String assignedUser = map.get("AssignedUser");
String owner = map.get("Owner");
String description = map.get("Description");
String detailedNotes = map.get("DetailedNote");
String dn_id = map.get("DN_Id");
dn_id = dn_id != null ? dn_id.replaceFirst("DN_", "") : dn_id;
UserAccountDAO udao = new UserAccountDAO(dataSource);
StudySubjectDAO ssdao = new StudySubjectDAO(dataSource);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(dataSource);
StudyEventDAO sedao = new StudyEventDAO(dataSource);
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(dataSource);
UserAccountBean assignedUserBean = (UserAccountBean) udao.findByUserName(assignedUser);
UserAccountBean ownerBean = (UserAccountBean) request.getSession().getAttribute("userBean");
StudySubjectBean ssBean = ssdao.findByOid(studySubjectOid);
StudyEventDefinitionBean sedBean = seddao.findByOid(se_oid);
StudyBean studyBean = getStudy(sedBean.getStudyId());
StudyEventBean seBean = (StudyEventBean) sedao.findByStudySubjectIdAndDefinitionIdAndOrdinal(ssBean.getId(), sedBean.getId(), Integer.valueOf(ordinal));
String entityType = "studyEvent";
DiscrepancyNoteBean parent = (DiscrepancyNoteBean) dndao.findByPK(Integer.valueOf(dn_id));
if (!mayProceed(resolutionStatus, noteType, seBean, entityName, parent, ownerBean)) {
httpStatus = org.springframework.http.HttpStatus.BAD_REQUEST;
return new ResponseEntity(httpStatus);
}
if (!parent.isActive()) {
saveFieldNotes(description, detailedNotes, seBean.getId(), entityType, studyBean, ownerBean, assignedUserBean, resolutionStatus, noteType, entityName);
httpStatus = org.springframework.http.HttpStatus.OK;
} else {
createDiscrepancyNoteBean(description, detailedNotes, seBean.getId(), entityType, studyBean, ownerBean, assignedUserBean, parent.getId(), resolutionStatus, noteType, entityName);
httpStatus = org.springframework.http.HttpStatus.OK;
}
return new ResponseEntity(httpStatus);
}
use of org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO in project OpenClinica by OpenClinica.
the class DiscrepancyNoteOutputServlet method populateRowsWithAttachedData.
private ArrayList<DiscrepancyNoteBean> populateRowsWithAttachedData(ArrayList<DiscrepancyNoteBean> noteRows) {
Locale l = LocaleResolver.getLocale(request);
resword = ResourceBundleProvider.getWordsBundle(l);
resformat = ResourceBundleProvider.getFormatBundle(l);
SimpleDateFormat sdf = new SimpleDateFormat(resformat.getString("date_format_string"), ResourceBundleProvider.getLocale());
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
StudySubjectDAO studySubjectDAO = new StudySubjectDAO(sm.getDataSource());
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
ItemDAO idao = new ItemDAO(sm.getDataSource());
StudyDAO studyDao = new StudyDAO(sm.getDataSource());
ItemGroupMetadataDAO<String, ArrayList> igmdao = new ItemGroupMetadataDAO<String, ArrayList>(sm.getDataSource());
ItemGroupDAO<String, ArrayList> igdao = new ItemGroupDAO<String, ArrayList>(sm.getDataSource());
ArrayList<DiscrepancyNoteBean> allNotes = new ArrayList<DiscrepancyNoteBean>();
for (int i = 0; i < noteRows.size(); i++) {
DiscrepancyNoteBean dnb = noteRows.get(i);
dnb.setCreatedDateString(dnb.getCreatedDate() == null ? "" : sdf.format(dnb.getCreatedDate()));
if (dnb.getParentDnId() == 0) {
ArrayList children = dndao.findAllByStudyAndParent(currentStudy, dnb.getId());
children = children == null ? new ArrayList() : children;
dnb.setNumChildren(children.size());
dnb.setChildren(children);
int lastDnId = dnb.getId();
int lastChild = 0;
for (int j = 0; j < children.size(); j++) {
DiscrepancyNoteBean child = (DiscrepancyNoteBean) children.get(j);
child.setCreatedDateString(child.getCreatedDate() == null ? "" : sdf.format(child.getCreatedDate()));
child.setUpdatedDateString(child.getCreatedDate() != null ? sdf.format(child.getCreatedDate()) : "");
if (child.getId() > lastDnId) {
lastDnId = child.getId();
lastChild = j;
}
}
if (children.size() > 0) {
DiscrepancyNoteBean lastdn = (DiscrepancyNoteBean) children.get(lastChild);
//dnb.setResStatus(ResolutionStatus.get(lastdn.getResolutionStatusId()));
/*
* The update date is the date created of the latest child
* note
*/
dnb.setUpdatedDate(lastdn.getCreatedDate());
dnb.setUpdatedDateString(dnb.getUpdatedDate() != null ? sdf.format(dnb.getUpdatedDate()) : "");
}
}
String entityType = dnb.getEntityType();
if (dnb.getEntityId() > 0 && !entityType.equals("")) {
AuditableEntityBean aeb = dndao.findEntity(dnb);
dnb.setEntityName(aeb.getName());
if (entityType.equalsIgnoreCase("subject")) {
// allNotes.add(dnb);
SubjectBean sb = (SubjectBean) aeb;
StudySubjectBean ssb = studySubjectDAO.findBySubjectIdAndStudy(sb.getId(), currentStudy);
dnb.setStudySub(ssb);
dnb.setSubjectName(ssb.getLabel());
String column = dnb.getColumn().trim();
if (!StringUtil.isBlank(column)) {
if ("gender".equalsIgnoreCase(column)) {
dnb.setEntityValue(sb.getGender() + "");
dnb.setEntityName(resword.getString("gender"));
} else if ("date_of_birth".equals(column)) {
if (sb.getDateOfBirth() != null) {
dnb.setEntityValue(sb.getDateOfBirth().toString());
}
dnb.setEntityName(resword.getString("date_of_birth"));
} else if ("unique_identifier".equalsIgnoreCase(column)) {
dnb.setEntityName(resword.getString("unique_identifier"));
dnb.setEntityValue(sb.getUniqueIdentifier());
}
}
} else if (entityType.equalsIgnoreCase("studySub")) {
// allNotes.add(dnb);
StudySubjectBean ssb = (StudySubjectBean) aeb;
dnb.setStudySub(ssb);
dnb.setSubjectName(ssb.getLabel());
String column = dnb.getColumn().trim();
if (!StringUtil.isBlank(column)) {
if ("enrollment_date".equals(column)) {
if (ssb.getEnrollmentDate() != null) {
dnb.setEntityValue(ssb.getEnrollmentDate().toString());
}
dnb.setEntityName(resword.getString("enrollment_date"));
}
}
} else if (entityType.equalsIgnoreCase("eventCRF")) {
StudyEventBean se = (StudyEventBean) sedao.findByPK(dnb.getEntityId());
StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
EventCRFBean ecb = (EventCRFBean) aeb;
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(ecb.getCRFVersionId());
CRFBean cb = (CRFBean) cdao.findByPK(cvb.getCrfId());
dnb.setStageId(ecb.getStage().getId());
dnb.setEntityName(cb.getName() + " (" + cvb.getName() + ")");
StudySubjectBean ssub = (StudySubjectBean) studySubjectDAO.findByPK(ecb.getStudySubjectId());
dnb.setStudySub(ssub);
dnb.setSubjectName(ssub.getLabel());
if (se != null) {
dnb.setEventStart(se.getDateStarted());
dnb.setEventName(se.getName());
}
dnb.setCrfName(cb.getName());
String crfStatus = resword.getString(ecb.getStage().getNameRaw());
if (crfStatus.equals("Invalid")) {
crfStatus = "";
} else if (crfStatus.equals("Data Entry Complete")) {
crfStatus = "Complete";
}
dnb.setCrfStatus(crfStatus);
String column = dnb.getColumn().trim();
if (!StringUtil.isBlank(column)) {
if ("date_interviewed".equals(column)) {
if (ecb.getDateInterviewed() != null) {
dnb.setEntityValue(ecb.getDateInterviewed().toString());
}
dnb.setEntityName(resword.getString("date_interviewed"));
} else if ("interviewer_name".equals(column)) {
dnb.setEntityValue(ecb.getInterviewerName());
dnb.setEntityName(resword.getString("interviewer_name"));
}
}
dnb.setEvent(se);
dnb.setStudyEventDefinitionBean(sedb);
// }
} else if (entityType.equalsIgnoreCase("studyEvent")) {
// allNotes.add(dnb);
StudyEventBean se = (StudyEventBean) sedao.findByPK(dnb.getEntityId());
StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
se.setName(sedb.getName());
dnb.setEntityName(sedb.getName());
StudySubjectBean ssub = (StudySubjectBean) studySubjectDAO.findByPK(se.getStudySubjectId());
dnb.setStudySub(ssub);
dnb.setEventStart(se.getDateStarted());
dnb.setEventName(se.getName());
dnb.setSubjectName(ssub.getLabel());
String column = dnb.getColumn().trim();
if (!StringUtil.isBlank(column)) {
if ("date_start".equals(column)) {
if (se.getDateStarted() != null) {
dnb.setEntityValue(se.getDateStarted().toString());
}
dnb.setEntityName(resword.getString("start_date"));
} else if ("date_end".equals(column)) {
if (se.getDateEnded() != null) {
dnb.setEntityValue(se.getDateEnded().toString());
}
dnb.setEntityName(resword.getString("end_date"));
} else if ("location".equals(column)) {
dnb.setEntityValue(se.getLocation());
dnb.setEntityName(resword.getString("location"));
}
}
dnb.setEvent(se);
dnb.setStudyEventDefinitionBean(sedb);
} else if (entityType.equalsIgnoreCase("itemData")) {
ItemDataBean idb = (ItemDataBean) iddao.findByPK(dnb.getEntityId());
ItemBean ib = (ItemBean) idao.findByPK(idb.getItemId());
EventCRFBean ec = (EventCRFBean) ecdao.findByPK(idb.getEventCRFId());
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(ec.getCRFVersionId());
CRFBean cb = (CRFBean) cdao.findByPK(cvb.getCrfId());
ItemGroupMetadataBean itemGroupMetadataBean = (ItemGroupMetadataBean) igmdao.findByItemAndCrfVersion(ib.getId(), cvb.getId());
Boolean isRepeatForSure = itemGroupMetadataBean.isRepeatingGroup();
if (isRepeatForSure) {
ItemGroupBean ig = (ItemGroupBean) igdao.findByPK(itemGroupMetadataBean.getItemGroupId());
dnb.setItemDataOrdinal(idb.getOrdinal());
dnb.setItemGroupName(ig.getName());
}
// allNotes.add(dnb);
dnb.setStageId(ec.getStage().getId());
dnb.setEntityName(ib.getName());
dnb.setEntityValue(idb.getValue());
StudyEventBean se = (StudyEventBean) sedao.findByPK(ec.getStudyEventId());
StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
se.setName(sedb.getName());
StudySubjectBean ssub = (StudySubjectBean) studySubjectDAO.findByPK(ec.getStudySubjectId());
dnb.setStudySub(ssub);
dnb.setSubjectName(ssub.getLabel());
dnb.setEventStart(se.getDateStarted());
dnb.setEventName(se.getName());
dnb.setCrfName(cb.getName());
String crfStatus = resword.getString(ec.getStage().getNameRaw());
if (crfStatus.equals("Invalid")) {
crfStatus = "";
} else if (crfStatus.equals("Data Entry Complete")) {
crfStatus = "Complete";
}
dnb.setCrfStatus(crfStatus);
dnb.setEvent(se);
dnb.setStudyEventDefinitionBean(sedb);
}
}
dnb.setStudy((StudyBean) studyDao.findByPK(dnb.getStudyId()));
if (dnb.getParentDnId() == 0 && dnb.getChildren().size() > 0) {
ArrayList<DiscrepancyNoteBean> children = dnb.getChildren();
int childrenSize = children.size();
for (int j = 0; j < childrenSize; j++) {
DiscrepancyNoteBean child = children.get(j);
child.setSubjectName(dnb.getSubjectName());
child.setEventName(dnb.getEventName());
child.setCrfName(dnb.getCrfName());
child.setCrfStatus(dnb.getCrfStatus());
child.setEntityName(dnb.getEntityName());
child.setEntityValue(dnb.getEntityValue());
child.setStudySub(dnb.getStudySub());
child.setStudy(dnb.getStudy());
}
}
allNotes.add(dnb);
}
return allNotes;
}
use of org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO in project OpenClinica by OpenClinica.
the class UpdateStudyEventServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormDiscrepancyNotes discNotes = null;
FormProcessor fp = new FormProcessor(request);
int studyEventId = fp.getInt(EVENT_ID, true);
int studySubjectId = fp.getInt(STUDY_SUBJECT_ID, true);
String module = fp.getString(MODULE);
request.setAttribute(MODULE, module);
String fromResolvingNotes = fp.getString("fromResolvingNotes", true);
if (StringUtil.isBlank(fromResolvingNotes)) {
session.removeAttribute(ViewNotesServlet.WIN_LOCATION);
session.removeAttribute(ViewNotesServlet.NOTES_TABLE);
checkStudyLocked(Page.MANAGE_STUDY, respage.getString("current_study_locked"));
checkStudyFrozen(Page.MANAGE_STUDY, respage.getString("current_study_frozen"));
}
if (studyEventId == 0 || studySubjectId == 0) {
addPageMessage(respage.getString("choose_a_study_event_to_edit"));
request.setAttribute("id", new Integer(studySubjectId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
return;
}
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean ssub = null;
if (studySubjectId > 0) {
ssub = (StudySubjectBean) ssdao.findByPK(studySubjectId);
request.setAttribute("studySubject", ssub);
// for the workflow
request.setAttribute("id", studySubjectId + "");
// box, so it can
// link back to view
// study subject
}
// YW 11-07-2007, a study event could not be updated if its study
// subject has been removed
// Status s = ((StudySubjectBean)new
// StudySubjectDAO(sm.getDataSource()).findByPK(studySubjectId)).getStatus();
Status s = ssub.getStatus();
if ("removed".equalsIgnoreCase(s.getName()) || "auto-removed".equalsIgnoreCase(s.getName())) {
addPageMessage(resword.getString("study_event") + resterm.getString("could_not_be") + resterm.getString("updated") + "." + respage.getString("study_subject_has_been_deleted"));
request.setAttribute("id", new Integer(studySubjectId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
}
// YW
request.setAttribute(STUDY_SUBJECT_ID, new Integer(studySubjectId).toString());
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
EventCRFDAO ecrfdao = new EventCRFDAO(sm.getDataSource());
StudyEventBean studyEvent = (StudyEventBean) sedao.findByPK(studyEventId);
studyEvent.setEventCRFs(ecrfdao.findAllByStudyEvent(studyEvent));
// only owner, admins, and study director/coordinator can update
// if (ub.getId() != studyEvent.getOwnerId()) {
// if (!ub.isSysAdmin() &&
// !currentRole.getRole().equals(Role.STUDYDIRECTOR)
// && !currentRole.getRole().equals(Role.COORDINATOR)) {
// addPageMessage(respage.getString("no_have_correct_privilege_current_study")
// + respage.getString("change_study_contact_sysadmin"));
// request.setAttribute("id", new Integer(studySubjectId).toString());
// forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
// return;
// }
// }
// above removed tbh 11162007
ArrayList statuses = SubjectEventStatus.toArrayList();
// remove more statuses here, tbh, 092007
// ### updates to status setting, below added tbh 102007
// following pieces of logic to be added:
/*
* REMOVED can happen at any step, COMPLETED can happen if the Subject
* Event is already complete, COMPLETED can also happen if all required
* CRFs in the Subject Event are completed, LOCKED can occur when all
* Event CRFs are completed, or not started, or removed, LOCKED/REMOVED
* are only options, however, when the user is study director or study
* coordinator SKIPPED/STOPPED? Additional rules spelled out on Nov 16
* 2007: STOPPED should only be in the list of choices after IDE has
* been started, i.e. not when SCHEDULED SKIPPED should only be in the
* list before IDE has been started, i.e. when SCHEDULED reminder about
* LOCKED happening only when CRFs are completed (not as in the
* above...) if a status is LOCKED already, it should allow a user to
* set the event back to COMPLETED
*/
StudyDAO sdao = new StudyDAO(this.sm.getDataSource());
StudyBean studyBean = (StudyBean) sdao.findByPK(ssub.getStudyId());
checkRoleByUserAndStudy(ub, studyBean.getParentStudyId(), studyBean.getId());
// To remove signed status from the list
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
boolean removeSign = false;
// DiscrepancyNoteDAO discDao = new
// DiscrepancyNoteDAO(sm.getDataSource());
ArrayList eventCrfs = studyEvent.getEventCRFs();
for (int i = 0; i < eventCrfs.size(); i++) {
EventCRFBean ecrf = (EventCRFBean) eventCrfs.get(i);
EventDefinitionCRFBean edcBean = edcdao.findByStudyEventIdAndCRFVersionId(studyBean, studyEventId, ecrf.getCRFVersionId());
if (ecrf.getStage().equals(DataEntryStage.INITIAL_DATA_ENTRY) || ecrf.getStage().equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) && edcBean.isDoubleEntry() == true) {
removeSign = true;
break;
}
}
if (currentRole.isResearchAssistant()) {
removeSign = true;
}
if (currentRole.isResearchAssistant2()) {
removeSign = true;
}
if (removeSign == true || !currentRole.isInvestigator()) {
statuses.remove(SubjectEventStatus.SIGNED);
}
/*
* if(!studyEvent.getSubjectEventStatus().equals(SubjectEventStatus.
* DATA_ENTRY_STARTED)) {
* statuses.remove(SubjectEventStatus.DATA_ENTRY_STARTED);
* //statuses.remove(SubjectEventStatus.SKIPPED); // per new rule
* 11-2007 }
*/
if (!studyEvent.getSubjectEventStatus().equals(SubjectEventStatus.NOT_SCHEDULED)) {
statuses.remove(SubjectEventStatus.NOT_SCHEDULED);
}
if (!studyEvent.getSubjectEventStatus().equals(SubjectEventStatus.SCHEDULED)) {
// can't lock a non-completed CRF, but removed above
statuses.remove(SubjectEventStatus.SCHEDULED);
// statuses.remove(SubjectEventStatus.SKIPPED);
// addl rule: skipped should only be present before data starts
// being entered
}
if (studyEvent.getSubjectEventStatus().equals(SubjectEventStatus.DATA_ENTRY_STARTED)) {
statuses.remove(SubjectEventStatus.SKIPPED);
}
ArrayList getECRFs = studyEvent.getEventCRFs();
// above removed tbh 102007, require to get all definitions, no matter
// if they are filled in or now
EventDefinitionCRFDAO edefcrfdao = new EventDefinitionCRFDAO(sm.getDataSource());
ArrayList getAllECRFs = (ArrayList) edefcrfdao.findAllByDefinition(studyBean, studyEvent.getStudyEventDefinitionId());
// does the study event have all complete CRFs which are required?
logger.debug("found number of ecrfs: " + getAllECRFs.size());
// may not be populated, only entered crfs seem to ping the list
for (int u = 0; u < getAllECRFs.size(); u++) {
EventDefinitionCRFBean ecrfBean = (EventDefinitionCRFBean) getAllECRFs.get(u);
//
logger.debug("found number of existing ecrfs: " + getECRFs.size());
if (getECRFs.size() == 0) {
statuses.remove(SubjectEventStatus.COMPLETED);
statuses.remove(SubjectEventStatus.LOCKED);
}
// otherwise...
for (int uv = 0; uv < getECRFs.size(); uv++) {
EventCRFBean existingBean = (EventCRFBean) getECRFs.get(uv);
logger.debug("***** found: " + existingBean.getCRFVersionId() + " " + existingBean.getCrf().getId() + " " + existingBean.getCrfVersion().getName() + " " + existingBean.getStatus().getName() + " " + existingBean.getStage().getName());
logger.debug("***** comparing above to ecrfBean.DefaultVersionID: " + ecrfBean.getDefaultVersionId());
// this is addressed in the if-clause above
if (!existingBean.getStatus().equals(Status.UNAVAILABLE) && edefcrfdao.isRequiredInDefinition(existingBean.getCRFVersionId(), studyEvent)) {
logger.debug("found that " + existingBean.getCrfVersion().getName() + " is required...");
// that is, it's not completed but required to complete
statuses.remove(SubjectEventStatus.COMPLETED);
statuses.remove(SubjectEventStatus.LOCKED);
// per new rule above 11-16-2007
}
// }
}
}
// below added 092007, tbh, task #1390
if (!ub.isSysAdmin() && !currentRole.getRole().equals(Role.STUDYDIRECTOR) && !currentRole.getRole().equals(Role.COORDINATOR)) {
statuses.remove(SubjectEventStatus.LOCKED);
}
// scheduled
if (studyEvent.getSubjectEventStatus().equals(SubjectEventStatus.DATA_ENTRY_STARTED)) {
statuses.remove(SubjectEventStatus.NOT_SCHEDULED);
statuses.remove(SubjectEventStatus.SCHEDULED);
}
// ### tbh, above modified 102007
request.setAttribute("statuses", statuses);
String action = fp.getString("action");
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(studyEvent.getStudyEventDefinitionId());
request.setAttribute(EVENT_DEFINITION_BEAN, sed);
if (action.equalsIgnoreCase("submit")) {
discNotes = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
DiscrepancyValidator v = new DiscrepancyValidator(request, discNotes);
SubjectEventStatus ses = SubjectEventStatus.get(fp.getInt(SUBJECT_EVENT_STATUS_ID));
studyEvent.setSubjectEventStatus(ses);
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ArrayList<EventCRFBean> eventCRFs = ecdao.findAllByStudyEvent(studyEvent);
if (ses.equals(SubjectEventStatus.SKIPPED) || ses.equals(SubjectEventStatus.STOPPED)) {
studyEvent.setStatus(Status.UNAVAILABLE);
for (int i = 0; i < eventCRFs.size(); i++) {
EventCRFBean ecb = eventCRFs.get(i);
ecb.setOldStatus(ecb.getStatus());
ecb.setStatus(Status.UNAVAILABLE);
ecb.setUpdater(ub);
ecb.setUpdatedDate(new Date());
ecdao.update(ecb);
}
} else {
for (int i = 0; i < eventCRFs.size(); i++) {
EventCRFBean ecb = eventCRFs.get(i);
ecb.setUpdater(ub);
ecb.setUpdatedDate(new Date());
ecdao.update(ecb);
}
}
// YW 3-12-2008, 2220 fix
String strEnd = fp.getDateTimeInputString(INPUT_ENDDATE_PREFIX);
String strEndScheduled = fp.getDateTimeInputString(INPUT_ENDDATE_PREFIX);
Date start = fp.getDateTime(INPUT_STARTDATE_PREFIX);
Date end = null;
v.addValidation(INPUT_STARTDATE_PREFIX, Validator.IS_DATE_TIME);
v.alwaysExecuteLastValidation(INPUT_STARTDATE_PREFIX);
if (!strEndScheduled.equals("")) {
v.addValidation(INPUT_ENDDATE_PREFIX, Validator.IS_DATE_TIME);
v.alwaysExecuteLastValidation(INPUT_ENDDATE_PREFIX);
}
// v.addValidation(INPUT_LOCATION, Validator.NO_BLANKS); Disable validation on location, location can be empty when updating a study event
HashMap errors = v.validate();
// YW, 3-12-2008, 2220 fix <<
if (!strEnd.equals("") && !errors.containsKey(INPUT_STARTDATE_PREFIX) && !errors.containsKey(INPUT_ENDDATE_PREFIX)) {
end = fp.getDateTime(INPUT_ENDDATE_PREFIX);
if (!fp.getString(INPUT_STARTDATE_PREFIX + "Date").equals(fp.getString(INPUT_ENDDATE_PREFIX + "Date"))) {
if (end.before(start)) {
v.addError(errors, INPUT_ENDDATE_PREFIX, resexception.getString("input_provided_not_occure_after_previous_start_date_time"));
}
} else {
// if in same date, only check when both had time entered
if (fp.timeEntered(INPUT_STARTDATE_PREFIX) && fp.timeEntered(INPUT_ENDDATE_PREFIX)) {
if (end.before(start) || end.equals(start)) {
v.addError(errors, INPUT_ENDDATE_PREFIX, resexception.getString("input_provided_not_occure_after_previous_start_date_time"));
}
}
}
}
if (!errors.isEmpty()) {
setInputMessages(errors);
String[] prefixes = { INPUT_STARTDATE_PREFIX, INPUT_ENDDATE_PREFIX };
fp.setCurrentDateTimeValuesAsPreset(prefixes);
setPresetValues(fp.getPresetValues());
studyEvent.setLocation(fp.getString(INPUT_LOCATION));
request.setAttribute("changeDate", fp.getString("changeDate"));
request.setAttribute(EVENT_BEAN, studyEvent);
forwardPage(Page.UPDATE_STUDY_EVENT);
} else if (studyEvent.getSubjectEventStatus().isSigned()) {
// Checks if the status is signed
// -----------------
request.setAttribute(STUDY_SUBJECT_ID, new Integer(studySubjectId).toString());
if (fp.getString(INPUT_STARTDATE_PREFIX + "Hour").equals("-1") && fp.getString(INPUT_STARTDATE_PREFIX + "Minute").equals("-1") && fp.getString(INPUT_STARTDATE_PREFIX + "Half").equals("")) {
studyEvent.setStartTimeFlag(false);
} else {
studyEvent.setStartTimeFlag(true);
}
studyEvent.setDateStarted(start);
if (!strEnd.equals("")) {
studyEvent.setDateEnded(end);
if (fp.getString(INPUT_ENDDATE_PREFIX + "Hour").equals("-1") && fp.getString(INPUT_ENDDATE_PREFIX + "Minute").equals("-1") && fp.getString(INPUT_ENDDATE_PREFIX + "Half").equals("")) {
studyEvent.setEndTimeFlag(false);
} else {
studyEvent.setEndTimeFlag(true);
}
}
studyEvent.setLocation(fp.getString(INPUT_LOCATION));
studyEvent.setStudyEventDefinition(sed);
// -------------------
ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean ssb = (StudySubjectBean) ssdao.findByPK(studyEvent.getStudySubjectId());
ecdao = new EventCRFDAO(sm.getDataSource());
eventCRFs = ecdao.findAllByStudyEvent(studyEvent);
ArrayList<Boolean> doRuleSetsExist = new ArrayList<Boolean>();
RuleSetDAO ruleSetDao = new RuleSetDAO(sm.getDataSource());
StudyBean study = (StudyBean) sdao.findByPK(ssb.getStudyId());
ArrayList eventDefinitionCRFs = (ArrayList) edcdao.findAllActiveByEventDefinitionId(study, studyEvent.getStudyEventDefinitionId());
ArrayList uncompletedEventDefinitionCRFs = getUncompletedCRFs(eventDefinitionCRFs, eventCRFs);
populateUncompletedCRFsWithCRFAndVersions(uncompletedEventDefinitionCRFs);
ArrayList displayEventCRFs = ViewStudySubjectServlet.getDisplayEventCRFs(sm.getDataSource(), eventCRFs, eventDefinitionCRFs, ub, currentRole, studyEvent.getSubjectEventStatus(), study);
request.setAttribute("studySubject", ssb);
request.setAttribute("uncompletedEventDefinitionCRFs", uncompletedEventDefinitionCRFs);
request.setAttribute("displayEventCRFs", displayEventCRFs);
request.setAttribute(EVENT_BEAN, studyEvent);
session.setAttribute("eventSigned", studyEvent);
DiscrepancyNoteUtil discNoteUtil = new DiscrepancyNoteUtil();
DisplayStudyEventBean displayEvBean = new DisplayStudyEventBean();
List<DisplayStudyEventBean> displayEvents = new ArrayList<DisplayStudyEventBean>();
// 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
displayEvBean.setStudyEvent(studyEvent);
displayEvents.add(displayEvBean);
// Don't filter for res status or disc note type; disc note
// beans are returned with eventCRFId set
discNoteUtil.injectParentDiscNotesIntoDisplayStudyEvents(displayEvents, new HashSet(), sm.getDataSource(), 0);
Map discNoteByEventCRFid = discNoteUtil.createDiscNoteMapByEventCRF(displayEvents);
request.setAttribute("discNoteByEventCRFid", discNoteByEventCRFid);
forwardPage(Page.UPDATE_STUDY_EVENT_SIGNED);
} else {
logger.debug("no validation error");
// YW 08-17-2007 << update start_time_flag column
if (fp.getString(INPUT_STARTDATE_PREFIX + "Hour").equals("-1") && fp.getString(INPUT_STARTDATE_PREFIX + "Minute").equals("-1") && fp.getString(INPUT_STARTDATE_PREFIX + "Half").equals("")) {
studyEvent.setStartTimeFlag(false);
} else {
studyEvent.setStartTimeFlag(true);
}
// YW >>
studyEvent.setDateStarted(start);
// YW, 3-12-2008, 2220 fix which adding End datetime <<
if (!strEnd.equals("")) {
studyEvent.setDateEnded(end);
if (fp.getString(INPUT_ENDDATE_PREFIX + "Hour").equals("-1") && fp.getString(INPUT_ENDDATE_PREFIX + "Minute").equals("-1") && fp.getString(INPUT_ENDDATE_PREFIX + "Half").equals("")) {
studyEvent.setEndTimeFlag(false);
} else {
studyEvent.setEndTimeFlag(true);
}
}
// YW >>
studyEvent.setLocation(fp.getString(INPUT_LOCATION));
logger.debug("update study event...");
studyEvent.setUpdater(ub);
studyEvent.setUpdatedDate(new Date());
StudyEventBean updatedStudyEvent = (StudyEventBean) sedao.update(studyEvent);
// save discrepancy notes into DB
FormDiscrepancyNotes fdn = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
AddNewSubjectServlet.saveFieldNotes(INPUT_LOCATION, fdn, dndao, studyEvent.getId(), "studyEvent", currentStudy);
AddNewSubjectServlet.saveFieldNotes(INPUT_STARTDATE_PREFIX, fdn, dndao, studyEvent.getId(), "studyEvent", currentStudy);
AddNewSubjectServlet.saveFieldNotes(INPUT_ENDDATE_PREFIX, fdn, dndao, studyEvent.getId(), "studyEvent", currentStudy);
// getRuleSetService().runRulesInBeanProperty(createRuleSet(ssub,sed),currentStudy,ub,request,ssub);
addPageMessage(respage.getString("study_event_updated"));
request.setAttribute("id", new Integer(studySubjectId).toString());
session.removeAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
// FORWARD SHOULD BE TO THE NEW PAGE
}
} else if (action.equalsIgnoreCase("confirm")) {
// confirming the signed
// status
String username = request.getParameter("j_user");
String password = request.getParameter("j_pass");
//tring encodedUserPass = org.akaza.openclinica.core.SecurityManager.getInstance().encrytPassword(password);
SecurityManager securityManager = ((SecurityManager) SpringServletAccess.getApplicationContext(context).getBean("securityManager"));
UserAccountBean ub = (UserAccountBean) session.getAttribute("userBean");
StudyEventBean seb = (StudyEventBean) session.getAttribute("eventSigned");
if (securityManager.verifyPassword(password, getUserDetails()) && ub.getName().equals(username)) {
seb.setUpdater(ub);
seb.setUpdatedDate(new Date());
sedao.update(seb);
// If all the StudyEvents become signed we will make the
// StudySubject signed as well
List studyEvents = sedao.findAllByStudySubject(ssub);
boolean allSigned = true;
for (Iterator iterator = studyEvents.iterator(); iterator.hasNext(); ) {
StudyEventBean temp = (StudyEventBean) iterator.next();
if (!temp.getSubjectEventStatus().equals(SubjectEventStatus.SIGNED)) {
allSigned = false;
break;
}
}
if (allSigned) {
logger.debug("Signing StudySubject [" + ssub.getSubjectId() + "]");
ssub.setStatus(Status.SIGNED);
ssub.setUpdater(ub);
ssdao.update(ssub);
}
// save discrepancy notes into DB
FormDiscrepancyNotes fdn = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
AddNewSubjectServlet.saveFieldNotes(INPUT_LOCATION, fdn, dndao, studyEvent.getId(), "studyEvent", currentStudy);
AddNewSubjectServlet.saveFieldNotes(INPUT_STARTDATE_PREFIX, fdn, dndao, studyEvent.getId(), "studyEvent", currentStudy);
AddNewSubjectServlet.saveFieldNotes(INPUT_ENDDATE_PREFIX, fdn, dndao, studyEvent.getId(), "studyEvent", currentStudy);
session.removeAttribute("eventSigned");
request.setAttribute("id", new Integer(studySubjectId).toString());
addPageMessage(respage.getString("study_event_updated"));
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
} else {
request.setAttribute(STUDY_SUBJECT_ID, new Integer(studySubjectId).toString());
request.setAttribute("studyEvent", seb);
// -------------------
ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean ssb = (StudySubjectBean) ssdao.findByPK(studyEvent.getStudySubjectId());
// prepare to figure out what the display should look like
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ArrayList<EventCRFBean> eventCRFs = ecdao.findAllByStudyEvent(studyEvent);
ArrayList<Boolean> doRuleSetsExist = new ArrayList<Boolean>();
RuleSetDAO ruleSetDao = new RuleSetDAO(sm.getDataSource());
StudyBean study = (StudyBean) sdao.findByPK(ssb.getStudyId());
ArrayList eventDefinitionCRFs = (ArrayList) edcdao.findAllActiveByEventDefinitionId(study, studyEvent.getStudyEventDefinitionId());
ArrayList uncompletedEventDefinitionCRFs = getUncompletedCRFs(eventDefinitionCRFs, eventCRFs);
populateUncompletedCRFsWithCRFAndVersions(uncompletedEventDefinitionCRFs);
ArrayList displayEventCRFs = ViewStudySubjectServlet.getDisplayEventCRFs(sm.getDataSource(), eventCRFs, eventDefinitionCRFs, ub, currentRole, studyEvent.getSubjectEventStatus(), study);
request.setAttribute("studySubject", ssb);
request.setAttribute("uncompletedEventDefinitionCRFs", uncompletedEventDefinitionCRFs);
request.setAttribute("displayEventCRFs", displayEventCRFs);
// ------------------
request.setAttribute("studyEvent", session.getAttribute("eventSigned"));
addPageMessage(restext.getString("password_match"));
forwardPage(Page.UPDATE_STUDY_EVENT_SIGNED);
}
} else {
logger.debug("no action, go to update page");
DiscrepancyNoteDAO discrepancyNoteDAO = new DiscrepancyNoteDAO(sm.getDataSource());
StudySubjectBean studySubjectBean = (StudySubjectBean) ssdao.findByPK(studyEvent.getStudySubjectId());
int studyId = studySubjectBean.getStudyId();
boolean subjectStudyIsCurrentStudy = studyId == currentStudy.getId();
boolean isParentStudy = studyBean.getParentStudyId() < 1;
ArrayList<DiscrepancyNoteBean> allNotesforSubjectAndEvent = new ArrayList<DiscrepancyNoteBean>();
if (subjectStudyIsCurrentStudy && isParentStudy) {
allNotesforSubjectAndEvent = discrepancyNoteDAO.findAllStudyEventByStudyAndId(currentStudy, studySubjectBean.getId());
} else {
// findAllStudyEventByStudiesAndSubjectId
if (!isParentStudy) {
StudyBean stParent = (StudyBean) sdao.findByPK(studyBean.getParentStudyId());
allNotesforSubjectAndEvent = discrepancyNoteDAO.findAllStudyEventByStudiesAndSubjectId(stParent, studyBean, studySubjectBean.getId());
} else {
allNotesforSubjectAndEvent = discrepancyNoteDAO.findAllStudyEventByStudiesAndSubjectId(currentStudy, studyBean, studySubjectBean.getId());
}
}
if (!allNotesforSubjectAndEvent.isEmpty()) {
setRequestAttributesForNotes(allNotesforSubjectAndEvent);
}
HashMap presetValues = new HashMap();
// YW 08-17-2007 <<
if (studyEvent.getStartTimeFlag() == true) {
Calendar c = new GregorianCalendar();
c.setTime(studyEvent.getDateStarted());
presetValues.put(INPUT_STARTDATE_PREFIX + "Hour", new Integer(c.get(Calendar.HOUR_OF_DAY)));
presetValues.put(INPUT_STARTDATE_PREFIX + "Minute", new Integer(c.get(Calendar.MINUTE)));
// necessary.
switch(c.get(Calendar.AM_PM)) {
case 0:
presetValues.put(INPUT_STARTDATE_PREFIX + "Half", "am");
break;
case 1:
presetValues.put(INPUT_STARTDATE_PREFIX + "Half", "pm");
break;
default:
presetValues.put(INPUT_STARTDATE_PREFIX + "Half", "");
break;
}
} else {
presetValues.put(INPUT_STARTDATE_PREFIX + "Hour", new Integer(-1));
presetValues.put(INPUT_STARTDATE_PREFIX + "Minute", new Integer(-1));
presetValues.put(INPUT_STARTDATE_PREFIX + "Half", "");
}
// YW >>
String dateValue = local_df.format(studyEvent.getDateStarted());
presetValues.put(INPUT_STARTDATE_PREFIX + "Date", dateValue);
// YW 3-12-2008, add end datetime for 2220 fix<<
presetValues.put(INPUT_ENDDATE_PREFIX + "Hour", new Integer(-1));
presetValues.put(INPUT_ENDDATE_PREFIX + "Minute", new Integer(-1));
presetValues.put(INPUT_ENDDATE_PREFIX + "Half", "");
if (studyEvent.getDateEnded() != null) {
if (studyEvent.getEndTimeFlag() == true) {
Calendar c = new GregorianCalendar();
c.setTime(studyEvent.getDateEnded());
presetValues.put(INPUT_ENDDATE_PREFIX + "Hour", new Integer(c.get(Calendar.HOUR_OF_DAY)));
presetValues.put(INPUT_ENDDATE_PREFIX + "Minute", new Integer(c.get(Calendar.MINUTE)));
// necessary.
switch(c.get(Calendar.AM_PM)) {
case 0:
presetValues.put(INPUT_ENDDATE_PREFIX + "Half", "am");
break;
case 1:
presetValues.put(INPUT_ENDDATE_PREFIX + "Half", "pm");
break;
default:
presetValues.put(INPUT_ENDDATE_PREFIX + "Half", "");
break;
}
}
presetValues.put(INPUT_ENDDATE_PREFIX + "Date", local_df.format(studyEvent.getDateEnded()));
}
// YW >>
setPresetValues(presetValues);
request.setAttribute("studyEvent", studyEvent);
request.setAttribute("studySubject", studySubjectBean);
discNotes = new FormDiscrepancyNotes();
session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes);
forwardPage(Page.UPDATE_STUDY_EVENT);
}
// else
}
use of org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO 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