openehr 2.4.3 → 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: 40ff9f4331d4dabef29f1178e862387d3aadb7c416268c97f5ac71bd239509a3
4
- data.tar.gz: fa2d3bc4b12109804ef131f9f498f1115f8a01e45f3482ede38a714d81e00fd1
3
+ metadata.gz: 969720a829357b3797b6d18e228dc5be152942fd641222725d746bacc7fd487f
4
+ data.tar.gz: 92563db045194d48ac82c71331a2f37752b20c83c4b4f892e561f59053912d8e
5
5
  SHA512:
6
- metadata.gz: a53690dd8004f16b0f2f130f1ec07f59c848878e1f13e1d4835cb0bb2712ca8a61d8005e2f202a58b7e86e899dcb7e861bc4495546bc7436de907ea81fe457c9
7
- data.tar.gz: 04eab1bf336f86d3f37790d3bb5d4615058c5f3fdb57e4777bb997b1912cfa8e7178031f5320e7b621c60fa6a82de3d3cbd2ec1850a5ae866f837e4a3ec6cfb3
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.6 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
@@ -487,11 +487,22 @@ module OpenEHR
487
487
 
488
488
  class CArchetypeRoot <CComplexObject
489
489
  attr_reader :slot_node_id, :archetype_id
490
+ # The terms and external bindings this one root carries in an
491
+ # operational template. An OPT repeats them under every
492
+ # C_ARCHETYPE_ROOT, and a template may rename them per root, so
493
+ # they differ between two roots that embed the same archetype.
494
+ # term_definitions: { language => { code => ArchetypeTerm } }
495
+ # term_bindings: { terminology => { code => [CodePhrase] } }
496
+ # Both are nil when not populated (e.g. a root not built by
497
+ # OPTParser, or a root without term_bindings).
498
+ attr_accessor :term_definitions, :term_bindings
490
499
 
491
500
  def initialize(args = {})
492
501
  super
493
502
  self.slot_node_id = args[:slot_node_id]
494
503
  self.archetype_id = args[:archetype_id]
504
+ self.term_definitions = args[:term_definitions]
505
+ self.term_bindings = args[:term_bindings]
495
506
  end
496
507
 
497
508
  def slot_node_id=(slot_node_id)
@@ -148,7 +148,7 @@ module OpenEHR
148
148
  when nil
149
149
  true
150
150
  when Model::ArchetypePredicate
151
- candidate.respond_to?(:archetype_node_id) && candidate.archetype_node_id == predicate.archetype_id
151
+ archetype_predicate_matches?(candidate, predicate)
152
152
  when Model::NodePredicate
153
153
  node_predicate_matches?(candidate, predicate)
154
154
  when Model::StandardPredicate
@@ -162,6 +162,21 @@ module OpenEHR
162
162
  end
163
163
  end
164
164
 
165
+ # archetypePredicate "[archetype_id]" matches by archetype_node_id
166
+ # alone; "[archetype_id, 'Name']" additionally requires the node's
167
+ # own `name` DV_TEXT to equal the given display name - the same
168
+ # rule as a nodePredicate's name value (issue #60).
169
+ def archetype_predicate_matches?(candidate, predicate)
170
+ return false unless candidate.respond_to?(:archetype_node_id) && candidate.archetype_node_id == predicate.archetype_id
171
+ return true unless predicate.value
172
+
173
+ unless predicate.value.is_a?(String)
174
+ raise ExecutionError, "cannot evaluate a #{predicate.value.class} archetype predicate value yet"
175
+ end
176
+
177
+ node_name_matches?(candidate, predicate.value)
178
+ end
179
+
165
180
  # nodePredicate "[atNNNN]" matches by archetype_node_id alone;
166
181
  # "[atNNNN, 'Name']" additionally requires the node's own `name`
167
182
  # DV_TEXT to equal the given display name.
@@ -20,7 +20,21 @@ 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
- ALLOWED_TERMINAL_HOPS = %w[magnitude name value].freeze
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.
28
+ ALLOWED_TERMINAL_HOPS = %w[code_string defining_code magnitude name time value].freeze
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
24
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
@@ -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,41 +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
- predicate.archetype_id
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
- def node_predicate_path_text(predicate)
127
- return predicate.code unless predicate.value
128
-
129
- unless predicate.value.is_a?(String)
130
- raise ExecutionError, "cannot evaluate a #{predicate.value.class} node predicate value yet"
131
- end
132
-
133
- "#{predicate.code}, '#{predicate.value}'"
134
- end
135
170
  end
136
171
  end
137
172
  end
@@ -29,6 +29,14 @@ module OpenEHR
29
29
  @value = value
30
30
  freeze
31
31
  end
32
+
33
+ # Query-text form, used in error messages that quote a path
34
+ # segment (see PathPart#to_s).
35
+ def to_s
36
+ return archetype_id if value.nil?
37
+
38
+ value.is_a?(String) ? "#{archetype_id}, '#{value}'" : "#{archetype_id}, $#{value.name}"
39
+ end
32
40
  end
33
41
 
34
42
  # nodePredicate : (ID_CODE | AT_CODE) (SYM_COMMA (STRING | PARAMETER | TERM_CODE | AT_CODE | ID_CODE))? | ... ;
