Thursday, 7 February 2013

Serial Arsonist

Decided I need my own C# serialisers for FHIR, reference implementation is absolutely fine but I have some desire to build to dotNet 2.0 only... don't ask why, I just do.

So model driven code creation is the way to go.  As part of the FHIR release there are a set of technical artifacts for implementers which offer a massive leg up for those that wish to stick to completely model driven code generation.  Have a look at ecoredefinitions.xml it can be used as the basis for getting this done - I am told this is an internal source, however, it has one of the big benefits of having all of the datatypes and resources specified.

Basically, to achieve my ends, I have tackled this generation in three parts (as defined by FHIR spec)
  1. Primitives : basic datatypes that map to XSD types in a nice way (and a mapping to C# types)
  2. Complex/Other Types : constructed types based on primitives for common 
  3. Resources : the clinical/administrative data groups 
Using the detail available to it is possible to generate serialisable classes supporting both XML and JSON representations.  The benefit here is as the resource definitions move around a bit through ballot and new additions I am trying to make the code automatically keep current.

So after some playing about I have my very rudimentary serialisable classes for dotNet 2.0 build in C#.  Of course the first resource to put something into is 'Patient' and of course for this project it has to be Mr. Burns. XML and JSON formats below.

Next.....maybe see which resources are appropriate for my GP system mapping... and how well I can map the content....

Test Patient #1 XML
<Patient xmlns="">
    <status value="generated" />
    <div xmlns=""><p>Burns, George M, 117y</p></div>
  <active value="true" />
      <use value="official" />
      <family value="Burns" />
      <given value="George" />
      <system value="" />
      <code value="M" />
    <birthDate value="1896-01-20" />
    <deceased value="false" />
    <type value="Organization" />
    <url value="../organisation/@1" />

Test Patient #1 JSON
  "Patient": {
    "text": {
      "status": {
        "value": "generated"
      "div": {
        "value": "<div><p>Burns, George M, 117y</p></div>"
    "active": {
      "value": true
    "details": {
      "name": [
          "use": {
            "value": "official"
          "family": [
              "value": "Burns"
          "given": [
              "value": "George"
      "gender": {
        "system": {
          "value": ""
        "code": {
          "value": "M"
      "birthDate": {
        "value": "1896-01-20"
      "deceased": {
        "value": false
    "provider": {
      "type": {
        "value": "Organization"
      "url": {
        "value": "../organisation/@1"

No comments:

Post a Comment