Search in sources :

Example 6 with QueryIntygResponse

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

the class UtkastApiControllerIT method testFilterDraftsForUnitVardAdminPagination.

@Test
public void testFilterDraftsForUnitVardAdminPagination() {
    RestAssured.sessionId = getAuthSession(DEFAULT_LAKARE);
    ArrayList<String> utkastIds = new ArrayList(), utkastPersonIds = new ArrayList();
    for (int i = 0; i < 2; i++) {
        // Sekretessmarkering på patient
        utkastIds.add(createUtkast("lisjp", "195401232540"));
        utkastPersonIds.add("19540123-2540");
        for (int j = 0; j < 8; j++) {
            utkastIds.add(createUtkast("lisjp", DEFAULT_PATIENT_PERSONNUMMER));
            utkastPersonIds.add(DEFAULT_PATIENT_PERSONNUMMER);
        }
    }
    // The newest utkast will be returned first, reverse the expected list
    Collections.reverse(utkastIds);
    Collections.reverse(utkastPersonIds);
    changeRoleTo("VARDADMINISTRATOR");
    // Should only get totalCount=16 since we added 2 patients with sekretessmarkering
    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(16)).extract().response().as(QueryIntygResponse.class);
    Assert.assertEquals(4, queryResponse.getResults().size());
    // Disabled. See comment on testFilterDraftsForUnitPagination
    /*        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", 14).expect().statusCode(200).when().get("api/utkast").then().body(matchesJsonSchemaInClasspath("jsonschema/webcert-query-utkast-response-schema.json")).body("totalCount", equalTo(16)).extract().response().as(QueryIntygResponse.class);
    Assert.assertEquals(2, queryResponse2.getResults().size());
// With pagesize=4 and startFrom=14 we will get the last 2 entries.
// Without sekretess markering the 2 entries would have matched 16 and 17.
// Since 17 is sekretess and filtered out we will get 15 and 16
/*        ListIntygEntry entry = queryResponse2.getResults().get(0);
        Assert.assertEquals(utkastIds.get(15), entry.getIntygId());
        Assert.assertEquals("fk7263", entry.getIntygType());
        Assert.assertEquals(utkastPersonIds.get(15), entry.getPatientId().getPersonnummer());

        entry = queryResponse2.getResults().get(1);
        Assert.assertEquals(utkastIds.get(16), entry.getIntygId());
        Assert.assertEquals("fk7263", entry.getIntygType());
        Assert.assertEquals(utkastPersonIds.get(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)

Example 7 with QueryIntygResponse

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

the class UtkastApiControllerIT method testFilterDraftsForUnit.

/**
 * Verify that filtering by enhetId and hsaId returns expected results.
 */
@Test
public void testFilterDraftsForUnit() {
    RestAssured.sessionId = getAuthSession(DEFAULT_LAKARE);
    String utkastId = createUtkast("ts-bas", DEFAULT_PATIENT_PERSONNUMMER);
    QueryIntygResponse queryResponse = given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).param("savedBy", DEFAULT_LAKARE.getHsaId()).param("enhetsId", DEFAULT_LAKARE.getEnhetId()).expect().statusCode(200).when().get("api/utkast").then().body(matchesJsonSchemaInClasspath("jsonschema/webcert-query-utkast-response-schema.json")).body("totalCount", equalTo(1)).extract().response().as(QueryIntygResponse.class);
    // The only result should match the utkast we created in the setup
    Assert.assertEquals(utkastId, queryResponse.getResults().get(0).getIntygId());
    Assert.assertEquals("ts-bas", queryResponse.getResults().get(0).getIntygType());
    Assert.assertEquals(formatPersonnummer(DEFAULT_PATIENT_PERSONNUMMER), queryResponse.getResults().get(0).getPatientId().getPersonnummer());
}
Also used : QueryIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.QueryIntygResponse) Test(org.junit.Test) BaseRestIntegrationTest(se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest)

Example 8 with QueryIntygResponse

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

the class UtkastApiController method performUtkastFilterQuery.

private QueryIntygResponse performUtkastFilterQuery(UtkastFilter filter) {
    // INTYG-4486: We can not get a totalCount with pageSize set if since we need to lookup/verify
    // sekretess!=UNDEFINED each entry from puService - even if user has authority to view sekretessmarkerade
    // resources.
    Integer pageSize = filter.getPageSize();
    filter.setPageSize(null);
    List<ListIntygEntry> listIntygEntries = IntygDraftsConverter.convertUtkastsToListIntygEntries(utkastService.filterIntyg(filter));
    // INTYG-4486, INTYG-4086: Always filter out any items with UNDEFINED sekretessmarkering status and not
    // authorized
    Map<Personnummer, SekretessStatus> sekretessStatusMap = patientDetailsResolver.getSekretessStatusForList(listIntygEntries.stream().map(lie -> lie.getPatientId()).collect(Collectors.toList()));
    final WebCertUser user = getWebCertUserService().getUser();
    listIntygEntries = listIntygEntries.stream().filter(lie -> this.passesSekretessCheck(lie.getPatientId(), lie.getIntygType(), user, sekretessStatusMap)).collect(Collectors.toList());
    // INTYG-4086: Mark all remaining ListIntygEntry having a patient with sekretessmarkering
    listIntygEntries.stream().forEach(lie -> markSekretessMarkering(lie, sekretessStatusMap));
    int totalCountOfFilteredIntyg = listIntygEntries.size();
    // logic
    if (filter.getStartFrom() < listIntygEntries.size()) {
        int toIndex = filter.getStartFrom() + pageSize;
        if (toIndex > listIntygEntries.size()) {
            toIndex = listIntygEntries.size();
        }
        listIntygEntries = listIntygEntries.subList(filter.getStartFrom(), toIndex);
    } else {
        // Index out of range
        listIntygEntries.clear();
    }
    QueryIntygResponse response = new QueryIntygResponse(listIntygEntries);
    response.setTotalCount(totalCountOfFilteredIntyg);
    return response;
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) QueryIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.QueryIntygResponse) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) ListIntygEntry(se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

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