Creating unit tests against a baseline XML can be difficult because of detail. What you can do in these cases is remove the stuff that doesn't matter, and enforce some rigor on other stuff in ways you control rather than your XML parser, transformer or generation infrastructure.
The stylesheet below is an example of just such a tool. If you run it over your CDA document, it will do a few things:
- Remove some content (such as the document id and effective time) which are usually unique and dynamically determined.
- Clean up ID attributes such that every ID attribute is numbered in document order in the format ID-1.
- Ensure that internal references to those ID attributes still point to the thing that they originally did.
This stylesheet uses the identity transformation with some little tweaks to "clean up" the things we don't care to compare. It's a pretty simple tool so I won't go into great detail about how to use it.
Keith
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cda="urn:hl7-org:v3">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match='@ID'>
<xsl:attribute name="ID">
<xsl:text>ID-</xsl:text>
<xsl:number count='//*[@ID]'/>
</xsl:attribute>
</xsl:template>
<xsl:template match='/cda:ClinicalDocument/cda:id|/cda:ClinicalDocument/cda:effectiveTime|/cda:ClinicalDocument/cda:*/cda:time'>
<xsl:copy>Ignored for Comparison</xsl:copy>
</xsl:template>
<xsl:template match="cda:reference/@value[starts-with(.,'#')]">
<xsl:attribute name="value">
<xsl:text>#ID-</xsl:text>
<xsl:value-of select='count(//*[@ID=substring-after(current(),"#")]/preceding::*/@ID)+1'/>
</xsl:attribute>
</xsl:template>
<xsl:template match='@ID' mode='count'>
<xsl:attribute name="ID">
<xsl:text>#ID-</xsl:text>
<xsl:number count='//*[@ID]'/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
0 comments:
Post a Comment