Browse Source

Merge branch '20201014_xt_api_new_branch' of http://git.shengws.com/csx/XT_New into 20201014_xt_api_new_branch

csx 4 years ago
parent
commit
6de492bc68

+ 65 - 14
controllers/his_api_controller.go View File

6
 	"XT_New/service"
6
 	"XT_New/service"
7
 	"XT_New/utils"
7
 	"XT_New/utils"
8
 	"encoding/json"
8
 	"encoding/json"
9
+	"fmt"
9
 	"github.com/astaxie/beego"
10
 	"github.com/astaxie/beego"
10
 	"reflect"
11
 	"reflect"
11
 	"strconv"
12
 	"strconv"
118
 	efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
119
 	efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
119
 
120
 
120
 	doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
121
 	doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
121
-
122
+	//获取所有科室信息
123
+	department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
122
 	c.ServeSuccessJSON(map[string]interface{}{
124
 	c.ServeSuccessJSON(map[string]interface{}{
123
 		"drugs":            drugs,
125
 		"drugs":            drugs,
124
 		"advices_template": advices,
126
 		"advices_template": advices,
125
 		"drugways":         drugways,
127
 		"drugways":         drugways,
126
 		"efs":              efs,
128
 		"efs":              efs,
127
 		"doctors":          doctors,
129
 		"doctors":          doctors,
130
+		"department":       department,
128
 	})
131
 	})
129
 }
132
 }
130
 func (c *HisApiController) CreateHisPrescription() {
133
 func (c *HisApiController) CreateHisPrescription() {
131
 	record_date := c.GetString("record_date")
134
 	record_date := c.GetString("record_date")
135
+	fmt.Println("record_date", record_date)
132
 	patient_id, _ := c.GetInt64("patient_id")
136
 	patient_id, _ := c.GetInt64("patient_id")
133
 	//diagnose := c.GetString("diagnose")
137
 	//diagnose := c.GetString("diagnose")
134
 	//sick_history := c.GetString("sick_history")
138
 	//sick_history := c.GetString("sick_history")
135
 	doctor, _ := c.GetInt64("doctor")
139
 	doctor, _ := c.GetInt64("doctor")
136
 	//departm/**/ent, _ := c.GetInt64("department")
140
 	//departm/**/ent, _ := c.GetInt64("department")
137
-
141
+	his_patient_id, _ := c.GetInt64("his_patient_id")
138
 	dataBody := make(map[string]interface{}, 0)
142
 	dataBody := make(map[string]interface{}, 0)
139
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
143
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
140
 	if err != nil {
144
 	if err != nil {
169
 
173
 
170
 				ctime := time.Now().Unix()
174
 				ctime := time.Now().Unix()
171
 				prescription := &models.HisPrescription{
175
 				prescription := &models.HisPrescription{
172
-					PatientId:  patient_id,
173
-					UserOrgId:  adminInfo.CurrentOrgId,
174
-					RecordDate: recordDateTime,
175
-					Ctime:      ctime,
176
-					Mtime:      ctime,
177
-					Type:       types,
178
-					Modifier:   adminInfo.AdminUser.Id,
179
-					Creator:    adminInfo.AdminUser.Id,
180
-					Status:     1,
181
-					Doctor:     doctor,
176
+					PatientId:    patient_id,
177
+					UserOrgId:    adminInfo.CurrentOrgId,
178
+					RecordDate:   recordDateTime,
179
+					Ctime:        ctime,
180
+					Mtime:        ctime,
181
+					Type:         types,
182
+					Modifier:     adminInfo.AdminUser.Id,
183
+					Creator:      adminInfo.AdminUser.Id,
184
+					Status:       1,
185
+					Doctor:       doctor,
186
+					HisPatientId: his_patient_id,
182
 				}
187
 				}
183
 				service.SaveHisPrescription(prescription)
188
 				service.SaveHisPrescription(prescription)
184
 
189
 
205
 							s.CreatedTime = ctime
210
 							s.CreatedTime = ctime
206
 							s.UpdatedTime = mtime
211
 							s.UpdatedTime = mtime
207
 							s.PatientId = patient_id
212
 							s.PatientId = patient_id
208
-
213
+							s.HisPatientId = his_patient_id
209
 							errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
214
 							errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
210
 							if errcode > 0 {
215
 							if errcode > 0 {
211
 								c.ServeFailJSONWithSGJErrorCode(errcode)
216
 								c.ServeFailJSONWithSGJErrorCode(errcode)
215
 						}
220
 						}
216
 					}
221
 					}
217
 				}
222
 				}
