diff --git a/resources/cql/EXLIQUID_ALIQUOTS_CQL_DIAGNOSIS b/resources/cql/EXLIQUID_ALIQUOTS_CQL_DIAGNOSIS deleted file mode 100644 index 1abf1cd..0000000 --- a/resources/cql/EXLIQUID_ALIQUOTS_CQL_DIAGNOSIS +++ /dev/null @@ -1,3 +0,0 @@ -define retrieveCondition: First(from [Condition] C return C.code.coding.where(system = 'http://fhir.de/CodeSystem/bfarm/icd-10-gm').code.first()) -define Diagnosis: if (retrieveCondition is null) then 'unknown' else retrieveCondition - diff --git a/resources/cql/EXLIQUID_ALIQUOTS_CQL_SPECIMEN b/resources/cql/EXLIQUID_ALIQUOTS_CQL_SPECIMEN deleted file mode 100644 index 2dcd10a..0000000 --- a/resources/cql/EXLIQUID_ALIQUOTS_CQL_SPECIMEN +++ /dev/null @@ -1,6 +0,0 @@ -define Specimen: -if InInitialPopulation then [Specimen] else {} as List - define Aliquot: - [Specimen] S - 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 - define function SampleType(specimen FHIR.Specimen): specimen.type.coding.where(system = 'https://fhir.bbmri.de/CodeSystem/SampleMaterialType').code.first() diff --git a/resources/cql/EXLIQUID_STRAT_W_ALIQUOTS b/resources/cql/EXLIQUID_STRAT_W_ALIQUOTS index 3cfe321..bc7f955 100644 --- a/resources/cql/EXLIQUID_STRAT_W_ALIQUOTS +++ b/resources/cql/EXLIQUID_STRAT_W_ALIQUOTS @@ -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) + + '"}' \ No newline at end of file diff --git a/src/util.rs b/src/util.rs index 282eb92..668fde7 100644 --- a/src/util.rs +++ b/src/util.rs @@ -450,24 +450,16 @@ mod test { let expected_result = "define Specimen:\nif InInitialPopulation then [Specimen] else {} as List\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\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";