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.127 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.126 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.125 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.124 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.123 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.121 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.120 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.119 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.118 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.117 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.116 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.115 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.113 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.112 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.111 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.110 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.109 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.108 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.106 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.105 app/controllers/renalware/virology/profiles_controller.rb