Sha256: b1b3520cec68bd99ce42f7d78254f8d897f7d28d0f3366111cc9fa757a45fe74

Contents?: true

Size: 1.49 KB

Versions: 62

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/hd"

# A Diary is the schedule of HD Station/Patients assignments for one week for a particular unit.
# A Diary is split into Periods (eg. am pm eve), and each Period has a matrix of slots
# Imagine Days eg 1 to 6 on the X axis and Stations on the Y axis, and into each 'slot' we
# put a patient.
# A patient can only be in one slot in any period.
#
# Do not create instances of this class explicity, always use the STI sub classes eg MasterDiary.
module Renalware
  module HD
    class Diary < ApplicationRecord
      include Accountable

      has_many :slots, class_name: "Renalware::HD::DiarySlot"
      has_many :patients, through: :slots, class_name: "Renalware::HD::Patient"
      validates :hospital_unit_id, presence: true
      validates :master, inclusion: { in: [true, false], allow_nil: true }
      composed_of :week,
                  mapping: [%w(week_number week_number), %w(year year)],
                  constructor: lambda{ |week_number, year|
                    WeekPeriod.new(week_number: week_number, year: year)
                  }

      def self.policy_class
        DiaryPolicy
      end

      # Searchs the object graph rather than a SQL search
      def slot_for(diurnal_period_code_id, station_id, day_of_week)
        slots.find do |slot|
          slot.diurnal_period_code_id == diurnal_period_code_id &&
            slot.station_id == station_id &&
            slot.day_of_week == day_of_week
        end
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
renalware-core-2.0.77 app/models/renalware/hd/diary.rb
renalware-core-2.0.76 app/models/renalware/hd/diary.rb
renalware-core-2.0.75 app/models/renalware/hd/diary.rb
renalware-core-2.0.74 app/models/renalware/hd/diary.rb
renalware-core-2.0.73 app/models/renalware/hd/diary.rb
renalware-core-2.0.72 app/models/renalware/hd/diary.rb
renalware-core-2.0.71 app/models/renalware/hd/diary.rb
renalware-core-2.0.70 app/models/renalware/hd/diary.rb
renalware-core-2.0.69 app/models/renalware/hd/diary.rb
renalware-core-2.0.68 app/models/renalware/hd/diary.rb
renalware-core-2.0.67 app/models/renalware/hd/diary.rb
renalware-core-2.0.64 app/models/renalware/hd/diary.rb
renalware-core-2.0.63 app/models/renalware/hd/diary.rb
renalware-core-2.0.62 app/models/renalware/hd/diary.rb
renalware-core-2.0.61 app/models/renalware/hd/diary.rb
renalware-core-2.0.60 app/models/renalware/hd/diary.rb
renalware-core-2.0.58 app/models/renalware/hd/diary.rb
renalware-core-2.0.57 app/models/renalware/hd/diary.rb
renalware-core-2.0.56 app/models/renalware/hd/diary.rb
renalware-core-2.0.55 app/models/renalware/hd/diary.rb