Class: OpenehrRails::EhrsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/openehr_rails/ehrs_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



11
12
13
14
15
16
# File 'app/controllers/openehr_rails/ehrs_controller.rb', line 11

def index
  @summaries = ::OpenehrRails::Rm::Ehr.order(created_at: :desc).map do |ehr|
    compositions = ::OpenehrRails::Rm::Composition.latest.where(ehr: ehr)
    EhrSummary.new(ehr, compositions.count, compositions.maximum(:context_start_time))
  end
end

#showObject



18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/openehr_rails/ehrs_controller.rb', line 18

def show
  @ehr = ::OpenehrRails::Rm::Ehr.find_by!(ehr_id: params[:id])

  scope = ::OpenehrRails::Rm::Composition.latest.where(ehr: @ehr)
  @template_ids = scope.distinct.order(:template_id).pluck(:template_id).compact
  scope = scope.where(template_id: params[:template_id]) if params[:template_id].present?

  @compositions = scope.to_a.sort_by { |c| c.context_start_time || c.created_at }.reverse
  @days = @compositions.group_by { |c| (c.context_start_time || c.created_at).to_date }
end