beda-software / fhir-py

FHIR Client for python
MIT License
174 stars 32 forks source link

Refactor __iter__ #52

Closed kylejbrk closed 4 years ago

kylejbrk commented 4 years ago

Not sure if it's anymore efficient but it's cleaner.

mkizesov commented 4 years ago

Hi! Thank you for your effort. This code doesn't work unfortunately.

kylejbrk commented 4 years ago

Whoops. I was putting the bundle data in next link. Should've tested first.

mkizesov commented 4 years ago

You also need to yield all items from the first request (which you get in next_link before the loop starts). Then get "next" link. And then you realize that you copypasted the half of the code from the while loop and maybe check "if next_link:" inside the loop is not that bad. But of course it'll be great if you'll find a more cleaner solution.

mkizesov commented 4 years ago

We can probably use part of your PR like this:

next_link = True
while next_link:
    ...
    next_link = get_by_path(bundle_data, ['link', {'relation': 'next'}, 'url'])

And remove if not next_link: break from the loop.