Link Search Menu Expand Document

Using Requests

import requests
import json
response = requests.get("http://hapi.fhir.org/baseR4/Patient/2543713")
response.status_code
200
data = json.loads(response.content.decode('utf-8'))
data['name']
[{'use': 'official', 'family': 'Chalmers', 'given': ['Peter', 'James']}]
data['name'][0]['family']
'Chalmers'
data['name'][0]['given']
['Peter', 'James']
data['name'][0]['given'][0]
'Peter'
response.text
'{\n  "resourceType": "Patient",\n  "id": "2543713",\n  "meta": {\n    "versionId": "1",\n    "lastUpdated": "2021-09-06T03:21:51.345+00:00",\n    "source": "#tE3DOhkavDLHnkhZ"\n  },\n  "text": {\n    "status": "generated",\n    "div": "<div xmlns=\\"http://www.w3.org/1999/xhtml\\">Some narrative</div>"\n  },\n  "active": true,\n  "name": [ {\n    "use": "official",\n    "family": "Chalmers",\n    "given": [ "Peter", "James" ]\n  } ],\n  "gender": "male",\n  "birthDate": "1974-12-25"\n}'
response.json()
{'resourceType': 'Patient',
 'id': '2543713',
 'meta': {'versionId': '1',
  'lastUpdated': '2021-09-06T03:21:51.345+00:00',
  'source': '#tE3DOhkavDLHnkhZ'},
 'text': {'status': 'generated',
  'div': '<div xmlns="http://www.w3.org/1999/xhtml">Some narrative</div>'},
 'active': True,
 'name': [{'use': 'official',
   'family': 'Chalmers',
   'given': ['Peter', 'James']}],
 'gender': 'male',
 'birthDate': '1974-12-25'}