use of org.akaza.openclinica.bean.managestudy.StudyBean in project OpenClinica by OpenClinica.
the class UpdateStudyServletNew method processRequest.
@Override
public void processRequest() throws Exception {
resetPanel();
FormProcessor fp = new FormProcessor(request);
Validator v = new Validator(request);
int studyId = fp.getInt("id");
studyId = studyId == 0 ? fp.getInt("studyId") : studyId;
String action = fp.getString("action");
StudyDAO sdao = new StudyDAO(sm.getDataSource());
boolean isInterventional = false;
study = (StudyBean) sdao.findByPK(studyId);
if (study.getId() != currentStudy.getId()) {
addPageMessage(respage.getString("not_current_study") + respage.getString("change_study_contact_sysadmin"));
forwardPage(Page.MENU_SERVLET);
return;
}
study.setId(studyId);
StudyConfigService scs = new StudyConfigService(sm.getDataSource());
study = scs.setParametersForStudy(study);
request.setAttribute("studyToView", study);
request.setAttribute("studyId", studyId + "");
request.setAttribute("studyPhaseMap", CreateStudyServlet.studyPhaseMap);
ArrayList statuses = Status.toStudyUpdateMembersList();
statuses.add(Status.PENDING);
request.setAttribute("statuses", statuses);
String interventional = resadmin.getString("interventional");
isInterventional = interventional.equalsIgnoreCase(study.getProtocolType());
request.setAttribute("isInterventional", isInterventional ? "1" : "0");
String protocolType = study.getProtocolTypeKey();
// A. Hamid. 5001
if (study.getParentStudyId() > 0) {
StudyBean parentStudy = (StudyBean) sdao.findByPK(study.getParentStudyId());
request.setAttribute("parentStudy", parentStudy);
}
ArrayList interventionArray = new ArrayList();
if (isInterventional) {
interventionArray = parseInterventions(study);
setMaps(isInterventional, interventionArray);
} else {
setMaps(isInterventional, interventionArray);
}
if (!action.equals("submit")) {
// First Load First Form
if (study.getDatePlannedStart() != null) {
fp.addPresetValue(INPUT_START_DATE, local_df.format(study.getDatePlannedStart()));
}
if (study.getDatePlannedEnd() != null) {
fp.addPresetValue(INPUT_END_DATE, local_df.format(study.getDatePlannedEnd()));
}
if (study.getProtocolDateVerification() != null) {
fp.addPresetValue(INPUT_VER_DATE, local_df.format(study.getProtocolDateVerification()));
}
setPresetValues(fp.getPresetValues());
// first load 2nd form
}
if (study == null) {
addPageMessage(respage.getString("please_choose_a_study_to_edit"));
forwardPage(Page.STUDY_LIST_SERVLET);
return;
}
if (action.equals("submit")) {
validateStudy1(fp, v);
validateStudy2(fp, new Validator(request));
validateStudy3(isInterventional, new Validator(request), fp);
validateStudy4(fp, new Validator(request));
validateStudy5(fp, new Validator(request));
validateStudy6(fp, new Validator(request));
confirmWholeStudy(fp);
request.setAttribute("studyToView", study);
if (!errors.isEmpty()) {
logger.error("found errors : " + errors.toString());
request.setAttribute("formMessages", errors);
forwardPage(Page.UPDATE_STUDY_NEW);
} else {
study.setProtocolType(protocolType);
submitStudy(study);
addPageMessage(respage.getString("the_study_has_been_updated_succesfully"));
ArrayList pageMessages = (ArrayList) request.getAttribute(PAGE_MESSAGE);
session.setAttribute("pageMessages", pageMessages);
response.sendRedirect(request.getContextPath() + "/pages/studymodule");
// forwardPage(Page.MANAGE_STUDY_MODULE);
}
} else {
forwardPage(Page.UPDATE_STUDY_NEW);
}
}
use of org.akaza.openclinica.bean.managestudy.StudyBean in project OpenClinica by OpenClinica.
the class UpdateStudyServlet method confirmStudy4.
/**
* Validates the forth section of study and save it into study bean
*
* @param request
* @param response
* @throws Exception
*/
private void confirmStudy4() throws Exception {
FormProcessor fp = new FormProcessor(request);
Validator v = new Validator(request);
v.addValidation("conditions", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 500);
v.addValidation("keywords", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
v.addValidation("eligibility", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 500);
errors = v.validate();
if (fp.getInt("expectedTotalEnrollment") <= 0) {
Validator.addError(errors, "expectedTotalEnrollment", respage.getString("expected_total_enrollment_must_be_a_positive_number"));
}
StudyBean newStudy = (StudyBean) session.getAttribute("newStudy");
newStudy.setConditions(fp.getString("conditions"));
newStudy.setKeywords(fp.getString("keywords"));
newStudy.setEligibility(fp.getString("eligibility"));
newStudy.setGender(fp.getString("gender"));
newStudy.setAgeMax(fp.getString("ageMax"));
newStudy.setAgeMin(fp.getString("ageMin"));
newStudy.setHealthyVolunteerAccepted(fp.getBoolean("healthyVolunteerAccepted"));
newStudy.setExpectedTotalEnrollment(fp.getInt("expectedTotalEnrollment"));
session.setAttribute("newStudy", newStudy);
request.setAttribute("facRecruitStatusMap", CreateStudyServlet.facRecruitStatusMap);
if (errors.isEmpty()) {
forwardPage(Page.UPDATE_STUDY6);
} else {
request.setAttribute("formMessages", errors);
forwardPage(Page.UPDATE_STUDY5);
}
}
use of org.akaza.openclinica.bean.managestudy.StudyBean in project OpenClinica by OpenClinica.
the class UpdateStudyServlet method updateStudy2.
/**
* Updates the study bean with inputs from second section
*
* @param request
* @return true if study type is Interventional, otherwise false
*/
private boolean updateStudy2() {
FormProcessor fp = new FormProcessor(request);
StudyBean newStudy = (StudyBean) session.getAttribute("newStudy");
// this is not fully supported yet, because the system will not handle
// studies which are pending
// or private...
newStudy.setStatus(Status.get(fp.getInt("statusId")));
newStudy.setProtocolDateVerification(fp.getDate(INPUT_VER_DATE));
newStudy.setDatePlannedStart(fp.getDate(INPUT_START_DATE));
if (StringUtil.isBlank(fp.getString(INPUT_END_DATE))) {
newStudy.setDatePlannedEnd(null);
} else {
newStudy.setDatePlannedEnd(fp.getDate(INPUT_END_DATE));
}
newStudy.setPhase(fp.getString("phase"));
if (fp.getInt("genetic") == 1) {
newStudy.setGenetic(true);
} else {
newStudy.setGenetic(false);
}
session.setAttribute("newStudy", newStudy);
String interventional = resadmin.getString("interventional");
return interventional.equalsIgnoreCase(newStudy.getProtocolType());
}
use of org.akaza.openclinica.bean.managestudy.StudyBean in project OpenClinica by OpenClinica.
the class UserAccountDAO method findStudyByUser.
/**
* Finds all the studies with roles for a user
*
* @param userName
* @param allStudies
* The result of calling StudyDAO.findAll();
*/
public ArrayList findStudyByUser(String userName, ArrayList allStudies) {
this.unsetTypeExpected();
this.setTypeExpected(1, TypeNames.STRING);
this.setTypeExpected(2, TypeNames.INT);
this.setTypeExpected(3, TypeNames.STRING);
HashMap allStudyUserRoleBeans = new HashMap();
HashMap variables = new HashMap();
variables.put(new Integer(1), userName);
ArrayList alist = this.select(digester.getQuery("findStudyByUser"), variables);
Iterator it = alist.iterator();
while (it.hasNext()) {
HashMap hm = (HashMap) it.next();
String roleName = (String) hm.get("role_name");
String studyName = (String) hm.get("name");
Integer studyId = (Integer) hm.get("study_id");
StudyUserRoleBean sur = new StudyUserRoleBean();
sur.setRoleName(roleName);
sur.setStudyId(studyId.intValue());
sur.setStudyName(studyName);
allStudyUserRoleBeans.put(studyId, sur);
}
// pseudocode:
// for each parent study P in the system
// if the user has a role in that study, add it to the answer
// otherwise, let parentAdded = false
//
// for each study, C, which is a child of P
// if the user has a role in C,
// if parentAdded = false
// add a StudyUserRole with study = P, role = invalid to the answer
// let parentAdded = true
// add the user's role in C to the answer
ArrayList answer = new ArrayList();
StudyDAO sdao = new StudyDAO(ds);
HashMap childrenByParentId = sdao.getChildrenByParentIds(allStudies);
for (int i = 0; i < allStudies.size(); i++) {
StudyBean parent = (StudyBean) allStudies.get(i);
if (parent == null || parent.getParentStudyId() > 0) {
continue;
}
boolean parentAdded = false;
Integer studyId = new Integer(parent.getId());
StudyUserRoleBean roleInStudy;
ArrayList subTreeRoles = new ArrayList();
if (allStudyUserRoleBeans.containsKey(studyId)) {
roleInStudy = (StudyUserRoleBean) allStudyUserRoleBeans.get(studyId);
subTreeRoles.add(roleInStudy);
parentAdded = true;
} else {
// we do this so that we can compute Role.max below
// without
// throwing a NullPointerException
roleInStudy = new StudyUserRoleBean();
}
ArrayList children = (ArrayList) childrenByParentId.get(studyId);
if (children == null) {
children = new ArrayList();
}
for (int j = 0; j < children.size(); j++) {
StudyBean child = (StudyBean) children.get(j);
Integer childId = new Integer(child.getId());
if (allStudyUserRoleBeans.containsKey(childId)) {
if (!parentAdded) {
roleInStudy.setStudyId(studyId.intValue());
roleInStudy.setRole(Role.INVALID);
roleInStudy.setStudyName(parent.getName());
subTreeRoles.add(roleInStudy);
parentAdded = true;
}
StudyUserRoleBean roleInChild = (StudyUserRoleBean) allStudyUserRoleBeans.get(childId);
Role max = Role.max(roleInChild.getRole(), roleInStudy.getRole());
roleInChild.setRole(max);
roleInChild.setParentStudyId(studyId.intValue());
subTreeRoles.add(roleInChild);
} else {
StudyUserRoleBean roleInChild = new StudyUserRoleBean();
roleInChild.setStudyId(child.getId());
roleInChild.setStudyName(child.getName());
roleInChild.setRole(roleInStudy.getRole());
roleInChild.setParentStudyId(studyId.intValue());
subTreeRoles.add(roleInChild);
}
}
if (parentAdded) {
answer.addAll(subTreeRoles);
}
}
return answer;
}
use of org.akaza.openclinica.bean.managestudy.StudyBean in project OpenClinica by OpenClinica.
the class StudyDAO method findAllByUserNotRemoved.
// YW 10-18-2007
public Collection findAllByUserNotRemoved(String username) {
this.unsetTypeExpected();
this.setTypesExpected();
HashMap variables = new HashMap();
variables.put(new Integer(1), username);
ArrayList alist = this.select(digester.getQuery("findAllByUserNotRemoved"), variables);
ArrayList al = new ArrayList();
Iterator it = alist.iterator();
while (it.hasNext()) {
StudyBean eb = (StudyBean) this.getEntityFromHashMap((HashMap) it.next());
al.add(eb);
}
return al;
}
Aggregations