28169 2 anni fa
parent
commit
46602b19c8
2 ha cambiato i file con 63 aggiunte e 61 eliminazioni
  1. 3 0
      controllers/doctors_api_controller.go
  2. 60 61
      service/pharmacy_service.go

+ 3 - 0
controllers/doctors_api_controller.go Vedi File

123
 		hisAdvices, err := service.GetHisDoctorAdvicesTwentyOne(orgID, date.Unix(), delivery_way, schedule_type, partition_type, patient_id, excution_way, 0, execution_frequency)
123
 		hisAdvices, err := service.GetHisDoctorAdvicesTwentyOne(orgID, date.Unix(), delivery_way, schedule_type, partition_type, patient_id, excution_way, 0, execution_frequency)
124
 		adminUser, _ := service.GetAllAdminUsers(orgID, adminUserInfo.CurrentAppId)
124
 		adminUser, _ := service.GetAllAdminUsers(orgID, adminUserInfo.CurrentAppId)
125
 		project, _ := service.GetPCHisPrescriptionProject(orgID, date.Unix(), delivery_way, patientType, partition_type, patient_id, excution_way)
125
 		project, _ := service.GetPCHisPrescriptionProject(orgID, date.Unix(), delivery_way, patientType, partition_type, patient_id, excution_way)
126
+
127
+		drug, _ := service.GetAllBaseDrugListTwenty(orgID)
126
 		for _, item := range project {
128
 		for _, item := range project {
127
 			index := 0
129
 			index := 0
128
 			for _, subItem := range item.HisPrescriptionTeamProject {
130
 			for _, subItem := range item.HisPrescriptionTeamProject {
152
 				"config":         config,
154
 				"config":         config,
153
 				"project_config": project_config,
155
 				"project_config": project_config,
154
 				"project":        project,
156
 				"project":        project,
157
+				"drug":           drug,
155
 			})
158
 			})
156
 		}
159
 		}
157
 	}
160
 	}

+ 60 - 61
service/pharmacy_service.go Vedi File

30
 	XTWriteDB().Create(&tmp)
30
 	XTWriteDB().Create(&tmp)
31
 }
31
 }
32
 
32
 
33
-//
34
 func SavePharmacy() (err error) {
33
 func SavePharmacy() (err error) {
35
 	var advice_info []*models.HisDoctorAdviceInfo
34
 	var advice_info []*models.HisDoctorAdviceInfo
36
 	err = XTReadDB().Raw("select * from xt_doctor_advice where id > 21780 and id < 21790").Scan(&advice_info).Error
35
 	err = XTReadDB().Raw("select * from xt_doctor_advice where id > 21780 and id < 21790").Scan(&advice_info).Error
40
 	return nil
39
 	return nil
41
 }
40
 }
42
 
41
 
43
-//查询药房中某一天的患者人数,is_medicine:0未发,1已发(改)
42
+// 查询药房中某一天的患者人数,is_medicine:0未发,1已发(改)
44
 func GetTodayPharmacy(stime, etime, orgid, is_medicine int64) (num int, err error) {
43
 func GetTodayPharmacy(stime, etime, orgid, is_medicine int64) (num int, err error) {
45
 	//orgid = 9675
44
 	//orgid = 9675
46
 	InitDrugidIsNil(orgid, stime, etime)
45
 	InitDrugidIsNil(orgid, stime, etime)
75
 
74
 
76
 }
75
 }
77
 
76
 
78
-//(改)
77
+// (改)
79
 func GetTodayDrug(stime, etime, orgid, is_medicine int64, keyword string) (list []*models.TmpPatient, err error) {
78
 func GetTodayDrug(stime, etime, orgid, is_medicine int64, keyword string) (list []*models.TmpPatient, err error) {
80
 	InitDrugidIsNil(orgid, stime, etime)
79
 	InitDrugidIsNil(orgid, stime, etime)
81
 	//病人
80
 	//病人
150
 
149
 
151
 }
150
 }
152
 
151
 
