@nsshunt/stsfhirpg 1.2.11 → 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() {
@@ -7683,7 +7739,9 @@ class ResourceHelper {
7683
7739
  this.#definitions.searchParametersByUrl[entry.fullUrl] = entry.resource;
7684
7740
  });
7685
7741
  await this._LoadSearchParameters();
7686
- return this.#definitions;
7742
+ await this.PreLoadSearchParameterData();
7743
+ this.#loaded = true;
7744
+ this.#definitions = void 0;
7687
7745
  };
7688
7746
  PreLoadSearchParameterData = async () => {
7689
7747
  console.log(`PreLoadSearchParameterData(): Start ...`);
@@ -7694,25 +7752,22 @@ class ResourceHelper {
7694
7752
  autoRenew: true,
7695
7753
  heartbeatMs: 1e4
7696
7754
  });
7697
- await this.searchParameterManager.EnsureSearchParameterDataLoaded();
7755
+ await this.searchParameterManager.EnsureSearchParameterDataLoaded(this.#definitions);
7698
7756
  console.log(`PreLoadSearchParameterData(): End`);
7699
7757
  };
7700
7758
  GetDefinitions = async () => {
7701
- if (!this.#definitions) {
7702
- await this.#LoadDefinitions();
7759
+ if (!this.#loaded) {
7760
+ if (!this.#definitions) {
7761
+ await this.#LoadDefinitions();
7762
+ }
7703
7763
  }
7704
- return this.#definitions;
7705
7764
  };
7706
- GetType = async (typeName) => {
7707
- await this.GetDefinitions();
7708
- return this.#definitions.types[typeName];
7709
- };
7710
- GetResource = async (resourceType) => {
7765
+ _GetResource = async (resourceType) => {
7711
7766
  await this.GetDefinitions();
7712
7767
  return this.#definitions.resources[resourceType];
7713
7768
  };
7714
- GetResourceField = async (resourceType, fieldPath) => {
7715
- const resource = await this.GetResource(resourceType);
7769
+ _GetResourceField = async (resourceType, fieldPath) => {
7770
+ const resource = await this._GetResource(resourceType);
7716
7771
  if (resource) {
7717
7772
  const foundRecord = resource.filter((o) => o.id === fieldPath);
7718
7773
  if (foundRecord.length > 0) {
@@ -7721,18 +7776,53 @@ class ResourceHelper {
7721
7776
  return void 0;
7722
7777
  }
7723
7778
  };
7724
- GetSearchParam = async (url) => {
7779
+ _GetSearchParam = async (url) => {
7725
7780
  await this.GetDefinitions();
7726
7781
  return this.#definitions.searchParametersByUrl[url];
7727
7782
  };
7728
- GetSearchParams = async () => {
7783
+ _GetSearchParams = async () => {
7729
7784
  await this.GetDefinitions();
7730
7785
  return this.#definitions.searchParametersByUrl;
7731
7786
  };
7732
- GetSearchParamsByResource = async (resource) => {
7787
+ GetType = async (typeName) => {
7788
+ await this.GetDefinitions();
7789
+ return await this.searchParameterManager.GetType(typeName);
7790
+ };
7791
+ GetResource = async (resourceType) => {
7733
7792
  await this.GetDefinitions();
7734
- return Object.values(this.#definitions.searchParametersByUrl).filter((sp) => sp.base.includes(resource)).map((sp) => sp);
7793
+ return await this.searchParameterManager.GetResource(resourceType);
7735
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
+ */
7736
7826
  // ------------------------------------------------------------------------------------------------------------------
7737
7827
  // Remove ( ) when either are present
7738
7828
  #RemoveOuterParentheses = (input) => {
@@ -7855,7 +7945,7 @@ class ResourceHelper {
7855
7945
  };
7856
7946
  };
7857
7947
  _LoadSearchParameters = async () => {
7858
- for (const [key, val] of Object.entries(await this.GetSearchParams())) {
7948
+ for (const [key, val] of Object.entries(await this._GetSearchParams())) {
7859
7949
  const { id, url, code, base, type, expression, component, target } = val;
7860
7950
  for (let i = 0; i < base.length; i++) {
7861
7951
  const resourceName = base[i];
@@ -7886,10 +7976,10 @@ class ResourceHelper {
7886
7976
  SP_TARGET,
7887
7977
  expressions,
7888
7978
  original_expressions,
7889
- SP_DEFINITION: await this.GetSearchParam(SP_URL)
7979
+ SP_DEFINITION: await this._GetSearchParam(SP_URL)
7890
7980
  };
7891
7981
  for (let i2 = 0; i2 < record.expressions.length; i2++) {
7892
- const rf = await this.GetResourceField(resourceName, record.expressions[i2].path);
7982
+ const rf = await this._GetResourceField(resourceName, record.expressions[i2].path);
7893
7983
  if (rf) {
7894
7984
  expressions[i2].RES_FIELD = rf;
7895
7985
  }
@@ -7900,7 +7990,7 @@ class ResourceHelper {
7900
7990
  const retVal = this.ProcessExpressions("", c.expression);
7901
7991
  c.expressions = retVal.expressions;
7902
7992
  c.original_expressions = retVal.original_expressions;
7903
- const def = await this.GetSearchParam(c.definition);
7993
+ const def = await this._GetSearchParam(c.definition);
7904
7994
  if (def && def.type) {
7905
7995
  c.type = def.type;
7906
7996
  }
@@ -7912,21 +8002,24 @@ class ResourceHelper {
7912
8002
  };
7913
8003
  GetSearchParamFromResourceTypeUrl = async (resourceType, url) => {
7914
8004
  await this.GetDefinitions();
7915
- 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);
7916
8007
  if (filterByNameAndUrl.length > 0) {
7917
8008
  return filterByNameAndUrl[0];
7918
8009
  }
7919
8010
  };
7920
8011
  GetSearchParamFromResourceType = async (resourceType, name) => {
7921
8012
  await this.GetDefinitions();
7922
- 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);
7923
8015
  if (filterByName.length > 0) {
7924
8016
  return filterByName[0];
7925
8017
  }
7926
8018
  };
7927
8019
  GetSearchParamsFromResourceType = async (resourceType) => {
7928
8020
  await this.GetDefinitions();
7929
- return this.#definitions.searchParametersByResourceType[resourceType].params;
8021
+ const rt = await this.searchParameterManager?.GetSearchParamFromResourceType(resourceType);
8022
+ return rt.params;
7930
8023
  };
7931
8024
  }
7932
8025
  var ansiStyles = { exports: {} };