use of org.pmiops.workbench.model.SearchRequest 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.SearchRequest in project workbench by all-of-us.
the class CohortBuilderControllerTest method countSubjectsICD9MeasurementChild.
@Test
public void countSubjectsICD9MeasurementChild() throws Exception {
SearchParameter icd9 = createSearchParameter(icd9MeasurementChild, "003.1");
SearchRequest searchRequest = createSearchRequests(icd9MeasurementChild.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 countSubjectsCPTMeasurement.
@Test
public void countSubjectsCPTMeasurement() throws Exception {
SearchParameter cpt = createSearchParameter(cptMeasurement, "0001Q");
SearchRequest searchRequest = createSearchRequests(cptMeasurement.getType(), Arrays.asList(cpt));
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 countSubjectsICD9ProcedureOccurrenceParent.
@Test
public void countSubjectsICD9ProcedureOccurrenceParent() throws Exception {
SearchParameter icd9 = createSearchParameter(icd9ProcedureParent, "002");
SearchRequest searchRequest = createSearchRequests(icd9ProcedureParent.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 countSubjectsICD10ConditionOccurrenceParent.
@Test
public void countSubjectsICD10ConditionOccurrenceParent() throws Exception {
SearchParameter icd10 = createSearchParameter(icd10ConditionParent, "A");
SearchRequest searchRequest = createSearchRequests(icd10ConditionParent.getType(), Arrays.asList(icd10));
assertParticipants(controller.countParticipants(cdrVersion.getCdrVersionId(), searchRequest), 1);
}
Aggregations