Search in sources :

Example 11 with ParticipantCohortStatusKey

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

the class ParticipantCohortStatusDaoTest method findAllParticipantIdSorting.

@Test
public void findAllParticipantIdSorting() throws Exception {
    PageRequest pageRequest = new PageRequest(page, 2, SortOrder.ASC, ParticipantCohortStatusColumns.PARTICIPANTID.toString());
    List<ParticipantCohortStatus> results = participantCohortStatusDao.findAll(1L, Collections.<Filter>emptyList(), 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(1).getBirthDate());
    assertEquals(expectedPCS1, results.get(0));
    assertEquals(expectedPCS2, results.get(1));
    pageRequest = new PageRequest(page, 2, SortOrder.DESC, ParticipantCohortStatusColumns.PARTICIPANTID.toString());
    results = participantCohortStatusDao.findAll(1L, Collections.<Filter>emptyList(), pageRequest);
    assertEquals(2, results.size());
    expectedPCS1 = createExpectedPCSWithConceptValues(new ParticipantCohortStatusKey().cohortReviewId(COHORT_REVIEW_ID).participantId(2), CohortStatus.EXCLUDED);
    expectedPCS1.setBirthDate(results.get(0).getBirthDate());
    expectedPCS2 = createExpectedPCSWithConceptValues(new ParticipantCohortStatusKey().cohortReviewId(COHORT_REVIEW_ID).participantId(1), CohortStatus.INCLUDED);
    expectedPCS2.setBirthDate(results.get(1).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) ParticipantCohortStatusKey(org.pmiops.workbench.db.model.ParticipantCohortStatusKey) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 12 with ParticipantCohortStatusKey

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

the class ParticipantCohortStatusDaoTest method findAllStatusSorting.

@Test
public void findAllStatusSorting() throws Exception {
    PageRequest pageRequest = new PageRequest(page, 2, SortOrder.ASC, ParticipantCohortStatusColumns.STATUS.toString());
    List<ParticipantCohortStatus> results = participantCohortStatusDao.findAll(1L, Collections.<Filter>emptyList(), pageRequest);
    assertEquals(2, results.size());
    ParticipantCohortStatus expectedPCS1 = createExpectedPCSWithConceptValues(new ParticipantCohortStatusKey().cohortReviewId(COHORT_REVIEW_ID).participantId(2), CohortStatus.EXCLUDED);
    expectedPCS1.setBirthDate(results.get(0).getBirthDate());
    ParticipantCohortStatus expectedPCS2 = createExpectedPCSWithConceptValues(new ParticipantCohortStatusKey().cohortReviewId(COHORT_REVIEW_ID).participantId(1), CohortStatus.INCLUDED);
    expectedPCS2.setBirthDate(results.get(1).getBirthDate());
    assertEquals(expectedPCS1, results.get(0));
    assertEquals(expectedPCS2, results.get(1));
    pageRequest = new PageRequest(page, 2, SortOrder.DESC, ParticipantCohortStatusColumns.STATUS.toString());
    results = participantCohortStatusDao.findAll(1L, Collections.<Filter>emptyList(), pageRequest);
    assertEquals(2, results.size());
    expectedPCS1 = createExpectedPCSWithConceptValues(new ParticipantCohortStatusKey().cohortReviewId(COHORT_REVIEW_ID).participantId(1), CohortStatus.INCLUDED);
    expectedPCS1.setBirthDate(results.get(0).getBirthDate());
    expectedPCS2 = createExpectedPCSWithConceptValues(new ParticipantCohortStatusKey().cohortReviewId(COHORT_REVIEW_ID).participantId(2), CohortStatus.EXCLUDED);
    expectedPCS2.setBirthDate(results.get(1).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) ParticipantCohortStatusKey(org.pmiops.workbench.db.model.ParticipantCohortStatusKey) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 13 with ParticipantCohortStatusKey

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

the class CohortReviewController method createParticipantCohortStatusesList.

/**
 * Helper method that builds a list of {@link ParticipantCohortStatus} from BigQuery results.
 *
 * @param cohortReviewId
 * @param result
 * @param rm
 * @return
 */
private List<ParticipantCohortStatus> createParticipantCohortStatusesList(Long cohortReviewId, QueryResult result, Map<String, Integer> rm) {
    List<ParticipantCohortStatus> participantCohortStatuses = new ArrayList<>();
    for (List<FieldValue> row : result.iterateAll()) {
        String birthDateTimeString = bigQueryService.getString(row, rm.get("birth_datetime"));
        if (birthDateTimeString == null) {
            throw new BigQueryException(500, "birth_datetime is null at position: " + rm.get("birth_datetime"));
        }
        java.util.Date birthDate = Date.from(Instant.ofEpochMilli(Double.valueOf(birthDateTimeString).longValue() * 1000));
        participantCohortStatuses.add(new ParticipantCohortStatus().participantKey(new ParticipantCohortStatusKey(cohortReviewId, bigQueryService.getLong(row, rm.get("person_id")))).status(CohortStatus.NOT_REVIEWED).birthDate(new java.sql.Date(birthDate.getTime())).genderConceptId(bigQueryService.getLong(row, rm.get("gender_concept_id"))).raceConceptId(bigQueryService.getLong(row, rm.get("race_concept_id"))).ethnicityConceptId(bigQueryService.getLong(row, rm.get("ethnicity_concept_id"))));
    }
    return participantCohortStatuses;
}
Also used : ParticipantCohortStatus(org.pmiops.workbench.db.model.ParticipantCohortStatus) ArrayList(java.util.ArrayList) ParticipantCohortStatusKey(org.pmiops.workbench.db.model.ParticipantCohortStatusKey) FieldValue(com.google.cloud.bigquery.FieldValue) BigQueryException(com.google.cloud.bigquery.BigQueryException) Date(java.sql.Date)

Example 14 with ParticipantCohortStatusKey

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

the class CohortMaterializationServiceTest method makeStatus.

private ParticipantCohortStatus makeStatus(long cohortReviewId, long participantId, CohortStatus status) {
    ParticipantCohortStatusKey key = new ParticipantCohortStatusKey();
    key.setCohortReviewId(cohortReviewId);
    key.setParticipantId(participantId);
    ParticipantCohortStatus result = new ParticipantCohortStatus();
    result.setStatus(status);
    result.setParticipantKey(key);
    return result;
}
Also used : ParticipantCohortStatus(org.pmiops.workbench.db.model.ParticipantCohortStatus) ParticipantCohortStatusKey(org.pmiops.workbench.db.model.ParticipantCohortStatusKey)

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