HL7 and Z-Segments

Post author
Iroberts80

Hello,  I was testing out the HL7.NET demo software and I cant seem to figure out how to read Custom Z segments to HL7 messages.  My ADTA31 message format is as follows:
MSH
EVN
PID
ZPI   <--85 Data elements in this segment
ZCN <-- this is a loop, around 30 data elements per segment
OBX
ZID

When i try to read the file i get a "Unexpected Segment ZPI at Pos 4".  I have attempted to make a custom object and still no luck.


string hl7template = "EdiFabric.Templates.Hl7";
//using (var reader = new Hl7Reader(path, (FHS fhs, BHS bhs, MSH msh) => typeof(TSADTA31Add).GetTypeInfo()))
using (var reader = new Hl7Reader(path, (FHS fhs, BHS bhs, MSH msh) => typeof(TSADTA31Add).GetTypeInfo()))
{
ediItems = reader.ReadToEnd().ToList();
}

[Serializable()]
[DataContract()]
[Message("HL7", "TSADTA31")]
public class TSADTA31Add : TSADTA31
{
[DataMember]
[Pos(4)]
public ZPI ZPI { get; set; }
[DataMember]
[Pos(5)]
public ZCN ZCN { get; set; }




}


[Serializable()]
[DataContract]
[Segment("ZPI")]
public class ZPI
{
// Change the comment from repeatable to single, with maximum length of 10 characters
[StringLength(1, 10)]
[DataElement("00098", typeof(HL7_AN))]
[DataMember]
[Pos(1)]
public new string Comment_03 { get; set; }
}
[Serializable()]
[DataContract]
[Segment("ZCN")]
public class ZCN
{
// Change the comment from repeatable to single, with maximum length of 10 characters
[StringLength(1, 10)]
[DataElement("00098", typeof(HL7_AN))]
[DataMember]
[Pos(1)]
public new string Comment_03 { get; set; }
}

Comments

2 comments

  • Comment author
    Admin

    Hello,

    This is the correct way to create your own segments, a couple of suggestions though:

    1. Omit the "new" keyword from the properties.

    2. When you are overriding positions, e.g., adding segments in between other segments, ensure that the positions do not overlap. In your case, change all positions from position 4 onwards to increment with 2 (the number of segments you are adding between), e.g. EVN moves to position 6

    [Pos(6)]
    public virtual EVN EVN { get; set; }

    PID to position 7, and so forth:

    [Pos(7)]
    public virtual PID PID { get; set; }

    This is in the base TSADTA31 class. Then on the derived class, add the ZPI and ZCN exactly as they are in your pseudo code.

    3. A segment loop means that the whole segment repeats multiple times, e.g. ZCN will repeat 30 times, like this:

    ZCN...
    ZCN...
    ZCN...

    In that case, you need to create it as a List, like this:

    [DataMember]
    [Pos(5)]
    public List<ZCN> ZCN { get; set; }

    , and add a maximum constraint if you want this validated, like this:

    [DataMember]
    [ListCount(30)]
    [Pos(5)]
    public List<ZCN> ZCN { get; set; }

    Let me know if it worked.

    1
  • Comment author
    Iroberts80

    Thank you so much! This helped out and now i can consume the Z-Segments!

    0

Please sign in to leave a comment.