Class: Renalware::HD::Scheduling::DiaryPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/renalware/hd/scheduling/diary_presenter.rb

Constant Summary collapse

NullDiary =
Naught.build do |config|
  config.black_hole
  config.define_explicit_conversions
  config.predicates_return false

  def master?
    false
  end

  def slot_for(diary_id, diurnal_period_code_id, station_id, day_of_week)
    NullSlot.new(diary_id, diurnal_period_code_id, station_id, day_of_week)
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, weekly_diary) ⇒ DiaryPresenter

Returns a new instance of DiaryPresenter.



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

def initialize(user, weekly_diary)
  @user = user
  @weekly_diary = weekly_diary
  @master_diary = weekly_diary.master_diary
  @null_diary = NullDiary.new
end

Instance Attribute Details

#master_diaryObject (readonly)

Returns the value of attribute master_diary.



10
11
12
# File 'app/presenters/renalware/hd/scheduling/diary_presenter.rb', line 10

def master_diary
  @master_diary
end

#null_diaryObject (readonly)

Returns the value of attribute null_diary.



10
11
12
# File 'app/presenters/renalware/hd/scheduling/diary_presenter.rb', line 10

def null_diary
  @null_diary
end

#userObject (readonly)

Returns the value of attribute user.



10
11
12
# File 'app/presenters/renalware/hd/scheduling/diary_presenter.rb', line 10

def user
  @user
end

#weekly_diaryObject (readonly)

Returns the value of attribute weekly_diary.



10
11
12
# File 'app/presenters/renalware/hd/scheduling/diary_presenter.rb', line 10

def weekly_diary
  @weekly_diary
end

Instance Method Details

#day_namesObject

rubocop:enable Layout/LineLength



59
60
61
62
# File 'app/presenters/renalware/hd/scheduling/diary_presenter.rb', line 59

def day_names
  all_day_names = Time::DAYS_INTO_WEEK.keys
  all_day_names.take(last_day_of_week)
end

#each_day(diurnal_period, station) ⇒ Object

rubocop:disable Layout/LineLength



46
47
48
49
50
51
52
53
54
55
56
# File 'app/presenters/renalware/hd/scheduling/diary_presenter.rb', line 46

def each_day(diurnal_period, station)
  (1..last_day_of_week).each do |day_of_week|
    diurnal_period_id = diurnal_period.id
    station_id = station.id
    valid_from = weekly_diary.week.date_on_first_day_of_week
    slot = weekly_diary.slot_for(diurnal_period_id, station_id, day_of_week) ||
           master_diary.slot_for(diurnal_period_id, station_id, day_of_week, valid_from: valid_from) ||
           null_diary.slot_for(weekly_diary.id, diurnal_period_id, station_id, day_of_week)
    yield(slot) if block_given?
  end
end

#each_diurnal_periodObject



35
36
37
38
39
# File 'app/presenters/renalware/hd/scheduling/diary_presenter.rb', line 35

def each_diurnal_period
  DiurnalPeriodCode.all.each do |diurnal_period_code|
    yield(diurnal_period_code) if block_given?
  end
end

#each_stationObject



41
42
43
# File 'app/presenters/renalware/hd/scheduling/diary_presenter.rb', line 41

def each_station
  stations.each_with_index { |station, index| yield(station, index + 1) if block_given? }
end

#station_locationsObject



72
73
74
# File 'app/presenters/renalware/hd/scheduling/diary_presenter.rb', line 72

def station_locations
  StationLocation.all
end

#stationsObject



64
65
66
67
68
69
70
# File 'app/presenters/renalware/hd/scheduling/diary_presenter.rb', line 64

def stations
  @stations ||= begin
    Station.includes(:location).for_unit(hospital_unit_id).ordered.map do |station|
      StationPresenter.new(station)
    end
  end
end