use of se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse in project webcert by sklintyg.
the class FragaSvarServiceImplTest method testFilterFragaSvarWithEnhetsIdAsParam.
@Test
public void testFilterFragaSvarWithEnhetsIdAsParam() {
WebCertUser webCertUser = createUser();
List<FragaSvar> queryResults = new ArrayList<>();
queryResults.add(buildFragaSvar(1L, MAY, null));
queryResults.add(buildFragaSvar(2L, MAY, null));
when(fragasvarRepositoryMock.filterFragaSvar(any(Filter.class))).thenReturn(queryResults);
when(fragasvarRepositoryMock.filterCountFragaSvar(any(Filter.class))).thenReturn(queryResults.size());
Filter params = new Filter();
params.setEnhetsIds(Arrays.asList(webCertUser.getValdVardenhet().getId()));
QueryFragaSvarResponse response = service.filterFragaSvar(params);
verify(fragasvarRepositoryMock).filterFragaSvar(any(Filter.class));
verify(fragasvarRepositoryMock).filterCountFragaSvar(any(Filter.class));
assertNotNull(response);
assertEquals(2, response.getResults().size());
}
use of se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse in project webcert by sklintyg.
the class FragaSvarServiceImpl method filterFragaSvar.
@Override
@Transactional(value = "jpaTransactionManager", readOnly = true)
public QueryFragaSvarResponse filterFragaSvar(Filter filter) {
List<ArendeListItem> results = fragaSvarRepository.filterFragaSvar(filter).stream().map(ArendeListItemConverter::convert).filter(Objects::nonNull).collect(Collectors.toList());
int totalResultsCount = fragaSvarRepository.filterCountFragaSvar(filter);
QueryFragaSvarResponse response = new QueryFragaSvarResponse();
response.setResults(results);
response.setTotalCount(totalResultsCount);
return response;
}
use of se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse in project webcert by sklintyg.
the class ArendeServiceImpl method filterArende.
@Override
@Transactional(value = "jpaTransactionManager", readOnly = true)
public QueryFragaSvarResponse filterArende(QueryFragaSvarParameter filterParameters) {
WebCertUser user = webcertUserService.getUser();
Set<String> intygstyperForPrivilege = authoritiesHelper.getIntygstyperForPrivilege(user, AuthoritiesConstants.PRIVILEGE_VISA_INTYG);
Filter filter;
if (!Strings.isNullOrEmpty(filterParameters.getEnhetId())) {
verifyEnhetsAuth(filterParameters.getEnhetId(), true);
filter = FilterConverter.convert(filterParameters, Arrays.asList(filterParameters.getEnhetId()), intygstyperForPrivilege);
} else {
filter = FilterConverter.convert(filterParameters, user.getIdsOfSelectedVardenhet(), intygstyperForPrivilege);
}
int originalStartFrom = filter.getStartFrom();
int originalPageSize = filter.getPageSize();
// INTYG-4086: Do NOT perform any paging. We must first load all applicable QA / ärenden, then apply
// sekretessmarkering filtering. THEN - we can do paging stuff in-memory. Very inefficient...
filter.setStartFrom(null);
filter.setPageSize(null);
List<ArendeListItem> results = arendeRepository.filterArende(filter).stream().map(ArendeListItemConverter::convert).filter(Objects::nonNull).peek(item -> item.setPaminnelse(!arendeRepository.findByPaminnelseMeddelandeId(item.getMeddelandeId()).isEmpty())).collect(Collectors.toList());
QueryFragaSvarResponse fsResults = fragaSvarService.filterFragaSvar(filter);
results.addAll(fsResults.getResults());
results.sort(Comparator.comparing(ArendeListItem::getReceivedDate).reversed());
QueryFragaSvarResponse response = new QueryFragaSvarResponse();
Map<Personnummer, SekretessStatus> sekretessStatusMap = patientDetailsResolver.getSekretessStatusForList(results.stream().map(ali -> Personnummer.createPersonnummer(ali.getPatientId()).get()).collect(Collectors.toList()));
// INTYG-4086, INTYG-4486: Filter out any items that doesn't pass sekretessmarkering rules
results = results.stream().filter(ali -> this.passesSekretessCheck(ali.getPatientId(), ali.getIntygTyp(), user, sekretessStatusMap)).collect(Collectors.toList());
// We must mark all items having patient with sekretessmarkering
results.stream().filter(ali -> hasSekretessStatus(ali, SekretessStatus.TRUE, sekretessStatusMap)).forEach(ali -> ali.setSekretessmarkering(true));
response.setTotalCount(results.size());
if (originalStartFrom >= results.size()) {
response.setResults(new ArrayList<>());
} else {
response.setResults(results.subList(originalStartFrom, Math.min(originalPageSize + originalStartFrom, results.size())));
}
return response;
}
use of se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse in project webcert by sklintyg.
the class FragaSvarServiceImplTest method testFilterFragaSvarWithNoEnhetsIdAsParam.
@Test
public void testFilterFragaSvarWithNoEnhetsIdAsParam() {
List<FragaSvar> queryResults = new ArrayList<>();
queryResults.add(buildFragaSvar(1L, MAY, null));
queryResults.add(buildFragaSvar(2L, MAY, null));
when(fragasvarRepositoryMock.filterFragaSvar(any(Filter.class))).thenReturn(queryResults);
when(fragasvarRepositoryMock.filterCountFragaSvar(any(Filter.class))).thenReturn(queryResults.size());
QueryFragaSvarResponse response = service.filterFragaSvar(new Filter());
verify(fragasvarRepositoryMock).filterFragaSvar(any(Filter.class));
verify(fragasvarRepositoryMock).filterCountFragaSvar(any(Filter.class));
assertNotNull(response);
assertEquals(2, response.getResults().size());
}
use of se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse in project webcert by sklintyg.
the class ArendeServiceTest method testFilterArendeWithNoEnhetsIdAsParam.
@Test
public void testFilterArendeWithNoEnhetsIdAsParam() {
when(webcertUserService.getUser()).thenReturn(createUser());
List<Arende> queryResults = new ArrayList<>();
queryResults.add(buildArende(UUID.randomUUID().toString(), LocalDateTime.now(), null));
queryResults.add(buildArende(UUID.randomUUID().toString(), LocalDateTime.now().plusDays(1), null));
when(arendeRepository.filterArende(any(Filter.class))).thenReturn(queryResults);
QueryFragaSvarResponse fsResponse = new QueryFragaSvarResponse();
fsResponse.setResults(new ArrayList<>());
fsResponse.setTotalCount(0);
when(fragaSvarService.filterFragaSvar(any(Filter.class))).thenReturn(fsResponse);
QueryFragaSvarParameter params = new QueryFragaSvarParameter();
QueryFragaSvarResponse response = service.filterArende(params);
verify(webcertUserService).getUser();
verify(arendeRepository).filterArende(any(Filter.class));
// verify(arendeRepository).filterArendeCount(any(Filter.class));
verify(fragaSvarService).filterFragaSvar(any(Filter.class));
assertEquals(2, response.getResults().size());
// assertEquals(3, response.getTotalCount());
}
Aggregations