@oystehr/sdk 4.2.5 → 4.3.1

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 (51) hide show
  1. package/README.md +30 -1
  2. package/dist/cjs/client/client.cjs +35 -7
  3. package/dist/cjs/client/client.cjs.map +1 -1
  4. package/dist/cjs/index.min.cjs +1 -1
  5. package/dist/cjs/index.min.cjs.map +1 -1
  6. package/dist/cjs/resources/classes/erx.cjs +8 -0
  7. package/dist/cjs/resources/classes/erx.cjs.map +1 -1
  8. package/dist/cjs/resources/classes/erx.d.ts +13 -1
  9. package/dist/cjs/resources/classes/fhir-ext.cjs +39 -10
  10. package/dist/cjs/resources/classes/fhir-ext.cjs.map +1 -1
  11. package/dist/cjs/resources/classes/fhir-ext.d.ts +8 -8
  12. package/dist/cjs/resources/classes/fhir.d.ts +2 -2
  13. package/dist/cjs/resources/types/ErxGetMedicationParams.d.ts +5 -0
  14. package/dist/cjs/resources/types/ErxGetMedicationResponse.d.ts +39 -0
  15. package/dist/cjs/resources/types/ErxSearchPharmaciesParams.d.ts +1 -0
  16. package/dist/cjs/resources/types/ZambdaCreateParams.d.ts +1 -1
  17. package/dist/cjs/resources/types/ZambdaExecuteResult.d.ts +6 -0
  18. package/dist/cjs/resources/types/ZambdaUpdateParams.d.ts +1 -1
  19. package/dist/cjs/resources/types/fhir.d.ts +20 -0
  20. package/dist/cjs/resources/types/index.d.ts +2 -0
  21. package/dist/esm/client/client.js +35 -7
  22. package/dist/esm/client/client.js.map +1 -1
  23. package/dist/esm/index.min.js +1 -1
  24. package/dist/esm/index.min.js.map +1 -1
  25. package/dist/esm/resources/classes/erx.d.ts +13 -1
  26. package/dist/esm/resources/classes/erx.js +8 -0
  27. package/dist/esm/resources/classes/erx.js.map +1 -1
  28. package/dist/esm/resources/classes/fhir-ext.d.ts +8 -8
  29. package/dist/esm/resources/classes/fhir-ext.js +39 -10
  30. package/dist/esm/resources/classes/fhir-ext.js.map +1 -1
  31. package/dist/esm/resources/classes/fhir.d.ts +2 -2
  32. package/dist/esm/resources/types/ErxGetMedicationParams.d.ts +5 -0
  33. package/dist/esm/resources/types/ErxGetMedicationResponse.d.ts +39 -0
  34. package/dist/esm/resources/types/ErxSearchPharmaciesParams.d.ts +1 -0
  35. package/dist/esm/resources/types/ZambdaCreateParams.d.ts +1 -1
  36. package/dist/esm/resources/types/ZambdaExecuteResult.d.ts +6 -0
  37. package/dist/esm/resources/types/ZambdaUpdateParams.d.ts +1 -1
  38. package/dist/esm/resources/types/fhir.d.ts +20 -0
  39. package/dist/esm/resources/types/index.d.ts +2 -0
  40. package/package.json +1 -1
  41. package/src/client/client.ts +37 -6
  42. package/src/resources/classes/erx.ts +25 -0
  43. package/src/resources/classes/fhir-ext.ts +69 -23
  44. package/src/resources/types/ErxGetMedicationParams.ts +7 -0
  45. package/src/resources/types/ErxGetMedicationResponse.ts +41 -0
  46. package/src/resources/types/ErxSearchPharmaciesParams.ts +1 -0
  47. package/src/resources/types/ZambdaCreateParams.ts +1 -1
  48. package/src/resources/types/ZambdaExecuteResult.ts +6 -0
  49. package/src/resources/types/ZambdaUpdateParams.ts +1 -1
  50. package/src/resources/types/fhir.ts +13 -0
  51. package/src/resources/types/index.ts +2 -0
@@ -1,6 +1,7 @@
1
1
  import { Address as AddressR4B, HumanName as HumanNameR4B } from 'fhir/r4b';
2
2
  import { Address as AddressR5, HumanName as HumanNameR5 } from 'fhir/r5';
