Using ResearchKit

      No Comments on Using ResearchKit

In this article we'll go over the main features of ResearchKit on a demo project and we'll get you started using ResearchKit.ResearchKit is a different kind of a framework. It’s used in apps that are conducting medical research. Apple has made this framework completely open source and anyone can contribute to it. It’s available on GitHub if you want to check it out. In this article we’ll go over the main features of ResearchKit on a demo project and we’ll get you started using ResearchKit.

Basic Components

In most medical researches you’ll see three main things. You will read and sign a document that informs you about the research and that contains all sorts of legal stuff. After the legal tidbits you’ll probably fill out a survey and perform some tasks. These are the basic components of medical research that ResearchKit offers to you:

  • Gathering Consent
  • Surveys
  • Active Tasks

You have a few more at your disposal, like navigable tasks (which are similar to a surveys) and charts. But these three are the basic ones that will get you started with ResearchKit.

ResearchKit supports these almost out of the box, all you have to do is provide the custom content (e.g. your questions).

A thing to note about ResearchKit. It’s a framework that will help you conduct your research, but it will not store the data anywhere. Data management is left entirely up to you.

Project Setup

The easiest way to set up ResearchKit is to use cocoapods. If you go through the official documentation you won’t find any mention of cocoapods (or at least I couldn’t find one easily), but ResearchKit is available on cocoapods. Before you jump in and install it, you’ll have to install Git-LFS first. It’s just one terminal command that you need to run and you only need to do it once on your machine. Download the command line extension and run the command in your terminal:

Now you can add the pod to the podfile:

Go ahead and run ‘pod install’. You should be all set ๐Ÿ™‚

Tasks And Steps

Everything in ResearchKit is a task. Tasks can contain one or more steps. And tasks are presented on the screen by a custom tasks view controller. You have a lot of different tasks and steps, but the principle is always the same. Construct your task with some steps and present it to the user.

Let’s start with a simple task, the consent.

Consents

A consent is a document that a test subject has to read and sign. Most of them follow the same document structure with the same sections. Apple has made this really easy to implement and if you implement the document sections in the order Apple has pre set, you will get some fancy animations when transitioning between document sections.

Our consent document will be a simple task that will have two steps. The visual consent step and the consent review step. Before working on these two, let’s make our lives a bit easier and our code a bit cleaner with some simple extensions:

Now we can create our consent document:

If you arrange your document sections in this order you’ll get some nice animations, we’ll show them in a bit. The consent section is a view that will be displayed with the info provided. A thing to note is that in the consent review step the document will be displayed in full. In the visual consent step only the ‘summary’ will be visible on the screen, your users will have to select a link to see the details.

At the end of the document we add a signature, which is also a functionality provided to you out of the box. The last thing that we have to do is create the ordered task with our two steps and present the task using the ‘ORKTaskViewController’.

This is how our consent task looks like in action with the two steps:

 

 

And here you can see that nice animation that we’ve talked about. At the end of the flow, your user will give their name and sign the document. We already mentioned that ResearchKit is not handling the data persistence. So it’s up to you to handle that data.

To handle the data, we have a convenient delegate callback:

You can access all the data for this task, and all the others that we’ll implement, by using the ‘.result’ property of the passed in ORKTaskViewController.

Surveys

Surveys are also very simple and versatile. We’re also going to create a few steps and add them to a task. Just like we did with the consents, we’ll create a few extensions to make our lives a bit easier:

Let’s construct our survey task:

The steps are very simple. The answers are more interesting. If you take a closer look, we have loads of different answer types available. Displayed here in the example are just a few, like your standard multiple choice answer, text answer and not so standard height picker ๐Ÿ™‚

All the steps we’ve created so far are skippable, but you can control this by setting the ‘.optional’ property to false on the steps you create.

Just like with the consent task, the delegate method will get called with the results of the survey and you can save the data where ever you want.

Active Tasks

The tasks we’ve covered so far are pretty simple. They’re just different kinds of forms that the user fills out. Active tasks are a more interactive part of ResearchKit. There’s lots of active tasks your users can perform and they measure a range of things. From measuring hearing and activity to measuring cognitive response and reflexes. In our example we’ll only cover one of them, the well-known tower of Hanoi:

Yes, it’s that simple ๐Ÿ™‚ This is how our task will look like when presented to the user:

Just like with the other tasks, you’ll get the results in the delegate callback. For the tower of Hanoi task you’ll even get the path the user took to solve the puzzle. Pretty neat ๐Ÿ™‚

Conclusion

In this article we’ve covered the basic use of ResearchKit and got you started using it. It’s a very specialized framework that makes it really easy to create apps for medical research. Apart from the standard surveys, you can create active tasks and collect data from your subjects.

One feature we haven’t covered are the graphs and navigable tasks. If we have, this article would have doubled in size, so let’s leave these for some other time ๐Ÿ™‚

You can find the example project on GitLab as well as all the code snippets from this article. As usual… I hope you had some fun and that you’ve learned something new today ๐Ÿ™‚

Have a nice day ๐Ÿ™‚
~D;

More resources

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.