Search in sources :

Example 56 with Program

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

the class CategoryOptionComboSupplier method get.

@Override
public Map<String, CategoryOptionCombo> get(ImportOptions importOptions, List<Event> events) {
    if (events == null) {
        return emptyMap();
    }
    // TODO this should be optimized to execute less SQL queries
    IdScheme idScheme = importOptions.getIdSchemes().getCategoryOptionIdScheme();
    Map<String, CategoryOptionCombo> eventToCocMap = new HashMap<>();
    Map<String, Program> programMap = programSupplier.get(importOptions, events);
    Map<String, ProgramStageInstance> programStageInstanceMap = programStageInstanceSupplier.get(importOptions, events);
    for (Event event : events) {
        Program program = programMap.get(event.getProgram());
        ProgramStageInstance psi = programStageInstanceMap.get(event.getUid());
        // validation stage
        if (program == null) {
            return emptyMap();
        }
        CategoryOptionCombo categoryOptionCombo = getCategoryOptionCombo(program, event, psi, idScheme);
        if (categoryOptionCombo != null) {
            eventToCocMap.put(event.getUid(), categoryOptionCombo);
        }
    }
    return eventToCocMap;
}
Also used : Program(org.hisp.dhis.program.Program) HashMap(java.util.HashMap) Event(org.hisp.dhis.dxf2.events.event.Event) IdScheme(org.hisp.dhis.common.IdScheme) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 57 with Program

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

the class DeduplicationHelperTest method shouldGenerateMergeObjectWIthEnrollments.

@Test
void shouldGenerateMergeObjectWIthEnrollments() throws PotentialDuplicateConflictException, PotentialDuplicateForbiddenException {
    TrackedEntityInstance original = getTeiA();
    Program programA = createProgram('A');
    ProgramInstance programInstanceA = createProgramInstance(programA, original, organisationUnitA);
    programInstanceA.setUid("programInstanceA");
    original.getProgramInstances().add(programInstanceA);
    TrackedEntityInstance duplicate = getTeiA();
    Program programB = createProgram('B');
    ProgramInstance programInstanceB = createProgramInstance(programB, duplicate, organisationUnitA);
    programInstanceB.setUid("programInstanceB");
    duplicate.getProgramInstances().add(programInstanceB);
    MergeObject generatedMergeObject = deduplicationHelper.generateMergeObject(original, duplicate);
    assertEquals("programInstanceB", generatedMergeObject.getEnrollments().get(0));
}
Also used : Program(org.hisp.dhis.program.Program) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 58 with Program

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

the class DeduplicationServiceMergeIntegrationTest method shouldManualMergeWithAuthorityAll.

@Test
void shouldManualMergeWithAuthorityAll() throws PotentialDuplicateConflictException, PotentialDuplicateForbiddenException {
    OrganisationUnit ou = createOrganisationUnit("OU_A");
    organisationUnitService.addOrganisationUnit(ou);
    creteUser(new HashSet<>(Collections.singletonList(ou)), UserAuthorityGroup.AUTHORITY_ALL);
    TrackedEntityType trackedEntityType = createTrackedEntityType('A');
    trackedEntityTypeService.addTrackedEntityType(trackedEntityType);
    TrackedEntityInstance original = createTrackedEntityInstance(ou);
    TrackedEntityInstance duplicate = createTrackedEntityInstance(ou);
    original.setTrackedEntityType(trackedEntityType);
    duplicate.setTrackedEntityType(trackedEntityType);
    trackedEntityInstanceService.addTrackedEntityInstance(original);
    trackedEntityInstanceService.addTrackedEntityInstance(duplicate);
    Program program = createProgram('A');
    Program program1 = createProgram('B');
    programService.addProgram(program);
    programService.addProgram(program1);
    ProgramInstance programInstance1 = createProgramInstance(program, original, ou);
    ProgramInstance programInstance2 = createProgramInstance(program1, duplicate, ou);
    programInstanceService.addProgramInstance(programInstance1);
    programInstanceService.addProgramInstance(programInstance2);
    original.getProgramInstances().add(programInstance1);
    duplicate.getProgramInstances().add(programInstance2);
    trackedEntityInstanceService.updateTrackedEntityInstance(original);
    trackedEntityInstanceService.updateTrackedEntityInstance(duplicate);
    PotentialDuplicate potentialDuplicate = new PotentialDuplicate(original.getUid(), duplicate.getUid());
    deduplicationService.addPotentialDuplicate(potentialDuplicate);
    DeduplicationMergeParams deduplicationMergeParams = DeduplicationMergeParams.builder().potentialDuplicate(potentialDuplicate).original(original).duplicate(duplicate).build();
    Date lastUpdatedOriginal = trackedEntityInstanceService.getTrackedEntityInstance(original.getUid()).getLastUpdated();
    deduplicationService.autoMerge(deduplicationMergeParams);
    assertEquals(deduplicationService.getPotentialDuplicateByUid(potentialDuplicate.getUid()).getStatus(), DeduplicationStatus.MERGED);
    assertTrue(trackedEntityInstanceService.getTrackedEntityInstance(original.getUid()).getLastUpdated().getTime() > lastUpdatedOriginal.getTime());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) Program(org.hisp.dhis.program.Program) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 59 with Program

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

