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="http://hl7.org/fhir">
  <text>
    <status value="generated" />
    <div xmlns="http://www.w3.org/1999/xhtml"><p>Burns, George M, 117y</p></div>
  </text>
  <active value="true" />
  <details>
    <name>
      <use value="official" />
      <family value="Burns" />
      <given value="George" />
    </name>
    <gender>
      <system value="http://hl7.org/fhir/sid/v2-0001" />
      <code value="M" />
    </gender>
    <birthDate value="1896-01-20" />
    <deceased value="false" />
  </details>
  <provider>
    <type value="Organization" />
    <url value="../organisation/@1" />
  </provider>
</Patient>


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": "http://hl7.org/fhir/sid/v2-0001"
        },
        "code": {
          "value": "M"
        }
      },
      "birthDate": {
        "value": "1896-01-20"
      },
      "deceased": {
        "value": false
      }
    },
    "provider": {
      "type": {
        "value": "Organization"
      },
      "url": {
        "value": "../organisation/@1"
      }
    }
  }
}




No comments:

Post a Comment