@nsshunt/stsfhirclient 1.1.3 → 1.1.5
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.mjs +679 -720
- package/dist/stsfhirclient.mjs.map +1 -1
- package/dist/stsfhirclient.umd.js +680 -721
- package/dist/stsfhirclient.umd.js.map +1 -1
- package/package.json +14 -15
- package/types/FhirClient.d.ts +1 -1
- package/types/FhirClient.d.ts.map +1 -1
package/dist/stsfhirclient.mjs
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __typeError = (msg) => {
|
|
3
|
-
throw TypeError(msg);
|
|
4
|
-
};
|
|
5
|
-
var __defNormalProp = (obj, key, value2) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value: value2 }) : obj[key] = value2;
|
|
6
|
-
var __publicField = (obj, key, value2) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value2);
|
|
7
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
8
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
9
|
-
var __privateAdd = (obj, member, value2) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value2);
|
|
10
|
-
var __privateSet = (obj, member, value2, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value2) : member.set(obj, value2), value2);
|
|
11
|
-
var _socketUtils, _id, _options2, _clientName, _debug, _error, _info, _SetupWSSClient, _OnSocketConnected, _options3, _DUMMY_USER, _stsfhirapiroot, _fhirSocketClient, _LogDebugMessage, _HandleError, _BuildQueryString, _InvokeResourceAPI;
|
|
12
1
|
import axios from "axios";
|
|
13
2
|
import { defaultLogger, Sleep, STSAxiosConfig } from "@nsshunt/stsutils";
|
|
14
3
|
const isNode$1 = Object.prototype.toString.call(typeof process !== "undefined" ? process : 0) === "[object process]";
|
|
@@ -4828,25 +4817,23 @@ Object.assign(lookup, {
|
|
|
4828
4817
|
io: lookup,
|
|
4829
4818
|
connect: lookup
|
|
4830
4819
|
});
|
|
4831
|
-
var __typeError2 = (msg) => {
|
|
4832
|
-
throw TypeError(msg);
|
|
4833
|
-
};
|
|
4834
|
-
var __accessCheck2 = (obj, member, msg) => member.has(obj) || __typeError2("Cannot " + msg);
|
|
4835
|
-
var __privateGet2 = (obj, member, getter) => (__accessCheck2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
4836
|
-
var __privateAdd2 = (obj, member, value2) => member.has(obj) ? __typeError2("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value2);
|
|
4837
|
-
var __privateSet2 = (obj, member, value2, setter) => (__accessCheck2(obj, member, "write to private field"), member.set(obj, value2), value2);
|
|
4838
|
-
var __privateMethod = (obj, member, method) => (__accessCheck2(obj, member, "access private method"), method);
|
|
4839
|
-
var _options, _sockets, _SocketIoClientHelper_instances, LogDebugMessage_fn, LogErrorMessage_fn, EstablishSocketConnect_fn;
|
|
4840
4820
|
const isNode = Object.prototype.toString.call(typeof process !== "undefined" ? process : 0) === "[object process]";
|
|
4841
4821
|
class SocketIoClientHelper {
|
|
4822
|
+
#options;
|
|
4823
|
+
#sockets = {};
|
|
4842
4824
|
constructor(options) {
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4825
|
+
this.#options = options;
|
|
4826
|
+
}
|
|
4827
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4828
|
+
#LogDebugMessage(message) {
|
|
4829
|
+
if (this.#options.logger) this.#options.logger.debug(message);
|
|
4830
|
+
}
|
|
4831
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4832
|
+
#LogErrorMessage(message) {
|
|
4833
|
+
if (this.#options.logger) this.#options.logger.error(message);
|
|
4847
4834
|
}
|
|
4848
4835
|
get sockets() {
|
|
4849
|
-
return
|
|
4836
|
+
return this.#sockets;
|
|
4850
4837
|
}
|
|
4851
4838
|
SetupClientSideSocket(name, address, socketIoCustomPath, onConnectCallBack, socketEventsCallBack, errorCallBack) {
|
|
4852
4839
|
this.sockets[name] = {
|
|
@@ -4855,7 +4842,7 @@ class SocketIoClientHelper {
|
|
|
4855
4842
|
socket: null,
|
|
4856
4843
|
errorCallBack
|
|
4857
4844
|
};
|
|
4858
|
-
|
|
4845
|
+
this.#EstablishSocketConnect(name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack);
|
|
4859
4846
|
return this.sockets[name].socket;
|
|
4860
4847
|
}
|
|
4861
4848
|
GetSocket(name) {
|
|
@@ -4864,127 +4851,117 @@ class SocketIoClientHelper {
|
|
|
4864
4851
|
GetSocketDetail(name) {
|
|
4865
4852
|
return this.sockets[name];
|
|
4866
4853
|
}
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
}
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
if (socketDetail.socket.connected === true) {
|
|
4881
|
-
socketDetail.socket.disconnect();
|
|
4854
|
+
#EstablishSocketConnect(name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack) {
|
|
4855
|
+
const socketDetail = this.sockets[name];
|
|
4856
|
+
if (socketDetail.socket !== null) {
|
|
4857
|
+
if (socketDetail.socket.connected === true) {
|
|
4858
|
+
socketDetail.socket.disconnect();
|
|
4859
|
+
}
|
|
4860
|
+
socketDetail.socket = null;
|
|
4861
|
+
if (isNode) {
|
|
4862
|
+
setTimeout(() => this.#EstablishSocketConnect(name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack), 100).unref();
|
|
4863
|
+
} else {
|
|
4864
|
+
setTimeout(() => this.#EstablishSocketConnect(name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack), 100);
|
|
4865
|
+
}
|
|
4866
|
+
return;
|
|
4882
4867
|
}
|
|
4883
|
-
|
|
4868
|
+
let socketOptions;
|
|
4884
4869
|
if (isNode) {
|
|
4885
|
-
|
|
4870
|
+
socketOptions = {
|
|
4871
|
+
transports: ["websocket"]
|
|
4872
|
+
};
|
|
4873
|
+
if (this.#options.agentManager) {
|
|
4874
|
+
socketOptions.agent = this.#options.agentManager.GetAgent(socketDetail.address);
|
|
4875
|
+
}
|
|
4886
4876
|
} else {
|
|
4887
|
-
|
|
4877
|
+
socketOptions = {
|
|
4878
|
+
transports: ["websocket"]
|
|
4879
|
+
};
|
|
4888
4880
|
}
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
let socketOptions;
|
|
4892
|
-
if (isNode) {
|
|
4893
|
-
socketOptions = {
|
|
4894
|
-
transports: ["websocket"]
|
|
4895
|
-
};
|
|
4896
|
-
if (__privateGet2(this, _options).agentManager) {
|
|
4897
|
-
socketOptions.agent = __privateGet2(this, _options).agentManager.GetAgent(socketDetail.address);
|
|
4881
|
+
if (socketIoCustomPath && socketIoCustomPath.localeCompare("") !== 0) {
|
|
4882
|
+
socketOptions.path = socketIoCustomPath;
|
|
4898
4883
|
}
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
};
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
}
|
|
4931
|
-
if (socketEventsCallBack) {
|
|
4932
|
-
socketEventsCallBack(socketDetail.socket);
|
|
4884
|
+
socketDetail.socket = lookup(socketDetail.address, socketOptions);
|
|
4885
|
+
socketDetail.socket.io.on("error", (err) => {
|
|
4886
|
+
this.#LogErrorMessage(`SocketIoClientHelper(): socketDetail.socket.io.on('error'): [${err}]`);
|
|
4887
|
+
});
|
|
4888
|
+
socketDetail.socket.io.on("reconnect_error", (err) => {
|
|
4889
|
+
this.#LogErrorMessage(`SocketIoClientHelper(): socketDetail.socket.io.on('reconnect_error'): [${err}]`);
|
|
4890
|
+
});
|
|
4891
|
+
socketDetail.socket.io.on("reconnect", (attempt) => {
|
|
4892
|
+
this.#LogErrorMessage(`SocketIoClientHelper(): socketDetail.socket.io.on('reconnect'): Number: [${attempt}]`);
|
|
4893
|
+
});
|
|
4894
|
+
socketDetail.socket.on("connect_error", (err) => {
|
|
4895
|
+
this.#LogErrorMessage(`SocketIoClientHelper(): socketDetail.socket.on('connect_error'): [${err}]`);
|
|
4896
|
+
});
|
|
4897
|
+
socketDetail.socket.on("connect_timeout", () => {
|
|
4898
|
+
this.#LogErrorMessage(`SocketIoClientHelper(): socketDetail.socket.on('connect_timeout')`);
|
|
4899
|
+
});
|
|
4900
|
+
socketDetail.socket.on("connect", () => {
|
|
4901
|
+
if (socketDetail.socket) {
|
|
4902
|
+
this.#LogDebugMessage(`SocketIoClientHelper(): Socket: [${socketDetail.socket.id}]: connected`);
|
|
4903
|
+
if (onConnectCallBack) {
|
|
4904
|
+
setTimeout(() => {
|
|
4905
|
+
onConnectCallBack(socketDetail.socket);
|
|
4906
|
+
}, 0);
|
|
4907
|
+
}
|
|
4908
|
+
if (socketEventsCallBack) {
|
|
4909
|
+
socketEventsCallBack(socketDetail.socket);
|
|
4910
|
+
}
|
|
4911
|
+
} else {
|
|
4912
|
+
const errorMessage = "SocketIoClientHelper(): Could not get socket object from socket.io";
|
|
4913
|
+
this.#LogErrorMessage(errorMessage);
|
|
4914
|
+
socketDetail.errorCallBack(new Error(errorMessage));
|
|
4933
4915
|
}
|
|
4934
|
-
}
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
if (__privateGet2(this, _options).agentManager) {
|
|
4952
|
-
__privateGet2(this, _options).agentManager.ResetAgent();
|
|
4916
|
+
});
|
|
4917
|
+
socketDetail.socket.on("disconnect", (reason) => {
|
|
4918
|
+
this.#LogDebugMessage("SocketIoClientHelper(): socket disconnect: " + reason);
|
|
4919
|
+
switch (reason) {
|
|
4920
|
+
case "io server disconnect":
|
|
4921
|
+
{
|
|
4922
|
+
this.#LogDebugMessage("SocketIoClientHelper(): The server disconnected using disconnectSockets, i.e. normal safe shutdown from explicit disconnection by the server.");
|
|
4923
|
+
this.#LogDebugMessage("SocketIoClientHelper(): The connection will be re-established when the server becomes available.");
|
|
4924
|
+
const socketDetail2 = this.sockets[name];
|
|
4925
|
+
socketDetail2.socket = null;
|
|
4926
|
+
if (isNode) {
|
|
4927
|
+
if (this.#options.agentManager) {
|
|
4928
|
+
this.#options.agentManager.ResetAgent();
|
|
4929
|
+
}
|
|
4930
|
+
setTimeout(() => this.#EstablishSocketConnect(name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack), 100).unref();
|
|
4931
|
+
} else {
|
|
4932
|
+
setTimeout(() => this.#EstablishSocketConnect(name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack), 100);
|
|
4953
4933
|
}
|
|
4954
|
-
setTimeout(() => __privateMethod(this, _SocketIoClientHelper_instances, EstablishSocketConnect_fn).call(this, name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack), 100).unref();
|
|
4955
|
-
} else {
|
|
4956
|
-
setTimeout(() => __privateMethod(this, _SocketIoClientHelper_instances, EstablishSocketConnect_fn).call(this, name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack), 100);
|
|
4957
|
-
}
|
|
4958
|
-
}
|
|
4959
|
-
break;
|
|
4960
|
-
case "io client disconnect":
|
|
4961
|
-
__privateMethod(this, _SocketIoClientHelper_instances, LogDebugMessage_fn).call(this, "SocketIoClientHelper(): The client disconnected using disconnectSockets, i.e. normal safe disconnection from explicit disconnection by the client.");
|
|
4962
|
-
__privateMethod(this, _SocketIoClientHelper_instances, LogDebugMessage_fn).call(this, "SocketIoClientHelper(): The connection will not be re-established automatically.");
|
|
4963
|
-
break;
|
|
4964
|
-
case "transport close":
|
|
4965
|
-
case "ping timeout":
|
|
4966
|
-
case "transport error":
|
|
4967
|
-
{
|
|
4968
|
-
__privateMethod(this, _SocketIoClientHelper_instances, LogDebugMessage_fn).call(this, `SocketIoClientHelper(): Server unexpectedly disconnected. Reason: [${reason}]`);
|
|
4969
|
-
__privateMethod(this, _SocketIoClientHelper_instances, LogDebugMessage_fn).call(this, "SocketIoClientHelper(): The connection will be re-established when the server becomes available.");
|
|
4970
|
-
const socketDetail2 = this.sockets[name];
|
|
4971
|
-
if (socketDetail2.socket) {
|
|
4972
|
-
socketDetail2.socket.disconnect();
|
|
4973
4934
|
}
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4935
|
+
break;
|
|
4936
|
+
case "io client disconnect":
|
|
4937
|
+
this.#LogDebugMessage("SocketIoClientHelper(): The client disconnected using disconnectSockets, i.e. normal safe disconnection from explicit disconnection by the client.");
|
|
4938
|
+
this.#LogDebugMessage("SocketIoClientHelper(): The connection will not be re-established automatically.");
|
|
4939
|
+
break;
|
|
4940
|
+
case "transport close":
|
|
4941
|
+
case "ping timeout":
|
|
4942
|
+
case "transport error":
|
|
4943
|
+
{
|
|
4944
|
+
this.#LogDebugMessage(`SocketIoClientHelper(): Server unexpectedly disconnected. Reason: [${reason}]`);
|
|
4945
|
+
this.#LogDebugMessage("SocketIoClientHelper(): The connection will be re-established when the server becomes available.");
|
|
4946
|
+
const socketDetail2 = this.sockets[name];
|
|
4947
|
+
if (socketDetail2.socket) {
|
|
4948
|
+
socketDetail2.socket.disconnect();
|
|
4949
|
+
}
|
|
4950
|
+
socketDetail2.socket = null;
|
|
4951
|
+
if (isNode) {
|
|
4952
|
+
if (this.#options.agentManager) {
|
|
4953
|
+
this.#options.agentManager?.ResetAgent();
|
|
4954
|
+
}
|
|
4955
|
+
setTimeout(() => this.#EstablishSocketConnect(name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack), 100).unref();
|
|
4956
|
+
} else {
|
|
4957
|
+
setTimeout(() => this.#EstablishSocketConnect(name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack), 100);
|
|
4978
4958
|
}
|
|
4979
|
-
setTimeout(() => __privateMethod(this, _SocketIoClientHelper_instances, EstablishSocketConnect_fn).call(this, name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack), 100).unref();
|
|
4980
|
-
} else {
|
|
4981
|
-
setTimeout(() => __privateMethod(this, _SocketIoClientHelper_instances, EstablishSocketConnect_fn).call(this, name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack), 100);
|
|
4982
4959
|
}
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
}
|
|
4986
|
-
}
|
|
4987
|
-
}
|
|
4960
|
+
break;
|
|
4961
|
+
}
|
|
4962
|
+
});
|
|
4963
|
+
}
|
|
4964
|
+
}
|
|
4988
4965
|
const byteToHex = [];
|
|
4989
4966
|
for (let i = 0; i < 256; ++i) {
|
|
4990
4967
|
byteToHex.push((i + 256).toString(16).slice(1));
|
|
@@ -5005,13 +4982,9 @@ function rng() {
|
|
|
5005
4982
|
}
|
|
5006
4983
|
const randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
5007
4984
|
const native = { randomUUID };
|
|
5008
|
-
function
|
|
5009
|
-
var _a;
|
|
5010
|
-
if (native.randomUUID && true && !options) {
|
|
5011
|
-
return native.randomUUID();
|
|
5012
|
-
}
|
|
4985
|
+
function _v4(options, buf, offset) {
|
|
5013
4986
|
options = options || {};
|
|
5014
|
-
const rnds = options.random ??
|
|
4987
|
+
const rnds = options.random ?? options.rng?.() ?? rng();
|
|
5015
4988
|
if (rnds.length < 16) {
|
|
5016
4989
|
throw new Error("Random bytes length must be >= 16");
|
|
5017
4990
|
}
|
|
@@ -5019,332 +4992,329 @@ function v4(options, buf, offset) {
|
|
|
5019
4992
|
rnds[8] = rnds[8] & 63 | 128;
|
|
5020
4993
|
return unsafeStringify(rnds);
|
|
5021
4994
|
}
|
|
4995
|
+
function v4(options, buf, offset) {
|
|
4996
|
+
if (native.randomUUID && true && !options) {
|
|
4997
|
+
return native.randomUUID();
|
|
4998
|
+
}
|
|
4999
|
+
return _v4(options);
|
|
5000
|
+
}
|
|
5022
5001
|
class FhirSocketClient {
|
|
5002
|
+
#socketUtils;
|
|
5003
|
+
#id = v4();
|
|
5004
|
+
#options;
|
|
5005
|
+
#clientName;
|
|
5023
5006
|
constructor(options) {
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
|
|
5007
|
+
this.#options = options;
|
|
5008
|
+
this.#socketUtils = new SocketIoClientHelper(this.#options.socketIoClientHelperOptions);
|
|
5009
|
+
const clientName = v4();
|
|
5010
|
+
this.#clientName = clientName;
|
|
5011
|
+
this.#SetupWSSClient(clientName, []);
|
|
5012
|
+
}
|
|
5013
|
+
#debug = (message) => defaultLogger.debug(message);
|
|
5014
|
+
#error = (error) => defaultLogger.error(error);
|
|
5015
|
+
#info = (message) => defaultLogger.info(message);
|
|
5016
|
+
#SetupWSSClient = async (clientName, joinRooms) => {
|
|
5017
|
+
console.log(chalk.yellow(`FhirSocketClient:#SetupWSSClient(): ID: [${this.#id}] clientName: [${clientName}] Starting ...`));
|
|
5018
|
+
const cstr = `${this.#options.fhirServerEndpoint}/nsstsfhir/`;
|
|
5019
|
+
console.log(chalk.yellow(`FhirSocketClient:#SetupWSSClient(): Socket connection string: [${cstr}]`));
|
|
5020
|
+
this.#socketUtils.SetupClientSideSocket(
|
|
5021
|
+
this.#options.socketClientName,
|
|
5022
|
+
// 'ststestrunner',
|
|
5023
|
+
cstr,
|
|
5024
|
+
// `https://stscore.stsmda.org:3005/nsstsfhir/` this.#options.ststccendpoint, stsfhir as the namespace
|
|
5025
|
+
this.#options.socketIoCustomPath,
|
|
5026
|
+
// '/stsfhirsocket/socket.io/',
|
|
5027
|
+
// Connected Callback
|
|
5028
|
+
(socket2) => this.#OnSocketConnected(socket2, clientName, joinRooms),
|
|
5029
|
+
// Events Registration
|
|
5030
|
+
(socket2) => {
|
|
5031
|
+
},
|
|
5032
|
+
// Error Callback
|
|
5033
|
+
(error) => this.#error(`FhirSocketClient:#SetupWSSClient(): Error clientName: [${clientName}]: SetupClientSideSocket call back: Error: [${error}]`)
|
|
5034
|
+
);
|
|
5035
|
+
console.log(chalk.yellow(`FhirSocketClient:#SetupWSSClient(): ID: [${this.#id}] clientName: [${clientName}] Started`));
|
|
5036
|
+
};
|
|
5037
|
+
// Handle connection logic separately
|
|
5038
|
+
#OnSocketConnected = (socket, clientName, joinRooms) => {
|
|
5039
|
+
this.#debug(chalk.green(`FhirSocketClient:#OnSocketConnected(): ID: [${this.#id}] clientName: [${clientName}]: --> connected`));
|
|
5040
|
+
if (joinRooms.length > 0) {
|
|
5041
|
+
socket.emit("__STSjoinRoom", joinRooms);
|
|
5042
|
+
}
|
|
5043
|
+
};
|
|
5044
|
+
WaitForSocketConnected = async () => {
|
|
5045
|
+
const socket = this.#socketUtils.GetSocket(this.#options.socketClientName);
|
|
5046
|
+
if (socket && socket.connected === true) {
|
|
5047
|
+
return;
|
|
5048
|
+
}
|
|
5049
|
+
console.log(chalk.yellow(`FhirSocketClient:#WaitForSocketConnected(): ID: [${this.#id}] clientName: [${this.#clientName}] Waiting for connection ...`));
|
|
5050
|
+
let connected = false;
|
|
5051
|
+
let attempts = 0;
|
|
5052
|
+
while (!connected) {
|
|
5053
|
+
attempts++;
|
|
5054
|
+
if (attempts % 10 === 0) {
|
|
5055
|
+
console.log(chalk.yellow(`FhirSocketClient:#WaitForSocketConnected(): ID: [${this.#id}] clientName: [${this.#clientName}] waiting for connection attempts: [${attempts}].`));
|
|
5063
5056
|
}
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
|
|
5067
|
-
|
|
5068
|
-
|
|
5069
|
-
if (attempts % 10 === 0) {
|
|
5070
|
-
console.log(chalk.yellow(`FhirSocketClient:#WaitForSocketConnected(): ID: [${__privateGet(this, _id)}] clientName: [${__privateGet(this, _clientName)}] waiting for connection attempts: [${attempts}].`));
|
|
5071
|
-
}
|
|
5072
|
-
const socketRetVal = __privateGet(this, _socketUtils).GetSocket(__privateGet(this, _options2).socketClientName);
|
|
5073
|
-
if (socketRetVal && socketRetVal.connected === true) {
|
|
5074
|
-
connected = true;
|
|
5075
|
-
console.log(chalk.yellow(`FhirSocketClient:#WaitForSocketConnected(): ID: [${__privateGet(this, _id)}] clientName: [${__privateGet(this, _clientName)}] Connection completed after: [${attempts}] attempts.`));
|
|
5076
|
-
break;
|
|
5077
|
-
}
|
|
5078
|
-
await Sleep(100);
|
|
5057
|
+
const socketRetVal = this.#socketUtils.GetSocket(this.#options.socketClientName);
|
|
5058
|
+
if (socketRetVal && socketRetVal.connected === true) {
|
|
5059
|
+
connected = true;
|
|
5060
|
+
console.log(chalk.yellow(`FhirSocketClient:#WaitForSocketConnected(): ID: [${this.#id}] clientName: [${this.#clientName}] Connection completed after: [${attempts}] attempts.`));
|
|
5061
|
+
break;
|
|
5079
5062
|
}
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
reject(err);
|
|
5097
|
-
} else {
|
|
5098
|
-
resolve(res);
|
|
5099
|
-
}
|
|
5100
|
-
});
|
|
5101
|
-
});
|
|
5063
|
+
await Sleep(100);
|
|
5064
|
+
}
|
|
5065
|
+
};
|
|
5066
|
+
get socket() {
|
|
5067
|
+
return this.#socketUtils.GetSocket(this.#options.socketClientName);
|
|
5068
|
+
}
|
|
5069
|
+
CreateResource = async (resource, domainResource) => {
|
|
5070
|
+
await this.WaitForSocketConnected();
|
|
5071
|
+
const promCreate = () => {
|
|
5072
|
+
const request = {
|
|
5073
|
+
headers: {
|
|
5074
|
+
"x-sts_user_id": "someuser"
|
|
5075
|
+
},
|
|
5076
|
+
params: {},
|
|
5077
|
+
query: {},
|
|
5078
|
+
body: domainResource
|
|
5102
5079
|
};
|
|
5103
|
-
return
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
},
|
|
5112
|
-
params: {},
|
|
5113
|
-
query: {},
|
|
5114
|
-
body: domainResources
|
|
5115
|
-
};
|
|
5116
|
-
return new Promise((resolve, reject) => {
|
|
5117
|
-
this.socket.timeout(__privateGet(this, _options2).timeout).emit("createFhirResources", resource, request, (err, res) => {
|
|
5118
|
-
if (err) {
|
|
5119
|
-
__privateGet(this, _error).call(this, `FhirSocketClient:CreateResources(): ID: [${__privateGet(this, _id)}] clientName: [${__privateGet(this, _clientName)}] Error: [${err}]`);
|
|
5120
|
-
reject(err);
|
|
5121
|
-
} else {
|
|
5122
|
-
resolve(res);
|
|
5123
|
-
}
|
|
5124
|
-
});
|
|
5080
|
+
return new Promise((resolve, reject) => {
|
|
5081
|
+
this.socket.timeout(this.#options.timeout).emit("createFhirResource", resource, request, (err, res) => {
|
|
5082
|
+
if (err) {
|
|
5083
|
+
this.#error(`FhirSocketClient:CreateResource(): ID: [${this.#id}] clientName: [${this.#clientName}] Error: [${err}]`);
|
|
5084
|
+
reject(err);
|
|
5085
|
+
} else {
|
|
5086
|
+
resolve(res);
|
|
5087
|
+
}
|
|
5125
5088
|
});
|
|
5089
|
+
});
|
|
5090
|
+
};
|
|
5091
|
+
return promCreate();
|
|
5092
|
+
};
|
|
5093
|
+
CreateResources = async (resource, domainResources) => {
|
|
5094
|
+
await this.WaitForSocketConnected();
|
|
5095
|
+
const promCreate = () => {
|
|
5096
|
+
const request = {
|
|
5097
|
+
headers: {
|
|
5098
|
+
"x-sts_user_id": "someuser"
|
|
5099
|
+
},
|
|
5100
|
+
params: {},
|
|
5101
|
+
query: {},
|
|
5102
|
+
body: domainResources
|
|
5126
5103
|
};
|
|
5127
|
-
return (
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
},
|
|
5136
|
-
params: {},
|
|
5137
|
-
query: {
|
|
5138
|
-
fhirResource: resourceId
|
|
5139
|
-
},
|
|
5140
|
-
body: {}
|
|
5141
|
-
};
|
|
5142
|
-
return new Promise((resolve, reject) => {
|
|
5143
|
-
this.socket.timeout(__privateGet(this, _options2).timeout).emit("getFhirResource", resource, request, (err, res) => {
|
|
5144
|
-
if (err) {
|
|
5145
|
-
__privateGet(this, _error).call(this, `FhirSocketClient:GetResource(): ID: [${__privateGet(this, _id)}] clientName: [${__privateGet(this, _clientName)}] Error: [${err}]`);
|
|
5146
|
-
reject(err);
|
|
5147
|
-
} else {
|
|
5148
|
-
resolve(res);
|
|
5149
|
-
}
|
|
5150
|
-
});
|
|
5104
|
+
return new Promise((resolve, reject) => {
|
|
5105
|
+
this.socket.timeout(this.#options.timeout).emit("createFhirResources", resource, request, (err, res) => {
|
|
5106
|
+
if (err) {
|
|
5107
|
+
this.#error(`FhirSocketClient:CreateResources(): ID: [${this.#id}] clientName: [${this.#clientName}] Error: [${err}]`);
|
|
5108
|
+
reject(err);
|
|
5109
|
+
} else {
|
|
5110
|
+
resolve(res);
|
|
5111
|
+
}
|
|
5151
5112
|
});
|
|
5113
|
+
});
|
|
5114
|
+
};
|
|
5115
|
+
return (await promCreate()).value;
|
|
5116
|
+
};
|
|
5117
|
+
GetResource = async (resource, resourceId) => {
|
|
5118
|
+
await this.WaitForSocketConnected();
|
|
5119
|
+
const promGet = () => {
|
|
5120
|
+
const request = {
|
|
5121
|
+
headers: {
|
|
5122
|
+
"x-sts_user_id": "someuser"
|
|
5123
|
+
},
|
|
5124
|
+
params: {},
|
|
5125
|
+
query: {
|
|
5126
|
+
fhirResource: resourceId
|
|
5127
|
+
},
|
|
5128
|
+
body: {}
|
|
5152
5129
|
};
|
|
5153
|
-
return
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
},
|
|
5162
|
-
params: {},
|
|
5163
|
-
query: searchParams ? searchParams : {},
|
|
5164
|
-
body: {}
|
|
5165
|
-
};
|
|
5166
|
-
return new Promise((resolve, reject) => {
|
|
5167
|
-
this.socket.timeout(__privateGet(this, _options2).timeout).emit("getFhirResources", resource, request, (err, res) => {
|
|
5168
|
-
if (err) {
|
|
5169
|
-
__privateGet(this, _error).call(this, `FhirSocketClient:GetResources(): ID: [${__privateGet(this, _id)}] clientName: [${__privateGet(this, _clientName)}] Error: [${err}]`);
|
|
5170
|
-
reject(err);
|
|
5171
|
-
} else {
|
|
5172
|
-
resolve(res);
|
|
5173
|
-
}
|
|
5174
|
-
});
|
|
5130
|
+
return new Promise((resolve, reject) => {
|
|
5131
|
+
this.socket.timeout(this.#options.timeout).emit("getFhirResource", resource, request, (err, res) => {
|
|
5132
|
+
if (err) {
|
|
5133
|
+
this.#error(`FhirSocketClient:GetResource(): ID: [${this.#id}] clientName: [${this.#clientName}] Error: [${err}]`);
|
|
5134
|
+
reject(err);
|
|
5135
|
+
} else {
|
|
5136
|
+
resolve(res);
|
|
5137
|
+
}
|
|
5175
5138
|
});
|
|
5139
|
+
});
|
|
5140
|
+
};
|
|
5141
|
+
return promGet();
|
|
5142
|
+
};
|
|
5143
|
+
GetResources = async (resource, searchParams) => {
|
|
5144
|
+
await this.WaitForSocketConnected();
|
|
5145
|
+
const promGet = () => {
|
|
5146
|
+
const request = {
|
|
5147
|
+
headers: {
|
|
5148
|
+
"x-sts_user_id": "someuser"
|
|
5149
|
+
},
|
|
5150
|
+
params: {},
|
|
5151
|
+
query: searchParams ? searchParams : {},
|
|
5152
|
+
body: {}
|
|
5176
5153
|
};
|
|
5177
|
-
return (
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
},
|
|
5186
|
-
params: {},
|
|
5187
|
-
query: {
|
|
5188
|
-
fhirResource: domainResource.id
|
|
5189
|
-
},
|
|
5190
|
-
body: domainResource
|
|
5191
|
-
};
|
|
5192
|
-
return new Promise((resolve, reject) => {
|
|
5193
|
-
this.socket.timeout(__privateGet(this, _options2).timeout).emit("updateFhirResource", resource, request, (err, res) => {
|
|
5194
|
-
if (err) {
|
|
5195
|
-
__privateGet(this, _error).call(this, `FhirSocketClient:UpdateResource(): ID: [${__privateGet(this, _id)}] clientName: [${__privateGet(this, _clientName)}] Error: [${err}]`);
|
|
5196
|
-
reject(err);
|
|
5197
|
-
} else {
|
|
5198
|
-
resolve(res);
|
|
5199
|
-
}
|
|
5200
|
-
});
|
|
5154
|
+
return new Promise((resolve, reject) => {
|
|
5155
|
+
this.socket.timeout(this.#options.timeout).emit("getFhirResources", resource, request, (err, res) => {
|
|
5156
|
+
if (err) {
|
|
5157
|
+
this.#error(`FhirSocketClient:GetResources(): ID: [${this.#id}] clientName: [${this.#clientName}] Error: [${err}]`);
|
|
5158
|
+
reject(err);
|
|
5159
|
+
} else {
|
|
5160
|
+
resolve(res);
|
|
5161
|
+
}
|
|
5201
5162
|
});
|
|
5163
|
+
});
|
|
5164
|
+
};
|
|
5165
|
+
return (await promGet()).value;
|
|
5166
|
+
};
|
|
5167
|
+
UpdateResource = async (resource, domainResource) => {
|
|
5168
|
+
await this.WaitForSocketConnected();
|
|
5169
|
+
const promCreate = () => {
|
|
5170
|
+
const request = {
|
|
5171
|
+
headers: {
|
|
5172
|
+
"x-sts_user_id": "someuser"
|
|
5173
|
+
},
|
|
5174
|
+
params: {},
|
|
5175
|
+
query: {
|
|
5176
|
+
fhirResource: domainResource.id
|
|
5177
|
+
},
|
|
5178
|
+
body: domainResource
|
|
5202
5179
|
};
|
|
5203
|
-
return (
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
},
|
|
5212
|
-
params: {},
|
|
5213
|
-
query: {},
|
|
5214
|
-
body: domainResources
|
|
5215
|
-
};
|
|
5216
|
-
return new Promise((resolve, reject) => {
|
|
5217
|
-
this.socket.timeout(__privateGet(this, _options2).timeout).emit("updateFhirResources", resource, request, (err, res) => {
|
|
5218
|
-
if (err) {
|
|
5219
|
-
__privateGet(this, _error).call(this, `FhirSocketClient:UpdateResources(): ID: [${__privateGet(this, _id)}] clientName: [${__privateGet(this, _clientName)}] Error: [${err}]`);
|
|
5220
|
-
reject(err);
|
|
5221
|
-
} else {
|
|
5222
|
-
resolve(res);
|
|
5223
|
-
}
|
|
5224
|
-
});
|
|
5180
|
+
return new Promise((resolve, reject) => {
|
|
5181
|
+
this.socket.timeout(this.#options.timeout).emit("updateFhirResource", resource, request, (err, res) => {
|
|
5182
|
+
if (err) {
|
|
5183
|
+
this.#error(`FhirSocketClient:UpdateResource(): ID: [${this.#id}] clientName: [${this.#clientName}] Error: [${err}]`);
|
|
5184
|
+
reject(err);
|
|
5185
|
+
} else {
|
|
5186
|
+
resolve(res);
|
|
5187
|
+
}
|
|
5225
5188
|
});
|
|
5189
|
+
});
|
|
5190
|
+
};
|
|
5191
|
+
return (await promCreate()).value;
|
|
5192
|
+
};
|
|
5193
|
+
UpdateResources = async (resource, domainResources) => {
|
|
5194
|
+
await this.WaitForSocketConnected();
|
|
5195
|
+
const promCreate = () => {
|
|
5196
|
+
const request = {
|
|
5197
|
+
headers: {
|
|
5198
|
+
"x-sts_user_id": "someuser"
|
|
5199
|
+
},
|
|
5200
|
+
params: {},
|
|
5201
|
+
query: {},
|
|
5202
|
+
body: domainResources
|
|
5226
5203
|
};
|
|
5227
|
-
return (
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
},
|
|
5236
|
-
params: {},
|
|
5237
|
-
query: {
|
|
5238
|
-
fhirResource: domainResource.id
|
|
5239
|
-
},
|
|
5240
|
-
body: domainResource
|
|
5241
|
-
};
|
|
5242
|
-
return new Promise((resolve, reject) => {
|
|
5243
|
-
this.socket.timeout(__privateGet(this, _options2).timeout).emit("patchFhirResource", resource, request, (err, res) => {
|
|
5244
|
-
if (err) {
|
|
5245
|
-
__privateGet(this, _error).call(this, `FhirSocketClient:PatchResource(): ID: [${__privateGet(this, _id)}] clientName: [${__privateGet(this, _clientName)}] Error: [${err}]`);
|
|
5246
|
-
reject(err);
|
|
5247
|
-
} else {
|
|
5248
|
-
resolve(res);
|
|
5249
|
-
}
|
|
5250
|
-
});
|
|
5204
|
+
return new Promise((resolve, reject) => {
|
|
5205
|
+
this.socket.timeout(this.#options.timeout).emit("updateFhirResources", resource, request, (err, res) => {
|
|
5206
|
+
if (err) {
|
|
5207
|
+
this.#error(`FhirSocketClient:UpdateResources(): ID: [${this.#id}] clientName: [${this.#clientName}] Error: [${err}]`);
|
|
5208
|
+
reject(err);
|
|
5209
|
+
} else {
|
|
5210
|
+
resolve(res);
|
|
5211
|
+
}
|
|
5251
5212
|
});
|
|
5213
|
+
});
|
|
5214
|
+
};
|
|
5215
|
+
return (await promCreate()).value;
|
|
5216
|
+
};
|
|
5217
|
+
PatchResource = async (resource, domainResource) => {
|
|
5218
|
+
await this.WaitForSocketConnected();
|
|
5219
|
+
const promCreate = () => {
|
|
5220
|
+
const request = {
|
|
5221
|
+
headers: {
|
|
5222
|
+
"x-sts_user_id": "someuser"
|
|
5223
|
+
},
|
|
5224
|
+
params: {},
|
|
5225
|
+
query: {
|
|
5226
|
+
fhirResource: domainResource.id
|
|
5227
|
+
},
|
|
5228
|
+
body: domainResource
|
|
5252
5229
|
};
|
|
5253
|
-
return (
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
},
|
|
5262
|
-
params: {},
|
|
5263
|
-
query: {},
|
|
5264
|
-
body: domainResources
|
|
5265
|
-
};
|
|
5266
|
-
return new Promise((resolve, reject) => {
|
|
5267
|
-
this.socket.timeout(__privateGet(this, _options2).timeout).emit("patchFhirResources", resource, request, (err, res) => {
|
|
5268
|
-
if (err) {
|
|
5269
|
-
__privateGet(this, _error).call(this, `FhirSocketClient:PatchResources(): ID: [${__privateGet(this, _id)}] clientName: [${__privateGet(this, _clientName)}] Error: [${err}]`);
|
|
5270
|
-
reject(err);
|
|
5271
|
-
} else {
|
|
5272
|
-
resolve(res);
|
|
5273
|
-
}
|
|
5274
|
-
});
|
|
5230
|
+
return new Promise((resolve, reject) => {
|
|
5231
|
+
this.socket.timeout(this.#options.timeout).emit("patchFhirResource", resource, request, (err, res) => {
|
|
5232
|
+
if (err) {
|
|
5233
|
+
this.#error(`FhirSocketClient:PatchResource(): ID: [${this.#id}] clientName: [${this.#clientName}] Error: [${err}]`);
|
|
5234
|
+
reject(err);
|
|
5235
|
+
} else {
|
|
5236
|
+
resolve(res);
|
|
5237
|
+
}
|
|
5275
5238
|
});
|
|
5239
|
+
});
|
|
5240
|
+
};
|
|
5241
|
+
return (await promCreate()).value;
|
|
5242
|
+
};
|
|
5243
|
+
PatchResources = async (resource, domainResources) => {
|
|
5244
|
+
await this.WaitForSocketConnected();
|
|
5245
|
+
const promCreate = () => {
|
|
5246
|
+
const request = {
|
|
5247
|
+
headers: {
|
|
5248
|
+
"x-sts_user_id": "someuser"
|
|
5249
|
+
},
|
|
5250
|
+
params: {},
|
|
5251
|
+
query: {},
|
|
5252
|
+
body: domainResources
|
|
5276
5253
|
};
|
|
5277
|
-
return (
|
|
5278
|
-
|
|
5279
|
-
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
},
|
|
5286
|
-
params: {},
|
|
5287
|
-
query: {
|
|
5288
|
-
fhirResource: resourceId
|
|
5289
|
-
},
|
|
5290
|
-
body: {}
|
|
5291
|
-
};
|
|
5292
|
-
return new Promise((resolve, reject) => {
|
|
5293
|
-
this.socket.timeout(__privateGet(this, _options2).timeout).emit("deleteFhirResource", resource, request, (err, res) => {
|
|
5294
|
-
if (err) {
|
|
5295
|
-
__privateGet(this, _error).call(this, `FhirSocketClient:DeleteResource(): ID: [${__privateGet(this, _id)}] clientName: [${__privateGet(this, _clientName)}] Error: [${err}]`);
|
|
5296
|
-
reject(err);
|
|
5297
|
-
} else {
|
|
5298
|
-
resolve(res);
|
|
5299
|
-
}
|
|
5300
|
-
});
|
|
5254
|
+
return new Promise((resolve, reject) => {
|
|
5255
|
+
this.socket.timeout(this.#options.timeout).emit("patchFhirResources", resource, request, (err, res) => {
|
|
5256
|
+
if (err) {
|
|
5257
|
+
this.#error(`FhirSocketClient:PatchResources(): ID: [${this.#id}] clientName: [${this.#clientName}] Error: [${err}]`);
|
|
5258
|
+
reject(err);
|
|
5259
|
+
} else {
|
|
5260
|
+
resolve(res);
|
|
5261
|
+
}
|
|
5301
5262
|
});
|
|
5263
|
+
});
|
|
5264
|
+
};
|
|
5265
|
+
return (await promCreate()).value;
|
|
5266
|
+
};
|
|
5267
|
+
DeleteResource = async (resource, resourceId) => {
|
|
5268
|
+
await this.WaitForSocketConnected();
|
|
5269
|
+
const promCreate = () => {
|
|
5270
|
+
const request = {
|
|
5271
|
+
headers: {
|
|
5272
|
+
"x-sts_user_id": "someuser"
|
|
5273
|
+
},
|
|
5274
|
+
params: {},
|
|
5275
|
+
query: {
|
|
5276
|
+
fhirResource: resourceId
|
|
5277
|
+
},
|
|
5278
|
+
body: {}
|
|
5302
5279
|
};
|
|
5303
|
-
return (
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
},
|
|
5312
|
-
params: {},
|
|
5313
|
-
query: {},
|
|
5314
|
-
body: domainResource
|
|
5315
|
-
};
|
|
5316
|
-
return new Promise((resolve, reject) => {
|
|
5317
|
-
this.socket.timeout(__privateGet(this, _options2).timeout).emit("deleteFhirResources", resource, delRequest, (err, res) => {
|
|
5318
|
-
if (err) {
|
|
5319
|
-
__privateGet(this, _error).call(this, `FhirSocketClient:DeleteResources(): ID: [${__privateGet(this, _id)}] clientName: [${__privateGet(this, _clientName)}] Error: [${err}]`);
|
|
5320
|
-
reject(err);
|
|
5321
|
-
} else {
|
|
5322
|
-
resolve(res);
|
|
5323
|
-
}
|
|
5324
|
-
});
|
|
5280
|
+
return new Promise((resolve, reject) => {
|
|
5281
|
+
this.socket.timeout(this.#options.timeout).emit("deleteFhirResource", resource, request, (err, res) => {
|
|
5282
|
+
if (err) {
|
|
5283
|
+
this.#error(`FhirSocketClient:DeleteResource(): ID: [${this.#id}] clientName: [${this.#clientName}] Error: [${err}]`);
|
|
5284
|
+
reject(err);
|
|
5285
|
+
} else {
|
|
5286
|
+
resolve(res);
|
|
5287
|
+
}
|
|
5325
5288
|
});
|
|
5289
|
+
});
|
|
5290
|
+
};
|
|
5291
|
+
return (await promCreate()).value;
|
|
5292
|
+
};
|
|
5293
|
+
DeleteResources = async (resource, domainResource) => {
|
|
5294
|
+
await this.WaitForSocketConnected();
|
|
5295
|
+
const prom = () => {
|
|
5296
|
+
const delRequest = {
|
|
5297
|
+
headers: {
|
|
5298
|
+
"x-sts_user_id": "someuser"
|
|
5299
|
+
},
|
|
5300
|
+
params: {},
|
|
5301
|
+
query: {},
|
|
5302
|
+
body: domainResource
|
|
5326
5303
|
};
|
|
5327
|
-
return (
|
|
5328
|
-
|
|
5329
|
-
|
|
5330
|
-
|
|
5331
|
-
|
|
5332
|
-
|
|
5333
|
-
|
|
5334
|
-
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
|
|
5304
|
+
return new Promise((resolve, reject) => {
|
|
5305
|
+
this.socket.timeout(this.#options.timeout).emit("deleteFhirResources", resource, delRequest, (err, res) => {
|
|
5306
|
+
if (err) {
|
|
5307
|
+
this.#error(`FhirSocketClient:DeleteResources(): ID: [${this.#id}] clientName: [${this.#clientName}] Error: [${err}]`);
|
|
5308
|
+
reject(err);
|
|
5309
|
+
} else {
|
|
5310
|
+
resolve(res);
|
|
5311
|
+
}
|
|
5312
|
+
});
|
|
5313
|
+
});
|
|
5314
|
+
};
|
|
5315
|
+
return (await prom()).value;
|
|
5316
|
+
};
|
|
5338
5317
|
}
|
|
5339
|
-
_socketUtils = new WeakMap();
|
|
5340
|
-
_id = new WeakMap();
|
|
5341
|
-
_options2 = new WeakMap();
|
|
5342
|
-
_clientName = new WeakMap();
|
|
5343
|
-
_debug = new WeakMap();
|
|
5344
|
-
_error = new WeakMap();
|
|
5345
|
-
_info = new WeakMap();
|
|
5346
|
-
_SetupWSSClient = new WeakMap();
|
|
5347
|
-
_OnSocketConnected = new WeakMap();
|
|
5348
5318
|
function sleep(ms) {
|
|
5349
5319
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
5350
5320
|
}
|
|
@@ -5388,7 +5358,6 @@ function createRetryAxiosClient(retryConfig) {
|
|
|
5388
5358
|
instance.interceptors.response.use(
|
|
5389
5359
|
(response) => response,
|
|
5390
5360
|
async (error) => {
|
|
5391
|
-
var _a;
|
|
5392
5361
|
const config = error.config;
|
|
5393
5362
|
if (!config || !config.method || !config.metadata) {
|
|
5394
5363
|
return Promise.reject(error);
|
|
@@ -5396,7 +5365,7 @@ function createRetryAxiosClient(retryConfig) {
|
|
|
5396
5365
|
const now = Date.now();
|
|
5397
5366
|
const elapsed = now - config.metadata.startTime;
|
|
5398
5367
|
const method = config.method.toLowerCase();
|
|
5399
|
-
const status =
|
|
5368
|
+
const status = error.response?.status;
|
|
5400
5369
|
const code = error.code;
|
|
5401
5370
|
const isRetryable = retryMethods.includes(method) && (retryErrorCodes.includes(code || "") || retryStatusCodes.includes(status || 0));
|
|
5402
5371
|
if (config.metadata.__retryCount < maxRetries && isRetryable && elapsed < maxRetryDurationMs) {
|
|
@@ -5415,317 +5384,307 @@ function createRetryAxiosClient(retryConfig) {
|
|
|
5415
5384
|
return instance;
|
|
5416
5385
|
}
|
|
5417
5386
|
class FhirClient {
|
|
5387
|
+
#options;
|
|
5388
|
+
#DUMMY_USER = "USR_user01@stsmda.com.au";
|
|
5389
|
+
//@@ needs to come from headers ??
|
|
5390
|
+
#stsfhirapiroot = "/stsfhirv2/r5";
|
|
5391
|
+
// Default value
|
|
5392
|
+
#fhirSocketClient = void 0;
|
|
5418
5393
|
constructor(options) {
|
|
5419
|
-
|
|
5420
|
-
|
|
5421
|
-
|
|
5422
|
-
|
|
5423
|
-
|
|
5424
|
-
|
|
5425
|
-
|
|
5426
|
-
|
|
5427
|
-
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5394
|
+
this.#options = options;
|
|
5395
|
+
if (this.#options.stsfhirapiroot !== void 0) {
|
|
5396
|
+
this.#stsfhirapiroot = this.#options.stsfhirapiroot;
|
|
5397
|
+
}
|
|
5398
|
+
if (this.#options.useSocketClient === true && this.#options.socketClientOptions) {
|
|
5399
|
+
this.#fhirSocketClient = new FhirSocketClient(this.#options.socketClientOptions);
|
|
5400
|
+
}
|
|
5401
|
+
}
|
|
5402
|
+
get options() {
|
|
5403
|
+
return this.#options;
|
|
5404
|
+
}
|
|
5405
|
+
#LogDebugMessage = (message) => {
|
|
5406
|
+
this.#options.logger.debug(message);
|
|
5407
|
+
};
|
|
5408
|
+
#HandleError = (error) => {
|
|
5409
|
+
this.#LogDebugMessage(chalk.red(`HandleError(): Error: [${error}]`));
|
|
5410
|
+
let responseCode = 500;
|
|
5411
|
+
if (axios.isAxiosError(error)) {
|
|
5412
|
+
const axiosError = error;
|
|
5413
|
+
if (axiosError.response) {
|
|
5414
|
+
responseCode = axiosError.response.status;
|
|
5415
|
+
this.#LogDebugMessage(chalk.red(`AXIOS Error Response.Status = [${axiosError.response.status}]`));
|
|
5416
|
+
} else {
|
|
5417
|
+
this.#LogDebugMessage(chalk.red(`AXIOS Error = [${axiosError}]`));
|
|
5439
5418
|
}
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5419
|
+
}
|
|
5420
|
+
return responseCode;
|
|
5421
|
+
};
|
|
5422
|
+
#BuildQueryString = (baseUrl, queryParams) => {
|
|
5423
|
+
const url2 = new URL(baseUrl);
|
|
5424
|
+
const searchParams = new URLSearchParams(queryParams);
|
|
5425
|
+
url2.search = searchParams.toString();
|
|
5426
|
+
return url2.toString();
|
|
5427
|
+
};
|
|
5428
|
+
#InvokeResourceAPI = async (url2, httpVerb, domainResource, filters) => {
|
|
5429
|
+
const accessToken = await this.#options.GetAccessToken();
|
|
5430
|
+
const requestConfig = new STSAxiosConfig(url2, httpVerb).withAuthHeaders(accessToken, this.#DUMMY_USER).withData(filters ? filters : domainResource ? domainResource : void 0);
|
|
5431
|
+
if (isNode$1 && this.#options.agentManager) {
|
|
5432
|
+
requestConfig.withAgentManager(this.#options.agentManager);
|
|
5433
|
+
}
|
|
5434
|
+
const api = createRetryAxiosClient({
|
|
5435
|
+
maxRetries: 4,
|
|
5436
|
+
retryDelayMs: 300,
|
|
5437
|
+
retryJitterMs: 150,
|
|
5438
|
+
maxRetryDurationMs: 5e3,
|
|
5439
|
+
onRetryAttempt: (attempt, error, delayMs) => {
|
|
5440
|
+
console.warn(`Retry #${attempt} after ${delayMs}ms due to ${error.code || error.response?.status}`);
|
|
5453
5441
|
}
|
|
5454
|
-
|
|
5455
|
-
|
|
5456
|
-
retryDelayMs: 300,
|
|
5457
|
-
retryJitterMs: 150,
|
|
5458
|
-
maxRetryDurationMs: 5e3,
|
|
5459
|
-
onRetryAttempt: (attempt, error, delayMs) => {
|
|
5460
|
-
var _a;
|
|
5461
|
-
console.warn(`Retry #${attempt} after ${delayMs}ms due to ${error.code || ((_a = error.response) == null ? void 0 : _a.status)}`);
|
|
5462
|
-
}
|
|
5463
|
-
// Below works also ...
|
|
5464
|
-
//stsAxiosConfig: requestConfig
|
|
5465
|
-
});
|
|
5466
|
-
return await api(url2, requestConfig.config);
|
|
5442
|
+
// Below works also ...
|
|
5443
|
+
//stsAxiosConfig: requestConfig
|
|
5467
5444
|
});
|
|
5468
|
-
|
|
5469
|
-
|
|
5470
|
-
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
errorResponse.response = {
|
|
5477
|
-
status: retVal.status
|
|
5478
|
-
};
|
|
5479
|
-
throw errorResponse;
|
|
5480
|
-
}
|
|
5481
|
-
} catch (error) {
|
|
5482
|
-
const errorResponse = new Error(`GetResource(): Error: [${error}]`);
|
|
5483
|
-
errorResponse.response = {
|
|
5484
|
-
status: StatusCodes.INTERNAL_SERVER_ERROR
|
|
5485
|
-
};
|
|
5486
|
-
throw errorResponse;
|
|
5487
|
-
}
|
|
5488
|
-
} else {
|
|
5489
|
-
const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}/${id}`;
|
|
5490
|
-
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "get", null, filters);
|
|
5491
|
-
if (response) {
|
|
5492
|
-
return response.data;
|
|
5445
|
+
return await api(url2, requestConfig.config);
|
|
5446
|
+
};
|
|
5447
|
+
GetResource = async (resource, id, filters) => {
|
|
5448
|
+
if (this.#options.useSocketClient === true && this.#fhirSocketClient) {
|
|
5449
|
+
try {
|
|
5450
|
+
const retVal = await this.#fhirSocketClient.GetResource(resource, id);
|
|
5451
|
+
if (retVal.status === StatusCodes.OK) {
|
|
5452
|
+
return retVal.value;
|
|
5493
5453
|
} else {
|
|
5494
|
-
|
|
5495
|
-
}
|
|
5496
|
-
}
|
|
5497
|
-
});
|
|
5498
|
-
__publicField(this, "GetResources", async (resource, filters, searchParams) => {
|
|
5499
|
-
if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
|
|
5500
|
-
try {
|
|
5501
|
-
return __privateGet(this, _fhirSocketClient).GetResources(resource, searchParams);
|
|
5502
|
-
} catch (error) {
|
|
5503
|
-
const errorResponse = new Error(`GetResources(): Error: [${error}]`);
|
|
5454
|
+
const errorResponse = new Error(`GetResource(): Invalid response status code: [${retVal.status}] expected: [${StatusCodes.OK}]`);
|
|
5504
5455
|
errorResponse.response = {
|
|
5505
|
-
status:
|
|
5456
|
+
status: retVal.status
|
|
5506
5457
|
};
|
|
5507
5458
|
throw errorResponse;
|
|
5508
5459
|
}
|
|
5460
|
+
} catch (error) {
|
|
5461
|
+
const errorResponse = new Error(`GetResource(): Error: [${error}]`);
|
|
5462
|
+
errorResponse.response = {
|
|
5463
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR
|
|
5464
|
+
};
|
|
5465
|
+
throw errorResponse;
|
|
5466
|
+
}
|
|
5467
|
+
} else {
|
|
5468
|
+
const url2 = `${this.#options.fhirEndpoint}${this.#stsfhirapiroot}/${resource}/${id}`;
|
|
5469
|
+
const response = await this.#InvokeResourceAPI(url2, "get", null, filters);
|
|
5470
|
+
if (response) {
|
|
5471
|
+
return response.data;
|
|
5509
5472
|
} else {
|
|
5510
|
-
|
|
5511
|
-
if (searchParams) {
|
|
5512
|
-
url2 = __privateGet(this, _BuildQueryString).call(this, url2, searchParams);
|
|
5513
|
-
}
|
|
5514
|
-
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "get", null, filters);
|
|
5515
|
-
if (response) {
|
|
5516
|
-
return response.data;
|
|
5517
|
-
} else {
|
|
5518
|
-
return null;
|
|
5519
|
-
}
|
|
5473
|
+
return null;
|
|
5520
5474
|
}
|
|
5521
|
-
}
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
|
|
5528
|
-
|
|
5529
|
-
|
|
5530
|
-
|
|
5531
|
-
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5475
|
+
}
|
|
5476
|
+
};
|
|
5477
|
+
GetResources = async (resource, filters, searchParams) => {
|
|
5478
|
+
if (this.#options.useSocketClient === true && this.#fhirSocketClient) {
|
|
5479
|
+
try {
|
|
5480
|
+
return this.#fhirSocketClient.GetResources(resource, searchParams);
|
|
5481
|
+
} catch (error) {
|
|
5482
|
+
const errorResponse = new Error(`GetResources(): Error: [${error}]`);
|
|
5483
|
+
errorResponse.response = {
|
|
5484
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR
|
|
5485
|
+
};
|
|
5486
|
+
throw errorResponse;
|
|
5487
|
+
}
|
|
5488
|
+
} else {
|
|
5489
|
+
let url2 = `${this.#options.fhirEndpoint}${this.#stsfhirapiroot}/${resource}`;
|
|
5490
|
+
if (searchParams) {
|
|
5491
|
+
url2 = this.#BuildQueryString(url2, searchParams);
|
|
5492
|
+
}
|
|
5493
|
+
const response = await this.#InvokeResourceAPI(url2, "get", null, filters);
|
|
5494
|
+
if (response) {
|
|
5495
|
+
return response.data;
|
|
5542
5496
|
} else {
|
|
5543
|
-
|
|
5544
|
-
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "post", domainResource, null);
|
|
5545
|
-
if (response) {
|
|
5546
|
-
if (response.status === StatusCodes.CREATED) {
|
|
5547
|
-
return response.data;
|
|
5548
|
-
} else {
|
|
5549
|
-
throw new Error(`CreateResource(): Invalid response status code: [${response.status}] expected: [${StatusCodes.CREATED}]`);
|
|
5550
|
-
}
|
|
5551
|
-
} else {
|
|
5552
|
-
return null;
|
|
5553
|
-
}
|
|
5497
|
+
return null;
|
|
5554
5498
|
}
|
|
5555
|
-
}
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
|
|
5499
|
+
}
|
|
5500
|
+
};
|
|
5501
|
+
CreateResource = async (resource, domainResource) => {
|
|
5502
|
+
if (this.#options.useSocketClient === true && this.#fhirSocketClient) {
|
|
5503
|
+
try {
|
|
5504
|
+
const retVal = await this.#fhirSocketClient.CreateResource(resource, domainResource);
|
|
5505
|
+
if (retVal.status === StatusCodes.CREATED) {
|
|
5506
|
+
return retVal.value;
|
|
5507
|
+
} else {
|
|
5508
|
+
const errorResponse = new Error(`CreateResource(): Invalid response status code: [${retVal.status}] expected: [${StatusCodes.CREATED}]`);
|
|
5562
5509
|
errorResponse.response = {
|
|
5563
|
-
status:
|
|
5510
|
+
status: retVal.status
|
|
5564
5511
|
};
|
|
5565
5512
|
throw errorResponse;
|
|
5566
5513
|
}
|
|
5567
|
-
}
|
|
5568
|
-
const
|
|
5569
|
-
|
|
5570
|
-
|
|
5514
|
+
} catch (error) {
|
|
5515
|
+
const errorResponse = new Error(`CreateResource(): Error: [${error}]`);
|
|
5516
|
+
errorResponse.response = {
|
|
5517
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR
|
|
5518
|
+
};
|
|
5519
|
+
throw errorResponse;
|
|
5520
|
+
}
|
|
5521
|
+
} else {
|
|
5522
|
+
const url2 = `${this.#options.fhirEndpoint}${this.#stsfhirapiroot}/${resource}`;
|
|
5523
|
+
const response = await this.#InvokeResourceAPI(url2, "post", domainResource, null);
|
|
5524
|
+
if (response) {
|
|
5525
|
+
if (response.status === StatusCodes.CREATED) {
|
|
5571
5526
|
return response.data;
|
|
5572
5527
|
} else {
|
|
5573
|
-
|
|
5528
|
+
throw new Error(`CreateResource(): Invalid response status code: [${response.status}] expected: [${StatusCodes.CREATED}]`);
|
|
5574
5529
|
}
|
|
5530
|
+
} else {
|
|
5531
|
+
return null;
|
|
5575
5532
|
}
|
|
5576
|
-
}
|
|
5577
|
-
|
|
5578
|
-
|
|
5579
|
-
|
|
5580
|
-
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5533
|
+
}
|
|
5534
|
+
};
|
|
5535
|
+
UpdateResource = async (resource, domainResource) => {
|
|
5536
|
+
if (this.#options.useSocketClient === true && this.#fhirSocketClient) {
|
|
5537
|
+
try {
|
|
5538
|
+
return this.#fhirSocketClient.UpdateResource(resource, domainResource);
|
|
5539
|
+
} catch (error) {
|
|
5540
|
+
const errorResponse = new Error(`UpdateResource(): Error: [${error}]`);
|
|
5541
|
+
errorResponse.response = {
|
|
5542
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR
|
|
5543
|
+
};
|
|
5544
|
+
throw errorResponse;
|
|
5545
|
+
}
|
|
5546
|
+
} else {
|
|
5547
|
+
const url2 = `${this.#options.fhirEndpoint}${this.#stsfhirapiroot}/${resource}/${domainResource.id}`;
|
|
5548
|
+
const response = await this.#InvokeResourceAPI(url2, "put", domainResource, null);
|
|
5549
|
+
if (response) {
|
|
5550
|
+
return response.data;
|
|
5588
5551
|
} else {
|
|
5589
|
-
|
|
5590
|
-
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "put", domainResources, null);
|
|
5591
|
-
if (response) {
|
|
5592
|
-
return response.data;
|
|
5593
|
-
} else {
|
|
5594
|
-
return null;
|
|
5595
|
-
}
|
|
5552
|
+
return null;
|
|
5596
5553
|
}
|
|
5597
|
-
}
|
|
5598
|
-
|
|
5599
|
-
|
|
5600
|
-
|
|
5601
|
-
|
|
5602
|
-
|
|
5603
|
-
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
|
|
5554
|
+
}
|
|
5555
|
+
};
|
|
5556
|
+
UpdateResources = async (resource, domainResources) => {
|
|
5557
|
+
if (this.#options.useSocketClient === true && this.#fhirSocketClient) {
|
|
5558
|
+
try {
|
|
5559
|
+
return this.#fhirSocketClient.UpdateResources(resource, domainResources);
|
|
5560
|
+
} catch (error) {
|
|
5561
|
+
const errorResponse = new Error(`UpdateResources(): Error: [${error}]`);
|
|
5562
|
+
errorResponse.response = {
|
|
5563
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR
|
|
5564
|
+
};
|
|
5565
|
+
throw errorResponse;
|
|
5566
|
+
}
|
|
5567
|
+
} else {
|
|
5568
|
+
const url2 = `${this.#options.fhirEndpoint}${this.#stsfhirapiroot}/${resource}`;
|
|
5569
|
+
const response = await this.#InvokeResourceAPI(url2, "put", domainResources, null);
|
|
5570
|
+
if (response) {
|
|
5571
|
+
return response.data;
|
|
5609
5572
|
} else {
|
|
5610
|
-
|
|
5611
|
-
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "patch", domainResource, null);
|
|
5612
|
-
if (response) {
|
|
5613
|
-
return response.data;
|
|
5614
|
-
} else {
|
|
5615
|
-
return null;
|
|
5616
|
-
}
|
|
5573
|
+
return null;
|
|
5617
5574
|
}
|
|
5618
|
-
}
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
|
|
5624
|
-
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
|
|
5629
|
-
|
|
5575
|
+
}
|
|
5576
|
+
};
|
|
5577
|
+
PatchResource = async (resource, domainResource) => {
|
|
5578
|
+
if (this.#options.useSocketClient === true && this.#fhirSocketClient) {
|
|
5579
|
+
try {
|
|
5580
|
+
return this.#fhirSocketClient.PatchResource(resource, domainResource);
|
|
5581
|
+
} catch (error) {
|
|
5582
|
+
const errorResponse = new Error(`PatchResource(): Error: [${error}]`);
|
|
5583
|
+
errorResponse.response = {
|
|
5584
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR
|
|
5585
|
+
};
|
|
5586
|
+
throw errorResponse;
|
|
5587
|
+
}
|
|
5588
|
+
} else {
|
|
5589
|
+
const url2 = `${this.#options.fhirEndpoint}${this.#stsfhirapiroot}/${resource}/${domainResource.id}`;
|
|
5590
|
+
const response = await this.#InvokeResourceAPI(url2, "patch", domainResource, null);
|
|
5591
|
+
if (response) {
|
|
5592
|
+
return response.data;
|
|
5630
5593
|
} else {
|
|
5631
|
-
|
|
5632
|
-
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "patch", domainResources, null);
|
|
5633
|
-
if (response) {
|
|
5634
|
-
return response.data;
|
|
5635
|
-
} else {
|
|
5636
|
-
return null;
|
|
5637
|
-
}
|
|
5594
|
+
return null;
|
|
5638
5595
|
}
|
|
5639
|
-
}
|
|
5640
|
-
|
|
5641
|
-
|
|
5642
|
-
|
|
5643
|
-
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5650
|
-
|
|
5596
|
+
}
|
|
5597
|
+
};
|
|
5598
|
+
PatchResources = async (resource, domainResources) => {
|
|
5599
|
+
if (this.#options.useSocketClient === true && this.#fhirSocketClient) {
|
|
5600
|
+
try {
|
|
5601
|
+
return this.#fhirSocketClient.PatchResources(resource, domainResources);
|
|
5602
|
+
} catch (error) {
|
|
5603
|
+
const errorResponse = new Error(`PatchResources(): Error: [${error}]`);
|
|
5604
|
+
errorResponse.response = {
|
|
5605
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR
|
|
5606
|
+
};
|
|
5607
|
+
throw errorResponse;
|
|
5608
|
+
}
|
|
5609
|
+
} else {
|
|
5610
|
+
const url2 = `${this.#options.fhirEndpoint}${this.#stsfhirapiroot}/${resource}`;
|
|
5611
|
+
const response = await this.#InvokeResourceAPI(url2, "patch", domainResources, null);
|
|
5612
|
+
if (response) {
|
|
5613
|
+
return response.data;
|
|
5651
5614
|
} else {
|
|
5652
|
-
|
|
5653
|
-
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "delete", null, null);
|
|
5654
|
-
if (response) {
|
|
5655
|
-
return response.data;
|
|
5656
|
-
} else {
|
|
5657
|
-
return null;
|
|
5658
|
-
}
|
|
5615
|
+
return null;
|
|
5659
5616
|
}
|
|
5660
|
-
}
|
|
5661
|
-
|
|
5662
|
-
|
|
5663
|
-
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
|
|
5667
|
-
|
|
5668
|
-
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
|
|
5617
|
+
}
|
|
5618
|
+
};
|
|
5619
|
+
DeleteResource = async (resource, id) => {
|
|
5620
|
+
if (this.#options.useSocketClient === true && this.#fhirSocketClient) {
|
|
5621
|
+
try {
|
|
5622
|
+
return this.#fhirSocketClient.DeleteResource(resource, id);
|
|
5623
|
+
} catch (error) {
|
|
5624
|
+
const errorResponse = new Error(`DeleteResource(): Error: [${error}]`);
|
|
5625
|
+
errorResponse.response = {
|
|
5626
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR
|
|
5627
|
+
};
|
|
5628
|
+
throw errorResponse;
|
|
5629
|
+
}
|
|
5630
|
+
} else {
|
|
5631
|
+
const url2 = `${this.#options.fhirEndpoint}${this.#stsfhirapiroot}/${resource}/${id}`;
|
|
5632
|
+
const response = await this.#InvokeResourceAPI(url2, "delete", null, null);
|
|
5633
|
+
if (response) {
|
|
5634
|
+
return response.data;
|
|
5672
5635
|
} else {
|
|
5673
|
-
|
|
5674
|
-
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "delete", domainResources, null);
|
|
5675
|
-
if (response) {
|
|
5676
|
-
return response.data;
|
|
5677
|
-
} else {
|
|
5678
|
-
return null;
|
|
5679
|
-
}
|
|
5636
|
+
return null;
|
|
5680
5637
|
}
|
|
5681
|
-
}
|
|
5682
|
-
|
|
5683
|
-
|
|
5638
|
+
}
|
|
5639
|
+
};
|
|
5640
|
+
DeleteResources = async (resource, domainResources) => {
|
|
5641
|
+
if (this.#options.useSocketClient === true && this.#fhirSocketClient) {
|
|
5684
5642
|
try {
|
|
5685
|
-
|
|
5686
|
-
if (isNode$1 && __privateGet(this, _options3).agentManager) {
|
|
5687
|
-
requestConfig.withAgentManager(__privateGet(this, _options3).agentManager);
|
|
5688
|
-
}
|
|
5689
|
-
const api = createRetryAxiosClient({
|
|
5690
|
-
maxRetries: 4,
|
|
5691
|
-
retryDelayMs: 300,
|
|
5692
|
-
retryJitterMs: 150,
|
|
5693
|
-
maxRetryDurationMs: 5e3,
|
|
5694
|
-
onRetryAttempt: (attempt, error, delayMs) => {
|
|
5695
|
-
var _a;
|
|
5696
|
-
console.warn(`Retry #${attempt} after ${delayMs}ms due to ${error.code || ((_a = error.response) == null ? void 0 : _a.status)}`);
|
|
5697
|
-
}
|
|
5698
|
-
});
|
|
5699
|
-
return await api(url2, requestConfig.config);
|
|
5643
|
+
return this.#fhirSocketClient.DeleteResources(resource, domainResources);
|
|
5700
5644
|
} catch (error) {
|
|
5701
|
-
|
|
5645
|
+
const errorResponse = new Error(`DeleteResources(): Error: [${error}]`);
|
|
5646
|
+
errorResponse.response = {
|
|
5647
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR
|
|
5648
|
+
};
|
|
5649
|
+
throw errorResponse;
|
|
5702
5650
|
}
|
|
5703
|
-
}
|
|
5704
|
-
|
|
5705
|
-
|
|
5706
|
-
|
|
5651
|
+
} else {
|
|
5652
|
+
const url2 = `${this.#options.fhirEndpoint}${this.#stsfhirapiroot}/${resource}`;
|
|
5653
|
+
const response = await this.#InvokeResourceAPI(url2, "delete", domainResources, null);
|
|
5654
|
+
if (response) {
|
|
5655
|
+
return response.data;
|
|
5656
|
+
} else {
|
|
5657
|
+
return null;
|
|
5707
5658
|
}
|
|
5708
|
-
});
|
|
5709
|
-
__privateSet(this, _options3, options);
|
|
5710
|
-
if (__privateGet(this, _options3).stsfhirapiroot !== void 0) {
|
|
5711
|
-
__privateSet(this, _stsfhirapiroot, __privateGet(this, _options3).stsfhirapiroot);
|
|
5712
5659
|
}
|
|
5713
|
-
|
|
5714
|
-
|
|
5660
|
+
};
|
|
5661
|
+
GetLatency = async () => {
|
|
5662
|
+
const url2 = `${this.#options.fhirEndpoint}${this.#stsfhirapiroot}/latency`;
|
|
5663
|
+
try {
|
|
5664
|
+
const requestConfig = new STSAxiosConfig(url2, "get").withDefaultHeaders();
|
|
5665
|
+
if (isNode$1 && this.#options.agentManager) {
|
|
5666
|
+
requestConfig.withAgentManager(this.#options.agentManager);
|
|
5667
|
+
}
|
|
5668
|
+
const api = createRetryAxiosClient({
|
|
5669
|
+
maxRetries: 4,
|
|
5670
|
+
retryDelayMs: 300,
|
|
5671
|
+
retryJitterMs: 150,
|
|
5672
|
+
maxRetryDurationMs: 5e3,
|
|
5673
|
+
onRetryAttempt: (attempt, error, delayMs) => {
|
|
5674
|
+
console.warn(`Retry #${attempt} after ${delayMs}ms due to ${error.code || error.response?.status}`);
|
|
5675
|
+
}
|
|
5676
|
+
});
|
|
5677
|
+
return await api(url2, requestConfig.config);
|
|
5678
|
+
} catch (error) {
|
|
5679
|
+
this.#HandleError(error);
|
|
5715
5680
|
}
|
|
5716
|
-
}
|
|
5717
|
-
|
|
5718
|
-
|
|
5719
|
-
|
|
5681
|
+
};
|
|
5682
|
+
Terminate = () => {
|
|
5683
|
+
if (this.#fhirSocketClient) {
|
|
5684
|
+
this.#fhirSocketClient.socket.disconnect();
|
|
5685
|
+
}
|
|
5686
|
+
};
|
|
5720
5687
|
}
|
|
5721
|
-
_options3 = new WeakMap();
|
|
5722
|
-
_DUMMY_USER = new WeakMap();
|
|
5723
|
-
_stsfhirapiroot = new WeakMap();
|
|
5724
|
-
_fhirSocketClient = new WeakMap();
|
|
5725
|
-
_LogDebugMessage = new WeakMap();
|
|
5726
|
-
_HandleError = new WeakMap();
|
|
5727
|
-
_BuildQueryString = new WeakMap();
|
|
5728
|
-
_InvokeResourceAPI = new WeakMap();
|
|
5729
5688
|
export {
|
|
5730
5689
|
FhirClient
|
|
5731
5690
|
};
|