From f9f8d8baa25d3fd14f2f566e0e4f42db8aa94cdd Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 13 Mar 2026 08:50:29 +1100 Subject: [PATCH 1/4] Add default configurations --- configurations/projector.json | 21 +++++++++++++++++++++ configurations/readme.md | 5 +++++ 2 files changed, 26 insertions(+) create mode 100644 configurations/projector.json create mode 100644 configurations/readme.md diff --git a/configurations/projector.json b/configurations/projector.json new file mode 100644 index 00000000..38ae8fc8 --- /dev/null +++ b/configurations/projector.json @@ -0,0 +1,21 @@ +{ + "hostName" : "NPM Publisher", + "server": { + "port": 3001, + "cors": { + "origin": true, + "credentials": true + } + }, + "modules": { + "npmprojector": { + "enabled": false, + "fhirVersion": "r4", + "basePath": "/us-core", + "npm": "hl7.fhir.us.core#7.0.1", + "resourceFolders": ["data"], + "searchParametersFolder": "data", + "debounceMs": 500 + } + } +} \ No newline at end of file diff --git a/configurations/readme.md b/configurations/readme.md new file mode 100644 index 00000000..cb54262d --- /dev/null +++ b/configurations/readme.md @@ -0,0 +1,5 @@ +This folder contains some basic starter configurations: + +* Terminology server: see tx-config.json for a vanilla server that doesn't contain any licensed content +* NPM web server: see projector.json for a basic configuration to make a package available online + From 4359aa18c7c8ec9bf4b07cc97fb50f771ab127d8 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 13 Mar 2026 08:51:16 +1100 Subject: [PATCH 2/4] Make crawlers more robust --- packages/package-crawler.js | 36 ++++++++++++++++++++++++++---------- packages/packages.js | 1 + registry/crawler.js | 32 +++++++++++++++++++------------- tests/tx/library.test.js | 4 ++-- tx/operation-context.js | 9 ++++++++- tx/vs/vs-vsac.js | 7 ++++--- tx/workers/worker.js | 6 ------ 7 files changed, 60 insertions(+), 35 deletions(-) diff --git a/packages/package-crawler.js b/packages/package-crawler.js index 82b39d8f..df8b5177 100644 --- a/packages/package-crawler.js +++ b/packages/package-crawler.js @@ -9,11 +9,12 @@ const {XMLParser} = require('fast-xml-parser'); const crypto = require('crypto'); const fs = require('fs'); const path = require('path'); +const {isDebugging} = require("../tx/operation-context"); class PackageCrawler { log; packages = new Set(); - + constructor(config, db, stats) { this.config = config; this.db = db; @@ -21,6 +22,7 @@ class PackageCrawler { this.totalBytes = 0; this.crawlerLog = {}; this.errors = ''; + this.abortController = null; this.db.run('PRAGMA journal_mode = WAL'); this.db.run('PRAGMA busy_timeout = 5000'); } @@ -28,7 +30,8 @@ class PackageCrawler { async crawl(log) { this.log = log; this.packages.clear(); - + this.abortController = new AbortController(); + const startTime = Date.now(); this.crawlerLog = { startTime: new Date().toISOString(), @@ -54,6 +57,7 @@ class PackageCrawler { // Process each feed for (const feedConfig of masterResponse.feeds) { + if (this.abortController?.signal.aborted) break; if (!feedConfig.url) { this.log.info('Skipping feed with no URL: '+ feedConfig); continue; @@ -71,6 +75,7 @@ class PackageCrawler { } // process simplifier last for (const feedConfig of masterResponse.feeds) { + if (this.abortController?.signal.aborted) break; if (!feedConfig.url) { this.log.info('Skipping feed with no URL: '+ feedConfig); continue; @@ -123,6 +128,7 @@ class PackageCrawler { } else { const response = await axios.get(url, { timeout: 30000, + signal: this.abortController?.signal, headers: { 'User-Agent': 'FHIR Package Crawler/1.0' } @@ -130,7 +136,7 @@ class PackageCrawler { return response.data; } } catch (error) { - console.log(error); + debugLog(error); if (error.response && error.response.status === 429) { throw new Error(`RATE_LIMITED: Server returned 429 Too Many Requests for ${url}`); } @@ -151,6 +157,7 @@ class PackageCrawler { } else { const response = await axios.get(url, { timeout: 30000, + signal: this.abortController?.signal, headers: { 'User-Agent': 'FHIR Package Crawler/1.0' } @@ -165,6 +172,7 @@ class PackageCrawler { return parser.parse(response.data); } } catch (error) { + debugLog(error); if (error.response && error.response.status === 429) { throw new Error(`RATE_LIMITED: Server returned 429 Too Many Requests for ${url}`); } @@ -182,6 +190,7 @@ class PackageCrawler { const response = await axios.get(url, { timeout: 60000, responseType: 'arraybuffer', + signal: this.abortController?.signal, headers: { 'User-Agent': 'FHIR Package Crawler/1.0' } @@ -191,6 +200,7 @@ class PackageCrawler { return Buffer.from(response.data); } } catch (error) { + debugLog(error); if (error.response && error.response.status === 429) { throw new Error(`RATE_LIMITED: Server returned 429 Too Many Requests for ${url}`); } @@ -222,6 +232,7 @@ class PackageCrawler { this.log.info(`Found ${items.length} items in feed`); for (let i = 0; i < items.length; i++) { + if (this.abortController?.signal.aborted) break; try { await this.updateItem(url, items[i], i, packageRestrictions, feedLog); } catch (itemError) { @@ -244,7 +255,7 @@ class PackageCrawler { } } catch (error) { - console.log(error); + debugLog(error); // Check if this is a 429 error on feed fetch if (error.message.includes('RATE_LIMITED')) { this.log.info(`Rate limited while fetching feed ${url}, skipping this feed`); @@ -302,7 +313,7 @@ class PackageCrawler { } // Check package restrictions - if (!this.isPackageAllowed(id, source, packageRestrictions)) { + if (!this.isPackageAllowed(id, source, packageRestrictions).allowed) { if (!source.includes('simplifier.net')) { const error = `The package ${id} is not allowed to come from ${source}`; this.log.info(error); @@ -333,7 +344,7 @@ class PackageCrawler { let pd = item.pubDate; pubDate = this.parsePubDate(pd); } catch (error) { - itemLog.error = `Invalid date format '{pd}': ${error.message}`; + itemLog.error = `Invalid date format '${pd}': ${error.message}`; itemLog.status = 'error'; return; } @@ -355,7 +366,7 @@ class PackageCrawler { itemLog.status = 'Fetched'; } catch (error) { - this.log.error(`Exception processing item ${itemLog.guid || index}:`+ error.message); + this.log.error(`Exception processing item ${itemLog.guid || index} from ${source}: `+ error.message); itemLog.status = 'Exception'; itemLog.error = error.message; if (error.message.includes('RATE_LIMITED')) { @@ -383,7 +394,7 @@ class PackageCrawler { if (this.matchesPattern(fixedPackageId, fixedMask)) { // This package matches a restriction - check if source is allowed - const allowedFeeds = restriction.feeds.map(feed => feed); + const allowedFeeds = restriction.feeds.map(feed => fixUrl(feed)); const feedList = allowedFeeds.join(', '); for (const allowedFeed of restriction.feeds) { @@ -500,7 +511,7 @@ class PackageCrawler { await this.commit(packageBuffer, npmPackage, date, guid, id, version, canonical, urls); } catch (error) { - console.log(error); + debugLog(error); this.log.error(`Error storing package ${guid}:`+ error.message); throw error; } @@ -562,6 +573,7 @@ class PackageCrawler { throw new Error('package.json not found in extracted package'); } + const packageJson = JSON.parse(files['package.json']); const hasInstallScripts = !!( packageJson.scripts && ( packageJson.scripts.preinstall || @@ -570,7 +582,6 @@ class PackageCrawler { ) ); const hasJavaScript = Object.keys(files).some(f => f.endsWith('.js') || f.endsWith('.mjs') || f.endsWith('.cjs')); - const packageJson = JSON.parse(files['package.json']); // Extract basic NPM fields const id = packageJson.name || ''; @@ -921,6 +932,11 @@ class PackageCrawler { return id; } } + shutdown() { + if (this.abortController) { + this.abortController.abort(); + } + } } module.exports = PackageCrawler; \ No newline at end of file diff --git a/packages/packages.js b/packages/packages.js index b3ef54c9..e429dce3 100644 --- a/packages/packages.js +++ b/packages/packages.js @@ -803,6 +803,7 @@ class PackagesModule { stopCrawlerJob() { if (this.crawlerJob) { + this.crawler.shutdown(); this.crawlerJob.stop(); this.crawlerJob = null; pckLog.info('Package crawler job stopped'); diff --git a/registry/crawler.js b/registry/crawler.js index e526b5b3..171c33a8 100644 --- a/registry/crawler.js +++ b/registry/crawler.js @@ -9,6 +9,7 @@ const { ServerVersionInformation, } = require('./model'); const {Extensions} = require("../tx/library/extensions"); +const {isDebugging} = require("../tx/operation-context"); const MASTER_URL = 'https://fhir.github.io/ig-registry/tx-servers.json'; @@ -89,7 +90,7 @@ class RegistryCrawler { // Update the current data this.currentData = newData; } catch (error) { - console.log(error.message); + debugLog(error); this.addLogEntry('error', 'Exception Scanning:', error); this.currentData.outcome = `Error: ${error.message}`; this.errors.push({ @@ -121,7 +122,7 @@ class RegistryCrawler { } if (!registry.address) { - this.addLogEntry('error', `No url provided for ${registry.name, registry.name}`, ''); + this.addLogEntry('error', `No url provided for ${registry.name}`, ''); return registry; } @@ -145,7 +146,7 @@ class RegistryCrawler { } } catch (error) { - console.log(error.message); + debugLog(error); registry.error = error.message; this.addLogEntry('error', `Exception processing registry ${registry.name}: ${error.message}`, registry.address); } @@ -236,7 +237,7 @@ class RegistryCrawler { this.addLogEntry('info', ` Server ${version.address}: ${version.lastTat} for ${version.codeSystems.length} CodeSystems and ${version.valueSets.length} ValueSets`); } catch (error) { - console.log(error.message); + debugLog(error); const elapsed = Date.now() - startTime; this.addLogEntry('error', `Server ${version.address}: Error after ${elapsed}ms: ${error.message}`); version.error = error.message; @@ -281,8 +282,8 @@ class RegistryCrawler { }); } } catch (error) { - console.log(error.message); - this.addLogEntry('error', `Could not fetch terminology capabilities: ${error.message}`); + debugLog(error); + this.addLogEntry('error', `Could not fetch terminology capabilities from ${version.address}: ${error.message}`); } if (this.abortController?.signal.aborted) return; @@ -330,8 +331,8 @@ class RegistryCrawler { }); } } catch (error) { - console.log(error.message); - this.addLogEntry('error', `Could not fetch terminology capabilities: ${error.message}`); + debugLog(error); + this.addLogEntry('error', `Could not fetch terminology capabilities from ${version.address}: ${error.message}`); } // Search for value sets @@ -348,14 +349,19 @@ class RegistryCrawler { */ async fetchValueSets(version, server, exclusions) { // Initial search URL + let count = 0; let searchUrl = `${version.address}/ValueSet?_elements=url,version`+(version.address.includes("fhir.org") ? "&_count=200" : ""); try { // Set of URLs to avoid duplicates const valueSetUrls = new Set(); - // Continue fetching while we have a URL while (searchUrl) { + count++; + if (count == 1000) { + throw new Error(`Fetch ValueSet loop exceeded 1000 iterations - a logic problem on the server? (${version.address})`); + } + if (this.abortController?.signal.aborted) break; this.log.debug(`Fetching value sets from ${searchUrl}`); const bundle = await this.fetchJson(searchUrl, server.code); @@ -389,7 +395,7 @@ class RegistryCrawler { version.valueSets = Array.from(valueSetUrls).sort(); } catch (error) { - console.log(error.message); + debugLog(error); this.addLogEntry('error', `Could not fetch value sets: ${error.message} from ${searchUrl}`); } } @@ -467,7 +473,7 @@ class RegistryCrawler { return response.data; } catch (error) { - console.log(error.message); + debugLog(error); if (error.response) { throw new Error(`HTTP ${error.response.status}: ${error.response.statusText}`); } else if (error.request) { @@ -611,14 +617,14 @@ class RegistryCrawler { * @param {string} level - Filter by log level * @returns {Array} Array of log entries */ - getLogs(limit = 100) + getLogs(limit = 100, level = null) { if (!this.logs) { return []; } // Filter by level if specified - let filteredLogs = this.logs; + let filteredLogs = level ? this.logs.filter(entry => entry.level === level) : this.logs; // Get the latest entries up to the limit return filteredLogs.slice(-limit); diff --git a/tests/tx/library.test.js b/tests/tx/library.test.js index a7085085..c15f2a72 100644 --- a/tests/tx/library.test.js +++ b/tests/tx/library.test.js @@ -1,6 +1,6 @@ const {Library} = require("../../tx/library"); const path = require("path"); -const {OperationContext} = require("../../tx/operation-context"); +const {OperationContext, isDebugging} = require("../../tx/operation-context"); const {Languages} = require("../../library/languages"); const NO_LOAD_TEST = true; @@ -69,7 +69,7 @@ describe('Provider Test', () => { } } catch (error) { - console.log(error); + debugLog(error); failureCount++; failures.push(`${key}: ${error.message}`); console.log(`✗ Error creating provider for ${key}: ${error.message}`); diff --git a/tx/operation-context.js b/tx/operation-context.js index f3c948d1..e3a19141 100644 --- a/tx/operation-context.js +++ b/tx/operation-context.js @@ -19,6 +19,12 @@ function isDebugging() { ); } +function debugLog(error, message) { + if (isDebugging()) { + console.log(error, message); + } +} + class TimeTracker { constructor() { @@ -584,5 +590,6 @@ module.exports = { TimeTracker, ResourceCache, ExpansionCache, - isDebugging + isDebugging, + debugLog }; \ No newline at end of file diff --git a/tx/vs/vs-vsac.js b/tx/vs/vs-vsac.js index 386301a8..8df4e6b0 100644 --- a/tx/vs/vs-vsac.js +++ b/tx/vs/vs-vsac.js @@ -4,6 +4,7 @@ const { AbstractValueSetProvider } = require('./vs-api'); const { ValueSetDatabase } = require('./vs-database'); const { VersionUtilities } = require('../../library/version-utilities'); const folders = require('../../library/folder-setup'); +const {isDebugging, debugLog} = require("../operation-context"); /** * VSAC (Value Set Authority Center) ValueSet provider @@ -178,7 +179,7 @@ class VSACValueSetProvider extends AbstractValueSetProvider { await this.processContentAndHistory(q, tracking, this.queue.length); } catch (error) { this.requeue.push(q) - console.log(error); + debugLog(error); this.stats.task('VSAC Sync', error.message); } // `running (${totalFetched} fetched, ${totalNew} new)`) @@ -190,7 +191,7 @@ class VSACValueSetProvider extends AbstractValueSetProvider { try { await this.processContentAndHistory(q, tracking, this.requeue.length); } catch (error) { - console.log(error); + debugLog(error); this.stats.task('VSAC Sync', error.message); } // `running (${totalFetched} fetched, ${totalNew} new)`) @@ -201,7 +202,7 @@ class VSACValueSetProvider extends AbstractValueSetProvider { await this._reloadMap(); console.log(`VSAC refresh completed. Total: ${tracking.totalFetched} ValueSets, Deleted: ${tracking.deletedCount}`); } catch (error) { - console.log(error, 'Error during VSAC refresh:'); + debugLog(error, 'Error during VSAC refresh:'); this.stats.task('VSAC Sync', `Error (${error.message})`); throw error; } finally { diff --git a/tx/workers/worker.js b/tx/workers/worker.js index 0a59f7d0..36050469 100644 --- a/tx/workers/worker.js +++ b/tx/workers/worker.js @@ -900,12 +900,6 @@ class TerminologyWorker { return true; } - debugLog(error) { - if (isDebugging()) { - console.log(error); - } - } - hasSupplement(cs, supplements) { for (let t of supplements) { if (t.vurl == cs.vurl) { From 1969cfd79c1ec1451290860cc83e8534d109180c Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 13 Mar 2026 08:55:57 +1100 Subject: [PATCH 3/4] lint fixes --- packages/package-crawler.js | 3 ++- registry/crawler.js | 2 +- tests/tx/library.test.js | 2 +- tx/vs/vs-vsac.js | 2 +- tx/workers/worker.js | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/package-crawler.js b/packages/package-crawler.js index df8b5177..c56657ab 100644 --- a/packages/package-crawler.js +++ b/packages/package-crawler.js @@ -9,7 +9,7 @@ const {XMLParser} = require('fast-xml-parser'); const crypto = require('crypto'); const fs = require('fs'); const path = require('path'); -const {isDebugging} = require("../tx/operation-context"); +const {debugLog} = require("../tx/operation-context"); class PackageCrawler { log; @@ -340,6 +340,7 @@ class PackageCrawler { // Parse publication date let pubDate; + let pd; try { let pd = item.pubDate; pubDate = this.parsePubDate(pd); diff --git a/registry/crawler.js b/registry/crawler.js index 171c33a8..ece1b28d 100644 --- a/registry/crawler.js +++ b/registry/crawler.js @@ -9,7 +9,7 @@ const { ServerVersionInformation, } = require('./model'); const {Extensions} = require("../tx/library/extensions"); -const {isDebugging} = require("../tx/operation-context"); +const {debugLog} = require("../tx/operation-context"); const MASTER_URL = 'https://fhir.github.io/ig-registry/tx-servers.json'; diff --git a/tests/tx/library.test.js b/tests/tx/library.test.js index c15f2a72..c67f5ad3 100644 --- a/tests/tx/library.test.js +++ b/tests/tx/library.test.js @@ -1,6 +1,6 @@ const {Library} = require("../../tx/library"); const path = require("path"); -const {OperationContext, isDebugging} = require("../../tx/operation-context"); +const {OperationContext, debugLog} = require("../../tx/operation-context"); const {Languages} = require("../../library/languages"); const NO_LOAD_TEST = true; diff --git a/tx/vs/vs-vsac.js b/tx/vs/vs-vsac.js index 8df4e6b0..766ab6a1 100644 --- a/tx/vs/vs-vsac.js +++ b/tx/vs/vs-vsac.js @@ -4,7 +4,7 @@ const { AbstractValueSetProvider } = require('./vs-api'); const { ValueSetDatabase } = require('./vs-database'); const { VersionUtilities } = require('../../library/version-utilities'); const folders = require('../../library/folder-setup'); -const {isDebugging, debugLog} = require("../operation-context"); +const {debugLog} = require("../operation-context"); /** * VSAC (Value Set Authority Center) ValueSet provider diff --git a/tx/workers/worker.js b/tx/workers/worker.js index 36050469..271ca5cb 100644 --- a/tx/workers/worker.js +++ b/tx/workers/worker.js @@ -1,4 +1,4 @@ -const { TerminologyError, isDebugging} = require('../operation-context'); +const { TerminologyError} = require('../operation-context'); const { CodeSystem } = require('../library/codesystem'); const ValueSet = require('../library/valueset'); const {VersionUtilities} = require("../../library/version-utilities"); From a5762c55e7df37433d6c3323e99cc8b61cef4f84 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 13 Mar 2026 09:20:23 +1100 Subject: [PATCH 4/4] fix code --- tx/workers/batch-validate.js | 5 +++-- tx/workers/batch.js | 5 +++-- tx/workers/expand.js | 5 +++-- tx/workers/lookup.js | 9 +++++---- tx/workers/read.js | 3 ++- tx/workers/related.js | 5 +++-- tx/workers/search.js | 3 ++- tx/workers/subsumes.js | 5 +++-- tx/workers/translate.js | 7 ++++--- tx/workers/validate.js | 15 ++++++++------- 10 files changed, 36 insertions(+), 26 deletions(-) diff --git a/tx/workers/batch-validate.js b/tx/workers/batch-validate.js index 3dcdf39a..d66e36dd 100644 --- a/tx/workers/batch-validate.js +++ b/tx/workers/batch-validate.js @@ -15,6 +15,7 @@ const { TerminologyWorker } = require('./worker'); const {OperationOutcome, Issue} = require("../library/operation-outcome"); const {Parameters} = require("../library/parameters"); const {ValidateWorker} = require("./validate"); +const {debugLog} = require("../operation-context"); class BatchValidateWorker extends TerminologyWorker { @@ -82,7 +83,7 @@ class BatchValidateWorker extends TerminologyWorker { output.push({name: "validation", resource : p}); } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); if (error instanceof Issue) { let op = new OperationOutcome(); op.addIssue(error); @@ -98,7 +99,7 @@ class BatchValidateWorker extends TerminologyWorker { return res.json(result); } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); return res.status(error.statusCode || 500).json(this.operationOutcome( 'error', error.issueCode || 'exception', error.message)); } diff --git a/tx/workers/batch.js b/tx/workers/batch.js index 2a17c2bf..135b1297 100644 --- a/tx/workers/batch.js +++ b/tx/workers/batch.js @@ -6,6 +6,7 @@ const { TerminologyWorker } = require('./worker'); const { Issue, OperationOutcome } = require('../library/operation-outcome'); +const {debugLog} = require("../operation-context"); class BatchWorker extends TerminologyWorker { /** @@ -40,7 +41,7 @@ class BatchWorker extends TerminologyWorker { await this.handleBatch(req, res); } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); if (error instanceof Issue) { const oo = new OperationOutcome(); oo.addIssue(error); @@ -160,7 +161,7 @@ class BatchWorker extends TerminologyWorker { } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); const statusCode = error.statusCode || 500; const issueCode = error.issueCode || 'exception'; diff --git a/tx/workers/expand.js b/tx/workers/expand.js index 54ea309f..a2e6fe3a 100644 --- a/tx/workers/expand.js +++ b/tx/workers/expand.js @@ -18,6 +18,7 @@ const {Issue, OperationOutcome} = require("../library/operation-outcome"); const crypto = require('crypto'); const ValueSet = require("../library/valueset"); const {VersionUtilities} = require("../../library/version-utilities"); +const {debugLog} = require("../operation-context"); // Expansion limits (from Pascal constants) const EXTERNAL_DEFAULT_LIMIT = 1000; @@ -1730,7 +1731,7 @@ class ExpandWorker extends TerminologyWorker { await this.handleTypeLevelExpand(req, res); } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); req.logInfo = this.usedSources.join("|")+" - error"+(error.msgId ? " "+error.msgId : ""); const statusCode = error.statusCode || 500; if (error instanceof Issue) { @@ -1765,7 +1766,7 @@ class ExpandWorker extends TerminologyWorker { await this.handleInstanceLevelExpand(req, res); } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); req.logInfo = this.usedSources.join("|")+" - error"+(error.msgId ? " "+error.msgId : ""); const statusCode = error.statusCode || 500; const issueCode = error.issueCode || 'exception'; diff --git a/tx/workers/lookup.js b/tx/workers/lookup.js index 3373a511..0d7e3536 100644 --- a/tx/workers/lookup.js +++ b/tx/workers/lookup.js @@ -13,6 +13,7 @@ const { Designations} = require("../library/designations"); const {TxParameters} = require("../params"); const {Parameters} = require("../library/parameters"); const {Issue, OperationOutcome} = require("../library/operation-outcome"); +const {debugLog} = require("../operation-context"); class LookupWorker extends TerminologyWorker { /** @@ -45,7 +46,7 @@ class LookupWorker extends TerminologyWorker { await this.handleTypeLevelLookup(req, res); } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); req.logInfo = this.usedSources.join("|")+" - error"+(error.msgId ? " "+error.msgId : ""); const statusCode = error.statusCode || 500; const issueCode = error.issueCode || 'exception'; @@ -72,7 +73,7 @@ class LookupWorker extends TerminologyWorker { await this.handleInstanceLevelLookup(req, res); } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); req.logInfo = this.usedSources.join("|")+" - error"+(error.msgId ? " "+error.msgId : ""); const issueCode = error.issueCode || 'exception'; return res.status(400).json({ @@ -159,7 +160,7 @@ class LookupWorker extends TerminologyWorker { return res.status(200).json(result); } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); req.logInfo = this.usedSources.join("|")+" - error"+(error.msgId ? " "+error.msgId : ""); if (error instanceof Issue) { let oo = new OperationOutcome(); @@ -223,7 +224,7 @@ class LookupWorker extends TerminologyWorker { return res.status(200).json(result); } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); req.logInfo = this.usedSources.join("|")+" - error"+(error.msgId ? " "+error.msgId : ""); if (error instanceof Issue) { let oo = new OperationOutcome(); diff --git a/tx/workers/read.js b/tx/workers/read.js index cf47847b..0c3ba4c4 100644 --- a/tx/workers/read.js +++ b/tx/workers/read.js @@ -5,6 +5,7 @@ // const { TerminologyWorker } = require('./worker'); +const {debugLog} = require("../operation-context"); class ReadWorker extends TerminologyWorker { /** @@ -67,7 +68,7 @@ class ReadWorker extends TerminologyWorker { } } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); req.logInfo = this.usedSources.join("|")+" - error"+(error.msgId ? " "+error.msgId : ""); return res.status(500).json({ resourceType: 'OperationOutcome', diff --git a/tx/workers/related.js b/tx/workers/related.js index 4eab01a3..01abddd8 100644 --- a/tx/workers/related.js +++ b/tx/workers/related.js @@ -16,6 +16,7 @@ const ValueSet = require("../library/valueset"); const {ValueSetExpander} = require("./expand"); const {SearchFilterText} = require("../library/designations"); const {ArrayMatcher} = require("../../library/utilities"); +const {debugLog} = require("../operation-context"); class RelatedWorker extends TerminologyWorker { @@ -49,7 +50,7 @@ class RelatedWorker extends TerminologyWorker { await this.handleTypeLevelRelated(req, res); } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); req.logInfo = this.usedSources.join("|")+" - error"+(error.msgId ? " "+error.msgId : ""); const statusCode = error.statusCode || 500; if (error instanceof Issue) { @@ -84,7 +85,7 @@ class RelatedWorker extends TerminologyWorker { await this.handleInstanceLevelRelated(req, res); } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); req.logInfo = this.usedSources.join("|")+" - error"+(error.msgId ? " "+error.msgId : ""); const statusCode = error.statusCode || 500; const issueCode = error.issueCode || 'exception'; diff --git a/tx/workers/search.js b/tx/workers/search.js index 3f9ec2ba..f242158c 100644 --- a/tx/workers/search.js +++ b/tx/workers/search.js @@ -7,6 +7,7 @@ const { TerminologyWorker } = require('./worker'); const {Utilities} = require("../../library/utilities"); +const {debugLog} = require("../operation-context"); class SearchWorker extends TerminologyWorker { /** @@ -114,7 +115,7 @@ class SearchWorker extends TerminologyWorker { } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); req.logInfo = "error "+(error.msgId || error.className); return res.status(500).json({ resourceType: 'OperationOutcome', diff --git a/tx/workers/subsumes.js b/tx/workers/subsumes.js index 24e8a723..2c328fa0 100644 --- a/tx/workers/subsumes.js +++ b/tx/workers/subsumes.js @@ -12,6 +12,7 @@ const { FhirCodeSystemProvider } = require('../cs/cs-cs'); const {TxParameters} = require("../params"); const {Parameters} = require("../library/parameters"); const {Issue, OperationOutcome} = require("../library/operation-outcome"); +const {debugLog} = require("../operation-context"); class SubsumesWorker extends TerminologyWorker { /** * @param {OperationContext} opContext - Operation context @@ -43,7 +44,7 @@ class SubsumesWorker extends TerminologyWorker { await this.handleTypeLevelSubsumes(req, res); } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); req.logInfo = "error "+(error.msgId || error.className); if (error instanceof Issue) { let oo = new OperationOutcome(); @@ -67,7 +68,7 @@ class SubsumesWorker extends TerminologyWorker { await this.handleInstanceLevelSubsumes(req, res); } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); if (error instanceof Issue) { let oo = new OperationOutcome(); oo.addIssue(error); diff --git a/tx/workers/translate.js b/tx/workers/translate.js index cae686c7..f20b2490 100644 --- a/tx/workers/translate.js +++ b/tx/workers/translate.js @@ -12,6 +12,7 @@ const { TxParameters } = require('../params'); const { Parameters } = require('../library/parameters'); const { Issue, OperationOutcome } = require('../library/operation-outcome'); const {ConceptMap} = require("../library/conceptmap"); +const {debugLog} = require("../operation-context"); class TranslateWorker extends TerminologyWorker { /** @@ -44,7 +45,7 @@ class TranslateWorker extends TerminologyWorker { await this.handleTypeLevelTranslate(req, res); } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); if (error instanceof Issue) { const oo = new OperationOutcome(); oo.addIssue(error); @@ -67,7 +68,7 @@ class TranslateWorker extends TerminologyWorker { await this.handleInstanceLevelTranslate(req, res); } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); if (error instanceof Issue) { const oo = new OperationOutcome(); oo.addIssue(error); @@ -410,7 +411,7 @@ class TranslateWorker extends TerminologyWorker { } } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); result.push({ name: 'result', valueBoolean: false diff --git a/tx/workers/validate.js b/tx/workers/validate.js index d1a44db7..7535befa 100644 --- a/tx/workers/validate.js +++ b/tx/workers/validate.js @@ -24,6 +24,7 @@ const {ValueSetExpander} = require("./expand"); const {FhirCodeSystemProvider} = require("../cs/cs-cs"); const {CodeSystem} = require("../library/codesystem"); const {VersionUtilities} = require("../../library/version-utilities"); +const {debugLog} = require("../operation-context"); const DEV_IGNORE_VALUESET = false; // todo: what's going on with this (ported from pascal) @@ -124,7 +125,7 @@ class ValueSetChecker { } } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); throw new Error('Exception expanding value set in order to infer system: ' + error.message); } return result; @@ -1946,7 +1947,7 @@ class ValidateWorker extends TerminologyWorker { } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); if (error instanceof Issue) { if (error.isHandleAsOO()) { let oo = new OperationOutcome(); @@ -2005,7 +2006,7 @@ class ValidateWorker extends TerminologyWorker { return result; } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); if (error instanceof Issue && !error.isHandleAsOO()) { return await this.handlePrepareError(error, coded, mode.mode, txp); } else { @@ -2064,7 +2065,7 @@ class ValidateWorker extends TerminologyWorker { } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); return res.status(error.statusCode || 500).json(this.operationOutcome( 'error', error.issueCode || 'exception', error.message)); } @@ -2085,7 +2086,7 @@ class ValidateWorker extends TerminologyWorker { } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); if (error instanceof Issue) { let op = new OperationOutcome(); op.addIssue(error); @@ -2165,7 +2166,7 @@ class ValidateWorker extends TerminologyWorker { } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); return res.status(error.statusCode || 500).json(this.operationOutcome( 'error', error.issueCode || 'exception', error.message)); } @@ -2405,7 +2406,7 @@ class ValidateWorker extends TerminologyWorker { await checker.prepare(); } catch (error) { this.log.error(error); - this.debugLog(error); + debugLog(error); if (!(error instanceof Issue) || error.isHandleAsOO()) { throw error; } else {