use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.
the class ListEventsForSubjectTableFactory method getCrfs.
@SuppressWarnings("unchecked")
private ArrayList<CRFBean> getCrfs(StudyEventDefinitionBean eventDefinition) {
if (this.crfBeans == null) {
crfBeans = new ArrayList<CRFBean>();
eventDefinitionCrfs = new ArrayList<EventDefinitionCRFBean>();
for (EventDefinitionCRFBean eventDefinitionCrf : (List<EventDefinitionCRFBean>) getEventDefintionCRFDAO().findAllActiveByEventDefinitionId(eventDefinition.getId())) {
CRFBean crfBean = (CRFBean) getCrfDAO().findByPK(eventDefinitionCrf.getCrfId());
ArrayList<CRFVersionBean> crfVersions = (ArrayList<CRFVersionBean>) getCrfVersionDAO().findAllByCRFId(eventDefinitionCrf.getCrfId());
crfBean.setVersions(crfVersions);
if (eventDefinitionCrf.getParentId() == 0) {
crfBeans.add(crfBean);
eventDefinitionCrfs.add(eventDefinitionCrf);
}
}
return crfBeans;
}
return crfBeans;
}
use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.
the class PrintAllEventCRFServlet method processRequest.
@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
FormProcessor fp = new FormProcessor(request);
SessionManager sm = (SessionManager) request.getSession().getAttribute("sm");
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
ArrayList<SectionBean> allSectionBeans;
// The PrintDataEntry servlet handles this parameter
boolean isSubmitted = false;
StudyEventDefinitionDAO sedao = new StudyEventDefinitionDAO(sm.getDataSource());
EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(sm.getDataSource());
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
StudyDAO studyDao = new StudyDAO(sm.getDataSource());
StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
ArrayList<StudyEventDefinitionBean> seds = new ArrayList<StudyEventDefinitionBean>();
seds = sedao.findAllByStudy(currentStudy);
// ArrayList eventDefinitionCRFs = (ArrayList) edao.findAllByStudy(site);
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
ArrayList<EventDefinitionCRFBean> edcs = new ArrayList();
for (StudyEventDefinitionBean sed : seds) {
int defId = sed.getId();
edcs.addAll(edcdao.findAllByDefinition(currentStudy, defId));
}
Map eventDefinitionDefaultVersions = new LinkedHashMap();
for (int i = 0; i < edcs.size(); i++) {
EventDefinitionCRFBean edc = edcs.get(i);
ArrayList versions = (ArrayList) cvdao.findAllByCRF(edc.getCrfId());
edc.setVersions(versions);
CRFBean crf = (CRFBean) cdao.findByPK(edc.getCrfId());
// edc.setCrfLabel(crf.getLabel());
edc.setCrfName(crf.getName());
// to show/hide edit action on jsp page
if (crf.getStatus().equals(Status.AVAILABLE)) {
edc.setOwner(crf.getOwner());
}
CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(edc.getDefaultVersionId());
StudyEventDefinitionBean studyEventDefinitionBean = (StudyEventDefinitionBean) sedao.findByPK(edc.getStudyEventDefinitionId());
edc.setDefaultVersionName(defaultVersion.getName());
if (defaultVersion.getStatus().isAvailable()) {
List list = (ArrayList) eventDefinitionDefaultVersions.get(studyEventDefinitionBean);
if (list == null)
list = new ArrayList();
list.add(defaultVersion);
eventDefinitionDefaultVersions.put(studyEventDefinitionBean, list);
}
}
// Whether IE6 or IE7 is involved
String isIE = fp.getString("ie");
if ("y".equalsIgnoreCase(isIE)) {
request.setAttribute("isInternetExplorer", "true");
}
SectionDAO sdao = new SectionDAO(sm.getDataSource());
CRFVersionDAO crfVersionDAO = new CRFVersionDAO(sm.getDataSource());
CRFDAO crfDao = new CRFDAO(sm.getDataSource());
Map sedCrfBeans = null;
for (Iterator it = eventDefinitionDefaultVersions.keySet().iterator(); it.hasNext(); ) {
if (sedCrfBeans == null)
sedCrfBeans = new LinkedHashMap();
StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) it.next();
List crfVersions = (ArrayList) eventDefinitionDefaultVersions.get(sedBean);
for (Iterator crfIt = crfVersions.iterator(); crfIt.hasNext(); ) {
CRFVersionBean crfVersionBean = (CRFVersionBean) crfIt.next();
allSectionBeans = new ArrayList<SectionBean>();
ArrayList sectionBeans = new ArrayList();
ItemGroupDAO itemGroupDao = new ItemGroupDAO(sm.getDataSource());
// Find truely grouped tables, not groups with a name of 'Ungrouped'
List<ItemGroupBean> itemGroupBeans = itemGroupDao.findOnlyGroupsByCRFVersionID(crfVersionBean.getId());
CRFBean crfBean = crfDao.findByVersionId(crfVersionBean.getId());
if (itemGroupBeans.size() > 0) {
// 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 data is involved or not
// ('false' in terms of this
// servlet; see PrintDataEntryServlet).
DisplaySectionBeanHandler handler = new DisplaySectionBeanHandler(false, getDataSource(), getServletContext());
handler.setCrfVersionId(crfVersionBean.getId());
//handler.setEventCRFId(eventCRFId);
List<DisplaySectionBean> displaySectionBeans = handler.getDisplaySectionBeans();
request.setAttribute("listOfDisplaySectionBeans", displaySectionBeans);
// Make available the CRF names and versions for
// the web page's header
CRFVersionBean crfverBean = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionBean.getId());
request.setAttribute("crfVersionBean", crfverBean);
request.setAttribute("crfBean", crfBean);
// Set an attribute signaling that data is not involved
request.setAttribute("dataInvolved", "false");
PrintCRFBean printCrfBean = new PrintCRFBean();
printCrfBean.setDisplaySectionBeans(displaySectionBeans);
printCrfBean.setCrfVersionBean(crfVersionBean);
printCrfBean.setCrfBean(crfBean);
printCrfBean.setEventCrfBean(ecb);
printCrfBean.setGrouped(true);
List list = (ArrayList) sedCrfBeans.get(sedBean);
if (list == null)
list = new ArrayList();
list.add(printCrfBean);
sedCrfBeans.put(sedBean, list);
continue;
}
ecb = new EventCRFBean();
ecb.setCRFVersionId(crfVersionBean.getId());
CRFVersionBean version = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionBean.getId());
ArrayList sects = (ArrayList) sdao.findByVersionId(version.getId());
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));
}
}
request.setAttribute(INPUT_EVENT_CRF, ecb);
request.setAttribute(SECTION_BEAN, sb);
request.setAttribute(ALL_SECTION_BEANS, allSectionBeans);
sectionBeans = super.getAllDisplayBeans(request);
DisplaySectionBean dsb = super.getDisplayBean(false, false, request, isSubmitted);
PrintCRFBean printCrfBean = new PrintCRFBean();
printCrfBean.setAllSections(sectionBeans);
printCrfBean.setDisplaySectionBean(dsb);
printCrfBean.setEventCrfBean(ecb);
printCrfBean.setCrfVersionBean(crfVersionBean);
printCrfBean.setCrfBean(crfBean);
printCrfBean.setGrouped(false);
List list = (ArrayList) sedCrfBeans.get(sedBean);
if (list == null)
list = new ArrayList();
list.add(printCrfBean);
sedCrfBeans.put(sedBean, list);
}
}
request.setAttribute("sedCrfBeans", sedCrfBeans);
request.setAttribute("studyName", currentStudy.getName());
forwardPage(Page.VIEW_ALL_DEFAULT_CRF_VERSIONS_PRINT, request, response);
}
use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.
the class RemoveStudyEventServlet method getDisplayEventCRFs.
/**
* Each of the event CRFs with its corresponding CRFBean. Then generates a
* list of DisplayEventCRFBeans, one for each event CRF.
*
* @param eventCRFs
* The list of event CRFs for this study event.
* @param eventDefinitionCRFs
* The list of event definition CRFs for this study event.
* @return The list of DisplayEventCRFBeans for this study event.
*/
private ArrayList getDisplayEventCRFs(ArrayList eventCRFs, ArrayList eventDefinitionCRFs) {
ArrayList answer = new ArrayList();
HashMap definitionsById = new HashMap();
int i;
for (i = 0; i < eventDefinitionCRFs.size(); i++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
definitionsById.put(new Integer(edc.getStudyEventDefinitionId()), edc);
}
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
for (i = 0; i < eventCRFs.size(); i++) {
EventCRFBean ecb = (EventCRFBean) eventCRFs.get(i);
// populate the event CRF with its crf bean
int crfVersionId = ecb.getCRFVersionId();
CRFBean cb = cdao.findByVersionId(crfVersionId);
ecb.setCrf(cb);
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(crfVersionId);
ecb.setCrfVersion(cvb);
// then get the definition so we can call
// DisplayEventCRFBean.setFlags
int studyEventId = ecb.getStudyEventId();
int studyEventDefinitionId = sedao.getDefinitionIdFromStudyEventId(studyEventId);
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) definitionsById.get(new Integer(studyEventDefinitionId));
DisplayEventCRFBean dec = new DisplayEventCRFBean();
dec.setFlags(ecb, ub, currentRole, edc.isDoubleEntry());
answer.add(dec);
}
return answer;
}
use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.
the class RemoveEventCRFServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
// eventCRFId
int eventCRFId = fp.getInt("id");
// studySubjectId
int studySubId = fp.getInt("studySubId");
checkStudyLocked("ViewStudySubject?id" + studySubId, respage.getString("current_study_locked"));
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
StudyDAO sdao = new StudyDAO(sm.getDataSource());
if (eventCRFId == 0) {
addPageMessage(respage.getString("please_choose_an_event_CRF_to_remove"));
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
} else {
EventCRFBean eventCRF = (EventCRFBean) ecdao.findByPK(eventCRFId);
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
request.setAttribute("studySub", studySub);
// construct info needed on view event crf page
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
int crfVersionId = eventCRF.getCRFVersionId();
CRFBean cb = cdao.findByVersionId(crfVersionId);
eventCRF.setCrf(cb);
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(crfVersionId);
eventCRF.setCrfVersion(cvb);
// then get the definition so we can call
// DisplayEventCRFBean.setFlags
int studyEventId = eventCRF.getStudyEventId();
StudyEventBean event = (StudyEventBean) sedao.findByPK(studyEventId);
int studyEventDefinitionId = sedao.getDefinitionIdFromStudyEventId(studyEventId);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(studyEventDefinitionId);
event.setStudyEventDefinition(sed);
request.setAttribute("event", event);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
StudyBean study = (StudyBean) sdao.findByPK(studySub.getStudyId());
EventDefinitionCRFBean edc = edcdao.findByStudyEventDefinitionIdAndCRFId(study, studyEventDefinitionId, cb.getId());
DisplayEventCRFBean dec = new DisplayEventCRFBean();
dec.setEventCRF(eventCRF);
dec.setFlags(eventCRF, ub, currentRole, edc.isDoubleEntry());
// find all item data
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
ArrayList itemData = iddao.findAllByEventCRFId(eventCRF.getId());
request.setAttribute("items", itemData);
String action = request.getParameter("action");
if ("confirm".equalsIgnoreCase(action)) {
if (eventCRF.getStatus().equals(Status.DELETED) || eventCRF.getStatus().equals(Status.AUTO_DELETED)) {
addPageMessage(respage.getString("this_event_CRF_is_removed_for_this_study") + " " + respage.getString("please_contact_sysadmin_for_more_information"));
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
return;
}
request.setAttribute("displayEventCRF", dec);
forwardPage(Page.REMOVE_EVENT_CRF);
} else {
logger.info("submit to remove the event CRF from study");
eventCRF.setStatus(Status.DELETED);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
// remove all the item data
for (int a = 0; a < itemData.size(); a++) {
ItemDataBean item = (ItemDataBean) itemData.get(a);
if (!item.getStatus().equals(Status.DELETED)) {
item.setStatus(Status.AUTO_DELETED);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
DiscrepancyNoteDAO dnDao = new DiscrepancyNoteDAO(sm.getDataSource());
List dnNotesOfRemovedItem = dnDao.findExistingNotesForItemData(item.getId());
if (!dnNotesOfRemovedItem.isEmpty()) {
DiscrepancyNoteBean itemParentNote = null;
for (Object obj : dnNotesOfRemovedItem) {
if (((DiscrepancyNoteBean) obj).getParentDnId() == 0) {
itemParentNote = (DiscrepancyNoteBean) obj;
}
}
DiscrepancyNoteBean dnb = new DiscrepancyNoteBean();
if (itemParentNote != null) {
dnb.setParentDnId(itemParentNote.getId());
dnb.setDiscrepancyNoteTypeId(itemParentNote.getDiscrepancyNoteTypeId());
}
dnb.setResolutionStatusId(ResolutionStatus.CLOSED.getId());
dnb.setStudyId(currentStudy.getId());
dnb.setAssignedUserId(ub.getId());
dnb.setOwner(ub);
dnb.setEntityType(DiscrepancyNoteBean.ITEM_DATA);
dnb.setEntityId(item.getId());
dnb.setColumn("value");
dnb.setCreatedDate(new Date());
dnb.setDescription("The item has been removed, this Discrepancy Note has been Closed.");
dnDao.create(dnb);
dnDao.createMapping(dnb);
itemParentNote.setResolutionStatusId(ResolutionStatus.CLOSED.getId());
dnDao.update(itemParentNote);
}
}
}
String emailBody = respage.getString("the_event_CRF") + " " + cb.getName() + " " + respage.getString("has_been_removed_from_the_event") + event.getStudyEventDefinition().getName() + ". " + respage.getString("has_been_removed_from_the_event_cont");
addPageMessage(emailBody);
sendEmail(emailBody);
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
}
}
}
use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.
the class LockCRFVersionServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
int crfVersionId = fp.getInt("id", true);
String action = fp.getString("action");
// checks which module the requests are from
String module = fp.getString(MODULE);
request.setAttribute(MODULE, module);
if (crfVersionId == 0) {
addPageMessage(respage.getString("choose_valid_crf_version"));
forwardPage(Page.CRF_LIST_SERVLET);
return;
}
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFVersionBean version = (CRFVersionBean) cvdao.findByPK(crfVersionId);
//System.out.println("crf version found:" + version.getName());
CRFBean crf = (CRFBean) cdao.findByPK(version.getCrfId());
if (!ub.isSysAdmin() && (version.getOwnerId() != ub.getId())) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
forwardPage(Page.MENU_SERVLET);
return;
}
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ArrayList eventCRFs = ecdao.findAllStudySubjectByCRFVersion(crfVersionId);
if (StringUtil.isBlank(action)) {
request.setAttribute("crfVersionToLock", version);
request.setAttribute("crf", crf);
request.setAttribute("eventSubjectsUsingVersion", eventCRFs);
forwardPage(Page.CONFIRM_LOCKING_CRF_VERSION);
} else if ("confirm".equalsIgnoreCase(action)) {
version.setStatus(Status.LOCKED);
version.setUpdater(ub);
cvdao.update(version);
ArrayList versionList = (ArrayList) cvdao.findAllByCRF(version.getCrfId());
if (versionList.size() > 0) {
EventDefinitionCRFDAO edCRFDao = new EventDefinitionCRFDAO(sm.getDataSource());
ArrayList edcList = (ArrayList) edCRFDao.findAllByCRF(version.getCrfId());
for (int i = 0; i < edcList.size(); i++) {
EventDefinitionCRFBean edcBean = (EventDefinitionCRFBean) edcList.get(i);
// @pgawade 18-May-2011 #5414 - Changes for setting the correct
// default crf version Id to event
// when existing default version is locked
// RemoveCRFVersionServlet.updateEventDef(edcBean, edCRFDao,
// versionList);
RemoveCRFVersionServlet.updateEventDef(edcBean, edCRFDao, versionList, crfVersionId);
}
}
addPageMessage(respage.getString("crf_version_archived_successfully"));
forwardPage(Page.CRF_LIST_SERVLET);
}
}
Aggregations