AMOQR: Een Actueel Medicatieoverzicht in je portemonnee

Een actueel medicatieoverzicht (AMO) is essentieel voor goede zorg. Bij een opname in een ziekenhuis bijvoorbeeld wordt je gevraagd eerst een AMO op te halen bij je apotheek. Dan wordt, met een medewerker van de apotheek, gekeken of de medicijnen zoals die in het systeem van de apotheker staan, nog kloppen: of je alles nog slikt wat erop staat, misschien gestopt bent met “zo nodig” middelen, of wellicht ook nog iets bij de kruidenier om de hoek hebt gekocht en inneemt. Dat krijg je mee op een of twee A4’tjes. Handig, want zo weet de specialist precies wat je neemt. Alleen: die A4’tjes neem je alleen mee wanneer je ze nodig hebt. Is het niet veel makkelijker een AMO te hebben dat je altijd mee kunt nemen?

Open space

Pas was ik op de Open Space Werkconferentie Medicatieoverdracht. Een inspirerende middag in de mooie Janskerk in Utrecht.

Wie gedacht had een middagje rustig te kunnen gaan zitten luisteren had het mis. De dames van meeuwenroos hebben ons aan het werk gezet, en alsof dat niet genoeg was mochten we een opdracht aan onszelf op een gefrankeerde kaart zetten. Over een maand krijgen we die in onze eigen brievenbus om te zien wat we ervan terecht hebben gebracht. (Anne, Helen, Elline, bij deze: die van mij mogen jullie houden. Opdracht voltooid.)

Een van de ideeën in de groepen was dat ophalen en meenemen van die A4’tjes, of ophalen van medicatie uit het Landelijk Schakelpunt omslachtig is. Iedereen (die dat wil) moet gewoon een actueel medicatieoverzicht bij zich kunnen hebben. In de binnenzak. Altijd. Mobieltje, en apps, werd meteen geroepen. Nu ben ik daar als ICT’er helemaal voor, maar het kan ook laagdrempeliger. Op een visitekaartje. Ik had me voorgenomen uit te zoeken of dat met een QR code ook kan.

Een Actueel Medicatieoverzicht (AMO)

Wanneer je een AMO ophaalt bij je apotheek ziet dat er zo uit:

amo

Je patiëntgegevens staan erop, de apotheker met wie het besproken is wordt genoemd, evenals huidige en recent beëindigde medicatie, eventuele labwaarden (bijvoorbeeld bloedwaarden) en andere zaken die van belang kunnen zijn zoals allergieëen. Tot slot, belangrijk: wie er naar gekeken heeft. De praktijk wijst uit dat het medicatieoverzicht dat de apotheker in het syteem heeft staan vaak niet up to date is, en apothekers die ik sprak zeggen me dat gegevens uit het LSP veel te vaak ook niet volledig zijn. De patiënt zelf weet het beste wat zij of hij slikt (of soms de mantelzorger), dus die moet meekijken om tot een echt AMO met de A van Actueel te komen. (Zie de richtlijn medicatieoverdracht voor de details van het AMO.)

En nu de portemonnee in!

Dat A4’tje past niet zo makkelijk in de portemonnee. En dit overzicht afdrukken op het formaat van een bankpasje levert ook geen leesbaar document op. Een QR-code kan dat wellicht oplossen.

wwwmdg

Hoeveel gegevens passen er eigenlijk in een QR code? Er zijn meerdere formaten (“versions”) met aantal blokjes (“modules”) van 21×21 (version 1) tot 177×177 (version 40). Hoe meer blokjes, hoe meer informatie. Daar komen nog zaken als foutcorrectie en dergelijke bijdie de hoeveelheid informatie beïnvloeden. Een paar rekensommen. Een visitekaartje is 55 mm hoog. Om een QR code heen moet wat witruimte zitten, er blijft dus zo’n 5 centimeter over. Scannen hoeft niet van een billboard, maar kan van dichtbij, dus we kunnen rustig voor een lage foutcorrectie gaan. Dan moet daar een QR code version 27 van 125×125 blokjes met zo’n 2100 alfanumerieke tekens in passen.

Dat lijkt genoeg. Maar ik wil het ook in de praktijk proberen. Ik maak dus een medicatieoverzicht met de patiëntgegevens van mij, zes medicatieregels en één contra-indicatie. Met wat passen en meten worden het 1425 tekens. Alles conform de richtlijn medicatieoverdracht, alleen de layout pas ik wat aan. Die tabellen werken niet goed samen met QR codes, en de icoontjes die in het AMO zitten passen er ook niet in. Dit zijn twee van de zes regels (met fictieve medicatie, aan een glas rode wijn op zijn tijd heb ik voldoende):

-------------------
KENACORT A 40 INJECTIESUSPENSIE 40MG/ML FLACON 5ML
verstrekking
van 1-3-2016 tot 5-6-2016
afgeleverd tot 5-6-2016
1 maal per week 15 milliliter
Dr. Dokter,06010859
-------------------
TRUSOPT OOGDRUPPELS 20MG/ML FLACON 5ML
verstrekking
van 1-3-2016 tot ---
afgeleverd tot 1-6-2016
2 maal per dag 1 druppel
Dr. Dokter,06010859 
-------------------

Met een van de vele onlineapps maak ik een QR code van de 1425 tekens, en download die. Die print ik met mijn huis-tuin-en-keukenprinter op visitekaartformaat. Ik download een QR app op mijn Samsung S4 Mini. Het werkt prima: bij scannen van mijn AMO-visitekaartje staan de gegevens van “mijn” AMO er weer.

20160531_181105

Voor patiënten die erg veel medicatie nemen, of voor het opnemen van labuitslagen zal het printje iets groter worden dan een visitekaartje. Het maximum van een QR code is 4296 tekens, dat is driemaal zoveel informatie als in mijn AMO met patiëntgegevens, zes medicatieregels en één contra-indicatie. Dat zal in de meeste gevallen wel voldoende zijn.

Uiteraard is er niets meer geheim aan dit kaartje wanneer ik mijn portemonnee kwijtraak. Datzelfde geldt overigens voor het papieren AMO in mijn binnenzak. Maar medicatie in een app op de telefoon, die beter beveiligd is, heeft ook nadelen. Wanneer ik een ongeluk krijg, en niet meer aanspreekbaar ben, kan de ambulance of de SEH ook niet meer bij mijn medicatie. Uiteindelijk blijft het een keuze voor iedere burger of ze een AMO met alle informatie bij zich willen dragen of niet. Iemand die medische risico’s loopt, zal het eerder doen, anderen zullen de medische gegevens liever achter slot en grendel laten. Geen reden uiteraard deze keuze niet aan de burger zelf aan te bieden.

AMO everywhere!

Het is natuurlijk geen enkel probleem dit AMOQR af te drukken op het “gewone” AMO. Daar is voldoende ruimte voor. Even uitknippen en in de portemonnee. Afdrukken bij de apotheek op een kartonnen kaartje, of sealen in een plastic hoesje is natuurlijk nog mooier. Altijd het laatste AMO op zak. Welke apotheek komt als eerste met deze extra service voor de patiënt?

amo4

Update 9-6-2016: Vandaag een interessant gesprek gehad met Bart Luiken van 112QR. Ze hebben een vergelijkbare implementatie, i.s.m.  o.a. MS Fonds en Epilepsie Vereniging Nederland. Een kaartje op zak. Niet met een statische QR, maar een dynamische die op een veilige manier toegang geeft tot je kritische gegevens op een website. Geïnteresseerden kunnen daar ook eens kijken naar de mogelijkheden.

3D Printing Myself – or: Do we have a Free Will?

I intend to read two books on free will soon, Samuel Harris’ ‘Free Will’ (which argues that free will is an illusion) and Julian Baggini’s ‘Freedom Regained’ (which argues free will is possible). Before reading those two (on which I will get back here), I wanted to pen down my own ideas on free will, to see whether reading the books will make me change my own views. The problem of free will has bothered me since I studied philosophy (or possibly before), since it seems to lead to either inconsistencies or world views which I find very implausible.

