-
Notifications
You must be signed in to change notification settings - Fork 47
Resources
The embedded Swift-FHIR library contains classes for all base FHIR profiles. All classes are documented in the technical documentation, their inheritance graph usually is:
-
FHIRAbstractBase
-
FHIRAbstractResource
-
Resource, generated from the base resource profile
- DomainResource, generated from the domain resource profile
-
Resource, generated from the base resource profile
-
FHIRAbstractResource
You have several options to instantiate FHIR elements and resources. For now only JSON serialization is supported.
These code examples assume a valid JSON file named Contract.json
to be present in the App bundle.
Error checking is omitted for readability purposes.
let url = NSBundle.mainBundle().URLForResource("Contract", withExtension: "json")!
let data = NSData(contentsOfURL: url)!
let json = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil) as! FHIRJSON
let contract = Contract(json: json)
let url = NSBundle.mainBundle().URLForResource("Contract", withExtension: "json")!
let data = NSData(contentsOfURL: url)!
let json = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil) as! FHIRJSON
let contract = FHIRElement.instantiateFrom(json, owner: nil) as? Contract
// equal to
let type = json["resourceType"] as! String
let contract = FHIRElement.factory(type, json: json, owner: nil)
This uses the factory methods shown above.
let contract = try NSBundle.mainBundle().fhir_bundledResource("Contract")
See the read
interaction below.
The FHIR REST API defines a set of logical interactions. These are all (to be) implemented as a class extension on Resource, at instance- or class-level, or are handled by the Server instance the client is hanging on to.
Currently, all server interactions use the JSON format by using the Server's performRequest*
methods.
Patient.read({patient-id}, server: smart.server) { resource, error in
// check error
// `resource` is a "Patient" instance on success
}
TBD
let encounter = Encounter(...) // must have _server assigned
encounter.update() { error in
// check error
}
TODO: PATCH
operation
let encounter = Encounter(...) // must have _server assigned
encounter.delete() { error in
// check error
}
TBD
The create
method will issue a create
call, issuing a POST with the resource's contents to the server.
It will add the Prefer
header with return=minimal
and will ignore body content if the server still returns it.
The resource's id
and meta
will be updated with data found in response headers.
let order = MedicationOrder(...)
order.create(server: smart.server) { error in
// check error
}
The createAndReturn
method also issues a create
call, a POST with the resource's contents.
It will add the Prefer
header with return=representation
and will, should the server ignore that request, issue a read
to retrieve resource data before calling the callback.
let order = MedicationOrder(...)
order.createAndReturn(server: smart.server) { error in
// check error
// resource has been populated with data fresh from the server
}
See the search page for detailed instructions. A basic example:
MedicationPrescription.search(["patient": id])
.perform(smart.server) { bundle, error in
// check error
// `bundle` is a Bundle instance
}
TBD
The Server instance handles working with the conformance statement. You don't usually need to work with conformance yourself, but you still can if you desire to do so. Take a look at the Server and Conformance class documentation for details.
TBD
TBD
See the search page.