Class: Renalware::HD::Scheduling::DiaryRange

Inherits:
Object
  • Object
show all
Defined in:
app/models/renalware/hd/scheduling/diary_range.rb

Overview

Represents a range of WeekPeriods and their diaries for a hospital unit

Instance Method Summary collapse

Instance Method Details

#create_missing_weekly_diaries(by:) ⇒ Object

If there are any missing weekly diaries in the date range, create them



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/renalware/hd/scheduling/diary_range.rb', line 14

def create_missing_weekly_diaries(by:)
  week_periods_in_range.each do |period|
    WeeklyDiary.find_or_create_by!(
      hospital_unit_id: unit.id,
      week_number: period.week_number,
      year: period.year
    ) do |diary|
      log_weekly_diary_creation(period)
      diary.master_diary = master_diary_for(unit, by)
      diary.by = by
    end
  end
end

#from_dateObject



35
36
37
# File 'app/models/renalware/hd/scheduling/diary_range.rb', line 35

def from_date
  from_week_period.date_on_first_day_of_week
end

#log_weekly_diary_creation(period) ⇒ Object



28
29
30
31
32
33
# File 'app/models/renalware/hd/scheduling/diary_range.rb', line 28

def log_weekly_diary_creation(period)
  Rails.logger.debug(
    "DEBUG: Creating weekly diary for unit #{unit.id} period "\
    "#{period.week_number}/#{period.year}"
  )
end

#to_dateObject



39
40
41
# File 'app/models/renalware/hd/scheduling/diary_range.rb', line 39

def to_date
  to_week_period.date_on_first_day_of_week
end