use of org.hisp.dhis.parser.expression.ProgramExpressionParams in project dhis2-core by dhis2.
the class ProgramItemStageElement method getSql.
@Override
public Object getSql(ExprContext ctx, CommonExpressionVisitor visitor) {
assumeStageElementSyntax(ctx);
String programStageId = ctx.uid0.getText();
String dataElementId = ctx.uid1.getText();
ProgramExpressionParams params = visitor.getProgParams();
int stageOffset = visitor.getState().getStageOffset();
String column;
if (isNonDefaultStageOffset(stageOffset)) {
if (isRepeatableStage(visitor.getProgramStageService(), programStageId)) {
column = visitor.getStatementBuilder().getProgramIndicatorEventColumnSql(programStageId, Integer.valueOf(stageOffset).toString(), SqlUtils.quote(dataElementId), params.getReportingStartDate(), params.getReportingEndDate(), params.getProgramIndicator());
} else {
throw new ParserException(getErrorMessage(programStageId));
}
} else {
column = visitor.getStatementBuilder().getProgramIndicatorDataValueSelectSql(programStageId, dataElementId, params.getReportingStartDate(), params.getReportingEndDate(), params.getProgramIndicator());
}
if (visitor.getState().isReplaceNulls()) {
DataElement dataElement = visitor.getIdObjectManager().get(DataElement.class, dataElementId);
if (dataElement == null) {
throw new ParserExceptionWithoutContext("Data element " + dataElementId + " not found during SQL generation.");
}
column = replaceNullSqlValues(column, dataElement.getValueType());
}
return column;
}
use of org.hisp.dhis.parser.expression.ProgramExpressionParams in project dhis2-core by dhis2.
the class ProgramSqlGeneratorItemsTest method test.
private Object test(String expression, AntlrExprLiteral exprLiteral, ExpressionItemMethod itemMethod) {
Set<String> dataElementsAndAttributesIdentifiers = new LinkedHashSet<>();
dataElementsAndAttributesIdentifiers.add(BASE_UID + "a");
dataElementsAndAttributesIdentifiers.add(BASE_UID + "b");
dataElementsAndAttributesIdentifiers.add(BASE_UID + "c");
ProgramExpressionParams params = ProgramExpressionParams.builder().programIndicator(programIndicator).reportingStartDate(startDate).reportingEndDate(endDate).dataElementAndAttributeIdentifiers(dataElementsAndAttributesIdentifiers).build();
CommonExpressionVisitor visitor = CommonExpressionVisitor.builder().idObjectManager(idObjectManager).dimensionService(dimensionService).programIndicatorService(programIndicatorService).programStageService(programStageService).statementBuilder(statementBuilder).i18n(new I18n(null, null)).constantMap(constantMap).itemMap(PROGRAM_INDICATOR_ITEMS).itemMethod(itemMethod).progParams(params).build();
visitor.setExpressionLiteral(exprLiteral);
return Parser.visit(expression, visitor);
}
use of org.hisp.dhis.parser.expression.ProgramExpressionParams in project dhis2-core by dhis2.
the class ProgramSqlGeneratorVariablesTest method test.
private Object test(String expression, AntlrExprLiteral exprLiteral, ProgramIndicator programIndicator) {
Set<String> dataElementsAndAttributesIdentifiers = new LinkedHashSet<>();
dataElementsAndAttributesIdentifiers.add(BASE_UID + "a");
dataElementsAndAttributesIdentifiers.add(BASE_UID + "b");
dataElementsAndAttributesIdentifiers.add(BASE_UID + "c");
ProgramExpressionParams params = ProgramExpressionParams.builder().programIndicator(programIndicator).reportingStartDate(startDate).reportingEndDate(endDate).dataElementAndAttributeIdentifiers(dataElementsAndAttributesIdentifiers).build();
subject = CommonExpressionVisitor.builder().idObjectManager(idObjectManager).dimensionService(dimensionService).programIndicatorService(programIndicatorService).programStageService(programStageService).statementBuilder(statementBuilder).i18n(new I18n(null, null)).itemMap(PROGRAM_INDICATOR_ITEMS).itemMethod(ITEM_GET_SQL).progParams(params).build();
subject.setExpressionLiteral(exprLiteral);
return Parser.visit(expression, subject);
}
use of org.hisp.dhis.parser.expression.ProgramExpressionParams in project dhis2-core by dhis2.
the class D2Condition method getSql.
@Override
public Object getSql(ExprContext ctx, CommonExpressionVisitor visitor) {
String testExpression = trimQuotes(ctx.stringLiteral().getText());
ProgramExpressionParams params = visitor.getProgParams();
String testSql = visitor.getProgramIndicatorService().getAnalyticsSql(testExpression, params.getProgramIndicator(), params.getReportingStartDate(), params.getReportingEndDate());
String valueIfTrue = visitor.castStringVisit(ctx.expr(0));
String valueIfFalse = visitor.castStringVisit(ctx.expr(1));
return "case when (" + testSql + ") then " + valueIfTrue + " else " + valueIfFalse + " end";
}
Aggregations