Search in sources :

Example 1 with QueryIntygResponse

use of se.inera.intyg.webcert.web.web.controller.api.dto.QueryIntygResponse in project webcert by sklintyg.

the class UtkastApiController method filterDraftsForUnit.

/**
 * Creates a filtered query to get drafts for a specific unit.
 */
@GET
@Path("/")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response filterDraftsForUnit(@QueryParam("") QueryIntygParameter filterParameters) {
    authoritiesValidator.given(getWebCertUserService().getUser()).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST).orThrow();
    UtkastFilter utkastFilter = createUtkastFilter(filterParameters);
    QueryIntygResponse queryResponse = performUtkastFilterQuery(utkastFilter);
    return Response.ok(queryResponse).build();
}
Also used : QueryIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.QueryIntygResponse) UtkastFilter(se.inera.intyg.webcert.persistence.utkast.repository.UtkastFilter) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with QueryIntygResponse

use of se.inera.intyg.webcert.web.web.controller.api.dto.QueryIntygResponse in project webcert by sklintyg.

the class UtkastApiControllerTest method testFilterDraftsForUnitSkipsSekretessIntygForUserWithoutAuthorithy.

@Test
public void testFilterDraftsForUnitSkipsSekretessIntygForUserWithoutAuthorithy() {
    setupUser("", LuseEntryPoint.MODULE_ID, AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST);
    Map<Personnummer, SekretessStatus> sekretessMap = mock(Map.class);
    when(sekretessMap.get(eq(PATIENT_PERSONNUMMER))).thenReturn(SekretessStatus.FALSE);
    when(sekretessMap.get(eq(PATIENT_PERSONNUMMER_PU_SEKRETESS))).thenReturn(SekretessStatus.TRUE);
    when(patientDetailsResolver.getSekretessStatusForList(anyList())).thenReturn(sekretessMap);
    when(utkastService.filterIntyg(any())).thenReturn(Arrays.asList(buildUtkast(PATIENT_PERSONNUMMER), buildUtkast(PATIENT_PERSONNUMMER_PU_SEKRETESS)));
    final Response response = utkastController.filterDraftsForUnit(buildQueryIntygParameter());
    final QueryIntygResponse queryIntygResponse = response.readEntity(QueryIntygResponse.class);
    assertEquals(1, queryIntygResponse.getTotalCount());
    assertEquals(1, queryIntygResponse.getResults().size());
    assertEquals(PATIENT_PERSONNUMMER, queryIntygResponse.getResults().get(0).getPatientId());
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) Response(javax.ws.rs.core.Response) QueryIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.QueryIntygResponse) QueryIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.QueryIntygResponse) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Test(org.junit.Test)

Example 3 with QueryIntygResponse

use of se.inera.intyg.webcert.web.web.controller.api.dto.QueryIntygResponse in project webcert by sklintyg.

the class UtkastApiControllerTest method testFilterDraftsForUnit.

@Test
public void testFilterDraftsForUnit() {
    setupUser(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, LuseEntryPoint.MODULE_ID, AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST);
    when(utkastService.filterIntyg(any())).thenReturn(Arrays.asList(buildUtkast(PATIENT_PERSONNUMMER), buildUtkast(PATIENT_PERSONNUMMER)));
    final Response response = utkastController.filterDraftsForUnit(buildQueryIntygParameter());
    final QueryIntygResponse queryIntygResponse = response.readEntity(QueryIntygResponse.class);
    assertEquals(2, queryIntygResponse.getTotalCount());
    assertEquals(2, queryIntygResponse.getResults().size());
}
Also used : Response(javax.ws.rs.core.Response) QueryIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.QueryIntygResponse) QueryIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.QueryIntygResponse) Test(org.junit.Test)

Example 4 with QueryIntygResponse

use of se.inera.intyg.webcert.web.web.controller.api.dto.QueryIntygResponse in project webcert by sklintyg.

the class UtkastApiControllerTest method testFilterDraftsForUnitSkipAllIntygWithUndefinedSekretessStatus.

