Skip to content

Commit

Permalink
Merge pull request #183 from smart-on-fhir/mikix/add-iter-docs-to-readme
Browse files Browse the repository at this point in the history
Update docs and demos to use new iter search methods
  • Loading branch information
mikix authored Nov 8, 2024
2 parents ff41695 + b7c0257 commit 44cd84a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
```

Expand Down
9 changes: 3 additions & 6 deletions demos/flask/flask_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -88,7 +85,7 @@ def index():
# generate simple body text
body += "<p>You are authorized and ready to make API requests for <em>{0}</em>.</p>".format(name)
pres = _get_prescriptions(smart)
if pres is not None:
if pres:
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]))
else:
body += "<p>(There are no prescriptions for {0})</p>".format("him" if 'male' == smart.patient.gender else "her")
Expand Down
2 changes: 1 addition & 1 deletion demos/flask/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
beaker>=1.13.0
fhirclient>=4
fhirclient>=4.3
flask>=2.3.2

0 comments on commit 44cd84a

Please sign in to comment.