@haste-health/fhirpath 0.12.2
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/lib/analyze.d.ts +12 -0
- package/lib/analyze.js +307 -0
- package/lib/analyze.js.map +1 -0
- package/lib/index.d.ts +18 -0
- package/lib/index.js +481 -0
- package/lib/index.js.map +1 -0
- package/lib/parserv2/index.d.ts +2 -0
- package/lib/parserv2/index.js +361 -0
- package/lib/parserv2/index.js.map +1 -0
- package/lib/parserv2/lexer.d.ts +35 -0
- package/lib/parserv2/lexer.js +190 -0
- package/lib/parserv2/lexer.js.map +1 -0
- package/lib/parserv2/types.d.ts +75 -0
- package/lib/parserv2/types.js +2 -0
- package/lib/parserv2/types.js.map +1 -0
- package/package.json +47 -0
- package/readme.md +105 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export type FunctionAST = {
|
|
2
|
+
type: "function";
|
|
3
|
+
functionName: string;
|
|
4
|
+
parameters: ExpressionAST[];
|
|
5
|
+
};
|
|
6
|
+
export type VariableAST = {
|
|
7
|
+
type: "variable";
|
|
8
|
+
value: string;
|
|
9
|
+
};
|
|
10
|
+
export type IdentifierAST = {
|
|
11
|
+
type: "identifier";
|
|
12
|
+
value: string;
|
|
13
|
+
};
|
|
14
|
+
export type ThisAST = {
|
|
15
|
+
type: "this";
|
|
16
|
+
};
|
|
17
|
+
export type IndexAST = {
|
|
18
|
+
type: "index";
|
|
19
|
+
};
|
|
20
|
+
export type TotalAST = {
|
|
21
|
+
type: "total";
|
|
22
|
+
};
|
|
23
|
+
export type InvocationAST = FunctionAST | IdentifierAST | ThisAST | IndexAST | TotalAST;
|
|
24
|
+
export type IndexedAST = {
|
|
25
|
+
type: "indexed";
|
|
26
|
+
index: ExpressionAST;
|
|
27
|
+
};
|
|
28
|
+
export type NullAST = {
|
|
29
|
+
type: "literal";
|
|
30
|
+
literalType: "null";
|
|
31
|
+
value: null;
|
|
32
|
+
};
|
|
33
|
+
export type BooleanAST = {
|
|
34
|
+
type: "literal";
|
|
35
|
+
literalType: "boolean";
|
|
36
|
+
value: boolean;
|
|
37
|
+
};
|
|
38
|
+
export type NumberAST = {
|
|
39
|
+
type: "literal";
|
|
40
|
+
literalType: "number";
|
|
41
|
+
value: number;
|
|
42
|
+
};
|
|
43
|
+
export type StringAST = {
|
|
44
|
+
type: "literal";
|
|
45
|
+
literalType: "string";
|
|
46
|
+
value: string;
|
|
47
|
+
};
|
|
48
|
+
export type DateAST = {
|
|
49
|
+
type: "literal";
|
|
50
|
+
literalType: "date";
|
|
51
|
+
value: string;
|
|
52
|
+
};
|
|
53
|
+
export type DateTimeAST = {
|
|
54
|
+
type: "literal";
|
|
55
|
+
literalType: "datetime";
|
|
56
|
+
value: string;
|
|
57
|
+
};
|
|
58
|
+
export type TimeAST = {
|
|
59
|
+
type: "literal";
|
|
60
|
+
literalType: "time";
|
|
61
|
+
value: string;
|
|
62
|
+
};
|
|
63
|
+
export type LiteralAST = NullAST | BooleanAST | NumberAST | StringAST | DateAST | DateTimeAST | TimeAST;
|
|
64
|
+
export type TermAST = ExpressionAST | InvocationAST | LiteralAST | VariableAST;
|
|
65
|
+
export type OperationAST = {
|
|
66
|
+
type: "operation";
|
|
67
|
+
operator: "*" | "/" | "div" | "mod" | "+" | "-" | "&" | "is" | "as" | "|" | "<=" | "<" | ">" | ">=" | "=" | "~" | "!=" | "!~" | "in" | "contains" | "and" | "or" | "xor" | "implies";
|
|
68
|
+
left: ExpressionAST;
|
|
69
|
+
right: ExpressionAST;
|
|
70
|
+
};
|
|
71
|
+
export type SingularExpression = {
|
|
72
|
+
type: "expression";
|
|
73
|
+
expression: [TermAST, ...Array<InvocationAST | IndexedAST>];
|
|
74
|
+
};
|
|
75
|
+
export type ExpressionAST = SingularExpression | OperationAST;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/parserv2/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@haste-health/fhirpath",
|
|
3
|
+
"version": "0.12.2",
|
|
4
|
+
"homepage": "https://haste.health",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/HasteHealth/HasteHealth.git"
|
|
8
|
+
},
|
|
9
|
+
"description": "",
|
|
10
|
+
"main": "lib/index.js",
|
|
11
|
+
"types": "lib/index.d.ts",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"test": "pnpm node --experimental-vm-modules $(pnpm bin jest)",
|
|
16
|
+
"publish": "pnpm build && pnpm npm publish --access public --tolerate-republish"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@haste-health/meta-value": "workspace:^",
|
|
20
|
+
"chevrotain": "^11.0.3"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@babel/plugin-syntax-import-attributes": "^7.26.0",
|
|
24
|
+
"@babel/preset-env": "^7.26.9",
|
|
25
|
+
"@babel/preset-typescript": "^7.26.0",
|
|
26
|
+
"@chevrotain/types": "^11.0.3",
|
|
27
|
+
"@haste-health/artifacts": "workspace:^",
|
|
28
|
+
"@haste-health/fhir-types": "workspace:^",
|
|
29
|
+
"@haste-health/haste-health.fhir.r4.core": "workspace:^",
|
|
30
|
+
"@haste-health/hl7.fhir.r4.core": "workspace:^",
|
|
31
|
+
"@jest/globals": "^29.7.0",
|
|
32
|
+
"@types/jest": "^29.5.14",
|
|
33
|
+
"jest": "^29.7.0",
|
|
34
|
+
"ts-jest": "^29.3.2",
|
|
35
|
+
"tsx": "4.11.2",
|
|
36
|
+
"typescript": "5.9.2"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"lib/**"
|
|
40
|
+
],
|
|
41
|
+
"exports": {
|
|
42
|
+
".": "./lib/index.js",
|
|
43
|
+
"./lib": "./lib/index.js",
|
|
44
|
+
"./analyze": "./lib/analyze.js",
|
|
45
|
+
"./lib/analyze": "./lib/analyze.js"
|
|
46
|
+
}
|
|
47
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# FHIRPath
|
|
2
|
+
|
|
3
|
+
## API
|
|
4
|
+
|
|
5
|
+
### evaluate
|
|
6
|
+
|
|
7
|
+
Returns a JS object/primitive based on the evaluation.
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
evaluate(
|
|
11
|
+
expression: string,
|
|
12
|
+
ctx: unknown,
|
|
13
|
+
options?: Options
|
|
14
|
+
): NonNullable<unknown>[]
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### evaluateWithMeta
|
|
18
|
+
|
|
19
|
+
Returns a @haste-health/meta-value singular value which contains data along with metadata about the evaluation.
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
function evaluateWithMeta(
|
|
23
|
+
expression: string,
|
|
24
|
+
ctx: unknown,
|
|
25
|
+
options?: Options
|
|
26
|
+
): MetaValueSingular<NonNullable<unknown>>[];
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Arguments
|
|
30
|
+
|
|
31
|
+
| name | type | description |
|
|
32
|
+
| ------------------ | ---------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
|
|
33
|
+
| expression | string | FHIRPath expression to evaluate. |
|
|
34
|
+
| ctx | unknown | The context which the fhirpath is being evaluated from (sets $this context). |
|
|
35
|
+
| options | Object | Includes variables and metadata deriviation functions. |
|
|
36
|
+
| options.variables | Object \| Function | If an object is Record\<variableName, variableValue\> else (variableName)=> variableValue. |
|
|
37
|
+
| options.meta | Object | MetaInformation used to zip metadata with value. Used in type functions and operators. |
|
|
38
|
+
| options.meta.type | string | Root type for ctx. |
|
|
39
|
+
| options.meta.getSD | (fhir_version: FHIRVersion, type: string) => StructureDefinition | Returns a StructureDefinition based on type passed in. |
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import * as fhirpath from "@haste-health/fhirpath";
|
|
45
|
+
|
|
46
|
+
// Default returns javascript object.
|
|
47
|
+
expect(fhirpath.evaluate("4 + 5", {})).toEqual([9]);
|
|
48
|
+
expect(fhirpath.evaluate("$this.test + 2 * 4", { test: 4 })).toEqual([12]);
|
|
49
|
+
|
|
50
|
+
// Evaluation with metavalue return (returns value in addition to meta information.)
|
|
51
|
+
expect(
|
|
52
|
+
evaluateWithMeta(
|
|
53
|
+
"$this.name",
|
|
54
|
+
{
|
|
55
|
+
resourceType: "Patient",
|
|
56
|
+
name: [{ given: ["bob"], family: "jameson" }],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
meta: {
|
|
60
|
+
type: "Patient",
|
|
61
|
+
getSD: (fhirVersion, type: code) => {
|
|
62
|
+
const foundSD = sds.find((sd) => sd.type === type);
|
|
63
|
+
return foundSD;
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
).map((v) => v.meta()?.type)
|
|
68
|
+
).toEqual(["HumanName"]);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Operations supported
|
|
72
|
+
|
|
73
|
+
| Operation | Description | Supported |
|
|
74
|
+
| ------------------------- | -------------------------------------------------------------------------------------------- | --------- |
|
|
75
|
+
| + (addition) | Concatenate strings or add values if numeric. | true |
|
|
76
|
+
| - (subtraction) | Subtracts the right operand from the left operand. | true |
|
|
77
|
+
| as type specifier | Returns left operand if value is of type specified. | true |
|
|
78
|
+
| is(type : type specifier) | Filters left operand based on type specifier. | true |
|
|
79
|
+
| \* (multiplication) | Multiplies both arguments. | true |
|
|
80
|
+
| / (division) | Divides the left operand by the right operand | true |
|
|
81
|
+
| \| (union collections) | Merge the two collections into a single collection | true |
|
|
82
|
+
| = (Equals) | Returns true if the left collection is equal to the right collection | true |
|
|
83
|
+
| != (Not Equals) | Converse operator of equals returns true if left collection is not equal to right collection | true |
|
|
84
|
+
|
|
85
|
+
## Supported Functions
|
|
86
|
+
|
|
87
|
+
| Name | Description | Supported |
|
|
88
|
+
| ---------- | ------------------------------------------------------------------------------------------------------------- | --------- |
|
|
89
|
+
| empty | Returns true if the input collection is empty ({ }) and false otherwise. | true |
|
|
90
|
+
| exists | Returns true if the collection has any elements, and false otherwise. | true |
|
|
91
|
+
| all | Returns true if for every element in the input collection, criteria evaluates to true. | true |
|
|
92
|
+
| allTrue | Takes a collection of Boolean values and returns true if all the items are true. | true |
|
|
93
|
+
| anyTrue | Takes a collection of Boolean values and returns true if any of the items are true. | true |
|
|
94
|
+
| allFalse | Takes a collection of Boolean values and returns true if all the items are false. | true |
|
|
95
|
+
| anyFalse | Takes a collection of Boolean values and returns true if any of the items are false. | true |
|
|
96
|
+
| subsetOf | Returns true if all items in the input collection are members of the collection passed in. | true |
|
|
97
|
+
| supersetOf | Returns true if all items in the collection passed as the other argument are members of the input collection. | true |
|
|
98
|
+
| count | Returns the integer count of the number of items in the input collection. | true |
|
|
99
|
+
| distinct | Returns a collection containing only the unique items in the input collection. | true |
|
|
100
|
+
| isDistinct | Returns true if all the items in the input collection are distinct. | true |
|
|
101
|
+
| where | Returns a collection containing only those elements in the input collection based on where expression. | true |
|
|
102
|
+
| select | Evaluates the projection expression for each item in the input collection. | true |
|
|
103
|
+
| repeat | A version of select that will repeat the projection and add it to the output collection. | true |
|
|
104
|
+
| ofType | Returns a collection that contains all items in the input collection that are of the given type. | true |
|
|
105
|
+
| as | Returns filter same as ofType used for backwards compatibility. | true |
|