Search code examples
javaxmledismooks

Smooks EDI Parsing - Repeated Segments


I'm trying to build a generic EDI parser that can handle when any situational segments are not present in a given file. This was easy enough using the minOccurs="0" attribute in the XML mapping, however I'm struggling to figure out how to handle this when multiple segments repeat with the same tag. For example:

CAS*PR*1*793~
NM1*QC*1*SHEPHARD*SAM*O***HN*666666666A~    --PatientName
NM1*IL*1*SHEPARD*JESSICA****HN*999887777A~  --InsuredName
MIA*0***138018.4~

Mapped using the following XML:

<medi:segment segcode="NM1" xmltag="PatientNameSegment" minOccurs="0" truncatable="true">
    <medi:field xmltag="EntityIdentifierCode" />
    <medi:field xmltag="EntityTypeQualifier" />
    <medi:field xmltag="LastName" />
    <medi:field xmltag="FirstName" />
    <medi:field xmltag="MiddleName" />
    <medi:field xmltag="NamePrefix" />
    <medi:field xmltag="NameSuffix" />
    <medi:field xmltag="IdentificationCodeQualifer" />
    <medi:field xmltag="IdentificationCode" />
</medi:segment>
<medi:segment segcode="NM1" xmltag="InsuredNameSegment" minOccurs="0" truncatable="true">
    <medi:field xmltag="EntityIdentifierCode" />
    <medi:field xmltag="EntityTypeQualifier" />
    <medi:field xmltag="LastName" />
    <medi:field xmltag="FirstName" />
    <medi:field xmltag="MiddleName" />
    <medi:field xmltag="NamePrefix" />
    <medi:field xmltag="NameSuffix" />
    <medi:field xmltag="IdentificationCodeQualifer" />
    <medi:field xmltag="IdentificationCode" />
</medi:segment>

But when the first line for patient name is removed from the input file, it will just load the insured name into the patient name and skip loading the insured name rather than leaving patient name blank.

Basically, what I'd like is equivalent of specifying "NM1*QC" as the segcode (as actually setting it to that kills the parser). I see that the Smooks documentation allows for regex matching as well but I'm not sure to what it is compared and have not had luck experimenting with it yet.

Thanks!


Solution

  • You need to make your parser qualifier (the QC and IL in first element) aware. I dont know if and how this is done with your specific product, but I am quite sure it is a basic requirement normally. A five second google tells me you could use segcode="NM1\*IL.*" but I doubt this is the right way to do it.