Free will – the idea that we choose our actions voluntarily, based on our own judgment, and that we could have chosen otherwise if we wanted – presupposes the idea of choice: that what we have done in the past could have been otherwise, and our future is not given by the circumstances, but a least partially decided by our own choices. So the question: do we have a free will is dependent on another question: do we have a choice at all. A thought experiment will help to highlight the essence of the problem.

Imagine a perfect 3D printer, capable of copying dead matter as well as living beings. If I were to copy myself, Marc-the-copy would be a perfect copy of Marc-the-original. Marc-the-copy would contain the same molecules, in the same places, the same strands of DNA, the same RNA, the same blood cells, intestinal lining and brain. The same neurons, intertwined in the same way, with the same amounts of neurotransmitter in the same spots, connected with the same axons to the same nerves. If there is still an idea of an ‘original’ and a ‘copy’, where the copy would not be ‘the same’, since there is only one original, we could assume that the original’s molecules would be split evenly amongst both copies, and that the 3D printer would supply each of both copies with the missing molecules, according to the blueprint – the now-gone original.

Next, assume that the 3D printer would print both Marc-copies to identical rooms, again perfect copies of each other. The same table with some coffee and some sandwiches, the same vase of identical roses underneath the same copy of a Vermeer’s Milkmaid. The same bright lightning, the same anonymous waiting room music on the same radio.

Now, what would both copies do? Would they do the same thing or not? Would both pick the ham sandwich, or might one go for ham and the other for tuna? Is it possible that one would skip the sandwiches and go straight for coffee, while the other would have a sandwich first and a coffee later? Could one tune the radio to Adele’s ‘Someone like you’, while the other copy would prefer Chopin’s Nocturnes? And, if you go for the same choice, would both copies do the same thing always? Again and again and again, as long as the environment is exactly the same? So basically: given the exact same material make-up of both individual and environment, would it be possible to have different outcomes when the individual is faced with a choice, or is the outcome of the choice always determined? This is not about determinism ‘light’, where we are bound by our genes and circumstances to be obese, or smart et cetera. That would still allow both copies to sometimes make different choices. This thought experiment is about a very strong determinism: is different action possible at all for both copies?

Let’s go down the possible scenarios, and see the repercussions of each scenario on the possibility of free will.

They would do the same.

That is, always the same. The world we’ve chosen is completely deterministic, at least where human choices are involved. All choices are contained in the material circumstances, and given those, the outcomes are fixed.

This view has some paradoxical consequences. The things we do often seem to make sense. If I want to drive to Paris, and I don’t know the way by heart, I will follow the road signs (or my navigation system nowadays). So if I’m near Brussels, and I see a sign ‘Paris’ with an arrow to an exit on my right hand, I will most likely take that exit. Now, in a deterministic universe, the road signs wouldn’t matter. I would take the right exit anyway, regardless of what the signs say, since my driving choices are predetermined. So whether the sign would point to the left exit for Paris or the right wouldn’t matter. Nothing said or written would matter at all, it seems. I do like to read a novel in the evening, and if the story is good, it gives me a sense of satisfaction. Now, in a deterministic universe, I could read a random collection of letters, a totally nonsensical whole of arbitrary non-words, and still have the same sense of satisfaction if the material circumstances dictated such.
Of course the two universes – one with the sign Paris to the right, and the other to the left, aren’t exactly the same, since at least the paint on both signs is applied differently. The point is this difference cannot explain my taking the right exit. The connection ‘sign to the right’ – ‘taking the right exit’ does only make sense if we suppose that I see the sign, read it, and make a decision based on that information – a decision which could have been otherwise. But exactly this free decision is impossible in a deterministic universe, since there is no choice. So we cannot say things sense because signs to the right trigger human decisions to go to the right, since humans cannot make such decisions.

So why does it all make sense? What are the possible answers to that in a deterministic universe?

It doesn’t make sense

This idea of sense is all an illusion. The road signs don’t influence where I go, nor does the novel I read induce my sense of happiness. That is all an illusion. In fact, many road signs do point to the left while I go right, and what I read is garbage (not in the sense of literary criticism, but in the sense that I do really read random collections of meaningless signs). In a deterministic universe we don’t need consistency between signs and actions, and there is in fact none.

This world view is maybe consistent in itself, but not very consistent with experience. We do feel we take the right exit because of the sign, and we enjoy the novel because of the content. So this view has some explaining left to do, and is very counterintuitive. And it needs explaining why we have the illusion of consistency.

It cannot not make sense

For some reason, a deterministic universe where road signs to Paris would point to the left, while people heading to Paris go right is not possible.
Of course such an observation is very intuitive. It seems most logical that if road signs point to the right, we would go right. But this only an explanation when we do have some degree of choice. It presumes we go right because we see the road sign, and decide to go right. Without that decision, what could possible cause the coherence between road signs and directions taken? If we do not have choices, the road sign to the right could not be the cause of our choice of taking the right exit.
So our choosing so cannot be the explanation of correspondence between signs and actions in a deterministic universe. Let’s see what could be, and what determines the outcomes of our actions.

Matter decides the outcomes

Matter (on a macroscopic level anyway) decides what happen, or at least our actions. Given a powerful enough computer, all our action could be calculated in advance. (Of course we needn’t assume a Newtonian universe. Matter may behave according to the quantum-mechanical uncertainty principle, but this doesn’t influence human behavior. It was only the choice of the two copies which was deterministic in our thought experiment, not necessarily the entire universe.)

But if it is matter that decides the deterministic outcomes of our choices, it is nearly impossible to see why things make sense. We must assume some law of nature which excludes nonsensical combinations, i.e. road signs to Paris to the left and cars heading for Paris going to the right. And this must be the weirdest kind of law possible, different from all laws of nature that we know.

Something else decides the outcomes

You may believe that it is not matter which decides the outcomes, but something else. An omnipotent god, or a universal non-material principle. This is more consistent. It all makes sense because god, (or the universal principle) has decided that things should make sense.

So in this universe we have no free will. Thus universe does make sense. Something (god, a non-material principle) makes it make sense. And this something also decides everything we do, the outcome of all our apparent choices. This universe is still somewhat counterintuitive since we do feel we make the choice to take the right exit ourselves, but this idea of freedom of choice may be an illusion. There are more known illusions of a similar nature. Assuming a god or principle doesn’t explain much: the question goes from ‘why does it all make sense’ to ‘why does a god make it make sense’ – but the world view is consistent in itself.

They would not do the same.

Now if we assume both copies of Marc would not (always) do the same thing, what could cause the difference in behavior?

Something material

We’ve already assumed the copies are the same, as are the rooms they’re in. So where could a material cause for different choices come from?

Something outside the individual

Maybe one could say that both copies are influenced by the universe at large, and they can’t both occupy the same space in that universe. This is a bit tweaking with the assumptions of the argument, which stated that both copies would have the same environment. And of course one can say that that simply is not possible. Still, if something material outside the copies would decide the difference in outcome, then this would be a deterministic universe. Each of the copies could not make another choice, since the outcomes are determined by something material outside. So saying ‘something outside’ makes the choices differ, still doesn’t really allow choice. We’re back at the deterministic world view, only the room has become larger.

Chance events

Maybe our brains are wired in such a way that they contain ‘quantum-mechanical coins’. In each of the two copies, the coins are flipped and one may land heads up, while the other goes for tails. The differences are pure chance. No influence of the individual.

This is a nondeterministic universe, albeit with only random ‘freedom’. There is no pre-determination, but also no real choice – just chance events. Things could have been otherwise, but only through random events. And randomness still doesn’t explain choice. If we flip a coin which decides whether we go right (heads up) or left (tails) and the coin lands heads up, we can say we’ve chosen to flip a coin, but we would never say we’ve chosen to go right. So the quantum-mechanical coin in our heads could explain variation in behavior, but we couldn’t really call it choice. It might explain why things appear to make sense – it the road signs say ‘Turn right for Paris’, our mental make-up might be so that the coin is much, much more likely to flip so that we do turn right.

Non-chance events

