Skip to content

Commit

Permalink
added basic data seeding
Browse files Browse the repository at this point in the history
  • Loading branch information
surabhisuman committed May 27, 2023
1 parent 3144311 commit 3bccf5c
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@

# Ignore master key for decrypting credentials and more.
/config/master.key
.idea
48 changes: 40 additions & 8 deletions .idea/workspace.xml

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

11 changes: 7 additions & 4 deletions app/controllers/health_care_provider_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ class HealthCareProviderController < ApplicationController
# checks eligibility for current medication/to be claim
def check_eligibility
amount = params[:amount].to_i
claim_type = params["claim_type"].to_s
claim_type = params[:claim_type].to_s
health_id = params[:health_id].to_s
customer = Person.find_by_health_id(health_id)
resp = CentralEntityHelper.get_eligibility(amount, claim_type, customer.id)
return render json: resp
render json: resp
rescue StandardError => e
puts(e.message)
render json: {msg: "Bad request"}
end

def send_pre_auth_request
Expand All @@ -17,7 +20,7 @@ def send_pre_auth_request
health_id = params[:health_id].to_s
customer = Person.find_by_health_id(health_id)
resp = InsuranceHelper.process_pre_auth(amount, claim_type, requester_id, customer.id)
return render json: resp
render json: resp
end

def update_docs_and_send_claim_request
Expand All @@ -26,7 +29,7 @@ def update_docs_and_send_claim_request
claim_type = params[:claim_type]
CentralEntityHelper.add_data_to_health_record(params[:prescriptions], params[:invoices], params[:person_id])
resp = InsuranceHelper.send_claim_request(claim_id, amount, claim_type)
return render json: resp
render json: resp
end

end
8 changes: 4 additions & 4 deletions app/helpers/central_entity_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ module CentralEntityHelper
class << self

def get_eligibility(claim_amount, claim_type, customer_id)
health_record = HealthReport.find_by_person_id(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
health_report = HealthReport.find_by_person_id(customer_id)
return { is_eligible: false } unless health_report
health_report.insurance_policies.each do |policy|
if policy.covers.include?(claim_type.downcase) && claim_amount <= policy.coverage.to_i
return { eligible_policy_id: policy.id, max_coverage_left: policy.coverage, is_eligible: true }
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/health_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ class HealthReport < ApplicationRecord
has_many :invoices
has_many :insurance_policies
has_many :prescriptions
has_one :person
belongs_to :person
end
1 change: 1 addition & 0 deletions app/models/person.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Person < ApplicationRecord

has_one :health_report

end
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
resources :invoices
resources :people
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
#

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'
# Defines the root path route ("/")
# root "articles#index"
#
end
1 change: 1 addition & 0 deletions db/migrate/20230527081421_create_invoices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class CreateInvoices < ActiveRecord::Migration[7.0]
def change
create_table :invoices do |t|
t.integer :amount
t.integer :health_report_id, required: true
t.timestamps
end
end
Expand Down
1 change: 1 addition & 0 deletions db/migrate/20230527081548_create_insurance_policies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def change
t.timestamp :end_date
t.integer :sum_insured
t.string :covers, array: true
t.integer :health_report_id, required: true
t.timestamps
end
end
Expand Down
1 change: 1 addition & 0 deletions db/migrate/20230527083418_create_prescriptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ def change
create_table :prescriptions do |t|
t.string :medicines, array: true
t.string :lab_tests, array: true
t.integer :health_report_id, required: true
t.timestamps
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class AddCoverageToInsurancePolicy < ActiveRecord::Migration[7.0]
def change
add_column :insurance_policies, :coverage, :string
add_column :insurance_policies, :coverage, :integer
end
end
5 changes: 4 additions & 1 deletion db/schema.rb

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

30 changes: 30 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,33 @@
#
# movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }])
# Character.create(name: "Luke", movie: movies.first)

# byebug

person = Person.create(
name: "Patient",
health_id: "patient@adhm",
email: "patient@gmail.com",
phone: '9999999999',
aadhar_number: "12332423",
)

consent = Consent.create(
requested_by: "<health-care-provider-id>",
person: person
)

health_report = HealthReport.create(
person: person
)


policy = InsurancePolicy.create(
insurer: "Insure Inc",
start_date: Time.now,
end_date: Time.now + 1.month,
sum_insured: 500000,
covers: "dental, opd, cancer, daibetes",
coverage: 40000,
health_report_id: health_report.id
)

0 comments on commit 3bccf5c

Please sign in to comment.