@nsshunt/stsfhirpg 1.2.28 → 1.2.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.
Files changed (32) hide show
  1. package/dist/index.cjs +1266 -803
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.mjs +1266 -803
  4. package/dist/index.mjs.map +1 -1
  5. package/package.json +1 -1
  6. package/types/fhir-database/dbsearchindexreference.d.ts.map +1 -1
  7. package/types/fhir-database/pg/pgfhiraccesslayer.d.ts +2 -1
  8. package/types/fhir-database/pg/pgfhiraccesslayer.d.ts.map +1 -1
  9. package/types/fhir-database/pg/pgfhircombo.d.ts +3 -1
  10. package/types/fhir-database/pg/pgfhircombo.d.ts.map +1 -1
  11. package/types/fhir-database/pg/pgfhirdate.d.ts +3 -1
  12. package/types/fhir-database/pg/pgfhirdate.d.ts.map +1 -1
  13. package/types/fhir-database/pg/pgfhirdbbase.d.ts +14 -0
  14. package/types/fhir-database/pg/pgfhirdbbase.d.ts.map +1 -0
  15. package/types/fhir-database/pg/pgfhirdbparamtypebase.d.ts +11 -0
  16. package/types/fhir-database/pg/pgfhirdbparamtypebase.d.ts.map +1 -0
  17. package/types/fhir-database/pg/pgfhirnumber.d.ts +3 -1
  18. package/types/fhir-database/pg/pgfhirnumber.d.ts.map +1 -1
  19. package/types/fhir-database/pg/pgfhirquantity.d.ts +3 -1
  20. package/types/fhir-database/pg/pgfhirquantity.d.ts.map +1 -1
  21. package/types/fhir-database/pg/pgfhirresource.d.ts +9 -10
  22. package/types/fhir-database/pg/pgfhirresource.d.ts.map +1 -1
  23. package/types/fhir-database/pg/pgfhirresourcelink.d.ts +3 -1
  24. package/types/fhir-database/pg/pgfhirresourcelink.d.ts.map +1 -1
  25. package/types/fhir-database/pg/pgfhirresourceversion.d.ts +5 -6
  26. package/types/fhir-database/pg/pgfhirresourceversion.d.ts.map +1 -1
  27. package/types/fhir-database/pg/pgfhirstring.d.ts +3 -1
  28. package/types/fhir-database/pg/pgfhirstring.d.ts.map +1 -1
  29. package/types/fhir-database/pg/pgfhirtoken.d.ts +3 -1
  30. package/types/fhir-database/pg/pgfhirtoken.d.ts.map +1 -1
  31. package/types/fhir-database/pg/pgfhiruri.d.ts +3 -1
  32. package/types/fhir-database/pg/pgfhiruri.d.ts.map +1 -1
package/dist/index.mjs CHANGED
@@ -13,7 +13,7 @@ import cluster from "cluster";
13
13
  import { Pool } from "pg";
14
14
  import { TinyEmitter } from "tiny-emitter";
15
15
  //#region \0rolldown/runtime.js
16
- var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
16
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
17
17
  //#endregion
18
18
  //#region src/fhir-utils/fhirDateUtils.ts
19
19
  var FHIRDateUtils = class {
@@ -3245,7 +3245,8 @@ var HashUtils = class HashUtils {
3245
3245
  return input.trim().replace(/\s+/g, " ").toLowerCase();
3246
3246
  };
3247
3247
  InitHash = async () => {
3248
- this.h64 = (await e()).h64;
3248
+ const api = await e();
3249
+ this.h64 = api.h64;
3249
3250
  };
3250
3251
  xxhash64Signed(input) {
3251
3252
  if (this.h64) return BigInt.asIntN(64, this.h64(input, this.HASH_SEED));
@@ -4786,19 +4787,46 @@ var PGPoolManager = class extends TinyEmitter {
4786
4787
  }
4787
4788
  };
4788
4789
  //#endregion
4790
+ //#region src/fhir-database/pg/pgfhirdbbase.ts
4791
+ var DBSTSFhirDBBase = class {
4792
+ _options;
4793
+ _poolManager;
4794
+ constructor(options) {
4795
+ this._options = options;
4796
+ this._poolManager = options.poolManager;
4797
+ }
4798
+ async withClient(fname, fn) {
4799
+ let client;
4800
+ try {
4801
+ client = await this._poolManager.connectReadWrite();
4802
+ } catch (error) {
4803
+ this._options.logger.error(`${fname}(): DB: Connection Error: [${error}]`);
4804
+ throw error;
4805
+ }
4806
+ try {
4807
+ return await fn(client);
4808
+ } catch (error) {
4809
+ this._options.logger.error(`${fname}(): DB: Query Error: [${error}]`);
4810
+ throw error;
4811
+ } finally {
4812
+ client.release();
4813
+ }
4814
+ }
4815
+ };
4816
+ //#endregion
4789
4817
  //#region src/fhir-database/pg/pgfhirresource.ts
4790
- var DBSTSResource = class {
4791
- #poolManager;
4792
- constructor(poolManager) {
4793
- this.#poolManager = poolManager;
4818
+ var DBSTSResource = class extends DBSTSFhirDBBase {
4819
+ constructor(options) {
4820
+ super(options);
4794
4821
  }
4795
4822
  async InsertResourceEx(client, data) {
4796
4823
  try {
4797
- await client.query(`
4824
+ return (await client.query(`
4798
4825
  INSERT INTO stsresfhir (
4799
4826
  PID, PARTITION_ID, PARTITION_DATE, RES_ID, RES_TYPE,
4800
4827
  RES_VER, RES_VERSION, RES_PUBLISHED, RES_UPDATED
4801
4828
  ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
4829
+ RETURNING RES_VER
4802
4830
  `, [
4803
4831
  data.PID,
4804
4832
  data.PARTITION_ID,
@@ -4809,146 +4837,90 @@ var DBSTSResource = class {
4809
4837
  data.RES_VERSION,
4810
4838
  BigInt(data.RES_PUBLISHED),
4811
4839
  BigInt(data.RES_UPDATED)
4812
- ]);
4840
+ ])).rows[0]?.res_ver;
4813
4841
  } catch (error) {
4814
- defaultLogger.error(`DBSTSResource:InsertResource(): Query Error: [${error}]`);
4842
+ this._options.logger.error(`DBSTSResource:InsertResource(): Query Error: [${error}]`);
4815
4843
  throw error;
4816
4844
  }
4817
4845
  }
4818
4846
  async InsertResource(data) {
4819
- try {
4820
- const client = await this.#poolManager.connectReadWrite();
4821
- try {
4822
- await this.InsertResourceEx(client, data);
4823
- } catch (error) {
4824
- defaultLogger.error(`DBSTSResource:InsertResource(): Query Error: [${error}]`);
4825
- } finally {
4826
- client.release();
4827
- }
4828
- } catch (error) {
4829
- defaultLogger.error(`DBSTSResource:InsertResource(): Connection Error: [${error}]`);
4830
- }
4847
+ return this.withClient("InsertResource", ((client) => this.InsertResourceEx(client, data)));
4831
4848
  }
4832
4849
  async UpdateResourceRecordEx(client, data) {
4833
4850
  try {
4834
- const res = await client.query(`
4851
+ return (await client.query(`
4835
4852
  UPDATE stsresfhir SET
4836
4853
  RES_VER = RES_VER + 1,
4837
4854
  RES_UPDATED = $1,
4838
4855
  RES_DELETED_AT = NULL
4839
4856
  WHERE RES_ID = $2 AND RES_TYPE = $3 AND RES_VER = $4
4857
+ RETURNING RES_VER
4840
4858
  `, [
4841
4859
  BigInt(data.RES_UPDATED),
4842
4860
  data.RES_ID,
4843
4861
  data.RES_TYPE,
4844
4862
  data.RES_VER
4845
- ]);
4846
- return res.rowCount ? res.rowCount > 0 : false;
4863
+ ])).rows[0]?.res_ver;
4847
4864
  } catch (error) {
4848
- defaultLogger.error(`DBSTSResource:UpdateResourceRecordEx(): Query Error: [${error}]`);
4865
+ this._options.logger.error(`DBSTSResource:UpdateResourceRecordEx(): Query Error: [${error}]`);
4849
4866
  throw error;
4850
4867
  }
4851
4868
  }
4852
4869
  async UpdateResourceRecord(data) {
4853
- try {
4854
- const client = await this.#poolManager.connectReadWrite();
4855
- try {
4856
- return await this.UpdateResourceRecordEx(client, data);
4857
- } catch (error) {
4858
- defaultLogger.error(`DBSTSResource:UpdateResourceRecord-1(): Query Error: [${error}]`);
4859
- } finally {
4860
- client.release();
4861
- }
4862
- } catch (error) {
4863
- defaultLogger.error(`DBSTSResource:UpdateResourceRecord-2(): Connection Error: [${error}]`);
4864
- }
4870
+ return this.withClient("UpdateResourceRecord", ((client) => this.UpdateResourceRecordEx(client, data)));
4865
4871
  }
4866
4872
  async DeleteResourceRecordEx(client, data) {
4867
4873
  try {
4868
- const res = await client.query(`
4874
+ return (await client.query(`
4869
4875
  UPDATE stsresfhir SET
4870
4876
  RES_DELETED_AT = $1,
4871
4877
  RES_VER = RES_VER + 1,
4872
4878
  RES_UPDATED = $2
4873
4879
  WHERE RES_ID = $3 AND RES_TYPE = $4 AND RES_VER = $5
4880
+ RETURNING RES_VER
4874
4881
  `, [
4875
4882
  BigInt(data.RES_DELETED_AT),
4876
4883
  BigInt(data.RES_UPDATED),
4877
4884
  data.RES_ID,
4878
4885
  data.RES_TYPE,
4879
4886
  data.RES_VER
4880
- ]);
4881
- return res.rowCount ? res.rowCount > 0 : false;
4887
+ ])).rows[0]?.res_ver;
4882
4888
  } catch (error) {
4883
- defaultLogger.error(`DBSTSResource:DeleteResourceRecord(): Query Error: [${error}]`);
4889
+ this._options.logger.error(`DBSTSResource:DeleteResourceRecord(): Query Error: [${error}]`);
4884
4890
  throw error;
4885
4891
  }
4886
4892
  }
4887
4893
  async DeleteResourceRecord(data) {
4888
- try {
4889
- const client = await this.#poolManager.connectReadWrite();
4890
- try {
4891
- return await this.DeleteResourceRecordEx(client, data);
4892
- } catch (error) {
4893
- defaultLogger.error(`DBSTSResource:DeleteResourceRecord(): Query Error: [${error}]`);
4894
- } finally {
4895
- client.release();
4896
- }
4897
- } catch (error) {
4898
- defaultLogger.error(`DBSTSResource:DeleteResourceRecord(): Connection Error: [${error}]`);
4899
- }
4894
+ return this.withClient("DeleteResourceRecord", ((client) => this.DeleteResourceRecordEx(client, data)));
4900
4895
  }
4901
4896
  async ReadResourceRecordEx(client, PID) {
4902
4897
  try {
4903
4898
  return (await client.query(`SELECT * FROM stsresfhir WHERE PID = $1`, [PID])).rows[0];
4904
4899
  } catch (error) {
4905
- defaultLogger.error(`DBSTSResource:ReadResourceRecord(): Query Error: [${error}]`);
4900
+ this._options.logger.error(`DBSTSResource:ReadResourceRecord(): Query Error: [${error}]`);
4906
4901
  throw error;
4907
4902
  }
4908
4903
  }
4909
4904
  async ReadResourceRecord(PID) {
4910
- try {
4911
- const client = await this.#poolManager.connectReadOnly();
4912
- try {
4913
- return await this.ReadResourceRecordEx(client, PID);
4914
- } catch (error) {
4915
- defaultLogger.error(`DBSTSResource:ReadResourceRecord(): Query Error: [${error}]`);
4916
- } finally {
4917
- client.release();
4918
- }
4919
- } catch (error) {
4920
- defaultLogger.error(`DBSTSResource:ReadResourceRecord(): Connection Error: [${error}]`);
4921
- }
4905
+ return this.withClient("ReadResourceRecord", ((client) => this.ReadResourceRecordEx(client, PID)));
4922
4906
  }
4923
4907
  async ReadAllResourceRecordsEx(client) {
4924
4908
  try {
4925
4909
  return (await client.query(`SELECT * FROM stsresfhir`)).rows;
4926
4910
  } catch (error) {
4927
- defaultLogger.error(`DBSTSResource:ReadAllResourceRecords(): Query Error: [${error}]`);
4911
+ this._options.logger.error(`DBSTSResource:ReadAllResourceRecords(): Query Error: [${error}]`);
4928
4912
  throw error;
4929
4913
  }
4930
4914
  }
4931
4915
  async ReadAllResourceRecords() {
4932
- try {
4933
- const client = await this.#poolManager.connectReadOnly();
4934
- try {
4935
- return await this.ReadAllResourceRecordsEx(client);
4936
- } catch (error) {
4937
- defaultLogger.error(`DBSTSResource:ReadAllResourceRecords(): Query Error: [${error}]`);
4938
- } finally {
4939
- client.release();
4940
- }
4941
- } catch (error) {
4942
- defaultLogger.error(`DBSTSResource:ReadAllResourceRecords(): Connection Error: [${error}]`);
4943
- }
4916
+ return this.withClient("ReadAllResourceRecords", ((client) => this.ReadAllResourceRecordsEx(client)));
4944
4917
  }
4945
4918
  };
4946
4919
  //#endregion
4947
4920
  //#region src/fhir-database/pg/pgfhirresourceversion.ts
4948
- var DBSTSResourceVersion = class {
4949
- #poolManager;
4950
- constructor(poolManager) {
4951
- this.#poolManager = poolManager;
4921
+ var DBSTSResourceVersion = class extends DBSTSFhirDBBase {
4922
+ constructor(options) {
4923
+ super(options);
4952
4924
  }
4953
4925
  async InsertResourceVersionEx(client, data) {
4954
4926
  const values = [
@@ -4962,86 +4934,67 @@ var DBSTSResourceVersion = class {
4962
4934
  data.RES
4963
4935
  ];
4964
4936
  try {
4965
- await client.query(`
4937
+ return (await client.query(`
4966
4938
  INSERT INTO stsresfhirver (
4967
4939
  PID, PARTITION_ID, PARTITION_DATE,
4968
4940
  RES_ID, RES_TYPE, RES_VER, OPERATION, RES
4969
4941
  ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
4970
- `, values);
4942
+ RETURNING RES_VER
4943
+ `, values)).rows[0]?.res_ver;
4971
4944
  } catch (error) {
4972
- defaultLogger.error(`DBSTSResourceVersion:InsertResourceVersion(): Query Error: [${error}]`);
4973
- defaultLogger.error(`DBSTSResourceVersion:InsertResourceVersion(): --> Values PID: [${values[0]}]`);
4974
- defaultLogger.error(`DBSTSResourceVersion:InsertResourceVersion(): --> Values PARTITION_ID: [${values[1]}]`);
4975
- defaultLogger.error(`DBSTSResourceVersion:InsertResourceVersion(): --> Values PARTITION_DATE: [${values[2]}]`);
4976
- defaultLogger.error(`DBSTSResourceVersion:InsertResourceVersion(): --> Values RES_ID: [${values[3]}]`);
4977
- defaultLogger.error(`DBSTSResourceVersion:InsertResourceVersion(): --> Values RES_TYPE: [${values[4]}]`);
4978
- defaultLogger.error(`DBSTSResourceVersion:InsertResourceVersion(): --> Values RES_VER: [${values[5]}]`);
4979
- defaultLogger.error(`DBSTSResourceVersion:InsertResourceVersion(): --> Values OPERATION: [${values[6]}]`);
4945
+ this._options.logger.error(`DBSTSResourceVersion:InsertResourceVersion(): Query Error: [${error}]`);
4946
+ this._options.logger.error(`DBSTSResourceVersion:InsertResourceVersion(): --> Values PID: [${values[0]}]`);
4947
+ this._options.logger.error(`DBSTSResourceVersion:InsertResourceVersion(): --> Values PARTITION_ID: [${values[1]}]`);
4948
+ this._options.logger.error(`DBSTSResourceVersion:InsertResourceVersion(): --> Values PARTITION_DATE: [${values[2]}]`);
4949
+ this._options.logger.error(`DBSTSResourceVersion:InsertResourceVersion(): --> Values RES_ID: [${values[3]}]`);
4950
+ this._options.logger.error(`DBSTSResourceVersion:InsertResourceVersion(): --> Values RES_TYPE: [${values[4]}]`);
4951
+ this._options.logger.error(`DBSTSResourceVersion:InsertResourceVersion(): --> Values RES_VER: [${values[5]}]`);
4952
+ this._options.logger.error(`DBSTSResourceVersion:InsertResourceVersion(): --> Values OPERATION: [${values[6]}]`);
4980
4953
  throw error;
4981
4954
  }
4982
4955
  }
4983
4956
  async InsertResourceVersion(data) {
4984
- try {
4985
- const client = await this.#poolManager.connectReadWrite();
4986
- try {
4987
- await this.InsertResourceVersionEx(client, data);
4988
- } catch (error) {
4989
- defaultLogger.error(`DBSTSResourceVersion:InsertResourceVersion(): Query Error: [${error}]`);
4990
- } finally {
4991
- client.release();
4992
- }
4993
- } catch (error) {
4994
- defaultLogger.error(`DBSTSResourceVersion:InsertResourceVersion(): Connection Error: [${error}]`);
4995
- }
4957
+ return this.withClient("InsertResourceVersion", ((client) => this.InsertResourceVersionEx(client, data)));
4996
4958
  }
4997
4959
  async ReadResourceVersionRecordEx(client, PID, RES_VER) {
4998
4960
  try {
4999
4961
  return (await client.query(`SELECT * FROM stsresfhirver WHERE PID = $1 AND RES_VER = $2`, [PID, RES_VER])).rows[0];
5000
4962
  } catch (error) {
5001
- defaultLogger.error(`DBSTSResourceVersion:ReadResourceVersionRecord(): Query Error: [${error}]`);
4963
+ this._options.logger.error(`DBSTSResourceVersion:ReadResourceVersionRecord(): Query Error: [${error}]`);
5002
4964
  throw error;
5003
4965
  }
5004
4966
  }
5005
4967
  async ReadResourceVersionRecord(PID, RES_VER) {
5006
- try {
5007
- const client = await this.#poolManager.connectReadWrite();
5008
- try {
5009
- return await this.ReadResourceVersionRecordEx(client, PID, RES_VER);
5010
- } catch (error) {
5011
- defaultLogger.error(`DBSTSResourceVersion:ReadResourceVersionRecord(): Query Error: [${error}]`);
5012
- } finally {
5013
- client.release();
5014
- }
5015
- } catch (error) {
5016
- defaultLogger.error(`DBSTSResourceVersion:ReadResourceVersionRecord(): Connection Error: [${error}]`);
5017
- }
4968
+ return this.withClient("ReadResourceVersionRecord", ((client) => this.ReadResourceVersionRecordEx(client, PID, RES_VER)));
5018
4969
  }
5019
4970
  async ReadAllResourceVersionRecordsEx(client) {
5020
4971
  try {
5021
4972
  return (await client.query(`SELECT * FROM stsresfhirver`)).rows;
5022
4973
  } catch (error) {
5023
- defaultLogger.error(`DBSTSResourceVersion:ReadAllResourceVersionRecords(): Query Error: [${error}]`);
4974
+ this._options.logger.error(`DBSTSResourceVersion:ReadAllResourceVersionRecords(): Query Error: [${error}]`);
5024
4975
  throw error;
5025
4976
  }
5026
4977
  }
5027
4978
  async ReadAllResourceVersionRecords() {
5028
- try {
5029
- const client = await this.#poolManager.connectReadWrite();
5030
- try {
5031
- return await this.ReadAllResourceVersionRecordsEx(client);
5032
- } catch (error) {
5033
- defaultLogger.error(`DBSTSResourceVersion:ReadAllResourceVersionRecords(): Query Error: [${error}]`);
5034
- } finally {
5035
- client.release();
5036
- }
5037
- } catch (error) {
5038
- defaultLogger.error(`DBSTSResourceVersion:ReadAllResourceVersionRecords(): Connection Error: [${error}]`);
5039
- }
4979
+ return this.withClient("ReadAllResourceVersionRecords", ((client) => this.ReadAllResourceVersionRecordsEx(client)));
5040
4980
  }
5041
4981
  };
5042
4982
  //#endregion
4983
+ //#region src/fhir-database/pg/pgfhirdbparamtypebase.ts
4984
+ var DBSTSFhirDBParamTypeBase = class {
4985
+ _options;
4986
+ constructor(options) {
4987
+ this._options = options;
4988
+ }
4989
+ replacer = (_, v) => typeof v === "bigint" ? { __bigint__: v.toString() } : v;
4990
+ reviver = (_, v) => v && v.__bigint__ !== void 0 ? BigInt(v.__bigint__) : v;
4991
+ };
4992
+ //#endregion
5043
4993
  //#region src/fhir-database/pg/pgfhirresourcelink.ts
5044
- var DBSTSResourceLink = class {
4994
+ var DBSTSResourceLink = class extends DBSTSFhirDBParamTypeBase {
4995
+ constructor(options) {
4996
+ super(options);
4997
+ }
5045
4998
  async InsertResourceLink(client, data) {
5046
4999
  try {
5047
5000
  await client.query(`
@@ -5089,327 +5042,852 @@ var DBSTSResourceLink = class {
5089
5042
  data.COMPOSITE_HASH_EXACT ? BigInt(data.COMPOSITE_HASH_EXACT) : null
5090
5043
  ]);
5091
5044
  } catch (error) {
5092
- defaultLogger.error(`DBSTSResourceLink:InsertResourceLink(): Query Error: [${error}]`);
5093
- throw error;
5045
+ const message = `DBSTSResourceLink:InsertResourceLink(): Query Error: [${error}]`;
5046
+ this._options.logger.error(message);
5047
+ throw new Error(message);
5094
5048
  }
5095
5049
  }
5096
5050
  async ReadResourceLinkByResourceIdRecord(client, RES_ID, RES_TYPE) {
5097
5051
  try {
5098
5052
  return (await client.query(`SELECT * FROM stsresfhirlink WHERE RES_ID = $1 AND RES_TYPE = $2`, [RES_ID, RES_TYPE])).rows;
5099
5053
  } catch (error) {
5100
- defaultLogger.error(`DBSTSResourceLink:ReadResourceLinkByResourceIdRecord(): Query Error: [${error}]`);
5101
- throw error;
5054
+ const message = `DBSTSResourceLink:ReadResourceLinkByResourceIdRecord(): Query Error: [${error}]`;
5055
+ this._options.logger.error(message);
5056
+ throw new Error(message);
5102
5057
  }
5103
5058
  }
5104
5059
  async ReadResourceLinkByPIDRecord(client, PID) {
5105
5060
  try {
5106
5061
  return (await client.query(`SELECT * FROM stsresfhirlink WHERE PID = $1 LIMIT 1`, [PID])).rows[0];
5107
5062
  } catch (error) {
5108
- defaultLogger.error(`DBSTSResourceLink:ReadResourceLinkByPIDRecord(): Query Error: [${error}]`);
5109
- throw error;
5063
+ const message = `DBSTSResourceLink:ReadResourceLinkByPIDRecord(): Query Error: [${error}]`;
5064
+ this._options.logger.error(message);
5065
+ throw new Error(message);
5110
5066
  }
5111
5067
  }
5112
5068
  async ReadAllResourceLinkRecords(client) {
5113
5069
  try {
5114
5070
  return (await client.query(`SELECT * FROM stsresfhirlink`)).rows;
5115
5071
  } catch (error) {
5116
- defaultLogger.error(`DBSTSResourceLink:ReadAllResourceLinkRecords(): Query Error: [${error}]`);
5117
- throw error;
5072
+ const message = `DBSTSResourceLink:ReadAllResourceLinkRecords(): Query Error: [${error}]`;
5073
+ this._options.logger.error(message);
5074
+ throw new Error(message);
5118
5075
  }
5119
5076
  }
5120
5077
  async DeleteResourceLinkRecord(client, data) {
5121
5078
  try {
5122
5079
  await client.query(`DELETE FROM stsresfhirlink WHERE RES_ID = $1 AND RES_TYPE = $2`, [data.RES_ID, data.RES_TYPE]);
5123
5080
  } catch (error) {
5124
- defaultLogger.error(`DBSTSResourceLink:DeleteResourceLinkRecord(): Query Error: [${error}]`);
5125
- throw error;
5081
+ const message = `DBSTSResourceLink:DeleteResourceLinkRecord(): Query Error: [${error}]`;
5082
+ this._options.logger.error(message);
5083
+ throw new Error(message);
5126
5084
  }
5127
5085
  }
5128
5086
  };
5129
5087
  //#endregion
5130
5088
  //#region src/fhir-database/pg/pgfhirstring.ts
5131
- var DBSTSString = class {
5089
+ var DBSTSString = class extends DBSTSFhirDBParamTypeBase {
5090
+ constructor(options) {
5091
+ super(options);
5092
+ }
5093
+ async InsertRecord(client, data) {
5094
+ try {
5095
+ await client.query(`
5096
+ INSERT INTO stsresfhirstring (
5097
+ PID,
5098
+ PARTITION_ID,
5099
+ PARTITION_DATE,
5100
+ SP_NAME,
5101
+ SP_PARAM_TYPE,
5102
+ RES_ID,
5103
+ RES_TYPE,
5104
+ SP_MISSING,
5105
+ SP_STR,
5106
+ HASH_IDENTITY,
5107
+ HASH_EXACT,
5108
+ SP_VALUE_NORMALIZED,
5109
+ SP_VALUE_EXACT,
5110
+ UPDATED,
5111
+ PATH_FOR_COMP,
5112
+ COMPOSITE,
5113
+ COMPOSITE_HASH_EXACT
5114
+ ) VALUES (
5115
+ $1, $2, $3,
5116
+ $4, $5, $6, $7,
5117
+ $8, $9, $10,
5118
+ $11, $12, $13, $14,
5119
+ $15, $16, $17
5120
+ )
5121
+ `, [
5122
+ data.PID,
5123
+ data.PARTITION_ID,
5124
+ data.PARTITION_DATE,
5125
+ data.SP_NAME ?? null,
5126
+ data.SP_PARAM_TYPE,
5127
+ data.RES_ID,
5128
+ data.RES_TYPE ?? null,
5129
+ data.SP_MISSING,
5130
+ data.SP_STR,
5131
+ data.HASH_IDENTITY,
5132
+ data.HASH_EXACT,
5133
+ data.SP_VALUE_NORMALIZED,
5134
+ data.SP_VALUE_EXACT,
5135
+ data.UPDATED,
5136
+ data.PATH_FOR_COMP,
5137
+ data.COMPOSITE,
5138
+ data.COMPOSITE_HASH_EXACT ? BigInt(data.COMPOSITE_HASH_EXACT) : null
5139
+ ]);
5140
+ } catch (error) {
5141
+ const message = `DBSTSString:InsertRecord(): Error: [${error}]`;
5142
+ this._options.logger.error(message);
5143
+ throw new Error(message);
5144
+ }
5145
+ }
5146
+ async ReadByPIDRecord(client, PID) {
5147
+ try {
5148
+ return (await client.query(`SELECT * FROM stsresfhirstring WHERE PID = $1 LIMIT 1`, [PID])).rows[0];
5149
+ } catch (error) {
5150
+ const message = `DBSTSString:ReadByPIDRecord(): Error: [${error}]`;
5151
+ this._options.logger.error(message);
5152
+ throw new Error(message);
5153
+ }
5154
+ }
5155
+ async ReadAllRecords(client) {
5156
+ try {
5157
+ return (await client.query(`SELECT * FROM stsresfhirstring`)).rows;
5158
+ } catch (error) {
5159
+ const message = `DBSTSString:ReadAllRecords(): Error: [${error}]`;
5160
+ this._options.logger.error(message);
5161
+ throw new Error(message);
5162
+ }
5163
+ }
5164
+ #FilterResults(data, results) {
5165
+ try {
5166
+ return results.filter((r) => r.SP_NAME === data.SP_NAME && r.RES_TYPE === data.RES_TYPE);
5167
+ } catch (error) {
5168
+ const message = `DBSTSString:#FilterResults(): Error: [${error}]`;
5169
+ this._options.logger.error(message);
5170
+ throw new Error(message);
5171
+ }
5172
+ }
5173
+ async ReadByValueNormalized(client, searchString, parameterName, resourceName) {
5174
+ try {
5175
+ const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5176
+ const norm = normalizeStringParam(searchString);
5177
+ const res = await client.query(`SELECT * FROM stsresfhirstring WHERE HASH_IDENTITY = $1 AND SP_VALUE_NORMALIZED LIKE $2`, [hash, norm]);
5178
+ return this.#FilterResults({
5179
+ SP_NAME: parameterName,
5180
+ RES_TYPE: resourceName
5181
+ }, res.rows);
5182
+ } catch (error) {
5183
+ const message = `DBSTSString:ReadByValueNormalized(): Error: [${error}]`;
5184
+ this._options.logger.error(message);
5185
+ throw new Error(message);
5186
+ }
5187
+ }
5188
+ async ReadByValueExact(client, data) {
5189
+ try {
5190
+ const res = await client.query(`SELECT * FROM stsresfhirstring WHERE HASH_EXACT = $1`, [BigInt(data.HASH_EXACT)]);
5191
+ return this.#FilterResults(data, res.rows);
5192
+ } catch (error) {
5193
+ const message = `DBSTSString:ReadByValueExact(): Error: [${error}]`;
5194
+ this._options.logger.error(message);
5195
+ throw new Error(message);
5196
+ }
5197
+ }
5198
+ async ReadByResID(client, RES_ID, RES_TYPE) {
5199
+ try {
5200
+ return (await client.query(`SELECT * FROM stsresfhirstring WHERE RES_ID = $1 AND RES_TYPE = $2`, [RES_ID, RES_TYPE])).rows;
5201
+ } catch (error) {
5202
+ const message = `DBSTSString:ReadByResID(): Error: [${error}]`;
5203
+ this._options.logger.error(message);
5204
+ throw new Error(message);
5205
+ }
5206
+ }
5207
+ async DeleteRecord(client, data) {
5208
+ try {
5209
+ await client.query(`DELETE FROM stsresfhirstring WHERE RES_ID = $1 AND RES_TYPE = $2`, [data.RES_ID, data.RES_TYPE]);
5210
+ } catch (error) {
5211
+ const message = `DBSTSString:DeleteRecord(): Error: [${error}]`;
5212
+ this._options.logger.error(message);
5213
+ throw new Error(message);
5214
+ }
5215
+ }
5216
+ };
5217
+ //#endregion
5218
+ //#region src/fhir-database/pg/pgfhirtoken.ts
5219
+ var DBSTSToken = class extends DBSTSFhirDBParamTypeBase {
5220
+ constructor(options) {
5221
+ super(options);
5222
+ }
5132
5223
  async InsertRecord(client, data) {
5133
- await client.query(`
5134
- INSERT INTO stsresfhirstring (
5224
+ try {
5225
+ const text = `
5226
+ INSERT INTO stsresfhirtoken (
5135
5227
  PID,
5136
5228
  PARTITION_ID,
5137
- PARTITION_DATE,
5229
+ PARTITION_DATE,
5138
5230
  SP_NAME,
5139
5231
  SP_PARAM_TYPE,
5140
- RES_ID,
5141
- RES_TYPE,
5142
- SP_MISSING,
5143
5232
  SP_STR,
5233
+ RES_ID,
5234
+ RES_TYPE,
5235
+ UPDATED,
5236
+ SP_MISSING,
5144
5237
  HASH_IDENTITY,
5145
- HASH_EXACT,
5146
- SP_VALUE_NORMALIZED,
5147
- SP_VALUE_EXACT,
5148
- UPDATED,
5238
+ SP_SYSTEM,
5239
+ SP_TOKEN_TYPE,
5240
+ SP_VALUE,
5241
+ HASH_VALUE,
5242
+ HASH_SYS,
5243
+ HASH_SYS_AND_VALUE,
5149
5244
  PATH_FOR_COMP,
5150
5245
  COMPOSITE,
5151
5246
  COMPOSITE_HASH_EXACT
5152
5247
  ) VALUES (
5153
- $1, $2, $3,
5154
- $4, $5, $6, $7,
5155
- $8, $9, $10,
5156
- $11, $12, $13, $14,
5157
- $15, $16, $17
5158
- )
5159
- `, [
5160
- data.PID,
5161
- data.PARTITION_ID,
5162
- data.PARTITION_DATE,
5163
- data.SP_NAME ?? null,
5164
- data.SP_PARAM_TYPE,
5165
- data.RES_ID,
5166
- data.RES_TYPE ?? null,
5167
- data.SP_MISSING,
5168
- data.SP_STR,
5169
- data.HASH_IDENTITY,
5170
- data.HASH_EXACT,
5171
- data.SP_VALUE_NORMALIZED,
5172
- data.SP_VALUE_EXACT,
5173
- data.UPDATED,
5174
- data.PATH_FOR_COMP,
5175
- data.COMPOSITE,
5176
- data.COMPOSITE_HASH_EXACT ? BigInt(data.COMPOSITE_HASH_EXACT) : null
5177
- ]);
5248
+ $1, $2, $3, $4, $5, $6,
5249
+ $7, $8, $9, $10, $11, $12,
5250
+ $13, $14, $15, $16, $17,
5251
+ $18, $19, $20
5252
+ )`;
5253
+ const values = [
5254
+ data.PID,
5255
+ data.PARTITION_ID ?? 0,
5256
+ data.PARTITION_DATE ?? 0,
5257
+ data.SP_NAME,
5258
+ data.SP_PARAM_TYPE,
5259
+ data.SP_STR,
5260
+ data.RES_ID,
5261
+ data.RES_TYPE,
5262
+ BigInt(data.UPDATED),
5263
+ data.SP_MISSING,
5264
+ BigInt(data.HASH_IDENTITY),
5265
+ data.SP_SYSTEM,
5266
+ data.SP_TOKEN_TYPE,
5267
+ data.SP_VALUE,
5268
+ data.HASH_VALUE,
5269
+ data.HASH_SYS,
5270
+ data.HASH_SYS_AND_VALUE,
5271
+ data.PATH_FOR_COMP,
5272
+ data.COMPOSITE,
5273
+ data.COMPOSITE_HASH_EXACT ? BigInt(data.COMPOSITE_HASH_EXACT) : null
5274
+ ];
5275
+ await client.query(text, values);
5276
+ } catch (error) {
5277
+ const message = `DBSTSToken:InsertRecord(): Error: [${error}]`;
5278
+ this._options.logger.error(message);
5279
+ throw new Error(message);
5280
+ }
5281
+ }
5282
+ async DeleteRecord(client, data) {
5283
+ try {
5284
+ await client.query(`DELETE FROM stsresfhirtoken WHERE RES_ID = $1 AND RES_TYPE = $2`, [data.RES_ID, data.RES_TYPE]);
5285
+ } catch (error) {
5286
+ const message = `DBSTSToken:DeleteRecord(): Error: [${error}]`;
5287
+ this._options.logger.error(message);
5288
+ throw new Error(message);
5289
+ }
5178
5290
  }
5179
5291
  async ReadByPIDRecord(client, PID) {
5180
- return (await client.query(`SELECT * FROM stsresfhirstring WHERE PID = $1 LIMIT 1`, [PID])).rows[0];
5292
+ try {
5293
+ return (await client.query(`SELECT * FROM stsresfhirtoken WHERE PID = $1`, [PID])).rows[0];
5294
+ } catch (error) {
5295
+ const message = `DBSTSToken:ReadByPIDRecord(): Error: [${error}]`;
5296
+ this._options.logger.error(message);
5297
+ throw new Error(message);
5298
+ }
5181
5299
  }
5182
5300
  async ReadAllRecords(client) {
5183
- return (await client.query(`SELECT * FROM stsresfhirstring`)).rows;
5301
+ try {
5302
+ return (await client.query(`SELECT * FROM stsresfhirtoken`)).rows;
5303
+ } catch (error) {
5304
+ const message = `DBSTSToken:ReadAllRecords(): Error: [${error}]`;
5305
+ this._options.logger.error(message);
5306
+ throw new Error(message);
5307
+ }
5184
5308
  }
5185
- #FilterResults(data, results) {
5186
- return results.filter((r) => r.SP_NAME === data.SP_NAME && r.RES_TYPE === data.RES_TYPE);
5309
+ async ReadByIdentity(client, parameterName, resourceName) {
5310
+ try {
5311
+ const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5312
+ const res = await client.query(`SELECT * FROM stsresfhirtoken WHERE HASH_IDENTITY = $1`, [hash]);
5313
+ return this.#filterResults({
5314
+ SP_NAME: parameterName,
5315
+ RES_TYPE: resourceName
5316
+ }, res.rows);
5317
+ } catch (error) {
5318
+ const message = `DBSTSToken:ReadByIdentity(): Error: [${error}]`;
5319
+ this._options.logger.error(message);
5320
+ throw new Error(message);
5321
+ }
5187
5322
  }
5188
- async ReadByValueNormalized(client, searchString, parameterName, resourceName) {
5189
- const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5190
- const norm = normalizeStringParam(searchString);
5191
- const res = await client.query(`SELECT * FROM stsresfhirstring WHERE HASH_IDENTITY = $1 AND SP_VALUE_NORMALIZED LIKE $2`, [hash, norm]);
5192
- return this.#FilterResults({
5193
- SP_NAME: parameterName,
5194
- RES_TYPE: resourceName
5195
- }, res.rows);
5323
+ async ReadByValue(client, searchValue, parameterName, resourceName) {
5324
+ try {
5325
+ const hash = hashStringParam(`${parameterName}|${resourceName}|${searchValue}`, true);
5326
+ const res = await client.query(`SELECT * FROM stsresfhirtoken WHERE HASH_VALUE = $1`, [hash]);
5327
+ return this.#filterResults({
5328
+ SP_NAME: parameterName,
5329
+ RES_TYPE: resourceName
5330
+ }, res.rows);
5331
+ } catch (error) {
5332
+ const message = `DBSTSToken:ReadByValue(): Error: [${error}]`;
5333
+ this._options.logger.error(message);
5334
+ throw new Error(message);
5335
+ }
5196
5336
  }
