beda-software / fhir-py

FHIR Client for python
MIT License
168 stars 31 forks source link

Add API for calling resource operations #60

Closed ir4y closed 4 years ago

ir4y commented 4 years ago
/Questionnaire/<id>/$populate
/Valuest/<id>/$expand
/Valuest/$expand

$ operation should be a string parameter and accept any string. It should work on both levels.

mkizesov commented 4 years ago

Some thoughts.

Operation on particular resource/reference

sdk.client.resource('Questionnaire', id=123).execute('$populate')
sdk.client.reference('Patient', 1).execute( ... )

async def execute(self, operation):
    pass

Operation on any path. In FHIR we can also use GET requests for operations (and there are some DELETE and PUT operations in Aidbox), but I think we should implement sdk.client.execute to work only with POST operations (because it's most common)

sdk.client.execute('/ValueSet/$expand', {'url': 'http://abc', 'filter': 'value'})

async def execute(path, payload, method?='post'):
    pass

# or using kwargs:
sdk.client.execute('/ValueSet/$expand', url='http://abc', filter='value')

async def execute(path, method?='post', **payload):
    pass

Also we can add public method for doing any requests with fhir-py aiohttp client. Something like:

sdk.client.request('post', '/Valuest/$expand', ...)

async def request(method, path, params=None, payload=None)
    pass
mkizesov commented 4 years ago

We decided that all methods should have similar set of params. Execute on resources affects only request url.

sdk.client.resource('Questionnaire', id=123).execute('$populate', **kwargs)

sdk.client.execute('/ValueSet/$expand', **kwargs)

# kwargs: method, params, payload, etc..
# Probably they should be the same as in aiohttp request
# and should be passed to aiohttp request without any changes