Skip to content

Commit 3edd395

Browse files
Merge branch 'feature/LF-3354/add-support-for-fhirclient' into 'master'
Add support for fhirclient See merge request lfor/fhirpath.js!44
2 parents a198b96 + 6693c4f commit 3edd395

15 files changed

Lines changed: 818 additions & 431 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
This log documents significant changes for each release. This project follows
44
[Semantic Versioning](http://semver.org/).
55

6+
## [4.6.0] - 2025-08-21
7+
### Added
8+
- the ability to pass HTTP headers in requests to FHIR servers, which can be
9+
used for authorization obtained via a third-party library (see fhirclient
10+
example in docs/auth.md).
11+
612
## [4.5.1] - 2025-07-09
713
### Added
814
- tests for the R5 model.

README.md

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,21 @@ where:
9393
currently supported %terminologies APIs.
9494
* options.fhirServerUrl - a URL pointing to a FHIR RESTful API server that
9595
is used to `resolve()` resources.
96-
* options.signal - an AbortSignal object that allows you to abort the
97-
asynchronous FHIRPath expression evaluation.
96+
* options.signal - an AbortSignal object that allows you to [abort the
97+
asynchronous FHIRPath expression evaluation](docs/abort.md).
98+
* options.httpHeaders - an object with HTTP headers that will be used
99+
when making requests to FHIR servers (e.g. for terminology servers).
100+
The object has the following structure:
101+
```
102+
{
103+
<server base url>: {
104+
<header name>: <header value>,
105+
...
106+
},
107+
...
108+
}
109+
```
110+
See [authentication to FHIR servers](docs/auth.md).
98111
99112
Note: The resource will be modified by this function to add type information.
100113
@@ -186,22 +199,6 @@ const path = fhirpath.compile(
186199
);
187200
```
188201
189-
But passing the `signal` option to compile() whose result is used more than once
190-
will cause abortion problems. If you need to abort the evaluation of the compiled
191-
expression, you should pass the signal option to the function that is returned
192-
by compile():
193-
194-
```js
195-
const path = fhirpath.compile(
196-
expression, model, {async: true}
197-
);
198-
const abortController = new AbortController();
199-
const signal = abortController.signal;
200-
let res = path(resource, environment, {signal});
201-
// Abort the evaluation of the compiled expression
202-
abortController.abort();
203-
```
204-
205202
If at some point you decide to convert all values which have internal types to
206203
standard JavaScript types you can use the special function "resolveInternalTypes":
207204

demo/package-lock.json

Lines changed: 66 additions & 104 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/abort.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Aborting the asynchronous FHIRPath expression evaluation
2+
3+
If you are using the `async` option, you may also pass in the `signal` option
4+
to allow for aborting the asynchronous evaluation of the FHIRPath expression.
5+
Note that passing the `signal` option to `compile()` whose result is used more
6+
than once is not allowed. If you need to abort the evaluation of the compiled
7+
expression, you should pass the signal option to the function that is returned
8+
by compile():
9+
10+
```js
11+
const evalExpr = fhirpath.compile(
12+
expression, model, {async: true}
13+
);
14+
const abortController = new AbortController();
15+
const signal = abortController.signal;
16+
let res = evalExpr(resource, environment, {signal});
17+
// Abort the evaluation of the compiled expression
18+
abortController.abort();
19+
```

docs/auth.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Authentication to FHIR servers
2+
3+
You may want to use third-party authentication to access FHIR servers
4+
(e.g. for terminology servers). In this case, you can pass in the `httpHeaders`
5+
option.
6+
7+
For example, if in your application you use
8+
[fhirclient npm-package](https://www.npmjs.com/package/fhirclient),
9+
which sets the `Authorization` header for requests to the FHIR server,
10+
you can pass in the same header to fhirpath.js so that it can
11+
access the FHIR server with the same authorization:
12+
```js
13+
FHIR.oauth2.ready().then(client => {
14+
const res = fhirpath.evaluate(
15+
{"resourceType": "QuestionnaireResponse", ...},
16+
'%context.repeat(item).answer.weight().sum()',
17+
{},
18+
fhirpath_r4_model,
19+
{
20+
async: true,
21+
terminologyUrl: 'https://some-server',
22+
httpHeaders: {
23+
'https://some-server': {
24+
// Use the same Authorization header as fhirClient
25+
Authorization: client.getAuthorizationHeader()
26+
}
27+
}
28+
}
29+
);
30+
});
31+
```

0 commit comments

Comments
 (0)