openehr 2.5.0 → 2.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1182edb39c044e8dff2459c540f9216e511b7f404008498aab658a4a1e37999f
4
- data.tar.gz: 9d7c892108c4de275b8c6beaf6699ddbe5be1bb4d3c3fc7315fb67ed4fd271fd
3
+ metadata.gz: 969720a829357b3797b6d18e228dc5be152942fd641222725d746bacc7fd487f
4
+ data.tar.gz: 92563db045194d48ac82c71331a2f37752b20c83c4b4f892e561f59053912d8e
5
5
  SHA512:
6
- metadata.gz: 8477cd032861a008bba3f3fc3ecdf18516235c64c634cb845c598c29875f6ee4b2feb24b96599f2c1d5a0d0d52b0c6bc7e18faf22adf97836ace83375ba8c3df
7
- data.tar.gz: 68f7cdf8a37e7707934a438b1e231d6894c64e63daf069e35a288dff0c76719058798277210cbfed31493456f03e3586678a83cf65cbc87187407d85342eb743
6
+ metadata.gz: f402935d892bb289ebde92de714f6c0d4ea125f3d96f77f0702d95307340a04445e8d85913c4bccd56559ac4d721b70936543bdd8b7e1a6b48be0f32f6b26cc1
7
+ data.tar.gz: b90f60f63449137cd37086bb0bbff5d6e3800c52fc1a721ded6e25573b9e3edef9ef152819f67f04e0d0a286b0cbd86cfadfd87cb368b02a2a235ddc28ebb138
data/README.rdoc CHANGED
@@ -8,7 +8,7 @@ A Ruby implementation of the openEHR specifications
8
8
  = Requirements
9
9
 
10
10
  * Supports the Ruby versions currently maintained upstream by Ruby core: 3.3, 3.4, and 4.0.
11
- * Developed with CRuby 4.0.7 on Linux; CI covers 3.3, 3.4, and 4.0.
11
+ * Developed with CRuby 4.0.10 on Linux; CI covers 3.3, 3.4, and 4.0.
12
12
  * Other versions, including 3.1 and 3.2, are not supported (both reached EOL).
13
13
 
14
14
  =Description
@@ -20,8 +20,22 @@ module OpenEHR
20
20
  # Attribute hops not reachable through the path_attribute DSL.
21
21
  # Expand only when a real query needs another one - see the
22
22
  # project's "no arbitrary send" rule in the class comment above.
23
+ #
24
+ # These names are generic: allowed on any value that has a public
25
+ # reader of that name (a value without one raises ExecutionError).
26
+ # A new name should normally go into TYPED_TERMINAL_HOPS instead,
27
+ # so that it is reachable only on the RM type it belongs to.
23
28
  ALLOWED_TERMINAL_HOPS = %w[code_string defining_code magnitude name time value].freeze
24
29
 
30
+ # Attribute hops allowed on one RM type only (matched with is_a?,
31
+ # so subclasses inherit them). Class names are resolved lazily:
32
+ # this file is loaded before parts of the RM.
33
+ TYPED_TERMINAL_HOPS = {
34
+ 'OpenEHR::RM::Common::Archetyped::Locatable' => %w[archetype_details],
35
+ 'OpenEHR::RM::Common::Archetyped::Archetyped' => %w[archetype_id template_id],
36
+ 'OpenEHR::RM::Composition::EventContext' => %w[end_time setting start_time]
37
+ }.freeze
38
+
25
39
  # Dataset::EHRRecord#ehr_id is already an unwrapped String (see
26
40
  # Dataset's own header comment), but AQL's "e/ehr_id/value" syntax
27
41
  # still expects a HierObjectID-shaped hop with its own #value -
@@ -88,7 +102,7 @@ module OpenEHR
88
102
  # PATHABLE#item_at_path itself), not an error - only an
89
103
  # *ambiguous* match (more than one item) is.
90
104
  def navigate_pathable(current, segment)
91
- matches = current.items_at_path(rm_path_for(segment))
105
+ matches = narrow_by_name(current.items_at_path(rm_path_for(segment)), segment.predicate)
92
106
  case matches.size
93
107
  when 0 then nil
94
108
  when 1 then matches.first
@@ -97,55 +111,62 @@ module OpenEHR
97
111
  end
98
112
  end
