FHIR Chat · String not recognized as valid DateTime · dotnet

Stream: dotnet

Topic: String not recognized as valid DateTime


view this post on Zulip Paul Watt (Jun 20 2018 at 06:29):

Has anyone come across this error when using the FhirClient to create or read (possible other actions but I haven't tested) on a remote server?
I am getting an exception of "String was not recognized as a valid DateTime." from the FhirClient but the create is successful on the fhir server.
Only occurs when accessing a remote server over https. Locally using http I'm not getting the error.

view this post on Zulip Michel Rutten (Jun 20 2018 at 19:03):

Hi @Paul Watt, I haven't seen this before. Could you provide an example of a rejected DateTime value?

view this post on Zulip Paul Watt (Jun 21 2018 at 03:12):

@Michel Rutten That's the thing - there is no DateTime value. I create a patient resource with no DateTime values and send as a create and the response from FhirClient throws this error but the resource is successfully added at the remote end. The response would only contain a meta.lastupdated such as "2018-06-20T06:22:08.27+00:00" .

view this post on Zulip Paul Watt (Jun 21 2018 at 09:17):

Looks like it is the server assigned meta.lastupdated that is throwing the error when the returned resource is initialized. I removed the lastupdated from the database and no longer get the error.
It's generated by this:

view this post on Zulip Paul Watt (Jun 21 2018 at 09:18):

fhir.FhirDateTime dt = new fhir.FhirDateTime(DateTime.Now);
meta.lastupdated = dt.ToDateTimeOffset();
Shouldn't this return the correct format?

view this post on Zulip Paul Watt (Jun 22 2018 at 00:55):

For anyone who gets this error from FhirClient - check your HTTP header Last-Modified format. The FhirClient was attempting to parse this and it wasn't in the expected format. That was the cause of the exception rather than than the resource itself.

view this post on Zulip Brian Postlethwaite (Jun 22 2018 at 18:28):

Might be a good idea if we can provide more detail in that exception to make that easier to detect.
Can you share where that is occurring so that it can be checked.

view this post on Zulip Paul Watt (Jun 25 2018 at 05:04):

I saw it when using FhirClient.Create() and FhirClient.Read() . It would throw this:

{System.FormatException: String was not recognized as a valid DateTime.
at Hl7.Fhir.Rest.TaskExtensions.WaitResultT

Probably from this:
if (!String.IsNullOrEmpty(response.Headers[HttpUtil.LASTMODIFIED]))
result.Response.LastModified = DateTimeOffset.Parse(response.Headers[HttpUtil.LASTMODIFIED]);

in Hl7.Fhir.Core/Rest/HttpToEntryExtensions.cs

view this post on Zulip Ewout Kramer (Jul 02 2018 at 11:43):

https://github.com/ewoutkramer/fhir-net-api/issues/631

view this post on Zulip Ewout Kramer (Jul 02 2018 at 11:43):

I'd enjoy a PR ;-)


Last updated: Apr 12 2022 at 19:14 UTC