1+ library Retrieve
2+ using FHIR version '4.0.0'
3+ include FHIRHelpers version '4.0.0'
4+
5+ codesystem icd10: 'http://hl7.org/fhir/sid/icd-10'
6+ codesystem SampleMaterialType: 'https://fhir.bbmri.de/CodeSystem/SampleMaterialType'
7+
8+
9+ context Patient
10+
11+ define AgeClass:
12+ if (Patient.birthDate is null ) then 'unknown' else ToString((AgeInYears() div 10 ) * 10 )
13+
14+ define Gender:
15+ if (Patient.gender is null ) then 'unknown' else Patient.gender
16+
17+ define Custodian:
18+ First(from Specimen.extension E
19+ where E.url = 'https://fhir.bbmri.de/StructureDefinition/Custodian'
20+ return (E.value as Reference).identifier.value)
21+
22+ define function SampleType(specimen FHIR.Specimen):
23+ case FHIRHelpers.ToCode(specimen.type.coding.where(system = 'https://fhir.bbmri.de/CodeSystem/SampleMaterialType' ).first())
24+ when Code 'plasma-edta' from SampleMaterialType then 'blood-plasma'
25+ when Code 'plasma-citrat' from SampleMaterialType then 'blood-plasma'
26+ when Code 'plasma-heparin' from SampleMaterialType then 'blood-plasma'
27+ when Code 'plasma-cell-free' from SampleMaterialType then 'blood-plasma'
28+ when Code 'plasma-other' from SampleMaterialType then 'blood-plasma'
29+ when Code 'plasma' from SampleMaterialType then 'blood-plasma'
30+ when Code 'tissue-formalin' from SampleMaterialType then 'tissue-ffpe'
31+ when Code 'tumor-tissue-ffpe' from SampleMaterialType then 'tissue-ffpe'
32+ when Code 'normal-tissue-ffpe' from SampleMaterialType then 'tissue-ffpe'
33+ when Code 'other-tissue-ffpe' from SampleMaterialType then 'tissue-ffpe'
34+ when Code 'tumor-tissue-frozen' from SampleMaterialType then 'tissue-frozen'
35+ when Code 'normal-tissue-frozen' from SampleMaterialType then 'tissue-frozen'
36+ when Code 'other-tissue-frozen' from SampleMaterialType then 'tissue-frozen'
37+ when Code 'tissue-paxgene-or-else' from SampleMaterialType then 'tissue-other'
38+ when Code 'derivative' from SampleMaterialType then 'derivative-other'
39+ when Code 'liquid' from SampleMaterialType then 'liquid-other'
40+ when Code 'tissue' from SampleMaterialType then 'tissue-other'
41+ when Code 'serum' from SampleMaterialType then 'blood-serum'
42+ when Code 'cf-dna' from SampleMaterialType then 'dna'
43+ when Code 'g-dna' from SampleMaterialType then 'dna'
44+ when Code 'blood-plasma' from SampleMaterialType then 'blood-plasma'
45+ when Code 'tissue-ffpe' from SampleMaterialType then 'tissue-ffpe'
46+ when Code 'tissue-frozen' from SampleMaterialType then 'tissue-frozen'
47+ when Code 'tissue-other' from SampleMaterialType then 'tissue-other'
48+ when Code 'derivative-other' from SampleMaterialType then 'derivative-other'
49+ when Code 'liquid-other' from SampleMaterialType then 'liquid-other'
50+ when Code 'blood-serum' from SampleMaterialType then 'blood-serum'
51+ when Code 'dna' from SampleMaterialType then 'dna'
52+ when Code 'buffy-coat' from SampleMaterialType then 'buffy-coat'
53+ when Code 'urine' from SampleMaterialType then 'urine'
54+ when Code 'ascites' from SampleMaterialType then 'ascites'
55+ when Code 'saliva' from SampleMaterialType then 'saliva'
56+ when Code 'csf-liquor' from SampleMaterialType then 'csf-liquor'
57+ when Code 'bone-marrow' from SampleMaterialType then 'bone-marrow'
58+ when Code 'peripheral-blood-cells-vital' from SampleMaterialType then 'peripheral-blood-cells-vital'
59+ when Code 'stool-faeces' from SampleMaterialType then 'stool-faeces'
60+ when Code 'rna' from SampleMaterialType then 'rna'
61+ when Code 'whole-blood' from SampleMaterialType then 'whole-blood'
62+ when Code 'swab' from SampleMaterialType then 'swab'
63+ when Code 'dried-whole-blood' from SampleMaterialType then 'dried-whole-blood'
64+ when null then 'Unknown'
65+ else 'Unknown'
66+ end
67+ define Specimen:
68+ if InInitialPopulation then [Specimen] S where (((((FHIRHelpers.ToDateTime(S.collection.collected) >= @2015-01-01 ) )))) else {} as List < Specimen>
69+
70+ define Diagnosis:
71+ if InInitialPopulation then [Condition] else {} as List < Condition>
72+
73+ define function DiagnosisCode(condition FHIR.Condition):
74+ condition.code.coding.where(system = 'http://fhir.de/CodeSystem/bfarm/icd-10-gm' ).code.first()
75+
76+ define function DiagnosisCode(condition FHIR.Condition, specimen FHIR.Specimen):
77+ Coalesce(
78+ condition.code.coding.where(system = 'http://hl7.org/fhir/sid/icd-10' ).code.first(),
79+ condition.code.coding.where(system = 'http://fhir.de/CodeSystem/dimdi/icd-10-gm' ).code.first(),
80+ condition.code.coding.where(system = 'http://fhir.de/CodeSystem/bfarm/icd-10-gm' ).code.first(),
81+ specimen.extension.where(url= 'https://fhir.bbmri.de/StructureDefinition/SampleDiagnosis' ).value.coding.code.first()
82+ )
83+
84+ define InInitialPopulation:
85+ ((((exists from [Specimen] S
86+ where FHIRHelpers.ToDateTime(S.collection.collected) >= @2015-01-01 ))))
0 commit comments