lib/generate_models.rb in cqm-models-3.0.0 vs lib/generate_models.rb in cqm-models-3.0.1
- old
+ new
@@ -73,15 +73,17 @@
puts Dir.entries('.')
# Open specified modelinfo file
modelinfo_file = ARGV[0]
raise 'Please provide a valid modelinfo file path and name.' if modelinfo_file.blank? || !File.file?(modelinfo_file)
+
modelinfo = File.open(modelinfo_file) { |f| Nokogiri::XML(f) }
# Open specified HQMF oid file
oids_file = ARGV[1]
raise 'Please provide a valid HQMF oid file path and name.' if oids_file.blank? || !File.file?(oids_file)
+
oids = JSON.parse(File.read(oids_file))
# If this script was run with a third parameter of 'TEST', then generate the models in a
# not standard location. This helps with testing.
IS_TEST = (ARGV[2] == 'TEST')
@@ -138,13 +140,11 @@
attributes << { name: 'qdmStatus', type: 'System.String', default: extra_info['qdm_status'] } if extra_info['qdm_status'].present?
hqmfOid_to_datatype_map[extra_info['hqmf_oid']] = datatype_name if extra_info['hqmf_oid'].present?
end
# Add the qdmVersion attribute unless the base type is one that will provide it
- unless ['QDM.Entity', 'QDM.Component'].include? type['baseType']
- attributes << { name: 'qdmVersion', type: 'System.String', default: qdm_version }
- end
+ attributes << { name: 'qdmVersion', type: 'System.String', default: qdm_version } unless ['QDM.Entity', 'QDM.Component'].include? type['baseType']
datatypes[datatype_name] = { attributes: attributes }
end
###############################################################################
@@ -307,13 +307,11 @@
end
# Inject Ruby Patient model extensions
GeneratorHelpers.inject_extension('templates/patient_extension.rb.erb', ruby_models_path + 'patient.rb')
# Inject Ruby Entity model extensions
-if datatypes['Entity']
- GeneratorHelpers.inject_extension('templates/entity_extension.rb.erb', ruby_models_path + 'entity.rb')
-end
+GeneratorHelpers.inject_extension('templates/entity_extension.rb.erb', ruby_models_path + 'entity.rb') if datatypes['Entity']
# Make sure Ruby models are in the correct module
ruby_models_path = 'app/models/qdm/'
ruby_models_path = 'app/models/test/qdm/' if IS_TEST
Dir.glob(ruby_models_path + '*.rb').each do |file_name|
@@ -339,9 +337,10 @@
contents.gsub!(/ include Mongoid::Document\n/, " include Mongoid::Document\n embedded_in :data_element\n")
File.open(file_name, 'w') { |file| file.puts contents }
end
# TODO: Might be able to make this list by finding baseType="System.Any" in model info file instead of hard-coding.
next if types_not_inherited_by_data_element.any? { |sub_string| sub_string.include?(File.basename(file_name)) }
+
contents.gsub!(/ include Mongoid::Document\n/, " include Mongoid::Document\n embedded_in :patient\n")
File.open(file_name, 'w') { |file| file.puts contents }
end
# Make sure Ruby datatypes models have the correct inheritance