How to change order of custom segments?

Help
miller50
2010-11-23
2013-05-13
  • miller50
    miller50
    2010-11-23

    I am using the addNonstandardSegment() method to create additional segments to the the message. These custom segments are repeating. This part appears to be working. However when the message is encoded back into a string, the custom segments are grouped instead of being in sequential order based on their creation. The message is actually encoded as:

    MSH, MSA, PID, PID, PID, PV1, PV1, PV1

    what I would like instead is:

    MSH, MSA, PID, PV1, PID, PV1, PID, PV1

    so the pattern should have each additional PV1 segment sequentially follow each additional corresponding PID segment.

    Here is my code that creates the custom segments:

    message constructor

            public PatientDemographicsQuery(string rawMessage, bool reponseMessageRequired)
                : base(rawMessage, reponseMessageRequired)
            {
                RSP_K21 = new NHapi.Model.V24.Message.RSP_K21();
                RSP_K21.addNonstandardSegment("PID");
                RSP_K21.addNonstandardSegment("PV1");
               …

    ---------BELOW METHODS CALLED INSIDE LOOP---------

    PID segment creation

            private void GeneratePIDSegment(int patientIndex)
            {
                PID pidSegment = (PID)RSP_K21.GetStructure("PID", patientIndex);
              
                /// PID-5
                // last name
                pidSegment.GetPatientName(0).FamilyName.Surname.Value = PatientList.LastName;

                // first name
                pidSegment.GetPatientName(0).GivenName.Value = PatientList.FirstName;

                etc…

    PV1 segment creation

           private void GeneratePV1Segment(int patientIndex)
            {
                PV1 pv1Segment = (PV1)RSP_K21.GetStructure("PV1", patientIndex);

                pv1Segment.AssignedPatientLocation.Room.Value = PatientList.RoomNumber;
                pv1Segment.AssignedPatientLocation.Bed.Value = PatientList.Bed;

                etc…
    ---------ABOVE METHODS CALLED INSIDE LOOP---------

    message encoding

            protected string EncodeMessageResponse(IMessage message)    // rsp message passed in
            {
                String encodedMessage = null;

                try
                {
                    PipeParser parser = new PipeParser();
                    encodedMessage = parser.Encode(message);               
                }
                catch (Exception e)
                {
                …

     
  • I think you might have to create a "group" message and then add the group as a non standard segment.  The group type should help to keep the PID and PV1 grouped together.  Take a look at the source code and look inside the Group namespace.  You should see examples there.