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