use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class ExtractBean method getMetadata.
/**
* Implements the Column algorithm in "Dataset Export Algorithms" Must be
* called after DatasetDAO.getDatasetData();
*/
public void getMetadata() {
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(ds);
CRFDAO cdao = new CRFDAO(ds);
CRFVersionDAO cvdao = new CRFVersionDAO(ds);
ItemDAO idao = new ItemDAO(ds);
ItemFormMetadataDAO ifmDAO = new ItemFormMetadataDAO(this.ds);
StudyGroupDAO studygroupDAO = new StudyGroupDAO(ds);
StudyGroupClassDAO studygroupclassDAO = new StudyGroupClassDAO(ds);
// SubjectGroupMapDAO subjectGroupMapDAO = new SubjectGroupMapDAO(ds);
studyGroupClasses = new ArrayList();
studyGroupMap = new HashMap();
studyGroupMaps = new HashMap<Integer, ArrayList>();
sedCrfColumns = new HashMap();
displayed = new HashMap();
sedCrfItemFormMetadataBeans = new HashMap();
studyEvents = seddao.findAllByStudy(study);
ArrayList finalStudyEvents = new ArrayList();
if (dataset.isShowSubjectGroupInformation()) {
// logger.info("found study id for maps: "+study.getId());
studyGroupMaps = studygroupDAO.findSubjectGroupMaps(study.getId());
// below is for a given subject; we need a data structure for
// all subjects
// studyGroupMap = studygroupDAO.findByStudySubject(currentSubject);
// problem: can't use currentSubject here, since it's not 'set up'
// properly
// how to get the current subject?
logger.info("found subject group ids: " + dataset.getSubjectGroupIds().toString());
// studyGroupClasses = dataset.getSubjectGroupIds();
for (int h = 0; h < dataset.getSubjectGroupIds().size(); h++) {
Integer groupId = (Integer) dataset.getSubjectGroupIds().get(h);
StudyGroupClassBean sgclass = (StudyGroupClassBean) studygroupclassDAO.findByPK(groupId.intValue());
// logger.info();
// hmm how to link groups to subjects though? only through
// subject group map
logger.info("found a studygroupclass bean: " + sgclass.getName());
studyGroupClasses.add(sgclass);
}
}
for (int i = 0; i < studyEvents.size(); i++) {
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) studyEvents.get(i);
if (!selectedSED(sed)) {
continue;
}
ArrayList CRFs = (ArrayList) cdao.findAllActiveByDefinition(sed);
ArrayList CRFsDisplayedInThisSED = new ArrayList();
for (int j = 0; j < CRFs.size(); j++) {
CRFBean cb = (CRFBean) CRFs.get(j);
if (!selectedSEDCRF(sed, cb)) {
continue;
} else {
CRFsDisplayedInThisSED.add(cb);
ArrayList CRFVersions = cvdao.findAllByCRFId(cb.getId());
for (int k = 0; k < CRFVersions.size(); k++) {
CRFVersionBean cvb = (CRFVersionBean) CRFVersions.get(k);
ArrayList Items = idao.findAllItemsByVersionId(cvb.getId());
// sort by ordinal/name
Collections.sort(Items);
for (int l = 0; l < Items.size(); l++) {
ItemBean ib = (ItemBean) Items.get(l);
if (selected(ib) && !getDisplayed(sed, cb, ib)) {
// logger.info("found at
// itemformmetadatadao: "+ib.getId()+",
// "+cvb.getId());
ItemFormMetadataBean ifmb = ifmDAO.findByItemIdAndCRFVersionId(ib.getId(), cvb.getId());
addColumn(sed, cb, ib);
addItemFormMetadataBeans(sed, cb, ifmb);
markDisplayed(sed, cb, ib);
}
}
}
}
// else
}
// for
sed.setCrfs(CRFsDisplayedInThisSED);
// make the setCrfs call "stick"
finalStudyEvents.add(sed);
}
this.studyEvents = finalStudyEvents;
}
use of org.akaza.openclinica.dao.submit.CRFVersionDAO 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.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class CreateCRFVersionServlet method canDeleteVersion.
/**
* Checks whether the version can be deleted
*
* @param previousVersionId
* @return
*/
private boolean canDeleteVersion(int previousVersionId) {
CRFVersionDAO cdao = new CRFVersionDAO(sm.getDataSource());
ArrayList items = null;
ArrayList itemsHaveData = new ArrayList();
// boolean isItemUsedByOtherVersion =
// cdao.isItemUsedByOtherVersion(previousVersionId);
// if (isItemUsedByOtherVersion) {
// ArrayList itemsUsedByOtherVersion = (ArrayList)
// cdao.findItemUsedByOtherVersion(previousVersionId);
// session.setAttribute("itemsUsedByOtherVersion",itemsUsedByOtherVersion);
// return false;
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ArrayList events = ecdao.findAllByCRFVersion(previousVersionId);
if (!events.isEmpty()) {
session.setAttribute("eventsForVersion", events);
return false;
}
items = cdao.findNotSharedItemsByVersion(previousVersionId);
for (int i = 0; i < items.size(); i++) {
ItemBean item = (ItemBean) items.get(i);
if (ub.getId() != item.getOwner().getId()) {
logger.debug("not owner" + item.getOwner().getId() + "<>" + ub.getId());
return false;
}
if (cdao.hasItemData(item.getId())) {
itemsHaveData.add(item);
logger.debug("item has data");
session.setAttribute("itemsHaveData", itemsHaveData);
return false;
}
}
// user is the owner and item not have data,
// delete previous version with non-shared items
NewCRFBean nib = (NewCRFBean) session.getAttribute("nib");
nib.setDeleteQueries(cdao.generateDeleteQueries(previousVersionId, items));
session.setAttribute("nib", nib);
return true;
}
use of org.akaza.openclinica.dao.submit.CRFVersionDAO 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);
CRFVersionDAO crfVersionDao = new CRFVersionDAO(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, CRFVersionBean> crfVersionById = crfVersionDao.buildCrfVersionById(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, crfVersionById, crfById, event.getStudyEventDefinitionId(), eventDefinitionCRFs));
ArrayList<DisplayEventDefinitionCRFBean> al = getUncompletedCRFs(eventDefinitionCRFs, eventCRFs, event.getSubjectEventStatus(), nonEmptyEventCrf, crfVersionById, crfById);
populateUncompletedCRFsWithCRFAndVersions(al, crfVersionById, 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.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class ViewItemDetailServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
int itemId = fp.getInt(ITEM_ID);
String itemOid = fp.getString(ITEM_OID);
ItemDAO idao = new ItemDAO(sm.getDataSource());
ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(sm.getDataSource());
ItemGroupMetadataDAO igmdao = new ItemGroupMetadataDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
SectionDAO sectionDao = new SectionDAO(sm.getDataSource());
if (itemId == 0 && itemOid == null) {
addPageMessage(respage.getString("please_choose_an_item_first"));
forwardPage(Page.ITEM_DETAIL);
return;
}
ItemBean item = itemId > 0 ? (ItemBean) idao.findByPK(itemId) : (ItemBean) idao.findByOid(itemOid).get(0);
ArrayList versions = idao.findAllVersionsByItemId(item.getId());
ArrayList versionItems = new ArrayList();
CRFBean crf = null;
ItemFormMetadataBean imfBean = null;
// finds each item metadata for each version
for (int i = 0; i < versions.size(); i++) {
Integer versionId = (Integer) versions.get(i);
CRFVersionBean version = (CRFVersionBean) cvdao.findByPK(versionId.intValue());
if (versionId != null && versionId.intValue() > 0) {
// YW 08-22-2007
if (igmdao.versionIncluded(versionId)) {
imfBean = ifmdao.findByItemIdAndCRFVersionId(item.getId(), versionId.intValue());
imfBean.setCrfVersionName(version.getName());
crf = (CRFBean) cdao.findByPK(version.getCrfId());
imfBean.setCrfName(crf.getName());
versionItems.add(imfBean);
} else {
imfBean = ifmdao.findByItemIdAndCRFVersionIdNotInIGM(item.getId(), versionId.intValue());
imfBean.setCrfVersionName(version.getName());
crf = (CRFBean) cdao.findByPK(version.getCrfId());
imfBean.setCrfName(crf.getName());
versionItems.add(imfBean);
}
}
}
SectionBean section = (SectionBean) sectionDao.findByPK(imfBean.getSectionId());
request.setAttribute(VERSION_ITEMS, versionItems);
request.setAttribute(ITEM_BEAN, item);
request.setAttribute("crf", crf);
request.setAttribute("section", section);
request.setAttribute("ifmdBean", imfBean);
forwardPage(Page.ITEM_DETAIL);
}
Aggregations