This seems hard to imagine. Both copies are the same, materially spoken. They don’t make the same choices. This difference is caused by something material. And this material cause is not a chance event, no throw of the dice.
It’s hard to imagine how pure matter (since in this universe, nothing but matter decides the difference in choice between Marc A. and Marc B.) could lead to any but random differences. Apparently in this universe, matter has some properties which are nondeterministic, but not chance either. It seems this universe assumes some hitherto undetected properties of matter. This is of course not impossible, but not very plausible too. We simply would assume some ‘choice’ of ‘free will’ property of matter itself, to explain our free will.

Something immaterial

Another assumption, if both copies of Marc do not make the same choice, is that the difference in behavior is caused by something nonmaterial.

Something immaterial in the individual

We can assume we have a (nonmaterial) mind, or a soul, or immaterial ‘spirit’. This spirit can make choices, and this causes the different outcomes for both copies of Marc. But how does this spirit influence the matter? This is basically Descartes’ problem. There is nothing in the material theories we have which allows such an interaction between an immaterial spirit and our material body. Somewhere there would need to be a connection, where the immaterial can trigger the material. This is not logically impossible, but still, given what we know, it’s hard to fathom where and how this would happen.

Something immaterial outside the individual.

If a god, or something else immaterial decides the different outcomes, the individual is apparently not free to choose. So, like the case where ‘outside matter’ decides the different outcomes, in this case there is no real choice either, since it is coming from outside. Once the ‘outside’ has made up its mind, there is no possibility for the individual to choose anything other than that what already had been decided outside. Taking a god as the cause of different actions of the two Marc copies does raise the same question as the spirit: where does this god interact with matter? (Note that a deterministic universe does not have this problem: a god could have created this universe from the start so that all outcomes are decided in advance, and wouldn’t need to interact with it after creation.)

Other solutions

We’re not smart enough

Maybe language, and human thought, is not capable of understanding the very concepts we are researching. Maybe ‘free will’ is simply not a consistent concept, and we cannot reason with it in the same way as we can with concepts such as cars, forces of nature, road signs or sandwiches.

An open question is why there is a universe at all – why isn’t there just nothing? I haven’t read any satisfactory answers to this question. The answers fall in two categories. The first assumes something else, god or a law of nature, which needs explaining as well – why is there a god instead of nothing, why is there a law of nature at all? The second does not assume something else, but doesn’t really move beyond the big bang. I believe it is possible that the concept of ‘nothing’ may just not make sense enough to reason with it. We never perceive ‘nothing’, only the absence of other stuff – no light, no people, no planets. But it is not a given that a combination of absences leads to a ‘nothing’ with which we can reason as if it were something. So maybe ‘nothing’ just isn’t a coherent enough concept, and the question ‘why isn’t here nothing’ just doesn’t make sense like ‘why isn’t there coffee’ because ‘nothing’ is not as coherent a concept as ‘coffee’.

In the same way, ‘free will’ may be a concept that’s not coherent enough to allow the kind of reasoning I’ve done with it in this paper. So instead of getting an answer, we must conclude that the question was wrong all the time. I do like this answer, but I have no proof of it either. There is no ‘grand theory’ explaining which concepts can be reasoned with, and which ones cannot. So saying ‘free will’ is an inconsistent concept does amount to assuming something to make the problem go away.

Yet other solutions

There might simply be more than we know. I’ve contrasted ‘material’ versus ‘immaterial’ stuff and more, but there may be more than we know of. I’ve touched upon the possibility of properties of matter yet unknown, and there may simply be stuff (material or not) constituting the universe that we do not know of yet. So maybe there is a free will, in a sensible way, be we still need to discover how or what makes it possible.

(Not a) conclusion

So far, for me, there is no satisfactory conclusion in the free will debate. A deterministic universe, were a god (or universal principle) has planned everything in advance, a has taken care that the world we live in appears to be a sensible one, is – at least – internally consistent.

So is a universe where we do have choice, but the choices are just random events. That’s not enough to constitute what we would normally call ‘free will’, but maybe that’s just how it is. There needn’t be a free will just because we think it’s nice if there is.

A universe with real choices, either chosen by our nonmaterial spirit, or a god, needs to explain how this nonmaterial thing interacts with matter ‘on the go’ – i.e. not from the start of the universe, but to allow for real choices once the material conditions are given. What we know of physics doesn’t offer any real possibilities here – but our knowledge of physics might be incomplete here.

And the question could be wrong because the concept of ‘free will’ is not consistent – but why would it, and how could we decide which concepts are consistent and which ones not?

Code Generation Strategies for ART DECOR

Last time I wrote about code generation using ART DECOR. This time we’ll look a some more code generation, and then consider various strategies for code generation.

In the previous post we saw how to generate HTML for a user interface for a transaction in ART DECOR. We can do the same for database code.

SQL

    --DROP TABLE vs_measured_by CASCADE;
    CREATE TABLE vs_measured_by (
        vs_measured_by_id int NOT NULL PRIMARY KEY,
        code varchar(255) NOT NULL,
        codeSystem varchar(255) NOT NULL,
        displayName varchar(255) NOT NULL
        );
        
    INSERT INTO vs_measured_by (vs_measured_by_id, code, codeSystem, displayName)
    VALUES (1, 'P', '2.16.840.1.113883.3.1937.99.62.3.5.1', 'Patient');
        
    INSERT INTO vs_measured_by (vs_measured_by_id, code, codeSystem, displayName)
    VALUES (2, 'T', '2.16.840.1.113883.3.1937.99.62.3.5.1', 'Home care provider');
        
    INSERT INTO vs_measured_by (vs_measured_by_id, code, codeSystem, displayName)
    VALUES (3, 'H', '2.16.840.1.113883.3.1937.99.62.3.5.1', 'GP');
        
    INSERT INTO vs_measured_by (vs_measured_by_id, code, codeSystem, displayName)
    VALUES (4, 'M', '2.16.840.1.113883.3.1937.99.62.3.5.1', 'Personal network');
        
    --DROP TABLE measurement_message CASCADE;
    CREATE TABLE measurement_message (
          measurement_message_id int NOT NULL PRIMARY KEY
        );
        
    --DROP TABLE measurement CASCADE;
    CREATE TABLE measurement (
          measurement_id int NOT NULL PRIMARY KEY
        , measurement_message_id int NOT NULL  REFERENCES measurement_message(measurement_message_id)
        , weight float
        , weight_unit char(96) NOT NULL
        , weight_gain boolean
        , length float
        , length_unit char(96)
        , datetime timestamp
        , measured_by int REFERENCES vs_measured_by(vs_measured_by_id)
        , comments varchar(255)        
    );
    
    --DROP TABLE weight_gain_data CASCADE;
    CREATE TABLE weight_gain_data (
          weight_gain_data_id int NOT NULL PRIMARY KEY
        , measurement_id int NOT NULL REFERENCES measurement(measurement_id)
        , size_weight_gain float
        , size_weight_gain_unit char(96)
        , cause_weight_gain varchar(255)        
    );
    
    --DROP TABLE person CASCADE;
    CREATE TABLE person (
          person_id int NOT NULL PRIMARY KEY
        , measurement_message_id int NOT NULL  REFERENCES measurement_message(measurement_message_id)
        , name varchar(255) NOT NULL
        , bsn varchar(255) NOT NULL
        , date_of_birth varchar(255)
        , number_of_children varchar(255)        
    );

