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()));
}
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());
}
Aggregations