Sha256: 7d2199d313ff065f615fa4fe5fe068e25601ee65bb0c1fb9236a7d3da8ecf877

Contents?: true

Size: 1.25 KB

Versions: 31

Compression:

Stored size: 1.25 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 }
          )
      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

31 entries across 31 versions & 1 rubygems

Version Path
renalware-core-2.0.130 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.129 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.128 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.127 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.126 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.125 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.124 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.123 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.121 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.120 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.119 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.118 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.117 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.116 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.115 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.113 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.112 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.111 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.110 app/models/renalware/ukrdc/pathology_observation_requests_query.rb
renalware-core-2.0.109 app/models/renalware/ukrdc/pathology_observation_requests_query.rb