use of org.akaza.openclinica.dao.submit.ItemDAO in project OpenClinica by OpenClinica.
the class ImportCRFDataService method lookupValidationErrors.
public List<DisplayItemBeanWrapper> lookupValidationErrors(HttpServletRequest request, ODMContainer odmContainer, UserAccountBean ub, HashMap<String, String> totalValidationErrors, HashMap<String, String> hardValidationErrors, ArrayList<Integer> permittedEventCRFIds) throws OpenClinicaException {
DisplayItemBeanWrapper displayItemBeanWrapper = null;
HashMap validationErrors = new HashMap();
List<DisplayItemBeanWrapper> wrappers = new ArrayList<DisplayItemBeanWrapper>();
ImportHelper importHelper = new ImportHelper();
FormDiscrepancyNotes discNotes = new FormDiscrepancyNotes();
DiscrepancyValidator discValidator = new DiscrepancyValidator(request, discNotes);
// create a second Validator, this one for hard edit checks
HashMap<String, String> hardValidator = new HashMap<String, String>();
StudyEventDAO studyEventDAO = new StudyEventDAO(ds);
StudyDAO studyDAO = new StudyDAO(ds);
StudyBean studyBean = studyDAO.findByOid(odmContainer.getCrfDataPostImportContainer().getStudyOID());
StudySubjectDAO studySubjectDAO = new StudySubjectDAO(ds);
StudyEventDefinitionDAO sedDao = new StudyEventDefinitionDAO(ds);
HashMap<String, ItemDataBean> blankCheck = new HashMap<String, ItemDataBean>();
String hardValidatorErrorMsgs = "";
ArrayList<SubjectDataBean> subjectDataBeans = odmContainer.getCrfDataPostImportContainer().getSubjectData();
int totalEventCRFCount = 0;
int totalItemDataBeanCount = 0;
for (SubjectDataBean subjectDataBean : subjectDataBeans) {
ArrayList<DisplayItemBean> displayItemBeans = new ArrayList<DisplayItemBean>();
logger.debug("iterating through subject data beans: found " + subjectDataBean.getSubjectOID());
ArrayList<StudyEventDataBean> studyEventDataBeans = subjectDataBean.getStudyEventData();
totalEventCRFCount += studyEventDataBeans.size();
StudySubjectBean studySubjectBean = studySubjectDAO.findByOidAndStudy(subjectDataBean.getSubjectOID(), studyBean.getId());
for (StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
int parentStudyId = studyBean.getParentStudyId();
StudyEventDefinitionBean sedBean = sedDao.findByOidAndStudy(studyEventDataBean.getStudyEventOID(), studyBean.getId(), parentStudyId);
ArrayList<FormDataBean> formDataBeans = studyEventDataBean.getFormData();
logger.debug("iterating through study event data beans: found " + studyEventDataBean.getStudyEventOID());
int ordinal = 1;
try {
ordinal = new Integer(studyEventDataBean.getStudyEventRepeatKey()).intValue();
} catch (Exception e) {
// trying to catch NPEs, because tags can be without the
// repeat key
}
StudyEventBean studyEvent = (StudyEventBean) studyEventDAO.findByStudySubjectIdAndDefinitionIdAndOrdinal(studySubjectBean.getId(), sedBean.getId(), ordinal);
displayItemBeans = new ArrayList<DisplayItemBean>();
for (FormDataBean formDataBean : formDataBeans) {
Map<String, Integer> groupMaxOrdinals = new HashMap<String, Integer>();
displayItemBeanWrapper = null;
CRFVersionDAO crfVersionDAO = new CRFVersionDAO(ds);
EventCRFDAO eventCRFDAO = new EventCRFDAO(ds);
ArrayList<CRFVersionBean> crfVersionBeans = crfVersionDAO.findAllByOid(formDataBean.getFormOID());
ArrayList<ImportItemGroupDataBean> itemGroupDataBeans = formDataBean.getItemGroupData();
if ((crfVersionBeans == null) || (crfVersionBeans.size() == 0)) {
MessageFormat mf = new MessageFormat("");
mf.applyPattern(respage.getString("your_crf_version_oid_did_not_generate"));
Object[] arguments = { formDataBean.getFormOID() };
throw new OpenClinicaException(mf.format(arguments), "");
}
CRFVersionBean crfVersion = crfVersionBeans.get(0);
// if you have a mispelled form oid you get an error here
// need to error out gracefully and post an error
logger.debug("iterating through form beans: found " + crfVersion.getOid());
// may be the point where we cut off item groups etc and
// instead work on sections
EventCRFBean eventCRFBean = eventCRFDAO.findByEventCrfVersion(studyEvent, crfVersion);
EventDefinitionCRFDAO eventDefinitionCRFDAO = new EventDefinitionCRFDAO(ds);
EventDefinitionCRFBean eventDefinitionCRF = eventDefinitionCRFDAO.findByStudyEventIdAndCRFVersionId(studyBean, studyEvent.getId(), crfVersion.getId());
if (eventCRFBean != null) {
if (permittedEventCRFIds.contains(new Integer(eventCRFBean.getId()))) {
for (ImportItemGroupDataBean itemGroupDataBean : itemGroupDataBeans) {
groupMaxOrdinals.put(itemGroupDataBean.getItemGroupOID(), 1);
}
// correctness, tbh
for (ImportItemGroupDataBean itemGroupDataBean : itemGroupDataBeans) {
ArrayList<ItemBean> blankCheckItems = new ArrayList<ItemBean>();
ArrayList<ImportItemDataBean> itemDataBeans = itemGroupDataBean.getItemData();
logger.debug("iterating through group beans: " + itemGroupDataBean.getItemGroupOID());
// put a checker in here
ItemGroupDAO itemGroupDAO = new ItemGroupDAO(ds);
ItemGroupBean testBean = itemGroupDAO.findByOid(itemGroupDataBean.getItemGroupOID());
if (testBean == null) {
// TODO i18n of message
MessageFormat mf = new MessageFormat("");
mf.applyPattern(respage.getString("your_item_group_oid_for_form_oid"));
Object[] arguments = { itemGroupDataBean.getItemGroupOID(), formDataBean.getFormOID() };
throw new OpenClinicaException(mf.format(arguments), "");
}
totalItemDataBeanCount += itemDataBeans.size();
for (ImportItemDataBean importItemDataBean : itemDataBeans) {
logger.debug(" iterating through item data beans: " + importItemDataBean.getItemOID());
ItemDAO itemDAO = new ItemDAO(ds);
ItemFormMetadataDAO itemFormMetadataDAO = new ItemFormMetadataDAO(ds);
List<ItemBean> itemBeans = itemDAO.findByOid(importItemDataBean.getItemOID());
if (!itemBeans.isEmpty()) {
ItemBean itemBean = itemBeans.get(0);
logger.debug(" found " + itemBean.getName());
// throw a null pointer? hopefully not if its been checked...
DisplayItemBean displayItemBean = new DisplayItemBean();
displayItemBean.setItem(itemBean);
ArrayList<ItemFormMetadataBean> metadataBeans = itemFormMetadataDAO.findAllByItemId(itemBean.getId());
logger.debug(" found metadata item beans: " + metadataBeans.size());
int groupOrdinal = 1;
if (itemGroupDataBean.getItemGroupRepeatKey() != null) {
try {
groupOrdinal = new Integer(itemGroupDataBean.getItemGroupRepeatKey()).intValue();
if (groupOrdinal > groupMaxOrdinals.get(itemGroupDataBean.getItemGroupOID())) {
groupMaxOrdinals.put(itemGroupDataBean.getItemGroupOID(), groupOrdinal);
}
} catch (Exception e) {
// do nothing here currently, we are
// looking for a number format
// exception
// from the above.
logger.debug("found npe for group ordinals, line 344!");
}
}
ItemDataBean itemDataBean = createItemDataBean(itemBean, eventCRFBean, importItemDataBean.getValue(), ub, groupOrdinal);
blankCheckItems.add(itemBean);
String newKey = groupOrdinal + "_" + itemGroupDataBean.getItemGroupOID() + "_" + itemBean.getOid() + "_" + subjectDataBean.getSubjectOID();
blankCheck.put(newKey, itemDataBean);
logger.info("adding " + newKey + " to blank checks");
if (!metadataBeans.isEmpty()) {
ItemFormMetadataBean metadataBean = metadataBeans.get(0);
// also possible nullpointer
displayItemBean.setData(itemDataBean);
displayItemBean.setMetadata(metadataBean);
displayItemBean.setEventDefinitionCRF(eventDefinitionCRF);
String eventCRFRepeatKey = studyEventDataBean.getStudyEventRepeatKey();
// if you do indeed leave off this in the XML it will pass but return 'null'
// tbh
attachValidator(displayItemBean, importHelper, discValidator, hardValidator, request, eventCRFRepeatKey, studySubjectBean.getOid());
displayItemBeans.add(displayItemBean);
} else {
MessageFormat mf = new MessageFormat("");
mf.applyPattern(respage.getString("no_metadata_could_be_found"));
Object[] arguments = { importItemDataBean.getItemOID() };
throw new OpenClinicaException(mf.format(arguments), "");
}
} else {
// report the error there
MessageFormat mf = new MessageFormat("");
mf.applyPattern(respage.getString("no_item_could_be_found"));
Object[] arguments = { importItemDataBean.getItemOID() };
throw new OpenClinicaException(mf.format(arguments), "");
}
}
// end item data beans
logger.debug(".. found blank check: " + blankCheck.toString());
for (int i = 1; i <= groupMaxOrdinals.get(itemGroupDataBean.getItemGroupOID()); i++) {
for (ItemBean itemBean : blankCheckItems) {
String newKey = i + "_" + itemGroupDataBean.getItemGroupOID() + "_" + itemBean.getOid() + "_" + subjectDataBean.getSubjectOID();
if (blankCheck.get(newKey) == null) {
// if it already exists, Do Not Add It.
ItemDataBean itemDataCheck = getItemDataDao().findByItemIdAndEventCRFIdAndOrdinal(itemBean.getId(), eventCRFBean.getId(), i);
logger.debug("found item data bean id: " + itemDataCheck.getId() + " for ordinal " + i);
if (itemDataCheck.getId() == 0) {
ItemDataBean blank = createItemDataBean(itemBean, eventCRFBean, "", ub, i);
DisplayItemBean displayItemBean = new DisplayItemBean();
displayItemBean.setItem(itemBean);
displayItemBean.setData(blank);
// displayItemBean.setMetadata(metadataBean);
// set event def crf?
displayItemBean.setEventDefinitionCRF(eventDefinitionCRF);
String eventCRFRepeatKey = studyEventDataBean.getStudyEventRepeatKey();
// if you do indeed leave off this in the XML it will pass but return
// 'null'
// tbh
displayItemBeans.add(displayItemBean);
logger.debug("... adding display item bean");
}
}
logger.debug("found a blank at " + i + ", adding " + blankCheckItems.size() + " blank items");
}
}
// << tbh #5548
blankCheckItems = new ArrayList<ItemBean>();
}
// end item group data beans
}
// matches if on permittedCRFIDs
CRFDAO crfDAO = new CRFDAO(ds);
CRFBean crfBean = crfDAO.findByVersionId(crfVersion.getCrfId());
// seems like an extravagance, but is not contained in crf
// version or event crf bean
validationErrors = discValidator.validate();
// totalValidationErrors.addAll(validationErrors);
for (Object errorKey : validationErrors.keySet()) {
// JN: to avoid duplicate errors
if (!totalValidationErrors.containsKey(errorKey.toString()))
totalValidationErrors.put(errorKey.toString(), validationErrors.get(errorKey).toString());
// assuming that this will be put back in to the core
// method's hashmap, updating statically, tbh 06/2008
logger.debug("+++ adding " + errorKey.toString());
}
logger.debug("-- hard validation checks: --");
for (Object errorKey : hardValidator.keySet()) {
logger.debug(errorKey.toString() + " -- " + hardValidator.get(errorKey));
hardValidationErrors.put(errorKey.toString(), hardValidator.get(errorKey));
// updating here 'statically' tbh 06/2008
hardValidatorErrorMsgs += hardValidator.get(errorKey) + "<br/><br/>";
}
String studyEventId = studyEvent.getId() + "";
String crfVersionId = crfVersion.getId() + "";
logger.debug("creation of wrapper: original count of display item beans " + displayItemBeans.size() + ", count of item data beans " + totalItemDataBeanCount + " count of validation errors " + validationErrors.size() + " count of study subjects " + subjectDataBeans.size() + " count of event crfs " + totalEventCRFCount + " count of hard error checks " + hardValidator.size());
// check if we need to overwrite
DataEntryStage dataEntryStage = eventCRFBean.getStage();
Status eventCRFStatus = eventCRFBean.getStatus();
boolean overwrite = false;
// //JN: Commenting out the following 2 lines, coz the prompt should come in the cases on
if (// eventCRFStatus.equals(Status.UNAVAILABLE) ||
dataEntryStage.equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) || dataEntryStage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) || dataEntryStage.equals(DataEntryStage.INITIAL_DATA_ENTRY) || dataEntryStage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
overwrite = true;
}
// << tbh, adding extra statuses to prevent appending, 06/2009
// SummaryStatsBean ssBean = new SummaryStatsBean();
// ssBean.setDiscNoteCount(totalValidationErrors);
// ssBean.setEventCrfCount(totalEventCRFCount);
// ssBean.setStudySubjectCount(subjectDataBeans.size());
// // add other stats here, tbh
// not working here, need to do it in a different method,
// tbh
// summary stats added tbh 05/2008
// JN: Changed from validationErrors to totalValidationErrors to create discrepancy notes for
// all
// the
displayItemBeanWrapper = new DisplayItemBeanWrapper(displayItemBeans, true, overwrite, validationErrors, studyEventId, crfVersionId, studyEventDataBean.getStudyEventOID(), studySubjectBean.getLabel(), eventCRFBean.getCreatedDate(), crfBean.getName(), crfVersion.getName(), studySubjectBean.getOid(), studyEventDataBean.getStudyEventRepeatKey());
// JN: Commenting out the following code, since we shouldn't re-initialize at this point, as
// validationErrors would get overwritten and the
// older errors will be overriden. Moving it after the form.
// Removing the comments for now, since it seems to be creating duplicate Discrepancy Notes.
validationErrors = new HashMap();
discValidator = new DiscrepancyValidator(request, discNotes);
// reset to allow for new errors...
}
}
// discValidator = new DiscrepancyValidator(request, discNotes);
if (displayItemBeanWrapper != null && displayItemBeans.size() > 0)
wrappers.add(displayItemBeanWrapper);
}
// after study events
// remove repeats here? remove them below by only forwarding the
// first
// each wrapper represents an Event CRF and a Form, but we don't
// have all events for all forms
// need to not add a wrapper for every event + form combination,
// but instead for every event + form combination which is present
// look at the hack below and see what happens
}
// thrown, tbh 06/2008
if (!hardValidator.isEmpty()) {
// throw new OpenClinicaException(hardValidatorErrorMsgs, "");
}
return wrappers;
}
use of org.akaza.openclinica.dao.submit.ItemDAO 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.dao.submit.ItemDAO 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);
}
use of org.akaza.openclinica.dao.submit.ItemDAO in project OpenClinica by OpenClinica.
the class ViewSelectedServlet method processRequest.
@Override
public void processRequest() throws Exception {
DatasetBean db = (DatasetBean) session.getAttribute("newDataset");
HashMap events = (HashMap) session.getAttribute(CreateDatasetServlet.EVENTS_FOR_CREATE_DATASET);
if (events == null) {
events = new HashMap();
}
request.setAttribute("eventlist", events);
CRFDAO crfdao = new CRFDAO(sm.getDataSource());
ItemDAO idao = new ItemDAO(sm.getDataSource());
ItemFormMetadataDAO imfdao = new ItemFormMetadataDAO(sm.getDataSource());
// new
ArrayList ids = CreateDatasetServlet.allSedItemIdsInStudy(events, crfdao, idao);
// ArrayList();
// ArrayList allItemsInStudy = EditSelectedServlet.selectAll(events,
// crfdao, idao);
// for (int j = 0; j < allItemsInStudy.size(); j++) {
// ItemBean item = (ItemBean) allItemsInStudy.get(j);
// Integer itemId = new Integer(item.getId());
// if (!ids.contains(itemId)) {
// ids.add(itemId);
// }
// }
session.setAttribute("numberOfStudyItems", new Integer(ids.size()).toString());
ArrayList items = new ArrayList();
if (db == null || db.getItemIds().size() == 0) {
session.setAttribute("allSelectedItems", items);
// FIXME can it be that we have no selected
setUpStudyGroups();
// items and
// some selected groups? tbh
forwardPage(Page.CREATE_DATASET_VIEW_SELECTED);
return;
}
items = getAllSelected(db, idao, imfdao);
session.setAttribute("allSelectedItems", items);
FormProcessor fp = new FormProcessor(request);
String status = fp.getString("status");
if (!StringUtil.isBlank(status) && "html".equalsIgnoreCase(status)) {
forwardPage(Page.CREATE_DATASET_VIEW_SELECTED_HTML);
} else {
setUpStudyGroups();
forwardPage(Page.CREATE_DATASET_VIEW_SELECTED);
}
}
use of org.akaza.openclinica.dao.submit.ItemDAO in project OpenClinica by OpenClinica.
the class ResolveDiscrepancyServlet method prepareRequestForResolution.
public boolean prepareRequestForResolution(HttpServletRequest request, DataSource ds, StudyBean currentStudy, DiscrepancyNoteBean note, boolean isCompleted) throws Exception {
String entityType = note.getEntityType().toLowerCase();
int id = note.getEntityId();
if ("subject".equalsIgnoreCase(entityType)) {
StudySubjectDAO ssdao = new StudySubjectDAO(ds);
StudySubjectBean ssb = ssdao.findBySubjectIdAndStudy(id, currentStudy);
request.setAttribute("action", "show");
request.setAttribute("id", String.valueOf(note.getEntityId()));
request.setAttribute("studySubId", String.valueOf(ssb.getId()));
} else if ("studysub".equalsIgnoreCase(entityType)) {
request.setAttribute("action", "show");
request.setAttribute("id", String.valueOf(note.getEntityId()));
} else if ("eventcrf".equalsIgnoreCase(entityType)) {
request.setAttribute("editInterview", "1");
EventCRFDAO ecdao = new EventCRFDAO(ds);
EventCRFBean ecb = (EventCRFBean) ecdao.findByPK(id);
request.setAttribute(TableOfContentsServlet.INPUT_EVENT_CRF_BEAN, ecb);
// If the request is passed along to ViewSectionDataEntryServlet,
// that code needs
// an event crf id; the (ecb.getId()+"") is necessary because
// FormProcessor throws
// a ClassCastException without the casting to a String
request.setAttribute(ViewSectionDataEntryServlet.EVENT_CRF_ID, ecb.getId() + "");
} else if ("studyevent".equalsIgnoreCase(entityType)) {
StudyEventDAO sedao = new StudyEventDAO(ds);
StudyEventBean seb = (StudyEventBean) sedao.findByPK(id);
request.setAttribute(EnterDataForStudyEventServlet.INPUT_EVENT_ID, String.valueOf(id));
request.setAttribute(UpdateStudyEventServlet.EVENT_ID, String.valueOf(id));
request.setAttribute(UpdateStudyEventServlet.STUDY_SUBJECT_ID, String.valueOf(seb.getStudySubjectId()));
} else // this is for item data
if ("itemdata".equalsIgnoreCase(entityType)) {
ItemDataDAO iddao = new ItemDataDAO(ds);
ItemDAO idao = new ItemDAO(ds);
ItemDataBean idb = (ItemDataBean) iddao.findByPK(id);
ItemBean item = (ItemBean) idao.findByPK(idb.getItemId());
ItemGroupMetadataDAO igmdao = new ItemGroupMetadataDAO<>(ds);
EventCRFDAO ecdao = new EventCRFDAO(ds);
EventCRFBean ecb = (EventCRFBean) ecdao.findByPK(idb.getEventCRFId());
FormLayoutDAO fldao = new FormLayoutDAO(ds);
FormLayoutBean formLayout = (FormLayoutBean) fldao.findByPK(ecb.getFormLayoutId());
StudyEventDAO sedao = new StudyEventDAO(ds);
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean ssb = (StudySubjectBean) ssdao.findByPK(ecb.getStudySubjectId());
ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(ds);
ItemFormMetadataBean ifmb = ifmdao.findByItemIdAndCRFVersionId(idb.getItemId(), ecb.getFormLayoutId());
ItemGroupMetadataBean igmBean = (ItemGroupMetadataBean) igmdao.findByItemAndCrfVersion(idb.getItemId(), ecb.getCRFVersionId());
ItemGroupDAO igdao = new ItemGroupDAO<>(ds);
ItemGroupBean igBean = (ItemGroupBean) igdao.findByPK(igmBean.getItemGroupId());
int repeatOrdinal = idb.getOrdinal();
ItemDataBean idata = null;
if (idb != null && idb.isDeleted()) {
return false;
}
if (igmBean.isRepeatingGroup() && repeatOrdinal > 1) {
List<ItemGroupMetadataBean> igms = igmdao.findMetaByGroupAndCrfVersion(igBean.getId(), ecb.getCRFVersionId());
for (int i = 0; i < idb.getOrdinal(); i++) {
for (ItemGroupMetadataBean igm : igms) {
idata = iddao.findByItemIdAndEventCRFIdAndOrdinal(igm.getItemId(), ecb.getId(), i + 1);
if (idata != null && idata.isDeleted()) {
repeatOrdinal--;
break;
}
}
}
}
EnketoUrlService enketoUrlService = (EnketoUrlService) SpringServletAccess.getApplicationContext(context).getBean("enketoUrlService");
StudyEventBean seb = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
// Cache the subject context for use during xform submission
PFormCache cache = PFormCache.getInstance(context);
PFormCacheSubjectContextEntry subjectContext = new PFormCacheSubjectContextEntry();
subjectContext.setStudySubjectOid(ssb.getOid());
subjectContext.setStudyEventDefinitionId(seb.getStudyEventDefinitionId());
subjectContext.setOrdinal(seb.getSampleOrdinal());
subjectContext.setFormLayoutOid(formLayout.getOid());
subjectContext.setUserAccountId(ub.getId());
subjectContext.setItemName(item.getName() + COMMENT);
subjectContext.setItemRepeatOrdinal(repeatOrdinal);
subjectContext.setItemInRepeatingGroup(igmBean.isRepeatingGroup());
subjectContext.setItemRepeatGroupName(igBean.getLayoutGroupPath());
String contextHash = cache.putSubjectContext(subjectContext);
String formUrl = null;
if (ecb.getId() > 0) {
formUrl = enketoUrlService.getEditUrl(contextHash, subjectContext, currentStudy.getOid(), null, null, QUERY_FLAVOR);
} else {
formUrl = enketoUrlService.getInitialDataEntryUrl(contextHash, subjectContext, currentStudy.getOid(), QUERY_FLAVOR);
}
int hashIndex = formUrl.lastIndexOf("#");
String part1 = formUrl;
String part2 = "";
if (hashIndex != -1) {
part1 = formUrl.substring(0, hashIndex);
part2 = formUrl.substring(hashIndex);
}
request.setAttribute(EnketoFormServlet.FORM_URL1, part1);
request.setAttribute(EnketoFormServlet.FORM_URL2, part2);
}
return true;
}
Aggregations