Beispiel #1
0
 private void ReloadTagsFor(PrescriptionDocument prescriptionDocument)
 {
     foreach (var prescripiton in prescriptionDocument.Prescriptions)
     {
         if (prescripiton.Tag != null)
         {
             prescripiton.Tag = (from t in this.Session.Query <Tag>()
                                 where t.Id == prescripiton.Tag.Id
                                 select t).First();
         }
         prescripiton.Drug = this.Session.Get <Drug>(prescripiton.Drug.Id);
     }
 }
        public List <string> ValidateTestInstance(string testFileName, string encryptionKey)
        {
            List <string> validationResults       = new List <string>();
            List <string> formatValidationResults = new List <string>();
            List <string> dataValidationResults   = new List <string>();
            string        templateID = string.Empty;

            // NZePS Schema Validation (not part of Toolkit)
            formatValidationResults.AddRange(ValidateNZePS(testFileName));

            // create instance of ePrescribing messaging class and use it to consume test data
            SimplMessageCodec    msg = new SimplMessageCodec();
            PrescriptionDocument pd  = new PrescriptionDocument();

            try
            {
                string testData = string.Empty;

                // read the file into a string as Toolkit does not create message files for NZePS
                using (StreamReader sr = File.OpenText(testFileName))
                {
                    testData = sr.ReadToEnd();
                }

                msg.encryptionKey = encryptionKey;
                msg.AddMessage(testData);

                // process transport message & add any message-related errors to list
                try
                {
                    msg.ConsumeIncomingMessage();
                    formatValidationResults.AddRange(msg.errors);
                }
                catch (Exception exFormat)
                {
                    formatValidationResults.Add("Exception : " + exFormat.Message);
                }

                // extract & validate CDA - add any errors to list
                try
                {
                    pd = msg.prescriptionDocument;

                    foreach (Template tmpl in pd.templates)
                    {
                        templateID = tmpl.oid;
                        if (templateID == this.documentTemplate)
                        {
                            break;
                        }
                    }

                    if (templateID != this.documentTemplate)
                    {
                        formatValidationResults.Add("Invalid Document Template ID " + templateID + " : expected " + this.documentTemplate);
                    }
                    else
                    {
                        pd.ValidateSchema(Specification.GetSchemaLocation());
                        formatValidationResults.AddRange(pd.schemaErrors);

                        pd.Validate();
                        dataValidationResults.AddRange(pd.allErrors);
                    }
                }
                catch (Exception exData)
                {
                    dataValidationResults.Add("Exception : " + exData.Message);
                }
            }
            catch (Exception ex)
            {
                formatValidationResults.Add("Exception : " + ex.Message);
                dataValidationResults.Add("Unable to validate due to formatting exception(s)");
            }
            finally
            {
                msg = null;
                pd  = null;
            }

            validationResults.Add("FORMAT : " + (formatValidationResults.Count < 1 ? "Pass" : "Fail"));
            validationResults.AddRange(formatValidationResults);
            validationResults.Add("DATA : " + (dataValidationResults.Count < 1 ? "Pass" : "Fail"));
            validationResults.AddRange(dataValidationResults);

            return(validationResults);
        }