From b7c02575d7f90682584bc6d2e9065a2328e29da3 Mon Sep 17 00:00:00 2001
From: Michael Terry
Date: Fri, 8 Nov 2024 09:16:04 -0500
Subject: [PATCH] Update docs and demos to use new iter search methods
---
README.md | 13 ++++++-------
demos/flask/flask_app.py | 9 +++------
demos/flask/requirements.txt | 2 +-
3 files changed, 10 insertions(+), 14 deletions(-)
diff --git a/README.md b/README.md
index 109c618f..260fc507 100644
--- a/README.md
+++ b/README.md
@@ -109,23 +109,22 @@ settings = {
smart = client.FHIRClient(settings=settings)
search = Encounter.where(struct={'subject': '2cda5aad-e409-4070-9a15-e1c35c46ed5a', 'status': 'finished'})
-encounters = search.perform_resources(smart.server)
-print({res.type[0].text for res in search.perform_resources(smart.server)})
+print({res.type[0].text for res in search.perform_resources_iter(smart.server)})
# {'Encounter for symptom', 'Encounter for check up (procedure)'}
# to include the resources referred to by the encounter via `subject` in the results
search = search.include('subject')
-print({res.resource_type for res in search.perform_resources(smart.server)})
+print({res.resource_type for res in search.perform_resources_iter(smart.server)})
# {'Encounter', 'Patient'}
# to include the Procedure resources which refer to the encounter via `encounter`
search = search.include('encounter', Procedure, reverse=True)
-print({res.resource_type for res in search.perform_resources(smart.server)})
+print({res.resource_type for res in search.perform_resources_iter(smart.server)})
# {'Encounter', 'Patient', 'Procedure'}
-# to get the raw Bundle instead of resources only, you can use:
-bundle = search.perform(smart.server)
-print({entry.resource.resource_type for entry in bundle.entry})
+# to get the raw Bundles instead of resources only, you can use:
+bundles = search.perform_iter(smart.server)
+print({entry.resource.resource_type for bundle in bundles for entry in bundle.entry})
# {'Encounter', 'Patient', 'Procedure'}
```
diff --git a/demos/flask/flask_app.py b/demos/flask/flask_app.py
index fbde5ee8..34eb7751 100755
--- a/demos/flask/flask_app.py
+++ b/demos/flask/flask_app.py
@@ -38,11 +38,8 @@ def _reset():
del session['state']
def _get_prescriptions(smart):
- bundle = MedicationRequest.where({'patient': smart.patient_id}).perform(smart.server)
- pres = [be.resource for be in bundle.entry] if bundle is not None and bundle.entry is not None else None
- if pres is not None and len(pres) > 0:
- return pres
- return None
+ search = MedicationRequest.where({'patient': smart.patient_id})
+ return list(search.perform_resources_iter(smart.server))
def _get_medication_by_ref(ref, smart):
med_id = ref.split("/")[1]
@@ -88,7 +85,7 @@ def index():
# generate simple body text
body += "You are authorized and ready to make API requests for {0}.
".format(name)
pres = _get_prescriptions(smart)
- if pres is not None:
+ if pres:
body += "{0} prescriptions:
".format("His" if 'male' == smart.patient.gender else "Her", ''.join([_get_med_name(p,smart) for p in pres]))
else:
body += "(There are no prescriptions for {0})
".format("him" if 'male' == smart.patient.gender else "her")
diff --git a/demos/flask/requirements.txt b/demos/flask/requirements.txt
index e69d659d..b06704c8 100644
--- a/demos/flask/requirements.txt
+++ b/demos/flask/requirements.txt
@@ -1,3 +1,3 @@
beaker>=1.13.0
-fhirclient>=4
+fhirclient>=4.3
flask>=2.3.2