Search in sources :

Example 1 with CdrVersion

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);
}
Also used : CdrVersion(org.pmiops.workbench.db.model.CdrVersion) SearchRequest(org.pmiops.workbench.model.SearchRequest) NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) Gson(com.google.gson.Gson) MaterializeCohortResponse(org.pmiops.workbench.model.MaterializeCohortResponse) JsonSyntaxException(com.google.gson.JsonSyntaxException) BadRequestException(org.pmiops.workbench.exceptions.BadRequestException) CohortReview(org.pmiops.workbench.db.model.CohortReview) Workspace(org.pmiops.workbench.db.model.Workspace)

Example 2 with CdrVersion

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));
}
Also used : CdrVersion(org.pmiops.workbench.db.model.CdrVersion) Before(org.junit.Before)

Example 3 with CdrVersion

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);
}
Also used : CdrVersion(org.pmiops.workbench.db.model.CdrVersion) Cohort(org.pmiops.workbench.db.model.Cohort) ParticipantCohortStatus(org.pmiops.workbench.db.model.ParticipantCohortStatus) ParticipantCohortStatusKey(org.pmiops.workbench.db.model.ParticipantCohortStatusKey) CohortReview(org.pmiops.workbench.db.model.CohortReview) Workspace(org.pmiops.workbench.db.model.Workspace) Before(org.junit.Before)

Example 4 with CdrVersion

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));
        }
    }
}
Also used : CdrVersion(org.pmiops.workbench.db.model.CdrVersion) BadRequestException(org.pmiops.workbench.exceptions.BadRequestException)

Example 5 with CdrVersion

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);
}
Also used : CdrVersion(org.pmiops.workbench.db.model.CdrVersion) User(org.pmiops.workbench.db.model.User) Before(org.junit.Before)

Aggregations

CdrVersion (org.pmiops.workbench.db.model.CdrVersion)18 Before (org.junit.Before)8 Test (org.junit.Test)8 Criteria (org.pmiops.workbench.model.Criteria)7 Gson (com.google.gson.Gson)4 User (org.pmiops.workbench.db.model.User)4 CohortReview (org.pmiops.workbench.db.model.CohortReview)2 Workspace (org.pmiops.workbench.db.model.Workspace)2 BadRequestException (org.pmiops.workbench.exceptions.BadRequestException)2 ResearchPurpose (org.pmiops.workbench.model.ResearchPurpose)2 Workspace (org.pmiops.workbench.model.Workspace)2 FieldValue (com.google.cloud.bigquery.FieldValue)1 QueryResult (com.google.cloud.bigquery.QueryResult)1 Blob (com.google.cloud.storage.Blob)1 BlobId (com.google.cloud.storage.BlobId)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Maps (com.google.common.collect.Maps)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1