Class: Renalware::Pathology::ObservationsGroupedByDateQuery
- Inherits:
-
Object
- Object
- Renalware::Pathology::ObservationsGroupedByDateQuery
- Defined in:
- app/models/renalware/pathology/observations_grouped_by_date_query.rb
Overview
A custom relation-like object, implementing a kaminiari-like pagination interface. Its a query object but means to be used like a relation. If passed into a view you can do = paginate(relation). See ObservationsGroupedByDateTable for intended usage.
.all() returns a jsonb hash of OBX results for each day a patient had an observation. Only returns observations whose code matches observation_descriptions
Example usage:
observation_descriptions = ..
rows = ObservationsGroupedByDateQuery.new(
patient: patient,
observation_descriptions: observation_descriptions,
per_page: 50,
page: 1
)
Example output:
patient_id observation_date observations
------------------------------------------
1 2018-02-02 {"CYA": "14"}
1 2016-06-15 {"CMVDNA": "0.10"}
1 2016-03-15 {"NA": "137", "TP": "74", "ALB": "48", "ALP": "71", ...
1 2016-02-29 {"NA": "136", "TP": "78", "ALB": "47", "ALP": "71", ...
Instance Attribute Summary collapse
-
#limit ⇒ Object
(also: #limit_value)
readonly
Returns the value of attribute limit.
-
#observation_descriptions ⇒ Object
readonly
Returns the value of attribute observation_descriptions.
-
#page ⇒ Object
(also: #current_page)
readonly
Returns the value of attribute page.
-
#patient ⇒ Object
readonly
Returns the value of attribute patient.
Instance Method Summary collapse
- #all ⇒ Object
-
#initialize(patient:, observation_descriptions:, page: 1, per_page: 50) ⇒ ObservationsGroupedByDateQuery
constructor
A new instance of ObservationsGroupedByDateQuery.
- #offset ⇒ Object
- #total_pages ⇒ Object
Constructor Details
#initialize(patient:, observation_descriptions:, page: 1, per_page: 50) ⇒ ObservationsGroupedByDateQuery
Returns a new instance of ObservationsGroupedByDateQuery.
39 40 41 42 43 44 45 |
# File 'app/models/renalware/pathology/observations_grouped_by_date_query.rb', line 39 def initialize(patient:, observation_descriptions:, page: 1, per_page: 50) @patient = patient @observation_descriptions = observation_descriptions.presence || observation_descriptions_null_object @page = Integer(page) @limit = Integer(per_page) end |
Instance Attribute Details
#limit ⇒ Object (readonly) Also known as: limit_value
Returns the value of attribute limit.
35 36 37 |
# File 'app/models/renalware/pathology/observations_grouped_by_date_query.rb', line 35 def limit @limit end |
#observation_descriptions ⇒ Object (readonly)
Returns the value of attribute observation_descriptions.
35 36 37 |
# File 'app/models/renalware/pathology/observations_grouped_by_date_query.rb', line 35 def observation_descriptions @observation_descriptions end |
#page ⇒ Object (readonly) Also known as: current_page
Returns the value of attribute page.
35 36 37 |
# File 'app/models/renalware/pathology/observations_grouped_by_date_query.rb', line 35 def page @page end |
#patient ⇒ Object (readonly)
Returns the value of attribute patient.
35 36 37 |
# File 'app/models/renalware/pathology/observations_grouped_by_date_query.rb', line 35 def patient @patient end |
Instance Method Details
#all ⇒ Object
57 58 59 60 61 |
# File 'app/models/renalware/pathology/observations_grouped_by_date_query.rb', line 57 def all return Pathology::Observation.none if observation_descriptions.empty? conn.execute(to_paginated_sql) end |
#offset ⇒ Object
53 54 55 |
# File 'app/models/renalware/pathology/observations_grouped_by_date_query.rb', line 53 def offset (page - 1) * limit end |
#total_pages ⇒ Object
47 48 49 50 51 |
# File 'app/models/renalware/pathology/observations_grouped_by_date_query.rb', line 47 def total_pages result = conn.execute(to_count_sql) total = result.getvalue(0, 0) (total.to_f / limit).ceil end |