Sha256: ce04fcbf36b04a5f4408325772a1a5e1c85b52ebbb59f7d9bae5cbfbc6bf235f

Contents?: true

Size: 1.28 KB

Versions: 18

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/pathology"

module Renalware
  module Pathology
    class NearestObservationResultsController < Pathology::BaseController
      def index
        near_date
        authorize Patient, :index?
        render json: nearest_results
      end

      private

      def code_group
        @code_group ||= CodeGroup.find(params[:code_group_id])
      end

      def observation_description_ids
        @observation_description_ids ||= code_group.memberships.pluck(:observation_description_id)
      end

      def near_date
        Date.parse(params[:date])
      end

      # rubocop:disable Metrics/MethodLength
      def nearest_results
        Pathology
          .cast_patient(Patient.find(params[:patient_id]))
          .observations
          .joins(:description)
          .where(description_id: observation_description_ids)
          .select(
            :observed_at,
            :result,
            :description_id,
            "pathology_observation_descriptions.code as code"
          )
          .map do |row|
            {
              code: row.code,
              observed_on: row.observed_at.to_date,
              result: row.result
            }
          end
      end
      # rubocop:enable Metrics/MethodLength
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/controllers/renalware/pathology/nearest_observation_results_controller.rb
renalware-core-2.1.0 app/controllers/renalware/pathology/nearest_observation_results_controller.rb
renalware-core-2.0.167 app/controllers/renalware/pathology/nearest_observation_results_controller.rb
renalware-core-2.0.166 app/controllers/renalware/pathology/nearest_observation_results_controller.rb
renalware-core-2.0.165 app/controllers/renalware/pathology/nearest_observation_results_controller.rb
renalware-core-2.0.164 app/controllers/renalware/pathology/nearest_observation_results_controller.rb
renalware-core-2.0.163 app/controllers/renalware/pathology/nearest_observation_results_controller.rb
renalware-core-2.0.162 app/controllers/renalware/pathology/nearest_observation_results_controller.rb
renalware-core-2.0.161 app/controllers/renalware/pathology/nearest_observation_results_controller.rb
renalware-core-2.0.160 app/controllers/renalware/pathology/nearest_observation_results_controller.rb
renalware-core-2.0.159 app/controllers/renalware/pathology/nearest_observation_results_controller.rb
renalware-core-2.0.158 app/controllers/renalware/pathology/nearest_observation_results_controller.rb
renalware-core-2.0.157 app/controllers/renalware/pathology/nearest_observation_results_controller.rb
renalware-core-2.0.156 app/controllers/renalware/pathology/nearest_observation_results_controller.rb
renalware-core-2.0.155 app/controllers/renalware/pathology/nearest_observation_results_controller.rb
renalware-core-2.0.153 app/controllers/renalware/pathology/nearest_observation_results_controller.rb
renalware-core-2.0.152 app/controllers/renalware/pathology/nearest_observation_results_controller.rb
renalware-core-2.0.151 app/controllers/renalware/pathology/nearest_observation_results_controller.rb