@medplum/core 0.9.8 → 0.9.11

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.
@@ -1,10 +1,9 @@
1
- /// <reference types="node" />
2
- import { Binary, Bundle, Communication, OperationOutcome, Project, ProjectMembership, Reference, Resource, UserConfiguration, ValueSet } from '@medplum/fhirtypes';
1
+ import { Binary, Bundle, Communication, ExtractResource, OperationOutcome, Project, ProjectMembership, Reference, Resource, ResourceType, UserConfiguration, ValueSet } from '@medplum/fhirtypes';
2
+ /** @ts-ignore */
3
3
  import type { CustomTableLayout, TDocumentDefinitions, TFontDictionary } from 'pdfmake/interfaces';
4
4
  import { EventTarget } from './eventtarget';
5
5
  import { Hl7Message } from './hl7';
6
6
  import { ReadablePromise } from './readablepromise';
7
- import { SearchRequest } from './search';
8
7
  import { IndexedStructureDefinition } from './types';
9
8
  import { ProfileResource } from './utils';
10
9
  /**
@@ -67,6 +66,46 @@ export interface MedplumClientOptions {
67
66
  * For nodejs applications, consider the 'node-fetch' package.
68
67
  */
69
68
  fetch?: FetchLike;
69
+ /**
70
+ * Create PDF implementation.
71
+ *
72
+ * Default is none, and PDF generation is disabled.
73
+ *
74
+ * In browser environments, import the client-side pdfmake library.
75
+ *
76
+ * ```html
77
+ * <script src="pdfmake.min.js"></script>
78
+ * <script>
79
+ * async function createPdf(docDefinition, tableLayouts, fonts) {
80
+ * return new Promise((resolve) => {
81
+ * pdfMake.createPdf(docDefinition, tableLayouts, fonts).getBlob(resolve);
82
+ * });
83
+ * }
84
+ * </script>
85
+ * ```
86
+ *
87
+ * In nodejs applications:
88
+ *
89
+ * ```ts
90
+ * import type { CustomTableLayout, TDocumentDefinitions, TFontDictionary } from 'pdfmake/interfaces';
91
+ * function createPdf(
92
+ * docDefinition: TDocumentDefinitions,
93
+ * tableLayouts?: { [name: string]: CustomTableLayout },
94
+ * fonts?: TFontDictionary
95
+ * ): Promise<Buffer> {
96
+ * return new Promise((resolve, reject) => {
97
+ * const printer = new PdfPrinter(fonts || {});
98
+ * const pdfDoc = printer.createPdfKitDocument(docDefinition, { tableLayouts });
99
+ * const chunks: Uint8Array[] = [];
100
+ * pdfDoc.on('data', (chunk: Uint8Array) => chunks.push(chunk));
101
+ * pdfDoc.on('end', () => resolve(Buffer.concat(chunks)));
102
+ * pdfDoc.on('error', reject);
103
+ * pdfDoc.end();
104
+ * });
105
+ * }
106
+ * ```
107
+ */
108
+ createPdf?: CreatePdfFunction;
70
109
  /**
71
110
  * Callback for when the client is unauthenticated.
72
111
  *
@@ -79,6 +118,11 @@ export interface MedplumClientOptions {
79
118
  export interface FetchLike {
80
119
  (url: string, options?: any): Promise<any>;
81
120
  }
121
+ export interface CreatePdfFunction {
122
+ (docDefinition: TDocumentDefinitions, tableLayouts?: {
123
+ [name: string]: CustomTableLayout;
124
+ } | undefined, fonts?: TFontDictionary | undefined): Promise<any>;
125
+ }
82
126
  export interface LoginRequest {
83
127
  readonly email: string;
84
128
  readonly password: string;
@@ -257,7 +301,7 @@ export declare class MedplumClient extends EventTarget {
257
301
  * Invalidates all cached search results or cached requests for the given resourceType.
258
302
  * @param resourceType The resource type to invalidate.
259
303
  */
260
- invalidateSearches(resourceType: string): void;
304
+ invalidateSearches<K extends ResourceType>(resourceType: K): void;
261
305
  /**
262
306
  * Makes an HTTP GET request to the specified URL.
263
307
  *
@@ -371,7 +415,7 @@ export declare class MedplumClient extends EventTarget {
371
415
  * @param query The FHIR search query or structured query object.
372
416
  * @returns The well-formed FHIR URL.
373
417
  */
374
- fhirSearchUrl(query: string | SearchRequest): URL;
418
+ fhirSearchUrl(resourceType: ResourceType, query: URLSearchParams | string): URL;
375
419
  /**
376
420
  * Sends a FHIR search request.
377
421
  *
@@ -426,7 +470,7 @@ export declare class MedplumClient extends EventTarget {
426
470
  * @param query The search query as either a string or a structured search object.
427
471
  * @returns Promise to the search result bundle.
428
472
  */
429
- search<T extends Resource>(query: string | SearchRequest, options?: RequestInit): ReadablePromise<Bundle<T>>;
473
+ search<K extends ResourceType>(resourceType: K, query: URLSearchParams | string, options?: RequestInit): ReadablePromise<Bundle<ExtractResource<K>>>;
430
474
  /**
431
475
  * Sends a FHIR search request for a single resource.
432
476
  *
@@ -446,7 +490,7 @@ export declare class MedplumClient extends EventTarget {
446
490
  * @param query The search query as either a string or a structured search object.
447
491
  * @returns Promise to the search result bundle.
448
492
  */
