Class: FacilitiesQuery::Base
- Inherits:
-
Object
- Object
- FacilitiesQuery::Base
- Defined in:
- app/models/facilities_query/base.rb
Direct Known Subclasses
BoundingBoxQuery, IdsQuery, RadialQuery, StateQuery, ZipQuery
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #get_facility_data(conditions, type, facility_type, services, additional_data = nil) ⇒ Object
- #ids_for_types(ids) ⇒ Object
-
#initialize(params) ⇒ Base
constructor
A new instance of Base.
-
#run ⇒ Object
This is the default response.
- #service_condition(type, service) ⇒ Object
Constructor Details
#initialize(params) ⇒ Base
Returns a new instance of Base.
7 8 9 |
# File 'app/models/facilities_query/base.rb', line 7 def initialize(params) @params = params end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
5 6 7 |
# File 'app/models/facilities_query/base.rb', line 5 def params @params end |
Instance Method Details
#get_facility_data(conditions, type, facility_type, services, additional_data = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/facilities_query/base.rb', line 16 def get_facility_data(conditions, type, facility_type, services, additional_data = nil) klass = BaseFacility::TYPE_MAP[facility_type].constantize return klass.none unless type.blank? || type == facility_type klass = klass.select(additional_data) if additional_data facilities = klass.where(conditions) service_conditions = services&.map do |service| service_condition(type, service) end facilities = facilities.where(service_conditions.join(' OR ')) if service_conditions&.any? facilities.where.not(facility_type: BaseFacility::DOD_HEALTH) end |
#ids_for_types(ids) ⇒ Object
38 39 40 41 42 43 |
# File 'app/models/facilities_query/base.rb', line 38 def ids_for_types(ids) ids.split(',').each_with_object(Hash.new { |h, k| h[k] = [] }) do |type_id, obj| facility_type, unique_id = type_id.split('_') obj[facility_type].push unique_id if facility_type && unique_id end end |
#run ⇒ Object
This is the default response. It is overriden in the child classes
12 13 14 |
# File 'app/models/facilities_query/base.rb', line 12 def run BaseFacility.none end |
#service_condition(type, service) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'app/models/facilities_query/base.rb', line 29 def service_condition(type, service) case type when 'benefits' "services->'benefits'->'standard' @> '[\"#{service}\"]'" when 'health' "services->'health' @> '[{\"sl1\":[\"#{service}\"]}]'" end end |