Search in sources :

Example 16 with ListIntygEntry

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

the class IntygApiControllerTest method testListIntyg.

@Test
public void testListIntyg() {
    // Mock call to Intygstjanst
    when(intygService.listIntyg(ENHET_IDS, PNR)).thenReturn(intygItemListResponse);
    Response response = intygCtrl.listDraftsAndIntygForPerson(PNR.getPersonnummer());
    @SuppressWarnings("unchecked") List<ListIntygEntry> res = (List<ListIntygEntry>) response.getEntity();
    assertNotNull(res);
    assertEquals(2, res.size());
}
Also used : Response(javax.ws.rs.core.Response) ListIntygEntry(se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry) List(java.util.List) Test(org.junit.Test)

Example 17 with ListIntygEntry

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

the class IntygAPIControllerIT method testNotifiedOnUtkast.

@Test
public void testNotifiedOnUtkast() {
    RestAssured.sessionId = getAuthSession(DEFAULT_LAKARE);
    String utkastId = createUtkast("lisjp", DEFAULT_PATIENT_PERSONNUMMER);
    Map<String, String> pathParams = new HashMap<>();
    pathParams.put("intygsTyp", "lisjp");
    pathParams.put("intygsId", utkastId);
    pathParams.put("version", "0");
    NotifiedState notifiedState = new NotifiedState();
    notifiedState.setNotified(true);
    ListIntygEntry updatedIntyg = given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).contentType(ContentType.JSON).and().body(notifiedState).and().pathParams(pathParams).expect().statusCode(200).when().put("api/intyg/{intygsTyp}/{intygsId}/{version}/vidarebefordra").then().body(matchesJsonSchemaInClasspath("jsonschema/webcert-put-notified-utkast-response-schema.json")).extract().response().as(ListIntygEntry.class);
    assertNotNull(updatedIntyg);
    assertEquals(utkastId, updatedIntyg.getIntygId());
    assertEquals("lisjp", updatedIntyg.getIntygType());
    // it's been updated, so version should have been incremented
    assertEquals(1, updatedIntyg.getVersion());
    // and of course it should have been vidarebefordrad as we instructed
    assertTrue(updatedIntyg.isVidarebefordrad());
}
Also used : HashMap(java.util.HashMap) ListIntygEntry(se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry) NotifiedState(se.inera.intyg.webcert.web.web.controller.api.dto.NotifiedState) Test(org.junit.Test) BaseRestIntegrationTest(se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest)

Example 18 with ListIntygEntry

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

the class IntygApiController method listDraftsAndIntygForPerson.

/**
 * Compiles a list of Intyg from two data sources. Signed Intyg are
 * retrieved from IntygstjÀnst, drafts are retrieved from Webcerts db. Both
 * types of Intyg are converted and merged into one sorted list.
 *
 * @param personNummerIn personnummer
 * @return a Response carrying a list containing all Intyg for a person.
 */
