Browse Source

11月8日库存管理

XMLWAN 2 years ago
parent
commit
947e24540b

+ 1 - 1
conf/app.conf View File

@@ -1,5 +1,5 @@
1 1
 appname = 血透
2
-httpport = 9529
2
+httpport = 9531
3 3
 runmode = dev
4 4
 
5 5
 #

+ 32 - 0
controllers/gobal_config_api_controller.go View File

@@ -114,6 +114,8 @@ func GobalConfigRegistRouters() {
114 114
 	beego.Router("/api/drug/getcancelstockdetail", &GobalConfigApiController{}, "Get:GetCancelStockDetail")
115 115
 
116 116
 	beego.Router("/api/changestocksetting/isopen", &GobalConfigApiController{}, "Get:ChangeStockSetting")
117
+
118
+	beego.Router("/api/changeadviceconfig", &GobalConfigApiController{}, "Get:ChangeAdviceConfig")
117 119
 }
118 120
 
119 121
 //provinces, _ := service.GetDistrictsByUpid(0)21
@@ -1560,10 +1562,12 @@ func (c *GobalConfigApiController) GetAllIsOpenConfig() {
1560 1562
 	_, project_config := service.FindXTHisProjectByOrgIdOne(adminUserInfo.CurrentOrgId)
1561 1563
 
1562 1564
 	stockSetting, _ := service.FindStockSettingById(adminUserInfo.CurrentOrgId)
1565
+	adviceSetting, _ := service.FindAdviceSettingById(adminUserInfo.CurrentOrgId)
1563 1566
 	c.ServeSuccessJSON(map[string]interface{}{
1564 1567
 		"is_open_xt_his":         config.IsOpen,
1565 1568
 		"is_open_xt_his_project": project_config.IsOpen,
1566 1569
 		"is_open_stock":          stockSetting.IsType,
1570
+		"is_open_advice":         adviceSetting.IsAdviceOpen,
1567 1571
 	})
1568 1572
 
1569 1573
 }
@@ -2363,3 +2367,31 @@ func (c *GobalConfigApiController) ChangeStockSetting() {
2363 2367
 		})
2364 2368
 	}
2365 2369
 }
2370
+
2371
+func (c *GobalConfigApiController) ChangeAdviceConfig() {
2372
+
2373
+	is_advice_open, _ := c.GetInt64("is_advice_open")
2374
+	orgId := c.GetAdminUserInfo().CurrentOrgId
2375
+	setting := models.XtAdviceSetting{
2376
+		IsAdviceOpen: is_advice_open,
2377
+		UserOrgId:    orgId,
2378
+		Status:       1,
2379
+		Ctime:        time.Now().Unix(),
2380
+		Mtime:        0,
2381
+	}
2382
+
2383
+	//查询是否存在
2384
+	_, errcode := service.GetAdviceConfig(orgId)
2385
+	if errcode == gorm.ErrRecordNotFound {
2386
+		service.CreateAdviceSetting(setting)
2387
+		c.ServeSuccessJSON(map[string]interface{}{
2388
+			"msg": 1,
2389
+		})
2390
+	} else if errcode == nil {
2391
+		service.UpdateAdviceSetting(orgId, setting)
2392
+		c.ServeSuccessJSON(map[string]interface{}{
2393
+			"msg": 1,
2394
+		})
2395
+	}
2396
+
2397
+}

+ 21 - 4
controllers/his_api_controller.go View File

