Search in sources :

Example 6 with CohortReview

use of org.pmiops.workbench.db.model.CohortReview 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)

Example 7 with CohortReview

use of org.pmiops.workbench.db.model.CohortReview in project workbench by all-of-us.

the class CohortReviewDaoTest method update.

@Test
public void update() throws Exception {
    CohortReview cohortReview = createCohortReview();
    cohortReviewDao.save(cohortReview);
    String sql = "select count(*) from cohort_review where cohort_review_id = ? and reviewed_count = ?";
    Object[] sqlParams = { cohortReview.getCohortReviewId(), cohortReview.getReviewedCount() };
    Integer expectedCount = new Integer("1");
    assertEquals(expectedCount, jdbcTemplate.queryForObject(sql, sqlParams, Integer.class));
    cohortReview = cohortReviewDao.findOne(cohortReview.getCohortReviewId());
    cohortReview.setReviewedCount(3);
    cohortReviewDao.saveAndFlush(cohortReview);
    sql = "select count(*) from cohort_review where cohort_review_id = ? and reviewed_count = ?";
    sqlParams = new Object[] { cohortReview.getCohortReviewId(), cohortReview.getReviewedCount() };
    assertEquals(expectedCount, jdbcTemplate.queryForObject(sql, sqlParams, Integer.class));
}
Also used : CohortReview(org.pmiops.workbench.db.model.CohortReview) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 8 with CohortReview

use of org.pmiops.workbench.db.model.CohortReview in project workbench by all-of-us.

the class CohortService method saveAndCloneReviews.

@Transactional
public Cohort saveAndCloneReviews(Cohort from, Cohort to) {
    Cohort saved = cohortDao.save(to);
    for (CohortReview fromReview : from.getCohortReviews()) {
        CohortReview cr = new CohortReview();
        cr.setCohortId(saved.getCohortId());
        cr.creationTime(saved.getCreationTime());
        cr.setLastModifiedTime(saved.getLastModifiedTime());
        cr.setCdrVersionId(fromReview.getCdrVersionId());
        cr.setMatchedParticipantCount(fromReview.getMatchedParticipantCount());
        cr.setReviewSize(fromReview.getReviewSize());
        cr.setReviewedCount(fromReview.getReviewedCount());
        cr.setReviewStatus(fromReview.getReviewStatus());
        cr = cohortReviewDao.save(cr);
        participantCohortStatusDao.bulkCopyByCohortReview(fromReview.getCohortReviewId(), cr.getCohortReviewId());
    }
    return saved;
}
Also used : Cohort(org.pmiops.workbench.db.model.Cohort) CohortReview(org.pmiops.workbench.db.model.CohortReview) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with CohortReview

use of org.pmiops.workbench.db.model.CohortReview in project workbench by all-of-us.

the class CohortsControllerTest method testMaterializeCohortNamedCohortWithReview.

@Test
public void testMaterializeCohortNamedCohortWithReview() throws Exception {
    Cohort cohort = createDefaultCohort();
    cohort = cohortsController.createCohort(workspace.getNamespace(), workspace.getId(), cohort).getBody();
    CohortReview cohortReview = new CohortReview();
    cohortReview.setCohortId(cohort.getId());
    cohortReview.setCdrVersionId(cdrVersion.getCdrVersionId());
    cohortReview.setReviewSize(2);
    cohortReview.setReviewedCount(2);
    cohortReviewDao.save(cohortReview);
    MaterializeCohortRequest request = new MaterializeCohortRequest();
    request.setCohortName(cohort.getName());
    MaterializeCohortResponse response = new MaterializeCohortResponse();
    when(cohortMaterializationService.materializeCohort(cohortReview, searchRequest, request)).thenReturn(response);
    assertThat(cohortsController.materializeCohort(WORKSPACE_NAMESPACE, WORKSPACE_NAME, request).getBody()).isEqualTo(response);
}
Also used : Cohort(org.pmiops.workbench.model.Cohort) MaterializeCohortRequest(org.pmiops.workbench.model.MaterializeCohortRequest) CohortReview(org.pmiops.workbench.db.model.CohortReview) MaterializeCohortResponse(org.pmiops.workbench.model.MaterializeCohortResponse) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 10 with CohortReview

use of org.pmiops.workbench.db.model.CohortReview in project workbench by all-of-us.

the class CohortReviewDaoTest method save.

@Test
public void save() throws Exception {
    CohortReview cohortReview = createCohortReview();
    cohortReviewDao.save(cohortReview);
    String sql = "select count(*) from cohort_review where cohort_review_id = ?";
    final Object[] sqlParams = { cohortReview.getCohortReviewId() };
    final Integer expectedCount = new Integer("1");
    assertEquals(expectedCount, jdbcTemplate.queryForObject(sql, sqlParams, Integer.class));
}
Also used : CohortReview(org.pmiops.workbench.db.model.CohortReview) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Aggregations

CohortReview (org.pmiops.workbench.db.model.CohortReview)23 org.pmiops.workbench.model (org.pmiops.workbench.model)7 Test (org.junit.Test)6 Cohort (org.pmiops.workbench.db.model.Cohort)6 ParticipantCohortStatus (org.pmiops.workbench.db.model.ParticipantCohortStatus)6 Workspace (org.pmiops.workbench.db.model.Workspace)6 Gson (com.google.gson.Gson)4 Timestamp (java.sql.Timestamp)4 PageRequest (org.pmiops.workbench.cohortreview.util.PageRequest)4 BadRequestException (org.pmiops.workbench.exceptions.BadRequestException)4 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)4 QueryResult (com.google.cloud.bigquery.QueryResult)3 CdrVersion (org.pmiops.workbench.db.model.CdrVersion)3 NotFoundException (org.pmiops.workbench.exceptions.NotFoundException)3 FieldValue (com.google.cloud.bigquery.FieldValue)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Before (org.junit.Before)2 ParticipantCohortStatusKey (org.pmiops.workbench.db.model.ParticipantCohortStatusKey)2 MaterializeCohortResponse (org.pmiops.workbench.model.MaterializeCohortResponse)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)1