use of org.akaza.openclinica.bean.managestudy.StudyBean in project OpenClinica by OpenClinica.
the class RandomizeService method getStudy.
private StudyBean getStudy(String oid) {
sdao = new StudyDAO(ds);
StudyBean studyBean = (StudyBean) sdao.findByOid(oid);
return studyBean;
}
use of org.akaza.openclinica.bean.managestudy.StudyBean in project OpenClinica by OpenClinica.
the class OdmImportServiceImpl method saveOrUpdateCrfAndFormLayouts.
private void saveOrUpdateCrfAndFormLayouts(String crfOid, List<OCodmComplexTypeDefinitionFormLayoutDef> formLayoutDefs, Form[] fmCrfs, UserAccount userAccount, Study study, String crfName) {
DataBinder dataBinder = new DataBinder(new FormLayout());
Errors errors = dataBinder.getBindingResult();
StudyBean currentStudy = new StudyBean();
currentStudy.setId(study.getStudyId());
UserAccountBean ub = new UserAccountBean();
ub.setId(userAccount.getUserId());
ub.setActiveStudyId(currentStudy.getId());
for (Form crf : fmCrfs) {
if (crf.getOcoid().equals(crfOid)) {
ExecuteIndividualCrfObject eicObj = new ExecuteIndividualCrfObject(crf, formLayoutDefs, errors, currentStudy, ub, true, null);
xformService.executeIndividualCrf(eicObj);
}
}
}
use of org.akaza.openclinica.bean.managestudy.StudyBean in project OpenClinica by OpenClinica.
the class SubjectTransferValidator method validate.
public void validate(Object obj, Errors e) {
SubjectTransferBean subjectTransferBean = (SubjectTransferBean) obj;
StudyBean 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;
}
UserAccountBean ua = subjectTransferBean.getOwner();
StudyUserRoleBean role = ua.getRoleByStudy(study);
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;
}
if (subjectTransferBean.getSiteIdentifier() != null) {
study = getStudyDAO().findSiteByUniqueIdentifier(subjectTransferBean.getStudyOid(), subjectTransferBean.getSiteIdentifier());
}
subjectTransferBean.setStudy(study);
if (study == null) {
e.reject("subjectTransferValidator.site_does_not_exist", new Object[] { subjectTransferBean.getSiteIdentifier() }, "Site identifier you specified does not correspond to a valid site.");
return;
}
int handleStudyId = study.getParentStudyId() > 0 ? study.getParentStudyId() : study.getId();
StudyParameterValueBean studyParameter = getStudyParameterValueDAO().findByHandleAndStudy(handleStudyId, "subjectPersonIdRequired");
String personId = subjectTransferBean.getPersonId();
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 (personId != null && personId.length() > 255) {
e.reject("subjectTransferValidator.personId_invalid_length", new Object[] { personId }, "personId: " + personId + " cannot be longer than 255 characters.");
return;
}
String idSetting = "";
StudyParameterValueBean subjectIdGenerationParameter = getStudyParameterValueDAO().findByHandleAndStudy(handleStudyId, "subjectIdGeneration");
idSetting = subjectIdGenerationParameter.getValue();
if (idSetting.equals("auto editable") || idSetting.equals("auto non-editable")) {
int nextLabel = getStudySubjectDAO().findTheGreatestLabel() + 1;
subjectTransferBean.setStudySubjectId(new Integer(nextLabel).toString());
}
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;
}
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;
}
String gender = subjectTransferBean.getGender() + "";
studyParameter = getStudyParameterValueDAO().findByHandleAndStudy(handleStudyId, "genderRequired");
if ("true".equals(studyParameter.getValue()) && (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");
//e.reject("subjectTransferValidator.gender_required", new Object[] { study.getName() }, "Gender is required to be '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;
}
}
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;
}
}
}
use of org.akaza.openclinica.bean.managestudy.StudyBean in project OpenClinica by OpenClinica.
the class EventActionValidator method isEventActionValueExpressionValid.
private boolean isEventActionValueExpressionValid(PropertyBean property, AuditableBeanWrapper<RuleSetBean> ruleSetBeanWrapper) {
StudyDAO studyDAO = new StudyDAO<String, ArrayList>(getDataSource());
StudyBean study = (StudyBean) studyDAO.findByPK(ruleSetBeanWrapper.getAuditableBean().getStudyId());
ExpressionBean expressionBean = isExpressionValid(property.getValueExpression(), ruleSetBeanWrapper);
ExpressionObjectWrapper eow = new ExpressionObjectWrapper(dataSource, study, expressionBean, ruleSetBeanWrapper.getAuditableBean(), ExpressionObjectWrapper.CONTEXT_VALUE_EXPRESSION);
ExpressionProcessor ep = ExpressionProcessorFactory.createExpressionProcessor(eow);
ep.setRespage(respage);
String errorString = ep.isRuleExpressionValid();
if (errorString != null) {
ruleSetBeanWrapper.error(errorString);
return false;
}
//Verify expression generates a valid date string.
try {
SimpleDateFormat df = new SimpleDateFormat(VALUE_EXPRESSION_DATE_FORMAT);
df.setLenient(false);
String valueExpression = ep.testEvaluateExpression();
Date valueExpressionDate = df.parse(valueExpression);
// date that was entered, if it's not, we assume that the date is invalid
if (!df.format(valueExpressionDate).equals(valueExpression)) {
return false;
}
} catch (ParseException ex) {
return false;
}
return true;
}
use of org.akaza.openclinica.bean.managestudy.StudyBean in project OpenClinica by OpenClinica.
the class ExpressionService method getStudyEventDefinitionFromExpressionForEventScheduling.
public StudyEventDefinitionBean getStudyEventDefinitionFromExpressionForEventScheduling(String expression, boolean onlyOID) {
StudyBean study = expressionWrapper.getStudyBean();
String studyEventDefinitionKey;
if (onlyOID)
studyEventDefinitionKey = expression.replaceAll(BRACKETS_AND_CONTENTS, "");
else
studyEventDefinitionKey = getOidFromExpression(expression, 1, 1).replaceAll(BRACKETS_AND_CONTENTS, "");
logger.debug("Expression : {} , Study Event Definition OID {} , Study Bean {} ", new Object[] { expression, studyEventDefinitionKey, study != null ? study.getId() : null });
if (studyEventDefinitions.get(studyEventDefinitionKey) != null) {
return studyEventDefinitions.get(studyEventDefinitionKey);
} else {
StudyEventDefinitionBean studyEventDefinition = getStudyEventDefinitionDao().findByOid(studyEventDefinitionKey);
// findByOidAndStudy method, tbh
if (studyEventDefinition != null) {
studyEventDefinitions.put(studyEventDefinitionKey, studyEventDefinition);
return studyEventDefinition;
} else {
return null;
}
}
}
Aggregations