-
Notifications
You must be signed in to change notification settings - Fork 47
Search
FHIR search operations search through an existing set of resources by a set of search criteria supplied as parameters to the search. The Swift framework provides the FHIRSearch class to configure and execute searches.
Searches are configured in a NoSQL-like approach proposed and used by fhir.js.
A search for all medication orders for patient with a known id can be as simple as:
let search = MedicationOrder.search(["patient": id])
Searching for all male patients in the Boston area with the exact family name "Willis" would be achieved with:
let search = Patient.search([
"address": "Boston",
"gender": "male",
"family": ["$exact": "Willis"]
])
This will translate into a REST request against:
Patient?address=Boston&gender=male&family:exact=Willis
These two searches are generated with convenience methods provided by all FHIRResource subclasses. You can also create FHIRSearch instances manually:
let search = FHIRSearch(query: [
"subject": [
"$type": "Patient",
"name": "Bruce",
"birthDate": ["$lt": "1970"]
]
])
The perform(server:)
method on the previously created FHIRSearch instances can be used to execute the search query to retrieve the result Bundle:
search.perform(smart.server) { bundle, error in
if nil != error {
// there was an error
}
else {
let bruces = bundle?.entry?
.filter() { return $0.resource is Patient }
.map() { return $0.resource as! Patient }
// now `bruces` holds all known Patient resources
// named Bruce and born earlier than 1970
}
}