From 3bccf5cadef74edc07ffdedd279c4860769421e3 Mon Sep 17 00:00:00 2001 From: Surabhi Suman Date: Sat, 27 May 2023 20:04:47 +0530 Subject: [PATCH] added basic data seeding --- .gitignore | 1 + .idea/workspace.xml | 48 +++++++++++++++---- .../health_care_provider_controller.rb | 11 +++-- app/helpers/central_entity_helper.rb | 8 ++-- app/models/health_report.rb | 2 +- app/models/person.rb | 1 + config/routes.rb | 5 ++ db/migrate/20230527081421_create_invoices.rb | 1 + ...0230527081548_create_insurance_policies.rb | 1 + .../20230527083418_create_prescriptions.rb | 1 + ...100527_add_coverage_to_insurance_policy.rb | 2 +- db/schema.rb | 5 +- db/seeds.rb | 30 ++++++++++++ 13 files changed, 97 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 12439e5..1f13e4b 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ # Ignore master key for decrypting credentials and more. /config/master.key +.idea diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 65f2c40..880bd4f 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,14 +2,22 @@ - + - + + - + + + + + + + + - + - - - + + + + + @@ -164,7 +179,7 @@ + + + + + file://$PROJECT_DIR$/app/controllers/health_care_provider_controller.rb + 7 + + + + + + + + + \ No newline at end of file diff --git a/app/controllers/health_care_provider_controller.rb b/app/controllers/health_care_provider_controller.rb index 044fc51..a78f6d6 100644 --- a/app/controllers/health_care_provider_controller.rb +++ b/app/controllers/health_care_provider_controller.rb @@ -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 @@ -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 @@ -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 diff --git a/app/helpers/central_entity_helper.rb b/app/helpers/central_entity_helper.rb index 370d6d4..d2b8019 100644 --- a/app/helpers/central_entity_helper.rb +++ b/app/helpers/central_entity_helper.rb @@ -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 diff --git a/app/models/health_report.rb b/app/models/health_report.rb index d4ba65f..3da7eba 100644 --- a/app/models/health_report.rb +++ b/app/models/health_report.rb @@ -2,5 +2,5 @@ class HealthReport < ApplicationRecord has_many :invoices has_many :insurance_policies has_many :prescriptions - has_one :person + belongs_to :person end diff --git a/app/models/person.rb b/app/models/person.rb index d3b9d78..8d0cf29 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -1,4 +1,5 @@ class Person < ApplicationRecord + has_one :health_report end diff --git a/config/routes.rb b/config/routes.rb index 1c53f07..5372b64 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/migrate/20230527081421_create_invoices.rb b/db/migrate/20230527081421_create_invoices.rb index 41245ae..a96f755 100644 --- a/db/migrate/20230527081421_create_invoices.rb +++ b/db/migrate/20230527081421_create_invoices.rb @@ -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 diff --git a/db/migrate/20230527081548_create_insurance_policies.rb b/db/migrate/20230527081548_create_insurance_policies.rb index fe9263f..29c6567 100644 --- a/db/migrate/20230527081548_create_insurance_policies.rb +++ b/db/migrate/20230527081548_create_insurance_policies.rb @@ -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 diff --git a/db/migrate/20230527083418_create_prescriptions.rb b/db/migrate/20230527083418_create_prescriptions.rb index 85a2bdf..f209f1c 100644 --- a/db/migrate/20230527083418_create_prescriptions.rb +++ b/db/migrate/20230527083418_create_prescriptions.rb @@ -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 diff --git a/db/migrate/20230527100527_add_coverage_to_insurance_policy.rb b/db/migrate/20230527100527_add_coverage_to_insurance_policy.rb index 7f4b8d3..1d49a98 100644 --- a/db/migrate/20230527100527_add_coverage_to_insurance_policy.rb +++ b/db/migrate/20230527100527_add_coverage_to_insurance_policy.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index b9357cf..e37ed8b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -54,13 +54,15 @@ t.datetime "end_date" t.integer "sum_insured" t.string "covers" + t.integer "health_report_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.string "coverage" + t.integer "coverage" end create_table "invoices", force: :cascade do |t| t.integer "amount" + t.integer "health_report_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false end @@ -89,6 +91,7 @@ create_table "prescriptions", force: :cascade do |t| t.string "medicines" t.string "lab_tests" + t.integer "health_report_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false end diff --git a/db/seeds.rb b/db/seeds.rb index bc25fce..5b250b8 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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: "", + 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 +)