Search in sources :

Example 1 with QueryFragaSvarResponse

use of se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse in project webcert by sklintyg.

the class ArendeServiceTest method testFilterArendeInvalidStartPosition.

@Test
public void testFilterArendeInvalidStartPosition() {
    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.getResults().add(buildArendeListItem("intyg1", LocalDateTime.now().minusDays(1)));
    fsResponse.setTotalCount(1);
    when(fragaSvarService.filterFragaSvar(any(Filter.class))).thenReturn(fsResponse);
    QueryFragaSvarParameter params = new QueryFragaSvarParameter();
    params.setStartFrom(5);
    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(0, response.getResults().size());
// assertEquals(4, 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)

Example 2 with QueryFragaSvarResponse

use of se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse in project webcert by sklintyg.

the class ArendeServiceTest method testFilterArendeFiltersOutNonVerifiedSekretessPatients.

@Test
@SuppressWarnings("unchecked")
public void testFilterArendeFiltersOutNonVerifiedSekretessPatients() {
    WebCertUser webCertUser = createUser();
    Map<Personnummer, SekretessStatus> map = mock(Map.class);
    when(map.get(any(Personnummer.class))).thenReturn(SekretessStatus.UNDEFINED);
    doReturn(map).when(patientDetailsResolver).getSekretessStatusForList(anyList());
    when(webcertUserService.getUser()).thenReturn(webCertUser);
    when(webcertUserService.isAuthorizedForUnit(any(), eq(true))).thenReturn(true);
    List<Arende> queryResults = new ArrayList<>();
    queryResults.add(buildArende(UUID.randomUUID().toString(), LocalDateTime.now(), null));
    queryResults.add(buildArende(UUID.randomUUID().toString(), LocalDateTime.now().minusDays(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();
    params.setEnhetId(webCertUser.getValdVardenhet().getId());
    QueryFragaSvarResponse response = service.filterArende(params);
    verify(patientDetailsResolver, times(1)).getSekretessStatusForList(anyList());
    verify(webcertUserService).isAuthorizedForUnit(anyString(), eq(true));
    verify(arendeRepository).filterArende(any(Filter.class));
    verify(fragaSvarService).filterFragaSvar(any(Filter.class));
    assertEquals(0, response.getResults().size());
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) 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) 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 3 with QueryFragaSvarResponse

use of se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse in project webcert by sklintyg.

the class ArendeServiceTest method testFilterArendeSelection.

@Test
public void testFilterArendeSelection() {
    when(webcertUserService.getUser()).thenReturn(createUser());
    when(authoritiesHelper.getIntygstyperForPrivilege(any(UserDetails.class), any())).thenReturn(new HashSet<>());
    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.getResults().add(buildArendeListItem("intyg1", LocalDateTime.now().minusDays(1)));
    fsResponse.setTotalCount(1);
    when(fragaSvarService.filterFragaSvar(any(Filter.class))).thenReturn(fsResponse);
    QueryFragaSvarParameter params = new QueryFragaSvarParameter();
    params.setStartFrom(2);
    params.setPageSize(10);
    QueryFragaSvarResponse response = service.filterArende(params);
    verify(webcertUserService).getUser();
    verify(arendeRepository, atLeastOnce()).filterArende(any(Filter.class));
    // verify(arendeRepository).filterArendeCount(any(Filter.class));
    verify(fragaSvarService).filterFragaSvar(any());
    assertEquals(1, response.getResults().size());
// assertEquals(4, 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)

Example 4 with QueryFragaSvarResponse

use of se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse in project webcert by sklintyg.

the class ArendeServiceTest method testFilterArendeSortsArendeListItemsByReceivedDate.

@Test
public void testFilterArendeSortsArendeListItemsByReceivedDate() {
    final String intygId1 = "intygId1";
    final String intygId2 = "intygId2";
    final String intygId3 = "intygId3";
    final String MEDDELANDE_ID = "arendeWithPaminnelseMEDDELANDE_ID";
    when(webcertUserService.getUser()).thenReturn(createUser());
    List<Arende> queryResults = new ArrayList<>();
    queryResults.add(buildArende(UUID.randomUUID().toString(), intygId3, LocalDateTime.now().plusDays(2), null, ENHET_ID));
    Arende arendeWithPaminnelse = buildArende(UUID.randomUUID().toString(), intygId2, LocalDateTime.now(), null, ENHET_ID);
    arendeWithPaminnelse.setMeddelandeId(MEDDELANDE_ID);
    queryResults.add(arendeWithPaminnelse);
    when(arendeRepository.filterArende(any(Filter.class))).thenReturn(queryResults);
    QueryFragaSvarResponse fsResponse = new QueryFragaSvarResponse();
    fsResponse.setResults(new ArrayList<>());
    fsResponse.getResults().add(buildArendeListItem(intygId1, LocalDateTime.now().minusDays(1)));
    fsResponse.setTotalCount(1);
    when(fragaSvarService.filterFragaSvar(any(Filter.class))).thenReturn(fsResponse);
    QueryFragaSvarParameter params = new QueryFragaSvarParameter();
    QueryFragaSvarResponse response = service.filterArende(params);
    assertEquals(3, response.getResults().size());
    assertEquals(intygId3, response.getResults().get(0).getIntygId());
    assertEquals(intygId2, response.getResults().get(1).getIntygId());
    assertEquals(intygId1, response.getResults().get(2).getIntygId());
}
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) Matchers.anyString(org.mockito.Matchers.anyString) QueryFragaSvarResponse(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse) Test(org.junit.Test)

Example 5 with QueryFragaSvarResponse

use of se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse in project webcert by sklintyg.

the class FragaSvarApiController method query.

@GET
@Path("/sok")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response query(@QueryParam("") QueryFragaSvarParameter queryParam) {
    authoritiesValidator.given(getWebCertUserService().getUser()).features(AuthoritiesConstants.FEATURE_HANTERA_FRAGOR).orThrow();
    QueryFragaSvarResponse result = arendeService.filterArende(queryParam);
    LOG.debug("/api/fragasvar/sok about to return : " + result.getTotalCount());
    return Response.ok(result).build();
}
Also used : QueryFragaSvarResponse(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

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