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());
}
}
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);
}
}
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;
}
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;
}
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() + "'");
}
}
Aggregations