Search in sources :

Example 1 with UserStudyExtended

use of com.odysseusinc.arachne.portal.model.UserStudyExtended 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 2 with UserStudyExtended

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

the class ParticipantLinkToParticipantDTOConverter method convert.

@Override
public ParticipantDTO convert(ParticipantLink participantLink) {
    ParticipantDTO participantDTO = new ParticipantDTO();
    ParticipantRole role = participantLink.getRole();
    final IUser user = participantLink.getUser();
    participantDTO.setId(user.getUuid());
    participantDTO.setFullName(user.getFullName());
    participantDTO.setRole(new OptionDTO(role.name(), role.toString()));
    participantDTO.setStatus(participantLink.getStatus().toString());
    if (participantLink instanceof UserStudyExtended) {
        if (DECLINED == participantLink.getStatus() && !isEmpty(((UserStudyExtended) participantLink).getComment())) {
            participantDTO.setComment(((UserStudyExtended) participantLink).getComment());
        }
        if (role.equals(ParticipantRole.DATA_SET_OWNER)) {
            DataSource ownedDataSource = ((UserStudyExtended) participantLink).getDataSource();
            participantDTO = new DataOwnerParticipantDTO(participantDTO, ownedDataSource.getId());
        }
    }
    return participantDTO;
}
Also used : DataOwnerParticipantDTO(com.odysseusinc.arachne.portal.api.v1.dto.DataOwnerParticipantDTO) IUser(com.odysseusinc.arachne.portal.model.IUser) ParticipantDTO(com.odysseusinc.arachne.portal.api.v1.dto.ParticipantDTO) DataOwnerParticipantDTO(com.odysseusinc.arachne.portal.api.v1.dto.DataOwnerParticipantDTO) OptionDTO(com.odysseusinc.arachne.commons.api.v1.dto.OptionDTO) UserStudyExtended(com.odysseusinc.arachne.portal.model.UserStudyExtended) ParticipantRole(com.odysseusinc.arachne.portal.model.ParticipantRole) DataSource(com.odysseusinc.arachne.portal.model.DataSource)

Example 3 with UserStudyExtended

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

the class PaperSpecification method getUserStudyLinkSubquery.

protected Subquery<UserStudyExtended> getUserStudyLinkSubquery(CriteriaQuery<?> query, CriteriaBuilder cb, Path<Long> studyId) {
    final Subquery<UserStudyExtended> userStudyExtendedLinkSubquery = query.subquery(UserStudyExtended.class);
    final Root<UserStudyExtended> userStudyLinkRoot = userStudyExtendedLinkSubquery.from(UserStudyExtended.class);
    userStudyExtendedLinkSubquery.select(userStudyLinkRoot);
    final Path<RawUser> linkUser = userStudyLinkRoot.get(UserStudyExtended_.user);
    final Path<Study> linkStudy = userStudyLinkRoot.get(UserStudyExtended_.study);
    final Path<Long> linkStudyId = linkStudy.get(Study_.id);
    final Path<ParticipantStatus> linkStatus = userStudyLinkRoot.get(UserStudyExtended_.status);
    Predicate userStudyPredicate = cb.and(cb.equal(linkUser, user), cb.equal(linkStudyId, studyId));
    userStudyPredicate = cb.and(userStudyPredicate, cb.notEqual(linkStatus, ParticipantStatus.DELETED));
    userStudyExtendedLinkSubquery.where(userStudyPredicate);
    return userStudyExtendedLinkSubquery;
}
Also used : Study(com.odysseusinc.arachne.portal.model.Study) ParticipantStatus(com.odysseusinc.arachne.portal.model.ParticipantStatus) RawUser(com.odysseusinc.arachne.portal.model.RawUser) UserStudyExtended(com.odysseusinc.arachne.portal.model.UserStudyExtended) Predicate(javax.persistence.criteria.Predicate)

Example 4 with UserStudyExtended

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

the class BaseStudyToStudyDTOConverter method convert.

