aaronhuggins / node-x12

ASC X12 parser, generator, query engine, and mapper; now with support for streams.
https://aaronhuggins.github.io/node-x12/
MIT License
52 stars 13 forks source link

Parse repeating HL blocks #17

Closed boxfoot closed 3 years ago

boxfoot commented 4 years ago

Hi,

This library is fantastic -- thank you! I am trying to use it to parse an EDI document and having trouble figuring out how to deal with repeating HL blocks.

Let's say somewhere in my document I have this sequence (contrived example, and this is the 278 transaction set)

HL*5*4*EV*1~
TRN*1*8610133036628200*1411289245~
TRN*2*040601002349C*9000012121~
HL*6*5*SS*0~
SV2**HC:65270:::::Repair of laceration; conjunctiva, with or without nonperforating laceration scl~
HL*7*5*SS*0~
SV2**HC:21175:::::Reconstruction, bifrontal, superior-lateral orbital rims and lower forehead, adv~
HL*8*4*EV*1~
TRN*1*8610133036628117*1411289245~
TRN*2*040601002349A*9000012121~
HL*9*8*SS*0~
SV2**HC:65270:::::Repair of laceration; conjunctiva, with or without nonperforating laceration scl~
HL*10*8*SS*0~
SV2**HC:21175:::::Reconstruction, bifrontal, superior-lateral orbital rims and lower forehead, adv~
HL*11*8*SS*0~

I would like to transform this into something like:

events: 
  [ {
    trns: 'FOREACH(TRN)=>HL+EV-TRN02', // I want this to just have the 2 TRNS from the first HL+EV but it has all 4
    lines: [
        { code: 'FOREACH(SV2)=>HL+EV+SS-SV202' }, // I want to (1) grab just the HL+SS for the first HL+EV but can't, also I want to parse the SS blocks into their own objects, not just a flat array  
    ]
},
{  // this objet would have the info from the second HL+EV
    trns: [ ], 
    lines: [
        { code: }
   ]
}]

Do you have any suggestions for how to parse in this way? Thank you.

fpw23 commented 4 years ago

@boxfoot I recently forked this project and tried to add support for what you are trying to do I think. I work in the medical EDI arena as well and have to parse 270/271 276/277 and 835. My solution involved adding a new macro called FORSEGLOOP which I semi documented here in the pull request. I also made a POC for testing it out here. You can find the source for it all here.

This all lead me to posting this new issue asking if there is any interest in making a micro service with a UI that utilizes this library via dynamic scripts. In my project at work I am at the point where we tested out all the generation and parsing scripts we need and now it is time to add to our main code. Unfortunately my CEO is short sided and can't see the vision so he wants me to directly embed the parsing and generating instead of building out a microservice. Maybe I am wrong and I just don't know how devs use EDI but my belief is that it would make more sense to have a simple drop in microservice instead of imbedding it. What are your thoughts?

ahuggins-nhs commented 4 years ago

@fpw23 Thanks for responding.

@boxfoot Sorry for not getting back to you on this, I've had my head underwater with projects related to AS2 protocol and JSON and haven't paid attention to EDI issues. I think @fpw23 is spot on, FORSEGLOOP is a great addition.

ahuggins-nhs commented 3 years ago

Closing, as work will eventually continue in the JS-EDI project.

Element selector language has been significantly enhanced to cover this use case.

https://github.com/ahuggins-nhs/js-edi/blob/main/packages/dom/query/README.md#hierarchical-level-selector

https://github.com/ahuggins-nhs/js-edi/blob/main/packages/dom/query/README.md#loop-selector