@haste-health/fhir-validation 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.
Files changed (2) hide show
  1. package/README.md +68 -3
  2. package/package.json +12 -12
package/README.md CHANGED
@@ -1,4 +1,69 @@
1
- # FHIR Validation
1
+ # @haste-health/fhir-validation
2
2
 
3
- Validates FHIR resources based around StructureDefinition.
4
- Supports R4 and R4B.
3
+ Validates FHIR R4 and R4B resources in TypeScript. `validate` checks a value against the base StructureDefinition of its type (element structure, cardinality, primitive formats, required bindings, reference targets) and then against every profile listed in `meta.profile` (cardinality, fixed values, patterns, slicing, type constraints, nested profiles). It returns `OperationOutcome` issues that name the failing element, ready to show in a UI or return as a FHIR `OperationOutcome`.
4
+
5
+ [`@haste-health/operation-execution`](https://www.npmjs.com/package/@haste-health/operation-execution) uses it to validate operation parameters. The Haste Health server validates writes with the Rust equivalent, [haste-fhir-profiling](https://crates.io/crates/haste-fhir-profiling).
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @haste-health/fhir-validation
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import validate from "@haste-health/fhir-validation";
17
+ import type { ValidationCTX } from "@haste-health/fhir-validation/types";
18
+ import { R4 } from "@haste-health/fhir-types/versions";
19
+ import type { uri } from "@haste-health/fhir-types/r4/types";
20
+
21
+ const ctx: ValidationCTX = {
22
+ fhirVersion: R4,
23
+ // Return the resource a canonical URL points at (StructureDefinitions for profiles).
24
+ // Resolve from a FHIR server, or offline from the FHIR packages with @haste-health/artifacts.
25
+ resolveCanonical: async (fhirVersion, type, url) =>
26
+ structureDefinitions.find((sd) => sd.url === url),
27
+ // Optional: check codes with a terminology service, called for elements whose
28
+ // binding strength is "required" with the binding's ValueSet URL and the code.
29
+ validateCode: async (valueSet, code) => true,
30
+ };
31
+
32
+ const issues = await validate(ctx, "Patient" as uri, {
33
+ resourceType: "Patient",
34
+ meta: {
35
+ profile: [
36
+ "http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient",
37
+ ],
38
+ },
39
+ name: [{ family: "Doe" }],
40
+ });
41
+ // [] when valid; otherwise issues such as
42
+ // { severity: "error", code: "required", diagnostics: "...", expression: ["/identifier"] }
43
+ ```
44
+
45
+ ## Entry points
46
+
47
+ | Import | Exports |
48
+ | ------------------------------------------ | -------------------------------------------------------------------------------------------------------- |
49
+ | `@haste-health/fhir-validation` | `validate(ctx, type, value, path?)`: structural validation plus the profiles in `meta.profile` |
50
+ | `@haste-health/fhir-validation/structural` | `validate(ctx, type, value, path?)`: structural validation only, also for data types such as `HumanName` |
51
+ | `@haste-health/fhir-validation/types` | `ValidationCTX`, `ElementLoc` |
52
+
53
+ `type` is the FHIR type name (`Patient`, `Observation`, `HumanName`, ...). The optional `path` is a `@haste-health/fhir-pointer` location used to prefix the issue locations when validating part of a larger document.
54
+
55
+ ## Profile support
56
+
57
+ - Cardinality, `fixed[x]`, `pattern[x]`, and type restrictions on choice elements.
58
+ - Slicing with `value`, `pattern`, `exists` and `type` discriminators; `profile` discriminators are not supported yet. Exercised against the US Core Patient and Blood Pressure profiles in the test suite.
59
+ - Element-level `type.profile` references, resolved through `resolveCanonical` and validated recursively.
60
+ - A profile whose canonical cannot be resolved is skipped rather than reported.
61
+
62
+ ## Links
63
+
64
+ - [API reference](https://typescript.haste.health/modules/_haste-health_fhir-validation.html)
65
+ - [Source](https://github.com/HasteHealth/HasteHealth/tree/main/frontend/packages/fhir-validation)
66
+ - [Profiling and validation guide](https://haste.health/docs/guides/profiling) and the [TypeScript SDK overview](https://haste.health/docs/api/sdks/typescript)
67
+ - Rust equivalent: [haste-fhir-profiling](https://crates.io/crates/haste-fhir-profiling)
68
+
69
+ 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/fhir-validation",
3
- "version": "0.127.1",
3
+ "version": "0.127.2",
4
4
  "homepage": "https://haste.health",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,11 +12,11 @@
12
12
  "types": "lib/structural/index.d.ts",
13
13
  "dependencies": {
14
14
  "jsonpointer": "^5.0.1",
15
- "@haste-health/codegen": "^0.127.1",
16
- "@haste-health/operation-outcomes": "^0.127.1",
17
- "@haste-health/fhir-pointer": "^0.127.1",
18
- "@haste-health/fhirpath": "^0.127.1",
19
- "@haste-health/meta-value": "^0.127.1"
15
+ "@haste-health/codegen": "^0.127.2",
16
+ "@haste-health/fhir-pointer": "^0.127.2",
17
+ "@haste-health/meta-value": "^0.127.2",
18
+ "@haste-health/operation-outcomes": "^0.127.2",
19
+ "@haste-health/fhirpath": "^0.127.2"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@babel/plugin-syntax-import-attributes": "^7.29.7",
@@ -28,15 +28,15 @@
28
28
  "jest": "^29.7.0",
29
29
  "ts-jest": "^29.4.11",
30
30
  "typescript": "6.0.3",
31
- "@haste-health/fhir-types": "^0.127.1",
32
- "@haste-health/artifacts": "^0.127.1",
33
- "@haste-health/haste-health.fhir.r4.core": "^0.127.1",
34
- "@haste-health/hl7.fhir.r4.core": "^0.127.1",
35
- "@haste-health/hl7.fhir.r4.test-data": "^0.127.1"
31
+ "@haste-health/artifacts": "^0.127.2",
32
+ "@haste-health/fhir-types": "^0.127.2",
33
+ "@haste-health/haste-health.fhir.r4.core": "^0.127.2",
34
+ "@haste-health/hl7.fhir.r4.test-data": "^0.127.2",
35
+ "@haste-health/hl7.fhir.r4.core": "^0.127.2"
36
36
  },
37
37
  "files": [
38
38
  "lib/**",
39
- "readme.md"
39
+ "README.md"
40
40
  ],
41
41
  "exports": {
42
42
  ".": "./lib/index.js",