use of org.pmiops.workbench.db.model.CohortReview in project workbench by all-of-us.
the class CohortReviewControllerTest method assertFindByCohortIdAndCdrVersionId.
private void assertFindByCohortIdAndCdrVersionId(String namespace, String name, long cohortId, long cdrVersionId, Integer page, Integer pageSize, SortOrder sortOrder, ParticipantCohortStatusColumns sortColumn) {
Integer pageParam = page == null ? 0 : page;
Integer pageSizeParam = pageSize == null ? 25 : pageSize;
sortColumn = (sortColumn == null || sortColumn.name().equals(sortColumn.PARTICIPANTID)) ? ParticipantCohortStatusColumns.PARTICIPANTID : sortColumn;
sortOrder = sortOrder == null ? SortOrder.ASC : sortOrder;
ParticipantCohortStatusKey key = new ParticipantCohortStatusKey().cohortReviewId(cohortId).participantId(participantId);
final Date dob = new Date(System.currentTimeMillis());
ParticipantCohortStatus dbParticipant = new ParticipantCohortStatus().participantKey(key).status(CohortStatus.INCLUDED).birthDate(dob).ethnicityConceptId(1L).genderConceptId(1L).raceConceptId(1L);
org.pmiops.workbench.model.ParticipantCohortStatus respParticipant = new org.pmiops.workbench.model.ParticipantCohortStatus().participantId(1L).status(CohortStatus.INCLUDED).birthDate(dob.getTime()).ethnicityConceptId(1L).genderConceptId(1L).raceConceptId(1L);
org.pmiops.workbench.model.CohortReview respCohortReview = new org.pmiops.workbench.model.CohortReview().cohortReviewId(1L).cohortId(cohortId).cdrVersionId(cdrVersionId).matchedParticipantCount(1000L).reviewedCount(0L).reviewSize(200L).page(pageParam).pageSize(pageSizeParam).sortOrder(sortOrder.toString()).sortColumn(sortColumn.toString()).participantCohortStatuses(Arrays.asList(respParticipant));
List<ParticipantCohortStatus> participants = new ArrayList<ParticipantCohortStatus>();
participants.add(dbParticipant);
CohortReview cohortReviewAfter = new CohortReview();
cohortReviewAfter.setCohortReviewId(1L);
cohortReviewAfter.setCohortId(cohortId);
cohortReviewAfter.setCdrVersionId(cdrVersionId);
cohortReviewAfter.setMatchedParticipantCount(1000);
cohortReviewAfter.setReviewSize(200);
cohortReviewAfter.setCreationTime(new Timestamp(System.currentTimeMillis()));
Cohort cohort = new Cohort();
cohort.setWorkspaceId(1);
Map<String, Map<Long, String>> concepts = new HashMap<>();
concepts.put(GenderRaceEthnicityType.RACE.name(), new HashMap<>());
concepts.put(GenderRaceEthnicityType.GENDER.name(), new HashMap<>());
concepts.put(GenderRaceEthnicityType.ETHNICITY.name(), new HashMap<>());
GenderRaceEthnicityConcept greConcept = new GenderRaceEthnicityConcept(concepts);
when(cohortReviewService.findCohortReview(cohortId, cdrVersionId)).thenReturn(cohortReviewAfter);
when(cohortReviewService.findAll(key.getCohortReviewId(), Collections.<Filter>emptyList(), new PageRequest(pageParam, pageSizeParam, sortOrder, sortColumn.toString()))).thenReturn(participants);
when(cohortReviewService.validateMatchingWorkspace(namespace, name, workspaceId, WorkspaceAccessLevel.READER)).thenReturn(new Workspace());
when(cohortReviewService.findCohort(cohortId)).thenReturn(cohort);
ParticipantCohortStatuses request = new ParticipantCohortStatuses();
request.page(page);
request.pageSize(pageSize);
request.sortOrder(sortOrder);
request.sortColumn(sortColumn);
request.pageFilterType(PageFilterType.PARTICIPANTCOHORTSTATUSES);
ResponseEntity<org.pmiops.workbench.model.CohortReview> response = reviewController.getParticipantCohortStatuses(namespace, name, cohortId, cdrVersionId, request);
org.pmiops.workbench.model.CohortReview actualCohortReview = response.getBody();
respCohortReview.setCreationTime(actualCohortReview.getCreationTime());
assertEquals(respCohortReview, response.getBody());
verify(cohortReviewService, atLeast(1)).validateMatchingWorkspace(namespace, name, workspaceId, WorkspaceAccessLevel.READER);
verify(cohortReviewService, atLeast(1)).findCohortReview(cohortId, cdrVersionId);
verify(cohortReviewService, times(1)).findAll(key.getCohortReviewId(), Collections.<Filter>emptyList(), new PageRequest(pageParam, pageSizeParam, sortOrder, sortColumn.toString()));
verify(cohortReviewService, atLeast(1)).findCohort(cohortId);
verifyNoMoreMockInteractions();
}
use of org.pmiops.workbench.db.model.CohortReview in project workbench by all-of-us.
the class CohortReviewDaoTest method update.
@Test
public void update() throws Exception {
CohortReview cohortReview = createCohortReview();
cohortReviewDao.save(cohortReview);
String sql = "select count(*) from cohort_review where cohort_review_id = ? and reviewed_count = ?";
Object[] sqlParams = { cohortReview.getCohortReviewId(), cohortReview.getReviewedCount() };
Integer expectedCount = new Integer("1");
assertEquals(expectedCount, jdbcTemplate.queryForObject(sql, sqlParams, Integer.class));
cohortReview = cohortReviewDao.findOne(cohortReview.getCohortReviewId());
cohortReview.setReviewedCount(3);
cohortReviewDao.saveAndFlush(cohortReview);
sql = "select count(*) from cohort_review where cohort_review_id = ? and reviewed_count = ?";
sqlParams = new Object[] { cohortReview.getCohortReviewId(), cohortReview.getReviewedCount() };
assertEquals(expectedCount, jdbcTemplate.queryForObject(sql, sqlParams, Integer.class));
}
use of org.pmiops.workbench.db.model.CohortReview in project workbench by all-of-us.
the class CohortService method saveAndCloneReviews.
@Transactional
public Cohort saveAndCloneReviews(Cohort from, Cohort to) {
Cohort saved = cohortDao.save(to);
for (CohortReview fromReview : from.getCohortReviews()) {
CohortReview cr = new CohortReview();
cr.setCohortId(saved.getCohortId());
cr.creationTime(saved.getCreationTime());
cr.setLastModifiedTime(saved.getLastModifiedTime());
cr.setCdrVersionId(fromReview.getCdrVersionId());
cr.setMatchedParticipantCount(fromReview.getMatchedParticipantCount());
cr.setReviewSize(fromReview.getReviewSize());
cr.setReviewedCount(fromReview.getReviewedCount());
cr.setReviewStatus(fromReview.getReviewStatus());
cr = cohortReviewDao.save(cr);
participantCohortStatusDao.bulkCopyByCohortReview(fromReview.getCohortReviewId(), cr.getCohortReviewId());
}
return saved;
}
use of org.pmiops.workbench.db.model.CohortReview in project workbench by all-of-us.
the class CohortsControllerTest method testMaterializeCohortNamedCohortWithReview.
@Test
public void testMaterializeCohortNamedCohortWithReview() throws Exception {
Cohort cohort = createDefaultCohort();
cohort = cohortsController.createCohort(workspace.getNamespace(), workspace.getId(), cohort).getBody();
CohortReview cohortReview = new CohortReview();
cohortReview.setCohortId(cohort.getId());
cohortReview.setCdrVersionId(cdrVersion.getCdrVersionId());
cohortReview.setReviewSize(2);
cohortReview.setReviewedCount(2);
cohortReviewDao.save(cohortReview);
MaterializeCohortRequest request = new MaterializeCohortRequest();
request.setCohortName(cohort.getName());
MaterializeCohortResponse response = new MaterializeCohortResponse();
when(cohortMaterializationService.materializeCohort(cohortReview, searchRequest, request)).thenReturn(response);
assertThat(cohortsController.materializeCohort(WORKSPACE_NAMESPACE, WORKSPACE_NAME, request).getBody()).isEqualTo(response);
}
use of org.pmiops.workbench.db.model.CohortReview in project workbench by all-of-us.
the class CohortReviewDaoTest method save.
@Test
public void save() throws Exception {
CohortReview cohortReview = createCohortReview();
cohortReviewDao.save(cohortReview);
String sql = "select count(*) from cohort_review where cohort_review_id = ?";
final Object[] sqlParams = { cohortReview.getCohortReviewId() };
final Integer expectedCount = new Integer("1");
assertEquals(expectedCount, jdbcTemplate.queryForObject(sql, sqlParams, Integer.class));
}
Aggregations