99
113
 
114
+ # A predicate's name value ("[id, 'Name']") is applied here, on the
115
+ # items PATHABLE returned for the id alone, instead of being written
116
+ # into the path text: PATHABLE path text quotes the name with
117
+ # apostrophes and cannot hold a name that contains one (issue #65).
118
+ # Same rule as Pathable.select_by_predicate: the node's name.value
119
+ # must equal the given name.
120
+ def narrow_by_name(items, predicate)
121
+ name = predicate_name(predicate)
122
+ return items if name.nil?
123
+
124
+ items.select do |item|
125
+ item.respond_to?(:name) && item.name.respond_to?(:value) && item.name.value == name
126
+ end
127
+ end
128
+
129
+ def predicate_name(predicate)
130
+ return nil if predicate.nil? || predicate.value.nil?
131
+ return predicate.value if predicate.value.is_a?(String)
132
+
133
+ kind = predicate.is_a?(Model::ArchetypePredicate) ? 'archetype' : 'node'
134
+ raise ExecutionError, "cannot evaluate a #{predicate.value.class} #{kind} predicate value yet"
135
+ end
136
+
100
137
  def navigate_terminal(current, segment)
101
138
  raise ExecutionError, "path predicates on a non-Pathable value are not supported (#{segment.attribute})" if segment.predicate
102
- unless ALLOWED_TERMINAL_HOPS.include?(segment.attribute)
139
+ unless terminal_hop_allowed?(current, segment.attribute)
103
140
  raise ExecutionError, "unsupported path attribute #{segment.attribute.inspect} on a #{current.class}"
104
141
  end
105
142
 
106
143
  current.public_send(segment.attribute)
107
144
  end
108
145
 
146
+ def terminal_hop_allowed?(current, attribute)
147
+ return current.respond_to?(attribute) if ALLOWED_TERMINAL_HOPS.include?(attribute)
148
+
149
+ TYPED_TERMINAL_HOPS.any? do |class_name, attributes|
150
+ attributes.include?(attribute) && current.is_a?(Object.const_get(class_name))
151
+ end
152
+ end
153
+
154
+ # PATHABLE path text for the segment, by id only - see narrow_by_name
155
+ # for the name value.
109
156
  def rm_path_for(segment)
110
157
  return "/#{segment.attribute}" unless segment.predicate
111
158
 
112
- "/#{segment.attribute}[#{predicate_path_text(segment.predicate)}]"
159
+ "/#{segment.attribute}[#{predicate_id_text(segment.predicate)}]"
113
160
  end
114
161
 
115
- def predicate_path_text(predicate)
162
+ def predicate_id_text(predicate)
116
163
  case predicate
117
- when Model::ArchetypePredicate
118
- archetype_predicate_path_text(predicate)
119
- when Model::NodePredicate
120
- node_predicate_path_text(predicate)
164
+ when Model::ArchetypePredicate then predicate.archetype_id
165
+ when Model::NodePredicate then predicate.code
121
166
  else
122
167
  raise ExecutionError, "cannot evaluate a #{predicate.class} path predicate yet"
123
168
  end
124
169
  end
125
-
126
- # "[archetype_id, 'Name']" carries its name value into the PATHABLE
127
- # path text the same way a node predicate does, so
128
- # Pathable.select_by_predicate can tell apart siblings that share
129
- # one archetype id (issue #60).
130
- def archetype_predicate_path_text(predicate)
131
- return predicate.archetype_id unless predicate.value
132
-
133
- unless predicate.value.is_a?(String)
134
- raise ExecutionError, "cannot evaluate a #{predicate.value.class} archetype predicate value yet"
135
- end
136
-
137
- "#{predicate.archetype_id}, '#{predicate.value}'"
138
- end
139
-
140
- def node_predicate_path_text(predicate)
141
- return predicate.code unless predicate.value
142
-
143
- unless predicate.value.is_a?(String)
144
- raise ExecutionError, "cannot evaluate a #{predicate.value.class} node predicate value yet"
145
- end
146
-
147
- "#{predicate.code}, '#{predicate.value}'"
148
- end
149
170
  end
150
171
  end
151
172
  end
@@ -288,7 +288,8 @@ module OpenEHR
288
288
  class ISO8601Date
289
289
  include ISO8601DateModule, Comparable
