Skip to content

Commit

Permalink
added pre auth and claim request apis
Browse files Browse the repository at this point in the history
  • Loading branch information
Surabhi Suman authored and Surabhi Suman committed May 27, 2023
1 parent cafd380 commit 0a7aad5
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 13 deletions.
9 changes: 6 additions & 3 deletions .idea/workspace.xml

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

51 changes: 51 additions & 0 deletions app/controllers/consents_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
class ConsentsController < ApplicationController
before_action :set_consent, only: %i[ show update destroy ]

# GET /consents
def index
@consents = Consent.all

render json: @consents
end

# GET /consents/1
def show
render json: @consent
end

# POST /consents
def create
@consent = Consent.new(consent_params)

if @consent.save
render json: @consent, status: :created, location: @consent
else
render json: @consent.errors, status: :unprocessable_entity
end
end

# PATCH/PUT /consents/1
def update
if @consent.update(consent_params)
render json: @consent
else
render json: @consent.errors, status: :unprocessable_entity
end
end

# DELETE /consents/1
def destroy
@consent.destroy
end

private
# Use callbacks to share common setup or constraints between actions.
def set_consent
@consent = Consent.find(params[:id])
end

# Only allow a list of trusted parameters through.
def consent_params
params.fetch(:consent, {})
end
end
7 changes: 6 additions & 1 deletion app/controllers/health_care_provider_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ def check_eligibility

def send_pre_auth_request
amount = params[:amount].to_i
claim_type = params["claim_type"].to_s
requester_id = params["requester_id"]
health_id = params[:health_id].to_s
customer = Person.find_by_health_id(health_id)
InsuranceHelper.process_pre_auth(amount, claim_type, requester_id, customer.id)
end

def send_claim_request

InsuranceHelper.send_claim_request(params)
end

end
4 changes: 2 additions & 2 deletions app/helpers/central_entity_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ def get_eligibility(claim_amount, claim_type, customer_id)
return false unless health_record
health_record.insurance_policies.each do |policy|
if policy.covers.contains(claim_type) && claim_amount <= policy.coverage.to_i
return true
return { eligible_policy_id: policy.id, max_coverage_left: policy.coverage, is_eligible: true }
end
end
false
{ is_eligible: false }
# get uhid of customer
# get health record
# check insurances and it's active status
Expand Down
53 changes: 47 additions & 6 deletions app/helpers/insurance_helper.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,52 @@
class CentralEntityHelper
class InsuranceHelper
class << self

def process_pre_auth(amount, claim_type, customer_id)
# check for customer consent on a loop - long polling/while true
# if consent doesn't exist - register customer consent
# if approved, store customer health data [later can be made accessible via api only for a limited time]
# and register claim in database with pre-auth status
# check for customer consent on a loop - long polling/while true
# if consent doesn't exist - register customer consent
# if approved, store customer health data [later can be made accessible via api only for a limited time]
# and register claim in database with pre-auth status
def process_pre_auth(amount, claim_type, requester_id, customer_id)
consent = Consent.find_by(person_id: customer_id, requested_by: requester_id)
if consent
# health_report = HealthReport.find_by_person_id(customer_id)
eligibility = CentralEntityHelper.get_eligibility(amount, claim_type, customer_id).with_indifferent_access
eligible_policy_id = eligibility[:eligible_policy_id]
claim = Claim.create(status: "pre-auth-approved", person_id: customer_id, insurance_policy_id: eligible_policy_id)
return { "success": true, "claim_id": claim.id }
else
data = "Pre auth request from " + requester_id
notification = Notification.create(title: "Pre-auth request", data: data, person_id: customer_id, sender: requester_id)
# send notification
return {"success": false }
end
end

# check if claim exists
# check claim status if in a valid state
# check eligible limit with insurance policy data
# calls fraud detection engine
# if fraud engine validates
# mark claim as success
# send notif to customer
def send_claim_request(params)
claim_id = params[:claim_id]
amount = params[:claims_amount]
claim_type = params[:claim_type]
#todo: add claim type to claim model
claim = Claim.find_by(id: claim_id)
if !claim || claim.status != 'pre-auth-approved'
return {"success": false, msg: "customer not authorised, invalid claim status"}
end
eligibility = CentralEntityHelper.get_eligibility(amount, claim_type, claim.person_id)
if eligibility[:is_eligible]
claim.update(status: "processing")
#todo: call fraud api
else
new_status = "rejected"
ClaimStatusHistory.create(transition_from: claim.status, transition_to: new_status, claim_id: claim.id)
claim.update(status: new_status)
# todo: create notif & notify customer
end
end
end
end
3 changes: 3 additions & 0 deletions app/models/consent.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Consent < ApplicationRecord
belongs_to :person
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Rails.application.routes.draw do
resources :consents
resources :claim_status_histories
resources :notifications
resources :claims
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20230527103556_create_consents.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateConsents < ActiveRecord::Migration[7.0]
def change
create_table :consents do |t|
t.timestamp :registered_on
t.string :requested_by
t.string :access_modules, array: true # to be used later
t.references :person, index: true, foreign_key: true
t.timestamps
end
end
end
7 changes: 7 additions & 0 deletions db/migrate/20230527110904_add_data_to_notification.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddDataToNotification < ActiveRecord::Migration[7.0]
def change
add_column :notifications, :title, :string
add_column :notifications, :data, :string
add_column :notifications, :sender, :string
end
end
16 changes: 15 additions & 1 deletion db/schema.rb

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

38 changes: 38 additions & 0 deletions test/controllers/consents_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require "test_helper"

class ConsentsControllerTest < ActionDispatch::IntegrationTest
setup do
@consent = consents(:one)
end

test "should get index" do
get consents_url, as: :json
assert_response :success
end

test "should create consent" do
assert_difference("Consent.count") do
post consents_url, params: { consent: { } }, as: :json
end

assert_response :created
end

test "should show consent" do
get consent_url(@consent), as: :json
assert_response :success
end

test "should update consent" do
patch consent_url(@consent), params: { consent: { } }, as: :json
assert_response :success
end

test "should destroy consent" do
assert_difference("Consent.count", -1) do
delete consent_url(@consent), as: :json
end

assert_response :no_content
end
end
11 changes: 11 additions & 0 deletions test/fixtures/consents.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

# This model initially had no columns defined. If you add columns to the
# model remove the "{}" from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
7 changes: 7 additions & 0 deletions test/models/consent_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

class ConsentTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit 0a7aad5

Please sign in to comment.