-
Notifications
You must be signed in to change notification settings - Fork 7
/
conditions.go
188 lines (166 loc) · 4.17 KB
/
conditions.go
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package infermedica
import (
"encoding/json"
"fmt"
"net/http"
"strings"
"time"
)
type Prevalence string
const (
PrevalenceVeryRare Prevalence = "very_rare"
PrevalenceRare Prevalence = "rare"
PrevalenceModerate Prevalence = "moderate"
PrevalenceCommon Prevalence = "common"
)
func (p Prevalence) Ptr() *Prevalence { return &p }
func (p Prevalence) String() string { return string(p) }
func (p *Prevalence) IsValid() bool {
_, err := PrevalenceFromString(p.String())
if err != nil {
return false
}
return true
}
func PrevalenceFromString(x string) (Prevalence, error) {
switch strings.ToLower(x) {
case "very_rare":
return PrevalenceVeryRare, nil
case "rare":
return PrevalenceRare, nil
case "moderate":
return PrevalenceModerate, nil
case "common":
return PrevalenceCommon, nil
default:
return "", fmt.Errorf("Unexpected value for Prevalence: %q", x)
}
}
type Acuteness string
const (
AcutenessChronic Acuteness = "chronic"
AcutenessChronicWithExacerbations Acuteness = "chronic_with_exacerbations"
AcutenessAcutePotentiallyChronic Acuteness = "acute_potentially_chronic"
AcutenessAcute Acuteness = "acute"
)
func (a Acuteness) Ptr() *Acuteness { return &a }
func (a Acuteness) String() string { return string(a) }
func (a *Acuteness) IsValid() bool {
_, err := AcutenessFromString(a.String())
if err != nil {
return false
}
return true
}
func AcutenessFromString(x string) (Acuteness, error) {
switch strings.ToLower(x) {
case "chronic":
return AcutenessChronic, nil
case "chronic_with_exacerbations":
return AcutenessChronicWithExacerbations, nil
case "acute_potentially_chronic":
return AcutenessAcutePotentiallyChronic, nil
case "acute":
return AcutenessAcute, nil
default:
return "", fmt.Errorf("Unexpected value for Acuteness: %q", x)
}
}
type Severity string
const (
SeverityMild Severity = "mild"
SeverityModerate Severity = "moderate"
SeveritySevere Severity = "severe"
)
func (s Severity) Ptr() *Severity { return &s }
func (s Severity) String() string { return string(s) }
func (s *Severity) IsValid() bool {
_, err := SeverityFromString(s.String())
if err != nil {
return false
}
return true
}
func SeverityFromString(x string) (Severity, error) {
switch strings.ToLower(x) {
case "mild":
return SeverityMild, nil
case "moderate":
return SeverityModerate, nil
case "severe":
return SeveritySevere, nil
default:
return "", fmt.Errorf("Unexpected value for Severity: %q", x)
}
}
type Condition struct {
ID string `json:"id"`
Name string `json:"name"`
CommonName string `json:"common_name"`
ICD10Code string `json:"icd10_code"`
}
type ConditionRes struct {
Condition
SexFilter SexFilter `json:"sex_filter"`
Categories []string `json:"categories"`
Prevalence Prevalence `json:"prevalence"`
Acuteness Acuteness `json:"acuteness"`
Severity Severity `json:"severity"`
Extras ConditionExtras `json:"extras"`
TriageLevel string `json:"triage_level"`
}
type ConditionExtras struct {
Hint string `json:"hint"`
ICD10Code string `json:"icd10_code"`
}
func (a *App) Conditions() (*[]ConditionRes, error) {
req, err := a.prepareRequest("GET", "conditions", nil)
if err != nil {
return nil, err
}
client := &http.Client{
Timeout: time.Second * 5,
}
res, err := client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
r := []ConditionRes{}
err = json.NewDecoder(res.Body).Decode(&r)
if err != nil {
return nil, err
}
return &r, nil
}
func (a *App) ConditionsIDMap() (*map[string]ConditionRes, error) {
r, err := a.Conditions()
if err != nil {
return nil, err
}
rmap := make(map[string]ConditionRes)
for _, sr := range *r {
rmap[sr.ID] = sr
}
return &rmap, nil
}
func (a *App) ConditionByID(id string) (*ConditionRes, error) {
req, err := a.prepareGETRequest("conditions/" + id)
if err != nil {
return nil, err
}
client := &http.Client{
Timeout: time.Second * 5,
}
res, err := client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
r := ConditionRes{}
err = json.NewDecoder(res.Body).Decode(&r)
if err != nil {
return nil, err
}
return &r, nil
}