Search in sources :

Example 1 with StudyUserRole

use of org.akaza.openclinica.domain.datamap.StudyUserRole in project OpenClinica by OpenClinica.

the class UserProcessor method process.

@Override
public void process(SubmissionContainer container) throws Exception {
    logger.info("Executing User Processor.");
    Errors errors = container.getErrors();
    String contextStudySubjectOid = container.getSubjectContext().get("studySubjectOID");
    String studySubjectOid = container.getSubject().getOcOid();
    String parentStudyOid = getParentStudy(container.getStudy().getOc_oid()).getOc_oid();
    // if study subject oid is not null, just look up user account
    if (contextStudySubjectOid != null) {
        String userName = parentStudyOid + "." + contextStudySubjectOid;
        UserAccount existingAccount = userAccountDao.findByUserName(userName);
        if (existingAccount == null) {
            logger.info("Could not find existing user account.  Aborting submission.");
            errors.reject("Could not find existing user account.  Aborting submission.");
            throw new Exception("Could not find existing user account.  Aborting submission.");
        }
        container.setUser(existingAccount);
    } else {
        String userName = parentStudyOid + "." + studySubjectOid;
        UserAccount existingAccount = userAccountDao.findByUserName(userName);
        if (existingAccount != null) {
            container.setUser(existingAccount);
            ;
        } else {
            // Create user account
            UserAccount rootUser = userAccountDao.findByUserId(1);
            UserAccount createdUser = new UserAccount();
            createdUser.setUserName(parentStudyOid + "." + container.getSubject().getOcOid());
            createdUser.setFirstName(INPUT_FIRST_NAME);
            createdUser.setLastName(INPUT_LAST_NAME);
            createdUser.setEmail(INPUT_EMAIL);
            createdUser.setInstitutionalAffiliation(INPUT_INSTITUTION);
            createdUser.setActiveStudy(container.getStudy());
            String passwordHash = UserAccountBean.LDAP_PASSWORD;
            createdUser.setPasswd(passwordHash);
            createdUser.setPasswdTimestamp(null);
            createdUser.setDateLastvisit(null);
            createdUser.setStatus(Status.DELETED);
            createdUser.setPasswdChallengeQuestion("");
            createdUser.setPasswdChallengeAnswer("");
            createdUser.setPhone("");
            createdUser.setUserAccount(rootUser);
            createdUser.setRunWebservices(false);
            createdUser.setActiveStudy(container.getStudy());
            UserType type = userTypeDao.findByUserTypeId(2);
            createdUser.setUserType(type);
            createdUser.setEnabled(true);
            createdUser.setAccountNonLocked(true);
            createdUser.setAccessCode("");
            createdUser.setApiKey("");
            createdUser = userAccountDao.saveOrUpdate(createdUser);
            container.setUser(createdUser);
            // Create study user role
            Date date = new Date();
            StudyUserRoleId studyUserRoleId = new StudyUserRoleId(Role.RESEARCHASSISTANT2.getName(), container.getStudy().getStudyId(), Status.AUTO_DELETED.getCode(), rootUser.getUserId(), date, createdUser.getUserName());
            StudyUserRole studyUserRole = new StudyUserRole(studyUserRoleId);
            studyUserRoleDao.saveOrUpdate(studyUserRole);
        // TODO: StudyUserRole object had to be heavily modified.  May need fixing.  Also roleName specified
        // doesn't exist in role table.  May need to fix that.
        // This table should also foreign key to user_account but doesn't.
        }
    }
}
Also used : Errors(org.springframework.validation.Errors) StudyUserRole(org.akaza.openclinica.domain.datamap.StudyUserRole) UserAccount(org.akaza.openclinica.domain.user.UserAccount) UserType(org.akaza.openclinica.domain.user.UserType) Date(java.util.Date) StudyUserRoleId(org.akaza.openclinica.domain.datamap.StudyUserRoleId)

Example 2 with StudyUserRole

use of org.akaza.openclinica.domain.datamap.StudyUserRole in project OpenClinica by OpenClinica.

the class OdmImportServiceImpl method importOdmToOC.

