Search in sources :

Example 1 with ProgramNotificationTemplate

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

the class ProgramNotificationTemplateObjectBundleHook method preCreate.

@Override
public <T extends IdentifiableObject> void preCreate(T object, ObjectBundle bundle) {
    if (!ProgramNotificationTemplate.class.isInstance(object))
        return;
    ProgramNotificationTemplate template = (ProgramNotificationTemplate) object;
    preProcess(template);
}
Also used : ProgramNotificationTemplate(org.hisp.dhis.program.notification.ProgramNotificationTemplate)

Example 2 with ProgramNotificationTemplate

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

the class ProgramNotificationTemplateObjectBundleHook method postUpdate.

@Override
public <T extends IdentifiableObject> void postUpdate(T persistedObject, ObjectBundle bundle) {
    if (!ProgramNotificationTemplate.class.isInstance(persistedObject))
        return;
    ProgramNotificationTemplate template = (ProgramNotificationTemplate) persistedObject;
    postProcess(template);
}
Also used : ProgramNotificationTemplate(org.hisp.dhis.program.notification.ProgramNotificationTemplate)

Example 3 with ProgramNotificationTemplate

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

the class ProgramNotificationTemplateObjectBundleHook method postCreate.

@Override
public <T extends IdentifiableObject> void postCreate(T persistedObject, ObjectBundle bundle) {
    if (!ProgramNotificationTemplate.class.isInstance(persistedObject))
        return;
    ProgramNotificationTemplate template = (ProgramNotificationTemplate) persistedObject;
    postProcess(template);
}
Also used : ProgramNotificationTemplate(org.hisp.dhis.program.notification.ProgramNotificationTemplate)

Example 4 with ProgramNotificationTemplate

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

the class ProgramStageInstanceStoreTest method testGetWithScheduledNotifications.

