use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.
the class ViewNotesServlet method processRequest.
/*
* (non-Javadoc)
*
* @see org.akaza.openclinica.control.core.SecureController#processRequest()
*/
@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");
}
}
FormProcessor fp = new FormProcessor(request);
if (fp.getString("showMoreLink").equals("")) {
showMoreLink = true;
} else {
showMoreLink = Boolean.parseBoolean(fp.getString("showMoreLink"));
}
int oneSubjectId = fp.getInt("id");
// BWP 11/03/2008 3029: This session attribute in removed in
// ResolveDiscrepancyServlet.mayProceed() >>
session.setAttribute("subjectId", oneSubjectId);
// >>
int resolutionStatusSubj = fp.getInt(RESOLUTION_STATUS);
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);
boolean removeSession = fp.getBoolean("removeSession");
// BWP 11/03/2008 3029: This session attribute in removed in
// ResolveDiscrepancyServlet.mayProceed() >>
session.setAttribute("module", module);
// >>
// Do we only want to view the notes for 1 subject?
String viewForOne = fp.getString("viewForOne");
boolean isForOneSubjectsNotes = "y".equalsIgnoreCase(viewForOne);
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
StudyDAO studyDAO = new StudyDAO(sm.getDataSource());
dndao.setFetchMapping(true);
int resolutionStatus = 0;
try {
resolutionStatus = Integer.parseInt(request.getParameter("resolutionStatus"));
} catch (NumberFormatException nfe) {
// Show all DN's
resolutionStatus = -1;
}
if (removeSession) {
session.removeAttribute(WIN_LOCATION);
session.removeAttribute(NOTES_TABLE);
}
// after resolving a note, user wants to go back to view notes page, we
// save the current URL
// so we can go back later
session.setAttribute(WIN_LOCATION, "ViewNotes?viewForOne=" + viewForOne + "&id=" + oneSubjectId + "&module=" + module + " &removeSession=1");
boolean hasAResolutionStatus = resolutionStatus >= 1 && resolutionStatus <= 6;
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);
}
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
StudyDAO studyDao = new StudyDAO(sm.getDataSource());
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
UserAccountDAO uadao = new UserAccountDAO(sm.getDataSource());
CRFVersionDAO crfVersionDao = new CRFVersionDAO(sm.getDataSource());
CRFDAO crfDao = new CRFDAO(sm.getDataSource());
StudyEventDAO studyEventDao = new StudyEventDAO(sm.getDataSource());
StudyEventDefinitionDAO studyEventDefinitionDao = new StudyEventDefinitionDAO(sm.getDataSource());
EventDefinitionCRFDAO eventDefinitionCRFDao = new EventDefinitionCRFDAO(sm.getDataSource());
ItemDataDAO itemDataDao = new ItemDataDAO(sm.getDataSource());
ItemDAO itemDao = new ItemDAO(sm.getDataSource());
EventCRFDAO eventCRFDao = new EventCRFDAO(sm.getDataSource());
ListNotesTableFactory factory = new ListNotesTableFactory(showMoreLink);
factory.setSubjectDao(sdao);
factory.setStudySubjectDao(subdao);
factory.setUserAccountDao(uadao);
factory.setStudyDao(studyDao);
factory.setCurrentStudy(currentStudy);
factory.setDiscrepancyNoteDao(dndao);
factory.setCrfDao(crfDao);
factory.setCrfVersionDao(crfVersionDao);
factory.setStudyEventDao(studyEventDao);
factory.setStudyEventDefinitionDao(studyEventDefinitionDao);
factory.setEventDefinitionCRFDao(eventDefinitionCRFDao);
factory.setItemDao(itemDao);
factory.setItemDataDao(itemDataDao);
factory.setEventCRFDao(eventCRFDao);
factory.setModule(moduleStr);
factory.setDiscNoteType(discNoteType);
factory.setResolutionStatus(resolutionStatus);
factory.setViewNotesService(resolveViewNotesService());
// factory.setResolutionStatusIds(resolutionStatusIds);
TableFacade tf = factory.createTable(request, response);
Map<String, Map<String, String>> stats = generateDiscrepancyNotesSummary(factory.getNotesSummary());
Map<String, String> totalMap = generateDiscrepancyNotesTotal(stats);
int grandTotal = 0;
for (String typeName : totalMap.keySet()) {
String total = totalMap.get(typeName);
grandTotal = total.equals("--") ? grandTotal + 0 : grandTotal + Integer.parseInt(total);
}
request.setAttribute("summaryMap", stats);
tf.setTotalRows(grandTotal);
String viewNotesHtml = tf.render();
request.setAttribute("viewNotesHtml", viewNotesHtml);
String viewNotesURL = this.getPageURL();
session.setAttribute("viewNotesURL", viewNotesURL);
String viewNotesPageFileName = this.getPageServletFileName();
session.setAttribute("viewNotesPageFileName", viewNotesPageFileName);
request.setAttribute("mapKeys", ResolutionStatus.getMembers());
request.setAttribute("typeNames", DiscrepancyNoteUtil.getTypeNames());
request.setAttribute("typeKeys", totalMap);
request.setAttribute("grandTotal", grandTotal);
if ("yes".equalsIgnoreCase(fp.getString(PRINT))) {
List<DiscrepancyNoteBean> allNotes = factory.findAllNotes(tf);
request.setAttribute("allNotes", allNotes);
forwardPage(Page.VIEW_DISCREPANCY_NOTES_IN_STUDY_PRINT);
} else {
forwardPage(Page.VIEW_DISCREPANCY_NOTES_IN_STUDY);
}
}
use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.
the class SDVUtil method getSubjectRows.
/*
Generate the rows for the study table. Each row represents an Event CRF.
*/
public Collection<SubjectSDVContainer> getSubjectRows(List<EventCRFBean> eventCRFBeans, HttpServletRequest request) {
if (eventCRFBeans == null || eventCRFBeans.isEmpty()) {
return new ArrayList<SubjectSDVContainer>();
}
getEventNamesForEventCRFs(eventCRFBeans);
StudySubjectDAO studySubjectDAO = new StudySubjectDAO(dataSource);
SubjectDAO subjectDAO = new SubjectDAO(dataSource);
StudyDAO studyDAO = new StudyDAO(dataSource);
StudyEventDAO studyEventDAO = new StudyEventDAO(dataSource);
EventDefinitionCRFDAO eventDefinitionCRFDAO = new EventDefinitionCRFDAO(dataSource);
StudySubjectBean studySubjectBean = null;
SubjectBean subjectBean = null;
StudyEventBean studyEventBean = null;
StudyBean studyBean = null;
EventDefinitionCRFBean eventDefinitionCRFBean = null;
Collection<SubjectSDVContainer> allRows = new ArrayList<SubjectSDVContainer>();
SubjectSDVContainer tempSDVBean = null;
StringBuilder actions = new StringBuilder("");
for (EventCRFBean crfBean : eventCRFBeans) {
tempSDVBean = new SubjectSDVContainer();
studySubjectBean = (StudySubjectBean) studySubjectDAO.findByPK(crfBean.getStudySubjectId());
studyEventBean = (StudyEventBean) studyEventDAO.findByPK(crfBean.getStudyEventId());
subjectBean = (SubjectBean) subjectDAO.findByPK(studySubjectBean.getSubjectId());
//find out the study's identifier
studyBean = (StudyBean) studyDAO.findByPK(studySubjectBean.getStudyId());
tempSDVBean.setStudyIdentifier(studyBean.getIdentifier());
eventDefinitionCRFBean = eventDefinitionCRFDAO.findByStudyEventIdAndCRFVersionId(studyBean, studyEventBean.getId(), crfBean.getCRFVersionId());
SourceDataVerification sourceData = eventDefinitionCRFBean.getSourceDataVerification();
if (sourceData != null) {
tempSDVBean.setSdvRequirementDefinition(sourceData.toString());
} else {
tempSDVBean.setSdvRequirementDefinition("");
}
tempSDVBean.setCrfNameVersion(getCRFName(crfBean.getCRFVersionId()) + "/ " + getCRFVersionName(crfBean.getCRFVersionId()));
if (crfBean.getStatus() != null) {
Integer status = crfBean.getStage().getId();
if (studyEventBean.getSubjectEventStatus() == SubjectEventStatus.LOCKED || studyEventBean.getSubjectEventStatus() == SubjectEventStatus.STOPPED || studyEventBean.getSubjectEventStatus() == SubjectEventStatus.SKIPPED) {
status = DataEntryStage.LOCKED.getId();
}
tempSDVBean.setCrfStatus(getCRFStatusIconPath(status, request, studySubjectBean.getId(), crfBean.getId(), crfBean.getCRFVersionId()));
}
tempSDVBean.setStudyEventStatus(studyEventBean.getStatus().getName());
//TODO: I18N Date must be formatted properly
Locale locale = LocaleResolver.getLocale(request);
SimpleDateFormat sdformat = I18nFormatUtil.getDateFormat(locale);
if (studySubjectBean.getEnrollmentDate() != null) {
tempSDVBean.setEnrollmentDate(sdformat.format(studySubjectBean.getEnrollmentDate()));
} else {
//tempSDVBean.setEnrollmentDate("unknown");
}
//TODO: I18N Date must be formatted properly
//Fix OC 1888
StudyEventDAO sedao = new StudyEventDAO(dataSource);
StudyEventBean seBean = (StudyEventBean) sedao.findByPK(crfBean.getStudyEventId());
tempSDVBean.setEventDate(sdformat.format(seBean.getDateStarted()));
// if (crfBean.getCreatedDate() != null) {
// tempSDVBean.setEventDate(sdformat.format(crfBean.getCreatedDate()));
// } else {
// //tempSDVBean.setEventDate("unknown");
//
// }
//crfBean.getEventName()
tempSDVBean.setEventName(crfBean.getEventName());
//The checkbox is next to the study subject id
StringBuilder sdvStatus = new StringBuilder("");
//"This Event CRF has been Source Data Verified. If you uncheck this box, you are removing Source Data Verification for the Event CRF and you will have to repeat the process. Select OK to continue and Cancel to cancel this transaction."
if (crfBean.isSdvStatus()) {
sdvStatus.append("<center><a href='javascript:void(0)' onclick='prompt(document.sdvForm,");
sdvStatus.append(crfBean.getId());
sdvStatus.append(")'>");
sdvStatus.append(getIconForSdvStatusPrefix()).append("DoubleCheck").append(ICON_FORCRFSTATUS_SUFFIX).append("</a></center>");
} else {
sdvStatus.append("<center><input style='margin-right: 5px' type='checkbox' ").append("class='sdvCheck'").append(" name='").append(CHECKBOX_NAME).append(crfBean.getId()).append("' /></center>");
}
//sdvStatus.append(studySubjectBean.getLabel());
tempSDVBean.setSdvStatus(sdvStatus.toString());
tempSDVBean.setStudySubjectId(studySubjectBean.getLabel());
if (subjectBean != null) {
tempSDVBean.setPersonId(subjectBean.getUniqueIdentifier());
} else {
tempSDVBean.setPersonId("");
}
//studySubjectBean.getSecondaryLabel()
tempSDVBean.setSecondaryId(studySubjectBean.getSecondaryLabel());
String statusName = studySubjectBean.getStatus().getName();
int statusId = studySubjectBean.getStatus().getId();
if (statusName != null) {
tempSDVBean.setStudySubjectStatus(statusName);
}
//TODO: I18N Date must be formatted properly
if (crfBean.getUpdatedDate() != null) {
tempSDVBean.setLastUpdatedDate(sdformat.format(crfBean.getUpdatedDate()));
} else {
tempSDVBean.setLastUpdatedDate("unknown");
}
if (crfBean.getUpdater() != null) {
tempSDVBean.setLastUpdatedBy(crfBean.getUpdater().getFirstName() + " " + crfBean.getUpdater().getLastName());
}
actions = new StringBuilder("");
//append("<input type='hidden' name='crfId' value='").append(crfBean.getId()).append("'").append("/> ")
if (!crfBean.isSdvStatus()) {
StringBuilder jsCodeString = new StringBuilder("this.form.method='GET'; this.form.action='").append(request.getContextPath()).append("/pages/handleSDVGet").append("';").append("this.form.crfId.value='").append(crfBean.getId()).append("';").append("this.form.submit();");
actions.append("<input type=\"submit\" class=\"button_medium\" value=\"SDV\" name=\"sdvSubmit\" ").append("onclick=\"").append(jsCodeString.toString()).append("\" />");
}
//Only implement the view icon if it is a event crf request
/*String bool = (String) request.getAttribute("isViewSubjectRequest");
if(! "y".equalsIgnoreCase(bool)){
StringBuilder urlPrefix = new StringBuilder("<a href='javascript:void(0)' onclick=\"document.location.href='");
StringBuilder path = new StringBuilder(request.getContextPath()).append("/pages/viewAllSubjectSDV?studyId=").append(studySubjectBean.getStudyId()).append("&studySubjectId=");
path.append(studySubjectBean.getId());
urlPrefix.append(path).append("'\">");
actions.append(" ").append(urlPrefix).append(VIEW_ICON_HTML).append("</a>");
}*/
tempSDVBean.setSdvStatusActions(actions.toString());
allRows.add(tempSDVBean);
}
return allRows;
}
use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.
the class SDVUtil method getTotalRowCountSubjects.
public int getTotalRowCountSubjects(FilterSet filterSet, int studyId, int studySubjectId) {
EventCRFDAO eventCRFDAO = new EventCRFDAO(dataSource);
if (filterSet.getFilters().size() == 0) {
return eventCRFDAO.countEventCRFsByStudySubject(studySubjectId, studyId, studyId);
}
int count = 0;
//Filter for study subject label
StudySubjectDAO studySubjectDAO = new StudySubjectDAO(dataSource);
StudySubjectBean studySubjectBean = new StudySubjectBean();
studySubjectBean = (StudySubjectBean) studySubjectDAO.findByPK(studySubjectId);
String label = studySubjectBean.getLabel();
String eventNameValue = "";
String eventDateValue = "";
String crfStatus = "";
String sdvStatus = "";
for (Filter filter : filterSet.getFilters()) {
if (filter.getProperty().equalsIgnoreCase("eventName")) {
eventNameValue = filter.getValue();
continue;
}
if (filter.getProperty().equalsIgnoreCase("eventDate")) {
eventDateValue = filter.getValue();
continue;
}
if (filter.getProperty().equalsIgnoreCase("crfStatus")) {
crfStatus = filter.getValue();
continue;
}
if (filter.getProperty().equalsIgnoreCase("sdvStatusActions")) {
sdvStatus = filter.getValue();
}
}
if (eventNameValue.length() > 0) {
return eventCRFDAO.countEventCRFsByEventNameSubjectLabel(eventNameValue, label);
}
if (eventDateValue.length() > 0) {
//return eventCRFDAO.countEventCRFsByEventDate(studyId,eventDateValue);
}
if (crfStatus.length() > 0) {
//return eventCRFDAO.countEventCRFsByCRFStatus(studyId,
// SubjectEventStatus.getSubjectEventStatusIdByName(crfStatus));
}
if (sdvStatus.length() > 0) {
// return eventCRFDAO.countEventCRFsByStudySDV(studyId,
// ("complete".equalsIgnoreCase(sdvStatus)));
}
return eventCRFDAO.countEventCRFsByStudySubject(studySubjectId, studyId, studyId);
}
use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.
the class ODMClinicaDataResource method getStudySubjectOID.
/**
* This function checks to see whether the supplied subject identifier is a Study Subject OID or a Study Subject ID.
* If a valid Study Subject OID or wildcard (*) is supplied, just return it.
* If a Study Subject ID is supplied, a lookup is done to get the Study Subject OID and return that.
*/
private String getStudySubjectOID(String subjectIdentifier, String studyOID) {
StudySubjectDAO studySubjectDAO = new StudySubjectDAO(getDataSource());
StudySubjectBean studySubject = studySubjectDAO.findByOid(subjectIdentifier);
if (subjectIdentifier.equals("*") || (studySubject != null && studySubject.getOid() != null))
return subjectIdentifier;
else {
StudyDAO studyDAO = new StudyDAO(getDataSource());
StudyBean study = studyDAO.findByOid(studyOID);
studySubject = studySubjectDAO.findByLabelAndStudy(subjectIdentifier, study);
if (studySubject != null && studySubject.getOid() != null)
return studySubject.getOid();
else
return subjectIdentifier;
}
}
use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.
the class SDVUtil method setSDVStatusForStudySubjects.
public boolean setSDVStatusForStudySubjects(List<Integer> studySubjectIds, int userId, boolean setVerification) {
EventCRFDAO eventCRFDAO = new EventCRFDAO(dataSource);
StudySubjectDAO studySubjectDAO = new StudySubjectDAO(dataSource);
EventDefinitionCRFDAO eventDefinitionCrfDAO = new EventDefinitionCRFDAO(dataSource);
StudyEventDAO studyEventDAO = new StudyEventDAO(dataSource);
CRFDAO crfDAO = new CRFDAO(dataSource);
if (studySubjectIds == null || studySubjectIds.isEmpty()) {
return true;
}
for (Integer studySubjectId : studySubjectIds) {
ArrayList<EventCRFBean> eventCrfs = eventCRFDAO.getEventCRFsByStudySubjectCompleteOrLocked(studySubjectId);
StudySubjectBean studySubject = (StudySubjectBean) studySubjectDAO.findByPK(studySubjectId);
for (EventCRFBean eventCRFBean : eventCrfs) {
CRFBean crfBean = crfDAO.findByVersionId(eventCRFBean.getCRFVersionId());
StudyEventBean studyEvent = (StudyEventBean) studyEventDAO.findByPK(eventCRFBean.getStudyEventId());
EventDefinitionCRFBean eventDefinitionCrf = eventDefinitionCrfDAO.findByStudyEventDefinitionIdAndCRFIdAndStudyId(studyEvent.getStudyEventDefinitionId(), crfBean.getId(), studySubject.getStudyId());
if (eventDefinitionCrf.getId() == 0) {
eventDefinitionCrf = eventDefinitionCrfDAO.findForStudyByStudyEventDefinitionIdAndCRFId(studyEvent.getStudyEventDefinitionId(), crfBean.getId());
}
if (eventDefinitionCrf.getSourceDataVerification() == SourceDataVerification.AllREQUIRED || eventDefinitionCrf.getSourceDataVerification() == SourceDataVerification.PARTIALREQUIRED) {
try {
eventCRFDAO.setSDVStatus(setVerification, userId, eventCRFBean.getId());
} catch (Exception exc) {
// System.out.println(exc.getMessage());
return false;
}
}
}
studySubjectDAO.update(studySubject);
}
return true;
}
Aggregations