Search in sources :

Example 26 with ProgramNotificationTemplate

use of org.hisp.dhis.program.notification.ProgramNotificationTemplate in project dhis2-core by dhis2.

the class ProgramRuleEngineTest method testNotificationWhenUsingD2HasValueWithTEA.

@Test
void testNotificationWhenUsingD2HasValueWithTEA() {
    setUpNotificationForD2HasValue();
    ProgramInstance programInstance = programInstanceService.getProgramInstance("UID-P2");
    List<RuleEffect> ruleEffects = programRuleEngine.evaluate(programInstance, Sets.newHashSet());
    assertEquals(1, ruleEffects.size());
    RuleAction ruleAction = ruleEffects.get(0).ruleAction();
    assertTrue(ruleAction instanceof RuleActionSendMessage);
    RuleActionSendMessage ruleActionSendMessage = (RuleActionSendMessage) ruleAction;
    assertEquals("PNT-2", ruleActionSendMessage.notification());
    ProgramNotificationTemplate template = programNotificationTemplateStore.getByUid("PNT-2");
    assertNotNull(template);
    assertEquals(NotificationTrigger.PROGRAM_RULE, template.getNotificationTrigger());
    assertEquals(ProgramNotificationRecipient.PROGRAM_ATTRIBUTE, template.getNotificationRecipient());
    assertEquals("message_template", template.getMessageTemplate());
}
Also used : ProgramNotificationTemplate(org.hisp.dhis.program.notification.ProgramNotificationTemplate) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ProgramRuleAction(org.hisp.dhis.programrule.ProgramRuleAction) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 27 with ProgramNotificationTemplate

use of org.hisp.dhis.program.notification.ProgramNotificationTemplate in project dhis2-core by dhis2.

the class ProgramRuleEngineTest method testSendMessageForEnrollmentAndEvent.

@Test
void testSendMessageForEnrollmentAndEvent() {
    setUpSendMessageForEnrollment();
    ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance("UID-PS1");
    List<RuleEffects> ruleEffects = programRuleEngine.evaluateEnrollmentAndEvents(programStageInstance.getProgramInstance(), Sets.newHashSet(programStageInstance), Lists.newArrayList());
    assertEquals(2, ruleEffects.size());
    RuleEffects enrollmentRuleEffects = ruleEffects.stream().filter(RuleEffects::isEnrollment).findFirst().get();
    RuleEffects eventRuleEffects = ruleEffects.stream().filter(RuleEffects::isEvent).findFirst().get();
    assertEquals("UID-PS1", eventRuleEffects.getTrackerObjectUid());
    RuleAction eventRuleAction = eventRuleEffects.getRuleEffects().get(0).ruleAction();
    RuleAction enrollmentRuleAction = enrollmentRuleEffects.getRuleEffects().get(0).ruleAction();
    assertTrue(eventRuleAction instanceof RuleActionSendMessage);
    assertTrue(enrollmentRuleAction instanceof RuleActionSendMessage);
    RuleActionSendMessage ruleActionSendMessage = (RuleActionSendMessage) eventRuleAction;
    assertEquals("PNT-1", ruleActionSendMessage.notification());
    ProgramNotificationTemplate template = programNotificationTemplateStore.getByUid("PNT-1");
    assertNotNull(template);
    assertEquals(NotificationTrigger.PROGRAM_RULE, template.getNotificationTrigger());
    assertEquals(ProgramNotificationRecipient.USER_GROUP, template.getNotificationRecipient());
    assertEquals("message_template", template.getMessageTemplate());
}
Also used : ProgramNotificationTemplate(org.hisp.dhis.program.notification.ProgramNotificationTemplate) ProgramRuleAction(org.hisp.dhis.programrule.ProgramRuleAction) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

ProgramNotificationTemplate (org.hisp.dhis.program.notification.ProgramNotificationTemplate)27 ProgramRuleAction (org.hisp.dhis.programrule.ProgramRuleAction)8 DhisSpringTest (org.hisp.dhis.DhisSpringTest)7 Test (org.junit.jupiter.api.Test)7 ProgramInstance (org.hisp.dhis.program.ProgramInstance)4 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)4 Date (java.util.Date)3 ExternalNotificationLogEntry (org.hisp.dhis.notification.logging.ExternalNotificationLogEntry)3 ProgramNotificationInstance (org.hisp.dhis.program.notification.ProgramNotificationInstance)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Calendar (java.util.Calendar)2 HashSet (java.util.HashSet)2 ValueType (org.hisp.dhis.common.ValueType)2 NotificationValidationResult (org.hisp.dhis.notification.logging.NotificationValidationResult)2 Nonnull (javax.annotation.Nonnull)1 EventDataValue (org.hisp.dhis.eventdatavalue.EventDataValue)1 ErrorReport (org.hisp.dhis.feedback.ErrorReport)1 BaseNotificationMessageRenderer.formatDate (org.hisp.dhis.notification.BaseNotificationMessageRenderer.formatDate)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 Program (org.hisp.dhis.program.Program)1