Sha256: 9cfce9aeea45add7b285661b74624a6e35cfbfb5ce3661b15f92c3a3c3a5abc1
Contents?: true
Size: 1.17 KB
Versions: 4
Compression:
Stored size: 1.17 KB
Contents
module Renalware module HD class UpdateRollingPatientStatistics < ApplicationJob def initialize(patient:) @patient = patient end def call return unless recent_sessions.any? stats = rolling_stats_for_this_patient stats.hospital_unit = most_recently_used_hospital_unit stats.assign_attributes(auditable_sessions.to_h) stats.session_count = recent_sessions.count stats.save! end private attr_reader :patient def recent_sessions @recent_sessions ||= Sessions::LatestPatientSessionsQuery.new(patient: patient).call end def auditable_sessions @auditable_sessions ||= Sessions::AuditableSessionCollection.new(recent_sessions) end def rolling_stats_for_this_patient @patient_rolling_stats ||= begin PatientStatistics.where(patient: patient, rolling: true, year: nil, month: nil).first_or_initialize end end def most_recently_used_hospital_unit recent_sessions.last.hospital_unit end end end end
Version data entries
4 entries across 4 versions & 1 rubygems