How to use cql-execution - 10 common examples

To help you get started, we’ve selected a few cql-execution examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AHRQ-CDS / AHRQ-CDS-Connect-Authoring-Tool / frontend / src / actions / artifacts.js View on Github external
function performExecuteArtifact(elmFiles, artifactName, params, patients, vsacCredentials, codeService, dataModel) {
  // Set up the library
  const elmFile = JSON.parse(_.find(elmFiles, f =>
    f.name.replace(/[\s-\\/]/g, '') === artifactName.replace(/[\s-\\/]/g, '')).content);
  const libraries = _.filter(elmFiles, f =>
    f.name.replace(/[\s-\\/]/g, '') !== artifactName.replace(/[\s-\\/]/g, '')).map(f => JSON.parse(f.content));
  const library = new cql.Library(elmFile, new cql.Repository(libraries));

  // Set up the parameters
  const cqlExecParams = convertParameters(params);

  // Create the patient source
  const patientSource = (dataModel.version === '3.0.0')
    ? cqlfhir.PatientSource.FHIRv300()
    : cqlfhir.PatientSource.FHIRv102();

  // Load the patient source with the patient
  patientSource.loadBundles(patients);

  // Extract the value sets from the ELM
  let valueSets = [];
  if (elmFile.library && elmFile.library.valueSets && elmFile.library.valueSets.def) {
    valueSets = elmFile.library.valueSets.def;
github HL7-DaVinci / dtr / src / elmExecutor / executeElm.js View on Github external
function executeElmAgainstPatientSource(executionInputs, patientSource) {
  // executionInputs.elmDependencies = [ fhirhelpersElm ]
  const repository = new cql.Repository(executionInputs.elmDependencies);
  const lib = new cql.Library(executionInputs.elm, repository);
  const codeService = new cql.CodeService(executionInputs.valueSetDB);
  const executor = new cql.Executor(lib, codeService, executionInputs.parameters);
  const results = executor.exec(patientSource);
  return results.patientResults[Object.keys(results.patientResults)[0]];
}
github HL7-DaVinci / dtr / src / elmExecutor / executeElm.js View on Github external
function executeElmAgainstPatientSource(executionInputs, patientSource) {
  // executionInputs.elmDependencies = [ fhirhelpersElm ]
  const repository = new cql.Repository(executionInputs.elmDependencies);
  const lib = new cql.Library(executionInputs.elm, repository);
  const codeService = new cql.CodeService(executionInputs.valueSetDB);
  const executor = new cql.Executor(lib, codeService, executionInputs.parameters);
  const results = executor.exec(patientSource);
  return results.patientResults[Object.keys(results.patientResults)[0]];
}
github HL7-DaVinci / dtr / src / elmExecutor / executeElm.js View on Github external
function executeElmAgainstPatientSource(executionInputs, patientSource) {
  // executionInputs.elmDependencies = [ fhirhelpersElm ]
  const repository = new cql.Repository(executionInputs.elmDependencies);
  const lib = new cql.Library(executionInputs.elm, repository);
  const codeService = new cql.CodeService(executionInputs.valueSetDB);
  const executor = new cql.Executor(lib, codeService, executionInputs.parameters);
  const results = executor.exec(patientSource);
  return results.patientResults[Object.keys(results.patientResults)[0]];
}
github AHRQ-CDS / AHRQ-CDS-Connect-Authoring-Tool / frontend / src / actions / artifacts.js View on Github external
.then(() => {
      // Value sets are loaded, so execute!
      const executor = new cql.Executor(library, codeService, cqlExecParams);
      const results = executor.exec(patientSource);
      return results;
    });
}
github HL7-DaVinci / dtr / src / elmExecutor / executeElm.js View on Github external
function executeElmAgainstPatientSource(executionInputs, patientSource) {
  // executionInputs.elmDependencies = [ fhirhelpersElm ]
  const repository = new cql.Repository(executionInputs.elmDependencies);
  const lib = new cql.Library(executionInputs.elm, repository);
  const codeService = new cql.CodeService(executionInputs.valueSetDB);
  const executor = new cql.Executor(lib, codeService, executionInputs.parameters);
  const results = executor.exec(patientSource);
  return results.patientResults[Object.keys(results.patientResults)[0]];
}
github AHRQ-CDS / AHRQ-CDS-Connect-Authoring-Tool / frontend / src / actions / artifacts.js View on Github external
case 'interval_of_decimal':
        paramsObj[p.name] = new cql.Interval(p.value.firstDecimal, p.value.secondDecimal);
        break;
      case 'interval_of_integer':
        paramsObj[p.name] = new cql.Interval(p.value.firstInteger, p.value.secondInteger);
        break;
      case 'interval_of_quantity': {
        const q1 = p.value.firstQuantity != null ? new cql.Quantity({
          value: p.value.firstQuantity,
          unit: p.value.unit
        }) : null;
        const q2 = p.value.secondQuantity != null ? new cql.Quantity({
          value: p.value.secondQuantity,
          unit: p.value.unit
        }) : null;
        paramsObj[p.name] = new cql.Interval(q1, q2);
        break;
      }
      case 'string':
        // Remove the leading and trailing single-quotes
        paramsObj[p.name] = p.value.replace(/^'(.*)'$/, '$1');
        break;
      case 'system_code':
        paramsObj[p.name] = new cql.Code(p.value.code, p.value.uri);
        break;
      case 'system_concept':
        paramsObj[p.name] = new cql.Concept([new cql.Code(p.value.code, p.value.uri)]);
        break;
      case 'system_quantity':
        paramsObj[p.name] = new cql.Quantity({
          value: p.value.quantity,
          unit: p.value.unit
github AHRQ-CDS / AHRQ-CDS-Connect-Authoring-Tool / frontend / src / actions / artifacts.js View on Github external
if (p.value.firstDate) {
          const str = p.value.firstTime ? `${p.value.firstDate}T${p.value.firstTime}` : p.value.firstDate;
          d1 = cql.DateTime.parse(str);
        }
        if (p.value.secondDate) {
          const str = p.value.secondTime ? `${p.value.secondDate}T${p.value.secondTime}` : p.value.secondDate;
          d2 = cql.DateTime.parse(str);
        }
        paramsObj[p.name] = new cql.Interval(d1, d2);
        break;
      }
      case 'interval_of_decimal':
        paramsObj[p.name] = new cql.Interval(p.value.firstDecimal, p.value.secondDecimal);
        break;
      case 'interval_of_integer':
        paramsObj[p.name] = new cql.Interval(p.value.firstInteger, p.value.secondInteger);
        break;
      case 'interval_of_quantity': {
        const q1 = p.value.firstQuantity != null ? new cql.Quantity({
          value: p.value.firstQuantity,
          unit: p.value.unit
        }) : null;
        const q2 = p.value.secondQuantity != null ? new cql.Quantity({
          value: p.value.secondQuantity,
          unit: p.value.unit
        }) : null;
        paramsObj[p.name] = new cql.Interval(q1, q2);
        break;
      }
      case 'string':
        // Remove the leading and trailing single-quotes
        paramsObj[p.name] = p.value.replace(/^'(.*)'$/, '$1');
github AHRQ-CDS / AHRQ-CDS-Connect-Authoring-Tool / frontend / src / actions / artifacts.js View on Github external
const q2 = p.value.secondQuantity != null ? new cql.Quantity({
          value: p.value.secondQuantity,
          unit: p.value.unit
        }) : null;
        paramsObj[p.name] = new cql.Interval(q1, q2);
        break;
      }
      case 'string':
        // Remove the leading and trailing single-quotes
        paramsObj[p.name] = p.value.replace(/^'(.*)'$/, '$1');
        break;
      case 'system_code':
        paramsObj[p.name] = new cql.Code(p.value.code, p.value.uri);
        break;
      case 'system_concept':
        paramsObj[p.name] = new cql.Concept([new cql.Code(p.value.code, p.value.uri)]);
        break;
      case 'system_quantity':
        paramsObj[p.name] = new cql.Quantity({
          value: p.value.quantity,
          unit: p.value.unit
        });
        break;
      case 'time':
        // CQL exec doesn't expose a Time class, so we must construct a DT and then get the Time
        paramsObj[p.name] = cql.DateTime.parse(`@0000-01-01${p.value.slice(1)}`).getTime();
        break;
      default: // do nothing
    }
  });
  return paramsObj;
