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

to_resource() error "Unknown search parameter 'id'" #55

Closed
motey opened this issue Mar 16, 2020 · 2 comments · Fixed by #56
Closed

to_resource() error "Unknown search parameter 'id'" #55

motey opened this issue Mar 16, 2020 · 2 comments · Fixed by #56
Labels
bug Something isn't working

Comments

@motey
Copy link
Contributor

motey commented Mar 16, 2020

I am trying to resolve references from a resource, with AsyncReference.to_resource()
This seems to fail.

example

import asyncio
from fhirpy import AsyncFHIRClient
from py2neo import Graph, Node, Relationship


async def main():
    # Create an instance
    client = AsyncFHIRClient(
        "http://hapi.fhir.org/baseR4",
        # "http://localhost:8080/fhir",
        authorization="Bearer TOKEN",
    )

    obser_client = client.resources("Observation")  # Return lazy search set
    obser_query = obser_client.search().limit(5)
    observations = await obser_query.fetch()
    for obser in observations:
        if "subject" in obser:
            # This will fail
            patient = await obser.subject.to_resource()


if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())

It looks like a typo on line

self.resource_type).search(id=self.id).get()

because when changing the line

self.resource_type).search(id=self.id).get()

to

self.resource_type).search(_id=self.id).get()

it seems to work.
Im just starting to work with fhir, and do not have a good overview of the subject matter.
Do I use the function in a wrong way?
Is the fhir test server data corrupt?
If i found a bug, i can provide a merge request.

@motey
Copy link
Contributor Author

motey commented Mar 16, 2020

Attaching error log:

Traceback (most recent call last):
  File "/media/bleimehl/Daten_Linux/Repos/git/dzdgitlab/fhir2neo4j/try-resolve-ref.py", line 25, in <module>
    loop.run_until_complete(main())
  File "/usr/lib/python3.7/asyncio/base_events.py", line 579, in run_until_complete
    return future.result()
  File "/media/bleimehl/Daten_Linux/Repos/git/dzdgitlab/fhir2neo4j/try-resolve-ref.py", line 20, in main
    patient = await obser.subject.to_resource()
  File "/home/bleimehl/.local/lib/python3.7/site-packages/fhirpy/base/lib.py", line 374, in to_resource
    return await self.client.resources(self.resource_type).search(id=self.id).get()
  File "/home/bleimehl/.local/lib/python3.7/site-packages/fhirpy/base/lib.py", line 270, in get
    res_data = await searchset.fetch()
  File "/home/bleimehl/.local/lib/python3.7/site-packages/fhirpy/base/lib.py", line 215, in fetch
    bundle_data = await self.client._fetch_resource(self.resource_type, self.params)
  File "/home/bleimehl/.local/lib/python3.7/site-packages/fhirpy/base/lib.py", line 89, in _fetch_resource
    return await self._do_request("get", path, params=params)
  File "/home/bleimehl/.local/lib/python3.7/site-packages/fhirpy/base/lib.py", line 86, in _do_request
    raise OperationOutcome(await r.text())
fhirpy.base.exceptions.OperationOutcome: {
  "resourceType": "OperationOutcome",
  "text": {
    "status": "generated",
    "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><h1>Operation Outcome</h1><table border=\"0\"><tr><td style=\"font-weight: bold;\">ERROR</td><td>[]</td><td><pre>Unknown search parameter &quot;id&quot;. Value search parameters for this search are: [_id, _language, active, address, address-city, address-country, address-postalcode, address-state, address-use, addresscontenttype, birthdate, death-date, deceased, email, eyecolour, family, gdaddresstype, gender, general-practitioner, given, identifier, language, link, middlename, mothersMaidenName, name, organization, phone, phonetic, race, sex, telecom]</pre></td>\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t</tr>\n\t\t</table>\n\t</div>"
  },
  "issue": [
    {
      "severity": "error",
      "code": "processing",
      "diagnostics": "Unknown search parameter \"id\". Value search parameters for this search are: [_id, _language, active, address, address-city, address-country, address-postalcode, address-state, address-use, addresscontenttype, birthdate, death-date, deceased, email, eyecolour, family, gdaddresstype, gender, general-practitioner, given, identifier, language, link, middlename, mothersMaidenName, name, organization, phone, phonetic, race, sex, telecom]"
    }
  ]
}

@mkizesov
Copy link
Contributor

mkizesov commented Mar 16, 2020

Thanks for pointing this out. I think it's a bug according to FHIR spec https://www.hl7.org/fhir/search.html#id
It worked for us because our FHIR server accept both id and _id params.
Feel free to provide a merge request!

@mkizesov mkizesov added the bug Something isn't working label Mar 16, 2020
mkizesov added a commit that referenced this issue Mar 16, 2020
mkizesov added a commit that referenced this issue Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants