Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instant on DocumentReference not properly output on json #145

Open
richard-keebler opened this issue Nov 17, 2023 · 1 comment
Open

Instant on DocumentReference not properly output on json #145

richard-keebler opened this issue Nov 17, 2023 · 1 comment

Comments

@richard-keebler
Copy link

  • fhir.resources version: v5
  • Python version: 3.11
  • Operating System: macos

Description

When loading a document reference from a json representation that originally came from a DocumentReference, it fails on validating the date. Below is a contrived example, but the json we're getting (and loading) is from a fhir repository that delivers and accepts json representations.

What I Did

d = DocumentReference(
  id="test",
  status=Code('unknown'),
  content=[DocumentReferenceContent(id="testc", attachment=Attachment(contentType=Code("text/plain"), data="hi"))],
  date=Instant(year=2023, day=8, month=8, hour=8, minute=8, second=8)
)

j = d.json()

item = json.loads(j)

dd = DocumentReference(**item) <-- this throws error invalid datetime format (type=value_error.datetime)

There is a hacky fix here. Just add a Z to the end of the date string representation and the problem is solved, i.e. item['date'] + "Z". I would expect though, that the string representation would already have that.

@janwijbrand
Copy link

Ah, you ran into this issue more or less simultaneously with me. Let say +1 to see if we can find a solution to this issue of "instants" that require timezone information in their string representation. What I did to circumvent for the time being is to add timezone info to the dt object that gets serialized later: dt.replace(tzinfo=datetime.timezone.utc)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants