About the data4life API

The following section gives you an overview of the data4life API. Only logged-in users can run queries and perform actions. When a request is made without a valid access token and a refresh token, the SDK throws an unauthorized exception.

Authentication and authorization

This section covers the authorization project features of the SDK.

  • Authentication is the process of verifying who users are.

  • Authorization is the process of verifying what users have access to.

Displaying the login screen

To display the login screen to users.

HCSDKClient.default.presentLogin(on: self, animated: true) { result in
    switch result {
    case .success:
        // Handle result
    case .failure(let error):
        // Handle error
    }
}

Displaying the login screen with custom OAuth 2.0 scopes

Scopes are a mechanism in the OAuth 2.0 protocol to limit an application’s access to a user account. The scope information is displayed to the user in the login screens.

To display the login screen with additional scopes to users.

let scopes = ["example", "scope"]
HCSDKClient.default.presentLogin(on: self, animated: true, scopes: scopes) { result in
    switch result {
    case .success:
        // Handle result
    case .failure(let error):
        // Handle error
    }
}

Using additional parameters for the login

To display the login screen with additional parameters, for example, with the loginCompletion callback.

func presentLogin(on viewController: UIViewController, animated: Bool, scopes: [String]? = nil, presentationCompletion: (() -> Void)? = nil, loginCompletion: @escaping DefaultResultBlock)

Logging out

To log the currently logged-in user out of the current session.

func logout(completion: @escaping DefaultResultBlock)

Checking if a user is logged in

To check if a user is logged in.

func userLoggedIn(_ completion: @escaping DefaultResultBlock)

Receiving updates about the session state

To receive updates about the session state.

func sessionStateDidChange(completion: @escaping (Bool) -> Void)

Handling response threads

All SDK calls accept DispatchQueue as a parameter. The defined queue is used to return results. The main queue is the default queue.

let queue = DispatchQueue.global(qos: .background)
HCSDKClient.default.creteRecord(document, queue: queue) { result in
    // Handle result
}

Managing records

The following sections describes how you perform queries and other actions for documents and records.

Creating a new record

To create a new record, use the createRecord method.

func createRecord<R: FHIRResource>(_ resource: R, completion: @escaping ResultBlock<Record<R>>)

Creating new records

To create several new records, use the createRecords method.

func createRecords<R: FHIRResource>(_ resources: [R], completion: @escaping ResultBlock<BatchResult<Record<R>, R>>)

Fetching a record by its ID

To fetch records for the given ID, use the fetchRecord method with the identifier parameter of the record.

func fetchRecord<R: FHIRResource>(withId identifier: String, completion: @escaping ResultBlock<Record<R>>)

Fetching multiple records with IDs

To fetch one or more records for the given IDs, use the fetchRecords method with the identifiers parameters of the records.

func fetchRecords<R: FHIRResource>(withIds identifiers: [String], completion: @escaping ResultBlock<BatchResult<Record<R>, String>>)

Updating a record

To update a record, use the updateRecord method.

public func updateRecord<R: FHIRResource>(_ resource: R, queue: DispatchQueue = responseQueue, completion: @escaping ResultBlock<Record<R>>)

Updating several records

To update several records, use the updateRecords method.

func updateRecords<R: FHIRResource>(_ resources: [R], completion: @escaping ResultBlock<BatchResult<Record<R>, R>>)

Deleting a record by its ID

To delete a record with its given ID, use the deleteRecord method with the identifier parameter of the record.

func deleteRecord(withId identifier: String, completion: @escaping ResultBlock<Void>)

Deleting multiple records by their IDs

To delete multiple records with their given IDs, use the deleteRecords method with the identifiers parameters of the records.

func deleteRecords(withIds identifiers: [String], completion: @escaping ResultBlock<BatchResult<String, String>>)

Counting records

To count the stored records per record type, use the countRecords method with the given type parameter. If you don’t provide a record type, the client returns the count of all available records.

func countRecords<R: FHIRResource>(withType type: R.Type?, completion: @escaping ResultBlock<Int>)

Managing document references

The DocumentReference resource describes another document. To support discovering and managing documents, references provide metadata about documents. In FHIR, the DocumentReference resource is used to index a document, clinical note, and other binary objects to make them available to a healthcare system.

Downloading all DocumentReference attachments with their data payloads

To download a record with its given ID, use the downloadRecord method and the identifier parameter of the record.

func downloadRecord<R: DocumentReference>(withId identifier: String, completion: @escaping ResultBlock<Record<R>>)

Downloading multiple DocumentReference records and all their attachments with their data payloads

To download one or more records with their given IDs, use the downloadRecords method and the identifiers parameters of the records.

func downloadRecords<R: DocumentReference>(withIds identifiers: [String], completion: @escaping ResultBlock<BatchResult<Record<R>, String>>)

Handling attachments

When downloading an attachment, you can specify which version of the attachment to download – if different options are available. If downloading a medium-size or small-size image, the downloaded attachment ID is a composed identifier of the original attachment and the thumbnail ID, separated by the # character. When the downloadType parameter is not specified or is unavailable, the original-size attachment (full-size version) is downloaded. The SDK automatically generates the medium-size and the small-size versions of attachments during attachment creation for resizable attachments. The following file formats support resizable attachments: PNG, TIFF, and JPEG.

public enum DownloadType {
    case full, medium, small
}

Downloading a single attachment with data payload

To download an attachment including the data payload, use the downloadAttachment method with the parameter of the attachment ID.

func downloadAttachment(withId identifier: String, recordId: String, downloadType: DownloadType = .full, completion: @escaping ResultBlock<Attachment>)

Downloading a list of attachments with data payloads

To download one or more attachments including their data payloads with their given IDs, use the downloadAttachments method with the parameters of the attachment ID.

func downloadAttachments(withIds identifiers: [String], recordId: String, downloadType: DownloadType = .full, completion: @escaping ResultBlock<[Attachment]>)

This website uses cookies - see our privacy policy for more information about cookies and your rights as a user. Click on "accept" to allow the cookie use.
More about this