Sha256: e72aaa30b0cdf497cc828877369710aa1c0f7c014b1786660b40c418d12d425b

Contents?: true

Size: 1.35 KB

Versions: 17

Compression:

Stored size: 1.35 KB

Contents

require_dependency "renalware/pathology"

module Renalware
  module Pathology
    class ViewCurrentObservationResults
      def initialize(patient, presenter, descriptions: default_descriptions)
        @patient = patient
        @descriptions = descriptions
        @presenter = presenter
      end

      def call(_params = {})
        # Get an array of observations for the requested descriptions
        results = find_current_observations_for_descriptions
        # Although we now have all the observations, they are not in the right order.
        # Hence this sort by description code.
        sorted_results = sort_results(results)
        present(sorted_results)
      end

      private

      def find_current_observations_for_descriptions
        CurrentObservationsForDescriptionsQuery
          .new(patient: @patient, descriptions: @descriptions)
          .call
      end

      def sort_results(results)
        @descriptions.map { |description| find_result_for_description(results, description) }
                     .compact
      end

      def find_result_for_description(results, description)
        results.detect { |result| result.description_code == description.code }
      end

      def present(results)
        @presenter.present(results)
      end

      def default_descriptions
        RelevantObservationDescription.all
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.rc9 app/models/renalware/pathology/view_current_observation_results.rb.dead
renalware-core-2.0.0.pre.rc8 app/models/renalware/pathology/view_current_observation_results.rb
renalware-core-2.0.0.pre.rc7 app/models/renalware/pathology/view_current_observation_results.rb
renalware-core-2.0.0.pre.rc6 app/models/renalware/pathology/view_current_observation_results.rb
renalware-core-2.0.0.pre.rc5 app/models/renalware/pathology/view_current_observation_results.rb
renalware-core-2.0.0.pre.rc4 app/models/renalware/pathology/view_current_observation_results.rb
renalware-core-2.0.0.pre.rc3 app/models/renalware/pathology/view_current_observation_results.rb
renalware-core-2.0.0.pre.rc1 app/models/renalware/pathology/view_current_observation_results.rb
renalware-core-2.0.0.pre.beta12 app/models/renalware/pathology/view_current_observation_results.rb
renalware-core-2.0.0.pre.beta11 app/models/renalware/pathology/view_current_observation_results.rb
renalware-core-2.0.0.pre.beta10 app/models/renalware/pathology/view_current_observation_results.rb
renalware-core-2.0.0.pre.beta9 app/models/renalware/pathology/view_current_observation_results.rb
renalware-core-2.0.0.pre.beta8 app/models/renalware/pathology/view_current_observation_results.rb
renalware-core-2.0.0.pre.beta7 app/models/renalware/pathology/view_current_observation_results.rb
renalware-core-2.0.0.pre.beta6 app/models/renalware/pathology/view_current_observation_results.rb
renalware-core-2.0.0.pre.beta5 app/models/renalware/pathology/view_current_observation_results.rb
renalware-core-2.0.0.pre.beta4 app/models/renalware/pathology/view_current_observation_results.rb