We are implementing the backend for a FHIR server and it is unclear how certain Date searches should be implemented. The FHIR documentation itself is very clear. The semantics and handling of Date, DateTime and Time types are clearly if somewhat complicated. We were surprised to find that the STU3 Search Parameter Definitions only contain searches of type Date but that’s OK, we can add new Definitions where we require more precision. The source of the confusion is that one of standard definitions, AllergyIntolerance.last-date is defined as “Date(/time) of last known occurrence of a reaction” but has a type of Date. Looking at the FHIR resource I find AllergyIntolerance.lastOccurance is of type dateTime.
Is the blanket application of the Date type to all calendar Search Parameter Definitions an error? I assume that the only way to determine the correct type of search to employ is to examine the type of the resource property being compared. Is this correct?
It is correct. The search parameter type is ‘date’ which specifies the format of the search parameter. We use the same format for the search parameter irrespective of the precision of the underlying element (what you are concerned with) because the format is the same, and because the precision of the search parameter does not have to match the precision of the underlying element (though you can insist that it does so to some degree or other if you think that’s necessary). Note that most servers do not implement different search functionality for dates and date/times, and don’t worry about the difference
Defining an element as date(/time) with a type of date - that’s an error (which I see is fixed in the draft of R4.
Thanks, that helps a lot. If I understand correctly then where I need a query with a DateTime parameter I should create a new Search Parameter Definition that specifies a DateTime as the type.
In theory, it seems it would not hurt to change existing Search Parameters Definitions from Date to DateTime where needed as this does not preclude the use of a Date or Partial Date. Would this be in the spirit of the specs?