• Inner Harbour Software

    Inner Harbour Software consists of a dedicated team of .Net programmers whose mission is to create exceptional and affordable HL7 products. Please email us at support@HL7Spy.com to contact us with questions regarding our products or services.
  • Home
  • /HL7 Code
  • /How do I find all A14 messages that do not have a matching A05?

How do I find all A14 messages that do not have a matching A05?


Thanks for making such a great product. 🙂 Question, I have two tabs open with ADT messages. I need to do a query to see what patients are in the first tab and are not in the second. There is not select Join type function supported. My first tab is A04’s and the second is A14’s. Need to know which A04’s don’t have my patient in the A14’s list.

I send a quick registration (A14) to a system that returns a A05 (or it should).  I need to know when an A05 is not returned for an A14.  The field I am actually matching on is PV1-50 (we put special IDs there).


Thank you for being a supportive customer.
The only way I can think of doing this is to merge the two tabs into a single tab and write a Custom Code function to perform the analysis. See my solution below.

private string _fileName = @"C:\temp\results.txt";
private class TrackedItem
   public int Index {get;set;}
   public string AlternateVisitNumber {get;set;}
   public string MessageControlId {get;set;}

Dictionary<string,TrackedItem> _a14s = new Dictionary<string,TrackedItem>(StringComparer.CurrentCultureIgnoreCase);
Dictionary<string,TrackedItem> _a05s = new Dictionary<string,TrackedItem>(StringComparer.CurrentCultureIgnoreCase);

public override void Run()
  // Get an HL7 Message in parsed format
  Hl7Message message = GetParsedMessage();
  var pv1 = message.GetFirstSegment<PV1>();
  if(pv1 == null)
    return; // no PV1 segment

  Dictionary<string,TrackedItem> collection=null;
  collection = _a14s;
  } else if(message.TriggerEvent=="A05")
    collection = _a05s;

  if(collection == null)
    return; // not an A05, or A04 message

  TrackedItem item=null;
  if(!collection.TryGetValue(pv1.AlternateVisitID_50.IDNumber_01.Value, out item))
    // remember information about the message
   item = new TrackedItem
            Index = MessageIndex,
            AlternateVisitNumber = pv1.AlternateVisitID_50.IDNumber_01.Value,
            MessageControlId = message.MSH.MessageControlID_10.Value,
    collection.Add(pv1.AlternateVisitID_50.IDNumber_01.Value, item);

// this is called at the very end
public override void OnFinish()
  using(var stream = new System.IO.StreamWriter(_fileName))
    stream.WriteLine("A14s without a matching A05");
    ExportDiff(stream, _a14s, _a05s);
    stream.WriteLine("A05s without a matching A14");
    ExportDiff(stream, _a05s, _a14s);
  } catch{}

// show the difference between two collections
private void ExportDiff(StreamWriter writer, Dictionary<string,TrackedItem> collection1, Dictionary<string,TrackedItem> collection2)
  foreach(TrackedItem item in collection1.Values.OrderBy(i=>i.Index))
      writer.Write(" ");
      writer.Write(" ");