Search in sources :

Example 26 with NotificationMessage

use of se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage 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)

Example 27 with NotificationMessage

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

the class RouteIT method ensureAggregatorFiltersOutAndratMessagesWhenSigned.

@Test
public void ensureAggregatorFiltersOutAndratMessagesWhenSigned() throws Exception {
    NotificationMessage notificationMessage1 = createNotificationMessage("intyg1", LocalDateTime.now(), HandelsekodEnum.SKAPAT, "luae_fs", SchemaVersion.VERSION_3);
    NotificationMessage notificationMessage2 = createNotificationMessage("intyg1", LocalDateTime.now(), HandelsekodEnum.ANDRAT, "luae_fs", SchemaVersion.VERSION_3);
    NotificationMessage notificationMessage3 = createNotificationMessage("intyg1", LocalDateTime.now(), HandelsekodEnum.ANDRAT, "luae_fs", SchemaVersion.VERSION_3);
    NotificationMessage notificationMessage4 = createNotificationMessage("intyg1", LocalDateTime.now(), HandelsekodEnum.SIGNAT, "luae_fs", SchemaVersion.VERSION_3);
    sendMessage(notificationMessage1);
    sendMessage(notificationMessage2);
    sendMessage(notificationMessage3);
    sendMessage(notificationMessage4);
    await().atMost(SECONDS_TO_WAIT, TimeUnit.SECONDS).until(() -> {
        int numberOfReceivedMessages = certificateStatusUpdateForCareResponderV3.getNumberOfReceivedMessages();
        if (numberOfReceivedMessages == 2) {
            List<NotificationStubEntry> notificationMessages = certificateStatusUpdateForCareResponderV3.getNotificationMessages();
            for (NotificationStubEntry nse : notificationMessages) {
                if (nse.handelseTyp.equals(HandelsekodEnum.ANDRAT.value())) {
                    fail("No ANDRAT messages are allowed when intyg has been signed");
                }
            }
        }
        return (numberOfReceivedMessages == 2);
    });
}
Also used : NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage) NotificationStubEntry(se.inera.intyg.webcert.notification_sender.mocks.NotificationStubEntry) Test(org.junit.Test)

Example 28 with NotificationMessage

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

the class RouteIT method ensureStubReceivedAllMessages.

@Test
public void ensureStubReceivedAllMessages() throws Exception {
    NotificationMessage notificationMessage1 = createNotificationMessage("intyg1", "fk7263", HandelsekodEnum.SKAPAT);
    NotificationMessage notificationMessage2 = createNotificationMessage("intyg2", "fk7263", HandelsekodEnum.ANDRAT);
    NotificationMessage notificationMessage3 = createNotificationMessage("intyg3", "fk7263", HandelsekodEnum.SIGNAT);
    sendMessage(notificationMessage1);
    sendMessage(notificationMessage2);
    sendMessage(notificationMessage3);
    await().atMost(SECONDS_TO_WAIT, TimeUnit.SECONDS).until(() -> {
        int numberOfReceivedMessages = certificateStatusUpdateForCareResponderStub.getNumberOfReceivedMessages();
        return (numberOfReceivedMessages == 3);
    });
}
Also used : NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage) Test(org.junit.Test)

Example 29 with NotificationMessage

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

the class NotificationAggregatorTest method buildMessage.

private Message buildMessage(String intygsId, HandelsekodEnum ht, LocalDateTime tid) throws JsonProcessingException {
    Message message = mock(Message.class);
    NotificationMessage nf = new NotificationMessage();
    nf.setIntygsId(intygsId);
    nf.setHandelse(ht);
    nf.setHandelseTid(tid);
    when(message.getBody()).thenReturn(objectMapper.writeValueAsString(nf));
    return message;
}
Also used : Message(org.apache.camel.Message) NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage) NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage)

Example 30 with NotificationMessage

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

the class NotificationTransformerTest method testSendBackwardsCompatibility.

@Test
public void testSendBackwardsCompatibility() throws Exception {
    // Given
    NotificationMessage notificationMessage = new NotificationMessage(INTYGS_ID, FK7263, LocalDateTime.now(), HandelsekodEnum.SKAPAT, LOGISK_ADRESS, "{ }", FragorOchSvar.getEmpty(), null, null, null, "ref");
    Message message = spy(new DefaultMessage());
    message.setBody(notificationMessage);
    setupInternalToNotification();
    // When
    transformer.process(message);
    // Then
    assertEquals(INTYGS_ID, ((CertificateStatusUpdateForCareType) message.getBody()).getUtlatande().getUtlatandeId().getExtension());
    assertEquals(HandelsekodEnum.SKAPAT.value(), message.getHeader(NotificationRouteHeaders.HANDELSE));
    assertEquals(INTYGS_ID, message.getHeader(NotificationRouteHeaders.INTYGS_ID));
    assertEquals(LOGISK_ADRESS, message.getHeader(NotificationRouteHeaders.LOGISK_ADRESS));
    assertEquals(SchemaVersion.VERSION_1.name(), message.getHeader(NotificationRouteHeaders.VERSION));
    verify(message, times(1)).setHeader(eq(NotificationRouteHeaders.LOGISK_ADRESS), eq(LOGISK_ADRESS));
    verify(message, times(1)).setHeader(eq(NotificationRouteHeaders.INTYGS_ID), eq(INTYGS_ID));
    verify(message, times(1)).setHeader(eq(NotificationRouteHeaders.HANDELSE), eq(HandelsekodEnum.SKAPAT.value()));
    verify(message, times(1)).setHeader(eq(NotificationRouteHeaders.VERSION), eq(SchemaVersion.VERSION_1.name()));
    verify(internalToNotification, times(1)).createCertificateStatusUpdateForCareType(any());
    verifyZeroInteractions(notificationPatientEnricher);
}
Also used : DefaultMessage(org.apache.camel.impl.DefaultMessage) NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage) Message(org.apache.camel.Message) NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage) DefaultMessage(org.apache.camel.impl.DefaultMessage) Test(org.junit.Test)

Aggregations

NotificationMessage (se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage)32 Test (org.junit.Test)21 LocalDateTime (java.time.LocalDateTime)8 Message (org.apache.camel.Message)8 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)8 DefaultMessage (org.apache.camel.impl.DefaultMessage)5 ArendeCount (se.inera.intyg.common.support.modules.support.api.notification.ArendeCount)5 Intyg (se.riv.clinicalprocess.healthcond.certificate.v3.Intyg)5 TextMessage (javax.jms.TextMessage)3 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 MessageCreator (org.springframework.jms.core.MessageCreator)3 HandelsekodEnum (se.inera.intyg.common.support.common.enumerations.HandelsekodEnum)3 FragorOchSvar (se.inera.intyg.common.support.modules.support.api.notification.FragorOchSvar)3 NotificationStubEntry (se.inera.intyg.webcert.notification_sender.mocks.NotificationStubEntry)3 CertificateStatusUpdateForCareType (se.riv.clinicalprocess.healthcond.certificate.certificatestatusupdateforcareresponder.v3.CertificateStatusUpdateForCareType)3 Session (javax.jms.Session)2 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)2 Handelse (se.inera.intyg.webcert.persistence.handelse.model.Handelse)2 CertificateStatusUpdateForCareType (se.riv.clinicalprocess.healthcond.certificate.certificatestatusupdateforcareresponder.v1.CertificateStatusUpdateForCareType)2