Skip to content

Commit 23a19b2

Browse files
committed
Remove build:browser from main build and convert examples to mini projects
1 parent 5865226 commit 23a19b2

37 files changed

Lines changed: 2180 additions & 25918 deletions

.github/pull_request_template.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ For items that are not-applicable, mark "N/A" and ✔.
1111
- [ ] Code coverage has not gone down and all code touched or added is covered.
1212
- [ ] Code passes lint and prettier (hint: use `npm run check` to run tests, lint, and prettier)
1313
- [ ] All dependent libraries are appropriately updated or have a corresponding PR related to this change
14-
- [ ] `cql4browsers.js` built with `npm run build:browser` if source changed.
15-
1614
**Reviewer:**
1715

1816
Name:

.github/workflows/ci-workflow.yml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@ jobs:
1212
with:
1313
node-version: 24.x
1414
- run: npm audit --omit=dev
15-
cql4browsers:
16-
name: Check cql4browsers
17-
runs-on: ubuntu-latest
18-
steps:
19-
- uses: actions/checkout@v6
20-
- uses: actions/setup-node@v6
21-
with:
22-
node-version: 24.x
23-
- run: ./bin/validate_cql4browsers.sh
2415
lint:
2516
name: Check lint and prettier
2617
runs-on: ubuntu-latest
@@ -73,3 +64,24 @@ jobs:
7364
working-directory: test-server
7465
- run: npm run check
7566
working-directory: test-server
67+
examples:
68+
name: Check examples
69+
runs-on: ubuntu-latest
70+
steps:
71+
- uses: actions/checkout@v6
72+
- uses: actions/setup-node@v6
73+
with:
74+
node-version: 24.x
75+
- run: npm ci
76+
- run: npm ci
77+
working-directory: examples/browser
78+
- run: npm test
79+
working-directory: examples/browser
80+
- run: npm ci
81+
working-directory: examples/node
82+
- run: npm test
83+
working-directory: examples/node
84+
- run: npm ci
85+
working-directory: examples/typescript
86+
- run: npm test
87+
working-directory: examples/typescript

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
lib
22
lib-test
3+
dist
34
node_modules
45
.DS_Store
56
.nyc_output

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
/test
77
/test-server
88
/CQL_Execution_Features.xlsx
9+
/examples

.oxlintrc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"ignorePatterns": [
1010
"**/lib",
1111
"**/lib-test",
12-
"test-server/**",
13-
"examples/browser/cql4browsers.js"
12+
"**/dist",
13+
"test-server/**"
1414
],
1515
"rules": {
1616
"no-loss-of-precision": "off",

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
lib
22
lib-test
3+
dist
34
node_modules
45
.nyc_output
56
.vscode
67
coverage
7-
cql4browsers.js
88
# the following uses its own prettier config
99
test-server
1010
# the following are generated by the test generator

README.md

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ To use this project, you should perform the following steps:
6969

7070
Please note that while the CQL Execution library supports many aspects of CQL, it does not support
7171
everything 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

7474
There are several steps involved to execute CQL. First, you must create a JSON representation of
7575
the 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-
8282
4. `./gradlew :cql-to-elm-cli:installDist`
8383
5. `./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

9089
In the rest of the examples, we'll assume an `age.cql` file with the following contents. This
9190
follows the example already in the "examples" folder (but of course you can use your own CQL):
@@ -110,12 +109,11 @@ define InDemographic:
110109
Next, 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"
112111
data 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

120118
const lib = new cql.Library(measure);
121119
const 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
151149
also 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

160160
If 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

170166
Next, 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"
172168
data 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');
178173
const measure = require('./age.json');
179174

180175
const 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

196191
executor
@@ -207,10 +202,12 @@ executor
207202
The 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

216213
If 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

353350
See [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-
```

bin/validate_cql4browsers.sh

Lines changed: 0 additions & 29 deletions
This file was deleted.

examples/browser/README.md

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1-
This example demonstrates a static html page running a _browserified_ version of the
2-
CQL execution engine. It currently only supports CQL using the System datatypes. It
3-
does not support other data models or execution on patients.
1+
This mini-project demonstrates the CQL execution engine in a static browser page. It
2+
uses the same `AgeAtMP` CQL and example patients as the Node.js and TypeScript
3+
mini-projects. It depends on the repository's local `cql-execution` package and owns
4+
its browser build tooling and generated output. The bundle assigns the example patients
5+
to `window.patients`, which is used by both the execution code and the page's patient
6+
table.
47

5-
The browserified code is checked into source control, but if you need to update it,
6-
you can follow these steps:
8+
From the repository root, install and build `cql-execution`:
79

8-
1. Install [Node.js](http://nodejs.org/) (Note: `npm` version `6.x.x` recommended)
9-
2. Execute the following from the _cql-execution_ directory:
10-
1. `npm install`
11-
2. `npm run build:all`
10+
```sh
11+
npm install
12+
```
13+
14+
Then install and build the browser example:
15+
16+
```sh
17+
cd examples/browser
18+
npm install
19+
npm run build
20+
```
21+
22+
Open `index.html` in a browser to run the example. For development, `npm run dev`
23+
builds the bundle, serves this directory, and rebuilds when its inputs change. Run
24+
`npm test` to build the bundle and verify both patients' `InDemographic` results.

examples/browser/age.cql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
library AgeAtMP version '1'
2+
3+
// NOTE: This example uses a custom data model that is very simplistic and suitable only for
4+
// demonstration and testing purposes. Real-world CQL should use a more appropriate model.
5+
using Simple version '1.0.0'
6+
7+
parameter MeasurementPeriod default Interval[DateTime(2013, 1, 1, 0, 0, 0, 0), DateTime(2014, 1, 1, 0, 0, 0, 0))
8+
9+
context Patient
10+
11+
define InDemographic:
12+
AgeInYearsAt(start of MeasurementPeriod) >= 2 and AgeInYearsAt(start of MeasurementPeriod) < 18

0 commit comments

Comments
 (0)