Home > Software engineering >  Dotnet - Filtering a FHIR Bundle by Resource.Effective
Dotnet - Filtering a FHIR Bundle by Resource.Effective

Time:12-03

I have been trying to perform a resource filtering by the 'Effective' attribute, but I seem to be running around in circles for the past hours and I am wondering if someone could give me a hand with this. The filtering method we have been using is the 'Select('query'), as shown below. (res is of type Bundle)

This works:

var selectedResource = res.Select("entry.resource.where(id = '" resourceId "')").FirstOrDefault();

This works:

var filteredResources = res.Select("entry.resource.ofType(" resourceType ")");

This doesn't work: (executed the below code on the QuickWatch)

Attempt #1

Description - Trying to compare with '2016-01-01' which is interpreted as string

res.Select("entry.resource.where(effective>='2016-01-01')"), results

"Invocation of operator '>=' failed: Cannot compare 2016-08-31T06:57:24-04:00 (of type Hl7.Fhir.ElementModel.Types.DateTime) to 2016-01-01 (of type Hl7.Fhir.ElementModel.Types.String), because the types differ."

Attempt #2

Description - Kept the quotes ( ' ' ) but changed the value inside to an actual DateTime initialization

res.Select("entry.resource.where(effective>='" new DateTime(2016,1,1) "')"), results

"Invocation of operator '>=' failed: Cannot compare 2016-08-31T06:57:24-04:00 (of type Hl7.Fhir.ElementModel.Types.DateTime) to 01/01/2016 00:00:00 (of type Hl7.Fhir.ElementModel.Types.String), because the types differ."

Attempt #3

Description - Previous one but without the quotes ( ' ' ) - Expected to be considered as string

res.Select("entry.resource.where(effective>=" new DateTime(2016,1,1) ")")

"Compilation failed: Parsing failure: unexpected '('; expected end of input (Line 1, Column 21); recently consumed: urce.where"

Does anyone have an idea on how to get this date comparison to work?

Please tell me if there is any further info I can provide to help you analyze the issue.

Thanks in advance!

Kind regards, AF

CodePudding user response:

This was answered in the discussion thread on the firely-net-sdk: https://github.com/FirelyTeam/firely-net-sdk/discussions/1924.

Quoting: DateTime literals begin with a @. See also the FhirPath specification: http://hl7.org/fhirpath/#datetime

So try to write te expression like this: res.Select("entry.resource.where(effective >= @2016-01-01)");

  • Related