Search in sources :

Example 16 with SekretessStatus

use of se.inera.intyg.webcert.common.model.SekretessStatus 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 17 with SekretessStatus

use of se.inera.intyg.webcert.common.model.SekretessStatus 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 18 with SekretessStatus

use of se.inera.intyg.webcert.common.model.SekretessStatus 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)

Example 19 with SekretessStatus

use of se.inera.intyg.webcert.common.model.SekretessStatus in project webcert by sklintyg.

the class IntygServiceImpl method listIntyg.

@Override
public Pair<List<ListIntygEntry>, Boolean> listIntyg(List<String> enhetId, Personnummer personnummer) {
    ListCertificatesForCareType request = new ListCertificatesForCareType();
    request.setPersonId(InternalConverterUtil.getPersonId(personnummer));
    SekretessStatus sekretessmarkering = patientDetailsResolver.getSekretessStatus(personnummer);
    for (String id : enhetId) {
        request.getEnhetsId().add(InternalConverterUtil.getHsaId(id));
    }
    try {
        ListCertificatesForCareResponseType response = listCertificateService.listCertificatesForCare(logicalAddress, request);
        List<ListIntygEntry> fullIntygItemList = intygConverter.convertIntygToListIntygEntries(response.getIntygsLista().getIntyg());
        intygRelationHelper.decorateIntygListWithRelations(fullIntygItemList);
        fullIntygItemList = filterByIntygTypeForUser(fullIntygItemList, sekretessmarkering);
        addDraftsToListForIntygNotSavedInIntygstjansten(fullIntygItemList, enhetId, personnummer);
        return Pair.of(fullIntygItemList, Boolean.FALSE);
    } catch (WebServiceException wse) {
        LOG.warn("Error when connecting to intygstjänsten: {}", wse.getMessage());
    }
    // If intygstjansten was unavailable, we return whatever certificates we can find and clearly inform
    // the caller that the set of certificates are only those that have been issued by WebCert.
    List<ListIntygEntry> intygItems = buildIntygItemListFromDrafts(enhetId, personnummer);
    for (ListIntygEntry lie : intygItems) {
        lie.setRelations(certificateRelationService.getRelations(lie.getIntygId()));
    }
    return Pair.of(intygItems, Boolean.TRUE);
}
Also used : ListCertificatesForCareType(se.riv.clinicalprocess.healthcond.certificate.listcertificatesforcare.v3.ListCertificatesForCareType) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) WebServiceException(javax.xml.ws.WebServiceException) ListIntygEntry(se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry) ListCertificatesForCareResponseType(se.riv.clinicalprocess.healthcond.certificate.listcertificatesforcare.v3.ListCertificatesForCareResponseType)

Example 20 with SekretessStatus

use of se.inera.intyg.webcert.common.model.SekretessStatus in project webcert by sklintyg.

the class IntygServiceImpl method buildIntygContentHolderForUtkast.

// NOTE! INTYG-4086. This method is used when fetching Intyg/Utkast from WC locally. The question is, should we
// replace the patient on the existing model with a freshly fetched one here or not? In case we're storing patient
// info entered manually for non FK-types here, we may end up overwriting a manually stored name etc...
private IntygContentHolder buildIntygContentHolderForUtkast(Utkast utkast, boolean relations) {
    try {
        // INTYG-4086: Patient object populated according to ruleset for the intygstyp at hand.
        Patient newPatientData = patientDetailsResolver.resolvePatient(utkast.getPatientPersonnummer(), utkast.getIntygsTyp());
        // create an "empty" Patient with personnummer only.
        if (newPatientData == null) {
            newPatientData = new Patient();
            newPatientData.setPersonId(utkast.getPatientPersonnummer());
        }
        // INTYG-5354, INTYG-5380: Don't use incomplete address from external data sources (PU/js).
        Utlatande utlatande = modelFacade.getUtlatandeFromInternalModel(utkast.getIntygsTyp(), utkast.getModel());
        if (!completeAddressProvided(newPatientData)) {
            // Use the old address data.
            Patient oldPatientData = utlatande.getGrundData().getPatient();
            copyOldAddressToNewPatientData(oldPatientData, newPatientData);
        }
        String updatedModel = moduleRegistry.getModuleApi(utkast.getIntygsTyp()).updateBeforeSave(utkast.getModel(), newPatientData);
        utlatande = modelFacade.getUtlatandeFromInternalModel(utkast.getIntygsTyp(), updatedModel);
        List<Status> statuses = IntygConverterUtil.buildStatusesFromUtkast(utkast);
        Relations certificateRelations = certificateRelationService.getRelations(utkast.getIntygsId());
        final SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(newPatientData.getPersonId());
        if (SekretessStatus.UNDEFINED.equals(sekretessStatus)) {
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Sekretesstatus could not be fetched from the PU service");
        }
        final boolean sekretessmarkerad = SekretessStatus.TRUE.equals(sekretessStatus);
        boolean patientNameChanged = patientDetailsResolver.isPatientNamedChanged(utlatande.getGrundData().getPatient(), newPatientData);
        boolean patientAddressChanged = patientDetailsResolver.isPatientAddressChanged(utlatande.getGrundData().getPatient(), newPatientData);
        return IntygContentHolder.builder().setContents(updatedModel).setUtlatande(utlatande).setStatuses(statuses).setRevoked(utkast.getAterkalladDatum() != null).setRelations(certificateRelations).setCreated(utkast.getSkapad()).setDeceased(isDeceased(utkast.getPatientPersonnummer())).setSekretessmarkering(sekretessmarkerad).setPatientNameChangedInPU(patientNameChanged).setPatientAddressChangedInPU(patientAddressChanged).build();
    } catch (ModuleException | ModuleNotFoundException e) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e);
    }
}
Also used : UtkastStatus(se.inera.intyg.webcert.common.model.UtkastStatus) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Status(se.inera.intyg.common.support.model.Status) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Patient(se.inera.intyg.common.support.model.common.internal.Patient) Relations(se.inera.intyg.webcert.web.web.controller.api.dto.Relations) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) 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