218
-
223
+				if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
224
+					projects := items["project"].([]interface{})
225
+					if len(projects) > 0 {
226
+						for _, project := range projects {
227
+							var p models.HisPrescriptionProject
228
+							p.PrescriptionId = prescription.ID
229
+							p.Ctime = time.Now().Unix()
230
+							p.Mtime = time.Now().Unix()
231
+							p.PatientId = patient_id
232
+							p.RecordDate = recordDateTime
233
+							p.UserOrgId = adminInfo.CurrentOrgId
234
+							p.HisPatientId = his_patient_id
235
+							errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
236
+							if errcode > 0 {
237
+								c.ServeFailJSONWithSGJErrorCode(errcode)
238
+								return
239
+							}
240
+							service.CreateHisProjectTwo(&p)
241
+						}
242
+					}
243
+				}
219
 			}
244
 			}
220
 		}
245
 		}
246
+
247
+		//查询患者今日处方信息
248
+		//_, errcode := service.GetHisPrescriptionTwo(his_patient_id, adminInfo.CurrentOrgId, recordDateTime)
249
+		//if errcode == nil{
250
+		//    //改变患者信息状态
251
+		//   service.UpdatedHisPatient(his_patient_id, adminInfo.CurrentOrgId, recordDateTime)
252
+		//
253
+		//}
221
 	}
254
 	}
222
 
255
 
223
 	if err == nil {
256
 	if err == nil {
536
 	}
569
 	}
537
 	return 0
570
 	return 0
538
 }
571
 }
572
+
573
+func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
574
+
575
+	if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
576
+		project_id := int64(json["id"].(float64))
577
+		project.ProjectId = project_id
578
+	}
579
+
580
+	if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
581
+		price := int64(json["price"].(float64))
582
+		formatInt_price := strconv.FormatInt(price, 10)
583
+		float_price, _ := strconv.ParseFloat(formatInt_price, 64)
584
+		project.Price = float_price
585
+	}
586
+
587
+	return 0
588
+
589
+}

+ 41 - 6
controllers/his_project_api_controller.go View File

54
 	beego.Router("/api/hist/getallprojecteam", &HisProjectApiController{}, "Get:GetAllProjectTeam")
54
 	beego.Router("/api/hist/getallprojecteam", &HisProjectApiController{}, "Get:GetAllProjectTeam")
55
 	beego.Router("/api/his/getprojectlistbyid", &HisProjectApiController{}, "Get:GetProjectListById")
55
 	beego.Router("/api/his/getprojectlistbyid", &HisProjectApiController{}, "Get:GetProjectListById")
56
 	beego.Router("/api/his/gethispatienthistory", &HisProjectApiController{}, "Get:GetHisPatientHistory")
56
 	beego.Router("/api/his/gethispatienthistory", &HisProjectApiController{}, "Get:GetHisPatientHistory")
57
+	beego.Router("/api/patient/changepatient", &HisProjectApiController{}, "Get:ChangePatient")
57
 }
58
 }
58
 
59
 
