class FHIR::STU3::Definitions
Public Class Methods
basetype(uri)
click to toggle source
Get the basetype (String) for a given profile or extension.
# File lib/fhir_stu3_models/bootstrap/definitions.rb, line 114 def self.basetype(uri) return nil if uri.nil? defn = profiles.detect { |x| x['url'] == uri } || extensions.detect { |x| x['url'] == uri } return nil if defn.nil? defn['baseType'] end
complex_types()
click to toggle source
# File lib/fhir_stu3_models/bootstrap/definitions.rb, line 38 def self.complex_types # complex data types start with an uppercase letter # and we'll filter out profiles on types (for example, Age is a profile on Quantity) @complex_types ||= types.select { |t| t['id'].start_with?(*('A'..'Z').to_a) && (t['id'] == t['snapshot']['element'].first['path']) } end
expansions()
click to toggle source
ValueSet Code Expansions
# File lib/fhir_stu3_models/bootstrap/definitions.rb, line 178 def self.expansions @@expansions ||= begin # load the expansions filename = File.join(@@defns, 'valuesets', 'expansions.json') raw = File.open(filename, 'r:UTF-8', &:read) JSON.parse(raw)['entry'].map { |e| e['resource'] } end end
extension_definition(extension_name)
click to toggle source
# File lib/fhir_stu3_models/bootstrap/definitions.rb, line 105 def self.extension_definition(extension_name) return nil if extension_name.nil? extension = extensions.find { |x| x['xmlId'] == extension_name || x['name'] == extension_name || x['url'] == extension_name } return nil if extension.nil? FHIR::STU3::StructureDefinition.new(extension) end
get_codes(uri)
click to toggle source
Get codes (Array of Strings) for a given expansion.
# File lib/fhir_stu3_models/bootstrap/definitions.rb, line 198 def self.get_codes(uri) return nil if uri.nil? return @@cache[uri] if @@cache[uri] valueset = expansions.find { |x| x['url'] == uri } || valuesets.find { |x| x['url'] == uri && x['resourceType'] == 'ValueSet' } unless valueset.nil? @@cache[uri] = {} if !valueset['expansion'].nil? && !valueset['expansion']['contains'].nil? keys = valueset['expansion']['contains'].map { |x| x['system'] }.uniq keys.each { |x| @@cache[uri][x] = [] } valueset['expansion']['contains'].each { |x| @@cache[uri][x['system']] << x['code'] } end if !valueset['compose'].nil? && !valueset['compose']['include'].nil? # for each system, if codes are included add those, otherwise lookup the codesystem in the list included_systems = [] valueset['compose']['include'].each do |code_group| system_url = code_group['system'] @@cache[uri][system_url] ||= [] code_group['concept']&.each { |y| @@cache[uri][system_url] << y['code'] } included_systems << system_url end included_systems.each { |x| @@cache[uri][x] ||= [] } systems = valuesets.select { |x| x['resourceType'] == 'CodeSystem' && included_systems.include?(x['url']) } systems.each do |included_system| included_system['concept']&.each { |y| @@cache[uri][included_system['url']] << y['code'] } end end @@cache[uri].each { |_system, codes| codes.uniq! } end @@cache[uri] end
get_display(uri, code)
click to toggle source
Get the “display” (human-readable title) for a given code in a code system (uri) If one can't be found, return nil
# File lib/fhir_stu3_models/bootstrap/definitions.rb, line 231 def self.get_display(uri, code) return nil if uri.nil? || code.nil? valuesets_and_expansions = expansions.select { |ex| ex['compose']['include'].detect { |i| i['system'] == uri } } valuesets_and_expansions += valuesets.select { |vs| vs['url'] == uri } code_hash = nil valuesets_and_expansions.each do |valueset| if valueset['expansion'] && valueset['expansion']['contains'] # This currently only matches 'expansions', not 'valuesets' code_hash = valueset['expansion']['contains'].detect { |contained| contained['system'] == uri && contained['code'] == code } elsif valueset['compose'] && valueset['compose']['include'] # This seems to only match 'valuesets' valueset['compose']['include'].each do |code_system| code_hash = code_system['concept'].detect { |con| con['code'] == code } if code_system['concept'] break if code_hash end elsif valueset['concept'] # This currently only matches 'valuesets', not 'expansions' code_hash = valueset['concept'].detect { |vs| vs['code'] == code } end break if code_hash end code_hash['display'] if code_hash end
get_profile_class(uri)
click to toggle source
Get a dynamically generated class for a given profile.
# File lib/fhir_stu3_models/bootstrap/definitions.rb, line 138 def self.get_profile_class(uri) return nil if uri.nil? load_profiles load_extensions defn = @@profiles.select { |x| x['url'] == uri }.first defn = @@extensions.select { |x| x['url'] == uri }.first if defn.nil? klass = nil unless defn.nil? generator = FHIR::STU3::Boot::Generator.new(false) type = defn['baseType'] id = defn['id'].gsub(/-|_/, '').capitalize defn['id'] = type # override profile id with baseType name for generator template = generator.generate_class([type], defn) f = Tempfile.new(["profile-#{id}", '.rb']) f.write("module FHIR\n") f.write("module Profile\n") f.write("module #{id}\n") f.write(template.to_s) 3.times { f.write("\nend") } f.close begin # load the profiled class load f # set the return class type klass = Object.const_get("FHIR::STU3::Profile::#{id}::#{type}") rescue FHIR::STU3.logger.error "Failed to generate class for profile #{uri}" end # unlink the file so it can be garbage collected f.unlink end klass end
primitive_types()
click to toggle source
# File lib/fhir_stu3_models/bootstrap/definitions.rb, line 32 def self.primitive_types # primitive data types start with a lowercase letter @primitive_types ||= types.select { |t| t['id'].start_with?(*('a'..'z').to_a) } end
profile(uri)
click to toggle source
Get the StructureDefinition
for a given profile.
# File lib/fhir_stu3_models/bootstrap/definitions.rb, line 123 def self.profile(uri) return nil if uri.nil? defn = profiles.detect { |x| x['url'] == uri } || extensions.detect { |x| x['url'] == uri } return nil if defn.nil? FHIR::STU3::StructureDefinition.new(defn) end
profiles_for_resource(resource_name)
click to toggle source
# File lib/fhir_stu3_models/bootstrap/definitions.rb, line 131 def self.profiles_for_resource(resource_name) return nil if resource_name.nil? profiles.select { |x| x['baseType'] == resource_name }.map { |x| FHIR::STU3::StructureDefinition.new(x) } end
resource_definition(resource_name)
click to toggle source
# File lib/fhir_stu3_models/bootstrap/definitions.rb, line 74 def self.resource_definition(resource_name) return nil if resource_name.nil? return @@cache[resource_name] if @@cache[resource_name] definition = resources.find { |x| x['xmlId'] == resource_name || x['name'] == resource_name || x['url'] == resource_name } @@cache[resource_name] = FHIR::STU3::StructureDefinition.new(definition) if definition @@cache[resource_name] end
resource_definitions()
click to toggle source
# File lib/fhir_stu3_models/bootstrap/definitions.rb, line 69 def self.resource_definitions resources.select { |r| r['kind'] == 'resource' } end
search_parameters(type_name)
click to toggle source
# File lib/fhir_stu3_models/bootstrap/definitions.rb, line 270 def self.search_parameters(type_name) return nil if type_name.nil? search_params.select { |p| p['base'].include?(type_name) && p['xpath'] && !p['xpath'].include?('extension') }.map { |p| p['code'] } end
type_definition(type_name)
click to toggle source
# File lib/fhir_stu3_models/bootstrap/definitions.rb, line 45 def self.type_definition(type_name) return nil if type_name.nil? return @@cache[type_name] if @@cache[type_name] definition = types.find { |x| x['xmlId'] == type_name || x['name'] == type_name || x['url'] == type_name } @@cache[type_name] = FHIR::STU3::StructureDefinition.new(definition) if definition @@cache[type_name] end
valuesets()
click to toggle source
# File lib/fhir_stu3_models/bootstrap/definitions.rb, line 188 def self.valuesets @@valuesets ||= begin # load the valuesets filename = File.join(@@defns, 'valuesets', 'valuesets.json') raw = File.open(filename, 'r:UTF-8', &:read) JSON.parse(raw)['entry'].map { |e| e['resource'] } end end
Private Class Methods
extensions()
click to toggle source
# File lib/fhir_stu3_models/bootstrap/definitions.rb, line 94 def self.extensions @@extensions ||= begin # load the built-in extensions filename = File.join(@@defns, 'structures', 'extension-definitions.json') raw = File.open(filename, 'r:UTF-8', &:read) JSON.parse(raw)['entry'].map { |e| e['resource'] } end end
profiles()
click to toggle source
# File lib/fhir_stu3_models/bootstrap/definitions.rb, line 83 def self.profiles @@profiles ||= begin # load the built-in profiles filename = File.join(@@defns, 'structures', 'profiles-others.json') raw = File.open(filename, 'r:UTF-8', &:read) JSON.parse(raw)['entry'].map { |e| e['resource'] } end end
resources()
click to toggle source
Resources, Profiles, Extensions
# File lib/fhir_stu3_models/bootstrap/definitions.rb, line 58 def self.resources @@resources ||= begin # load the resources filename = File.join(@@defns, 'structures', 'profiles-resources.json') raw = File.open(filename, 'r:UTF-8', &:read) JSON.parse(raw)['entry'].map { |e| e['resource'] } end end
search_params()
click to toggle source
Search Params
# File lib/fhir_stu3_models/bootstrap/definitions.rb, line 259 def self.search_params @@search_params ||= begin # load the search parameters filename = File.join(@@defns, 'structures', 'search-parameters.json') raw = File.open(filename, 'r:UTF-8', &:read) JSON.parse(raw)['entry'].map { |e| e['resource'] } end end
types()
click to toggle source
Types
# File lib/fhir_stu3_models/bootstrap/definitions.rb, line 21 def self.types @@types ||= begin # load the types filename = File.join(@@defns, 'structures', 'profiles-types.json') raw = File.open(filename, 'r:UTF-8', &:read) JSON.parse(raw)['entry'].map { |e| e['resource'] } end end