use of org.pmiops.workbench.model.MaterializeCohortResponse in project workbench by all-of-us.
the class CohortsController method materializeCohort.
@Override
public ResponseEntity<MaterializeCohortResponse> materializeCohort(String workspaceNamespace, String workspaceId, MaterializeCohortRequest request) {
// This also enforces registered auth domain.
workspaceService.enforceWorkspaceAccessLevel(workspaceNamespace, workspaceId, WorkspaceAccessLevel.READER);
Workspace workspace = workspaceService.getRequired(workspaceNamespace, workspaceId);
CdrVersion cdrVersion = workspace.getCdrVersion();
CdrVersionContext.setCdrVersion(cdrVersion);
if (request.getCdrVersionName() != null) {
cdrVersion = cdrVersionDao.findByName(request.getCdrVersionName());
if (cdrVersion == null) {
throw new NotFoundException(String.format("Couldn't find CDR version with name %s", request.getCdrVersionName()));
}
}
String cohortSpec;
CohortReview cohortReview = null;
if (request.getCohortName() != null) {
org.pmiops.workbench.db.model.Cohort cohort = cohortDao.findCohortByNameAndWorkspaceId(request.getCohortName(), workspace.getWorkspaceId());
if (cohort == null) {
throw new NotFoundException(String.format("Couldn't find cohort with name %s in workspace %s/%s", request.getCohortName(), workspaceNamespace, workspaceId));
}
cohortReview = cohortReviewDao.findCohortReviewByCohortIdAndCdrVersionId(cohort.getCohortId(), cdrVersion.getCdrVersionId());
cohortSpec = cohort.getCriteria();
} else if (request.getCohortSpec() != null) {
cohortSpec = request.getCohortSpec();
if (request.getStatusFilter() != null) {
throw new BadRequestException("statusFilter cannot be used with cohortSpec");
}
} else {
throw new BadRequestException("Must specify either cohortName or cohortSpec");
}
Integer pageSize = request.getPageSize();
if (pageSize == null || pageSize == 0) {
request.setPageSize(DEFAULT_PAGE_SIZE);
} else if (pageSize < 0) {
throw new BadRequestException(String.format("Invalid page size: %s; must be between 1 and %d", pageSize, MAX_PAGE_SIZE));
} else if (pageSize > MAX_PAGE_SIZE) {
request.setPageSize(MAX_PAGE_SIZE);
}
SearchRequest searchRequest;
try {
searchRequest = new Gson().fromJson(cohortSpec, SearchRequest.class);
} catch (JsonSyntaxException e) {
throw new BadRequestException("Invalid cohort spec");
}
MaterializeCohortResponse response = cohortMaterializationService.materializeCohort(cohortReview, searchRequest, request);
return ResponseEntity.ok(response);
}
use of org.pmiops.workbench.model.MaterializeCohortResponse in project workbench by all-of-us.
the class CohortMaterializationServiceTest method testMaterializeCohortPersonFieldSetPersonIdWithStringLessThanNullNonMatch.
@Test
public void testMaterializeCohortPersonFieldSetPersonIdWithStringLessThanNullNonMatch() {
TableQuery tableQuery = new TableQuery();
tableQuery.setTableName("person");
tableQuery.setColumns(ImmutableList.of("person_id"));
ColumnFilter filter = new ColumnFilter();
filter.setColumnName("ethnicity_source_value");
filter.setOperator(Operator.LESS_THAN);
filter.setValue("esv");
tableQuery.addFiltersItem(ImmutableList.of(filter));
FieldSet fieldSet = new FieldSet();
fieldSet.setTableQuery(tableQuery);
MaterializeCohortResponse response = cohortMaterializationService.materializeCohort(null, SearchRequests.allGenders(), makeRequest(fieldSet, 1000));
assertPersonIds(response);
assertThat(response.getNextPageToken()).isNull();
}
use of org.pmiops.workbench.model.MaterializeCohortResponse in project workbench by all-of-us.
the class CohortMaterializationServiceTest method testMaterializeCohortPersonFieldSetPersonIdWithNumberGreaterThanFilter.
@Test
public void testMaterializeCohortPersonFieldSetPersonIdWithNumberGreaterThanFilter() {
TableQuery tableQuery = new TableQuery();
tableQuery.setTableName("person");
tableQuery.setColumns(ImmutableList.of("person_id"));
ColumnFilter filter = new ColumnFilter();
filter.setColumnName("person_id");
filter.setOperator(Operator.GREATER_THAN);
filter.setValueNumber(new BigDecimal(2L));
tableQuery.addFiltersItem(ImmutableList.of(filter));
FieldSet fieldSet = new FieldSet();
fieldSet.setTableQuery(tableQuery);
MaterializeCohortResponse response = cohortMaterializationService.materializeCohort(null, SearchRequests.allGenders(), makeRequest(fieldSet, 1000));
assertPersonIds(response, 102246L);
assertThat(response.getNextPageToken()).isNull();
}
use of org.pmiops.workbench.model.MaterializeCohortResponse in project workbench by all-of-us.
the class CohortMaterializationServiceTest method testMaterializeCohortWithReviewNotExcludedFilter.
@Test
public void testMaterializeCohortWithReviewNotExcludedFilter() {
MaterializeCohortRequest request = makeRequest(2);
request.setStatusFilter(ImmutableList.of(CohortStatus.NOT_REVIEWED, CohortStatus.INCLUDED, CohortStatus.NEEDS_FURTHER_REVIEW));
MaterializeCohortResponse response = cohortMaterializationService.materializeCohort(cohortReview, SearchRequests.allGenders(), request);
// With a not excluded status filter, ID 2 is not returned.
assertPersonIds(response, 1L, 102246L);
assertThat(response.getNextPageToken()).isNull();
}
use of org.pmiops.workbench.model.MaterializeCohortResponse in project workbench by all-of-us.
the class CohortMaterializationServiceTest method testMaterializeCohortWithReviewJustExcludedFilter.
@Test
public void testMaterializeCohortWithReviewJustExcludedFilter() {
MaterializeCohortRequest request = makeRequest(2);
request.setStatusFilter(ImmutableList.of(CohortStatus.EXCLUDED));
MaterializeCohortResponse response = cohortMaterializationService.materializeCohort(cohortReview, SearchRequests.allGenders(), request);
assertPersonIds(response, 2L);
assertThat(response.getNextPageToken()).isNull();
}
Aggregations