use of org.akaza.openclinica.bean.service.StudyParameterValueBean in project OpenClinica by OpenClinica.
the class UpdateStudyServletNew method submitStudy.
private void submitStudy(StudyBean newStudy) {
StudyDAO sdao = new StudyDAO(sm.getDataSource());
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
StudyBean study1 = newStudy;
logger.info("study bean to be updated:" + study1.getName());
study1.setUpdatedDate(new Date());
study1.setUpdater((UserAccountBean) session.getAttribute("userBean"));
sdao.update(study1);
ArrayList siteList = (ArrayList) sdao.findAllByParent(newStudy.getId());
if (siteList.size() > 0) {
sdao.updateSitesStatus(study1);
}
StudyParameterValueBean spv = new StudyParameterValueBean();
spv.setStudyId(study1.getId());
spv.setParameter("collectDob");
spv.setValue(new Integer(study1.getStudyParameterConfig().getCollectDob()).toString());
updateParameter(spvdao, spv);
spv.setParameter("discrepancyManagement");
spv.setValue(study1.getStudyParameterConfig().getDiscrepancyManagement());
updateParameter(spvdao, spv);
spv.setParameter("genderRequired");
spv.setValue(study1.getStudyParameterConfig().getGenderRequired());
updateParameter(spvdao, spv);
spv.setParameter("subjectPersonIdRequired");
spv.setValue(study1.getStudyParameterConfig().getSubjectPersonIdRequired());
updateParameter(spvdao, spv);
spv.setParameter("interviewerNameRequired");
spv.setValue(study1.getStudyParameterConfig().getInterviewerNameRequired());
updateParameter(spvdao, spv);
spv.setParameter("interviewerNameDefault");
spv.setValue(study1.getStudyParameterConfig().getInterviewerNameDefault());
updateParameter(spvdao, spv);
spv.setParameter("interviewerNameEditable");
spv.setValue(study1.getStudyParameterConfig().getInterviewerNameEditable());
updateParameter(spvdao, spv);
// BWP 1/12/2009 3169 Update interviewerNameEditable and
// interviewDateEditable parameters for all sites>>
List<StudyBean> sites = new ArrayList<StudyBean>();
sites = (ArrayList) sdao.findAllByParent(newStudy.getId());
if (sites != null && !sites.isEmpty()) {
updateInterviewerForSites(newStudy, sites, spvdao, "interviewerNameEditable");
}
// >>
spv.setParameter("interviewDateRequired");
spv.setValue(study1.getStudyParameterConfig().getInterviewDateRequired());
updateParameter(spvdao, spv);
spv.setParameter("interviewDateDefault");
spv.setValue(study1.getStudyParameterConfig().getInterviewDateDefault());
updateParameter(spvdao, spv);
spv.setParameter("interviewDateEditable");
spv.setValue(study1.getStudyParameterConfig().getInterviewDateEditable());
updateParameter(spvdao, spv);
// BWP 1/12/2009 3169>>
if (sites != null && !sites.isEmpty()) {
updateInterviewerForSites(newStudy, sites, spvdao, "interviewDateEditable");
}
// >>
spv.setParameter("subjectIdGeneration");
spv.setValue(study1.getStudyParameterConfig().getSubjectIdGeneration());
updateParameter(spvdao, spv);
spv.setParameter("subjectIdPrefixSuffix");
spv.setValue(study1.getStudyParameterConfig().getSubjectIdPrefixSuffix());
updateParameter(spvdao, spv);
spv.setParameter("personIdShownOnCRF");
spv.setValue(study1.getStudyParameterConfig().getPersonIdShownOnCRF());
updateParameter(spvdao, spv);
spv.setParameter("secondaryLabelViewable");
spv.setValue(study1.getStudyParameterConfig().getSecondaryLabelViewable());
updateParameter(spvdao, spv);
// tbh, 06/04/2009 3684>>
spv.setParameter("adminForcedReasonForChange");
spv.setValue(study1.getStudyParameterConfig().getAdminForcedReasonForChange());
updateParameter(spvdao, spv);
// >>
// AH 08/26/2010 5732
spv.setParameter("eventLocationRequired");
spv.setValue(study1.getStudyParameterConfig().getEventLocationRequired());
updateParameter(spvdao, spv);
StudyBean curStudy = (StudyBean) session.getAttribute("study");
if (curStudy != null && study1.getId() == curStudy.getId()) {
super.currentStudy = study1;
session.setAttribute("study", study1);
}
// update manage_pedigrees for all sites
ArrayList children = (ArrayList) sdao.findAllByParent(study1.getId());
for (int i = 0; i < children.size(); i++) {
StudyBean child = (StudyBean) children.get(i);
// same as parent's type
child.setType(study1.getType());
child.setUpdatedDate(new Date());
child.setUpdater(ub);
sdao.update(child);
// YW << update "collectDob" and "genderRequired" for sites
StudyParameterValueBean childspv = new StudyParameterValueBean();
childspv.setStudyId(child.getId());
childspv.setParameter("collectDob");
childspv.setValue(new Integer(study1.getStudyParameterConfig().getCollectDob()).toString());
updateParameter(spvdao, childspv);
childspv.setParameter("genderRequired");
childspv.setValue(study1.getStudyParameterConfig().getGenderRequired());
updateParameter(spvdao, childspv);
}
}
use of org.akaza.openclinica.bean.service.StudyParameterValueBean in project OpenClinica by OpenClinica.
the class UpdateStudyServletNew method updateParameter.
private void updateParameter(StudyParameterValueDAO spvdao, StudyParameterValueBean spv) {
StudyParameterValueBean spv1 = spvdao.findByHandleAndStudy(spv.getStudyId(), spv.getParameter());
logger.debug("found parameter: " + spv.getParameter());
if (spv1.getId() > 0) {
spvdao.update(spv);
logger.debug("updating");
} else {
spvdao.create(spv);
logger.debug("creating");
}
}
use of org.akaza.openclinica.bean.service.StudyParameterValueBean in project OpenClinica by OpenClinica.
the class UpdateStudyServletNew method updateInterviewerForSites.
private void updateInterviewerForSites(StudyBean studyBean, List<StudyBean> sites, StudyParameterValueDAO studyParameterValueDAO, String parameterType) {
StudyParameterValueBean studyParameterValueBean = new StudyParameterValueBean();
if ("interviewerNameEditable".equalsIgnoreCase(parameterType)) {
studyParameterValueBean.setParameter("interviewerNameEditable");
studyParameterValueBean.setValue(studyBean.getStudyParameterConfig().getInterviewerNameEditable());
} else {
studyParameterValueBean.setParameter("interviewDateEditable");
studyParameterValueBean.setValue(studyBean.getStudyParameterConfig().getInterviewDateEditable());
}
for (StudyBean siteBean : sites) {
studyParameterValueBean.setStudyId(siteBean.getId());
updateParameter(studyParameterValueDAO, studyParameterValueBean);
}
}
use of org.akaza.openclinica.bean.service.StudyParameterValueBean in project OpenClinica by OpenClinica.
the class UpdateStudyServlet method submitStudy.
private void submitStudy() {
StudyDAO sdao = new StudyDAO(sm.getDataSource());
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
StudyBean study1 = (StudyBean) session.getAttribute("newStudy");
logger.info("study bean to be updated:" + study1.getName());
study1.setUpdatedDate(new Date());
study1.setUpdater((UserAccountBean) session.getAttribute("userBean"));
logger.debug("study's parentId=" + study1.getParentStudyId());
sdao.update(study1);
StudyParameterValueBean spv = new StudyParameterValueBean();
spv.setStudyId(study1.getId());
spv.setParameter("collectDob");
spv.setValue(new Integer(study1.getStudyParameterConfig().getCollectDob()).toString());
updateParameter(spvdao, spv);
spv.setParameter("discrepancyManagement");
spv.setValue(study1.getStudyParameterConfig().getDiscrepancyManagement());
updateParameter(spvdao, spv);
spv.setParameter("genderRequired");
spv.setValue(study1.getStudyParameterConfig().getGenderRequired());
updateParameter(spvdao, spv);
spv.setParameter("subjectPersonIdRequired");
spv.setValue(study1.getStudyParameterConfig().getSubjectPersonIdRequired());
updateParameter(spvdao, spv);
spv.setParameter("interviewerNameRequired");
spv.setValue(study1.getStudyParameterConfig().getInterviewerNameRequired());
updateParameter(spvdao, spv);
spv.setParameter("interviewerNameDefault");
spv.setValue(study1.getStudyParameterConfig().getInterviewerNameDefault());
updateParameter(spvdao, spv);
spv.setParameter("interviewerNameEditable");
spv.setValue(study1.getStudyParameterConfig().getInterviewerNameEditable());
updateParameter(spvdao, spv);
spv.setParameter("interviewDateRequired");
spv.setValue(study1.getStudyParameterConfig().getInterviewDateRequired());
updateParameter(spvdao, spv);
spv.setParameter("interviewDateDefault");
spv.setValue(study1.getStudyParameterConfig().getInterviewDateDefault());
updateParameter(spvdao, spv);
spv.setParameter("interviewDateEditable");
spv.setValue(study1.getStudyParameterConfig().getInterviewDateEditable());
updateParameter(spvdao, spv);
spv.setParameter("subjectIdGeneration");
spv.setValue(study1.getStudyParameterConfig().getSubjectIdGeneration());
updateParameter(spvdao, spv);
spv.setParameter("subjectIdPrefixSuffix");
spv.setValue(study1.getStudyParameterConfig().getSubjectIdPrefixSuffix());
updateParameter(spvdao, spv);
spv.setParameter("personIdShownOnCRF");
spv.setValue(study1.getStudyParameterConfig().getPersonIdShownOnCRF());
updateParameter(spvdao, spv);
StudyBean curStudy = (StudyBean) session.getAttribute("study");
if (curStudy != null && study1.getId() == curStudy.getId()) {
super.currentStudy = study1;
session.setAttribute("study", study1);
}
// update manage_pedigrees for all sites
ArrayList children = (ArrayList) sdao.findAllByParent(study1.getId());
for (int i = 0; i < children.size(); i++) {
StudyBean child = (StudyBean) children.get(i);
// same as parent's type
child.setType(study1.getType());
child.setUpdatedDate(new Date());
child.setUpdater(ub);
sdao.update(child);
// YW << update "collectDob" and "genderRequired" for sites
StudyParameterValueBean childspv = new StudyParameterValueBean();
childspv.setStudyId(child.getId());
childspv.setParameter("collectDob");
childspv.setValue(new Integer(study1.getStudyParameterConfig().getCollectDob()).toString());
updateParameter(spvdao, childspv);
childspv.setParameter("genderRequired");
childspv.setValue(study1.getStudyParameterConfig().getGenderRequired());
updateParameter(spvdao, childspv);
// YW >>
}
session.removeAttribute("newStudy");
session.removeAttribute("interventions");
}
use of org.akaza.openclinica.bean.service.StudyParameterValueBean in project OpenClinica by OpenClinica.
the class SubjectTransferValidator method validate.
@Override
public void validate(Object obj, Errors e) {
SubjectTransferBean subjectTransferBean = (SubjectTransferBean) obj;
if (subjectTransferBean.getStudyOid() == null) {
e.reject("studyEventTransferValidator.study_does_not_exist");
return;
}
Status[] included_status = new Status[] { Status.AVAILABLE };
StudyBean study = helper.verifyStudy(getStudyDAO(), subjectTransferBean.getStudyOid(), included_status, e);
if (study == null)
return;
StudyBean site = null;
int site_id = -1;
subjectTransferBean.setStudy(study);
if (subjectTransferBean.getSiteIdentifier() != null) {
site = helper.verifySite(getStudyDAO(), subjectTransferBean.getStudyOid(), subjectTransferBean.getSiteIdentifier(), included_status, e);
if (site == null) {
return;
}
site_id = site.getId();
subjectTransferBean.setStudy(site);
}
boolean isRoleVerified = helper.verifyRole(subjectTransferBean.getOwner(), study.getId(), site_id, Role.MONITOR, e);
if (!isRoleVerified) {
return;
}
// StudyBean study = null;
// if ( subjectTransferBean.getStudyOid() != null)
// {
// study = getStudyDAO().findByUniqueIdentifier(subjectTransferBean.getStudyOid());
// if (study == null) {
// e.reject("subjectTransferValidator.study_does_not_exist", new Object[] { subjectTransferBean.getStudyOid() }, "Study identifier you specified "
// + subjectTransferBean.getStudyOid() + " does not correspond to a valid study.");
// return;
// }
// //validate study status
// if (study != null && !study.getStatus().isAvailable()) {
// e.reject("subjectTransferValidator.study_status_wrong", new Object[] { subjectTransferBean.getStudyOid() }, "Study "
// + subjectTransferBean.getStudyOid() +" has wrong status. Subject can be added to an 'AVAILABLE' study only.");
// return;
// }
// subjectTransferBean.setStudy(study);
// }
// UserAccountBean ua = subjectTransferBean.getOwner();
// StudyUserRoleBean role = ua.getRoleByStudy(subjectTransferBean.getStudy());
// if (role.getId() == 0 || role.getRole().equals(Role.MONITOR)) {
// e.reject("subjectTransferValidator.insufficient_permissions", "You do not have sufficient privileges to proceed with this operation.");
// return;
// }
// StudyBean site = null;
// if (subjectTransferBean.getSiteIdentifier() != null) {
// site = getStudyDAO().findSiteByUniqueIdentifier(subjectTransferBean.getStudyOid(), subjectTransferBean.getSiteIdentifier());
// if (site == null) {
// e.reject("subjectTransferValidator.site_does_not_exist", new Object[] { subjectTransferBean.getSiteIdentifier() },
// "Site identifier you specified does not correspond to a valid site.");
// return;
// }
// //validate site status
// if ( ! site.getStatus().isAvailable()) {
//
// e.reject("subjectTransferValidator.site_status_wrong", new Object[] { subjectTransferBean.getSiteIdentifier() }, "Site "
// + site.getName() +" has wrong status. Subject can be added to an 'AVAILABLE' site only.");
// return;
// }
// subjectTransferBean.setStudy(site);//???????????
// }
// role = ua.getRoleByStudy(site);
// if (role.getId() == 0 || role.getRole().equals(Role.MONITOR)) {
// e.reject("subjectTransferValidator.insufficient_permissions", "You do not have sufficient privileges to proceed with this operation.");
// return;
// }
//
int handleStudyId = study.getParentStudyId() > 0 ? study.getParentStudyId() : study.getId();
StudyParameterValueBean studyParameter = getStudyParameterValueDAO().findByHandleAndStudy(handleStudyId, "subjectPersonIdRequired");
String personId = subjectTransferBean.getPersonId();
if (personId.contains("<") || personId.contains(">")) {
e.reject("subjectTransferValidator.person_id_can_not_contain_html_lessthan_or_greaterthan_elements");
return;
}
if ("required".equals(studyParameter.getValue()) && (personId == null || personId.length() < 1)) {
e.reject("subjectTransferValidator.personId_required", new Object[] { study.getName() }, "personId is required for the study: " + study.getName());
return;
}
if ("not used".equals(studyParameter.getValue()) && !(personId == null || personId.length() < 1)) {
e.reject("subjectTransferValidator.personId_not_used", new Object[] { study.getName() }, "personId is not used for the study: " + study.getName());
return;
}
if (personId != null && personId.length() > 255) {
e.reject("subjectTransferValidator.personId_invalid_length", new Object[] { personId }, "personId: " + personId + " cannot be longer than 255 characters.");
return;
}
// verify that personId is unique
if (subjectTransferBean.getPersonId() != null && subjectTransferBean.getPersonId().length() > 0) {
// SubjectBean subjectWithSamePersonId = getSubjectDao().findByUniqueIdentifierAndStudy( subjectTransferBean.getPersonId(), study.getId());
SubjectBean subjectWithSamePersonId = getSubjectDao().findByUniqueIdentifierAndAnyStudy(subjectTransferBean.getPersonId(), study.getId());
if (subjectWithSamePersonId.getId() != 0) {
e.reject("subjectTransferValidator.personId_duplicated", new Object[] { personId }, "A subject with the Person ID: " + personId + " is already enrolled in this study. ");
return;
}
}
StudyParameterValueBean subjectIdGenerationParameter = getStudyParameterValueDAO().findByHandleAndStudy(handleStudyId, "subjectIdGeneration");
String idSetting = subjectIdGenerationParameter.getValue();
if (!(idSetting.equals("auto editable") || idSetting.equals("auto non-editable"))) {
String studySubjectId = subjectTransferBean.getStudySubjectId();
if (studySubjectId == null || studySubjectId.length() < 1) {
e.reject("subjectTransferValidator.studySubjectId_required");
return;
} else if (studySubjectId.length() > 30) {
e.reject("subjectTransferValidator.studySubjectId_invalid_length", new Object[] { studySubjectId }, "studySubjectId: " + studySubjectId + " cannot be longer than 30 characters.");
return;
} else {
// checks whether there is a subject with same id inside current study
StudySubjectBean subjectWithSame = getStudySubjectDAO().findByLabelAndStudy(studySubjectId, study);
if (subjectWithSame.getLabel().equals(studySubjectId)) {
e.reject("subjectTransferValidator.subject_duplicated_label", new Object[] { studySubjectId, study.getIdentifier() }, "studySubjectId: " + studySubjectId + " already exists for " + study.getIdentifier() + " study .");
return;
}
}
if (studySubjectId.contains("<") || studySubjectId.contains(">")) {
e.reject("subjectTransferValidator.study_subject_id_can_not_contain_html_lessthan_or_greaterthan_elements");
return;
}
}
String secondaryId = subjectTransferBean.getSecondaryId();
if (secondaryId != null && secondaryId.length() > 30) {
e.reject("subjectTransferValidator.secondaryId_invalid_length", new Object[] { secondaryId }, "secondaryId: " + secondaryId + " cannot be longer than 30 characters.");
return;
}
if (secondaryId.contains("<") || secondaryId.contains(">")) {
e.reject("subjectTransferValidator.secondary_id_can_not_contain_html_lessthan_or_greaterthan_elements");
return;
}
String gender = String.valueOf(subjectTransferBean.getGender());
studyParameter = getStudyParameterValueDAO().findByHandleAndStudy(handleStudyId, "genderRequired");
if ("true".equals(studyParameter.getValue())) {
if (gender == null || gender.length() < 1) {
e.reject("subjectTransferValidator.gender_required", new Object[] { study.getName() }, "Gender is required for the study: " + study.getName());
return;
}
if (!"m".equals(gender) && !"f".equals(gender)) {
e.reject("subjectTransferValidator.gender_is_m_or_f");
return;
}
} else {
if (gender.trim().length() > 0 && !("m".equals(gender) || "f".equals(gender))) {
e.reject("subjectTransferValidator.gender_is_m_or_f");
return;
}
}
Date dateOfBirth = subjectTransferBean.getDateOfBirth();
String yearOfBirth = subjectTransferBean.getYearOfBirth();
studyParameter = getStudyParameterValueDAO().findByHandleAndStudy(handleStudyId, "collectDob");
if ("1".equals(studyParameter.getValue()) && (dateOfBirth == null)) {
e.reject("subjectTransferValidator.dateOfBirth_required", new Object[] { study.getName() }, "Date of birth is required for the study " + study.getName());
return;
} else if ("2".equals(studyParameter.getValue()) && (yearOfBirth == null)) {
e.reject("subjectTransferValidator.yearOfBirth_required", new Object[] { study.getName() }, "Year of birth is required for the study " + study.getName());
return;
} else if ("2".equals(studyParameter.getValue()) && (yearOfBirth != null)) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
subjectTransferBean.setDateOfBirth(sdf.parse(subjectTransferBean.getYearOfBirth()));
} catch (ParseException xe) {
e.reject("subjectTransferValidator.yearOfBirth_invalid", new Object[] { yearOfBirth }, "Year of birth: " + yearOfBirth + " is not valid");
return;
}
//not used
} else if ("3".equals(studyParameter.getValue())) {
if (dateOfBirth != null || !(yearOfBirth == null || yearOfBirth.length() < 1)) {
e.reject("subjectTransferValidator.date_of_birth_notused", new Object[] { study.getName() }, "Date of Birth is not used for the study " + study.getName());
return;
}
}
Date enrollmentDate = subjectTransferBean.getEnrollmentDate();
if (enrollmentDate == null) {
e.reject("subjectTransferValidator.enrollmentDate_required");
return;
} else {
if ((new Date()).compareTo(enrollmentDate) < 0) {
e.reject("subjectTransferValidator.enrollmentDate_should_be_in_past");
return;
}
}
}
Aggregations