Sha256: 0f5365557644d82cc7be26d657933296471f1a38da6fcce6b9953ac7eb3c330f

Contents?: true

Size: 1.31 KB

Versions: 24

Compression:

Stored size: 1.31 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])
        document.htlv = YearDatedDiagnosis.new(document_params[:htlv])
        profile.save_by(current_user)
      end

      def profile_params
        params.require(:virology_profile).permit(document: {})
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
renalware-core-2.0.78 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.77 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.76 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.75 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.74 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.73 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.72 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.71 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.70 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.69 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.68 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.67 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.64 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.63 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.62 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.61 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.60 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.58 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.57 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.56 app/controllers/renalware/virology/profiles_controller.rb