-
Notifications
You must be signed in to change notification settings - Fork 7
/
symptoms.go
79 lines (73 loc) · 1.8 KB
/
symptoms.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
package infermedica
import (
"encoding/json"
"net/http"
"time"
)
type SymptomRes struct {
ID string `json:"id"`
Name string `json:"name"`
CommonName string `json:"common_name"`
Category string `json:"category"`
Seriousness string `json:"seriousness"`
Children []SymptomChild `json:"children"`
ImageURL string `json:"image_url"`
ImageSource string `json:"image_source"`
ParentID string `json:"parent_id"`
ParentRelation string `json:"parent_relation"`
Question string `json:"question"`
SexFilter SexFilter `json:"sex_filter"`
}
type SymptomChild struct {
ID string `json:"id"`
ParentRelation string `json:"parent_relation"`
}
func (a *App) Symptoms() (*[]SymptomRes, error) {
req, err := a.prepareRequest("GET", "symptoms", nil)
if err != nil {
return nil, err
}
client := &http.Client{
Timeout: time.Second * 10,
}
res, err := client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
r := []SymptomRes{}
err = json.NewDecoder(res.Body).Decode(&r)
if err != nil {
return nil, err
}
return &r, nil
}
func (a *App) SymptomsIDMap() (*map[string]SymptomRes, error) {
r, err := a.Symptoms()
if err != nil {
return nil, err
}
rmap := make(map[string]SymptomRes)
for _, sr := range *r {
rmap[sr.ID] = sr
}
return &rmap, nil
}
func (a *App) SymptomByID(id string) (*SymptomRes, error) {
req, err := a.prepareRequest("GET", "symptoms/"+id, nil)
if err != nil {
return nil, err
}
client := &http.Client{}
res, err := client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
r := SymptomRes{}
err = json.NewDecoder(res.Body).Decode(&r)
if err != nil {
return nil, err
}
return &r, nil
}