use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class PrintEventCRFServlet method processRequest.
@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
FormProcessor fp = new FormProcessor(request);
StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
// The PrintDataEntry servlet handles this parameter
int eventCRFId = fp.getInt("ecId");
// JN:The following were the the global variables, moved as local.
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
StudyEventDefinitionDAO sedao = new StudyEventDefinitionDAO(getDataSource());
int defId = fp.getInt("id", true);
boolean isSubmitted = false;
ArrayList<SectionBean> allSectionBeans;
if (defId == 0) {
addPageMessage(respage.getString("please_choose_a_definition_to_view"), request);
forwardPage(Page.LIST_DEFINITION_SERVLET, request, response);
} else {
// definition id
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) sedao.findByPK(defId);
EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(getDataSource());
ArrayList eventDefinitionCRFs = (ArrayList) edao.findAllByDefinition(defId);
CRFVersionDAO cvdao = new CRFVersionDAO(getDataSource());
CRFDAO cdao = new CRFDAO(getDataSource());
ArrayList defaultVersions = new ArrayList();
for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.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());
// There could be separate EventDefinitionCRF objects with same default version id.
if (defaultVersions.contains(defaultVersion)) {
continue;
}
edc.setDefaultVersionName(defaultVersion.getName());
if (edc.getStatus().isAvailable()) {
defaultVersions.add(defaultVersion);
}
}
// Whether IE6 or IE7 is involved
String isIE = fp.getString("ie");
if ("y".equalsIgnoreCase(isIE)) {
request.setAttribute("isInternetExplorer", "true");
}
int eventDefinitionCRFId = fp.getInt("eventDefinitionCRFId");
// EventDefinitionCRFDao findByStudyEventIdAndCRFVersionId(int
// studyEventId, int crfVersionId)
SectionDAO sdao = new SectionDAO(getDataSource());
CRFVersionDAO crfVersionDAO = new CRFVersionDAO(getDataSource());
CRFDAO crfDao = new CRFDAO(getDataSource());
ArrayList printCrfBeans = new ArrayList();
for (Iterator it = defaultVersions.iterator(); it.hasNext(); ) {
allSectionBeans = new ArrayList<SectionBean>();
ArrayList sectionBeans = new ArrayList();
CRFVersionBean crfVersionBean = (CRFVersionBean) it.next();
// The existing application doesn't print null values, even if they are
// defined in the event definition
// int crfVersionId = fp.getInt("id");
// BWP 2/7/2008>> Find out if the CRF has grouped tables, and if so,
// use
// that dedicated JSP
ItemGroupDAO itemGroupDao = new ItemGroupDAO(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);
printCrfBeans.add(printCrfBean);
printCrfBean.setGrouped(true);
// IllegalStateException
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(ALL_SECTION_BEANS, allSectionBeans);
request.setAttribute(INPUT_EVENT_CRF, ecb);
sectionBeans = super.getAllDisplayBeans(request);
request.setAttribute(SECTION_BEAN, sb);
DisplaySectionBean dsb = super.getDisplayBean(false, false, request, isSubmitted);
// request.setAttribute("allSections", sectionBeans);
// request.setAttribute("displayAllCRF", "1");
// request.setAttribute(BEAN_DISPLAY, dsb);
// request.setAttribute(BEAN_ANNOTATIONS, ecb.getAnnotations());
// request.setAttribute("sec", sb);
// request.setAttribute("EventCRFBean", super.ecb);
PrintCRFBean printCrfBean = new PrintCRFBean();
printCrfBean.setAllSections(sectionBeans);
printCrfBean.setDisplaySectionBean(dsb);
printCrfBean.setEventCrfBean(ecb);
printCrfBean.setCrfVersionBean(crfVersionBean);
printCrfBean.setCrfBean(crfBean);
printCrfBeans.add(printCrfBean);
printCrfBean.setGrouped(false);
}
String studyName = null;
String siteName = null;
if (currentStudy.getParentStudyId() > 0) {
studyName = currentStudy.getParentStudyName();
siteName = currentStudy.getName();
} else {
studyName = currentStudy.getName();
}
request.setAttribute("printCrfBeans", printCrfBeans);
request.setAttribute("studyName", studyName);
request.setAttribute("site", siteName);
request.setAttribute("eventDefinition", sed.getName());
forwardPage(Page.VIEW_DEFAULT_CRF_VERSIONS_PRINT, request, response);
}
}
use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class RemoveEventDefinitionServlet method processRequest.
@Override
public void processRequest() throws Exception {
String idString = request.getParameter("id");
int defId = Integer.valueOf(idString.trim()).intValue();
StudyEventDefinitionDAO sdao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) sdao.findByPK(defId);
// checkRoleByUserAndStudy(ub.getName(), sed.getStudyId(), 0);
if (currentStudy.getId() != sed.getStudyId()) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
forwardPage(Page.MENU_SERVLET);
return;
}
// find all CRFs
EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(sm.getDataSource());
ArrayList eventDefinitionCRFs = (ArrayList) edao.findAllByDefinition(defId);
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
ArrayList versions = (ArrayList) cvdao.findAllByCRF(edc.getCrfId());
edc.setVersions(versions);
CRFBean crf = (CRFBean) cdao.findByPK(edc.getCrfId());
edc.setCrfName(crf.getName());
CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(edc.getDefaultVersionId());
edc.setDefaultVersionName(defaultVersion.getName());
CRFBean cBean = (CRFBean) cdao.findByPK(edc.getCrfId());
String crfPath = sed.getOid() + "." + cBean.getOid();
edc.setOffline(getEventDefinitionCrfTagService().getEventDefnCrfOfflineStatus(2, crfPath, true));
}
// finds all events
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
ArrayList events = (ArrayList) sedao.findAllByDefinition(sed.getId());
String action = request.getParameter("action");
if (StringUtil.isBlank(idString)) {
addPageMessage(respage.getString("please_choose_a_SED_to_remove"));
forwardPage(Page.LIST_DEFINITION_SERVLET);
} else {
if ("confirm".equalsIgnoreCase(action)) {
if (!sed.getStatus().equals(Status.AVAILABLE)) {
addPageMessage(respage.getString("this_SED_is_not_available_for_this_study") + respage.getString("please_contact_sysadmin_for_more_information"));
forwardPage(Page.LIST_DEFINITION_SERVLET);
return;
}
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
if (participateFormStatus.equals("enabled"))
baseUrl();
request.setAttribute("participateFormStatus", participateFormStatus);
request.setAttribute("definitionToRemove", sed);
request.setAttribute("eventDefinitionCRFs", eventDefinitionCRFs);
request.setAttribute("events", events);
forwardPage(Page.REMOVE_DEFINITION);
} else {
logger.info("submit to remove the definition");
// remove definition
sed.setStatus(Status.DELETED);
sed.setUpdater(ub);
sed.setUpdatedDate(new Date());
sdao.update(sed);
// remove all crfs
for (int j = 0; j < eventDefinitionCRFs.size(); j++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(j);
if (!edc.getStatus().equals(Status.DELETED)) {
edc.setStatus(Status.AUTO_DELETED);
edc.setUpdater(ub);
edc.setUpdatedDate(new Date());
edao.update(edc);
}
}
// remove all events
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
for (int j = 0; j < events.size(); j++) {
StudyEventBean event = (StudyEventBean) events.get(j);
if (!event.getStatus().equals(Status.DELETED)) {
event.setStatus(Status.AUTO_DELETED);
event.setUpdater(ub);
event.setUpdatedDate(new Date());
sedao.update(event);
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
// remove all the item data
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.DELETED)) {
eventCRF.setStatus(Status.AUTO_DELETED);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
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.DELETED)) {
item.setStatus(Status.AUTO_DELETED);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
}
}
String emailBody = respage.getString("the_SED") + sed.getName() + " " + respage.getString("has_been_removed_from_the_study") + currentStudy.getName() + ".";
addPageMessage(emailBody);
// sendEmail(emailBody);
forwardPage(Page.LIST_DEFINITION_SERVLET);
}
}
}
use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class SignStudySubjectServlet method getUncompletedCRFs.
/**
* Finds all the event definitions for which no event CRF exists - which is
* the list of event definitions with uncompleted event CRFs.
*
* @param eventDefinitionCRFs
* All of the event definition CRFs for this study event.
* @param eventCRFs
* All of the event CRFs for this study event.
* @return The list of event definitions for which no event CRF exists.
*/
public static ArrayList getUncompletedCRFs(DataSource ds, ArrayList eventDefinitionCRFs, ArrayList eventCRFs, SubjectEventStatus status) {
int i;
HashMap completed = new HashMap();
HashMap startedButIncompleted = new HashMap();
ArrayList answer = new ArrayList();
for (i = 0; i < eventDefinitionCRFs.size(); i++) {
EventDefinitionCRFBean edcrf = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
completed.put(new Integer(edcrf.getCrfId()), Boolean.FALSE);
startedButIncompleted.put(new Integer(edcrf.getCrfId()), new EventCRFBean());
}
CRFVersionDAO cvdao = new CRFVersionDAO(ds);
ItemDataDAO iddao = new ItemDataDAO(ds);
for (i = 0; i < eventCRFs.size(); i++) {
EventCRFBean ecrf = (EventCRFBean) eventCRFs.get(i);
int crfId = cvdao.getCRFIdFromCRFVersionId(ecrf.getCRFVersionId());
ArrayList idata = iddao.findAllByEventCRFId(ecrf.getId());
if (!idata.isEmpty()) {
// this crf has data already
completed.put(new Integer(crfId), Boolean.TRUE);
} else {
// event crf got created, but no data entered
startedButIncompleted.put(new Integer(crfId), ecrf);
}
}
// TODO possible relation to 1689 here, tbh
for (i = 0; i < eventDefinitionCRFs.size(); i++) {
DisplayEventDefinitionCRFBean dedc = new DisplayEventDefinitionCRFBean();
EventDefinitionCRFBean edcrf = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
// System.out.println("created dedc with edcrf
// "+edcrf.getCrfName()+" default version "+
// edcrf.getDefaultVersionName()+", id
// "+edcrf.getDefaultVersionId());
dedc.setEdc(edcrf);
// below added tbh, 112007 to fix bug 1943
if (status.equals(SubjectEventStatus.LOCKED)) {
dedc.setStatus(Status.LOCKED);
}
Boolean b = (Boolean) completed.get(new Integer(edcrf.getCrfId()));
EventCRFBean ev = (EventCRFBean) startedButIncompleted.get(new Integer(edcrf.getCrfId()));
if (b == null || !b.booleanValue()) {
// System.out.println("entered boolean loop with ev
// "+ev.getId()+" crf version id "+
// ev.getCRFVersionId());
dedc.setEventCRF(ev);
answer.add(dedc);
// System.out.println("just added dedc to answer");
// removed, tbh, since this is proving nothing, 11-2007
/*
* if (dedc.getEdc().getDefaultVersionId() !=
* dedc.getEventCRF().getId()) { System.out.println("ID
* MISMATCH: edc name "+dedc.getEdc().getName()+ ", default
* version id "+dedc.getEdc().getDefaultVersionId()+ " event crf
* id "+dedc.getEventCRF().getId()); }
*/
}
}
return answer;
}
use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class SignStudySubjectServlet 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.
* @return The list of DisplayEventCRFBeans for this study event.
*/
public static ArrayList getDisplayEventCRFs(StudyBean study, DataSource ds, ArrayList eventCRFs, UserAccountBean ub, StudyUserRoleBean currentRole, SubjectEventStatus status) {
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(ds);
CRFDAO cdao = new CRFDAO(ds);
CRFVersionDAO cvdao = new CRFVersionDAO(ds);
ItemDataDAO iddao = new ItemDataDAO(ds);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(ds);
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));
// fix problem of the above code(commented out), find the correct
// edc, note that on definitionId can be related to multiple
// eventdefinitioncrfBeans
EventDefinitionCRFBean edc = edcdao.findByStudyEventDefinitionIdAndCRFId(study, studyEventDefinitionId, cb.getId());
// rules updated 112007 tbh
if (status.equals(SubjectEventStatus.LOCKED) || status.equals(SubjectEventStatus.SKIPPED) || status.equals(SubjectEventStatus.STOPPED)) {
ecb.setStage(DataEntryStage.LOCKED);
// we need to set a SED-wide flag here, because other edcs
// in this event can be filled in and change the status, tbh
} else if (status.equals(SubjectEventStatus.INVALID)) {
ecb.setStage(DataEntryStage.LOCKED);
} else if (!cb.getStatus().equals(Status.AVAILABLE)) {
ecb.setStage(DataEntryStage.LOCKED);
} else if (!cvb.getStatus().equals(Status.AVAILABLE)) {
ecb.setStage(DataEntryStage.LOCKED);
}
// TODO need to refactor since this is similar to other code, tbh
if (edc != null) {
// System.out.println("edc is not null, need to set flags");
DisplayEventCRFBean dec = new DisplayEventCRFBean();
// System.out.println("edc.isDoubleEntry()" +
// edc.isDoubleEntry() + ecb.getId());
dec.setFlags(ecb, ub, currentRole, edc.isDoubleEntry());
// if (dec.isLocked()) {
// System.out.println("*** found a locked DEC: " + edc.getCrfName());
// }
ArrayList idata = iddao.findAllByEventCRFId(ecb.getId());
if (!idata.isEmpty()) {
// consider an event crf started only if item data get
// created
answer.add(dec);
}
}
}
return answer;
}
use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class SignStudySubjectServlet method populateUncompletedCRFsWithCRFAndVersions.
public static void populateUncompletedCRFsWithCRFAndVersions(DataSource ds, ArrayList uncompletedEventDefinitionCRFs) {
CRFDAO cdao = new CRFDAO(ds);
CRFVersionDAO cvdao = new CRFVersionDAO(ds);
int size = uncompletedEventDefinitionCRFs.size();
for (int i = 0; i < size; i++) {
DisplayEventDefinitionCRFBean dedcrf = (DisplayEventDefinitionCRFBean) uncompletedEventDefinitionCRFs.get(i);
CRFBean cb = (CRFBean) cdao.findByPK(dedcrf.getEdc().getCrfId());
dedcrf.getEdc().setCrf(cb);
ArrayList versions = (ArrayList) cvdao.findAllActiveByCRF(dedcrf.getEdc().getCrfId());
dedcrf.getEdc().setVersions(versions);
uncompletedEventDefinitionCRFs.set(i, dedcrf);
}
}
Aggregations