Class: OpenehrRails::Opt::FieldExtractor
- Inherits:
-
Object
- Object
- OpenehrRails::Opt::FieldExtractor
- Defined in:
- lib/openehr_rails/opt/field_extractor.rb
Overview
Walks the constraint tree of an OperationalTemplate and extracts the data ELEMENTs as flat field descriptions. This is the single source of truth that drives model/migration/view generation and, later, the openEHR RM <-> FHIR mapping.
Each field is a Hash:
name: Ruby attribute / DB column name (ASCII, unique)
label: display text from the template terminology (any language)
path: RM path from the COMPOSITION content
rm_type: openEHR data value type (e.g. 'DV_QUANTITY')
node_id: at-code of the ELEMENT
archetype_id: id of the enclosing archetype root (entry)
column_type: ActiveRecord column type symbol
units: unit string for DV_QUANTITY
magnitude_range: [lower, upper] for DV_QUANTITY
code_list: allowed codes for DV_CODED_TEXT
code_labels: {code => text} resolved from the terminology
terminology_id: terminology of the code list
required: true when the entry and element are both mandatory
Constant Summary collapse
- ENTRY_TYPES =
%w[OBSERVATION EVALUATION INSTRUCTION ACTION ADMIN_ENTRY].freeze
- SECTION_TYPE =
'SECTION'.freeze
- COLUMN_TYPES =
{ 'DV_QUANTITY' => :float, 'DV_PROPORTION' => :float, 'DV_COUNT' => :integer, 'DV_ORDINAL' => :integer, 'DV_SCALE' => :float, 'DV_TEXT' => :string, 'DV_CODED_TEXT' => :string, 'DV_IDENTIFIER' => :string, 'DV_URI' => :string, 'DV_BOOLEAN' => :boolean, 'DV_DATE' => :date, 'DV_TIME' => :time, 'DV_DATE_TIME' => :datetime, 'DV_DURATION' => :string }.freeze
- DESCENDABLE_ATTRIBUTES =
ELEMENT containers we descend into; protocol/state are skipped for now.
%w[data events items value].freeze
Instance Method Summary collapse
- #entries ⇒ Object
- #fields ⇒ Object
-
#initialize(template) ⇒ FieldExtractor
constructor
A new instance of FieldExtractor.
Constructor Details
#initialize(template) ⇒ FieldExtractor
Returns a new instance of FieldExtractor.
46 47 48 |
# File 'lib/openehr_rails/opt/field_extractor.rb', line 46 def initialize(template) @template = template end |
Instance Method Details
#entries ⇒ Object
50 51 52 |
# File 'lib/openehr_rails/opt/field_extractor.rb', line 50 def entries @entries ||= content_roots.map { |root, path| build_entry(root, path) } end |
#fields ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/openehr_rails/opt/field_extractor.rb', line 54 def fields @fields ||= begin used = {} entries.flat_map { |entry| entry[:fields] }.each do |field| field[:name] = uniquify(field[:name], used) end end end |