diff --git a/Assignment Two.xcodeproj/project.pbxproj b/Assignment Two.xcodeproj/project.pbxproj index 90fa3e5..f17489f 100644 --- a/Assignment Two.xcodeproj/project.pbxproj +++ b/Assignment Two.xcodeproj/project.pbxproj @@ -9,7 +9,7 @@ /* Begin PBXBuildFile section */ 63A3CE7CD4FC0CCD0333F867 /* Pods_Assignment_Two.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7DE9A4430C3A45320910A5E /* Pods_Assignment_Two.framework */; }; 8E0A956625B6767B0025461E /* CKTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E0A956525B6767B0025461E /* CKTaskViewController.swift */; }; - 8E0A956925B677950025461E /* RKTaskSamples.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E0A956825B677950025461E /* RKTaskSamples.swift */; }; + 8E0A956925B677950025461E /* GeneralPatientQuestionnaire.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E0A956825B677950025461E /* GeneralPatientQuestionnaire.swift */; }; 8E35408925B8FE3A007B7029 /* SurveyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E35408825B8FE3A007B7029 /* SurveyView.swift */; }; 8E35408D25B8FFC9007B7029 /* RoundedTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E35408C25B8FFC9007B7029 /* RoundedTextView.swift */; }; 8E35409625B90E80007B7029 /* ORKESerialization.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E35409425B90E80007B7029 /* ORKESerialization.m */; }; @@ -20,12 +20,14 @@ 8EF8F77D2597C7DE000850BF /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8EF8F77C2597C7DE000850BF /* ContentView.swift */; }; 8EF8F77F2597C7E1000850BF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8EF8F77E2597C7E1000850BF /* Assets.xcassets */; }; 8EF8F7822597C7E1000850BF /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8EF8F7812597C7E1000850BF /* Preview Assets.xcassets */; }; + FD472A5425BFC1F400F6A49A /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = FD472A5325BFC1F400F6A49A /* GoogleService-Info.plist */; }; + FD472A5A25BFC75400F6A49A /* MedicationQuestionnaire.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD472A5925BFC75400F6A49A /* MedicationQuestionnaire.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ 4483BDF88A5E2878F34C059F /* Pods-Assignment Two.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Assignment Two.release.xcconfig"; path = "Target Support Files/Pods-Assignment Two/Pods-Assignment Two.release.xcconfig"; sourceTree = ""; }; 8E0A956525B6767B0025461E /* CKTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CKTaskViewController.swift; sourceTree = ""; }; - 8E0A956825B677950025461E /* RKTaskSamples.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RKTaskSamples.swift; sourceTree = ""; }; + 8E0A956825B677950025461E /* GeneralPatientQuestionnaire.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralPatientQuestionnaire.swift; sourceTree = ""; }; 8E35408825B8FE3A007B7029 /* SurveyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SurveyView.swift; sourceTree = ""; }; 8E35408C25B8FFC9007B7029 /* RoundedTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundedTextView.swift; sourceTree = ""; }; 8E35409325B90E7F007B7029 /* Assignment Two-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Assignment Two-Bridging-Header.h"; sourceTree = ""; }; @@ -42,6 +44,8 @@ 8EF8F7812597C7E1000850BF /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 8EF8F7832597C7E1000850BF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; E7DE9A4430C3A45320910A5E /* Pods_Assignment_Two.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Assignment_Two.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + FD472A5325BFC1F400F6A49A /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; + FD472A5925BFC75400F6A49A /* MedicationQuestionnaire.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MedicationQuestionnaire.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -100,6 +104,7 @@ 8EF8F76E2597C7DE000850BF = { isa = PBXGroup; children = ( + FD472A5325BFC1F400F6A49A /* GoogleService-Info.plist */, 8EF8F7792597C7DE000850BF /* Assignment Two */, 8EF8F7782597C7DE000850BF /* Products */, BC78C6756808D892DF11E798 /* Pods */, @@ -123,7 +128,8 @@ 8E35408B25B8FEF2007B7029 /* Views */, 8EF8F77A2597C7DE000850BF /* Assignment_TwoApp.swift */, 8E35409825B90F1B007B7029 /* RKTaskDelegate.swift */, - 8E0A956825B677950025461E /* RKTaskSamples.swift */, + 8E0A956825B677950025461E /* GeneralPatientQuestionnaire.swift */, + FD472A5925BFC75400F6A49A /* MedicationQuestionnaire.swift */, ); path = "Assignment Two"; sourceTree = ""; @@ -215,6 +221,7 @@ files = ( 8EF8F7822597C7E1000850BF /* Preview Assets.xcassets in Resources */, 8EF8F77F2597C7E1000850BF /* Assets.xcassets in Resources */, + FD472A5425BFC1F400F6A49A /* GoogleService-Info.plist in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -268,7 +275,7 @@ buildActionMask = 2147483647; files = ( 8E8775DD25B8F8B800AB350A /* HeaderView.swift in Sources */, - 8E0A956925B677950025461E /* RKTaskSamples.swift in Sources */, + 8E0A956925B677950025461E /* GeneralPatientQuestionnaire.swift in Sources */, 8E35409D25B90F7A007B7029 /* CKStudyUser.swift in Sources */, 8E35408925B8FE3A007B7029 /* SurveyView.swift in Sources */, 8EF8F77D2597C7DE000850BF /* ContentView.swift in Sources */, @@ -276,6 +283,7 @@ 8E35409625B90E80007B7029 /* ORKESerialization.m in Sources */, 8E0A956625B6767B0025461E /* CKTaskViewController.swift in Sources */, 8EF8F77B2597C7DE000850BF /* Assignment_TwoApp.swift in Sources */, + FD472A5A25BFC75400F6A49A /* MedicationQuestionnaire.swift in Sources */, 8E35409925B90F1B007B7029 /* RKTaskDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -408,7 +416,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_ASSET_PATHS = "\"Assignment Two/Preview Content\""; - DEVELOPMENT_TEAM = CQRZ4E7K9U; + DEVELOPMENT_TEAM = Z7SA65KY4V; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = "Assignment Two/Supporting Files/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 14.0; @@ -416,7 +424,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = "edu.stanford.cs342.Assignment-Two"; + PRODUCT_BUNDLE_IDENTIFIER = "edu.stanford.cs342.Assignment-Two-CCH"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Assignment Two/Supporting Files/Assignment Two-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -434,7 +442,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_ASSET_PATHS = "\"Assignment Two/Preview Content\""; - DEVELOPMENT_TEAM = CQRZ4E7K9U; + DEVELOPMENT_TEAM = Z7SA65KY4V; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = "Assignment Two/Supporting Files/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 14.0; @@ -442,7 +450,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = "edu.stanford.cs342.Assignment-Two"; + PRODUCT_BUNDLE_IDENTIFIER = "edu.stanford.cs342.Assignment-Two-CCH"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Assignment Two/Supporting Files/Assignment Two-Bridging-Header.h"; SWIFT_VERSION = 5.0; diff --git a/Assignment Two/GeneralPatientQuestionnaire.swift b/Assignment Two/GeneralPatientQuestionnaire.swift new file mode 100644 index 0000000..16bb06b --- /dev/null +++ b/Assignment Two/GeneralPatientQuestionnaire.swift @@ -0,0 +1,104 @@ +// +// StudyTasks.swift +// +// Created for Biodesign's CS342 +// Copyright © 2019 Stanford University. +// All rights reserved. +// + +import ResearchKit + +/** + This file contains some sample `ResearchKit` tasks + that you can modify and use throughout your project! +*/ +struct GeneralPatientQuestionnaire { + + /** + Sample task template! + */ + static let form: ORKOrderedTask = { + var steps = [ORKStep]() + + /* + CS342 -- ASSIGNMENT 2 + Add steps to the array above to create a survey! + */ + + // Introduction + let instructionStep = ORKInstructionStep(identifier: "Introstep") + instructionStep.title = "SF-12 Patient Questionnaire" + instructionStep.text = "Welcome" + instructionStep.image = UIImage(named: "doctor") + instructionStep.detailText = "This information will help your doctors keep track of how you feel and how well you are able to do your usual activities. If you are unsure about how to answer a question, please give the best answer you can." + steps.append(instructionStep) + + // Q1 + let firstStepAnswerFormat = ORKAnswerFormat.scale(withMaximumValue: 5, minimumValue: 1, defaultValue: 3, step: 1, vertical: false, maximumValueDescription: "Excellent", minimumValueDescription: "Poor") + let firstStep = ORKQuestionStep(identifier: "SF-12-1", title: "Patient Questionnaire", question: "In general, how would you describe your health?", answer: firstStepAnswerFormat) + steps.append(firstStep) + + // Q2 + let secondStepAnswerFormat = ORKAnswerFormat.scale(withMaximumValue: 3, minimumValue: 1, defaultValue: 2, step: 1, vertical: false, maximumValueDescription: "Limited a lot", minimumValueDescription: "Not limited at all") + let secondStep = ORKQuestionStep(identifier: "SF-12-2", title: "Activites", question: "To what extent does your health limit you in moderate activities, such as moving a table, pushing a vacuum cleaner, or playing golf?", answer: secondStepAnswerFormat) + steps.append(secondStep) + + // Q3 + let thirdStepAnswerFormat = ORKAnswerFormat.scale(withMaximumValue: 3, minimumValue: 1, defaultValue: 2, step: 1, vertical: false, maximumValueDescription: "Limited a lot", minimumValueDescription: "Not limited at all") + let thirdStep = ORKQuestionStep(identifier: "SF-12-3", title: "Activites", question: "To what extent does your health limit you walking up several flights of stairs consecutively?", answer: thirdStepAnswerFormat) + steps.append(thirdStep) + + // Q4 + let fourthStepAnswerFormat = ORKAnswerFormat.booleanAnswerFormat() + let fourthStep = ORKQuestionStep(identifier: "SF-12-4", title: "Activities", question: "During the past four weeks, have you accomplished less than you would like due to your physical health?", answer: fourthStepAnswerFormat) + steps.append(fourthStep) + + // Q5 + let fifthStepAnswerFormat = ORKAnswerFormat.booleanAnswerFormat() + let fifthStep = ORKQuestionStep(identifier: "SF-12-5", title: "Activities", question: "During the past four weeks, have you been limited in the kind of work or activities you can undertake by your physical health?", answer: fifthStepAnswerFormat) + steps.append(fifthStep) + + // Q6 + let sixthStepAnswerFormat = ORKAnswerFormat.booleanAnswerFormat() + let sixthStep = ORKQuestionStep(identifier: "SF-12-6", title: "Activities", question: "During the past four weeks, have you accomplished less than you would like due to emotional problems?", answer: sixthStepAnswerFormat) + steps.append(sixthStep) + + // Q7 + let seventhStepAnswerFormat = ORKAnswerFormat.booleanAnswerFormat() + let seventhStep = ORKQuestionStep(identifier: "SF-12-7", title: "Activities", question: "During the past four weeks, did you perform work or activities less carefully than usual due to emotional problems?", answer: seventhStepAnswerFormat) + steps.append(seventhStep) + + // Q8 + let eighthStepAnswerFormat = ORKAnswerFormat.scale(withMaximumValue: 5, minimumValue: 1, defaultValue: 3, step: 1, vertical: false, maximumValueDescription: "Extremely", minimumValueDescription: "Not at all") + let eighthStep = ORKQuestionStep(identifier: "SF-12-8", title: "Pain", question: "During the last four weeks, how much did pain interfere with your normal work (including both housework and work outside the home)?", answer: eighthStepAnswerFormat) + steps.append(eighthStep) + + // Q9 + let ninthStepAnswerFormat = ORKAnswerFormat.scale(withMaximumValue: 6, minimumValue: 1, defaultValue: 3, step: 1, vertical: false, maximumValueDescription: "All of the time", minimumValueDescription: "None of the time") + let ninthStep = ORKQuestionStep(identifier: "SF-12-9", title: "Emotions", question: "During the last four weeks, how often have you felt calm and peaceful?", answer: ninthStepAnswerFormat) + steps.append(ninthStep) + + // Q10 + let tenthStepAnswerFormat = ORKAnswerFormat.scale(withMaximumValue: 6, minimumValue: 1, defaultValue: 3, step: 1, vertical: false, maximumValueDescription: "All of the time", minimumValueDescription: "None of the time") + let tenthStep = ORKQuestionStep(identifier: "SF-12-10", title: "Emotions", question: "During the last four weeks, how often have you had a lot of energy?", answer: tenthStepAnswerFormat) + steps.append(tenthStep) + + // Q11 + let eleventhStepAnswerFormat = ORKAnswerFormat.scale(withMaximumValue: 6, minimumValue: 1, defaultValue: 3, step: 1, vertical: false, maximumValueDescription: "All of the time", minimumValueDescription: "None of the time") + let eleventhStep = ORKQuestionStep(identifier: "SF-12-11", title: "Emotions", question: "During the last four weeks, how often have you felt downhearted and blue?", answer: eleventhStepAnswerFormat) + steps.append(eleventhStep) + + // Q12 + let twelfthStepAnswerFormat = ORKAnswerFormat.scale(withMaximumValue: 6, minimumValue: 1, defaultValue: 3, step: 1, vertical: false, maximumValueDescription: "All of the time", minimumValueDescription: "None of the time") + let twelfthStep = ORKQuestionStep(identifier: "SF-12-12", title: "Emotions", question: "During the last four weeks, how often has your physical health or emotional problems interfered with your social activities (like visiting with friends, relatives, etc.)?", answer: twelfthStepAnswerFormat) + steps.append(twelfthStep) + + let summaryStep = ORKInstructionStep(identifier: "SummaryStep") + summaryStep.title = "SF-12 Complete" + summaryStep.text = "Thank you for completing the survey." + summaryStep.image = UIImage(named: "Portrait") + steps.append(summaryStep) + + return ORKOrderedTask(identifier: "GeneralPatientQuestionnaire", steps: steps) + }() +} diff --git a/Assignment Two/MedicationQuestionnaire.swift b/Assignment Two/MedicationQuestionnaire.swift new file mode 100644 index 0000000..2ae83af --- /dev/null +++ b/Assignment Two/MedicationQuestionnaire.swift @@ -0,0 +1,232 @@ +// +// StudyTasks.swift +// +// Created for Biodesign's CS342 +// Copyright © 2019 Stanford University. +// All rights reserved. +// + +import ResearchKit + +/** + This file contains some sample `ResearchKit` tasks + that you can modify and use throughout your project! +*/ +struct MedicationQuestionnaire { + + /** + Sample task template! + */ + static let form: ORKNavigableOrderedTask = { + + var steps = [ORKStep]() + + /* + CS342 -- ASSIGNMENT 2 + Add steps to the array above to create a survey! + */ + + let instructionStep = ORKInstructionStep(identifier: "Introstep") + instructionStep.title = "BMQ-1 Patient Questionnaire" + instructionStep.text = "Welcome" + instructionStep.image = UIImage(named: "doctor") + instructionStep.detailText = "This form asks about the medications you currently take for high blood pressure. Please include any medication that you might be taking for high blood pressure, including water pills." + steps.append(instructionStep) + + // Q1 + let firstStepAnswerFormat = ORKBooleanAnswerFormat() + let firstStep = ORKQuestionStep(identifier: "Q1", title: "Medications", question: "Do you have your medications currently?", answer: firstStepAnswerFormat) + steps.append(firstStep) + + // Q2 + let secondStep = ORKQuestionStep(identifier: "Q2", title: "Medications", question: "How many medications do you currently take for heart problems?", answer: ORKAnswerFormat.decimalAnswerFormat(withUnit: nil)) + steps.append(secondStep) + + // Q3 + let thirdStepAnswerFormat = ORKBooleanAnswerFormat() + let thirdStep = ORKQuestionStep(identifier: "Q3", title: "Medications", question: "Have you stopped taking any medications for heart problems in the last 6 months?", answer: thirdStepAnswerFormat) + thirdStep.isOptional = false + steps.append(thirdStep) + + // automatically generate stopped form for 5 drugs + for index in 0...5 { + // Q4 + let stoppedStep = ORKFormStep(identifier: "Q4-\(index)", title: "Stopped Drug \(index + 1)", text: "What heart medication was stopped?") + + // name of the drug + let drugNameAnswerFormat = ORKAnswerFormat.textAnswerFormat() + let drugNameSection = ORKFormItem(sectionTitle: "Please enter the name of the drug:") + let drugNameQ = ORKFormItem(identifier: "Q4-drug-\(index)", text: nil, answerFormat: drugNameAnswerFormat) + + // reason it was stopped + let drugDateAnswerFormat = ORKAnswerFormat.textAnswerFormat() + let drugDateSection = ORKFormItem(sectionTitle: "Reason it was stopped:") + let drugDateQ = ORKFormItem(identifier: "Q4-reason-\(index)", text: nil, answerFormat: drugDateAnswerFormat) + + stoppedStep.formItems = [ + drugNameSection, + drugNameQ, + drugDateSection, + drugDateQ + ] + steps.append(stoppedStep) + + if index < 5 { + // Check if we have more stopped drugs to report + let extraDrugStep = ORKQuestionStep(identifier: "MoreStopped?-\(index)", title: "", question: "Have you stopped taking any other drugs?", answer: ORKBooleanAnswerFormat()) + extraDrugStep.isOptional = false + steps.append(extraDrugStep) + } + } + + + // automatically generate forms for 20 drugs + for index in 0...20 { + // build out the form for a specific drug + let drugStep = ORKFormStep(identifier: "drug-entry-\(index)", title: "Current Drug \(index + 1)", text: "Enter a medication that you currently take for high blood pressure") + + // name of the drug + let drugNameAnswerFormat = ORKAnswerFormat.textAnswerFormat() + let drugNameSection = ORKFormItem(sectionTitle: "Please enter the name of the drug") + let drugNameQ = ORKFormItem(identifier: "drug-name-\(index)", text: nil, answerFormat: drugNameAnswerFormat) + + // how often + let prescribedFrequencyChoices = [ + ORKTextChoice(text: "Every Day", detailText: nil, value: 1 as NSCoding & NSCopying & NSObjectProtocol, exclusive: true), + ORKTextChoice(text: "As Needed", detailText: nil, value: 2 as NSCoding & NSCopying & NSObjectProtocol, exclusive: true), + ORKTextChoice(text: "Don't Know", detailText: nil, value: 3 as NSCoding & NSCopying & NSObjectProtocol, exclusive: true), + ] + let prescribedFrequencyAnswerFormat = ORKTextChoiceAnswerFormat(style: .singleChoice, textChoices: prescribedFrequencyChoices) + let prescribedFrequencyQ = ORKFormItem(identifier: "prescribed-frequency-\(index)", text: "How often does your doctor want you you to take this drug?", answerFormat: prescribedFrequencyAnswerFormat) + + // intention of the drug + let drugIntentChoices = [ + ORKTextChoice(text: "Get rid of water", detailText: nil, value: 1 as NSCoding & NSCopying & NSObjectProtocol, exclusive: false), + ORKTextChoice(text: "Lower my pressure", detailText: nil, value: 2 as NSCoding & NSCopying & NSObjectProtocol, exclusive: false), + ORKTextChoice(text: "Prevent a stroke", detailText: nil, value: 3 as NSCoding & NSCopying & NSObjectProtocol, exclusive: false), + ORKTextChoice(text: "Prevent heart problems", detailText: nil, value: 4 as NSCoding & NSCopying & NSObjectProtocol, exclusive: false), + ORKTextChoice(text: "Relieve headaches", detailText: nil, value: 5 as NSCoding & NSCopying & NSObjectProtocol, exclusive: false), + ORKTextChoice(text: "Don't know", detailText: nil, value: 7 as NSCoding & NSCopying & NSObjectProtocol, exclusive: true), + ORKTextChoiceOther.choice(withText: "Other", detailText: nil, value: 6 as NSCoding & NSCopying & NSObjectProtocol, exclusive: false, textViewPlaceholderText: "Other") + ] + let drugIntentAnswerFormat = ORKTextChoiceAnswerFormat(style: .multipleChoice, textChoices: drugIntentChoices) + let drugIntentQ = ORKFormItem(identifier: "drug-intention-\(index)", text: "How is this drug supposed to help you? (Select all that apply)", answerFormat: drugIntentAnswerFormat) + + let numDaysTakenAnswerFormat = ORKAnswerFormat.scale(withMaximumValue: 7, minimumValue: 0, defaultValue: 0, step: 1, vertical: false, maximumValueDescription: "days", minimumValueDescription: nil) + let numDaysTakenQ = ORKFormItem(identifier: "num-days-taken-\(index)", text: "In the past week, how many days did you take this drug?", answerFormat: numDaysTakenAnswerFormat) + + let timesPerDayAnswerFormat = ORKAnswerFormat.scale(withMaximumValue: 3, minimumValue: 0, defaultValue: 0, step: 1, vertical: false, maximumValueDescription: "doses per day", minimumValueDescription: nil) + let timesPerDayQ = ORKFormItem(identifier: "doses-per-day-\(index)", text: "In the past week, how many times per day did you take this drug?", answerFormat: timesPerDayAnswerFormat) + + let pillsPerDoseAnswerFormat = ORKAnswerFormat.scale(withMaximumValue: 3, minimumValue: 0, defaultValue: 0, step: 1, vertical: false, maximumValueDescription: "pills per dose", minimumValueDescription: nil) + let pillsPerDoseQ = ORKFormItem(identifier: "pills-per-dose-\(index)", text: "When you take this drug, how many pills do you consume at once?", answerFormat: pillsPerDoseAnswerFormat) + + let missedDoseAnswerFormat = ORKAnswerFormat.scale(withMaximumValue: 7, minimumValue: 0, defaultValue: 0, step: 1, vertical: false, maximumValueDescription: "times", minimumValueDescription: nil) + let missedDoseQ = ORKFormItem(identifier: "times-missed-\(index)", text: "How many times did you miss taking this drug?", answerFormat: missedDoseAnswerFormat) + + let effectivenessChoices = [ + ORKTextChoice(text: "Not well at all", detailText: nil, value: 1 as NSCoding & NSCopying & NSObjectProtocol, exclusive: true), + ORKTextChoice(text: "Moderately well", detailText: nil, value: 2 as NSCoding & NSCopying & NSObjectProtocol, exclusive: true), + ORKTextChoice(text: "Very well", detailText: nil, value: 3 as NSCoding & NSCopying & NSObjectProtocol, exclusive: true), + ORKTextChoice(text: "Don't know", detailText: nil, value: 4 as NSCoding & NSCopying & NSObjectProtocol, exclusive: true), + ] + let effectivenessAnswerFormat = ORKTextChoiceAnswerFormat(style: .singleChoice, textChoices: effectivenessChoices) + let effectivenessQ = ORKFormItem(identifier: "perceived-effectiveness-\(index)", text: "How well does this drug work for you?", answerFormat: effectivenessAnswerFormat) + + let botherChoices = [ + ORKTextChoice(text: "Not at all", detailText: nil, value: 1 as NSCoding & NSCopying & NSObjectProtocol, exclusive: true), + ORKTextChoice(text: "Bothers a little", detailText: nil, value: 2 as NSCoding & NSCopying & NSObjectProtocol, exclusive: true), + ORKTextChoice(text: "Bothers a lot", detailText: nil, value: 3 as NSCoding & NSCopying & NSObjectProtocol, exclusive: true), + ORKTextChoice(text: "Don't know", detailText: nil, value: 4 as NSCoding & NSCopying & NSObjectProtocol, exclusive: true), + ] + let botherAnswerFormat = ORKTextChoiceAnswerFormat(style: .singleChoice, textChoices: botherChoices) + let botherQ = ORKFormItem(identifier: "bother-index-\(index)", text: "How much does this drug bother you?", answerFormat: botherAnswerFormat) + + + // difficulty section + let rememberDifficultyFormat = ORKAnswerFormat.scale(withMaximumValue: 3, minimumValue: 0, defaultValue: 0, step: 1, vertical: false, maximumValueDescription: "A lot", minimumValueDescription: "A little") + let rememberDifficultyQ = ORKFormItem(identifier: "difficulty-remember-\(index)", text: "How much difficulty are you having remembering all the doses?", answerFormat: rememberDifficultyFormat) + + let payDifficultyFormat = ORKAnswerFormat.scale(withMaximumValue: 3, minimumValue: 0, defaultValue: 0, step: 1, vertical: false, maximumValueDescription: "A lot", minimumValueDescription: "A little") + let payDifficultyQ = ORKFormItem(identifier: "difficulty-pay-\(index)", text: "How much difficulty are you having paying for this drug?", answerFormat: payDifficultyFormat) + + let refillDifficultyFormat = ORKAnswerFormat.scale(withMaximumValue: 3, minimumValue: 0, defaultValue: 0, step: 1, vertical: false, maximumValueDescription: "A lot", minimumValueDescription: "A little") + let refillDifficultyQ = ORKFormItem(identifier: "difficulty-refill-\(index)", text: "How much difficulty are you having getting your refill on time?", answerFormat: refillDifficultyFormat) + + let sideEffectDifficultyFormat = ORKAnswerFormat.scale(withMaximumValue: 3, minimumValue: 0, defaultValue: 0, step: 1, vertical: false, maximumValueDescription: "A lot", minimumValueDescription: "A little") + let sideEffectDifficultyQ = ORKFormItem(identifier: "difficulty-side-effect-\(index)", text: "How many unwanted side effects are you experiencing?", answerFormat: sideEffectDifficultyFormat) + + let longTermEffectDifficultyFormat = ORKAnswerFormat.scale(withMaximumValue: 3, minimumValue: 0, defaultValue: 0, step: 1, vertical: false, maximumValueDescription: "A lot", minimumValueDescription: "A little") + let longTermEffectDifficultyQ = ORKFormItem(identifier: "difficulty-long-effect-\(index)", text: "I worry about the long term effects of this drug", answerFormat: longTermEffectDifficultyFormat) + + let otherConcernsDifficultyFormat = ORKAnswerFormat.scale(withMaximumValue: 3, minimumValue: 0, defaultValue: 0, step: 1, vertical: false, maximumValueDescription: "A lot", minimumValueDescription: "A little") + let otherConcernsDifficultyQ = ORKFormItem(identifier: "difficulty-other-\(index)", text: "This drug causes other concerns or problems", answerFormat: otherConcernsDifficultyFormat) + + drugStep.formItems = [ + drugNameSection, + drugNameQ, + prescribedFrequencyQ, + drugIntentQ, + numDaysTakenQ, + timesPerDayQ, + pillsPerDoseQ, + missedDoseQ, + effectivenessQ, + botherQ, + rememberDifficultyQ, + payDifficultyQ, + refillDifficultyQ, + sideEffectDifficultyQ, + longTermEffectDifficultyQ, + otherConcernsDifficultyQ + ] + steps.append(drugStep) + + if index < 20 { + // Check if we have more drugs to report + let extraDrugStep = ORKQuestionStep(identifier: "MoreDrugs?-\(index)", title: "", question: "Do you have any other current medications?", answer: ORKBooleanAnswerFormat()) + extraDrugStep.isOptional = false + steps.append(extraDrugStep) + } + } + + // Thank you page + let summaryStep = ORKInstructionStep(identifier: "SummaryStep") + summaryStep.title = "Drug Form Complete" + summaryStep.text = "Thank you for completing the survey." + summaryStep.image = UIImage(named: "Portrait") + steps.append(summaryStep) + + let ret_value = ORKNavigableOrderedTask(identifier: "SurveyTask-Assessment", steps: steps) + + // rules for drug forms + for index in 0...19 { + // Navigation Rule + let resultSelector = ORKResultSelector(resultIdentifier: "MoreDrugs?-\(index)") + let predicateAnswerType = ORKResultPredicate.predicateForBooleanQuestionResult(with: resultSelector, expectedAnswer: true) + + let predicateRule = ORKPredicateStepNavigationRule(resultPredicates: [predicateAnswerType], destinationStepIdentifiers: ["drug-entry-\(index + 1)"], defaultStepIdentifier: "SummaryStep", validateArrays: true) + + ret_value.setNavigationRule(predicateRule, forTriggerStepIdentifier: "MoreDrugs?-\(index)") + } + + // rules for stopped drug forms + for index in 0...4 { + let resultSelector = ORKResultSelector(resultIdentifier: "MoreStopped?-\(index)") + let predicateAnswerType = ORKResultPredicate.predicateForBooleanQuestionResult(with: resultSelector, expectedAnswer: true) + + let predicateRule = ORKPredicateStepNavigationRule(resultPredicates: [predicateAnswerType], destinationStepIdentifiers: ["Q4-\(index + 1)"], defaultStepIdentifier: "drug-entry-0", validateArrays: true) + + ret_value.setNavigationRule(predicateRule, forTriggerStepIdentifier: "MoreStopped?-\(index)") + } + + // rule for stopping any drugs + let resultSelector = ORKResultSelector(resultIdentifier: "Q3") + let predicateAnswerType = ORKResultPredicate.predicateForBooleanQuestionResult(with: resultSelector, expectedAnswer: true) + + let predicateRule = ORKPredicateStepNavigationRule(resultPredicates: [predicateAnswerType], destinationStepIdentifiers: ["Q4-0"], defaultStepIdentifier: "drug-entry-0", validateArrays: true) + ret_value.setNavigationRule(predicateRule, forTriggerStepIdentifier: "Q3") + + return ret_value + }() +} diff --git a/Assignment Two/RKTaskSamples.swift b/Assignment Two/RKTaskSamples.swift deleted file mode 100644 index c1a92f1..0000000 --- a/Assignment Two/RKTaskSamples.swift +++ /dev/null @@ -1,30 +0,0 @@ -// -// StudyTasks.swift -// -// Created for Biodesign's CS342 -// Copyright © 2019 Stanford University. -// All rights reserved. -// - -import ResearchKit - -/** - This file contains some sample `ResearchKit` tasks - that you can modify and use throughout your project! -*/ -struct RKTaskSamples { - - /** - Sample task template! - */ - static let sampleSurveyTask: ORKOrderedTask = { - var steps = [ORKStep]() - - /* - CS342 -- ASSIGNMENT 2 - Add steps to the array above to create a survey! - */ - - return ORKOrderedTask(identifier: "SurveyTask-Assessment", steps: steps) - }() -} diff --git a/Assignment Two/Views/SurveyView.swift b/Assignment Two/Views/SurveyView.swift index bdbc6b2..07e236e 100644 --- a/Assignment Two/Views/SurveyView.swift +++ b/Assignment Two/Views/SurveyView.swift @@ -36,9 +36,21 @@ struct SurveyView: View { The task must conform to the ORKOrderedTask class. */ - // surveyOptional = /* my ORKOrderedTask */ + surveyOptional = GeneralPatientQuestionnaire.form }) { - RoundedTextView("Start Survey", backgroundColor: .red) + RoundedTextView("Start General Patient Questionnaire", backgroundColor: .red) + } + + Button(action: { + /* + CS342 -- ASSIGNMENT 2 + Set surveyOptional to any ResearchKit task of your choice! + The task must conform to the ORKOrderedTask class. + */ + + surveyOptional = MedicationQuestionnaire.form + }) { + RoundedTextView("Start Medication Questionnaire", backgroundColor: .blue) } Spacer() diff --git a/GoogleService-Info.plist b/GoogleService-Info.plist new file mode 100644 index 0000000..27eb424 --- /dev/null +++ b/GoogleService-Info.plist @@ -0,0 +1,34 @@ + + + + + CLIENT_ID + 67502622712-81fir1q958agpr90cjkm02enm8oebb1e.apps.googleusercontent.com + REVERSED_CLIENT_ID + com.googleusercontent.apps.67502622712-81fir1q958agpr90cjkm02enm8oebb1e + API_KEY + AIzaSyBMdous87zD_1RpUzgnCA0swkGLjYb7Agk + GCM_SENDER_ID + 67502622712 + PLIST_VERSION + 1 + BUNDLE_ID + edu.stanford.cs342.Assignment-Two + PROJECT_ID + cs342-cch + STORAGE_BUCKET + cs342-cch.appspot.com + IS_ADS_ENABLED + + IS_ANALYTICS_ENABLED + + IS_APPINVITE_ENABLED + + IS_GCM_ENABLED + + IS_SIGNIN_ENABLED + + GOOGLE_APP_ID + 1:67502622712:ios:a8e5bf228e5d8ec365b80d + + \ No newline at end of file diff --git a/Podfile.lock b/Podfile.lock index 8a57376..316b8df 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -365,4 +365,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 98f88fc51cfb40838bdcf99149cc6ce9cc363723 -COCOAPODS: 1.10.0 +COCOAPODS: 1.10.1 diff --git a/Pods/Manifest.lock b/Pods/Manifest.lock index 8a57376..316b8df 100644 --- a/Pods/Manifest.lock +++ b/Pods/Manifest.lock @@ -365,4 +365,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 98f88fc51cfb40838bdcf99149cc6ce9cc363723 -COCOAPODS: 1.10.0 +COCOAPODS: 1.10.1 diff --git a/Pods/Pods.xcodeproj/project.pbxproj b/Pods/Pods.xcodeproj/project.pbxproj index 8ca38c0..8faf47b 100644 --- a/Pods/Pods.xcodeproj/project.pbxproj +++ b/Pods/Pods.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 50; + objectVersion = 51; objects = { /* Begin PBXAggregateTarget section */ @@ -21200,7 +21200,7 @@ LastUpgradeCheck = 1100; }; buildConfigurationList = 4821239608C13582E20E6DA73FD5F1F9 /* Build configuration list for PBXProject "Pods" */; - compatibilityVersion = "Xcode 9.3"; + compatibilityVersion = "Xcode 10.0"; developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( diff --git a/README.md b/README.md index 182f4b4..8859da3 100755 --- a/README.md +++ b/README.md @@ -7,4 +7,4 @@ Getting started with ResearchKit -biodesign logo \ No newline at end of file +biodesign logo