XSL

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0" >
    
    <xsl:output method="text" indent="no"/>
    
    <xsl:template match="/">
        <xsl:apply-templates select="//valueSet"/>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:template>
    
    <xsl:template match="dataset">
    --DROP TABLE <xsl:value-of select="@shortName"/> CASCADE;
    CREATE TABLE <xsl:value-of select="@shortName"/> (
          <xsl:value-of select="@shortName"/>_id int NOT NULL PRIMARY KEY
        );
        <xsl:apply-templates/>        
    </xsl:template>

    <xsl:template match="concept[@type='group']">
    --DROP TABLE <xsl:value-of select="implementation/@shortName"/> CASCADE;
    CREATE TABLE <xsl:value-of select="implementation/@shortName"/> (
          <xsl:value-of select="implementation/@shortName"/>_id int NOT NULL PRIMARY KEY
        <xsl:if test="local-name(..) = 'dataset'">, <xsl:value-of select="../@shortName"/>_id int NOT NULL  REFERENCES <xsl:value-of select="../@shortName"/>(<xsl:value-of select="../@shortName"/>_id)</xsl:if>
        <xsl:if test="local-name(..) = 'concept'">, <xsl:value-of select="../implementation/@shortName"/>_id int NOT NULL REFERENCES <xsl:value-of select="../implementation/@shortName"/>(<xsl:value-of select="../implementation/@shortName"/>_id)</xsl:if>
        <xsl:apply-templates select="concept[@type='item']"/>        
    );
    <xsl:apply-templates  select="concept[@type='group']"/>        
    </xsl:template>

    <xsl:template match="concept[@type='item']">
        , <xsl:value-of select="implementation/@shortName"/>
        <xsl:choose>
            <xsl:when test="valueDomain/@type='code'"> int REFERENCES <xsl:value-of select="translate(valueSet/@name, '-', '_')"/>(<xsl:value-of select="translate(valueSet/@name, '-', '_')"/>_id)</xsl:when>
            <xsl:when test="valueDomain/@type='boolean'"> boolean</xsl:when>
            <xsl:when test="valueDomain/@type='decimal'"> float</xsl:when>
            <xsl:when test="valueDomain/@type='datetime'"> timestamp</xsl:when>
            <xsl:when test="valueDomain/@type='quantity'"> float
        , <xsl:value-of select="implementation/@shortName"/>_unit char(96)</xsl:when>
            <xsl:otherwise> varchar(255)</xsl:otherwise>
        </xsl:choose>
        <xsl:if test="@isMandatory='true'"> NOT NULL</xsl:if>
    </xsl:template>

    <xsl:template match="valueSet">
    --DROP TABLE <xsl:value-of select="translate(@name, '-', '_')"/> CASCADE;
    CREATE TABLE <xsl:value-of select="translate(@name, '-', '_')"/> (
        <xsl:value-of select="translate(@name, '-', '_')"/>_id int NOT NULL PRIMARY KEY,
        code varchar(255) NOT NULL,
        codeSystem varchar(255) NOT NULL,
        displayName varchar(255) NOT NULL
        );
        <xsl:for-each select="conceptList/concept">
    INSERT INTO <xsl:value-of select="translate(../../@name, '-', '_')"/> (<xsl:value-of select="translate(../../@name, '-', '_')"/>_id, code, codeSystem, displayName)
    VALUES (<xsl:value-of select="@localId"/>, '<xsl:value-of select="@code"/>', '<xsl:value-of select="@codeSystem"/>', '<xsl:value-of select="name"/>');
        </xsl:for-each>
    </xsl:template>

    <xsl:template match="@*|node()">
        <xsl:apply-templates select="@*|node()"/>
    </xsl:template>
</xsl:stylesheet>

XML

