Browse Source

耗材参数

XMLWAN 4 years ago
parent
commit
3a945f66c8

+ 167 - 2
controllers/dialysis_parameter_api_controller.go View File

@@ -5,6 +5,7 @@ import (
5 5
 	"XT_New/service"
6 6
 	"fmt"
7 7
 	"github.com/astaxie/beego"
8
+	"github.com/jinzhu/gorm"
8 9
 	"strings"
9 10
 	"time"
10 11
 )
@@ -17,6 +18,10 @@ func DialysisPrameteRoutes() {
17 18
 	beego.Router("/api/dialysis/getdialysisparameters", &DialysisPrameterApiController{}, "Get:GetDialysisParameters")
18 19
 	beego.Router("/api/dialysis/getdialysisbatchparameters", &DialysisPrameterApiController{}, "Get:GetDialysisBatchParameters")
19 20
 	beego.Router("/api/dialysis/getwarehouseoutlist", &DialysisPrameterApiController{}, "Get:GetWareHouseOutList")
21
+	beego.Router("/api/dialysis/getallmaterial", &DialysisPrameterApiController{}, "Get:GetAllMaterial")
22
+	beego.Router("/api/dialysis/getcollectlist", &DialysisPrameterApiController{}, "Get:GetCollectList")
23
+	beego.Router("/api/dialysis/getbatchcollection", &DialysisPrameterApiController{}, "Get:GetBatchCollection")
24
+	beego.Router("/api/dialysis/getgatherlist", &DialysisPrameterApiController{}, "Get:GetGatherList")
20 25
 }
21 26
 
22 27
 func (this *DialysisPrameterApiController) GetDialysisParameters() {
@@ -43,10 +48,43 @@ func (this *DialysisPrameterApiController) GetDialysisParameters() {
43 48
 		}
44 49
 	} else {
45 50
 		dialysisSchedule, err, total := service.GetDialysisParameter(adminUserInfo.CurrentOrgId, theTime.Unix(), schedulType, partitionType, page, limit)
51
+
52
+		//查询今日排班的病人
53
+		patient, err := service.GetDialysisTodaySchedulePatient(adminUserInfo.CurrentOrgId, theTime.Unix(), page, limit)
54
+
55
+		var vlist []interface{}
56
+		var elist []interface{}
57
+		for _, item := range patient {
58
+			//查询当前日期的病人是否存在数据
59
+			_, errcode := service.GetToDayDialysisPrescription(item.PatientId, adminUserInfo.CurrentOrgId, theTime.Unix())
60
+			if errcode == gorm.ErrRecordNotFound {
61
+				//查询每个病人透析处方的最后一次数据
62
+				prescription, _ := service.GetLastDialysisPrescription(item.PatientId, adminUserInfo.CurrentOrgId)
63
+				vlist = append(vlist, prescription)
64
+			} else if errcode == nil {
65
+				//获取当前日期
66
+				prescription, _ := service.GetDialysisPrescriptionList(item.PatientId, adminUserInfo.CurrentOrgId, theTime.Unix())
67
+				vlist = append(vlist, prescription)
68
+			}
69
+
70
+			_, errcodes := service.GetTodayAssessmentBeforDialysis(item.PatientId, adminUserInfo.CurrentOrgId, theTime.Unix())
71
+			if errcodes == gorm.ErrRecordNotFound {
72
+				//查询每个病人透前评估的最后一次数据
73
+				dialysis, _ := service.GetLastAssessmentBeforDialysis(item.PatientId, adminUserInfo.CurrentOrgId)
74
+				elist = append(elist, dialysis)
75
+			} else if errcodes == nil {
76
+				dialysis, _ := service.GetAssessmentBeforDialysisByStartime(item.PatientId, adminUserInfo.CurrentOrgId, theTime.Unix())
77
+				elist = append(elist, dialysis)
78
+			}
79
+
80
+		}
81
+
46 82
 		if err == nil {
47 83
 			this.ServeSuccessJSON(map[string]interface{}{
48
-				"schedule": dialysisSchedule,
49
-				"total":    total,
84
+				"schedule":     dialysisSchedule,
85
+				"total":        total,
86
+				"prescription": vlist,
87
+				"dialysbefor":  elist,
50 88
 			})
51 89
 		} else {
52 90
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
@@ -91,3 +129,130 @@ func (this *DialysisPrameterApiController) GetWareHouseOutList() {
91 129
 		})
92 130
 	}