@Transactional
public void importOdmToOC(ODM odm) {
    UserAccount userAccount = getCurrentUser();
    // TODO add validation to all entities
    ODMcomplexTypeDefinitionStudy odmStudy = odm.getStudy().get(0);
    Study study = saveOrUpdateStudy(odm, userAccount, odmStudy);
    ParticipantPortalRegistrar portal = new ParticipantPortalRegistrar();
    portal.registerStudy(study.getOc_oid(), study.getOc_oid(), study.getName());
    StudyParameterValue spv = getStudyParameterValueDao().findByStudyIdParameter(study.getStudyId(), "participantPortal");
    // Update OC Study configuration
    if (spv == null) {
        spv = new StudyParameterValue();
        spv.setStudy(study);
    }
    spv.setValue("enabled");
    spv = getStudyParameterValueDao().saveOrUpdate(spv);
    StudyUserRole studyUserRole = null;
    StudyUserRoleId studyUserRoleId = null;
    Form[] fmCrfs = getAllCrfsByProtIdFromFormManager(study);
    ArrayList<StudyUserRole> surRoles = getStudyUserRoleDao().findAllUserRolesByUserAccount(userAccount, study.getStudyId(), study.getStudyId());
    if (surRoles.size() == 0) {
        studyUserRoleId = new StudyUserRoleId();
        studyUserRole = new StudyUserRole();
        studyUserRole = getStudyUserRoleDao().saveOrUpdate(populateUserRole(study, userAccount, studyUserRole, studyUserRoleId));
    }
    StudyEventDefinition studyEventDefinition = null;
    List<ODMcomplexTypeDefinitionMetaDataVersion> odmMetadataVersions = odmStudy.getMetaDataVersion();
    List<ODMcomplexTypeDefinitionStudyEventDef> odmStudyEventDefs = saveOrUpdateEvent(userAccount, study, odmMetadataVersions);
    CrfBean crf = null;
    FormLayout formLayout = null;
    saveOrUpdateCrf(userAccount, study, odmMetadataVersions, fmCrfs);
    List<ODMcomplexTypeDefinitionStudyEventRef> odmStudyEventRefs = odmMetadataVersions.get(0).getProtocol().getStudyEventRef();
    for (ODMcomplexTypeDefinitionStudyEventRef odmStudyEventRef : odmStudyEventRefs) {
        for (ODMcomplexTypeDefinitionStudyEventDef odmStudyEventDef : odmStudyEventDefs) {
            if (odmStudyEventDef.getOID().equals(odmStudyEventRef.getStudyEventOID())) {
                studyEventDefinition = getStudyEventDefDao().findByOcOID(odmStudyEventDef.getOID());
                studyEventDefinition.setOrdinal(odmStudyEventRef.getOrderNumber().intValue());
                studyEventDefinition = getStudyEventDefDao().saveOrUpdate(studyEventDefinition);
                List<EventDefinitionCrf> jsonEventDefCrfList = new ArrayList<>();
                EventDefinitionCrf eventDefinitionCrf = null;
                for (ODMcomplexTypeDefinitionFormRef odmFormRef : odmStudyEventDef.getFormRef()) {
                    crf = getCrfDao().findByOcOID(odmFormRef.getFormOID());
                    eventDefinitionCrf = getEventDefinitionCrfDao().findByStudyEventDefinitionIdAndCRFIdAndStudyId(studyEventDefinition.getStudyEventDefinitionId(), crf.getCrfId(), study.getStudyId());
                    String defaultVersionName = null;
                    OCodmComplexTypeDefinitionConfigurationParameters conf = odmFormRef.getConfigurationParameters();
                    List<OCodmComplexTypeDefinitionFormLayoutRef> formLayoutRefs = odmFormRef.getFormLayoutRef();
                    if (formLayoutRefs.size() == 1 && formLayoutRefs.get(0).getIsDefaultVersion() == null) {
                        defaultVersionName = formLayoutRefs.get(0).getOID();
                    } else {
                        for (OCodmComplexTypeDefinitionFormLayoutRef formLayoutRef : formLayoutRefs) {
                            if (formLayoutRef.getIsDefaultVersion().equalsIgnoreCase("Yes")) {
                                defaultVersionName = formLayoutRef.getOID();
                            }
                        }
                    }
                    if (defaultVersionName == null) {
                        defaultVersionName = formLayoutRefs.get(0).getOID();
                    }
                    formLayout = getFormLayoutDao().findByNameCrfId(defaultVersionName, crf.getCrfId());
                    EventDefinitionCrfDTO edcObj = new EventDefinitionCrfDTO();
                    edcObj.setUserAccount(userAccount);
                    edcObj.setConf(conf);
                    edcObj.setCrf(crf);
                    edcObj.setEventDefinitionCrf(eventDefinitionCrf);
                    edcObj.setOdmFormRef(odmFormRef);
                    edcObj.setStudy(study);
                    edcObj.setFormLayout(formLayout);
                    edcObj.setStudyEventDefinition(studyEventDefinition);
                    EDCTagDTO populateEDCTagParameter = new EDCTagDTO();
                    populateEDCTagParameter.setConf(conf);
                    populateEDCTagParameter.setConf(conf);
                    populateEDCTagParameter.setEventDefinitionCrf(eventDefinitionCrf);
                    populateEDCTagParameter.setUserAccount(userAccount);
                    eventDefinitionCrf = saveOrUpdateEventDefnCrf(new EventDefinitionCrfDTO(edcObj));
                    saveOrUpdateEDCTag(new EDCTagDTO(populateEDCTagParameter), studyEventDefinition, crf);
                    jsonEventDefCrfList.add(eventDefinitionCrf);
                }
                List<EventDefinitionCrf> ocEventDefCrfList = getEventDefinitionCrfDao().findAvailableByStudyEventDefStudy(studyEventDefinition.getStudyEventDefinitionId(), study.getStudyId());
                for (EventDefinitionCrf ocEventDefCrf : ocEventDefCrfList) {
                    if (!jsonEventDefCrfList.contains(ocEventDefCrf)) {
                        ocEventDefCrf.setStatusId(Status.DELETED.getCode());
                        getEventDefinitionCrfDao().saveOrUpdate(ocEventDefCrf);
                    }
                }
            }
        }
    }
}
Also used : CrfBean(org.akaza.openclinica.domain.datamap.CrfBean) Form(org.akaza.openclinica.service.dto.Form) ArrayList(java.util.ArrayList) ODMcomplexTypeDefinitionStudy(org.cdisc.ns.odm.v130.ODMcomplexTypeDefinitionStudy) EventDefinitionCrf(org.akaza.openclinica.domain.datamap.EventDefinitionCrf) ODMcomplexTypeDefinitionMetaDataVersion(org.cdisc.ns.odm.v130.ODMcomplexTypeDefinitionMetaDataVersion) StudyUserRole(org.akaza.openclinica.domain.datamap.StudyUserRole) ODMcomplexTypeDefinitionFormRef(org.cdisc.ns.odm.v130.ODMcomplexTypeDefinitionFormRef) StudyUserRoleId(org.akaza.openclinica.domain.datamap.StudyUserRoleId) FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) Study(org.akaza.openclinica.domain.datamap.Study) ODMcomplexTypeDefinitionStudy(org.cdisc.ns.odm.v130.ODMcomplexTypeDefinitionStudy) StudyEventDefinition(org.akaza.openclinica.domain.datamap.StudyEventDefinition) StudyParameterValue(org.akaza.openclinica.domain.datamap.StudyParameterValue) ODMcomplexTypeDefinitionStudyEventDef(org.cdisc.ns.odm.v130.ODMcomplexTypeDefinitionStudyEventDef) ParticipantPortalRegistrar(org.akaza.openclinica.service.pmanage.ParticipantPortalRegistrar) OCodmComplexTypeDefinitionConfigurationParameters(org.openclinica.ns.odm_ext_v130.v31.OCodmComplexTypeDefinitionConfigurationParameters) OCodmComplexTypeDefinitionFormLayoutRef(org.openclinica.ns.odm_ext_v130.v31.OCodmComplexTypeDefinitionFormLayoutRef) ODMcomplexTypeDefinitionStudyEventRef(org.cdisc.ns.odm.v130.ODMcomplexTypeDefinitionStudyEventRef) UserAccount(org.akaza.openclinica.domain.user.UserAccount) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with StudyUserRole

