Search in sources :

Example 36 with Personnummer

use of se.inera.intyg.schemas.contract.Personnummer in project webcert by sklintyg.

the class SrsApiController method setConsent.

@PUT
@Path("/consent/{personnummer}/{hsaId}")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Set consent for patient and careunit", httpMethod = "PUT", produces = MediaType.APPLICATION_JSON)
public Response setConsent(@ApiParam(value = "Personnummer") @PathParam("personnummer") String personnummer, @ApiParam(value = "HsaId för vårdenhet") @PathParam("hsaId") String hsaId, boolean consent) {
    authoritiesValidator.given(getWebCertUserService().getUser()).features(AuthoritiesConstants.FEATURE_SRS).orThrow();
    try {
        Personnummer p = createPnr(personnummer);
        ResultCodeEnum result = srsService.setConsent(hsaId, p, consent);
        monitoringLog.logSetSrsConsent(p, consent);
        return Response.ok(result).build();
    } catch (InvalidPersonNummerException e) {
        return Response.status(Response.Status.BAD_REQUEST).build();
    }
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) InvalidPersonNummerException(se.inera.intyg.schemas.contract.InvalidPersonNummerException) ResultCodeEnum(se.riv.clinicalprocess.healthcond.certificate.types.v2.ResultCodeEnum) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT)

Example 37 with Personnummer

use of se.inera.intyg.schemas.contract.Personnummer 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 38 with Personnummer

use of se.inera.intyg.schemas.contract.Personnummer in project webcert by sklintyg.

the class CopyUtkastServiceImpl method createUtkastFromTemplate.

@Override
public CreateUtkastFromTemplateResponse createUtkastFromTemplate(CreateUtkastFromTemplateRequest copyRequest) {
    String originalIntygId = copyRequest.getOriginalIntygId();
    LOG.debug("Creating utkast from template certificate '{}'", originalIntygId);
    WebCertUser user = userService.getUser();
    boolean coherentJournaling = user != null && user.getParameters() != null && user.getParameters().isSjf();
    try {
        if (intygService.isRevoked(copyRequest.getOriginalIntygId(), copyRequest.getOriginalIntygTyp(), coherentJournaling)) {
            LOG.debug("Cannot create utkast from template certificate with id '{}', the certificate is revoked", originalIntygId);
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Original certificate is revoked");
        }
        String intygsTyp = copyRequest.getTyp();
        if (authoritiesValidator.given(user, intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG, AuthoritiesConstants.FEATURE_UNIKT_INTYG_INOM_VG, AuthoritiesConstants.FEATURE_UNIKT_UTKAST_INOM_VG).isVerified()) {
            Personnummer personnummer = copyRequest.containsNyttPatientPersonnummer() ? copyRequest.getNyttPatientPersonnummer() : copyRequest.getPatient().getPersonId();
            Map<String, Map<String, Boolean>> intygstypToStringToBoolean = utkastService.checkIfPersonHasExistingIntyg(personnummer, user);
            Boolean utkastExists = intygstypToStringToBoolean.get("utkast").get(intygsTyp);
            Boolean intygExists = intygstypToStringToBoolean.get("intyg").get(intygsTyp);
            if (utkastExists != null && utkastExists) {
                if (authoritiesValidator.given(user, intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_UTKAST_INOM_VG).isVerified()) {
                    throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Drafts of this type must be unique within this caregiver.");
                }
            }
            if (intygExists != null) {
                if (authoritiesValidator.given(user, intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG).isVerified()) {
                    throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Certificates of this type must be globally unique.");
                } else if (intygExists && authoritiesValidator.given(user, intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG_INOM_VG).isVerified()) {
                    throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Certificates of this type must be unique within this caregiver.");
                }
            }
        }
        verifyNotReplacedWithSigned(copyRequest.getOriginalIntygId(), "create utkast from template");
        CopyUtkastBuilderResponse builderResponse = buildUtkastFromTemplateBuilderResponse(copyRequest, originalIntygId, true, coherentJournaling);
        Utkast savedUtkast = saveAndNotify(builderResponse, user);
        if (copyRequest.isDjupintegrerad()) {
            checkIntegreradEnhet(builderResponse);
        }
        return new CreateUtkastFromTemplateResponse(savedUtkast.getIntygsTyp(), savedUtkast.getIntygsId(), originalIntygId);
    } catch (ModuleException | ModuleNotFoundException me) {
        LOG.error("Module exception occured when trying to make a copy of " + originalIntygId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, me);
    }
}
Also used : CreateUtkastFromTemplateResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) Map(java.util.Map) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 39 with Personnummer