93 131
 }
132
+
133
+func (this *DialysisPrameterApiController) GetAllMaterial() {
134
+
135
+	timeLayout := "2006-01-02"
136
+	loc, _ := time.LoadLocation("Local")
137
+	start_time := this.GetString("startime")
138
+	startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
139
+	fmt.Println("开始时间", startime)
140
+	endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 23:59:59", loc)
141
+	fmt.Println("结束时间", endtime)
142
+	orgId := this.GetAdminUserInfo().CurrentOrgId
143
+	material, err := service.GetAllMaterial(startime.Unix(), endtime.Unix(), orgId)
144
+	if err == nil {
145
+		this.ServeSuccessJSON(map[string]interface{}{
146
+			"material": material,
147
+		})
148
+	}
149
+}
150
+
151
+func (this *DialysisPrameterApiController) GetCollectList() {
152
+
153
+	timeLayout := "2006-01-02"
154
+	loc, _ := time.LoadLocation("Local")
155
+	limit, _ := this.GetInt64("limit")
156
+	fmt.Println(limit)
157
+	page, _ := this.GetInt64("page")
158
+	fmt.Println("page", page)
159
+	partitiontype, _ := this.GetInt64("partitionType")
160
+	fmt.Println(partitiontype)
161
+	scheduletype, _ := this.GetInt64("scheduleType")
162
+	fmt.Println(scheduletype)
163
+	start_time := this.GetString("start_time")
164
+	fmt.Println(start_time)
165
+	startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
166
+	orgId := this.GetAdminUserInfo().CurrentOrgId
167
+	endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 23:59:59", loc)
168
+	keyword := this.GetString("keyword")
169
+	//获取透析参数数据
170
+	schedule, err, total := service.GetCollectList(limit, page, partitiontype, scheduletype, startime.Unix(), orgId, keyword)
171
+
172
+	//查询今日排班的病人
173
+	patient, err := service.GetDialysisTodaySchedulePatient(orgId, startime.Unix(), page, limit)
174
+
175
+	var vlist []interface{}
176
+	for _, item := range patient {
177
+		//查询当前日期的病人是否存在数据
178
+		_, errcode := service.GetToDayDialysisPrescription(item.PatientId, orgId, startime.Unix())
179
+		if errcode == gorm.ErrRecordNotFound {
180
+			//查询每个病人透析处方的最后一次数据
181
+			prescription, _ := service.GetLastDialysisPrescription(item.PatientId, orgId)
182
+			vlist = append(vlist, prescription)
183
+		} else if errcode == nil {
184
+			//获取当前日期
185
+			prescription, _ := service.GetDialysisPrescriptionList(item.PatientId, orgId, startime.Unix())
186
+			vlist = append(vlist, prescription)
187
+		}
188
+
189
+	}
190
+	//获取透析耗材数据
191
+	consumables, err := service.GetDialysisConsumables(startime.Unix(), endtime.Unix(), orgId)
192
+	if err == nil {
193
+		this.ServeSuccessJSON(map[string]interface{}{
194
+			"schedule":    schedule,
195
+			"total":       total,
196
+			"consumables": consumables,
197
+			"prescrption": vlist,
198
+		})
199
+	}
200
+}
201
+
202
+func (this *DialysisPrameterApiController) GetBatchCollection() {
203
+	timeLayout := "2006-01-02"
204
+	loc, _ := time.LoadLocation("Local")
205
+	adminUser := this.GetAdminUserInfo()
206
+	orgId := adminUser.CurrentOrgId
207
+	fmt.Println(orgId)
208
+	start_time := this.GetString("startime")
209
+	startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
210
+	endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 23:59:59", loc)
211
+	schIDStr := this.GetString("ids")
212
+	//获取透析耗材数据
213
+	consumables, err := service.GetDialysisConsumables(startime.Unix(), endtime.Unix(), orgId)
214
+	if len(schIDStr) == 0 {
215
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
216
+		return
217
+	}
218
+	idStrs := strings.Split(schIDStr, ",")
219
+	fmt.Println(idStrs)
220
+	schedule, err := service.GetBatchCollection(orgId, idStrs)
221
+	if err == nil {
222
+		this.ServeSuccessJSON(map[string]interface{}{
223
+			"schedule":    schedule,
224
+			"consumables": consumables,
225
+		})
226
+	}
227
+}
228
+
229
+func (this *DialysisPrameterApiController) GetGatherList() {
230
+
231
+	timeLayout := "2006-01-02"
232
+	loc, _ := time.LoadLocation("Local")
233
+	adminUser := this.GetAdminUserInfo()
234
+	orgId := adminUser.CurrentOrgId
235
+	fmt.Println(orgId)
236
+	start_time := this.GetString("start_time")
237
+	end_time := this.GetString("end_time")
238
+	startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
239
+	endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
240
+	fmt.Println("开始时间", startime)
241
+	fmt.Println("结束时间", endtime)
242
+
243
+	warehouselist, err := service.GetWareHouseOutList(startime.Unix(), endtime.Unix(), orgId)
244
+
245
+	//获取透析耗材数据
246
+	consumables, err := service.GetDialysisConsumables(startime.Unix(), endtime.Unix(), orgId)
247
+
248
+	//统计抗凝剂数据
249
+	count, err := service.GetAnticoagulantCount(startime.Unix(), endtime.Unix(), orgId)
250
+	fmt.Println("er--------------------------------------", count)
251
+	if err == nil {
252
+		this.ServeSuccessJSON(map[string]interface{}{
253
+			"warehouselist": warehouselist,
254
+			"consumables":   consumables,
255
+			"count":         count,
256
+		})
257
+	}
258
+}