153
-//查询患者(改)
152
+// 查询患者(改)
154
 func GetManyUsers(tmp []int64) (list []*models.TmpPatient, err error) {
153
 func GetManyUsers(tmp []int64) (list []*models.TmpPatient, err error) {
155
 
154
 
156
 	for i := 0; i < len(tmp); i++ {
155
 	for i := 0; i < len(tmp); i++ {
167
 	return
166
 	return
168
 }
167
 }
169
 
168
 
170
-//查询患者当天时间段中的药,is_medicine:0未发,1已发(改)
169
+// 查询患者当天时间段中的药,is_medicine:0未发,1已发(改)
171
 func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (pp []*models.PharmacyContent, err error) {
170
 func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (pp []*models.PharmacyContent, err error) {
172
 	InitDrugidIsNil(orgid, stime, etime)
171
 	InitDrugidIsNil(orgid, stime, etime)
173
 	var tmp []*models.HisDoctorAdviceInfoL
172
 	var tmp []*models.HisDoctorAdviceInfoL
230
 	return
229
 	return
231
 }
230
 }
232
 
231
 
233
-//获取创建者姓名(改)
232
+// 获取创建者姓名(改)
234
 func GetAdminUserName(doctor, orgid int64) string {
233
 func GetAdminUserName(doctor, orgid int64) string {
235
 	var tmp models.VmUserAdminRole
234
 	var tmp models.VmUserAdminRole
236
 	XTReadDB().Model(&models.VmUserAdminRole{}).Where("admin_user_id = ? and org_id = ? and status = 1", doctor, orgid).Find(&tmp)
235
 	XTReadDB().Model(&models.VmUserAdminRole{}).Where("admin_user_id = ? and org_id = ? and status = 1", doctor, orgid).Find(&tmp)
237
 	return tmp.UserName
236
 	return tmp.UserName
238
 }
237
 }
239
 
238
 
240
-//查询该机构的药房配置,true: 通过药房发药,false:不通过药房发药。如果没有该机构的信息则生成一条数据
239
+// 查询该机构的药房配置,true: 通过药房发药,false:不通过药房发药。如果没有该机构的信息则生成一条数据
241
 func GetOrgIdPharmacyConfig(orgid int64) bool {
240
 func GetOrgIdPharmacyConfig(orgid int64) bool {
242
 	var total int
241
 	var total int
243
 	var tmp_pharmacy models.PharmacyConfig
242
 	var tmp_pharmacy models.PharmacyConfig
263
 	}
262
 	}
264
 }
263
 }
265
 
264
 
