module FHIR::Json

Public Class Methods

from_json(json) click to toggle source
# File lib/fhir_models/bootstrap/json.rb, line 13
def self.from_json(json)
  hash = JSON.parse(json)
  resource = nil
  begin
    resource_type = hash['resourceType']
    klass = Module.const_get("FHIR::#{resource_type}")
    resource = klass.new(hash)
  rescue => e
    FHIR.logger.error("Failed to deserialize JSON:\n#{e.backtrace}")
    FHIR.logger.debug("JSON:\n#{json}")
    resource = nil
  end
  resource
end

Public Instance Methods

to_json(opts = nil) click to toggle source

This module includes methods to serialize or deserialize FHIR resources to and from JSON.

# File lib/fhir_models/bootstrap/json.rb, line 9
def to_json(opts = nil)
  JSON.pretty_generate(to_hash, opts)
end