@medplum/core 0.5.2 → 0.9.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 +158 -29
- package/dist/cjs/index.js +1047 -89
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.min.js +1 -15
- package/dist/cjs/index.min.js.map +1 -1
- package/dist/esm/index.js +1034 -90
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +1 -15
- package/dist/esm/index.min.js.map +1 -1
- package/dist/types/client.d.ts +427 -13
- package/dist/types/fix-ro-iddentifiers.d.ts +0 -0
- package/dist/types/hl7.d.ts +43 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/repo.d.ts +116 -0
- package/dist/types/search.d.ts +10 -12
- package/dist/types/utils.d.ts +48 -3
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
# Medplum
|
|
2
|
-
|
|
3
|
-
Medplum is a healthcare platform that helps you quickly develop high-quality compliant applications. Medplum includes a FHIR server, React component library, and developer app.
|
|
4
|
-
|
|
5
1
|
# Medplum JS Client Library
|
|
6
2
|
|
|
7
3
|
The Medplum JS Client Library is a pure TypeScript library for calling a FHIR server from the browser.
|
|
@@ -16,13 +12,25 @@ The Medplum JS Client Library is a pure TypeScript library for calling a FHIR se
|
|
|
16
12
|
|
|
17
13
|
## Installation
|
|
18
14
|
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
Add as a dependency:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @medplum/core
|
|
21
19
|
```
|
|
22
20
|
|
|
23
21
|
## Basic Usage
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
Create a new `MedplumClient`:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { MedplumClient } from '@medplum/core';
|
|
27
|
+
|
|
28
|
+
const medplum = new MedplumClient();
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Create a `MedplumClient` with additional configuration options:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
26
34
|
import { MedplumClient } from '@medplum/core';
|
|
27
35
|
|
|
28
36
|
const medplum = new MedplumClient({
|
|
@@ -31,12 +39,11 @@ const medplum = new MedplumClient({
|
|
|
31
39
|
});
|
|
32
40
|
```
|
|
33
41
|
|
|
34
|
-
##
|
|
35
|
-
|
|
36
|
-
Authenticate with a FHIR server via OAuth2 redirect:
|
|
42
|
+
## Authenticate with client credenials
|
|
37
43
|
|
|
38
|
-
```
|
|
39
|
-
medplum
|
|
44
|
+
```ts
|
|
45
|
+
const medplum = new MedplumClient();
|
|
46
|
+
medplum.clientCredentials(MY_CLIENT_ID, MY_CLIENT_SECRET);
|
|
40
47
|
```
|
|
41
48
|
|
|
42
49
|
## Authenticating with Medplum
|
|
@@ -50,25 +57,39 @@ Before you begin
|
|
|
50
57
|
|
|
51
58
|
After that, you can use the `startLogin()` method:
|
|
52
59
|
|
|
53
|
-
```
|
|
60
|
+
```ts
|
|
54
61
|
const loginResult = await medplum.startLogin(email, password, remember);
|
|
55
62
|
const profile = await medplum.processCode(loginResult.code);
|
|
56
63
|
console.log(profile);
|
|
57
64
|
```
|
|
58
65
|
|
|
66
|
+
## Authenticating with OAuth
|
|
67
|
+
|
|
68
|
+
Authenticate with a FHIR server via OAuth2 redirect:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
medplum.signInWithRedirect().then((user) => console.log(user));
|
|
72
|
+
```
|
|
73
|
+
|
|
59
74
|
## Search
|
|
60
75
|
|
|
61
76
|
Search for any resource using a [FHIR search](https://www.hl7.org/fhir/search.html) string:
|
|
62
77
|
|
|
63
|
-
```
|
|
78
|
+
```ts
|
|
79
|
+
search<T extends Resource>(query: string | SearchRequest, options: RequestInit = {}): Promise<Bundle<T>>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Example:
|
|
83
|
+
|
|
84
|
+
```ts
|
|
64
85
|
medplum.search('Patient?given=eve').then((bundle) => {
|
|
65
86
|
bundle.entry.forEach((entry) => console.log(entry.resource));
|
|
66
87
|
});
|
|
67
88
|
```
|
|
68
89
|
|
|
69
|
-
|
|
90
|
+
Example using a structured object:
|
|
70
91
|
|
|
71
|
-
```
|
|
92
|
+
```ts
|
|
72
93
|
medplum
|
|
73
94
|
.search({
|
|
74
95
|
resourceType: 'Patient',
|
|
@@ -87,10 +108,16 @@ medplum
|
|
|
87
108
|
|
|
88
109
|
## Create
|
|
89
110
|
|
|
90
|
-
Create
|
|
111
|
+
[Create resource](https://www.hl7.org/fhir/http.html#create):
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
createResource<T extends Resource>(resource: T): Promise<T>
|
|
115
|
+
```
|
|
91
116
|
|
|
92
|
-
|
|
93
|
-
|
|
117
|
+
Example:
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
medplum.createResource({
|
|
94
121
|
resourceType: 'Observation',
|
|
95
122
|
subject: {
|
|
96
123
|
reference: 'Patient/123',
|
|
@@ -102,26 +129,128 @@ medplum.create({
|
|
|
102
129
|
});
|
|
103
130
|
```
|
|
104
131
|
|
|
105
|
-
## Read
|
|
132
|
+
## Read a resource
|
|
133
|
+
|
|
134
|
+
[Read a resource by ID](https://www.hl7.org/fhir/http.html#read):
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
readResource<T extends Resource>(resourceType: string, id: string): Promise<T>
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Example:
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
const patient = await medplum.readResource('Patient', '123');
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Read resource history
|
|
147
|
+
|
|
148
|
+
[Read resource history](https://www.hl7.org/fhir/http.html#history):
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
readHistory<T extends Resource>(resourceType: string, id: string): Promise<Bundle<T>>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Example:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
const historyBundle = await medplum.readHistory('Patient', '123');
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Read resource version
|
|
161
|
+
|
|
162
|
+
[Read a specific version](https://www.hl7.org/fhir/http.html#vread):
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
readVersion<T extends Resource>(resourceType: string, id: string, vid: string): Promise<T>
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Example:
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
const version = await medplum.readVersion('Patient', '123', '456');
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Update a resource
|
|
175
|
+
|
|
176
|
+
[Update a resource](https://www.hl7.org/fhir/http.html#update):
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
updateResource<T extends Resource>(resource: T): Promise<T>
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Example:
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
const result = await medplum.updateResource({
|
|
186
|
+
resourceType: 'Patient',
|
|
187
|
+
id: '123',
|
|
188
|
+
name: [{
|
|
189
|
+
family: 'Smith',
|
|
190
|
+
given: ['John']
|
|
191
|
+
}]
|
|
192
|
+
});
|
|
193
|
+
console.log(result.meta.versionId);
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Delete a resource
|
|
106
197
|
|
|
107
|
-
|
|
198
|
+
[Delete a resource](https://www.hl7.org/fhir/http.html#delete):
|
|
108
199
|
|
|
109
|
-
```
|
|
110
|
-
|
|
200
|
+
```ts
|
|
201
|
+
deleteResource(resourceType: string, id: string): Promise<any>
|
|
111
202
|
```
|
|
112
203
|
|
|
113
|
-
|
|
204
|
+
Example:
|
|
114
205
|
|
|
115
|
-
```
|
|
116
|
-
medplum.
|
|
206
|
+
```ts
|
|
207
|
+
await medplum.deleteResource('Patient', '123');
|
|
117
208
|
```
|
|
118
209
|
|
|
119
|
-
|
|
210
|
+
## Patch a resource
|
|
211
|
+
|
|
212
|
+
[Patch a resource](https://www.hl7.org/fhir/http.html#patch):
|
|
120
213
|
|
|
121
|
-
```
|
|
122
|
-
|
|
214
|
+
```ts
|
|
215
|
+
patchResource<T extends Resource>(resourceType: string, id: string, operations: Operation[]): Promise<T>
|
|
123
216
|
```
|
|
124
217
|
|
|
218
|
+
Example:
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
const result = await medplum.patchResource('Patient', '123', [
|
|
222
|
+
{op: 'replace', path: '/name/0/family', value: 'Smith'},
|
|
223
|
+
]);
|
|
224
|
+
console.log(result.meta.versionId);
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## GraphQL
|
|
228
|
+
|
|
229
|
+
[Execute a GraphQL query](https://www.hl7.org/fhir/graphql.html):
|
|
230
|
+
|
|
231
|
+
```ts
|
|
232
|
+
graphql(query: string, options?: RequestInit): Promise<any>
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Example:
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
const result = await graphql(`
|
|
239
|
+
{
|
|
240
|
+
PatientList(name: "Alice") {
|
|
241
|
+
name {
|
|
242
|
+
given,
|
|
243
|
+
family
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
`);
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## About Medplum
|
|
251
|
+
|
|
252
|
+
Medplum is a healthcare platform that helps you quickly develop high-quality compliant applications. Medplum includes a FHIR server, React component library, and developer app.
|
|
253
|
+
|
|
125
254
|
## License
|
|
126
255
|
|
|
127
256
|
Apache 2.0. Copyright © Medplum 2022
|