Search in sources :

Example 96 with Program

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());
}
Also used : Program(org.hisp.dhis.program.Program) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Event(org.hisp.dhis.tracker.domain.Event) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 97 with Program

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);
}
Also used : ProgramRuleVariable(org.hisp.dhis.programrule.ProgramRuleVariable) ObjectBundleParams(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams) Program(org.hisp.dhis.program.Program) ProgramRule(org.hisp.dhis.programrule.ProgramRule) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DataElement(org.hisp.dhis.dataelement.DataElement) ProgramRuleAction(org.hisp.dhis.programrule.ProgramRuleAction) ObjectBundle(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle) List(java.util.List) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 98 with Program

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());
}
Also used : Program(org.hisp.dhis.program.Program) CategoryCombo(org.hisp.dhis.category.CategoryCombo) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 99 with Program

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));
}
Also used : Program(org.hisp.dhis.program.Program) Query(org.hisp.dhis.query.Query) Schema(org.hisp.dhis.schema.Schema) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ProgramSchemaDescriptor(org.hisp.dhis.schema.descriptors.ProgramSchemaDescriptor) Test(org.junit.jupiter.api.Test)

Example 100 with Program

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));
}
Also used : Program(org.hisp.dhis.program.Program) Schema(org.hisp.dhis.schema.Schema) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ProgramSchemaDescriptor(org.hisp.dhis.schema.descriptors.ProgramSchemaDescriptor) 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