Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Rails 7 and mongoid 8 #217

Merged
merged 9 commits into from
Mar 7, 2024
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,3 @@ jobs:
run: |
./bin/validate_dist.sh
./bin/validate_browser.sh
./bin/validate_generator.sh
4 changes: 2 additions & 2 deletions app/models/cqm/individual_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class IndividualResult
field :state, type: String, default: 'queued'

# Relations to other model classes
belongs_to :measure
belongs_to :patient
belongs_to :measure, class_name: 'CQM::Measure', inverse_of: :calculation_result
belongs_to :patient, class_name: 'CQM::Patient', inverse_of: :calculation_result

# Convert the stored array into a hash between clause and result
def clause_results_by_clause
Expand Down
2 changes: 1 addition & 1 deletion app/models/cqm/measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Measure
# hence the 'inverse_of: nil')
has_and_belongs_to_many :value_sets, inverse_of: nil

has_many :calculation_results, class_name: 'CQM::IndividualResult'
has_many :calculation_results, class_name: 'CQM::IndividualResult', inverse_of: :measure

def all_stratifications
population_sets.flat_map(&:stratifications)
Expand Down
2 changes: 1 addition & 1 deletion app/models/cqm/patient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Patient

has_and_belongs_to_many :providers, class_name: 'CQM::Provider'
embeds_one :qdmPatient, class_name: 'QDM::Patient', autobuild: true
has_many :calculation_results, class_name: 'CQM::IndividualResult'
has_many :calculation_results, class_name: 'CQM::IndividualResult', inverse_of: :patient

# Include '_type' in any JSON output. This is necessary for deserialization.
def to_json(options = nil)
Expand Down
2 changes: 0 additions & 2 deletions app/models/cqm/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class Provider
field :specialty, type: String
field :title, type: String

validates_uniqueness_of :npi, allow_blank: true

embeds_many :addresses
embeds_many :telecoms
embeds_many :ids, class_name: 'QDM::Identifier'
Expand Down
2 changes: 2 additions & 0 deletions app/models/qdm/attributes/identifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ class Identifier < Attribute
field :namingSystem, type: String
field :value, type: String
field :qdmVersion, type: String, default: '5.6'

validates_uniqueness_of :value, conditions: -> { where(namingSystem: CQM::Provider::NPI_OID) }
end
end
4 changes: 3 additions & 1 deletion app/models/qdm/basetypes/data_element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def shift_dates(seconds)
elsif field == 'facilityLocation'
facility_location = send(field)
unless facility_location.nil?
shift_facility_location_dates(facility_location, seconds)
# Guessing something changed in mongoid such that facility_location gets typed to an Object
# but this method (I think) expects a Hash.
shift_facility_location_dates(facility_location.attributes, seconds)
send(field + '=', facility_location)
end
end
Expand Down
9 changes: 5 additions & 4 deletions cqm-models.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Gem::Specification.new do |spec|
spec.name = 'cqm-models'
spec.version = '4.1.2'
spec.version = '4.2.0'
spec.authors = ['aholmes@mitre.org', 'mokeefe@mitre.org', 'lades@mitre.org']

spec.summary = 'Mongo models that correspond to the QDM specification.'
Expand All @@ -22,10 +22,11 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'bundle-audit'
spec.add_development_dependency 'byebug', '~> 11.0.1'
spec.add_development_dependency 'codecov'
spec.add_development_dependency 'mongoid', '~> 6.4'
spec.add_development_dependency 'rails', '~> 5.2'
spec.add_development_dependency 'mongoid', '~> 8'
spec.add_development_dependency 'nokogiri', '>= 1.16.2'
spec.add_development_dependency 'rails', '~> 7.1'
spec.add_development_dependency 'rake', '~> 12.3.3'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rubocop', '~> 0.54.0'
spec.add_development_dependency 'rubocop', '~> 0.63.0'
spec.add_development_dependency 'simplecov'
end
10 changes: 5 additions & 5 deletions spec/cqm/models_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@
expect(@patient_de1.qdmPatient.diagnostic_studies.first.relevantPeriod.high.utc.to_s).to include('07:00:00')

# DiatnosticStudyPerformed facilityLocation high and low should be two hours ahead
expect(@patient_de1.qdmPatient.diagnostic_studies.first.facilityLocation['locationPeriod'][:low].utc.to_s).to include('06:00:00')
expect(@patient_de1.qdmPatient.diagnostic_studies.first.facilityLocation['locationPeriod'][:high].utc.to_s).to include('07:00:00')
expect(@patient_de1.qdmPatient.diagnostic_studies.first.facilityLocation.locationPeriod.low.utc.to_s).to include('06:00:00')
expect(@patient_de1.qdmPatient.diagnostic_studies.first.facilityLocation.locationPeriod.high.utc.to_s).to include('07:00:00')
end

it 'shift patient data elements backwards in time' do
Expand Down Expand Up @@ -198,8 +198,8 @@
expect(@patient_de2.qdmPatient.diagnostic_studies.first.relevantPeriod.high.utc.to_s).to include('03:00:00')

# DiatnosticStudyPerformed facilityLocation high and low should be two hours behind
expect(@patient_de2.qdmPatient.diagnostic_studies.first.facilityLocation['locationPeriod'][:low].utc.to_s).to include('02:00:00')
expect(@patient_de2.qdmPatient.diagnostic_studies.first.facilityLocation['locationPeriod'][:high].utc.to_s).to include('03:00:00')
expect(@patient_de2.qdmPatient.diagnostic_studies.first.facilityLocation.locationPeriod.low.utc.to_s).to include('02:00:00')
expect(@patient_de2.qdmPatient.diagnostic_studies.first.facilityLocation.locationPeriod.high.utc.to_s).to include('03:00:00')
end

it 'relatedTo properly links data elements' do
Expand All @@ -216,7 +216,7 @@
it 'entity datatype can be saved correctly' do
puts @patient_c.qdmPatient.dataElements[3].participant.first['identifier']
@patient_c.save
expect(@patient_c.qdmPatient.dataElements[3].participant.first['specialty'][:code]).to eq 'foo code 2'
expect(@patient_c.qdmPatient.dataElements[3].participant.first['specialty'].code).to eq 'foo code 2'
expect(@patient_c.qdmPatient.dataElements[3].participant.first['identifier']['value']).to eq 'foo value'
end

Expand Down
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

Mongoid.load!('config/mongoid.yml', :test)

# Seems new version of mongoid (and/or Mongo) doesn't default to UTC.
Time.zone = 'UTC'

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = '.rspec_status'
Expand Down
Loading