use of org.akaza.openclinica.dao.submit.EventCRFDAO in project OpenClinica by OpenClinica.
the class SubjectIdSDVFactory method getRow.
private SubjectAggregateContainer getRow(StudySubjectBean studySubjectBean) {
SubjectAggregateContainer row = new SubjectAggregateContainer();
EventCRFDAO eventCRFDAO = new EventCRFDAO(dataSource);
StudyDAO studyDAO = new StudyDAO(dataSource);
StudySubjectDAO studySubjectDAO = new StudySubjectDAO(dataSource);
StudyGroupDAO studyGroupDAO = new StudyGroupDAO(dataSource);
row.setStudySubjectId(studySubjectBean.getLabel());
row.setPersonId(studySubjectBean.getUniqueIdentifier());
row.setStudySubjectStatus(studySubjectBean.getStatus().getName());
int numberEventCRFs = eventCRFDAO.countEventCRFsByStudySubject(studySubjectBean.getId(), studySubjectBean.getStudyId(), studySubjectBean.getStudyId());
row.setTotalEventCRF(numberEventCRFs + "");
StudyBean studyBean = (StudyBean) studyDAO.findByPK(studySubjectBean.getStudyId());
row.setSiteId(studyBean.getIdentifier());
List<EventCRFBean> eventCRFBeans = eventCRFDAO.getEventCRFsByStudySubject(studySubjectBean.getId(), studySubjectBean.getStudyId(), studySubjectBean.getStudyId());
HashMap<String, Integer> stats = getEventCRFStats(eventCRFBeans, studySubjectBean);
//int numberCRFComplete = getNumberCompletedEventCRFs(eventCRFBeans);
//row.setNumberCRFComplete(numberCRFComplete + "");
row.setNumberCRFComplete(stats.get("numberOfCompletedEventCRFs") + "");
row.setNumberOfCRFsSDV(stats.get("numberOfSDVdEventCRFs") + "");
//row.setNumberOfCRFsSDV(getNumberSDVdEventCRFs(eventCRFBeans) + "");
//boolean studySubjectSDVd = eventCRFDAO.countEventCRFsByByStudySubjectCompleteOrLockedAndNotSDVd(studySubjectBean.getId()) == 0 && numberCRFComplete > 0;
boolean studySubjectSDVd = stats.get("areEventCRFsSDVd") == -1 || stats.get("areEventCRFsSDVd") == 1 ? false : true;
StringBuilder sdvStatus = new StringBuilder("");
if (stats.get("shouldDisplaySDVButton") == 0) {
sdvStatus.append("");
} else if (studySubjectSDVd) {
sdvStatus.append("<center><a href='javascript:void(0)' onclick='prompt(document.sdvForm,");
sdvStatus.append(studySubjectBean.getId());
sdvStatus.append(")'>");
sdvStatus.append(getIconForCrfStatusPrefix()).append("DoubleCheck").append(ICON_FORCRFSTATUS_SUFFIX).append("</a></center>");
} else {
sdvStatus.append("<center><input style='margin-right: 5px' type='checkbox' ").append("class='sdvCheck'").append(" name='").append("sdvCheck_").append(studySubjectBean.getId()).append("' /></center>");
}
row.setSdvStatus(sdvStatus.toString());
List<StudyGroupBean> studyGroupBeans = studyGroupDAO.getGroupByStudySubject(studySubjectBean.getId(), studySubjectBean.getStudyId(), studySubjectBean.getStudyId());
if (studyGroupBeans != null && !studyGroupBeans.isEmpty()) {
row.setGroup(studyGroupBeans.get(0).getName());
}
StringBuilder actions = new StringBuilder("<table><tr><td>");
StringBuilder urlPrefix = new StringBuilder("<a href=\"");
StringBuilder path = new StringBuilder(contextPath).append("/pages/viewAllSubjectSDVtmp?studyId=").append(studyId).append("&sdv_f_studySubjectId=");
path.append(studySubjectBean.getLabel());
urlPrefix.append(path).append("\">");
actions.append(urlPrefix).append(SDVUtil.VIEW_ICON_HTML).append("</a></td>");
if (!studySubjectSDVd && stats.get("shouldDisplaySDVButton") == 1) {
StringBuilder jsCodeString = new StringBuilder("this.form.method='GET'; this.form.action='").append(contextPath).append("/pages/sdvStudySubject").append("';").append("this.form.theStudySubjectId.value='").append(studySubjectBean.getId()).append("';").append("this.form.submit();");
actions.append("<td><input type=\"submit\" class=\"button\" value=\"SDV\" name=\"sdvSubmit\" ").append("onclick=\"").append(jsCodeString.toString()).append("\" /></td>");
} else if (!studySubjectSDVd) {
actions.append("<td> SDV N/A</td>");
}
actions.append("</tr></table>");
row.setActions(actions.toString());
return row;
}
use of org.akaza.openclinica.dao.submit.EventCRFDAO in project OpenClinica by OpenClinica.
the class SDVUtil method getFilteredItems.
@SuppressWarnings("unchecked")
private Collection<SubjectSDVContainer> getFilteredItems(EventCRFSDVFilter filterSet, EventCRFSDVSort sortSet, int rowStart, int rowEnd, int studyId, HttpServletRequest request) {
EventCRFDAO eventCRFDAO = new EventCRFDAO(dataSource);
List<EventCRFBean> eventCRFBeans = new ArrayList<EventCRFBean>();
/*
StudyEventDAO studyEventDAO = new StudyEventDAO(dataSource);
StudyDAO studyDAO = new StudyDAO(dataSource);
StudyBean studyBean = (StudyBean) studyDAO.findByPK(studyId);
String label = "";
String eventName = "";
String eventDate = "";
String sdvStatus = "";
String crfStatus = "";
String studyIdentifier = "";
String sdvRequirement = "";
SourceDataVerification sourceDataVerification = null;
if (filterSet.getFilter("studySubjectId") != null) {
label = filterSet.getFilter("studySubjectId").getValue().trim();
eventCRFBeans = eventCRFDAO.getEventCRFsByStudySubjectLabelLimit(label, studyId, studyId, rowEnd - rowStart, rowStart);
} else if (filterSet.getFilter("eventName") != null) {
eventName = filterSet.getFilter("eventName").getValue().trim();
eventCRFBeans = eventCRFDAO.getEventCRFsByEventNameLimit(eventName, rowEnd - rowStart, rowStart);
} else if (filterSet.getFilter("eventDate") != null) {
eventDate = filterSet.getFilter("eventDate").getValue().trim();
eventCRFBeans = eventCRFDAO.getEventCRFsByEventDateLimit(studyId, eventDate, rowEnd - rowStart, rowStart);
} else if (filterSet.getFilter("crfStatus") != null) {
//
//SubjectEventStatus.getSubjectEventStatusIdByName(crfStatus)
crfStatus = filterSet.getFilter("crfStatus").getValue().trim();
//Get the study event for the event crf
eventCRFBeans = eventCRFDAO.getEventCRFsByCRFStatus(studyId, Integer.parseInt(crfStatus), rowEnd - rowStart, rowStart);
} else if (filterSet.getFilter("sdvStatus") != null) {
sdvStatus = filterSet.getFilter("sdvStatus").getValue().trim();
eventCRFBeans = eventCRFDAO.getEventCRFsByStudySDV(studyId, ("complete".equalsIgnoreCase(sdvStatus)), rowEnd - rowStart, rowStart);
} else if (filterSet.getFilter("studyIdentifier") != null) {
studyIdentifier = filterSet.getFilter("studyIdentifier").getValue().trim();
eventCRFBeans = eventCRFDAO.getEventCRFsByStudyIdentifier(studyId, studyId, studyIdentifier, rowEnd - rowStart, rowStart);
} else if (filterSet.getFilter("sdvRequirementDefinition") != null) {
ArrayList<Integer> reqs = new ArrayList<Integer>();
sdvRequirement = filterSet.getFilter("sdvRequirementDefinition").getValue().trim();
if (sdvRequirement.contains("&")) {
for (String requirement : sdvRequirement.split("&")) {
reqs.add(SourceDataVerification.getByI18nDescription(requirement.trim()).getCode());
}
} else {
reqs.add(SourceDataVerification.getByI18nDescription(sdvRequirement.trim()).getCode());
}
if (reqs.size() > 0) {
Integer[] a = { 1 };
eventCRFBeans = eventCRFDAO.getEventCRFsBySDVRequirement(studyId, studyId, rowEnd - rowStart, rowStart, reqs.toArray(a));
}
} else {
eventCRFBeans = eventCRFDAO.getEventCRFsByStudy(studyId, studyId, rowEnd - rowStart, rowStart);
}
*/
eventCRFBeans = eventCRFDAO.getWithFilterAndSort(studyId, studyId, filterSet, sortSet, rowStart, rowEnd);
return getSubjectRows(eventCRFBeans, request);
}
use of org.akaza.openclinica.dao.submit.EventCRFDAO in project OpenClinica by OpenClinica.
the class ImportCRFDataService method eventCRFStatusesValid.
/*
* purpose: returns false if any of the forms/EventCRFs fail the UpsertOnBean rules.
*/
public boolean eventCRFStatusesValid(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());
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 true;
}
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);
// event crf, yet.
if (eventCrfBeans.isEmpty()) {
logger.debug(" found no event crfs from Study Event id " + studyEventBean.getId() + ", location " + studyEventBean.getLocation());
if ((studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.SCHEDULED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.DATA_ENTRY_STARTED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.COMPLETED))) {
if (!upsert.isNotStarted())
return false;
}
}
for (EventCRFBean ecb : eventCrfBeans) {
Integer ecbId = new Integer(ecb.getId());
if (!(ecb.getStage().equals(DataEntryStage.INITIAL_DATA_ENTRY) && upsert.isDataEntryStarted()) && !(ecb.getStage().equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) && upsert.isDataEntryComplete()))
return false;
}
}
}
}
}
return true;
}
use of org.akaza.openclinica.dao.submit.EventCRFDAO 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;
}
use of org.akaza.openclinica.dao.submit.EventCRFDAO in project OpenClinica by OpenClinica.
the class DataImportService method submitData.
public ArrayList<String> submitData(ODMContainer odmContainer, DataSource dataSource, StudyBean studyBean, UserAccountBean userBean, List<DisplayItemBeanWrapper> displayItemBeanWrappers, Map<Integer, String> importedCRFStatuses) throws Exception {
boolean discNotesGenerated = false;
ItemDataDAO itemDataDao = new ItemDataDAO(dataSource);
itemDataDao.setFormatDates(false);
EventCRFDAO eventCrfDao = new EventCRFDAO(dataSource);
StringBuffer auditMsg = new StringBuffer();
int eventCrfBeanId = -1;
EventCRFBean eventCrfBean = null;
ArrayList<Integer> eventCrfInts;
ItemDataBean itemDataBean;
CrfBusinessLogicHelper crfBusinessLogicHelper = new CrfBusinessLogicHelper(dataSource);
for (DisplayItemBeanWrapper wrapper : displayItemBeanWrappers) {
boolean resetSDV = false;
logger.debug("right before we check to make sure it is savable: " + wrapper.isSavable());
if (wrapper.isSavable()) {
eventCrfInts = new ArrayList<Integer>();
logger.debug("wrapper problems found : " + wrapper.getValidationErrors().toString());
if (wrapper.getDisplayItemBeans() != null && wrapper.getDisplayItemBeans().size() == 0) {
return getReturnList("fail", "", "No items to submit. Please check your XML.");
}
for (DisplayItemBean displayItemBean : wrapper.getDisplayItemBeans()) {
eventCrfBeanId = displayItemBean.getData().getEventCRFId();
eventCrfBean = (EventCRFBean) eventCrfDao.findByPK(eventCrfBeanId);
logger.debug("found value here: " + displayItemBean.getData().getValue());
logger.debug("found status here: " + eventCrfBean.getStatus().getName());
itemDataBean = itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(displayItemBean.getItem().getId(), eventCrfBean.getId(), displayItemBean.getData().getOrdinal());
if (wrapper.isOverwrite() && itemDataBean.getStatus() != null) {
if (!itemDataBean.getValue().equals(displayItemBean.getData().getValue()))
resetSDV = true;
logger.debug("just tried to find item data bean on item name " + displayItemBean.getItem().getName());
itemDataBean.setUpdatedDate(new Date());
itemDataBean.setUpdater(userBean);
itemDataBean.setValue(displayItemBean.getData().getValue());
// set status?
itemDataDao.update(itemDataBean);
logger.debug("updated: " + itemDataBean.getItemId());
// need to set pk here in order to create dn
displayItemBean.getData().setId(itemDataBean.getId());
} else {
resetSDV = true;
itemDataDao.create(displayItemBean.getData());
logger.debug("created: " + displayItemBean.getData().getItemId());
itemDataBean = itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(displayItemBean.getItem().getId(), eventCrfBean.getId(), displayItemBean.getData().getOrdinal());
// logger.debug("found: id " + itemDataBean2.getId() + " name " + itemDataBean2.getName());
displayItemBean.getData().setId(itemDataBean.getId());
}
ItemDAO idao = new ItemDAO(dataSource);
ItemBean ibean = (ItemBean) idao.findByPK(displayItemBean.getData().getItemId());
// logger.debug("*** checking for validation errors: " + ibean.getName());
String itemOid = displayItemBean.getItem().getOid() + "_" + wrapper.getStudyEventRepeatKey() + "_" + displayItemBean.getData().getOrdinal() + "_" + wrapper.getStudySubjectOid();
// wrapper.getValidationErrors().toString());
if (wrapper.getValidationErrors().containsKey(itemOid)) {
ArrayList<String> messageList = (ArrayList<String>) wrapper.getValidationErrors().get(itemOid);
for (String message : messageList) {
DiscrepancyNoteBean parentDn = createDiscrepancyNote(ibean, message, eventCrfBean, displayItemBean, null, userBean, dataSource, studyBean);
createDiscrepancyNote(ibean, message, eventCrfBean, displayItemBean, parentDn.getId(), userBean, dataSource, studyBean);
discNotesGenerated = true;
logger.debug("*** created disc note with message: " + message);
auditMsg.append(wrapper.getStudySubjectOid() + ": " + ibean.getOid() + ": " + message + "---");
// split by this ? later, tbh
// displayItemBean);
}
}
if (!eventCrfInts.contains(new Integer(eventCrfBean.getId()))) {
String eventCRFStatus = importedCRFStatuses.get(new Integer(eventCrfBean.getId()));
if (eventCRFStatus != null && eventCRFStatus.equals(DataEntryStage.INITIAL_DATA_ENTRY.getName()) && eventCrfBean.getStatus().isAvailable()) {
crfBusinessLogicHelper.markCRFStarted(eventCrfBean, userBean, true);
} else {
crfBusinessLogicHelper.markCRFComplete(eventCrfBean, userBean, true);
}
eventCrfInts.add(new Integer(eventCrfBean.getId()));
}
}
// Reset the SDV status if item data has been changed or added
if (eventCrfBean != null && resetSDV)
eventCrfDao.setSDVStatus(false, userBean.getId(), eventCrfBean.getId());
}
}
if (!discNotesGenerated) {
return getReturnList("success", "", auditMsg.toString());
} else {
return getReturnList("warn", "", auditMsg.toString());
}
}
Aggregations