Sha256: e901effe6f5c2cad9fe600f99528c10a2567b86ff60113bf89cd8998197036b7

Contents?: true

Size: 735 Bytes

Versions: 9

Compression:

Stored size: 735 Bytes

Contents

module FHIR
  module DSTU2
    module Json
      #
      #  This module includes methods to serialize or deserialize FHIR::DSTU2 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::DSTU2::#{resource_type}")
          resource = klass.new(hash)
        rescue => e
          FHIR::DSTU2.logger.error("Failed to deserialize JSON:\n#{e.message}\n#{e.backtrace}")
          FHIR::DSTU2.logger.debug("JSON:\n#{json}")
          resource = nil
        end
        resource
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
fhir_dstu2_models-1.0.10 lib/fhir_dstu2_models/bootstrap/json.rb
fhir_dstu2_models-1.0.9 lib/fhir_dstu2_models/bootstrap/json.rb
fhir_dstu2_models-1.0.8 lib/fhir_dstu2_models/bootstrap/json.rb
fhir_dstu2_models-1.0.7 lib/fhir_dstu2_models/bootstrap/json.rb
fhir_dstu2_models-1.0.6 lib/fhir_dstu2_models/bootstrap/json.rb
fhir_dstu2_models-1.0.5 lib/fhir_dstu2_models/bootstrap/json.rb
fhir_dstu2_models-1.0.4 lib/fhir_dstu2_models/bootstrap/json.rb
fhir_dstu2_models-1.0.3 lib/fhir_dstu2_models/bootstrap/json.rb
fhir_dstu2_models-1.0.2 lib/fhir_dstu2_models/bootstrap/json.rb