Search in sources :

Example 1 with StudyDataSourceLink

use of com.odysseusinc.arachne.portal.model.StudyDataSourceLink in project ArachneCentralAPI by OHDSI.

the class BaseStudyController method addDataSource.

@ApiOperation("Add data source to the study.")
@RequestMapping(value = "/api/v1/study-management/studies/{studyId}/data-sources/{dataSourceId}", method = POST)
public EntityLinkDTO addDataSource(Principal principal, @PathVariable("studyId") Long studyId, @PathVariable("dataSourceId") Long dataSourceId) throws PermissionDeniedException, NotExistException, AlreadyExistException {
    final IUser createdBy = getUser(principal);
    StudyDataSourceLink link = studyService.addDataSource(createdBy, studyId, dataSourceId);
    return conversionService.convert(link, EntityLinkDTO.class);
}
Also used : StudyDataSourceLink(com.odysseusinc.arachne.portal.model.StudyDataSourceLink) IUser(com.odysseusinc.arachne.portal.model.IUser) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with StudyDataSourceLink

use of com.odysseusinc.arachne.portal.model.StudyDataSourceLink in project ArachneCentralAPI by OHDSI.

the class StudyToStudyMediumDTOConverter method convert.

@Override
public StudyMediumDTO convert(Study source) {
    final StudyMediumDTO studyDTO = new StudyMediumDTO();
    studyDTO.setId(source.getId());
    studyDTO.setTitle(source.getTitle());
    studyDTO.setDescription(source.getDescription());
    studyDTO.setCreated(source.getCreated());
    studyDTO.setStartDate(source.getStartDate());
    studyDTO.setEndDate(source.getEndDate());
    studyDTO.setStatus(conversionService.convert(source.getStatus(), StudyStatusDTO.class));
    final Map<ParticipantRole, List<UserStudyExtended>> studyParticipants = source.getParticipants().stream().collect(Collectors.groupingBy(link -> link.getRole() == ParticipantRole.LEAD_INVESTIGATOR ? LEAD_INVESTIGATOR : CONTRIBUTOR));
    final List<UserStudyExtended> studyLeads = studyParticipants.get(LEAD_INVESTIGATOR);
    if (!CollectionUtils.isEmpty(studyLeads)) {
        studyDTO.setStudyLeads(studyLeads.stream().filter(distinctByKey(p -> p.getUser().getId())).map(studyParticipant -> conversionService.convert(studyParticipant, ParticipantDTO.class)).collect(Collectors.toList()));
    }
    final List<UserStudyExtended> studyContributors = studyParticipants.get(CONTRIBUTOR);
    if (!CollectionUtils.isEmpty(studyContributors)) {
        studyDTO.setStudyParticipants(studyContributors.stream().filter(distinctByKey(p -> p.getUser().getId())).map(studyParticipant -> conversionService.convert(studyParticipant, ParticipantExtendedDTO.class)).collect(Collectors.toList()));
    }
    final List<StudyDataSourceLink> studyDataSources = source.getDataSources();
    studyDTO.setStudyDataSources(studyDataSources.stream().map(studyDataSource -> conversionService.convert(studyDataSource.getDataSource(), DataSourceDTO.class)).collect(Collectors.toList()));
    return studyDTO;
}
Also used : LEAD_INVESTIGATOR(com.odysseusinc.arachne.portal.model.ParticipantRole.LEAD_INVESTIGATOR) StudyStatusDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyStatusDTO) CONTRIBUTOR(com.odysseusinc.arachne.portal.model.ParticipantRole.CONTRIBUTOR) ParticipantDTO(com.odysseusinc.arachne.portal.api.v1.dto.ParticipantDTO) Predicate(java.util.function.Predicate) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) GenericConversionService(org.springframework.core.convert.support.GenericConversionService) DataSourceDTO(com.odysseusinc.arachne.portal.api.v1.dto.DataSourceDTO) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) List(java.util.List) Component(org.springframework.stereotype.Component) UserStudyExtended(com.odysseusinc.arachne.portal.model.UserStudyExtended) ParticipantRole(com.odysseusinc.arachne.portal.model.ParticipantRole) CollectionUtils(org.springframework.util.CollectionUtils) StudyMediumDTO(com.odysseusinc.arachne.portal.api.v1.dto.StudyMediumDTO) Map(java.util.Map) BaseConversionServiceAwareConverter(com.odysseusinc.arachne.portal.api.v1.dto.converters.BaseConversionServiceAwareConverter) StudyDataSourceLink(com.odysseusinc.arachne.portal.model.StudyDataSourceLink) ParticipantExtendedDTO(com.odysseusinc.arachne.portal.api.v1.dto.ParticipantExtendedDTO) Study(com.odysseusinc.arachne.portal.model.Study) StudyDataSourceLink(com.odysseusinc.arachne.portal.model.StudyDataSourceLink) ParticipantDTO(com.odysseusinc.arachne.portal.api.v1.dto.ParticipantDTO) UserStudyExtended(com.odysseusinc.arachne.portal.model.UserStudyExtended) StudyMediumDTO(com.odysseusinc.arachne.portal.api.v1.dto.StudyMediumDTO) DataSourceDTO(com.odysseusinc.arachne.portal.api.v1.dto.DataSourceDTO) StudyStatusDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyStatusDTO) List(java.util.List) ParticipantExtendedDTO(com.odysseusinc.arachne.portal.api.v1.dto.ParticipantExtendedDTO) ParticipantRole(com.odysseusinc.arachne.portal.model.ParticipantRole)

