Skip to content

Commit

Permalink
fixed claim process api
Browse files Browse the repository at this point in the history
  • Loading branch information
surabhisuman committed May 27, 2023
1 parent 0705af1 commit 983b447
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 28 deletions.
39 changes: 26 additions & 13 deletions .idea/workspace.xml

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

4 changes: 2 additions & 2 deletions app/controllers/health_care_provider_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def send_pre_auth_request

def update_docs_and_send_claim_request
claim_id = params[:claim_id]
amount = params[:claims_amount]
amount = params[:amount]
claim_type = params[:claim_type]
CentralEntityHelper.add_data_to_health_record(params[:prescriptions], params[:invoices], null, params[:person_id])
CentralEntityHelper.add_data_to_health_record(params[:prescriptions], params[:invoices], nil, params[:person_id])
resp = InsuranceHelper.send_claim_request(claim_id, amount, claim_type)
render json: resp
rescue StandardError => e
Expand Down
16 changes: 10 additions & 6 deletions app/helpers/central_entity_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ def get_eligibility(claim_amount, claim_type, customer_id)

def add_data_to_health_record(new_prescriptions, new_invoices, new_claims, customer_id)
health_report = HealthReport.find_by_person_id(customer_id)
invoices = health_report.invoices
prescriptions = health_report.prescriptions
invoices = health_report.invoices.to_a
prescriptions = health_report.prescriptions.to_a
new_invoices.each do |ninv|
invoices.add(Invoice.create(amount: ninv[:amount], health_report: health_report))
invoices << Invoice.create(amount: ninv[:amount], health_report: health_report)
end
new_prescriptions.each do |npr|
prescriptions.add(Prescription.create(medicines: npr[:medicines], lab_tests: npr[:lab_tests], health_report: health_report))
prescriptions << Prescription.create(medicines: npr[:medicines], lab_tests: npr[:lab_tests], health_report: health_report)
end
claims = health_report.claims.to_a
if new_claims
new_claims.each do |nc|
claims << nc
end
end
claims = health_report.claims
claims.add(new_claims)
health_report.update(invoices: invoices, prescriptions: prescriptions, claims: claims)
end

Expand Down
11 changes: 7 additions & 4 deletions app/helpers/insurance_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@ def send_claim_request(claim_id, amount, claim_type)
eligibility = CentralEntityHelper.get_eligibility(amount, claim_type, claim.person_id)
if eligibility[:is_eligible]
updateClaimStatus("processing", claim)
insured_policy = InsurancePolicy.find_by_id(eligibility[:eligible_policy_id])
is_fraud = false # todo: replace with gpt call
unless is_fraud
updateClaimStatus("approved", claim)
updated_coverage = insured_policy.coverage - amount
insured_policy.update(coverage: updated_coverage)
CentralEntityHelper.add_data_to_health_record([], [], [claim], claim.person_id)
# NotificationHelper.send_notification(claim.insurance_policy.)
return
NotificationHelper.send_notification(insured_policy.insurer, claim.person_id, "Claim of Rs." + (amount.to_s) +" approved")
return {"success": true, "msg": "Claim processed successfully"}
end
end
self.updateClaimStatus("rejected", claim)
# todo: create notif & notify customer
updateClaimStatus("rejected", claim)
NotificationHelper.send_notification(insured_policy.insurer, claim.person_id, "Claim of Rs." + amount +" rejected")
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/notification_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module NotificationHelper
class << self

def send_notification(requester_id, customer_id, context)
existing_notification = Notification.find_by(sender: requester_id, person_id: customer_id, title: context);
existing_notification = Notification.find_by(sender: requester_id, person_id: customer_id, title: context)
return if existing_notification
data = context + " from " + requester_id
notification = Notification.create(title: context, data: data, person_id: customer_id, sender: requester_id)
Expand Down
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ class Application < Rails::Application
# Skip views, helpers and assets when generating a new resource.
config.api_only = true
config.autoload_paths << "#{Rails.root}/app/services"
Rails.application.config.hosts << "health.abhishekm.one"
end
end
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

post '/eligibility', to: 'health_care_provider#check_eligibility'
post '/send_pre_auth_request', to: 'health_care_provider#send_pre_auth_request'
post '/update_docs_and_send_claim_request', to: 'health_care_provider#health_care_provider'
post '/health_care_provider', to: 'health_care_provider#update_docs_and_send_claim_request'
# Defines the root path route ("/")
# root "articles#index"
#
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20230527175940_add_health_report_to_claims.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddHealthReportToClaims < ActiveRecord::Migration[7.0]
def change
add_reference :claims, :health_report, index: true
end
end
4 changes: 3 additions & 1 deletion db/schema.rb

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

0 comments on commit 983b447

Please sign in to comment.