use of org.akaza.openclinica.bean.submit.SubjectBean in project OpenClinica by OpenClinica.
the class AddNewSubjectServlet method processRequest.
// YW >>
/*
* (non-Javadoc)
*
* @see org.akaza.openclinica.control.core.SecureController#processRequest()
*/
@Override
protected void processRequest() throws Exception {
checkStudyLocked(Page.LIST_STUDY_SUBJECTS, respage.getString("current_study_locked"));
checkStudyFrozen(Page.LIST_STUDY_SUBJECTS, respage.getString("current_study_frozen"));
StudySubjectDAO ssd = new StudySubjectDAO(sm.getDataSource());
StudyDAO stdao = new StudyDAO(sm.getDataSource());
StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
ArrayList classes = new ArrayList();
panel.setStudyInfoShown(false);
FormProcessor fp = new FormProcessor(request);
FormDiscrepancyNotes discNotes;
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
// TODO l10n for dates? Note that in some places we hard-code the YOB by
// using "01/01/"+yob,
// not exactly supporting i18n...tbh
// YW << update study parameters of current study.
// "collectDob" and "genderRequired" are set as the same as the parent
// study
int parentStudyId = currentStudy.getParentStudyId();
if (parentStudyId <= 0) {
parentStudyId = currentStudy.getId();
classes = sgcdao.findAllActiveByStudy(currentStudy);
} else {
StudyBean parentStudy = (StudyBean) stdao.findByPK(parentStudyId);
classes = sgcdao.findAllActiveByStudy(parentStudy);
}
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
StudyParameterValueBean parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "collectDob");
currentStudy.getStudyParameterConfig().setCollectDob(parentSPV.getValue());
parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "genderRequired");
currentStudy.getStudyParameterConfig().setGenderRequired(parentSPV.getValue());
// YW >>
// tbh
StudyParameterValueBean checkPersonId = spvdao.findByHandleAndStudy(parentStudyId, "subjectPersonIdRequired");
currentStudy.getStudyParameterConfig().setSubjectPersonIdRequired(checkPersonId.getValue());
if (!fp.isSubmitted()) {
if (fp.getBoolean("instr")) {
session.removeAttribute(FORM_DISCREPANCY_NOTES_NAME);
forwardPage(Page.INSTRUCTIONS_ENROLL_SUBJECT);
} else {
setUpBeans(classes);
Date today = new Date(System.currentTimeMillis());
String todayFormatted = local_df.format(today);
fp.addPresetValue(INPUT_ENROLLMENT_DATE, todayFormatted);
// YW 10-07-2007 <<
String idSetting = "";
if (currentStudy.getParentStudyId() > 0) {
parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "subjectIdGeneration");
currentStudy.getStudyParameterConfig().setSubjectIdGeneration(parentSPV.getValue());
}
idSetting = currentStudy.getStudyParameterConfig().getSubjectIdGeneration();
// YW >>
logger.info("subject id setting :" + idSetting);
// available ID (label) for now
if (idSetting.equals("auto editable") || idSetting.equals("auto non-editable")) {
// Shaoyu Su
// int nextLabel = ssd.findTheGreatestLabel() + 1;
// fp.addPresetValue(INPUT_LABEL, new Integer(nextLabel).toString());
fp.addPresetValue(INPUT_LABEL, resword.getString("id_generated_Save_Add"));
}
setPresetValues(fp.getPresetValues());
discNotes = new FormDiscrepancyNotes();
session.setAttribute(FORM_DISCREPANCY_NOTES_NAME, discNotes);
forwardPage(Page.ADD_NEW_SUBJECT);
}
} else {
// values in database <subject> table for "add existing subject"
if (!fp.getBoolean(EXISTING_SUB_SHOWN)) {
DOB = fp.getString(INPUT_DOB);
YOB = fp.getString(INPUT_YOB);
GENDER = fp.getString(INPUT_GENDER);
}
// YW >>
discNotes = (FormDiscrepancyNotes) session.getAttribute(FORM_DISCREPANCY_NOTES_NAME);
if (discNotes == null) {
discNotes = new FormDiscrepancyNotes();
}
DiscrepancyValidator v = new DiscrepancyValidator(request, discNotes);
v.addValidation(INPUT_LABEL, Validator.NO_BLANKS);
String subIdSetting = currentStudy.getStudyParameterConfig().getSubjectIdGeneration();
if (!subIdSetting.equalsIgnoreCase("auto non-editable") && !subIdSetting.equalsIgnoreCase("auto editable")) {
v.addValidation(INPUT_LABEL, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 30);
}
if (currentStudy.getStudyParameterConfig().getSubjectPersonIdRequired().equals("required")) {
v.addValidation(INPUT_UNIQUE_IDENTIFIER, Validator.NO_BLANKS);
}
v.addValidation(INPUT_UNIQUE_IDENTIFIER, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
if (!StringUtils.isBlank(fp.getString(INPUT_SECONDARY_LABEL))) {
v.addValidation(INPUT_SECONDARY_LABEL, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 30);
}
String dobSetting = currentStudy.getStudyParameterConfig().getCollectDob();
if (dobSetting.equals("1")) {
// date of birth
v.addValidation(INPUT_DOB, Validator.IS_A_DATE);
if (!StringUtils.isBlank(fp.getString("INPUT_DOB"))) {
v.alwaysExecuteLastValidation(INPUT_DOB);
}
v.addValidation(INPUT_DOB, Validator.DATE_IN_PAST);
} else if (dobSetting.equals("2")) {
// year of birth
v.addValidation(INPUT_YOB, Validator.IS_AN_INTEGER);
v.alwaysExecuteLastValidation(INPUT_YOB);
v.addValidation(INPUT_YOB, Validator.COMPARES_TO_STATIC_VALUE, NumericComparisonOperator.GREATER_THAN_OR_EQUAL_TO, 1000);
// get today's year
Date today = new Date();
Calendar c = Calendar.getInstance();
c.setTime(today);
int currentYear = c.get(Calendar.YEAR);
v.addValidation(INPUT_YOB, Validator.COMPARES_TO_STATIC_VALUE, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, currentYear);
} else {
// DOB not used, added tbh 102007
logger.info("should read this only if DOB not used");
}
ArrayList acceptableGenders = new ArrayList();
acceptableGenders.add("m");
acceptableGenders.add("f");
if (!currentStudy.getStudyParameterConfig().getGenderRequired().equals("false")) {
v.addValidation(INPUT_GENDER, Validator.IS_IN_SET, acceptableGenders);
}
v.addValidation(INPUT_ENROLLMENT_DATE, Validator.IS_A_DATE);
v.alwaysExecuteLastValidation(INPUT_ENROLLMENT_DATE);
v.addValidation(INPUT_ENROLLMENT_DATE, Validator.DATE_IN_PAST);
boolean locationError = false;
if (fp.getBoolean("addWithEvent")) {
v.addValidation(INPUT_EVENT_START_DATE, Validator.IS_A_DATE);
v.alwaysExecuteLastValidation(INPUT_EVENT_START_DATE);
if (currentStudy.getStudyParameterConfig().getEventLocationRequired().equalsIgnoreCase("required")) {
v.addValidation("location", Validator.NO_BLANKS);
locationError = true;
}
}
HashMap errors = v.validate();
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
// global
String uniqueIdentifier = fp.getString(INPUT_UNIQUE_IDENTIFIER);
// Id
SubjectBean subjectWithSameId = new SubjectBean();
SubjectBean subjectWithSameIdInParent = new SubjectBean();
boolean showExistingRecord = false;
if (!uniqueIdentifier.equals("")) {
boolean subjectWithSameIdInCurrentStudyTree = false;
// checks whether there is a subject with same id inside current
// study/site
subjectWithSameId = sdao.findByUniqueIdentifierAndStudy(uniqueIdentifier, currentStudy.getId());
// tbh
if (subjectWithSameId.isActive()) {
// ||
// subjectWithSameIdInParent.isActive())
// {
Validator.addError(errors, INPUT_UNIQUE_IDENTIFIER, resexception.getString("subject_with_person_ID") + " " + uniqueIdentifier + " " + resexception.getString("is_already_enrolled_in_this_study"));
subjectWithSameIdInCurrentStudyTree = true;
logger.info("just added unique id in study tree");
} else {
// checks whether there is a subject with same id inside
// sites of
// current study
subjectWithSameId = sdao.findByUniqueIdentifierAndParentStudy(uniqueIdentifier, currentStudy.getId());
if (subjectWithSameId.isActive()) {
StudySubjectBean ssub = ssd.findBySubjectIdAndStudy(subjectWithSameId.getId(), currentStudy);
StudyBean site = (StudyBean) stdao.findByPK(ssub.getStudyId());
Validator.addError(errors, INPUT_UNIQUE_IDENTIFIER, resexception.getString("this_subject_person_ID") + " " + uniqueIdentifier + resexception.getString("has_already_enrolled_site") + site.getName() + resexception.getString("of_current_study_need_to_move") + resexception.getString("please_have_user_manage_privileges"));
subjectWithSameIdInCurrentStudyTree = true;
} else {
// check whether there is a subject with same id in the
// parent study
subjectWithSameId = sdao.findByUniqueIdentifierAndStudy(uniqueIdentifier, currentStudy.getParentStudyId());
if (subjectWithSameId.isActive()) {
Validator.addError(errors, INPUT_UNIQUE_IDENTIFIER, resexception.getString("this_subject_with_person_ID") + " " + uniqueIdentifier + resexception.getString("has_already_enrolled_parent_study"));
subjectWithSameIdInCurrentStudyTree = true;
} else {
// YW 11-26-2007 << check whether there is a subject
// with the same id in other sites of the same study
subjectWithSameId = sdao.findByUniqueIdentifierAndParentStudy(uniqueIdentifier, currentStudy.getParentStudyId());
if (subjectWithSameId.isActive()) {
Validator.addError(errors, INPUT_UNIQUE_IDENTIFIER, resexception.getString("this_subject_with_person_ID") + " " + uniqueIdentifier + resexception.getString("has_already_enrolled_site_study"));
subjectWithSameIdInCurrentStudyTree = true;
}
// YW >>
}
}
}
if (!subjectWithSameIdInCurrentStudyTree) {
subjectWithSameId = sdao.findByUniqueIdentifier(uniqueIdentifier);
// found subject with same id in other study
if (subjectWithSameId.isActive()) {
showExistingRecord = true;
}
}
}
// end of the block if(!uniqueIdentifier.equals(""))
String label = fp.getString(INPUT_LABEL);
String personId = fp.getString(INPUT_UNIQUE_IDENTIFIER);
String secondaryLable = fp.getString(INPUT_SECONDARY_LABEL);
// then Study Subject ID should be created when db row is inserted.
if (label.contains("<") || label.contains(">")) {
Validator.addError(errors, INPUT_LABEL, resexception.getString("study_subject_id_can_not_contain_html_lessthan_or_greaterthan_elements"));
}
if (secondaryLable.contains("<") || secondaryLable.contains(">")) {
Validator.addError(errors, INPUT_SECONDARY_LABEL, resexception.getString("secondary_id_can_not_contain_html_lessthan_or_greaterthan_elements"));
}
if (personId.contains("<") || personId.contains(">")) {
Validator.addError(errors, INPUT_UNIQUE_IDENTIFIER, resexception.getString("person_id_can_not_contain_html_lessthan_or_greaterthan_elements"));
}
if (!label.equalsIgnoreCase(resword.getString("id_generated_Save_Add"))) {
StudySubjectBean subjectWithSameLabel = ssd.findByLabelAndStudy(label, currentStudy);
StudySubjectBean subjectWithSameLabelInParent = new StudySubjectBean();
// tbh
if (currentStudy.getParentStudyId() > 0) {
// <
subjectWithSameLabelInParent = ssd.findSameByLabelAndStudy(label, currentStudy.getParentStudyId(), 0);
// --
// blank
// id
// since
// the
// ss
// hasn't
// been
// created
// yet,
// tbh
}
// tbh
if (subjectWithSameLabel.isActive() || subjectWithSameLabelInParent.isActive()) {
Validator.addError(errors, INPUT_LABEL, resexception.getString("another_assigned_this_ID_choose_unique"));
}
}
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);
if ("Required".equals(sgc.getSubjectAssignment()) && groupId == 0) {
Validator.addError(errors, "studyGroupId" + i, resexception.getString("group_class_is_required"));
}
if (notes.trim().length() > 255) {
Validator.addError(errors, "notes" + i, resexception.getString("notes_cannot_longer_255"));
}
sgc.setStudyGroupId(groupId);
sgc.setGroupNotes(notes);
}
}
if (!errors.isEmpty()) {
addPageMessage(respage.getString("there_were_some_errors_submission"));
if (locationError) {
addPageMessage(respage.getString("location_blank_error"));
}
setInputMessages(errors);
fp.addPresetValue(INPUT_DOB, fp.getString(INPUT_DOB));
fp.addPresetValue(INPUT_YOB, fp.getString(INPUT_YOB));
fp.addPresetValue(INPUT_GENDER, fp.getString(INPUT_GENDER));
fp.addPresetValue(INPUT_UNIQUE_IDENTIFIER, uniqueIdentifier);
fp.addPresetValue(INPUT_LABEL, label);
fp.addPresetValue(INPUT_SECONDARY_LABEL, fp.getString(INPUT_SECONDARY_LABEL));
fp.addPresetValue(INPUT_ENROLLMENT_DATE, fp.getString(INPUT_ENROLLMENT_DATE));
fp.addPresetValue(INPUT_EVENT_START_DATE, fp.getString(INPUT_EVENT_START_DATE));
fp.addPresetValue(STUDY_EVENT_DEFINITION, fp.getInt(STUDY_EVENT_DEFINITION));
fp.addPresetValue(LOCATION, fp.getString(LOCATION));
fp.addPresetValue(EDIT_DOB, fp.getString(EDIT_DOB));
setPresetValues(fp.getPresetValues());
setUpBeans(classes);
boolean existingSubShown = fp.getBoolean(EXISTING_SUB_SHOWN);
if (!existingSubShown) {
Object isSubjectOverlay = fp.getRequest().getParameter("subjectOverlay");
if (isSubjectOverlay != null) {
int eventId = fp.getInt("studyEventDefinition");
if (eventId < 1) {
Validator.addError(errors, STUDY_EVENT_DEFINITION, resexception.getString("input_not_acceptable_option"));
}
String location = fp.getString(LOCATION);
if (location == null && location.length() == 0) {
Validator.addError(errors, LOCATION, resexception.getString("field_not_blank"));
}
request.setAttribute("showOverlay", true);
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
} else {
forwardPage(Page.ADD_NEW_SUBJECT);
}
} else {
forwardPage(Page.ADD_EXISTING_SUBJECT);
}
} else {
// no errors
StudySubjectBean studySubject = new StudySubjectBean();
SubjectBean subject = new SubjectBean();
boolean existingSubShown = fp.getBoolean(EXISTING_SUB_SHOWN);
if (showExistingRecord && !existingSubShown) {
needUpdate = false;
subject = subjectWithSameId;
Calendar cal = Calendar.getInstance();
int year = 0;
if (subject.getDateOfBirth() != null) {
cal.setTime(subject.getDateOfBirth());
year = cal.get(Calendar.YEAR);
fp.addPresetValue(INPUT_DOB, local_df.format(subject.getDateOfBirth()));
} else {
fp.addPresetValue(INPUT_DOB, "");
}
if (currentStudy.getStudyParameterConfig().getCollectDob().equals("1") && !subject.isDobCollected()) {
// fp.addPresetValue(EDIT_DOB, "yes");
fp.addPresetValue(INPUT_DOB, fp.getString(INPUT_DOB));
}
// YW << it has been taken off to solve bug0001125
/*
* else { fp.addPresetValue(INPUT_DOB, ""); }
*/
// YW >>
fp.addPresetValue(INPUT_YOB, String.valueOf(year));
if (!currentStudy.getStudyParameterConfig().getGenderRequired().equals("false")) {
fp.addPresetValue(INPUT_GENDER, subject.getGender() + "");
} else {
fp.addPresetValue(INPUT_GENDER, "");
}
// Shaoyu Su: delay setting INPUT_LABEL field
if (!label.equalsIgnoreCase(resword.getString("id_generated_Save_Add"))) {
fp.addPresetValue(INPUT_LABEL, label);
}
fp.addPresetValue(INPUT_SECONDARY_LABEL, fp.getString(INPUT_SECONDARY_LABEL));
fp.addPresetValue(INPUT_ENROLLMENT_DATE, fp.getString(INPUT_ENROLLMENT_DATE));
fp.addPresetValue(INPUT_EVENT_START_DATE, fp.getString(INPUT_EVENT_START_DATE));
// YW >>
fp.addPresetValue(INPUT_UNIQUE_IDENTIFIER, subject.getUniqueIdentifier());
setPresetValues(fp.getPresetValues());
setUpBeans(classes);
// YW <<
int warningCount = 0;
if (currentStudy.getStudyParameterConfig().getGenderRequired().equalsIgnoreCase("true")) {
if (String.valueOf(subjectWithSameId.getGender()).equals(" ")) {
fp.addPresetValue(G_WARNING, "emptytrue");
fp.addPresetValue(INPUT_GENDER, GENDER);
needUpdate = true;
updateSubject = subjectWithSameId;
updateSubject.setGender(GENDER.toCharArray()[0]);
warningCount++;
} else if (!String.valueOf(subjectWithSameId.getGender()).equals(GENDER)) {
fp.addPresetValue(G_WARNING, "true");
warningCount++;
} else {
fp.addPresetValue(G_WARNING, "false");
}
} else {
fp.addPresetValue(G_WARNING, "false");
}
// Current study required DOB
if (currentStudy.getStudyParameterConfig().getCollectDob().equals("1")) {
// date-of-birth in subject table is not completed
if (subjectWithSameId.isDobCollected() == false) {
needUpdate = true;
updateSubject = subjectWithSameId;
updateSubject.setDobCollected(true);
if (subjectWithSameId.getDateOfBirth() == null) {
fp.addPresetValue(INPUT_DOB, DOB);
updateSubject.setDateOfBirth(new Date(DOB));
} else {
String y = String.valueOf(subjectWithSameId.getDateOfBirth()).split("\\-")[0];
String[] d = DOB.split("\\/");
// if year-of-birth in subject table
if (!y.equals("0001")) {
// year, use year-of-birth
if (!y.equals(d[2])) {
fp.addPresetValue(D_WARNING, "dobYearWrong");
fp.addPresetValue(INPUT_DOB, d[0] + "/" + d[1] + "/" + y);
updateSubject.setDateOfBirth(sdf.parse(d[0] + "/" + d[1] + "/" + y));
} else {
fp.addPresetValue(D_WARNING, "dobUsed");
fp.addPresetValue(INPUT_DOB, DOB);
updateSubject.setDateOfBirth(sdf.parse(DOB));
}
} else // date-of-birth is not required in subject
// table
{
fp.addPresetValue(D_WARNING, "emptyD");
fp.addPresetValue(INPUT_DOB, DOB);
updateSubject.setDateOfBirth(sdf.parse(DOB));
}
}
warningCount++;
} else // date-of-birth in subject table but doesn't match DOB
if (!local_df.format(subjectWithSameId.getDateOfBirth()).toString().equals(DOB)) {
// System.out.println("comparing " +
// local_df.format(
// subjectWithSameId.getDateOfBirth()).toString());
fp.addPresetValue(D_WARNING, "currentDOBWrong");
warningCount++;
} else // date-of-birth in subject table matchs DOB
{
fp.addPresetValue(D_WARNING, "false");
}
} else // current Study require YOB
if (currentStudy.getStudyParameterConfig().getCollectDob().equals("2")) {
String y = String.valueOf(subjectWithSameId.getDateOfBirth()).split("\\-")[0];
// year of date-of-birth in subject table is avaible
if (!y.equals("0001")) {
// year in subject table doesn't match YOB,
if (!y.equals(YOB)) {
fp.addPresetValue(Y_WARNING, "yobWrong");
warningCount++;
} else // year in subject table matches YOB
{
fp.addPresetValue(Y_WARNING, "false");
}
} else // year of date-of-birth in the subject talbe is not
// availbe, YOB is used
{
needUpdate = true;
updateSubject = subjectWithSameId;
fp.addPresetValue(Y_WARNING, "yearEmpty");
fp.addPresetValue(INPUT_YOB, YOB);
updateSubject.setDateOfBirth(sdf.parse("01/01/" + YOB));
warningCount++;
}
} else // current study require no DOB, there is no need to check
// date-of-birth in the subject table
{
fp.addPresetValue(Y_WARNING, "false");
}
if (warningCount > 0) {
warningCount = 0;
forwardPage(Page.ADD_EXISTING_SUBJECT);
return;
}
// forwardPage(Page.ADD_EXISTING_SUBJECT);
// return;
// YW >>
}
// to be inserted into both <subject> and <studysubject> tables
if (!showExistingRecord) {
// YW >>
if (!StringUtil.isBlank(fp.getString(INPUT_GENDER))) {
subject.setGender(fp.getString(INPUT_GENDER).charAt(0));
} else {
subject.setGender(' ');
}
subject.setUniqueIdentifier(uniqueIdentifier);
if (currentStudy.getStudyParameterConfig().getCollectDob().equals("1")) {
if (!StringUtil.isBlank(fp.getString(INPUT_DOB))) {
subject.setDateOfBirth(fp.getDate(INPUT_DOB));
subject.setDobCollected(true);
} else {
subject.setDateOfBirth(null);
subject.setDobCollected(false);
}
} else if (currentStudy.getStudyParameterConfig().getCollectDob().equals("2")) {
// generate a fake birthday in 01/01/YYYY format, only
// the year is
// valid
// added the "2" to make sure that 'not used' is kept to
// null, tbh 102007
subject.setDobCollected(false);
int yob = fp.getInt(INPUT_YOB);
Date fakeDate = new Date("01/01/" + yob);
// Calendar fakeCal = Calendar.getInstance();
// fakeCal.set(Calendar.YEAR, yob);
// fakeCal.set(Calendar.MONTH, 1);
// fakeCal.set(Calendar.DAY_OF_MONTH, 1);
// String dobString = "01/01/" + yob;
String dobString = local_df.format(fakeDate);
try {
Date fakeDOB = local_df.parse(dobString);
subject.setDateOfBirth(fakeDOB);
} catch (ParseException pe) {
subject.setDateOfBirth(new Date());
addPageMessage(respage.getString("problem_happened_saving_year"));
}
}
subject.setStatus(Status.AVAILABLE);
subject.setOwner(ub);
subject = sdao.create(subject);
if (!subject.isActive()) {
throw new OpenClinicaException(resexception.getString("could_not_create_subject"), "3");
}
// YW << for showExistingRecord && existingSubShown,
// If input value(s) is(are) different from database,
// warning will be shown.
// If value(s) in database is(are) empty, entered value(s)
// could be used;
// Otherwise, value(s) in database will be used.
// For date-of-birth, if database only has year-of-birth,
// the year in database will be used for year part
} else if (existingSubShown) {
if (!needUpdate) {
subject = subjectWithSameId;
} else {
updateSubject.setUpdater(ub);
updateSubject = (SubjectBean) sdao.update(updateSubject);
if (!updateSubject.isActive()) {
throw new OpenClinicaException("Could not create subject.", "5");
}
subject = updateSubject;
needUpdate = false;
}
}
// YW >>
// enroll the subject in the active study
studySubject.setSubjectId(subject.getId());
studySubject.setStudyId(currentStudy.getId());
studySubject.setLabel(fp.getString(INPUT_LABEL));
studySubject.setSecondaryLabel(fp.getString(INPUT_SECONDARY_LABEL));
studySubject.setStatus(Status.AVAILABLE);
studySubject.setEnrollmentDate(fp.getDate(INPUT_ENROLLMENT_DATE));
if (fp.getBoolean("addWithEvent")) {
studySubject.setEventStartDate(fp.getDate(INPUT_EVENT_START_DATE));
}
studySubject.setOwner(ub);
// Shaoyu Su: prevent same label ("Study Subject ID")
if (fp.getString(INPUT_LABEL).equalsIgnoreCase(resword.getString("id_generated_Save_Add"))) {
synchronized (simpleLockObj) {
int nextLabel = ssd.findTheGreatestLabel() + 1;
studySubject.setLabel(nextLabel + "");
studySubject = ssd.createWithoutGroup(studySubject);
if (showExistingRecord && !existingSubShown) {
fp.addPresetValue(INPUT_LABEL, label);
}
}
} else {
studySubject = ssd.createWithoutGroup(studySubject);
}
if (!classes.isEmpty() && studySubject.isActive()) {
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
for (int i = 0; i < classes.size(); i++) {
StudyGroupClassBean group = (StudyGroupClassBean) classes.get(i);
int studyGroupId = group.getStudyGroupId();
String notes = group.getGroupNotes();
SubjectGroupMapBean map = new SubjectGroupMapBean();
map.setNotes(group.getGroupNotes());
map.setStatus(Status.AVAILABLE);
map.setStudyGroupId(group.getStudyGroupId());
map.setStudySubjectId(studySubject.getId());
map.setStudyGroupClassId(group.getId());
map.setOwner(ub);
if (map.getStudyGroupId() > 0) {
sgmdao.create(map);
}
}
}
if (!studySubject.isActive()) {
throw new OpenClinicaException(resexception.getString("could_not_create_study_subject"), "4");
}
// save discrepancy notes into DB
FormDiscrepancyNotes fdn = (FormDiscrepancyNotes) session.getAttribute(FORM_DISCREPANCY_NOTES_NAME);
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
String[] subjectFields = { INPUT_DOB, INPUT_YOB, INPUT_GENDER };
for (String element : subjectFields) {
saveFieldNotes(element, fdn, dndao, subject.getId(), "subject", currentStudy);
}
saveFieldNotes(INPUT_ENROLLMENT_DATE, fdn, dndao, studySubject.getId(), "studySub", currentStudy);
request.removeAttribute(FormProcessor.FIELD_SUBMITTED);
request.setAttribute(CreateNewStudyEventServlet.INPUT_STUDY_SUBJECT, studySubject);
request.setAttribute(CreateNewStudyEventServlet.INPUT_REQUEST_STUDY_SUBJECT, "no");
request.setAttribute(FormProcessor.FIELD_SUBMITTED, "0");
addPageMessage(respage.getString("subject_with_unique_identifier") + studySubject.getLabel() + respage.getString("X_was_created_succesfully"));
if (fp.getBoolean("addWithEvent")) {
createStudyEvent(fp, studySubject);
// YW <<
request.setAttribute("id", studySubject.getId() + "");
// String url= response.encodeRedirectURL("ViewStudySubject?id=" + studySubject.getId());
// response.sendRedirect(url);
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
// + studySubject.getId()));
return;
}
String submitEvent = fp.getString(SUBMIT_EVENT_BUTTON);
String submitEnroll = fp.getString(SUBMIT_ENROLL_BUTTON);
String submitDone = fp.getString(SUBMIT_DONE_BUTTON);
session.removeAttribute(FORM_DISCREPANCY_NOTES_NAME);
if (!StringUtil.isBlank(submitEvent)) {
forwardPage(Page.CREATE_NEW_STUDY_EVENT_SERVLET);
} else if (!StringUtil.isBlank(submitEnroll)) {
// NEW MANTIS ISSUE 4770
setUpBeans(classes);
Date today = new Date(System.currentTimeMillis());
String todayFormatted = local_df.format(today);
fp.addPresetValue(INPUT_ENROLLMENT_DATE, todayFormatted);
// YW 10-07-2007 <<
String idSetting = "";
if (currentStudy.getParentStudyId() > 0) {
parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "subjectIdGeneration");
currentStudy.getStudyParameterConfig().setSubjectIdGeneration(parentSPV.getValue());
}
idSetting = currentStudy.getStudyParameterConfig().getSubjectIdGeneration();
// YW >>
logger.info("subject id setting :" + idSetting);
// set up auto study subject id
if (idSetting.equals("auto editable") || idSetting.equals("auto non-editable")) {
// Shaoyu Su
// int nextLabel = ssd.findTheGreatestLabel() + 1;
// fp.addPresetValue(INPUT_LABEL, new Integer(nextLabel).toString());
fp.addPresetValue(INPUT_LABEL, resword.getString("id_generated_Save_Add"));
}
setPresetValues(fp.getPresetValues());
discNotes = new FormDiscrepancyNotes();
session.setAttribute(FORM_DISCREPANCY_NOTES_NAME, discNotes);
// End of 4770
forwardPage(Page.ADD_NEW_SUBJECT);
} else {
// forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
// forwardPage(Page.SUBMIT_DATA_SERVLET);
request.setAttribute("id", studySubject.getId() + "");
// String url=response.encodeRedirectURL("ViewStudySubject?id=" + studySubject.getId());
// response.sendRedirect(url);
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
return;
}
}
// end of no error (errors.isEmpty())
}
// end of fp.isSubmitted()
}
use of org.akaza.openclinica.bean.submit.SubjectBean in project OpenClinica by OpenClinica.
the class AddNewSubjectServlet method displaySubjects.
/**
* Find study subject id for each subject, and construct displaySubjectBean
*
* @param displayArray
* @param subjects
*/
public static void displaySubjects(ArrayList displayArray, ArrayList subjects, StudySubjectDAO ssdao, StudyDAO stdao) {
for (int i = 0; i < subjects.size(); i++) {
SubjectBean subject = (SubjectBean) subjects.get(i);
ArrayList studySubs = ssdao.findAllBySubjectId(subject.getId());
String protocolSubjectIds = "";
for (int j = 0; j < studySubs.size(); j++) {
StudySubjectBean studySub = (StudySubjectBean) studySubs.get(j);
int studyId = studySub.getStudyId();
StudyBean stu = (StudyBean) stdao.findByPK(studyId);
String protocolId = stu.getIdentifier();
if (j == studySubs.size() - 1) {
protocolSubjectIds = protocolId + "-" + studySub.getLabel();
} else {
protocolSubjectIds = protocolId + "-" + studySub.getLabel() + ", ";
}
}
DisplaySubjectBean dsb = new DisplaySubjectBean();
dsb.setSubject(subject);
dsb.setStudySubjectIds(protocolSubjectIds);
displayArray.add(dsb);
}
}
use of org.akaza.openclinica.bean.submit.SubjectBean in project OpenClinica by OpenClinica.
the class ViewSectionDataEntryRESTUrlServlet method processRequest.
@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
FormProcessor fp = new FormProcessor(request);
StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
boolean isSubmitted = false;
EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) request.getAttribute(EVENT_DEF_CRF_BEAN);
if (!fp.getString("exitTo").equals("")) {
request.setAttribute("exitTo", request.getContextPath() + "/" + fp.getString("exitTo"));
}
int crfVersionId = fp.getInt("crfVersionId", true);
Integer sectionId = (Integer) request.getAttribute("sectionId");
if (sectionId == null || sectionId == 0) {
sectionId = new Integer(1);
}
int eventCRFId = fp.getInt(EVENT_CRF_ID, true);
int studySubjectId = fp.getInt("studySubjectId", true);
String action = fp.getString("action");
HttpSession session = request.getSession();
String fromResolvingNotes = fp.getString("fromResolvingNotes", true);
if (StringUtil.isBlank(fromResolvingNotes)) {
session.removeAttribute(ViewNotesServlet.WIN_LOCATION);
session.removeAttribute(ViewNotesServlet.NOTES_TABLE);
}
// Added for
request.setAttribute("studySubjectId", studySubjectId + "");
// Mantis
// Issue
// 2268
// Added
request.setAttribute("crfListPage", fp.getString("crfListPage"));
// for
// Mantis
// Issue
// 2268
// Added for
request.setAttribute("eventId", fp.getString("eventId"));
// Mantis
// Issue
// 2268
// YW <<
int sedId = fp.getInt("sedId");
request.setAttribute("sedId", sedId + "");
int crfId = fp.getInt("crfId");
// BWP>> ... try to get crfId from crfVersionId
if (crfId == 0 && crfVersionId > 0) {
CRFVersionDAO crfVDao = new CRFVersionDAO(getDataSource());
CRFVersionBean crvVBean = (CRFVersionBean) crfVDao.findByPK(crfVersionId);
if (crvVBean != null) {
crfId = crvVBean.getCrfId();
}
}
// YW >>
// int eventDefinitionCRFId = fp.getInt("eventDefinitionCRFId");
Integer eventDefinitionCRFId = (Integer) (request.getAttribute("eventDefinitionCRFId"));
EventDefinitionCRFDAO eventCrfDao = new EventDefinitionCRFDAO(getDataSource());
edcb = (EventDefinitionCRFBean) eventCrfDao.findByPK(eventDefinitionCRFId);
if (eventCRFId == 0 && edcb.getStudyId() != currentStudy.getParentStudyId() && edcb.getStudyId() != currentStudy.getId()) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_study_contact_sysadmin"), request);
throw new InsufficientPermissionException(Page.MENU_SERVLET, resexception.getString("not_director"), "1");
}
if (crfId == 0 && eventDefinitionCRFId > 0) {
// eventCrfDao.findByPK(eventDefinitionCRFId);
if (edcb != null) {
crfId = edcb.getCrfId();
}
}
request.setAttribute("crfId", crfId + "");
request.setAttribute("eventDefinitionCRFId", eventDefinitionCRFId + "");
String printVersion = fp.getString("print");
// BWP>> this has to be removed for CRFs that do not display an
// interviewdate
// for a particular event
session.removeAttribute("presetValues");
EventCRFDAO ecdao = new EventCRFDAO(getDataSource());
SectionDAO sdao = new SectionDAO(getDataSource());
String age = "";
if (sectionId == 0 && crfVersionId == 0 && eventCRFId == 0) {
addPageMessage(respage.getString("please_choose_a_CRF_to_view"), request);
// forwardPage(Page.SUBMIT_DATA_SERVLET);
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET, request, response);
// >> changed tbh, 06/2009
return;
}
if (studySubjectId > 0) {
StudySubjectDAO ssdao = new StudySubjectDAO(getDataSource());
StudySubjectBean sub = (StudySubjectBean) ssdao.findByPK(studySubjectId);
request.setAttribute("studySubject", sub);
}
if (eventCRFId > 0) {
// for event crf, the input crfVersionId from url =0
ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
StudyEventDAO sedao = new StudyEventDAO(getDataSource());
StudyEventBean event = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
// event.getSubjectEventStatus().getName());
if (event.getSubjectEventStatus().equals(SubjectEventStatus.LOCKED)) {
request.setAttribute("isLocked", "yes");
// System.out.println("this event crf is locked");
} else // @pgawade 28-Aug-2012 Reverted the change no. 2 in
// https://issuetracker.openclinica.com/view.php?id=12343#c56722
{
request.setAttribute("isLocked", "no");
}
if (studySubjectId <= 0) {
studySubjectId = event.getStudySubjectId();
request.setAttribute("studySubjectId", studySubjectId + "");
}
// Get the status/number of item discrepancy notes
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(getDataSource());
ArrayList<DiscrepancyNoteBean> allNotes = new ArrayList<DiscrepancyNoteBean>();
List<DiscrepancyNoteBean> eventCrfNotes = new ArrayList<DiscrepancyNoteBean>();
List<DiscrepancyNoteThread> noteThreads = new ArrayList<DiscrepancyNoteThread>();
// if (eventCRFId > 0) {
// this method finds only parent notes
allNotes = dndao.findAllTopNotesByEventCRF(eventCRFId);
// add interviewer.jsp related notes to this Collection
eventCrfNotes = dndao.findOnlyParentEventCRFDNotesFromEventCRF(ecb);
if (!eventCrfNotes.isEmpty()) {
allNotes.addAll(eventCrfNotes);
// make sure a necessary request attribute "hasNameNote" is set
// properly
this.setAttributeForInterviewerDNotes(eventCrfNotes, request);
}
// }
// Create disc note threads out of the various notes
DiscrepancyNoteUtil dNoteUtil = new DiscrepancyNoteUtil();
noteThreads = dNoteUtil.createThreadsOfParents(allNotes, getDataSource(), currentStudy, null, -1, true);
// variables that provide values for the CRF discrepancy note header
int updatedNum = 0;
int openNum = 0;
int closedNum = 0;
int resolvedNum = 0;
int notAppNum = 0;
DiscrepancyNoteBean tempBean;
for (DiscrepancyNoteThread dnThread : noteThreads) {
/*
* 3014: do not count parent beans, only the last child disc
* note of the thread.
*/
tempBean = dnThread.getLinkedNoteList().getLast();
if (tempBean != null) {
if (ResolutionStatus.UPDATED.equals(tempBean.getResStatus())) {
updatedNum++;
} else if (ResolutionStatus.OPEN.equals(tempBean.getResStatus())) {
openNum++;
} else if (ResolutionStatus.CLOSED.equals(tempBean.getResStatus())) {
// if (dn.getParentDnId() > 0){
closedNum++;
// }
} else if (ResolutionStatus.RESOLVED.equals(tempBean.getResStatus())) {
// if (dn.getParentDnId() > 0){
resolvedNum++;
// }
} else if (ResolutionStatus.NOT_APPLICABLE.equals(tempBean.getResStatus())) {
notAppNum++;
}
}
}
request.setAttribute("updatedNum", updatedNum + "");
request.setAttribute("openNum", openNum + "");
request.setAttribute("closedNum", closedNum + "");
request.setAttribute("resolvedNum", resolvedNum + "");
request.setAttribute("notAppNum", notAppNum + "");
DisplayTableOfContentsBean displayBean = TableOfContentsServlet.getDisplayBean(ecb, getDataSource(), currentStudy);
// Make sure that the interviewDate in the eventCRF is properly
// formatted
// for viewSectionDataEntry.jsp --> interviewer.jsp
// int studyEventId = (Integer)request.getAttribute("studyEvent");
// SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
//
Date tmpDate = displayBean.getEventCRF().getDateInterviewed();
String formattedInterviewerDate;
try {
DateFormat local_df = new SimpleDateFormat(resformat.getString("date_format_string"), ResourceBundleProvider.getLocale());
formattedInterviewerDate = local_df.format(tmpDate);
} catch (Exception e) {
formattedInterviewerDate = "";
}
HashMap presetVals = (HashMap) session.getAttribute("presetValues");
if (presetVals == null) {
presetVals = new HashMap();
session.setAttribute("presetValues", presetVals);
}
presetVals.put("interviewDate", formattedInterviewerDate);
request.setAttribute("toc", displayBean);
ArrayList sections = displayBean.getSections();
request.setAttribute("sectionNum", sections.size() + "");
if (!sections.isEmpty()) {
if (sectionId == 0) {
SectionBean firstSec = (SectionBean) sections.get(0);
sectionId = firstSec.getId();
}
} else {
addPageMessage(respage.getString("there_are_no_sections_ins_this_CRF"), request);
// forwardPage(Page.SUBMIT_DATA_SERVLET);
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET, request, response);
// >> changed tbh, 06/2009
return;
}
} else if (crfVersionId > 0) {
// for viewing blank CRF
DisplayTableOfContentsBean displayBean = ViewTableOfContentServlet.getDisplayBean(getDataSource(), crfVersionId);
request.setAttribute("toc", displayBean);
ArrayList sections = displayBean.getSections();
request.setAttribute("sectionNum", sections.size() + "");
if (!sections.isEmpty()) {
if (sectionId == 0) {
SectionBean firstSec = (SectionBean) sections.get(0);
sectionId = firstSec.getId();
}
} else {
addPageMessage(respage.getString("there_are_no_sections_ins_this_CRF_version"), request);
if (eventCRFId == 0) {
forwardPage(Page.CRF_LIST_SERVLET, request, response);
} else {
// forwardPage(Page.SUBMIT_DATA_SERVLET);
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET, request, response);
// >> changed tbh, 06/2009
}
return;
}
}
sb = (SectionBean) sdao.findByPK(sectionId);
if (eventCRFId == 0) {
ecb = new EventCRFBean();
ecb.setCRFVersionId(sb.getCRFVersionId());
if (currentStudy.getParentStudyId() > 0) {
// this is a site,find parent
StudyDAO studydao = new StudyDAO(getDataSource());
StudyBean parentStudy = (StudyBean) studydao.findByPK(currentStudy.getParentStudyId());
request.setAttribute("studyTitle", parentStudy.getName());
request.setAttribute("siteTitle", currentStudy.getName());
} else {
request.setAttribute("studyTitle", currentStudy.getName());
}
} else {
ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
request.setAttribute(INPUT_EVENT_CRF, ecb);
request.setAttribute(SECTION_BEAN, sb);
// This is the StudySubjectBean
StudySubjectDAO ssdao = new StudySubjectDAO(getDataSource());
StudySubjectBean sub = (StudySubjectBean) ssdao.findByPK(ecb.getStudySubjectId());
// This is the SubjectBean
SubjectDAO subjectDao = new SubjectDAO(getDataSource());
int subjectId = sub.getSubjectId();
int studyId = sub.getStudyId();
SubjectBean subject = (SubjectBean) subjectDao.findByPK(subjectId);
// Let us process the age
if (currentStudy.getStudyParameterConfig().getCollectDob().equals("1")) {
StudyEventDAO sedao = new StudyEventDAO(getDataSource());
StudyEventBean se = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
se.setStudyEventDefinition(sed);
request.setAttribute("studyEvent", se);
// YW 11-16-2007 enrollment-date is used for computing age
age = Utils.getInstacne().processAge(sub.getEnrollmentDate(), subject.getDateOfBirth());
}
// Get the study then the parent study
StudyDAO studydao = new StudyDAO(getDataSource());
StudyBean study = (StudyBean) studydao.findByPK(studyId);
if (study.getParentStudyId() > 0) {
// this is a site,find parent
StudyBean parentStudy = (StudyBean) studydao.findByPK(study.getParentStudyId());
request.setAttribute("studyTitle", parentStudy.getName());
request.setAttribute("siteTitle", study.getName());
} else {
request.setAttribute("studyTitle", study.getName());
}
request.setAttribute("studySubject", sub);
request.setAttribute("subject", subject);
request.setAttribute("age", age);
}
// FormBeanUtil formUtil = new FormBeanUtil();
// DisplaySectionBean newDisplayBean = new DisplaySectionBean();
boolean hasItemGroup = false;
// we will look into db to see if any repeating items for this CRF
// section
ItemGroupDAO igdao = new ItemGroupDAO(getDataSource());
List<ItemGroupBean> itemGroups = igdao.findLegitGroupBySectionId(sectionId);
if (!itemGroups.isEmpty()) {
hasItemGroup = true;
}
// if the List of DisplayFormGroups is empty, then the servlet defers to
// the prior method
// of generating a DisplaySectionBean for the application
DisplaySectionBean dsb;
// want to get displayBean with grouped and ungrouped items
request.setAttribute(EVENT_DEF_CRF_BEAN, edcb);
request.setAttribute(INPUT_EVENT_CRF, ecb);
request.setAttribute(SECTION_BEAN, sb);
dsb = super.getDisplayBean(hasItemGroup, false, request, isSubmitted);
FormDiscrepancyNotes discNotes = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
if (discNotes == null) {
discNotes = new FormDiscrepancyNotes();
session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes);
}
/*
* if (hasItemGroup) { //
* dsb.setDisplayItemGroups(newDisplayBean.getDisplayItemGroups());
* request.setAttribute("new_table", true); }
*/
// If the Horizontal type table will be used, then set the
// DisplaySectionBean's
// DisplayFormGroups List to the ones we have just generated
// @pgawade 30-May-2012 Fix for issue 13963 - added an extra parameter
// 'isSubmitted' to method createItemWithGroups
List<DisplayItemWithGroupBean> displayItemWithGroups = super.createItemWithGroups(dsb, hasItemGroup, eventDefinitionCRFId, request, isSubmitted);
dsb.setDisplayItemGroups(displayItemWithGroups);
super.populateNotesWithDBNoteCounts(discNotes, dsb, request);
if (fp.getString("fromViewNotes") != null && "1".equals(fp.getString("fromViewNotes"))) {
request.setAttribute("fromViewNotes", fp.getString("fromViewNotes"));
} else {
session.removeAttribute("viewNotesURL");
}
if ("saveNotes".equalsIgnoreCase(action)) {
LOGGER.info("33333how many group rows:" + dsb.getDisplayItemGroups().size());
// let's save notes for the blank items
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(getDataSource());
discNotes = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
for (int i = 0; i < dsb.getDisplayItemGroups().size(); i++) {
DisplayItemWithGroupBean diwb = dsb.getDisplayItemGroups().get(i);
if (diwb.isInGroup()) {
List<DisplayItemGroupBean> dgbs = diwb.getItemGroups();
LOGGER.info("dgbs size: " + dgbs.size());
for (int j = 0; j < dgbs.size(); j++) {
DisplayItemGroupBean displayGroup = dgbs.get(j);
List<DisplayItemBean> items = displayGroup.getItems();
LOGGER.info("item size: " + items.size());
for (DisplayItemBean displayItem : items) {
String inputName = getGroupItemInputName(displayGroup, j, displayItem);
LOGGER.info("inputName:" + inputName);
LOGGER.info("item data id:" + displayItem.getData().getId());
AddNewSubjectServlet.saveFieldNotes(inputName, discNotes, dndao, displayItem.getData().getId(), "itemData", currentStudy);
}
}
} else {
DisplayItemBean dib = diwb.getSingleItem();
// TODO work on this line
String inputName = getInputName(dib);
AddNewSubjectServlet.saveFieldNotes(inputName, discNotes, dndao, dib.getData().getId(), DiscrepancyNoteBean.ITEM_DATA, currentStudy);
ArrayList childItems = dib.getChildren();
for (int j = 0; j < childItems.size(); j++) {
DisplayItemBean child = (DisplayItemBean) childItems.get(j);
inputName = getInputName(child);
AddNewSubjectServlet.saveFieldNotes(inputName, discNotes, dndao, dib.getData().getId(), DiscrepancyNoteBean.ITEM_DATA, currentStudy);
}
}
}
addPageMessage("Discrepancy notes are saved successfully.", request);
request.setAttribute("id", studySubjectId + "");
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET, request, response);
// "ViewStudySubject?id=" + studySubjectId));
return;
} else {
request.setAttribute(BEAN_DISPLAY, dsb);
request.setAttribute(BEAN_ANNOTATIONS, ecb.getAnnotations());
request.setAttribute("sec", sb);
request.setAttribute("EventCRFBean", ecb);
int tabNum = 1;
if ("".equalsIgnoreCase(fp.getString("tabId"))) {
tabNum = 1;
} else {
tabNum = fp.getInt("tabId");
}
request.setAttribute("tabId", new Integer(tabNum).toString());
// 2808: Signal interviewer.jsp that the containing page is
// viewSectionData,
// for the purpose of suppressing discrepancy note icons for the
// interview date and name fields
request.setAttribute(ENCLOSING_PAGE, "viewSectionData");
if ("yes".equalsIgnoreCase(printVersion)) {
forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PRINT, request, response);
} else {
forwardPage(Page.VIEW_SECTION_DATA_ENTRY, request, response);
}
}
}
use of org.akaza.openclinica.bean.submit.SubjectBean in project OpenClinica by OpenClinica.
the class ViewDiscrepancyNoteServlet method processRequest.
@Override
@SuppressWarnings("unchecked")
protected void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
int eventCRFId = fp.getInt(CreateDiscrepancyNoteServlet.EVENT_CRF_ID);
request.setAttribute(CreateDiscrepancyNoteServlet.EVENT_CRF_ID, new Integer(eventCRFId));
request.setAttribute(DIS_TYPES, DiscrepancyNoteType.list);
if (currentRole.getRole().equals(Role.RESEARCHASSISTANT) || currentRole.getRole().equals(Role.RESEARCHASSISTANT2) || currentRole.getRole().equals(Role.INVESTIGATOR)) {
ArrayList<ResolutionStatus> resStatuses = new ArrayList();
resStatuses.add(ResolutionStatus.UPDATED);
resStatuses.add(ResolutionStatus.RESOLVED);
request.setAttribute(RES_STATUSES, resStatuses);
// it's for parentDNId is null or 0
request.setAttribute(WHICH_RES_STATUSES, "22");
ArrayList<ResolutionStatus> resStatuses2 = new ArrayList<ResolutionStatus>();
resStatuses2.add(ResolutionStatus.OPEN);
resStatuses2.add(ResolutionStatus.RESOLVED);
request.setAttribute(RES_STATUSES2, resStatuses2);
List<DiscrepancyNoteType> types2 = new ArrayList<DiscrepancyNoteType>(DiscrepancyNoteType.list);
types2.remove(DiscrepancyNoteType.QUERY);
request.setAttribute(DIS_TYPES2, types2);
} else if (currentRole.getRole().equals(Role.MONITOR)) {
ArrayList<ResolutionStatus> resStatuses = new ArrayList();
resStatuses.add(ResolutionStatus.OPEN);
resStatuses.add(ResolutionStatus.UPDATED);
resStatuses.add(ResolutionStatus.CLOSED);
request.setAttribute(RES_STATUSES, resStatuses);
request.setAttribute(WHICH_RES_STATUSES, "1");
ArrayList<DiscrepancyNoteType> types2 = new ArrayList<DiscrepancyNoteType>();
types2.add(DiscrepancyNoteType.QUERY);
request.setAttribute(DIS_TYPES2, types2);
} else {
// Role.STUDYDIRECTOR Role.COORDINATOR
List<ResolutionStatus> resStatuses = new ArrayList<ResolutionStatus>(ResolutionStatus.list);
resStatuses.remove(ResolutionStatus.NOT_APPLICABLE);
request.setAttribute(RES_STATUSES, resStatuses);
;
// it's for parentDNId is null or 0 and FVC
request.setAttribute(WHICH_RES_STATUSES, "2");
ArrayList<ResolutionStatus> resStatuses2 = new ArrayList<ResolutionStatus>();
resStatuses2.add(ResolutionStatus.OPEN);
resStatuses2.add(ResolutionStatus.RESOLVED);
request.setAttribute(RES_STATUSES2, resStatuses2);
}
// logic from CreateDiscrepancyNoteServlet
request.setAttribute("unlock", "0");
fp.getBoolean(IS_REASON_FOR_CHANGE);
fp.getBoolean(ERROR_FLAG);
String monitor = fp.getString("monitor");
// } else if ("1".equalsIgnoreCase(monitor)) {// change to allow user to
if ("1".equalsIgnoreCase(monitor)) {
// change to allow user to
// enter note for all items,
// not just blank items
request.setAttribute(CAN_MONITOR, "1");
request.setAttribute("monitor", monitor);
} else {
request.setAttribute(CAN_MONITOR, "0");
}
Boolean fromBox = fp.getBoolean(FROM_BOX);
if (fromBox == null || !fromBox) {
session.removeAttribute(BOX_TO_SHOW);
session.removeAttribute(BOX_DN_MAP);
session.removeAttribute(AUTOVIEWS);
}
Boolean refresh = fp.getBoolean("refresh");
request.setAttribute("refresh", refresh + "");
String ypos = fp.getString("y");
if (ypos == null || ypos.length() == 0) {
ypos = "0";
}
request.setAttribute("y", ypos);
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
int entityId = fp.getInt(ENTITY_ID, true);
String name = fp.getString(ENTITY_TYPE, true);
String column = fp.getString(ENTITY_COLUMN, true);
String field = fp.getString(ENTITY_FIELD, true);
String isLocked = fp.getString(LOCKED_FLAG);
if (!StringUtil.isBlank(isLocked) && "yes".equalsIgnoreCase(isLocked)) {
request.setAttribute(LOCKED_FLAG, "yes");
} else {
request.setAttribute(LOCKED_FLAG, "no");
}
DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
int subjectId = fp.getInt(CreateDiscrepancyNoteServlet.SUBJECT_ID, true);
int itemId = fp.getInt(CreateDiscrepancyNoteServlet.ITEM_ID, true);
StudySubjectBean ssub = new StudySubjectBean();
if (subjectId > 0) {
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ssub = (StudySubjectBean) ssdao.findByPK(subjectId);
request.setAttribute("noteSubject", ssub);
}
ItemBean item = new ItemBean();
if (itemId > 0) {
ItemDAO idao = new ItemDAO(sm.getDataSource());
item = (ItemBean) idao.findByPK(itemId);
request.setAttribute("item", item);
request.setAttribute("entityName", item.getName());
}
ItemDataBean itemData = new ItemDataBean();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
int preUserId = 0;
if (!StringUtil.isBlank(name)) {
if ("itemData".equalsIgnoreCase(name)) {
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
itemData = (ItemDataBean) iddao.findByPK(entityId);
request.setAttribute("entityValue", itemData.getValue());
request.setAttribute("entityName", item.getName());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
EventCRFBean ec = (EventCRFBean) ecdao.findByPK(itemData.getEventCRFId());
preUserId = ec.getOwnerId() > 0 ? ec.getOwnerId() : 0;
request.setAttribute("entityCreatedDate", sdf.format(ec.getCreatedDate()));
StudyEventDAO sed = new StudyEventDAO(sm.getDataSource());
StudyEventBean se = (StudyEventBean) sed.findByPK(ec.getStudyEventId());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
se.setName(sedb.getName());
request.setAttribute("studyEvent", se);
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFVersionBean cv = (CRFVersionBean) cvdao.findByPK(ec.getCRFVersionId());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFBean crf = (CRFBean) cdao.findByPK(cv.getCrfId());
request.setAttribute("crf", crf);
} else if ("studySub".equalsIgnoreCase(name)) {
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ssub = (StudySubjectBean) ssdao.findByPK(entityId);
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
SubjectBean sub = (SubjectBean) sdao.findByPK(ssub.getSubjectId());
request.setAttribute("noteSubject", ssub);
if (!StringUtil.isBlank(column)) {
if ("enrollment_date".equalsIgnoreCase(column)) {
if (ssub.getEnrollmentDate() != null) {
request.setAttribute("entityValue", dateFormatter.format(ssub.getEnrollmentDate()));
}
request.setAttribute("entityName", resword.getString("enrollment_date"));
} else if ("gender".equalsIgnoreCase(column)) {
request.setAttribute("entityValue", sub.getGender() + "");
request.setAttribute("entityName", resword.getString("gender"));
} else if ("date_of_birth".equalsIgnoreCase(column)) {
if (sub.getDateOfBirth() != null) {
request.setAttribute("entityValue", dateFormatter.format(sub.getDateOfBirth()));
}
request.setAttribute("entityName", resword.getString("date_of_birth"));
} else if ("unique_identifier".equalsIgnoreCase(column)) {
if (sub.getUniqueIdentifier() != null) {
request.setAttribute("entityValue", sub.getUniqueIdentifier());
}
request.setAttribute("entityName", resword.getString("unique_identifier"));
}
}
preUserId = ssub.getOwnerId() > 0 ? ssub.getOwnerId() : 0;
request.setAttribute("entityCreatedDate", sdf.format(ssub.getCreatedDate()));
} else if ("subject".equalsIgnoreCase(name)) {
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
SubjectBean sub = (SubjectBean) sdao.findByPK(entityId);
// be caution: here for subject, noteSubject is SubjectBean and
// label is unique_identifier
sub.setLabel(sub.getUniqueIdentifier());
request.setAttribute("noteSubject", sub);
if (!StringUtil.isBlank(column)) {
if ("gender".equalsIgnoreCase(column)) {
request.setAttribute("entityValue", ssub.getGender() + "");
request.setAttribute("entityName", resword.getString("gender"));
} else if ("date_of_birth".equalsIgnoreCase(column)) {
if (sub.getDateOfBirth() != null) {
request.setAttribute("entityValue", dateFormatter.format(sub.getDateOfBirth()));
}
request.setAttribute("entityName", resword.getString("date_of_birth"));
} else if ("unique_identifier".equalsIgnoreCase(column)) {
request.setAttribute("entityValue", sub.getUniqueIdentifier());
request.setAttribute("entityName", resword.getString("unique_identifier"));
}
}
preUserId = sub.getOwnerId() > 0 ? sub.getOwnerId() : 0;
request.setAttribute("entityCreatedDate", sdf.format(sub.getCreatedDate()));
} else if ("studyEvent".equalsIgnoreCase(name)) {
StudyEventDAO sed = new StudyEventDAO(sm.getDataSource());
StudyEventBean se = (StudyEventBean) sed.findByPK(entityId);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
se.setName(sedb.getName());
request.setAttribute("studyEvent", se);
request.setAttribute("noteSubject", new StudySubjectDAO(sm.getDataSource()).findByPK(se.getStudySubjectId()));
if (!StringUtil.isBlank(column)) {
if ("location".equalsIgnoreCase(column)) {
request.setAttribute("entityValue", se.getLocation());
request.setAttribute("entityName", resword.getString("location"));
} else if ("start_date".equalsIgnoreCase(column)) {
if (se.getDateStarted() != null) {
request.setAttribute("entityValue", dateFormatter.format(se.getDateStarted()));
}
request.setAttribute("entityName", resword.getString("start_date"));
} else if ("end_date".equalsIgnoreCase(column)) {
if (se.getDateEnded() != null) {
request.setAttribute("entityValue", dateFormatter.format(se.getDateEnded()));
}
request.setAttribute("entityName", resword.getString("end_date"));
}
}
preUserId = se.getOwnerId() > 0 ? se.getOwnerId() : 0;
request.setAttribute("entityCreatedDate", sdf.format(se.getCreatedDate()));
} else if ("eventCrf".equalsIgnoreCase(name)) {
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
EventCRFBean ec = (EventCRFBean) ecdao.findByPK(entityId);
if (!StringUtil.isBlank(column)) {
if ("date_interviewed".equals(column)) {
if (ec.getDateInterviewed() != null) {
request.setAttribute("entityValue", dateFormatter.format(ec.getDateInterviewed()));
}
request.setAttribute("entityName", resword.getString("date_interviewed"));
} else if ("interviewer_name".equals(column)) {
request.setAttribute("entityValue", ec.getInterviewerName());
request.setAttribute("entityName", resword.getString("interviewer_name"));
}
}
setupStudyEventCRFAttributes(ec);
preUserId = ec.getOwnerId() > 0 ? ec.getOwnerId() : 0;
request.setAttribute("entityCreatedDate", sdf.format(ec.getCreatedDate()));
}
}
boolean writeToDB = fp.getBoolean(CreateDiscrepancyNoteServlet.WRITE_TO_DB, true);
HashMap<Integer, Integer> autoviews = (HashMap<Integer, Integer>) session.getAttribute(AUTOVIEWS);
autoviews = autoviews == null ? new HashMap<Integer, Integer>() : autoviews;
HashMap<Integer, DiscrepancyNoteBean> boxDNMap = (HashMap<Integer, DiscrepancyNoteBean>) session.getAttribute(BOX_DN_MAP);
if (boxDNMap == null || !boxDNMap.containsKey(0)) {
boxDNMap = new HashMap<Integer, DiscrepancyNoteBean>();
// initialize dn for a new thread
DiscrepancyNoteBean dnb = new DiscrepancyNoteBean();
if (currentRole.getRole().equals(Role.RESEARCHASSISTANT) || currentRole.getRole().equals(Role.RESEARCHASSISTANT2) || currentRole.getRole().equals(Role.INVESTIGATOR)) {
dnb.setDiscrepancyNoteTypeId(DiscrepancyNoteType.ANNOTATION.getId());
dnb.setResolutionStatusId(ResolutionStatus.NOT_APPLICABLE.getId());
autoviews.put(0, 0);
// request.setAttribute("autoView", "0");
} else {
dnb.setDiscrepancyNoteTypeId(DiscrepancyNoteType.QUERY.getId());
dnb.setAssignedUserId(preUserId);
autoviews.put(0, 1);
// request.setAttribute("autoView", "1");
}
boxDNMap.put(0, dnb);
} else if (boxDNMap.containsKey(0)) {
int dnTypeId = boxDNMap.get(0).getDiscrepancyNoteTypeId();
autoviews.put(0, dnTypeId == 3 ? 1 : 0);
}
if (boxDNMap.containsKey(0)) {
int dnTypeId0 = boxDNMap.get(0).getDiscrepancyNoteTypeId();
if (dnTypeId0 == 2 || dnTypeId0 == 4) {
request.setAttribute("typeID0", dnTypeId0 + "");
}
}
// request.setAttribute("enterData", enterData);
request.setAttribute("monitor", monitor);
request.setAttribute(ENTITY_ID, entityId + "");
request.setAttribute(ENTITY_TYPE, name);
request.setAttribute(ENTITY_FIELD, field);
request.setAttribute(ENTITY_COLUMN, column);
request.setAttribute(CreateDiscrepancyNoteServlet.WRITE_TO_DB, writeToDB ? "1" : "0");
ArrayList notes = (ArrayList) dndao.findAllByEntityAndColumn(name, entityId, column);
if (notes.size() > 0) {
notes.get(0);
// @pgawade 21-May-2011 Corrected the condition to throw no access
// error
StudyDAO studyDAO = new StudyDAO(sm.getDataSource());
int parentStudyForNoteSub = 0;
// @pgawade #9801: 07-June-2011 corrected the way to get study
// subject id associated with discrepancy note
// int noteSubId = note.getOwnerId();
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
// StudySubjectBean notessub = (StudySubjectBean)
// ssdao.findByPK(noteSubId);
StudySubjectBean notessub = (StudySubjectBean) ssdao.findByPK(subjectId);
StudyBean studyBeanSub = (StudyBean) studyDAO.findByPK(notessub.getStudyId());
if (null != studyBeanSub) {
parentStudyForNoteSub = studyBeanSub.getParentStudyId();
}
if (notessub.getStudyId() != currentStudy.getId() && currentStudy.getId() != parentStudyForNoteSub) {
addPageMessage(noAccessMessage);
throw new InsufficientPermissionException(Page.MENU_SERVLET, exceptionName, "1");
}
}
FormDiscrepancyNotes newNotes = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
Map<Integer, DiscrepancyNoteBean> noteTree = new LinkedHashMap<Integer, DiscrepancyNoteBean>();
String session_key = eventCRFId + "_" + field;
ArrayList newFieldNotes = null;
if (newNotes != null && (!newNotes.getNotes(field).isEmpty() || !newNotes.getNotes(session_key).isEmpty())) {
newFieldNotes = newNotes.getNotes(field);
if (newFieldNotes == null || newFieldNotes.size() == 0) {
newFieldNotes = newNotes.getNotes(session_key);
}
// System.out.println("how many notes:" + newFieldNotes.size());
for (int i = 0; i < newFieldNotes.size(); i++) {
DiscrepancyNoteBean note = (DiscrepancyNoteBean) newFieldNotes.get(i);
note.setLastUpdator(ub);
note.setLastDateUpdated(new Date());
note.setDisType(DiscrepancyNoteType.get(note.getDiscrepancyNoteTypeId()));
note.setResStatus(ResolutionStatus.get(note.getResolutionStatusId()));
note.setSaved(false);
if (itemId > 0) {
note.setEntityName(item.getName());
note.setEntityValue(itemData.getValue());
}
note.setSubjectName(ssub.getName());
note.setEntityType(name);
int pId = note.getParentDnId();
if (pId == 0) {
// we can only keep one unsaved note because
// note.id == 0
noteTree.put(note.getId(), note);
}
}
for (int i = 0; i < newFieldNotes.size(); i++) {
DiscrepancyNoteBean note = (DiscrepancyNoteBean) newFieldNotes.get(i);
int pId = note.getParentDnId();
if (pId > 0) {
note.setSaved(false);
note.setLastUpdator(ub);
note.setLastDateUpdated(new Date());
note.setEntityName(item.getName());
note.setSubjectName(ssub.getName());
note.setEntityType(name);
note.setDisType(DiscrepancyNoteType.get(note.getDiscrepancyNoteTypeId()));
note.setResStatus(ResolutionStatus.get(note.getResolutionStatusId()));
DiscrepancyNoteBean parent = noteTree.get(new Integer(pId));
if (parent != null) {
parent.getChildren().add(note);
}
}
}
}
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
HashMap<Integer, String> fvcInitAssigns = new HashMap<Integer, String>();
for (int i = 0; i < notes.size(); i++) {
DiscrepancyNoteBean note = (DiscrepancyNoteBean) notes.get(i);
note.setColumn(column);
note.setEntityId(entityId);
note.setEntityType(name);
note.setField(field);
Date lastUpdatedDate = note.getCreatedDate();
UserAccountBean lastUpdator = (UserAccountBean) udao.findByPK(note.getOwnerId());
note.setLastUpdator(lastUpdator);
note.setLastDateUpdated(lastUpdatedDate);
int pId = note.getParentDnId();
note.setDisType(DiscrepancyNoteType.get(note.getDiscrepancyNoteTypeId()));
note.setResStatus(ResolutionStatus.get(note.getResolutionStatusId()));
if (pId == 0) {
noteTree.put(new Integer(note.getId()), note);
}
}
for (int i = 0; i < notes.size(); i++) {
DiscrepancyNoteBean note = (DiscrepancyNoteBean) notes.get(i);
int pId = note.getParentDnId();
if (itemId > 0) {
note.setEntityName(item.getName());
note.setEntityValue(itemData.getValue());
}
note.setSubjectName(ssub.getName());
note.setEntityType(name);
Date lastUpdatedDate = note.getCreatedDate();
UserAccountBean lastUpdator = (UserAccountBean) udao.findByPK(note.getOwnerId());
note.setLastUpdator(lastUpdator);
note.setLastDateUpdated(lastUpdatedDate);
note.setDisType(DiscrepancyNoteType.get(note.getDiscrepancyNoteTypeId()));
note.setResStatus(ResolutionStatus.get(note.getResolutionStatusId()));
if (pId > 0) {
DiscrepancyNoteBean parent = noteTree.get(new Integer(pId));
if (parent != null) {
parent.getChildren().add(note);
if (!note.getCreatedDate().before(parent.getLastDateUpdated())) {
parent.setLastDateUpdated(note.getCreatedDate());
}
if (note.getDiscrepancyNoteTypeId() == 1 && note.getAssignedUserId() > 0) {
int ownerId = note.getOwnerId();
if (fvcInitAssigns.containsKey(pId)) {
String f = fvcInitAssigns.get(pId);
String fn = note.getId() + "." + ownerId;
if (fn.compareTo(f) < 0) {
fvcInitAssigns.put(pId, fn);
}
} else {
fvcInitAssigns.put(pId, note.getId() + "." + ownerId);
}
}
}
}
}
Set parents = noteTree.keySet();
Iterator it = parents.iterator();
while (it.hasNext()) {
Integer key = (Integer) it.next();
DiscrepancyNoteBean note = noteTree.get(key);
note.setNumChildren(note.getChildren().size());
note.setEntityType(name);
if (!boxDNMap.containsKey(key)) {
DiscrepancyNoteBean dn = new DiscrepancyNoteBean();
dn.setId(key);
int dnTypeId = note.getDiscrepancyNoteTypeId();
dn.setDiscrepancyNoteTypeId(dnTypeId);
if (dnTypeId == 3) {
// Query
dn.setAssignedUserId(note.getOwnerId());
} else if (dnTypeId == 1) {
// FVC
if (fvcInitAssigns.containsKey(key)) {
String[] s = fvcInitAssigns.get(key).split("\\.");
int i = Integer.parseInt(s.length == 2 ? s[1].trim() : "0");
dn.setAssignedUserId(i);
}
}
Role r = currentRole.getRole();
// currentStudy.getId() != currentStudy.getParentStudyId()) {
if (r.equals(Role.RESEARCHASSISTANT) || r.equals(Role.RESEARCHASSISTANT2) || r.equals(Role.INVESTIGATOR)) {
if (dn.getDiscrepancyNoteTypeId() == DiscrepancyNoteType.QUERY.getId() && note.getResStatus().getId() == ResolutionStatus.UPDATED.getId()) {
dn.setResolutionStatusId(ResolutionStatus.UPDATED.getId());
} else {
dn.setResolutionStatusId(ResolutionStatus.RESOLVED.getId());
}
if (dn.getAssignedUserId() > 0) {
autoviews.put(key, 1);
} else {
autoviews.put(key, 0);
}
// copied from CreateDiscrepancyNoteServlet
// request.setAttribute("autoView", "0");
// hide the panel, tbh
} else {
if (note.getResStatus().getId() == ResolutionStatus.RESOLVED.getId()) {
dn.setResolutionStatusId(ResolutionStatus.CLOSED.getId());
} else if (note.getResStatus().getId() == ResolutionStatus.CLOSED.getId()) {
dn.setResolutionStatusId(ResolutionStatus.UPDATED.getId());
} else if (r.equals(Role.MONITOR)) {
dn.setResolutionStatusId(ResolutionStatus.UPDATED.getId());
} else if (dn.getDiscrepancyNoteTypeId() == 1) {
dn.setResolutionStatusId(ResolutionStatus.RESOLVED.getId());
} else {
dn.setResolutionStatusId(ResolutionStatus.UPDATED.getId());
}
autoviews.put(key, 1);
if (dn.getAssignedUserId() > 0) {
} else {
dn.setAssignedUserId(preUserId);
}
}
boxDNMap.put(key, dn);
}
}
session.setAttribute(BOX_DN_MAP, boxDNMap);
session.setAttribute(AUTOVIEWS, autoviews);
// noteTree is a Hashmap mapping note id to a parent note, with all the
// child notes
// stored in the children List.
// BWP 3029>>make sure the parent note has an updated resolution status
// and
// updated date
fixStatusUpdatedDate(noteTree);
request.setAttribute(DIS_NOTES, noteTree);
// copied from CreatediscrepancyNoteServlet generateUserAccounts
StudyDAO studyDAO = new StudyDAO(sm.getDataSource());
StudyBean subjectStudy = studyDAO.findByStudySubjectId(subjectId);
int studyId = currentStudy.getId();
ArrayList<UserAccountBean> userAccounts = new ArrayList();
if (currentStudy.getParentStudyId() > 0) {
userAccounts = udao.findAllUsersByStudyOrSite(studyId, currentStudy.getParentStudyId(), subjectId);
} else if (subjectStudy.getParentStudyId() > 0) {
userAccounts = udao.findAllUsersByStudyOrSite(subjectStudy.getId(), subjectStudy.getParentStudyId(), subjectId);
} else {
userAccounts = udao.findAllUsersByStudyOrSite(studyId, 0, subjectId);
}
request.setAttribute(USER_ACCOUNTS, userAccounts);
request.setAttribute(VIEW_DN_LINK, this.getPageServletFileName());
// audit log items (from ViewItemAuditLogServlet.java)
AuditDAO adao = new AuditDAO(sm.getDataSource());
if (name.equalsIgnoreCase("studysub")) {
name = "study_subject";
} else if (name.equalsIgnoreCase("eventcrf")) {
name = "event_crf";
} else if (name.equalsIgnoreCase("studyevent")) {
name = "study_event";
} else if (name.equalsIgnoreCase("itemdata")) {
name = "item_data";
}
ArrayList itemAuditEvents = adao.findItemAuditEvents(entityId, name);
request.setAttribute("itemAudits", itemAuditEvents);
forwardPage(Page.VIEW_DISCREPANCY_NOTE);
}
use of org.akaza.openclinica.bean.submit.SubjectBean in project OpenClinica by OpenClinica.
the class ListStudySubjectTableFactory method setDataAndLimitVariables.
@Override
public void setDataAndLimitVariables(TableFacade tableFacade) {
Limit limit = tableFacade.getLimit();
FindSubjectsFilter subjectFilter = getSubjectFilter(limit);
if (!limit.isComplete()) {
int totalRows = getStudySubjectDAO().getCountWithFilter(subjectFilter, getStudyBean());
tableFacade.setTotalRows(totalRows);
}
FindSubjectsSort subjectSort = getSubjectSort(limit);
int rowStart = limit.getRowSelect().getRowStart();
int rowEnd = limit.getRowSelect().getRowEnd();
Collection<StudySubjectBean> items = getStudySubjectDAO().getWithFilterAndSort(getStudyBean(), subjectFilter, subjectSort, rowStart, rowEnd);
Collection<HashMap<Object, Object>> theItems = new ArrayList<HashMap<Object, Object>>();
for (StudySubjectBean studySubjectBean : items) {
HashMap<Object, Object> theItem = new HashMap<Object, Object>();
theItem.put("studySubject", studySubjectBean);
theItem.put("studySubject.label", studySubjectBean.getLabel());
theItem.put("studySubject.status", studySubjectBean.getStatus());
theItem.put("enrolledAt", ((StudyBean) getStudyDAO().findByPK(studySubjectBean.getStudyId())).getIdentifier());
theItem.put("studySubject.oid", studySubjectBean.getOid());
theItem.put("studySubject.secondaryLabel", studySubjectBean.getSecondaryLabel());
SubjectBean subjectBean = (SubjectBean) getSubjectDAO().findByPK(studySubjectBean.getSubjectId());
theItem.put("subject", subjectBean);
theItem.put("subject.charGender", subjectBean.getGender());
// Get All study events for this study subject and then put list in
// HashMap with study event definition id as
// key and a list of study events as the value.
List<StudyEventBean> allStudyEventsForStudySubject = getStudyEventDAO().findAllByStudySubject(studySubjectBean);
HashMap<Integer, List<StudyEventBean>> allStudyEventsForStudySubjectBySedId = new HashMap<Integer, List<StudyEventBean>>();
theItem.put("isSignable", isSignable(allStudyEventsForStudySubject, studySubjectBean));
for (StudyEventBean studyEventBean : allStudyEventsForStudySubject) {
if (allStudyEventsForStudySubjectBySedId.get(studyEventBean.getStudyEventDefinitionId()) == null) {
ArrayList<StudyEventBean> a = new ArrayList<StudyEventBean>();
a.add(studyEventBean);
allStudyEventsForStudySubjectBySedId.put(studyEventBean.getStudyEventDefinitionId(), a);
} else {
allStudyEventsForStudySubjectBySedId.get(studyEventBean.getStudyEventDefinitionId()).add(studyEventBean);
}
}
SubjectGroupMapBean subjectGroupMapBean;
for (StudyGroupClassBean studyGroupClass : getStudyGroupClasses()) {
subjectGroupMapBean = getSubjectGroupMapDAO().findAllByStudySubjectAndStudyGroupClass(studySubjectBean.getId(), studyGroupClass.getId());
if (null != subjectGroupMapBean) {
theItem.put("sgc_" + studyGroupClass.getId(), subjectGroupMapBean.getStudyGroupId());
theItem.put("grpName_sgc_" + studyGroupClass.getId(), subjectGroupMapBean.getStudyGroupName());
}
}
subjectGroupMapBean = null;
for (StudyEventDefinitionBean studyEventDefinition : getStudyEventDefinitions()) {
List<StudyEventBean> studyEvents = allStudyEventsForStudySubjectBySedId.get(studyEventDefinition.getId());
SubjectEventStatus subjectEventStatus = null;
studyEvents = studyEvents == null ? new ArrayList<StudyEventBean>() : studyEvents;
if (studyEvents.size() < 1) {
subjectEventStatus = SubjectEventStatus.NOT_SCHEDULED;
} else {
for (StudyEventBean studyEventBean : studyEvents) {
if (studyEventBean.getSampleOrdinal() == 1) {
subjectEventStatus = studyEventBean.getSubjectEventStatus();
break;
}
}
}
theItem.put("sed_" + studyEventDefinition.getId(), subjectEventStatus.getId());
theItem.put("sed_" + studyEventDefinition.getId() + "_studyEvents", studyEvents);
theItem.put("sed_" + studyEventDefinition.getId() + "_object", studyEventDefinition);
}
theItems.add(theItem);
}
// Do not forget to set the items back on the tableFacade.
tableFacade.setItems(theItems);
}
Aggregations