Search in sources :

Example 11 with SymbolNode

use of org.activityinfo.model.formula.SymbolNode in project activityinfo by bedatadriven.

the class TableViewModel method parentFormula.

private String parentFormula(ParsedFormula formula) {
    if (!formula.isValid()) {
        return formula.getFormula();
    }
    SymbolNode parentSymbol = new SymbolNode(ColumnModel.PARENT_SYMBOL);
    FormulaNode transformed = formula.getRootNode().transform(node -> {
        if (node instanceof SymbolNode) {
            // A -> parent.A
            return new CompoundExpr(parentSymbol, (SymbolNode) node);
        } else {
            return node;
        }
    });
    return transformed.asExpression();
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) SymbolNode(org.activityinfo.model.formula.SymbolNode) FormulaNode(org.activityinfo.model.formula.FormulaNode)

Example 12 with SymbolNode

use of org.activityinfo.model.formula.SymbolNode in project activityinfo by bedatadriven.

the class GeoPointFormat method getColumnModels.

@Override
public List<ColumnModel> getColumnModels() {
    ColumnModel latitudeModel = new ColumnModel();
    latitudeModel.setId(getLatitudeId());
    latitudeModel.setFormula(new CompoundExpr(formula, new SymbolNode("latitude")));
    ColumnModel longitudeModel = new ColumnModel();
    longitudeModel.setId(getLongitudeId());
    longitudeModel.setFormula(new CompoundExpr(formula, new SymbolNode("longitude")));
    return Arrays.asList(latitudeModel, longitudeModel);
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) SymbolNode(org.activityinfo.model.formula.SymbolNode) ColumnModel(org.activityinfo.model.query.ColumnModel)

Example 13 with SymbolNode

use of org.activityinfo.model.formula.SymbolNode in project activityinfo by bedatadriven.

the class MultiEnumFormat method getColumnModels.

@Override
public List<ColumnModel> getColumnModels() {
    List<ColumnModel> columns = new ArrayList<>();
    for (EnumItem enumItem : enumType.getValues()) {
        ColumnModel model = new ColumnModel();
        model.setId(getItemId(enumItem));
        model.setFormula(new CompoundExpr(formula, new SymbolNode(enumItem.getId())));
        columns.add(model);
    }
    return columns;
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) SymbolNode(org.activityinfo.model.formula.SymbolNode) ArrayList(java.util.ArrayList) ColumnModel(org.activityinfo.model.query.ColumnModel) EnumItem(org.activityinfo.model.type.enumerated.EnumItem)

Example 14 with SymbolNode

use of org.activityinfo.model.formula.SymbolNode in project activityinfo by bedatadriven.

the class FieldPath method toExpr.

public FormulaNode toExpr() {
    Iterator<ResourceId> it = path.iterator();
    FormulaNode expr = new SymbolNode(it.next());
    while (it.hasNext()) {
        expr = new CompoundExpr(expr, new SymbolNode(it.next()));
    }
    return expr;
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) SymbolNode(org.activityinfo.model.formula.SymbolNode) FormulaNode(org.activityinfo.model.formula.FormulaNode) ResourceId(org.activityinfo.model.resource.ResourceId)

Example 15 with SymbolNode

use of org.activityinfo.model.formula.SymbolNode in project activityinfo by bedatadriven.

the class SubFormSummaryTest method matchNodes.

@Test
public void matchNodes() {
    TestingStorageProvider catalog = new TestingStorageProvider();
    ClinicForm clinicForm = catalog.getClinicForm();
    FormTree formTree = catalog.getFormTree(clinicForm.getFormId());
    NodeMatcher nodeMatcher = new NodeMatcher(formTree);
    Collection<NodeMatch> nodeMatches = nodeMatcher.resolveSymbol(new SymbolNode("NUM_CONSULT"));
    assertThat(nodeMatches, hasSize(1));
    NodeMatch nodeMatch = Iterables.getOnlyElement(nodeMatches);
    JoinNode joinNode = Iterables.getOnlyElement(nodeMatch.getJoins());
}
Also used : SymbolNode(org.activityinfo.model.formula.SymbolNode) FormTree(org.activityinfo.model.formTree.FormTree) JoinNode(org.activityinfo.store.query.shared.join.JoinNode) NodeMatch(org.activityinfo.store.query.shared.NodeMatch) NodeMatcher(org.activityinfo.store.query.shared.NodeMatcher) Test(org.junit.Test)

Aggregations

SymbolNode (org.activityinfo.model.formula.SymbolNode)22 CompoundExpr (org.activityinfo.model.formula.CompoundExpr)12 FormulaNode (org.activityinfo.model.formula.FormulaNode)8 ColumnModel (org.activityinfo.model.query.ColumnModel)6 Test (org.junit.Test)5 FormTree (org.activityinfo.model.formTree.FormTree)4 ResourceId (org.activityinfo.model.resource.ResourceId)3 JoinNode (org.activityinfo.store.query.shared.join.JoinNode)3 ConstantNode (org.activityinfo.model.formula.ConstantNode)2 ColumnSet (org.activityinfo.model.query.ColumnSet)2 ColumnView (org.activityinfo.model.query.ColumnView)2 QueryModel (org.activityinfo.model.query.QueryModel)2 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Optional (com.google.common.base.Optional)1 Supplier (com.google.common.base.Supplier)1 HashMultimap (com.google.common.collect.HashMultimap)1 Multimap (com.google.common.collect.Multimap)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1