Skip to content

Commit

Permalink
BE | Ask va api Fix Inquiry bug and create FacilitiesDataJob (#19976)
Browse files Browse the repository at this point in the history
* Created get_facilities_mock_data.json and update static_data.json

- get_facilties_mock_data.json is a list of PATSR approved health facilities
- static_data.json is now up to data with the most recent addition from CRM API

* Fix bug in InquiryDetails and update spec

- inquiry_details now handles `it's a general question` correctly

* Created FacilitiesDataJob

- Job will run every 24hours to cache the data

* Update HealthFacilities#search

- search now will filter and allow only patsr approved facilities
  • Loading branch information
Khoa-V-Nguyen authored Dec 20, 2024
1 parent 064a5bb commit 69d29cc
Show file tree
Hide file tree
Showing 12 changed files with 1,993 additions and 2,482 deletions.
3 changes: 3 additions & 0 deletions lib/periodic_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
# Update Optionset data cache
mgr.register('0 0 * * *', 'Crm::OptionsetDataJob')

# Update Facilities data cache
mgr.register('0 0 * * *', 'Crm::FacilitiesDataJob')

# Update FormSubmissionAttempt status from Lighthouse Benefits Intake API
mgr.register('0 0 * * *', 'BenefitsIntakeStatusJob')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@ def search
api_result.tmp_covid_online_scheduling = mobile_api_get_by_id(api_result.id)
end
end
render_json(serializer, lighthouse_params, api_results)

patsr_approved_codes = retrieve_patsr_approved_facilities.pluck(:FacilityCode)

filtered_results = WillPaginate::Collection.create(
api_results.current_page,
api_results.per_page,
api_results.total_entries
) do |pager|
filtered_items = api_results.select { |object| patsr_approved_codes.include?(object.unique_id) }
pager.replace(filtered_items)
pager.total_entries = filtered_items.size
end

render_json(serializer, lighthouse_params, filtered_results)
end

def show
Expand All @@ -28,6 +41,11 @@ def show

private

def retrieve_patsr_approved_facilities
data = Crm::CacheData.new.fetch_and_cache_data(endpoint: 'Facilities', cache_key: 'Facilities', payload: {})
JSON.parse(data, symbolize_names: true)[:Data]
end

def api
FacilitiesApi::V2::Lighthouse::Client.new
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def call
inquiry_details = base_inquiry_details(inquiry_params[:your_role])

if education_benefits?(inquiry_params[:select_category],
inquiry_params[:select_topic])
inquiry_params[:select_topic]) ||
inquiry_params[:who_is_your_question_about] == "It's a general question"
return general_inquiry(inquiry_params, inquiry_details)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def fetch_state(state_code)
def formatted_pronouns(pronouns)
return unless pronouns

pronouns[:pronouns_not_listed_text].presence || pronouns.key(true)&.to_s&.tr('_', '/')
pronouns[:pronouns_not_listed_text].presence || pronouns.key('true')&.to_s&.tr('_', '/')
end

def contact_field(field, inquiry_details, inquiry_params)
Expand Down
28 changes: 28 additions & 0 deletions modules/ask_va_api/app/sidekiq/crm/facilities_data_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

require 'sidekiq'

module Crm
class FacilitiesDataJob
include Sidekiq::Job

# Schedule to run every 24 hours. Adjust as needed.
sidekiq_options retry: false, unique_for: 24.hours

def perform
Crm::CacheData.new.fetch_and_cache_data(endpoint: 'Facilities', cache_key: 'Facilities', payload: {})
rescue => e
log_error('optionset', e)
end

private

def log_error(action, exception)
LogService.new.call(action) do |span|
span.set_tag('error', true)
span.set_tag('error.msg', exception.message)
end
Rails.logger.error("Error during #{action}: #{exception.message}")
end
end
end
177 changes: 177 additions & 0 deletions modules/ask_va_api/config/locales/get_facilities_mock_data.json

Large diffs are not rendered by default.

Loading

0 comments on commit 69d29cc

Please sign in to comment.