diff --git a/surveys-example.xcodeproj.zip b/surveys-example.xcodeproj.zip new file mode 100644 index 0000000..9f19740 Binary files /dev/null and b/surveys-example.xcodeproj.zip differ diff --git a/surveys-example/AppDelegate.swift b/surveys-example/AppDelegate.swift new file mode 100644 index 0000000..6122a33 --- /dev/null +++ b/surveys-example/AppDelegate.swift @@ -0,0 +1,36 @@ +// +// AppDelegate.swift +// surveys-example +// +// Created by Juan David López Regalado on 12/06/24. +// + +import UIKit + +@main +class AppDelegate: UIResponder, UIApplicationDelegate { + + + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + return true + } + + // MARK: UISceneSession Lifecycle + + func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { + // Called when a new scene session is being created. + // Use this method to select a configuration to create the new scene with. + return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) + } + + func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { + // Called when the user discards a scene session. + // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. + // Use this method to release any resources that were specific to the discarded scenes, as they will not return. + } + + +} + diff --git a/surveys-example/Assets.xcassets/AccentColor.colorset/Contents.json b/surveys-example/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 0000000..eb87897 --- /dev/null +++ b/surveys-example/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/surveys-example/Assets.xcassets/AppIcon.appiconset/Contents.json b/surveys-example/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..13613e3 --- /dev/null +++ b/surveys-example/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,13 @@ +{ + "images" : [ + { + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/surveys-example/Assets.xcassets/Contents.json b/surveys-example/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/surveys-example/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/surveys-example/Assets.xcassets/pcie-logo.imageset/Contents.json b/surveys-example/Assets.xcassets/pcie-logo.imageset/Contents.json new file mode 100644 index 0000000..00696bc --- /dev/null +++ b/surveys-example/Assets.xcassets/pcie-logo.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "pcie-logo.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/surveys-example/Assets.xcassets/pcie-logo.imageset/pcie-logo.png b/surveys-example/Assets.xcassets/pcie-logo.imageset/pcie-logo.png new file mode 100644 index 0000000..f8d3d9b Binary files /dev/null and b/surveys-example/Assets.xcassets/pcie-logo.imageset/pcie-logo.png differ diff --git a/surveys-example/Base.lproj/LaunchScreen.storyboard b/surveys-example/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..865e932 --- /dev/null +++ b/surveys-example/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/surveys-example/Base.lproj/Main.storyboard b/surveys-example/Base.lproj/Main.storyboard new file mode 100644 index 0000000..173e418 --- /dev/null +++ b/surveys-example/Base.lproj/Main.storyboard @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/surveys-example/ConsentManager.swift b/surveys-example/ConsentManager.swift new file mode 100644 index 0000000..7734296 --- /dev/null +++ b/surveys-example/ConsentManager.swift @@ -0,0 +1,79 @@ +// +// ConsentManager.swift +// surveys-example +// +// Created by Juan David López Regalado on 12/06/24. +// + +import Foundation +import UIKit +import ResearchKit + +class ConsentManager{ + static let shared = ConsentManager() + + func createConsentTask() -> ORKTask{ + + // Pagina de Welcome + let welcomeStep = ORKInstructionStep(identifier: "consentWelcomeInstructionStep") + welcomeStep.title = "Welcome!" + welcomeStep.iconImage = UIImage(systemName: "hand.wave") + welcomeStep.detailText = "Thank you for being part of the biomarker project aimed at determining the level of sedentary lifestyle. However, before accepting, please read the next part." // explain the consent + + let sign = ORKInstructionStep(identifier: "signAccept") + sign.title = "Please Sign if you Accept" + + + // Pagina del before you join + let beforeYouJoin = ORKInstructionStep(identifier: "informedConsentInstructionStep") + beforeYouJoin.iconImage = UIImage(systemName: "doc.text.magnifyinglass") + beforeYouJoin.title = "Before You Join" + + let sharingHealthDataBodyItem = ORKBodyItem(text: "The study will ask you to share some of your Health data.", + detailText: nil, + image: UIImage(systemName: "heart.fill"), + learnMoreItem: nil, + bodyItemStyle: .image) + + let completingTasksBodyItem = ORKBodyItem(text: "You will be asked to complete various tasks over the duration of the study.", + detailText: nil, + image: UIImage(systemName: "checkmark.circle.fill"), + learnMoreItem: nil, + bodyItemStyle: .image) + + let signatureBodyItem = ORKBodyItem(text: "Before joining, we will ask you to sign an informed consent document.", + detailText: nil, + image: UIImage(systemName: "signature"), + learnMoreItem: nil, + bodyItemStyle: .image) + + let secureDataBodyItem = ORKBodyItem(text: "Your data is kept private and secure.", + detailText: nil, + image: UIImage(systemName: "lock.fill"), + learnMoreItem: nil, + bodyItemStyle: .image) + + beforeYouJoin.bodyItems = [ + sharingHealthDataBodyItem, + completingTasksBodyItem, + signatureBodyItem, + secureDataBodyItem + ] + + + let instructionSteps = [sign] + + let webViewStep = ORKWebViewStep(identifier: "WebViewStepIdentifier", instructionSteps:instructionSteps) + webViewStep.showSignatureAfterContent = true + + + let task = ORKOrderedTask(identifier: "ConsentTask", steps: [welcomeStep, beforeYouJoin, webViewStep, /*other steps*/]) + + return task + + + } + + + +} diff --git a/surveys-example/Info.plist b/surveys-example/Info.plist new file mode 100644 index 0000000..dd3c9af --- /dev/null +++ b/surveys-example/Info.plist @@ -0,0 +1,25 @@ + + + + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + $(PRODUCT_MODULE_NAME).SceneDelegate + UISceneStoryboardFile + Main + + + + + + diff --git a/surveys-example/SceneDelegate.swift b/surveys-example/SceneDelegate.swift new file mode 100644 index 0000000..4140907 --- /dev/null +++ b/surveys-example/SceneDelegate.swift @@ -0,0 +1,52 @@ +// +// SceneDelegate.swift +// surveys-example +// +// Created by Juan David López Regalado on 12/06/24. +// + +import UIKit + +class SceneDelegate: UIResponder, UIWindowSceneDelegate { + + var window: UIWindow? + + + func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { + // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. + // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. + // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). + guard let _ = (scene as? UIWindowScene) else { return } + } + + func sceneDidDisconnect(_ scene: UIScene) { + // Called as the scene is being released by the system. + // This occurs shortly after the scene enters the background, or when its session is discarded. + // Release any resources associated with this scene that can be re-created the next time the scene connects. + // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead). + } + + func sceneDidBecomeActive(_ scene: UIScene) { + // Called when the scene has moved from an inactive state to an active state. + // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. + } + + func sceneWillResignActive(_ scene: UIScene) { + // Called when the scene will move from an active state to an inactive state. + // This may occur due to temporary interruptions (ex. an incoming phone call). + } + + func sceneWillEnterForeground(_ scene: UIScene) { + // Called as the scene transitions from the background to the foreground. + // Use this method to undo the changes made on entering the background. + } + + func sceneDidEnterBackground(_ scene: UIScene) { + // Called as the scene transitions from the foreground to the background. + // Use this method to save data, release shared resources, and store enough scene-specific state information + // to restore the scene back to its current state. + } + + +} + diff --git a/surveys-example/SurveyManager.swift b/surveys-example/SurveyManager.swift new file mode 100644 index 0000000..2ad4db3 --- /dev/null +++ b/surveys-example/SurveyManager.swift @@ -0,0 +1,417 @@ +// +// Tasks.swift +// surveys-example +// +// Created by Juan David López Regalado on 14/06/24. +// +import Foundation +import ResearchKit + +class SurveyManager { + static let shared = SurveyManager() + + func createSurveyTask() -> ORKTask { + + // Agradecimiento y explicaciojn + let thankUJoin = ORKInstructionStep(identifier: "thankUJoin") + thankUJoin.title = "Thank You!" + thankUJoin.iconImage = UIImage(systemName: "heart.fill") + thankUJoin.detailText = "Thanks For Join Us, I Would Appreciate It If You Answered The Next Questions as Honestly as Possible, remember That Your Data is Private, it will not be Shared with Anyone Else and Will Only be Used for the Proposed Study." + +// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- + // Ficha de identificacion + + let personalInfoStepTitle = "Personal Information" + let personalInfoStep = ORKInstructionStep(identifier: "personalInfoStep") + personalInfoStep.title = personalInfoStepTitle + personalInfoStep.text = "Here you will find questions about your personal data" + personalInfoStep.image = UIImage(systemName: "person.fill") + + + // Nombre + let textQuestionStepTitle = "Name" + let textAnswerFormat = ORKTextAnswerFormat(maximumLength: 30) + textAnswerFormat.multipleLines = false + let textQuestionStep = ORKQuestionStep(identifier: "textName", title: textQuestionStepTitle, question: "What is your name?", answer: textAnswerFormat) + + // Sexo + let multiGenderChoice = "Sex" + let gendChoices = [ + ORKTextChoice(text: "Male", value: "male" as NSString), + ORKTextChoice(text: "Female", value: "female" as NSString), + ORKTextChoice(text: "I prefer not to say", value: "Inf" as NSString)] + + let genderChoiceFormat = ORKTextChoiceAnswerFormat(style: .singleChoice, textChoices: gendChoices) + let multiGenderQuestionStep = ORKQuestionStep(identifier: "multiGenderQuestionStep", title: multiGenderChoice,question: "What is your Sex?", answer: genderChoiceFormat) + + // Fecha de nacimiento + let dobStepTitle = "Date of Birth" + let dobAnswerFormat = ORKDateAnswerFormat(style: .date) + let dobStep = ORKQuestionStep(identifier: "dobStep", title: dobStepTitle, question: "When were you born?", answer: dobAnswerFormat) + + + // Peso + let weighQuestion = ORKFormItem(sectionTitle: "What is your weight?") + + let weightQuestionFormItem = ORKFormItem(identifier: "weightQuestionForm", text: nil, answerFormat: ORKAnswerFormat.weightAnswerFormat()) + weightQuestionFormItem.placeholder = "Tap here" + + let weighForm = ORKFormStep(identifier: "WeightQuestionIde", title: "Weigh", text: " ") + weighForm.formItems = [weighQuestion, weightQuestionFormItem] + + // Estatura + let heightQuestion = ORKFormItem(sectionTitle: "What is your height?") + + let heightQuestionFormItem = ORKFormItem(identifier: "weightQuestionForm", text: nil, answerFormat: ORKAnswerFormat.heightAnswerFormat()) + heightQuestionFormItem.placeholder = "Tap here" + + let heightForm = ORKFormStep(identifier: "HeightQuestionIde", title: "Height", text: " ") + heightForm.formItems = [heightQuestion, heightQuestionFormItem] + + // Residencia + let residenceChoice = "Reside" + let residenceChoices = [ + ORKTextChoice(text: "Urban", value: "urban" as NSString), + ORKTextChoice(text: "Sub-urban", value: "suburban" as NSString), + ORKTextChoice(text: "Rural", value: "Rural" as NSString)] + + let residenceChoiceFormat = ORKTextChoiceAnswerFormat(style: .singleChoice, textChoices: residenceChoices) + let residenceQuestionStep = ORKQuestionStep(identifier: "residenceStep", title: residenceChoice,question: "Where do you Reside?", answer: residenceChoiceFormat) + + + // Pregunta de ocupación + let occupationQuestionTitle = "Occupation" + let occupationChoices = [ + ORKTextChoice(text: "Student", value: "student" as NSString), + ORKTextChoice(text: "Employed", value: "employed" as NSString), + ORKTextChoice(text: "Self-Employed", value: "self_employed" as NSString), + ORKTextChoice(text: "Unemployed", value: "unemployed" as NSString), + ORKTextChoice(text: "Retired", value: "retired" as NSString), + ORKTextChoice(text: "Homemaker", value: "homemaker" as NSString), + ORKTextChoice(text: "Other", value: "other" as NSString) + ] + + let occupationChoiceFormat = ORKValuePickerAnswerFormat(textChoices: occupationChoices) + let occupationQuestionStep = ORKQuestionStep(identifier: "occupationQuestionStep", title: occupationQuestionTitle, question: "What is your occupation?", answer: occupationChoiceFormat) + + // Pregunta adicional para especificar detalles de ocupación + let specifyOccupationDetailsTitle = "Please specify your occupation:" + let specifyOccupationAnswerFormat = ORKTextAnswerFormat(maximumLength: 100) + specifyOccupationAnswerFormat.multipleLines = true // Permitir múltiples líneas para detalles extensos + let specifyOccupationDetailsStep = ORKQuestionStep(identifier: "specifyOccupationDetailsStep", title: specifyOccupationDetailsTitle, question: "Please specify your occupation:", answer: specifyOccupationAnswerFormat) + + // Añadir la pregunta adicional después de la pregunta de ocupación + let occupationFormStep = ORKFormStep(identifier: "OccupationFormStep", title: "Occupation", text: "Select your occupation and specify details if necessary.") + occupationFormStep.formItems = [ + ORKFormItem(identifier: "OccupationFormItem", text: nil, answerFormat: occupationChoiceFormat), + ORKFormItem(identifier: "SpecifyOccupationDetailsFormItem", text: nil, answerFormat: specifyOccupationAnswerFormat) + ] + + +//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=- + + // Heredo Familiares + + let hereditaryInfoStepTitle = "Hereditary Family History" + let hereditaryInfoStep = ORKInstructionStep(identifier: "hereditaryInfoStep") + hereditaryInfoStep.title = hereditaryInfoStepTitle + hereditaryInfoStep.text = "Here you will find questions about your family, and their diseases" + hereditaryInfoStep.image = UIImage(systemName: "person.3.fill") + + // Patologías hereditarias + let patologyChoice = "Pathologies" + let patologyChoices = [ + ORKTextChoice(text: "Diabetes", value: "diabetes" as NSString), + ORKTextChoice(text: "Heart Disease", value: "heartDisease" as NSString), + ORKTextChoice(text: "Hypertension", value: "hypertension" as NSString), + ORKTextChoice(text: "Cancer", value: "cancer" as NSString), + ORKTextChoice(text: "Asthma", value: "asthma" as NSString)] + + let patologyChoiceFormat = ORKTextChoiceAnswerFormat(style: .multipleChoice, textChoices: patologyChoices) + let patologyQuestionStep = ORKQuestionStep(identifier: "patologyStep", title: patologyChoice, question: "Select only the pathologies that your close relatives such as father, mother, grandfather or grandmother have or had.", answer: patologyChoiceFormat) + + + // Patologías mentales hereditarias + let mentalPatologyChoice = "Mental Pathologies" + let mentalPatologyChoices = [ + ORKTextChoice(text: "Bipolarity", value: "bipolarity" as NSString), + ORKTextChoice(text: "Autism", value: "autism" as NSString), + ORKTextChoice(text: "Depression", value: "depression" as NSString), + ORKTextChoice(text: "ADHD", value: "adhd" as NSString), + ORKTextChoice(text: "Anxiety", value: "anxiety" as NSString)] + + let mentalPatologyChoiceFormat = ORKTextChoiceAnswerFormat(style: .multipleChoice, textChoices: mentalPatologyChoices) + let mentalPatologyQuestionStep = ORKQuestionStep(identifier: "mentalPatologyStep", title: mentalPatologyChoice, question: "Select only the mental pathologies that your close relatives such as father, mother, grandfather or grandmother have or had.", answer: mentalPatologyChoiceFormat) + + +//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- + + // Antecedentes personales patológicos + + let persInfoStepTitle = "Pathological personal history" + let persInfoStep = ORKInstructionStep(identifier: "persInfoStep") + persInfoStep.title = persInfoStepTitle + persInfoStep.text = "In this part you will find questions about the diseases you suffered or suffer from." + persInfoStep.image = UIImage(systemName: "person.crop.circle") + + // Enfermedades propias + let diseasesChoice = "Diseases" + let diseasesChoices = [ + ORKTextChoice(text: "Diabetes", value: "diabetes" as NSString), + ORKTextChoice(text: "Heart Disease", value: "heartDisease" as NSString), + ORKTextChoice(text: "Hypertension", value: "hypertension" as NSString), + ORKTextChoice(text: "Cancer", value: "cancer" as NSString), + ORKTextChoice(text: "Asthma", value: "asthma" as NSString), + ORKTextChoice(text: "Hepatitis", value: "hepatitis" as NSString), + ORKTextChoice(text: "Covid", value: "covid" as NSString), + ORKTextChoice(text: "Tuberculosis", value: "tuberculosis" as NSString), + ORKTextChoice(text: "AIDS", value: "aids" as NSString), + ORKTextChoice(text: "Bipolarity", value: "bipolarity" as NSString), + ORKTextChoice(text: "Autism", value: "autism" as NSString), + ORKTextChoice(text: "Depression", value: "depression" as NSString), + ORKTextChoice(text: "ADHD", value: "adhd" as NSString), + ORKTextChoice(text: "Anxiety", value: "anxiety" as NSString)] + + let diseasesChoiceFormat = ORKTextChoiceAnswerFormat(style: .multipleChoice, textChoices: diseasesChoices) + let diseasesQuestionStep = ORKQuestionStep(identifier: "diseasesStep", title: diseasesChoice, question: "Select the diseases you have had or suffer from.", answer: diseasesChoiceFormat) + + + // Vacunacion + let vaccinationQuestionTitle = "Vaccination" + let vaccinationChoices = [ + ORKTextChoice(text: "Yes", value: "never" as NSString), + ORKTextChoice(text: "No", value: "little" as NSString), + ORKTextChoice(text: "I don't remember ", value: "moderate" as NSString),] + + let vaccinationChoiceFormat = ORKValuePickerAnswerFormat(textChoices: vaccinationChoices) + let vaccinationQuestionStep = ORKQuestionStep(identifier: "vaccinationQuestionStep", title: vaccinationQuestionTitle, question: "Do you have your complete vaccination schedule?", answer: vaccinationChoiceFormat) + + // Bebedor alcohol + let alcoholQuestionTitle = "Alcohol drinker" + let alcoholChoices = [ + ORKTextChoice(text: "No Drinks Alcohol", value: "nodrink" as NSString), + ORKTextChoice(text: "Social Drinker", value: "social" as NSString), + ORKTextChoice(text: "Occasional Drinker ", value: "occasional" as NSString), + ORKTextChoice(text: "Dependent Drinker", value: "dependent" as NSString),] + + let alcoholChoiceFormat = ORKValuePickerAnswerFormat(textChoices: alcoholChoices) + let alcoholQuestionStep = ORKQuestionStep(identifier: "alcoholQuestionStep", title: alcoholQuestionTitle, question: "What kind of drinker are you?", answer: alcoholChoiceFormat) + + // fumador tabaco + let smokeQuestionTitle = "Tobacco Smoker" + let smokeChoices = [ + ORKTextChoice(text: "No Smoker", value: "nosmoke" as NSString), + ORKTextChoice(text: "Social Smoker", value: "socialsmoke" as NSString), + ORKTextChoice(text: "Occasional Smoker ", value: "occasionalsmoke" as NSString), + ORKTextChoice(text: "Dependent Smoker", value: "dependentsmoke" as NSString),] + + let smokeChoiceFormat = ORKValuePickerAnswerFormat(textChoices: smokeChoices) + let smokeQuestionStep = ORKQuestionStep(identifier: "smokeQuestionStep", title: smokeQuestionTitle, question: "What kind of smoker are you?", answer: smokeChoiceFormat) + + // drogas + let drugsPatologyChoice = "Drugs" + let drugsPatologyChoices = [ + ORKTextChoice(text: "I do not consume drugs", value: "nodrugs" as NSString), + ORKTextChoice(text: "Marihuana", value: "marihuana" as NSString), + ORKTextChoice(text: "Cocaine", value: "cocaine" as NSString), + ORKTextChoice(text: "MDMA (Ectasty)", value: "mdma" as NSString), + ORKTextChoice(text: "Heroine", value: "heroine" as NSString), + ORKTextChoice(text: "Methamphetamine", value: "metha" as NSString), + ORKTextChoice(text: "LSD", value: "lsd" as NSString), + ORKTextChoice(text: "Hallucinogenic Mushrooms", value: "mushrooms" as NSString), + ORKTextChoice(text: "Other", value: "other" as NSString),] + + let drugsPatologyChoiceFormat = ORKTextChoiceAnswerFormat(style: .multipleChoice, textChoices: drugsPatologyChoices) + let drugsPatologyQuestionStep = ORKQuestionStep(identifier: "drugsPatologyStep", title: drugsPatologyChoice, question: "Select the drug or drugs you consume", answer: drugsPatologyChoiceFormat) + + let frecuencyDrugsQuestionTitle = "Frequency of Drug Use" + let frecuencyDrugsChoices = [ + ORKTextChoice(text: "Never", value: "never" as NSString), + ORKTextChoice(text: "A little", value: "little" as NSString), + ORKTextChoice(text: "Moderate", value: "moderate" as NSString), + ORKTextChoice(text: "A lot", value: "lot" as NSString),] + + let frecuencyDrugsChoiceFormat = ORKValuePickerAnswerFormat(textChoices: frecuencyDrugsChoices) + let frecuencyDrugsQuestionStep = ORKQuestionStep(identifier: "frecuencyDrugsQuestionStep", title: frecuencyDrugsQuestionTitle, question: "How often do you use drugs?", answer: frecuencyDrugsChoiceFormat) + + +//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- + + // Antecedentes no patológicos + + let noPersInfoStepTitle = "Non-pathological history" + let noPersInfoStep = ORKInstructionStep(identifier: "moPersInfoStep") + noPersInfoStep.title = noPersInfoStepTitle + noPersInfoStep.text = "In this section, you'll find questions about your non-pathological backgrounds, such as your daily activities and personal habits." + noPersInfoStep.image = UIImage(systemName: "book.fill") + + + // pregunta de actividad física en escala de likert + let scaleQuestionStepTitle = "Physical activity" + let scaleAnswerFormat = ORKScaleAnswerFormat(maximumValue: 10, minimumValue: 0, defaultValue: 5, step: 1) + let scaleQuestionStep = ORKQuestionStep(identifier: "scaleQuestionStep", title: scaleQuestionStepTitle,question: "How active are you?", answer: scaleAnswerFormat) + + + // Tipo de actividad fisica que realizas. + let multiChoiceQuestionStepTitle = "What types of physical activities do you do?" + let textChoices = [ + ORKTextChoice(text: "Walking", value: "walking" as NSString), + ORKTextChoice(text: "Running", value: "running" as NSString), + ORKTextChoice(text: "Swimming", value: "swimming" as NSString), + ORKTextChoice(text: "Cycling", value: "cycling" as NSString), + ORKTextChoice(text: "Soccer", value: "soccer" as NSString), + ORKTextChoice(text: "Basketball", value: "basketball" as NSString), + ORKTextChoice(text: "Tennis", value: "tennis" as NSString), + ORKTextChoice(text: "Baseball", value: "baseball" as NSString), + ORKTextChoice(text: "Golf", value: "golf" as NSString), + ORKTextChoice(text: "Athletics", value: "athletic" as NSString), + ORKTextChoice(text: "Football", value: "football" as NSString), + ORKTextChoice(text: "Martial Arts", value: "martialarts" as NSString), + ORKTextChoice(text: "Other", value: "other" as NSString), + + ] + let multiChoiceAnswerFormat = ORKTextChoiceAnswerFormat(style: .multipleChoice, textChoices: textChoices) + let multiChoiceQuestionStep = ORKQuestionStep(identifier: "multiChoiceQuestionStep", title: multiChoiceQuestionStepTitle, question: "Select the activities you do regularly", answer: multiChoiceAnswerFormat) + + // hobbies + let hobbieQuestionStepTitle = "What types of physical activities do you do?" + let hobbietextChoices = [ + ORKTextChoice(text: "Reading", value: "reading" as NSString), + ORKTextChoice(text: "Watching movies and series", value: "watchingmovies" as NSString), + ORKTextChoice(text: "Video Gaming", value: "gaming" as NSString), + ORKTextChoice(text: "Cooking and baking", value: "cooking" as NSString), + ORKTextChoice(text: "Traveling", value: "traveling" as NSString), + ORKTextChoice(text: "Gardening", value: "gardening" as NSString), + ORKTextChoice(text: "Arts", value: "arts" as NSString), + ORKTextChoice(text: "Music", value: "music" as NSString), + ORKTextChoice(text: "Photography", value: "photography" as NSString), + ORKTextChoice(text: "Writing", value: "writing" as NSString), + ORKTextChoice(text: "Dancing", value: "dancing" as NSString), + ORKTextChoice(text: "Other", value: "other" as NSString), + + ] + let hobbieAnswerFormat = ORKTextChoiceAnswerFormat(style: .multipleChoice, textChoices: hobbietextChoices) + let hobbieQuestionStep = ORKQuestionStep(identifier: "hobbieQuestionStep", title: hobbieQuestionStepTitle, question: "Select the activities you do regularly", answer: hobbieAnswerFormat) + + // level of study + let studyQuestionTitle = "Level of study" + let studyChoices = [ + ORKTextChoice(text: "Elementary School", value: "elementary" as NSString), + ORKTextChoice(text: "Middle School", value: "middle" as NSString), + ORKTextChoice(text: "High School", value: "high" as NSString), + ORKTextChoice(text: "Bachelor's Degree", value: "bachelor" as NSString), + ORKTextChoice(text: "Master's Degree", value: "master" as NSString), + ORKTextChoice(text: "Doctorate", value: "doctorate" as NSString), + ORKTextChoice(text: "Other", value: "other" as NSString), + ] + + let studyChoiceFormat = ORKValuePickerAnswerFormat(textChoices: studyChoices) + let studyQuestionStep = ORKQuestionStep(identifier: "studyQuestionStep", title: studyQuestionTitle, question: "What is your level of study?", answer: studyChoiceFormat) + + // transporte + let transportationQuestionTitle = "Transportation" + let transportationChoices = [ + ORKTextChoice(text: "Telecommuting (remote work)", value: "telecommuting" as NSString), + ORKTextChoice(text: "Car", value: "car" as NSString), + ORKTextChoice(text: "Public Transport (bus, subway, tram, train)", value: "publictransport" as NSString), + ORKTextChoice(text: "Bicycle", value: "bicycle" as NSString), + ORKTextChoice(text: "Motorcycle", value: "motorcycle" as NSString), + ORKTextChoice(text: "Walking", value: "walking" as NSString), + ORKTextChoice(text: "Electric Scooter", value: "electricscooter" as NSString), + ORKTextChoice(text: "Skateboard", value: "skateboard" as NSString), + ORKTextChoice(text: "Other", value: "other" as NSString), + ] + + let transportationChoiceFormat = ORKValuePickerAnswerFormat(textChoices: transportationChoices) + let transportationQuestionStep = ORKQuestionStep(identifier: "transportationQuestionStep", title: transportationQuestionTitle, question: "What is the means of transportation you use from home to work or school?", answer: transportationChoiceFormat) + + //Alimentación + + let foodQuestionTitle = "Alimentation" + let foodChoices = [ + ORKTextChoice(text: "Good", value: "good" as NSString), + ORKTextChoice(text: "Average", value: "average" as NSString), + ORKTextChoice(text: "Poor", value: "poor" as NSString),] + + let foodChoiceFormat = ORKValuePickerAnswerFormat(textChoices: foodChoices) + let foodQuestionStep = ORKQuestionStep(identifier: "foodQuestionStep", title: foodQuestionTitle, question: "How would you describe your quality and quantity of food?", answer: foodChoiceFormat) + + // cuantas veces comes + let alimentationQuestionStepTitle = "Alimentation" + let alimentationAnswerFormat = ORKScaleAnswerFormat(maximumValue: 10, minimumValue: 0, defaultValue: 3, step: 1) + let alimentationQuestionStep = ORKQuestionStep(identifier: "alimentationQuestionStep", title: alimentationQuestionStepTitle,question: "How many meals do you have a day?", answer: alimentationAnswerFormat) + + // tipo de alimento + let typeFoodChoice = "Types of food" + let typeFoodChoices = [ + ORKTextChoice(text: "Chicken", value: "chicken" as NSString), + ORKTextChoice(text: "Beef", value: "beef" as NSString), + ORKTextChoice(text: "Pork", value: "pork" as NSString), + ORKTextChoice(text: "Seafood", value: "seafood" as NSString), + ORKTextChoice(text: "Fruits/Vegetables", value: "fruitsvegetables" as NSString), + ORKTextChoice(text: "Other", value: "other" as NSString) + ] + + let typeFoodChoiceFormat = ORKTextChoiceAnswerFormat(style: .multipleChoice, textChoices: typeFoodChoices) + let typeFoodQuestionStep = ORKQuestionStep(identifier: "typeFoodStep", title: typeFoodChoice, question: "SWhat type of food do you eat?", answer: typeFoodChoiceFormat) + + +//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- + + // Mostrar las preguntas + + return ORKOrderedTask(identifier: "SurveyTask", steps: [thankUJoin, personalInfoStep, textQuestionStep, multiGenderQuestionStep, dobStep, weighForm, heightForm, residenceQuestionStep, occupationQuestionStep, occupationFormStep, hereditaryInfoStep, patologyQuestionStep, mentalPatologyQuestionStep, persInfoStep, diseasesQuestionStep, vaccinationQuestionStep, alcoholQuestionStep, smokeQuestionStep, drugsPatologyQuestionStep, frecuencyDrugsQuestionStep,noPersInfoStep, scaleQuestionStep, multiChoiceQuestionStep, hobbieQuestionStep, studyQuestionStep, transportationQuestionStep, foodQuestionStep, alimentationQuestionStep, typeFoodQuestionStep]) + } + + +} + + + +/*// Telefono +let phoneNumber = "Phone Number" +let phoneNumberCan = ORKTextAnswerFormat(maximumLength: 10) +phoneNumberCan.multipleLines = false +let phoneNumberTap = ORKQuestionStep(identifier: "phoneNum", title: phoneNumber, question: "What is your Phone Number", answer: phoneNumberCan) + +// Pregunta de domicilio (dirección) +let addressStepTitle = "Address" + +let streetAnswerFormat = ORKTextAnswerFormat(maximumLength: 100) +streetAnswerFormat.multipleLines = false +let streetFormItem = ORKFormItem(identifier: "streetFormItem", text: "Street: ", answerFormat: streetAnswerFormat) + +let numberAnswerFormat = ORKTextAnswerFormat(maximumLength: 50) +numberAnswerFormat.multipleLines = false +let numberFormItem = ORKFormItem(identifier: "numberFormItem", text: "Number: ", answerFormat: numberAnswerFormat) + +let zipCodeAnswerFormat = ORKTextAnswerFormat(maximumLength: 10) +zipCodeAnswerFormat.multipleLines = false +let zipCodeFormItem = ORKFormItem(identifier: "zipCodeFormItem", text: "ZIP Code: ", answerFormat: zipCodeAnswerFormat) + +let cityAnswerFormat = ORKTextAnswerFormat(maximumLength: 50) +cityAnswerFormat.multipleLines = false +let cityFormItem = ORKFormItem(identifier: "cityFormItem", text: "City: ", answerFormat: cityAnswerFormat) + +let stateAnswerFormat = ORKTextAnswerFormat(maximumLength: 50) +stateAnswerFormat.multipleLines = false +let stateFormItem = ORKFormItem(identifier: "stateFormItem", text: "State: ", answerFormat: stateAnswerFormat) + +let countryAnswerFormat = ORKTextAnswerFormat(maximumLength: 50) +countryAnswerFormat.multipleLines = false +let countryFormItem = ORKFormItem(identifier: "countryFormItem", text: "Country: ", answerFormat: countryAnswerFormat) + +let addressFormStep = ORKFormStep(identifier: "AddressFormStep", title: addressStepTitle, text: "Enter your address") +addressFormStep.formItems = [streetFormItem, numberFormItem, zipCodeFormItem, cityFormItem, stateFormItem, countryFormItem] + +// Estado civil +let maritalStatusChoice = "Marital Status" +let maritalStatusChoices = [ + ORKTextChoice(text: "Single", value: "single" as NSString), + ORKTextChoice(text: "Married", value: "married" as NSString), + ORKTextChoice(text: "Divorced", value: "divorced" as NSString), + ORKTextChoice(text: "Widowed", value: "widowed" as NSString), + ORKTextChoice(text: "I prefer not to say", value: "prefer_not_to_say" as NSString) +] +let maritalStatusChoiceFormat = ORKValuePickerAnswerFormat(textChoices: maritalStatusChoices) +let maritalStatusQuestionStep = ORKQuestionStep(identifier: "maritalStatusQuestionStep", title: maritalStatusChoice, question: "What is your marital status", answer: maritalStatusChoiceFormat)*/ diff --git a/surveys-example/ViewController.swift b/surveys-example/ViewController.swift new file mode 100644 index 0000000..f9ee561 --- /dev/null +++ b/surveys-example/ViewController.swift @@ -0,0 +1,49 @@ +// +// ViewController.swift +// surveys-example +// +// Created by Juan David López Regalado on 12/06/24. +// + +import UIKit +import ResearchKit +import ResearchKitUI + +class ViewController: UIViewController, ORKTaskViewControllerDelegate { + + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view. + } + + + @IBAction func startSurveyTapped(_ sender: Any) { + let consentTask = ConsentManager.shared.createConsentTask() + let taskViewController = ORKTaskViewController(task: consentTask, taskRun: nil) + + taskViewController.delegate = self + present(taskViewController,animated: true, completion: nil) + + } + + func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith reason: ORKTaskFinishReason, error: (any Error)?) { + taskViewController.dismiss(animated: true, completion: nil) + + + + if reason == .completed { + startSurvey() + } + + func startSurvey() { + let surveyTask = SurveyManager.shared.createSurveyTask() + let taskViewController = ORKTaskViewController(task: surveyTask, taskRun: nil) + + taskViewController.delegate = self + present(taskViewController, animated: true, completion: nil) + } + + + } +} +