266
-//修改该机构的药房配置
265
+// 修改该机构的药房配置
267
 func ModifyPharmacyConfig(orgid, isopen int64) (err error) {
266
 func ModifyPharmacyConfig(orgid, isopen int64) (err error) {
268
 	if isopen == 1 || isopen == 2 {
267
 	if isopen == 1 || isopen == 2 {
269
 		err = XTWriteDB().Model(&models.PharmacyConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{
268
 		err = XTWriteDB().Model(&models.PharmacyConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{
276
 	return
275
 	return
277
 }
276
 }
278
 
277
 
279
-//查询该药品是否通过药房发药.0否;1是
278
+// 查询该药品是否通过药房发药.0否;1是
280
 func DrugAllocation(drug_id int64) (is_pharmacy int64, err error) {
279
 func DrugAllocation(drug_id int64) (is_pharmacy int64, err error) {
281
 	tmp := models.BaseDrugLib{}
280
 	tmp := models.BaseDrugLib{}
282
 	err = XTReadDB().Model(&models.BaseDrugLib{}).Where("id = ?", drug_id).Find(&tmp).Error
281
 	err = XTReadDB().Model(&models.BaseDrugLib{}).Where("id = ?", drug_id).Find(&tmp).Error
283
 	return tmp.IsPharmacy, err
282
 	return tmp.IsPharmacy, err
284
 }
283
 }
285
 
284
 
286
-//根据id查询该药是否发药
285
+// 根据id查询该药是否发药
287
 func MedicineState(id int64) (is_medicine models.HisDoctorAdviceInfoL, err error) {
286
 func MedicineState(id int64) (is_medicine models.HisDoctorAdviceInfoL, err error) {
288
 	tmp := models.HisDoctorAdviceInfoL{}
287
 	tmp := models.HisDoctorAdviceInfoL{}
289
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where("id = ?", id).Find(&tmp).Error
288
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where("id = ?", id).Find(&tmp).Error
290
 	return tmp, err
289
 	return tmp, err
291
 }
290
 }
292
 
291
 
293
-//发药明细列表(
292
+// 发药明细列表(
294
 func DispensingDetailsList(stime, etime, orgid, page, limit int64, keyword string) (dislist []*models.DispensingList, total int64, err error) {
293
 func DispensingDetailsList(stime, etime, orgid, page, limit int64, keyword string) (dislist []*models.DispensingList, total int64, err error) {
295
 	var fenye []*models.Pharmary //分页用的
294
 	var fenye []*models.Pharmary //分页用的
296
 	offset := (page - 1) * limit
295
 	offset := (page - 1) * limit
329
 	return
328
 	return
330
 }
329
 }
331
 
330
 
332
-//处方详情//////////////////////
331
+// 处方详情//////////////////////
333
 func PrescriptionDetails(patient_id, record_date, orgid int64) (pre []*models.PrescripDetails, err error) {
332
 func PrescriptionDetails(patient_id, record_date, orgid int64) (pre []*models.PrescripDetails, err error) {
334
 	var tmp []*models.HisDoctorAdviceInfoL
333
 	var tmp []*models.HisDoctorAdviceInfoL
335
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
334
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
371
 	return
370
 	return
372
 }
371
 }
373
 
372
 
374
-//查询病人的his id
373
+// 查询病人的his id
375
 func GetHisID(prescription_id, orgid int64) (id int64) {
374
 func GetHisID(prescription_id, orgid int64) (id int64) {
376
 	var tmp models.HisPrintPrescription
375
 	var tmp models.HisPrintPrescription
377
 	XTReadDB().Model(&models.HisPrintPrescription{}).Where("id = ?", prescription_id).Find(&tmp)
376
 	XTReadDB().Model(&models.HisPrintPrescription{}).Where("id = ?", prescription_id).Find(&tmp)
380
 	return fin.ID
379
 	return fin.ID
381
 }
380
 }
382
 
381
 
383
-//根据药品id获取药品信息
382
+// 根据药品id获取药品信息
384
 func GetDrugNameTX(id int64, tx *gorm.DB) (tmp models.SpBaseDrug, err error) {
383
 func GetDrugNameTX(id int64, tx *gorm.DB) (tmp models.SpBaseDrug, err error) {
385
 	err = tx.Model(&models.SpBaseDrug{}).Where("id = ? and status = 1", id).Find(&tmp).Error
384
 	err = tx.Model(&models.SpBaseDrug{}).Where("id = ? and status = 1", id).Find(&tmp).Error
386
 	return
385
 	return
392
 	return
391
 	return
393
 }
392
 }
394
 
393
 
395
-//查询药品(使用keyword)
394
+// 查询药品(使用keyword)
396
 func GetManyDrugs(orgid int64, keyword string) (map[int64]models.PharmacyBaseDrug, error) {
395
 func GetManyDrugs(orgid int64, keyword string) (map[int64]models.PharmacyBaseDrug, error) {
397
 	var tmp []*models.PharmacyBaseDrug
396
 	var tmp []*models.PharmacyBaseDrug
398
 	tt := make(map[int64]models.PharmacyBaseDrug)
397
 	tt := make(map[int64]models.PharmacyBaseDrug)
403
 	return tt, err
402
 	return tt, err
404
 }
403
 }
405
 
404
 
406
-//查询(
405
+// 查询(
407
 func GetTodayMedicine(stime, etime, orgid, is_medicine int64, keyword string) (finlly []*models.ListOfDrugs, err error) {
406
 func GetTodayMedicine(stime, etime, orgid, is_medicine int64, keyword string) (finlly []*models.ListOfDrugs, err error) {
408
 	InitDrugidIsNil(orgid, stime, etime)
407
 	InitDrugidIsNil(orgid, stime, etime)
409
 	var tmp []*models.TmpLLL
408
 	var tmp []*models.TmpLLL
474
 	return
473
 	return
475
 }
474
 }
476
 
475
 
477
-//根据药品id获取药品规格(
476
+// 根据药品id获取药品规格(
478
 func FindDrugSpecifications(id int64) (name, specifications string) {
477
 func FindDrugSpecifications(id int64) (name, specifications string) {
479
 	var tmp models.PharmacyBaseDrug
478
 	var tmp models.PharmacyBaseDrug
480
 	XTReadDB().Model(&models.PharmacyBaseDrug{}).Where("id = ?", id).Find(&tmp)
479
 	XTReadDB().Model(&models.PharmacyBaseDrug{}).Where("id = ?", id).Find(&tmp)
483
 	return
482
 	return
484
 }
483
 }
485
 
484
 
486
-//根据药品id获取当前药品出库仓库的库存数量
485
+// 根据药品id获取当前药品出库仓库的库存数量
487
 func GetInventoryQuantity(orgid, drugid int64) (number string, err error) {
486
 func GetInventoryQuantity(orgid, drugid int64) (number string, err error) {
488
 	//获取药品拆零数量
487
 	//获取药品拆零数量
489
 	var phar models.PharmacyBaseDrug
488
 	var phar models.PharmacyBaseDrug
516
 	return
515
 	return
517
 }
516
 }
518
 
517
 
519
-//获取该药品的病人信息(
518
+// 获取该药品的病人信息(
520
 func FindMedicationList(orgid, drug_id, stime, etime, is_medicine int64) (pp []*models.PatientInformation, err error) { ///////////////
519
 func FindMedicationList(orgid, drug_id, stime, etime, is_medicine int64) (pp []*models.PatientInformation, err error) { ///////////////
521
 	InitDrugidIsNil(orgid, stime, etime)
520
 	InitDrugidIsNil(orgid, stime, etime)
522
 	var tmp []*models.HisDoctorAdviceInfoL
521
 	var tmp []*models.HisDoctorAdviceInfoL
566
 	return
565
 	return
567
 }
566
 }
568
 
567
 
569
-//患者发药按钮点击(
568
+// 患者发药按钮点击(
570
 func DispensingMedicine(orgid, patient_id, stime, etime, creater int64) (err error) {
569
 func DispensingMedicine(orgid, patient_id, stime, etime, creater int64) (err error) {
571
 	//开事务
570
 	//开事务
572
 	tx := XTWriteDB().Begin()
571
 	tx := XTWriteDB().Begin()
688
 	return
687
 	return
689
 }
688
 }
690
 
689
 
691
-//患者退药按钮点击
690
+// 患者退药按钮点击
692
 func DrugWithdrawal(orgid, patient_id, stime, etime, creater int64) (err error) {
691
 func DrugWithdrawal(orgid, patient_id, stime, etime, creater int64) (err error) {
693
 	//开事务
692
 	//开事务
694
 	tx := XTWriteDB().Begin()
693
 	tx := XTWriteDB().Begin()
829
 	return
828
 	return
830
 }
829
 }
831
 
830
 
832
-//获取患者名称
831
+// 获取患者名称
833
 func FindUserName(patient_id int64) (name string) {
832
 func FindUserName(patient_id int64) (name string) {
834
 	var tmp models.GetHisName
833
 	var tmp models.GetHisName
835
 	XTReadDB().Model(&models.GetHisName{}).Where("id = ?", patient_id).Find(&tmp)
834
 	XTReadDB().Model(&models.GetHisName{}).Where("id = ?", patient_id).Find(&tmp)
837
 	return
836
 	return
838
 }
837
 }
839
 
838
 
840
-//获取药品名称
839
+// 获取药品名称
841
 func FindDrugsName(drug_id int64) (name string) {
840
 func FindDrugsName(drug_id int64) (name string) {
842
 	var tmp models.Drug
841
 	var tmp models.Drug
843
 	XTReadDB().Model(&models.Drug{}).Where("id = ?", drug_id).Find(&tmp)
842
 	XTReadDB().Model(&models.Drug{}).Where("id = ?", drug_id).Find(&tmp)
845
 	return
844
 	return
846
 }
845
 }
847
 
846
 
848
-//药品发药按钮点击(
847
+// 药品发药按钮点击(
849
 func MedicineDeparture(ids string, creater, orgid int64) (err error) {
848
 func MedicineDeparture(ids string, creater, orgid int64) (err error) {
850
 	//开事务
849
 	//开事务
851
 	tx := XTWriteDB().Begin()
850
 	tx := XTWriteDB().Begin()
995
 	return
994
 	return
996
 }
995
 }
997
 
996
 
998
-//获取领药人姓名(
997
+// 获取领药人姓名(
999
 func GetUserAdminName(id, orgID int64) string {
998
 func GetUserAdminName(id, orgID int64) string {
1000
 	var tmp models.XTSgjUserAdminRole
999
 	var tmp models.XTSgjUserAdminRole
1001
 	XTReadDB().Model(&models.XTSgjUserAdminRole{}).Where("admin_user_id = ? and org_id = ?", id, orgID).Find(&tmp)
1000
 	XTReadDB().Model(&models.XTSgjUserAdminRole{}).Where("admin_user_id = ? and org_id = ?", id, orgID).Find(&tmp)
1002
 	return tmp.UserName
1001
 	return tmp.UserName
1003
 }
1002
 }
1004
 
1003
 
1005
-//根据id查询是否已发药,true已发药,false未发药gai
1004
+// 根据id查询是否已发药,true已发药,false未发药gai
1006
 func GiveTheMedicine(id int64) bool {
1005
 func GiveTheMedicine(id int64) bool {
1007
 	var xue models.PharmacyDoctorAdvice
1006
 	var xue models.PharmacyDoctorAdvice
1008
 	XTReadDB().Model(&models.PharmacyDoctorAdvice{}).Where("id = ?", id).Find(&xue)
1007
 	XTReadDB().Model(&models.PharmacyDoctorAdvice{}).Where("id = ?", id).Find(&xue)
1012
 	return false
1011
 	return false
1013
 }
1012
 }
1014
 
1013
 
1015
-//查询改组中的药品是否包含已发药的,true已发药,false未发药
1014
+// 查询改组中的药品是否包含已发药的,true已发药,false未发药
1016
 func GiveGroupMedicine(orgid, groupNo int64) bool {
1015
 func GiveGroupMedicine(orgid, groupNo int64) bool {
1017
 	var total int
1016
 	var total int
1018
 	XTReadDB().Model(&models.DoctorAdvice{}).Where("user_org_id = ? and groupno = ? and status = 1 and is_medicine = 1", orgid, groupNo).Count(&total)
1017
 	XTReadDB().Model(&models.DoctorAdvice{}).Where("user_org_id = ? and groupno = ? and status = 1 and is_medicine = 1", orgid, groupNo).Count(&total)
1022
 	return false
1021
 	return false
1023
 }
1022
 }
1024
 
1023
 
1025
-//查询处方中是否包含已发药的
1024
+// 查询处方中是否包含已发药的
1026
 func GiveChuMedicine(id int64) bool {
1025
 func GiveChuMedicine(id int64) bool {
1027
 	var total int
1026
 	var total int
1028
 	XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where("prescription_id = ? and status = 1 and is_medicine = 1", id).Count(&total)
1027
 	XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where("prescription_id = ? and status = 1 and is_medicine = 1", id).Count(&total)
1032
 	return false
1031
 	return false
1033
 }
1032
 }
1034
 
1033
 
1035
-//根据处方id查找该处方中是否存在已发药的药品
1034
+// 根据处方id查找该处方中是否存在已发药的药品
1036
 func IsChuIssuedDrugs(prescription_id int64) bool {
1035
 func IsChuIssuedDrugs(prescription_id int64) bool {
1037
 	var total int
1036
 	var total int
1038
 	XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where("prescription_id = ? and status = 1 and is_medicine = 1", prescription_id).Count(&total)
1037
 	XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where("prescription_id = ? and status = 1 and is_medicine = 1", prescription_id).Count(&total)
1042
 	return false
1041
 	return false
1043
 }
1042
 }
1044
 
1043
 
1045
-//判断该药品是否通过药房管理出库,true是,false否
1046
-//id 药品id,org_id 机构id
1044
+// 判断该药品是否通过药房管理出库,true是,false否
1045
+// id 药品id,org_id 机构id
1047
 func IsPharmacyDelivery(id, org_id int64) bool {
1046
 func IsPharmacyDelivery(id, org_id int64) bool {
1048
 	//判断药品是否通过药房管理
1047
 	//判断药品是否通过药房管理
1049
 	var total01 int
1048
 	var total01 int
1057
 	return false
1056
 	return false
1058
 }
1057
 }
1059
 
1058
 
1060
-//判断机构是否通过药房管理出库
1059
+// 判断机构是否通过药房管理出库
1061
 func IsPharmacyConfig(orgid int64) (bo bool) {
1060
 func IsPharmacyConfig(orgid int64) (bo bool) {
1062
 	var total int
1061
 	var total int
1063
 	XTReadDB().Model(&models.PharmacyConfig{}).Where("user_org_id = ? and is_open = 1 and status = 1", orgid).Count(&total)
1062
 	XTReadDB().Model(&models.PharmacyConfig{}).Where("user_org_id = ? and is_open = 1 and status = 1", orgid).Count(&total)
1067
 	return false
1066
 	return false
1068
 }
1067
 }
1069
 
1068
 
1070
-//根据患者id和发药时间,获取医生的id和姓名
1069
+// 根据患者id和发药时间,获取医生的id和姓名
1071
 func GetDoctorIds(id, recordtime, orgid int64) (doctor_id int64, doctor_name string, err error) {
1070
 func GetDoctorIds(id, recordtime, orgid int64) (doctor_id int64, doctor_name string, err error) {
1072
 	var tmp []*models.TmpAdviceDoctor
1071
 	var tmp []*models.TmpAdviceDoctor
1073
 	//var tmp []int64
1072
 	//var tmp []int64
1091
 	return dataString
1090
 	return dataString
1092
 }
1091
 }
1093
 
1092
 
1094
-//封装扣减库存
1093
+// 封装扣减库存
1095
 func FenStock(orgid, creater int64, v *models.HisDoctorAdviceInfo) (err error) {
1094
 func FenStock(orgid, creater int64, v *models.HisDoctorAdviceInfo) (err error) {
1096
 
1095
 
1097
 	err = HisDrugsDelivery(orgid, creater, v)
1096
 	err = HisDrugsDelivery(orgid, creater, v)
1118
 	return
1117
 	return
1119
 }
1118
 }
1120
 
1119
 
1121
-//封装查询药品库存是否足够
1120
+// 封装查询药品库存是否足够
1122
 func FenDrugInventory(item *models.HisDoctorAdviceInfo, orgid int64) bool {
1121
 func FenDrugInventory(item *models.HisDoctorAdviceInfo, orgid int64) bool {
1123
 	var total int64
1122
 	var total int64
1124
 	var prescribing_number_total int64
1123
 	var prescribing_number_total int64
1233
 	return false, err
1232
 	return false, err
1234
 }
1233
 }
1235
 
1234
 
1236
-//判断药品是否零用
1235
+// 判断药品是否零用
1237
 func PettyCash(id int64) bool {
1236
 func PettyCash(id int64) bool {
1238
 	drug := models.XtBaseDrug{}
1237
 	drug := models.XtBaseDrug{}
1239
 	XTReadDB().Model(&drug).Where("id = ? and status = 1", id).Find(&drug)
1238
 	XTReadDB().Model(&drug).Where("id = ? and status = 1", id).Find(&drug)
1243
 	return false
1242
 	return false
1244
 }
1243
 }
1245
 
1244
 
1246
-//初始化
1245
+// 初始化
1247
 func InitDrugidIsNil(orgid, stime, etime int64) {
1246
 func InitDrugidIsNil(orgid, stime, etime int64) {
1248
 	var advice []*models.DoctorAdvice
1247
 	var advice []*models.DoctorAdvice
1249
 	XTReadDB().Model(&models.DoctorAdvice{}).Where("drug_id = 0 and user_org_id = ? and status = 1 and created_time >= ? and created_time <= ?", orgid, stime, etime).Find(&advice)
1248
 	XTReadDB().Model(&models.DoctorAdvice{}).Where("drug_id = 0 and user_org_id = ? and status = 1 and created_time >= ? and created_time <= ?", orgid, stime, etime).Find(&advice)
1250
 	for _, v := range advice {
1249
 	for _, v := range advice {
1251
-		XTWriteDB().Exec("update xt_doctor_advice set drug_id = (select id from xt_base_drug where drug_name = ? and org_id = ?) where id = ?", v.AdviceName, v.UserOrgId, v.ID)
1250
+		XTWriteDB().Exec("update xt_doctor_advice set drug_id = (select id from xt_base_drug where drug_name = ? and org_id = ? and status = 1 limit 1) where id = ?", v.AdviceName, v.UserOrgId, v.ID)
1252
 	}
1251
 	}
1253
 }
1252
 }
1254
 
1253
 
1255
-//改变处方状态(发药
1254
+// 改变处方状态(发药
1256
 func ChangeHisPrescription(tmp []int64) (err error) {
1255
 func ChangeHisPrescription(tmp []int64) (err error) {
1257
 	var advice_info []*models.HisDoctorAdviceInfo
1256
 	var advice_info []*models.HisDoctorAdviceInfo
1258
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfo{}).Where("id in (?) and status = 1", tmp).Find(&advice_info).Error
1257
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfo{}).Where("id in (?) and status = 1", tmp).Find(&advice_info).Error
1279
 	return
1278
 	return
1280
 }
1279
 }
1281
 
1280
 
1282
-//改变处方状态(退药
1281
+// 改变处方状态(退药
1283
 func ChangeHisPrescriptionT(tmp []int64) (err error) {
1282
 func ChangeHisPrescriptionT(tmp []int64) (err error) {
1284
 	var advice_info []*models.HisDoctorAdviceInfo
1283
 	var advice_info []*models.HisDoctorAdviceInfo
1285
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfo{}).Where("id in (?) and status = 1", tmp).Find(&advice_info).Error
1284
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfo{}).Where("id in (?) and status = 1", tmp).Find(&advice_info).Error
1311
 	return
1310
 	return
1312
 }
1311
 }
1313
 
1312
 
1314
-//改变处方状态
1313
+// 改变处方状态
1315
 func ChangeHisPrescriptionid(id string) (err error) {
1314
 func ChangeHisPrescriptionid(id string) (err error) {
1316
 	var advice models.HisDoctorAdviceInfo
1315
 	var advice models.HisDoctorAdviceInfo
1317
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ? and status = 1", id).Find(&advice).Error
1316
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ? and status = 1", id).Find(&advice).Error
1331
 	return
1330
 	return
1332
 }
1331
 }
1333
 
1332
 
1334
-//获取药品规格
1333
+// 获取药品规格
1335
 func ReplacementDrugs(orgid int64, special bool) (list []*models.ReplacementDrugs, err error) {
1334
 func ReplacementDrugs(orgid int64, special bool) (list []*models.ReplacementDrugs, err error) {
1336
 	var g errgroup.Group
1335
 	var g errgroup.Group
1337
 	var lib []*models.BaseDrugLib
1336
 	var lib []*models.BaseDrugLib
1368
 	return
1367
 	return
1369
 }
1368
 }
1370
 
1369
 
1371
-//获取药品规格,不考虑特殊病
1370
+// 获取药品规格,不考虑特殊病
1372
 func ReplacementDrugsT(orgid int64) (list []*models.ReplacementDrugs, err error) {
1371
 func ReplacementDrugsT(orgid int64) (list []*models.ReplacementDrugs, err error) {
1373
 	var lib []*models.BaseDrugLib
1372
 	var lib []*models.BaseDrugLib
1374
 	err = readDb.Model(&models.BaseDrugLib{}).Where("org_id = ?  AND status = 1 and drug_status not like '%停用%' ", orgid).Find(&lib).Error
1373
 	err = readDb.Model(&models.BaseDrugLib{}).Where("org_id = ?  AND status = 1 and drug_status not like '%停用%' ", orgid).Find(&lib).Error
1390
 	return
1389
 	return
1391
 }
1390
 }
1392
 
1391
 
1393
-//根据药品id获取药品名字
1392
+// 根据药品id获取药品名字
1394
 func IdToDrugName(id int64) (name string) {
1393
 func IdToDrugName(id int64) (name string) {
1395
 	var lib models.BaseDrugLib
1394
 	var lib models.BaseDrugLib
1396
 	readDb.Model(&models.BaseDrugLib{}).Where("id = ?", id).Find(&lib)
1395
 	readDb.Model(&models.BaseDrugLib{}).Where("id = ?", id).Find(&lib)
1397
 	return lib.DrugName
1396
 	return lib.DrugName
1398
 }
1397
 }
1399
 
1398
 
1400
-//获取项目和耗材和套餐
1399
+// 获取项目和耗材和套餐
1401
 func ProjectConsumables3(orgid int64) (list []*models.DropDownList, err error) {
1400
 func ProjectConsumables3(orgid int64) (list []*models.DropDownList, err error) {
1402
 
1401
 
1403
 	var project []*models.XtHisProject
1402
 	var project []*models.XtHisProject
1439
 	return
1438
 	return
1440
 }
1439
 }
1441
 
1440
 
1442
-//获取项目和耗材
1441
+// 获取项目和耗材
1443
 func ProjectConsumables2(orgid int64, special bool) (list []*models.DropDownList, err error) {
1442
 func ProjectConsumables2(orgid int64, special bool) (list []*models.DropDownList, err error) {
1444
 
1443
 
1445
 	var project []*models.XtHisProject
1444
 	var project []*models.XtHisProject
1477
 	return
1476
 	return
1478
 }
1477
 }
1479
 
1478
 
1480
-//获取项目和耗材不考虑特殊病
1479
+// 获取项目和耗材不考虑特殊病
1481
 func ProjectConsumables2T(orgid int64) (list []*models.DropDownList, err error) {
1480
 func ProjectConsumables2T(orgid int64) (list []*models.DropDownList, err error) {
1482
 
1481
 
1483
 	var project []*models.XtHisProject
1482
 	var project []*models.XtHisProject
1507
 	return
1506
 	return
1508
 }
1507
 }
1509
 
1508
 
1510
-//查询药品
1509
+// 查询药品
1511
 func FindPatientDrug(orgid, patient_id, drugid, mode int64) bool {
1510
 func FindPatientDrug(orgid, patient_id, drugid, mode int64) bool {
1512
 	var total int
1511
 	var total int
1513
 	XTReadDB().Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and status = 1 and "+
1512
 	XTReadDB().Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and status = 1 and "+
1519
 	return false
1518
 	return false
1520
 }
1519
 }
1521
 
1520
 
1522
-//查询项目
1521
+// 查询项目
1523
 func FindPatientXiang(orgid, patient_id, drugid, mode int64) bool {
1522
 func FindPatientXiang(orgid, patient_id, drugid, mode int64) bool {
1524
 	var total int
1523
 	var total int
1525
 	XTReadDB().Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and status = 1 and type = 2 and "+
1524
 	XTReadDB().Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and status = 1 and type = 2 and "+
1531
 	return false
1530
 	return false
1532
 }
1531
 }
1533
 
1532
 
1534
-//查询耗材
1533
+// 查询耗材
1535
 func FindPatientXiang2(orgid, patient_id, drugid, mode int64) bool {
1534
 func FindPatientXiang2(orgid, patient_id, drugid, mode int64) bool {
1536
 	var total int
1535
 	var total int
1537
 	XTReadDB().Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and status = 1 and type = 3 and "+
1536
 	XTReadDB().Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and status = 1 and type = 3 and "+
1543
 	return false
1542
 	return false
1544
 }
1543
 }
1545
 
1544
 
1546
-//types处方类型,1.药品 2.项目,model透析模式
1545
+// types处方类型,1.药品 2.项目,model透析模式
1547
 func GetHisInfoTempalteId(model, orgid, types int64) (tp []int64) {
1546
 func GetHisInfoTempalteId(model, orgid, types int64) (tp []int64) {
1548
 	type tmpid struct {
1547
 	type tmpid struct {
1549
 		Id int64
1548
 		Id int64
1557
 	return
1556
 	return
1558
 }
1557
 }
1559
 
1558
 
1560
-//替换药品处方模板
1559
+// 替换药品处方模板
1561
 func ReplaceDrugPrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, s models.HisPrescriptionAdviceTemplate, tx *gorm.DB) (err error) {
1560
 func ReplaceDrugPrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, s models.HisPrescriptionAdviceTemplate, tx *gorm.DB) (err error) {
1562
 	err = tx.Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and "+
1561
 	err = tx.Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and "+
1563
 		"status = 1 and prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1562
 		"status = 1 and prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1577
 	return err
1576
 	return err
1578
 }
1577
 }
1579
 
1578
 
1580
-//替换项目模板
1579
+// 替换项目模板
1581
 func ReplaceProjectPrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, s models.HisPrescriptionProjectTemplate, tx *gorm.DB) (err error) {
1580
 func ReplaceProjectPrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, s models.HisPrescriptionProjectTemplate, tx *gorm.DB) (err error) {
1582
 	err = tx.Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and "+
1581
 	err = tx.Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and "+
1583
 		"status = 1 and prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1582
 		"status = 1 and prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1599
 	return err
1598
 	return err
1600
 }
1599
 }
