use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class SurveyTest method updateAndQuery.
@Test
public void updateAndQuery() {
// Post a number of records
RecordGenerator generator = survey.getGenerator();
int numRows = 20;
for (int i = 0; i < numRows; i++) {
client.createRecord(generator.get());
}
// Now query a few records
QueryModel queryModel = new QueryModel(survey.getFormId());
queryModel.selectField(survey.getGenderFieldId()).as("gender");
queryModel.selectField(survey.getAgeFieldId()).as("age");
queryModel.selectField(survey.getDobFieldId()).as("dob");
ColumnSet columnSet = client.queryTable(queryModel);
ColumnView gender = columnSet.getColumnView("gender");
ColumnView age = columnSet.getColumnView("age");
ColumnView dob = columnSet.getColumnView("dob");
assertThat(gender.numRows(), equalTo(numRows));
assertThat(gender.getType(), equalTo(ColumnType.STRING));
assertThat(age.numRows(), equalTo(numRows));
}
use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class DateFunctionQueryTest method invalidArityTest.
@Test
public void invalidArityTest() {
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("YEARFRAC(TODAY())").as("age");
ColumnSet columnSet = builder.build(queryModel);
ColumnView age = columnSet.getColumnView("age");
assertThat(age.numRows(), equalTo(IntakeForm.ROW_COUNT));
System.out.println(age);
}
use of org.activityinfo.model.query.ColumnView 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);
}
use of org.activityinfo.model.query.ColumnView 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()));
}
use of org.activityinfo.model.query.ColumnView 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));
}
Aggregations