use of org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO 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.managestudy.EventDefinitionCRFDAO in project OpenClinica by OpenClinica.
the class SubjectIdSDVFactory method getEventCRFStats.
private HashMap<String, Integer> getEventCRFStats(List<EventCRFBean> eventCRFBeans, StudySubjectBean studySubject) {
StudyEventDAO studyEventDAO = new StudyEventDAO(dataSource);
EventDefinitionCRFDAO eventDefinitionCrfDAO = new EventDefinitionCRFDAO(dataSource);
CRFDAO crfDAO = new CRFDAO(dataSource);
StudyEventBean studyEventBean = null;
Integer numberOfCompletedEventCRFs = 0;
Integer numberOfSDVdEventCRFs = 0;
Integer areEventCRFsSDVd = eventCRFBeans.size() > 0 ? 0 : -1;
Boolean partialOrHundred = false;
Integer shouldDisplaySDVButton = 0;
for (EventCRFBean eventBean : eventCRFBeans) {
studyEventBean = (StudyEventBean) studyEventDAO.findByPK(eventBean.getStudyEventId());
CRFBean crfBean = crfDAO.findByVersionId(eventBean.getCRFVersionId());
// get number of completed event crfs
if (eventBean.getStatus() == Status.UNAVAILABLE || eventBean.getStatus() == Status.LOCKED) {
numberOfCompletedEventCRFs++;
}
// get number of completed event SDVd events
if (eventBean.isSdvStatus()) {
numberOfSDVdEventCRFs++;
}
// get number of all non SDVd events that are 100% or partial required
EventDefinitionCRFBean eventDefinitionCrf = eventDefinitionCrfDAO.findByStudyEventDefinitionIdAndCRFIdAndStudyId(studyEventBean.getStudyEventDefinitionId(), crfBean.getId(), studySubject.getStudyId());
if (eventDefinitionCrf.getId() == 0) {
eventDefinitionCrf = eventDefinitionCrfDAO.findForStudyByStudyEventDefinitionIdAndCRFId(studyEventBean.getStudyEventDefinitionId(), crfBean.getId());
}
if ((eventDefinitionCrf.getSourceDataVerification() == SourceDataVerification.AllREQUIRED || eventDefinitionCrf.getSourceDataVerification() == SourceDataVerification.PARTIALREQUIRED) && (eventBean.getStatus() == Status.UNAVAILABLE || eventBean.getStatus() == Status.LOCKED)) {
partialOrHundred = true;
}
if ((eventDefinitionCrf.getSourceDataVerification() == SourceDataVerification.AllREQUIRED || eventDefinitionCrf.getSourceDataVerification() == SourceDataVerification.PARTIALREQUIRED) && eventBean.isSdvStatus() == false && (eventBean.getStatus() == Status.UNAVAILABLE || eventBean.getStatus() == Status.LOCKED)) {
areEventCRFsSDVd = 1;
}
}
HashMap<String, Integer> stats = new HashMap<String, Integer>();
stats.put("numberOfCompletedEventCRFs", numberOfCompletedEventCRFs);
stats.put("numberOfSDVdEventCRFs", numberOfSDVdEventCRFs);
stats.put("areEventCRFsSDVd", partialOrHundred == false ? 1 : areEventCRFsSDVd);
stats.put("shouldDisplaySDVButton", numberOfCompletedEventCRFs > 0 && partialOrHundred == true ? 1 : 0);
return stats;
}
use of org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO in project OpenClinica by OpenClinica.
the class RestoreStudyServlet method processRequest.
@Override
public void processRequest() throws Exception {
StudyDAO sdao = new StudyDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
int studyId = fp.getInt("id");
StudyBean study = (StudyBean) sdao.findByPK(studyId);
// find all sites
ArrayList sites = (ArrayList) sdao.findAllByParent(studyId);
// find all user and roles in the study, include ones in sites
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
ArrayList userRoles = udao.findAllByStudyId(studyId);
// find all subjects in the study, include ones in sites
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ArrayList subjects = ssdao.findAllByStudy(study);
// find all events in the study, include ones in sites
StudyEventDefinitionDAO sefdao = new StudyEventDefinitionDAO(sm.getDataSource());
ArrayList definitions = sefdao.findAllByStudy(study);
String action = request.getParameter("action");
if (studyId == 0) {
addPageMessage(respage.getString("please_choose_a_study_to_restore"));
forwardPage(Page.STUDY_LIST_SERVLET);
} else {
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute("studyToRestore", study);
request.setAttribute("sitesToRestore", sites);
request.setAttribute("userRolesToRestore", userRoles);
request.setAttribute("subjectsToRestore", subjects);
request.setAttribute("definitionsToRRestore", definitions);
forwardPage(Page.RESTORE_STUDY);
} else {
logger.info("submit to restore the study");
// change all statuses to unavailable
StudyDAO studao = new StudyDAO(sm.getDataSource());
study.setStatus(study.getOldStatus());
study.setUpdater(ub);
study.setUpdatedDate(new Date());
studao.update(study);
// YW 09-27-2007 << restore auto-removed sites
for (int i = 0; i < sites.size(); i++) {
StudyBean site = (StudyBean) sites.get(i);
if (site.getStatus() == Status.AUTO_DELETED) {
site.setStatus(site.getOldStatus());
site.setUpdater(ub);
site.setUpdatedDate(new Date());
sdao.update(site);
}
}
// restore all users and roles
for (int i = 0; i < userRoles.size(); i++) {
StudyUserRoleBean role = (StudyUserRoleBean) userRoles.get(i);
if (role.getStatus().equals(Status.AUTO_DELETED)) {
role.setStatus(Status.AVAILABLE);
role.setUpdater(ub);
role.setUpdatedDate(new Date());
udao.updateStudyUserRole(role, role.getUserName());
}
}
// is current active study
if (study.getId() == currentStudy.getId()) {
currentStudy.setStatus(Status.AVAILABLE);
StudyUserRoleBean r = (new UserAccountDAO(sm.getDataSource())).findRoleByUserNameAndStudyId(ub.getName(), currentStudy.getId());
currentRole.setRole(r.getRole());
} else // active site will be restored as well if it was auto-removed
if (currentStudy.getParentStudyId() == study.getId() && currentStudy.getStatus() == Status.AUTO_DELETED) {
currentStudy.setStatus(Status.AVAILABLE);
StudyUserRoleBean r = (new UserAccountDAO(sm.getDataSource())).findRoleByUserNameAndStudyId(ub.getName(), currentStudy.getId());
StudyUserRoleBean rInParent = (new UserAccountDAO(sm.getDataSource())).findRoleByUserNameAndStudyId(ub.getName(), currentStudy.getParentStudyId());
// according to logic in SecureController.java: inherited
// role from parent study, pick the higher role
currentRole.setRole(Role.get(Role.max(r.getRole(), rInParent.getRole()).getId()));
}
// restore all subjects
for (int i = 0; i < subjects.size(); i++) {
StudySubjectBean subject = (StudySubjectBean) subjects.get(i);
if (subject.getStatus().equals(Status.AUTO_DELETED)) {
subject.setStatus(Status.AVAILABLE);
subject.setUpdater(ub);
subject.setUpdatedDate(new Date());
ssdao.update(subject);
}
}
// restore all study_group
StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
ArrayList groups = sgcdao.findAllByStudy(study);
for (int i = 0; i < groups.size(); i++) {
StudyGroupClassBean group = (StudyGroupClassBean) groups.get(i);
if (group.getStatus().equals(Status.AUTO_DELETED)) {
group.setStatus(Status.AVAILABLE);
group.setUpdater(ub);
group.setUpdatedDate(new Date());
sgcdao.update(group);
// all subject_group_map
ArrayList subjectGroupMaps = sgmdao.findAllByStudyGroupClassId(group.getId());
for (int j = 0; j < subjectGroupMaps.size(); j++) {
SubjectGroupMapBean sgMap = (SubjectGroupMapBean) subjectGroupMaps.get(j);
if (sgMap.getStatus().equals(Status.AUTO_DELETED)) {
sgMap.setStatus(Status.AVAILABLE);
sgMap.setUpdater(ub);
sgMap.setUpdatedDate(new Date());
sgmdao.update(sgMap);
}
}
}
}
// restore all event definitions and event
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
for (int i = 0; i < definitions.size(); i++) {
StudyEventDefinitionBean definition = (StudyEventDefinitionBean) definitions.get(i);
if (definition.getStatus().equals(Status.AUTO_DELETED)) {
definition.setStatus(Status.AVAILABLE);
definition.setUpdater(ub);
definition.setUpdatedDate(new Date());
sefdao.update(definition);
ArrayList edcs = (ArrayList) edcdao.findAllByDefinition(definition.getId());
for (int j = 0; j < edcs.size(); j++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) edcs.get(j);
if (edc.getStatus().equals(Status.AUTO_DELETED)) {
edc.setStatus(Status.AVAILABLE);
edc.setUpdater(ub);
edc.setUpdatedDate(new Date());
edcdao.update(edc);
}
}
ArrayList events = (ArrayList) sedao.findAllByDefinition(definition.getId());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
for (int j = 0; j < events.size(); j++) {
StudyEventBean event = (StudyEventBean) events.get(j);
if (event.getStatus().equals(Status.AUTO_DELETED)) {
event.setStatus(Status.AVAILABLE);
event.setUpdater(ub);
event.setUpdatedDate(new Date());
sedao.update(event);
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
for (int k = 0; k < eventCRFs.size(); k++) {
EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
if (eventCRF.getStatus().equals(Status.AUTO_DELETED)) {
eventCRF.setStatus(eventCRF.getOldStatus());
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
ArrayList itemDatas = iddao.findAllByEventCRFId(eventCRF.getId());
for (int a = 0; a < itemDatas.size(); a++) {
ItemDataBean item = (ItemDataBean) itemDatas.get(a);
if (item.getStatus().equals(Status.AUTO_DELETED)) {
item.setStatus(item.getOldStatus());
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
}
}
}
}
// for definitions
DatasetDAO datadao = new DatasetDAO(sm.getDataSource());
ArrayList dataset = datadao.findAllByStudyId(study.getId());
for (int i = 0; i < dataset.size(); i++) {
DatasetBean data = (DatasetBean) dataset.get(i);
if (data.getStatus().equals(Status.AUTO_DELETED)) {
data.setStatus(Status.AVAILABLE);
data.setUpdater(ub);
data.setUpdatedDate(new Date());
datadao.update(data);
}
}
addPageMessage(respage.getString("this_study_has_been_restored_succesfully"));
forwardPage(Page.STUDY_LIST_SERVLET);
}
}
}
use of org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO in project OpenClinica by OpenClinica.
the class RemoveEventDefinitionServlet method processRequest.
@Override
public void processRequest() throws Exception {
String idString = request.getParameter("id");
int defId = Integer.valueOf(idString.trim()).intValue();
StudyEventDefinitionDAO sdao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) sdao.findByPK(defId);
// checkRoleByUserAndStudy(ub.getName(), sed.getStudyId(), 0);
if (currentStudy.getId() != sed.getStudyId()) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
forwardPage(Page.MENU_SERVLET);
return;
}
// find all CRFs
EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(sm.getDataSource());
ArrayList eventDefinitionCRFs = (ArrayList) edao.findAllByDefinition(defId);
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
ArrayList versions = (ArrayList) cvdao.findAllByCRF(edc.getCrfId());
edc.setVersions(versions);
CRFBean crf = (CRFBean) cdao.findByPK(edc.getCrfId());
edc.setCrfName(crf.getName());
CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(edc.getDefaultVersionId());
edc.setDefaultVersionName(defaultVersion.getName());
CRFBean cBean = (CRFBean) cdao.findByPK(edc.getCrfId());
String crfPath = sed.getOid() + "." + cBean.getOid();
edc.setOffline(getEventDefinitionCrfTagService().getEventDefnCrfOfflineStatus(2, crfPath, true));
}
// finds all events
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
ArrayList events = (ArrayList) sedao.findAllByDefinition(sed.getId());
String action = request.getParameter("action");
if (StringUtil.isBlank(idString)) {
addPageMessage(respage.getString("please_choose_a_SED_to_remove"));
forwardPage(Page.LIST_DEFINITION_SERVLET);
} else {
if ("confirm".equalsIgnoreCase(action)) {
if (!sed.getStatus().equals(Status.AVAILABLE)) {
addPageMessage(respage.getString("this_SED_is_not_available_for_this_study") + respage.getString("please_contact_sysadmin_for_more_information"));
forwardPage(Page.LIST_DEFINITION_SERVLET);
return;
}
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
if (participateFormStatus.equals("enabled"))
baseUrl();
request.setAttribute("participateFormStatus", participateFormStatus);
request.setAttribute("definitionToRemove", sed);
request.setAttribute("eventDefinitionCRFs", eventDefinitionCRFs);
request.setAttribute("events", events);
forwardPage(Page.REMOVE_DEFINITION);
} else {
logger.info("submit to remove the definition");
// remove definition
sed.setStatus(Status.DELETED);
sed.setUpdater(ub);
sed.setUpdatedDate(new Date());
sdao.update(sed);
// remove all crfs
for (int j = 0; j < eventDefinitionCRFs.size(); j++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(j);
if (!edc.getStatus().equals(Status.DELETED)) {
edc.setStatus(Status.AUTO_DELETED);
edc.setUpdater(ub);
edc.setUpdatedDate(new Date());
edao.update(edc);
}
}
// remove all events
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
for (int j = 0; j < events.size(); j++) {
StudyEventBean event = (StudyEventBean) events.get(j);
if (!event.getStatus().equals(Status.DELETED)) {
event.setStatus(Status.AUTO_DELETED);
event.setUpdater(ub);
event.setUpdatedDate(new Date());
sedao.update(event);
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
// remove all the item data
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
for (int k = 0; k < eventCRFs.size(); k++) {
EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
if (!eventCRF.getStatus().equals(Status.DELETED)) {
eventCRF.setStatus(Status.AUTO_DELETED);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
ArrayList itemDatas = iddao.findAllByEventCRFId(eventCRF.getId());
for (int a = 0; a < itemDatas.size(); a++) {
ItemDataBean item = (ItemDataBean) itemDatas.get(a);
if (!item.getStatus().equals(Status.DELETED)) {
item.setStatus(Status.AUTO_DELETED);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
}
}
String emailBody = respage.getString("the_SED") + sed.getName() + " " + respage.getString("has_been_removed_from_the_study") + currentStudy.getName() + ".";
addPageMessage(emailBody);
// sendEmail(emailBody);
forwardPage(Page.LIST_DEFINITION_SERVLET);
}
}
}
use of org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO in project OpenClinica by OpenClinica.
the class RemoveStudyEventServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
// studyEventId
int studyEventId = fp.getInt("id");
// studySubjectId
int studySubId = fp.getInt("studySubId");
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
if (studyEventId == 0) {
addPageMessage(respage.getString("please_choose_a_SE_to_remove"));
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
} else {
StudyEventBean event = (StudyEventBean) sedao.findByPK(studyEventId);
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
request.setAttribute("studySub", studySub);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(event.getStudyEventDefinitionId());
event.setStudyEventDefinition(sed);
StudyDAO studydao = new StudyDAO(sm.getDataSource());
StudyBean study = (StudyBean) studydao.findByPK(studySub.getStudyId());
request.setAttribute("study", study);
String action = request.getParameter("action");
if ("confirm".equalsIgnoreCase(action)) {
//
// if (!event.getStatus().equals(Status.AVAILABLE)) {
// addPageMessage(respage.getString("this_event_is_not_available_for_this_study")
// + " "
// +
// respage.getString("please_contact_sysadmin_for_more_information"));
// request.setAttribute("id", new
// Integer(studySubId).toString());
// forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
// return;
// }
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
// find all crfs in the definition
ArrayList eventDefinitionCRFs = (ArrayList) edcdao.findAllByEventDefinitionId(study, sed.getId());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
// construct info needed on view study event page
DisplayStudyEventBean de = new DisplayStudyEventBean();
de.setStudyEvent(event);
de.setDisplayEventCRFs(getDisplayEventCRFs(eventCRFs, eventDefinitionCRFs));
request.setAttribute("displayEvent", de);
forwardPage(Page.REMOVE_STUDY_EVENT);
} else {
logger.info("submit to remove the event from study");
// remove event from study
event.setStatus(Status.DELETED);
event.setUpdater(ub);
event.setUpdatedDate(new Date());
sedao.update(event);
// remove all event crfs
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
for (int k = 0; k < eventCRFs.size(); k++) {
EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
if (!eventCRF.getStatus().equals(Status.DELETED)) {
eventCRF.setStatus(Status.AUTO_DELETED);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
// remove all the item data
ArrayList itemDatas = iddao.findAllByEventCRFId(eventCRF.getId());
for (int a = 0; a < itemDatas.size(); a++) {
ItemDataBean item = (ItemDataBean) itemDatas.get(a);
if (!item.getStatus().equals(Status.DELETED)) {
item.setStatus(Status.AUTO_DELETED);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
String emailBody = respage.getString("the_event") + " " + event.getStudyEventDefinition().getName() + " " + respage.getString("has_been_removed_from_the_subject_record_for") + " " + studySub.getLabel() + " " + respage.getString("in_the_study") + " " + study.getName() + ".";
addPageMessage(emailBody);
// sendEmail(emailBody);
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
}
}
}
Aggregations