Esempio n. 1
0
        private static void TestExtensionMethods()
        {
            if (parsedMessages.Count > 0)
            {
                Console.WriteLine("\n==============================================\nTesting extension methods on ADT_A08 (HL7 V2.3) messages.");

                List <IMessage> a08 = parsedMessages.Where(im => (im.Version == "2.3") && (im.GetStructureName() == "ADT_A08")).ToList();
                Console.WriteLine("\nFound {0} A08 messages.", a08.Count());

                // Compare messages
                Console.WriteLine("");
                Console.WriteLine("Compare A08 messages.");
                Console.WriteLine("A08_1 {0} A08_1.", a08[0].IsEqual(a08[0]) ? "is the same as" : "isn't the same as");
                Console.WriteLine("A08_1 {0} A08_2.", a08[0].IsEqual(a08[1]) ? "is the same as" : "isn't the same as");

                // Compare segments
                ISegment s1 = (ISegment)a08[0].GetStructure("PID");
                ISegment s2 = (ISegment)a08[1].GetStructure("PID");
                Console.WriteLine("");
                Console.WriteLine("Compare PID segments.");
                Console.WriteLine("PID1 {0} PID1.", s1.IsEqual(s1) ? "is the same as" : "isn't the same as");
                Console.WriteLine("PID1 {0} PID2.", s1.IsEqual(s2) ? "is the same as" : "isn't the same as");
                Console.WriteLine("");

                ADT_A08 a08msg = null;
                foreach (IMessage msg in a08)
                {
                    a08msg = (ADT_A08)msg;
                    Console.WriteLine("Getting address from message.");

                    foreach (XAD xad in a08msg.PID.GetPatientAddressRecords())
                    {
                        string x = xad.StreetAddress.Value;
                        Console.WriteLine("Found street record '{0}'.", x);
                    }
                }

                if (a08msg != null)
                {
                    Console.WriteLine("Testing Add method.");
                    int x = a08msg.PID.PatientAddressRepetitionsUsed;
                    Console.WriteLine("Message has {0} PatientAddress record(s).", x);

                    Console.WriteLine("Adding record.");
                    a08msg.PID.AddPatientAddress();
                    Console.Write("Message has {0} PatientAddress record(s): ", a08msg.PID.PatientAddressRepetitionsUsed);
                    if ((a08msg.PID.PatientAddressRepetitionsUsed - x) == 1)
                    {
                        Console.WriteLine("OK!");
                    }
                    else
                    {
                        Console.WriteLine("Failure!");
                    }
                }

                Console.WriteLine("\nDone!");
            }
        }