Search in sources :

Example 1 with Filter

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

the class CohortReviewServiceImpl method validateParticipantCohortAnnotation.

/**
 * Helper method to validate that requested annotations are proper.
 *
 * @param participantCohortAnnotation
 */
private void validateParticipantCohortAnnotation(ParticipantCohortAnnotation participantCohortAnnotation, CohortAnnotationDefinition cohortAnnotationDefinition) {
    if (cohortAnnotationDefinition.getAnnotationType().equals(AnnotationType.BOOLEAN)) {
        if (participantCohortAnnotation.getAnnotationValueBoolean() == null) {
            throw createBadRequestException(AnnotationType.BOOLEAN.name(), participantCohortAnnotation.getCohortAnnotationDefinitionId());
        }
    } else if (cohortAnnotationDefinition.getAnnotationType().equals(AnnotationType.STRING)) {
        if (StringUtils.isBlank(participantCohortAnnotation.getAnnotationValueString())) {
            throw createBadRequestException(AnnotationType.STRING.name(), participantCohortAnnotation.getCohortAnnotationDefinitionId());
        }
    } else if (cohortAnnotationDefinition.getAnnotationType().equals(AnnotationType.DATE)) {
        if (StringUtils.isBlank(participantCohortAnnotation.getAnnotationValueDateString())) {
            throw createBadRequestException(AnnotationType.DATE.name(), participantCohortAnnotation.getCohortAnnotationDefinitionId());
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date date = new Date(sdf.parse(participantCohortAnnotation.getAnnotationValueDateString()).getTime());
            participantCohortAnnotation.setAnnotationValueDate(date);
        } catch (ParseException e) {
            throw new BadRequestException(String.format("Invalid Request: Please provide a valid %s value (%s) for annotation defintion id: %s", AnnotationType.DATE.name(), sdf.toPattern(), participantCohortAnnotation.getCohortAnnotationDefinitionId()));
        }
    } else if (cohortAnnotationDefinition.getAnnotationType().equals(AnnotationType.INTEGER)) {
        if (participantCohortAnnotation.getAnnotationValueInteger() == null) {
            throw createBadRequestException(AnnotationType.INTEGER.name(), participantCohortAnnotation.getCohortAnnotationDefinitionId());
        }
    } else if (cohortAnnotationDefinition.getAnnotationType().equals(AnnotationType.ENUM)) {
        if (StringUtils.isBlank(participantCohortAnnotation.getAnnotationValueEnum())) {
            throw createBadRequestException(AnnotationType.ENUM.name(), participantCohortAnnotation.getCohortAnnotationDefinitionId());
        }
        List<CohortAnnotationEnumValue> enumValues = cohortAnnotationDefinition.getEnumValues().stream().filter(enumValue -> participantCohortAnnotation.getAnnotationValueEnum().equals(enumValue.getName())).collect(Collectors.toList());
        if (enumValues.isEmpty()) {
            throw createBadRequestException(AnnotationType.ENUM.name(), participantCohortAnnotation.getCohortAnnotationDefinitionId());
        }
        participantCohortAnnotation.setCohortAnnotationEnumValue(enumValues.get(0));
    }
}
Also used : AnnotationType(org.pmiops.workbench.model.AnnotationType) CohortReview(org.pmiops.workbench.db.model.CohortReview) PageRequest(org.pmiops.workbench.cohortreview.util.PageRequest) Provider(javax.inject.Provider) ModifyParticipantCohortAnnotationRequest(org.pmiops.workbench.model.ModifyParticipantCohortAnnotationRequest) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleDateFormat(java.text.SimpleDateFormat) ParticipantCohortAnnotation(org.pmiops.workbench.db.model.ParticipantCohortAnnotation) StringUtils(org.apache.commons.lang3.StringUtils) CohortReviewDao(org.pmiops.workbench.db.dao.CohortReviewDao) CohortAnnotationDefinitionDao(org.pmiops.workbench.db.dao.CohortAnnotationDefinitionDao) GenderRaceEthnicityConcept(org.pmiops.workbench.cdr.cache.GenderRaceEthnicityConcept) ParticipantCohortAnnotationDao(org.pmiops.workbench.db.dao.ParticipantCohortAnnotationDao) Service(org.springframework.stereotype.Service) CohortAnnotationEnumValue(org.pmiops.workbench.db.model.CohortAnnotationEnumValue) Workspace(org.pmiops.workbench.db.model.Workspace) ParseException(java.text.ParseException) BadRequestException(org.pmiops.workbench.exceptions.BadRequestException) WorkspaceService(org.pmiops.workbench.db.dao.WorkspaceService) ParticipantCohortStatusDao(org.pmiops.workbench.db.dao.ParticipantCohortStatusDao) Cohort(org.pmiops.workbench.db.model.Cohort) CohortDao(org.pmiops.workbench.db.dao.CohortDao) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Date(java.sql.Date) Filter(org.pmiops.workbench.model.Filter) List(java.util.List) CohortAnnotationDefinition(org.pmiops.workbench.db.model.CohortAnnotationDefinition) NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) WorkspaceAccessLevel(org.pmiops.workbench.model.WorkspaceAccessLevel) ParticipantCohortStatus(org.pmiops.workbench.db.model.ParticipantCohortStatus) Transactional(org.springframework.transaction.annotation.Transactional) BadRequestException(org.pmiops.workbench.exceptions.BadRequestException) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.sql.Date) CohortAnnotationEnumValue(org.pmiops.workbench.db.model.CohortAnnotationEnumValue)

Example 2 with Filter

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

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

the class ParticipantCohortStatusDaoTest method findAllBadFilterTypes.

@Test
public void findAllBadFilterTypes() 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("z")));
    assertBadRequest(pageRequest, filters, "Problems parsing participantId: For input string: \"z\"");
    filters.clear();
    filters.add(new Filter().property(ParticipantCohortStatusColumns.STATUS).operator(Operator.EQUAL).values(Arrays.asList("z")));
    assertBadRequest(pageRequest, filters, "Problems parsing status: No enum constant org.pmiops.workbench.model.CohortStatus.z");
    filters.clear();
    filters.add(new Filter().property(ParticipantCohortStatusColumns.BIRTHDATE).operator(Operator.EQUAL).values(Arrays.asList("z")));
    assertBadRequest(pageRequest, filters, "Problems parsing birthDate: Unparseable date: \"z\"");
}
Also used : PageRequest(org.pmiops.workbench.cohortreview.util.PageRequest) Filter(org.pmiops.workbench.model.Filter) ArrayList(java.util.ArrayList) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 4 with Filter

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

the class ParticipantCohortStatusDaoTest method findAllBadFilterValuesSize.

@Test
public void findAllBadFilterValuesSize() 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", "2")));
    assertBadRequest(pageRequest, filters, "Invalid request: property: participantId using operartor: EQUAL must have a single value.");
    filters.clear();
    filters.add(new Filter().property(ParticipantCohortStatusColumns.STATUS).operator(Operator.EQUAL).values(new ArrayList<>()));
    assertBadRequest(pageRequest, filters, "Invalid request: property: status values: is empty.");
}
Also used : PageRequest(org.pmiops.workbench.cohortreview.util.PageRequest) Filter(org.pmiops.workbench.model.Filter) ArrayList(java.util.ArrayList) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 5 with Filter

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

the class ParticipantCohortStatusDaoTest method findAllPaging.

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

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