WriteProcessingInstruction() public abstract method

public abstract WriteProcessingInstruction ( string name, string text ) : void
name string
text string
return void
Example #1
0
        public void WriteResponseMessage ( XmlWriter writer, string innerXml, NuxleusAsyncResult asyncResult ) {

            using (writer) {
                writer.WriteStartDocument();
                if (m_responseType == ResponseType.REDIRECT) {
                    writer.WriteProcessingInstruction("xml-stylesheet", "type='text/xsl' href='/service/transform/openid-redirect.xsl'");
                }
                writer.WriteStartElement("auth");
                writer.WriteAttributeString("xml:base", "http://dev.amp.fm/");
                writer.WriteAttributeString("status", m_status);
                if (m_responseType == ResponseType.REDIRECT) {
                    writer.WriteElementString("url", "http://dev.amp.fm/");
                }
                if (m_responseType == ResponseType.QUERY_RESPONSE && innerXml != null) {
                    writer.WriteStartElement("response");
                    writer.WriteRaw(innerXml);
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
                writer.WriteEndDocument();
            }

            asyncResult.CompleteCall();

        }
 private static void WriteNode(XmlReader reader, XmlWriter writer)
 {
     while (reader.Read())
     {
         switch (reader.NodeType)
         {
         case XmlNodeType.Element:
             writer.WriteStartElement(reader.Name);
             break;
         case XmlNodeType.Text:
             writer.WriteString(reader.Value);
             break;
         case XmlNodeType.CDATA:
             writer.WriteCData(reader.Value);
             break;
         case XmlNodeType.ProcessingInstruction:
             writer.WriteProcessingInstruction(reader.Name, reader.Value);
             break;
         case XmlNodeType.Comment:
             writer.WriteComment(reader.Value);
             break;
         case XmlNodeType.XmlDeclaration:
             break;
         case XmlNodeType.Document:
             break;
         case XmlNodeType.DocumentType:
             break;
         case XmlNodeType.EntityReference:
             break;
         case XmlNodeType.EndElement:
             writer.WriteEndElement();
             break;
         }
     }
 }
 public override void WriteTo(XmlWriter writer)
 {
     if (writer == null)
     {
         throw new ArgumentNullException("writer");
     }
     writer.WriteProcessingInstruction(this.target, this.data);
 }
Example #4
0
        public bool writePi(string target, string content)
        {
            if (_state.Count != 0)
            {
                return(false);
            }

            return(CheckedCall(() => _writer.WriteProcessingInstruction(target, content)));
        }
 private static void WriteIncludes(LocalizationDictionary dictionary, XmlWriter writer) {
   foreach(var include in dictionary.Includes) {
     var data = "include=\""+include.Path+"\"";
     if(!String.IsNullOrEmpty(include.Prefix)) {
       data += " prefix=\""+include.Prefix+"\"";
     }
     writer.WriteProcessingInstruction("mios-localization", data);
   }
 }
        public void WriteStartDocument()
        {
            if (_writer == null)
            {
                throw new InvalidOperationException("Cannot write after closing.");
            }

            _writer.WriteProcessingInstruction("mso-application", "progid=\"Excel.Sheet\"");
            _writer.WriteStartElement("ss", "Workbook", "urn:schemas-microsoft-com:office:spreadsheet");
            WriteExcelStyles();
        }
        /// <summary>
        /// Saves the current node to the specified XmlWriter.
        /// </summary>
        /// <param name="writer">The XmlWriter to which you want to save.</param>
        public override void WriteTo(XmlWriter writer)
        {
            writer.WriteProcessingInstruction("xml", string.Format("version=\"1.0\" encoding=\"{0}\"", EncodingName()));

            if (HasChildNodes)
            {
                foreach (HtmlNode subnode in ChildNodes)
                {
                    subnode.WriteTo(writer);
                }
            }
        }
Example #8
0
        private static void WriteShallowNode(XmlReader reader, XmlWriter writer)
        {
            switch (reader.NodeType)
            {
                case XmlNodeType.Element:
                    writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                    writer.WriteAttributes(reader, true);
                    if (reader.IsEmptyElement)
                    {
                        writer.WriteEndElement();
                    }
                    return;

                case XmlNodeType.Text:
                    writer.WriteString(reader.Value);
                    return;

                case XmlNodeType.CDATA:
                    writer.WriteCData(reader.Value);
                    return;

                case XmlNodeType.ProcessingInstruction:
                    writer.WriteProcessingInstruction(reader.Name, reader.Value);
                    return;

                case XmlNodeType.Comment:
                    writer.WriteComment(reader.Value);
                    return;

                case XmlNodeType.DocumentType:
                    writer.WriteDocType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value);
                    return;

                case XmlNodeType.Whitespace:
                    writer.WriteWhitespace(reader.Value);
                    return;

                case XmlNodeType.SignificantWhitespace:
                    writer.WriteWhitespace(reader.Value);
                    return;

                case XmlNodeType.EndElement:
                    writer.WriteFullEndElement();
                    return;

                case XmlNodeType.XmlDeclaration:
                    writer.WriteProcessingInstruction(reader.Name, reader.Value);
                    return;
            }
            throw new InvalidOperationException("Invalid node");
        }
Example #9
0
        static void Main(string[] args)
        {
            //Write XML 1.1 file
            StringBuilder     sb  = new StringBuilder();
            XmlWriterSettings xws = new XmlWriterSettings();

            xws.Encoding = Encoding.UTF8;
            xws.Indent   = true;
            //Disable character checking
            xws.CheckCharacters = false;

            System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(sb, xws);
            //write your own header
            xw.WriteProcessingInstruction("xml", "version='1.1'");
            XElement doc = new XElement("root");

            doc.Add(
                new XElement("test",
                             new XAttribute("val", "\x03")));
            //use WriteTo instead of Save
            doc.WriteTo(xw);
            xw.Close();

            //Print XML contents to console
            Console.WriteLine(sb.ToString());


            //Read XML 1.1 file
            TextReader tr = new StringReader(sb.ToString());

            tr.ReadLine(); //skip Version number '1.1' is invalid. exception

            XmlReaderSettings xrs = new XmlReaderSettings();

            xrs.CheckCharacters = false;
            XmlReader xr = XmlReader.Create(tr, xrs);

            var xmldoc = XElement.Load(xr);

            foreach (var e in xmldoc.Elements())
            {
                Console.Write("Element: {0}", e.Name);
                foreach (var a in e.Attributes())
                {
                    Console.Write(" Attribute: {0}={1}", a.Name, a.Value);
                }
                Console.WriteLine();
            }
        }
Example #10
0
        public void Build(XmlWriter writer)
        {
            writer.WriteProcessingInstruction("xml-stylesheet", "type='text/xsl' href='style.xsl'");
            writer.WriteStartElement("types");
            this.DumpApiDocs(writer, "target", "NLog.Targets.TargetAttribute", "", " target");
            this.DumpApiDocs(writer, "layout", "NLog.Layouts.LayoutAttribute", "", "");
            this.DumpApiDocs(writer, "layout-renderer", "NLog.LayoutRenderers.LayoutRendererAttribute", "${", "}");
            this.DumpApiDocs(writer, "filter", "NLog.Filters.FilterAttribute", "", " filter");

            this.DumpApiDocs(writer, "target", "NLog.TargetAttribute", "", " target");
            this.DumpApiDocs(writer, "layout", "NLog.LayoutAttribute", "", "");
            this.DumpApiDocs(writer, "layout-renderer", "NLog.LayoutRendererAttribute", "${", "}");
            this.DumpApiDocs(writer, "filter", "NLog.FilterAttribute", "", " filter");
            writer.WriteEndElement();
        }
Example #11
0
		///<summary>Generates all the xml up to the point where the first statement would go.</summary>
		public static void GeneratePracticeInfo(XmlWriter writer) {
			writer.WriteProcessingInstruction("xml","version = \"1.0\" standalone=\"yes\"");
			writer.WriteStartElement("StatementFile");
			//sender address----------------------------------------------------------
			writer.WriteStartElement("SenderAddress");
			writer.WriteElementString("Name",PrefC.GetString(PrefName.PracticeTitle));
			writer.WriteElementString("Address1",PrefC.GetString(PrefName.PracticeAddress));
			writer.WriteElementString("Address2",PrefC.GetString(PrefName.PracticeAddress2));
			writer.WriteElementString("City",PrefC.GetString(PrefName.PracticeCity));
			writer.WriteElementString("State",PrefC.GetString(PrefName.PracticeST));
			writer.WriteElementString("Zip",PrefC.GetString(PrefName.PracticeZip));
			writer.WriteElementString("Phone",PrefC.GetString(PrefName.PracticePhone));//enforced to be 10 digit fairly rigidly by the UI
			writer.WriteEndElement();//SenderAddress
			writer.WriteStartElement("Statements");
		}
Example #12
0
		//these are temporary:
		//private static string vendorID="68";
		//private static string vendorPMScode="144";
		//private static string clientAccountNumber="8011";//the dental office number set by EHG
		//private static string creditCardChoices="MC,D,V,A";//MasterCard,Discover,Visa,AmericanExpress
		//private static string userName="";
		//private static string password="";

		///<summary>Generates all the xml up to the point where the first statement would go.</summary>
		public static void GeneratePracticeInfo(XmlWriter writer) {
			writer.WriteProcessingInstruction("xml","version = \"1.0\" standalone=\"yes\"");
			writer.WriteStartElement("EISStatementFile");
			writer.WriteAttributeString("VendorID",PrefC.GetString(PrefName.BillingElectVendorId));
			writer.WriteAttributeString("OutputFormat","StmOut_Blue6Col");
			writer.WriteAttributeString("Version","2");
			writer.WriteElementString("SubmitDate",DateTime.Today.ToString("yyyy-MM-dd"));
			writer.WriteElementString("PrimarySubmitter",PrefC.GetString(PrefName.BillingElectVendorPMSCode));
			writer.WriteElementString("Transmitter","EHG");
			writer.WriteStartElement("Practice");
			writer.WriteAttributeString("AccountNumber",PrefC.GetString(PrefName.BillingElectClientAcctNumber));
			//sender address----------------------------------------------------------
			writer.WriteStartElement("SenderAddress");
			writer.WriteElementString("Name",PrefC.GetString(PrefName.PracticeTitle));
			writer.WriteElementString("Address1",PrefC.GetString(PrefName.PracticeAddress));
			writer.WriteElementString("Address2",PrefC.GetString(PrefName.PracticeAddress2));
			writer.WriteElementString("City",PrefC.GetString(PrefName.PracticeCity));
			writer.WriteElementString("State",PrefC.GetString(PrefName.PracticeST));
			writer.WriteElementString("Zip",PrefC.GetString(PrefName.PracticeZip));
			writer.WriteElementString("Phone",PrefC.GetString(PrefName.PracticePhone));//enforced to be 10 digit fairly rigidly by the UI
			writer.WriteEndElement();//senderAddress
			//remit address----------------------------------------------------------
			writer.WriteStartElement("RemitAddress");
			writer.WriteElementString("Name",PrefC.GetString(PrefName.PracticeTitle));
			if(PrefC.GetString(PrefName.PracticeBillingAddress)=="") {//same as sender address
				writer.WriteElementString("Address1",PrefC.GetString(PrefName.PracticeAddress));
				writer.WriteElementString("Address2",PrefC.GetString(PrefName.PracticeAddress2));
				writer.WriteElementString("City",PrefC.GetString(PrefName.PracticeCity));
				writer.WriteElementString("State",PrefC.GetString(PrefName.PracticeST));
				writer.WriteElementString("Zip",PrefC.GetString(PrefName.PracticeZip));
			}
			else {
				writer.WriteElementString("Address1",PrefC.GetString(PrefName.PracticeBillingAddress));
				writer.WriteElementString("Address2",PrefC.GetString(PrefName.PracticeBillingAddress2));
				writer.WriteElementString("City",PrefC.GetString(PrefName.PracticeBillingCity));
				writer.WriteElementString("State",PrefC.GetString(PrefName.PracticeBillingST));
				writer.WriteElementString("Zip",PrefC.GetString(PrefName.PracticeBillingZip));				
			}
			writer.WriteElementString("Phone",PrefC.GetString(PrefName.PracticePhone));//phone is same in either case
			writer.WriteEndElement();//remitAddress
			//Rendering provider------------------------------------------------------
			Provider prov=Providers.GetProv(PrefC.GetLong(PrefName.PracticeDefaultProv));
			writer.WriteStartElement("RenderingProvider");
			writer.WriteElementString("Name",prov.GetFormalName());
			writer.WriteElementString("LicenseNumber",prov.StateLicense);
			writer.WriteElementString("State",PrefC.GetString(PrefName.PracticeST));
			writer.WriteEndElement();//Rendering provider
		}
    private void WriteNodeSingle(XmlReader reader, XmlWriter writer) {
      Contract.Requires(reader != null);
      Contract.Requires(writer != null);

      switch (reader.NodeType) {
        case XmlNodeType.Element:
          this.WriteElement(reader, writer);
          break;
        case XmlNodeType.Text:
          this.WriteText(reader, writer);
          break;
        case XmlNodeType.Whitespace:
        case XmlNodeType.SignificantWhitespace:
          this.WriteWhitespace(reader, writer);
          break;
        case XmlNodeType.CDATA:
          this.WriteCDATA(reader, writer);
          break;
        case XmlNodeType.EntityReference:
          Contract.Assume(false, "entityref not supported");
          writer.WriteString(reader.Name);
          break;
        case XmlNodeType.XmlDeclaration:
        case XmlNodeType.ProcessingInstruction:
          var pinstr = reader.Name;
          Contract.Assume(!String.IsNullOrEmpty(pinstr));
          writer.WriteProcessingInstruction(pinstr, reader.Value);
          break;
        case XmlNodeType.DocumentType:
          writer.WriteDocType(
              reader.Name,
              reader.GetAttribute("PUBLIC"),
              reader.GetAttribute("SYSTEM"),
              reader.Value);
          break;
        case XmlNodeType.Comment:
          WriteComment(reader, writer);
          break;
        case XmlNodeType.EndElement:
          this.WriteEndElement(reader, writer);
          break;
      }
    }
        public void AddStyleSheets(XmlWriter xmlWriter, IHasStyleSheets model)
        {
            if (model.StyleSheets == null)
            {
                return;
            }

            foreach (var styleSheet in model.StyleSheets)
            {
                StringBuilder stringBuilder = new StringBuilder($@"type=""{styleSheet.Type}"" href=""{styleSheet.Url}""");

                WriteAttribute(stringBuilder, "title", styleSheet.Title);
                WriteAttribute(stringBuilder, "media", styleSheet.Media);
                WriteAttribute(stringBuilder, "charset", styleSheet.Charset);

                if (styleSheet.Alternate.HasValue && styleSheet.Alternate.Value != YesNo.None)
                {
                    WriteAttribute(stringBuilder, "alternate", styleSheet.Alternate.Value.ToString().ToLowerInvariant());
                }

                xmlWriter.WriteProcessingInstruction("xml-stylesheet", stringBuilder.ToString());
            }
        }
Example #15
0
 // Saves the node to the specified XmlWriter.
 public override void WriteTo(XmlWriter w)
 {
     w.WriteProcessingInstruction(_target, _data);
 }
