Browse Source

透析参数

XMLWAN 4 years ago
parent
commit
6c953d4568

+ 84 - 10
controllers/dialysis_parameter_api_controller.go View File

@@ -94,6 +94,8 @@ func (this *DialysisPrameterApiController) GetDialysisParameters() {
94 94
 }
95 95
 
96 96
 func (this *DialysisPrameterApiController) GetDialysisBatchParameters() {
97
+	timeLayout := "2006-01-02"
98
+	loc, _ := time.LoadLocation("Local")
97 99
 	adminUser := this.GetAdminUserInfo()
98 100
 	orgId := adminUser.CurrentOrgId
99 101
 	schIDStr := this.GetString("ids")
@@ -102,11 +104,40 @@ func (this *DialysisPrameterApiController) GetDialysisBatchParameters() {
102 104
 		return
103 105
 	}
104 106
 	idStrs := strings.Split(schIDStr, ",")
105
-
107
+	startime := this.GetString("startime")
108
+	theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", startime+" 00:00:00", loc)
106 109
 	parameters, err := service.GetDialysisBatchParameters(idStrs, orgId)
110
+	var vlist []interface{}
111
+	var elist []interface{}
112
+	for _, item := range parameters {
113
+		//查询当前日期的病人是否存在数据
114
+		_, errcode := service.GetToDayDialysisPrescription(item.PatientId, orgId, theTime.Unix())
115
+		if errcode == gorm.ErrRecordNotFound {
116
+			//查询每个病人透析处方的最后一次数据
117
+			prescription, _ := service.GetLastDialysisPrescription(item.PatientId, orgId)
118
+			vlist = append(vlist, prescription)
119
+		} else if errcode == nil {
120
+			//获取当前日期
121
+			prescription, _ := service.GetDialysisPrescriptionList(item.PatientId, orgId, theTime.Unix())
122
+			vlist = append(vlist, prescription)
123
+		}
124
+
125
+		_, errcodes := service.GetTodayAssessmentBeforDialysis(item.PatientId, orgId, theTime.Unix())
126
+		if errcodes == gorm.ErrRecordNotFound {
127
+			//查询每个病人透前评估的最后一次数据
128
+			dialysis, _ := service.GetLastAssessmentBeforDialysis(item.PatientId, orgId)
129
+			elist = append(elist, dialysis)
130
+		} else if errcodes == nil {
131
+			dialysis, _ := service.GetAssessmentBeforDialysisByStartime(item.PatientId, orgId, theTime.Unix())
132
+			elist = append(elist, dialysis)
133
+		}
134
+
135
+	}
107 136
 	if err == nil {
108 137
 		this.ServeSuccessJSON(map[string]interface{}{
109
-			"schedule": parameters,
138
+			"schedule":     parameters,
139
+			"prescription": vlist,
140
+			"dialysbefor":  elist,
110 141
 		})
111 142
 	}
112 143
 }
