@haste-health/meta-value 0.127.0 → 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 +64 -0
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# @haste-health/meta-value
|
|
2
|
+
|
|
3
|
+
Wraps a FHIR value together with its type information: the FHIR version, the element's declared type (`HumanName`, `code`, `BackboneElement` and so on), its cardinality and its location inside the containing resource. Descending through a `MetaValue` field by field keeps the metadata in step with the data, including choice types (`value[x]`), content references, and the `_field` companions that carry primitive extensions. The metadata tables are generated from the FHIR R4 and R4B StructureDefinitions.
|
|
4
|
+
|
|
5
|
+
This is what gives [`@haste-health/fhirpath`](https://www.npmjs.com/package/@haste-health/fhirpath) type-aware evaluation (`is`, `as`, `ofType`), lets [`@haste-health/fhir-pointer`](https://www.npmjs.com/package/@haste-health/fhir-pointer) turn a JSON Pointer into a FHIRPath, and drives element validation in [`@haste-health/fhir-validation`](https://www.npmjs.com/package/@haste-health/fhir-validation).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @haste-health/meta-value
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { R4 } from "@haste-health/fhir-types/versions";
|
|
17
|
+
import { flatten } from "@haste-health/meta-value/utilities";
|
|
18
|
+
import { metaValue } from "@haste-health/meta-value/v2";
|
|
19
|
+
|
|
20
|
+
const patient = metaValue(
|
|
21
|
+
{ fhirVersion: R4 },
|
|
22
|
+
{
|
|
23
|
+
resourceType: "Patient",
|
|
24
|
+
name: [{ given: ["Bob"], _given: [{ id: "g1" }] }],
|
|
25
|
+
deceasedBoolean: true,
|
|
26
|
+
},
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
patient?.meta()?.type; // "Patient" (taken from resourceType)
|
|
30
|
+
|
|
31
|
+
const name = patient?.descend("name");
|
|
32
|
+
name?.meta(); // { fhirVersion: "4.0", type: "HumanName", cardinality: "array" }
|
|
33
|
+
|
|
34
|
+
const given = flatten(name)[0]?.descend("given")?.descend(0);
|
|
35
|
+
given?.getValue(); // "Bob"
|
|
36
|
+
given?.location(); // ["name", 0, "given", 0]
|
|
37
|
+
given?.descend("id")?.getValue(); // "g1", read from the _given companion
|
|
38
|
+
|
|
39
|
+
patient?.descend("deceased")?.meta()?.type; // "boolean", resolved from deceasedBoolean
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Pass `type` in the options when the value is not a resource, for example `{ fhirVersion: R4, type: "HumanName" }`. Values with no matching metadata still work: they descend as plain JavaScript objects and `meta()` returns `undefined`.
|
|
43
|
+
|
|
44
|
+
## API
|
|
45
|
+
|
|
46
|
+
| Import | Contents |
|
|
47
|
+
| ------------------------------------ | ------------------------------------------------------------------------------------------------ |
|
|
48
|
+
| `@haste-health/meta-value/v2` | `metaValue(options, value)` |
|
|
49
|
+
| `@haste-health/meta-value/interface` | `IMetaValue`, `IMetaValueArray`, `TypeInfo`, `Location` |
|
|
50
|
+
| `@haste-health/meta-value/utilities` | `flatten`, `isResourceType`, `isPrimitiveType`, `isObject`, `isArray` and friends |
|
|
51
|
+
| `@haste-health/meta-value/meta` | `getStartingMeta`, `getMeta`, `resolveMeta`: direct access to the metadata tables |
|
|
52
|
+
| `@haste-health/meta-value/spoof` | `spoof(version, type)`: a typed value with no data, for analysing expressions without a resource |
|
|
53
|
+
| `@haste-health/meta-value` | `resolveTypeToCanonical(version, type)` plus the `v2`, `interfaces` and `utilities` namespaces |
|
|
54
|
+
|
|
55
|
+
Every `IMetaValue` offers `meta()`, `getValue()`, `location()`, `descend(field)`, `keys()`, `isType(type)`, `asType(type)` and `isArray()`; arrays add `toArray()`.
|
|
56
|
+
|
|
57
|
+
## Links
|
|
58
|
+
|
|
59
|
+
- [API reference](https://typescript.haste.health/modules/_haste-health_meta-value.html)
|
|
60
|
+
- [Source](https://github.com/HasteHealth/HasteHealth/tree/main/frontend/packages/meta-value)
|
|
61
|
+
- [TypeScript SDK overview](https://haste.health/docs/api/sdks/typescript)
|
|
62
|
+
- Rust equivalent: the `MetaValue` trait in [haste-reflect](https://crates.io/crates/haste-reflect)
|
|
63
|
+
|
|
64
|
+
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/meta-value",
|
|
3
|
-
"version": "0.127.
|
|
3
|
+
"version": "0.127.2",
|
|
4
4
|
"homepage": "https://haste.health",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"jest": "^29.7.0",
|
|
23
23
|
"ts-jest": "^29.4.11",
|
|
24
24
|
"typescript": "6.0.3",
|
|
25
|
-
"@haste-health/
|
|
26
|
-
"@haste-health/
|
|
27
|
-
"@haste-health/
|
|
28
|
-
"@haste-health/
|
|
29
|
-
"@haste-health/hl7.fhir.r4.core": "^0.127.
|
|
25
|
+
"@haste-health/codegen": "^0.127.2",
|
|
26
|
+
"@haste-health/artifacts": "^0.127.2",
|
|
27
|
+
"@haste-health/fhir-types": "^0.127.2",
|
|
28
|
+
"@haste-health/haste-health.fhir.r4.core": "^0.127.2",
|
|
29
|
+
"@haste-health/hl7.fhir.r4.core": "^0.127.2"
|
|
30
30
|
},
|
|
31
31
|
"files": [
|
|
32
32
|
"lib/**"
|