XMLWAN 4 år sedan
förälder
incheckning
4407b42a48

+ 1 - 0
controllers/data_api_controller.go Visa fil

990
 					FrequencyType:         frequency_type,
990
 					FrequencyType:         frequency_type,
991
 					Way:                   way,
991
 					Way:                   way,
992
 					DrugId:                drug_id,
992
 					DrugId:                drug_id,
993
+					DrugNameId:            0,
993
 				}
994
 				}
994
 				subTemplate = append(subTemplate, subTemps)
995
 				subTemplate = append(subTemplate, subTemps)
995
 
996
 

+ 22 - 11
controllers/manager_center_api_controller.go Visa fil

191
 func (c *ManagerCenterApiController) EditBaseDrugLib() {
191
 func (c *ManagerCenterApiController) EditBaseDrugLib() {
192
 	id, _ := c.GetInt64("id")
192
 	id, _ := c.GetInt64("id")
193
 	drug_name := c.GetString("drug_name")
193
 	drug_name := c.GetString("drug_name")
194
-	fmt.Println("drug_name--------", drug_name)
194
+
195
 	pinyin := c.GetString("pinyin")
195
 	pinyin := c.GetString("pinyin")
196
 	wubi := c.GetString("wubi")
196
 	wubi := c.GetString("wubi")
197
 	drug_alias := c.GetString("drug_alias")
197
 	drug_alias := c.GetString("drug_alias")
236
 	is_statistics_work, _ := c.GetInt64("is_statistics_work")
236
 	is_statistics_work, _ := c.GetInt64("is_statistics_work")
237
 	is_charge_use, _ := c.GetInt64("is_charge_use")
237
 	is_charge_use, _ := c.GetInt64("is_charge_use")
238
 	drug_code := c.GetString("drug_code")
238
 	drug_code := c.GetString("drug_code")
239
-	unit := c.GetString("unit")
239
+	//unit := c.GetString("unit")
240
 	adminInfo := c.GetAdminUserInfo()
240
 	adminInfo := c.GetAdminUserInfo()
241
 	drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, id)
241
 	drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, id)
242
 
242
 
296
 	err := service.UpdateBaseDrugLib(drugLib)
296
 	err := service.UpdateBaseDrugLib(drugLib)
297
 
297
 
298
 	//修改xt_drug_name 表
298
 	//修改xt_drug_name 表
299
-
300
 	drugName := models.XtDrugName{
299
 	drugName := models.XtDrugName{
301
 		DrugName: drug_name,
300
 		DrugName: drug_name,
302
 	}
301
 	}
307
 		DrugName:       drug_name,
306
 		DrugName:       drug_name,
308
 		DrugSpec:       drug_spec,
307
 		DrugSpec:       drug_spec,
309
 		DrugStockLimit: drug_stock_limit,
308
 		DrugStockLimit: drug_stock_limit,
310
-		MinUnit:        unit,
309
+		MinUnit:        min_unit,
311
 	}
310
 	}
312
 
311
 
313
 	service.UpdateStandName(id, adminInfo.CurrentOrgId, &standName)
312
 	service.UpdateStandName(id, adminInfo.CurrentOrgId, &standName)
319
 		PrescribingNumber:  prescribing_number,
318
 		PrescribingNumber:  prescribing_number,
320
 		DeliveryWay:        delivery_way,
319
 		DeliveryWay:        delivery_way,
321
 		SingleDose:         single_dose,
320
 		SingleDose:         single_dose,
322
-		MinUnit:            unit,
321
+		MinUnit:            min_unit,
323
 	}
322
 	}
324
 
323
 
