Sha256: a6d4657f64310d1da5aaebc4b9e785df872a182a7d78ca2b8d48e9c605097239

Contents?: true

Size: 1.06 KB

Versions: 28

Compression:

Stored size: 1.06 KB

Contents

module Renalware
  module PD
    class SavePeritonitisEpisode
      include Wisper::Publisher

      def initialize(patient:, episode:)
        @patient = patient
        @episode = episode
      end

      def call(params:)
        success = save_episode(episode, params)
        success ? broadcast(:save_success, episode) : broadcast(:save_failure, episode)
        success
      end

      private

      attr_reader :patient, :episode

      def episodes
        patient.peritonitis_episodes
      end

      def save_episode(episode, params)
        PeritonitisEpisode.transaction do
          episode.assign_attributes(params.except(:episode_types))
          episode.save && save_episode_types(episode.episode_types, params)
        end
      end

      def save_episode_types(episode_types, params)
        episode_type_desc_ids = params.fetch(:episode_types, [])
        episode_types.destroy_all
        episode_type_desc_ids.each do |desc_id|
          episode_types.create!(peritonitis_episode_type_description_id: desc_id)
        end
        true
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
renalware-core-2.0.8 app/models/renalware/pd/save_peritonitis_episode.rb
renalware-core-2.0.7 app/models/renalware/pd/save_peritonitis_episode.rb
renalware-core-2.0.5 app/models/renalware/pd/save_peritonitis_episode.rb
renalware-core-2.0.4 app/models/renalware/pd/save_peritonitis_episode.rb
renalware-core-2.0.3 app/models/renalware/pd/save_peritonitis_episode.rb
renalware-core-2.0.2 app/models/renalware/pd/save_peritonitis_episode.rb
renalware-core-2.0.1 app/models/renalware/pd/save_peritonitis_episode.rb
renalware-core-2.0.0 app/models/renalware/pd/save_peritonitis_episode.rb
renalware-core-2.0.0.pre.rc13 app/models/renalware/pd/save_peritonitis_episode.rb
renalware-core-2.0.0.pre.rc11 app/models/renalware/pd/save_peritonitis_episode.rb
renalware-core-2.0.0.pre.rc10 app/models/renalware/pd/save_peritonitis_episode.rb
renalware-core-2.0.0.pre.rc9 app/models/renalware/pd/save_peritonitis_episode.rb
renalware-core-2.0.0.pre.rc8 app/models/renalware/pd/save_peritonitis_episode.rb
renalware-core-2.0.0.pre.rc7 app/models/renalware/pd/save_peritonitis_episode.rb
renalware-core-2.0.0.pre.rc6 app/models/renalware/pd/save_peritonitis_episode.rb
renalware-core-2.0.0.pre.rc5 app/models/renalware/pd/save_peritonitis_episode.rb
renalware-core-2.0.0.pre.rc4 app/models/renalware/pd/save_peritonitis_episode.rb
renalware-core-2.0.0.pre.rc3 app/models/renalware/pd/save_peritonitis_episode.rb
renalware-core-2.0.0.pre.rc1 app/models/renalware/pd/save_peritonitis_episode.rb
renalware-core-2.0.0.pre.beta12 app/models/renalware/pd/save_peritonitis_episode.rb