Search in sources :

Example 6 with Filter

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

the class ParticipantCohortStatusDaoTest method findAllSearchCriteriaEqual.

@Test
public void findAllSearchCriteriaEqual() 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.EQUAL).values(Arrays.asList("1")));
    filters.add(new Filter().property(ParticipantCohortStatusColumns.STATUS).operator(Operator.EQUAL).values(Arrays.asList(CohortStatus.INCLUDED.toString())));
    filters.add(new Filter().property(ParticipantCohortStatusColumns.BIRTHDATE).operator(Operator.EQUAL).values(Arrays.asList(new Date(System.currentTimeMillis()).toString())));
    filters.add(new Filter().property(ParticipantCohortStatusColumns.GENDER).operator(Operator.EQUAL).values(Arrays.asList("MALE")));
    filters.add(new Filter().property(ParticipantCohortStatusColumns.RACE).operator(Operator.EQUAL).values(Arrays.asList("Asian")));
    filters.add(new Filter().property(ParticipantCohortStatusColumns.ETHNICITY).operator(Operator.EQUAL).values(Arrays.asList("Not Hispanic")));
    List<ParticipantCohortStatus> results = participantCohortStatusDao.findAll(1L, filters, pageRequest);
    assertEquals(1, results.size());
    ParticipantCohortStatus expectedPCS = createExpectedPCSWithConceptValues(new ParticipantCohortStatusKey().cohortReviewId(COHORT_REVIEW_ID).participantId(1), CohortStatus.INCLUDED);
    expectedPCS.setBirthDate(results.get(0).getBirthDate());
    assertEquals(expectedPCS, results.get(0));
}
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 7 with Filter

use of org.pmiops.workbench.model.Filter 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 8 with Filter

use of org.pmiops.workbench.model.Filter 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 9 with Filter

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

the class ParticipantCohortStatusDaoImpl method buildFilteringSql.

private String buildFilteringSql(List<Filter> filtersList, MapSqlParameterSource parameters) {
    List<String> sqlParts = new ArrayList<>();
    sqlParts.add(WHERE_CLAUSE_TEMPLATE);
    for (Filter filter : filtersList) {
        String sql = ParticipantCohortStatusDbInfo.fromName(filter.getProperty()).getFunction().apply(filter, parameters);
        sqlParts.add(sql);
    }
    return (!sqlParts.isEmpty()) ? String.join(" and ", sqlParts) : "";
}
Also used : Filter(org.pmiops.workbench.model.Filter) ArrayList(java.util.ArrayList)

Aggregations

Filter (org.pmiops.workbench.model.Filter)9 PageRequest (org.pmiops.workbench.cohortreview.util.PageRequest)8 Test (org.junit.Test)7 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)7 ParticipantCohortStatus (org.pmiops.workbench.db.model.ParticipantCohortStatus)6 ArrayList (java.util.ArrayList)5 ParticipantCohortStatusKey (org.pmiops.workbench.db.model.ParticipantCohortStatusKey)5 Date (java.sql.Date)3 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 List (java.util.List)1 Logger (java.util.logging.Logger)1 Collectors (java.util.stream.Collectors)1 Provider (javax.inject.Provider)1 StringUtils (org.apache.commons.lang3.StringUtils)1 GenderRaceEthnicityConcept (org.pmiops.workbench.cdr.cache.GenderRaceEthnicityConcept)1 CohortAnnotationDefinitionDao (org.pmiops.workbench.db.dao.CohortAnnotationDefinitionDao)1 CohortDao (org.pmiops.workbench.db.dao.CohortDao)1 CohortReviewDao (org.pmiops.workbench.db.dao.CohortReviewDao)1 ParticipantCohortAnnotationDao (org.pmiops.workbench.db.dao.ParticipantCohortAnnotationDao)1