use of org.pmiops.workbench.db.model.CohortReview in project workbench by all-of-us.
the class CohortReviewController method getParticipantProcedures.
@Override
public ResponseEntity<ParticipantProceduresListResponse> getParticipantProcedures(String workspaceNamespace, String workspaceId, Long cohortId, Long cdrVersionId, Long participantId, PageFilterRequest request) {
CohortReview review = validateRequestAndSetCdrVersion(workspaceNamespace, workspaceId, cohortId, cdrVersionId, WorkspaceAccessLevel.READER);
// this validates that the participant is in the requested review.
cohortReviewService.findParticipantCohortStatus(review.getCohortReviewId(), participantId);
PageRequest pageRequest = createPageRequest(request);
QueryResult result = bigQueryService.executeQuery(bigQueryService.filterBigQueryConfig(reviewTabQueryBuilder.buildQuery(ReviewTabQueries.PROCEDURE, participantId, pageRequest)));
Map<String, Integer> rm = bigQueryService.getResultMapper(result);
ParticipantProceduresListResponse response = new ParticipantProceduresListResponse();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
for (List<FieldValue> row : result.iterateAll()) {
ParticipantProcedure procedure = new ParticipantProcedure().itemDate(sdf.format(bigQueryService.getDate(row, rm.get("item_date")))).standardVocabulary(bigQueryService.getString(row, rm.get("standard_vocabulary"))).standardName(bigQueryService.getString(row, rm.get("standard_name"))).sourceValue(bigQueryService.getString(row, rm.get("source_value"))).sourceVocabulary(bigQueryService.getString(row, rm.get("source_vocabulary"))).sourceName(bigQueryService.getString(row, rm.get("source_name"))).age(bigQueryService.getLong(row, rm.get("age")).intValue());
response.addItemsItem(procedure);
}
result = bigQueryService.executeQuery(bigQueryService.filterBigQueryConfig(reviewTabQueryBuilder.buildCountQuery(ReviewTabQueries.PROCEDURE, participantId)));
rm = bigQueryService.getResultMapper(result);
List<FieldValue> row = result.iterateAll().iterator().next();
response.count(bigQueryService.getLong(row, rm.get("count")));
response.setPageRequest(new org.pmiops.workbench.model.PageRequest().page(pageRequest.getPageNumber()).pageSize(pageRequest.getPageSize()).sortOrder(pageRequest.getSortOrder()).sortColumn(pageRequest.getSortColumn()));
return ResponseEntity.ok(response);
}
use of org.pmiops.workbench.db.model.CohortReview in project workbench by all-of-us.
the class CohortReviewController method getParticipantConditions.
@Override
public ResponseEntity<ParticipantConditionsListResponse> getParticipantConditions(String workspaceNamespace, String workspaceId, Long cohortId, Long cdrVersionId, Long participantId, PageFilterRequest request) {
CohortReview review = validateRequestAndSetCdrVersion(workspaceNamespace, workspaceId, cohortId, cdrVersionId, WorkspaceAccessLevel.READER);
// this validates that the participant is in the requested review.
cohortReviewService.findParticipantCohortStatus(review.getCohortReviewId(), participantId);
PageRequest pageRequest = createPageRequest(request);
QueryResult result = bigQueryService.executeQuery(bigQueryService.filterBigQueryConfig(reviewTabQueryBuilder.buildQuery(ReviewTabQueries.CONDITION, participantId, pageRequest)));
Map<String, Integer> rm = bigQueryService.getResultMapper(result);
ParticipantConditionsListResponse response = new ParticipantConditionsListResponse();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
for (List<FieldValue> row : result.iterateAll()) {
ParticipantCondition condition = new ParticipantCondition().itemDate(sdf.format(bigQueryService.getDate(row, rm.get("item_date")))).standardVocabulary(bigQueryService.getString(row, rm.get("standard_vocabulary"))).standardName(bigQueryService.getString(row, rm.get("standard_name"))).sourceValue(bigQueryService.getString(row, rm.get("source_value"))).sourceVocabulary(bigQueryService.getString(row, rm.get("source_vocabulary"))).sourceName(bigQueryService.getString(row, rm.get("source_name")));
response.addItemsItem(condition);
}
result = bigQueryService.executeQuery(bigQueryService.filterBigQueryConfig(reviewTabQueryBuilder.buildCountQuery(ReviewTabQueries.CONDITION, participantId)));
rm = bigQueryService.getResultMapper(result);
List<FieldValue> row = result.iterateAll().iterator().next();
response.count(bigQueryService.getLong(row, rm.get("count")));
response.setPageRequest(new org.pmiops.workbench.model.PageRequest().page(pageRequest.getPageNumber()).pageSize(pageRequest.getPageSize()).sortOrder(pageRequest.getSortOrder()).sortColumn(pageRequest.getSortColumn()));
return ResponseEntity.ok(response);
}
use of org.pmiops.workbench.db.model.CohortReview in project workbench by all-of-us.
the class CohortReviewController method createCohortReview.
/**
* Create a cohort review per the specified workspaceId, cohortId, cdrVersionId and size. If participant cohort status
* data exists for a review or no cohort review exists for cohortReviewId then throw a
* {@link BadRequestException}.
*
* @param workspaceNamespace
* @param workspaceId
* @param cohortId
* @param cdrVersionId
* @param request
*/
@Override
public ResponseEntity<org.pmiops.workbench.model.CohortReview> createCohortReview(String workspaceNamespace, String workspaceId, Long cohortId, Long cdrVersionId, CreateReviewRequest request) {
if (request.getSize() <= 0 || request.getSize() > MAX_REVIEW_SIZE) {
throw new BadRequestException(String.format("Invalid Request: Cohort Review size must be between %s and %s", 0, MAX_REVIEW_SIZE));
}
Cohort cohort = cohortReviewService.findCohort(cohortId);
// this validates that the user is in the proper workspace
Workspace workspace = cohortReviewService.validateMatchingWorkspace(workspaceNamespace, workspaceId, cohort.getWorkspaceId(), WorkspaceAccessLevel.WRITER);
CdrVersionContext.setCdrVersion(workspace.getCdrVersion());
CohortReview cohortReview = null;
try {
cohortReview = cohortReviewService.findCohortReview(cohortId, cdrVersionId);
} catch (NotFoundException nfe) {
cohortReview = initializeCohortReview(cdrVersionId, cohort).reviewStatus(ReviewStatus.NONE).reviewSize(0L);
cohortReviewService.saveCohortReview(cohortReview);
}
if (cohortReview.getReviewSize() > 0) {
throw new BadRequestException(String.format("Invalid Request: Cohort Review already created for cohortId: %s, cdrVersionId: %s", cohortId, cdrVersionId));
}
SearchRequest searchRequest = new Gson().fromJson(getCohortDefinition(cohort), SearchRequest.class);
QueryResult result = bigQueryService.executeQuery(bigQueryService.filterBigQueryConfig(participantCounter.buildParticipantIdQuery(new ParticipantCriteria(searchRequest), request.getSize(), 0L)));
Map<String, Integer> rm = bigQueryService.getResultMapper(result);
List<ParticipantCohortStatus> participantCohortStatuses = createParticipantCohortStatusesList(cohortReview.getCohortReviewId(), result, rm);
cohortReview.reviewSize(participantCohortStatuses.size()).reviewStatus(ReviewStatus.CREATED);
// when saving ParticipantCohortStatuses to the database the long value of birthdate is mutated.
cohortReviewService.saveFullCohortReview(cohortReview, participantCohortStatuses);
ParticipantCohortStatuses filterRequest = new ParticipantCohortStatuses();
filterRequest.setPage(PAGE);
filterRequest.setPageSize(PAGE_SIZE);
filterRequest.setSortOrder(SortOrder.ASC);
filterRequest.setPageFilterType(PageFilterType.PARTICIPANTCOHORTSTATUSES);
filterRequest.setSortColumn(ParticipantCohortStatusColumns.PARTICIPANTID);
List<ParticipantCohortStatus> paginatedPCS = cohortReviewService.findAll(cohortReview.getCohortReviewId(), Collections.<Filter>emptyList(), createPageRequest(filterRequest));
lookupGenderRaceEthnicityValues(paginatedPCS);
org.pmiops.workbench.model.CohortReview responseReview = TO_CLIENT_COHORTREVIEW.apply(cohortReview, createPageRequest(filterRequest));
responseReview.setParticipantCohortStatuses(paginatedPCS.stream().map(TO_CLIENT_PARTICIPANT).collect(Collectors.toList()));
return ResponseEntity.ok(responseReview);
}
use of org.pmiops.workbench.db.model.CohortReview in project workbench by all-of-us.
the class CohortsController method materializeCohort.
@Override
public ResponseEntity<MaterializeCohortResponse> materializeCohort(String workspaceNamespace, String workspaceId, MaterializeCohortRequest request) {
// This also enforces registered auth domain.
workspaceService.enforceWorkspaceAccessLevel(workspaceNamespace, workspaceId, WorkspaceAccessLevel.READER);
Workspace workspace = workspaceService.getRequired(workspaceNamespace, workspaceId);
CdrVersion cdrVersion = workspace.getCdrVersion();
CdrVersionContext.setCdrVersion(cdrVersion);
if (request.getCdrVersionName() != null) {
cdrVersion = cdrVersionDao.findByName(request.getCdrVersionName());
if (cdrVersion == null) {
throw new NotFoundException(String.format("Couldn't find CDR version with name %s", request.getCdrVersionName()));
}
}
String cohortSpec;
CohortReview cohortReview = null;
if (request.getCohortName() != null) {
org.pmiops.workbench.db.model.Cohort cohort = cohortDao.findCohortByNameAndWorkspaceId(request.getCohortName(), workspace.getWorkspaceId());
if (cohort == null) {
throw new NotFoundException(String.format("Couldn't find cohort with name %s in workspace %s/%s", request.getCohortName(), workspaceNamespace, workspaceId));
}
cohortReview = cohortReviewDao.findCohortReviewByCohortIdAndCdrVersionId(cohort.getCohortId(), cdrVersion.getCdrVersionId());
cohortSpec = cohort.getCriteria();
} else if (request.getCohortSpec() != null) {
cohortSpec = request.getCohortSpec();
if (request.getStatusFilter() != null) {
throw new BadRequestException("statusFilter cannot be used with cohortSpec");
}
} else {
throw new BadRequestException("Must specify either cohortName or cohortSpec");
}
Integer pageSize = request.getPageSize();
if (pageSize == null || pageSize == 0) {
request.setPageSize(DEFAULT_PAGE_SIZE);
} else if (pageSize < 0) {
throw new BadRequestException(String.format("Invalid page size: %s; must be between 1 and %d", pageSize, MAX_PAGE_SIZE));
} else if (pageSize > MAX_PAGE_SIZE) {
request.setPageSize(MAX_PAGE_SIZE);
}
SearchRequest searchRequest;
try {
searchRequest = new Gson().fromJson(cohortSpec, SearchRequest.class);
} catch (JsonSyntaxException e) {
throw new BadRequestException("Invalid cohort spec");
}
MaterializeCohortResponse response = cohortMaterializationService.materializeCohort(cohortReview, searchRequest, request);
return ResponseEntity.ok(response);
}
use of org.pmiops.workbench.db.model.CohortReview in project workbench by all-of-us.
the class CohortReviewControllerTest method setUp.
@Before
public void setUp() {
LocalDate personBirthDate = LocalDate.of(1980, Month.FEBRUARY, 17);
LocalDate procedureDate1 = LocalDate.of(2009, Month.DECEMBER, 2);
LocalDate procedureDate2 = LocalDate.of(2009, Month.DECEMBER, 3);
Period age1 = Period.between(personBirthDate, procedureDate1);
Period age2 = Period.between(personBirthDate, procedureDate2);
expectedCondition1 = new ParticipantCondition().itemDate("2008-07-22").standardVocabulary("SNOMED").standardName("SNOMED").sourceValue("0020").sourceVocabulary("ICD9CM").sourceName("Typhoid and paratyphoid fevers");
expectedCondition2 = new ParticipantCondition().itemDate("2008-08-01").standardVocabulary("SNOMED").standardName("SNOMED").sourceValue("0021").sourceVocabulary("ICD9CM").sourceName("Typhoid and paratyphoid fevers");
expectedProcedure1 = new ParticipantProcedure().itemDate("2009-12-02").standardVocabulary("ICD10CM").standardName("name").sourceValue("val").sourceVocabulary("ICD10CM").sourceName("name").age(age1.getYears());
expectedProcedure2 = new ParticipantProcedure().itemDate("2009-12-03").standardVocabulary("CPT4").standardName("name").sourceValue("val").sourceVocabulary("CPT4").sourceName("name").age(age2.getYears());
cdrVersion = new CdrVersion();
cdrVersion.setBigqueryDataset(testWorkbenchConfig.bigquery.dataSetId);
cdrVersion.setBigqueryProject(testWorkbenchConfig.bigquery.projectId);
cdrVersionDao.save(cdrVersion);
workspace = new Workspace();
workspace.setCdrVersion(cdrVersion);
workspace.setWorkspaceNamespace(NAMESPACE);
workspace.setFirecloudName(NAME);
workspaceDao.save(workspace);
cohort = new Cohort();
cohort.setWorkspaceId(workspace.getWorkspaceId());
cohortDao.save(cohort);
CohortReview review = new CohortReview().cdrVersionId(cdrVersion.getCdrVersionId()).cohortId(cohort.getCohortId());
cohortReviewDao.save(review);
ParticipantCohortStatusKey key = new ParticipantCohortStatusKey().participantId(PARTICIPANT_ID).cohortReviewId(review.getCohortReviewId());
ParticipantCohortStatus participantCohortStatus = new ParticipantCohortStatus().participantKey(key);
participantCohortStatusDao.save(participantCohortStatus);
}
Aggregations