@@ -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
@@ -155,7 +155,39 @@ module OpenEHR
155
155
  ArchetypeTerminology.new(
156
156
  concept_code: concept_code,
157
157
  original_language: language,
158
- term_definitions: td)
158
+ term_definitions: td,
159
+ term_bindings: opt_term_bindings(nodes))
160
+ end
161
+
162
+ # An OPT writes term_bindings as
163
+ # <term_bindings terminology="T"><items code="atNNNN"><value>
164
+ # <terminology_id><value>T</value></terminology_id>
165
+ # <code_string>[T::code]</code_string></value></items></term_bindings>
166
+ # (a serialized CODE_PHRASE per item), not the flat
167
+ # attribute-plus-text shape XMLArchetypeParser#ontology_bindings
168
+ # reads. The result has the same in-memory shape on both paths:
169
+ # { terminology => { code => [CodePhrase] } }. code_string is kept
170
+ # exactly as written. nil (not {}) when the archetype has no
171
+ # term_bindings, so "not populated" stays distinguishable.
172
+ # The method name is deliberately not one openehr-rails'
173
+ # OpenehrRails::Opt::Parser subclass already defines.
174
+ def opt_term_bindings(nodes)
175
+ bindings = nodes.xpath('term_bindings').each_with_object({}) do |binding, by_terminology|
176
+ codes = (by_terminology[binding['terminology']] ||= {})
177
+ binding.xpath('items').each do |item|
178
+ (codes[item['code']] ||= []) << opt_binding_code_phrase(item)
179
+ end
180
+ end
181
+ bindings.empty? ? nil : bindings
182
+ end
183
+
184
+ def opt_binding_code_phrase(item)
185
+ OpenEHR::RM::DataTypes::Text::CodePhrase.new(
186
+ code_string: text_on_path(item, './value/code_string'),
187
+ terminology_id: OpenEHR::RM::Support::Identification::TerminologyID.new(
188
+ value: text_on_path(item, './value/terminology_id/value')
189
+ )
190
+ )
159
191
  end
160
192
 
161
193
  def term_definitions(nodes)
@@ -169,6 +201,17 @@ module OpenEHR
169
201
  { language.code_string => term_items }
170
202
  end
171
203
 
204
+ # One C_ARCHETYPE_ROOT's own terms, for CArchetypeRoot#term_definitions:
205
+ # { language => { code => ArchetypeTerm } }. Unlike
206
+ # component_terminologies (keyed by archetype id, last root wins,
207
+ # { language => [ArchetypeTerm] }), this is kept per root, so a
208
+ # template's per-root renames survive (issue #58).
209
+ def opt_root_term_definitions(nodes)
210
+ term_definitions(nodes).transform_values do |terms|
211
+ terms.to_h { |term| [term.code, term] }
212
+ end
213
+ end
214
+
172
215
  def empty_then_nil(val)
173
216
  if val.empty?
174
217
  return nil
@@ -21,11 +21,17 @@ module OpenEHR
21
21
  node.id = id unless id.nil? or id.empty?
22
22
  occurrences = occurrences(xml.xpath('./occurrences'))
23
23
  archetype_id = OpenEHR::RM::Support::Identification::ArchetypeID.new(value: text_on_path(xml, './archetype_id/value'))
24
+ # The top-level definition's path is "/". An embedded root is
25
+ # addressed by its archetype id, the way RM data paths and AQL
26
+ # address it - its node_id is "at0000" for nearly every embedded
27
+ # archetype, so it cannot tell sibling roots apart (issue #43).
24
28
  if node.root? or node.id.nil?
25
29
  node.path = "/"
30
+ else
31
+ node.path = "#{node.path}[#{archetype_id.value}]"
26
32
  end
27
33
  component_terminologies(archetype_id, xml)
28
- OpenEHR::AM::Archetype::ConstraintModel::CArchetypeRoot.new(rm_type_name: rm_type_name, node_id: node.id, path: node.path, occurrences: occurrences, archetype_id: archetype_id, attributes: attributes(xml.xpath('./attributes'), node))
34
+ OpenEHR::AM::Archetype::ConstraintModel::CArchetypeRoot.new(rm_type_name: rm_type_name, node_id: node.id, path: node.path, occurrences: occurrences, archetype_id: archetype_id, term_definitions: opt_root_term_definitions(xml), term_bindings: opt_term_bindings(xml), attributes: attributes(xml.xpath('./attributes'), node))
29
35
  end
30
36
 
31
37
  def c_complex_object(xml, node)
@@ -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
@@ -36,6 +36,10 @@ module OpenEHR
36
36
  ].freeze
37
37
  TERMINOLOGY_ID_IVARS = [:@name, :@version_id].freeze
38
38
  IDENTIFIER_IVARS = (ARCHETYPE_ID_IVARS + TERMINOLOGY_ID_IVARS).uniq.freeze
39
+ # CArchetypeRoot only (issue #58): its per-root terminology is
40
+ # scoped per class here, not added to EXCLUDED_IVARS, because
41
+ # ArchetypeOntology legitimately has ivars of the same two names.
42
+ ARCHETYPE_ROOT_IVARS = [:@term_definitions, :@term_bindings].freeze
39
43
 
40
44
  def initialize(rm_instance)
41
45
  @rm_instance = rm_instance
@@ -82,6 +86,8 @@ module OpenEHR
82
86
  exclusions + ARCHETYPE_ID_IVARS
83
87
  when OpenEHR::RM::Support::Identification::TerminologyID
84
88
  exclusions + TERMINOLOGY_ID_IVARS
89
+ when OpenEHR::AM::Archetype::ConstraintModel::CArchetypeRoot
90
+ exclusions + ARCHETYPE_ROOT_IVARS
85
91
  else
86
92
  exclusions
87
93
  end
@@ -1,3 +1,3 @@
1
1
  module OpenEHR
2
- VERSION = "2.4.3"
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.4.3
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shinji KOBAYASHI
@@ -253,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
253
253
  - !ruby/object:Gem::Version
254
254
  version: '0'
255
255
  requirements: []
256
- rubygems_version: 4.0.16
256
+ rubygems_version: 4.0.20
257
257
  specification_version: 4
258
258
  summary: Ruby implementation of the openEHR specification
259
259
  test_files: []