use of org.pmiops.workbench.cdr.cache.GenderRaceEthnicityConcept 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();
}
use of org.pmiops.workbench.cdr.cache.GenderRaceEthnicityConcept 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();
}
Aggregations