Search in sources :

Example 1 with ParticipantCohortStatusKey

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

the class CohortReviewControllerTest method setUp.

@Before
public void setUp() {
    LocalDate personBirthDate = LocalDate.of(1980, Month.FEBRUARY, 17);
    LocalDate procedureDate1 = LocalDate.of(2009, Month.DECEMBER, 2);
    LocalDate procedureDate2 = LocalDate.of(2009, Month.DECEMBER, 3);
    Period age1 = Period.between(personBirthDate, procedureDate1);
    Period age2 = Period.between(personBirthDate, procedureDate2);
    expectedCondition1 = new ParticipantCondition().itemDate("2008-07-22").standardVocabulary("SNOMED").standardName("SNOMED").sourceValue("0020").sourceVocabulary("ICD9CM").sourceName("Typhoid and paratyphoid fevers");
    expectedCondition2 = new ParticipantCondition().itemDate("2008-08-01").standardVocabulary("SNOMED").standardName("SNOMED").sourceValue("0021").sourceVocabulary("ICD9CM").sourceName("Typhoid and paratyphoid fevers");
    expectedProcedure1 = new ParticipantProcedure().itemDate("2009-12-02").standardVocabulary("ICD10CM").standardName("name").sourceValue("val").sourceVocabulary("ICD10CM").sourceName("name").age(age1.getYears());
    expectedProcedure2 = new ParticipantProcedure().itemDate("2009-12-03").standardVocabulary("CPT4").standardName("name").sourceValue("val").sourceVocabulary("CPT4").sourceName("name").age(age2.getYears());
    cdrVersion = new CdrVersion();
    cdrVersion.setBigqueryDataset(testWorkbenchConfig.bigquery.dataSetId);
    cdrVersion.setBigqueryProject(testWorkbenchConfig.bigquery.projectId);
    cdrVersionDao.save(cdrVersion);
    workspace = new Workspace();
    workspace.setCdrVersion(cdrVersion);
    workspace.setWorkspaceNamespace(NAMESPACE);
    workspace.setFirecloudName(NAME);
    workspaceDao.save(workspace);
    cohort = new Cohort();
    cohort.setWorkspaceId(workspace.getWorkspaceId());
    cohortDao.save(cohort);
    CohortReview review = new CohortReview().cdrVersionId(cdrVersion.getCdrVersionId()).cohortId(cohort.getCohortId());
    cohortReviewDao.save(review);
    ParticipantCohortStatusKey key = new ParticipantCohortStatusKey().participantId(PARTICIPANT_ID).cohortReviewId(review.getCohortReviewId());
    ParticipantCohortStatus participantCohortStatus = new ParticipantCohortStatus().participantKey(key);
    participantCohortStatusDao.save(participantCohortStatus);
}
Also used : CdrVersion(org.pmiops.workbench.db.model.CdrVersion) Cohort(org.pmiops.workbench.db.model.Cohort) ParticipantCohortStatus(org.pmiops.workbench.db.model.ParticipantCohortStatus) ParticipantCohortStatusKey(org.pmiops.workbench.db.model.ParticipantCohortStatusKey) CohortReview(org.pmiops.workbench.db.model.CohortReview) Workspace(org.pmiops.workbench.db.model.Workspace) Before(org.junit.Before)

Example 2 with ParticipantCohortStatusKey

use of org.pmiops.workbench.db.model.ParticipantCohortStatusKey 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 3 with ParticipantCohortStatusKey

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

the class ParticipantCohortStatusDaoTest method findAllRsaveParticipantCohortStatuses.

/**
 * Prefixed this test with a a zzz to ensure that it runs last using the {@link FixMethodOrder} annotation.
 * This method has to run last because the batching implementation has to call a commit. This commit causes
 * problems with other test cases results.
 *
 * @throws Exception
 */
