Skip to content

Commit

Permalink
Allow searching for claims by ey details
Browse files Browse the repository at this point in the history
Until the practitioner has submitted their portion of the claim EY
claims aren't easily searchable in the admin area. This commit makes
them searchable on EY provider details.
  • Loading branch information
rjlynch committed Jan 16, 2025
1 parent 8988747 commit 85a2e4e
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/models/claim/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,23 @@ def claims
Payment.where(id: search_term)
)

claims_matched_on_ey_provider_details = Claim
.joins(:early_years_payment_eligibility)
.joins("JOIN eligible_ey_providers ON eligible_ey_providers.urn = early_years_payment_eligibilities.nursery_urn")
.where(
<<~SQL, search_term: search_term
LOWER(claims.practitioner_email_address) = LOWER(:search_term)
OR LOWER(early_years_payment_eligibilities.provider_email_address) = LOWER(:search_term)
OR LOWER(eligible_ey_providers.nursery_name) = LOWER(:search_term)
OR LOWER(eligible_ey_providers.primary_key_contact_email_address) = LOWER(:search_term)
OR LOWER(eligible_ey_providers.secondary_contact_email_address) = LOWER(:search_term)
SQL
)

claim_match_query
.or(Claim.where(eligibility_id: eligibility_ids))
.or(Claim.where(id: claims_matched_on_payment_ids))
.or(Claim.where(id: claims_matched_on_ey_provider_details))
end

private
Expand Down
107 changes: 107 additions & 0 deletions spec/models/claim/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,111 @@
it { is_expected.not_to include(claim_3) }
it { is_expected.not_to include(claim_4) }
end

context "search by EY provider details" do
let!(:provider_1) do
create(
:eligible_ey_provider,
primary_key_contact_email_address: "[email protected]"
)
end

let!(:provider_2) do
create(
:eligible_ey_provider,
secondary_contact_email_address: "[email protected]"
)
end

let!(:provider_3) do
create(
:eligible_ey_provider,
nursery_name: "Test Nursery"
)
end

let!(:claim_1) do
create(
:claim,
policy: Policies::EarlyYearsPayments,
eligibility_attributes: {
nursery_urn: provider_1.urn
}
)
end

let!(:claim_2) do
create(
:claim,
policy: Policies::EarlyYearsPayments,
eligibility_attributes: {
nursery_urn: provider_2.urn
}
)
end

let!(:claim_3) do
create(
:claim,
policy: Policies::EarlyYearsPayments,
eligibility_attributes: {
nursery_urn: provider_3.urn
}
)
end

let!(:claim_4) do
create(
:claim,
policy: Policies::EarlyYearsPayments,
eligibility_attributes: {
provider_email_address: "[email protected]",
nursery_urn: create(:eligible_ey_provider).urn
}
)
end

let!(:claim_5) do
create(
:claim,
policy: Policies::EarlyYearsPayments,
practitioner_email_address: "[email protected]",
eligibility_attributes: {
nursery_urn: create(:eligible_ey_provider).urn
}
)
end

subject { search.claims }

context "when searching for a primary key contact email address" do
let(:query) { provider_1.primary_key_contact_email_address }

it { is_expected.to match_array([claim_1]) }
end

context "when searching for a secondary key contact email address" do
let(:query) { provider_2.secondary_contact_email_address }

it { is_expected.to match_array([claim_2]) }
end

context "when searching for a nursery name" do
let(:query) { provider_3.nursery_name }

it { is_expected.to match_array([claim_3]) }
end

context "when searching for a provider email address" do
let(:query) { claim_4.eligibility.provider_email_address }

it { is_expected.to match_array([claim_4]) }
end

context "when searching for a practitioner email address" do
let(:query) { claim_5.practitioner_email_address }

it { is_expected.to match_array([claim_5]) }
end
end
end

0 comments on commit 85a2e4e

Please sign in to comment.