Search in sources :

Example 1 with Attribute

use of org.pmiops.workbench.model.Attribute in project workbench by all-of-us.

the class CohortBuilderControllerTest method countSubjectsDemoAge.

@Test
public void countSubjectsDemoAge() throws Exception {
    LocalDate birthdate = LocalDate.of(1980, 8, 01);
    LocalDate now = LocalDate.now();
    Integer age = Period.between(birthdate, now).getYears();
    Criteria demoAge = createDemoCriteria("DEMO", "AGE", null);
    SearchParameter demo = createSearchParameter(demoAge, null);
    demo.attribute(new Attribute().operator("=").operands(Arrays.asList(age.toString())));
    SearchRequest searchRequests = createSearchRequests(demoAge.getType(), Arrays.asList(demo));
    assertParticipants(controller.countParticipants(cdrVersion.getCdrVersionId(), searchRequests), 1);
}
Also used : SearchRequest(org.pmiops.workbench.model.SearchRequest) Attribute(org.pmiops.workbench.model.Attribute) Criteria(org.pmiops.workbench.cdr.model.Criteria) SearchParameter(org.pmiops.workbench.model.SearchParameter) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 2 with Attribute

use of org.pmiops.workbench.model.Attribute in project workbench by all-of-us.

the class DemoQueryBuilderTest method buildQueryJobConfig_AttributeWithNoOperands.

@Test
public void buildQueryJobConfig_AttributeWithNoOperands() throws Exception {
    List<SearchParameter> params = new ArrayList<>();
    params.add(new SearchParameter().domain("DEMO").subtype("AGE").attribute(new Attribute().operator("=")));
    try {
        queryBuilder.buildQueryJobConfig(new QueryParameters().type("DEMO").parameters(params));
    } catch (IllegalArgumentException ex) {
        assertEquals("Age must provide an operator and operands.", ex.getMessage());
    }
}
Also used : Attribute(org.pmiops.workbench.model.Attribute) ArrayList(java.util.ArrayList) SearchParameter(org.pmiops.workbench.model.SearchParameter) Test(org.junit.Test)

Example 3 with Attribute

use of org.pmiops.workbench.model.Attribute in project workbench by all-of-us.

the class DemoQueryBuilderTest method buildQueryJobConfig.

@Test
public void buildQueryJobConfig() throws Exception {
    String genderNamedParameter = "";
    String ageNamedParameter = "";
    String raceNamedParameter = "";
    List<SearchParameter> params = new ArrayList<>();
    params.add(new SearchParameter().type("DEMO").subtype("GEN").conceptId(8507L));
    params.add(new SearchParameter().type("DEMO").subtype("AGE").attribute(new Attribute().operator("=").operands(Arrays.asList("18"))));
    params.add(new SearchParameter().type("DEM0").subtype("RACE").conceptId(1234L));
    params.add(new SearchParameter().type("DEM0").subtype("RACE").conceptId(1235L));
    QueryJobConfiguration queryJobConfiguration = queryBuilder.buildQueryJobConfig(new QueryParameters().type("DEMO").parameters(params));
    for (String key : queryJobConfiguration.getNamedParameters().keySet()) {
        if (key.startsWith("gen")) {
            genderNamedParameter = key;
        } else if (key.startsWith("race")) {
            raceNamedParameter = key;
        } else {
            ageNamedParameter = key;
        }
    }
    String expected = "select person_id\n" + "from `${projectId}.${dataSetId}.person` p\n" + "where\n" + "p.gender_concept_id in unnest(@" + genderNamedParameter + ")\n" + "and\n" + "p.race_concept_id in unnest(@" + raceNamedParameter + ")\n" + "and\n" + "CAST(FLOOR(DATE_DIFF(CURRENT_DATE, DATE(p.year_of_birth, p.month_of_birth, p.day_of_birth), MONTH)/12) as INT64) =\n" + "@" + ageNamedParameter + "\n";
    assertEquals(expected, queryJobConfiguration.getQuery());
    assertEquals("8507", queryJobConfiguration.getNamedParameters().get(genderNamedParameter).getArrayValues().get(0).getValue());
    assertEquals("18", queryJobConfiguration.getNamedParameters().get(ageNamedParameter).getValue());
    assertEquals("1234", queryJobConfiguration.getNamedParameters().get(raceNamedParameter).getArrayValues().get(0).getValue());
    assertEquals("1235", queryJobConfiguration.getNamedParameters().get(raceNamedParameter).getArrayValues().get(1).getValue());
}
Also used : Attribute(org.pmiops.workbench.model.Attribute) ArrayList(java.util.ArrayList) SearchParameter(org.pmiops.workbench.model.SearchParameter) QueryJobConfiguration(com.google.cloud.bigquery.QueryJobConfiguration) Test(org.junit.Test)

