-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProviderValidator.java
More file actions
181 lines (142 loc) · 3.64 KB
/
ProviderValidator.java
File metadata and controls
181 lines (142 loc) · 3.64 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package edu.easternct.bigdata;
import java.util.Arrays;
import java.util.List;
public class ProviderValidator {
String line;
private boolean clean;
String[] stateSet = { "AA", "AE", "AK", "AL", "AP", "AR", "AS", "AZ", "CA",
"CO", "CT", "DC", "DE", "FL", "FM", "GA", "GU", "HI", "IA", "ID",
"IL", "IN", "KS", "KY", "LA", "MA", "MD", "ME", "MH", "MI", "MN",
"MO", "MP", "MS", "MT", "NC", "ND", "NE", "NH", "NJ", "NM", "NV",
"NY", "OH", "OK", "OR", "PA", "PR", "PW", "RI", "SC", "SD", "TN",
"TX", "UT", "VA", "VI", "VT", "WA", "WI", "WV", "WY" };
List<String> goodStates = Arrays.asList(stateSet);
/* error count */
int errorCnt = 0;
private int npi; //0th index in string[]
private String state; //11th index in string[]
private String gender; //5th index in string[]
private String providerType; //12th index in string[]
private String entityCode;
public ProviderValidator() {
this.line = null;
}
public ProviderValidator(String line) {
this.line = line;
}
/**
* @return clean indicator
*/
public boolean isClean() {
return clean;
}
/**
* @param clean
* the clean to set
*/
public void setClean(boolean clean) {
this.clean = clean;
}
/**
* @return the errorCnt
*/
public int getErrorCnt() {
return errorCnt;
}
/**
* @param errorCnt
* the errorCnt to set
*/
public void setErrorCnt(int errorCnt) {
this.errorCnt = errorCnt;
}
public boolean parser() {
String[] tokens = line.split(",");
if (tokens.length <15)
return false;
// validate that it's not an organization
if (validateOrg(tokens[6])) {
// validate npi
if (validateNPI(tokens[0])) {
this.npi = Integer.parseInt(tokens[0]);
} else {
this.npi = 0;
errorCnt++;
}
//validate gender
if (validateGender(tokens[5])) {
this.gender =tokens[5];
} else {
this.gender =null;
errorCnt++;
}
//validate state
if (validateState(tokens[11])) {
this.state =tokens[11];
} else {
this.state = null;
errorCnt++;
}
//validate Provider type
if (validatePT(tokens[13])) {
this.providerType = tokens[13];
} else {
this.providerType = null;
errorCnt++;
}
} else errorCnt++;
if (errorCnt > 0) {
setClean(false);
return false;
} else
setClean(true);
return true;
}
public boolean validateNPI(String npi) {
boolean valid = true;
//if it isn't a digit or is null, it's false
if ((npi == null) || (!npi.matches("^\\d+$")))
valid = false;
return valid;
}
public boolean validateGender(String gender) {
boolean valid = true;
//not a very progressive measure, but can only be F or M.
if ((gender == null) || (!gender.matches("[FM]")))
valid = false;
return valid;
}
public boolean validateState(String st){
boolean valid = true;
if (!goodStates.contains(st))
valid = false;
return valid;
}
public boolean validateOrg(String org) {
boolean valid = true;
if ((org == null) || (!org.matches("[I]")))
valid = false;
return valid;
}
public boolean validatePT(String pt){
boolean valid = true;
if ((pt == null) || (!pt.matches("[a-zA-Z]+")))
valid = false;
return valid;
}
//i wanted to create a method to use the valid data to populate Provider classes directly
public Provider generateProvider(){
return new Provider(this.npi, this.state,this.gender, this.providerType);
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "npi: " + npi + " Gender: " + gender +
" Provider Type: " + providerType + " State: " + state +
" Entity Code: " + entityCode + " Clean: " + clean;
}
}