<dataset id="2.16.840.1.113883.3.1937.99.62.3.1.1" effectiveDate="2012-05-30T11:32:36" statusCode="draft" versionLabel="" transactionId="2.16.840.1.113883.3.1937.99.62.3.4.2" transactionEffectiveDate="2012-09-05T16:59:35" shortName="measurement_message"><!--
 This is a view of the transaction view of Measurement message containing DECOR specifications for a transaction or dataset in a single, hierarchical view. 
 All inheritances are resolved, for transactions the dataset is filtered for those concepts occurring in the transaction.
 Valuesets are contained within the concept for easy reference. 
 Xpaths are calculated on a best effort basis. The should be considered a starting point for application logic, not an endpoint. -->
    <name language="en-US">Measurement message</name>
    <desc language="en-US">Measurement message test</desc>
    <concept minimumMultiplicity="0" maximumMultiplicity="*" isMandatory="false" id="2.16.840.1.113883.3.1937.99.62.3.2.1" statusCode="cancelled" effectiveDate="2012-05-30T11:32:36" type="group">
        <name language="en-US">Measurement</name>
        <desc language="en-US">Measurement of body weight on a specific date</desc>
        <implementation shortName="measurement">
            <templateLocation></templateLocation>
        </implementation>
        <concept minimumMultiplicity="1" maximumMultiplicity="1" conformance="M" isMandatory="true" id="2.16.840.1.113883.3.1937.99.62.3.2.3" statusCode="cancelled" effectiveDate="2011-01-28T00:00:00" type="item">
            <name language="en-US">Weight</name>
            <desc language="en-US">Weight measurement</desc>
            <implementation shortName="weight">
                <templateLocation></templateLocation>
            </implementation>
            <valueDomain type="quantity">
                <property unit="kg" minInclude="25" maxInclude="240"></property>
            </valueDomain>
            <terminologyAssociation conceptId="2.16.840.1.113883.3.1937.99.62.3.2.3" code="27113001" codeSystem="2.16.840.1.113883.6.96" displayName="Body weight"></terminologyAssociation>
        </concept>
        <concept minimumMultiplicity="0" maximumMultiplicity="1" isMandatory="false" id="2.16.840.1.113883.3.1937.99.62.3.2.13" statusCode="cancelled" effectiveDate="2011-01-28T00:00:00" type="item">
            <name language="en-US">Weight gain</name>
            <desc language="en-US">Is there a weight gain?</desc>
            <implementation shortName="weight_gain">
                <templateLocation></templateLocation>
            </implementation>
            <valueDomain type="boolean"></valueDomain>
        </concept>
        <concept minimumMultiplicity="0" maximumMultiplicity="1" conformance="C" isMandatory="false" id="2.16.840.1.113883.3.1937.99.62.3.2.18" statusCode="cancelled" effectiveDate="2011-01-28T00:00:00" type="group">
            <name language="en-US">Weight gain data</name>
            <desc language="en-US">Weight gain data</desc>
            <implementation shortName="weight_gain_data">
                <templateLocation></templateLocation>
            </implementation>
            <condition minimumMultiplicity="1" maximumMultiplicity="1" conformance="M" isMandatory="true">Bij gewichtstoename</condition>
            <condition minimumMultiplicity="" maximumMultiplicity="" conformance="NP" isMandatory=""></condition>
            <concept minimumMultiplicity="0" maximumMultiplicity="1" isMandatory="false" id="2.16.840.1.113883.3.1937.99.62.3.2.19" statusCode="cancelled" effectiveDate="2011-01-28T00:00:00" type="item">
                <name language="en-US">Size weight gain</name>
                <desc language="en-US"></desc>
                <implementation shortName="size_weight_gain">
                    <templateLocation></templateLocation>
                </implementation>
                <valueDomain type="quantity">
                    <property unit="gram"></property>
                </valueDomain>
            </concept>
            <concept minimumMultiplicity="0" maximumMultiplicity="1" isMandatory="false" id="2.16.840.1.113883.3.1937.99.62.3.2.20" statusCode="cancelled" effectiveDate="2011-01-28T00:00:00" type="item">
                <name language="en-US">Cause weight gain</name>
                <desc language="en-US"></desc>
                <implementation shortName="cause_weight_gain">
                    <templateLocation></templateLocation>
                </implementation>
                <valueDomain type="string"></valueDomain>
            </concept>
        </concept>
        <concept minimumMultiplicity="0" maximumMultiplicity="1" isMandatory="false" id="2.16.840.1.113883.3.1937.99.62.3.2.15" statusCode="cancelled" effectiveDate="2011-01-28T00:00:00" type="item">
            <name language="en-US">Length</name>
            <desc language="en-US">Body length</desc>
            <implementation shortName="length">
                <templateLocation></templateLocation>
            </implementation>
            <valueDomain type="quantity">
                <property unit="m" minInclude="0" maxInclude="3" fractionDigits="2"></property>
                <property unit="cm" minInclude="0" maxInclude="300" fractionDigits="0!"></property>
            </valueDomain>
        </concept>
        <concept minimumMultiplicity="0" maximumMultiplicity="1" isMandatory="false" id="2.16.840.1.113883.3.1937.99.62.3.2.2" statusCode="cancelled" effectiveDate="2011-01-28T00:00:00" type="item">
            <name language="en-US">Datetime</name>
            <desc language="en-US">Date of the measurement</desc>
            <implementation shortName="datetime">
                <templateLocation></templateLocation>
            </implementation>
            <valueDomain type="datetime"></valueDomain>
            <terminologyAssociation conceptId="2.16.840.1.113883.3.1937.99.62.3.2.2" code="DM" codeSystem="2.16.840.1.113883.3.1937.99.62.3.5.2" displayName="Datum meting"></terminologyAssociation>
        </concept>
        <concept minimumMultiplicity="0" maximumMultiplicity="1" isMandatory="false" id="2.16.840.1.113883.3.1937.99.62.3.2.5" statusCode="cancelled" effectiveDate="2011-01-28T00:00:00" type="item">
            <name language="en-US">Measured by</name>
            <desc language="en-US">Person who performed the measurement</desc>
            <implementation shortName="measured_by">
                <templateLocation></templateLocation>
            </implementation>
            <valueDomain type="code">
                <conceptList id="2.16.840.1.113883.3.1937.99.62.3.2.5.0">
                    <concept id="2.16.840.1.113883.3.1937.99.62.3.2.5.1">
                        <name language="en-US">Patient</name>
                    </concept>
                    <concept id="2.16.840.1.113883.3.1937.99.62.3.2.5.2">
                        <name language="en-US">Home care provider</name>
                    </concept>
                    <concept id="2.16.840.1.113883.3.1937.99.62.3.2.5.3">
                        <name language="en-US">GP</name>
                    </concept>
                    <concept id="2.16.840.1.113883.3.1937.99.62.3.2.5.4">
                        <name language="en-US">Personal network</name>
                    </concept>
                </conceptList>
            </valueDomain>
            <valueSet id="2.16.840.1.113883.3.1937.99.62.3.11.5" effectiveDate="2012-07-25T15:22:56" name="demo1-meting-door" displayName="demo1-meting-door" statusCode="draft">
                <terminologyAssociation conceptId="2.16.840.1.113883.3.1937.99.62.3.2.5.0" valueSet="demo1-meting-door"></terminologyAssociation>
                <conceptList id="2.16.840.1.113883.3.1937.99.62.3.2.5.0">
                    <concept localId="1" code="P" codeSystem="2.16.840.1.113883.3.1937.99.62.3.5.1" displayName="Patiënt" level="0" type="A">
                        <name language="en-US">Patient</name>
                    </concept>
                    <concept localId="2" code="T" codeSystem="2.16.840.1.113883.3.1937.99.62.3.5.1" displayName="Thuiszorg" level="0" type="S">
                        <name language="en-US">Home care provider</name>
                    </concept>
                    <concept localId="3" code="H" codeSystem="2.16.840.1.113883.3.1937.99.62.3.5.1" displayName="Huisarts" level="0" type="D">
                        <name language="en-US">GP</name>
                    </concept>
                    <concept localId="4" code="M" codeSystem="2.16.840.1.113883.3.1937.99.62.3.5.1" displayName="Family care" level="0" type="L">
                        <name language="en-US">Personal network</name>
                    </concept>
                </conceptList>
            </valueSet>
            <terminologyAssociation conceptId="2.16.840.1.113883.3.1937.99.62.3.2.5" code="MD" codeSystem="2.16.840.1.113883.3.1937.99.62.3.5.2" displayName="Meting door"></terminologyAssociation>
        </concept>
        <concept minimumMultiplicity="0" maximumMultiplicity="*" isMandatory="false" id="2.16.840.1.113883.3.1937.99.62.3.2.17" statusCode="cancelled" effectiveDate="2012-09-09T16:06:28" type="item">
            <name language="en-US">Comments</name>
            <desc language="en-US"></desc>
            <implementation shortName="comments">
                <templateLocation></templateLocation>
            </implementation>
            <valueDomain type="text"></valueDomain>
        </concept>
    </concept>
    <concept minimumMultiplicity="1" maximumMultiplicity="1" conformance="M" isMandatory="true" id="2.16.840.1.113883.3.1937.99.62.3.2.6" statusCode="draft" effectiveDate="2012-05-30T14:18:23" type="group">
        <name language="en-US">Person</name>
        <desc language="en-US">Person</desc>
        <implementation shortName="person">
            <templateLocation></templateLocation>
        </implementation>
        <concept minimumMultiplicity="1" maximumMultiplicity="1" conformance="M" isMandatory="true" id="2.16.840.1.113883.3.1937.99.62.3.2.4" statusCode="draft" effectiveDate="2012-05-30T14:18:23" type="item">
            <name language="en-US">Name</name>
            <desc language="en-US">Name of the person</desc>
            <implementation shortName="name">
                <templateLocation></templateLocation>
            </implementation>
            <valueDomain type="complex"></valueDomain>
        </concept>
        <concept minimumMultiplicity="1" maximumMultiplicity="1" conformance="M" isMandatory="true" id="2.16.840.1.113883.3.1937.99.62.3.2.7" statusCode="draft" effectiveDate="2012-05-30T14:18:23" type="item">
            <name language="en-US">BSN</name>
            <desc language="en-US">Dutch Social Security Number</desc>
            <implementation shortName="bsn">
                <templateLocation></templateLocation>
            </implementation>
            <valueDomain type="identifier"></valueDomain>
        </concept>
        <concept minimumMultiplicity="0" maximumMultiplicity="1" isMandatory="false" id="2.16.840.1.113883.3.1937.99.62.3.2.8" statusCode="draft" effectiveDate="2012-05-30T14:18:23" type="item">
            <name language="en-US">Date of birth</name>
            <desc language="en-US">Date of birth of the person</desc>
            <implementation shortName="date_of_birth">
                <templateLocation></templateLocation>
            </implementation>
            <valueDomain type="date"></valueDomain>
        </concept>
        <concept minimumMultiplicity="0" maximumMultiplicity="1" isMandatory="false" id="2.16.840.1.113883.3.1937.99.62.3.2.14" statusCode="deprecated" effectiveDate="2012-05-30T14:18:23" type="item">
            <name language="en-US">Number of children</name>
            <desc language="en-US">Number of children</desc>
            <implementation shortName="number_of_children">
                <templateLocation></templateLocation>
            </implementation>
            <valueDomain type="count"></valueDomain>
        </concept>
    </concept>
</dataset>

Like in the HTML generation, the XSLT used to generate the code operates on the output of RetrieveTransaction, and is rather small itself. And, like before, this is not a complete code generator yet: not all datatypes are included etc., so only use this as the start for your own code generators. This generated SQL (tested on PostgreSQL) implements the following database model:

 ada-codegen-dbEach concept group becomes a table, value sets (vs-measured-by) get their own table, which is populated by the rows in the value set.

vs-table

If we hook up some middleware, which can be pretty generic, the middleware, the HTML UI and the database would be a complete application.

Some caveats for real-world usage:

  1. It’s probably better to derive the SQL datatypes from the HL7v3 datatypes in RetrieveTransaction (only possible when HL7v3 is the target, and specs are complete). For more information on generating SQL from HL7v3 datatypes, see RIMBAA_MGRID_HL7v3_Datatypes.pdf for a thorough approach.
  2. Value sets here get their own table. Another approach is to have one table for all value sets, with extra columns for value set name or id. Take care: the approach I’ve chosen uses artificial primary keys in de value set table (with values 1, 2, 3…). This works well for a single version, but what’s constant over several versions of a message is the combination of code and codeSystem. So if you follow my approach, make sure to keep the primary keys constant over time.
  3. I simply generated a separate table for each concept group. It’s easy to improve over that approach: groups which are 0..1 or 1..1 do not need their own table. Basically, the generated database is split in more tables than necessary.

The next question is what the best strategies for code generation along the lines I’ve sketched are. Of course it’s possible to generate an entire application, but that would be suboptimal. ART DECOR (usually, not necessarily) models interchange, so messaging between applications, and not static information models. The requirements for a database are as a rule not covered by interchange models. So while this approach is possible, it would probably need an augmented underlying model.

