Accessing Loaded EDI Data – JS

Index

    Accessing Loaded EDI Data

    Because EDIValidator creates an EDILightWeightDocument after validation, consuming EDI data is done the same way as getting data from the EDILightWeightDocuments.

    Example

    validator.validate();
    //Get the EDI document loaded into memory
    let loadedEDIFile = validator.EDILightWeightDocument;
    //Get EDI Data
    let stTransaction = loadedEDIFile.Loops.getItem(0).getLoop(“INTERCHANGE HEADER/FUNCTIONAL GROUP/ST HEADER”)
    let stSegment = stTransaction.getSegment(“ST”);
    let ediData = “”;
    ediData += “Transaction Name = ” + stSegment.Name + “\n”;
    ediData += “Transaction Number = ” + stSegment.Elements.getItem(1).DataValue + “\n”;
    ediData += “Transaction Impl = ” + stSegment.Elements.getItem(2).DataValue + “\n”;
    ediData += “\n”;
    //Get all billing providers
    let billingProviderLoops = stTransaction.getLoops(“2000A”);
           
    for(let i=0;i < billingProviderLoops.Count;i++)
    {
        //Get billing provider name
        let billingProviderLoop = billingProviderLoops.getItem(i).getLoop(“2010AA”);
        let billingProviderNameSegment = billingProviderLoop.getSegment(“NM1”);
        ediData += “Billing Provider = ” + billingProviderNameSegment.Elements.getItem(2).DataValue+ “\n”;
        //Get subscriber name
        let subscriberLoop = billingProviderLoops.getItem(i).getLoop(“2000B/2010BA”);
        let subscriberNameSegment = subscriberLoop.getSegment(“NM1”);
        ediData += “Subscriber Name = ” + subscriberNameSegment.Elements.getItem(2).DataValue+ “\n”;
        //Get the claim loop
        let claimLoop = billingProviderLoops.getItem(i).getLoop(“2000B/2300”);
        if (claimLoop == null){
            claimLoop = billingProviderLoops.getItem(i).getLoop(“2000B/2000C/2300”);
        }
        let claimSegment = claimLoop.getSegment(“CLM”);
        ediData += “Claim ID = ” + claimSegment.Elements.getItem(0).DataValue + “\n”;
        ediData += “Claim Price = ” + claimSegment.Elements.getItem(1).DataValue + “\n”;
             
        let serviceLoops = claimLoop.getLoops(“2400”);
        for(let j=0;j < serviceLoops.Count;j++)
        {
            let serviceSegment = serviceLoops.getItem(j).getSegment(“SV2”);
            ediData += “Service Price= ” + serviceSegment.Elements.getItem(2).DataValue+ “\n”;
        }
        ediData += “\n\n”;
    }
    console.log(ediData);
     

    Output

    in EDI Validator – JS
    Did this article answer your question?