imsweb / x12-parser

A Java parser for ANSI ASC X12 documents.
Other
80 stars 44 forks source link

Unable to parse 837 document #18

Closed mcpierce closed 4 years ago

mcpierce commented 4 years ago

New to using x12-parser, this could be a case of user error (no documentation for the project, so I'm winging it).

I have a simple parser app:

package com.outpatientservicesllc.adaptors;

import com.imsweb.x12.Loop;
import com.imsweb.x12.reader.X12Reader;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;

@Component
@Log4j2
public class ANSI837DocumentAdaptor {
  public void loadFile(String filename) throws IOException {
    this.log.debug("Loading file: {}", filename);
    X12Reader reader =
        new X12Reader(X12Reader.FileType.ANSI837_5010_X222, new FileInputStream(filename));
    List<Loop> loops = reader.getLoops();

    this.log.debug("Processing {} loop{}", loops.size(), loops.size() == 1 ? "" : "s");

    for (int index = 0; index < loops.size(); index++) {
      this.log.debug("[{}] {}", index, loops.get(index));
    }
  }
}

and the following unit test:

package com.outpatientservicesllc.adaptors;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.junit.MockitoJUnitRunner;

import java.io.IOException;

@RunWith(MockitoJUnitRunner.class)
public class ANSI837DocumentAdaptorTest {
  private static final String TEST_837_FILE = "src/test/resources/ANSI837.txt";

  @InjectMocks private ANSI837DocumentAdaptor adaptor;

  @Test
  public void testLoadDocument() throws IOException {
    adaptor.loadFile(TEST_837_FILE);
  }
}

But when I attempt to load my test document, I get the following output:

15:48:14.601 [main] DEBUG com.outpatientservicesllc.adaptors.ANSI837DocumentAdaptor - Loading file: src/test/resources/ANSI837.txt
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.thoughtworks.xstream.core.util.Fields (file:/Users/mcpierce/.m2/repository/com/thoughtworks/xstream/xstream/1.4.11.1/xstream-1.4.11.1.jar) to field java.util.TreeMap.comparator
WARNING: Please consider reporting this to the maintainers of com.thoughtworks.xstream.core.util.Fields
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
15:48:15.417 [main] DEBUG com.outpatientservicesllc.adaptors.ANSI837DocumentAdaptor - Processing 0 loops

I don't understand why it says there are 0 loops, which I assume means there is no data (again, no documentation to go by). Am I doing something wrong? I see the file's been loaded, but I don't see any way of getting to the data.

angelaszek commented 4 years ago

It looks like you are constructing the reader and getting the list of loops correctly so it's not clear to me why the list size is 0. We have an X12ReaderTest class that has several examples of reading files and how to get the data. The X12ReaderTest.validate837Valid() method shows how it is getting data from the x12_valid.txt sample file that can be found in the test/resources/837_5010 directory. Hopefully these examples will help.

mcpierce commented 4 years ago

Here is the text that I'm trying to parse. It's a piece of sample data from my client:

ISA*00*          *00*          *  *               *  *               *190108*1501*^*00501*000000002*1*P*:~GS*HC***20190108*1501*190108003*X*005010X222A1~ST*837*0001*005010X222A1~BHT*0019*00*20190108030421*20190108*0304*CH~NM1*41*2*ATHENS DIAGNOSTIC CENTER*****46*~PER*IC*ADC*TE*7063163662~NM1*40*2*BCBS   HMO*****46*~HL*1**20*1~NM1*85*2*ATHENS DIAGNOSTIC CENTER*****XX*1679523708~N3*1063 BAXTER STREET~N4*ATHENS*GA*306069998~REF*EI*582588390~NM1*87*2~N3*PO BOX 933237~N4*ATLANTA*GA*31193~HL*2*1*22*0~SBR*P*18*GA8039H1CS******BL~NM1*IL*1*SIMPSON*BART****MI*STHA111114884~N3*367 CHRISTIAN CHURCH RD~N4*COMER*GA*30629~DMG*D8*19751229*F~NM1*PR*2*BCBS   HMO*****PI*601~N3*PO BOX 9907~N4*COLUMBUS*GA*31908~CLM*OSL97*600***11:B:1*Y*A*Y*Y*P~REF*D9*OSL78~HI*ABK:E042~NM1*DN*1*CLINEY*DUKE****XX*1992861900~NM1*82*1*DEWITTE*JON*J***XX*1760461313~PRV*PE*PXC*2085R0202X~LX*1~SV1*HC:76536*600*UN*1***1~DTP*472*RD8*20190102-20190102~REF*6R*OSL27~SE*33*0001~ST*837*0002*005010X222A1~BHT*0019*00*20190108030421*20190108*0304*CH~NM1*41*2*ATHENS DIAGNOSTIC CENTER*****46*~PER*IC*ADC*TE*7063163662~NM1*40*2*BCBS   PPO*****46*~HL*1**20*1~NM1*85*2*ATHENS DIAGNOSTIC CENTER*****XX*1679523708~N3*1063 BAXTER STREET~N4*ATHENS*GA*306069998~REF*EI*582588390~NM1*87*2~N3*PO BOX 933237~N4*ATLANTA*GA*31193~HL*2*1*22*0~SBR*P*18*GA6140M301******BL~NM1*IL*1*HOLTNER*JACK*J***MI*XKL116A16015~N3*120 CABIN RD~N4*ATHENS*GA*30605~DMG*D8*19670206*F~NM1*PR*2*BCBS   PPO*****PI*601~N3*PO BOX 9907~N4*COLUMBUS*GA*31908~CLM*OSL132*600***11:B:1*Y*A*Y*Y*P~REF*D9*OSL79~HI*ABK:E042~NM1*DN*1*FIRTHNER*MATT*R***XX*1710098496~NM1*82*1*DEWITTE*JON*J***XX*1760461313~PRV*PE*PXC*2085R0202X~LX*1~SV1*HC:76536*600*UN*1***1~DTP*472*RD8*20190102-20190102~REF*6R*OSL33~SE*33*0002~ST*837*0003*005010X222A1~BHT*0019*00*20190108030421*20190108*0304*CH~NM1*41*2*ATHENS DIAGNOSTIC CENTER*****46*~PER*IC*ADC*TE*7063163662~NM1*40*2*BCBS    PATHWAY EXCHANGE*****46*~HL*1**20*1~NM1*85*2*ATHENS DIAGNOSTIC CENTER*****XX*1679523708~N3*1063 BAXTER STREET~N4*ATHENS*GA*306069998~REF*EI*582588390~NM1*87*2~N3*PO BOX 933237~N4*ATLANTA*GA*31193~HL*2*1*22*0~SBR*P*18**BCBS    PATHWAY EXCHANGE*****BL~NM1*IL*1*HENSER*MOND*S***MI*JRQ111M94175~N3*71 FAIR RD~N4*LEXINGTON*GA*30648~DMG*D8*19980603*F~NM1*PR*2*BCBS    PATHWAY EXCHANGE*****PI*00601~N3*PO BOX 9907~N4*COLUMBUS*GA*31908~CLM*OSL104*700***11:B:1*Y*A*Y*Y*P~REF*D9*OSL76~HI*ABK:N911~NM1*DN*1*GUL*AFAQ****XX*1548422280~NM1*82*1*CHERRY*PATRICK*W***XX*1528046877~PRV*PE*PXC*2085R0202X~LX*1~SV1*HC:76830*700*UN*1***1~DTP*472*RD8*20190102-20190102~REF*6R*OSL31~SE*33*0003~ST*837*0004*005010X222A1~BHT*0019*00*20190108030421*20190108*0304*CH~NM1*41*2*ATHENS DIAGNOSTIC CENTER*****46*~PER*IC*ADC*TE*7063163662~NM1*40*2*UHC   UNITED HEALTHCARE MEDICARE D*****46*~HL*1**20*1~NM1*85*2*ATHENS DIAGNOSTIC CENTER*****XX*1679523708~N3*1063 BAXTER STREET~N4*ATHENS*GA*306069998~REF*EI*582588390~NM1*87*2~N3*PO BOX 933237~N4*ATLANTA*GA*31193~HL*2*1*22*0~SBR*P*18*99979******CI~NM1*IL*1*DAVIS*LARRY****MI*911104978~N3*558 ROSCOE ROAD~N4*MONROE*GA*30656~DMG*D8*19560629*M~NM1*PR*2*UHC   UNITED HEALTHCARE MEDICARE D*****PI*87726A~N3*PO BOX 30883~N4*SALT LAKE CITY*UT*84130~CLM*OSL103*800***11:B:1*Y*A*Y*Y*P~REF*D9*OSL77~HI*ABK:N433~NM1*DN*1*SCHWENE*CATNISS*B***XX*1122628127~NM1*82*1*CHERRY*PATRICK*W***XX*1528046877~PRV*PE*PXC*2085R0202X~LX*1~SV1*HC:76870*800*UN*1***1~DTP*472*RD8*20190102-20190102~REF*6R*OSL30~SE*33*0004~GE*4*190108003~IEA*1*000000002~
ctmay4 commented 4 years ago

Please make sure to not post any real names or addresses. If your sample has not been deidentified, please remove it.

mcpierce commented 4 years ago

@ctmay4 Of course. This is scrubbed sample data.

ctmay4 commented 4 years ago

Thanks. Just wanted to make sure.

angelaszek commented 4 years ago

Calling reader.getFatalErrors() reveals that there is a problem with the structure of the file. The messaging is vague and could be improved, however, it looks like ISA07 is missing a code. If a segment is missing one of the required codes then it's not able to be validated and the parsing fails. The list of required codes for ISA07 (an all other elements) can be found in resources/mapping/837.5010.X222.A1.xml

Once I changed that first segment I was able to read the file. An example of the updated line is below. Note that I added in 01 in the 7th element.

ISA*00* *00* * * *01* *190108*1501*^*00501*000000002*1*P*:~

mcpierce commented 4 years ago

Okay, thank you. So it was definitely a case of the testing data was malform?

angelaszek commented 4 years ago

Yes, once I made that change I was able to extract values from the file similar to the unit tests.

mcpierce commented 4 years ago

Very good. Closing this issue as not a bug.