use of org.akaza.openclinica.domain.datamap.StudyUserRole in project OpenClinica by OpenClinica.

the class GenerateClinicalDataServiceImpl method getClinicalData.

/**
 * This is a generic method where the control enters first. Regardless what URL is being used. Depending upon the combination of URL parameters, further course is determined.
 */
@Override
public LinkedHashMap<String, OdmClinicalDataBean> getClinicalData(String studyOID, String studySubjectOID, String studyEventOID, String formVersionOID, Boolean collectDNs, Boolean collectAudit, Locale locale, int userId) {
    setLocale(locale);
    setCollectDns(collectDNs);
    setCollectAudits(collectAudit);
    LinkedHashMap<String, OdmClinicalDataBean> clinicalDataHash = new LinkedHashMap<String, OdmClinicalDataBean>();
    UserAccount userAccount = getUserAccountDao().findByColumnName(userId, "userId");
    LOGGER.debug("Entering the URL with " + studyOID + ":" + studySubjectOID + ":" + studyEventOID + ":" + formVersionOID + ":DNS:" + collectDNs + ":Audits:" + collectAudit);
    LOGGER.info("Determining the generic paramters...");
    Study study = getStudyDao().findByOcOID(studyOID);
    int parentStudyId = 0;
    int studyId = study.getStudyId();
    if (study.getStudy() != null) {
        isActiveRoleAtSite = true;
        parentStudyId = study.getStudy().getStudyId();
    } else {
        parentStudyId = studyId;
        isActiveRoleAtSite = false;
    }
    ArrayList<StudyUserRole> surlist = getStudyUserRoleDao().findAllUserRolesByUserAccount(userAccount, studyId, parentStudyId);
    if (surlist == null || surlist.size() == 0) {
        // Does not have permission to view study or site info / return null
        return null;
    }
    // This piece of code identifies if the study subject is assigned to study level or site level. If the study subject assigned to site  is pulled from study level this will get the site OID correctly displayed.
    if (!studySubjectOID.equals(INDICATE_ALL)) {
        StudySubjectDao ssdao = getStudySubjectDao();
        StudySubject ss = (StudySubject) getStudySubjectDao().findByColumnName(studySubjectOID, "ocOid");
        studyOID = ss.getStudy().getOc_oid();
    }
    if (studyEventOID.equals(INDICATE_ALL) && formVersionOID.equals(INDICATE_ALL) && !studySubjectOID.equals(INDICATE_ALL) && !studyOID.equals(INDICATE_ALL)) {
        LOGGER.info("Adding all the study events,formevents as it is a *");
        LOGGER.info("study subject is not all and so is study");
        clinicalDataHash.put(studyOID, getClinicalData(studyOID, studySubjectOID));
        return clinicalDataHash;
    } else if (studyEventOID.equals(INDICATE_ALL) && formVersionOID.equals(INDICATE_ALL) && studySubjectOID.equals(INDICATE_ALL) && !studyOID.equals(INDICATE_ALL)) {
        LOGGER.info("At the study level.. study event,study subject and forms are *");
        return getClinicalData(studyOID);
    } else if (!studyEventOID.equals(INDICATE_ALL) && !studySubjectOID.equals(INDICATE_ALL) && !studyOID.equals(INDICATE_ALL) && formVersionOID.equals(INDICATE_ALL)) {
        LOGGER.info("Obtaining the form version specific");
        clinicalDataHash.put(studyOID, getClinicalDatas(studyOID, studySubjectOID, studyEventOID, null));
        return clinicalDataHash;
    } else if (!studyEventOID.equals(INDICATE_ALL) && !studySubjectOID.equals(INDICATE_ALL) && !studyOID.equals(INDICATE_ALL) && !formVersionOID.equals(INDICATE_ALL)) {
        clinicalDataHash.put(studyOID, getClinicalDatas(studyOID, studySubjectOID, studyEventOID, formVersionOID));
        return clinicalDataHash;
    }
    return null;
}
Also used : Study(org.akaza.openclinica.domain.datamap.Study) StudyUserRole(org.akaza.openclinica.domain.datamap.StudyUserRole) StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) OdmClinicalDataBean(org.akaza.openclinica.bean.odmbeans.OdmClinicalDataBean) UserAccount(org.akaza.openclinica.domain.user.UserAccount) StudySubjectDao(org.akaza.openclinica.dao.hibernate.StudySubjectDao) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

