Search in sources :

Example 1 with StudyDTO

use of com.odysseusinc.arachne.portal.api.v1.dto.StudyDTO in project ArachneCentralAPI by OHDSI.

the class BaseStudyController method suggest.

@ApiOperation("Suggest study.")
@RequestMapping(value = "/api/v1/study-management/studies/search", method = GET)
public JsonResult<List<StudyDTO>> suggest(Principal principal, @RequestParam("id") String requestId, @RequestParam("query") String query, @RequestParam("region") SuggestSearchRegion region) throws PermissionDeniedException {
    JsonResult<List<StudyDTO>> result;
    IUser owner = getUser(principal);
    Long id;
    switch(region) {
        case DATASOURCE:
            id = Long.valueOf(requestId);
            break;
        case PARTICIPANT:
            IUser participant = Optional.ofNullable(userService.getByUuid(requestId)).orElseThrow(() -> new NotExistException(EX_USER_NOT_EXISTS, User.class));
            id = participant.getId();
            break;
        default:
            id = 0L;
            break;
    }
    Iterable<T> studies = studyService.suggestStudy(query, owner, id, region);
    result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
    List<StudyDTO> studiesDTOs = new LinkedList<>();
    for (Study study : studies) {
        studiesDTOs.add(conversionService.convert(study, StudyDTO.class));
    }
    result.setResult(studiesDTOs);
    return result;
}
Also used : UserStudy(com.odysseusinc.arachne.portal.model.UserStudy) Study(com.odysseusinc.arachne.portal.model.Study) CreateStudyDTO(com.odysseusinc.arachne.portal.api.v1.dto.CreateStudyDTO) StudyDTO(com.odysseusinc.arachne.portal.api.v1.dto.StudyDTO) User(com.odysseusinc.arachne.portal.model.User) IUser(com.odysseusinc.arachne.portal.model.IUser) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) LinkedList(java.util.LinkedList) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) GET(org.springframework.web.bind.annotation.RequestMethod.GET) POST(org.springframework.web.bind.annotation.RequestMethod.POST) IUser(com.odysseusinc.arachne.portal.model.IUser) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with StudyDTO

use of com.odysseusinc.arachne.portal.api.v1.dto.StudyDTO in project ArachneCentralAPI by OHDSI.

the class StudyToStudyShortDTOConverter method convert.

@Override
public StudyShortDTO convert(Study source) {
    final StudyShortDTO studyDTO = new StudyShortDTO();
    studyDTO.setId(source.getId());
    studyDTO.setTitle(source.getTitle());
    studyDTO.setKind(source.getKind());
    return studyDTO;
}
Also used : StudyShortDTO(com.odysseusinc.arachne.portal.api.v1.dto.StudyShortDTO)

Example 3 with StudyDTO

use of com.odysseusinc.arachne.portal.api.v1.dto.StudyDTO 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 4 with StudyDTO

use of com.odysseusinc.arachne.portal.api.v1.dto.StudyDTO in project ArachneCentralAPI by OHDSI.

the class BaseStudyToStudyListDTOConverter method convert.

@Override
public DTO convert(S userStudyExtendedLink) {
    DTO studyDTO = createResultObject();
    Study source = userStudyExtendedLink.getStudy();
    List<IUser> studyLeadList = studyService.findLeads(source);
    studyDTO.setStatus(conversionService.convert(source.getStatus(), StudyStatusDTO.class));
    studyDTO.setTitle(source.getTitle());
    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.setId(source.getId());
    StringBuilder stringBuilder = new StringBuilder();
    for (String participantRole : userStudyExtendedLink.getRole() != null ? userStudyExtendedLink.getRole().split(",") : new String[] {}) {
        stringBuilder.append(ParticipantRole.valueOf(participantRole).toString()).append(", ");
    }
    stringBuilder.delete(stringBuilder.length() - 2, stringBuilder.length());
    studyDTO.setRole(stringBuilder.toString());
    studyDTO.setPermissions(conversionService.convert(source, PermissionsDTO.class));
    studyDTO.setFavourite(userStudyExtendedLink.getFavourite());
    studyDTO.setLeadList(studyLeadList.stream().map(studyLead -> conversionService.convert(studyLead, ShortUserDTO.class)).collect(Collectors.toList()));
    studyDTO.setPrivacy(source.getPrivacy());
    proceedAdditionalFields(studyDTO, userStudyExtendedLink);
    return studyDTO;
}
Also used : Study(com.odysseusinc.arachne.portal.model.Study) StudyStatusDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyStatusDTO) ShortUserDTO(com.odysseusinc.arachne.portal.api.v1.dto.ShortUserDTO) PermissionsDTO(com.odysseusinc.arachne.portal.api.v1.dto.PermissionsDTO) IUser(com.odysseusinc.arachne.portal.model.IUser) StudyStatusDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyStatusDTO) PermissionsDTO(com.odysseusinc.arachne.portal.api.v1.dto.PermissionsDTO) StudyListDTO(com.odysseusinc.arachne.portal.api.v1.dto.StudyListDTO) ShortUserDTO(com.odysseusinc.arachne.portal.api.v1.dto.ShortUserDTO) StudyTypeDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyTypeDTO) StudyTypeDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyTypeDTO)

