generated from espoo-dev/rails_boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Feat development seeds #255
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b43a02a
Refacts apartment_multiplier BuildTotalAmountCents on EventProcedures…
mattfeg 64ad6e1
Creates feature to add seed data for development.
mattfeg 54d048b
Merge branch 'main' of github.com:espoo-dev/med_system_backend into f…
mattfeg 6253b43
Fixes update for the AmountCents of EventProcedure seed
mattfeg 813f97e
Fixes lint offenses.
mattfeg ffbe25a
Changes the output log using 'puts' to 'Rails.logger.debug'
mattfeg 183115a
Adds specs for Users and Procedures development seeds
mattfeg 0bc445e
Adds seed specs for Procedures, Patients, HealthInsurances,Hospitals,…
mattfeg 46bb652
Update README.md with new setup config
mattfeg c6e9a1f
Remove unnecessary destroy_all methods on seeds specs
mattfeg b600c4a
Fixes seeds specs to verify added data in database
mattfeg 809da0a
Adds data/procedures/*.json files to .gitignore
mattfeg e41eec5
Configs seeding for development environment
mattfeg acef5af
Update README with development commands
mattfeg be40caa
Creates load_seed subject for dev seeds specs
mattfeg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,3 +39,5 @@ | |
| # Ignore all environment files (except example). | ||
| /.env* | ||
| !.env.example | ||
|
|
||
| lib/data/procedures/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| Rails.logger.debug "1. Creating User..." | ||
|
|
||
| user = User.create!( | ||
| email: "user@email.com", | ||
| password: "qwe123", | ||
| password_confirmation: "qwe123" | ||
| ) | ||
| Rails.logger.debug { "Created User with email: #{user.email}" } | ||
| Rails.logger.debug { "User's password: #{user.password}" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| Rake::Task.clear | ||
| Rails.application.load_tasks | ||
|
|
||
| Rails.logger.debug "2. Creating default Procedures..." | ||
|
|
||
| Rake::Task["port_values_2008:import"].invoke | ||
| Rake::Task["procedures:create_json_file"].invoke("lib/data/procedures.csv", 100) | ||
|
|
||
| batch_files = Rails.root.glob("lib/data/procedures/batch_*.json") | ||
|
|
||
| if batch_files.empty? | ||
| Rails.logger.debug "No JSON files found." | ||
| else | ||
| batch_files.each do |batch_file| | ||
| next unless File.exist?(batch_file) | ||
|
|
||
| Rails.logger.debug { "Importing #{batch_file}" } | ||
|
|
||
| Rake::Task["procedures:persist_in_database"].invoke(batch_file) | ||
| Rake::Task["procedures:persist_in_database"].reenable | ||
| end | ||
| end | ||
|
|
||
| Rails.logger.debug { "Created #{batch_files.count} default Procedures!" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| Rails.logger.debug "8. Creating custom Procedure..." | ||
|
|
||
| user = User.last | ||
| procedure = Procedure.create!( | ||
| name: "Procedure A CUSTOM", | ||
| code: "123", | ||
| amount_cents: 12_345, | ||
| description: "Desc A", | ||
| custom: true, | ||
| user_id: user.id | ||
| ) | ||
| Rails.logger.debug { "Created custom Procedure: #{procedure.name} (#{procedure.code})" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| Rails.logger.debug "7. Creating custom Health Insurance..." | ||
|
|
||
| user = User.last | ||
| health_insurance = HealthInsurance.create!( | ||
| name: "Plano de saude CUSTOM", | ||
| custom: true, | ||
| user_id: user.id | ||
| ) | ||
| Rails.logger.debug { "Created custom Health Insurance: #{health_insurance.name}" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| Rails.logger.debug "5. Creating Hospital..." | ||
|
|
||
| hospital = Hospital.create!( | ||
| name: "Hospital A", | ||
| address: "A St." | ||
| ) | ||
| Rails.logger.debug { "Created Hospital: #{hospital.name}" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| Rails.logger.debug "6. Creating Patient..." | ||
|
|
||
| user = User.last | ||
| patient = Patient.create!( | ||
| name: "Paciente Usuario 1", | ||
| user_id: user.id | ||
| ) | ||
| Rails.logger.debug { "Created Patient: #{patient.name}" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| Rails.logger.debug "9. Creating Medical Shifts..." | ||
|
|
||
| date = Date.yesterday | ||
| user = User.last | ||
| hospital = Hospital.last | ||
| MedicalShift.create!( | ||
| user_id: user.id, | ||
| workload: :twelve, | ||
| start_date: date, | ||
| start_hour: Time.zone.local(date.year, date.month, date.day, 8, 0, 0), | ||
| amount_cents: 1_511_80, | ||
| payd: false, | ||
| hospital_name: hospital.name | ||
| ) | ||
|
|
||
| MedicalShift.create!( | ||
| user_id: user.id, | ||
| workload: :six, | ||
| start_date: date, | ||
| start_hour: Time.zone.local(date.year, date.month, date.day, 14, 0, 0), | ||
| amount_cents: 755_90, | ||
| payd: true, | ||
| hospital_name: hospital.name | ||
| ) | ||
|
|
||
| Rails.logger.debug { "Created Medical Shifts for user on #{date}" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| Rails.logger.debug "Creating EventProcedures..." | ||
|
|
||
| user = User.last | ||
| patient = Patient.last | ||
| hospital = Hospital.last | ||
| procedure_default = Procedure.first | ||
| procedure_custom = Procedure.last | ||
| health_insurance_default = HealthInsurance.first | ||
| health_insurance_custom = HealthInsurance.last | ||
| cbhpm = Cbhpm.last | ||
|
|
||
| event_procedure_default = EventProcedure.create!( | ||
| procedure_id: procedure_default.id, | ||
| patient_id: patient.id, | ||
| hospital_id: hospital.id, | ||
| health_insurance_id: health_insurance_default.id, | ||
| patient_service_number: "PSN12345", | ||
| date: DateTime.current + 1.day, | ||
| urgency: true, | ||
| room_type: :apartment, | ||
| user_id: user.id, | ||
| payd: true, | ||
| payment: :health_insurance, | ||
| cbhpm_id: cbhpm.id | ||
| ) | ||
|
|
||
| event_procedure_default_updated = EventProcedures::BuildTotalAmountCents.result( | ||
| event_procedure: event_procedure_default | ||
| ) | ||
| event_procedure_default.update(total_amount_cents: event_procedure_default_updated.total_amount_cents) | ||
|
|
||
| custom_event_procedures_data_unpaid = [ | ||
| { psn: "PSN67890", date: DateTime.current - 2.days, amount: 15_00 }, | ||
| { psn: "PSN67891", date: DateTime.current - 3.days, amount: 20_00 }, | ||
| { psn: "PSN67892", date: DateTime.current - 4.days, amount: 80_00 }, | ||
| { psn: "PSN67893", date: DateTime.current - 5.days, amount: 25_00 }, | ||
| { psn: "PSN67894", date: DateTime.current - 6.days, amount: 20_00 }, | ||
| { psn: "PSN67895", date: DateTime.current - 7.days, amount: 30_00 }, | ||
| { psn: "PSN67896", date: DateTime.current - 8.days, amount: 40_00 } | ||
| ] | ||
|
|
||
| custom_paid_event_procedures_data_paid = [ | ||
| { psn: "PSN67900", date: DateTime.current - 9.days, amount: 10_00 }, | ||
| { psn: "PSN67901", date: DateTime.current - 10.days, amount: 150_00 }, | ||
| { psn: "PSN67902", date: DateTime.current - 11.days, amount: 50_00 }, | ||
| { psn: "PSN67903", date: DateTime.current - 12.days, amount: 100_00 }, | ||
| { psn: "PSN67904", date: DateTime.current - 13.days, amount: 1_000_00 }, | ||
| { psn: "PSN67905", date: DateTime.current - 14.days, amount: 200_00 }, | ||
| { psn: "PSN67906", date: DateTime.current - 15.days, amount: 300_00 } | ||
| ] | ||
|
|
||
| custom_event_procedures_data_unpaid.each do |data| | ||
| EventProcedure.create!( | ||
| procedure_id: procedure_custom.id, | ||
| patient_id: patient.id, | ||
| hospital_id: hospital.id, | ||
| health_insurance_id: health_insurance_custom.id, | ||
| patient_service_number: data[:psn], | ||
| date: data[:date], | ||
| urgency: false, | ||
| room_type: :ward, | ||
| total_amount_cents: data[:amount], | ||
| user_id: user.id, | ||
| payd: false, | ||
| payment: :others, | ||
| cbhpm_id: cbhpm.id | ||
| ) | ||
| end | ||
|
|
||
| custom_paid_event_procedures_data_paid.each do |data| | ||
| EventProcedure.create!( | ||
| procedure_id: procedure_custom.id, | ||
| patient_id: patient.id, | ||
| hospital_id: hospital.id, | ||
| health_insurance_id: health_insurance_custom.id, | ||
| patient_service_number: data[:psn], | ||
| date: data[:date], | ||
| urgency: false, | ||
| room_type: :ward, | ||
| total_amount_cents: data[:amount], | ||
| user_id: user.id, | ||
| payd: true, | ||
| payment: :health_insurance, | ||
| cbhpm_id: cbhpm.id | ||
| ) | ||
| end | ||
|
|
||
| Rails.logger.debug "Created EventProcedures for user" |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "rails_helper" | ||
|
|
||
| RSpec.describe "Event Procedures seed" do | ||
| subject(:load_seed) { load seed_file } | ||
|
|
||
| let(:seed_file) { Rails.root.join("db/seeds/09_event_procedures.rb") } | ||
|
|
||
| before do | ||
| user = create(:user) | ||
| create(:patient, user: user) | ||
| create(:hospital) | ||
| create(:procedure, custom: false) | ||
| create(:procedure, custom: true, user: user) | ||
| create(:health_insurance, custom: false) | ||
| create(:health_insurance, custom: true, user: user) | ||
| create(:cbhpm) | ||
| end | ||
|
|
||
| it "runs without errors" do | ||
| expect { load_seed }.not_to raise_error | ||
| end | ||
|
|
||
| it "creates records in the database" do | ||
| expect { load_seed }.to change(EventProcedure, :count).from(0).to(15) | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "rails_helper" | ||
|
|
||
| RSpec.describe "Custom Health Insurances seed" do | ||
| subject(:load_seed) { load seed_file } | ||
|
|
||
| let(:seed_file) { Rails.root.join("db/seeds/05_health_insurances_custom.rb") } | ||
|
|
||
| before do | ||
| create(:user) | ||
| end | ||
|
|
||
| it "runs without errors" do | ||
| expect { load_seed }.not_to raise_error | ||
| end | ||
|
|
||
| it "creates records in the database" do | ||
| expect { load_seed }.to change(HealthInsurance, :count).from(0).to(1) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "rails_helper" | ||
|
|
||
| RSpec.describe "Default Health Insurances seed" do | ||
| subject(:load_seed) { load seed_file } | ||
|
|
||
| let(:seed_file) { Rails.root.join("db/seeds/04_health_insurances_default.rb") } | ||
|
|
||
| it "runs without errors" do | ||
| expect { load_seed }.not_to raise_error | ||
| end | ||
|
|
||
| it "creates records in the database" do | ||
| expect { load_seed }.to change(HealthInsurance, :count).from(0).to(9) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "rails_helper" | ||
|
|
||
| RSpec.describe "Hospitals seed" do | ||
| subject(:load_seed) { load seed_file } | ||
|
|
||
| let(:seed_file) { Rails.root.join("db/seeds/06_hospitals.rb") } | ||
|
|
||
| it "runs without errors" do | ||
| expect { load_seed }.not_to raise_error | ||
| end | ||
|
|
||
| it "creates records in the database" do | ||
| expect { load_seed }.to change(Hospital, :count).from(0).to(1) | ||
| end | ||
| end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.