use of org.pmiops.workbench.model.SearchRequest 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);
}
use of org.pmiops.workbench.model.SearchRequest 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.SearchRequest 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.SearchRequest in project workbench by all-of-us.
the class CohortBuilderControllerTest method createSearchRequests.
private SearchRequest createSearchRequests(String type, List<SearchParameter> parameters) {
final SearchGroupItem searchGroupItem = new SearchGroupItem().type(type).searchParameters(parameters);
final SearchGroup searchGroup = new SearchGroup().addItemsItem(searchGroupItem);
List<SearchGroup> groups = new ArrayList<>();
groups.add(searchGroup);
return new SearchRequest().includes(groups);
}
use of org.pmiops.workbench.model.SearchRequest in project workbench by all-of-us.
the class ParticipantCounter method buildQuery.
public QueryJobConfiguration buildQuery(ParticipantCriteria participantCriteria, String sqlTemplate, String endSql, String mainTable, Map<String, QueryParameterValue> params) {
SearchRequest request = participantCriteria.getSearchRequest();
StringBuilder queryBuilder = new StringBuilder(sqlTemplate.replace("${mainTable}", mainTable));
if (request == null) {
queryBuilder.append(PERSON_ID_WHITELIST_TEMPLATE.replace("${mainTable}", mainTable));
params.put(PERSON_ID_WHITELIST_PARAM, QueryParameterValue.array(participantCriteria.getParticipantIdsToInclude().toArray(new Long[0]), Long.class));
} else {
domainLookupService.findCodesForEmptyDomains(request.getIncludes());
domainLookupService.findCodesForEmptyDomains(request.getExcludes());
if (request.getIncludes().isEmpty() && request.getExcludes().isEmpty()) {
throw new BadRequestException("Invalid SearchRequest: includes[] and excludes[] cannot both be empty");
}
// build query for included search groups
StringJoiner joiner = buildQuery(request.getIncludes(), mainTable, params, false);
// if includes is empty then don't add the excludes clause
if (joiner.toString().isEmpty()) {
joiner.merge(buildQuery(request.getExcludes(), mainTable, params, false));
} else {
joiner.merge(buildQuery(request.getExcludes(), mainTable, params, true));
}
Set<Long> participantIdsToExclude = participantCriteria.getParticipantIdsToExclude();
if (!participantIdsToExclude.isEmpty()) {
joiner.add(PERSON_ID_BLACKLIST_TEMPLATE.replace("${mainTable}", mainTable));
params.put(PERSON_ID_BLACKLIST_PARAM, QueryParameterValue.array(participantIdsToExclude.toArray(new Long[0]), Long.class));
}
queryBuilder.append(joiner.toString());
}
queryBuilder.append(endSql.replace("${mainTable}", mainTable));
return QueryJobConfiguration.newBuilder(queryBuilder.toString()).setNamedParameters(params).setUseLegacySql(false).build();
}
Aggregations