use of org.akaza.openclinica.bean.submit.DisplayItemBeanWrapper in project OpenClinica by OpenClinica.
the class ImportCRFDataServlet method processRequest.
@Override
public void processRequest() throws Exception {
resetPanel();
panel.setStudyInfoShown(false);
panel.setOrderedData(true);
FormProcessor fp = new FormProcessor(request);
// checks which module the requests are from
String module = fp.getString(MODULE);
// keep the module in the session
session.setAttribute(MODULE, module);
String action = request.getParameter("action");
CRFVersionBean version = (CRFVersionBean) session.getAttribute("version");
File xsdFile = new File(SpringServletAccess.getPropertiesDir(context) + "ODM1-3-0.xsd");
File xsdFile2 = new File(SpringServletAccess.getPropertiesDir(context) + "ODM1-2-1.xsd");
if (StringUtil.isBlank(action)) {
logger.info("action is blank");
request.setAttribute("version", version);
forwardPage(Page.IMPORT_CRF_DATA);
}
if ("confirm".equalsIgnoreCase(action)) {
String dir = SQLInitServlet.getField("filePath");
if (!new File(dir).exists()) {
logger.info("The filePath in datainfo.properties is invalid " + dir);
addPageMessage(respage.getString("filepath_you_defined_not_seem_valid"));
forwardPage(Page.IMPORT_CRF_DATA);
}
// All the uploaded files will be saved in filePath/crf/original/
String theDir = dir + "crf" + File.separator + "original" + File.separator;
if (!new File(theDir).isDirectory()) {
new File(theDir).mkdirs();
logger.info("Made the directory " + theDir);
}
// MultipartRequest multi = new MultipartRequest(request, theDir, 50 * 1024 * 1024);
File f = null;
try {
f = uploadFile(theDir, version);
} catch (Exception e) {
logger.warn("*** Found exception during file upload***");
e.printStackTrace();
}
if (f == null) {
forwardPage(Page.IMPORT_CRF_DATA);
}
// TODO
// validation steps
// 1. valid xml - validated by file uploader below
// LocalConfiguration config = LocalConfiguration.getInstance();
// config.getProperties().setProperty(
// "org.exolab.castor.parser.namespaces",
// "true");
// config
// .getProperties()
// .setProperty("org.exolab.castor.sax.features",
// "http://xml.org/sax/features/validation,
// http://apache.org/xml/features/validation/schema,
// http://apache.org/xml/features/validation/schema-full-checking");
// // above sets to validate against namespace
Mapping myMap = new Mapping();
// @pgawade 18-April-2011 Fix for issue 8394
String ODM_MAPPING_DIRPath = CoreResources.ODM_MAPPING_DIR;
myMap.loadMapping(ODM_MAPPING_DIRPath + File.separator + "cd_odm_mapping.xml");
Unmarshaller um1 = new Unmarshaller(myMap);
// um1.addNamespaceToPackageMapping("http://www.openclinica.org/ns/odm_ext_v130/v3.1", "OpenClinica");
// um1.addNamespaceToPackageMapping("http://www.cdisc.org/ns/odm/v1.3"
// ,
// "ODMContainer");
boolean fail = false;
ODMContainer odmContainer = new ODMContainer();
session.removeAttribute("odmContainer");
try {
// schemaValidator.validateAgainstSchema(f, xsdFile);
// utf-8 compliance, tbh 06/2009
InputStreamReader isr = new InputStreamReader(new FileInputStream(f), "UTF-8");
odmContainer = (ODMContainer) um1.unmarshal(isr);
logger.debug("Found crf data container for study oid: " + odmContainer.getCrfDataPostImportContainer().getStudyOID());
logger.debug("found length of subject list: " + odmContainer.getCrfDataPostImportContainer().getSubjectData().size());
// 2. validates against ODM 1.3
// check it all below, throw an exception and route to a
// different
// page if not working
// TODO this block of code needs the xerces serializer in order
// to
// work
// StringWriter myWriter = new StringWriter();
// Marshaller m1 = new Marshaller(myWriter);
//
// m1.setProperty("org.exolab.castor.parser.namespaces",
// "true");
// m1
// .setProperty("org.exolab.castor.sax.features",
// "http://xml.org/sax/features/validation,
// http://apache.org/xml/features/validation/schema,
// http://apache.org/xml/features/validation/schema-full-checking
// ");
//
// m1.setMapping(myMap);
// m1.setNamespaceMapping("",
// "http://www.cdisc.org/ns/odm/v1.3");
// m1.setSchemaLocation("http://www.cdisc.org/ns/odm/v1.3
// ODM1-3.xsd");
// m1.marshal(odmContainer);
// if you havent thrown it, you wont throw it here
addPageMessage(respage.getString("passed_xml_validation"));
} catch (Exception me1) {
me1.printStackTrace();
// expanding it to all exceptions, but hoping to catch Marshal
// Exception or SAX Exceptions
logger.info("found exception with xml transform");
//
logger.info("trying 1.2.1");
try {
schemaValidator.validateAgainstSchema(f, xsdFile2);
// for backwards compatibility, we also try to validate vs
// 1.2.1 ODM 06/2008
InputStreamReader isr = new InputStreamReader(new FileInputStream(f), "UTF-8");
odmContainer = (ODMContainer) um1.unmarshal(isr);
} catch (Exception me2) {
// not sure if we want to report me2
MessageFormat mf = new MessageFormat("");
mf.applyPattern(respage.getString("your_xml_is_not_well_formed"));
Object[] arguments = { me1.getMessage() };
addPageMessage(mf.format(arguments));
//
// addPageMessage("Your XML is not well-formed, and does not
// comply with the ODM 1.3 Schema. Please check it, and try
// again. It returned the message: "
// + me1.getMessage());
// me1.printStackTrace();
forwardPage(Page.IMPORT_CRF_DATA);
// you can't really wait to forward because then you throw
// NPEs
// in the next few parts of the code
}
}
// TODO need to output further here
// 2.a. is the study the same one that the user is in right now?
// 3. validates against study metadata
// 3.a. is that study subject in that study?
// 3.b. is that study event def in that study?
// 3.c. is that site in that study?
// 3.d. is that crf version in that study event def?
// 3.e. are those item groups in that crf version?
// 3.f. are those items in that item group?
List<String> errors = getImportCRFDataService().validateStudyMetadata(odmContainer, ub.getActiveStudyId());
if (errors != null) {
// add to session
// forward to another page
logger.info(errors.toString());
for (String error : errors) {
addPageMessage(error);
}
if (errors.size() > 0) {
// fail = true;
forwardPage(Page.IMPORT_CRF_DATA);
} else {
addPageMessage(respage.getString("passed_study_check"));
addPageMessage(respage.getString("passed_oid_metadata_check"));
}
}
logger.debug("passed error check");
// TODO ADD many validation steps before we get to the
// session-setting below
// 4. is the event in the correct status to accept data import?
// -- scheduled, data entry started, completed
// (and the event should already be created)
// (and the event should be independent, ie not affected by other
// events)
Boolean eventCRFStatusesValid = getImportCRFDataService().eventCRFStatusesValid(odmContainer, ub);
ImportCRFInfoContainer importCrfInfo = new ImportCRFInfoContainer(odmContainer, sm.getDataSource());
// The eventCRFBeans list omits EventCRFs that don't match UpsertOn rules. If EventCRF did not exist and
// doesn't match upsert, it won't be created.
List<EventCRFBean> eventCRFBeans = getImportCRFDataService().fetchEventCRFBeans(odmContainer, ub);
List<DisplayItemBeanWrapper> displayItemBeanWrappers = new ArrayList<DisplayItemBeanWrapper>();
HashMap<String, String> totalValidationErrors = new HashMap<String, String>();
HashMap<String, String> hardValidationErrors = new HashMap<String, String>();
// The following map is used for setting the EventCRF status post import.
HashMap<Integer, String> importedCRFStatuses = getImportCRFDataService().fetchEventCRFStatuses(odmContainer);
// method in the ImportCRFDataService is modified for this fix.
if (eventCRFBeans == null) {
fail = true;
addPageMessage(respage.getString("no_event_status_matching"));
} else {
ArrayList<Integer> permittedEventCRFIds = new ArrayList<Integer>();
logger.info("found a list of eventCRFBeans: " + eventCRFBeans.toString());
// List<DisplayItemBeanWrapper> displayItemBeanWrappers = new ArrayList<DisplayItemBeanWrapper>();
// HashMap<String, String> totalValidationErrors = new
// HashMap<String, String>();
// HashMap<String, String> hardValidationErrors = new
// HashMap<String, String>();
logger.debug("found event crfs " + eventCRFBeans.size());
// -- does the event already exist? if not, fail
if (!eventCRFBeans.isEmpty()) {
for (EventCRFBean eventCRFBean : eventCRFBeans) {
DataEntryStage dataEntryStage = eventCRFBean.getStage();
Status eventCRFStatus = eventCRFBean.getStatus();
logger.info("Event CRF Bean: id " + eventCRFBean.getId() + ", data entry stage " + dataEntryStage.getName() + ", status " + eventCRFStatus.getName());
if (eventCRFStatus.equals(Status.AVAILABLE) || dataEntryStage.equals(DataEntryStage.INITIAL_DATA_ENTRY) || dataEntryStage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) || dataEntryStage.equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) || dataEntryStage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
// actually want the negative
// was status == available and the stage questions, but
// when you are at 'data entry complete' your status is
// set to 'unavailable'.
// >> tbh 09/2008
// HOWEVER, when one event crf is removed and the rest
// are good, what happens???
// need to create a list and inform that one is blocked
// and the rest are not...
//
permittedEventCRFIds.add(new Integer(eventCRFBean.getId()));
} else {
// fail = true;
// addPageMessage(respage.getString(
// "the_event_crf_not_correct_status"));
// forwardPage(Page.IMPORT_CRF_DATA);
}
}
// did we exclude all the event CRFs? if not, pass, else fail
if (eventCRFBeans.size() >= permittedEventCRFIds.size()) {
addPageMessage(respage.getString("passed_event_crf_status_check"));
} else {
fail = true;
addPageMessage(respage.getString("the_event_crf_not_correct_status"));
}
try {
List<DisplayItemBeanWrapper> tempDisplayItemBeanWrappers = new ArrayList<DisplayItemBeanWrapper>();
tempDisplayItemBeanWrappers = getImportCRFDataService().lookupValidationErrors(request, odmContainer, ub, totalValidationErrors, hardValidationErrors, permittedEventCRFIds);
logger.debug("generated display item bean wrappers " + tempDisplayItemBeanWrappers.size());
logger.debug("size of total validation errors: " + totalValidationErrors.size());
displayItemBeanWrappers.addAll(tempDisplayItemBeanWrappers);
} catch (NullPointerException npe1) {
// what if you have 2 event crfs but the third is a fake?
fail = true;
logger.debug("threw a NPE after calling lookup validation errors");
System.out.println(ExceptionUtils.getStackTrace(npe1));
addPageMessage(respage.getString("an_error_was_thrown_while_validation_errors"));
// npe1.printStackTrace();
} catch (OpenClinicaException oce1) {
fail = true;
logger.debug("threw an OCE after calling lookup validation errors " + oce1.getOpenClinicaMessage());
addPageMessage(oce1.getOpenClinicaMessage());
}
} else if (!eventCRFStatusesValid) {
fail = true;
addPageMessage(respage.getString("the_event_crf_not_correct_status"));
} else {
fail = true;
addPageMessage(respage.getString("no_event_crfs_matching_the_xml_metadata"));
}
// for (HashMap<String, String> crfData : importedData) {
// DisplayItemBeanWrapper displayItemBeanWrapper =
// testing(request,
// crfData);
// displayItemBeanWrappers.add(displayItemBeanWrapper);
// errors = displayItemBeanWrapper.getValidationErrors();
//
// }
}
if (fail) {
logger.debug("failed here - forwarding...");
forwardPage(Page.IMPORT_CRF_DATA);
} else {
addPageMessage(respage.getString("passing_crf_edit_checks"));
session.setAttribute("odmContainer", odmContainer);
session.setAttribute("importedData", displayItemBeanWrappers);
session.setAttribute("validationErrors", totalValidationErrors);
session.setAttribute("hardValidationErrors", hardValidationErrors);
session.setAttribute("importedCRFStatuses", importedCRFStatuses);
session.setAttribute("importCrfInfo", importCrfInfo);
// above are updated 'statically' by the method that originally
// generated the wrappers; soon the only thing we will use
// wrappers for is the 'overwrite' flag
logger.debug("+++ content of total validation errors: " + totalValidationErrors.toString());
SummaryStatsBean ssBean = getImportCRFDataService().generateSummaryStatsBean(odmContainer, displayItemBeanWrappers, importCrfInfo);
session.setAttribute("summaryStats", ssBean);
// will have to set hard edit checks here as well
session.setAttribute("subjectData", odmContainer.getCrfDataPostImportContainer().getSubjectData());
forwardPage(Page.VERIFY_IMPORT_SERVLET);
}
// }
}
}
use of org.akaza.openclinica.bean.submit.DisplayItemBeanWrapper in project OpenClinica by OpenClinica.
the class VerifyImportedCRFDataServlet method processRequest.
@Override
@SuppressWarnings(value = "unchecked")
public void processRequest() throws Exception {
ItemDataDAO itemDataDao = new ItemDataDAO(sm.getDataSource());
itemDataDao.setFormatDates(false);
EventCRFDAO eventCrfDao = new EventCRFDAO(sm.getDataSource());
CrfBusinessLogicHelper crfBusinessLogicHelper = new CrfBusinessLogicHelper(sm.getDataSource());
String action = request.getParameter("action");
FormProcessor fp = new FormProcessor(request);
// checks which module the requests are from
String module = fp.getString(MODULE);
request.setAttribute(MODULE, module);
resetPanel();
panel.setStudyInfoShown(false);
panel.setOrderedData(true);
setToPanel(resword.getString("create_CRF"), respage.getString("br_create_new_CRF_entering"));
setToPanel(resword.getString("create_CRF_version"), respage.getString("br_create_new_CRF_uploading"));
setToPanel(resword.getString("revise_CRF_version"), respage.getString("br_if_you_owner_CRF_version"));
setToPanel(resword.getString("CRF_spreadsheet_template"), respage.getString("br_download_blank_CRF_spreadsheet_from"));
setToPanel(resword.getString("example_CRF_br_spreadsheets"), respage.getString("br_download_example_CRF_instructions_from"));
if ("confirm".equalsIgnoreCase(action)) {
List<DisplayItemBeanWrapper> displayItemBeanWrappers = (List<DisplayItemBeanWrapper>) session.getAttribute("importedData");
logger.info("Size of displayItemBeanWrappers : " + displayItemBeanWrappers.size());
forwardPage(Page.VERIFY_IMPORT_CRF_DATA);
}
if ("save".equalsIgnoreCase(action)) {
// setup ruleSets to run if applicable
RuleSetServiceInterface ruleSetService = (RuleSetServiceInterface) SpringServletAccess.getApplicationContext(context).getBean("ruleSetService");
List<ImportDataRuleRunnerContainer> containers = this.ruleRunSetup(sm.getDataSource(), currentStudy, ub, ruleSetService);
List<DisplayItemBeanWrapper> displayItemBeanWrappers = (List<DisplayItemBeanWrapper>) session.getAttribute("importedData");
// System.out.println("Size of displayItemBeanWrappers : " +
// displayItemBeanWrappers.size());
HashMap<Integer, String> importedCRFStatuses = (HashMap<Integer, String>) session.getAttribute("importedCRFStatuses");
for (DisplayItemBeanWrapper wrapper : displayItemBeanWrappers) {
boolean resetSDV = false;
int eventCrfBeanId = -1;
EventCRFBean eventCrfBean = new EventCRFBean();
// TODO : tom , the wrapper object has all the necessary data -
// as you see we check the
// is to see if this data is Savable if it is then we go ahead
// and save it. if not we discard.
// So the change needs to happen here , instead of discarding we
// need to file discrepancy notes
// and save the data. If you look in the
// Page.VERIFY_IMPORT_CRF_DATA jsp file you can see how I am
// pulling the errors. and use that in the same way.
logger.info("right before we check to make sure it is savable: " + wrapper.isSavable());
if (wrapper.isSavable()) {
ArrayList<Integer> eventCrfInts = new ArrayList<Integer>();
// wrapper.getValidationErrors().toString());
for (DisplayItemBean displayItemBean : wrapper.getDisplayItemBeans()) {
eventCrfBeanId = displayItemBean.getData().getEventCRFId();
eventCrfBean = (EventCRFBean) eventCrfDao.findByPK(eventCrfBeanId);
logger.info("found value here: " + displayItemBean.getData().getValue());
logger.info("found status here: " + eventCrfBean.getStatus().getName());
// System.out.println("found event crf bean name here: "
// +
// eventCrfBean.getEventName()+" id "+eventCrfBean.getId
// ());
// SO, items can be created in a wrapper which is set to
// overwrite
// we get around this by checking the bean first, to
// make sure it's not null
ItemDataBean itemDataBean = new ItemDataBean();
itemDataBean = itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(displayItemBean.getItem().getId(), eventCrfBean.getId(), displayItemBean.getData().getOrdinal());
if (wrapper.isOverwrite() && itemDataBean.getStatus() != null) {
if (!itemDataBean.getValue().equals(displayItemBean.getData().getValue()))
resetSDV = true;
logger.info("just tried to find item data bean on item name " + displayItemBean.getItem().getName());
itemDataBean.setUpdatedDate(new Date());
itemDataBean.setUpdater(ub);
itemDataBean.setValue(displayItemBean.getData().getValue());
// set status?
itemDataDao.update(itemDataBean);
logger.info("updated: " + itemDataBean.getItemId());
// need to set pk here in order to create dn
displayItemBean.getData().setId(itemDataBean.getId());
} else {
resetSDV = true;
itemDataDao.create(displayItemBean.getData());
logger.info("created: " + displayItemBean.getData().getItemId() + "event CRF ID = " + eventCrfBean.getId() + "CRF VERSION ID =" + eventCrfBean.getCRFVersionId());
// does this dao function work for repeating
// events/groups?
// ItemDataBean itemDataBean =
// itemDataDao.findByEventCRFIdAndItemName(
// eventCrfBean,
// displayItemBean.getItem().getName());
ItemDataBean itemDataBean2 = itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(displayItemBean.getItem().getId(), eventCrfBean.getId(), displayItemBean.getData().getOrdinal());
logger.info("found: id " + itemDataBean2.getId() + " name " + itemDataBean2.getName());
displayItemBean.getData().setId(itemDataBean2.getId());
}
// logger.info("created item data bean:
// "+displayItemBean.getData().getId());
// logger.info("created:
// "+displayItemBean.getData().getName());
// logger.info("continued:
// "+displayItemBean.getData().getItemId());
ItemDAO idao = new ItemDAO(sm.getDataSource());
ItemBean ibean = (ItemBean) idao.findByPK(displayItemBean.getData().getItemId());
// logger.info("continued2: getName " +
// ibean.getName());
// System.out.println("*** checking for validation errors: "
// + ibean.getName());
String itemOid = displayItemBean.getItem().getOid() + "_" + wrapper.getStudyEventRepeatKey() + "_" + displayItemBean.getData().getOrdinal() + "_" + wrapper.getStudySubjectOid();
if (wrapper.getValidationErrors().containsKey(itemOid)) {
ArrayList messageList = (ArrayList) wrapper.getValidationErrors().get(itemOid);
// could it be more than one? tbh 08/2008
for (int iter = 0; iter < messageList.size(); iter++) {
String message = (String) messageList.get(iter);
DiscrepancyNoteBean parentDn = ImportSpringJob.createDiscrepancyNote(ibean, message, eventCrfBean, displayItemBean, null, ub, sm.getDataSource(), currentStudy);
ImportSpringJob.createDiscrepancyNote(ibean, message, eventCrfBean, displayItemBean, parentDn.getId(), ub, sm.getDataSource(), currentStudy);
// System.out.println("*** created disc note with message: "
// + message);
// displayItemBean);
}
}
// "+displayItemBean.getDbData().getName());
if (!eventCrfInts.contains(new Integer(eventCrfBean.getId()))) {
String eventCRFStatus = importedCRFStatuses.get(new Integer(eventCrfBean.getId()));
if (eventCRFStatus != null && eventCRFStatus.equals(DataEntryStage.INITIAL_DATA_ENTRY.getName()) && eventCrfBean.getStatus().isAvailable()) {
crfBusinessLogicHelper.markCRFStarted(eventCrfBean, ub);
} else {
crfBusinessLogicHelper.markCRFComplete(eventCrfBean, ub);
}
eventCrfInts.add(new Integer(eventCrfBean.getId()));
}
}
// Reset the SDV status if item data has been changed or added
if (eventCrfBean != null && resetSDV)
eventCrfDao.setSDVStatus(false, ub.getId(), eventCrfBean.getId());
// end of item datas, tbh
// crfBusinessLogicHelper.markCRFComplete(eventCrfBean, ub);
// System .out.println("*** just updated event crf bean: "+
// eventCrfBean.getId());
// need to update the study event status as well, tbh
// crfBusinessLogicHelper.updateStudyEvent(eventCrfBean,
// ub);
// above should do it for us, tbh 08/2008
}
}
addPageMessage(respage.getString("data_has_been_successfully_import"));
addPageMessage(this.ruleActionWarnings(this.runRules(currentStudy, ub, containers, ruleSetService, ExecutionMode.SAVE)));
// forwardPage(Page.SUBMIT_DATA_SERVLET);
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
// replaced tbh, 06/2009
}
}
use of org.akaza.openclinica.bean.submit.DisplayItemBeanWrapper in project OpenClinica by OpenClinica.
the class DataImportService method submitData.
public ArrayList<String> submitData(ODMContainer odmContainer, DataSource dataSource, StudyBean studyBean, UserAccountBean userBean, List<DisplayItemBeanWrapper> displayItemBeanWrappers, Map<Integer, String> importedCRFStatuses) throws Exception {
boolean discNotesGenerated = false;
ItemDataDAO itemDataDao = new ItemDataDAO(dataSource);
itemDataDao.setFormatDates(false);
EventCRFDAO eventCrfDao = new EventCRFDAO(dataSource);
StringBuffer auditMsg = new StringBuffer();
int eventCrfBeanId = -1;
EventCRFBean eventCrfBean = null;
ArrayList<Integer> eventCrfInts;
ItemDataBean itemDataBean;
CrfBusinessLogicHelper crfBusinessLogicHelper = new CrfBusinessLogicHelper(dataSource);
for (DisplayItemBeanWrapper wrapper : displayItemBeanWrappers) {
boolean resetSDV = false;
logger.debug("right before we check to make sure it is savable: " + wrapper.isSavable());
if (wrapper.isSavable()) {
eventCrfInts = new ArrayList<Integer>();
logger.debug("wrapper problems found : " + wrapper.getValidationErrors().toString());
if (wrapper.getDisplayItemBeans() != null && wrapper.getDisplayItemBeans().size() == 0) {
return getReturnList("fail", "", "No items to submit. Please check your XML.");
}
for (DisplayItemBean displayItemBean : wrapper.getDisplayItemBeans()) {
eventCrfBeanId = displayItemBean.getData().getEventCRFId();
eventCrfBean = (EventCRFBean) eventCrfDao.findByPK(eventCrfBeanId);
logger.debug("found value here: " + displayItemBean.getData().getValue());
logger.debug("found status here: " + eventCrfBean.getStatus().getName());
itemDataBean = itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(displayItemBean.getItem().getId(), eventCrfBean.getId(), displayItemBean.getData().getOrdinal());
if (wrapper.isOverwrite() && itemDataBean.getStatus() != null) {
if (!itemDataBean.getValue().equals(displayItemBean.getData().getValue()))
resetSDV = true;
logger.debug("just tried to find item data bean on item name " + displayItemBean.getItem().getName());
itemDataBean.setUpdatedDate(new Date());
itemDataBean.setUpdater(userBean);
itemDataBean.setValue(displayItemBean.getData().getValue());
// set status?
itemDataDao.update(itemDataBean);
logger.debug("updated: " + itemDataBean.getItemId());
// need to set pk here in order to create dn
displayItemBean.getData().setId(itemDataBean.getId());
} else {
resetSDV = true;
itemDataDao.create(displayItemBean.getData());
logger.debug("created: " + displayItemBean.getData().getItemId());
itemDataBean = itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(displayItemBean.getItem().getId(), eventCrfBean.getId(), displayItemBean.getData().getOrdinal());
// logger.debug("found: id " + itemDataBean2.getId() + " name " + itemDataBean2.getName());
displayItemBean.getData().setId(itemDataBean.getId());
}
ItemDAO idao = new ItemDAO(dataSource);
ItemBean ibean = (ItemBean) idao.findByPK(displayItemBean.getData().getItemId());
// logger.debug("*** checking for validation errors: " + ibean.getName());
String itemOid = displayItemBean.getItem().getOid() + "_" + wrapper.getStudyEventRepeatKey() + "_" + displayItemBean.getData().getOrdinal() + "_" + wrapper.getStudySubjectOid();
// wrapper.getValidationErrors().toString());
if (wrapper.getValidationErrors().containsKey(itemOid)) {
ArrayList<String> messageList = (ArrayList<String>) wrapper.getValidationErrors().get(itemOid);
for (String message : messageList) {
DiscrepancyNoteBean parentDn = createDiscrepancyNote(ibean, message, eventCrfBean, displayItemBean, null, userBean, dataSource, studyBean);
createDiscrepancyNote(ibean, message, eventCrfBean, displayItemBean, parentDn.getId(), userBean, dataSource, studyBean);
discNotesGenerated = true;
logger.debug("*** created disc note with message: " + message);
auditMsg.append(wrapper.getStudySubjectOid() + ": " + ibean.getOid() + ": " + message + "---");
// split by this ? later, tbh
// displayItemBean);
}
}
if (!eventCrfInts.contains(new Integer(eventCrfBean.getId()))) {
String eventCRFStatus = importedCRFStatuses.get(new Integer(eventCrfBean.getId()));
if (eventCRFStatus != null && eventCRFStatus.equals(DataEntryStage.INITIAL_DATA_ENTRY.getName()) && eventCrfBean.getStatus().isAvailable()) {
crfBusinessLogicHelper.markCRFStarted(eventCrfBean, userBean, true);
} else {
crfBusinessLogicHelper.markCRFComplete(eventCrfBean, userBean, true);
}
eventCrfInts.add(new Integer(eventCrfBean.getId()));
}
}
// Reset the SDV status if item data has been changed or added
if (eventCrfBean != null && resetSDV)
eventCrfDao.setSDVStatus(false, userBean.getId(), eventCrfBean.getId());
}
}
if (!discNotesGenerated) {
return getReturnList("success", "", auditMsg.toString());
} else {
return getReturnList("warn", "", auditMsg.toString());
}
}
use of org.akaza.openclinica.bean.submit.DisplayItemBeanWrapper 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.bean.submit.DisplayItemBeanWrapper in project OpenClinica by OpenClinica.
the class ImportCRFDataService method generateSummaryStatsBean.
public SummaryStatsBean generateSummaryStatsBean(ODMContainer odmContainer, List<DisplayItemBeanWrapper> wrappers, ImportCRFInfoContainer importCrfInfo) {
int countSubjects = 0;
int countEventCRFs = 0;
int discNotesGenerated = 0;
for (DisplayItemBeanWrapper wr : wrappers) {
HashMap validations = wr.getValidationErrors();
discNotesGenerated += validations.size();
}
ArrayList<SubjectDataBean> subjectDataBeans = odmContainer.getCrfDataPostImportContainer().getSubjectData();
countSubjects += subjectDataBeans.size();
for (SubjectDataBean subjectDataBean : subjectDataBeans) {
ArrayList<StudyEventDataBean> studyEventDataBeans = subjectDataBean.getStudyEventData();
for (StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
ArrayList<FormDataBean> formDataBeans = studyEventDataBean.getFormData();
// this would be the place to add more stats
for (FormDataBean formDataBean : formDataBeans) {
countEventCRFs += 1;
}
}
}
SummaryStatsBean ssBean = new SummaryStatsBean();
ssBean.setDiscNoteCount(discNotesGenerated);
ssBean.setEventCrfCount(countEventCRFs);
ssBean.setStudySubjectCount(countSubjects);
ssBean.setSkippedCrfCount(importCrfInfo.getCountSkippedEventCrfs());
return ssBean;
}
Aggregations