Search in sources :

Example 11 with VardpersonReferens

use of se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens in project webcert by sklintyg.

the class NotificationMessageFactoryTest method createUtkast.

private Utkast createUtkast(String intygId) {
    VardpersonReferens vardperson = new VardpersonReferens();
    vardperson.setHsaId("SE12345678-0000");
    vardperson.setNamn("Dr Börje Dengroth");
    Utkast utkast = new Utkast();
    utkast.setIntygsId(intygId);
    utkast.setIntygsTyp(INTYGS_TYP);
    utkast.setEnhetsId("SE12345678-1000");
    utkast.setEnhetsNamn("Vårdenhet 1");
    utkast.setPatientPersonnummer(Personnummer.createPersonnummer("19121212-1212").get());
    utkast.setPatientFornamn("Tolvan");
    utkast.setPatientEfternamn("Tolvansson");
    utkast.setStatus(UtkastStatus.DRAFT_INCOMPLETE);
    utkast.setModel("{model}");
    utkast.setSkapadAv(vardperson);
    utkast.setSenastSparadAv(vardperson);
    return utkast;
}
Also used : Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) VardpersonReferens(se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens)

Example 12 with VardpersonReferens

use of se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens in project webcert by sklintyg.

the class UtkastApiControllerTest method buildUtkast.

private Utkast buildUtkast(Personnummer personnr) {
    Utkast utkast = new Utkast();
    utkast.setIntygsTyp("luse");
    utkast.setVardgivarId("456");
    utkast.setStatus(UtkastStatus.DRAFT_COMPLETE);
    utkast.setSenastSparadAv(new VardpersonReferens());
    utkast.setSenastSparadDatum(LocalDateTime.now());
    utkast.setPatientPersonnummer(personnr);
    return utkast;
}
Also used : Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) VardpersonReferens(se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens)

Example 13 with VardpersonReferens

use of se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens in project webcert by sklintyg.

the class SignaturServiceImpl method createDraftHash.

/**
 * Called from the Controller when initiating a client (e.g. NetID) signature. Rewritten in INTYG-5048 so
 * <i>starting</i> a signature process does NOT mutate the Utkast in any way. Instead, a temporary intyg JSON model
 * including the signatureDate and signing identity is stored in a {@link PagaendeSignering} entity.
 * <p>
 * Once the signing has been completed
 * (see {@link SignaturServiceImpl#createAndPersistSignature(Utkast, SignaturTicket, String, WebCertUser)}) the
 * hash, intygsId and version from the JSON model in the PagaendeSignatur is validated and if everything works out,
 * the final state is written to the Utkast table.
 * <p>
 * If the user for some reason failed to finish the signing (cancelled in NetID etc.), the Utkast table won't be
 * affected or contain a signingDate even though it wasn't signed. A stale entry may remain in PAGAENDE_SIGNERING
 * but since those cannot be reused such entries can remain there indefinitely or until cleaned up by a janitor
 * task.
 *
 * @param intygId The id of the draft to generate signing ticket for
 * @param version version
 * @return
 */
