瀏覽代碼

耗材参数

XMLWAN 4 年之前
父節點
當前提交
4407b42a48

+ 1 - 0
controllers/data_api_controller.go 查看文件

@@ -990,6 +990,7 @@ func (c *DataApiController) CreateAdviceTemplate() {
990 990
 					FrequencyType:         frequency_type,
991 991
 					Way:                   way,
992 992
 					DrugId:                drug_id,
993
+					DrugNameId:            0,
993 994
 				}
994 995
 				subTemplate = append(subTemplate, subTemps)
995 996
 

+ 22 - 11
controllers/manager_center_api_controller.go 查看文件

@@ -191,7 +191,7 @@ func (c *ManagerCenterApiController) CreateBaseDrugLib() {
191 191
 func (c *ManagerCenterApiController) EditBaseDrugLib() {
192 192
 	id, _ := c.GetInt64("id")
193 193
 	drug_name := c.GetString("drug_name")
194
-	fmt.Println("drug_name--------", drug_name)
194
+
195 195
 	pinyin := c.GetString("pinyin")
196 196
 	wubi := c.GetString("wubi")
197 197
 	drug_alias := c.GetString("drug_alias")
@@ -236,7 +236,7 @@ func (c *ManagerCenterApiController) EditBaseDrugLib() {
236 236
 	is_statistics_work, _ := c.GetInt64("is_statistics_work")
237 237
 	is_charge_use, _ := c.GetInt64("is_charge_use")
238 238
 	drug_code := c.GetString("drug_code")
239
-	unit := c.GetString("unit")
239
+	//unit := c.GetString("unit")
240 240
 	adminInfo := c.GetAdminUserInfo()
241 241
 	drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, id)
242 242
 
@@ -296,7 +296,6 @@ func (c *ManagerCenterApiController) EditBaseDrugLib() {
296 296
 	err := service.UpdateBaseDrugLib(drugLib)
297 297
 
298 298
 	//修改xt_drug_name 表
299
-
300 299
 	drugName := models.XtDrugName{
301 300
 		DrugName: drug_name,
302 301
 	}
@@ -307,7 +306,7 @@ func (c *ManagerCenterApiController) EditBaseDrugLib() {
307 306
 		DrugName:       drug_name,
308 307
 		DrugSpec:       drug_spec,
309 308
 		DrugStockLimit: drug_stock_limit,
310
-		MinUnit:        unit,
309
+		MinUnit:        min_unit,
311 310
 	}
312 311
 
313 312
 	service.UpdateStandName(id, adminInfo.CurrentOrgId, &standName)
@@ -319,26 +318,27 @@ func (c *ManagerCenterApiController) EditBaseDrugLib() {
319 318
 		PrescribingNumber:  prescribing_number,
320 319
 		DeliveryWay:        delivery_way,
321 320
 		SingleDose:         single_dose,
322
-		MinUnit:            unit,
321
+		MinUnit:            min_unit,
323 322
 	}
324 323
 
325 324
 	service.UpdateSelfMedical(id, adminInfo.CurrentOrgId, &medical)
325
+
326 326
 	//修改入库表
327
-	nameId, err := service.GetDrugNameId(id, adminInfo.CurrentOrgId)
327
+	//nameId, err := service.GetDrugNameId(id, adminInfo.CurrentOrgId)
328 328
 
329 329
 	stock := models.XtSelfStock{
330 330
 		DrugSpec: drug_spec,
331 331
 		DrugName: drug_name,
332
-		MinUnit:  unit,
332
+		MinUnit:  min_unit,
333 333
 	}
334 334
 
335
-	service.UpdatedSelfStock(&stock, nameId.ID, adminInfo.CurrentOrgId)
335
+	service.UpdatedSelfStock(&stock, id, adminInfo.CurrentOrgId)
336 336
 	outStock := models.XtSelfOutStock{
337 337
 		DrugName: drug_name,
338 338
 		DrugSpec: drug_spec,
339 339
 	}
340 340
 	//修改出库表
341
-	service.UpdatedOutSelfStock(&outStock, nameId.ID, adminInfo.CurrentOrgId)
341
+	service.UpdatedOutSelfStock(&outStock, id, adminInfo.CurrentOrgId)
342 342
 
343 343
 	//查询未执行的医嘱
344 344
 	advice := models.DoctorAdvice{
@@ -347,10 +347,21 @@ func (c *ManagerCenterApiController) EditBaseDrugLib() {
347 347
 		DeliveryWay:        delivery_way,
348 348
 		ExecutionFrequency: execution_frequency,
349 349
 		SingleDose:         single_dose,
350
-		SingleDoseUnit:     unit,
350
+		SingleDoseUnit:     min_unit,
351 351
 	}
352 352
 
353
-	service.UpdateNoExcuteDoctorAdvice(nameId.ID, adminInfo.CurrentOrgId, &advice)
353
+	service.UpdateNoExcuteDoctorAdvice(id, adminInfo.CurrentOrgId, &advice)
354
+
355
+	//修改医嘱模板
356
+	template := models.DoctorAdviceTemplate{
357
+		AdviceName:         drug_name,
358
+		AdviceDesc:         drug_spec,
359
+		DeliveryWay:        delivery_way,
360
+		ExecutionFrequency: execution_frequency,
361
+		SingleDose:         single_dose,
362
+		SingleDoseUnit:     min_unit,
363
+	}
364
+	service.UpdatedDoctorAdviceTemplate(id, adminInfo.CurrentOrgId, &template)
354 365
 
355 366
 	if err == nil {
356 367
 		c.ServeSuccessJSON(map[string]interface{}{

+ 5 - 0
controllers/mobile_api_controllers/dialysis_api_controller.go 查看文件

@@ -2622,6 +2622,11 @@ func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
2622 2622
 			advice.DrugId = drug_id
2623 2623
 		}
2624 2624
 
2625
+		if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
2626
+			drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
2627
+			advice.DrugNameId = drug_name_id
2628
+		}
2629
+
2625 2630
 		if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
2626 2631
 			template_id, _ := adviceNameM["template_id"].(string)
2627 2632
 			advice.TemplateId = template_id

+ 27 - 4
controllers/mobile_api_controllers/patient_api_controller.go 查看文件

@@ -167,6 +167,7 @@ func (c *PatientApiController) EditDialysisSolution() {
167 167
 }
168 168
 
169 169
 func (c *PatientApiController) CreateDoctorAdvice() {
170
+	fmt.Println("进来了吗-----------------------------")
170 171
 	patient, _ := c.GetInt64("id", 0)
171 172
 	if patient <= 0 {
172 173
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -951,7 +952,8 @@ func (c *PatientApiController) ExecDoctorAdvice() {
951 952
 		if groupno > 0 {
952 953
 			advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
953 954
 			for _, item := range advices {
954
-				if item.ExecutionState == 2 {
955
+				fmt.Println("------------进来没有22222222", item.ExecutionState)
956
+				if item.ExecutionState == 1 {
955 957
 					prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
956 958
 					count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
957 959
 
@@ -967,7 +969,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
967 969
 					//插入自备药出库单
968 970
 					outStock := models.XtSelfOutStock{
969 971
 						DrugName:       item.AdviceName,
970
-						DrugNameId:     item.DrugId,
972
+						DrugNameId:     item.DrugNameId,
971 973
 						DrugSpec:       item.AdviceDesc,
972 974
 						OutstoreNumber: count,
973 975
 						AdminUserId:    adminUserInfo.AdminUser.Id,
@@ -988,6 +990,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
988 990
 			advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
989 991
 			for _, item := range advices {
990 992
 				if item.ExecutionState == 1 {
993
+
991 994
 					prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
992 995
 					count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
993 996
 
@@ -1003,7 +1006,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1003 1006
 					//插入自备药出库单
1004 1007
 					outStock := models.XtSelfOutStock{
1005 1008
 						DrugName:       item.AdviceName,
1006
-						DrugNameId:     item.DrugId,
1009
+						DrugNameId:     item.DrugNameId,
1007 1010
 						DrugSpec:       item.AdviceDesc,
1008 1011
 						OutstoreNumber: count,
1009 1012
 						AdminUserId:    adminUserInfo.AdminUser.Id,
@@ -2355,6 +2358,16 @@ func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (co
2355 2358
 		}
2356 2359
 	}
2357 2360
 
2361
+	if dataBody["drug_name_id"] == nil {
2362
+		advice.DrugNameId = 0
2363
+	} else {
2364
+		if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
2365
+			drug_name_id := int64(dataBody["drug_name_id"].(float64))
2366
+			advice.DrugNameId = drug_name_id
2367
+			fmt.Println("0000000000", advice.DrugNameId)
2368
+		}
2369
+	}
2370
+
2358 2371
 	if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
2359 2372
 		singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
2360 2373
 		advice.SingleDose = singleDose
@@ -2766,7 +2779,7 @@ func (c *PatientApiController) GetPrintDialysisOrder() {
2766 2779
 
2767 2780
 func (c *PatientApiController) CreateGroupAdvice() {
2768 2781
 	is_child, _ := c.GetInt64("is_child", 0)
2769
-
2782
+	fmt.Println("is_child------------------------------", is_child)
2770 2783
 	if is_child == 1 {
2771 2784
 		patient, _ := c.GetInt64("id", 0)
2772 2785
 		if patient <= 0 {
@@ -2890,6 +2903,7 @@ func (c *PatientApiController) CreateGroupAdvice() {
2890 2903
 			advice.PatientId = patientInfo.ID
2891 2904
 			advice.AdviceDoctor = adminUserInfo.AdminUser.Id
2892 2905
 
2906
+			//入口
2893 2907
 			errcode := c.setAdviceWithJSON(&advice, adviceNameM)
2894 2908
 			if errcode > 0 {
2895 2909
 				c.ServeFailJSONWithSGJErrorCode(errcode)
@@ -3080,6 +3094,15 @@ func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, jso
3080 3094
 		}
3081 3095
 	}
3082 3096
 
3097
+	if json["drug_name_id"] == nil {
3098
+		advice.DrugNameId = 0
3099
+	} else {
3100
+		if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
3101
+			drug_name_id := int64(json["drug_name_id"].(float64))
3102
+			advice.DrugNameId = drug_name_id
3103
+		}
3104
+	}
3105
+
3083 3106
 	if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
3084 3107
 		drugSpecUnit, _ := json["drug_spec_unit"].(string)
3085 3108
 		advice.DrugSpecUnit = drugSpecUnit

+ 5 - 0
controllers/patient_api_controller.go 查看文件

@@ -1238,6 +1238,11 @@ func (c *PatientApiController) CreateGroupAdvice() {
1238 1238
 			advice.DrugId = drug_id
1239 1239
 		}
1240 1240
 
1241
+		if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
1242
+			drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
1243
+			advice.DrugNameId = drug_name_id
1244
+		}
1245
+
1241 1246
 		if adviceType == 1 {
1242 1247
 
1243 1248
 			if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {

+ 19 - 6
controllers/self_drug_api_congtroller.go 查看文件

@@ -186,14 +186,23 @@ func (this *SelfDrugApiController) SaveRulleName() {
186 186
 		DrugId:         drug_id,
187 187
 	}
188 188
 
189
-	err := service.SaveRulleName(&drugSpecName)
190
-	if err != nil {
191
-		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
189
+	//查询该机构下药品规格名称是否存在
190
+	_, errcode := service.IsExistStandName(drug_name, drug_spec, adminUserInfo.CurrentOrgId)
191
+
192
+	if errcode == gorm.ErrRecordNotFound {
193
+		err := service.SaveRulleName(&drugSpecName)
194
+		if err != nil {
195
+			this.ServeFailJsonSend(enums.ErrorCodeDataException, "创建规格失败")
196
+			return
197
+		}
198
+		this.ServeSuccessJSON(map[string]interface{}{
199
+			"RullerName": drugSpecName,
200
+		})
201
+	} else if errcode == nil {
202
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "规格已存在")
192 203
 		return
193 204
 	}
194
-	this.ServeSuccessJSON(map[string]interface{}{
195
-		"RullerName": drugSpecName,
196
-	})
205
+
197 206
 }
198 207
 
199 208
 func (this *SelfDrugApiController) EditRullerName() {
@@ -566,6 +575,9 @@ func (this *SelfDrugApiController) GetStockList() {
566 575
 	stocklist, err := service.GetStockList(patientid, startimeUnix, keyword, orgId)
567 576
 	//统计出库数量
568 577
 	outStocklist, err := service.GetOutStockList(patientid, startimeUnix, keyword, orgId)
578
+
579
+	//统计该病人时间段内出库条数
580
+	outList, err := service.GetTotalOutStockList(patientid, startimeUnix, keyword, orgId)
569 581
 	if err != nil {
570 582
 		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
571 583
 		return
@@ -574,6 +586,7 @@ func (this *SelfDrugApiController) GetStockList() {
574 586
 		"medicalList":  medicalList,
575 587
 		"stocklist":    stocklist,
576 588
 		"outStocklist": outStocklist,
589
+		"outList":      outList,
577 590
 	})
578 591
 }
579 592
 

+ 1 - 0
models/dialysis.go 查看文件

@@ -395,6 +395,7 @@ type DoctorAdvice struct {
395 395
 	IsCheck               int64           `gorm:"-" json:"is_check" form:"is_check"`
396 396
 	Way                   int64           `gorm:"column:way" json:"way" form:"way"`
397 397
 	DrugId                int64           `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
398
+	DrugNameId            int64           `gorm:"column:drug_name_id" json:"drug_name_id" form:"drug_name_id"`
398 399
 }
399 400
 
400 401
 func (DoctorAdvice) TableName() string {

+ 1 - 0
models/doctor_advice_models.go 查看文件

@@ -74,6 +74,7 @@ type DoctorAdviceTemplate struct {
74 74
 	FrequencyType           int64                   `gorm:"column:frequency_type" json:"frequency_type"`
75 75
 	DrugId                  int64                   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
76 76
 	Way                     int64                   `gorm:"column:way" json:"way" form:"way"`
77
+	DrugNameId              int64                   `gorm:"column:drug_name_id" json:"drug_name_id" form:"drug_name_id"`
77 78
 	SubDoctorAdviceTemplate []*DoctorAdviceTemplate `gorm:"ForeignKey:ParentId;AssociationForeignKey:ID" json:"child"`
78 79
 }
79 80
 

+ 1 - 1
service/doctor_advice_service.go 查看文件

@@ -204,7 +204,7 @@ func FindDoctorAdviceTemplateById(id int64, org_id int64) (temps models.DoctorAd
204 204
 
205 205
 func FindAllAdviceTemplate(org_id int64, advice_type int64) (temps []*models.DoctorAdviceParentTemplate, err error) {
206 206
 	err = readDb.Model(&models.DoctorAdviceParentTemplate{}).Preload("DoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
207
-		return db.Select("id,advice_name,advice_desc,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,status,created_time,updated_time,parent_id,template_id,drug_spec,drug_spec_unit,advice_type,day_count,week_days,frequency_type,way,drug_id, IF(parent_id>0, parent_id, id) as advice_order").Where("status = 1").Order("advice_order desc, id")
207
+		return db.Select("id,advice_name,advice_desc,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,status,created_time,updated_time,parent_id,template_id,drug_spec,drug_spec_unit,advice_type,day_count,week_days,frequency_type,way,drug_id,drug_name_id, IF(parent_id>0, parent_id, id) as advice_order").Where("status = 1").Order("advice_order desc, id")
208 208
 	}).Where("org_id = ? AND status=1 AND advice_type = ?", org_id, advice_type).Find(&temps).Error
209 209
 	return
210 210
 }

+ 2 - 2
service/mobile_dialysis_service.go 查看文件

@@ -491,7 +491,7 @@ func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*
491 491
 	err := readDb.
492 492
 		Model(&models.DoctorAdvice{}).
493 493
 		Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientID, orgID, recordDate).
494
-		Select("id,user_org_id,patient_id,advice_type,advice_date,record_date,start_time,advice_name,advice_desc,reminder_date, drug_spec, drug_spec_unit,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,advice_doctor,status,created_time,updated_time,advice_affirm,remark,stop_time,stop_reason,stop_doctor,stop_state,parent_id,execution_time,execution_staff,execution_state,checker, check_state, check_time,way,drug_id,IF(parent_id>0, parent_id, id) as advice_order,groupno").
494
+		Select("id,user_org_id,patient_id,advice_type,advice_date,record_date,start_time,advice_name,advice_desc,reminder_date, drug_spec, drug_spec_unit,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,advice_doctor,status,created_time,updated_time,advice_affirm,remark,stop_time,stop_reason,stop_doctor,stop_state,parent_id,execution_time,execution_staff,execution_state,checker, check_state, check_time,way,drug_id,drug_name_id,IF(parent_id>0, parent_id, id) as advice_order,groupno").
495 495
 		Order("start_time asc, groupno desc, advice_order desc, id").
496 496
 		Scan(&records).Error
497 497
 
@@ -508,7 +508,7 @@ func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int
508 508
 	err := readDb.
509 509
 		Model(&models.DoctorAdvice{}).
510 510
 		Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and advice_type = 2", patientID, orgID, recordDate).
511
-		Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, single_dose, single_dose_unit, prescribing_number, prescribing_number_unit, delivery_way, execution_frequency, advice_doctor, status, created_time,updated_time, advice_affirm, remark, stop_time, stop_reason, stop_doctor, stop_state, parent_id, execution_time, execution_staff, execution_state, checker, check_state, check_time, groupno,way,drug_id, IF(parent_id > 0, parent_id, id) as advice_order").
511
+		Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, single_dose, single_dose_unit, prescribing_number, prescribing_number_unit, delivery_way, execution_frequency, advice_doctor, status, created_time,updated_time, advice_affirm, remark, stop_time, stop_reason, stop_doctor, stop_state, parent_id, execution_time, execution_staff, execution_state, checker, check_state, check_time, groupno,way,drug_id,drug_name_id, IF(parent_id > 0, parent_id, id) as advice_order").
512 512
 		Order("start_time asc, groupno desc, advice_order desc, id asc").
513 513
 		Scan(&records).Error
514 514
 

+ 39 - 3
service/self_drug_service.go 查看文件

@@ -68,6 +68,18 @@ func GetUnitByBaseId(id int64) (models.XtBaseDrug, error) {
68 68
 	return drug, err
69 69
 }
70 70
 
71
+func IsExistStandName(drugname string, drugspec string, orgid int64) (*models.XtStandName, error) {
72
+	standName := models.XtStandName{}
73
+	err := XTReadDB().Model(&standName).Where("drug_name = ? and drug_spec = ? and user_org_id = ? and status = 1", drugname, drugspec, orgid).Find(&standName).Error
74
+	if err == gorm.ErrRecordNotFound {
75
+		return nil, err
76
+	}
77
+	if err != nil {
78
+		return nil, err
79
+	}
80
+	return &standName, nil
81
+}
82
+
71 83
 func SaveRulleName(rullName *models.XtStandName) error {
72 84
 
73 85
 	err := XTWriteDB().Model(&rullName).Create(&rullName).Error
@@ -263,6 +275,24 @@ func GetOutStockList(patientid int64, startime int64, keyword string, orgid int6
263 275
 	return outStock, err
264 276
 }
265 277
 
278
+func GetTotalOutStockList(patientid int64, startime int64, keyword string, orgid int64) (outStock []*models.SelfOutStock, err error) {
279
+
280
+	likeKey := "%" + keyword + "%"
281
+	db := XTReadDB().Table("xt_self_out_stock as x").Where("x.status = 1")
282
+	if patientid > 0 {
283
+		db = db.Where("x.patient_id = ?", patientid)
284
+	}
285
+	if orgid > 0 {
286
+		db = db.Where("x.user_org_id = ?", orgid)
287
+	}
288
+	if startime > 0 {
289
+		db = db.Where("x.storck_time<=?", startime)
290
+	}
291
+
292
+	err = db.Select("x.id,x.drug_name,x.drug_name_id,x.drug_spec,x.remarks,x.outstore_number,x.admin_user_id,x.storck_time,x.user_org_id,x.patient_id,x.exit_mode,x.medic_id").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.name like ? or s.dialysis_no like ?", likeKey, likeKey).Find(&outStock).Error
293
+	return outStock, err
294
+}
295
+
266 296
 //func GetOutStockList(patientid int64, startime int64, keyword string) (outStock []*models.XtSelfOutStocks, err error) {
267 297
 //	db := XTReadDB().Table("xt_self_out_stock as x").Where("x.status = 1")
268 298
 //	likeKey := "%" + keyword + "%"
@@ -337,7 +367,7 @@ func GetAllPatientStockList(drug_name string, drug_spec string, startime int64,
337 367
 	if orgid > 0 {
338 368
 		db = db.Where("x.user_org_id = ?", orgid)
339 369
 	}
340
-	err = db.Group("x.patient_id,x.drug_name,x.drug_spec").Select("x.drug_name,x.drug_spec,x.patient_id,x.store_number,sum(x.store_number) as total,s.name,s.dialysis_no,x.min_unit").Joins("left join xt_patients as  s on s.id = x.patient_id").Where("s.name like ? or s.dialysis_no like ?", likeKey, likeKey).Scan(&stocks).Error
370
+	err = db.Group("x.patient_id,x.drug_name,x.drug_spec").Select("t.drug_name,t.drug_spec,x.patient_id,x.store_number,sum(x.store_number) as total,s.name,s.dialysis_no,x.min_unit").Joins("left join xt_patients as  s on s.id = x.patient_id").Joins("left join xt_self_medical as t on t.id = x.medic_id").Where("s.name like ? or s.dialysis_no like ?", likeKey, likeKey).Scan(&stocks).Error
341 371
 	return stocks, err
342 372
 }
343 373
 
@@ -578,13 +608,13 @@ func GetDrugNameId(id int64, orgid int64) (models.XtSelfMedical, error) {
578 608
 }
579 609
 
580 610
 func UpdatedSelfStock(stock *models.XtSelfStock, id int64, orgid int64) error {
581
-	err := XTWriteDB().Model(&stock).Where("medic_id=? and user_org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"drug_name": stock.DrugName, "min_unit": stock.MinUnit, "drug_spec": stock.DrugSpec}).Error
611
+	err := XTWriteDB().Model(&stock).Where("drug_name_id=? and user_org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"drug_name": stock.DrugName, "min_unit": stock.MinUnit, "drug_spec": stock.DrugSpec}).Error
582 612
 	return err
583 613
 }
584 614
 
585 615
 func UpdatedOutSelfStock(stock *models.XtSelfOutStock, id int64, orgid int64) error {
586 616
 
587
-	err := XTWriteDB().Model(&stock).Where("medic_id = ? and user_org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"drug_name": stock.DrugName, "drug_spec": stock.DrugName}).Error
617
+	err := XTWriteDB().Model(&stock).Where("drug_name_id = ? and user_org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"drug_name": stock.DrugName, "drug_spec": stock.DrugSpec}).Error
588 618
 	return err
589 619
 }
590 620
 
@@ -593,3 +623,9 @@ func UpdateNoExcuteDoctorAdvice(id int64, orgid int64, advice *models.DoctorAdvi
593 623
 	err := XTWriteDB().Model(&advice).Where("drug_id = ? and user_org_id = ? and status = 1 and  execution_state = 2", id, orgid).Updates(map[string]interface{}{"advice_name": advice.AdviceName, "advice_desc": advice.AdviceDesc, "single_dose": advice.SingleDose, "single_dose_unit": advice.SingleDoseUnit, "delivery_way": advice.DeliveryWay, "execution_frequency": advice.ExecutionFrequency}).Error
594 624
 	return err
595 625
 }
626
+
627
+func UpdatedDoctorAdviceTemplate(id int64, orgid int64, template *models.DoctorAdviceTemplate) error {
628
+
629
+	err := XTWriteDB().Model(&template).Where("drug_id = ? and org_id = ? and status = 1", id, orgid).Updates(map[string]interface{}{"advice_name": template.AdviceName, "advice_desc": template.AdviceDesc, "single_dose": template.SingleDose, "single_dose_unit": template.SingleDoseUnit, "delivery_way": template.DeliveryWay, "execution_frequency": template.ExecutionFrequency}).Error
630
+	return err
631
+}