@Test
void testGetWithScheduledNotifications() {
    ProgramNotificationTemplate a1 = createProgramNotificationTemplate("a1", -1, SCHEDULED_DAYS_DUE_DATE, ProgramNotificationRecipient.TRACKED_ENTITY_INSTANCE), a2 = createProgramNotificationTemplate("a2", -2, SCHEDULED_DAYS_DUE_DATE, ProgramNotificationRecipient.TRACKED_ENTITY_INSTANCE), a3 = createProgramNotificationTemplate("a3", 1, SCHEDULED_DAYS_DUE_DATE, ProgramNotificationRecipient.TRACKED_ENTITY_INSTANCE), b1 = createProgramNotificationTemplate("b1", -1, SCHEDULED_DAYS_DUE_DATE, ProgramNotificationRecipient.TRACKED_ENTITY_INSTANCE), b2 = createProgramNotificationTemplate("b2", -2, SCHEDULED_DAYS_DUE_DATE, ProgramNotificationRecipient.TRACKED_ENTITY_INSTANCE), b3 = createProgramNotificationTemplate("b3", 1, SCHEDULED_DAYS_DUE_DATE, ProgramNotificationRecipient.TRACKED_ENTITY_INSTANCE), c1 = createProgramNotificationTemplate("c1", -1, SCHEDULED_DAYS_DUE_DATE, ProgramNotificationRecipient.TRACKED_ENTITY_INSTANCE), c2 = createProgramNotificationTemplate("c2", -2, SCHEDULED_DAYS_DUE_DATE, ProgramNotificationRecipient.TRACKED_ENTITY_INSTANCE), c3 = createProgramNotificationTemplate("c3", 1, SCHEDULED_DAYS_DUE_DATE, ProgramNotificationRecipient.TRACKED_ENTITY_INSTANCE);
    programNotificationStore.save(a1);
    programNotificationStore.save(a2);
    programNotificationStore.save(a3);
    programNotificationStore.save(b1);
    programNotificationStore.save(b2);
    programNotificationStore.save(b3);
    programNotificationStore.save(c1);
    programNotificationStore.save(c2);
    programNotificationStore.save(c3);
    // Stage
    stageA.setNotificationTemplates(Sets.newHashSet(a1, a2, a3));
    programStageService.updateProgramStage(stageA);
    stageB.setNotificationTemplates(Sets.newHashSet(b1, b2, b3));
    programStageService.updateProgramStage(stageB);
    stageC.setNotificationTemplates(Sets.newHashSet(c1, c2, c3));
    programStageService.updateProgramStage(stageC);
    // Dates
    Calendar cal = Calendar.getInstance();
    PeriodType.clearTimeOfDay(cal);
    // 2016-01-10 -> "today"
    Date today = cal.getTime();
    // 2016-01-11
    cal.add(Calendar.DATE, 1);
    Date tomorrow = cal.getTime();
    // 2016-01-09
    cal.add(Calendar.DATE, -2);
    Date yesterday = cal.getTime();
    // Events
    ProgramStageInstance eventA = new ProgramStageInstance(programInstanceA, stageA);
    eventA.setDueDate(tomorrow);
    programStageInstanceStore.save(eventA);
    ProgramStageInstance eventB = new ProgramStageInstance(programInstanceB, stageB);
    eventB.setDueDate(today);
    programStageInstanceStore.save(eventB);
    ProgramStageInstance eventC = new ProgramStageInstance(programInstanceB, stageC);
    eventC.setDueDate(yesterday);
    programStageInstanceStore.save(eventC);
    // Queries
    List<ProgramStageInstance> results;
    // A
    results = programStageInstanceStore.getWithScheduledNotifications(a1, today);
    assertEquals(1, results.size());
    assertEquals(eventA, results.get(0));
    results = programStageInstanceStore.getWithScheduledNotifications(a2, today);
    assertEquals(0, results.size());
    results = programStageInstanceStore.getWithScheduledNotifications(a3, today);
    assertEquals(0, results.size());
    // B
    results = programStageInstanceStore.getWithScheduledNotifications(b1, today);
    assertEquals(0, results.size());
    results = programStageInstanceStore.getWithScheduledNotifications(b2, today);
    assertEquals(0, results.size());
    results = programStageInstanceStore.getWithScheduledNotifications(b3, today);
    assertEquals(0, results.size());
    // C
    results = programStageInstanceStore.getWithScheduledNotifications(c1, today);
    assertEquals(0, results.size());
    results = programStageInstanceStore.getWithScheduledNotifications(c2, today);
    assertEquals(0, results.size());
    results = programStageInstanceStore.getWithScheduledNotifications(c3, today);
    assertEquals(1, results.size());
    assertEquals(eventC, results.get(0));
}
Also used : ProgramNotificationTemplate(org.hisp.dhis.program.notification.ProgramNotificationTemplate) Calendar(java.util.Calendar) Date(java.util.Date) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 5 with ProgramNotificationTemplate

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

the class ProgramRuleEntityMapperServiceTest method setProgramRuleAction.

private ProgramRuleAction setProgramRuleAction(ProgramRuleAction programRuleActionA, ProgramRuleActionType type, String content, String data) {
    programRuleActionA.setProgramRuleActionType(type);
    if (type == ProgramRuleActionType.ASSIGN) {
        programRuleActionA.setContent(content);
        programRuleActionA.setData(data);
    }
    if (type == ProgramRuleActionType.DISPLAYTEXT) {
        programRuleActionA.setLocation("feedback");
        programRuleActionA.setContent("content");
        programRuleActionA.setData("true");
    }
    if (type == ProgramRuleActionType.SENDMESSAGE) {
        ProgramNotificationTemplate notificationTemplate = new ProgramNotificationTemplate();
        notificationTemplate.setUid("uid0");
        programRuleActionA.setTemplateUid(notificationTemplate.getUid());
    }
    return programRuleActionA;
}
Also used : ProgramNotificationTemplate(org.hisp.dhis.program.notification.ProgramNotificationTemplate)

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