@medplum/core 0.5.2 → 0.9.0

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 (50) hide show
  1. package/dist/cjs/index.js +819 -60
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/index.min.js +1 -1
  4. package/dist/cjs/index.min.js.map +1 -1
  5. package/dist/esm/index.js +817 -61
  6. package/dist/esm/index.js.map +1 -1
  7. package/dist/esm/index.min.js +1 -1
  8. package/dist/esm/index.min.js.map +1 -1
  9. package/dist/types/client.d.ts +427 -13
  10. package/dist/types/fix-ro-iddentifiers.d.ts +0 -0
  11. package/dist/types/index.d.ts +1 -0
  12. package/dist/types/repo.d.ts +116 -0
  13. package/dist/types/search.d.ts +9 -12
  14. package/dist/types/utils.d.ts +21 -0
  15. package/docs/.nojekyll +1 -0
  16. package/docs/assets/highlight.css +92 -0
  17. package/docs/assets/icons.css +1043 -0
  18. package/docs/assets/icons.png +0 -0
  19. package/docs/assets/icons@2x.png +0 -0
  20. package/docs/assets/main.js +52 -0
  21. package/docs/assets/search.js +1 -0
  22. package/docs/assets/style.css +1414 -0
  23. package/docs/assets/widgets.png +0 -0
  24. package/docs/assets/widgets@2x.png +0 -0
  25. package/docs/classes/LegacyRepositoryClient.html +71 -0
  26. package/docs/classes/MedplumClient.html +324 -0
  27. package/docs/classes/OperationOutcomeError.html +6 -0
  28. package/docs/enums/Operator.html +5 -0
  29. package/docs/enums/PropertyType.html +5 -0
  30. package/docs/enums/SearchParameterType.html +1 -0
  31. package/docs/index.html +89 -0
  32. package/docs/interfaces/AddressFormatOptions.html +1 -0
  33. package/docs/interfaces/FetchLike.html +1 -0
  34. package/docs/interfaces/Filter.html +1 -0
  35. package/docs/interfaces/GoogleCredentialResponse.html +1 -0
  36. package/docs/interfaces/HumanNameFormatOptions.html +1 -0
  37. package/docs/interfaces/IndexedStructureDefinition.html +19 -0
  38. package/docs/interfaces/LoginAuthenticationResponse.html +1 -0
  39. package/docs/interfaces/LoginProfileResponse.html +1 -0
  40. package/docs/interfaces/LoginScopeResponse.html +1 -0
  41. package/docs/interfaces/LoginState.html +1 -0
  42. package/docs/interfaces/MedplumClientOptions.html +33 -0
  43. package/docs/interfaces/RegisterRequest.html +1 -0
  44. package/docs/interfaces/SearchParameterDetails.html +1 -0
  45. package/docs/interfaces/SearchRequest.html +1 -0
  46. package/docs/interfaces/SortRule.html +1 -0
  47. package/docs/interfaces/TokenResponse.html +1 -0
  48. package/docs/interfaces/TypeSchema.html +10 -0
  49. package/docs/modules.html +138 -0
  50. package/package.json +3 -2
@@ -1,4 +1,5 @@
1
1
  import { Binary, Bundle, Project, ProjectMembership, Reference, Resource, UserConfiguration, ValueSet } from '@medplum/fhirtypes';
2
+ import { Operation } from 'fast-json-patch';
2
3
  import { EventTarget } from './eventtarget';
3
4
  import { SearchRequest } from './search';
4
5
  import { IndexedStructureDefinition } from './types';
@@ -97,6 +98,54 @@ export interface TokenResponse {
97
98
  readonly project: Reference<Project>;
98
99
  readonly profile: Reference<ProfileResource>;
99
100
  }