use of se.inera.intyg.schemas.contract.Personnummer in project webcert by sklintyg.

the class NotificationPatientEnricher method enrichWithPatient.

public void enrichWithPatient(Intyg intyg) throws TemporaryException {
    // INTYG-4190, hämta patientens uppgifter från PU-tjänsten och klistra in i utlåtandet.
    String intygsTyp = intyg.getTyp().getCode();
    switch(intygsTyp.toLowerCase()) {
        case "luse":
        case "luae_na":
        case "luae_fs":
        case "lisjp":
            String personId = intyg.getPatient().getPersonId().getExtension();
            Personnummer personnummer = Personnummer.createPersonnummer(personId).orElseThrow(() -> new IllegalArgumentException("Cannot create Personummer object from personId: " + personId));
            PersonSvar personSvar = puService.getPerson(personnummer);
            if (personSvar.getStatus() == PersonSvar.Status.FOUND) {
                if (!personSvar.getPerson().isSekretessmarkering()) {
                    intyg.setPatient(buildPatientFromPersonSvar(personSvar.getPerson()));
                } else {
                    intyg.getPatient().setEfternamn(SEKRETESSMARKERING);
                    intyg.getPatient().setFornamn(EMPTY_STRING);
                    intyg.getPatient().setMellannamn(EMPTY_STRING);
                    intyg.getPatient().setPostadress(EMPTY_STRING);
                    intyg.getPatient().setPostnummer(EMPTY_STRING);
                    intyg.getPatient().setPostort(EMPTY_STRING);
                }
            } else if (personSvar.getStatus() == PersonSvar.Status.ERROR) {
                throw new TemporaryException(new IllegalStateException("Could not query PU-service for enriching notification with patient data."));
            } else {
                LOG.warn("PU-service returned NOT_FOUND for personnummer: {}, not enriching notification.", personnummer.getPersonnummerHash());
            }
            break;
        default:
            // Do nothing
            break;
    }
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) TemporaryException(se.inera.intyg.webcert.common.sender.exception.TemporaryException) PersonSvar(se.inera.intyg.infra.integration.pu.model.PersonSvar)

Example 40 with Personnummer

use of se.inera.intyg.schemas.contract.Personnummer in project webcert by sklintyg.

the class GetPrivatePractitionerResponderStub method getGetPrivatePractitionerResponseTypeForPnr.

private GetPrivatePractitionerResponseType getGetPrivatePractitionerResponseTypeForPnr(GetPrivatePractitionerType parameters) {
    String id = parameters.getPersonalIdentityNumber();
    Personnummer personnummer = Personnummer.createPersonnummer(id).orElse(null);
    GetPrivatePractitionerResponseType response = new GetPrivatePractitionerResponseType();
    // if matching -- create error response
    if (PERSONNUMMER_ERROR_RESPONSE.equals(id)) {
        response.setHoSPerson(null);
        response.setResultCode(ResultCodeEnum.ERROR);
        response.setResultText("FAILURE: an error occured while trying to get private practitioner with personal identity number: " + Personnummer.getPersonnummerHashSafe(personnummer) + " exists.");
        return response;
    }
    // if matching -- throw exception
    if (PERSONNUMMER_THROW_EXCEPTION.equals(id)) {
        throw new SOAPFaultException(createSOAPFault());
    }
    HoSPersonType person = personStub.get(id);
    if (person == null) {
        response.setResultCode(ResultCodeEnum.INFO);
        response.setResultText("No private practitioner with personal identity number: " + Personnummer.getPersonnummerHashSafe(personnummer) + " exists.");
    } else {
        response.setHoSPerson(person);
        response.setResultCode(ResultCodeEnum.OK);
    }
    return response;
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) GetPrivatePractitionerResponseType(se.riv.infrastructure.directory.privatepractitioner.getprivatepractitionerresponder.v1.GetPrivatePractitionerResponseType) HoSPersonType(se.riv.infrastructure.directory.privatepractitioner.v1.HoSPersonType) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException)

Aggregations

Personnummer (se.inera.intyg.schemas.contract.Personnummer)44 Test (org.junit.Test)15 SekretessStatus (se.inera.intyg.webcert.common.model.SekretessStatus)15 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)11 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)11 PersonSvar (se.inera.intyg.infra.integration.pu.model.PersonSvar)8 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Response (javax.ws.rs.core.Response)6 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)6 LocalDateTime (java.time.LocalDateTime)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 GroupableItem (se.inera.intyg.webcert.common.model.GroupableItem)4 Collectors (java.util.stream.Collectors)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Fk7263EntryPoint (se.inera.intyg.common.fk7263.support.Fk7263EntryPoint)3