Example 5 with StudyDTO

use of com.odysseusinc.arachne.portal.api.v1.dto.StudyDTO in project ArachneCentralAPI by OHDSI.

the class BaseUserStudyItemToStudyDTOConverter method convert.

@Override
public S convert(AbstractUserStudyListItem source) {
    final Study study = source.getStudy();
    S studyDto = createResultObject();
    StudyDTO baseObject = conversionService.convert(study, getDtoClass());
    baseObject.setFavourite(source.getFavourite());
    List<StudyDataSourceLink> links = study.getDataSources().stream().filter(ds -> DataSourceStatus.DELETED.equals(ds.getStatus())).collect(Collectors.toList());
    // this list won't be empty only in case when we intentionally get all (include those with deleted_at != NULL) StudyDataSourceLinks from repository
    if (!links.isEmpty()) {
        List<DataSourceDTO> dataSourceDTOS = converterUtils.convertList(links, DataSourceDTO.class);
        baseObject.getDataSources().addAll(dataSourceDTOS);
    }
    converterUtils.shallowCopy(studyDto, baseObject);
    studyDto.setPrivacy(study.getPrivacy());
    proceedAdditionalFields(studyDto, source);
    return studyDto;
}
Also used : List(java.util.List) StudyDTO(com.odysseusinc.arachne.portal.api.v1.dto.StudyDTO) ArachneConverterUtils(com.odysseusinc.arachne.portal.util.ArachneConverterUtils) BaseConversionServiceAwareConverter(com.odysseusinc.arachne.portal.api.v1.dto.converters.BaseConversionServiceAwareConverter) Autowired(org.springframework.beans.factory.annotation.Autowired) DataSourceStatus(com.odysseusinc.arachne.portal.model.DataSourceStatus) DataSourceDTO(com.odysseusinc.arachne.portal.api.v1.dto.DataSourceDTO) StudyDataSourceLink(com.odysseusinc.arachne.portal.model.StudyDataSourceLink) Collectors(java.util.stream.Collectors) AbstractUserStudyListItem(com.odysseusinc.arachne.portal.model.AbstractUserStudyListItem) Study(com.odysseusinc.arachne.portal.model.Study) Study(com.odysseusinc.arachne.portal.model.Study) StudyDTO(com.odysseusinc.arachne.portal.api.v1.dto.StudyDTO) DataSourceDTO(com.odysseusinc.arachne.portal.api.v1.dto.DataSourceDTO) StudyDataSourceLink(com.odysseusinc.arachne.portal.model.StudyDataSourceLink)

Aggregations

StudyStatusDTO (com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyStatusDTO)10 StudyDTO (com.odysseusinc.arachne.portal.api.v1.dto.StudyDTO)9 Study (com.odysseusinc.arachne.portal.model.Study)9 CreateStudyDTO (com.odysseusinc.arachne.portal.api.v1.dto.CreateStudyDTO)8 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)7 ExpectedDatabases (com.github.springtestdbunit.annotation.ExpectedDatabases)7 Test (org.junit.Test)7 WithUserDetails (org.springframework.security.test.context.support.WithUserDetails)7 StudyTypeDTO (com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyTypeDTO)6 List (java.util.List)5 Autowired (org.springframework.beans.factory.annotation.Autowired)4 PermissionsDTO (com.odysseusinc.arachne.portal.api.v1.dto.PermissionsDTO)3 StudyMediumDTO (com.odysseusinc.arachne.portal.api.v1.dto.StudyMediumDTO)3 BaseConversionServiceAwareConverter (com.odysseusinc.arachne.portal.api.v1.dto.converters.BaseConversionServiceAwareConverter)3 IUser (com.odysseusinc.arachne.portal.model.IUser)3 Collectors (java.util.stream.Collectors)3 DataSourceDTO (com.odysseusinc.arachne.portal.api.v1.dto.DataSourceDTO)2 ParticipantDTO (com.odysseusinc.arachne.portal.api.v1.dto.ParticipantDTO)2 ShortUserDTO (com.odysseusinc.arachne.portal.api.v1.dto.ShortUserDTO)2 StudyListDTO (com.odysseusinc.arachne.portal.api.v1.dto.StudyListDTO)2