use of org.akaza.openclinica.dao.managestudy.StudyDAO in project OpenClinica by OpenClinica.
the class DownloadAttachedFileServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
String filePathName = "";
String fileName = fp.getString("fileName");
File f = new File(fileName);
if (fileName != null && fileName.length() > 0) {
int parentStudyId = currentStudy.getParentStudyId();
String testPath = Utils.getAttachedFileRootPath();
String tail = File.separator + f.getName();
String testName = testPath + currentStudy.getOid() + tail;
File temp = new File(testName);
if (temp.exists()) {
filePathName = testName;
logger.info(currentStudy.getName() + " existing filePathName=" + filePathName);
} else {
if (currentStudy.isSite(parentStudyId)) {
testName = testPath + ((StudyBean) new StudyDAO(sm.getDataSource()).findByPK(parentStudyId)).getOid() + tail;
temp = new File(testName);
if (temp.exists()) {
filePathName = testName;
logger.info("parent existing filePathName=" + filePathName);
}
} else {
ArrayList<StudyBean> sites = (ArrayList<StudyBean>) new StudyDAO(sm.getDataSource()).findAllByParent(currentStudy.getId());
for (StudyBean s : sites) {
testPath = Utils.getAttachedFilePath(s);
// + s.getIdentifier() + tail;
testName = testPath + tail;
File test = new File(testName);
if (test.exists()) {
filePathName = testName;
logger.info("site of currentStudy existing filePathName=" + filePathName);
break;
}
}
}
}
}
logger.info("filePathName=" + filePathName + " fileName=" + fileName);
File file = new File(filePathName);
if (!file.exists() || file.length() <= 0) {
addPageMessage("File " + filePathName + " " + respage.getString("not_exist"));
// try to use the passed in the existing file
file = new File(fileName);
}
if (!file.exists() || file.length() <= 0) {
addPageMessage("File " + filePathName + " " + respage.getString("not_exist"));
} else {
// response.setContentType("application/octet-stream");
response.setHeader("Content-disposition", "attachment; filename=\"" + fileName + "\";");
response.setHeader("Pragma", "public");
ServletOutputStream outStream = response.getOutputStream();
DataInputStream inStream = null;
try {
response.setContentType("application/download");
response.setHeader("Cache-Control", "max-age=0");
response.setContentLength((int) file.length());
byte[] bbuf = new byte[(int) file.length()];
inStream = new DataInputStream(new FileInputStream(file));
int length;
while (inStream != null && (length = inStream.read(bbuf)) != -1) {
outStream.write(bbuf, 0, length);
}
inStream.close();
outStream.flush();
outStream.close();
} catch (Exception ee) {
ee.printStackTrace();
} finally {
if (inStream != null) {
inStream.close();
}
if (outStream != null) {
outStream.close();
}
}
}
}
use of org.akaza.openclinica.dao.managestudy.StudyDAO in project OpenClinica by OpenClinica.
the class EnterDataForStudyEventServlet method processRequest.
/*
* (non-Javadoc)
*
* @see org.akaza.openclinica.control.core.SecureController#processRequest()
*/
@Override
protected void processRequest() throws Exception {
// removeLockedCRF(ub.getId());
getCrfLocker().unlockAllForUser(ub.getId());
FormProcessor fp = new FormProcessor(request);
int eventId = fp.getInt(INPUT_EVENT_ID, true);
request.setAttribute("eventId", eventId + "");
// so we can display the event for which we're entering data
StudyEventBean seb = getStudyEvent(eventId);
// so we can display the subject's label
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean studySubjectBean = (StudySubjectBean) ssdao.findByPK(seb.getStudySubjectId());
int studyId = studySubjectBean.getStudyId();
StudyDAO studydao = new StudyDAO(sm.getDataSource());
StudyBean study = (StudyBean) studydao.findByPK(studyId);
// 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 study event
DiscrepancyNoteDAO discrepancyNoteDAO = new DiscrepancyNoteDAO(sm.getDataSource());
ArrayList<DiscrepancyNoteBean> allNotesforSubjectAndEvent = new ArrayList<DiscrepancyNoteBean>();
// These methods return only parent disc notes
if (subjectStudyIsCurrentStudy && isParentStudy) {
allNotesforSubjectAndEvent = discrepancyNoteDAO.findAllStudyEventByStudyAndId(currentStudy, studySubjectBean.getId());
} else {
// findAllStudyEventByStudiesAndSubjectId
if (!isParentStudy) {
StudyBean stParent = (StudyBean) studydao.findByPK(study.getParentStudyId());
allNotesforSubjectAndEvent = discrepancyNoteDAO.findAllStudyEventByStudiesAndSubjectId(stParent, study, studySubjectBean.getId());
} else {
allNotesforSubjectAndEvent = discrepancyNoteDAO.findAllStudyEventByStudiesAndSubjectId(currentStudy, study, studySubjectBean.getId());
}
}
if (!allNotesforSubjectAndEvent.isEmpty()) {
setRequestAttributesForNotes(allNotesforSubjectAndEvent);
}
// prepare to figure out what the display should look like
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ArrayList<EventCRFBean> eventCRFs = ecdao.findAllByStudyEvent(seb);
ArrayList<Boolean> doRuleSetsExist = new ArrayList<Boolean>();
RuleSetDAO ruleSetDao = new RuleSetDAO(sm.getDataSource());
for (EventCRFBean eventCrfBean : eventCRFs) {
// Boolean result = ruleSetDao.findByEventCrf(eventCrfBean) != null
// ? Boolean.TRUE : Boolean.FALSE;
// doRuleSetsExist.add(result);
}
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
ArrayList eventDefinitionCRFs = (ArrayList) edcdao.findAllActiveByEventDefinitionId(study, seb.getStudyEventDefinitionId());
// get the event definition CRFs for which no event CRF exists
// the event definition CRFs must be populated with versions so we can
// let the user choose which version he will enter data for
// However, this method seems to be returning DisplayEventDefinitionCRFs
// that contain valid eventCRFs??
ArrayList uncompletedEventDefinitionCRFs = getUncompletedCRFs(eventDefinitionCRFs, eventCRFs);
populateUncompletedCRFsWithCRFAndVersions(uncompletedEventDefinitionCRFs);
// BWP 2816 << Attempt to provide the DisplayEventDefinitionCRF with a
// valid owner
// only if its container eventCRf has a valid id
populateUncompletedCRFsWithAnOwner(uncompletedEventDefinitionCRFs);
// >>BWP
// for the event definition CRFs for which event CRFs exist, get
// DisplayEventCRFBeans, which the JSP will use to determine what
// the user will see for each event CRF
// removing the below row in exchange for the ViewStudySubjectServlet
// version, for two
// reasons:
// 1. concentrate all business logic in one place
// 2. VSSS seems to handle the javascript creation correctly
// ArrayList displayEventCRFs = getDisplayEventCRFs(eventCRFs,
// eventDefinitionCRFs, seb.getSubjectEventStatus());
ArrayList displayEventCRFs = ViewStudySubjectServlet.getDisplayEventCRFs(sm.getDataSource(), eventCRFs, eventDefinitionCRFs, ub, currentRole, seb.getSubjectEventStatus(), study);
// Issue 3212 BWP << hide certain CRFs at the site level
if (currentStudy.getParentStudyId() > 0) {
HideCRFManager hideCRFManager = HideCRFManager.createHideCRFManager();
uncompletedEventDefinitionCRFs = hideCRFManager.removeHiddenEventDefinitionCRFBeans(uncompletedEventDefinitionCRFs);
displayEventCRFs = hideCRFManager.removeHiddenEventCRFBeans(displayEventCRFs);
}
// >>
request.setAttribute(BEAN_STUDY_EVENT, seb);
request.setAttribute("doRuleSetsExist", doRuleSetsExist);
request.setAttribute(BEAN_STUDY_SUBJECT, studySubjectBean);
request.setAttribute(BEAN_UNCOMPLETED_EVENTDEFINITIONCRFS, uncompletedEventDefinitionCRFs);
request.setAttribute(BEAN_DISPLAY_EVENT_CRFS, displayEventCRFs);
// @pgawade 31-Aug-2012 fix for issue #15315: Reverting to set the request variable "beans" back
// this is for generating side info panel
ArrayList beans = ViewStudySubjectServlet.getDisplayStudyEventsForStudySubject(studySubjectBean, sm.getDataSource(), ub, currentRole);
request.setAttribute("beans", beans);
EventCRFBean ecb = new EventCRFBean();
ecb.setStudyEventId(eventId);
request.setAttribute("eventCRF", ecb);
// Make available the study
request.setAttribute("study", currentStudy);
forwardPage(Page.ENTER_DATA_FOR_STUDY_EVENT);
}
use of org.akaza.openclinica.dao.managestudy.StudyDAO in project OpenClinica by OpenClinica.
the class EditFormController method getStudy.
private StudyBean getStudy(Integer id) {
sdao = new StudyDAO(dataSource);
StudyBean studyBean = (StudyBean) sdao.findByPK(id);
return studyBean;
}
use of org.akaza.openclinica.dao.managestudy.StudyDAO in project OpenClinica by OpenClinica.
the class IdtViewController method getStudy.
private StudyBean getStudy(Integer id) {
sdao = new StudyDAO(dataSource);
StudyBean studyBean = (StudyBean) sdao.findByPK(id);
return studyBean;
}
use of org.akaza.openclinica.dao.managestudy.StudyDAO in project OpenClinica by OpenClinica.
the class IdtViewController method getStudy.
private StudyBean getStudy(String oid) {
sdao = new StudyDAO(dataSource);
StudyBean studyBean = (StudyBean) sdao.findByOid(oid);
return studyBean;
}
Aggregations