Search in sources :

Example 6 with Vardenhet

use of se.inera.intyg.common.support.model.common.internal.Vardenhet in project webcert by sklintyg.

the class HoSPersonHelper method createVardenhetFromIntygUser.

public static Vardenhet createVardenhetFromIntygUser(String enhetId, IntygUser user) {
    AbstractVardenhet enhet = HoSPersonHelper.findVardenhetEllerMottagning(user, enhetId).orElseThrow(() -> new IllegalStateException("User '" + user.getHsaId() + "' has no MIU for care unit '" + enhetId + "'"));
    if (enhet instanceof se.inera.intyg.infra.integration.hsa.model.Vardenhet) {
        se.inera.intyg.infra.integration.hsa.model.Vardenhet hsaVardenhet = (se.inera.intyg.infra.integration.hsa.model.Vardenhet) enhet;
        se.inera.intyg.infra.integration.hsa.model.Vardgivare hsaVardgivare = HoSPersonHelper.findVardgivare(user, hsaVardenhet.getVardgivareHsaId()).orElseThrow(() -> new IllegalStateException("Unable to find parent vÄrdgivare for vardenhet '" + enhetId + "'"));
        Vardenhet vardenhet = new Vardenhet();
        vardenhet.setEnhetsnamn(hsaVardenhet.getNamn());
        vardenhet.setEnhetsid(hsaVardenhet.getId());
        vardenhet.setArbetsplatsKod(hsaVardenhet.getArbetsplatskod());
        vardenhet.setPostadress(hsaVardenhet.getPostadress());
        vardenhet.setPostnummer(hsaVardenhet.getPostnummer());
        vardenhet.setPostort(hsaVardenhet.getPostort());
        vardenhet.setTelefonnummer(hsaVardenhet.getTelefonnummer());
        se.inera.intyg.common.support.model.common.internal.Vardgivare vardgivare = new se.inera.intyg.common.support.model.common.internal.Vardgivare();
        vardgivare.setVardgivarid(hsaVardgivare.getId());
        vardgivare.setVardgivarnamn(hsaVardgivare.getNamn());
        vardenhet.setVardgivare(vardgivare);
        return vardenhet;
    }
    if (enhet instanceof Mottagning) {
        Mottagning m = (Mottagning) enhet;
        se.inera.intyg.infra.integration.hsa.model.Vardgivare hsaVardgivare = HoSPersonHelper.findVardgivareForMottagning(user, m.getId()).orElseThrow(() -> new IllegalStateException("Unable to find parent vÄrdgivare for mottagning '" + enhetId + "'"));
        Vardenhet vardenhet = new Vardenhet();
        vardenhet.setEnhetsnamn(m.getNamn());
        vardenhet.setEnhetsid(m.getId());
        vardenhet.setArbetsplatsKod(m.getArbetsplatskod());
        vardenhet.setPostadress(m.getPostadress());
        vardenhet.setPostnummer(m.getPostnummer());
        vardenhet.setPostort(m.getPostort());
        vardenhet.setTelefonnummer(m.getTelefonnummer());
        se.inera.intyg.common.support.model.common.internal.Vardgivare vardgivare = new se.inera.intyg.common.support.model.common.internal.Vardgivare();
        vardgivare.setVardgivarid(hsaVardgivare.getId());
        vardgivare.setVardgivarnamn(hsaVardgivare.getNamn());
        vardenhet.setVardgivare(vardgivare);
        return vardenhet;
    }
    throw new IllegalArgumentException("AbstractVardenhet instance passed to createVardenhetFromIntygUser was of unsupported type: " + enhet.getClass().getName());
}
Also used : AbstractVardenhet(se.inera.intyg.infra.integration.hsa.model.AbstractVardenhet) AbstractVardenhet(se.inera.intyg.infra.integration.hsa.model.AbstractVardenhet) Vardenhet(se.inera.intyg.common.support.model.common.internal.Vardenhet) Vardgivare(se.inera.intyg.infra.integration.hsa.model.Vardgivare) Vardgivare(se.inera.intyg.infra.integration.hsa.model.Vardgivare) Mottagning(se.inera.intyg.infra.integration.hsa.model.Mottagning)

Example 7 with Vardenhet

use of se.inera.intyg.common.support.model.common.internal.Vardenhet in project webcert by sklintyg.

the class CopyUtkastServiceImplTest method setup.

