-
Notifications
You must be signed in to change notification settings - Fork 1
/
AppDelegate.swift
130 lines (106 loc) · 6.1 KB
/
AppDelegate.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
Copyright (c) 2019, Apple Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
3. Neither the name of the copyright holder(s) nor the names of any contributors
may be used to endorse or promote products derived from this software without
specific prior written permission. No license is granted to the trademarks of
the copyright holders even if such marks are included in this software.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import CareKit
import Contacts
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
// Manages synchronization of a CoreData store
lazy var synchronizedStoreManager: OCKSynchronizedStoreManager = {
let store = OCKStore(name: "SampleAppStore", type: .inMemory)
store.populateSampleData()
let manager = OCKSynchronizedStoreManager(wrapping: store)
return manager
}()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
return true
}
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
}
private extension OCKStore {
// Adds tasks and contacts into the store
func populateSampleData() {
let thisMorning = Calendar.current.startOfDay(for: Date())
let aFewDaysAgo = Calendar.current.date(byAdding: .day, value: -4, to: thisMorning)!
let beforeBreakfast = Calendar.current.date(byAdding: .hour, value: 8, to: aFewDaysAgo)!
let afterLunch = Calendar.current.date(byAdding: .hour, value: 14, to: aFewDaysAgo)!
let schedule = OCKSchedule(composing: [
OCKScheduleElement(start: beforeBreakfast, end: nil,
interval: DateComponents(day: 1)),
OCKScheduleElement(start: afterLunch, end: nil,
interval: DateComponents(day: 2))
])
var doxylamine = OCKTask(id: "doxylamine", title: "Take Doxylamine",
carePlanUUID: nil, schedule: schedule)
doxylamine.instructions = "Take 25mg of doxylamine when you experience nausea."
let nauseaSchedule = OCKSchedule(composing: [
OCKScheduleElement(start: beforeBreakfast, end: nil, interval: DateComponents(day: 1),
text: "Anytime throughout the day", targetValues: [], duration: .allDay)
])
var nausea = OCKTask(id: "nausea", title: "Track your nausea",
carePlanUUID: nil, schedule: nauseaSchedule)
nausea.impactsAdherence = false
nausea.instructions = "Tap the button below anytime you experience nausea."
let kegelSchedule = OCKSchedule(composing: [OCKScheduleElement(start: beforeBreakfast, end: nil, interval: DateComponents(day: 2))])
var kegels = OCKTask(id: "kegels", title: "Kegel Exercises", carePlanUUID: nil, schedule: kegelSchedule)
kegels.impactsAdherence = true
kegels.instructions = "Perform kegel exercies"
addTasks([nausea, doxylamine, kegels], callbackQueue: .main, completion: nil)
var contact1 = OCKContact(id: "jane", givenName: "Jane",
familyName: "Daniels", carePlanUUID: nil)
contact1.asset = "JaneDaniels"
contact1.title = "Family Practice Doctor"
contact1.role = "Dr. Daniels is a family practice doctor with 8 years of experience."
contact1.emailAddresses = [OCKLabeledValue(label: CNLabelEmailiCloud, value: "janedaniels@icloud.com")]
contact1.phoneNumbers = [OCKLabeledValue(label: CNLabelWork, value: "(324) 555-7415")]
contact1.messagingNumbers = [OCKLabeledValue(label: CNLabelWork, value: "(324) 555-7415")]
contact1.address = {
let address = OCKPostalAddress()
address.street = "2598 Reposa Way"
address.city = "San Francisco"
address.state = "CA"
address.postalCode = "94127"
return address
}()
var contact2 = OCKContact(id: "matthew", givenName: "Matthew",
familyName: "Reiff", carePlanUUID: nil)
contact2.asset = "MatthewReiff"
contact2.title = "OBGYN"
contact2.role = "Dr. Reiff is an OBGYN with 13 years of experience."
contact2.phoneNumbers = [OCKLabeledValue(label: CNLabelWork, value: "(324) 555-7415")]
contact2.messagingNumbers = [OCKLabeledValue(label: CNLabelWork, value: "(324) 555-7415")]
contact2.address = {
let address = OCKPostalAddress()
address.street = "396 El Verano Way"
address.city = "San Francisco"
address.state = "CA"
address.postalCode = "94127"
return address
}()
addContacts([contact1, contact2])
}
}