/// <summary>
        /// Create and return Validation Test Object of the passed-in Type.
        /// </summary>
        /// <param name="specType">Specification Type</param>
        /// <returns>Instance of the passed class that implements the IValidationTest Interface</returns>
        /// <remarks>Implements Abstract Factory Pattern</remarks>
        public static IValidationTest Create(SpecificationType specType)
        {
            IValidationTest testInstance = null;

            switch (specType)
            {
            case SpecificationType.GP2GP:
                testInstance = new Gp2Gp();
                break;

            case SpecificationType.ePrescribing:
                testInstance = new ePrescription();
                break;

            case SpecificationType.eDischargeSummary:
                testInstance = new eDischargeSummary();
                break;

            case SpecificationType.PharmacyHealthSummary:
                testInstance = new PharmacyHealthSummary();
                break;

            case SpecificationType.CdaTemplates:
                testInstance = new CdaTemplates();
                break;

            case SpecificationType.InterRaiCommunityHealth:
                testInstance = new InterRaiCommunityHealth();
                break;

            case SpecificationType.InterRaiHomeCare:
                testInstance = new InterRaiHomeCare();
                break;

            case SpecificationType.InterRaiLongTermCareFacility:
                testInstance = new InterRaiLongTermCareFacility();
                break;

            case SpecificationType.InterRaiContact:
                testInstance = new InterRaiContact();
                break;

            case SpecificationType.GP2GPV2:
                testInstance = new Gp2Gpv2();
                break;

            default:
                testInstance = null;
                break;
            }

            return(testInstance);
        }
예제 #2
0
        static internal string GetSpecificationInstance(SpecificationType specType)
        {
            string specInstance = string.Empty;

            // determine name of Test Instance File & check that it exists
            IValidationTest testInstance = ValidationTestFactory.Create(specType);

            // safest way to get to Test Files folder (under bin folder) in all environments
            string fileFullName = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath) + @"\Test Files\" + testInstance.testFileName + testInstance.testFileExtension;

            if (!File.Exists(fileFullName))
            {
                throw new Exception("Test Instance (" + testInstance.testFileName + ") Not Found");
            }

            // read the file into a string
            using (StreamReader sr = File.OpenText(fileFullName))
            {
                specInstance = sr.ReadToEnd();
            }

            return(specInstance);
        }
예제 #3
0
        static internal List <string> Validate(SpecificationType specType, string testData)
        {
            List <string> validationResults = new List <string>();

            string encryptionKey = "GP2GPzENCRYPTION";
            string fileFullName  = string.Empty;

            // create Test Instance
            IValidationTest testInstance = ValidationTestFactory.Create(specType);

            try
            {
                // validate transport format
                string fileHeader     = testData.Substring(0, 10).ToUpper();
                bool   validTransport = true;

                if (testInstance.transportFormatType == FormatType.XML || testInstance.transportFormatType == FormatType.XML_NZEPS)
                {
                    validTransport = fileHeader.StartsWith(@"<?XML ");
                }
                else if (testInstance.transportFormatType == FormatType.HL7v2)
                {
                    validTransport = fileHeader.StartsWith(@"MSH|^~\&|");
                }

                if (!validTransport)
                {
                    validationResults.Add("TRANSPORT : Fail");
                    validationResults.Add("Invalid Message File Format : specification requires " + testInstance.transportFormatType.ToString());
                    validationResults.Add("FORMAT : ???");
                    validationResults.Add("Unable to validate");
                    validationResults.Add("DATA : ???");
                    validationResults.Add("Unable to validate");
                }
                else
                {
                    validationResults.Add("TRANSPORT : Pass");
                    // create temporary test file (this is supported from Windows Azure Role)
                    fileFullName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + testInstance.testFileExtension;

                    // write the test data string to the temporary test file (required for Toolkit message consumption)
                    using (StreamWriter sw = new StreamWriter(fileFullName))
                    {
                        sw.Write(testData);
                    }

                    // call test instance validate method for Format and Data checks
                    validationResults.AddRange(testInstance.ValidateTestInstance(fileFullName, encryptionKey));
                }
            }
            finally
            {
                // delete temporary test file
                if (File.Exists(fileFullName))
                {
                    File.Delete(fileFullName);
                }
            }

            return(validationResults);
        }