A better approach is to use code generation as a messaging layer between your own application and the outside world. Parse incoming messages and store them in temporary tables. RetrieveTransaction already contains XPath expressions which point to the right locations in the incoming XML (not 100% complete though, so use as a starting point). Then populate your own DB from the temporary tables, and empty the latter.

strategy-1

This is a very flexible model: when there is a new version of the messaging standard, simply re-generate the insulating layer with generated tables. This will enable you to read new messages without too much ado. The conversion to the proprietary DB will need some updating, of course: there is a new version of the message, so things will have changed. Still, the prorietary DB will be insulated from many changes to the messaging format itself, and the logic which needs updating will be minimized.

Another strategy is to use code generation to generate form parts which do not have corresponding fields in your own database. Such a strategy would involve:

  • generate an HTML form from RetrieveTransaction;
  • prepopulate the form with all the data which already is in your own database;
  • present the form to the user (embedded within your own application);
  • have the user complete the information which is not in your database;
  • generate a message, and send it.

This strategy corresponds well to cases where for instance generic patient data are already in your database, but additional information is needed for some report which needs to be sent. Again, if a new version of the report and message is coming along, this approach ensures only minimal changes to the underlying logic.

Code generation is already used in many projects in the Netherlands, both to generate UI and database logic, as well as for data extraction. All in all, ART DECOR provides all the tools needed to leverage your applications with code generation, and thus implement exchanges in a quick and robust fashion.

Mijn medisch dossier is van mij! Of toch niet?

Je hoort het met enige regelmaat. “Het is eigenlijk heel simpel: het dossier van een patiënt is eigendom van die patiënt! En niet van anderen, zoals de zorgverlener.” Maar zo eenvoudig is het niet.

Om te beginnen bestaat er in Nederland geen “eigendom” van intellectuele gegevens. Op het fysieke dossier kan wel eigendomsrecht rusten, maar in deze tijd van digitale dossiers is dat vrij betekenisloos geworden. Een digitaal dossier is dus niemands juridische eigendom. (Zie ook: ‘Van wie is het dossier’, Anton Ekker, Nictiz 2010.) Er is hoogstens sprake van auteursrecht, maar daarop wordt bij medische dossiers zelden of nooit een beroep gedaan. Prima, zal de tegenwerping zijn, misschien klopt dat in technische zin wel, maar dat is juridische haarkloverij. Moreel gezien is er maar één iemand eigenaar van het dossier, en dat is de patiënt! Maar nee, ook dat klopt niet.

Neem een simpel voorbeeld. Mijn arts schrijft mij een recept uit voor 30 keer 75 mg Nortrilen. Dat recept maakt deel uit van mijn medisch dossier. Maar mag ik nu naar eigen inzicht dat recept wijzigen, en die 30 veranderen in 300? De Wet op de Geneesmiddelenvoorziening stelt dat een recept door een arts ondertekend moet zijn. Wat ik dus ook zelf aanpas in een dossier, een recept is het daarna niet meer. Zo zal een arts ook niet willen dat ik in “mijn” dossier de diagnose obstipatie aanpas wanneer ik vermoed dat er toch wel wat ernstigers dan dat aan de hand zal zijn. (Wanneer een patiënt het niet eens is met een diagnose, heeft deze wel het recht een eigen verklaring aan het dossier toe te laten voegen.) En wanneer ik een bloedwaarde in een laboratoriumuitslag aanpas, is dat geen laboratoriumuitslag meer, maar gewoon een kladje waarin ik zelf wat gerommeld heb. Wat is dat nog voor “eigenaarschap”, wanneer ik de gegevens niet aan mag passen?

Zelfs het (laten) verwijderen van gegevens uit mijn dossier mag niet altijd. Meestal heb ik dat recht wel, maar niet als een aanmerkelijk belang van een derde zich daartegen verzet. Zo’n  belang kan bijvoorbeeld de arts zelf hebben. Wanneer ik een klacht over de arts indien bij een tuchtcollege, kan de arts zijn dossier nodig hebben om zich te verdedigen, en hoeft het zolang de zaak loopt, niet te vernietigen wanneer ik daarom vraag.

Kortom, ik heb het recht niet “mijn” dossier naar eigen inzicht te wijzigen, en onder omstandigheden kan ik het zelfs niet verwijderen. Wat voor een eigendom is dat? De feitelijke situatie is natuurlijk anders. Juridisch is er geen sprake van eigendomsrechten, en in lossere zin is het eigendom gedeeld:  de zorgverlener heeft het deels geschreven, en de medische inhoud is de verantwoordelijkheid van de zorgverlener.

Uiteraard kan ik prima spreken over “mijn medisch dossier”, maar dan in de zin van “over mij”, niet “van mij”. De essentie van “mijn dossier” is dan ook ten eerste dat ik mag bepalen wat ermee gebeurt: wie het in mag zien, wat er uit verwijderd wordt (met een klein voorbehoud om anderen te beschermen), en uiteraard: dat ik er zelf bij mag! Niet een beetje, niet een deel, maar helemaal. Dat is in Nederland in de praktijk nog niet altijd goed geregeld. Daarover een andere keer meer.

Using ART DECOR for Code Generation

ART DECOR is a framework for capturing medical information requirements, mostly for the exchange of data in healthcare. In a short series of articles we will explore the benefits ART DECOR offers for implementers. (See the ART DECOR Factsheet for a short general introduction, or art-decor.org for detailed documentation on ART DECOR.) ART DECOR captures the data needs of healthcare professionals and patients in datasets and scenarios. ART DECOR does not only help healthcare professionals and IT architects to model medical data, it also offers a wealth of goodies for implementers, some easier to find than others.

Take a look at one of our demos, Measurements by Patient. This page, the ProjectIndex gives access to most resources available for developers. Look for instance at the Vital Sign Result valueset from the Vital Signs Demo. It’s also available in XML and CSV, for easier importing into an application. But let’s look further, to the main transaction from the first demo, the Measurement Message. Most of the data needed for an application is in there: field names, data types, code lists, cardinality, help text (description). This data is also available as XML, and this is an ideal hook for code generation. This XML version of RetrieveTransaction contains even more in the <implementation> element, which contains an XML- or SQL-friendly name (shortName), as well as the HL7 datatype. RetrieveTransaction gathers all data from the dataset, transaction and valueSets, and combines those into a single view.

RT

There’s also detailed documentation for RetrieveTransaction. RetrieveTransaction thus contains almost everything that’s needed for code generation. In the example below, I’ve made a basic HTML code generator. This is just an example, if you wish to use is for real code generation, you will need to adapt it – only some datatypes are supported, the submit action doesn’t actually do anything etc. Later we’ll look at a more full-fledged code generator.

ToHtml

What is done here is just a simple XSL conversion from the RetrieveTransaction output to a HTML page. The XML tab contains the RetrieveTransaction output, the XSL tab the stylesheet which is the actual code generator, and the HTML tab the generated code. The Result tab shows the rendered HTML (it is a .png, since the HTML doesn’t render well in WordPress – here is the HTML Result page as HTML).

Result

Result

