Closed jf-tech closed 1 year ago
Patch coverage: 100.00%
and no project coverage change.
Comparison is base (
9e0c8da
) 100.00% compared to head (80b2ff2
) 100.00%.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Issue: https://github.com/jf-tech/omniparser/issues/212
repetition_delimiter
: delimiter to separate multiple data instances for an element. For example, if^
is the repetition delimiter for a segmentDMG*D8*19690815*M**A^B^C^D~
, then the last element has 4 pieces of data:A
,B
,C
, andD
. Any element withoutrepetition_delimiter
present has essentially one piece of data; similarly, if^
is the repetition delimiter for a segmentCLM*A37YH556*500***11:B:1^12:B:2~
, the last element has 2 pieces of data:11:B:1
and12:B:2
, each of which is further delimited by acomponent_delimiter
:
. Note, sincerepetition_delimiter
creates multiple pieces of data under the same element name in the schema, in most cases the suitable construct type intransform_declarations
isarray
.Currently we read in all the elements and their components in serial in
NonValidatingReader
into a slice:[]RawSegElem
, each of which contains the element value, the element index, and component index if there are more than 1 component. Whenrepetition_delimiter
is added, we continue down the same pattern:NonValidatingReader
still reads everything into the slice, except now, there potentially can be multipleRawSegElem
share the sameElemIndex
andCompIndex
.Using the example above:
^
is the rep delim and seg isCLM*A37YH556*500***11:B:1^12:B:2~
. AfterNonValidatingReader.Read()
is done, we'll have the following[]RawSegElem
(simplified):Note the last 3 elements have the same
ElemIndex
andCompIndex
as the previous 3 elements. This behavior is new and introduced in this PR.Now on the EDI reader side (reader.go), previously when we match element decl against the raw element slice, we only do one way scan, because
ElemIndex
andCompIndex
are always increase, thus we never need to back-scan. With introduction of potentially duplicateElemIndex
andCompIndex
, now for each of the element decl, we simply do a full[]RawSegElem
scan. Yes, it is a bit more expensive but given usually the number of total elements and components in a seg is really really small (around 20), we feel this trade-off is acceptable without making the already-complex code even more so.With this reader change, the IDR produced will potentially contain child element nodes with the same element name. Thus in schema writing, it's practically required that the user of the
repetition_delimiter
feature needs to usearray
type in thetransform_declarations
.