use of org.akaza.openclinica.bean.submit.SubjectBean 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.SubjectBean in project OpenClinica by OpenClinica.
the class SubjectRow method compareColumn.
/*
* (non-Javadoc)
*
* @see org.akaza.openclinica.core.EntityBeanRow#compareColumn(java.lang.Object,
* int)
*/
@Override
protected int compareColumn(Object row, int sortingColumn) {
if (!row.getClass().equals(SubjectRow.class)) {
return 0;
}
SubjectBean thisSubject = (SubjectBean) bean;
SubjectBean argSubject = (SubjectBean) ((SubjectRow) row).bean;
int answer = 0;
switch(sortingColumn) {
case COL_NAME:
answer = thisSubject.getName().toLowerCase().compareTo(argSubject.getName().toLowerCase());
break;
case COL_GENDER:
answer = (thisSubject.getGender() + "").compareTo(argSubject.getGender() + "");
break;
case COL_DATE_CREATED:
answer = compareDate(thisSubject.getCreatedDate(), argSubject.getCreatedDate());
break;
case COL_OWNER:
answer = thisSubject.getOwner().getName().toLowerCase().compareTo(argSubject.getOwner().getName().toLowerCase());
break;
case COL_DATE_UPDATED:
answer = compareDate(thisSubject.getUpdatedDate(), argSubject.getUpdatedDate());
break;
case COL_UPDATER:
answer = thisSubject.getUpdater().getName().toLowerCase().compareTo(argSubject.getUpdater().getName().toLowerCase());
break;
case COL_STATUS:
answer = thisSubject.getStatus().compareTo(argSubject.getStatus());
break;
}
return answer;
}
use of org.akaza.openclinica.bean.submit.SubjectBean in project OpenClinica by OpenClinica.
the class UpdateSubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
FormDiscrepancyNotes discNotes = new FormDiscrepancyNotes();
String fromResolvingNotes = fp.getString("fromResolvingNotes", true);
if (StringUtils.isBlank(fromResolvingNotes)) {
session.removeAttribute(ViewNotesServlet.WIN_LOCATION);
session.removeAttribute(ViewNotesServlet.NOTES_TABLE);
checkStudyLocked(Page.LIST_SUBJECT_SERVLET, respage.getString("current_study_locked"));
checkStudyFrozen(Page.LIST_SUBJECT_SERVLET, respage.getString("current_study_frozen"));
}
int subjectId = fp.getInt("id", true);
int studySubId = fp.getInt("studySubId", true);
if (subjectId == 0) {
addPageMessage(respage.getString("please_choose_subject_to_edit"));
forwardPage(Page.LIST_SUBJECT_SERVLET);
} else {
String action = fp.getString("action", true);
if (StringUtils.isBlank("action")) {
addPageMessage(respage.getString("no_action_specified"));
forwardPage(Page.LIST_SUBJECT_SERVLET);
return;
}
SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId);
if (action.equals("show") || action.equals("confirm")) {
request.setAttribute("studySubId", new Integer(studySubId));
request.setAttribute("id", new Integer(subjectId));
request.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes);
}
if ("show".equalsIgnoreCase(action)) {
// no DOB collected
request.setAttribute("localBirthDate", "");
if (!currentStudy.getStudyParameterConfig().getCollectDob().equals("3") && subject.getDateOfBirth() != null) {
setLocalDOB(subject);
}
discNotes = new FormDiscrepancyNotes();
request.setAttribute("genderDNFlag", "icon_noNote");
request.setAttribute("birthDNFlag", "icon_noNote");
request.setAttribute("subjectToUpdate", subject);
setDNFlag(subjectId);
forwardPage(Page.UPDATE_SUBJECT);
} else if ("confirm".equalsIgnoreCase(action)) {
confirm(subject, subjectId);
} else {
String gender = fp.getString("gender");
subject.setGender(gender.charAt(0));
if (currentStudy.getStudyParameterConfig().getSubjectPersonIdRequired().equals("required") || currentStudy.getStudyParameterConfig().getSubjectPersonIdRequired().equals("optional")) {
subject.setUniqueIdentifier(fp.getString("uniqueIdentifier"));
}
subject.setUpdater(ub);
if (!currentStudy.getStudyParameterConfig().getCollectDob().equals("3")) {
if (currentStudy.getStudyParameterConfig().getCollectDob().equals("2")) {
String d_date = fp.getString(DATE_DOB_TO_SAVE);
if (!(d_date == null || d_date.trim().length() == 0)) {
Date date_new = yformat.parse(fp.getString(DATE_DOB_TO_SAVE));
subject.setDateOfBirth(date_new);
}
}
if (currentStudy.getStudyParameterConfig().getCollectDob().equals("1")) {
Date date_new = local_df.parse(fp.getString(DATE_DOB_TO_SAVE));
subject.setDateOfBirth(date_new);
}
}
sdao.update(subject);
// save discrepancy notes into DB
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
FormDiscrepancyNotes fdn = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
AddNewSubjectServlet.saveFieldNotes("gender", fdn, dndao, subject.getId(), "subject", currentStudy);
AddNewSubjectServlet.saveFieldNotes(DATE_DOB, fdn, dndao, subject.getId(), "subject", currentStudy);
addPageMessage(respage.getString("subject_updated_succcesfully"));
if (studySubId > 0) {
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
} else {
forwardPage(Page.LIST_SUBJECT_SERVLET);
}
}
}
}
use of org.akaza.openclinica.bean.submit.SubjectBean in project OpenClinica by OpenClinica.
the class ListSubjectTableFactory method setDataAndLimitVariables.
@SuppressWarnings("unchecked")
@Override
public void setDataAndLimitVariables(TableFacade tableFacade) {
// initialize i18n
resword = ResourceBundleProvider.getWordsBundle(getLocale());
resformat = ResourceBundleProvider.getFormatBundle(getLocale());
Limit limit = tableFacade.getLimit();
ListSubjectFilter listSubjectFilter = getListSubjectFilter(limit);
if (!limit.isComplete()) {
Integer totalRows = getSubjectDao().getCountWithFilter(listSubjectFilter, getCurrentStudy());
if (totalRows == null) {
totalRows = 0;
}
tableFacade.setTotalRows(totalRows.intValue());
}
ListSubjectSort listSubjectSort = getListSubjectSort(limit);
int rowStart = limit.getRowSelect().getRowStart();
int rowEnd = limit.getRowSelect().getRowEnd();
Collection<SubjectBean> items = getSubjectDao().getWithFilterAndSort(getCurrentStudy(), listSubjectFilter, listSubjectSort, rowStart, rowEnd);
Collection<HashMap<Object, Object>> theItems = new ArrayList<HashMap<Object, Object>>();
for (SubjectBean subject : items) {
UserAccountBean owner = (UserAccountBean) getUserAccountDao().findByPK(subject.getOwnerId());
UserAccountBean updater = subject.getUpdaterId() == 0 ? null : (UserAccountBean) getUserAccountDao().findByPK(subject.getUpdaterId());
HashMap<Object, Object> h = new HashMap<Object, Object>();
String studySubjectIdAndStudy = "";
List<StudySubjectBean> studySubjects = getStudySubjectDao().findAllBySubjectId(subject.getId());
for (StudySubjectBean studySubjectBean : studySubjects) {
StudyBean study = (StudyBean) getStudyDao().findByPK(studySubjectBean.getStudyId());
studySubjectIdAndStudy += studySubjectIdAndStudy.length() == 0 ? "" : ",";
studySubjectIdAndStudy += study.getIdentifier() + "-" + studySubjectBean.getLabel();
}
h.put("studySubjectIdAndStudy", studySubjectIdAndStudy);
h.put("subject", subject);
h.put("subject.uniqueIdentifier", subject.getUniqueIdentifier());
h.put("subject.gender", subject.getGender());
Date tempDate = subject.getCreatedDate();
String tempDateStr = tempDate == null ? "" : I18nFormatUtil.getDateFormat(getLocale()).format(tempDate);
h.put("subject.createdDate", tempDateStr);
h.put("subject.owner", owner);
tempDate = subject.getUpdatedDate();
tempDateStr = tempDate == null ? "" : I18nFormatUtil.getDateFormat(getLocale()).format(tempDate);
h.put("subject.updatedDate", tempDateStr);
h.put("subject.updater", updater);
h.put("subject.status", subject.getStatus());
theItems.add(h);
}
tableFacade.setItems(theItems);
}
use of org.akaza.openclinica.bean.submit.SubjectBean in project OpenClinica by OpenClinica.
the class RemoveSubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
int subjectId = fp.getInt("id");
String action = fp.getString("action");
if (subjectId == 0 || StringUtil.isBlank(action)) {
addPageMessage(respage.getString("please_choose_a_subject_to_remove"));
forwardPage(Page.SUBJECT_LIST_SERVLET);
} else {
SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId);
// find all study subjects
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ArrayList studySubs = ssdao.findAllBySubjectId(subjectId);
// find study events
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
ArrayList events = sedao.findAllBySubjectId(subjectId);
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute("subjectToRemove", subject);
request.setAttribute("studySubs", studySubs);
request.setAttribute("events", events);
forwardPage(Page.REMOVE_SUBJECT);
} else {
logger.info("submit to remove the subject");
// change all statuses to deleted
subject.setStatus(Status.DELETED);
subject.setUpdater(ub);
subject.setUpdatedDate(new Date());
sdao.update(subject);
// remove subject references from study
for (int i = 0; i < studySubs.size(); i++) {
StudySubjectBean studySub = (StudySubjectBean) studySubs.get(i);
if (!studySub.getStatus().equals(Status.DELETED)) {
studySub.setStatus(Status.AUTO_DELETED);
studySub.setUpdater(ub);
studySub.setUpdatedDate(new Date());
ssdao.update(studySub);
}
}
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);
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.getUniqueIdentifier() + " " + respage.getString("has_been_removed_succesfully");
addPageMessage(emailBody);
// sendEmail(emailBody);
forwardPage(Page.SUBJECT_LIST_SERVLET);
}
}
}
Aggregations