use of org.akaza.openclinica.dao.submit.ItemDataDAO 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("subStudy", 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);
}
}
}
use of org.akaza.openclinica.dao.submit.ItemDataDAO in project OpenClinica by OpenClinica.
the class RemoveStudySubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
// studySubjectId
String studySubIdString = request.getParameter("id");
String subIdString = request.getParameter("subjectId");
String studyIdString = request.getParameter("studyId");
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
if (StringUtil.isBlank(studySubIdString) || StringUtil.isBlank(subIdString) || StringUtil.isBlank(studyIdString)) {
addPageMessage(respage.getString("please_choose_a_study_subject_to_remove"));
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
} else {
int studyId = Integer.valueOf(studyIdString.trim()).intValue();
int studySubId = Integer.valueOf(studySubIdString.trim()).intValue();
int subjectId = Integer.valueOf(subIdString.trim()).intValue();
SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId);
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
StudyDAO studydao = new StudyDAO(sm.getDataSource());
StudyBean study = (StudyBean) studydao.findByPK(studyId);
checkRoleByUserAndStudy(ub, study.getParentStudyId(), study.getId());
// find study events
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
// ArrayList events = sedao.findAllByStudyAndStudySubjectId(study, studySubId);
ArrayList<DisplayStudyEventBean> displayEvents = ViewStudySubjectServlet.getDisplayStudyEventsForStudySubject(studySub, sm.getDataSource(), ub, currentRole);
String action = request.getParameter("action");
if ("confirm".equalsIgnoreCase(action)) {
if (!studySub.getStatus().equals(Status.AVAILABLE)) {
addPageMessage(respage.getString("this_subject_is_not_available_for_this_study") + " " + respage.getString("please_contact_sysadmin_for_more_information"));
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
return;
}
request.setAttribute("subject", subject);
request.setAttribute("study", study);
request.setAttribute("studySub", studySub);
request.setAttribute("events", displayEvents);
forwardPage(Page.REMOVE_STUDY_SUBJECT);
} else {
logger.info("submit to remove the subject from study");
// remove subject from study
studySub.setStatus(Status.DELETED);
studySub.setUpdater(ub);
studySub.setUpdatedDate(new Date());
subdao.update(studySub);
// remove all study events
// remove all event crfs
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
for (int j = 0; j < displayEvents.size(); j++) {
DisplayStudyEventBean dispEvent = displayEvents.get(j);
StudyEventBean event = dispEvent.getStudyEvent();
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);
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_subject") + " " + subject.getName() + " " + respage.getString("has_been_removed_from_the_study") + study.getName() + ".";
addPageMessage(emailBody);
// try{
// sendEmail(emailBody);
// }catch(Exception ex){
// addPageMessage(respage.getString("mail_cannot_be_sent_to_admin"));
// }
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
}
}
}
use of org.akaza.openclinica.dao.submit.ItemDataDAO in project OpenClinica by OpenClinica.
the class RestoreStudySubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
// studySubjectId
String studySubIdString = request.getParameter("id");
String subIdString = request.getParameter("subjectId");
String studyIdString = request.getParameter("studyId");
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
if (StringUtil.isBlank(studySubIdString) || StringUtil.isBlank(subIdString) || StringUtil.isBlank(studyIdString)) {
addPageMessage(respage.getString("please_choose_study_subject_to_restore"));
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
} else {
int studyId = Integer.valueOf(studyIdString.trim()).intValue();
int studySubId = Integer.valueOf(studySubIdString.trim()).intValue();
int subjectId = Integer.valueOf(subIdString.trim()).intValue();
SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId);
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
StudyDAO studydao = new StudyDAO(sm.getDataSource());
StudyBean study = (StudyBean) studydao.findByPK(studyId);
// find study events
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
// ArrayList events = sedao.findAllByStudyAndStudySubjectId(study, studySubId);
ArrayList<DisplayStudyEventBean> displayEvents = ViewStudySubjectServlet.getDisplayStudyEventsForStudySubject(studySub, sm.getDataSource(), ub, currentRole);
String action = request.getParameter("action");
if ("confirm".equalsIgnoreCase(action)) {
if (studySub.getStatus().equals(Status.AVAILABLE)) {
addPageMessage(respage.getString("this_subject_is_already_available_for_study") + " " + respage.getString("please_contact_sysadmin_for_more_information"));
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
return;
}
request.setAttribute("subject", subject);
request.setAttribute("study", study);
request.setAttribute("studySub", studySub);
request.setAttribute("events", displayEvents);
forwardPage(Page.RESTORE_STUDY_SUBJECT);
} else {
logger.info("submit to restore the subject from study");
// restore subject from study
studySub.setStatus(Status.AVAILABLE);
studySub.setUpdater(ub);
studySub.setUpdatedDate(new Date());
subdao.update(studySub);
// restore all study events
// restore all event crfs
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
for (int j = 0; j < displayEvents.size(); j++) {
DisplayStudyEventBean dispEvent = displayEvents.get(j);
StudyEventBean event = dispEvent.getStudyEvent();
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(Status.AVAILABLE);
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.AUTO_DELETED)) {
item.setStatus(Status.AVAILABLE);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
}
String emailBody = respage.getString("the_subject") + " " + subject.getName() + " " + respage.getString("has_been_restored_to_the_study") + " " + study.getName() + ".";
addPageMessage(emailBody);
// try{
// sendEmail(emailBody);
// }catch (Exception ex){
// addPageMessage(respage.getString("mail_cannot_be_sent_to_admin"));
// }
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
}
}
}
use of org.akaza.openclinica.dao.submit.ItemDataDAO in project OpenClinica by OpenClinica.
the class SignStudySubjectServlet method getUncompletedCRFs.
/**
* Finds all the event definitions for which no event CRF exists - which is
* the list of event definitions with uncompleted event CRFs.
*
* @param eventDefinitionCRFs
* All of the event definition CRFs for this study event.
* @param eventCRFs
* All of the event CRFs for this study event.
* @return The list of event definitions for which no event CRF exists.
*/
public static ArrayList getUncompletedCRFs(DataSource ds, ArrayList eventDefinitionCRFs, ArrayList eventCRFs, SubjectEventStatus status) {
int i;
HashMap completed = new HashMap();
HashMap startedButIncompleted = new HashMap();
ArrayList answer = new ArrayList();
for (i = 0; i < eventDefinitionCRFs.size(); i++) {
EventDefinitionCRFBean edcrf = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
completed.put(new Integer(edcrf.getCrfId()), Boolean.FALSE);
startedButIncompleted.put(new Integer(edcrf.getCrfId()), new EventCRFBean());
}
CRFVersionDAO cvdao = new CRFVersionDAO(ds);
ItemDataDAO iddao = new ItemDataDAO(ds);
for (i = 0; i < eventCRFs.size(); i++) {
EventCRFBean ecrf = (EventCRFBean) eventCRFs.get(i);
int crfId = cvdao.getCRFIdFromCRFVersionId(ecrf.getCRFVersionId());
ArrayList idata = iddao.findAllByEventCRFId(ecrf.getId());
if (!idata.isEmpty()) {
// this crf has data already
completed.put(new Integer(crfId), Boolean.TRUE);
} else {
// event crf got created, but no data entered
startedButIncompleted.put(new Integer(crfId), ecrf);
}
}
// TODO possible relation to 1689 here, tbh
for (i = 0; i < eventDefinitionCRFs.size(); i++) {
DisplayEventDefinitionCRFBean dedc = new DisplayEventDefinitionCRFBean();
EventDefinitionCRFBean edcrf = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
// System.out.println("created dedc with edcrf
// "+edcrf.getCrfName()+" default version "+
// edcrf.getDefaultVersionName()+", id
// "+edcrf.getDefaultVersionId());
dedc.setEdc(edcrf);
// below added tbh, 112007 to fix bug 1943
if (status.equals(SubjectEventStatus.LOCKED)) {
dedc.setStatus(Status.LOCKED);
}
Boolean b = (Boolean) completed.get(new Integer(edcrf.getCrfId()));
EventCRFBean ev = (EventCRFBean) startedButIncompleted.get(new Integer(edcrf.getCrfId()));
if (b == null || !b.booleanValue()) {
// System.out.println("entered boolean loop with ev
// "+ev.getId()+" crf version id "+
// ev.getCRFVersionId());
dedc.setEventCRF(ev);
answer.add(dedc);
// System.out.println("just added dedc to answer");
// removed, tbh, since this is proving nothing, 11-2007
/*
* if (dedc.getEdc().getDefaultVersionId() !=
* dedc.getEventCRF().getId()) { System.out.println("ID
* MISMATCH: edc name "+dedc.getEdc().getName()+ ", default
* version id "+dedc.getEdc().getDefaultVersionId()+ " event crf
* id "+dedc.getEventCRF().getId()); }
*/
}
}
return answer;
}
use of org.akaza.openclinica.dao.submit.ItemDataDAO in project OpenClinica by OpenClinica.
the class SignStudySubjectServlet 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.
* @return The list of DisplayEventCRFBeans for this study event.
*/
public static ArrayList getDisplayEventCRFs(StudyBean study, DataSource ds, ArrayList eventCRFs, UserAccountBean ub, StudyUserRoleBean currentRole, SubjectEventStatus status) {
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);
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();
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));
// 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();
// 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;
}
Aggregations