Repository navigation
Expand file tree
/
Copy pathCrunchNPI.java
More file actions
67 lines (58 loc) · 1.99 KB
/
Copy pathCrunchNPI.java
File metadata and controls
67 lines (58 loc) · 1.99 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
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import org.apache.commons.validator.routines.checkdigit.LuhnCheckDigit;
public class CrunchNPI
{
public static void main(String[] args)
{
LuhnCheckDigit luhn = new LuhnCheckDigit();
//Input file which needs to be parsed
String fileToParse = "/npi/npidata.csv";
BufferedReader fileReader = null;
//Delimiter used in CSV file
final String DELIMITER = ",";
try
{
String line = "";
//Create the file reader
fileReader = new BufferedReader(new FileReader(fileToParse));
int lineCount = 0;
//Read the file line by line
while ((line = fileReader.readLine()) != null)
{
// the first row contains header information
if (lineCount > 0) {
String[] fields = line.split(DELIMITER);
String npi = "80840" + slice_range(fields[0], 1, fields[0].length() - 1);
luhn.isValid(npi);
}
lineCount++;
}
}
catch (Exception e) {
e.printStackTrace();
}
finally
{
try {
fileReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static String slice_start(String s, int startIndex) {
if (startIndex < 0) startIndex = s.length() + startIndex;
return s.substring(startIndex);
}
public static String slice_end(String s, int endIndex) {
if (endIndex < 0) endIndex = s.length() + endIndex;
return s.substring(0, endIndex);
}
public static String slice_range(String s, int startIndex, int endIndex) {
if (startIndex < 0) startIndex = s.length() + startIndex;
if (endIndex < 0) endIndex = s.length() + endIndex;
return s.substring(startIndex, endIndex);
}
}