use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.
the class RandomizeActionValidator method validateOidInPropertyBean.
public void validateOidInPropertyBean(PropertyBean propertyBean, Errors e, String p) {
if (getExpressionService().isExpressionPartial(getRuleSetBean().getTarget().getValue())) {
if (getExpressionService().getExpressionSize(propertyBean.getOid()).intValue() > 3) {
e.rejectValue(p + "oid", "oid.invalid", "OID: " + propertyBean.getOid() + " is Invalid.");
}
try {
getExpressionService().isExpressionValid(propertyBean.getOid());
} catch (OpenClinicaSystemException ose) {
e.rejectValue(p + "oid", "oid.invalid", "OID: " + propertyBean.getOid() + " is Invalid.");
}
// Use OID in destinationProperty to get CRF
CRFBean destinationPropertyOidCrf = getExpressionService().getCRFFromExpression(propertyBean.getOid());
if (destinationPropertyOidCrf == null) {
ItemBean item = getExpressionService().getItemBeanFromExpression(propertyBean.getOid());
destinationPropertyOidCrf = getCrfDAO().findByItemOid(item.getOid());
}
// Use Target get CRF
CRFBean targetCrf = getExpressionService().getCRFFromExpression(getRuleSetBean().getTarget().getValue());
if (targetCrf == null) {
ItemBean item = getExpressionService().getItemBeanFromExpression(getRuleSetBean().getTarget().getValue());
targetCrf = getCrfDAO().findByItemOid(item.getOid());
}
// Get All event definitions the selected CRF belongs to
List<StudyEventDefinitionBean> destinationPropertyStudyEventDefinitions = getStudyEventDefinitionDAO().findAllByCrf(destinationPropertyOidCrf);
List<StudyEventDefinitionBean> targetStudyEventDefinitions = getStudyEventDefinitionDAO().findAllByCrf(targetCrf);
Collection intersection = CollectionUtils.intersection(destinationPropertyStudyEventDefinitions, targetStudyEventDefinitions);
if (intersection.size() == 0) {
e.rejectValue(p + "oid", "oid.invalid", "OID: " + propertyBean.getOid() + " is Invalid.");
}
} else {
String expression = getExpressionService().constructFullExpressionIfPartialProvided(propertyBean.getOid(), getRuleSetBean().getTarget().getValue());
ItemBean item = getExpressionService().getItemBeanFromExpression(expression);
if (!getExpressionService().isRandomizeActionExpressionValid(propertyBean.getOid(), getRuleSetBean(), 3) || item == null) {
e.rejectValue(p + "oid", "oid.invalid", "OID: " + propertyBean.getOid() + " is Invalid.");
}
}
}
use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.
the class ExpressionService method getEventDefinitionCRF.
public EventDefinitionCRFBean getEventDefinitionCRF(String expression) {
if (expression.split(ESCAPED_SEPERATOR).length < 4) {
return null;
}
StudyEventDefinitionBean studyEventDefinition = getStudyEventDefinitionFromExpression(expression);
CRFBean crf = getCRFFromExpression(expression);
if (studyEventDefinition == null || crf == null)
throw new OpenClinicaSystemException("OCRERR_0020");
return getEventDefinitionCRFDao().findByStudyEventDefinitionIdAndCRFId(this.expressionWrapper.getStudyBean(), studyEventDefinition.getId(), crf.getId());
}
use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.
the class EditSelectedServlet method selectAll.
/**
* Finds all the items in a study giving all events in the study
*
* @param events
* @return
*/
public static ArrayList selectAll(HashMap events, CRFDAO crfdao, ItemDAO idao) {
ArrayList allItems = new ArrayList();
Iterator it = events.keySet().iterator();
while (it.hasNext()) {
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) it.next();
ArrayList crfs = (ArrayList) crfdao.findAllActiveByDefinition(sed);
for (int i = 0; i < crfs.size(); i++) {
CRFBean crf = (CRFBean) crfs.get(i);
ArrayList items = idao.findAllActiveByCRF(crf);
for (int j = 0; j < items.size(); j++) {
ItemBean item = (ItemBean) items.get(j);
item.setCrfName(crf.getName());
item.setDefName(sed.getName());
item.setDefId(sed.getId());
item.setSelected(true);
}
allItems.addAll(items);
}
}
return allItems;
}
use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.
the class SelectItemsServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
int crfId = fp.getInt("crfId");
int defId = fp.getInt("defId");
int eventAttr = fp.getInt("eventAttr");
int subAttr = fp.getInt("subAttr");
int CRFAttr = fp.getInt("CRFAttr");
int groupAttr = fp.getInt("groupAttr");
int discAttr = fp.getInt("discAttr");
CRFDAO crfdao = new CRFDAO(sm.getDataSource());
ItemDAO idao = new ItemDAO(sm.getDataSource());
ItemFormMetadataDAO imfdao = new ItemFormMetadataDAO(sm.getDataSource());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
HashMap events = (HashMap) session.getAttribute(CreateDatasetServlet.EVENTS_FOR_CREATE_DATASET);
if (events == null) {
events = new HashMap();
}
request.setAttribute("eventlist", events);
logger.info("found dob setting: " + currentStudy.getStudyParameterConfig().getCollectDob());
if (crfId == 0) {
// no crf selected
if (eventAttr == 0 && subAttr == 0 && CRFAttr == 0 && groupAttr == 0 && discAttr == 0) {
forwardPage(Page.CREATE_DATASET_2);
} else if (eventAttr > 0) {
request.setAttribute("subjectAgeAtEvent", "1");
if (currentStudy.getStudyParameterConfig().getCollectDob().equals("3")) {
request.setAttribute("subjectAgeAtEvent", "0");
logger.info("dob not collected, setting age at event to 0");
}
forwardPage(Page.CREATE_DATASET_EVENT_ATTR);
} else if (subAttr > 0) {
if (currentStudy.getStudyParameterConfig().getCollectDob().equals("3")) {
logger.info("dob not collected, setting age at event to 0");
}
forwardPage(Page.CREATE_DATASET_SUB_ATTR);
} else if (CRFAttr > 0) {
forwardPage(Page.CREATE_DATASET_CRF_ATTR);
} else if (groupAttr > 0) {
// TODO set up subject group classes here?
setUpStudyGroupPage();
forwardPage(Page.CREATE_DATASET_GROUP_ATTR);
} else // else if (discAttr > 0) {
// forwardPage(Page.CREATE_DATASET_DISC_ATTR);
// }
{
forwardPage(Page.CREATE_DATASET_2);
}
return;
}
CRFBean crf = (CRFBean) crfdao.findByPK(crfId);
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(defId);
session.setAttribute("crf", crf);
session.setAttribute("definition", sed);
DatasetBean db = (DatasetBean) session.getAttribute("newDataset");
if (db == null) {
db = new DatasetBean();
}
session.setAttribute("newDataset", db);
// save current def id in the seesion to avoid duplicated def id in
// dataset
// bean
// session.setAttribute(CURRENT_DEF_ID, new Integer(defId));
ArrayList items = idao.findAllActiveByCRF(crf);
for (int i = 0; i < items.size(); i++) {
ItemBean item = (ItemBean) items.get(i);
/*
* logger.info("testing on item id "+ item.getId()+ " crf version id "+
* item.getItemMeta().getCrfVersionId());
*/
ItemFormMetadataBean meta = imfdao.findByItemIdAndCRFVersionId(item.getId(), item.getItemMeta().getCrfVersionId());
// TODO change the above data access function, tbh
// ArrayList metas = imfdao.findAllByItemId(item.getId());
meta.setCrfVersionName(item.getItemMeta().getCrfVersionName());
// logger.info("crf versionname" + meta.getCrfVersionName());
item.getItemMetas().add(meta);
// item.setItemMetas(metas);
}
HashMap itemMap = new HashMap();
for (int i = 0; i < items.size(); i++) {
ItemBean item = (ItemBean) items.get(i);
if (!itemMap.containsKey(defId + "_" + item.getId())) {
if (db.getItemMap().containsKey(defId + "_" + item.getId())) {
item.setSelected(true);
item.setDatasetItemMapKey(defId + "_" + item.getId());
// logger.info("Item got selected already11");
}
// itemMap.put(new Integer(item.getId()), item);
itemMap.put(defId + "_" + item.getId(), item);
} else {
// same item,combine the metadata
ItemBean uniqueItem = (ItemBean) itemMap.get(defId + "_" + item.getId());
uniqueItem.getItemMetas().add(item.getItemMetas().get(0));
if (db.getItemMap().containsKey(defId + "_" + uniqueItem.getId())) {
uniqueItem.setSelected(true);
// logger.info("Item got selected already22");
}
}
}
ArrayList itemArray = new ArrayList(itemMap.values());
// now sort them by ordinal/name
Collections.sort(itemArray);
session.setAttribute("allItems", itemArray);
forwardPage(Page.CREATE_DATASET_2);
}
use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.
the class DiscrepancyNoteOutputServlet method populateRowsWithAttachedData.
private ArrayList<DiscrepancyNoteBean> populateRowsWithAttachedData(ArrayList<DiscrepancyNoteBean> noteRows) {
Locale l = LocaleResolver.getLocale(request);
resword = ResourceBundleProvider.getWordsBundle(l);
resformat = ResourceBundleProvider.getFormatBundle(l);
SimpleDateFormat sdf = new SimpleDateFormat(resformat.getString("date_format_string"), ResourceBundleProvider.getLocale());
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
StudySubjectDAO studySubjectDAO = new StudySubjectDAO(sm.getDataSource());
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
ItemDAO idao = new ItemDAO(sm.getDataSource());
StudyDAO studyDao = new StudyDAO(sm.getDataSource());
ItemGroupMetadataDAO<String, ArrayList> igmdao = new ItemGroupMetadataDAO<String, ArrayList>(sm.getDataSource());
ItemGroupDAO<String, ArrayList> igdao = new ItemGroupDAO<String, ArrayList>(sm.getDataSource());
ArrayList<DiscrepancyNoteBean> allNotes = new ArrayList<DiscrepancyNoteBean>();
for (int i = 0; i < noteRows.size(); i++) {
DiscrepancyNoteBean dnb = noteRows.get(i);
dnb.setCreatedDateString(dnb.getCreatedDate() == null ? "" : sdf.format(dnb.getCreatedDate()));
if (dnb.getParentDnId() == 0) {
ArrayList children = dndao.findAllByStudyAndParent(currentStudy, dnb.getId());
children = children == null ? new ArrayList() : children;
dnb.setNumChildren(children.size());
dnb.setChildren(children);
int lastDnId = dnb.getId();
int lastChild = 0;
for (int j = 0; j < children.size(); j++) {
DiscrepancyNoteBean child = (DiscrepancyNoteBean) children.get(j);
child.setCreatedDateString(child.getCreatedDate() == null ? "" : sdf.format(child.getCreatedDate()));
child.setUpdatedDateString(child.getCreatedDate() != null ? sdf.format(child.getCreatedDate()) : "");
if (child.getId() > lastDnId) {
lastDnId = child.getId();
lastChild = j;
}
}
if (children.size() > 0) {
DiscrepancyNoteBean lastdn = (DiscrepancyNoteBean) children.get(lastChild);
// dnb.setResStatus(ResolutionStatus.get(lastdn.getResolutionStatusId()));
/*
* The update date is the date created of the latest child
* note
*/
dnb.setUpdatedDate(lastdn.getCreatedDate());
dnb.setUpdatedDateString(dnb.getUpdatedDate() != null ? sdf.format(dnb.getUpdatedDate()) : "");
}
}
String entityType = dnb.getEntityType();
if (dnb.getEntityId() > 0 && !entityType.equals("")) {
AuditableEntityBean aeb = dndao.findEntity(dnb);
dnb.setEntityName(aeb.getName());
if (entityType.equalsIgnoreCase("subject")) {
// allNotes.add(dnb);
SubjectBean sb = (SubjectBean) aeb;
StudySubjectBean ssb = studySubjectDAO.findBySubjectIdAndStudy(sb.getId(), currentStudy);
dnb.setStudySub(ssb);
dnb.setSubjectName(ssb.getLabel());
String column = dnb.getColumn().trim();
if (!StringUtil.isBlank(column)) {
if ("gender".equalsIgnoreCase(column)) {
dnb.setEntityValue(sb.getGender() + "");
dnb.setEntityName(resword.getString("gender"));
} else if ("date_of_birth".equals(column)) {
if (sb.getDateOfBirth() != null) {
dnb.setEntityValue(sb.getDateOfBirth().toString());
}
dnb.setEntityName(resword.getString("date_of_birth"));
} else if ("unique_identifier".equalsIgnoreCase(column)) {
dnb.setEntityName(resword.getString("unique_identifier"));
dnb.setEntityValue(sb.getUniqueIdentifier());
}
}
} else if (entityType.equalsIgnoreCase("studySub")) {
// allNotes.add(dnb);
StudySubjectBean ssb = (StudySubjectBean) aeb;
dnb.setStudySub(ssb);
dnb.setSubjectName(ssb.getLabel());
String column = dnb.getColumn().trim();
if (!StringUtil.isBlank(column)) {
if ("enrollment_date".equals(column)) {
if (ssb.getEnrollmentDate() != null) {
dnb.setEntityValue(ssb.getEnrollmentDate().toString());
}
dnb.setEntityName(resword.getString("enrollment_date"));
}
}
} else if (entityType.equalsIgnoreCase("eventCRF")) {
StudyEventBean se = (StudyEventBean) sedao.findByPK(dnb.getEntityId());
StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
EventCRFBean ecb = (EventCRFBean) aeb;
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(ecb.getCRFVersionId());
CRFBean cb = (CRFBean) cdao.findByPK(cvb.getCrfId());
dnb.setStageId(ecb.getStage().getId());
dnb.setEntityName(cb.getName() + " (" + cvb.getName() + ")");
StudySubjectBean ssub = (StudySubjectBean) studySubjectDAO.findByPK(ecb.getStudySubjectId());
dnb.setStudySub(ssub);
dnb.setSubjectName(ssub.getLabel());
if (se != null) {
dnb.setEventStart(se.getDateStarted());
dnb.setEventName(se.getName());
}
dnb.setCrfName(cb.getName());
String crfStatus = resword.getString(ecb.getStage().getNameRaw());
if (crfStatus.equals("Invalid")) {
crfStatus = "";
} else if (crfStatus.equals("Data Entry Complete")) {
crfStatus = "Complete";
}
dnb.setCrfStatus(crfStatus);
String column = dnb.getColumn().trim();
if (!StringUtil.isBlank(column)) {
if ("date_interviewed".equals(column)) {
if (ecb.getDateInterviewed() != null) {
dnb.setEntityValue(ecb.getDateInterviewed().toString());
}
dnb.setEntityName(resword.getString("date_interviewed"));
} else if ("interviewer_name".equals(column)) {
dnb.setEntityValue(ecb.getInterviewerName());
dnb.setEntityName(resword.getString("interviewer_name"));
}
}
dnb.setEvent(se);
dnb.setStudyEventDefinitionBean(sedb);
// }
} else if (entityType.equalsIgnoreCase("studyEvent")) {
// allNotes.add(dnb);
StudyEventBean se = (StudyEventBean) sedao.findByPK(dnb.getEntityId());
StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
se.setName(sedb.getName());
dnb.setEntityName(sedb.getName());
StudySubjectBean ssub = (StudySubjectBean) studySubjectDAO.findByPK(se.getStudySubjectId());
dnb.setStudySub(ssub);
dnb.setEventStart(se.getDateStarted());
dnb.setEventName(se.getName());
dnb.setSubjectName(ssub.getLabel());
String column = dnb.getColumn().trim();
if (!StringUtil.isBlank(column)) {
if ("date_start".equals(column)) {
if (se.getDateStarted() != null) {
dnb.setEntityValue(se.getDateStarted().toString());
}
dnb.setEntityName(resword.getString("start_date"));
} else if ("date_end".equals(column)) {
if (se.getDateEnded() != null) {
dnb.setEntityValue(se.getDateEnded().toString());
}
dnb.setEntityName(resword.getString("end_date"));
} else if ("location".equals(column)) {
dnb.setEntityValue(se.getLocation());
dnb.setEntityName(resword.getString("location"));
}
}
dnb.setEvent(se);
dnb.setStudyEventDefinitionBean(sedb);
} else if (entityType.equalsIgnoreCase("itemData")) {
ItemDataBean idb = (ItemDataBean) iddao.findByPK(dnb.getEntityId());
ItemBean ib = (ItemBean) idao.findByPK(idb.getItemId());
EventCRFBean ec = (EventCRFBean) ecdao.findByPK(idb.getEventCRFId());
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(ec.getCRFVersionId());
CRFBean cb = (CRFBean) cdao.findByPK(cvb.getCrfId());
ItemGroupMetadataBean itemGroupMetadataBean = (ItemGroupMetadataBean) igmdao.findByItemAndCrfVersion(ib.getId(), cvb.getId());
Boolean isRepeatForSure = itemGroupMetadataBean.isRepeatingGroup();
if (isRepeatForSure) {
ItemGroupBean ig = (ItemGroupBean) igdao.findByPK(itemGroupMetadataBean.getItemGroupId());
dnb.setItemDataOrdinal(idb.getOrdinal());
dnb.setItemGroupName(ig.getName());
}
// allNotes.add(dnb);
dnb.setStageId(ec.getStage().getId());
dnb.setEntityName(ib.getName());
dnb.setEntityValue(idb.getValue());
StudyEventBean se = (StudyEventBean) sedao.findByPK(ec.getStudyEventId());
StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
se.setName(sedb.getName());
StudySubjectBean ssub = (StudySubjectBean) studySubjectDAO.findByPK(ec.getStudySubjectId());
dnb.setStudySub(ssub);
dnb.setSubjectName(ssub.getLabel());
dnb.setEventStart(se.getDateStarted());
dnb.setEventName(se.getName());
dnb.setCrfName(cb.getName());
String crfStatus = resword.getString(ec.getStage().getNameRaw());
if (crfStatus.equals("Invalid")) {
crfStatus = "";
} else if (crfStatus.equals("Data Entry Complete")) {
crfStatus = "Complete";
}
dnb.setCrfStatus(crfStatus);
dnb.setEvent(se);
dnb.setStudyEventDefinitionBean(sedb);
}
}
dnb.setStudy((StudyBean) studyDao.findByPK(dnb.getStudyId()));
if (dnb.getParentDnId() == 0 && dnb.getChildren().size() > 0) {
ArrayList<DiscrepancyNoteBean> children = dnb.getChildren();
int childrenSize = children.size();
for (int j = 0; j < childrenSize; j++) {
DiscrepancyNoteBean child = children.get(j);
child.setSubjectName(dnb.getSubjectName());
child.setEventName(dnb.getEventName());
child.setCrfName(dnb.getCrfName());
child.setCrfStatus(dnb.getCrfStatus());
child.setEntityName(dnb.getEntityName());
child.setEntityValue(dnb.getEntityValue());
child.setStudySub(dnb.getStudySub());
child.setStudy(dnb.getStudy());
}
}
allNotes.add(dnb);
}
return allNotes;
}
Aggregations