Sha256: 5cb94265a248a354e74ab8f2e40a1c2cb7aeffab537631e165d3b5c5169156a4

Contents?: true

Size: 1.71 KB

Versions: 44

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

# This module contains utility methods for retrieving models
module MalawiHivProgramReports
  module Utils
    module ModelUtils
      # Retrieve concept by its name
      #
      # Parameters:
      #  name - A string repr of the concept name
      def concept(name)
        ::Concept.joins(:concept_names).where('LOWER(concept_name.name) = ?', name.downcase).first
      end

      def concept_name(name)
        ::ConceptName.where('LOWER(name) = ?', name.downcase).first
      end

      def concept_name_to_id(name)
        return nil if name.blank?

        concept_name(name)&.concept_id
      end

      def concept_id_to_name(id)
        return nil if id.blank?

        concept = ::Concept.find_by_concept_id(id)
        concept&.fullname
      end

      def program(name)
        ::Program.where('LOWER(name) = ?', name.downcase).first
      end

      def encounter_type(name)
        ::EncounterType.where('LOWER(name) = ?', name.downcase).first
      end

      def global_property(name)
        ::GlobalProperty.where('LOWER(property) = ?', name.downcase).first
      end

      def user_property(name, user_id: nil)
        user_id ||= ::User.current.user_id
        ::UserProperty.where('user_id = ? AND LOWER(property) = ?', user_id, name).first
      end

      def order_type(name)
        ::OrderType.where('LOWER(name) = ?', name.downcase).first
      end

      def report_type(name)
        ::ReportType.where('LOWER(name) = ?', name.downcase).first
      end

      def patient_identifier_type(name)
        ::PatientIdentifierType.where('LOWER(name) = ?', name.downcase).first
      end

      def drug(name)
        ::Drug.where('LOWER(name) = ?', name.downcase).first
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
malawi_hiv_program_reports-1.1.18 app/services/malawi_hiv_program_reports/utils/model_utils.rb
malawi_hiv_program_reports-1.1.17 app/services/malawi_hiv_program_reports/utils/model_utils.rb
malawi_hiv_program_reports-1.1.16 app/services/malawi_hiv_program_reports/utils/model_utils.rb
malawi_hiv_program_reports-1.1.15 app/services/malawi_hiv_program_reports/utils/model_utils.rb
malawi_hiv_program_reports-1.1.14 app/services/malawi_hiv_program_reports/utils/model_utils.rb
malawi_hiv_program_reports-1.1.13 app/services/malawi_hiv_program_reports/utils/model_utils.rb
malawi_hiv_program_reports-1.1.12 app/services/malawi_hiv_program_reports/utils/model_utils.rb
malawi_hiv_program_reports-1.1.11 app/services/malawi_hiv_program_reports/utils/model_utils.rb
malawi_hiv_program_reports-1.1.10 app/services/malawi_hiv_program_reports/utils/model_utils.rb
malawi_hiv_program_reports-1.1.9 app/services/malawi_hiv_program_reports/utils/model_utils.rb
malawi_hiv_program_reports-1.1.8 app/services/malawi_hiv_program_reports/utils/model_utils.rb
malawi_hiv_program_reports-1.1.7 app/services/malawi_hiv_program_reports/utils/model_utils.rb
malawi_hiv_program_reports-1.1.6 app/services/malawi_hiv_program_reports/utils/model_utils.rb
malawi_hiv_program_reports-1.1.5 app/services/malawi_hiv_program_reports/utils/model_utils.rb
malawi_hiv_program_reports-1.1.4 app/services/malawi_hiv_program_reports/utils/model_utils.rb
malawi_hiv_program_reports-1.1.3 app/services/malawi_hiv_program_reports/utils/model_utils.rb
malawi_hiv_program_reports-1.1.2 app/services/malawi_hiv_program_reports/utils/model_utils.rb
malawi_hiv_program_reports-1.1.1 app/services/malawi_hiv_program_reports/utils/model_utils.rb
malawi_hiv_program_reports-1.1.0 app/services/malawi_hiv_program_reports/utils/model_utils.rb
malawi_hiv_program_reports-1.0.27 app/services/malawi_hiv_program_reports/utils/model_utils.rb