fhirsmith 0.4.2 → 0.5.1

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 (92) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +1 -1
  3. package/library/cron-utilities.js +136 -0
  4. package/library/html-server.js +13 -29
  5. package/library/html.js +3 -8
  6. package/library/languages.js +160 -37
  7. package/library/package-manager.js +48 -1
  8. package/library/utilities.js +100 -19
  9. package/package.json +2 -2
  10. package/packages/package-crawler.js +6 -1
  11. package/packages/packages.js +38 -54
  12. package/publisher/publisher.js +19 -27
  13. package/registry/api.js +11 -10
  14. package/registry/crawler.js +31 -29
  15. package/registry/model.js +5 -26
  16. package/registry/registry.js +32 -41
  17. package/server.js +89 -12
  18. package/shl/shl.js +0 -18
  19. package/static/assets/js/statuspage.js +1 -9
  20. package/stats.js +39 -1
  21. package/token/token.js +14 -9
  22. package/translations/Messages.properties +2 -1
  23. package/tx/README.md +17 -6
  24. package/tx/cs/cs-api.js +19 -1
  25. package/tx/cs/cs-base.js +77 -0
  26. package/tx/cs/cs-country.js +46 -0
  27. package/tx/cs/cs-cpt.js +9 -5
  28. package/tx/cs/cs-cs.js +27 -13
  29. package/tx/cs/cs-lang.js +60 -22
  30. package/tx/cs/cs-loinc.js +69 -98
  31. package/tx/cs/cs-mimetypes.js +4 -0
  32. package/tx/cs/cs-ndc.js +6 -0
  33. package/tx/cs/cs-omop.js +16 -15
  34. package/tx/cs/cs-rxnorm.js +23 -1
  35. package/tx/cs/cs-snomed.js +283 -40
  36. package/tx/cs/cs-ucum.js +90 -70
  37. package/tx/importers/import-sct.module.js +371 -35
  38. package/tx/importers/readme.md +117 -7
  39. package/tx/library/bundle.js +5 -0
  40. package/tx/library/capabilitystatement.js +3 -142
  41. package/tx/library/codesystem.js +19 -173
  42. package/tx/library/conceptmap.js +4 -218
  43. package/tx/library/designations.js +14 -1
  44. package/tx/library/extensions.js +7 -0
  45. package/tx/library/namingsystem.js +3 -89
  46. package/tx/library/operation-outcome.js +8 -3
  47. package/tx/library/parameters.js +3 -2
  48. package/tx/library/renderer.js +10 -6
  49. package/tx/library/terminologycapabilities.js +3 -243
  50. package/tx/library/valueset.js +3 -235
  51. package/tx/library.js +100 -13
  52. package/tx/operation-context.js +23 -4
  53. package/tx/params.js +35 -38
  54. package/tx/provider.js +6 -5
  55. package/tx/sct/expressions.js +12 -3
  56. package/tx/tx-html.js +80 -89
  57. package/tx/tx.fhir.org.yml +6 -5
  58. package/tx/tx.js +163 -13
  59. package/tx/vs/vs-database.js +56 -39
  60. package/tx/vs/vs-package.js +21 -2
  61. package/tx/vs/vs-vsac.js +175 -39
  62. package/tx/workers/batch-validate.js +2 -0
  63. package/tx/workers/batch.js +2 -0
  64. package/tx/workers/expand.js +132 -112
  65. package/tx/workers/lookup.js +33 -14
  66. package/tx/workers/metadata.js +2 -2
  67. package/tx/workers/read.js +3 -2
  68. package/tx/workers/related.js +574 -0
  69. package/tx/workers/search.js +46 -9
  70. package/tx/workers/subsumes.js +13 -3
  71. package/tx/workers/translate.js +7 -3
  72. package/tx/workers/validate.js +258 -285
  73. package/tx/workers/worker.js +43 -39
  74. package/tx/xml/bundle-xml.js +237 -0
  75. package/tx/xml/xml-base.js +215 -64
  76. package/tx/xversion/xv-bundle.js +71 -0
  77. package/tx/xversion/xv-capabiliityStatement.js +137 -0
  78. package/tx/xversion/xv-codesystem.js +169 -0
  79. package/tx/xversion/xv-conceptmap.js +224 -0
  80. package/tx/xversion/xv-namingsystem.js +88 -0
  81. package/tx/xversion/xv-operationoutcome.js +27 -0
  82. package/tx/xversion/xv-parameters.js +87 -0
  83. package/tx/xversion/xv-resource.js +45 -0
  84. package/tx/xversion/xv-terminologyCapabilities.js +214 -0
  85. package/tx/xversion/xv-valueset.js +234 -0
  86. package/utilities/dev-proxy-server.js +126 -0
  87. package/utilities/explode-results.js +58 -0
  88. package/utilities/split-by-system.js +198 -0
  89. package/utilities/vsac-cs-fetcher.js +0 -0
  90. package/{windows-install.js → utilities/windows-install.js} +2 -0
  91. package/vcl/vcl.js +0 -18
  92. package/xig/xig.js +241 -230
