Search in sources :

Example 6 with Personnummer

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

the class NotificationPatientEnricher method buildPatientFromPersonSvar.

private se.riv.clinicalprocess.healthcond.certificate.v3.Patient buildPatientFromPersonSvar(Person person) {
    se.riv.clinicalprocess.healthcond.certificate.v3.Patient patient = new se.riv.clinicalprocess.healthcond.certificate.v3.Patient();
    Optional<Personnummer> personnummer = Optional.ofNullable(person.getPersonnummer());
    PersonId personId = new PersonId();
    personId.setRoot(SamordningsnummerValidator.isSamordningsNummer(personnummer) ? Constants.SAMORDNING_ID_OID : Constants.PERSON_ID_OID);
    personId.setExtension(personnummer.get().getPersonnummer());
    patient.setPersonId(personId);
    patient.setFornamn(nullSafe(person.getFornamn()));
    if (person.getMellannamn() != null) {
        patient.setMellannamn(person.getMellannamn());
    }
    patient.setEfternamn(nullSafe(person.getEfternamn()));
    patient.setPostadress(nullSafe(person.getPostadress()));
    patient.setPostnummer(nullSafe(person.getPostnummer()));
    patient.setPostort(nullSafe(person.getPostort()));
    return patient;
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) PersonId(se.riv.clinicalprocess.healthcond.certificate.types.v3.PersonId)

Example 7 with Personnummer

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

the class ValidatePrivatePractitionerResponderStub method validatePrivatePractitioner.

@Override
public ValidatePrivatePractitionerResponseType validatePrivatePractitioner(String logicalAddress, ValidatePrivatePractitionerType parameters) {
    // Do validation of parameters object
    validate(parameters);
    String id = parameters.getPersonalIdentityNumber();
    Personnummer personnummer = Personnummer.createPersonnummer(id).orElse(null);
    ValidatePrivatePractitionerResponseType response = new ValidatePrivatePractitionerResponseType();
    HoSPersonType person = personStub.get(id);
    if (person == null) {
        response.setResultCode(ResultCodeEnum.ERROR);
        response.setResultText("No private practitioner with personal identity number: " + Personnummer.getPersonnummerHashSafe(personnummer) + " exists.");
    } else if (person.isGodkandAnvandare()) {
        response.setResultCode(ResultCodeEnum.OK);
    } else {
        response.setResultCode(ResultCodeEnum.ERROR);
        response.setResultText("Private practitioner with personal identity number: " + Personnummer.getPersonnummerHashSafe(personnummer) + " is not authorized to use webcert.");
    }
    return response;
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) ValidatePrivatePractitionerResponseType(se.riv.infrastructure.directory.privatepractitioner.validateprivatepractitionerresponder.v1.ValidatePrivatePractitionerResponseType) HoSPersonType(se.riv.infrastructure.directory.privatepractitioner.v1.HoSPersonType)

Example 8 with Personnummer

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

the class CopyUtkastServiceImpl method refreshPatientDetailsFromPUService.

private Person refreshPatientDetailsFromPUService(AbstractCreateCopyRequest copyRequest) {
    Personnummer personnummer;
    if (copyRequest.containsNyttPatientPersonnummer()) {
        LOG.debug("Request contained a new personnummer to use for the copy");
        personnummer = copyRequest.getNyttPatientPersonnummer();
    } else {
        personnummer = copyRequest.getPatient().getPersonId();
    }
    LOG.debug("Refreshing person data to use for the copy");
    PersonSvar personSvar = getPersonSvar(personnummer);
    if (PersonSvar.Status.ERROR.equals(personSvar.getStatus())) {
        LOG.error("An error occured when using '{}' to lookup person data", personnummer.getPersonnummerHash());
        return null;
    } else if (PersonSvar.Status.NOT_FOUND.equals(personSvar.getStatus())) {
        LOG.error("No person data was found using '{}' to lookup person data", personnummer.getPersonnummerHash());
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "No person data found using '" + personnummer.getPersonnummerHash() + "'");
    }
    return personSvar.getPerson();
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) PersonSvar(se.inera.intyg.infra.integration.pu.model.PersonSvar) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 9 with Personnummer

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

the class UtkastServiceImpl method updatePatientOnDraft.

@Override
public void updatePatientOnDraft(UpdatePatientOnDraftRequest request) {
    // diff draftPatient and request patient: if no changes, do nothing
    String draftId = request.getDraftId();
    LOG.debug("Checking that Patient is up-to-date on Utkast '{}'", draftId);
    Utkast utkast = utkastRepository.findOne(draftId);
    if (utkast == null) {
        LOG.warn("Utkast '{}' was not found", draftId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "The utkast could not be found");
    }
    if (webCertUserService.getUser().getIdsOfAllVardenheter().stream().noneMatch(enhet -> enhet.equalsIgnoreCase(utkast.getEnhetsId()))) {
        LOG.error("User did not have any medarbetaruppdrag for enhet '{}'", utkast.getEnhetsId());
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, "User did not have any medarbetaruppdrag for enhet " + utkast.getEnhetsId());
    }
    // check that the draft hasn't been modified concurrently
    if (utkast.getVersion() != request.getVersion()) {
        LOG.debug("Utkast '{}' was concurrently modified", draftId);
        throw new OptimisticLockException(utkast.getSenastSparadAv().getNamn());
    }
    // check that the draft is still a draft
    if (!isTheDraftStillADraft(utkast.getStatus())) {
        LOG.error("Utkast '{}' can not be updated since it is no longer in draft mode", draftId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "This utkast can not be updated since it is no longer in draft mode");
    }
    final ModuleApi moduleApi = getModuleApi(utkast.getIntygsTyp());
    // INTYG-4086
    Patient draftPatient = getPatientFromCurrentDraft(moduleApi, utkast.getModel());
    Optional<Personnummer> optionalPnr = Optional.ofNullable(request.getPersonnummer());
    Optional<Personnummer> optionalDraftPnr = Optional.ofNullable(draftPatient.getPersonId());
    if (optionalDraftPnr.isPresent()) {
        // Spara undan det gamla personnummret temporärt
        String oldPersonId = optionalDraftPnr.get().getPersonnummer();
        webCertUserService.getUser().getParameters().setBeforeAlternateSsn(oldPersonId);
    }
    if ((optionalPnr.isPresent() || SamordningsnummerValidator.isSamordningsNummer(optionalPnr)) && !isHashEqual(optionalPnr, optionalDraftPnr)) {
        // INTYG-4086: Ta reda på om man skall kunna uppdatera annat än personnumret? Och om man uppdaterar
        // personnumret -
        // vilka regler gäller då för namn och adress? Samma regler som i PatientDetailsResolverImpl?
        draftPatient.setPersonId(optionalPnr.get());
        try {
            String updatedModel = moduleApi.updateBeforeSave(utkast.getModel(), draftPatient);
            updateUtkastModel(utkast, updatedModel);
            saveDraft(utkast);
            monitoringService.logUtkastPatientDetailsUpdated(utkast.getIntygsId(), utkast.getIntygsTyp());
            sendNotification(utkast, Event.CHANGED);
        } catch (ModuleException e) {
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, "Patient details on Utkast " + draftId + " could not be updated", e);
        }
    } else {
        LOG.debug("Utkast '{}' patient details were already up-to-date: no update needed", draftId);
    }
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) OptimisticLockException(javax.persistence.OptimisticLockException) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 10 with Personnummer

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

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