-
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:
-
FHIRElement
-
FHIRResource
-
Resource, generated from the base resource profile
- DomainResource, generated from the domain resource profile
-
Resource, generated from the base resource profile
-
FHIRResource
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 = NSBundle.mainBundle().fhir_bundledResource("Contract") as? 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. These interactions will all use the Server's JSON methods:
getJSON(path:callback:)
putJSON(path:body:callback:)
postJSON(path:body:callback:)
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
}
let encounter = Encounter(...) // must have _server assigned
encounter.delete() { error in
// check error
}
TBD
let prescription = MedicationPrescription(...)
prescription.create(server: smart.server) { error in
// check error
}
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.