325
 	service.UpdateSelfMedical(id, adminInfo.CurrentOrgId, &medical)
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
 	stock := models.XtSelfStock{
329
 	stock := models.XtSelfStock{
330
 		DrugSpec: drug_spec,
330
 		DrugSpec: drug_spec,
331
 		DrugName: drug_name,
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
 	outStock := models.XtSelfOutStock{
336
 	outStock := models.XtSelfOutStock{
337
 		DrugName: drug_name,
337
 		DrugName: drug_name,
338
 		DrugSpec: drug_spec,
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
 	advice := models.DoctorAdvice{
344
 	advice := models.DoctorAdvice{
347
 		DeliveryWay:        delivery_way,
347
 		DeliveryWay:        delivery_way,
348
 		ExecutionFrequency: execution_frequency,
348
 		ExecutionFrequency: execution_frequency,
349
 		SingleDose:         single_dose,
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
 	if err == nil {
366
 	if err == nil {
356
 		c.ServeSuccessJSON(map[string]interface{}{
367
 		c.ServeSuccessJSON(map[string]interface{}{

+ 5 - 0
controllers/mobile_api_controllers/dialysis_api_controller.go Visa fil

2622
 			advice.DrugId = drug_id
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
 		if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
2630
 		if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
2626
 			template_id, _ := adviceNameM["template_id"].(string)
2631
 			template_id, _ := adviceNameM["template_id"].(string)
2627
 			advice.TemplateId = template_id
2632
 			advice.TemplateId = template_id

+ 27 - 4
controllers/mobile_api_controllers/patient_api_controller.go Visa fil

167
 }
167
 }
168
 
168
 
169
 func (c *PatientApiController) CreateDoctorAdvice() {
169
 func (c *PatientApiController) CreateDoctorAdvice() {
170
+	fmt.Println("进来了吗-----------------------------")
170
 	patient, _ := c.GetInt64("id", 0)
171
 	patient, _ := c.GetInt64("id", 0)
171
 	if patient <= 0 {
172
 	if patient <= 0 {
172
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
173
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
951
 		if groupno > 0 {
952
 		if groupno > 0 {
952
 			advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
953
 			advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
953
 			for _, item := range advices {
954
 			for _, item := range advices {
954
-				if item.ExecutionState == 2 {
955
+				fmt.Println("------------进来没有22222222", item.ExecutionState)
956
+				if item.ExecutionState == 1 {
955
 					prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
957
 					prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
956
 					count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
958
 					count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
957
 
959
 
967
 					//插入自备药出库单
969
 					//插入自备药出库单
968
 					outStock := models.XtSelfOutStock{
970
 					outStock := models.XtSelfOutStock{
969
 						DrugName:       item.AdviceName,
971
 						DrugName:       item.AdviceName,
970
-						DrugNameId:     item.DrugId,
972
+						DrugNameId:     item.DrugNameId,
971
 						DrugSpec:       item.AdviceDesc,
973
 						DrugSpec:       item.AdviceDesc,
972
 						OutstoreNumber: count,
974
 						OutstoreNumber: count,
973
 						AdminUserId:    adminUserInfo.AdminUser.Id,
975
 						AdminUserId:    adminUserInfo.AdminUser.Id,
988
 			advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
990
 			advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
989
 			for _, item := range advices {
991
 			for _, item := range advices {
990
 				if item.ExecutionState == 1 {
992
 				if item.ExecutionState == 1 {
993
+
991
 					prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
994
 					prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
992
 					count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
995
 					count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
993
 
996
 
1003
 					//插入自备药出库单
1006
 					//插入自备药出库单
1004
 					outStock := models.XtSelfOutStock{
1007
 					outStock := models.XtSelfOutStock{
1005
 						DrugName:       item.AdviceName,
1008
 						DrugName:       item.AdviceName,
1006
-						DrugNameId:     item.DrugId,
1009
+						DrugNameId:     item.DrugNameId,
1007
 						DrugSpec:       item.AdviceDesc,
1010
 						DrugSpec:       item.AdviceDesc,
1008
 						OutstoreNumber: count,
1011
 						OutstoreNumber: count,
1009
 						AdminUserId:    adminUserInfo.AdminUser.Id,
1012
 						AdminUserId:    adminUserInfo.AdminUser.Id,
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
 	if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
2371
 	if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
2359
 		singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
2372
 		singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
2360
 		advice.SingleDose = singleDose
2373
 		advice.SingleDose = singleDose
2766
 
2779
 
2767
 func (c *PatientApiController) CreateGroupAdvice() {
2780
 func (c *PatientApiController) CreateGroupAdvice() {
2768
 	is_child, _ := c.GetInt64("is_child", 0)
2781
 	is_child, _ := c.GetInt64("is_child", 0)
2769
-
2782
+	fmt.Println("is_child------------------------------", is_child)
2770
 	if is_child == 1 {
2783
 	if is_child == 1 {
2771
 		patient, _ := c.GetInt64("id", 0)
2784
 		patient, _ := c.GetInt64("id", 0)
2772
 		if patient <= 0 {
2785
 		if patient <= 0 {
2890
 			advice.PatientId = patientInfo.ID
2903
 			advice.PatientId = patientInfo.ID
2891
 			advice.AdviceDoctor = adminUserInfo.AdminUser.Id
2904
 			advice.AdviceDoctor = adminUserInfo.AdminUser.Id
2892
 
2905
 
2906
+			//入口
2893
 			errcode := c.setAdviceWithJSON(&advice, adviceNameM)
2907
 			errcode := c.setAdviceWithJSON(&advice, adviceNameM)
2894
 			if errcode > 0 {
2908
 			if errcode > 0 {
2895
 				c.ServeFailJSONWithSGJErrorCode(errcode)
2909
 				c.ServeFailJSONWithSGJErrorCode(errcode)
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
 	if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
3106
 	if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
3084
 		drugSpecUnit, _ := json["drug_spec_unit"].(string)
3107
 		drugSpecUnit, _ := json["drug_spec_unit"].(string)
3085
 		advice.DrugSpecUnit = drugSpecUnit
3108
 		advice.DrugSpecUnit = drugSpecUnit

+ 5 - 0
controllers/patient_api_controller.go Visa fil

1238
 			advice.DrugId = drug_id
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
 		if adviceType == 1 {
1246
 		if adviceType == 1 {
1242
 
1247
 
1243
 			if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
1248
 			if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {

+ 19 - 6
controllers/self_drug_api_congtroller.go Visa fil

186
 		DrugId:         drug_id,
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
 		return
203
 		return
193
 	}
204
 	}
194
-	this.ServeSuccessJSON(map[string]interface{}{
195
-		"RullerName": drugSpecName,
196
-	})
205
+
197
 }
206
 }
198
 
207
 
199
 func (this *SelfDrugApiController) EditRullerName() {
208
 func (this *SelfDrugApiController) EditRullerName() {
566
 	stocklist, err := service.GetStockList(patientid, startimeUnix, keyword, orgId)
575
 	stocklist, err := service.GetStockList(patientid, startimeUnix, keyword, orgId)
567
 	//统计出库数量
576
 	//统计出库数量
568
 	outStocklist, err := service.GetOutStockList(patientid, startimeUnix, keyword, orgId)
577
 	outStocklist, err := service.GetOutStockList(patientid, startimeUnix, keyword, orgId)
578
+
579
+	//统计该病人时间段内出库条数
580
+	outList, err := service.GetTotalOutStockList(patientid, startimeUnix, keyword, orgId)
569
 	if err != nil {
581
 	if err != nil {
570
 		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
582
 		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
571
 		return
583
 		return
574
 		"medicalList":  medicalList,
586
 		"medicalList":  medicalList,
575
 		"stocklist":    stocklist,
587
 		"stocklist":    stocklist,
576
 		"outStocklist": outStocklist,
588
 		"outStocklist": outStocklist,
589
+		"outList":      outList,
577
 	})
590
 	})
578
 }
591
 }
579
 
592
 

+ 1 - 0
models/dialysis.go Visa fil

395
 	IsCheck               int64           `gorm:"-" json:"is_check" form:"is_check"`
395
 	IsCheck               int64           `gorm:"-" json:"is_check" form:"is_check"`
396
 	Way                   int64           `gorm:"column:way" json:"way" form:"way"`
396
 	Way                   int64           `gorm:"column:way" json:"way" form:"way"`
397
 	DrugId                int64           `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
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
 func (DoctorAdvice) TableName() string {
401
 func (DoctorAdvice) TableName() string {

+ 1 - 0
models/doctor_advice_models.go Visa fil

74
 	FrequencyType           int64                   `gorm:"column:frequency_type" json:"frequency_type"`
74
 	FrequencyType           int64                   `gorm:"column:frequency_type" json:"frequency_type"`
75
 	DrugId                  int64                   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
75
 	DrugId                  int64                   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
76
 	Way                     int64                   `gorm:"column:way" json:"way" form:"way"`
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
 	SubDoctorAdviceTemplate []*DoctorAdviceTemplate `gorm:"ForeignKey:ParentId;AssociationForeignKey:ID" json:"child"`
78
 	SubDoctorAdviceTemplate []*DoctorAdviceTemplate `gorm:"ForeignKey:ParentId;AssociationForeignKey:ID" json:"child"`
78
 }
79
 }
79
 
80
 

+ 1 - 1
service/doctor_advice_service.go Visa fil

204
 
204
 
205
 func FindAllAdviceTemplate(org_id int64, advice_type int64) (temps []*models.DoctorAdviceParentTemplate, err error) {
205
 func FindAllAdviceTemplate(org_id int64, advice_type int64) (temps []*models.DoctorAdviceParentTemplate, err error) {
206
 	err = readDb.Model(&models.DoctorAdviceParentTemplate{}).Preload("DoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
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
 	}).Where("org_id = ? AND status=1 AND advice_type = ?", org_id, advice_type).Find(&temps).Error
208
 	}).Where("org_id = ? AND status=1 AND advice_type = ?", org_id, advice_type).Find(&temps).Error
209
 	return
209
 	return
210
 }
210
 }

+ 2 - 2
service/mobile_dialysis_service.go Visa fil

491
 	err := readDb.
491
 	err := readDb.
492
 		Model(&models.DoctorAdvice{}).
492
 		Model(&models.DoctorAdvice{}).
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).
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
 		Order("start_time asc, groupno desc, advice_order desc, id").
495
 		Order("start_time asc, groupno desc, advice_order desc, id").
496
 		Scan(&records).Error
496
 		Scan(&records).Error
497
 
497
 
508
 	err := readDb.
508
 	err := readDb.
509
 		Model(&models.DoctorAdvice{}).
509
 		Model(&models.DoctorAdvice{}).
510
 		Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and advice_type = 2", patientID, orgID, recordDate).
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
 		Order("start_time asc, groupno desc, advice_order desc, id asc").
512
 		Order("start_time asc, groupno desc, advice_order desc, id asc").
513
 		Scan(&records).Error
513
 		Scan(&records).Error
514
 
514
 

+ 39 - 3
service/self_drug_service.go Visa fil

68
 	return drug, err
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
 func SaveRulleName(rullName *models.XtStandName) error {
83
 func SaveRulleName(rullName *models.XtStandName) error {
72
 
84
 
73
 	err := XTWriteDB().Model(&rullName).Create(&rullName).Error
85
 	err := XTWriteDB().Model(&rullName).Create(&rullName).Error
263
 	return outStock, err
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
 //func GetOutStockList(patientid int64, startime int64, keyword string) (outStock []*models.XtSelfOutStocks, err error) {
296
 //func GetOutStockList(patientid int64, startime int64, keyword string) (outStock []*models.XtSelfOutStocks, err error) {
267
 //	db := XTReadDB().Table("xt_self_out_stock as x").Where("x.status = 1")
297
 //	db := XTReadDB().Table("xt_self_out_stock as x").Where("x.status = 1")
268
 //	likeKey := "%" + keyword + "%"
298
 //	likeKey := "%" + keyword + "%"
337
 	if orgid > 0 {
367
 	if orgid > 0 {
338
 		db = db.Where("x.user_org_id = ?", orgid)
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
 	return stocks, err
371
 	return stocks, err
342
 }
372
 }
343
 
373
 
578
 }
608
 }
579
 
609
 
580
 func UpdatedSelfStock(stock *models.XtSelfStock, id int64, orgid int64) error {
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
 	return err
612
 	return err
583
 }
613
 }
584
 
614
 
585
 func UpdatedOutSelfStock(stock *models.XtSelfOutStock, id int64, orgid int64) error {
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
 	return err
618
 	return err
589
 }
619
 }
590
 
620
 
593
 	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
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
 	return err
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
+}