public void EV_1089SETParseTest() { PRPA_IN201305UV02 test = new PRPA_IN201305UV02(); test.Sender = new RMIM.UV.NE2010.MCCI_MT100200UV01.Sender(); test.Sender.Device = new RMIM.UV.NE2010.MCCI_MT100200UV01.Device(); test.Sender.Device.Id = new SET <II>() { NullFlavor = NullFlavor.NoInformation }; XmlIts1Formatter fmtr = new XmlIts1Formatter(); fmtr.GraphAides.Add(new DatatypeFormatter()); var sw = new StringWriter(); XmlStateWriter writer = new XmlStateWriter(XmlWriter.Create(sw)); fmtr.Graph(writer, test); writer.Flush(); String xmlString = sw.ToString(); StringReader sr = new StringReader(xmlString); XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr)); var result = fmtr.Parse(rdr); Assert.IsNotNull(result.Structure as PRPA_IN201305UV02); Assert.IsNotNull((result.Structure as PRPA_IN201305UV02).Sender.Device.Id); //Assert.AreEqual(test, result.Structure); }
public void SXPRSTMixedComponentsFormatting() { SXPR <RTO <INT, INT> > test = SXPR <RTO <INT, INT> > .CreateSXPR(new IVL <RTO <INT, INT> >(new RTO <INT, INT>(1, 3), new RTO <INT, INT>(2, 3)), new PIVL <RTO <INT, INT> >( new IVL <RTO <INT, INT> >(new RTO <INT, INT>(2, 3), new RTO <INT, INT>(5, 6)), new PQ((decimal)1.0, "y") ) //new SXCM<RTO<INT,INT>>(new RTO<INT,INT>(1,2)) { Operator = SetOperator.A }, //new IVL<RTO<INT,INT>>(new RTO<INT,INT>(1,2)) { Operator = SetOperator.Intersect ); StringWriter sw = new StringWriter(); DatatypeFormatter fmtr = new DatatypeFormatter(); XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw)); xw.WriteStartElement("sxpr"); fmtr.Graph(xw, test); xw.WriteEndElement(); // comp xw.Flush(); Tracer.Trace(sw.ToString()); StringReader sr = new StringReader(sw.ToString()); XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr)); rdr.Read(); rdr.Read(); var parse = fmtr.Parse(rdr, typeof(SXPR <RTO <INT, INT> >)).Structure as SXPR <RTO <INT, INT> >; Assert.AreEqual(parse.Count, test.Count); for (int i = 0; i < parse.Count; i++) { Assert.AreEqual(parse[i].GetType(), test[i].GetType()); } }
/// <summary> /// Logs the message. /// </summary> /// <param name="message">The message to log.</param> private static void LogMessage(IGraphable message) { XmlWriter writer = null; var formatter = new XmlIts1Formatter { ValidateConformance = true, }; var dtf = new DatatypeFormatter(); formatter.GraphAides.Add(dtf); var sb = new StringBuilder(); writer = XmlWriter.Create(sb, new XmlWriterSettings { Indent = true, OmitXmlDeclaration = true }); var stateWriter = new XmlStateWriter(writer); formatter.Graph(stateWriter, message); stateWriter.Flush(); traceSource.TraceEvent(TraceEventType.Verbose, 0, sb.ToString()); }
public void XmlStateWriterTest01() { // Initialize the XmlWriter & State writer StringWriter sw = new StringWriter(); var xw = XmlWriter.Create(sw, new XmlWriterSettings() { Indent = true }); // Write something at the start xw.WriteStartElement("myHl7ExampleInstance"); xw.WriteAttributeString("interactionId", "MCCI_IN000000UV01"); // State writer should always be used XmlStateWriter xsw = new XmlStateWriter(xw); // Create a simple instance MCCI_IN000000UV01 instance = new MCCI_IN000000UV01( Guid.NewGuid(), DateTime.Now, MCCI_IN000000UV01.GetInteractionId(), ProcessingID.Production, "P", AcknowledgementCondition.Always); // Setup the formatter IXmlStructureFormatter structureFormatter = new XmlIts1Formatter() { ValidateConformance = false }; structureFormatter.GraphAides.Add(new DatatypeFormatter()); // Print current path of the xmlwriter before formatting instance var writeStatePreFormat = xsw.WriteState; Console.WriteLine("Write state pre-format: {0}", writeStatePreFormat); // Format var result = structureFormatter.Graph(xsw, instance); // Print current path of the xmlwriter after formatting instance var writeStatePostFormat = xsw.WriteState; Console.WriteLine("Write state post-format: {0}", writeStatePostFormat); // Test that the write states before and after formatting has changed. // This demonstrates how the state of the xml writer can be tracked while runnning. Assert.AreNotEqual(writeStatePreFormat, writeStatePostFormat); // Flush state writer xsw.Flush(); // finish the stream xw.WriteEndElement(); }
static void Main(string[] args) { // We can speed up initial serialization by loading a cached formatter assembly MARC.Everest.Formatters.XML.ITS1.Formatter fmtr = new MARC.Everest.Formatters.XML.ITS1.Formatter(); // If you want to experiment and see the difference in serialization times, try commenting these lines out // and seeing the effect. fmtr.GraphAides.Add(new DatatypeFormatter()); fmtr.ValidateConformance = false; // Create the CDA ClinicalDocument cda = new ClinicalDocument( new II("2.16.840.1.113883.19.4", "c266"), // Create an identifier for the document new CE <String>("33049-3", "2.16.840.1.113883.6.1", "LOINC", null, "Consultation note", null), // Specify the type of document DateTime.Now, // Effective time of the document (now) x_BasicConfidentialityKind.Normal, // Confidentiality code of N = Normal CreateRecordTarget(), // Create a record target, this is good for code reuse CreateAuthor(), // Create the author node CreateCustodian(), // Create custodian node CreateComponent() // Create component Node ) { Title = UserPrompt <ST>("Document Title:") }; Console.Clear(); Console.WriteLine("Here is your CDA:"); // Prepare the output XmlStateWriter xsw = new XmlStateWriter(XmlWriter.Create(Console.OpenStandardOutput(), new XmlWriterSettings() { Indent = true })); DateTime start = DateTime.Now; var result = fmtr.Graph(xsw, cda); xsw.Flush(); Console.WriteLine("Took {0} ms to render", DateTime.Now.Subtract(start).TotalMilliseconds); // We can serialize again to see the learning pattern of Everest for (int i = 2; i < 20; i++) { xsw = new XmlStateWriter(XmlWriter.Create(new MemoryStream(), new XmlWriterSettings() { Indent = true })); start = DateTime.Now; result = fmtr.Graph(xsw, cda); xsw.Flush(); Console.WriteLine("Render #{1} Took {0} ms to render", DateTime.Now.Subtract(start).TotalMilliseconds, i); } Console.ReadKey(); }
/// <summary> /// Illustrates formatting a message /// </summary> private static void FormatInstance(IGraphable message) { Console.WriteLine("Formatting..."); // We'll indent the output XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(Console.OpenStandardOutput(), new XmlWriterSettings() { Indent = true })); m_formatter.Graph(xw, message); xw.Flush(); }
/// <summary> /// Serialize as a string /// </summary> internal static String SerializeAsString(IGraphable graph) { DatatypeR2Formatter fmtr = new DatatypeR2Formatter(); StringWriter sw = new StringWriter(); XmlStateWriter xsw = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings() { Indent = true })); xsw.WriteStartElement("test", "urn:hl7-org:v3"); xsw.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance"); var result = fmtr.Graph(xsw, graph); xsw.WriteEndElement(); xsw.Flush(); sw.Flush(); System.Diagnostics.Trace.WriteLine(sw.ToString()); Assert.AreEqual(ResultCode.Accepted, result.Code); return(sw.ToString()); }
public void SXPRTSMixedComponentsFormatting() { SXPR <TS> test = SXPR <TS> .CreateSXPR(new IVL <TS>(DateTime.Now, DateTime.Now.AddDays(1)), new PIVL <TS>( new IVL <TS>(DateTime.Now, DateTime.Now.AddDays(1)), new PQ((decimal)1.0, "y") ), //new SXCM<TS>(DateTime.Now) { Operator = SetOperator.A }, new IVL <TS>(DateTime.Now) { Operator = SetOperator.Intersect }, new EIVL <TS>(DomainTimingEventType.BeforeLunch, new IVL <PQ>( new PQ((decimal)1.0, "d") ) ) { Operator = SetOperator.Inclusive }); StringWriter sw = new StringWriter(); DatatypeFormatter fmtr = new DatatypeFormatter(); XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw)); xw.WriteStartElement("sxpr"); fmtr.Graph(xw, test); xw.WriteEndElement(); // comp xw.Flush(); Tracer.Trace(sw.ToString()); StringReader sr = new StringReader(sw.ToString()); XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr)); rdr.Read(); rdr.Read(); var parse = fmtr.Parse(rdr, typeof(SXPR <TS>)).Structure as SXPR <TS>; Assert.AreEqual(parse.Count, test.Count); for (int i = 0; i < parse.Count; i++) { Assert.AreEqual(parse[i].GetType(), test[i].GetType()); } }
public void CreateReqElemOutputTest02() { XmlWriter xw = null; Stream s = null; try { /* STREAMWRITER CODE * s = File.Create("C:/Test Files/example85Data2.xml"); * StreamWriter sw1 = new StreamWriter(s); * * /* END STREAMWRITER CODE */ // Setup the formatter var its1Formatter = new XmlIts1Formatter() { ValidateConformance = true, CreateRequiredElements = true }; its1Formatter.GraphAides.Add(new DatatypeFormatter() { ValidateConformance = false } ); // Initialize the XmlWriter & State writer StringWriter sw = new StringWriter(); xw = XmlWriter.Create(sw, new XmlWriterSettings() { Indent = true }); // State writer should always be used XmlStateWriter xsw = new XmlStateWriter(xw); // Create an instance REPC_IN000076CA instance = new REPC_IN000076CA( Guid.NewGuid(), DateTime.Now, ResponseMode.Immediate, REPC_IN000076CA.GetInteractionId(), REPC_IN000076CA.GetProfileId(), ProcessingID.Production, AcknowledgementCondition.Always, new MARC.Everest.RMIM.CA.R020402.MCCI_MT002200CA.Receiver(), new MARC.Everest.RMIM.CA.R020402.MCCI_MT002200CA.Sender() ); instance.controlActEvent = new MARC.Everest.RMIM.CA.R020402.MCAI_MT700210CA.ControlActEvent <MARC.Everest.RMIM.CA.R020402.REPC_MT220001CA.Document>(); // Format var result = its1Formatter.Graph(xsw, instance); /* STREAMWRITER CODE * var result2 = its1Formatter.Graph(s, instance); * // Close streamwriter * sw1.Close(); * /* END STREAMWRITER CODE */ // Flush the xml state writer xsw.Flush(); if (result.Code != ResultCode.Accepted) { Console.WriteLine("RESULT CODE: {0}", result.Code); foreach (var detail in result.Details) { Console.WriteLine("{0}: {1}", detail.Type, detail.Message); } } // Assert: Instance is not conformant. Assert.AreEqual(ResultCode.Rejected, result.Code); /* STREAMWRITER CODE * // Validate that the written file contains the two injected strings. * StreamReader sr = new StreamReader("C:/Test Files/example85Data2.xml"); * * String xmlFromFile = ""; * // write everything in the stream to the console * while (!sr.EndOfStream) * { * // store lines into a string * xmlFromFile += sr.ReadLine(); * } * * // Write xml from the file onto the console * Console.WriteLine(xmlFromFile); * /* END STREAMWRITER CODE */ } finally { if (xw != null) { xw.Close(); } } }// end test method
public void EV_1110_DefaultUniprocessorCustomTypeTest() { // Load a sample because I don't want to write a full construction method ClinicalDocument clinicalDocument = null; using (Stream inStream = typeof(EV_1110).Assembly.GetManifestResourceStream("MARC.Everest.Test.Resources.phrDocTesting_140219112155-0500.xml")) { XmlIts1Formatter fmtr = new XmlIts1Formatter(); fmtr.ValidateConformance = false; fmtr.GraphAides.Add(new ClinicalDocumentDatatypeFormatter()); var result = fmtr.Parse(XmlReader.Create(inStream), typeof(ClinicalDocument)); clinicalDocument = result.Structure as ClinicalDocument; } var observation = new ObservationMyProfile() { MoodCode = x_ActMoodDocumentObservation.Eventoccurrence, Code = "3202-20", EntryRelationship = new List <EntryRelationship>() { new EntryRelationship(x_ActRelationshipEntryRelationship.HasComponent, true) { ClinicalStatement = new ObservationMyProfile() } } } ; CascadeNullFlavor(observation.EntryRelationship[0], NullFlavor.Unknown); // Cascade a null flavor on one of the entries clinicalDocument.Component.GetBodyChoiceIfStructuredBody().Component[1].Section.Entry.Add(new Entry( x_ActRelationshipEntry.HasComponent, false, observation )); // Cascade a null flavor on one of the entries clinicalDocument.Component.GetBodyChoiceIfStructuredBody().Component[2].Section.Entry.Add(new Entry( x_ActRelationshipEntry.HasComponent, false, observation )); // Cascade a null flavor on one of the entries clinicalDocument.Component.GetBodyChoiceIfStructuredBody().Component[3].Section.Entry.Add(new Entry( x_ActRelationshipEntry.HasComponent, false, observation )); StringWriter sw = new StringWriter(); using (XmlWriter xw = XmlWriter.Create(sw, new XmlWriterSettings() { Indent = true })) { XmlIts1Formatter fmtr = new XmlIts1Formatter(); fmtr.ValidateConformance = false; fmtr.GraphAides.Add(new ClinicalDocumentDatatypeFormatter()); fmtr.Settings = SettingsType.DefaultUniprocessor; fmtr.Settings |= SettingsType.SuppressXsiNil; fmtr.Settings |= SettingsType.SuppressNullEnforcement; fmtr.Settings |= SettingsType.AlwaysCheckForOverrides; fmtr.RegisterXSITypeName("POCD_MT000040.Observation", typeof(MARC.Everest.Test.Regressions.EV_1102.ObservationWithConfidentialityCode)); using (XmlStateWriter xsw = new XmlStateWriter(xw)) { xsw.WriteStartElement("hl7", "ClinicalDocument", "urn:hl7-org:v3"); xsw.WriteAttributeString("xmlns", "xsi", null, XmlIts1Formatter.NS_XSI); xsw.WriteAttributeString("schemaLocation", XmlIts1Formatter.NS_XSI, @"urn:hl7-org:v3 Schemas/CDA-PITO-E2E.xsd"); xsw.WriteAttributeString("xmlns", null, null, @"urn:hl7-org:v3"); xsw.WriteAttributeString("xmlns", "hl7", null, @"urn:hl7-org:v3"); xsw.WriteAttributeString("xmlns", "e2e", null, @"http://standards.pito.bc.ca/E2E-DTC/cda"); xsw.WriteAttributeString("xmlns", "xs", null, @"http://www.w3.org/2001/XMLSchema"); IFormatterGraphResult result = fmtr.Graph(xsw, clinicalDocument); foreach (ResultDetail itm in result.Details) { Trace.WriteLine(String.Format("{0}:{1} @ {2}", itm.Type, itm.Message, itm.Location)); } xsw.WriteEndElement(); // clinical document xsw.Flush(); } } Trace.WriteLine(sw.ToString()); Regex re = new Regex(@"\<entryRelationship.*/\>"); if (re.IsMatch(sw.ToString())) { Assert.Fail("Output of entry relationship is not as expected"); } }
public void ExtractingUnsupportedPropertiesTest01() { XmlWriter xw = null; try { XmlIts1Formatter its1Formatter = new XmlIts1Formatter() { ValidateConformance = false, CreateRequiredElements = true }; // Assign R1 graphing aide its1Formatter.GraphAides.Add(new DatatypeFormatter() { ValidateConformance = true, CompatibilityMode = DatatypeFormatterCompatibilityMode.Universal }); // initialize the XmlWriter & State Writer StringWriter sw = new StringWriter(); // Initialize XmlWriter and state writer xw = XmlWriter.Create(sw, new XmlWriterSettings() { Indent = true }); XmlStateWriter xsw = new XmlStateWriter(xw); // Create and populate an instance of type 'Patient' var instance = Utils.CreatePatient( Guid.NewGuid(), new EN(), new AD(PostalAddressUse.VacationHome, new ADXP[] { } ) { // populate AD properties to see which are not supported ControlActExt = "populated", ControlActRoot = "populated", Flavor = "AD.BASIC", IsNotOrdered = true, UpdateMode = new CS <UpdateMode>(), Use = new SET <CS <PostalAddressUse> >(), UseablePeriod = new GTS(), ValidTimeHigh = new TS(), ValidTimeLow = new TS(), NullFlavor = null }, new TEL() ); // Format var result = its1Formatter.Graph(xsw, instance); // Iterate through the result details and get the unsupported details foreach (var dtl in result.Details) { if (dtl is UnsupportedDatatypeR1PropertyResultDetail) { var unsupp = dtl as UnsupportedDatatypeR1PropertyResultDetail; Console.WriteLine("The porperty '{0}' in datatype '{1}' was not formatted!", unsupp.PropertyName, unsupp.DatatypeName); } } // Flush the xml state writer xsw.Flush(); } finally { if (xw != null) { xw.Close(); } } }// end test method