Sha256: 3e9ce1d10c75b0e0f6b42f052c9f75f00d08bf5c4a76d5a8ad4c825fa7981139

Contents?: true

Size: 1.29 KB

Versions: 27

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/ukrdc"
require "attr_extras"

module Renalware
  module UKRDC
    class PathologyObservationRequestsQuery
      pattr_initialize [:patient_id!, :changes_since!]

      def call
        observation_requests
      end

      private

      def observation_requests
        Pathology::ObservationRequest
          .where(id: Pathology::ObservationRequest.distinct_for_patient_id(patient_id))
          .where("requested_at >= ?", effective_changes_since)
          .where("loinc_code is not null")
          .eager_load(
            :description,
            observations: { description: :measurement_unit }
          )
          .order(observed_at: :asc)
      end

      # If there is a pathology_start_date configured in an ENV var, use this
      # for fetching pathology. This allows us to send a one-off batch of patients
      # with historical pathology. Most of the time this setting is not present, and
      # default to using changes_since.
      def effective_changes_since
        configured_pathology_start_date || changes_since
      end

      def configured_pathology_start_date
        start_date = Renalware.config.ukrdc_pathology_start_date
        return if start_date.blank?

        Date.parse(start_date)
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
renalware-core-2.0.159 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.158 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.157 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.156 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.155 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.153 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.152 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.151 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.149 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.148 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.147 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.146 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.145 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.144 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.143 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.142 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.141 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.140 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.139 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.138 app/models/renalware/ukrdc/pathology_observation_requests_query.rb