Sha256: 93e3c66fe567bf0c5716d0d0e7f2e17822fa0eb363f49ab712e528fadc5e7c55

Contents?: true

Size: 628 Bytes

Versions: 7

Compression:

Stored size: 628 Bytes

Contents

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

    def to_json
      JSON.pretty_unparse(to_hash)
    end

    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
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fhir_models-4.0.1 lib/fhir_models/bootstrap/json.rb
fhir_models-4.0.0 lib/fhir_models/bootstrap/json.rb
fhir_models-3.0.4 lib/fhir_models/bootstrap/json.rb
fhir_models-3.0.3 lib/fhir_models/bootstrap/json.rb
fhir_models-3.0.2 lib/fhir_models/bootstrap/json.rb
fhir_models-3.0.1 lib/fhir_models/bootstrap/json.rb
fhir_models-1.8.3 lib/fhir_models/bootstrap/json.rb