|
@@ -2,11 +2,13 @@ package controllers
|
2
|
2
|
|
3
|
3
|
import (
|
4
|
4
|
"XT_New/enums"
|
|
5
|
+ "XT_New/models"
|
5
|
6
|
"XT_New/service"
|
6
|
7
|
"XT_New/utils"
|
7
|
8
|
"fmt"
|
8
|
9
|
"github.com/astaxie/beego"
|
9
|
10
|
"strconv"
|
|
11
|
+ "strings"
|
10
|
12
|
"time"
|
11
|
13
|
)
|
12
|
14
|
|
|
@@ -26,6 +28,465 @@ func StatisticsApiRegistRouters() {
|
26
|
28
|
beego.Router("/api/commonqc/statistiscperson/get", &StatisticsApiController{}, "get:GetPersonCommonInspectionStatistisc")
|
27
|
29
|
beego.Router("/api/commonqc/patientstatistiscall/get", &StatisticsApiController{}, "get:GetPatientCommonInspectionStatistisc")
|
28
|
30
|
|
|
31
|
+ //透析总量统计
|
|
32
|
+ beego.Router("/api/commonqc/dialysis/total", &StatisticsApiController{}, "get:GetDialysisTotal")
|
|
33
|
+ beego.Router("/api/commonqc/dialysis/detail", &StatisticsApiController{}, "get:GetDialysisTotalDetail")
|
|
34
|
+ beego.Router("/api/commonqc/dialysis/details", &StatisticsApiController{}, "get:GetDialysisTotalDetailInfo")
|
|
35
|
+
|
|
36
|
+ beego.Router("/api/commonqc/anticoagulant", &StatisticsApiController{}, "get:GetAnticoagulant")
|
|
37
|
+ beego.Router("/api/commonqc/anticoagulant/detail", &StatisticsApiController{}, "get:GetAnticoagulantDetail")
|
|
38
|
+
|
|
39
|
+ beego.Router("/api/commonqc/dialyzer", &StatisticsApiController{}, "get:GetDialyzer")
|
|
40
|
+ beego.Router("/api/commonqc/dialyzer/config", &StatisticsApiController{}, "get:GetDialyzerConfig")
|
|
41
|
+ beego.Router("/api/commonqc/dialyzer/detail", &StatisticsApiController{}, "get:GetDialyzerDetail")
|
|
42
|
+
|
|
43
|
+ beego.Router("/api/commonqc/dialysistreat/finish", &StatisticsApiController{}, "get:GetDialysisTreatFinsh")
|
|
44
|
+ beego.Router("/api/commonqc/dialysistreat/detail", &StatisticsApiController{}, "get:GetDialysisTreatDetail")
|
|
45
|
+
|
|
46
|
+}
|
|
47
|
+
|
|
48
|
+func (c *StatisticsApiController) GetDialysisTreatFinsh() {
|
|
49
|
+ start_date := c.GetString("start_date")
|
|
50
|
+ end_date := c.GetString("end_date")
|
|
51
|
+ timeLayout := "2006-01-02"
|
|
52
|
+ loc, _ := time.LoadLocation("Local")
|
|
53
|
+ var startTime int64
|
|
54
|
+ if len(start_date) > 0 {
|
|
55
|
+ theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
|
|
56
|
+ fmt.Println("err-----------", err)
|
|
57
|
+ if err != nil {
|
|
58
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
59
|
+ return
|
|
60
|
+ }
|
|
61
|
+ startTime = theTime.Unix()
|
|
62
|
+ }
|
|
63
|
+ var endTime int64
|
|
64
|
+ if len(end_date) > 0 {
|
|
65
|
+ theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
|
|
66
|
+ if err != nil {
|
|
67
|
+ utils.ErrorLog(err.Error())
|
|
68
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
69
|
+ return
|
|
70
|
+ }
|
|
71
|
+ endTime = theTime.Unix()
|
|
72
|
+ }
|
|
73
|
+ data, _ := service.GetDialysisCompletionRate(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime)
|
|
74
|
+ total, _ := service.GetDialysisCompletionTotal(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime)
|
|
75
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
76
|
+ "data": data,
|
|
77
|
+ "total": total,
|
|
78
|
+ })
|
|
79
|
+}
|
|
80
|
+func (c *StatisticsApiController) GetDialysisTreatDetail() {
|
|
81
|
+ start_date := c.GetString("start_date")
|
|
82
|
+ end_date := c.GetString("end_date")
|
|
83
|
+ mode, _ := c.GetInt64("mode")
|
|
84
|
+ page, _ := c.GetInt64("page", 0)
|
|
85
|
+ limit, _ := c.GetInt64("limit", 0)
|
|
86
|
+ if page <= 0 {
|
|
87
|
+ page = 1
|
|
88
|
+ }
|
|
89
|
+ if limit <= 0 {
|
|
90
|
+ limit = 10
|
|
91
|
+ }
|
|
92
|
+ timeLayout := "2006-01-02"
|
|
93
|
+ loc, _ := time.LoadLocation("Local")
|
|
94
|
+ var startTime int64
|
|
95
|
+ if len(start_date) > 0 {
|
|
96
|
+ theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
|
|
97
|
+ fmt.Println("err-----------", err)
|
|
98
|
+ if err != nil {
|
|
99
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
100
|
+ return
|
|
101
|
+ }
|
|
102
|
+ startTime = theTime.Unix()
|
|
103
|
+ }
|
|
104
|
+ var endTime int64
|
|
105
|
+ if len(end_date) > 0 {
|
|
106
|
+ theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
|
|
107
|
+ if err != nil {
|
|
108
|
+ utils.ErrorLog(err.Error())
|
|
109
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
110
|
+ return
|
|
111
|
+ }
|
|
112
|
+ endTime = theTime.Unix()
|
|
113
|
+ }
|
|
114
|
+ data, total, _ := service.GetDialysisCompletionDetail(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime, mode, limit, page)
|
|
115
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
116
|
+ "list": data,
|
|
117
|
+ "total": total,
|
|
118
|
+ })
|
|
119
|
+}
|
|
120
|
+
|
|
121
|
+func (c *StatisticsApiController) GetDialysisTotal() {
|
|
122
|
+ start_date := c.GetString("start_date")
|
|
123
|
+ end_date := c.GetString("end_date")
|
|
124
|
+ mode, _ := c.GetInt64("mode")
|
|
125
|
+ origin, _ := c.GetInt64("origin")
|
|
126
|
+ time_way, _ := c.GetInt64("time_way")
|
|
127
|
+
|
|
128
|
+ timeLayout := "2006-01-02"
|
|
129
|
+ loc, _ := time.LoadLocation("Local")
|
|
130
|
+ var startTime int64
|
|
131
|
+ if len(start_date) > 0 {
|
|
132
|
+ theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
|
|
133
|
+ fmt.Println("err-----------", err)
|
|
134
|
+ if err != nil {
|
|
135
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
136
|
+ return
|
|
137
|
+ }
|
|
138
|
+ startTime = theTime.Unix()
|
|
139
|
+ }
|
|
140
|
+ var endTime int64
|
|
141
|
+ if len(end_date) > 0 {
|
|
142
|
+ theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
|
|
143
|
+ if err != nil {
|
|
144
|
+ utils.ErrorLog(err.Error())
|
|
145
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
146
|
+ return
|
|
147
|
+ }
|
|
148
|
+ endTime = theTime.Unix()
|
|
149
|
+ }
|
|
150
|
+ if mode == 0 { //统计透析模式不限
|
|
151
|
+ //获取总人数
|
|
152
|
+ p_total, _ := service.GetNewDialysiTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, origin)
|
|
153
|
+ count_struct, _ := service.GetNewDialysisCountMode(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, origin, 0)
|
|
154
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
155
|
+ "patient_count": p_total,
|
|
156
|
+ "list": count_struct,
|
|
157
|
+ })
|
|
158
|
+ } else { //固定某个模式
|
|
159
|
+ // 拆分日期范围
|
|
160
|
+ dates, err := splitDateRange(start_date, end_date)
|
|
161
|
+ if err != nil {
|
|
162
|
+ fmt.Println("Error:", err)
|
|
163
|
+ return
|
|
164
|
+ }
|
|
165
|
+
|
|
166
|
+ var cuss []models.CustomDialysisData
|
|
167
|
+ p_total, _ := service.GetNewDialysiTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, origin)
|
|
168
|
+ switch time_way {
|
|
169
|
+ case 1:
|
|
170
|
+ // 按周统计
|
|
171
|
+ weeks := groupByWeek(dates)
|
|
172
|
+ for _, week := range weeks {
|
|
173
|
+ var cus models.CustomDialysisData
|
|
174
|
+ counts, _ := service.GetNewDialysisCountModeTwo(week[0].Unix(), week[len(week)-1].Unix(), c.GetAdminUserInfo().CurrentOrgId, origin, mode)
|
|
175
|
+ cus.Date = strings.Split(week[0].String(), " ")[0] + "~" + strings.Split(week[len(week)-1].String(), " ")[0]
|
|
176
|
+ cus.Count = counts.Count
|
|
177
|
+ cus.Total = p_total
|
|
178
|
+ cuss = append(cuss, cus)
|
|
179
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
180
|
+ "list": cuss,
|
|
181
|
+ })
|
|
182
|
+ }
|
|
183
|
+
|
|
184
|
+ break
|
|
185
|
+ case 2:
|
|
186
|
+ startDate, err := time.Parse("2006-01-02", start_date)
|
|
187
|
+ if err != nil {
|
|
188
|
+ fmt.Println("Error parsing start date:", err)
|
|
189
|
+ return
|
|
190
|
+ }
|
|
191
|
+
|
|
192
|
+ endDate, err := time.Parse("2006-01-02", end_date)
|
|
193
|
+ if err != nil {
|
|
194
|
+ fmt.Println("Error parsing end date:", err)
|
|
195
|
+ return
|
|
196
|
+ }
|
|
197
|
+ dailyDates := splitByDay(startDate, endDate)
|
|
198
|
+ for _, date := range dailyDates {
|
|
199
|
+ //fmt.Println(date)
|
|
200
|
+ var cus models.CustomDialysisData
|
|
201
|
+ counts, _ := service.GetNewDialysisCountModeTwo(date.Unix(), date.Unix(), c.GetAdminUserInfo().CurrentOrgId, origin, mode)
|
|
202
|
+ cus.Date = date.Format("2006-01-02")
|
|
203
|
+ cus.Count = counts.Count
|
|
204
|
+ cus.Total = p_total
|
|
205
|
+ cuss = append(cuss, cus)
|
|
206
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
207
|
+ "list": cuss,
|
|
208
|
+ })
|
|
209
|
+
|
|
210
|
+ }
|
|
211
|
+
|
|
212
|
+ break
|
|
213
|
+ case 3:
|
|
214
|
+ // 按月统计
|
|
215
|
+ months := groupByMonth(dates)
|
|
216
|
+ for _, month := range months {
|
|
217
|
+ var cus models.CustomDialysisData
|
|
218
|
+ counts, _ := service.GetNewDialysisCountModeTwo(month[0].Unix(), month[len(month)-1].Unix(), c.GetAdminUserInfo().CurrentOrgId, origin, mode)
|
|
219
|
+ cus.Date = strings.Split(month[0].String(), " ")[0] + "~" + strings.Split(month[len(month)-1].String(), " ")[0]
|
|
220
|
+ cus.Count = counts.Count
|
|
221
|
+ cus.Total = p_total
|
|
222
|
+ cuss = append(cuss, cus)
|
|
223
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
224
|
+ "list": cuss,
|
|
225
|
+ })
|
|
226
|
+ //fmt.Println("Month:", month[0], "~", month[len(month)-1])
|
|
227
|
+ }
|
|
228
|
+ break
|
|
229
|
+ case 4:
|
|
230
|
+ // 按年统计
|
|
231
|
+ years := groupByYear(dates)
|
|
232
|
+ for _, year := range years {
|
|
233
|
+ var cus models.CustomDialysisData
|
|
234
|
+ counts, _ := service.GetNewDialysisCountModeTwo(year[0].Unix(), year[len(year)-1].Unix(), c.GetAdminUserInfo().CurrentOrgId, origin, mode)
|
|
235
|
+ cus.Date = strings.Split(year[0].String(), " ")[0] + "~" + strings.Split(year[len(year)-1].String(), " ")[0]
|
|
236
|
+ cus.Count = counts.Count
|
|
237
|
+ cus.Total = p_total
|
|
238
|
+ cuss = append(cuss, cus)
|
|
239
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
240
|
+ "list": cuss,
|
|
241
|
+ })
|
|
242
|
+ }
|
|
243
|
+ break
|
|
244
|
+ }
|
|
245
|
+ }
|
|
246
|
+
|
|
247
|
+}
|
|
248
|
+func (c *StatisticsApiController) GetDialysisTotalDetail() {
|
|
249
|
+ start_date := c.GetString("start_date")
|
|
250
|
+ end_date := c.GetString("end_date")
|
|
251
|
+ mode, _ := c.GetInt64("mode")
|
|
252
|
+ origin, _ := c.GetInt64("origin")
|
|
253
|
+ time_way, _ := c.GetInt64("time_way")
|
|
254
|
+ timeLayout := "2006-01-02"
|
|
255
|
+ loc, _ := time.LoadLocation("Local")
|
|
256
|
+ var startTime int64
|
|
257
|
+ if len(start_date) > 0 {
|
|
258
|
+ theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
|
|
259
|
+ fmt.Println("err-----------", err)
|
|
260
|
+ if err != nil {
|
|
261
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
262
|
+ return
|
|
263
|
+ }
|
|
264
|
+ startTime = theTime.Unix()
|
|
265
|
+ }
|
|
266
|
+ var endTime int64
|
|
267
|
+ if len(end_date) > 0 {
|
|
268
|
+ theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
|
|
269
|
+ if err != nil {
|
|
270
|
+ utils.ErrorLog(err.Error())
|
|
271
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
272
|
+ return
|
|
273
|
+ }
|
|
274
|
+ endTime = theTime.Unix()
|
|
275
|
+ }
|
|
276
|
+
|
|
277
|
+ if origin == 1 {
|
|
278
|
+ data, _ := service.GetDialysisStats(startTime, endTime, time_way, mode)
|
|
279
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
280
|
+ "data": data,
|
|
281
|
+ })
|
|
282
|
+ } else {
|
|
283
|
+ data, _ := service.GetScheduleStats(startTime, endTime, time_way, mode)
|
|
284
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
285
|
+ "data": data,
|
|
286
|
+ })
|
|
287
|
+ }
|
|
288
|
+}
|
|
289
|
+func (c *StatisticsApiController) GetDialysisTotalDetailInfo() {
|
|
290
|
+
|
|
291
|
+}
|
|
292
|
+
|
|
293
|
+func (c *StatisticsApiController) GetAnticoagulant() {
|
|
294
|
+ start_date := c.GetString("start_date")
|
|
295
|
+ end_date := c.GetString("end_date")
|
|
296
|
+ timeLayout := "2006-01-02"
|
|
297
|
+ loc, _ := time.LoadLocation("Local")
|
|
298
|
+ var startTime int64
|
|
299
|
+ if len(start_date) > 0 {
|
|
300
|
+ theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
|
|
301
|
+ fmt.Println("err-----------", err)
|
|
302
|
+ if err != nil {
|
|
303
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
304
|
+ return
|
|
305
|
+ }
|
|
306
|
+ startTime = theTime.Unix()
|
|
307
|
+ }
|
|
308
|
+ var endTime int64
|
|
309
|
+ if len(end_date) > 0 {
|
|
310
|
+ theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
|
|
311
|
+ if err != nil {
|
|
312
|
+ utils.ErrorLog(err.Error())
|
|
313
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
314
|
+ return
|
|
315
|
+ }
|
|
316
|
+ endTime = theTime.Unix()
|
|
317
|
+ }
|
|
318
|
+
|
|
319
|
+ total, err2 := service.GetAnticoagulantTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
|
|
320
|
+ if err2 != nil {
|
|
321
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
322
|
+ return
|
|
323
|
+ }
|
|
324
|
+ anticoagulantData, err := service.GetAnticoagulantData(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
|
|
325
|
+ if err != nil {
|
|
326
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
327
|
+ return
|
|
328
|
+ }
|
|
329
|
+ type respData struct {
|
|
330
|
+ Name string `json:"name"`
|
|
331
|
+ Count int `json:"count"`
|
|
332
|
+ Percentage float64 `json:"percentage"`
|
|
333
|
+ }
|
|
334
|
+ var respDatas []respData
|
|
335
|
+ for anticoagulant, count := range anticoagulantData {
|
|
336
|
+ var respData respData
|
|
337
|
+ respData.Name = anticoagulant
|
|
338
|
+ respData.Count = count
|
|
339
|
+ respData.Percentage = float64(count) / float64(total) * 100
|
|
340
|
+ respDatas = append(respDatas, respData)
|
|
341
|
+ }
|
|
342
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
343
|
+ "data": respDatas,
|
|
344
|
+ })
|
|
345
|
+
|
|
346
|
+}
|
|
347
|
+func (c *StatisticsApiController) GetAnticoagulantDetail() {
|
|
348
|
+ anticoagulant, _ := c.GetInt64("anticoagulant")
|
|
349
|
+ start_date := c.GetString("start_date")
|
|
350
|
+ end_date := c.GetString("end_date")
|
|
351
|
+ timeLayout := "2006-01-02"
|
|
352
|
+ page, _ := c.GetInt64("page", 0)
|
|
353
|
+ limit, _ := c.GetInt64("limit", 0)
|
|
354
|
+ if page <= 0 {
|
|
355
|
+ page = 1
|
|
356
|
+ }
|
|
357
|
+ if limit <= 0 {
|
|
358
|
+ limit = 10
|
|
359
|
+ }
|
|
360
|
+ loc, _ := time.LoadLocation("Local")
|
|
361
|
+ var startTime int64
|
|
362
|
+ if len(start_date) > 0 {
|
|
363
|
+ theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
|
|
364
|
+ fmt.Println("err-----------", err)
|
|
365
|
+ if err != nil {
|
|
366
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
367
|
+ return
|
|
368
|
+ }
|
|
369
|
+ startTime = theTime.Unix()
|
|
370
|
+ }
|
|
371
|
+ var endTime int64
|
|
372
|
+ if len(end_date) > 0 {
|
|
373
|
+ theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
|
|
374
|
+ if err != nil {
|
|
375
|
+ utils.ErrorLog(err.Error())
|
|
376
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
377
|
+ return
|
|
378
|
+ }
|
|
379
|
+ endTime = theTime.Unix()
|
|
380
|
+ }
|
|
381
|
+ prescriptions, total, _ := service.GetPrescriptionByAnticoagulant(page, limit, c.GetAdminUserInfo().CurrentOrgId, anticoagulant, startTime, endTime)
|
|
382
|
+
|
|
383
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
384
|
+ "prescriptions": prescriptions,
|
|
385
|
+ "total": total,
|
|
386
|
+ })
|
|
387
|
+
|
|
388
|
+}
|
|
389
|
+
|
|
390
|
+func (c *StatisticsApiController) GetDialyzer() {
|
|
391
|
+ start_date := c.GetString("start_date")
|
|
392
|
+ end_date := c.GetString("end_date")
|
|
393
|
+ timeLayout := "2006-01-02"
|
|
394
|
+ loc, _ := time.LoadLocation("Local")
|
|
395
|
+ var startTime int64
|
|
396
|
+ if len(start_date) > 0 {
|
|
397
|
+ theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
|
|
398
|
+ fmt.Println("err-----------", err)
|
|
399
|
+ if err != nil {
|
|
400
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
401
|
+ return
|
|
402
|
+ }
|
|
403
|
+ startTime = theTime.Unix()
|
|
404
|
+ }
|
|
405
|
+ var endTime int64
|
|
406
|
+ if len(end_date) > 0 {
|
|
407
|
+ theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
|
|
408
|
+ if err != nil {
|
|
409
|
+ utils.ErrorLog(err.Error())
|
|
410
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
411
|
+ return
|
|
412
|
+ }
|
|
413
|
+ endTime = theTime.Unix()
|
|
414
|
+ }
|
|
415
|
+
|
|
416
|
+ total, err2 := service.GetDialyzerTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
|
|
417
|
+ if err2 != nil {
|
|
418
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
419
|
+ return
|
|
420
|
+ }
|
|
421
|
+ dialyzers, err := service.GetDialyzerData(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
|
|
422
|
+ if err != nil {
|
|
423
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
424
|
+ return
|
|
425
|
+ }
|
|
426
|
+ type respData struct {
|
|
427
|
+ Name string `json:"name"`
|
|
428
|
+ Count int `json:"count"`
|
|
429
|
+ Percentage float64 `json:"percentage"`
|
|
430
|
+ }
|
|
431
|
+ var respDatas []respData
|
|
432
|
+ for _, item := range dialyzers {
|
|
433
|
+ var respData respData
|
|
434
|
+ respData.Name = item.Dialyzer
|
|
435
|
+ respData.Count = item.Count
|
|
436
|
+ respData.Percentage = float64(item.Count) / float64(total) * 100
|
|
437
|
+ respDatas = append(respDatas, respData)
|
|
438
|
+ }
|
|
439
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
440
|
+ "data": respDatas,
|
|
441
|
+ })
|
|
442
|
+
|
|
443
|
+}
|
|
444
|
+func (c *StatisticsApiController) GetDialyzerDetail() {
|
|
445
|
+ dialyzer := c.GetString("Dialyzer")
|
|
446
|
+ start_date := c.GetString("start_date")
|
|
447
|
+ end_date := c.GetString("end_date")
|
|
448
|
+ timeLayout := "2006-01-02"
|
|
449
|
+ page, _ := c.GetInt64("page", 0)
|
|
450
|
+ limit, _ := c.GetInt64("limit", 0)
|
|
451
|
+ if page <= 0 {
|
|
452
|
+ page = 1
|
|
453
|
+ }
|
|
454
|
+ if limit <= 0 {
|
|
455
|
+ limit = 10
|
|
456
|
+ }
|
|
457
|
+ loc, _ := time.LoadLocation("Local")
|
|
458
|
+ var startTime int64
|
|
459
|
+ if len(start_date) > 0 {
|
|
460
|
+ theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
|
|
461
|
+ fmt.Println("err-----------", err)
|
|
462
|
+ if err != nil {
|
|
463
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
464
|
+ return
|
|
465
|
+ }
|
|
466
|
+ startTime = theTime.Unix()
|
|
467
|
+ }
|
|
468
|
+ var endTime int64
|
|
469
|
+ if len(end_date) > 0 {
|
|
470
|
+ theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
|
|
471
|
+ if err != nil {
|
|
472
|
+ utils.ErrorLog(err.Error())
|
|
473
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
474
|
+ return
|
|
475
|
+ }
|
|
476
|
+ endTime = theTime.Unix()
|
|
477
|
+ }
|
|
478
|
+ prescriptions, total, _ := service.GetPrescriptionByDialyzer(page, limit, c.GetAdminUserInfo().CurrentOrgId, dialyzer, startTime, endTime)
|
|
479
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
480
|
+ "prescriptions": prescriptions,
|
|
481
|
+ "total": total,
|
|
482
|
+ })
|
|
483
|
+
|
|
484
|
+}
|
|
485
|
+func (c *StatisticsApiController) GetDialyzerConfig() {
|
|
486
|
+ dialyzers, _ := service.GetDialyzerSummary(c.GetAdminUserInfo().CurrentOrgId)
|
|
487
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
488
|
+ "dialyzers": dialyzers,
|
|
489
|
+ })
|
29
|
490
|
}
|
30
|
491
|
|
31
|
492
|
// 配置检验数据查询
|
|
@@ -206,34 +667,148 @@ func (c *StatisticsApiController) GetPatientCommonInspectionStatistisc() {
|
206
|
667
|
}
|
207
|
668
|
|
208
|
669
|
func (c *StatisticsApiController) GetFivePatientInspectionStatistisc() {
|
209
|
|
- start_date := c.GetString("start_date")
|
|
670
|
+ //start_date := c.GetString("start_date")
|
210
|
671
|
end_date := c.GetString("end_date")
|
211
|
|
- keyword := c.GetString("keyword")
|
212
|
|
- timeLayout := "2006-01-02"
|
213
|
|
- loc, _ := time.LoadLocation("Local")
|
214
|
|
- var startTime int64
|
215
|
|
- if len(start_date) > 0 {
|
216
|
|
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
|
217
|
|
- if err != nil {
|
218
|
|
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
219
|
|
- return
|
|
672
|
+ //keyword := c.GetString("keyword")
|
|
673
|
+ //timeLayout := "2006-01-02"
|
|
674
|
+ //loc, _ := time.LoadLocation("Local")
|
|
675
|
+
|
|
676
|
+ dynamicFields := make([]map[string]interface{}, 0)
|
|
677
|
+ list, _ := service.GetLatestInspectionValues(c.GetAdminUserInfo().CurrentOrgId, strings.Split(end_date, "-")[0]+"-"+strings.Split(end_date, "-")[1])
|
|
678
|
+ fmt.Println(list)
|
|
679
|
+
|
|
680
|
+ for _, result := range list {
|
|
681
|
+ fmt.Println(result)
|
|
682
|
+ // 打印患者ID
|
|
683
|
+ nb := result["姓名"].([]byte)
|
|
684
|
+ name := string(nb)
|
|
685
|
+
|
|
686
|
+ //ynamicFields := make([]map[string]interface{})
|
|
687
|
+
|
|
688
|
+ //var dynamicFields DynamicData
|
|
689
|
+ ynamicField := make(map[string]interface{})
|
|
690
|
+ ynamicField["姓名"] = name
|
|
691
|
+ // 打印其他列的值
|
|
692
|
+ for columnName, columnValue := range result {
|
|
693
|
+ // 跳过患者ID列
|
|
694
|
+
|
|
695
|
+ if columnName == "姓名" {
|
|
696
|
+ continue
|
|
697
|
+ }
|
|
698
|
+ // 检查值是否为nil
|
|
699
|
+ if columnValue == nil {
|
|
700
|
+ fmt.Printf("Column: %s, Value: <nil>\n", columnName)
|
|
701
|
+ continue
|
|
702
|
+ }
|
|
703
|
+
|
|
704
|
+ // 将字节切片转换为字符串
|
|
705
|
+ byteValue, ok := columnValue.([]byte)
|
|
706
|
+ if !ok {
|
|
707
|
+ // 如果无法转换为[]byte,输出错误信息
|
|
708
|
+ fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
|
|
709
|
+ continue
|
|
710
|
+ }
|
|
711
|
+
|
|
712
|
+ // 将字节切片转换为字符串
|
|
713
|
+ strValue := string(byteValue)
|
|
714
|
+
|
|
715
|
+ // 尝试将字符串转换为浮点数
|
|
716
|
+ floatValue, err := strconv.ParseFloat(strValue, 64)
|
|
717
|
+ if err != nil {
|
|
718
|
+ // 如果转换失败,输出错误信息
|
|
719
|
+ fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
|
|
720
|
+ } else {
|
|
721
|
+ // 如果转换成功,输出列名和浮点数值
|
|
722
|
+ fmt.Printf("Column: %s, Value: %f\n", columnName, floatValue)
|
|
723
|
+ }
|
|
724
|
+ ynamicField["年月"] = strings.Split(end_date, "-")[0] + "-" + strings.Split(end_date, "-")[1]
|
|
725
|
+ ynamicField[columnName] = floatValue
|
|
726
|
+ dynamicFields = append(dynamicFields, ynamicField)
|
220
|
727
|
}
|
221
|
|
- startTime = theTime.Unix()
|
222
|
728
|
}
|
223
|
|
- var endTime int64
|
224
|
|
- if len(end_date) > 0 {
|
225
|
|
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
|
226
|
|
- if err != nil {
|
227
|
|
- utils.ErrorLog(err.Error())
|
228
|
|
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
229
|
|
- return
|
|
729
|
+
|
|
730
|
+ seen := make(map[interface{}]struct{})
|
|
731
|
+ var uniqueFields []map[string]interface{}
|
|
732
|
+
|
|
733
|
+ for _, field := range dynamicFields {
|
|
734
|
+ value := field["姓名"]
|
|
735
|
+ // 如果值未在map中出现过,则将其添加到新的切片中,并将其添加到map中
|
|
736
|
+ if _, ok := seen[value]; !ok {
|
|
737
|
+ seen[value] = struct{}{}
|
|
738
|
+ uniqueFields = append(uniqueFields, field)
|
230
|
739
|
}
|
231
|
|
- endTime = theTime.Unix()
|
232
|
740
|
}
|
233
|
|
- list, _ := service.GetPatientFiveInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, keyword)
|
|
741
|
+
|
234
|
742
|
c.ServeSuccessJSON(map[string]interface{}{
|
235
|
|
- "list": list,
|
|
743
|
+ "list": uniqueFields,
|
236
|
744
|
})
|
|
745
|
+ //list, _ := service.GetPatientFiveInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, keyword)
|
|
746
|
+ //
|
|
747
|
+ //var names []string
|
|
748
|
+ //
|
|
749
|
+ //for _, item := range list {
|
|
750
|
+ // names = append(names, item.ItemName)
|
|
751
|
+ //}
|
|
752
|
+ //
|
|
753
|
+ //names = RemoveRepeatedNameElement(names)
|
|
754
|
+ //fmt.Println(names)
|
|
755
|
+ //
|
|
756
|
+ //var tempList []models.InspectionTen
|
|
757
|
+ //list_two := RemoveRepeatedInspectPatientElement(list)
|
|
758
|
+ //for _, item := range list_two {
|
|
759
|
+ // var temp models.InspectionTen
|
|
760
|
+ // var temptwos []models.InspectionValue
|
|
761
|
+ // temp.PatientId = item.PatientId
|
|
762
|
+ // temp.Name = item.Name
|
|
763
|
+ // for _, subitem := range list {
|
|
764
|
+ // if item.PatientId == subitem.PatientId {
|
|
765
|
+ // var temptwo models.InspectionValue
|
|
766
|
+ // temptwo.Name = subitem.ItemName
|
|
767
|
+ // temptwo.Value = subitem.InspectValue
|
|
768
|
+ // temptwos = append(temptwos, temptwo)
|
|
769
|
+ // }
|
|
770
|
+ // }
|
|
771
|
+ // temp.Values = temptwos
|
|
772
|
+ // tempList = append(tempList, temp)
|
|
773
|
+ //}
|
|
774
|
+ //
|
|
775
|
+ //var filtered []string
|
|
776
|
+ //for _, item := range names {
|
|
777
|
+ // if item != "a" {
|
|
778
|
+ // filtered = append(filtered, item)
|
|
779
|
+ // }
|
|
780
|
+ //}
|
|
781
|
+ //
|
|
782
|
+ //for _, item := range tempList {
|
|
783
|
+ // for _, subitem := range item.Values {
|
|
784
|
+ // for _, name := range filtered {
|
|
785
|
+ // if subitem.Name != name {
|
|
786
|
+ // filtered = append(filtered, name)
|
|
787
|
+ // }
|
|
788
|
+ // }
|
|
789
|
+ // }
|
|
790
|
+ //}
|
|
791
|
+ //
|
|
792
|
+ ////// 将剩余字符串填充到 Inspection 数组中
|
|
793
|
+ ////for _, name := range filtered {
|
|
794
|
+ //// var temptwo models.InspectionValue
|
|
795
|
+ //// temptwo.Name = subitem.ItemName
|
|
796
|
+ //// temptwo.Value = subitem.InspectValue
|
|
797
|
+ //// temptwos = append(temptwos, temptwo)
|
|
798
|
+ ////}
|
|
799
|
+ //
|
|
800
|
+ //for _, item := range tempList {
|
|
801
|
+ // //for _, subitem := range item.Values {
|
|
802
|
+ // var temptwo models.InspectionValue
|
|
803
|
+ // for _, name := range filtered {
|
|
804
|
+ // temptwo.Name = name
|
|
805
|
+ // temptwo.Value = ""
|
|
806
|
+ // }
|
|
807
|
+ // item.Values = append(item.Values, temptwo)
|
|
808
|
+ // //}
|
|
809
|
+ // fmt.Println(item.Values)
|
|
810
|
+ //}
|
|
811
|
+
|
237
|
812
|
}
|
238
|
813
|
func (c *StatisticsApiController) GetPatientInspectionStatistisc() {
|
239
|
814
|
start_date := c.GetString("start_date")
|
|
@@ -544,3 +1119,131 @@ func (c *StatisticsApiController) GetStatistics() {
|
544
|
1119
|
})
|
545
|
1120
|
|
546
|
1121
|
}
|
|
1122
|
+
|
|
1123
|
+func RemoveRepeatedInspectPatientElement(arr []models.InspectionTenOne) (newArr []models.InspectionTenOne) {
|
|
1124
|
+ newArr = make([]models.InspectionTenOne, 0)
|
|
1125
|
+ for i := 0; i < len(arr); i++ {
|
|
1126
|
+ repeat := false
|
|
1127
|
+ for j := i + 1; j < len(arr); j++ {
|
|
1128
|
+ if arr[i].PatientId == arr[j].PatientId {
|
|
1129
|
+ repeat = true
|
|
1130
|
+ break
|
|
1131
|
+ }
|
|
1132
|
+ }
|
|
1133
|
+ if !repeat {
|
|
1134
|
+ newArr = append(newArr, arr[i])
|
|
1135
|
+ }
|
|
1136
|
+ }
|
|
1137
|
+ return
|
|
1138
|
+}
|
|
1139
|
+
|
|
1140
|
+func RemoveRepeatedNameElement(arr []string) (newArr []string) {
|
|
1141
|
+ newArr = make([]string, 0)
|
|
1142
|
+ for i := 0; i < len(arr); i++ {
|
|
1143
|
+ repeat := false
|
|
1144
|
+ for j := i + 1; j < len(arr); j++ {
|
|
1145
|
+ if arr[i] == arr[j] {
|
|
1146
|
+ repeat = true
|
|
1147
|
+ break
|
|
1148
|
+ }
|
|
1149
|
+ }
|
|
1150
|
+ if !repeat {
|
|
1151
|
+ newArr = append(newArr, arr[i])
|
|
1152
|
+ }
|
|
1153
|
+ }
|
|
1154
|
+ return
|
|
1155
|
+}
|
|
1156
|
+
|
|
1157
|
+// 根据指定的日期范围拆分成周、月、年
|
|
1158
|
+func splitDateRange(startDate, endDate string) ([]time.Time, error) {
|
|
1159
|
+ startTime, err := time.Parse("2006-01-02", startDate)
|
|
1160
|
+ if err != nil {
|
|
1161
|
+ return nil, err
|
|
1162
|
+ }
|
|
1163
|
+
|
|
1164
|
+ endTime, err := time.Parse("2006-01-02", endDate)
|
|
1165
|
+ if err != nil {
|
|
1166
|
+ return nil, err
|
|
1167
|
+ }
|
|
1168
|
+
|
|
1169
|
+ var result []time.Time
|
|
1170
|
+
|
|
1171
|
+ for date := startTime; date.Before(endTime) || date.Equal(endTime); date = date.AddDate(0, 0, 1) {
|
|
1172
|
+ result = append(result, date)
|
|
1173
|
+ }
|
|
1174
|
+
|
|
1175
|
+ return result, nil
|
|
1176
|
+}
|
|
1177
|
+
|
|
1178
|
+// 按周统计日期
|
|
1179
|
+func groupByWeek(dates []time.Time) [][]time.Time {
|
|
1180
|
+ var result [][]time.Time
|
|
1181
|
+ var currentWeek []time.Time
|
|
1182
|
+
|
|
1183
|
+ for _, date := range dates {
|
|
1184
|
+ currentWeek = append(currentWeek, date)
|
|
1185
|
+ if date.Weekday() == time.Sunday {
|
|
1186
|
+ result = append(result, currentWeek)
|
|
1187
|
+ currentWeek = nil
|
|
1188
|
+ }
|
|
1189
|
+ }
|
|
1190
|
+
|
|
1191
|
+ if len(currentWeek) > 0 {
|
|
1192
|
+ result = append(result, currentWeek)
|
|
1193
|
+ }
|
|
1194
|
+
|
|
1195
|
+ return result
|
|
1196
|
+}
|
|
1197
|
+
|
|
1198
|
+// 按月统计日期
|
|
1199
|
+func groupByMonth(dates []time.Time) [][]time.Time {
|
|
1200
|
+ var result [][]time.Time
|
|
1201
|
+ var currentMonth []time.Time
|
|
1202
|
+ lastMonth := dates[0].Month()
|
|
1203
|
+
|
|
1204
|
+ for _, date := range dates {
|
|
1205
|
+ if date.Month() != lastMonth {
|
|
1206
|
+ result = append(result, currentMonth)
|
|
1207
|
+ currentMonth = nil
|
|
1208
|
+ lastMonth = date.Month()
|
|
1209
|
+ }
|
|
1210
|
+ currentMonth = append(currentMonth, date)
|
|
1211
|
+ }
|
|
1212
|
+
|
|
1213
|
+ if len(currentMonth) > 0 {
|
|
1214
|
+ result = append(result, currentMonth)
|
|
1215
|
+ }
|
|
1216
|
+
|
|
1217
|
+ return result
|
|
1218
|
+}
|
|
1219
|
+
|
|
1220
|
+// 按年统计日期
|
|
1221
|
+func groupByYear(dates []time.Time) [][]time.Time {
|
|
1222
|
+ var result [][]time.Time
|
|
1223
|
+ var currentYear []time.Time
|
|
1224
|
+ lastYear := dates[0].Year()
|
|
1225
|
+
|
|
1226
|
+ for _, date := range dates {
|
|
1227
|
+ if date.Year() != lastYear {
|
|
1228
|
+ result = append(result, currentYear)
|
|
1229
|
+ currentYear = nil
|
|
1230
|
+ lastYear = date.Year()
|
|
1231
|
+ }
|
|
1232
|
+ currentYear = append(currentYear, date)
|
|
1233
|
+ }
|
|
1234
|
+
|
|
1235
|
+ if len(currentYear) > 0 {
|
|
1236
|
+ result = append(result, currentYear)
|
|
1237
|
+ }
|
|
1238
|
+
|
|
1239
|
+ return result
|
|
1240
|
+}
|
|
1241
|
+
|
|
1242
|
+// 将日期拆分为按天统计
|
|
1243
|
+func splitByDay(startDate, endDate time.Time) []time.Time {
|
|
1244
|
+ var dates []time.Time
|
|
1245
|
+ for d := startDate; !d.After(endDate); d = d.AddDate(0, 0, 1) {
|
|
1246
|
+ dates = append(dates, d)
|
|
1247
|
+ }
|
|
1248
|
+ return dates
|
|
1249
|
+}
|