Search in sources :

Example 6 with ColumnSetBuilder

use of org.activityinfo.store.query.server.ColumnSetBuilder in project activityinfo by bedatadriven.

the class DateFunctionQueryTest method testFloorToday.

@Test
public void testFloorToday() {
    TestingStorageProvider catalog = new TestingStorageProvider();
    IntakeForm intakeForm = catalog.getIntakeForm();
    ColumnSetBuilder builder = new ColumnSetBuilder(catalog, new NullFormScanCache(), new NullFormSupervisor());
    QueryModel queryModel = new QueryModel(intakeForm.getFormId());
    queryModel.selectExpr("TODAY()").as("today");
    queryModel.selectExpr("FLOOR(YEARFRAC(\"2017-05-05\", DOB))").as("ageFloored");
    queryModel.selectExpr("FLOOR(1.5)").as("floor");
    queryModel.selectExpr("DOB").as("dob");
    ColumnSet columnSet = builder.build(queryModel);
    ColumnView floor = columnSet.getColumnView("floor");
    ColumnView ageFloored = columnSet.getColumnView("ageFloored");
    assertThat(floor.numRows(), equalTo(intakeForm.getRecords().size()));
    assertThat(floor.getDouble(0), equalTo(1.0));
    assertThat(ageFloored.getDouble(0), equalTo(45.0));
    assertThat(ageFloored.getDouble(3), equalTo(29.0));
    System.out.println(ageFloored);
}
Also used : ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) NullFormScanCache(org.activityinfo.store.query.shared.NullFormScanCache) ColumnView(org.activityinfo.model.query.ColumnView) ColumnSet(org.activityinfo.model.query.ColumnSet) NullFormSupervisor(org.activityinfo.store.query.shared.NullFormSupervisor) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Example 7 with ColumnSetBuilder

use of org.activityinfo.store.query.server.ColumnSetBuilder in project activityinfo by bedatadriven.

the class EnumerationQueryTest method enumIdTests.

@Test
public void enumIdTests() {
    TestingStorageProvider catalog = new TestingStorageProvider();
    ColumnSetBuilder builder = new ColumnSetBuilder(catalog, new NullFormScanCache(), new NullFormSupervisor());
    QueryModel queryModel = new QueryModel(EmptyForm.FORM_ID);
    queryModel.selectField(EmptyForm.ENUM_FIELD_ID).as("emptyEnum");
    queryModel.selectField(EmptyForm.POP_ENUM_FIELD_ID).as("populatedEnum");
    ColumnSet columnSet = builder.build(queryModel);
    ColumnView emptyEnum = columnSet.getColumnView("emptyEnum");
    ColumnView populatedEnum = columnSet.getColumnView("populatedEnum");
    // // Standard Enum Id Checks
    // Null check on empty set first
    assertThat(emptyEnum.get(0), equalTo(null));
    assertThat(((EnumColumnView) emptyEnum).getId(0), equalTo(null));
    // Value check on populated set
    assertThat(populatedEnum.get(0).toString(), equalTo("One"));
    assertThat(((EnumColumnView) populatedEnum).getId(0), equalTo(EmptyForm.ENUM_ONE_ID.asString()));
    // // Selected Row Enum Id Checks
    ColumnView emptySelectedRow = emptyEnum.select(new int[] { 0 });
    ColumnView populatedSelectedRow = populatedEnum.select(new int[] { 0 });
    // Null check on empty set first
    assertThat(emptySelectedRow.get(0), equalTo(null));
    assertThat(((EnumColumnView) emptySelectedRow).getId(0), equalTo(null));
    // Value check on populated set
    assertThat(populatedSelectedRow.get(0).toString(), equalTo("One"));
    assertThat(((EnumColumnView) populatedSelectedRow).getId(0), equalTo(EmptyForm.ENUM_ONE_ID.asString()));
}
Also used : ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) NullFormScanCache(org.activityinfo.store.query.shared.NullFormScanCache) ColumnView(org.activityinfo.model.query.ColumnView) EnumColumnView(org.activityinfo.model.query.EnumColumnView) ColumnSet(org.activityinfo.model.query.ColumnSet) NullFormSupervisor(org.activityinfo.store.query.shared.NullFormSupervisor) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Example 8 with ColumnSetBuilder