Example 3 with StudyDataSourceLink

use of com.odysseusinc.arachne.portal.model.StudyDataSourceLink in project ArachneCentralAPI by OHDSI.

the class BaseDataSourceServiceImpl method suggestDataSource.

@Override
public Page<DS> suggestDataSource(final String query, final Long studyId, final Long userId, PageRequest pageRequest) {
    List<DataSourceStatus> BAD_STATUSES = Arrays.asList(DataSourceStatus.DELETED, DataSourceStatus.DECLINED);
    final String[] split = query.trim().split(" ");
    CriteriaBuilder cb = this.entityManager.getCriteriaBuilder();
    CriteriaQuery<DS> cq = cb.createQuery(getType());
    Root<DS> root = cq.from(getType());
    Subquery sq = cq.subquery(Long.class);
    Root<StudyDataSourceLink> dsLink = sq.from(StudyDataSourceLink.class);
    sq.select(dsLink.get("dataSource").get("id"));
    sq.where(cb.and(cb.equal(dsLink.get("study").get("id"), studyId), cb.not(dsLink.get("status").in(BAD_STATUSES))));
    cq.select(root);
    // TRUE
    Predicate nameClause = cb.conjunction();
    if (split.length > 1 || (split.length == 1 && !split[0].equals(""))) {
        List<Predicate> predictList = new ArrayList<>();
        for (String one : split) {
            predictList.add(cb.like(cb.lower(root.get("name")), one + "%"));
            predictList.add(cb.like(cb.lower(root.get("dataNode").get("name")), one + "%"));
        }
        nameClause = cb.or(predictList.toArray(new Predicate[] {}));
    }
    cq.where(cb.and(cb.not(root.get("id").in(sq)), nameClause, cb.isNull(root.get("deleted")), cb.isTrue(root.get("published")), cb.isFalse(root.get("dataNode").get("virtual"))));
    TypedQuery<DS> typedQuery = this.entityManager.createQuery(cq);
    List<DS> list = typedQuery.setFirstResult(pageRequest.getOffset()).setMaxResults(pageRequest.getPageSize()).getResultList();
    return new PageImpl<>(list, pageRequest, list.size());
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) PageImpl(org.springframework.data.domain.PageImpl) StudyDataSourceLink(com.odysseusinc.arachne.portal.model.StudyDataSourceLink) ArrayList(java.util.ArrayList) Subquery(javax.persistence.criteria.Subquery) Predicate(javax.persistence.criteria.Predicate) DataSourceStatus(com.odysseusinc.arachne.portal.model.DataSourceStatus)