@Test
public void findAllRsaveParticipantCohortStatuses() throws Exception {
    ParticipantCohortStatusKey key1 = new ParticipantCohortStatusKey().cohortReviewId(2).participantId(3);
    ParticipantCohortStatusKey key2 = new ParticipantCohortStatusKey().cohortReviewId(2).participantId(4);
    ParticipantCohortStatus pcs1 = new ParticipantCohortStatus().participantKey(key1).status(CohortStatus.INCLUDED).birthDate(new Date(System.currentTimeMillis())).ethnicityConceptId(1L).genderConceptId(1L).raceConceptId(1L);
    ParticipantCohortStatus pcs2 = new ParticipantCohortStatus().participantKey(key2).status(CohortStatus.EXCLUDED).birthDate(new Date(System.currentTimeMillis())).ethnicityConceptId(1L).genderConceptId(1L).raceConceptId(1L);
    participantCohortStatusDao.saveParticipantCohortStatusesCustom(Arrays.asList(pcs1, pcs2));
    String sql = "select count(*) from participant_cohort_status where cohort_review_id = ?";
    final Object[] sqlParams = { key1.getCohortReviewId() };
    final Integer expectedCount = new Integer("2");
    assertEquals(expectedCount, jdbcTemplate.queryForObject(sql, sqlParams, Integer.class));
}
Also used : ParticipantCohortStatus(org.pmiops.workbench.db.model.ParticipantCohortStatus) ParticipantCohortStatusKey(org.pmiops.workbench.db.model.ParticipantCohortStatusKey) Date(java.sql.Date) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 4 with ParticipantCohortStatusKey

use of org.pmiops.workbench.db.model.ParticipantCohortStatusKey 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));
}
Also used : PageRequest(org.pmiops.workbench.cohortreview.util.PageRequest) Filter(org.pmiops.workbench.model.Filter) ParticipantCohortStatus(org.pmiops.workbench.db.model.ParticipantCohortStatus) ArrayList(java.util.ArrayList) ParticipantCohortStatusKey(org.pmiops.workbench.db.model.ParticipantCohortStatusKey) Date(java.sql.Date) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 5 with ParticipantCohortStatusKey

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

the class ParticipantCohortStatusDaoTest method findByParticipantKeyCohortReviewIdAndParticipantKeyParticipantId.

@Test
public void findByParticipantKeyCohortReviewIdAndParticipantKeyParticipantId() throws Exception {
    ParticipantCohortStatus participant1 = createExpectedPCS(new ParticipantCohortStatusKey().cohortReviewId(COHORT_REVIEW_ID).participantId(1), CohortStatus.INCLUDED);
    ParticipantCohortStatus actualParticipant = participantCohortStatusDao.findByParticipantKey_CohortReviewIdAndParticipantKey_ParticipantId(COHORT_REVIEW_ID, participant1.getParticipantKey().getParticipantId());
    participant1.setBirthDate(actualParticipant.getBirthDate());
    assertEquals(participant1, actualParticipant);
}
Also used : ParticipantCohortStatus(org.pmiops.workbench.db.model.ParticipantCohortStatus) ParticipantCohortStatusKey(org.pmiops.workbench.db.model.ParticipantCohortStatusKey) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Aggregations

ParticipantCohortStatus (org.pmiops.workbench.db.model.ParticipantCohortStatus)14 ParticipantCohortStatusKey (org.pmiops.workbench.db.model.ParticipantCohortStatusKey)14 Test (org.junit.Test)8 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)8 PageRequest (org.pmiops.workbench.cohortreview.util.PageRequest)7 Date (java.sql.Date)6 Filter (org.pmiops.workbench.model.Filter)5 ArrayList (java.util.ArrayList)4 Workspace (org.pmiops.workbench.db.model.Workspace)3 Cohort (org.pmiops.workbench.db.model.Cohort)2 CohortReview (org.pmiops.workbench.db.model.CohortReview)2 BigQueryException (com.google.cloud.bigquery.BigQueryException)1 FieldValue (com.google.cloud.bigquery.FieldValue)1 Timestamp (java.sql.Timestamp)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 Before (org.junit.Before)1 GenderRaceEthnicityConcept (org.pmiops.workbench.cdr.cache.GenderRaceEthnicityConcept)1 CdrVersion (org.pmiops.workbench.db.model.CdrVersion)1