XML for SET<II> datatype
xmlcoder
#1 Posted : Thursday, December 8, 2011 4:01:24 AM(UTC)
Rank: Member

Groups: Registered
Joined: 12/7/2011(UTC)
Posts: 18
Points: 54

Thanks: 2 times
Was thanked: 0 time(s) in 0 post(s)
I am attempting to use a SET<II> datatype.

Code:

private SET<II> id;


I then add several Guid instances of II to the SET ( visible in the debug tool ).

when I serialise this to XML I use the following code, borrowed from the datatypes demo code :

Code:

        internal static void SerialiseDataType(IGraphable dataType, XmlWriter xmlWriter, string elementName)
        {
            if (dataType != null)
            {
                xmlWriter.WriteStartElement(elementName);

                Formatter fmtr = new Formatter();
                fmtr.GraphAides.Add(typeof(MARC.Everest.Formatters.XML.Datatypes.R1.Formatter));
                fmtr.GraphObject(xmlWriter, dataType);

                xmlWriter.WriteEndElement();
            }
        }


This yields

Code:

<id/>


i.e. an empty element

Where am I going wrong? Why is the element empty?
justin.fyfe1
#2 Posted : Thursday, December 8, 2011 10:09:11 AM(UTC)

Rank: Administration

Medals: Mobile Tech Grasshopper: Mobile Tech GrasshopperHealth Informatics MVP

Groups: Registered, Administrators
Joined: 7/22/2010(UTC)
Posts: 96
Points: 297
Man
Location: Hamilton, ON

Thanks: 2 times
Was thanked: 17 time(s) in 17 post(s)
Ah yes, this issue has to do with the fact that the built in XmlSerializer (ca. .NET 2.0) does not have the ability to get the name of the current element, so the SET formatter can't figure out what element should be repeated (well, there is a workaround for this but it wasn't very pretty). Unfortunately we discovered this "issue" after about 90% of the formatters were already written (and the issue only affects SET, LIST, BAG, etc...) so we didn't change the code.

The solution would be to use an XmlStateWriter. You can use the XmlStateWriter at the root of serialization, or just at the level that you want to start tracking (I'm using the latest build to illustrate formatting)

Code:

internal static void SerialiseDataType(IGraphable dataType, XmlWriter xmlWriter, string elementName)
        {
            if (dataType != null)
            {
                var stateWriter = new XmlStateWriter(xmlWriter);

                stateWriter.WriteStartElement(elementName);

                DatatypeFormatter fmtr = new DatatypeFormatter();
                fmtr.Graph(xmlWriter, dataType);

                stateWriter.WriteEndElement();
            }
        }



Of course, this means that any result details returned by the formatter will be relative to the start of the state writer (ie: if there is an error validating the SET or an II within the SET then the errors will be reported relative to the start of the state writer).

The other option is to wrap the XmlWriter at the root of serialization. The XML ITS1 formatter does this for the user transparently so most of the examples just pass instance of IGraphable to the ITS1 formatter, however the ITS1 formatter usually formats MessageType structures rather than DataType structures meaning that the XmlStateWriter created by the ITS1 formatter will have element context.

I also see that you're trying to just serialize data types, if this is the case you can increase performance by just using the Data Types R1 formatter directly (without using the primary formatter, which is intended for MessageTypes). This won't work if you have lists of non-data types though (ie: LIST<Person>, or SET<AssignedEntity>).

Additionally, if you're interested there is a UV.CDAr2 assembly in the latest snapshot of Everest which contains the message structures for the plain old ClinicalDocument type. If you're building vanilla CDA instnaces, you could construct an instance of this class and pass it to an XML ITS1 formatter.

Thanks for these questions by the way, they are great ideas for blog posts. I have a personal blog at http://fyfej.blogspot.com which has more in-depth converage of Everest 1.0 features. We're also working on a better developer's guide.
xmlcoder
#3 Posted : Thursday, December 8, 2011 1:03:55 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/7/2011(UTC)
Posts: 18
Points: 54

Thanks: 2 times
Was thanked: 0 time(s) in 0 post(s)
Thanks for the response, a wealth of detail :-)

Firstly. yes I am only trying serialise the datatypes so I will take a look and see if I can follow your suggestion. I had implemented a number of data types myself before I explored the Everest library. I am now migrating to Everest as there is so much richness in the assembly that I just has not catered for. It's going to be a real help.

Unfortunately I can't use the UV.CDAr2 assembly as the CDA I am using has a number of localisations ( that exist in a different namespace ) then the UV version. The product I am working on is to build a simplified API to create instances based on a profile of CDA developed for use within the UK. It's quite a simple CDA profile but should lower the barrier to entry for companies creating CDA documents.

When it is a bit more mature the code will be made open source. I'll post a link to the repository in this forum so people can see one way of delivering benefit from the great work you have done here.
justin.fyfe1
#4 Posted : Thursday, December 8, 2011 7:46:09 PM(UTC)

Rank: Administration

Medals: Mobile Tech Grasshopper: Mobile Tech GrasshopperHealth Informatics MVP

Groups: Registered, Administrators
Joined: 7/22/2010(UTC)
Posts: 96
Points: 297
Man
Location: Hamilton, ON

Thanks: 2 times
Was thanked: 17 time(s) in 17 post(s)
No problem.

If you require any assistance from our team please don't hesitate to post questions and ask for help. We're very supportive of our users and try to incorporate feedback into the framework.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

SoClean Theme By Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.112 seconds.