Sha256: b58f2bb5f7b61e2f7434b40a8d2fa4d8165b5b5956913a2ad59e87e4a68ac421

Contents?: true

Size: 710 Bytes

Versions: 2

Compression:

Stored size: 710 Bytes

Contents

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fhir_stu3_models-3.0.1 lib/fhir_stu3_models/bootstrap/json.rb
fhir_stu3_models-3.0.0 lib/fhir_stu3_models/bootstrap/json.rb