59
 func (this *HisProjectApiController) SaveProject() {
60
 func (this *HisProjectApiController) SaveProject() {
727
 	timeLayout := "2006-01-02"
728
 	timeLayout := "2006-01-02"
728
 	loc, _ := time.LoadLocation("Local")
729
 	loc, _ := time.LoadLocation("Local")
729
 	age, _ := this.GetInt64("age")
730
 	age, _ := this.GetInt64("age")
730
-
731
 	birthday := this.GetString("birthDay")
731
 	birthday := this.GetString("birthDay")
732
 	birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
732
 	birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
733
 	birthUnix := birthdays.Unix()
733
 	birthUnix := birthdays.Unix()
757
 	totals_float, _ := strconv.ParseFloat(totals, 64)
757
 	totals_float, _ := strconv.ParseFloat(totals, 64)
758
 	adminUserInfo := this.GetAdminUserInfo()
758
 	adminUserInfo := this.GetAdminUserInfo()
759
 	orgId := adminUserInfo.CurrentOrgId
759
 	orgId := adminUserInfo.CurrentOrgId
760
-	timeStr := time.Now().Format("2006-01-02")
761
-	fmt.Println("timeStr:", timeStr)
762
-	timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
760
+	recordDateStr := time.Now().Format("2006-01-02")
761
+	recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
762
+	fmt.Println("parseDateErr", parseDateErr)
763
+	nowtime := recordDate.Unix()
763
 
764
 
764
 	bloodPatient, errcode := service.GetBloodPatientByIdCard(idcard, orgId)
765
 	bloodPatient, errcode := service.GetBloodPatientByIdCard(idcard, orgId)
765
 	if errcode == gorm.ErrRecordNotFound {
766
 	if errcode == gorm.ErrRecordNotFound {
769
 			IdType:                 certificates,
770
 			IdType:                 certificates,
770
 			CostOfProduction:       cost_float,
771
 			CostOfProduction:       cost_float,
771
 			Departments:            department,
772
 			Departments:            department,
772
-			AdminUserId:            doctor,
773
+			Doctor:                 doctor,
774
+			AdminUserId:            adminUserInfo.AdminUser.Id,
773
 			MedicalTreatmentType:   medicalcare,
775
 			MedicalTreatmentType:   medicalcare,
774
 			IdCardNo:               idcard,
776
 			IdCardNo:               idcard,
775
 			IsNeedCostOfProduction: cost_checked,
777
 			IsNeedCostOfProduction: cost_checked,
783
 			Total:                  totals_float,
785
 			Total:                  totals_float,
784
 			UserOrgId:              orgId,
786
 			UserOrgId:              orgId,
785
 			Status:                 1,
787
 			Status:                 1,
786
-			RecordDate:             timeStringToTime.Unix(),
788
+			RecordDate:             nowtime,
789
+			IsReturn:               1,
787
 		}
790
 		}
788
 		err := service.CreateHisPatient(&patient)
791
 		err := service.CreateHisPatient(&patient)
789
 		if err != nil {
792
 		if err != nil {
872
 	adminUserInfo := this.GetAdminUserInfo()
875
 	adminUserInfo := this.GetAdminUserInfo()
873
 	orgId := adminUserInfo.CurrentOrgId
876
 	orgId := adminUserInfo.CurrentOrgId
874
 	history, total, err := service.GetHisPatientHistory(keyword, startTime.Unix(), endTime.Unix(), register_type, limit, page, orgId)
877
 	history, total, err := service.GetHisPatientHistory(keyword, startTime.Unix(), endTime.Unix(), register_type, limit, page, orgId)
878
+
875
 	department, err := service.GetAllDepartMent(orgId)
879
 	department, err := service.GetAllDepartMent(orgId)
880
+	appId := adminUserInfo.CurrentAppId
881
+	doctor, err := service.GetAllDoctor(orgId, appId)
876
 	if err != nil {
882
 	if err != nil {
877
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
883
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
878
 		return
884
 		return
881
 		"history":    history,
887
 		"history":    history,
882
 		"total":      total,
888
 		"total":      total,
883
 		"department": department,
889
 		"department": department,
890
+		"doctor":     doctor,
884
 	})
891
 	})
885
 }
892
 }