101
+ /**
102
+ * The MedplumClient class provides a client for the Medplum FHIR server.
103
+ *
104
+ * The client can be used in the browser, in a NodeJS application, or in a Medplum Bot.
105
+ *
106
+ * The client provides helpful methods for common operations such as:
107
+ * 1) Authenticating
108
+ * 2) Creating resources
109
+ * 2) Reading resources
110
+ * 3) Updating resources
111
+ * 5) Deleting resources
112
+ * 6) Searching
113
+ * 7) Making GraphQL queries
114
+ *
115
+ * Here is a quick example of how to use the client:
116
+ *
117
+ * ```typescript
118
+ * import { MedplumClient } from '@medplum/core';
119
+ * const medplum = new MedplumClient();
120
+ * ```
121
+ *
122
+ * Create a `Patient`:
123
+ *
124
+ * ```typescript
125
+ * const patient = await medplum.createResource({
126
+ * resourceType: 'Patient',
127
+ * name: [{
128
+ * given: ['Alice'],
129
+ * family: 'Smith'
130
+ * }]
131
+ * });
132
+ * ```
133
+ *
134
+ * Read a `Patient` by ID:
135
+ *
136
+ * ```typescript
137
+ * const patient = await medplum.readResource('Patient', '123');
138
+ * console.log(patient.name[0].given[0]);
139
+ * ```
140
+ *
141
+ * Search for a `Patient` by name:
142
+ *
143
+ * ```typescript
144
+ * const bundle = await medplum.search('Patient?name=Alice');
145
+ * console.log(bundle.total);
146
+ * ```
147
+ *
148
+ */
100
149
  export declare class MedplumClient extends EventTarget {
101
150
  #private;
102
151
  constructor(options?: MedplumClientOptions);
@@ -104,10 +153,71 @@ export declare class MedplumClient extends EventTarget {
104
153
  * Clears all auth state including local storage and session storage.
105
154
  */
106
155
  clear(): void;
107
- get(url: string): Promise<any>;
108
- post(url: string, body: any, contentType?: string): Promise<any>;
109
- put(url: string, body: any, contentType?: string): Promise<any>;
110
- delete(url: string): Promise<any>;
156
+ /**
157
+ * Makes an HTTP GET request to the specified URL.
158
+ *
159
+ * This is a lower level method for custom requests.
160
+ * For common operations, we recommend using higher level methods
161
+ * such as `readResource()`, `search()`, etc.
162
+ *
163
+ * @param url The target URL.
164
+ * @param options Optional fetch options.
165
+ * @returns Promise to the response content.
166
+ */
167
+ get(url: string, options?: RequestInit): Promise<any>;
168
+ /**
169
+ * Makes an HTTP POST request to the specified URL.
170
+ *
171
+ * This is a lower level method for custom requests.
172
+ * For common operations, we recommend using higher level methods
173
+ * such as `createResource()`.
174
+ *
175
+ * @param url The target URL.
176
+ * @param body The content body. Strings and `File` objects are passed directly. Other objects are converted to JSON.
177
+ * @param contentType The content type to be included in the "Content-Type" header.
178
+ * @param options Optional fetch options.
179
+ * @returns Promise to the response content.
180
+ */
181
+ post(url: string, body: any, contentType?: string, options?: RequestInit): Promise<any>;
182
+ /**
183
+ * Makes an HTTP PUT request to the specified URL.
184
+ *
185
+ * This is a lower level method for custom requests.
186
+ * For common operations, we recommend using higher level methods
187
+ * such as `updateResource()`.
188
+ *
189
+ * @param url The target URL.
190
+ * @param body The content body. Strings and `File` objects are passed directly. Other objects are converted to JSON.
191
+ * @param contentType The content type to be included in the "Content-Type" header.
192
+ * @param options Optional fetch options.
193
+ * @returns Promise to the response content.
194
+ */
195
+ put(url: string, body: any, contentType?: string, options?: RequestInit): Promise<any>;
196
+ /**
197
+ * Makes an HTTP PATCH request to the specified URL.
198
+ *
199
+ * This is a lower level method for custom requests.
200
+ * For common operations, we recommend using higher level methods
201
+ * such as `patchResource()`.
202
+ *
203
+ * @param url The target URL.
204
+ * @param operations Array of JSONPatch operations.
205
+ * @param options Optional fetch options.
206
+ * @returns Promise to the response content.
207
+ */
208
+ patch(url: string, operations: Operation[], options?: RequestInit): Promise<any>;
209
+ /**
210
+ * Makes an HTTP DELETE request to the specified URL.
211
+ *
212
+ * This is a lower level method for custom requests.
213
+ * For common operations, we recommend using higher level methods
214
+ * such as `deleteResource()`.
215
+ *
216
+ * @param url The target URL.
217
+ * @param options Optional fetch options.
218
+ * @returns Promise to the response content.
219
+ */
220
+ delete(url: string, options?: RequestInit): Promise<any>;
111
221
  /**
112
222
  * Tries to register a new user.
113
223
  * @param request The registration request.
@@ -155,10 +265,99 @@ export declare class MedplumClient extends EventTarget {
155
265
  fhirUrl(...path: string[]): string;
156
266
  /**
157
267
  * Sends a FHIR search request.
158
- * @param search The search query.
268
+ *
269
+ * Example using a FHIR search string:
270
+ *
271
+ * ```typescript
272
+ * const bundle = await client.search('Patient?name=Alice');
273
+ * console.log(bundle);
274
+ * ```
275
+ *
276
+ * Example using a structured search:
277
+ *
278
+ * ```typescript
279
+ * const bundle = await client.search({
280
+ * resourceType: 'Patient',
281
+ * filters: [{
282
+ * code: 'name',
283
+ * operator: 'eq',
284
+ * value: 'Alice',
285
+ * }]
286
+ * });
287
+ * console.log(bundle);
288
+ * ```
289
+ *
290
+ * The return value is a FHIR bundle:
291
+ *
292
+ * ```json
293
+ * {
294
+ * "resourceType": "Bundle",
295
+ * "type": "searchest",
296
+ * "total": 1,
297
+ * "entry": [
298
+ * {
299
+ * "resource": {
300
+ * "resourceType": "Patient",
301
+ * "name": [
302
+ * {
303
+ * "given": [
304
+ * "George"
305
+ * ],
306
+ * "family": "Washington"
307
+ * }
308
+ * ],
309
+ * }
310
+ * }
311
+ * ]
312
+ * }
313
+ * ```
314
+ *
315
+ * See FHIR search for full details: https://www.hl7.org/fhir/search.html
316
+ *
317
+ * @param query The search query as either a string or a structured search object.
318
+ * @returns Promise to the search result bundle.
319
+ */
320
+ search<T extends Resource>(query: string | SearchRequest, options?: RequestInit): Promise<Bundle<T>>;
321
+ /**
322
+ * Sends a FHIR search request for a single resource.
323
+ *
324
+ * This is a convenience method for `search()` that returns the first resource rather than a `Bundle`.
325
+ *
326
+ * Example using a FHIR search string:
327
+ *
328
+ * ```typescript
329
+ * const patient = await client.searchOne('Patient?identifier=123');
330
+ * console.log(patient);
331
+ * ```
332
+ *
333
+ * The return value is the resource, if available; otherwise, undefined.
334
+ *
335
+ * See FHIR search for full details: https://www.hl7.org/fhir/search.html
336
+ *
337
+ * @param query The search query as either a string or a structured search object.
338
+ * @returns Promise to the search result bundle.
339
+ */
340
+ searchOne<T extends Resource>(query: string | SearchRequest, options?: RequestInit): Promise<T | undefined>;
341
+ /**
342
+ * Sends a FHIR search request for an array of resources.
343
+ *
344
+ * This is a convenience method for `search()` that returns the resources as an array rather than a `Bundle`.
345
+ *
346
+ * Example using a FHIR search string:
347
+ *
348
+ * ```typescript
349
+ * const patients = await client.searchResources('Patient?name=Alice');
350
+ * console.log(patients);
351
+ * ```
352
+ *
353
+ * The return value is an array of resources.
354
+ *
355
+ * See FHIR search for full details: https://www.hl7.org/fhir/search.html
356
+ *
357
+ * @param query The search query as either a string or a structured search object.
159
358
  * @returns Promise to the search result bundle.
160
359
  */
161
- search<T extends Resource>(search: SearchRequest): Promise<Bundle<T>>;
360
+ searchResources<T extends Resource>(query: string | SearchRequest, options?: RequestInit): Promise<T[]>;
162
361
  /**
163
362
  * Searches a ValueSet resource using the "expand" operation.
164
363
  * See: https://www.hl7.org/fhir/operation-valueset-expand.html
@@ -166,7 +365,7 @@ export declare class MedplumClient extends EventTarget {
166
365
  * @param filter The search string.
167
366
  * @returns Promise to expanded ValueSet.
168
367
  */
169
- searchValueSet(system: string, filter: string): Promise<ValueSet>;
368
+ searchValueSet(system: string, filter: string, options?: RequestInit): Promise<ValueSet>;
170
369
  /**
171
370
  * Returns a cached resource if it is available.
172
371
  * @param resourceType The FHIR resource type.
@@ -181,9 +380,81 @@ export declare class MedplumClient extends EventTarget {
181
380
  * @returns The resource if it is available in the cache; undefined otherwise.
182
381
  */
183
382
  getCachedReference<T extends Resource>(reference: Reference<T>): T | undefined;
184
- read<T extends Resource>(resourceType: string, id: string): Promise<T>;
383
+ /**
384
+ * Reads a resource by resource type and ID.
385
+ *
386
+ * Example:
387
+ *
388
+ * ```typescript
389
+ * const patient = await medplum.readResource('Patient', '123');
390
+ * console.log(patient);
391
+ * ```
392
+ *
393
+ * See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
394
+ *
395
+ * @param resourceType The FHIR resource type.
396
+ * @param id The resource ID.
397
+ * @returns The resource if available; undefined otherwise.
398
+ */
399
+ readResource<T extends Resource>(resourceType: string, id: string): Promise<T>;
400
+ /**
401
+ * Reads a resource by resource type and ID using the in-memory resource cache.
402
+ *
403
+ * If the resource is not available in the cache, it will be read from the server.
404
+ *
405
+ * Example:
406
+ *
407
+ * ```typescript
408
+ * const patient = await medplum.readCached('Patient', '123');
409
+ * console.log(patient);
410
+ * ```
411
+ *
412
+ * See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
413
+ *
414
+ * @param resourceType The FHIR resource type.
415
+ * @param id The resource ID.
416
+ * @returns The resource if available; undefined otherwise.
417
+ */
185
418
  readCached<T extends Resource>(resourceType: string, id: string): Promise<T>;
419
+ /**
420
+ * Reads a resource by `Reference`.
421
+ *
422
+ * This is a convenience method for `readResource()` that accepts a `Reference` object.
423
+ *
424
+ * Example:
425
+ *
426
+ * ```typescript
427
+ * const serviceRequest = await medplum.readResource('ServiceRequest', '123');
428
+ * const patient = await medplum.readReference(serviceRequest.subject);
429
+ * console.log(patient);
430
+ * ```
431
+ *
432
+ * See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
433
+ *
434
+ * @param reference The FHIR reference object.
435
+ * @returns The resource if available; undefined otherwise.
436
+ */
186
437
  readReference<T extends Resource>(reference: Reference<T>): Promise<T>;
438
+ /**
439
+ * Reads a resource by `Reference` using the in-memory resource cache.
440
+ *
441
+ * This is a convenience method for `readResource()` that accepts a `Reference` object.
442
+ *
443
+ * If the resource is not available in the cache, it will be read from the server.
444
+ *
445
+ * Example:
446
+ *
447
+ * ```typescript
448
+ * const serviceRequest = await medplum.readResource('ServiceRequest', '123');
449
+ * const patient = await medplum.readCachedReference(serviceRequest.subject);
450
+ * console.log(patient);
451
+ * ```
452
+ *
453
+ * See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
454
+ *
455
+ * @param reference The FHIR reference object.
456
+ * @returns The resource if available; undefined otherwise.
457
+ */
187
458
  readCachedReference<T extends Resource>(reference: Reference<T>): Promise<T>;
188
459
  /**
189
460
  * Returns a cached schema for a resource type.
@@ -200,16 +471,158 @@ export declare class MedplumClient extends EventTarget {
200
471
  * @returns Promise to a schema with the requested resource type.
201
472
  */
202
473
  requestSchema(resourceType: string): Promise<IndexedStructureDefinition>;
474
+ /**
475
+ * Reads resource history by resource type and ID.
476
+ *
477
+ * The return value is a bundle of all versions of the resource.
478
+ *
479
+ * Example:
480
+ *
481
+ * ```typescript
482
+ * const history = await medplum.readHistory('Patient', '123');
483
+ * console.log(history);
484
+ * ```
485
+ *
486
+ * See the FHIR "history" operation for full details: https://www.hl7.org/fhir/http.html#history
487
+ *
488
+ * @param resourceType The FHIR resource type.
489
+ * @param id The resource ID.
490
+ * @returns The resource if available; undefined otherwise.
491
+ */
203
492
  readHistory<T extends Resource>(resourceType: string, id: string): Promise<Bundle<T>>;
493
+ /**
494
+ * Reads a specific version of a resource by resource type, ID, and version ID.
495
+ *
496
+ * Example:
497
+ *
498
+ * ```typescript
499
+ * const version = await medplum.readVersion('Patient', '123', '456');
500
+ * console.log(version);
501
+ * ```
502
+ *
503
+ * See the FHIR "vread" operation for full details: https://www.hl7.org/fhir/http.html#vread
504
+ *
505
+ * @param resourceType The FHIR resource type.
506
+ * @param id The resource ID.
507
+ * @returns The resource if available; undefined otherwise.
508
+ */
509
+ readVersion<T extends Resource>(resourceType: string, id: string, vid: string): Promise<T>;
204
510
  readPatientEverything(id: string): Promise<Bundle>;
205
- create<T extends Resource>(resource: T): Promise<T>;
511
+ /**
512
+ * Creates a new FHIR resource.
513
+ *
514
+ * The return value is the newly created resource, including the ID and meta.
515
+ *
516
+ * Example:
517
+ *
518
+ * ```typescript
519
+ * const result = await medplum.createResource({
520
+ * resourceType: 'Patient',
521
+ * name: [{
522
+ * family: 'Smith',
523
+ * given: ['John']
524
+ * }]
525
+ * });
526
+ * console.log(result.id);
527
+ * ```
528
+ *
529
+ * See the FHIR "create" operation for full details: https://www.hl7.org/fhir/http.html#create
530
+ *
531
+ * @param resource The FHIR resource to create.
532
+ * @returns The result of the create operation.
533
+ */
534
+ createResource<T extends Resource>(resource: T): Promise<T>;
535
+ /**
536
+ * Creates a FHIR `Binary` resource with the provided data content.
537
+ *
538
+ * The return value is the newly created resource, including the ID and meta.
539
+ *
540
+ * The `data` parameter can be a string or a `File` object.
541
+ *
542
+ * A `File` object often comes from a `<input type="file">` element.
543
+ *
544
+ * Example:
545
+ *
546
+ * ```typescript
547
+ * const result = await medplum.createBinary(myFile, 'test.jpg', 'image/jpeg');
548
+ * console.log(result.id);
549
+ * ```
550
+ *
551
+ * See the FHIR "create" operation for full details: https://www.hl7.org/fhir/http.html#create
552
+ *
553
+ * @param resource The FHIR resource to create.
554
+ * @returns The result of the create operation.
555
+ */
206
556
  createBinary(data: any, filename: string, contentType: string): Promise<Binary>;
207
- update<T extends Resource>(resource: T): Promise<T>;
208
- patch(resourceType: string, id: string, operations: any): Promise<any>;
557
+ /**
558
+ * Updates a FHIR resource.
559
+ *
560
+ * The return value is the updated resource, including the ID and meta.
561
+ *
562
+ * Example:
563
+ *
564
+ * ```typescript
565
+ * const result = await medplum.updateResource({
566
+ * resourceType: 'Patient',
567
+ * id: '123',
568
+ * name: [{
569
+ * family: 'Smith',
570
+ * given: ['John']
571
+ * }]
572
+ * });
573
+ * console.log(result.meta.versionId);
574
+ * ```
575
+ *
576
+ * See the FHIR "update" operation for full details: https://www.hl7.org/fhir/http.html#update
577
+ *
578
+ * @param resource The FHIR resource to update.
579
+ * @returns The result of the update operation.
580
+ */
581
+ updateResource<T extends Resource>(resource: T): Promise<T>;
582
+ /**
583
+ * Updates a FHIR resource using JSONPatch operations.
584
+ *
585
+ * The return value is the updated resource, including the ID and meta.
586
+ *
587
+ * Example:
588
+ *
589
+ * ```typescript
590
+ * const result = await medplum.patchResource('Patient', '123', [
591
+ * {op: 'replace', path: '/name/0/family', value: 'Smith'},
592
+ * ]);
593
+ * console.log(result.meta.versionId);
594
+ * ```
595
+ *
596
+ * See the FHIR "update" operation for full details: https://www.hl7.org/fhir/http.html#patch
597
+ *
598
+ * See the JSONPatch specification for full details: https://tools.ietf.org/html/rfc6902
599
+ *
600
+ * @param resourceType The FHIR resource type.
601
+ * @param id The resource ID.
602
+ * @param operations The JSONPatch operations.
603
+ * @returns The result of the patch operations.
604
+ */
605
+ patchResource<T extends Resource>(resourceType: string, id: string, operations: Operation[]): Promise<T>;
606
+ /**
607
+ * Deletes a FHIR resource by resource type and ID.
608
+ *
609
+ * Example:
610
+ *
611
+ * ```typescript
612
+ * await medplum.deleteResource('Patient', '123');
613
+ * ```
614
+ *
615
+ * See the FHIR "delete" operation for full details: https://www.hl7.org/fhir/http.html#delete
616
+ *
617
+ * @param resourceType The FHIR resource type.
618
+ * @param id The resource ID.
619
+ * @returns The result of the delete operation.
620
+ */
209
621
  deleteResource(resourceType: string, id: string): Promise<any>;
210
- graphql(query: string): Promise<any>;
622
+ graphql(query: string, options?: RequestInit): Promise<any>;
211
623
  getActiveLogin(): LoginState | undefined;
212
624
  setActiveLogin(login: LoginState): Promise<void>;
625
+ setAccessToken(accessToken: string): void;
213
626
  getLogins(): LoginState[];
214
627
  isLoading(): boolean;
215
628
  getProfile(): ProfileResource | undefined;
@@ -220,11 +633,12 @@ export declare class MedplumClient extends EventTarget {
220
633
  * @param url The URL to request.
221
634
  * @returns Promise to the response body as a blob.
222
635
  */
223
- download(url: string): Promise<Blob>;
636
+ download(url: string, options?: RequestInit): Promise<Blob>;
224
637
  /**
225
638
  * Processes an OAuth authorization code.
226
639
  * See: https://openid.net/specs/openid-connect-core-1_0.html#TokenRequest
227
640
  * @param code The authorization code received by URL parameter.
228
641
  */
229
642
  processCode(code: string): Promise<ProfileResource>;
643
+ clientCredentials(clientId: string, clientSecret: string): Promise<ProfileResource>;
230
644
  }
File without changes
@@ -1,6 +1,7 @@
1
1
  export * from './client';
2
2
  export * from './format';
3
3
  export * from './outcomes';
4
+ export * from './repo';
4
5
  export * from './search';
5
6
  export * from './searchparams';
6
7
  export * from './types';
@@ -0,0 +1,116 @@
1
+ import { Bundle, OperationOutcome, Reference, Resource } from '@medplum/fhirtypes';
2
+ import { Operation } from 'fast-json-patch';
3
+ import { MedplumClient } from './client';
4
+ import { SearchRequest } from './search';
5
+ /**
6
+ * The LegacyRepositoryResult type is a tuple of operation outcome and optional resource.
7
+ * @deprecated
8
+ */
9
+ export declare type LegacyRepositoryResult<T extends Resource | undefined> = Promise<[OperationOutcome, T | undefined]>;
10
+ /**
11
+ * The LegacyRepositoryClient is a supplementary API client that matches the legacy "Repository" API.
12
+ * The "Repository" API is deprecated and will be removed in a future release.
13
+ * This LegacyRepositoryClient is also deprecated and will be removed in a future release.
14
+ * @deprecated
15
+ */
16
+ export declare class LegacyRepositoryClient {
17
+ #private;
18
+ constructor(client: MedplumClient);
19
+ /**
20
+ * Creates a resource.
21
+ *
22
+ * See: https://www.hl7.org/fhir/http.html#create
23
+ *
24
+ * @param resource The resource to create.
25
+ * @returns Operation outcome and the new resource.
26
+ * @deprecated
27
+ */
28
+ createResource<T extends Resource>(resource: T): LegacyRepositoryResult<T>;
29
+ /**
30
+ * Returns a resource.
31
+ *
32
+ * See: https://www.hl7.org/fhir/http.html#read
33
+ *
34
+ * @param resourceType The FHIR resource type.
35
+ * @param id The FHIR resource ID.
36
+ * @returns Operation outcome and a resource.
37
+ * @deprecated
38
+ */
39
+ readResource<T extends Resource>(resourceType: string, id: string): LegacyRepositoryResult<T>;
40
+ /**
41
+ * Returns a resource by FHIR reference.
42
+ *
43
+ * See: https://www.hl7.org/fhir/http.html#read
44
+ *
45
+ * @param reference The FHIR reference.
46
+ * @returns Operation outcome and a resource.
47
+ * @deprecated
48
+ */
49
+ readReference<T extends Resource>(reference: Reference<T>): LegacyRepositoryResult<T>;
50
+ /**
51
+ * Returns resource history.
52
+ *
53
+ * See: https://www.hl7.org/fhir/http.html#history
54
+ *
55
+ * @param resourceType The FHIR resource type.
56
+ * @param id The FHIR resource ID.
57
+ * @returns Operation outcome and a history bundle.
58
+ * @deprecated
59
+ */
60
+ readHistory<T extends Resource>(resourceType: string, id: string): LegacyRepositoryResult<Bundle<T>>;
61
+ /**
62
+ * Returns a resource version.
63
+ *
64
+ * See: https://www.hl7.org/fhir/http.html#vread
65
+ *
66
+ * @param resourceType The FHIR resource type.
67
+ * @param id The FHIR resource ID.
68
+ * @param vid The version ID.
69
+ * @returns Operation outcome and a resource.
70
+ * @deprecated
71
+ */
72
+ readVersion<T extends Resource>(resourceType: string, id: string, vid: string): LegacyRepositoryResult<T>;
73
+ /**
74
+ * Updates a resource.
75
+ *
76
+ * See: https://www.hl7.org/fhir/http.html#update
77
+ *
78
+ * @param resource The resource to update.
79
+ * @returns Operation outcome and the updated resource.
80
+ * @deprecated
81
+ */
82
+ updateResource<T extends Resource>(resource: T): LegacyRepositoryResult<T>;
83
+ /**
84
+ * Deletes a resource.
85
+ *
86
+ * See: https://www.hl7.org/fhir/http.html#delete
87
+ *
88
+ * @param resourceType The FHIR resource type.
89
+ * @param id The resource ID.
90
+ * @returns Operation outcome.
91
+ * @deprecated
92
+ */
93
+ deleteResource(resourceType: string, id: string): LegacyRepositoryResult<undefined>;
94
+ /**
95
+ * Patches a resource.
96
+ *
97
+ * See: https://www.hl7.org/fhir/http.html#patch
98
+ *
99
+ * @param resourceType The FHIR resource type.
100
+ * @param id The resource ID.
101
+ * @param patch Array of JSONPatch operations.
102
+ * @returns Operation outcome and the resource.
103
+ * @deprecated
104
+ */
105
+ patchResource(resourceType: string, id: string, patch: Operation[]): LegacyRepositoryResult<Resource>;
106
+ /**
107
+ * Searches for resources.
108
+ *
109
+ * See: https://www.hl7.org/fhir/http.html#search
110
+ *
111
+ * @param searchRequest The search request.
112
+ * @returns The search result bundle.
113
+ * @deprecated
114
+ */
115
+ search<T extends Resource>(query: SearchRequest | string): LegacyRepositoryResult<Bundle<T>>;
116
+ }
@@ -1,12 +1,12 @@
1
1
  export interface SearchRequest {
2
2
  readonly resourceType: string;
3
- readonly filters?: Filter[];
4
- readonly sortRules?: SortRule[];
5
- readonly page?: number;
6
- readonly count?: number;
7
- readonly fields?: string[];
8
- readonly name?: string;
9
- readonly total?: 'none' | 'estimate' | 'accurate';
3
+ filters?: Filter[];
4
+ sortRules?: SortRule[];
5
+ page?: number;
6
+ count?: number;
7
+ fields?: string[];
8
+ name?: string;
9
+ total?: 'none' | 'estimate' | 'accurate';
10
10
  }
11
11
  export interface Filter {
12
12
  code: string;
@@ -48,13 +48,10 @@ export declare enum Operator {
48
48
  *
49
49
  * See the FHIR search spec: http://hl7.org/fhir/r4/search.html
50
50
  *
51
- * @param location The URL to parse.
51
+ * @param url The URL to parse.
52
52
  * @returns Parsed search definition.
53
53
  */
54
- export declare function parseSearchDefinition(location: {
55
- pathname: string;
56
- search?: string;
57
- }): SearchRequest;
54
+ export declare function parseSearchDefinition(url: string): SearchRequest;
58
55
  /**
59
56
  * Formats a search definition object into a query string.
60
57
  * Note: The return value does not include the resource type.
@@ -44,6 +44,27 @@ export declare function getImageSrc(resource: Resource): string | undefined;
44
44
  * @returns A Date object.
45
45
  */
46
46
  export declare function getDateProperty(date: string | undefined): Date | undefined;
47
+ /**
48
+ * Calculates the age in years from the birth date.
49
+ * @param birthDateStr The birth date or start date in ISO-8601 format YYYY-MM-DD.
50
+ * @param endDateStr Optional end date in ISO-8601 format YYYY-MM-DD. Default value is today.
51
+ * @returns The age in years, months, and days.
52
+ */
53
+ export declare function calculateAge(birthDateStr: string, endDateStr?: string): {
54
+ years: number;
55
+ months: number;
56
+ days: number;
57
+ };
58
+ /**
59
+ * Calculates the age string for display using the age appropriate units.
60
+ * If the age is greater than or equal to 2 years, then the age is displayed in years.
61
+ * If the age is greater than or equal to 1 month, then the age is displayed in months.
62
+ * Otherwise, the age is displayed in days.
63
+ * @param birthDateStr The birth date or start date in ISO-8601 format YYYY-MM-DD.
64
+ * @param endDateStr Optional end date in ISO-8601 format YYYY-MM-DD. Default value is today.
65
+ * @returns The age string.
66
+ */
67
+ export declare function calculateAgeString(birthDateStr: string, endDateStr?: string): string | undefined;
47
68
  /**
48
69
  * FHIR JSON stringify.
49
70
  * Removes properties with empty string values.