Browse Source

11月8日库存管理

XMLWAN 3 years ago
parent
commit
947e24540b

+ 1 - 1
conf/app.conf View File

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

+ 32 - 0
controllers/gobal_config_api_controller.go View File

114
 	beego.Router("/api/drug/getcancelstockdetail", &GobalConfigApiController{}, "Get:GetCancelStockDetail")
114
 	beego.Router("/api/drug/getcancelstockdetail", &GobalConfigApiController{}, "Get:GetCancelStockDetail")
115
 
115
 
116
 	beego.Router("/api/changestocksetting/isopen", &GobalConfigApiController{}, "Get:ChangeStockSetting")
116
 	beego.Router("/api/changestocksetting/isopen", &GobalConfigApiController{}, "Get:ChangeStockSetting")
117
+
118
+	beego.Router("/api/changeadviceconfig", &GobalConfigApiController{}, "Get:ChangeAdviceConfig")
117
 }
119
 }
118
 
120
 
119
 //provinces, _ := service.GetDistrictsByUpid(0)21
121
 //provinces, _ := service.GetDistrictsByUpid(0)21
1560
 	_, project_config := service.FindXTHisProjectByOrgIdOne(adminUserInfo.CurrentOrgId)
1562
 	_, project_config := service.FindXTHisProjectByOrgIdOne(adminUserInfo.CurrentOrgId)
1561
 
1563
 
1562
 	stockSetting, _ := service.FindStockSettingById(adminUserInfo.CurrentOrgId)
1564
 	stockSetting, _ := service.FindStockSettingById(adminUserInfo.CurrentOrgId)
1565
+	adviceSetting, _ := service.FindAdviceSettingById(adminUserInfo.CurrentOrgId)
1563
 	c.ServeSuccessJSON(map[string]interface{}{
1566
 	c.ServeSuccessJSON(map[string]interface{}{
1564
 		"is_open_xt_his":         config.IsOpen,
1567
 		"is_open_xt_his":         config.IsOpen,
1565
 		"is_open_xt_his_project": project_config.IsOpen,
1568
 		"is_open_xt_his_project": project_config.IsOpen,
1566
 		"is_open_stock":          stockSetting.IsType,
1569
 		"is_open_stock":          stockSetting.IsType,
1570
+		"is_open_advice":         adviceSetting.IsAdviceOpen,
1567
 	})
1571
 	})
1568
 
1572
 
1569
 }
1573
 }
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
 
2887
 
2888
 	sick, _ := c.GetInt64("sick")
2888
 	sick, _ := c.GetInt64("sick")
2889
 	diagnose, _ := c.GetInt64("diagnose")
2889
 	diagnose, _ := c.GetInt64("diagnose")
2890
-	id, _ := c.GetInt64("id")
2891
-
2890
+	//id, _ := c.GetInt64("id")
2892
 	timeLayout := "2006-01-02"
2891
 	timeLayout := "2006-01-02"
2893
 	loc, _ := time.LoadLocation("Local")
2892
 	loc, _ := time.LoadLocation("Local")
2894
 	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
2893
 	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
2906
 	}
2905
 	}
2907
 	sickTimes := sickTime.Unix()
2906
 	sickTimes := sickTime.Unix()
