-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMiniPatientVerificationController.swift
146 lines (112 loc) · 4.53 KB
/
MiniPatientVerificationController.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//
// PatientVerificationController.swift
// SMARTMarkers
//
// Created by Raheel Sayeed on 18/03/18.
// Copyright © 2018 Boston Children's Hospital. All rights reserved.
//
import UIKit
import SMART
class MiniPatientVerificationController: UIViewController {
let patient : Patient
let datePicker = UIDatePicker()
open var onCompletion : ((_ success: Bool) -> Void)?
init(patient: Patient ) {
datePicker.datePickerMode = .date
datePicker.translatesAutoresizingMaskIntoConstraints = false
self.patient = patient
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.white
configureView()
}
func continueToTasks() {
//Verification is always assumed to be the topMost hence can be popped.
if let navigationController = self.navigationController, navigationController.topViewController == self {
navigationController.popViewController(animated: true)
}
}
@objc func verifyPatient(_ sender: Any?) {
if verify() == false {
let alert = UIAlertController(title: "Verification Failed", message: "Incorrect entry, please try again or talk to the practitioner", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
alert.addAction(UIAlertAction(title: "DEMO:OVERRIDE", style: .destructive, handler: { [weak self] (_ ) in
self?.continueToTasks()
}))
present(alert, animated: true)
}
else {
continueToTasks()
}
}
@objc func cancelVerification(_ sender: Any?) {
LocalAuth.verifyDeviceUser { [weak self] (success, error) in
if success {
self?.dismiss(animated: true)
}
}
}
func verify() -> Bool {
return datePicker.date.fhir_asDate() == patient.birthDate
}
func roundButton(_ title: String) -> UIButton {
let frame = CGRect(x: 0, y: 0, width: 100, height: 100)
let btn = RoundedButton(frame: frame)
btn.translatesAutoresizingMaskIntoConstraints = false
btn.setTitle(title, for: .normal)
btn.titleLabel?.font = UIFont.systemFont(ofSize: 20)
return btn
}
func titleLabel(_ title: String) -> UILabel {
let titleLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 100))
titleLabel.font = UIFont.boldSystemFont(ofSize: 30)
titleLabel.text = title
titleLabel.textAlignment = .center
titleLabel.adjustsFontSizeToFitWidth = true
titleLabel.translatesAutoresizingMaskIntoConstraints = false
return titleLabel
}
func configureView() {
let verifyButton = roundButton("Verify")
verifyButton.addTarget(self, action: #selector(verifyPatient(_:)), for: .touchUpInside)
let cancelButton = UIButton(type: .roundedRect)
cancelButton.setTitle("Cancel", for: .normal)
cancelButton.titleLabel?.font = UIFont.systemFont(ofSize: 20)
cancelButton.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
cancelButton.translatesAutoresizingMaskIntoConstraints = false
cancelButton.addTarget(self, action: #selector(cancelVerification(_:)), for: .touchUpInside)
let titleLabel = self.titleLabel("Enter your birthday for Verification")
let subtitleLabel = self.titleLabel(patient.ep_MRNumber())
subtitleLabel.textColor = UIColor.lightGray
subtitleLabel.adjustsFontSizeToFitWidth = true
subtitleLabel.font = UIFont.systemFont(ofSize: 20)
let patientLabel = self.titleLabel(patient.humanName!)
let views = ["titlelbl" : titleLabel, "patientlbl": patientLabel, "verifyBtn" : verifyButton, "cancelBtn" : cancelButton, "datepicker" : datePicker, "subtitlelbl" : subtitleLabel]
Array(views.values).forEach { view.addSubview($0) }
func ac(_ s: String,_ vs: [String:Any]) {
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: s, options: [], metrics: nil, views: vs))
}
let centerY = NSLayoutConstraint(item: datePicker,
attribute: .centerY,
relatedBy: .equal,
toItem: view,
attribute: .centerY,
multiplier: 1.0,
constant: 0.0);
ac("V:|-40-[titlelbl]", views)
ac("H:|-[titlelbl]-|", views)
ac("H:|-[subtitlelbl]-|", views)
ac("H:|-70-[verifyBtn]-70-|", views)
ac("H:|-[datepicker]-|", views)
view.addConstraint(centerY)
ac("H:|-40-[patientlbl]-40-|", views)
ac("V:[patientlbl]-[subtitlelbl]-20-[datepicker]-20-[verifyBtn(60)]", views)
ac("H:|-70-[cancelBtn]-70-|", views)
ac("V:[verifyBtn]-30-[cancelBtn]", views )
}
}