Browse Source

历史排班

28169 9 months ago
parent
commit
30e4d5fef9

BIN
XT_New.exe View File


+ 14 - 12
controllers/base_api_controller.go View File

@@ -72,9 +72,10 @@ func (this *BaseAuthAPIController) Prepare() {
72 72
 	this.BaseAPIController.Prepare()
73 73
 	if this.GetAdminUserInfo() == nil {
74 74
 		var userAdmin models.AdminUser
75
-		userAdmin.Id = 16919
76
-		userAdmin.Mobile = "15717313968"
77
-		userAdmin.Id = 10489 //4,809
75
+		userAdmin.Id = 1448
76
+		userAdmin.Mobile = "13318599895"
77
+
78
+		userAdmin.Id = 1 //4,809
78 79
 		userAdmin.Mobile = "12222222222"
79 80
 		userAdmin.IsSuperAdmin = true
80 81
 		userAdmin.Status = 1
@@ -82,7 +83,7 @@ func (this *BaseAuthAPIController) Prepare() {
82 83
 		userAdmin.ModifyTime = 1530786071
83 84
 		var subscibe models.ServeSubscibe
84 85
 		subscibe.ID = 11
85
-		subscibe.OrgId = 10510 //机构id 10344
86
+		subscibe.OrgId = 10480 //机构id
86 87
 		subscibe.PeriodStart = 1547447814
87 88
 		subscibe.PeriodEnd = 1550039814
88 89
 		subscibe.State = 1
@@ -92,8 +93,8 @@ func (this *BaseAuthAPIController) Prepare() {
92 93
 		subscibes := make(map[int64]*models.ServeSubscibe, 0)
93 94
 		subscibes[4] = &subscibe
94 95
 		var adminUserInfo service.AdminUserInfo
95
-		adminUserInfo.CurrentOrgId = 10510 //机构id小英9675或4
96
-		adminUserInfo.CurrentAppId = 11211 //4
96
+		adminUserInfo.CurrentOrgId = 10480 //机构id小英9675或4
97
+		adminUserInfo.CurrentAppId = 14    //4
97 98
 		adminUserInfo.AdminUser = &userAdmin
98 99
 		adminUserInfo.Subscibes = subscibes
99 100
 		this.SetSession("admin_user_info", &adminUserInfo)
@@ -317,9 +318,10 @@ func (this *BaseServeAPIController) Prepare() {
317 318
 	this.BaseAPIController.Prepare()
318 319
 	if this.GetAdminUserInfo() == nil {
319 320
 		var userAdmin models.AdminUser
320
-		userAdmin.Id = 16919
321
-		userAdmin.Mobile = "15717313968"
322
-		userAdmin.Id = 16919 //4,809
321
+		userAdmin.Id = 1448
322
+		userAdmin.Mobile = "13318599895"
323
+
324
+		userAdmin.Id = 1 //4,809
323 325
 		userAdmin.Mobile = "12222222222"
324 326
 		userAdmin.IsSuperAdmin = false
325 327
 		userAdmin.Status = 1
@@ -327,7 +329,7 @@ func (this *BaseServeAPIController) Prepare() {
327 329
 		userAdmin.ModifyTime = 1530786071
328 330
 		var subscibe models.ServeSubscibe
329 331
 		subscibe.ID = 11
330
-		subscibe.OrgId = 10510 //机构id小英10344或4或10666
332
+		subscibe.OrgId = 10480 //机构id小英9675或4
331 333
 		subscibe.PeriodStart = 1538035409
332 334
 		subscibe.PeriodEnd = 1569571409
333 335
 		subscibe.State = 1
@@ -337,8 +339,8 @@ func (this *BaseServeAPIController) Prepare() {
337 339
 		subscibes := make(map[int64]*models.ServeSubscibe, 0)
338 340
 		subscibes[4] = &subscibe
339 341
 		var adminUserInfo service.AdminUserInfo
340
-		adminUserInfo.CurrentOrgId = 10510 //机构id小英10344或4或10666
341
-		adminUserInfo.CurrentAppId = 11211 //4
342
+		adminUserInfo.CurrentOrgId = 10480 //机构id小英9675或4
343
+		adminUserInfo.CurrentAppId = 14    //4
342 344
 		adminUserInfo.AdminUser = &userAdmin
343 345
 		adminUserInfo.Subscibes = subscibes
344 346
 		this.SetSession("admin_user_info", &adminUserInfo)

+ 0 - 1
controllers/dialysis_record_api_controller.go View File

@@ -86,7 +86,6 @@ func (this *DialysisRecordAPIController) GetSchedules() {
86 86
 	if orgID == 9671 || orgID == 9675 || orgID == 10164 || orgID == 9679 {
87 87
 		redis.Set(key, scheduals_json_str, time.Second*60)
88 88
 	}
89
-	fmt.Println("len2o2o2o2o2", len(scheduals_json_str))
90 89
 
91 90
 	if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
92 91
 

File diff suppressed because it is too large
+ 11335 - 0
controllers/his_api_controller.go.3084552755


+ 1 - 1
controllers/new_mobile_api_controllers/staff_schedule_api_controller.go View File

@@ -429,7 +429,7 @@ func (this *StaffScheduleApiController) GetAllZonePb() {
429 429
 	}
430 430
 
431 431
 	//查询排班里面的空透析器
432
-	if orgid == 10375 || orgid == 10510 || orgid == 9538 {
432
+	if orgid == 10375 || orgid == 10510 || orgid == 9538 || orgid == 10610 {
433 433
 
434 434
 		schedulesFive, _ := service.GetMobileScheduleListByScheduleDateOne(orgid, startTime)
435 435
 

+ 10 - 0
controllers/stock_in_api_controller.go View File

@@ -8029,12 +8029,22 @@ func (this *StockManagerApiController) GetInvetoryWarehouseInfoList() {
8029 8029
 	storehouse_id, _ := this.GetInt64("storehouse_id")
8030 8030
 	orgId := this.GetAdminUserInfo().CurrentOrgId
8031 8031
 	list, _ := service.GetInvetoryWarehouseInfoList(orgId, storehouse_id)
8032
+	var info []*models.WarehousingInfo
8033
+	if orgId == 10571 {
8034
+		for _, item := range list {
8035
+			if strings.ContainsAny(item.GoodInfo.GoodStatus, "收费") {
8036
+				info = append(info, item)
8037
+			}
8038
+		}
8039
+	}
8040
+
8032 8041
 	manufacturerList, _ := service.GetAllManufacturerList(orgId)
8033 8042
 	dealerList, _ := service.GetAllDealerList(orgId)
8034 8043
 	this.ServeSuccessJSON(map[string]interface{}{
8035 8044
 		"list":             list,
8036 8045
 		"manufacturerList": manufacturerList,
8037 8046
 		"dealerList":       dealerList,
8047
+		"info":             info,
8038 8048
 	})
8039 8049
 }
8040 8050
 

+ 41 - 0
models/export_data_models.go View File

@@ -0,0 +1,41 @@
1
+package models
2
+
3
+type BatchHisOrderInfo struct {
4
+	ID               int64   `gorm:"column:id" json:"id" form:"id"`
5
+	OrderNumber      string  `gorm:"column:order_number" json:"order_number" form:"order_number"`
6
+	UploadDate       int64   `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
7
+	AdviceId         int64   `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
8
+	DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
9
+	Cnt              float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
10
+	Pric             float64 `gorm:"column:pric" json:"pric" form:"pric"`
11
+	PatientId        int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
12
+	PricUplmtAmt     float64 `gorm:"column:pric_uplmt_amt" json:"pric_uplmt_amt" form:"pric_uplmt_amt"`
13
+	SelfpayProp      float64 `gorm:"column:selfpay_prop" json:"selfpay_prop" form:"selfpay_prop"`
14
+	FulamtOwnpayAmt  float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
15
+	OverlmtAmt       float64 `gorm:"column:overlmt_amt" json:"overlmt_amt" form:"overlmt_amt"`
16
+	PreselfpayAmt    float64 `gorm:"column:preselfpay_amt" json:"preselfpay_amt" form:"preselfpay_amt"`
17
+	BasMednFlag      string  `gorm:"column:bas_medn_flag" json:"bas_medn_flag" form:"bas_medn_flag"`
18
+	MedChrgitmType   string  `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
19
+	HiNegoDrugFlag   string  `gorm:"column:hi_nego_drug_flag" json:"hi_nego_drug_flag" form:"hi_nego_drug_flag"`
20
+	Status           int64   `gorm:"column:status" json:"status" form:"status"`
21
+	Memo             string  `gorm:"column:memo" json:"memo" form:"memo"`
22
+	FeedetlSn        string  `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
23
+	Mtime            int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
24
+	InscpScpAmt      float64 `gorm:"column:inscp_scp_amt" json:"inscp_scp_amt" form:"inscp_scp_amt"`
25
+	DrtReimFlag      string  `gorm:"column:drt_reim_flag" json:"drt_reim_flag" form:"drt_reim_flag"`
26
+	Ctime            int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
27
+	ListSpItemFlag   string  `gorm:"column:list_sp_item_flag" json:"list_sp_item_flag" form:"list_sp_item_flag"`
28
+	ChldMedcFlag     string  `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
29
+	LmtUsedFlag      string  `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
30
+	ChrgitmLv        string  `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
31
+	UserOrgId        int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
32
+	HisPatientId     int64   `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
33
+	OrderId          int64   `gorm:"column:order_id" json:"order_id" form:"order_id"`
34
+	ProjectId        int64   `gorm:"column:project_id" json:"project_id" form:"project_id"`
35
+	Type             int64   `gorm:"column:type" json:"type" form:"type"`
36
+	ItemId           int64   `gorm:"column:item_id" json:"item_id" form:"item_id"`
37
+}
38
+
39
+func (BatchHisOrderInfo) TableName() string {
40
+	return "his_order_info"
41
+}

+ 7 - 0
models/qc.go View File

@@ -0,0 +1,7 @@
1
+package models
2
+
3
+type CustomDialysisData struct {
4
+	Date  string `json:"date"`
5
+	Count int64  `json:"count"`
6
+	Total int64  `json:"total"`
7
+}

BIN
service/2.pdf View File


BIN
service/9.pdf View File


+ 667 - 0
service/statistis_qc_service.go View File

@@ -0,0 +1,667 @@
1
+package service
2
+
3
+import (
4
+	"XT_New/models"
5
+	"fmt"
6
+	"strings"
7
+)
8
+
9
+func GetDialysisTotalDatas() {
10
+
11
+}
12
+
13
+func GetNewDialysiTotal(startime int64, endtime int64, orgid int64, origin int64) (int64, error) {
14
+	counts := models.PatientPrescriptionCountStruct{}
15
+	var err error
16
+	if origin == 1 { //透析记录,上机为准
17
+		db := XTReadDB().Table("xt_dialysis_order as x")
18
+		err = db.Select("count(x.id) as count").Where("x.dialysis_date >= ? and x.dialysis_date<=? and x.user_org_id = ? AND x.status = 1", startime, endtime, orgid).Scan(&counts).Error
19
+		return counts.Count, err
20
+
21
+	} else {
22
+		db := XTReadDB().Table("xt_schedule as sch")
23
+		//err = db.Select("COUNT(DISTINCT patient_id) AS total_employees").Where("x.dialysis_date >= ? and x.dialysis_date<=? and x.user_org_id = ? AND x.status = 1", startime, endtime, orgid).Scan(&counts).Error
24
+		var count int64
25
+		err := db.Model(&Schedule{}).
26
+			Select("patient_id, schedule_date").
27
+			Group("patient_id, schedule_date").
28
+			Where("schedule_date >= ? AND schedule_date  <= ?", startime, endtime).
29
+			Count(&count).
30
+			Error
31
+		return count, err
32
+
33
+	}
34
+
35
+}
36
+
37
+type TreatmentMode struct {
38
+	ModeID   int    `json:"mode_id"`
39
+	ModeName string `json:"mode_name"`
40
+}
41
+
42
+type DialysisStat struct {
43
+	Date   string         `json:"日期"`
44
+	Counts map[string]int `json:"counts"`
45
+	Total  int            `json:"合计"`
46
+}
47
+
48
+func getTreatmentModes() ([]TreatmentMode, error) {
49
+	var modes []TreatmentMode
50
+	if err := XTReadDB().Find(&modes).Error; err != nil {
51
+		return nil, err
52
+	}
53
+	return modes, nil
54
+}
55
+
56
+func GetDialysisStats(startDate int64, endDate int64, groupBy int64, mode int64) ([]DialysisStat, error) {
57
+	var stats []DialysisStat
58
+	var modes []TreatmentMode
59
+	if mode > 0 {
60
+		modes, _ = getTreatmentModes()
61
+	} else {
62
+		modes_two, _ := getTreatmentModes()
63
+		for _, item := range modes_two {
64
+			if item.ModeID == int(mode) {
65
+				modes = append(modes, item)
66
+			}
67
+		}
68
+	}
69
+	// 获取透析模式
70
+	if err != nil {
71
+		return nil, err
72
+	}
73
+
74
+	// 构建日期格式
75
+	dateFormat := "%Y-%m-%d"
76
+	switch groupBy {
77
+	case 2:
78
+		dateFormat = "%Y-%m-%d"
79
+	case 1:
80
+		dateFormat = "%Y-%u"
81
+	case 3:
82
+		dateFormat = "%Y-%m"
83
+	case 4:
84
+		dateFormat = "%Y"
85
+	default:
86
+		return nil, fmt.Errorf("invalid group by option")
87
+	}
88
+	// 构建动态查询语句
89
+	selectClauses := []string{fmt.Sprintf("DATE_FORMAT(p.record_date, '%s') AS `日期`", dateFormat)}
90
+	for _, mode := range modes {
91
+		selectClauses = append(selectClauses, fmt.Sprintf("SUM(CASE WHEN t.mode_name = '%s' THEN 1 ELSE 0 END) AS `%s`", mode.ModeName, mode.ModeName))
92
+	}
93
+	selectClauses = append(selectClauses, "COUNT(*) AS `合计`")
94
+
95
+	query := fmt.Sprintf(`
96
+        SELECT
97
+            %s
98
+        FROM
99
+            xt_dialysis_prescription p
100
+        JOIN
101
+            xt_treatment_mode t ON p.mode_id = t.mode_id
102
+        WHERE
103
+            p.record_date >= ? AND p.record_date <= ?
104
+        GROUP BY
105
+            DATE_FORMAT(p.record_date, '%s')
106
+    `, dateFormat, dateFormat, selectClauses)
107
+
108
+	rows, err := readDb.Raw(query, startDate, endDate).Rows()
109
+	if err != nil {
110
+		return nil, err
111
+	}
112
+	defer rows.Close()
113
+
114
+	// 解析查询结果
115
+	for rows.Next() {
116
+		var stat DialysisStat
117
+		stat.Counts = make(map[string]int)
118
+		cols := []interface{}{&stat.Date}
119
+		for _, mode := range modes {
120
+			var count int
121
+			cols = append(cols, &count)
122
+			stat.Counts[mode.ModeName] = count
123
+		}
124
+		var total int
125
+		cols = append(cols, &total)
126
+		stat.Total = total
127
+		if err := rows.Scan(cols...); err != nil {
128
+			return nil, err
129
+		}
130
+		stats = append(stats, stat)
131
+	}
132
+
133
+	return stats, nil
134
+}
135
+
136
+func GetScheduleStats(startDate int64, endDate int64, groupBy int64, mode int64) ([]DialysisStat, error) {
137
+	var stats []DialysisStat
138
+	var modes []TreatmentMode
139
+	if mode > 0 {
140
+		modes, _ = getTreatmentModes()
141
+	} else {
142
+		modes_two, _ := getTreatmentModes()
143
+		for _, item := range modes_two {
144
+			if item.ModeID == int(mode) {
145
+				modes = append(modes, item)
146
+			}
147
+		}
148
+	}
149
+	// 获取透析模式
150
+	if err != nil {
151
+		return nil, err
152
+	}
153
+
154
+	// 构建日期格式
155
+	dateFormat := "%Y-%m-%d"
156
+	switch groupBy {
157
+	case 2:
158
+		dateFormat = "%Y-%m-%d"
159
+	case 1:
160
+		dateFormat = "%Y-%u"
161
+	case 3:
162
+		dateFormat = "%Y-%m"
163
+	case 4:
164
+		dateFormat = "%Y"
165
+	default:
166
+		return nil, fmt.Errorf("invalid group by option")
167
+	}
168
+	// 构建动态查询语句
169
+	selectClauses := []string{fmt.Sprintf("DATE_FORMAT(p.schudle_date, '%s') AS `日期`", dateFormat)}
170
+	for _, mode := range modes {
171
+		selectClauses = append(selectClauses, fmt.Sprintf("SUM(CASE WHEN t.mode_name = '%s' THEN 1 ELSE 0 END) AS `%s`", mode.ModeName, mode.ModeName))
172
+	}
173
+	selectClauses = append(selectClauses, "COUNT(*) AS `合计`")
174
+
175
+	query := fmt.Sprintf(`
176
+        SELECT
177
+            %s
178
+        FROM
179
+            xt_schedule p
180
+        JOIN
181
+            xt_treatment_mode t ON p.mode_id = t.mode_id
182
+        WHERE
183
+            p.schedule_date >= ? AND p.schedule_date <= ?
184
+        GROUP BY
185
+            DATE_FORMAT(p.schedule_date, '%s')
186
+    `, dateFormat, dateFormat, selectClauses)
187
+
188
+	rows, err := readDb.Raw(query, startDate, endDate).Rows()
189
+	if err != nil {
190
+		return nil, err
191
+	}
192
+	defer rows.Close()
193
+
194
+	// 解析查询结果
195
+	for rows.Next() {
196
+		var stat DialysisStat
197
+		stat.Counts = make(map[string]int)
198
+		cols := []interface{}{&stat.Date}
199
+		for _, mode := range modes {
200
+			var count int
201
+			cols = append(cols, &count)
202
+			stat.Counts[mode.ModeName] = count
203
+		}
204
+		var total int
205
+		cols = append(cols, &total)
206
+		stat.Total = total
207
+		if err := rows.Scan(cols...); err != nil {
208
+			return nil, err
209
+		}
210
+		stats = append(stats, stat)
211
+	}
212
+
213
+	return stats, nil
214
+}
215
+
216
+func GetNewDialysisCountMode(starttime int64, endtime int64, orgid int64, origin int64, mode_id int64) (counts []*models.PatientPrescriptionCountStruct, err error) {
217
+	if origin == 1 {
218
+
219
+		db := readDb.Table("xt_dialysis_order as o").Where("o.status = 1")
220
+		if starttime > 0 {
221
+			db = db.Where("o.dialysis_date >=?", starttime)
222
+		}
223
+		if endtime > 0 {
224
+			db = db.Where("o.dialysis_date<=?", endtime)
225
+		}
226
+		if orgid > 0 {
227
+			db = db.Where("o.user_org_id = ?", orgid)
228
+		}
229
+		if mode_id == 0 {
230
+			err = db.Select("s.mode_id,count(s.mode_id) as count").Joins("join xt_dialysis_prescription as s on s.patient_id = o.patient_id and s.record_date = o.dialysis_date and s.status= 1 AND s.record_date >= ? AND s.record_date <= ? AND  s.mode_id > 0 ", starttime, endtime).Group("s.mode_id").Scan(&counts).Error
231
+
232
+		} else {
233
+
234
+			err = db.Select("s.mode_id,count(s.mode_id) as count").Joins("join xt_dialysis_prescription as s on s.patient_id = o.patient_id and s.record_date = o.dialysis_date and s.status= 1 AND s.record_date >= ? AND s.record_date <= ? AND  s.mode_id = ? ", starttime, endtime, mode_id).Group("s.mode_id").Scan(&counts).Error
235
+
236
+		}
237
+		return counts, err
238
+
239
+	} else {
240
+		db := readDb.Table("xt_schedule as o").Where("o.status = 1").Select("patient_id, schedule_date").Group("patient_id, schedule_date,mode_id")
241
+		if starttime > 0 {
242
+			db = db.Where("o.schedule_date >= ?", starttime)
243
+		}
244
+		if endtime > 0 {
245
+			db = db.Where("o.schedule_date <= ?", endtime)
246
+		}
247
+		if orgid > 0 {
248
+			db = db.Where("o.user_org_id = ?", orgid)
249
+		}
250
+		err = db.Select("o.mode_id,count(o.mode_id) as count").Scan(&counts).Error
251
+		return counts, err
252
+
253
+	}
254
+
255
+}
256
+
257
+func GetNewDialysisCountModeTwo(starttime int64, endtime int64, orgid int64, origin int64, mode_id int64) (counts models.CustomDialysisData, err error) {
258
+	if origin == 1 {
259
+		db := readDb.Table("xt_dialysis_order as o").Where("o.status = 1")
260
+		if starttime > 0 {
261
+			db = db.Where("o.dialysis_date >=?", starttime)
262
+		}
263
+		if endtime > 0 {
264
+			db = db.Where("o.dialysis_date<=?", endtime)
265
+		}
266
+		if orgid > 0 {
267
+			db = db.Where("o.user_org_id = ?", orgid)
268
+		}
269
+
270
+		err = db.Select("s.mode_id,count(s.mode_id) as count").Joins("join xt_dialysis_prescription as s on s.patient_id = o.patient_id and s.record_date = o.dialysis_date and s.status= 1 AND s.record_date >= ? AND s.record_date <= ? AND  s.mode_id = ? ", starttime, endtime, mode_id).Group("s.mode_id").Scan(&counts).Error
271
+		return counts, err
272
+
273
+	} else {
274
+		db := readDb.Table("xt_schedule as o").Where("o.status = 1").Select("patient_id, schedule_date").Group("patient_id, schedule_date,mode_id")
275
+		if starttime > 0 {
276
+			db = db.Where("o.schedule_date >= ?", starttime)
277
+		}
278
+		if endtime > 0 {
279
+			db = db.Where("o.schedule_date <= ?", endtime)
280
+		}
281
+		if orgid > 0 {
282
+			db = db.Where("o.user_org_id = ?", orgid)
283
+		}
284
+		if mode_id > 0 {
285
+			db = db.Where("o.mode_id = ?", mode_id)
286
+		}
287
+
288
+		err = db.Select("o.mode_id,count(o.mode_id) as count").Scan(&counts).Error
289
+		return counts, err
290
+
291
+	}
292
+
293
+}
294
+
295
+var anticoagulantMap = map[int]string{
296
+	1:  "无肝素",
297
+	2:  "普通肝素",
298
+	3:  "低分子肝素",
299
+	4:  "阿加曲班",
300
+	5:  "枸橼酸钠",
301
+	6:  "低分子肝素钙",
302
+	7:  "低分子肝素钠",
303
+	8:  "依诺肝素",
304
+	9:  "达肝素",
305
+	10: "体外抗凝",
306
+	11: "那屈肝素",
307
+	12: "无抗凝剂",
308
+	13: "那屈肝素钙",
309
+	14: "肝素钙注射液",
310
+	15: "甲磺酸萘莫司他",
311
+	16: "低分子量肝素钙",
312
+	17: "肝素钠",
313
+}
314
+
315
+func GetAnticoagulantData(start_time int64, end_time int64, org_id int64) (map[string]int, error) {
316
+	var results []struct {
317
+		Anticoagulant int
318
+		Count         int
319
+	}
320
+
321
+	err := XTReadDB().Model(&models.DialysisPrescription{}).
322
+		Select("anticoagulant, COUNT(*) as count").
323
+		Where("status = 1 and record_date >= ? and record_date <= ? and user_org_id = ?", start_time, end_time, org_id).
324
+		Group("anticoagulant").
325
+		Scan(&results).Error
326
+	if err != nil {
327
+		return nil, err
328
+	}
329
+	anticoagulantData := make(map[string]int)
330
+	for _, result := range results {
331
+		if name, ok := anticoagulantMap[result.Anticoagulant]; ok {
332
+			anticoagulantData[name] = result.Count
333
+		} else {
334
+			anticoagulantData[fmt.Sprintf("Unknown (%d)", result.Anticoagulant)] = result.Count
335
+		}
336
+	}
337
+
338
+	return anticoagulantData, nil
339
+}
340
+func GetAnticoagulantTotal(start_time int64, end_time int64, org_id int64) (total int64, err error) {
341
+	err = XTReadDB().Model(&models.DialysisPrescription{}).
342
+		Where("record_date >= ? and record_date <= ? and user_org_id = ? and status = 1", start_time, end_time, org_id).
343
+		Count(&total).Error
344
+
345
+	return
346
+}
347
+func GetDialyzerSummary(org_id int64) ([]string, error) {
348
+	var Dialyzer []string
349
+	err := XTReadDB().Model(&models.DialysisPrescription{}).
350
+		Select("dialysis_dialyszers").
351
+		Where(" user_org_id = ? and status = 1", org_id).
352
+		Group("dialysis_dialyszers").
353
+		Scan(&Dialyzer).Error
354
+	if err != nil {
355
+		return nil, err
356
+	}
357
+	return Dialyzer, nil
358
+}
359
+
360
+type DialyzerResult struct {
361
+	Dialyzer string
362
+	Count    int
363
+}
364
+
365
+func GetDialyzerData(start_time int64, end_time int64, org_id int64) (dr []DialyzerResult, err error) {
366
+	err = XTReadDB().Model(&models.DialysisPrescription{}).
367
+		Select("dialysis_dialyszers as dialyzer, COUNT(*) as count").
368
+		Where("record_date >= ? and record_date <= ? and user_org_id = ? and status = 1", start_time, end_time, org_id).
369
+		Group("dialysis_dialyszers").
370
+		Scan(&dr).Error
371
+	return
372
+}
373
+
374
+func GetDialyzerTotal(start_time int64, end_time int64, org_id int64) (total int64, err error) {
375
+	err = XTReadDB().Model(&models.DialysisPrescription{}).
376
+		Where("status = 1 and record_date >= ? and record_date <= ? and user_org_id = ? and dialysis_dialyszers <> ''", start_time, end_time, org_id).
377
+		Count(&total).Error
378
+	return
379
+}
380
+
381
+func GetPrescriptionByAnticoagulant(page int64, limit int64, orgid int64, anticoagulant int64, start_time int64, end_time int64) (solution []*models.DialysisPrescription, total int64, err error) {
382
+
383
+	db := XTReadDB().Model(&models.DialysisPrescription{}).Where("status = 1")
384
+	if anticoagulant > 0 {
385
+		db = db.Where("anticoagulant = ?", anticoagulant)
386
+	}
387
+	if orgid > 0 {
388
+		db = db.Where("user_org_id = ?", orgid)
389
+	}
390
+	db = db.Where("record_date >= ? and record_date <= ?", start_time, end_time)
391
+
392
+	offset := (page - 1) * limit
393
+
394
+	err = db.Count(&total).Offset(offset).Limit(limit).Find(&solution).Error
395
+	return solution, total, err
396
+}
397
+
398
+func GetPrescriptionByDialyzer(page int64, limit int64, orgid int64, dialyzer string, start_time int64, end_time int64) (solution []*models.DialysisPrescription, total int64, err error) {
399
+
400
+	db := XTReadDB().Model(&models.DialysisPrescription{}).Where("status = 1")
401
+	if len(dialyzer) > 0 {
402
+		db = db.Where("dialysis_dialyszers = ?", dialyzer)
403
+	}
404
+	if orgid > 0 {
405
+		db = db.Where("user_org_id = ?", orgid)
406
+	}
407
+	db = db.Where("record_date >= ? and record_date <= ?", start_time, end_time)
408
+
409
+	offset := (page - 1) * limit
410
+
411
+	err = db.Count(&total).Offset(offset).Limit(limit).Find(&solution).Error
412
+	return solution, total, err
413
+}
414
+
415
+type DialysisData struct {
416
+	DialysisStatus string `json:"dialysis_status"`
417
+	Count          int    `json:"count"`
418
+}
419
+
420
+type CustomData struct {
421
+	DialysisNo       string
422
+	PatientName      string
423
+	DialysisDate     string
424
+	DialysisDuration string
425
+	ActualDuration   string
426
+	Diff             string
427
+	Doctor           string
428
+	Nurse            string
429
+}
430
+
431
+func GetDialysisCompletionRate(org_id int64, start_time int64, end_time int64) (map[string]int, error) {
432
+	var results []DialysisData
433
+	query := `
434
+        SELECT
435
+            CASE
436
+                WHEN ABS(TIMESTAMPDIFF(MINUTE, MAKETIME(p.dialysis_duration_hour, p.dialysis_duration_minute, 0), MAKETIME(a.actual_treatment_hour, a.actual_treatment_minute, 0))) <= 15 THEN '达标'
437
+                WHEN TIMESTAMPDIFF(MINUTE, MAKETIME(p.dialysis_duration_hour, p.dialysis_duration_minute, 0), MAKETIME(a.actual_treatment_hour, a.actual_treatment_minute, 0)) < 0 THEN '未达标'
438
+                ELSE '超时'
439
+            END AS dialysis_status,
440
+            COUNT(*) AS count
441
+        FROM
442
+            xt_dialysis_order o
443
+        JOIN
444
+            xt_dialysis_prescription p ON o.dialysis_date = p.record_date AND o.patient_id = p.patient_id AND p.user_org_id = ?
445
+        JOIN
446
+            xt_assessment_after_dislysis a ON o.dialysis_date = a.assessment_date AND o.patient_id = a.patient_id AND a.user_org_id = ?
447
+        WHERE
448
+            o.stage = 2 AND o.user_org_id = ? AND o.dialysis_date >= ? AND o.dialysis_date <= ?
449
+        GROUP BY
450
+            dialysis_status;
451
+    `
452
+	if err := readDb.Raw(query, org_id, org_id, org_id, start_time, end_time).Scan(&results).Error; err != nil {
453
+		return nil, err
454
+	}
455
+	dialysisCompletionRate := make(map[string]int)
456
+	for _, result := range results {
457
+		dialysisCompletionRate[result.DialysisStatus] = result.Count
458
+	}
459
+	return dialysisCompletionRate, nil
460
+}
461
+func GetDialysisCompletionTotal(org_id int64, start_time int64, end_time int64) (int64, error) {
462
+	var Count int64
463
+	query := `
464
+        SELECT
465
+            COUNT(*) AS count
466
+        FROM
467
+            xt_dialysis_order o
468
+        JOIN
469
+            xt_dialysis_prescription p ON o.dialysis_date = p.record_date AND o.patient_id = p.patient_id AND p.user_org_id = ?
470
+        JOIN
471
+            xt_assessment_after_dislysis a ON o.dialysis_date = a.assessment_date AND o.patient_id = a.patient_id AND a.user_org_id = ?
472
+        WHERE
473
+            o.stage = 2 AND o.user_org_id = ? AND o.dialysis_date >= ? AND o.dialysis_date <= ?
474
+        GROUP BY
475
+            dialysis_status;
476
+    `
477
+	if err := readDb.Raw(query, org_id, org_id, org_id, start_time, end_time).Scan(&Count).Error; err != nil {
478
+		return 0, err
479
+	}
480
+
481
+	return Count, nil
482
+}
483
+func GetDialysisCompletionDetail(org_id int64, start_time int64, end_time int64, mode int64, limit int64, page int64) (date []*CustomData, total int64, err error) {
484
+	var query string
485
+	if mode == 0 {
486
+		query = `
487
+        SELECT
488
+           p.dialysis_no as dialysis_no,
489
+           p.name as patient_name,
490
+           FROM_UNIXTIME(o.dialysis_date) as dialysis_date,
491
+           CONCAT(p.dialysis_duration_hour, 'h', p.dialysis_duration_minute,'min') as dialysis_duration,
492
+           CONCAT(a.actual_treatment_hour, 'h', a.actual_treatment_minute,'min') as actual_duration,
493
+           ABS(TIMESTAMPDIFF(MINUTE, MAKETIME(p.dialysis_duration_hour, p.dialysis_duration_minute, 0), MAKETIME(a.actual_treatment_hour, a.actual_treatment_minute, 0))) as diff,
494
+           p.prescription_doctor as doctor,
495
+           p.finish_nurse as nurse
496
+        FROM
497
+            xt_dialysis_order o
498
+    	JOIN           
499
+            xt_patients pp ON o.patient_id = pp.id AND pp.user_org_id = ?
500
+        JOIN
501
+            xt_dialysis_prescription p ON o.dialysis_date = p.record_date AND o.patient_id = p.patient_id AND p.user_org_id = ?
502
+        JOIN
503
+            xt_assessment_after_dislysis a ON o.dialysis_date = a.assessment_date AND o.patient_id = a.patient_id AND a.user_org_id = ?
504
+        WHERE
505
+            o.stage = 2 AND o.user_org_id = ? AND o.dialysis_date >= ? AND o.dialysis_date <= ?
506
+    `
507
+
508
+	} else if mode == 1 {
509
+		query = `
510
+        SELECT
511
+           p.dialysis_no as dialysis_no,
512
+           p.name as patient_name,
513
+           FROM_UNIXTIME(o.dialysis_date) as dialysis_date,
514
+           CONCAT(p.dialysis_duration_hour, 'h', p.dialysis_duration_minute,'min') as dialysis_duration,
515
+           CONCAT(a.actual_treatment_hour, 'h', a.actual_treatment_minute,'min') as actual_duration,
516
+           ABS(TIMESTAMPDIFF(MINUTE, MAKETIME(p.dialysis_duration_hour, p.dialysis_duration_minute, 0), MAKETIME(a.actual_treatment_hour, a.actual_treatment_minute, 0))) as diff,
517
+           p.prescription_doctor as doctor,
518
+           p.finish_nurse as nurse
519
+        FROM
520
+            xt_dialysis_order o
521
+    	JOIN           
522
+            xt_patients pp ON o.patient_id = pp.id AND pp.user_org_id = ?
523
+        JOIN
524
+            xt_dialysis_prescription p ON o.dialysis_date = p.record_date AND o.patient_id = p.patient_id AND p.user_org_id = ?
525
+        JOIN
526
+            xt_assessment_after_dislysis a ON o.dialysis_date = a.assessment_date AND o.patient_id = a.patient_id AND a.user_org_id = ?
527
+        WHERE
528
+            o.stage = 2 AND o.user_org_id = ? AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND ABS(TIMESTAMPDIFF(MINUTE, MAKETIME(p.dialysis_duration_hour, p.dialysis_duration_minute, 0), MAKETIME(a.actual_treatment_hour, a.actual_treatment_minute, 0))) <= 15
529
+    `
530
+
531
+	} else if mode == 2 {
532
+		query = `
533
+        SELECT
534
+           p.dialysis_no as dialysis_no,
535
+           p.name as patient_name,
536
+           FROM_UNIXTIME(o.dialysis_date) as dialysis_date,
537
+           CONCAT(p.dialysis_duration_hour, 'h', p.dialysis_duration_minute,'min') as dialysis_duration,
538
+           CONCAT(a.actual_treatment_hour, 'h', a.actual_treatment_minute,'min') as actual_duration,
539
+           ABS(TIMESTAMPDIFF(MINUTE, MAKETIME(p.dialysis_duration_hour, p.dialysis_duration_minute, 0), MAKETIME(a.actual_treatment_hour, a.actual_treatment_minute, 0))) as diff,
540
+           p.prescription_doctor as doctor,
541
+           p.finish_nurse as nurse
542
+        FROM
543
+            xt_dialysis_order o
544
+    	JOIN           
545
+            xt_patients pp ON o.patient_id = pp.id AND pp.user_org_id = ?
546
+        JOIN
547
+            xt_dialysis_prescription p ON o.dialysis_date = p.record_date AND o.patient_id = p.patient_id AND p.user_org_id = ?
548
+        JOIN
549
+            xt_assessment_after_dislysis a ON o.dialysis_date = a.assessment_date AND o.patient_id = a.patient_id AND a.user_org_id = ?
550
+        WHERE
551
+            o.stage = 2 AND o.user_org_id = ? AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND TIMESTAMPDIFF(MINUTE, MAKETIME(p.dialysis_duration_hour, p.dialysis_duration_minute, 0), MAKETIME(a.actual_treatment_hour, a.actual_treatment_minute, 0)) < 0
552
+    `
553
+
554
+	} else if mode == 3 {
555
+		query = `
556
+        SELECT
557
+           p.dialysis_no as dialysis_no,
558
+           p.name as patient_name,
559
+           FROM_UNIXTIME(o.dialysis_date) as dialysis_date,
560
+           CONCAT(p.dialysis_duration_hour, 'h', p.dialysis_duration_minute,'min') as dialysis_duration,
561
+           CONCAT(a.actual_treatment_hour, 'h', a.actual_treatment_minute,'min') as actual_duration,
562
+           ABS(TIMESTAMPDIFF(MINUTE, MAKETIME(p.dialysis_duration_hour, p.dialysis_duration_minute, 0), MAKETIME(a.actual_treatment_hour, a.actual_treatment_minute, 0))) as diff,
563
+           p.prescription_doctor as doctor,
564
+           p.finish_nurse as nurse
565
+        FROM
566
+            xt_dialysis_order o
567
+    	JOIN           
568
+            xt_patients pp ON o.patient_id = pp.id AND pp.user_org_id = ?
569
+        JOIN
570
+            xt_dialysis_prescription p ON o.dialysis_date = p.record_date AND o.patient_id = p.patient_id AND p.user_org_id = ?
571
+        JOIN
572
+            xt_assessment_after_dislysis a ON o.dialysis_date = a.assessment_date AND o.patient_id = a.patient_id AND a.user_org_id = ?
573
+        WHERE
574
+            o.stage = 2 AND o.user_org_id = ? AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND TIMESTAMPDIFF(MINUTE, MAKETIME(p.dialysis_duration_hour, p.dialysis_duration_minute, 0), MAKETIME(a.actual_treatment_hour, a.actual_treatment_minute, 0)) > 15
575
+    `
576
+	}
577
+	offset := (page - 1) * limit
578
+
579
+	if err := readDb.Raw(query, org_id, org_id, org_id, org_id, start_time, end_time).Count(&total).Offset(offset).Limit(limit).Scan(&date).Error; err != nil {
580
+		return nil, 0, err
581
+	}
582
+
583
+	return
584
+}
585
+
586
+type QualityControlStandard struct {
587
+	ItemName        string `json:"item_name"`
588
+	ProjectMame     string `json:"project_name"`
589
+	InspectionMajor int64  `json:"inspection_major"`
590
+	InspectionMinor int64  `json:"inspection_minor"`
591
+}
592
+
593
+func getQualityControlStandards(org_id int64) ([]QualityControlStandard, error) {
594
+	var standards []QualityControlStandard
595
+	if err := readDb.Model(&models.XtQualityControlStandard{}).Select("re.project_name as project_name,re.item_name as item_name,xt_quality_control_standard.inspection_major as inspection_major,xt_quality_control_standard.inspection_minor as inspection_minor").Joins("join xt_inspection_reference re on re.project_id = xt_quality_control_standard.inspection_major and re.item_id = xt_quality_control_standard.inspection_minor and re.org_id = ?", org_id).Where("xt_quality_control_standard.user_org_id = ? and xt_quality_control_standard.status = 1", org_id).Scan(&standards).Error; err != nil {
596
+		return nil, err
597
+	}
598
+	return standards, nil
599
+}
600
+
601
+type DialysisQualityStat struct {
602
+	Month  string             `json:"月"`
603
+	Name   string             `json:"姓名"`
604
+	Counts map[string]float64 `json:"counts"`
605
+}
606
+
607
+func GetLatestInspectionValues(org_id int64, yearMonth string) ([]map[string]interface{}, error) {
608
+	standards, err := getQualityControlStandards(org_id)
609
+	if err != nil {
610
+		return nil, err
611
+	}
612
+
613
+	var selectFields []string
614
+	for _, standard := range standards {
615
+		field := fmt.Sprintf("IFNULL(MAX(CASE WHEN i.item_name = %s THEN i.inspect_value END),'') AS `%s`",
616
+			"'"+standard.ItemName+"'", standard.ItemName)
617
+		selectFields = append(selectFields, field)
618
+	}
619
+
620
+	query := fmt.Sprintf(`
621
+		SELECT
622
+		    p.name as '姓名',
623
+			%s
624
+		FROM xt_inspection i
625
+		JOIN xt_patients p On p.id = i.patient_id
626
+		WHERE DATE_FORMAT(FROM_UNIXTIME(i.inspect_date), '%%Y-%%m') = ? and org_id = ?
627
+		
628
+		GROUP BY i.patient_id
629
+	`, strings.Join(selectFields, ", "))
630
+
631
+	var results []map[string]interface{}
632
+	rows, err := readDb.Raw(query, yearMonth, org_id).Rows()
633
+	if err != nil {
634
+		return nil, err
635
+	}
636
+	defer rows.Close()
637
+
638
+	columns, err := rows.Columns()
639
+	if err != nil {
640
+		return nil, err
641
+	}
642
+
643
+	for rows.Next() {
644
+		// 创建一个长度为列数的切片,用于存储每一行的值
645
+		columnValues := make([]interface{}, len(columns))
646
+		columnPointers := make([]interface{}, len(columns))
647
+		for i := range columnValues {
648
+			columnPointers[i] = &columnValues[i]
649
+		}
650
+
651
+		// 扫描当前行的值
652
+		if err := rows.Scan(columnPointers...); err != nil {
653
+			return nil, err
654
+		}
655
+
656
+		// 将扫描到的值放入结果 map 中
657
+		result := make(map[string]interface{})
658
+		for i, colName := range columns {
659
+			val := columnPointers[i].(*interface{})
660
+			result[colName] = *val
661
+		}
662
+
663
+		results = append(results, result)
664
+	}
665
+
666
+	return results, nil
667
+}