@oystehr/sdk 4.3.10 → 4.3.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.
- package/dist/cjs/client/client.cjs +12 -5
- package/dist/cjs/client/client.cjs.map +1 -1
- package/dist/cjs/client/client.d.ts +5 -0
- package/dist/cjs/index.min.cjs +1 -1
- package/dist/cjs/index.min.cjs.map +1 -1
- package/dist/cjs/resources/classes/fhir-ext.cjs +27 -4
- package/dist/cjs/resources/classes/fhir-ext.cjs.map +1 -1
- package/dist/cjs/resources/classes/fhir-ext.d.ts +23 -3
- package/dist/cjs/resources/types/fhir.d.ts +13 -0
- package/dist/esm/client/client.d.ts +5 -0
- package/dist/esm/client/client.js +12 -5
- package/dist/esm/client/client.js.map +1 -1
- package/dist/esm/index.min.js +1 -1
- package/dist/esm/index.min.js.map +1 -1
- package/dist/esm/resources/classes/fhir-ext.d.ts +23 -3
- package/dist/esm/resources/classes/fhir-ext.js +27 -4
- package/dist/esm/resources/classes/fhir-ext.js.map +1 -1
- package/dist/esm/resources/types/fhir.d.ts +13 -0
- package/package.json +1 -1
- package/src/client/client.ts +22 -8
- package/src/resources/classes/fhir-ext.ts +52 -7
- package/src/resources/types/fhir.ts +13 -0
|
@@ -267,6 +267,43 @@ export interface OystehrFHIRUpdateClientRequest extends OystehrClientRequest {
|
|
|
267
267
|
optimisticLockingVersionId?: string;
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
+
/**
|
|
271
|
+
* Optional parameter that can be passed to the FHIR create method. In addition
|
|
272
|
+
* to the standard request options, it supports FHIR conditional create via the
|
|
273
|
+
* 'If-None-Exist' header.
|
|
274
|
+
*/
|
|
275
|
+
export interface OystehrFHIRCreateClientRequest extends OystehrClientRequest {
|
|
276
|
+
/**
|
|
277
|
+
* Perform a FHIR conditional create using the 'If-None-Exist' header. The value is a
|
|
278
|
+
* FHIR search query that identifies whether a matching resource already exists:
|
|
279
|
+
* - if no resource matches, the resource is created as normal;
|
|
280
|
+
* - if exactly one resource matches, no resource is created and the existing one is returned;
|
|
281
|
+
* - if more than one resource matches, the request fails with a 412 Precondition Failed error.
|
|
282
|
+
*
|
|
283
|
+
* Accepts either a raw search query string (e.g. `'identifier=http://acme.org|1234'`) or an
|
|
284
|
+
* array of SearchParam objects (e.g. `[{ name: 'identifier', value: 'http://acme.org|1234' }]`).
|
|
285
|
+
*
|
|
286
|
+
* @see https://www.hl7.org/fhir/http.html#cond-update for the conditional create specification.
|
|
287
|
+
*/
|
|
288
|
+
ifNoneExist?: string | SearchParam[];
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Serializes an If-None-Exist value into a FHIR search query string. A raw string is
|
|
293
|
+
* returned unchanged; an array of SearchParam objects is encoded as a query string
|
|
294
|
+
* (e.g. "identifier=sys|123&active=true").
|
|
295
|
+
*/
|
|
296
|
+
function ifNoneExistToString(value: string | SearchParam[]): string {
|
|
297
|
+
if (typeof value === 'string') {
|
|
298
|
+
return value;
|
|
299
|
+
}
|
|
300
|
+
const search = new URLSearchParams();
|
|
301
|
+
for (const param of value) {
|
|
302
|
+
search.append(param.name, String(param.value));
|
|
303
|
+
}
|
|
304
|
+
return search.toString();
|
|
305
|
+
}
|
|
306
|
+
|
|
270
307
|
function isAsyncRequestMode(mode: FhirResponseMode | undefined): mode is Exclude<FhirResponseMode, 'sync'> {
|
|
271
308
|
return mode === 'async-bundle' || mode === 'async-bulk';
|
|
272
309
|
}
|
|
@@ -385,34 +422,38 @@ export async function searchAndGetAllPages<T extends FhirResource>(
|
|
|
385
422
|
export async function create<T extends FhirResource>(
|
|
386
423
|
this: SDKResource,
|
|
387
424
|
params: FhirCreateParams<T>,
|
|
388
|
-
request:
|
|
425
|
+
request: OystehrFHIRCreateClientRequest & { mode: Exclude<FhirResponseMode, 'sync'> }
|
|
389
426
|
): Promise<FhirAsyncJobHandle>;
|
|
390
427
|
export async function create<T extends FhirResource>(
|
|
391
428
|
this: SDKResource,
|
|
392
429
|
params: FhirCreateParams<T>,
|
|
393
|
-
request?:
|
|
430
|
+
request?: OystehrFHIRCreateClientRequest & { mode?: 'sync' | undefined }
|
|
394
431
|
): Promise<FhirFetcherResponse<FhirResourceReturnValue<T>>>;
|
|
395
432
|
export async function create<T extends FhirResource>(
|
|
396
433
|
this: SDKResource,
|
|
397
434
|
params: FhirCreateParams<T>,
|
|
398
|
-
request?:
|
|
435
|
+
request?: OystehrFHIRCreateClientRequest
|
|
399
436
|
): Promise<FhirFetcherResponse<FhirResourceReturnValue<T>> | FhirAsyncJobHandle> {
|
|
400
437
|
const tagged = applyTagToResource(this.config, params);
|
|
401
438
|
const { resourceType } = tagged;
|
|
402
439
|
const requestMode = request?.mode;
|
|
440
|
+
const ifNoneExistRequest = {
|
|
441
|
+
...request,
|
|
442
|
+
ifNoneExist: request?.ifNoneExist !== undefined ? ifNoneExistToString(request.ifNoneExist) : undefined,
|
|
443
|
+
};
|
|
403
444
|
if (isAsyncRequestMode(requestMode)) {
|
|
404
445
|
return await this.startAsyncJob(
|
|
405
446
|
`/${resourceType}`,
|
|
406
447
|
'POST',
|
|
407
448
|
tagged as unknown as Record<string, unknown>,
|
|
408
449
|
requestMode,
|
|
409
|
-
|
|
450
|
+
ifNoneExistRequest
|
|
410
451
|
);
|
|
411
452
|
}
|
|
412
453
|
|
|
413
454
|
return await this.fhirRequest<FhirResourceReturnValue<T>>(`/${resourceType}`, 'POST')(
|
|
414
455
|
tagged as unknown as Record<string, unknown>,
|
|
415
|
-
|
|
456
|
+
ifNoneExistRequest
|
|
416
457
|
);
|
|
417
458
|
}
|
|
418
459
|
|
|
@@ -946,9 +987,13 @@ function batchInputRequestToBundleEntryItem<T extends FhirResource>(
|
|
|
946
987
|
// POST creates require a full resource
|
|
947
988
|
if (method === 'POST' && 'resource' in request) {
|
|
948
989
|
const resource = applyTagToResource(config, request.resource);
|
|
949
|
-
const { fullUrl } = request;
|
|
990
|
+
const { fullUrl, ifNoneExist } = request;
|
|
950
991
|
return {
|
|
951
|
-
|
|
992
|
+
request: {
|
|
993
|
+
...baseRequest.request,
|
|
994
|
+
// Conditional create: only create the resource if no existing resource matches the query.
|
|
995
|
+
ifNoneExist: ifNoneExist !== undefined ? ifNoneExistToString(ifNoneExist) : undefined,
|
|
996
|
+
},
|
|
952
997
|
resource: resource as T,
|
|
953
998
|
fullUrl,
|
|
954
999
|
} as BundleEntry<T>;
|
|
@@ -127,6 +127,19 @@ export interface BatchInputPostRequest<F extends FhirResource> extends BatchInpu
|
|
|
127
127
|
method: 'POST';
|
|
128
128
|
resource: F;
|
|
129
129
|
fullUrl?: string;
|
|
130
|
+
/**
|
|
131
|
+
* Perform a FHIR conditional create for this entry using the bundle entry's `ifNoneExist`
|
|
132
|
+
* field. The value is a FHIR search query that identifies whether a matching resource already
|
|
133
|
+
* exists: if no resource matches, the resource is created; if exactly one matches, no resource
|
|
134
|
+
* is created and the existing one is returned; if more than one matches, the entry fails with a
|
|
135
|
+
* 412 Precondition Failed error.
|
|
136
|
+
*
|
|
137
|
+
* Accepts either a raw search query string (e.g. `'identifier=http://acme.org|1234'`) or an
|
|
138
|
+
* array of SearchParam objects (e.g. `[{ name: 'identifier', value: 'http://acme.org|1234' }]`).
|
|
139
|
+
*
|
|
140
|
+
* @see https://www.hl7.org/fhir/http.html#cond-update
|
|
141
|
+
*/
|
|
142
|
+
ifNoneExist?: string | SearchParam[];
|
|
130
143
|
}
|
|
131
144
|
|
|
132
145
|
/**
|