@Test
public void testFilterDraftsForUnitSkipAllIntygWithUndefinedSekretessStatus() {
    setupUser(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, LuseEntryPoint.MODULE_ID, AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST);
    Map<Personnummer, SekretessStatus> sekretessMap = mock(Map.class);
    when(sekretessMap.get(any())).thenReturn(SekretessStatus.UNDEFINED);
    when(patientDetailsResolver.getSekretessStatusForList(anyList())).thenReturn(sekretessMap);
    when(utkastService.filterIntyg(any())).thenReturn(Arrays.asList(buildUtkast(PATIENT_PERSONNUMMER), buildUtkast(PATIENT_PERSONNUMMER)));
    final Response response = utkastController.filterDraftsForUnit(buildQueryIntygParameter());
    final QueryIntygResponse queryIntygResponse = response.readEntity(QueryIntygResponse.class);
    assertEquals(0, queryIntygResponse.getTotalCount());
    assertEquals(0, queryIntygResponse.getResults().size());
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) Response(javax.ws.rs.core.Response) QueryIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.QueryIntygResponse) QueryIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.QueryIntygResponse) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Test(org.junit.Test)

Example 5 with QueryIntygResponse

use of se.inera.intyg.webcert.web.web.controller.api.dto.QueryIntygResponse in project webcert by sklintyg.

the class UtkastApiControllerIT method testFilterDraftsForUnitPagination.

@Test
public void testFilterDraftsForUnitPagination() {
    RestAssured.sessionId = getAuthSession(DEFAULT_LAKARE);
    ArrayList<String> utkastIds = new ArrayList(), utkastPersonIds = new ArrayList();
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 8; j++) {
            utkastIds.add(createUtkast("luse", DEFAULT_PATIENT_PERSONNUMMER));
            utkastPersonIds.add(DEFAULT_PATIENT_PERSONNUMMER);
        }
        // Sekretessmarkering på patient
        utkastIds.add(createUtkast("luse", "195401232540"));
        utkastPersonIds.add("19540123-2540");
    }
    // The newest utkast will be returned first, reverse the expected list
    Collections.reverse(utkastIds);
    Collections.reverse(utkastPersonIds);
    QueryIntygResponse queryResponse = given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).param("savedBy", DEFAULT_LAKARE.getHsaId()).param("enhetsId", DEFAULT_LAKARE.getEnhetId()).param("pageSize", 4).expect().statusCode(200).when().get("api/utkast").then().body(matchesJsonSchemaInClasspath("jsonschema/webcert-query-utkast-response-schema.json")).body("totalCount", equalTo(18)).extract().response().as(QueryIntygResponse.class);
    Assert.assertEquals(4, queryResponse.getResults().size());
    // Removed verification of intyg in the response.
    // The timing resolution is too low on senastSparadDatum when running on the build environment.
    // When running locally with dev profile and h2 we get millisecond resolution and the test works.
    // We would need several seconds of sleep between createUtkast for this to work on the build environment.
    /*        for(int i = 0; i < 4; i++) {
            ListIntygEntry entry = queryResponse.getResults().get(i);
            Assert.assertEquals(utkastIds.get(i), entry.getIntygId());
            Assert.assertEquals("fk7263", entry.getIntygType());
            Assert.assertEquals(utkastPersonIds.get(i), entry.getPatientId().getPersonnummer());
        }*/
    QueryIntygResponse queryResponse2 = given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).param("savedBy", DEFAULT_LAKARE.getHsaId()).param("enhetsId", DEFAULT_LAKARE.getEnhetId()).param("pageSize", 4).param("startFrom", 16).expect().statusCode(200).when().get("api/utkast").then().body(matchesJsonSchemaInClasspath("jsonschema/webcert-query-utkast-response-schema.json")).body("totalCount", equalTo(18)).extract().response().as(QueryIntygResponse.class);
    Assert.assertEquals(2, queryResponse2.getResults().size());
/*        for(int i = 0; i < 2; i++) {
            ListIntygEntry entry = queryResponse2.getResults().get(i);
            Assert.assertEquals(utkastIds.get(i + 16), entry.getIntygId());
            Assert.assertEquals("fk7263", entry.getIntygType());
            Assert.assertEquals(utkastPersonIds.get(i + 16), entry.getPatientId().getPersonnummer());
        }*/
}
Also used : QueryIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.QueryIntygResponse) ArrayList(java.util.ArrayList) Test(org.junit.Test) BaseRestIntegrationTest(se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest)

Aggregations

QueryIntygResponse (se.inera.intyg.webcert.web.web.controller.api.dto.QueryIntygResponse)8 Test (org.junit.Test)6 Response (javax.ws.rs.core.Response)3 Personnummer (se.inera.intyg.schemas.contract.Personnummer)3 SekretessStatus (se.inera.intyg.webcert.common.model.SekretessStatus)3 BaseRestIntegrationTest (se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest)3 ArrayList (java.util.ArrayList)2 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 UtkastFilter (se.inera.intyg.webcert.persistence.utkast.repository.UtkastFilter)1 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)1 ListIntygEntry (se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry)1