use of org.akaza.openclinica.bean.managestudy.StudySubjectBean in project OpenClinica by OpenClinica.
the class ViewNotesServlet method filterForOneSubject.
public ArrayList<DiscrepancyNoteBean> filterForOneSubject(ArrayList<DiscrepancyNoteBean> allNotes, int subjectId, int resolutionStatus) {
if (allNotes == null || allNotes.isEmpty() || subjectId == 0)
return allNotes;
// Are the D Notes filtered by resolution?
boolean filterByRes = resolutionStatus >= 1 && resolutionStatus <= 5;
ArrayList<DiscrepancyNoteBean> filteredNotes = new ArrayList<DiscrepancyNoteBean>();
StudySubjectDAO subjectDao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean studySubjBean = (StudySubjectBean) subjectDao.findByPK(subjectId);
for (DiscrepancyNoteBean discBean : allNotes) {
if (discBean.getSubjectName().equalsIgnoreCase(studySubjBean.getLabel())) {
if (!filterByRes) {
filteredNotes.add(discBean);
} else {
if (discBean.getResolutionStatusId() == resolutionStatus) {
filteredNotes.add(discBean);
}
}
}
}
return filteredNotes;
}
use of org.akaza.openclinica.bean.managestudy.StudySubjectBean in project OpenClinica by OpenClinica.
the class ViewStudyEventsServlet method genEventsForPrint.
/**
* Generates an arraylist of study events for printing
*
* @param fp
* @param definitions
* @param startDate
* @param endDate
* @param sedId
* @param definitionId
* @param statusId
* @return
*/
private ArrayList genEventsForPrint(FormProcessor fp, ArrayList definitions, Date startDate, Date endDate, int sedId, int definitionId, int statusId) {
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ArrayList allEvents = new ArrayList();
definitions = findDefinitionById(definitions, definitionId);
// YW <<
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ArrayList studySubjects = ssdao.findAllByStudyId(currentStudy.getId());
// YW >>
for (int i = 0; i < definitions.size(); i++) {
ViewEventDefinitionBean ved = new ViewEventDefinitionBean();
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) definitions.get(i);
ved.setDefinition(sed);
// YW <<
ArrayList events = new ArrayList();
for (int s = 0; s < studySubjects.size(); ++s) {
StudySubjectBean ssb = (StudySubjectBean) studySubjects.get(s);
ArrayList evts = sedao.findAllWithSubjectLabelByStudySubjectAndDefinition(ssb, sed.getId());
for (int v = 0; v < evts.size(); ++v) {
events.add(evts.get(v));
}
}
// YW >>
int subjectScheduled = 0;
int subjectCompleted = 0;
int subjectDiscontinued = 0;
events = findEventByStatusAndDate(events, statusId, startDate, endDate);
Date firstStartDateForScheduled = null;
Date lastCompletionDate = null;
// find the first firstStartDateForScheduled
for (int k = 0; k < events.size(); k++) {
StudyEventBean se = (StudyEventBean) events.get(k);
if (se.getSubjectEventStatus().equals(SubjectEventStatus.SCHEDULED)) {
firstStartDateForScheduled = se.getDateStarted();
break;
}
}
// find the first lastCompletionDate
for (int k = 0; k < events.size(); k++) {
StudyEventBean se = (StudyEventBean) events.get(k);
if (se.getSubjectEventStatus().equals(SubjectEventStatus.COMPLETED)) {
lastCompletionDate = se.getDateEnded();
break;
}
}
for (int j = 0; j < events.size(); j++) {
StudyEventBean se = (StudyEventBean) events.get(j);
if (se.getSubjectEventStatus().equals(SubjectEventStatus.SCHEDULED)) {
subjectScheduled++;
if (se.getDateStarted().before(new Date())) {
ArrayList eventCRFs = ecdao.findAllByStudyEvent(se);
if (eventCRFs.isEmpty()) {
se.setScheduledDatePast(true);
}
}
if (firstStartDateForScheduled == null) {
firstStartDateForScheduled = se.getDateStarted();
} else if (se.getDateStarted().before(firstStartDateForScheduled)) {
firstStartDateForScheduled = se.getDateStarted();
}
} else if (se.getSubjectEventStatus().equals(SubjectEventStatus.COMPLETED)) {
subjectCompleted++;
if (lastCompletionDate == null) {
lastCompletionDate = se.getDateEnded();
} else if (se.getDateEnded().after(lastCompletionDate)) {
lastCompletionDate = se.getDateEnded();
}
} else if (se.getSubjectEventStatus().getId() > 4) {
// dropped out/stopped/skipped/relapse
subjectDiscontinued++;
}
}
ved.setSubjectCompleted(subjectCompleted);
ved.setSubjectScheduled(subjectScheduled);
ved.setSubjectDiscontinued(subjectDiscontinued);
ved.setFirstScheduledStartDate(firstStartDateForScheduled);
ved.setLastCompletionDate(lastCompletionDate);
ved.setStudyEvents(events);
if (!events.isEmpty()) {
allEvents.add(ved);
}
}
return allEvents;
}
use of org.akaza.openclinica.bean.managestudy.StudySubjectBean in project OpenClinica by OpenClinica.
the class ViewStudyEventsServlet method genTables.
/**
*
* @param fp
* @param definitions
* @param startDate
* @param endDate
* @param sedId
* @param definitionId
* @param statusId
* @return
*/
private ArrayList genTables(FormProcessor fp, ArrayList definitions, Date startDate, Date endDate, int sedId, int definitionId, int statusId) {
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ArrayList allEvents = new ArrayList();
definitions = findDefinitionById(definitions, definitionId);
// YW <<
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ArrayList studySubjects = ssdao.findAllByStudyId(currentStudy.getId());
// YW >>
for (int i = 0; i < definitions.size(); i++) {
ViewEventDefinitionBean ved = new ViewEventDefinitionBean();
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) definitions.get(i);
ved.setDefinition(sed);
// YW <<
ArrayList events = new ArrayList();
for (int s = 0; s < studySubjects.size(); ++s) {
StudySubjectBean ssb = (StudySubjectBean) studySubjects.get(s);
ArrayList evts = sedao.findAllWithSubjectLabelByStudySubjectAndDefinition(ssb, sed.getId());
for (int v = 0; v < evts.size(); ++v) {
StudyEventBean seb = (StudyEventBean) evts.get(v);
if (!(currentRole.isDirector() || currentRole.isCoordinator()) && seb.getSubjectEventStatus().isLocked()) {
seb.setEditable(false);
}
events.add(seb);
}
}
int subjectScheduled = 0;
int subjectCompleted = 0;
int subjectDiscontinued = 0;
events = findEventByStatusAndDate(events, statusId, startDate, endDate);
Date firstStartDateForScheduled = null;
Date lastCompletionDate = null;
// find the first firstStartDateForScheduled
for (int k = 0; k < events.size(); k++) {
StudyEventBean se = (StudyEventBean) events.get(k);
if (se.getSubjectEventStatus().equals(SubjectEventStatus.SCHEDULED)) {
firstStartDateForScheduled = se.getDateStarted();
break;
}
}
// find the first lastCompletionDate
for (int k = 0; k < events.size(); k++) {
StudyEventBean se = (StudyEventBean) events.get(k);
if (se.getSubjectEventStatus().equals(SubjectEventStatus.COMPLETED) && se.getDateEnded() != null) {
lastCompletionDate = se.getDateEnded();
break;
}
}
for (int j = 0; j < events.size(); j++) {
StudyEventBean se = (StudyEventBean) events.get(j);
if (se.getSubjectEventStatus().equals(SubjectEventStatus.SCHEDULED)) {
subjectScheduled++;
if (se.getDateStarted().before(new Date())) {
ArrayList eventCRFs = ecdao.findAllByStudyEvent(se);
if (eventCRFs.isEmpty()) {
se.setScheduledDatePast(true);
}
}
if (firstStartDateForScheduled == null) {
firstStartDateForScheduled = se.getDateStarted();
} else if (se.getDateStarted().before(firstStartDateForScheduled)) {
firstStartDateForScheduled = se.getDateStarted();
}
} else if (se.getSubjectEventStatus().equals(SubjectEventStatus.COMPLETED)) {
subjectCompleted++;
if (lastCompletionDate == null) {
lastCompletionDate = se.getDateEnded();
} else if (se.getDateEnded() != null && se.getDateEnded().after(lastCompletionDate)) {
lastCompletionDate = se.getDateEnded();
}
} else if (se.getSubjectEventStatus().getId() > 4) {
// dropped out/stopped/skipped/relapse
subjectDiscontinued++;
}
}
ved.setSubjectCompleted(subjectCompleted);
ved.setSubjectScheduled(subjectScheduled);
ved.setSubjectDiscontinued(subjectDiscontinued);
ved.setFirstScheduledStartDate(firstStartDateForScheduled);
ved.setLastCompletionDate(lastCompletionDate);
EntityBeanTable table;
if (sedId == sed.getId()) {
// apply finding function or ordering
// function
// to a specific table
table = fp.getEntityBeanTable();
} else {
table = new EntityBeanTable();
}
// sort by event
table.setSortingIfNotExplicitlySet(1, false);
// start date,
// desc
ArrayList allEventRows = StudyEventRow.generateRowsFromBeans(events);
String[] columns = { resword.getString("study_subject_ID"), resword.getString("event_date_started"), resword.getString("subject_event_status"), resword.getString("actions") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.hideColumnLink(3);
HashMap args = new HashMap();
args.put("sedId", new Integer(sed.getId()).toString());
args.put("definitionId", new Integer(definitionId).toString());
args.put("statusId", new Integer(statusId).toString());
args.put("startDate", local_df.format(startDate));
args.put("endDate", local_df.format(endDate));
table.setQuery("ViewStudyEvents", args);
table.setRows(allEventRows);
table.computeDisplay();
ved.setStudyEventTable(table);
if (!events.isEmpty()) {
allEvents.add(ved);
}
}
//A. Hamid.
return allEvents;
}
use of org.akaza.openclinica.bean.managestudy.StudySubjectBean in project OpenClinica by OpenClinica.
the class ViewEventCRFServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
int eventCRFId = fp.getInt("id", true);
int studySubId = fp.getInt("studySubId", true);
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
ItemDAO idao = new ItemDAO(sm.getDataSource());
ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
SectionDAO secdao = new SectionDAO(sm.getDataSource());
if (eventCRFId == 0) {
addPageMessage(respage.getString("please_choose_an_event_CRF_to_view"));
forwardPage(Page.LIST_STUDY_SUBJECTS);
} else {
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
request.setAttribute("studySub", studySub);
EventCRFBean eventCRF = (EventCRFBean) ecdao.findByPK(eventCRFId);
CRFBean crf = cdao.findByVersionId(eventCRF.getCRFVersionId());
request.setAttribute("crf", crf);
ArrayList sections = secdao.findAllByCRFVersionId(eventCRF.getCRFVersionId());
for (int j = 0; j < sections.size(); j++) {
SectionBean section = (SectionBean) sections.get(j);
ArrayList itemData = iddao.findAllByEventCRFId(eventCRFId);
ArrayList displayItemData = new ArrayList();
for (int i = 0; i < itemData.size(); i++) {
ItemDataBean id = (ItemDataBean) itemData.get(i);
DisplayItemBean dib = new DisplayItemBean();
ItemBean item = (ItemBean) idao.findByPK(id.getItemId());
ItemFormMetadataBean ifm = ifmdao.findByItemIdAndCRFVersionId(item.getId(), eventCRF.getCRFVersionId());
item.setItemMeta(ifm);
dib.setItem(item);
dib.setData(id);
dib.setMetadata(ifm);
displayItemData.add(dib);
}
section.setItems(displayItemData);
}
request.setAttribute("sections", sections);
request.setAttribute("studySubId", new Integer(studySubId).toString());
forwardPage(Page.VIEW_EVENT_CRF);
}
}
use of org.akaza.openclinica.bean.managestudy.StudySubjectBean in project OpenClinica by OpenClinica.
the class AddNewSubjectServlet method displaySubjects.
/**
* Find study subject id for each subject, and construct displaySubjectBean
*
* @param displayArray
* @param subjects
*/
public static void displaySubjects(ArrayList displayArray, ArrayList subjects, StudySubjectDAO ssdao, StudyDAO stdao) {
for (int i = 0; i < subjects.size(); i++) {
SubjectBean subject = (SubjectBean) subjects.get(i);
ArrayList studySubs = ssdao.findAllBySubjectId(subject.getId());
String protocolSubjectIds = "";
for (int j = 0; j < studySubs.size(); j++) {
StudySubjectBean studySub = (StudySubjectBean) studySubs.get(j);
int studyId = studySub.getStudyId();
StudyBean stu = (StudyBean) stdao.findByPK(studyId);
String protocolId = stu.getIdentifier();
if (j == studySubs.size() - 1) {
protocolSubjectIds = protocolId + "-" + studySub.getLabel();
} else {
protocolSubjectIds = protocolId + "-" + studySub.getLabel() + ", ";
}
}
DisplaySubjectBean dsb = new DisplaySubjectBean();
dsb.setSubject(subject);
dsb.setStudySubjectIds(protocolSubjectIds);
displayArray.add(dsb);
}
}
Aggregations