Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new query for exliquid dashboard #103

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading