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));
}
}
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));
}
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\"");
}
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.");
}
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));
}
Aggregations