Sha256: f6b762068d5ec339aa1fc1c5066151db3a9aeceb88c67008d49b206c756fb6cc
Contents?: true
Size: 1.5 KB
Versions: 23
Compression:
Stored size: 1.5 KB
Contents
require_dependency "renalware/transplants" require_dependency "renalware/success" require_dependency "renalware/failure" # Service object responsible for creating a new DonorStage and terminated the previous one # if found. module Renalware module Transplants class CreateDonorStage def initialize(patient:, options: {}) @patient = patient @options = options end def call DonorStage.transaction do terminate_current_stage if current_stage.present? stage = build_new_stage if stage.save ::Renalware::Success.new(stage) else ::Renalware::Failure.new(stage) end end end private attr_reader :patient, :options def current_stage @current_stage ||= DonorStage.for_patient(patient).current.first end def terminate_current_stage current_stage.terminated_on = started_on_for_new_stage current_stage.by = by current_stage.save! @current_stage = nil end def build_new_stage DonorStage.new( patient: patient, started_on: started_on_for_new_stage, stage_position_id: options.fetch(:stage_position_id), stage_status_id: options.fetch(:stage_status_id), notes: options.fetch(:notes), by: by ) end def by options.fetch(:by) end def started_on_for_new_stage options.fetch(:started_on) end end end end
Version data entries
23 entries across 23 versions & 1 rubygems