Search in sources :

Example 11 with QuantityType

use of org.activityinfo.model.type.number.QuantityType 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)

Example 12 with QuantityType

use of org.activityinfo.model.type.number.QuantityType in project activityinfo by bedatadriven.

the class SchemaCsvWriterV3Test method setupMonthly.

private void setupMonthly() {
    washForm = new FormClass(ResourceId.valueOf("FORM3"));
    washForm.setLabel("Emergency WASH");
    washForm.addElement(new FormField(ResourceId.valueOf("WF1")).setLabel("Partner").setRequired(true).setType(new ReferenceType(Cardinality.SINGLE, ResourceId.valueOf("PARTNER_FORM"))));
    washForm.addElement(new FormField(ResourceId.valueOf("Population")).setCode("POP").setLabel("Affected Population Size").setType(new QuantityType("households")).setRequired(true));
    washForm.addElement(new FormField(ResourceId.valueOf("Population")).setCode("POP").setLabel("Affected Population Size").setType(new QuantityType("households")).setRequired(true));
    FormClass subFormClass = new FormClass(ResourceId.valueOf("FORM4"));
    subFormClass.setSubFormKind(SubFormKind.WEEKLY);
    subFormClass.addElement(new FormField(ResourceId.valueOf("WSF1")).setLabel("Water Trucking").setType(new QuantityType("households")).setRequired(true));
    subFormClass.addElement(new FormField(ResourceId.valueOf("WSF2")).setLabel("Cholorination").setType(new QuantityType("households")).setRequired(true));
    washForm.addElement(new FormField(ResourceId.valueOf("SF")).setLabel("Monthly Output").setType(new SubFormReferenceType(subFormClass.getId())));
    formClassProvider.add(washForm);
    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) FormField(org.activityinfo.model.form.FormField) SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) ReferenceType(org.activityinfo.model.type.ReferenceType)

Example 13 with QuantityType

use of org.activityinfo.model.type.number.QuantityType in project activityinfo by bedatadriven.

the class MySqlCatalogIntegrationTest method testActivity.

@Test
public void testActivity() throws IOException {
    QueryModel model = new QueryModel(activityFormClass(33));
    model.selectField("date1");
    model.selectField("date2");
    model.selectExpr("Partner.name");
    FormTree formTree = new FormTreeBuilder(catalog).queryTree(activityFormClass(33));
    FormTreePrettyPrinter.print(formTree);
    FormClass formClass = catalog.getForm(activityFormClass(33)).get().getFormClass();
    for (FormField field : formClass.getFields()) {
        if (field.getType() instanceof QuantityType) {
            model.selectField(field.getId()).as("I" + CuidAdapter.getLegacyIdFromCuid(field.getId()));
        }
    }
    Stopwatch stopwatch = Stopwatch.createStarted();
    ColumnSet columnSet = columnSetBuilder.build(model);
    System.out.println("Query executed in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms");
    assertThat(columnSet.getNumRows(), equalTo(652));
    StringWriter stringWriter = new StringWriter();
    RowBasedJsonWriter writer = new RowBasedJsonWriter(stringWriter);
    writer.write(columnSet);
    System.out.println(stringWriter.toString());
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) StringWriter(java.io.StringWriter) QuantityType(org.activityinfo.model.type.number.QuantityType) FormClass(org.activityinfo.model.form.FormClass) CuidAdapter.activityFormClass(org.activityinfo.model.legacy.CuidAdapter.activityFormClass) Stopwatch(com.google.common.base.Stopwatch) ColumnSet(org.activityinfo.model.query.ColumnSet) RowBasedJsonWriter(org.activityinfo.store.query.output.RowBasedJsonWriter) QueryModel(org.activityinfo.model.query.QueryModel) FormField(org.activityinfo.model.form.FormField) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) Test(org.junit.Test)

Example 14 with QuantityType

use of org.activityinfo.model.type.number.QuantityType in project activityinfo by bedatadriven.

the class ActivityUpdater method insertIndicatorRow.

