Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP-5307: Add firm offices to new PDA result #7209

Merged
merged 5 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 30 additions & 26 deletions app/services/pda/compare_provider_details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ def compare_result
if match?
log_message("Provider #{@provider.id} results match.")
else
log_message("Provider #{@provider.id} #{result.firm_id} does not match firm.ccms_id #{firm.ccms_id}") unless firm_ccms_id_matches?
log_message("Provider #{@provider.id} #{result.firm_name} does not match firm.name #{firm.name}") unless firm_name_matches?
log_message("Provider #{@provider.id} #{result.firm_id} does not match firm.ccms_id #{old_firm.ccms_id}") unless firm_ccms_id_matches?
log_message("Provider #{@provider.id} \"#{result.firm_name}\" does not match firm.name \"#{old_firm.name}\"") unless firm_name_matches?
log_message("Provider #{@provider.id} #{result.contact_id} does not match provider.contact_id #{@provider.contact_id}") unless contact_id_matches?
log_message("Provider #{@provider.id} #{pda_office_details} does not match #{provider_office_details}") unless offices_match?
log_message("Provider #{@provider.id} #{new_office_details} does not match #{old_office_details}") unless offices_match?
end
end

Expand All @@ -51,44 +51,48 @@ def match?
].all?
end

def firm
@firm ||= @provider.firm
def firm_ccms_id_matches?
@firm_ccms_id_matches ||= old_firm.ccms_id.eql?(result.firm_id.to_s)
end

def provider_offices
@provider_offices ||= @provider.offices
def firm_name_matches?
@firm_name_matches ||= old_firm.name.eql?(result.firm_name)
end

def provider_office_details
@provider_office_details ||= provider_offices.map { |office| "#{office.ccms_id} #{office.code}" }.to_s
def contact_id_matches?
@contact_id_matches ||= @provider.contact_id.eql?(result.contact_id)
end

def pda_office_details
@pda_office_details ||= result.offices.map { |office| "#{office.id} #{office.code}" }.to_s
def offices_match?
sorted_new_provider_offices == sorted_old_provider_offices
end

def firm_ccms_id_matches?
@firm_ccms_id_matches ||= firm.ccms_id.eql?(result.firm_id.to_s)
def old_firm
@old_firm ||= @provider.firm
end

def firm_name_matches?
@firm_name_matches ||= firm.name.eql?(result.firm_name)
def old_office_details
@old_office_details ||= old_provider_offices.map { |office| "#{office.ccms_id} #{office.code}" }.to_s
end

def contact_id_matches?
@contact_id_matches ||= @provider.contact_id.eql?(result.contact_id)
def sorted_old_provider_offices
@sorted_old_provider_offices ||= old_provider_offices.map { |o| [o.ccms_id.to_s, o.code.to_s] }.sort
end

def offices_match?
return false if provider_offices.count != result.offices.count
def old_provider_offices
@old_provider_offices ||= @provider.offices
end

result.offices.each do |office|
provider_office = provider_offices.find_by!(ccms_id: office.id)
return false if provider_office.code != office.code
end
true
rescue ActiveRecord::RecordNotFound
false
def new_office_details
@new_office_details ||= new_provider_offices.map { |office| "#{office.id} #{office.code}" }.to_s
end

def sorted_new_provider_offices
@sorted_new_provider_offices ||= new_provider_offices.map { |o| [o.id.to_s, o.code.to_s] }.sort
end

def new_provider_offices
@new_provider_offices ||= result.firm_offices
end
end
end
2 changes: 1 addition & 1 deletion app/services/pda/provider_details_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def firm
end

def offices
provider_details.offices.map do |ccms_office|
provider_details.firm_offices.map do |ccms_office|
Office.find_or_initialize_by(ccms_id: ccms_office.id) do |office|
office.code = ccms_office.code
end
Expand Down
68 changes: 41 additions & 27 deletions app/services/pda/provider_details_retriever.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ module PDA
class ProviderDetailsRetriever
ApiError = Class.new(StandardError)
ApiRecordNotFoundError = Class.new(StandardError)
class Response
class Result
OfficeStruct = Struct.new(:id, :code)

attr_reader :firm_id,
:contact_id,
:firm_name,
:offices
:provider_offices,
:firm_offices

def initialize(json_response)
response = JSON.parse(json_response)
firm = response["firm"]
def initialize(result)
firm = result["firm"]
@firm_id = firm["ccmsFirmId"]
@firm_name = firm["firmName"]
user = response["user"]

user = result["user"]
@contact_id = user["ccmsContactId"]
@offices = response["officeCodes"].map { |office| OfficeStruct.new(id: office["ccmsProviderOfficeId"], code: office["firmOfficeCode"]) }
@provider_offices = result["officeCodes"].map { |office| OfficeStruct.new(id: office["ccmsFirmOfficeId"], code: office["firmOfficeCode"]) }
@firm_offices = result["firm_offices"].map { |office| OfficeStruct.new(id: office["ccmsFirmOfficeId"], code: office["firmOfficeCode"]) }
end
end

Expand All @@ -30,49 +32,61 @@ def self.call(username)
end

def call
body = response.body
Result.new(result)
end

raise_error unless response.status.eql?(200)
private

raise_record_not_found_error if body.empty?
def result
firm_id = provider_offices.dig("firm", "firmId")
firm_offices = provider_firm_offices(firm_id)

Response.new(body)
provider_offices.merge("firm_offices" => firm_offices["offices"])
end

private
def provider_offices
return @provider_offices if @provider_offices

response = conn.get("/provider-user/#{encoded_username}/provider-offices")
handle_errors(response)

@provider_offices = JSON.parse(response.body)
end

def provider_firm_offices(firm_id)
return @provider_firm_offices if @provider_firm_offices

response = conn.get("/provider-firms/#{firm_id}/provider-offices")
handle_errors(response)

def url
@url ||= "#{Rails.configuration.x.pda.url}/provider-user/#{encoded_uri}/provider-offices"
@provider_firm_offices = JSON.parse(response.body)
end

def encoded_uri
def encoded_username
URI.encode_www_form_component(@username).gsub("+", "%20")
end

def conn
@conn ||= Faraday.new(url: Rails.configuration.x.pda.url, headers:)
end

def headers
{
"accept" => "application/json",
"X-Authorization" => Rails.configuration.x.pda.auth_key,
}
end

def conn
@conn ||= Faraday.new(url:, headers:)
end

def response
@response ||= query_api
end

def query_api
conn.get url
def handle_errors(response)
raise_error(response) unless response.success?
raise_record_not_found_error(response) if response.body.empty?
end

def raise_error
def raise_error(response)
raise ApiError, "API Call Failed: (#{response.status}) #{response.body}"
end

def raise_record_not_found_error
def raise_record_not_found_error(response)
raise ApiRecordNotFoundError, "Retrieval Failed: (#{response.status}) #{response.body}"
end
end
Expand Down
2 changes: 1 addition & 1 deletion helm_deploy/apply-for-legal-aid/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
https://{{ .Values.ingress.host }}{{ $.Values.ingress.path }}
https://{{ .Values.deploy.host }}{{ $.Values.ingress.path }}
jsugarman marked this conversation as resolved.
Show resolved Hide resolved
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "apply-for-legal-aid.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading