use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO 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.dao.managestudy.StudySubjectDAO 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.dao.managestudy.StudySubjectDAO 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.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.
the class DataEntryServlet method createEventCRF.
/**
* Creates a new Event CRF or update the exsiting one, that is, an event CRF can be created but not item data yet, in this case, still consider it is not
* started(called uncompleted before)
* @param request TODO
* @param fp TODO
*
* @return
* @throws Exception
*/
private EventCRFBean createEventCRF(HttpServletRequest request, FormProcessor fp) throws InconsistentStateException {
locale = LocaleResolver.getLocale(request);
// < resmessage =
// ResourceBundle.getBundle("org.akaza.openclinica.i18n.page_messages",
// locale);
// < restext =
// ResourceBundle.getBundle("org.akaza.openclinica.i18n.notes",locale);
// <
// resexception=ResourceBundle.getBundle(
// "org.akaza.openclinica.i18n.exceptions",locale);
UserAccountBean ub = (UserAccountBean) request.getSession().getAttribute(USER_BEAN_NAME);
StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
EventCRFBean ecb;
EventCRFDAO ecdao = new EventCRFDAO(getDataSource());
int crfVersionId = fp.getInt(INPUT_CRF_VERSION_ID);
LOGGER.trace("***FOUND*** crfversionid: " + crfVersionId);
int studyEventId = fp.getInt(INPUT_STUDY_EVENT_ID);
int eventDefinitionCRFId = fp.getInt(INPUT_EVENT_DEFINITION_CRF_ID);
int subjectId = fp.getInt(INPUT_SUBJECT_ID);
int eventCRFId = fp.getInt(INPUT_EVENT_CRF_ID);
LOGGER.trace("look specifically wrt event crf id: " + eventCRFId);
LOGGER.trace("Creating event CRF. Study id: " + currentStudy.getId() + "; CRF Version id: " + crfVersionId + "; Study Event id: " + studyEventId + "; Event Definition CRF id: " + eventDefinitionCRFId + "; Subject: " + subjectId);
StudySubjectDAO ssdao = new StudySubjectDAO(getDataSource());
StudySubjectBean ssb = ssdao.findBySubjectIdAndStudy(subjectId, currentStudy);
if (ssb.getId() <= 0) {
LOGGER.trace("throwing ISE with study subject bean id of " + ssb.getId());
// "begin_data_entry_without_event_but_subject"));
throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("begin_data_entry_without_event_but_subject"));
}
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(getDataSource());
StudyEventDefinitionBean sedb = seddao.findByEventDefinitionCRFId(eventDefinitionCRFId);
// logger.trace("study event definition:" + sedb.getId());
if (sedb.getId() <= 0) {
addPageMessage(resexception.getString("begin_data_entry_without_event_but_study"), request);
throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("begin_data_entry_without_event_but_study"));
}
CRFVersionDAO cvdao = new CRFVersionDAO(getDataSource());
EntityBean eb = cvdao.findByPK(crfVersionId);
if (eb.getId() <= 0) {
//addPageMessage(resexception.getString("begin_data_entry_without_event_but_CRF"));
throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("begin_data_entry_without_event_but_CRF"));
}
StudyEventDAO sedao = new StudyEventDAO(getDataSource());
StudyEventBean sEvent = (StudyEventBean) sedao.findByPK(studyEventId);
StudyBean studyWithSED = currentStudy;
if (currentStudy.getParentStudyId() > 0) {
studyWithSED = new StudyBean();
studyWithSED.setId(currentStudy.getParentStudyId());
}
AuditableEntityBean aeb = sedao.findByPKAndStudy(studyEventId, studyWithSED);
if (aeb.getId() <= 0) {
addPageMessage(resexception.getString("begin_data_entry_without_event_but_especified_event"), request);
throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("begin_data_entry_without_event_but_especified_event"));
}
ecb = new EventCRFBean();
if (eventCRFId == 0) {
// no event CRF created yet
ArrayList ecList = ecdao.findByEventSubjectVersion(sEvent, ssb, (CRFVersionBean) eb);
if (ecList.size() > 0) {
ecb = (EventCRFBean) ecList.get(0);
} else {
ecb.setAnnotations("");
ecb.setCreatedDate(new Date());
ecb.setCRFVersionId(crfVersionId);
if (currentStudy.getStudyParameterConfig().getInterviewerNameDefault().equals("blank")) {
ecb.setInterviewerName("");
} else {
// default will be event's owner name
ecb.setInterviewerName(sEvent.getOwner().getName());
}
if (!currentStudy.getStudyParameterConfig().getInterviewDateDefault().equals("blank")) {
if (sEvent.getDateStarted() != null) {
// default
ecb.setDateInterviewed(sEvent.getDateStarted());
// date
} else {
// logger.trace("evnet start date is null, so date
// interviewed is null");
ecb.setDateInterviewed(null);
}
} else {
ecb.setDateInterviewed(null);
// logger.trace("date interviewed is
// null,getInterviewDateDefault() is blank");
}
// ecb.setOwnerId(ub.getId());
// above depreciated, try without it, tbh
ecb.setOwner(ub);
ecb.setStatus(Status.AVAILABLE);
ecb.setCompletionStatusId(1);
ecb.setStudySubjectId(ssb.getId());
ecb.setStudyEventId(studyEventId);
ecb.setValidateString("");
ecb.setValidatorAnnotations("");
ecb = (EventCRFBean) ecdao.create(ecb);
LOGGER.debug("*********CREATED EVENT CRF");
}
} else {
// there is an event CRF already, only need to update
ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
ecb.setCRFVersionId(crfVersionId);
ecb.setUpdatedDate(new Date());
ecb.setUpdater(ub);
ecb = updateECB(sEvent, request);
ecb = (EventCRFBean) ecdao.update(ecb);
}
if (ecb.getId() <= 0) {
addPageMessage(resexception.getString("new_event_CRF_not_created"), request);
throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("new_event_CRF_not_created"));
} else {
if (sEvent.getSubjectEventStatus().equals(SubjectEventStatus.SIGNED)) {
sEvent.setSubjectEventStatus(SubjectEventStatus.COMPLETED);
sEvent.setUpdater(ub);
sEvent.setUpdatedDate(new Date());
sedao.update(sEvent);
} else {
sEvent.setSubjectEventStatus(SubjectEventStatus.DATA_ENTRY_STARTED);
sEvent.setUpdater(ub);
sEvent.setUpdatedDate(new Date());
sedao.update(sEvent);
}
}
return ecb;
}
use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.
the class CreateDiscrepancyNoteServlet method updateStudySubjectStatus.
/**
* Pulls the note related information from database according to note type
*
* @param note
*/
private void updateStudySubjectStatus(String entityType, int entityId) {
if ("itemData".equalsIgnoreCase(entityType)) {
int itemDataId = entityId;
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
ItemDataBean itemData = (ItemDataBean) iddao.findByPK(itemDataId);
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
StudyEventDAO svdao = new StudyEventDAO(sm.getDataSource());
StudySubjectDAO studySubjectDAO = new StudySubjectDAO(sm.getDataSource());
EventCRFBean ec = (EventCRFBean) ecdao.findByPK(itemData.getEventCRFId());
StudyEventBean event = (StudyEventBean) svdao.findByPK(ec.getStudyEventId());
StudySubjectBean studySubject = (StudySubjectBean) studySubjectDAO.findByPK(event.getStudySubjectId());
if (studySubject.getStatus() != null && studySubject.getStatus().equals(Status.SIGNED)) {
studySubject.setStatus(Status.AVAILABLE);
studySubject.setUpdater(ub);
studySubject.setUpdatedDate(new Date());
studySubjectDAO.update(studySubject);
}
if (ec.isSdvStatus()) {
studySubject.setStatus(Status.AVAILABLE);
studySubject.setUpdater(ub);
studySubject.setUpdatedDate(new Date());
studySubjectDAO.update(studySubject);
ec.setSdvStatus(false);
ec.setSdvUpdateId(ub.getId());
ecdao.update(ec);
}
}
}
Aggregations