Search in sources :

Example 1 with SekretessStatus

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());
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Filter(se.inera.intyg.webcert.persistence.model.Filter) QueryFragaSvarParameter(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarParameter) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) QueryFragaSvarResponse(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse) Test(org.junit.Test)

Example 2 with SekretessStatus

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();
    }
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) InvalidPersonNummerException(se.inera.intyg.schemas.contract.InvalidPersonNummerException) IntygModule(se.inera.intyg.common.support.modules.registry.IntygModule) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with SekretessStatus

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();
}
Also used : ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) CreateNewDraftRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Map(java.util.Map) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 4 with SekretessStatus

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()));
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) AuthoritiesValidator(se.inera.intyg.infra.security.authorities.validation.AuthoritiesValidator) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) PatientDetailsResolver(se.inera.intyg.webcert.web.service.patient.PatientDetailsResolver) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) WebCertUserService(se.inera.intyg.webcert.web.service.user.WebCertUserService) Collectors(java.util.stream.Collectors) GroupableItem(se.inera.intyg.webcert.common.model.GroupableItem) Component(org.springframework.stereotype.Component) List(java.util.List) Map(java.util.Map) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) AuthoritiesConstants(se.inera.intyg.infra.security.common.model.AuthoritiesConstants) GroupableItem(se.inera.intyg.webcert.common.model.GroupableItem) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) HashMap(java.util.HashMap) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 5 with SekretessStatus

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"));
}
Also used : SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Aggregations

SekretessStatus (se.inera.intyg.webcert.common.model.SekretessStatus)20 Personnummer (se.inera.intyg.schemas.contract.Personnummer)14 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)9 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)7 Map (java.util.Map)5 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Response (javax.ws.rs.core.Response)3 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)3 GroupableItem (se.inera.intyg.webcert.common.model.GroupableItem)3 ListIntygEntry (se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry)3 LocalDateTime (java.time.LocalDateTime)2 Collectors (java.util.stream.Collectors)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 WebServiceException (javax.xml.ws.WebServiceException)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2