Example code
Edwardiv1 opened this issue · 3 comments
Edwardiv1 commented
Hi, is there any example code for creating X12 837 5010 data (or anything else really that shows how to use the library)?
Thanks
angelaszek commented
Here is a sample file with some example code about how one could use the library to read it. I hope this helps.
--Sorry, I forgot to mention that this library supports reading and parsing X12 837 5010 data (as well as some other versions). It doesn't create them.
public class TestClaimLab {
public static void main(String[] args) throws Exception {
// create the reader
X12Reader reader = new X12Reader(X12Reader.FileType.ANSI837_5010_X222, new File("path-to-file\\sample-claim-github.txt"));
if(reader.getErrors().isEmpty())
System.out.println("NO ERRORS!");
// working with loops (printing IDs to keep the output more readable)
System.out.println("GET LOOP ID: " + reader.getLoop().getId());
System.out.println("GET LOOP FROM WITHIN STRUCTURE: " + reader.getLoop().getLoop("2010BA").getId());
System.out.println("GET PARENT LOOP: " + reader.getLoop().getLoop("2010BA").getParent().getId());
System.out.println("GET LOOP BY INDEX (in the event loop occurs multiple times): " + reader.getLoop().getLoop("2000B", 0).getId());
// you can get lists of loops, segments and elements too loop over (printing IDs to keep the output more readable)
System.out.println("GET LIST OF SUBLOOPS: " + reader.getLoop().getLoop("2000A").getLoops().stream().map(Loop::getId).collect(Collectors.toList()));
System.out.println("GET LIST OF SEGMENTS WITHIN LOOP: " + reader.getLoop().getLoop("2010AA").getSegments().stream().map(Segment::getId).collect(Collectors.toList()));
System.out.println("GET LIST OF ELEMENTS WITHIN SEGMENT: " + reader.getLoop().getLoop("2010AA").getSegment("NM1").getElements().stream().map(Element::getId).collect(Collectors.toList()));
// get specific values from a subloop
System.out.println("GET SPECIFIC FIELD: " + reader.getLoop().getLoop("2000A").getElement("2010AA", "NM1", "NM103"));
System.out.println("GET SPECIFIC FIELD: " + reader.getLoop().getLoop("2000A", 0).getElement("2010AA", "NM1", "NM103"));
System.out.println("GET SPECIFIC FIELD: " + reader.getLoop().getLoop("2000A").getLoop("2010AA", 0).getSegment("PER", 1). getElement("PER04"));
System.out.println("GET COMPOSITE ELEMENT: " + reader.getLoop().getLoop("2300").getSegment("CLM").getElement("CLM05").getSubElement(1));
// get separators from file
System.out.println("GET SEGMENT SEPARATOR: " + reader.getLoop().getSeparators().getSegment());
System.out.println("GET ELEMENT SEPARATOR: " + reader.getLoop().getSeparators().getElement());
System.out.println("GET COMPOSITE ELEMENT SEPARATOR: " + reader.getLoop().getSeparators().getCompositeElement());
}
}
AswiniBhuvanesh commented
Hi
Is there any sample to refer for EDI Writer
angelaszek commented
We don't have any samples that refer to EDI writer. We just have samples of how this library can be used to process X12 files.