fhirpath 0.2.0.pre4 → 0.2.0.pre5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eacb9dc2934ca76d58acb3c6aab97acc1f2d602f436d28d1518a0ee26a25c14d
4
- data.tar.gz: 7460ad33f47fd12408aaa905318285cec5e05f4db3503dcfd3ea4612c2d3ab53
3
+ metadata.gz: 85f3b8a5df3dbd8edd95959a40260bd4a12eeb03b09c862befacf50439ea95a1
4
+ data.tar.gz: 17a74859ea3503d853acac89bad663de21f3d14c0e5fa755b29c415adf063c16
5
5
  SHA512:
6
- metadata.gz: 3e5de5efdbd7037022c0e36587dbebec79ab0406da23b76067b858d49f47b9edfecff975ef9e048fb19fd3455c1e2e704ad4491f77bffb47517abc46e3d5fc64
7
- data.tar.gz: 5e7b7ec8152d3534464c70b739e025d63b06490f3c3fe8dcb16dc26017af0597d888243057de6600ac5a922eddda05035a7a5254773085a6d738ef339b65d494
6
+ metadata.gz: 02f4d65b6b8b760ac5e6583e093fa998508fbc623eb025453f9354b41de8a843e127c95863d9a3958dd7ca4301bc3253f5b926972e6eafcb66b48260d22a4df1
7
+ data.tar.gz: 1ad8cd8dfb6d77003b6d2dbf9528fac97a30434f8f74f8330faa9beed66c48b7881a6752a6b3b4b9e30d13798a83c9350f16e97ab5e4de27f87404e55d05e2d3
data/CHANGELOG.md CHANGED
@@ -4,7 +4,7 @@ All notable changes to this project are documented here. The project is pre-1.0;
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
- ## [0.2.0.pre4] - 2026-09-07
7
+ ## [0.2.0.pre5] - 2026-09-07
8
8
  - Add the `aggregate()` function with `$this`, `$total`, and `$index` variables for general-purpose collection aggregation (issue #43). The function signature is `aggregate(expression, initial)` where the expression is evaluated per item with the accumulator as `$total`. Empty collections return the initial value (or empty if omitted). Closes issue #43.
9
9
  - Add keyword-named functions (`contains`, `in`) usable after member access (`Patient.name.contains('John')`) — the lexer previously classified these as binary operators only, preventing function-call syntax after `.` (issue #66). Also registers both as standard functions with arity 1.
10
10
  - Accept raw JSON strings in `FHIRPath.evaluate()` and `CompiledExpression#evaluate`: strings starting with `{` or `[` after optional whitespace are parsed via `JSON.parse` once per call; malformed JSON raises `JSONInputError` (code `:invalid_json`); `Hash`/`Array` inputs pass through unchanged; other strings remain singleton string values (issue #56).
data/README.md CHANGED
@@ -42,8 +42,6 @@ documented limitations before using this implementation in production.
42
42
 
43
43
  ## Quick start
44
44
 
45
- ## Quick start
46
-
47
45
  ```ruby
48
46
  require "fhirpath"
49
47
 
@@ -51,7 +49,7 @@ require "fhirpath"
51
49
  data = { items: [1, 2, 3, 4, 5] }
52
50
  FHIRPath.evaluate(data, "items.where($this > 3)") # => [4, 5]
53
51
 
54
- # FHIR R4 model adapter
52
+ # FHIR R4 model adapter — Ruby Hash
55
53
  observation = {
56
54
  "resourceType" => "Observation",
57
55
  "id" => "obs-1",
@@ -65,6 +63,25 @@ FHIRPath.evaluate(observation, "valueQuantity.value > 5.0", model: :r4) # => [t
65
63
  FHIRPath.evaluate(observation, "valueQuantity.unit", model: :r4) # => ["mmol/L"]
66
64
  FHIRPath.evaluate(observation, "code.coding.system", model: :r4) # => ["http://loinc.org"]
67
65
 
66
+ # Raw JSON string input — evaluate FHIR resources directly from HTTP responses
67
+ patient_json = <<~JSON
68
+ {
69
+ "resourceType": "Patient",
70
+ "id": "pat-1",
71
+ "name": [{ "use": "official", "family": "Chalmers", "given": ["Peter", "James"] }],
72
+ "gender": "male",
73
+ "birthDate": "1974-12-25",
74
+ "address": [{ "use": "home", "city": "PleasantVille", "state": "Vic", "postalCode": "3999" }]
75
+ }
76
+ JSON
77
+
78
+ FHIRPath.evaluate(patient_json, "Patient.name.where(use='official').family", model: :r4)
79
+ # => ["Chalmers"]
80
+ FHIRPath.evaluate(patient_json, "Patient.birthDate", model: :r4)
81
+ # => ["1974-12-25"]
82
+ FHIRPath.evaluate(patient_json, "Patient.address.city", model: :r4)
83
+ # => ["PleasantVille"]
84
+
68
85
  # Type filtering with ofType()
69
86
  bundle = {
70
87
  "resourceType" => "Bundle",
@@ -74,6 +91,13 @@ bundle = {
74
91
  ]
75
92
  }
76
93
  FHIRPath.evaluate(bundle, "entry.resource.ofType(Observation)", model: :r4) # => [Observation resource]
94
+
95
+ # Compiled expression reuse
96
+ program = FHIRPath.compile("Patient.name.family")
97
+ program.evaluate({ "resourceType" => "Patient", "name" => [{ "family" => "Lovelace" }] }).to_a
98
+ # => ["Lovelace"]
99
+ program.call(patient_json).to_a # also accepts raw JSON strings
100
+ # => ["Chalmers"]
77
101
  ```
78
102
 
79
103
  FHIR R4 JSON can be selected explicitly through the versioned provider. The
data/docs/api.md CHANGED
@@ -65,6 +65,54 @@ Returns a `FHIRPath::Collection`. Empty results are collections with `empty? ==
65
65
 
66
66
  The `resource` argument may be an already-parsed Hash/Array (used directly, never re-serialized) or a raw JSON document String. Strings that open with `{` or `[` after leading whitespace are parsed with `JSON.parse` once per call; a malformed document raises `FHIRPath::JSONInputError` (code `:invalid_json`) with a generic public message that does not echo document contents, while `original_cause` retains the underlying `JSON::ParserError` for programmatic diagnostics. Any other String — plain text, JSON scalar text such as `"null"` or `"123"`, or a quoted JSON primitive like `"\"Ada\""` — keeps its pre-existing meaning as a singleton FHIRPath string value and is never parsed. Parsing builds a fresh structure per call; the caller's String and any Hash/Array resource are never mutated or frozen. `CompiledExpression#evaluate` and `#call` apply the same resource handling.
67
67
 
68
+ **Resource input handling summary:**
69
+
70
+ | Input type | Behavior |
71
+ |------------|----------|
72
+ | `Hash` / `Array` | Used directly (never re-serialized) |
73
+ | String starting with `{` or `[` (after whitespace) | Parsed as JSON document via `JSON.parse` once per call; malformed JSON raises `JSONInputError` (code `invalid_json`) |
74
+ | Any other String | Treated as a singleton FHIRPath string value (never parsed) |
75
+
76
+ ```ruby
77
+ # Hash input — used directly
78
+ FHIRPath.evaluate({ "resourceType" => "Patient" }, "Patient.id")
79
+
80
+ # JSON object string — parsed as JSON document
81
+ json = '{ "resourceType": "Patient", "id": "123" }'
82
+ FHIRPath.evaluate(json, "Patient.id") # => ["123"]
83
+
84
+ # JSON array string — parsed as JSON document
85
+ FHIRPath.evaluate('[1, 2, 3]', 'count()') # => [3]
86
+
87
+ # Whitespace before { or [ is ignored
88
+ FHIRPath.evaluate(" \n{ \"resourceType\": \"Patient\" }", "Patient.id")
89
+
90
+ # Plain string — NOT parsed, treated as FHIRPath string value
91
+ FHIRPath.evaluate("just text", "$this") # => ["just text"]
92
+
93
+ # JSON scalar text — NOT parsed (not an object/array)
94
+ FHIRPath.evaluate("123", "$this") # => ["123"] (string, not number)
95
+ FHIRPath.evaluate("true", "$this") # => ["true"] (string, not Boolean)
96
+ FHIRPath.evaluate("null", "$this") # => ["null"] (string, not empty)
97
+
98
+ # Quoted JSON primitive — NOT parsed
99
+ FHIRPath.evaluate('"Ada"', "$this") # => ["\"Ada\""] (string with quotes)
100
+ ```
101
+
102
+ **Error handling:**
103
+
104
+ ```ruby
105
+ # Malformed JSON raises structured JSONInputError
106
+ begin
107
+ FHIRPath.evaluate('{ "resourceType": "Patient", invalid: }', "Patient.id")
108
+ rescue FHIRPath::JSONInputError => e
109
+ e.code # => :invalid_json
110
+ e.message # => "resource string is not valid JSON" (no document contents)
111
+ e.to_h[:code] # => :invalid_json
112
+ e.original_cause # => JSON::ParserError (for programmatic diagnostics)
113
+ end
114
+ ```
115
+
68
116
  `variables:` supplies external constants using either String or Symbol keys:
69
117
 
70
118
  ```ruby
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FHIRPath
4
- VERSION = '0.2.0.pre4'
4
+ VERSION = '0.2.0.pre5'
5
5
  # A stable release requires the complete release gate to be deliberately
6
6
  # promoted. Keep pre-release status explicit while the shared-suite and
7
7
  # model-adapter work remains incomplete.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fhirpath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.pre4
4
+ version: 0.2.0.pre5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicco Reyes