Skip to content

Commit 8941f60

Browse files
authored
Merge pull request #45 from imsweb/x12-270-271-support-44
Add X12 270 271 support
2 parents 15d7335 + 8ab7a41 commit 8941f60

File tree

5 files changed

+95
-8
lines changed

5 files changed

+95
-8
lines changed

src/main/java/com/imsweb/x12/reader/X12Reader.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class X12Reader {
5050
private static final String _X223_ANSI_VERSION = "005010X223A2";
5151
private static final String _X231_ANSI_VERSION = "005010X231A1";
5252
private static final String _X214_ANSI_VERSION = "005010X214";
53+
private static final String _X270_271_092_ANSI_VERSION = "004010X092A1";
5354
private static final Map<FileType, String> _TYPES = new HashMap<>();
5455

5556
private List<String> _errors = new ArrayList<>();
@@ -73,7 +74,9 @@ public enum FileType {
7374
ANSI837_5010_X222("mapping/837.5010.X222.A1.xml"),
7475
ANSI837_5010_X223("mapping/837Q3.I.5010.X223.A1.xml"),
7576
ANSI837_5010_X231("mapping/999.5010.xml"),
76-
ANSI837_5010_X214("mapping/277.5010.X214.xml");
77+
ANSI837_5010_X214("mapping/277.5010.X214.xml"),
78+
ANSI270_4010_X092("mapping/270.4010.X092.A1.xml"),
79+
ANSI271_4010_X092("mapping/271.4010.X092.A1.xml");
7780

7881
private String _mapping;
7982

@@ -115,6 +118,8 @@ public synchronized TransactionDefinition getDefinition() {
115118
_TYPES.put(FileType.ANSI837_5010_X223, _X223_ANSI_VERSION);
116119
_TYPES.put(FileType.ANSI837_5010_X214, _X214_ANSI_VERSION);
117120
_TYPES.put(FileType.ANSI837_5010_X231, _X231_ANSI_VERSION);
121+
_TYPES.put(FileType.ANSI270_4010_X092, _X270_271_092_ANSI_VERSION);
122+
_TYPES.put(FileType.ANSI271_4010_X092, _X270_271_092_ANSI_VERSION);
118123
}
119124

120125
/**
@@ -404,7 +409,7 @@ private boolean checkVersionsAreConsistent(Separators separators, Reader reader)
404409
version = lineString.substring(versionStartPos + 1);
405410
}
406411
reader.reset();
407-
412+
408413
boolean result = _TYPES.get(_type).equals(version);
409414

410415
if (!result)
@@ -709,7 +714,7 @@ private LoopConfig getMatchedLoop(String[] tokens, String previousLoopID) {
709714

710715
if (matchedLoops.size() > 1) {
711716
// starting a new loop but we aren't quite sure which one yet. Remove loops where the segment is known to be the last segment of that loop - clearly we aren't in a new loop then
712-
matchedLoops = matchedLoops.stream().filter(lc -> !(lc.getLastSegmentXid().getXid().equals(tokens[0]) && codesValidatedForLoopId(tokens, lc.getLastSegmentXid()))).collect(
717+
matchedLoops = matchedLoops.stream().filter(lc -> lc.getLastSegmentXid() == null || !(lc.getLastSegmentXid().getXid().equals(tokens[0]) && codesValidatedForLoopId(tokens, lc.getLastSegmentXid()))).collect(
713718
Collectors.toList());
714719
result = matchedLoops.isEmpty() ? null : (matchedLoops.size() == 1 ? matchedLoops.get(0) : getFinalizedMatch(previousLoopID, matchedLoops));
715720
}
@@ -800,10 +805,9 @@ else if (tokens == null)
800805
_errors.add("Unable to split elements to validate segment ID!");
801806
i++;
802807
}
803-
804-
if (!lineMatchesFormat)
808+
809+
if (!lineMatchesFormat)
805810
_errors.add("Unable to find a matching segment format in loop " + loopId);
806-
807811
lineMatchesFormat = false;
808812
}
809813

src/main/resources/mapping/271.4010.X092.A1.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2814,8 +2814,6 @@
28142814
</element>
28152815
</segment>
28162816
<!--End of PRV segment-->
2817-
</loop>
2818-
<!--End of 2120C loop-->
28192817
<segment xid="LE">
28202818
<name>Loop Trailer</name>
28212819
<usage>S</usage>
@@ -2832,6 +2830,8 @@
28322830
</element>
28332831
</segment>
28342832
<!--End of LE segment-->
2833+
</loop>
2834+
<!--End of 2120C loop-->
28352835
</loop>
28362836
<!--End of 2110C loop-->
28372837
</loop>

src/test/java/com/imsweb/x12/reader/X12ReaderTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,49 @@ public void test999Rejected() throws Exception {
14931493

14941494
}
14951495

1496+
@Test
1497+
public void test270() throws Exception {
1498+
URL url = this.getClass().getResource("/x270_271/x270.txt");
1499+
X12Reader reader = new X12Reader(FileType.ANSI270_4010_X092, new File(url.getFile()));
1500+
1501+
List<Loop> loops = reader.getLoops();
1502+
Assert.assertEquals(1, loops.size());
1503+
Loop loop = reader.getLoops().get(0);
1504+
assertEquals(1, loop.getLoops().size());
1505+
1506+
Element statusCodeElement = loop.getLoop("GS_LOOP").getLoop("ST_LOOP").getLoop("DETAIL")
1507+
.getLoop("2000A")
1508+
.getLoop("2000B")
1509+
.getLoop("2000C")
1510+
.getLoop("2100C")
1511+
.getLoop("2110C")
1512+
.getSegment("EQ")
1513+
.getElement("EQ01");
1514+
Assert.assertEquals("30", statusCodeElement.getSubValues().get(0));
1515+
}
1516+
1517+
@Test
1518+
public void test271() throws Exception {
1519+
URL url = this.getClass().getResource("/x270_271/x271.txt");
1520+
X12Reader reader = new X12Reader(FileType.ANSI271_4010_X092, new File(url.getFile()));
1521+
1522+
List<Loop> loops = reader.getLoops();
1523+
Assert.assertEquals(1, loops.size());
1524+
Loop loop = reader.getLoops().get(0);
1525+
assertEquals(1, loop.getLoops().size());
1526+
1527+
Element statusCodeElement = loop.getLoop("GS_LOOP").getLoop("ST_LOOP").getLoop("DETAIL")
1528+
.getLoop("2000A")
1529+
.getLoop("2000B")
1530+
.getLoop("2000C")
1531+
.getLoop("2100C")
1532+
.getLoop("2110C")
1533+
.getLoop("2120C")
1534+
.getSegment("NM1")
1535+
.getElement("NM101");
1536+
Assert.assertEquals("P3", statusCodeElement.getSubValues().get(0));
1537+
}
1538+
14961539
@Test
14971540
public void testAmbiguousLoop() throws Exception {
14981541
URL url = this.getClass().getResource("/837_5010/x12_ambiguous_loop.txt");
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
ISA*03*0000000000*01*0000000000*ZZ*ABCDEFGHIJKLMNO*ZZ*123456789012345*101127*1719*U*00401*000003438*0*P*:~
2+
GS*HS*EMEDNYBAT*XDZ*20110311*100831*14420*X*004010X092A1~
3+
ST*270*000121~
4+
BHT*0022*13**20021010*0800*~
5+
HL*1**20*1~
6+
NM1*PR*2*CHILDRENS SPECIAL HEALTHCARE*****FI*356000158**~
7+
HL*2*1*21*1~
8+
NM1*1P*2******SV*123456**~
9+
HL*3*2*22*1~
10+
TRN*1*1234667890*9876543210*~
11+
NM1*IL*1*DOE*JANE****MI*123456**~
12+
REF*SY*123456789**~
13+
DMG*D8*19851031*******~
14+
DTP*307*RD8*20021201-20021231~
15+
EQ*30***~
16+
SE*15*0000121~
17+
GE*1*14420~
18+
IEA*1*000014420~
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ISA*03*0000000000*01*0000000000*ZZ*ABCDEFGHIJKLMNO*ZZ*123456789012345*101127*1719*U*00401*000003438*0*P*>~
2+
GS*HB*EMEDNYBAT*XDZ*20110311*100831*14420*X*004010X092A1~
3+
ST*271*4321*005010X279A1~
4+
BHT*0022*11*10001234*20060501*1319~
5+
HL*1**20*1~
6+
NM1*PR*2*ABC COMPANY*****PI*842610001~
7+
HL*2*1*21*1~
8+
NM1*1P*2*BONE AND JOINT CLINIC*****SV*2000035~
9+
HL*3*2*22*0~
10+
TRN*2*93175-012547*9877281234~
11+
NM1*IL*1*SMITH*JOHN****MI*123456789~
12+
N3*15197 BROADWAY AVENUE*APT 215~
13+
N4*KANSAS CITY*MO*64108~
14+
DMG*D8*19630519*M~
15+
DTP*346*D8*20060101~
16+
EB*1**30**GOLD 123 PLAN********~
17+
LS*2120~
18+
NM1*P3*1*JONES*MARCUS****SV*0202034~
19+
LE*2120~
20+
SE*22*4321~
21+
GE*1*14420~
22+
IEA*1*000014420~

0 commit comments

Comments
 (0)