@ -36,6 +36,8 @@ Doing that, ResearchKit is ready to use.
The first part for develop a application is the visual part, you need to create a visual interface because the participants need a intuitive screen. This repository is not about the interface part, only about the ResearchKit part, therefore, we will skip the visual part, we can only say that it is necessary to place 3 buttons, one for consent, another for IPAQ and another for MMSE.
In this case needs 3 ViewControllers, each one for activity, it is the most easy form to doing and the code it's more easy too.
The visual interface needs to be easy, intuitive, but the design is part of you.
The main screen should be like the next image:
@ -260,6 +262,692 @@ If you push the button, the consent will be open.

Its time for IPAQ and MMSE, These questionnaires, as mentioned in the article, will be digitized so that they can be answered on Apple mobile devices. The first thing to do is to know the different questions that the questionnaire contains in order to digitize it in the many functions that ResearchKit has incorporated. In this case, ORKValuePickerAnswerFormat, ORKTextAnswerFormat, ORKTextChoiceAnswerFormat, and ORKScaleAnswerFormat are used.
Its time for IPAQ and MMSE, These questionnaires, as mentioned in the article, will be digitized so that they can be answered on Apple mobile devices. The first thing to do is to know the different questions that the questionnaire contains in order to digitize it in the many functions that ResearchKit has incorporated. In this case, ORKValuePickerAnswerFormat, ORKTextAnswerFormat, ORKNumericAnswerFormat, ORKTextChoiceAnswerFormat, and ORKScaleAnswerFormat are used.
For doing a digital questions it is necessary to check the type of physical question, for example:
IPAQ have 7 Questions and 5 espaces for only read (sentences), so the first part is the title, the title says: "INTERNATIONAL PHYSICAL ACTIVITY QUESTIONNAIRE (IPAQ)", its only a sentence so in xcode need the function ORKInstructionStep as see:
```
// Define the introduction step
let ipaqInfo = ORKInstructionStep(identifier: "IPAQInfo")
ipaqInfo.detailText = "International Physical Activity Questionnaire\n\nWe will ask you 7 questions related to your physical activity. Please answer as honestly as possible."
```
This function have one identifier, a title, one iconImage and a detailText, so the sentence looks like.

