Search in sources :

Example 11 with ParticipantCohortAnnotation

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

the class ParticipantCohortAnnotationDaoTest method findByCohortReviewIdAndCohortAnnotationDefinitionIdAndParticipantId.

@Test
public void findByCohortReviewIdAndCohortAnnotationDefinitionIdAndParticipantId() throws Exception {
    ParticipantCohortAnnotation expectedPCA = new ParticipantCohortAnnotation().annotationId(annotationId).cohortAnnotationDefinitionId(cohortAnnotationDefinitionId).cohortReviewId(cohortReviewId).participantId(participantId).annotationValueBoolean(Boolean.TRUE);
    ParticipantCohortAnnotation actualPCA = participantCohortAnnotationDao.findByCohortReviewIdAndCohortAnnotationDefinitionIdAndParticipantId(cohortReviewId, cohortAnnotationDefinitionId, participantId);
    assertEquals(expectedPCA, actualPCA);
}
Also used : ParticipantCohortAnnotation(org.pmiops.workbench.db.model.ParticipantCohortAnnotation) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 12 with ParticipantCohortAnnotation

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

the class CohortReviewServiceImplTest method saveParticipantCohortAnnotationNotFoundCohortAnnotationDefinition.

@Test
public void saveParticipantCohortAnnotationNotFoundCohortAnnotationDefinition() throws Exception {
    long cohortAnnotationDefinitionId = 1;
    long cohortReviewId = 1;
    long participantId = 1;
    ParticipantCohortAnnotation participantCohortAnnotation = new ParticipantCohortAnnotation().annotationValueBoolean(Boolean.TRUE).cohortAnnotationDefinitionId(cohortAnnotationDefinitionId).cohortReviewId(cohortReviewId).participantId(participantId);
    when(cohortAnnotationDefinitionDao.findOne(cohortAnnotationDefinitionId)).thenReturn(null);
    try {
        cohortReviewService.saveParticipantCohortAnnotation(cohortReviewId, participantCohortAnnotation);
        fail("Should have thrown NotFoundExcpetion!");
    } catch (NotFoundException e) {
        assertEquals("Not Found: No cohort annotation definition found for id: " + cohortAnnotationDefinitionId, e.getMessage());
    }
    verify(cohortAnnotationDefinitionDao).findOne(cohortAnnotationDefinitionId);
    verifyNoMoreMockInteractions();
}
Also used : NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) ParticipantCohortAnnotation(org.pmiops.workbench.db.model.ParticipantCohortAnnotation) Test(org.junit.Test)

Example 13 with ParticipantCohortAnnotation

use of org.pmiops.workbench.db.model.ParticipantCohortAnnotation 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 ParticipantCohortAnnotation

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

the class CohortReviewServiceImplTest method saveParticipantCohortAnnotationBadRequest.

@Test
public void saveParticipantCohortAnnotationBadRequest() throws Exception {
    long cohortAnnotationDefinitionId = 1;
    long cohortReviewId = 1;
    long participantId = 1;
    ParticipantCohortAnnotation participantCohortAnnotation = new ParticipantCohortAnnotation().cohortAnnotationDefinitionId(cohortAnnotationDefinitionId).cohortReviewId(cohortReviewId).participantId(participantId);
    assertParticipantCohortAnnotationBadRequest(participantCohortAnnotation, createCohortAnnotationDefinition(cohortAnnotationDefinitionId, AnnotationType.BOOLEAN));
    assertParticipantCohortAnnotationBadRequest(participantCohortAnnotation, createCohortAnnotationDefinition(cohortAnnotationDefinitionId, AnnotationType.STRING));
    assertParticipantCohortAnnotationBadRequest(participantCohortAnnotation, createCohortAnnotationDefinition(cohortAnnotationDefinitionId, AnnotationType.INTEGER));
    assertParticipantCohortAnnotationBadRequest(participantCohortAnnotation, createCohortAnnotationDefinition(cohortAnnotationDefinitionId, AnnotationType.STRING));
    assertParticipantCohortAnnotationBadRequest(participantCohortAnnotation, createCohortAnnotationDefinition(cohortAnnotationDefinitionId, AnnotationType.ENUM));
}
Also used : ParticipantCohortAnnotation(org.pmiops.workbench.db.model.ParticipantCohortAnnotation) Test(org.junit.Test)

Example 15 with ParticipantCohortAnnotation

use of org.pmiops.workbench.db.model.ParticipantCohortAnnotation 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

ParticipantCohortAnnotation (org.pmiops.workbench.db.model.ParticipantCohortAnnotation)16 Test (org.junit.Test)12 CohortAnnotationDefinition (org.pmiops.workbench.db.model.CohortAnnotationDefinition)5 NotFoundException (org.pmiops.workbench.exceptions.NotFoundException)5 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)4 CohortAnnotationEnumValue (org.pmiops.workbench.db.model.CohortAnnotationEnumValue)3 ModifyParticipantCohortAnnotationRequest (org.pmiops.workbench.model.ModifyParticipantCohortAnnotationRequest)3 Date (java.sql.Date)2 SimpleDateFormat (java.text.SimpleDateFormat)2 BadRequestException (org.pmiops.workbench.exceptions.BadRequestException)2 ParseException (java.text.ParseException)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 Before (org.junit.Before)1 GenderRaceEthnicityConcept (org.pmiops.workbench.cdr.cache.GenderRaceEthnicityConcept)1 PageRequest (org.pmiops.workbench.cohortreview.util.PageRequest)1 CohortAnnotationDefinitionDao (org.pmiops.workbench.db.dao.CohortAnnotationDefinitionDao)1