Skip to content

Commit

Permalink
Merge pull request #104 from samply/develop
Browse files Browse the repository at this point in the history
exliquid
  • Loading branch information
enola-dkfz authored Jan 26, 2024
2 parents b60223f + 4a28276 commit 6e3a109
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 21 deletions.
3 changes: 0 additions & 3 deletions resources/cql/EXLIQUID_ALIQUOTS_CQL_DIAGNOSIS

This file was deleted.

6 changes: 0 additions & 6 deletions resources/cql/EXLIQUID_ALIQUOTS_CQL_SPECIMEN

This file was deleted.

39 changes: 38 additions & 1 deletion resources/cql/EXLIQUID_STRAT_W_ALIQUOTS
Original file line number Diff line number Diff line change
@@ -1,2 +1,39 @@
define InInitialPopulation: exists ExliquidSpecimenWithAliquot and
define InInitialPopulation:
exists AnySpecimen

define AnySpecimen:
[Specimen] S

define retrieveCondition:
First(from [Condition] C
return ('{\"subject_reference\": \"' + C.subject.reference
+ '\", \"diagnosis_code\": \"'
+ C.code.coding.where(system = 'http://fhir.de/CodeSystem/bfarm/icd-10-gm').code.first()
+ '\"}'
))

define Diagnosis:
if (retrieveCondition is null) then '{\"subject_reference\": \"\", \"diagnosis_code\": \"\"}'
else retrieveCondition

define function getSampletype(specimen FHIR.Specimen):
if (not exists specimen.type.coding.where(system = 'https://fhir.bbmri.de/CodeSystem/SampleMaterialType').code) then 'null'
else specimen.type.coding.where(system = 'https://fhir.bbmri.de/CodeSystem/SampleMaterialType').code.first()

define function getRestamount(specimen FHIR.Specimen):
if (not exists specimen.collection.quantity.value) then '0' else specimen.collection.quantity.value.toString()

define function getParentReference(specimen FHIR.Specimen):
if (not exists specimen.parent.reference) then 'null' else specimen.parent.reference

define function getSubjectReference(specimen FHIR.Specimen):
if (not exists specimen.subject.reference) then 'null' else specimen.subject.reference

