Search in sources :

Example 11 with SekretessStatus

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

the class IntygServiceImpl method getIntygData.

/**
 * Builds a IntygContentHolder by first trying to get the Intyg from intygstjansten. If
 * not found or the Intygstjanst couldn't be reached, the local Utkast - if available -
 * will be used instead.
 * <p>
 * Note that even when found, we check if we need to decorate the response with data from the utkast in order
 * to mitigate async send states. (E.g. a send may be in resend due to 3rd party issues, in that case decorate with
 * data about sent state from the Utkast)
 *
 * @param relations
 */
private IntygContentHolder getIntygData(String intygId, String typ, boolean relations) {
    try {
        CertificateResponse certificate = modelFacade.getCertificate(intygId, typ);
        String internalIntygJsonModel = certificate.getInternalModel();
        final Personnummer personId = certificate.getUtlatande().getGrundData().getPatient().getPersonId();
        // INTYG-4086: Patient object populated according to ruleset for the intygstyp at hand.
        // Since an FK-intyg never will have anything other than personId, try to fetch all using ruleset
        Patient newPatientData = patientDetailsResolver.resolvePatient(personId, typ);
        Utlatande utlatande = null;
        boolean patientNameChanged = false;
        boolean patientAddressChanged = false;
        try {
            utlatande = moduleRegistry.getModuleApi(typ).getUtlatandeFromJson(internalIntygJsonModel);
            patientNameChanged = patientDetailsResolver.isPatientNamedChanged(utlatande.getGrundData().getPatient(), newPatientData);
            patientAddressChanged = patientDetailsResolver.isPatientAddressChanged(utlatande.getGrundData().getPatient(), newPatientData);
        } catch (IOException e) {
            LOG.error("Failed to getUtlatandeFromJson intygsId {} while checking for updated patient information", intygId);
        }
        // parameters were available.
        if (newPatientData != null) {
            // Get the module api and use the "updateBeforeSave" to update the outbound "model" with the
            // Patient object.
            ModuleApi moduleApi = moduleRegistry.getModuleApi(typ);
            // INTYG-5354, INTYG-5380: Don't use incomplete address from external data sources (PU/js).
            if (!completeAddressProvided(newPatientData)) {
                // Use the old address data.
                Patient oldPatientData = utlatande.getGrundData().getPatient();
                copyOldAddressToNewPatientData(oldPatientData, newPatientData);
            }
            internalIntygJsonModel = moduleApi.updateBeforeSave(internalIntygJsonModel, newPatientData);
        }
        utkastIntygDecorator.decorateWithUtkastStatus(certificate);
        Relations certificateRelations = intygRelationHelper.getRelationsForIntyg(intygId);
        final SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(personId);
        if (SekretessStatus.UNDEFINED.equals(sekretessStatus)) {
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Sekretesstatus could not be fetched from the PU service");
        }
        final boolean sekretessmarkering = SekretessStatus.TRUE.equals(sekretessStatus);
        Utkast utkast = utkastRepository.findOneByIntygsIdAndIntygsTyp(intygId, typ);
        final LocalDateTime created = utkast != null ? utkast.getSkapad() : null;
        return IntygContentHolder.builder().setContents(internalIntygJsonModel).setUtlatande(certificate.getUtlatande()).setStatuses(certificate.getMetaData().getStatus()).setRevoked(certificate.isRevoked()).setRelations(certificateRelations).setCreated(created).setDeceased(isDeceased(personId)).setSekretessmarkering(sekretessmarkering).setPatientNameChangedInPU(patientNameChanged).setPatientAddressChangedInPU(patientAddressChanged).build();
    } catch (IntygModuleFacadeException me) {
        // It's possible the Intygstjanst hasn't received the Intyg yet, look for it locally before rethrowing
        // exception
        Utkast utkast = utkastRepository.findOneByIntygsIdAndIntygsTyp(intygId, typ);
        if (utkast == null) {
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, me);
        }
        return buildIntygContentHolderForUtkast(utkast, relations);
    } catch (WebServiceException wse) {
        // Something went wrong communication-wise, try to find a matching Utkast instead.
        Utkast utkast = utkastRepository.findOneByIntygsIdAndIntygsTyp(intygId, typ);
        if (utkast == null) {
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "Cannot get intyg. Intygstjansten was not reachable and the Utkast could " + "not be found, perhaps it was issued by a non-webcert system?");
        }
        return buildIntygContentHolderForUtkast(utkast, relations);
    } catch (ModuleNotFoundException | ModuleException e) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e);
    }
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ChronoLocalDateTime(java.time.chrono.ChronoLocalDateTime) LocalDateTime(java.time.LocalDateTime) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) WebServiceException(javax.xml.ws.WebServiceException) CertificateResponse(se.inera.intyg.common.support.modules.support.api.dto.CertificateResponse) Patient(se.inera.intyg.common.support.model.common.internal.Patient) Relations(se.inera.intyg.webcert.web.web.controller.api.dto.Relations) IOException(java.io.IOException) IntygModuleFacadeException(se.inera.intyg.webcert.web.service.intyg.converter.IntygModuleFacadeException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException)