893
+
894
+func (this *HisProjectApiController) ChangePatient() {
895
+
896
+	id, _ := this.GetInt64("id")
897
+	//查询该患者今日是否已经就诊
898
+	recordDateStr := time.Now().Format("2006-01-02")
899
+	recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
900
+	fmt.Println("parseDateErr", parseDateErr)
901
+	nowtime := recordDate.Unix()
902
+	adminUserInfo := this.GetAdminUserInfo()
903
+	orgId := adminUserInfo.CurrentOrgId
904
+	_, errcode := service.GetHisPrescriptionTwo(id, orgId, nowtime)
905
+	if errcode == gorm.ErrRecordNotFound {
906
+		err := service.ChangePatient(id)
907
+		if err != nil {
908
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
909
+			return
910
+		}
911
+		returnData := make(map[string]interface{}, 0)
912
+		returnData["msg"] = "ok"
913
+		this.ServeSuccessJSON(returnData)
914
+		return
915
+	} else if errcode == nil {
916
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
917
+		return
918
+	}
919
+
920
+}

+ 1 - 1
controllers/mobile_api_controllers/check_weight_api_controller.go View File

354
 		var system_dialysisPrescribe *models.SystemPrescription
354
 		var system_dialysisPrescribe *models.SystemPrescription
355
 
355
 
356
 		var mode_id int64
356
 		var mode_id int64
357
-		weightfirst, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
357
+		weightfirst, _ := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
358
 		if weightfirst.DryWeight > weighing_before {
358
 		if weightfirst.DryWeight > weighing_before {
359
 			return
359
 			return
360
 		}
360
 		}

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

1685
 		UpdatedTime:           time.Now().Unix(),
1685
 		UpdatedTime:           time.Now().Unix(),
1686
 	}
1686
 	}
1687
 
1687
 
1688
+	//只针对广慈医院
1689
+	if template.TemplateId == 26 || template.TemplateId == 25 {
1690
+		// 查询病人是否有透前评估数据
1691
+		befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
1692
+		//如果有数据就插入
1693
+		if errcode == nil {
1694
+			record.SystolicBloodPressure = befor.SystolicBloodPressure
1695
+			record.DiastolicBloodPressure = befor.DiastolicBloodPressure
1696
+			record.BreathingRate = befor.BreathingRate
1697
+			record.PulseFrequency = befor.PulseFrequency
1698
+			record.Temperature = befor.Temperature
1699
+		}
1700
+	}
1701
+
1688
 	// 如果当天有插入数据,则不再往透析纪录里插入数据
1702
 	// 如果当天有插入数据,则不再往透析纪录里插入数据
1689
 	if newdialysisRecord.ID > 0 {
1703
 	if newdialysisRecord.ID > 0 {
1690
 		err := service.CreateMonitor(&record)
1704
 		err := service.CreateMonitor(&record)

+ 20 - 2
controllers/mobile_api_controllers/patient_api_controller.go View File

982
 						MedicId:        item.DrugId,
982
 						MedicId:        item.DrugId,
983
 						StockOutNumber: warehousing_out_order,
983
 						StockOutNumber: warehousing_out_order,
984
 					}
984
 					}
985
-					service.CreateOutStock(&outStock)
985
+					//查询 该患者是否已出库
986
+					out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
987
+					fmt.Println("errcode ------------------22222", errcode)
988
+					if errcode == gorm.ErrRecordNotFound {
989
+						service.CreateOutStock(&outStock)
990
+					} else if errcode == nil {
991
+						err := service.UpdatedSelfOutSatock(out.ID, &outStock)
992
+						fmt.Println("err", err)
993
+					}
986
 				}
994
 				}
987
 			}
995
 			}
988
 		} else {
996
 		} else {
1004
 					number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1012
 					number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1005
 					number = number + total
1013
 					number = number + total
1006
 					warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
1014
 					warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
1015
+
1007
 					//插入自备药出库单
1016
 					//插入自备药出库单
1008
 					outStock := models.XtSelfOutStock{
1017
 					outStock := models.XtSelfOutStock{
1009
 						DrugName:       item.AdviceName,
1018
 						DrugName:       item.AdviceName,
1020
 						MedicId:        item.DrugId,
1029
 						MedicId:        item.DrugId,
1021
 						StockOutNumber: warehousing_out_order,
1030
 						StockOutNumber: warehousing_out_order,
1022
 					}
1031
 					}
1023
-					service.CreateOutStock(&outStock)
1032
+
1033
+					//查询 该患者是否已出库
1034
+					out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
1035
+					fmt.Println("errcode ------------------", errcode)
1036
+					if errcode == gorm.ErrRecordNotFound {
1037
+						service.CreateOutStock(&outStock)
1038
+					} else if errcode == nil {
1039
+						err := service.UpdatedSelfOutSatock(out.ID, &outStock)
1040
+						fmt.Println("err", err)
1041
+					}
1024
 
1042
 
1025
 				}
