Search in sources :

Example 11 with EnumItem

use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.

the class CompactingEnumColumnBuilderTest method buildCompact.

@Test
public void buildCompact() {
    EnumItem a = new EnumItem(ResourceId.valueOf("a"), "Enumerated Item A");
    EnumItem b = new EnumItem(ResourceId.valueOf("b"), "Enumerated Item B");
    EnumItem c = new EnumItem(ResourceId.valueOf("c"), "Enumerated Item C");
    EnumType enumType = new EnumType(Cardinality.SINGLE, a, b, c);
    CompactingEnumColumnBuilder builder = new CompactingEnumColumnBuilder(new PendingSlot<ColumnView>(), enumType);
    for (int i = 0; i < 13; i++) {
        builder.onNext(new EnumValue(a.getId()));
        builder.onNext(new EnumValue(b.getId()));
        builder.onNext(new EnumValue(c.getId()));
        builder.onNext(null);
    }
    ColumnView column8 = builder.build8();
    ColumnView column32 = builder.build32();
    for (int i = 0; i < column32.numRows(); i++) {
        if (!Objects.equals(column8.getString(i), column32.getString(i))) {
            throw new AssertionError("Vectors not equal at index " + i);
        }
    }
    assertThat(builder.build(), instanceOf(DiscreteStringColumnView8.class));
}
Also used : EnumType(org.activityinfo.model.type.enumerated.EnumType) EnumValue(org.activityinfo.model.type.enumerated.EnumValue) ColumnView(org.activityinfo.model.query.ColumnView) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) Test(org.junit.Test)

Example 12 with EnumItem

use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.

the class NodeMatcherTest method multiEnum.

private FormField multiEnum(String id, String label, String... values) {
    List<EnumItem> enumValues = Lists.newArrayList();
    for (String value : values) {
        enumValues.add(new EnumItem(ResourceId.valueOf(value), value));
    }
    EnumType type = new EnumType(Cardinality.MULTIPLE, enumValues);
    FormField field = new FormField(ResourceId.valueOf(id));
    field.setLabel(label);
    field.setType(type);
    return field;
}
Also used : EnumType(org.activityinfo.model.type.enumerated.EnumType) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) FormField(org.activityinfo.model.form.FormField)

Example 13 with EnumItem

use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.

the class NodeMatcher method matchEnum.

private Optional<NodeMatch> matchEnum(QueryPath queryPath, FormTree.Node field) {
    if (queryPath.matches(field)) {
        QueryPath next = queryPath.next();
        if (next.isLeaf()) {
            EnumType type = (EnumType) field.getType();
            List<EnumItem> matchingItems = Lists.newArrayList();
            for (EnumItem enumItem : type.getValues()) {
                if (next.head().equals(enumItem.getId().asString()) || next.head().equalsIgnoreCase(enumItem.getLabel()) || next.head().equalsIgnoreCase(enumItem.getCode())) {
                    matchingItems.add(enumItem);
                }
            }
            if (matchingItems.size() == 1) {
                return Optional.of(NodeMatch.forEnumItem(field, matchingItems.get(0)));
            }
        }
    }
    return Optional.absent();
}
Also used : EnumType(org.activityinfo.model.type.enumerated.EnumType) EnumItem(org.activityinfo.model.type.enumerated.EnumItem)

Example 14 with EnumItem

use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.

the class EnumGenerator method get.

@Override
public FieldValue get() {
    double missing = random.nextDouble();
    if (missing < probabilityMissing) {
        return null;
    }
    int itemIndex = random.nextInt(enumType.getValues().size());
    EnumItem item = enumType.getValues().get(itemIndex);
    return new EnumValue(item.getId());
}
Also used : EnumValue(org.activityinfo.model.type.enumerated.EnumValue) EnumItem(org.activityinfo.model.type.enumerated.EnumItem)

Example 15 with EnumItem

use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.

the class SchemaCsvWriterV3Test method setupSurveyForm.

