use of org.akaza.openclinica.dao.submit.ItemDAO in project OpenClinica by OpenClinica.
the class SecureController method getNoteInfo.
public DiscrepancyNoteBean getNoteInfo(DiscrepancyNoteBean note) {
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
if ("itemData".equalsIgnoreCase(note.getEntityType())) {
int itemDataId = note.getEntityId();
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
ItemDataBean itemData = (ItemDataBean) iddao.findByPK(itemDataId);
ItemDAO idao = new ItemDAO(sm.getDataSource());
if (StringUtil.isBlank(note.getEntityName())) {
ItemBean item = (ItemBean) idao.findByPK(itemData.getItemId());
note.setEntityName(item.getName());
request.setAttribute("item", item);
}
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
StudyEventDAO svdao = new StudyEventDAO(sm.getDataSource());
EventCRFBean ec = (EventCRFBean) ecdao.findByPK(itemData.getEventCRFId());
StudyEventBean event = (StudyEventBean) svdao.findByPK(ec.getStudyEventId());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(event.getStudyEventDefinitionId());
note.setEventName(sed.getName());
note.setEventStart(event.getDateStarted());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFBean crf = cdao.findByVersionId(ec.getCRFVersionId());
note.setCrfName(crf.getName());
note.setEventCRFId(ec.getId());
if (StringUtil.isBlank(note.getSubjectName())) {
StudySubjectBean ss = (StudySubjectBean) ssdao.findByPK(ec.getStudySubjectId());
note.setSubjectName(ss.getName());
}
if (note.getDiscrepancyNoteTypeId() == 0) {
// default
note.setDiscrepancyNoteTypeId(DiscrepancyNoteType.FAILEDVAL.getId());
// value
}
} else if ("eventCrf".equalsIgnoreCase(note.getEntityType())) {
int eventCRFId = note.getEntityId();
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
StudyEventDAO svdao = new StudyEventDAO(sm.getDataSource());
EventCRFBean ec = (EventCRFBean) ecdao.findByPK(eventCRFId);
StudyEventBean event = (StudyEventBean) svdao.findByPK(ec.getStudyEventId());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(event.getStudyEventDefinitionId());
note.setEventName(sed.getName());
note.setEventStart(event.getDateStarted());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFBean crf = cdao.findByVersionId(ec.getCRFVersionId());
note.setCrfName(crf.getName());
StudySubjectBean ss = (StudySubjectBean) ssdao.findByPK(ec.getStudySubjectId());
note.setSubjectName(ss.getName());
note.setEventCRFId(ec.getId());
} else if ("studyEvent".equalsIgnoreCase(note.getEntityType())) {
int eventId = note.getEntityId();
StudyEventDAO svdao = new StudyEventDAO(sm.getDataSource());
StudyEventBean event = (StudyEventBean) svdao.findByPK(eventId);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(event.getStudyEventDefinitionId());
note.setEventName(sed.getName());
note.setEventStart(event.getDateStarted());
StudySubjectBean ss = (StudySubjectBean) ssdao.findByPK(event.getStudySubjectId());
note.setSubjectName(ss.getName());
} else if ("studySub".equalsIgnoreCase(note.getEntityType())) {
int studySubjectId = note.getEntityId();
StudySubjectBean ss = (StudySubjectBean) ssdao.findByPK(studySubjectId);
note.setSubjectName(ss.getName());
} else if ("Subject".equalsIgnoreCase(note.getEntityType())) {
int subjectId = note.getEntityId();
StudySubjectBean ss = ssdao.findBySubjectIdAndStudy(subjectId, currentStudy);
note.setSubjectName(ss.getName());
}
return note;
}
use of org.akaza.openclinica.dao.submit.ItemDAO in project OpenClinica by OpenClinica.
the class VariableSubstitutionHelper method buildTokensMap.
@SuppressWarnings("unchecked")
private static Map<String, String> buildTokensMap(DisplaySectionBean section, StudySubjectBean studySubject, StudyBean study, StudyEventDefinitionBean eventDef, StudyEventBean event, DataSource dataSource) {
ItemDAO itemDAO = new ItemDAO(dataSource);
List<ItemBean> items = itemDAO.findAllWithItemDataByFormLayoutId(section.getCrfVersion().getId(), section.getEventCRF().getId());
Map<String, String> tokensMap = new HashMap<String, String>();
tokensMap.put("studySubject", encode(studySubject.getName()));
if (studySubject.getOid() != null && !studySubject.getOid().isEmpty()) {
tokensMap.put("studySubjectOID", encode(studySubject.getOid()));
} else
tokensMap.put("studySubjectOID", "");
tokensMap.put("studyName", encode(study.getName()));
tokensMap.put("eventName", encode(eventDef.getName()));
if (event == null)
tokensMap.put("eventOrdinal", "");
else
tokensMap.put("eventOrdinal", encode(Integer.toString(event.getSampleOrdinal())));
tokensMap.put("crfName", encode(section.getCrf().getName()));
tokensMap.put("crfVersion", encode(section.getCrfVersion().getName()));
// Render a set of "item['ITEM_NAME']" tokens for existing item data
for (ItemBean item : items) {
// If the item has multiple values, combine them in a comma-separated list
List<String> values = new ArrayList<String>();
for (ItemDataBean itemData : item.getItemDataElements()) {
values.add(itemData.getValue());
}
String value = StringUtils.join(values, ',');
tokensMap.put("item['" + item.getName() + "']", encode(value));
}
if (LOG.isDebugEnabled()) {
for (String key : tokensMap.keySet()) {
LOG.debug("Substitution context: {} = {}", key, tokensMap.get(key));
}
}
return tokensMap;
}
use of org.akaza.openclinica.dao.submit.ItemDAO in project OpenClinica by OpenClinica.
the class ViewRuleAssignmentNewServlet method createStudyEventForInfoPanel.
private void createStudyEventForInfoPanel() {
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ItemDAO itemdao = new ItemDAO(sm.getDataSource());
StudyBean studyWithEventDefinitions = currentStudy;
if (currentStudy.getParentStudyId() > 0) {
studyWithEventDefinitions = new StudyBean();
studyWithEventDefinitions.setId(currentStudy.getParentStudyId());
}
CRFDAO crfdao = new CRFDAO(sm.getDataSource());
ArrayList seds = seddao.findAllActiveByStudy(studyWithEventDefinitions);
HashMap events = new LinkedHashMap();
for (int i = 0; i < seds.size(); i++) {
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seds.get(i);
ArrayList<CRFBean> crfs = (ArrayList<CRFBean>) crfdao.findAllActiveByDefinition(sed);
if (currentStudy.getParentStudyId() > 0) {
// sift through these CRFs and see which ones are hidden
HideCRFManager hideCRFs = HideCRFManager.createHideCRFManager();
crfs = hideCRFs.removeHiddenCRFBeans(studyWithEventDefinitions, sed, crfs, sm.getDataSource());
}
if (!crfs.isEmpty()) {
events.put(sed, crfs);
}
}
request.setAttribute("eventlist", events);
request.setAttribute("crfCount", crfdao.getCountofActiveCRFs());
request.setAttribute("itemCount", itemdao.getCountofActiveItems());
request.setAttribute("ruleSetCount", getRuleSetService().getRuleSetDao().count(currentStudy));
}
use of org.akaza.openclinica.dao.submit.ItemDAO in project OpenClinica by OpenClinica.
the class FormBeanUtil method createDisplaySectionBWithFormGroupsForPrint.
public DisplaySectionBean createDisplaySectionBWithFormGroupsForPrint(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) {
//TODO:fix me!
itBeans = itemDao.findAllItemsByGroupIdForPrint(itemGroup.getId(), crfVersionId, sectionId);
logger.debug("just ran find all by group id " + itemGroup.getId() + " found " + itBeans.size() + " item beans");
//TODO:fix me add item_form_metadata.section_id to the query
List<ItemGroupMetadataBean> metadata = igMetaDAO.findMetaByGroupAndSectionForPrint(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 = getDisplayBeansFromItemsForPrint(itBeans, dataSource, eventCrfBean, sectionId, nullValuesList, context, crfVersionId);
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.ItemDAO in project OpenClinica by OpenClinica.
the class FormBeanUtil method getDisplayBeanFromSingleItem.
public DisplayItemBean getDisplayBeanFromSingleItem(ItemFormMetadataBean itemFBean, int sectionId, DataSource dataSource, EventCRFBean eventCrfBean, List<String> nullValuesList, ServletContext context) {
DisplayItemBean disBean = new DisplayItemBean();
ItemBean itemBean = new ItemBean();
ItemDAO itemDAO = new ItemDAO(dataSource);
ItemDataDAO itemDataDao = new ItemDataDAO(dataSource);
if (itemFBean == null)
return disBean;
itemBean = (ItemBean) itemDAO.findByPK(itemFBean.getItemId());
if (itemBean == null) {
itemBean = new ItemBean();
}
// Add any null values to checks or radios
String responseName;
List<ResponseOptionBean> respOptions;
ResponseOptionBean respBean;
boolean hasNullValues = nullValuesList != null && !nullValuesList.isEmpty();
// Only include Items that belong to the associated section
if (itemFBean.getSectionId() == sectionId) {
ItemDataBean itemDataBean = itemDataDao.findByItemIdAndEventCRFId(itemBean.getId(), eventCrfBean.getId());
disBean.setItem(itemBean);
disBean.setMetadata(runDynamicsCheck(itemFBean, eventCrfBean, itemDataBean, context));
disBean.setData(itemDataBean);
logger.debug("3. just set: " + itemDataBean.getValue());
responseName = disBean.getMetadata().getResponseSet().getResponseType().getName();
respOptions = disBean.getMetadata().getResponseSet().getOptions();
if (hasNullValues && respOptions != null && ("checkbox".equalsIgnoreCase(responseName) || "radio".equalsIgnoreCase(responseName) || "single-select".equalsIgnoreCase(responseName) || "multi-select".equalsIgnoreCase(responseName))) {
this.addBeansToResponseOptions(nullValuesList, respOptions);
}
}
return disBean;
}
Aggregations