use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.
the class PrintDataEntryServlet method processRequest.
@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
FormProcessor fp = new FormProcessor(request);
boolean isSubmitted = false;
int eventCRFId = fp.getInt("ecId");
//JN:The following were the the global variables, moved as local.
EventCRFBean ecb;
SectionDAO sdao = new SectionDAO(getDataSource());
ArrayList<SectionBean> allSectionBeans = new ArrayList<SectionBean>();
ArrayList sectionBeans = new ArrayList();
String age = "";
StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
// Whether IE6 or IE7 is involved
String isIE = fp.getString("ie");
if ("y".equalsIgnoreCase(isIE)) {
request.setAttribute("isInternetExplorer", "true");
}
if (eventCRFId == 0) {
ecb = new EventCRFBean();
// super.ecb.setCRFVersionId(sb.getCRFVersionId());
} else {
EventCRFDAO ecdao = new EventCRFDAO(getDataSource());
ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
// Get all the SectionBeans attached to this ECB
ArrayList sects = sdao.findAllByCRFVersionId(ecb.getCRFVersionId());
for (int i = 0; i < sects.size(); i++) {
sb = (SectionBean) sects.get(i);
// super.sb = sb;
int sectId = sb.getId();
if (sectId > 0) {
allSectionBeans.add((SectionBean) sdao.findByPK(sectId));
}
}
// 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);
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);
// Let us process the age
if (currentStudy.getStudyParameterConfig().getCollectDob().equals("1")) {
// 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() + " - " + study.getName());
} else {
request.setAttribute("studyTitle", study.getName());
}
request.setAttribute("studySubject", sub);
request.setAttribute("subject", subject);
request.setAttribute("studyEvent", se);
request.setAttribute("age", age);
request.setAttribute(INPUT_EVENT_CRF, ecb);
request.setAttribute(SECTION_BEAN, sb);
request.setAttribute(ALL_SECTION_BEANS, allSectionBeans);
// Get the section beans from super
sectionBeans = super.getAllDisplayBeans(request);
}
// Find out whether the sections involve groups
ItemGroupDAO itemGroupDao = new ItemGroupDAO(getDataSource());
// Find truely grouped tables, not groups with a name of 'Ungrouped'
// CRF VERSION ID WILL BE 0 IF "ecId" IS NOT IN THE QUERYSTRING
int crfVersionId = ecb.getCRFVersionId();
List<ItemGroupBean> itemGroupBeans = itemGroupDao.findOnlyGroupsByCRFVersionID(crfVersionId);
boolean sectionsHaveGroups = false;
if (itemGroupBeans.size() > 0) {
sectionsHaveGroups = true;
// get a DisplaySectionBean for each section of the CRF, sort them,
// then
// dispatch the request to a print JSP. the constructor for this
// handler takes
// a boolean value depending on whether an event or data is involved
// or not
DisplaySectionBeanHandler handler = new DisplaySectionBeanHandler(true, getDataSource(), getServletContext());
handler.setCrfVersionId(crfVersionId);
handler.setEventCRFId(eventCRFId);
List<DisplaySectionBean> displaySectionBeans = handler.getDisplaySectionBeans();
CRFVersionDAO crfVersionDAO = new CRFVersionDAO(getDataSource());
CRFDAO crfDao = new CRFDAO(getDataSource());
request.setAttribute("listOfDisplaySectionBeans", displaySectionBeans);
// Make available the CRF names and versions for
// the web page's header
CRFVersionBean crfverBean = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionId);
request.setAttribute("crfVersionBean", crfverBean);
CRFBean crfBean = crfDao.findByVersionId(crfVersionId);
request.setAttribute("crfBean", crfBean);
// Set an attribute signaling that an event and/or data is involved
request.setAttribute("dataInvolved", "true");
}
request.setAttribute(BEAN_ANNOTATIONS, ecb.getAnnotations());
request.setAttribute("EventCRFBean", ecb);
// We do not need most of these attributes if groups are involved
if (!sectionsHaveGroups) {
request.setAttribute(INPUT_EVENT_CRF, ecb);
request.setAttribute(SECTION_BEAN, sb);
DisplaySectionBean dsb = super.getDisplayBean(false, false, request, isSubmitted);
request.setAttribute("allSections", sectionBeans);
request.setAttribute("displayAll", "1");
request.setAttribute(BEAN_DISPLAY, dsb);
request.setAttribute("sec", sb);
forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PRINT, request, response);
} else {
// end if(! sectionsHaveGroups)
forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PRINT_GROUPS, request, response);
}
}
use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.
the class RestoreStudyEventServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
// studyEventId
int studyEventId = fp.getInt("id");
// studySubjectId
int studySubId = fp.getInt("studySubId");
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
if (studyEventId == 0) {
addPageMessage(respage.getString("please_choose_a_SE_to_restore"));
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
} else {
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
// YW 11-07-2007, a study event could not be restored if its study
// subject has been removed
Status s = studySub.getStatus();
if ("removed".equalsIgnoreCase(s.getName()) || "auto-removed".equalsIgnoreCase(s.getName())) {
addPageMessage(resword.getString("study_event") + resterm.getString("could_not_be") + resterm.getString("restored") + "." + respage.getString("study_subject_has_been_deleted"));
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
}
// YW
StudyEventBean event = (StudyEventBean) sedao.findByPK(studyEventId);
request.setAttribute("studySub", studySub);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(event.getStudyEventDefinitionId());
event.setStudyEventDefinition(sed);
StudyDAO studydao = new StudyDAO(sm.getDataSource());
StudyBean study = (StudyBean) studydao.findByPK(studySub.getStudyId());
request.setAttribute("study", study);
String action = request.getParameter("action");
if ("confirm".equalsIgnoreCase(action)) {
if (event.getStatus().equals(Status.AVAILABLE)) {
addPageMessage(respage.getString("this_event_is_already_available_for_study") + " " + respage.getString("please_contact_sysadmin_for_more_information"));
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
return;
}
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
// find all crfs in the definition
ArrayList eventDefinitionCRFs = (ArrayList) edcdao.findAllByEventDefinitionId(study, sed.getId());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
// construct info needed on view study event page
DisplayStudyEventBean de = new DisplayStudyEventBean();
de.setStudyEvent(event);
de.setDisplayEventCRFs(getDisplayEventCRFs(eventCRFs, eventDefinitionCRFs));
request.setAttribute("displayEvent", de);
forwardPage(Page.RESTORE_STUDY_EVENT);
} else {
logger.info("submit to restore the event to study");
// restore event to study
event.setStatus(Status.AVAILABLE);
event.setUpdater(ub);
event.setUpdatedDate(new Date());
sedao.update(event);
// restore event crfs
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
for (int k = 0; k < eventCRFs.size(); k++) {
EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
if (eventCRF.getStatus().equals(Status.AUTO_DELETED)) {
eventCRF.setStatus(Status.AVAILABLE);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
// remove all the item data
ArrayList itemDatas = iddao.findAllByEventCRFId(eventCRF.getId());
for (int a = 0; a < itemDatas.size(); a++) {
ItemDataBean item = (ItemDataBean) itemDatas.get(a);
if (item.getStatus().equals(Status.AUTO_DELETED)) {
item.setStatus(Status.AVAILABLE);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
String emailBody = respage.getString("the_event") + event.getStudyEventDefinition().getName() + " " + respage.getString("has_been_restored_to_the_study") + " " + study.getName() + ".";
addPageMessage(emailBody);
// sendEmail(emailBody);
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
}
}
}
use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.
the class RestoreStudySubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
// studySubjectId
String studySubIdString = request.getParameter("id");
String subIdString = request.getParameter("subjectId");
String studyIdString = request.getParameter("studyId");
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
if (StringUtil.isBlank(studySubIdString) || StringUtil.isBlank(subIdString) || StringUtil.isBlank(studyIdString)) {
addPageMessage(respage.getString("please_choose_study_subject_to_restore"));
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
} else {
int studyId = Integer.valueOf(studyIdString.trim()).intValue();
int studySubId = Integer.valueOf(studySubIdString.trim()).intValue();
int subjectId = Integer.valueOf(subIdString.trim()).intValue();
SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId);
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
StudyDAO studydao = new StudyDAO(sm.getDataSource());
StudyBean study = (StudyBean) studydao.findByPK(studyId);
// find study events
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
// ArrayList events = sedao.findAllByStudyAndStudySubjectId(study, studySubId);
ArrayList<DisplayStudyEventBean> displayEvents = ViewStudySubjectServlet.getDisplayStudyEventsForStudySubject(studySub, sm.getDataSource(), ub, currentRole);
String action = request.getParameter("action");
if ("confirm".equalsIgnoreCase(action)) {
if (studySub.getStatus().equals(Status.AVAILABLE)) {
addPageMessage(respage.getString("this_subject_is_already_available_for_study") + " " + respage.getString("please_contact_sysadmin_for_more_information"));
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
return;
}
request.setAttribute("subject", subject);
request.setAttribute("study", study);
request.setAttribute("studySub", studySub);
request.setAttribute("events", displayEvents);
forwardPage(Page.RESTORE_STUDY_SUBJECT);
} else {
logger.info("submit to restore the subject from study");
// restore subject from study
studySub.setStatus(Status.AVAILABLE);
studySub.setUpdater(ub);
studySub.setUpdatedDate(new Date());
subdao.update(studySub);
// restore all study events
// restore all event crfs
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
for (int j = 0; j < displayEvents.size(); j++) {
DisplayStudyEventBean dispEvent = displayEvents.get(j);
StudyEventBean event = dispEvent.getStudyEvent();
if (event.getStatus().equals(Status.AUTO_DELETED)) {
event.setStatus(Status.AVAILABLE);
event.setUpdater(ub);
event.setUpdatedDate(new Date());
sedao.update(event);
}
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
for (int k = 0; k < eventCRFs.size(); k++) {
EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
if (eventCRF.getStatus().equals(Status.AUTO_DELETED)) {
eventCRF.setStatus(Status.AVAILABLE);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
// remove all the item data
ArrayList itemDatas = iddao.findAllByEventCRFId(eventCRF.getId());
for (int a = 0; a < itemDatas.size(); a++) {
ItemDataBean item = (ItemDataBean) itemDatas.get(a);
if (item.getStatus().equals(Status.AUTO_DELETED)) {
item.setStatus(Status.AVAILABLE);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
}
String emailBody = respage.getString("the_subject") + " " + subject.getName() + " " + respage.getString("has_been_restored_to_the_study") + " " + study.getName() + ".";
addPageMessage(emailBody);
// try{
// sendEmail(emailBody);
// }catch (Exception ex){
// addPageMessage(respage.getString("mail_cannot_be_sent_to_admin"));
// }
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
}
}
}
use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.
the class SDVController method renderSubjectsTable.
/*
Create a JMesa-based table for showing the event CRFs.
*/
private String renderSubjectsTable(List<EventCRFBean> eventCRFBeans, int studySubjectId, HttpServletRequest request) {
StudySubjectDAO studySubjectDAO = new StudySubjectDAO(dataSource);
StudySubjectBean subjectBean = (StudySubjectBean) studySubjectDAO.findByPK(studySubjectId);
Collection<SubjectSDVContainer> items = sdvUtil.getSubjectRows(eventCRFBeans, request);
//The number of items represents the total number of returned rows
int totalRowCount = 0;
if (items != null && items.size() > 0) {
totalRowCount = items.size();
}
TableFacade tableFacade = createTableFacade("sdv", request);
//set to the total row count
if (totalRowCount > 1) {
tableFacade.setMaxRowsIncrements(15, 50, totalRowCount);
}
tableFacade.setColumnProperties("studySubjectId", "personId", "secondaryId", "eventName", "eventDate", "enrollmentDate", "subjectStatus", "crfNameVersion", "crfStatus", "lastUpdatedDate", "lastUpdatedBy", "sdvStatusActions");
tableFacade.setItems(items);
//Fix column titles
HtmlTable table = (HtmlTable) tableFacade.getTable();
//i18n caption; TODO: convert to Spring messages
ResourceBundle resourceBundle = ResourceBundle.getBundle("org.akaza.openclinica.i18n.words", LocaleResolver.getLocale(request));
String[] allTitles = { resourceBundle.getString("study_subject_ID"), resourceBundle.getString("person_ID"), resourceBundle.getString("secondary_ID"), resourceBundle.getString("event_name"), resourceBundle.getString("event_date"), resourceBundle.getString("enrollment_date"), resourceBundle.getString("subject_status"), resourceBundle.getString("CRF_name") + " / " + resourceBundle.getString("version"), resourceBundle.getString("CRF_status"), resourceBundle.getString("last_updated_date"), resourceBundle.getString("last_updated_by"), resourceBundle.getString("SDV_status") + " / " + resourceBundle.getString("actions") };
setTitles(allTitles, table);
table.getTableRenderer().setWidth("800");
return tableFacade.render();
}
use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.
the class ImportSpringJob method createDiscrepancyNote.
public static DiscrepancyNoteBean createDiscrepancyNote(ItemBean itemBean, String message, EventCRFBean eventCrfBean, DisplayItemBean displayItemBean, Integer parentId, UserAccountBean uab, DataSource ds, StudyBean study) {
// DisplayItemBean displayItemBean) {
DiscrepancyNoteBean note = new DiscrepancyNoteBean();
StudySubjectDAO ssdao = new StudySubjectDAO(ds);
note.setDescription(message);
note.setDetailedNotes("Failed Validation Check");
note.setOwner(uab);
note.setCreatedDate(new Date());
note.setResolutionStatusId(ResolutionStatus.OPEN.getId());
note.setDiscrepancyNoteTypeId(DiscrepancyNoteType.FAILEDVAL.getId());
if (parentId != null) {
note.setParentDnId(parentId);
}
note.setField(itemBean.getName());
note.setStudyId(study.getId());
note.setEntityName(itemBean.getName());
note.setEntityType(DiscrepancyNoteBean.ITEM_DATA);
note.setEntityValue(displayItemBean.getData().getValue());
note.setEventName(eventCrfBean.getName());
note.setEventStart(eventCrfBean.getCreatedDate());
note.setCrfName(displayItemBean.getEventDefinitionCRF().getCrfName());
StudySubjectBean ss = (StudySubjectBean) ssdao.findByPK(eventCrfBean.getStudySubjectId());
note.setSubjectName(ss.getName());
note.setEntityId(displayItemBean.getData().getId());
note.setColumn("value");
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(ds);
note = (DiscrepancyNoteBean) dndao.create(note);
// so that the below method works, need to set the entity above
// System.out.println("trying to create mapping with " + note.getId() +
// " " + note.getEntityId() + " " + note.getColumn() + " " +
// note.getEntityType());
dndao.createMapping(note);
return note;
}
Aggregations