use of org.akaza.openclinica.bean.submit.DisplayEventCRFBean in project OpenClinica by OpenClinica.
the class RemoveStudyEventServlet method getDisplayEventCRFs.
/**
* Each of the event CRFs with its corresponding CRFBean. Then generates a
* list of DisplayEventCRFBeans, one for each event CRF.
*
* @param eventCRFs
* The list of event CRFs for this study event.
* @param eventDefinitionCRFs
* The list of event definition CRFs for this study event.
* @return The list of DisplayEventCRFBeans for this study event.
*/
private ArrayList getDisplayEventCRFs(ArrayList eventCRFs, ArrayList eventDefinitionCRFs) {
ArrayList answer = new ArrayList();
HashMap definitionsById = new HashMap();
int i;
for (i = 0; i < eventDefinitionCRFs.size(); i++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
definitionsById.put(new Integer(edc.getStudyEventDefinitionId()), edc);
}
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
for (i = 0; i < eventCRFs.size(); i++) {
EventCRFBean ecb = (EventCRFBean) eventCRFs.get(i);
// populate the event CRF with its crf bean
int crfVersionId = ecb.getCRFVersionId();
CRFBean cb = cdao.findByVersionId(crfVersionId);
ecb.setCrf(cb);
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(crfVersionId);
ecb.setCrfVersion(cvb);
// then get the definition so we can call
// DisplayEventCRFBean.setFlags
int studyEventId = ecb.getStudyEventId();
int studyEventDefinitionId = sedao.getDefinitionIdFromStudyEventId(studyEventId);
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) definitionsById.get(new Integer(studyEventDefinitionId));
DisplayEventCRFBean dec = new DisplayEventCRFBean();
dec.setFlags(ecb, ub, currentRole, edc.isDoubleEntry());
answer.add(dec);
}
return answer;
}
use of org.akaza.openclinica.bean.submit.DisplayEventCRFBean in project OpenClinica by OpenClinica.
the class RemoveEventCRFServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
// eventCRFId
int eventCRFId = fp.getInt("id");
// studySubjectId
int studySubId = fp.getInt("studySubId");
checkStudyLocked("ViewStudySubject?id" + studySubId, respage.getString("current_study_locked"));
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_remove"));
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());
ArrayList itemData = iddao.findAllByEventCRFId(eventCRF.getId());
request.setAttribute("items", itemData);
String action = request.getParameter("action");
if ("confirm".equalsIgnoreCase(action)) {
if (eventCRF.getStatus().equals(Status.DELETED) || eventCRF.getStatus().equals(Status.AUTO_DELETED)) {
addPageMessage(respage.getString("this_event_CRF_is_removed_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;
}
request.setAttribute("displayEventCRF", dec);
forwardPage(Page.REMOVE_EVENT_CRF);
} else {
logger.info("submit to remove the event CRF from study");
eventCRF.setStatus(Status.DELETED);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
// remove all the item data
for (int a = 0; a < itemData.size(); a++) {
ItemDataBean item = (ItemDataBean) itemData.get(a);
if (!item.getStatus().equals(Status.DELETED)) {
item.setStatus(Status.AUTO_DELETED);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
DiscrepancyNoteDAO dnDao = new DiscrepancyNoteDAO(sm.getDataSource());
List dnNotesOfRemovedItem = dnDao.findExistingNotesForItemData(item.getId());
if (!dnNotesOfRemovedItem.isEmpty()) {
DiscrepancyNoteBean itemParentNote = null;
for (Object obj : dnNotesOfRemovedItem) {
if (((DiscrepancyNoteBean) obj).getParentDnId() == 0) {
itemParentNote = (DiscrepancyNoteBean) obj;
}
}
DiscrepancyNoteBean dnb = new DiscrepancyNoteBean();
if (itemParentNote != null) {
dnb.setParentDnId(itemParentNote.getId());
dnb.setDiscrepancyNoteTypeId(itemParentNote.getDiscrepancyNoteTypeId());
}
dnb.setResolutionStatusId(ResolutionStatus.CLOSED.getId());
dnb.setStudyId(currentStudy.getId());
dnb.setAssignedUserId(ub.getId());
dnb.setOwner(ub);
dnb.setEntityType(DiscrepancyNoteBean.ITEM_DATA);
dnb.setEntityId(item.getId());
dnb.setColumn("value");
dnb.setCreatedDate(new Date());
dnb.setDescription("The item has been removed, this Discrepancy Note has been Closed.");
dnDao.create(dnb);
dnDao.createMapping(dnb);
itemParentNote.setResolutionStatusId(ResolutionStatus.CLOSED.getId());
dnDao.update(itemParentNote);
}
}
}
String emailBody = respage.getString("the_event_CRF") + " " + cb.getName() + " " + respage.getString("has_been_removed_from_the_event") + event.getStudyEventDefinition().getName() + ". " + respage.getString("has_been_removed_from_the_event_cont");
addPageMessage(emailBody);
sendEmail(emailBody);
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
}
}
}
use of org.akaza.openclinica.bean.submit.DisplayEventCRFBean in project OpenClinica by OpenClinica.
the class RestoreStudyEventServlet method getDisplayEventCRFs.
/**
* Each of the event CRFs with its corresponding CRFBean. Then generates a
* list of DisplayEventCRFBeans, one for each event CRF.
*
* @param eventCRFs
* The list of event CRFs for this study event.
* @param eventDefinitionCRFs
* The list of event definition CRFs for this study event.
* @return The list of DisplayEventCRFBeans for this study event.
*/
private ArrayList getDisplayEventCRFs(ArrayList eventCRFs, ArrayList eventDefinitionCRFs) {
ArrayList answer = new ArrayList();
HashMap definitionsById = new HashMap();
int i;
for (i = 0; i < eventDefinitionCRFs.size(); i++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
definitionsById.put(new Integer(edc.getStudyEventDefinitionId()), edc);
}
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
for (i = 0; i < eventCRFs.size(); i++) {
EventCRFBean ecb = (EventCRFBean) eventCRFs.get(i);
// populate the event CRF with its crf bean
int crfVersionId = ecb.getCRFVersionId();
CRFBean cb = cdao.findByVersionId(crfVersionId);
ecb.setCrf(cb);
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(crfVersionId);
ecb.setCrfVersion(cvb);
// then get the definition so we can call
// DisplayEventCRFBean.setFlags
int studyEventId = ecb.getStudyEventId();
int studyEventDefinitionId = sedao.getDefinitionIdFromStudyEventId(studyEventId);
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) definitionsById.get(new Integer(studyEventDefinitionId));
DisplayEventCRFBean dec = new DisplayEventCRFBean();
dec.setFlags(ecb, ub, currentRole, edc.isDoubleEntry());
answer.add(dec);
}
return answer;
}
use of org.akaza.openclinica.bean.submit.DisplayEventCRFBean in project OpenClinica by OpenClinica.
the class ViewStudySubjectServlet method getDisplayEventCRFs.
/**
* Each of the event CRFs with its corresponding CRFBean. Then generates a
* list of DisplayEventCRFBeans, one for each event CRF.
*
* @param eventCRFs
* The list of event CRFs for this study event.
* @param eventDefinitionCRFs
* The list of event definition CRFs for this study event.
* @return The list of DisplayEventCRFBeans for this study event.
*/
public static ArrayList getDisplayEventCRFs(DataSource ds, ArrayList eventCRFs, ArrayList eventDefinitionCRFs, UserAccountBean ub, StudyUserRoleBean currentRole, SubjectEventStatus status, StudyBean study) {
ArrayList answer = new ArrayList();
// HashMap definitionsById = new HashMap();
int i;
/*
* for (i = 0; i < eventDefinitionCRFs.size(); i++) {
* EventDefinitionCRFBean edc = (EventDefinitionCRFBean)
* eventDefinitionCRFs.get(i); definitionsById.put(new
* Integer(edc.getStudyEventDefinitionId()), edc); }
*/
StudyEventDAO sedao = new StudyEventDAO(ds);
CRFDAO cdao = new CRFDAO(ds);
CRFVersionDAO cvdao = new CRFVersionDAO(ds);
FormLayoutDAO fldao = new FormLayoutDAO(ds);
ItemDataDAO iddao = new ItemDataDAO(ds);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(ds);
for (i = 0; i < eventCRFs.size(); i++) {
EventCRFBean ecb = (EventCRFBean) eventCRFs.get(i);
// populate the event CRF with its crf bean
int crfVersionId = ecb.getCRFVersionId();
int formLayoutId = ecb.getFormLayoutId();
CRFBean cb = cdao.findByLayoutId(formLayoutId);
ecb.setCrf(cb);
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(crfVersionId);
ecb.setCrfVersion(cvb);
FormLayoutBean flb = (FormLayoutBean) fldao.findByPK(formLayoutId);
ecb.setFormLayout(flb);
// then get the definition so we can call
// DisplayEventCRFBean.setFlags
int studyEventId = ecb.getStudyEventId();
int studyEventDefinitionId = sedao.getDefinitionIdFromStudyEventId(studyEventId);
// EventDefinitionCRFBean edc = (EventDefinitionCRFBean)
// definitionsById.get(new Integer(
// studyEventDefinitionId));
// fix problem of the above code(commented out), find the correct
// edc, note that on definitionId can be related to multiple
// eventdefinitioncrfBeans
EventDefinitionCRFBean edc = edcdao.findByStudyEventDefinitionIdAndCRFId(study, studyEventDefinitionId, cb.getId());
// rules updated 112007 tbh
if (status.equals(SubjectEventStatus.LOCKED) || status.equals(SubjectEventStatus.SKIPPED) || status.equals(SubjectEventStatus.STOPPED)) {
ecb.setStage(DataEntryStage.LOCKED);
// we need to set a SED-wide flag here, because other edcs
// in this event can be filled in and change the status, tbh
} else if (status.equals(SubjectEventStatus.INVALID)) {
ecb.setStage(DataEntryStage.LOCKED);
} else if (!cb.getStatus().equals(Status.AVAILABLE)) {
ecb.setStage(DataEntryStage.LOCKED);
} else if (!cvb.getStatus().equals(Status.AVAILABLE)) {
ecb.setStage(DataEntryStage.LOCKED);
}
// TODO need to refactor since this is similar to other code, tbh
if (edc != null) {
// System.out.println("edc is not null, need to set flags");
DisplayEventCRFBean dec = new DisplayEventCRFBean();
dec.setEventDefinitionCRF(edc);
// System.out.println("edc.isDoubleEntry()" +
// edc.isDoubleEntry() + ecb.getId());
dec.setFlags(ecb, ub, currentRole, edc.isDoubleEntry());
if (dec.isLocked()) {
// System.out.println("*** found a locked DEC:
// "+edc.getCrfName());
}
ArrayList idata = iddao.findAllByEventCRFId(ecb.getId());
if (!idata.isEmpty()) {
// consider an event crf started only if item data get
// created
answer.add(dec);
}
}
}
return answer;
}
use of org.akaza.openclinica.bean.submit.DisplayEventCRFBean in project OpenClinica by OpenClinica.
the class StudySubjectServiceImpl method getDisplayStudyEventsForStudySubject.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<DisplayStudyEventBean> getDisplayStudyEventsForStudySubject(StudySubjectBean studySubject, UserAccountBean userAccount, StudyUserRoleBean currentRole) {
StudyEventDAO studyEventDao = new StudyEventDAO(dataSource);
StudyEventDefinitionDAO studyEventDefinitionDao = new StudyEventDefinitionDAO(dataSource);
StudyDAO studyDao = new StudyDAO(dataSource);
EventDefinitionCRFDAO eventDefinitionCrfDao = new EventDefinitionCRFDAO(dataSource);
EventCRFDAO eventCrfDao = new EventCRFDAO(dataSource);
CRFDAO crfDao = new CRFDAO(dataSource);
FormLayoutDAO formLayoutDAO = new FormLayoutDAO(dataSource);
ArrayList events = studyEventDao.findAllByStudySubject(studySubject);
Map<Integer, StudyEventDefinitionBean> eventDefinitionByEvent = studyEventDefinitionDao.findByStudySubject(studySubject.getId());
StudyBean study = (StudyBean) studyDao.findByPK(studySubject.getStudyId());
Map<Integer, SortedSet<EventDefinitionCRFBean>> eventDefinitionCrfByStudyEventDefinition;
if (study.getParentStudyId() < 1) {
// Is a study
eventDefinitionCrfByStudyEventDefinition = eventDefinitionCrfDao.buildEventDefinitionCRFListByStudyEventDefinitionForStudy(studySubject.getId());
} else {
// Is a site
eventDefinitionCrfByStudyEventDefinition = eventDefinitionCrfDao.buildEventDefinitionCRFListByStudyEventDefinition(studySubject.getId(), study.getId(), study.getParentStudyId());
}
Map<Integer, SortedSet<EventCRFBean>> eventCrfListByStudyEvent = eventCrfDao.buildEventCrfListByStudyEvent(studySubject.getId());
Map<Integer, Integer> maxOrdinalByStudyEvent = studyEventDefinitionDao.buildMaxOrdinalByStudyEvent(studySubject.getId());
Set<Integer> nonEmptyEventCrf = eventCrfDao.buildNonEmptyEventCrfIds(studySubject.getId());
Map<Integer, FormLayoutBean> formLayoutById = formLayoutDAO.buildFormLayoutById(studySubject.getId());
Map<Integer, CRFBean> crfById = crfDao.buildCrfById(studySubject.getId());
ArrayList<DisplayStudyEventBean> displayEvents = new ArrayList<DisplayStudyEventBean>();
for (int i = 0; i < events.size(); i++) {
StudyEventBean event = (StudyEventBean) events.get(i);
StudyEventDefinitionBean sed = eventDefinitionByEvent.get(event.getStudyEventDefinitionId());
event.setStudyEventDefinition(sed);
List eventDefinitionCRFs = new ArrayList((eventDefinitionCrfByStudyEventDefinition.containsKey(sed.getId()) ? eventDefinitionCrfByStudyEventDefinition.get(sed.getId()) : Collections.EMPTY_LIST));
List eventCRFs = new ArrayList((eventCrfListByStudyEvent.containsKey(event.getId())) ? eventCrfListByStudyEvent.get(event.getId()) : Collections.EMPTY_LIST);
// construct info needed on view study event page
DisplayStudyEventBean de = new DisplayStudyEventBean();
de.setStudyEvent(event);
de.setDisplayEventCRFs((ArrayList<DisplayEventCRFBean>) getDisplayEventCRFs(eventCRFs, userAccount, currentRole, event.getSubjectEventStatus(), study, nonEmptyEventCrf, formLayoutById, crfById, event.getStudyEventDefinitionId(), eventDefinitionCRFs));
ArrayList<DisplayEventDefinitionCRFBean> al = getUncompletedCRFs(eventDefinitionCRFs, eventCRFs, event.getSubjectEventStatus(), nonEmptyEventCrf, formLayoutById, crfById);
populateUncompletedCRFsWithCRFAndVersions(al, formLayoutById, crfById);
de.setUncompletedCRFs(al);
// de.setMaximumSampleOrdinal(studyEventDao.getMaxSampleOrdinal(sed,
// studySubject));
de.setMaximumSampleOrdinal(maxOrdinalByStudyEvent.get(event.getStudyEventDefinitionId()));
displayEvents.add(de);
// event.setEventCRFs(createAllEventCRFs(eventCRFs,
// eventDefinitionCRFs));
}
return displayEvents;
}
Aggregations