Class: Renalware::Pathology::ObservationDescriptionsByCodeQuery
- Inherits:
-
Object
- Object
- Renalware::Pathology::ObservationDescriptionsByCodeQuery
- Defined in:
- app/models/renalware/pathology/observation_descriptions_by_code_query.rb
Instance Method Summary collapse
-
#call ⇒ Object
Executes SQL that looks like this: SELECT “pathology_observation_descriptions”.* FROM “pathology_observation_descriptions” WHERE “pathology_observation_descriptions”.“code” IN (‘HGB’, ‘MCV’, ‘MCH’,… ORDER BY CASE code WHEN ‘HGB’ THEN 0 WHEN ‘MCV’ THEN 1 WHEN ‘MCH’ THEN 2 … END and returns results that look like this: [ #<Renalware::Pathology::ObservationDescription id: 767, code: “HGB”, name: “HGB”>, #<Renalware::Pathology::ObservationDescription id: 1058, code: “MCV”, name: “MCV”>, #<Renalware::Pathology::ObservationDescription id: 1055, code: “MCH”, name: “MCH”>, … ].
-
#initialize(relation: ObservationDescription, codes:) ⇒ ObservationDescriptionsByCodeQuery
constructor
A new instance of ObservationDescriptionsByCodeQuery.
Constructor Details
#initialize(relation: ObservationDescription, codes:) ⇒ ObservationDescriptionsByCodeQuery
Returns a new instance of ObservationDescriptionsByCodeQuery.
9 10 11 12 |
# File 'app/models/renalware/pathology/observation_descriptions_by_code_query.rb', line 9 def initialize(relation: ObservationDescription, codes:) @relation = relation @codes = Array(codes) end |
Instance Method Details
#call ⇒ Object
Executes SQL that looks like this:
SELECT "pathology_observation_descriptions".* FROM "pathology_observation_descriptions"
WHERE "pathology_observation_descriptions"."code" IN ('HGB', 'MCV', 'MCH',...
ORDER BY CASE code
WHEN 'HGB' THEN 0
WHEN 'MCV' THEN 1
WHEN 'MCH' THEN 2
...
END
and returns results that look like this:
[
#<Renalware::Pathology::ObservationDescription id: 767, code: "HGB", name: "HGB">,
#<Renalware::Pathology::ObservationDescription id: 1058, code: "MCV", name: "MCV">,
#<Renalware::Pathology::ObservationDescription id: 1055, code: "MCH", name: "MCH">,
...
]
30 31 32 33 34 35 |
# File 'app/models/renalware/pathology/observation_descriptions_by_code_query.rb', line 30 def call stmt = SQL::IndexedCaseStmt.new(:code, @codes) # Generate a CASE statement for ordering records = @relation.where(code: @codes).order(stmt.generate) verify_all_records_found(records) records end |