use of org.akaza.openclinica.bean.managestudy.StudyGroupBean in project OpenClinica by OpenClinica.
the class StudyGroupDAO method findByStudySubject.
/*
* created for Extract Bean, we give the method a study subject bean and it
* returns for us a hash map of class ids pointing to study group beans, tbh
* July 2007
*/
public HashMap findByStudySubject(StudySubjectBean studySubject) {
HashMap classBeanMap = new HashMap();
HashMap variables = new HashMap();
variables.put(new Integer(1), new Integer(studySubject.getId()));
String sql = digester.getQuery("findByStudySubject");
ArrayList alist = this.select(sql, variables);
Iterator it = alist.iterator();
if (it.hasNext()) {
StudyGroupBean sgbean = (StudyGroupBean) this.getEntityFromHashMap((HashMap) it.next());
classBeanMap.put(new Integer(sgbean.getStudyGroupClassId()), sgbean);
}
return classBeanMap;
}
use of org.akaza.openclinica.bean.managestudy.StudyGroupBean in project OpenClinica by OpenClinica.
the class StudyGroupDAO method findSubjectGroupMaps.
public HashMap findSubjectGroupMaps(int studyId) {
logger.info("testing with variable: " + studyId);
HashMap subjectGroupMaps = new HashMap();
ArrayList groupMaps = new ArrayList();
HashMap subjectGroupMap = new HashMap();
HashMap variables = new HashMap();
this.setTypesExpected();
this.setTypeExpected(5, TypeNames.INT);
variables.put(new Integer(1), new Integer(studyId));
String sql = digester.getQuery("findSubjectGroupMaps");
// logger.info("*** "+sql);
ArrayList alist = this.select(sql, variables);
Iterator it = alist.iterator();
while (it.hasNext()) {
logger.info("iteration over answers...");
subjectGroupMap = new HashMap();
HashMap answers = (HashMap) it.next();
Integer studySubjectId = (Integer) answers.get("study_subject_id");
logger.info("iteration over answers..." + studySubjectId.intValue());
if (subjectGroupMaps.containsKey(studySubjectId)) {
groupMaps = (ArrayList) subjectGroupMaps.get(studySubjectId);
// subjectGroupMap =
// (HashMap)subjectGroupMaps.get(studySubjectId);
} else {
groupMaps = new ArrayList();
}
StudyGroupBean sgbean = (StudyGroupBean) this.getEntityFromHashMap(answers);
subjectGroupMap.put(new Integer(sgbean.getStudyGroupClassId()), sgbean);
groupMaps.add(subjectGroupMap);
logger.info("subjectgroupmaps: just put in " + sgbean.getStudyGroupClassId());
subjectGroupMaps.put(studySubjectId, groupMaps);
}
return subjectGroupMaps;
}
use of org.akaza.openclinica.bean.managestudy.StudyGroupBean in project OpenClinica by OpenClinica.
the class CreateSubjectGroupClassServlet method submitGroup.
/**
* Saves study group information into database
*
* @throws OpenClinicaException
*/
private void submitGroup() throws OpenClinicaException, IOException {
StudyGroupClassBean group = (StudyGroupClassBean) session.getAttribute("group");
ArrayList studyGroups = (ArrayList) session.getAttribute("studyGroups");
StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
group.setStudyId(currentStudy.getId());
group.setOwner(ub);
group.setStatus(Status.AVAILABLE);
group = (StudyGroupClassBean) sgcdao.create(group);
if (!group.isActive()) {
addPageMessage(respage.getString("the_subject_group_class_not_created_database"));
} else {
StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
for (int i = 0; i < studyGroups.size(); i++) {
StudyGroupBean sg = (StudyGroupBean) studyGroups.get(i);
sg.setStudyGroupClassId(group.getId());
sg.setOwner(ub);
sg.setStatus(Status.AVAILABLE);
sgdao.create(sg);
}
addPageMessage(respage.getString("the_subject_group_class_created_succesfully"));
}
ArrayList pageMessages = (ArrayList) request.getAttribute(PAGE_MESSAGE);
session.setAttribute("pageMessages", pageMessages);
response.sendRedirect(request.getContextPath() + Page.MANAGE_STUDY_MODULE.getFileName());
}
use of org.akaza.openclinica.bean.managestudy.StudyGroupBean in project OpenClinica by OpenClinica.
the class UpdateSubjectGroupClassServlet method submitGroup.
private void submitGroup() throws OpenClinicaException {
StudyGroupClassBean group = (StudyGroupClassBean) session.getAttribute("group");
ArrayList studyGroups = (ArrayList) session.getAttribute("studyGroups");
ArrayList newStudyGroups = (ArrayList) session.getAttribute("newStudyGroups");
StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
group.setUpdater(ub);
group.setUpdatedDate(new Date());
group = (StudyGroupClassBean) sgcdao.update(group);
if (!group.isActive()) {
addPageMessage(respage.getString("the_subject_group_class_no_updated_database"));
} else {
StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
for (int i = 0; i < studyGroups.size(); i++) {
StudyGroupBean sg = (StudyGroupBean) studyGroups.get(i);
sg.setStudyGroupClassId(group.getId());
if (sg.getId() == 0) {
sg.setOwner(ub);
sg.setStatus(Status.AVAILABLE);
sgdao.create(sg);
} else {
sg.setUpdater(ub);
sg.setStatus(Status.AVAILABLE);
sgdao.update(sg);
}
}
addPageMessage(respage.getString("the_subject_group_class_updated_succesfully"));
}
forwardPage(Page.SUBJECT_GROUP_CLASS_LIST_SERVLET);
}
use of org.akaza.openclinica.bean.managestudy.StudyGroupBean in project OpenClinica by OpenClinica.
the class UpdateStudySubjectServlet method confirm.
/**
* Processes 'confirm' request, validate the study subject object
*
* @param sub
* @throws Exception
*/
private void confirm(StudyGroupDAO sgdao) throws Exception {
ArrayList classes = (ArrayList) session.getAttribute("groups");
StudySubjectBean sub = (StudySubjectBean) session.getAttribute("studySub");
FormDiscrepancyNotes discNotes = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
DiscrepancyValidator v = new DiscrepancyValidator(request, discNotes);
FormProcessor fp = new FormProcessor(request);
java.util.Date enrollDate = sub.getEnrollmentDate();
if (ub.isSysAdmin() || currentRole.isManageStudy() || currentRole.isInvestigator() || currentStudy.getParentStudyId() > 0 && currentRole.isResearchAssistant() || currentStudy.getParentStudyId() > 0 && currentRole.isResearchAssistant2()) {
// currentRole.getRoleName().equals(Role.STUDYDIRECTOR) || currentRole.getRoleName().equals(Role.COORDINATOR)) {
v.addValidation("label", Validator.NO_BLANKS);
v.addValidation("label", Validator.DOES_NOT_CONTAIN_HTML_LESSTHAN_GREATERTHAN_ELEMENTS);
v.addValidation("secondaryLabel", Validator.DOES_NOT_CONTAIN_HTML_LESSTHAN_GREATERTHAN_ELEMENTS);
String eDateString = fp.getString("enrollmentDate");
if (!StringUtil.isBlank(eDateString)) {
v.addValidation("enrollmentDate", Validator.IS_A_DATE);
v.alwaysExecuteLastValidation("enrollmentDate");
}
errors = v.validate();
if (!StringUtil.isBlank(fp.getString("label"))) {
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean sub1 = (StudySubjectBean) ssdao.findAnotherBySameLabel(fp.getString("label").trim(), currentStudy.getId(), sub.getId());
// JRWS>> Also look for labels in the child studies
if (sub1.getId() == 0) {
sub1 = (StudySubjectBean) ssdao.findAnotherBySameLabelInSites(fp.getString("label").trim(), currentStudy.getId(), sub.getId());
}
if (sub1.getId() > 0) {
Validator.addError(errors, "label", resexception.getString("subject_ID_used_by_another_choose_unique"));
}
}
sub.setLabel(fp.getString("label"));
sub.setSecondaryLabel(fp.getString("secondaryLabel"));
try {
local_df.setLenient(false);
if (!StringUtil.isBlank(eDateString)) {
enrollDate = local_df.parse(eDateString);
} else {
enrollDate = null;
}
} catch (ParseException fe) {
logger.warn("Enrollment Date cannot be parsed.");
}
sub.setEnrollmentDate(enrollDate);
}
// below added tbh 092007, fix for YY vs YYYY formatting
String enrollDateStr = enrollDate != null ? local_df.format(enrollDate) : "";
session.setAttribute("enrollDateStr", enrollDateStr);
// above added tbh 092007
session.setAttribute("studySub", sub);
if (!classes.isEmpty()) {
for (int i = 0; i < classes.size(); i++) {
StudyGroupClassBean sgc = (StudyGroupClassBean) classes.get(i);
int groupId = fp.getInt("studyGroupId" + i);
String notes = fp.getString("notes" + i);
v.addValidation("notes" + i, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
sgc.setStudyGroupId(groupId);
sgc.setGroupNotes(notes);
if (groupId > 0) {
StudyGroupBean sgb = (StudyGroupBean) sgdao.findByPK(groupId);
sgc.setStudyGroupName(sgb.getName());
}
}
}
session.setAttribute("groups", classes);
if (!errors.isEmpty()) {
logger.info("has errors");
if (StringUtil.isBlank(sub.getLabel())) {
addPageMessage(respage.getString("must_enter_subject_ID_for_identifying") + respage.getString("this_may_be_external_ID_number") + respage.getString("you_may_enter_study_subject_ID_listed") + respage.getString("study_subject_ID_should_not_contain_protected_information"));
} else {
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean sub1 = (StudySubjectBean) subdao.findAnotherBySameLabel(sub.getLabel(), sub.getStudyId(), sub.getId());
if (sub1.getId() > 0) {
addPageMessage(resexception.getString("subject_ID_used_by_another_choose_unique"));
}
}
request.setAttribute("formMessages", errors);
forwardPage(Page.UPDATE_STUDY_SUBJECT);
} else {
forwardPage(Page.UPDATE_STUDY_SUBJECT_CONFIRM);
}
}
Aggregations