Search in sources :

Example 16 with CalculatedFieldType

use of org.activityinfo.model.type.expr.CalculatedFieldType in project activityinfo by bedatadriven.

the class ActivityLoader method addField.

private void addField(Activity activity, ResultSet rs, Map<Integer, List<EnumItem>> attributes) throws SQLException {
    int id = rs.getInt("id");
    FormField formField;
    if (rs.getString("Type").equals("ENUM")) {
        formField = new FormField(CuidAdapter.attributeGroupField(id));
    } else {
        formField = new FormField(CuidAdapter.indicatorField(id));
    }
    formField.setLabel(rs.getString("Name"));
    formField.setRequired(getMandatory(rs));
    formField.setVisible(getVisible(rs));
    formField.setDescription(rs.getString("Description"));
    formField.setCode(rs.getString("code"));
    if (rs.getBoolean("ca") && rs.getString("expr") != null) {
        formField.setType(new CalculatedFieldType(rs.getString("expr")));
    } else {
        switch(rs.getString("Type")) {
            default:
            case "QUANTITY":
                formField.setType(new QuantityType().setUnits(rs.getString("units")).setAggregation(rs.getInt("Aggregation")));
                break;
            case "BARCODE":
                formField.setType(BarcodeType.INSTANCE);
                break;
            case "FREE_TEXT":
                formField.setType(TextType.SIMPLE);
                break;
            case "NARRATIVE":
                formField.setType(NarrativeType.INSTANCE);
                break;
            case "ENUM":
                formField.setType(createEnumType(rs, attributes));
                break;
        }
    }
    ActivityField field = new ActivityField(id, rs.getString("category"), formField, rs.getInt("sortOrder"));
    field.sortOrder = rs.getInt("sortOrder");
    activity.fields.add(field);
}
Also used : CalculatedFieldType(org.activityinfo.model.type.expr.CalculatedFieldType) QuantityType(org.activityinfo.model.type.number.QuantityType) FormField(org.activityinfo.model.form.FormField)

Aggregations

CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)16 QuantityType (org.activityinfo.model.type.number.QuantityType)12 FormClass (org.activityinfo.model.form.FormClass)7 FormField (org.activityinfo.model.form.FormField)7 Test (org.junit.Test)6 EnumType (org.activityinfo.model.type.enumerated.EnumType)4 FieldType (org.activityinfo.model.type.FieldType)3 ColumnView (org.activityinfo.model.query.ColumnView)2 QueryModel (org.activityinfo.model.query.QueryModel)2 ResourceId (org.activityinfo.model.resource.ResourceId)2 NarrativeType (org.activityinfo.model.type.NarrativeType)2 ReferenceType (org.activityinfo.model.type.ReferenceType)2 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)2 Quantity (org.activityinfo.model.type.number.Quantity)2 TextType (org.activityinfo.model.type.primitive.TextType)2 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)2 LocalDateType (org.activityinfo.model.type.time.LocalDateType)2 ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)2 TypedRecordUpdate (org.activityinfo.store.spi.TypedRecordUpdate)2 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)1