use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.
the class SDVUtil method prepareSDVSelectElements.
public void prepareSDVSelectElements(HttpServletRequest request, StudyBean studyBean) {
// Study event statuses
List<String> studyEventStatuses = new ArrayList<String>();
for (org.akaza.openclinica.domain.Status stat : org.akaza.openclinica.domain.Status.values()) {
studyEventStatuses.add(stat.getDescription());
}
request.setAttribute("studyEventStatuses", studyEventStatuses);
// SDV requirements
List<String> sdvRequirements = new ArrayList<String>();
for (SourceDataVerification sdvRequire : SourceDataVerification.values()) {
sdvRequirements.add(sdvRequire.getDescription());
}
request.setAttribute("sdvRequirements", SourceDataVerification.values());
// study event definitions
StudyEventDefinitionDAO studyEventDefinitionDAO = new StudyEventDefinitionDAO(dataSource);
List<StudyEventDefinitionBean> studyEventDefinitionBeans = new ArrayList<StudyEventDefinitionBean>();
studyEventDefinitionBeans = studyEventDefinitionDAO.findAllByStudy(studyBean);
request.setAttribute("studyEventDefinitions", studyEventDefinitionBeans);
// study event status
request.setAttribute("studyEventStatuses", Status.toArrayList());
// event CRF status
request.setAttribute("eventCRFDStatuses", SubjectEventStatus.toArrayList());
StudyEventDAO studyEventDAO = new StudyEventDAO(dataSource);
List<StudyEventBean> studyEventBeans = studyEventDAO.findAllByStudy(studyBean);
List<EventCRFBean> eventCRFBeans = getAllEventCRFs(studyEventBeans);
SortedSet<String> eventCRFNames = new TreeSet<String>();
for (EventCRFBean bean : eventCRFBeans) {
eventCRFNames.add(getCRFName(bean.getCRFVersionId()));
}
request.setAttribute("eventCRFNames", eventCRFNames);
}
use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.
the class SDVUtil method filterEventCRFs.
public List<EventCRFBean> filterEventCRFs(List<EventCRFBean> eventCRFBeans, BindingResult bindingResult) {
/*
* study_subject_id=Subject+D&eventCRF=0&studyEventDefinition=0&
* studyEventStatus=-1&eventCRFStatus=-1&eventcrfSDVStatus=None&
* sdvRequirement=0&startUpdatedDate=&endDate=&submit=Apply+Filter
*/
List<EventCRFBean> newList = new ArrayList<EventCRFBean>();
if (eventCRFBeans == null || eventCRFBeans.isEmpty() || bindingResult == null) {
return eventCRFBeans;
}
SdvFilterDataBean filterBean = (SdvFilterDataBean) bindingResult.getTarget();
StudySubjectBean studySubjectBean = null;
StudyEventBean studyEventBean = null;
StudySubjectDAO studySubjectDAO = new StudySubjectDAO(dataSource);
StudyEventDAO studyEventDAO = new StudyEventDAO(dataSource);
boolean studySub = true, studyEventDef = true, studyEventStatus = true, eventCRFStatusBool = true, eventcrfSDVStatus = true, eventCRFNameBool = true, upDatedDateBool = true, sdvRequirementBool = true;
for (EventCRFBean eventCBean : eventCRFBeans) {
// filter study subject
if (filterBean.getStudy_subject_id().length() > 0) {
studySubjectBean = (StudySubjectBean) studySubjectDAO.findByPK(eventCBean.getStudySubjectId());
studySub = filterBean.getStudy_subject_id().equalsIgnoreCase(studySubjectBean.getLabel());
}
if (filterBean.getStudyEventDefinition() > 0) {
studyEventBean = (StudyEventBean) studyEventDAO.findByPK(eventCBean.getStudyEventId());
studyEventDef = filterBean.getStudyEventDefinition() == studyEventBean.getStudyEventDefinitionId();
}
// Event CRF status
if (filterBean.getStudyEventStatus() > 0) {
studyEventStatus = filterBean.getStudyEventStatus() == eventCBean.getStatus().getId();
}
// Event CRF subject event status
if (filterBean.getEventCRFStatus() > 0) {
studyEventBean = (StudyEventBean) studyEventDAO.findByPK(eventCBean.getStudyEventId());
eventCRFStatusBool = filterBean.getEventCRFStatus() == studyEventBean.getSubjectEventStatus().getId();
}
// Event CRF SDV status; true or false
if (!filterBean.getEventcrfSDVStatus().equalsIgnoreCase("N/A")) {
boolean sdvBool = filterBean.getEventcrfSDVStatus().equalsIgnoreCase("complete");
eventcrfSDVStatus = eventCBean.isSdvStatus() == sdvBool;
}
// Event CRF name match
if (filterBean.getEventCRFName().length() > 0) {
String tmpName = getCRFName(eventCBean.getCRFVersionId());
eventCRFNameBool = tmpName.equalsIgnoreCase(filterBean.getEventCRFName());
}
// event CRF updated date
if (eventCBean.getUpdatedDate() != null && filterBean.getStartUpdatedDate() != null && filterBean.getEndDate() != null) {
GregorianCalendar calStart = new GregorianCalendar();
calStart.setTime(filterBean.getStartUpdatedDate());
GregorianCalendar calendarEnd = new GregorianCalendar();
calendarEnd.setTime(filterBean.getEndDate());
GregorianCalendar calendarNow = new GregorianCalendar();
calendarNow.setTime(eventCBean.getUpdatedDate());
upDatedDateBool = calendarNow.after(calStart) && calendarNow.before(calendarEnd) || calendarNow.equals(calStart) || calendarNow.equals(calendarEnd);
}
if (upDatedDateBool && eventCRFNameBool && eventcrfSDVStatus && eventCRFStatusBool && studyEventStatus && studyEventDef && studySub) {
newList.add(eventCBean);
}
}
return newList;
}
use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.
the class OpenRosaServices method getSchedule.
@GET
@Path("/{studyOID}/getSchedule")
@Produces(MediaType.APPLICATION_XML)
public String getSchedule(@Context HttpServletRequest request, @Context HttpServletResponse response, @Context ServletContext context, @PathParam("studyOID") String studyOID, @RequestHeader("Authorization") String authorization) throws Exception {
String ssoid = request.getParameter("studySubjectOID");
StudySubjectDAO ssdao = new StudySubjectDAO<String, ArrayList>(dataSource);
StudySubjectBean ssBean = ssdao.findByOid(ssoid);
if (!mayProceedSubmission(studyOID, ssBean))
return null;
HashMap<String, String> urlCache = (HashMap<String, String>) context.getAttribute("pformURLCache");
context.getAttribute("subjectContextCache");
if (ssoid == null) {
return "<error>studySubjectOID is null :(</error>";
}
try {
// Need to retrieve crf's for next event
StudyEventDAO eventDAO = new StudyEventDAO(getDataSource());
StudyEventBean nextEvent = (StudyEventBean) eventDAO.getNextScheduledEvent(ssoid);
CRFVersionDAO versionDAO = new CRFVersionDAO(getDataSource());
ArrayList<CRFVersionBean> crfs = versionDAO.findDefCRFVersionsByStudyEvent(nextEvent.getStudyEventDefinitionId());
PFormCache cache = PFormCache.getInstance(context);
for (CRFVersionBean crfVersion : crfs) {
String enketoURL = cache.getPFormURL(studyOID, crfVersion.getOid());
String contextHash = cache.putSubjectContext(ssoid, String.valueOf(nextEvent.getStudyEventDefinitionId()), String.valueOf(nextEvent.getSampleOrdinal()), crfVersion.getOid());
}
} catch (Exception e) {
LOGGER.debug(e.getMessage());
LOGGER.debug(ExceptionUtils.getStackTrace(e));
return "<error>" + e.getMessage() + "</error>";
}
response.setHeader("Content-Type", "text/xml; charset=UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=\"schedule.xml\";");
response.setContentType("text/xml; charset=utf-8");
return "<result>success</result>";
}
use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.
the class ImportCRFDataService method fetchEventCRFStatuses.
/*
* purpose: Build a map of EventCRFs and the statuses they should have post-import. Assumes EventCRFs have been
* created for "Not Started" forms.
*/
public void fetchEventCRFStatuses(ODMContainer odmContainer, HashMap<Integer, String> importedCRFStatuses) {
EventCRFDAO eventCrfDAO = new EventCRFDAO(ds);
StudySubjectDAO studySubjectDAO = new StudySubjectDAO(ds);
StudyEventDefinitionDAO studyEventDefinitionDAO = new StudyEventDefinitionDAO(ds);
StudyDAO studyDAO = new StudyDAO(ds);
StudyEventDAO studyEventDAO = new StudyEventDAO(ds);
String studyOID = odmContainer.getCrfDataPostImportContainer().getStudyOID();
StudyBean studyBean = studyDAO.findByOid(studyOID);
ArrayList<SubjectDataBean> subjectDataBeans = odmContainer.getCrfDataPostImportContainer().getSubjectData();
for (SubjectDataBean subjectDataBean : subjectDataBeans) {
ArrayList<StudyEventDataBean> studyEventDataBeans = subjectDataBean.getStudyEventData();
StudySubjectBean studySubjectBean = studySubjectDAO.findByOidAndStudy(subjectDataBean.getSubjectOID(), studyBean.getId());
for (StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
ArrayList<FormDataBean> formDataBeans = studyEventDataBean.getFormData();
String sampleOrdinal = studyEventDataBean.getStudyEventRepeatKey() == null ? "1" : studyEventDataBean.getStudyEventRepeatKey();
StudyEventDefinitionBean studyEventDefinitionBean = studyEventDefinitionDAO.findByOidAndStudy(studyEventDataBean.getStudyEventOID(), studyBean.getId(), studyBean.getParentStudyId());
logger.info("find all by def and subject " + studyEventDefinitionBean.getName() + " study subject " + studySubjectBean.getName());
StudyEventBean studyEventBean = (StudyEventBean) studyEventDAO.findByStudySubjectIdAndDefinitionIdAndOrdinal(studySubjectBean.getId(), studyEventDefinitionBean.getId(), Integer.parseInt(sampleOrdinal));
for (FormDataBean formDataBean : formDataBeans) {
CRFVersionDAO crfVersionDAO = new CRFVersionDAO(ds);
ArrayList<CRFVersionBean> crfVersionBeans = crfVersionDAO.findAllByOid(formDataBean.getFormOID());
for (CRFVersionBean crfVersionBean : crfVersionBeans) {
ArrayList<EventCRFBean> eventCrfBeans = eventCrfDAO.findByEventSubjectVersion(studyEventBean, studySubjectBean, crfVersionBean);
for (EventCRFBean ecb : eventCrfBeans) {
Integer ecbId = new Integer(ecb.getId());
if (!importedCRFStatuses.keySet().contains(ecbId) && formDataBean.getEventCRFStatus() != null) {
importedCRFStatuses.put(ecb.getId(), formDataBean.getEventCRFStatus());
}
}
}
}
}
}
}
use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.
the class ImportCRFDataService method fetchEventCRFBeans.
/*
* purpose: look up EventCRFBeans by the following: Study Subject, Study Event, CRF Version, using the
* findByEventSubjectVersion method in EventCRFDAO. May return more than one, hmm.
*/
public List<EventCRFBean> fetchEventCRFBeans(ODMContainer odmContainer, UserAccountBean ub) {
ArrayList<EventCRFBean> eventCRFBeans = new ArrayList<EventCRFBean>();
ArrayList<Integer> eventCRFBeanIds = new ArrayList<Integer>();
EventCRFDAO eventCrfDAO = new EventCRFDAO(ds);
StudySubjectDAO studySubjectDAO = new StudySubjectDAO(ds);
StudyEventDefinitionDAO studyEventDefinitionDAO = new StudyEventDefinitionDAO(ds);
StudyDAO studyDAO = new StudyDAO(ds);
StudyEventDAO studyEventDAO = new StudyEventDAO(ds);
UpsertOnBean upsert = odmContainer.getCrfDataPostImportContainer().getUpsertOn();
// If Upsert bean is not present, create one with default settings
if (upsert == null)
upsert = new UpsertOnBean();
String studyOID = odmContainer.getCrfDataPostImportContainer().getStudyOID();
StudyBean studyBean = studyDAO.findByOid(studyOID);
ArrayList<SubjectDataBean> subjectDataBeans = odmContainer.getCrfDataPostImportContainer().getSubjectData();
for (SubjectDataBean subjectDataBean : subjectDataBeans) {
ArrayList<StudyEventDataBean> studyEventDataBeans = subjectDataBean.getStudyEventData();
StudySubjectBean studySubjectBean = studySubjectDAO.findByOidAndStudy(subjectDataBean.getSubjectOID(), studyBean.getId());
for (StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
ArrayList<FormDataBean> formDataBeans = studyEventDataBean.getFormData();
String sampleOrdinal = studyEventDataBean.getStudyEventRepeatKey() == null ? "1" : studyEventDataBean.getStudyEventRepeatKey();
StudyEventDefinitionBean studyEventDefinitionBean = studyEventDefinitionDAO.findByOidAndStudy(studyEventDataBean.getStudyEventOID(), studyBean.getId(), studyBean.getParentStudyId());
logger.info("find all by def and subject " + studyEventDefinitionBean.getName() + " study subject " + studySubjectBean.getName());
for (FormDataBean formDataBean : formDataBeans) {
CRFVersionDAO crfVersionDAO = new CRFVersionDAO(ds);
ArrayList<CRFVersionBean> crfVersionBeans = crfVersionDAO.findAllByOid(formDataBean.getFormOID());
// studySubjectBean.getId(),Integer.parseInt(sampleOrdinal));
for (CRFVersionBean crfVersionBean : crfVersionBeans) {
// iterate the studyeventbeans here
// for (StudyEventBean studyEventBean : studyEventBeans) {
StudyEventBean studyEventBean = (StudyEventBean) studyEventDAO.findByStudySubjectIdAndDefinitionIdAndOrdinal(studySubjectBean.getId(), studyEventDefinitionBean.getId(), Integer.parseInt(sampleOrdinal));
// locked
if (studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.LOCKED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.SIGNED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.STOPPED)) {
return null;
}
ArrayList<EventCRFBean> eventCrfBeans = eventCrfDAO.findByEventSubjectVersion(studyEventBean, studySubjectBean, crfVersionBean);
// event crf, yet.
if (eventCrfBeans.isEmpty()) {
logger.debug(" found no event crfs from Study Event id " + studyEventBean.getId() + ", location " + studyEventBean.getLocation());
// necessary, avoiding false-positives
if ((studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.SCHEDULED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.DATA_ENTRY_STARTED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.COMPLETED)) && upsert.isNotStarted()) {
EventCRFBean newEventCrfBean = new EventCRFBean();
newEventCrfBean.setStudyEventId(studyEventBean.getId());
newEventCrfBean.setStudySubjectId(studySubjectBean.getId());
newEventCrfBean.setCRFVersionId(crfVersionBean.getId());
newEventCrfBean.setDateInterviewed(new Date());
newEventCrfBean.setOwner(ub);
newEventCrfBean.setInterviewerName(ub.getName());
// place
newEventCrfBean.setCompletionStatusId(1);
// filler
newEventCrfBean.setStatus(Status.AVAILABLE);
newEventCrfBean.setStage(DataEntryStage.INITIAL_DATA_ENTRY);
// these will be updated later in the
// workflow
newEventCrfBean = (EventCRFBean) eventCrfDAO.create(newEventCrfBean);
// eventCrfBeans.add(newEventCrfBean);
logger.debug(" created and added new event crf");
if (!eventCRFBeanIds.contains(newEventCrfBean.getId())) {
eventCRFBeans.add(newEventCrfBean);
eventCRFBeanIds.add(newEventCrfBean.getId());
}
}
} else {
}
for (EventCRFBean ecb : eventCrfBeans) {
Integer ecbId = new Integer(ecb.getId());
if ((upsert.isDataEntryStarted() && ecb.getStage().equals(DataEntryStage.INITIAL_DATA_ENTRY)) || (upsert.isDataEntryComplete() && ecb.getStage().equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE)))
if (!eventCRFBeanIds.contains(ecbId)) {
eventCRFBeans.add(ecb);
eventCRFBeanIds.add(ecbId);
}
}
}
}
}
}
// iteration one
return eventCRFBeans;
}
Aggregations