+ 135 - 0
controllers/new_mobile_api_controllers/dialysis_parameter_api_controller.go View File

@@ -0,0 +1,135 @@
1
+package new_mobile_api_controllers
2
+
3
+import (
4
+	"XT_New/controllers/mobile_api_controllers"
5
+	"XT_New/enums"
6
+	"XT_New/service"
7
+	"fmt"
8
+	"time"
9
+)
10
+
11
+type DialysisParamerterApiController struct {
12
+	mobile_api_controllers.MobileBaseAPIAuthController
13
+}
14
+
15
+func (this *DialysisParamerterApiController) GetAllMobileZon() {
16
+
17
+	adminUserInfo := this.GetMobileAdminUserInfo()
18
+	orgid := adminUserInfo.Org.Id
19
+	err, zone := service.GetAllDeviceZone(orgid)
20
+	if err == nil {
21
+		this.ServeSuccessJSON(map[string]interface{}{
22
+			"zone": zone,
23
+		})
24
+	}
25
+}
26
+
27
+func (this *DialysisParamerterApiController) GetMobileDialysisParameters() {
28
+	timeLayout := "2006-01-02"
29
+	loc, _ := time.LoadLocation("Local")
30
+	adminUserInfo := this.GetMobileAdminUserInfo()
31
+	orgid := adminUserInfo.Org.Id
32
+	fmt.Println(orgid)
33
+	keywords := this.GetString("keyword")
34
+	fmt.Println("keyword", keywords)
35
+	start_time := this.GetString("start_time")
36
+	fmt.Println("start_time", start_time)
37
+	limit, _ := this.GetInt64("limit")
38
+	fmt.Println(limit)
39
+	page, _ := this.GetInt64("page")
40
+	fmt.Println(page)
41
+	partitionType, _ := this.GetInt64("partitionType")
42
+	fmt.Println("partiontype", partitionType)
43
+	scheduleType, _ := this.GetInt64("scheduleType")
44
+	fmt.Println(scheduleType)
45
+	theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
46
+	if len(keywords) > 0 {
47
+		dialysisSchedule, err, total := service.GetDialysisParametersByKeyword(orgid, keywords, scheduleType, partitionType, page, limit, theTime.Unix())
48
+		if err == nil {
49
+			this.ServeSuccessJSON(map[string]interface{}{
50
+				"schedule": dialysisSchedule,
51
+				"total":    total,
52
+			})
53
+		} else {
54
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
55
+		}
56
+	} else {
57
+		dialysisSchedule, err, total := service.GetDialysisParameter(orgid, theTime.Unix(), scheduleType, partitionType, page, limit)
58
+		if err == nil {
59
+			this.ServeSuccessJSON(map[string]interface{}{
60
+				"schedule": dialysisSchedule,
61
+				"total":    total,
62
+			})
63
+		} else {
64
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
65
+		}
66
+	}
67
+}
68
+
69
+func (this *DialysisParamerterApiController) GetMobileWareHouseOutList() {
70
+
71
+	timeLayout := "2006-01-02"
72
+	loc, _ := time.LoadLocation("Local")
73
+	start_time := this.GetString("start_time")
74
+	startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
75
+	end_time := this.GetString("end_time")
76
+	endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
77
+	fmt.Println(start_time, end_time)
78
+	orgId := this.GetMobileAdminUserInfo().Org.Id
79
+	wareoutlist, err := service.GetWareHouseOutList(startime.Unix(), endtime.Unix(), orgId)
80
+	if err == nil {
81
+		this.ServeSuccessJSON(map[string]interface{}{
82
+			"wareoutlist": wareoutlist,
83
+		})
84
+	}
85
+}
86
+
87
+func (this *DialysisParamerterApiController) GetAllMobileMaterial() {
88
+
89
+	timeLayout := "2006-01-02"
90
+	loc, _ := time.LoadLocation("Local")
91
+	start_time := this.GetString("startime")
92
+	startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
93
+	fmt.Println("开始时间", startime)
94
+	endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 23:59:59", loc)
95
+	fmt.Println("结束时间", endtime)
96
+	adminUserInfo := this.GetMobileAdminUserInfo()
97
+	orgId := adminUserInfo.Org.Id
98
+	material, err := service.GetAllMaterial(startime.Unix(), endtime.Unix(), orgId)
99
+	if err == nil {
100
+		this.ServeSuccessJSON(map[string]interface{}{
101
+			"material": material,
102
+		})
103
+	}
104
+}
105
+
106
+func (this *DialysisParamerterApiController) GetMobileCollectList() {
107
+
108
+	timeLayout := "2006-01-02"
109
+	loc, _ := time.LoadLocation("Local")
110
+	limit, _ := this.GetInt64("limit")
111
+	fmt.Println(limit)
112
+	page, _ := this.GetInt64("page")
113
+	fmt.Println("page", page)
114
+	partitiontype, _ := this.GetInt64("partitionType")
115
+	fmt.Println(partitiontype)
116
+	scheduletype, _ := this.GetInt64("scheduleType")
117
+	fmt.Println(scheduletype)
118
+	start_time := this.GetString("start_time")
119
+	fmt.Println(start_time)
120
+	startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
121
+	orgId := this.GetMobileAdminUserInfo().Org.Id
122
+	endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 23:59:59", loc)
123
+	keyword := this.GetString("keyword")
124
+	//获取透析参数数据
125
+	schedule, err, total := service.GetCollectList(limit, page, partitiontype, scheduletype, startime.Unix(), orgId, keyword)
126
+	//获取透析耗材数据
127
+	consumables, err := service.GetDialysisConsumables(startime.Unix(), endtime.Unix(), orgId)
128
+	if err == nil {
129
+		this.ServeSuccessJSON(map[string]interface{}{
130
+			"schedule":    schedule,
131
+			"total":       total,
132
+			"consumables": consumables,
133
+		})
134
+	}
135
+}

