@nsshunt/stsfhirclient 2.0.28 → 2.0.30
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/stsfhirclient.cjs
CHANGED
|
@@ -9228,261 +9228,6 @@ function createRetryAxiosClient(retryConfig) {
|
|
|
9228
9228
|
return instance;
|
|
9229
9229
|
}
|
|
9230
9230
|
//#endregion
|
|
9231
|
-
//#region src/cv2/fhirRESTClient.ts
|
|
9232
|
-
var FhirRESTClient = class {
|
|
9233
|
-
#options;
|
|
9234
|
-
constructor(options) {
|
|
9235
|
-
this.#options = options;
|
|
9236
|
-
}
|
|
9237
|
-
BaseUrl() {
|
|
9238
|
-
return `${this.#options.endpoint}:${this.#options.stsfhirport}${this.#options.stsfhirapiroot}`;
|
|
9239
|
-
}
|
|
9240
|
-
LogError = (method, error) => {
|
|
9241
|
-
this.#options.logger.error(`FhirRESTClient:${method}(): Error: [${error}]`);
|
|
9242
|
-
this.#options.logger.error(error);
|
|
9243
|
-
};
|
|
9244
|
-
LogWarning = (method, message) => {
|
|
9245
|
-
this.#options.logger.warn(`FhirRESTClient:${method}(): Warn: [${message}]`);
|
|
9246
|
-
};
|
|
9247
|
-
/**
|
|
9248
|
-
*
|
|
9249
|
-
* @param url
|
|
9250
|
-
* @param httpVerb
|
|
9251
|
-
* @param versionIdETag Format "W/<versionNumber", e.g. "W/3"
|
|
9252
|
-
* @param resource
|
|
9253
|
-
* @returns
|
|
9254
|
-
*/
|
|
9255
|
-
#InvokeResourceAPI = async (url, httpVerb, versionIdETag, resource, contentType) => {
|
|
9256
|
-
const accessToken = await this.#options.GetAccessToken();
|
|
9257
|
-
let requestConfig;
|
|
9258
|
-
const headers = {
|
|
9259
|
-
Prefer: "return=representation",
|
|
9260
|
-
Accept: "application/fhir+json"
|
|
9261
|
-
};
|
|
9262
|
-
if (versionIdETag && versionIdETag !== "") headers["If-Match"] = versionIdETag;
|
|
9263
|
-
if (httpVerb === "patch") {
|
|
9264
|
-
requestConfig = new _nsshunt_stsutils.STSAxiosConfig(url, httpVerb).withApplicationMergePatchAndJsonContentTypeHeaders();
|
|
9265
|
-
if (resource && contentType) {
|
|
9266
|
-
if (contentType.localeCompare("application/merge-patch+json") === 0) requestConfig = new _nsshunt_stsutils.STSAxiosConfig(url, httpVerb).withApplicationMergePatchAndJsonContentTypeHeaders();
|
|
9267
|
-
else if (contentType.localeCompare("application/json-patch+json") === 0) requestConfig = new _nsshunt_stsutils.STSAxiosConfig(url, httpVerb).withApplicationJsonPatchAndJsonContentTypeHeaders();
|
|
9268
|
-
}
|
|
9269
|
-
} else requestConfig = new _nsshunt_stsutils.STSAxiosConfig(url, httpVerb).withApplicationFhirAndJsonContentTypeHeaders();
|
|
9270
|
-
requestConfig.withAuthHeaders(accessToken, this.#options.user).withHeaders(headers);
|
|
9271
|
-
if (resource) requestConfig.withData(resource);
|
|
9272
|
-
if (this.#options.agentManager) requestConfig.withAgentManager(this.#options.agentManager);
|
|
9273
|
-
return await createRetryAxiosClient({
|
|
9274
|
-
maxRetries: 4,
|
|
9275
|
-
retryDelayMs: 300,
|
|
9276
|
-
retryJitterMs: 150,
|
|
9277
|
-
maxRetryDurationMs: 5e3,
|
|
9278
|
-
onRetryAttempt: (attempt, error, delayMs) => {
|
|
9279
|
-
this.LogWarning("#InvokeResourceAPI", `Retry #${attempt} after ${delayMs}ms due to ${error.code || error.response?.status}`);
|
|
9280
|
-
if (this.#options.onRetryAttempt) this.#options.onRetryAttempt(attempt, error, delayMs);
|
|
9281
|
-
}
|
|
9282
|
-
})(url, requestConfig.config);
|
|
9283
|
-
};
|
|
9284
|
-
ProcessBatchOrTransactionResources = async (bundle) => {
|
|
9285
|
-
try {
|
|
9286
|
-
let url = `${this.BaseUrl()}`;
|
|
9287
|
-
const retVal = await this.#InvokeResourceAPI(url, "post", null, bundle);
|
|
9288
|
-
if (retVal) return {
|
|
9289
|
-
status: retVal.status,
|
|
9290
|
-
body: retVal.data
|
|
9291
|
-
};
|
|
9292
|
-
else throw new Error(`FhirRESTClient:ProcessBatchOrTransactionResources(): No response from #InvokeResourceAPI`);
|
|
9293
|
-
} catch (error) {
|
|
9294
|
-
this.LogError("ProcessBatchOrTransactionResources", error);
|
|
9295
|
-
throw error;
|
|
9296
|
-
}
|
|
9297
|
-
};
|
|
9298
|
-
GetResources = async (searchUrl) => {
|
|
9299
|
-
try {
|
|
9300
|
-
const retVal = await this.#InvokeResourceAPI(searchUrl.toString(), "get", null, null);
|
|
9301
|
-
if (retVal) return {
|
|
9302
|
-
status: retVal.status,
|
|
9303
|
-
body: retVal.data
|
|
9304
|
-
};
|
|
9305
|
-
else throw new Error(`FhirRESTClient:GetResources(): No response from #InvokeResourceAPI`);
|
|
9306
|
-
} catch (error) {
|
|
9307
|
-
this.LogError("GetResources", error);
|
|
9308
|
-
throw error;
|
|
9309
|
-
}
|
|
9310
|
-
};
|
|
9311
|
-
GetHistoryFhirResources = async (searchUrl) => {
|
|
9312
|
-
try {
|
|
9313
|
-
return await this.GetResources(searchUrl);
|
|
9314
|
-
} catch (error) {
|
|
9315
|
-
this.LogError("GetHistoryFhirResources", error);
|
|
9316
|
-
throw error;
|
|
9317
|
-
}
|
|
9318
|
-
};
|
|
9319
|
-
GetHistoryFhirResource = async (searchUrl) => {
|
|
9320
|
-
try {
|
|
9321
|
-
return await this.GetResources(searchUrl);
|
|
9322
|
-
} catch (error) {
|
|
9323
|
-
this.LogError("GetHistoryFhirResource", error);
|
|
9324
|
-
throw error;
|
|
9325
|
-
}
|
|
9326
|
-
};
|
|
9327
|
-
GetAllFhirResources = async (searchUrl) => {
|
|
9328
|
-
try {
|
|
9329
|
-
return await this.GetResources(searchUrl);
|
|
9330
|
-
} catch (error) {
|
|
9331
|
-
this.LogError("GetAllFhirResources", error);
|
|
9332
|
-
throw error;
|
|
9333
|
-
}
|
|
9334
|
-
};
|
|
9335
|
-
GetResource = async (resourceType, resourceId) => {
|
|
9336
|
-
try {
|
|
9337
|
-
let url = `${`${this.BaseUrl()}/${resourceType}`}/${resourceId}`;
|
|
9338
|
-
const retVal = await this.#InvokeResourceAPI(url, "get", null, null);
|
|
9339
|
-
if (retVal) return {
|
|
9340
|
-
status: retVal.status,
|
|
9341
|
-
body: retVal.data
|
|
9342
|
-
};
|
|
9343
|
-
else throw new Error(`FhirRESTClient:GetResource(): No response from #InvokeResourceAPI`);
|
|
9344
|
-
} catch (error) {
|
|
9345
|
-
if (axios.default.isAxiosError(error)) {
|
|
9346
|
-
const axiosError = error;
|
|
9347
|
-
return {
|
|
9348
|
-
status: axiosError.response.status,
|
|
9349
|
-
body: axiosError.response.data,
|
|
9350
|
-
headers: { ETag: axiosError.response.headers["etag"] }
|
|
9351
|
-
};
|
|
9352
|
-
} else throw error;
|
|
9353
|
-
}
|
|
9354
|
-
};
|
|
9355
|
-
PutResource = async (resourceType, domainResource, versionIdETag) => {
|
|
9356
|
-
try {
|
|
9357
|
-
let url = `${`${this.BaseUrl()}/${resourceType}`}/${domainResource.id}`;
|
|
9358
|
-
const retVal = await this.#InvokeResourceAPI(url, "put", versionIdETag, domainResource);
|
|
9359
|
-
if (retVal) return {
|
|
9360
|
-
status: retVal.status,
|
|
9361
|
-
body: retVal.data
|
|
9362
|
-
};
|
|
9363
|
-
else throw new Error(`FhirRESTClient:PutResource(): No response from #InvokeResourceAPI`);
|
|
9364
|
-
} catch (error) {
|
|
9365
|
-
this.LogError("PutResource", error);
|
|
9366
|
-
throw error;
|
|
9367
|
-
}
|
|
9368
|
-
};
|
|
9369
|
-
PatchResource = async (resourceType, resourceId, domainResource, contentType, versionIdETag) => {
|
|
9370
|
-
try {
|
|
9371
|
-
let url = `${`${this.BaseUrl()}/${resourceType}`}/${resourceId}`;
|
|
9372
|
-
const retVal = await this.#InvokeResourceAPI(url, "patch", versionIdETag, domainResource, contentType);
|
|
9373
|
-
if (retVal) return {
|
|
9374
|
-
status: retVal.status,
|
|
9375
|
-
body: retVal.data
|
|
9376
|
-
};
|
|
9377
|
-
else throw new Error(`FhirRESTClient:PatchResource(): No response from #InvokeResourceAPI`);
|
|
9378
|
-
} catch (error) {
|
|
9379
|
-
this.LogError("PatchResource", error);
|
|
9380
|
-
throw error;
|
|
9381
|
-
}
|
|
9382
|
-
};
|
|
9383
|
-
PostResource = async (resourceType, domainResource) => {
|
|
9384
|
-
try {
|
|
9385
|
-
const url = `${this.BaseUrl()}/${resourceType}`;
|
|
9386
|
-
const retVal = await this.#InvokeResourceAPI(url, "post", null, domainResource);
|
|
9387
|
-
if (retVal) return {
|
|
9388
|
-
status: retVal.status,
|
|
9389
|
-
body: retVal.data
|
|
9390
|
-
};
|
|
9391
|
-
else throw new Error(`FhirRESTClient:PostResource(): No response from #InvokeResourceAPI`);
|
|
9392
|
-
} catch (error) {
|
|
9393
|
-
this.LogError("PostResource", error);
|
|
9394
|
-
throw error;
|
|
9395
|
-
}
|
|
9396
|
-
};
|
|
9397
|
-
GetHistoryInstanceFhirResource = async (resourceType, resourceId, versionId) => {
|
|
9398
|
-
try {
|
|
9399
|
-
const url = `${`${this.BaseUrl()}/${resourceType}`}/${resourceId}/_history/${versionId.toString()}`;
|
|
9400
|
-
const retVal = await this.#InvokeResourceAPI(url, "get", null, null);
|
|
9401
|
-
if (retVal) return {
|
|
9402
|
-
status: retVal.status,
|
|
9403
|
-
body: retVal.data
|
|
9404
|
-
};
|
|
9405
|
-
else throw new Error(`FhirRESTClient:GetHistoryInstanceFhirResource(): No response from #InvokeResourceAPI`);
|
|
9406
|
-
} catch (error) {
|
|
9407
|
-
if (axios.default.isAxiosError(error)) {
|
|
9408
|
-
const axiosError = error;
|
|
9409
|
-
return {
|
|
9410
|
-
status: axiosError.response.status,
|
|
9411
|
-
body: axiosError.response.data,
|
|
9412
|
-
headers: { ETag: axiosError.response.headers["etag"] }
|
|
9413
|
-
};
|
|
9414
|
-
} else throw error;
|
|
9415
|
-
}
|
|
9416
|
-
};
|
|
9417
|
-
ExtractNumber(str) {
|
|
9418
|
-
if (typeof str !== "string") return null;
|
|
9419
|
-
const match = str.match(/^\s*(?:W\/\s*)?"\s*([\d.]+)\s*"$/i);
|
|
9420
|
-
return match ? Number(match[1]) : null;
|
|
9421
|
-
}
|
|
9422
|
-
DeleteResource = async (resourceType, resourceId, versionIdETag) => {
|
|
9423
|
-
try {
|
|
9424
|
-
let url = `${`${this.BaseUrl()}/${resourceType}`}/${resourceId}`;
|
|
9425
|
-
const retVal = await this.#InvokeResourceAPI(url, "delete", versionIdETag, null);
|
|
9426
|
-
if (retVal) return {
|
|
9427
|
-
status: retVal.status,
|
|
9428
|
-
body: retVal.data
|
|
9429
|
-
};
|
|
9430
|
-
else throw new Error(`FhirRESTClient:DeleteResource(): No response from #InvokeResourceAPI`);
|
|
9431
|
-
} catch (error) {
|
|
9432
|
-
if (axios.default.isAxiosError(error)) {
|
|
9433
|
-
const axiosError = error;
|
|
9434
|
-
const versionNumber = this.ExtractNumber(versionIdETag) + 1;
|
|
9435
|
-
return {
|
|
9436
|
-
status: axiosError.response.status,
|
|
9437
|
-
body: axiosError.response.data,
|
|
9438
|
-
headers: { ETag: `W/"${versionNumber}"` }
|
|
9439
|
-
};
|
|
9440
|
-
} else throw error;
|
|
9441
|
-
}
|
|
9442
|
-
};
|
|
9443
|
-
GetMetadata = async () => {
|
|
9444
|
-
try {
|
|
9445
|
-
const resourceUrl = `${this.BaseUrl()}/metadata`;
|
|
9446
|
-
const retVal = await this.#InvokeResourceAPI(resourceUrl, "get", null, null);
|
|
9447
|
-
if (retVal) return {
|
|
9448
|
-
status: retVal.status,
|
|
9449
|
-
body: retVal.data
|
|
9450
|
-
};
|
|
9451
|
-
else throw new Error(`FhirRESTClient:GetMetadata(): No response from #InvokeResourceAPI`);
|
|
9452
|
-
} catch (error) {
|
|
9453
|
-
this.LogError("GetMetadata", error);
|
|
9454
|
-
throw error;
|
|
9455
|
-
}
|
|
9456
|
-
};
|
|
9457
|
-
GetLatency = async (params) => {
|
|
9458
|
-
try {
|
|
9459
|
-
const url = `${this.BaseUrl()}/latency`;
|
|
9460
|
-
const retVal = await this.#InvokeResourceAPI(url, "get", null, null);
|
|
9461
|
-
if (retVal) return {
|
|
9462
|
-
status: retVal.status,
|
|
9463
|
-
body: retVal.data
|
|
9464
|
-
};
|
|
9465
|
-
else throw new Error(`FhirRESTClient:GetLatency(): No response from #InvokeResourceAPI`);
|
|
9466
|
-
} catch (error) {
|
|
9467
|
-
this.LogError("GetLatency", error);
|
|
9468
|
-
throw error;
|
|
9469
|
-
}
|
|
9470
|
-
};
|
|
9471
|
-
GenericSearchTesting = async (resourceType, params) => {
|
|
9472
|
-
try {
|
|
9473
|
-
const retVal = await this.#InvokeResourceAPI(`${this.BaseUrl()}/${resourceType}/_genericSearchTesting`, "post", null, params);
|
|
9474
|
-
if (retVal) return {
|
|
9475
|
-
status: retVal.status,
|
|
9476
|
-
body: retVal.data
|
|
9477
|
-
};
|
|
9478
|
-
else throw new Error(`FhirRESTClient:GenericSearchTesting(): No response from #InvokeResourceAPI`);
|
|
9479
|
-
} catch (error) {
|
|
9480
|
-
this.LogError("GenericSearchTesting", error);
|
|
9481
|
-
throw error;
|
|
9482
|
-
}
|
|
9483
|
-
};
|
|
9484
|
-
};
|
|
9485
|
-
//#endregion
|
|
9486
9231
|
//#region node_modules/chalk/source/vendor/ansi-styles/index.js
|
|
9487
9232
|
var ANSI_BACKGROUND_OFFSET = 10;
|
|
9488
9233
|
var wrapAnsi16 = (offset = 0) => (code) => `\u001B[${code + offset}m`;
|
|
@@ -9818,6 +9563,280 @@ Object.defineProperties(createChalk.prototype, styles);
|
|
|
9818
9563
|
var chalk = createChalk();
|
|
9819
9564
|
createChalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
9820
9565
|
//#endregion
|
|
9566
|
+
//#region src/cv2/fhirRESTClient.ts
|
|
9567
|
+
var FhirRESTClient = class {
|
|
9568
|
+
#options;
|
|
9569
|
+
constructor(options) {
|
|
9570
|
+
this.#options = options;
|
|
9571
|
+
}
|
|
9572
|
+
BaseUrl() {
|
|
9573
|
+
return `${this.#options.endpoint}:${this.#options.stsfhirport}${this.#options.stsfhirapiroot}`;
|
|
9574
|
+
}
|
|
9575
|
+
HandleError = (error) => {
|
|
9576
|
+
this.#options.logger.error(chalk.red(`HandleError(): Error: [${error}]`));
|
|
9577
|
+
if (axios.default.isAxiosError(error)) {
|
|
9578
|
+
const axiosError = error;
|
|
9579
|
+
if (axiosError.response) {
|
|
9580
|
+
this.#options.logger.error(chalk.red(`AXIOS Error Response.Status = [${axiosError.response.status}]`));
|
|
9581
|
+
if (axiosError.response.headers) this.#options.logger.error(chalk.red(` headers: [${JSON.stringify(axiosError.response.headers)}]`));
|
|
9582
|
+
if (axiosError.response.data) this.#options.logger.error(chalk.red(` data: [${JSON.stringify(axiosError.response.data)}]`));
|
|
9583
|
+
try {
|
|
9584
|
+
if (axiosError.response.config) this.#options.logger.error(chalk.red(` config: [${JSON.stringify(axiosError.response.config)}]`));
|
|
9585
|
+
} catch (innererror) {
|
|
9586
|
+
this.#options.logger.error(chalk.red(` could not get response config, error: [${innererror}]`));
|
|
9587
|
+
}
|
|
9588
|
+
} else this.#options.logger.error(chalk.red(`AXIOS Error = [${axiosError}]`));
|
|
9589
|
+
}
|
|
9590
|
+
};
|
|
9591
|
+
LogError = (method, error) => {
|
|
9592
|
+
this.#options.logger.error(`FhirRESTClient:${method}(): Error: [${error}]`);
|
|
9593
|
+
this.#options.logger.error(error);
|
|
9594
|
+
console.error(error);
|
|
9595
|
+
this.HandleError(error);
|
|
9596
|
+
process.exit(0);
|
|
9597
|
+
};
|
|
9598
|
+
LogWarning = (method, message) => {
|
|
9599
|
+
this.#options.logger.warn(`FhirRESTClient:${method}(): Warn: [${message}]`);
|
|
9600
|
+
};
|
|
9601
|
+
/**
|
|
9602
|
+
*
|
|
9603
|
+
* @param url
|
|
9604
|
+
* @param httpVerb
|
|
9605
|
+
* @param versionIdETag Format "W/<versionNumber", e.g. "W/3"
|
|
9606
|
+
* @param resource
|
|
9607
|
+
* @returns
|
|
9608
|
+
*/
|
|
9609
|
+
#InvokeResourceAPI = async (url, httpVerb, versionIdETag, resource, contentType) => {
|
|
9610
|
+
const accessToken = await this.#options.GetAccessToken();
|
|
9611
|
+
let requestConfig;
|
|
9612
|
+
const headers = {
|
|
9613
|
+
Prefer: "return=representation",
|
|
9614
|
+
Accept: "application/fhir+json"
|
|
9615
|
+
};
|
|
9616
|
+
if (versionIdETag && versionIdETag !== "") headers["If-Match"] = versionIdETag;
|
|
9617
|
+
if (httpVerb === "patch") {
|
|
9618
|
+
requestConfig = new _nsshunt_stsutils.STSAxiosConfig(url, httpVerb).withApplicationMergePatchAndJsonContentTypeHeaders();
|
|
9619
|
+
if (resource && contentType) {
|
|
9620
|
+
if (contentType.localeCompare("application/merge-patch+json") === 0) requestConfig = new _nsshunt_stsutils.STSAxiosConfig(url, httpVerb).withApplicationMergePatchAndJsonContentTypeHeaders();
|
|
9621
|
+
else if (contentType.localeCompare("application/json-patch+json") === 0) requestConfig = new _nsshunt_stsutils.STSAxiosConfig(url, httpVerb).withApplicationJsonPatchAndJsonContentTypeHeaders();
|
|
9622
|
+
}
|
|
9623
|
+
} else requestConfig = new _nsshunt_stsutils.STSAxiosConfig(url, httpVerb).withApplicationFhirAndJsonContentTypeHeaders();
|
|
9624
|
+
requestConfig.withAuthHeaders(accessToken, this.#options.user).withHeaders(headers);
|
|
9625
|
+
if (resource) requestConfig.withData(resource);
|
|
9626
|
+
if (this.#options.agentManager) requestConfig.withAgentManager(this.#options.agentManager);
|
|
9627
|
+
return await createRetryAxiosClient({
|
|
9628
|
+
maxRetries: 4,
|
|
9629
|
+
retryDelayMs: 300,
|
|
9630
|
+
retryJitterMs: 150,
|
|
9631
|
+
maxRetryDurationMs: 5e3,
|
|
9632
|
+
onRetryAttempt: (attempt, error, delayMs) => {
|
|
9633
|
+
this.LogWarning("#InvokeResourceAPI", `Retry #${attempt} after ${delayMs}ms due to ${error.code || error.response?.status}`);
|
|
9634
|
+
if (this.#options.onRetryAttempt) this.#options.onRetryAttempt(attempt, error, delayMs);
|
|
9635
|
+
}
|
|
9636
|
+
})(url, requestConfig.config);
|
|
9637
|
+
};
|
|
9638
|
+
ProcessBatchOrTransactionResources = async (bundle) => {
|
|
9639
|
+
try {
|
|
9640
|
+
let url = `${this.BaseUrl()}`;
|
|
9641
|
+
const retVal = await this.#InvokeResourceAPI(url, "post", null, bundle);
|
|
9642
|
+
if (retVal) return {
|
|
9643
|
+
status: retVal.status,
|
|
9644
|
+
body: retVal.data
|
|
9645
|
+
};
|
|
9646
|
+
else throw new Error(`FhirRESTClient:ProcessBatchOrTransactionResources(): No response from #InvokeResourceAPI`);
|
|
9647
|
+
} catch (error) {
|
|
9648
|
+
this.LogError("ProcessBatchOrTransactionResources", error);
|
|
9649
|
+
throw error;
|
|
9650
|
+
}
|
|
9651
|
+
};
|
|
9652
|
+
GetResources = async (searchUrl) => {
|
|
9653
|
+
try {
|
|
9654
|
+
const retVal = await this.#InvokeResourceAPI(searchUrl.toString(), "get", null, null);
|
|
9655
|
+
if (retVal) return {
|
|
9656
|
+
status: retVal.status,
|
|
9657
|
+
body: retVal.data
|
|
9658
|
+
};
|
|
9659
|
+
else throw new Error(`FhirRESTClient:GetResources(): No response from #InvokeResourceAPI`);
|
|
9660
|
+
} catch (error) {
|
|
9661
|
+
this.LogError("GetResources", error);
|
|
9662
|
+
throw error;
|
|
9663
|
+
}
|
|
9664
|
+
};
|
|
9665
|
+
GetHistoryFhirResources = async (searchUrl) => {
|
|
9666
|
+
try {
|
|
9667
|
+
return await this.GetResources(searchUrl);
|
|
9668
|
+
} catch (error) {
|
|
9669
|
+
this.LogError("GetHistoryFhirResources", error);
|
|
9670
|
+
throw error;
|
|
9671
|
+
}
|
|
9672
|
+
};
|
|
9673
|
+
GetHistoryFhirResource = async (searchUrl) => {
|
|
9674
|
+
try {
|
|
9675
|
+
return await this.GetResources(searchUrl);
|
|
9676
|
+
} catch (error) {
|
|
9677
|
+
this.LogError("GetHistoryFhirResource", error);
|
|
9678
|
+
throw error;
|
|
9679
|
+
}
|
|
9680
|
+
};
|
|
9681
|
+
GetAllFhirResources = async (searchUrl) => {
|
|
9682
|
+
try {
|
|
9683
|
+
return await this.GetResources(searchUrl);
|
|
9684
|
+
} catch (error) {
|
|
9685
|
+
this.LogError("GetAllFhirResources", error);
|
|
9686
|
+
throw error;
|
|
9687
|
+
}
|
|
9688
|
+
};
|
|
9689
|
+
GetResource = async (resourceType, resourceId) => {
|
|
9690
|
+
try {
|
|
9691
|
+
let url = `${`${this.BaseUrl()}/${resourceType}`}/${resourceId}`;
|
|
9692
|
+
const retVal = await this.#InvokeResourceAPI(url, "get", null, null);
|
|
9693
|
+
if (retVal) return {
|
|
9694
|
+
status: retVal.status,
|
|
9695
|
+
body: retVal.data
|
|
9696
|
+
};
|
|
9697
|
+
else throw new Error(`FhirRESTClient:GetResource(): No response from #InvokeResourceAPI`);
|
|
9698
|
+
} catch (error) {
|
|
9699
|
+
if (axios.default.isAxiosError(error)) {
|
|
9700
|
+
const axiosError = error;
|
|
9701
|
+
return {
|
|
9702
|
+
status: axiosError.response.status,
|
|
9703
|
+
body: axiosError.response.data,
|
|
9704
|
+
headers: { ETag: axiosError.response.headers["etag"] }
|
|
9705
|
+
};
|
|
9706
|
+
} else throw error;
|
|
9707
|
+
}
|
|
9708
|
+
};
|
|
9709
|
+
PutResource = async (resourceType, domainResource, versionIdETag) => {
|
|
9710
|
+
try {
|
|
9711
|
+
let url = `${`${this.BaseUrl()}/${resourceType}`}/${domainResource.id}`;
|
|
9712
|
+
const retVal = await this.#InvokeResourceAPI(url, "put", versionIdETag, domainResource);
|
|
9713
|
+
if (retVal) return {
|
|
9714
|
+
status: retVal.status,
|
|
9715
|
+
body: retVal.data
|
|
9716
|
+
};
|
|
9717
|
+
else throw new Error(`FhirRESTClient:PutResource(): No response from #InvokeResourceAPI`);
|
|
9718
|
+
} catch (error) {
|
|
9719
|
+
this.LogError("PutResource", error);
|
|
9720
|
+
throw error;
|
|
9721
|
+
}
|
|
9722
|
+
};
|
|
9723
|
+
PatchResource = async (resourceType, resourceId, domainResource, contentType, versionIdETag) => {
|
|
9724
|
+
try {
|
|
9725
|
+
let url = `${`${this.BaseUrl()}/${resourceType}`}/${resourceId}`;
|
|
9726
|
+
const retVal = await this.#InvokeResourceAPI(url, "patch", versionIdETag, domainResource, contentType);
|
|
9727
|
+
if (retVal) return {
|
|
9728
|
+
status: retVal.status,
|
|
9729
|
+
body: retVal.data
|
|
9730
|
+
};
|
|
9731
|
+
else throw new Error(`FhirRESTClient:PatchResource(): No response from #InvokeResourceAPI`);
|
|
9732
|
+
} catch (error) {
|
|
9733
|
+
this.LogError("PatchResource", error);
|
|
9734
|
+
throw error;
|
|
9735
|
+
}
|
|
9736
|
+
};
|
|
9737
|
+
PostResource = async (resourceType, domainResource) => {
|
|
9738
|
+
try {
|
|
9739
|
+
const url = `${this.BaseUrl()}/${resourceType}`;
|
|
9740
|
+
const retVal = await this.#InvokeResourceAPI(url, "post", null, domainResource);
|
|
9741
|
+
if (retVal) return {
|
|
9742
|
+
status: retVal.status,
|
|
9743
|
+
body: retVal.data
|
|
9744
|
+
};
|
|
9745
|
+
else throw new Error(`FhirRESTClient:PostResource(): No response from #InvokeResourceAPI`);
|
|
9746
|
+
} catch (error) {
|
|
9747
|
+
this.LogError("PostResource", error);
|
|
9748
|
+
throw error;
|
|
9749
|
+
}
|
|
9750
|
+
};
|
|
9751
|
+
GetHistoryInstanceFhirResource = async (resourceType, resourceId, versionId) => {
|
|
9752
|
+
try {
|
|
9753
|
+
const url = `${`${this.BaseUrl()}/${resourceType}`}/${resourceId}/_history/${versionId.toString()}`;
|
|
9754
|
+
const retVal = await this.#InvokeResourceAPI(url, "get", null, null);
|
|
9755
|
+
if (retVal) return {
|
|
9756
|
+
status: retVal.status,
|
|
9757
|
+
body: retVal.data
|
|
9758
|
+
};
|
|
9759
|
+
else throw new Error(`FhirRESTClient:GetHistoryInstanceFhirResource(): No response from #InvokeResourceAPI`);
|
|
9760
|
+
} catch (error) {
|
|
9761
|
+
if (axios.default.isAxiosError(error)) {
|
|
9762
|
+
const axiosError = error;
|
|
9763
|
+
return {
|
|
9764
|
+
status: axiosError.response.status,
|
|
9765
|
+
body: axiosError.response.data,
|
|
9766
|
+
headers: { ETag: axiosError.response.headers["etag"] }
|
|
9767
|
+
};
|
|
9768
|
+
} else throw error;
|
|
9769
|
+
}
|
|
9770
|
+
};
|
|
9771
|
+
ExtractNumber(str) {
|
|
9772
|
+
if (typeof str !== "string") return null;
|
|
9773
|
+
const match = str.match(/^\s*(?:W\/\s*)?"\s*([\d.]+)\s*"$/i);
|
|
9774
|
+
return match ? Number(match[1]) : null;
|
|
9775
|
+
}
|
|
9776
|
+
DeleteResource = async (resourceType, resourceId, versionIdETag) => {
|
|
9777
|
+
try {
|
|
9778
|
+
let url = `${`${this.BaseUrl()}/${resourceType}`}/${resourceId}`;
|
|
9779
|
+
const retVal = await this.#InvokeResourceAPI(url, "delete", versionIdETag, null);
|
|
9780
|
+
if (retVal) return {
|
|
9781
|
+
status: retVal.status,
|
|
9782
|
+
body: retVal.data
|
|
9783
|
+
};
|
|
9784
|
+
else throw new Error(`FhirRESTClient:DeleteResource(): No response from #InvokeResourceAPI`);
|
|
9785
|
+
} catch (error) {
|
|
9786
|
+
if (axios.default.isAxiosError(error)) {
|
|
9787
|
+
const axiosError = error;
|
|
9788
|
+
const versionNumber = this.ExtractNumber(versionIdETag) + 1;
|
|
9789
|
+
return {
|
|
9790
|
+
status: axiosError.response.status,
|
|
9791
|
+
body: axiosError.response.data,
|
|
9792
|
+
headers: { ETag: `W/"${versionNumber}"` }
|
|
9793
|
+
};
|
|
9794
|
+
} else throw error;
|
|
9795
|
+
}
|
|
9796
|
+
};
|
|
9797
|
+
GetMetadata = async () => {
|
|
9798
|
+
try {
|
|
9799
|
+
const resourceUrl = `${this.BaseUrl()}/metadata`;
|
|
9800
|
+
const retVal = await this.#InvokeResourceAPI(resourceUrl, "get", null, null);
|
|
9801
|
+
if (retVal) return {
|
|
9802
|
+
status: retVal.status,
|
|
9803
|
+
body: retVal.data
|
|
9804
|
+
};
|
|
9805
|
+
else throw new Error(`FhirRESTClient:GetMetadata(): No response from #InvokeResourceAPI`);
|
|
9806
|
+
} catch (error) {
|
|
9807
|
+
this.LogError("GetMetadata", error);
|
|
9808
|
+
throw error;
|
|
9809
|
+
}
|
|
9810
|
+
};
|
|
9811
|
+
GetLatency = async (params) => {
|
|
9812
|
+
try {
|
|
9813
|
+
const url = `${this.BaseUrl()}/latency`;
|
|
9814
|
+
const retVal = await this.#InvokeResourceAPI(url, "get", null, null);
|
|
9815
|
+
if (retVal) return {
|
|
9816
|
+
status: retVal.status,
|
|
9817
|
+
body: retVal.data
|
|
9818
|
+
};
|
|
9819
|
+
else throw new Error(`FhirRESTClient:GetLatency(): No response from #InvokeResourceAPI`);
|
|
9820
|
+
} catch (error) {
|
|
9821
|
+
this.LogError("GetLatency", error);
|
|
9822
|
+
throw error;
|
|
9823
|
+
}
|
|
9824
|
+
};
|
|
9825
|
+
GenericSearchTesting = async (resourceType, params) => {
|
|
9826
|
+
try {
|
|
9827
|
+
const retVal = await this.#InvokeResourceAPI(`${this.BaseUrl()}/${resourceType}/_genericSearchTesting`, "post", null, params);
|
|
9828
|
+
if (retVal) return {
|
|
9829
|
+
status: retVal.status,
|
|
9830
|
+
body: retVal.data
|
|
9831
|
+
};
|
|
9832
|
+
else throw new Error(`FhirRESTClient:GenericSearchTesting(): No response from #InvokeResourceAPI`);
|
|
9833
|
+
} catch (error) {
|
|
9834
|
+
this.LogError("GenericSearchTesting", error);
|
|
9835
|
+
throw error;
|
|
9836
|
+
}
|
|
9837
|
+
};
|
|
9838
|
+
};
|
|
9839
|
+
//#endregion
|
|
9821
9840
|
//#region node_modules/@nsshunt/stssocketioutils/dist/tiny-emitter-DcZ69ZvJ.js
|
|
9822
9841
|
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
9823
9842
|
var require_tiny_emitter = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|