449
- searchOne<T extends Resource>(query: string | SearchRequest, options?: RequestInit): ReadablePromise<T | undefined>;
493
+ searchOne<K extends ResourceType>(resourceType: K, query: URLSearchParams | string, options?: RequestInit): ReadablePromise<ExtractResource<K> | undefined>;
450
494
  /**
451
495
  * Sends a FHIR search request for an array of resources.
452
496
  *
@@ -466,7 +510,7 @@ export declare class MedplumClient extends EventTarget {
466
510
  * @param query The search query as either a string or a structured search object.
467
511
  * @returns Promise to the search result bundle.
468
512
  */
469
- searchResources<T extends Resource>(query: string | SearchRequest, options?: RequestInit): ReadablePromise<T[]>;
513
+ searchResources<K extends ResourceType>(resourceType: K, query: URLSearchParams | string, options?: RequestInit): ReadablePromise<ExtractResource<K>[]>;
470
514
  /**
471
515
  * Searches a ValueSet resource using the "expand" operation.
472
516
  * See: https://www.hl7.org/fhir/operation-valueset-expand.html
@@ -481,7 +525,7 @@ export declare class MedplumClient extends EventTarget {
481
525
  * @param id The FHIR resource ID.
482
526
  * @returns The resource if it is available in the cache; undefined otherwise.
483
527
  */
484
- getCached<T extends Resource>(resourceType: string, id: string): T | undefined;
528
+ getCached<K extends ResourceType>(resourceType: K, id: string): ExtractResource<K> | undefined;
485
529
  /**
486
530
  * Returns a cached resource if it is available.
487
531
  * @param resourceType The FHIR resource type.
@@ -505,7 +549,7 @@ export declare class MedplumClient extends EventTarget {
505
549
  * @param id The resource ID.
506
550
  * @returns The resource if available; undefined otherwise.
507
551
  */
508
- readResource<T extends Resource>(resourceType: string, id: string): ReadablePromise<T>;
552
+ readResource<K extends ResourceType>(resourceType: K, id: string): ReadablePromise<ExtractResource<K>>;
509
553
  /**
510
554
  * Reads a resource by `Reference`.
511
555
  *
@@ -558,7 +602,7 @@ export declare class MedplumClient extends EventTarget {
558
602
  * @param id The resource ID.
559
603
  * @returns Promise to the resource history.
560
604
  */
561
- readHistory<T extends Resource>(resourceType: string, id: string): ReadablePromise<Bundle<T>>;
605
+ readHistory<K extends ResourceType>(resourceType: K, id: string): ReadablePromise<Bundle<ExtractResource<K>>>;
562
606
  /**
563
607
  * Reads a specific version of a resource by resource type, ID, and version ID.
564
608
  *
@@ -575,7 +619,7 @@ export declare class MedplumClient extends EventTarget {
575
619
  * @param id The resource ID.
576
620
  * @returns The resource if available; undefined otherwise.
577
621
  */
578
- readVersion<T extends Resource>(resourceType: string, id: string, vid: string): ReadablePromise<T>;
622
+ readVersion<K extends ResourceType>(resourceType: K, id: string, vid: string): ReadablePromise<ExtractResource<K>>;
579
623
  readPatientEverything(id: string): ReadablePromise<Bundle>;
580
624
  /**
581
625
  * Creates a new FHIR resource.
@@ -663,7 +707,7 @@ export declare class MedplumClient extends EventTarget {
663
707
  * @param contentType Content type for the binary.
664
708
  * @returns The result of the create operation.
665
709
  */
666
- createBinary(data: string | File | Blob | Buffer, filename: string | undefined, contentType: string): Promise<Binary>;
710
+ createBinary(data: string | File | Blob | Uint8Array, filename: string | undefined, contentType: string): Promise<Binary>;
667
711
  /**
668
712
  * Creates a PDF as a FHIR `Binary` resource based on pdfmake document definition.
669
713
  *
@@ -746,7 +790,7 @@ export declare class MedplumClient extends EventTarget {
746
790
  * @param operations The JSONPatch operations.
747
791
  * @returns The result of the patch operations.
748
792
  */
749
- patchResource<T extends Resource>(resourceType: string, id: string, operations: PatchOperation[]): Promise<T>;
793
+ patchResource<K extends ResourceType>(resourceType: K, id: string, operations: PatchOperation[]): Promise<ExtractResource<K>>;
750
794
  /**
751
795
  * Deletes a FHIR resource by resource type and ID.
752
796
  *
@@ -762,7 +806,7 @@ export declare class MedplumClient extends EventTarget {
762
806
  * @param id The resource ID.
763
807
  * @returns The result of the delete operation.
764
808
  */
765
- deleteResource(resourceType: string, id: string): Promise<any>;
809
+ deleteResource(resourceType: ResourceType, id: string): Promise<any>;
766
810
  /**
767
811
  * Sends an email using the Medplum Email API.
768
812
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medplum/core",
3
- "version": "0.9.8",
3
+ "version": "0.9.11",
4
4
  "description": "Medplum TS/JS Library",
5
5
  "author": "Medplum <hello@medplum.com>",
6
6
  "license": "Apache-2.0",
@@ -17,7 +17,7 @@
17
17
  "test": "jest"
18
18
  },
19
19
  "devDependencies": {
20
- "@medplum/fhirtypes": "0.9.8"
20
+ "@medplum/fhirtypes": "0.9.11"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "pdfmake": "0.2.5"
package/test9-2.pdf ADDED
File without changes
package/test9-3.pdf ADDED
File without changes
package/test9-4.pdf ADDED
Binary file
package/test9.pdf ADDED
File without changes
@@ -1,5 +0,0 @@
1
- /// <reference types="node" />
2
- import type { CustomTableLayout, TDocumentDefinitions, TFontDictionary } from 'pdfmake/interfaces';
3
- export declare function generatePdf(docDefinition: TDocumentDefinitions, tableLayouts?: {
4
- [name: string]: CustomTableLayout;
5
- }, fonts?: TFontDictionary): Promise<Blob | Buffer>;