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());
}
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");
}
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");
}
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();
}
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();
}
}
Aggregations