1601
 
1600
 
1602
-//删除项目模板
1601
+// 删除项目模板
1603
 func DeleteProjectTemplate(orgid, patient_id, drugid int64, ids []int64, tx *gorm.DB) (err error) {
1602
 func DeleteProjectTemplate(orgid, patient_id, drugid int64, ids []int64, tx *gorm.DB) (err error) {
1604
 	err = tx.Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and "+
1603
 	err = tx.Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and "+
1605
 		"prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1604
 		"prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1609
 	return err
1608
 	return err
1610
 }
1609
 }
1611
 
1610
 
1612
-//删除处方模板
1611
+// 删除处方模板
1613
 func DeletePrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, tx *gorm.DB) (err error) {
1612
 func DeletePrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, tx *gorm.DB) (err error) {
1614
 	err = tx.Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and "+
1613
 	err = tx.Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and "+
1615
 		"prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1614
 		"prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1619
 	return err
1618
 	return err
1620
 }
1619
 }
1621
 
1620
 
1622
-//根据透析模式和患者id获取该患者的处方内容
1621
+// 根据透析模式和患者id获取该患者的处方内容
1623
 func PTemplateInformation(orgid, mode_id, patient_id int64) (tmp interface{}, err error) {
1622
 func PTemplateInformation(orgid, mode_id, patient_id int64) (tmp interface{}, err error) {
1624
 	//获取处方id
1623
 	//获取处方id
1625
 	var tt []*models.HisPrescriptionTemplate
1624
 	var tt []*models.HisPrescriptionTemplate
1695
 
1694
 
1696
 }
1695
 }
