-
Notifications
You must be signed in to change notification settings - Fork 6
/
UserTask.swift
124 lines (81 loc) · 3.14 KB
/
UserTask.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
//
// UserTask.swift
// c3-pro
//
// Created by Pascal Pfiffner on 5/19/15.
// Copyright (c) 2015 Boston Children's Hospital. All rights reserved.
//
import Foundation
import SMART
/// The type of the task.
public enum UserTaskType: String {
case unknown = "unknown"
case consent = "consent"
case survey = "survey"
public var localizedName: String {
switch self {
case .consent: return "Consent".c3_localized
case .survey: return "Survey".c3_localized
default: return "Unknown".c3_localized
}
}
}
public let UserDidReceiveTaskNotification = Notification.Name(rawValue: "UserDidReceiveTask")
public let UserDidCompleteTaskNotification = Notification.Name(rawValue: "UserDidCompleteTask")
/// The key for Notification user dictionaries where one finds the associated User instance.
public let kUserTaskNotificationUserKey = "user"
/// To be used in notification's `userInfo` dictionaries.
public let kUserTaskNotificationTaskIdKey = "user-task-id"
/**
A task a user needs to complete, such as consenting or taking a survey.
*/
public protocol UserTask {
/// Unique identifier for the task instance, e.g. a UUID, as opposed to `taskId`.
var id: String { get }
/// An identifier for the task, e.g. "survey-1"; there can be multiple task instances for the same `taskId`.
var taskId: String { get }
/// The type of the task.
var type: UserTaskType { get }
/// The title of this task.
var title: String? { get set }
/// Which user this task is assigned to
var assignedTo: User? { get set }
/// The notification type of this task.
var notificationType: NotificationManagerNotificationType? { get set }
/// The day this task is due.
var dueDate: Date? { get set }
/// Whether this task is due and has neither been completed nor expired.
var due: Bool { get }
var humanDueDate: String? { get }
/// The day this task has been completed.
var completedDate: Date? { get set }
/// The day this task has expired or will expire (also the max date to which the user can delay the task).
var expiredDate: Date? { get set }
/// Human-readable date this task has either been completed or has expired.
var humanCompletedExpiredDate: String? { get }
/// Whether this task is pending.
var pending: Bool { get }
/// Whether this task has been completed.
var completed: Bool { get }
/// Whether this task has expired.
var expired: Bool { get }
/// Whether this task can be reviewed.
var canReview: Bool { get }
/// The resource resulting from this task, if any.
var resultResource: Resource? { get }
init(id: String, taskId: String, type: UserTaskType)
// MARK: - Creation & Completion
/** Call this method to let the user know about the new task and emit a notification. Should emit "UserDidReceiveTaskNotification". */
func add(to user: User) throws
/** Call this method to mark a task complete. */
func completed(on date: Date, with context: Any?)
// MARK: - Serialization
init(serialized: [String: Any]) throws
func serialized() -> [String: Any]
func serializedMinimal() -> [String: Any]
}
extension UserTask {
static func ==(a: UserTask, b: UserTask) -> Bool {
return a.id == b.id
}
}