Search in sources :

Example 1 with ProgramStageService

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

the class ProgramItemStageElement method getDescription.

@Override
public Object getDescription(ExprContext ctx, CommonExpressionVisitor visitor) {
    assumeStageElementSyntax(ctx);
    String programStageId = ctx.uid0.getText();
    String dataElementId = ctx.uid1.getText();
    ProgramStageService stageService = visitor.getProgramStageService();
    ProgramStage programStage = stageService.getProgramStage(programStageId);
    DataElement dataElement = visitor.getIdObjectManager().get(DataElement.class, dataElementId);
    if (programStage == null) {
        throw new ParserExceptionWithoutContext("Program stage " + programStageId + " not found");
    }
    if (dataElement == null) {
        throw new ParserExceptionWithoutContext("Data element " + dataElementId + " not found");
    }
    if (isNonDefaultStageOffset(visitor.getState().getStageOffset()) && !isRepeatableStage(stageService, programStageId)) {
        throw new ParserException(getErrorMessage(programStageId));
    }
    String description = programStage.getDisplayName() + ProgramIndicator.SEPARATOR_ID + dataElement.getDisplayName();
    visitor.getItemDescriptions().put(ctx.getText(), description);
    return ValidationUtils.getNullReplacementValue(dataElement.getValueType());
}
Also used : ParserExceptionWithoutContext(org.hisp.dhis.antlr.ParserExceptionWithoutContext) DataElement(org.hisp.dhis.dataelement.DataElement) ParserException(org.hisp.dhis.antlr.ParserException) ProgramStageService(org.hisp.dhis.program.ProgramStageService) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 2 with ProgramStageService

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

the class EventAnalyticsDimensionsServiceTest method setup.

@BeforeEach
void setup() {
    ProgramStageService programStageService = mock(ProgramStageService.class);
    CategoryService categoryService = mock(CategoryService.class);
    Program program = mock(Program.class);
    ProgramStage programStage = mock(ProgramStage.class);
    when(programStageService.getProgramStage(any())).thenReturn(programStage);
    when(programStage.getProgram()).thenReturn(program);
    when(program.getDataElements()).thenReturn(allValueTypeDataElements());
    when(program.getProgramIndicators()).thenReturn(Collections.emptySet());
    when(program.getTrackedEntityAttributes()).thenReturn(allValueTypeTEAs());
    eventAnalyticsDimensionsService = new DefaultEventAnalyticsDimensionsService(programStageService, categoryService);
}
Also used : Program(org.hisp.dhis.program.Program) ProgramStageService(org.hisp.dhis.program.ProgramStageService) CategoryService(org.hisp.dhis.category.CategoryService) ProgramStage(org.hisp.dhis.program.ProgramStage) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ProgramStage (org.hisp.dhis.program.ProgramStage)2 ProgramStageService (org.hisp.dhis.program.ProgramStageService)2 ParserException (org.hisp.dhis.antlr.ParserException)1 ParserExceptionWithoutContext (org.hisp.dhis.antlr.ParserExceptionWithoutContext)1 CategoryService (org.hisp.dhis.category.CategoryService)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 Program (org.hisp.dhis.program.Program)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1