@@ -1,4 +1,4 @@
1
- const {VersionUtilities} = require("../../library/version-utilities");
1
+ const {namingSystemToR5, namingSystemFromR5} = require("../xversion/xv-namingsystem");
2
2
 
3
3
  /**
4
4
  * Represents a FHIR NamingSystem resource with version conversion support
@@ -40,7 +40,7 @@ class NamingSystem {
40
40
  constructor(jsonObj, version = 'R5') {
41
41
  this.version = version;
42
42
  // Convert to R5 format internally (modifies input for performance)
43
- this.jsonObj = this._convertToR5(jsonObj, version);
43
+ this.jsonObj = namingSystemToR5(jsonObj, version);
44
44
  this.validate();
45
45
  }
46
46
 
@@ -50,96 +50,10 @@ class NamingSystem {
50
50
  * @returns {string} JSON string
51
51
  */
52
52
  toJSONString(version = 'R5') {
53
- const outputObj = this._convertFromR5(this.jsonObj, version);
53
+ const outputObj = namingSystemFromR5(this.jsonObj, version);
54
54
  return JSON.stringify(outputObj);
55
55
  }
56
56
 
57
- /**
58
- * Converts input NamingSystem to R5 format (modifies input object for performance)
59
- * @param {Object} jsonObj - The input NamingSystem object
60
- * @param {string} version - Source FHIR version
61
- * @returns {Object} The same object, potentially modified to R5 format
62
- * @private
63
- */
64
- _convertToR5(jsonObj, version) {
65
- if (version === 'R5') {
66
- return jsonObj; // Already R5, no conversion needed
67
- }
68
-
69
- if (version === 'R3') {
70
- // R3 to R5: Remove replacedBy field (we ignore it completely)
71
- if (jsonObj.replacedBy !== undefined) {
72
- delete jsonObj.replacedBy;
73
- }
74
- return jsonObj;
75
- }
76
-
77
- if (version === 'R4') {
78
- // R4 to R5: No structural conversion needed
79
- // R5 is backward compatible for the structural elements we care about
80
- return jsonObj;
81
- }
82
-
83
- throw new Error(`Unsupported FHIR version: ${version}`);
84
- }
85
-
86
- /**
87
- * Converts R5 NamingSystem to target version format (clones object first)
88
- * @param {Object} r5Obj - The R5 format NamingSystem object
89
- * @param {string} targetVersion - Target FHIR version
90
- * @returns {Object} New object in target version format
91
- * @private
92
- */
93
- _convertFromR5(r5Obj, targetVersion) {
94
- if (VersionUtilities.isR5Ver(targetVersion)) {
95
- return r5Obj; // No conversion needed
96
- }
97
-
98
- // Clone the object to avoid modifying the original
99
- const cloned = JSON.parse(JSON.stringify(r5Obj));
100
-
101
- if (VersionUtilities.isR4Ver(targetVersion)) {
102
- return this._convertR5ToR4(cloned);
103
- } else if (VersionUtilities.isR3Ver(targetVersion)) {
104
- return this._convertR5ToR3(cloned);
105
- }
106
-
107
- throw new Error(`Unsupported target FHIR version: ${targetVersion}`);
108
- }
109
-
110
- /**
111
- * Converts R5 NamingSystem to R4 format
112
- * @param {Object} r5Obj - Cloned R5 NamingSystem object
113
- * @returns {Object} R4 format NamingSystem
114
- * @private
115
- */
116
- _convertR5ToR4(r5Obj) {
117
- // Remove R5-specific elements that don't exist in R4
118
- if (r5Obj.versionAlgorithmString) {
119
- delete r5Obj.versionAlgorithmString;
120
- }
121
- if (r5Obj.versionAlgorithmCoding) {
122
- delete r5Obj.versionAlgorithmCoding;
123
- }
124
-
125
- return r5Obj;
126
- }
127
-
128
- /**
129
- * Converts R5 NamingSystem to R3 format
130
- * @param {Object} r5Obj - Cloned R5 NamingSystem object
131
- * @returns {Object} R3 format NamingSystem
132
- * @private
133
- */
134
- _convertR5ToR3(r5Obj) {
135
- // First apply R4 conversions
136
- const r4Obj = this._convertR5ToR4(r5Obj);
137
-
138
- // R3 doesn't have some R4/R5 fields, but we'll just let them through
139
- // since most additions are backward compatible in JSON
140
-
141
- return r4Obj;
142
- }
143
57
 
