Sha256: 014e01bbdfd5b76998753210321c51ac891c3abdfa282e9cbf5e0b768e35e3d1

Contents?: true

Size: 1.32 KB

Versions: 8

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/surveys"

module Renalware
  module Surveys
    class POSSComponent < ApplicationComponent
      include ToggleHelper

      attr_reader :patient

      def initialize(patient:)
        @patient = patient
      end

      # Backed by a SQL view
      def rows
        @rows ||= POSSPivotedResponse.where(patient_id: patient.id)
      end

      def question_labels
        @question_labels ||= begin
          survey
            .questions
            .order(:position)
            .select(:code, :label, :label_abbrv)
            .each_with_object({}) { |q, hash| hash[q.code] = q.admin_label }
        end
      end

      # Return data for charting
      def data_for_question_code(_code)
        Renalware::Surveys::Response
          .where(patient_id: patient.id, question_id: 1)
          .pluck(:answered_on, :value)
          .to_h
      end

      def column_headings
        @column_headings ||= begin
          headings = ["Date"]

          headings.concat(
            Renalware::Survey
            .find_by!(code: "prom")
            .questions
            .order(:position)
            .pluck(:label)
          )
          headings
        end
      end

      def survey
        @survey ||= Renalware::Surveys::Survey.find_by!(code: "prom")
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
renalware-core-2.0.159 app/components/renalware/surveys/pos_s_component.rb
renalware-core-2.0.158 app/components/renalware/surveys/pos_s_component.rb
renalware-core-2.0.157 app/components/renalware/surveys/pos_s_component.rb
renalware-core-2.0.156 app/components/renalware/surveys/pos_s_component.rb
renalware-core-2.0.155 app/components/renalware/surveys/pos_s_component.rb
renalware-core-2.0.153 app/components/renalware/surveys/pos_s_component.rb
renalware-core-2.0.152 app/components/renalware/surveys/pos_s_component.rb
renalware-core-2.0.151 app/components/renalware/surveys/pos_s_component.rb