Search in sources :

Example 6 with QueryFragaSvarResponse

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());
}
Also used : Filter(se.inera.intyg.webcert.persistence.model.Filter) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) QueryFragaSvarResponse(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse) Test(org.junit.Test)

Example 7 with QueryFragaSvarResponse

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;
}
Also used : ArendeListItem(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem) ArendeListItemConverter(se.inera.intyg.webcert.web.converter.ArendeListItemConverter) QueryFragaSvarResponse(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with QueryFragaSvarResponse

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;
}
Also used : Arrays(java.util.Arrays) ArendeDraft(se.inera.intyg.webcert.persistence.arende.model.ArendeDraft) PatientDetailsResolver(se.inera.intyg.webcert.web.service.patient.PatientDetailsResolver) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) MonitoringLogService(se.inera.intyg.webcert.web.service.monitoring.MonitoringLogService) Lakare(se.inera.intyg.webcert.web.service.dto.Lakare) WebCertUserService(se.inera.intyg.webcert.web.service.user.WebCertUserService) CertificateSenderService(se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderService) Fk7263EntryPoint(se.inera.intyg.common.fk7263.support.Fk7263EntryPoint) UtkastRepository(se.inera.intyg.webcert.persistence.utkast.repository.UtkastRepository) SendMessageToRecipientTypeConverter(se.inera.intyg.webcert.common.client.converter.SendMessageToRecipientTypeConverter) ArendeAmne(se.inera.intyg.webcert.persistence.arende.model.ArendeAmne) Map(java.util.Map) HsaEmployeeService(se.inera.intyg.infra.integration.hsa.services.HsaEmployeeService) SendMessageToRecipientType(se.riv.clinicalprocess.healthcond.certificate.sendMessageToRecipient.v2.SendMessageToRecipientType) Status(se.inera.intyg.webcert.persistence.model.Status) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) AuthoritiesValidator(se.inera.intyg.infra.security.authorities.validation.AuthoritiesValidator) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Predicate(java.util.function.Predicate) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Set(java.util.Set) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Objects(java.util.Objects) QueryFragaSvarParameter(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarParameter) AnsweredWithIntyg(se.inera.intyg.webcert.web.web.controller.api.dto.AnsweredWithIntyg) List(java.util.List) NotificationEvent(se.inera.intyg.webcert.web.service.notification.NotificationEvent) ArendeConversationView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView) FrageStallare(se.inera.intyg.webcert.web.service.fragasvar.dto.FrageStallare) NotNull(org.jetbrains.annotations.NotNull) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Filter(se.inera.intyg.webcert.persistence.model.Filter) FragaSvarService(se.inera.intyg.webcert.web.service.fragasvar.FragaSvarService) SendMessageToRecipientTypeBuilder(se.inera.intyg.webcert.web.integration.builders.SendMessageToRecipientTypeBuilder) CertificateSenderException(se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderException) ArendeListItem(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GroupableItem(se.inera.intyg.webcert.common.model.GroupableItem) Value(org.springframework.beans.factory.annotation.Value) ArendeConverter(se.inera.intyg.webcert.web.converter.ArendeConverter) Strings(com.google.common.base.Strings) ArendeListItemConverter(se.inera.intyg.webcert.web.converter.ArendeListItemConverter) TsBasEntryPoint(se.inera.intyg.common.ts_bas.support.TsBasEntryPoint) Service(org.springframework.stereotype.Service) AuthoritiesHelper(se.inera.intyg.infra.security.authorities.AuthoritiesHelper) AnsweredWithIntygUtil(se.inera.intyg.webcert.web.converter.util.AnsweredWithIntygUtil) StatisticsGroupByUtil(se.inera.intyg.webcert.web.service.util.StatisticsGroupByUtil) ArendeViewConverter(se.inera.intyg.webcert.web.converter.ArendeViewConverter) NotificationService(se.inera.intyg.webcert.web.service.notification.NotificationService) Logger(org.slf4j.Logger) ArendeRepository(se.inera.intyg.webcert.persistence.arende.repository.ArendeRepository) TsDiabetesEntryPoint(se.inera.intyg.common.ts_diabetes.support.TsDiabetesEntryPoint) WebCertServiceErrorCodeEnum(se.inera.intyg.webcert.common.service.exception.WebCertServiceErrorCodeEnum) QueryFragaSvarResponse(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Clock(java.time.Clock) FilterConverter(se.inera.intyg.webcert.web.converter.FilterConverter) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AuthoritiesConstants(se.inera.intyg.infra.security.common.model.AuthoritiesConstants) Comparator(java.util.Comparator) Transactional(org.springframework.transaction.annotation.Transactional) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Fk7263EntryPoint(se.inera.intyg.common.fk7263.support.Fk7263EntryPoint) TsBasEntryPoint(se.inera.intyg.common.ts_bas.support.TsBasEntryPoint) TsDiabetesEntryPoint(se.inera.intyg.common.ts_diabetes.support.TsDiabetesEntryPoint) QueryFragaSvarResponse(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse) Personnummer(se.inera.intyg.schemas.contract.Personnummer) ArendeListItem(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem) Filter(se.inera.intyg.webcert.persistence.model.Filter) Objects(java.util.Objects) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with QueryFragaSvarResponse

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());
}
Also used : Filter(se.inera.intyg.webcert.persistence.model.Filter) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) QueryFragaSvarResponse(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse) Test(org.junit.Test)

Example 10 with QueryFragaSvarResponse

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());
}
Also used : Filter(se.inera.intyg.webcert.persistence.model.Filter) QueryFragaSvarParameter(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarParameter) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) QueryFragaSvarResponse(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse) Test(org.junit.Test)

Aggregations

QueryFragaSvarResponse (se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse)12 Filter (se.inera.intyg.webcert.persistence.model.Filter)10 Test (org.junit.Test)9 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)8 MedicinsktArende (se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende)8 QueryFragaSvarParameter (se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarParameter)8 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)4 Matchers.anyString (org.mockito.Matchers.anyString)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Personnummer (se.inera.intyg.schemas.contract.Personnummer)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 Strings (com.google.common.base.Strings)1 Clock (java.time.Clock)1 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1