use of org.hisp.dhis.program.notification.ProgramNotificationTemplate in project dhis2-core by dhis2.
the class ProgramNotificationTemplateController method getProgramNotificationTemplates.
// -------------------------------------------------------------------------
// GET
// -------------------------------------------------------------------------
@PreAuthorize("hasRole('ALL')")
@GetMapping(produces = { "application/json" }, value = "/filter")
@ResponseBody
public PagingWrapper<ProgramNotificationTemplate> getProgramNotificationTemplates(@RequestParam(required = false) String program, @RequestParam(required = false) String programStage, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false, defaultValue = "0") int page, @RequestParam(required = false, defaultValue = "50") int pageSize) {
ProgramNotificationTemplateParam params = ProgramNotificationTemplateParam.builder().program(programService.getProgram(program)).programStage(programStageService.getProgramStage(programStage)).skipPaging(skipPaging).page(page).pageSize(pageSize).build();
PagingWrapper<ProgramNotificationTemplate> templatePagingWrapper = new PagingWrapper<>();
if (!skipPaging) {
long total = programNotificationTemplateService.countProgramNotificationTemplates(params);
templatePagingWrapper = templatePagingWrapper.withPager(PagingWrapper.Pager.builder().page(page).pageSize(pageSize).total(total).build());
}
List<ProgramNotificationTemplate> instances = programNotificationTemplateService.getProgramNotificationTemplates(params);
return templatePagingWrapper.withInstances(instances);
}
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 ProgramNotificationTemplateObjectBundleHook method preUpdate.
@Override
public <T extends IdentifiableObject> void preUpdate(T object, T persistedObject, ObjectBundle bundle) {
if (!ProgramNotificationTemplate.class.isInstance(object))
return;
ProgramNotificationTemplate template = (ProgramNotificationTemplate) object;
preProcess(template);
}
use of org.hisp.dhis.program.notification.ProgramNotificationTemplate in project dhis2-core by dhis2.
the class ProgramNotificationMessageRendererTest method setUpTest.
@Override
protected void setUpTest() throws Exception {
DateTime testDate1 = DateTime.now();
testDate1.withTimeAtStartOfDay();
testDate1 = testDate1.minusDays(70);
Date incidentDate = testDate1.toDate();
DateTime testDate2 = DateTime.now();
testDate2.withTimeAtStartOfDay();
Date enrollmentDate = testDate2.toDate();
dataElementA = createDataElement('A', ValueType.TEXT, AggregationType.NONE, DataElementDomain.TRACKER);
dataElementA.setUid(dataElementUid);
dataElementB = createDataElement('B', ValueType.TEXT, AggregationType.NONE, DataElementDomain.TRACKER);
dataElementB.setUid("DEB-UID");
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
trackedEntityAttributeA = createTrackedEntityAttribute('A');
trackedEntityAttributeA.setUid(trackedEntityAttributeUid);
trackedEntityAttributeB = createTrackedEntityAttribute('B');
attributeService.addTrackedEntityAttribute(trackedEntityAttributeA);
attributeService.addTrackedEntityAttribute(trackedEntityAttributeB);
organisationUnitA = createOrganisationUnit('A');
organisationUnitA.setUid(orgUnitUid);
organisationUnitService.addOrganisationUnit(organisationUnitA);
programA = createProgram('A', new HashSet<>(), organisationUnitA);
programA.setUid(programUid);
programService.addProgram(programA);
programTrackedEntityAttributeA = createProgramTrackedEntityAttribute(programA, trackedEntityAttributeA);
programTrackedEntityAttributeB = createProgramTrackedEntityAttribute(programA, trackedEntityAttributeB);
programTrackedEntityAttributeStore.save(programTrackedEntityAttributeA);
programTrackedEntityAttributeStore.save(programTrackedEntityAttributeB);
programA.setProgramAttributes(Arrays.asList(programTrackedEntityAttributeA, programTrackedEntityAttributeB));
programService.updateProgram(programA);
programStageA = createProgramStage('A', programA);
programStageA.setUid(programStageUid);
programStageService.saveProgramStage(programStageA);
programStageDataElementA = createProgramStageDataElement(programStageA, dataElementA, 1);
programStageDataElementB = createProgramStageDataElement(programStageA, dataElementB, 2);
programStageDataElementService.addProgramStageDataElement(programStageDataElementA);
programStageDataElementService.addProgramStageDataElement(programStageDataElementB);
programStageA.setProgramStageDataElements(Sets.newHashSet(programStageDataElementA, programStageDataElementB));
programStageService.updateProgramStage(programStageA);
programA.setProgramStages(Sets.newHashSet(programStageA));
programService.updateProgram(programA);
trackedEntityInstanceA = createTrackedEntityInstance(organisationUnitA);
trackedEntityInstanceA.setUid(trackedEntityUid);
entityInstanceService.addTrackedEntityInstance(trackedEntityInstanceA);
trackedEntityAttributeValueA = new TrackedEntityAttributeValue(trackedEntityAttributeA, trackedEntityInstanceA, "attribute-test");
trackedEntityAttributeValueService.addTrackedEntityAttributeValue(trackedEntityAttributeValueA);
trackedEntityInstanceA.setTrackedEntityAttributeValues(Sets.newHashSet(trackedEntityAttributeValueA));
entityInstanceService.updateTrackedEntityInstance(trackedEntityInstanceA);
// ProgramInstance to be provided in message renderer
programInstanceA = programInstanceService.enrollTrackedEntityInstance(trackedEntityInstanceA, programA, enrollmentDate, incidentDate, organisationUnitA);
programInstanceA.setUid(enrollmentUid);
programInstanceService.updateProgramInstance(programInstanceA);
// ProgramStageInstance to be provided in message renderer
programStageInstanceA = new ProgramStageInstance(programInstanceA, programStageA);
programStageInstanceA.setOrganisationUnit(organisationUnitA);
programStageInstanceA.setDueDate(enrollmentDate);
programStageInstanceA.setExecutionDate(new Date());
programStageInstanceA.setUid("PSI-UID");
eventDataValueA = new EventDataValue();
eventDataValueA.setDataElement(dataElementA.getUid());
eventDataValueA.setAutoFields();
eventDataValueA.setValue("dataElementA-Text");
eventDataValueB = new EventDataValue();
eventDataValueB.setDataElement(dataElementB.getUid());
eventDataValueB.setAutoFields();
eventDataValueB.setValue("dataElementB-Text");
programStageInstanceA.setEventDataValues(Sets.newHashSet(eventDataValueA, eventDataValueB));
programStageInstanceService.addProgramStageInstance(programStageInstanceA);
programInstanceA.getProgramStageInstances().add(programStageInstanceA);
programInstanceService.updateProgramInstance(programInstanceA);
programNotificationTemplate = new ProgramNotificationTemplate();
programNotificationTemplate.setName("Test-PNT");
programNotificationTemplate.setMessageTemplate("message_template");
programNotificationTemplate.setDeliveryChannels(Sets.newHashSet(DeliveryChannel.SMS));
programNotificationTemplate.setSubjectTemplate("subject_template");
programNotificationTemplate.setNotificationTrigger(NotificationTrigger.PROGRAM_RULE);
programNotificationTemplate.setAutoFields();
programNotificationTemplate.setUid("PNT-1");
programNotificationTemplateStore.save(programNotificationTemplate);
}
use of org.hisp.dhis.program.notification.ProgramNotificationTemplate in project dhis2-core by dhis2.
the class ProgramInstanceStoreTest method testGetWithScheduledNotifications.
@Test
void testGetWithScheduledNotifications() {
ProgramNotificationTemplate a1 = createProgramNotificationTemplate("a1", -1, SCHEDULED_DAYS_INCIDENT_DATE, ProgramNotificationRecipient.TRACKED_ENTITY_INSTANCE), a2 = createProgramNotificationTemplate("a2", 1, SCHEDULED_DAYS_INCIDENT_DATE, ProgramNotificationRecipient.TRACKED_ENTITY_INSTANCE), a3 = createProgramNotificationTemplate("a3", 7, SCHEDULED_DAYS_ENROLLMENT_DATE, ProgramNotificationRecipient.TRACKED_ENTITY_INSTANCE);
programNotificationStore.save(a1);
programNotificationStore.save(a2);
programNotificationStore.save(a3);
// TEI
TrackedEntityInstance teiX = createTrackedEntityInstance(organisationUnitA);
TrackedEntityInstance teiY = createTrackedEntityInstance(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