Giter Site home page Giter Site logo

client-py's People

Contributors

abjonnes avatar armaghan-behlum avatar briankolowitz avatar corbinbs avatar dependabot[bot] avatar devin-fisher avatar ducu avatar ektar avatar erikwiffin avatar felixlc avatar hsolbrig avatar martinburchell avatar p2 avatar raheelsayeed avatar rhoffman12 avatar timharsch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

client-py's Issues

Basic custom helper functions in the Resource classes

I see that the way of getting the human name of a patient is handled in the FHIRClient class.

smart = client.FHIRClient(settings=my_settings)
r = Patient.where({'id': 1000})  # FHIRSearch object
results = r.perform(smart.server)  # Bundle object, two results
first_result = results.entry[0]
patient = first_result.resource
print smart.human_name(patient.name[0])

To me, this could naturally be a method of the Patient object, like this:

print patient.human_name

I'm interested in creating more functions like this, say what is the base title of on Observation object, which has no natural FHIR top-level field to represent it. For example, to me, the "title" of this resource is "Respiratory Rate" in the observation.code.text field (which is actually different for this resource, where I would say the "title" is "Weight Measured" in the observation.code.coding.display field).

Is this need very particular to how I'm applying it? How should I proceed?

  1. Create my own wrapping library, or
  2. Bring the discussion to the FHIR standards committee, or
  3. Improve the python client to allow for these functions to exist. Maybe a plug-in framework?

FHIR headers not set for create, update, delete

Hi:
I was trying to save the FHIR object. It was failing and when I debugged the reason, I figured out that there was no FHIR headers set like in _get() method.. Here is the snip that I have added and the save is working.. I wanted to know if there is any reason why it is not set like in get method..
if self.auth is not None and self.auth.can_sign_headers():
headers = self.auth.signed_headers(headers)
Thanks
Trinadh..

in models strict=False does not turn off validation as expected

in models strict=False parameter does not turn off validation as I expected.

>>> import fhirclient.models.observation as O
>>> o = O.Observation(strict=False)
>>> o.as_json()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ehaas/Documents/testing/pyexcel/venv36/lib/python3.6/site-packages/fhirclient/models/fhirabstractresource.py", line 42, in as_json
    js = super(FHIRAbstractResource, self).as_json()
  File "/Users/ehaas/Documents/testing/pyexcel/venv36/lib/python3.6/site-packages/fhirclient/models/fhirabstractbase.py", line 297, in as_json
    raise FHIRValidationError(errs)
fhirclient.models.fhirabstractbase.FHIRValidationError: {root}:
  'Property "code" on <fhirclient.models.observation.Observation object at 0x1022975c0> is not optional, you must provide a value for it'
  'Property "status" on <fhirclient.models.observation.Observation object at 0x1022975c0> is not optional, you must provide a value for it'

FHIR R4

I am curious to know if there is a timeline for FHIR R4 support, i.e., updated models.

module 'fhirclient.models.medication' has no attribute 'read'

Taking my first steps with adding some Fhir goodness to an application i've been working on.

Everything has gone well so far and was up and running with some basic queries but ran into problems taking things further to be more usable.

import fhirclient.models.medicationrequest as meds import fhirclient.models.medication as mednames

