senaranya/HL7

Wrong segment index values when multiple messages are created

senaranya opened this issue · 1 comments

The segment classes use static properties to maintain segment-index. This is required as one can add new segments to a given message object and expect the index to auto-increment. The side-effect to this is, if you create a second message, adding the same segments will now start indexing from their index in the last message instead of 1! This happens because static properties are class properties, not object ones, and thus shared across all objects.

To counter this, add a 4th argument in message constructor, and expose a public method resetSegmentIndices(). Users should be able to use one of these to reset segment indices to 1.

Fixed at release 1.7.0