Search in sources :

Example 11 with EnumType

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

the class CloneDatabaseTest method assertFormClass.

private void assertFormClass(FormClass sourceFormClass, FormClass targetFormClass) {
    assertNotEquals(sourceFormClass.getId(), targetFormClass.getId());
    assertEquals(sourceFormClass.getLabel(), targetFormClass.getLabel());
    assertEquals(sourceFormClass.getDescription(), targetFormClass.getDescription());
    // fields
    for (FormField sourceField : sourceFormClass.getFields()) {
        FormField targetField = (FormField) elementByName(targetFormClass.getElements(), sourceField.getLabel());
        assertNotEquals(sourceField.getId(), targetField.getId());
        assertEquals(sourceField.getDescription(), targetField.getDescription());
        assertEquals(sourceField.getCode(), targetField.getCode());
        assertEquals(sourceField.getRelevanceConditionExpression(), targetField.getRelevanceConditionExpression());
        assertEquals(sourceField.getType().getTypeClass(), targetField.getType().getTypeClass());
        // todo
        if (sourceField.getType() instanceof ReferenceType) {
        // need something more sophisticated to check equality of ReferenceType
        } else if (sourceField.getType() instanceof EnumType) {
        // need something more sophisticated to check equality of ReferenceType
        }
    }
    // sections
    for (FormSection sourceSection : sourceFormClass.getSections()) {
        FormSection targetSection = (FormSection) elementByName(targetFormClass.getElements(), sourceSection.getLabel());
        assertNotEquals(sourceSection.getId(), targetSection.getId());
        assertEquals(sourceSection.getLabel(), targetSection.getLabel());
    }
}
Also used : FormSection(org.activityinfo.model.form.FormSection) EnumType(org.activityinfo.model.type.enumerated.EnumType) FormField(org.activityinfo.model.form.FormField) ReferenceType(org.activityinfo.model.type.ReferenceType)

Example 12 with EnumType

use of org.activityinfo.model.type.enumerated.EnumType 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 13 with EnumType

use of org.activityinfo.model.type.enumerated.EnumType 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 14 with EnumType

use of org.activityinfo.model.type.enumerated.EnumType 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 15 with EnumType

use of org.activityinfo.model.type.enumerated.EnumType 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

EnumType (org.activityinfo.model.type.enumerated.EnumType)39 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)30 FormField (org.activityinfo.model.form.FormField)14 FormClass (org.activityinfo.model.form.FormClass)11 ResourceId (org.activityinfo.model.resource.ResourceId)7 QuantityType (org.activityinfo.model.type.number.QuantityType)7 Test (org.junit.Test)7 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)5 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)5 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)4 CuidAdapter.activityFormClass (org.activityinfo.model.legacy.CuidAdapter.activityFormClass)3 JsonValue (org.activityinfo.json.JsonValue)2 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)2 ColumnView (org.activityinfo.model.query.ColumnView)2 Cardinality (org.activityinfo.model.type.Cardinality)2 FieldType (org.activityinfo.model.type.FieldType)2 FieldValue (org.activityinfo.model.type.FieldValue)2 NarrativeType (org.activityinfo.model.type.NarrativeType)2 ReferenceType (org.activityinfo.model.type.ReferenceType)2 TextType (org.activityinfo.model.type.primitive.TextType)2