# CQL CQL - Using CQL With FHIR v3.0.0-ballot

## OperationDefinition: CQL CQL 

 
The $cql operation evaluates a CQL expression and returns the result. The operation has a single return parameter that can be of any type to accommodate the possible result types of a CQL expression. 



## Resource Content

```json
{
  "resourceType" : "OperationDefinition",
  "id" : "cql-cql",
  "extension" : [{
    "url" : "http://hl7.org/fhir/StructureDefinition/structuredefinition-fmm",
    "valueInteger" : 4
  },
  {
    "url" : "http://hl7.org/fhir/StructureDefinition/structuredefinition-wg",
    "valueCode" : "cds"
  },
  {
    "url" : "http://hl7.org/fhir/StructureDefinition/structuredefinition-standards-status",
    "valueCode" : "trial-use"
  }],
  "url" : "http://hl7.org/fhir/uv/cql/OperationDefinition/cql-cql",
  "version" : "3.0.0-ballot",
  "name" : "CQLCQL",
  "title" : "CQL CQL",
  "status" : "active",
  "kind" : "operation",
  "experimental" : false,
  "date" : "2023-11-27T16:26:11+00:00",
  "publisher" : "HL7 International / Clinical Decision Support",
  "contact" : [{
    "telecom" : [{
      "system" : "url",
      "value" : "http://www.hl7.org/Special/committees/dss"
    }]
  }],
  "description" : "The $cql operation evaluates a CQL expression and returns the result. The operation has a single return parameter that can be of any type to accommodate the possible result types of a CQL expression.",
  "jurisdiction" : [{
    "coding" : [{
      "system" : "http://unstats.un.org/unsd/methods/m49/m49.htm",
      "code" : "001",
      "display" : "World"
    }]
  }],
  "purpose" : "This operation is defined to support evaluating CQL expressions directly via an operation",
  "affectsState" : false,
  "code" : "cql",
  "system" : true,
  "type" : false,
  "instance" : false,
  "parameter" : [{
    "name" : "subject",
    "use" : "in",
    "min" : 0,
    "max" : "1",
    "documentation" : "Subject for which the expression will be evaluated. This corresponds to the context in which the expression will be evaluated and is represented as a relative FHIR id (e.g. Patient/123), which establishes both the context and context value for the evaluation.",
    "type" : "string",
    "searchType" : "reference"
  },
  {
    "name" : "expression",
    "use" : "in",
    "min" : 1,
    "max" : "1",
    "documentation" : "Expression to be evaluated. Note that this is an expression of CQL, not the text of a library with definition statements.",
    "type" : "string"
  },
  {
    "name" : "parameters",
    "use" : "in",
    "min" : 0,
    "max" : "1",
    "documentation" : "Any input parameters for the expression. The Parameters resource provided in this input **SHALL** conform to the [CQLParameters](StructureDefinition-cql-parameters.html) profile. Parameters defined in this input will be made available by name to the CQL expression. Parameter types are mapped to CQL as specified in the Using CQL section of this implementation guide. If a parameter appears more than once in the input Parameters resource, it is represented with a List in the input CQL. If a parameter has parts, it is represented as a Tuple in the input CQL. Note that parameters may be arbitrarily nested, for example, a list of tuples, or tuples that have list or interval valued elements.",
    "type" : "Parameters"
  },
  {
    "name" : "library",
    "use" : "in",
    "min" : 0,
    "max" : "*",
    "documentation" : "A library to be included. The library is resolved by url and made available by name within the expression to be evaluated.",
    "part" : [{
      "name" : "url",
      "use" : "in",
      "min" : 1,
      "max" : "1",
      "documentation" : "The canonical url (with optional version) of the library to be included",
      "type" : "canonical"
    },
    {
      "name" : "name",
      "use" : "in",
      "min" : 0,
      "max" : "1",
      "documentation" : "The name of the library to be used to reference the library within the CQL expression. If no name is provided, the name of the library will be used",
      "type" : "string"
    }]
  },
  {
    "name" : "useServerData",
    "use" : "in",
    "min" : 0,
    "max" : "1",
    "documentation" : "Whether to use data from the server performing the evaluation. If this parameter is true (the default), then the operation will use data first from any bundles provided as parameters (through the data and prefetch parameters), second data from the server performing the operation, and third, data from the dataEndpoint parameter (if provided). If this parameter is false, the operation will use data first from the bundles provided in the data or prefetch parameters, and second from the dataEndpoint parameter (if provided).",
    "type" : "boolean"
  },
  {
    "name" : "data",
    "use" : "in",
    "min" : 0,
    "max" : "1",
    "documentation" : "Data to be made available to the library evaluation. This parameter is exclusive with the prefetchData parameter (i.e. either provide all data as a single bundle, or provide data using multiple bundles with prefetch descriptions).",
    "type" : "Bundle"
  },
  {
    "name" : "prefetchData",
    "use" : "in",
    "min" : 0,
    "max" : "*",
    "documentation" : "Data to be made available to the library evaluation, organized as prefetch response bundles. Each prefetchData parameter specifies either the name of the prefetchKey it is satisfying, a DataRequirement describing the prefetch, or both.",
    "part" : [{
      "name" : "key",
      "use" : "in",
      "min" : 0,
      "max" : "1",
      "documentation" : "The key of the prefetch item. When using this operation as part of a CDS Hooks implementation, this SHALL be the name of a prefetch item in a CDS Hooks discovery response. Prefetch data SHALL be made available to retrieve statements in the CQL and SHOULD NOT be provided as the value of any CQL parameters in the library being evaluated to avoid confusion between context parameters and retrieve data.",
      "type" : "string"
    },
    {
      "name" : "descriptor",
      "use" : "in",
      "min" : 0,
      "max" : "1",
      "documentation" : "A DataRequirement describing the content of the prefetch item.",
      "type" : "DataRequirement"
    },
    {
      "name" : "data",
      "use" : "in",
      "min" : 0,
      "max" : "1",
      "documentation" : "The prefetch data as a Bundle. If this part is missing, it indicates there is no data associated with this prefetch item.",
      "type" : "Bundle"
    }]
  },
  {
    "name" : "dataEndpoint",
    "use" : "in",
    "min" : 0,
    "max" : "1",
    "documentation" : "An endpoint to use to access data referenced by retrieve operations in the library. If provided, this endpoint is used after the data or prefetchData bundles, and the server, if the useServerData parameter is true.",
    "type" : "Endpoint"
  },
  {
    "name" : "contentEndpoint",
    "use" : "in",
    "min" : 0,
    "max" : "1",
    "documentation" : "**DEPRECATED: Use the artifactEndpointConfiguration parameter instead.** An endpoint to use to access content (i.e. libraries) referenced by the library. If no content endpoint is supplied, the evaluation will attempt to retrieve content from the server on which the operation is being performed.",
    "type" : "Endpoint"
  },
  {
    "name" : "terminologyEndpoint",
    "use" : "in",
    "min" : 0,
    "max" : "1",
    "documentation" : "**DEPRECATED: Use the artifactEndpointConfiguration parameter instead.** An endpoint to use to access terminology (i.e. valuesets, codesystems, and membership testing) referenced by the library. If no terminology endpoint is supplied, the evaluation will attempt to use the server on which the operation is being performed as the terminology server.",
    "type" : "Endpoint"
  },
  {
    "name" : "artifactEndpointConfiguration",
    "use" : "in",
    "min" : 0,
    "max" : "*",
    "documentation" : "Configuration information to resolve canonical artifacts\n* `artifactRoute`: An optional route used to determine whether this endpoint is expected to be able to resolve artifacts that match the route (i.e. start with the route, up to and including the entire url)\n* `endpointUri`: The URI of the endpoint, exclusive with the `endpoint` parameter\n* `endpoint`: An Endpoint resource describing the endpoint, exclusive with the `endpointUri` parameter\n\n**Processing semantics**:\n\nCreate a canonical-like reference (e.g.\n`{canonical.url}|{canonical.version}` or similar extensions for non-canonical artifacts).\n\n* Given a single `artifactEndpointConfiguration`\n  * When `artifactRoute` is present\n    * And canonical or artifact reference *starts with* `artifactRoute`\n    * Then attempt to resolve with `endpointUri` or `endpoint`\n  * When `artifactRoute` is not present\n    * Then attempt to resolve with `endpointUri` or `endpoint`\n* Given multiple `artifactEndpointConfiguration`s\n  * Then rank order each configuration (see below)\n  * And attempt to resolve with `endpointUri` or `endpoint` in order until resolved\n\nRank each `artifactEndpointConfiguration` such that:\n* if `artifactRoute` is present *and* canonical or artifact reference *starts with* `artifactRoute`: rank based on number of matching characters \n* if `artifactRoute` is *not* present: include but rank lower\n\nNOTE: For evenly ranked `artifactEndpointConfiguration`s, order as defined in the\nOperationDefinition.",
    "part" : [{
      "name" : "artifactRoute",
      "use" : "in",
      "min" : 0,
      "max" : "1",
      "type" : "uri"
    },
    {
      "name" : "endpointUri",
      "use" : "in",
      "min" : 0,
      "max" : "1",
      "type" : "uri"
    },
    {
      "name" : "endpoint",
      "use" : "in",
      "min" : 0,
      "max" : "1",
      "type" : "Endpoint"
    }]
  },
  {
    "name" : "timestamp",
    "use" : "in",
    "min" : 0,
    "max" : "1",
    "documentation" : "The timestamp of the evaluation request.",
    "type" : "dateTime"
  },
  {
    "name" : "return",
    "use" : "out",
    "min" : 1,
    "max" : "*",
    "documentation" : "The result of evaluating the given expression, returned as a FHIR Type following the mapping from [CQL to FHIR](conformance.html#fhir-type-mapping) types. If the result is a list, the parameter will be repeated for each element in the list, with the special case that an empty list is represented with a parameter with a cqf-cqlType extension indicating the type of the result (e.g. List<Integer>) and the cqf-isEmptyList extension\n\nBecause the cardinality of the return parameter is 1..*, the result of the $cql evaluate will always be a Parameters resource. In addition, the resulting Parameters resource **SHALL** conform to the [CQLParameters](StructureDefinition-cql-parameters.html) profile.",
    "type" : "Resource"
  },
  {
    "name" : "_messages",
    "use" : "out",
    "min" : 0,
    "max" : "1",
    "documentation" : "An OperationOutcome that contains any information, warning, and/or error messages that were generated while evaluating the CQL expression.\n\nOperation processing often generates information, warning, or error messages that don't necessarily stop processing (and so don't result in an OperationOutcome as the overall result of the operation) but still need to be communicated as part of the result. This parameter allows for these messages to be included as a reference to an OperationOutcome resource.",
    "type" : "OperationOutcome"
  }]
}

```
