Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Not proud of, but we are using this as a place to run scripts,
# since we can't run rake tasks or access console on render free version

# Rails.logger.debug "Seeding default data..."
# Rails.logger.debug "Seeding data..."
# Dir[Rails.root.join("db/seeds/*.rb")].each do |seed|
# load seed
# end
Expand Down
11 changes: 11 additions & 0 deletions db/seeds/01_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

$stdout.puts "1. Creating User..."

user = User.create!(
email: "user@email.com",
password: "qwe123",
password_confirmation: "qwe123"
)
$stdout.puts "Created User with email: #{user.email}"
$stdout.puts "User's password: #{user.password}"
26 changes: 26 additions & 0 deletions db/seeds/02_procedures_default.rb
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

$stdout.puts "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?
$stdout.puts "No JSON files found."
else
batch_files.each do |batch_file|
next unless File.exist?(batch_file)

$stdout.puts "Importing #{batch_file}"

Rake::Task["procedures:persist_in_database"].invoke(batch_file)
Rake::Task["procedures:persist_in_database"].reenable
end
end

$stdout.puts "Created default Procedures!"
14 changes: 14 additions & 0 deletions db/seeds/03_procedures_custom.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

$stdout.puts "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
)
$stdout.puts "Created custom Procedure: #{procedure.name} (#{procedure.code})"
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

$stdout.puts "4. Creating default Health Insurances..."

health_insurance_data = [
"São Camilo",
"ISSEC",
Expand All @@ -15,3 +17,5 @@
health_insurance_data.each do |name|
HealthInsurance.create!(name: name)
end

$stdout.puts "Created #{health_insurance_data.count} default Health Insurances..."
11 changes: 11 additions & 0 deletions db/seeds/05_health_insurances_custom.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

$stdout.puts "7. Creating custom Health Insurance..."

user = User.last
health_insurance = HealthInsurance.create!(
name: "Plano de saude CUSTOM",
custom: true,
user_id: user.id
)
$stdout.puts "Created custom Health Insurance: #{health_insurance.name}"
9 changes: 9 additions & 0 deletions db/seeds/06_hospitals.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

$stdout.puts "5. Creating Hospital..."

hospital = Hospital.create!(
name: "Hospital A",
address: "A St."
)
$stdout.puts "Created Hospital: #{hospital.name}"
10 changes: 10 additions & 0 deletions db/seeds/07_patients.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

$stdout.puts "6. Creating Patient..."

user = User.last
patient = Patient.create!(
name: "Paciente Usuario 1",
user_id: user.id
)
$stdout.puts "Created Patient: #{patient.name}"
28 changes: 28 additions & 0 deletions db/seeds/08_medical_shifts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

$stdout.puts "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
)

$stdout.puts "Created Medical Shifts for user on #{date}"
50 changes: 50 additions & 0 deletions db/seeds/09_event_procedures.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

$stdout.puts "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: false,
room_type: :ward,
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)

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: "PSN67890",
date: DateTime.current + 2.days,
urgency: true,
room_type: :apartment,
total_amount_cents: 15_000,
user_id: user.id,
payd: false,
payment: :others,
cbhpm_id: cbhpm.id
)

$stdout.puts "Created EventProcedures for user"
45 changes: 0 additions & 45 deletions db/seeds/procedures.rb

This file was deleted.