-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added pre auth and claim request apis
- Loading branch information
Surabhi Suman
authored and
Surabhi Suman
committed
May 27, 2023
1 parent
cafd380
commit 0a7aad5
Showing
13 changed files
with
205 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Consent < ApplicationRecord | ||
belongs_to :person | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |