@nsshunt/stsfhirpg 1.2.12 → 1.2.13

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.
@@ -7130,7 +7130,7 @@ class SearchParameterManager {
7130
7130
  constructor(options) {
7131
7131
  this.options = options;
7132
7132
  }
7133
- EnsureSearchParameterDataLoaded = async () => {
7133
+ EnsureSearchParameterDataLoaded = async (resources) => {
7134
7134
  if (this.alreadyComplete) {
7135
7135
  return this.alreadyComplete;
7136
7136
  }
@@ -7186,7 +7186,7 @@ class SearchParameterManager {
7186
7186
  return;
7187
7187
  }
7188
7188
  try {
7189
- await this.#LoadDefinitions();
7189
+ await this.#LoadDefinitions(resources);
7190
7190
  } catch (error) {
7191
7191
  console.error(error);
7192
7192
  throw error;
@@ -7234,14 +7234,69 @@ class SearchParameterManager {
7234
7234
  console.log(`SearchParameterManager(): redis closed`);
7235
7235
  }
7236
7236
  };
7237
- #LoadDefinitions = async () => {
7237
+ /*
7238
+ private GetTypeKey(typeName: string) {
7239
+ return `stsfhir_type_${typeName}`;
7240
+ }
7241
+
7242
+ private GetSearchParameterByFullUrlKey(fullUrl: string) {
7243
+ return `stsfhir_sp_${fullUrl}`;
7244
+ }
7245
+
7246
+ private GetResourceKey(resourceType: string) {
7247
+ return `stsfhir_resource_${resourceType}`;
7248
+ }
7249
+
7250
+ private GetSearchParameterByResourceTypeKey(resourceType: string) {
7251
+ return `stsfhir_sp_resource_${resourceType}`;
7252
+ }
7253
+
7254
+ private GetSTSCustomSearchParameterByResourceTypeKey(resourceType: string) {
7255
+ return `stsfhir_stscustom_sp_resource_${resourceType}`;
7256
+ }
7257
+ */
7258
+ #LoadDefinitions = async (resources) => {
7238
7259
  console.log("Data Load Starting ...");
7239
- for (let i = 0; i < 10; i++) {
7240
- console.log(`Loading ...: [${i}]`);
7241
- await stsutils.Sleep(500);
7260
+ for (const [key, value] of Object.entries(resources.searchParametersByResourceType)) {
7261
+ await this.redis.hSet(`__stsfhir__searchParametersByResourceType`, key, JSON.stringify(value));
7262
+ }
7263
+ for (const [key, value] of Object.entries(resources.searchParametersByUrl)) {
7264
+ await this.redis.hSet(`__stsfhir__searchParametersByUrl`, key, JSON.stringify(value));
7265
+ }
7266
+ for (const [key, value] of Object.entries(resources.resources)) {
7267
+ await this.redis.hSet(`__stsfhir__resources`, key, JSON.stringify(value));
7268
+ }
7269
+ for (const [key, value] of Object.entries(resources.types)) {
7270
+ await this.redis.hSet(`__stsfhir__types`, key, JSON.stringify(value));
7242
7271
  }
7243
7272
  console.log("All Done ***********************************************************************************");
7244
7273
  };
7274
+ GetSearchParamFromResourceType = async (resourceType) => {
7275
+ const retVal = await this.redis.hGet(`__stsfhir__searchParametersByResourceType`, resourceType);
7276
+ return JSON.parse(retVal);
7277
+ };
7278
+ GetType = async (typeName) => {
7279
+ const retVal = await this.redis.hGet(`__stsfhir__types`, typeName);
7280
+ return JSON.parse(retVal);
7281
+ };
7282
+ GetResource = async (resourceType) => {
7283
+ const retVal = await this.redis.hGet(`__stsfhir__resources`, resourceType);
7284
+ return JSON.parse(retVal);
7285
+ };
7286
+ GetSearchParam = async (url) => {
7287
+ const retVal = await this.redis.hGet(`__stsfhir__searchParametersByUrl`, url);
7288
+ return JSON.parse(retVal);
7289
+ };
7290
+ /*
7291
+ GetSearchParams = async (): Promise<SearchParameter[]> => {
7292
+ const retVal = await this.redis!.hGetAll(`__stsfhir__searchParametersByUrl`);
7293
+ const searchParameters: SearchParameter[] = [ ];
7294
+ for (const [key, value] of Object.entries(retVal)) {
7295
+ searchParameters.push(JSON.parse(value));
7296
+ }
7297
+ return searchParameters;
7298
+ }
7299
+ */
7245
7300
  /*
7246
7301
  private GetTypeKey(typeName: string) {
7247
7302
  return `stsfhir_type_${typeName}`;
@@ -7632,6 +7687,7 @@ const typesPath = "fhir-spec/profiles-types.json";
7632
7687
  const searchParamsPath = "fhir-spec/search-parameters.json";
7633
7688
  class ResourceHelper {
7634
7689
  #definitions;
7690
+ #loaded = false;
7635
7691
  searchParameterManager;
7636
7692
  static instance;
7637
7693
  constructor() {
@@ -7684,7 +7740,8 @@ class ResourceHelper {
7684
7740
  });
7685
7741
  await this._LoadSearchParameters();
7686
7742
  await this.PreLoadSearchParameterData();
7687
- return this.#definitions;
7743
+ this.#loaded = true;
7744
+ this.#definitions = void 0;
7688
7745
  };
7689
7746
  PreLoadSearchParameterData = async () => {
7690
7747
  console.log(`PreLoadSearchParameterData(): Start ...`);
@@ -7695,25 +7752,22 @@ class ResourceHelper {
7695
7752
  autoRenew: true,
7696
7753
  heartbeatMs: 1e4
7697
7754
  });
7698
- await this.searchParameterManager.EnsureSearchParameterDataLoaded();
7755
+ await this.searchParameterManager.EnsureSearchParameterDataLoaded(this.#definitions);
7699
7756
  console.log(`PreLoadSearchParameterData(): End`);
7700
7757
  };
7701
7758
  GetDefinitions = async () => {
7702
- if (!this.#definitions) {
7703
- await this.#LoadDefinitions();
7759
+ if (!this.#loaded) {
7760
+ if (!this.#definitions) {
7761
+ await this.#LoadDefinitions();
7762
+ }
7704
7763
  }
7705
- return this.#definitions;
7706
7764
  };
7707
- GetType = async (typeName) => {
7708
- await this.GetDefinitions();
7709
- return this.#definitions.types[typeName];
7710
- };
7711
- GetResource = async (resourceType) => {
7765
+ _GetResource = async (resourceType) => {
7712
7766
  await this.GetDefinitions();
7713
7767
  return this.#definitions.resources[resourceType];
7714
7768
  };
7715
- GetResourceField = async (resourceType, fieldPath) => {
7716
- const resource = await this.GetResource(resourceType);
7769
+ _GetResourceField = async (resourceType, fieldPath) => {
7770
+ const resource = await this._GetResource(resourceType);
7717
7771
  if (resource) {
7718
7772
  const foundRecord = resource.filter((o) => o.id === fieldPath);
7719
7773
  if (foundRecord.length > 0) {
@@ -7722,18 +7776,53 @@ class ResourceHelper {
7722
7776
  return void 0;
7723
7777
  }
7724
7778
  };
7725
- GetSearchParam = async (url) => {
7779
+ _GetSearchParam = async (url) => {
7726
7780
  await this.GetDefinitions();
7727
7781
  return this.#definitions.searchParametersByUrl[url];
7728
7782
  };
7729
- GetSearchParams = async () => {
7783
+ _GetSearchParams = async () => {
7730
7784
  await this.GetDefinitions();
7731
7785
  return this.#definitions.searchParametersByUrl;
7732
7786
  };
7733
- GetSearchParamsByResource = async (resource) => {
7787
+ GetType = async (typeName) => {
7788
+ await this.GetDefinitions();
7789
+ return await this.searchParameterManager.GetType(typeName);
7790
+ };
7791
+ GetResource = async (resourceType) => {
7734
7792
  await this.GetDefinitions();
7735
- return Object.values(this.#definitions.searchParametersByUrl).filter((sp) => sp.base.includes(resource)).map((sp) => sp);
7793
+ return await this.searchParameterManager.GetResource(resourceType);
7736
7794
  };
7795
+ GetResourceField = async (resourceType, fieldPath) => {
7796
+ const resource = await this.GetResource(resourceType);
7797
+ if (resource) {
7798
+ const foundRecord = resource.filter((o) => o.id === fieldPath);
7799
+ if (foundRecord.length > 0) {
7800
+ return foundRecord[0];
7801
+ }
7802
+ return void 0;
7803
+ }
7804
+ };
7805
+ GetSearchParam = async (url) => {
7806
+ await this.GetDefinitions();
7807
+ return await this.searchParameterManager.GetSearchParam(url);
7808
+ };
7809
+ /*
7810
+ private GetSearchParams = async (): Promise<SearchParameter[]> => {
7811
+ await this.GetDefinitions();
7812
+ return await this.searchParameterManager!.GetSearchParams();
7813
+ }
7814
+
7815
+ GetSearchParamsByResource = async (resource: string): Promise<SearchParameter[]> => {
7816
+ await this.GetDefinitions();
7817
+ const searchParams = await this.GetSearchParams();
7818
+ return searchParams
7819
+ .filter(sp => sp.base.includes(resource))
7820
+ .map(sp => sp)
7821
+ //return Object.values(this.#definitions!.searchParametersByUrl)
7822
+ //.filter(sp => sp.base.includes(resource))
7823
+ //.map(sp => sp)
7824
+ }
7825
+ */
7737
7826
  // ------------------------------------------------------------------------------------------------------------------
7738
7827
  // Remove ( ) when either are present
7739
7828
  #RemoveOuterParentheses = (input) => {
@@ -7856,7 +7945,7 @@ class ResourceHelper {
7856
7945
  };
7857
7946
  };
7858
7947
  _LoadSearchParameters = async () => {
7859
- for (const [key, val] of Object.entries(await this.GetSearchParams())) {
7948
+ for (const [key, val] of Object.entries(await this._GetSearchParams())) {
7860
7949
  const { id, url, code, base, type, expression, component, target } = val;
7861
7950
  for (let i = 0; i < base.length; i++) {
7862
7951
  const resourceName = base[i];
@@ -7887,10 +7976,10 @@ class ResourceHelper {
7887
7976
  SP_TARGET,
7888
7977
  expressions,
7889
7978
  original_expressions,
7890
- SP_DEFINITION: await this.GetSearchParam(SP_URL)
7979
+ SP_DEFINITION: await this._GetSearchParam(SP_URL)
7891
7980
  };
7892
7981
  for (let i2 = 0; i2 < record.expressions.length; i2++) {
7893
- const rf = await this.GetResourceField(resourceName, record.expressions[i2].path);
7982
+ const rf = await this._GetResourceField(resourceName, record.expressions[i2].path);
7894
7983
  if (rf) {
7895
7984
  expressions[i2].RES_FIELD = rf;
7896
7985
  }
@@ -7901,7 +7990,7 @@ class ResourceHelper {
7901
7990
  const retVal = this.ProcessExpressions("", c.expression);
7902
7991
  c.expressions = retVal.expressions;
7903
7992
  c.original_expressions = retVal.original_expressions;
7904
- const def = await this.GetSearchParam(c.definition);
7993
+ const def = await this._GetSearchParam(c.definition);
7905
7994
  if (def && def.type) {
7906
7995
  c.type = def.type;
7907
7996
  }
@@ -7913,21 +8002,24 @@ class ResourceHelper {
7913
8002
  };
7914
8003
  GetSearchParamFromResourceTypeUrl = async (resourceType, url) => {
7915
8004
  await this.GetDefinitions();
7916
- const filterByNameAndUrl = this.#definitions.searchParametersByResourceType[resourceType].params.filter((rt) => rt.SP_URL.localeCompare(url) === 0);
8005
+ const rt = await this.searchParameterManager?.GetSearchParamFromResourceType(resourceType);
8006
+ const filterByNameAndUrl = rt.params.filter((rt2) => rt2.SP_URL.localeCompare(url) === 0);
7917
8007
  if (filterByNameAndUrl.length > 0) {
7918
8008
  return filterByNameAndUrl[0];
7919
8009
  }
7920
8010
  };
7921
8011
  GetSearchParamFromResourceType = async (resourceType, name) => {
7922
8012
  await this.GetDefinitions();
7923
- const filterByName = this.#definitions.searchParametersByResourceType[resourceType].params.filter((rt) => rt.SP_NAME.localeCompare(name) === 0);
8013
+ const rt = await this.searchParameterManager?.GetSearchParamFromResourceType(resourceType);
8014
+ const filterByName = rt.params.filter((rt2) => rt2.SP_NAME.localeCompare(name) === 0);
7924
8015
  if (filterByName.length > 0) {
7925
8016
  return filterByName[0];
7926
8017
  }
7927
8018
  };
7928
8019
  GetSearchParamsFromResourceType = async (resourceType) => {
7929
8020
  await this.GetDefinitions();
7930
- return this.#definitions.searchParametersByResourceType[resourceType].params;
8021
+ const rt = await this.searchParameterManager?.GetSearchParamFromResourceType(resourceType);
8022
+ return rt.params;
7931
8023
  };
7932
8024
  }
7933
8025
  var ansiStyles = { exports: {} };