use of org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO in project OpenClinica by OpenClinica.
the class UpdateSubStudyServlet method submitSiteEventDefinitions.
private void submitSiteEventDefinitions(StudyBean site) throws MalformedURLException {
FormProcessor fp = new FormProcessor(request);
Validator v = new Validator(request);
HashMap<String, Boolean> changes = new HashMap<String, Boolean>();
HashMap<String, Boolean> changeStatus = (HashMap<String, Boolean>) session.getAttribute("changed");
ArrayList<StudyEventDefinitionBean> seds = new ArrayList<StudyEventDefinitionBean>();
ArrayList<EventDefinitionCRFBean> defCrfs = new ArrayList<EventDefinitionCRFBean>();
StudyEventDefinitionDAO sedDao = new StudyEventDefinitionDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
FormLayoutDAO fldao = new FormLayoutDAO(sm.getDataSource());
StudyBean parentStudyBean;
if (site.getParentStudyId() == 0) {
parentStudyBean = site;
} else {
StudyDAO studyDAO = new StudyDAO(sm.getDataSource());
parentStudyBean = (StudyBean) studyDAO.findByPK(site.getParentStudyId());
}
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
ArrayList<EventDefinitionCRFBean> eventDefCrfList = (ArrayList<EventDefinitionCRFBean>) edcdao.findAllActiveSitesAndStudiesPerParentStudy(parentStudyBean.getId());
ArrayList<EventDefinitionCRFBean> toBeCreatedEventDefBean = new ArrayList<>();
ArrayList<EventDefinitionCRFBean> toBeUpdatedEventDefBean = new ArrayList<>();
ArrayList<EventDefinitionCRFBean> edcsInSession = new ArrayList<EventDefinitionCRFBean>();
boolean changestate = false;
seds = (ArrayList<StudyEventDefinitionBean>) session.getAttribute("definitions");
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
String participateFormStatus = spvdao.findByHandleAndStudy(parentStudyBean.getId(), "participantPortal").getValue();
if (participateFormStatus.equals("enabled"))
baseUrl();
request.setAttribute("participateFormStatus", participateFormStatus);
for (StudyEventDefinitionBean sed : seds) {
ArrayList<EventDefinitionCRFBean> edcs = sed.getCrfs();
int start = 0;
for (EventDefinitionCRFBean edcBean : edcs) {
int edcStatusId = edcBean.getStatus().getId();
if (edcStatusId == 5 || edcStatusId == 7) {
} else {
String order = start + "-" + edcBean.getId();
int defaultVersionId = fp.getInt("defaultVersionId" + order);
String requiredCRF = fp.getString("requiredCRF" + order);
String doubleEntry = fp.getString("doubleEntry" + order);
String electronicSignature = fp.getString("electronicSignature" + order);
String hideCRF = fp.getString("hideCRF" + order);
String participantForm = fp.getString("participantForm" + order);
String allowAnonymousSubmission = fp.getString("allowAnonymousSubmission" + order);
String submissionUrl = fp.getString("submissionUrl" + order);
String offline = fp.getString("offline" + order);
int sdvId = fp.getInt("sdvOption" + order);
ArrayList<String> selectedVersionIdList = fp.getStringArray("versionSelection" + order);
int selectedVersionIdListSize = selectedVersionIdList.size();
String selectedVersionIds = "";
if (selectedVersionIdListSize > 0) {
for (String id : selectedVersionIdList) {
selectedVersionIds += id + ",";
}
selectedVersionIds = selectedVersionIds.substring(0, selectedVersionIds.length() - 1);
}
String sdvOption = fp.getString("sdvOption" + order);
boolean changed = false;
if (changeStatus != null && changeStatus.get(sed.getId() + "-" + edcBean.getId()) != null) {
changed = changeStatus.get(sed.getId() + "-" + edcBean.getId());
edcBean.setSubmissionUrl(submissionUrl);
}
boolean isRequired = !StringUtil.isBlank(requiredCRF) && "yes".equalsIgnoreCase(requiredCRF.trim()) ? true : false;
boolean isDouble = !StringUtil.isBlank(doubleEntry) && "yes".equalsIgnoreCase(doubleEntry.trim()) ? true : false;
boolean hasPassword = !StringUtil.isBlank(electronicSignature) && "yes".equalsIgnoreCase(electronicSignature.trim()) ? true : false;
boolean isHide = !StringUtil.isBlank(hideCRF) && "yes".equalsIgnoreCase(hideCRF.trim()) ? true : false;
System.out.println("crf name :" + edcBean.getCrfName());
System.out.println("submissionUrl: " + submissionUrl);
if (edcBean.getParentId() > 0) {
int dbDefaultVersionId = edcBean.getDefaultVersionId();
if (defaultVersionId != dbDefaultVersionId) {
changed = true;
FormLayoutBean defaultVersion = (FormLayoutBean) fldao.findByPK(defaultVersionId);
edcBean.setDefaultVersionId(defaultVersionId);
edcBean.setDefaultVersionName(defaultVersion.getName());
}
if (isRequired != edcBean.isRequiredCRF()) {
changed = true;
edcBean.setRequiredCRF(isRequired);
}
if (isDouble != edcBean.isDoubleEntry()) {
changed = true;
edcBean.setDoubleEntry(isDouble);
}
if (hasPassword != edcBean.isElectronicSignature()) {
changed = true;
edcBean.setElectronicSignature(hasPassword);
}
if (isHide != edcBean.isHideCrf()) {
changed = true;
edcBean.setHideCrf(isHide);
}
if (!submissionUrl.equals(edcBean.getSubmissionUrl())) {
changed = true;
edcBean.setSubmissionUrl(submissionUrl);
}
if (!StringUtil.isBlank(selectedVersionIds) && !selectedVersionIds.equals(edcBean.getSelectedVersionIds())) {
changed = true;
String[] ids = selectedVersionIds.split(",");
ArrayList<Integer> idList = new ArrayList<Integer>();
for (String id : ids) {
idList.add(Integer.valueOf(id));
}
edcBean.setSelectedVersionIdList(idList);
edcBean.setSelectedVersionIds(selectedVersionIds);
}
if (sdvId > 0 && sdvId != edcBean.getSourceDataVerification().getCode()) {
changed = true;
edcBean.setSourceDataVerification(SourceDataVerification.getByCode(sdvId));
}
if (changed) {
edcBean.setUpdater(ub);
edcBean.setUpdatedDate(new Date());
logger.debug("update for site");
toBeUpdatedEventDefBean.add(edcBean);
// edcdao.update(edcBean);
}
} else {
// only if definition-crf has been modified, will it be
// saved for the site
int defaultId = defaultVersionId > 0 ? defaultVersionId : edcBean.getDefaultVersionId();
int dbDefaultVersionId = edcBean.getDefaultVersionId();
if (defaultId == dbDefaultVersionId) {
if (isRequired == edcBean.isRequiredCRF()) {
if (isDouble == edcBean.isDoubleEntry()) {
if (hasPassword == edcBean.isElectronicSignature()) {
if (isHide == edcBean.isHideCrf()) {
if (submissionUrl.equals("")) {
if (selectedVersionIdListSize > 0) {
if (selectedVersionIdListSize == edcBean.getVersions().size()) {
if (sdvId > 0) {
if (sdvId != edcBean.getSourceDataVerification().getCode()) {
changed = true;
}
}
} else {
changed = true;
}
}
} else {
changed = true;
}
} else {
changed = true;
}
} else {
changed = true;
}
} else {
changed = true;
}
} else {
changed = true;
}
} else {
changed = true;
}
if (changed) {
CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(defaultId);
edcBean.setDefaultVersionId(defaultId);
edcBean.setDefaultVersionName(defaultVersion.getName());
edcBean.setRequiredCRF(isRequired);
edcBean.setDoubleEntry(isDouble);
edcBean.setElectronicSignature(hasPassword);
edcBean.setHideCrf(isHide);
edcBean.setSubmissionUrl(submissionUrl);
if (selectedVersionIdListSize > 0 && selectedVersionIdListSize != edcBean.getVersions().size()) {
String[] ids = selectedVersionIds.split(",");
ArrayList<Integer> idList = new ArrayList<Integer>();
for (String id : ids) {
idList.add(Integer.valueOf(id));
}
edcBean.setSelectedVersionIdList(idList);
edcBean.setSelectedVersionIds(selectedVersionIds);
}
if (sdvId > 0 && sdvId != edcBean.getSourceDataVerification().getCode()) {
edcBean.setSourceDataVerification(SourceDataVerification.getByCode(sdvId));
}
// edcBean.setParentId(edcBean.getId());
edcBean.setStudyId(site.getId());
edcBean.setUpdater(ub);
edcBean.setUpdatedDate(new Date());
logger.debug("create for the site");
toBeCreatedEventDefBean.add(edcBean);
// edcdao.create(edcBean);
}
}
++start;
changes.put(sed.getId() + "-" + edcBean.getId(), changed);
}
edcsInSession.add(edcBean);
}
sed.setPopulated(false);
eventDefCrfList = validateSubmissionUrl(edcsInSession, eventDefCrfList, v, sed);
edcsInSession.clear();
}
errors = v.validate();
if (!errors.isEmpty()) {
logger.info("has errors");
StudyBean study = createStudyBean();
session.setAttribute("newStudy", study);
request.setAttribute("formMessages", errors);
session.setAttribute("changed", changes);
forwardPage(Page.UPDATE_SUB_STUDY);
} else {
for (EventDefinitionCRFBean toBeCreated : toBeCreatedEventDefBean) {
toBeCreated.setParentId(toBeCreated.getId());
edcdao.create(toBeCreated);
}
for (EventDefinitionCRFBean toBeUpdated : toBeUpdatedEventDefBean) {
edcdao.update(toBeUpdated);
}
}
}
use of org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO in project OpenClinica by OpenClinica.
the class UpdateEventDefinitionServlet method submitDefinition.
/**
* Updates the definition
*
*/
private void submitDefinition() {
ArrayList edcs = (ArrayList) session.getAttribute("eventDefinitionCRFs");
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) session.getAttribute("definition");
StudyEventDefinitionDAO edao = new StudyEventDefinitionDAO(sm.getDataSource());
if (sed != null)
logger.info("Definition bean to be updated:" + sed.getName() + sed.getCategory());
sed.setUpdater(ub);
sed.setUpdatedDate(new Date());
sed.setStatus(Status.AVAILABLE);
edao.update(sed);
EventDefinitionCRFDAO cdao = new EventDefinitionCRFDAO(sm.getDataSource());
CRFDAO crfdao = new CRFDAO(sm.getDataSource());
for (int i = 0; i < edcs.size(); i++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) edcs.get(i);
if (edc.getId() > 0) {
// need to do update
edc.setUpdater(ub);
edc.setUpdatedDate(new Date());
logger.info("Status:" + edc.getStatus().getName());
logger.info("version:" + edc.getDefaultVersionId());
logger.info("Electronic Signature [" + edc.isElectronicSignature() + "]");
if (!sed.isRepeating()) {
edc.setAllowAnonymousSubmission(false);
edc.setSubmissionUrl("");
}
cdao.update(edc);
String crfPath = sed.getOid() + "." + edc.getCrf().getOid();
getEventDefinitionCrfTagService().saveEventDefnCrfOfflineTag(2, crfPath, edc, sed);
ArrayList<EventDefinitionCRFBean> eventDefCrfBeans = cdao.findAllByCrfDefinitionInSiteOnly(edc.getStudyEventDefinitionId(), edc.getCrfId());
for (EventDefinitionCRFBean eventDefCrfBean : eventDefCrfBeans) {
eventDefCrfBean.setParticipantForm(edc.isParticipantForm());
eventDefCrfBean.setAllowAnonymousSubmission(edc.isAllowAnonymousSubmission());
cdao.update(eventDefCrfBean);
}
if (edc.getStatus().equals(Status.DELETED) || edc.getStatus().equals(Status.AUTO_DELETED)) {
removeAllEventsItems(edc, sed);
}
if (edc.getOldStatus() != null && edc.getOldStatus().equals(Status.DELETED)) {
restoreAllEventsItems(edc, sed);
}
} else {
// to insert
edc.setOwner(ub);
edc.setCreatedDate(new Date());
edc.setStatus(Status.AVAILABLE);
if (!sed.isRepeating()) {
edc.setAllowAnonymousSubmission(false);
edc.setSubmissionUrl("");
}
cdao.create(edc);
CRFBean cBean = (CRFBean) crfdao.findByPK(edc.getCrfId());
String crfPath = sed.getOid() + "." + cBean.getOid();
getEventDefinitionCrfTagService().saveEventDefnCrfOfflineTag(2, crfPath, edc, sed);
}
}
session.removeAttribute("definition");
session.removeAttribute("eventDefinitionCRFs");
session.removeAttribute("tmpCRFIdMap");
session.removeAttribute("crfsWithVersion");
session.removeAttribute("eventDefinitionCRFs");
addPageMessage(respage.getString("the_ED_has_been_updated_succesfully"));
forwardPage(Page.LIST_DEFINITION_SERVLET);
}
use of org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO in project OpenClinica by OpenClinica.
the class TableOfContentsServlet method getDisplayBean.
public static DisplayTableOfContentsBean getDisplayBean(EventCRFBean ecb, DataSource ds, StudyBean currentStudy) {
DisplayTableOfContentsBean answer = new DisplayTableOfContentsBean();
answer.setEventCRF(ecb);
// get data
StudySubjectDAO ssdao = new StudySubjectDAO(ds);
StudySubjectBean ssb = (StudySubjectBean) ssdao.findByPK(ecb.getStudySubjectId());
answer.setStudySubject(ssb);
StudyEventDAO sedao = new StudyEventDAO(ds);
StudyEventBean seb = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
answer.setStudyEvent(seb);
SectionDAO sdao = new SectionDAO(ds);
ArrayList sections = getSections(ecb, ds);
answer.setSections(sections);
// get metadata
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(ds);
StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(seb.getStudyEventDefinitionId());
answer.setStudyEventDefinition(sedb);
CRFVersionDAO cvdao = new CRFVersionDAO(ds);
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(ecb.getCRFVersionId());
answer.setCrfVersion(cvb);
CRFDAO cdao = new CRFDAO(ds);
CRFBean cb = (CRFBean) cdao.findByPK(cvb.getCrfId());
answer.setCrf(cb);
StudyBean studyForStudySubject = new StudyDAO(ds).findByStudySubjectId(ssb.getId());
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(ds);
EventDefinitionCRFBean edcb = edcdao.findByStudyEventDefinitionIdAndCRFId(studyForStudySubject, sedb.getId(), cb.getId());
answer.setEventDefinitionCRF(edcb);
answer.setAction(getActionForStage(ecb.getStage()));
return answer;
}
use of org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO in project OpenClinica by OpenClinica.
the class ViewRuleAssignmentNewServlet method createStudyEventForInfoPanel.
private void createStudyEventForInfoPanel() {
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ItemDAO itemdao = new ItemDAO(sm.getDataSource());
StudyBean studyWithEventDefinitions = currentStudy;
if (currentStudy.getParentStudyId() > 0) {
studyWithEventDefinitions = new StudyBean();
studyWithEventDefinitions.setId(currentStudy.getParentStudyId());
}
CRFDAO crfdao = new CRFDAO(sm.getDataSource());
ArrayList seds = seddao.findAllActiveByStudy(studyWithEventDefinitions);
HashMap events = new LinkedHashMap();
for (int i = 0; i < seds.size(); i++) {
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seds.get(i);
ArrayList<CRFBean> crfs = (ArrayList<CRFBean>) crfdao.findAllActiveByDefinition(sed);
if (currentStudy.getParentStudyId() > 0) {
// sift through these CRFs and see which ones are hidden
HideCRFManager hideCRFs = HideCRFManager.createHideCRFManager();
crfs = hideCRFs.removeHiddenCRFBeans(studyWithEventDefinitions, sed, crfs, sm.getDataSource());
}
if (!crfs.isEmpty()) {
events.put(sed, crfs);
}
}
request.setAttribute("eventlist", events);
request.setAttribute("crfCount", crfdao.getCountofActiveCRFs());
request.setAttribute("itemCount", itemdao.getCountofActiveItems());
request.setAttribute("ruleSetCount", getRuleSetService().getRuleSetDao().count(currentStudy));
}
use of org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO in project OpenClinica by OpenClinica.
the class ViewDiscrepancyNoteServlet method setupStudyEventCRFAttributes.
private void setupStudyEventCRFAttributes(EventCRFBean eventCRFBean) {
StudyEventDAO sed = new StudyEventDAO(sm.getDataSource());
StudyEventBean studyEventBean = (StudyEventBean) sed.findByPK(eventCRFBean.getStudyEventId());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(studyEventBean.getStudyEventDefinitionId());
studyEventBean.setName(sedb.getName());
request.setAttribute("studyEvent", studyEventBean);
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFVersionBean cv = (CRFVersionBean) cvdao.findByPK(eventCRFBean.getCRFVersionId());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFBean crf = (CRFBean) cdao.findByPK(cv.getCrfId());
request.setAttribute("crf", crf);
}
Aggregations