fhirsmith 0.17.0 → 0.18.0

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 (121) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/README.md +80 -13
  3. package/config-template.json +106 -1
  4. package/ips/ai-client.js +263 -0
  5. package/ips/composer.js +805 -0
  6. package/ips/editor-schema.js +289 -0
  7. package/ips/editor.js +290 -0
  8. package/ips/fhirpath-ips.js +397 -0
  9. package/ips/ips-codeable-concepts.md +1742 -0
  10. package/ips/ips-template.html +125 -0
  11. package/ips/ips-valuesets.js +159 -0
  12. package/ips/ips.js +1736 -0
  13. package/ips/membership.js +179 -0
  14. package/ips/pipeline.js +1012 -0
  15. package/ips/presenter.js +974 -0
  16. package/ips/profile-editor.js +578 -0
  17. package/ips/profiles.js +506 -0
  18. package/ips/readme.md +460 -0
  19. package/ips/render.js +1482 -0
  20. package/ips/search-params.js +83 -0
  21. package/ips/search.js +667 -0
  22. package/ips/share.js +178 -0
  23. package/ips/store.js +650 -0
  24. package/ips/terminology.js +395 -0
  25. package/ips/tx-client.js +202 -0
  26. package/ips/valuesets/CodeSystem-absent-unknown-uv-ips.json +206 -0
  27. package/ips/valuesets/ValueSet-absent-or-unknown-immunizations-uv-ips.json +59 -0
  28. package/ips/valuesets/ValueSet-ips-allergy-code.json +59 -0
  29. package/ips/valuesets/ValueSet-ips-allergy-manifestation.json +356 -0
  30. package/ips/valuesets/ValueSet-ips-allergy-substance.json +37 -0
  31. package/ips/valuesets/ValueSet-ips-body-site.json +26 -0
  32. package/ips/valuesets/ValueSet-ips-clinical-finding-or-none.json +35 -0
  33. package/ips/valuesets/ValueSet-ips-clinical-finding.json +26 -0
  34. package/ips/valuesets/ValueSet-ips-condition-code.json +72 -0
  35. package/ips/valuesets/ValueSet-ips-condition-severity.json +30 -0
  36. package/ips/valuesets/ValueSet-ips-condition-stage.json +26 -0
  37. package/ips/valuesets/ValueSet-ips-exposure-route.json +26 -0
  38. package/ips/valuesets/ValueSet-ips-imaging-procedure.json +25 -0
  39. package/ips/valuesets/ValueSet-ips-immunization-status-reason.json +43 -0
  40. package/ips/valuesets/ValueSet-ips-international-codes.json +25 -0
  41. package/ips/valuesets/ValueSet-ips-medication-ingredient.json +26 -0
  42. package/ips/valuesets/ValueSet-ips-medication-status-reason.json +37 -0
  43. package/ips/valuesets/ValueSet-ips-medication.json +50 -0
  44. package/ips/valuesets/ValueSet-ips-observation-code.json +18 -0
  45. package/ips/valuesets/ValueSet-ips-observation-interpretation.json +18 -0
  46. package/ips/valuesets/ValueSet-ips-procedure-followup.json +51 -0
  47. package/ips/valuesets/ValueSet-ips-procedure-outcome.json +30 -0
  48. package/ips/valuesets/ValueSet-ips-procedure-reason.json +37 -0
  49. package/ips/valuesets/ValueSet-ips-procedure.json +116 -0
  50. package/ips/valuesets/ValueSet-ips-route.json +46 -0
  51. package/ips/valuesets/ValueSet-ips-target-disease.json +171 -0
  52. package/ips/valuesets/ValueSet-ips-vaccine.json +31 -0
  53. package/ips/valuesets/elements.json +44 -0
  54. package/library/daily-report.js +422 -0
  55. package/library/fhir-search-values.js +138 -0
  56. package/library/html-server.js +32 -23
  57. package/library/mailer.js +77 -0
  58. package/library/narrative-check.js +21 -2
  59. package/library/npm-audit.js +25 -0
  60. package/library/package-manager.js +4 -2
  61. package/library/sqlite-session-store.js +29 -1
  62. package/package.json +7 -2
  63. package/packages/packages.js +34 -3
  64. package/publisher/publisher.js +29 -0
  65. package/registry/auth-store.js +366 -0
  66. package/registry/auth.js +872 -0
  67. package/registry/crawler.js +41 -1
  68. package/registry/documentation/api.md +162 -0
  69. package/registry/documentation/configuration.md +93 -0
  70. package/registry/documentation/documents.md +74 -0
  71. package/registry/documentation/internals.md +151 -0
  72. package/registry/documentation/readme.md +100 -0
  73. package/registry/documentation/security.md +199 -0
  74. package/registry/documents.js +309 -0
  75. package/registry/openapi.yaml +30 -0
  76. package/registry/registry-template.html +1 -1
  77. package/registry/registry.js +230 -44
  78. package/registry/uptime.js +154 -0
  79. package/server.js +105 -44
  80. package/shl/shl.js +64 -9
  81. package/stats-db.js +93 -0
  82. package/stats.js +158 -1
  83. package/testing/search.js +2 -108
  84. package/testing/store.js +5 -0
  85. package/testing/testing.js +20 -0
  86. package/token/token-template.html +5 -4
  87. package/token/token.js +17 -10
  88. package/translations/Messages.properties +9 -0
  89. package/tx/README.md +52 -0
  90. package/tx/cs/cs-api.js +90 -14
  91. package/tx/cs/cs-cs.js +56 -1
  92. package/tx/cs/cs-icd11.js +366 -112
  93. package/tx/cs/cs-icf.js +418 -0
  94. package/tx/cs/cs-loinc.js +47 -25
  95. package/tx/cs/cs-omop.js +10 -3
  96. package/tx/cs/cs-snomed.js +918 -55
  97. package/tx/cs/cs-ucum.js +6 -0
  98. package/tx/cs/icd11-expressions.js +191 -78
  99. package/tx/importers/export-icd11-codesystem.js +58 -12
  100. package/tx/importers/icd11-schema.md +9 -5
  101. package/tx/library.js +98 -4
  102. package/tx/openapi-operations.js +4 -0
  103. package/tx/params.js +8 -1
  104. package/tx/provider.js +16 -4
  105. package/tx/sct/documentation.md +251 -0
  106. package/tx/sct/ecl.js +758 -46
  107. package/tx/sct/expressions.js +113 -52
  108. package/tx/syndication/syndication-feed.js +218 -0
  109. package/tx/syndication/syndication-store.js +415 -0
  110. package/tx/tx-html.js +15 -1
  111. package/tx/tx.fhir.org.yml +2 -3
  112. package/tx/tx.js +144 -2
  113. package/tx/vs/vs-vsac.js +25 -6
  114. package/tx/workers/expand.js +33 -6
  115. package/tx/workers/lookup.js +61 -6
  116. package/tx/workers/subsumes.js +1 -1
  117. package/tx/workers/translate.js +166 -15
  118. package/tx/workers/validate.js +128 -6
  119. package/utilities/make-sct-test-extension.js +264 -0
  120. package/xig/xig.js +32 -0
  121. package/registry/readme.md +0 -124
