Search in sources :

Example 16 with ParticipantCohortStatus

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

the class ParticipantCohortStatusDaoTest method findAllStatusSorting.

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

Example 17 with ParticipantCohortStatus

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

the class CohortReviewServiceImplTest method findParticipantCohortStatus.

@Test
public void findParticipantCohortStatus() throws Exception {
    long cohortReviewId = 1;
    long participantId = 1;
    ParticipantCohortStatus pcs = new ParticipantCohortStatus();
    when(participantCohortStatusDao.findByParticipantKey_CohortReviewIdAndParticipantKey_ParticipantId(cohortReviewId, participantId)).thenReturn(pcs);
    ParticipantCohortStatus actualpcs = cohortReviewService.findParticipantCohortStatus(cohortReviewId, participantId);
    assertEquals(pcs, actualpcs);
    verify(participantCohortStatusDao).findByParticipantKey_CohortReviewIdAndParticipantKey_ParticipantId(cohortReviewId, participantId);
    verifyNoMoreMockInteractions();
}
Also used : ParticipantCohortStatus(org.pmiops.workbench.db.model.ParticipantCohortStatus) Test(org.junit.Test)

Example 18 with ParticipantCohortStatus

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

the class CohortReviewController method updateParticipantCohortStatus.

@Override
public ResponseEntity<org.pmiops.workbench.model.ParticipantCohortStatus> updateParticipantCohortStatus(String workspaceNamespace, String workspaceId, Long cohortId, Long cdrVersionId, Long participantId, ModifyCohortStatusRequest cohortStatusRequest) {
    CohortReview cohortReview = validateRequestAndSetCdrVersion(workspaceNamespace, workspaceId, cohortId, cdrVersionId, WorkspaceAccessLevel.WRITER);
    ParticipantCohortStatus participantCohortStatus = cohortReviewService.findParticipantCohortStatus(cohortReview.getCohortReviewId(), participantId);
    participantCohortStatus.setStatus(cohortStatusRequest.getStatus());
    cohortReviewService.saveParticipantCohortStatus(participantCohortStatus);
    lookupGenderRaceEthnicityValues(Arrays.asList(participantCohortStatus));
    cohortReview.lastModifiedTime(new Timestamp(System.currentTimeMillis()));
    cohortReview.incrementReviewedCount();
    cohortReviewService.saveCohortReview(cohortReview);
    return ResponseEntity.ok(TO_CLIENT_PARTICIPANT.apply(participantCohortStatus));
}
Also used : ParticipantCohortStatus(org.pmiops.workbench.db.model.ParticipantCohortStatus) CohortReview(org.pmiops.workbench.db.model.CohortReview) Timestamp(java.sql.Timestamp)

Example 19 with ParticipantCohortStatus

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

the class CohortReviewController method getParticipantCohortStatus.

@Override
public ResponseEntity<org.pmiops.workbench.model.ParticipantCohortStatus> getParticipantCohortStatus(String workspaceNamespace, String workspaceId, Long cohortId, Long cdrVersionId, Long participantId) {
    CohortReview review = validateRequestAndSetCdrVersion(workspaceNamespace, workspaceId, cohortId, cdrVersionId, WorkspaceAccessLevel.READER);
    ParticipantCohortStatus status = cohortReviewService.findParticipantCohortStatus(review.getCohortReviewId(), participantId);
    lookupGenderRaceEthnicityValues(Arrays.asList(status));
    return ResponseEntity.ok(TO_CLIENT_PARTICIPANT.apply(status));
}
Also used : ParticipantCohortStatus(org.pmiops.workbench.db.model.ParticipantCohortStatus) CohortReview(org.pmiops.workbench.db.model.CohortReview)

Example 20 with ParticipantCohortStatus

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

the class CohortReviewController method getParticipantCohortStatuses.

/**
 * Get all participants for the specified cohortId and cdrVersionId. This endpoint does pagination
 * based on page, pageSize, sortOrder and sortColumn.
 */
@Override
public ResponseEntity<org.pmiops.workbench.model.CohortReview> getParticipantCohortStatuses(String workspaceNamespace, String workspaceId, Long cohortId, Long cdrVersionId, PageFilterRequest request) {
    CohortReview cohortReview = null;
    Cohort cohort = cohortReviewService.findCohort(cohortId);
    Workspace workspace = cohortReviewService.validateMatchingWorkspace(workspaceNamespace, workspaceId, cohort.getWorkspaceId(), WorkspaceAccessLevel.READER);
    CdrVersionContext.setCdrVersion(workspace.getCdrVersion());
    try {
        cohortReview = cohortReviewService.findCohortReview(cohortId, cdrVersionId);
    } catch (NotFoundException nfe) {
        cohortReview = initializeCohortReview(cdrVersionId, cohort);
    }
    PageRequest pageRequest = createPageRequest(request);
    List<Filter> filters = request.getFilters() == null ? Collections.<Filter>emptyList() : request.getFilters().getItems();
    List<ParticipantCohortStatus> participantCohortStatuses = cohortReviewService.findAll(cohortReview.getCohortReviewId(), filters, pageRequest);
    org.pmiops.workbench.model.CohortReview responseReview = TO_CLIENT_COHORTREVIEW.apply(cohortReview, pageRequest);
    responseReview.setParticipantCohortStatuses(participantCohortStatuses.stream().map(TO_CLIENT_PARTICIPANT).collect(Collectors.toList()));
    return ResponseEntity.ok(responseReview);
}
Also used : PageRequest(org.pmiops.workbench.cohortreview.util.PageRequest) Cohort(org.pmiops.workbench.db.model.Cohort) ParticipantCohortStatus(org.pmiops.workbench.db.model.ParticipantCohortStatus) NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) org.pmiops.workbench.model(org.pmiops.workbench.model) CohortReview(org.pmiops.workbench.db.model.CohortReview) Workspace(org.pmiops.workbench.db.model.Workspace)

Aggregations

ParticipantCohortStatus (org.pmiops.workbench.db.model.ParticipantCohortStatus)23 ParticipantCohortStatusKey (org.pmiops.workbench.db.model.ParticipantCohortStatusKey)14 Test (org.junit.Test)12 PageRequest (org.pmiops.workbench.cohortreview.util.PageRequest)9 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)9 Date (java.sql.Date)6 CohortReview (org.pmiops.workbench.db.model.CohortReview)6 Workspace (org.pmiops.workbench.db.model.Workspace)6 Filter (org.pmiops.workbench.model.Filter)5 ArrayList (java.util.ArrayList)4 Cohort (org.pmiops.workbench.db.model.Cohort)4 org.pmiops.workbench.model (org.pmiops.workbench.model)3 Timestamp (java.sql.Timestamp)2 NotFoundException (org.pmiops.workbench.exceptions.NotFoundException)2 BigQueryException (com.google.cloud.bigquery.BigQueryException)1 FieldValue (com.google.cloud.bigquery.FieldValue)1 QueryResult (com.google.cloud.bigquery.QueryResult)1 Gson (com.google.gson.Gson)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1