Example #16
0
        /// <summary>
        /// Replay all cached events to an XmlWriter.
        /// </summary>
        public void EventsToWriter(XmlWriter writer) {
            XmlEvent[] page;
            int idxPage, idxEvent;
            byte[] bytes;
            char[] chars;
            XmlRawWriter rawWriter;

            // Special-case single text node at the top-level
            if (this.singleText.Count != 0) {
                writer.WriteString(this.singleText.GetResult());
                return;
            }

            rawWriter = writer as XmlRawWriter;

            // Loop over set of pages
            for (idxPage = 0; idxPage < this.pages.Count; idxPage++) {
                page = this.pages[idxPage];

                // Loop over events in each page
                for (idxEvent = 0; idxEvent < page.Length; idxEvent++) {
                    switch (page[idxEvent].EventType) {
                        case XmlEventType.Unknown:
                            // No more events
                            Debug.Assert(idxPage + 1 == this.pages.Count);
                            return;

                        case XmlEventType.DocType:
                            writer.WriteDocType(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3, (string) page[idxEvent].Object);
                            break;

                        case XmlEventType.StartElem:
                            writer.WriteStartElement(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3);
                            break;

                        case XmlEventType.StartAttr:
                            writer.WriteStartAttribute(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3);
                            break;

                        case XmlEventType.EndAttr:
                            writer.WriteEndAttribute();
                            break;

                        case XmlEventType.CData:
                            writer.WriteCData(page[idxEvent].String1);
                            break;

                        case XmlEventType.Comment:
                            writer.WriteComment(page[idxEvent].String1);
                            break;

                        case XmlEventType.PI:
                            writer.WriteProcessingInstruction(page[idxEvent].String1, page[idxEvent].String2);
                            break;

                        case XmlEventType.Whitespace:
                            writer.WriteWhitespace(page[idxEvent].String1);
                            break;

                        case XmlEventType.String:
                            writer.WriteString(page[idxEvent].String1);
                            break;

                        case XmlEventType.Raw:
                            writer.WriteRaw(page[idxEvent].String1);
                            break;

                        case XmlEventType.EntRef:
                            writer.WriteEntityRef(page[idxEvent].String1);
                            break;

                        case XmlEventType.CharEnt:
                            writer.WriteCharEntity((char) page[idxEvent].Object);
                            break;

                        case XmlEventType.SurrCharEnt:
                            chars = (char[]) page[idxEvent].Object;
                            writer.WriteSurrogateCharEntity(chars[0], chars[1]);
                            break;

                        case XmlEventType.Base64:
                            bytes = (byte[]) page[idxEvent].Object;
                            writer.WriteBase64(bytes, 0, bytes.Length);
                            break;

                        case XmlEventType.BinHex:
                            bytes = (byte[]) page[idxEvent].Object;
                            writer.WriteBinHex(bytes, 0, bytes.Length);
                            break;

                        case XmlEventType.XmlDecl1:
                            if (rawWriter != null)
                                rawWriter.WriteXmlDeclaration((XmlStandalone) page[idxEvent].Object);
                            break;

                        case XmlEventType.XmlDecl2:
                            if (rawWriter != null)
                                rawWriter.WriteXmlDeclaration(page[idxEvent].String1);
                            break;

                        case XmlEventType.StartContent:
                            if (rawWriter != null)
                                rawWriter.StartElementContent();
                            break;

                        case XmlEventType.EndElem:
                            if (rawWriter != null)
                                rawWriter.WriteEndElement(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3);
                            else
                                writer.WriteEndElement();
                            break;

                        case XmlEventType.FullEndElem:
                            if (rawWriter != null)
                                rawWriter.WriteFullEndElement(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3);
                            else
                                writer.WriteFullEndElement();
                            break;

                        case XmlEventType.Nmsp:
                            if (rawWriter != null)
                                rawWriter.WriteNamespaceDeclaration(page[idxEvent].String1, page[idxEvent].String2);
                            else
                                writer.WriteAttributeString("xmlns", page[idxEvent].String1, XmlReservedNs.NsXmlNs, page[idxEvent].String2);
                            break;

                        case XmlEventType.EndBase64:
                            if (rawWriter != null)
                                rawWriter.WriteEndBase64();
                            break;

                        case XmlEventType.Close:
                            writer.Close();
                            break;

                        case XmlEventType.Flush:
                            writer.Flush();
                            break;

                        case XmlEventType.Dispose:
                            ((IDisposable)writer).Dispose();
                            break;

                        default:
                            Debug.Assert(false, "Unknown event: " + page[idxEvent].EventType);
                            break;
                    }
                }
            }

            Debug.Assert(false, "Unknown event should be added to end of event sequence.");
        }
 internal void WriteSiteMapHeader(XmlWriter writer)
 {
     //start off the site map
     writer.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");
     writer.WriteStartElement("urlset");
     writer.WriteAttributeString("xmlns", "http://www.google.com/schemas/sitemap/0.9");
 }
        internal void BuildSubtree(XmlReader reader, XmlWriter writer)
        {
            string ns = "http://www.w3.org/2000/xmlns/";
            ReadState readState = reader.ReadState;
            if ((readState != ReadState.Initial) && (readState != ReadState.Interactive))
            {
                throw new ArgumentException(Res.GetString("Xml_InvalidOperation"), "reader");
            }
            int num = 0;
            if (readState == ReadState.Initial)
            {
                if (!reader.Read())
                {
                    return;
                }
                num++;
            }
            do
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                    {
                        writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                        bool isEmptyElement = reader.IsEmptyElement;
                        while (reader.MoveToNextAttribute())
                        {
                            if (reader.NamespaceURI == ns)
                            {
                                if (reader.Prefix.Length == 0)
                                {
                                    writer.WriteAttributeString("", "xmlns", ns, reader.Value);
                                }
                                else
                                {
                                    writer.WriteAttributeString("xmlns", reader.LocalName, ns, reader.Value);
                                }
                            }
                            else
                            {
                                writer.WriteStartAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                                writer.WriteString(reader.Value);
                                writer.WriteEndAttribute();
                            }
                        }
                        reader.MoveToElement();
                        if (isEmptyElement)
                        {
                            writer.WriteEndElement();
                        }
                        else
                        {
                            num++;
                        }
                        break;
                    }
                    case XmlNodeType.Attribute:
                        if (reader.NamespaceURI != ns)
                        {
                            writer.WriteStartAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                            writer.WriteString(reader.Value);
                            writer.WriteEndAttribute();
                            break;
                        }
                        if (reader.Prefix.Length != 0)
                        {
                            writer.WriteAttributeString("xmlns", reader.LocalName, ns, reader.Value);
                            break;
                        }
                        writer.WriteAttributeString("", "xmlns", ns, reader.Value);
                        break;

                    case XmlNodeType.Text:
                    case XmlNodeType.CDATA:
                        writer.WriteString(reader.Value);
                        break;

                    case XmlNodeType.EntityReference:
                        reader.ResolveEntity();
                        break;

                    case XmlNodeType.ProcessingInstruction:
                        writer.WriteProcessingInstruction(reader.LocalName, reader.Value);
                        break;

                    case XmlNodeType.Comment:
                        writer.WriteComment(reader.Value);
                        break;

                    case XmlNodeType.Whitespace:
                    case XmlNodeType.SignificantWhitespace:
                        writer.WriteString(reader.Value);
                        break;

                    case XmlNodeType.EndElement:
                        writer.WriteFullEndElement();
                        num--;
                        break;
                }
            }
            while (reader.Read() && (num > 0));
        }
		private static void GenerateQRDACatOne(List<QualityMeasure> listQMs,DateTime dateStart,DateTime dateEnd,string folderRoot) {
			//create a list of all unique patients who belong to the initial patient population for any of the 9 CQMs
			List<EhrCqmPatient> listAllEhrPats=new List<EhrCqmPatient>();
			//create a dictionary linking a patient to the measures to which they belong
			Dictionary<long,List<QualityMeasure>> dictPatNumListQMs=new Dictionary<long,List<QualityMeasure>>();
			for(int i=0;i<listQMs.Count;i++) {
				for(int j=0;j<listQMs[i].ListEhrPats.Count;j++) {
					if(!dictPatNumListQMs.ContainsKey(listQMs[i].ListEhrPats[j].EhrCqmPat.PatNum)) {
						dictPatNumListQMs.Add(listQMs[i].ListEhrPats[j].EhrCqmPat.PatNum,new List<QualityMeasure>() { listQMs[i] });
						listAllEhrPats.Add(listQMs[i].ListEhrPats[j]);
					}
					else {
						dictPatNumListQMs[listQMs[i].ListEhrPats[j].EhrCqmPat.PatNum].Add(listQMs[i]);
					}
				}
			}
			//listAllPats contains every unique patient who belongs to one of the initial patient population for any of the 9 CQMs
			//dictPatNumListQMs is a dictionary linking a patient to a list of measure for which they are in the initial patient population
			StringBuilder strBuilder=new StringBuilder();
			StringBuilder strBuilderPatDataEntries=new StringBuilder();
			//this dictionary links a PatNum key to the patient's Cat I xml dictionary value
			Dictionary<long,string> dictPatNumXml=new Dictionary<long,string>();
			#region Cateogry I QRDA Documents
			for(int i=0;i<listAllEhrPats.Count;i++) {
				strBuilder=new StringBuilder();
				strBuilderPatDataEntries=new StringBuilder();
				EhrCqmPatient ehrPatCur=listAllEhrPats[i];
				Patient patCur=ehrPatCur.EhrCqmPat;//just to make referencing easier
				long patNumCur=ehrPatCur.EhrCqmPat.PatNum;//just to make referencing easier
				XmlWriterSettings xmlSettings=new XmlWriterSettings();
				xmlSettings.Encoding=Encoding.UTF8;
				xmlSettings.OmitXmlDeclaration=true;
				xmlSettings.Indent=true;
				xmlSettings.IndentChars="   ";
				xmlSettings.ConformanceLevel=ConformanceLevel.Fragment;
				using(_w=XmlWriter.Create(strBuilder,xmlSettings)) {
					//Begin Clinical Document
					_w.WriteRaw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
					_w.WriteProcessingInstruction("xml-stylesheet","type=\"text/xsl\" href=\"cda.xsl\"");
					_w.WriteWhitespace("\r\n");
					_w.WriteStartElement("ClinicalDocument","urn:hl7-org:v3");
					_w.WriteAttributeString("xmlns","xsi",null,"http://www.w3.org/2001/XMLSchema-instance");
					_w.WriteAttributeString("xsi","schemaLocation",null,"urn:./CDA.xsd");
					_w.WriteAttributeString("xmlns","voc",null,"urn:hl7-org:v3/voc");
					_w.WriteAttributeString("xmlns","sdtc",null,"urn:hl7-org:sdtc");
					#region QRDA I Header
					_w.WriteComment("QRDA Header");
					StartAndEnd("realmCode","code","US");
					StartAndEnd("typeId","root","2.16.840.1.113883.1.3","extension","POCD_HD000040");//template id to assert use of the CDA standard
					_w.WriteComment("US General Header Template");
					TemplateId("2.16.840.1.113883.10.20.22.1.1");
					_w.WriteComment("QRDA Template");
					TemplateId("2.16.840.1.113883.10.20.24.1.1");
					_w.WriteComment("QDM-based QRDA Template");
					TemplateId("2.16.840.1.113883.10.20.24.1.2");
					_w.WriteComment("This is the globally unique identifier for this QRDA document");
					Guid();
					_w.WriteComment("QRDA document type code");
					StartAndEnd("code","code","55182-0","codeSystem",strCodeSystemLoinc,"codeSystemName",strCodeSystemNameLoinc,"displayName","Quality Measure Report");
					_w.WriteElementString("title","QRDA Incidence Report");
					_w.WriteComment("This is the document creation time");
					TimeElement("effectiveTime",DateTime.Now);
					StartAndEnd("confidentialityCode","code","N","codeSystem","2.16.840.1.113883.5.25");//Fixed value.  Confidentiality Code System.  Codes: N=(Normal), R=(Restricted),V=(Very Restricted)
					StartAndEnd("languageCode","code","en-US");
					#region recordTarget
					_w.WriteComment("Reported patient");
					Start("recordTarget");
					#region patientRole
					Start("patientRole");
					string strHICNum=ValidateMedicaidID(patCur.MedicaidID);
					if(strHICNum!="") {
						_w.WriteComment("This is the patient's Medicare HIC (Health Insurance Claim) number");
						StartAndEnd("id","root","2.16.840.1.113883.4.572","extension",strHICNum);
					}
					//_w.WriteComment("The extension is the patient's Open Dental number, the root is the assigning authority");
					//StartAndEnd("id","root",_strOIDInternalPatRoot,"extension",patNumCur.ToString());
					if(patCur.SSN.Trim().Length==9) {
						_w.WriteComment("This is the patient's SSN using the HL7 SSN OID");
						StartAndEnd("id","root","2.16.840.1.113883.4.1","extension",patCur.SSN.Trim());//HL7 SSN OID root with patient's SSN if they have a valid one
					}
					AddressUnitedStates(patCur.Address,patCur.Address2,patCur.City,patCur.State,patCur.Zip,"HP");//Validated
					if(patCur.WirelessPhone.Trim()!="") {//There is at least one phone, due to validation.
						StartAndEnd("telecom","use","MC","value","tel:"+patCur.WirelessPhone.Trim());
						_w.WriteComment("MC is \"mobile contact\" from codeSystem 2.16.840.1.113883.5.1119");
					}
					else if(patCur.HmPhone.Trim()!="") {
						StartAndEnd("telecom","use","HP","value","tel:"+patCur.HmPhone.Trim());
						_w.WriteComment("HP is \"primary home\" from codeSystem 2.16.840.1.113883.5.1119");
					}
					else if(patCur.WkPhone.Trim()!="") {
						StartAndEnd("telecom","use","WP","value","tel:"+patCur.WkPhone.Trim());
						_w.WriteComment("WP is \"work place\" from codeSystem 2.16.840.1.113883.5.1119");
					}
					#region patient
					Start("patient");
					#region name
					Start("name","use","L");
					_w.WriteComment("L is \"Legal\" from codeSystem 2.16.840.1.113883.5.45");
					_w.WriteElementString("given",patCur.FName);//Validated
					if(patCur.MiddleI!="") {
						_w.WriteElementString("given",patCur.MiddleI);
					}
					_w.WriteElementString("family",patCur.LName);//Validated
					if(patCur.Title!="") {
						Start("suffix","qualifier","TITLE");
						_w.WriteString(patCur.Title);
						End("suffix");
					}
					End("name");
					#endregion name
					//Will always be present, because there are only 3 options and the user is forced to make a choice in the UI.
					if(patCur.Gender==PatientGender.Female) {
						StartAndEnd("administrativeGenderCode","code","F","codeSystem","2.16.840.1.113883.5.1","displayName","Female","codeSystemName","HL7 AdministrativeGender");
					}
					else if(patCur.Gender==PatientGender.Male) {
						StartAndEnd("administrativeGenderCode","code","M","codeSystem","2.16.840.1.113883.5.1","displayName","Male","codeSystemName","HL7 AdministrativeGender");
					}
					else {
						StartAndEnd("administrativeGenderCode","code","UN","codeSystem","2.16.840.1.113883.5.1","displayName","Undifferentiated","codeSystemName","HL7 AdministrativeGender");
					}
					DateElement("birthTime",patCur.Birthdate);//Validated
					if(patCur.Position==PatientPosition.Divorced) {
						StartAndEnd("maritalStatusCode","code","D","displayName","Divorced","codeSystem","2.16.840.1.113883.5.2","codeSystemName","MaritalStatusCode");
					}
					else if(patCur.Position==PatientPosition.Married) {
						StartAndEnd("maritalStatusCode","code","M","displayName","Married","codeSystem","2.16.840.1.113883.5.2","codeSystemName","MaritalStatusCode");
					}
					else if(patCur.Position==PatientPosition.Widowed) {
						StartAndEnd("maritalStatusCode","code","W","displayName","Widowed","codeSystem","2.16.840.1.113883.5.2","codeSystemName","MaritalStatusCode");
					}
					else {//Single and child
						StartAndEnd("maritalStatusCode","code","S","displayName","Never Married","codeSystem","2.16.840.1.113883.5.2","codeSystemName","MaritalStatusCode");
					}
					#region raceCode
					string strRaceDescript="";
					string strRaceCode="2131-1";//default will be "Other Race"
					//if declined to specify race, null flavor is "ASKU" - Asked, but not known. Information was sought, but not found
					//if race is not present, null flavor is "UNK" - Unknown. A proper value is applicable, but is not known.
					//These will appear as <raceCode nullFlavor=”ASKU”/> or <raceCode nullFlavor=”UNK”/> respectively
					bool isRaceNull=false;
					if(ehrPatCur.ListPatientRaces.Count==0) {
						isRaceNull=true;
						strRaceDescript="UNK";
					}
					else if(ehrPatCur.ListPatientRaces.Count==1) {//if only one race is entered (already separated out the ethnicities) then we can construct the raceCode element with selected race
						switch(ehrPatCur.ListPatientRaces[0].Race) {
							case PatRace.AfricanAmerican:
								strRaceDescript="Black or African American";
								strRaceCode=ehrPatCur.ListPatientRaces[0].CdcrecCode;
								break;
							case PatRace.AmericanIndian:
								strRaceDescript="American Indian or Alaska Native";
								strRaceCode=ehrPatCur.ListPatientRaces[0].CdcrecCode;
								break;
							case PatRace.Asian:
							case PatRace.White:
								strRaceDescript=ehrPatCur.ListPatientRaces[0].Race.ToString();
								strRaceCode=ehrPatCur.ListPatientRaces[0].CdcrecCode;
								break;
							case PatRace.HawaiiOrPacIsland:
								strRaceDescript="Native Hawaiian or Other Pacific Islander";
								strRaceCode=ehrPatCur.ListPatientRaces[0].CdcrecCode;
								break;
							case PatRace.DeclinedToSpecifyRace:
								isRaceNull=true;
								strRaceDescript="ASKU";
								break;
							default://any other race will be reported as "Other race"
								strRaceDescript="Other Race";
								break;
						}
					}
					//"If there are multiple race values reported for a patient, count as ‘Other Race’ value" from downloaded implementation guide found:
					//\\SERVERFILES\storage\EHR\Quality Measures\QRDA\QRDAIII_CMS_EP_2014_ImplementationGuide_Vol1\QRDA_III_CMS_EP_2014_IG_Vol 2.pdf page 49
					else {
						strRaceDescript="Other Race";
					}
					if(isRaceNull) {//either declined to specify (flavor "ASKU") or no race recorded (flavor "UNK")
						StartAndEnd("raceCode","nullFlavor",strRaceDescript);
					}
					else {
						StartAndEnd("raceCode","code",strRaceCode,"displayName",strRaceDescript,"codeSystem","2.16.840.1.113883.6.238","codeSystemName","CDC Race and Ethnicity");
					}
					#endregion raceCode
					#region ethnicityGroupCode
					string strEthnicityCode="";
					string strEthnicityDescript="";
					bool isDeclinedEthnicity=false;
					if(ehrPatCur.Ethnicity!=null) {
						if(ehrPatCur.Ethnicity.Race==PatRace.Hispanic) {
							strEthnicityDescript="Hispanic";
							strEthnicityCode=ehrPatCur.Ethnicity.CdcrecCode;
						}
						else if(ehrPatCur.Ethnicity.Race==PatRace.NotHispanic) {
							strEthnicityDescript="Not Hispanic or Latino";
							strEthnicityCode=ehrPatCur.Ethnicity.CdcrecCode;
						}
						else {
							isDeclinedEthnicity=true;
						}
					}
					if(ehrPatCur.Ethnicity==null) {
						StartAndEnd("ethnicGroupCode","nullFlavor","UNK");
					}
					else if(isDeclinedEthnicity) {
						StartAndEnd("ethnicGroupCode","nullFlavor","ASKU");
					}
					else if(strEthnicityCode!="" && strEthnicityDescript!=""){
						StartAndEnd("ethnicGroupCode","code",strEthnicityCode,"displayName",strEthnicityDescript,"codeSystem","2.16.840.1.113883.6.238","codeSystemName","CDC Race and Ethnicity");
					}
					#endregion ethnicityGroupCode
					End("patient");
					#endregion patient
					End("patientRole");
					#endregion patientRole
					End("recordTarget");
					#endregion recordTarget
					#region comments
					//The author element represents the creator of the clinical document.  The author may be a device, or a person.  Section 4.1.2, page 69.
					//Participant Scenarios in a QRDA Category I Document (section 5.1.5.3, page 94)
					//Three possible scenarios given, the first sounds like it applies to us
					//1.) QRDA is wholly constructed automatically by device
					//Author - Device
					//Custodian - Organization that owns and reports the data (e.g. hospital, dental practice)
					//Informant - N/A
					//Legal Authenticator - A designated person in the organization (may be assigned to the report automatically)
					//2.) QRDA is partially constructed automatically by device, partially constructed by quality manager
					//3.) QRDA is constructed manually (e.g. by an organization that doesn't have an EHR)
					//We will generate a device author element, a practice custodian element, no informant element, and a Legal Authenticator element using the practice default provider
					#endregion
					#region author
					Start("author");
					TimeElement("time",DateTime.Now);
					Start("assignedAuthor");
					StartAndEnd("id","root","2.16.840.1.113883.3.4337","assigningAuthorityName","HL7 OID Registry");
					AddressUnitedStates("3995 Fairview Industrial Dr. SE","Suite 110","Salem","OR","97302","WP");
					StartAndEnd("telecom","use","WP","value","tel:(503)363-5432");
					Start("assignedAuthoringDevice");
					_w.WriteElementString("manufacturerModelName","Open Dental version "+PrefC.GetString(PrefName.ProgramVersion));
					_w.WriteElementString("softwareName","Open Dental Software Inc.");
					End("assignedAuthoringDevice");
					End("assignedAuthor");
					End("author");
					#endregion author
					#region custodian
					//"Represents the organization in charge of maintaining the document." Section 4.1.5, page 77
					//The custodian is the steward that is entrusted with the care of the document. Every CDA document has exactly one custodian.
					Start("custodian");
					Start("assignedCustodian");
					Start("representedCustodianOrganization");
					StartAndEnd("id","root",_strOIDInternalRoot);//This is the root assigned to the practice, based on the OD root 2.16.840.1.113883.3.4337
					_w.WriteElementString("name",PrefC.GetString(PrefName.PracticeTitle));//Validated
					string strPracticePhone=PrefC.GetString(PrefName.PracticePhone);//Validated
					strPracticePhone="("+strPracticePhone.Substring(0,3)+")"+strPracticePhone.Substring(3,3)+"-"+strPracticePhone.Substring(6);
					StartAndEnd("telecom","use","WP","value","tel:"+strPracticePhone);//Validated
					AddressUnitedStates(PrefC.GetString(PrefName.PracticeAddress),PrefC.GetString(PrefName.PracticeAddress2),PrefC.GetString(PrefName.PracticeCity),PrefC.GetString(PrefName.PracticeST),PrefC.GetString(PrefName.PracticeZip),"WP");//Validated
					End("representedCustodianOrganization");
					End("assignedCustodian");
					End("custodian");
					#endregion custodian
					#region legalAuthenticator
					//This element identifies the single person legally responsible for the document and must be present if the document has been legally authenticated.
					Start("legalAuthenticator");
					TimeElement("time",DateTime.Now);
					StartAndEnd("signatureCode","code","S");
					Start("assignedEntity");
					Provider provLegal=Providers.GetProv(PrefC.GetLong(PrefName.PracticeDefaultProv));
					StartAndEnd("id","root","2.16.840.1.113883.4.6","extension",provLegal.NationalProvID,"assigningAuthorityName","NPI");//Validated NPI
					AddressUnitedStates(PrefC.GetString(PrefName.PracticeAddress),PrefC.GetString(PrefName.PracticeAddress2),PrefC.GetString(PrefName.PracticeCity),PrefC.GetString(PrefName.PracticeST),PrefC.GetString(PrefName.PracticeZip),"WP");//Validated
					StartAndEnd("telecom","use","WP","value","tel:"+strPracticePhone);//Validated
					Start("assignedPerson");
					Start("name");
					_w.WriteElementString("given",provLegal.FName);//Validated
					_w.WriteElementString("family",provLegal.LName);//Validated
					End("name");
					End("assignedPerson");
					End("assignedEntity");
					End("legalAuthenticator");
					#endregion legalAuthenticator
					#region documentationOf
					Start("documentationOf","typeCode","DOC");
					_w.WriteComment("care provision");
					Start("serviceEvent","classCode","PCPR");
					Start("effectiveTime");
					DateElement("low",dateStart);
					DateElement("high",dateEnd);
					End("effectiveTime");
					#region performer
					Start("performer","typeCode","PRF");
					Start("assignedEntity");
					if(_provOutQrda.NationalProvID!="") {
						_w.WriteComment("This is the provider NPI");
						StartAndEnd("id","root","2.16.840.1.113883.4.6","extension",_provOutQrda.NationalProvID);
					}
					if(_provOutQrda.UsingTIN && _provOutQrda.SSN!="") {
						_w.WriteComment("This is the provider TIN");
						StartAndEnd("id","root","2.16.840.1.113883.4.2","extension",_provOutQrda.SSN);
					}
					_w.WriteComment("This is the practice OID provider root and Open Dental assigned ProvNum extension");
					StartAndEnd("id","root",_strOIDInternalProvRoot,"extension",_provOutQrda.ProvNum.ToString());
					Start("representedOrganization");
					//we don't currently have an organization level TIN or an organization Facility CMS Certification Number (CCN)
					//both id's are identified as "SHOULD" elements.  We will include the practice name
					//_w.WriteComment("This is the organization TIN");
					//_w.WriteComment("This is the organization CCN");
					_w.WriteElementString("name",PrefC.GetString(PrefName.PracticeTitle));//Validated
					End("representedOrganization");
					End("assignedEntity");
					End("performer");
					#endregion performer
					End("serviceEvent");
					End("documentationOf");
					#endregion documentationOf
					#endregion QRDA I Header
					#region QRDA I Body
					_w.WriteComment("QRDA Body");
					Start("component");
					Start("structuredBody");
					#region Reporting Parameters
					Start("component");
					Start("section");
					_w.WriteComment(@"
					  *****************************************************************
					  Reporting Parameters Section
					  *****************************************************************
					  ");
					_w.WriteComment("Reporting Parameters Section Template");
					TemplateId("2.16.840.1.113883.10.20.17.2.1");
					StartAndEnd("code","code","55187-9","codeSystem",strCodeSystemLoinc,"codeSystemName",strCodeSystemNameLoinc,"displayName","Reporting Parameters");
					_w.WriteElementString("title","Reporting Parameters");
					Start("text");
					Start("list");
					_w.WriteElementString("item","Reporting period: "+dateStart.ToString("MMMM dd, yyyy")+" 00:00 - "+dateEnd.ToString("MMMM dd, yyyy")+" 23:59");
					End("list");
					End("text");
					Start("entry","typeCode","DRIV");
					Start("act","classCode","ACT","moodCode","EVN");
					_w.WriteComment("Reporting Parameteres Act Template");
					TemplateId("2.16.840.1.113883.10.20.17.3.8");
					StartAndEnd("code","code","252116004","codeSystem",strCodeSystemSnomed,"codeSystemName",strCodeSystemNameSnomed,"displayName","Observation Parameters");
					Start("effectiveTime");
					StartAndEnd("low","value",dateStart.ToString("yyyyMMdd")+"000000");
					StartAndEnd("high","value",dateEnd.ToString("yyyyMMdd")+"235959");
					End("effectiveTime");
					End("act");
					End("entry");
					End("section");
					End("component");
					#endregion Reporting Parameters
					#region Measure Section
					Start("component");
					Start("section");
					_w.WriteComment(@"
					  *****************************************************************
					  Measure Section
					  *****************************************************************
					  ");
					_w.WriteComment("Measure Section Template");
					TemplateId("2.16.840.1.113883.10.20.24.2.2");
					_w.WriteComment("Measure Section QDM Template");
					TemplateId("2.16.840.1.113883.10.20.24.2.3");
					_w.WriteComment("This is the LOINC code for \"Measure document\". This stays the same for all measure sections required by QRDA standard");
					StartAndEnd("code","code","55186-1","codeSystem",strCodeSystemLoinc,"codeSystemName",strCodeSystemNameLoinc,"displayName","Measure Document");
					_w.WriteElementString("title","Measure Section");
					#region text version of eMeasures as table
					Start("text");
					Start("table","border","1","width","100%");
					Start("thead");
					Start("tr");
					_w.WriteElementString("th","eMeasure Identifier (MAT)");
					_w.WriteElementString("th","eMeasure Title");
					_w.WriteElementString("th","Version neutral identifier");
					_w.WriteElementString("th","eMeasure Version Number");
					_w.WriteElementString("th","Version specific identifier");
					End("tr");
					End("thead");
					Start("tbody");
					for(int j=0;j<listQMs.Count;j++) {
						//_listExtraPopIndxs will contain all of the Type2014 enum types that are stratifications or extra populations of other measures, so skip them here
						if(_listExtraPopIndxs.Contains(i)) {
							continue;
						}
						MeasureTextTableRow(listQMs[j].eMeasureTitle,listQMs[j].eMeasureNum,listQMs[j].eMeasureVNeutralId,listQMs[j].eMeasureVersion,listQMs[j].eMeasureVSpecificId);
					}
					End("tbody");
					End("table");
					End("text");
					#endregion text version of eMeasures as table
					#region eMeasure entries
					_w.WriteComment("1..* Organizers, each containing a reference to an eMeasure");
					for(int j=0;j<listQMs.Count;j++) {
						//_listExtraPopIndxs will contain all of the Type2014 enum types that are stratifications or extra populations of other measures, so skip them here
						if(_listExtraPopIndxs.Contains(i)) {
							continue;
						}
						MeasureEntry(listQMs[j].eMeasureVSpecificId,listQMs[j].eMeasureTitle,listQMs[j].eMeasureVNeutralId,listQMs[j].eMeasureVersion);
					}
					#endregion eMeasure entries
					End("section");
					End("component");
					#endregion Measure Section
					#region Patient Data
					Start("component");
					Start("section");
					_w.WriteComment(@"
					  *****************************************************************
					  Patient Data Section
					  *****************************************************************
					  ");
					_w.WriteComment("Patient Data Section Template");
					TemplateId("2.16.840.1.113883.10.20.17.2.4");
					_w.WriteComment("Patient Data QDM Section Template");
					TemplateId("2.16.840.1.113883.10.20.24.2.1");
					StartAndEnd("code","code","55188-7","codeSystem",strCodeSystemLoinc,"codeSystemName",strCodeSystemNameLoinc,"displayName","Patient Data");
					_w.WriteElementString("title","Patient Data");
					Start("text");
					Start("table","border","1","width","100%");
					Start("thead");
					Start("tr");
					_w.WriteElementString("th","Description");
					_w.WriteElementString("th","Value Set");
					_w.WriteElementString("th","Code");
					_w.WriteElementString("th","Date/Time");
					_w.WriteElementString("th","Results");
					End("tr");
					End("thead");
					Start("tbody");
					using(_x=XmlWriter.Create(strBuilderPatDataEntries,xmlSettings)) {
						_x.WriteStartElement("ClinicalDocument","urn:hl7-org:v3");
						_x.WriteAttributeString("xmlns","xsi",null,"http://www.w3.org/2001/XMLSchema-instance");
						_x.WriteAttributeString("xsi","schemaLocation",null,"urn:./CDA.xsd");
						_x.WriteAttributeString("xmlns","voc",null,"urn:hl7-org:v3/voc");
						_x.WriteAttributeString("xmlns","sdtc",null,"urn:hl7-org:sdtc");
						List<QualityMeasure> listQMsCur=dictPatNumListQMs[patNumCur];
						//this list of unique item ids is used when building the plain text version so that the encounter/procedure/item will only be in the plain text version once
						//we will add the item to the entries multiple times since the item can belong to different value sets
						//and must have the value set specific to the measure for which it qualifies the patient
						List<string> listUniqueItemExtensionsWithValueSetOIDs=new List<string>();
						List<string> listUniqueItemExtensions=new List<string>();
						//create encounter entries for each measure for this patient
						#region encounters
						for(int j=0;j<listQMsCur.Count;j++) {
							if(!listQMsCur[j].DictPatNumListEncounters.ContainsKey(patNumCur)) {
								continue;
							}
							for(int k=0;k<listQMsCur[j].DictPatNumListEncounters[patNumCur].Count;k++) {
								EhrCqmEncounter encCur=listQMsCur[j].DictPatNumListEncounters[patNumCur][k];
								//if in this list with ValueSetOID, then it must be in the non-ValueSetOID list, so just continue
								string extensCur=CqmItemAbbreviation.Enc.ToString()+encCur.ValueSetOID+"Num"+encCur.EhrCqmEncounterNum.ToString();
								if(!listUniqueItemExtensionsWithValueSetOIDs.Contains(extensCur)) {
									listUniqueItemExtensionsWithValueSetOIDs.Add(extensCur);
									GenerateEncounterEntry(encCur);
								}
								extensCur=CqmItemAbbreviation.Enc.ToString()+encCur.EhrCqmEncounterNum.ToString();
								if(listUniqueItemExtensions.Contains(extensCur)) {
									continue;
								}
								listUniqueItemExtensions.Add(extensCur);
								#region BuildPlainTextVersion
								string descript="Encounter, Performed: "+encCur.ValueSetName;
								PatientDataTextTableRow(descript,encCur.ValueSetOID,encCur.CodeSystemName,encCur.CodeValue,encCur.DateEncounter,encCur.DateEncounter,"");
								#endregion BuildPlainTextVersion
							}
						}
						#endregion encounters
						//create intervention entries for each measure for this patient
						#region interventions
						for(int j=0;j<listQMsCur.Count;j++) {
							if(!listQMsCur[j].DictPatNumListInterventions.ContainsKey(patNumCur)) {
								continue;
							}
							for(int k=0;k<listQMsCur[j].DictPatNumListInterventions[patNumCur].Count;k++) {
								EhrCqmIntervention iCur=listQMsCur[j].DictPatNumListInterventions[patNumCur][k];
								string extensCur=CqmItemAbbreviation.Ivn.ToString()+iCur.ValueSetOID+"Num"+iCur.EhrCqmInterventionNum.ToString();
								if(!listUniqueItemExtensionsWithValueSetOIDs.Contains(extensCur)) {
									listUniqueItemExtensionsWithValueSetOIDs.Add(extensCur);
									GenerateInterventionEntry(iCur);
								}
								extensCur=CqmItemAbbreviation.Ivn.ToString()+iCur.EhrCqmInterventionNum.ToString();
								if(listUniqueItemExtensions.Contains(extensCur)) {
									continue;
								}
								listUniqueItemExtensions.Add(extensCur);
								#region BuildPlainTextVersion
								string descript="";
								if(listQMsCur[j].Type2014==QualityType2014.WeightAdult || listQMsCur[j].Type2014==QualityType2014.WeightOver65) {//interventions in these two measures are ordered
									descript="Intervention, Order: ";
								}
								else {
									descript="Intervention, Performed: ";
								}
								descript+=iCur.ValueSetName;
								PatientDataTextTableRow(descript,iCur.ValueSetOID,iCur.CodeSystemName,iCur.CodeValue,iCur.DateEntry,iCur.DateEntry,"");
								#endregion BuildPlainTextVersion
							}
						}
						#endregion interventions
						//create ehrmeasureevents for each measure for this patient
						#region ehrmeasureevents
						for(int j=0;j<listQMsCur.Count;j++) {
							if(!listQMsCur[j].DictPatNumListMeasureEvents.ContainsKey(patNumCur)) {
								continue;
							}
							for(int k=0;k<listQMsCur[j].DictPatNumListMeasureEvents[patNumCur].Count;k++) {
								EhrCqmMeasEvent mCur=listQMsCur[j].DictPatNumListMeasureEvents[patNumCur][k];
								string extensCur=CqmItemAbbreviation.MeasEvn.ToString()+mCur.ValueSetOID+"Num"+mCur.EhrCqmMeasEventNum.ToString();
								if(!listUniqueItemExtensionsWithValueSetOIDs.Contains(extensCur)) {
									listUniqueItemExtensionsWithValueSetOIDs.Add(extensCur);
									GenerateMeasEventEntry(mCur);
								}
								extensCur=CqmItemAbbreviation.MeasEvn.ToString()+mCur.EhrCqmMeasEventNum.ToString();
								if(listUniqueItemExtensions.Contains(extensCur)) {
									continue;
								}
								listUniqueItemExtensions.Add(extensCur);
								#region BuildPlainTextVersion
								string descript="";
								if(mCur.EventType==EhrMeasureEventType.TobaccoUseAssessed) {
									descript="Patient Characteristic: ";
								}
								else if(mCur.EventType==EhrMeasureEventType.CurrentMedsDocumented) {
									descript="Procedure, Performed: ";
								}
								descript+=mCur.ValueSetName+" - "+mCur.Description;
								PatientDataTextTableRow(descript,mCur.ValueSetOID,mCur.CodeSystemName,mCur.CodeValue,mCur.DateTEvent,mCur.DateTEvent,"");
								#endregion BuildPlainTextVersion
							}
						}
						#endregion ehrmeasureevents
						//create medicationpats for each measure for this patient
						#region medicationpats
						for(int j=0;j<listQMsCur.Count;j++) {
							//have to check for CompletionStatus=NotAdministered if vaccine, vaccines given are procedures performed, not given are medication allergy or intolerance
							if(!listQMsCur[j].DictPatNumListMedPats.ContainsKey(patNumCur)) {
								continue;
							}
							for(int k=0;k<listQMsCur[j].DictPatNumListMedPats[patNumCur].Count;k++) {
								EhrCqmMedicationPat mPatCur=listQMsCur[j].DictPatNumListMedPats[patNumCur][k];
								string extensCur=CqmItemAbbreviation.MedPat.ToString()+mPatCur.ValueSetOID+"Num";								
								if(mPatCur.EhrCqmMedicationPatNum!=0) {
									extensCur+=mPatCur.EhrCqmMedicationPatNum.ToString();
								}
								else {
									extensCur+=mPatCur.EhrCqmVaccinePatNum.ToString();
								}
								if(!listUniqueItemExtensionsWithValueSetOIDs.Contains(extensCur)) {
									listUniqueItemExtensionsWithValueSetOIDs.Add(extensCur);
									GenerateMedPatsEntry(mPatCur);
								}
								extensCur=CqmItemAbbreviation.MedPat.ToString();	
								if(mPatCur.EhrCqmMedicationPatNum!=0) {
									extensCur+=mPatCur.EhrCqmMedicationPatNum.ToString();
								}
								else {
									extensCur+=mPatCur.EhrCqmVaccinePatNum.ToString();
								}
								if(listUniqueItemExtensions.Contains(extensCur)) {
									continue;
								}
								listUniqueItemExtensions.Add(extensCur);
								#region BuildPlainTextVersion
								string descript="";
								string codeValue="";
								//represents a medication.  Used by tobacco cessation or above/below normal weight meds
								if(mPatCur.EhrCqmMedicationPatNum!=0) {
									codeValue=mPatCur.RxCui.ToString();
									//Will be Medication, Active/Order
									if(mPatCur.PatNote!="") {//PatNote means an order
										descript="Medication, Ordered: ";
									}
									else {
										descript="Medication, Active: ";
									}
								}
								//EhrCqmVaccinePatNum will only be set if pneumonia or influenza measure and it represents a vaccine
								else {
									codeValue=mPatCur.CVXCode;
									if(mPatCur.CompletionStatus==VaccineCompletionStatus.NotAdministered) {//NotAdministered is due to an allergy or intolerance
										descript="Medication, Allergy: ";
									}
									else {//only getting CompletionStatus=Complete or NotAdministered, the else is for Complete
										descript="Medication, Administered: ";
									}
								}
								descript+=mPatCur.ValueSetName+" - "+mPatCur.Description;
								PatientDataTextTableRow(descript,mPatCur.ValueSetOID,mPatCur.CodeSystemName,codeValue,mPatCur.DateStart,mPatCur.DateStop,"");
								#endregion BuildPlainTextVersion
							}
						}
						#endregion medicationpats
						//create ehrnotperformeds for each measure for this patient
						#region ehrnotperformeds
						for(int j=0;j<listQMsCur.Count;j++) {
							//have to determine what is not being performed, Procedure (flu vaccine, current meds documented), Medication (flu vaccine), Physical Exam, Tobacco screening
							//if ValueSetOID=2.16.840.1.113883.3.526.3.1254, then Medication, Administered not done: Medical/Patient/System Reason (flu vaccine med)
							//if ValueSetOID=2.16.840.1.113883.3.526.3.402, then Procedure, Performed not done: Medical/Patient/System Reason (flu vaccine proc)
							//if ValueSetOID=2.16.840.1.113883.3.600.1.462, then Procedure, Performed not done: Medical or Other reason not done (current meds documented proc)
							//if ValueSetOID=2.16.840.1.113883.3.600.1.681, then Physical Exam, Performed not done: Medical or Other reason not done/Patient Reason Refused (vitalsign exam)
							//if ValueSetOID=2.16.840.1.113883.3.526.3.1278, then Risk Category Assessment not done: Medical Reason (tobacco assessment)
							//Then use the negationInd="true" attribute to indicate that it was not performed
							if(!listQMsCur[j].DictPatNumListNotPerfs.ContainsKey(patNumCur)) {
								continue;
							}
							for(int k=0;k<listQMsCur[j].DictPatNumListNotPerfs[patNumCur].Count;k++) {
								EhrCqmNotPerf npCur=listQMsCur[j].DictPatNumListNotPerfs[patNumCur][k];
								string extensCur=CqmItemAbbreviation.NotPerf.ToString()+npCur.ValueSetOID+"Num"+npCur.EhrCqmNotPerfNum.ToString();
								if(!listUniqueItemExtensionsWithValueSetOIDs.Contains(extensCur)) {
									listUniqueItemExtensionsWithValueSetOIDs.Add(extensCur);
									GenerateNotPerfEntry(npCur);
								}
								extensCur=CqmItemAbbreviation.NotPerf.ToString()+npCur.EhrCqmNotPerfNum.ToString();
								if(listUniqueItemExtensions.Contains(extensCur)) {
									continue;
								}
								listUniqueItemExtensionsWithValueSetOIDs.Add(extensCur);
								#region BuildPlainTextVersion
								string descript="";
								if(npCur.ValueSetOID=="2.16.840.1.113883.3.526.3.1254") {
									descript="Medication, Administered not done: ";
								}
								else if(npCur.ValueSetOID=="2.16.840.1.113883.3.526.3.402" || npCur.ValueSetOID=="2.16.840.1.113883.3.600.1.462") {
									descript="Procedure, Performed not done: ";
								}
								else if(npCur.ValueSetOID=="2.16.840.1.113883.3.600.1.681") {
									descript="Physical Exam, Performed not done: ";
								}
								else {//must be a 2.16.840.1.113883.3.526.3.1278, not performed items restricted to one of these 5 value sets
									descript="Risk Category Assessment not done: ";
								}
								descript+=npCur.ValueSetName+" - "+npCur.DescriptionReason;
								PatientDataTextTableRow(descript,npCur.ValueSetOID,npCur.CodeSystemName,npCur.CodeValue,npCur.DateEntry,npCur.DateEntry,"");
								#endregion BuildPlainTextVersion
							}
						}
						#endregion ehrnotperformeds
						//create problems for each measure for this patient
						#region problems
						for(int j=0;j<listQMsCur.Count;j++) {
							//if ValueSetOID = 2.16.840.1.113883.3.526.3.1255, SNOMEDCT - 315640000 - Influenza vaccination declined (situation), then it is a Communication, From patient to provider:
							//if ValueSetOID = 2.16.840.1.113883.3.464.1003.110.12.1028, SNOMEDCT - 310578008 - Pneumococcal vaccination given (finding), then it is a Risk Category Assessment:
							//if ValueSetOID = 2.16.840.1.113883.3.600.1.1579 - Palliative Care, then it is a Procedure, Order:
							//Otherwise it is a Diagnosis, Active:
							if(!listQMsCur[j].DictPatNumListProblems.ContainsKey(patNumCur)) {
								continue;
							}
							for(int k=0;k<listQMsCur[j].DictPatNumListProblems[patNumCur].Count;k++) {
								EhrCqmProblem probCur=listQMsCur[j].DictPatNumListProblems[patNumCur][k];
								string extensCur=CqmItemAbbreviation.Prob.ToString()+probCur.ValueSetOID+"Num"+probCur.EhrCqmProblemNum.ToString();
								if(!listUniqueItemExtensionsWithValueSetOIDs.Contains(extensCur)) {
									listUniqueItemExtensionsWithValueSetOIDs.Add(extensCur);
									switch(probCur.ValueSetOID) {
										case "2.16.840.1.113883.3.526.3.1255":
											GenerateCommunicationEntry(probCur);
											break;
										case "2.16.840.1.113883.3.464.1003.110.12.1028":
											GenerateRiskAssessEntry(probCur);
											break;
										case "2.16.840.1.113883.3.600.1.1579":
											GenerateProcedureEntry(null,probCur);
											break;
										default:
											GenerateDiagnosisEntry(probCur);
											break;
									}
								}
								extensCur=CqmItemAbbreviation.Prob.ToString()+probCur.EhrCqmProblemNum.ToString();
								if(listUniqueItemExtensions.Contains(extensCur)) {
									continue;
								}
								listUniqueItemExtensions.Add(extensCur);
								#region BuildPlainTextVersion
								string descript="";
								switch(probCur.ValueSetOID) {
									case "2.16.840.1.113883.3.526.3.1255":
										descript="Communication, From patient to provider: ";
										break;
									case "2.16.840.1.113883.3.464.1003.110.12.1028":
										descript="Risk Category Assessment: ";
										break;
									case "2.16.840.1.113883.3.600.1.1579":
										descript="Procedure, Order: ";
										break;
									default:
										descript="Diagnosis, Active: ";
										break;
								}
								descript+=probCur.ValueSetName+" - "+probCur.Description;
								PatientDataTextTableRow(descript,probCur.ValueSetOID,probCur.CodeSystemName,probCur.CodeValue,probCur.DateStart,probCur.DateStop,"");
								#endregion BuildPlainTextVersion
							}
						}
						#endregion problems
						//create procs for each measure for this patient
						#region procs
						for(int j=0;j<listQMsCur.Count;j++) {
							if(!listQMsCur[j].DictPatNumListProcs.ContainsKey(patNumCur)) {
								continue;
							}
							for(int k=0;k<listQMsCur[j].DictPatNumListProcs[patNumCur].Count;k++) {
								EhrCqmProc procCur=listQMsCur[j].DictPatNumListProcs[patNumCur][k];
								string extensCur=CqmItemAbbreviation.Proc.ToString()+procCur.ValueSetOID+"Num"+procCur.EhrCqmProcNum.ToString();
								if(!listUniqueItemExtensionsWithValueSetOIDs.Contains(extensCur)) {
									listUniqueItemExtensionsWithValueSetOIDs.Add(extensCur);
									GenerateProcedureEntry(procCur,null);
								}
								extensCur=CqmItemAbbreviation.Proc.ToString()+procCur.EhrCqmProcNum.ToString();
								if(listUniqueItemExtensions.Contains(extensCur)) {
									continue;
								}
								listUniqueItemExtensions.Add(extensCur);
								#region BuildPlainTextVersion
								string descript="Procedure, Performed: "+procCur.ValueSetName+" - "+procCur.Description;
								PatientDataTextTableRow(descript,procCur.ValueSetOID,procCur.CodeSystemName,procCur.ProcCode,procCur.ProcDate,procCur.ProcDate,"");
								#endregion BuildPlainTextVersion
							}
						}
						#endregion procs
						//create vitalsigns for each measure for this patient
						#region vitalsigns
						for(int j=0;j<listQMsCur.Count;j++) {
							if(!listQMsCur[j].DictPatNumListVitalsigns.ContainsKey(patNumCur)) {
								continue;
							}
							for(int k=0;k<listQMsCur[j].DictPatNumListVitalsigns[patNumCur].Count;k++) {
								EhrCqmVitalsign vCur=listQMsCur[j].DictPatNumListVitalsigns[patNumCur][k];
								string extensCur="";
								if(vCur.BpDiastolic>0) {
									extensCur=CqmItemAbbreviation.Vital.ToString()+"2.16.840.1.113883.3.526.3.1033"+"Num"+vCur.EhrCqmVitalsignNum.ToString();
									if(!listUniqueItemExtensionsWithValueSetOIDs.Contains(extensCur)) {
										listUniqueItemExtensionsWithValueSetOIDs.Add(extensCur);
										GenerateVitalsignEntry(vCur,"BPd");
									}
								}
								if(vCur.BpSystolic>0) {
									extensCur=CqmItemAbbreviation.Vital.ToString()+"2.16.840.1.113883.3.526.3.1032"+"Num"+vCur.EhrCqmVitalsignNum.ToString();
									if(!listUniqueItemExtensionsWithValueSetOIDs.Contains(extensCur)) {
										listUniqueItemExtensionsWithValueSetOIDs.Add(extensCur);
										GenerateVitalsignEntry(vCur,"BPs");
									}
								}
								if(vCur.BMI>0) {
									extensCur=CqmItemAbbreviation.Vital.ToString()+"2.16.840.1.113883.3.464.1003.121.12.1014"+"Num"+vCur.EhrCqmVitalsignNum.ToString();
									if(!listUniqueItemExtensionsWithValueSetOIDs.Contains(extensCur)) {
										listUniqueItemExtensionsWithValueSetOIDs.Add(extensCur);
										GenerateVitalsignEntry(vCur,"Ht");
									}
									extensCur=CqmItemAbbreviation.Vital.ToString()+"2.16.840.1.113883.3.464.1003.121.12.1015"+"Num"+vCur.EhrCqmVitalsignNum.ToString();
									if(!listUniqueItemExtensionsWithValueSetOIDs.Contains(extensCur)) {
										listUniqueItemExtensionsWithValueSetOIDs.Add(extensCur);
										GenerateVitalsignEntry(vCur,"Wt");
									}
									extensCur=CqmItemAbbreviation.Vital.ToString()+"2.16.840.1.113883.3.600.1.681"+vCur.EhrCqmVitalsignNum.ToString();
									if(!listUniqueItemExtensionsWithValueSetOIDs.Contains(extensCur)) {
										listUniqueItemExtensionsWithValueSetOIDs.Add(extensCur);
										GenerateVitalsignEntry(vCur,"BMI");
									}
								}
								//if(vCur.BMIPercentile>-1) {
								//	GenerateVitalsignEntry(vCur,"BMIp");
								//}
								extensCur=CqmItemAbbreviation.Vital.ToString()+vCur.EhrCqmVitalsignNum.ToString();
								if(listUniqueItemExtensions.Contains(extensCur)) {
									continue;
								}
								listUniqueItemExtensions.Add(extensCur);
								#region BuildPlainTextVersion
								string descript="";
								if(vCur.BpDiastolic>0) {
									descript="Physical Exam, Finding: Diastolic Blood Pressure";
									PatientDataTextTableRow(descript,"2.16.840.1.113883.3.526.3.1033","LOINC","8462-4",vCur.DateTaken,vCur.DateTaken,vCur.BpDiastolic.ToString()+" mmHg");
								}
								if(vCur.BpSystolic>0) {
									descript="Physical Exam, Finding: Systolic Blood Pressure";
									PatientDataTextTableRow(descript,"2.16.840.1.113883.3.526.3.1032","LOINC","8480-6",vCur.DateTaken,vCur.DateTaken,vCur.BpSystolic.ToString()+" mmHg");
								}
								if(vCur.BMI>0) {
									descript="Physical Exam, Finding: Height";
									PatientDataTextTableRow(descript,"2.16.840.1.113883.3.464.1003.121.12.1014","LOINC",vCur.HeightExamCode,vCur.DateTaken,vCur.DateTaken,vCur.Height.ToString()+" in");
									descript="Physical Exam, Finding: Weight";
									PatientDataTextTableRow(descript,"2.16.840.1.113883.3.464.1003.121.12.1015","LOINC",vCur.WeightExamCode,vCur.DateTaken,vCur.DateTaken,vCur.Weight.ToString()+" lb");
									descript="Physical Exam, Finding: BMI LOINC Value";
									PatientDataTextTableRow(descript,"2.16.840.1.113883.3.600.1.681","LOINC","39156-5",vCur.DateTaken,vCur.DateTaken,vCur.BMI.ToString("0.00")+" kg/m2");
								}
								//if(vCur.BMIPercentile>-1) {
								//	descript="Physical Exam, Finding: BMI Percentile";
								//	PatientDataTextTableRow(descript,"2.16.840.1.113883.3.464.1003.121.12.1012","LOINC",vCur.BMIExamCode,vCur.DateTaken,vCur.DateTaken,vCur.BMIPercentile.ToString());
								//}
								#endregion BuildPlainTextVersion
							}
						}
						#endregion vitalsigns
						_x.WriteEndElement();
					}
					End("tbody");
					End("table");
					End("text");
					XmlDocument doc=new XmlDocument();
					doc.LoadXml(strBuilderPatDataEntries.ToString());
					XmlElement elementClinicalDocument=doc.DocumentElement;
					for(int n=0;n<elementClinicalDocument.ChildNodes.Count;n++) {
						elementClinicalDocument.ChildNodes[n].WriteTo(_w);
					}
					Start("entry");
					Start("observation","classCode","OBS","moodCode","EVN");
					_w.WriteComment("Patient Characteristic Payer Template");
					TemplateId("2.16.840.1.113883.10.20.24.3.55");
					StartAndEnd("id","root",_strOIDInternalCQMRoot,"extension",CqmItemAbbreviation.Payer.ToString()+patCur.PatNum.ToString());
					StartAndEnd("code","code","48768-6","displayName","Payment source","codeSystem",strCodeSystemLoinc,"codeSystemName",strCodeSystemNameLoinc);
					StartAndEnd("statusCode","code","completed");
					Start("value");
					_w.WriteAttributeString("xsi","type",null,"CD");
					Attribs("code",ehrPatCur.PayorSopCode,"displayName",ehrPatCur.PayorDescription,"codeSystem","2.16.840.1.113883.3.221.5","codeSystemName","Source of Payment Typology");
					_w.WriteAttributeString("sdtc","valueSet",null,ehrPatCur.PayorValueSetOID);
					End("value");
					End("observation");
					End("entry");
					End("section");
					End("component");
					#endregion Patient Data
					End("structuredBody");
					#endregion QRDA I Body
					End("component");
					End("ClinicalDocument");
				}
				string xmlResult=strBuilder.ToString();
				dictPatNumXml.Add(patNumCur,xmlResult);
				SecurityLogs.MakeLogEntry(Permissions.Copy,patNumCur,"QRDA Category I generated");//Create audit log entry.
			}
			for(int i=0;i<listAllEhrPats.Count;i++) {
				Patient patCur=listAllEhrPats[i].EhrCqmPat;
				if(!dictPatNumXml.ContainsKey(patCur.PatNum)) {//every patient will be in the dictionary, this is just in case
					continue;
				}
				List<QualityMeasure> listPatQMs=dictPatNumListQMs[patCur.PatNum];
				for(int j=0;j<listPatQMs.Count;j++) {
					System.IO.File.WriteAllText(folderRoot+"\\Measure_"+listPatQMs[j].eMeasureNum+"\\"+patCur.PatNum+"_"+patCur.LName+"_"+patCur.FName+".xml",dictPatNumXml[patCur.PatNum]);
				}
			}
			try {
				string[] allMeasDirs=System.IO.Directory.GetDirectories(folderRoot);
				for(int i=0;i<allMeasDirs.Length;i++) {
					using(ZipFile zipCur=new ZipFile()) {
						string[] allPatFiles=System.IO.Directory.GetFiles(allMeasDirs[i]);
						zipCur.AddFiles(allPatFiles,"");
						zipCur.Save(allMeasDirs[i]+".zip");
						System.IO.Directory.Delete(allMeasDirs[i],true);
					}
				}
			}
			catch(Exception ex){
				throw new ApplicationException("Zipfile creation error: "+ex.Message);
			}
			_w.Flush();
			_w.Close();
			#endregion Cateogry I QRDA Documents
		}
Example #20
0
 public override void WriteTo(XmlWriter w)
 {
     // This doesn't seem to match up very well with w.WriteStartDocument()
     // so writing out PI here. (it used to be WriteRaw)
     w.WriteProcessingInstruction("xml", Value);
 }
Example #21
0
        /// <summary>
        /// Saves the current node to the specified XmlWriter.
        /// </summary>
        /// <param name="writer">The XmlWriter to which you want to save.</param>
        public void WriteTo(XmlWriter writer)
        {
            switch (_nodetype)
            {
                case HtmlNodeType.Comment:
                    writer.WriteComment(GetXmlComment((HtmlCommentNode) this));
                    break;

                case HtmlNodeType.Document:
                    writer.WriteProcessingInstruction("xml",
                                                      "version=\"1.0\" encoding=\"" +
                                                      _ownerdocument.GetOutEncoding().BodyName + "\"");
                    if (HasChildNodes)
                    {
                        foreach (HtmlNode subnode in ChildNodes)
                        {
                            subnode.WriteTo(writer);
                        }
                    }
                    break;

                case HtmlNodeType.Text:
                    string html = ((HtmlTextNode) this).Text;
                    writer.WriteString(html);
                    break;

                case HtmlNodeType.Element:
                    string name = _ownerdocument.OptionOutputUpperCase ? Name.ToUpper() : Name;

                    if (_ownerdocument.OptionOutputOriginalCase)
                        name = OriginalName;

                    writer.WriteStartElement(name);
                    WriteAttributes(writer, this);

                    if (HasChildNodes)
                    {
                        foreach (HtmlNode subnode in ChildNodes)
                        {
                            subnode.WriteTo(writer);
                        }
                    }
                    writer.WriteEndElement();
                    break;
            }
        }
Example #22
0
 public override void WriteProcessingInstruction(string name, string?text)
 {
     _writer.WriteProcessingInstruction(name, text);
 }
Example #23
0
File: EhrCCD.cs Project: mnisl/OD
		///<summary>Throws an exception if validation fails.</summary>
		private string GenerateCCD(Patient pat,string referralReason,bool hasAllergy,bool hasEncounter,bool hasFunctionalStatus,bool hasImmunization,bool hasMedication,bool hasPlanOfCare,bool hasProblem,bool hasProcedure,bool hasReferral,bool hasResult,bool hasSocialHistory,bool hasVitalSign,string instructions,DateTime date) {
			Medications.Refresh();
			string strErrors=ValidateAll(pat,date);
			if(strErrors!="") {
				throw new ApplicationException(strErrors);
			}
			_patOutCcd=pat;
			_hashCcdIds=new HashSet<string>();//The IDs only need to be unique within each CCD document.
			_hashCcdGuids=new HashSet<string>();//The UUIDs only need to be unique within each CCD document.
			XmlWriterSettings xmlSettings=new XmlWriterSettings();
			xmlSettings.Encoding=Encoding.UTF8;
			xmlSettings.OmitXmlDeclaration=true;
			xmlSettings.Indent=true;
			xmlSettings.IndentChars="   ";
			StringBuilder strBuilder=new StringBuilder();
			using(_w=XmlWriter.Create(strBuilder,xmlSettings)) {
				//Begin Clinical Document
				_w.WriteRaw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
				_w.WriteProcessingInstruction("xml-stylesheet","type=\"text/xsl\" href=\"ccd.xsl\"");
				_w.WriteWhitespace("\r\n");
				_w.WriteStartElement("ClinicalDocument","urn:hl7-org:v3");
				_w.WriteAttributeString("xmlns","xsi",null,"http://www.w3.org/2001/XMLSchema-instance");
				_w.WriteAttributeString("xsi","noNamespaceSchemaLocation",null,"Registry_Payment.xsd");
				_w.WriteAttributeString("xsi","schemaLocation",null,"urn:hl7-org:v3 http://xreg2.nist.gov:8080/hitspValidation/schema/cdar2c32/infrastructure/cda/C32_CDA.xsd");
				StartAndEnd("realmCode","code","US");
				StartAndEnd("typeId","root","2.16.840.1.113883.1.3","extension","POCD_HD000040");//template id to assert use of the CCD standard
				_w.WriteComment("US General Header Template");
				TemplateId("2.16.840.1.113883.10.20.22.1.1");
				_w.WriteComment("Conforms to CCD requirements");
				TemplateId("2.16.840.1.113883.10.20.22.1.2");
				Guid();
				StartAndEnd("code","code","34133-9","codeSystemName",strCodeSystemNameLoinc,"codeSystem",strCodeSystemLoinc,"displayName","Summarization of Episode Note");
				_w.WriteElementString("title","Continuity of Care Document");
				TimeElement("effectiveTime",DateTime.Now);
				StartAndEnd("confidentialityCode","code","N","codeSystem","2.16.840.1.113883.5.25");//Fixed value.  Confidentiality Code System.  Codes: N=(Normal), R=(Restricted),V=(Very Restricted)
				StartAndEnd("languageCode","code","en-US");
				Start("recordTarget");
				Start("patientRole");
				//TODO: We might need to assign a global GUID for each office so that the patient can be uniquely identified anywhere in the world.
				StartAndEnd("id","extension",pat.PatNum.ToString(),"root",OIDInternals.GetForType(IdentifierType.Patient).IDRoot);
				if(pat.SSN.Length==9) {
					StartAndEnd("id","extension",pat.SSN,"root","2.16.840.1.113883.4.1");//TODO: We might need to assign a global GUID for each office so that the patient can be uniquely identified anywhere in the world.
				}
				AddressUnitedStates(pat.Address,pat.Address2,pat.City,pat.State);//Validated
				if(pat.WirelessPhone.Trim()!="") {//There is at least one phone, due to validation.
					StartAndEnd("telecom","use","HP","value","tel:"+pat.WirelessPhone.Trim());
				}
				else if(pat.HmPhone.Trim()!="") {
					StartAndEnd("telecom","use","HP","value","tel:"+pat.HmPhone.Trim());
				}
				else if(pat.WkPhone.Trim()!="") {
					StartAndEnd("telecom","use","HP","value","tel:"+pat.WkPhone.Trim());
				}
				Start("patient");
				Start("name","use","L");
				_w.WriteElementString("given",pat.FName.Trim());//Validated
				if(pat.MiddleI!="") {
					_w.WriteElementString("given",pat.MiddleI.Trim());
				}
				_w.WriteElementString("family",pat.LName.Trim());//Validated
				if(pat.Title!="") {
					Start("suffix","qualifier","TITLE");
					_w.WriteString(pat.Title);
					End("suffix");
				}
				End("name");
				string strGender="UN";//Undifferentiated
				if(pat.Gender==PatientGender.Female) {
					strGender="F";
				}
				else if(pat.Gender==PatientGender.Male) {
					strGender="M";
				}
				StartAndEnd("administrativeGenderCode","code",strGender,"codeSystem","2.16.840.1.113883.5.1");//Will always be present, because there are only 3 options and the user is forced to make a choice in the UI.
				DateElement("birthTime",pat.Birthdate);//Validated
				if(pat.Position==PatientPosition.Divorced) {
					StartAndEnd("maritalStatusCode","code","D","displayName","Divorced","codeSystem","2.16.840.1.113883.5.2","codeSystemName","MaritalStatusCode");
				}
				else if(pat.Position==PatientPosition.Married) {
					StartAndEnd("maritalStatusCode","code","M","displayName","Married","codeSystem","2.16.840.1.113883.5.2","codeSystemName","MaritalStatusCode");
				}
				else if(pat.Position==PatientPosition.Widowed) {
					StartAndEnd("maritalStatusCode","code","W","displayName","Widowed","codeSystem","2.16.840.1.113883.5.2","codeSystemName","MaritalStatusCode");
				}
				else {//Single and child
					StartAndEnd("maritalStatusCode","code","S","displayName","Never Married","codeSystem","2.16.840.1.113883.5.2","codeSystemName","MaritalStatusCode");
				}
				bool isRaceFound=true;
				PatRace patRace=PatRace.DeclinedToSpecifyRace;
				bool isHispanicOrLatino=false;
				List<PatientRace> listPatientRaces=PatientRaces.GetForPatient(pat.PatNum);
				for(int i=0;i<listPatientRaces.Count;i++) {
					if(listPatientRaces[i].Race==PatRace.Hispanic) {
						isHispanicOrLatino=true;
					}
					else if(listPatientRaces[i].Race==PatRace.NotHispanic) {
						//Nothing to do. Flag is set to false by default.
					}
					else if(listPatientRaces[i].Race==PatRace.DeclinedToSpecifyRace) {
						isRaceFound=false;
					}
					else if(patRace==PatRace.DeclinedToSpecifyRace) {//Only once race can be specified in the CCD document.
						patRace=listPatientRaces[i].Race;
					}
				}
				if(isRaceFound) {//The patient did not decline to specify.
					if(patRace==PatRace.AfricanAmerican) {
						StartAndEnd("raceCode","code","2054-5","displayName","Black or African American","codeSystem","2.16.840.1.113883.6.238","codeSystemName","Race &amp; Ethnicity - CDC");
					}
					else if(patRace==PatRace.AmericanIndian) {
						StartAndEnd("raceCode","code","1002-5","displayName","American Indian or Alaska Native","codeSystem","2.16.840.1.113883.6.238","codeSystemName","Race &amp; Ethnicity - CDC");
					}
					else if(patRace==PatRace.Asian) {
						StartAndEnd("raceCode","code","2028-9","displayName","Asian","codeSystem","2.16.840.1.113883.6.238","codeSystemName","Race &amp; Ethnicity - CDC");
					}
					else if(patRace==PatRace.HawaiiOrPacIsland) {
						StartAndEnd("raceCode","code","2076-8","displayName","Native Hawaiian or Other Pacific Islander","codeSystem","2.16.840.1.113883.6.238","codeSystemName","Race &amp; Ethnicity - CDC");
					}
					else if(patRace==PatRace.White) {
						StartAndEnd("raceCode","code","2106-3","displayName","White","codeSystem","2.16.840.1.113883.6.238","codeSystemName","Race &amp; Ethnicity - CDC");
					}
					else {//Aboriginal, Other, Multiracial
						StartAndEnd("raceCode","code","2131-1","displayName","Other Race","codeSystem","2.16.840.1.113883.6.238","codeSystemName","Race &amp; Ethnicity - CDC");
					}
				}
				if(isHispanicOrLatino) {
					StartAndEnd("ethnicGroupCode","code","2135-2","displayName","Hispanic or Latino","codeSystem","2.16.840.1.113883.6.238","codeSystemName","Race &amp; Ethnicity - CDC");
				}
				else {//Not hispanic
					StartAndEnd("ethnicGroupCode","code","2186-5","displayName","Not Hispanic or Latino","codeSystem","2.16.840.1.113883.6.238","codeSystemName","Race &amp; Ethnicity - CDC");
				}
				if(_patOutCcd.Language.Trim().Length==3) {
					//This segment is optional, but we added it because it seems to be important to Drummond.
					//We can only allow 3 letter ISO-3 codes. It is possible that the user manually typed something which is 3 characters and is not an ISO code,
					//but we will enhance for that situation later. This should catch 98% of all situations for now.					
					Start("languageCommunication");
					StartAndEnd("languageCode","code",pat.Language.Trim().ToLower());
					End("languageCommunication");
				}
				End("patient");
				End("patientRole");
				End("recordTarget");
				//author--------------------------------------------------------------------------------------------------
				//The author element represents the creator of the clinical document.  The author may be a device, or a person.  Section 2.1.2, page 65
				//pat.PrivProv cannot be zero, because of validation below.
				Provider provAuthor=Providers.GetProv(pat.PriProv);//Uses primary provider, the primary provider cannot have the IsNotPerson set to true so they must have a first name.
				Start("author");
				TimeElement("time",DateTime.Now);
				Start("assignedAuthor");
				StartAndEnd("id","extension",provAuthor.NationalProvID,"root","2.16.840.1.113883.4.6");//Validated NPI. TODO: We might need to assign a global GUID for each office so that the provider can be uniquely identified anywhere in the world.
				StartAndEnd("code","code",GetTaxonomy(provAuthor),"codeSystem",strCodeSystemNucc,"codeSystemName",strCodeSystemNameNucc);
				AddressUnitedStates(PrefC.GetString(PrefName.PracticeAddress),PrefC.GetString(PrefName.PracticeAddress2),PrefC.GetString(PrefName.PracticeCity),PrefC.GetString(PrefName.PracticeST));//Validated
				string strPracticePhone=PrefC.GetString(PrefName.PracticePhone);//Validated
				strPracticePhone=strPracticePhone.Substring(0,3)+"-"+strPracticePhone.Substring(3,3)+"-"+strPracticePhone.Substring(6);
				StartAndEnd("telecom","use","WP","value","tel:"+strPracticePhone);//Validated
				Start("assignedPerson");
				Start("name");
				_w.WriteElementString("given",provAuthor.FName.Trim());//Validated
				_w.WriteElementString("family",provAuthor.LName.Trim());//Validated
				End("name");
				End("assignedPerson");
				End("assignedAuthor");
				End("author");
				//custodian------------------------------------------------------------------------------------------------
				//"Represents the organization in charge of maintaining the document." Section 2.1.5, page 72
				//The custodian is the steward that is entrusted with the care of the document. Every CDA document has exactly one custodian.
				Provider provCustodian=Providers.GetProv(PrefC.GetLong(PrefName.PracticeDefaultProv));
				Start("custodian");
				Start("assignedCustodian");
				Start("representedCustodianOrganization");
				StartAndEnd("id","extension",provCustodian.NationalProvID,"root","2.16.840.1.113883.4.6");//Validated NPI. We might need to assign a global GUID for each office so that the provider can be uniquely identified anywhere in the world.
				string custodianTitle=PrefC.GetString(PrefName.PracticeTitle);
				string custodianAddress=PrefC.GetString(PrefName.PracticeAddress);//Validated
				string custodianAddress2=PrefC.GetString(PrefName.PracticeAddress2);//Validated
				string custodianCity=PrefC.GetString(PrefName.PracticeCity);//Validated
				string custodianState=PrefC.GetString(PrefName.PracticeST);//Validated
				string custodianPhone=strPracticePhone;
				if(!PrefC.GetBool(PrefName.EasyNoClinics) && _patOutCcd.ClinicNum!=0) {
					Clinic clinicCustodian=Clinics.GetClinic(_patOutCcd.ClinicNum);
					custodianTitle=clinicCustodian.Description;
					custodianAddress=clinicCustodian.Address;//Validated
					custodianAddress2=clinicCustodian.Address2;//Validated
					custodianCity=clinicCustodian.City;//Validated
					custodianState=clinicCustodian.State;//Validated
					custodianPhone=clinicCustodian.Phone;//Validated
				}
				_w.WriteElementString("name",custodianTitle);//Validated
				StartAndEnd("telecom","use","WP","value","tel:"+custodianPhone);//Validated
				AddressUnitedStates(custodianAddress,custodianAddress2,custodianCity,custodianState);//Validated
				End("representedCustodianOrganization");
				End("assignedCustodian");
				End("custodian");
				//legalAuthenticator--------------------------------------------------------------------------------------
				//This element identifies the single person legally responsible for the document and must be present if the document has been legally authenticated.
				Provider provLegal=Providers.GetProv(PrefC.GetLong(PrefName.PracticeDefaultProv));
				if(!provLegal.IsNotPerson) {
					Start("legalAuthenticator");
					TimeElement("time",DateTime.Now);
					StartAndEnd("signatureCode","code","S");
					Start("assignedEntity");
					if(pat.PriProv>0) {
						provLegal=Providers.GetProv(pat.PriProv);
					}
					StartAndEnd("id","root","2.16.840.1.113883.4.6","extension",provLegal.NationalProvID);//Validated NPI. We might need to assign a global GUID for each office so that the provider can be uniquely identified anywhere in the world.
					string legalAuthAddress=PrefC.GetString(PrefName.PracticeAddress);//Validated
					string legalAuthAddress2=PrefC.GetString(PrefName.PracticeAddress2);//Validated
					string legalAuthCity=PrefC.GetString(PrefName.PracticeCity);//Validated
					string legalAuthState=PrefC.GetString(PrefName.PracticeST);//Validated
					string legalAuthPhone=strPracticePhone;
					if(!PrefC.GetBool(PrefName.EasyNoClinics) && _patOutCcd.ClinicNum!=0) {
						Clinic clinicAuth=Clinics.GetClinic(_patOutCcd.ClinicNum);
						legalAuthAddress=clinicAuth.Address;//Validated
						legalAuthAddress2=clinicAuth.Address2;//Validated
						legalAuthCity=clinicAuth.City;//Validated
						legalAuthState=clinicAuth.State;//Validated
						legalAuthPhone=clinicAuth.Phone;//Validated
					}
					AddressUnitedStates(legalAuthAddress,legalAuthAddress2,legalAuthCity,legalAuthState);//Validated
					StartAndEnd("telecom","use","WP","value","tel:"+legalAuthPhone);//Validated
					Start("assignedPerson");
					Start("name");
					_w.WriteElementString("given",provLegal.FName.Trim());//Validated
					_w.WriteElementString("family",provLegal.LName.Trim());//Validated
					End("name");
					End("assignedPerson");
					End("assignedEntity");
					End("legalAuthenticator");
				}
				Start("documentationOf","typeCode","DOC");
				Start("serviceEvent","classCode","PCPR");
				Start("effectiveTime");
				TimeElement("low",DateTime.Now);
				TimeElement("high",DateTime.Now);
				End("effectiveTime");
				Provider provPri=Providers.GetProv(_patOutCcd.PriProv);//Cannot be zero, because of validation below.
				if(!provPri.IsNotPerson) {
					Start("performer","typeCode","PRF");
					Start("assignedEntity");
					if(provPri==null) {
						provPri=Providers.GetProv(PrefC.GetLong(PrefName.PracticeDefaultProv));
					}
					StartAndEnd("id","root","2.16.840.1.113883.4.6","extension",provPri.NationalProvID);//Validated NPI. We might need to assign a global GUID for each office so that the provider can be uniquely identified anywhere in the world.
					AddressUnitedStates(PrefC.GetString(PrefName.PracticeAddress),PrefC.GetString(PrefName.PracticeAddress2),PrefC.GetString(PrefName.PracticeCity),PrefC.GetString(PrefName.PracticeST));//Validated
					StartAndEnd("telecom","use","WP","value","tel:"+strPracticePhone);//Validated
					Start("assignedPerson");
					Start("name");
					_w.WriteElementString("given",provPri.FName.Trim());//Validated
					_w.WriteElementString("family",provPri.LName.Trim());//Validated
					End("name");
					End("assignedPerson");
					End("assignedEntity");
					End("performer");
				}
				End("serviceEvent");
				End("documentationOf");
				_w.WriteComment(@"
=====================================================================================================
Body
=====================================================================================================");
				Start("component");
				Start("structuredBody");
				GenerateCcdSectionAllergies(hasAllergy);
				GenerateCcdSectionEncounters(hasEncounter);
				GenerateCcdSectionFunctionalStatus(hasFunctionalStatus);
				GenerateCcdSectionImmunizations(hasImmunization);
				GenerateCcdSectionInstructions(instructions);
				GenerateCcdSectionMedications(hasMedication);
				GenerateCcdSectionPlanOfCare(hasPlanOfCare);
				GenerateCcdSectionProblems(hasProblem);
				GenerateCcdSectionProcedures(hasProcedure);
				GenerateCcdSectionReasonForReferral(hasReferral,referralReason);
				GenerateCcdSectionResults(hasResult);//Lab Results
				GenerateCcdSectionSocialHistory(hasSocialHistory);
				GenerateCcdSectionVitalSigns(hasVitalSign);
				End("structuredBody");
				End("component");
				End("ClinicalDocument");
			}
			SecurityLogs.MakeLogEntry(Permissions.Copy,pat.PatNum,"CCD generated");			//Create audit log entry.
			return strBuilder.ToString();
		}
Example #24
0
 // Writes the content (inner XML) of the current node into the provided XmlWriter.
 private async Task WriteNodeAsync(XmlWriter xtw, bool defattr)
 {
     int d = this.NodeType == XmlNodeType.None ? -1 : this.Depth;
     while (await this.ReadAsync().ConfigureAwait(false) && (d < this.Depth))
     {
         switch (this.NodeType)
         {
             case XmlNodeType.Element:
                 xtw.WriteStartElement(this.Prefix, this.LocalName, this.NamespaceURI);
                 xtw.WriteAttributes(this, defattr);
                 if (this.IsEmptyElement)
                 {
                     xtw.WriteEndElement();
                 }
                 break;
             case XmlNodeType.Text:
                 xtw.WriteString(await this.GetValueAsync().ConfigureAwait(false));
                 break;
             case XmlNodeType.Whitespace:
             case XmlNodeType.SignificantWhitespace:
                 xtw.WriteWhitespace(await this.GetValueAsync().ConfigureAwait(false));
                 break;
             case XmlNodeType.CDATA:
                 xtw.WriteCData(this.Value);
                 break;
             case XmlNodeType.EntityReference:
                 xtw.WriteEntityRef(this.Name);
                 break;
             case XmlNodeType.XmlDeclaration:
             case XmlNodeType.ProcessingInstruction:
                 xtw.WriteProcessingInstruction(this.Name, this.Value);
                 break;
             case XmlNodeType.DocumentType:
                 xtw.WriteDocType(this.Name, this.GetAttribute("PUBLIC"), this.GetAttribute("SYSTEM"), this.Value);
                 break;
             case XmlNodeType.Comment:
                 xtw.WriteComment(this.Value);
                 break;
             case XmlNodeType.EndElement:
                 xtw.WriteFullEndElement();
                 break;
         }
     }
     if (d == this.Depth && this.NodeType == XmlNodeType.EndElement)
     {
         await ReadAsync().ConfigureAwait(false);
     }
 }
Example #25
0
		public MoonLogProvider ()
		{
			XmlWriterSettings settings;

			DateTime now = DateTime.Now;
			Uri docuri = HtmlPage.Document.DocumentUri;

			if (docuri.Scheme != "http" && docuri.Scheme != "https") {
				Console.WriteLine ("MoonLogProvider: Disabled since we're not loading the test from http(s).");
				return;
			}

			baseuri = string.Concat (docuri.Scheme, "://", docuri.Host, ":", docuri.Port.ToString (), docuri.LocalPath.Substring (0, docuri.LocalPath.Length - System.IO.Path.GetFileName (docuri.LocalPath).Length));

			// Create a unique filename
			filename = string.Format ("moon-unit-log-{0}-{1}.xml",
				now.ToUniversalTime ().ToString ("yyyy-MM-dd-HH-mm-ss", CultureInfo.InvariantCulture.DateTimeFormat),
				DateTime.Now.Ticks.ToString (CultureInfo.InvariantCulture.NumberFormat));

			settings = new XmlWriterSettings ();
			settings.Indent = true;
			settings.Encoding = Encoding.UTF8;
			writer = XmlWriter.Create (text, settings);
			writer.WriteStartDocument ();
			writer.WriteProcessingInstruction ("xml-stylesheet", "type='text/xsl' href='moon-unit-log.xsl'");

			totals = new int [typeof (TestOutcome).GetFields (BindingFlags.Static | BindingFlags.Public).Length + 1];
			KnownIssueIndex = totals.Length - 1;
		}
Example #26
0
 // Write this node and all of its contents to a specified XmlWriter.
 public override void WriteTo(XmlWriter w)
 {
     w.WriteProcessingInstruction(Name, Value);
 }
Example #27
0
        /// <summary>
        /// Replay all cached events to an XmlWriter.
        /// </summary>
        public void EventsToWriter(XmlWriter writer)
        {
            XmlEvent[] page;
            int        idxPage, idxEvent;

            byte[]       bytes;
            char[]       chars;
            XmlRawWriter rawWriter;

            // Special-case single text node at the top-level
            if (this.singleText.Count != 0)
            {
                writer.WriteString(this.singleText.GetResult());
                return;
            }

            rawWriter = writer as XmlRawWriter;

            // Loop over set of pages
            for (idxPage = 0; idxPage < this.pages.Count; idxPage++)
            {
                page = this.pages[idxPage];

                // Loop over events in each page
                for (idxEvent = 0; idxEvent < page.Length; idxEvent++)
                {
                    switch (page[idxEvent].EventType)
                    {
                    case XmlEventType.Unknown:
                        // No more events
                        Debug.Assert(idxPage + 1 == this.pages.Count);
                        return;

                    case XmlEventType.DocType:
                        writer.WriteDocType(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3, (string)page[idxEvent].Object);
                        break;

                    case XmlEventType.StartElem:
                        writer.WriteStartElement(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3);
                        break;

                    case XmlEventType.StartAttr:
                        writer.WriteStartAttribute(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3);
                        break;

                    case XmlEventType.EndAttr:
                        writer.WriteEndAttribute();
                        break;

                    case XmlEventType.CData:
                        writer.WriteCData(page[idxEvent].String1);
                        break;

                    case XmlEventType.Comment:
                        writer.WriteComment(page[idxEvent].String1);
                        break;

                    case XmlEventType.PI:
                        writer.WriteProcessingInstruction(page[idxEvent].String1, page[idxEvent].String2);
                        break;

                    case XmlEventType.Whitespace:
                        writer.WriteWhitespace(page[idxEvent].String1);
                        break;

                    case XmlEventType.String:
                        writer.WriteString(page[idxEvent].String1);
                        break;

                    case XmlEventType.Raw:
                        writer.WriteRaw(page[idxEvent].String1);
                        break;

                    case XmlEventType.EntRef:
                        writer.WriteEntityRef(page[idxEvent].String1);
                        break;

                    case XmlEventType.CharEnt:
                        writer.WriteCharEntity((char)page[idxEvent].Object);
                        break;

                    case XmlEventType.SurrCharEnt:
                        chars = (char[])page[idxEvent].Object;
                        writer.WriteSurrogateCharEntity(chars[0], chars[1]);
                        break;

                    case XmlEventType.Base64:
                        bytes = (byte[])page[idxEvent].Object;
                        writer.WriteBase64(bytes, 0, bytes.Length);
                        break;

                    case XmlEventType.BinHex:
                        bytes = (byte[])page[idxEvent].Object;
                        writer.WriteBinHex(bytes, 0, bytes.Length);
                        break;

                    case XmlEventType.XmlDecl1:
                        if (rawWriter != null)
                        {
                            rawWriter.WriteXmlDeclaration((XmlStandalone)page[idxEvent].Object);
                        }
                        break;

                    case XmlEventType.XmlDecl2:
                        if (rawWriter != null)
                        {
                            rawWriter.WriteXmlDeclaration(page[idxEvent].String1);
                        }
                        break;

                    case XmlEventType.StartContent:
                        if (rawWriter != null)
                        {
                            rawWriter.StartElementContent();
                        }
                        break;

                    case XmlEventType.EndElem:
                        if (rawWriter != null)
                        {
                            rawWriter.WriteEndElement(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3);
                        }
                        else
                        {
                            writer.WriteEndElement();
                        }
                        break;

                    case XmlEventType.FullEndElem:
                        if (rawWriter != null)
                        {
                            rawWriter.WriteFullEndElement(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3);
                        }
                        else
                        {
                            writer.WriteFullEndElement();
                        }
                        break;

                    case XmlEventType.Nmsp:
                        if (rawWriter != null)
                        {
                            rawWriter.WriteNamespaceDeclaration(page[idxEvent].String1, page[idxEvent].String2);
                        }
                        else
                        {
                            writer.WriteAttributeString("xmlns", page[idxEvent].String1, XmlReservedNs.NsXmlNs, page[idxEvent].String2);
                        }
                        break;

                    case XmlEventType.EndBase64:
                        if (rawWriter != null)
                        {
                            rawWriter.WriteEndBase64();
                        }
                        break;

                    case XmlEventType.Close:
                        writer.Close();
                        break;

                    case XmlEventType.Flush:
                        writer.Flush();
                        break;

                    case XmlEventType.Dispose:
                        ((IDisposable)writer).Dispose();
                        break;

                    default:
                        Debug.Assert(false, "Unknown event: " + page[idxEvent].EventType);
                        break;
                    }
                }
            }

            Debug.Assert(false, "Unknown event should be added to end of event sequence.");
        }
Example #28
0
 ///<summary>Generates all the xml up to the point where the first statement would go.</summary>
 public static void GeneratePracticeInfo(XmlWriter writer)
 {
     writer.WriteProcessingInstruction("xml","version = \"1.0\" standalone=\"yes\"");
     writer.WriteStartElement("Statements");
 }
Example #29
0
        /// <summary>
        /// Write out the processing instruction that contains the line number information.
        /// </summary>
        /// <param name="reader">The xml reader.</param>
        /// <param name="writer">The xml writer.</param>
        /// <param name="offset">The artificial offset to use when writing the current line number.  Used for the foreach processing.</param>
        private void WriteProcessingInstruction(XmlReader reader, XmlWriter writer, int offset)
        {
            this.UpdateInformation(reader, offset);

            if (!this.currentLineNumberWritten)
            {
                SourceLineNumberCollection sourceLineNumbers = this.GetCurrentSourceLineNumbers();

                // write the encoded source line numbers as a string into the "ln" processing instruction
                writer.WriteProcessingInstruction(Preprocessor.LineNumberElementName, sourceLineNumbers.EncodedSourceLineNumbers);
            }
        }
        private void WriteNode(XmlWriter xtw, bool defattr)
        {
            int num = (this.NodeType == XmlNodeType.None) ? -1 : this.Depth;
            while (this.Read() && (num < this.Depth))
            {
                switch (this.NodeType)
                {
                    case XmlNodeType.Element:
                        xtw.WriteStartElement(this.Prefix, this.LocalName, this.NamespaceURI);
                        ((XmlTextWriter) xtw).QuoteChar = this.QuoteChar;
                        xtw.WriteAttributes(this, defattr);
                        if (this.IsEmptyElement)
                        {
                            xtw.WriteEndElement();
                        }
                        break;

                    case XmlNodeType.Text:
                        xtw.WriteString(this.Value);
                        break;

                    case XmlNodeType.CDATA:
                        xtw.WriteCData(this.Value);
                        break;

                    case XmlNodeType.EntityReference:
                        xtw.WriteEntityRef(this.Name);
                        break;

                    case XmlNodeType.ProcessingInstruction:
                    case XmlNodeType.XmlDeclaration:
                        xtw.WriteProcessingInstruction(this.Name, this.Value);
                        break;

                    case XmlNodeType.Comment:
                        xtw.WriteComment(this.Value);
                        break;

                    case XmlNodeType.DocumentType:
                        xtw.WriteDocType(this.Name, this.GetAttribute("PUBLIC"), this.GetAttribute("SYSTEM"), this.Value);
                        break;

                    case XmlNodeType.Whitespace:
                    case XmlNodeType.SignificantWhitespace:
                        xtw.WriteWhitespace(this.Value);
                        break;

                    case XmlNodeType.EndElement:
                        xtw.WriteFullEndElement();
                        break;
                }
            }
            if ((num == this.Depth) && (this.NodeType == XmlNodeType.EndElement))
            {
                this.Read();
            }
        }
Example #31
0
        public void EventsToWriter(XmlWriter writer)
        {
            if (this.singleText.Count != 0)
            {
                writer.WriteString(this.singleText.GetResult());
            }
            else
            {
                XmlRawWriter writer2 = writer as XmlRawWriter;
                for (int i = 0; i < this.pages.Count; i++)
                {
                    XmlEvent[] eventArray = this.pages[i];
                    for (int j = 0; j < eventArray.Length; j++)
                    {
                        byte[] buffer;
                        switch (eventArray[j].EventType)
                        {
                        case XmlEventType.Unknown:
                            return;

                        case XmlEventType.DocType:
                        {
                            writer.WriteDocType(eventArray[j].String1, eventArray[j].String2, eventArray[j].String3, (string)eventArray[j].Object);
                            continue;
                        }

                        case XmlEventType.StartElem:
                        {
                            writer.WriteStartElement(eventArray[j].String1, eventArray[j].String2, eventArray[j].String3);
                            continue;
                        }

                        case XmlEventType.StartAttr:
                        {
                            writer.WriteStartAttribute(eventArray[j].String1, eventArray[j].String2, eventArray[j].String3);
                            continue;
                        }

                        case XmlEventType.EndAttr:
                        {
                            writer.WriteEndAttribute();
                            continue;
                        }

                        case XmlEventType.CData:
                        {
                            writer.WriteCData(eventArray[j].String1);
                            continue;
                        }

                        case XmlEventType.Comment:
                        {
                            writer.WriteComment(eventArray[j].String1);
                            continue;
                        }

                        case XmlEventType.PI:
                        {
                            writer.WriteProcessingInstruction(eventArray[j].String1, eventArray[j].String2);
                            continue;
                        }

                        case XmlEventType.Whitespace:
                        {
                            writer.WriteWhitespace(eventArray[j].String1);
                            continue;
                        }

                        case XmlEventType.String:
                        {
                            writer.WriteString(eventArray[j].String1);
                            continue;
                        }

                        case XmlEventType.Raw:
                        {
                            writer.WriteRaw(eventArray[j].String1);
                            continue;
                        }

                        case XmlEventType.EntRef:
                        {
                            writer.WriteEntityRef(eventArray[j].String1);
                            continue;
                        }

                        case XmlEventType.CharEnt:
                        {
                            writer.WriteCharEntity((char)eventArray[j].Object);
                            continue;
                        }

                        case XmlEventType.SurrCharEnt:
                        {
                            char[] chArray = (char[])eventArray[j].Object;
                            writer.WriteSurrogateCharEntity(chArray[0], chArray[1]);
                            continue;
                        }

                        case XmlEventType.Base64:
                        {
                            buffer = (byte[])eventArray[j].Object;
                            writer.WriteBase64(buffer, 0, buffer.Length);
                            continue;
                        }

                        case XmlEventType.BinHex:
                        {
                            buffer = (byte[])eventArray[j].Object;
                            writer.WriteBinHex(buffer, 0, buffer.Length);
                            continue;
                        }

                        case XmlEventType.XmlDecl1:
                        {
                            if (writer2 != null)
                            {
                                writer2.WriteXmlDeclaration((XmlStandalone)eventArray[j].Object);
                            }
                            continue;
                        }

                        case XmlEventType.XmlDecl2:
                        {
                            if (writer2 != null)
                            {
                                writer2.WriteXmlDeclaration(eventArray[j].String1);
                            }
                            continue;
                        }

                        case XmlEventType.StartContent:
                        {
                            if (writer2 != null)
                            {
                                writer2.StartElementContent();
                            }
                            continue;
                        }

                        case XmlEventType.EndElem:
                        {
                            if (writer2 == null)
                            {
                                break;
                            }
                            writer2.WriteEndElement(eventArray[j].String1, eventArray[j].String2, eventArray[j].String3);
                            continue;
                        }

                        case XmlEventType.FullEndElem:
                        {
                            if (writer2 == null)
                            {
                                goto Label_0367;
                            }
                            writer2.WriteFullEndElement(eventArray[j].String1, eventArray[j].String2, eventArray[j].String3);
                            continue;
                        }

                        case XmlEventType.Nmsp:
                        {
                            if (writer2 == null)
                            {
                                goto Label_0394;
                            }
                            writer2.WriteNamespaceDeclaration(eventArray[j].String1, eventArray[j].String2);
                            continue;
                        }

                        case XmlEventType.EndBase64:
                        {
                            if (writer2 != null)
                            {
                                writer2.WriteEndBase64();
                            }
                            continue;
                        }

                        case XmlEventType.Close:
                        {
                            writer.Close();
                            continue;
                        }

                        case XmlEventType.Flush:
                        {
                            writer.Flush();
                            continue;
                        }

                        case XmlEventType.Dispose:
                        {
                            writer.Dispose();
                            continue;
                        }

                        default:
                        {
                            continue;
                        }
                        }
                        writer.WriteEndElement();
                        continue;
Label_0367:
                        writer.WriteFullEndElement();
                        continue;
Label_0394:
                        writer.WriteAttributeString("xmlns", eventArray[j].String1, "http://www.w3.org/2000/xmlns/", eventArray[j].String2);
                    }
                }
            }
        }
Example #32
0
        public static void WriteShallowNode(XmlReader reader, XmlWriter writer)
        {
            //Console.WriteLine("{0}: {1}", reader.NodeType, reader.Name);

            switch(reader.NodeType) {
                case XmlNodeType.Element:
                    writer.WriteStartElement(reader.Prefix	, reader.LocalName, reader.NamespaceURI);
                    writer.WriteAttributes(reader, true);
                    if(reader.IsEmptyElement)
                        writer.WriteEndElement();
                    break;
                case XmlNodeType.Text:
                    writer.WriteString(reader.Value);
                    break;
                case XmlNodeType.Whitespace:
                case XmlNodeType.SignificantWhitespace:
                    writer.WriteWhitespace(reader.Value);
                    break;
                case XmlNodeType.CDATA:
                    writer.WriteCData(reader.Value);
                    break;
                case XmlNodeType.EntityReference:
                    writer.WriteEntityRef(reader.Name);
                    break;
                case XmlNodeType.XmlDeclaration:
                case XmlNodeType.ProcessingInstruction:
                    writer.WriteProcessingInstruction(reader.Name, reader.Value);
                    break;
                case XmlNodeType.DocumentType:
                    writer.WriteDocType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value);
                    break;
                case XmlNodeType.Comment:
                    writer.WriteComment(reader.Value);
                    break;
                case XmlNodeType.EndElement:
                    writer.WriteFullEndElement();
                    break;
            }
        }
		///<summary>This method generates the entire Category III aggregate information document and places it in the path supplied in folderRoot\QRDA_Category_III.xml.</summary>
		private static void GenerateQRDACatThree(List<QualityMeasure> listQMs,DateTime dateStart,DateTime dateEnd,string folderRoot) {
			XmlWriterSettings xmlSettings=new XmlWriterSettings();
			xmlSettings.Encoding=Encoding.UTF8;
			xmlSettings.OmitXmlDeclaration=true;
			xmlSettings.Indent=true;
			xmlSettings.IndentChars="\t";
			using(_w=XmlWriter.Create(folderRoot+"\\QRDA_Category_III.xml",xmlSettings)) {
				//Begin Clinical Document
				_w.WriteProcessingInstruction("xml-stylesheet","type=\"text/xsl\" href=\"qrda.xsl\"");
				_w.WriteWhitespace("\r\n");
				_w.WriteStartElement("ClinicalDocument","urn:hl7-org:v3");
				_w.WriteAttributeString("xmlns","xsi",null,"http://www.w3.org/2001/XMLSchema-instance");
				_w.WriteAttributeString("xsi","schemaLocation",null,"urn:./CDA.xsd");
				_w.WriteAttributeString("xmlns","voc",null,"urn:hl7-org:v3/voc");
				#region QRDA III Header
				_w.WriteComment("QRDA III Header");
				StartAndEnd("realmCode","code","US");
				StartAndEnd("typeId","root","2.16.840.1.113883.1.3","extension","POCD_HD000040");//template id to assert use of the CDA standard
				_w.WriteComment("QRDA Category III Release 1 Template");
				TemplateId("2.16.840.1.113883.10.20.27.1.1");
				_w.WriteComment("This is the globally unique identifier for this QRDA III document");
				Guid();
				_w.WriteComment("QRDA III document type code");
				StartAndEnd("code","code","55184-6","codeSystem",strCodeSystemLoinc,"codeSystemName",strCodeSystemNameLoinc,"displayName","Quality Reporting Document Architecture Calculated Summary Report");
				_w.WriteElementString("title","QRDA Calculated Summary Report for CMS Measures 68, 69, 74, 75, 127, 138, 147, 155, and 165");
				_w.WriteComment("This is the document creation time");
				TimeElement("effectiveTime",DateTime.Now);
				StartAndEnd("confidentialityCode","code","N","codeSystem","2.16.840.1.113883.5.25");//Fixed value.  Confidentiality Code System.  Codes: N=(Normal), R=(Restricted),V=(Very Restricted)
				StartAndEnd("languageCode","code","en-US");
				#region recordTarget
				_w.WriteComment("Record Target and ID - but ID is nulled to NA. This is an aggregate summary report. Therefore CDA's required patient identifier is nulled.");
				Start("recordTarget");
				Start("patientRole");
				StartAndEnd("id","nullFlavor","NA");
				End("patientRole");
				End("recordTarget");
				#endregion recordTarget
				#region comments
				//The author element represents the creator of the clinical document.  The author may be a device, or a person.
				//Participant Scenarios in a QRDA Category III Document (section 2.3, page 29)
				//Several possible scenarios given, the first sounds like it applies to us
				//Scenario - QRDA is wholly constructed automatically by device
				//Author - Device
				//Custodian - Organization that owns and reports the data (e.g. hospital, dental practice)
				//Legal Authenticator - A designated person in the organization (may be assigned to the report automatically)
				//We will generate a device author element, a practice custodian element, and a Legal Authenticator element using the practice default provider
				#endregion comments
				#region author
				Start("author");
				TimeElement("time",DateTime.Now);
				Start("assignedAuthor");
				StartAndEnd("id","root","2.16.840.1.113883.3.4337","assigningAuthorityName","HL7 OID Registry");
				Start("assignedAuthoringDevice");
				_w.WriteElementString("softwareName","Open Dental version "+PrefC.GetString(PrefName.ProgramVersion));
				End("assignedAuthoringDevice");
				Start("representedOrganization");
				_w.WriteElementString("name",PrefC.GetString(PrefName.PracticeTitle));//Validated
				End("representedOrganizaion");
				End("assignedAuthor");
				End("author");
				#endregion author
				#region custodian
				//Represents the organization in charge of maintaining the document.
				//The custodian is the steward that is entrusted with the care of the document. Every CDA document has exactly one custodian.
				Start("custodian");
				Start("assignedCustodian");
				Start("representedCustodianOrganization");
				StartAndEnd("id","root",_strOIDInternalRoot);//This is the root assigned to the practice, based on the OD root 2.16.840.1.113883.3.4337
				_w.WriteElementString("name",PrefC.GetString(PrefName.PracticeTitle));//Validated
				End("representedCustodianOrganization");
				End("assignedCustodian");
				End("custodian");
				#endregion custodian
				#region legalAuthenticator
				//This element identifies the single person legally responsible for the document and must be present if the document has been legally authenticated.
				Start("legalAuthenticator");
				TimeElement("time",DateTime.Now);
				StartAndEnd("signatureCode","code","S");
				Start("assignedEntity");
				Provider provLegal=Providers.GetProv(PrefC.GetLong(PrefName.PracticeDefaultProv));
				StartAndEnd("id","root","2.16.840.1.113883.4.6","extension",provLegal.NationalProvID,"assigningAuthorityName","NPI");//Validated NPI
				Start("representedOrganization");
				StartAndEnd("id","root",_strOIDInternalRoot);//This is the root assigned to the practice, based on the OD root 2.16.840.1.113883.3.4337
				_w.WriteElementString("name",PrefC.GetString(PrefName.PracticeTitle));//Validated
				End("representedOrganization");
				End("assignedEntity");
				End("legalAuthenticator");
				#endregion legalAuthenticator
				#region documentationOf
				//The documentationOf service event can contain identifiers for all of the (one or more) providers involved, using the serviceEvent/performer elements.
				//A serviceEvent/performer element must be present for each performer reporting data to a quality organization.
				Start("documentationOf","typeCode","DOC");
				Start("serviceEvent","classCode","PCPR");//PCPR is HL7ActClass code for Care Provision
				_w.WriteComment("Care Provision");
				Start("effectiveTime");
				DateElement("low",dateStart);
				DateElement("high",dateEnd);
				End("effectiveTime");
				Start("performer","typeCode","PRF");
				Start("time");
				StartAndEnd("low","value",dateStart.ToString("yyyyMMdd")+"000000");
				StartAndEnd("high","value",dateEnd.ToString("yyyyMMdd")+"235959");
				End("time");
				Start("assignedEntity");
				if(_provOutQrda.NationalProvID!="") {
					_w.WriteComment("This is the provider NPI");
					StartAndEnd("id","root","2.16.840.1.113883.4.6","extension",_provOutQrda.NationalProvID);
				}
				if(_provOutQrda.UsingTIN && _provOutQrda.SSN!="") {
					_w.WriteComment("This is the provider TIN");
					StartAndEnd("id","root","2.16.840.1.113883.4.2","extension",_provOutQrda.SSN);
				}
				_w.WriteComment("This is the practice OID provider root and Open Dental assigned ProvNum extension");
				StartAndEnd("id","root",_strOIDInternalProvRoot,"extension",_provOutQrda.ProvNum.ToString());
				Start("representedOrganization");
				//we don't currently have an organization level TIN or an organization Facility CMS Certification Number (CCN)
				//both id's are identified as "SHOULD" elements.  We will include the practice name
				_w.WriteElementString("name",PrefC.GetString(PrefName.PracticeTitle));//Validated
				End("representedOrganization");
				End("assignedEntity");
				End("performer");
				End("serviceEvent");
				End("documentationOf");
				#endregion participant
				#endregion QRDA III Header
				#region QRDA III Body
				Start("component");
				Start("structuredBody");
				#region reportingParameters component
				_w.WriteComment("Reporting Parameters Component");
				Start("component");
				Start("section");
				_w.WriteComment("Reporting Parameters Section Template");
				TemplateId("2.16.840.1.113883.10.20.17.2.1");
				_w.WriteComment("QRDA Category III Reporting Parameters Section Template");
				TemplateId("2.16.840.1.113883.10.20.27.2.2");
				StartAndEnd("code","code","55187-9","displayName","Reporting Parameters","codeSystem",strCodeSystemLoinc,"codeSystemName",strCodeSystemNameLoinc);
				_w.WriteElementString("title","Reporting Parameters");
				Start("text");
				Start("list");
				_w.WriteElementString("item","Reporting period: "+dateStart.ToString("MMMM dd, yyyy")+" 00:00 - "+dateEnd.ToString("MMMM dd, yyyy")+" 23:59");
				End("list");
				End("text");
				Start("entry","typeCode","DRIV");
				Start("act","classCode","ACT","moodCode","EVN");
				_w.WriteComment("Reporting Parameters Act Template");
				TemplateId("2.16.840.1.113883.10.20.17.3.8");
				StartAndEnd("code","code","252116004","displayName","Observation Parameters","codeSystem",strCodeSystemSnomed,"codeSystemName",strCodeSystemNameSnomed);
				Start("effectiveTime");
				_w.WriteComment("The first day of the reporting period");
				DateElement("low",dateStart);
				_w.WriteComment("The last day of the reporting period");
				DateElement("high",dateEnd);
				End("effectiveTime");
				End("act");
				End("entry");
				End("section");
				End("component");
				#endregion reportingParameters component
				#region measure component
				_w.WriteComment("Measures Component");
				Start("component");
				Start("section");
				//structuredBody[component[section(reportingParameters)]][component2[section(measureSection)]]]
				_w.WriteComment("Measure Section Template");
				TemplateId("2.16.840.1.113883.10.20.24.2.2");
				_w.WriteComment("QRDA Category III Measure Section Template");
				TemplateId("2.16.840.1.113883.10.20.27.2.1");
				StartAndEnd("code","code","55186-1","displayName","Measure Section","codeSystem",strCodeSystemLoinc,"codeSystemName",strCodeSystemNameLoinc);
				_w.WriteElementString("title","Measure Section");
				#region TEXT SECTION
				Start("text");
				List<Dictionary<string,int>> listPopCountDicts=new List<Dictionary<string,int>>();
				//get the indexes of the three stratifications
				int s1Indx=(int)QualityType2014.CariesPrevent_1;
				int s2Indx=(int)QualityType2014.CariesPrevent_2;
				int s3Indx=(int)QualityType2014.CariesPrevent_3;
				//get the index of the WeightAdult (population 2)
				int pop2Indx=(int)QualityType2014.WeightAdult;
				//get the indexes of the additional two numerators and 2 stratifications
				int numer2=(int)QualityType2014.WeightChild_1_2;
				int numer3=(int)QualityType2014.WeightChild_1_3;
				int s1numer1Indx=(int)QualityType2014.WeightChild_2_1;
				int s1numer2Indx=(int)QualityType2014.WeightChild_2_2;
				int s1numer3Indx=(int)QualityType2014.WeightChild_2_3;
				int s2numer1Indx=(int)QualityType2014.WeightChild_3_1;
				int s2numer2Indx=(int)QualityType2014.WeightChild_3_2;
				int s2numer3Indx=(int)QualityType2014.WeightChild_3_3;
				int numPops=1;//if set to two or three, this will generate additional sets of population data (measure 69 has two populations, measure 155 has 3 numerators)
				for(int i=0;i<listQMs.Count;i++) {
					//_listExtraPopIndxs will contain all of the Type2014 enum types that are stratifications or extra populations of other measures, so skip them here
					if(_listExtraPopIndxs.Contains(i)) {
						continue;
					}
					switch(i) {
						case (int)QualityType2014.WeightOver65:
							//this wil create 2 populations, one for weight ages 18-64 and one for weight 65+
							numPops=2;
							break;
						case (int)QualityType2014.WeightChild_1_1:
							//this will create 3 data sections, one for each numerator
							//We will have Numerator 1 with ipp,denom,except,exclus,numer data, Numerator 2 data, and Numerator 3 data, each with their own stratifications
							numPops=3;
							break;
					}
					if(listQMs[i].Type2014==QualityType2014.MedicationsEntered) {
						listPopCountDicts=FillDictPopCounts(listQMs[i].ListEhrPats,listQMs[i].DictPatNumListEncounters);
					}
					else {
						listPopCountDicts=FillDictPopCounts(listQMs[i].ListEhrPats,null);
					}
					Start("table","border","1","width","100%");
					Start("thead");
					Start("tr");
					_w.WriteElementString("th","eMeasure Identifier (MAT)");
					_w.WriteElementString("th","eMeasure Title");
					_w.WriteElementString("th","Version neutral identifier");
					_w.WriteElementString("th","eMeasure Version Number");
					_w.WriteElementString("th","Version specific identifier");
					End("tr");
					End("thead");
					Start("tbody");
					MeasureTextTableRow(listQMs[i].eMeasureTitle,listQMs[i].eMeasureNum,listQMs[i].eMeasureVNeutralId,listQMs[i].eMeasureVersion,listQMs[i].eMeasureVSpecificId);
					End("tbody");
					End("table");
					for(int p=0;p<numPops;p++) {//usually only runs 1 loop, measure 69 has two populations, and measure 155 has 3 numerators, in which case it will run more than once
						int measureIndx=i;
						if(numPops==2) {
							if(p==0) {
								StartAndEnd("br");
							}
							Start("content","styleCode","Bold");
							_w.WriteString("Population "+(p+1).ToString()+":");
							End("content");
							if(p>0) {//fill stratification data with supplemental data from other population (only used by measure 69)
								measureIndx=pop2Indx;
								listPopCountDicts=FillDictPopCounts(listQMs[measureIndx].ListEhrPats,null);
							}
						}
						else if(numPops==3) {
							if(p==0) {
								StartAndEnd("br");
							}
							Start("content","styleCode","Bold");
							_w.WriteString("Numerator "+(p+1).ToString()+":");
							End("content");
							if(p==1) {//second iteration, fill dictionaries with numerator 2 data for stratifications
								measureIndx=numer2;
								listPopCountDicts=FillDictPopCounts(listQMs[measureIndx].ListEhrPats,null);
							}
							if(p==2) {//third iteration, fill dictionaries with numerator 3 data for stratifications
								measureIndx=numer3;
								listPopCountDicts=FillDictPopCounts(listQMs[measureIndx].ListEhrPats,null);
							}
						}
						Start("list");
						#region Performeance and Reporting Rate TEXT VERSION
						Start("item");
						Start("content","styleCode","Bold");
						_w.WriteString("Performance Rate");
						End("content");
						if(listQMs[measureIndx].ListEhrPats.Count==0) {
							_w.WriteString(": NA");
						}
						else {
							_w.WriteString(": "+listQMs[measureIndx].PerformanceRate.ToString("0.00")+"%");
						}
						End("item");
						Start("item");
						Start("content","styleCode","Bold");
						_w.WriteString("Reporting Rate");
						End("content");
						if(listQMs[measureIndx].ListEhrPats.Count==0) {
							_w.WriteString(": NA");
						}
						else {
							_w.WriteString(": "+listQMs[measureIndx].ReportingRate.ToString("0.00")+"%");
						}
						End("item");
						#endregion Performeance and Reporting Rate TEXT VERSION
						#region IPP TEXT VERSION
						//Start Initial Patient Population text
						Start("item");
						Start("content","styleCode","Bold");
						_w.WriteString("Initial Patient Population");
						End("content");
						_w.WriteString(": "+listPopCountDicts[0]["All"].ToString());
						if(listPopCountDicts[0]["All"]>0) {
							Start("list");
							#region Stratification
							if(i==(int)QualityType2014.CariesPrevent || i==(int)QualityType2014.WeightChild_1_1) {
								Start("item");
								Start("content","styleCode","Bold");
								_w.WriteString("Reporting Stratum 1");
								End("content");
								if(p==0) {
									if(i==(int)QualityType2014.CariesPrevent) {
										_w.WriteString(": "+listQMs[s1Indx].ListEhrPats.Count.ToString());
									}
									else {
										_w.WriteString(": "+listQMs[s1numer1Indx].ListEhrPats.Count.ToString());
									}
								}
								else if(p==1) {
									_w.WriteString(": "+listQMs[s1numer2Indx].ListEhrPats.Count.ToString());
								}
								else if(p==2) {
									_w.WriteString(": "+listQMs[s1numer3Indx].ListEhrPats.Count.ToString());
								}
								End("item");
							}
							if(i==(int)QualityType2014.CariesPrevent || i==(int)QualityType2014.WeightChild_1_1) {
								Start("item");
								Start("content","styleCode","Bold");
								_w.WriteString("Reporting Stratum 2");
								End("content");
								if(p==0) {
									if(i==(int)QualityType2014.CariesPrevent) {
										_w.WriteString(": "+listQMs[s2Indx].ListEhrPats.Count.ToString());
									}
									else {
										_w.WriteString(": "+listQMs[s2numer1Indx].ListEhrPats.Count.ToString());
									}
								}
								else if(p==1) {
									_w.WriteString(": "+listQMs[s2numer2Indx].ListEhrPats.Count.ToString());
								}
								else if(p==2) {
									_w.WriteString(": "+listQMs[s2numer3Indx].ListEhrPats.Count.ToString());
								}
								End("item");
							}
							if(p==0 && i==(int)QualityType2014.CariesPrevent) {
								Start("item");
								Start("content","styleCode","Bold");
								_w.WriteString("Reporting Stratum 3");
								End("content");
								_w.WriteString(": "+listQMs[s3Indx].ListEhrPats.Count.ToString());
								End("item");
							}
							#endregion
							foreach(KeyValuePair<string,int> kvpair in listPopCountDicts[0]) {
								if(kvpair.Value==0 || kvpair.Key=="All") {
									continue;
								}
								Start("item");
								Start("content","styleCode","Bold");
								_w.WriteString(GetSupplementDataPrintString(kvpair.Key));
								End("content");
								_w.WriteString(": "+kvpair.Value.ToString());
								End("item");
							}
							End("list");
						}
						End("item");
						#endregion IPP TEXT VERSION
						#region DENOM TEXT VERSION
						//Start Denominator text
						Start("item");
						Start("content","styleCode","Bold");
						_w.WriteString("Denominator");
						End("content");
						_w.WriteString(": "+listPopCountDicts[1]["All"]);
						if(listPopCountDicts[1]["All"]>0) {
							Start("list");
							#region Stratification
							if(i==(int)QualityType2014.CariesPrevent || i==(int)QualityType2014.WeightChild_1_1) {
								Start("item");
								Start("content","styleCode","Bold");
								_w.WriteString("Reporting Stratum 1");
								End("content");
								if(p==0) {
									if(i==(int)QualityType2014.CariesPrevent) {
										_w.WriteString(": "+listQMs[s1Indx].Denominator.ToString());
									}
									else {
										_w.WriteString(": "+listQMs[s1numer1Indx].Denominator.ToString());
									}
								}
								else if(p==1) {
									_w.WriteString(": "+listQMs[s1numer2Indx].Denominator.ToString());
								}
								else if(p==2) {
									_w.WriteString(": "+listQMs[s1numer3Indx].Denominator.ToString());
								}
								End("item");
							}
							if(i==(int)QualityType2014.CariesPrevent || i==(int)QualityType2014.WeightChild_1_1) {
								Start("item");
								Start("content","styleCode","Bold");
								_w.WriteString("Reporting Stratum 2");
								End("content");
								if(p==0) {
									if(i==(int)QualityType2014.CariesPrevent) {
										_w.WriteString(": "+listQMs[s2Indx].Denominator.ToString());
									}
									else {
										_w.WriteString(": "+listQMs[s2numer1Indx].Denominator.ToString());
									}
								}
								else if(p==1) {
									_w.WriteString(": "+listQMs[s2numer2Indx].Denominator.ToString());
								}
								else if(p==2) {
									_w.WriteString(": "+listQMs[s2numer3Indx].Denominator.ToString());
								}
								End("item");
							}
							if(p==0 && i==(int)QualityType2014.CariesPrevent) {
								Start("item");
								Start("content","styleCode","Bold");
								_w.WriteString("Reporting Stratum 3");
								End("content");
								_w.WriteString(": "+listQMs[s3Indx].Denominator.ToString());
								End("item");
							}
							#endregion
							foreach(KeyValuePair<string,int> kvpair in listPopCountDicts[1]) {
								if(kvpair.Value==0 || kvpair.Key=="All") {
									continue;
								}
								Start("item");
								Start("content","styleCode","Bold");
								_w.WriteString(GetSupplementDataPrintString(kvpair.Key));
								End("content");
								_w.WriteString(": "+kvpair.Value.ToString());
								End("item");
							}
							End("list");
						}
						End("item");
						#endregion DENOM TEXT VERSION
						#region DENEXCL TEXT VERSION
						//Start Denominator Exclusion text
						Start("item");
						Start("content","styleCode","Bold");
						_w.WriteString("Denominator Exclusion");
						End("content");
						_w.WriteString(": "+listPopCountDicts[2]["All"].ToString());
						if(listPopCountDicts[2]["All"]>0) {
							Start("list");
							#region Stratification
							if(i==(int)QualityType2014.CariesPrevent || i==(int)QualityType2014.WeightChild_1_1) {
								Start("item");
								Start("content","styleCode","Bold");
								_w.WriteString("Reporting Stratum 1");
								End("content");
								if(p==0) {
									if(i==(int)QualityType2014.CariesPrevent) {
										_w.WriteString(": "+listQMs[s1Indx].Exclusions.ToString());
									}
									else {
										_w.WriteString(": "+listQMs[s1numer1Indx].Exclusions.ToString());
									}
								}
								else if(p==1) {
									_w.WriteString(": "+listQMs[s1numer2Indx].Exclusions.ToString());
								}
								else if(p==2) {
									_w.WriteString(": "+listQMs[s1numer3Indx].Exclusions.ToString());
								}
								End("item");
							}
							if(i==(int)QualityType2014.CariesPrevent || i==(int)QualityType2014.WeightChild_1_1) {
								Start("item");
								Start("content","styleCode","Bold");
								_w.WriteString("Reporting Stratum 2");
								End("content");
								if(p==0) {
									if(i==(int)QualityType2014.CariesPrevent) {
										_w.WriteString(": "+listQMs[s2Indx].Exclusions.ToString());
									}
									else {
										_w.WriteString(": "+listQMs[s2numer1Indx].Exclusions.ToString());
									}
								}
								else if(p==1) {
									_w.WriteString(": "+listQMs[s2numer2Indx].Exclusions.ToString());
								}
								else if(p==2) {
									_w.WriteString(": "+listQMs[s2numer3Indx].Exclusions.ToString());
								}
								End("item");
							}
							if(p==0 && i==(int)QualityType2014.CariesPrevent) {
								Start("item");
								Start("content","styleCode","Bold");
								_w.WriteString("Reporting Stratum 3");
								End("content");
								_w.WriteString(": "+listQMs[s3Indx].Exclusions.ToString());
								End("item");
							}
							#endregion
							foreach(KeyValuePair<string,int> kvpair in listPopCountDicts[2]) {
								if(kvpair.Value==0 || kvpair.Key=="All") {
									continue;
								}
								Start("item");
								Start("content","styleCode","Bold");
								_w.WriteString(GetSupplementDataPrintString(kvpair.Key));
								End("content");
								_w.WriteString(": "+kvpair.Value.ToString());
								End("item");
							}
							End("list");
						}
						End("item");
						#endregion DENEXCL TEXT VERSION
						#region NUMER TEXT VERSION
						//Start Numerator text
						Start("item");
						Start("content","styleCode","Bold");
						_w.WriteString("Numerator");
						End("content");
						_w.WriteString(": "+listPopCountDicts[3]["All"].ToString());
						if(listPopCountDicts[3]["All"]>0) {
							Start("list");
							#region Stratification
							if(i==(int)QualityType2014.CariesPrevent || i==(int)QualityType2014.WeightChild_1_1) {
								Start("item");
								Start("content","styleCode","Bold");
								_w.WriteString("Reporting Stratum 1");
								End("content");
								if(p==0) {									
									if(i==(int)QualityType2014.CariesPrevent) {
										_w.WriteString(": "+listQMs[s1Indx].Numerator.ToString());
									}
									else {
										_w.WriteString(": "+listQMs[s1numer1Indx].Numerator.ToString());
									}
								}
								else if(p==1) {
									_w.WriteString(": "+listQMs[s1numer2Indx].Numerator.ToString());
								}
								else if(p==2) {
									_w.WriteString(": "+listQMs[s1numer3Indx].Numerator.ToString());
								}
								End("item");
							}
							if(i==(int)QualityType2014.CariesPrevent || i==(int)QualityType2014.WeightChild_1_1) {
								Start("item");
								Start("content","styleCode","Bold");
								_w.WriteString("Reporting Stratum 2");
								End("content");
								if(p==0) {									
									if(i==(int)QualityType2014.CariesPrevent) {
										_w.WriteString(": "+listQMs[s2Indx].Numerator.ToString());
									}
									else {
										_w.WriteString(": "+listQMs[s2numer1Indx].Numerator.ToString());
									}
								}
								else if(p==1) {
									_w.WriteString(": "+listQMs[s2numer2Indx].Numerator.ToString());
								}
								else if(p==2) {
									_w.WriteString(": "+listQMs[s2numer3Indx].Numerator.ToString());
								}
								End("item");
							}
							if(p==0 && i==(int)QualityType2014.CariesPrevent) {
								Start("item");
								Start("content","styleCode","Bold");
								_w.WriteString("Reporting Stratum 3");
								End("content");
								_w.WriteString(": "+listQMs[s3Indx].Numerator.ToString());
								End("item");
							}
							#endregion
							foreach(KeyValuePair<string,int> kvpair in listPopCountDicts[3]) {
								if(kvpair.Value==0 || kvpair.Key=="All") {
									continue;
								}
								Start("item");
								Start("content","styleCode","Bold");
								_w.WriteString(GetSupplementDataPrintString(kvpair.Key));
								End("content");
								_w.WriteString(": "+kvpair.Value.ToString());
								End("item");
							}
							End("list");
						}
						End("item");
						#endregion NUMER TEXT VERSION
						#region DENEXCEP TEXT VERSION
						//Start Denominator Exception text
						Start("item");
						Start("content","styleCode","Bold");
						_w.WriteString("Denominator Exception");
						End("content");
						_w.WriteString(": "+listPopCountDicts[4]["All"].ToString());
						if(listPopCountDicts[4]["All"]>0) {
							Start("list");
							#region Stratification
							if(i==(int)QualityType2014.CariesPrevent || i==(int)QualityType2014.WeightChild_1_1) {
								Start("item");
								Start("content","styleCode","Bold");
								_w.WriteString("Reporting Stratum 1");
								End("content");
								if(p==0) {
									if(i==(int)QualityType2014.CariesPrevent) {
										_w.WriteString(": "+listQMs[s1Indx].Exceptions.ToString());
									}
									else {
										_w.WriteString(": "+listQMs[s1numer1Indx].Exceptions.ToString());
									}
								}
								else if(p==1) {
									_w.WriteString(": "+listQMs[s1numer2Indx].Exceptions.ToString());
								}
								else if(p==2) {
									_w.WriteString(": "+listQMs[s1numer3Indx].Exceptions.ToString());
								}
								End("item");
							}
							if(i==(int)QualityType2014.CariesPrevent || i==(int)QualityType2014.WeightChild_1_1) {
								Start("item");
								Start("content","styleCode","Bold");
								_w.WriteString("Reporting Stratum 2");
								End("content");
								if(p==0) {
									if(i==(int)QualityType2014.CariesPrevent) {
										_w.WriteString(": "+listQMs[s2Indx].Exceptions.ToString());
									}
									else {
										_w.WriteString(": "+listQMs[s2numer1Indx].Exceptions.ToString());
									}
								}
								else if(p==1) {
									_w.WriteString(": "+listQMs[s2numer2Indx].Exceptions.ToString());
								}
								else if(p==2) {
									_w.WriteString(": "+listQMs[s2numer3Indx].Exceptions.ToString());
								}
								End("item");
							}
							if(p==0 && i==(int)QualityType2014.CariesPrevent) {
								Start("item");
								Start("content","styleCode","Bold");
								_w.WriteString("Reporting Stratum 3");
								End("content");
								_w.WriteString(": "+listQMs[s3Indx].Exceptions.ToString());
								End("item");
							}
							#endregion
							foreach(KeyValuePair<string,int> kvpair in listPopCountDicts[4]) {
								if(kvpair.Value==0 || kvpair.Key=="All") {
									continue;
								}
								Start("item");
								Start("content","styleCode","Bold");
								_w.WriteString(GetSupplementDataPrintString(kvpair.Key));
								End("content");
								_w.WriteString(": "+kvpair.Value.ToString());
								End("item");
							}
							End("list");
						}
						End("item");
						#endregion DENEXCEP TEXT VERSION
						End("list");
					}
				}
				End("text");
				#endregion TEXT SECTION
				#region ENTRY SECTION
				for(int i=0;i<listQMs.Count;i++) {
					//_listExtraPopIndxs will contain all of the Type2014 enum types that are stratifications or extra populations of other measures, so skip them here
					if(_listExtraPopIndxs.Contains(i)) {
						continue;
					}
					switch(i) {
						case (int)QualityType2014.WeightOver65:
							//this wil create 2 populations, one for weight ages 18-64 and one for weight 65+
							numPops=2;
							break;
						case (int)QualityType2014.WeightChild_1_1:
							//this will create 3 data sections, one for each numerator
							//We will have Numerator 1 with ipp,denom,except,exclus,numer data, Numerator 2 data, and Numerator 3 data, each with their own stratifications
							numPops=3;
							break;
					}
					if(listQMs[i].Type2014==QualityType2014.MedicationsEntered) {
						listPopCountDicts=FillDictPopCounts(listQMs[i].ListEhrPats,listQMs[i].DictPatNumListEncounters);
					}
					else {
						listPopCountDicts=FillDictPopCounts(listQMs[i].ListEhrPats,null);
					}
					_w.WriteComment("***************PROPORTION MEASURE ENTRIES (1 entry per population per measure)***************");
					for(int p=0;p<numPops;p++) {//usually only runs 1 loop, measure 69 has two populations, and measure 155 has 3 numerators, in which case it will run more than once
						int measureIndx=i;
						if(numPops==2 && p>0) {//fill stratification data with supplemental data from other population
							measureIndx=pop2Indx;
							listPopCountDicts=FillDictPopCounts(listQMs[measureIndx].ListEhrPats,null);
						}
						if(numPops==3 && p>0) {//only 3 populations for measure 155, Numerators 1-3
							if(p==1) {//second iteration, fill dictionaries with numerator 2 data for stratifications
								measureIndx=numer2;
								listPopCountDicts=FillDictPopCounts(listQMs[measureIndx].ListEhrPats,null);
							}
							if(p==2) {//third iteration, fill dictionaries with numerator 3 data for stratifications
								measureIndx=numer3;
								listPopCountDicts=FillDictPopCounts(listQMs[measureIndx].ListEhrPats,null);
							}
						}
						Start("entry");
						#region Measure Reference
						//start of Measure Reference and Results entries (measureSection)section[entry 1..*]
						Start("organizer","classCode","CLUSTER","moodCode","EVN");
						_w.WriteComment("Measure Reference Template");
						TemplateId("2.16.840.1.113883.10.20.24.3.98");
						_w.WriteComment("Measure Reference and Results Template");
						TemplateId("2.16.840.1.113883.10.20.27.3.1");
						StartAndEnd("statusCode","code","completed");
						Start("reference","typeCode","REFR");
						Start("externalDocument","classCode","DOC","moodCode","EVN");
						StartAndEnd("id","root",listQMs[measureIndx].eMeasureVSpecificId);//version specific id
						StartAndEnd("code","code","57024-2","displayName","Health Quality Measure Document","codeSystem",strCodeSystemLoinc,"codeSystemName",strCodeSystemNameLoinc);
						_w.WriteElementString("text",listQMs[measureIndx].eMeasureTitle);
						StartAndEnd("setId","root",listQMs[measureIndx].eMeasureVNeutralId);//version neutral id
						StartAndEnd("versionNumber","value",listQMs[measureIndx].eMeasureVersion);
						End("externalDocument");
						End("reference");
						Start("reference","typeCode","REFR");
						Start("externalObservation");
						StartAndEnd("id","root",listQMs[measureIndx].eMeasureSetId);
						StartAndEnd("code","code","55185-3","displayName","measure set","codeSystem",strCodeSystemLoinc,"codeSystemName",strCodeSystemNameLoinc);
						if(listQMs[measureIndx].Type2014==QualityType2014.MedicationsEntered) {//Measure 68 is the only one with a title that is not "None" or "NA"
							_w.WriteElementString("text","CLINICAL QUALITY MEASURE SET 2014");
						}
						else if(listQMs[measureIndx].Type2014==QualityType2014.CariesPrevent || listQMs[measureIndx].Type2014==QualityType2014.ChildCaries) {
							_w.WriteElementString("text","Not Applicable");
						}
						else {
							_w.WriteElementString("text","None");
						}
						End("externalObservation");
						End("reference");
						#endregion Measure Reference
						#region Performance Rate Component
						_w.WriteComment("***************Performance Rate 1 per entry (entry=Measure or Population within a measure)***************");
						Start("component");
						//Performance rate=Numerator/(Denominator-Exclusions-Exceptions)
						Start("observation","classCode","OBS","moodCode","EVN");
						_w.WriteComment("Performance Rate for Proportion Measure Template");
						TemplateId("2.16.840.1.113883.10.20.27.3.14");
						StartAndEnd("code","code","72510-1","displayName","Performance Rate","codeSystem",strCodeSystemLoinc,"codeSystemName",strCodeSystemNameLoinc);
						StartAndEnd("statusCode","code","completed");
						Start("value");
						_w.WriteAttributeString("xsi","type",null,"REAL");
						if(listQMs[measureIndx].PerformanceRate==0) {
							Attribs("nullFlavor","NA");//if no patients in denominator, then performance rate is null
						}
						else {
							Attribs("value",listQMs[measureIndx].PerformanceRate.ToString("0.00"));
						}
						End("value");
						End("observation");
						End("component");
						#endregion Performance Rate Component
						#region Reporting Rate Component
						_w.WriteComment("***************Reporting Rate 1 per entry (entry=Measure or Population within a measure)***************");
						Start("component");
						//Reporting rate=(Numerator+Exclusions+Exceptions)/Denominator
						Start("observation","classCode","OBS","moodCode","EVN");
						_w.WriteComment("Reporting Rate for Proportion Measure Template");
						TemplateId("2.16.840.1.113883.10.20.27.3.15");
						StartAndEnd("code","code","72509-3","displayName","Reporting Rate","codeSystem",strCodeSystemLoinc,"codeSystemName",strCodeSystemNameLoinc);
						StartAndEnd("statusCode","code","completed");
						Start("value");
						_w.WriteAttributeString("xsi","type",null,"REAL");
						if(listQMs[measureIndx].PerformanceRate==0) {
							Attribs("nullFlavor","NA");//if no patients in denominator, then reporting rate is null
						}
						else {
							Attribs("value",listQMs[measureIndx].ReportingRate.ToString("0.00"));
						}
						End("value");
						End("observation");
						End("component");
						#endregion Reporting Rate Component
						//***************************************MEASURE DATA COMPONENTS*******************************
						_w.WriteComment("***************Measure Data component entries (1..*) represent aggregate counts IPP,DENOM,DENEX,DENEXCEP,NUMER***************");
						#region Measure Data
						for(int j=0;j<listPopCountDicts.Count;j++) {
							switch(j) {
								case 0:
									_w.WriteComment("Initial Patient Population component");
									break;
								case 1:
									_w.WriteComment("Denominator component");
									break;
								case 2:
									if(listQMs[measureIndx].eMeasureDenexId=="") {//if no exclusions defined for this measure, continue
										continue;
									}
									_w.WriteComment("Denominator Exclusion component");
									break;
								case 3:
									_w.WriteComment("Numerator component");
									break;
								case 4:
									if(listQMs[measureIndx].eMeasureDenexcepId=="") {//if no exceptions defined for this measure, continue
										continue;
									}
									_w.WriteComment("Denominator Exception component");
									break;
								default:
									throw new ApplicationException("Error in creating QRDA Category III in Measure Data Components section.");
							}
							Start("component");
							Start("observation","classCode","OBS","moodCode","EVN");
							_w.WriteComment("Measure Data Template");
							TemplateId("2.16.840.1.113883.10.20.27.3.5");
							StartAndEnd("code","code","ASSERTION","displayName","Assertion","codeSystem","2.16.840.1.113883.5.4","codeSystemName","ActCode");
							StartAndEnd("statusCode","code","completed");
							Start("value");
							_w.WriteAttributeString("xsi","type",null,"CD");
							switch(j) {
								case 0:
									Attribs("code","IPP","displayName","Initial Patient Population");
									break;
								case 1:
									Attribs("code","DENOM","displayName","Denominator");
									break;
								case 2:
									Attribs("code","DENEX","displayName","Denominator Exclusions");
									break;
								case 3:
									Attribs("code","NUMER","displayName","Numerator");
									break;
								case 4:
									Attribs("code","DENEXCEP","displayName","Denominator Exceptions");
									break;
								default:
									throw new ApplicationException("Error in creating QRDA Category III in Measure Data Components section.");
							}
							Attribs("codeSystem","2.16.840.1.113883.5.1063","codeSystemName","ObservationValue");
							End("value");
							#region Measure Count entry
							//*************Aggregate count entry**************
							_w.WriteComment("Aggregate Count entryRelationship");
							Start("entryRelationship","typeCode","SUBJ","inversionInd","true");
							Start("observation","classCode","OBS","moodCode","EVN");
							_w.WriteComment("Aggregate Count Template");
							TemplateId("2.16.840.1.113883.10.20.27.3.3");
							StartAndEnd("code","code","MSRAGG","displayName","rate aggregation","codeSystem","2.16.840.1.113883.5.4","codeSystemName","ActCode");
							Start("value");
							_w.WriteAttributeString("xsi","type",null,"INT");
							Attribs("value",listPopCountDicts[j]["All"].ToString());
							End("value");
							StartAndEnd("methodCode","code","COUNT","displayName","Count","codeSystem","2.16.840.1.113883.5.84","codeSystemName","ObservationMethod");
							End("observation");
							End("entryRelationship");
							#endregion Measure Count entry
							#region Stratification entries
							//**************Reporting Stratum entryRelationship**************
							//Measure 155 (wight counseling child) has two Strata, Measure 74 (primary caries prevention) has three Strata
							int iterations=0;
							if(i==(int)QualityType2014.CariesPrevent) {
								iterations=3;
							}
							else if(i==(int)QualityType2014.WeightChild_1_1) {
								iterations=2;
							}
							//most measures do not have strata, so these entryRelationships will not usually be created.  Only Measure 155 and 74 have stratification items.
							for(int s=0;s<iterations;s++) {
								_w.WriteComment("***************Reporting Stratum entry***************");
								Start("entryRelationship","typeCode","COMP");
								Start("observation","classCode","OBS","moodCode","EVN");
								_w.WriteComment("Reporting Stratum Template");
								TemplateId("2.16.840.1.113883.10.20.27.3.4");
								StartAndEnd("code","code","ASSERTION","displayName","Assertion","codeSystem","2.16.840.1.113883.5.4","codeSystemName","ActCode");
								StartAndEnd("statusCode","code","completed");
								Start("value");
								_w.WriteAttributeString("xsi","type",null,"CD");
								Attribs("nullFlavor","OTH");
								End("value");
								_w.WriteComment("Stratum");
								Start("entryRelationship","typeCode","SUBJ","inversionInd","true");
								Start("observation","classCode","OBS","moodCode","EVN");
								_w.WriteComment("Aggregate Count Template");
								TemplateId("2.16.840.1.113883.10.20.27.3.3");
								StartAndEnd("code","code","MSRAGG","displayName","rate aggregation","codeSystem","2.16.840.1.113883.5.4","codeSystemName","ActCode");
								Start("value");
								_w.WriteAttributeString("xsi","type",null,"INT");
								int stratIndx=0;
								if(i==(int)QualityType2014.CariesPrevent) {
									if(s==0) {//first strata
										stratIndx=s1Indx;
									}
									if(s==1) {//second strata
										stratIndx=s2Indx;
									}
									if(s==2) {//third strata
										stratIndx=s3Indx;
									}
								}
								else if(i==(int)QualityType2014.WeightChild_1_1) {
									if(p==0) {
										if(s==0) {//second numerator
											stratIndx=s1numer1Indx;
										}
										if(s==1) {//third numerator
											stratIndx=s2numer1Indx;
										}
									}
									if(p==1) {
										if(s==0) {//first strata, second numerator
											stratIndx=s1numer2Indx;
										}
										if(s==1) {//second strata, second population
											stratIndx=s2numer2Indx;
										}
									}
									if(p==2) {
										if(s==0) {//first strata, third population
											stratIndx=s1numer3Indx;
										}
										if(s==1) {//second strata, third population
											stratIndx=s2numer3Indx;
										}
									}
								}
								switch(j) {
									case 0:
										Attribs("value",listQMs[stratIndx].ListEhrPats.Count.ToString());
										break;
									case 1:
										Attribs("value",listQMs[stratIndx].Denominator.ToString());
										break;
									case 2:
										Attribs("value",listQMs[stratIndx].Exclusions.ToString());
										break;
									case 3:
										Attribs("value",listQMs[stratIndx].Numerator.ToString());
										break;
									case 4:
										Attribs("value",listQMs[stratIndx].Exceptions.ToString());
										break;
								}
								End("value");
								StartAndEnd("methodCode","code","COUNT","displayName","Count","codeSystem","2.16.840.1.113883.5.84","codeSystemName","ObservationMethod");
								End("observation");
								End("entryRelationship");
								//end of aggregate count
								//Start reference to strata in eMeasure
								Start("reference","typeCode","REFR");
								_w.WriteComment("Reference to the relevant strata in the eMeasure");
								Start("externalObservation","classCode","OBS","moodCode","EVN");
								switch(j) {
									case 0:
										StartAndEnd("id","root",listQMs[stratIndx].eMeasureIppId);
										break;
									case 1:
										StartAndEnd("id","root",listQMs[stratIndx].eMeasureDenomId);
										break;
									case 2:
										StartAndEnd("id","root",listQMs[stratIndx].eMeasureDenexId);
										break;
									case 3:
										StartAndEnd("id","root",listQMs[stratIndx].eMeasureNumerId);
										break;
									case 4:
										StartAndEnd("id","root",listQMs[stratIndx].eMeasureDenexcepId);
										break;
								}								
								End("externalObservation");
								End("reference");
								//end of reference to eMeasure
								End("observation");								
								End("entryRelationship");
							}
							#endregion Stratification entries
							#region SUPPLEMENTAL DATA STRATUM
							//loop through each of the population counts for this population and generate relevant supplemental data entries
							foreach(KeyValuePair<string,int> kvpair in listPopCountDicts[j]) {
								if(kvpair.Key=="All" && kvpair.Value==0) {//do not need to have these supplemental data entries if no initial patient population, break out of loop
									break;
								}
								if(kvpair.Value==0 || kvpair.Key=="All") {
									continue;
								}
								switch(kvpair.Key) {
									case "Male":
									case "Female":
									case "Unknown":
										//**************Sex Supplemental Data entry**************
										#region Sex Supplemental Data Entry
										_w.WriteComment("Sex Supplemental Data entryRelationship");
										Start("entryRelationship","typeCode","COMP");
										Start("observation","classCode","OBS","moodCode","EVN");
										_w.WriteComment("Sex Supplemental Data Element Template");
										TemplateId("2.16.840.1.113883.10.20.27.3.6");
										StartAndEnd("code","code","184100006","displayName","Patient sex","codeSystem",strCodeSystemSnomed,"codeSystemName",strCodeSystemNameSnomed);
										StartAndEnd("statusCode","code","completed");
										Start("value");
										_w.WriteAttributeString("xsi","type",null,"CD");
										if(kvpair.Key==PatientGender.Male.ToString()) {
											Attribs("code","M","displayName","Male");
										}
										else if(kvpair.Key==PatientGender.Female.ToString()) {
											Attribs("code","F","displayName","Female");
										}
										else {
											Attribs("code","UN","displayName","Undifferentiated");
										}
										Attribs("codeSystem","2.16.840.1.113883.5.1","codeSystemName","AdministrativeGender");
										End("value");
										#endregion Sex Supplemental Data Entry
										break;
									case "Hispanic":
									case "NotHispanic":
										//**************Ethnicity Supplemental Data**************
										#region Ethnicity Supplemental Data Entry
										_w.WriteComment("Ethnicity Supplemental Data entryRelationship");
										Start("entryRelationship","typeCode","COMP");
										Start("observation","classCode","OBS","moodCode","EVN");
										_w.WriteComment("Ethnicity Supplemental Data Element Template");
										TemplateId("2.16.840.1.113883.10.20.27.3.7");
										StartAndEnd("code","code","364699009","displayName","Ethnic Group","codeSystem",strCodeSystemSnomed,"codeSystemName",strCodeSystemNameSnomed);
										StartAndEnd("statusCode","code","completed");
										Start("value");
										_w.WriteAttributeString("xsi","type",null,"CD");
										if(kvpair.Key==PatRace.Hispanic.ToString()) {
											Attribs("code","2135-2","displayName","Hispanic or Latino");
										}
										else if(kvpair.Key==PatRace.NotHispanic.ToString()) {
											Attribs("code","2186-5","displayName","Not Hispanic or Latino");
										}
										Attribs("codeSystem","2.16.840.1.113883.6.238","codeSystemName","Race &amp; Ethnicity - CDC");
										End("value");
										#endregion Ethnicity Supplemental Data Entry
										break;
									case "AfricanAmerican":
									case "AmericanIndian":
									case "Asian":
									case "White":
									case "HawaiiOrPacIsland":
									case "Other":
										//**************Race Supplemental Data**************
										#region Race Supplemental Data Entry
										_w.WriteComment("Race Supplemental Data entryRelationship");
										Start("entryRelationship","typeCode","COMP");
										Start("observation","classCode","OBS","moodCode","EVN");
										_w.WriteComment("Race Supplemental Data Element Template");
										TemplateId("2.16.840.1.113883.10.20.27.3.8");
										StartAndEnd("code","code","103579009","displayName","Race","codeSystem",strCodeSystemSnomed,"codeSystemName",strCodeSystemNameSnomed);
										StartAndEnd("statusCode","code","completed");
										Start("value");
										_w.WriteAttributeString("xsi","type",null,"CD");
										if(kvpair.Key==PatRace.AfricanAmerican.ToString()) {
											Attribs("code","2054-5","displayName","Black or African American");
										}
										else if(kvpair.Key==PatRace.AmericanIndian.ToString()) {
											Attribs("code","1002-5","displayName","American Indian or Alaska Native");
										}
										else if(kvpair.Key==PatRace.Asian.ToString()) {
											Attribs("code","2028-9","displayName","Asian");
										}
										else if(kvpair.Key==PatRace.White.ToString()) {
											Attribs("code","2131-1","displayName","White");
										}
										else if(kvpair.Key==PatRace.HawaiiOrPacIsland.ToString()) {
											Attribs("code","2076-8","displayName","Native Hawaiian or Other Pacific Islander");
										}
										else if(kvpair.Key==PatRace.Other.ToString()) {
											Attribs("code","2106-3","displayName","Other Race");
										}
										Attribs("codeSystem","2.16.840.1.113883.6.238","codeSystemName","Race &amp; Ethnicity - CDC");
										End("value");
										#endregion Race Supplemental Data Entry
										break;
									case "Medicare":
									case "Medicaid":
									case "Other Gvmt":
									case "Private":
									case "Self-pay":
										//**************Payer Supplemental Data**************
										#region Payer Supplemental Data Entry
										_w.WriteComment("Payer Supplemental Data entryRelationship");
										Start("entryRelationship","typeCode","COMP");
										Start("observation","classCode","OBS","moodCode","EVN");
										_w.WriteComment("Patient Characteristic Payer Template");
										TemplateId("2.16.840.1.113883.10.20.24.3.55");
										_w.WriteComment("Payer Supplemental Data Element Template");
										TemplateId("2.16.840.1.113883.10.20.27.3.9");
										Guid();
										StartAndEnd("code","code","48768-6","displayName","Payment source","codeSystem",strCodeSystemLoinc,"codeSystemName",strCodeSystemNameLoinc);
										StartAndEnd("statusCode","code","completed");
										Start("value");
										_w.WriteAttributeString("xsi","type",null,"CD");
										if(kvpair.Key=="Medicare") {
											Attribs("code","1","displayName","Medicare");
										}
										else if(kvpair.Key=="Medicaid") {
											Attribs("code","2","displayName","Medicaid");
										}
										else if(kvpair.Key=="Other Gvmt") {
											Attribs("code","349","displayName","Other Government (Federal/State/Local) (excluding Department of Corrections)");
										}
										else if(kvpair.Key=="Private") {
											Attribs("code","5","displayName","Private Health Insurance");
										}
										else {
											Attribs("code","8","displayName","No Payment from an Organization/Agency/Program/Private Payer Listed");
										}
										Attribs("codeSystem","2.16.840.1.113883.3.221.5","codeSystemName","Source of Payment Typology");
										End("value");
										#endregion Payer Supplemental Data Entry
										break;
									default:
										throw new ApplicationException("Error in creating QRDA Category III in Measure Data Components section.");
								}
								_w.WriteComment("Aggregate Count entryRelationship");
								Start("entryRelationship","typeCode","SUBJ","inversionInd","true");
								_w.WriteComment("Aggregate Count Template");
								Start("observation","classCode","OBS","moodCode","EVN");
								TemplateId("2.16.840.1.113883.10.20.27.3.3");
								StartAndEnd("code","code","MSRAGG","displayName","rate aggregation","codeSystem","2.16.840.1.113883.5.4","codeSystemName","ActCode");
								Start("value");
								_w.WriteAttributeString("xsi","type",null,"INT");
								Attribs("value",kvpair.Value.ToString());
								End("value");
								StartAndEnd("methodCode","code","COUNT","displayName","Count","codeSystem","2.16.840.1.113883.5.84","codeSystemName","ObservationMethod");
								End("observation");
								End("entryRelationship");
								End("observation");
								End("entryRelationship");
							}
							#endregion SUPPLEMENTAL DATA STRATUM
							//*************eMeasure Reference**************
							_w.WriteComment("eMeasure reference");
							Start("reference","typeCode","REFR");
							Start("externalObservation","classCode","OBS","moodCode","EVN");
							switch(j) {
								case 0:
									StartAndEnd("id","root",listQMs[measureIndx].eMeasureIppId);
									break;
								case 1:
									StartAndEnd("id","root",listQMs[measureIndx].eMeasureDenomId);
									break;
								case 2:
									StartAndEnd("id","root",listQMs[measureIndx].eMeasureDenexId);
									break;
								case 3:
									StartAndEnd("id","root",listQMs[measureIndx].eMeasureNumerId);
									break;
								case 4:
									StartAndEnd("id","root",listQMs[measureIndx].eMeasureDenexcepId);
									break;
							}
							End("externalObservation");
							End("reference");
							End("observation");
							End("component");
						}
					#endregion Measure Data
					End("organizer");
					End("entry");
					}
				}
				End("section");
				#endregion ENTRY SECTION
				End("component");
				#endregion measure component
				End("structuredBody");
				End("component");
				#endregion QRDA III Body
				End("ClinicalDocument");
				_w.Flush();
				_w.Close();
			}
		}
Example #34
0
 private void InvokeMethod(XmlWriter w, string methodName)
 {
     byte[] buffer = new byte[10];
     switch (methodName)
     {
         case "WriteStartDocument":
             w.WriteStartDocument();
             break;
         case "WriteStartElement":
             w.WriteStartElement("root");
             break;
         case "WriteEndElement":
             w.WriteEndElement();
             break;
         case "WriteStartAttribute":
             w.WriteStartAttribute("attr");
             break;
         case "WriteEndAttribute":
             w.WriteEndAttribute();
             break;
         case "WriteCData":
             w.WriteCData("test");
             break;
         case "WriteComment":
             w.WriteComment("test");
             break;
         case "WritePI":
             w.WriteProcessingInstruction("name", "test");
             break;
         case "WriteEntityRef":
             w.WriteEntityRef("e");
             break;
         case "WriteCharEntity":
             w.WriteCharEntity('c');
             break;
         case "WriteSurrogateCharEntity":
             w.WriteSurrogateCharEntity('\uDC00', '\uDBFF');
             break;
         case "WriteWhitespace":
             w.WriteWhitespace(" ");
             break;
         case "WriteString":
             w.WriteString("foo");
             break;
         case "WriteChars":
             char[] charArray = new char[] { 'a', 'b', 'c', 'd' };
             w.WriteChars(charArray, 0, 3);
             break;
         case "WriteRaw":
             w.WriteRaw("<foo>bar</foo>");
             break;
         case "WriteBase64":
             w.WriteBase64(buffer, 0, 9);
             break;
         case "WriteBinHex":
             w.WriteBinHex(buffer, 0, 9);
             break;
         case "LookupPrefix":
             string str = w.LookupPrefix("foo");
             break;
         case "WriteNmToken":
             w.WriteNmToken("foo");
             break;
         case "WriteName":
             w.WriteName("foo");
             break;
         case "WriteQualifiedName":
             w.WriteQualifiedName("foo", "bar");
             break;
         case "WriteValue":
             w.WriteValue(Int32.MaxValue);
             break;
         case "WriteAttributes":
             XmlReader xr1 = ReaderHelper.Create(new StringReader("<root attr='test'/>"));
             xr1.Read();
             w.WriteAttributes(xr1, false);
             break;
         case "WriteNodeReader":
             XmlReader xr2 = ReaderHelper.Create(new StringReader("<root/>"));
             xr2.Read();
             w.WriteNode(xr2, false);
             break;
         case "Flush":
             w.Flush();
             break;
         default:
             CError.Equals(false, "Unexpected param in testcase: {0}", methodName);
             break;
     }
 }
Example #35
0
 // Saves the node to the specified XmlWriter.
 public override void WriteTo(XmlWriter w)
 {
     w.WriteProcessingInstruction(Name, InnerText);
 }
Example #36
0
 public bool writePi(string target, string content) => CheckedCall(() => _writer.WriteProcessingInstruction(target, content));
Example #37
0
        /* -------------------------------------------------------------------------------------
        * Name:  WriteShallowNode
        * Goal:  Copy piece-by-piece
        * History:
        * 2/oct/2015 ERK Created
          ------------------------------------------------------------------------------------- */
        public void WriteShallowNode(XmlReader reader, XmlWriter writer)
        {
            if (reader == null) {
            throw new ArgumentNullException("reader");
              }
              if (writer == null) {
            throw new ArgumentNullException("writer");
              }
              try {
            switch (reader.NodeType) {
              case XmlNodeType.Element:
            writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
            bool bIsFOLIA = (reader.LocalName == "FoLiA");
            string sLocalName = reader.LocalName;
            // Process attributes one by one
            if (reader.HasAttributes) {
              if (reader.MoveToFirstAttribute()) {
                do {
                  if (reader.Name != "xmlns") {
                    bool bWritten = false;
                    // Action depends on local name
                    switch (sLocalName) {
                      case "FoLiA":
                        // Is the the attribute @version?
                        if (reader.Name == "version") { writer.WriteAttributeString(reader.Name, FOLIA_VERSION); bWritten = true; }
                        break;
                      case "t":
                        // is this the attribute @class?
                        if (reader.Name == "class") { writer.WriteAttributeString(reader.Name, "eng"); bWritten = true; }
                        break;
                    }
                    if (!bWritten) {
                      String[] arName = reader.Name.Split(':');
                      if (arName.Length > 1) {
                        writer.WriteAttributeString(arName[0], arName[1], null, reader.Value);

                      } else {
                        writer.WriteAttributeString(reader.Name, reader.Value);
                      }
                    }
                    /*
                    // Check for FoLiA version
                    if (bIsFOLIA && reader.Name == "version") {
                      // Adapt version number
                      writer.WriteAttributeString(reader.Name, FOLIA_VERSION);
                    } else {
                      String[] arName = reader.Name.Split(':');
                      if (arName.Length > 1) {
                        writer.WriteAttributeString(arName[0], arName[1], null, reader.Value);

                      } else {
                        writer.WriteAttributeString(reader.Name, reader.Value);
                      }
                    } */
                  }
                } while (reader.MoveToNextAttribute());
              }
            }

            if (reader.IsEmptyElement) {
              writer.WriteEndElement();
            }
            break;
              case XmlNodeType.Text:
            writer.WriteString(reader.Value);
            break;
              case XmlNodeType.Whitespace:
              case XmlNodeType.SignificantWhitespace:
            writer.WriteWhitespace(reader.Value);
            break;
              case XmlNodeType.CDATA:
            writer.WriteCData(reader.Value);
            break;
              case XmlNodeType.EntityReference:
            writer.WriteEntityRef(reader.Name);
            break;
              case XmlNodeType.XmlDeclaration:
              case XmlNodeType.ProcessingInstruction:
            writer.WriteProcessingInstruction(reader.Name, reader.Value);
            break;
              case XmlNodeType.DocumentType:
            writer.WriteDocType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value);
            break;
              case XmlNodeType.Comment:
            writer.WriteComment(reader.Value);
            break;
              case XmlNodeType.EndElement:
            writer.WriteFullEndElement();
            break;
            }
              } catch (Exception ex) {
            errHandle.DoError("WriteShallowNode", ex); // Provide standard error message
              }
        }
Example #38
0
        // Writes the content (inner XML) of the current node into the provided XmlWriter.
        private async Task WriteNodeAsync(XmlWriter xtw, bool defattr)
        {
#if !SILVERLIGHT
            Debug.Assert(xtw is XmlTextWriter);
#endif
            int d = this.NodeType == XmlNodeType.None ? -1 : this.Depth;
            while (await this.ReadAsync().ConfigureAwait(false) && (d < this.Depth))
            {
                switch (this.NodeType)
                {
                case XmlNodeType.Element:
                    xtw.WriteStartElement(this.Prefix, this.LocalName, this.NamespaceURI);
#if !SILVERLIGHT // Removing dependency on XmlTextWriter
                    ((XmlTextWriter)xtw).QuoteChar = this.QuoteChar;
#endif
                    xtw.WriteAttributes(this, defattr);
                    if (this.IsEmptyElement)
                    {
                        xtw.WriteEndElement();
                    }
                    break;

                case XmlNodeType.Text:
                    xtw.WriteString(await this.GetValueAsync().ConfigureAwait(false));
                    break;

                case XmlNodeType.Whitespace:
                case XmlNodeType.SignificantWhitespace:
                    xtw.WriteWhitespace(await this.GetValueAsync().ConfigureAwait(false));
                    break;

                case XmlNodeType.CDATA:
                    xtw.WriteCData(this.Value);
                    break;

                case XmlNodeType.EntityReference:
                    xtw.WriteEntityRef(this.Name);
                    break;

                case XmlNodeType.XmlDeclaration:
                case XmlNodeType.ProcessingInstruction:
                    xtw.WriteProcessingInstruction(this.Name, this.Value);
                    break;

                case XmlNodeType.DocumentType:
                    xtw.WriteDocType(this.Name, this.GetAttribute("PUBLIC"), this.GetAttribute("SYSTEM"), this.Value);
                    break;

                case XmlNodeType.Comment:
                    xtw.WriteComment(this.Value);
                    break;

                case XmlNodeType.EndElement:
                    xtw.WriteFullEndElement();
                    break;
                }
            }
            if (d == this.Depth && this.NodeType == XmlNodeType.EndElement)
            {
                await ReadAsync().ConfigureAwait(false);
            }
        }
 // Saves the node to the specified XmlWriter.
 public override void WriteTo(XmlWriter w) {
     w.WriteProcessingInstruction(target, data);
 }
        // Writes the content (inner XML) of the current node into the provided XmlWriter.
        private void WriteNode(XmlWriter xtw, bool defattr) {
#if !SILVERLIGHT
            Debug.Assert(xtw is XmlTextWriter);
#endif
            int d = this.NodeType == XmlNodeType.None ? -1 : this.Depth;
            while (this.Read() && (d < this.Depth)) {
                switch (this.NodeType) {
                    case XmlNodeType.Element:
                        xtw.WriteStartElement(this.Prefix, this.LocalName, this.NamespaceURI);
#if !SILVERLIGHT // Removing dependency on XmlTextWriter
                        ((XmlTextWriter)xtw).QuoteChar = this.QuoteChar;
#endif
                        xtw.WriteAttributes(this, defattr);
                        if (this.IsEmptyElement) {
                            xtw.WriteEndElement();
                        }
                        break;
                    case XmlNodeType.Text:
                        xtw.WriteString(this.Value);
                        break;
                    case XmlNodeType.Whitespace:
                    case XmlNodeType.SignificantWhitespace:
                        xtw.WriteWhitespace(this.Value);
                        break;
                    case XmlNodeType.CDATA:
                        xtw.WriteCData(this.Value);
                        break;
                    case XmlNodeType.EntityReference:
                        xtw.WriteEntityRef(this.Name);
                        break;
                    case XmlNodeType.XmlDeclaration:
                    case XmlNodeType.ProcessingInstruction:
                        xtw.WriteProcessingInstruction(this.Name, this.Value);
                        break;
                    case XmlNodeType.DocumentType:
                        xtw.WriteDocType(this.Name, this.GetAttribute("PUBLIC"), this.GetAttribute("SYSTEM"), this.Value);
                        break;
                    case XmlNodeType.Comment:
                        xtw.WriteComment(this.Value);
                        break;
                    case XmlNodeType.EndElement:
                        xtw.WriteFullEndElement();
                        break;
                }
            }
            if (d == this.Depth && this.NodeType == XmlNodeType.EndElement) {
                Read();
            }
        }
Example #41
0
 /// <include file='doc\XmlDeclaration.uex' path='docs/doc[@for="XmlDeclaration.WriteTo"]/*' />
 /// <devdoc>
 ///    <para>
 ///       Saves the node to the specified XmlWriter.
 ///    </para>
 /// </devdoc>
 public override void WriteTo(XmlWriter w)
 {
     w.WriteProcessingInstruction(Name, InnerText);
 }
Example #42
0
 public override void WriteProcessingInstruction(string name, string text)
 {
     CheckAsync();
     coreWriter.WriteProcessingInstruction(name, text);
 }
Example #43
0
 /// <summary>
 /// Write element text
 /// </summary>
 /// <param name="writer">XML writer</param>
 protected override void WriteText(XmlWriter writer)
 {
     string text = Utils.To<string>(Value);
     if (text != null)
     {
         text = text.Trim() + Environment.NewLine;
         if (text.Length > 0)
         {
             if (text.IndexOfAny("><&".ToCharArray()) != -1)
             {
                 if (!text.Contains("?>"))
                     writer.WriteProcessingInstruction("_", text);
                 else
                     writer.WriteCData(text);
             }
             else
                 writer.WriteValue(text);
         }
     }
 }
 public override void WriteProcessingInstruction(string name, string?text)
 {
     EndCDataSection();
     _wrapped.WriteProcessingInstruction(name, text);
 }