@@ -69,7 +69,7 @@ To use this project, you should perform the following steps:
6969
7070Please note that while the CQL Execution library supports many aspects of CQL, it does not support
7171everything in the CQL specification. You should check to see what is implemented (by referencing
72- the unit tests) before expecting it to work! For a working example , see ` examples ` .
72+ the unit tests) before expecting it to work! For working examples , see the ` examples ` directory .
7373
7474There are several steps involved to execute CQL. First, you must create a JSON representation of
7575the ELM. For the easiest integration, we will generate a JSON file using cql-to-elm:
@@ -82,10 +82,9 @@ the ELM. For the easiest integration, we will generate a JSON file using cql-to-
82824 . ` ./gradlew :cql-to-elm-cli:installDist `
83835 . ` ./cql-to-elm-cli/build/install/cql-to-elm-cli/bin/cql-to-elm-cli --format=JSON --input ${path_to_cql} --output ${path_to_cql-execution}/customCQL `
8484
85- The above example puts the example CQL into a subfolder of the ` cql-execution ` project to make the
86- relative paths to ` cql-execution ` libraries easier, but it doesn't _ have_ to go there. If you put
87- it elsewhere, you'll need to modify the examples below so that the ` require ` statements point to
88- the correct location of the ` cql ` export.
85+ This repository contains self-contained Node.js and TypeScript mini-projects under ` examples ` .
86+ They depend on the repository's local ` cql-execution ` package; projects outside this repository
87+ should install ` cql-execution ` from npm instead.
8988
9089In the rest of the examples, we'll assume an ` age.cql ` file with the following contents. This
9190follows the example already in the "examples" folder (but of course you can use your own CQL):
@@ -110,12 +109,11 @@ define InDemographic:
110109Next, we can create a TypeScript file to execute the above CQL. This file will need to contain (or
111110` import ` ) JSON patient representations for testing as well. Our example CQL uses a "Simple"
112111data model developed only for demonstration and testing purposes. In this model, each patient is
113- represented using a simple JSON object. For ease of use, let's put the file in the ` customCQL `
114- directory:
112+ represented using a simple JSON object.
115113
116114``` typescript
117- import cql from ' ../../src/ cql' ;
118- import * as measure from ' ./age.json' ; // Requires the "resolveJsonModule" compiler option to be "true"
115+ import cql from ' cql-execution ' ;
116+ import measure from ' ./age.json' ; // Requires the "resolveJsonModule" compiler option to be "true"
119117
120118const lib = new cql .Library (measure );
121119const executor = new cql .Executor (lib );
@@ -125,14 +123,14 @@ const psource = new cql.PatientSource([
125123 recordType: ' Patient' ,
126124 name: ' John Smith' ,
127125 gender: ' M' ,
128- birthDate: ' 1980-02-17T06:15 '
126+ birthDate: ' 1980-02-17 '
129127 },
130128 {
131129 id: ' 2' ,
132130 recordType: ' Patient' ,
133131 name: ' Sally Smith' ,
134132 gender: ' F' ,
135- birthDate: ' 2007-08-02T11:47 '
133+ birthDate: ' 2007-08-02 '
136134 }
137135]);
138136
@@ -151,30 +149,27 @@ In the above file, we've assumed the JSON ELM JSON file for the measure is calle
151149also assumed a couple of very simple patients. Let's call the file we just created
152150` exec-age.ts ` .
153151
154- Now we can execute the measure using [ tsx ] ( https://tsx.is/ ) :
152+ The complete TypeScript example has its own dependencies, scripts, and tests. Run it with :
155153
156- ``` bash
157- npx tsx ${path_to_cql-execution} /customCQL/exec-age.ts
154+ ``` bash
155+ cd examples/typescript
156+ npm install
157+ npm start
158158```
159159
160160If all is well, it should print the result object to standard out.
161161
162162## JavaScript Example
163163
164- For usage in regular JavaScript, we can refer to the compiled JavaScript in the ` lib ` directory.
165- Ensure that this JavaScript is present by running ` npm run build ` before continuing on to the example.
166- We will follow the same steps as the above TypeScript example, but our JavaScript code must use ` require `
167- instead of ` import ` , and will load the ` cql-execution ` library from the ` lib ` directory. As before,
168- let's put the file in the ` customCQL ` directory:
164+ For regular JavaScript, we use ` require ` to load the installed ` cql-execution ` package:
169165
170166Next, create a JavaScript file to execute the CQL above. This file will need to contain (or
171167` require ` ) JSON patient representations for testing as well. Our example CQL uses a "Simple"
172168data model developed only for demonstration and testing purposes. In this model, each patient is
173- represented using a simple JSON object. For ease of use, let's put the file in the ` customCQL `
174- directory:
169+ represented using a simple JSON object.
175170
176171``` js
177- const cql = require (' ../lib/ cql' );
172+ const cql = require (' cql-execution ' );
178173const measure = require (' ./age.json' );
179174
180175const lib = new cql.Library (measure);
@@ -184,13 +179,13 @@ const psource = new cql.PatientSource([ {
184179 ' recordType' : ' Patient' ,
185180 ' name' : ' John Smith' ,
186181 ' gender' : ' M' ,
187- ' birthDate' : ' 1980-02-17T06:15 '
182+ ' birthDate' : ' 1980-02-17 '
188183}, {
189184 ' id' : ' 2' ,
190185 ' recordType' : ' Patient' ,
191186 ' name' : ' Sally Smith' ,
192187 ' gender' : ' F' ,
193- ' birthDate' : ' 2007-08-02T11:47 '
188+ ' birthDate' : ' 2007-08-02 '
194189} ]);
195190
196191executor
@@ -207,10 +202,12 @@ executor
207202The above file has the same assumptions as the TypeScript example above. Let's call the file we just created
208203` exec-age.js ` .
209204
210- Now we can execute the measure using Node.js :
205+ The complete Node.js example has its own dependencies, scripts, and tests. Run it with :
211206
212207``` shell
213- node ${path_to_cql-execution} /customCQL/exec-age.js
208+ cd examples/node
209+ npm install
210+ npm start
214211```
215212
216213If all is well, it should print the result object to standard out, and the output should be identical to that of the TypeScript example.
@@ -351,12 +348,3 @@ execute `npm run watch:test-data`.
351348# Using the Test Server and CQL Tests Runner
352349
353350See [ test-server/README.md] ( test-server/README.md ) .
354-
355- # Pull Requests
356-
357- If TypeScript source code is modified, ` cql4browsers.js ` needs to be included in the pull request,
358- otherwise GitHub Actions CI will fail. To generate this file, run:
359-
360- ```
361- npm run build:browser
362- ```
0 commit comments