Search in sources :

Example 11 with CohortAnnotationDefinition

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

the class CohortAnnotationDefinitionDaoTest method save_NoEnumValues.

@Test
public void save_NoEnumValues() throws Exception {
    CohortAnnotationDefinition cohortAnnotationDefinition = createCohortAnnotationDefinition();
    cohortAnnotationDefinitionDao.save(cohortAnnotationDefinition);
    String sql = "select count(*) from cohort_annotation_definition where cohort_annotation_definition_id = ?";
    final Object[] sqlParams = { cohortAnnotationDefinition.getCohortAnnotationDefinitionId() };
    final Integer expectedCount = new Integer("1");
    assertEquals(expectedCount, jdbcTemplate.queryForObject(sql, sqlParams, Integer.class));
}
Also used : CohortAnnotationDefinition(org.pmiops.workbench.db.model.CohortAnnotationDefinition) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 12 with CohortAnnotationDefinition

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

the class CohortAnnotationDefinitionDaoTest method save_WithEnumValues.

@Test
public void save_WithEnumValues() throws Exception {
    CohortAnnotationDefinition cohortAnnotationDefinition = createCohortAnnotationDefinition();
    CohortAnnotationEnumValue enumValue1 = new CohortAnnotationEnumValue().name("z").order(0).cohortAnnotationDefinition(cohortAnnotationDefinition);
    CohortAnnotationEnumValue enumValue2 = new CohortAnnotationEnumValue().name("r").order(1).cohortAnnotationDefinition(cohortAnnotationDefinition);
    CohortAnnotationEnumValue enumValue3 = new CohortAnnotationEnumValue().name("a").order(2).cohortAnnotationDefinition(cohortAnnotationDefinition);
    cohortAnnotationDefinition.getEnumValues().add(enumValue1);
    cohortAnnotationDefinition.getEnumValues().add(enumValue2);
    cohortAnnotationDefinition.getEnumValues().add(enumValue3);
    cohortAnnotationDefinitionDao.save(cohortAnnotationDefinition);
    String sql = "select count(*) from cohort_annotation_definition where cohort_annotation_definition_id = ?";
    Object[] sqlParams = { cohortAnnotationDefinition.getCohortAnnotationDefinitionId() };
    Integer expectedCount = new Integer("1");
    assertEquals(expectedCount, jdbcTemplate.queryForObject(sql, sqlParams, Integer.class));
    sql = "select count(*) from cohort_annotation_enum_value where cohort_annotation_definition_id = ?";
    sqlParams = new Object[] { cohortAnnotationDefinition.getCohortAnnotationDefinitionId() };
    expectedCount = new Integer("3");
    assertEquals(expectedCount, jdbcTemplate.queryForObject(sql, sqlParams, Integer.class));
    List<CohortAnnotationDefinition> cad = cohortAnnotationDefinitionDao.findByCohortId(cohortAnnotationDefinition.getCohortId());
    assertEquals(cohortAnnotationDefinition, cad.get(0));
}
Also used : CohortAnnotationDefinition(org.pmiops.workbench.db.model.CohortAnnotationDefinition) CohortAnnotationEnumValue(org.pmiops.workbench.db.model.CohortAnnotationEnumValue) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 13 with CohortAnnotationDefinition

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

the class CohortReviewServiceImplTest method updateParticipantCohortAnnotationModify.