5197
- async ReadByValueExact(client, data) {
5198
- const res = await client.query(`SELECT * FROM stsresfhirstring WHERE HASH_EXACT = $1`, [BigInt(data.HASH_EXACT)]);
5199
- return this.#FilterResults(data, res.rows);
5337
+ async ReadBySystem(client, searchSystem, parameterName, resourceName) {
5338
+ try {
5339
+ const hash = hashStringParam(`${parameterName}|${resourceName}|${searchSystem}`, true);
5340
+ const res = await client.query(`SELECT * FROM stsresfhirtoken WHERE HASH_SYS = $1`, [hash]);
5341
+ return this.#filterResults({
5342
+ SP_NAME: parameterName,
5343
+ RES_TYPE: resourceName
5344
+ }, res.rows);
5345
+ } catch (error) {
5346
+ const message = `DBSTSToken:ReadBySystem(): Error: [${error}]`;
5347
+ this._options.logger.error(message);
5348
+ throw new Error(message);
5349
+ }
5350
+ }
5351
+ async ReadBySystemAndValue(client, searchSystem, searchValue, parameterName, resourceName) {
5352
+ try {
5353
+ const hash = hashStringParam(`${parameterName}|${resourceName}|${searchSystem}|${searchValue}`, true);
5354
+ const res = await client.query(`SELECT * FROM stsresfhirtoken WHERE HASH_SYS_AND_VALUE = $1`, [hash]);
5355
+ return this.#filterResults({
5356
+ SP_NAME: parameterName,
5357
+ RES_TYPE: resourceName
5358
+ }, res.rows);
5359
+ } catch (error) {
5360
+ const message = `DBSTSToken:ReadBySystemAndValue(): Error: [${error}]`;
5361
+ this._options.logger.error(message);
5362
+ throw new Error(message);
5363
+ }
5200
5364
  }
5201
5365
  async ReadByResID(client, RES_ID, RES_TYPE) {
5202
- return (await client.query(`SELECT * FROM stsresfhirstring WHERE RES_ID = $1 AND RES_TYPE = $2`, [RES_ID, RES_TYPE])).rows;
5366
+ try {
5367
+ return (await client.query(`SELECT * FROM stsresfhirtoken WHERE RES_ID = $1 AND RES_TYPE = $2`, [RES_ID, RES_TYPE])).rows;
5368
+ } catch (error) {
5369
+ const message = `DBSTSToken:ReadByResID(): Error: [${error}]`;
5370
+ this._options.logger.error(message);
5371
+ throw new Error(message);
5372
+ }
5203
5373
  }
5204
- async DeleteRecord(client, data) {
5205
- await client.query(`DELETE FROM stsresfhirstring WHERE RES_ID = $1 AND RES_TYPE = $2`, [data.RES_ID, data.RES_TYPE]);
5374
+ #filterResults(data, results) {
5375
+ try {
5376
+ return results.filter((r) => r.SP_NAME === data.SP_NAME && r.RES_TYPE === data.RES_TYPE);
5377
+ } catch (error) {
5378
+ const message = `DBSTSToken:#filterResults(): Error: [${error}]`;
5379
+ this._options.logger.error(message);
5380
+ throw new Error(message);
5381
+ }
5206
5382
  }
5207
5383
  };
5208
5384
  //#endregion
5209
- //#region src/fhir-database/pg/pgfhirtoken.ts
5210
- var DBSTSToken = class {
5385
+ //#region src/fhir-database/pg/pgfhirquantity.ts
5386
+ var DBSTSQuantity = class extends DBSTSFhirDBParamTypeBase {
5387
+ constructor(options) {
5388
+ super(options);
5389
+ }
5211
5390
  async InsertRecord(client, data) {
5212
- const text = `
5213
- INSERT INTO stsresfhirtoken (
5214
- PID,
5215
- PARTITION_ID,
5216
- PARTITION_DATE,
5217
- SP_NAME,
5218
- SP_PARAM_TYPE,
5219
- SP_STR,
5220
- RES_ID,
5221
- RES_TYPE,
5222
- UPDATED,
5223
- SP_MISSING,
5224
- HASH_IDENTITY,
5225
- SP_SYSTEM,
5226
- SP_TOKEN_TYPE,
5227
- SP_VALUE,
5228
- HASH_VALUE,
5229
- HASH_SYS,
5230
- HASH_SYS_AND_VALUE,
5231
- PATH_FOR_COMP,
5232
- COMPOSITE,
5233
- COMPOSITE_HASH_EXACT
5234
- ) VALUES (
5235
- $1, $2, $3, $4, $5, $6,
5236
- $7, $8, $9, $10, $11, $12,
5237
- $13, $14, $15, $16, $17,
5238
- $18, $19, $20
5239
- )`;
5240
- const values = [
5241
- data.PID,
5242
- data.PARTITION_ID ?? 0,
5243
- data.PARTITION_DATE ?? 0,
5244
- data.SP_NAME,
5245
- data.SP_PARAM_TYPE,
5246
- data.SP_STR,
5247
- data.RES_ID,
5248
- data.RES_TYPE,
5249
- BigInt(data.UPDATED),
5250
- data.SP_MISSING,
5251
- BigInt(data.HASH_IDENTITY),
5252
- data.SP_SYSTEM,
5253
- data.SP_TOKEN_TYPE,
5254
- data.SP_VALUE,
5255
- data.HASH_VALUE,
5256
- data.HASH_SYS,
5257
- data.HASH_SYS_AND_VALUE,
5258
- data.PATH_FOR_COMP,
5259
- data.COMPOSITE,
5260
- data.COMPOSITE_HASH_EXACT ? BigInt(data.COMPOSITE_HASH_EXACT) : null
5261
- ];
5262
- await client.query(text, values);
5391
+ try {
5392
+ const text = `
5393
+ INSERT INTO stsresfhirquantity (
5394
+ PID,
5395
+ PARTITION_ID,
5396
+ PARTITION_DATE,
5397
+ SP_NAME,
5398
+ SP_PARAM_TYPE,
5399
+ SP_STR,
5400
+ RES_ID,
5401
+ RES_TYPE,
5402
+ UPDATED,
5403
+ SP_MISSING,
5404
+ HASH_IDENTITY,
5405
+ SP_SYSTEM,
5406
+ SP_VALUE,
5407
+ SP_UNITS,
5408
+ HASH_IDENTITY_AND_UNITS,
5409
+ HASH_IDENTITY_SYS_UNITS,
5410
+ PATH_FOR_COMP,
5411
+ COMPOSITE,
5412
+ COMPOSITE_HASH_EXACT
5413
+ ) VALUES (
5414
+ $1, $2, $3, $4, $5, $6,
5415
+ $7, $8, $9, $10, $11, $12,
5416
+ $13, $14, $15, $16,
5417
+ $17, $18, $19
5418
+ )`;
5419
+ const values = [
5420
+ data.PID,
5421
+ data.PARTITION_ID,
5422
+ data.PARTITION_DATE,
5423
+ data.SP_NAME,
5424
+ data.SP_PARAM_TYPE,
5425
+ data.SP_STR,
5426
+ data.RES_ID,
5427
+ data.RES_TYPE,
5428
+ BigInt(data.UPDATED),
5429
+ data.SP_MISSING,
5430
+ BigInt(data.HASH_IDENTITY),
5431
+ data.SP_SYSTEM,
5432
+ data.SP_VALUE,
5433
+ data.SP_UNITS,
5434
+ data.HASH_IDENTITY_AND_UNITS,
5435
+ data.HASH_IDENTITY_SYS_UNITS,
5436
+ data.PATH_FOR_COMP,
5437
+ data.COMPOSITE,
5438
+ data.COMPOSITE_HASH_EXACT ? BigInt(data.COMPOSITE_HASH_EXACT) : null
5439
+ ];
5440
+ await client.query(text, values);
5441
+ } catch (error) {
5442
+ const message = `DBSTSQuantity:InsertRecord(): Error: [${error}]`;
5443
+ this._options.logger.error(message);
5444
+ throw new Error(message);
5445
+ }
5263
5446
  }
5264
5447
  async DeleteRecord(client, data) {
5265
- await client.query(`DELETE FROM stsresfhirtoken WHERE RES_ID = $1 AND RES_TYPE = $2`, [data.RES_ID, data.RES_TYPE]);
5448
+ try {
5449
+ await client.query(`DELETE FROM stsresfhirquantity WHERE RES_ID = $1 AND RES_TYPE = $2`, [data.RES_ID, data.RES_TYPE]);
5450
+ } catch (error) {
5451
+ const message = `DBSTSQuantity:DeleteRecord(): Error: [${error}]`;
5452
+ this._options.logger.error(message);
5453
+ throw new Error(message);
5454
+ }
5266
5455
  }
5267
5456
  async ReadByPIDRecord(client, PID) {
5268
- return (await client.query(`SELECT * FROM stsresfhirtoken WHERE PID = $1`, [PID])).rows[0];
5457
+ try {
5458
+ return (await client.query(`SELECT * FROM stsresfhirquantity WHERE PID = $1`, [PID])).rows[0];
5459
+ } catch (error) {
5460
+ const message = `DBSTSQuantity:ReadByPIDRecord(): Error: [${error}]`;
5461
+ this._options.logger.error(message);
5462
+ throw new Error(message);
5463
+ }
5269
5464
  }
5270
5465
  async ReadAllRecords(client) {
5271
- return (await client.query(`SELECT * FROM stsresfhirtoken`)).rows;
5466
+ try {
5467
+ return (await client.query(`SELECT * FROM stsresfhirquantity`)).rows;
5468
+ } catch (error) {
5469
+ const message = `DBSTSQuantity:ReadAllRecords(): Error: [${error}]`;
5470
+ this._options.logger.error(message);
5471
+ throw new Error(message);
5472
+ }
5272
5473
  }
5273
5474
  async ReadByIdentity(client, parameterName, resourceName) {
5274
- const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5275
- const res = await client.query(`SELECT * FROM stsresfhirtoken WHERE HASH_IDENTITY = $1`, [hash]);
5276
- return this.#filterResults({
5277
- SP_NAME: parameterName,
5278
- RES_TYPE: resourceName
5279
- }, res.rows);
5475
+ try {
5476
+ const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5477
+ const res = await client.query(`SELECT * FROM stsresfhirquantity WHERE HASH_IDENTITY = $1`, [hash]);
5478
+ return this.#filterResults({
5479
+ SP_NAME: parameterName,
5480
+ RES_TYPE: resourceName
5481
+ }, res.rows);
5482
+ } catch (error) {
5483
+ const message = `DBSTSQuantity:ReadByIdentity(): Error: [${error}]`;
5484
+ this._options.logger.error(message);
5485
+ throw new Error(message);
5486
+ }
5280
5487
  }
5281
- async ReadByValue(client, searchValue, parameterName, resourceName) {
5282
- const hash = hashStringParam(`${parameterName}|${resourceName}|${searchValue}`, true);
5283
- const res = await client.query(`SELECT * FROM stsresfhirtoken WHERE HASH_VALUE = $1`, [hash]);
5284
- return this.#filterResults({
5285
- SP_NAME: parameterName,
5286
- RES_TYPE: resourceName
5287
- }, res.rows);
5488
+ async ReadByUnits(client, units, searchValue, parameterName, resourceName) {
5489
+ try {
5490
+ const hash = hashStringParam(`${parameterName}|${resourceName}|${units}`, true);
5491
+ const res = await client.query(`SELECT * FROM stsresfhirquantity WHERE HASH_IDENTITY_AND_UNITS = $1 AND SP_VALUE = $2`, [hash, searchValue]);
5492
+ return this.#filterResults({
5493
+ SP_NAME: parameterName,
5494
+ RES_TYPE: resourceName
5495
+ }, res.rows);
5496
+ } catch (error) {
5497
+ const message = `DBSTSQuantity:ReadByUnits(): Error: [${error}]`;
5498
+ this._options.logger.error(message);
5499
+ throw new Error(message);
5500
+ }
5288
5501
  }
5289
- async ReadBySystem(client, searchSystem, parameterName, resourceName) {
5290
- const hash = hashStringParam(`${parameterName}|${resourceName}|${searchSystem}`, true);
5291
- const res = await client.query(`SELECT * FROM stsresfhirtoken WHERE HASH_SYS = $1`, [hash]);
5292
- return this.#filterResults({
5293
- SP_NAME: parameterName,
5294
- RES_TYPE: resourceName
5295
- }, res.rows);
5502
+ async ReadBySystemAndUnits(client, searchSystem, units, searchValue, parameterName, resourceName) {
5503
+ try {
5504
+ const hash = hashStringParam(`${parameterName}|${resourceName}|${searchSystem}|${units}`, true);
5505
+ const res = await client.query(`SELECT * FROM stsresfhirquantity WHERE HASH_IDENTITY_SYS_UNITS = $1 AND SP_VALUE = $2`, [hash, searchValue]);
5506
+ return this.#filterResults({
5507
+ SP_NAME: parameterName,
5508
+ RES_TYPE: resourceName
5509
+ }, res.rows);
5510
+ } catch (error) {
5511
+ const message = `DBSTSQuantity:ReadBySystemAndUnits(): Error: [${error}]`;
5512
+ this._options.logger.error(message);
5513
+ throw new Error(message);
5514
+ }
5296
5515
  }
5297
- async ReadBySystemAndValue(client, searchSystem, searchValue, parameterName, resourceName) {
5298
- const hash = hashStringParam(`${parameterName}|${resourceName}|${searchSystem}|${searchValue}`, true);
5299
- const res = await client.query(`SELECT * FROM stsresfhirtoken WHERE HASH_SYS_AND_VALUE = $1`, [hash]);
5300
- return this.#filterResults({
5301
- SP_NAME: parameterName,
5302
- RES_TYPE: resourceName
5303
- }, res.rows);
5516
+ async ReadByResID(client, RES_ID, RES_TYPE) {
5517
+ try {
5518
+ return (await client.query(`SELECT * FROM stsresfhirquantity WHERE RES_ID = $1 AND RES_TYPE = $2`, [RES_ID, RES_TYPE])).rows;
5519
+ } catch (error) {
5520
+ const message = `DBSTSQuantity:ReadByResID(): Error: [${error}]`;
5521
+ this._options.logger.error(message);
5522
+ throw new Error(message);
5523
+ }
5524
+ }
5525
+ #filterResults(data, results) {
5526
+ try {
5527
+ return results.filter((r) => r.SP_NAME === data.SP_NAME && r.RES_TYPE === data.RES_TYPE);
5528
+ } catch (error) {
5529
+ const message = `DBSTSQuantity:#filterResults(): Error: [${error}]`;
5530
+ this._options.logger.error(message);
5531
+ throw new Error(message);
5532
+ }
5533
+ }
5534
+ };
5535
+ //#endregion
5536
+ //#region src/fhir-database/pg/pgfhirnumber.ts
5537
+ var DBSTSNumber = class extends DBSTSFhirDBParamTypeBase {
5538
+ constructor(options) {
5539
+ super(options);
5540
+ }
5541
+ async InsertRecord(client, data) {
5542
+ try {
5543
+ const text = `
5544
+ INSERT INTO stsresfhirnumber (
5545
+ PID,
5546
+ PARTITION_ID,
5547
+ PARTITION_DATE,
5548
+ SP_NAME,
5549
+ SP_PARAM_TYPE,
5550
+ SP_STR,
5551
+ RES_ID,
5552
+ RES_TYPE,
5553
+ UPDATED,
5554
+ SP_MISSING,
5555
+ HASH_IDENTITY,
5556
+ SP_VALUE,
5557
+ PATH_FOR_COMP,
5558
+ COMPOSITE,
5559
+ COMPOSITE_HASH_EXACT
5560
+ ) VALUES (
5561
+ $1, $2, $3, $4, $5, $6,
5562
+ $7, $8, $9, $10, $11, $12,
5563
+ $13, $14, $15
5564
+ )`;
5565
+ const values = [
5566
+ data.PID,
5567
+ data.PARTITION_ID ?? 0,
5568
+ data.PARTITION_DATE ?? 0,
5569
+ data.SP_NAME,
5570
+ data.SP_PARAM_TYPE,
5571
+ data.SP_STR,
5572
+ data.RES_ID,
5573
+ data.RES_TYPE,
5574
+ BigInt(data.UPDATED),
5575
+ data.SP_MISSING,
5576
+ BigInt(data.HASH_IDENTITY),
5577
+ data.SP_VALUE ?? 0,
5578
+ data.PATH_FOR_COMP,
5579
+ data.COMPOSITE,
5580
+ data.COMPOSITE_HASH_EXACT ? BigInt(data.COMPOSITE_HASH_EXACT) : null
5581
+ ];
5582
+ await client.query(text, values);
5583
+ } catch (error) {
5584
+ const message = `DBSTSNumber:InsertRecord(): Error: [${error}]`;
5585
+ this._options.logger.error(message);
5586
+ throw new Error(message);
5587
+ }
5588
+ }
5589
+ async DeleteRecord(client, data) {
5590
+ try {
5591
+ await client.query(`DELETE FROM stsresfhirnumber WHERE RES_ID = $1 AND RES_TYPE = $2`, [data.RES_ID, data.RES_TYPE]);
5592
+ } catch (error) {
5593
+ const message = `DBSTSNumber:DeleteRecord(): Error: [${error}]`;
5594
+ this._options.logger.error(message);
5595
+ throw new Error(message);
5596
+ }
5597
+ }
5598
+ async ReadByPIDRecord(client, PID) {
5599
+ try {
5600
+ return (await client.query(`SELECT * FROM stsresfhirnumber WHERE PID = $1`, [PID])).rows[0];
5601
+ } catch (error) {
5602
+ const message = `DBSTSNumber:ReadByPIDRecord(): Error: [${error}]`;
5603
+ this._options.logger.error(message);
5604
+ throw new Error(message);
5605
+ }
5606
+ }
5607
+ async ReadAllRecords(client) {
5608
+ try {
5609
+ return (await client.query(`SELECT * FROM stsresfhirnumber`)).rows;
5610
+ } catch (error) {
5611
+ const message = `DBSTSNumber:ReadAllRecords(): Error: [${error}]`;
5612
+ this._options.logger.error(message);
5613
+ throw new Error(message);
5614
+ }
5615
+ }
5616
+ async ReadByIdentity(client, parameterName, resourceName) {
5617
+ try {
5618
+ const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5619
+ const res = await client.query(`SELECT * FROM stsresfhirnumber WHERE HASH_IDENTITY = $1`, [hash]);
5620
+ return this.#filterResults({
5621
+ SP_NAME: parameterName,
5622
+ RES_TYPE: resourceName
5623
+ }, res.rows);
5624
+ } catch (error) {
5625
+ const message = `DBSTSNumber:ReadByIdentity(): Error: [${error}]`;
5626
+ this._options.logger.error(message);
5627
+ throw new Error(message);
5628
+ }
5629
+ }
5630
+ async ReadByValue(client, searchValue, parameterName, resourceName) {
5631
+ try {
5632
+ const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5633
+ const res = await client.query(`SELECT * FROM stsresfhirnumber WHERE HASH_IDENTITY = $1 AND SP_VALUE = $2`, [hash, searchValue]);
5634
+ return this.#filterResults({
5635
+ SP_NAME: parameterName,
5636
+ RES_TYPE: resourceName
5637
+ }, res.rows);
5638
+ } catch (error) {
5639
+ const message = `DBSTSNumber:ReadByValue(): Error: [${error}]`;
5640
+ this._options.logger.error(message);
5641
+ throw new Error(message);
5642
+ }
5304
5643
  }
5305
5644
  async ReadByResID(client, RES_ID, RES_TYPE) {
5306
- return (await client.query(`SELECT * FROM stsresfhirtoken WHERE RES_ID = $1 AND RES_TYPE = $2`, [RES_ID, RES_TYPE])).rows;
5645
+ try {
5646
+ return (await client.query(`SELECT * FROM stsresfhirnumber WHERE RES_ID = $1 AND RES_TYPE = $2`, [RES_ID, RES_TYPE])).rows;
5647
+ } catch (error) {
5648
+ const message = `DBSTSNumber:ReadByResID(): Error: [${error}]`;
5649
+ this._options.logger.error(message);
5650
+ throw new Error(message);
5651
+ }
5307
5652
  }
5308
5653
  #filterResults(data, results) {
5309
- return results.filter((r) => r.SP_NAME === data.SP_NAME && r.RES_TYPE === data.RES_TYPE);
5654
+ try {
5655
+ return results.filter((r) => r.SP_NAME === data.SP_NAME && r.RES_TYPE === data.RES_TYPE);
5656
+ } catch (error) {
5657
+ const message = `DBSTSNumber:#filterResults(): Error: [${error}]`;
5658
+ this._options.logger.error(message);
5659
+ throw new Error(message);
5660
+ }
5310
5661
  }
5311
5662
  };
5312
5663
  //#endregion
5313
- //#region src/fhir-database/pg/pgfhirquantity.ts
5314
- var DBSTSQuantity = class {
5664
+ //#region src/fhir-database/pg/pgfhirdate.ts
5665
+ var DBSTSDate = class extends DBSTSFhirDBParamTypeBase {
5666
+ constructor(options) {
5667
+ super(options);
5668
+ }
5315
5669
  async InsertRecord(client, data) {
5316
- const text = `
5317
- INSERT INTO stsresfhirquantity (
5318
- PID,
5319
- PARTITION_ID,
5320
- PARTITION_DATE,
5321
- SP_NAME,
5322
- SP_PARAM_TYPE,
5323
- SP_STR,
5324
- RES_ID,
5325
- RES_TYPE,
5326
- UPDATED,
5327
- SP_MISSING,
5328
- HASH_IDENTITY,
5329
- SP_SYSTEM,
5330
- SP_VALUE,
5331
- SP_UNITS,
5332
- HASH_IDENTITY_AND_UNITS,
5333
- HASH_IDENTITY_SYS_UNITS,
5334
- PATH_FOR_COMP,
5335
- COMPOSITE,
5336
- COMPOSITE_HASH_EXACT
5337
- ) VALUES (
5338
- $1, $2, $3, $4, $5, $6,
5339
- $7, $8, $9, $10, $11, $12,
5340
- $13, $14, $15, $16,
5341
- $17, $18, $19
5342
- )`;
5343
- const values = [
5344
- data.PID,
5345
- data.PARTITION_ID,
5346
- data.PARTITION_DATE,
5347
- data.SP_NAME,
5348
- data.SP_PARAM_TYPE,
5349
- data.SP_STR,
5350
- data.RES_ID,
5351
- data.RES_TYPE,
5352
- BigInt(data.UPDATED),
5353
- data.SP_MISSING,
5354
- BigInt(data.HASH_IDENTITY),
5355
- data.SP_SYSTEM,
5356
- data.SP_VALUE,
5357
- data.SP_UNITS,
5358
- data.HASH_IDENTITY_AND_UNITS,
5359
- data.HASH_IDENTITY_SYS_UNITS,
5360
- data.PATH_FOR_COMP,
5361
- data.COMPOSITE,
5362
- data.COMPOSITE_HASH_EXACT ? BigInt(data.COMPOSITE_HASH_EXACT) : null
5363
- ];
5364
- await client.query(text, values);
5670
+ try {
5671
+ const text = `
5672
+ INSERT INTO stsresfhirdate (
5673
+ PID,
5674
+ PARTITION_ID,
5675
+ PARTITION_DATE,
5676
+ SP_NAME,
5677
+ SP_PARAM_TYPE,
5678
+ SP_STR,
5679
+ RES_ID,
5680
+ RES_TYPE,
5681
+ UPDATED,
5682
+ SP_MISSING,
5683
+ HASH_IDENTITY,
5684
+ SP_VALUE_LOW,
5685
+ SP_VALUE_HIGH,
5686
+ SP_VALUE_LOW_DATE_ORDINAL,
5687
+ SP_VALUE_HIGH_DATE_ORDINAL,
5688
+ PATH_FOR_COMP,
5689
+ COMPOSITE,
5690
+ COMPOSITE_HASH_EXACT
5691
+ ) VALUES (
5692
+ $1, $2, $3, $4, $5, $6,
5693
+ $7, $8, $9, $10, $11, $12,
5694
+ $13, $14, $15,
5695
+ $16, $17, $18
5696
+ )`;
5697
+ const values = [
5698
+ data.PID,
5699
+ data.PARTITION_ID ?? 0,
5700
+ data.PARTITION_DATE ?? 0,
5701
+ data.SP_NAME,
5702
+ data.SP_PARAM_TYPE,
5703
+ data.SP_STR,
5704
+ data.RES_ID,
5705
+ data.RES_TYPE,
5706
+ BigInt(data.UPDATED),
5707
+ data.SP_MISSING,
5708
+ BigInt(data.HASH_IDENTITY),
5709
+ data.SP_VALUE_LOW ? data.SP_VALUE_LOW.toJSDate() : null,
5710
+ data.SP_VALUE_HIGH ? data.SP_VALUE_HIGH.toJSDate() : null,
5711
+ data.SP_VALUE_LOW_DATE_ORDINAL,
5712
+ data.SP_VALUE_HIGH_DATE_ORDINAL,
5713
+ data.PATH_FOR_COMP,
5714
+ data.COMPOSITE,
5715
+ data.COMPOSITE_HASH_EXACT ? BigInt(data.COMPOSITE_HASH_EXACT) : null
5716
+ ];
5717
+ await client.query(text, values);
5718
+ } catch (error) {
5719
+ const message = `DBSTSDate:InsertRecord(): Error: [${error}]`;
5720
+ this._options.logger.error(message);
5721
+ throw new Error(message);
5722
+ }
5365
5723
  }
5366
5724
  async DeleteRecord(client, data) {
5367
- await client.query(`DELETE FROM stsresfhirquantity WHERE RES_ID = $1 AND RES_TYPE = $2`, [data.RES_ID, data.RES_TYPE]);
5725
+ try {
5726
+ await client.query(`DELETE FROM stsresfhirdate WHERE RES_ID = $1 AND RES_TYPE = $2`, [data.RES_ID, data.RES_TYPE]);
5727
+ } catch (error) {
5728
+ const message = `DBSTSDate:DeleteRecord(): Error: [${error}]`;
5729
+ this._options.logger.error(message);
5730
+ throw new Error(message);
5731
+ }
5368
5732
  }
5369
5733
  async ReadByPIDRecord(client, PID) {
5370
- return (await client.query(`SELECT * FROM stsresfhirquantity WHERE PID = $1`, [PID])).rows[0];
5734
+ try {
5735
+ const res = await client.query(`SELECT * FROM stsresfhirdate WHERE PID = $1`, [PID]);
5736
+ if (res.rows && res.rows.length === 1) {
5737
+ if (res.rows[0].sp_value_high !== null) res.rows[0].sp_value_high = DateTime.fromJSDate(res.rows[0].sp_value_high);
5738
+ if (res.rows[0].sp_value_low !== null) res.rows[0].sp_value_low = DateTime.fromJSDate(res.rows[0].sp_value_low);
5739
+ }
5740
+ return res.rows[0];
5741
+ } catch (error) {
5742
+ const message = `DBSTSDate:ReadByPIDRecord(): Error: [${error}]`;
5743
+ this._options.logger.error(message);
5744
+ throw new Error(message);
5745
+ }
5371
5746
  }
5372
5747
  async ReadAllRecords(client) {
5373
- return (await client.query(`SELECT * FROM stsresfhirquantity`)).rows;
5748
+ try {
5749
+ return (await client.query(`SELECT * FROM stsresfhirdate`)).rows;
5750
+ } catch (error) {
5751
+ const message = `DBSTSDate:ReadAllRecords(): Error: [${error}]`;
5752
+ this._options.logger.error(message);
5753
+ throw new Error(message);
5754
+ }
5755
+ }
5756
+ async ReadByIdentity(client, parameterName, resourceName) {
5757
+ try {
5758
+ const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5759
+ const res = await client.query(`SELECT * FROM stsresfhirdate WHERE HASH_IDENTITY = $1`, [hash]);
5760
+ return this.#filterResults({
5761
+ SP_NAME: parameterName,
5762
+ RES_TYPE: resourceName
5763
+ }, res.rows);
5764
+ } catch (error) {
5765
+ const message = `DBSTSDate:ReadByIdentity(): Error: [${error}]`;
5766
+ this._options.logger.error(message);
5767
+ throw new Error(message);
5768
+ }
5769
+ }
5770
+ async ReadByDateTime(client, SP_VALUE_LOW, SP_VALUE_HIGH, parameterName, resourceName) {
5771
+ try {
5772
+ const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5773
+ const res = await client.query(`SELECT * FROM stsresfhirdate WHERE HASH_IDENTITY = $1 AND SP_VALUE_LOW >= $2 AND SP_VALUE_HIGH <= $3`, [
5774
+ hash,
5775
+ SP_VALUE_LOW,
5776
+ SP_VALUE_HIGH
5777
+ ]);
5778
+ return this.#filterResults({
5779
+ SP_NAME: parameterName,
5780
+ RES_TYPE: resourceName
5781
+ }, res.rows);
5782
+ } catch (error) {
5783
+ const message = `DBSTSDate:ReadByDateTime(): Error: [${error}]`;
5784
+ this._options.logger.error(message);
5785
+ throw new Error(message);
5786
+ }
5787
+ }
5788
+ async ReadByDateTimeLow(client, SP_VALUE_LOW, parameterName, resourceName) {
5789
+ try {
5790
+ const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5791
+ const res = await client.query(`SELECT * FROM stsresfhirdate WHERE HASH_IDENTITY = $1 AND SP_VALUE_LOW >= $2`, [hash, SP_VALUE_LOW]);
5792
+ return this.#filterResults({
5793
+ SP_NAME: parameterName,
5794
+ RES_TYPE: resourceName
5795
+ }, res.rows);
5796
+ } catch (error) {
5797
+ const message = `DBSTSDate:ReadByDateTimeLow(): Error: [${error}]`;
5798
+ this._options.logger.error(message);
5799
+ throw new Error(message);
5800
+ }
5801
+ }
5802
+ async ReadByDateTimeHigh(client, SP_VALUE_HIGH, parameterName, resourceName) {
5803
+ try {
5804
+ const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5805
+ const res = await client.query(`SELECT * FROM stsresfhirdate WHERE HASH_IDENTITY = $1 AND SP_VALUE_HIGH <= $2`, [hash, SP_VALUE_HIGH]);
5806
+ return this.#filterResults({
5807
+ SP_NAME: parameterName,
5808
+ RES_TYPE: resourceName
5809
+ }, res.rows);
5810
+ } catch (error) {
5811
+ const message = `DBSTSDate:ReadByDateTimeHigh(): Error: [${error}]`;
5812
+ this._options.logger.error(message);
5813
+ throw new Error(message);
5814
+ }
5374
5815
  }
