use of org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO in project OpenClinica by OpenClinica.
the class CrfBusinessLogicHelper method areAllCompleted.
protected boolean areAllCompleted(StudyEventBean seBean, StudyBean study) {
EventDefinitionCRFDAO edcDao = new EventDefinitionCRFDAO(ds);
EventCRFDAO eventCrfDao = new EventCRFDAO(ds);
ArrayList allCRFs = eventCrfDao.findAllByStudyEvent(seBean);
ArrayList allEDCs = (ArrayList) edcDao.findAllActiveByEventDefinitionId(study, seBean.getStudyEventDefinitionId());
boolean eventCompleted = true;
logger.info("found all crfs: " + allCRFs.size());
logger.info("found all edcs: " + allEDCs.size());
for (int i = 0; i < allCRFs.size(); i++) {
EventCRFBean ec = (EventCRFBean) allCRFs.get(i);
// logger.info("found a crf name from event crf bean: " +
// ec.getCrf().getName());
logger.info("found a event name from event crf bean: " + ec.getEventName() + " crf version id: " + ec.getCRFVersionId());
if (!ec.getStatus().equals(Status.UNAVAILABLE) || allCRFs.size() < allEDCs.size()) {
eventCompleted = false;
break;
}
}
logger.info("returning for are all completed: " + eventCompleted);
return eventCompleted;
}
use of org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO in project OpenClinica by OpenClinica.
the class CrfBusinessLogicHelper method getEventDefinitionCrfByStudyEventAndCrfVersion.
private EventDefinitionCRFBean getEventDefinitionCrfByStudyEventAndCrfVersion(EventCRFBean eventCrf, StudyBean study) {
EventDefinitionCRFDAO eventDefinitionCrfDao = new EventDefinitionCRFDAO(ds);
// TODO we have to get that id before we can continue
eventDefinitionCrfDao = new EventDefinitionCRFDAO(ds);
EventDefinitionCRFBean eventDefinitionCrf = eventDefinitionCrfDao.findByStudyEventIdAndCRFVersionId(study, eventCrf.getStudyEventId(), eventCrf.getCRFVersionId());
return eventDefinitionCrf;
}
use of org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO in project OpenClinica by OpenClinica.
the class StudySubjectServiceImpl method getDisplayStudyEventsForStudySubject.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<DisplayStudyEventBean> getDisplayStudyEventsForStudySubject(StudySubjectBean studySubject, UserAccountBean userAccount, StudyUserRoleBean currentRole) {
StudyEventDAO studyEventDao = new StudyEventDAO(dataSource);
StudyEventDefinitionDAO studyEventDefinitionDao = new StudyEventDefinitionDAO(dataSource);
StudyDAO studyDao = new StudyDAO(dataSource);
EventDefinitionCRFDAO eventDefinitionCrfDao = new EventDefinitionCRFDAO(dataSource);
EventCRFDAO eventCrfDao = new EventCRFDAO(dataSource);
CRFDAO crfDao = new CRFDAO(dataSource);
FormLayoutDAO formLayoutDAO = new FormLayoutDAO(dataSource);
ArrayList events = studyEventDao.findAllByStudySubject(studySubject);
Map<Integer, StudyEventDefinitionBean> eventDefinitionByEvent = studyEventDefinitionDao.findByStudySubject(studySubject.getId());
StudyBean study = (StudyBean) studyDao.findByPK(studySubject.getStudyId());
Map<Integer, SortedSet<EventDefinitionCRFBean>> eventDefinitionCrfByStudyEventDefinition;
if (study.getParentStudyId() < 1) {
// Is a study
eventDefinitionCrfByStudyEventDefinition = eventDefinitionCrfDao.buildEventDefinitionCRFListByStudyEventDefinitionForStudy(studySubject.getId());
} else {
// Is a site
eventDefinitionCrfByStudyEventDefinition = eventDefinitionCrfDao.buildEventDefinitionCRFListByStudyEventDefinition(studySubject.getId(), study.getId(), study.getParentStudyId());
}
Map<Integer, SortedSet<EventCRFBean>> eventCrfListByStudyEvent = eventCrfDao.buildEventCrfListByStudyEvent(studySubject.getId());
Map<Integer, Integer> maxOrdinalByStudyEvent = studyEventDefinitionDao.buildMaxOrdinalByStudyEvent(studySubject.getId());
Set<Integer> nonEmptyEventCrf = eventCrfDao.buildNonEmptyEventCrfIds(studySubject.getId());
Map<Integer, FormLayoutBean> formLayoutById = formLayoutDAO.buildFormLayoutById(studySubject.getId());
Map<Integer, CRFBean> crfById = crfDao.buildCrfById(studySubject.getId());
ArrayList<DisplayStudyEventBean> displayEvents = new ArrayList<DisplayStudyEventBean>();
for (int i = 0; i < events.size(); i++) {
StudyEventBean event = (StudyEventBean) events.get(i);
StudyEventDefinitionBean sed = eventDefinitionByEvent.get(event.getStudyEventDefinitionId());
event.setStudyEventDefinition(sed);
List eventDefinitionCRFs = new ArrayList((eventDefinitionCrfByStudyEventDefinition.containsKey(sed.getId()) ? eventDefinitionCrfByStudyEventDefinition.get(sed.getId()) : Collections.EMPTY_LIST));
List eventCRFs = new ArrayList((eventCrfListByStudyEvent.containsKey(event.getId())) ? eventCrfListByStudyEvent.get(event.getId()) : Collections.EMPTY_LIST);
// construct info needed on view study event page
DisplayStudyEventBean de = new DisplayStudyEventBean();
de.setStudyEvent(event);
de.setDisplayEventCRFs((ArrayList<DisplayEventCRFBean>) getDisplayEventCRFs(eventCRFs, userAccount, currentRole, event.getSubjectEventStatus(), study, nonEmptyEventCrf, formLayoutById, crfById, event.getStudyEventDefinitionId(), eventDefinitionCRFs));
ArrayList<DisplayEventDefinitionCRFBean> al = getUncompletedCRFs(eventDefinitionCRFs, eventCRFs, event.getSubjectEventStatus(), nonEmptyEventCrf, formLayoutById, crfById);
populateUncompletedCRFsWithCRFAndVersions(al, formLayoutById, crfById);
de.setUncompletedCRFs(al);
// de.setMaximumSampleOrdinal(studyEventDao.getMaxSampleOrdinal(sed,
// studySubject));
de.setMaximumSampleOrdinal(maxOrdinalByStudyEvent.get(event.getStudyEventDefinitionId()));
displayEvents.add(de);
// event.setEventCRFs(createAllEventCRFs(eventCRFs,
// eventDefinitionCRFs));
}
return displayEvents;
}
use of org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO in project OpenClinica by OpenClinica.
the class DeleteCRFVersionServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
int versionId = fp.getInt(VERSION_ID, true);
String action = request.getParameter("action");
if (versionId == 0) {
addPageMessage(respage.getString("please_choose_a_CRF_version_to_delete"));
forwardPage(Page.CRF_LIST_SERVLET);
} else {
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
StudyEventDefinitionDAO sedDao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDAO seDao = new StudyEventDAO(sm.getDataSource());
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
CRFVersionBean version = (CRFVersionBean) cvdao.findByPK(versionId);
// find definitions using this version
ArrayList definitions = edcdao.findByDefaultVersion(version.getId());
for (Object edcBean : definitions) {
StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) sedDao.findByPK(((EventDefinitionCRFBean) edcBean).getStudyEventDefinitionId());
((EventDefinitionCRFBean) edcBean).setEventName(sedBean.getName());
}
// find event crfs using this version
ArrayList<ItemDataBean> idBeans = iddao.findByCRFVersion(version);
ArrayList<EventCRFBean> eCRFs = ecdao.findAllByCRF(version.getCrfId());
for (EventCRFBean eCRF : eCRFs) {
StudySubjectBean ssBean = (StudySubjectBean) ssdao.findByPK(eCRF.getStudySubjectId());
eCRF.setStudySubject(ssBean);
StudyEventBean seBean = (StudyEventBean) seDao.findByPK(eCRF.getStudyEventId());
StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) sedDao.findByPK(seBean.getStudyEventDefinitionId());
seBean.setStudyEventDefinition(sedBean);
eCRF.setStudyEvent(seBean);
}
ArrayList eventCRFs = ecdao.findAllByCRFVersion(versionId);
boolean canDelete = true;
if (!definitions.isEmpty()) {
// used in definition
canDelete = false;
request.setAttribute("definitions", definitions);
addPageMessage(respage.getString("this_CRF_version") + " " + version.getName() + respage.getString("has_associated_study_events_definitions_cannot_delete"));
} else if (!idBeans.isEmpty()) {
canDelete = false;
request.setAttribute("eventCRFs", eCRFs);
request.setAttribute("itemDataForVersion", idBeans);
addPageMessage(respage.getString("this_CRF_version") + " " + version.getName() + respage.getString("has_associated_item_data_cannot_delete"));
} else if (!eventCRFs.isEmpty()) {
canDelete = false;
request.setAttribute("eventsForVersion", eventCRFs);
addPageMessage(respage.getString("this_CRF_version") + " " + version.getName() + respage.getString("has_associated_study_events_cannot_delete"));
}
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute(VERSION_TO_DELETE, version);
forwardPage(Page.DELETE_CRF_VERSION);
} else {
// submit
if (canDelete) {
ArrayList items = cvdao.findNotSharedItemsByVersion(versionId);
NewCRFBean nib = new NewCRFBean(sm.getDataSource(), version.getCrfId());
nib.setDeleteQueries(cvdao.generateDeleteQueries(versionId, items));
nib.deleteFromDB();
addPageMessage(respage.getString("the_CRF_version_has_been_deleted_succesfully"));
} else {
addPageMessage(respage.getString("the_CRF_version_cannot_be_deleted"));
}
forwardPage(Page.CRF_LIST_SERVLET);
}
}
}
use of org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO in project OpenClinica by OpenClinica.
the class RemoveCRFServlet method processRequest.
@Override
public void processRequest() throws Exception {
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
// checks which module the requests are from
String module = fp.getString(MODULE);
request.setAttribute(MODULE, module);
int crfId = fp.getInt("id", true);
String action = request.getParameter("action");
if (crfId == 0) {
addPageMessage(respage.getString("please_choose_a_CRF_to_remove"));
forwardPage(Page.CRF_LIST_SERVLET);
} else {
CRFBean crf = (CRFBean) cdao.findByPK(crfId);
ArrayList versions = cvdao.findAllByCRFId(crfId);
crf.setVersions(versions);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
ArrayList edcs = (ArrayList) edcdao.findAllByCRF(crfId);
SectionDAO secdao = new SectionDAO(sm.getDataSource());
EventCRFDAO evdao = new EventCRFDAO(sm.getDataSource());
ArrayList eventCRFs = evdao.findAllByCRF(crfId);
StudyEventDAO seDao = new StudyEventDAO(sm.getDataSource());
StudyEventDefinitionDAO sedDao = new StudyEventDefinitionDAO(sm.getDataSource());
for (Object ecBean : eventCRFs) {
StudyEventBean seBean = (StudyEventBean) seDao.findByPK(((EventCRFBean) ecBean).getStudyEventId());
StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) sedDao.findByPK(seBean.getStudyEventDefinitionId());
((EventCRFBean) ecBean).setEventName(sedBean.getName());
}
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute("crfToRemove", crf);
request.setAttribute("eventCRFs", eventCRFs);
forwardPage(Page.REMOVE_CRF);
} else {
logger.info("submit to remove the crf");
crf.setStatus(Status.DELETED);
crf.setUpdater(ub);
crf.setUpdatedDate(new Date());
cdao.update(crf);
for (int i = 0; i < versions.size(); i++) {
CRFVersionBean version = (CRFVersionBean) versions.get(i);
if (!version.getStatus().equals(Status.DELETED)) {
version.setStatus(Status.AUTO_DELETED);
version.setUpdater(ub);
version.setUpdatedDate(new Date());
cvdao.update(version);
ArrayList sections = secdao.findAllByCRFVersionId(version.getId());
for (int j = 0; j < sections.size(); j++) {
SectionBean section = (SectionBean) sections.get(j);
if (!section.getStatus().equals(Status.DELETED)) {
section.setStatus(Status.AUTO_DELETED);
section.setUpdater(ub);
section.setUpdatedDate(new Date());
secdao.update(section);
}
}
}
}
for (int i = 0; i < edcs.size(); i++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) edcs.get(i);
if (!edc.getStatus().equals(Status.DELETED)) {
edc.setStatus(Status.AUTO_DELETED);
edc.setUpdater(ub);
edc.setUpdatedDate(new Date());
edcdao.update(edc);
}
}
ItemDataDAO idao = new ItemDataDAO(sm.getDataSource());
for (int i = 0; i < eventCRFs.size(); i++) {
EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(i);
if (!eventCRF.getStatus().equals(Status.DELETED)) {
eventCRF.setStatus(Status.AUTO_DELETED);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
evdao.update(eventCRF);
ArrayList items = idao.findAllByEventCRFId(eventCRF.getId());
for (int j = 0; j < items.size(); j++) {
ItemDataBean item = (ItemDataBean) items.get(j);
if (!item.getStatus().equals(Status.DELETED)) {
item.setStatus(Status.AUTO_DELETED);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
idao.update(item);
}
}
}
}
addPageMessage(respage.getString("the_CRF") + crf.getName() + " " + respage.getString("has_been_removed_succesfully"));
forwardPage(Page.CRF_LIST_SERVLET);
}
}
}
Aggregations