-
Notifications
You must be signed in to change notification settings - Fork 37
CQL Test Server for CQL Tests Runner #360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cmoesel
wants to merge
9
commits into
master
Choose a base branch
from
test-server
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f4bf717
Initial commit of the test server (supporting $cql)
cmoesel 28a76c9
test-server: use built cql-execution code from lib
cmoesel ab634d4
Add test-server README and update eslint/prettier
cmoesel a9be766
Fix tsconfig issues
cmoesel 9ed891f
Add support to test-server for testing CQL Long as a BigInt
cmoesel b5f0daa
Apply suggestions from code review
cmoesel f92c40d
Address PR review comments
cmoesel 6c30420
Remove cql-exec-fhir from test-server
cmoesel 5aef2fd
Update tsconfig
cmoesel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| lib-cov | ||
| *.seed | ||
| *.log | ||
| *.csv | ||
| *.dat | ||
| *.out | ||
| *.pid | ||
| *.gz | ||
| *.swp | ||
|
|
||
| pids | ||
| logs | ||
| results | ||
| tmp | ||
|
|
||
| # API keys and secrets | ||
| .env | ||
|
|
||
| # Dependency directory | ||
| node_modules | ||
|
|
||
| # Editors | ||
| .vscode | ||
| .idea | ||
| *.iml | ||
|
|
||
| # OS metadata | ||
| .DS_Store | ||
| Thumbs.db | ||
|
|
||
| # Ignore built ts files | ||
| dist/**/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "trailingComma": "none", | ||
| "arrowParens": "avoid", | ||
| "endOfLine": "auto", | ||
| "printWidth": 100, | ||
| "tabWidth": 2, | ||
| "singleQuote": true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| # CQL Test Server | ||
|
|
||
| A barebones implementation of the FHIR [$cql](https://build.fhir.org/ig/HL7/cql-ig/en/OperationDefinition-cql-cql.html) operation that evaluates CQL expressions using the CQL execution engine and uses the [CQL FHIR Type Mapping](https://build.fhir.org/ig/HL7/cql-ig/en/conformance.html#fhir-type-mapping) to return results as a FHIR `Parameters` resource. This server is intended to be used as a target for the [cql-tests-runner](https://github.com/cqframework/cql-tests-runner) and is tuned specifically for that use case. | ||
|
|
||
| ## Endpoint | ||
|
|
||
| - POST `/fhir/$cql` | ||
| - Example request: | ||
| ```json | ||
| { | ||
| "resourceType": "Parameters", | ||
| "parameter": [{ "name": "expression", "valueString": "1 + 2" }] | ||
| } | ||
| ``` | ||
| - Example response: | ||
| ```json | ||
| { | ||
| "resourceType": "Parameters", | ||
| "parameter": [{ | ||
| "extension": [{ | ||
| "url": "http://hl7.org/fhir/StructureDefinition/cqf-cqlType", | ||
| "valueString": "System.Integer" | ||
| }], | ||
| "name": "return", | ||
| "valueInteger": 3 | ||
| }] | ||
| } | ||
| ``` | ||
| - Errors: | ||
| - HTTP 400 if the `expression` parameter is missing or empty | ||
| - HTTP 500 if there is an unexpected / unrecoverable server-side error | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| This project uses Node.js. It has been tested using Node 24 but should work with any recent LTS version. | ||
|
|
||
| ## Developing Scripts | ||
|
|
||
| The `package.json` file defines scripts to support development of the test-server source code. These include: | ||
|
|
||
| - `npm run lint`: run eslint against the test-server source code | ||
| - `npm run lint:fix`: fix eslint errors (as possible) | ||
| - `npm run prettier`: run prettier against the test-server source code | ||
| - `npm run prettier:fix`: fix prettier violations (as possible) | ||
| - `npm test`: run the unit tests | ||
|
|
||
| Scripts for building and running the server are documented below. | ||
|
|
||
| ## Start The Server | ||
|
|
||
| From this directory: | ||
|
|
||
| ### Install dependencies: | ||
|
|
||
| ```sh | ||
| npm install | ||
| ``` | ||
|
|
||
| ### Development mode: | ||
|
|
||
| ```sh | ||
| npm run dev | ||
| ``` | ||
|
|
||
| The development mode builds the `cql-execution` source (to ensure it uses the latest changes) before running the server. It watches for changes to the `test-server` source and hot-reloads as necessary. By default, it uses the javascript CQL-to-ELM translator and listens on `http://localhost:8000`. | ||
|
|
||
| _NOTE: The watch mode will NOT detect or hot-reload changes in the `cql-execution` source. You must stop and restart the `test-server` to pick up changes in the `cql-execution` source._ | ||
|
elsaperelli marked this conversation as resolved.
|
||
|
|
||
| # Production mode: | ||
|
|
||
| ```sh | ||
| npm run build | ||
| npm start | ||
| ``` | ||
|
|
||
| The production mode builds the `cql-execution` source and `test-server` source then runs the server _without_ watching for changes. By default, it uses the javascript CQL-to-ELM translator and listens on `http://localhost:8000`. | ||
|
|
||
| ### Configuration | ||
|
|
||
| - `PORT` (optional): Port to bind. Defaults to `8000`. | ||
| - `USE_TRANSLATION_SERVICE` (optional, default: `false`): If `true`, the server will use a local [CQL Translation Service](https://github.com/cqframework/cql-translation-service) for CQL-to-ELM. In this case, the CQL Translation service must be running and available at `http://localhost:8080`. If `false`, the server will use the javascript CQL-to-ELM module to compile CQL. | ||
|
|
||
| You can export these variables before running the server or place them in a `.env` file: | ||
|
|
||
| ```ini | ||
| PORT=8000 | ||
| USE_TRANSLATION_SERVICE=false | ||
| ``` | ||
|
|
||
| ## Quick Test With curl | ||
|
|
||
| ```sh | ||
| curl -X POST http://localhost:8000/fhir/\$cql \ | ||
|
elsaperelli marked this conversation as resolved.
|
||
| -H "Content-Type: application/fhir+json" \ | ||
| -d '{ | ||
| "resourceType": "Parameters", | ||
| "parameter": [ | ||
| { "name": "expression", "valueString": "1 + 2" } | ||
| ] | ||
| }' | ||
| ``` | ||
|
|
||
| ## Use With cql-tests-runner | ||
|
|
||
| This server is designed to be a `$cql` target for the [cql-tests-runner](https://github.com/cqframework/cql-tests-runner). To execute the test-runner against this server: | ||
|
|
||
| 1. Download or clone the `cql-tests-runner` repository. | ||
|
|
||
| 2. Start this test-server (see above), e.g. at `http://localhost:8000`. | ||
|
|
||
| 3. In cql-tests-runner folder, create or edit a [test runner configuration](https://github.com/cqframework/cql-tests-runner?tab=readme-ov-file#configuration-settings) that points to the test-server endpoint. If you are using port 8000, you may choose to use the existing [conf/cql-execution-local.json](https://github.com/cqframework/cql-tests-runner/blob/main/conf/cql-execution-local.json) file. | ||
|
|
||
| 4. Run the tests from the cql-tests-runner folder: | ||
|
|
||
| ```sh | ||
| npm install | ||
| git submodule update --init --recursive | ||
| npx tsx src/bin/cql-tests.ts run-tests conf/cql-execution-local.json ./results | ||
| ``` | ||
|
|
||
| The runner will POST each test expression to `http://localhost:8000/fhir/$cql` and expect FHIR `Parameters` responses per the mapping. The test-server logs each incoming expression, the raw result, and the result mapped to `FHIR Parameters`. When the run is done, you can find the results in the cql-tests-runner folder's `results` sub-folder. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { defineConfig, globalIgnores } from 'eslint/config'; | ||
| import globals from 'globals'; | ||
| import tsParser from '@typescript-eslint/parser'; | ||
| import path from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import js from '@eslint/js'; | ||
| import { FlatCompat } from '@eslint/eslintrc'; | ||
|
|
||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = path.dirname(__filename); | ||
| const compat = new FlatCompat({ | ||
| baseDirectory: __dirname, | ||
| recommendedConfig: js.configs.recommended, | ||
| allConfig: js.configs.all | ||
| }); | ||
|
|
||
| export default defineConfig([ | ||
| globalIgnores(['dist', 'node_modules']), | ||
| { | ||
| extends: compat.extends('plugin:@typescript-eslint/recommended', 'prettier'), | ||
| languageOptions: { | ||
| globals: { | ||
| ...globals.node, | ||
| ...globals.mocha | ||
| }, | ||
| parser: tsParser, | ||
| ecmaVersion: 6, | ||
| sourceType: 'module', | ||
| parserOptions: { | ||
| ecmaFeatures: { experimentalObjectRestSpread: true } | ||
| } | ||
| }, | ||
| rules: { | ||
| '@typescript-eslint/no-require-imports': 'off', | ||
| '@typescript-eslint/no-explicit-any': 'off', | ||
| 'no-unused-vars': 'off', // redundant to rule below | ||
| '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }], | ||
| indent: ['error', 2, { SwitchCase: 1 }], | ||
| 'no-console': ['warn', { allow: ['warn', 'error'] }], | ||
| 'no-loss-of-precision': 'off', | ||
| quotes: ['error', 'single', { allowTemplateLiterals: true, avoidEscape: true }], | ||
| semi: ['error', 'always'], | ||
| curly: 'error' | ||
| } | ||
| }, | ||
| { | ||
| files: ['test/**/*.{js,ts}', 'examples/**/*.js', 'bin/**/*.js'], | ||
| rules: { | ||
| '@typescript-eslint/no-var-requires': 'off' | ||
| } | ||
| } | ||
| ]); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.