@aehrc/ecl-core 1.7.0 → 1.9.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.
package/README.md CHANGED
@@ -50,6 +50,31 @@ const formatted = formatDocument('<<404684003:246075003=<<19829001', {
50
50
 
51
51
  Range formatting is also supported via `expandToExpressionBoundaries`, `getExpressionsInRange`, and `formatRangeExpressions`.
52
52
 
53
+ ### Minifying
54
+
55
+ ```typescript
56
+ import { minifyExpression } from '@aehrc/ecl-core';
57
+
58
+ minifyExpression(`/* Lung findings */
59
+ (<< 404684003 |Clinical finding| :
60
+ 363698007 |Finding site| = << 39057004 |Lung structure|)
61
+ OR << 71388002 |Procedure|`);
62
+ // → '/* Lung findings */(<<404684003:363698007=<<39057004)OR <<71388002'
63
+
64
+ minifyExpression('<< 404684003 /* any */ {{ D term = "heart attack" }}', { removeComments: true });
65
+ // → '<<404684003{{D term="heart attack"}}'
66
+ ```
67
+
68
+ Returns the shortest text that parses to the same expression, for storing ECL where size and RF2 safety matter, such as the query field of a query specification reference set:
69
+
70
+ - display terms are removed;
71
+ - whitespace is removed wherever the grammar makes it optional, and is one space where it is mandatory: after `AND`, `OR` and `MINUS`, and between the items of a set such as `(en-au (prefer) en-gb)`;
72
+ - a space is kept where removing it would join two words (`D term`, `R 363698007`) or two characters into a different operator;
73
+ - quoted strings are kept as written, except that a tab or line break in one becomes a space;
74
+ - block comments are kept, with their whitespace collapsed, unless `removeComments` is set.
75
+
76
+ The result has no tab, carriage return or line feed. Operand order, brackets and refinement groups are never changed. Before returning, the result is re-parsed and its structure compared with the input's. Throws `MinifyError` for unparseable input. Pure, synchronous, zero-network-dependency.
77
+
53
78
  ### Validation
54
79
 
55
80
  ```typescript
@@ -113,6 +138,7 @@ const fhir = new FhirTerminologyService({
113
138
  baseUrl: 'https://tx.ontoserver.csiro.au/fhir', // default
114
139
  timeout: 2000, // lookup timeout (ms)
115
140
  snomedVersion: '', // SNOMED version URI (empty = server default)
141
+ rateLimitWaitMs: 60_000, // how long one request may wait out HTTP 429s
116
142
  });
117
143
 
118
144
  const concept = await fhir.getConceptInfo('404684003');
@@ -122,6 +148,15 @@ const results = await fhir.evaluateEcl('< 404684003');
122
148
  // { concepts: [...], total }
123
149
  ```
124
150
 
151
+ Rate limits: when the server says its allowance is spent (a 429, or
152
+ `x-ratelimit-remaining: 0`), every request of the service waits for the reset
153
+ it gives (`Retry-After` or `x-ratelimit-reset`), up to `rateLimitWaitMs` per
154
+ request, rather than failing. When the limit resets, held requests go oldest
155
+ first, as many at a time as the server says it has room for. This applies to
156
+ every user of the service (hovers, diagnostics, derive), so a request can take
157
+ that long on a rate-limited server, or longer when many are queued: the budget
158
+ is checked after each 429, not while a request waits its turn.
159
+
125
160
  ### Deriving ECL from a Concept List
126
161
 
127
162
  The opposite of `$expand`: given a code list or a reference set, propose ECL
@@ -148,11 +183,15 @@ additions reported), a greedy grouping, a cost-based cover, and always the
148
183
  enumeration or `^ refset` itself. They are ranked by clauses + additions +
149
184
  misses.
150
185
 
151
- The hierarchy candidates are built from one IS-A subgraph around the set,
152
- fetched in about four expansions that return each concept's parents
153
- (`expandCompose` with `parents: true`, FHIR `property=parent`): the set, its
154
- ancestors, their children, and the descendants of the ancestors worth trying
155
- as groupers. Candidates are built and ranked on that graph without further
186
+ The hierarchy candidates are built from one IS-A subgraph around the set. For
187
+ a list (`walkGraph`, the default) it is walked: the codes are looked up in
188
+ chunks of 10,000 with their activity, parents and children (`expandCompose`
189
+ with `parents`/`children`, FHIR `property=parent`/`property=child`), then each
190
+ new level of ancestors, and then below the ancestors worth trying as groupers,
191
+ level by level. No request carries the list as ECL. A server that does not
192
+ return children, or does not flag inactive concepts in an expansion, gets the
193
+ older path: about four expansions that carry the set as ECL and return
194
+ parents. Candidates are built and ranked on that graph without further
156
195
  requests, and only the best are counted again on the server, so every count
157
196
  reported comes from the server. A graph candidate that by its local counts
158
197
  costs at least as much as the input itself (listing every member, or the
@@ -195,6 +234,46 @@ value, a range with `>=` and `<=`, or `= *`) and cardinalities
195
234
  (`[2..*] attribute = *`). When no refinement is exact, a subtraction
196
235
  `(C) MINUS (D)` is also tried, with D describing what the refinement C adds.
197
236
 
237
+ Lists that are one slice of a hierarchy, such as an AMT list of MPUUs under
238
+ its drug classes, also get a **restricted cover**, `(<< A OR << B …) AND ^ R`,
239
+ exact by construction: the groupers alone would add concepts outside the
240
+ slice, and `R` removes them. `restrictTo: 'auto'` (the default) uses the AMT
241
+ level reference set that holds every member when all of them are medicinal
242
+ products, and does nothing otherwise; give an expression to use it instead, or
243
+ `''` to turn the cover off. Once this cover is exact, the attribute-refinement
244
+ search is skipped in `'auto'` mode.
245
+
246
+ #### Incomplete results
247
+
248
+ Derive goes on when a server request fails (times out, is rate-limited past
249
+ `rateLimitWaitMs`, or answers 5xx): it drops what the request was for and adds
250
+ a note. `result.failures` counts the requests whose loss changed the result,
251
+ and `formatDeriveReport` then starts with "Incomplete: N server queries
252
+ failed". A request whose failure derive makes up for with others is not
253
+ counted. Check `failures` before treating a long enumeration as "no rule
254
+ exists": with every count failing, the enumeration is all that is left.
255
+ `compressExpression` reports `failures` the same way.
256
+
257
+ #### Large lists
258
+
259
+ These options keep large lists cheap for the server and for memory. All but
260
+ `localScoring` are on by default.
261
+
262
+ | Option | Default | Effect |
263
+ | ------------------ | ------- | ----------------------------------------------------------------------------------------------------- |
264
+ | `walkGraph` | `true` | Build the graph by looking codes up in chunks, as above |
265
+ | `batchLookups` | `true` | Read the refinement sample's relationships in one FHIR batch request (`getDefiningRelationshipsMany`) |
266
+ | `scopedExclusions` | `true` | Count a near miss's additions excluding only the members below it, not the whole list |
267
+ | `parallelPages` | `true` | Ask for the later pages of a multi-page expansion at once |
268
+ | `localScoring` | `false` | Count graph candidates on the graph and check only the best on the server |
269
+
270
+ Measured on `tx.ontoserver.csiro.au` with an 87,000-code list, all to the same
271
+ result: with the defaults, 32–40 s, 37 requests and 22 MB uploaded (most of it
272
+ the list, sent with each candidate's server count); with `localScoring` on,
273
+ 11–13 s, 29 requests and 2.5 MB; before these options, 207 s and 69 MB. In a 512 MiB container (`node:20-alpine`) that list peaks at 136 MB of
274
+ heap and a 195,000-code list at 164 MB. Above `maxGraphConcepts` (200,000)
275
+ derive falls back to a query per count, which is slow.
276
+
198
277
  `deriveEcl({ ecl }, terminology)` takes the set an expression selects. For
199
278
  pasted text, `deriveInputFromText(text)` picks the input: a list of bare
200
279
  concepts joined by OR, AND or commas becomes `{ conceptIds }` (so inactive and
@@ -224,13 +303,14 @@ it is turned into ECL. They follow checks of the NHS ValueSet Management Tool
224
303
  (CHK numbers below), and all are advisory. `formatDeriveReport` prints them
225
304
  under "Review:". The checks:
226
305
 
227
- | Field | Check | Flags | Limit (default) |
228
- | ------------------ | ----- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
229
- | `clauses` | CHK16 | The best exact candidate needs more clauses than the limit | `maxClauses` (35) |
230
- | `nearMisses` | CHK12 | Concepts X where the list holds most, but not all, of `<< X`, with the missing concepts counted on the server. Only the outermost of nested ones is listed | `nearMissShare` (0.9), `nearMissMinSize` (5), `maxNearMisses` (5) |
231
- | `spansHierarchies` | CHK15 | Members in more than one top-level hierarchy (`hierarchies` gives the counts) | |
232
- | `inactive` | CHK07 | Inactive ids in the input, or a reference set's inactive members | |
233
- | `impliedInactive` | CHK08 | Inactive concepts the members' history implies but the input leaves out. Off unless asked for; needs ECL history supplements on the server | `impliedInactive` (false; `true` is `'HISTORY-MOD'`) |
306
+ | Field | Check | Flags | Limit (default) |
307
+ | ------------------ | ----- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
308
+ | `clauses` | CHK16 | The best exact candidate needs more clauses than the limit | `maxClauses` (35) |
309
+ | `nearMisses` | CHK12 | Concepts X where the list holds most, but not all, of `<< X`, with the missing concepts counted on the server. Only the outermost of nested ones is listed | `nearMissShare` (0.9), `nearMissMinSize` (5), `maxNearMisses` (5) |
310
+ | `spansHierarchies` | CHK15 | Members in more than one top-level hierarchy (`hierarchies` gives the counts) | |
311
+ | `inactive` | CHK07 | Inactive ids in the input, or a reference set's inactive members | |
312
+ | `impliedInactive` | CHK08 | Inactive concepts the members' history implies but the input leaves out. Off unless asked for; needs ECL history supplements on the server | `impliedInactive` (false; `true` is `'HISTORY-MOD'`) |
313
+ | `duplicateTerms` | CHK13 | Different members with the same preferred term (e.g. a procedure and an observable entity), with FSNs to tell them apart. Whitespace and the case of the first letter are ignored. Skipped for lists of more than `maxGraphConcepts` members | `maxDuplicateTerms` (20; 0 turns it off) |
234
314
 
235
315
  Near misses need the IS-A subgraph (see `useGraph`); without it they are
236
316
  skipped with a note. Only groupers whose subtree the subgraph loaded are judged:
@@ -42,6 +42,8 @@ export interface CompressResult {
42
42
  notes: string[];
43
43
  /** Syntax errors; the expression is not compressed when there are any. */
44
44
  errors: string[];
45
+ /** Server requests that failed; above 0 a shorter form may be missing (see `DeriveResult.failures`). */
46
+ failures: number;
45
47
  }
46
48
  /**
47
49
  * Propose shorter forms of an ECL expression, each with exact counts and
@@ -1 +1 @@
1
- {"version":3,"file":"compress-expression.d.ts","sourceRoot":"","sources":["../../src/derive/compress-expression.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAIL,KAAK,qBAAqB,EAE1B,KAAK,aAAa,EACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAuC,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAExF,MAAM,WAAW,iBAAiB;IAChC,uEAAuE;IACvE,UAAU,EAAE,MAAM,CAAC;IACnB,mDAAmD;IACnD,GAAG,EAAE,MAAM,CAAC;IACZ,sDAAsD;IACtD,SAAS,EAAE,aAAa,CAAC;IACzB,sDAAsD;IACtD,MAAM,EAAE,aAAa,CAAC;IACtB,KAAK,EAAE,OAAO,CAAC;IACf,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,UAAU,EAAE,OAAO,CAAC;IACpB;;;;OAIG;IACH,MAAM,EAAE,UAAU,GAAG,YAAY,GAAG,SAAS,CAAC;IAC9C,kEAAkE;IAClE,YAAY,CAAC,EAAE,qBAAqB,CAAC;CACtC;AAED,MAAM,WAAW,cAAc;IAC7B,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,qFAAqF;IACrF,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC3D,yEAAyE;IACzE,UAAU,EAAE,iBAAiB,EAAE,CAAC;IAChC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,0EAA0E;IAC1E,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,mBAAmB,EAChC,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,cAAc,CAAC,CAsEzB;AAuHD,gGAAgG;AAChG,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAoBnE"}
1
+ {"version":3,"file":"compress-expression.d.ts","sourceRoot":"","sources":["../../src/derive/compress-expression.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAKL,KAAK,qBAAqB,EAE1B,KAAK,aAAa,EACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAyD,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAE1G,MAAM,WAAW,iBAAiB;IAChC,uEAAuE;IACvE,UAAU,EAAE,MAAM,CAAC;IACnB,mDAAmD;IACnD,GAAG,EAAE,MAAM,CAAC;IACZ,sDAAsD;IACtD,SAAS,EAAE,aAAa,CAAC;IACzB,sDAAsD;IACtD,MAAM,EAAE,aAAa,CAAC;IACtB,KAAK,EAAE,OAAO,CAAC;IACf,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,UAAU,EAAE,OAAO,CAAC;IACpB;;;;OAIG;IACH,MAAM,EAAE,UAAU,GAAG,YAAY,GAAG,SAAS,CAAC;IAC9C,kEAAkE;IAClE,YAAY,CAAC,EAAE,qBAAqB,CAAC;CACtC;AAED,MAAM,WAAW,cAAc;IAC7B,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,qFAAqF;IACrF,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC3D,yEAAyE;IACzE,UAAU,EAAE,iBAAiB,EAAE,CAAC;IAChC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,0EAA0E;IAC1E,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,wGAAwG;IACxG,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,mBAAmB,EAChC,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,cAAc,CAAC,CAKzB;AAmMD,gGAAgG;AAChG,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAqBnE"}
@@ -22,4 +22,21 @@ export declare function outermost<T extends {
22
22
  }>(g: TaxonomyGraph, items: T[], max: number): T[];
23
23
  /** The near misses on the graph alone: {@link nearMissCandidates}, outermost first, at most `max`. */
24
24
  export declare function findNearMisses(g: TaxonomyGraph, share: number, minSize: number, max: number): LocalNearMiss[];
25
+ /** Different concepts of the list with the same preferred term (CHK13). */
26
+ export interface LocalDuplicateTerm {
27
+ /** The term as the lowest id has it. */
28
+ term: string;
29
+ /** Sorted. */
30
+ conceptIds: string[];
31
+ }
32
+ /**
33
+ * Groups of two or more concepts whose terms match, ordered by term. Runs of
34
+ * whitespace and the case of the first letter are ignored, as SNOMED CT
35
+ * terms are mostly case-insensitive only there. Concepts without a term are
36
+ * left out.
37
+ */
38
+ export declare function findDuplicateTerms(concepts: {
39
+ code: string;
40
+ display: string;
41
+ }[]): LocalDuplicateTerm[];
25
42
  //# sourceMappingURL=critique.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"critique.d.ts","sourceRoot":"","sources":["../../src/derive/critique.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,6DAA6D;AAC7D,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,kCAAkC;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,aAAa,EAAE,CAWpG;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,EAAE,CAUzG;AAED,sGAAsG;AACtG,wBAAgB,cAAc,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,aAAa,EAAE,CAE7G"}
1
+ {"version":3,"file":"critique.d.ts","sourceRoot":"","sources":["../../src/derive/critique.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,6DAA6D;AAC7D,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,kCAAkC;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,aAAa,EAAE,CAWpG;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,EAAE,CAUzG;AAED,sGAAsG;AACtG,wBAAgB,cAAc,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,aAAa,EAAE,CAE7G;AAED,2EAA2E;AAC3E,MAAM,WAAW,kBAAkB;IACjC,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,cAAc;IACd,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EAAE,GAAG,kBAAkB,EAAE,CAiBtG"}
@@ -39,12 +39,13 @@ export interface DeriveOptions {
39
39
  /**
40
40
  * Attribute refinement candidates (`focus : attribute = value`):
41
41
  * `'auto'` builds them when the set cuts across the IS-A hierarchy: more than
42
- * 20 roots, or more than 3 with no exact IS-A candidate of 3 clauses or fewer.
42
+ * 20 roots, or more than 3 with no exact IS-A candidate of 3 clauses or fewer;
43
+ * never when an exact cover within a reference set was found (see `restrictTo`).
43
44
  * Default `'auto'`. Needs `getDefiningRelationships`.
44
45
  */
45
46
  refinements?: 'auto' | 'always' | 'never';
46
47
  /**
47
- * The focus for refinement candidates, e.g. `^ 929360081000036101` for AMT
48
+ * The focus for refinement candidates, e.g. `^ 929360071000036103` for AMT
48
49
  * MPUUs. Default: `<<` the most specific concept above every member.
49
50
  */
50
51
  refinementFocus?: string;
@@ -80,6 +81,42 @@ export interface DeriveOptions {
80
81
  * `true` uses the defaults of {@link CritiqueOptions}. Default false.
81
82
  */
82
83
  critique?: boolean | CritiqueOptions;
84
+ /**
85
+ * Build a cover that is exact within this expression, `(<< A OR << B …) AND R`,
86
+ * for sets that are one slice of a hierarchy: a reference set's members under
87
+ * a few groupers, where the groupers alone add the concepts outside it (an
88
+ * AMT list of MPUUs under its drug classes). `'auto'` uses the AMT level
89
+ * reference set holding every member when all of them are medicinal
90
+ * products, and is a no-op otherwise; `''` turns the cover off. Graph path
91
+ * only. Default `'auto'`.
92
+ */
93
+ restrictTo?: string;
94
+ /** Fetch the later pages of a multi-page expansion concurrently. Default true. */
95
+ parallelPages?: boolean;
96
+ /**
97
+ * Take graph candidates' counts from the graph instead of the server, and
98
+ * check only the best candidate on the server (falling back to server counts
99
+ * for all when its count differs). Default false.
100
+ */
101
+ localScoring?: boolean;
102
+ /**
103
+ * When counting what a grouper adds (near misses), exclude only the members
104
+ * below it, which the graph knows, not the whole set. Default true.
105
+ */
106
+ scopedExclusions?: boolean;
107
+ /**
108
+ * Resolve a list by looking its codes up in chunks, with parents and
109
+ * children, and build the IS-A graph by walking from there instead of with
110
+ * queries that carry the list as ECL. Falls back to those queries on a
111
+ * server that does not return `property=child`, or does not flag inactive
112
+ * concepts in an expansion. Default true.
113
+ */
114
+ walkGraph?: boolean;
115
+ /**
116
+ * Read the refinement sample's relationships in one FHIR batch request,
117
+ * falling back to one lookup each when the server refuses it. Default true.
118
+ */
119
+ batchLookups?: boolean;
83
120
  }
84
121
  /** Limits for {@link CodelistCritique}. */
85
122
  export interface CritiqueOptions {
@@ -97,6 +134,11 @@ export interface CritiqueOptions {
97
134
  * Needs a server that supports ECL history supplements. Default false.
98
135
  */
99
136
  impliedInactive?: boolean | 'HISTORY-MIN' | 'HISTORY-MOD' | 'HISTORY-MAX';
137
+ /**
138
+ * CHK13: the most shared terms reported (0 turns the check off). Default 20.
139
+ * Lists of more than `maxGraphConcepts` members are not checked.
140
+ */
141
+ maxDuplicateTerms?: number;
100
142
  }
101
143
  /** A concept the list holds most, but not all, of `<< conceptId` of (CHK12). */
102
144
  export interface NearMiss {
@@ -109,6 +151,15 @@ export interface NearMiss {
109
151
  /** `<< conceptId` concepts the list leaves out, counted on the server. */
110
152
  missing: SetDifference;
111
153
  }
154
+ /** Different members with the same preferred term (CHK13), e.g. a procedure and an observable entity. */
155
+ export interface DuplicateTerm {
156
+ term: string;
157
+ /** Sorted by id; `fsn` tells them apart, unless `omitTerms`. */
158
+ concepts: {
159
+ conceptId: string;
160
+ fsn?: string;
161
+ }[];
162
+ }
112
163
  /**
113
164
  * Structural checks on the list, after the NHS ValueSet Management Tool's
114
165
  * (CHK numbers are its checks). Advisory: each can be intended.
@@ -127,6 +178,8 @@ export interface CodelistCritique {
127
178
  spansHierarchies: boolean;
128
179
  /** CHK07: inactive ids in the input. */
129
180
  inactive: string[];
181
+ /** CHK13: members that share a preferred term. */
182
+ duplicateTerms: DuplicateTerm[];
130
183
  /** CHK08: inactive concepts the history implies but the input leaves out (when asked for). */
131
184
  impliedInactive?: SetDifference;
132
185
  }
@@ -171,6 +224,12 @@ export type CandidateConstruction = {
171
224
  includes: HierarchyClause[];
172
225
  /** Clauses subtracted with MINUS. */
173
226
  exclusions: HierarchyClause[];
227
+ } | {
228
+ /** A cover exact within `restrictTo`: the clauses ORed, then `AND restrictTo`. */
229
+ kind: 'restricted-cover';
230
+ restrictTo: string;
231
+ /** The highest concepts with no non-member of `restrictTo` below them, as `<< x`; a member that has one, as `= x`. */
232
+ includes: HierarchyClause[];
174
233
  } | {
175
234
  kind: 'ancestor-cover';
176
235
  /** The clauses, in the order chosen: `<< member` or `< ancestor` (a non-member). */
@@ -227,6 +286,14 @@ export interface DeriveResult {
227
286
  notes: string[];
228
287
  /** Structural checks on the list, when the `critique` option asks for them. */
229
288
  critique?: CodelistCritique;
289
+ /**
290
+ * Server requests that failed (unreachable, timed out, rate-limited, 5xx).
291
+ * Each drops a candidate or a check rather than the result, so above 0 the
292
+ * result is incomplete: a candidate the server could not count is missing,
293
+ * and the best one left may be far worse than the best that exists. `notes`
294
+ * says what was lost.
295
+ */
296
+ failures: number;
230
297
  }
231
298
  /**
232
299
  * Propose ECL expressions for a set of concepts, ranked, each with exact counts
@@ -236,10 +303,16 @@ export interface DeriveResult {
236
303
  * @throws `TerminologyTransportError` / `TerminologyHttpError` when the server fails.
237
304
  */
238
305
  export declare function deriveEcl(input: DeriveInput, terminology: ITerminologyService, options?: DeriveOptions): Promise<DeriveResult>;
306
+ /**
307
+ * Preferred terms for the ids in the candidates worth decorating. Terms are
308
+ * decoration: when the lookup fails, the candidates go out with bare ids and,
309
+ * given `notes`, a note says why (the failure itself is counted by the caller's
310
+ * service), rather than losing a finished result.
311
+ */
239
312
  export declare function displayTerms(candidates: {
240
313
  ecl: string;
241
314
  clauses: number;
242
- }[], terminology: ITerminologyService): Promise<Map<string, string>>;
315
+ }[], terminology: ITerminologyService, notes?: string[]): Promise<Map<string, string>>;
243
316
  /** Add display terms and format, unless the candidate is too long to be worth it. */
244
317
  export declare function decorate(ecl: string, terms: Map<string, string>): string;
245
318
  /**
@@ -259,4 +332,6 @@ export declare function parseConceptIdList(text: string): string[];
259
332
  export declare function deriveInputFromText(text: string): DeriveInput;
260
333
  /** A plain-text report of a {@link DeriveResult}, for an output channel or a chat message. */
261
334
  export declare function formatDeriveReport(result: DeriveResult): string;
335
+ /** The first line of a report whose result lost candidates or checks to server failures. */
336
+ export declare function incompleteLine(failures: number): string;
262
337
  //# sourceMappingURL=derive-ecl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"derive-ecl.d.ts","sourceRoot":"","sources":["../../src/derive/derive-ecl.ts"],"names":[],"mappings":"AAoDA,OAAO,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AAC,EAAE,gBAAgB,CAAC;IAC5B;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,CAAC;CAClB;AA2DD;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,KAAK,EAAE,WAAW,EAClB,WAAW,EAAE,mBAAmB,EAChC,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,YAAY,CAAC,CAQvB;AA05CD;;;;;GAKG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EAAE,EAC9C,WAAW,EAAE,mBAAmB,EAChC,KAAK,CAAC,EAAE,MAAM,EAAE,GACf,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAiB9B;AAED,qFAAqF;AACrF,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAOxE;AAID;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAczD;AAeD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAW7D;AAuBD,8FAA8F;AAC9F,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAuC/D;AA0CD,4FAA4F;AAC5F,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAKvD"}
@@ -18,7 +18,7 @@ export interface RefinementClause {
18
18
  export declare function refinementCandidates(members: MemberSet, roots: {
19
19
  codes: string[];
20
20
  total: number;
21
- }, givenFoci: string[], fixedFocus: boolean, q: SetQueries, terminology: ITerminologyService, notes: string[]): Promise<{
21
+ }, givenFoci: string[], fixedFocus: boolean, q: SetQueries, terminology: ITerminologyService, notes: string[], batch?: boolean): Promise<{
22
22
  focus: string;
23
23
  clauses: R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EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAMhG"}
@@ -1,10 +1,17 @@
1
1
  import { EvaluationConcept, ITerminologyService, ValueSetClause, ValueSetCompose } from '../terminology/types';
2
+ import { Walk } from './taxonomy-graph';
2
3
  export interface SetDifference {
3
4
  count: number;
4
5
  /** Up to `sampleSize` of the concepts, as the server returned them. */
5
6
  sample: EvaluationConcept[];
6
7
  }
7
8
  export declare const SNOMED_ROOT = "138875005";
9
+ /**
10
+ * Codes per request when looking concepts up by code. The server's cost grows
11
+ * with the codes in a request, and is paid again for every page of it, so a
12
+ * long list costs least as many small requests rather than one paged one.
13
+ */
14
+ export declare const LOOKUP_CHUNK = 10000;
8
15
  /** Concurrent set queries; see {@link SetQueries}. */
9
16
  export declare const MAX_IN_FLIGHT = 8;
10
17
  /** Numeric order for SCTIDs, so output does not depend on input or server order. */
@@ -20,11 +27,28 @@ export declare function orGroup(terms: string[]): string;
20
27
  export declare function stripTermsAndComments(ecl: string): string;
21
28
  export declare function countClauses(ecl: string): number;
22
29
  export type ExpandCompose = NonNullable<ITerminologyService['expandCompose']>;
30
+ /**
31
+ * The service behind a {@link countingFailures} wrapper (or `terminology`
32
+ * itself), for a request whose failure the caller recovers from by other
33
+ * requests, which are counted: a failure there loses nothing, so it must not
34
+ * mark the result incomplete.
35
+ */
36
+ export declare function uncounted(terminology: ITerminologyService): ITerminologyService;
37
+ export declare function countingFailures(terminology: ITerminologyService): {
38
+ service: ITerminologyService;
39
+ failures: () => number;
40
+ };
23
41
  /** The set under study, as a compose clause and as an ECL operand. */
24
42
  export interface MemberSet {
25
43
  clause: ValueSetClause;
26
44
  ecl: string;
27
45
  size: number;
46
+ /** The members with their terms, when resolving the input already listed them. */
47
+ concepts?: EvaluationConcept[];
48
+ /** The members looked up with their parents and children, when resolving the input did that, for the graph. */
49
+ walk?: Walk;
50
+ /** Resolving the input found that the server gives no parents or children, so the graph cannot be walked. */
51
+ walkUnsupported?: boolean;
28
52
  }
29
53
  /**
30
54
  * Set queries against the server. At most {@link MAX_IN_FLIGHT} run at once:
@@ -32,9 +56,25 @@ export interface MemberSet {
32
56
  */
33
57
  export declare class SetQueries {
34
58
  private readonly expandCompose;
59
+ private readonly parallelPages;
35
60
  private inFlight;
36
61
  private readonly waiting;
37
- constructor(expandCompose: ExpandCompose);
62
+ constructor(expandCompose: ExpandCompose, parallelPages?: boolean);
63
+ /**
64
+ * The rest of an expansion whose first `first.length` concepts have been
65
+ * read, up to `until`, in order. Pages step by the first page's length, which
66
+ * is the server's page cap when it returned fewer than asked (Ontoserver
67
+ * caps at 50,000; other servers lower). With `parallelPages` those pages are
68
+ * asked for at once. Whatever is still missing after that (a server whose
69
+ * pages shrink) is read one page after another, advancing by what each page
70
+ * actually held, so a smaller cap never silently drops concepts.
71
+ */
72
+ private rest;
73
+ /**
74
+ * Append the pages from `step` to `until`, `step` apart, asked for at once.
75
+ * Only the run of full pages is kept: after a short one the offsets no longer line up.
76
+ */
77
+ private pagesAtOnce;
38
78
  private expand;
39
79
  count(compose: ValueSetCompose): Promise<number>;
40
80
  sample(compose: ValueSetCompose, count: number, activeOnly?: boolean): Promise<SetDifference>;
@@ -43,6 +83,42 @@ export declare class SetQueries {
43
83
  codes: string[];
44
84
  total: number;
45
85
  }>;
86
+ /** Up to `max` concepts of the set with their terms, in the server's order, plus the set's exact total. */
87
+ concepts(compose: ValueSetCompose, max: number, activeOnly?: boolean): Promise<{
88
+ concepts: EvaluationConcept[];
89
+ total: number;
90
+ }>;
91
+ /**
92
+ * The concepts of `codes` the server knows, in chunks of {@link LOOKUP_CHUNK}
93
+ * run concurrently, with their terms and, as asked, parents and children.
94
+ * With `activeOnly: false` inactive ones come back flagged `inactive`.
95
+ */
96
+ lookup(codes: readonly string[], options?: {
97
+ activeOnly?: boolean;
98
+ parents?: boolean;
99
+ children?: boolean;
100
+ activity?: boolean;
101
+ }): Promise<EvaluationConcept[]>;
102
+ /**
103
+ * {@link lookup}, with each chunk's answer passed through `each` as it
104
+ * arrives, so a caller that keeps less than the server sends need not hold
105
+ * every answer at once. The results are in chunk order.
106
+ */
107
+ lookupEach<T>(codes: readonly string[], options: {
108
+ activeOnly?: boolean;
109
+ parents?: boolean;
110
+ children?: boolean;
111
+ activity?: boolean;
112
+ }, each: (concepts: EvaluationConcept[]) => T): Promise<T[]>;
113
+ /**
114
+ * Up to `max` concepts of a set known to have at most `max`, such as a list
115
+ * of codes: with `parallelPages` every page is asked for at once, since the
116
+ * offsets do not depend on the first page's total.
117
+ */
118
+ conceptsUpTo(compose: ValueSetCompose, max: number, activeOnly?: boolean): Promise<{
119
+ concepts: EvaluationConcept[];
120
+ total: number;
121
+ }>;
46
122
  /**
47
123
  * Every concept of the set with its direct parents, or why not: the set has
48
124
  * more than `max` concepts, or the server does not return parents.
@@ -1 +1 @@
1
- {"version":3,"file":"set-queries.d.ts","sourceRoot":"","sources":["../../src/derive/set-queries.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEpH,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,MAAM,EAAE,iBAAiB,EAAE,CAAC;CAC7B;AAED,eAAO,MAAM,WAAW,cAAc,CAAC;AAGvC,sDAAsD;AACtD,eAAO,MAAM,aAAa,IAAI,CAAC;AAE/B,oFAAoF;AACpF,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAGxD;AAED,gEAAgE;AAChE,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAE/C;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAA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AO,GAChG,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAI/B;;;;OAIG;IACG,UAAU,CAAC,CAAC,EAChB,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,OAAO,EAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,EAC5F,IAAI,EAAE,CAAC,QAAQ,EAAE,iBAAiB,EAAE,KAAK,CAAC,GACzC,OAAO,CAAC,CAAC,EAAE,CAAC;IAef;;;;OAIG;IACG,YAAY,CAChB,OAAO,EAAE,eAAe,EACxB,GAAG,EAAE,MAAM,EACX,UAAU,UAAO,GAChB,OAAO,CAAC;QAAE,QAAQ,EAAE,iBAAiB,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAc5D;;;OAGG;IACG,KAAK,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,WAAW,GAAG,YAAY,CAAC;IAW/G,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAGvC"}
@@ -1,3 +1,4 @@
1
+ import { EvaluationConcept } from '../terminology/types';
1
2
  import { MemberSet, SetQueries } from './set-queries';
2
3
  export interface TaxonomyGraph {
3
4
  readonly members: ReadonlySet<string>;
@@ -13,10 +14,20 @@ export interface TaxonomyGraph {
13
14
  hasDescendants(id: string): boolean;
14
15
  /** Members at or below `id`. */
15
16
  truePos(id: string): number;
17
+ /** The members at or below `id`, sorted byId; complete, since every member's ancestors are loaded. */
18
+ membersBelow(id: string): string[];
16
19
  /** Members with no member ancestor, sorted byId. */
17
20
  roots(): string[];
18
21
  /** Concepts in `>> list` except the SNOMED root, sorted byId. */
19
22
  ancestors(): string[];
23
+ /**
24
+ * Walked graphs only: load the descendants of `ids` by walking
25
+ * down, looking up only concepts not yet seen. False when they are too many
26
+ * or the server cannot say; the graph is then unchanged.
27
+ */
28
+ loadBelow?(ids: string[]): Promise<boolean>;
29
+ /** Walked graphs only: a concept's term, when a lookup returned it. */
30
+ term?(id: string): string | undefined;
20
31
  }
21
32
  /** What was too large to fetch, or `'parents'` when the server does not return them. */
22
33
  export interface GraphUnavailable {
@@ -33,6 +44,53 @@ export interface TaxonomyGraphOptions {
33
44
  * graph partial. Default: none, the graph is unavailable.
34
45
  */
35
46
  fallbackDescend?: TaxonomyGraphOptions['descend'];
47
+ /** The set's active codes when already known, so they are not fetched again. */
48
+ memberCodes?: string[];
49
+ /**
50
+ * Build the graph by walking: look the members up with their
51
+ * parents and children, then each new level of ancestors, in chunks, and
52
+ * below the picked groupers the same way, level by level. No query carries
53
+ * the set as ECL. Needs a server that returns `property=child`; without it
54
+ * the ECL queries are used.
55
+ */
56
+ walk?: boolean;
57
+ /** The active members as already looked up, with parents and children, so they are not looked up again. */
58
+ seed?: Walk;
59
+ /**
60
+ * Queries for `loadBelow` once the graph is built. Its caller falls back to
61
+ * server counts when it fails, so derive passes queries whose failures are
62
+ * not counted (see `uncounted`). Default: the graph's own.
63
+ */
64
+ belowQueries?: SetQueries;
36
65
  }
37
66
  export declare function loadTaxonomyGraph(members: MemberSet, q: SetQueries, options: TaxonomyGraphOptions): Promise<TaxonomyGraph | GraphUnavailable>;
67
+ /** Concept ids, each numbered once, shared by a walk and the graph built from it. */
68
+ declare class Ids {
69
+ readonly list: string[];
70
+ private readonly index;
71
+ get(id: string): number | undefined;
72
+ /** The number of `id`, given one if it has none. */
73
+ at(id: string): number;
74
+ }
75
+ /** A looked-up concept, with its parents and children by number. */
76
+ export interface Node {
77
+ parents: number[];
78
+ children: number[];
79
+ display: string;
80
+ }
81
+ /**
82
+ * Concepts looked up with their parents and children, by number. Resolving a
83
+ * list can start one, converting each chunk as it arrives, so the server's
84
+ * answers are not all held at once (see {@link TaxonomyGraphOptions.seed}).
85
+ */
86
+ export declare class Walk {
87
+ readonly ids: Ids;
88
+ readonly nodes: Map<number, Node>;
89
+ /** The nodes for `concepts`, not yet added; null when one came back without the parents or children asked for. */
90
+ nodesFor(concepts: EvaluationConcept[]): [number, Node][] | null;
91
+ add(nodes: [number, Node][]): void;
92
+ /** True when every one of `codes` has been looked up. */
93
+ has(codes: Iterable<string>): boolean;
94
+ }
95
+ export {};
38
96
  //# sourceMappingURL=taxonomy-graph.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"taxonomy-graph.d.ts","sourceRoot":"","sources":["../../src/derive/taxonomy-graph.ts"],"names":[],"mappings":"AAYA,OAAO,EAA8B,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAE5F,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACtC,+FAA+F;IAC/F,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,uFAAuF;IACvF,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IACjC,2GAA2G;IAC3G,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC/B,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC9B,6EAA6E;IAC7E,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAClC,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IACpC,gCAAgC;IAChC,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,oDAAoD;IACpD,KAAK,IAAI,MAAM,EAAE,CAAC;IAClB,iEAAiE;IACjE,SAAS,IAAI,MAAM,EAAE,CAAC;CACvB;AAED,wFAAwF;AACxF,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,CAAC;CAC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