Example 4 with Attribute

use of org.pmiops.workbench.model.Attribute in project workbench by all-of-us.

the class CohortBuilderControllerTest method countSubjectsDemoGenderAndAge.

@Test
public void countSubjectsDemoGenderAndAge() throws Exception {
    Criteria demoGender = createDemoCriteria("DEMO", "GEN", "8507");
    SearchParameter demoGenderSearchParam = createSearchParameter(demoGender, null);
    LocalDate birthdate = LocalDate.of(1980, 8, 01);
    LocalDate now = LocalDate.now();
    Integer age = Period.between(birthdate, now).getYears();
    Criteria demoAge = createDemoCriteria("DEMO", "AGE", null);
    SearchParameter demoAgeSearchParam = createSearchParameter(demoAge, null);
    demoAgeSearchParam.attribute(new Attribute().operator("=").operands(Arrays.asList(age.toString())));
    SearchRequest searchRequests = createSearchRequests(demoAge.getType(), Arrays.asList(demoGenderSearchParam, demoAgeSearchParam));
    assertParticipants(controller.countParticipants(cdrVersion.getCdrVersionId(), searchRequests), 1);
}
Also used : SearchRequest(org.pmiops.workbench.model.SearchRequest) Attribute(org.pmiops.workbench.model.Attribute) Criteria(org.pmiops.workbench.cdr.model.Criteria) SearchParameter(org.pmiops.workbench.model.SearchParameter) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 5 with Attribute

use of org.pmiops.workbench.model.Attribute in project workbench by all-of-us.

the class CohortBuilderControllerTest method countSubjectsICD9AndDemo.

@Test
public void countSubjectsICD9AndDemo() throws Exception {
    Criteria demoGender = createDemoCriteria("DEMO", "GEN", "8507");
    SearchParameter demoGenderSearchParam = createSearchParameter(demoGender, null);
    LocalDate birthdate = LocalDate.of(1980, 8, 01);
    LocalDate now = LocalDate.now();
    Integer age = Period.between(birthdate, now).getYears();
    Criteria demoAge = createDemoCriteria("DEMO", "AGE", null);
    SearchParameter demoAgeSearchParam = createSearchParameter(demoAge, null);
    demoAgeSearchParam.attribute(new Attribute().operator("=").operands(Arrays.asList(age.toString())));
    SearchRequest searchRequests = createSearchRequests(demoAge.getType(), Arrays.asList(demoGenderSearchParam, demoAgeSearchParam));
    SearchParameter icd9 = createSearchParameter(icd9MeasurementChild, "003.1");
    SearchGroupItem anotherSearchGroupItem = new SearchGroupItem().type(icd9.getType()).searchParameters(Arrays.asList(icd9));
    searchRequests.getIncludes().get(0).addItemsItem(anotherSearchGroupItem);
    assertParticipants(controller.countParticipants(cdrVersion.getCdrVersionId(), searchRequests), 1);
}
Also used : SearchRequest(org.pmiops.workbench.model.SearchRequest) Attribute(org.pmiops.workbench.model.Attribute) Criteria(org.pmiops.workbench.cdr.model.Criteria) SearchParameter(org.pmiops.workbench.model.SearchParameter) LocalDate(java.time.LocalDate) SearchGroupItem(org.pmiops.workbench.model.SearchGroupItem) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 Attribute (org.pmiops.workbench.model.Attribute)5 SearchParameter (org.pmiops.workbench.model.SearchParameter)5 LocalDate (java.time.LocalDate)3 Criteria (org.pmiops.workbench.cdr.model.Criteria)3 SearchRequest (org.pmiops.workbench.model.SearchRequest)3 ArrayList (java.util.ArrayList)2 QueryJobConfiguration (com.google.cloud.bigquery.QueryJobConfiguration)1 SearchGroupItem (org.pmiops.workbench.model.SearchGroupItem)1