+ 14 - 0
controllers/new_mobile_api_controllers/dialysis_parameter_api_router.go View File

@@ -0,0 +1,14 @@
1
+package new_mobile_api_controllers
2
+
3
+import (
4
+	"github.com/astaxie/beego"
5
+)
6
+
7
+func DialysisParameterApiControllersRegisterRouters() {
8
+
9
+	beego.Router("/m/api/getallmobilezone", &DialysisParamerterApiController{}, "Get:GetAllMobileZon")
10
+	beego.Router("/m/api/getmobiledialysisparameters", &DialysisParamerterApiController{}, "Get:GetMobileDialysisParameters")
11
+	beego.Router("/m/api/getmobilewarehouseoutlist", &DialysisParamerterApiController{}, "Get:GetMobileWareHouseOutList")
12
+	beego.Router("/m/api/getallmobilematerial", &DialysisParamerterApiController{}, "Get:GetAllMobileMaterial")
13
+	beego.Router("/m/api/getmobilecollectlist", &DialysisParamerterApiController{}, "Get:GetMobileCollectList")
14
+}

+ 25 - 0
models/dialysis_parameter_models.go View File

@@ -56,3 +56,28 @@ type XtWarehouseOutInfo struct {
56 56
 	TypeName                string  `gorm:"column:type_name" json:"type_name" form:"type_name"`
57 57
 	SpecificationName       string  `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
58 58
 }
59
+
60
+type XtAutomaticReduceDetail struct {
61
+	ID                      int64  `gorm:"column:id" json:"id" form:"id"`
62
+	WarehouseOutId          int64  `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
63
+	WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
64
+	PatientId               int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
65
+	Ctime                   int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
66
+	Mtime                   int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
67
+	Status                  int64  `gorm:"column:status" json:"status" form:"status"`
68
+	RecordTime              int64  `gorm:"column:record_time" json:"record_time" form:"record_time"`
69
+	OrgId                   int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
70
+	GoodId                  int64  `gorm:"column:good_id" json:"good_id" form:"good_id"`
71
+	GoodTypeId              int64  `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
72
+	Count                   int64  `gorm:"column:count" json:"count" form:"count"`
73
+	TypeName                string `gorm:"column:type_name" json:"type_name" form:"type_name"`
74
+	SpecificationName       string `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
75
+}
76
+
77
+type DialysisPrescriptionCount struct {
78
+	PatientId     int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
79
+	Count         int64 `gorm:"column:count" json:"count" form:"count"`
80
+	OrgId         int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
81
+	RecordDate    int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
82
+	Anticoagulant int64 `gorm:"column:anticoagulant" json:"anticoagulant" form:"anticoagulant"`
83
+}