use of org.activityinfo.store.query.server.ColumnSetBuilder in project activityinfo by bedatadriven.

the class SubFormSummaryTest method minMaxFunction.

@Test
public void minMaxFunction() {
    TestingStorageProvider catalog = new TestingStorageProvider();
    ClinicForm clinicForm = catalog.getClinicForm();
    ColumnSetBuilder builder = new ColumnSetBuilder(catalog, new NullFormScanCache(), new NullFormSupervisor());
    QueryModel queryModel = new QueryModel(clinicForm.getFormId());
    queryModel.selectResourceId().as("id");
    queryModel.selectExpr("MIN(NUM_CONSULT)").as("min");
    queryModel.selectExpr("MAX(NUM_CONSULT)").as("max");
    ColumnSet columnSet = builder.build(queryModel);
    ColumnView id = columnSet.getColumnView("id");
    ColumnView min = columnSet.getColumnView("min");
    ColumnView max = columnSet.getColumnView("max");
    System.out.println(columnSet.getColumnView("id"));
    System.out.println(min);
    System.out.println(max);
    assertThat(id.getString(0), equalTo("c0"));
    assertThat(min.getDouble(0), equalTo(56.0));
    assertThat(max.getDouble(0), equalTo(247.0));
}
Also used : ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) NullFormScanCache(org.activityinfo.store.query.shared.NullFormScanCache) ColumnView(org.activityinfo.model.query.ColumnView) ColumnSet(org.activityinfo.model.query.ColumnSet) NullFormSupervisor(org.activityinfo.store.query.shared.NullFormSupervisor) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Example 9 with ColumnSetBuilder

use of org.activityinfo.store.query.server.ColumnSetBuilder in project activityinfo by bedatadriven.

the class AbstractMySqlTest method query.

protected final void query(QueryModel queryModel) {
    ColumnSetBuilder builder = new ColumnSetBuilder(catalog, cache, new FormSupervisorAdapter(catalog, userId));
    columnSet = builder.build(queryModel);
    for (String field : columnSet.getColumns().keySet()) {
        System.out.println(field + ": " + column(field));
    }
}
Also used : ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) FormSupervisorAdapter(org.activityinfo.store.query.server.FormSupervisorAdapter)

Example 10 with ColumnSetBuilder

use of org.activityinfo.store.query.server.ColumnSetBuilder in project activityinfo by bedatadriven.

the class MySqlCatalogIntegrationTest method setup.

@BeforeClass
public static void setup() throws Throwable {
    System.out.println("Initializing Locale...");
    LocaleProxy.initialize();
    System.out.println("Running setup...");
    dbunit = new DbUnit();
    dbunit.openDatabase();
    dbunit.dropAllRows();
    dbunit.loadDatset(Resources.getResource(MySqlCatalogTest.class, "rdc.db.xml"));
    catalog = new MySqlCatalogProvider().openCatalog(dbunit.getExecutor());
    columnSetBuilder = new ColumnSetBuilder(catalog, new NullFormSupervisor());
}
Also used : ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) NullFormSupervisor(org.activityinfo.store.query.shared.NullFormSupervisor) BeforeClass(org.junit.BeforeClass)

Aggregations

ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)20 NullFormSupervisor (org.activityinfo.store.query.shared.NullFormSupervisor)16 ColumnSet (org.activityinfo.model.query.ColumnSet)14 QueryModel (org.activityinfo.model.query.QueryModel)13 Test (org.junit.Test)11 ColumnView (org.activityinfo.model.query.ColumnView)8 NullFormScanCache (org.activityinfo.store.query.shared.NullFormScanCache)8 FormClass (org.activityinfo.model.form.FormClass)5 FormField (org.activityinfo.model.form.FormField)3 Quantity (org.activityinfo.model.type.number.Quantity)3 QuantityType (org.activityinfo.model.type.number.QuantityType)3 Charsets (com.google.common.base.Charsets)2 Operation (io.swagger.v3.oas.annotations.Operation)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 MediaType (javax.ws.rs.core.MediaType)2 Response (javax.ws.rs.core.Response)2 StreamingOutput (javax.ws.rs.core.StreamingOutput)2