@GET
@Path("/person/{personNummer}")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response listDraftsAndIntygForPerson(@PathParam("personNummer") String personNummerIn) {
    Personnummer personNummer = createPnr(personNummerIn);
    LOG.debug("Retrieving intyg for person {}", personNummer.getPersonnummerHash());
    // INTYG-4086 (epic) - make sure only users with HANTERA_SEKRETESSMARKERAD_PATIENT can list intyg for patient
    // with sekretessmarkering.
    SekretessStatus patientSekretess = patientDetailsResolver.getSekretessStatus(personNummer);
    if (patientSekretess == SekretessStatus.UNDEFINED) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Error checking sekretessmarkering state in PU-service.");
    }
    authoritiesValidator.given(getWebCertUserService().getUser()).privilegeIf(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, patientSekretess == SekretessStatus.TRUE).orThrow();
    List<String> enhetsIds = getEnhetIdsForCurrentUser();
    if (enhetsIds.isEmpty()) {
        LOG.error("Current user has no assignments");
        return Response.status(Status.BAD_REQUEST).build();
    }
    Pair<List<ListIntygEntry>, Boolean> intygItemListResponse = intygService.listIntyg(enhetsIds, personNummer);
    LOG.debug("Got #{} intyg", intygItemListResponse.getLeft().size());
    List<Utkast> utkastList;
    if (authoritiesValidator.given(getWebCertUserService().getUser()).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST).isVerified()) {
        Set<String> intygstyper = authoritiesHelper.getIntygstyperForPrivilege(getWebCertUserService().getUser(), AuthoritiesConstants.PRIVILEGE_VISA_INTYG);
        utkastList = utkastRepository.findDraftsByPatientAndEnhetAndStatus(DaoUtil.formatPnrForPersistence(personNummer), enhetsIds, ALL_DRAFTS, intygstyper);
        LOG.debug("Got #{} utkast", utkastList.size());
    } else {
        utkastList = Collections.emptyList();
    }
    List<ListIntygEntry> allIntyg = IntygDraftsConverter.merge(intygItemListResponse.getLeft(), utkastList);
    // INTYG-4477
    if (patientSekretess == SekretessStatus.TRUE) {
        Set<String> allowedTypes = authoritiesHelper.getIntygstyperAllowedForSekretessmarkering();
        allIntyg = allIntyg.stream().filter(intyg -> allowedTypes.contains(intyg.getIntygType())).collect(Collectors.toList());
    }
    Response.ResponseBuilder responseBuilder = Response.ok(allIntyg);
    if (intygItemListResponse.getRight()) {
        responseBuilder = responseBuilder.header(OFFLINE_MODE, Boolean.TRUE.toString());
    }
    return responseBuilder.build();
}
Also used : SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) ListIntygEntry(se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Response(javax.ws.rs.core.Response) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) List(java.util.List)

Example 19 with ListIntygEntry

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

the class IntygApiController method setNotifiedOnIntyg.

/**
 * Sets the notified flag on an Intyg.
 *
 * @param intygsId      Id of the Intyg
 * @param notifiedState True or False
 * @return Response
 */
@PUT
@Path("/{intygsTyp}/{intygsId}/{version}/vidarebefordra")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
@Consumes(MediaType.APPLICATION_JSON)
public Response setNotifiedOnIntyg(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId, @PathParam("version") long version, NotifiedState notifiedState) {
    authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST).privilege(AuthoritiesConstants.PRIVILEGE_VIDAREBEFORDRA_UTKAST).orThrow();
    Utkast updatedIntyg;
    try {
        updatedIntyg = utkastService.setNotifiedOnDraft(intygsId, version, notifiedState.isNotified());
    } catch (OptimisticLockException | OptimisticLockingFailureException e) {
        monitoringLogService.logUtkastConcurrentlyEdited(intygsId, intygsTyp);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.CONCURRENT_MODIFICATION, e.getMessage());
    }
    LOG.debug("Set forward to {} on intyg {} with id '{}'", new Object[] { updatedIntyg.getVidarebefordrad(), intygsTyp, updatedIntyg.getIntygsId() });
    ListIntygEntry intygEntry = IntygDraftsConverter.convertUtkastToListIntygEntry(updatedIntyg);
    return Response.ok(intygEntry).build();
}
Also used : OptimisticLockingFailureException(org.springframework.dao.OptimisticLockingFailureException) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) OptimisticLockException(javax.persistence.OptimisticLockException) ListIntygEntry(se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 20 with ListIntygEntry

use of se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry 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

ListIntygEntry (se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry)26 Test (org.junit.Test)16 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)12 Signatur (se.inera.intyg.webcert.persistence.utkast.model.Signatur)5 List (java.util.List)4 Response (javax.ws.rs.core.Response)3 Personnummer (se.inera.intyg.schemas.contract.Personnummer)3 SekretessStatus (se.inera.intyg.webcert.common.model.SekretessStatus)3 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)2 ListCertificatesForCareType (se.riv.clinicalprocess.healthcond.certificate.listcertificatesforcare.v3.ListCertificatesForCareType)2 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 OptimisticLockException (javax.persistence.OptimisticLockException)1 WebServiceException (javax.xml.ws.WebServiceException)1 ArgumentMatchers.anyBoolean (org.mockito.ArgumentMatchers.anyBoolean)1 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 OptimisticLockingFailureException (org.springframework.dao.OptimisticLockingFailureException)1 IntygRelations (se.inera.intyg.clinicalprocess.healthcond.certificate.listrelationsforcertificate.v1.IntygRelations)1