HTML

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Measurement message</title>
   </head>
   <body>
      <h1>Measurement message</h1>
      <form name="editor" action="save" method="post">
         <table style="border-style: solid; border-width: 1px;">
            <tbody>
               <tr>
                  <td>
                     <table name="measurement" style="border-style: solid; border-width: 1px;">
                        <tbody>
                           <tr>
                              <h2>Measurement</h2>
                           </tr>
                           <tr>
                              <td>Weight: </td>
                              <td><input name="weight" type="number" step="0.01">kg</td>
                           </tr>
                           <tr>
                              <td>Weight gain: </td>
                              <td><input name="weight_gain" type="checkbox"></td>
                           </tr>
                           <tr>
                              <td>
                                 <table name="weight_gain_data" style="border-style: solid; border-width: 1px;">
                                    <tbody>
                                       <tr>
                                          <h2>Weight gain data</h2>
                                       </tr>
                                       <tr>
                                          <td>Size weight gain: </td>
                                          <td><input name="size_weight_gain" type="number" step="0.01">gram</td>
                                       </tr>
                                       <tr>
                                          <td>Cause weight gain: </td>
                                          <td><input name="cause_weight_gain" type="text"></td>
                                       </tr>
                                    </tbody>
                                 </table>
                              </td>
                           </tr>
                           <tr>
                              <td>Length: </td>
                              <td><input name="length" type="number" step="0.01">m</td>
                           </tr>
                           <tr>
                              <td>Datetime: </td>
                              <td><input name="datetime" type="datetime-local"></td>
                           </tr>
                           <tr>
                              <td>Measured by: </td>
                              <td><select>
                                    <option value="1">Patient</option>
                                    <option value="2">Home care provider</option>
                                    <option value="3">GP</option>
                                    <option value="4">Personal network</option></select></td>
                           </tr>
                           <tr>
                              <td>Comments: </td>
                              <td><input name="comments" type="text"></td>
                           </tr>
                        </tbody>
                     </table>
                  </td>
               </tr>
               <tr>
                  <td>
                     <table name="person" style="border-style: solid; border-width: 1px;">
                        <tbody>
                           <tr>
                              <h2>Person</h2>
                           </tr>
                           <tr>
                              <td>Name: </td>
                              <td><input name="name" type="text"></td>
                           </tr>
                           <tr>
                              <td>BSN: </td>
                              <td><input name="bsn" type="text"></td>
                           </tr>
                           <tr>
                              <td>Date of birth: </td>
                              <td><input name="date_of_birth" type="text"></td>
                           </tr>
                           <tr>
                              <td>Number of children: </td>
                              <td><input name="number_of_children" type="text"></td>
                           </tr>
                        </tbody>
                     </table>
                  </td>
               </tr>
            </tbody>
         </table><input type="submit" value="Save"></form>
   </body>
</html>

XSL

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0">

    <xsl:output method="html" indent="yes"/>

    <xsl:template match="dataset">
        <html>
            <head>
                <title>
                    <xsl:value-of select="name"/>
                </title>
            </head>
            <body>
                <h1>
                    <xsl:value-of select="name"/>
                </h1>
                <form name="editor" action="save" method="post">
                    <table style="border-style: solid; border-width: 1px;">
                        <tbody>
                            <xsl:apply-templates/>
                        </tbody>
                    </table>
                    <input type="submit" value="Save"/>
                </form>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="concept[@type='group']">
        <tr>
            <td>
                <table name="{implementation/@shortName}" style="border-style: solid; border-width: 1px;">
                    <tbody>
                        <tr>
                            <h2>
                                <xsl:value-of select="name"/>
                            </h2>
                        </tr>
                        <xsl:apply-templates/>
                    </tbody>
                </table>
            </td>
        </tr>
    </xsl:template>

    <xsl:template match="concept[@type='item']">
        <tr>
            <td><xsl:value-of select="name"/>: </td>
            <td>
                <xsl:if test="valueDomain/@type!='code'">
                    <input name="{implementation/@shortName}">
                    <xsl:choose>
                        <xsl:when test="valueDomain/@type='boolean'"><xsl:attribute name="type">checkbox</xsl:attribute></xsl:when>
                        <xsl:when test="valueDomain/@type='decimal'"><xsl:attribute name="type">number</xsl:attribute></xsl:when>
                        <xsl:when test="valueDomain/@type='datetime'"><xsl:attribute name="type">datetime-local</xsl:attribute></xsl:when>
                        <xsl:when test="valueDomain/@type='quantity'"><xsl:attribute name="type">number</xsl:attribute><xsl:attribute name="step">0.01</xsl:attribute> <xsl:value-of select="valueDomain/property[1]/@unit"/></xsl:when>
                        <xsl:otherwise><xsl:attribute name="type">text</xsl:attribute></xsl:otherwise>
                    </xsl:choose>
                    </input>
                </xsl:if>
                <xsl:if test="valueDomain/@type='code'">
                    <select>
                        <xsl:for-each select="valueDomain/conceptList/concept">
                            <option value="{tokenize(@id, '\.')[last()]}"><xsl:value-of select="name[1]"/></option>
                        </xsl:for-each>
                    </select>
                </xsl:if>
            </td>
        </tr>
    </xsl:template>

    <xsl:template match="@*|node()">
        <xsl:apply-templates select="@*|node()"/>
    </xsl:template>
</xsl:stylesheet>

XML

