Sha256: b0ab879e6b4f15d384998fe9e9268f9b9b37451bf0eeb6ffc14cfbe5d8309862

Contents?: true

Size: 1.49 KB

Versions: 17

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/virology"

module Renalware
  module Virology
    class ProfilesController < Virology::BaseController
      def edit
        profile = find_profile
        authorize profile
        render_edit(profile: profile)
      end

      def update
        profile = find_profile
        authorize profile
        if update_profile(profile)
          redirect_to patient_virology_dashboard_path(patient)
        else
          render_edit(profile: profile)
        end
      end

      private

      def find_profile
        patient.profile || patient.build_profile
      end

      def render_edit(profile:)
        render :edit, locals: { patient: patient, profile: profile }
      end

      def update_profile(profile)
        document_params = profile_params[:document]
        document = profile.document
        document.hiv = YearDatedDiagnosis.new(document_params[:hiv])
        document.hepatitis_b = YearDatedDiagnosis.new(document_params[:hepatitis_b])
        document.hepatitis_c = YearDatedDiagnosis.new(document_params[:hepatitis_c])
        profile.save_by(current_user)
      end

      def profile_params
        params
          .require(:virology_profile)
          .permit(attributes)
          .merge(document: document_attributes)
      end

      def attributes
        [
          document: []
        ]
      end

      def document_attributes
        params.require(:virology_profile).fetch(:document, nil).try(:permit!)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
renalware-core-2.0.39 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.38 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.37 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.36 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.35 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.34 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.33 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.32 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.31 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.30 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.28 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.27 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.26 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.25 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.24 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.23 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.22 app/controllers/renalware/virology/profiles_controller.rb