Resource

open class Resource: FHIRAbstractResource

Base Resource.

This is the base resource type for everything.

  • Attempt to instantiate a Resource of the receiving class by reading a JSON file at the given filesystem path.

    Declaration

    Swift

    public class func instantiate(fromPath path: String) throws -> Self

    Parameters

    path

    The local path to read the JSON file from

    Return Value

    An instance of the receiving class

  • Creates a Reference instance containing a relative reference to the receiver.

    Throws if creating the reference fails; mostly happens when the instance doesn’t have an id.

    Declaration

    Swift

    public func asRelativeReference() throws -> Reference

    Return Value

    A Reference instance on success

  • The string used to fill a reference’s display property for the instance.

    Declaration

    Swift

    public func preferredRelativeReferenceDisplay() -> String?
  • Returns the relative URL path to the receiver’s type of resource. This usually is the same as the resource’s name.

    Declaration

    Swift

    public func relativeURLBase() -> String

    Return Value

    A string indicating the relative URL base, e.g. “MedicationPrescription”

  • The relative URL path of the resource; the instance needs to have an id, otherwise a FHIRError is thrown.

    Declaration

    Swift

    public func relativeURLPath() throws -> String

    Return Value

    A string indicating the relative URL, e.g. “MedicationPrescription/1234”

  • The absolute URL of the resource. Needs the instance’s server property to be set and have an id, otherwise a FHIRError is thrown.

    Declaration

    Swift

    public func absoluteURL() throws -> URL

    Return Value

    The resource’s absolute URL, e.g. “https://fhir.smarthealthit.org/MedicationPrescription/1234”

  • Reads the resource with the given id from the given server.

    Forwards to class method readFrom with the resource’s relative URL, created from the supplied id and the resource’s base.

    Declaration

    Swift

    public class func read(_ id: String, server: FHIRServer, options: FHIRRequestOption = [], callback: @escaping FHIRResourceErrorCallback)

    Parameters

    id

    The id of the resource to read

    server

    The server from which to read

    options

    Options to use when executing this request, if any

    callback

    The callback to execute once done. The callback is NOT guaranteed to be executed on the main thread!

  • Reads the resource from the given path on the given server.

    This method creates a FHIRJSONRequestHandler for a GET request and deserializes the returned JSON into an instance on success.

    Declaration

    Swift

    public class func readFrom(_ path: String, server: FHIRServer, options: FHIRRequestOption = [], callback: @escaping FHIRResourceErrorCallback)

    Parameters

    path

    The relative path on the server from which to read resource data from

    server

    The server to use

    options

    Options to use when executing this request, if any

    callback

    The callback to execute once done. The callback is NOT guaranteed to be executed on the main thread!

  • Create the receiver on the given server.

    This method issues a POST, with the receiver serialized to JSON as the request’s body data, to the FHIR server. If the call succeeds (i.e. does not return an error), the receiver updates its meta properties from the response Location, if available, and the _server property is assigned.

    This method will set the Prefer header to return=minimal, meaning the server may not return the actual resource content created. Use createAndReturn(server:callback:) if you want to make sure that you’re getting the resource back.

    Declaration

    Swift

    public func create(_ server: FHIRServer, callback: @escaping FHIRErrorCallback)

    Parameters

    server

    The server on which to create the resource

    callback

    The callback to execute once done. The callback is NOT guaranteed to be executed on the main thread!

  • Create the receiver on the given server, ensuring that the created resource is returned.

    This method issues a POST, with the receiver serialized to JSON as the request’s body data, to the FHIR server. If the call succeeds (i.e. does not return an error), the receiver updates its properties from the full resource response, and the _server property is assigned.

    This method will set the Prefer header to return=representation, meaning the server should return the actual resource created. If it does not do so, a read call will be issued to ensure the most recent representation is in memory, and then the callback is called. Use create(server:callback:) if you do not need the actual resource back.

    Declaration

    Swift

    func createAndReturn(_ server: FHIRServer, callback: @escaping FHIRErrorCallback)

    Parameters

    server

    The server on which to create the resource

    callback

    The callback to execute once done. The callback is NOT guaranteed to be executed on the main thread!

  • Update the resource’s server representation with its current values.

    This method serializes the instance to JSON and issues a PUT call to the receiver’s _server instance.

    Declaration

    Swift

    public func update(callback: @escaping FHIRErrorCallback)

    Parameters

    callback

    The callback to execute once done. The callback is NOT guaranteed to be executed on the main thread!

  • Deletes the receiver’s representation from its server.

    This method forwards to the delete class method, substituting the receiver’s path and server.

    Declaration

    Swift

    public func delete(callback: @escaping FHIRErrorCallback)
  • Deletes the resource with the given ID from the server.

    This implementation issues a DELETE call against the given path on the given server.

    Declaration

    Swift

    public class func delete(_ path: String, server: FHIRServer, callback: @escaping FHIRErrorCallback)
  • Perform a search against the receiver’s type’s compartment.

    UNFINISHED.

    Declaration

    Swift

    public func search(_ query: Any) -> FHIRSearch
  • Perform a search, wich the given query construct, against the receiver’s compartment.

    Declaration

    Swift

    public class func search(_ query: Any) -> FHIRSearch
  • Inspects meta.tag and returns true if it finds the SUBSETTED tag, which should be present if _summary=true was requested.

    Declaration

    Swift

    public var _isSummary: Bool