1043
 				}
1026
 			}
1044
 			}

+ 2 - 0
models/his_models.go View File

491
 	Mtime                  int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
491
 	Mtime                  int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
492
 	PatientId              int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
492
 	PatientId              int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
493
 	Number                 string  `gorm:"column:number" json:"number" form:"number"`
493
 	Number                 string  `gorm:"column:number" json:"number" form:"number"`
494
+	Doctor                 int64   `gorm:"column:doctor" json:"doctor" form:"doctor"`
495
+	IsReturn               int64   `gorm:"column:is_return" json:"is_return" form:"is_return"`
494
 }
496
 }
495
 
497
 
496
 func (XtHisPatient) TableName() string {
498
 func (XtHisPatient) TableName() string {

+ 27 - 1
service/his_project_service.go View File

304
 	if orgid > 0 {
304
 	if orgid > 0 {
305
 		db = db.Where("x.user_org_id = ?", orgid)
305
 		db = db.Where("x.user_org_id = ?", orgid)
306
 	}
306
 	}
307
-	err = db.Select("x.id,x.balance_accounts_type,x.medical_insurance_number,x.name,x.gender,x.id_type,x.medical_treatment_type,x.birthday,x.record_date,x.age,x.phone_number,x.id_card_no,x.register_type,x.admin_user_id,x.departments,x.is_need_cost_of_production,x.register_cost,x.treatment_cost,x.cost_of_production,x.total,x.user_org_id,x.patient_id,x.number").Count(&total).Offset(offset).Limit(limit).Find(&hisPatient).Error
307
+	err = db.Select("x.id,x.balance_accounts_type,x.medical_insurance_number,x.name,x.gender,x.id_type,x.medical_treatment_type,x.birthday,x.record_date,x.age,x.phone_number,x.id_card_no,x.register_type,x.admin_user_id,x.departments,x.is_need_cost_of_production,x.register_cost,x.treatment_cost,x.cost_of_production,x.total,x.user_org_id,x.patient_id,x.number,x.doctor,x.is_return").Count(&total).Offset(offset).Limit(limit).Find(&hisPatient).Error
308
 	return hisPatient, total, err
308
 	return hisPatient, total, err
309
 }
309
 }
310
+
311
+func ChangePatient(id int64) error {
312
+	patient := models.XtHisPatient{}
313
+
314
+	err := XTWriteDB().Model(&patient).Where("id = ?", id).Updates(map[string]interface{}{"is_return": 2}).Error
315
+	return err
316
+}
317
+
318
+func GetHisPrescriptionTwo(patientid int64, orgid int64, recorddate int64) (*models.HisPrescription, error) {
319
+	prescription := models.HisPrescription{}
320
+	err := XTReadDB().Model(&prescription).Where("his_patient_id = ? and user_org_id = ? and record_date = ? and status = 1", patientid, orgid, recorddate).Find(&prescription).Error
321
+	if err != nil {
322
+		if err == gorm.ErrRecordNotFound {
323
+			return nil, err
324
+		} else {
325
+			return nil, err
326
+		}
327
+	}
328
+	return &prescription, nil
329
+}
330
+
331
+func UpdatedHisPatient(hispatientid int64, orgid int64, recorddate int64) error {
332
+	hisPatient := models.HisPatient{}
333
+	err := XTWriteDB().Model(&hisPatient).Where("id = ? and user_org_id = ? and record_date = ?", hispatientid, orgid, recorddate).Updates(map[string]interface{}{"is_return": 3}).Error
334
+	return err
335
+}

+ 5 - 0
service/his_service.go View File

156
 	err = writeDb.Create(s).Error
156
 	err = writeDb.Create(s).Error
157
 	return
157
 	return
158
 }