290
290
  def initialize(string)
291
- /(\d{4})(?:-(\d{2})(?:-(\d{2})?)?)?/ =~ string
291
+ # Anchored (issue #72): YYYY, YYYY-MM or YYYY-MM-DD and nothing else.
292
+ /\A(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?\z/ =~ string
292
293
  if $1.nil?
293
294
  raise ArgumentError, 'data invalid'
294
295
  else
@@ -495,7 +496,17 @@ module OpenEHR
495
496
  def hour_unknown?
496
497
  @hour.nil?
497
498
  end
498
-
499
+
500
+ # A date-time may have no time part at all (YYYY-MM-DD, YYYY-MM,
501
+ # YYYY; issue #59), so the hour may be nil here, unlike in a time.
502
+ def hour=(hour)
503
+ if hour.nil?
504
+ @hour = nil
505
+ else
506
+ super
507
+ end
508
+ end
509
+
499
510
  def as_string
500
511
  if (!@year.nil? and !@month.nil? and !@day.nil?)
501
512
  s = Date.new(@year, @month, @day).to_s
@@ -526,7 +537,20 @@ module OpenEHR
526
537
  class ISO8601DateTime
527
538
  include ISO8601DateTimeModule, Comparable
528
539
  def initialize(string)
529
- unless /(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?T(\d{2})(?::(\d{2})(?::(\d{2})(?:(\.|,)(\d+))?)?(Z|([+-]\d{2}):?(\d{2}))?)?/ =~ string
540
+ # Anchored, and the date must be complete before a time may follow
541
+ # (issue #72): unanchored, any string containing a date-time passed
542
+ # and the rest was dropped.
543
+ #
544
+ # The time part, and the day and month, may be missing (YYYY-MM-DD,
545
+ # YYYY-MM, YYYY; issue #59), so a value known only to the day or
546
+ # the year is kept at that precision instead of a time of day being
547
+ # made up. openEHR BASE Foundation Types is not consistent here:
548
+ # section 6.2 ("Partial variants of Iso8601_date_time can include
549
+ # missing hours, days and months") and the Iso8601_date_time class
550
+ # description allow it; valid_iso8601_date_time and the class
551
+ # invariants (Partial_validity_hour: not hour_unknown, ...) do not.
552
+ # This implementation follows the former.
553
+ unless /\A(\d{4})(?:-(\d{2})(?:-(\d{2})(?:T(\d{2})(?::(\d{2})(?::(\d{2})(?:(\.|,)(\d+))?)?(Z|([+-]\d{2}):?(\d{2}))?)?)?)?)?\z/ =~ string
530
554
  raise ArgumentError, 'format invalid'
531
555
  else
532
556
  self.year = $1.to_i
@@ -223,8 +223,15 @@ module OpenEHR
223
223
  self.timezone = iso8601date_time.timezone
224
224
  end
225
225
 
226
+ # A missing part counts as the earliest value it could have
227
+ # (month 1, day 1, 00:00:00), so partial values (issue #59:
228
+ # YYYY-MM-DD, YYYY-MM, YYYY; and the time-partial forms, which
229
+ # raised TypeError here before) order as their earliest instant.
230
+ # Comparable#== follows this ordering: values of different
231
+ # precision that denote the same earliest instant are ==, while
232
+ # their #value still differs.
226
233
  def magnitude
227
- hour, minute = @hour, @minute
234
+ hour, minute = @hour || 0, @minute || 0
228
235
  if @timezone
229
236
  if @timezone.sign == -1
230
237
  hour -= @timezone.hour
@@ -235,10 +242,10 @@ module OpenEHR
235
242
  end
236
243
  end
237
244
  seconds = (((((((@year * 365.24) +
238
- (@month * 30.42) +
239
- @day) * 24) +
245
+ ((@month || 1) * 30.42) +
246
+ (@day || 1)) * 24) +
240
247
  hour) * 60) +
241
- minute) * 60) + @second
248
+ minute) * 60) + (@second || 0)
242
249
  if @fractional_second.nil?
243
250
  return seconds
244
251
  else
@@ -1,3 +1,3 @@
1
1
  module OpenEHR
2
- VERSION = "2.5.0"
2
+ VERSION = "2.6.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openehr
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shinji KOBAYASHI