Class: OpenehrRails::Rm::GraphBuilder
- Inherits:
-
Object
- Object
- OpenehrRails::Rm::GraphBuilder
- Defined in:
- lib/openehr_rails/rm/graph_builder.rb
Overview
Builds the persisted RM node graph from a canonical composition hash (the shape Storable#to_rm_composition emits, also accepted from external canonical JSON). Inverse of CanonicalSerializer.
Constant Summary collapse
- RESERVED_KEYS =
Metadata keys that are not structural child attributes.
%w[_type archetype_node_id archetype_details name uid feeder_audit links].freeze
- MULTIPLE_ATTRIBUTES =
OpenehrRails::Storable::MULTIPLE_ATTRIBUTES
- SPECIAL_ATTRIBUTES =
Node attributes stored as typed columns instead of child rows.
{ 'HISTORY' => %w[origin], 'POINT_EVENT' => %w[time], 'INTERVAL_EVENT' => %w[time width math_function], 'ELEMENT' => %w[null_flavour] }.freeze
Instance Method Summary collapse
- #build!(composition) ⇒ Object
- #composition_attributes ⇒ Object
-
#initialize(canonical_hash) ⇒ GraphBuilder
constructor
A new instance of GraphBuilder.
Constructor Details
#initialize(canonical_hash) ⇒ GraphBuilder
Returns a new instance of GraphBuilder.
22 23 24 |
# File 'lib/openehr_rails/rm/graph_builder.rb', line 22 def initialize(canonical_hash) @hash = canonical_hash end |
Instance Method Details
#build!(composition) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/openehr_rails/rm/graph_builder.rb', line 37 def build!(composition) Array(@hash['content']).each_with_index do |entry_hash, index| build_node(composition, nil, 'content', entry_hash, index, "/content[#{entry_hash['archetype_node_id']}]") end composition end |
#composition_attributes ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/openehr_rails/rm/graph_builder.rb', line 26 def composition_attributes details = @hash['archetype_details'] || {} { archetype_node_id: @hash['archetype_node_id'], template_id: details.dig('template_id', 'value'), name_value: @hash.dig('name', 'value'), uid: @hash.dig('uid', 'value'), rm_version: details['rm_version'] || '1.0.4' }.compact end |