Search in sources :

Example 16 with TrackedEntityInstance

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

Example 17 with TrackedEntityInstance

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");
}
Also used : TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) DateTime(org.joda.time.DateTime) HashSet(java.util.HashSet)

Example 18 with TrackedEntityInstance

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackedEntity(org.hisp.dhis.trackedentity.TrackedEntity) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Example 19 with TrackedEntityInstance

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);
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Example 20 with TrackedEntityInstance

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Aggregations

TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)33 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)11 Date (java.util.Date)10 HashSet (java.util.HashSet)9 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)8 ArrayList (java.util.ArrayList)7 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)7 Program (org.hisp.dhis.program.Program)6 ProgramInstance (org.hisp.dhis.program.ProgramInstance)6 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)6 List (java.util.List)5 NotAllowedException (org.hisp.dhis.api.mobile.NotAllowedException)5 PatientList (org.hisp.dhis.api.mobile.model.LWUITmodel.PatientList)5 PatientAttribute (org.hisp.dhis.api.mobile.model.PatientAttribute)4 Grid (org.hisp.dhis.common.Grid)4 TrackedEntityInstanceQueryParams (org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams)4 Activity (org.hisp.dhis.api.mobile.model.Activity)3 Patient (org.hisp.dhis.api.mobile.model.LWUITmodel.Patient)3 IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)3 QueryItem (org.hisp.dhis.common.QueryItem)3