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()); } }
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); } } }
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 EV_1087Test() { RelatedPerson person = new RelatedPerson( SET <PN> .CreateSET(new PN(EntityNameUse.Legal, "John Smith")), SET <TEL> .CreateSET((TEL)"mailto:[email protected]"), "F", DateTime.Now, DateTime.Today, SET <AD> .CreateSET(AD.CreateAD(PostalAddressUse.Direct, new ADXP("123 Main Street West, Hamilton, ON"))), null); person.DeceasedInd = true; // This fails try { XmlIts1Formatter fmtr = new XmlIts1Formatter(); fmtr.Settings = SettingsType.DefaultLegacy; fmtr.GraphAides.Add(new DatatypeFormatter()); StringWriter sw = new StringWriter(); using (XmlStateWriter writer = new XmlStateWriter(XmlWriter.Create(sw))) { writer.WriteStartElement("test", "urn:hl7-org:v3"); fmtr.Graph(writer, person); writer.WriteEndElement(); } } catch (Exception ex) { Assert.Fail(); } }
/// <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()); }
/// <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; }
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(); }
public void FormatPatient() { // 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 = Utils.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. // Details results in a result code // that indicates the outcome of the graph. 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); } }
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")); }
/// <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()); } }
/// <summary> /// Serialize query /// </summary> internal static byte[] SerializeQuery(IGraphable queryByParameter) { using (XmlIts1Formatter fmtr = new XmlIts1Formatter() { ValidateConformance = false }) { StringBuilder sb = new StringBuilder(); XmlStateWriter writer = new XmlStateWriter(XmlWriter.Create(sb)); // Write the start element writer.WriteStartElement("queryByParameter", "urn:hl7-org:v3"); fmtr.GraphAides.Add(new DatatypeFormatter() { CompatibilityMode = DatatypeFormatterCompatibilityMode.Universal, ValidateConformance = false }); fmtr.Graph(writer, queryByParameter); writer.WriteEndElement(); writer.Close(); // Return the constructed result return(Encoding.ASCII.GetBytes(sb.ToString())); } }
public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result) { ANY instance = o as ANY; XmlStateWriter stw = s as XmlStateWriter; // Now render if (instance == null) { throw new InvalidOperationException("Could not cast object to the ANY data type"); } else if (instance.NullFlavor != null) { s.WriteAttributeString("nullFlavor", Util.ToWireFormat(instance.NullFlavor)); } else if (instance.Flavor != null) { if (result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian) { s.WriteAttributeString("specializationType", instance.Flavor); } else { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Flavor", "ANY", s.ToString())); } } string currentElementName = ""; if (s is MARC.Everest.Xml.XmlStateWriter) { currentElementName = (s as MARC.Everest.Xml.XmlStateWriter).CurrentPath; } // Validate if (result.ValidateConformance && !instance.Validate()) { result.AddResultDetail(new DatatypeValidationResultDetail(ResultDetailType.Error, o.GetType().Name, currentElementName)); } // Disabled for test // Validate flavor... IResultDetail[] flavor; if (instance.Flavor != null && result.ValidateConformance && Util.ValidateFlavor(instance.Flavor.ToUpper(), instance, out flavor) == false) { result.AddResultDetail(new DatatypeFlavorValidationResultDetail(ResultDetailType.Warning, instance.GetType().Name, instance.Flavor, currentElementName)); result.AddResultDetail(flavor); } // Warn if items can't be represented in R1 if (instance.ControlActExt != null) { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ControlActExt", "ANY", currentElementName)); } if (instance.ControlActRoot != null) { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ControlActRoot", "ANY", currentElementName)); } if (instance.ValidTimeHigh != null) { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ValidTimeHigh", "ANY", currentElementName)); } if (instance.ValidTimeLow != null) { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ValidTimeLow", "ANY", currentElementName)); } if (instance.UpdateMode != null) { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "UpdateMode", "ANY", currentElementName)); } }
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(); } }
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
public virtual void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result) { ANY instance = o as ANY; XmlStateWriter stw = s as XmlStateWriter; // Now render if (instance == null) { throw new InvalidOperationException("Could not cast object to the ANY data type"); } else if (instance.NullFlavor != null) { s.WriteAttributeString("nullFlavor", Util.ToWireFormat(instance.NullFlavor)); } else if (instance.Flavor != null) { if (result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian) { s.WriteAttributeString("specializationType", instance.Flavor); } else { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Flavor", "ANY", s.ToString())); } } // Validate if (result.ValidateConformance && !instance.Validate()) { foreach (var r in instance.ValidateEx()) { r.Location = s.ToString(); result.AddResultDetail(r); } result.Code = ResultCode.Rejected; } // Disabled for test // Validate flavor... IResultDetail[] flavor; if (instance.Flavor != null && result.ValidateConformance && Util.ValidateFlavor(instance.Flavor.ToUpper(), instance, out flavor) == false) { result.AddResultDetail(new DatatypeFlavorValidationResultDetail(ResultDetailType.Warning, instance.GetType().Name, instance.Flavor, s.ToString())); result.AddResultDetail(flavor); if (result.Code < ResultCode.AcceptedNonConformant) { result.Code = ResultCode.AcceptedNonConformant; } } // Warn if items can't be represented in R1 if (instance.ControlActExt != null) { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ControlActExt", "ANY", s.ToString())); } if (instance.ControlActRoot != null) { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ControlActRoot", "ANY", s.ToString())); } if (instance.ValidTimeHigh != null && !(instance is EN)) { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ValidTimeHigh", "ANY", s.ToString())); } if (instance.ValidTimeLow != null && !(instance is EN)) { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ValidTimeLow", "ANY", s.ToString())); } if (instance.UpdateMode != null) { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "UpdateMode", "ANY", s.ToString())); } }
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 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
static void Main(string[] args) { ClinicalDocument cda = new ClinicalDocument(); cda.MoodCode = null; cda.ClassCode = null; cda.TypeId = II.CreatePublic("2.16.840.1.113883.1.3", "POCD_HD000040"); cda.TemplateId = LIST <II> .CreateList( new II("2.16.840.1.113883.3.4424.13.10.1.1"), new II("2.16.840.1.113883.3.4424.13.10.1.2"), new II("2.16.840.1.113883.3.4424.13.10.1.3", "1.1.1")); cda.Id = new II("2.16.840.1.113883.3.4424.7.2.1", "2345678") { Displayable = true }; var pi = new PertinentInformation() { TemplateId = LIST <II> .CreateList(new II("1.13.2.3")) }; pi.CoveragePlan = new CoveragePlan(new CD <String>("PUBLICPOL", "2.16.840.1.113883.11.19350")); pi.CoveragePlan.Code.Qualifier = LIST <CR <String> > .CreateList( new CR <String>( new CV <String>("RLEKUD", "1.2.3.4", null, null, "Refundacja ...", null), new CD <String>("IB", "1.2.3.4") ) ); //cda.DataEnterer = new MyDataEnterer(); //cda.PertinentInformation.Add(pi); cda.RecordTarget.Add(new RecordTarget { PatientRole = new PatientRole() }); cda.RecordTarget[0].PatientRole.Addr = SET <AD> .CreateSET(AD.CreateAD(new ADXPPL("Kiszka", AddressPartType.PostalCode) { PostCity = "PT" })); XmlIts1Formatter xftr = new XmlIts1Formatter(); //xftr.AddFormatterAssembly(Assembly.GetExecutingAssembly()); xftr.GraphAides.Add(new ClinicalDocumentDatatypeFormatter()); xftr.ValidateConformance = false; xftr.RegisterXSITypeName("POCD_MT000040UV.ClinicalDocument", typeof(ClinicalDocument)); xftr.Settings |= SettingsType.AlwaysCheckForOverrides; using (XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(Console.Out, new XmlWriterSettings() { Indent = true }))) { xw.WriteStartElement("", "ClinicalDocument", "urn:hl7-org:v3"); xw.WriteAttributeString("xmlns", "extPL", null, "http://www.csioz.gov.pl/xsd/extPL/r1"); xw.WriteAttributeString("xmlns", "xsi", null, XmlIts1Formatter.NS_XSI); //xw.WriteAttributeString("xsi", "type", XmlIts1Formatter.NS_XSI, "extPL:ClinicalDocument"); xftr.Graph(xw, cda); xw.WriteEndElement(); } PatientData pat = new PatientData() { Address = "123 Main Street West", City = "Hamilton", DateOfBirth = new DateTime(1995, 04, 03), FamilyName = "Smith", Gender = "F", GivenName = "Sarah", Id = "102-30343", OtherIds = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("2.16.2.3.2.3.2.4", "123-231-435") }, State = "ON" }; PhysicianData aut = new PhysicianData() { AddressLine = " 35 King Street West ", City = " Hamilton ", OrgId = " 123 - 1221 ", OrgName = new[] { " Good Health Clinics " }, PhysicianId = " 1023433 - ON ", PhysicianName = new string[] { " Dr.", " Francis ", " F ", " Family " }, Postal = "L0R2A0" }; // var o = Parse(@"C:\temp\schematron\rec.xml"); // Create the CDA //ClinicalDocument doc = CreateAPSDocument(pat, null, aut, DateTime.Now); //PrintStructure(doc); Console.ReadKey(); }