private static XmlDocument Serialize(IGraphable graph) { using (var ms = new MemoryStream()) using (var xmlWriter = XmlWriter.Create(ms, new XmlWriterSettings { Indent = true })) using (var xsw = new XmlStateWriter(xmlWriter)) { var structureFormatter = CreateStructureFormater(); xsw.WriteStartElement("ClinicalDocument", "urn:hl7-org:v3"); xsw.WriteAttributeString("xmlns", "xsi", null, XmlIts1Formatter.NS_XSI); xsw.WriteAttributeString("xmlns", null, null, "urn:hl7-org:v3"); xsw.WriteAttributeString("xmlns", "custom", null, CustomNamespace); xsw.WriteAttributeString("xsi", "type", XmlIts1Formatter.NS_XSI, "custom:ClinicalDocument"); structureFormatter.Graph(xsw, graph); xsw.Close(); ms.Seek(0, SeekOrigin.Begin); Debug.WriteLine(Encoding.UTF8.GetString(ms.ToArray())); using (var reader = new XmlTextReader(ms)) { var result = new XmlDocument(); result.Load(reader); return result; } } }
/// <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(); }
public void UVPEqualsSerializationTest() { MARC.Everest.DataTypes.UVP<MARC.Everest.DataTypes.INT> aValue = new MARC.Everest.DataTypes.UVP<MARC.Everest.DataTypes.INT>(), bValue = null; aValue.Probability = (decimal)0.0f; aValue.Value = new MARC.Everest.DataTypes.INT(0); aValue.Flavor = "0"; StringWriter sw = new StringWriter(); DatatypeFormatter fmtr = new DatatypeFormatter() { CompatibilityMode = DatatypeFormatterCompatibilityMode.Canadian }; XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings() { Encoding = System.Text.Encoding.UTF8 })); xw.WriteStartElement("test"); fmtr.Graph(xw, aValue); xw.WriteEndElement(); // comp xw.Flush(); StringReader sr = new StringReader(sw.ToString()); XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr)); rdr.Read(); rdr.Read(); bValue = Util.Convert<MARC.Everest.DataTypes.UVP<MARC.Everest.DataTypes.INT>>(fmtr.Parse(rdr, typeof(MARC.Everest.DataTypes.UVP<MARC.Everest.DataTypes.INT>)).Structure); Assert.AreEqual(aValue, bValue); }
/// <summary> /// Write the content of <paramref name="graph"/> onto <paramref name="writer"/>. /// </summary> /// <param name="writer">The writer to serialize <paramref name="graph"/>.</param> /// <param name="graph">The object to graph to <paramref name="writer"/>.</param> public override void WriteObjectContent(System.Xml.XmlDictionaryWriter writer, object graph) { XmlStateWriter xsw = new XmlStateWriter(writer as XmlWriter); var result = Formatter.Graph(xsw, (IGraphable)graph); this.Details = result.Details; this.ResultCode = result.Code; }
/// <summary> /// Graphs object <paramref name="o"/> onto stream <paramref name="s"/> /// </summary> /// <param name="s">The stream to which <paramref name="o"/> is to be graphed</param> /// <param name="o">The object to be graphed</param> /// <returns>A <see cref="T:MARC.Everest.Formatters.XML.ITS1.Its1FormatterGraphResult"/> structure contianing the /// results of formatting</returns> /// <seealso cref="F:Graph(System.Xml.XmlWriter,MARC.Everest.Interfaces.IGraphable)"/> public IFormatterGraphResult Graph(Stream s, IGraphable o) { ThrowIfDisposed(); XmlWriter xwtr = XmlWriter.Create(s); XmlStateWriter xw = new XmlStateWriter(xwtr); if (o == null) return new XmlIts1FormatterGraphResult(ResultCode.AcceptedNonConformant, null); //TODO: Length will never be less than 0 so the logic should be > 0 instead of != 0. bool needsRoot = o.GetType().GetCustomAttributes(typeof(InteractionAttribute), true).Length == 0; if (needsRoot) { object[] sa = o.GetType().GetCustomAttributes(typeof(StructureAttribute), true); needsRoot = sa.Length == 0 || !(sa[0] as StructureAttribute).IsEntryPoint; if (needsRoot) { xw.WriteStartElement(o.GetType().FullName, "urn:hl7-org:v3"); xw.WriteAttributeString("xmlns", "xsi", null, XmlIts1Formatter.NS_XSI); } } // Determine if this is not an interaction var result = Graph(xw, o); if (needsRoot) xw.WriteEndElement(); xw.Flush(); return result; }
public void ADEqualsSerializationTest() { MARC.Everest.DataTypes.AD aValue = new MARC.Everest.DataTypes.AD(), bValue = null; aValue.Use = new MARC.Everest.DataTypes.SET<MARC.Everest.DataTypes.CS<MARC.Everest.DataTypes.PostalAddressUse>>(0) { new MARC.Everest.DataTypes.CS<MARC.Everest.DataTypes.PostalAddressUse>(MARC.Everest.DataTypes.PostalAddressUse.HomeAddress) }; aValue.IsNotOrdered = false; aValue.Part.Add(new MARC.Everest.DataTypes.ADXP("123 Main Street West", MARC.Everest.DataTypes.AddressPartType.AddressLine)); aValue.Flavor = "0"; StringWriter sw = new StringWriter(); DatatypeFormatter fmtr = new DatatypeFormatter() { CompatibilityMode = DatatypeFormatterCompatibilityMode.Canadian }; XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings() { Encoding = System.Text.Encoding.UTF8 })); xw.WriteStartElement("test", "urn:hl7-org:v3"); fmtr.Graph(xw, aValue); xw.WriteEndElement(); // comp xw.Flush(); StringReader sr = new StringReader(sw.ToString()); XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr)); rdr.Read(); rdr.Read(); bValue = Util.Convert<MARC.Everest.DataTypes.AD>(fmtr.Parse(rdr, typeof(MARC.Everest.DataTypes.AD)).Structure); Assert.AreEqual(aValue, bValue); }
public void EIVLEqualsSerializationTest() { MARC.Everest.DataTypes.EIVL<MARC.Everest.DataTypes.INT> aValue = new MARC.Everest.DataTypes.EIVL<MARC.Everest.DataTypes.INT>(), bValue = null; aValue.Event = new MARC.Everest.DataTypes.CS<MARC.Everest.DataTypes.DomainTimingEventType>(MARC.Everest.DataTypes.DomainTimingEventType.BeforeMeal); aValue.Offset = new MARC.Everest.DataTypes.IVL<MARC.Everest.DataTypes.PQ>(new MARC.Everest.DataTypes.PQ((decimal)0, "0")); aValue.Operator = new System.Nullable<MARC.Everest.DataTypes.SetOperator>(MARC.Everest.DataTypes.SetOperator.Hull); aValue.Flavor = "0"; StringWriter sw = new StringWriter(); DatatypeFormatter fmtr = new DatatypeFormatter() { CompatibilityMode = DatatypeFormatterCompatibilityMode.Canadian }; XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings() { Encoding = System.Text.Encoding.UTF8 })); xw.WriteStartElement("test"); fmtr.Graph(xw, aValue); xw.WriteEndElement(); // comp xw.Flush(); StringReader sr = new StringReader(sw.ToString()); XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr)); rdr.Read(); rdr.Read(); bValue = Util.Convert<MARC.Everest.DataTypes.EIVL<MARC.Everest.DataTypes.INT>>(fmtr.Parse(rdr, typeof(MARC.Everest.DataTypes.EIVL<MARC.Everest.DataTypes.INT>)).Structure); Assert.AreEqual(aValue, bValue); }
public void COEqualsSerializationTest() { MARC.Everest.DataTypes.CO aValue = new MARC.Everest.DataTypes.CO(), bValue = null; aValue.OriginalText = new MARC.Everest.DataTypes.ED(new System.Byte[] { 0 }, "0"); aValue.Code = new MARC.Everest.DataTypes.CD<System.String>("0"); aValue.Code.CodeSystem = "0"; aValue.Code.CodeSystemName = "0"; aValue.Code.CodeSystemVersion = "0"; aValue.Flavor = "0"; StringWriter sw = new StringWriter(); DatatypeFormatter fmtr = new DatatypeFormatter() { CompatibilityMode = DatatypeFormatterCompatibilityMode.Canadian }; XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings() { Encoding = System.Text.Encoding.UTF8 })); xw.WriteStartElement("test"); fmtr.Graph(xw, aValue); xw.WriteEndElement(); // comp xw.Flush(); StringReader sr = new StringReader(sw.ToString()); XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr)); rdr.Read(); rdr.Read(); bValue = Util.Convert<MARC.Everest.DataTypes.CO>(fmtr.Parse(rdr, typeof(MARC.Everest.DataTypes.CO)).Structure); Assert.AreEqual(aValue, bValue); }
public void EDEqualsSerializationTest() { MARC.Everest.DataTypes.ED aValue = new MARC.Everest.DataTypes.ED(), bValue = null; aValue.Data = new System.Byte[] { 0 }; aValue.Compression = new System.Nullable<MARC.Everest.DataTypes.Interfaces.EncapsulatedDataCompression>(MARC.Everest.DataTypes.Interfaces.EncapsulatedDataCompression.DF); aValue.Representation = MARC.Everest.DataTypes.Interfaces.EncapsulatedDataRepresentation.TXT; aValue.Language = "0"; aValue.MediaType = "0"; aValue.IntegrityCheck = new System.Byte[] { 0 }; aValue.IntegrityCheckAlgorithm = new System.Nullable<MARC.Everest.DataTypes.Interfaces.EncapsulatedDataIntegrityAlgorithm>(MARC.Everest.DataTypes.Interfaces.EncapsulatedDataIntegrityAlgorithm.SHA1); aValue.Thumbnail = new MARC.Everest.DataTypes.ED(new System.Byte[] { 0 }, "0"); aValue.Flavor = "0"; StringWriter sw = new StringWriter(); DatatypeFormatter fmtr = new DatatypeFormatter() { CompatibilityMode = DatatypeFormatterCompatibilityMode.Canadian }; XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings() { Encoding = System.Text.Encoding.UTF8 })); xw.WriteStartElement("test"); fmtr.Graph(xw, aValue); xw.WriteEndElement(); // comp xw.Flush(); StringReader sr = new StringReader(sw.ToString()); XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr)); rdr.Read(); rdr.Read(); bValue = Util.Convert<MARC.Everest.DataTypes.ED>(fmtr.Parse(rdr, typeof(MARC.Everest.DataTypes.ED)).Structure); Assert.AreEqual(aValue, bValue); }
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 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
private static void MakeCCDA() { // 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(); fmtr.GraphAides.Add(new DatatypeFormatter()); fmtr.ValidateConformance = false; ClinicalDocument ccda = new ClinicalDocument(); MakeCCDAHeader(ccda); MakeCCDABody(ccda); Console.Clear(); Console.WriteLine("CCD Generated"); Console.ReadKey(); //ValidateCCDA(ccda); XmlStateWriter xsw = new XmlStateWriter(XmlWriter.Create("D:\\EverestPoC.xml", new XmlWriterSettings() { Indent = true })); DateTime start = DateTime.Now; var result = fmtr.Graph(xsw, ccda); xsw.Flush(); }
public void IVLInclusiveFormattingTest() { IVL<INT> intIvl = new IVL<INT>(1, 4); intIvl.LowClosed = true; intIvl.HighClosed = false; MemoryStream ms = new MemoryStream(); XmlStateWriter writer = new XmlStateWriter(XmlWriter.Create(ms)); writer.WriteStartElement("ivl", "urn:hl7-org:v3"); MARC.Everest.Formatters.XML.Datatypes.R1.DatatypeFormatter fmtr = new MARC.Everest.Formatters.XML.Datatypes.R1.DatatypeFormatter(); fmtr.Graph(writer, intIvl); writer.Close(); ms.Seek(0, SeekOrigin.Begin); XmlDocument d = new XmlDocument(); d.Load(ms); Tracer.Trace(d.OuterXml); Assert.IsTrue(d.OuterXml.Contains("inclusive")); }
public void BuildPatientTest02() { // Flag used to verify if the graph result // contains details alongside its errors. bool noDetails = true; // Flag used to verify that the create instance is valid. bool valInstance = false; // Create a formatter with a graph aide XmlIts1Formatter fmtr = new XmlIts1Formatter(); // Gets or sets a list of aide formatters // that assist in the formatting of this instance fmtr.GraphAides.Add(new DatatypeFormatter()); // Format to a string StringWriter sw = new StringWriter(); XmlStateWriter xmlSw = new XmlStateWriter( XmlWriter.Create(sw, new XmlWriterSettings() { Indent = true }) ); // Call our method here with invalid instance identifier. var patient = Utils.CreatePatient( new II(), EN.CreateEN(EntityNameUse.Legal, new ENXP("John", EntityNamePartType.Given), new ENXP("Smith", EntityNamePartType.Family) ), AD.CreateAD(PostalAddressUse.HomeAddress, "123 Main Street West", "Hamilton", "Ontario", "Canada" ), "*****@*****.**" ); // Format to the formatter var result = fmtr.Graph(xmlSw, patient); // Flush and close xmlSw.Close(); // Output to console Console.WriteLine("XML:"); Console.WriteLine(sw.ToString()); // If we get errors, set error catching flag to false and // print the details of each error. if (result.Details.Count() > 0) { noDetails = false; Console.WriteLine("validation:"); foreach (var dtl in result.Details) Console.WriteLine("{0} : {1}", dtl.Type, dtl.Message); } else { valInstance = true; } // Assert: Either there are no errors, // or there are details in the 'details' collection. if (noDetails) { Assert.AreEqual(valInstance, true); } else if (!valInstance) { Assert.AreEqual(noDetails, false); } else { // Test fails Assert.Fail(); } }
static void Main(string[] args) { // Create a formatter with a graph aide XmlIts1Formatter fmtr = new XmlIts1Formatter(); // Gets or sets a list of aide formatters // that assist in the formatting of this instance fmtr.GraphAides.Add(new DatatypeFormatter()); // Format to a string StringWriter sw = new StringWriter(); XmlStateWriter xmlSw = new XmlStateWriter( XmlWriter.Create(sw, new XmlWriterSettings(){Indent = true}) ); // Call our method here... var patient = CreatePatient( Guid.NewGuid(), EN.CreateEN(EntityNameUse.Legal, new ENXP ("John", EntityNamePartType.Given), new ENXP ("Smith", EntityNamePartType.Family) ), AD.CreateAD(PostalAddressUse.HomeAddress, "123 Main Street West", "Hamilton", "Ontario", "Canada" ), "*****@*****.**" ); // Format to the formatter var details = fmtr.Graph(xmlSw, patient); // Flush and close xmlSw.Close(); // Output to console Console.WriteLine("XML: "); Console.WriteLine(sw.ToString()); Console.WriteLine("Validation:"); foreach (var dtl in details.Details) { Console.WriteLine("{0} : {1}", dtl.Type, dtl.Message); } Console.ReadKey(); }
public void IIEqualsSerializationTest() { MARC.Everest.DataTypes.II aValue = new MARC.Everest.DataTypes.II(), bValue = null; aValue.Root = "0"; aValue.Extension = "0"; aValue.Displayable = false; aValue.Use = new System.Nullable<MARC.Everest.DataTypes.IdentifierUse>(MARC.Everest.DataTypes.IdentifierUse.Business); aValue.Flavor = "0"; StringWriter sw = new StringWriter(); DatatypeFormatter fmtr = new DatatypeFormatter() { CompatibilityMode = DatatypeFormatterCompatibilityMode.Canadian }; XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings() { Encoding = System.Text.Encoding.UTF8 })); xw.WriteStartElement("test"); fmtr.Graph(xw, aValue); xw.WriteEndElement(); // comp xw.Flush(); StringReader sr = new StringReader(sw.ToString()); XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr)); rdr.Read(); rdr.Read(); bValue = Util.Convert<MARC.Everest.DataTypes.II>(fmtr.Parse(rdr, typeof(MARC.Everest.DataTypes.II)).Structure); Assert.AreEqual(aValue, bValue); }
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 IVLEqualsSerializationLowTest() { MARC.Everest.DataTypes.IVL<MARC.Everest.DataTypes.INT> aValue = new MARC.Everest.DataTypes.IVL<MARC.Everest.DataTypes.INT>(), bValue = null; aValue.Low = new MARC.Everest.DataTypes.INT(0); aValue.LowClosed = false; //aValue.High = new MARC.Everest.DataTypes.INT(0); //aValue.HighIncluded = false; //aValue.Width = new MARC.Everest.DataTypes.PQ(0, "0"); aValue.Operator = new System.Nullable<MARC.Everest.DataTypes.SetOperator>(MARC.Everest.DataTypes.SetOperator.Hull); aValue.Flavor = "0"; StringWriter sw = new StringWriter(); DatatypeFormatter fmtr = new DatatypeFormatter() { CompatibilityMode = DatatypeFormatterCompatibilityMode.Canadian }; XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings() { Encoding = System.Text.Encoding.UTF8 })); xw.WriteStartElement("test"); fmtr.Graph(xw, aValue); xw.WriteEndElement(); // comp xw.Flush(); StringReader sr = new StringReader(sw.ToString()); XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr)); rdr.Read(); rdr.Read(); bValue = Util.Convert<MARC.Everest.DataTypes.IVL<MARC.Everest.DataTypes.INT>>(fmtr.Parse(rdr, typeof(MARC.Everest.DataTypes.IVL<MARC.Everest.DataTypes.INT>)).Structure); Assert.AreEqual(aValue, bValue); }
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 ENEqualsSerializationTest() { MARC.Everest.DataTypes.EN aValue = new MARC.Everest.DataTypes.EN(), bValue = null; aValue.Use = new MARC.Everest.DataTypes.SET<MARC.Everest.DataTypes.CS<MARC.Everest.DataTypes.EntityNameUse>>(MARC.Everest.DataTypes.EntityNameUse.Legal); aValue.Flavor = "0"; aValue.Part.Add(new MARC.Everest.DataTypes.ENXP("Bob", MARC.Everest.DataTypes.EntityNamePartType.Given)); aValue.Part.Add(new MARC.Everest.DataTypes.ENXP("Dole", MARC.Everest.DataTypes.EntityNamePartType.Family)); StringWriter sw = new StringWriter(); DatatypeFormatter fmtr = new DatatypeFormatter() { CompatibilityMode = DatatypeFormatterCompatibilityMode.Canadian }; XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings() { Encoding = System.Text.Encoding.UTF8 })); xw.WriteStartElement("test"); fmtr.Graph(xw, aValue); xw.WriteEndElement(); // comp xw.Flush(); StringReader sr = new StringReader(sw.ToString()); XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr)); rdr.Read(); rdr.Read(); bValue = Util.Convert<MARC.Everest.DataTypes.EN>(fmtr.Parse(rdr, typeof(MARC.Everest.DataTypes.EN)).Structure); Assert.AreEqual(aValue, bValue); }
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()); }
public void ADXPEqualsSerializationTest() { MARC.Everest.DataTypes.ADXP aValue = new MARC.Everest.DataTypes.ADXP(), bValue = null; aValue.Value = "0"; aValue.Code = "0"; aValue.Type = new System.Nullable<MARC.Everest.DataTypes.AddressPartType>(MARC.Everest.DataTypes.AddressPartType.AddressLine); aValue.Flavor = "0"; StringWriter sw = new StringWriter(); DatatypeFormatter fmtr = new DatatypeFormatter() { CompatibilityMode = DatatypeFormatterCompatibilityMode.Canadian }; XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings() { Encoding = System.Text.Encoding.UTF8 })); xw.WriteStartElement("test"); fmtr.Graph(xw, aValue); xw.WriteEndElement(); // comp xw.Flush(); StringReader sr = new StringReader(sw.ToString()); XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr)); rdr.Read(); rdr.Read(); bValue = Util.Convert<MARC.Everest.DataTypes.ADXP>(fmtr.Parse(rdr, typeof(MARC.Everest.DataTypes.ADXP)).Structure); bValue.Type = MARC.Everest.DataTypes.AddressPartType.AddressLine; Assert.AreEqual(aValue, bValue); }
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 TELEqualsSerializationTest() { MARC.Everest.DataTypes.TEL aValue = new MARC.Everest.DataTypes.TEL(), bValue = null; aValue.Use = new MARC.Everest.DataTypes.SET<MARC.Everest.DataTypes.CS<MARC.Everest.DataTypes.Interfaces.TelecommunicationAddressUse>>(0) { new MARC.Everest.DataTypes.CS<MARC.Everest.DataTypes.Interfaces.TelecommunicationAddressUse>(MARC.Everest.DataTypes.Interfaces.TelecommunicationAddressUse.Home) }; aValue.UseablePeriod = new MARC.Everest.DataTypes.GTS(new MARC.Everest.DataTypes.IVL<MARC.Everest.DataTypes.TS>(new MARC.Everest.DataTypes.TS(DateTime.Parse("2011-1-10")))); aValue.Value = "0"; aValue.Flavor = "0"; StringWriter sw = new StringWriter(); DatatypeFormatter fmtr = new DatatypeFormatter() { CompatibilityMode = DatatypeFormatterCompatibilityMode.Canadian }; XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings() { Encoding = System.Text.Encoding.UTF8 })); xw.WriteStartElement("test"); fmtr.Graph(xw, aValue); xw.WriteEndElement(); // comp xw.Flush(); StringReader sr = new StringReader(sw.ToString()); XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr)); rdr.Read(); rdr.Read(); bValue = Util.Convert<MARC.Everest.DataTypes.TEL>(fmtr.Parse(rdr, typeof(MARC.Everest.DataTypes.TEL)).Structure); Assert.AreEqual(aValue, bValue); }
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(); }
public void PIVLEqualsSerializationTest() { MARC.Everest.DataTypes.PIVL<MARC.Everest.DataTypes.INT> aValue = new MARC.Everest.DataTypes.PIVL<MARC.Everest.DataTypes.INT>(), bValue = null; aValue.Phase = new MARC.Everest.DataTypes.IVL<MARC.Everest.DataTypes.INT>(new MARC.Everest.DataTypes.INT(0)); aValue.Period = new MARC.Everest.DataTypes.PQ((decimal)0, "0"); aValue.Alignment = new System.Nullable<MARC.Everest.DataTypes.CalendarCycle>(MARC.Everest.DataTypes.CalendarCycle.Year); aValue.InstitutionSpecified = false; aValue.Operator = new System.Nullable<MARC.Everest.DataTypes.SetOperator>(MARC.Everest.DataTypes.SetOperator.Hull); aValue.Flavor = "0"; StringWriter sw = new StringWriter(); DatatypeFormatter fmtr = new DatatypeFormatter() { CompatibilityMode = DatatypeFormatterCompatibilityMode.Canadian }; XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings() { Encoding = System.Text.Encoding.UTF8 })); xw.WriteStartElement("test"); fmtr.Graph(xw, aValue); xw.WriteEndElement(); // comp xw.Flush(); StringReader sr = new StringReader(sw.ToString()); XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr)); rdr.Read(); rdr.Read(); bValue = Util.Convert<MARC.Everest.DataTypes.PIVL<MARC.Everest.DataTypes.INT>>(fmtr.Parse(rdr, typeof(MARC.Everest.DataTypes.PIVL<MARC.Everest.DataTypes.INT>)).Structure); Assert.AreEqual(aValue, bValue); }
/// <summary> /// Graphs <paramref name="o"/> onto the <see cref="T:System.Xml.XmlWriter"/> <paramref name="s"/> /// </summary> /// <param name="s">The <see cref="T:System.Xml.XmlWriter"/> that should be used to graph the object</param> /// <param name="o">The <see cref="T:MARC.Everest.Interfaces.IGraphable"/> that should be graphed</param> /// <returns>A <see cref="T:MARC.Everest.Formatters.XML.ITS1.Its1FormatterGraphResult"/> containing the results of the graph</returns> /// <remarks> /// <para> /// This particular overload of the Graph method can be used to graph objects into a <see cref="T:System.Xml.XmlWriter"/> and can provide /// an opportunity to use Everest as an assistant (or XmlSerializerSurrogate) for more complex systems like WCF. /// </para> /// <example> /// <code lang="cs" title="Using Everest as a Serializer Assistant"> /// <![CDATA[ /// StringWriter sw = new StringWriter(); /// XmlWriter writer = XmlWriter.Create(sw); /// writer.WriteStartElement("hello", "urn:my-org"); /// /// Formatter f = new Formatter(); /// f.GraphAides.Add(typeof(MARC.Everest.Formatters.XML.DataTypes.R1.Formatter)); /// f.ValidateConformance = false; /// f.Graph(writer, new MCCI_IN000002CA()); /// /// writer.WriteEndElement(); /// writer.Close(); /// Console.WriteLine(sw.ToString()); /// /// ]]> /// </code> /// outputs /// <code lang="xml" title="Output of example"> /// <![CDATA[ /// <hello xmlns="urn:my-org"> /// <MCCI_IN000002CA xmlns="urn:hl7-org:v3"/> /// </hello> /// ]]> /// </code> /// </example> /// <para> /// When using this method, it is recommended that you pass a <see cref="T:MARC.Everest.Xml.XmlStateWriter"/> as it /// will allow the formatter to give additional location information when reporting issues. /// </para> /// </remarks> public IFormatterGraphResult Graph(XmlWriter s, IGraphable o) { ThrowIfDisposed(); var resultContext = new XmlIts1FormatterGraphResult(ResultCode.Accepted, null); IGraphable context = null; // Clear out result cache if (s.WriteState == WriteState.Start || String.IsNullOrEmpty(s.ToString()) || o is IInteraction) context = o; if (!(s is XmlStateWriter)) s = new XmlStateWriter(s); if (o == null) resultContext.Code = ResultCode.AcceptedNonConformant; else { GraphObject(s, o, o.GetType(), context, resultContext); resultContext.Code = CalculateResultCode(resultContext.Details); } return resultContext; }