Example 4 with StudyDataSourceLink

use of com.odysseusinc.arachne.portal.model.StudyDataSourceLink in project ArachneCentralAPI by OHDSI.

the class BaseStudyServiceImpl method processDataSourceInvitation.

@Override
public void processDataSourceInvitation(IUser user, Long id, Boolean accepted, String comment) {
    StudyDataSourceLink studyDataSourceLink = studyDataSourceLinkRepository.findByIdAndOwnerId(id, user.getId());
    if (studyDataSourceLink != null) {
        DataSourceStatus status = TRUE.equals(accepted) ? APPROVED : DECLINED;
        studyDataSourceLink.setStatus(status);
        if (DECLINED == status) {
            if (!StringUtils.isEmpty(comment)) {
                dataSourceCommentRepository.save(new StudyDataSourceComment(studyDataSourceLink.getId(), user.getId(), comment));
            }
        }
    }
}
Also used : StudyDataSourceComment(com.odysseusinc.arachne.portal.model.StudyDataSourceComment) StudyDataSourceLink(com.odysseusinc.arachne.portal.model.StudyDataSourceLink) DataSourceStatus(com.odysseusinc.arachne.portal.model.DataSourceStatus)

Example 5 with StudyDataSourceLink

use of com.odysseusinc.arachne.portal.model.StudyDataSourceLink in project ArachneCentralAPI by OHDSI.

the class BaseStudyServiceImpl method removeDataSourceUnsecured.

@Override
public void removeDataSourceUnsecured(Long studyId, Long dataSourceId) {
    Study study = studyRepository.findOne(studyId);
    if (study == null) {
        throw new NotExistException("study does not exist.", Study.class);
    }
    StudyDataSourceLink studyDataSourceLink = studyDataSourceLinkRepository.findByStudyIdAndDataSourceId(study.getId(), dataSourceId);
    if (studyDataSourceLink == null) {
        throw new NotExistException("studyDataSourceLink does not exist.", StudyDataSourceLink.class);
    }
    studyDataSourceLinkRepository.delete(studyDataSourceLink.getId());
}
Also used : UserStudy(com.odysseusinc.arachne.portal.model.UserStudy) Study(com.odysseusinc.arachne.portal.model.Study) FavouriteStudy(com.odysseusinc.arachne.portal.model.FavouriteStudy) StudyDataSourceLink(com.odysseusinc.arachne.portal.model.StudyDataSourceLink) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException)

Aggregations

StudyDataSourceLink (com.odysseusinc.arachne.portal.model.StudyDataSourceLink)8 DataSourceDTO (com.odysseusinc.arachne.portal.api.v1.dto.DataSourceDTO)3 ParticipantDTO (com.odysseusinc.arachne.portal.api.v1.dto.ParticipantDTO)2 StudyStatusDTO (com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyStatusDTO)2 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)2 DataSourceStatus (com.odysseusinc.arachne.portal.model.DataSourceStatus)2 Study (com.odysseusinc.arachne.portal.model.Study)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 BaseAnalysisDTO (com.odysseusinc.arachne.portal.api.v1.dto.BaseAnalysisDTO)1 CreateVirtualDataSourceDTO (com.odysseusinc.arachne.portal.api.v1.dto.CreateVirtualDataSourceDTO)1 ParticipantExtendedDTO (com.odysseusinc.arachne.portal.api.v1.dto.ParticipantExtendedDTO)1 PermissionsDTO (com.odysseusinc.arachne.portal.api.v1.dto.PermissionsDTO)1 StudyDTO (com.odysseusinc.arachne.portal.api.v1.dto.StudyDTO)1 StudyFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.StudyFileDTO)1 StudyMediumDTO (com.odysseusinc.arachne.portal.api.v1.dto.StudyMediumDTO)1 BaseConversionServiceAwareConverter (com.odysseusinc.arachne.portal.api.v1.dto.converters.BaseConversionServiceAwareConverter)1 StudyTypeDTO (com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyTypeDTO)1