Skip to content

Commit

Permalink
Add clinical event sample SQL code
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthijsPon committed Apr 19, 2024
1 parent 7fc6800 commit c2019ad
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
42 changes: 42 additions & 0 deletions clinical_event_counts.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
-- This is example code to get Clinical Event counts using pure SQL
-- Could replace JAVA code tied to the /api/clinical-event-type-counts/fetch endpoint
-- Authors: Robert Sheridan, Matthijs Pon

WITH select_all_events_from_studies AS -- Keeps this table IN memory, saves overhead?
(
SELECT
sample.stable_id AS stableId,
clinical_event.event_type AS eventType,
patient.stable_id AS patientId,
cancer_study.cancer_study_identifier AS cancerStudyId
FROM
sample
Inner Join patient ON sample.patient_id = patient.internal_id
Inner join clinical_event ON clinical_event.patient_id = patient.internal_id
Inner Join cancer_study ON cancer_study.cancer_study_id = patient.cancer_study_id
WHERE cancer_study.cancer_study_identifier IN ('brca_akt1_genie_2019','erbb2_genie_public','crc_public_genie_bpc',
'nsclc_public_genie_bpc','mbc_genie_2020')
),
studyViewFilter AS -- TEMP representation of full studyviewfilter, this is only the clinical event part
(
SELECT
DISTINCT stableId AS uniqueSampleKey,
patientId AS uniquePatientKey
FROM
select_all_events_from_studies WHERE eventType IN ('Treatment', 'LAB_TEST') -- OR
INTERSECT -- AND
SELECT
DISTINCT stableId AS UniqueSampleKey,
patientId AS uniquePatientKey
FROM
select_all_events_from_studies WHERE eventType IN ('Pathology') -- OR
)
SELECT
eventType,
count(DISTINCT patientId) AS count -- Counts are on patient level
FROM
select_all_events_from_studies
WHERE
stableId IN (SELECT uniqueSampleKey FROM studyViewFilter)
GROUP BY eventType
ORDER BY count DESC;
32 changes: 32 additions & 0 deletions clinical_event_studyviewfilter.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-- This is example code to filter a sample list using clinical event filters
-- Should become part of a bigger 'StudyViewFilter' SQL statement, which performs the full filtering.
-- Authors: Robert Sheridan, Matthijs Pon

WITH select_all_events_from_study as -- Keeps this table in memory, saves overhead?
(
SELECT
sample.stable_id as stableId,
clinical_event.event_type as eventType,
patient.stable_id as patientId,
cancer_study.cancer_study_identifier as cancerStudyId
FROM
sample
Inner Join patient on sample.patient_id = patient.internal_id
Inner join clinical_event on clinical_event.patient_id = patient.internal_id
Inner Join cancer_study on cancer_study.cancer_study_id = patient.cancer_study_id
WHERE cancer_study.cancer_study_identifier in ('brca_akt1_genie_2019','erbb2_genie_public','crc_public_genie_bpc',
'nsclc_public_genie_bpc','mbc_genie_2020')
)
SELECT
DISTINCT stableId as uniqueSampleKey,
patientId as uniquePatientKey,
cancerStudyId
FROM
select_all_events_from_study WHERE eventType in ('Treatment', 'LAB_TEST') -- OR filter
INTERSECT -- AND filter
SELECT
DISTINCT stableId as UniqueSampleKey,
patientId as uniquePatientKey,
cancerStudyId
FROM
select_all_events_from_study WHERE eventType in ('Pathology'); -- OR filter

0 comments on commit c2019ad

Please sign in to comment.