158
 }
159
+
160
+func CreateHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
161
+	err = writeDb.Create(project).Error
162
+	return
163
+}

+ 1 - 1
service/manage_service.go View File

253
 
253
 
254
 func UpdatePlanInfo(id int64, orgid int64, plan models.DevicePlan) error {
254
 func UpdatePlanInfo(id int64, orgid int64, plan models.DevicePlan) error {
255
 
255
 
256
-	err := writeUserDb.Model(&plan).Where("id = ? AND user_org_id = ?", id, orgid).Updates(map[string]interface{}{"device_type": plan.DeviceType, "disinfec_time": plan.DisinfecTime, "time": plan.Time, "classtime": plan.Classtime, "way": plan.Way, "machine_disinfectant": plan.MachineDisinfectant, "disinfectan_way": plan.MachineDisinfectant, "disinfectant": plan.Disinfectant, "mtime": time.Now().Unix()}).Error
256
+	err := writeUserDb.Model(&plan).Where("id = ? AND user_org_id = ?", id, orgid).Updates(map[string]interface{}{"device_type": plan.DeviceType, "disinfec_time": plan.DisinfecTime, "time": plan.Time, "classtime": plan.Classtime, "way": plan.Way, "machine_disinfectant": plan.MachineDisinfectant, "disinfectan_way": plan.DisinfectanWay, "disinfectant": plan.Disinfectant, "mtime": time.Now().Unix()}).Error
257
 	return err
257
 	return err
258
 }
258
 }
259
 
259
 

+ 14 - 0
service/mobile_dialysis_service.go View File

1597
 	}
1597
 	}
1598
 	return
1598
 	return
1599
 }
1599
 }
1600
+
1601
+func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
1602
+
1603
+	evaluation := models.PredialysisEvaluation{}
1604
+
1605
+	err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
1606
+	if err == gorm.ErrRecordNotFound {
1607
+		return nil, err
1608
+	}
1609
+	if err != nil {
1610
+		return nil, err
1611
+	}
1612
+	return &evaluation, nil
1613
+}

+ 19 - 0
service/self_drug_service.go View File

4
 	"XT_New/models"
4
 	"XT_New/models"
5
 	"fmt"
5
 	"fmt"
6
 	"github.com/jinzhu/gorm"
6
 	"github.com/jinzhu/gorm"
7
+	"time"
7
 )
8
 )
8
 
9
 
9
 func GetCurrentPatient(orgid int64) (patients []*models.DrugPatients, err error) {
10
 func GetCurrentPatient(orgid int64) (patients []*models.DrugPatients, err error) {
733
 	return drugName, err
734
 	return drugName, err
734
 
735
 
735
 }
736
 }
737
+
738
+func GetSelfOutStock(orgid int64, advicedate int64, patientid int64, adivicename string, advicedesc string) (*models.XtSelfOutStock, error) {
739
+	stock := models.XtSelfOutStock{}
740
+	err = XTReadDB().Model(&stock).Where("user_org_id = ? and storck_time = ? and patient_id = ? and drug_name = ? and drug_spec = ? and status = 1", orgid, advicedate, patientid, adivicename, advicedesc).Find(&stock).Error
741
+	if err == gorm.ErrRecordNotFound {
742
+		return nil, err
743
+	}
744
+	if err != nil {
745
+		return nil, err
746
+	}
747
+	return &stock, err
748
+}
749
+
750
+func UpdatedSelfOutSatock(id int64, stock *models.XtSelfOutStock) error {
751
+
752
+	err := XTWriteDB().Model(&stock).Where("id = ?", id).Updates(map[string]interface{}{"drug_name": stock.DrugName, "drug_name_id": stock.DrugNameId, "drug_spec": stock.DrugSpec, "outstore_number": stock.OutstoreNumber, "admin_user_id": stock.AdminUserId, "storck_time": stock.StorckTime, "patient_id": stock.PatientId, "stock_out_number": stock.StockOutNumber, "exit_mode": stock.ExitMode, "medic_id": stock.MedicId, "updated_time": time.Now().Unix()}).Error
753
+	return err
754
+}