Module: MalawiHivProgramReports::Utils::ModelUtils
- Included in:
- ArvRefillPeriods, Clinic::TptOutcome, Clinic::ViralLoad, Clinic::VisitsReport, Cohort::Disaggregated, Cohort::Outcomes, Cohort::Regimens, Cohort::SideEffects, Moh::ArtCohort, Moh::CohortBuilder, Moh::CohortDisaggregated, Pepfar::MaternalStatus, Pepfar::TxNew, Pepfar::TxRtt, Pepfar::ViralLoadCoverage2
- Defined in:
- app/services/malawi_hiv_program_reports/utils/model_utils.rb
Instance Method Summary collapse
-
#concept(name) ⇒ Object
Retrieve concept by its name.
- #concept_id_to_name(id) ⇒ Object
- #concept_name(name) ⇒ Object
- #concept_name_to_id(name) ⇒ Object
- #drug(name) ⇒ Object
- #encounter_type(name) ⇒ Object
- #global_property(name) ⇒ Object
- #order_type(name) ⇒ Object
- #patient_identifier_type(name) ⇒ Object
- #program(name) ⇒ Object
- #report_type(name) ⇒ Object
- #user_property(name, user_id: nil) ⇒ Object
Instance Method Details
#concept(name) ⇒ Object
Retrieve concept by its name
Parameters:
name - A string repr of the concept name
11 12 13 |
# File 'app/services/malawi_hiv_program_reports/utils/model_utils.rb', line 11 def concept(name) ::Concept.joins(:concept_names).where('LOWER(concept_name.name) = ?', name.downcase).first end |
#concept_id_to_name(id) ⇒ Object
25 26 27 28 29 30 |
# File 'app/services/malawi_hiv_program_reports/utils/model_utils.rb', line 25 def concept_id_to_name(id) return nil if id.blank? concept = ::Concept.find_by_concept_id(id) concept&.fullname end |
#concept_name(name) ⇒ Object
15 16 17 |
# File 'app/services/malawi_hiv_program_reports/utils/model_utils.rb', line 15 def concept_name(name) ::ConceptName.where('LOWER(name) = ?', name.downcase).first end |
#concept_name_to_id(name) ⇒ Object
19 20 21 22 23 |
# File 'app/services/malawi_hiv_program_reports/utils/model_utils.rb', line 19 def concept_name_to_id(name) return nil if name.blank? concept_name(name)&.concept_id end |
#drug(name) ⇒ Object
61 62 63 |
# File 'app/services/malawi_hiv_program_reports/utils/model_utils.rb', line 61 def drug(name) ::Drug.where('LOWER(name) = ?', name.downcase).first end |
#encounter_type(name) ⇒ Object
36 37 38 |
# File 'app/services/malawi_hiv_program_reports/utils/model_utils.rb', line 36 def encounter_type(name) ::EncounterType.where('LOWER(name) = ?', name.downcase).first end |
#global_property(name) ⇒ Object
40 41 42 |
# File 'app/services/malawi_hiv_program_reports/utils/model_utils.rb', line 40 def global_property(name) ::GlobalProperty.where('LOWER(property) = ?', name.downcase).first end |
#order_type(name) ⇒ Object
49 50 51 |
# File 'app/services/malawi_hiv_program_reports/utils/model_utils.rb', line 49 def order_type(name) ::OrderType.where('LOWER(name) = ?', name.downcase).first end |
#patient_identifier_type(name) ⇒ Object
57 58 59 |
# File 'app/services/malawi_hiv_program_reports/utils/model_utils.rb', line 57 def patient_identifier_type(name) ::PatientIdentifierType.where('LOWER(name) = ?', name.downcase).first end |
#program(name) ⇒ Object
32 33 34 |
# File 'app/services/malawi_hiv_program_reports/utils/model_utils.rb', line 32 def program(name) ::Program.where('LOWER(name) = ?', name.downcase).first end |
#report_type(name) ⇒ Object
53 54 55 |
# File 'app/services/malawi_hiv_program_reports/utils/model_utils.rb', line 53 def report_type(name) ::ReportType.where('LOWER(name) = ?', name.downcase).first end |
#user_property(name, user_id: nil) ⇒ Object
44 45 46 47 |
# File 'app/services/malawi_hiv_program_reports/utils/model_utils.rb', line 44 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 |