github AHRQ-CDS / AHRQ-CDS-Connect-Authoring-Tool / frontend / src / actions / artifacts.js View on Github external
}
        if (p.value.secondDate) {
          const str = p.value.secondTime ? `${p.value.secondDate}T${p.value.secondTime}` : p.value.secondDate;
          d2 = cql.DateTime.parse(str);
        }
        paramsObj[p.name] = new cql.Interval(d1, d2);
        break;
      }
      case 'interval_of_decimal':
        paramsObj[p.name] = new cql.Interval(p.value.firstDecimal, p.value.secondDecimal);
        break;
      case 'interval_of_integer':
        paramsObj[p.name] = new cql.Interval(p.value.firstInteger, p.value.secondInteger);
        break;
      case 'interval_of_quantity': {
        const q1 = p.value.firstQuantity != null ? new cql.Quantity({
          value: p.value.firstQuantity,
          unit: p.value.unit
        }) : null;
        const q2 = p.value.secondQuantity != null ? new cql.Quantity({
          value: p.value.secondQuantity,
          unit: p.value.unit
        }) : null;
        paramsObj[p.name] = new cql.Interval(q1, q2);
        break;
      }
      case 'string':
        // Remove the leading and trailing single-quotes
        paramsObj[p.name] = p.value.replace(/^'(.*)'$/, '$1');
        break;
      case 'system_code':
        paramsObj[p.name] = new cql.Code(p.value.code, p.value.uri);