-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtypes.jl
104 lines (86 loc) · 2.37 KB
/
types.jl
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
"""
Supertype of the various authentication types.
## Summary
abstract type Authentication <: Any
"""
abstract type Authentication end
"""
Subtypes of `FHIRVersion` are singleton structs that correspond to versions of the
FHIR specification.
## Summary
abstract type FHIRVersion <: Any
"""
abstract type FHIRVersion end
"""
The base URL for a FHIR server.
The base URL is also called the "Service Root URL"
## Summary
struct BaseURL <: Any
## Fields
- uri :: URIs.URI
"""
struct BaseURL
uri::URIs.URI
"""
BaseURL(base_url::Union{URIs.URI, AbstractString})
Construct a `BaseURL` object given the base URL.
The base URL is also called the "Service Root URL".
"""
function BaseURL(uri::Union{URIs.URI,AbstractString}; require_https::Bool = true)
_uri = uri isa URIs.URI ? uri : URIs.URI(uri)
if lowercase(_uri.scheme) != "https"
msg = "The following FHIR Base URL does not use HTTPS: $(uri)"
if require_https
throw(ArgumentError(msg))
else
@warn "`require_https` is set to `false` - we strongly recommend setting it to `true`"
@warn msg
end
end
return new(_uri)
end
end
"""
A FHIR client.
## Summary
struct Client{V <: FHIRVersion, A <: Authentication} <: Any
## Fields
- fhir_version :: V
- base_url :: BaseURL
- auth :: A
"""
struct Client{V<:FHIRVersion,A<:Authentication}
fhir_version::V
base_url::BaseURL
auth::A
end
get_auth(client::Client) = client.auth
get_base_url(client::Client) = client.base_url
get_fhir_version(client::Client) = client.fhir_version
function Base.shred!(client::Client)::Nothing
Base.shred!(client.auth)
return nothing
end
struct Credential
secret_buffer::Base.SecretBuffer
end
Credential() = Credential(Base.SecretBuffer())
struct AnonymousAuth <: Authentication end
struct JWTAuth <: Authentication
jwt_cred::Credential
end
JWTAuth() = JWTAuth(Credential())
struct OAuth2 <: Authentication
oauth2_cred::Credential
end
OAuth2() = OAuth2(Credential())
struct UsernamePassAuth <: Authentication
username::String
password_cred::Credential
end
@inline function UsernamePassAuth(username::AbstractString)
return UsernamePassAuth(username, Credential())
end
@inline function UsernamePassAuth(; username::AbstractString)
return UsernamePassAuth(username, Credential())
end