forked from itznishant/FraudAnalyticsSystem_RCode_
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoFraud_Unstructure_Business Rules.R
More file actions
127 lines (88 loc) · 3.2 KB
/
AutoFraud_Unstructure_Business Rules.R
File metadata and controls
127 lines (88 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env Rscript
# Order in which Parameters are to be passed to the code in the command line
# -loss_date 12/20/2013 ; -claim_num C1001
# Code for reading the command line inputs
args <- commandArgs(trailingOnly = TRUE)
# Reading the parameters from the command line and assigning to R varibles
Param1<-args[1]
Loss_date<-as.Date(args[2],format='%m/%d/%Y')
sc1<-args[3]
#Loss_date
Param2<-args[4]
ClaimNum <-args[5]
#ClaimNum
# Connecting to Oracle table
# Extract the record for the specific claim
suppressMessages(require(RODBC))
channel<-odbcConnect("RORACLE",uid="fraudrepo",pwd="fraudrepo",believeNRows=FALSE)
ClaimRecord=sqlQuery(channel,sprintf("select * from RENGINEINVOKE where Claim_id = '%s'",ClaimNum))
#Unstructured Data
unstructureRecord=sqlQuery(channel,sprintf("select * from FAS_POLICE_UNSTRUCTED_DATA where CLAIMID='%s'",ClaimNum))
unstructureRecord$CLAIM_ID = as.character(unstructureRecord$CLAIMID)
unstructureRecord$DATE_OF_INCIDENT = as.Date(as.character(unstructureRecord$DATE_OF_INCIDENT),format='%Y-%m-%d')
unstructureRecord$DATE_OF_POLICE_REPORT = as.Date(as.character(unstructureRecord$DATE_OF_POLICE_REPORT),format='%Y-%m-%d')
options(warn=-1)
# Initializing Fraud Score variable and Triggered business rule list
FraudScore=0
BRList=list();
if(nrow(unstructureRecord)!=0)
{
# Business Rule1
if(Loss_date!=unstructureRecord$DATE_OF_INCIDENT)
{
FraudScore=FraudScore+20
BRList=c(BRList,"Mismatch between Date of incident and Loss date")
}
#Business Rule2
date_pattern<-parse(file = "unstructureRecord", n = NULL, text = unstructureRecord$DATE_OF_POLICE_REPORT)
#CHECK FOR POLICE DATE [UNSTRUCTURED DATA]
CHECK_POLICE_DATE <- is.na(date_pattern)
Rule2a <- ClaimRecord$POLICE_REPORT
Rule2b <- CHECK_POLICE_DATE
if(Rule2a=="YES" && Rule2b=="TRUE")
{
FraudScore=FraudScore+20;
BRList=c(BRList,"Mismatch in police report data")
}
if(Rule2a=="NO" && Rule2b=="FALSE")
{
FraudScore=FraudScore+20;
BRList=c(BRList,"Mismatch in police report data")
}
#Business Rule3
Rule3a<-grep("DIDN'T REALIZE",unstructureRecord$REMARKS,ignore.case=F,fixed = TRUE)
Rule3b<-grep("Careless",unstructureRecord$REMARKS,ignore.case=F,fixed = TRUE)
Rule3c<-grep("Did not notice",unstructureRecord$REMARKS,ignore.case=F,fixed = TRUE)
BR_CHECK <- Rule13a||Rule13b||Rule13c != 0
Rule3 <- isTRUE(BR_CHECK)
if(Rule3==TRUE)
{
FraudScore=FraudScore+20;
BRList=c(BRList,"Unwanted terms were found")
}
#Business Rule4
Rule4 <-is.na(unstructureRecord$REMARKS)
if(Rule4==TRUE)
{
FraudScore=FraudScore+20;
BRList=c(BRList,"Remarks not present")
}
# Printing the final outputs
cat("\n\n\n")
}
if(FraudScore>0)
{
cat("Fraud Score =",FraudScore)
cat("\n\n\nThe List of triggered business rules are:\n\n")
paste(BRList)
}
if(FraudScore==0)
{
cat("Fraud Score =",FraudScore)
cat("\n\n\nNo Fraud Business rules were triggered for this claim\n\n")
}
if(nrow(unstructureRecord)==0)
{
print("CLAIMID NOT FOUND")
}
odbcClose(channel)