lib/fhir_models/bootstrap/preprocess.rb in fhir_models-1.8.2 vs lib/fhir_models/bootstrap/preprocess.rb in fhir_models-1.8.3

- old
+ new

@@ -9,11 +9,11 @@ json = File.open(filename, 'r:UTF-8', &:read) hash = JSON.parse(json) # Remove entries that do not interest us: CompartmentDefinitions, OperationDefinitions, Conformance statements hash['entry'].select! do |entry| - %w(StructureDefinition ValueSet CodeSystem SearchParameter).include? entry['resource']['resourceType'] + %w[StructureDefinition ValueSet CodeSystem SearchParameter].include? entry['resource']['resourceType'] end # Remove unnecessary elements from the hash hash['entry'].each do |entry| next unless entry['resource'] @@ -32,71 +32,56 @@ puts " Removed #{(start - finish) / 1024} KB" if start != finish end def self.pre_process_structuredefinition(hash) # Remove large HTML narratives and unused content - %w(text publisher contact description requirements mapping).each { |key| hash.delete(key) } + %w[text publisher contact description requirements mapping].each { |key| hash.delete(key) } - # Remove unused descriptions within the snapshot elements - if hash['snapshot'] - hash['snapshot']['element'].each do |element| - %w(short definition comments requirements alias mapping).each { |key| element.delete(key) } + # Remove unused descriptions within the snapshot and differential elements + %w[snapshot differential].each do |key| + next unless hash[key] + hash[key]['element'].each do |element| + %w[short definition comments requirements alias mapping].each { |subkey| element.delete(subkey) } end end - # Remove unused descriptions within the differential elements - if hash['differential'] - hash['differential']['element'].each do |element| - %w(short definition comments requirements alias mapping).each { |key| element.delete(key) } - end - end end def self.pre_process_valueset(hash) # Remove large HTML narratives and unused content - %w(meta text publisher contact description requirements).each { |key| hash.delete(key) } + %w[meta text publisher contact description requirements].each { |key| hash.delete(key) } - if hash['compose'] && hash['compose']['include'] - hash['compose']['include'].each do |element| + return unless hash['compose'] + %w[include exclude].each do |key| + next unless hash['compose'][key] + hash['compose'][key].each do |element| next unless element['concept'] element['concept'].each do |concept| concept.delete('designation') end end end - - if hash['compose'] && hash['compose']['exclude'] - hash['compose']['exclude'].each do |element| - next unless element['concept'] - element['concept'].each do |concept| - concept.delete('designation') - end - end - end end def self.pre_process_codesystem(hash) # Remove large HTML narratives and unused content - %w(meta text publisher contact description requirements).each { |key| hash.delete(key) } - - if hash['concept'] - hash['concept'].each do |concept| - pre_process_codesystem_concept(concept) - end + %w[meta text publisher contact description requirements].each { |key| hash.delete(key) } + return unless hash['concept'] + hash['concept'].each do |concept| + pre_process_codesystem_concept(concept) end end def self.pre_process_codesystem_concept(hash) - %w(extension definition designation).each { |key| hash.delete(key) } - if hash['concept'] - hash['concept'].each do |concept| - pre_process_codesystem_concept(concept) - end + %w[extension definition designation].each { |key| hash.delete(key) } + return unless hash['concept'] + hash['concept'].each do |concept| + pre_process_codesystem_concept(concept) end end def self.pre_process_searchparam(hash) # Remove large HTML narratives and unused content - %w(id url name date publisher contact description xpathUsage).each { |key| hash.delete(key) } + %w[id url name date publisher contact description xpathUsage].each { |key| hash.delete(key) } end def self.remove_fhir_comments(hash) hash.delete('fhir_comments') hash.each do |_key, value|