3 Commits 496d1a6937 ... 49f6db926b

Autor SHA1 Mensagem Data
  陈少旭 49f6db926b 提交代码 3 semanas atrás
  陈少旭 1d2a347acd Merge branch '20230223_xt_api_new_branch' of http://git.shengws.com/csx/XT_New into 20230223_xt_api_new_branch 3 semanas atrás
  陈少旭 c23d26905e 提交代码 3 semanas atrás

+ 34 - 0
controllers/his_export_data_controller.go Ver arquivo

@@ -28,6 +28,7 @@ func HisExportDataApiRegistRouters() {
28 28
 	beego.Router("/api/export/10697/summary", &HisExportDataController{}, "Get:Get10697SummaryExportData")
29 29
 
30 30
 	beego.Router("/api/export/10697/summary", &HisExportDataController{}, "Get:Get10697SummaryExportData")
31
+	beego.Router("/api/export/summary", &HisExportDataController{}, "Get:GetSummaryExport")
31 32
 
32 33
 	beego.Router("/api/batch/orderlist", &HisExportDataController{}, "Get:GetBatchOrderDetail")
33 34
 
@@ -126,6 +127,39 @@ func (c *HisExportDataController) Get10697SummaryExportData() {
126 127
 	})
127 128
 }
128 129
 
