Cortex iOS
Last updated
Was this helpful?
Last updated
Was this helpful?
Welcome to the iOS Client SDK for . This framework provides a wrapper for the as well as several helper tools to directly integrate those features to your iOS application.
For basic integration and initialization steps, check the README.md file in the SDK repository.
Check out the for a few examples on how to get some specific things done with the Medable SDK. This tutorial shows one way to quickly get started using a new or existing Swift iOS project. Before you begin, you should have generated an API key. If not, .
In Xcode, select File > New Project...
``
Select Single View Application
and click next.
Enter your project details. For this tutorial, we'll call the app "NewHealthCo"
Integrate the SDK following the integration instructions from the README.md file in the SDK repository.
Add the Medable start function to your AppDelegate and set the logger level to Debug so you can see more detailed network responses in the consoleSwift
Then build and run the app
You've successfully connected to your Medable HIPAA compliant backend. You're ready to collect PHI.
However, the Cortex iOS SDK makes this quite simple with pagination helpers.
The following examples illustrate how to paginate through a list of c_prescription
instances.
This is how an instance of MDPaginationHelper
is created and initialized:
Objective-C
If you use the delegate approach, don't forget to conform to the MDPaginationHelperDelegate
protocol,
Objective-C
and implement the delegate methods to get the results:
Objective-C
Both delegate methods are marked as optional. If you don't implement the didLoadAllResults
, and loadAllPages
is called, you'll get all the results in the first method, together with the results from calling loadNextPage
. So, if you need to get the results of both calls separately, implement both.
📘NoteThe delegate approach and the results callback approach can be used simultaneously.
📘NoteYou'll find documentation about
cacheResults
andinverseOrder
, as well as for some other pagination options (e.g. list property pagination, or paging using a field other than_id
), in theMDPaginationHelper.h
header file.
If you don't want to manage the instances of MDPaginationHelper
, you can leave that to the MDPaginationManager
. Just create the instances using the MDPaginationManager
class. Let's achieve the same as before; the only difference relies in how you create the instance:
Objective-C
Later on, that paginator's instance can be retrieved by doing this:
Objective-C
If you don't need to retrieve the pagination helpers by identifier, but you still want the manager to take care of storing them; there is a function to generate random identifiers:
Objective-C
Objective-C
Objective-C
Objective-C
Now, we want to create instances of those objects using Cortex from the client side. Objective-C
Now, we want to edit an existing instance of that type of object using Cortex from the client side. Objective-C
Now, we want to list existing instances of that type of object using Cortex from the client side.
📘Note
Objective-C
📘Note
Objective-C
Using a download path: Objective-C
In the response of the first step, that is, in the callback of whichever method was used in step 1 --create or update; is when the actual file upload takes place using upload information sent by the Cortex API.
📘File Uploads
The Medable Cortex iOS SDK features an upload operations manager, that takes care of the following tasks:
Keep an up to date list of ongoing upload operations.
Keep an up to date list of recently successfully completed operations.
Keep an up to date list of recently failed operations.
Keep a progress value (percentage expressed in the 0..1 range) for each operation.
Emit notifications for every change in the manager: - Newly added upload. - Upload completed or failed. - Upload operation progress changed.
Every time there is a significant event in the upload operations manager, it emits a notification using the string kOperationProgressChangedNotification
, which is declared in MDUploadOperations.h
:
Objective-C
As expressed in the comment, this notification is emitted for every change in the upload operations manager.
How to listen the notifications: Objective-C
How to handle the notifications: Objective-C
Within the notification, depending on the event, two different objects could be sent:
A MDUploadOperation
object is delivered inside the NSNotification.object
property if it is notifying about upload progress. See below for more info.
A MDUploadOperations
object is delivered inside the NSNotification.object
property if it is notifying about the following events:
A new MDUploadOperation
was added to the queue.
A MDUploadOperation
succeeded.
A MDUploadOperation
failed.
A MDUploadOperation
was removed from completed/failed.
Flushing operations. Flushing ongoing, succeeded and failed queues.
The state of all upload operations can be queried from the MDUploadOperations
class by checking the the following class methods:
Objective-C
An ongoing operation is an upload task that is still uploading, i.e. it hasn't failed and it hasn't completed the upload yet.
Recently completed operations are short lived. After completion, the operation objects will stay in this list for at least 10 seconds. After this time, they'll be removed from the list.
Recently failed operations live a little longer. After failing, the operation objects will stay in this list for at least 1 minute. Again, after this time, they are be removed from the list.
Each operation is an instance of class MDUploadOperation
. Here are some interesting features they provide:
Progress: Use the progressNumber
attribute to determine the progress percentage (measured in the 0..1 range) of the upload operation.
Data Task: Use the operation
property, of class NSURLSessionDataTask
for the data task that the operation is using. You may call cancel
on this object to cancel the upload.
File Name: If you are uploading several things at once, the fileName
property contains the name of the file being uploaded.
NSProgress: Apple's NSProgress
class allows for fine grain progress reporting, the operationProgress
property returns the associated NSProgress
object with this upload operations.
To cancel an ongoing operation, just call cancel
on its data task, which you get from calling operation
on the MDUploadOperation
instance.
Here is code to cancel an ongoing operation: Objective-C
Any operation that has failed can be retried, it need not be in the failed operations set, but beware that the upload tokens used will eventually expire.
Here is code to retry an operation currently in the failed set: Objective-C
If you're upgrading from a previous version to 1.10 or newer, you will need to make the following changes:
Remove the Medable framework from the Xcode project.
Replace any instance of Medable/Medable.h
with MedableCortex/MedableCortex.h
The app shows a blank screen but you should see proper console outputs
When working with lists, it is often important to page through results. The recommended approaches to working with lists through the API are outlined .
For information on how to create custom cortex objects such as the example c_prescription
object, see .
For more information on working with your Cortex Objects in iOS, see .
Let's suppose we are using a custom Prescription
object definition that was created using the guide.
Let's suppose we are using a custom Prescription
object definition that was created using the guide.
Let's suppose we are using a custom Prescription
object definition that was created using the guide.
For paginated listing take a look the guide.
If you need to use a custom class instead of MDObjectInstance
and want Cortex to return instances of your class instead, follow the guide.
s can be downloaded using one of two methods.
Or using a MDFacet
of the .
Objective-C
File uploads are a two step process as described in the documentation.
In the first step, a file property name and the file name is sent to the server. This could happen when and also when .
For this sample, let's suppose we are creating an instance of a c_anObject
object type that, has a c_image
property. We want to upload an image to the content
facet of that .
Objective-C
For a deeper management of file uploads take a look at the documentation.
Following the , update to the latest version.