Search in sources :

Example 16 with ModuleApi

use of se.inera.intyg.common.support.modules.support.api.ModuleApi 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 17 with ModuleApi

use of se.inera.intyg.common.support.modules.support.api.ModuleApi in project webcert by sklintyg.

the class IntygModuleFacadeImpl method registerCertificate.

@Override
public void registerCertificate(String intygType, String internalIntygJsonModel) throws ModuleException, IntygModuleFacadeException {
    try {
        ModuleApi moduleApi = moduleRegistry.getModuleApi(intygType);
        moduleApi.registerCertificate(internalIntygJsonModel, logicalAddress);
    } catch (ModuleNotFoundException e) {
        LOG.error("ModuleNotFoundException occured for intygstyp '{}' when registering certificate", intygType);
        throw new IntygModuleFacadeException("ModuleNotFoundException occured when registering certificate", e);
    }
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)

Example 18 with ModuleApi

use of se.inera.intyg.common.support.modules.support.api.ModuleApi in project webcert by sklintyg.

the class ArendeViewConverter method convertToMedicinsktArendeView.

private List<MedicinsktArendeView> convertToMedicinsktArendeView(List<MedicinsktArende> medicinskaArenden, String intygsId, String intygsTyp) {
    List<MedicinsktArendeView> medicinskaArendenViews = new ArrayList<>();
    if (CollectionUtils.isEmpty(medicinskaArenden)) {
        return medicinskaArendenViews;
    }
    List<String> frageIds = medicinskaArenden.stream().map(MedicinsktArende::getFrageId).distinct().collect(Collectors.toList());
    ModuleApi moduleApi = null;
    try {
        moduleApi = moduleRegistry.getModuleApi(intygsTyp);
    } catch (ModuleNotFoundException e) {
        LOG.error("Module not found for certificate of type {}", intygsTyp);
        Throwables.propagate(e);
    }
    Utlatande utlatande = intygService.fetchIntygData(intygsId, intygsTyp, false).getUtlatande();
    Map<String, List<String>> arendeParameters = moduleApi.getModuleSpecificArendeParameters(utlatande, frageIds);
    for (MedicinsktArende arende : medicinskaArenden) {
        Integer position = getListPositionForInstanceId(arende);
        String jsonPropertyHandle = getJsonPropertyHandle(arende, position, arendeParameters);
        MedicinsktArendeView view = MedicinsktArendeView.builder().setFrageId(arende.getFrageId()).setInstans(arende.getInstans()).setText(arende.getText()).setPosition(Math.max(position - 1, 0)).setJsonPropertyHandle(jsonPropertyHandle).build();
        medicinskaArendenViews.add(view);
    }
    return medicinskaArendenViews;
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) MedicinsktArendeView(se.inera.intyg.webcert.web.web.controller.api.dto.MedicinsktArendeView)

Example 19 with ModuleApi

use of se.inera.intyg.common.support.modules.support.api.ModuleApi in project webcert by sklintyg.

the class UtkastServiceImpl method getPopulatedModelFromIntygModule.

private String getPopulatedModelFromIntygModule(String intygType, CreateNewDraftHolder draftRequest) {
    LOG.debug("Calling module '{}' to get populated model", intygType);
    String modelAsJson;
    try {
        ModuleApi moduleApi = moduleRegistry.getModuleApi(intygType);
        modelAsJson = moduleApi.createNewInternal(draftRequest);
    } catch (ModuleException | ModuleNotFoundException me) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, me);
    }
    LOG.debug("Got populated model of {} chars from module '{}'", getSafeLength(modelAsJson), intygType);
    return modelAsJson;
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 20 with ModuleApi

use of se.inera.intyg.common.support.modules.support.api.ModuleApi in project webcert by sklintyg.

the class NotificationTransformer method process.

public void process(Message message) throws ModuleException, IOException, ModuleNotFoundException, TemporaryException {
    LOG.debug("Receiving message: {}", message.getMessageId());
    NotificationMessage notificationMessage = message.getBody(NotificationMessage.class);
    message.setHeader(NotificationRouteHeaders.LOGISK_ADRESS, notificationMessage.getLogiskAdress());
    message.setHeader(NotificationRouteHeaders.INTYGS_ID, notificationMessage.getIntygsId());
    // Note that this header have been set already by the original sender to accommodate header-based routing
    // in the aggreagatorRoute. It is 100% safe to overwrite it at this point.
    message.setHeader(NotificationRouteHeaders.HANDELSE, notificationMessage.getHandelse().value());
    if (notificationMessage.getVersion() != null) {
        message.setHeader(NotificationRouteHeaders.VERSION, notificationMessage.getVersion().name());
    } else {
        message.setHeader(NotificationRouteHeaders.VERSION, SchemaVersion.VERSION_1.name());
    }
    if (SchemaVersion.VERSION_3.equals(notificationMessage.getVersion())) {
        ModuleApi moduleApi = moduleRegistry.getModuleApi(notificationMessage.getIntygsTyp());
        Utlatande utlatande = moduleApi.getUtlatandeFromJson(notificationMessage.getUtkast());
        Intyg intyg = moduleApi.getIntygFromUtlatande(utlatande);
        notificationPatientEnricher.enrichWithPatient(intyg);
        message.setBody(NotificationTypeConverter.convert(notificationMessage, intyg));
    } else if (Fk7263EntryPoint.MODULE_ID.equals(notificationMessage.getIntygsTyp())) {
        message.setBody(fk7263Transform.createCertificateStatusUpdateForCareType(notificationMessage));
    } else {
        throw new IllegalArgumentException("Unsupported combination of version '" + notificationMessage.getVersion() + "' and type '" + notificationMessage.getIntygsTyp() + "'");
    }
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage) Intyg(se.riv.clinicalprocess.healthcond.certificate.v3.Intyg) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande)

Aggregations

ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)27 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)13 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)12 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)11 Test (org.junit.Test)10 IOException (java.io.IOException)8 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)7 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)7 Patient (se.inera.intyg.common.support.model.common.internal.Patient)6 ExternalServiceCallException (se.inera.intyg.common.support.modules.support.api.exception.ExternalServiceCallException)5 Personnummer (se.inera.intyg.schemas.contract.Personnummer)5 ArrayList (java.util.ArrayList)3 WebServiceException (javax.xml.ws.WebServiceException)3 Transactional (org.springframework.transaction.annotation.Transactional)3 UtkastStatus (se.inera.intyg.webcert.common.model.UtkastStatus)3 Intyg (se.riv.clinicalprocess.healthcond.certificate.v3.Intyg)3 LocalDateTime (java.time.LocalDateTime)2 OptimisticLockException (javax.persistence.OptimisticLockException)2 Relation (se.inera.intyg.common.support.model.common.internal.Relation)2 Vardenhet (se.inera.intyg.common.support.model.common.internal.Vardenhet)2