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);
}
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;
}
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());
}
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));
}
}
}
}
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());
}
Aggregations