144
58
  /**
145
59
  * Gets the FHIR version this NamingSystem was loaded from
@@ -28,9 +28,10 @@ class Issue extends Error {
28
28
  code: this.cause,
29
29
  details: {
30
30
  text: this.message
31
- },
32
- location: [ this.path ],
33
- expression: [ this.path ]
31
+ }
32
+ }
33
+ if (this.path) {
34
+ res.expression = [this.path]
34
35
  }
35
36
  if (this.issueCode) {
36
37
  res.details.coding = [{ system: "http://hl7.org/fhir/tools/CodeSystem/tx-issue-type", code : this.issueCode }];
@@ -82,6 +83,10 @@ class OperationOutcome {
82
83
  this.jsonObj = jsonObj ? jsonObj : { "resourceType": "OperationOutcome" };
83
84
  }
84
85
 
86
+ addIssueIfNew(newIssue) {
87
+ return this.addIssue(newIssue, true);
88
+ }
89
+
85
90
  addIssue(newIssue, ifNotDuplicate = false) {
86
91
  validateParameter(newIssue, "newIssue", Object);
87
92
  if (ifNotDuplicate) {
@@ -1,10 +1,11 @@
1
1
  const {getValuePrimitive, getValueDT} = require("../../library/utilities");
2
+ const {parametersToR5} = require("../xversion/xv-parameters");
2
3
 
3
4
  class Parameters {
4
5
  jsonObj;
5
6
 
6
- constructor (jsonObj = null) {
7
- this.jsonObj = jsonObj ? jsonObj : { "resourceType": "Parameters" };
7
+ constructor (jsonObj = null, fhirVersion = 'R5') {
8
+ this.jsonObj = parametersToR5(jsonObj ? jsonObj : { "resourceType": "Parameters" }, fhirVersion);
8
9
  }
9
10
 
10
11
  addParamStr(name, value) {
@@ -24,7 +24,7 @@ class Renderer {
24
24
  if (arg.systemUri !== undefined && arg.version !== undefined && arg.code !== undefined && arg.display !== undefined) {
25
25
  // It's a Coding
26
26
  return this.displayCodedCoding(arg);
27
- } else if (arg.coding !== undefined) {
27
+ } else if (arg.coding !== undefined || arg.text) {
28
28
  // It's a CodeableConcept
29
29
  return this.displayCodedCodeableConcept(arg);
30
30
  } else if (arg.systemUri !== undefined && arg.version !== undefined) {
@@ -74,11 +74,15 @@ class Renderer {
74
74
 
75
75
  displayCodedCodeableConcept(code) {
76
76
  let result = '';
77
- for (const c of code.coding) {
78
- if (result) {
79
- result = result + ', ';
77
+ if (code.text && !code.coding) {
78
+ result = '"'+code.text+'"';
79
+ } else {
80
+ for (const c of code.coding || []) {
81
+ if (result) {
82
+ result = result + ', ';
83
+ }
84
+ result = result + this.displayCodedCoding(c);
80
85
  }
81
- result = result + this.displayCodedCoding(c);
82
86
  }
83
87
  return '[' + result + ']';
84
88
  }
@@ -1280,7 +1284,7 @@ class Renderer {
1280
1284
  return div_.toString();
1281
1285
  }
1282
1286
 
1283
- async renderCapabilityRest(x, rest, cs) {
1287
+ async renderCapabilityRest(x, rest) {
1284
1288
  x.h3().tx(`REST ${rest.mode || 'server'} Definition`);
1285
1289
 
1286
1290
  if (rest.documentation) {
@@ -1,5 +1,5 @@
1
1
  const {CanonicalResource} = require("./canonical-resource");
2
- const {VersionUtilities} = require("../../library/version-utilities");
2
+ const {terminologyCapabilitiesToR5, terminologyCapabilitiesFromR5} = require("../xversion/xv-terminologyCapabilities");
3
3
 
4
4
  /**
5
5
  * Represents a FHIR TerminologyCapabilities resource with version conversion support.
@@ -17,7 +17,7 @@ class TerminologyCapabilities extends CanonicalResource {
17
17
  constructor(jsonObj, fhirVersion = 'R5') {
18
18
  super(jsonObj, fhirVersion);
19
19
  // Convert to R5 format internally (modifies input for performance)
20
- this.jsonObj = this._convertToR5(jsonObj, fhirVersion);
20
+ this.jsonObj = terminologyCapabilitiesToR5(jsonObj, fhirVersion);
21
21
  this.validate();
22
22
  this.id = this.jsonObj.id;
23
23
  }
@@ -38,7 +38,7 @@ class TerminologyCapabilities extends CanonicalResource {
38
38
  * @returns {string} JSON string
39
39
  */
