Read a section in FHIR Document Reference Data - c#

Is there any way to read a CCD Data section inside the CCDA XML using FhirSerialization in R4.
I have a DocumentReference FHIR Object and in that I have DATA section in a byte format. I have converted it to a string using the below line.
string decodedSamlRequest = System.Text.Encoding.UTF8.GetString(dfv);
and now in this decodedSamlRequest I have the CCD XML content.
<?xml version="1.0" encoding="UTF-8"?>
<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:voc="xyz" xmlns:sdtc="xyz" xmlns:xsi="xyz">
<realmCode code="US"/>
<assignedCustodian>
<representedCustodianOrganization>
<id root="123" extension="92"/>
<name>some xyz</name>
<telecom use="WP" value="tel:1234"/>
<addr use="WP">
<streetAddressLine>address</streetAddressLine>
<city>city</city>
<state>state</state>
<postalCode>12345</postalCode>
<country>US</country>
</addr>
</representedCustodianOrganization>
</assignedCustodian>
</custodian>
</ClinicalDocument>
In this I need to read the CITY element under Custodian Tag.

From FHIR's perspective, all content within an attachment is opaque. You can certainly write code to parse, access and manipulate that content - and could even create custom SearchParameters that could filter based on it. But you can't navigate into it using FHIRPath or using the navigation machinery found in any of the reference implementations.

Related

DTD must be defined before the document root element

