Search in sources :

Example 1 with GenderRaceEthnicityConcept

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();
}
Also used : HashMap(java.util.HashMap) GenderRaceEthnicityConcept(org.pmiops.workbench.cdr.cache.GenderRaceEthnicityConcept) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) QueryResult(com.google.cloud.bigquery.QueryResult) PageRequest(org.pmiops.workbench.cohortreview.util.PageRequest) ArrayList(java.util.ArrayList) List(java.util.List) FieldValue(com.google.cloud.bigquery.FieldValue) ParticipantCriteria(org.pmiops.workbench.cohortbuilder.ParticipantCriteria) CohortReview(org.pmiops.workbench.db.model.CohortReview) Test(org.junit.Test)

Example 2 with GenderRaceEthnicityConcept

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();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp) PageRequest(org.pmiops.workbench.cohortreview.util.PageRequest) ParticipantCohortStatus(org.pmiops.workbench.db.model.ParticipantCohortStatus) org.pmiops.workbench.model(org.pmiops.workbench.model) GenderRaceEthnicityConcept(org.pmiops.workbench.cdr.cache.GenderRaceEthnicityConcept) ParticipantCohortStatusKey(org.pmiops.workbench.db.model.ParticipantCohortStatusKey) Date(java.sql.Date) Cohort(org.pmiops.workbench.db.model.Cohort) CohortReview(org.pmiops.workbench.db.model.CohortReview) HashMap(java.util.HashMap) Map(java.util.Map) Workspace(org.pmiops.workbench.db.model.Workspace)

Aggregations

ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 GenderRaceEthnicityConcept (org.pmiops.workbench.cdr.cache.GenderRaceEthnicityConcept)2 PageRequest (org.pmiops.workbench.cohortreview.util.PageRequest)2 CohortReview (org.pmiops.workbench.db.model.CohortReview)2 FieldValue (com.google.cloud.bigquery.FieldValue)1 QueryResult (com.google.cloud.bigquery.QueryResult)1 Gson (com.google.gson.Gson)1 Date (java.sql.Date)1 Timestamp (java.sql.Timestamp)1 List (java.util.List)1 Map (java.util.Map)1 Test (org.junit.Test)1 ParticipantCriteria (org.pmiops.workbench.cohortbuilder.ParticipantCriteria)1 Cohort (org.pmiops.workbench.db.model.Cohort)1 ParticipantCohortStatus (org.pmiops.workbench.db.model.ParticipantCohortStatus)1 ParticipantCohortStatusKey (org.pmiops.workbench.db.model.ParticipantCohortStatusKey)1 Workspace (org.pmiops.workbench.db.model.Workspace)1 org.pmiops.workbench.model (org.pmiops.workbench.model)1