40
40
  toJSONString(version = 'R5') {
41
- const outputObj = this._convertFromR5(this.jsonObj, version);
41
+ const outputObj = terminologyCapabilitiesFromR5(this.jsonObj, version);
42
42
  return JSON.stringify(outputObj);
43
43
  }
44
44
 
@@ -51,246 +51,6 @@ class TerminologyCapabilities extends CanonicalResource {
51
51
  return this._convertFromR5(this.jsonObj, version);
52
52
  }
53
53
 
54
- /**
55
- * Converts input TerminologyCapabilities to R5 format (modifies input object for performance)
56
- * @param {Object} jsonObj - The input TerminologyCapabilities object
57
- * @param {string} version - Source FHIR version
58
- * @returns {Object} The same object, potentially modified to R5 format
59
- * @private
60
- */
61
- _convertToR5(jsonObj, version) {
62
- if (version === 'R5') {
63
- return jsonObj; // Already R5, no conversion needed
64
- }
65
-
66
- if (version === 'R4') {
67
- // R4 to R5: No major structural changes needed for TerminologyCapabilities
68
- return jsonObj;
69
- }
70
-
71
- if (VersionUtilities.isR3Ver(version)) {
72
- // R3: TerminologyCapabilities doesn't exist - it's a Parameters resource
73
- // Convert from Parameters format to TerminologyCapabilities
74
- return this._convertParametersToR5(jsonObj);
75
- }
76
-
77
- throw new Error(`Unsupported FHIR version: ${version}`);
78
- }
79
-
80
- /**
81
- * Converts R3 Parameters format to R5 TerminologyCapabilities
82
- * @param {Object} params - The Parameters resource
83
- * @returns {Object} TerminologyCapabilities in R5 format
84
- * @private
85
- */
86
- _convertParametersToR5(params) {
87
- if (params.resourceType !== 'Parameters') {
88
- throw new Error('R3 TerminologyCapabilities must be a Parameters resource');
89
- }
90
-
91
- const result = {
92
- resourceType: 'TerminologyCapabilities',
93
- id: params.id,
94
- status: 'active', // Default, as Parameters doesn't carry this
95
- kind: 'instance', // Default for terminology server capabilities
96
- codeSystem: []
97
- };
98
-
99
- const parameters = params.parameter || [];
100
- let currentSystem = null;
101
-
102
- for (const param of parameters) {
103
- switch (param.name) {
104
- case 'url':
105
- result.url = param.valueUri;
106
- break;
107
- case 'version':
108
- if (currentSystem) {
109
- // This is a code system version
110
- if (param.valueCode) {
111
- currentSystem.version = currentSystem.version || [];
112
- currentSystem.version.push({ code: param.valueCode });
113
- }
114
- // Empty version parameter means no specific version
115
- } else {
116
- // This is the TerminologyCapabilities version
117
- result.version = param.valueCode || param.valueString;
118
- }
119
- break;
120
- case 'date':
121
- result.date = param.valueDateTime;
122
- break;
123
- case 'system':
124
- // Start a new code system
125
- currentSystem = { uri: param.valueUri };
126
- result.codeSystem.push(currentSystem);
127
- break;
128
- case 'expansion.parameter':
129
- result.expansion = result.expansion || { parameter: [] };
130
- result.expansion.parameter.push({ name: param.valueCode });
131
- break;
132
- }
133
- }
134
-
135
- return result;
136
- }
137
-
138
- /**
139
- * Converts R5 TerminologyCapabilities to target version format (clones object first)
140
- * @param {Object} r5Obj - The R5 format TerminologyCapabilities object
141
- * @param {string} targetVersion - Target FHIR version
142
- * @returns {Object} New object in target version format
143
- * @private
144
- */
145
- _convertFromR5(r5Obj, targetVersion) {
146
- if (VersionUtilities.isR5Ver(targetVersion)) {
147
- return r5Obj; // No conversion needed
148
- }
149
-
150
- // Clone the object to avoid modifying the original
151
- const cloned = JSON.parse(JSON.stringify(r5Obj));
152
-
153
- if (VersionUtilities.isR4Ver(targetVersion)) {
154
- return this._convertR5ToR4(cloned);
155
- } else if (VersionUtilities.isR3Ver(targetVersion)) {
156
- return this._convertR5ToR3(cloned);
157
- }
158
-
159
- throw new Error(`Unsupported target FHIR version: ${targetVersion}`);
160
- }
161
-
162
- /**
163
- * Converts R5 TerminologyCapabilities to R4 format
164
- * @param {Object} r5Obj - Cloned R5 TerminologyCapabilities object
165
- * @returns {Object} R4 format TerminologyCapabilities
166
- * @private
167
- */
168
- _convertR5ToR4(r5Obj) {
169
- // Remove R5-specific elements
170
- if (r5Obj.versionAlgorithmString) {
171
- delete r5Obj.versionAlgorithmString;
172
- }
173
- if (r5Obj.versionAlgorithmCoding) {
174
- delete r5Obj.versionAlgorithmCoding;
175
- }
176
-
177
- // Convert valueCanonical to valueUri throughout the object
178
- this._convertCanonicalToUri(r5Obj);
179
-
180
- return r5Obj;
181
- }
182
-
183
- /**
184
- * Converts R5 TerminologyCapabilities to R3 format (Parameters resource)
185
- * In R3, TerminologyCapabilities didn't exist - we represent it as a Parameters resource
186
- * @param {Object} r5Obj - Cloned R5 TerminologyCapabilities object
187
- * @returns {Object} R3 format Parameters resource
188
- * @private
189
- */
190
- _convertR5ToR3(r5Obj) {
191
- const params = {
192
- resourceType: 'Parameters',
193
- id: r5Obj.id,
194
- parameter: []
195
- };
196
-
197
- // Add url parameter
198
- if (r5Obj.url) {
199
- params.parameter.push({
200
- name: 'url',
201
- valueUri: r5Obj.url
202
- });
203
- }
204
-
205
- // Add version parameter
206
- if (r5Obj.version) {
207
- params.parameter.push({
208
- name: 'version',
209
- valueCode: r5Obj.version
210
- });
211
- }
212
-
213
- // Add date parameter
214
- if (r5Obj.date) {
215
- params.parameter.push({
216
- name: 'date',
217
- valueDateTime: r5Obj.date
218
- });
219
- }
220
-
221
- // Add code systems with their versions
222
- for (const codeSystem of r5Obj.codeSystem || []) {
223
- // Add system parameter
224
- params.parameter.push({
225
- name: 'system',
226
- valueUri: codeSystem.uri
227
- });
228
-
229
- // Add version parameter(s) for this code system
230
- if (codeSystem.version && codeSystem.version.length > 0) {
231
- for (const ver of codeSystem.version) {
232
- if (ver.code) {
233
- params.parameter.push({
234
- name: 'version',
235
- valueCode: ver.code
236
- });
237
- } else {
238
- // Empty version parameter when no specific version
239
- params.parameter.push({
240
- name: 'version'
241
- });
242
- }
243
- }
244
- } else {
245
- // No version specified for this code system
246
- params.parameter.push({
247
- name: 'version'
248
- });
249
- }
250
- }
251
-
252
- // Add expansion parameters
253
- if (r5Obj.expansion && r5Obj.expansion.parameter) {
254
- for (const expParam of r5Obj.expansion.parameter) {
255
- params.parameter.push({
256
- name: 'expansion.parameter',
257
- valueCode: expParam.name
258
- });
259
- }
260
- }
261
-
262
- return params;
263
- }
264
-
265
- /**
266
- * Recursively converts valueCanonical to valueUri in an object
267
- * R3/R4 doesn't have canonical type in the same way, so valueCanonical must become valueUri
268
- * @param {Object} obj - Object to convert
269
- * @private
270
- */
271
- _convertCanonicalToUri(obj) {
272
- if (!obj || typeof obj !== 'object') {
273
- return;
274
- }
275
-
276
- if (Array.isArray(obj)) {
277
- obj.forEach(item => this._convertCanonicalToUri(item));
278
- return;
279
- }
280
-
281
- // Convert valueCanonical to valueUri
282
- if (obj.valueCanonical !== undefined) {
283
- obj.valueUri = obj.valueCanonical;
284
- delete obj.valueCanonical;
285
- }
286
-
287
- // Recurse into all properties
288
- for (const key of Object.keys(obj)) {
289
- if (typeof obj[key] === 'object') {
290
- this._convertCanonicalToUri(obj[key]);
291
- }
292
- }
293
- }
294
54
 
295
55
  /**
296
56
  * Validates that this is a proper TerminologyCapabilities resource