First thing that I wondered after hearing about FHIR is “What is a Healthcare Resource?” and very simple answer is available in FHIR specification (http://www.hl7.org/implement/standards/fhir/ ).
Second thing I wondered was “What does it look like?” and there are many examples available in FHIR specification. But as a beginner on FHIR I started comparing it with HL7 v2.x (on which I have implemented many projects) and this created some confusions.
I found FHIR concept a reall simple but it was difficult to understand implementation and real interoperability scenarios in RESTful environment without doing some hands on with test servers:
Connect with test servers available & feel the resources using (Covered in this post)
- Fiddler (http://www.fiddler2.com/fiddler2/ )
- Your own client in C#
- Using XmlHttpRequest
Implement a simple REST service with http GET and expose a healthcare resource (will cover this in my next post)
- Patient resource collection feed
I think after doing this, you will have fair idea about FHIR, healthcare resources and interoperability using FHIR.
Let’s start by connecting FHIR test serversNote: A detailed presentation with screenshots is available at http://www.slideshare.net/j4jayantsingh/fhir-feel-the-fire-1
http://wiki.hl7.org/index.php?title=Publicly_Available_FHIR_Servers_for_testing lists all the publically available test servers. In this post I will connect to Grahame's test server. You should try all the available. (Note that these servers are testing servers. They may be sporadically unavailable)
Connect Test Servers using FiddlerOpen Fiddler and compose a new resource request. As first step we will request a conformance resource to know how an application or implementation supports FHIR.
Compose this request: OPTIONS http://hl7connect.healthintersections.com.au/svc/fhir/
You can view the raw xml/json data in fiddler and explore the details of a resource.
Some other simple resource requests would be:
GET http://hl7connect.healthintersections.com.au/svc/fhir/patient to get Patient Resource Feed
GET http://hl7connect.healthintersections.com.au/svc/fhir/patient/@1 to get Patient id 1
GET http://hl7connect.healthintersections.com.au/svc/fhir/document to get Document Resource Feed
Let's try to find a resource which doesn’t exist on server
GET http://hl7connect.healthintersections.com.au/svc/fhir/document/@123456 this will return HTTP 404 Not Found
Connect test servers with your own client in C#Now, let’s create simple desktop client in C# which will work similar to fiddler, but writing a client on your own will provide you better understanding of FHIR & RESTFul approach.
In this client I will just provide a mechanism to call a RESTFul resource and display result in raw (xml/json) format. Once we have the data in xml/json we can parser it the way we want. This application uses a library called RestSharp.
Following is the code with comments to help you understand
//create a RestClient var client = new RestClient(); //Assign base url of RESTFul Server client.BaseUrl = "http://hl7connect.healthintersections.com.au/svc/fhir/"; //HTTP method(GET/POST etc) to use for this request Method method = (Method)Enum.Parse((typeof(Method)), cmbHttpOptions.Text); //Create RestRequest request = new RestRequest(method); //Add header "Accept" to request xml or json data format if(cmbContentType.Text.Equals("xml")) request.AddHeader("Accept", "application/xml"); //use text/xml+fhir else request.AddHeader("Accept", "application/json"); //use application/json //resource to query like patient, patient/@1, document etc. request.Resource = "patient/@1"; //Execute the request and get response IRestResponse response = client.Execute(request); //display the raw response header txtResult.Text = "************Response Header***********\n" for (int i = 0; i < response.Headers.Count; i++) txtResult.Text += response.Headers[i].Name + ": " + response.Headers[i].Value + "\n"; txtResult.Text += "StatusCode: " + response.StatusCode + "\n"; //display the raw response content txtResult.Text += "\n\n************Raw Content**********\n"; txtResult.Text += response.Content;
Please note: your might have to clear browser cache to view the effect of Content-Type(xml/json)
Please try playing around with more resource URIs and explore FHIR. Reference Implementation available with FHIR specification provides classes to parse this xml or json data received from FHIR test server.
In second part of this post I will provide a sample WCF REST service and expose a "Patient" resource, a GET on Patient resource will return Patient Resource Feed.
Comments:I appreciate honest (positive/negative) feedback.
|Ewout Kramer on 27th March 2013
use text/xml+fhir for the xml format of Resources, and application/json otherwise
Furthermore, once you start transferring atom feeds, we use application/atom+xml or application/json (so this last one is the same as for individual resources!)