@haste-health/operation-outcomes 0.127.1 → 0.127.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1 +1,60 @@
|
|
|
1
|
-
# operation-outcomes
|
|
1
|
+
# @haste-health/operation-outcomes
|
|
2
|
+
|
|
3
|
+
Builds FHIR [OperationOutcome](https://hl7.org/fhir/R4/operationoutcome.html) resources and throws them as a typed JavaScript error. The Haste Health TypeScript packages that can fail with a FHIR-shaped error ([`@haste-health/client`](https://www.npmjs.com/package/@haste-health/client), [`@haste-health/fhir-validation`](https://www.npmjs.com/package/@haste-health/fhir-validation), [`@haste-health/operation-execution`](https://www.npmjs.com/package/@haste-health/operation-execution), [`@haste-health/fhir-pointer`](https://www.npmjs.com/package/@haste-health/fhir-pointer), [`@haste-health/hl7v2-parsing`](https://www.npmjs.com/package/@haste-health/hl7v2-parsing) and [`@haste-health/testscript-runner`](https://www.npmjs.com/package/@haste-health/testscript-runner)) all report problems through it, so one `catch` handles them all.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @haste-health/operation-outcomes
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import {
|
|
15
|
+
OperationError,
|
|
16
|
+
isOperationError,
|
|
17
|
+
issueToStatusCode,
|
|
18
|
+
outcomeError,
|
|
19
|
+
} from "@haste-health/operation-outcomes";
|
|
20
|
+
|
|
21
|
+
function readPatient(id: string) {
|
|
22
|
+
if (!id) {
|
|
23
|
+
throw new OperationError(
|
|
24
|
+
outcomeError("not-found", `Patient '${id}' not found`),
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
readPatient("");
|
|
31
|
+
} catch (e) {
|
|
32
|
+
if (isOperationError(e)) {
|
|
33
|
+
const status = issueToStatusCode(e.outcome.issue[0]); // 404
|
|
34
|
+
respond(status, e.outcome); // the OperationOutcome resource
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## API
|
|
40
|
+
|
|
41
|
+
| Export | Purpose |
|
|
42
|
+
| --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
43
|
+
| `OperationError` | `Error` subclass carrying an `OperationOutcome`, read back through `.outcome` |
|
|
44
|
+
| `isOperationError(e)` | Type guard for `catch` blocks |
|
|
45
|
+
| `issue(severity, code, diagnostics, expression?)` | One `OperationOutcome.issue` entry |
|
|
46
|
+
| `issueError`, `issueFatal`, `issueWarning`, `issueInfo` | `issue` with the severity fixed |
|
|
47
|
+
| `outcome(issues)` | Wraps issues in an `OperationOutcome` resource |
|
|
48
|
+
| `outcomeError`, `outcomeFatal`, `outcomeWarning`, `outcomeInfo` | A single-issue `OperationOutcome` in one call |
|
|
49
|
+
| `issueToStatusCode(issue)` | HTTP status for an issue: `fatal` 500; `error` 400, or 404 for `not-found`, 401 for `login`, 403 for `forbidden`; `warning` and `information` 200 |
|
|
50
|
+
|
|
51
|
+
`code` takes the FHIR [IssueType](https://hl7.org/fhir/R4/valueset-issue-type.html) codes (`invalid`, `required`, `not-found`, `forbidden`, `not-supported`, `conflict`, ...), and `expression` is the list of FHIRPath or JSON pointer locations the issue refers to.
|
|
52
|
+
|
|
53
|
+
## Links
|
|
54
|
+
|
|
55
|
+
- [API reference](https://typescript.haste.health/modules/_haste-health_operation-outcomes.html)
|
|
56
|
+
- [Source](https://github.com/HasteHealth/HasteHealth/tree/main/frontend/packages/operation-outcomes)
|
|
57
|
+
- [TypeScript SDK overview](https://haste.health/docs/api/sdks/typescript)
|
|
58
|
+
- Rust equivalent: [haste-fhir-operation-error](https://crates.io/crates/haste-fhir-operation-error)
|
|
59
|
+
|
|
60
|
+
Part of [Haste Health](https://haste.health), licensed under [Apache-2.0](https://github.com/HasteHealth/HasteHealth/blob/main/LICENSE).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haste-health/operation-outcomes",
|
|
3
|
-
"version": "0.127.
|
|
3
|
+
"version": "0.127.2",
|
|
4
4
|
"homepage": "https://haste.health",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"jest": "^29.7.0",
|
|
17
17
|
"ts-jest": "^29.4.11",
|
|
18
18
|
"typescript": "6.0.3",
|
|
19
|
-
"@haste-health/fhir-types": "^0.127.
|
|
19
|
+
"@haste-health/fhir-types": "^0.127.2"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
22
|
"lib/**",
|