private void insertIndicatorRow(FormField formField, int sortOrder) {
    SqlInsert insert = SqlInsert.insertInto("indicator");
    insert.value("indicatorId", CuidAdapter.getLegacyIdFromCuid(formField.getId()));
    insert.value("activityId", activityId);
    insert.value("name", formField.getLabel());
    insert.value("nameInExpression", formField.getCode());
    insert.value("description", formField.getDescription());
    if (formField.getType() instanceof QuantityType) {
        insert.value("aggregation", ((QuantityType) formField.getType()).getAggregation().ordinal());
    } else {
        insert.value("aggregation", 0);
    }
    insert.value("sortOrder", sortOrder);
    insert.value("type", formField.getType().getTypeClass().getId());
    insert.value("mandatory", formField.isRequired());
    if (formField.getType() instanceof QuantityType) {
        QuantityType quantityType = (QuantityType) formField.getType();
        insert.value("units", quantityType.getUnits());
    }
    if (formField.getType() instanceof CalculatedFieldType) {
        CalculatedFieldType type = (CalculatedFieldType) formField.getType();
        insert.value("calculatedAutomatically", true);
        insert.value("expression", type.getExpression());
    }
    insert.execute(executor);
}
Also used : CalculatedFieldType(org.activityinfo.model.type.expr.CalculatedFieldType) QuantityType(org.activityinfo.model.type.number.QuantityType)

Example 15 with QuantityType

use of org.activityinfo.model.type.number.QuantityType in project activityinfo by bedatadriven.

the class ActivityUpdater method updateIndicatorRow.

private void updateIndicatorRow(ActivityField existingField, FormField formField, int sortOrder) {
    SqlUpdate update = SqlUpdate.update("indicator");
    update.where("indicatorId", existingField.getId());
    update.setIfChanged("name", existingField.getFormField().getLabel(), formField.getLabel());
    update.setIfChanged("nameInExpression", existingField.getFormField().getCode(), formField.getCode(), 255);
    update.setIfChanged("sortOrder", existingField.getSortOrder(), sortOrder);
    update.setIfChanged("description", existingField.getFormField().getDescription(), formField.getDescription());
    update.setIfChanged("mandatory", existingField.getFormField().isRequired(), formField.isRequired());
    if (existingField.getFormField().getType() instanceof QuantityType) {
        QuantityType existingType = (QuantityType) existingField.getFormField().getType();
        QuantityType updatedType = (QuantityType) formField.getType();
        update.setIfChanged("units", existingType.getUnits(), updatedType.getUnits(), 255);
        update.setIfChanged("aggregation", existingType.getAggregation(), updatedType.getAggregation());
    }
    if (existingField.getFormField().getType() instanceof CalculatedFieldType) {
        CalculatedFieldType existingType = (CalculatedFieldType) existingField.getFormField().getType();
        CalculatedFieldType updatedType = (CalculatedFieldType) formField.getType();
        update.setIfChanged("expression", existingType.getExpression(), updatedType.getExpression());
    }
    update.execute(executor);
}
Also used : CalculatedFieldType(org.activityinfo.model.type.expr.CalculatedFieldType) QuantityType(org.activityinfo.model.type.number.QuantityType)

Aggregations

QuantityType (org.activityinfo.model.type.number.QuantityType)34 FormClass (org.activityinfo.model.form.FormClass)20 FormField (org.activityinfo.model.form.FormField)19 Test (org.junit.Test)18 ResourceId (org.activityinfo.model.resource.ResourceId)13 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)12 EnumType (org.activityinfo.model.type.enumerated.EnumType)8 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)7 Quantity (org.activityinfo.model.type.number.Quantity)7 QueryModel (org.activityinfo.model.query.QueryModel)6 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)6 JsonValue (org.activityinfo.json.JsonValue)5 CuidAdapter.activityFormClass (org.activityinfo.model.legacy.CuidAdapter.activityFormClass)5 ColumnSet (org.activityinfo.model.query.ColumnSet)5 ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)4 NullFormSupervisor (org.activityinfo.store.query.shared.NullFormSupervisor)4 TypedRecordUpdate (org.activityinfo.store.spi.TypedRecordUpdate)4 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)3 FieldType (org.activityinfo.model.type.FieldType)3 TextType (org.activityinfo.model.type.primitive.TextType)3