5375
- async ReadByIdentity(client, parameterName, resourceName) {
5376
- const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5377
- const res = await client.query(`SELECT * FROM stsresfhirquantity WHERE HASH_IDENTITY = $1`, [hash]);
5378
- return this.#filterResults({
5379
- SP_NAME: parameterName,
5380
- RES_TYPE: resourceName
5381
- }, res.rows);
5816
+ async ReadByDateOrdinal(client, SP_VALUE_LOW_DATE_ORDINAL, SP_VALUE_HIGH_DATE_ORDINAL, parameterName, resourceName) {
5817
+ try {
5818
+ const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5819
+ const res = await client.query(`SELECT * FROM stsresfhirdate WHERE HASH_IDENTITY = $1 AND SP_VALUE_LOW_DATE_ORDINAL >= $2 AND SP_VALUE_HIGH_DATE_ORDINAL <= $3`, [
5820
+ hash,
5821
+ SP_VALUE_LOW_DATE_ORDINAL,
5822
+ SP_VALUE_HIGH_DATE_ORDINAL
5823
+ ]);
5824
+ return this.#filterResults({
5825
+ SP_NAME: parameterName,
5826
+ RES_TYPE: resourceName
5827
+ }, res.rows);
5828
+ } catch (error) {
5829
+ const message = `DBSTSDate:ReadByDateOrdinal(): Error: [${error}]`;
5830
+ this._options.logger.error(message);
5831
+ throw new Error(message);
5832
+ }
5382
5833
  }
5383
- async ReadByUnits(client, units, searchValue, parameterName, resourceName) {
5384
- const hash = hashStringParam(`${parameterName}|${resourceName}|${units}`, true);
5385
- const res = await client.query(`SELECT * FROM stsresfhirquantity WHERE HASH_IDENTITY_AND_UNITS = $1 AND SP_VALUE = $2`, [hash, searchValue]);
5386
- return this.#filterResults({
5387
- SP_NAME: parameterName,
5388
- RES_TYPE: resourceName
5389
- }, res.rows);
5834
+ async ReadByDateOrdinalLow(client, SP_VALUE_LOW_DATE_ORDINAL, parameterName, resourceName) {
5835
+ try {
5836
+ const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5837
+ const res = await client.query(`SELECT * FROM stsresfhirdate WHERE HASH_IDENTITY = $1 AND SP_VALUE_LOW_DATE_ORDINAL >= $2`, [hash, SP_VALUE_LOW_DATE_ORDINAL]);
5838
+ return this.#filterResults({
5839
+ SP_NAME: parameterName,
5840
+ RES_TYPE: resourceName
5841
+ }, res.rows);
5842
+ } catch (error) {
5843
+ const message = `DBSTSDate:ReadByDateOrdinalLow(): Error: [${error}]`;
5844
+ this._options.logger.error(message);
5845
+ throw new Error(message);
5846
+ }
5390
5847
  }
5391
- async ReadBySystemAndUnits(client, searchSystem, units, searchValue, parameterName, resourceName) {
5392
- const hash = hashStringParam(`${parameterName}|${resourceName}|${searchSystem}|${units}`, true);
5393
- const res = await client.query(`SELECT * FROM stsresfhirquantity WHERE HASH_IDENTITY_SYS_UNITS = $1 AND SP_VALUE = $2`, [hash, searchValue]);
5394
- return this.#filterResults({
5395
- SP_NAME: parameterName,
5396
- RES_TYPE: resourceName
5397
- }, res.rows);
5848
+ async ReadByDateOrdinalHigh(client, SP_VALUE_HIGH_DATE_ORDINAL, parameterName, resourceName) {
5849
+ try {
5850
+ const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5851
+ const res = await client.query(`SELECT * FROM stsresfhirdate WHERE HASH_IDENTITY = $1 AND SP_VALUE_HIGH_DATE_ORDINAL <= $2`, [hash, SP_VALUE_HIGH_DATE_ORDINAL]);
5852
+ return this.#filterResults({
5853
+ SP_NAME: parameterName,
5854
+ RES_TYPE: resourceName
5855
+ }, res.rows);
5856
+ } catch (error) {
5857
+ const message = `DBSTSDate:ReadByDateOrdinalHigh(): Error: [${error}]`;
5858
+ this._options.logger.error(message);
5859
+ throw new Error(message);
5860
+ }
5398
5861
  }
5399
5862
  async ReadByResID(client, RES_ID, RES_TYPE) {
5400
- return (await client.query(`SELECT * FROM stsresfhirquantity WHERE RES_ID = $1 AND RES_TYPE = $2`, [RES_ID, RES_TYPE])).rows;
5863
+ try {
5864
+ return (await client.query(`SELECT * FROM stsresfhirdate WHERE RES_ID = $1 AND RES_TYPE = $2`, [RES_ID, RES_TYPE])).rows;
5865
+ } catch (error) {
5866
+ const message = `DBSTSDate:ReadByResID(): Error: [${error}]`;
5867
+ this._options.logger.error(message);
5868
+ throw new Error(message);
5869
+ }
5401
5870
  }
5402
5871
  #filterResults(data, results) {
5403
- return results.filter((r) => r.SP_NAME === data.SP_NAME && r.RES_TYPE === data.RES_TYPE);
5872
+ try {
5873
+ return results.filter((r) => r.SP_NAME === data.SP_NAME && r.RES_TYPE === data.RES_TYPE);
5874
+ } catch (error) {
5875
+ const message = `DBSTSDate:#filterResults(): Error: [${error}]`;
5876
+ this._options.logger.error(message);
5877
+ throw new Error(message);
5878
+ }
5404
5879
  }
5405
5880
  };
5406
5881
  //#endregion
