use of org.pmiops.workbench.model.SearchParameter in project workbench by all-of-us.
the class CohortBuilderControllerTest method countSubjectsICD10ConditionOccurrenceChild.
@Test
public void countSubjectsICD10ConditionOccurrenceChild() throws Exception {
SearchParameter icd10 = createSearchParameter(icd10ConditionChild, "A09");
SearchRequest searchRequest = createSearchRequests(icd10ConditionChild.getType(), Arrays.asList(icd10));
assertParticipants(controller.countParticipants(cdrVersion.getCdrVersionId(), searchRequest), 1);
}
use of org.pmiops.workbench.model.SearchParameter in project workbench by all-of-us.
the class CohortBuilderControllerTest method countSubjectsICD9MeasurementParent.
@Test
public void countSubjectsICD9MeasurementParent() throws Exception {
SearchParameter icd9 = createSearchParameter(icd9MeasurementParent, "003");
SearchRequest searchRequest = createSearchRequests(icd9MeasurementParent.getType(), Arrays.asList(icd9));
assertParticipants(controller.countParticipants(cdrVersion.getCdrVersionId(), searchRequest), 1);
}
use of org.pmiops.workbench.model.SearchParameter in project workbench by all-of-us.
the class CodesQueryBuilder method buildQueryJobConfig.
@Override
public QueryJobConfiguration buildQueryJobConfig(QueryParameters params) {
Map<GroupType, ListMultimap<String, SearchParameter>> paramMap = getMappedParameters(params.getParameters());
List<String> queryParts = new ArrayList<String>();
Map<String, QueryParameterValue> queryParams = new HashMap<>();
for (GroupType group : paramMap.keySet()) {
ListMultimap<String, SearchParameter> domainMap = paramMap.get(group);
for (String domain : domainMap.keySet()) {
final List<SearchParameter> searchParameterList = domainMap.get(domain);
final SearchParameter parameter = searchParameterList.get(0);
final String type = parameter.getType();
final String subtype = parameter.getSubtype();
List<String> codes = searchParameterList.stream().map(SearchParameter::getValue).collect(Collectors.toList());
if (group.equals(GroupType.NOT_GROUP)) {
buildNotGroupQuery(type, subtype, queryParts, queryParams, domain, codes);
} else {
buildGroupQuery(type, subtype, queryParts, queryParams, domain, codes);
}
}
}
String finalSql = OUTER_SQL_TEMPLATE.replace("${innerSql}", String.join(UNION_TEMPLATE, queryParts));
return QueryJobConfiguration.newBuilder(finalSql).setNamedParameters(queryParams).setUseLegacySql(false).build();
}
use of org.pmiops.workbench.model.SearchParameter in project workbench by all-of-us.
the class ParticipantCounterTest method buildParticipantCounterQuery.
@Test
public void buildParticipantCounterQuery() 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.buildParticipantCounterQuery(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 count(*) as count\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";
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());
}
use of org.pmiops.workbench.model.SearchParameter in project workbench by all-of-us.
the class ParticipantCounterTest method buildParticipantCounterQuery_ExcludesWithoutIncludes.
@Test
public void buildParticipantCounterQuery_ExcludesWithoutIncludes() throws Exception {
String genderNamedParameter = "";
SearchParameter parameter1 = new SearchParameter().subtype("GEN").conceptId(8507L);
SearchGroupItem searchGroupItem1 = new SearchGroupItem().type("DEMO").addSearchParametersItem(parameter1);
SearchGroup searchGroup1 = new SearchGroup().addItemsItem(searchGroupItem1);
SearchRequest request = new SearchRequest().addExcludesItem(searchGroup1);
QueryJobConfiguration actualRequest = participantCounter.buildParticipantCounterQuery(new ParticipantCriteria(request));
for (String key : actualRequest.getNamedParameters().keySet()) {
if (key.startsWith("gen")) {
genderNamedParameter = key;
}
}
final String expectedSql = "select count(*) as count\n" + "from `${projectId}.${dataSetId}.person` person\n" + "where\n" + "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";
assertEquals(expectedSql, actualRequest.getQuery());
assertEquals("8507", actualRequest.getNamedParameters().get(genderNamedParameter).getArrayValues().get(0).getValue());
}
Aggregations