-
Notifications
You must be signed in to change notification settings - Fork 87
Description
When instantiating a Message, a sequence can be passed to the constructor, but this sequence must be formed in a very specific way, else the Message instance is functionally unusable (though will still be converted to a valid HL7 message when called within str(), and will still be accepted by remote MLLP systems when sent via the built-in client).
It appears that the sequence format that the Message expects to hold would be of/similar to this format :
Message(
sequence=[
Segment(
sequence=[
Field(
sequence=[str]
# OR
[Repetition(
sequence=[
Component(sequence=[str])
]
)]
)
]
)
]
) Intuitively, it should be possible to pass a list[str] to Segment(sequence=) in the same way that it can be with Field() (especially with segments like “MSH” where nearly all fields are typically single-level). However, if a list[str] is passed to Segment instead of a list[Field], several of the Message class’s methods break—they appear to be reliant on Message.segments(), which expects the internal sequence be represented as a list[list[…]]. Message.extract_field() is an example of this; interestingly, Segment.extract_field() does work regardless of how the Segment is instatiated.
It would be strongly preferred if:
- Constructors for all
Containersubclasses above the lowest level detect if alist[str]is passed insequence=, then automatically parse to a compatible structure (much safer). - Methods like
Message.segments()are adjusted to remove reliance on nested sequences.