lib/health-data-standards/import/bundle/importer.rb in health-data-standards-3.6.1 vs lib/health-data-standards/import/bundle/importer.rb in health-data-standards-3.7.0

- old
+ new

@@ -60,25 +60,32 @@ unpack_and_store_valuesets(zip_file, bundle) unpack_and_store_results(zip_file, options[:type], measure_ids, bundle) unless options[:exclude_results] end - bundle + return bundle + ensure + # If the bundle is nil or the bundle has never been saved then do not set done_importing or run save. + if bundle && bundle.created_at + bundle.done_importing = true + bundle.save + end end # Save a javascript function into Mongo's system.js collection for measure execution. # # @param [String] name The name by which the function will be referred. # @param [String] fn The body of the function being saved. def self.save_system_js_fn(name, fn) fn = "function () {\n #{fn} \n }" - Mongoid.default_session['system.js'].find('_id' => name).upsert( - { - "_id" => name, - "value" => BSON::Code.new(fn) - } + Mongoid.default_client['system.js'].replace_one({ + "_id" => name}, + { + "_id" => name, + "value" => BSON::Code.new(fn) + },{upsert: true} ) end # A utility function for finding files in a bundle. Strip a file path of it's extension and just give the filename. # @@ -108,18 +115,18 @@ source_measure = unpack_json(entry) # we clone so that we have a source without a bundle id measure = source_measure.clone measure_ids << measure['id'] measure['bundle_id'] = bundle.id - Mongoid.default_session["measures"].insert(measure) + Mongoid.default_client["measures"].insert_one(measure) if update_measures - Mongoid.default_session["measures"].where({hqmf_id: measure["hqmf_id"], sub_id: measure["sub_id"]}).each do |m| + Mongoid.default_client["measures"].find({hqmf_id: measure["hqmf_id"], sub_id: measure["sub_id"]}).each do |m| b = HealthDataStandards::CQM::Bundle.find(m["bundle_id"]) if b.version < bundle.version m.merge!(source_measure) - Mongoid.default_session["measures"].where({"_id" => m["_id"]}).update(m) + Mongoid.default_client["measures"].update_one({"_id" => m["_id"]},m) end end end report_progress('measures', (index*100/entries.length)) if index%10 == 0 end @@ -173,18 +180,18 @@ end end def self.compare_dates(entry, start_date, end_date) if entry.start_time * 1000 == start_date - if entry.end_time == nil + if entry.end_time == nil if end_date == nil return true - else + else return false end else entry.end_time * 1000 == end_date - return true + return true end end return false end @@ -203,11 +210,11 @@ def self.unpack_and_store_valuesets(zip, bundle) entries = zip.glob(SOURCE_ROOTS[:valuesets]) entries.each_with_index do |entry, index| vs = HealthDataStandards::SVS::ValueSet.new(unpack_json(entry)) vs['bundle_id'] = bundle.id - HealthDataStandards::SVS::ValueSet.collection.insert(vs.as_document) + HealthDataStandards::SVS::ValueSet.collection.insert_one(vs.as_document) report_progress('Value Sets', (index*100/entries.length)) if index%10 == 0 end puts "\rLoading: Value Sets Complete " end @@ -231,10 +238,10 @@ if patient = Record.by_patient_id(medical_record_id).first document['value']['patient_id'] = patient.id end end document['bundle_id'] = bundle.id - Mongoid.default_session[collection].insert(document) + Mongoid.default_client[collection].insert_one(document) end end puts "\rLoading: Results Complete " end