Skip to content

Commit

Permalink
feat: added exliquid code
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickskowronekdkfz committed Sep 20, 2023
1 parent 06f211f commit d15bd54
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 11 deletions.
5 changes: 0 additions & 5 deletions core/cql/src/beam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,8 @@ export class Beam implements RequestTarget {
}

async send(query: string, measures: Object[]): Promise<string> {
console.debug(`send running withCredentials: ${this.withCredentials}`)
this.resultSubject$.next(new Map<string, any>())

console.log("Send")
console.log(query)
console.log(measures)

let baseCQL = btoa(unescape(encodeURIComponent(query)));

let libUUID = uuidv4();
Expand Down
93 changes: 88 additions & 5 deletions core/cql/src/cql-translator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import {
LENS_CONFIG_TOKEN,
} from '@samply/lens-core';

import { formatDate } from '@angular/common';



@Injectable({
providedIn: 'root',
})
Expand Down Expand Up @@ -87,6 +91,7 @@ export class CqlTranslatorService implements QueryTranslator {

cqltemplate = new Map<string, string>([
['gender', 'Patient.gender'],
["samplingDate", "exists from [Specimen] S\nwhere FHIRHelpers.ToDateTime(S.collection.collected) between {{D1}} and {{D2}}"],
['conditionValue', "exists [Condition: Code '{{C}}' from {{A1}}]"],
[
'conditionBodySite',
Expand Down Expand Up @@ -167,6 +172,7 @@ export class CqlTranslatorService implements QueryTranslator {

criterionMap = new Map<string, { type: string; alias?: string[] }>([
['gender', { type: 'gender' }],
['samplingDate', { type: 'samplingDate' }],
['diagnosis', { type: 'conditionValue', alias: ['icd10'] }],
['bodySite', { type: 'conditionBodySite', alias: ['bodySite'] }],
[
Expand Down Expand Up @@ -282,10 +288,6 @@ export class CqlTranslatorService implements QueryTranslator {
"codesystem SampleMaterialType: 'https://fhir.bbmri.de/CodeSystem/SampleMaterialType'\n" +
'\n';

console.log('Addition');
console.log(this.configuration.cqlHeaderAddition);
// cqlHeader + this.configuration.cqlHeaderAddition

let singletons: string = this.configuration.backendMeasureReplacement
? this.configuration.cqlInitPopPlaceholder + '\n'
: 'define InInitialPopulation:\n';
Expand Down Expand Up @@ -344,6 +346,31 @@ export class CqlTranslatorService implements QueryTranslator {
case 'procedureResidualstatus':
case 'medicationStatement':
case 'specimen':
case 'samplingDate':
{
if (
typeof criterion.value == 'object' &&
!(criterion.value instanceof Array) &&
(criterion.value.min instanceof Date &&
criterion.value.max instanceof Date)
)
{
expression = expression.slice(0, -1);
expression += " and ("

expression +=
this.substituteCQLExpressionDate(
criterion.key,
myCriterion.alias,
myCQL,
'',
criterion.value.min as Date,
criterion.value.max as Date
) + ') and\n';
}
break;

}
case 'hasSpecimen':
case 'Organization':
case 'observationMolecularMarkerName':
Expand Down Expand Up @@ -532,7 +559,6 @@ export class CqlTranslatorService implements QueryTranslator {

getCodesystems(): string {
let codesystems: string = '';
console.log(this.codesystems);
this.codesystems.forEach((systems) => {
codesystems += systems + '\n';
});
Expand All @@ -541,4 +567,61 @@ export class CqlTranslatorService implements QueryTranslator {
}
return codesystems;
}



substituteCQLExpressionDate(
key: string,
alias: string[] | undefined,
cql: string,
value?: string,
min?: Date,
max?: Date
): string {
let cqlString: string;
if (value) {
cqlString = cql.replace(new RegExp('{{C}}'), value);
while (cqlString.search('{{C}}') != -1) {
cqlString = cqlString.replace(new RegExp('{{C}}'), value);
}
} else {
cqlString = cql;
}
cqlString = cqlString.replace(new RegExp('{{K}}'), key);
if (alias && alias[0]) {
cqlString = cqlString.replace(new RegExp('{{A1}}', 'g'), alias[0]);
if (alias[0] != 'icd10' && alias[0] != 'SampleMaterialType') {
const systemExpression =
'codesystem ' + alias[0] + ": '" + this.alias.get(alias[0]) + "'";
if (!this.codesystems.includes(systemExpression)) {
//this doesn't work
this.codesystems.push(systemExpression);
}
}
}
if (alias && alias[1]) {
cqlString = cqlString.replace(new RegExp('{{A2}}', 'g'), alias[1]);
const systemExpression =
'codesystem ' + alias[1] + ": '" + this.alias.get(alias[1]) + "'";
if (!this.codesystems.includes(systemExpression)) {
this.codesystems.push(systemExpression);
}
}
if (min) {
cqlString = cqlString.replace(
new RegExp('{{D1}}'),
'@' + formatDate(min, 'yyyy-MM-dd', 'en_US')
);
}
if (max) {
cqlString = cqlString.replace(
new RegExp('{{D2}}'),
'@' + formatDate(max, 'yyyy-MM-dd', 'en_US')
);
}
return cqlString;
}


}

1 change: 0 additions & 1 deletion core/cql/src/measure-transformer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export class MeasureTransformerService implements ResultTransformer {
results.forEach((data, requestTarget) => {
let siteMeasures: Array<Measure> = []
if (data != undefined && data.group instanceof Array) {
console.log(`Running through adding`)
data.group.forEach((group: any) => {
siteMeasures.push(this.transformToMeasure(group, requestTarget))
})
Expand Down

0 comments on commit d15bd54

Please sign in to comment.