Module: FHIR::ClassJson
Instance Method Summary collapse
-
#from_json(json) ⇒ Object
This module includes methods to serialize or deserialize FHIR resources to and from JSON.
Instance Method Details
#from_json(json) ⇒ Object
This module includes methods to serialize or deserialize FHIR resources to and from JSON.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fhir_models/bootstrap/json.rb', line 9 def from_json(json) hash = JSON.parse(json) resource = nil begin resource_type = hash['resourceType'] klass = versioned_fhir_module.const_get(resource_type) resource = klass.new(hash) rescue StandardError => e FHIR.logger.error("Failed to deserialize JSON:\n#{e.backtrace}") FHIR.logger.debug("JSON:\n#{json}") resource = nil end resource end |