use of org.hisp.dhis.trackedentity.TrackedEntityInstance 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());
}
use of org.hisp.dhis.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class ProgramInstanceStoreTest method setUpTest.
@Override
public void setUpTest() {
organisationUnitA = createOrganisationUnit('A');
int idA = organisationUnitService.addOrganisationUnit(organisationUnitA);
organisationUnitB = createOrganisationUnit('B');
int idB = organisationUnitService.addOrganisationUnit(organisationUnitB);
orgunitIds = new HashSet<>();
orgunitIds.add(idA);
orgunitIds.add(idB);
programA = createProgram('A', new HashSet<>(), organisationUnitA);
programService.addProgram(programA);
ProgramStage stageA = new ProgramStage("StageA", programA);
stageA.setSortOrder(1);
programStageService.saveProgramStage(stageA);
ProgramStage stageB = new ProgramStage("StageB", programA);
stageB.setSortOrder(2);
programStageService.saveProgramStage(stageB);
Set<ProgramStage> programStages = new HashSet<>();
programStages.add(stageA);
programStages.add(stageB);
programA.setProgramStages(programStages);
programService.updateProgram(programA);
programB = createProgram('B', new HashSet<>(), organisationUnitA);
programService.addProgram(programB);
programC = createProgram('C', new HashSet<>(), organisationUnitA);
programService.addProgram(programC);
entityInstanceA = createTrackedEntityInstance('A', organisationUnitA);
entityInstanceService.addTrackedEntityInstance(entityInstanceA);
TrackedEntityInstance entityInstanceB = createTrackedEntityInstance('B', organisationUnitB);
entityInstanceService.addTrackedEntityInstance(entityInstanceB);
DateTime testDate1 = DateTime.now();
testDate1.withTimeAtStartOfDay();
testDate1 = testDate1.minusDays(70);
incidentDate = testDate1.toDate();
DateTime testDate2 = DateTime.now();
testDate2.withTimeAtStartOfDay();
enrollmentDate = testDate2.toDate();
programInstanceA = new ProgramInstance(enrollmentDate, incidentDate, entityInstanceA, programA);
programInstanceA.setUid("UID-A");
programInstanceB = new ProgramInstance(enrollmentDate, incidentDate, entityInstanceA, programB);
programInstanceB.setUid("UID-B");
programInstanceB.setStatus(ProgramStatus.CANCELLED);
programInstanceC = new ProgramInstance(enrollmentDate, incidentDate, entityInstanceA, programC);
programInstanceC.setUid("UID-C");
programInstanceC.setStatus(ProgramStatus.COMPLETED);
programInstanceD = new ProgramInstance(enrollmentDate, incidentDate, entityInstanceB, programA);
programInstanceD.setUid("UID-D");
}
use of org.hisp.dhis.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class DefaultProgramInstanceService method getFromUrl.
@Override
public ProgramInstanceQueryParams getFromUrl(Set<String> ou, OrganisationUnitSelectionMode ouMode, Date lastUpdated, String program, ProgramStatus programStatus, Date programStartDate, Date programEndDate, String trackedEntity, String trackedEntityInstance, Boolean followUp, Integer page, Integer pageSize, boolean totalPages, boolean skipPaging) {
ProgramInstanceQueryParams params = new ProgramInstanceQueryParams();
if (ou != null) {
for (String orgUnit : ou) {
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(orgUnit);
if (organisationUnit == null) {
throw new IllegalQueryException("Organisation unit does not exist: " + orgUnit);
}
params.getOrganisationUnits().add(organisationUnit);
}
}
Program pr = program != null ? programService.getProgram(program) : null;
if (program != null && pr == null) {
throw new IllegalQueryException("Program does not exist: " + program);
}
TrackedEntity te = trackedEntity != null ? trackedEntityService.getTrackedEntity(trackedEntity) : null;
if (trackedEntity != null && te == null) {
throw new IllegalQueryException("Tracked entity does not exist: " + program);
}
TrackedEntityInstance tei = trackedEntityInstance != null ? trackedEntityInstanceService.getTrackedEntityInstance(trackedEntityInstance) : null;
if (trackedEntityInstance != null && tei == null) {
throw new IllegalQueryException("Tracked entity instance does not exist: " + program);
}
params.setProgram(pr);
params.setProgramStatus(programStatus);
params.setFollowUp(followUp);
params.setLastUpdated(lastUpdated);
params.setProgramStartDate(programStartDate);
params.setProgramEndDate(programEndDate);
params.setTrackedEntity(te);
params.setTrackedEntityInstance(tei);
params.setOrganisationUnitMode(ouMode);
params.setPage(page);
params.setPageSize(pageSize);
params.setTotalPages(totalPages);
params.setSkipPaging(skipPaging);
return params;
}
use of org.hisp.dhis.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class DefaultProgramInstanceService method incompleteProgramInstanceStatus.
@Override
public void incompleteProgramInstanceStatus(ProgramInstance programInstance) {
Program program = programInstance.getProgram();
TrackedEntityInstance tei = programInstance.getEntityInstance();
if (getProgramInstances(tei, program, ProgramStatus.ACTIVE).size() > 0) {
log.warn("Program has another active enrollment going on. Not possible to incomplete");
throw new IllegalQueryException("Program has another active enrollment going on. Not possible to incomplete");
}
// -----------------------------------------------------------------
// Update program-instance
// -----------------------------------------------------------------
programInstance.setStatus(ProgramStatus.ACTIVE);
updateProgramInstance(programInstance);
}
use of org.hisp.dhis.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class SmsDeliveryChannelStrategy method setAttributes.
@Override
public ProgramMessage setAttributes(ProgramMessage message) {
validate(message);
OrganisationUnit orgUnit = getOrganisationUnit(message);
TrackedEntityInstance tei = getTrackedEntityInstance(message);
if (orgUnit != null) {
message.getRecipients().getPhoneNumbers().add(getOrganisationUnitRecipient(orgUnit));
}
if (tei != null) {
message.getRecipients().getPhoneNumbers().add(getTrackedEntityInstanceRecipient(tei, ValueType.PHONE_NUMBER));
}
return message;
}
Aggregations