Search in sources :

Example 6 with ProgramNotificationTemplate

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

the class ProgramNotificationTemplateObjectBundleHook method resolveTemplateRecipients.

private void resolveTemplateRecipients(ProgramNotificationTemplate pnt, ProgramNotificationRecipient pnr) {
    Function<ProgramNotificationTemplate, ValueType> resolver = RECIPIENT_RESOLVER.get(pnr);
    ValueType valueType = null;
    if (resolver != null && pnt.getRecipientProgramAttribute() != null) {
        valueType = resolver.apply(pnt);
    }
    pnt.setDeliveryChannels(CHANNEL_MAPPER.getOrDefault(valueType, Sets.newHashSet()));
}
Also used : ValueType(org.hisp.dhis.common.ValueType) ProgramNotificationTemplate(org.hisp.dhis.program.notification.ProgramNotificationTemplate)

Example 7 with ProgramNotificationTemplate

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

the class ProgramInstanceStoreTest method testGetWithScheduledNotifications.

@Test
public void testGetWithScheduledNotifications() {
    ProgramNotificationTemplate a1 = createProgramNotificationTemplate("a1", -1, SCHEDULED_DAYS_INCIDENT_DATE), a2 = createProgramNotificationTemplate("a2", 1, SCHEDULED_DAYS_INCIDENT_DATE), a3 = createProgramNotificationTemplate("a3", 7, SCHEDULED_DAYS_ENROLLMENT_DATE);
    programNotificationStore.save(a1);
    programNotificationStore.save(a2);
    programNotificationStore.save(a3);
    // TEI
    TrackedEntityInstance teiX = createTrackedEntityInstance('X', organisationUnitA);
    TrackedEntityInstance teiY = createTrackedEntityInstance('Y', organisationUnitA);
    entityInstanceService.addTrackedEntityInstance(teiX);
    entityInstanceService.addTrackedEntityInstance(teiY);
    // Program
    programA.setNotificationTemplates(Sets.newHashSet(a1, a2, a3));
    programService.updateProgram(programA);
    // Dates
    Calendar cal = Calendar.getInstance();
    PeriodType.clearTimeOfDay(cal);
    Date today = cal.getTime();
    cal.add(Calendar.DATE, 1);
    Date tomorrow = cal.getTime();
    cal.add(Calendar.DATE, -2);
    Date yesterday = cal.getTime();
    cal.add(Calendar.DATE, -6);
    Date aWeekAgo = cal.getTime();
    // Enrollments
    ProgramInstance enrollmentA = new ProgramInstance(today, tomorrow, teiX, programA);
    programInstanceStore.save(enrollmentA);
    ProgramInstance enrollmentB = new ProgramInstance(aWeekAgo, yesterday, teiY, programA);
    programInstanceStore.save(enrollmentB);
    // Queries
    List<ProgramInstance> results;
    // A
    results = programInstanceStore.getWithScheduledNotifications(a1, today);
    assertEquals(1, results.size());
    assertEquals(enrollmentA, results.get(0));
    results = programInstanceStore.getWithScheduledNotifications(a2, today);
    assertEquals(1, results.size());
    assertEquals(enrollmentB, results.get(0));
    results = programInstanceStore.getWithScheduledNotifications(a3, today);
    assertEquals(1, results.size());
    assertEquals(enrollmentB, results.get(0));
    results = programInstanceStore.getWithScheduledNotifications(a3, yesterday);
    assertEquals(0, results.size());
}
Also used : ProgramNotificationTemplate(org.hisp.dhis.program.notification.ProgramNotificationTemplate) Calendar(java.util.Calendar) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Date(java.util.Date) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

ProgramNotificationTemplate (org.hisp.dhis.program.notification.ProgramNotificationTemplate)7 Calendar (java.util.Calendar)2 Date (java.util.Date)2 DhisSpringTest (org.hisp.dhis.DhisSpringTest)2 Test (org.junit.Test)2 ValueType (org.hisp.dhis.common.ValueType)1 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)1