@haste-health/fhir-types 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 (3) hide show
  1. package/README.md +60 -0
  2. package/package.json +2 -2
  3. package/readme.md +0 -103
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # @haste-health/fhir-types
2
+
3
+ TypeScript types for every FHIR R4 (4.0.1) and R4B (4.3.0) resource, complex type and primitive, generated from the FHIR StructureDefinitions in the Haste Health [artifacts](https://github.com/HasteHealth/HasteHealth/tree/main/artifacts) packages. The same generation covers Haste Health's own resources, so `User`, `Membership`, `Project`, `ClientApplication`, `AccessPolicyV2`, `IdentityProvider` and `ViewDefinition` are typed alongside `Patient` and `Observation`.
4
+
5
+ The package is almost entirely types. The runtime exports are the version constants and three `Set`s of type names. Every other Haste Health TypeScript package builds on it, from [`@haste-health/client`](https://www.npmjs.com/package/@haste-health/client) to the React components.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @haste-health/fhir-types
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import type { Patient, date, id } from "@haste-health/fhir-types/r4/types";
17
+ import {
18
+ R4,
19
+ type Resource,
20
+ type ResourceType,
21
+ } from "@haste-health/fhir-types/versions";
22
+
23
+ const patient: Patient = {
24
+ resourceType: "Patient",
25
+ id: "123" as id,
26
+ name: [{ family: "Williams", given: ["Eve"] }],
27
+ birthDate: "1973-05-31" as date,
28
+ };
29
+
30
+ // Version-generic code: Resource<Version, Type> is the matching interface.
31
+ function summarize<T extends ResourceType<R4>>(
32
+ type: T,
33
+ resource: Resource<R4, T>,
34
+ ) {
35
+ return `${type}/${resource.id}`;
36
+ }
37
+ ```
38
+
39
+ FHIR primitives other than `string` and `boolean` are branded types (`id`, `code`, `date`, `uri`, `decimal` and so on), so a `uri` is not accepted where a `code` is expected and literals need an `as code` style cast. Primitive extensions live in the `_field` companion properties, as in FHIR JSON.
40
+
41
+ ## Modules
42
+
43
+ | Import | Contents |
44
+ | ----------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
45
+ | `@haste-health/fhir-types/r4/types` | R4 interfaces and primitives, `ResourceType`, `AResource<T>`, `Resource`, `DataType`, `AData<T>` |
46
+ | `@haste-health/fhir-types/r4b/types` | The same for R4B |
47
+ | `@haste-health/fhir-types/r4/sets`, `/r4b/sets` | Runtime `Set<string>`s: `resourceTypes`, `complexTypes`, `primitiveTypes` |
48
+ | `@haste-health/fhir-types/versions` | `R4` (`"4.0"`), `R4B` (`"4.3"`), `FHIR_VERSION`, and version-generic `Resource<V, T>`, `ResourceType<V>`, `Data<V, T>` |
49
+
50
+ The generated files carry a `@generated` header. Regenerate them from the `frontend/` workspace with `pnpm --filter @haste-health/fhir-types run generate` after changing the artifacts.
51
+
52
+ ## Links
53
+
54
+ - [API reference](https://typescript.haste.health/modules/_haste-health_fhir-types.html)
55
+ - [Source](https://github.com/HasteHealth/HasteHealth/tree/main/frontend/packages/fhir-types)
56
+ - [TypeScript SDK overview](https://haste.health/docs/api/sdks/typescript)
57
+ - [FHIR R4 model reference](https://haste.health/docs/reference/fhir/model/resources/Patient) on haste.health, one page per resource
58
+ - Rust equivalent: [haste-fhir-model](https://crates.io/crates/haste-fhir-model)
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/fhir-types",
3
- "version": "0.127.1",
3
+ "version": "0.127.2",
4
4
  "homepage": "https://haste.health",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,7 +29,7 @@
29
29
  "typescript": "6.0.3"
30
30
  },
31
31
  "files": [
32
- "readme.md",
32
+ "README.md",
33
33
  "types/**",
34
34
  "lib/**",
35
35
  "src/**"
package/readme.md DELETED
@@ -1,103 +0,0 @@
1
- # FHIR Typescript Types
2
-
3
- Typescript types generated off of FHIR StructureDefinitions.
4
-
5
- ## Usage
6
-
7
- ```typescript
8
- import { Observation, Patient, id } from "@haste-health/fhir-types/r4/types";
9
-
10
- const patient: Patient = {
11
- name: [
12
- {
13
- use: "official",
14
- given: ["Eve"],
15
- family: "Williams",
16
- },
17
- ],
18
- active: true,
19
- gender: "female",
20
- address: [
21
- {
22
- use: "home",
23
- line: ["2222 Home Street"],
24
- },
25
- ],
26
- telecom: [
27
- {
28
- use: "work",
29
- value: "555-555-2003",
30
- system: "phone",
31
- },
32
- ],
33
- birthDate: "1973-05-31",
34
- identifier: [
35
- {
36
- type: {
37
- coding: [
38
- {
39
- code: "SS",
40
- system: "http://terminology.hl7.org/CodeSystem/v2-0203",
41
- },
42
- ],
43
- },
44
- value: "444222222",
45
- system: "http://hl7.org/fhir/sid/us-ssn",
46
- },
47
- ],
48
- resourceType: "Patient",
49
- managingOrganization: {
50
- reference: "Organization/hl7",
51
- },
52
- };
53
- ```
54
-
55
- ## Sets
56
-
57
- Sets can be used to determine whether a type is a resource, primitive or complex type.
58
- These are utilities that can be useful
59
-
60
- | name | description |
61
- | -------------- | ---------------------------------------------------------------- |
62
- | resourceTypes | String set of FHIR resource types |
63
- | complexTypes | String set of FHIR complex types (HumanName, Identifier etc...). |
64
- | primitiveTypes | String set of FHIR primitive types (string, id, decimal etc...). |
65
-
66
- ### Usage
67
-
68
- ```typescript
69
- import {
70
- primitiveTypes,
71
- resourceTypes,
72
- } from "@haste-health/fhir-types/r4/sets";
73
-
74
- function isPrimitiveType(type: string) {
75
- returnprimitiveTypes.has(type);
76
- }
77
- function isResourceType(type: string) {
78
- returnresourceTypes.has(type);
79
- }
80
- ```
81
-
82
- ## Utility Types
83
-
84
- Various utility types generally used for Typescript generic functions.
85
-
86
- | Name | Description |
87
- | ------------ | -------------------------------------------------------------------------------------------------------------------------------------- |
88
- | ResourceType | One of the resourcetypes, ie "Patient", "Observation". |
89
- | AResource | Generic type with an argument of ResourceType, when passed in, returns an instance of ResourceType IE AResource\<"Patient"\> = Patient |
90
- | Resource | An instance of one of the resource types |
91
-
92
- ### Example
93
-
94
- Pulled from @haste-health/client this example passes in an argument of ResourceType
95
- which is a string of only allowed ResourceTypes and using AResource returns an object in conformance with the type passed in.
96
-
97
- ```typescript
98
- read<T extends ResourceType>(
99
- ctx: CTX,
100
- resourceType: T,
101
- id: id
102
- ): Promise<AResource<T> | undefined>;
103
- ```