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.1.1 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.1.0 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.167 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.166 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.165 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.164 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.163 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.162 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.161 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.160 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.159 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.158 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.157 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.156 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.155 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.153 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.152 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.151 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.149 app/controllers/renalware/virology/profiles_controller.rb
renalware-core-2.0.148 app/controllers/renalware/virology/profiles_controller.rb