5407
- //#region src/fhir-database/pg/pgfhirnumber.ts
5408
- var DBSTSNumber = class {
5882
+ //#region src/fhir-database/pg/pgfhiruri.ts
5883
+ var DBSTSUri = class extends DBSTSFhirDBParamTypeBase {
5884
+ constructor(options) {
5885
+ super(options);
5886
+ }
5409
5887
  async InsertRecord(client, data) {
5410
5888
  try {
5411
5889
  const text = `
5412
- INSERT INTO stsresfhirnumber (
5890
+ INSERT INTO stsresfhiruri (
5413
5891
  PID,
5414
5892
  PARTITION_ID,
5415
5893
  PARTITION_DATE,
@@ -5421,14 +5899,15 @@ var DBSTSNumber = class {
5421
5899
  UPDATED,
5422
5900
  SP_MISSING,
5423
5901
  HASH_IDENTITY,
5424
- SP_VALUE,
5902
+ SP_URI,
5903
+ HASH_URI,
5425
5904
  PATH_FOR_COMP,
5426
5905
  COMPOSITE,
5427
5906
  COMPOSITE_HASH_EXACT
5428
5907
  ) VALUES (
5429
5908
  $1, $2, $3, $4, $5, $6,
5430
- $7, $8, $9, $10, $11, $12,
5431
- $13, $14, $15
5909
+ $7, $8, $9, $10, $11, $12, $13,
5910
+ $14, $15, $16
5432
5911
  )`;
5433
5912
  const values = [
5434
5913
  data.PID,
@@ -5442,269 +5921,99 @@ var DBSTSNumber = class {
5442
5921
  BigInt(data.UPDATED),
5443
5922
  data.SP_MISSING,
5444
5923
  BigInt(data.HASH_IDENTITY),
5445
- data.SP_VALUE ?? 0,
5924
+ data.SP_URI,
5925
+ data.HASH_URI,
5446
5926
  data.PATH_FOR_COMP,
5447
5927
  data.COMPOSITE,
5448
5928
  data.COMPOSITE_HASH_EXACT ? BigInt(data.COMPOSITE_HASH_EXACT) : null
5449
5929
  ];
5450
5930
  await client.query(text, values);
5451
5931
  } catch (error) {
5452
- console.error(error);
5932
+ const message = `DBSTSUri:InsertRecord(): Error: [${error}]`;
5933
+ this._options.logger.error(message);
5934
+ throw new Error(message);
5453
5935
  }
5454
5936
  }
5455
5937
  async DeleteRecord(client, data) {
5456
- await client.query(`DELETE FROM stsresfhirnumber WHERE RES_ID = $1 AND RES_TYPE = $2`, [data.RES_ID, data.RES_TYPE]);
5457
- }
5458
- async ReadByPIDRecord(client, PID) {
5459
- return (await client.query(`SELECT * FROM stsresfhirnumber WHERE PID = $1`, [PID])).rows[0];
5460
- }
5461
- async ReadAllRecords(client) {
5462
- return (await client.query(`SELECT * FROM stsresfhirnumber`)).rows;
5463
- }
5464
- async ReadByIdentity(client, parameterName, resourceName) {
5465
- const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5466
- const res = await client.query(`SELECT * FROM stsresfhirnumber WHERE HASH_IDENTITY = $1`, [hash]);
5467
- return this.#filterResults({
5468
- SP_NAME: parameterName,
5469
- RES_TYPE: resourceName
5470
- }, res.rows);
5471
- }
5472
- async ReadByValue(client, searchValue, parameterName, resourceName) {
5473
- const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5474
- const res = await client.query(`SELECT * FROM stsresfhirnumber WHERE HASH_IDENTITY = $1 AND SP_VALUE = $2`, [hash, searchValue]);
5475
- return this.#filterResults({
5476
- SP_NAME: parameterName,
5477
- RES_TYPE: resourceName
5478
- }, res.rows);
5479
- }
5480
- async ReadByResID(client, RES_ID, RES_TYPE) {
5481
- return (await client.query(`SELECT * FROM stsresfhirnumber WHERE RES_ID = $1 AND RES_TYPE = $2`, [RES_ID, RES_TYPE])).rows;
5482
- }
5483
- #filterResults(data, results) {
5484
- return results.filter((r) => r.SP_NAME === data.SP_NAME && r.RES_TYPE === data.RES_TYPE);
5485
- }
5486
- };
5487
- //#endregion
5488
- //#region src/fhir-database/pg/pgfhirdate.ts
5489
- var DBSTSDate = class {
5490
- async InsertRecord(client, data) {
5491
- const text = `
5492
- INSERT INTO stsresfhirdate (
5493
- PID,
5494
- PARTITION_ID,
5495
- PARTITION_DATE,
5496
- SP_NAME,
5497
- SP_PARAM_TYPE,
5498
- SP_STR,
5499
- RES_ID,
5500
- RES_TYPE,
5501
- UPDATED,
5502
- SP_MISSING,
5503
- HASH_IDENTITY,
5504
- SP_VALUE_LOW,
5505
- SP_VALUE_HIGH,
5506
- SP_VALUE_LOW_DATE_ORDINAL,
5507
- SP_VALUE_HIGH_DATE_ORDINAL,
5508
- PATH_FOR_COMP,
5509
- COMPOSITE,
5510
- COMPOSITE_HASH_EXACT
5511
- ) VALUES (
5512
- $1, $2, $3, $4, $5, $6,
5513
- $7, $8, $9, $10, $11, $12,
5514
- $13, $14, $15,
5515
- $16, $17, $18
5516
- )`;
5517
- const values = [
5518
- data.PID,
5519
- data.PARTITION_ID ?? 0,
5520
- data.PARTITION_DATE ?? 0,
5521
- data.SP_NAME,
5522
- data.SP_PARAM_TYPE,
5523
- data.SP_STR,
5524
- data.RES_ID,
5525
- data.RES_TYPE,
5526
- BigInt(data.UPDATED),
5527
- data.SP_MISSING,
5528
- BigInt(data.HASH_IDENTITY),
5529
- data.SP_VALUE_LOW ? data.SP_VALUE_LOW.toJSDate() : null,
5530
- data.SP_VALUE_HIGH ? data.SP_VALUE_HIGH.toJSDate() : null,
5531
- data.SP_VALUE_LOW_DATE_ORDINAL,
5532
- data.SP_VALUE_HIGH_DATE_ORDINAL,
5533
- data.PATH_FOR_COMP,
5534
- data.COMPOSITE,
5535
- data.COMPOSITE_HASH_EXACT ? BigInt(data.COMPOSITE_HASH_EXACT) : null
5536
- ];
5537
- await client.query(text, values);
5538
- }
5539
- async DeleteRecord(client, data) {
5540
- await client.query(`DELETE FROM stsresfhirdate WHERE RES_ID = $1 AND RES_TYPE = $2`, [data.RES_ID, data.RES_TYPE]);
5541
- }
5542
- async ReadByPIDRecord(client, PID) {
5543
- const res = await client.query(`SELECT * FROM stsresfhirdate WHERE PID = $1`, [PID]);
5544
- if (res.rows && res.rows.length === 1) {
5545
- if (res.rows[0].sp_value_high !== null) res.rows[0].sp_value_high = DateTime.fromJSDate(res.rows[0].sp_value_high);
5546
- if (res.rows[0].sp_value_low !== null) res.rows[0].sp_value_low = DateTime.fromJSDate(res.rows[0].sp_value_low);
5938
+ try {
5939
+ await client.query(`DELETE FROM stsresfhiruri WHERE RES_ID = $1 AND RES_TYPE = $2`, [data.RES_ID, data.RES_TYPE]);
5940
+ } catch (error) {
5941
+ const message = `DBSTSUri:DeleteRecord(): Error: [${error}]`;
5942
+ this._options.logger.error(message);
5943
+ throw new Error(message);
5547
5944
  }
5548
- return res.rows[0];
5549
- }
5550
- async ReadAllRecords(client) {
5551
- return (await client.query(`SELECT * FROM stsresfhirdate`)).rows;
5552
- }
5553
- async ReadByIdentity(client, parameterName, resourceName) {
5554
- const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5555
- const res = await client.query(`SELECT * FROM stsresfhirdate WHERE HASH_IDENTITY = $1`, [hash]);
5556
- return this.#filterResults({
5557
- SP_NAME: parameterName,
5558
- RES_TYPE: resourceName
5559
- }, res.rows);
5560
- }
5561
- async ReadByDateTime(client, SP_VALUE_LOW, SP_VALUE_HIGH, parameterName, resourceName) {
5562
- const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5563
- const res = await client.query(`SELECT * FROM stsresfhirdate WHERE HASH_IDENTITY = $1 AND SP_VALUE_LOW >= $2 AND SP_VALUE_HIGH <= $3`, [
5564
- hash,
5565
- SP_VALUE_LOW,
5566
- SP_VALUE_HIGH
5567
- ]);
5568
- return this.#filterResults({
5569
- SP_NAME: parameterName,
5570
- RES_TYPE: resourceName
5571
- }, res.rows);
5572
- }
5573
- async ReadByDateTimeLow(client, SP_VALUE_LOW, parameterName, resourceName) {
5574
- const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5575
- const res = await client.query(`SELECT * FROM stsresfhirdate WHERE HASH_IDENTITY = $1 AND SP_VALUE_LOW >= $2`, [hash, SP_VALUE_LOW]);
5576
- return this.#filterResults({
5577
- SP_NAME: parameterName,
5578
- RES_TYPE: resourceName
5579
- }, res.rows);
5580
- }
5581
- async ReadByDateTimeHigh(client, SP_VALUE_HIGH, parameterName, resourceName) {
5582
- const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5583
- const res = await client.query(`SELECT * FROM stsresfhirdate WHERE HASH_IDENTITY = $1 AND SP_VALUE_HIGH <= $2`, [hash, SP_VALUE_HIGH]);
5584
- return this.#filterResults({
5585
- SP_NAME: parameterName,
5586
- RES_TYPE: resourceName
5587
- }, res.rows);
5588
- }
5589
- async ReadByDateOrdinal(client, SP_VALUE_LOW_DATE_ORDINAL, SP_VALUE_HIGH_DATE_ORDINAL, parameterName, resourceName) {
5590
- const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5591
- const res = await client.query(`SELECT * FROM stsresfhirdate WHERE HASH_IDENTITY = $1 AND SP_VALUE_LOW_DATE_ORDINAL >= $2 AND SP_VALUE_HIGH_DATE_ORDINAL <= $3`, [
5592
- hash,
5593
- SP_VALUE_LOW_DATE_ORDINAL,
5594
- SP_VALUE_HIGH_DATE_ORDINAL
5595
- ]);
5596
- return this.#filterResults({
5597
- SP_NAME: parameterName,
5598
- RES_TYPE: resourceName
5599
- }, res.rows);
5600
- }
5601
- async ReadByDateOrdinalLow(client, SP_VALUE_LOW_DATE_ORDINAL, parameterName, resourceName) {
5602
- const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5603
- const res = await client.query(`SELECT * FROM stsresfhirdate WHERE HASH_IDENTITY = $1 AND SP_VALUE_LOW_DATE_ORDINAL >= $2`, [hash, SP_VALUE_LOW_DATE_ORDINAL]);
5604
- return this.#filterResults({
5605
- SP_NAME: parameterName,
5606
- RES_TYPE: resourceName
5607
- }, res.rows);
5608
- }
5609
- async ReadByDateOrdinalHigh(client, SP_VALUE_HIGH_DATE_ORDINAL, parameterName, resourceName) {
5610
- const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5611
- const res = await client.query(`SELECT * FROM stsresfhirdate WHERE HASH_IDENTITY = $1 AND SP_VALUE_HIGH_DATE_ORDINAL <= $2`, [hash, SP_VALUE_HIGH_DATE_ORDINAL]);
5612
- return this.#filterResults({
5613
- SP_NAME: parameterName,
5614
- RES_TYPE: resourceName
5615
- }, res.rows);
5616
- }
5617
- async ReadByResID(client, RES_ID, RES_TYPE) {
5618
- return (await client.query(`SELECT * FROM stsresfhirdate WHERE RES_ID = $1 AND RES_TYPE = $2`, [RES_ID, RES_TYPE])).rows;
5619
- }
5620
- #filterResults(data, results) {
5621
- return results.filter((r) => r.SP_NAME === data.SP_NAME && r.RES_TYPE === data.RES_TYPE);
5622
- }
5623
- };
5624
- //#endregion
5625
- //#region src/fhir-database/pg/pgfhiruri.ts
5626
- var DBSTSUri = class {
5627
- async InsertRecord(client, data) {
5628
- const text = `
5629
- INSERT INTO stsresfhiruri (
5630
- PID,
5631
- PARTITION_ID,
5632
- PARTITION_DATE,
5633
- SP_NAME,
5634
- SP_PARAM_TYPE,
5635
- SP_STR,
5636
- RES_ID,
5637
- RES_TYPE,
5638
- UPDATED,
5639
- SP_MISSING,
5640
- HASH_IDENTITY,
5641
- SP_URI,
5642
- HASH_URI,
5643
- PATH_FOR_COMP,
5644
- COMPOSITE,
5645
- COMPOSITE_HASH_EXACT
5646
- ) VALUES (
5647
- $1, $2, $3, $4, $5, $6,
5648
- $7, $8, $9, $10, $11, $12, $13,
5649
- $14, $15, $16
5650
- )`;
5651
- const values = [
5652
- data.PID,
5653
- data.PARTITION_ID ?? 0,
5654
- data.PARTITION_DATE ?? 0,
5655
- data.SP_NAME,
5656
- data.SP_PARAM_TYPE,
5657
- data.SP_STR,
5658
- data.RES_ID,
5659
- data.RES_TYPE,
5660
- BigInt(data.UPDATED),
5661
- data.SP_MISSING,
5662
- BigInt(data.HASH_IDENTITY),
5663
- data.SP_URI,
5664
- data.HASH_URI,
5665
- data.PATH_FOR_COMP,
5666
- data.COMPOSITE,
5667
- data.COMPOSITE_HASH_EXACT ? BigInt(data.COMPOSITE_HASH_EXACT) : null
5668
- ];
5669
- await client.query(text, values);
5670
- }
5671
- async DeleteRecord(client, data) {
5672
- await client.query(`DELETE FROM stsresfhiruri WHERE RES_ID = $1 AND RES_TYPE = $2`, [data.RES_ID, data.RES_TYPE]);
5673
5945
  }
5674
5946
  async ReadByPIDRecord(client, PID) {
5675
- return (await client.query(`SELECT * FROM stsresfhiruri WHERE PID = $1`, [PID])).rows[0];
5947
+ try {
5948
+ return (await client.query(`SELECT * FROM stsresfhiruri WHERE PID = $1`, [PID])).rows[0];
5949
+ } catch (error) {
5950
+ const message = `DBSTSUri:ReadByPIDRecord(): Error: [${error}]`;
5951
+ this._options.logger.error(message);
5952
+ throw new Error(message);
5953
+ }
5676
5954
  }
5677
5955
  async ReadAllRecords(client) {
5678
- return (await client.query(`SELECT * FROM stsresfhiruri`)).rows;
5956
+ try {
5957
+ return (await client.query(`SELECT * FROM stsresfhiruri`)).rows;
5958
+ } catch (error) {
5959
+ const message = `DBSTSUri:ReadAllRecords(): Error: [${error}]`;
5960
+ this._options.logger.error(message);
5961
+ throw new Error(message);
5962
+ }
5679
5963
  }
5680
5964
  async ReadByIdentity(client, parameterName, resourceName) {
5681
- const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5682
- const res = await client.query(`SELECT * FROM stsresfhiruri WHERE HASH_IDENTITY = $1`, [hash]);
5683
- return this.#filterResults({
5684
- SP_NAME: parameterName,
5685
- RES_TYPE: resourceName
5686
- }, res.rows);
5965
+ try {
5966
+ const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5967
+ const res = await client.query(`SELECT * FROM stsresfhiruri WHERE HASH_IDENTITY = $1`, [hash]);
5968
+ return this.#filterResults({
5969
+ SP_NAME: parameterName,
5970
+ RES_TYPE: resourceName
5971
+ }, res.rows);
5972
+ } catch (error) {
5973
+ const message = `DBSTSUri:ReadByIdentity(): Error: [${error}]`;
5974
+ this._options.logger.error(message);
5975
+ throw new Error(message);
5976
+ }
5687
5977
  }
5688
5978
  async ReadByURI(client, uri, parameterName, resourceName) {
5689
- const hash = hashStringParam(`${parameterName}|${resourceName}|${uri}`, true);
5690
- const res = await client.query(`SELECT * FROM stsresfhiruri WHERE HASH_URI = $1`, [hash]);
5691
- return this.#filterResults({
5692
- SP_NAME: parameterName,
5693
- RES_TYPE: resourceName
5694
- }, res.rows);
5979
+ try {
5980
+ const hash = hashStringParam(`${parameterName}|${resourceName}|${uri}`, true);
5981
+ const res = await client.query(`SELECT * FROM stsresfhiruri WHERE HASH_URI = $1`, [hash]);
5982
+ return this.#filterResults({
5983
+ SP_NAME: parameterName,
5984
+ RES_TYPE: resourceName
5985
+ }, res.rows);
5986
+ } catch (error) {
5987
+ const message = `DBSTSUri:ReadByURI(): Error: [${error}]`;
5988
+ this._options.logger.error(message);
5989
+ throw new Error(message);
5990
+ }
5695
5991
  }
5696
5992
  async ReadByResID(client, RES_ID, RES_TYPE) {
5697
- return (await client.query(`SELECT * FROM stsresfhiruri WHERE RES_ID = $1 AND RES_TYPE = $2`, [RES_ID, RES_TYPE])).rows;
5993
+ try {
5994
+ return (await client.query(`SELECT * FROM stsresfhiruri WHERE RES_ID = $1 AND RES_TYPE = $2`, [RES_ID, RES_TYPE])).rows;
5995
+ } catch (error) {
5996
+ const message = `DBSTSUri:ReadByResID(): Error: [${error}]`;
5997
+ this._options.logger.error(message);
5998
+ throw new Error(message);
5999
+ }
5698
6000
  }
5699
6001
  #filterResults(data, results) {
5700
- return results.filter((r) => r.SP_NAME === data.SP_NAME && r.RES_TYPE === data.RES_TYPE);
6002
+ try {
6003
+ return results.filter((r) => r.SP_NAME === data.SP_NAME && r.RES_TYPE === data.RES_TYPE);
6004
+ } catch (error) {
6005
+ const message = `DBSTSUri:#filterResults(): Error: [${error}]`;
6006
+ this._options.logger.error(message);
6007
+ throw new Error(message);
6008
+ }
5701
6009
  }
5702
6010
  };
5703
6011
  //#endregion
5704
6012
  //#region src/fhir-database/pg/pgfhircombo.ts