the class DeduplicationServiceTest method shouldNotBeAutoMergeableWithSameProgram.

@Test
void shouldNotBeAutoMergeableWithSameProgram() throws PotentialDuplicateConflictException, PotentialDuplicateForbiddenException {
    Program program = new Program();
    program.setUid("progrUid");
    program.setDescription("programDescr");
    program.setName("programName");
    when(programInstanceA.getProgram()).thenReturn(program);
    when(programInstanceB.getProgram()).thenReturn(program);
    assertThrows(PotentialDuplicateConflictException.class, () -> deduplicationService.autoMerge(deduplicationMergeParams));
    verify(deduplicationHelper, times(0)).generateMergeObject(trackedEntityInstanceA, trackedEntityInstanceB);
    verify(potentialDuplicateStore, times(0)).update(any());
    verify(potentialDuplicateStore, times(0)).auditMerge(deduplicationMergeParams);
}
Also used : Program(org.hisp.dhis.program.Program) Test(org.junit.jupiter.api.Test)

Example 60 with Program

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

the class DeduplicationServiceTest method shouldNotBeAutoMergeableSameProgramInstance.

@Test
void shouldNotBeAutoMergeableSameProgramInstance() throws PotentialDuplicateConflictException, PotentialDuplicateForbiddenException {
    Program program = new Program();
    program.setUid("programUid");
    when(programInstanceA.getProgram()).thenReturn(program);
    when(programInstanceB.getProgram()).thenReturn(program);
    when(trackedEntityInstanceA.getProgramInstances()).thenReturn(Sets.newHashSet(programInstanceA));
    when(trackedEntityInstanceB.getProgramInstances()).thenReturn(Sets.newHashSet(programInstanceB));
    assertThrows(PotentialDuplicateConflictException.class, () -> deduplicationService.autoMerge(deduplicationMergeParams));
    verify(deduplicationHelper, times(0)).generateMergeObject(trackedEntityInstanceA, trackedEntityInstanceB);
    verify(potentialDuplicateStore, times(0)).update(any());
    verify(potentialDuplicateStore, times(0)).auditMerge(deduplicationMergeParams);
}
Also used : Program(org.hisp.dhis.program.Program) Test(org.junit.jupiter.api.Test)

Aggregations

Program (org.hisp.dhis.program.Program)344 Test (org.junit.jupiter.api.Test)160 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)123 ProgramStage (org.hisp.dhis.program.ProgramStage)109 ProgramInstance (org.hisp.dhis.program.ProgramInstance)79 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)68 Date (java.util.Date)47 Collectors (java.util.stream.Collectors)44 User (org.hisp.dhis.user.User)44 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)42 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)42 BeforeEach (org.junit.jupiter.api.BeforeEach)42 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)41 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)41 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)40 DhisConvenienceTest.createProgram (org.hisp.dhis.DhisConvenienceTest.createProgram)39 CategoryCombo (org.hisp.dhis.category.CategoryCombo)39 DataElement (org.hisp.dhis.dataelement.DataElement)39 Event (org.hisp.dhis.tracker.domain.Event)38 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)37