use of org.akaza.openclinica.dao.managestudy.ListDiscNotesForCRFFilter 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.dao.managestudy.ListDiscNotesForCRFFilter in project OpenClinica by OpenClinica.
the class ListDiscNotesForCRFTableFactory method getListEventsForSubjectFilter.
protected ListDiscNotesForCRFFilter getListEventsForSubjectFilter(Limit limit) {
ListDiscNotesForCRFFilter listDiscNotesForCRFFilter = new ListDiscNotesForCRFFilter(selectedStudyEventDefinition.getId());
FilterSet filterSet = limit.getFilterSet();
Collection<Filter> filters = filterSet.getFilters();
for (Filter filter : filters) {
String property = filter.getProperty();
String value = filter.getValue();
listDiscNotesForCRFFilter.addFilter(property, value);
}
return listDiscNotesForCRFFilter;
}
Aggregations