Class: Renalware::HD::DiaryPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/renalware/hd/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.



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

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.



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

def master_diary
  @master_diary
end

#null_diaryObject (readonly)

Returns the value of attribute null_diary.



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

def null_diary
  @null_diary
end

#userObject (readonly)

Returns the value of attribute user.



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

def user
  @user
end

#weekly_diaryObject (readonly)

Returns the value of attribute weekly_diary.



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

def weekly_diary
  @weekly_diary
end

Instance Method Details

#day_namesObject



55
56
57
58
# File 'app/presenters/renalware/hd/diary_presenter.rb', line 55

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



44
45
46
47
48
49
50
51
52
53
# File 'app/presenters/renalware/hd/diary_presenter.rb', line 44

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
    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) ||
           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



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

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

#each_stationObject



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

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

#station_locationsObject



68
69
70
# File 'app/presenters/renalware/hd/diary_presenter.rb', line 68

def station_locations
  StationLocation.all
end

#stationsObject



60
61
62
63
64
65
66
# File 'app/presenters/renalware/hd/diary_presenter.rb', line 60

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