@Override
@Transactional("jpaTransactionManager")
public SignaturTicket createDraftHash(String intygId, long version) {
    LOG.debug("Hash for clientsignature of draft '{}'", intygId);
    // Fetch Webcert user
    WebCertUser user = getWebcertUserForSignering();
    // Fetch the certificate draft
    Utkast utkast = getUtkastForSignering(intygId, version, user);
    LocalDateTime signeringstid = LocalDateTime.now();
    try {
        VardpersonReferens vardpersonReferens = UpdateUserUtil.createVardpersonFromWebCertUser(user);
        ModuleApi moduleApi = moduleRegistry.getModuleApi(utkast.getIntygsTyp());
        Vardenhet vardenhetFromJson = moduleApi.getUtlatandeFromJson(utkast.getModel()).getGrundData().getSkapadAv().getVardenhet();
        String updatedInternal = moduleApi.updateBeforeSigning(utkast.getModel(), IntygConverterUtil.buildHosPersonalFromWebCertUser(user, vardenhetFromJson), signeringstid);
        // Skapa ny PagaendeSignering
        PagaendeSignering pagaendeSignering = new PagaendeSignering();
        pagaendeSignering.setIntygData(updatedInternal);
        pagaendeSignering.setIntygsId(utkast.getIntygsId());
        pagaendeSignering.setSigneradAvHsaId(vardpersonReferens.getHsaId());
        pagaendeSignering.setSigneradAvNamn(vardpersonReferens.getNamn());
        pagaendeSignering.setSigneringsDatum(signeringstid);
        pagaendeSignering = pagaendeSigneringRepository.save(pagaendeSignering);
        return createSignaturTicket(utkast.getIntygsId(), pagaendeSignering.getInternReferens(), utkast.getVersion(), updatedInternal, signeringstid);
    } catch (ModuleNotFoundException | IOException | ModuleException e) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Unable to sign certificate: " + e.getMessage());
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) PagaendeSignering(se.inera.intyg.webcert.persistence.utkast.model.PagaendeSignering) IOException(java.io.IOException) Vardenhet(se.inera.intyg.common.support.model.common.internal.Vardenhet) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) VardpersonReferens(se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with VardpersonReferens

use of se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens in project webcert by sklintyg.

the class SignaturServiceImpl method createAndPersistSignature.

private SignaturTicket createAndPersistSignature(Utkast utkast, SignaturTicket ticket, String rawSignature, WebCertUser user) {
    validateUniqueIntyg(user, utkast.getIntygsTyp(), utkast.getPatientPersonnummer());
    PagaendeSignering pagaendeSignering = pagaendeSigneringRepository.findOne(ticket.getPagaendeSigneringId());
    if (pagaendeSignering == null) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Can't complete signing of certificate, no PagaendeSignering found for interreferens " + ticket.getPagaendeSigneringId());
    }
    String payload = pagaendeSignering.getIntygData();
    if (!pagaendeSignering.getIntygsId().equals(utkast.getIntygsId())) {
        LOG.error("Signing of utkast '{}' failed since the intygsId ({}) on the Utkast is different from the one " + "on the signing operation ({})", utkast.getIntygsId(), pagaendeSignering.getIntygsId());
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Internal error signing utkast, the payload of utkast " + utkast.getIntygsId() + " has been modified since signing was initialized");
    }
    if (!ticket.getHash().equals(createHash(payload))) {
        LOG.error("Signing of utkast '{}' failed since the payload has been modified since signing was initialized", utkast.getIntygsId());
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Internal error signing utkast, the payload of utkast " + utkast.getIntygsId() + " has been modified since signing was initialized");
    }
    if (utkast.getVersion() != ticket.getVersion()) {
        LOG.error("Signing of utkast '{}' failed since the version on the utkast ({}) differs from when the signing was initialized ({})", utkast.getIntygsId(), utkast.getVersion(), ticket.getVersion());
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.CONCURRENT_MODIFICATION, "Cannot complete signing, Utkast version differs from signature ticket version.");
    }
    Signatur signatur = new Signatur(ticket.getSigneringstid(), user.getHsaId(), ticket.getIntygsId(), payload, ticket.getHash(), rawSignature);
    // Update user information ("senast sparat av")
    // Add signature to the utkast and set status as signed
    utkast.setSenastSparadAv(new VardpersonReferens(pagaendeSignering.getSigneradAvHsaId(), pagaendeSignering.getSigneradAvNamn()));
    utkast.setModel(payload);
    utkast.setSignatur(signatur);
    utkast.setStatus(UtkastStatus.SIGNED);
    // Persist utkast with added signature
    Utkast savedUtkast = utkastRepository.save(utkast);
    // Send to Intygstjanst
    intygService.storeIntyg(savedUtkast);
    // Remove PagaendeSignering
    pagaendeSigneringRepository.delete(ticket.getPagaendeSigneringId());
    return ticket;
}
Also used : Signatur(se.inera.intyg.webcert.persistence.utkast.model.Signatur) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) PagaendeSignering(se.inera.intyg.webcert.persistence.utkast.model.PagaendeSignering) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) VardpersonReferens(se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens)

Example 15 with VardpersonReferens

use of se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens in project webcert by sklintyg.

the class CopyUtkastServiceImplTest method createCopyUtkast.

private Utkast createCopyUtkast() {
    Utkast utkast = new Utkast();
    utkast.setIntygsId(INTYG_COPY_ID);
    utkast.setIntygsTyp(INTYG_TYPE);
    utkast.setPatientPersonnummer(PATIENT_SSN);
    utkast.setPatientFornamn(PATIENT_FNAME);
    utkast.setPatientMellannamn(PATIENT_MNAME);
    utkast.setPatientEfternamn(PATIENT_LNAME);
    utkast.setEnhetsId(VARDENHET_ID);
    utkast.setEnhetsNamn(VARDENHET_NAME);
    utkast.setVardgivarId(VARDGIVARE_ID);
    utkast.setVardgivarNamn(VARDGIVARE_NAME);
    utkast.setModel(INTYG_JSON);
    VardpersonReferens vpRef = new VardpersonReferens();
    vpRef.setHsaId(HOSPERSON_ID);
    vpRef.setNamn(HOSPERSON_NAME);
    utkast.setSenastSparadAv(vpRef);
    utkast.setSkapadAv(vpRef);
    return utkast;
}
Also used : Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) VardpersonReferens(se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens)

Aggregations

VardpersonReferens (se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens)33 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)21 Before (org.junit.Before)5 Signatur (se.inera.intyg.webcert.persistence.utkast.model.Signatur)5 Test (org.junit.Test)4 HoSPersonal (se.inera.intyg.common.support.model.common.internal.HoSPersonal)4 Vardenhet (se.inera.intyg.common.support.model.common.internal.Vardenhet)4 SchemaVersion (se.inera.intyg.common.support.modules.support.api.notification.SchemaVersion)4 IntygUser (se.inera.intyg.infra.security.common.model.IntygUser)4 TakResult (se.inera.intyg.webcert.integration.tak.model.TakResult)4 BaseCreateDraftCertificateTest (se.inera.intyg.webcert.web.integration.interactions.createdraftcertificate.BaseCreateDraftCertificateTest)4 IntegreradEnhetEntry (se.inera.intyg.webcert.web.integration.registry.dto.IntegreradEnhetEntry)4 ResultValidator (se.inera.intyg.webcert.web.integration.validators.ResultValidator)4 CreateNewDraftRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest)4 Vardgivare (se.inera.intyg.common.support.model.common.internal.Vardgivare)3 PagaendeSignering (se.inera.intyg.webcert.persistence.utkast.model.PagaendeSignering)3 CreateDraftCertificateResponseType (se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.CreateDraftCertificateResponseType)3 CreateDraftCertificateType (se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.CreateDraftCertificateType)3 Intyg (se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.Intyg)3 TypAvIntyg (se.riv.clinicalprocess.healthcond.certificate.types.v3.TypAvIntyg)3