Search in sources :

Example 31 with Personnummer

use of se.inera.intyg.schemas.contract.Personnummer 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 32 with Personnummer

use of se.inera.intyg.schemas.contract.Personnummer in project webcert by sklintyg.

the class PersonApiControllerTest method testGetPersonuppgifter.

@Test
public void testGetPersonuppgifter() {
    Personnummer personnummer = createPnr("19121212-1212");
    when(puService.getPerson(any(Personnummer.class))).thenReturn(new PersonSvar(new Person(personnummer, false, false, "fnamn", "mnamn", "enamn", "paddr", "pnr", "port"), PersonSvar.Status.FOUND));
    Response response = personCtrl.getPersonuppgifter(personnummer.getPersonnummer());
    assertNotNull(response);
    assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
    PersonuppgifterResponse res = (PersonuppgifterResponse) response.getEntity();
    assertEquals(PersonSvar.Status.FOUND, res.getStatus());
    assertEquals(false, res.getPerson().isSekretessmarkering());
    assertEquals("fnamn", res.getPerson().getFornamn());
    assertEquals("mnamn", res.getPerson().getMellannamn());
    assertEquals("enamn", res.getPerson().getEfternamn());
    assertEquals("paddr", res.getPerson().getPostadress());
    assertEquals("pnr", res.getPerson().getPostnummer());
    assertEquals("port", res.getPerson().getPostort());
    verify(mockMonitoringService).logPULookup(personnummer, "FOUND");
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) PersonuppgifterResponse(se.inera.intyg.webcert.web.web.controller.api.dto.PersonuppgifterResponse) Response(javax.ws.rs.core.Response) PersonuppgifterResponse(se.inera.intyg.webcert.web.web.controller.api.dto.PersonuppgifterResponse) PersonSvar(se.inera.intyg.infra.integration.pu.model.PersonSvar) Person(se.inera.intyg.infra.integration.pu.model.Person) Test(org.junit.Test)

Example 33 with Personnummer

use of se.inera.intyg.schemas.contract.Personnummer in project webcert by sklintyg.

the class PersonApiControllerTest method testGetPersonuppgifterSekretess.

@Test
public void testGetPersonuppgifterSekretess() {
    Personnummer personnummer = createPnr("19121212-1212");
    when(puService.getPerson(any(Personnummer.class))).thenReturn(new PersonSvar(new Person(personnummer, true, false, "fnamn", "mnamn", "enamn", "paddr", "pnr", "port"), PersonSvar.Status.FOUND));
    Response response = personCtrl.getPersonuppgifter(personnummer.getPersonnummer());
    assertNotNull(response);
    assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
    PersonuppgifterResponse res = (PersonuppgifterResponse) response.getEntity();
    assertEquals(PersonSvar.Status.FOUND, res.getStatus());
    assertEquals(true, res.getPerson().isSekretessmarkering());
    assertEquals("fnamn", res.getPerson().getFornamn());
    assertEquals("mnamn", res.getPerson().getMellannamn());
    assertEquals("enamn", res.getPerson().getEfternamn());
    assertEquals("paddr", res.getPerson().getPostadress());
    assertEquals("pnr", res.getPerson().getPostnummer());
    assertEquals("port", res.getPerson().getPostort());
    verify(mockMonitoringService).logPULookup(personnummer, "FOUND");
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) PersonuppgifterResponse(se.inera.intyg.webcert.web.web.controller.api.dto.PersonuppgifterResponse) Response(javax.ws.rs.core.Response) PersonuppgifterResponse(se.inera.intyg.webcert.web.web.controller.api.dto.PersonuppgifterResponse) PersonSvar(se.inera.intyg.infra.integration.pu.model.PersonSvar) Person(se.inera.intyg.infra.integration.pu.model.Person) Test(org.junit.Test)

Example 34 with Personnummer

use of se.inera.intyg.schemas.contract.Personnummer 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 35 with Personnummer

use of se.inera.intyg.schemas.contract.Personnummer in project webcert by sklintyg.

the class PersonApiController method getPersonuppgifter.

@GET
@Path("/{personnummer}")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response getPersonuppgifter(@PathParam("personnummer") String personnummerIn) {
    try {
        Personnummer personnummer = createPnr(personnummerIn);
        LOG.debug("Hämtar personuppgifter för: {}", personnummer.getPersonnummerHash());
        PersonSvar personSvar = puService.getPerson(personnummer);
        monitoringService.logPULookup(personnummer, personSvar.getStatus().name());
        return Response.ok(new PersonuppgifterResponse(personSvar)).build();
    } catch (InvalidPersonNummerException e) {
        LOG.error(e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).build();
    }
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) InvalidPersonNummerException(se.inera.intyg.schemas.contract.InvalidPersonNummerException) PersonuppgifterResponse(se.inera.intyg.webcert.web.web.controller.api.dto.PersonuppgifterResponse) PersonSvar(se.inera.intyg.infra.integration.pu.model.PersonSvar) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Personnummer (se.inera.intyg.schemas.contract.Personnummer)44 Test (org.junit.Test)15 SekretessStatus (se.inera.intyg.webcert.common.model.SekretessStatus)15 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)11 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)11 PersonSvar (se.inera.intyg.infra.integration.pu.model.PersonSvar)8 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Response (javax.ws.rs.core.Response)6 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)6 LocalDateTime (java.time.LocalDateTime)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 GroupableItem (se.inera.intyg.webcert.common.model.GroupableItem)4 Collectors (java.util.stream.Collectors)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Fk7263EntryPoint (se.inera.intyg.common.fk7263.support.Fk7263EntryPoint)3