use of org.akaza.openclinica.bean.submit.EventCRFBean 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.EventCRFBean in project OpenClinica by OpenClinica.
the class ListDiscNotesForCRFTableFactory method setDataAndLimitVariables.
@SuppressWarnings("unchecked")
@Override
public void setDataAndLimitVariables(TableFacade tableFacade) {
Limit limit = tableFacade.getLimit();
ListDiscNotesForCRFFilter listDiscNotesForCRF = getListEventsForSubjectFilter(limit);
listDiscNotesForCRF.addFilter("dn.discrepancy_note_type_id", this.discNoteType);
StringBuffer constraints = new StringBuffer();
if (this.discNoteType > 0 && this.discNoteType < 10) {
constraints.append(" and dn.discrepancy_note_type_id=" + this.discNoteType);
}
if (this.resolutionStatusIds != null && this.resolutionStatusIds.size() > 0) {
String s = " and (";
for (Integer resolutionStatusId : this.resolutionStatusIds) {
s += "dn.resolution_status_id = " + resolutionStatusId + " or ";
}
s = s.substring(0, s.length() - 3) + " )";
listDiscNotesForCRF.addFilter("dn.resolution_status_id", s);
constraints.append(s);
}
if (!limit.isComplete()) {
int totalRows = getStudySubjectDAO().getCountWithFilter(listDiscNotesForCRF, getStudyBean());
tableFacade.setTotalRows(totalRows);
}
ListDiscNotesForCRFSort eventsForSubjectSort = getListEventsForSubjectSort(limit);
int rowStart = limit.getRowSelect().getRowStart();
int rowEnd = limit.getRowSelect().getRowEnd();
Collection<StudySubjectBean> items = getStudySubjectDAO().getWithFilterAndSort(getStudyBean(), listDiscNotesForCRF, eventsForSubjectSort, rowStart, rowEnd);
Collection<HashMap<Object, Object>> theItems = new ArrayList<HashMap<Object, Object>>();
boolean hasDN = false;
for (StudySubjectBean studySubjectBean : items) {
HashMap<Object, Object> theItem = new HashMap<Object, Object>();
theItem.put("studySubject", studySubjectBean);
theItem.put("studySubject.label", studySubjectBean.getLabel());
theItem.put("studySubject.status", studySubjectBean.getStatus());
SubjectBean subjectBean = (SubjectBean) getSubjectDAO().findByPK(studySubjectBean.getSubjectId());
theItem.put("subject", subjectBean);
theItem.put("subject.charGender", subjectBean.getGender());
// Get EventCrfs for study Subject
List<EventCRFBean> eventCrfs = getEventCRFDAO().findAllByStudySubject(studySubjectBean.getId());
HashMap<String, EventCRFBean> crfAsKeyEventCrfAsValue = new HashMap<String, EventCRFBean>();
for (EventCRFBean eventCRFBean : eventCrfs) {
CRFBean crf = getCrfDAO().findByVersionId(eventCRFBean.getCRFVersionId());
crfAsKeyEventCrfAsValue.put(crf.getId() + "_" + eventCRFBean.getStudyEventId(), eventCRFBean);
}
// Get the event Status
List<StudyEventBean> eventsForStudySubjectAndEventDefinitions = getStudyEventDAO().findAllByDefinitionAndSubject(selectedStudyEventDefinition, studySubjectBean);
List<DisplayBean> events = new ArrayList<DisplayBean>();
// study event size < 1
if (eventsForStudySubjectAndEventDefinitions.size() < 1) {
DisplayBean d = new DisplayBean();
d.getProps().put("event", null);
d.getProps().put("event.status", SubjectEventStatus.NOT_SCHEDULED);
d.getProps().put("event.startDate", null);
for (int i = 0; i < getCrfs(selectedStudyEventDefinition).size(); i++) {
CRFBean crf = getCrfs(selectedStudyEventDefinition).get(i);
HashMap<ResolutionStatus, Integer> discCounts = new HashMap<ResolutionStatus, Integer>();
d.getProps().put("crf_" + crf.getId(), DataEntryStage.UNCOMPLETED);
d.getProps().put("crf_" + crf.getId() + "_eventCrf", null);
d.getProps().put("crf_" + crf.getId() + "_crf", crf);
d.getProps().put("crf_" + crf.getId() + "_eventDefinitionCrf", eventDefinitionCrfs.get(i));
d.getProps().put("crf_" + crf.getId() + "_discCounts", discCounts);
theItem.put("crf_" + crf.getId(), "");
}
events.add(d);
}
// study event size >0
for (StudyEventBean studyEventBean : eventsForStudySubjectAndEventDefinitions) {
DisplayBean d = new DisplayBean();
d.getProps().put("event", studyEventBean);
d.getProps().put("event.status", studyEventBean.getSubjectEventStatus());
d.getProps().put("event.startDate", studyEventBean.getCreatedDate());
for (int i = 0; i < getCrfs(selectedStudyEventDefinition).size(); i++) {
CRFBean crf = getCrfs(selectedStudyEventDefinition).get(i);
EventCRFBean eventCRFBean = crfAsKeyEventCrfAsValue.get(crf.getId() + "_" + studyEventBean.getId());
HashMap<ResolutionStatus, Integer> discCounts = new HashMap<ResolutionStatus, Integer>();
if (eventCRFBean != null) {
d.getProps().put("crf_" + crf.getId(), eventCRFBean.getStage());
d.getProps().put("crf_" + crf.getId() + "_eventCrf", eventCRFBean);
// List<DiscrepancyNoteBean> discs =
// getDiscrepancyNoteDAO().findAllByStudyEvent(studyEventBean);
List<DiscrepancyNoteBean> discs = getDiscrepancyNoteDAO().findAllParentItemNotesByEventCRFWithConstraints(eventCRFBean.getId(), constraints);
hasDN = hasDN == false ? discs != null && discs.size() > 0 : hasDN;
for (DiscrepancyNoteBean discrepancyNoteBean : discs) {
Integer value = discCounts.get(discrepancyNoteBean.getResStatus());
if (value != null) {
discCounts.put(discrepancyNoteBean.getResStatus(), ++value);
} else {
discCounts.put(discrepancyNoteBean.getResStatus(), 1);
}
}
d.getProps().put("crf_" + crf.getId() + "_discCounts", discCounts);
} else {
d.getProps().put("crf_" + crf.getId(), DataEntryStage.UNCOMPLETED);
d.getProps().put("crf_" + crf.getId() + "_eventCrf", null);
d.getProps().put("crf_" + crf.getId() + "_discCounts", discCounts);
}
d.getProps().put("crf_" + crf.getId() + "_crf", crf);
d.getProps().put("crf_" + crf.getId() + "_eventDefinitionCrf", eventDefinitionCrfs.get(i));
theItem.put("crf_" + crf.getId(), "");
}
events.add(d);
}
theItem.put("events", events);
theItem.put("event.status", "");
theItem.put("event.startDate", "");
theItems.add(theItem);
}
// Do not forget to set the items back on the tableFacade.
tableFacade.setItems(theItems);
this.setStudyHasDiscNotes(hasDN);
}
use of org.akaza.openclinica.bean.submit.EventCRFBean in project OpenClinica by OpenClinica.
the class MarkEventCRFCompleteServlet method processRequest.
/*
* (non-Javadoc)
*
* @see org.akaza.openclinica.control.core.SecureController#processRequest()
*/
@Override
protected void processRequest() throws Exception {
// FormDiscrepancyNotes discNotes =
// (FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.
// FORM_DISCREPANCY_NOTES_NAME);
getEventCRFBean();
getEventDefinitionCRFBean();
DataEntryStage stage = ecb.getStage();
request.setAttribute(TableOfContentsServlet.INPUT_EVENT_CRF_BEAN, ecb);
// Page errorPage = Page.TABLE_OF_CONTENTS_SERVLET;
Page errorPage = Page.LIST_STUDY_SUBJECTS_SERVLET;
if (stage.equals(DataEntryStage.UNCOMPLETED) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.LOCKED)) {
throw new InconsistentStateException(errorPage, respage.getString("not_mark_CRF_complete1"));
}
if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
if (!edcb.isDoubleEntry()) {
throw new InconsistentStateException(errorPage, respage.getString("not_mark_CRF_complete2"));
}
}
if (!isEachRequiredFieldFillout()) {
throw new InconsistentStateException(errorPage, respage.getString("not_mark_CRF_complete4"));
}
if (ecb.getInterviewerName().trim().equals("")) {
throw new InconsistentStateException(errorPage, respage.getString("not_mark_CRF_complete5"));
}
if (!fp.isSubmitted()) {
DisplayTableOfContentsBean toc = TableOfContentsServlet.getDisplayBean(ecb, sm.getDataSource(), currentStudy);
toc = TableOfContentsServlet.getDisplayBeanWithShownSections(sm.getDataSource(), toc, (DynamicsMetadataService) SpringServletAccess.getApplicationContext(getServletContext()).getBean("dynamicsMetadataService"));
request.setAttribute(BEAN_DISPLAY, toc);
resetPanel();
panel.setStudyInfoShown(false);
panel.setOrderedData(true);
setToPanel(resword.getString("subject"), toc.getStudySubject().getLabel());
setToPanel(resword.getString("study_event_definition"), toc.getStudyEventDefinition().getName());
StudyEventBean seb = toc.getStudyEvent();
setToPanel(resword.getString("location"), seb.getLocation());
setToPanel(resword.getString("start_date"), seb.getDateStarted().toString());
setToPanel(resword.getString("end_date"), seb.getDateEnded().toString());
setToPanel(resword.getString("CRF"), toc.getCrf().getName());
setToPanel(resword.getString("CRF_version"), toc.getCrfVersion().getName());
forwardPage(Page.MARK_EVENT_CRF_COMPLETE);
} else {
boolean markComplete = fp.getString(INPUT_MARK_COMPLETE).equals(VALUE_YES);
if (markComplete) {
Status newStatus = ecb.getStatus();
boolean ide = true;
if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY) && edcb.isDoubleEntry()) {
newStatus = Status.PENDING;
ecb.setUpdaterId(ub.getId());
ecb.setUpdatedDate(new Date());
ecb.setDateCompleted(new Date());
} else if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY) && !edcb.isDoubleEntry()) {
newStatus = Status.UNAVAILABLE;
ecb.setUpdaterId(ub.getId());
ecb.setUpdatedDate(new Date());
ecb.setDateCompleted(new Date());
ecb.setDateValidateCompleted(new Date());
} else if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
newStatus = Status.UNAVAILABLE;
ecb.setDateValidateCompleted(new Date());
ide = false;
}
ecb.setStatus(newStatus);
ecb = (EventCRFBean) ecdao.update(ecb);
ecdao.markComplete(ecb, ide);
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
iddao.updateStatusByEventCRF(ecb, newStatus);
// change status for event
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudyEventBean seb = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
seb.setUpdatedDate(new Date());
seb.setUpdater(ub);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
ArrayList allCRFs = ecdao.findAllByStudyEvent(seb);
ArrayList allEDCs = edcdao.findAllActiveByEventDefinitionId(seb.getStudyEventDefinitionId());
boolean eventCompleted = true;
for (int i = 0; i < allCRFs.size(); i++) {
EventCRFBean ec = (EventCRFBean) allCRFs.get(i);
if (!ec.getStatus().equals(Status.UNAVAILABLE)) {
eventCompleted = false;
break;
}
}
if (eventCompleted && allCRFs.size() >= allEDCs.size()) {
seb.setSubjectEventStatus(SubjectEventStatus.COMPLETED);
}
seb = (StudyEventBean) sedao.update(seb);
addPageMessage(respage.getString("event_CRF_marked_complete"));
request.setAttribute(EnterDataForStudyEventServlet.INPUT_EVENT_ID, String.valueOf(ecb.getStudyEventId()));
forwardPage(Page.ENTER_DATA_FOR_STUDY_EVENT_SERVLET);
} else {
request.setAttribute(DataEntryServlet.INPUT_IGNORE_PARAMETERS, Boolean.TRUE);
addPageMessage(respage.getString("event_CRF_not_marked_complete"));
forwardPage(errorPage);
}
}
}
use of org.akaza.openclinica.bean.submit.EventCRFBean in project OpenClinica by OpenClinica.
the class TableOfContentsServlet method createEventCRF.
/**
* Creates a new Event CRF or update the exsiting one, that is, an event CRF
* can be created but not item data yet, in this case, still consider it is
* not started(called uncompleted before)
*
* @return
* @throws Exception
*/
private EventCRFBean createEventCRF() throws Exception {
EventCRFBean ecb;
ecdao = new EventCRFDAO(sm.getDataSource());
int crfVersionId = fp.getInt(INPUT_CRF_VERSION_ID);
int studyEventId = fp.getInt(INPUT_STUDY_EVENT_ID);
int eventDefinitionCRFId = fp.getInt(INPUT_EVENT_DEFINITION_CRF_ID);
int subjectId = fp.getInt(INPUT_SUBJECT_ID);
int eventCRFId = fp.getInt(INPUT_EVENT_CRF_ID);
logger.info("Creating event CRF within Table of Contents. Study id: " + currentStudy.getId() + "; CRF Version id: " + crfVersionId + "; Study Event id: " + studyEventId + "; Event Definition CRF id: " + eventDefinitionCRFId + "; Subject: " + subjectId);
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean ssb = ssdao.findBySubjectIdAndStudy(subjectId, currentStudy);
if (!ssb.isActive()) {
throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("trying_to_begin_DE1"));
}
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sedb = seddao.findByEventDefinitionCRFId(eventDefinitionCRFId);
if (!ssb.isActive() || !sedb.isActive()) {
throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("trying_to_begin_DE2"));
}
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
EntityBean eb = cvdao.findByPK(crfVersionId);
if (!eb.isActive()) {
throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("trying_to_begin_DE3"));
}
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudyEventBean sEvent = (StudyEventBean) sedao.findByPK(studyEventId);
StudyBean studyWithSED = currentStudy;
if (currentStudy.getParentStudyId() > 0) {
studyWithSED = new StudyBean();
studyWithSED.setId(currentStudy.getParentStudyId());
}
AuditableEntityBean aeb = sedao.findByPKAndStudy(studyEventId, studyWithSED);
if (!aeb.isActive()) {
throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("trying_to_begin_DE4"));
}
ecb = new EventCRFBean();
if (eventCRFId == 0) {
// no event CRF created yet
ecb.setAnnotations("");
ecb.setCreatedDate(new Date());
ecb.setCRFVersionId(crfVersionId);
ecb.setInterviewerName("");
if (sEvent.getDateStarted() != null) {
// default date
ecb.setDateInterviewed(sEvent.getDateStarted());
} else {
ecb.setDateInterviewed(null);
}
ecb.setOwnerId(ub.getId());
ecb.setStatus(Status.AVAILABLE);
ecb.setCompletionStatusId(1);
ecb.setStudySubjectId(ssb.getId());
ecb.setStudyEventId(studyEventId);
ecb.setValidateString("");
ecb.setValidatorAnnotations("");
ecb = (EventCRFBean) ecdao.create(ecb);
logger.info("CREATED EVENT CRF");
} else {
// there is an event CRF already, only need to update
ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
ecb.setCRFVersionId(crfVersionId);
ecb.setUpdatedDate(new Date());
ecb.setUpdater(ub);
ecb = (EventCRFBean) ecdao.update(ecb);
}
if (!ecb.isActive()) {
throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("new_event_CRF_not_created_database_error"));
} else {
sEvent.setSubjectEventStatus(SubjectEventStatus.DATA_ENTRY_STARTED);
sEvent.setUpdater(ub);
sEvent.setUpdatedDate(new Date());
sedao.update(sEvent);
}
return ecb;
}
use of org.akaza.openclinica.bean.submit.EventCRFBean in project OpenClinica by OpenClinica.
the class ListStudySubjectTableFactory method eventHasRequiredUncompleteCRFs.
@SuppressWarnings("unchecked")
private boolean eventHasRequiredUncompleteCRFs(StudyEventBean studyEventBean) {
List<EventCRFBean> eventCrfBeans = new ArrayList<EventCRFBean>();
eventCrfBeans.addAll(getEventCRFDAO().findAllByStudyEvent(studyEventBean));
// method false.
for (EventCRFBean crfBean : eventCrfBeans) {
if (crfBean != null && crfBean.getCompletionStatusId() == 0) {
if (getEventDefintionCRFDAO().isRequiredInDefinition(crfBean.getCRFVersionId(), studyEventBean)) {
return true;
}
}
}
return false;
}
Aggregations