Search in sources :

Example 6 with CohortAnnotationDefinition

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

the class CohortAnnotationDefinitionDaoTest method findByCohortIdOrderByEnumValuesAsc.

@Test
public void findByCohortIdOrderByEnumValuesAsc() throws Exception {
    CohortAnnotationDefinition cohortAnnotationDefinition = createCohortAnnotationDefinition();
    cohortAnnotationDefinitionDao.save(cohortAnnotationDefinition);
    List<CohortAnnotationDefinition> expectedDBList = cohortAnnotationDefinitionDao.findByCohortId(cohortAnnotationDefinition.getCohortId());
    assertEquals(expectedDBList.get(0), cohortAnnotationDefinition);
}
Also used : CohortAnnotationDefinition(org.pmiops.workbench.db.model.CohortAnnotationDefinition) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 7 with CohortAnnotationDefinition

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

the class ParticipantCohortAnnotationDaoTest method setUp.

@Before
public void setUp() throws Exception {
    CohortAnnotationDefinition cohortAnnotationDefinition = new CohortAnnotationDefinition().cohortId(COHORT_ID).columnName("enum").annotationType(AnnotationType.ENUM);
    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);
    ParticipantCohortAnnotation pca = new ParticipantCohortAnnotation().cohortAnnotationDefinitionId(cohortAnnotationDefinitionId).cohortReviewId(cohortReviewId).participantId(participantId).annotationValueBoolean(Boolean.TRUE);
    ParticipantCohortAnnotation pca1 = new ParticipantCohortAnnotation().cohortAnnotationDefinitionId(cohortAnnotationDefinitionId1).cohortReviewId(cohortReviewId).participantId(participantId).annotationValueEnum("test");
    pca1.setCohortAnnotationEnumValue(enumValue1);
    annotationId = participantCohortAnnotationDao.save(pca).getAnnotationId();
    participantCohortAnnotationDao.save(pca1);
}
Also used : CohortAnnotationDefinition(org.pmiops.workbench.db.model.CohortAnnotationDefinition) ParticipantCohortAnnotation(org.pmiops.workbench.db.model.ParticipantCohortAnnotation) CohortAnnotationEnumValue(org.pmiops.workbench.db.model.CohortAnnotationEnumValue) Before(org.junit.Before)

Example 8 with CohortAnnotationDefinition

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

the class CohortReviewControllerTest method assertCreateParticipantCohortAnnotation.

private void assertCreateParticipantCohortAnnotation(ParticipantCohortAnnotation request, AnnotationType annotationType) throws Exception {
    ParticipantCohortStatusKey key = new ParticipantCohortStatusKey().cohortReviewId(cohortReviewId).participantId(participantId);
    ParticipantCohortStatus participantCohortStatus = new ParticipantCohortStatus().participantKey(key);
    CohortAnnotationDefinition cohortAnnotationDefinition = new CohortAnnotationDefinition().annotationType(annotationType);
    if (request.getAnnotationValueEnum() != null) {
        CohortAnnotationEnumValue cohortAnnotationEnumValue = new CohortAnnotationEnumValue().name(request.getAnnotationValueEnum());
        cohortAnnotationDefinition.setEnumValues(new TreeSet(Arrays.asList(cohortAnnotationEnumValue)));
    }
    when(cohortReviewService.findCohort(cohortId)).thenReturn(createCohort(cohortId, workspaceId, null));
    when(cohortReviewService.validateMatchingWorkspace(namespace, name, workspaceId, WorkspaceAccessLevel.WRITER)).thenReturn(new Workspace());
    when(cohortReviewService.findCohortReview(cohortId, cdrVersionId)).thenReturn(createCohortReview(0, cohortId, cohortReviewId, cdrVersionId, null));
    when(cohortReviewService.saveParticipantCohortAnnotation(isA(Long.class), isA(org.pmiops.workbench.db.model.ParticipantCohortAnnotation.class))).thenReturn(createParticipantCohortAnnotation(request));
    ParticipantCohortAnnotation response = reviewController.createParticipantCohortAnnotation(namespace, name, cohortId, cdrVersionId, participantId, request).getBody();
    assertEquals(request, response);
    verify(cohortReviewService, atLeastOnce()).findCohort(cohortId);
    verify(cohortReviewService, atLeastOnce()).validateMatchingWorkspace(namespace, name, workspaceId, WorkspaceAccessLevel.WRITER);
    verify(cohortReviewService, atLeastOnce()).findCohortReview(cohortId, cdrVersionId);
    verify(cohortReviewService, atLeastOnce()).saveParticipantCohortAnnotation(isA(Long.class), isA(org.pmiops.workbench.db.model.ParticipantCohortAnnotation.class));
    verifyNoMoreMockInteractions();
}
Also used : CohortAnnotationDefinition(org.pmiops.workbench.db.model.CohortAnnotationDefinition) ParticipantCohortStatus(org.pmiops.workbench.db.model.ParticipantCohortStatus) TreeSet(java.util.TreeSet) ParticipantCohortStatusKey(org.pmiops.workbench.db.model.ParticipantCohortStatusKey) CohortAnnotationEnumValue(org.pmiops.workbench.db.model.CohortAnnotationEnumValue) Workspace(org.pmiops.workbench.db.model.Workspace)

