@haste-health/artifacts 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 +68 -29
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,30 +1,69 @@
1
- # Artifacts
2
-
3
- Loads FHIR artifacts based around fhirVersion on package.json and .index.json file.
4
-
5
- ## API
6
-
7
- ```typescript
8
- /**
9
- * Interface used to search dependencies for .index.json files and load their contents.
10
- * @param options Artifact Load options
11
- * @returns A list of resources of type T
12
- */
13
- export default function loadArtifacts<
14
- Version extends FHIR_VERSION,
15
- T extends ResourceType<Version>,
16
- >({
17
- fhirVersion,
18
- resourceType,
19
- silence,
20
- currentDirectory,
21
- onlyPackages,
22
- }: {
23
- // Only support R4 and R4B for now.
24
- fhirVersion: Version;
25
- resourceType: T;
26
- silence?: boolean;
27
- currentDirectory: string;
28
- onlyPackages?: string[];
29
- }): Resource<Version, T>[];
1
+ # @haste-health/artifacts
2
+
3
+ Loads FHIR conformance resources from the FHIR npm packages installed in your project. A FHIR package such as [`@haste-health/hl7.fhir.r4.core`](https://www.npmjs.com/package/@haste-health/hl7.fhir.r4.core), [`@haste-health/hl7.fhir.us.core`](https://www.npmjs.com/package/@haste-health/hl7.fhir.us.core) or [`@haste-health/haste-health.fhir.r4.core`](https://www.npmjs.com/package/@haste-health/haste-health.fhir.r4.core) ships an `.index.json` that lists every resource file it contains. `loadArtifacts` walks your `package.json` dependencies, keeps the packages whose `fhirVersions` match, and returns the resources of the type you ask for, flattening Bundles on the way. `generateIndexFile` builds that `.index.json` for a package of your own.
4
+
5
+ This is how the Haste Health code generators ([`@haste-health/codegen`](https://www.npmjs.com/package/@haste-health/codegen) and the CLI), [`@haste-health/meta-value`](https://www.npmjs.com/package/@haste-health/meta-value) and the validation and operation test suites obtain StructureDefinitions, OperationDefinitions, SearchParameters and terminology without a server.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @haste-health/artifacts @haste-health/hl7.fhir.r4.core
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { fileURLToPath } from "node:url";
17
+ import { loadArtifacts } from "@haste-health/artifacts";
18
+ import { R4 } from "@haste-health/fhir-types/versions";
19
+
20
+ const structureDefinitions = loadArtifacts({
21
+ fhirVersion: R4,
22
+ resourceType: "StructureDefinition",
23
+ // Any file inside your package: the nearest package.json's dependencies are scanned.
24
+ currentDirectory: fileURLToPath(import.meta.url),
25
+ });
26
+
27
+ const patient = structureDefinitions.find(
28
+ (sd) => sd.url === "http://hl7.org/fhir/StructureDefinition/Patient",
29
+ );
30
30
  ```
31
+
32
+ | Option | Meaning |
33
+ | ------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
34
+ | `fhirVersion` | `R4` or `R4B` from `@haste-health/fhir-types/versions`; a package is used when one of its `fhirVersions` starts with it |
35
+ | `resourceType` | The resource type to load; the return type follows it |
36
+ | `currentDirectory` | Where to start searching upwards for the `package.json` whose dependencies are scanned |
37
+ | `onlyPackages` | Restrict to these package names |
38
+ | `loadDevelopmentPackages` | Also scan `devDependencies` |
39
+ | `silence` | Suppress the log line printed per package |
40
+
41
+ ### Indexing your own package
42
+
43
+ ```ts
44
+ import { writeFileSync } from "node:fs";
45
+ import { generateIndexFile } from "@haste-health/artifacts";
46
+
47
+ const index = generateIndexFile({
48
+ root: "./my-implementation-guide",
49
+ artifactLocations: ["definitions"], // directories under root, walked recursively
50
+ extension: ".json", // default; the HL7 core package indexes ".min.json"
51
+ ignore: ["*.schema.json"], // glob-like patterns, * matches anything
52
+ });
53
+
54
+ writeFileSync(
55
+ "./my-implementation-guide/.index.json",
56
+ JSON.stringify(index, null, 2),
57
+ );
58
+ ```
59
+
60
+ Every JSON file with a `resourceType` gets an entry with its `filename` and `resourceType`; a Bundle gets one entry per resource type it contains. Add `fhirVersions` (for example `["4.0.1"]`) to the package's `package.json` so `loadArtifacts` recognises it.
61
+
62
+ ## Links
63
+
64
+ - [API reference](https://typescript.haste.health/modules/_haste-health_artifacts.html)
65
+ - [Source](https://github.com/HasteHealth/HasteHealth/tree/main/frontend/packages/artifacts), and the FHIR packages themselves under [artifacts/](https://github.com/HasteHealth/HasteHealth/tree/main/artifacts)
66
+ - [TypeScript SDK overview](https://haste.health/docs/api/sdks/typescript)
67
+ - FHIR package conventions: [FHIR NPM Package Spec](https://confluence.hl7.org/display/FHIR/NPM+Package+Specification)
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/artifacts",
3
- "version": "0.127.1",
3
+ "version": "0.127.3",
4
4
  "homepage": "https://haste.health",
5
5
  "repository": {
6
6
  "type": "git",
@@ -19,7 +19,7 @@
19
19
  "devDependencies": {
20
20
  "@types/node": "^22.20.0",
21
21
  "typescript": "6.0.3",
22
- "@haste-health/fhir-types": "^0.127.1"
22
+ "@haste-health/fhir-types": "^0.127.3"
23
23
  },
24
24
  "files": [
25
25
  "lib/**",