package/tx/cs/cs-api.js CHANGED
@@ -67,19 +67,89 @@ class CodeSystemProvider {
67
67
  */
68
68
 
69
69
  /**
70
- * The display name of the code system - what $lookup reports as its name parameter, and
71
- * what a person reads. Every provider should override this; the fallback is the
72
- * versioned uri, which is not a name, and a provider that forgets ends up reporting
70
+ * The name of the code system (CodeSystem.name, or the provider's equivalent). Every
71
+ * provider should override this; the fallback is the versioned uri, which is not a name,
72
+ * and a provider that forgets ends up reporting
73
73
  * "http://snomed.info/sct|http://snomed.info/sct/731000124108/version/20230301" where
74
74
  * the others report "LOINC".
75
+ * @returns {string} name of the code system
76
+ */
77
+ name() { return this.system() + (this.version() ? "|"+this.version() : "") }
78
+
79
+ /**
80
+ * What $lookup reports as its `name` parameter - "a display name for the code system".
81
+ * That is the title, translated into the request's language where the provider can,
82
+ * falling back to name(). Only $lookup uses this; everything else keeps using name().
83
+ * The default has no title to offer, so it is name().
84
+ * @param {Languages} [languages] - the request's working languages (displayLanguage, else
85
+ * Accept-Language)
75
86
  * @returns {string} display name for the code system
76
87
  */
88
+ // eslint-disable-next-line no-unused-vars
89
+ lookupName(languages) { return this.name(); }
90
+
91
+ /**
92
+ * A second, shorter form of the code that some code systems also carry - ICD-11's short
93
+ * classification code (1A00) beside its code, the entity uri. $validate-code reports it as
94
+ * the classificationCode output parameter when the request used the code itself, and
95
+ * $expand always reports it as a contains property. Null (the default) when there is none.
96
+ * @param {CodeSystemProviderContext} context
97
+ * @returns {Promise<string|null>}
98
+ */
99
+ // eslint-disable-next-line no-unused-vars
100
+ async classificationCode(context) { return null; }
101
+
77
102
  /**
78
- * @param {Languages} [languages] - the request's working languages, for a provider whose name
79
- * is translated; the default ignores them
103
+ * The classificationCode $validate-code reports for a code as it was given: by default the
104
+ * concept's classificationCode, whatever spelling was used.
105
+ * @param {CodeSystemProviderContext} context the concept the code located
106
+ * @param {string} code the code as given
107
+ * @returns {Promise<string|null>}
80
108
  */
81
109
  // eslint-disable-next-line no-unused-vars
82
- name(languages) { return this.system() + (this.version() ? "|"+this.version() : "") }
110
+ async reportedClassificationCode(context, code) { return this.classificationCode(context); }
111
+
112
+ /**
113
+ * The code to put in an expansion for a concept the value set enumerated as `requested`.
114
+ * The default keeps the value set's own spelling; a code system whose normal form differs
115
+ * from what a value set may write (ICD-11: short code vs entity uri) returns code().
116
+ * @param {CodeSystemProviderContext} context
117
+ * @param {string} requested - the code as the value set wrote it
118
+ * @returns {Promise<string>}
119
+ */
120
+ // eslint-disable-next-line no-unused-vars
121
+ async expansionCode(context, requested) { return requested; }
122
+
123
+ /**
124
+ * Properties an expansion carries on every contains entry whatever the request asked
125
+ * for (each must also come back from properties()). None by default.
126
+ * @returns {string[]}
127
+ */
128
+ mandatoryExpansionProperties() { return []; }
129
+
130
+ /**
131
+ * Check the extensions on a Coding that this code system defines - ICD-11's
132
+ * classificationCode, say. Called by $validate-code once the coding's code has validated.
133
+ * Extensions the code system does not define are not its business, and are ignored.
134
+ *
135
+ * @param {Object} coding the Coding as given
136
+ * @param {CodeSystemProviderContext} context the concept the code located
137
+ * @returns {Promise<{index: number, msgId: string, params: string[]}[]>} one entry per problem,
138
+ * naming the extension (its index in coding.extension) and the message; none by default
139
+ */
140
+ // eslint-disable-next-line no-unused-vars
141
+ async checkCodingExtensions(coding, context) { return []; }
142
+
143
+ /**
144
+ * Things $validate-code should say about a code that is valid - for a postcoordinated
145
+ * expression, say, a qualifier the grammar allows but a rule of the code system does not
146
+ * (ICD-11: two values on an axis that takes one).
147
+ *
148
+ * @param {CodeSystemProviderContext} context the concept the code located
149
+ * @returns {Promise<{severity: string, msgId: string, params: string[]}[]>} none by default
150
+ */
151
+ // eslint-disable-next-line no-unused-vars
152
+ async codeIssues(context) { return []; }
83
153
 
84
154
  /**
85
155
  * @returns {string} uri for the code system
@@ -540,9 +610,11 @@ class CodeSystemProvider {
540
610
  * @param {CodeSystemProviderContext} ctxt the context to add properties for
541
611
  * @param {string[]} props the properties requested
542
612
  * @param {Parameters} params the parameters response to add to
613
+ * @param {TxParameters} [txParams] the parsed request parameters, for providers whose output
614
+ * depends on more than the property list (ICD-11's post-coordination-metadata)
543
615
  */
544
-
545
- async extendLookup(ctxt, props, params) { }
616
+ // eslint-disable-next-line no-unused-vars
617
+ async extendLookup(ctxt, props, params, txParams) { }
546
618
 
547
619
  // procedure getCDSInfo(card : TCDSHookCard; langList : THTTPLanguageList; baseURL, code, display : String); virtual;
548
620
 
@@ -954,15 +1026,19 @@ class CodeSystemFactoryProvider {
954
1026
  }
955
1027
 
956
1028
  /**
957
- * build and return a known concept map from the URL, if there is one.
1029
+ * Add any concept maps this code system implies for translating from source
1030
+ * (a system URI, with the version of the source coding, which may be empty)
1031
+ * to dest (a system URI, possibly with |version).
958
1032
  *
959
- * the conceptmap is never visible to a user; if it has an implicitSource, then
1033
+ * The conceptmap is never visible to a user; if it has an internalSource, then
960
1034
  * provider.getTranslations will be called when it's actually used
961
- * @param url
962
- * @param version
963
- * @returns {ConceptMap}
1035
+ * @param conceptMaps - the list to add to
1036
+ * @param source - the source system URI
1037
+ * @param sourceVersion - the version of the source coding (may be null)
1038
+ * @param dest - the target system URI, possibly with |version
964
1039
  */
965
- async findImplicitConceptMaps(conceptMaps, source, dest) {
1040
+ // eslint-disable-next-line no-unused-vars
1041
+ async findImplicitConceptMaps(conceptMaps, source, sourceVersion, dest) {
966
1042
  return null;
967
1043
  }
968
1044
 
package/tx/cs/cs-cs.js CHANGED
@@ -171,7 +171,35 @@ class FhirCodeSystemProviderFilterContext {
171
171
  }
172
172
  }
173
173
 
174
+ // Code systems loaded as ordinary CodeSystem resources (from a package, or supplied by a
175
+ // client) that need behaviour beyond the resource: a grammar, say. Keyed on the CodeSystem
176
+ // url; the class extends FhirCodeSystemProvider, so the content still comes from the
177
+ // resource. Required lazily, because the subclasses require this module.
178
+ let specialisedProviders = null;
179
+
180
+ function providerClassFor(url) {
181
+ if (specialisedProviders === null) {
182
+ specialisedProviders = new Map([
183
+ ['http://hl7.org/fhir/sid/icf', require('./cs-icf').IcfCodeSystemProvider]
184
+ ]);
185
+ }
186
+ return specialisedProviders.get(url) || FhirCodeSystemProvider;
187
+ }
188
+
174
189
  class FhirCodeSystemProvider extends BaseCSServices {
190
+ /**
191
+ * The provider for a CodeSystem resource: a FhirCodeSystemProvider, or the subclass
192
+ * registered for its url. Always use this rather than the constructor.
193
+ * @param {OperationContext} opContext
194
+ * @param {CodeSystem} codeSystem
195
+ * @param {CodeSystem[]} supplements
196
+ * @returns {FhirCodeSystemProvider}
197
+ */
198
+ static create(opContext, codeSystem, supplements) {
199
+ const cls = providerClassFor(codeSystem.url);
200
+ return new cls(opContext, codeSystem, supplements);
201
+ }
202
+
175
203
  /**
176
204
  * @param {CodeSystem} codeSystem - The primary CodeSystem
177
205
  * @param {CodeSystem[]} supplements - Array of supplement CodeSystems
@@ -197,6 +225,33 @@ class FhirCodeSystemProvider extends BaseCSServices {
197
225
  return this.codeSystem.jsonObj.name || '';
198
226
  }
199
227
 
228
+ /**
229
+ * $lookup's display name: CodeSystem.title, translated where the resource carries a
230
+ * translation for one of the request's languages, else the title as written, else name.
231
+ * @param {Languages} [languages] - the request's working languages
232
+ * @returns {string}
233
+ */
234
+ lookupName(languages) {
235
+ const cs = this.codeSystem.jsonObj;
236
+ if (!cs.title) return this.name();
237
+ const base = (c) => String(c || '').toLowerCase().split('-')[0];
238
+ const translations = (cs._title?.extension || [])
239
+ .filter(e => e.url === 'http://hl7.org/fhir/StructureDefinition/translation')
240
+ .map(e => ({
241
+ lang: (e.extension || []).find(x => x.url === 'lang')?.valueCode,
242
+ content: (e.extension || []).find(x => x.url === 'content')?.valueString,
243
+ }))
244
+ .filter(t => t.lang && t.content);
245
+ for (const l of languages || []) {
246
+ const want = base(l.language || l.code);
247
+ if (!want) continue;
248
+ if (cs.language && base(cs.language) === want) return cs.title;
249
+ const t = translations.find(t => base(t.lang) === want);
250
+ if (t) return t.content;
251
+ }
252
+ return cs.title;
253
+ }
254
+
200
255
  /**
201
256
  * @returns {string} URI for the code system
202
257
  */
@@ -1747,7 +1802,7 @@ class FhirCodeSystemFactory extends CodeSystemFactoryProvider {
1747
1802
  });
1748
1803
  }
1749
1804
 
1750
- return new FhirCodeSystemProvider(opContext, codeSystem, supplements);
1805
+ return FhirCodeSystemProvider.create(opContext, codeSystem, supplements);
1751
1806
  }
1752
1807
 
1753
1808
  // eslint-disable-next-line no-unused-vars