search = meds.MedicationRequest.where(struct={'subject': '2c4c5104-6d23-4c0a-97e9-bd229fc3559c', 'status': 'active'})
medications = search.perform_resources(smart.server)`

this appropriately returns two resources with a references:
-Medication/97e9b032-aad0-4c3e-9143-bb9e145c0491
-Medication/2c1ca733-3562-497a-82fa-ca6218258314

however

for medication in medications: medref = medication.medicationReference.reference med = mednames.Medication.read(medref, smart.server)
returns the error that

module 'fhirclient.models.medication' has no attribute 'read'

Goal is to produce a list of the actual names of the medication the patient is on so it might be i'm going about it the wrong way but this seems to be the way implied by the documentation.

Need SNI support in client

It looks like Requests (used in the Python client) needs some additional modules in order to support SNI (we have multiple certificats served on the same IP). https://stackoverflow.com/questions/18578439/using-requests-with-tls-doesnt-give-sni-support/18579484#18579484 Otherwise, the client throws an SSLError (hostname 'stub.smarthealthit.org' doesn't match either of '*.smartplatforms.org', 'smartplatforms.org') when pointed at a API server that is on a host with multiple certificates.

The test case is running any Python-based sample app against https://stub.smarthealthit.org/smart/dstu2 (for example using the launcher at https://stub.smarthealthit.org/). This service will not work for self-launched apps that ask for context. Works for apps that are launched in context (via the launcher at https://stub.smarthealthit.org/ or similar) and with apps that don't need context. The sample app that comes with the Python client is a standalone app that needs context assigned after launch, so not good for testing. We have another sample app that needs to be launched in context and should work for testing purposes: https://github.com/smart-on-fhir/sample-apps/blob/master/rest-app/app.py

SyntaxError: invalid syntax in /beaker/synchronization.py

The requirements_flask_app.txt specifies Beaker==1.7.0. When I attempt to run the Flask app using this Beaker version I get a syntax error, as seen below. After performing pip install --update beaker, the latest version of Beaker 1.10.0 does not have this issue.

File "/Users/artrudeau/client-py/env/lib/python3.7/site-packages/beaker/synchronization.py", line 289
self.async = 0
^
SyntaxError: invalid syntax

normalize fhir model classes

Pascal I apologize if this question does not relate exactly to this project but I cannot figure out how to contact you directly. I am playing with fhir client model classed and they are great but I am wondering if there is an easy way with client or maybe some other project that would allow normalizing resources into flat structures so they can be loaded to RDBMS. One idea I have is to somehow use your fhir model parser / generator to generate table DDLs and appropriate mappings. For example, patient resource will turn into multiple flat structures (table like) such as patient, patient_name, patient_identifiers etc. Hope it makes sense

change logging mechanism and debug of FHIR operations

Hi:
This is an enhancement request.

Currently fhirclient relies on root logger configuration to log messages. In my application the root configuration is set to warning. There is no way to enable DEBUG for fhirclient only.. Can the logging be changed to:

import logging
logger = logging.getLogger(__name__)

Also I feel requests_toolbelt.utils.dump can be used to debug the responses from ehr server. Is it possible to include the library in requirement and enable the debug like below (I use in debug mode):

    from requests_toolbelt.utils import dump
    res = self.session.put(url, headers=headers, data=json.dumps(resource_json))
    logging.debug('SMART SERVER:\r\n{0}'.format(dump.dump_response(res).decode('utf-8')))
    self.raise_for_status(res)

Thanks
Trinadh..

Date parsing of FHIR date gives wrong values for non-ISO formats

If a questionnaire response contains an answer with a valueDate field set to '1/1/1980', the resulting FHIRDate objects have a date value of '1101-01-01', rather than '1980-01-01'.

Ideally date parsing should be smart enough to handle different common date formats, but if ISO format is required, parsing should probably fail with an error rather than generating the wrong value when a non-ISO format is provided.

Relative imports do not work for FHIR-1.8.0 when using Python 2.7.12

When using either the FHIR-1.8.0 release or the latest-ci feature branch (the latter just to confirm that the issue also exists for FHIR 1.9), the relative imports fails for fhirreference.

The simplest way to reproduce is to create a small Python script in the root of a downloaded version of client-py-FHIR-1.8.0:

import isodate
import fhirclient.models.patient as p

Using Ubuntu 16.04, "python3 test_importing.py" works without issue (the exact Python version is 3.5.2), while "python2.7 test_importing.py" results in the following:

Traceback (most recent call last):
File "test_importing.py", line 2, in
import fhirclient.models.patient as p
File "/home/mikkel/Downloads/client-py-FHIR-1.8.0/fhirclient/models/patient.py", line 8, in
from . import domainresource
File "/home/mikkel/Downloads/client-py-FHIR-1.8.0/fhirclient/models/domainresource.py", line 55, in
from . import extension
File "/home/mikkel/Downloads/client-py-FHIR-1.8.0/fhirclient/models/extension.py", line 232, in
from . import annotation
File "/home/mikkel/Downloads/client-py-FHIR-1.8.0/fhirclient/models/annotation.py", line 57, in
from . import fhirreference
File "/home/mikkel/Downloads/client-py-FHIR-1.8.0/fhirclient/models/fhirreference.py", line 7, in
from . import reference
File "/home/mikkel/Downloads/client-py-FHIR-1.8.0/fhirclient/models/reference.py", line 48, in
from . import identifier
File "/home/mikkel/Downloads/client-py-FHIR-1.8.0/fhirclient/models/identifier.py", line 66, in
from . import fhirreference
ImportError: cannot import name fhirreference

The error is not limited to the Patient resource, but can be reproduced when trying to import other FHIR resources (e.g., Task, Questionnaire) that contains references.

The problem does not exist in the FHIR-1.6.0 release, which works with 2.7.12.

Please let me know if I can be of any help when/if you have the time to look at this issue :)

as_json() generate josn with single quote

Sample code

patient = Patient()
patient.id = '123'
print(patient.as_json())

It generates

{'id': '123', 'resourceType': 'Patient'}

Lots of JSON view/validator complains about this json string because it uses single quote.
According to json.org,
"A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes."
Is there a settings to let as_json() generate string using double quotes?

No good way to use multiple versions of the library in a single project?

In S4S we're building some demo apps that connect to DSTU2 clinical data servers and an STU3 financial server from CMS. I tried loading two versions of the library at different paths, but

https://github.com/smart-on-fhir/client-py/blob/master/fhirclient/__init__.py#L5

seems to clobber the namespaces. Has this come up before? I can think about ways to improve the module loading, but wanted to start with a quick sanity check.

Jinja wordwrap wraps each character instead of word

I just tried client-py on Arch linux (python 3.7 - I don't know what's the culprit...). The model output seems completely unreadable, because all the docstrings are "vertical" - the parser creates a wordwrap after each character, instead of after each 75 characters. This only breaks for the docstring, everything else seems to be ok.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  Generated from FHIR 3.0.1.11917 (http://hl7.org/fhir/StructureDefinition/Account) on 2018-09-22.
#  2018, SMART Health IT.


from . import domainresource

class Account(domainresource.DomainResource):
    """ 
    T
    r
    a
    c
    k
    s
    b
    a
    l
    a
    n
    c
    e
    ,
    c
    h
    a
    r
    g
    e
    s
    ,
    f
    o
    r
    p


# AND SO ON

I can only remove this behaviour if I remove the whole |wordwrap(width=75) part of the corresponding code lines here, line 18 and here, line 21 in the resource template.

pip freeze:

bumpversion==0.5.3
certifi==2018.8.24
chardet==3.0.4
colorlog==2.10.0
Django==2.1.1
idna==2.7
isodate==0.6.0
Jinja2==2.10
MarkupSafe==0.23
pytz==2018.5
requests==2.19.1
six==1.11.0
urllib3==1.23

I really don't know why this happens. Maybe it's a Jinja2 problem?

Search in FHIR

I am trying to search a patient using given name through a local server. this is my code. Local server's authentication is turned off.

in the view class of django framework

from fhirclient import client
from fhirclient.models.patient import Patient as fhir_patient
from fhirclient.server import FHIRServer
from fhirclient.models.fhirsearch import FHIRSearch

in one of the view function I tried to search for patient. First with id(this works) then using search(does not work).

server = FHIRServer( request, base_uri="http://localhost:8080")
patient = fhir_patient.read("1098667", server)

The above code works and I can read the patient details.

fs = FHIRSearch(fhir_patient,{"given":"rob"})
r = fs.perform_resources(server)

I get a list with 1 object with None type...

image

So looking deep into the code , I can confirm that I get the expected server response. But the bundle class is not reading it.

more of my inspection..

in server.py
value of the url is 'http://localhost:8080/Patient?given=rob'

the response from the server is as follows. (ie res._content variable )

{
"resourceType": "Bundle",
"title": "FHIR Atom Feed",
"id": "http://localhost:9080/Patient?given=rob",
"link": [
{
"rel": "self",
"href": "http://localhost:9080/Patient?given=rob"
}
],
"totalResults": 1,
"updated": "2015-08-19T10:07:21.063+08:00",
"author": [
{
"name": "groovy.config.atom.author-name",
"uri": "groovy.config.atom.author-uri"
}
],
"entry": [
{
"title": "Patient/1098667",
"id": "http://localhost:9080/Patient/1098667",
"updated": "2015-08-19T10:07:21.063+08:00",
"content": {
"resourceType": "Patient",
"text": {
"status": "generated",
"div": "

\n \n

Robert Hill

\n \n
"
},
"identifier": [
{
"use": "usual",
"label": "SMART Hospital MRN",
"system": "urn:oid:0.1.2.3.4.5.6.7",
"value": "1098667"
}
],
"name": [
{
"use": "official",
"family": [
"Hill"
],
"given": [
"Robert",
"P."
]
}
],
"telecom": [
{
"system": "email",
"value": "[email protected]"
}
],
"gender": {
"coding": [
{
"system": "http://hl7.org/fhir/v3/AdministrativeGender",
"code": "M",
"display": "Male"
}
]
},
"birthDate": "1953-10-27",
"address": [
{
"use": "home",
"line": [
"42 Park St"
],
"city": "Bixby",
"state": "OK",
"zip": "74008",
"country": "USA"
}
],
"active": true
}
}
]
}

But the bundle class always respond with 1 entry with a None type. Image is attached. Am I doing something wrong. ?

Data models fail with Python 2.7

As has become clear with pull request #7, there is an import issue with Python 2.7, which has a problem with current imports while Python 3 works just fine. The problem is that Python 3 chokes on import element with:

ImportError: No module named 'element'

Looks like this needs to be solved with:

try:
    import element
except ImportError as e:
    from . import element

Updating a resource causes: Status: 412 Precondition Failed

Hi,

When I change a FHIR entity and try to update it is causing: Status: 412 Precondition Failed

From the spec for updating a resource we have to set If-Match header whose value I have to pick from meta section in a resource.

The below code snip works that I added in server.py function=put_json()):

        if resource_json.get('id', None) is not None:
            headers['If-Match'] = 'W/"{}"'.format(resource_json.get('meta').get('versionId'))

Thanks
Trinadh..

human_name function in client-py/fhirclient/client.py gives error in some cases

Hi,
The function human_name() in client.py does not behave properly for some patient examples. The test example I tried is:

from fhirclient import client
import fhirclient.models.patient as p

settings = {
'app_id': 'my_web_app',
'api_base': 'https://sb-fhir-stu3.smarthealthit.org/smartstu3/open'
}
smart = client.FHIRClient(settings=settings)
patient = p.Patient.read('44a35c47-72b1-4e49-bb1e-518b0abedd65', smart.server)
print (smart.human_name(patient.name[0]))

Example data:

"name": [
{
"use": "official",
"family": "Abbott",
"given": [
"Gonzalo"
],
"prefix": [
"Mr."
]
}

The reason the function fails is that it expects all prefix, given, family names as lists whereas family name is definitely not a list at shown above. Also some times the suffix is None and this is not tested in the function before use and so gives error.

  • Krishna

Reading all paginated results from a bundle

Hi,

I am reading observation data of a patient.. The result are paginated.. I want to process paginated results and retrieve all the observations. Is there a way to do that without implementing my own code? I implemented a code but I am not sure if this is right implementation..

def _handle_search(smart, klass, struct):
    bundle = klass.where(struct).perform(smart.server)
    result = list()
    while True:
        logger.info(json.dumps(bundle.as_json(), indent=2))
        entries = [be.resource for be in bundle.entry] if bundle is not None and bundle.entry is not None else None
        logger.info('Retrieved {}/{} entries...'.format(
            len(bundle.entry) if bundle.entry else 0, bundle.total))
        if entries is not None and len(entries) > 0:
            result += entries

        url_params = _get_next_url_params(bundle.link)
        if len(url_params) > 1:
            bundle = klass.where(url_params).perform(smart.server)
        else:
            break

    return result


def _get_next_url_params(links):
    url = None
    for link in links:
        if link.relation == 'next':
            url = link.url

    params = {}
    if url is not None:
        import urlparse
        params = dict(urlparse.parse_qsl(urlparse.urlsplit(url).query))
    return params

Thanks
Trinadh..

Ability to use fhirclient for DSTU2 as well as DSTU3

Hi,

I am not sure if there is a way one can use the fhirclient for DSTU2 as well as STU3? The current master is updated with STU3. I want to pick the latest code but use models from DSTU2. If there is a way of specifying the version while creating the FHIRClient by passing in the version that one want to use would be great..

Thanks
Trinadh..

fhirclient-1.0.6 cannot create new resources on server

When using the create function on fhirabstractresource classes, the path passed to the server.put_json() function is the relative path, not the relative base. When attempting to use fhirclient-1.0.6 with a FHIR 1.6.0 server, this results in a PUT request to a Patient/None endpoint, failing the addition. In the current master branch this issue has been fixed, but the code pulled from the 1.0.6 apt repository still has this bug.

Broken example on readme

I was trying to go through the read me instructions, but I got an error after passing the first information.

`from fhirclient import client
settings = {
'app_id': 'my_web_app',
'api_base': 'https://fhir-open-api-dstu2.smarthealthit.org'
}
smart = client.FHIRClient(settings=settings)