@Test
public void updateParticipantCohortAnnotationModify() throws Exception {
    long annotationId = 1;
    long cohortAnnotationDefinitionId = 1;
    long cohortReviewId = 1;
    long participantId = 1;
    ParticipantCohortAnnotation participantCohortAnnotation = new ParticipantCohortAnnotation().annotationValueBoolean(Boolean.TRUE).cohortAnnotationDefinitionId(cohortAnnotationDefinitionId).cohortReviewId(cohortReviewId).participantId(participantId);
    ModifyParticipantCohortAnnotationRequest modifyRequest = new ModifyParticipantCohortAnnotationRequest().annotationValueBoolean(Boolean.FALSE);
    CohortAnnotationDefinition cohortAnnotationDefinition = createCohortAnnotationDefinition(cohortAnnotationDefinitionId, AnnotationType.BOOLEAN);
    when(participantCohortAnnotationDao.findByAnnotationIdAndCohortReviewIdAndParticipantId(annotationId, cohortReviewId, participantId)).thenReturn(participantCohortAnnotation);
    when(cohortAnnotationDefinitionDao.findOne(cohortAnnotationDefinitionId)).thenReturn(cohortAnnotationDefinition);
    cohortReviewService.updateParticipantCohortAnnotation(annotationId, cohortReviewId, participantId, modifyRequest);
    verify(participantCohortAnnotationDao).findByAnnotationIdAndCohortReviewIdAndParticipantId(annotationId, cohortReviewId, participantId);
    verify(cohortAnnotationDefinitionDao).findOne(cohortAnnotationDefinitionId);
    verifyNoMoreMockInteractions();
}
Also used : CohortAnnotationDefinition(org.pmiops.workbench.db.model.CohortAnnotationDefinition) ParticipantCohortAnnotation(org.pmiops.workbench.db.model.ParticipantCohortAnnotation) ModifyParticipantCohortAnnotationRequest(org.pmiops.workbench.model.ModifyParticipantCohortAnnotationRequest) Test(org.junit.Test)

Example 14 with CohortAnnotationDefinition

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

the class CohortReviewServiceImpl method updateParticipantCohortAnnotation.

@Override
public ParticipantCohortAnnotation updateParticipantCohortAnnotation(Long annotationId, Long cohortReviewId, Long participantId, ModifyParticipantCohortAnnotationRequest modifyRequest) {
    ParticipantCohortAnnotation participantCohortAnnotation = participantCohortAnnotationDao.findByAnnotationIdAndCohortReviewIdAndParticipantId(annotationId, cohortReviewId, participantId);
    if (participantCohortAnnotation == null) {
        throw new NotFoundException(String.format("Not Found: Participant Cohort Annotation does not exist for annotationId: %s, cohortReviewId: %s, participantId: %s", annotationId, cohortReviewId, participantId));
    }
    participantCohortAnnotation.annotationValueString(modifyRequest.getAnnotationValueString()).annotationValueEnum(modifyRequest.getAnnotationValueEnum()).annotationValueDateString(modifyRequest.getAnnotationValueDate()).annotationValueBoolean(modifyRequest.getAnnotationValueBoolean()).annotationValueInteger(modifyRequest.getAnnotationValueInteger());
    CohortAnnotationDefinition cohortAnnotationDefinition = findCohortAnnotationDefinition(participantCohortAnnotation.getCohortAnnotationDefinitionId());
    validateParticipantCohortAnnotation(participantCohortAnnotation, cohortAnnotationDefinition);
    return participantCohortAnnotationDao.save(participantCohortAnnotation);
}
Also used : CohortAnnotationDefinition(org.pmiops.workbench.db.model.CohortAnnotationDefinition) NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) ParticipantCohortAnnotation(org.pmiops.workbench.db.model.ParticipantCohortAnnotation)

Aggregations

CohortAnnotationDefinition (org.pmiops.workbench.db.model.CohortAnnotationDefinition)14 Test (org.junit.Test)7 ParticipantCohortAnnotation (org.pmiops.workbench.db.model.ParticipantCohortAnnotation)5 CohortAnnotationEnumValue (org.pmiops.workbench.db.model.CohortAnnotationEnumValue)4 BadRequestException (org.pmiops.workbench.exceptions.BadRequestException)4 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)4 ModifyParticipantCohortAnnotationRequest (org.pmiops.workbench.model.ModifyParticipantCohortAnnotationRequest)3 ParticipantCohortStatus (org.pmiops.workbench.db.model.ParticipantCohortStatus)2 Workspace (org.pmiops.workbench.db.model.Workspace)2 NotFoundException (org.pmiops.workbench.exceptions.NotFoundException)2 Date (java.sql.Date)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 List (java.util.List)1 TreeSet (java.util.TreeSet)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 Before (org.junit.Before)1