use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.
the class RuleSetService method filterRuleSetsByStudyEventOrdinal.
@SuppressWarnings("unchecked")
public List<RuleSetBean> filterRuleSetsByStudyEventOrdinal(List<RuleSetBean> ruleSets, String crfVersionId) {
ArrayList<RuleSetBean> validRuleSets = new ArrayList<RuleSetBean>();
for (RuleSetBean ruleSetBean : ruleSets) {
String studyEventDefinitionOrdinal = getExpressionService().getStudyEventDefinitionOrdninalCurated(ruleSetBean.getTarget().getValue());
String studyEventDefinitionOid = getExpressionService().getStudyEventDefenitionOid(ruleSetBean.getTarget().getValue());
String crfOrCrfVersionOid = getExpressionService().getCrfOid(ruleSetBean.getTarget().getValue());
// whole expression is provided in target
if (studyEventDefinitionOid != null && crfOrCrfVersionOid != null) {
List<StudyEventBean> studyEvents = null;
if (crfOrCrfVersionOid.equals("STARTDATE") || crfOrCrfVersionOid.equals("STATUS")) {
StudyEventDefinitionBean sedBean = getStudyEventDefinitionDao().findByOid(studyEventDefinitionOid);
studyEvents = (List<StudyEventBean>) getStudyEventDao().findAllByDefinition(sedBean.getId());
logger.debug("studyEventDefinitionOrdinal {} , studyEventDefinitionOid {} , crfOrCrfVersionOid {} , studyEvents {}", new Object[] { studyEventDefinitionOrdinal, studyEventDefinitionOid, crfOrCrfVersionOid, studyEvents.size() });
} else {
studyEvents = getStudyEventDao().findAllByStudyEventDefinitionAndCrfOids(studyEventDefinitionOid, crfOrCrfVersionOid);
logger.debug("studyEventDefinitionOrdinal {} , studyEventDefinitionOid {} , crfOrCrfVersionOid {} , studyEvents {}", new Object[] { studyEventDefinitionOrdinal, studyEventDefinitionOid, crfOrCrfVersionOid, studyEvents.size() });
}
if (studyEventDefinitionOrdinal.equals("") && studyEvents.size() > 0) {
for (StudyEventBean studyEvent : studyEvents) {
ruleSetBean.addExpression(replaceSEDOrdinal(ruleSetBean.getTarget(), studyEvent));
}
validRuleSets.add(ruleSetBean);
} else {
for (StudyEventBean studyEvent : studyEvents) {
if (studyEventDefinitionOrdinal.equals(String.valueOf(studyEvent.getSampleOrdinal()))) {
ruleSetBean.addExpression(replaceSEDOrdinal(ruleSetBean.getTarget(), studyEvent));
}
}
validRuleSets.add(ruleSetBean);
}
} else {
// partial expression is provided in target
CRFBean crf = null;
List<CRFVersionBean> crfVersions = new ArrayList<CRFVersionBean>();
CRFVersionBean crfVersion = null;
if (crfOrCrfVersionOid == null) {
crf = getCrfDao().findByItemOid(getExpressionService().getItemOid(ruleSetBean.getTarget().getValue()));
if (crfVersionId != null) {
crfVersion = (CRFVersionBean) getCrfVersionDao().findByPK(Integer.valueOf(crfVersionId));
crfVersions.add(crfVersion);
} else {
crfVersions = (List<CRFVersionBean>) getCrfVersionDao().findAllByCRF(crf.getId());
}
} else {
crf = getExpressionService().getCRFFromExpression(ruleSetBean.getTarget().getValue());
if (crfVersionId != null) {
crfVersion = (CRFVersionBean) getCrfVersionDao().findByPK(Integer.valueOf(crfVersionId));
} else {
crfVersion = getExpressionService().getCRFVersionFromExpression(ruleSetBean.getTarget().getValue());
}
if (crfVersion != null) {
crfVersions.add(crfVersion);
} else {
crfVersions = (List<CRFVersionBean>) getCrfVersionDao().findAllByCRF(crf.getId());
}
}
List<StudyEventDefinitionBean> studyEventDefinitions = getStudyEventDefinitionDao().findAllByCrf(crf);
for (StudyEventDefinitionBean studyEventDefinitionBean : studyEventDefinitions) {
for (CRFVersionBean crfVersionBean : crfVersions) {
String expression = getExpressionService().constructFullExpressionIfPartialProvided(ruleSetBean.getTarget().getValue(), crfVersionBean, studyEventDefinitionBean);
List<StudyEventBean> studyEvents = getStudyEventDao().findAllByStudyEventDefinitionAndCrfOids(studyEventDefinitionBean.getOid(), crfVersionBean.getOid());
logger.debug("studyEventDefinitionOrdinal {} , studyEventDefinitionOid {} , crfOrCrfVersionOid {} , studyEvents {}", new Object[] { studyEventDefinitionOrdinal, studyEventDefinitionBean.getOid(), crfVersionBean.getOid(), studyEvents.size() });
for (StudyEventBean studyEvent : studyEvents) {
ruleSetBean.addExpression(replaceSEDOrdinal(ruleSetBean.getTarget(), studyEvent, expression));
}
}
}
validRuleSets.add(ruleSetBean);
}
}
logExpressions(validRuleSets);
logger.debug("Size of RuleSets post filterRuleSetsByStudyEventOrdinal() {} ", validRuleSets.size());
return validRuleSets;
}
use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.
the class ExpressionService method getValueFromDbb.
public HashMap<String, String> getValueFromDbb(String expression) throws OpenClinicaSystemException {
HashMap<String, String> map = new HashMap<>();
if (isExpressionPartial(expression)) {
throw new OpenClinicaSystemException("getValueFromDb:We cannot get the Value of a PARTIAL expression : " + expression);
}
try {
// Get the studyEventId from RuleSet Target so we can know which
// StudySubject we are dealing with.
String ruleSetExpression = expressionWrapper.getRuleSet().getTarget().getValue();
String ruleSetExpressionStudyEventId = getStudyEventDefinitionOidOrdinalFromExpression(ruleSetExpression);
StudyEventBean studyEvent = (StudyEventBean) getStudyEventDao().findByPK(Integer.valueOf(ruleSetExpressionStudyEventId));
// Prepare Method arguments
String studyEventDefinitionOid = getStudyEventDefinitionOidFromExpression(expression);
String crfOrCrfVersionOid = getCrfOidFromExpression(expression);
String studyEventDefinitionOrdinal = getStudyEventDefinitionOidOrdinalFromExpression(expression);
studyEventDefinitionOrdinal = studyEventDefinitionOrdinal.equals("") ? "1" : studyEventDefinitionOrdinal;
String studySubjectId = String.valueOf(studyEvent.getStudySubjectId());
System.out.println("studySubjectId: " + studySubjectId);
logger.debug("ruleSet studyEventId {} , studyEventDefinitionOid {} , crfOrCrfVersionOid {} , studyEventDefinitionOrdinal {} ,studySubjectId {}", new Object[] { studyEvent.getId(), studyEventDefinitionOid, crfOrCrfVersionOid, studyEventDefinitionOrdinal, studySubjectId });
StudyEventBean studyEventofThisExpression = getStudyEventDao().findAllByStudyEventDefinitionAndCrfOidsAndOrdinal(studyEventDefinitionOid, crfOrCrfVersionOid, studyEventDefinitionOrdinal, studySubjectId);
if (studyEvent.getId() == studyEventofThisExpression.getId())
map.put("match", "true");
logger.debug("studyEvent : {} , itemOid {} , itemGroupOid {}", new Object[] { studyEventofThisExpression.getId(), getItemOidFromExpression(expression), getItemGroupOidFromExpression(expression) });
List<ItemDataBean> itemData = getItemDataDao().findByStudyEventAndOids(Integer.valueOf(studyEventofThisExpression.getId()), getItemOidFromExpression(expression), getItemGroupOidFromExpression(expression));
expression = fixGroupOrdinal(expression, ruleSetExpression, itemData, expressionWrapper.getEventCrf());
Integer index = getItemGroupOidOrdinalFromExpression(expression).equals("") ? 0 : Integer.valueOf(getItemGroupOidOrdinalFromExpression(expression)) - 1;
ItemDataBean itemDataBean = itemData.get(index);
ItemBean itemBean = (ItemBean) getItemDao().findByPK(itemDataBean.getItemId());
String value = itemData.get(index).getValue();
value = ifValueIsDate(itemBean, value);
map.put("value", value);
return map;
} catch (Exception e) {
return map;
}
}
use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.
the class RuleSetListenerService method onApplicationEvent.
@Override
public void onApplicationEvent(final OnStudyEventUpdated event) {
LOGGER.debug("listening");
if (event.getContainer().getChangeDetails().getStartDateChanged() || event.getContainer().getChangeDetails().getStatusChanged()) {
StudyEvent studyEvent = event.getContainer().getEvent();
Integer studyEventDefId = studyEvent.getStudyEventDefinition().getStudyEventDefinitionId();
Integer studyEventOrdinal = studyEvent.getSampleOrdinal();
Integer userId = studyEvent.getUpdateId();
if (userId == null && studyEvent.getUserAccount() != null)
userId = studyEvent.getUserAccount().getUserId();
StudyEventBean studyEventBean = new StudyEventBean();
studyEventBean.setId(studyEvent.getStudyEventId());
ArrayList<RuleSetBean> ruleSets = (ArrayList<RuleSetBean>) createRuleSet(studyEventDefId);
for (RuleSetBean ruleSet : ruleSets) {
ArrayList<RuleSetBean> ruleSetBeans = new ArrayList();
ExpressionBean eBean = new ExpressionBean();
eBean.setValue(ruleSet.getTarget().getValue() + ".A.B");
ruleSet.setTarget(eBean);
ruleSet.addExpression(getRuleSetService().replaceSEDOrdinal(ruleSet.getTarget(), studyEventBean));
ruleSetBeans.add(ruleSet);
getRuleSetService().runIndividualRulesInBeanProperty(ruleSetBeans, userId, event.getContainer().getChangeDetails(), studyEventOrdinal);
}
}
}
use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.
the class RuleSetService method filterRuleSetsByStudySubject.
/*
* (non-Javadoc)
* @see org.akaza.openclinica.service.rule.RuleSetServiceInterface#filterRuleSetsByStudyEventOrdinal(java.util.List)
*/
@SuppressWarnings("unchecked")
public List<RuleSetBean> filterRuleSetsByStudySubject(List<RuleSetBean> ruleSets) throws NumberFormatException, ParseException {
for (RuleSetBean ruleSet : ruleSets) {
List<ExpressionBean> filteredExpressions = new ArrayList<ExpressionBean>();
if (ruleSet.getExpressions() != null) {
for (ExpressionBean expression : ruleSet.getExpressions()) {
String studyEventId = getExpressionService().getStudyEventDefinitionOrdninalCurated(expression.getValue());
StudyEventBean studyEvent = (StudyEventBean) getStudyEventDao().findByPK(Integer.valueOf(studyEventId));
StudySubjectBean studySubject = (StudySubjectBean) getStudySubjecdao().findByPK(studyEvent.getStudySubjectId());
if (doTriggerRule(ruleSet, studySubject)) {
ExpressionBean expBean = new ExpressionBean();
expBean.setValue(expression.getValue());
expBean.setContext(expression.getContext());
filteredExpressions.add(expBean);
}
}
ruleSet.setExpressions(filteredExpressions);
} else {
ruleSet.setExpressions(filteredExpressions);
}
}
logExpressions(ruleSets);
return ruleSets;
}
use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.
the class DeleteEventCRFServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
int studySubId = fp.getInt(STUDY_SUB_ID, true);
int eventCRFId = fp.getInt(EVENT_CRF_ID);
String action = request.getParameter("action");
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
StudyDAO sdao = new StudyDAO(sm.getDataSource());
if (eventCRFId == 0) {
addPageMessage(respage.getString("please_choose_an_event_CRF_to_delete"));
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
} else {
EventCRFBean eventCRF = (EventCRFBean) ecdao.findByPK(eventCRFId);
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
request.setAttribute("studySub", studySub);
// construct info needed on view event crf page
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
int crfVersionId = eventCRF.getCRFVersionId();
CRFBean cb = cdao.findByVersionId(crfVersionId);
eventCRF.setCrf(cb);
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(crfVersionId);
eventCRF.setCrfVersion(cvb);
// then get the definition so we can call
// DisplayEventCRFBean.setFlags
int studyEventId = eventCRF.getStudyEventId();
StudyEventBean event = (StudyEventBean) sedao.findByPK(studyEventId);
int studyEventDefinitionId = sedao.getDefinitionIdFromStudyEventId(studyEventId);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(studyEventDefinitionId);
event.setStudyEventDefinition(sed);
request.setAttribute("event", event);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
StudyBean study = (StudyBean) sdao.findByPK(studySub.getStudyId());
EventDefinitionCRFBean edc = edcdao.findByStudyEventDefinitionIdAndCRFId(study, studyEventDefinitionId, cb.getId());
DisplayEventCRFBean dec = new DisplayEventCRFBean();
dec.setEventCRF(eventCRF);
dec.setFlags(eventCRF, ub, currentRole, edc.isDoubleEntry());
// find all item data
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
dnDao = new DiscrepancyNoteDAO(sm.getDataSource());
ArrayList<ItemDataBean> itemData = iddao.findAllByEventCRFId(eventCRF.getId());
request.setAttribute("items", itemData);
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute("displayEventCRF", dec);
forwardPage(Page.DELETE_EVENT_CRF);
} else {
logger.info("submit to delete the event CRF from event");
// OC-6303 Deleting Event CRF resets Show / Hide logic
// delete records from DynamicItemForm and DynamicItemGroup
getDynamicsItemFormMetadataDao().delete(eventCRFId);
getDynamicsItemGroupMetadataDao().delete(eventCRFId);
eventCRF.setOldStatus(eventCRF.getStatus());
eventCRF.setStatus(Status.RESET);
eventCRF.setUpdater(ub);
// OC-12177 added to fix displaying DDE workflow status
eventCRF.setValidatorId(0);
ecdao.update(eventCRF);
for (ItemDataBean itemdata : itemData) {
// OC-6343 Rule behaviour must be reset if an Event CRF is deleted
// delete the records from ruleActionRunLogDao
getRuleActionRunLogDao().delete(itemdata.getId());
// OC-6344 Notes & Discrepancies must be set to "closed" when event CRF is deleted
// parentDiscrepancyNoteList is the list of the parent DNs records only
ArrayList<DiscrepancyNoteBean> parentDiscrepancyNoteList = getDnDao().findParentNotesOnlyByItemData(itemdata.getId());
for (DiscrepancyNoteBean parentDiscrepancyNote : parentDiscrepancyNoteList) {
if (parentDiscrepancyNote.getResolutionStatusId() != 4) {
// if the DN's resolution status is not set to Closed
String description = resword.getString("dn_auto-closed_description");
String detailedNotes = resword.getString("dn_auto_closed_detailed_notes");
// create new DN record , new DN Map record , also update the parent record
createDiscrepancyNoteBean(description, detailedNotes, itemdata.getId(), study, ub, parentDiscrepancyNote);
}
}
iddao = new ItemDataDAO(sm.getDataSource());
ifmdao = new ItemFormMetadataDAO(sm.getDataSource());
ItemDataBean idBean = (ItemDataBean) iddao.findByPK(itemdata.getId());
ItemFormMetadataBean ifmBean = ifmdao.findByItemIdAndCRFVersionId(idBean.getItemId(), crfVersionId);
// Updating Dn_item_data_map actovated column into false for the existing DNs
ArrayList<DiscrepancyNoteBean> dnBeans = getDnDao().findExistingNotesForItemData(itemdata.getId());
if (dnBeans.size() != 0) {
DiscrepancyNoteBean dnBean = new DiscrepancyNoteBean();
dnBean.setEntityId(itemdata.getId());
dnBean.setActivated(false);
getDnDao().updateDnMapActivation(dnBean);
}
// Default Values are not addressed
itemdata.setValue("");
itemdata.setOldStatus(itemdata.getStatus());
itemdata.setOwner(ub);
itemdata.setStatus(Status.AVAILABLE);
itemdata.setUpdater(ub);
iddao.updateUser(itemdata);
iddao.update(itemdata);
}
// OC-6291 event_crf status change
eventCRF.setOldStatus(eventCRF.getStatus());
eventCRF.setStatus(Status.AVAILABLE);
eventCRF.setUpdater(ub);
ecdao.update(eventCRF);
if (event.getSubjectEventStatus().isCompleted() || event.getSubjectEventStatus().isSigned()) {
event.setSubjectEventStatus(SubjectEventStatus.DATA_ENTRY_STARTED);
event.setUpdater(ub);
sedao = new StudyEventDAO(sm.getDataSource());
sedao.update(event);
}
String emailBody = respage.getString("the_event_CRF") + cb.getName() + respage.getString("has_been_deleted_from_the_event") + event.getStudyEventDefinition().getName() + ". " + respage.getString("has_been_deleted_from_the_event_cont");
addPageMessage(emailBody);
// sendEmail(emailBody);
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
}
}
}
Aggregations