1697
 
1696
 
1698
-//收尾工作
1697
+// 收尾工作
1699
 func Scavenger(orgid int64) (err error) {
1698
 func Scavenger(orgid int64) (err error) {
1700
 	//开事务
1699
 	//开事务
1701
 	tx := XTWriteDB().Begin()
1700
 	tx := XTWriteDB().Begin()
1764
 	return
1763
 	return
1765
 }
1764
 }
1766
 
1765
 
1767
-//分区和收费(患者发药
1766
+// 分区和收费(患者发药
1768
 func PartitionAndLayout(stime, etime, orgid, shift, partition int64, flist []*models.TmpPatient) (tmp []*models.TmpPatient, err error) {
1767
 func PartitionAndLayout(stime, etime, orgid, shift, partition int64, flist []*models.TmpPatient) (tmp []*models.TmpPatient, err error) {
1769
 	//获取排班
1768
 	//获取排班
1770
 	var sch []*models.XtScheduleTwo
1769
 	var sch []*models.XtScheduleTwo
1794
 	return
1793
 	return
1795
 }
1794
 }
1796
 
1795
 
1797
-//分区和收费(药品发药
1796
+// 分区和收费(药品发药
1798
 func PartitionAndLayoutDrug(deliveryway string, stime, etime, orgid, shift, partition int64, flist []*models.PatientInformation) (tmp []*models.PatientInformation, err error) {
1797
 func PartitionAndLayoutDrug(deliveryway string, stime, etime, orgid, shift, partition int64, flist []*models.PatientInformation) (tmp []*models.PatientInformation, err error) {
1799
 	//获取排班
1798
 	//获取排班
1800
 	var sch []*models.XtScheduleTwo
1799
 	var sch []*models.XtScheduleTwo
1833
 	return
1832
 	return
1834
 }
1833
 }
1835
 
1834
 
1836
-//给药途径
1835
+// 给药途径
1837
 func Administration(deliveryway string, orgid int64, flist []*models.ListOfDrugs) (tmp []*models.ListOfDrugs, err error) {
1836
 func Administration(deliveryway string, orgid int64, flist []*models.ListOfDrugs) (tmp []*models.ListOfDrugs, err error) {
1838
 	//查询药品
1837
 	//查询药品
1839
 	var pp []*models.PharmacyBaseDrug
1838
 	var pp []*models.PharmacyBaseDrug
1860
 	return
1859
 	return
1861
 }
1860
 }
1862
 
1861
 
1863
-//计算总量
1862
+// 计算总量
1864
 func CalculateTheTotalAmount(tmp []*models.PatientInformation, drug_id int64) (total string, err error) {
1863
 func CalculateTheTotalAmount(tmp []*models.PatientInformation, drug_id int64) (total string, err error) {
1865
 	//获取药品信息
1864
 	//获取药品信息
1866
 	var t models.SpBaseDrug
1865
 	var t models.SpBaseDrug