We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fcee053 commit f92ecf1Copy full SHA for f92ecf1
1 file changed
app/policies/vaccination_record_policy.rb
@@ -67,28 +67,16 @@ def resolve
67
team = user.selected_team
68
return scope.none if team.nil?
69
70
- patient_subquery =
+ relevant_patients =
71
Patient
72
+ .select("1")
73
.joins(patient_sessions: :session)
- .select(:id)
74
- .distinct
+ .where("patients.id = vaccination_records.patient_id")
75
.where(sessions: { team_id: team.id })
76
.arel
77
- .as("patients")
78
scope
79
- .joins(
80
- VaccinationRecord
81
- .arel_table
82
- .join(patient_subquery, Arel::Nodes::OuterJoin)
83
- .on(
84
- VaccinationRecord.arel_table[:patient_id].eq(
85
- patient_subquery[:id]
86
- )
87
88
- .join_sources
89
90
.kept
91
- .where(patient_subquery[:id].not_eq(nil))
+ .where(relevant_patients.exists)
92
.or(scope.kept.where(session: team.sessions))
93
.or(
94
scope.kept.where(
0 commit comments