130
+func (c *HisExportDataController) GetSummaryExport() {
131
+	start_time := c.GetString("start_time")
132
+	end_time := c.GetString("end_time")
133
+	//ins := c.GetString("ins")
134
+	timeLayout := "2006-01-02"
135
+	loc, _ := time.LoadLocation("Local")
136
+	var startTime int64
137
+	if len(start_time) > 0 {
138
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
139
+		if err != nil {
140
+			fmt.Println(err)
141
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
142
+			return
143
+		}
144
+		startTime = theTime.Unix()
145
+	}
146
+	var endTime int64
147
+	if len(end_time) > 0 {
148
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
149
+		if err != nil {
150
+			utils.ErrorLog(err.Error())
151
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
152
+			return
153
+		}
154
+		endTime = theTime.Unix()
155
+	}
156
+	fmt.Println("111111")
157
+	result, _ := service.GetHisOrderBy10697SummaryThree(start_time, end_time, startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
158
+	c.ServeSuccessJSON(map[string]interface{}{
159
+		"result": result,
160
+	})
161
+}
162
+
129 163
 func (c *HisExportDataController) GetExportSettleData() {
130 164
 	patient_id, _ := c.GetInt64("patient_id", 0)
131 165
 	start_time := c.GetString("start_time")

+ 19 - 5
controllers/new_stock_api_controller.go Ver arquivo

@@ -196,16 +196,15 @@ func (this *NewStockApiController) GetHisDrugCodeQuery() {
196 196
 		endTime = theTime.Unix()
197 197
 	}
198 198
 
199
-	if is_type == 1 {
199
+	if is_type == 1 { //HIS 药品类医嘱
200 200
 		list, total, _ := service.GetHisDrugCodeQuery(orgId, startTime, endTime, limit, page, is_sale, is_settle, keywords, is_code)
201
-
201
+		//project_list, total, _ := service.GetHisGoodCodeQuery(orgId, startTime, endTime, limit, page, is_sale, is_settle, keywords, is_code)
202 202
 		drug, _ := service.GetAllDrugList(orgId)
203
-
204 203
 		codeConfig, _ := service.GetDrugCodeConfig(orgId)
205
-
206 204
 		patients, _ := service.GetAllpatient(orgId)
207 205
 		this.ServeSuccessJSON(map[string]interface{}{
208
-			"list":       list,
206
+			"list": list,
207
+			//"project_list": project_list,
209 208
 			"total":      total,
210 209
 			"drug":       drug,
211 210
 			"patients":   patients,
@@ -213,6 +212,21 @@ func (this *NewStockApiController) GetHisDrugCodeQuery() {
213 212
 		})
214 213
 	}
215 214
 
215
+	if is_type == 3 { //HIS 耗材类医嘱
216
+		//list, total, _ := service.GetHisDrugCodeQuery(orgId, startTime, endTime, limit, page, is_sale, is_settle, keywords, is_code)
217
+		project_list, total, _ := service.GetHisGoodCodeQuery(orgId, startTime, endTime, limit, page, is_sale, is_settle, keywords, is_code)
218
+		drug, _ := service.GetAllDrugList(orgId)
219
+		codeConfig, _ := service.GetDrugCodeConfig(orgId)
220
+		patients, _ := service.GetAllpatient(orgId)
221
+		this.ServeSuccessJSON(map[string]interface{}{
222
+			"project_list": project_list,
223
+			"total":        total,
224
+			"drug":         drug,
225
+			"patients":     patients,
226
+			"codeConfig":   codeConfig,
227
+		})
228
+	}
229
+
216 230
 	if is_type == 2 {
217 231
 		advice, total, _ := service.GetBloodDrugCode(orgId, startTime, endTime, limit, page, is_sale)
218 232
 

+ 123 - 123
controllers/pharmacy_controller.go Ver arquivo

@@ -144,13 +144,13 @@ func (this *PharmacyController) TodayNumber() {
144 144
 
145 145
 	itotal, _ = service.GetTodayAdviceCount(stime, etime, orgid, 0)
146 146
 
147
-	drug, _ := service.GetAllBaseDrugList(orgid)
147
+	//drug, _ := service.GetAllBaseDrugList(orgid)
148 148
 
149 149
 	config, _ := service.GetDrugCodeConfig(orgid)
150 150
 	this.ServeSuccessJSON(map[string]interface{}{
151 151
 		"wtotal": wtotal,
152 152
 		"itotal": itotal,
153
-		"drug":   drug,
153
+		//"drug":   drug,
154 154
 		"config": config,
155 155
 	})
156 156
 	return
@@ -182,57 +182,22 @@ func (this *PharmacyController) IssuedDrug() {
182 182
 	}
183 183
 	timeLayout := "2006-01-02"
184 184
 	loc, _ := time.LoadLocation("Local")
185
-	var stime, etime int64
186
-	if times == "" {
187
-		stime, etime = service.GetNowTime()
188
-	} else {
189
-		stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
190
-		stime = stmp.Unix()
191
-		etime = stime + 86399
192
-	}
193
-
194
-	var patientsId []int64
185
+	var stime int64
186
+	stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
187
+	stime = stmp.Unix()
188
+	is_medicine := 1
189
+	fmt.Println(partition)
190
+	w_his_advice_patient, _ := service.GetWaitPharmacyHISAdvicePatient(partition, shift, stime, orgid, keyword, is_medicine)
191
+	w_xt_advice_patient, _ := service.GetWaitPharmacyXTPatient(partition, shift, stime, orgid, keyword, is_medicine)
192
+	w_his_goods_patient, _ := service.GetWaitPharmacyHISGoodsPatient(partition, shift, stime, orgid, keyword, is_medicine)
193
+	var patients []*models.PharmacyPatients
194
+	patients = append(patients, w_his_advice_patient...)
195
+	patients = append(patients, w_xt_advice_patient...)
196
+	patients = append(patients, w_his_goods_patient...)
197
+	patients = RemoveRepeatedPurviewElement(patients)
195 198
 
196
-	patient, _ := service.GetPatientKeyWord(keyword, orgid)
197
-	if len(patient) > 0 {
198
-		for _, item := range patient {
199
-			patientsId = append(patientsId, item.ID)
200
-		}
201
-	}
202
-
203
-	//获取排班班次
204
-	schedule, _ := service.GetSchedulePatientId(stime, etime, orgid, shift, partition, patientsId)
205
-
206
-	var ids []int64
207
-	for _, item := range schedule {
208
-		ids = append(ids, item.PatientId)
209
-	}
210
-
211
-	list, _ := service.GetTodayAdviceCountOne(stime, etime, orgid, 1, ids)
212
-
213
-	var flist []models.TmpPatientOne
214
-	if len(list) > 0 {
215
-		for _, item := range list {
216
-			patientlist, _ := service.GetPatientByAdviceId(item.PatientId)
217
-			flist = append(flist, patientlist)
218
-		}
219
-	}
220
-
221
-	listTwo, _ := service.GetTodayAdviceCountTwo(stime, etime, orgid, 1)
222
-
223
-	var vlist []*models.HisDoctorAdviceInfo
224
-	if len(listTwo) > 0 {
225
-		for _, item := range listTwo {
226
-			//查询该患者是否有排班
227
-			scheduleList, _ := service.GetPatientAdviceScheduleByPatient(item.PatientId, item.UserOrgId, item.AdviceDate)
228
-			if len(scheduleList) == 0 {
229
-				vlist = append(vlist, item)
230
-			}
231
-		}
232
-	}
233 199
 	this.ServeSuccessJSON(map[string]interface{}{
234
-		"list":    flist,
235
-		"listTwo": vlist,
200
+		"user_patientList": patients,
236 201
 	})
237 202
 
238 203
 	//if orgid != 10164 && orgid == 3877 && orgid != 10188 && orgid != 10217 && orgid != 9671 && orgid != 10387 && orgid != 10375 && orgid != 10480 && orgid == 10344 {
@@ -257,6 +222,24 @@ func (this *PharmacyController) IssuedDrug() {
257 222
 	//}
258 223
 
259 224
 }
225
+
226
+func RemoveRepeatedPurviewElement(arr []*models.PharmacyPatients) (newArr []*models.PharmacyPatients) {
227
+	newArr = make([]*models.PharmacyPatients, 0)
228
+	for i := 0; i < len(arr); i++ {
229
+		repeat := false
230
+		for j := i + 1; j < len(arr); j++ {
231
+			if arr[i].ID == arr[j].ID {
232
+				repeat = true
233
+				break
234
+			}
235
+		}
236
+		if !repeat {
237
+			newArr = append(newArr, arr[i])
238
+		}
239
+	}
240
+	return
241
+}
242
+
260 243
 func (this *PharmacyController) WaitingDrug() {
261 244
 	var err error
262 245
 	defer func() {
@@ -282,63 +265,23 @@ func (this *PharmacyController) WaitingDrug() {
282 265
 	orgid := this.GetAdminUserInfo().CurrentOrgId
283 266
 	timeLayout := "2006-01-02"
284 267
 	loc, _ := time.LoadLocation("Local")
285
-	var stime, etime int64
286
-	if times == "" {
287
-		stime, etime = service.GetNowTime()
288
-	} else {
289
-		stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
290
-		stime = stmp.Unix()
291
-		etime = stime + 86399
292
-	}
293
-
294
-	var patientsId []int64
295
-
296
-	patient, _ := service.GetPatientKeyWord(keyword, orgid)
297
-
298
-	if len(patient) > 0 {
299
-		for _, item := range patient {
300
-			patientsId = append(patientsId, item.ID)
301
-		}
302
-	}
268
+	var stime int64
303 269
 
304
-	//当未发药的人数
305
-	//获取排班班次
306
-	schedule, _ := service.GetSchedulePatientId(stime, etime, orgid, shift, partition, patientsId)
307
-	var ids []int64
308
-	for _, item := range schedule {
309
-		ids = append(ids, item.PatientId)
310
-	}
311
-
312
-	list, _ := service.GetTodayAdviceCountOne(stime, etime, orgid, 0, ids)
270
+	stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
271
+	stime = stmp.Unix()
313 272
 
314
-	listTwo, _ := service.GetTodayAdviceCountTwo(stime, etime, orgid, 0)
273
+	is_medicine := 0
274
+	w_his_advice_patient, _ := service.GetWaitPharmacyHISAdvicePatient(partition, shift, stime, orgid, keyword, is_medicine)
275
+	w_xt_advice_patient, _ := service.GetWaitPharmacyXTPatient(partition, shift, stime, orgid, keyword, is_medicine)
276
+	w_his_goods_patient, _ := service.GetWaitPharmacyHISGoodsPatient(partition, shift, stime, orgid, keyword, is_medicine)
277
+	var patients []*models.PharmacyPatients
278
+	patients = append(patients, w_his_advice_patient...)
279
+	patients = append(patients, w_xt_advice_patient...)
280
+	patients = append(patients, w_his_goods_patient...)
281
+	patients = RemoveRepeatedPurviewElement(patients)
315 282
 
316
-	var vlist []*models.HisDoctorAdviceInfo
317
-	if len(listTwo) > 0 {
318
-		for _, item := range listTwo {
319
-			//查询该患者是否有排班
320
-			scheduleList, _ := service.GetPatientAdviceScheduleByPatient(item.PatientId, item.UserOrgId, item.AdviceDate)
321
-			if len(scheduleList) == 0 {
322
-				vlist = append(vlist, item)
323
-			}
324
-		}
325
-	}
326
-
327
-	patientList, _ := service.GetAllpatient(orgid)
328
-
329
-	var flist []models.TmpPatientOne
330
-	if len(list) > 0 {
331
-		for _, item := range list {
332
-			patientlist, _ := service.GetPatientByAdviceId(item.PatientId)
333
-			flist = append(flist, patientlist)
334
-		}
335
-	}
336
-	baseList, _ := service.GetAllBaseDrugListTwo(orgid)
337 283
 	this.ServeSuccessJSON(map[string]interface{}{
338
-		"list":        flist,
339
-		"baseList":    baseList,
340
-		"listTwo":     vlist,
341
-		"patientList": patientList,
284
+		"wait_patientList": patients,
342 285
 	})
343 286
 	return
344 287
 
@@ -370,22 +313,16 @@ func (this *PharmacyController) GetPharmacyContent() {
370 313
 	}
371 314
 	var list []*models.PharmacyContent
372 315
 	list, err = service.GetPatientMedication(orgid, patient_id, stime, etime, is_medicine)
373
-
374
-	baseList, _ := service.GetAllBaseDrugListTwo(orgid)
375
-
316
+	list_p, err := service.GetPatientProject(orgid, patient_id, stime, etime, is_medicine)
317
+	list = append(list, list_p...)
318
+	//baseList, _ := service.GetAllBaseDrugListTwo(orgid)
376 319
 	patients, _ := service.GetPatientByIDOne(orgid, patient_id)
377
-	order, _ := service.GetMobiledialysiOrder(orgid, patient_id, stime)
378
-	numberList, _ := service.GetAllBedNumberList(orgid)
379
-	zoneList, _ := service.GetAllZoneByList(orgid)
380
-
320
+	//zoneList, _ := service.GetAllZoneByList(orgid)
381 321
 	appId := this.GetAdminUserInfo().CurrentAppId
382 322
 	adminUserES, _ := service.GetAllAdminUserES(orgid, appId)
383 323
 	allDoctor, _ := service.GetAllDoctor(orgid, appId)
384
-
385 324
 	prescriptionListByToDay, _ := service.GetPrescriptionListByToDay(orgid, patient_id, stime)
386
-
387 325
 	diagnose, _ := service.FindAllDiagnose(orgid)
388
-
389 326
 	config, _ := service.GetDrugCodeConfig(orgid)
390 327
 	if err != nil {
391 328
 		utils.ErrorLog(err.Error())
@@ -394,24 +331,77 @@ func (this *PharmacyController) GetPharmacyContent() {
394 331
 	}
395 332
 	return_value := make(map[string]interface{})
396 333
 	return_value["list"] = list
397
-	return_value["baseList"] = baseList
398 334
 	return_value["patients"] = patients
399
-	return_value["order"] = order
400
-	return_value["numberList"] = numberList
401
-	return_value["zoneList"] = zoneList
402 335
 	return_value["adminUserES"] = adminUserES
403 336
 	return_value["doctors"] = allDoctor
404 337
 	return_value["prescription"] = prescriptionListByToDay
405 338
 	return_value["diagnose"] = diagnose
406 339
 	return_value["config"] = config
407
-	//if is_medicine == 1{发药时间先不展示
408
-	//	return_value["time"] = time
409
-	//}
340
+
410 341
 	this.ServeSuccessJSON(return_value)
411 342
 	return
412 343
 
413 344
 }
414 345
 
346
+//func (this *PharmacyController) GetNewPharmacyContent() {
347
+//	patient_id, _ := this.GetInt64("patient_id", 0)
348
+//	is_medicine, _ := this.GetInt64("is_medicine", 0) //0:待发药,1:已发药
349
+//	times := this.GetString("time", "")
350
+//	orgid := this.GetAdminUserInfo().CurrentOrgId
351
+//	timeLayout := "2006-01-02"
352
+//	loc, _ := time.LoadLocation("Local")
353
+//	var stime, etime int64
354
+//	if times == "" {
355
+//		stime, etime = service.GetNowTime()
356
+//	} else {
357
+//		stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
358
+//		stime = stmp.Unix()
359
+//		etime = stime + 86399
360
+//	}
361
+//	var list []*models.PharmacyContent
362
+//	list, err = service.GetPatientMedication(orgid, patient_id, stime, etime, is_medicine)
363
+//
364
+//	baseList, _ := service.GetAllBaseDrugListTwo(orgid)
365
+//
366
+//	patients, _ := service.GetPatientByIDOne(orgid, patient_id)
367
+//	order, _ := service.GetMobiledialysiOrder(orgid, patient_id, stime)
368
+//	numberList, _ := service.GetAllBedNumberList(orgid)
369
+//	zoneList, _ := service.GetAllZoneByList(orgid)
370
+//
371
+//	appId := this.GetAdminUserInfo().CurrentAppId
372
+//	adminUserES, _ := service.GetAllAdminUserES(orgid, appId)
373
+//	allDoctor, _ := service.GetAllDoctor(orgid, appId)
374
+//
375
+//	prescriptionListByToDay, _ := service.GetPrescriptionListByToDay(orgid, patient_id, stime)
376
+//
377
+//	diagnose, _ := service.FindAllDiagnose(orgid)
378
+//
379
+//	config, _ := service.GetDrugCodeConfig(orgid)
380
+//	if err != nil {
381
+//		utils.ErrorLog(err.Error())
382
+//		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
383
+//		return
384
+//	}
385
+//	return_value := make(map[string]interface{})
386
+//	return_value["list"] = list
387
+//	return_value["baseList"] = baseList
388
+//	return_value["patients"] = patients
389
+//	return_value["order"] = order
390
+//	return_value["numberList"] = numberList
391
+//	return_value["zoneList"] = zoneList
392
+//	return_value["adminUserES"] = adminUserES
393
+//	return_value["doctors"] = allDoctor
394
+//	return_value["prescription"] = prescriptionListByToDay
395
+//	return_value["diagnose"] = diagnose
396
+//	return_value["config"] = config
397
+//	//if is_medicine == 1{发药时间先不展示
398
+//	//	return_value["time"] = time
399
+//	//}
400
+//	this.ServeSuccessJSON(return_value)
401
+//	return
402
+//
403
+//}
404
+
415 405
 // 发药按钮点击
416 406
 func (this *PharmacyController) DispensingMedicine() {
417 407
 
@@ -502,6 +492,9 @@ func (this *PharmacyController) DispensingMedicine() {
502 492
 	if orgid != 10480 && orgid != 10188 && orgid != 10217 && orgid != 10164 && orgid != 10666 {
503 493
 		//发药
504 494
 		err = service.DispensingMedicine(orgid, patient_id, stime, etime, creater)
495
+
496
+		err = service.DispensingGoods(orgid, patient_id, stime, etime, creater)
497
+
505 498
 		if err != nil {
506 499
 			utils.ErrorLog(err.Error())
507 500
 			this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
@@ -518,6 +511,7 @@ func (this *PharmacyController) DispensingMedicine() {
518 511
 		//发药逻辑
519 512
 
520 513
 		service.DispensingMedicineOne(orgid, patient_id, stime, etime, creater)
514
+		err = service.DispensingGoods(orgid, patient_id, stime, etime, creater)
521 515
 
522 516
 		//针对桑植盛康
523 517
 		if orgid == 10387 || orgid == 3877 {
@@ -577,14 +571,13 @@ func (this *PharmacyController) DrugWithdrawal() {
577 571
 		etime = stime + 86399
578 572
 	}
579 573
 	err = service.DrugWithdrawal(orgid, patient_id, stime, etime, creater)
580
-
574
+	err = service.DrugWithdrawalForGood(orgid, patient_id, stime, etime, creater)
581 575
 	prescriptionList, _ := service.GetHisPrescriptionByStartTime(orgid, patient_id, stime, etime)
582 576
 	if len(prescriptionList) > 0 {
583 577
 		for _, item := range prescriptionList {
584 578
 			service.ModiftyPrescpiton(item.ID)
585 579
 		}
586 580
 	}
587
-
588 581
 	if err != nil {
589 582
 		utils.ErrorLog(err.Error())
590 583
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
@@ -1423,16 +1416,23 @@ func (this *PharmacyController) ChangeDrugCode() {
1423 1416
 	orgId := this.GetAdminUserInfo().CurrentOrgId
1424 1417
 	data_source, _ := this.GetInt64("data_source")
1425 1418
 	drug_code := this.GetString("drug_code")
1419
+	//item_type := this.GetString("type")
1420
+
1426 1421
 	str := strings.Replace(drug_code, " ", "", -1)
1427 1422
 	// 去除换行符
1428 1423
 	str = strings.Replace(str, "\n", "", -1)
1429 1424
 	if data_source == 1 {
1430 1425
 		service.ChangeHisDrugCode(id, str, orgId)
1426
+
1431 1427
 	}
1432 1428
 	if data_source == 2 {
1433 1429
 		service.ChangeAdivceDrugCode(id, str, orgId)
1434 1430
 	}
1435 1431
 
1432
+	if data_source == 3 {
1433
+		service.ChangeHisProjectCode(id, str, orgId)
1434
+	}
1435
+
1436 1436
 	this.ServeSuccessJSON(map[string]interface{}{
1437 1437
 		"msg": "msg",
1438 1438
 	})

+ 13 - 11
models/good_models.go Ver arquivo

@@ -35,17 +35,19 @@ func (NewGoodsType) TableName() string {
35 35
 }
36 36
 
37 37
 type GoodInfo struct {
38
-	ID                          int64                `gorm:"column:id" json:"id" form:"id"`
39
-	GoodCode                    string               `gorm:"column:good_code" json:"good_code" form:"good_code"`
40
-	SpecificationName           string               `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
41
-	GoodTypeId                  int64                `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
42
-	GoodUnit                    int64                `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
43
-	BuyPrice                    float64              `gorm:"column:buy_price" json:"buy_price" form:"buy_price"`
44
-	SellPrice                   float64              `gorm:"column:sell_price" json:"sell_price" form:"sell_price"`
45
-	Remark                      string               `gorm:"column:remark" json:"remark" form:"remark"`
46
-	Ctime                       int64                `gorm:"column:ctime" json:"ctime" form:"ctime"`
47
-	Mtime                       int64                `gorm:"column:mtime" json:"mtime" form:"mtime"`
48
-	Manufacturer                int64                `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
38
+	ID                int64        `gorm:"column:id" json:"id" form:"id"`
39
+	GoodCode          string       `gorm:"column:good_code" json:"good_code" form:"good_code"`
40
+	SpecificationName string       `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
41
+	GoodTypeId        int64        `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
42
+	GoodUnit          int64        `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
43
+	BuyPrice          float64      `gorm:"column:buy_price" json:"buy_price" form:"buy_price"`
44
+	SellPrice         float64      `gorm:"column:sell_price" json:"sell_price" form:"sell_price"`
45
+	Remark            string       `gorm:"column:remark" json:"remark" form:"remark"`
46
+	Ctime             int64        `gorm:"column:ctime" json:"ctime" form:"ctime"`
47
+	Mtime             int64        `gorm:"column:mtime" json:"mtime" form:"mtime"`
48
+	Manufacturer      int64        `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
49
+	Manufacturers     Manufacturer `gorm:"ForeignKey:ID;AssociationForeignKey:Manufacturer" json:"Manufacturer"`
50
+
49 51
 	Dealer                      int64                `gorm:"column:dealer" json:"dealer" form:"dealer"`
50 52
 	ExpiryDateWarnDayCount      int64                `gorm:"column:expiry_date_warn_day_count" json:"expiry_date_warn_day_count" form:"expiry_date_warn_day_count"`
51 53
 	StockWarnCount              int64                `gorm:"column:stock_warn_count" json:"stock_warn_count" form:"stock_warn_count"`

+ 203 - 143
models/his_models.go Ver arquivo

@@ -290,82 +290,83 @@ func (HisDoctorAdviceInfo) TableName() string {
290 290
 }
291 291
 
292 292
 type Drug struct {
293
-	ID                          int64   `gorm:"column:id" json:"id" form:"id"`
294
-	DrugName                    string  `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
295
-	Pinyin                      string  `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
296
-	Wubi                        string  `gorm:"column:wubi" json:"wubi" form:"wubi"`
297
-	DrugAlias                   string  `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
298
-	DrugAliasPinyin             string  `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
299
-	DrugAliasWubi               string  `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
300
-	DrugCategory                int64   `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
301
-	DrugSpec                    string  `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
302
-	DrugType                    int64   `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
303
-	DrugStockLimit              string  `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
304
-	DrugOriginPlace             string  `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
305
-	DrugDosageForm              int64   `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
306
-	MedicalInsuranceLevel       int64   `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
307
-	MaxUnit                     string  `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
308
-	MinNumber                   int64   `gorm:"column:min_number" json:"min_number" form:"min_number"`
309
-	MinUnit                     string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
310
-	Dose                        string  `gorm:"column:dose" json:"dose" form:"dose"`
311
-	DoseUnit                    string  `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
312
-	UnitMatrixing               string  `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
313
-	RetailPrice                 float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
314
-	MinPrice                    float64 `gorm:"column:min_price" json:"min_price" form:"min_price"`
315
-	LastPrice                   float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
316
-	DrugControl                 int64   `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
317
-	Number                      string  `gorm:"column:number" json:"number" form:"number"`
318
-	DrugClassify                string  `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
319
-	DrugDose                    float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
320
-	DrugDoseUnit                int64   `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
321
-	MedicalInsuranceNumber      string  `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
322
-	ProvincesCode               string  `gorm:"column:provinces_code" json:"provinces_code" form:"provinces_code"`
323
-	Manufacturer                int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
324
-	PharmacologyCategory        int64   `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
325
-	StatisticsCategory          int64   `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
326
-	Code                        string  `gorm:"column:code" json:"code" form:"code"`
327
-	IsSpecialDiseases           int64   `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
328
-	IsRecord                    int64   `gorm:"column:is_record" json:"is_record" form:"is_record"`
329
-	Agent                       string  `gorm:"column:agent" json:"agent" form:"agent"`
330
-	DrugStatus                  string  `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
331
-	LimitRemark                 string  `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
332
-	DeliveryWay                 string  `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
333
-	ExecutionFrequency          string  `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
334
-	SingleDose                  float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
335
-	PrescribingNumber           float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
336
-	Label                       int64   `gorm:"column:label" json:"label" form:"label"`
337
-	Sort                        int64   `gorm:"column:sort" json:"sort" form:"sort"`
338
-	IsUseDoctorAdvice           int64   `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
339
-	IsDefault                   int64   `gorm:"column:is_default" json:"is_default" form:"is_default"`
340
-	IsChargePredict             int64   `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
341
-	IsStatisticsWork            int64   `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
342
-	IsChargeUse                 int64   `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
343
-	Status                      int64   `gorm:"column:status" json:"status" form:"status"`
344
-	Ctime                       int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
345
-	Mtime                       int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
346
-	OrgId                       int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
347
-	DrugCode                    string  `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
348
-	Dealer                      int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
349
-	PrescriptionMark            int64   `gorm:"column:prescription_mark" json:"prescription_mark" form:"prescription_mark"`
350
-	RecordDate                  int64   `gorm:"column:record_date" json:"record_date" form:"record_date"`
351
-	DrugRemark                  string  `gorm:"column:drug_remark" json:"drug_remark" form:"drug_remark"`
352
-	SocialSecurityDirectoryCode string  `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
353
-	DoseCode                    string  `gorm:"column:dose_code" json:"dose_code" form:"dose_code"`
354
-	IsMark                      int64   `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
355
-	HospApprFlag                int64   `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
356
-	LmtUsedFlag                 int64   `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
357
-	Dosage                      string  `gorm:"column:dosage" json:"dosage" form:"dosage"`
358
-	Unval                       string  `gorm:"column:unval" json:"unval" form:"unval"`
359
-	PackingUnit                 string  `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
360
-	PackingPrice                float64 `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
361
-	DrugDay                     string  `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
362
-	Total                       float64 `gorm:"column:total" json:"total" form:"total"`
363
-	PrescribingNumberUnit       string  `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
364
-	IsUser                      int64   `gorm:"column:is_user" json:"is_user" form:"is_user"`
365
-	Bck01b                      string  `gorm:"column:bck01b" json:"bck01b" form:"bck01b"`
366
-	Bby01                       string  `gorm:"column:bby01" json:"bby01" form:"bby01"`
367
-	Bbx01                       string  `gorm:"column:bbx01" json:"bbx01" form:"bbx01"`
368
-	IsZeroFlag                  int64   `gorm:"column:is_zero_flag" json:"is_zero_flag" form:"is_zero_flag"`
293
+	ID                          int64        `gorm:"column:id" json:"id" form:"id"`
294
+	DrugName                    string       `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
295
+	Pinyin                      string       `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
296
+	Wubi                        string       `gorm:"column:wubi" json:"wubi" form:"wubi"`
297
+	DrugAlias                   string       `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
298
+	DrugAliasPinyin             string       `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
299
+	DrugAliasWubi               string       `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
300
+	DrugCategory                int64        `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
301
+	DrugSpec                    string       `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
302
+	DrugType                    int64        `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
303
+	DrugStockLimit              string       `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
304
+	DrugOriginPlace             string       `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
305
+	DrugDosageForm              int64        `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
306
+	MedicalInsuranceLevel       int64        `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
307
+	MaxUnit                     string       `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
308
+	MinNumber                   int64        `gorm:"column:min_number" json:"min_number" form:"min_number"`
309
+	MinUnit                     string       `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
310
+	Dose                        string       `gorm:"column:dose" json:"dose" form:"dose"`
311
+	DoseUnit                    string       `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
312
+	UnitMatrixing               string       `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
313
+	RetailPrice                 float64      `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
314
+	MinPrice                    float64      `gorm:"column:min_price" json:"min_price" form:"min_price"`
315
+	LastPrice                   float64      `gorm:"column:last_price" json:"last_price" form:"last_price"`
316
+	DrugControl                 int64        `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
317
+	Number                      string       `gorm:"column:number" json:"number" form:"number"`
318
+	DrugClassify                string       `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
319
+	DrugDose                    float64      `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
320
+	DrugDoseUnit                int64        `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
321
+	MedicalInsuranceNumber      string       `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
322
+	ProvincesCode               string       `gorm:"column:provinces_code" json:"provinces_code" form:"provinces_code"`
323
+	Manufacturer                int64        `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
324
+	Manufacturers               Manufacturer `gorm:"ForeignKey:ID;AssociationForeignKey:Manufacturer" json:"Manufacturer"`
325
+	PharmacologyCategory        int64        `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
326
+	StatisticsCategory          int64        `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
327
+	Code                        string       `gorm:"column:code" json:"code" form:"code"`
328
+	IsSpecialDiseases           int64        `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
329
+	IsRecord                    int64        `gorm:"column:is_record" json:"is_record" form:"is_record"`
330
+	Agent                       string       `gorm:"column:agent" json:"agent" form:"agent"`
331
+	DrugStatus                  string       `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
332
+	LimitRemark                 string       `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
333
+	DeliveryWay                 string       `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
334
+	ExecutionFrequency          string       `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
335
+	SingleDose                  float64      `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
336
+	PrescribingNumber           float64      `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
337
+	Label                       int64        `gorm:"column:label" json:"label" form:"label"`
338
+	Sort                        int64        `gorm:"column:sort" json:"sort" form:"sort"`
339
+	IsUseDoctorAdvice           int64        `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
340
+	IsDefault                   int64        `gorm:"column:is_default" json:"is_default" form:"is_default"`
341
+	IsChargePredict             int64        `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
342
+	IsStatisticsWork            int64        `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
343
+	IsChargeUse                 int64        `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
344
+	Status                      int64        `gorm:"column:status" json:"status" form:"status"`
345
+	Ctime                       int64        `gorm:"column:ctime" json:"ctime" form:"ctime"`
346
+	Mtime                       int64        `gorm:"column:mtime" json:"mtime" form:"mtime"`
347
+	OrgId                       int64        `gorm:"column:org_id" json:"org_id" form:"org_id"`
348
+	DrugCode                    string       `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
349
+	Dealer                      int64        `gorm:"column:dealer" json:"dealer" form:"dealer"`
350
+	PrescriptionMark            int64        `gorm:"column:prescription_mark" json:"prescription_mark" form:"prescription_mark"`
351
+	RecordDate                  int64        `gorm:"column:record_date" json:"record_date" form:"record_date"`
352
+	DrugRemark                  string       `gorm:"column:drug_remark" json:"drug_remark" form:"drug_remark"`
353
+	SocialSecurityDirectoryCode string       `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
354
+	DoseCode                    string       `gorm:"column:dose_code" json:"dose_code" form:"dose_code"`
355
+	IsMark                      int64        `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
356
+	HospApprFlag                int64        `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
357
+	LmtUsedFlag                 int64        `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
358
+	Dosage                      string       `gorm:"column:dosage" json:"dosage" form:"dosage"`
359
+	Unval                       string       `gorm:"column:unval" json:"unval" form:"unval"`
360
+	PackingUnit                 string       `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
361
+	PackingPrice                float64      `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
362
+	DrugDay                     string       `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
363
+	Total                       float64      `gorm:"column:total" json:"total" form:"total"`
364
+	PrescribingNumberUnit       string       `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
365
+	IsUser                      int64        `gorm:"column:is_user" json:"is_user" form:"is_user"`
366
+	Bck01b                      string       `gorm:"column:bck01b" json:"bck01b" form:"bck01b"`
367
+	Bby01                       string       `gorm:"column:bby01" json:"bby01" form:"bby01"`
368
+	Bbx01                       string       `gorm:"column:bbx01" json:"bbx01" form:"bbx01"`
369
+	IsZeroFlag                  int64        `gorm:"column:is_zero_flag" json:"is_zero_flag" form:"is_zero_flag"`
369 370
 }
370 371
 
371 372
 func (Drug) TableName() string {
@@ -545,6 +546,8 @@ type TempHisOrder struct {
545 546
 	IsUploadOrderInfo int64  `gorm:"column:is_upload_order_info" json:"is_upload_order_info" form:"is_upload_order_info"`
546 547
 	IsUploadSuccess   int64  `gorm:"column:is_upload_success" json:"is_upload_success" form:"is_upload_success"`
547 548
 	CardDesc          string `gorm:"card_desc" json:"card_desc" form:"card_desc"`
549
+	PackNum           int64  `gorm:"column:pack_num" json:"pack_num" form:"pack_num"`
550
+	GoodPackNum       int64  `gorm:"column:good_pack_num" json:"good_pack_num" form:"good_pack_num"`
548 551
 }
549 552
 
550 553
 func (TempHisOrder) TableName() string {
@@ -907,6 +910,10 @@ type HisPrescriptionProject struct {
907 910
 	ExecutionFrequencyId int64        `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
908 911
 	IsOut                int64        `gorm:"column:is_out" json:"is_out" form:"is_out"` //新增字段
909 912
 	YbSyncStatus         int64        `gorm:"column:yb_sync_status" json:"yb_sync_status" form:"yb_sync_status"`
913
+
914
+	DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
915
+
916
+	DispensingTime int64 `gorm:"column:dispensing_time" json:"dispensing_time" form:"dispensing_time"`
910 917
 }
911 918
 
912 919
 func (HisPrescriptionProject) TableName() string {
@@ -1112,6 +1119,8 @@ type HisOrder struct {
1112 1119
 	IsUploadSuccess         int64                   `gorm:"column:is_upload_success" json:"is_upload_success" form:"is_upload_success"`
1113 1120
 	SickName                string                  `gorm:"column:sick_name" json:"sick_name" form:"sick_name"`
1114 1121
 	CardDesc                string                  `gorm:"card_desc" json:"card_desc" form:"card_desc"`
1122
+	PackNum                 int64                   `gorm:"column:pack_num" json:"pack_num" form:"pack_num"`
1123
+	GoodPackNum             int64                   `gorm:"column:good_pack_num" json:"good_pack_num" form:"good_pack_num"`
1115 1124
 }
1116 1125
 
1117 1126
 func (HisOrder) TableName() string {
@@ -1176,7 +1185,9 @@ type HisOrderELE struct {
1176 1185
 	IsMedicineInsurance int64     `gorm:"column:is_medicine_insurance" json:"is_medicine_insurance" form:"is_medicine_insurance"`
1177 1186
 	PayWay              int64     `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
1178 1187
 
1179
-	Patients Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
1188
+	Patients    Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
1189
+	PackNum     int64    `gorm:"column:pack_num" json:"pack_num" form:"pack_num"`
1190
+	GoodPackNum int64    `gorm:"column:good_pack_num" json:"good_pack_num" form:"good_pack_num"`
1180 1191
 }
1181 1192
 
1182 1193
 func (HisOrderELE) TableName() string {
@@ -2996,78 +3007,127 @@ type HisOrder10726Summary struct {
2996 3007
 }
2997 3008
 
2998 3009
 type NewHisDoctorAdviceInfo struct {
2999
-	ID                    int64              `gorm:"column:id" json:"id" form:"id"`
3000
-	UserOrgId             int64              `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
3001
-	PatientId             int64              `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
3002
-	HisPatientId          int64              `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
3003
-	AdviceType            int64              `gorm:"column:advice_type" json:"advice_type" form:"advice_type"`
3004
-	AdviceDate            int64              `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
3005
-	StartTime             int64              `gorm:"column:start_time" json:"start_time" form:"start_time"`
3006
-	AdviceName            string             `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
3007
-	AdviceDesc            string             `gorm:"column:advice_desc" json:"advice_desc" form:"advice_desc"`
3008
-	ReminderDate          int64              `gorm:"column:reminder_date" json:"reminder_date" form:"reminder_date"`
3009
-	SingleDose            float64            `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
3010
-	SingleDoseUnit        string             `gorm:"column:single_dose_unit" json:"single_dose_unit" form:"single_dose_unit"`
3011
-	PrescribingNumber     float64            `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
3012
-	PrescribingNumberUnit string             `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
3013
-	DeliveryWay           string             `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
3014
-	ExecutionFrequency    string             `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
3015
-	AdviceDoctor          int64              `gorm:"column:advice_doctor" json:"advice_doctor" form:"advice_doctor"`
3016
-	Status                int64              `gorm:"column:status" json:"status" form:"status"`
3017
-	CreatedTime           int64              `gorm:"column:created_time" json:"created_time" form:"created_time"`
3018
-	UpdatedTime           int64              `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
3019
-	AdviceAffirm          string             `gorm:"column:advice_affirm" json:"advice_affirm" form:"advice_affirm"`
3020
-	Remark                string             `gorm:"column:remark" json:"remark" form:"remark"`
3021
-	StopTime              int64              `gorm:"column:stop_time" json:"stop_time" form:"stop_time"`
3022
-	StopReason            string             `gorm:"column:stop_reason" json:"stop_reason" form:"stop_reason"`
3023
-	StopDoctor            int64              `gorm:"column:stop_doctor" json:"stop_doctor" form:"stop_doctor"`
3024
-	StopState             int64              `gorm:"column:stop_state" json:"stop_state" form:"stop_state"`
3025
-	ParentId              int64              `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
3026
-	ExecutionTime         int64              `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
3027
-	ExecutionStaff        int64              `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
3028
-	ExecutionState        int64              `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
3029
-	Checker               int64              `gorm:"column:checker" json:"checker" form:"checker"`
3030
-	RecordDate            int64              `gorm:"column:record_date" json:"record_date" form:"record_date"`
3031
-	DialysisOrderId       int64              `gorm:"column:dialysis_order_id" json:"dialysis_order_id" form:"dialysis_order_id"`
3032
-	CheckTime             int64              `gorm:"column:check_time" json:"check_time" form:"check_time"`
3033
-	CheckState            int64              `gorm:"column:check_state" json:"check_state" form:"check_state"`
3034
-	DrugSpec              float64            `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
3035
-	DrugSpecUnit          string             `gorm:"column:drug_spec_unit" json:"drug_spec_unit" form:"drug_spec_unit"`
3036
-	Groupno               int64              `gorm:"column:groupno" json:"groupno" form:"groupno"`
3037
-	RemindType            int64              `gorm:"column:remind_type" json:"remind_type" form:"remind_type"`
3038
-	FrequencyType         int64              `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
3039
-	DayCount              int64              `gorm:"column:day_count" json:"day_count" form:"day_count"`
3040
-	WeekDay               string             `gorm:"column:week_day" json:"week_day" form:"week_day"`
3041
-	TemplateId            string             `gorm:"column:template_id" json:"template_id" form:"template_id"`
3042
-	Modifier              int64              `gorm:"column:modifier" json:"modifier" form:"modifier"`
3043
-	DrugId                int64              `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
3044
-	Price                 float64            `gorm:"column:price" json:"price" form:"price"`
3045
-	PrescriptionId        int64              `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
3046
-	MedListCodg           string             `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
3047
-	FeedetlSn             string             `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
3048
-	Day                   int64              `gorm:"column:day" json:"day" form:"day"`
3049
-	Drug                  Drug               `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" json:"drug"`
3050
-	Diagnosis             int64              `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
3051
-	Way                   int64              `gorm:"column:way" json:"way" form:"way"`
3052
-	HospApprFlag          int64              `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
3053
-	LmtUsedFlag           int64              `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
3054
-	IsMedicine            int64              `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
3055
-	ExecutionFrequencyId  int64              `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
3056
-	IsSettle              int64              `gorm:"column:is_settle" json:"is_settle" form:"is_settle"`
3057
-	IsMobile              int64              `gorm:"column:is_mobile" json:"is_mobile" form:"is_mobile"`
3058
-	IsSelfDrug            int64              `gorm:"column:is_self_drug" json:"is_self_drug" form:"is_self_drug"`
3059
-	DrugWayCount          string             `gorm:"column:drug_way_count" json:"drug_way_count" form:"drug_way_count"`
3060
-	YbSyncStatus          int64              `gorm:"column:yb_sync_status" json:"yb_sync_status" form:"yb_sync_status"`
3061
-	DrugCode              string             `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
3062
-	IsUpload              int64              `gorm:"column:is_upload" json:"is_upload" form:"is_upload"`
3063
-	ZeroFlag              int64              `gorm:"column:zero_flag" json:"zero_flag" form:"zero_flag"`
3064
-	NewHisPrescription    NewHisPrescription `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"pre"`
3010
+	ID                    int64   `gorm:"column:id" json:"id" form:"id"`
3011
+	UserOrgId             int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
3012
+	PatientId             int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
3013
+	HisPatientId          int64   `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
3014
+	AdviceType            int64   `gorm:"column:advice_type" json:"advice_type" form:"advice_type"`
3015
+	AdviceDate            int64   `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
3016
+	StartTime             int64   `gorm:"column:start_time" json:"start_time" form:"start_time"`
3017
+	AdviceName            string  `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
3018
+	AdviceDesc            string  `gorm:"column:advice_desc" json:"advice_desc" form:"advice_desc"`
3019
+	ReminderDate          int64   `gorm:"column:reminder_date" json:"reminder_date" form:"reminder_date"`
3020
+	SingleDose            float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
3021
+	SingleDoseUnit        string  `gorm:"column:single_dose_unit" json:"single_dose_unit" form:"single_dose_unit"`
3022
+	PrescribingNumber     float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
3023
+	PrescribingNumberUnit string  `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
3024
+	DeliveryWay           string  `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
3025
+	ExecutionFrequency    string  `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
3026
+	AdviceDoctor          int64   `gorm:"column:advice_doctor" json:"advice_doctor" form:"advice_doctor"`
3027
+	Status                int64   `gorm:"column:status" json:"status" form:"status"`
3028
+	CreatedTime           int64   `gorm:"column:created_time" json:"created_time" form:"created_time"`
3029
+	UpdatedTime           int64   `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
3030
+	AdviceAffirm          string  `gorm:"column:advice_affirm" json:"advice_affirm" form:"advice_affirm"`
3031
+	Remark                string  `gorm:"column:remark" json:"remark" form:"remark"`
3032
+	StopTime              int64   `gorm:"column:stop_time" json:"stop_time" form:"stop_time"`
3033
+	StopReason            string  `gorm:"column:stop_reason" json:"stop_reason" form:"stop_reason"`
3034
+	StopDoctor            int64   `gorm:"column:stop_doctor" json:"stop_doctor" form:"stop_doctor"`
3035
+	StopState             int64   `gorm:"column:stop_state" json:"stop_state" form:"stop_state"`
3036
+	ParentId              int64   `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
3037
+	ExecutionTime         int64   `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
3038
+	ExecutionStaff        int64   `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
3039
+	ExecutionState        int64   `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
3040
+	Checker               int64   `gorm:"column:checker" json:"checker" form:"checker"`
3041
+	RecordDate            int64   `gorm:"column:record_date" json:"record_date" form:"record_date"`
3042
+	DialysisOrderId       int64   `gorm:"column:dialysis_order_id" json:"dialysis_order_id" form:"dialysis_order_id"`
3043
+	CheckTime             int64   `gorm:"column:check_time" json:"check_time" form:"check_time"`
3044
+	CheckState            int64   `gorm:"column:check_state" json:"check_state" form:"check_state"`
3045
+	DrugSpec              float64 `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
3046
+	DrugSpecUnit          string  `gorm:"column:drug_spec_unit" json:"drug_spec_unit" form:"drug_spec_unit"`
3047
+	Groupno               int64   `gorm:"column:groupno" json:"groupno" form:"groupno"`
3048
+	RemindType            int64   `gorm:"column:remind_type" json:"remind_type" form:"remind_type"`
3049
+	FrequencyType         int64   `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
3050
+	DayCount              int64   `gorm:"column:day_count" json:"day_count" form:"day_count"`
3051
+	WeekDay               string  `gorm:"column:week_day" json:"week_day" form:"week_day"`
3052
+	TemplateId            string  `gorm:"column:template_id" json:"template_id" form:"template_id"`
3053
+	Modifier              int64   `gorm:"column:modifier" json:"modifier" form:"modifier"`
3054
+	DrugId                int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
3055
+	Price                 float64 `gorm:"column:price" json:"price" form:"price"`
3056
+	PrescriptionId        int64   `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
3057
+	MedListCodg           string  `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
3058
+	FeedetlSn             string  `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
3059
+	Day                   int64   `gorm:"column:day" json:"day" form:"day"`
3060
+	Drug                  Drug    `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" json:"drug"`
3061
+	Diagnosis             int64   `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
3062
+	Way                   int64   `gorm:"column:way" json:"way" form:"way"`
3063
+	HospApprFlag          int64   `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
3064
+	LmtUsedFlag           int64   `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
3065
+	IsMedicine            int64   `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
3066
+	ExecutionFrequencyId  int64   `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
3067
+	IsSettle              int64   `gorm:"column:is_settle" json:"is_settle" form:"is_settle"`
3068
+	IsMobile              int64   `gorm:"column:is_mobile" json:"is_mobile" form:"is_mobile"`
3069
+	IsSelfDrug            int64   `gorm:"column:is_self_drug" json:"is_self_drug" form:"is_self_drug"`
3070
+	DrugWayCount          string  `gorm:"column:drug_way_count" json:"drug_way_count" form:"drug_way_count"`
3071
+	YbSyncStatus          int64   `gorm:"column:yb_sync_status" json:"yb_sync_status" form:"yb_sync_status"`
3072
+	DrugCode              string  `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
3073
+	IsUpload              int64   `gorm:"column:is_upload" json:"is_upload" form:"is_upload"`
3074
+
3075
+	ZeroFlag           int64              `gorm:"column:zero_flag" json:"zero_flag" form:"zero_flag"`
3076
+	NewHisPrescription NewHisPrescription `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"pre"`
3065 3077
 }
3066 3078
 
3067 3079
 func (NewHisDoctorAdviceInfo) TableName() string {
3068 3080
 	return "his_doctor_advice_info"
3069 3081
 }
3070 3082
 
3083
+type NewHisPrintPrescriptionProject struct {
3084
+	ID                   int64              `gorm:"column:id" json:"id" form:"id"`
3085
+	ProjectId            int64              `gorm:"column:project_id" json:"project_id" form:"project_id"`
3086
+	Price                float64            `gorm:"column:price" json:"price" form:"price"`
3087
+	UserOrgId            int64              `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
3088
+	Status               int64              `gorm:"column:status" json:"status" form:"status"`
3089
+	Ctime                int64              `gorm:"column:ctime" json:"ctime" form:"ctime"`
3090
+	Mtime                int64              `gorm:"column:mtime" json:"mtime" form:"mtime"`
3091
+	PatientId            int64              `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
3092
+	HisPatientId         int64              `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
3093
+	RecordDate           int64              `gorm:"column:record_date" json:"record_date" form:"record_date"`
3094
+	PrescriptionId       int64              `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
3095
+	Count                string             `gorm:"column:count" json:"count" form:"count"`
3096
+	FeedetlSn            string             `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
3097
+	MedListCodg          string             `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
3098
+	SingleDose           string             `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
3099
+	DeliveryWay          string             `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
3100
+	ExecutionFrequency   string             `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
3101
+	Day                  string             `gorm:"column:day" json:"day" form:"day"`
3102
+	HisProject           HisProject         `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"project"`
3103
+	GoodInfo             GoodInfo           `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"good_info"`
3104
+	Remark               string             `gorm:"column:remark" json:"remark" form:"remark"`
3105
+	Unit                 string             `gorm:"column:unit" json:"unit" form:"unit"`
3106
+	Type                 int64              `gorm:"column:type" json:"type" form:"type"`
3107
+	Doctor               int64              `gorm:"column:doctor" json:"doctor" form:"doctor"`
3108
+	ExecutionTime        int64              `gborm:"column:execution_time" json:"execution_time" form:"execution_time"`
3109
+	ExecutionStaff       int64              `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
3110
+	ExecutionState       int64              `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
3111
+	CheckTime            int64              `gorm:"column:check_time" json:"check_time" form:"check_time"`
3112
+	CheckState           int64              `gorm:"column:check_state" json:"check_state" form:"check_state"`
3113
+	Checker              int64              `gorm:"column:checker" json:"checker" form:"checker"`
3114
+	StartTime            int64              `gorm:"column:start_time" json:"start_time" form:"start_time"`
3115
+	TeamId               int64              `gorm:"column:team_id" json:"team_id" form:"team_id"`
3116
+	FrequencyType        int64              `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
3117
+	DayCount             int64              `gorm:"column:day_count" json:"day_count" form:"day_count"`
3118
+	WeekDay              string             `gorm:"column:week_day" json:"week_day" form:"week_day"`
3119
+	IsCheckTeam          int64              `gorm:"-" json:"is_check_team" form:"is_check_team"`
3120
+	ExecutionFrequencyId int64              `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
3121
+	IsUpload             int64              `gorm:"column:is_upload" json:"is_upload" form:"is_upload"`
3122
+	NewHisPrescription   NewHisPrescription `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"pre"`
3123
+	DrugCode             string             `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
3124
+	IsMedicine           int64              `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
3125
+}
3126
+
3127
+func (NewHisPrintPrescriptionProject) TableName() string {
3128
+	return "his_prescription_project"
3129
+}
3130
+
3071 3131
 type NewHisPrescription struct {
3072 3132
 	ID                 int64  `gorm:"column:id" json:"id" form:"id"`
3073 3133
 	UserOrgId          int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`

+ 51 - 0
models/pharmacy_models.go Ver arquivo

@@ -63,6 +63,10 @@ type PharmacyContent struct {
63 63
 	Price          float64
64 64
 	DrugCode       string
65 65
 	ZeroFlag       string
66
+	MName          string
67
+	Spec           string
68
+	Type           int64
69
+	Bm             string
66 70
 }
67 71
 
68 72
 // 发药明细列表
@@ -211,12 +215,59 @@ type HisDoctorAdviceInfoL struct {
211 215
 	DispensingTime        int64   `gorm:"column:dispensing_time" json:"dispensing_time" form:"dispensing_time"`
212 216
 	DrugCode              string  `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
213 217
 	ZeroFlag              int64   `gorm:"column:zero_flag" json:"zero_flag" form:"zero_flag"`
218
+	Drug                  Drug    `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" json:"drug"`
214 219
 }
215 220
 
216 221
 func (HisDoctorAdviceInfoL) TableName() string {
217 222
 	return "sgj_xt.his_doctor_advice_info"
218 223
 }
219 224
 
225
+type HisPrintPrescriptionProjectL struct {
226
+	ID                   int64    `gorm:"column:id" json:"id" form:"id"`
227
+	ProjectId            int64    `gorm:"column:project_id" json:"project_id" form:"project_id"`
228
+	Price                float64  `gorm:"column:price" json:"price" form:"price"`
229
+	UserOrgId            int64    `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
230
+	Status               int64    `gorm:"column:status" json:"status" form:"status"`
231
+	Ctime                int64    `gorm:"column:ctime" json:"ctime" form:"ctime"`
232
+	Mtime                int64    `gorm:"column:mtime" json:"mtime" form:"mtime"`
233
+	PatientId            int64    `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
234
+	HisPatientId         int64    `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
235
+	RecordDate           int64    `gorm:"column:record_date" json:"record_date" form:"record_date"`
236
+	PrescriptionId       int64    `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
237
+	Count                string   `gorm:"column:count" json:"count" form:"count"`
238
+	FeedetlSn            string   `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
239
+	MedListCodg          string   `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
240
+	SingleDose           string   `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
241
+	DeliveryWay          string   `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
242
+	ExecutionFrequency   string   `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
243
+	Day                  string   `gorm:"column:day" json:"day" form:"day"`
244
+	GoodInfo             GoodInfo `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"good_info"`
245
+	Remark               string   `gorm:"column:remark" json:"remark" form:"remark"`
246
+	Unit                 string   `gorm:"column:unit" json:"unit" form:"unit"`
247
+	Type                 int64    `gorm:"column:type" json:"type" form:"type"`
248
+	Doctor               int64    `gorm:"column:doctor" json:"doctor" form:"doctor"`
249
+	ExecutionTime        int64    `gborm:"column:execution_time" json:"execution_time" form:"execution_time"`
250
+	ExecutionStaff       int64    `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
251
+	ExecutionState       int64    `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
252
+	CheckTime            int64    `gorm:"column:check_time" json:"check_time" form:"check_time"`
253
+	CheckState           int64    `gorm:"column:check_state" json:"check_state" form:"check_state"`
254
+	Checker              int64    `gorm:"column:checker" json:"checker" form:"checker"`
255
+	StartTime            int64    `gorm:"column:start_time" json:"start_time" form:"start_time"`
256
+	TeamId               int64    `gorm:"column:team_id" json:"team_id" form:"team_id"`
257
+	FrequencyType        int64    `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
258
+	DayCount             int64    `gorm:"column:day_count" json:"day_count" form:"day_count"`
259
+	WeekDay              string   `gorm:"column:week_day" json:"week_day" form:"week_day"`
260
+	IsCheckTeam          int64    `gorm:"-" json:"is_check_team" form:"is_check_team"`
261
+	ExecutionFrequencyId int64    `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
262
+	DrugCode             string   `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
263
+	IsMedicine           int64    `gorm:"is_medicine" json:"is_medicine" form:"is_medicine"`
264
+	DispensingTime       int64    `gorm:"column:dispensing_time" json:"dispensing_time" form:"dispensing_time"`
265
+}
266
+
267
+func (HisPrintPrescriptionProjectL) TableName() string {
268
+	return "his_prescription_project"
269
+}
270
+
220 271
 type XtDoctorAdviceL struct {
221 272
 	ID                    int64   `gorm:"column:id" json:"id" form:"id"`
222 273
 	UserOrgId             int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`

+ 324 - 0
service/export_data_service.go Ver arquivo

@@ -2,7 +2,9 @@ package service
2 2
 
3 3
 import (
4 4
 	"XT_New/models"
5
+	"fmt"
5 6
 	"github.com/jinzhu/gorm"
7
+	"log"
6 8
 )
7 9
 
8 10
 type ExportPatient struct {
@@ -292,6 +294,39 @@ type MedicalCharges struct {
292 294
 	OtherPayment             float64 `gorm:"column:其它支付"`   // 其它支付
293 295
 }
294 296
 
297
+type MedicalChargesThree struct {
298
+	PatientID                string  `gorm:"column:ID"`   // 姓名
299
+	PsnName                  string  `gorm:"column:姓名"`   // 姓名
300
+	TypeName                 string  `gorm:"column:类型"`   // 姓名
301
+	Total                    float64 `gorm:"column:合计次数"` // 姓名
302
+	XtCount                  float64 `gorm:"column:血透"`
303
+	XlCount                  float64 `gorm:"column:血滤"`
304
+	GlCount                  float64 `gorm:"column:灌流"`
305
+	WesternMedicineFee       float64 `gorm:"column:西药费"`    // 西药费
306
+	ChinesePatentMedicineFee float64 `gorm:"column:中成药费"`   // 中成药费
307
+	HealthMaterialsFee       float64 `gorm:"column:耗材费"`    // 卫生材料费
308
+	RegistrationFee          float64 `gorm:"column:挂号费"`    // 挂号费
309
+	TreatmentFee             float64 `gorm:"column:治疗费"`    // 治疗费
310
+	ExaminationFee           float64 `gorm:"column:检查费"`    // 检查费
311
+	LaboratoryFee            float64 `gorm:"column:化验费"`    // 化验费
312
+	NursingFee               float64 `gorm:"column:护理费"`    // 护理费
313
+	OtherFee                 float64 `gorm:"column:其他费"`    // 其他费
314
+	BedsFee                  float64 `gorm:"column:床位费"`    // 床位费
315
+	ConsultationFee          float64 `gorm:"column:诊察费"`    // 诊察费
316
+	ChineseMedicineFee       float64 `gorm:"column:中药饮片费"`  // 中药饮片费
317
+	GeneralTreatmentFee      float64 `gorm:"column:一般诊疗费"`  // 一般诊疗费
318
+	TotalMedicalFee          float64 `gorm:"column:合计"`     // 医疗费总额
319
+	SelfPay                  float64 `gorm:"column:自费金额"`   // 个人自付金额
320
+	AcctPay                  float64 `gorm:"column:个人账户支付"` // 基本账户支付
321
+	Return                   string  `gorm:"column:退费"`     // 共济账户支付
322
+	YouHui                   string  `gorm:"column:优惠"`     // 公务员补助
323
+	YingShou                 float64 `gorm:"column:应收"`     // 统筹支付金额
324
+	GuaZhang                 string  `gorm:"column:挂账"`     // 医疗救助
325
+	ChongZhang               string  `gorm:"column:冲账"`     // 大病支付
326
+	ShiShou                  float64 `gorm:"column:实收"`     // 企业补充支付
327
+	YiShou                   float64 `gorm:"column:已收"`     // 重大疾病补充 (Empty in SQL, will be left blank in Go)
328
+}
329
+
295 330
 func GetHisOrderBy10697Summary(start_time string, end_time string, ins string) (results []MedicalCharges, err error) {
296 331
 	err = readDb.Table("his_order").
297 332
 		Select(`
@@ -394,6 +429,295 @@ func GetHisOrderBy10697SummaryTwo(startTime, endTime, ins string, st_stamp, end_
394 429
 	return results, nil
395 430
 }
396 431
 
432
+func GetHisOrderBy10697SummaryThree(startTime, endTime string, st_stamp, end_stamp int64, org_id int64) ([]*MedicalChargesThree, error) {
433
+	var results []*MedicalChargesThree
434
+	// 改为字符串数组
435
+	medChargeTypes := []string{"01", "02", "03", "04", "05", "07", "08", "09", "10", "11", "12", "13", "14"}
436
+
437
+	// 定义子查询
438
+	subQuery := readDb.Table("his_order_info").
439
+		Select(`
440
+            order_number, 
441
+            med_chrgitm_type, 
442
+            SUM(det_item_fee_sumamt) AS det_item_fee_sumamt`).
443
+		Where("user_org_id = ? AND STATUS = ? AND (upload_date) >= ? AND (upload_date) <= ? AND med_chrgitm_type IN (?)",
444
+			org_id, 1,
445
+			st_stamp,
446
+			end_stamp,
447
+			medChargeTypes).
448
+		Group("order_number, med_chrgitm_type").
449
+		SubQuery() // 作为临时表
450
+
451
+	// 执行主查询
452
+	err := readDb.Table("his_order").
453
+		Select(`p.id as ID, p.name AS 姓名,
454
+			CASE his_order.insutype
455
+				WHEN '390' THEN '城乡'
456
+				WHEN '310' THEN '职工'
457
+				ELSE '未知' 
458
+			END AS "类型",
459
+			SUM(CASE i.med_chrgitm_type WHEN '09' THEN i.det_item_fee_sumamt ELSE 0 END) AS 西药费,
460
+			0 AS 成药费,
461
+			SUM(CASE i.med_chrgitm_type WHEN '11' THEN i.det_item_fee_sumamt ELSE 0 END) AS 中成药费,
462
+			SUM(CASE i.med_chrgitm_type WHEN '08' THEN i.det_item_fee_sumamt ELSE 0 END) AS 耗材费,
463
+			SUM(CASE i.med_chrgitm_type WHEN '13' THEN i.det_item_fee_sumamt ELSE 0 END) AS 挂号费,
464
+			SUM(CASE i.med_chrgitm_type WHEN '05' THEN i.det_item_fee_sumamt ELSE 0 END) AS 治疗费,
465
+			SUM(CASE i.med_chrgitm_type WHEN '03' THEN i.det_item_fee_sumamt ELSE 0 END) AS 检查费,
466
+			SUM(CASE i.med_chrgitm_type WHEN '04' THEN i.det_item_fee_sumamt ELSE 0 END) AS 化验费,
467
+			SUM(CASE i.med_chrgitm_type WHEN '07' THEN i.det_item_fee_sumamt ELSE 0 END) AS 护理费,
468
+			SUM(CASE i.med_chrgitm_type WHEN '14' THEN i.det_item_fee_sumamt ELSE 0 END) AS 其他费,
469
+			0 AS 合计,  -- 移除不必要的DISTINCT
470
+			0 AS 自费金额,
471
+			0 AS 个人账户支付,
472
+			0 AS 医保报销金额,
473
+			"" AS 退费,
474
+			"" AS 优惠,
475
+			0 AS 应收,
476
+			"" AS 挂账,
477
+			"" AS 冲账,
478
+			0 AS 实收`).
479
+		Joins("JOIN (?) i ON his_order.number = i.order_number", subQuery).                       // 使用子查询
480
+		Joins("JOIN xt_patients p on p.id = his_order.patient_id and p.user_org_id = ?", org_id). // 使用子查询
481
+
482
+		Where("his_order.user_org_id = ? AND his_order.order_status = ? AND his_order.setl_time >= ? AND his_order.setl_time <= ?  AND his_order.STATUS = ?",
483
+			org_id, 2, startTime+" 00:00:00", endTime+" 23:59:59", 1).
484
+		Group("his_order.patient_id").
485
+		Scan(&results).Error
486
+
487
+	if err != nil {
488
+		return nil, err
489
+	}
490
+
491
+	type CusTotal struct {
492
+		MedfeeSumamt float64
493
+		PsnCashPay   float64
494
+		AcctPay      float64
495
+		FunPay       float64
496
+	}
497
+
498
+	// To store totals per patient
499
+	patientTotals := make(map[string]CusTotal)
500
+	var grandTotal CusTotal
501
+
502
+	for _, item := range results {
503
+		var tempTotal CusTotal
504
+
505
+		err := readDb.Model(models.HisOrder{}).
506
+			Select("sum(medfee_sumamt) as medfee_sumamt, "+
507
+				"sum(psn_cash_pay) as psn_cash_pay, "+
508
+				"sum(acct_pay) as acct_pay, "+
509
+				"sum(fund_pay_sumamt) as fun_pay").
510
+			Where("patient_id = ? and user_org_id = ? "+
511
+				"and setl_time >= ? and setl_time <= ? "+
512
+				"and status = 1 and order_status = 2",
513
+				item.PatientID, org_id,
514
+				startTime+" 00:00:00", endTime+" 23:59:59").
515
+			Scan(&tempTotal).Error
516
+
517
+		if err != nil {
518
+			log.Printf("Error querying for patient %s: %v", item.PatientID, err)
519
+			continue
520
+		}
521
+
522
+		// Store this patient's total
523
+		patientTotals[item.PatientID] = tempTotal
524
+
525
+		// Accumulate to grand total
526
+		grandTotal.MedfeeSumamt += tempTotal.MedfeeSumamt
527
+		grandTotal.PsnCashPay += tempTotal.PsnCashPay
528
+		grandTotal.AcctPay += tempTotal.AcctPay
529
+		grandTotal.FunPay += tempTotal.FunPay
530
+	}
531
+
532
+	// Print totals per patient
533
+	for patientID, total := range patientTotals {
534
+		//fmt.Printf("Patient %s total: %+v\n", patientID, total)
535
+		for _, item := range results {
536
+			if patientID == item.PatientID {
537
+				item.TotalMedicalFee = total.MedfeeSumamt
538
+				item.SelfPay = total.PsnCashPay
539
+				item.AcctPay = total.AcctPay
540
+				item.YingShou = total.MedfeeSumamt
541
+				item.ShiShou = total.MedfeeSumamt
542
+				item.YiShou = total.PsnCashPay
543
+				fmt.Println(item)
544
+			}
545
+
546
+		}
547
+	}
548
+
549
+	type CusTotalTwo struct {
550
+		XT float64 `gorm:"column:XT"`
551
+		XL float64 `gorm:"column:XL"`
552
+		GL float64 `gorm:"column:GL"`
553
+	}
554
+
555
+	// To store totals per patient
556
+	patientTotals_two := make(map[string]CusTotalTwo)
557
+	var grandTotal_two CusTotalTwo
558
+
559
+	for _, item := range results {
560
+		if org_id == 9478 {
561
+			var tempTotal CusTotalTwo
562
+
563
+			readDb.Table("his_order_info as oi").Select(`
564
+    COALESCE(SUM(CASE WHEN project.project_name = '血液透析(用)' THEN p.count ELSE 0 END), 0) as XT,
565
+    COALESCE(SUM(CASE WHEN project.project_name = '血液透析滤过(用)' THEN p.count ELSE 0 END), 0) as XL,
566
+    COALESCE(SUM(CASE WHEN project.project_name = '血液灌流(用)' THEN p.count ELSE 0 END), 0) as GL
567
+`).
568
+				Joins("JOIN his_order o ON oi.order_number = o.number AND o.setl_time BETWEEN ? AND ? AND o.order_status = 2 AND o.status = 1", startTime+" 00:00:00", endTime+" 23:59:59").
569
+				Joins("JOIN his_prescription_project p ON oi.project_id = p.id").
570
+				Joins("LEFT JOIN xt_his_project project ON p.project_id = project.id").
571
+				Joins("JOIN xt_patients pp ON oi.patient_id = pp.id").
572
+				Where(`
573
+    oi.patient_id = ? 
574
+    AND oi.project_id > 0 
575
+    AND oi.user_org_id = ? 
576
+    AND oi.upload_date >= ? 
577
+    AND oi.upload_date <= ? 
578
+    AND oi.status = 1 
579
+    AND p.type = 2 
580
+    AND project.project_name IN ('血液透析(用)','血液透析滤过(用)','血液灌流(用)')
581
+`, item.PatientID, org_id, st_stamp, end_stamp).
582
+				Scan(&tempTotal)
583
+
584
+			patientTotals_two[item.PatientID] = tempTotal
585
+			grandTotal_two.GL += tempTotal.GL
586
+			grandTotal_two.XT += tempTotal.XT
587
+			grandTotal_two.XL += tempTotal.XL
588
+
589
+		} else {
590
+			var tempTotal CusTotalTwo
591
+
592
+			readDb.Table("his_order_info as oi").Select(`
593
+    COALESCE(SUM(CASE WHEN project.project_name = '血液透析' THEN p.count ELSE 0 END), 0) as XT,
594
+    COALESCE(SUM(CASE WHEN project.project_name = '血液透析滤过' THEN p.count ELSE 0 END), 0) as XL,
595
+    COALESCE(SUM(CASE WHEN project.project_name = '血液灌流' THEN p.count ELSE 0 END), 0) as GL
596
+`).
597
+				Joins("JOIN his_order o ON oi.order_number = o.number AND o.setl_time BETWEEN ? AND ? AND o.order_status = 2 AND o.status = 1", startTime+" 00:00:00", endTime+" 23:59:59").
598
+				Joins("JOIN his_prescription_project p ON oi.project_id = p.id").
599
+				Joins("LEFT JOIN xt_his_project project ON p.project_id = project.id").
600
+				Joins("JOIN xt_patients pp ON oi.patient_id = pp.id").
601
+				Where(`
602
+    oi.patient_id = ? 
603
+    AND oi.project_id > 0 
604
+    AND oi.user_org_id = ? 
605
+    AND oi.upload_date >= ? 
606
+    AND oi.upload_date <= ? 
607
+    AND oi.status = 1 
608
+    AND p.type = 2 
609
+    AND project.project_name IN ('血液透析','血液透析滤过','血液灌流')
610
+`, item.PatientID, org_id, st_stamp, end_stamp).
611
+				Scan(&tempTotal)
612
+
613
+			patientTotals_two[item.PatientID] = tempTotal
614
+			grandTotal_two.GL += tempTotal.GL
615
+			grandTotal_two.XT += tempTotal.XT
616
+			grandTotal_two.XL += tempTotal.XL
617
+
618
+		}
619
+	}
620
+	fmt.Println(patientTotals_two)
621
+
622
+	for patientID, total := range patientTotals_two {
623
+		//fmt.Printf("Patient %s total: %+v\n", patientID, total)
624
+		for _, item := range results {
625
+			if patientID == item.PatientID {
626
+				item.Total = total.XL + total.GL + total.XT
627
+				item.XtCount = total.XT
628
+				item.XlCount = total.XL
629
+				item.GlCount = total.GL
630
+			}
631
+
632
+		}
633
+	}
634
+	// Print grand total
635
+	//fmt.Printf("Grand total for all patients: %+v\n", grandTotal)
636
+	return results, nil
637
+}
638
+
639
+func GetHisOrderBySummary(startTime, endTime string, st_stamp, end_stamp int64, org_id int64) ([]MedicalChargesThree, error) {
640
+	var results []MedicalChargesThree
641
+	medChargeTypes := []string{"01", "02", "03", "04", "05", "07", "08", "09", "10", "11", "12", "13", "14"}
642
+
643
+	// 优化后的费用聚合子查询(使用覆盖索引)
644
+	subQuery := readDb.Table("his_order_info").
645
+		Select(`order_number, med_chrgitm_type, SUM(det_item_fee_sumamt) AS det_item_fee_sumamt`).
646
+		Where("user_org_id = ? AND status = ? AND upload_date BETWEEN ? AND ?",
647
+			org_id, 1, st_stamp, end_stamp).
648
+		Where("med_chrgitm_type IN (?)", medChargeTypes).
649
+		Group("order_number, med_chrgitm_type").
650
+		SubQuery()
651
+
652
+	// 处理时间范围格式
653
+	startTimeFull := fmt.Sprintf("%s 00:00:00", startTime)
654
+	endTimeFull := fmt.Sprintf("%s 23:59:59", endTime)
655
+
656
+	err := readDb.Table("his_order").
657
+		Select(`his_order.psn_name AS 姓名,
658
+			CASE his_order.insutype
659
+				WHEN '390' THEN '城乡'
660
+				WHEN '310' THEN '职工'
661
+				ELSE '未知' 
662
+			END AS "类型",
663
+			SUM(CASE i.med_chrgitm_type WHEN '09' THEN i.det_item_fee_sumamt ELSE 0 END) AS 西药费,
664
+			0 AS 成药费,
665
+			SUM(CASE i.med_chrgitm_type WHEN '11' THEN i.det_item_fee_sumamt ELSE 0 END) AS 中成药费,
666
+			SUM(CASE i.med_chrgitm_type WHEN '08' THEN i.det_item_fee_sumamt ELSE 0 END) AS 耗材费,
667
+			SUM(CASE i.med_chrgitm_type WHEN '13' THEN i.det_item_fee_sumamt ELSE 0 END) AS 挂号费,
668
+			SUM(CASE i.med_chrgitm_type WHEN '05' THEN i.det_item_fee_sumamt ELSE 0 END) AS 治疗费,
669
+			SUM(CASE i.med_chrgitm_type WHEN '03' THEN i.det_item_fee_sumamt ELSE 0 END) AS 检查费,
670
+			SUM(CASE i.med_chrgitm_type WHEN '04' THEN i.det_item_fee_sumamt ELSE 0 END) AS 化验费,
671
+			SUM(CASE i.med_chrgitm_type WHEN '07' THEN i.det_item_fee_sumamt ELSE 0 END) AS 护理费,
672
+			SUM(CASE i.med_chrgitm_type WHEN '14' THEN i.det_item_fee_sumamt ELSE 0 END) AS 其他费,
673
+			SUM(his_order.medfee_sumamt) AS 合计,  -- 移除不必要的DISTINCT
674
+			SUM(his_order.psn_cash_pay) AS 自费金额,
675
+			SUM(his_order.acct_pay) AS 个人账户支付,
676
+			SUM(his_order.fund_pay_sumamt) AS 医保报销金额,
677
+			"" AS 退费,
678
+			"" AS 优惠,
679
+			SUM(his_order.medfee_sumamt) AS 应收,
680
+			"" AS 挂账,
681
+			"" AS 冲账,
682
+			SUM(his_order.medfee_sumamt) AS 实收`).
683
+		Joins("JOIN (?) i ON his_order.number = i.order_number", subQuery).
684
+		//Joins("LEFTJOIN (?) p ON his_order.number = p.order_number", projectJoinQuery).
685
+		Where("his_order.user_org_id = ?", org_id).
686
+		Where("his_order.order_status = ?", 2).
687
+		Where("his_order.setl_time BETWEEN ? AND ?", startTimeFull, endTimeFull).
688
+		Where("his_order.is_medicine_insurance = ?", 1).
689
+		Where("his_order.status = ?", 1).
690
+		Group("his_order.patient_id").
691
+		Scan(&results).Error
692
+
693
+	if err != nil {
694
+		return nil, err
695
+	}
696
+
697
+	return results, nil
698
+}
699
+
700
+// 建议的索引方案(MySQL语法示例)
701
+/*
702
+-- his_order_info 表
703
+ALTER TABLE his_order_info
704
+ADD INDEX idx_org_status_upload (user_org_id, status, upload_date),
705
+ADD INDEX idx_order_medtype (order_number, med_chrgitm_type);
706
+
707
+-- his_order 表
708
+ALTER TABLE his_order
709
+ADD INDEX idx_org_status_setltime (user_org_id, order_status, setl_time),
710
+ADD INDEX idx_patient_setltime (patient_id, setl_time);
711
+
712
+-- his_prescription_project 表
713
+ALTER TABLE his_prescription_project
714
+ADD INDEX idx_org_record_project (user_org_id, record_date, project_id),
715
+ADD INDEX idx_status_project (status, project_id);
716
+
717
+-- xt_his_project 表
718
+ALTER TABLE xt_his_project
719
+ADD INDEX idx_org_project (id, user_org_id);
720
+*/
397 721
 type MedicalChargesTwo struct {
398 722
 	TotalMedicalFee float64 `gorm:"column:医疗费总额"`     // 医疗费总额
399 723
 	Fund            float64 `gorm:"column:基金支付总金额"`   // 个人自付金额

+ 472 - 3
service/pharmacy_service.go Ver arquivo

@@ -300,7 +300,9 @@ func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (p
300 300
 	InitDrugidIsNil(orgid, stime, etime)
301 301
 	var tmp []*models.HisDoctorAdviceInfoL
302 302
 	if orgid == 10375 {
303
-		err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
303
+		err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Preload("Drug", func(db *gorm.DB) *gorm.DB {
304
+			return db.Preload("Manufacturers", "status = 1").Where("status = 1")
305
+		}).Where(
304 306
 			"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and patient_id = ? and drug_id in (select id from xt_base_drug where org_id = ?)", stime, etime, orgid, patient_id, orgid).Find(&tmp).Error
305 307
 		if err != nil {
306 308
 			return pp, err
@@ -322,6 +324,10 @@ func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (p
322 324
 				Price:        v.Price,
323 325
 				DrugCode:     v.DrugCode,
324 326
 				ZeroFlag:     config.ToString(v.ZeroFlag),
327
+				MName:        v.Drug.Manufacturers.ManufacturerName,
328
+				Spec:         v.Drug.Dose + v.Drug.DoseUnit + strconv.FormatInt(v.Drug.MinNumber, 10) + v.Drug.MinUnit + "/" + v.Drug.MaxUnit,
329
+				Type:         1,
330
+				Bm:           v.Drug.MedicalInsuranceNumber,
325 331
 			})
326 332
 		}
327 333
 
@@ -354,6 +360,7 @@ func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (p
354 360
 				Remarks:      v.Remark,
355 361
 				DrugId:       v.DrugId,
356 362
 				DrugCode:     v.DrugCode,
363
+				Type:         1,
357 364
 			})
358 365
 		}
359 366
 		return
@@ -361,13 +368,17 @@ func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (p
361 368
 
362 369
 	if orgid != 10375 {
363 370
 		if is_medicine == 0 {
364
-			err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
371
+			err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Preload("Drug", func(db *gorm.DB) *gorm.DB {
372
+				return db.Preload("Manufacturers", "status = 1").Where("status = 1")
373
+			}).Where(
365 374
 				"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp).Error
366 375
 			if err != nil {
367 376
 				return pp, err
368 377
 			}
369 378
 		} else {
370
-			err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
379
+			err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Preload("Drug", func(db *gorm.DB) *gorm.DB {
380
+				return db.Preload("Manufacturers", "status = 1").Where("status = 1")
381
+			}).Where(
371 382
 				"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp).Error
372 383
 			if err != nil {
373 384
 				return pp, err
@@ -393,6 +404,10 @@ func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (p
393 404
 				Price:          v.Price,
394 405
 				DrugCode:       v.DrugCode,
395 406
 				ZeroFlag:       config.ToString(v.ZeroFlag),
407
+				MName:          v.Drug.Manufacturers.ManufacturerName,
408
+				Spec:           v.Drug.Dose + v.Drug.DoseUnit + strconv.FormatInt(v.Drug.MinNumber, 10) + v.Drug.MinUnit + "/" + v.Drug.MaxUnit,
409
+				Type:           1,
410
+				Bm:             v.Drug.MedicalInsuranceNumber,
396 411
 			})
397 412
 		}
398 413
 
@@ -428,6 +443,8 @@ func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (p
428 443
 				ExecutionStaff: v.ExecutionStaff,
429 444
 				ExecutionTime:  v.ExecutionTime,
430 445
 				DrugCode:       v.DrugCode,
446
+				Type:           1,
447
+
431 448
 				//Price:        v.Price,
432 449
 
433 450
 			})
@@ -437,6 +454,55 @@ func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (p
437 454
 	return
438 455
 }
439 456
 
457
+func GetPatientProject(orgid, patient_id, stime, etime, is_medicine int64) (pp []*models.PharmacyContent, err error) {
458
+	var tmp []*models.HisPrintPrescriptionProjectL
459
+
460
+	if is_medicine == 0 {
461
+		err = XTReadDB().Model(&models.HisPrintPrescriptionProjectL{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
462
+			return db.Preload("Manufacturers", "status = 1").Where("status = 1")
463
+		}).Where(
464
+			"status = 1 and record_date >= ? and record_date <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and type = 3", stime, etime, orgid, patient_id, is_medicine).Find(&tmp).Error
465
+		if err != nil {
466
+			return pp, err
467
+		}
468
+	} else {
469
+		err = XTReadDB().Model(&models.HisPrintPrescriptionProjectL{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
470
+			return db.Preload("Manufacturers", "status = 1").Where("status = 1")
471
+		}).Where(
472
+			"status = 1 and record_date >= ? and record_date <= ? and user_org_id = ? and patient_id = ? and is_medicine = ?  and type = 3", stime, etime, orgid, patient_id, is_medicine).Find(&tmp).Error
473
+		if err != nil {
474
+			return pp, err
475
+		}
476
+	}
477
+
478
+	for _, v := range tmp {
479
+		pp = append(pp, &models.PharmacyContent{
480
+			ID:             v.ID,
481
+			Name:           v.GoodInfo.GoodName,
482
+			SingleDosage:   config.ToString(v.SingleDose) + v.Unit,
483
+			Usage:          v.DeliveryWay,
484
+			Frequency:      v.ExecutionFrequency,
485
+			Days:           config.ToString(v.Day) + "天",
486
+			Total:          config.ToString(v.Count) + v.Unit,
487
+			Doctor:         GetAdminUserName(v.Doctor, orgid), //开立医生
488
+			DataSources:    "his处方",
489
+			Remarks:        v.Remark, //备注
490
+			DrugId:         v.GoodInfo.ID,
491
+			ExecutionState: v.ExecutionState,
492
+			ExecutionStaff: v.ExecutionStaff,
493
+			ExecutionTime:  v.ExecutionTime,
494
+			Price:          v.Price,
495
+			DrugCode:       v.DrugCode,
496
+			MName:          v.GoodInfo.Manufacturers.ManufacturerName,
497
+			Spec:           v.GoodInfo.SpecificationName,
498
+			Type:           2,
499
+			Bm:             v.GoodInfo.MedicalInsuranceNumber,
500
+		})
501
+	}
502
+
503
+	return
504
+}
505
+
440 506
 // 获取创建者姓名(改)
441 507
 func GetAdminUserName(doctor, orgid int64) string {
442 508
 	var tmp models.VmUserAdminRole
@@ -793,21 +859,43 @@ func DispensingMedicine(orgid, patient_id, stime, etime, creater int64) (err err
793 859
 	time_now := time.Now().Unix()
794 860
 	var hids []*models.TmpID
795 861
 	var xids []*models.TmpID
862
+
863
+	var projectids []*models.TmpID
864
+
796 865
 	err = tx.Raw("select id from his_doctor_advice_info where status = 1 and advice_date >= ? and advice_date <= ? "+
797 866
 		"and user_org_id = ? and patient_id = ? and is_medicine = 0 and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) ", stime, etime, orgid, patient_id, orgid).Scan(&hids).Error
798 867
 	if err != nil {
799 868
 		return
800 869
 	}
870
+
871
+	err = tx.Raw("select id from his_prescription_project where status = 1 and record_date >= ? and record_date <= ? "+
872
+		"and user_org_id = ? and patient_id = ? and is_medicine = 0  ", stime, etime, orgid, patient_id).Scan(&projectids).Error
873
+	if err != nil {
874
+		return
875
+	}
876
+
801 877
 	hid := make([]int64, 0)
878
+
879
+	pid := make([]int64, 0)
880
+
802 881
 	for _, v := range hids {
803 882
 		hid = append(hid, v.Id)
804 883
 	}
884
+	for _, v := range projectids {
885
+		pid = append(pid, v.Id)
886
+	}
805 887
 	var advice_info []*models.HisDoctorAdviceInfo
806 888
 	err = tx.Model(&models.HisDoctorAdviceInfo{}).Where("id in (?) and status = 1", hid).Find(&advice_info).Error
807 889
 	if err != nil {
808 890
 		return
809 891
 	}
810 892
 
893
+	var project_info []*models.HisPrescriptionProject
894
+	err = tx.Model(&models.HisPrescriptionProject{}).Where("id in (?) and status = 1", pid).Find(&project_info).Error
895
+	if err != nil {
896
+		return
897
+	}
898
+
811 899
 	if orgid != 10480 {
812 900
 		for _, v := range advice_info {
813 901
 
@@ -911,6 +999,55 @@ func DispensingMedicine(orgid, patient_id, stime, etime, creater int64) (err err
911 999
 	return
912 1000
 }
913 1001
 
1002
+func DispensingGoods(orgid, patient_id, stime, etime, creater int64) (err error) {
1003
+	//开事务
1004
+	tx := XTWriteDB().Begin()
1005
+	defer func() {
1006
+		if err != nil {
1007
+			utils.ErrorLog("事务失败,原因为: %v", err)
1008
+			tx.Rollback()
1009
+		} else {
1010
+			tx.Commit()
1011
+		}
1012
+	}()
1013
+	time_now := time.Now().Unix()
1014
+
1015
+	var projectids []*models.TmpID
1016
+
1017
+	err = tx.Raw("select id from his_prescription_project where status = 1 and record_date >= ? and record_date <= ? "+
1018
+		"and user_org_id = ? and patient_id = ? and is_medicine = 0 and type = 3 ", stime, etime, orgid, patient_id).Scan(&projectids).Error
1019
+	if err != nil {
1020
+		return
1021
+	}
1022
+
1023
+	pid := make([]int64, 0)
1024
+
1025
+	for _, v := range projectids {
1026
+		pid = append(pid, v.Id)
1027
+	}
1028
+
1029
+	var project_info []*models.HisPrescriptionProject
1030
+	err = tx.Model(&models.HisPrescriptionProject{}).Where("id in (?) and status = 1", pid).Find(&project_info).Error
1031
+	if err != nil {
1032
+		return
1033
+	}
1034
+
1035
+	//修改状态
1036
+	errs := XTWriteDB().Model(&models.HisPrescriptionProject{}).Where("id in (?)", pid).Updates(map[string]interface{}{
1037
+		"is_medicine":     1,
1038
+		"dispensing_time": time_now,
1039
+	}).Error
1040
+	if errs != nil {
1041
+		return errs
1042
+	}
1043
+	err1 := ChangeHisPrescriptionByGood(pid)
1044
+	if err1 != nil {
1045
+		return err1
1046
+	}
1047
+
1048
+	return
1049
+}
1050
+
914 1051
 func DispensingMedicineOne(orgid, patient_id, stime, etime, creater int64) (err error) {
915 1052
 
916 1053
 	//开事务
@@ -1229,6 +1366,52 @@ func DrugWithdrawal(orgid, patient_id, stime, etime, creater int64) (err error)
1229 1366
 	return
1230 1367
 }
1231 1368
 
1369
+func DrugWithdrawalForGood(orgid, patient_id, stime, etime, creater int64) (err error) {
1370
+	//开事务
1371
+	tx := XTWriteDB().Begin()
1372
+	defer func() {
1373
+		if err != nil {
1374
+			utils.ErrorLog("事务失败,原因为: %v", err)
1375
+			tx.Rollback()
1376
+		} else {
1377
+			tx.Commit()
1378
+		}
1379
+	}()
1380
+	map_time := make(map[int64]int64)
1381
+	var hids []*models.TmpID
1382
+	//var hid,xid []int64//查询已发药的药品
1383
+	err = tx.Raw("select id,dispensing_time from his_prescription_project where  type = 3 and status = 1 and record_date >= ? and record_date <= ?"+
1384
+		" and user_org_id = ? and patient_id = ? and is_medicine = 1", stime, etime, orgid, patient_id).Scan(&hids).Error
1385
+	if err != nil {
1386
+		return
1387
+	}
1388
+	hid := make([]int64, 0)
1389
+	for _, v := range hids {
1390
+		hid = append(hid, v.Id)
1391
+		map_time[v.DispensingTime] = v.DispensingTime
1392
+	}
1393
+	//修改状态
1394
+	errs := XTWriteDB().Model(&models.HisPrintPrescriptionProjectL{}).Where("id in (?)", hid).Updates(map[string]interface{}{
1395
+		"is_medicine":     0,
1396
+		"dispensing_time": 0,
1397
+	}).Error
1398
+	if errs != nil {
1399
+		return errs
1400
+	}
1401
+	ChangeHisPrescriptionTwo(hid)
1402
+	//删除掉发药明细
1403
+	for k, _ := range map_time {
1404
+		err = tx.Model(&models.Pharmary{}).Where("user_org_id = ? and record_date = ? and patient_id = ? ", orgid, k, patient_id).Updates(map[string]interface{}{
1405
+			"status": 0,
1406
+			"mtime":  time.Now().Unix(),
1407
+		}).Error
1408
+		if err != nil {
1409
+			return
1410
+		}
1411
+	}
1412
+	return
1413
+}
1414
+
1232 1415
 // 获取患者名称
1233 1416
 func FindUserName(patient_id int64) (name string) {
1234 1417
 	var tmp models.GetHisName
@@ -1245,6 +1428,14 @@ func FindDrugsName(drug_id int64) (name string) {
1245 1428
 	return
1246 1429
 }
1247 1430
 
1431
+// 获取药品名称
1432
+func FindGoodsName(project_id int64) (name string) {
1433
+	var tmp models.GoodInfo
1434
+	XTReadDB().Model(&models.GoodInfo{}).Where("id = ?", project_id).Find(&tmp)
1435
+	name = tmp.GoodName
1436
+	return
1437
+}
1438
+
1248 1439
 // 药品发药按钮点击(
1249 1440
 func MedicineDeparture(ids string, creater, orgid int64) (err error) {
1250 1441
 	//开事务
@@ -1689,6 +1880,31 @@ func ChangeHisPrescription(tmp []int64) (err error) {
1689 1880
 	return
1690 1881
 }
1691 1882
 
1883
+func ChangeHisPrescriptionByGood(tmp []int64) (err error) {
1884
+	var advice_info []*models.HisPrescriptionProject
1885
+	err = XTReadDB().Model(&models.HisPrescriptionProject{}).Where("id in (?) and status = 1", tmp).Find(&advice_info).Error
1886
+	if err != nil {
1887
+		if err == gorm.ErrRecordNotFound {
1888
+			return nil
1889
+		}
1890
+		return
1891
+	}
1892
+
1893
+	tmp_id := make(map[int64]int64)
1894
+	for _, v := range advice_info {
1895
+		tmp_id[v.PrescriptionId] = v.PrescriptionId
1896
+	}
1897
+	for k, _ := range tmp_id {
1898
+		err = XTWriteDB().Model(&models.HisPrintPrescription{}).Where("id = ?", k).Updates(map[string]interface{}{
1899
+			"is_medicine": 1,
1900
+		}).Error
1901
+		if err != nil {
1902
+			return
1903
+		}
1904
+	}
1905
+	return
1906
+}
1907
+
1692 1908
 // 改变处方状态(退药
1693 1909
 func ChangeHisPrescriptionT(tmp []int64) (err error) {
1694 1910
 	var advice_info []*models.HisDoctorAdviceInfo
@@ -1721,6 +1937,35 @@ func ChangeHisPrescriptionT(tmp []int64) (err error) {
1721 1937
 	return
1722 1938
 }
1723 1939
 
1940
+func ChangeHisPrescriptionTwo(tmp []int64) (err error) {
1941
+	var advice_info []*models.HisPrescriptionProject
1942
+	err = XTReadDB().Model(&models.HisPrescriptionProject{}).Where("id in (?) and status = 1", tmp).Find(&advice_info).Error
1943
+	if err != nil {
1944
+		if err == gorm.ErrRecordNotFound {
1945
+			return nil
1946
+		}
1947
+		return
1948
+	}
1949
+	tmp_id := make(map[int64]int64)
1950
+	for _, v := range advice_info {
1951
+		tmp_id[v.PrescriptionId] = v.PrescriptionId
1952
+	}
1953
+	for k, _ := range tmp_id {
1954
+		var total int
1955
+		//查询退药的
1956
+		XTReadDB().Model(&models.HisPrescriptionProject{}).Where("prescription_id = ? and status = 1 and is_medicine = 1", k).Count(&total)
1957
+		if total == 0 {
1958
+			err = XTWriteDB().Model(&models.HisPrescriptionProject{}).Where("id = ?", k).Updates(map[string]interface{}{
1959
+				"is_medicine": 0,
1960
+			}).Error
1961
+			if err != nil {
1962
+				return
1963
+			}
1964
+		}
1965
+	}
1966
+	return
1967
+}
1968
+
1724 1969
 // 改变处方状态
1725 1970
 func ChangeHisPrescriptionid(id string) (err error) {
1726 1971
 	var advice models.HisDoctorAdviceInfo
@@ -2368,6 +2613,27 @@ func FindeHisAdviceDocAdvice(orgid int64, patient_id int64, stime int64, etime i
2368 2613
 	return advice, err
2369 2614
 }
2370 2615
 
2616
+func FindeHisProjectDocAdvice(orgid int64, patient_id int64, stime int64, etime int64) (advice []*models.HisPrescriptionProject, err error) {
2617
+
2618
+	db := XTReadDB().Model(&advice).Where("status= 1 and is_medicine = 0")
2619
+
2620
+	if orgid > 0 {
2621
+		db = db.Where("user_org_id = ?", orgid)
2622
+	}
2623
+	if patient_id > 0 {
2624
+		db = db.Where("patient_id = ?", patient_id)
2625
+	}
2626
+	if stime > 0 {
2627
+		db = db.Where("recrod_date >=?", stime)
2628
+	}
2629
+	if etime > 0 {
2630
+		db = db.Where("recrod_date<=?", etime)
2631
+	}
2632
+	err = db.Find(&advice).Error
2633
+
2634
+	return advice, err
2635
+}
2636
+
2371 2637
 func FindeHisAdviceDocAdviceOne(orgid int64, patient_id int64, drug_id int64, advice_date int64) (advice []*models.HisDoctorAdviceInfo, err error) {
2372 2638
 
2373 2639
 	db := XTReadDB().Model(&advice).Where("status= 1 and is_medicine = 0")
@@ -2470,6 +2736,12 @@ func ChangeHisDrugCode(id int64, drug_code string, user_org_id int64) (models.Hi
2470 2736
 	return adviceInfo, err
2471 2737
 }
2472 2738
 
2739
+func ChangeHisProjectCode(id int64, drug_code string, user_org_id int64) (models.HisPrescriptionProject, error) {
2740
+	adviceInfo := models.HisPrescriptionProject{}
2741
+	err := XTWriteDB().Model(&adviceInfo).Where("id = ? and user_org_id = ? and status =1", id, user_org_id).Updates(map[string]interface{}{"drug_code": drug_code}).Error
2742
+	return adviceInfo, err
2743
+}
2744
+
2473 2745
 func ChangeAdivceDrugCode(id int64, drug_code string, user_org_id int64) (models.DoctorAdvice, error) {
2474 2746
 
2475 2747
 	adviceInfo := models.DoctorAdvice{}
@@ -2575,3 +2847,200 @@ func GetNewBaseDrugById(id int64) (models.NBXtBaseDrug, error) {
2575 2847
 
2576 2848
 	return drug, err
2577 2849
 }
2850
+
2851
+func GetNewPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (pp []*models.PharmacyContent, err error) {
2852
+	InitDrugidIsNil(orgid, stime, etime)
2853
+	var tmp []*models.HisDoctorAdviceInfoL
2854
+	if orgid == 10375 {
2855
+		err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
2856
+			"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and patient_id = ? and drug_id in (select id from xt_base_drug where org_id = ?)", stime, etime, orgid, patient_id, orgid).Find(&tmp).Error
2857
+		if err != nil {
2858
+			return pp, err
2859
+		}
2860
+
2861
+		for _, v := range tmp {
2862
+			pp = append(pp, &models.PharmacyContent{
2863
+				ID:           v.ID,
2864
+				Name:         v.AdviceName,
2865
+				SingleDosage: config.ToString(v.SingleDose) + v.SingleDoseUnit,
2866
+				Usage:        v.DeliveryWay,
2867
+				Frequency:    v.ExecutionFrequency,
2868
+				Days:         config.ToString(v.Day) + "天",
2869
+				Total:        config.ToString(v.PrescribingNumber) + v.PrescribingNumberUnit,
2870
+				Doctor:       GetAdminUserName(v.AdviceDoctor, orgid), //开立医生
2871
+				DataSources:  "his处方",
2872
+				Remarks:      v.Remark, //备注
2873
+				DrugId:       v.DrugId,
2874
+				Price:        v.Price,
2875
+				DrugCode:     v.DrugCode,
2876
+				ZeroFlag:     config.ToString(v.ZeroFlag),
2877
+			})
2878
+		}
2879
+
2880
+		var tmp_advice []*models.XtDoctorAdviceL
2881
+		if is_medicine == 0 {
2882
+			err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
2883
+				"status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp_advice).Error
2884
+			if err != nil {
2885
+				return pp, err
2886
+			}
2887
+		} else {
2888
+			err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
2889
+				"status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp_advice).Error
2890
+			if err != nil {
2891
+				return pp, err
2892
+			}
2893
+		}
2894
+
2895
+		for _, v := range tmp_advice {
2896
+			pp = append(pp, &models.PharmacyContent{
2897
+				ID:           v.ID,
2898
+				Name:         v.AdviceName,
2899
+				SingleDosage: config.ToString(v.SingleDose) + v.SingleDoseUnit,
2900
+				Usage:        v.DeliveryWay,
2901
+				Frequency:    v.ExecutionFrequency,
2902
+				Days:         "-",
2903
+				Total:        config.ToString(v.PrescribingNumber) + v.PrescribingNumberUnit,
2904
+				Doctor:       GetAdminUserName(v.AdviceDoctor, orgid),
2905
+				DataSources:  "临时医嘱",
2906
+				Remarks:      v.Remark,
2907
+				DrugId:       v.DrugId,
2908
+				DrugCode:     v.DrugCode,
2909
+			})
2910
+		}
2911
+		return
2912
+	}
2913
+
2914
+	if orgid != 10375 {
2915
+		if is_medicine == 0 {
2916
+			err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
2917
+				"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp).Error
2918
+			if err != nil {
2919
+				return pp, err
2920
+			}
2921
+		} else {
2922
+			err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
2923
+				"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp).Error
2924
+			if err != nil {
2925
+				return pp, err
2926
+			}
2927
+		}
2928
+
2929
+		for _, v := range tmp {
2930
+			pp = append(pp, &models.PharmacyContent{
2931
+				ID:             v.ID,
2932
+				Name:           v.AdviceName,
2933
+				SingleDosage:   config.ToString(v.SingleDose) + v.SingleDoseUnit,
2934
+				Usage:          v.DeliveryWay,
2935
+				Frequency:      v.ExecutionFrequency,
2936
+				Days:           config.ToString(v.Day) + "天",
2937
+				Total:          config.ToString(v.PrescribingNumber) + v.PrescribingNumberUnit,
2938
+				Doctor:         GetAdminUserName(v.AdviceDoctor, orgid), //开立医生
2939
+				DataSources:    "his处方",
2940
+				Remarks:        v.Remark, //备注
2941
+				DrugId:         v.DrugId,
2942
+				ExecutionState: v.ExecutionState,
2943
+				ExecutionStaff: v.ExecutionStaff,
2944
+				ExecutionTime:  v.ExecutionTime,
2945
+				Price:          v.Price,
2946
+				DrugCode:       v.DrugCode,
2947
+				ZeroFlag:       config.ToString(v.ZeroFlag),
2948
+			})
2949
+		}
2950
+
2951
+		var tmp_advice []*models.XtDoctorAdviceL
2952
+		if is_medicine == 0 {
2953
+			err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
2954
+				"status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp_advice).Error
2955
+			if err != nil {
2956
+				return pp, err
2957
+			}
2958
+		} else {
2959
+			err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
2960
+				"status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp_advice).Error
2961
+			if err != nil {
2962
+				return pp, err
2963
+			}
2964
+		}
2965
+
2966
+		for _, v := range tmp_advice {
2967
+			pp = append(pp, &models.PharmacyContent{
2968
+				ID:             v.ID,
2969
+				Name:           v.AdviceName,
2970
+				SingleDosage:   config.ToString(v.SingleDose) + v.SingleDoseUnit,
2971
+				Usage:          v.DeliveryWay,
2972
+				Frequency:      v.ExecutionFrequency,
2973
+				Days:           "-",
2974
+				Total:          config.ToString(v.PrescribingNumber) + v.PrescribingNumberUnit,
2975
+				Doctor:         GetAdminUserName(v.AdviceDoctor, orgid),
2976
+				DataSources:    "临时医嘱",
2977
+				Remarks:        v.Remark,
2978
+				DrugId:         v.DrugId,
2979
+				ExecutionState: v.ExecutionState,
2980
+				ExecutionStaff: v.ExecutionStaff,
2981
+				ExecutionTime:  v.ExecutionTime,
2982
+				DrugCode:       v.DrugCode,
2983
+				//Price:        v.Price,
2984
+
2985
+			})
2986
+		}
2987
+		return
2988
+	}
2989
+	return
2990
+}
2991
+
2992
+func GetWaitPharmacyHISAdvicePatient(zone_id int64, sch_type int64, record_date int64, org_id int64, keyword string, is_medicine int) (patient []*models.PharmacyPatients, err error) {
2993
+	fmt.Println(zone_id)
2994
+	db := readDb.Model(&models.PharmacyPatients{})
2995
+	if zone_id > 0 {
2996
+		db = db.Joins("join xt_schedule on xt_schedule.patient_id = xt_patients.id and xt_schedule.schedule_date = ?  and xt_schedule.user_org_id = ? and xt_schedule.status = 1 and xt_schedule.partition_id = ?", record_date, org_id, zone_id)
2997
+	}
2998
+	if sch_type > 0 {
2999
+		db = db.Joins("join xt_schedule on xt_schedule.patient_id = xt_patients.id and xt_schedule.schedule_date = ?  and xt_schedule.user_org_id = ? and xt_schedule.status = 1 and xt_schedule.schedule_type = ?", record_date, org_id, sch_type)
3000
+	}
3001
+	db = db.Joins("join his_doctor_advice_info on xt_patients.id = his_doctor_advice_info.patient_id and his_doctor_advice_info.is_medicine = ? and his_doctor_advice_info.advice_date = ? and his_doctor_advice_info.user_org_id = ? and his_doctor_advice_info.status = 1", is_medicine, record_date, org_id)
3002
+	if len(keyword) > 0 {
3003
+		keyword = "%" + keyword + "%"
3004
+		db = db.Where("xt_patients.name like ?", keyword)
3005
+
3006
+	}
3007
+	err = db.Where("xt_patients.user_org_id = ?", org_id).Group("xt_patients.id").Find(&patient).Error
3008
+	return
3009
+}
3010
+
3011
+func GetWaitPharmacyXTPatient(zone_id int64, sch_type int64, record_date int64, org_id int64, keyword string, is_medicine int) (patient []*models.PharmacyPatients, err error) {
3012
+	db := readDb.Model(&models.PharmacyPatients{})
3013
+	if zone_id > 0 {
3014
+		db = db.Joins("join xt_schedule on xt_schedule.patient_id = xt_patients.id and xt_schedule.schedule_date = ?  and xt_schedule.user_org_id = ? and xt_schedule.status = 1 and xt_schedule.schedule_type = ?", record_date, org_id, sch_type)
3015
+	}
3016
+	if sch_type > 0 {
3017
+		db = db.Joins("join xt_schedule on xt_schedule.patient_id = xt_patients.id and xt_schedule.schedule_date = ?  and xt_schedule.user_org_id = ? and xt_schedule.status = 1 and xt_schedule.partition_id = ?", record_date, org_id, zone_id)
3018
+	}
3019
+	db = db.Joins("join xt_doctor_advice on xt_patients.id = xt_doctor_advice.patient_id and xt_doctor_advice.is_medicine = ? and xt_doctor_advice.advice_date = ? and xt_doctor_advice.user_org_id = ? and xt_doctor_advice.status = 1", is_medicine, record_date, org_id)
3020
+	if len(keyword) > 0 {
3021
+		keyword = "%" + keyword + "%"
3022
+		db = db.Where("xt_patients.name like ?", keyword)
3023
+
3024
+	}
3025
+	err = db.Where("xt_patients.user_org_id = ?", org_id).Group("xt_patients.id").Find(&patient).Error
3026
+
3027
+	return
3028
+}
3029
+
3030
+func GetWaitPharmacyHISGoodsPatient(zone_id int64, sch_type int64, record_date int64, org_id int64, keyword string, is_medicine int) (patient []*models.PharmacyPatients, err error) {
3031
+	db := readDb.Model(&models.PharmacyPatients{})
3032
+	if zone_id > 0 {
3033
+		db = db.Joins("join xt_schedule on xt_schedule.patient_id = xt_patients.id and xt_schedule.schedule_date = ?  and xt_schedule.user_org_id = ? and xt_schedule.status = 1 and xt_schedule.schedule_type = ?", record_date, org_id, sch_type)
3034
+	}
3035
+	if sch_type > 0 {
3036
+		db = db.Joins("join xt_schedule on xt_schedule.patient_id = xt_patients.id and xt_schedule.schedule_date = ?  and xt_schedule.user_org_id = ? and xt_schedule.status = 1 and xt_schedule.partition_id = ?", record_date, org_id, zone_id)
3037
+	}
3038
+	db = db.Joins("join his_prescription_project on xt_patients.id = his_prescription_project.patient_id  and his_prescription_project.record_date = ? and his_prescription_project.user_org_id = ? and his_prescription_project.type = 3 and his_prescription_project.status = 1 and his_prescription_project.is_medicine = ?", record_date, org_id, is_medicine)
3039
+	if len(keyword) > 0 {
3040
+		keyword = "%" + keyword + "%"
3041
+		db = db.Where("xt_patients.name like ?", keyword)
3042
+
3043
+	}
3044
+	err = db.Where("xt_patients.user_org_id = ?", org_id).Group("xt_patients.id").Find(&patient).Error
3045
+	return
3046
+}

+ 49 - 0
service/stock_service.go Ver arquivo

@@ -11068,6 +11068,55 @@ func GetHisDrugCodeQuery(orgId int64, start_time int64, end_time int64, limit in
11068 11068
 	return list, total, err
11069 11069
 }
11070 11070
 
11071
+func GetHisGoodCodeQuery(orgId int64, start_time int64, end_time int64, limit int64, page int64, is_sale int64, is_settle int64, keywords string, is_code int64) (list []*models.NewHisPrintPrescriptionProject, total int64, err error) {
11072
+
11073
+	db := XTReadDB().Model(&models.NewHisPrintPrescriptionProject{}).Preload("NewHisPrescription", "status = 1").Preload("GoodInfo", "status = 1").Where("his_prescription_project.status=1")
11074
+	if is_settle == 2 {
11075
+		db = db.Joins("join his_prescription on his_prescription.id = his_prescription_project.prescription_id and his_prescription.order_status = 2 and his_prescription.status = 1")
11076
+
11077
+	} else if is_settle == 1 {
11078
+		db = db.Joins("join his_prescription on his_prescription.id = his_prescription_project.prescription_id and his_prescription.order_status <> 2 and his_prescription.status = 1")
11079
+	}
11080
+	if is_code == 2 {
11081
+		//db = db.Joins("join his_prescription on his_prescription.id = his_doctor_advice_info.prescription_id and his_prescription.order_status = 2 and his_prescription.status = 1")
11082
+
11083
+		db = db.Where("his_prescription_project.drug_code <> ''")
11084
+
11085
+	} else if is_code == 1 {
11086
+
11087
+		db = db.Where("length(his_prescription_project.drug_code) = 0")
11088
+
11089
+	}
11090
+
11091
+	if len(keywords) > 0 {
11092
+		keywords = "%" + keywords + "%"
11093
+		db = db.Joins("join xt_patients on xt_patients.id = his_doctor_advice_info.patient_id and xt_patients.user_org_id = ? and xt_patients.name like ?", orgId, keywords)
11094
+
11095
+	}
11096
+
11097
+	if orgId > 0 {
11098
+		db = db.Where("his_prescription_project.user_org_id=?", orgId)
11099
+	}
11100
+	if start_time > 0 {
11101
+		db = db.Where("his_prescription_project.record_date >= ?", start_time)
11102
+	}
11103
+	if end_time > 0 {
11104
+		db = db.Where("his_prescription_project.record_date<=?", end_time)
11105
+	}
11106
+	offset := (page - 1) * limit
11107
+	if is_sale == 1 {
11108
+		db = db.Where("his_prescription_project.is_upload = 1")
11109
+	}
11110
+	if is_sale == 2 {
11111
+		db = db.Where("his_prescription_project.is_upload = 2 or his_prescription_project.is_upload =0")
11112
+	}
11113
+	db = db.Where("his_prescription_project.type = 3")
11114
+
11115
+	err = db.Count(&total).Offset(offset).Limit(limit).Order("his_prescription_project.record_date desc").Find(&list).Error
11116
+
11117
+	return list, total, err
11118
+}
11119
+
11071 11120
 func GetBloodDrugCode(orgId int64, start_time int64, end_time int64, limit int64, page int64, is_sale int64) (advice []*models.DoctorAdvice, total int64, err error) {
11072 11121
 
11073 11122
 	db := XTReadDB().Model(&advice).Where("status=1 and advice_type !=1")