@@ -2887,8 +2887,7 @@ func (c *HisApiController) CreateHisPatientCaseHistory() {
2887 2887
 
2888 2888
 	sick, _ := c.GetInt64("sick")
2889 2889
 	diagnose, _ := c.GetInt64("diagnose")
2890
-	id, _ := c.GetInt64("id")
2891
-
2890
+	//id, _ := c.GetInt64("id")
2892 2891
 	timeLayout := "2006-01-02"
2893 2892
 	loc, _ := time.LoadLocation("Local")
2894 2893
 	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
@@ -2906,6 +2905,14 @@ func (c *HisApiController) CreateHisPatientCaseHistory() {
2906 2905
 	}
2907 2906
 	sickTimes := sickTime.Unix()
2908 2907
 	ctime := time.Now().Unix()
2908
+
2909
+	primary_disease := c.GetString("primary_disease")
2910
+	confirm_failure_date := c.GetString("confirm_failure_date")
2911
+	confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
2912
+	drug_allergy_history := c.GetString("drug_allergy_history")
2913
+	physical_examination := c.GetString("physical_examination")
2914
+	special_inspection := c.GetString("special_inspection")
2915
+	lab_apparatus := c.GetString("lab_apparatus")
2909 2916
 	caseHistory := models.HisPatientCaseHistory{
2910 2917
 		HisPatientId:            his_patient_id,
2911 2918
 		PatientId:               patient_id,
@@ -2939,27 +2946,37 @@ func (c *HisApiController) CreateHisPatientCaseHistory() {
2939 2946
 		Sick:                    sick,
2940 2947
 		Diagnose:                diagnose,
2941 2948
 		AllergicHistory:         allergic_history,
2949
+		PrimaryDisease:          primary_disease,
2950
+		ConfirmFailureDate:      confirm_failure_date_time.Unix(),
2951
+		DrugAllergyHistory:      drug_allergy_history,
2952
+		PhysicalExamination:     physical_examination,
2953
+		SpecialInspection:       special_inspection,
2954
+		LabApparatus:            lab_apparatus,
2942 2955
 	}
2943 2956
 	//查询该患者是否有病历
2944
-	_, errcodes := service.GetHisPatientCaseHistoryById(id)
2957
+	_, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
2945 2958
 	if errcodes == gorm.ErrRecordNotFound {
2946 2959
 		err = service.SaveHisPatientCaseHistory(&caseHistory)
2960
+		historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
2947 2961
 		if err != nil {
2948 2962
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
2949 2963
 			return
2950 2964
 		}
2951 2965
 		c.ServeSuccessJSON(map[string]interface{}{
2952 2966
 			"caseHistory": caseHistory,
2967
+			"historyInfo": historyInfo,
2953 2968
 		})
2954 2969
 		return
2955 2970
 	} else if errcodes == nil {
2956
-		err := service.UpdatePatientCaseHistory(id, &caseHistory)
2971
+		err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
2972
+		historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
2957 2973
 		if err != nil {
2958 2974
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
2959 2975
 			return
2960 2976
 		}
2961 2977
 		c.ServeSuccessJSON(map[string]interface{}{
2962 2978
 			"caseHistory": caseHistory,
2979
+			"historyInfo": historyInfo,
2963 2980
 		})
2964 2981
 	}
2965 2982
 

+ 1 - 0
controllers/mobile_api_controllers/dialysis_api_controller.go View File

@@ -405,6 +405,7 @@ func (this *DialysisAPIController) DialysisRecord() {
405 405
 	schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
406 406
 	go func() {
407 407
 		patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
408
+		fmt.Println("patient23333223322323", patient.TrobleShoot)
408 409
 		ch <- struct{}{}
409 410
 	}()
410 411
 

+ 2 - 1
controllers/mobile_api_controllers/mobile_api_base_controller.go View File

@@ -53,7 +53,8 @@ type MobileBaseAPIAuthController struct {
53 53
 func (this *MobileBaseAPIAuthController) Prepare() {
54 54
 	token := this.Ctx.GetCookie("token_cookie")
55 55
 	logout_cookie := this.Ctx.GetCookie("logout_cookie")
56
-
56
+	fmt.Println("token232232232323232332232332323322332232323", token)
57
+	fmt.Println("login232232232323232332232332323322332232323", logout_cookie)
57 58
 	//if len(token) == 0{
58 59
 	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
59 60
 	//	this.StopRun()

+ 1 - 1
controllers/patient_api_controller.go View File

@@ -734,7 +734,7 @@ func (c *PatientApiController) EditLapseto() {
734 734
 
735 735
 	err = service.EditPatientLapseto(&patient, &lapseto)
736 736
 
737
-	if lapseto.LapsetoType == 3 {
737
+	if lapseto.LapsetoType == 3 || lapseto.LapsetoType == 2 {
738 738
 		service.UpdateScheduleByDeathTime(id, lapsetoTimeUnix.Unix())
739 739
 		service.UpdateScheduleItemByPatientId(id)
740 740
 	}

+ 1 - 1
controllers/schedule_api_controller.go View File

@@ -1436,7 +1436,7 @@ func (this *ScheduleApiController) ExportSchedule() {
1436 1436
 			if err == nil {
1437 1437
 				for _, item := range schedules {
1438 1438
 					if item.ScheduleDate > clear_schedule_date {
1439
-						//查询已经存在的所有排班
1439
+						//查询该患者是否转出获取死亡
1440 1440
 
1441 1441
 						//查找当天日期是否存在
1442 1442
 						_, errcode := service.GetTodayScheduleIsExistOne(item.PatientId, item.ScheduleDate, item.UserOrgId)

+ 15 - 0
models/his_models.go View File

@@ -174,6 +174,15 @@ type HisCaseHistoryTemplate struct {
174 174
 	UserName                string `gorm:"column:user_name" json:"user_name" form:"user_name"`
175 175
 	DoctorAdvice            string `gorm:"column:doctor_advice" json:"doctor_advice" form:"doctor_advice"`
176 176
 	Remark                  string `gorm:"column:remark" json:"remark" form:"remark"`
177
+	Sick                    int64  `gorm:"column:sick" json:"sick" form:"sick"`
178
+	Diagnose                int64  `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
179
+	AllergicHistory         string `gorm:"column:allergic_history" json:"allergic_history" form:"allergic_history"`
180
+	PrimaryDisease          string `gorm:"column:primary_disease" json:"primary_disease" form:"primary_disease"`
181
+	ConfirmFailureDate      int64  `gorm:"column:confirm_failure_date" json:"confirm_failure_date" form:"confirm_failure_date"`
182
+	DrugAllergyHistory      string `gorm:"column:drug_allergy_history" json:"drug_allergy_history" form:"drug_allergy_history"`
183
+	PhysicalExamination     string `gorm:"column:physical_examination" json:"physical_examination" form:"physical_examination"`
184
+	SpecialInspection       string `gorm:"column:special_inspection" json:"special_inspection" form:"special_inspection"`
185
+	LabApparatus            string `gorm:"column:lab_apparatus" json:"lab_apparatus" form:"lab_apparatus"`
177 186
 }
178 187
 
179 188
 func (HisCaseHistoryTemplate) TableName() string {
@@ -370,6 +379,12 @@ type HisPatientCaseHistory struct {
370 379
 	Sick                    int64   `gorm:"column:sick" json:"sick" form:"sick"`
371 380
 	Diagnose                int64   `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
372 381
 	AllergicHistory         string  `gorm:"column:allergic_history" json:"allergic_history" form:"allergic_history"`
382
+	PrimaryDisease          string  `gorm:"column:primary_disease" json:"primary_disease" form:"primary_disease"`
383
+	ConfirmFailureDate      int64   `gorm:"column:confirm_failure_date" json:"confirm_failure_date" form:"confirm_failure_date"`
384
+	DrugAllergyHistory      string  `gorm:"column:drug_allergy_history" json:"drug_allergy_history" form:"drug_allergy_history"`
385
+	PhysicalExamination     string  `gorm:"column:physical_examination" json:"physical_examination" form:"physical_examination"`
386
+	SpecialInspection       string  `gorm:"column:special_inspection" json:"special_inspection" form:"special_inspection"`
387
+	LabApparatus            string  `gorm:"column:lab_apparatus" json:"lab_apparatus" form:"lab_apparatus"`
373 388
 }
374 389
 
375 390
 func (HisPatientCaseHistory) TableName() string {

+ 13 - 0
models/stock_models.go View File

@@ -1345,3 +1345,16 @@ type XtStockSetting struct {
1345 1345
 func (XtStockSetting) TableName() string {
1346 1346
 	return "xt_stock_setting"
1347 1347
 }
1348
+
1349
+type XtAdviceSetting struct {
1350
+	ID           int64 `gorm:"column:id" json:"id" form:"id"`
1351
+	IsAdviceOpen int64 `gorm:"column:is_advice_open" json:"is_advice_open" form:"is_advice_open"`
1352
+	UserOrgId    int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1353
+	Status       int64 `gorm:"column:status" json:"status" form:"status"`
1354
+	Ctime        int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
1355
+	Mtime        int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
1356
+}
1357
+
1358
+func (XtAdviceSetting) TableName() string {
1359
+	return "xt_advice_setting"
1360
+}

+ 12 - 5
service/his_service.go View File

@@ -335,7 +335,7 @@ func GetXTPatientInfo(org_id int64, patient_id int64) (info models.Patients, err
335 335
 }
336 336
 
337 337
 func GetHisPatientCaseHistoryInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatientCaseHistory, err error) {
338
-	err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
338
+	err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Last(&info).Error
339 339
 	return
340 340
 }
341 341
 
@@ -372,9 +372,9 @@ func SaveHisPatientCaseHistoryTemplate(template models.HisCaseHistoryTemplate) (
372 372
 	return
373 373
 }
374 374
 
375
-func GetHisPatientCaseHistoryById(id int64) (*models.HisPatientCaseHistory, error) {
375
+func GetHisPatientCaseHistoryById(patient_id int64, record_date int64, user_org_id int64) (*models.HisPatientCaseHistory, error) {
376 376
 	history := models.HisPatientCaseHistory{}
377
-	err := XTReadDB().Model(&history).Where("id = ? and status = 1", id).Find(&history).Error
377
+	err := XTReadDB().Model(&history).Where("patient_id = ? and status = 1 and user_org_id = ? and record_date = ?", patient_id, user_org_id, record_date).Find(&history).Error
378 378
 	if err != nil {
379 379
 		if err == gorm.ErrRecordNotFound {
380 380
 			return nil, err
@@ -385,14 +385,21 @@ func GetHisPatientCaseHistoryById(id int64) (*models.HisPatientCaseHistory, erro
385 385
 	return &history, nil
386 386
 }
387 387
 
388
+func GetLastHisPatientCaseHistoryById(patient_id int64) (models.HisPatientCaseHistory, error) {
389
+	history := models.HisPatientCaseHistory{}
390
+	err := XTReadDB().Model(&history).Where("patient_id = ? and status = 1", patient_id).Last(&history).Error
391
+	return history, err
392
+}
393
+
388 394
 func SaveHisPatientCaseHistory(caseHistory *models.HisPatientCaseHistory) error {
389 395
 	err := writeDb.Create(&caseHistory).Error
390 396
 	return err
391 397
 }
392 398
 
393
-func UpdatePatientCaseHistory(id int64, his *models.HisPatientCaseHistory) error {
399
+func UpdatePatientCaseHistory(patient_id int64, record_date int64, user_org_id int64, his *models.HisPatientCaseHistory) error {
400
+
401
+	err := XTWriteDB().Model(&his).Where("patient_id = ? and record_date = ? and user_org_id = ? and status  =1", patient_id, record_date, user_org_id).Updates(map[string]interface{}{"temperature": his.Temperature, "blood_sugar": his.BloodSugar, "pulse": his.Pulse, "allergic_history": his.AllergicHistory, "diagnose": his.AllergicHistory, "sick": his.Sick, "remark": his.Remark, "doctor_advice": his.DoctorAdvice, "breathing": his.Breathing, "delivery_way": his.DeliveryWay, "diagnostic": his.Diagnostic, "family_history": his.FamilyHistory, "personal_history": his.PersonalHistory, "chief_conplaint": his.ChiefConplaint, "doctor": his.Doctor, "past_history": his.PastHistory, "history_of_present_illness": his.HistoryOfPresentIllness, "is_infect": his.IsInfect, "sick_date": his.SickDate, "symptom": his.Symptom, "sick_type": his.SickType, "blood_fat": his.BloodFat, "sbp": his.Sbp, "dbp": his.Dbp, "primary_disease": his.PrimaryDisease, "confirm_failure_date": his.ConfirmFailureDate, "drug_allergy_history": his.DrugAllergyHistory, "physical_examination": his.PhysicalExamination, "special_inspection": his.SpecialInspection, "lab_apparatus": his.LabApparatus}).Error
394 402
 
395
-	err := XTWriteDB().Model(&his).Where("id = ? and status  =1", id).Updates(map[string]interface{}{"temperature": his.Temperature, "blood_sugar": his.BloodSugar, "pulse": his.Pulse, "allergic_history": his.AllergicHistory, "diagnose": his.AllergicHistory, "sick": his.Sick, "remark": his.Remark, "doctor_advice": his.DoctorAdvice, "breathing": his.Breathing, "delivery_way": his.DeliveryWay, "diagnostic": his.Diagnostic, "family_history": his.FamilyHistory, "personal_history": his.PersonalHistory, "chief_conplaint": his.ChiefConplaint, "doctor": his.Doctor, "past_history": his.PastHistory, "history_of_present_illness": his.HistoryOfPresentIllness, "is_infect": his.IsInfect, "sick_date": his.SickDate, "symptom": his.Symptom, "sick_type": his.SickType, "blood_fat": his.BloodFat, "sbp": his.Sbp, "dbp": his.Dbp}).Error
396 403
 	return err
397 404
 }
398 405
 

+ 1 - 1
service/patient_service.go View File

@@ -533,7 +533,7 @@ func FindPatientByIdWithDiseases(orgID int64, id int64) (patient models.Patients
533 533
 	key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(id, 10) + ":patient_info"
534 534
 
535 535
 	patient_info_str, _ := redis.Get(key).Result()
536
-
536
+	fmt.Println("patient_info_stre223322323232323323223", patient_info_str)
537 537
 	if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
538 538
 		err = readDb.Model(&models.Patients{}).Preload("Contagions", "status = 1").Preload("Diseases", "status = 1").Where("id = ? and user_org_id=? and status=1", id, orgID).First(&patient).Error
539 539
 		if err != nil {

+ 36 - 5
service/stock_service.go View File

@@ -1127,7 +1127,7 @@ func FindDrugWarehousingInfoByIdOne(id []string, org_id int64) (list []*models.S
1127 1127
 	if org_id > 0 {
1128 1128
 		db = db.Where("x.org_id = ?", org_id)
1129 1129
 	}
1130
-	err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.remark,x.batch_number,x.batch_number,t.manufacturer,t.dealer,t.drug_name,t.last_price,t.dose_unit,t.dose,t.min_number,t.min_unit,t.max_unit,t.drug_type").Joins("left join xt_base_drug as t on t.id = x.drug_id").Scan(&list).Error
1130
+	err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.remark,x.batch_number,x.batch_number,x.manufacturer,x.dealer,t.drug_name,t.last_price,t.dose_unit,t.dose,t.min_number,t.min_unit,t.max_unit,t.drug_type").Joins("left join xt_base_drug as t on t.id = x.drug_id").Scan(&list).Error
1131 1131
 	return list, err
1132 1132
 }
1133 1133
 
@@ -6345,7 +6345,7 @@ func GetDrugDetailSummary(startime int64, endtime int64, keyword string, limit i
6345 6345
 
6346 6346
 	if len(keyword) > 0 {
6347 6347
 		likeKey := "%" + keyword + "%"
6348
-		db = db.Select("x.patient_id,x.user_org_id,x.id,x.advice_date,x.advice_date,x.prescribing_number_unit,x.drug_id").Joins("left join sgj_xt.xt_base_drug as d on d.id = x.drug_id").Where("d.drug_name like ?", likeKey)
6348
+		db = db.Select("x.patient_id,x.user_org_id,x.id,x.advice_date,x.advice_date,x.prescribing_number_unit,x.drug_id,x.prescribing_number").Joins("left join sgj_xt.xt_base_drug as d on d.id = x.drug_id").Where("d.drug_name like ?", likeKey)
6349 6349
 	}
6350 6350
 
6351 6351
 	offset := (page - 1) * limit
@@ -6372,7 +6372,7 @@ func GetDrugDetailSummaryOne(startime int64, endtime int64, keyword string, limi
6372 6372
 
6373 6373
 	if len(keyword) > 0 {
6374 6374
 		likeKey := "%" + keyword + "%"
6375
-		db = db.Select("x.patient_id,x.user_org_id,x.id,x.advice_date,x.advice_date,x.prescribing_number_unit,x.drug_id").Joins("left join sgj_xt.xt_base_drug as d on d.id = x.drug_id").Where("d.drug_name like ?", likeKey)
6375
+		db = db.Select("x.patient_id,x.user_org_id,x.id,x.advice_date,x.advice_date,x.prescribing_number_unit,x.drug_id,x.prescribing_number").Joins("left join sgj_xt.xt_base_drug as d on d.id = x.drug_id").Where("d.drug_name like ?", likeKey)
6376 6376
 	}
6377 6377
 
6378 6378
 	err = db.Order("x.created_time desc").Scan(&adviceinfo).Error
@@ -6403,7 +6403,7 @@ func GetGoodDetailSummary(startime int64, endtime int64, keyword string, limit i
6403 6403
 
6404 6404
 	if len(keyword) > 0 {
6405 6405
 		likeKey := "%" + keyword + "%"
6406
-		db = db.Select("x.id,x.project_id,x.user_org_id,x.patient_id,x.record_date").Joins("left join xt_good_information as d on d.id = x.project_id").Where("d.good_name like ?", likeKey).Group("d.id")
6406
+		db = db.Select("x.id,x.project_id,x.user_org_id,x.patient_id,x.record_date,x.count").Joins("left join xt_good_information as d on d.id = x.project_id").Where("d.good_name like ?", likeKey).Group("d.id")
6407 6407
 	}
6408 6408
 
6409 6409
 	offset := (page - 1) * limit
@@ -6429,7 +6429,7 @@ func GetGoodDetailSummaryOne(startime int64, endtime int64, keyword string, limi
6429 6429
 
6430 6430
 	if len(keyword) > 0 {
6431 6431
 		likeKey := "%" + keyword + "%"
6432
-		db = db.Select("x.id,x.project_id,x.user_org_id,x.patient_id,x.record_date").Joins("left join xt_good_information as d on d.id = x.project_id").Where("d.good_name like ? ", likeKey).Group("d.id")
6432
+		db = db.Select("x.id,x.project_id,x.user_org_id,x.patient_id,x.record_date,x.count").Joins("left join xt_good_information as d on d.id = x.project_id").Where("d.good_name like ? ", likeKey).Group("d.id")
6433 6433
 	}
6434 6434
 
6435 6435
 	err = db.Order("x.ctime desc").Group("x.id").Scan(&project).Error
@@ -6481,3 +6481,34 @@ func GetAutoStockOutById(good_id, record_date int64, orgid int64, patient_id int
6481 6481
 	err := XTReadDB().Where("good_id = ? and record_time = ? and org_id = ? and status = 1 and patient_id = ?", good_id, record_date, orgid, patient_id).Find(&detail).Error
6482 6482
 	return detail, err
6483 6483
 }
6484
+
6485
+func GetAdviceConfig(orgid int64) (*models.XtAdviceSetting, error) {
6486
+
6487
+	setting := models.XtAdviceSetting{}
6488
+	err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&setting).Error
6489
+	if err == gorm.ErrRecordNotFound {
6490
+		return nil, err
6491
+	}
6492
+	if err != nil {
6493
+		return nil, err
6494
+	}
6495
+	return &setting, nil
6496
+}
6497
+
6498
+func CreateAdviceSetting(setting models.XtAdviceSetting) error {
6499
+
6500
+	err := XTWriteDB().Create(&setting).Error
6501
+	return err
6502
+}
6503
+
6504
+func UpdateAdviceSetting(orgid int64, setting models.XtAdviceSetting) error {
6505
+
6506
+	err := XTWriteDB().Model(&setting).Where("user_org_id = ? and status = 1", orgid).Update(map[string]interface{}{"is_advice_open": setting.IsAdviceOpen, "mtime": time.Now().Unix()}).Error
6507
+	return err
6508
+}
6509
+
6510
+func FindAdviceSettingById(orgid int64) (models.XtAdviceSetting, error) {
6511
+	setting := models.XtAdviceSetting{}
6512
+	err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&setting).Error
6513
+	return setting, err
6514
+}