Skip to content

Commit 5e36a65

Browse files
authored
Merge pull request #205 from samply/siorgp_sql_queries
fix and add sql queries for the public siorgp dashboard
2 parents 365b323 + 8edf4c1 commit 5e36a65

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

resources/sql/SIORGP_PUBLIC_MAIN renamed to resources/sql/SIORGP_PUBLIC_METPREDICT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ select t.value as pat_pseudonym,
2929
t7.value as location_primary_tumor_precise,
3030
t3.value as therapy,
3131
t4.value as metastases_therapy,
32-
t6.value::integer as age_at_enrollment
32+
t6.value::numeric as age_at_enrollment
3333
from t
3434
left join t t2 on t.pat_ref = t2.pat_ref and t2.code='SIOP_LOCALISATION_PRIMARY_TUMOR'
3535
left join t t3 on t.pat_ref = t3.pat_ref and t3.code='SIOP_NEOADJ_T_RECTAL_CARCINOMA'

resources/sql/SIORGP_PUBLIC_NEOMATCH

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* SIorgP NeoMatch project
2+
The approach chosen here is to minimize the number of tasks generated and thus network traffic via Beam
3+
=> one large query that returns all the most necessary fields over multiple smaller queries
4+
*/
5+
with t as (
6+
select
7+
o.resource->'subject'->>'reference' as pat_ref,
8+
o.resource->'code'->'coding'->0->>'code' as crf,
9+
component->'code'->'coding'->0->>'code' AS code,
10+
COALESCE(
11+
component->'valueCodeableConcept'->'coding'->0->>'code',
12+
component->>'valueDateTime',
13+
component->'valueQuantity'->>'value',
14+
component->>'valueString'
15+
) AS value
16+
FROM
17+
observation o ,
18+
jsonb_array_elements(o.resource->'component') AS component
19+
where o.resource->'code'->'coding'->0->>'code' like 'SIOrgP%'
20+
),
21+
t2 AS (
22+
select t.value as pat_pseudonym,
23+
t2.value as gender,
24+
t6.value::numeric as age_at_enrollment
25+
from t
26+
left join t t2 on t.pat_ref = t2.pat_ref and t2.code='SIOP_GENDER'
27+
left join t t6 on t.pat_ref = t6.pat_ref and t6.code='SIOP_AGE_STUDY_ENROLLMENT'
28+
left join patient p on t.pat_ref = 'Patient/' || (p.resource->>'id')::text
29+
where t.crf like 'SIOrgP - NeoMatch - Visite 1%' and t.code = 'SIOP_PATIENT_PSEUDONYM'
30+
)
31+
-- the total number of patients
32+
select 'NeoMatch' as project, 'n_patients' as field, (select count(distinct pat_pseudonym) from t2) as value
33+
union
34+
select 'NeoMatch' as project, 'gender_male' as field, (select count(distinct pat_pseudonym) from t2 where gender = 'MALE') as value
35+
union
36+
select 'NeoMatch' as project, 'gender_female' as field, (select count(distinct pat_pseudonym) from t2 where gender = 'FEMALE') as value
37+
union
38+
select 'NeoMatch' as project, '<=30' as field, (select count(distinct pat_pseudonym) from t2 where age_at_enrollment <= 30) as value
39+
union
40+
select 'NeoMatch' as project, '31-40' as field, (select count(distinct pat_pseudonym) from t2 where age_at_enrollment >= 31 and age_at_enrollment <= 40) as value
41+
union
42+
select 'NeoMatch' as project, '41-50' as field, (select count(distinct pat_pseudonym) from t2 where age_at_enrollment >= 41 and age_at_enrollment <= 50) as value
43+
union
44+
select 'NeoMatch' as project, '51-60' as field, (select count(distinct pat_pseudonym) from t2 where age_at_enrollment >= 51 and age_at_enrollment <= 60) as value
45+
union
46+
select 'NeoMatch' as project, '>=61' as field, (select count(distinct pat_pseudonym) from t2 where age_at_enrollment >= 61) as value;

0 commit comments

Comments
 (0)