Sha256: b2cef1a4d0b9320c099fe3e9cd29a5e999095db7e034dc0520e20bacafd2c3fc

Contents?: true

Size: 1.29 KB

Versions: 39

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/ukrdc"
require "attr_extras"
require "benchmark"

module Renalware
  module UKRDC
    module TreatmentTimeline
      # Re-generates the ukrdc_treatments table
      class GenerateTreatments
        def self.call
          new.call
        end

        def call
          elapsed_ms = Benchmark.ms do
            generate_treatments
          end
          log("\nCreated #{UKRDC::Treatment.count} UKRDC Treatments in #{elapsed_ms / 1000.0}s")
        end

        private

        def patient_scope
          Renalware::Patient
            .select(:id)
            .where("send_to_renalreg = true or send_to_rpv = true")
        end

        # rubocop:disable Rails/Output, Metrics/AbcSize
        def generate_treatments
          PrepareTables.call
          Rails.logger.info "#{patient_scope.count} patients"
          patient_scope.find_each.with_index do |patient, index|
            print "\n#{patient.id}: "
            GenerateTimeline.new(patient).call
            # Start gargbage collection periodically to prevent server ram issues.
            GC.start if (index % 50).zero?
          end
        end
        # rubocop:enable Rails/Output, Metrics/AbcSize

        def log(msg)
          Rails.logger.info(msg)
        end
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

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