5705
- var DBSTSCombo = class {
5706
- #replacer = (_, v) => typeof v === "bigint" ? { __bigint__: v.toString() } : v;
5707
- #reviver = (_, v) => v && v.__bigint__ !== void 0 ? BigInt(v.__bigint__) : v;
6013
+ var DBSTSCombo = class extends DBSTSFhirDBParamTypeBase {
6014
+ constructor(options) {
6015
+ super(options);
6016
+ }
5708
6017
  async InsertRecord(client, data) {
5709
6018
  try {
5710
6019
  const text = `
@@ -5743,28 +6052,51 @@ var DBSTSCombo = class {
5743
6052
  ];
5744
6053
  await client.query(text, values);
5745
6054
  } catch (error) {
5746
- defaultLogger.error(`DBSTSCombo:InsertRecord(): Error: [${error}]`);
5747
- defaultLogger.error(data);
5748
- defaultLogger.error(JSON.stringify(data, this.#replacer, 2));
5749
- throw error;
6055
+ const message = `DBSTSCombo:InsertRecord(): Error: [${error}]`;
6056
+ this._options.logger.error(message);
6057
+ throw new Error(message);
5750
6058
  }
5751
6059
  }
5752
6060
  async DeleteRecord(client, data) {
5753
- await client.query(`DELETE FROM stsresfhircombo WHERE RES_ID = $1 AND RES_TYPE = $2`, [data.RES_ID, data.RES_TYPE]);
6061
+ try {
6062
+ await client.query(`DELETE FROM stsresfhircombo WHERE RES_ID = $1 AND RES_TYPE = $2`, [data.RES_ID, data.RES_TYPE]);
6063
+ } catch (error) {
6064
+ const message = `DBSTSCombo:DeleteRecord(): Error: [${error}]`;
6065
+ this._options.logger.error(message);
6066
+ throw new Error(message);
6067
+ }
5754
6068
  }
5755
6069
  async ReadByPIDRecord(client, PID) {
5756
- return (await client.query(`SELECT * FROM stsresfhircombo WHERE PID = $1`, [PID])).rows[0];
6070
+ try {
6071
+ return (await client.query(`SELECT * FROM stsresfhircombo WHERE PID = $1`, [PID])).rows[0];
6072
+ } catch (error) {
6073
+ const message = `DBSTSCombo:ReadByPIDRecord(): Error: [${error}]`;
6074
+ this._options.logger.error(message);
6075
+ throw new Error(message);
6076
+ }
5757
6077
  }
5758
6078
  async ReadAllRecords(client) {
5759
- return (await client.query(`SELECT * FROM stsresfhircombo`)).rows;
6079
+ try {
6080
+ return (await client.query(`SELECT * FROM stsresfhircombo`)).rows;
6081
+ } catch (error) {
6082
+ const message = `DBSTSCombo:ReadAllRecords(): Error: [${error}]`;
6083
+ this._options.logger.error(message);
6084
+ throw new Error(message);
6085
+ }
5760
6086
  }
5761
6087
  async ReadByIdentity(client, parameterName, resourceName) {
5762
- const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
5763
- const res = await client.query(`SELECT * FROM stsresfhircombo WHERE HASH_IDENTITY = $1`, [hash]);
5764
- return this.#filterResults({
5765
- SP_NAME: parameterName,
5766
- RES_TYPE: resourceName
5767
- }, res.rows);
6088
+ try {
6089
+ const hash = hashStringParam(`${parameterName}|${resourceName}`, true);
6090
+ const res = await client.query(`SELECT * FROM stsresfhircombo WHERE HASH_IDENTITY = $1`, [hash]);
6091
+ return this.#filterResults({
6092
+ SP_NAME: parameterName,
6093
+ RES_TYPE: resourceName
6094
+ }, res.rows);
6095
+ } catch (error) {
6096
+ const message = `DBSTSCombo:ReadByIdentity(): Error: [${error}]`;
6097
+ this._options.logger.error(message);
6098
+ throw new Error(message);
6099
+ }
5768
6100
  }
5769
6101
  async ReadByString(client, stringVal, parameterName, resourceName) {
5770
6102
  return [];
@@ -5788,10 +6120,22 @@ var DBSTSCombo = class {
5788
6120
  return [];
5789
6121
  }
5790
6122
  async ReadByResID(client, RES_ID, RES_TYPE) {
5791
- return (await client.query(`SELECT * FROM stsresfhircombo WHERE RES_ID = $1 AND RES_TYPE = $2`, [RES_ID, RES_TYPE])).rows;
6123
+ try {
6124
+ return (await client.query(`SELECT * FROM stsresfhircombo WHERE RES_ID = $1 AND RES_TYPE = $2`, [RES_ID, RES_TYPE])).rows;
6125
+ } catch (error) {
6126
+ const message = `DBSTSCombo:ReadByResID(): Error: [${error}]`;
6127
+ this._options.logger.error(message);
6128
+ throw new Error(message);
6129
+ }
5792
6130
  }
5793
6131
  #filterResults(data, results) {
5794
- return results.filter((r) => r.SP_NAME === data.SP_NAME && r.RES_TYPE === data.RES_TYPE);
6132
+ try {
6133
+ return results.filter((r) => r.SP_NAME === data.SP_NAME && r.RES_TYPE === data.RES_TYPE);
6134
+ } catch (error) {
6135
+ const message = `DBSTSCombo:#filterResults(): Error: [${error}]`;
6136
+ this._options.logger.error(message);
6137
+ throw new Error(message);
6138
+ }
5795
6139
  }
5796
6140
  };
5797
6141
  //#endregion
@@ -5813,8 +6157,6 @@ var PGFhirAccessLayer = class extends TinyEmitter {
5813
6157
  #dbSTSCombo;
5814
6158
  #transactions = {};
5815
6159
  #maxTransactionTime = 6e4;
5816
- #replacer = (_, v) => typeof v === "bigint" ? { __bigint__: v.toString() } : v;
5817
- #reviver = (_, v) => v && v.__bigint__ !== void 0 ? BigInt(v.__bigint__) : v;
5818
6160
  constructor(options) {
5819
6161
  super();
5820
6162
  this.#options = options;
@@ -5822,18 +6164,34 @@ var PGFhirAccessLayer = class extends TinyEmitter {
5822
6164
  logger: this.#options.logger,
5823
6165
  usedefaultdb: this.#options.usedefaultdb
5824
6166
  });
5825
- this.#dbSTSResource = new DBSTSResource(this.#poolManager);
5826
- this.#dbSTSResourceVersion = new DBSTSResourceVersion(this.#poolManager);
6167
+ this.#dbSTSResource = new DBSTSResource({
6168
+ logger: this.#options.logger,
6169
+ poolManager: this.#poolManager
6170
+ });
6171
+ this.#dbSTSResourceVersion = new DBSTSResourceVersion({
6172
+ logger: this.#options.logger,
6173
+ poolManager: this.#poolManager
6174
+ });
5827
6175
  this.#dbSearchIndex = DBSearchIndex.getInstance();
5828
- this.#dbSTSResourceLink = new DBSTSResourceLink();
5829
- this.#dbSTSString = new DBSTSString();
5830
- this.#dbSTSToken = new DBSTSToken();
5831
- this.#dbSTSQuantity = new DBSTSQuantity();
5832
- this.#dbSTSNumber = new DBSTSNumber();
5833
- this.#dbSTSDate = new DBSTSDate();
5834
- this.#dbSTSUri = new DBSTSUri();
5835
- this.#dbSTSCombo = new DBSTSCombo();
5836
- }
6176
+ this.#dbSTSResourceLink = new DBSTSResourceLink({ logger: this.#options.logger });
6177
+ this.#dbSTSString = new DBSTSString({ logger: this.#options.logger });
6178
+ this.#dbSTSToken = new DBSTSToken({ logger: this.#options.logger });
6179
+ this.#dbSTSQuantity = new DBSTSQuantity({ logger: this.#options.logger });
6180
+ this.#dbSTSNumber = new DBSTSNumber({ logger: this.#options.logger });
6181
+ this.#dbSTSDate = new DBSTSDate({ logger: this.#options.logger });
6182
+ this.#dbSTSUri = new DBSTSUri({ logger: this.#options.logger });
6183
+ this.#dbSTSCombo = new DBSTSCombo({ logger: this.#options.logger });
6184
+ }
6185
+ GetOperationOutcome = (code, diagnostics) => {
6186
+ return {
6187
+ resourceType: "OperationOutcome",
6188
+ issue: [{
6189
+ severity: "error",
6190
+ code,
6191
+ diagnostics
6192
+ }]
6193
+ };
6194
+ };
5837
6195
  async StartDatabase() {
5838
6196
  return true;
5839
6197
  }
@@ -6019,14 +6377,14 @@ var PGFhirAccessLayer = class extends TinyEmitter {
6019
6377
  return false;
6020
6378
  };
6021
6379
  CreateResource = async (resource, transactionHandle) => {
6022
- if (this.#poolManager) try {
6023
- let PK = randomUUID$1();
6024
- const RES_ID = resource.id;
6025
- const RES_TYPE = resource.resourceType;
6026
- const RES = JSON.stringify(resource);
6027
- const now = (/* @__PURE__ */ new Date()).getTime();
6028
- let client;
6029
- let useTransaction;
6380
+ if (!this.#poolManager) {
6381
+ const errorMessage = `CreateResource(): poolManager not set`;
6382
+ this.#options.logger.error(errorMessage);
6383
+ throw new Error(errorMessage);
6384
+ }
6385
+ let client;
6386
+ let useTransaction;
6387
+ try {
6030
6388
  if (transactionHandle && this.#transactions[transactionHandle]) {
6031
6389
  client = this.#transactions[transactionHandle].client;
6032
6390
  useTransaction = false;
@@ -6034,50 +6392,72 @@ var PGFhirAccessLayer = class extends TinyEmitter {
6034
6392
  client = await this.#poolManager.connectReadWrite();
6035
6393
  useTransaction = true;
6036
6394
  }
6037
- try {
6038
- if (useTransaction) await client.query("BEGIN");
6039
- await this.#dbSTSResource.InsertResourceEx(client, {
6040
- PID: PK,
6041
- PARTITION_ID: 0,
6042
- PARTITION_DATE: 0,
6043
- RES_ID,
6044
- RES_TYPE,
6045
- RES_VER: 1,
6046
- RES_VERSION: "r5",
6047
- RES_PUBLISHED: now,
6048
- RES_UPDATED: now
6049
- });
6050
- await this.#dbSTSResourceVersion.InsertResourceVersionEx(client, {
6051
- PID: randomUUID$1(),
6052
- PARTITION_ID: 0,
6053
- PARTITION_DATE: 0,
6054
- RES_ID,
6055
- RES_TYPE,
6056
- RES_VER: 1,
6057
- OPERATION: "POST",
6058
- RES
6059
- });
6060
- performance.now();
6061
- await this.UpdateIndexes(client, resource);
6062
- if (useTransaction) await client.query("COMMIT");
6063
- return resource;
6064
- } catch (error) {
6065
- if (useTransaction) await client.query("ROLLBACK");
6066
- } finally {
6067
- if (useTransaction) client.release();
6068
- }
6069
6395
  } catch (error) {
6070
- defaultLogger.error(`PGFhirAccessLayer:CreateResource(): [${error}]`);
6396
+ const errorMessage = `CreateResource(): Could not get connection: Error: [${error}]`;
6397
+ this.#options.logger.error(errorMessage);
6398
+ throw new Error(errorMessage);
6071
6399
  }
6072
- };
6073
- UpdateResource = async (resource, RES_VER, operation, transactionHandle) => {
6074
- if (this.#poolManager) try {
6400
+ try {
6075
6401
  const RES_ID = resource.id;
6076
6402
  const RES_TYPE = resource.resourceType;
6077
- const RES = JSON.stringify(resource);
6078
6403
  const now = (/* @__PURE__ */ new Date()).getTime();
6079
- let client;
6080
- let useTransaction;
6404
+ if (useTransaction) await client.query("BEGIN");
6405
+ const newVersion = await this.#dbSTSResource.InsertResourceEx(client, {
6406
+ PID: randomUUID$1(),
6407
+ PARTITION_ID: 0,
6408
+ PARTITION_DATE: 0,
6409
+ RES_ID,
6410
+ RES_TYPE,
6411
+ RES_VER: 1,
6412
+ RES_VERSION: "r5",
6413
+ RES_PUBLISHED: now,
6414
+ RES_UPDATED: now
6415
+ });
6416
+ if (newVersion === void 0) {
6417
+ const errorMessage = `CreateResource(): Version Conflict. newVersion is undefined.`;
6418
+ this.#options.logger.error(errorMessage);
6419
+ throw new Error(errorMessage);
6420
+ }
6421
+ resource.meta ??= {};
6422
+ resource.meta.versionId = String(newVersion);
6423
+ resource.meta.lastUpdated = new Date(now).toISOString();
6424
+ const RES = JSON.stringify(resource);
6425
+ if (await this.#dbSTSResourceVersion.InsertResourceVersionEx(client, {
6426
+ PID: randomUUID$1(),
6427
+ PARTITION_ID: 0,
6428
+ PARTITION_DATE: 0,
6429
+ RES_ID,
6430
+ RES_TYPE,
6431
+ RES_VER: newVersion,
6432
+ OPERATION: "POST",
6433
+ RES
6434
+ }) === void 0) {
6435
+ const errorMessage = `CreateResource(): Version Conflict. resourceVersionRunResult is undefined.`;
6436
+ this.#options.logger.error(errorMessage);
6437
+ throw new Error(errorMessage);
6438
+ }
6439
+ performance.now();
6440
+ await this.UpdateIndexes(client, resource);
6441
+ if (useTransaction) await client.query("COMMIT");
6442
+ return resource;
6443
+ } catch (error) {
6444
+ if (useTransaction) await client.query("ROLLBACK");
6445
+ const errorMessage = `CreateResource(): Error: [${error}]`;
6446
+ this.#options.logger.error(errorMessage);
6447
+ throw new Error(errorMessage);
6448
+ } finally {
6449
+ if (useTransaction) client.release();
6450
+ }
6451
+ };
6452
+ UpdateResource = async (resource, RES_VER, operation, transactionHandle) => {
6453
+ if (!this.#poolManager) {
6454
+ const errorMessage = `UpdateResource(): poolManager not set`;
6455
+ this.#options.logger.error(errorMessage);
6456
+ throw new Error(errorMessage);
6457
+ }
6458
+ let client;
6459
+ let useTransaction;
6460
+ try {
6081
6461
  if (transactionHandle && this.#transactions[transactionHandle]) {
6082
6462
  client = this.#transactions[transactionHandle].client;
6083
6463
  useTransaction = false;
@@ -6085,43 +6465,66 @@ var PGFhirAccessLayer = class extends TinyEmitter {
6085
6465
  client = await this.#poolManager.connectReadWrite();
6086
6466
  useTransaction = true;
6087
6467
  }
6088
- try {
6089
- if (useTransaction) await client.query("BEGIN");
6090
- await this.#dbSTSResource.UpdateResourceRecordEx(client, {
6091
- RES_TYPE,
6092
- RES_ID,
6093
- RES_VER,
6094
- RES_UPDATED: now
6095
- });
6096
- await this.#dbSTSResourceVersion.InsertResourceVersionEx(client, {
6097
- PID: randomUUID$1(),
6098
- PARTITION_ID: 0,
6099
- PARTITION_DATE: 0,
6100
- RES_ID,
6101
- RES_TYPE,
6102
- RES_VER: RES_VER + 1,
6103
- OPERATION: operation,
6104
- RES
6105
- });
6106
- await this.UpdateIndexes(client, resource);
6107
- if (useTransaction) await client.query("COMMIT");
6108
- return resource;
6109
- } catch (error) {
6110
- if (useTransaction) await client.query("ROLLBACK");
6111
- } finally {
6112
- if (useTransaction) client.release();
6468
+ } catch (error) {
6469
+ const errorMessage = `UpdateResource(): Could not get connection: Error: [${error}]`;
6470
+ this.#options.logger.error(errorMessage);
6471
+ throw new Error(errorMessage);
6472
+ }
6473
+ try {
6474
+ const RES_ID = resource.id;
6475
+ const RES_TYPE = resource.resourceType;
6476
+ const now = (/* @__PURE__ */ new Date()).getTime();
6477
+ if (useTransaction) await client.query("BEGIN");
6478
+ const newVersion = await this.#dbSTSResource.UpdateResourceRecordEx(client, {
6479
+ RES_TYPE,
6480
+ RES_ID,
6481
+ RES_VER,
6482
+ RES_UPDATED: now
6483
+ });
6484
+ if (newVersion === void 0) {
6485
+ const errorMessage = `UpdateResource(): Version Conflict. newVersion is undefined. RES_VER: [${RES_VER}]`;
6486
+ this.#options.logger.error(errorMessage);
6487
+ throw new Error(errorMessage);
6488
+ }
6489
+ resource.meta ??= {};
6490
+ resource.meta.versionId = String(newVersion);
6491
+ resource.meta.lastUpdated = new Date(now).toISOString();
6492
+ const RES = JSON.stringify(resource);
6493
+ if (await this.#dbSTSResourceVersion.InsertResourceVersionEx(client, {
6494
+ PID: randomUUID$1(),
6495
+ PARTITION_ID: 0,
6496
+ PARTITION_DATE: 0,
6497
+ RES_ID,
6498
+ RES_TYPE,
6499
+ RES_VER: newVersion,
6500
+ OPERATION: operation,
6501
+ RES
6502
+ }) === void 0) {
6503
+ const errorMessage = `UpdateResource(): Version Conflict. resourceVersionRunResult is undefined. RES_VER: [${RES_VER}]`;
6504
+ this.#options.logger.error(errorMessage);
6505
+ throw new Error(errorMessage);
6113
6506
  }
6507
+ await this.UpdateIndexes(client, resource);
6508
+ if (useTransaction) await client.query("COMMIT");
6509
+ return resource;
6114
6510
  } catch (error) {
6115
- defaultLogger.error(`PGFhirAccessLayer:UpdateResource(): [${error}]`);
6511
+ if (useTransaction) await client.query("ROLLBACK");
6512
+ const errorMessage = `UpdateResource(): Error: [${error}]`;
6513
+ this.#options.logger.error(errorMessage);
6514
+ throw new Error(errorMessage);
6515
+ } finally {
6516
+ if (useTransaction) client.release();
6116
6517
  }
6117
6518
  };
