@medplum/cli 2.0.16 → 2.0.18
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 +1 -252
- package/dist/cjs/index.cjs +593 -154
- package/dist/cjs/index.cjs.map +1 -1
- package/package.json +11 -3
package/README.md
CHANGED
|
@@ -16,260 +16,9 @@ Or add as a package dependency:
|
|
|
16
16
|
npm install @medplum/cli
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
## Authentication
|
|
20
|
-
|
|
21
|
-
Use one of these authentication options:
|
|
22
|
-
|
|
23
|
-
1. Stored credentials in `~/.medplum/credentials`. You can use the `medplum login` command (see below) to automatically create this file.
|
|
24
|
-
2. Client credentials in environment variables `MEDPLUM_CLIENT_ID` and `MEDPLUM_CLIENT_SECRET`. `dotenv` is enabled, so you can store them in a `.env` file.
|
|
25
|
-
|
|
26
19
|
## Usage
|
|
27
20
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
medplum <command> <args>
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
If installed as a package dependency, you can use the `medplum` command via `npx`:
|
|
35
|
-
|
|
36
|
-
```bash
|
|
37
|
-
npx medplum <command> <args>
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
By default, the `medplum` command uses the Medplum hosted API at "https://api.medplum.com". If you want to use the `medplum` command against your own self-hosted server, you can use the `MEDPLUM_BASE_URL` environment variable. `dotenv` is enabled, so you can store this value in a `.env` file.
|
|
41
|
-
|
|
42
|
-
### Auth
|
|
43
|
-
|
|
44
|
-
#### `login`
|
|
45
|
-
|
|
46
|
-
The `login` command opens a web browser to a Medplum authentication page.
|
|
47
|
-
|
|
48
|
-
On successful login, the command writes credentials to disk at `~/.medplum/credentials`.
|
|
49
|
-
|
|
50
|
-
The `medplum` command will then load those credentials on all future runs.
|
|
51
|
-
|
|
52
|
-
Example:
|
|
53
|
-
|
|
54
|
-
```bash
|
|
55
|
-
medplum login
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
#### `whoami`
|
|
59
|
-
|
|
60
|
-
The `whoami` command displays whether the client is authenticated, and, if so, the name of the current user and current Medplum project.
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
medplum whoami
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### RESTful Operations
|
|
67
|
-
|
|
68
|
-
The `medplum` command can be used as a convenient tool for basic Medplum CRUD and RESTful operations.
|
|
69
|
-
|
|
70
|
-
While all API endpoints are available to any command line HTTP client such as `curl` or `wget`, there are a few advantages to using the `medplum` command:
|
|
71
|
-
|
|
72
|
-
1. Authentication and credentials - login once using the `login` command, and the `Authorization` header will be set automatically.
|
|
73
|
-
2. URL prefixes - adds the base URL (i.e., "https://api.medplum.com") and FHIR path prefix (i.e., "fhir/R4/").
|
|
74
|
-
3. Pretty print - formats the JSON with spaces and newlines.
|
|
75
|
-
4. Medplum extended mode - adds the `X-Medplum` HTTP header for private Medplum fields.
|
|
76
|
-
|
|
77
|
-
#### `get`
|
|
78
|
-
|
|
79
|
-
Makes an HTTP `GET` request.
|
|
80
|
-
|
|
81
|
-
```bash
|
|
82
|
-
medplum get <url>
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
Example: Search for patients:
|
|
86
|
-
|
|
87
|
-
```bash
|
|
88
|
-
medplum get 'Patient?name=homer'
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
Example: Read patient by ID:
|
|
92
|
-
|
|
93
|
-
```bash
|
|
94
|
-
medplum get Patient/$id
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
#### `post`
|
|
98
|
-
|
|
99
|
-
Makes an HTTP `POST` request.
|
|
100
|
-
|
|
101
|
-
```bash
|
|
102
|
-
medplum post <url> <body>
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
Example: Create a patient:
|
|
106
|
-
|
|
107
|
-
```bash
|
|
108
|
-
medplum post Patient '{"resourceType":"Patient","name":[{"family":"Simpson"}]}'
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
Example: Invoke a FHIR operation:
|
|
112
|
-
|
|
113
|
-
```bash
|
|
114
|
-
medplum post 'Patient/$validate' '{"resourceType":"Patient","name":[{"family":"Simpson"}]}'
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
#### `put`
|
|
118
|
-
|
|
119
|
-
Makes an HTTP `PUT` request.
|
|
120
|
-
|
|
121
|
-
```bash
|
|
122
|
-
medplum put <url> <body>
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
Example: Update a patient:
|
|
126
|
-
|
|
127
|
-
```bash
|
|
128
|
-
medplum put Patient/$id '{"resourceType":"Patient","name":[{"family":"Simpson"}]}'
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
#### `patch`
|
|
132
|
-
|
|
133
|
-
Makes an HTTP `PATCH` request.
|
|
134
|
-
|
|
135
|
-
```bash
|
|
136
|
-
medplum patch <url> <body>
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
Example: Update a patient with [JSONPatch](https://jsonpatch.com/):
|
|
140
|
-
|
|
141
|
-
```bash
|
|
142
|
-
medplum patch Patient/$id '[{"op":"add","path":"/active","value":[true]}]'
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
#### `delete`
|
|
146
|
-
|
|
147
|
-
Makes an HTTP `DELETE` request.
|
|
148
|
-
|
|
149
|
-
```bash
|
|
150
|
-
medplum delete <url>
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
Example: Delete patient by ID:
|
|
154
|
-
|
|
155
|
-
```bash
|
|
156
|
-
medplum delete Patient/$id
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
### Bots
|
|
160
|
-
|
|
161
|
-
#### Bots Config file
|
|
162
|
-
|
|
163
|
-
Create a Medplum config file called `medplum.config.json`:
|
|
164
|
-
|
|
165
|
-
```json
|
|
166
|
-
{
|
|
167
|
-
"bots": [
|
|
168
|
-
{
|
|
169
|
-
"name": "hello-world",
|
|
170
|
-
"id": "f0465c2e-11d4-4c36-b834-8e86f7472b4b",
|
|
171
|
-
"source": "src/index.ts",
|
|
172
|
-
"dist": "dist/index.js"
|
|
173
|
-
}
|
|
174
|
-
]
|
|
175
|
-
}
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
The `name` property is a friendly name you can use to reference the Bot in commands.
|
|
179
|
-
|
|
180
|
-
The `id` property refers to the Bot ID in your Medplum project.
|
|
181
|
-
|
|
182
|
-
The `source` property is the file path to the original source. When you "save" the Bot, the contents of this file will be saved to the Bot `code` property. This file can be JavaScript or TypeScript.
|
|
183
|
-
|
|
184
|
-
The `dist` property is the optional file path to the compiled source. If omitted, the command falls back to using the `source` property. When you "deploy" the Bot, the contents of this file will be deployed to the Bot runtime. This file must be JavaScript.
|
|
185
|
-
|
|
186
|
-
#### save-bot
|
|
187
|
-
|
|
188
|
-
Updates the `code` value on a `Bot` resource
|
|
189
|
-
|
|
190
|
-
Syntax:
|
|
191
|
-
|
|
192
|
-
```bash
|
|
193
|
-
npx medplum save-bot <bot name>
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
Example:
|
|
197
|
-
|
|
198
|
-
```bash
|
|
199
|
-
npx medplum save-bot hello-world
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
#### deploy-bot
|
|
203
|
-
|
|
204
|
-
Deploys the Bot code
|
|
205
|
-
|
|
206
|
-
Syntax:
|
|
207
|
-
|
|
208
|
-
```bash
|
|
209
|
-
npx medplum deploy-bot <bot name>
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
Example:
|
|
213
|
-
|
|
214
|
-
```bash
|
|
215
|
-
npx medplum-deploy-bot <bot name>
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
## Bots Example
|
|
219
|
-
|
|
220
|
-
Create a Medplum config file `medplum.config.json`:
|
|
221
|
-
|
|
222
|
-
```json
|
|
223
|
-
{
|
|
224
|
-
"bots": [
|
|
225
|
-
{
|
|
226
|
-
"name": "hello-world",
|
|
227
|
-
"id": "f0465c2e-11d4-4c36-b834-8e86f7472b4b",
|
|
228
|
-
"source": "src/hello-world.ts",
|
|
229
|
-
"dist": "dist/hello-world.js"
|
|
230
|
-
}
|
|
231
|
-
]
|
|
232
|
-
}
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
Replace the sample `id` with your Bot's ID.
|
|
236
|
-
|
|
237
|
-
Write your bot in `src/hello-world.ts`. This can be TypeScript. It can reference `@medplum/core` and `node-fetch`:
|
|
238
|
-
|
|
239
|
-
```ts
|
|
240
|
-
import { MedplumClient } from '@medplum/core';
|
|
241
|
-
import { Resource } from '@medplum/fhirtypes';
|
|
242
|
-
|
|
243
|
-
export async function handler(medplum: MedplumClient, event: BotEvent): Promise<any> {
|
|
244
|
-
console.log('Hello world');
|
|
245
|
-
}
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
You can use the Medplum CLI to save it:
|
|
249
|
-
|
|
250
|
-
```bash
|
|
251
|
-
npx medplum save-bot hello-world
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
Compile with vanilla `tsc` (no bundler required)
|
|
255
|
-
|
|
256
|
-
```bash
|
|
257
|
-
npx tsc
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
The result will be JavaScript output in `dist/hello-world.js`:
|
|
261
|
-
|
|
262
|
-
```javascript
|
|
263
|
-
export async function handler(medplum, input) {
|
|
264
|
-
console.log('Hello world');
|
|
265
|
-
}
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
You can then use the Medplum CLI to deploy it.
|
|
269
|
-
|
|
270
|
-
```bash
|
|
271
|
-
npx medplum deploy-bot hello-world
|
|
272
|
-
```
|
|
21
|
+
See <https://www.medplum.com/docs/cli> for usage.
|
|
273
22
|
|
|
274
23
|
## About Medplum
|
|
275
24
|
|