Skip to content

Commit 44cd84a

Browse files
authored
Merge pull request #183 from smart-on-fhir/mikix/add-iter-docs-to-readme
Update docs and demos to use new iter search methods
2 parents ff41695 + b7c0257 commit 44cd84a

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

README.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,22 @@ settings = {
109109
smart = client.FHIRClient(settings=settings)
110110

111111
search = Encounter.where(struct={'subject': '2cda5aad-e409-4070-9a15-e1c35c46ed5a', 'status': 'finished'})
112-
encounters = search.perform_resources(smart.server)
113-
print({res.type[0].text for res in search.perform_resources(smart.server)})
112+
print({res.type[0].text for res in search.perform_resources_iter(smart.server)})
114113
# {'Encounter for symptom', 'Encounter for check up (procedure)'}
115114

116115
# to include the resources referred to by the encounter via `subject` in the results
117116
search = search.include('subject')
118-
print({res.resource_type for res in search.perform_resources(smart.server)})
117+
print({res.resource_type for res in search.perform_resources_iter(smart.server)})
119118
# {'Encounter', 'Patient'}
120119

121120
# to include the Procedure resources which refer to the encounter via `encounter`
122121
search = search.include('encounter', Procedure, reverse=True)
123-
print({res.resource_type for res in search.perform_resources(smart.server)})
122+
print({res.resource_type for res in search.perform_resources_iter(smart.server)})
124123
# {'Encounter', 'Patient', 'Procedure'}
125124

126-
# to get the raw Bundle instead of resources only, you can use:
127-
bundle = search.perform(smart.server)
128-
print({entry.resource.resource_type for entry in bundle.entry})
125+
# to get the raw Bundles instead of resources only, you can use:
126+
bundles = search.perform_iter(smart.server)
127+
print({entry.resource.resource_type for bundle in bundles for entry in bundle.entry})
129128
# {'Encounter', 'Patient', 'Procedure'}
130129
```
131130

demos/flask/flask_app.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,8 @@ def _reset():
3838
del session['state']
3939

4040
def _get_prescriptions(smart):
41-
bundle = MedicationRequest.where({'patient': smart.patient_id}).perform(smart.server)
42-
pres = [be.resource for be in bundle.entry] if bundle is not None and bundle.entry is not None else None
43-
if pres is not None and len(pres) > 0:
44-
return pres
45-
return None
41+
search = MedicationRequest.where({'patient': smart.patient_id})
42+
return list(search.perform_resources_iter(smart.server))
4643

4744
def _get_medication_by_ref(ref, smart):
4845
med_id = ref.split("/")[1]
@@ -88,7 +85,7 @@ def index():
8885
# generate simple body text
8986
body += "<p>You are authorized and ready to make API requests for <em>{0}</em>.</p>".format(name)
9087
pres = _get_prescriptions(smart)
91-
if pres is not None:
88+
if pres:
9289
body += "<p>{0} prescriptions: <ul><li>{1}</li></ul></p>".format("His" if 'male' == smart.patient.gender else "Her", '</li><li>'.join([_get_med_name(p,smart) for p in pres]))
9390
else:
9491
body += "<p>(There are no prescriptions for {0})</p>".format("him" if 'male' == smart.patient.gender else "her")

demos/flask/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
beaker>=1.13.0
2-
fhirclient>=4
2+
fhirclient>=4.3
33
flask>=2.3.2

0 commit comments

Comments
 (0)