forked from nextgenhealthcare/connect-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EDI X12 Batch Script.js
61 lines (61 loc) · 1.1 KB
/
EDI X12 Batch Script.js
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
var segDelim = '~';
var elementDelim = '*';
var subelementDelim = ':';
var infer = true;
var message = new java.lang.StringBuilder();
var ch;
while ((ch = consume(1)) != null) {
if (infer) {
elementDelim = consume(3);
subelementDelim = consume(101);
segDelim = consume(1);
consumeNewline();
infer = false;
continue;
} else if (ch == segDelim) {
consumeNewline();
reader.mark(3);
if (readChar() == 'I' && readChar() == 'N' && readChar() == 'S') {
reader.reset();
break;
}
reader.reset();
}
}
return message.toString();
function readChar() {
var c = reader.read();
return c == -1 ? null : java.lang.Character.valueOf(c);
}
function consume(num) {
var ch;
for (var i = 1; i <= num; i++) {
ch = readChar();
if (ch != null) {
message.append(ch);
}
}
return ch;
}
function consumeNewline() {
reader.mark(1);
var ch = readChar();
if (ch == '\r') {
message.append(ch);
reader.mark(1);
if ((ch = readChar()) == '\n') {
message.append(ch);
} else {
reader.reset();
}
} else if (ch == '\n') {
message.append(ch);
} else {
reader.reset();
}
}