Retrieving all Observations for a patient

1,190 views
Skip to first unread message

Kunal Patel

unread,
May 19, 2016, 11:15:29 AM5/19/16
to FHIR DOTNET
Hello,

This question really has two part to it.
  1. How to retrieve Observations for a patient
  2. How to retrieve Observations for a patient taken at a particular time or within a 'range' of time.
I'm a newbie trying to experiment with Spark Server and the .NET API. Any help is appreciated. TIA.

Dan-Mihai Patrascu

unread,
May 20, 2016, 9:51:43 AM5/20/16
to FHIR DOTNET
Hi,
I've tried this only in the Epic sandbox, but it should work for Spark also:

private FhirClient client { get; set; }
 
       
/// <summary>
       
/// Initialize FHIR Client
       
/// </summary>
       
/// <param name="uri">Ex. "http://fhir.com/svc/fhir"</param>
       
public PatientResource(string uri)
       
{
            client
= new FhirClient(new Uri(uri));
            client
.UseFormatParam = true;
            client
.PreferredFormat = ResourceFormat.Json;
       
}
 
       
/// <summary>
       
/// Retrieves all Observations for the specified patient
       
/// </summary>
       
/// <param name="patientId">filter</param>
       
/// <param name="code">filter</param>
       
/// <returns>Bundle</returns>
       
public Bundle SearchObservation(string patientId, string code)
       
{
           
var query = new string[] { string.Format("patient={0}", patientId), string.Format("code={0}", code) };
           
var bundle = client.Search<Observation>(query);
 
           
return bundle;
       
}

You can add the date filter exactly as the code filter;

Mirjam Baltus

unread,
May 20, 2016, 10:51:59 AM5/20/16
to FHIR DOTNET
Yes, that should work for Spark as well, although I note that your search asks for a code in addition to just the patient id, which is not necessary for a search on Spark.

You could also use SearchParams instead of building a search string:

var q = new SearchParams();
q.Add("subject", "example");
Bundle result = client.Search<Observation>(q);

If you don't have the technical id, but only have the Patient's name or business identifier, you could use a chained parameter:
q.Add("subject.name", "peter");
or
q.Add("subject.identifier", "1234567");



Kunal Patel

unread,
May 23, 2016, 8:59:34 AM5/23/16
to FHIR DOTNET
Thank you very much Dan!

Do all the FHIR server have their own 'code' for various vitals signs? For e.g. if I wanted to search for a Heart Rate for a patient on an Epic server, would that query also work if I changed the FhirClient Uri to point to Spark server?

Kunal Patel

unread,
May 23, 2016, 9:05:52 AM5/23/16
to FHIR DOTNET
Thank you very much Mirjam! Your suggestion simplifies it further.

How can I get all the 'latest' set of vitals for the patient? Is there any simpler way to do it rather than just put a range of dates in the query?

Mirjam Baltus

unread,
May 24, 2016, 7:16:41 AM5/24/16
to FHIR DOTNET
Hi Kunal,
to get the latest set of vitals, you could add the _lastUpdated parameter to your search.
From the search page of the specs:

The search parameter _lastUpdated can be used to select resources based on the last time they were changed:
GET [base]/Observation?_lastUpdated=>2010-10-01
You will also be able to find other examples of valid searches on that page (in REST syntax, so no .Net code examples).

My answer to your other question would be: the servers don't determine the codes used for the vital signs. That is up to business rules. When two parties use the same rules, they will have the same codes in their resources, but other parties may well choose to use other codes. I think the only thing the FHIR specs say about this, is that LOINC codes are recommended.

Kunal Patel

unread,
May 25, 2016, 10:39:53 AM5/25/16
to FHIR DOTNET
Hi Mirjam,

Thank you for your reply.

I was looking at how to do it using Fhir-net-api, but I ended up doing following, please correct me if I'm doing it wrong.

SearchParams param = new SearchParams().Add( "subject.name", "van" ).Add( "_lastUpdated", "gt2016-01-07" ).Add( "_lastUpdated", "lt2016-04-21" );

var result = m_client.Search<Patient>(  );

It worked. When changed the FhirClient to pint to Epic Server, it returns nothing even when searched with subject.name as 'James' (which is one the patient available on the Epic Server)

Also, if the patient is on continuous monitoring i.e. say a Pulse oximeter sending out Heart Rate and SpO2 every second or so, and having more than one observation for the patient within an hour. With above _lastUpdated parameter I will really have lots of Observations returned to me or I'll have to store the time of last observation that I had fetched, which is bit awkward for a stateless protocol. Would be keen to learn any other workaround(s) that you know of?

Mirjam Baltus

unread,
May 30, 2016, 8:00:27 AM5/30/16
to FHIR DOTNET
I think you should change your search to 

var result = m_client.Search<Observation>( param );

That way you search the Observations instead of the Patients and use the params object to constrain your search.

For the Epic server you should check their specification. Just like they do not let you search Patients with the 'name' parameter, I could imagine they restrict chained parameters like 'subject.name' as well. If that is the case, perhaps you will need multiple searches: one to get the Patient id based on the Patients given and family names, and one where you use that id to search for the Observations linked to that patient.

The _lastUpdated parameter is of type date, which means you can use this format to specify it: yyyy-mm-ddThh:mm:ss[Z|(+|-)hh:mm] (the standard XML format). So yes, if you could store the last time you performed the search, you can specify a more precise date/time later on.
The only other thing I can think of to limit the number of Observations, is to add the _sort:desc parameter to sort based on _lastUpdated date, plus perhaps use _count to limit the number of Observations returned. NB: you will miss out on some of the results, but from your comments my interpretation is that you do not need the complete set of Observations.

If you need more complex search functionality, for example to get back 1 Observation for every hourly period, you will have to implement a named query on the server side (only possible if you have control over the server yourself, so not on Spark or Epic sandbox), or perform multiple searches client side.


Brian Postlethwaite

unread,
Jun 22, 2016, 11:48:02 PM6/22/16
to FHIR DOTNET
I know it's a little late, and it might have been covered in one of the other threads, but the Epic server doesn't support just Name, it requires you to provide given and family (and maybe birthdate, but not sure here)
Reply all
Reply to author
Forward
0 new messages