Search in sources :

Example 6 with SearchGroup

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

the class DomainLookupServiceTest method findCodesForEmptyDomains.

@Test
public void findCodesForEmptyDomains() throws Exception {
    SearchParameter searchParameter1 = new SearchParameter().type("ICD9").value("001").domain("Condition");
    SearchParameter searchParameter2 = new SearchParameter().type("ICD9").value("002").domain(null);
    SearchGroupItem searchGroupItem1 = new SearchGroupItem().type("ICD9").addSearchParametersItem(searchParameter1).addSearchParametersItem(searchParameter2);
    SearchRequest request = new SearchRequest().addIncludesItem(new SearchGroup().addItemsItem(searchGroupItem1));
    List<String> lookups = new ArrayList<>();
    lookups.add("Procedure");
    when(criteriaDao.findCriteriaByTypeAndCode(searchParameter2.getType(), searchParameter2.getValue())).thenReturn(lookups);
    domainLookupService.findCodesForEmptyDomains(request.getIncludes());
    assertEquals(2, searchGroupItem1.getSearchParameters().size());
    assertEquals("001", searchGroupItem1.getSearchParameters().get(0).getValue());
    assertEquals("Condition", searchGroupItem1.getSearchParameters().get(0).getDomain());
    assertEquals("002", searchGroupItem1.getSearchParameters().get(1).getValue());
    assertEquals("Procedure", searchGroupItem1.getSearchParameters().get(1).getDomain());
    verify(criteriaDao, times(1)).findCriteriaByTypeAndCode(searchParameter2.getType(), searchParameter2.getValue());
    verifyNoMoreInteractions(criteriaDao);
}
Also used : SearchRequest(org.pmiops.workbench.model.SearchRequest) SearchGroup(org.pmiops.workbench.model.SearchGroup) ArrayList(java.util.ArrayList) SearchParameter(org.pmiops.workbench.model.SearchParameter) SearchGroupItem(org.pmiops.workbench.model.SearchGroupItem) Test(org.junit.Test)

Example 7 with SearchGroup

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

the class ParticipantCounterTest method buildParticipantIdQuery.

