28
28
# created_at :datetime not null
29
29
# updated_at :datetime not null
30
30
# gp_practice_id :bigint
31
- # organisation_id :bigint
32
31
# school_id :bigint
33
32
#
34
33
# Indexes
39
38
# index_patients_on_names_family_first (family_name,given_name)
40
39
# index_patients_on_names_given_first (given_name,family_name)
41
40
# index_patients_on_nhs_number (nhs_number) UNIQUE
42
- # index_patients_on_organisation_id (organisation_id)
43
41
# index_patients_on_school_id (school_id)
44
42
#
45
43
# Foreign Keys
46
44
#
47
45
# fk_rails_... (gp_practice_id => locations.id)
48
- # fk_rails_... (organisation_id => organisations.id)
49
46
# fk_rails_... (school_id => locations.id)
50
47
#
51
48
class Patient < ApplicationRecord
@@ -56,11 +53,10 @@ class Patient < ApplicationRecord
56
53
include PendingChangesConcern
57
54
include Schoolable
58
55
59
- audited associated_with : :organisation
56
+ audited
60
57
has_associated_audits
61
58
62
59
belongs_to :gp_practice , class_name : "Location" , optional : true
63
- belongs_to :organisation , optional : true
64
60
65
61
has_many :access_log_entries
66
62
has_many :consent_notifications
@@ -77,11 +73,12 @@ class Patient < ApplicationRecord
77
73
has_many :vaccination_records , -> { kept }
78
74
has_many :vaccination_statuses
79
75
80
- has_many :parents , through : :parent_relationships
81
76
has_many :gillick_assessments , through : :patient_sessions
77
+ has_many :parents , through : :parent_relationships
82
78
has_many :pre_screenings , through : :patient_sessions
83
79
has_many :session_attendances , through : :patient_sessions
84
80
has_many :sessions , through : :patient_sessions
81
+ has_many :organisations , through : :sessions
85
82
86
83
has_many :sessions_for_current_academic_year ,
87
84
-> { for_current_academic_year } ,
@@ -354,6 +351,8 @@ def invalidate!
354
351
update_column ( :invalidated_at , Time . current )
355
352
end
356
353
354
+ def not_in_organisation? = patient_sessions . empty?
355
+
357
356
def dup_for_pending_changes
358
357
dup . tap do |new_patient |
359
358
new_patient . nhs_number = nil
@@ -385,7 +384,6 @@ def self.from_consent_form(consent_form)
385
384
given_name : consent_form . given_name ,
386
385
home_educated : consent_form . home_educated ,
387
386
nhs_number : consent_form . nhs_number ,
388
- organisation : consent_form . organisation ,
389
387
preferred_family_name : consent_form . preferred_family_name ,
390
388
preferred_given_name : consent_form . preferred_given_name ,
391
389
school : consent_form . school
0 commit comments