@@ -171,9 +202,10 @@ func (this *DialysisPrameterApiController) GetCollectList() {
171 202
 
172 203
 	//查询今日排班的病人
173 204
 	patient, err := service.GetDialysisTodaySchedulePatient(orgId, startime.Unix(), page, limit)
174
-
175 205
 	var vlist []interface{}
206
+	var clist []interface{}
176 207
 	for _, item := range patient {
208
+		fmt.Println("---------", item.PatientId)
177 209
 		//查询当前日期的病人是否存在数据
178 210
 		_, errcode := service.GetToDayDialysisPrescription(item.PatientId, orgId, startime.Unix())
179 211
 		if errcode == gorm.ErrRecordNotFound {
@@ -186,15 +218,27 @@ func (this *DialysisPrameterApiController) GetCollectList() {
186 218
 			vlist = append(vlist, prescription)
187 219
 		}
188 220
 
221
+		//查询每个病人当前日期是否存在数据
222
+		_, errco := service.GetAotoMaticReduceByPatientId(item.PatientId, orgId, startime.Unix(), endtime.Unix())
223
+		fmt.Println("errco--------------------------", errco)
224
+		if errco == gorm.ErrRecordNotFound {
225
+			reduece, _ := service.GetMaticReduece(item.PatientId, orgId)
226
+			clist = append(clist, reduece)
227
+		} else if errco == nil {
228
+			reduece, _ := service.GetMaticeReduceByPatientId(item.PatientId, orgId, startime.Unix(), endtime.Unix())
229
+			clist = append(clist, reduece)
230
+		}
189 231
 	}
190 232
 	//获取透析耗材数据
191 233
 	consumables, err := service.GetDialysisConsumables(startime.Unix(), endtime.Unix(), orgId)
234
+
192 235
 	if err == nil {
193 236
 		this.ServeSuccessJSON(map[string]interface{}{
194
-			"schedule":    schedule,
195
-			"total":       total,
196
-			"consumables": consumables,
197
-			"prescrption": vlist,
237
+			"schedule":     schedule,
238
+			"total":        total,
239
+			"consumables":  consumables,
240
+			"prescription": vlist,
241
+			"reducelist":   clist,
198 242
 		})
199 243
 	}
200 244
 }
@@ -211,17 +255,47 @@ func (this *DialysisPrameterApiController) GetBatchCollection() {
211 255
 	schIDStr := this.GetString("ids")
212 256
 	//获取透析耗材数据
213 257
 	consumables, err := service.GetDialysisConsumables(startime.Unix(), endtime.Unix(), orgId)
258
+
214 259
 	if len(schIDStr) == 0 {
215 260
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
216 261
 		return
217 262
 	}
218 263
 	idStrs := strings.Split(schIDStr, ",")
219 264
 	fmt.Println(idStrs)
265
+	var vlist []interface{}
266
+	var clist []interface{}
220 267
 	schedule, err := service.GetBatchCollection(orgId, idStrs)
268
+	for _, item := range schedule {
269
+		//查询当前日期的病人是否存在数据
270
+		_, errcode := service.GetToDayDialysisPrescription(item.PatientId, orgId, startime.Unix())
271
+		if errcode == gorm.ErrRecordNotFound {
272
+			//查询每个病人透析处方的最后一次数据
273
+			prescription, _ := service.GetLastDialysisPrescription(item.PatientId, orgId)
274
+			vlist = append(vlist, prescription)
275
+		} else if errcode == nil {
276
+			//获取当前日期
277
+			prescription, _ := service.GetDialysisPrescriptionList(item.PatientId, orgId, startime.Unix())
278
+			vlist = append(vlist, prescription)
279
+		}
280
+
281
+		//查询每个病人当前日期是否存在数据
282
+		_, errco := service.GetAotoMaticReduceByPatientId(item.PatientId, orgId, startime.Unix(), endtime.Unix())
283
+		fmt.Println("errco", errco)
284
+		if errco == gorm.ErrRecordNotFound {
285
+			reduece, _ := service.GetMaticReduece(item.PatientId, orgId)
286
+			clist = append(clist, reduece)
287
+		} else if errco == nil {
288
+			reduece, _ := service.GetMaticeReduceByPatientId(item.PatientId, orgId, startime.Unix(), endtime.Unix())
289
+			clist = append(clist, reduece)
290
+		}
291
+
292
+	}
221 293
 	if err == nil {
222 294
 		this.ServeSuccessJSON(map[string]interface{}{
223
-			"schedule":    schedule,
224
-			"consumables": consumables,
295
+			"schedule":     schedule,
296
+			"consumables":  consumables,
297
+			"prescripiton": vlist,
298
+			"reducelist":   clist,
225 299
 		})
226 300
 	}
227 301
 }
@@ -247,7 +321,7 @@ func (this *DialysisPrameterApiController) GetGatherList() {
247 321
 
248 322
 	//统计抗凝剂数据
249 323
 	count, err := service.GetAnticoagulantCount(startime.Unix(), endtime.Unix(), orgId)
250
-	fmt.Println("er--------------------------------------", count)
324
+
251 325
 	if err == nil {
252 326
 		this.ServeSuccessJSON(map[string]interface{}{
253 327
 			"warehouselist": warehouselist,

+ 95 - 5
controllers/new_mobile_api_controllers/dialysis_parameter_api_controller.go View File

@@ -5,6 +5,7 @@ import (
5 5
 	"XT_New/enums"
6 6
 	"XT_New/service"
7 7
 	"fmt"
8
+	"github.com/jinzhu/gorm"
8 9
 	"time"
9 10
 )
10 11
 
@@ -55,10 +56,40 @@ func (this *DialysisParamerterApiController) GetMobileDialysisParameters() {
55 56
 		}
56 57
 	} else {
57 58
 		dialysisSchedule, err, total := service.GetDialysisParameter(orgid, theTime.Unix(), scheduleType, partitionType, page, limit)
59
+		//查询今日排班的病人
60
+		patient, err := service.GetDialysisTodaySchedulePatient(orgid, theTime.Unix(), page, limit)
61
+		var vlist []interface{}
62
+		var elist []interface{}
63
+		for _, item := range patient {
64
+			//查询当前日期的病人是否存在数据
65
+			_, errcode := service.GetToDayDialysisPrescription(item.PatientId, orgid, theTime.Unix())
66
+			if errcode == gorm.ErrRecordNotFound {
67
+				//查询每个病人透析处方的最后一次数据
68
+				prescription, _ := service.GetLastDialysisPrescription(item.PatientId, orgid)
69
+				vlist = append(vlist, prescription)
70
+			} else if errcode == nil {
71
+				//获取当前日期
72
+				prescription, _ := service.GetDialysisPrescriptionList(item.PatientId, orgid, theTime.Unix())
73
+				vlist = append(vlist, prescription)
74
+			}
75
+
76
+			_, errcodes := service.GetTodayAssessmentBeforDialysis(item.PatientId, orgid, theTime.Unix())
77
+			if errcodes == gorm.ErrRecordNotFound {
78
+				//查询每个病人透前评估的最后一次数据
79
+				dialysis, _ := service.GetLastAssessmentBeforDialysis(item.PatientId, orgid)
80
+				elist = append(elist, dialysis)
81
+			} else if errcodes == nil {
82
+				dialysis, _ := service.GetAssessmentBeforDialysisByStartime(item.PatientId, orgid, theTime.Unix())
83
+				elist = append(elist, dialysis)
84
+			}
85
+
86
+		}
58 87
 		if err == nil {
59 88
 			this.ServeSuccessJSON(map[string]interface{}{
60
-				"schedule": dialysisSchedule,
61
-				"total":    total,
89
+				"schedule":     dialysisSchedule,
90
+				"total":        total,
91
+				"prescription": vlist,
92
+				"dialysbefor":  elist,
62 93
 			})
63 94
 		} else {
64 95
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
@@ -123,13 +154,72 @@ func (this *DialysisParamerterApiController) GetMobileCollectList() {
123 154
 	keyword := this.GetString("keyword")
124 155
 	//获取透析参数数据
125 156
 	schedule, err, total := service.GetCollectList(limit, page, partitiontype, scheduletype, startime.Unix(), orgId, keyword)
157
+	//查询今日排班的病人
158
+	patient, err := service.GetDialysisTodaySchedulePatient(orgId, startime.Unix(), page, limit)
159
+	var vlist []interface{}
160
+	var clist []interface{}
161
+	for _, item := range patient {
162
+
163
+		//查询当前日期的病人是否存在数据
164
+		_, errcode := service.GetToDayDialysisPrescription(item.PatientId, orgId, startime.Unix())
165
+		if errcode == gorm.ErrRecordNotFound {
166
+			//查询每个病人透析处方的最后一次数据
167
+			prescription, _ := service.GetLastDialysisPrescription(item.PatientId, orgId)
168
+			vlist = append(vlist, prescription)
169
+		} else if errcode == nil {
170
+			//获取当前日期
171
+			prescription, _ := service.GetDialysisPrescriptionList(item.PatientId, orgId, startime.Unix())
172
+			vlist = append(vlist, prescription)
173
+		}
174
+
175
+		//查询每个病人当前日期是否存在数据
176
+		_, errco := service.GetAotoMaticReduceByPatientId(item.PatientId, orgId, startime.Unix(), endtime.Unix())
177
+		if errco == gorm.ErrRecordNotFound {
178
+			reduece, _ := service.GetMaticReduece(item.PatientId, orgId)
179
+			clist = append(clist, reduece)
180
+		} else if errco == nil {
181
+			reduece, _ := service.GetMaticeReduceByPatientId(item.PatientId, orgId, startime.Unix(), endtime.Unix())
182
+			clist = append(clist, reduece)
183
+		}
184
+	}
185
+	//获取透析耗材数据
186
+	consumables, err := service.GetDialysisConsumables(startime.Unix(), endtime.Unix(), orgId)
187
+	if err == nil {
188
+		this.ServeSuccessJSON(map[string]interface{}{
189
+			"schedule":     schedule,
190
+			"total":        total,
191
+			"consumables":  consumables,
192
+			"prescription": vlist,
193
+			"reducelist":   clist,
194
+		})
195
+	}
196
+}
197
+
198
+func (this *DialysisParamerterApiController) GetMobileGatherList() {
199
+
200
+	timeLayout := "2006-01-02"
201
+	loc, _ := time.LoadLocation("Local")
202
+	start_time := this.GetString("start_time")
203
+	end_time := this.GetString("end_time")
204
+	startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
205
+	endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
206
+	adminUserInfo := this.GetMobileAdminUserInfo()
207
+	orgId := adminUserInfo.Org.Id
208
+	fmt.Println("开始时间", startime)
209
+	fmt.Println("结束时间", endtime)
210
+	warehouselist, err := service.GetWareHouseOutList(startime.Unix(), endtime.Unix(), orgId)
211
+
126 212
 	//获取透析耗材数据
127 213
 	consumables, err := service.GetDialysisConsumables(startime.Unix(), endtime.Unix(), orgId)
214
+
215
+	//统计抗凝剂数据
216
+	count, err := service.GetAnticoagulantCount(startime.Unix(), endtime.Unix(), orgId)
217
+
128 218
 	if err == nil {
129 219
 		this.ServeSuccessJSON(map[string]interface{}{
130
-			"schedule":    schedule,
131
-			"total":       total,
132
-			"consumables": consumables,
220
+			"warehouselist": warehouselist,
221
+			"consumables":   consumables,
222
+			"count":         count,
133 223
 		})
134 224
 	}
135 225
 }

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

@@ -11,4 +11,5 @@ func DialysisParameterApiControllersRegisterRouters() {
11 11
 	beego.Router("/m/api/getmobilewarehouseoutlist", &DialysisParamerterApiController{}, "Get:GetMobileWareHouseOutList")
12 12
 	beego.Router("/m/api/getallmobilematerial", &DialysisParamerterApiController{}, "Get:GetAllMobileMaterial")
13 13
 	beego.Router("/m/api/getmobilecollectlist", &DialysisParamerterApiController{}, "Get:GetMobileCollectList")
14
+	beego.Router("/m/api/getmobilegatherlist", &DialysisParamerterApiController{}, "Get:GetMobileGatherList")
14 15
 }

+ 19 - 0
models/dialysis_parameter_models.go View File

@@ -81,3 +81,22 @@ type DialysisPrescriptionCount struct {
81 81
 	RecordDate    int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
82 82
 	Anticoagulant int64 `gorm:"column:anticoagulant" json:"anticoagulant" form:"anticoagulant"`
83 83
 }
84
+
85
+type BloodAutomaticReduceDetail struct {
86
+	ID                      int64  `gorm:"column:id" json:"id" form:"id"`
87
+	WarehouseOutId          int64  `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
88
+	WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
89
+	PatientId               int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
90
+	Ctime                   int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
91
+	Mtime                   int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
92
+	Status                  int64  `gorm:"column:status" json:"status" form:"status"`
93
+	RecordTime              int64  `gorm:"column:record_time" json:"record_time" form:"record_time"`
94
+	OrgId                   int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
95
+	GoodId                  int64  `gorm:"column:good_id" json:"good_id" form:"good_id"`
96
+	GoodTypeId              int64  `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
97
+	Count                   int64  `gorm:"column:count" json:"count" form:"count"`
98
+}
99
+
100
+func (BloodAutomaticReduceDetail) TableName() string {
101
+	return "xt_automatic_reduce_detail"
102
+}

+ 30 - 2
service/dialysis_parameter_service.go View File

@@ -178,7 +178,7 @@ func GetDialysisConsumables(startime int64, endtime int64, orgid int64) (reduced
178 178
 	if orgid > 0 {
179 179
 		db = db.Where("x.org_id =?", orgid)
180 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
181
+	err = db.Select("x.patient_id,x.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 182
 	return reducedetail, err
183 183
 }
184 184
 
@@ -204,7 +204,7 @@ func GetAnticoagulantCount(startime int64, endtime int64, orgid int64) (prescrip
204 204
 
205 205
 	db := XTReadDB().Table("xt_dialysis_prescription as x").Where("x.status = 1")
206 206
 	if orgid > 0 {
207
-		db = db.Where("x.user_org_id = ?", orgid)
207
+		db = db.Where("x.user_org_id = ? and x.anticoagulant <> 0", orgid)
208 208
 	}
209 209
 	if startime > 0 {
210 210
 		db = db.Where("x.record_date >= ?", startime)
@@ -274,3 +274,31 @@ func GetAssessmentBeforDialysisByStartime(patientid int64, orgid int64, startime
274 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 275
 	return evaluation, err
276 276
 }
277
+
278
+func GetAotoMaticReduceByPatientId(patientid int64, orgid int64, startime int64, endtime int64) (*models.BloodAutomaticReduceDetail, error) {
279
+
280
+	detail := models.BloodAutomaticReduceDetail{}
281
+	err := XTReadDB().Model(&detail).Where("patient_id = ? and org_id =? and record_time >=? and record_time <=? and status = 1", patientid, orgid, startime, endtime).Find(&detail).Error
282
+	if err == gorm.ErrRecordNotFound {
283
+		return nil, err
284
+	}
285
+	if err != nil {
286
+		return nil, err
287
+	}
288
+	return &detail, nil
289
+}
290
+
291
+func GetMaticReduece(patientid int64, orgid int64) (models.BloodAutomaticReduceDetail, error) {
292
+
293
+	detail := models.BloodAutomaticReduceDetail{}
294
+	err := XTReadDB().Model(&detail).Where("patient_id = ? and org_id= ?  and status = 1", patientid, orgid).Last(&detail).Error
295
+
296
+	return detail, err
297
+}
298
+
299
+func GetMaticeReduceByPatientId(patientid int64, orgid int64, startime int64, endtime int64) (models.BloodAutomaticReduceDetail, error) {
300
+
301
+	detail := models.BloodAutomaticReduceDetail{}
302
+	err := XTReadDB().Model(&detail).Where("patient_id = ? and org_id = ? and record_time >=? and record_time<=? and status =1", patientid, orgid, startime, endtime).Find(&detail).Error
303
+	return detail, err
304
+}