3
3
  import {
4
+ BatchBundle,
4
5
  BatchInput,
5
6
  BatchInputRequest,
6
7
  Binary,
@@ -14,8 +15,11 @@ import {
14
15
  FhirHistorySearchParams,
15
16
  FhirPatchParams,
16
17
  FhirResource,
18
+ FhirResourceReturnValue,
17
19
  FhirSearchParams,
18
20
  FhirUpdateParams,
21
+ OperationOutcome,
22
+ TransactionBundle,
19
23
  } from '../..';
20
24
  import { addParamsToSearch, FhirFetcherResponse, OystehrClientRequest, SDKResource } from '../../client/client';
21
25
 
@@ -79,7 +83,9 @@ export async function search<T extends FhirResource>(
79
83
  ...requestBundle,
80
84
  entry: requestBundle.entry as Array<BundleEntry<T>> | undefined,
81
85
  unbundle: function (this: { entry?: Array<BundleEntry<T>> | undefined }) {
82
- return this.entry?.map((entry) => entry.resource).filter((entry): entry is T => entry !== undefined) ?? [];
86
+ return (
87
+ this.entry?.map((entry) => entry.resource).filter((resource): resource is T => resource !== undefined) ?? []
88
+ );
83
89
  },
84
90
  };
85
91
  return bundle;
@@ -89,7 +95,7 @@ export async function create<T extends FhirResource>(
89
95
  this: SDKResource,
90
96
  params: FhirCreateParams<T>,
91
97
  request?: OystehrClientRequest
92
- ): Promise<FhirFetcherResponse<T>> {
98
+ ): Promise<FhirFetcherResponse<FhirResourceReturnValue<T>>> {
93
99
  const { resourceType } = params;
94
100
  return this.fhirRequest(`/${resourceType}`, 'POST')(params as unknown as Record<string, unknown>, request);
95
101
  }
@@ -98,15 +104,15 @@ export async function get<T extends FhirResource>(
98
104
  this: SDKResource,
99
105
  { resourceType, id }: FhirGetParams<T>,
100
106
  request?: OystehrClientRequest
101
- ): Promise<FhirFetcherResponse<T>> {
102
- return this.fhirRequest<T>(`/${resourceType}/${id}`, 'GET')({}, request);
107
+ ): Promise<FhirFetcherResponse<FhirResourceReturnValue<T>>> {
108
+ return this.fhirRequest<FhirResourceReturnValue<T>>(`/${resourceType}/${id}`, 'GET')({}, request);
103
109
  }
104
110
 
105
111
  export async function update<T extends FhirResource>(
106
112
  this: SDKResource,
107
113
  params: FhirUpdateParams<T>,
108
114
  request?: OystehrFHIRUpdateClientRequest
109
- ): Promise<FhirFetcherResponse<T>> {
115
+ ): Promise<FhirFetcherResponse<FhirResourceReturnValue<T>>> {
110
116
  const { id, resourceType } = params;
111
117
  return this.fhirRequest(`/${resourceType}/${id}`, 'PUT')(params as unknown as Record<string, unknown>, {
112
118
  ...request,
@@ -118,7 +124,7 @@ export async function patch<T extends FhirResource>(
118
124
  this: SDKResource,
119
125
  { resourceType, id, operations }: FhirPatchParams<T>,
120
126
  request?: OystehrFHIRUpdateClientRequest
121
- ): Promise<FhirFetcherResponse<T>> {
127
+ ): Promise<FhirFetcherResponse<FhirResourceReturnValue<T>>> {
122
128
  return this.fhirRequest(`/${resourceType}/${id}`, 'PATCH')(operations, {
123
129
  ...request,
124
130
  contentType: 'application/json-patch+json',
@@ -130,7 +136,7 @@ async function del<T extends FhirResource>(
130
136
  this: SDKResource,
131
137
  { resourceType, id }: FhirDeleteParams<T>,
132
138
  request?: OystehrClientRequest
133
- ): Promise<FhirFetcherResponse<T>> {
139
+ ): Promise<FhirFetcherResponse<FhirResourceReturnValue<T>>> {
134
140
  return this.fhirRequest(`/${resourceType}/${id}`, 'DELETE')({}, request);
135
141
  }
136
142
  export { del as delete };
@@ -269,25 +275,65 @@ function batchInputRequestToBundleEntryItem<T extends FhirResource>(
269
275
  throw new Error('Unrecognized method');
270
276
  }
271
277
 
272
- function bundleRequest(type: 'batch' | 'transaction') {
273
- return async function <BundleContentType extends FhirResource>(
274
- this: SDKResource,
275
- input: BatchInput<BundleContentType>,
276
- request?: OystehrClientRequest
277
- ): Promise<FhirFetcherResponse<Bundle<BundleContentType>>> {
278
- return this.fhirRequest('/', 'POST')(
279
- {
280
- resourceType: 'Bundle',
281
- type,
282
- entry: input.requests.map(batchInputRequestToBundleEntryItem),
283
- },
284
- request
285
- );
278
+ export async function batch<BundleContentType extends FhirResource>(
279
+ this: SDKResource,
280
+ input: BatchInput<BundleContentType>,
281
+ request?: OystehrClientRequest
282
+ ): Promise<FhirFetcherResponse<BatchBundle<BundleContentType>>> {
283
+ const resp = await this.fhirRequest('/', 'POST')(
284
+ {
285
+ resourceType: 'Bundle',
286
+ type: 'batch',
287
+ entry: input.requests.map(batchInputRequestToBundleEntryItem),
288
+ },
289
+ request
290
+ );
291
+ const bundle: BatchBundle<BundleContentType> = {
292
+ ...resp,
293
+ entry: resp.entry as Array<BundleEntry<BundleContentType>> | undefined,
294
+ unbundle: function (this: { entry?: Array<BundleEntry<BundleContentType>> | undefined }) {
295
+ return (
296
+ this.entry
297
+ ?.map((entry) => entry.resource)
298
+ .filter((resource): resource is BundleContentType => resource !== undefined) ?? []
299
+ );
300
+ },
301
+ errors: function (this: { entry?: Array<BundleEntry<BundleContentType>> | undefined }) {
302
+ return this.entry
303
+ ?.filter((entry) => entry.response?.status?.startsWith('4') || entry.response?.status?.startsWith('5'))
304
+ .map((entry) => entry.response?.outcome)
305
+ .filter((outcome): outcome is OperationOutcome => outcome !== undefined);
306
+ },
286
307
  };
308
+ return bundle;
287
309
  }
288
310
 
289
- export const batch = bundleRequest('batch');
290
- export const transaction = bundleRequest('transaction');
311
+ export async function transaction<BundleContentType extends FhirResource>(
312
+ this: SDKResource,
313
+ input: BatchInput<BundleContentType>,
314
+ request?: OystehrClientRequest
315
+ ): Promise<FhirFetcherResponse<TransactionBundle<BundleContentType>>> {
316
+ const resp = await this.fhirRequest('/', 'POST')(
317
+ {
318
+ resourceType: 'Bundle',
319
+ type: 'transaction',
320
+ entry: input.requests.map(batchInputRequestToBundleEntryItem),
321
+ },
322
+ request
323
+ );
324
+ const bundle: TransactionBundle<BundleContentType> = {
325
+ ...resp,
326
+ entry: resp.entry as Array<BundleEntry<BundleContentType>> | undefined,
327
+ unbundle: function (this: { entry?: Array<BundleEntry<BundleContentType>> | undefined }) {
328
+ return (
329
+ this.entry
330
+ ?.map((entry) => entry.resource)
331
+ .filter((resource): resource is BundleContentType => resource !== undefined) ?? []
332
+ );
333
+ },
334
+ };
335
+ return bundle;
336
+ }
291
337
 
292
338
  export function formatAddress(
293
339
  address: AddressR4B | AddressR5,
@@ -0,0 +1,7 @@
1
+ // AUTOGENERATED -- DO NOT EDIT
2
+
3
+ export interface ErxGetMedicationParams {
4
+ drugId?: number;
5
+ ndc?: string;
6
+ rxcui?: number;
7
+ }
@@ -0,0 +1,41 @@
1
+ // AUTOGENERATED -- DO NOT EDIT
2
+
3
+ /**
4
+ * Medication
5
+ */
6
+ export interface ErxGetMedicationResponse {
7
+ /**
8
+ * The Medi-Span identifier for the medication.
9
+ */
10
+ id: number;
11
+ /**
12
+ * RxNorm Concept Unique (RxCUI) identifier of medication.
13
+ */
14
+ ndc?: string | null;
15
+ /**
16
+ * RxNorm Concept Unique (RxCUI) identifier of medication.
17
+ */
18
+ rxcui?: number | null;
19
+ /**
20
+ * Human readable name of medication.
21
+ */
22
+ name: string;
23
+ /**
24
+ * Alternative human readable name of medication.
25
+ */
26
+ displayName?: string;
27
+ route?: string;
28
+ doseForm?: string;
29
+ strength?: string;
30
+ dispenseUnit?: string;
31
+ isBrandName: boolean;
32
+ genericName?: string | null;
33
+ isOtc: boolean;
34
+ classification?: string;
35
+ schedule?: number;
36
+ stateSchedules?: {
37
+ name: string;
38
+ schedule?: number;
39
+ }[];
40
+ isObsolete: boolean;
41
+ }
@@ -1,6 +1,7 @@
1
1
  // AUTOGENERATED -- DO NOT EDIT
2
2
 
3
3
  export interface ErxSearchPharmaciesParams {
4
+ name?: string;
4
5
  address?: string;
5
6
  city?: string;
6
7
  state?: string;
@@ -15,7 +15,7 @@ export interface ZambdaCreateParams {
15
15
  /**
16
16
  * The runtime to use for the Zambda Function.
17
17
  */
18
- runtime: 'nodejs20.x' | 'nodejs22.x' | 'python3.13' | 'python3.12' | 'java21' | 'dotnet8' | 'ruby3.3';
18
+ runtime: 'nodejs20.x' | 'nodejs22.x' | 'nodejs24.x' | 'python3.13' | 'python3.12' | 'java21' | 'dotnet8' | 'ruby3.3';
19
19
  /**
20
20
  * The amount of memory in MB to allocate to the Zambda Function. If not specified, a system default (1024MB) will be used. Min: 128MB, Max: 10240MB.
21
21
  */
@@ -16,4 +16,10 @@ export interface ZambdaExecuteResult {
16
16
  | string
17
17
  | number
18
18
  | null;
19
+ /**
20
+ * Optional HTTP headers returned by the Zambda Function
21
+ */
22
+ headers?: {
23
+ [k: string]: any;
24
+ };
19
25
  }
@@ -15,7 +15,7 @@ export interface ZambdaUpdateParams {
15
15
  /**
16
16
  * The runtime to use for the Zambda Function.
17
17
  */
18
- runtime?: 'nodejs20.x' | 'nodejs22.x' | 'python3.13' | 'python3.12' | 'java21' | 'dotnet8' | 'ruby3.3';
18
+ runtime?: 'nodejs20.x' | 'nodejs22.x' | 'nodejs24.x' | 'python3.13' | 'python3.12' | 'java21' | 'dotnet8' | 'ruby3.3';
19
19
  /**
20
20
  * The amount of memory in MB to allocate to the Zambda Function. If not specified, a system default (1024MB) will be used. Min: 128MB, Max: 10240MB.
21
21
  */
@@ -34,12 +34,25 @@ export type Bundle<F extends FhirResource> = EntrylessFhirBundle<F> & {
34
34
  entry?: Array<BundleEntry<F>> | undefined;
35
35
  unbundle: (this: { entry?: Array<BundleEntry<F>> }) => F[];
36
36
  };
37
+ export type BatchBundle<F extends FhirResource> = EntrylessFhirBundle<F> & {
38
+ entry?: Array<BundleEntry<F>> | undefined;
39
+ unbundle: (this: { entry?: Array<BundleEntry<F>> }) => F[];
40
+ errors: (this: { entry?: Array<BundleEntry<F>> }) => OperationOutcome[] | undefined;
41
+ };
42
+ export type TransactionBundle<F extends FhirResource> = EntrylessFhirBundle<F> & {
43
+ entry?: Array<BundleEntry<F>> | undefined;
44
+ unbundle: (this: { entry?: Array<BundleEntry<F>> }) => F[];
45
+ };
37
46
  export type BundleEntry<F extends FhirResource> = F extends FhirResourceR4B ? BundleEntryR4B<F> : BundleEntryR5<F>;
38
47
  export type Binary<F extends FhirResource> = F extends FhirResourceR4B ? BinaryR4B : BinaryR5;
39
48
  export type OperationOutcome = OperationOutcomeR4B | OperationOutcomeR5;
40
49
 
41
50
  export type SearchParam = { name: string; value: string | number };
42
51
 
52
+ export type FhirResourceReturnValue<T extends FhirResource> = T extends { id?: string | undefined }
53
+ ? Omit<T, 'id'> & { id: string }
54
+ : T;
55
+
43
56
  export interface FhirSearchParams<T extends FhirResource> {
44
57
  resourceType: T['resourceType'];
45
58
  params?: SearchParam[];
@@ -177,6 +177,8 @@ export * from './ErxSearchAllergensParams';
177
177
  export * from './ErxSearchAllergensResponse';
178
178
  export * from './ErxSearchMedicationsParams';
179
179
  export * from './ErxSearchMedicationsResponse';
180
+ export * from './ErxGetMedicationParams';
181
+ export * from './ErxGetMedicationResponse';
180
182
  export * from './ErxGetConfigurationResponse';
181
183
  export * from './ErxCheckAllergyInteractionsParams';
182
184
  export * from './ErxCheckAllergyInteractionsResponse';