1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
def create_account
Account.create!({
name: Faker::Name.name,
address: Faker::Address.street_address,
birth_date: Faker::Date.birthday(min_age: 18, max_age: 65)
})
end
def random_physician
if Physician.any? && Time.now.to_i.even?
return Physician.order(Arel.sql('RANDOM()')).first
end
Physician.create!({
account: create_account,
hired_at: 1.month.ago,
qualifications: ['heart', 'brain']
})
end
def create_patient
Patient.create!(
account: create_account,
physician: random_physician,
referring_physician: random_physician,
contacted_at: Faker::Date.between(from: 6.months.ago, to: 1.hour.ago)
)
end
def random_patient
return Patient.order(Arel.sql('RANDOM()')).first if Patient.any? && Time.now.to_i.odd?
create_patient
end
def random_count
rand(100)
end
ApplicationRecord.transaction do
[
{ name: 'Intensive Care Unit', location: 'MT-M' },
{ name: 'Pshychiatry', location: 'FMC-2' },
{ name: 'Adult Outpatient Mental Health', location: 'SSB-2' },
{ name: 'Child & Adolescent Pshyciatry', location: 'SSB-2' },
{ name: 'Burns', location: 'FMC-3' },
{ name: 'Surgery - Head & Neck / Plastics', location: 'FMC-3' },
{ name: 'Acute Medicine', location: 'FMC-3' },
{ name: 'Medicine', location: 'SSB-3' },
{ name: 'Renal', location: 'SSB-3' },
{ name: 'Solid Organ Transplant', location: 'SSB-3' },
{ name: 'Ante Partum', location: 'FMC-4' },
{ name: 'Surgery - Short Stay', location: 'FMC-4' },
{ name: 'Gynecology / Gyne-Oncology', location: 'FMC-4' },
{ name: 'Trauma', location: 'MT-4' },
{ name: 'Medicine', location: 'SSB-4' },
{ name: 'Acute Medicine / Aphersis', location: 'SSB-4' },
{ name: 'Labour & Delivery', location: 'FMC-5' },
{ name: 'Post Partum', location: 'FMC-5' },
{ name: 'Orthopedics', location: 'MT-5' },
{ name: 'Neonatal Intensive Care Unit (NICU)', location: 'FMC-5' },
{ name: 'Hematology / Oncology / BMT', location: 'SSB-5' },
{ name: 'Hematology / BMT / Day Medicine', location: 'SSB-5' },
{ name: 'Neuro Rehab', location: 'SSB-5' },
{ name: 'Thoracic Surgery / Pulmonary Medicine', location: 'SSB-6' },
{ name: 'Medicine', location: 'FMC-6' },
{ name: 'Orthopedics', location: 'MT-6' },
{ name: 'Transition', location: 'FMC-7' },
].each do |attributes|
nurse = Nurse.create!({ account: create_account, hired_at: 1.year.ago, qualifications: ['medicine'] })
care_centre = CareCentre.create!(attributes.merge(nurse_in_charge: nurse))
Bed.create!(random_count.times.map { |n| { care_centre: care_centre, room_number: n.to_s } })
end
random_count.times do
create_patient
end
random_count.times do
patient = random_patient
Treatment.create!(
patient: patient,
name: Faker::FunnyName.name,
number: SecureRandom.uuid,
occurred_at: Faker::Date.between(from: patient.contacted_at, to: 1.hour.ago),
results: Faker::Lorem.paragraphs,
)
end
end
CareCentre.find_each do |centre|
puts centre.name
puts "-" * 10
puts "Nurse: #{centre&.nurse_in_charge&.name}"
puts "Beds: #{centre.beds.count}"
puts "Beds Available: #{centre.beds.available.count}"
end
|