# frozen_string_literal: true

require_dependency "renalware/patients"
require "attr_extras"

module Renalware
  module Patients
    class ClearPatientUKRDCData
      pattr_initialize [:patient!, :by!]

      def self.call(**args)
        new(**args).call
      end

      def call
        patient.send_to_rpv = false
        patient.rpv_decision_on = Time.zone.today
        patient.rpv_recorded_by = by.to_s
        patient.save_by!(by)
      end
    end
  end
end

# frozen_string_literal: true

require_dependency "renalware/patients"
require "attr_extras"

module Renalware
  module Patients
    class ClearPatientUKRDCData
      pattr_initialize [:patient!, :by!]

      def self.call(**args)
        new(**args).call
      end

      def call
        patient.send_to_rpv = false
        patient.rpv_decision_on = Time.zone.today
        patient.rpv_recorded_by = by.to_s
        patient.skip_death_validations = true
        patient.save_by!(by)
      end
    end
  end
end

Fix bug clearing UKRDC data when patient dies
Fix bug clearing UKRDC data when patient dies

When a patient dies the patient model enters a state where no
further changes can be made to it unless you set the date_of_death
and death causes. However this validation can be overriden by setting
the virtual accessor Patient#skip_death_validations = true.

This commit adds this to ClearPatientUKRDCData to prevent it
raising a validation error when it attempts to save
the patient.
