use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class ListEventDefinitionServlet method processRequest.
/**
* Processes the request
*/
@Override
public void processRequest() throws Exception {
StudyEventDefinitionDAO edao = new StudyEventDefinitionDAO(sm.getDataSource());
UserAccountDAO sdao = new UserAccountDAO(sm.getDataSource());
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
CRFDAO crfDao = new CRFDAO(sm.getDataSource());
CRFVersionDAO crfVersionDao = new CRFVersionDAO(sm.getDataSource());
ArrayList seds = edao.findAllByStudy(currentStudy);
// request.setAttribute("seds", seds);
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
for (int i = 0; i < seds.size(); i++) {
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seds.get(i);
Collection eventDefinitionCRFlist = edcdao.findAllParentsByDefinition(sed.getId());
Map crfWithDefaultVersion = new LinkedHashMap();
for (Iterator it = eventDefinitionCRFlist.iterator(); it.hasNext(); ) {
EventDefinitionCRFBean edcBean = (EventDefinitionCRFBean) it.next();
CRFBean crfBean = (CRFBean) crfDao.findByPK(edcBean.getCrfId());
CRFVersionBean crfVersionBean = (CRFVersionBean) crfVersionDao.findByPK(edcBean.getDefaultVersionId());
logger.info("ED[" + sed.getName() + "]crf[" + crfBean.getName() + "]dv[" + crfVersionBean.getName() + "]");
crfWithDefaultVersion.put(crfBean.getName(), crfVersionBean.getName());
}
sed.setCrfsWithDefaultVersion(crfWithDefaultVersion);
logger.info("CRF size [" + sed.getCrfs().size() + "]");
if (sed.getUpdater().getId() == 0) {
sed.setUpdater(sed.getOwner());
sed.setUpdatedDate(sed.getCreatedDate());
}
if (isPopulated(sed, sedao)) {
sed.setPopulated(true);
}
}
FormProcessor fp = new FormProcessor(request);
EntityBeanTable table = fp.getEntityBeanTable();
ArrayList allStudyRows = StudyEventDefinitionRow.generateRowsFromBeans(seds);
String[] columns = { resword.getString("order"), resword.getString("name"), resword.getString("OID"), resword.getString("repeating"), resword.getString("type"), resword.getString("category"), resword.getString("populated"), resword.getString("date_created"), resword.getString("date_updated"), resword.getString("CRFs"), resword.getString("default_version"), resword.getString("actions") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
// >> tbh #4169 09/2009
table.hideColumnLink(2);
table.hideColumnLink(3);
table.hideColumnLink(4);
table.hideColumnLink(6);
table.hideColumnLink(7);
table.hideColumnLink(8);
table.hideColumnLink(9);
// crfs, tbh
table.hideColumnLink(10);
table.hideColumnLink(11);
table.hideColumnLink(12);
// << tbh 09/2009
table.setQuery("ListEventDefinition", new HashMap());
// if (!currentStudy.getStatus().isLocked()) {
// table.addLink(resworkflow.getString(
// "create_a_new_study_event_definition"), "DefineStudyEvent");
// }
table.setRows(allStudyRows);
table.setPaginated(false);
table.computeDisplay();
request.setAttribute("table", table);
request.setAttribute("defSize", new Integer(seds.size()));
if (request.getParameter("read") != null && request.getParameter("read").equals("true")) {
request.setAttribute("readOnly", true);
}
forwardPage(Page.STUDY_EVENT_DEFINITION_LIST);
}
use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class AddCRFToDefinitionServlet method addCRF.
private void addCRF() throws Exception {
FormProcessor fp = new FormProcessor(request);
CRFVersionDAO vdao = new CRFVersionDAO(sm.getDataSource());
ArrayList crfArray = new ArrayList();
Map tmpCRFIdMap = (HashMap) session.getAttribute("tmpCRFIdMap");
if (tmpCRFIdMap == null) {
tmpCRFIdMap = new HashMap();
}
ArrayList crfsWithVersion = (ArrayList) session.getAttribute("crfsWithVersion");
for (int i = 0; i < crfsWithVersion.size(); i++) {
int id = fp.getInt("id" + i);
String name = fp.getString("name" + i);
String selected = fp.getString("selected" + i);
if (!StringUtil.isBlank(selected) && "yes".equalsIgnoreCase(selected.trim())) {
logger.info("one crf selected");
CRFBean cb = new CRFBean();
cb.setId(id);
cb.setName(name);
// only find active verions
ArrayList versions = (ArrayList) vdao.findAllActiveByCRF(cb.getId());
cb.setVersions(versions);
crfArray.add(cb);
} else {
if (tmpCRFIdMap.containsKey(id)) {
tmpCRFIdMap.remove(id);
}
}
}
for (Iterator tmpCRFIterator = tmpCRFIdMap.keySet().iterator(); tmpCRFIterator.hasNext(); ) {
int id = (Integer) tmpCRFIterator.next();
String name = (String) tmpCRFIdMap.get(id);
boolean isExists = false;
for (Iterator it = crfArray.iterator(); it.hasNext(); ) {
CRFBean cb = (CRFBean) it.next();
if (id == cb.getId()) {
isExists = true;
}
}
if (!isExists) {
CRFBean cb = new CRFBean();
cb.setId(id);
cb.setName(name);
// only find active verions
ArrayList versions = (ArrayList) vdao.findAllActiveByCRF(cb.getId());
cb.setVersions(versions);
crfArray.add(cb);
}
}
session.removeAttribute("tmpCRFIdMap");
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
if (crfArray.size() == 0) {
// no crf seleted
addPageMessage(respage.getString("no_new_CRF_added"));
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) session.getAttribute("definition");
String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
request.setAttribute("participateFormStatus", participateFormStatus);
sed.setCrfs(new ArrayList());
session.setAttribute("definition", sed);
forwardPage(Page.UPDATE_EVENT_DEFINITION1);
} else {
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) session.getAttribute("definition");
String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
if (participateFormStatus.equals("enabled"))
baseUrl();
request.setAttribute("participateFormStatus", participateFormStatus);
ArrayList edcs = (ArrayList) session.getAttribute("eventDefinitionCRFs");
int ordinalForNewCRF = edcs.size();
for (int i = 0; i < crfArray.size(); i++) {
CRFBean crf = (CRFBean) crfArray.get(i);
EventDefinitionCRFBean edcBean = new EventDefinitionCRFBean();
edcBean.setCrfId(crf.getId());
edcBean.setCrfName(crf.getName());
edcBean.setStudyId(ub.getActiveStudyId());
edcBean.setStatus(Status.AVAILABLE);
edcBean.setStudyEventDefinitionId(sed.getId());
edcBean.setStudyId(ub.getActiveStudyId());
edcBean.setSourceDataVerification(SourceDataVerification.NOTREQUIRED);
ordinalForNewCRF = ordinalForNewCRF + 1;
edcBean.setOrdinal(ordinalForNewCRF);
edcBean.setVersions(crf.getVersions());
CRFVersionBean defaultVersion1 = (CRFVersionBean) vdao.findByPK(edcBean.getDefaultVersionId());
edcBean.setDefaultVersionName(defaultVersion1.getName());
ordinalForNewCRF++;
edcs.add(edcBean);
}
session.setAttribute("eventDefinitionCRFs", edcs);
ArrayList<String> sdvOptions = new ArrayList<String>();
sdvOptions.add(SourceDataVerification.AllREQUIRED.toString());
sdvOptions.add(SourceDataVerification.PARTIALREQUIRED.toString());
sdvOptions.add(SourceDataVerification.NOTREQUIRED.toString());
sdvOptions.add(SourceDataVerification.NOTAPPLICABLE.toString());
request.setAttribute("sdvOptions", sdvOptions);
addPageMessage(respage.getString("has_have_been_added_need_confirmation"));
forwardPage(Page.UPDATE_EVENT_DEFINITION1);
}
}
use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class DefineStudyEventServlet method confirmWholeDefinition.
/**
* Validates the entire definition
*
* @throws Exception
*/
private void confirmWholeDefinition() throws Exception {
Validator v = new Validator(request);
FormProcessor fp = new FormProcessor(request);
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) session.getAttribute("definition");
ArrayList eventDefinitionCRFs = new ArrayList();
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
for (int i = 0; i < sed.getCrfs().size(); i++) {
EventDefinitionCRFBean edcBean = new EventDefinitionCRFBean();
int crfId = fp.getInt("crfId" + i);
int defaultVersionId = fp.getInt("defaultVersionId" + i);
edcBean.setCrfId(crfId);
edcBean.setDefaultVersionId(defaultVersionId);
CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(edcBean.getDefaultVersionId());
edcBean.setDefaultVersionName(defaultVersion.getName());
String crfName = fp.getString("crfName" + i);
// String crfLabel = fp.getString("crfLabel" + i);
edcBean.setCrfName(crfName);
// edcBean.setCrfLabel(crfLabel);
String requiredCRF = fp.getString("requiredCRF" + i);
String doubleEntry = fp.getString("doubleEntry" + i);
String decisionCondition = fp.getString("decisionCondition" + i);
String electronicSignature = fp.getString("electronicSignature" + i);
String participantForm = fp.getString("participantForm" + i);
String allowAnonymousSubmission = fp.getString("allowAnonymousSubmission" + i);
String submissionUrl = fp.getString("submissionUrl" + i);
String offline = fp.getString("offline" + i);
// issue 312 BWP<<
String hiddenCrf = fp.getString("hiddenCrf" + i);
// hideCRF is false by default in the bean
if (!StringUtil.isBlank(hiddenCrf) && "yes".equalsIgnoreCase(hiddenCrf.trim())) {
edcBean.setHideCrf(true);
} else {
edcBean.setHideCrf(false);
}
// >>
String sdvOption = fp.getString("sdvOption" + i);
if (!StringUtils.isBlank(sdvOption)) {
int id = Integer.valueOf(sdvOption);
edcBean.setSourceDataVerification(SourceDataVerification.getByCode(id));
}
if (!StringUtils.isBlank(requiredCRF) && "yes".equalsIgnoreCase(requiredCRF.trim())) {
edcBean.setRequiredCRF(true);
} else {
edcBean.setRequiredCRF(false);
}
if (!StringUtils.isBlank(participantForm) && "yes".equalsIgnoreCase(participantForm.trim())) {
edcBean.setParticipantForm(true);
} else {
edcBean.setParticipantForm(false);
}
// when participant form is not selected, force allow anonymous to be not selected
if (edcBean.isParticipantForm() && !StringUtils.isBlank(allowAnonymousSubmission) && "yes".equalsIgnoreCase(allowAnonymousSubmission.trim())) {
edcBean.setAllowAnonymousSubmission(true);
} else {
edcBean.setAllowAnonymousSubmission(false);
}
if (!StringUtils.isBlank(offline) && "yes".equalsIgnoreCase(offline.trim())) {
edcBean.setOffline(true);
} else {
edcBean.setOffline(false);
}
if (!StringUtils.isBlank(doubleEntry) && "yes".equalsIgnoreCase(doubleEntry.trim())) {
edcBean.setDoubleEntry(true);
} else {
edcBean.setDoubleEntry(false);
}
if (!StringUtils.isBlank(decisionCondition) && "yes".equalsIgnoreCase(decisionCondition.trim())) {
edcBean.setDecisionCondition(true);
} else {
edcBean.setDecisionCondition(false);
}
if (!StringUtils.isBlank(electronicSignature) && "yes".equalsIgnoreCase(electronicSignature.trim())) {
edcBean.setElectronicSignature(true);
} else {
edcBean.setElectronicSignature(false);
}
// also useful to protect from naughty submission not coming from our html form
if (edcBean.isParticipantForm() && edcBean.isAllowAnonymousSubmission()) {
edcBean.setSubmissionUrl(submissionUrl.trim());
}
ArrayList<CRFVersionBean> versions = cvdao.findAllByCRFId(crfId);
edcBean.setVersions(versions);
String nullString = "";
// process null values
ArrayList nulls = NullValue.toArrayList();
for (int a = 0; a < nulls.size(); a++) {
NullValue n = (NullValue) nulls.get(a);
String myNull = fp.getString(n.getName().toLowerCase() + i);
if (!StringUtils.isBlank(myNull) && "yes".equalsIgnoreCase(myNull.trim())) {
nullString = nullString + n.getName().toUpperCase() + ",";
}
}
edcBean.setNullValues(nullString);
edcBean.setStudyId(ub.getActiveStudyId());
eventDefinitionCRFs.add(edcBean);
}
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
request.setAttribute("participateFormStatus", participateFormStatus);
if (participateFormStatus.equals("enabled"))
baseUrl();
request.setAttribute("participateFormStatus", participateFormStatus);
request.setAttribute("eventDefinitionCRFs", eventDefinitionCRFs);
// not used on page
session.setAttribute("edCRFs", eventDefinitionCRFs);
ArrayList<EventDefinitionCRFBean> edcsInSession = (ArrayList<EventDefinitionCRFBean>) session.getAttribute("edCRFs");
int parentStudyId = sed.getStudyId();
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
ArrayList<EventDefinitionCRFBean> eventDefCrfList = (ArrayList<EventDefinitionCRFBean>) edcdao.findAllActiveSitesAndStudiesPerParentStudy(parentStudyId);
if (eventDefCrfList.size() != 0)
validateSubmissionUrl(edcsInSession, eventDefCrfList, v);
errors = v.validate();
if (!errors.isEmpty()) {
ArrayList<String> sdvOptions = new ArrayList<String>();
sdvOptions.add(SourceDataVerification.AllREQUIRED.toString());
sdvOptions.add(SourceDataVerification.PARTIALREQUIRED.toString());
sdvOptions.add(SourceDataVerification.NOTREQUIRED.toString());
sdvOptions.add(SourceDataVerification.NOTAPPLICABLE.toString());
request.setAttribute("sdvOptions", sdvOptions);
logger.info("has errors");
session.setAttribute("eventDefinitionCRFs", eventDefinitionCRFs);
request.setAttribute("formMessages", errors);
forwardPage(Page.DEFINE_STUDY_EVENT4);
}
forwardPage(Page.DEFINE_STUDY_EVENT_CONFIRM);
}
use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class DefineStudyEventServlet method confirmDefinition2.
private void confirmDefinition2() throws Exception {
FormProcessor fp = new FormProcessor(request);
CRFVersionDAO vdao = new CRFVersionDAO(sm.getDataSource());
ArrayList crfArray = new ArrayList();
Map tmpCRFIdMap = (HashMap) session.getAttribute("tmpCRFIdMap");
// trying to avoid NPE not sure why we would get it there ((tmpCRFIdMap.containsKey(id))), tbh
if (tmpCRFIdMap == null) {
tmpCRFIdMap = new HashMap();
}
ArrayList crfsWithVersion = (ArrayList) session.getAttribute("crfsWithVersion");
for (int i = 0; i < crfsWithVersion.size(); i++) {
int id = fp.getInt("id" + i);
String name = fp.getString("name" + i);
// String label = fp.getString("label" + i);
String selected = fp.getString("selected" + i);
// logger.info("selected:" + selected);
if (!StringUtils.isBlank(selected) && "yes".equalsIgnoreCase(selected.trim())) {
logger.debug("one crf selected");
CRFBean cb = new CRFBean();
cb.setId(id);
cb.setName(name);
// only find active verions
ArrayList versions = (ArrayList) vdao.findAllActiveByCRF(cb.getId());
cb.setVersions(versions);
crfArray.add(cb);
} else {
if (tmpCRFIdMap.containsKey(id)) {
tmpCRFIdMap.remove(id);
}
}
}
for (Iterator tmpCRFIterator = tmpCRFIdMap.keySet().iterator(); tmpCRFIterator.hasNext(); ) {
int id = (Integer) tmpCRFIterator.next();
String name = (String) tmpCRFIdMap.get(id);
boolean isExists = false;
for (Iterator it = crfArray.iterator(); it.hasNext(); ) {
CRFBean cb = (CRFBean) it.next();
if (id == cb.getId()) {
isExists = true;
}
}
if (!isExists) {
CRFBean cb = new CRFBean();
cb.setId(id);
cb.setName(name);
// only find active verions
ArrayList versions = (ArrayList) vdao.findAllActiveByCRF(cb.getId());
cb.setVersions(versions);
crfArray.add(cb);
}
}
session.removeAttribute("tmpCRFIdMap");
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
if (crfArray.size() == 0) {
// no crf seleted
// addPageMessage("At least one CRF must be selected.");
// request.setAttribute("crfs", crfs);
addPageMessage(respage.getString("no_CRF_selected_for_definition_add_later"));
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) session.getAttribute("definition");
sed.setCrfs(new ArrayList());
String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
request.setAttribute("participateFormStatus", participateFormStatus);
session.setAttribute("definition", sed);
request.setAttribute("eventDefinitionCRFs", new ArrayList());
// not used on page
session.setAttribute("edCRFs", new ArrayList());
forwardPage(Page.DEFINE_STUDY_EVENT_CONFIRM);
// forwardPage(Page.DEFINE_STUDY_EVENT2);
} else {
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) session.getAttribute("definition");
// crfs selected by user
sed.setCrfs(crfArray);
session.setAttribute("eventDefinitionCRFs", new ArrayList());
session.setAttribute("definition", sed);
String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
if (participateFormStatus.equals("enabled"))
baseUrl();
request.setAttribute("participateFormStatus", participateFormStatus);
ArrayList<String> sdvOptions = new ArrayList<String>();
sdvOptions.add(SourceDataVerification.AllREQUIRED.toString());
sdvOptions.add(SourceDataVerification.PARTIALREQUIRED.toString());
sdvOptions.add(SourceDataVerification.NOTREQUIRED.toString());
sdvOptions.add(SourceDataVerification.NOTAPPLICABLE.toString());
request.setAttribute("sdvOptions", sdvOptions);
forwardPage(Page.DEFINE_STUDY_EVENT3);
}
}
use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class DefineStudyEventServlet method confirmDefinition1.
/**
* Validates the first section of definition inputs
*
* @throws Exception
*/
private void confirmDefinition1() throws Exception {
Validator v = new Validator(request);
FormProcessor fp = new FormProcessor(request);
v.addValidation("name", Validator.NO_BLANKS);
v.addValidation("name", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 2000);
v.addValidation("description", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 2000);
v.addValidation("category", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 2000);
errors = v.validate();
session.setAttribute("definition", createStudyEventDefinition());
if (errors.isEmpty()) {
logger.debug("no errors in the first section");
// logger.debug("actionName*******" + fp.getString("actionName"));
// debugger.debug("pageNum*******" + fp.getString("pageNum"));
CRFVersionDAO vdao = new CRFVersionDAO(sm.getDataSource());
ArrayList crfArray = new ArrayList();
/*
* The tmpCRFIdMap will hold all the selected CRFs in the session
* when the user is navigating through the list. This has been done
* so that when the user moves to the next page of CRF list, the
* selection made in the previous page doesn't get lost.
*/
Map tmpCRFIdMap = (HashMap) session.getAttribute("tmpCRFIdMap");
if (tmpCRFIdMap == null) {
tmpCRFIdMap = new HashMap();
}
ArrayList crfsWithVersion = (ArrayList) session.getAttribute("crfsWithVersion");
for (int i = 0; i < crfsWithVersion.size(); i++) {
int id = fp.getInt("id" + i);
String name = fp.getString("name" + i);
String selected = fp.getString("selected" + i);
if (!StringUtil.isBlank(selected) && "yes".equalsIgnoreCase(selected.trim())) {
tmpCRFIdMap.put(id, name);
} else {
// deselected.
if (tmpCRFIdMap.containsKey(id)) {
tmpCRFIdMap.remove(id);
}
}
}
session.setAttribute("tmpCRFIdMap", tmpCRFIdMap);
EntityBeanTable table = fp.getEntityBeanTable();
ArrayList allRows = CRFRow.generateRowsFromBeans(crfsWithVersion);
String[] columns = { resword.getString("CRF_name"), resword.getString("date_created"), resword.getString("owner"), resword.getString("date_updated"), resword.getString("last_updated_by"), resword.getString("selected") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.hideColumnLink(5);
StudyEventDefinitionBean def1 = (StudyEventDefinitionBean) session.getAttribute("definition");
HashMap args = new HashMap();
args.put("actionName", "next");
args.put("pageNum", "1");
args.put("name", URLEncoder.encode(def1.getName(), "UTF-8"));
args.put("repeating", new Boolean(def1.isRepeating()).toString());
args.put("category", def1.getCategory());
args.put("description", URLEncoder.encode(def1.getDescription(), "UTF-8"));
args.put("type", def1.getType());
table.setQuery("DefineStudyEvent", args, true);
table.setRows(allRows);
table.computeDisplay();
request.setAttribute("table", table);
forwardPage(Page.DEFINE_STUDY_EVENT2);
} else {
logger.debug("has validation errors in the first section");
request.setAttribute("formMessages", errors);
forwardPage(Page.DEFINE_STUDY_EVENT1);
}
}
Aggregations