+ 1 - 0
routers/router.go View File

@@ -65,4 +65,5 @@ func init() {
65 65
 	controllers.DoctorScheduleRouters()
66 66
 	new_m_api.StaffScheduleApiControllersRegisterRouters()
67 67
 	controllers.DialysisPrameteRoutes()
68
+	new_m_api.DialysisParameterApiControllersRegisterRouters()
68 69
 }

+ 169 - 4
service/dialysis_parameter_service.go View File

@@ -2,11 +2,12 @@ package service
2 2
 
3 3
 import (
4 4
 	"XT_New/models"
5
+	"fmt"
5 6
 	"github.com/jinzhu/gorm"
6 7
 )
7 8
 
8 9
 func GetDialysisParametersByKeyword(orgID int64, keyword string, schedulType int64, partitionType int64, page int64, limit int64, schedulDate int64) ([]*models.DialysisParameter, error, int64) {
9
-
10
+	fmt.Println("scheduletye ======================", schedulType)
10 11
 	var patients []*models.Patients
11 12
 	getPatientErr := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ? AND (name like ? OR dialysis_no like ?)", orgID, "%"+keyword+"%", "%"+keyword+"%").Find(&patients).Error
12 13
 	if getPatientErr != nil {
@@ -34,7 +35,6 @@ func GetDialysisParametersByKeyword(orgID int64, keyword string, schedulType int
34 35
 	}
35 36
 	if partitionType > 0 {
36 37
 		db = db.Joins("inner join xt_device_number as d_n on d_n.id = xt_schedule.bed_id and d_n.zone_id = ? and d_n.status = 1", partitionType)
37
-		// db = db.Where("partition_id = ?", partitionType)
38 38
 	}
39 39
 	if schedulDate > 0 {
40 40
 		db = db.Where("schedule_date = ?", schedulDate)
@@ -49,7 +49,6 @@ func GetDialysisParameter(orgID int64, schedulDate int64, schedulType int64, par
49 49
 	db := readDb.
50 50
 		Model(&models.MonitorDialysisSchedule{}).
51 51
 		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
52
-		// Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
53 52
 		Preload("TreatmentMode", "status = 1").
54 53
 		Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
55 54
 		Preload("AssessmentBeforeDislysis", "status = 1 AND  user_org_id = ?", orgID).
@@ -68,7 +67,6 @@ func GetDialysisParameter(orgID int64, schedulDate int64, schedulType int64, par
68 67
 	}
69 68
 	if partitionType > 0 {
70 69
 		db = db.Joins("inner join xt_device_number on xt_device_number.id = xt_schedule.bed_id and xt_device_number.zone_id = ? and xt_device_number.status = 1", partitionType)
71
-		// db = db.Where("partition_id = ?", partitionType)
72 70
 	}
73 71
 	offset := (page - 1) * limit
74 72
 	err = db.Count(&total).Offset(offset).Limit(limit).Order("bed_id desc").Find(&schedule).Error
@@ -109,3 +107,170 @@ func GetWareHouseOutList(startime int64, endtime int64, orgid int64) (warehouse
109 107
 	err = db.Select("x.id,x.warehouse_out_id,x.good_id,x.good_type_id,x.count,x.warehouse_out_order_number,x.sys_record_time,s.specification_name,t.type_name").Joins("left join xt_good_information as s on s.id = x.good_id").Where("s.status = 1 and s.org_id = ?", orgid).Joins("left join xt_goods_type as t on t.id = x.good_type_id").Order("x.id desc").Scan(&warehouse).Error
110 108
 	return warehouse, err
111 109
 }
110
+
111
+func GetAllMaterial(startime int64, endtime int64, orgid int64) (reducedetail []*models.XtAutomaticReduceDetail, err error) {
112
+
113
+	db := XTReadDB().Table("xt_automatic_reduce_detail as x").Where("x.status = 1")
114
+	if startime > 0 {
115
+		db = db.Where("x.record_time>=?", startime)
116
+	}
117
+	if endtime > 0 {
118
+		db = db.Where("x.record_time<=?", endtime)
119
+	}
120
+	if orgid > 0 {
121
+		db = db.Where("x.org_id = ?", orgid)
122
+	}
123
+	err = db.Select("x.patient_id,x.record_time,x.good_id,t.type_name").Joins("left join xt_goods_type as t on t.id = x.good_type_id").Group("x.good_type_id").Scan(&reducedetail).Error
124
+	return reducedetail, err
125
+}
126
+
127
+func GetCollectList(limit int64, page int64, partitionType int64, schedulType int64, schedulDate int64, orgID int64, keyword string) ([]*models.DialysisParameter, error, int64) {
128
+
129
+	var patients []*models.Patients
130
+	getPatientErr := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ? AND (name like ? OR dialysis_no like ?)", orgID, "%"+keyword+"%", "%"+keyword+"%").Find(&patients).Error
131
+	if getPatientErr != nil {
132
+		return nil, getPatientErr, 0
133
+	}
134
+	patientIDs := make([]int64, len(patients))
135
+	for index, patient := range patients {
136
+		patientIDs[index] = patient.ID
137
+	}
138
+
139
+	db := readDb.
140
+		Model(&models.DialysisSchedule{}).
141
+		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
142
+		// Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
143
+		Preload("TreatmentMode", "status = 1").
144
+		Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
145
+		Preload("AssessmentBeforeDislysis", "status = 1 AND  user_org_id = ?", orgID).
146
+		Preload("AssessmentAfterDislysis", "status = 1 AND  user_org_id = ?", orgID).
147
+		Preload("MonitoringRecord", "status = 1 AND  user_org_id = ?", orgID).
148
+		Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
149
+		Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
150
+	db = db.Where("xt_schedule.status = 1 AND patient_id in (?)", patientIDs)
151
+	if schedulType > 0 {
152
+		db = db.Where("schedule_type = ?", schedulType)
153
+	}
154
+	if partitionType > 0 {
155
+		db = db.Joins("inner join xt_device_number as d_n on d_n.id = xt_schedule.bed_id and d_n.zone_id = ? and d_n.status = 1", partitionType)
156
+		// db = db.Where("partition_id = ?", partitionType)
157
+	}
158
+	if schedulDate > 0 {
159
+		db = db.Where("schedule_date = ?", schedulDate)
160
+	}
161
+	var schedules []*models.DialysisParameter
162
+	total := int64(0)
163
+	err := db.Count(&total).Offset(limit * (page - 1)).Limit(limit).Order("schedule_date desc").Find(&schedules).Error
164
+	return schedules, err, total
165
+}
166
+
167
+func GetDialysisConsumables(startime int64, endtime int64, orgid int64) (reducedetail []*models.XtAutomaticReduceDetail, err error) {
168
+
169
+	db := XTReadDB().Table("xt_automatic_reduce_detail as x").Where("x.status = 1")
170
+	table := XTReadDB().Table("xt_warehouse_out_info as f").Where("f.status = 1 and f.org_id = ?", orgid)
171
+	fmt.Println(table)
172
+	if startime > 0 {
173
+		db = db.Where("x.record_time >=?", startime)
174
+	}
175
+	if endtime > 0 {
176
+		db = db.Where("x.record_time <=?", endtime)
177
+	}
178
+	if orgid > 0 {
179
+		db = db.Where("x.org_id =?", orgid)
180
+	}
181
+	err = db.Select("x.patient_id,f.count,x.good_id,x.good_type_id,t.specification_name,s.type_name").Joins("left join xt_good_information as t on t.id = x.good_id").Where("t.org_id = ? and t.status = 1", orgid).Joins("left join xt_goods_type as s on s.id = x.good_type_id").Joins("left join xt_warehouse_out_info as f on f.id = x.warehouse_out_id").Scan(&reducedetail).Error
182
+	return reducedetail, err
183
+}
184
+
185
+func GetBatchCollection(orgID int64, schIDs []string) (schedules []*models.DialysisParameter, err error) {
186
+
187
+	db := readDb.
188
+		Model(&models.DialysisSchedule{}).
189
+		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
190
+		// Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
191
+		Preload("TreatmentMode", "status = 1").
192
+		Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
193
+		Preload("AssessmentBeforeDislysis", "status = 1 AND  user_org_id = ?", orgID).
194
+		Preload("AssessmentAfterDislysis", "status = 1 AND  user_org_id = ?", orgID).
195
+		Preload("MonitoringRecord", "status = 1 AND  user_org_id = ?", orgID).
196
+		Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
197
+		Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
198
+	db = db.Where("xt_schedule.status = 1 AND id in (?)", schIDs)
199
+	err = db.Order("schedule_date desc").Find(&schedules).Error
200
+	return schedules, err
201
+}
202
+
203
+func GetAnticoagulantCount(startime int64, endtime int64, orgid int64) (prescriptionCount []*models.DialysisPrescriptionCount, err error) {
204
+
205
+	db := XTReadDB().Table("xt_dialysis_prescription as x").Where("x.status = 1")
206
+	if orgid > 0 {
207
+		db = db.Where("x.user_org_id = ?", orgid)
208
+	}
209
+	if startime > 0 {
210
+		db = db.Where("x.record_date >= ?", startime)
211
+	}
212
+	if endtime > 0 {
213
+		db = db.Where("x.record_date<=?", endtime)
214
+	}
215
+
216
+	err = db.Select("x.patient_id,x.anticoagulant,x.record_date,count(id) as count").Group("x.anticoagulant").Scan(&prescriptionCount).Error
217
+	return prescriptionCount, err
218
+}
219
+
220
+func GetDialysisTodaySchedulePatient(orgid int64, startime int64, page int64, limit int64) (schedule []*models.XtSchedule, err error) {
221
+	offset := (page - 1) * limit
222
+	err = XTReadDB().Model(&schedule).Where("user_org_id = ? and schedule_date = ? and status = 1", orgid, startime).Offset(offset).Limit(limit).Find(&schedule).Error
223
+	return schedule, err
224
+}
225
+
226
+func GetToDayDialysisPrescription(patientid int64, orgid int64, startime int64) (*models.XtDialysisPrescription, error) {
227
+	prescription := models.XtDialysisPrescription{}
228
+	err := XTReadDB().Model(&prescription).Where("patient_id = ? and user_org_id = ? and record_date = ? and status = 1", patientid, orgid, startime).Find(&prescription).Error
229
+	if err == gorm.ErrRecordNotFound {
230
+		return nil, err
231
+	}
232
+	if err != nil {
233
+		return nil, err
234
+	}
235
+	return &prescription, nil
236
+
237
+}
238
+
239
+func GetLastDialysisPrescription(patientid int64, orgid int64) (models.XtDialysisPrescription, error) {
240
+
241
+	prescription := models.XtDialysisPrescription{}
242
+	err = XTReadDB().Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1", patientid, orgid).Last(&prescription).Error
243
+	return prescription, err
244
+}
245
+
246
+func GetLastAssessmentBeforDialysis(patientid int64, orgid int64) (models.PredialysisEvaluation, error) {
247
+
248
+	evaluation := models.PredialysisEvaluation{}
249
+	err := XTReadDB().Model(&evaluation).Where("patient_id = ? and user_org_id = ? and status = 1", patientid, orgid).Last(&evaluation).Error
250
+	return evaluation, err
251
+}
252
+
253
+func GetDialysisPrescriptionList(patientid int64, orgid int64, startime int64) (models.XtDialysisPrescription, error) {
254
+	prescription := models.XtDialysisPrescription{}
255
+	err := XTReadDB().Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientid, orgid, startime).Find(&prescription).Error
256
+	return prescription, err
257
+}
258
+
259
+func GetTodayAssessmentBeforDialysis(patientid int64, orgid int64, startime int64) (*models.PredialysisEvaluation, error) {
260
+
261
+	evaluation := models.PredialysisEvaluation{}
262
+	err := XTReadDB().Model(&evaluation).Where("patient_id = ? and user_org_id = ? and assessment_date = ? and status = 1", patientid, orgid, startime).Find(&evaluation).Error
263
+	if err == gorm.ErrRecordNotFound {
264
+		return nil, err
265
+	}
266
+	if err != nil {
267
+		return nil, err
268
+	}
269
+	return &evaluation, nil
270
+}
271
+
272
+func GetAssessmentBeforDialysisByStartime(patientid int64, orgid int64, startime int64) (models.PredialysisEvaluation, error) {
273
+	evaluation := models.PredialysisEvaluation{}
274
+	err := XTReadDB().Model(&evaluation).Where("patient_id = ? and user_org_id = ? and assessment_date = ? and status = 1", patientid, orgid, startime).Find(&evaluation).Error
275
+	return evaluation, err
276
+}