Example 12 with SekretessStatus

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

the class ArendeServiceImpl method filterArende.

@Override
@Transactional(value = "jpaTransactionManager", readOnly = true)
public QueryFragaSvarResponse filterArende(QueryFragaSvarParameter filterParameters) {
    WebCertUser user = webcertUserService.getUser();
    Set<String> intygstyperForPrivilege = authoritiesHelper.getIntygstyperForPrivilege(user, AuthoritiesConstants.PRIVILEGE_VISA_INTYG);
    Filter filter;
    if (!Strings.isNullOrEmpty(filterParameters.getEnhetId())) {
        verifyEnhetsAuth(filterParameters.getEnhetId(), true);
        filter = FilterConverter.convert(filterParameters, Arrays.asList(filterParameters.getEnhetId()), intygstyperForPrivilege);
    } else {
        filter = FilterConverter.convert(filterParameters, user.getIdsOfSelectedVardenhet(), intygstyperForPrivilege);
    }
    int originalStartFrom = filter.getStartFrom();
    int originalPageSize = filter.getPageSize();
    // INTYG-4086: Do NOT perform any paging. We must first load all applicable QA / ärenden, then apply
    // sekretessmarkering filtering. THEN - we can do paging stuff in-memory. Very inefficient...
    filter.setStartFrom(null);
    filter.setPageSize(null);
    List<ArendeListItem> results = arendeRepository.filterArende(filter).stream().map(ArendeListItemConverter::convert).filter(Objects::nonNull).peek(item -> item.setPaminnelse(!arendeRepository.findByPaminnelseMeddelandeId(item.getMeddelandeId()).isEmpty())).collect(Collectors.toList());
    QueryFragaSvarResponse fsResults = fragaSvarService.filterFragaSvar(filter);
    results.addAll(fsResults.getResults());
    results.sort(Comparator.comparing(ArendeListItem::getReceivedDate).reversed());
    QueryFragaSvarResponse response = new QueryFragaSvarResponse();
    Map<Personnummer, SekretessStatus> sekretessStatusMap = patientDetailsResolver.getSekretessStatusForList(results.stream().map(ali -> Personnummer.createPersonnummer(ali.getPatientId()).get()).collect(Collectors.toList()));
    // INTYG-4086, INTYG-4486: Filter out any items that doesn't pass sekretessmarkering rules
    results = results.stream().filter(ali -> this.passesSekretessCheck(ali.getPatientId(), ali.getIntygTyp(), user, sekretessStatusMap)).collect(Collectors.toList());
    // We must mark all items having patient with sekretessmarkering
    results.stream().filter(ali -> hasSekretessStatus(ali, SekretessStatus.TRUE, sekretessStatusMap)).forEach(ali -> ali.setSekretessmarkering(true));
    response.setTotalCount(results.size());
    if (originalStartFrom >= results.size()) {
        response.setResults(new ArrayList<>());
    } else {
        response.setResults(results.subList(originalStartFrom, Math.min(originalPageSize + originalStartFrom, results.size())));
    }
    return response;
}
Also used : Arrays(java.util.Arrays) ArendeDraft(se.inera.intyg.webcert.persistence.arende.model.ArendeDraft) PatientDetailsResolver(se.inera.intyg.webcert.web.service.patient.PatientDetailsResolver) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) MonitoringLogService(se.inera.intyg.webcert.web.service.monitoring.MonitoringLogService) Lakare(se.inera.intyg.webcert.web.service.dto.Lakare) WebCertUserService(se.inera.intyg.webcert.web.service.user.WebCertUserService) CertificateSenderService(se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderService) Fk7263EntryPoint(se.inera.intyg.common.fk7263.support.Fk7263EntryPoint) UtkastRepository(se.inera.intyg.webcert.persistence.utkast.repository.UtkastRepository) SendMessageToRecipientTypeConverter(se.inera.intyg.webcert.common.client.converter.SendMessageToRecipientTypeConverter) ArendeAmne(se.inera.intyg.webcert.persistence.arende.model.ArendeAmne) Map(java.util.Map) HsaEmployeeService(se.inera.intyg.infra.integration.hsa.services.HsaEmployeeService) SendMessageToRecipientType(se.riv.clinicalprocess.healthcond.certificate.sendMessageToRecipient.v2.SendMessageToRecipientType) Status(se.inera.intyg.webcert.persistence.model.Status) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) AuthoritiesValidator(se.inera.intyg.infra.security.authorities.validation.AuthoritiesValidator) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Predicate(java.util.function.Predicate) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Set(java.util.Set) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Objects(java.util.Objects) QueryFragaSvarParameter(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarParameter) AnsweredWithIntyg(se.inera.intyg.webcert.web.web.controller.api.dto.AnsweredWithIntyg) List(java.util.List) NotificationEvent(se.inera.intyg.webcert.web.service.notification.NotificationEvent) ArendeConversationView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView) FrageStallare(se.inera.intyg.webcert.web.service.fragasvar.dto.FrageStallare) NotNull(org.jetbrains.annotations.NotNull) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Filter(se.inera.intyg.webcert.persistence.model.Filter) FragaSvarService(se.inera.intyg.webcert.web.service.fragasvar.FragaSvarService) SendMessageToRecipientTypeBuilder(se.inera.intyg.webcert.web.integration.builders.SendMessageToRecipientTypeBuilder) CertificateSenderException(se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderException) ArendeListItem(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GroupableItem(se.inera.intyg.webcert.common.model.GroupableItem) Value(org.springframework.beans.factory.annotation.Value) ArendeConverter(se.inera.intyg.webcert.web.converter.ArendeConverter) Strings(com.google.common.base.Strings) ArendeListItemConverter(se.inera.intyg.webcert.web.converter.ArendeListItemConverter) TsBasEntryPoint(se.inera.intyg.common.ts_bas.support.TsBasEntryPoint) Service(org.springframework.stereotype.Service) AuthoritiesHelper(se.inera.intyg.infra.security.authorities.AuthoritiesHelper) AnsweredWithIntygUtil(se.inera.intyg.webcert.web.converter.util.AnsweredWithIntygUtil) StatisticsGroupByUtil(se.inera.intyg.webcert.web.service.util.StatisticsGroupByUtil) ArendeViewConverter(se.inera.intyg.webcert.web.converter.ArendeViewConverter) NotificationService(se.inera.intyg.webcert.web.service.notification.NotificationService) Logger(org.slf4j.Logger) ArendeRepository(se.inera.intyg.webcert.persistence.arende.repository.ArendeRepository) TsDiabetesEntryPoint(se.inera.intyg.common.ts_diabetes.support.TsDiabetesEntryPoint) WebCertServiceErrorCodeEnum(se.inera.intyg.webcert.common.service.exception.WebCertServiceErrorCodeEnum) QueryFragaSvarResponse(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Clock(java.time.Clock) FilterConverter(se.inera.intyg.webcert.web.converter.FilterConverter) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AuthoritiesConstants(se.inera.intyg.infra.security.common.model.AuthoritiesConstants) Comparator(java.util.Comparator) Transactional(org.springframework.transaction.annotation.Transactional) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Fk7263EntryPoint(se.inera.intyg.common.fk7263.support.Fk7263EntryPoint) TsBasEntryPoint(se.inera.intyg.common.ts_bas.support.TsBasEntryPoint) TsDiabetesEntryPoint(se.inera.intyg.common.ts_diabetes.support.TsDiabetesEntryPoint) QueryFragaSvarResponse(se.inera.intyg.webcert.web.service.fragasvar.dto.QueryFragaSvarResponse) Personnummer(se.inera.intyg.schemas.contract.Personnummer) ArendeListItem(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeListItem) Filter(se.inera.intyg.webcert.persistence.model.Filter) Objects(java.util.Objects) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with SekretessStatus

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

the class BaseCreateDraftCertificateValidator method validateBusinessRulesForSekretessmarkeradPatient.

protected void validateBusinessRulesForSekretessmarkeradPatient(ResultValidator errors, Personnummer personnummer, String intygsTyp, IntygUser user) {
    if (personnummer != null) {
        final SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(personnummer);
        if (sekretessStatus != SekretessStatus.UNDEFINED) {
            validateSekretess(errors, intygsTyp, sekretessStatus);
            validateHsaUserMayCreateDraft(errors, user, sekretessStatus);
        }
    }
}
Also used : SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus)

Example 14 with SekretessStatus

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

the class StatisticsGroupByUtilTest method testFilterAndGroupForTwoResultsOfSameUnitOneIsSekrForVardadmin.

@Test
public void testFilterAndGroupForTwoResultsOfSameUnitOneIsSekrForVardadmin() {
    when(webCertUserService.getUser()).thenReturn(buildUserOfRole(AUTHORITIES_RESOLVER.getRole("VARDADMINISTRATOR")));
    Personnummer pnr1 = Personnummer.createPersonnummer(PNR1).get();
    Personnummer pnr2 = Personnummer.createPersonnummer(PNR2).get();
    Map<Personnummer, SekretessStatus> sekrMap = new HashMap<>();
    sekrMap.put(pnr1, SekretessStatus.FALSE);
    sekrMap.put(pnr2, SekretessStatus.TRUE);
    when(patientDetailsResolver.getSekretessStatusForList(anyList())).thenReturn(sekrMap);
    List<GroupableItem> queryResult = new ArrayList<>();
    queryResult.add(new GroupableItem("id-1", HSA1, PNR1, FK7263));
    queryResult.add(new GroupableItem("id-2", HSA1, PNR2, FK7263));
    // Should be filtered away
    queryResult.add(new GroupableItem("id-3", HSA1, PNR2, TSBAS));
    Map<String, Long> result = testee.toSekretessFilteredMap(queryResult);
    assertEquals(1, result.size());
    assertEquals(new Long(1L), result.get(HSA1));
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) GroupableItem(se.inera.intyg.webcert.common.model.GroupableItem) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 15 with SekretessStatus

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

the class StatisticsGroupByUtilTest method setup.

@Before
public void setup() {
    Personnummer pnr1 = Personnummer.createPersonnummer(PNR1).get();
    Personnummer pnr2 = Personnummer.createPersonnummer(PNR2).get();
    Personnummer pnr3 = Personnummer.createPersonnummer(PNR3).get();
    Map<Personnummer, SekretessStatus> sekrMap = new HashMap<>();
    sekrMap.put(pnr1, SekretessStatus.FALSE);
    sekrMap.put(pnr2, SekretessStatus.TRUE);
    sekrMap.put(pnr3, SekretessStatus.FALSE);
    when(patientDetailsResolver.getSekretessStatusForList(anyList())).thenReturn(sekrMap);
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) HashMap(java.util.HashMap) Before(org.junit.Before)

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