use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.
the class EventStatusPreProcessorTest method testVisitedStatusIsConvertedToActive.
@Test
void testVisitedStatusIsConvertedToActive() {
// Given
Event event = new Event();
event.setStatus(EventStatus.VISITED);
event.setProgramStage("programStageUid");
TrackerBundle bundle = TrackerBundle.builder().events(Collections.singletonList(event)).build();
ProgramInstance programInstance = new ProgramInstance();
programInstance.setUid("programInstanceUid");
Program program = new Program();
program.setUid("programUid");
ProgramStage programStage = new ProgramStage();
programStage.setUid("programStageUid");
programStage.setProgram(program);
TrackerPreheat preheat = new TrackerPreheat();
preheat.putProgramInstancesWithoutRegistration("programUid", programInstance);
preheat.put(TrackerIdentifier.UID, programStage);
bundle.setPreheat(preheat);
// When
preProcessorToTest.process(bundle);
// Then
assertEquals(EventStatus.ACTIVE, bundle.getEvents().get(0).getStatus());
}
use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.
the class ProgramRuleIntegrationTest method setUpTest.
@Override
public void setUpTest() throws Exception {
renderService = _renderService;
userService = _userService;
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("tracker/simple_metadata.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validationReport = objectBundleValidationService.validate(bundle);
assertFalse(validationReport.hasErrorReports());
objectBundleService.commit(bundle);
Program program = bundle.getPreheat().get(PreheatIdentifier.UID, Program.class, "BFcipDERJnf");
Program programWithoutRegistration = bundle.getPreheat().get(PreheatIdentifier.UID, Program.class, "BFcipDERJne");
DataElement dataElement1 = bundle.getPreheat().get(PreheatIdentifier.UID, DataElement.class, "DATAEL00001");
DataElement dataElement2 = bundle.getPreheat().get(PreheatIdentifier.UID, DataElement.class, "DATAEL00002");
ProgramStage programStage = bundle.getPreheat().get(PreheatIdentifier.UID, ProgramStage.class, "NpsdDv6kKSO");
ProgramRuleVariable programRuleVariable = createProgramRuleVariableWithDataElement('A', program, dataElement2);
programRuleVariableService.addProgramRuleVariable(programRuleVariable);
ProgramRule programRuleA = createProgramRule('A', program);
programRuleA.setUid("ProgramRule");
programRuleService.addProgramRule(programRuleA);
ProgramRule programRuleWithoutRegistration = createProgramRule('W', programWithoutRegistration);
programRuleService.addProgramRule(programRuleWithoutRegistration);
ProgramRule programRuleB = createProgramRule('B', program);
programRuleB.setProgramStage(programStage);
programRuleService.addProgramRule(programRuleB);
ProgramRuleAction programRuleActionShowWarning = createProgramRuleAction('A', programRuleA);
programRuleActionShowWarning.setProgramRuleActionType(ProgramRuleActionType.SHOWWARNING);
programRuleActionShowWarning.setContent("WARNING");
programRuleActionService.addProgramRuleAction(programRuleActionShowWarning);
ProgramRuleAction programRuleActionAssign = createProgramRuleAction('C', programRuleA);
programRuleActionAssign.setProgramRuleActionType(ProgramRuleActionType.ASSIGN);
programRuleActionAssign.setData("#{ProgramRuleVariableA}");
programRuleActionAssign.setDataElement(dataElement1);
programRuleActionService.addProgramRuleAction(programRuleActionAssign);
ProgramRuleAction programRuleActionShowWarningForProgramStage = createProgramRuleAction('B', programRuleB);
programRuleActionShowWarningForProgramStage.setProgramRuleActionType(ProgramRuleActionType.SHOWWARNING);
programRuleActionShowWarningForProgramStage.setContent("PROGRAM STAGE WARNING");
programRuleActionService.addProgramRuleAction(programRuleActionShowWarningForProgramStage);
programRuleA.getProgramRuleActions().add(programRuleActionShowWarning);
programRuleA.getProgramRuleActions().add(programRuleActionAssign);
programRuleWithoutRegistration.getProgramRuleActions().add(programRuleActionShowWarning);
programRuleService.updateProgramRule(programRuleWithoutRegistration);
programRuleB.getProgramRuleActions().add(programRuleActionShowWarningForProgramStage);
programRuleService.updateProgramRule(programRuleB);
userA = userService.getUser("M5zQapPyTZI");
injectSecurityContext(userA);
}
use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.
the class ProgramMapperTest method testCategoryComboIsSetForDefaultCategoryCombos.
@Test
void testCategoryComboIsSetForDefaultCategoryCombos() {
Program program = new Program();
CategoryCombo cc = createCategoryCombo('A');
cc.setName(CategoryCombo.DEFAULT_CATEGORY_COMBO_NAME);
assertTrue(cc.isDefault(), "tests rely on this CC being the default one");
program.setCategoryCombo(cc);
Program mappedProgram = ProgramMapper.INSTANCE.map(program);
assertEquals(cc, mappedProgram.getCategoryCombo());
}
use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.
the class AbstractSchemaStrategyCachingTest method verifyObjectNotInCacheIsFetchedFromDbAndPutInCache.
@Test
void verifyObjectNotInCacheIsFetchedFromDbAndPutInCache() {
// Given
final Schema schema = new ProgramSchemaDescriptor().getSchema();
String UID = CodeGenerator.generateUid();
Program program = rnd.nextObject(Program.class);
when(cache.get(Program.class.getSimpleName(), UID)).thenReturn(Optional.empty());
doReturn(singletonList(program)).when(queryService).query(any(Query.class));
ProgramStrategy strategy = new ProgramStrategy(schemaService, queryService, manager, cache);
// When
strategy.queryForIdentifiableObjects(preheat, schema, TrackerIdentifier.UID, singletonList(singletonList(UID)), CopyMapper.class);
// Then
assertThat(preheat.getAll(Program.class), hasSize(1));
verify(cache, times(1)).put(eq("Program"), anyString(), any(), eq(20), eq(10L));
}
use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.
the class AbstractSchemaStrategyCachingTest method verifyObjectInCacheIsReturned.
@Test
void verifyObjectInCacheIsReturned() {
// Given
final Schema schema = new ProgramSchemaDescriptor().getSchema();
String UID = CodeGenerator.generateUid();
Program program = rnd.nextObject(Program.class);
when(cache.get(Program.class.getSimpleName(), UID)).thenReturn(Optional.of(program));
ProgramStrategy strategy = new ProgramStrategy(schemaService, queryService, manager, cache);
// When
strategy.queryForIdentifiableObjects(preheat, schema, TrackerIdentifier.UID, singletonList(singletonList(UID)), ProgramMapper.INSTANCE.getClass());
// Then
assertThat(preheat.getAll(Program.class), hasSize(1));
}
Aggregations