define function SingleStrat(specimen FHIR.Specimen):
'{"specimen_id": "' + specimen.id +
'", "sampletype": "' + getSampletype(specimen) +
'", "exliquid_tag": ' + (specimen.identifier.system contains 'http://dktk.dkfz.de/fhir/sid/exliquid-specimen').toString() +
', "rest_amount": "' + getRestamount(specimen) +
'", "parent_reference": "' + getParentReference(specimen) +
'", "subject_reference": "' + getSubjectReference(specimen) +
'"}'
14 changes: 3 additions & 11 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,24 +450,16 @@ mod test {
let expected_result = "define Specimen:\nif InInitialPopulation then [Specimen] else {} as List<Specimen>\ndefine ExliquidSpecimen:\n from [Specimen] S\n where S.identifier.system contains 'http://dktk.dkfz.de/fhir/sid/exliquid-specimen'\ndefine function SampleType(specimen FHIR.Specimen):\n specimen.type.coding.where(system = 'https://fhir.bbmri.de/CodeSystem/SampleMaterialType').code.first()\n";
assert_eq!(replace_cql(decoded_library), expected_result);

let decoded_library = "EXLIQUID_ALIQUOTS_CQL_SPECIMEN";
let expected_result = "define Specimen:\nif InInitialPopulation then [Specimen] else {} as List<Specimen>\n define Aliquot:\n [Specimen] S\n where exists S.collection.quantity.value and exists S.parent.reference and S.container.specimenQuantity.value > 0 define AliquotGroupReferences: flatten Aliquot S return S.parent.reference define AliquotGroupWithAliquot: [Specimen] S where not (S.identifier.system contains 'http://dktk.dkfz.de/fhir/sid/exliquid-specimen') and not exists S.collection.quantity.value and not exists S.container.specimenQuantity.value and AliquotGroupReferences contains 'Specimen/' + S.id define PrimarySampleReferences: flatten AliquotGroupWithAliquot S return S.parent.reference define ExliquidSpecimenWithAliquot: from [Specimen] PrimarySample where PrimarySample.identifier.system contains 'http://dktk.dkfz.de/fhir/sid/exliquid-specimen' and PrimarySampleReferences contains 'Specimen/' + PrimarySample.id \n define function SampleType(specimen FHIR.Specimen): specimen.type.coding.where(system = 'https://fhir.bbmri.de/CodeSystem/SampleMaterialType').code.first()\n";
let decoded_library = "EXLIQUID_STRAT_W_ALIQUOTS";
let expected_result = "define InInitialPopulation:\n exists AnySpecimen\n \ndefine AnySpecimen:\n [Specimen] S\n\ndefine retrieveCondition:\n First(from [Condition] C\n return ('{\\\"subject_reference\\\": \\\"' + C.subject.reference \n + '\\\", \\\"diagnosis_code\\\": \\\"' \n + C.code.coding.where(system = 'http://fhir.de/CodeSystem/bfarm/icd-10-gm').code.first() \n + '\\\"}'\n ))\n \ndefine Diagnosis:\n if (retrieveCondition is null) then '{\\\"subject_reference\\\": \\\"\\\", \\\"diagnosis_code\\\": \\\"\\\"}' \n else retrieveCondition\n\ndefine function getSampletype(specimen FHIR.Specimen):\n if (not exists specimen.type.coding.where(system = 'https://fhir.bbmri.de/CodeSystem/SampleMaterialType').code) then 'null'\n else specimen.type.coding.where(system = 'https://fhir.bbmri.de/CodeSystem/SampleMaterialType').code.first()\n\ndefine function getRestamount(specimen FHIR.Specimen):\n if (not exists specimen.collection.quantity.value) then '0' else specimen.collection.quantity.value.toString()\n\ndefine function getParentReference(specimen FHIR.Specimen): \n if (not exists specimen.parent.reference) then 'null' else specimen.parent.reference\n\ndefine function getSubjectReference(specimen FHIR.Specimen): \n if (not exists specimen.subject.reference) then 'null' else specimen.subject.reference\n\ndefine function SingleStrat(specimen FHIR.Specimen):\n '{\"specimen_id\": \"' + specimen.id + \n '\", \"sampletype\": \"' + getSampletype(specimen) +\n '\", \"exliquid_tag\": ' + (specimen.identifier.system contains 'http://dktk.dkfz.de/fhir/sid/exliquid-specimen').toString() +\n ', \"rest_amount\": \"' + getRestamount(specimen) +\n '\", \"parent_reference\": \"' + getParentReference(specimen) +\n '\", \"subject_reference\": \"' + getSubjectReference(specimen) +\n '\"}'";
assert_eq!(replace_cql(decoded_library), expected_result);

let decoded_library = "EXLIQUID_ALIQUOTS_CQL_DIAGNOSIS";
let expected_result = "define retrieveCondition: First(from [Condition] C return C.code.coding.where(system = 'http://fhir.de/CodeSystem/bfarm/icd-10-gm').code.first())\ndefine Diagnosis: if (retrieveCondition is null) then 'unknown' else retrieveCondition\n\n";
assert_eq!(replace_cql(decoded_library), expected_result);

let decoded_library = "EXLIQUID_STRAT_DEF_IN_INITIAL_POPULATION";
let expected_result = "define InInitialPopulation:\n exists ExliquidSpecimen and\n\n";
assert_eq!(replace_cql(decoded_library), expected_result);

let decoded_library = "EXLIQUID_STRAT_W_ALIQUOTS";
let expected_result =
"define InInitialPopulation: exists ExliquidSpecimenWithAliquot and \n\n";

assert_eq!(replace_cql(decoded_library), expected_result);


let decoded_library = "MTBA_STRAT_GENETIC_VARIANT";
let expected_result = "define GeneticVariantCode:\nFirst (from [Observation: Code '69548-6' from loinc] O return O.component.where(code.coding contains Code '48018-6' from loinc).value.coding.code.first())\n";

Expand Down

0 comments on commit 6e3a109

Please sign in to comment.