The fhir.resources DateTime object is not spec compliant. The spec (and the doc comments) both require a +zz:zz or Z timezone suffix, it is using datetime.isoformat() which does not do this. Python isoformat() violates ISO8601 https://stackoverflow.com/a/23705687/1480205
We are trying to interoperate with a partner and they are unable to consume the FHIR JSON we generate since the DateTimes are all wrong. We think a workaround will be to correctly pre-format the datetime and use the str instead of the actual datetime object, it looks like to_string will leave it alone in that case.
Description
The fhir.resources
DateTime
object is not spec compliant. The spec (and the doc comments) both require a+zz:zz
orZ
timezone suffix, it is usingdatetime.isoformat()
which does not do this. Pythonisoformat()
violates ISO8601 https://stackoverflow.com/a/23705687/1480205See
DateTime.to_string
https://github.com/nazrulworld/fhir.resources/blob/main/fhir/resources/fhirtypes.py#L511We are trying to interoperate with a partner and they are unable to consume the FHIR JSON we generate since the DateTimes are all wrong. We think a workaround will be to correctly pre-format the
datetime
and use thestr
instead of the actualdatetime
object, it looks liketo_string
will leave it alone in that case.What I Did
All DateTimes in FHIR objects are of the form
2021-05-07T21:41:57.120530
This is not compliant with the doc comment or the spec https://www.hl7.org/fhir/datatypes.html#dateTime