@Before
public void setup() {
    hoSPerson = new HoSPersonal();
    hoSPerson.setPersonId(HOSPERSON_ID);
    hoSPerson.setFullstandigtNamn(HOSPERSON_NAME);
    Vardgivare vardgivare = new Vardgivare();
    vardgivare.setVardgivarid(VARDGIVARE_ID);
    vardgivare.setVardgivarnamn(VARDGIVARE_NAME);
    Vardenhet vardenhet = new Vardenhet();
    vardenhet.setEnhetsid(VARDENHET_ID);
    vardenhet.setEnhetsnamn(VARDENHET_NAME);
    vardenhet.setVardgivare(vardgivare);
    hoSPerson.setVardenhet(vardenhet);
    patient = new Patient();
    patient.setPersonId(PATIENT_SSN);
}
Also used : HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) Patient(se.inera.intyg.common.support.model.common.internal.Patient) Vardgivare(se.inera.intyg.common.support.model.common.internal.Vardgivare) Vardenhet(se.inera.intyg.common.support.model.common.internal.Vardenhet) Before(org.junit.Before)

Example 8 with Vardenhet

use of se.inera.intyg.common.support.model.common.internal.Vardenhet 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 9 with Vardenhet

use of se.inera.intyg.common.support.model.common.internal.Vardenhet in project webcert by sklintyg.

the class IntygConverterUtil method buildVardenhet.

private static Vardenhet buildVardenhet(WebCertUser user) {
    Vardenhet vardenhet = new Vardenhet();
    SelectableVardenhet sourceVardenhet = user.getValdVardenhet();
    if (sourceVardenhet != null && sourceVardenhet instanceof AbstractVardenhet) {
        AbstractVardenhet valdVardenhet = (AbstractVardenhet) sourceVardenhet;
        vardenhet.setArbetsplatsKod(valdVardenhet.getArbetsplatskod());
        vardenhet.setEnhetsid(valdVardenhet.getId());
        vardenhet.setEnhetsnamn(valdVardenhet.getNamn());
        vardenhet.setEpost(valdVardenhet.getEpost());
        vardenhet.setPostadress(valdVardenhet.getPostadress());
        vardenhet.setPostnummer(valdVardenhet.getPostnummer());
        vardenhet.setPostort(valdVardenhet.getPostort());
        vardenhet.setTelefonnummer(valdVardenhet.getTelefonnummer());
    }
    vardenhet.setVardgivare(buildVardgivare(user.getValdVardgivare()));
    return vardenhet;
}
Also used : AbstractVardenhet(se.inera.intyg.infra.integration.hsa.model.AbstractVardenhet) Vardenhet(se.inera.intyg.common.support.model.common.internal.Vardenhet) AbstractVardenhet(se.inera.intyg.infra.integration.hsa.model.AbstractVardenhet) SelectableVardenhet(se.inera.intyg.infra.integration.hsa.model.SelectableVardenhet) SelectableVardenhet(se.inera.intyg.infra.integration.hsa.model.SelectableVardenhet)

Example 10 with Vardenhet

use of se.inera.intyg.common.support.model.common.internal.Vardenhet in project webcert by sklintyg.

the class CreateDraftCertificateResponderImpl method addVardenhetToRegistry.

private void addVardenhetToRegistry(CreateNewDraftRequest utkastsRequest) {
    Vardenhet vardenhet = utkastsRequest.getHosPerson().getVardenhet();
    Vardgivare vardgivare = vardenhet.getVardgivare();
    IntegreradEnhetEntry integreradEnhet = new IntegreradEnhetEntry(vardenhet.getEnhetsid(), vardenhet.getEnhetsnamn(), vardgivare.getVardgivarid(), vardgivare.getVardgivarnamn());
    integreradeEnheterRegistry.putIntegreradEnhet(integreradEnhet, false, true);
}
Also used : IntegreradEnhetEntry(se.inera.intyg.webcert.web.integration.registry.dto.IntegreradEnhetEntry) Vardenhet(se.inera.intyg.common.support.model.common.internal.Vardenhet) Vardgivare(se.inera.intyg.common.support.model.common.internal.Vardgivare)

Aggregations

Vardenhet (se.inera.intyg.common.support.model.common.internal.Vardenhet)20 Vardgivare (se.inera.intyg.common.support.model.common.internal.Vardgivare)13 AbstractVardenhet (se.inera.intyg.infra.integration.hsa.model.AbstractVardenhet)8 Patient (se.inera.intyg.common.support.model.common.internal.Patient)6 HoSPersonal (se.inera.intyg.common.support.model.common.internal.HoSPersonal)5 Before (org.junit.Before)4 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)4 VardpersonReferens (se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens)4 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)4 CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)4 ValidateDraftResponse (se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse)3 IntegreradEnhetEntry (se.inera.intyg.webcert.web.integration.registry.dto.IntegreradEnhetEntry)3 IOException (java.io.IOException)2 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)2 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)2 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)2 LocalDateTime (java.time.LocalDateTime)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1