-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathDataType+Utilities.swift
75 lines (60 loc) · 1.56 KB
/
DataType+Utilities.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
//
// DataType+Utilities.swift
//
// Created by Dave Carlson on 2/18/17.
// Copyright © 2017 Clinical Cloud Solutions, LLC. All rights reserved.
//
import Foundation
import SMART
extension CodeableConcept {
func displayString(system: String? = nil) -> String? {
// if text is provided, use as default human-readable display
if let text = text?.string {
return text
}
var selectedCoding: Coding?
if let codeableConcepts = coding {
for coding in codeableConcepts {
if let codeSystem = system {
// if 'system' parameter included, use first matching Coding
if codeSystem == coding.system?.absoluteString {
selectedCoding = coding
break
}
}
else {
// use the first coding
selectedCoding = coding
break
}
}
}
return selectedCoding?.display?.string ?? selectedCoding?.code?.string
}
}
extension Period {
func displayString() -> String? {
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .medium
dateFormatter.timeStyle = .none
var startString: String?
var endString: String?
if let startDate = start {
startString = dateFormatter.string(from: startDate.nsDate)
}
if let endDate = end {
endString = dateFormatter.string(from: endDate.nsDate)
}
var displayString: String?
if let from = startString, let to = endString {
displayString = "Between " + from + " and " + to
}
else if let from = startString {
displayString = "After " + from
}
else if let to = endString {
displayString = "Before " + to
}
return displayString
}
}