you can omit one part, but with all the features it's more complete, and for all the sentences it's the same, for both questionnaires.
Now, for questions, let's see the question one of IPAQ, it said: "1. During the last 7 days, on how many days did you do vigorous physical activities like heavy lifting, digging, aerobics, or fast bicycling?", so the firt step is decide in one window all the questions or one for window, in this case it is one for window, so the main function it is ORKQuestionStep, and now, what type of answer exist various types, like picker, text, text choices, scale, among others, it depends our question, for this case, is picker, so the function should be like:
````
let vigorousDaysChoices = [
ORKTextChoice(text: "None", value: "None" as NSString),
ORKTextChoice(text: "1 day", value: "1 day" as NSString),
ORKTextChoice(text: "2 days", value: "2 days" as NSString),
ORKTextChoice(text: "3 days", value: "3 days" as NSString),
ORKTextChoice(text: "4 days", value: "4 days" as NSString),
ORKTextChoice(text: "5 days", value: "5 days" as NSString),
ORKTextChoice(text: "6 days", value: "6 days" as NSString),
ORKTextChoice(text: "7 days", value: "7 days" as NSString)
]
let vigorousDaysStep = ORKQuestionStep(
identifier: "VigorousDays",
title: "Question 1",
question: "In the last 7 days, how many days did you perform vigorous physical activities such as heavy lifting, digging, aerobics, or fast cycling?",
the first part is the choices as the participant need to see, second part is the identifier, title, the question and the type of answer, and this type of question its the semae only change the choices.

Other type of questions is Numeric, Text, scale, but each one have its structure, but follow kind of the same for to declarate.
The next image show different types of questions in MMSE, numeric, scale, image, etc.

For doing a IPAQ, as metioned before we need 7 questions and 5 sentences, so the code, is like:
```
import Foundation
import ResearchKit
class IPAQManager {
static let shared = IPAQManager()
func createIPAQ() -> ORKTask {
// Define the introduction step
let ipaqInfo = ORKInstructionStep(identifier: "IPAQInfo")
ipaqInfo.detailText = "International Physical Activity Questionnaire\n\nWe will ask you 7 questions related to your physical activity. Please answer as honestly as possible."
// Section 1: Vigorous Activities
let sec1 = ORKInstructionStep(identifier: "Sec1")
sec1.title = "Section 1"
sec1.detailText = "Think about all the VIGOROUS activities you did in the last 7 days. Vigorous physical activities are those that require intense physical effort and make you breathe much harder than usual. Consider only those activities that lasted at least 10 consecutive minutes."
let vigorousDaysChoices = [
ORKTextChoice(text: "None", value: "None" as NSString),
ORKTextChoice(text: "1 day", value: "1 day" as NSString),
ORKTextChoice(text: "2 days", value: "2 days" as NSString),
ORKTextChoice(text: "3 days", value: "3 days" as NSString),
ORKTextChoice(text: "4 days", value: "4 days" as NSString),
ORKTextChoice(text: "5 days", value: "5 days" as NSString),
ORKTextChoice(text: "6 days", value: "6 days" as NSString),
ORKTextChoice(text: "7 days", value: "7 days" as NSString)
]
let vigorousDaysStep = ORKQuestionStep(
identifier: "VigorousDays",
title: "Question 1",
question: "In the last 7 days, how many days did you perform vigorous physical activities such as heavy lifting, digging, aerobics, or fast cycling?",
sec2.detailText = "Think about all the MODERATE activities you did in the last 7 days. Moderate activities require moderate physical effort and make you breathe somewhat harder than usual. Consider only those activities that lasted at least 10 consecutive minutes."
let moderateDaysChoices = [
ORKTextChoice(text: "None", value: "None" as NSString),
ORKTextChoice(text: "1 day", value: "1 day" as NSString),
ORKTextChoice(text: "2 days", value: "2 days" as NSString),
ORKTextChoice(text: "3 days", value: "3 days" as NSString),
ORKTextChoice(text: "4 days", value: "4 days" as NSString),
ORKTextChoice(text: "5 days", value: "5 days" as NSString),
ORKTextChoice(text: "6 days", value: "6 days" as NSString),
ORKTextChoice(text: "7 days", value: "7 days" as NSString)
]
let moderateDaysStep = ORKQuestionStep(
identifier: "ModerateDays",
title: "Question 3",
question: "In the last 7 days, how many days did you perform moderate physical activities such as carrying light loads, cycling at a regular pace, or playing doubles tennis? Do not include walking.",
sec3.detailText = "Think about the time you spent WALKING in the last 7 days. This includes walking at work or home, walking to travel from place to place, or any other walking you might do solely for recreation, sport, exercise, or leisure."
let walkingDaysChoices = [
ORKTextChoice(text: "None", value: "None" as NSString),
ORKTextChoice(text: "1 day", value: "1 day" as NSString),
ORKTextChoice(text: "2 days", value: "2 days" as NSString),
ORKTextChoice(text: "3 days", value: "3 days" as NSString),
ORKTextChoice(text: "4 days", value: "4 days" as NSString),
ORKTextChoice(text: "5 days", value: "5 days" as NSString),
ORKTextChoice(text: "6 days", value: "6 days" as NSString),
ORKTextChoice(text: "7 days", value: "7 days" as NSString)
]
let walkingDaysStep = ORKQuestionStep(
identifier: "WalkingDays",
title: "Question 5",
question: "In the last 7 days, how many days did you walk for at least 10 consecutive minutes?",
sec4.detailText = "The last question is about the time you spent SITTING during the weekdays of the last 7 days. This includes time spent at work, at home, while studying, and during leisure time. It includes time spent sitting at a desk, visiting friends, reading, traveling by car, bus, train, or watching television."
let sittingStep = ORKQuestionStep(
identifier: "SittingTime",
title: "Question 7",
question: "On a typical weekday, how much time (in minutes) did you spend sitting?",
mmseInfo.detailText = "Mini-Mental State Examination\n\nWe will ask you some questions related to your cognition. Please answer as honestly as possible."
// Section 1
let sec1 = ORKInstructionStep(identifier: "Sec1")
sec1.title = "Orientation in Time and Space"
sec1.detailText = "Without checking anything on your phone or any other device, please answer the following questions."
// Question 1
let MMSE1choices = [
ORKTextChoice(text: "Monday", value: "Monday" as NSString),
ORKTextChoice(text: "Tuesday", value: "Tuesday" as NSString),
ORKTextChoice(text: "Wednesday", value: "Wednesday" as NSString),
ORKTextChoice(text: "Thursday", value: "Thursday" as NSString),
ORKTextChoice(text: "Friday", value: "Friday" as NSString),
ORKTextChoice(text: "Saturday", value: "Saturday" as NSString),
ORKTextChoice(text: "Sunday", value: "Sunday" as NSString),
ORKTextChoice(text: "I don’t know", value: "I don’t know" as NSString)
let MMSE7AnswerFormat = ORKTextAnswerFormat(maximumLength: 50)
MMSE7AnswerFormat.multipleLines = true
let MMSE7QuestionStep = ORKQuestionStep(
identifier: "07Location",
title: "Question 7",
question: "Where are you right now? (e.g., Home, Work, Park, School)",
answer: MMSE7AnswerFormat
)
MMSE7QuestionStep.isOptional = false
// Question 8
let MMSE8AnswerFormat = ORKTextAnswerFormat(maximumLength: 50)
MMSE8AnswerFormat.multipleLines = true
let MMSE8QuestionStep = ORKQuestionStep(
identifier: "08City",
title: "Question 8",
question: "What city are you in?",
answer: MMSE8AnswerFormat
)
MMSE8QuestionStep.isOptional = false
// Question 9
let MMSE9AnswerFormat = ORKTextAnswerFormat(maximumLength: 50)
MMSE9AnswerFormat.multipleLines = true
let MMSE9QuestionStep = ORKQuestionStep(
identifier: "09State",
title: "Question 9",
question: "What state are you in?",
answer: MMSE9AnswerFormat
)
MMSE9QuestionStep.isOptional = false
// Question 10
let MMSE10QuestionStepTitle = "Question 10"
let MMSE10AnswerFormat = ORKTextAnswerFormat(maximumLength: 50)
MMSE10AnswerFormat.multipleLines = true
let MMSE10QuestionStep = ORKQuestionStep(identifier: "10Country", title: MMSE10QuestionStepTitle, question: "Which country are you in?", answer: MMSE10AnswerFormat)
sec2.detailText = "Without reviewing anything on your phone or any other device, answer the following questions"
// Question 11
let words1 = ORKInstructionStep(identifier: "words1")
words1.title = "Reading"
words1.detailText = "Read the following 3 words and click the (Next) button \n\nHORSE\n\nWEIGHT\n\nAPPLE"
// Word 1
let MMSE11QuestionStepTitle1 = "Question 11"
let MMSE11QuestionStepAnswer1 = ORKTextAnswerFormat(maximumLength: 30)
MMSE11QuestionStepAnswer1.multipleLines = false
let MMSE11QuestionStep1 = ORKQuestionStep(identifier: "11word1", title: MMSE11QuestionStepTitle1, question: "What was the first word?", answer: MMSE11QuestionStepAnswer1)
MMSE11QuestionStep1.isOptional = false
// Word 2
let MMSE11QuestionStepTitle2 = "Question 11"
let MMSE11QuestionStepAnswer2 = ORKTextAnswerFormat(maximumLength: 30)
MMSE11QuestionStepAnswer2.multipleLines = false
let MMSE11QuestionStep2 = ORKQuestionStep(identifier: "11word2", title: MMSE11QuestionStepTitle2, question: "What was the second word?", answer: MMSE11QuestionStepAnswer2)
MMSE11QuestionStep2.isOptional = false
// Word 3
let MMSE11QuestionStepTitle3 = "Question 11"
let MMSE11QuestionStepAnswer3 = ORKTextAnswerFormat(maximumLength: 30)
MMSE11QuestionStepAnswer3.multipleLines = false
let MMSE11QuestionStep3 = ORKQuestionStep(identifier: "11word3", title: MMSE11QuestionStepTitle3, question: "What was the third word?", answer: MMSE11QuestionStepAnswer3)
sec4.detailText = "Remember the 3 words we mentioned earlier, write them below"
// Question 13
// Word 1
let MMSE13QuestionStepTitle1 = "Question 13"
let MMSE13QuestionStepAnswer1 = ORKTextAnswerFormat(maximumLength: 30)
MMSE13QuestionStepAnswer1.multipleLines = false
let MMSE13QuestionStep1 = ORKQuestionStep(identifier: "13word1", title: MMSE13QuestionStepTitle1, question: "What was the first word?", answer: MMSE13QuestionStepAnswer1)
MMSE13QuestionStep1.isOptional = false
// Word 2
let MMSE13QuestionStepTitle2 = "Question 13"
let MMSE13QuestionStepAnswer2 = ORKTextAnswerFormat(maximumLength: 30)
MMSE13QuestionStepAnswer2.multipleLines = false
let MMSE13QuestionStep2 = ORKQuestionStep(identifier: "13word2", title: MMSE13QuestionStepTitle2, question: "What was the second word?", answer: MMSE13QuestionStepAnswer2)
MMSE13QuestionStep2.isOptional = false
// Word 3
let MMSE13QuestionStepTitle3 = "Question 13"
let MMSE13QuestionStepAnswer3 = ORKTextAnswerFormat(maximumLength: 30)
MMSE13QuestionStepAnswer3.multipleLines = false
let MMSE13QuestionStep3 = ORKQuestionStep(identifier: "13word3", title: MMSE13QuestionStepTitle3, question: "What was the third word?", answer: MMSE13QuestionStepAnswer3)
let MMSE15QuestionStepAnswer1 = ORKTextAnswerFormat(maximumLength: 30)
MMSE15QuestionStepAnswer1.multipleLines = false
let MMSE15QuestionStep1 = ORKQuestionStep(identifier: "15copy", title: MMSE15QuestionStepTitle1, question: "Repeat the phrase: No ifs, ands, or buts", answer: MMSE15QuestionStepAnswer1)
let ind16 = ORKInstructionStep(identifier: "ind16")
ind16.title = "Question 16"
ind16.detailText = "I will give you some instructions. Please follow them in the order I tell you: \n\n 1. Select the number 8 \n\n 2. Select all the words that start with P \n\n 3. Write the word 'hair'"
And the same form like consent, questionnaires needs to asign a button for trigger a window of formulaire. So the button need to drag to the ViewController, and put the next code:
IPAQ:
```
import UIKit
import ResearchKitUI
import ResearchKit
class IPAQViewController: UIViewController, ORKTaskViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func ipaqButton(_ sender: UIButton) {
let task = IPAQManager.shared.createIPAQ()
let taskViewController = ORKTaskViewController(task: task, taskRun: nil)