Class: OpenEHR::Serializer::RMJSONSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/openehr/serializer/rm_json_serializer.rb

Overview

Canonical JSON for an RM instance graph: a generic reflection walker (not a hand-written serializer per RM class), tagging each object with a "_type" discriminator (via OpenEHR::RM.type_name_of) and recursing into every non-nil instance variable except @parent (PATHABLE's back-reference, which would otherwise make every subtree cyclic). A defensive visited-object guard covers any other unexpected back-reference.

Constant Summary collapse

EXCLUDED_IVARS =

Instance variables that value=-style setters derive and cache from a single canonical attribute (e.g. value), but which are not part of openEHR ITS-JSON canonical form and have no corresponding OpenEHR::RM::Factory::Factory to reconstruct them on read - see docs/design/fix-rmjson-roundtrip-plan.md for the full inventory and how each was found (DvDate/DvTime/DvDateTime's value= in lib/openehr/rm/data_types/quantity/date_time.rb; UIDBasedID/ ObjectVersionID's value= in lib/openehr/rm/support/identification.rb).

[
  :@parent,
  :@year, :@month, :@day,                      # DvDate, DvDateTime
  :@hour, :@minute, :@second, :@fractional_second, # DvTime, DvDateTime
  :@timezone,                                  # DvTime (String), DvDateTime (Timezone)
  :@root, :@extension,                         # UIDBasedID, HierObjectID, ObjectVersionID
  :@oid, :@creating_system_id, :@version_tree_id, # ObjectVersionID
  :@rm_originator, :@rm_name, :@rm_entity,     # ArchetypeID
  :@concept_name, :@specialisation, :@version_id, # ArchetypeID, TerminologyID
  :@name                                       # TerminologyID
].freeze
ARCHETYPE_ID_IVARS =
[
  :@rm_originator, :@rm_name, :@rm_entity,
  :@concept_name, :@specialisation, :@version_id
].freeze
TERMINOLOGY_ID_IVARS =
[:@name, :@version_id].freeze
IDENTIFIER_IVARS =
(ARCHETYPE_ID_IVARS + TERMINOLOGY_ID_IVARS).uniq.freeze

Instance Method Summary collapse

Constructor Details

#initialize(rm_instance) ⇒ RMJSONSerializer

Returns a new instance of RMJSONSerializer.



40
41
42
# File 'lib/openehr/serializer/rm_json_serializer.rb', line 40

def initialize(rm_instance)
  @rm_instance = rm_instance
end

Instance Method Details

#serializeObject



44
45
46
# File 'lib/openehr/serializer/rm_json_serializer.rb', line 44

def serialize
  JSON.generate(to_value(@rm_instance, Set.new.compare_by_identity))
end