6118
6519
  DeleteResource = async (resource, RES_VER, transactionHandle) => {
6119
- if (this.#poolManager) try {
6120
- const RES_ID = resource.id;
6121
- const RES_TYPE = resource.resourceType;
6122
- const now = new Date(DateTime.fromISO(resource.meta.lastUpdated).toJSDate()).getTime();
6123
- let client;
6124
- let useTransaction;
6520
+ if (!this.#poolManager) {
6521
+ const errorMessage = `DeleteResource(): poolManager not set`;
6522
+ this.#options.logger.error(errorMessage);
6523
+ throw new Error(errorMessage);
6524
+ }
6525
+ let client;
6526
+ let useTransaction;
6527
+ try {
6125
6528
  if (transactionHandle && this.#transactions[transactionHandle]) {
6126
6529
  client = this.#transactions[transactionHandle].client;
6127
6530
  useTransaction = false;
@@ -6129,39 +6532,64 @@ var PGFhirAccessLayer = class extends TinyEmitter {
6129
6532
  client = await this.#poolManager.connectReadWrite();
6130
6533
  useTransaction = true;
6131
6534
  }
6132
- try {
6133
- if (useTransaction) await client.query("BEGIN");
6134
- await this.#dbSTSResource.DeleteResourceRecordEx(client, {
6135
- RES_ID,
6136
- RES_TYPE,
6137
- RES_VER,
6138
- RES_DELETED_AT: now,
6139
- RES_UPDATED: now
6140
- });
6141
- await this.#dbSTSResourceVersion.InsertResourceVersionEx(client, {
6142
- PID: randomUUID$1(),
6143
- PARTITION_ID: 0,
6144
- PARTITION_DATE: 0,
6145
- RES_ID,
6146
- RES_TYPE,
6147
- RES_VER: RES_VER + 1,
6148
- OPERATION: "DELETE",
6149
- RES: ""
6150
- });
6151
- await this.UpdateIndexes(client, resource);
6152
- if (useTransaction) await client.query("COMMIT");
6153
- return resource;
6154
- } catch (error) {
6155
- if (useTransaction) await client.query("ROLLBACK");
6156
- } finally {
6157
- if (useTransaction) client.release();
6535
+ } catch (error) {
6536
+ const errorMessage = `DeleteResource(): Could not get connection: Error: [${error}]`;
6537
+ this.#options.logger.error(errorMessage);
6538
+ throw new Error(errorMessage);
6539
+ }
6540
+ try {
6541
+ const RES_ID = resource.id;
6542
+ const RES_TYPE = resource.resourceType;
6543
+ const now = (/* @__PURE__ */ new Date()).getTime();
6544
+ if (useTransaction) await client.query("BEGIN");
6545
+ const newVersion = await this.#dbSTSResource.DeleteResourceRecordEx(client, {
6546
+ RES_ID,
6547
+ RES_TYPE,
6548
+ RES_VER,
6549
+ RES_DELETED_AT: now,
6550
+ RES_UPDATED: now
6551
+ });
6552
+ if (newVersion === void 0) {
6553
+ const errorMessage = `DeleteResource(): Version Conflict. newVersion is undefined. RES_VER: [${RES_VER}]`;
6554
+ this.#options.logger.error(errorMessage);
6555
+ throw new Error(errorMessage);
6158
6556
  }
6557
+ resource.meta ??= {};
6558
+ resource.meta.versionId = String(newVersion);
6559
+ resource.meta.lastUpdated = new Date(now).toISOString();
6560
+ if (await this.#dbSTSResourceVersion.InsertResourceVersionEx(client, {
6561
+ PID: randomUUID$1(),
6562
+ PARTITION_ID: 0,
6563
+ PARTITION_DATE: 0,
6564
+ RES_ID,
6565
+ RES_TYPE,
6566
+ RES_VER: newVersion,
6567
+ OPERATION: "DELETE",
6568
+ RES: ""
6569
+ }) === void 0) {
6570
+ const errorMessage = `DeleteResource(): Version Conflict. resourceVersionRunResult is undefined. RES_VER: [${RES_VER}]`;
6571
+ this.#options.logger.error(errorMessage);
6572
+ throw new Error(errorMessage);
6573
+ }
6574
+ await this.UpdateIndexes(client, resource);
6575
+ if (useTransaction) await client.query("COMMIT");
6576
+ return resource;
6159
6577
  } catch (error) {
6160
- defaultLogger.error(`PGFhirAccessLayer:DeleteResource(): [${error}]`);
6578
+ if (useTransaction) await client.query("ROLLBACK");
6579
+ const errorMessage = `DeleteResource(): Error: [${error}]`;
6580
+ this.#options.logger.error(errorMessage);
6581
+ throw new Error(errorMessage);
6582
+ } finally {
6583
+ if (useTransaction) client.release();
6161
6584
  }
6162
6585
  };
6163
6586
  ReadResourceRecord = async (RES_TYPE, RES_ID, transactionHandle) => {
6164
- if (this.#poolManager) try {
6587
+ if (!this.#poolManager) {
6588
+ const errorMessage = `ReadResourceRecord(): poolManager not set`;
6589
+ this.#options.logger.error(errorMessage);
6590
+ throw new Error(errorMessage);
6591
+ }
6592
+ try {
6165
6593
  let client;
6166
6594
  let useTransaction;
6167
6595
  if (transactionHandle && this.#transactions[transactionHandle]) {
@@ -6173,19 +6601,19 @@ var PGFhirAccessLayer = class extends TinyEmitter {
6173
6601
  }
6174
6602
  try {
6175
6603
  return (await client.query(`
6176
- SELECT
6177
- r.*, v.* FROM stsresfhir r
6178
- JOIN
6179
- stsresfhirver v
6180
- ON
6181
- r.RES_ID = v.RES_ID AND
6182
- r.RES_TYPE = v.RES_TYPE AND
6183
- r.RES_VER = v.RES_VER
6184
- WHERE
6185
- r.RES_ID = $1 AND
6186
- r.RES_TYPE = $2 AND
6187
- r.RES_DELETED_AT IS NULL
6188
- `, [RES_ID, RES_TYPE])).rows[0];
6604
+ SELECT
6605
+ r.*, v.* FROM stsresfhir r
6606
+ JOIN
6607
+ stsresfhirver v
6608
+ ON
6609
+ r.RES_ID = v.RES_ID AND
6610
+ r.RES_TYPE = v.RES_TYPE AND
6611
+ r.RES_VER = v.RES_VER
6612
+ WHERE
6613
+ r.RES_ID = $1 AND
6614
+ r.RES_TYPE = $2 AND
6615
+ r.RES_DELETED_AT IS NULL
6616
+ `, [RES_ID, RES_TYPE])).rows[0];
6189
6617
  } catch (error) {
6190
6618
  defaultLogger.error(`DBSTSResource:ReadResourceRecord(): Query Error: [${error}]`);
6191
6619
  } finally {
@@ -6196,7 +6624,12 @@ var PGFhirAccessLayer = class extends TinyEmitter {
6196
6624
  }
6197
6625
  };
6198
6626
  ReadResourceRecordWithVersion = async (RES_TYPE, RES_ID, RES_VER, transactionHandle) => {
6199
- if (this.#poolManager) try {
6627
+ if (!this.#poolManager) {
6628
+ const errorMessage = `ReadResourceRecordWithVersion(): poolManager not set`;
6629
+ this.#options.logger.error(errorMessage);
6630
+ throw new Error(errorMessage);
6631
+ }
6632
+ try {
6200
6633
  let client;
6201
6634
  let useTransaction;
6202
6635
  if (transactionHandle && this.#transactions[transactionHandle]) {
@@ -6208,18 +6641,18 @@ var PGFhirAccessLayer = class extends TinyEmitter {
6208
6641
  }
6209
6642
  try {
6210
6643
  return (await client.query(`
6211
- SELECT
6212
- r.*, v.*, r.res_ver as R_res_ver, v.res_ver as V_res_ver FROM stsresfhir r
6213
- JOIN
6214
- stsresfhirver v
6215
- ON
6216
- r.RES_ID = v.RES_ID AND
6217
- r.RES_TYPE = v.RES_TYPE
6218
- WHERE
6219
- r.RES_ID = $1 AND
6220
- r.RES_TYPE = $2 AND
6221
- v.RES_VER = $3
6222
- `, [
6644
+ SELECT
6645
+ r.*, v.*, r.res_ver as R_res_ver, v.res_ver as V_res_ver FROM stsresfhir r
6646
+ JOIN
6647
+ stsresfhirver v
6648
+ ON
6649
+ r.RES_ID = v.RES_ID AND
6650
+ r.RES_TYPE = v.RES_TYPE
6651
+ WHERE
6652
+ r.RES_ID = $1 AND
6653
+ r.RES_TYPE = $2 AND
6654
+ v.RES_VER = $3
6655
+ `, [
6223
6656
  RES_ID,
6224
6657
  RES_TYPE,
6225
6658
  RES_VER
@@ -6234,7 +6667,12 @@ var PGFhirAccessLayer = class extends TinyEmitter {
6234
6667
  }
6235
6668
  };
6236
6669
  ReadResourceInstanceWithAllVersions = async (RES_TYPE, RES_ID, transactionHandle) => {
6237
- if (this.#poolManager) try {
6670
+ if (!this.#poolManager) {
6671
+ const errorMessage = `ReadResourceInstanceWithAllVersions(): poolManager not set`;
6672
+ this.#options.logger.error(errorMessage);
6673
+ throw new Error(errorMessage);
6674
+ }
6675
+ try {
6238
6676
  let client;
6239
6677
  let useTransaction;
6240
6678
  if (transactionHandle && this.#transactions[transactionHandle]) {
@@ -6246,19 +6684,19 @@ var PGFhirAccessLayer = class extends TinyEmitter {
6246
6684
  }
6247
6685
  try {
6248
6686
  return (await client.query(`
6249
- SELECT
6250
- r.*, v.*, r.res_ver as R_res_ver, v.res_ver as V_res_ver FROM stsresfhir r
6251
- JOIN
6252
- stsresfhirver v
6253
- ON
6254
- r.RES_ID = v.RES_ID AND
6255
- r.RES_TYPE = v.RES_TYPE
6256
- WHERE
6257
- r.RES_ID = $1 AND
6258
- r.RES_TYPE = $2
6259
- ORDER BY
6260
- v.RES_TYPE ASC, v.RES_ID ASC, v.RES_VER DESC
6261
- `, [RES_ID, RES_TYPE])).rows;
6687
+ SELECT
6688
+ r.*, v.*, r.res_ver as R_res_ver, v.res_ver as V_res_ver FROM stsresfhir r
6689
+ JOIN
6690
+ stsresfhirver v
6691
+ ON
6692
+ r.RES_ID = v.RES_ID AND
6693
+ r.RES_TYPE = v.RES_TYPE
6694
+ WHERE
6695
+ r.RES_ID = $1 AND
6696
+ r.RES_TYPE = $2
6697
+ ORDER BY
6698
+ v.RES_TYPE ASC, v.RES_ID ASC, v.RES_VER DESC
6699
+ `, [RES_ID, RES_TYPE])).rows;
6262
6700
  } catch (error) {
6263
6701
  defaultLogger.error(`DBSTSResource:ReadResourceRecord(): Query Error: [${error}]`);
6264
6702
  } finally {
@@ -6269,7 +6707,12 @@ var PGFhirAccessLayer = class extends TinyEmitter {
6269
6707
  }
6270
6708
  };
6271
6709
  ReadResourcesWithAllVersions = async (RES_TYPE, transactionHandle) => {
6272
- if (this.#poolManager) try {
6710
+ if (!this.#poolManager) {
6711
+ const errorMessage = `ReadResourcesWithAllVersions(): poolManager not set`;
6712
+ this.#options.logger.error(errorMessage);
6713
+ throw new Error(errorMessage);
6714
+ }
6715
+ try {
6273
6716
  let client;
6274
6717
  let useTransaction;
6275
6718
  if (transactionHandle && this.#transactions[transactionHandle]) {
@@ -6281,18 +6724,18 @@ var PGFhirAccessLayer = class extends TinyEmitter {
6281
6724
  }
6282
6725
  try {
6283
6726
  return (await client.query(`
6284
- SELECT
6285
- r.*, v.*, r.res_ver as R_res_ver, v.res_ver as V_res_ver FROM stsresfhir r
6286
- JOIN
6287
- stsresfhirver v
6288
- ON
6289
- r.RES_ID = v.RES_ID AND
6290
- r.RES_TYPE = v.RES_TYPE
6291
- WHERE
6292
- r.RES_TYPE = $1
6293
- ORDER BY
6294
- v.RES_TYPE ASC, v.RES_ID ASC, v.RES_VER DESC
6295
- `, [RES_TYPE])).rows;
6727
+ SELECT
6728
+ r.*, v.*, r.res_ver as R_res_ver, v.res_ver as V_res_ver FROM stsresfhir r
6729
+ JOIN
6730
+ stsresfhirver v
6731
+ ON
6732
+ r.RES_ID = v.RES_ID AND
6733
+ r.RES_TYPE = v.RES_TYPE
6734
+ WHERE
6735
+ r.RES_TYPE = $1
6736
+ ORDER BY
6737
+ v.RES_TYPE ASC, v.RES_ID ASC, v.RES_VER DESC
6738
+ `, [RES_TYPE])).rows;
6296
6739
  } catch (error) {
6297
6740
  defaultLogger.error(`DBSTSResource:ReadResourceRecord(): Query Error: [${error}]`);
6298
6741
  } finally {
@@ -6303,7 +6746,12 @@ var PGFhirAccessLayer = class extends TinyEmitter {
6303
6746
  }
6304
6747
  };
6305
6748
  ReadAllResourcesWithVersions = async (transactionHandle) => {
6306
- if (this.#poolManager) try {
6749
+ if (!this.#poolManager) {
6750
+ const errorMessage = `ReadAllResourcesWithVersions(): poolManager not set`;
6751
+ this.#options.logger.error(errorMessage);
6752
+ throw new Error(errorMessage);
6753
+ }
6754
+ try {
6307
6755
  let client;
6308
6756
  let useTransaction;
6309
6757
  if (transactionHandle && this.#transactions[transactionHandle]) {
@@ -6315,16 +6763,16 @@ var PGFhirAccessLayer = class extends TinyEmitter {
6315
6763
  }
6316
6764
  try {
6317
6765
  return (await client.query(`
6318
- SELECT
6319
- r.*, v.* FROM stsresfhir r
6320
- JOIN
6321
- stsresfhirver v
6322
- ON
6323
- r.RES_ID = v.RES_ID AND
6324
- r.RES_TYPE = v.RES_TYPE AND
6325
- ORDER BY
6326
- v.RES_TYPE ASC, v.RES_ID ASC, v.RES_VER DESC
6327
- `)).rows;
6766
+ SELECT
6767
+ r.*, v.* FROM stsresfhir r
6768
+ JOIN
6769
+ stsresfhirver v
6770
+ ON
6771
+ r.RES_ID = v.RES_ID AND
6772
+ r.RES_TYPE = v.RES_TYPE AND
6773
+ ORDER BY
6774
+ v.RES_TYPE ASC, v.RES_ID ASC, v.RES_VER DESC
6775
+ `)).rows;
6328
6776
  } catch (error) {
6329
6777
  defaultLogger.error(`DBSTSResource:ReadResourceRecord(): Query Error: [${error}]`);
6330
6778
  } finally {
@@ -6338,7 +6786,12 @@ var PGFhirAccessLayer = class extends TinyEmitter {
6338
6786
  return this.#dbSTSResourceVersion.ReadAllResourceVersionRecords();
6339
6787
  };
6340
6788
  ReadResourceIndexes = async (resource, transactionHandle) => {
6341
- if (this.#poolManager) try {
6789
+ if (!this.#poolManager) {
6790
+ const errorMessage = `ReadResourceIndexes(): poolManager not set`;
6791
+ this.#options.logger.error(errorMessage);
6792
+ throw new Error(errorMessage);
6793
+ }
6794
+ try {
6342
6795
  const resultSet = {
6343
6796
  "stsresfhirlink": [],
6344
6797
  "stsresfhirstring": [],
@@ -6378,7 +6831,12 @@ var PGFhirAccessLayer = class extends TinyEmitter {
6378
6831
  }
6379
6832
  };
6380
6833
  ExecuteReadQuery = async (queryData, transactionHandle) => {
6381
- if (this.#poolManager) try {
6834
+ if (!this.#poolManager) {
6835
+ const errorMessage = `ExecuteReadQuery(): poolManager not set`;
6836
+ this.#options.logger.error(errorMessage);
6837
+ throw new Error(errorMessage);
6838
+ }
6839
+ try {
6382
6840
  let client;
6383
6841
  let useTransaction;
6384
6842
  if (transactionHandle && this.#transactions[transactionHandle]) {
@@ -6401,7 +6859,12 @@ var PGFhirAccessLayer = class extends TinyEmitter {
6401
6859
  }
6402
6860
  };
6403
6861
  TruncateAll = async () => {
6404
- if (this.#poolManager) try {
6862
+ if (!this.#poolManager) {
6863
+ const errorMessage = `TruncateAll(): poolManager not set`;
6864
+ this.#options.logger.error(errorMessage);
6865
+ throw new Error(errorMessage);
6866
+ }
6867
+ try {
6405
6868
  let client;
6406
6869
  client = await this.#poolManager.connectReadWrite();
6407
6870
  try {