use of org.pmiops.workbench.cohortreview.util.PageRequest in project workbench by all-of-us.
the class CohortReviewController method getParticipantProcedures.
@Override
public ResponseEntity<ParticipantProceduresListResponse> getParticipantProcedures(String workspaceNamespace, String workspaceId, Long cohortId, Long cdrVersionId, Long participantId, PageFilterRequest request) {
CohortReview review = validateRequestAndSetCdrVersion(workspaceNamespace, workspaceId, cohortId, cdrVersionId, WorkspaceAccessLevel.READER);
// this validates that the participant is in the requested review.
cohortReviewService.findParticipantCohortStatus(review.getCohortReviewId(), participantId);
PageRequest pageRequest = createPageRequest(request);
QueryResult result = bigQueryService.executeQuery(bigQueryService.filterBigQueryConfig(reviewTabQueryBuilder.buildQuery(ReviewTabQueries.PROCEDURE, participantId, pageRequest)));
Map<String, Integer> rm = bigQueryService.getResultMapper(result);
ParticipantProceduresListResponse response = new ParticipantProceduresListResponse();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
for (List<FieldValue> row : result.iterateAll()) {
ParticipantProcedure procedure = new ParticipantProcedure().itemDate(sdf.format(bigQueryService.getDate(row, rm.get("item_date")))).standardVocabulary(bigQueryService.getString(row, rm.get("standard_vocabulary"))).standardName(bigQueryService.getString(row, rm.get("standard_name"))).sourceValue(bigQueryService.getString(row, rm.get("source_value"))).sourceVocabulary(bigQueryService.getString(row, rm.get("source_vocabulary"))).sourceName(bigQueryService.getString(row, rm.get("source_name"))).age(bigQueryService.getLong(row, rm.get("age")).intValue());
response.addItemsItem(procedure);
}
result = bigQueryService.executeQuery(bigQueryService.filterBigQueryConfig(reviewTabQueryBuilder.buildCountQuery(ReviewTabQueries.PROCEDURE, participantId)));
rm = bigQueryService.getResultMapper(result);
List<FieldValue> row = result.iterateAll().iterator().next();
response.count(bigQueryService.getLong(row, rm.get("count")));
response.setPageRequest(new org.pmiops.workbench.model.PageRequest().page(pageRequest.getPageNumber()).pageSize(pageRequest.getPageSize()).sortOrder(pageRequest.getSortOrder()).sortColumn(pageRequest.getSortColumn()));
return ResponseEntity.ok(response);
}
use of org.pmiops.workbench.cohortreview.util.PageRequest in project workbench by all-of-us.
the class CohortReviewController method getParticipantConditions.
@Override
public ResponseEntity<ParticipantConditionsListResponse> getParticipantConditions(String workspaceNamespace, String workspaceId, Long cohortId, Long cdrVersionId, Long participantId, PageFilterRequest request) {
CohortReview review = validateRequestAndSetCdrVersion(workspaceNamespace, workspaceId, cohortId, cdrVersionId, WorkspaceAccessLevel.READER);
// this validates that the participant is in the requested review.
cohortReviewService.findParticipantCohortStatus(review.getCohortReviewId(), participantId);
PageRequest pageRequest = createPageRequest(request);
QueryResult result = bigQueryService.executeQuery(bigQueryService.filterBigQueryConfig(reviewTabQueryBuilder.buildQuery(ReviewTabQueries.CONDITION, participantId, pageRequest)));
Map<String, Integer> rm = bigQueryService.getResultMapper(result);
ParticipantConditionsListResponse response = new ParticipantConditionsListResponse();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
for (List<FieldValue> row : result.iterateAll()) {
ParticipantCondition condition = new ParticipantCondition().itemDate(sdf.format(bigQueryService.getDate(row, rm.get("item_date")))).standardVocabulary(bigQueryService.getString(row, rm.get("standard_vocabulary"))).standardName(bigQueryService.getString(row, rm.get("standard_name"))).sourceValue(bigQueryService.getString(row, rm.get("source_value"))).sourceVocabulary(bigQueryService.getString(row, rm.get("source_vocabulary"))).sourceName(bigQueryService.getString(row, rm.get("source_name")));
response.addItemsItem(condition);
}
result = bigQueryService.executeQuery(bigQueryService.filterBigQueryConfig(reviewTabQueryBuilder.buildCountQuery(ReviewTabQueries.CONDITION, participantId)));
rm = bigQueryService.getResultMapper(result);
List<FieldValue> row = result.iterateAll().iterator().next();
response.count(bigQueryService.getLong(row, rm.get("count")));
response.setPageRequest(new org.pmiops.workbench.model.PageRequest().page(pageRequest.getPageNumber()).pageSize(pageRequest.getPageSize()).sortOrder(pageRequest.getSortOrder()).sortColumn(pageRequest.getSortColumn()));
return ResponseEntity.ok(response);
}
use of org.pmiops.workbench.cohortreview.util.PageRequest in project workbench by all-of-us.
the class CohortReviewControllerTest method assertFindByCohortIdAndCdrVersionId.
private void assertFindByCohortIdAndCdrVersionId(String namespace, String name, long cohortId, long cdrVersionId, Integer page, Integer pageSize, SortOrder sortOrder, ParticipantCohortStatusColumns sortColumn) {
Integer pageParam = page == null ? 0 : page;
Integer pageSizeParam = pageSize == null ? 25 : pageSize;
sortColumn = (sortColumn == null || sortColumn.name().equals(sortColumn.PARTICIPANTID)) ? ParticipantCohortStatusColumns.PARTICIPANTID : sortColumn;
sortOrder = sortOrder == null ? SortOrder.ASC : sortOrder;
ParticipantCohortStatusKey key = new ParticipantCohortStatusKey().cohortReviewId(cohortId).participantId(participantId);
final Date dob = new Date(System.currentTimeMillis());
ParticipantCohortStatus dbParticipant = new ParticipantCohortStatus().participantKey(key).status(CohortStatus.INCLUDED).birthDate(dob).ethnicityConceptId(1L).genderConceptId(1L).raceConceptId(1L);
org.pmiops.workbench.model.ParticipantCohortStatus respParticipant = new org.pmiops.workbench.model.ParticipantCohortStatus().participantId(1L).status(CohortStatus.INCLUDED).birthDate(dob.getTime()).ethnicityConceptId(1L).genderConceptId(1L).raceConceptId(1L);
org.pmiops.workbench.model.CohortReview respCohortReview = new org.pmiops.workbench.model.CohortReview().cohortReviewId(1L).cohortId(cohortId).cdrVersionId(cdrVersionId).matchedParticipantCount(1000L).reviewedCount(0L).reviewSize(200L).page(pageParam).pageSize(pageSizeParam).sortOrder(sortOrder.toString()).sortColumn(sortColumn.toString()).participantCohortStatuses(Arrays.asList(respParticipant));
List<ParticipantCohortStatus> participants = new ArrayList<ParticipantCohortStatus>();
participants.add(dbParticipant);
CohortReview cohortReviewAfter = new CohortReview();
cohortReviewAfter.setCohortReviewId(1L);
cohortReviewAfter.setCohortId(cohortId);
cohortReviewAfter.setCdrVersionId(cdrVersionId);
cohortReviewAfter.setMatchedParticipantCount(1000);
cohortReviewAfter.setReviewSize(200);
cohortReviewAfter.setCreationTime(new Timestamp(System.currentTimeMillis()));
Cohort cohort = new Cohort();
cohort.setWorkspaceId(1);
Map<String, Map<Long, String>> concepts = new HashMap<>();
concepts.put(GenderRaceEthnicityType.RACE.name(), new HashMap<>());
concepts.put(GenderRaceEthnicityType.GENDER.name(), new HashMap<>());
concepts.put(GenderRaceEthnicityType.ETHNICITY.name(), new HashMap<>());
GenderRaceEthnicityConcept greConcept = new GenderRaceEthnicityConcept(concepts);
when(cohortReviewService.findCohortReview(cohortId, cdrVersionId)).thenReturn(cohortReviewAfter);
when(cohortReviewService.findAll(key.getCohortReviewId(), Collections.<Filter>emptyList(), new PageRequest(pageParam, pageSizeParam, sortOrder, sortColumn.toString()))).thenReturn(participants);
when(cohortReviewService.validateMatchingWorkspace(namespace, name, workspaceId, WorkspaceAccessLevel.READER)).thenReturn(new Workspace());
when(cohortReviewService.findCohort(cohortId)).thenReturn(cohort);
ParticipantCohortStatuses request = new ParticipantCohortStatuses();
request.page(page);
request.pageSize(pageSize);
request.sortOrder(sortOrder);
request.sortColumn(sortColumn);
request.pageFilterType(PageFilterType.PARTICIPANTCOHORTSTATUSES);
ResponseEntity<org.pmiops.workbench.model.CohortReview> response = reviewController.getParticipantCohortStatuses(namespace, name, cohortId, cdrVersionId, request);
org.pmiops.workbench.model.CohortReview actualCohortReview = response.getBody();
respCohortReview.setCreationTime(actualCohortReview.getCreationTime());
assertEquals(respCohortReview, response.getBody());
verify(cohortReviewService, atLeast(1)).validateMatchingWorkspace(namespace, name, workspaceId, WorkspaceAccessLevel.READER);
verify(cohortReviewService, atLeast(1)).findCohortReview(cohortId, cdrVersionId);
verify(cohortReviewService, times(1)).findAll(key.getCohortReviewId(), Collections.<Filter>emptyList(), new PageRequest(pageParam, pageSizeParam, sortOrder, sortColumn.toString()));
verify(cohortReviewService, atLeast(1)).findCohort(cohortId);
verifyNoMoreMockInteractions();
}
use of org.pmiops.workbench.cohortreview.util.PageRequest in project workbench by all-of-us.
the class ParticipantCohortStatusDaoTest method findAllSearchCriteriaIn.
@Test
public void findAllSearchCriteriaIn() throws Exception {
PageRequest pageRequest = new PageRequest(page, pageSize, SortOrder.ASC, ParticipantCohortStatusColumns.PARTICIPANTID.toString());
List<Filter> filters = new ArrayList<>();
filters.add(new Filter().property(ParticipantCohortStatusColumns.PARTICIPANTID).operator(Operator.IN).values(Arrays.asList("1", "2")));
filters.add(new Filter().property(ParticipantCohortStatusColumns.STATUS).operator(Operator.IN).values(Arrays.asList(CohortStatus.INCLUDED.toString(), CohortStatus.EXCLUDED.toString())));
filters.add(new Filter().property(ParticipantCohortStatusColumns.BIRTHDATE).operator(Operator.IN).values(Arrays.asList(new Date(System.currentTimeMillis()).toString())));
filters.add(new Filter().property(ParticipantCohortStatusColumns.GENDER).operator(Operator.IN).values(Arrays.asList("MALE", "FEMALE")));
filters.add(new Filter().property(ParticipantCohortStatusColumns.RACE).operator(Operator.IN).values(Arrays.asList("Asian", "White")));
filters.add(new Filter().property(ParticipantCohortStatusColumns.ETHNICITY).operator(Operator.IN).values(Arrays.asList("Not Hispanic", "Hispanic")));
List<ParticipantCohortStatus> results = participantCohortStatusDao.findAll(1L, filters, pageRequest);
assertEquals(2, results.size());
ParticipantCohortStatus expectedPCS1 = createExpectedPCSWithConceptValues(new ParticipantCohortStatusKey().cohortReviewId(COHORT_REVIEW_ID).participantId(1), CohortStatus.INCLUDED);
expectedPCS1.setBirthDate(results.get(0).getBirthDate());
ParticipantCohortStatus expectedPCS2 = createExpectedPCSWithConceptValues(new ParticipantCohortStatusKey().cohortReviewId(COHORT_REVIEW_ID).participantId(2), CohortStatus.EXCLUDED);
expectedPCS2.setBirthDate(results.get(0).getBirthDate());
assertEquals(expectedPCS1, results.get(0));
assertEquals(expectedPCS2, results.get(1));
}
use of org.pmiops.workbench.cohortreview.util.PageRequest in project workbench by all-of-us.
the class ParticipantCohortStatusDaoTest method findAllBadFilterTypes.
@Test
public void findAllBadFilterTypes() throws Exception {
PageRequest pageRequest = new PageRequest(page, pageSize, SortOrder.ASC, ParticipantCohortStatusColumns.PARTICIPANTID.toString());
List<Filter> filters = new ArrayList<>();
filters.add(new Filter().property(ParticipantCohortStatusColumns.PARTICIPANTID).operator(Operator.EQUAL).values(Arrays.asList("z")));
assertBadRequest(pageRequest, filters, "Problems parsing participantId: For input string: \"z\"");
filters.clear();
filters.add(new Filter().property(ParticipantCohortStatusColumns.STATUS).operator(Operator.EQUAL).values(Arrays.asList("z")));
assertBadRequest(pageRequest, filters, "Problems parsing status: No enum constant org.pmiops.workbench.model.CohortStatus.z");
filters.clear();
filters.add(new Filter().property(ParticipantCohortStatusColumns.BIRTHDATE).operator(Operator.EQUAL).values(Arrays.asList("z")));
assertBadRequest(pageRequest, filters, "Problems parsing birthDate: Unparseable date: \"z\"");
}
Aggregations