<dataset id="2.16.840.1.113883.3.1937.99.62.3.1.1" effectiveDate="2012-05-30T11:32:36" statusCode="draft" versionLabel="" transactionId="2.16.840.1.113883.3.1937.99.62.3.4.2" transactionEffectiveDate="2012-09-05T16:59:35" shortName="measurement_message"><!--
 This is a view of the transaction view of Measurement message containing DECOR specifications for a transaction or dataset in a single, hierarchical view. 
 All inheritances are resolved, for transactions the dataset is filtered for those concepts occurring in the transaction.
 Valuesets are contained within the concept for easy reference. 
 Xpaths are calculated on a best effort basis. The should be considered a starting point for application logic, not an endpoint. -->
    <name language="en-US">Measurement message</name>
    <desc language="en-US">Measurement message test</desc>
    <concept minimumMultiplicity="0" maximumMultiplicity="*" isMandatory="false" id="2.16.840.1.113883.3.1937.99.62.3.2.1" statusCode="cancelled" effectiveDate="2012-05-30T11:32:36" type="group">
        <name language="en-US">Measurement</name>
        <desc language="en-US">Measurement of body weight on a specific date</desc>
        <implementation shortName="measurement">
            <templateLocation></templateLocation>
        </implementation>
        <concept minimumMultiplicity="1" maximumMultiplicity="1" conformance="M" isMandatory="true" id="2.16.840.1.113883.3.1937.99.62.3.2.3" statusCode="cancelled" effectiveDate="2011-01-28T00:00:00" type="item">
            <name language="en-US">Weight</name>
            <desc language="en-US">Weight measurement</desc>
            <implementation shortName="weight">
                <templateLocation></templateLocation>
            </implementation>
            <valueDomain type="quantity">
                <property unit="kg" minInclude="25" maxInclude="240"></property>
            </valueDomain>
            <terminologyAssociation conceptId="2.16.840.1.113883.3.1937.99.62.3.2.3" code="27113001" codeSystem="2.16.840.1.113883.6.96" displayName="Body weight"></terminologyAssociation>
        </concept>
        <concept minimumMultiplicity="0" maximumMultiplicity="1" isMandatory="false" id="2.16.840.1.113883.3.1937.99.62.3.2.13" statusCode="cancelled" effectiveDate="2011-01-28T00:00:00" type="item">
            <name language="en-US">Weight gain</name>
            <desc language="en-US">Is there a weight gain?</desc>
            <implementation shortName="weight_gain">
                <templateLocation></templateLocation>
            </implementation>
            <valueDomain type="boolean"></valueDomain>
        </concept>
        <concept minimumMultiplicity="0" maximumMultiplicity="1" conformance="C" isMandatory="false" id="2.16.840.1.113883.3.1937.99.62.3.2.18" statusCode="cancelled" effectiveDate="2011-01-28T00:00:00" type="group">
            <name language="en-US">Weight gain data</name>
            <desc language="en-US">Weight gain data</desc>
            <implementation shortName="weight_gain_data">
                <templateLocation></templateLocation>
            </implementation>
            <condition minimumMultiplicity="1" maximumMultiplicity="1" conformance="M" isMandatory="true">Bij gewichtstoename</condition>
            <condition minimumMultiplicity="" maximumMultiplicity="" conformance="NP" isMandatory=""></condition>
            <concept minimumMultiplicity="0" maximumMultiplicity="1" isMandatory="false" id="2.16.840.1.113883.3.1937.99.62.3.2.19" statusCode="cancelled" effectiveDate="2011-01-28T00:00:00" type="item">
                <name language="en-US">Size weight gain</name>
                <desc language="en-US"></desc>
                <implementation shortName="size_weight_gain">
                    <templateLocation></templateLocation>
                </implementation>
                <valueDomain type="quantity">
                    <property unit="gram"></property>
                </valueDomain>
            </concept>
            <concept minimumMultiplicity="0" maximumMultiplicity="1" isMandatory="false" id="2.16.840.1.113883.3.1937.99.62.3.2.20" statusCode="cancelled" effectiveDate="2011-01-28T00:00:00" type="item">
                <name language="en-US">Cause weight gain</name>
                <desc language="en-US"></desc>
                <implementation shortName="cause_weight_gain">
                    <templateLocation></templateLocation>
                </implementation>
                <valueDomain type="string"></valueDomain>
            </concept>
        </concept>
        <concept minimumMultiplicity="0" maximumMultiplicity="1" isMandatory="false" id="2.16.840.1.113883.3.1937.99.62.3.2.15" statusCode="cancelled" effectiveDate="2011-01-28T00:00:00" type="item">
            <name language="en-US">Length</name>
            <desc language="en-US">Body length</desc>
            <implementation shortName="length">
                <templateLocation></templateLocation>
            </implementation>
            <valueDomain type="quantity">
                <property unit="m" minInclude="0" maxInclude="3" fractionDigits="2"></property>
                <property unit="cm" minInclude="0" maxInclude="300" fractionDigits="0!"></property>
            </valueDomain>
        </concept>
        <concept minimumMultiplicity="0" maximumMultiplicity="1" isMandatory="false" id="2.16.840.1.113883.3.1937.99.62.3.2.2" statusCode="cancelled" effectiveDate="2011-01-28T00:00:00" type="item">
            <name language="en-US">Datetime</name>
            <desc language="en-US">Date of the measurement</desc>
            <implementation shortName="datetime">
                <templateLocation></templateLocation>
            </implementation>
            <valueDomain type="datetime"></valueDomain>
            <terminologyAssociation conceptId="2.16.840.1.113883.3.1937.99.62.3.2.2" code="DM" codeSystem="2.16.840.1.113883.3.1937.99.62.3.5.2" displayName="Datum meting"></terminologyAssociation>
        </concept>
        <concept minimumMultiplicity="0" maximumMultiplicity="1" isMandatory="false" id="2.16.840.1.113883.3.1937.99.62.3.2.5" statusCode="cancelled" effectiveDate="2011-01-28T00:00:00" type="item">
            <name language="en-US">Measured by</name>
            <desc language="en-US">Person who performed the measurement</desc>
            <implementation shortName="measured_by">
                <templateLocation></templateLocation>
            </implementation>
            <valueDomain type="code">
                <conceptList id="2.16.840.1.113883.3.1937.99.62.3.2.5.0">
                    <concept id="2.16.840.1.113883.3.1937.99.62.3.2.5.1">
                        <name language="en-US">Patient</name>
                    </concept>
                    <concept id="2.16.840.1.113883.3.1937.99.62.3.2.5.2">
                        <name language="en-US">Home care provider</name>
                    </concept>
                    <concept id="2.16.840.1.113883.3.1937.99.62.3.2.5.3">
                        <name language="en-US">GP</name>
                    </concept>
                    <concept id="2.16.840.1.113883.3.1937.99.62.3.2.5.4">
                        <name language="en-US">Personal network</name>
                    </concept>
                </conceptList>
            </valueDomain>
            <valueSet id="2.16.840.1.113883.3.1937.99.62.3.11.5" effectiveDate="2012-07-25T15:22:56" name="demo1-meting-door" displayName="demo1-meting-door" statusCode="draft">
                <terminologyAssociation conceptId="2.16.840.1.113883.3.1937.99.62.3.2.5.0" valueSet="demo1-meting-door"></terminologyAssociation>
                <conceptList id="2.16.840.1.113883.3.1937.99.62.3.2.5.0">
                    <concept localId="1" code="P" codeSystem="2.16.840.1.113883.3.1937.99.62.3.5.1" displayName="Patiënt" level="0" type="A">
                        <name language="en-US">Patient</name>
                    </concept>
                    <concept localId="2" code="T" codeSystem="2.16.840.1.113883.3.1937.99.62.3.5.1" displayName="Thuiszorg" level="0" type="S">
                        <name language="en-US">Home care provider</name>
                    </concept>
                    <concept localId="3" code="H" codeSystem="2.16.840.1.113883.3.1937.99.62.3.5.1" displayName="Huisarts" level="0" type="D">
                        <name language="en-US">GP</name>
                    </concept>
                    <concept localId="4" code="M" codeSystem="2.16.840.1.113883.3.1937.99.62.3.5.1" displayName="Family care" level="0" type="L">
                        <name language="en-US">Personal network</name>
                    </concept>
                </conceptList>
            </valueSet>
            <terminologyAssociation conceptId="2.16.840.1.113883.3.1937.99.62.3.2.5" code="MD" codeSystem="2.16.840.1.113883.3.1937.99.62.3.5.2" displayName="Meting door"></terminologyAssociation>
        </concept>
        <concept minimumMultiplicity="0" maximumMultiplicity="*" isMandatory="false" id="2.16.840.1.113883.3.1937.99.62.3.2.17" statusCode="cancelled" effectiveDate="2012-09-09T16:06:28" type="item">
            <name language="en-US">Comments</name>
            <desc language="en-US"></desc>
            <implementation shortName="comments">
                <templateLocation></templateLocation>
            </implementation>
            <valueDomain type="text"></valueDomain>
        </concept>
    </concept>
    <concept minimumMultiplicity="1" maximumMultiplicity="1" conformance="M" isMandatory="true" id="2.16.840.1.113883.3.1937.99.62.3.2.6" statusCode="draft" effectiveDate="2012-05-30T14:18:23" type="group">
        <name language="en-US">Person</name>
        <desc language="en-US">Person</desc>
        <implementation shortName="person">
            <templateLocation></templateLocation>
        </implementation>
        <concept minimumMultiplicity="1" maximumMultiplicity="1" conformance="M" isMandatory="true" id="2.16.840.1.113883.3.1937.99.62.3.2.4" statusCode="draft" effectiveDate="2012-05-30T14:18:23" type="item">
            <name language="en-US">Name</name>
            <desc language="en-US">Name of the person</desc>
            <implementation shortName="name">
                <templateLocation></templateLocation>
            </implementation>
            <valueDomain type="complex"></valueDomain>
        </concept>
        <concept minimumMultiplicity="1" maximumMultiplicity="1" conformance="M" isMandatory="true" id="2.16.840.1.113883.3.1937.99.62.3.2.7" statusCode="draft" effectiveDate="2012-05-30T14:18:23" type="item">
            <name language="en-US">BSN</name>
            <desc language="en-US">Dutch Social Security Number</desc>
            <implementation shortName="bsn">
                <templateLocation></templateLocation>
            </implementation>
            <valueDomain type="identifier"></valueDomain>
        </concept>
        <concept minimumMultiplicity="0" maximumMultiplicity="1" isMandatory="false" id="2.16.840.1.113883.3.1937.99.62.3.2.8" statusCode="draft" effectiveDate="2012-05-30T14:18:23" type="item">
            <name language="en-US">Date of birth</name>
            <desc language="en-US">Date of birth of the person</desc>
            <implementation shortName="date_of_birth">
                <templateLocation></templateLocation>
            </implementation>
            <valueDomain type="date"></valueDomain>
        </concept>
        <concept minimumMultiplicity="0" maximumMultiplicity="1" isMandatory="false" id="2.16.840.1.113883.3.1937.99.62.3.2.14" statusCode="deprecated" effectiveDate="2012-05-30T14:18:23" type="item">
            <name language="en-US">Number of children</name>
            <desc language="en-US">Number of children</desc>
            <implementation shortName="number_of_children">
                <templateLocation></templateLocation>
            </implementation>
            <valueDomain type="count"></valueDomain>
        </concept>
    </concept>
</dataset>

As you can see, the actual XSLT to generate the HTML code is pretty small. A real HTML generator would need some more, but still needn’t be large. For a larger example, here is the generated HTML for the epSOS Patient Summary (due to IP issues, some Snomed codes are not included, so corresponding drop-downs will be empty).

In the second installment of this short series, we’ll take a further look at strategies for code generation with ART DECOR.