Search in sources :

Example 36 with StudyBean

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;
}
Also used : StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Example 37 with 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);
        }
    }
}
Also used : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) Errors(org.springframework.validation.Errors) ExecuteIndividualCrfObject(org.akaza.openclinica.service.crfdata.ExecuteIndividualCrfObject) Form(org.akaza.openclinica.service.dto.Form) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) DataBinder(org.springframework.validation.DataBinder)

Example 38 with StudyBean

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;
        }
    }
}
Also used : StudyParameterValueBean(org.akaza.openclinica.bean.service.StudyParameterValueBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) ParseException(java.text.ParseException) SubjectTransferBean(org.akaza.openclinica.bean.managestudy.SubjectTransferBean) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 39 with StudyBean

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;
}
Also used : ExpressionProcessor(org.akaza.openclinica.domain.rule.expression.ExpressionProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ExpressionObjectWrapper(org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper) ParseException(java.text.ParseException) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) SimpleDateFormat(java.text.SimpleDateFormat) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean) Date(java.util.Date)

Example 40 with StudyBean

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;
        }
    }
}
Also used : StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)

Aggregations

StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)350 ArrayList (java.util.ArrayList)183 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)175 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)92 HashMap (java.util.HashMap)84 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)66 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)65 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)62 Date (java.util.Date)59 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)58 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)57 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)56 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)54 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)52 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)52 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)45 Locale (java.util.Locale)39 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)39 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)37 Iterator (java.util.Iterator)36