@Override
public DTO convert(final S source) {
    final DTO studyDTO = super.convert(source);
    final Tenant studyTenant = source.getTenant();
    List<UserStudyExtended> sourceParticipants = new ArrayList<>(source.getParticipants());
    Comparator<UserStudyExtended> comparator = Comparator.comparing(p -> p.getStatus().ordinal());
    sourceParticipants.sort(comparator.thenComparing((p1, p2) -> StringUtils.compare(p1.getUser().getFullName(), p2.getUser().getFullName())));
    for (final UserStudyExtended studyUserLink : sourceParticipants) {
        final ParticipantDTO participantDTO = conversionService.convert(studyUserLink, ParticipantDTO.class);
        if (!studyUserLink.getUser().getTenants().contains(studyTenant)) {
            participantDTO.setCanBeRecreated(Boolean.FALSE);
        }
        studyDTO.getParticipants().add(participantDTO);
    }
    studyDTO.setStatus(conversionService.convert(source.getStatus(), StudyStatusDTO.class));
    studyDTO.setType(conversionService.convert(source.getType(), StudyTypeDTO.class));
    studyDTO.setEndDate(source.getEndDate());
    studyDTO.setStartDate(source.getStartDate());
    studyDTO.setDescription(source.getDescription());
    studyDTO.setCreated(source.getCreated());
    studyDTO.setUpdated(source.getUpdated());
    studyDTO.setPaperId(source.getPaper() == null ? null : source.getPaper().getId());
    studyDTO.setPrivacy(source.getPrivacy());
    proceedAdditionalFields(studyDTO, source);
    return studyDTO;
}
Also used : StudyStatusDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyStatusDTO) Tenant(com.odysseusinc.arachne.portal.model.security.Tenant) AnalysisService(com.odysseusinc.arachne.portal.service.analysis.AnalysisService) ParticipantDTO(com.odysseusinc.arachne.portal.api.v1.dto.ParticipantDTO) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) List(java.util.List) StudyTypeDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyTypeDTO) UserStudyExtended(com.odysseusinc.arachne.portal.model.UserStudyExtended) StudyDTO(com.odysseusinc.arachne.portal.api.v1.dto.StudyDTO) ArachneConverterUtils(com.odysseusinc.arachne.portal.util.ArachneConverterUtils) BaseStudyService(com.odysseusinc.arachne.portal.service.BaseStudyService) Comparator(java.util.Comparator) Study(com.odysseusinc.arachne.portal.model.Study) Tenant(com.odysseusinc.arachne.portal.model.security.Tenant) StudyStatusDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyStatusDTO) ArrayList(java.util.ArrayList) ParticipantDTO(com.odysseusinc.arachne.portal.api.v1.dto.ParticipantDTO) UserStudyExtended(com.odysseusinc.arachne.portal.model.UserStudyExtended) StudyStatusDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyStatusDTO) ParticipantDTO(com.odysseusinc.arachne.portal.api.v1.dto.ParticipantDTO) StudyTypeDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyTypeDTO) StudyDTO(com.odysseusinc.arachne.portal.api.v1.dto.StudyDTO) StudyTypeDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyTypeDTO)

Example 5 with UserStudyExtended

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

the class BaseStudyToWorkspaceDTOConverter method convert.

@Override
public DTO convert(S source) {
    final DTO workspaceDTO = super.convert(source);
    if (!source.getParticipants().isEmpty()) {
        Optional<UserStudyExtended> leadOptional = source.getParticipants().stream().filter(participant -> participant.getRole().equals(ParticipantRole.LEAD_INVESTIGATOR)).findFirst();
        workspaceDTO.setLeadParticipant(conversionService.convert(leadOptional.orElseThrow(() -> {
            final String message = "Lead investigator for workspace id = " + workspaceDTO.getId() + " doesn't exist";
            return new NotExistException(message, UserStudyExtended.class);
        }), ParticipantDTO.class));
    }
    return workspaceDTO;
}
Also used : NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) AnalysisService(com.odysseusinc.arachne.portal.service.analysis.AnalysisService) ParticipantDTO(com.odysseusinc.arachne.portal.api.v1.dto.ParticipantDTO) UserStudyExtended(com.odysseusinc.arachne.portal.model.UserStudyExtended) ParticipantRole(com.odysseusinc.arachne.portal.model.ParticipantRole) ArachneConverterUtils(com.odysseusinc.arachne.portal.util.ArachneConverterUtils) Optional(java.util.Optional) Autowired(org.springframework.beans.factory.annotation.Autowired) BaseStudyService(com.odysseusinc.arachne.portal.service.BaseStudyService) WorkspaceDTO(com.odysseusinc.arachne.portal.api.v1.dto.WorkspaceDTO) Study(com.odysseusinc.arachne.portal.model.Study) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) ParticipantDTO(com.odysseusinc.arachne.portal.api.v1.dto.ParticipantDTO) UserStudyExtended(com.odysseusinc.arachne.portal.model.UserStudyExtended) ParticipantDTO(com.odysseusinc.arachne.portal.api.v1.dto.ParticipantDTO) WorkspaceDTO(com.odysseusinc.arachne.portal.api.v1.dto.WorkspaceDTO)

Aggregations

UserStudyExtended (com.odysseusinc.arachne.portal.model.UserStudyExtended)5 ParticipantDTO (com.odysseusinc.arachne.portal.api.v1.dto.ParticipantDTO)4 Study (com.odysseusinc.arachne.portal.model.Study)4 ParticipantRole (com.odysseusinc.arachne.portal.model.ParticipantRole)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 StudyStatusDTO (com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyStatusDTO)2 BaseStudyService (com.odysseusinc.arachne.portal.service.BaseStudyService)2 AnalysisService (com.odysseusinc.arachne.portal.service.analysis.AnalysisService)2 ArachneConverterUtils (com.odysseusinc.arachne.portal.util.ArachneConverterUtils)2 List (java.util.List)2 OptionDTO (com.odysseusinc.arachne.commons.api.v1.dto.OptionDTO)1 DataOwnerParticipantDTO (com.odysseusinc.arachne.portal.api.v1.dto.DataOwnerParticipantDTO)1 DataSourceDTO (com.odysseusinc.arachne.portal.api.v1.dto.DataSourceDTO)1 ParticipantExtendedDTO (com.odysseusinc.arachne.portal.api.v1.dto.ParticipantExtendedDTO)1 StudyDTO (com.odysseusinc.arachne.portal.api.v1.dto.StudyDTO)1 StudyMediumDTO (com.odysseusinc.arachne.portal.api.v1.dto.StudyMediumDTO)1 WorkspaceDTO (com.odysseusinc.arachne.portal.api.v1.dto.WorkspaceDTO)1 BaseConversionServiceAwareConverter (com.odysseusinc.arachne.portal.api.v1.dto.converters.BaseConversionServiceAwareConverter)1 StudyTypeDTO (com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyTypeDTO)1 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)1