Sha256: b3a903beebb7b7e8805f8cd0a9934a2440fca058b1145b8c74fbf2718344aa3e

Contents?: true

Size: 1.45 KB

Versions: 86

Compression:

Stored size: 1.45 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 = profile.document
        document.hiv = year_date_diagnosis_for(:hiv)
        document.hepatitis_b = year_date_diagnosis_for(:hepatitis_b)
        document.hepatitis_b_core_antibody = year_date_diagnosis_for(:hepatitis_b_core_antibody)
        document.hepatitis_c = year_date_diagnosis_for(:hepatitis_c)
        document.htlv = year_date_diagnosis_for(:htlv)
        profile.save_by(current_user)
      end

      def year_date_diagnosis_for(condition)
        document_params = profile_params[:document]
        YearDatedDiagnosis.new(document_params[condition])
      end

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

Version data entries

86 entries across 86 versions & 1 rubygems

Version Path
renalware-core-2.0.147 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.146 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.145 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.144 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.143 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.142 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.141 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.140 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.139 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.138 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.137 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.136 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.135 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.134 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.133 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.132 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.131 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.130 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.129 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.128 app/controllers/renalware/virology/profiles_controller.rb