import fhirclient.models.patient as p
patient = p.Patient.read('hca-pat-1', smart.server)
`
I received the following error.

screenshot

Is the dstu-2 site not available?

as_json() on FHIRAbstractBase returns a dictionary

I've noticed that the as_json() method actually returns a Python dictionary.

Intuitively, I'd expect this to return a JSON string (e.g. as json.dumps() would) and a method such as as_dict() to return it as a Python dictionary.

Location header is ignored during create/update methods

Hi,

REST specification returns a Location header on successful POST/PATCH and has to be handled appropriately by the caller.. The create()/update() methods are successful with HTTP 201 but the response does not return the actual object reason being the Location header is ignored..

Snip from server.py->post_json()

    res = self.session.get(url, headers=headers)
    self.raise_for_status(res)
    return res

Snip from fhirabstractresource->create()

    ret = srv.put_json(self.relativePath(), self.as_json())
    if len(ret.text) > 0:
        return ret.json()
    return None

Here fhirabstractresource is getting all the headers since it receives a Response object but ignores the response headers. The return response is always None on successful creation since REST does not return any data on success..

Thanks
Trinadh.

FHIRValidationError:

<from fhirclient import client
settings = {
'app_id': 'first_fhir',
'api_base': 'https://syntheticmass.mitre.org/fhir/'
#https://syntheticmass.mitre.org/fhir/Patient/58b3663e3425def0f0f6a229/$everything
}
smart = client.FHIRClient(settings=settings)
import fhirclient.models.observation as o
ob_data = o.Observation.read('58b3663e3425def0f0f69522',smart.server)
ob_data >

Got error:
FHIRValidationError: {root}:
Superfluous entry "encounter" in data for <fhirclient.models.observation.Observation object at 0x0000026A163A8390>

Parsing drops extensions on primitives

Documenting a known issue: parsing FHIR resources with extensions on primitives silently drops the extensions. For example:

{
  "resourceType": "Patient",
  "gender": "male",
  "_gender": {
    "extension": [{
      "url": "http://test-extension",
      "valueString": "with extra data"
    }]
  }
}

Cannot perform search with more than one instance of same param

Because the search parameters are received as a dictionary, it is impossible to construct a search query where the same parameter is used twice, because a dictionary requires unique keys. This makes it impossible to construct a search URL for results between two values, which is actually a pretty normal use case, e.g. when searching for results between two dates:

http://fhirtest.uhn.ca/baseDstu3/MedicationDispense?whenprepared=gt2018-05-21T00%3A00%3A00-05%3A00&whenprepared=lt2018-05-24T23%3A59%3A59-05%3A00

Is there an undocumented trick for this, or is this not possible at the moment?

Dependensies

I was goig to setup client-py and it did not automatically work after running pip install -r requirements_flask_app.txt
Fixed the problem by updating Werkzeug.
So maybe the line: Werkzeug==0.10.4 in requirements_slask_app.txt should be fixed?

valueDecimal won't accept long values

Questionnaire responses can have an answer of type integer, limited to 32 bits; or they can use valueDecimal for bigger numbers.

However, if the client doesn't put a decimal point, and instead sets valueDecimal to a number that won't fit into an int (e.g. 10000000000000000000), it gets parsed as a long, and the parser gives a validation error:

FHIRValidationError: {root}: group: question: answer: valueDecimal: Wrong type <type 'long'> for property "valueDecimal" on $lt;class 'fhirclient.models.questionnaireresponse.QuestionnaireResponseGroupQuestionAnswer'>, expecting <type 'float'>

Long values without decimal points should be accepted here (even if it means having to convert to a float).

backboneelement ImportError - Python 3.4.2

This may be similar to a problem noted in issue #8

This occurred running flask_app.py after following the build instructions in the README.md

(fcenv)xxxx@raspberrypi:~/projects/client-py $ python -V
Python 3.4.2
(fcenv)xxxx@raspberrypi:~/projects/client-py $ python flask_app.py
Traceback (most recent call last):
File "flask_app.py", line 5, in
from fhirclient.models.medication import Medication
File "/home/xxxx/projects/client-py/fhirclient/models/medication.py", line 8, in
from . import domainresource
File "/home/xxxx/projects/client-py/fhirclient/models/domainresource.py", line 55, in
from . import extension
File "/home/xxxx/projects/client-py/fhirclient/models/extension.py", line 206, in
from . import annotation
File "/home/xxxx/projects/client-py/fhirclient/models/annotation.py", line 57, in
from . import fhirreference
File "/home/xxxx/projects/client-py/fhirclient/models/fhirreference.py", line 98, in
from . import bundle
File "/home/xxxx/projects/client-py/fhirclient/models/bundle.py", line 61, in
from . import backboneelement
File "/home/xxxx/projects/client-py/fhirclient/models/backboneelement.py", line 41, in
from . import extension
ImportError: cannot import name 'extension'
(fcenv)xxxx@raspberrypi:~/projects/client-py $

FHIRDate.as_json uses original instead of isostring

From fhirdate.py

    def as_json(self):\n
        if self.origval is not None:
            return self.origval
        return self.isostring

Sample code

date = FHIRDate('20190527T210000')
print(date.as_json())
print(date.isostring)

outputs

20190527T210000
2019-05-27T21:00:00

as_json() function should output the same result as isostring

SOLVED: 406 HTTP errors using mismatched `fhirclient` version and FHIR endpoint

Not really an issue with this code, but just signpost for others having similar troubles:

We were attempting to contact the Cerner unauthenticated demo/sandbox FHIR server at https://fhir-open.sandboxcerner.com/dstu2/0b8a0111-e8e6-4c26-a91c-5069cbc6b1ca using this fhirclient library. This is a DSTU2 version FHIR server so we should have maded sure we were using the correct version of fhirclient, however we thought we'd try with the master branch initially.

The Cerner server seems very sensitive to being passed only the correct 'Accept': 'application/json+fhir' header, and will refuse to interact if the header is 'Accept': 'application/fhir+json'.

The error received is factually accurate but didn't particularly aid us in finding the problem: (included here for Googleability)

requests.exceptions.HTTPError: 406 Client Error: Not Acceptable for url

Postman's error when passing similar invalid headers is coming back from the server and is a little more detailed:

The Accept type is invalid. See the documentation on the fhir.cerner.com website for acceptable format values for the resource you are attempting to access.

It's our own fault for not using the right version of the library, but we wasted a good hour trying to work out what the problem was and then figuring out how to pass a different header using fhirclient, when all we really needed to do was:

pip install fhirclient==1.0.3

Batch/Transaction using the client library

Hey,

I have been using the client library for the last few days and I find it very convenient to get and create resources for a given ResourceType.

However, I have quite struggled to find a way to do a batch (even a transaction actually) ref interaction with the FHIR server using this library.

Such use-case happens for instance when trying to get a summary of the health of a given patient (general informations, conditions, medications...). It becomes rapidly annoying and ineffective to do multiple HTTP requests for each ResourceType to be included, hence the use of the batch interaction.

I have not found an intuitive way to use the client library to do so. I basically wanted to know if I had missed something, or if it is not possible right now.

PS: I have been able to make a batch interaction by constructing a Bundle with several "request" objects and then posting this bundle to the base URL using FHIRServer.post_json, which returns a requests response, hard to parse.

Thank you very much for your help !

Unhelpful error message on malformed conformance statement.

This affects v1.0.6.

If the conformance statement parser is provided a null when it expects an object, the error message is confusing.

I was attempting to load a conformance statement where conformance.rest.resources had nulls in the searchTerms array. See https://gist.github.com/erikwiffin/cdcb94b0228a081c510d554a921cdc8d. When I tried to load the conformance statement, I got the following error message:

FHIRValidationError: {root}:
  rest:
    resource:
      searchParam:
        name 'self' is not defined

I can't quite follow the logic in https://github.com/smart-on-fhir/client-py/blob/v1.0.6/fhirclient/models/fhirabstractbase.py, but it looks like something in update_with_json isn't correctly checking that it has a dictionary instead of a None. A check so that a more accurate error message could be displayed would be really helpful. Also, the tree rest.resource.searchParam feels like it skipped a step. Something to indicate which resource is causing the problem, whether that be an array index or the resource type would make that a lot more legible.

I realize this is an issue with an older version of the client library, but my FHIR server is still DSTU2 and 3.0.0 can't read that at all.

Add support for logging FHIR requests

As part of the S4S project (http://syncfor.science/), we'd like to be able to log all of our FHIR requests so that we can see how various API implementations are changing over time. Right now, this doesn't seem possible using the fhirclient library.

The obvious hook for this behavior would be in FHIRServer._get, but there's a lot of different ways this could be accomplished. The easiest in my mind is some kind of last_response property on the FHIRServer class. Any time a call to one of the request methods is made, the response would be set to last_response before res.json() is returned. My calling code would then be responsible for accessing that property and storing it somewhere.

A more involved solution would be some kind of HTTP'er class that FHIRServer would use for any of its HTTP related behavior instead of calling the requests library directly. Then I could write my own logging-aware HTTP'er and provide that to my FHIRServer instance instead of the default one that would ship with this library. This could also potentially make it easier to resolve some of the issues raised in #16, having auth.py set up some kind of SecureHTTP'er maybe? I haven't thought that use case through very well, but modularization is always helpful. ;)

refresh_token is getting lost during auth.py->reauthorize()->_request_access_token() call

Hi:
auth.py->_request_access_token() is being called during reauthorize(). What is happening is after login I got a refresh_token and after reauthorize() is called, refresh token is getting set to None, so subsequent reauthorize() fails with an error.. Here is the code snip:

    self.refresh_token = ret_params.get('refresh_token') <-- Assignment before checking..
    if self.refresh_token is not None:
        del ret_params['refresh_token']

Not sure if this is right fix but it checks if the response contains the required value before overwriting..

    refresh_token = ret_params.get('refresh_token')
    if  refresh_token:
        self.refresh_token = refresh_token
        del ret_params['refresh_token']

Exception:
Traceback (most recent call last):
File "/Users/trinadh/work/.venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/trinadh/work/.venv/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/Users/trinadh/work/smart_fhir_poc/smart_fhir_poc/fhir_app/views.py", line 640, in create_med_statement
if smart.reauthorize():
File "/Users/trinadh/work/.venv/lib/python2.7/site-packages/fhirclient/client.py", line 138, in reauthorize
self._handle_launch_context(ctx)
File "/Users/trinadh/work/.venv/lib/python2.7/site-packages/fhirclient/client.py", line 143, in _handle_launch_context
if 'patient' in ctx:
TypeError: argument of type 'NoneType' is not iterable

Thanks
Trinadh..

Improvement: pytest implementation, travis-ci for continuous integration, flake8 for style guide enforcement

Hi @p2
I am Nazrul, I have some suggestions to make this wonderful product to be more explicit and standard.

  1. pytest: pytest is better than unittest and more powerful of course.
  2. For continuous integration we could use https://travis-ci.org/ as you know this is free for opensource project.
  3. flake8 http://flake8.pycqa.org/en/latest/ undoubtedly one of the best tool that is enforcing the best coding style.
  4. 100% code coverage: we code use https://coveralls.io/ for inspection.
  5. documentation improvement for developer as development guide .

I understand, you might be so busy, In that case I could manage some times, if you have agreement on those enhancements,

Syntax Error in fhirsearch.py

Hi,

Is there a syntax error in fhirsearch.py, class=FHIRSearchParamOperatorHandler, method=apply

    def apply(self, param):
        if self.key not in self.__class__.operators:
            raise Exception('Unknown operator "{}" for "{}"'.format(self.key, parent.name))
        param.value = self.__class__.operators[self.key] + self.value

Should be raise Exception('Unknown operator "{}" for "{}"'.format(self.key, param.name))

Thanks
Trinadh..

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.