@Test
public void buildParticipantIdQuery() throws Exception {
    String genderNamedParameter = "";
    String conditionNamedParameter = "";
    String procedureNamedParameter = "";
    String cmConditionParameter = "";
    String procConditionParameter = "";
    String cmProcedureParameter = "";
    String procProcedureParameter = "";
    SearchParameter parameter1 = new SearchParameter().domain("Condition").group(false).type("ICD9").value("001.1");
    SearchParameter parameter2 = new SearchParameter().subtype("GEN").conceptId(8507L);
    SearchParameter parameter3 = new SearchParameter().domain("Procedure").group(false).type("CPT").value("001.2");
    SearchGroupItem searchGroupItem1 = new SearchGroupItem().type("ICD9").addSearchParametersItem(parameter1);
    SearchGroupItem searchGroupItem2 = new SearchGroupItem().type("DEMO").addSearchParametersItem(parameter2);
    SearchGroupItem searchGroupItem3 = new SearchGroupItem().type("CPT").addSearchParametersItem(parameter3);
    SearchGroup searchGroup1 = new SearchGroup().addItemsItem(searchGroupItem1);
    SearchGroup searchGroup2 = new SearchGroup().addItemsItem(searchGroupItem2);
    SearchGroup searchGroup3 = new SearchGroup().addItemsItem(searchGroupItem3);
    SearchRequest request = new SearchRequest().addIncludesItem(searchGroup1).addIncludesItem(searchGroup2).addExcludesItem(searchGroup3);
    QueryJobConfiguration actualRequest = participantCounter.buildParticipantIdQuery(new ParticipantCriteria(request), 200, 0);
    for (String key : actualRequest.getNamedParameters().keySet()) {
        if (key.startsWith("gen")) {
            genderNamedParameter = key;
        } else if (key.startsWith("Condition")) {
            conditionNamedParameter = key;
            cmConditionParameter = "cm" + key.replace("Condition", "");
            procConditionParameter = "proc" + key.replace("Condition", "");
        } else if (key.startsWith("Procedure")) {
            procedureNamedParameter = key;
            cmProcedureParameter = "cm" + key.replace("Procedure", "");
            procProcedureParameter = "proc" + key.replace("Procedure", "");
        }
    }
    final String expectedSql = "select person_id, race_concept_id, gender_concept_id, ethnicity_concept_id, birth_datetime\n" + "from `${projectId}.${dataSetId}.person` person\n" + "where\n" + "person.person_id in (select person_id\n" + "from `${projectId}.${dataSetId}.person` p\n" + "where person_id in (select person_id\n" + "from `${projectId}.${dataSetId}.condition_occurrence` a, `${projectId}.${dataSetId}.concept` b\n" + "where a.condition_source_concept_id = b.concept_id\n" + "and b.vocabulary_id in (@" + cmConditionParameter + ",@" + procConditionParameter + ")\n" + "and b.concept_code in unnest(@" + conditionNamedParameter + ")\n" + ")\n" + ")\n" + "and person.person_id in (select person_id\n" + "from `${projectId}.${dataSetId}.person` p\n" + "where\n" + "p.gender_concept_id in unnest(@" + genderNamedParameter + ")\n" + ")\n" + "and not exists\n" + "(select 'x' from\n" + "(select person_id\n" + "from `${projectId}.${dataSetId}.person` p\n" + "where person_id in (select person_id\n" + "from `${projectId}.${dataSetId}.procedure_occurrence` a, `${projectId}.${dataSetId}.concept` b\n" + "where a.procedure_source_concept_id = b.concept_id\n" + "and b.vocabulary_id in (@" + cmProcedureParameter + ",@" + procProcedureParameter + ")\n" + "and b.concept_code in unnest(@" + procedureNamedParameter + ")\n" + ")\n" + ")\n" + "x where x.person_id = person.person_id)\n" + "order by person_id\n" + "limit 200";
    assertEquals(expectedSql, actualRequest.getQuery());
    assertEquals("8507", actualRequest.getNamedParameters().get(genderNamedParameter).getArrayValues().get(0).getValue());
    assertEquals(parameter1.getValue(), actualRequest.getNamedParameters().get(conditionNamedParameter).getArrayValues().get(0).getValue());
}
Also used : SearchRequest(org.pmiops.workbench.model.SearchRequest) SearchGroup(org.pmiops.workbench.model.SearchGroup) SearchParameter(org.pmiops.workbench.model.SearchParameter) QueryJobConfiguration(com.google.cloud.bigquery.QueryJobConfiguration) SearchGroupItem(org.pmiops.workbench.model.SearchGroupItem) Test(org.junit.Test)

Example 8 with SearchGroup

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

the class ParticipantCounterTest method buildChartInfoCounterQuery.

@Test
public void buildChartInfoCounterQuery() throws Exception {
    String genderNamedParameter = "";
    String conditionNamedParameter = "";
    String procedureNamedParameter = "";
    String cmConditionParameter = "";
    String procConditionParameter = "";
    String cmProcedureParameter = "";
    String procProcedureParameter = "";
    SearchParameter parameter1 = new SearchParameter().domain("Condition").group(false).type("ICD9").value("001.1");
    SearchParameter parameter2 = new SearchParameter().subtype("GEN").conceptId(8507L);
    SearchParameter parameter3 = new SearchParameter().domain("Procedure").group(false).type("CPT").value("001.2");
    SearchGroupItem searchGroupItem1 = new SearchGroupItem().type("ICD9").addSearchParametersItem(parameter1);
    SearchGroupItem searchGroupItem2 = new SearchGroupItem().type("DEMO").addSearchParametersItem(parameter2);
    SearchGroupItem searchGroupItem3 = new SearchGroupItem().type("CPT").addSearchParametersItem(parameter3);
    SearchGroup searchGroup1 = new SearchGroup().addItemsItem(searchGroupItem1);
    SearchGroup searchGroup2 = new SearchGroup().addItemsItem(searchGroupItem2);
    SearchGroup searchGroup3 = new SearchGroup().addItemsItem(searchGroupItem3);
    SearchRequest request = new SearchRequest().addIncludesItem(searchGroup1).addIncludesItem(searchGroup2).addExcludesItem(searchGroup3);
    QueryJobConfiguration actualRequest = participantCounter.buildChartInfoCounterQuery(new ParticipantCriteria(request));
    for (String key : actualRequest.getNamedParameters().keySet()) {
        if (key.startsWith("gen")) {
            genderNamedParameter = key;
        } else if (key.startsWith("Condition")) {
            conditionNamedParameter = key;
            cmConditionParameter = "cm" + key.replace("Condition", "");
            procConditionParameter = "proc" + key.replace("Condition", "");
        } else if (key.startsWith("Procedure")) {
            procedureNamedParameter = key;
            cmProcedureParameter = "cm" + key.replace("Procedure", "");
            procProcedureParameter = "proc" + key.replace("Procedure", "");
        }
    }
    final String expectedSql = "select concept1.concept_code as gender, \n" + "case when concept2.concept_name is null then 'Unknown' else concept2.concept_name end as race, \n" + "case when CAST(FLOOR(DATE_DIFF(CURRENT_DATE, DATE(person.year_of_birth, person.month_of_birth, person.day_of_birth), MONTH)/12) as INT64) >= 0 and CAST(FLOOR(DATE_DIFF(CURRENT_DATE, DATE(person.year_of_birth, person.month_of_birth, person.day_of_birth), MONTH)/12) as INT64) <= 18 then '0-18'\n" + "when CAST(FLOOR(DATE_DIFF(CURRENT_DATE, DATE(person.year_of_birth, person.month_of_birth, person.day_of_birth), MONTH)/12) as INT64) >= 19 and CAST(FLOOR(DATE_DIFF(CURRENT_DATE, DATE(person.year_of_birth, person.month_of_birth, person.day_of_birth), MONTH)/12) as INT64) <= 44 then '19-44'\n" + "when CAST(FLOOR(DATE_DIFF(CURRENT_DATE, DATE(person.year_of_birth, person.month_of_birth, person.day_of_birth), MONTH)/12) as INT64) >= 45 and CAST(FLOOR(DATE_DIFF(CURRENT_DATE, DATE(person.year_of_birth, person.month_of_birth, person.day_of_birth), MONTH)/12) as INT64) <= 64 then '45-64'\n" + "else '> 65'\n" + "end as ageRange,\n" + "count(*) as count\n" + "from `${projectId}.${dataSetId}.person` person\n" + "left join `${projectId}.${dataSetId}.concept` concept1 on (person.gender_concept_id = concept1.concept_id and concept1.vocabulary_id = 'Gender')\n" + "left join `${projectId}.${dataSetId}.concept` concept2 on (person.race_concept_id = concept2.concept_id and concept2.vocabulary_id = 'Race')\n" + "where\n" + "person.person_id in (select person_id\n" + "from `${projectId}.${dataSetId}.person` p\n" + "where person_id in (select person_id\n" + "from `${projectId}.${dataSetId}.condition_occurrence` a, `${projectId}.${dataSetId}.concept` b\n" + "where a.condition_source_concept_id = b.concept_id\n" + "and b.vocabulary_id in (@" + cmConditionParameter + ",@" + procConditionParameter + ")\n" + "and b.concept_code in unnest(@" + conditionNamedParameter + ")\n" + ")\n" + ")\n" + "and person.person_id in (select person_id\n" + "from `${projectId}.${dataSetId}.person` p\n" + "where\n" + "p.gender_concept_id in unnest(@" + genderNamedParameter + ")\n" + ")\n" + "and not exists\n" + "(select 'x' from\n" + "(select person_id\n" + "from `${projectId}.${dataSetId}.person` p\n" + "where person_id in (select person_id\n" + "from `${projectId}.${dataSetId}.procedure_occurrence` a, `${projectId}.${dataSetId}.concept` b\n" + "where a.procedure_source_concept_id = b.concept_id\n" + "and b.vocabulary_id in (@" + cmProcedureParameter + ",@" + procProcedureParameter + ")\n" + "and b.concept_code in unnest(@" + procedureNamedParameter + ")\n" + ")\n" + ")\n" + "x where x.person_id = person.person_id)\n" + "group by gender, race, ageRange\n" + "order by gender, race, ageRange\n";
    assertEquals(expectedSql, actualRequest.getQuery());
    assertEquals("8507", actualRequest.getNamedParameters().get(genderNamedParameter).getArrayValues().get(0).getValue());
    assertEquals(parameter1.getValue(), actualRequest.getNamedParameters().get(conditionNamedParameter).getArrayValues().get(0).getValue());
}
Also used : SearchRequest(org.pmiops.workbench.model.SearchRequest) SearchGroup(org.pmiops.workbench.model.SearchGroup) SearchParameter(org.pmiops.workbench.model.SearchParameter) QueryJobConfiguration(com.google.cloud.bigquery.QueryJobConfiguration) SearchGroupItem(org.pmiops.workbench.model.SearchGroupItem) Test(org.junit.Test)

Example 9 with SearchGroup

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

the class DomainLookupService method findCodesForEmptyDomains.

/**
 * Find all domain ids for {@link SearchGroup}s in the following groups:
 * ICD9, ICD10 and CPT.
 *
 * @param searchGroups
 */
public void findCodesForEmptyDomains(List<SearchGroup> searchGroups) {
    searchGroups.stream().flatMap(searchGroup -> searchGroup.getItems().stream()).filter(item -> item.getType().matches("ICD9|ICD10")).forEach(item -> {
        List<SearchParameter> paramsWithDomains = new ArrayList<>();
        for (SearchParameter parameter : item.getSearchParameters()) {
            if (parameter.getDomain() == null || parameter.getDomain().isEmpty()) {
                List<String> domainLookups = (parameter.getSubtype() == null) ? criteriaDao.findCriteriaByTypeAndCode(parameter.getType(), parameter.getValue()) : criteriaDao.findCriteriaByTypeAndSubtypeAndCode(parameter.getType(), parameter.getSubtype(), parameter.getValue());
                for (String row : domainLookups) {
                    paramsWithDomains.add(new SearchParameter().domain(row).value(parameter.getValue()).type(parameter.getType()).subtype(parameter.getSubtype()).group(parameter.getGroup()));
                }
            } else {
                paramsWithDomains.add(parameter);
            }
        }
        item.setSearchParameters(paramsWithDomains);
    });
}
Also used : SearchGroup(org.pmiops.workbench.model.SearchGroup) List(java.util.List) Service(org.springframework.stereotype.Service) Autowired(org.springframework.beans.factory.annotation.Autowired) CriteriaDao(org.pmiops.workbench.cdr.dao.CriteriaDao) SearchParameter(org.pmiops.workbench.model.SearchParameter) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) SearchParameter(org.pmiops.workbench.model.SearchParameter)

Example 10 with SearchGroup

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

the class CohortBuilderControllerTest method countSubjectsDemoExcluded.

@Test
public void countSubjectsDemoExcluded() throws Exception {
    Criteria demoGender = createDemoCriteria("DEMO", "GEN", "8507");
    SearchParameter demoGenderSearchParam = createSearchParameter(demoGender, null);
    SearchParameter demoGenderSearchParamExclude = createSearchParameter(demoGender, null);
    SearchGroupItem excludeSearchGroupItem = new SearchGroupItem().type(demoGender.getType()).searchParameters(Arrays.asList(demoGenderSearchParamExclude));
    SearchGroup excludeSearchGroup = new SearchGroup().addItemsItem(excludeSearchGroupItem);
    SearchRequest searchRequests = createSearchRequests(demoGender.getType(), Arrays.asList(demoGenderSearchParam));
    searchRequests.getExcludes().add(excludeSearchGroup);
    assertParticipants(controller.countParticipants(cdrVersion.getCdrVersionId(), searchRequests), 0);
}
Also used : SearchRequest(org.pmiops.workbench.model.SearchRequest) SearchGroup(org.pmiops.workbench.model.SearchGroup) Criteria(org.pmiops.workbench.cdr.model.Criteria) SearchParameter(org.pmiops.workbench.model.SearchParameter) SearchGroupItem(org.pmiops.workbench.model.SearchGroupItem) Test(org.junit.Test)

Aggregations

SearchGroup (org.pmiops.workbench.model.SearchGroup)10 SearchGroupItem (org.pmiops.workbench.model.SearchGroupItem)8 SearchRequest (org.pmiops.workbench.model.SearchRequest)8 SearchParameter (org.pmiops.workbench.model.SearchParameter)7 Test (org.junit.Test)6 QueryJobConfiguration (com.google.cloud.bigquery.QueryJobConfiguration)5 ArrayList (java.util.ArrayList)4 List (java.util.List)1 StringJoiner (java.util.StringJoiner)1 CriteriaDao (org.pmiops.workbench.cdr.dao.CriteriaDao)1 Criteria (org.pmiops.workbench.cdr.model.Criteria)1 QueryParameters (org.pmiops.workbench.cohortbuilder.querybuilder.QueryParameters)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Service (org.springframework.stereotype.Service)1