use of org.pmiops.workbench.cohortbuilder.ParticipantCriteria in project workbench by all-of-us.
the class CohortBuilderController method getChartInfo.
@Override
public ResponseEntity<ChartInfoListResponse> getChartInfo(Long cdrVersionId, SearchRequest request) {
CdrVersionContext.setCdrVersion(cdrVersionDao.findOne(cdrVersionId));
ChartInfoListResponse response = new ChartInfoListResponse();
QueryJobConfiguration qjc = bigQueryService.filterBigQueryConfig(participantCounter.buildChartInfoCounterQuery(new ParticipantCriteria(request)));
QueryResult result = bigQueryService.executeQuery(qjc);
Map<String, Integer> rm = bigQueryService.getResultMapper(result);
for (List<FieldValue> row : result.iterateAll()) {
response.addItemsItem(new ChartInfo().gender(bigQueryService.getString(row, rm.get("gender"))).race(bigQueryService.getString(row, rm.get("race"))).ageRange(bigQueryService.getString(row, rm.get("ageRange"))).count(bigQueryService.getLong(row, rm.get("count"))));
}
return ResponseEntity.ok(response);
}
use of org.pmiops.workbench.cohortbuilder.ParticipantCriteria in project workbench by all-of-us.
the class CohortBuilderController method countParticipants.
/**
* This method will return a count of unique subjects
* defined by the provided {@link SearchRequest}.
*/
@Override
public ResponseEntity<Long> countParticipants(Long cdrVersionId, SearchRequest request) {
CdrVersionContext.setCdrVersion(cdrVersionDao.findOne(cdrVersionId));
QueryJobConfiguration qjc = bigQueryService.filterBigQueryConfig(participantCounter.buildParticipantCounterQuery(new ParticipantCriteria(request)));
QueryResult result = bigQueryService.executeQuery(qjc);
Map<String, Integer> rm = bigQueryService.getResultMapper(result);
List<FieldValue> row = result.iterateAll().iterator().next();
return ResponseEntity.ok(bigQueryService.getLong(row, rm.get("count")));
}
use of org.pmiops.workbench.cohortbuilder.ParticipantCriteria in project workbench by all-of-us.
the class CohortReviewController method initializeCohortReview.
/**
* Helper method to create a new {@link CohortReview}.
*
* @param cdrVersionId
* @param cohort
*/
private CohortReview initializeCohortReview(Long cdrVersionId, Cohort cohort) {
SearchRequest request = new Gson().fromJson(getCohortDefinition(cohort), SearchRequest.class);
QueryResult result = bigQueryService.executeQuery(bigQueryService.filterBigQueryConfig(participantCounter.buildParticipantCounterQuery(new ParticipantCriteria(request))));
Map<String, Integer> rm = bigQueryService.getResultMapper(result);
List<FieldValue> row = result.iterateAll().iterator().next();
long cohortCount = bigQueryService.getLong(row, rm.get("count"));
return createNewCohortReview(cohort.getCohortId(), cdrVersionId, cohortCount);
}
use of org.pmiops.workbench.cohortbuilder.ParticipantCriteria in project workbench by all-of-us.
the class CohortReviewController method createCohortReview.
/**
* Create a cohort review per the specified workspaceId, cohortId, cdrVersionId and size. If participant cohort status
* data exists for a review or no cohort review exists for cohortReviewId then throw a
* {@link BadRequestException}.
*
* @param workspaceNamespace
* @param workspaceId
* @param cohortId
* @param cdrVersionId
* @param request
*/
@Override
public ResponseEntity<org.pmiops.workbench.model.CohortReview> createCohortReview(String workspaceNamespace, String workspaceId, Long cohortId, Long cdrVersionId, CreateReviewRequest request) {
if (request.getSize() <= 0 || request.getSize() > MAX_REVIEW_SIZE) {
throw new BadRequestException(String.format("Invalid Request: Cohort Review size must be between %s and %s", 0, MAX_REVIEW_SIZE));
}
Cohort cohort = cohortReviewService.findCohort(cohortId);
// this validates that the user is in the proper workspace
Workspace workspace = cohortReviewService.validateMatchingWorkspace(workspaceNamespace, workspaceId, cohort.getWorkspaceId(), WorkspaceAccessLevel.WRITER);
CdrVersionContext.setCdrVersion(workspace.getCdrVersion());
CohortReview cohortReview = null;
try {
cohortReview = cohortReviewService.findCohortReview(cohortId, cdrVersionId);
} catch (NotFoundException nfe) {
cohortReview = initializeCohortReview(cdrVersionId, cohort).reviewStatus(ReviewStatus.NONE).reviewSize(0L);
cohortReviewService.saveCohortReview(cohortReview);
}
if (cohortReview.getReviewSize() > 0) {
throw new BadRequestException(String.format("Invalid Request: Cohort Review already created for cohortId: %s, cdrVersionId: %s", cohortId, cdrVersionId));
}
SearchRequest searchRequest = new Gson().fromJson(getCohortDefinition(cohort), SearchRequest.class);
QueryResult result = bigQueryService.executeQuery(bigQueryService.filterBigQueryConfig(participantCounter.buildParticipantIdQuery(new ParticipantCriteria(searchRequest), request.getSize(), 0L)));
Map<String, Integer> rm = bigQueryService.getResultMapper(result);
List<ParticipantCohortStatus> participantCohortStatuses = createParticipantCohortStatusesList(cohortReview.getCohortReviewId(), result, rm);
cohortReview.reviewSize(participantCohortStatuses.size()).reviewStatus(ReviewStatus.CREATED);
// when saving ParticipantCohortStatuses to the database the long value of birthdate is mutated.
cohortReviewService.saveFullCohortReview(cohortReview, participantCohortStatuses);
ParticipantCohortStatuses filterRequest = new ParticipantCohortStatuses();
filterRequest.setPage(PAGE);
filterRequest.setPageSize(PAGE_SIZE);
filterRequest.setSortOrder(SortOrder.ASC);
filterRequest.setPageFilterType(PageFilterType.PARTICIPANTCOHORTSTATUSES);
filterRequest.setSortColumn(ParticipantCohortStatusColumns.PARTICIPANTID);
List<ParticipantCohortStatus> paginatedPCS = cohortReviewService.findAll(cohortReview.getCohortReviewId(), Collections.<Filter>emptyList(), createPageRequest(filterRequest));
lookupGenderRaceEthnicityValues(paginatedPCS);
org.pmiops.workbench.model.CohortReview responseReview = TO_CLIENT_COHORTREVIEW.apply(cohortReview, createPageRequest(filterRequest));
responseReview.setParticipantCohortStatuses(paginatedPCS.stream().map(TO_CLIENT_PARTICIPANT).collect(Collectors.toList()));
return ResponseEntity.ok(responseReview);
}
use of org.pmiops.workbench.cohortbuilder.ParticipantCriteria in project workbench by all-of-us.
the class CohortReviewControllerTest method createCohortReview.
@Test
public void createCohortReview() throws Exception {
String definition = "{\"includes\":[{\"items\":[{\"type\":\"DEMO\",\"searchParameters\":" + "[{\"value\":\"Age\",\"subtype\":\"AGE\",\"conceptId\":null,\"attribute\":" + "{\"operator\":\"between\",\"operands\":[18,66]}}],\"modifiers\":[]}]}],\"excludes\":[]}";
SearchRequest searchRequest = new Gson().fromJson(definition, SearchRequest.class);
QueryResult queryResult = mock(QueryResult.class);
Iterable testIterable = new Iterable() {
@Override
public Iterator iterator() {
List<FieldValue> list = new ArrayList<>();
list.add(null);
return list.iterator();
}
};
Map<String, Integer> rm = new HashMap<>();
rm.put("person_id", 0);
rm.put("birth_datetime", 1);
rm.put("gender_concept_id", 2);
rm.put("race_concept_id", 3);
rm.put("ethnicity_concept_id", 4);
when(workspaceService.enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.READER)).thenReturn(WorkspaceAccessLevel.OWNER);
when(cohortReviewService.findCohortReview(cohortId, cdrVersionId)).thenReturn(createCohortReview(0, cohortId, cohortReviewId, cdrVersionId, null));
when(cohortReviewService.findCohort(cohortId)).thenReturn(createCohort(cohortId, workspaceId, definition));
when(cohortReviewService.validateMatchingWorkspace(namespace, name, workspaceId, WorkspaceAccessLevel.WRITER)).thenReturn(createWorkspace(workspaceId, namespace, name));
when(participantCounter.buildParticipantIdQuery(new ParticipantCriteria(searchRequest), 200, 0L)).thenReturn(null);
when(bigQueryService.filterBigQueryConfig(null)).thenReturn(null);
when(bigQueryService.executeQuery(null)).thenReturn(queryResult);
when(bigQueryService.getResultMapper(queryResult)).thenReturn(rm);
when(queryResult.iterateAll()).thenReturn(testIterable);
when(bigQueryService.getLong(null, 0)).thenReturn(0L);
when(bigQueryService.getString(null, 1)).thenReturn("1");
when(bigQueryService.getLong(null, 2)).thenReturn(0L);
when(bigQueryService.getLong(null, 3)).thenReturn(0L);
when(bigQueryService.getLong(null, 4)).thenReturn(0L);
when(genderRaceEthnicityConceptProvider.get()).thenReturn(new GenderRaceEthnicityConcept(createGenderRaceEthnicityConcept()));
doNothing().when(cohortReviewService).saveFullCohortReview(createCohortReview(1, cohortId, cohortReviewId, cdrVersionId, ReviewStatus.CREATED), Arrays.asList(createParticipantCohortStatus(cohortReviewId, 0, CohortStatus.NOT_REVIEWED)));
when(cohortReviewService.findAll(isA(Long.class), isA(List.class), isA(PageRequest.class))).thenReturn(Arrays.asList(createParticipantCohortStatus(cohortReviewId, 0, CohortStatus.INCLUDED)));
reviewController.createCohortReview(namespace, name, cohortId, cdrVersionId, new CreateReviewRequest().size(200));
verify(cohortReviewService, times(1)).findCohortReview(cohortId, cdrVersionId);
verify(cohortReviewService, times(1)).findCohort(cohortId);
verify(cohortReviewService, times(1)).validateMatchingWorkspace(namespace, name, workspaceId, WorkspaceAccessLevel.WRITER);
verify(participantCounter, times(1)).buildParticipantIdQuery(new ParticipantCriteria(searchRequest), 200, 0L);
verify(bigQueryService, times(1)).filterBigQueryConfig(null);
verify(bigQueryService, times(1)).executeQuery(null);
verify(bigQueryService, times(1)).getResultMapper(queryResult);
verify(bigQueryService, times(1)).getLong(null, 0);
verify(bigQueryService, times(1)).getString(null, 1);
verify(bigQueryService, times(1)).getLong(null, 2);
verify(bigQueryService, times(1)).getLong(null, 3);
verify(bigQueryService, times(1)).getLong(null, 4);
verify(queryResult, times(1)).iterateAll();
verify(cohortReviewService, times(1)).saveFullCohortReview(isA(CohortReview.class), isA(List.class));
verify(genderRaceEthnicityConceptProvider, times(1)).get();
verify(cohortReviewService).findAll(isA(Long.class), isA(List.class), isA(PageRequest.class));
verifyNoMoreMockInteractions();
}
Aggregations