-
Notifications
You must be signed in to change notification settings - Fork 7
/
labtests.go
109 lines (100 loc) · 2.33 KB
/
labtests.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
package infermedica
import (
"encoding/json"
"net/http"
"time"
"github.com/pkg/errors"
)
type LabTestsRes struct {
ID string `json:"id"`
Name string `json:"name"`
CommonName string `json:"common_name"`
Category string `json:"category"`
Results []LabResult `json:"results"`
}
type LabResult struct {
ID string `json:"id"`
Type string `json:"type"`
}
func (a *App) LabTests() (*[]LabTestsRes, error) {
req, err := a.prepareRequest("GET", "lab_tests", 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 := []LabTestsRes{}
err = json.NewDecoder(res.Body).Decode(&r)
if err != nil {
return nil, err
}
return &r, nil
}
func (a *App) LabTestsIDMap() (*map[string]LabTestsRes, error) {
r, err := a.LabTests()
if err != nil {
return nil, err
}
rmap := make(map[string]LabTestsRes)
for _, sr := range *r {
rmap[sr.ID] = sr
}
return &rmap, nil
}
func (a *App) LabTestByID(id string) (*LabTestsRes, error) {
req, err := a.prepareRequest("GET", "lab_tests/"+id, nil)
if err != nil {
return nil, err
}
client := &http.Client{}
res, err := client.Do(req)
if err != nil {
return nil, err
}
r := LabTestsRes{}
err = json.NewDecoder(res.Body).Decode(&r)
if err != nil {
return nil, err
}
return &r, nil
}
type LabTestsRecommendRes struct {
Recommended []LabTestsRecommendation `json:"recommended"`
Obligatory []LabTestsRecommendation `json:"obligatory"`
}
type LabTestsRecommendation struct {
PanelID string `json:"panel_id"`
Name string `json:"name"`
Position int `json:"position"`
LabTests []LabTestsID `json:"lab_tests"`
}
type LabTestsID struct {
ID string `json:"id"`
}
// Recommend is a func to request lab test recommendations for given data
func (a *App) LabTestsRecommend(dr DiagnosisReq) (*LabTestsRecommendRes, error) {
if !dr.Sex.IsValid() {
return nil, errors.New("Unexpected value for Sex")
}
req, err := a.prepareRequest("POST", "lab_tests/recommend", dr)
if err != nil {
return nil, err
}
client := &http.Client{}
res, err := client.Do(req)
if err != nil {
return nil, err
}
r := LabTestsRecommendRes{}
err = json.NewDecoder(res.Body).Decode(&r)
if err != nil {
return nil, err
}
return &r, nil
}