I'm creating an XML file programatically. To create the starting tag I have the code:
Dim XDoc As XDocument = <?xml version="1.0" encoding="UTF-8" standalone="yes"?><Customers></Customers>
It's then followed by looping through the data, adding in the required elements using the Root.Add method. The XML displays in the browser successfully.
Xdoc.Root.Add(<customer>
<fields>
</customer>
When some clients connect to this XML data, if there is no data to retrieve the page is displayed as:
<?xml version="1.0"?>
<Customers/>
When reading the XML URL from a .NET project:
Dim Xdoc As XDocument = XDocument.Load(UrlToXmlFile)
The error "DTD must be defined before the document root element" is thrown.
Although I can trap the error, I thought perhaps I may have done something wrong when creating the XML (XML isn't my strong point).
Some sites suggest adding a DTD (<!DOCTYPE note SYSTEM "Note.dtd"> for example). I don't know if this is correct or if I can ignore the error or if there is a better way to to declare this?
Update: when i view the page directly in Chrome, it displays the XML as
<Customers>
<customer>....</customer>
<customer>....</customer>
</Customers>
in IE it displays as
<?xml version="1.0"?>
<Customers>
<customer>....</customer>
<customer>....</customer>
</Customers>
but in both browsers when i look at 'view source' it shows
<Customers>
<customer>....</customer>
<customer>....</customer>
</Customers>
I don't know of this would be an issue?
Update 2
XDoc.Save(Sr)
Response.Clear()
Response.Buffer = True
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/xml"
Response.Write(Sr.GetStringBuilder.ToString)
Response.Flush()
Response.End()
Here is an example showing the generation/saving and loading of your xml with no errors.
Dim XmlFile As String = "C:\\Temp\\TestData.xml"
Dim XDoc As XDocument = <?xml version="1.0" encoding="UTF-8"?><Customers></Customers>
For ForCount As Integer = 0 To 10
XDoc.Root.Add("<customer>Customer" & ForCount.ToString & "</customer>")
Next
XDoc.Save(XmlFile)
Dim XDocReader As XDocument = XDocument.Load(XmlFile)
Also it sounds like you might be using a web service. Use fiddler to verify your web service is not adding in that attribute when serving the data. I do not see how you are exporting the XML. Make sure you are not just doing a .ToSrting on XDoc, that will only generate the inner XML.

how to add uri of lexicon file in xml

I am writing code for custom grammar for that I created a lexicon file which I am using in XML grammar file. I want to add the lexicon with my software to the end user as an embedded resources so how can i reference it's uri in XML?
my XML codes are
<?xml version="1.0" encoding="utf-8"?>
<grammar
version="1.0" mode="voice" root="Voice_Automator"
xml:lang="en-IN" tag-format="semantics/1.0"
sapi:alphabet="x-microsoft-ups"
xml:base="http://www.contoso.com/"
xmlns="http://www.w3.org/2001/06/grammar"
xmlns:sapi="http://schemas.microsoft.com/Speech/2002/06/SRGSExtensions">
**<lexicon uri="C:\Users\Agrawal\Documents\Visual Studio 2010\Projects\123.pls" />**
i want to use 123.pls file as an embedded resource so at the end user the program should load it properly
Use one of the XML link mechanisms:
XLink
<lexicon xmlns:link="http://www.w3.org/1999/xlink" xlink:href="C:\Users\Agrawal\Documents\Visual Studio 2010\Projects\123.pls"/>
External Entity
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE foo [<!ENTITY bar SYSTEM "C:\Users\Agrawal\Documents\Visual Studio 2010\Projects\123.pls"> ]>
<grammar version="1.0" mode="voice" root="Voice_Automator" xml:lang="en-IN" tag-format="semantics/1.0" sapi:alphabet="x-microsoft-ups" xml:base="http://www.contoso.com/" xmlns="http://www.w3.org/2001/06/grammar" xmlns:sapi="http://schemas.microsoft.com/Speech/2002/06/SRGSExtensions">
<? &bar; ?>
</grammar>
References
XML Linking Language
XML Linking and Style
XML: How to read one file into another
XML: How to load the contents of one xml file into another
How do I check for the existence of an external file with XSL?
how to use xpointer to link to specific node from another document
Generate HTML / Help files from VS 2010 C# XML documentation

Modifying xml file without changing special chars

I have an XML file with structure:
<?xml version='1.0'?>
<a>
<b>
<d>
<LineCode>0</LineCode>
<LineName>Metro</LineName>
<LineDescription>Test C&C all countries with MCFM</LineDescription>
</d>
.......
<e>.....</e>
<f>....</f>
</b>
</a>
In this file I have added section with following code:
XElement newElement = new XElement("e",
new XElement("e1", "test1"),
new XElement("e2", "test2"),
new XElement("e3", "test3 ));
doc.Root.Element("a").Element("d").AddAfterSelf(newElement);
doc.Save(file.Directory + "//" + file.Name);
After i run this code all my special chars used in the initial XML file are modified .
For exemple first row became:
<?xml version="1.0" encoding="utf-8"?>
line became:
<LineDescription>Test C&C all countries with MCFM</LineDescription>
How to add the new section in my XML file without modifying the existing chars?Or how to save without modifying existing special chars?
== Observation #1 ==
<!-- Before: -->
<?xml version='1.0'?>
<!-- After: -->
<?xml version="1.0" encoding="utf-8"?>
Explanation: If the encoding attribute is omitted, utf-8 is the default.
== Observation #2 ==
<!-- Before: -->
&
<!-- After: -->
&
Explanation: These XML entities for representing the ampersand are equivalent.
== Summary ==
The new files are to be used by other applications and it is possible that there
might be problems reading or processing the new files.
Well-behaved XML processing software should treat your before- and after- documents in an equivalent fashion. So, if you encounter problems reading or processing the newly edited XML files, those problems really should be addressed. But it is possible that you may not have the kinds of problems that you anticipate.
If the code processing your file is supposed to handle standard XML, it should not matter which form the characters are stored in. Your original file is using the numeric code for the character, while the newly saved file is using the standard entity name. The same applies for the XML header line - version='1.0' and version="1.0" - should be treated exactly the same, and the additional element just identifies which character set was used in writing the file.
Provided your other applications are using standard XML parsers, or custom parsers which are capable of reading standard XML there should be no problem with the modified XML. The only issue you might have is if these other applications cannot read standard XML (ie they assume that all values use single quotes, or they don't correctly process the XML standard entities, etc) - in this case you may need to use a filtering parser on any file sent to those applications to ensure that these requirements are met. (ie a simple SAX parser which writes out the file as the events are triggered using the additional limitations)

How can I Deserialize a RSS?

This is my code:
var objectText = XmlReader.Create(requestedURL);
XmlSerializer mySerializer = new XmlSerializer(typeof(InstagramItems));
var instagramItems = (InstagramItems)mySerializer.Deserialize(objectText);
but seems it can't work with RSS (which are "XML more or less"):
Server Error - <rss xmlns=''> was not expected.
How can I do it? I believe there are .NET library without using 3rd part plugins.
Part of the RSS:
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:georss="http://www.georss.org/georss" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<title>Photos tagged as "example" on Instagram</title>
<link>http://instagram.com</link>
<description>Photos tagged as "example" on Instagram</description>
<atom:link href="http://instagram.com/tags/example/feed/recent.rss" rel="self" />
</channel>
Step 1: Download the RSS XSD : http://www.thearchitect.co.uk/schemas/rss-2_0.xsd
Step 2: Use xsd.exe to generate an RSS type based on the schema
Step 3: If objectText is only an RSS document, then just substitute your newly created RSS type for InstagramITems in the above code.
Step 3a: If the object text is mixed Instagram and RSS code, then use the DataContractSerializer and pre-register both Instagram and RSS types with the DataContractSerializer before attempting to deserialize
XmlSerializer works with specific xml format, if you suply any other format other then which it expects the metioned exception will be throwned.
You can parse the xml manualy and create InstagramItems from the parsed xml, I would recommed using linq to xml here is an example http://social.msdn.microsoft.com/Forums/vstudio/en-US/e38e69ac-d325-4cc4-bdf7-bc940e19e63f/read-xml-and-create-objects-using-linq

Reading a template and creating a new XML file using the read template

I'm attempting to read a XML template, code below, and put this content to a new XML file.
<?xml version="1.0" encoding="utf-8"?>
<Format>
<Name title=""></Name>
<FormatA>
<Scheme name="A" set="number" get="integer">
<Sample set="number" get="integer">33</Sample>
</Scheme>
</FormatA>
<FormatX>
<Scheme name="A" set="number" get="integer">
<Sample set="number" get="integer">44</Sample>
</Scheme>
</FormatX>
</Format>
And will input values and write the title and a value for name. e.g When I enter "Counter" for the title and "Cnt" for the value. It will write
<Name title="Counter">Cnt</Name>
Basically, I'll just copy the contents of the template, put it in the new XML file with the inputted title and value.
Thank you for reading and who will answer my inquiry.
Did you tried string.Format?
Create the Template XML file with
Place Holders, like this {1}
Call
String.Format(XmlContent,"Counter","Cnt")
Hope it helps.

Categories

Resources