StudyUserRole (org.akaza.openclinica.domain.datamap.StudyUserRole)3 UserAccount (org.akaza.openclinica.domain.user.UserAccount)3 Study (org.akaza.openclinica.domain.datamap.Study)2 StudyUserRoleId (org.akaza.openclinica.domain.datamap.StudyUserRoleId)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 OdmClinicalDataBean (org.akaza.openclinica.bean.odmbeans.OdmClinicalDataBean)1 StudySubjectDao (org.akaza.openclinica.dao.hibernate.StudySubjectDao)1 CrfBean (org.akaza.openclinica.domain.datamap.CrfBean)1 EventDefinitionCrf (org.akaza.openclinica.domain.datamap.EventDefinitionCrf)1 FormLayout (org.akaza.openclinica.domain.datamap.FormLayout)1 StudyEventDefinition (org.akaza.openclinica.domain.datamap.StudyEventDefinition)1 StudyParameterValue (org.akaza.openclinica.domain.datamap.StudyParameterValue)1 StudySubject (org.akaza.openclinica.domain.datamap.StudySubject)1 UserType (org.akaza.openclinica.domain.user.UserType)1 Form (org.akaza.openclinica.service.dto.Form)1 ParticipantPortalRegistrar (org.akaza.openclinica.service.pmanage.ParticipantPortalRegistrar)1 ODMcomplexTypeDefinitionFormRef (org.cdisc.ns.odm.v130.ODMcomplexTypeDefinitionFormRef)1 ODMcomplexTypeDefinitionMetaDataVersion (org.cdisc.ns.odm.v130.ODMcomplexTypeDefinitionMetaDataVersion)1