use of org.pmiops.workbench.db.model.CdrVersion 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.CdrVersion in project workbench by all-of-us.
the class CohortBuilderControllerTest method setUp.
@Before
public void setUp() {
cdrVersion = new CdrVersion();
cdrVersion.setCdrVersionId(1L);
cdrVersion.setBigqueryDataset(testWorkbenchConfig.bigquery.dataSetId);
cdrVersion.setBigqueryProject(testWorkbenchConfig.bigquery.projectId);
CdrVersionContext.setCdrVersion(cdrVersion);
cdrVersionDao.save(cdrVersion);
icd9ConditionParent = criteriaDao.save(createCriteriaParent(TYPE_ICD9, SUBTYPE_NONE, "001"));
icd9ConditionChild = criteriaDao.save(createCriteriaChild(TYPE_ICD9, SUBTYPE_NONE, icd9ConditionParent.getId(), "001", DOMAIN_CONDITION));
icd9ProcedureParent = criteriaDao.save(createCriteriaParent(TYPE_ICD9, SUBTYPE_NONE, "002"));
icd9ProcedureChild = criteriaDao.save(createCriteriaChild(TYPE_ICD9, SUBTYPE_NONE, icd9ProcedureParent.getId(), "002", DOMAIN_PROCEDURE));
icd9MeasurementParent = criteriaDao.save(createCriteriaParent(TYPE_ICD9, SUBTYPE_NONE, "003"));
icd9MeasurementChild = criteriaDao.save(createCriteriaChild(TYPE_ICD9, SUBTYPE_NONE, icd9MeasurementParent.getId(), "003", DOMAIN_MEASUREMENT));
icd10ConditionParent = criteriaDao.save(createCriteriaParent(TYPE_ICD10, SUBTYPE_ICD10CM, "A"));
icd10ConditionChild = criteriaDao.save(createCriteriaChild(TYPE_ICD10, SUBTYPE_ICD10CM, icd10ConditionParent.getId(), "A09", DOMAIN_CONDITION));
icd10ProcedureParent = criteriaDao.save(createCriteriaParent(TYPE_ICD10, SUBTYPE_ICD10PCS, "16"));
icd10ProcedureChild = criteriaDao.save(createCriteriaChild(TYPE_ICD10, SUBTYPE_ICD10PCS, icd10ProcedureParent.getId(), "16070", DOMAIN_PROCEDURE));
icd10MeasurementParent = criteriaDao.save(createCriteriaParent(TYPE_ICD10, SUBTYPE_ICD10CM, "R92"));
icd10MeasurementChild = criteriaDao.save(createCriteriaChild(TYPE_ICD10, SUBTYPE_ICD10CM, icd10MeasurementParent.getId(), "R92.2", DOMAIN_MEASUREMENT));
cptProcedure = criteriaDao.save(createCriteriaChild(TYPE_CPT, SUBTYPE_CPT4, 1L, "0001T", DOMAIN_PROCEDURE));
cptObservation = criteriaDao.save(createCriteriaChild(TYPE_CPT, SUBTYPE_CPT4, 1L, "0001Z", DOMAIN_OBSERVATION));
cptMeasurement = criteriaDao.save(createCriteriaChild(TYPE_CPT, SUBTYPE_CPT4, 1L, "0001Q", DOMAIN_MEASUREMENT));
cptDrug = criteriaDao.save(createCriteriaChild(TYPE_CPT, SUBTYPE_CPT4, 1L, "90703", DOMAIN_DRUG));
}
use of org.pmiops.workbench.db.model.CdrVersion 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);
}
use of org.pmiops.workbench.db.model.CdrVersion in project workbench by all-of-us.
the class WorkspacesController method setCdrVersionId.
private void setCdrVersionId(org.pmiops.workbench.db.model.Workspace dbWorkspace, String cdrVersionId) {
if (cdrVersionId != null) {
try {
CdrVersion cdrVersion = cdrVersionDao.findOne(Long.parseLong(cdrVersionId));
if (cdrVersion == null) {
throw new BadRequestException(String.format("CDR version with ID %s not found", cdrVersionId));
}
dbWorkspace.setCdrVersion(cdrVersion);
} catch (NumberFormatException e) {
throw new BadRequestException(String.format("Invalid cdr version ID: %s", cdrVersionId));
}
}
}
use of org.pmiops.workbench.db.model.CdrVersion in project workbench by all-of-us.
the class AuditControllerTest method setUp.
@Before
public void setUp() {
User user = new User();
user.setEmail(USER_EMAIL);
user.setUserId(123L);
user.setFreeTierBillingProjectName(FC_PROJECT_ID);
user.setDisabled(false);
user = userDao.save(user);
cdrV1 = new CdrVersion();
cdrV1.setBigqueryProject(CDR_V1_PROJECT_ID);
cdrV1 = cdrVersionDao.save(cdrV1);
cdrV2 = new CdrVersion();
cdrV2.setBigqueryProject(CDR_V2_PROJECT_ID);
cdrV2 = cdrVersionDao.save(cdrV2);
CLOCK.setInstant(NOW);
}
Aggregations