Search in sources :

Example 11 with NotificationMessage

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

the class NotificationTypeConverterTest method testConvert.

@Test
public void testConvert() throws Exception {
    final String intygsId = "intygsid";
    final LocalDateTime handelsetid = LocalDateTime.now().minusDays(1);
    final HandelsekodEnum handelsetyp = HandelsekodEnum.ANDRAT;
    final int skickadeFragorTotalt = 8;
    final int skickadeFragorHanterade = 7;
    final int skickadeFragorBesvarade = 6;
    final int skickadeFragorEjBesvarade = 5;
    final int mottagnaFragorTotalt = 4;
    final int mottagnaFragorHanterade = 3;
    final int mottagnaFragorBesvarade = 2;
    final int mottagnaFragorEjBesvarade = 1;
    final Intyg intyg = buildIntyg();
    ArendeCount skickadeFragor = new ArendeCount(skickadeFragorTotalt, skickadeFragorEjBesvarade, skickadeFragorBesvarade, skickadeFragorHanterade);
    ArendeCount mottagnaFragor = new ArendeCount(mottagnaFragorTotalt, mottagnaFragorEjBesvarade, mottagnaFragorBesvarade, mottagnaFragorHanterade);
    NotificationMessage msg = new NotificationMessage(intygsId, "luse", handelsetid, handelsetyp, "address", "", null, skickadeFragor, mottagnaFragor, SchemaVersion.VERSION_3, "ref");
    CertificateStatusUpdateForCareType res = NotificationTypeConverter.convert(msg, intyg);
    assertEquals(intyg, res.getIntyg());
    assertEquals(HandelsekodEnum.ANDRAT.value(), res.getHandelse().getHandelsekod().getCode());
    assertEquals(HandelsekodEnum.ANDRAT.description(), res.getHandelse().getHandelsekod().getDisplayName());
    assertEquals(handelsetid, res.getHandelse().getTidpunkt());
    assertNotNull(res.getHandelse().getHandelsekod().getCodeSystem());
    // handelsekod -> codeSystemName is not valid in schema but incorrectly generated in java class
    // therefore we should not populate this field
    assertNull(res.getHandelse().getHandelsekod().getCodeSystemName());
    assertSkickadeFrågor(skickadeFragorTotalt, skickadeFragorHanterade, skickadeFragorBesvarade, skickadeFragorEjBesvarade, res);
    assertMottagnaFragor(mottagnaFragorTotalt, mottagnaFragorHanterade, mottagnaFragorBesvarade, mottagnaFragorEjBesvarade, res);
    // Make sure we have a valid Intyg according to service contract
    assertEquals(NotificationTypeConverter.TEMPORARY_ARBETSPLATSKOD, res.getIntyg().getSkapadAv().getEnhet().getArbetsplatskod().getExtension());
    assertNull(res.getIntyg().getSkapadAv().getEnhet().getEpost());
}
Also used : LocalDateTime(java.time.LocalDateTime) NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage) Intyg(se.riv.clinicalprocess.healthcond.certificate.v3.Intyg) ArendeCount(se.inera.intyg.common.support.modules.support.api.notification.ArendeCount) CertificateStatusUpdateForCareType(se.riv.clinicalprocess.healthcond.certificate.certificatestatusupdateforcareresponder.v3.CertificateStatusUpdateForCareType) HandelsekodEnum(se.inera.intyg.common.support.common.enumerations.HandelsekodEnum) Test(org.junit.Test)

Example 12 with NotificationMessage

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

the class NotificationMessageDiscardFilterTest method testReturnsLatestSaved.

@Test
public void testReturnsLatestSaved() throws IOException {
    String intygsId = UUID.randomUUID().toString();
    LocalDateTime first = LocalDateTime.now().minusSeconds(5);
    NotificationMessage nm2 = buildNotificationMessage(intygsId, HandelsekodEnum.ANDRAT, LocalDateTime.now().minusSeconds(10));
    NotificationMessage nm1 = buildNotificationMessage(intygsId, HandelsekodEnum.ANDRAT, first);
    NotificationMessage nm3 = buildNotificationMessage(intygsId, HandelsekodEnum.ANDRAT, LocalDateTime.now().minusSeconds(15));
    List<Message> processed = testee.process(Arrays.asList(to(nm2), to(nm1), to(nm3)));
    assertEquals(1, processed.size());
    NotificationMessage notificationMessage = om.readValue((String) processed.get(0).getBody(), NotificationMessage.class);
    assertEquals(first, notificationMessage.getHandelseTid());
}
Also used : LocalDateTime(java.time.LocalDateTime) 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)

Example 13 with NotificationMessage

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

the class NotificationMessageDiscardFilterTest method buildNotificationMessage.

private NotificationMessage buildNotificationMessage(String intygsId, HandelsekodEnum ht, LocalDateTime tid) {
    NotificationMessage nf = new NotificationMessage();
    nf.setIntygsId(intygsId);
    nf.setHandelse(ht);
    nf.setHandelseTid(tid);
    return nf;
}
Also used : NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage)

Example 14 with NotificationMessage

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

the class NotificationMessageDiscardFilter method handleAndratNotification.

private void handleAndratNotification(Map<String, List<Message>> latestMessage, Message camelMsg, NotificationMessage msg) {
    List<Message> existingMessagesForIntygsId = latestMessage.get(msg.getIntygsId());
    // If SIGNERAT entry exists, do nothing
    if (existingMessagesForIntygsId.stream().filter(existingMsg -> getNotificationFromBody(existingMsg).getHandelse() == HandelsekodEnum.SIGNAT).count() > 0) {
        return;
    }
    // Extract the existing msg of ANDRAT type if it exists (Can never be more than one)
    Message andratMsg = existingMessagesForIntygsId.stream().filter(existingMsg -> getNotificationFromBody(existingMsg).getHandelse() == HandelsekodEnum.ANDRAT).findFirst().orElse(null);
    // No existing of type, add.
    if (andratMsg == null) {
        existingMessagesForIntygsId.add(camelMsg);
    } else if (getNotificationFromBody(andratMsg).getHandelseTid().compareTo(msg.getHandelseTid()) < 0) {
        // Exists, but older - replace.
        existingMessagesForIntygsId.remove(andratMsg);
        existingMessagesForIntygsId.add(camelMsg);
    }
}
Also used : Message(org.apache.camel.Message) NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage)

Example 15 with NotificationMessage

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

the class NotificationMessageDiscardFilter method handleSigneratNotification.

private void handleSigneratNotification(Map<String, List<Message>> latestMessage, Message camelMsg, NotificationMessage msg) {
    // Add it, we need to have it in the list temporarily in case there are subsequent ANDRAT.
    latestMessage.get(msg.getIntygsId()).add(camelMsg);
    // Remove any "ANDRAT" messages
    Iterator<Message> i = latestMessage.get(msg.getIntygsId()).iterator();
    while (i.hasNext()) {
        Message existingMsg = i.next();
        if (getNotificationFromBody(existingMsg).getHandelse() == HandelsekodEnum.ANDRAT) {
            i.remove();
        }
    }
}
Also used : Message(org.apache.camel.Message) NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage)

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