Skip to content

Commit

Permalink
auto create consent on notification approval
Browse files Browse the repository at this point in the history
  • Loading branch information
surabhisuman committed May 28, 2023
1 parent 789a285 commit 93217d3
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 57 deletions.
52 changes: 9 additions & 43 deletions .idea/workspace.xml

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

7 changes: 7 additions & 0 deletions app/controllers/consents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ def show
render json: @consent
end

def approve_consent
@consent = Consent.create(consultation_id: params[:consultation_id], person_id: params[:person_id], registered_on: Time.now)
notification = Notification.find_by(id: params[:notification_id])
notification.update(notification_type: Notification::TYPE["NOTICE"], data: @notification.data + " Approved")
render json: @consent
end

# POST /consents
def create
@consent = Consent.new(consent_params)
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/notifications_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
class NotificationsController < ApplicationController
before_action :set_notification, only: %i[ show update destroy ]

# GET /notifications
# GET /notifications?person_id
def index
# fetch all notifications, delete all notification in current scope, send notification over http
# wait for next request to come in. one more thing, FE pe state nahi kar payneg manage. no code tool very limited. yes. ok
if params[:person_id].present?
@notifications = Notification.where(person_id: params[:person_id])
else
Expand Down
8 changes: 4 additions & 4 deletions app/helpers/insurance_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ def process_pre_auth(requester_id, customer_id, eligibility)
#todo: stitch some mechanism to create consent when notification is approved or just create consent from seeds
consent = Consent.find_by(person_id: customer_id, consultation_id: consultation.id)
#todo: comment next line
consent = Consent.create(consultation: consultation, person_id: customer_id, registered_on: Time.now)
# consent = Consent.create(consultation: consultation, person_id: customer_id, registered_on: Time.now)
# a consent is valid for 2 days
if consent && (Time.now-1.day..Time.now+2.days).cover?(consent.registered_on)
# health_report = HealthReport.find_by_person_id(customer_id)
eligible_policy_id = eligibility[:eligible_policy_id]
claim = Claim.create(status: "pre-auth-approved", person_id: customer_id, insurance_policy_id: eligible_policy_id, consultation_id: consultation.id)
return { "success": true, "claim_id": claim.id, "consultation_id": consultation.id, msg: "Pre auth claim registered successfully" }
else
NotificationHelper.send_notification(requester_id, customer_id, "Pre Auth Request", consultation.id)
NotificationHelper.send_notification(requester_id, customer_id, "Pre Auth Request", consultation.id, "CONSENT")
# send notification
return { "success": false, "msg": "Consent pending fom customer" }
end
Expand Down Expand Up @@ -48,12 +48,12 @@ def send_claim_request(claim_id, amount, eligibility)
updateClaimStatus("approved", claim)
updated_coverage = insured_policy.coverage - amount
insured_policy.update(coverage: updated_coverage)
NotificationHelper.send_notification(insured_policy.insurer, claim.person_id, "Claim of Rs." + (amount.to_s) +" approved", claim.consultation_id)
NotificationHelper.send_notification(insured_policy.insurer, claim.person_id, "Claim of Rs." + (amount.to_s) +" approved", claim.consultation_id, "NOTICE")
return {"success": true, "msg": "Claim processed successfully"}
end
end
updateClaimStatus("rejected", claim)
NotificationHelper.send_notification(insured_policy.insurer, claim.person_id, "Claim of Rs." + amount +" rejected", claim.consultation_id)
NotificationHelper.send_notification(insured_policy.insurer, claim.person_id, "Claim of Rs." + amount +" rejected", claim.consultation_id, "NOTICE")
end

private
Expand Down
6 changes: 3 additions & 3 deletions app/helpers/notification_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ module NotificationHelper

class << self

def send_notification(requester_id, customer_id, context, consultation_id)
existing_notification = Notification.find_by(sender: requester_id, person_id: customer_id, title: context, consultation_id: consultation_id)
def send_notification(requester_id, customer_id, context, consultation_id, type)
existing_notification = Notification.find_by(sender: requester_id, person_id: customer_id, title: context, consultation_id: consultation_id, notification_type: type)
return if existing_notification
data = context + " from " + requester_id
notification = Notification.create(title: context, data: data, person_id: customer_id, sender: requester_id, consultation_id: consultation_id)
notification = Notification.create(title: context, data: data, person_id: customer_id, sender: requester_id, consultation_id: consultation_id, notification_type: type)
# send notification
# todo: figure out how to send
end
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@
# Defines the root path route ("/")
# root "articles#index"
#
#
post '/approve_consent', to: "consents#approve_consent"
end
4 changes: 2 additions & 2 deletions db/migrate/20230527190746_add_columns_to_claims.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class AddColumnsToClaims < ActiveRecord::Migration[7.0]
# - Date of Service: 10th March, 2022
# - Provider: Ruby Hall Clinic, Pune - already in place name change?todo didn;t get
# - Provider: Ruby Hall Clinic, Pune
# - Diagnosis: Pregnancy
# - Procedure: Caesarean section, Hospitalization (for 3 days)
# - Claim Amount: ₹1,80,000 - already in place name change?todo
# - Claim Amount: ₹1,80,000
# - Paid by Insurance: ₹1,62,000
# - Out of Pocket: ₹18,000

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20230527235615_change_notification_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ChangeNotificationType < ActiveRecord::Migration[7.0]
def change
rename_column :notifications, :type, :notification_type
end
end
4 changes: 2 additions & 2 deletions db/schema.rb

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

0 comments on commit 93217d3

Please sign in to comment.