Example 9 with CohortAnnotationDefinition

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

the class CohortReviewServiceImplTest method assertSaveParticipantCohortAnnotation.

private void assertSaveParticipantCohortAnnotation(ParticipantCohortAnnotation participantCohortAnnotation, AnnotationType annotationType) {
    long cohortAnnotationDefinitionId = participantCohortAnnotation.getCohortAnnotationDefinitionId();
    long cohortReviewId = participantCohortAnnotation.getCohortReviewId();
    long participantId = participantCohortAnnotation.getParticipantId();
    CohortAnnotationDefinition cohortAnnotationDefinition = createCohortAnnotationDefinition(cohortAnnotationDefinitionId, annotationType);
    when(cohortAnnotationDefinitionDao.findOne(cohortAnnotationDefinitionId)).thenReturn(cohortAnnotationDefinition);
    when(participantCohortAnnotationDao.findByCohortReviewIdAndCohortAnnotationDefinitionIdAndParticipantId(cohortReviewId, cohortAnnotationDefinitionId, participantId)).thenReturn(null);
    when(participantCohortAnnotationDao.save(participantCohortAnnotation)).thenReturn(participantCohortAnnotation);
    cohortReviewService.saveParticipantCohortAnnotation(cohortReviewId, participantCohortAnnotation);
    verify(cohortAnnotationDefinitionDao, atLeastOnce()).findOne(cohortAnnotationDefinitionId);
    verify(participantCohortAnnotationDao, atLeastOnce()).findByCohortReviewIdAndCohortAnnotationDefinitionIdAndParticipantId(cohortReviewId, cohortAnnotationDefinitionId, participantId);
    verify(participantCohortAnnotationDao, atLeastOnce()).save(participantCohortAnnotation);
    verifyNoMoreMockInteractions();
}
Also used : CohortAnnotationDefinition(org.pmiops.workbench.db.model.CohortAnnotationDefinition)

Example 10 with CohortAnnotationDefinition

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

the class CohortAnnotationDefinitionDaoTest method findByCohortIdAndColumnName.

@Test
public void findByCohortIdAndColumnName() throws Exception {
    CohortAnnotationDefinition cohortAnnotationDefinition = createCohortAnnotationDefinition();
    cohortAnnotationDefinitionDao.save(cohortAnnotationDefinition);
    CohortAnnotationDefinition expectedAnnotationDefinition = cohortAnnotationDefinitionDao.findByCohortIdAndColumnName(cohortAnnotationDefinition.getCohortId(), cohortAnnotationDefinition.getColumnName());
    assertEquals(expectedAnnotationDefinition, cohortAnnotationDefinition);
}
Also used : CohortAnnotationDefinition(org.pmiops.workbench.db.model.CohortAnnotationDefinition) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

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