Sha256: 9e2d93d60163a655ade0a0779d4c2c5c7faa46a250f66bb392ae71955f78b617
Contents?: true
Size: 1.23 KB
Versions: 9
Compression:
Stored size: 1.23 KB
Contents
# frozen_string_literal: true module Renalware module HD class GenerateMonthlyStatisticsForPatient def initialize(patient:, period:) @patient = patient @period = period end def call options = { patient: patient, period: period } sessions = Sessions::AuditablePatientSessionsInPeriodQuery.new(**options).call create_patient_statistics(sessions) end private attr_reader :period, :patient def create_patient_statistics(sessions) return unless sessions.any? stats = build_patient_statistics stats.hospital_unit = most_recently_used_hospital_unit(sessions) stats.assign_attributes(auditable_sessions(sessions).to_h) stats.session_count = sessions.length stats.save! end def build_patient_statistics PatientStatistics.where( patient: patient, month: period.month, year: period.year, rolling: nil ).first_or_initialize end def auditable_sessions(sessions) Sessions::AuditableSessionCollection.new(sessions) end def most_recently_used_hospital_unit(sessions) sessions.last&.hospital_unit end end end end
Version data entries
9 entries across 9 versions & 1 rubygems