Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Commit 836c310

Browse files
committed
Implement eligibility check
1 parent 762942d commit 836c310

2 files changed

Lines changed: 44 additions & 3 deletions

File tree

modules/vaos/app/services/vaos/v2/unified/provider_search_service.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,13 @@ def assign_distance(provider, user_address)
141141
def filter_supported_facilities(facilities, category_of_care)
142142
return facilities if category_of_care.blank?
143143

144-
# We'll need to filter based on category of care and eligibility
144+
vaos_service_type = ServiceTypeMapper.to_vaos(category_of_care)
145+
return facilities if vaos_service_type.nil?
145146

146-
facilities
147+
facilities.select do |facility|
148+
va_stub = VAProvider.new(location_id: facility.unique_id)
149+
eligibility_service.check_eligibility(va_stub, category_of_care)[:direct_eligible]
150+
end
147151
end
148152

149153
def fetch_clinics_for_facility(facility, clinical_service)
@@ -167,6 +171,10 @@ def systems_service
167171
@systems_service ||= VAOS::V2::SystemsService.new(current_user)
168172
end
169173

174+
def eligibility_service
175+
@eligibility_service ||= EligibilityService.new(current_user)
176+
end
177+
170178
def combine_and_sort(va_providers, eps_providers, referral)
171179
referral_provider, other_eps = partition_referral_provider(eps_providers, referral)
172180

modules/vaos/spec/services/vaos/v2/unified/provider_search_service_spec.rb

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
end
6363

6464
let(:systems_service) { instance_double(VAOS::V2::SystemsService) }
65+
let(:eligibility_service) { instance_double(VAOS::V2::Unified::EligibilityService) }
6566

6667
before do
6768
allow(user).to receive(:vet360_contact_info).and_return(vet360_contact_info)
@@ -75,6 +76,8 @@
7576
allow(FacilitiesApi::V2::Lighthouse::Client).to receive(:new).and_return(lighthouse_client)
7677
allow(Eps::ProviderService).to receive(:new).and_return(eps_provider_service)
7778
allow(VAOS::V2::SystemsService).to receive(:new).with(user).and_return(systems_service)
79+
allow(VAOS::V2::Unified::EligibilityService).to receive(:new).with(user).and_return(eligibility_service)
80+
allow(eligibility_service).to receive(:check_eligibility).and_return({ direct_eligible: true })
7881

7982
allow(lighthouse_client).to receive(:get_facilities).and_return([lighthouse_facility])
8083
allow(eps_provider_service).to receive(:search_by_location).and_return([eps_provider_hash])
@@ -199,7 +202,7 @@
199202
expect(results.first.provider_type).to eq('va')
200203
end
201204

202-
it 'requests clinics for each Lighthouse facility (filter_supported_facilities is not yet applied)' do
205+
it 'includes all Lighthouse facilities when category_of_care does not map to a VAOS service (no eligibility filter)' do
203206
non_matching_facility = double(
204207
'Facility',
205208
id: 'vha_984', unique_id: '984', name: 'Other VA',
@@ -217,6 +220,36 @@
217220
expect(va_providers.size).to eq(2)
218221
expect(va_providers.map(&:location_id).sort).to eq(%w[983 984])
219222
expect(systems_service).to have_received(:get_facility_clinics).twice
223+
expect(eligibility_service).not_to have_received(:check_eligibility)
224+
end
225+
226+
it 'excludes VA facilities that fail direct-scheduling eligibility when category maps to VAOS' do
227+
non_matching_facility = double(
228+
'Facility',
229+
id: 'vha_984', unique_id: '984', name: 'Other VA',
230+
address: nil, phone: nil, lat: 28.12, long: -80.65,
231+
facility_type: 'va_health_facility',
232+
services: { 'health' => [{ 'serviceId' => 'audiology' }] }
233+
)
234+
allow(lighthouse_client).to receive(:get_facilities).and_return(
235+
[lighthouse_facility, non_matching_facility]
236+
)
237+
audio_referral = double('Referral', category_of_care: 'audiology', provider_npi: '91560381x')
238+
239+
allow(eligibility_service).to receive(:check_eligibility) do |va_provider, category_of_care_arg|
240+
expect(category_of_care_arg).to eq('audiology')
241+
{
242+
facility_id: va_provider.location_id,
243+
vaos_service_type: 'audiology',
244+
direct_eligible: va_provider.location_id == '983'
245+
}
246+
end
247+
248+
results = service.search(referral: audio_referral)
249+
250+
va_providers = results.select { |p| p.provider_type == 'va' }
251+
expect(va_providers.map(&:location_id)).to eq(['983'])
252+
expect(systems_service).to have_received(:get_facility_clinics).once
220253
end
221254

222255
it 'returns no VA providers when get_facility_clinics returns no clinics' do

0 commit comments

Comments
 (0)