private void setupSurveyForm() {
    surveyForm = new FormClass(ResourceId.valueOf("FORM1"));
    surveyForm.setLabel("Household Survey");
    surveyForm.addElement(new FormField(ResourceId.valueOf("F1")).setCode("NAME").setLabel("What is your name?").setDescription("The head of household's name").setRequired(true).setType(TextType.SIMPLE));
    surveyForm.addElement(new FormField(ResourceId.valueOf("F2")).setCode("AGE").setLabel("What is your age?").setType(new QuantityType("years")).setRequired(true));
    surveyForm.addElement(new FormField(ResourceId.valueOf("F3")).setCode("GENDER").setLabel("Gender of head of household").setType(new EnumType(Cardinality.SINGLE, new EnumItem(ResourceId.valueOf("GF"), "Female"), new EnumItem(ResourceId.valueOf("GM"), "Male"))).setRequired(true));
    surveyForm.addElement(new FormField(ResourceId.valueOf("F4")).setLabel("Are you currently pregnant?").setRelevanceConditionExpression("AGE > 18 && GENDER == 'Female'").setType(new EnumType(Cardinality.SINGLE, new EnumItem(ResourceId.valueOf("PY"), "Yes"), new EnumItem(ResourceId.valueOf("PN"), "No"))).setRequired(true));
    surveyForm.addElement(new FormField(ResourceId.valueOf("F5")).setLabel("Remarks").setType(NarrativeType.INSTANCE).setRequired(false));
    FormClass subFormClass = new FormClass(ResourceId.valueOf("FORM2"));
    subFormClass.setSubFormKind(SubFormKind.REPEATING);
    subFormClass.addElement(new FormField(ResourceId.valueOf("F21")).setLabel("Name").setType(TextType.SIMPLE).setRequired(true));
    subFormClass.addElement(new FormField(ResourceId.valueOf("F22")).setLabel("Age").setType(new QuantityType("years")).setRequired(true));
    subFormClass.addElement(new FormField(ResourceId.valueOf("F23")).setLabel("Gender").setType(new EnumType(Cardinality.SINGLE, new EnumItem(ResourceId.valueOf("GF"), "Female"), new EnumItem(ResourceId.valueOf("GM"), "Male"))).setRequired(true));
    subFormClass.addElement(new FormField(ResourceId.valueOf("F24")).setLabel("Vaccinations").setType(new EnumType(Cardinality.MULTIPLE, new EnumItem(ResourceId.valueOf("V1"), "Measles"), new EnumItem(ResourceId.valueOf("V2"), "Mumps"), new EnumItem(ResourceId.valueOf("V3"), "Rubella"))));
    surveyForm.addElement(new FormField(ResourceId.valueOf("SF")).setLabel("Household members").setType(new SubFormReferenceType(subFormClass.getId())));
    formClassProvider.add(surveyForm);
    formClassProvider.add(subFormClass);
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) QuantityType(org.activityinfo.model.type.number.QuantityType) FormClass(org.activityinfo.model.form.FormClass) EnumType(org.activityinfo.model.type.enumerated.EnumType) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) FormField(org.activityinfo.model.form.FormField)

Aggregations

EnumItem (org.activityinfo.model.type.enumerated.EnumItem)44 EnumType (org.activityinfo.model.type.enumerated.EnumType)30 FormField (org.activityinfo.model.form.FormField)11 FormClass (org.activityinfo.model.form.FormClass)9 ResourceId (org.activityinfo.model.resource.ResourceId)9 Test (org.junit.Test)7 QuantityType (org.activityinfo.model.type.number.QuantityType)6 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)5 CuidAdapter.activityFormClass (org.activityinfo.model.legacy.CuidAdapter.activityFormClass)4 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)3 CompoundExpr (org.activityinfo.model.formula.CompoundExpr)2 SymbolNode (org.activityinfo.model.formula.SymbolNode)2 ColumnModel (org.activityinfo.model.query.ColumnModel)2 ColumnView (org.activityinfo.model.query.ColumnView)2 Cardinality (org.activityinfo.model.type.Cardinality)2 FieldValue (org.activityinfo.model.type.FieldValue)2 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)2 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)2 ActivityField (org.activityinfo.store.mysql.metadata.ActivityField)2 Optional (com.google.common.base.Optional)1