You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/normalizeCqlExecution.ts
+59-4Lines changed: 59 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,72 @@
1
-
/**
2
-
* This is a stub description for now.
3
-
*/
4
1
import{Uri,window}from'vscode';
5
2
import{buildParameters}from'./buildParameters';
6
3
import{executeCQL}from'./executeCql';
7
4
8
5
/**
9
-
* Normalizes the execution of CQL based on the type of operation ('file' or 'expression').
6
+
* Normalizes the execution of CQL operations based on the type of operation ('file' or 'expression').
7
+
*
8
+
* This function serves as a **Gatekeeper** by validating the workspace environment and **Normalizing** the data
9
+
* required for execution. It takes VS Code-specific details, determines the type of operation to be executed
10
+
* (such as [$cql](https://build.fhir.org/ig/HL7/cql-ig/OperationDefinition-cql-cql.html), [$evaluate-measure](https://hl7.org/fhir/R4/measure-operation-evaluate-measure.html), [$apply](https://hl7.org/fhir/R4/plandefinition-operation-apply.html) for PlanDefinitions, or [$evaluate](https://build.fhir.org/ig/HL7/cql-ig/OperationDefinition-cql-library-evaluate.html) for Libraries), and standardizes
11
+
* this data into strings or URIs. These are then passed on to {@link buildParameters} for the construction of the
12
+
* necessary execution parameters, which are finally handed off to {@link executeCQL} to perform the execution.
13
+
*
14
+
* **Purpose:**
15
+
*
16
+
* - **Gatekeeper**: Validates the current state, ensuring the correct file type (CQL) and operation type (file or expression).
17
+
* - **Normalizer**: Takes workspace-specific details and standardizes them into a format suitable for execution.
18
+
* - **Executor**: Delegates the actual execution to the appropriate functions after normalizing the input data.
19
+
*
20
+
* **Quick Examples:**
21
+
*
22
+
* - **Executing a Full CQL File**:
23
+
* ```typescript
24
+
* const uri = URI.parse("file:///Users/developer/vscode-project/input/cql/my-library.cql");
25
+
* await normalizeCqlExecution(uri, 'file');
26
+
* // Executes the entire CQL file specified by the URI.
27
+
* ```
28
+
*
29
+
* - **Executing a Single CQL Expression**:
30
+
* ```typescript
31
+
* const uri = URI.parse("file:///Users/developer/vscode-project/input/cql/my-library.cql");
32
+
* await normalizeCqlExecution(uri, 'expression');
33
+
* // Executes a single expression based on the current cursor position in the active editor.
34
+
* ```
35
+
*
36
+
* **Dependencies:**
37
+
*
38
+
* - **Active Text Editor**: The function depends on the active text editor being open with the CQL file.
39
+
* - **CQL File Requirement**: The function currently only supports CQL files. In the future, support for Measure, PlanDefinition, and Questionnaire files may be added.
40
+
* - **Helper Functions**:
41
+
* - **`{@link buildParameters}(uri, expression)`**: Collects all parameters required for execution.
42
+
* - **`{@link executeCQL}(operationArgs)`**: Handles the actual execution of the CQL.
43
+
*
44
+
* **Considerations and Limitations:**
45
+
*
46
+
* - **Expression Execution**:
47
+
* - The function relies on the presence of a valid CQL `define` statement on the current cursor line when executing a single expression.
48
+
* - If no valid definition is found, an error message is displayed, and execution is halted.
49
+
*
50
+
* - **File Type Limitation**:
51
+
* - Currently limited to `.cql` files. Future enhancements may include support for [Measure](https://hl7.org/fhir/R4/measure.html), [PlanDefinition](https://hl7.org/fhir/R4/plandefinition.html), and [Questionnaire](https://hl7.org/fhir/R4/questionnaire.html) files.
52
+
*
53
+
* **Future Enhancements:**
54
+
*
55
+
* - **Measurement Period**: Incorporate support for Measure files.
56
+
* - **PlanDefinition and Questionnaire Support**: Expand the function to handle these additional FHIR resources.
57
+
* - **Flexible Contexts**: Enable the function to handle more complex execution contexts beyond CQL, such as PlanDefinitions or other FHIR artifacts.
58
+
*
59
+
* **Error Handling**:
60
+
*
61
+
* - **No Active Editor**: Displays a message if no active text editor is found.
62
+
* - **Invalid File Type**: Displays a message if the current file is not a CQL file.
63
+
* - **Missing Definition**: Displays an error if no valid CQL definition is found on the selected line during expression execution.
10
64
*
11
65
* @param {Uri} uri - The URI of the file or resource.
12
66
* @param {'file' | 'expression'} type - The type of operation: 'file' for full file execution, 'expression' for single expression execution.
13
67
* @returns {Promise<void>} A promise that resolves when the execution is complete.
0 commit comments