@aehrc/ecl-core 1.0.4 → 1.1.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/dist/index.d.ts CHANGED
@@ -38,6 +38,31 @@ declare interface AttributeValueNode extends ASTNode {
38
38
  rawValue?: string;
39
39
  }
40
40
 
41
+ /**
42
+ * Build a replacement ECL fragment for an inactive concept based on a historical association.
43
+ *
44
+ * - SAME AS / REPLACED BY: direct 1:1 replacement
45
+ * - POSSIBLY EQUIVALENT TO / ALTERNATIVE: parenthesized OR disjunction (or bare if single target)
46
+ *
47
+ * Display terms are included in the replacement when available.
48
+ */
49
+ export declare function buildReplacementText(association: HistoricalAssociation): ReplacementResult;
50
+
51
+ /**
52
+ * Returns a canonical string form of the given ECL expression.
53
+ *
54
+ * Applies deterministic ordering (AND/OR operands, refinement attributes),
55
+ * strips display terms, removes redundant parentheses, and normalises whitespace.
56
+ *
57
+ * Throws `CanonicaliseError` if the expression cannot be parsed.
58
+ */
59
+ export declare function canonicalise(expression: string): string;
60
+
61
+ export declare class CanonicaliseError extends Error {
62
+ readonly parseErrors: ParseError[];
63
+ constructor(message: string, parseErrors: ParseError[]);
64
+ }
65
+
41
66
  /**
42
67
  * Check an expression for mixed AND/OR operators in refinement clauses.
43
68
  *
@@ -53,6 +78,20 @@ export declare function checkMixedRefinementOperators(ast: ExpressionNode, sourc
53
78
  /** Clear all cached filter completions (e.g. on edition change). */
54
79
  export declare function clearFilterCache(): void;
55
80
 
81
+ /**
82
+ * Compares two ECL expressions.
83
+ *
84
+ * Returns 'identical' if the trimmed input strings are equal.
85
+ * Returns 'structurally_equivalent' if they differ but canonicalise to the same form.
86
+ * Returns 'different' otherwise.
87
+ *
88
+ * Both expressions must be syntactically valid. If either fails to parse,
89
+ * a CanonicaliseError is thrown.
90
+ */
91
+ export declare function compareExpressions(a: string, b: string): ComparisonResult;
92
+
93
+ export declare type ComparisonResult = 'identical' | 'structurally_equivalent' | 'different';
94
+
56
95
  export declare interface CompoundExpressionNode extends ASTNode {
57
96
  type: NodeType.CompoundExpression;
58
97
  operator: LogicalOperatorNode;
@@ -381,6 +420,11 @@ export declare class FhirTerminologyService implements ITerminologyService {
381
420
  private parseSnomedVersionValue;
382
421
  private fetchWithTimeout;
383
422
  getConceptInfo(conceptId: string): Promise<ConceptInfo | null>;
423
+ /** Map of SNOMED CT historical association reference set IDs to association types. */
424
+ private static readonly ASSOCIATION_REFSETS;
425
+ getHistoricalAssociations(conceptId: string): Promise<HistoricalAssociation[]>;
426
+ /** Query a single implicit ConceptMap for historical association targets. */
427
+ private translateAssociation;
384
428
  validateConcepts(conceptIds: string[]): Promise<Map<string, ConceptInfo | null>>;
385
429
  private bulkExpand;
386
430
  searchConcepts(query: string): Promise<SearchResponse>;
@@ -454,6 +498,13 @@ export declare interface FormattingOptions {
454
498
  * Defaults to false.
455
499
  */
456
500
  breakAfterColon: boolean;
501
+ /**
502
+ * Remove parentheses that don't change the meaning of the expression.
503
+ * Removes parens around non-compound expressions (e.g. `(404684003)` → `404684003`)
504
+ * and flattens same-operator nesting (e.g. `(A AND B) AND C` → `A AND B AND C`).
505
+ * Defaults to false.
506
+ */
507
+ removeRedundantParentheses: boolean;
457
508
  }
458
509
 
459
510
  /** Look up an article by its ID */
@@ -554,6 +605,17 @@ export declare function getValidOperatorsAtPosition(line: string, position: numb
554
605
  */
555
606
  export declare function groupIntoExpressions(text: string): Expression[];
556
607
 
608
+ export declare interface HistoricalAssociation {
609
+ type: HistoricalAssociationType;
610
+ refsetId: string;
611
+ targets: {
612
+ code: string;
613
+ display: string;
614
+ }[];
615
+ }
616
+
617
+ export declare type HistoricalAssociationType = 'same-as' | 'replaced-by' | 'possibly-equivalent-to' | 'alternative';
618
+
557
619
  export declare interface HistorySupplementNode extends ASTNode {
558
620
  type: NodeType.HistorySupplement;
559
621
  profile?: 'MIN' | 'MOD' | 'MAX';
@@ -618,6 +680,7 @@ export declare interface ITerminologyService {
618
680
  validateConcepts(conceptIds: string[]): Promise<Map<string, ConceptInfo | null>>;
619
681
  searchConcepts(query: string): Promise<SearchResponse>;
620
682
  evaluateEcl(expression: string, limit?: number): Promise<EvaluationResponse>;
683
+ getHistoricalAssociations?(conceptId: string): Promise<HistoricalAssociation[]>;
621
684
  }
622
685
 
623
686
  /** A single knowledge article (e.g., one operator, one pattern) */
@@ -816,6 +879,11 @@ declare interface RefinementWarning {
816
879
  */
817
880
  export declare function refineParseError(ctx: ErrorContext): RefinedError;
818
881
 
882
+ export declare interface ReplacementResult {
883
+ replacement: string;
884
+ label: string;
885
+ }
886
+
819
887
  /**
820
888
  * Resolves an "Add display terms" code action by performing FHIR lookups
821
889
  * for each bare concept ID and inserting display terms into the expression.