-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathReport.swift
106 lines (77 loc) · 2.57 KB
/
Report.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
//
// Report.swift
// SMARTMarkers
//
// Created by Raheel Sayeed on 3/1/19.
// Copyright © 2019 Boston Children's Hospital. All rights reserved.
//
import Foundation
import SMART
/**
Report Protocol
All FHIR resources inheriting from `Resource` that are results of a PGHD `Instrument` must conform to the report protocol.
*/
public protocol Report: Resource {
/// FHIR resourceType
var rp_resourceType: String { get }
/// Identifier: usually `resource.id`
var rp_identifier: String? { get }
/// Display friendly title
var rp_title : String? { get }
/// Type of report; based on `Coding`
var rp_code: Coding? { get }
/// Report description
var rp_description: String? { get }
/// Date resource created/generated/updated
var rp_date: Date? { get }
/// Observation value; if any
var rp_observation: String? { get }
/// Representation `ViewController`
var rp_viewController: UIViewController? { get }
/// Assign a `Patient` to the generated Resource
@discardableResult
func sm_assign(patient: Patient) -> Bool
}
/**
Default extension for `Report`
rp_resourceType returns FHIR Resource Type; rp_viewController returns a generic `ReportViewController`
*/
public extension Report {
var rp_resourceType: String {
return sm_resourceType()
}
var rp_viewController: UIViewController? {
return ReportViewController(self)
}
var sm_Unit: String? {
if let slf = self as? Observation {
return slf.valueQuantity?.unit?.string ??
slf.valueQuantity?.code?.string ??
slf.component?.first?.valueQuantity?.unit?.string ??
slf.component?.first?.valueQuantity?.code?.string
}
return nil
}
}
public struct FHIRReportOptions {
public let resourceType: Report.Type
public let relation: [String: String]
public init(_ type: Report.Type, _ relation: [String: String]) {
self.resourceType = type
self.relation = relation
}
}
extension SMART.Bundle {
func sm_ContentSummary() -> String? {
let content = entry?.reduce(into: String(), { (bundleString, entry) in
let report = entry.resource as? Report
bundleString += report?.sm_resourceType() ?? "Type: \(entry.resource?.sm_resourceType() ?? "-")"
bundleString += ": " + (report?.rp_date?.shortDate ?? "-")
bundleString += "\n"
})
return content == nil ? nil : String(content!.dropLast())
}
func sm_resourceCount() -> Int {
return entry?.count ?? 0
}
}