2908
 	ctime := time.Now().Unix()
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
 	caseHistory := models.HisPatientCaseHistory{
2916
 	caseHistory := models.HisPatientCaseHistory{
2910
 		HisPatientId:            his_patient_id,
2917
 		HisPatientId:            his_patient_id,
2911
 		PatientId:               patient_id,
2918
 		PatientId:               patient_id,
2939
 		Sick:                    sick,
2946
 		Sick:                    sick,
2940
 		Diagnose:                diagnose,
2947
 		Diagnose:                diagnose,
2941
 		AllergicHistory:         allergic_history,
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
 	if errcodes == gorm.ErrRecordNotFound {
2958
 	if errcodes == gorm.ErrRecordNotFound {
2946
 		err = service.SaveHisPatientCaseHistory(&caseHistory)
2959
 		err = service.SaveHisPatientCaseHistory(&caseHistory)
2960
+		historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
2947
 		if err != nil {
2961
 		if err != nil {
2948
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
2962
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
2949
 			return
2963
 			return
2950
 		}
2964
 		}
2951
 		c.ServeSuccessJSON(map[string]interface{}{
2965
 		c.ServeSuccessJSON(map[string]interface{}{
2952
 			"caseHistory": caseHistory,
2966
 			"caseHistory": caseHistory,
2967
+			"historyInfo": historyInfo,
2953
 		})
2968
 		})
2954
 		return
2969
 		return
2955
 	} else if errcodes == nil {
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
 		if err != nil {
2973
 		if err != nil {
2958
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
2974
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
2959
 			return
2975
 			return
2960
 		}
2976
 		}
2961
 		c.ServeSuccessJSON(map[string]interface{}{
2977
 		c.ServeSuccessJSON(map[string]interface{}{
2962
 			"caseHistory": caseHistory,
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
 	schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
405
 	schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
406
 	go func() {
406
 	go func() {
407
 		patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
407
 		patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
408
+		fmt.Println("patient23333223322323", patient.TrobleShoot)
408
 		ch <- struct{}{}
409
 		ch <- struct{}{}
409
 	}()
410
 	}()
410
 
411
 

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

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

+ 1 - 1
controllers/patient_api_controller.go View File

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

+ 1 - 1
controllers/schedule_api_controller.go View File

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

+ 15 - 0
models/his_models.go View File

174
 	UserName                string `gorm:"column:user_name" json:"user_name" form:"user_name"`
174
 	UserName                string `gorm:"column:user_name" json:"user_name" form:"user_name"`
175
 	DoctorAdvice            string `gorm:"column:doctor_advice" json:"doctor_advice" form:"doctor_advice"`
175
 	DoctorAdvice            string `gorm:"column:doctor_advice" json:"doctor_advice" form:"doctor_advice"`
176
 	Remark                  string `gorm:"column:remark" json:"remark" form:"remark"`
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
 func (HisCaseHistoryTemplate) TableName() string {
188
 func (HisCaseHistoryTemplate) TableName() string {
370
 	Sick                    int64   `gorm:"column:sick" json:"sick" form:"sick"`
379
 	Sick                    int64   `gorm:"column:sick" json:"sick" form:"sick"`
371
 	Diagnose                int64   `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
380
 	Diagnose                int64   `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
372
 	AllergicHistory         string  `gorm:"column:allergic_history" json:"allergic_history" form:"allergic_history"`
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
 func (HisPatientCaseHistory) TableName() string {
390
 func (HisPatientCaseHistory) TableName() string {

+ 13 - 0
models/stock_models.go View File

1345
 func (XtStockSetting) TableName() string {
1345
 func (XtStockSetting) TableName() string {
1346
 	return "xt_stock_setting"
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
 }
335
 }
336
 
336
 
337
 func GetHisPatientCaseHistoryInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatientCaseHistory, err error) {
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
 	return
339
 	return
340
 }
340
 }
341
 
341
 
372
 	return
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
 	history := models.HisPatientCaseHistory{}
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
 	if err != nil {
378
 	if err != nil {
379
 		if err == gorm.ErrRecordNotFound {
379
 		if err == gorm.ErrRecordNotFound {
380
 			return nil, err
380
 			return nil, err
385
 	return &history, nil
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
 func SaveHisPatientCaseHistory(caseHistory *models.HisPatientCaseHistory) error {
394
 func SaveHisPatientCaseHistory(caseHistory *models.HisPatientCaseHistory) error {
389
 	err := writeDb.Create(&caseHistory).Error
395
 	err := writeDb.Create(&caseHistory).Error
390
 	return err
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
 	return err
403
 	return err
397
 }
404
 }
398
 
405
 

+ 1 - 1
service/patient_service.go View File

533
 	key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(id, 10) + ":patient_info"
533
 	key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(id, 10) + ":patient_info"
534
 
534
 
535
 	patient_info_str, _ := redis.Get(key).Result()
535
 	patient_info_str, _ := redis.Get(key).Result()
536
-
536
+	fmt.Println("patient_info_stre223322323232323323223", patient_info_str)
537
 	if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
537
 	if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
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
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
 		if err != nil {
539
 		if err != nil {

+ 36 - 5
service/stock_service.go View File

1127
 	if org_id > 0 {
1127
 	if org_id > 0 {
1128
 		db = db.Where("x.org_id = ?", org_id)
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
 	return list, err
1131
 	return list, err
1132
 }
1132
 }
1133
 
1133
 
6345
 
6345
 
6346
 	if len(keyword) > 0 {
6346
 	if len(keyword) > 0 {
6347
 		likeKey := "%" + keyword + "%"
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
 	offset := (page - 1) * limit
6351
 	offset := (page - 1) * limit
6372
 
6372
 
6373
 	if len(keyword) > 0 {
6373
 	if len(keyword) > 0 {
6374
 		likeKey := "%" + keyword + "%"
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
 	err = db.Order("x.created_time desc").Scan(&adviceinfo).Error
6378
 	err = db.Order("x.created_time desc").Scan(&adviceinfo).Error
6403
 
6403
 
6404
 	if len(keyword) > 0 {
6404
 	if len(keyword) > 0 {
6405
 		likeKey := "%" + keyword + "%"
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
 	offset := (page - 1) * limit
6409
 	offset := (page - 1) * limit
6429
 
6429
 
6430
 	if len(keyword) > 0 {
6430
 	if len(keyword) > 0 {
6431
 		likeKey := "%" + keyword + "%"
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
 	err = db.Order("x.ctime desc").Group("x.id").Scan(&project).Error
6435
 	err = db.Order("x.ctime desc").Group("x.id").Scan(&project).Error
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
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
 	return detail, err
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
+}