@haste-health/fhir-pointer 0.127.1 → 0.127.3

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 +74 -0
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -0,0 +1,74 @@
1
+ # @haste-health/fhir-pointer
2
+
3
+ Typesafe pointers into FHIR resources. A `Loc` is a string of the form `<fhirVersion>|<resourceType>|<id>/<json pointer>` whose type parameters remember the root resource type and the type of the element it points at, so `descend` only accepts fields that exist on the current element and `get` returns the element's type. A `Loc` converts to a plain JSON Pointer (RFC 6901) and, with the type metadata from [`@haste-health/meta-value`](https://www.npmjs.com/package/@haste-health/meta-value), to a FHIRPath expression.
4
+
5
+ [`@haste-health/fhir-patch-building`](https://www.npmjs.com/package/@haste-health/fhir-patch-building) builds JSON Patches from these pointers, [`@haste-health/fhir-validation`](https://www.npmjs.com/package/@haste-health/fhir-validation) and [`@haste-health/operation-execution`](https://www.npmjs.com/package/@haste-health/operation-execution) use them to say where an error occurred, and the Haste Health admin app and React components bind form fields to resource elements with them.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @haste-health/fhir-pointer
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import {
17
+ ascend,
18
+ descend,
19
+ fields,
20
+ get,
21
+ pointer,
22
+ toFHIRPath,
23
+ toJSONPointer,
24
+ } from "@haste-health/fhir-pointer";
25
+ import type { Patient, id } from "@haste-health/fhir-types/r4/types";
26
+ import { R4 } from "@haste-health/fhir-types/versions";
27
+
28
+ const patient = {
29
+ resourceType: "Patient",
30
+ id: "123",
31
+ name: [{ given: ["John"] }],
32
+ } as Patient;
33
+
34
+ const root = pointer(R4, "Patient", "123" as id); // "4.0|Patient|123"
35
+ const given = descend(descend(descend(root, "name"), 0), "given");
36
+ // typed as Loc<Patient, string[] | undefined, ...>, "4.0|Patient|123/name/0/given"
37
+
38
+ get(given, patient); // ["John"]
39
+ fields(given); // ["name", 0, "given"]
40
+ ascend(given); // { parent: "4.0|Patient|123/name/0", field: "given" }
41
+ toJSONPointer(given); // "/name/0/given"
42
+
43
+ const coding = descend(
44
+ descend(
45
+ descend(pointer(R4, "Observation", "o1" as id), "valueCodeableConcept"),
46
+ "coding",
47
+ ),
48
+ 0,
49
+ );
50
+ toFHIRPath(coding); // "$this.value.coding[0]"
51
+ ```
52
+
53
+ Field names are escaped per RFC 6901 (`~` and `/`), and `get` returns `undefined` rather than throwing when part of the path is missing.
54
+
55
+ ## API
56
+
57
+ | Function | Purpose |
58
+ | ------------------------------------------- | ----------------------------------------------------------------------- |
59
+ | `pointer(version, resourceType, id)` | Root `Loc` for a resource |
60
+ | `typedPointer<V, T>()` | Root `Loc` for any value, without FHIR metadata |
61
+ | `descend(loc, field)`, `ascend(loc)` | Move down one field or array index, or back up to the parent |
62
+ | `get(loc, value)` | Read the element the pointer addresses |
63
+ | `fields(loc)`, `root(loc)`, `pathMeta(loc)` | Path segments, the root pointer, and `{ version, type, id }` |
64
+ | `toJSONPointer(loc)`, `toFHIRPath(loc)` | Conversions; `toFHIRPath` folds choice types (`valueCoding` to `value`) |
65
+ | `Loc<Root, Element, Parent>`, `NullGuard` | The pointer type and the helper that propagates optional parents |
66
+
67
+ ## Links
68
+
69
+ - [API reference](https://typescript.haste.health/modules/_haste-health_fhir-pointer.html)
70
+ - [Source](https://github.com/HasteHealth/HasteHealth/tree/main/frontend/packages/fhir-pointer)
71
+ - [TypeScript SDK overview](https://haste.health/docs/api/sdks/typescript)
72
+ - Rust equivalent: [haste-pointer](https://crates.io/crates/haste-pointer)
73
+
74
+ 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-pointer",
3
- "version": "0.127.1",
3
+ "version": "0.127.3",
4
4
  "homepage": "https://haste.health",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,17 +21,17 @@
21
21
  "jest": "^29.7.0",
22
22
  "ts-jest": "^29.4.11",
23
23
  "typescript": "6.0.3",
24
- "@haste-health/fhir-types": "^0.127.1"
24
+ "@haste-health/fhir-types": "^0.127.3"
25
25
  },
26
26
  "files": [
27
- "readme.md",
27
+ "README.md",
28
28
  "lib/**",
29
29
  "src/**"
30
30
  ],
31
31
  "dependencies": {
32
32
  "jsonpointer": "^5.0.1",
33
- "@haste-health/operation-outcomes": "^0.127.1",
34
- "@haste-health/meta-value": "^0.127.1"
33
+ "@haste-health/meta-value": "^0.127.3",
34
+ "@haste-health/operation-outcomes": "^0.127.3"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "tsc",