use of org.akaza.openclinica.dao.submit.SectionDAO in project OpenClinica by OpenClinica.
the class TableOfContentsServlet method getSections.
public static ArrayList getSections(EventCRFBean ecb, DataSource ds) {
SectionDAO sdao = new SectionDAO(ds);
ItemGroupDAO igdao = new ItemGroupDAO(ds);
HashMap numItemsBySectionId = sdao.getNumItemsBySectionId();
HashMap numItemsPlusRepeatBySectionId = sdao.getNumItemsPlusRepeatBySectionId(ecb);
HashMap numItemsCompletedBySectionId = sdao.getNumItemsCompletedBySectionId(ecb);
HashMap numItemsPendingBySectionId = sdao.getNumItemsPendingBySectionId(ecb);
ArrayList sections = sdao.findAllByCRFVersionId(ecb.getCRFVersionId());
for (int i = 0; i < sections.size(); i++) {
SectionBean sb = (SectionBean) sections.get(i);
int sectionId = sb.getId();
Integer key = new Integer(sectionId);
// YW 10-11-2007 << handle number of item completion on tab.
int numItems = getIntById(numItemsBySectionId, key);
List<ItemGroupBean> itemGroups = igdao.findLegitGroupBySectionId(sectionId);
if (!itemGroups.isEmpty()) {
// this section has repeating rows-jxu
int numItemsPlusRepeat = getIntById(numItemsPlusRepeatBySectionId, key);
if (numItemsPlusRepeat > numItems) {
sb.setNumItems(numItemsPlusRepeat);
} else {
sb.setNumItems(numItems);
}
} else {
sb.setNumItems(numItems);
}
// According to logic that I searched from code of this package by
// this time,
// for double data entry and stage.initial_data_entry,
// pending should be the status in query.
int numItemsCompleted = getIntById(numItemsCompletedBySectionId, key);
// the following is removed to fix issue 2091-jxu
// if(numItemsCompleted == 0) {
// numItemsCompleted = getIntById(numItemsPendingBySectionId, key) ;
// }
sb.setNumItemsCompleted(numItemsCompleted);
// YW >>
sb.setNumItemsNeedingValidation(getIntById(numItemsPendingBySectionId, key));
sections.set(i, sb);
}
return sections;
}
use of org.akaza.openclinica.dao.submit.SectionDAO in project OpenClinica by OpenClinica.
the class FormBeanUtil method createDisplaySectionBWithFormGroups.
/**
* Create a DisplaySectionBean with a list of ItemGroupBeans. This List will
* include any ItemGroupBeans that are associated with ungrouped items; in
* other words, the DisplaySectionBean will represent a section that has
* both ungrouped and grouped tables.
*
* @param sectionId
* The Section ID associated with the Items, which end up
* providing the content of the tables.
* @param crfVersionId
* The CRF version ID associated with the Items.
* @param dataSource
* @param eventCRFDefId
* The id for the Event CRF Definition.
* @return A DisplaySectionBean with sorted ItemGroupBeans, meaning the
* ItemGroupBeans should be listed in the order that they appear on
* the CRF section.
* @return A DisplaySectionBean representing a CRF section.
*/
public DisplaySectionBean createDisplaySectionBWithFormGroups(int sectionId, int crfVersionId, DataSource dataSource, int eventCRFDefId, EventCRFBean eventCrfBean, ServletContext context) {
DisplaySectionBean displaySectionBean = new DisplaySectionBean();
ItemGroupDAO formGroupDAO = new ItemGroupDAO(dataSource);
ItemGroupMetadataDAO igMetaDAO = new ItemGroupMetadataDAO(dataSource);
ItemDAO itemDao = new ItemDAO(dataSource);
ItemFormMetadataDAO metaDao = new ItemFormMetadataDAO(dataSource);
SectionDAO sectionDao = new SectionDAO(dataSource);
// Give the DisplaySectionBean a legitimate SectionBean
SectionBean secBean = (SectionBean) sectionDao.findByPK(sectionId);
displaySectionBean.setSection(secBean);
// changed from: findGroupBySectionId
List<ItemGroupBean> itemGroupBeans = formGroupDAO.findLegitGroupAllBySectionId(sectionId);
// all items associated with the section, including those not in a group
List<ItemFormMetadataBean> allMetas = new ArrayList<ItemFormMetadataBean>();
try {
allMetas = metaDao.findAllBySectionId(sectionId);
} catch (OpenClinicaException oce) {
logger.info("oce.getOpenClinicaMessage() = " + oce.getOpenClinicaMessage());
}
// Sort these items according to their position on the CRF; their
// ordinal
Collections.sort(allMetas);
// The DisplayItemGroupBean(s) for "nongrouped" items
List<DisplayItemGroupBean> nonGroupBeans = null;
// if(itemGroupBeans.isEmpty()) return displaySectionBean;
// Find out whether there are any checkboxes/radios/select elements
// and if so, get any null values
// associated with them
List<String> nullValuesList = new ArrayList<String>();
boolean itemsHaveChecksRadios = itemsIncludeChecksRadiosSelects(allMetas);
if (itemsHaveChecksRadios && eventCRFDefId > 0) {
// method returns null values as a List<String>
nullValuesList = this.getNullValuesByEventCRFDefId(eventCRFDefId, dataSource);
}
// Get the items associated with each group
List<ItemBean> itBeans;
List<DisplayItemBean> displayItems;
List<DisplayItemGroupBean> displayFormBeans = new ArrayList<DisplayItemGroupBean>();
DisplayItemGroupBean displayItemGBean;
for (ItemGroupBean itemGroup : itemGroupBeans) {
itBeans = itemDao.findAllItemsByGroupId(itemGroup.getId(), crfVersionId);
logger.debug("just ran find all by group id " + itemGroup.getId() + " found " + itBeans.size() + " item beans");
List<ItemGroupMetadataBean> metadata = igMetaDAO.findMetaByGroupAndSection(itemGroup.getId(), crfVersionId, sectionId);
if (!metadata.isEmpty()) {
// for a given crf version, all the items in the same group
// have the same group metadata info
// so we can get one of the metadata and set the metadata for
// the group
ItemGroupMetadataBean meta = metadata.get(0);
itemGroup.setMeta(meta);
}
displayItems = getDisplayBeansFromItems(itBeans, dataSource, eventCrfBean, sectionId, nullValuesList, context);
displayItemGBean = this.createDisplayFormGroup(displayItems, itemGroup);
displayFormBeans.add(displayItemGBean);
}
// We still have to sort these display item group beans on their
// ItemGroupMetadataBean?
// then number their ordinals accordingly
Collections.sort(displayFormBeans, new Comparator<DisplayItemGroupBean>() {
public int compare(DisplayItemGroupBean displayItemGroupBean, DisplayItemGroupBean displayItemGroupBean1) {
return displayItemGroupBean.getGroupMetaBean().compareTo(displayItemGroupBean1.getGroupMetaBean());
}
});
// Now provide the display item group beans with an ordinal
int digOrdinal = 0;
for (DisplayItemGroupBean digBean : displayFormBeans) {
digBean.setOrdinal(++digOrdinal);
}
// find out whether there are any ungrouped items by comparing the
// number of
// grouped items to allMetas.size()
// List<DisplayItemGroupBean> nonGroupBeans=null;
int tempCount = 0;
for (DisplayItemGroupBean groupBean : displayFormBeans) {
tempCount += groupBean.getItems().size();
}
if (tempCount < allMetas.size()) {
nonGroupBeans = createGroupBeansForNongroupedItems(allMetas, displayFormBeans, sectionId, dataSource, nullValuesList, eventCrfBean, context);
}
if (nonGroupBeans != null) {
displayFormBeans.addAll(nonGroupBeans);
}
// sort the list according to the ordinal of the contained
// DisplayItemGroupBeans
Collections.sort(displayFormBeans, new Comparator<DisplayItemGroupBean>() {
public int compare(DisplayItemGroupBean disFormGroupBean, DisplayItemGroupBean disFormGroupBean1) {
Integer compInt = disFormGroupBean1.getOrdinal();
Integer compInt2 = disFormGroupBean.getOrdinal();
return compInt2.compareTo(compInt);
}
});
displaySectionBean.setDisplayFormGroups(displayFormBeans);
return displaySectionBean;
}
use of org.akaza.openclinica.dao.submit.SectionDAO 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);
}
}
}
use of org.akaza.openclinica.dao.submit.SectionDAO in project OpenClinica by OpenClinica.
the class RemoveCRFVersionServlet method processRequest.
@Override
public void processRequest() throws Exception {
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
int versionId = fp.getInt("id", true);
String module = fp.getString("module");
request.setAttribute("module", module);
String action = fp.getString("action");
if (versionId == 0) {
addPageMessage(respage.getString("please_choose_a_CRF_version_to_remove"));
forwardPage(Page.CRF_LIST_SERVLET);
} else {
if (StringUtil.isBlank(action)) {
addPageMessage(respage.getString("no_action_specified"));
forwardPage(Page.CRF_LIST_SERVLET);
return;
}
CRFVersionBean version = (CRFVersionBean) cvdao.findByPK(versionId);
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;
}
SectionDAO secdao = new SectionDAO(sm.getDataSource());
EventCRFDAO evdao = new EventCRFDAO(sm.getDataSource());
// find all event crfs by version id
ArrayList eventCRFs = evdao.findUndeletedWithStudySubjectsByCRFVersion(versionId);
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute("versionToRemove", version);
request.setAttribute("eventCRFs", eventCRFs);
forwardPage(Page.REMOVE_CRF_VERSION);
} else {
logger.info("submit to remove the crf version");
// version
version.setStatus(Status.DELETED);
version.setUpdater(ub);
version.setUpdatedDate(new Date());
cvdao.update(version);
// crfs in the second pass
for (int ii = 0; ii < eventCRFs.size(); ii++) {
EventCRFBean ecbean = (EventCRFBean) eventCRFs.get(ii);
ecbean.setStatus(Status.AUTO_DELETED);
ecbean.setUpdater(ub);
ecbean.setUpdatedDate(new Date());
evdao.update(ecbean);
}
// added above tbh 092007, to fix task
// all sections
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);
}
}
// all item data related to event crfs
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);
}
}
}
}
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);
updateEventDef(edcBean, edCRFDao, versionList);
}
}
addPageMessage(respage.getString("the_CRF") + version.getName() + " " + respage.getString("has_been_removed_succesfully"));
forwardPage(Page.CRF_LIST_SERVLET);
}
}
}
use of org.akaza.openclinica.dao.submit.SectionDAO in project OpenClinica by OpenClinica.
the class ViewTableOfContentServlet method getDisplayBean.
public static DisplayTableOfContentsBean getDisplayBean(DataSource ds, int crfVersionId) {
DisplayTableOfContentsBean answer = new DisplayTableOfContentsBean();
SectionDAO sdao = new SectionDAO(ds);
ArrayList sections = getSections(crfVersionId, ds);
answer.setSections(sections);
CRFVersionDAO cvdao = new CRFVersionDAO(ds);
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(crfVersionId);
answer.setCrfVersion(cvb);
CRFDAO cdao = new CRFDAO(ds);
CRFBean cb = (CRFBean) cdao.findByPK(cvb.getCrfId());
answer.setCrf(cb);
answer.setEventCRF(new EventCRFBean());
answer.setStudyEventDefinition(new StudyEventDefinitionBean());
return answer;
}
Aggregations