@nsshunt/stsfhirpg 1.2.12 → 1.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/stsfhirpg.cjs +115 -411
- package/dist/stsfhirpg.cjs.map +1 -1
- package/dist/stsfhirpg.mjs +115 -411
- package/dist/stsfhirpg.mjs.map +1 -1
- package/package.json +1 -1
- package/types/fhir-utils/resourceHelper.d.ts +4 -2
- package/types/fhir-utils/resourceHelper.d.ts.map +1 -1
- package/types/searchParameterManager.d.ts +9 -1
- package/types/searchParameterManager.d.ts.map +1 -1
package/dist/stsfhirpg.mjs
CHANGED
|
@@ -7125,10 +7125,11 @@ class SearchParameterManager {
|
|
|
7125
7125
|
redis;
|
|
7126
7126
|
alreadyComplete = null;
|
|
7127
7127
|
options;
|
|
7128
|
+
cache = {};
|
|
7128
7129
|
constructor(options) {
|
|
7129
7130
|
this.options = options;
|
|
7130
7131
|
}
|
|
7131
|
-
EnsureSearchParameterDataLoaded = async () => {
|
|
7132
|
+
EnsureSearchParameterDataLoaded = async (resources) => {
|
|
7132
7133
|
if (this.alreadyComplete) {
|
|
7133
7134
|
return this.alreadyComplete;
|
|
7134
7135
|
}
|
|
@@ -7184,7 +7185,7 @@ class SearchParameterManager {
|
|
|
7184
7185
|
return;
|
|
7185
7186
|
}
|
|
7186
7187
|
try {
|
|
7187
|
-
await this.#LoadDefinitions();
|
|
7188
|
+
await this.#LoadDefinitions(resources);
|
|
7188
7189
|
} catch (error) {
|
|
7189
7190
|
console.error(error);
|
|
7190
7191
|
throw error;
|
|
@@ -7232,396 +7233,62 @@ class SearchParameterManager {
|
|
|
7232
7233
|
console.log(`SearchParameterManager(): redis closed`);
|
|
7233
7234
|
}
|
|
7234
7235
|
};
|
|
7235
|
-
#
|
|
7236
|
+
#searchParametersByResourceTypeKey = `__stsfhir__searchParametersByResourceType`;
|
|
7237
|
+
#searchParametersByUrlKey = `__stsfhir__searchParametersByUrl`;
|
|
7238
|
+
#resourcesKey = `__stsfhir__resources`;
|
|
7239
|
+
#typesKey = `__stsfhir__types`;
|
|
7240
|
+
#LoadDefinitions = async (resources) => {
|
|
7236
7241
|
console.log("Data Load Starting ...");
|
|
7237
|
-
for (
|
|
7238
|
-
|
|
7239
|
-
|
|
7242
|
+
for (const [key, value] of Object.entries(resources.searchParametersByResourceType)) {
|
|
7243
|
+
await this.redis.hSet(this.#searchParametersByResourceTypeKey, key, JSON.stringify(value));
|
|
7244
|
+
}
|
|
7245
|
+
for (const [key, value] of Object.entries(resources.searchParametersByUrl)) {
|
|
7246
|
+
await this.redis.hSet(this.#searchParametersByUrlKey, key, JSON.stringify(value));
|
|
7247
|
+
}
|
|
7248
|
+
for (const [key, value] of Object.entries(resources.resources)) {
|
|
7249
|
+
await this.redis.hSet(this.#resourcesKey, key, JSON.stringify(value));
|
|
7250
|
+
}
|
|
7251
|
+
for (const [key, value] of Object.entries(resources.types)) {
|
|
7252
|
+
await this.redis.hSet(this.#typesKey, key, JSON.stringify(value));
|
|
7240
7253
|
}
|
|
7241
7254
|
console.log("All Done ***********************************************************************************");
|
|
7242
7255
|
};
|
|
7243
|
-
|
|
7244
|
-
|
|
7245
|
-
|
|
7246
|
-
|
|
7247
|
-
|
|
7248
|
-
|
|
7249
|
-
|
|
7250
|
-
|
|
7251
|
-
|
|
7252
|
-
|
|
7253
|
-
|
|
7254
|
-
|
|
7255
|
-
|
|
7256
|
-
|
|
7257
|
-
|
|
7258
|
-
|
|
7259
|
-
|
|
7260
|
-
|
|
7261
|
-
|
|
7262
|
-
|
|
7263
|
-
|
|
7264
|
-
|
|
7265
|
-
|
|
7266
|
-
|
|
7267
|
-
|
|
7268
|
-
|
|
7269
|
-
|
|
7270
|
-
|
|
7271
|
-
|
|
7272
|
-
|
|
7273
|
-
|
|
7274
|
-
|
|
7275
|
-
|
|
7276
|
-
|
|
7277
|
-
|
|
7278
|
-
|
|
7279
|
-
ClinicalUseDefinition product reference ClinicalUseDefinition.subject.where(resolve() is MedicinalProductDefinition)
|
|
7280
|
-
|
|
7281
|
-
OrganizationAffiliation email token OrganizationAffiliation.contact.telecom.where(system='email')
|
|
7282
|
-
OrganizationAffiliation phone token OrganizationAffiliation.contact.telecom.where(system='phone')
|
|
7283
|
-
|
|
7284
|
-
PackagedProductDefinition biological reference PackagedProductDefinition.packaging.containedItem.item.reference
|
|
7285
|
-
PackagedProductDefinition contained-item reference PackagedProductDefinition.packaging.containedItem.item.reference
|
|
7286
|
-
|
|
7287
|
-
Patient deceased token Patient.deceased.exists() and Patient.deceased != false
|
|
7288
|
-
Practitioner deceased token Practitioner.deceased.exists() and Practitioner.deceased != false
|
|
7289
|
-
|
|
7290
|
-
Location contains special Location.extension('http://hl7.org/fhir/StructureDefinition/location-boundary-geojson').value
|
|
7291
|
-
|
|
7292
|
-
QuestionnaireResponse item-subject reference QuestionnaireResponse.item.where(extension('http://hl7.org/fhir/StructureDefinition/questionnaireresponse-isSubject').exists()).answer.valueReference
|
|
7293
|
-
*/
|
|
7294
|
-
/*
|
|
7295
|
-
private _ProcessExpressions = (resourceName: string, SP_EXPRESSION: string): any => {
|
|
7296
|
-
let expressions: any[] = [];
|
|
7297
|
-
|
|
7298
|
-
//SP_EXPRESSION = this.#RemoveSurroundingParentheses(val2.expression);
|
|
7299
|
-
expressions = SP_EXPRESSION.split('|').map(e => e.trim());
|
|
7300
|
-
|
|
7301
|
-
expressions = expressions.map(e => this._RemoveSurroundingParentheses(e).trim());
|
|
7302
|
-
|
|
7303
|
-
if (resourceName !== '') {
|
|
7304
|
-
expressions = expressions.filter(e => e.split('.')[0].trim().localeCompare(resourceName) === 0);
|
|
7305
|
-
}
|
|
7306
|
-
|
|
7307
|
-
let original_expressions = [ ...expressions ];
|
|
7308
|
-
|
|
7309
|
-
// ofType processing
|
|
7310
|
-
expressions = expressions.map((e: string) => {
|
|
7311
|
-
let capturedTypeOf = undefined;
|
|
7312
|
-
return {
|
|
7313
|
-
path: e.replace(
|
|
7314
|
-
/\.ofType\(([^)]+)\)/g,
|
|
7315
|
-
(_: string, typeName: string) => {
|
|
7316
|
-
capturedTypeOf = true;
|
|
7317
|
-
return typeName.charAt(0).toUpperCase() + typeName.slice(1)
|
|
7318
|
-
}),
|
|
7319
|
-
typeOf: capturedTypeOf
|
|
7320
|
-
}
|
|
7321
|
-
});
|
|
7322
|
-
|
|
7323
|
-
//@@ exists processing here is more or less hard coded to the deceased attribute.
|
|
7324
|
-
//@@ in future, we need an actual fhir language parser.
|
|
7325
|
-
expressions.forEach(expression => {
|
|
7326
|
-
try {
|
|
7327
|
-
const sp = expression as ISearchParamExpressionRecord;
|
|
7328
|
-
if (sp.path.indexOf('exists()') >= 0) {
|
|
7329
|
-
// Person.deceased.exists() and Person.deceased != false
|
|
7330
|
-
const parts = sp.path.split(' ');
|
|
7331
|
-
const i = parts[0].indexOf('exists()');
|
|
7332
|
-
if (i >= 0) {
|
|
7333
|
-
let fieldExistsEx = parts[0].substring(0, i-1);
|
|
7334
|
-
let op = parts[1];
|
|
7335
|
-
let fieldTestEx = parts[2];
|
|
7336
|
-
let comparator = parts[3];
|
|
7337
|
-
let value = parts[4];
|
|
7338
|
-
|
|
7339
|
-
const fieldExistsParts = fieldExistsEx.split('.');
|
|
7340
|
-
let fieldExists = fieldExistsParts.slice(1).join('.');
|
|
7341
|
-
|
|
7342
|
-
const fieldTestParts = fieldTestEx.split('.');
|
|
7343
|
-
let fieldTest = fieldTestParts.slice(1).join('.');
|
|
7344
|
-
|
|
7345
|
-
sp.exists = {
|
|
7346
|
-
fieldExists: [ `${fieldExists}Boolean`, `${fieldExists}DataTime` ], // [x]Boolean or [x]DateTime
|
|
7347
|
-
op,
|
|
7348
|
-
fieldTest: [ `${fieldTest}Boolean`, `${fieldTest}DataTime` ],
|
|
7349
|
-
comparator,
|
|
7350
|
-
value: [ value, undefined ]
|
|
7351
|
-
}
|
|
7352
|
-
}
|
|
7353
|
-
}
|
|
7354
|
-
} catch (error) {
|
|
7355
|
-
|
|
7356
|
-
}
|
|
7357
|
-
});
|
|
7358
|
-
|
|
7359
|
-
// where(resolve()) processing
|
|
7360
|
-
let capturedType: string | undefined;
|
|
7361
|
-
expressions = expressions.map((obj: any) => {
|
|
7362
|
-
capturedType = undefined;
|
|
7363
|
-
const { path, typeOf, exists } = obj;
|
|
7364
|
-
return {
|
|
7365
|
-
path: path.replace(
|
|
7366
|
-
/\.where\(resolve\(\)\s+is\s+([^)]+)\)/,
|
|
7367
|
-
(_: string, typeName: string) => {
|
|
7368
|
-
capturedType = typeName;
|
|
7369
|
-
//return ` // reference = ${capturedType}`; // remove the .where(...) part (you can put ` // ${capturedType}` if you want to keep a comment)
|
|
7370
|
-
return '';
|
|
7371
|
-
}),
|
|
7372
|
-
typeOf,
|
|
7373
|
-
reference: capturedType,
|
|
7374
|
-
exists
|
|
7375
|
-
}
|
|
7376
|
-
});
|
|
7377
|
-
|
|
7378
|
-
// .where processing
|
|
7379
|
-
// The element before the .where will be an array. So this test checks which element(s) from that array are satisifed.
|
|
7380
|
-
let capturedWhere: any = undefined;
|
|
7381
|
-
expressions = expressions.map((obj: any) => {
|
|
7382
|
-
capturedWhere = undefined;
|
|
7383
|
-
const { path, reference, typeOf, exists } = obj;
|
|
7384
|
-
const retVal: any = {
|
|
7385
|
-
path: path.replace(/([^.]+)\.where\(([^=]+)='([^']+)'\)/g, (_: string, field: string, subfield: string, value: string) => {
|
|
7386
|
-
capturedWhere = { field, subfield, value }
|
|
7387
|
-
return field;
|
|
7388
|
-
}),
|
|
7389
|
-
typeOf,
|
|
7390
|
-
reference,
|
|
7391
|
-
exists
|
|
7392
|
-
}
|
|
7393
|
-
if (capturedWhere) {
|
|
7394
|
-
capturedWhere.full = `${capturedWhere.field}[*].${capturedWhere.subfield}=${capturedWhere.value}`;
|
|
7395
|
-
retVal.where = capturedWhere;
|
|
7396
|
-
}
|
|
7397
|
-
return retVal;
|
|
7398
|
-
});
|
|
7399
|
-
|
|
7400
|
-
|
|
7401
|
-
return {
|
|
7402
|
-
expressions,
|
|
7403
|
-
original_expressions
|
|
7404
|
-
};
|
|
7405
|
-
}
|
|
7406
|
-
|
|
7407
|
-
#LoadDefinitions = async (): Promise<void> => {
|
|
7408
|
-
try {
|
|
7409
|
-
let usePath = '';
|
|
7410
|
-
if (fs.existsSync(`${specPath1}${resourcesPath}`)) {
|
|
7411
|
-
usePath = specPath1;
|
|
7412
|
-
} else {
|
|
7413
|
-
usePath = specPath2;
|
|
7414
|
-
}
|
|
7415
|
-
const __resources: any = JSON.parse(fs.readFileSync(`${usePath}${resourcesPath}`, 'utf-8'));
|
|
7416
|
-
const __types: any = JSON.parse(fs.readFileSync(`${usePath}${typesPath}`, 'utf-8'));
|
|
7417
|
-
const __searchParams: any = JSON.parse(fs.readFileSync(`${usePath}${searchParamsPath}`, 'utf-8'));
|
|
7418
|
-
|
|
7419
|
-
for (let i=0; i < (__resources.entry as any[]).length; i++) {
|
|
7420
|
-
const entry = __resources.entry[i];
|
|
7421
|
-
const resource: any = entry.resource;
|
|
7422
|
-
if (resource?.snapshot?.element) {
|
|
7423
|
-
const rt = resource.type as string;
|
|
7424
|
-
await this.redis!.set(this.GetResourceKey(rt), JSON.stringify(resource.snapshot.element));
|
|
7425
|
-
}
|
|
7426
|
-
};
|
|
7427
|
-
|
|
7428
|
-
for (let i=0; i < (__types.entry as any[]).length; i++) {
|
|
7429
|
-
const entry = __types.entry[i];
|
|
7430
|
-
const type = entry.resource;
|
|
7431
|
-
if (type?.snapshot?.element) {
|
|
7432
|
-
await this.redis!.set(this.GetTypeKey(type.type), JSON.stringify(type.snapshot.element));
|
|
7433
|
-
}
|
|
7434
|
-
};
|
|
7435
|
-
|
|
7436
|
-
for (let i=0; i < (__searchParams.entry as any[]).length; i++) {
|
|
7437
|
-
const entry = __searchParams.entry[i];
|
|
7438
|
-
await this.redis!.set(this.GetSearchParameterByFullUrlKey(entry.fullUrl), JSON.stringify(entry.resource));
|
|
7439
|
-
const { code, base } = entry.resource;
|
|
7440
|
-
if (base) {
|
|
7441
|
-
for (let j=0; j < base.length; j++) {
|
|
7442
|
-
const resourceType = base[j];
|
|
7443
|
-
await this.redis!.hSet(this.GetSearchParameterByResourceTypeKey(resourceType), code, JSON.stringify(entry.resource));
|
|
7444
|
-
}
|
|
7445
|
-
}
|
|
7446
|
-
};
|
|
7447
|
-
|
|
7448
|
-
//await this.#LoadDefinitionsPass2(__searchParams);
|
|
7449
|
-
|
|
7450
|
-
console.log(`All completed ...`);
|
|
7451
|
-
} catch (error) {
|
|
7452
|
-
console.error(error);
|
|
7453
|
-
throw error;
|
|
7454
|
-
}
|
|
7455
|
-
}
|
|
7456
|
-
*/
|
|
7457
|
-
/*
|
|
7458
|
-
#LoadDefinitionsPass2 = async (__searchParams: any): Promise<void> => {
|
|
7459
|
-
try {
|
|
7460
|
-
for (let i=0; i < (__searchParams.entry as any[]).length; i++) {
|
|
7461
|
-
|
|
7462
|
-
console.log(`Processing (i) entry: [${i}]`);
|
|
7463
|
-
|
|
7464
|
-
if (i === 47 ) {
|
|
7465
|
-
console.log(`here...`)
|
|
7466
|
-
}
|
|
7467
|
-
|
|
7468
|
-
const entry = __searchParams.entry[i];
|
|
7469
|
-
|
|
7470
|
-
const { id, url, code, base, type, expression, component, target } = entry.resource;
|
|
7471
|
-
|
|
7472
|
-
if (base) {
|
|
7473
|
-
for (let j=0; j < base.length; j++) {
|
|
7474
|
-
const resourceType = base[j];
|
|
7475
|
-
const SP_ID = id;
|
|
7476
|
-
const SP_NAME = code; // code is the true SP name (but in the spec, name is usually the same as code)
|
|
7477
|
-
const SP_TYPE = type;
|
|
7478
|
-
const SP_URL = url;
|
|
7479
|
-
const SP_TARGET = target;
|
|
7480
|
-
let SP_EXPRESSION: string = expression;
|
|
7481
|
-
let expressions: any[] = [];
|
|
7482
|
-
let original_expressions: any[] = [];
|
|
7483
|
-
if (SP_EXPRESSION) {
|
|
7484
|
-
const retVal = this._ProcessExpressions(code, SP_EXPRESSION);
|
|
7485
|
-
expressions = retVal.expressions;
|
|
7486
|
-
original_expressions = retVal.original_expressions;
|
|
7487
|
-
}
|
|
7488
|
-
|
|
7489
|
-
const record: ISearchParamRecord = {
|
|
7490
|
-
SP_ID,
|
|
7491
|
-
SP_NAME,
|
|
7492
|
-
SP_TYPE,
|
|
7493
|
-
SP_URL,
|
|
7494
|
-
SP_TARGET,
|
|
7495
|
-
expressions,
|
|
7496
|
-
original_expressions,
|
|
7497
|
-
SP_DEFINITION: entry.resource // this.resourceHelper.GetSearchParam(SP_URL)
|
|
7498
|
-
};
|
|
7499
|
-
|
|
7500
|
-
for (let i=0; i < record.expressions.length; i++) {
|
|
7501
|
-
//console.log(record.expressions[i]);
|
|
7502
|
-
const rf = await this.GetResourceField(resourceType, record.expressions[i].path);
|
|
7503
|
-
if (rf) {
|
|
7504
|
-
expressions[i].RES_FIELD = rf;
|
|
7505
|
-
}
|
|
7506
|
-
}
|
|
7507
|
-
|
|
7508
|
-
if (component) {
|
|
7509
|
-
record.component = [ ...component ];
|
|
7510
|
-
for (let k=0; k < record.component.length; k++) {
|
|
7511
|
-
const c = record.component[k] as any;
|
|
7512
|
-
//c.SP_RAW_PATHS = (c.expression.split('|') as any[]).map(rp => rp.trim());
|
|
7513
|
-
//c.SP_PATHS = (c.SP_RAW_PATHS as any[]).map(rawPath => this.ResolveFhirChoiceType(rawPath));
|
|
7514
|
-
const retVal = this._ProcessExpressions('', c.expression);
|
|
7515
|
-
c.expressions = retVal.expressions;
|
|
7516
|
-
c.original_expressions = retVal.original_expressions;
|
|
7517
|
-
|
|
7518
|
-
let def = null;
|
|
7519
|
-
const foundSearchParameter = await this.redis!.get(this.GetSearchParameterByFullUrlKey(c.definition));
|
|
7520
|
-
if (foundSearchParameter) {
|
|
7521
|
-
def = JSON.parse(foundSearchParameter);
|
|
7522
|
-
}
|
|
7523
|
-
//const def = await this.GetSearchParam(c.definition); //@@ fails here ...
|
|
7524
|
-
|
|
7525
|
-
if (def && def.type) {
|
|
7526
|
-
c.type = def.type
|
|
7527
|
-
}
|
|
7528
|
-
}
|
|
7529
|
-
}
|
|
7530
|
-
|
|
7531
|
-
await this.redis!.hSet(this.GetSTSCustomSearchParameterByResourceTypeKey(resourceType),
|
|
7532
|
-
code, JSON.stringify(record));
|
|
7533
|
-
|
|
7534
|
-
console.log(`Loaded...(j): [${j}]`);
|
|
7535
|
-
}
|
|
7536
|
-
console.log(`All Loaded...`);
|
|
7537
|
-
}
|
|
7538
|
-
console.log(`Loaded...(i): [${i}]`);
|
|
7539
|
-
};
|
|
7540
|
-
console.log(`Loaded...`);
|
|
7541
|
-
} catch (error) {
|
|
7542
|
-
console.error(error);
|
|
7543
|
-
throw error;
|
|
7544
|
-
}
|
|
7545
|
-
}
|
|
7546
|
-
*/
|
|
7547
|
-
/*
|
|
7548
|
-
GetType = async (typeName: string): Promise<any[]> => {
|
|
7549
|
-
await this.EnsureSearchParameterDataLoaded();
|
|
7550
|
-
const foundType = await this.redis!.get(this.GetTypeKey(typeName));
|
|
7551
|
-
if (foundType) {
|
|
7552
|
-
return JSON.parse(foundType);
|
|
7553
|
-
}
|
|
7554
|
-
return [ ];
|
|
7555
|
-
}
|
|
7556
|
-
|
|
7557
|
-
GetResource = async (resourceType: string): Promise<any[]> => {
|
|
7558
|
-
await this.EnsureSearchParameterDataLoaded();
|
|
7559
|
-
const foundResourceType = await this.redis!.get(this.GetResourceKey(resourceType));
|
|
7560
|
-
if (foundResourceType) {
|
|
7561
|
-
return JSON.parse(foundResourceType);
|
|
7562
|
-
}
|
|
7563
|
-
return [ ];
|
|
7564
|
-
}
|
|
7565
|
-
|
|
7566
|
-
GetResourceField = async (resourceType: string, fieldPath: string): Promise<any> => {
|
|
7567
|
-
const resource: any[] = await this.GetResource(resourceType);
|
|
7568
|
-
if (resource) {
|
|
7569
|
-
const foundRecord = resource.filter(o => o.id === fieldPath);
|
|
7570
|
-
if (foundRecord.length > 0) {
|
|
7571
|
-
return foundRecord[0];
|
|
7572
|
-
}
|
|
7573
|
-
return undefined;
|
|
7574
|
-
}
|
|
7575
|
-
}
|
|
7576
|
-
|
|
7577
|
-
GetSearchParam = async (fullUrl: string): Promise<any> => {
|
|
7578
|
-
await this.EnsureSearchParameterDataLoaded();
|
|
7579
|
-
const foundSearchParameter = await this.redis!.get(this.GetSearchParameterByFullUrlKey(fullUrl));
|
|
7580
|
-
if (foundSearchParameter) {
|
|
7581
|
-
return JSON.parse(foundSearchParameter);
|
|
7582
|
-
}
|
|
7583
|
-
return null;
|
|
7584
|
-
}
|
|
7585
|
-
|
|
7586
|
-
GetSearchParamsByResourceType = async (resourceType: string): Promise<SearchParameter[]> => {
|
|
7587
|
-
await this.EnsureSearchParameterDataLoaded();
|
|
7588
|
-
const all = await this.redis!.hGetAll(this.GetSearchParameterByResourceTypeKey(resourceType));
|
|
7589
|
-
const parsed = Object.values(all).map(v => JSON.parse(v));
|
|
7590
|
-
return parsed;
|
|
7591
|
-
}
|
|
7592
|
-
|
|
7593
|
-
GetSTSCustomSearchParametersByResourceType = async (resourceType: string): Promise<ISearchParamRecord[]> => {
|
|
7594
|
-
await this.EnsureSearchParameterDataLoaded();
|
|
7595
|
-
const all = await this.redis!.hGetAll(this.GetSTSCustomSearchParameterByResourceTypeKey(resourceType));
|
|
7596
|
-
const parsed = Object.values(all).map(v => JSON.parse(v));
|
|
7597
|
-
return parsed;
|
|
7598
|
-
}
|
|
7599
|
-
|
|
7600
|
-
GetSearchParamFromResourceTypeUrl = async (resourceType: string, url: string): Promise<ISearchParamRecord | undefined> => {
|
|
7601
|
-
const customSearchParameters = await this.GetSTSCustomSearchParametersByResourceType(resourceType);
|
|
7602
|
-
const filterByNameAndUrl = customSearchParameters.filter(rt => rt.SP_URL.localeCompare(url) === 0);
|
|
7603
|
-
if (filterByNameAndUrl.length > 0) {
|
|
7604
|
-
return filterByNameAndUrl[0];
|
|
7605
|
-
}
|
|
7606
|
-
}
|
|
7607
|
-
|
|
7608
|
-
GetSearchParamFromResourceType = async (resourceType: string, name: string): Promise<ISearchParamRecord | undefined> => {
|
|
7609
|
-
const customSearchParameters = await this.GetSTSCustomSearchParametersByResourceType(resourceType);
|
|
7610
|
-
const filterByName = customSearchParameters.filter(rt => rt.SP_NAME.localeCompare(name) === 0);
|
|
7611
|
-
if (filterByName.length > 0) {
|
|
7612
|
-
return filterByName[0];
|
|
7613
|
-
}
|
|
7614
|
-
}
|
|
7615
|
-
|
|
7616
|
-
GetPathsFromResourceType = async (resourceType: string, name: string): Promise<string[]> => {
|
|
7617
|
-
const customSearchParameters = await this.GetSTSCustomSearchParametersByResourceType(resourceType);
|
|
7618
|
-
const filterByName = customSearchParameters.filter(rt => rt.SP_NAME.localeCompare(name) === 0);
|
|
7619
|
-
if (filterByName.length > 0) {
|
|
7620
|
-
return filterByName[0].expressions.map(e => e.path)
|
|
7621
|
-
}
|
|
7622
|
-
return [ ];
|
|
7623
|
-
}
|
|
7624
|
-
*/
|
|
7256
|
+
GetSearchParamFromResourceType = async (resourceType) => {
|
|
7257
|
+
const key = `${this.#searchParametersByResourceTypeKey}_${resourceType}`;
|
|
7258
|
+
if (this.cache[key]) {
|
|
7259
|
+
return this.cache[key];
|
|
7260
|
+
}
|
|
7261
|
+
const retVal = await this.redis.hGet(this.#searchParametersByResourceTypeKey, resourceType);
|
|
7262
|
+
this.cache[key] = JSON.parse(retVal);
|
|
7263
|
+
return this.cache[key];
|
|
7264
|
+
};
|
|
7265
|
+
GetType = async (typeName) => {
|
|
7266
|
+
const key = `${this.#typesKey}_${typeName}`;
|
|
7267
|
+
if (this.cache[key]) {
|
|
7268
|
+
return this.cache[key];
|
|
7269
|
+
}
|
|
7270
|
+
const retVal = await this.redis.hGet(this.#typesKey, typeName);
|
|
7271
|
+
this.cache[key] = JSON.parse(retVal);
|
|
7272
|
+
return this.cache[key];
|
|
7273
|
+
};
|
|
7274
|
+
GetResource = async (resourceType) => {
|
|
7275
|
+
const key = `${this.#resourcesKey}_${resourceType}`;
|
|
7276
|
+
if (this.cache[key]) {
|
|
7277
|
+
return this.cache[key];
|
|
7278
|
+
}
|
|
7279
|
+
const retVal = await this.redis.hGet(this.#resourcesKey, resourceType);
|
|
7280
|
+
this.cache[key] = JSON.parse(retVal);
|
|
7281
|
+
return this.cache[key];
|
|
7282
|
+
};
|
|
7283
|
+
GetSearchParam = async (url) => {
|
|
7284
|
+
const key = `${this.#searchParametersByUrlKey}_${url}`;
|
|
7285
|
+
if (this.cache[key]) {
|
|
7286
|
+
return this.cache[key];
|
|
7287
|
+
}
|
|
7288
|
+
const retVal = await this.redis.hGet(this.#searchParametersByUrlKey, url);
|
|
7289
|
+
this.cache[key] = JSON.parse(retVal);
|
|
7290
|
+
return this.cache[key];
|
|
7291
|
+
};
|
|
7625
7292
|
}
|
|
7626
7293
|
const specPath1 = "./dist/";
|
|
7627
7294
|
const specPath2 = "./node_modules/@nsshunt/stsfhirpg/dist/";
|
|
@@ -7630,6 +7297,7 @@ const typesPath = "fhir-spec/profiles-types.json";
|
|
|
7630
7297
|
const searchParamsPath = "fhir-spec/search-parameters.json";
|
|
7631
7298
|
class ResourceHelper {
|
|
7632
7299
|
#definitions;
|
|
7300
|
+
#loaded = false;
|
|
7633
7301
|
searchParameterManager;
|
|
7634
7302
|
static instance;
|
|
7635
7303
|
constructor() {
|
|
@@ -7682,7 +7350,8 @@ class ResourceHelper {
|
|
|
7682
7350
|
});
|
|
7683
7351
|
await this._LoadSearchParameters();
|
|
7684
7352
|
await this.PreLoadSearchParameterData();
|
|
7685
|
-
|
|
7353
|
+
this.#loaded = true;
|
|
7354
|
+
this.#definitions = void 0;
|
|
7686
7355
|
};
|
|
7687
7356
|
PreLoadSearchParameterData = async () => {
|
|
7688
7357
|
console.log(`PreLoadSearchParameterData(): Start ...`);
|
|
@@ -7693,25 +7362,22 @@ class ResourceHelper {
|
|
|
7693
7362
|
autoRenew: true,
|
|
7694
7363
|
heartbeatMs: 1e4
|
|
7695
7364
|
});
|
|
7696
|
-
await this.searchParameterManager.EnsureSearchParameterDataLoaded();
|
|
7365
|
+
await this.searchParameterManager.EnsureSearchParameterDataLoaded(this.#definitions);
|
|
7697
7366
|
console.log(`PreLoadSearchParameterData(): End`);
|
|
7698
7367
|
};
|
|
7699
7368
|
GetDefinitions = async () => {
|
|
7700
|
-
if (!this.#
|
|
7701
|
-
|
|
7369
|
+
if (!this.#loaded) {
|
|
7370
|
+
if (!this.#definitions) {
|
|
7371
|
+
await this.#LoadDefinitions();
|
|
7372
|
+
}
|
|
7702
7373
|
}
|
|
7703
|
-
return this.#definitions;
|
|
7704
7374
|
};
|
|
7705
|
-
|
|
7706
|
-
await this.GetDefinitions();
|
|
7707
|
-
return this.#definitions.types[typeName];
|
|
7708
|
-
};
|
|
7709
|
-
GetResource = async (resourceType) => {
|
|
7375
|
+
_GetResource = async (resourceType) => {
|
|
7710
7376
|
await this.GetDefinitions();
|
|
7711
7377
|
return this.#definitions.resources[resourceType];
|
|
7712
7378
|
};
|
|
7713
|
-
|
|
7714
|
-
const resource = await this.
|
|
7379
|
+
_GetResourceField = async (resourceType, fieldPath) => {
|
|
7380
|
+
const resource = await this._GetResource(resourceType);
|
|
7715
7381
|
if (resource) {
|
|
7716
7382
|
const foundRecord = resource.filter((o) => o.id === fieldPath);
|
|
7717
7383
|
if (foundRecord.length > 0) {
|
|
@@ -7720,18 +7386,53 @@ class ResourceHelper {
|
|
|
7720
7386
|
return void 0;
|
|
7721
7387
|
}
|
|
7722
7388
|
};
|
|
7723
|
-
|
|
7389
|
+
_GetSearchParam = async (url) => {
|
|
7724
7390
|
await this.GetDefinitions();
|
|
7725
7391
|
return this.#definitions.searchParametersByUrl[url];
|
|
7726
7392
|
};
|
|
7727
|
-
|
|
7393
|
+
_GetSearchParams = async () => {
|
|
7728
7394
|
await this.GetDefinitions();
|
|
7729
7395
|
return this.#definitions.searchParametersByUrl;
|
|
7730
7396
|
};
|
|
7731
|
-
|
|
7397
|
+
GetType = async (typeName) => {
|
|
7398
|
+
await this.GetDefinitions();
|
|
7399
|
+
return await this.searchParameterManager.GetType(typeName);
|
|
7400
|
+
};
|
|
7401
|
+
GetResource = async (resourceType) => {
|
|
7402
|
+
await this.GetDefinitions();
|
|
7403
|
+
return await this.searchParameterManager.GetResource(resourceType);
|
|
7404
|
+
};
|
|
7405
|
+
GetResourceField = async (resourceType, fieldPath) => {
|
|
7406
|
+
const resource = await this.GetResource(resourceType);
|
|
7407
|
+
if (resource) {
|
|
7408
|
+
const foundRecord = resource.filter((o) => o.id === fieldPath);
|
|
7409
|
+
if (foundRecord.length > 0) {
|
|
7410
|
+
return foundRecord[0];
|
|
7411
|
+
}
|
|
7412
|
+
return void 0;
|
|
7413
|
+
}
|
|
7414
|
+
};
|
|
7415
|
+
GetSearchParam = async (url) => {
|
|
7732
7416
|
await this.GetDefinitions();
|
|
7733
|
-
return
|
|
7417
|
+
return await this.searchParameterManager.GetSearchParam(url);
|
|
7734
7418
|
};
|
|
7419
|
+
/*
|
|
7420
|
+
private GetSearchParams = async (): Promise<SearchParameter[]> => {
|
|
7421
|
+
await this.GetDefinitions();
|
|
7422
|
+
return await this.searchParameterManager!.GetSearchParams();
|
|
7423
|
+
}
|
|
7424
|
+
|
|
7425
|
+
GetSearchParamsByResource = async (resource: string): Promise<SearchParameter[]> => {
|
|
7426
|
+
await this.GetDefinitions();
|
|
7427
|
+
const searchParams = await this.GetSearchParams();
|
|
7428
|
+
return searchParams
|
|
7429
|
+
.filter(sp => sp.base.includes(resource))
|
|
7430
|
+
.map(sp => sp)
|
|
7431
|
+
//return Object.values(this.#definitions!.searchParametersByUrl)
|
|
7432
|
+
//.filter(sp => sp.base.includes(resource))
|
|
7433
|
+
//.map(sp => sp)
|
|
7434
|
+
}
|
|
7435
|
+
*/
|
|
7735
7436
|
// ------------------------------------------------------------------------------------------------------------------
|
|
7736
7437
|
// Remove ( ) when either are present
|
|
7737
7438
|
#RemoveOuterParentheses = (input) => {
|
|
@@ -7854,7 +7555,7 @@ class ResourceHelper {
|
|
|
7854
7555
|
};
|
|
7855
7556
|
};
|
|
7856
7557
|
_LoadSearchParameters = async () => {
|
|
7857
|
-
for (const [key, val] of Object.entries(await this.
|
|
7558
|
+
for (const [key, val] of Object.entries(await this._GetSearchParams())) {
|
|
7858
7559
|
const { id, url, code, base, type, expression, component, target } = val;
|
|
7859
7560
|
for (let i = 0; i < base.length; i++) {
|
|
7860
7561
|
const resourceName = base[i];
|
|
@@ -7885,10 +7586,10 @@ class ResourceHelper {
|
|
|
7885
7586
|
SP_TARGET,
|
|
7886
7587
|
expressions,
|
|
7887
7588
|
original_expressions,
|
|
7888
|
-
SP_DEFINITION: await this.
|
|
7589
|
+
SP_DEFINITION: await this._GetSearchParam(SP_URL)
|
|
7889
7590
|
};
|
|
7890
7591
|
for (let i2 = 0; i2 < record.expressions.length; i2++) {
|
|
7891
|
-
const rf = await this.
|
|
7592
|
+
const rf = await this._GetResourceField(resourceName, record.expressions[i2].path);
|
|
7892
7593
|
if (rf) {
|
|
7893
7594
|
expressions[i2].RES_FIELD = rf;
|
|
7894
7595
|
}
|
|
@@ -7899,7 +7600,7 @@ class ResourceHelper {
|
|
|
7899
7600
|
const retVal = this.ProcessExpressions("", c.expression);
|
|
7900
7601
|
c.expressions = retVal.expressions;
|
|
7901
7602
|
c.original_expressions = retVal.original_expressions;
|
|
7902
|
-
const def = await this.
|
|
7603
|
+
const def = await this._GetSearchParam(c.definition);
|
|
7903
7604
|
if (def && def.type) {
|
|
7904
7605
|
c.type = def.type;
|
|
7905
7606
|
}
|
|
@@ -7911,21 +7612,24 @@ class ResourceHelper {
|
|
|
7911
7612
|
};
|
|
7912
7613
|
GetSearchParamFromResourceTypeUrl = async (resourceType, url) => {
|
|
7913
7614
|
await this.GetDefinitions();
|
|
7914
|
-
const
|
|
7615
|
+
const rt = await this.searchParameterManager?.GetSearchParamFromResourceType(resourceType);
|
|
7616
|
+
const filterByNameAndUrl = rt.params.filter((rt2) => rt2.SP_URL.localeCompare(url) === 0);
|
|
7915
7617
|
if (filterByNameAndUrl.length > 0) {
|
|
7916
7618
|
return filterByNameAndUrl[0];
|
|
7917
7619
|
}
|
|
7918
7620
|
};
|
|
7919
7621
|
GetSearchParamFromResourceType = async (resourceType, name) => {
|
|
7920
7622
|
await this.GetDefinitions();
|
|
7921
|
-
const
|
|
7623
|
+
const rt = await this.searchParameterManager?.GetSearchParamFromResourceType(resourceType);
|
|
7624
|
+
const filterByName = rt.params.filter((rt2) => rt2.SP_NAME.localeCompare(name) === 0);
|
|
7922
7625
|
if (filterByName.length > 0) {
|
|
7923
7626
|
return filterByName[0];
|
|
7924
7627
|
}
|
|
7925
7628
|
};
|
|
7926
7629
|
GetSearchParamsFromResourceType = async (resourceType) => {
|
|
7927
7630
|
await this.GetDefinitions();
|
|
7928
|
-
|
|
7631
|
+
const rt = await this.searchParameterManager?.GetSearchParamFromResourceType(resourceType);
|
|
7632
|
+
return rt.params;
|
|
7929
7633
|
};
|
|
7930
7634
|
}
|
|
7931
7635
|
var ansiStyles = { exports: {} };
|