use of se.inera.intyg.webcert.common.model.SekretessStatus in project webcert by sklintyg.
the class ArendeServiceTest method testFilterArendeFiltersOutNonVerifiedSekretessPatients.
@Test
@SuppressWarnings("unchecked")
public void testFilterArendeFiltersOutNonVerifiedSekretessPatients() {
WebCertUser webCertUser = createUser();
Map<Personnummer, SekretessStatus> map = mock(Map.class);
when(map.get(any(Personnummer.class))).thenReturn(SekretessStatus.UNDEFINED);
doReturn(map).when(patientDetailsResolver).getSekretessStatusForList(anyList());
when(webcertUserService.getUser()).thenReturn(webCertUser);
when(webcertUserService.isAuthorizedForUnit(any(), eq(true))).thenReturn(true);
List<Arende> queryResults = new ArrayList<>();
queryResults.add(buildArende(UUID.randomUUID().toString(), LocalDateTime.now(), null));
queryResults.add(buildArende(UUID.randomUUID().toString(), LocalDateTime.now().minusDays(1), null));
when(arendeRepository.filterArende(any(Filter.class))).thenReturn(queryResults);
QueryFragaSvarResponse fsResponse = new QueryFragaSvarResponse();
fsResponse.setResults(new ArrayList<>());
fsResponse.setTotalCount(0);
when(fragaSvarService.filterFragaSvar(any(Filter.class))).thenReturn(fsResponse);
QueryFragaSvarParameter params = new QueryFragaSvarParameter();
params.setEnhetId(webCertUser.getValdVardenhet().getId());
QueryFragaSvarResponse response = service.filterArende(params);
verify(patientDetailsResolver, times(1)).getSekretessStatusForList(anyList());
verify(webcertUserService).isAuthorizedForUnit(anyString(), eq(true));
verify(arendeRepository).filterArende(any(Filter.class));
verify(fragaSvarService).filterFragaSvar(any(Filter.class));
assertEquals(0, response.getResults().size());
}
use of se.inera.intyg.webcert.common.model.SekretessStatus in project webcert by sklintyg.
the class ModuleApiController method getModulesMap.
/**
* Serving module configuration populating selectors based on user.
*
* @return a JSON object
*/
@GET
@Path("/map/{patientId}")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response getModulesMap(@PathParam("patientId") String patientId) {
try {
Personnummer personnummer = createPnr(patientId);
SekretessStatus sekretessmarkering = patientDetailsResolver.getSekretessStatus(personnummer);
List<IntygModule> intygModules = moduleRegistry.listAllModules();
// If patient has sekretessmarkering or PU-service didn't respond, filter out ts-intyg using privilege.
if (sekretessmarkering == SekretessStatus.TRUE || sekretessmarkering == SekretessStatus.UNDEFINED) {
// INTYG-4086
intygModules = intygModules.stream().filter(module -> authoritiesValidator.given(getWebCertUserService().getUser(), module.getId()).privilege(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT).isVerified()).collect(Collectors.toList());
}
if (patientDetailsResolver.isAvliden(personnummer)) {
intygModules = intygModules.stream().filter(module -> authoritiesValidator.given(getWebCertUserService().getUser(), module.getId()).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST_AVLIDEN).isVerified()).collect(Collectors.toList());
}
return Response.ok(intygModules).build();
} catch (InvalidPersonNummerException e) {
LOG.error(e.getMessage());
return Response.status(Response.Status.BAD_REQUEST).build();
}
}
use of se.inera.intyg.webcert.common.model.SekretessStatus in project webcert by sklintyg.
the class UtkastApiController method createUtkast.
/**
* Create a new draft.
*/
@POST
@Path("/{intygsTyp}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response createUtkast(@PathParam("intygsTyp") String intygsTyp, CreateUtkastRequest request) {
try {
if (moduleRegistry.getIntygModule(intygsTyp).isDeprecated()) {
LOG.error("Request for deprecated module {}", intygsTyp);
return Response.status(Status.BAD_REQUEST).build();
}
} catch (ModuleNotFoundException e) {
LOG.error("Request for unknown module {}", intygsTyp);
return Response.status(Status.BAD_REQUEST).build();
}
authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST).privilege(AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG).orThrow();
final SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(request.getPatientPersonnummer());
if (SekretessStatus.UNDEFINED.equals(sekretessStatus)) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Could not fetch sekretesstatus for patient from PU service");
}
// INTYG-4086: If the patient is sekretessmarkerad, we need an additional check.
boolean sekr = sekretessStatus == SekretessStatus.TRUE;
if (sekr) {
authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).privilege(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT).orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, "User missing required privilege or cannot handle sekretessmarkerad patient"));
}
if (!request.isValid()) {
LOG.error("Request is invalid: " + request.toString());
return Response.status(Status.BAD_REQUEST).build();
}
LOG.debug("Attempting to create draft of type '{}'", intygsTyp);
if (authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG, AuthoritiesConstants.FEATURE_UNIKT_INTYG_INOM_VG, AuthoritiesConstants.FEATURE_UNIKT_UTKAST_INOM_VG).isVerified()) {
Map<String, Map<String, Boolean>> intygstypToStringToBoolean = utkastService.checkIfPersonHasExistingIntyg(request.getPatientPersonnummer(), getWebCertUserService().getUser());
Boolean utkastExists = intygstypToStringToBoolean.get("utkast").get(intygsTyp);
Boolean intygExists = intygstypToStringToBoolean.get("intyg").get(intygsTyp);
if (utkastExists != null && utkastExists) {
if (authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_UTKAST_INOM_VG).isVerified()) {
return Response.status(Status.BAD_REQUEST).build();
}
}
if (intygExists != null) {
if (authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG).isVerified()) {
return Response.status(Status.BAD_REQUEST).build();
} else if (intygExists && authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG_INOM_VG).isVerified()) {
return Response.status(Status.BAD_REQUEST).build();
}
}
}
CreateNewDraftRequest serviceRequest = createServiceRequest(request);
Utkast utkast = utkastService.createNewDraft(serviceRequest);
LOG.debug("Created a new draft of type '{}' with id '{}'", intygsTyp, utkast.getIntygsId());
return Response.ok().entity(utkast).build();
}
use of se.inera.intyg.webcert.common.model.SekretessStatus in project webcert by sklintyg.
the class StatisticsGroupByUtil method toSekretessFilteredMap.
/**
* Takes a list of object[] where each object[] is one of utkast, fraga/svar or arende represented as:
*
* [0] id (unique, this is what we want to count per enhetsId)
* [1] enhetsId
* [2] personnummer
*
* This method will filter out any items belonging to a patient having sekretessmarkering and return the result as a
* map: EnhetsId -> number of id for that unit.
*
* @param groupableItems
* Each item is an array of: id, enhetsId, personnummer, intygsTyp.
* @return
* Map with enhetsId -> count, with personummer being sekretessmarkerade has been removed.
*/
public Map<String, Long> toSekretessFilteredMap(List<GroupableItem> groupableItems) {
if (groupableItems == null || groupableItems.size() == 0) {
return new HashMap<>();
}
List<GroupableItem> filteredGroupableItems = getFilteredGroupableItemList(groupableItems);
WebCertUser user = webCertUserService.getUser();
Map<Personnummer, SekretessStatus> sekretessStatusMap = patientDetailsResolver.getSekretessStatusForList(getPersonummerList(filteredGroupableItems));
// update sekretess status
filteredGroupableItems.forEach(item -> item.setSekretessStatus(sekretessStatusMap.get(createPnr(item.getPersonnummer()))));
return filteredGroupableItems.stream().filter(item -> item.getSekretessStatus() != SekretessStatus.UNDEFINED).filter(item -> authoritiesValidator.given(user, item.getIntygsTyp()).privilegeIf(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, item.getSekretessStatus() == SekretessStatus.TRUE).isVerified()).collect(Collectors.groupingBy(GroupableItem::getEnhetsId, Collectors.counting()));
}
use of se.inera.intyg.webcert.common.model.SekretessStatus in project webcert by sklintyg.
the class IntegrationServiceImpl method verifySekretessmarkering.
void verifySekretessmarkering(Utkast utkast, WebCertUser user) {
SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(utkast.getPatientPersonnummer());
if (SekretessStatus.UNDEFINED.equals(sekretessStatus)) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Could not fetch sekretesstatus for patient from PU service");
}
authoritiesValidator.given(user, utkast.getIntygsTyp()).privilegeIf(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, sekretessStatus == SekretessStatus.TRUE).orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, "User missing required privilege or cannot handle sekretessmarkerad patient"));
}
Aggregations