use of org.akaza.openclinica.dao.submit.SubjectDAO in project OpenClinica by OpenClinica.
the class UpdateSubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
FormDiscrepancyNotes discNotes = new FormDiscrepancyNotes();
String fromResolvingNotes = fp.getString("fromResolvingNotes", true);
if (StringUtils.isBlank(fromResolvingNotes)) {
session.removeAttribute(ViewNotesServlet.WIN_LOCATION);
session.removeAttribute(ViewNotesServlet.NOTES_TABLE);
checkStudyLocked(Page.LIST_SUBJECT_SERVLET, respage.getString("current_study_locked"));
checkStudyFrozen(Page.LIST_SUBJECT_SERVLET, respage.getString("current_study_frozen"));
}
int subjectId = fp.getInt("id", true);
int studySubId = fp.getInt("studySubId", true);
if (subjectId == 0) {
addPageMessage(respage.getString("please_choose_subject_to_edit"));
forwardPage(Page.LIST_SUBJECT_SERVLET);
} else {
String action = fp.getString("action", true);
if (StringUtils.isBlank("action")) {
addPageMessage(respage.getString("no_action_specified"));
forwardPage(Page.LIST_SUBJECT_SERVLET);
return;
}
SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId);
if (action.equals("show") || action.equals("confirm")) {
request.setAttribute("studySubId", new Integer(studySubId));
request.setAttribute("id", new Integer(subjectId));
request.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes);
}
if ("show".equalsIgnoreCase(action)) {
// no DOB collected
request.setAttribute("localBirthDate", "");
if (!currentStudy.getStudyParameterConfig().getCollectDob().equals("3") && subject.getDateOfBirth() != null) {
setLocalDOB(subject);
}
discNotes = new FormDiscrepancyNotes();
request.setAttribute("genderDNFlag", "icon_noNote");
request.setAttribute("birthDNFlag", "icon_noNote");
request.setAttribute("subjectToUpdate", subject);
setDNFlag(subjectId);
forwardPage(Page.UPDATE_SUBJECT);
} else if ("confirm".equalsIgnoreCase(action)) {
confirm(subject, subjectId);
} else {
String gender = fp.getString("gender");
subject.setGender(gender.charAt(0));
if (currentStudy.getStudyParameterConfig().getSubjectPersonIdRequired().equals("required") || currentStudy.getStudyParameterConfig().getSubjectPersonIdRequired().equals("optional")) {
subject.setUniqueIdentifier(fp.getString("uniqueIdentifier"));
}
subject.setUpdater(ub);
if (!currentStudy.getStudyParameterConfig().getCollectDob().equals("3")) {
if (currentStudy.getStudyParameterConfig().getCollectDob().equals("2")) {
String d_date = fp.getString(DATE_DOB_TO_SAVE);
if (!(d_date == null || d_date.trim().length() == 0)) {
Date date_new = yformat.parse(fp.getString(DATE_DOB_TO_SAVE));
subject.setDateOfBirth(date_new);
}
}
if (currentStudy.getStudyParameterConfig().getCollectDob().equals("1")) {
Date date_new = local_df.parse(fp.getString(DATE_DOB_TO_SAVE));
subject.setDateOfBirth(date_new);
}
}
sdao.update(subject);
// save discrepancy notes into DB
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
FormDiscrepancyNotes fdn = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
AddNewSubjectServlet.saveFieldNotes("gender", fdn, dndao, subject.getId(), "subject", currentStudy);
AddNewSubjectServlet.saveFieldNotes(DATE_DOB, fdn, dndao, subject.getId(), "subject", currentStudy);
addPageMessage(respage.getString("subject_updated_succcesfully"));
if (studySubId > 0) {
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
} else {
forwardPage(Page.LIST_SUBJECT_SERVLET);
}
}
}
}
use of org.akaza.openclinica.dao.submit.SubjectDAO in project OpenClinica by OpenClinica.
the class ListSubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
StudyDAO studyDao = new StudyDAO(sm.getDataSource());
UserAccountDAO uadao = new UserAccountDAO(sm.getDataSource());
ListSubjectTableFactory factory = new ListSubjectTableFactory();
factory.setSubjectDao(sdao);
factory.setStudySubjectDao(subdao);
factory.setUserAccountDao(uadao);
factory.setStudyDao(studyDao);
factory.setCurrentStudy(currentStudy);
String auditLogsHtml = factory.createTable(request, response).render();
request.setAttribute("listSubjectsHtml", auditLogsHtml);
forwardPage(Page.SUBJECT_LIST);
}
use of org.akaza.openclinica.dao.submit.SubjectDAO in project OpenClinica by OpenClinica.
the class RemoveSubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
int subjectId = fp.getInt("id");
String action = fp.getString("action");
if (subjectId == 0 || StringUtil.isBlank(action)) {
addPageMessage(respage.getString("please_choose_a_subject_to_remove"));
forwardPage(Page.SUBJECT_LIST_SERVLET);
} else {
SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId);
// find all study subjects
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ArrayList studySubs = ssdao.findAllBySubjectId(subjectId);
// find study events
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
ArrayList events = sedao.findAllBySubjectId(subjectId);
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute("subjectToRemove", subject);
request.setAttribute("studySubs", studySubs);
request.setAttribute("events", events);
forwardPage(Page.REMOVE_SUBJECT);
} else {
logger.info("submit to remove the subject");
// change all statuses to deleted
subject.setStatus(Status.DELETED);
subject.setUpdater(ub);
subject.setUpdatedDate(new Date());
sdao.update(subject);
// remove subject references from study
for (int i = 0; i < studySubs.size(); i++) {
StudySubjectBean studySub = (StudySubjectBean) studySubs.get(i);
if (!studySub.getStatus().equals(Status.DELETED)) {
studySub.setStatus(Status.AUTO_DELETED);
studySub.setUpdater(ub);
studySub.setUpdatedDate(new Date());
ssdao.update(studySub);
}
}
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
for (int j = 0; j < events.size(); j++) {
StudyEventBean event = (StudyEventBean) events.get(j);
if (!event.getStatus().equals(Status.DELETED)) {
event.setStatus(Status.AUTO_DELETED);
event.setUpdater(ub);
event.setUpdatedDate(new Date());
sedao.update(event);
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
for (int k = 0; k < eventCRFs.size(); k++) {
EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
if (!eventCRF.getStatus().equals(Status.DELETED)) {
eventCRF.setStatus(Status.AUTO_DELETED);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
// remove all the item data
ArrayList itemDatas = iddao.findAllByEventCRFId(eventCRF.getId());
for (int a = 0; a < itemDatas.size(); a++) {
ItemDataBean item = (ItemDataBean) itemDatas.get(a);
if (!item.getStatus().equals(Status.DELETED)) {
item.setStatus(Status.AUTO_DELETED);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
}
}
String emailBody = respage.getString("the_subject") + " " + subject.getUniqueIdentifier() + " " + respage.getString("has_been_removed_succesfully");
addPageMessage(emailBody);
// sendEmail(emailBody);
forwardPage(Page.SUBJECT_LIST_SERVLET);
}
}
}
use of org.akaza.openclinica.dao.submit.SubjectDAO in project OpenClinica by OpenClinica.
the class RandomizeService method getStudySubjectAttrValue.
private String getStudySubjectAttrValue(String expr, EventCRFBean eventCrfBean, RuleSetBean ruleSet) {
String value = "";
StudySubjectDAO<String, ArrayList> ssdao = new StudySubjectDAO<>(ds);
SubjectDAO subdao = new SubjectDAO(ds);
StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(ds);
StudyGroupDAO sgdao = new StudyGroupDAO(ds);
StudyDAO<String, ArrayList> sdao = new StudyDAO<>(ds);
StudySubjectBean ssBean = (StudySubjectBean) ssdao.findByPK(eventCrfBean.getStudySubjectId());
SubjectBean subjectBean = (SubjectBean) subdao.findByPK(ssBean.getSubjectId());
String prefix = "STUDYGROUPCLASSLIST";
String param = expr.split("\\.", -1)[1].trim();
if (param.equalsIgnoreCase("BIRTHDATE")) {
value = subjectBean.getDateOfBirth().toString();
} else if (param.equalsIgnoreCase("SEX")) {
if (String.valueOf(subjectBean.getGender()).equals("m"))
value = "Male";
else
value = "Female";
// value =String.valueOf(ssBean.getGender());
} else if (param.startsWith(prefix)) {
String gcName = param.substring(21, param.indexOf("\"]"));
StudyGroupBean sgBean = sgdao.findSubjectStudyGroup(ssBean.getId(), gcName);
if (sgBean != null)
value = sgBean.getName();
}
return value;
}
use of org.akaza.openclinica.dao.submit.SubjectDAO in project OpenClinica by OpenClinica.
the class SignStudySubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
String action = fp.getString("action");
// studySubjectId
int studySubId = fp.getInt("id", true);
String module = fp.getString(MODULE);
request.setAttribute(MODULE, module);
if (studySubId == 0) {
addPageMessage(respage.getString("please_choose_a_subject_to_view"));
forwardPage(Page.LIST_STUDY_SUBJECTS);
return;
}
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
if (!permitSign(studySub, sm.getDataSource())) {
addPageMessage(respage.getString("subject_event_cannot_signed"));
// forwardPage(Page.SUBMIT_DATA_SERVLET);
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
// >> changed tbh, 06/2009
return;
}
if (action.equalsIgnoreCase("confirm")) {
String username = request.getParameter("j_user");
String password = request.getParameter("j_pass");
SecurityManager securityManager = ((SecurityManager) SpringServletAccess.getApplicationContext(context).getBean("securityManager"));
// String encodedUserPass =
// org.akaza.openclinica.core.SecurityManager
// .getInstance().encrytPassword(password);
UserAccountBean ub = (UserAccountBean) session.getAttribute("userBean");
if (securityManager.verifyPassword(password, getUserDetails()) && ub.getName().equals(username)) {
if (signSubjectEvents(studySub, sm.getDataSource(), ub)) {
// Making the StudySubject signed as all the events have
// become signed.
studySub.setStatus(Status.SIGNED);
studySub.setUpdater(ub);
subdao.update(studySub);
addPageMessage(respage.getString("subject_event_signed"));
// forwardPage(Page.SUBMIT_DATA_SERVLET);
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
// >> changed tbh, 06/2009
return;
} else {
addPageMessage(respage.getString("errors_in_submission_see_below"));
forwardPage(Page.LIST_STUDY_SUBJECTS);
return;
}
} else {
request.setAttribute("id", new Integer(studySubId).toString());
addPageMessage(restext.getString("password_match"));
forwardPage(Page.LIST_STUDY_SUBJECTS);
return;
}
}
request.setAttribute("studySub", studySub);
int studyId = studySub.getStudyId();
int subjectId = studySub.getSubjectId();
SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId);
if (currentStudy.getStudyParameterConfig().getCollectDob().equals("2")) {
Date dob = subject.getDateOfBirth();
if (dob != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(dob);
int year = cal.get(Calendar.YEAR);
request.setAttribute("yearOfBirth", new Integer(year));
} else {
request.setAttribute("yearOfBirth", "");
}
}
request.setAttribute("subject", subject);
StudyDAO studydao = new StudyDAO(sm.getDataSource());
StudyBean study = (StudyBean) studydao.findByPK(studyId);
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
study.getStudyParameterConfig().setCollectDob(spvdao.findByHandleAndStudy(studyId, "collectDob").getValue());
if (study.getParentStudyId() > 0) {
// this is a site,find parent
StudyBean parentStudy = (StudyBean) studydao.findByPK(study.getParentStudyId());
request.setAttribute("parentStudy", parentStudy);
} else {
request.setAttribute("parentStudy", new StudyBean());
}
ArrayList children = (ArrayList) sdao.findAllChildrenByPK(subjectId);
request.setAttribute("children", children);
// find study events
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
// find all eventcrfs for each event
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ArrayList<DisplayStudyEventBean> displayEvents = getDisplayStudyEventsForStudySubject(study, studySub, sm.getDataSource(), ub, currentRole);
DiscrepancyNoteUtil discNoteUtil = new DiscrepancyNoteUtil();
// Don't filter for now; disc note beans are returned with eventCRFId
// set
discNoteUtil.injectParentDiscNotesIntoDisplayStudyEvents(displayEvents, new HashSet(), sm.getDataSource(), 0);
// All the displaystudyevents for one subject
request.setAttribute("displayStudyEvents", displayEvents);
// Set up a Map for the JSP view, mapping the eventCRFId to another Map:
// the
// inner Map maps the resolution status name to the number of notes for
// that
// eventCRF id, as in New --> 2
Map discNoteByEventCRFid = discNoteUtil.createDiscNoteMapByEventCRF(displayEvents);
request.setAttribute("discNoteByEventCRFid", discNoteByEventCRFid);
EntityBeanTable table = fp.getEntityBeanTable();
// sort by start date,
table.setSortingIfNotExplicitlySet(1, false);
// desc
ArrayList allEventRows = DisplayStudyEventRow.generateRowsFromBeans(displayEvents);
String[] columns = { resword.getString("event") + " (" + resword.getString("occurrence_number") + ")", resword.getString("start_date1"), resword.getString("location"), resword.getString("status"), resword.getString("actions"), resword.getString("CRFs_atrib") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.hideColumnLink(4);
table.hideColumnLink(5);
if (!"removed".equalsIgnoreCase(studySub.getStatus().getName()) && !"auto-removed".equalsIgnoreCase(studySub.getStatus().getName())) {
table.addLink(resword.getString("add_new_event"), "CreateNewStudyEvent?" + CreateNewStudyEventServlet.INPUT_STUDY_SUBJECT_ID_FROM_VIEWSUBJECT + "=" + studySub.getId());
}
HashMap args = new HashMap();
args.put("id", new Integer(studySubId).toString());
table.setQuery("ViewStudySubject", args);
table.setRows(allEventRows);
table.computeDisplay();
request.setAttribute("table", table);
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
ArrayList groupMaps = (ArrayList) sgmdao.findAllByStudySubject(studySubId);
request.setAttribute("groups", groupMaps);
AuditEventDAO aedao = new AuditEventDAO(sm.getDataSource());
ArrayList logs = aedao.findEventStatusLogByStudySubject(studySubId);
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
ArrayList eventLogs = new ArrayList();
for (int i = 0; i < logs.size(); i++) {
AuditEventBean avb = (AuditEventBean) logs.get(i);
StudyEventAuditBean sea = new StudyEventAuditBean();
sea.setAuditEvent(avb);
StudyEventBean se = (StudyEventBean) sedao.findByPK(avb.getEntityId());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
sea.setDefinition(sed);
String old = avb.getOldValue().trim();
try {
if (!StringUtil.isBlank(old)) {
SubjectEventStatus oldStatus = SubjectEventStatus.get(new Integer(old).intValue());
sea.setOldSubjectEventStatus(oldStatus);
}
String newValue = avb.getNewValue().trim();
if (!StringUtil.isBlank(newValue)) {
SubjectEventStatus newStatus = SubjectEventStatus.get(new Integer(newValue).intValue());
sea.setNewSubjectEventStatus(newStatus);
}
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
// logger.warning("^^^ caught NFE");
}
UserAccountBean updater = (UserAccountBean) udao.findByPK(avb.getUserId());
sea.setUpdater(updater);
eventLogs.add(sea);
}
// logger.warning("^^^ finished iteration");
request.setAttribute("eventLogs", eventLogs);
forwardPage(Page.SIGN_STUDY_SUBJECT);
}
Aggregations