Browse Source

处方模板一件新增

mainqaq 2 years ago
parent
commit
142e28dc68

+ 3 - 0
controllers/drug_pharmacy_management_controller.go View File

@@ -469,6 +469,9 @@ func (this *PharmacyApiController) GetReturnPharmacyBaseDrug() {
469 469
 func (this *PharmacyApiController) SaveSetting() {
470 470
 	var err error
471 471
 	defer func() {
472
+		if rec := recover(); rec != nil {
473
+			err = fmt.Errorf("程序异常:%v", rec)
474
+		}
472 475
 		if err != nil {
473 476
 			service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
474 477
 		}

+ 936 - 1
controllers/his_config_api_controller.go View File

@@ -6,9 +6,13 @@ import (
6 6
 	"XT_New/service"
7 7
 	"XT_New/utils"
8 8
 	"encoding/json"
9
+	"fmt"
9 10
 	"github.com/astaxie/beego"
11
+	"github.com/astaxie/beego/config"
12
+	"golang.org/x/sync/errgroup"
10 13
 	"reflect"
11 14
 	"strconv"
15
+	"strings"
12 16
 	"time"
13 17
 )
14 18
 
@@ -16,11 +20,16 @@ type HisConfigApiController struct {
16 20
 	BaseAuthAPIController
17 21
 }
18 22
 
23
+const (
24
+	AddTypeDrug    = 1 //药品
25
+	AddTypeProject = 2 //项目
26
+)
27
+
19 28
 func HisConfigApiRegistRouters() {
20 29
 	beego.Router("/api/his/patient/list", &HisConfigApiController{}, "get:GetAllHisPatientsList")
21 30
 	beego.Router("/api/his/prescriptiontemplate/list", &HisConfigApiController{}, "get:GetPrescriptionTemplateList")
22 31
 	beego.Router("/api/his/prescriptiontemplate/info", &HisConfigApiController{}, "get:GetPrescriptionTemplateInfo")
23
-	beego.Router("/api/his/prescriptiontemplate/create", &HisConfigApiController{}, "post:CreatePrescriptionTemplate")
32
+	beego.Router("/api/his/prescriptiontemplate/create", &HisConfigApiController{}, "post:CreatePrescriptionTemplate") //批量添加
24 33
 	beego.Router("/api/his/prescriptiontemplate/delete", &HisConfigApiController{}, "post:DeletePrescriptionTemplate")
25 34
 	beego.Router("/api/his/prescriptioninfotemplate/delete", &HisConfigApiController{}, "post:DeletePrescriptionInfoTemplate")
26 35
 	beego.Router("/api/his/advicetemplate/delete", &HisConfigApiController{}, "post:DeleteAdviceTemplate")
@@ -35,6 +44,19 @@ func HisConfigApiRegistRouters() {
35 44
 	beego.Router("/api/his/projectmodetemplate/delete", &HisConfigApiController{}, "post:DeleteModeProjectTemplate")
36 45
 	beego.Router("/api/his/advicempdetemplate/delete", &HisConfigApiController{}, "post:DeleteModeAdviceTemplate")
37 46
 	beego.Router("/api/his/prescriptioninfomodetemplate/delete", &HisConfigApiController{}, "post:DeletePrescriptionInfoModeTemplate")
47
+	beego.Router("/api/his/getdialysismodename", &HisConfigApiController{}, "get:GetDialysisModeName") //根据透析模式获取患者姓名
48
+	beego.Router("/api/his/getdrugsname", &HisConfigApiController{}, "get:GetDrugsName")               //根据类型获取药品名称
49
+	beego.Router("/api/his/getmodeconfigs", &HisConfigApiController{}, "get:GetModeConfigs")
50
+	beego.Router("/api/his/getdrugsinformation", &HisConfigApiController{}, "get:GetDrugsInformation") //根据id获取药品耗材项目基本信息
51
+	beego.Router("/api/his/replacepeoplename", &HisConfigApiController{}, "get:ReplacePeopleName")     //替换——获取患者名字
52
+	beego.Router("/api/his/replaceconfig", &HisConfigApiController{}, "get:ReplaceConfig")
53
+	beego.Router("/api/his/replacesavedrug", &HisConfigApiController{}, "post:ReplaceSaveDrug")          //替换——药品保存
54
+	beego.Router("/api/his/replacesaveproject", &HisConfigApiController{}, "post:ReplaceSaveProject")    //替换——项目保存
55
+	beego.Router("/api/his/deletedrugsbatch", &HisConfigApiController{}, "get:DeleteDrugsBatch")         //批量删除——药品
56
+	beego.Router("/api/his/batchdeleteitems", &HisConfigApiController{}, "get:BatchDeleteItems")         //批量删除——项目
57
+	beego.Router("/api/his/addstemplate", &HisConfigApiController{}, "post:AddsTemplate")                //批量添加
58
+	beego.Router("/api/his/ptemplateinformation", &HisConfigApiController{}, "get:PTemplateInformation") //根据患者id、透析模式获取处方模板信息
59
+	beego.Router("/api/his/deleteone", &HisConfigApiController{}, "get:DeleteOne")                       //删除单条处方模板
38 60
 }
39 61
 
40 62
 func (c *HisConfigApiController) GetAllHisPatientsList() {
@@ -898,3 +920,916 @@ func (c *HisConfigApiController) DeletePrescriptionInfoModeTemplate() {
898 920
 		return
899 921
 	}
900 922
 }
923
+
924
+func (c *HisConfigApiController) GetDialysisModeName() {
925
+	var err error
926
+	defer func() {
927
+		if rec := recover(); rec != nil {
928
+			err = fmt.Errorf("程序异常:%v", rec)
929
+		}
930
+		if err != nil {
931
+			service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
932
+		}
933
+	}()
934
+	orgid := c.GetAdminUserInfo().CurrentOrgId
935
+	mode, _ := c.GetInt64("mode")
936
+	var list []*models.DialysisPatient
937
+	list, err = service.GetDialysisModePatient(orgid, mode)
938
+	if err != nil {
939
+		c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
940
+		return
941
+	}
942
+	c.ServeSuccessJSON(map[string]interface{}{
943
+		"list": list,
944
+	})
945
+	return
946
+
947
+}
948
+func (c *HisConfigApiController) GetDrugsName() {
949
+	var err error
950
+	defer func() {
951
+		if rec := recover(); rec != nil {
952
+			err = fmt.Errorf("程序异常:%v", rec)
953
+		}
954
+		if err != nil {
955
+			service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
956
+		}
957
+	}()
958
+	orgid := c.GetAdminUserInfo().CurrentOrgId
959
+	addtype, _ := c.GetInt("addtype")
960
+	//special,_ := c.GetInt("special")
961
+	//tmpBool := false
962
+	//if special == IsSpecialDiseases{
963
+	//	tmpBool = true
964
+	//}
965
+
966
+	tmp := make(map[string]interface{}, 0)
967
+	if addtype == AddTypeDrug {
968
+		var list []*models.ReplacementDrugs
969
+		list, err = service.ReplacementDrugs(orgid, true)
970
+		if err != nil {
971
+			c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
972
+			return
973
+		}
974
+		var list2 []*models.ReplacementDrugs
975
+		list2, err = service.ReplacementDrugs(orgid, false)
976
+		if err != nil {
977
+			c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
978
+			return
979
+		}
980
+		tmp["list"] = list
981
+		tmp["list2"] = list2
982
+	} else if addtype == AddTypeProject {
983
+		var list3 []*models.DropDownList
984
+		list3, err = service.ProjectConsumables2(orgid, true)
985
+		if err != nil {
986
+			c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
987
+			return
988
+		}
989
+		var list4 []*models.DropDownList
990
+		list4, err = service.ProjectConsumables2(orgid, false)
991
+		if err != nil {
992
+			c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
993
+			return
994
+		}
995
+		tmp["list"] = list3
996
+		tmp["list2"] = list4
997
+	} else {
998
+		err = fmt.Errorf("类型解析错误")
999
+		if err != nil {
1000
+			c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
1001
+			return
1002
+		}
1003
+	}
1004
+	c.ServeSuccessJSON(tmp)
1005
+	return
1006
+
1007
+}
1008
+
1009
+//配置项
1010
+func (c *HisConfigApiController) GetModeConfigs() {
1011
+	var err error
1012
+	defer func() {
1013
+		if rec := recover(); rec != nil {
1014
+			err = fmt.Errorf("程序异常:%v", rec)
1015
+		}
1016
+		if err != nil {
1017
+			service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
1018
+		}
1019
+	}()
1020
+	orgid := c.GetAdminUserInfo().CurrentOrgId
1021
+	var drugways []*models.DrugwayDic
1022
+	var efs []*models.ExecutionFrequencyDic
1023
+	var dataconfig []*models.DictDataconfig
1024
+	drugways, _, err = service.GetDrugWayDics(orgid)
1025
+	if err != nil {
1026
+		c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
1027
+		return
1028
+	}
1029
+	efs, _, err = service.GetExecutionFrequencyDics(orgid)
1030
+	if err != nil {
1031
+		c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
1032
+		return
1033
+	}
1034
+	dataconfig, err = service.GetDataConfig(orgid)
1035
+	c.ServeSuccessJSON(map[string]interface{}{
1036
+		"drugways":   drugways,
1037
+		"efs":        efs,
1038
+		"dataconfig": dataconfig, //组
1039
+	})
1040
+	return
1041
+}
1042
+func (c *HisConfigApiController) GetDrugsInformation() {
1043
+	var err error
1044
+	defer func() {
1045
+		if rec := recover(); rec != nil {
1046
+			err = fmt.Errorf("程序异常:%v", rec)
1047
+		}
1048
+		if err != nil {
1049
+			service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
1050
+		}
1051
+	}()
1052
+	orgid := c.GetAdminUserInfo().CurrentOrgId
1053
+	id := c.GetString("id", "")
1054
+	if len(id) == 0 {
1055
+		err = fmt.Errorf("参数错误")
1056
+		c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
1057
+		return
1058
+	}
1059
+	var list interface{}
1060
+	list, err = service.QueryFourTables(id, orgid)
1061
+	if err != nil {
1062
+		c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
1063
+		return
1064
+	}
1065
+	c.ServeSuccessJSON(map[string]interface{}{
1066
+		"list": list,
1067
+	})
1068
+	return
1069
+}
1070
+
1071
+func (c *HisConfigApiController) ReplacePeopleName() {
1072
+	var g errgroup.Group
1073
+	var err error
1074
+	defer func() {
1075
+		if rec := recover(); rec != nil {
1076
+			err = fmt.Errorf("程序异常:%v", rec)
1077
+		}
1078
+		if err != nil {
1079
+			service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
1080
+		}
1081
+	}()
1082
+	orgid := c.GetAdminUserInfo().CurrentOrgId
1083
+	mode, _ := c.GetInt64("mode") //透析模式
1084
+	id := c.GetString("id", "")   //药品/项目/耗材id
1085
+	if id == "" {
1086
+		c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
1087
+		return
1088
+	}
1089
+	var list []*models.DialysisPatient
1090
+	finlist := make([]*models.DialysisPatient, 0) //筛选后的列表
1091
+	list, err = service.GetDialysisModePatient(orgid, mode)
1092
+	if err != nil {
1093
+		c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
1094
+		return
1095
+	}
1096
+	for _, v := range list {
1097
+		v := v
1098
+		g.Go(func() error {
1099
+			//判断该患者是否有使用该药品/项目/耗材
1100
+			tmpid := id[:1]
1101
+			bo := false
1102
+			if tmpid == "p" {
1103
+				pid := id[1:]
1104
+				tmpisid, _ := strconv.ParseInt(pid, 10, 64)
1105
+				tp := service.FindPatientXiang(orgid, v.ID, tmpisid, mode)
1106
+				if tp {
1107
+					bo = true
1108
+				}
1109
+
1110
+			} else if tmpid == "i" {
1111
+				pid := id[1:]
1112
+				tmpisid, _ := strconv.ParseInt(pid, 10, 64)
1113
+				tp := service.FindPatientXiang2(orgid, v.ID, tmpisid, mode)
1114
+				if tp {
1115
+					bo = true
1116
+				}
1117
+			} else {
1118
+				pid := id
1119
+				tmpisid, _ := strconv.ParseInt(pid, 10, 64)
1120
+				tp := service.FindPatientDrug(orgid, v.ID, tmpisid, mode)
1121
+				if tp {
1122
+					bo = true
1123
+				}
1124
+			}
1125
+			if bo {
1126
+				finlist = append(finlist, v)
1127
+			}
1128
+			return nil
1129
+		})
1130
+	}
1131
+	if err = g.Wait(); err != nil {
1132
+		c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
1133
+		return
1134
+	}
1135
+
1136
+	c.ServeSuccessJSON(map[string]interface{}{
1137
+		"list": finlist,
1138
+	})
1139
+	return
1140
+}
1141
+func (c *HisConfigApiController) ReplaceConfig() {
1142
+	var err error
1143
+	defer func() {
1144
+		if rec := recover(); rec != nil {
1145
+			err = fmt.Errorf("程序异常:%v", rec)
1146
+		}
1147
+		if err != nil {
1148
+			service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
1149
+		}
1150
+	}()
1151
+	orgid := c.GetAdminUserInfo().CurrentOrgId
1152
+	tmp := make(map[string]interface{}, 0)
1153
+	var list []*models.ReplacementDrugs
1154
+	var list2 []*models.DropDownList
1155
+	list, err = service.ReplacementDrugsT(orgid)
1156
+	if err != nil {
1157
+		c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
1158
+		return
1159
+	}
1160
+	tmp["list"] = list
1161
+	list2, err = service.ProjectConsumables2T(orgid)
1162
+	if err != nil {
1163
+		c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
1164
+		return
1165
+	}
1166
+	tmp["list2"] = list2
1167
+	c.ServeSuccessJSON(tmp)
1168
+	return
1169
+
1170
+}
1171
+
1172
+//批量替换——药品
1173
+func (c *HisConfigApiController) ReplaceSaveDrug() {
1174
+	var g errgroup.Group
1175
+	var err error
1176
+	tx := service.XTWriteDB().Begin()
1177
+	defer func() {
1178
+		if rec := recover(); rec != nil {
1179
+			err = fmt.Errorf("程序异常:%v", rec)
1180
+		}
1181
+		if err != nil {
1182
+			service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
1183
+			tx.Rollback()
1184
+		} else {
1185
+			tx.Commit()
1186
+		}
1187
+	}()
1188
+	mode_id, _ := c.GetInt64("mode_id", 0)  //透析模式
1189
+	types, _ := c.GetInt64("type", 1)       //1.药品 2.项目
1190
+	patient_id := c.GetString("patient_id") //患者
1191
+	replaced := c.GetString("replaced", "") //被替换的药品、项目、耗材id
1192
+	orgid := c.GetAdminUserInfo().CurrentOrgId
1193
+	dataBody := make(map[string]interface{}, 0)
1194
+	err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
1195
+	if err != nil {
1196
+		utils.ErrorLog(err.Error())
1197
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1198
+		return
1199
+	}
1200
+	t_ids := ""
1201
+	if patient_id[len(patient_id)-1] == 44 {
1202
+		t_ids = patient_id[:len(patient_id)-1]
1203
+	} else {
1204
+		t_ids = patient_id
1205
+	}
1206
+	tmp_id := strings.Split(t_ids, ",")
1207
+	ids := service.GetHisInfoTempalteId(mode_id, orgid, types) //获取所有药品模板id
1208
+	drugid, _ := strconv.ParseInt(replaced, 10, 64)
1209
+	for _, v := range tmp_id {
1210
+		v := v
1211
+		g.Go(func() error {
1212
+			pp, _ := strconv.ParseInt(v, 10, 64) //患者id
1213
+			var err error
1214
+			if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
1215
+				prescriptions, _ := dataBody["prescriptions"].([]interface{})
1216
+				if len(prescriptions) > 0 {
1217
+					for _, item := range prescriptions {
1218
+						items := item.(map[string]interface{})
1219
+						var s models.HisPrescriptionAdviceTemplate
1220
+						var tmpdrugid int64
1221
+						if items["drug_name"] != nil && reflect.TypeOf(items["drug_name"]).String() == "string" {
1222
+							tmpdrugid, _ = strconv.ParseInt(items["drug_name"].(string), 10, 64)
1223
+						}
1224
+						if items["drug_name"] != nil && reflect.TypeOf(items["drug_name"]).String() == "float64" {
1225
+							tmpdrugid = int64(items["drug_name"].(float64))
1226
+						}
1227
+						s.AdviceName = service.FindDrugsName(tmpdrugid) //药品名称
1228
+						if items["id"] == nil {
1229
+							err = fmt.Errorf("缺少参数")
1230
+							return err
1231
+						} else {
1232
+							if items["id"] != nil && reflect.TypeOf(items["id"]).String() == "string" {
1233
+								tmp_drugid := items["id"].(string)
1234
+								drug_id, _ := strconv.ParseInt(tmp_drugid, 10, 64)
1235
+								s.DrugId = drug_id //药品id
1236
+							}
1237
+							if items["id"] != nil && reflect.TypeOf(items["id"]).String() == "float64" {
1238
+								drug_id := int64(items["id"].(float64))
1239
+								s.DrugId = drug_id
1240
+							}
1241
+						}
1242
+						if items["remark"] != nil && reflect.TypeOf(items["remark"]).String() == "string" {
1243
+							remark, _ := items["remark"].(string)
1244
+							s.Remark = remark //备注
1245
+						}
1246
+						if items["single_dose"] != nil && reflect.TypeOf(items["single_dose"]).String() == "string" {
1247
+							singleDose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
1248
+							s.SingleDose = singleDose
1249
+						}
1250
+						if items["single_dose"] != nil && reflect.TypeOf(items["single_dose"]).String() == "float64" {
1251
+							singleDose := items["single_dose"].(float64)
1252
+							s.SingleDose = singleDose
1253
+						}
1254
+						if items["single_dose_unit"] != nil && reflect.TypeOf(items["single_dose_unit"]).String() == "string" {
1255
+							singleDoseUnit, _ := items["single_dose_unit"].(string)
1256
+							s.SingleDoseUnit = singleDoseUnit
1257
+						}
1258
+						if items["prescribing_number"] != nil && reflect.TypeOf(items["prescribing_number"]).String() == "string" {
1259
+							prescribingNumber, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
1260
+							s.PrescribingNumber = prescribingNumber
1261
+						}
1262
+						if items["prescribing_number"] != nil && reflect.TypeOf(items["prescribing_number"]).String() == "float64" {
1263
+							prescribingNumber := items["prescribing_number"].(float64)
1264
+							s.PrescribingNumber = prescribingNumber
1265
+						}
1266
+						if items["prescribing_number_unit"] != nil && reflect.TypeOf(items["prescribing_number_unit"]).String() == "string" {
1267
+							prescribingNumberUnit, _ := items["prescribing_number_unit"].(string)
1268
+							s.PrescribingNumberUnit = prescribingNumberUnit
1269
+						}
1270
+						if items["delivery_way"] != nil && reflect.TypeOf(items["delivery_way"]).String() == "string" {
1271
+							deliveryWay, _ := items["delivery_way"].(string)
1272
+							s.DeliveryWay = deliveryWay
1273
+						}
1274
+						if items["execution_frequency"] != nil && reflect.TypeOf(items["execution_frequency"]).String() == "string" {
1275
+							executionFrequency, _ := items["execution_frequency"].(string)
1276
+							s.ExecutionFrequency = executionFrequency
1277
+						}
1278
+						if items["price"] != nil && reflect.TypeOf(items["price"]).String() == "string" {
1279
+							price, _ := strconv.ParseFloat(items["price"].(string), 64)
1280
+							s.Price = price
1281
+						}
1282
+						if items["price"] != nil && reflect.TypeOf(items["price"]).String() == "float64" {
1283
+							price := items["price"].(float64)
1284
+							s.Price = price
1285
+						}
1286
+						if items["day"] != nil && reflect.TypeOf(items["day"]).String() == "string" {
1287
+							day, _ := strconv.ParseInt(items["day"].(string), 10, 64)
1288
+							s.Day = day
1289
+						}
1290
+						if items["day"] != nil && reflect.TypeOf(items["day"]).String() == "float64" {
1291
+							day := int64(items["day"].(float64))
1292
+							s.Day = day
1293
+						}
1294
+						s.FrequencyType = 1
1295
+						err = service.ReplaceDrugPrescriptionTemplate(orgid, pp, drugid, ids, s, tx)
1296
+						if err != nil {
1297
+							return err
1298
+						}
1299
+
1300
+					}
1301
+					return nil
1302
+				}
1303
+			}
1304
+			return err
1305
+		})
1306
+	}
1307
+	if errs := g.Wait(); errs != nil {
1308
+		err = errs
1309
+		c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errs.Error())
1310
+		return
1311
+	}
1312
+	c.ServeSuccessJSON(map[string]interface{}{
1313
+		"list": "替换成功",
1314
+	})
1315
+	return
1316
+}
1317
+
1318
+//批量替换项目
1319
+func (c *HisConfigApiController) ReplaceSaveProject() {
1320
+	var g errgroup.Group
1321
+	var err error
1322
+	tx := service.XTWriteDB().Begin()
1323
+	defer func() {
1324
+		if rec := recover(); rec != nil {
1325
+			err = fmt.Errorf("程序异常:%v", rec)
1326
+		}
1327
+		if err != nil {
1328
+			service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
1329
+			tx.Rollback()
1330
+		} else {
1331
+			tx.Commit()
1332
+		}
1333
+	}()
1334
+	mode_id, _ := c.GetInt64("mode_id", 0)  //透析模式
1335
+	types, _ := c.GetInt64("type", 2)       //1.药品 2.项目
1336
+	patient_id := c.GetString("patient_id") //患者
1337
+	replaced := c.GetString("replaced", "") //被替换的药品、项目、耗材id
1338
+	orgid := c.GetAdminUserInfo().CurrentOrgId
1339
+	dataBody := make(map[string]interface{}, 0)
1340
+	err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
1341
+	if err != nil {
1342
+		utils.ErrorLog(err.Error())
1343
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1344
+		return
1345
+	}
1346
+	t_ids := ""
1347
+	if patient_id[len(patient_id)-1] == 44 {
1348
+		t_ids = patient_id[:len(patient_id)-1]
1349
+	} else {
1350
+		t_ids = patient_id
1351
+	}
1352
+	tmp_id := strings.Split(t_ids, ",")
1353
+	ids := service.GetHisInfoTempalteId(mode_id, orgid, types) //获取所有药品模板id
1354
+	drugid, _ := strconv.ParseInt(replaced[1:], 10, 64)
1355
+	for _, v := range tmp_id {
1356
+		v := v
1357
+		g.Go(func() error {
1358
+			pp, _ := strconv.ParseInt(v, 10, 64) //患者id
1359
+			var err error
1360
+			if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
1361
+				prescriptions, _ := dataBody["prescriptions"].([]interface{})
1362
+				if len(prescriptions) > 0 {
1363
+					for _, item := range prescriptions {
1364
+						items := item.(map[string]interface{})
1365
+						var s models.HisPrescriptionProjectTemplate
1366
+						if items["id"] != nil {
1367
+							id := items["id"].(string)
1368
+							if id != "" {
1369
+								tmpPid := id[1:]
1370
+								project_id, _ := strconv.ParseInt(tmpPid, 10, 64)
1371
+								if id[0] == 112 {
1372
+									s.Type = 2
1373
+								}
1374
+								if id[0] == 105 {
1375
+									s.Type = 3
1376
+								}
1377
+								s.ProjectId = project_id
1378
+							} else {
1379
+								s.ProjectId = int64(0)
1380
+							}
1381
+
1382
+						}
1383
+						if items["frequency_type"] != nil && reflect.TypeOf(items["frequency_type"]).String() == "string" {
1384
+							tmp_drugid := items["frequency_type"].(string)
1385
+							frequency_type, _ := strconv.ParseInt(tmp_drugid, 10, 64)
1386
+							s.FrequencyType = frequency_type
1387
+						}
1388
+						if items["frequency_type"] != nil && reflect.TypeOf(items["frequency_type"]).String() == "float64" {
1389
+							frequency_type := int64(items["frequency_type"].(float64))
1390
+							s.FrequencyType = frequency_type
1391
+						}
1392
+						if items["day_count"] != nil && reflect.TypeOf(items["day_count"]).String() == "string" {
1393
+							tmp_drugid := items["day_count"].(string)
1394
+							day_count, _ := strconv.ParseInt(tmp_drugid, 10, 64)
1395
+							s.DayCount = day_count
1396
+						}
1397
+						if items["day_count"] != nil && reflect.TypeOf(items["day_count"]).String() == "float64" {
1398
+							day_count := int64(items["day_count"].(float64))
1399
+							s.DayCount = day_count
1400
+						}
1401
+						if items["week_day"] != nil && reflect.TypeOf(items["week_day"]).String() == "string" {
1402
+							week_day, _ := items["week_day"].(string)
1403
+							s.WeekDay = week_day
1404
+						}
1405
+						if items["week_day"] != nil && reflect.TypeOf(items["week_day"]).String() == "float64" {
1406
+							week_day := config.ToString(items["week_day"].(float64))
1407
+							s.WeekDay = week_day
1408
+						}
1409
+						if items["price"] != nil && reflect.TypeOf(items["price"]).String() == "string" {
1410
+							price, _ := strconv.ParseFloat(items["price"].(string), 64)
1411
+							s.Price = price
1412
+						}
1413
+
1414
+						if items["price"] != nil && reflect.TypeOf(items["price"]).String() == "float64" {
1415
+							price := items["price"].(float64)
1416
+							s.Price = price
1417
+						}
1418
+						if items["prescribing_number"] != nil && reflect.TypeOf(items["prescribing_number"]).String() == "string" {
1419
+							total, _ := items["prescribing_number"].(string)
1420
+							//totals, _ := strconv.ParseInt(total, 10, 64)
1421
+							s.Count = total
1422
+						}
1423
+						if items["prescribing_number"] != nil && reflect.TypeOf(items["prescribing_number"]).String() == "float64" {
1424
+							total := config.ToString(items["prescribing_number"].(float64))
1425
+							//totals, _ := strconv.ParseInt(total, 10, 64)
1426
+							s.Count = total
1427
+						}
1428
+						if items["single_dose"] != nil && reflect.TypeOf(items["single_dose"]).String() == "string" {
1429
+							single_dose, _ := items["single_dose"].(string)
1430
+							s.SingleDose = single_dose
1431
+						}
1432
+						if items["single_dose"] != nil && reflect.TypeOf(items["single_dose"]).String() == "float64" {
1433
+							single_dose := config.ToString(items["single_dose"].(float64))
1434
+							s.SingleDose = single_dose
1435
+						}
1436
+						if items["delivery_way"] != nil && reflect.TypeOf(items["delivery_way"]).String() == "string" {
1437
+							delivery_way, _ := items["delivery_way"].(string)
1438
+							s.DeliveryWay = delivery_way
1439
+						}
1440
+						if items["execution_frequency"] != nil && reflect.TypeOf(items["execution_frequency"]).String() == "string" {
1441
+							execution_frequency, _ := items["execution_frequency"].(string)
1442
+							s.ExecutionFrequency = execution_frequency
1443
+						}
1444
+						if items["remark"] != nil && reflect.TypeOf(items["remark"]).String() == "string" {
1445
+							remark, _ := items["remark"].(string)
1446
+							s.Remark = remark
1447
+						}
1448
+						if items["day"] != nil && reflect.TypeOf(items["remark"]).String() == "string" {
1449
+							day, _ := items["number_days"].(string)
1450
+							s.Day = day
1451
+						}
1452
+						if items["day"] != nil && reflect.TypeOf(items["remark"]).String() == "float64" {
1453
+							day := config.ToString(items["number_days"].(float64))
1454
+							s.Day = day
1455
+						}
1456
+
1457
+						if items["unit"] != nil && reflect.TypeOf(items["unit"]).String() == "string" {
1458
+							unit, _ := items["unit"].(string)
1459
+							s.Unit = unit
1460
+						}
1461
+						err = service.ReplaceProjectPrescriptionTemplate(orgid, pp, drugid, ids, s, tx)
1462
+						if err != nil {
1463
+							return err
1464
+						}
1465
+
1466
+					}
1467
+					return nil
1468
+				}
1469
+			}
1470
+			return err
1471
+		})
1472
+	}
1473
+	if errs := g.Wait(); errs != nil {
1474
+		err = errs
1475
+		c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errs.Error())
1476
+		return
1477
+	}
1478
+	c.ServeSuccessJSON(map[string]interface{}{
1479
+		"list": "替换成功",
1480
+	})
1481
+	return
1482
+}
1483
+
1484
+//批量删除项目
1485
+func (c *HisConfigApiController) BatchDeleteItems() {
1486
+	var g errgroup.Group
1487
+	var err error
1488
+	tx := service.XTWriteDB().Begin()
1489
+	defer func() {
1490
+		if rec := recover(); rec != nil {
1491
+			err = fmt.Errorf("程序异常:%v", rec)
1492
+		}
1493
+		if err != nil {
1494
+			service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
1495
+			tx.Rollback()
1496
+		} else {
1497
+			tx.Commit()
1498
+		}
1499
+	}()
1500
+	mode_id, _ := c.GetInt64("mode_id", 0)  //透析模式
1501
+	types, _ := c.GetInt64("type", 2)       //1.药品 2.项目
1502
+	patient_id := c.GetString("patient_id") //患者
1503
+	replaced := c.GetString("replaced", "") //被删除的药品、项目、耗材id
1504
+	orgid := c.GetAdminUserInfo().CurrentOrgId
1505
+	t_ids := ""
1506
+	if patient_id[len(patient_id)-1] == 44 {
1507
+		t_ids = patient_id[:len(patient_id)-1]
1508
+	} else {
1509
+		t_ids = patient_id
1510
+	}
1511
+	tmp_id := strings.Split(t_ids, ",")
1512
+	ids := service.GetHisInfoTempalteId(mode_id, orgid, types) //获取所有药品模板id
1513
+	drugid, _ := strconv.ParseInt(replaced[1:], 10, 64)
1514
+	for _, v := range tmp_id {
1515
+		v := v
1516
+		g.Go(func() error {
1517
+			pp, _ := strconv.ParseInt(v, 10, 64) //患者id
1518
+			var err error
1519
+			err = service.DeleteProjectTemplate(orgid, pp, drugid, ids, tx)
1520
+			return err
1521
+		})
1522
+	}
1523
+	if errs := g.Wait(); errs != nil {
1524
+		err = errs
1525
+		c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errs.Error())
1526
+		return
1527
+	}
1528
+	c.ServeSuccessJSON(map[string]interface{}{
1529
+		"list": "删除成功",
1530
+	})
1531
+	return
1532
+}
1533
+
1534
+//批量删除药品
1535
+func (c *HisConfigApiController) DeleteDrugsBatch() {
1536
+	var g errgroup.Group
1537
+	var err error
1538
+	tx := service.XTWriteDB().Begin()
1539
+	defer func() {
1540
+		if rec := recover(); rec != nil {
1541
+			err = fmt.Errorf("程序异常:%v", rec)
1542
+		}
1543
+		if err != nil {
1544
+			service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
1545
+			tx.Rollback()
1546
+		} else {
1547
+			tx.Commit()
1548
+		}
1549
+	}()
1550
+	mode_id, _ := c.GetInt64("mode_id", 0)  //透析模式
1551
+	types, _ := c.GetInt64("type", 1)       //1.药品 2.项目
1552
+	patient_id := c.GetString("patient_id") //患者
1553
+	replaced := c.GetString("replaced", "") //被替换的药品、项目、耗材id
1554
+	orgid := c.GetAdminUserInfo().CurrentOrgId
1555
+	t_ids := ""
1556
+	if patient_id[len(patient_id)-1] == 44 {
1557
+		t_ids = patient_id[:len(patient_id)-1]
1558
+	} else {
1559
+		t_ids = patient_id
1560
+	}
1561
+	tmp_id := strings.Split(t_ids, ",")
1562
+	ids := service.GetHisInfoTempalteId(mode_id, orgid, types) //获取所有药品模板id
1563
+	drugid, _ := strconv.ParseInt(replaced, 10, 64)
1564
+	for _, v := range tmp_id {
1565
+		v := v
1566
+		g.Go(func() error {
1567
+			pp, _ := strconv.ParseInt(v, 10, 64) //患者id
1568
+			var err error
1569
+			err = service.DeletePrescriptionTemplate(orgid, pp, drugid, ids, tx)
1570
+			return err
1571
+		})
1572
+	}
1573
+	if errs := g.Wait(); errs != nil {
1574
+		err = errs
1575
+		c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errs.Error())
1576
+		return
1577
+	}
1578
+	c.ServeSuccessJSON(map[string]interface{}{
1579
+		"list": "删除成功",
1580
+	})
1581
+	return
1582
+}
1583
+
1584
+//批量添加
1585
+func (c *HisConfigApiController) AddsTemplate() {
1586
+	var g errgroup.Group
1587
+	var err error
1588
+	defer func() {
1589
+		if rec := recover(); rec != nil {
1590
+			err = fmt.Errorf("程序异常:%v", rec)
1591
+		}
1592
+		if err != nil {
1593
+			service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
1594
+		}
1595
+	}()
1596
+	//id, _ := c.GetInt64("id")
1597
+	name := c.GetString("name", "")
1598
+	mode_id, _ := c.GetInt64("mode_id", 0)
1599
+	types, _ := c.GetInt64("type", 1) //没啥用
1600
+	patient_id := c.GetString("patient_id")
1601
+	//patient_id, _ := c.GetInt64("patient_id", 0)
1602
+	if name == "" {
1603
+		name = service.DialysisModeName(mode_id)
1604
+	}
1605
+	adminInfo := c.GetAdminUserInfo()
1606
+	dataBody := make(map[string]interface{}, 0)
1607
+	err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
1608
+	if err != nil {
1609
+		utils.ErrorLog(err.Error())
1610
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1611
+		return
1612
+	}
1613
+	t_ids := ""
1614
+	if patient_id[len(patient_id)-1] == 44 {
1615
+		t_ids = patient_id[:len(patient_id)-1]
1616
+	} else {
1617
+		t_ids = patient_id
1618
+	}
1619
+	tmp_id := strings.Split(t_ids, ",")
1620
+	for _, v := range tmp_id {
1621
+		v := v
1622
+		g.Go(func() error {
1623
+			var err error
1624
+			pa, _ := strconv.ParseInt(v, 10, 64)
1625
+			tmp_bool_id := service.IsDialysisMode(adminInfo.CurrentOrgId, pa, mode_id)
1626
+
1627
+			var src_template models.HisPrescriptionTemplate
1628
+			if !tmp_bool_id {
1629
+				template := models.HisPrescriptionTemplate{
1630
+					UserOrgId: adminInfo.CurrentOrgId,
1631
+					PatientId: pa,
1632
+					Type:      types,
1633
+					Status:    1,
1634
+					Ctime:     time.Now().Unix(),
1635
+					Mtime:     time.Now().Unix(),
1636
+					Name:      name,
1637
+					Mode:      mode_id,
1638
+				}
1639
+				src_template = template
1640
+				service.CreateHisPrescriptionTemplate(&src_template)
1641
+			} else {
1642
+				//查询出该模板的id
1643
+				src_template, err = service.IdOfTheTemplate(adminInfo.CurrentOrgId, pa, mode_id)
1644
+				if err != nil {
1645
+					return err
1646
+				}
1647
+				src_template.Name = name
1648
+				src_template.Mode = mode_id
1649
+				service.SaveHisPrescriptionTemplate(&src_template)
1650
+			}
1651
+
1652
+			if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
1653
+				prescriptions, _ := dataBody["prescriptions"].([]interface{})
1654
+				if len(prescriptions) > 0 {
1655
+					for _, item := range prescriptions {
1656
+						items := item.(map[string]interface{})
1657
+
1658
+						id := int64(0)
1659
+						//fmt.Println("111111111111111111111")
1660
+						//if items["type"] == nil {
1661
+						//	utils.ErrorLog("type")
1662
+						//	//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1663
+						//	fmt.Println("222222222222222")
1664
+						//	err = fmt.Errorf("参数错误")
1665
+						//	return err
1666
+						//}
1667
+						//fmt.Println("33333333333")
1668
+						//type1 := types
1669
+						med_type := ""
1670
+						var tmps float64
1671
+						if items["patient_value"] != nil && reflect.TypeOf(items["patient_value"]).String() == "float64" {
1672
+							tmps = items["patient_value"].(float64)
1673
+						}
1674
+						if items["patient_value"] != nil && reflect.TypeOf(items["patient_value"]).String() == "string" {
1675
+							tmps, _ = strconv.ParseFloat(items["patient_value"].(string), 64)
1676
+						}
1677
+						if tmps == 1 {
1678
+							med_type = "11"
1679
+						} else if tmps == 2 {
1680
+							med_type = "14"
1681
+						} else {
1682
+							err = fmt.Errorf("医疗类型参数错误")
1683
+						}
1684
+
1685
+						ctime := time.Now().Unix()
1686
+						prescription := &models.HisPrescriptionInfoTemplate{
1687
+							ID:          id,
1688
+							PatientId:   pa,
1689
+							UserOrgId:   adminInfo.CurrentOrgId,
1690
+							Ctime:       ctime,
1691
+							Mtime:       ctime,
1692
+							Type:        types,
1693
+							Modifier:    adminInfo.AdminUser.Id,
1694
+							Creator:     adminInfo.AdminUser.Id,
1695
+							Status:      1,
1696
+							PTemplateId: src_template.ID,
1697
+							MedType:     med_type,
1698
+						}
1699
+						service.CreateHisPrescriptionInfoTemplate(prescription)
1700
+
1701
+						if items["tableDatas"] != nil && reflect.TypeOf(items["tableDatas"]).String() == "[]interface {}" {
1702
+							advices := items["tableDatas"].([]interface{})
1703
+							//group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
1704
+							groupNo := int64(0)
1705
+							ctime := time.Now().Unix()
1706
+							mtime := ctime
1707
+							if len(advices) > 0 {
1708
+								for k, advice := range advices {
1709
+									var s models.HisPrescriptionAdviceTemplate
1710
+									s.PrescriptionId = prescription.ID
1711
+									s.AdviceType = 2
1712
+									s.StopState = 2
1713
+									s.ExecutionState = 2
1714
+									s.Status = 1
1715
+									s.UserOrgId = adminInfo.CurrentOrgId
1716
+									s.Groupno = groupNo
1717
+									s.CreatedTime = ctime
1718
+									s.UpdatedTime = mtime
1719
+									s.PatientId = pa
1720
+									errcode := service.FensetAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
1721
+									if errcode > 0 {
1722
+										//c.ServeFailJSONWithSGJErrorCode(errcode)
1723
+										err = fmt.Errorf("参数错误")
1724
+										return err
1725
+									}
1726
+									if s.FrequencyType == 0 {
1727
+										s.FrequencyType = 1
1728
+									}
1729
+									s.Groupno = int64(k + 1) //序号
1730
+									if s.DrugId != 0 {
1731
+										service.CreateHisPrescriptionAdviceTemplate(&s)
1732
+									}
1733
+								}
1734
+							}
1735
+						}
1736
+						if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
1737
+							projects := items["project"].([]interface{})
1738
+							if len(projects) > 0 {
1739
+								for _, project := range projects {
1740
+									var p models.HisPrescriptionProjectTemplate
1741
+									p.PrescriptionId = prescription.ID
1742
+									p.Ctime = time.Now().Unix()
1743
+									p.Mtime = time.Now().Unix()
1744
+									p.PatientId = pa
1745
+									p.UserOrgId = adminInfo.CurrentOrgId
1746
+									p.Status = 1
1747
+									errcode := service.FensetProjectTemplateWithJSON(&p, project.(map[string]interface{}))
1748
+									if errcode > 0 {
1749
+										//c.ServeFailJSONWithSGJErrorCode(errcode)
1750
+										err = fmt.Errorf("参数错误")
1751
+										return err
1752
+									}
1753
+									if p.FrequencyType == 0 {
1754
+										p.FrequencyType = 1
1755
+									}
1756
+									if p.ProjectId != 0 {
1757
+										service.CreateHisPrescriptionProjectTemplate(&p)
1758
+									}
1759
+
1760
+								}
1761
+							}
1762
+						}
1763
+					}
1764
+					return nil
1765
+				}
1766
+			}
1767
+			return err
1768
+		})
1769
+	}
1770
+	if errs := g.Wait(); errs != nil {
1771
+		err = errs
1772
+		c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errs.Error())
1773
+		return
1774
+	}
1775
+	c.ServeSuccessJSON(map[string]interface{}{
1776
+		"list": "创建成功",
1777
+	})
1778
+	return
1779
+
1780
+}
1781
+
1782
+//根据透析模式和患者id获取该患者的处方内容
1783
+func (c *HisConfigApiController) PTemplateInformation() {
1784
+	var err error
1785
+	defer func() {
1786
+		if rec := recover(); rec != nil {
1787
+			err = fmt.Errorf("程序异常:%v", rec)
1788
+		}
1789
+		if err != nil {
1790
+			service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
1791
+		}
1792
+	}()
1793
+	orgid := c.GetAdminUserInfo().CurrentOrgId
1794
+	mode_id, _ := c.GetInt64("mode_id", 0)    //透析模式
1795
+	patient_id, _ := c.GetInt64("patient_id") //患者
1796
+	list, err := service.PTemplateInformation(orgid, mode_id, patient_id)
1797
+	if err != nil {
1798
+		c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
1799
+		return
1800
+	}
1801
+	c.ServeSuccessJSON(map[string]interface{}{
1802
+		"list": list,
1803
+	})
1804
+	return
1805
+}
1806
+
1807
+//删除单条记录
1808
+func (c *HisConfigApiController) DeleteOne() {
1809
+	var err error
1810
+	defer func() {
1811
+		if rec := recover(); rec != nil {
1812
+			err = fmt.Errorf("程序异常:%v", rec)
1813
+		}
1814
+		if err != nil {
1815
+			service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
1816
+		}
1817
+	}()
1818
+	orgid := c.GetAdminUserInfo().CurrentOrgId
1819
+	types, _ := c.GetInt64("type") //透析模式
1820
+	id, _ := c.GetInt64("id")      //患者
1821
+	err = service.DeleteOne(types, id)
1822
+	if err != nil {
1823
+		c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
1824
+		return
1825
+	}
1826
+	err = service.Scavenger(orgid)
1827
+	if err != nil {
1828
+		c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
1829
+		return
1830
+	}
1831
+	c.ServeSuccessJSON(map[string]interface{}{
1832
+		"list": "成功",
1833
+	})
1834
+	return
1835
+}

+ 24 - 4
controllers/patient_api_controller.go View File

@@ -82,6 +82,15 @@ func PatientApiRegistRouters() {
82 82
 
83 83
 //GetPatientsList 取患者列表
84 84
 func (c *PatientApiController) GetPatientsList() {
85
+	var err error
86
+	defer func() {
87
+		if rec := recover(); rec != nil {
88
+			err = fmt.Errorf("程序异常:%v", rec)
89
+		}
90
+		if err != nil {
91
+			service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
92
+		}
93
+	}()
85 94
 	page, _ := c.GetInt64("page", 1)
86 95
 	limit, _ := c.GetInt64("limit", 10)
87 96
 	schedulType, _ := c.GetInt64("schedul_type", 0)
@@ -132,7 +141,9 @@ func (c *PatientApiController) GetPatientsList() {
132 141
 		theEndtTIme = theTime.Unix()
133 142
 	}
134 143
 
135
-	patients, total, _ := service.GetPatientList(adminUserInfo.CurrentOrgId, keywords, page, limit, schedulType, bindingState, lapseto, source, theStartTIme, theEndtTIme, contagion, reimbursement_way, isscheduling, isprescription, isStartTime, isEndTime)
144
+	var patients []*models.Patients
145
+	var total int64
146
+	patients, total, err = service.GetPatientList(adminUserInfo.CurrentOrgId, keywords, page, limit, schedulType, bindingState, lapseto, source, theStartTIme, theEndtTIme, contagion, reimbursement_way, isscheduling, isprescription, isStartTime, isEndTime)
136 147
 
137 148
 	c.ServeSuccessJSON(map[string]interface{}{
138 149
 		"patients": patients,
@@ -1103,7 +1114,15 @@ func (c *PatientApiController) CreateDryWeights() {
1103 1114
 }
1104 1115
 
1105 1116
 func (c *PatientApiController) CreateGroupAdvice() {
1106
-
1117
+	var err error
1118
+	defer func() {
1119
+		if rec := recover(); rec != nil {
1120
+			err = fmt.Errorf("程序异常:%v", rec)
1121
+		}
1122
+		if err != nil {
1123
+			service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
1124
+		}
1125
+	}()
1107 1126
 	patient, _ := c.GetInt64("id", 0)
1108 1127
 	groupNo, _ := c.GetInt64("groupno", 0)
1109 1128
 
@@ -1113,14 +1132,15 @@ func (c *PatientApiController) CreateGroupAdvice() {
1113 1132
 	}
1114 1133
 
1115 1134
 	adminUserInfo := c.GetAdminUserInfo()
1116
-	patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
1135
+	var patientInfo models.Patients
1136
+	patientInfo, err = service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
1117 1137
 	if patientInfo.ID == 0 {
1118 1138
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
1119 1139
 		return
1120 1140
 	}
1121 1141
 
1122 1142
 	dataBody := make(map[string]interface{}, 0)
1123
-	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
1143
+	err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
1124 1144
 	if err != nil {
1125 1145
 		utils.ErrorLog(err.Error())
1126 1146
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)

+ 111 - 26
controllers/pharmacy_controller.go View File

@@ -5,6 +5,7 @@ import (
5 5
 	"XT_New/models"
6 6
 	"XT_New/service"
7 7
 	"XT_New/utils"
8
+	"fmt"
8 9
 	"github.com/astaxie/beego"
9 10
 	"time"
10 11
 )
@@ -15,36 +16,40 @@ type PharmacyController struct {
15 16
 
16 17
 func PharmacyApiRegistRouters() {
17 18
 	beego.Router("/api/pharmacy/ceshili", &PharmacyController{}, "get:Tlili")
18
-	beego.Router("/api/pharmacy/todaynumber", &PharmacyController{}, "get:TodayNumber")                   //查询今天的待发药,已发药人数(
19
-	beego.Router("/api/pharmacy/waitingdrug", &PharmacyController{}, "get:WaitingDrug")                   //获取当天待发药的所有患者(
20
-	beego.Router("/api/pharmacy/issueddrugs", &PharmacyController{}, "get:IssuedDrug")                    //获取当天已发药的所有患者(
21
-	beego.Router("/api/pharmacy/getpharmacycontent", &PharmacyController{}, "get:GetPharmacyContent")     //获取当天该患者的所有信息(
22
-	beego.Router("/api/pharmacy/dispensingmedicine", &PharmacyController{}, "get:DispensingMedicine")     //患者发药按钮点击(
23
-	beego.Router("/api/pharmacy/drugwithdrawal", &PharmacyController{}, "get:DrugWithdrawal")             //退药按钮点击
24
-	beego.Router("/api/pharmacy/dispensingdetails", &PharmacyController{}, "get:DispensingDetails")       //获取发药明细的患者列表(
25
-	beego.Router("/api/pharmacy/prescriptiondetails", &PharmacyController{}, "get:PrescriptionDetails")   //发药明细-详情(
26
-	beego.Router("/api/pharmacy/dispensemedicine", &PharmacyController{}, "get:DispenseMedicine")         //获取当天已发药的药品(
27
-	beego.Router("/api/pharmacy/waitingmedicine", &PharmacyController{}, "get:WaitingMedicine")           //获取当天待发药的药品(
28
-	beego.Router("/api/pharmacy/getpatientswithdrugs", &PharmacyController{}, "get:GetPatientsWithDrugs") //获取当天该药品的所有患者(
29
-	beego.Router("/api/pharmacy/medicinedeparture", &PharmacyController{}, "get:MedicineDeparture")       //药品发药按钮点击(
30
-	beego.Router("/api/pharmacy/getcurrentname", &PharmacyController{}, "get:GetCurrentName")             //获取当前登录账号的名字(
19
+	beego.Router("/api/pharmacy/todaynumber", &PharmacyController{}, "get:TodayNumber")                     //查询今天的待发药,已发药人数(
20
+	beego.Router("/api/pharmacy/waitingdrug", &PharmacyController{}, "get:WaitingDrug")                     //获取当天待发药的所有患者(
21
+	beego.Router("/api/pharmacy/issueddrugs", &PharmacyController{}, "get:IssuedDrug")                      //获取当天已发药的所有患者(
22
+	beego.Router("/api/pharmacy/getpharmacycontent", &PharmacyController{}, "get:GetPharmacyContent")       //获取当天该患者的所有信息(
23
+	beego.Router("/api/pharmacy/dispensingmedicine", &PharmacyController{}, "get:DispensingMedicine")       //患者发药按钮点击(
24
+	beego.Router("/api/pharmacy/drugwithdrawal", &PharmacyController{}, "get:DrugWithdrawal")               //退药按钮点击
25
+	beego.Router("/api/pharmacy/dispensingdetails", &PharmacyController{}, "get:DispensingDetails")         //获取发药明细的患者列表(
26
+	beego.Router("/api/pharmacy/prescriptiondetails", &PharmacyController{}, "get:PrescriptionDetails")     //发药明细-详情(
27
+	beego.Router("/api/pharmacy/dispensemedicine", &PharmacyController{}, "get:DispenseMedicine")           //获取当天已发药的药品(
28
+	beego.Router("/api/pharmacy/waitingmedicine", &PharmacyController{}, "get:WaitingMedicine")             //获取当天待发药的药品(
29
+	beego.Router("/api/pharmacy/getpatientswithdrugs", &PharmacyController{}, "get:GetPatientsWithDrugs")   //获取当天该药品的所有患者(
30
+	beego.Router("/api/pharmacy/medicinedeparture", &PharmacyController{}, "get:MedicineDeparture")         //药品发药按钮点击(
31
+	beego.Router("/api/pharmacy/getcurrentname", &PharmacyController{}, "get:GetCurrentName")               //获取当前登录账号的名字(
32
+	beego.Router("/api/pharmacy/getpartitionlist", &PharmacyController{}, "get:GetPartitionList")           //获取当前机构的分区列表
33
+	beego.Router("/api/pharmacy/routeofadministration", &PharmacyController{}, "get:RouteOfAdministration") //获取当前机构的给药途径
31 34
 }
32 35
 func (this *PharmacyController) Tlili() {
33
-	times := this.GetString("time", "")
34
-	timeLayout := "2006-01-02"
35
-	loc, _ := time.LoadLocation("Local")
36
-	var stime, etime int64
37
-	if times == "" {
38
-		stime, etime = service.GetNowTime()
39
-	} else {
40
-		stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
41
-		stime = stmp.Unix()
42
-		etime = stime + 86399
36
+	var err error
37
+	defer func() {
38
+		if rec := recover(); rec != nil {
39
+			err = fmt.Errorf("程序异常:%v", rec)
40
+		}
41
+		if err != nil {
42
+			service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
43
+		}
44
+	}()
45
+	var list2 []*models.ReplacementDrugs
46
+	list2, err = service.ReplacementDrugs(9675, false)
47
+	if err != nil {
48
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
49
+		return
43 50
 	}
44
-	orgid := this.GetAdminUserInfo().CurrentOrgId
45
-	service.InitDrugidIsNil(orgid, stime, etime)
46 51
 	this.ServeSuccessJSON(map[string]interface{}{
47
-		"list": "err",
52
+		"list": list2,
48 53
 	})
49 54
 	return
50 55
 }
@@ -60,6 +65,9 @@ func (this *PharmacyController) GetCurrentName() {
60 65
 func (this *PharmacyController) TodayNumber() {
61 66
 	var err error
62 67
 	defer func() {
68
+		if rec := recover(); rec != nil {
69
+			err = fmt.Errorf("程序异常:%v", rec)
70
+		}
63 71
 		if err != nil {
64 72
 			service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
65 73
 		}
@@ -100,6 +108,9 @@ func (this *PharmacyController) TodayNumber() {
100 108
 func (this *PharmacyController) IssuedDrug() {
101 109
 	var err error
102 110
 	defer func() {
111
+		if rec := recover(); rec != nil {
112
+			err = fmt.Errorf("程序异常:%v", rec)
113
+		}
103 114
 		if err != nil {
104 115
 			service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
105 116
 		}
@@ -133,6 +144,9 @@ func (this *PharmacyController) IssuedDrug() {
133 144
 func (this *PharmacyController) WaitingDrug() {
134 145
 	var err error
135 146
 	defer func() {
147
+		if rec := recover(); rec != nil {
148
+			err = fmt.Errorf("程序异常:%v", rec)
149
+		}
136 150
 		if err != nil {
137 151
 			service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
138 152
 		}
@@ -168,6 +182,9 @@ func (this *PharmacyController) WaitingDrug() {
168 182
 func (this *PharmacyController) GetPharmacyContent() {
169 183
 	var err error
170 184
 	defer func() {
185
+		if rec := recover(); rec != nil {
186
+			err = fmt.Errorf("程序异常:%v", rec)
187
+		}
171 188
 		if err != nil {
172 189
 			service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
173 190
 		}
@@ -207,6 +224,9 @@ func (this *PharmacyController) GetPharmacyContent() {
207 224
 func (this *PharmacyController) DispensingMedicine() {
208 225
 	var err error
209 226
 	defer func() {
227
+		if rec := recover(); rec != nil {
228
+			err = fmt.Errorf("程序异常:%v", rec)
229
+		}
210 230
 		if err != nil {
211 231
 			service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
212 232
 		}
@@ -241,6 +261,9 @@ func (this *PharmacyController) DispensingMedicine() {
241 261
 func (this *PharmacyController) DrugWithdrawal() {
242 262
 	var err error
243 263
 	defer func() {
264
+		if rec := recover(); rec != nil {
265
+			err = fmt.Errorf("程序异常:%v", rec)
266
+		}
244 267
 		if err != nil {
245 268
 			service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
246 269
 		}
@@ -276,6 +299,9 @@ func (this *PharmacyController) DrugWithdrawal() {
276 299
 func (this *PharmacyController) DispensingDetails() {
277 300
 	var err error
278 301
 	defer func() {
302
+		if rec := recover(); rec != nil {
303
+			err = fmt.Errorf("程序异常:%v", rec)
304
+		}
279 305
 		if err != nil {
280 306
 			service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
281 307
 		}
@@ -321,6 +347,9 @@ func (this *PharmacyController) DispensingDetails() {
321 347
 func (this *PharmacyController) PrescriptionDetails() {
322 348
 	var err error
323 349
 	defer func() {
350
+		if rec := recover(); rec != nil {
351
+			err = fmt.Errorf("程序异常:%v", rec)
352
+		}
324 353
 		if err != nil {
325 354
 			service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
326 355
 		}
@@ -351,6 +380,9 @@ func (this *PharmacyController) PrescriptionDetails() {
351 380
 func (this *PharmacyController) DispenseMedicine() {
352 381
 	var err error
353 382
 	defer func() {
383
+		if rec := recover(); rec != nil {
384
+			err = fmt.Errorf("程序异常:%v", rec)
385
+		}
354 386
 		if err != nil {
355 387
 			service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
356 388
 		}
@@ -386,6 +418,9 @@ func (this *PharmacyController) DispenseMedicine() {
386 418
 func (this *PharmacyController) WaitingMedicine() {
387 419
 	var err error
388 420
 	defer func() {
421
+		if rec := recover(); rec != nil {
422
+			err = fmt.Errorf("程序异常:%v", rec)
423
+		}
389 424
 		if err != nil {
390 425
 			service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
391 426
 		}
@@ -421,6 +456,9 @@ func (this *PharmacyController) WaitingMedicine() {
421 456
 func (this *PharmacyController) GetPatientsWithDrugs() {
422 457
 	var err error
423 458
 	defer func() {
459
+		if rec := recover(); rec != nil {
460
+			err = fmt.Errorf("程序异常:%v", rec)
461
+		}
424 462
 		if err != nil {
425 463
 			service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
426 464
 		}
@@ -456,6 +494,9 @@ func (this *PharmacyController) GetPatientsWithDrugs() {
456 494
 func (this *PharmacyController) MedicineDeparture() {
457 495
 	var err error
458 496
 	defer func() {
497
+		if rec := recover(); rec != nil {
498
+			err = fmt.Errorf("程序异常:%v", rec)
499
+		}
459 500
 		if err != nil {
460 501
 			service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
461 502
 		}
@@ -477,3 +518,47 @@ func (this *PharmacyController) MedicineDeparture() {
477 518
 	})
478 519
 	return
479 520
 }
521
+
522
+func (this *PharmacyController) GetPartitionList() {
523
+	var err error
524
+	defer func() {
525
+		if rec := recover(); rec != nil {
526
+			err = fmt.Errorf("程序异常:%v", rec)
527
+		}
528
+		if err != nil {
529
+			service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
530
+		}
531
+	}()
532
+	orgid := this.GetAdminUserInfo().CurrentOrgId
533
+	list, err := service.GetAllValidDeviceZones(orgid)
534
+	if err != nil {
535
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
536
+		return
537
+	}
538
+	this.ServeSuccessJSON(map[string]interface{}{
539
+		"list": list,
540
+	})
541
+	return
542
+}
543
+
544
+func (this *PharmacyController) RouteOfAdministration() {
545
+	var err error
546
+	defer func() {
547
+		if rec := recover(); rec != nil {
548
+			err = fmt.Errorf("程序异常:%v", rec)
549
+		}
550
+		if err != nil {
551
+			service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
552
+		}
553
+	}()
554
+	orgid := this.GetAdminUserInfo().CurrentOrgId
555
+	list, _, err := service.GetDrugWayDics(orgid)
556
+	if err != nil {
557
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
558
+		return
559
+	}
560
+	this.ServeSuccessJSON(map[string]interface{}{
561
+		"list": list,
562
+	})
563
+	return
564
+}

+ 3 - 0
controllers/supply_order_api_contorller.go View File

@@ -125,6 +125,9 @@ func CheckParams(this *SupplyOrderApiController, m *map[string][]string) (map[st
125 125
 func (this *SupplyOrderApiController) GetSupplyList() {
126 126
 	var err error
127 127
 	defer func() {
128
+		if rec := recover(); rec != nil {
129
+			err = fmt.Errorf("程序异常:%v", rec)
130
+		}
128 131
 		if err != nil {
129 132
 			service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
130 133
 		}

+ 428 - 142
models/pharmacy_models.go View File

@@ -2,183 +2,189 @@ package models
2 2
 
3 3
 //药房表
4 4
 type Pharmary struct {
5
-	ID			int64	`gorm:"column:id" json:"id" form:"id"`
6
-	UserOrgId	int64	`gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
7
-	PatientId  int64	`gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
8
-	Ctime 		int64	`gorm:"column:ctime" json:"ctime" form:"ctime"`
9
-	Mtime 		int64	`gorm:"column:mtime" json:"mtime" form:"mtime"`
10
-	Status 		int64	`gorm:"column:status" json:"status" form:"status"`
11
-	RecordDate  int64	`gorm:"column:record_date" json:"record_date" form:"record_date"`
5
+	ID         int64 `gorm:"column:id" json:"id" form:"id"`
6
+	UserOrgId  int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
7
+	PatientId  int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
8
+	Ctime      int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
9
+	Mtime      int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
10
+	Status     int64 `gorm:"column:status" json:"status" form:"status"`
11
+	RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
12 12
 }
13 13
 
14
-func (Pharmary)TableName() string {
14
+func (Pharmary) TableName() string {
15 15
 	return "sgj_xt.xt_pharmacy"
16 16
 }
17 17
 
18 18
 type XtErrs struct {
19
-	OrgId			int64	`gorm:"column:org_id" json:"org_id" form:"org_id"`
20
-	Route			string	`gorm:"column:route" json:"route" form:"route"`
21
-	Parameter		string	`gorm:"column:parameter" json:"parameter" form:"parameter"`
22
-	Text_err		string	`gorm:"column:text_err" json:"text_err" form:"text_err"`
19
+	OrgId     int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
20
+	Route     string `gorm:"column:route" json:"route" form:"route"`
21
+	Parameter string `gorm:"column:parameter" json:"parameter" form:"parameter"`
22
+	Text_err  string `gorm:"column:text_err" json:"text_err" form:"text_err"`
23 23
 }
24
-func (XtErrs)TableName() string {
24
+
25
+func (XtErrs) TableName() string {
25 26
 	return "sgj_xt.xt_errs"
26 27
 }
27 28
 
28 29
 //病人
29 30
 type TmpPatient struct {
30
-	PatientID int64
31
-	Name string
32
-	DialysisNo string	//透析号
31
+	PatientID  int64
32
+	Name       string
33
+	DialysisNo string //透析号
33 34
 }
34 35
 
35 36
 //药品信息
36 37
 type PharmacyContent struct {
37
-	Name string		//名称
38
+	Name         string //名称
38 39
 	SingleDosage string //单次用量
39
-	Usage string	//用法
40
-	Frequency string //频率
41
-	Days string	//天数
42
-	Total string //总量
43
-	Doctor string	//开立医生
44
-	DataSources string	//数据来源
45
-	Remarks string	//备注
40
+	Usage        string //用法
41
+	Frequency    string //频率
42
+	Days         string //天数
43
+	Total        string //总量
44
+	Doctor       string //开立医生
45
+	DataSources  string //数据来源
46
+	Remarks      string //备注
46 47
 }
48
+
47 49
 //发药明细列表
48 50
 type DispensingList struct {
49
-	PatientID int64	//	患者id
50
-	Name string	//患者姓名
51
-	DoctorId	int64	//医生id
52
-	DoctorName string	//医生姓名
53
-	RecordTime	int64	//发药时间(转化前)
54
-	RecordDate 	string	//发药时间(转化后)
51
+	PatientID  int64  //	患者id
52
+	Name       string //患者姓名
53
+	DoctorId   int64  //医生id
54
+	DoctorName string //医生姓名
55
+	RecordTime int64  //发药时间(转化前)
56
+	RecordDate string //发药时间(转化后)
55 57
 }
56 58
 type PrescripDetailsList struct {
57 59
 	Name string //处方名
58
-	Id int64	//处方id
60
+	Id   int64  //处方id
59 61
 	Pres []*PrescripDetails
60 62
 }
63
+
61 64
 //处方详情
62 65
 type PrescripDetails struct {
63
-	Drugname string		//药品名称
66
+	Drugname     string //药品名称
64 67
 	SingleDosage string //单次用量
65
-	Usage string	//用法
66
-	Frequency string //频率
67
-	Days string	//天数
68
-	Total string //总量
69
-	UnitPrice string//单价
70
-	Remarks string	//备注
68
+	Usage        string //用法
69
+	Frequency    string //频率
70
+	Days         string //天数
71
+	Total        string //总量
72
+	UnitPrice    string //单价
73
+	Remarks      string //备注
71 74
 }
75
+
72 76
 //临时医嘱
73 77
 type StatOrder struct {
74
-	StartTime string//开始时间
75
-	Name string//医嘱名称
76
-	Specifications string //药品规格
77
-	PreQuantity string//开药数量
78
-	SingleDosage string//单次用量
79
-	RouteOfAdministration string//给药途径
80
-	ExecutionFrequency string//执行频率
78
+	StartTime             string //开始时间
79
+	Name                  string //医嘱名称
80
+	Specifications        string //药品规格
81
+	PreQuantity           string //开药数量
82
+	SingleDosage          string //单次用量
83
+	RouteOfAdministration string //给药途径
84
+	ExecutionFrequency    string //执行频率
81 85
 }
86
+
82 87
 //退库用的结构体
83 88
 type SpecialForStock struct {
84
-	BatchNumber 		string	`json:"batch_number"`
85
-	BatchNumberId		int64	`json:"batch_number_id"`
86
-	Dealer				string	`json:"dealer"`
87
-	DrugId				int64	`json:"drug_id"`
88
-	DrugName			string	`json:"drug_name"`
89
-	DrugType			int64	`json:"drug_type"`
90
-	DrugWarehouseInfo	interface{}	`json:"drug_warehouse_info"`
91
-	ExpiryDate			string	`json:"expiry_date"`
92
-	LastPrice			float64	`json:"last_price"`
93
-	Manufacturer		string	`json:"manufacturer"`
94
-	MaxUnit				string	`json:"max_unit"`
95
-	MinUnit				string	`json:"min_unit"`
96
-	Name 				string	`json:"name"`
97
-	Price 				string	`json:"price"`
98
-	ProductDate			string	`json:"product_date"`
99
-	RegisterAccount		string	`json:"register_account"`
100
-	Remark				string	`json:"remark"`
101
-	RetailPrice			string	`json:"retail_price"`
102
-	ReturnCount			string	`json:"return_count"`
103
-
89
+	BatchNumber       string      `json:"batch_number"`
90
+	BatchNumberId     int64       `json:"batch_number_id"`
91
+	Dealer            string      `json:"dealer"`
92
+	DrugId            int64       `json:"drug_id"`
93
+	DrugName          string      `json:"drug_name"`
94
+	DrugType          int64       `json:"drug_type"`
95
+	DrugWarehouseInfo interface{} `json:"drug_warehouse_info"`
96
+	ExpiryDate        string      `json:"expiry_date"`
97
+	LastPrice         float64     `json:"last_price"`
98
+	Manufacturer      string      `json:"manufacturer"`
99
+	MaxUnit           string      `json:"max_unit"`
100
+	MinUnit           string      `json:"min_unit"`
101
+	Name              string      `json:"name"`
102
+	Price             string      `json:"price"`
103
+	ProductDate       string      `json:"product_date"`
104
+	RegisterAccount   string      `json:"register_account"`
105
+	Remark            string      `json:"remark"`
106
+	RetailPrice       string      `json:"retail_price"`
107
+	ReturnCount       string      `json:"return_count"`
104 108
 }
109
+
105 110
 //药品发药药品列表
106 111
 type ListOfDrugs struct {
107
-	ID int64	`json:"id"`		//药品id
108
-	Name string	`json:"name"`	//药品 名称
109
-	Specifications string	`json:"specifications"` //规格
110
-	Stock string	`json:"stock"`  //库存(当前的仓库库存)
112
+	ID             int64  `json:"id"`             //药品id
113
+	Name           string `json:"name"`           //药品 名称
114
+	Specifications string `json:"specifications"` //规格
115
+	Stock          string `json:"stock"`          //库存(当前的仓库库存)
111 116
 }
117
+
112 118
 //病人信息
113 119
 type PatientInformation struct {
114
-	Id			string  `json:"id"`//hid表示his_doctor_advice_info的id ,xid表示xt_doctor_advice的id
115
-	Name 		string  `json:"name"`//患者姓名
116
-	SingleDosage string	`json:"single_dosage"` //单次用量
117
-	Usage string		`json:"usage"`//用法
118
-	Frequency string `json:"frequency"`//频率
119
-	Days string	`json:"days"`//天数
120
-	Total string `json:"total"`//总量
121
-	DataSources string	`json:"data_sources"`//数据来源
122
-	People	string	`json:"people"`//领药人
120
+	Id           string `json:"id"`            //hid表示his_doctor_advice_info的id ,xid表示xt_doctor_advice的id
121
+	Name         string `json:"name"`          //患者姓名
122
+	SingleDosage string `json:"single_dosage"` //单次用量
123
+	Usage        string `json:"usage"`         //用法
124
+	Frequency    string `json:"frequency"`     //频率
125
+	Days         string `json:"days"`          //天数
126
+	Total        string `json:"total"`         //总量
127
+	DataSources  string `json:"data_sources"`  //数据来源
128
+	People       string `json:"people"`        //领药人
123 129
 }
124 130
 type HisDoctorAdviceInfoL struct {
125
-	ID                    int64                  `gorm:"column:id" json:"id" form:"id"`
126
-	UserOrgId             int64                  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
127
-	PatientId             int64                  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
128
-	HisPatientId          int64                  `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
129
-	AdviceType            int64                  `gorm:"column:advice_type" json:"advice_type" form:"advice_type"`
130
-	AdviceDate            int64                  `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
131
-	StartTime             int64                  `gorm:"column:start_time" json:"start_time" form:"start_time"`
132
-	AdviceName            string                 `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
133
-	AdviceDesc            string                 `gorm:"column:advice_desc" json:"advice_desc" form:"advice_desc"`
134
-	ReminderDate          int64                  `gorm:"column:reminder_date" json:"reminder_date" form:"reminder_date"`
135
-	SingleDose            float64                `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
136
-	SingleDoseUnit        string                 `gorm:"column:single_dose_unit" json:"single_dose_unit" form:"single_dose_unit"`
137
-	PrescribingNumber     float64                `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
138
-	PrescribingNumberUnit string                 `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
139
-	DeliveryWay           string                 `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
140
-	ExecutionFrequency    string                 `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
141
-	AdviceDoctor          int64                  `gorm:"column:advice_doctor" json:"advice_doctor" form:"advice_doctor"`
142
-	Status                int64                  `gorm:"column:status" json:"status" form:"status"`
143
-	CreatedTime           int64                  `gorm:"column:created_time" json:"created_time" form:"created_time"`
144
-	UpdatedTime           int64                  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
145
-	AdviceAffirm          string                 `gorm:"column:advice_affirm" json:"advice_affirm" form:"advice_affirm"`
146
-	Remark                string                 `gorm:"column:remark" json:"remark" form:"remark"`
147
-	StopTime              int64                  `gorm:"column:stop_time" json:"stop_time" form:"stop_time"`
148
-	StopReason            string                 `gorm:"column:stop_reason" json:"stop_reason" form:"stop_reason"`
149
-	StopDoctor            int64                  `gorm:"column:stop_doctor" json:"stop_doctor" form:"stop_doctor"`
150
-	StopState             int64                  `gorm:"column:stop_state" json:"stop_state" form:"stop_state"`
151
-	ParentId              int64                  `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
152
-	ExecutionTime         int64                  `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
153
-	ExecutionStaff        int64                  `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
154
-	ExecutionState        int64                  `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
155
-	Checker               int64                  `gorm:"column:checker" json:"checker" form:"checker"`
156
-	RecordDate            int64                  `gorm:"column:record_date" json:"record_date" form:"record_date"`
157
-	DialysisOrderId       int64                  `gorm:"column:dialysis_order_id" json:"dialysis_order_id" form:"dialysis_order_id"`
158
-	CheckTime             int64                  `gorm:"column:check_time" json:"check_time" form:"check_time"`
159
-	CheckState            int64                  `gorm:"column:check_state" json:"check_state" form:"check_state"`
160
-	DrugSpec              float64                `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
161
-	DrugSpecUnit          string                 `gorm:"column:drug_spec_unit" json:"drug_spec_unit" form:"drug_spec_unit"`
162
-	Groupno               int64                  `gorm:"column:groupno" json:"groupno" form:"groupno"`
163
-	RemindType            int64                  `gorm:"column:remind_type" json:"remind_type" form:"remind_type"`
164
-	FrequencyType         int64                  `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
165
-	DayCount              int64                  `gorm:"column:day_count" json:"day_count" form:"day_count"`
166
-	WeekDay               string                 `gorm:"column:week_day" json:"week_day" form:"week_day"`
167
-	TemplateId            string                 `gorm:"column:template_id" json:"template_id" form:"template_id"`
168
-	Modifier              int64                  `gorm:"column:modifier" json:"modifier" form:"modifier"`
169
-	DrugId                int64                  `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
170
-	Price                 float64                `gorm:"column:price" json:"price" form:"price"`
171
-	PrescriptionId        int64                  `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
172
-	MedListCodg           string                 `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
173
-	FeedetlSn             string                 `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
174
-	Day                   int64                  `gorm:"column:day" json:"day" form:"day"`
175
-	Diagnosis             int64                  `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
176
-	Way                   int64                  `gorm:"column:way" json:"way" form:"way"`
177
-	HospApprFlag          int64                  `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
178
-	LmtUsedFlag           int64                  `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
179
-	IsMedicine			  int64					 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
180
-	People				  int64					 `gorm:"column:people" json:"people" form:"people"`
181
-	DispensingTime		  int64					 `gorm:"column:dispensing_time" json:"dispensing_time" form:"dispensing_time"`
131
+	ID                    int64   `gorm:"column:id" json:"id" form:"id"`
132
+	UserOrgId             int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
133
+	PatientId             int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
134
+	HisPatientId          int64   `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
135
+	AdviceType            int64   `gorm:"column:advice_type" json:"advice_type" form:"advice_type"`
136
+	AdviceDate            int64   `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
137
+	StartTime             int64   `gorm:"column:start_time" json:"start_time" form:"start_time"`
138
+	AdviceName            string  `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
139
+	AdviceDesc            string  `gorm:"column:advice_desc" json:"advice_desc" form:"advice_desc"`
140
+	ReminderDate          int64   `gorm:"column:reminder_date" json:"reminder_date" form:"reminder_date"`
141
+	SingleDose            float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
142
+	SingleDoseUnit        string  `gorm:"column:single_dose_unit" json:"single_dose_unit" form:"single_dose_unit"`
143
+	PrescribingNumber     float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
144
+	PrescribingNumberUnit string  `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
145
+	DeliveryWay           string  `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
146
+	ExecutionFrequency    string  `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
147
+	AdviceDoctor          int64   `gorm:"column:advice_doctor" json:"advice_doctor" form:"advice_doctor"`
148
+	Status                int64   `gorm:"column:status" json:"status" form:"status"`
149
+	CreatedTime           int64   `gorm:"column:created_time" json:"created_time" form:"created_time"`
150
+	UpdatedTime           int64   `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
151
+	AdviceAffirm          string  `gorm:"column:advice_affirm" json:"advice_affirm" form:"advice_affirm"`
152
+	Remark                string  `gorm:"column:remark" json:"remark" form:"remark"`
153
+	StopTime              int64   `gorm:"column:stop_time" json:"stop_time" form:"stop_time"`
154
+	StopReason            string  `gorm:"column:stop_reason" json:"stop_reason" form:"stop_reason"`
155
+	StopDoctor            int64   `gorm:"column:stop_doctor" json:"stop_doctor" form:"stop_doctor"`
156
+	StopState             int64   `gorm:"column:stop_state" json:"stop_state" form:"stop_state"`
157
+	ParentId              int64   `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
158
+	ExecutionTime         int64   `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
159
+	ExecutionStaff        int64   `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
160
+	ExecutionState        int64   `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
161
+	Checker               int64   `gorm:"column:checker" json:"checker" form:"checker"`
162
+	RecordDate            int64   `gorm:"column:record_date" json:"record_date" form:"record_date"`
163
+	DialysisOrderId       int64   `gorm:"column:dialysis_order_id" json:"dialysis_order_id" form:"dialysis_order_id"`
164
+	CheckTime             int64   `gorm:"column:check_time" json:"check_time" form:"check_time"`
165
+	CheckState            int64   `gorm:"column:check_state" json:"check_state" form:"check_state"`
166
+	DrugSpec              float64 `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
167
+	DrugSpecUnit          string  `gorm:"column:drug_spec_unit" json:"drug_spec_unit" form:"drug_spec_unit"`
168
+	Groupno               int64   `gorm:"column:groupno" json:"groupno" form:"groupno"`
169
+	RemindType            int64   `gorm:"column:remind_type" json:"remind_type" form:"remind_type"`
170
+	FrequencyType         int64   `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
171
+	DayCount              int64   `gorm:"column:day_count" json:"day_count" form:"day_count"`
172
+	WeekDay               string  `gorm:"column:week_day" json:"week_day" form:"week_day"`
173
+	TemplateId            string  `gorm:"column:template_id" json:"template_id" form:"template_id"`
174
+	Modifier              int64   `gorm:"column:modifier" json:"modifier" form:"modifier"`
175
+	DrugId                int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
176
+	Price                 float64 `gorm:"column:price" json:"price" form:"price"`
177
+	PrescriptionId        int64   `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
178
+	MedListCodg           string  `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
179
+	FeedetlSn             string  `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
180
+	Day                   int64   `gorm:"column:day" json:"day" form:"day"`
181
+	Diagnosis             int64   `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
182
+	Way                   int64   `gorm:"column:way" json:"way" form:"way"`
183
+	HospApprFlag          int64   `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
184
+	LmtUsedFlag           int64   `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
185
+	IsMedicine            int64   `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
186
+	People                int64   `gorm:"column:people" json:"people" form:"people"`
187
+	DispensingTime        int64   `gorm:"column:dispensing_time" json:"dispensing_time" form:"dispensing_time"`
182 188
 }
183 189
 
184 190
 func (HisDoctorAdviceInfoL) TableName() string {
@@ -231,24 +237,304 @@ type XtDoctorAdviceL struct {
231 237
 	UserName              string  `gorm:"column:user_name" json:"user_name" form:"user_name"`
232 238
 	CheckerName           string  `gorm:"column:user_name" json:"name" form:"name"`
233 239
 	Modifier              int64   `gorm:"column:modifier" json:"modifier" form:"modifier"`
234
-	IsMedicine			  int64	  `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
235
-	People				  int64	  `gorm:"column:people" json:"people" form:"people"`
236
-	DispensingTime		  int64	  `gorm:"column:dispensing_time" json:"dispensing_time" form:"dispensing_time"`
240
+	IsMedicine            int64   `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
241
+	People                int64   `gorm:"column:people" json:"people" form:"people"`
242
+	DispensingTime        int64   `gorm:"column:dispensing_time" json:"dispensing_time" form:"dispensing_time"`
237 243
 }
238 244
 
239 245
 func (XtDoctorAdviceL) TableName() string {
240 246
 	return "sgj_xt.xt_doctor_advice"
241 247
 }
248
+
242 249
 type TmpTTT struct {
243 250
 	PatientID int64
244 251
 }
245 252
 type TmpLLL struct {
246
-	DrugId    int64
253
+	DrugId int64
247 254
 }
248 255
 type TmpID struct {
249
-	Id    int64
256
+	Id             int64
250 257
 	DispensingTime int64
251 258
 }
252
-type TmpAdviceDoctor  struct {
253
-	AdviceDoctor    int64
259
+type TmpAdviceDoctor struct {
260
+	AdviceDoctor int64
261
+}
262
+
263
+//替换药品名称
264
+type ReplacementDrugs struct {
265
+	Id   int64  `json:"id"`
266
+	Name string `json:"name"`
267
+}
268
+
269
+//病人
270
+type DialysisPatient struct {
271
+	ID   int64  `json:"id"`
272
+	Name string `json:"name"`
273
+}
274
+
275
+//项目下拉列表
276
+type DropDownList struct {
277
+	Id   string `json:"id"`
278
+	Name string `json:"name"`
279
+}
280
+type XtHisProjectL struct {
281
+	ID                          int64   `gorm:"column:id" json:"id" form:"id"`
282
+	ProjectName                 string  `gorm:"column:project_name" json:"project_name" form:"project_name"`
283
+	Pinyin                      string  `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
284
+	Wubi                        string  `gorm:"column:wubi" json:"wubi" form:"wubi"`
285
+	Price                       float64 `gorm:"column:price" json:"price" form:"price"`
286
+	Unit                        string  `gorm:"column:unit" json:"unit" form:"unit"`
287
+	CostClassify                int64   `gorm:"column:cost_classify" json:"cost_classify" form:"cost_classify"`
288
+	ExecutiveSection            int64   `gorm:"column:executive_section" json:"executive_section" form:"executive_section"`
289
+	MedicalCoverage             int64   `gorm:"column:medical_coverage" json:"medical_coverage" form:"medical_coverage"`
290
+	StatisticalClassification   int64   `gorm:"column:statistical_classification" json:"statistical_classification" form:"statistical_classification"` //统计分类(组
291
+	DiseaseDirectory            int64   `gorm:"column:disease_directory" json:"disease_directory" form:"disease_directory"`
292
+	IsRecord                    int64   `gorm:"column:is_record" json:"is_record" form:"is_record"`
293
+	MedicalCode                 string  `gorm:"column:medical_code" json:"medical_code" form:"medical_code"`
294
+	TubeColor                   int64   `gorm:"column:tube_color" json:"tube_color" form:"tube_color"`
295
+	MedicalStatus               int64   `gorm:"column:medical_status" json:"medical_status" form:"medical_status"`
296
+	Remark                      string  `gorm:"column:remark" json:"remark" form:"remark"`
297
+	Sign                        int64   `gorm:"column:sign" json:"sign" form:"sign"`
298
+	DefaultNumber               string  `gorm:"column:default_number" json:"prescribing_number" form:"default_number"`
299
+	IsDefault                   int64   `gorm:"column:is_default" json:"is_default" form:"is_default"`
300
+	IsCharge                    int64   `gorm:"column:is_charge" json:"is_charge" form:"is_charge"`
301
+	IsEstimate                  int64   `gorm:"column:is_estimate" json:"is_estimate" form:"is_estimate"`
302
+	IsWorkload                  int64   `gorm:"column:is_workload" json:"is_workload" form:"is_workload"`
303
+	Sort                        string  `gorm:"column:sort" json:"sort" form:"sort"`
304
+	DoctorAdvice                int64   `gorm:"column:doctor_advice" json:"doctor_advice" form:"doctor_advice"`
305
+	UserOrgId                   int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
306
+	Status                      int64   `gorm:"column:status" json:"status" form:"status"`
307
+	CreatedTime                 int64   `gorm:"column:created_time" json:"created_time" form:"created_time"`
308
+	UpdatedTime                 int64   `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
309
+	SingleDose                  string  `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
310
+	ExecutionFrequency          string  `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
311
+	DeliveryWay                 string  `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
312
+	NumberDays                  string  `gorm:"column:number_days" json:"day" form:"number_days"`
313
+	Total                       string  `gorm:"column:total" json:"total" form:"total"`
314
+	Category                    int64   `gorm:"column:category" json:"category" form:"category"`
315
+	IsMark                      int64   `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
316
+	SpecailProject              int64   `gorm:"column:specail_project" json:"specail_project" form:"specail_project"`
317
+	SocialSecurityDirectoryCode string  `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
318
+	RecordDate                  int64   `gorm:"column:record_date" json:"record_date" form:"record_date"`
319
+	Translate                   string  `json:"translate"` //翻译——统计分类(组
320
+}
321
+
322
+func (XtHisProjectL) TableName() string {
323
+	return "sgj_xt.xt_his_project"
324
+}
325
+
326
+type GoodInfoL struct {
327
+	ID                     int64   `gorm:"column:id" json:"id" form:"id"`
328
+	GoodCode               string  `gorm:"column:good_code" json:"good_code" form:"good_code"`
329
+	SpecificationName      string  `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
330
+	GoodTypeId             int64   `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
331
+	GoodUnit               int64   `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
332
+	BuyPrice               float64 `gorm:"column:buy_price" json:"buy_price" form:"buy_price"`
333
+	SellPrice              float64 `gorm:"column:sell_price" json:"sell_price" form:"sell_price"`
334
+	Remark                 string  `gorm:"column:remark" json:"remark" form:"remark"`
335
+	Ctime                  int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
336
+	Mtime                  int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
337
+	Manufacturer           int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
338
+	Dealer                 int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
339
+	ExpiryDateWarnDayCount int64   `gorm:"column:expiry_date_warn_day_count" json:"expiry_date_warn_day_count" form:"expiry_date_warn_day_count"`
340
+	StockWarnCount         int64   `gorm:"column:stock_warn_count" json:"stock_warn_count" form:"stock_warn_count"`
341
+	IsReuse                int64   `gorm:"column:is_reuse" json:"is_reuse" form:"is_reuse"`
342
+	Status                 int64   `gorm:"column:status" json:"status" form:"status"`
343
+	FilmArea               string  `gorm:"column:film_area" json:"film_area" form:"film_area"`
344
+	IsUse                  int64   `gorm:"column:is_use" json:"is_use" form:"is_use"`
345
+	FilmMaterialQuality    string  `gorm:"column:film_material_quality" json:"film_material_quality" form:"film_material_quality"`
346
+	OrgId                  int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
347
+	Modifier               int64   `gorm:"column:modifier" json:"modifier" form:"modifier"`
348
+	Creater                int64   `gorm:"column:creater" json:"creater" form:"creater"`
349
+	GoodName               string  `gorm:"column:good_name" json:"good_name" form:"good_name"`
350
+	Pinyin                 string  `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
351
+	Wubi                   string  `gorm:"column:wubi" json:"wubi" form:"wubi"`
352
+	GoodKind               int64   `gorm:"column:good_kind" json:"good_kind" form:"good_kind"` //组
353
+	MedicalInsuranceLevel  int64   `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
354
+	RetailPrice            float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
355
+	MedicalInsuranceNumber string  `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
356
+	ProvincesCode          string  `gorm:"column:provinces_code" json:"provinces_code" form:"provinces_code"`
357
+
358
+	IsSpecialDiseases           int64                `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
359
+	IsRecord                    int64                `gorm:"column:is_record" json:"is_record" form:"is_record"`
360
+	StatisticsCategory          int64                `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
361
+	GoodStatus                  string               `gorm:"column:good_status" json:"good_status" form:"good_status"`
362
+	DefaultCount                int64                `gorm:"column:default_count" json:"default_count" form:"default_count"`
363
+	Sign                        int64                `gorm:"column:sign" json:"sign" form:"sign"`
364
+	IsDefault                   int64                `gorm:"column:is_default" json:"is_default" form:"is_default"`
365
+	IsChargeUse                 int64                `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
366
+	IsChargePredict             int64                `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
367
+	IsStatisticsWork            int64                `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
368
+	Sort                        int64                `gorm:"column:sort" json:"sort" form:"sort"`
369
+	IsDoctorUse                 int64                `gorm:"column:is_doctor_use" json:"is_doctor_use" form:"is_doctor_use"`
370
+	Agent                       string               `gorm:"column:agent" json:"agent" form:"agent"`
371
+	GoodNumber                  string               `gorm:"column:good_number" json:"good_number" form:"good_number"`
372
+	GoodsType                   GoodsType            `gorm:"ForeignKey:ID;AssociationForeignKey:GoodTypeId" json:"type"`
373
+	CommdityCode                string               `gorm:"column:commdity_code" json:"commdity_code" form:"commdity_code"`
374
+	SocialSecurityDirectoryCode string               `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
375
+	ProductionType              string               `gorm:"column:production_type" json:"production_type" form:"production_type"`
376
+	SpecialMedical              string               `gorm:"column:special_medical" json:"special_medical" form:"special_medical"`
377
+	IsMark                      int64                `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
378
+	MinNumber                   int64                `gorm:"column:min_number" json:"min_number" form:"min_number"`
379
+	PackingUnit                 string               `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
380
+	PackingPrice                float64              `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
381
+	DefaultCountUnit            string               `gorm:"column:default_count_unit" json:"default_count_unit" form:"default_count_unit"`
382
+	MinUnit                     string               `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
383
+	Total                       float64              `gorm:"column:total" json:"total" form:"total"`
384
+	StWarehousingInfo           []*StWarehousingInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"xt_warehouse_info"`
385
+	CancelStockInfo             []*CancelStockInfo   `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"cancel_stock_info"`
386
+	RegisterNumber              string               `gorm:"column:register_number" json:"register_number" form:"register_number"`
387
+	GoodSotckInfo               []*GoodSotckInfo     `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_stock_in"`
388
+	IsUser                      int64                `gorm:"column:is_user" json:"is_user" form:"is_user"`
389
+	Number                      string               `gorm:"column:number" json:"number" form:"number"`
390
+	IsWarehouse                 int64                `gorm:"column:is_warehouse" json:"is_warehouse" form:"is_warehouse"`
391
+	SumCount                    int64                `gorm:"column:sum_count" json:"sum_count" form:"sum_count"`
392
+	BatchRetaiPrice             float64              `gorm:"column:batch_retai_price" json:"batch_retai_price" form:"batch_retai_price"`
393
+	SumInCount                  int64                `gorm:"column:sum_in_count" json:"sum_in_count" form:"sum_in_count"`
394
+	WarehousingInfo             []*WarehousingInfo   `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"warehouse_info"`
395
+	Translate                   string               `json:"translate"` //翻译——统计分类(组
396
+}
397
+
398
+func (GoodInfoL) TableName() string {
399
+	return "sgj_xt.xt_good_information"
400
+}
401
+
402
+type BaseDrugLibL struct {
403
+	ID                          int64   `gorm:"column:id" json:"id" form:"id"`
404
+	DrugName                    string  `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
405
+	Pinyin                      string  `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
406
+	Wubi                        string  `gorm:"column:wubi" json:"wubi" form:"wubi"`
407
+	DrugAlias                   string  `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
408
+	DrugAliasPinyin             string  `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
409
+	DrugAliasWubi               string  `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
410
+	DrugCategory                int64   `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
411
+	DrugSpec                    string  `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
412
+	DrugType                    int64   `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
413
+	DrugStockLimit              string  `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
414
+	DrugOriginPlace             string  `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
415
+	DrugDosageForm              int64   `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
416
+	MedicalInsuranceLevel       int64   `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
417
+	MaxUnit                     string  `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
418
+	MinNumber                   int64   `gorm:"column:min_number" json:"min_number" form:"min_number"`
419
+	MinUnit                     string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
420
+	Dose                        string  `gorm:"column:dose" json:"dose" form:"dose"`
421
+	DoseUnit                    string  `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
422
+	MinPrice                    float64 `gorm:"column:min_price" json:"min_price" form:"min_price"`
423
+	UnitMatrixing               string  `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
424
+	RetailPrice                 float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
425
+	LastPrice                   float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
426
+	DrugControl                 int64   `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
427
+	Number                      string  `gorm:"column:number" json:"number" form:"number"`
428
+	DrugClassify                string  `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
429
+	DrugDose                    float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
430
+	DrugDoseUnit                int64   `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
431
+	MedicalInsuranceNumber      string  `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
432
+	ProvincesCode               string  `gorm:"column:provinces_code" json:"provinces_code" form:"provinces_code"`
433
+	Manufacturer                int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
434
+	PharmacologyCategory        int64   `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
435
+	StatisticsCategory          int64   `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
436
+	Code                        string  `gorm:"column:code" json:"code" form:"code"`
437
+	IsSpecialDiseases           int64   `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
438
+	IsRecord                    int64   `gorm:"column:is_record" json:"is_record" form:"is_record"`
439
+	Agent                       string  `gorm:"column:agent" json:"agent" form:"agent"`
440
+	DrugStatus                  string  `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
441
+	LimitRemark                 string  `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
442
+	DeliveryWay                 string  `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
443
+	ExecutionFrequency          string  `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
444
+	SingleDose                  float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
445
+	SingleDoseUnit              string  `json:"single_dose_unit"` //danwei
446
+	PrescribingNumber           float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
447
+	Label                       int64   `gorm:"column:label" json:"label" form:"label"`
448
+	Sort                        int64   `gorm:"column:sort" json:"sort" form:"sort"`
449
+	IsUseDoctorAdvice           int64   `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
450
+	IsDefault                   int64   `gorm:"column:is_default" json:"is_default" form:"is_default"`
451
+	IsChargePredict             int64   `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
452
+	IsStatisticsWork            int64   `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
453
+	IsChargeUse                 int64   `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
454
+	Status                      int64   `gorm:"column:status" json:"status" form:"status"`
455
+	Ctime                       int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
456
+	Mtime                       int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
457
+	OrgId                       int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
458
+	DrugCode                    string  `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
459
+	Dealer                      int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
460
+	PrescriptionMark            int64   `gorm:"column:prescription_mark" json:"prescription_mark" form:"prescription_mark"`
461
+	RecordDate                  int64   `gorm:"column:record_date" json:"record_date" form:"record_date"`
462
+	DrugRemark                  string  `gorm:"column:drug_remark" json:"drug_remark" form:"drug_remark"`
463
+	SocialSecurityDirectoryCode string  `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
464
+	DoseCode                    string  `gorm:"column:dose_code" json:"dose_code" form:"dose_code"`
465
+	IsMark                      int64   `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
466
+	HospApprFlag                int64   `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
467
+	LmtUsedFlag                 int64   `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
468
+	//MedicineInsurancePercentage []*MedicineInsurancePercentage `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
469
+	DrugDay               string                 `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
470
+	Total                 float64                `gorm:"column:total" json:"total" form:"total"`
471
+	PrescribingNumberUnit string                 `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
472
+	DrugWarehouseInfo     []*XtDrugWarehouseInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug_warehouse_info"`
473
+	IsUse                 int64                  `gorm:"column:is_user" json:"is_user" form:"is_user"`
474
+	BatchRetaiPrice       float64                `gorm:"column:batch_retai_price" json:"batch_retai_price" form:"batch_retai_price"`
475
+	SumCount              int64                  `gorm:"column:sum_count" json:"sum_count" form:"sum_count"`
476
+	SumInCount            int64                  `gorm:"column:sum_in_count" json:"sum_in_count" form:"sum_in_count"`
477
+	IsPharmacy            int64                  `gorm:"column:is_pharmacy" json:"is_pharmacy" form:"is_pharmacy"`
478
+	List1                 interface{}            `json:"list_1"`
479
+	List2                 interface{}            `json:"list_2"`
480
+}
481
+
482
+func (BaseDrugLibL) TableName() string {
483
+	return "xt_base_drug"
484
+}
485
+
486
+//组
487
+type HisPrescriptionInfoTemplateL struct {
488
+	ID                             int64                              `gorm:"column:id" json:"id" form:"id"`
489
+	UserOrgId                      int64                              `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
490
+	RecordDate                     int64                              `gorm:"column:record_date" json:"record_date" form:"record_date"`
491
+	PatientId                      int64                              `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
492
+	Status                         int64                              `gorm:"column:status" json:"status" form:"status"`
493
+	Ctime                          int64                              `gorm:"column:ctime" json:"ctime" form:"ctime"`
494
+	Mtime                          int64                              `gorm:"column:mtime" json:"mtime" form:"mtime"`
495
+	Type                           int64                              `gorm:"column:type" json:"type" form:"type"`
496
+	Creator                        int64                              `gorm:"column:creator" json:"creator" form:"creator"`
497
+	Modifier                       int64                              `gorm:"column:modifier" json:"modifier" form:"modifier"`
498
+	PType                          int64                              `gorm:"column:p_type" json:"p_type" form:"p_type"`
499
+	PTemplateId                    int64                              `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
500
+	HisPrescriptionAdviceTemplate  []*HisPrescriptionAdviceTemplate   `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
501
+	HisPrescriptionProjectTemplate []*HisPrescriptionProjectTemplateL `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
502
+	MedType                        string                             `gorm:"column:med_type" json:"med_type" form:"med_type"`
503
+}
504
+
505
+func (HisPrescriptionInfoTemplateL) TableName() string {
506
+	return "his_prescription_info_template"
507
+}
508
+
509
+type HisPrescriptionProjectTemplateL struct {
510
+	ID                 int64         `gorm:"column:id" json:"id" form:"id"`
511
+	ProjectId          int64         `gorm:"column:project_id" json:"project_id" form:"project_id"`
512
+	Price              float64       `gorm:"column:price" json:"price" form:"price"`
513
+	UserOrgId          int64         `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
514
+	Status             int64         `gorm:"column:status" json:"status" form:"status"`
515
+	Ctime              int64         `gorm:"column:ctime" json:"ctime" form:"ctime"`
516
+	Mtime              int64         `gorm:"column:mtime" json:"mtime" form:"mtime"`
517
+	PatientId          int64         `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
518
+	HisPatientId       int64         `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
519
+	RecordDate         int64         `gorm:"column:record_date" json:"record_date" form:"record_date"`
520
+	Count              string        `gorm:"column:count" json:"count" form:"count"`
521
+	FeedetlSn          string        `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
522
+	MedListCodg        string        `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
523
+	SingleDose         string        `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
524
+	DeliveryWay        string        `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
525
+	ExecutionFrequency string        `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
526
+	Day                string        `gorm:"column:day" json:"day" form:"day"`
527
+	Remark             string        `gorm:"column:remark" json:"remark" form:"remark"`
528
+	Unit               string        `gorm:"column:unit" json:"unit" form:"unit"`
529
+	Type               int64         `gorm:"column:type" json:"type" form:"type"`
530
+	PrescriptionId     int64         `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
531
+	XtHisProject       XtHisProjectL `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
532
+	GoodInfo           GoodInfoL     `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"good_info"`
533
+	FrequencyType      int64         `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
534
+	DayCount           int64         `gorm:"column:day_count" json:"day_count" form:"day_count"`
535
+	WeekDay            string        `gorm:"column:week_day" json:"week_day" form:"week_day"`
536
+}
537
+
538
+func (HisPrescriptionProjectTemplateL) TableName() string {
539
+	return "his_prescription_project_template"
254 540
 }

+ 821 - 0
service/his_config_service.go View File

@@ -1,7 +1,14 @@
1 1
 package service
2 2
 
3 3
 import (
4
+	"XT_New/enums"
4 5
 	"XT_New/models"
6
+	"XT_New/utils"
7
+	"fmt"
8
+	"github.com/astaxie/beego/config"
9
+	"golang.org/x/sync/errgroup"
10
+	"reflect"
11
+	"strconv"
5 12
 	"time"
6 13
 )
7 14
 
@@ -56,3 +63,817 @@ func DelelteHisPrescriptionProjectTemplate(id int64, user_org_id int64) (err err
56 63
 
57 64
 	return
58 65
 }
66
+
67
+//封装保存接口
68
+func FenCreatePrescriptionTemplate(id, mode_id, types, patient_id int64, name string, adminInfo *AdminUserInfo, dataBody map[string]interface{}) (err error) {
69
+	tmp_bool_id := IsDialysisMode(adminInfo.CurrentOrgId, patient_id, mode_id)
70
+
71
+	var src_template models.HisPrescriptionTemplate
72
+	if !tmp_bool_id {
73
+		template := models.HisPrescriptionTemplate{
74
+			UserOrgId: adminInfo.CurrentOrgId,
75
+			PatientId: patient_id,
76
+			Type:      types,
77
+			Status:    1,
78
+			Ctime:     time.Now().Unix(),
79
+			Mtime:     time.Now().Unix(),
80
+			Name:      name,
81
+			Mode:      mode_id,
82
+		}
83
+		src_template = template
84
+		CreateHisPrescriptionTemplate(&src_template)
85
+	} else {
86
+		//查询出该模板的id
87
+		err = XTReadDB().Model(&models.HisPrescriptionTemplate{}).Where("user_org_id = ? and patient_id = ? and status = 1 and mode = ?", adminInfo.CurrentOrgId, patient_id, mode_id).Find(&src_template).Error
88
+		if err != nil {
89
+			return
90
+		}
91
+		src_template.Name = name
92
+		src_template.Mode = mode_id
93
+		SaveHisPrescriptionTemplate(&src_template)
94
+	}
95
+
96
+	if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
97
+		prescriptions, _ := dataBody["prescriptions"].([]interface{})
98
+		if len(prescriptions) > 0 {
99
+			for _, item := range prescriptions {
100
+				items := item.(map[string]interface{})
101
+
102
+				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
103
+					utils.ErrorLog("id")
104
+					//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
105
+					err = fmt.Errorf("参数错误")
106
+					return
107
+				}
108
+
109
+				id := int64(items["id"].(float64))
110
+
111
+				if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
112
+					utils.ErrorLog("type")
113
+					//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
114
+					err = fmt.Errorf("参数错误")
115
+					return
116
+				}
117
+				types := int64(items["type"].(float64))
118
+
119
+				if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
120
+					utils.ErrorLog("med_type")
121
+					//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
122
+					err = fmt.Errorf("参数错误")
123
+					return
124
+				}
125
+				med_type := strconv.Itoa(int(items["med_type"].(float64)))
126
+
127
+				ctime := time.Now().Unix()
128
+				prescription := &models.HisPrescriptionInfoTemplate{
129
+					ID:          id,
130
+					PatientId:   patient_id,
131
+					UserOrgId:   adminInfo.CurrentOrgId,
132
+					Ctime:       ctime,
133
+					Mtime:       ctime,
134
+					Type:        types,
135
+					Modifier:    adminInfo.AdminUser.Id,
136
+					Creator:     adminInfo.AdminUser.Id,
137
+					Status:      1,
138
+					PTemplateId: src_template.ID,
139
+					MedType:     med_type,
140
+				}
141
+				CreateHisPrescriptionInfoTemplate(prescription)
142
+
143
+				if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
144
+					advices := items["advices"].([]interface{})
145
+					//group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
146
+					groupNo := int64(0)
147
+					ctime := time.Now().Unix()
148
+					mtime := ctime
149
+					if len(advices) > 0 {
150
+						for _, advice := range advices {
151
+							var s models.HisPrescriptionAdviceTemplate
152
+							s.PrescriptionId = prescription.ID
153
+							s.AdviceType = 2
154
+							s.StopState = 2
155
+							s.ExecutionState = 2
156
+							s.Status = 1
157
+							s.UserOrgId = adminInfo.CurrentOrgId
158
+							s.Groupno = groupNo
159
+							s.CreatedTime = ctime
160
+							s.UpdatedTime = mtime
161
+							s.PatientId = patient_id
162
+							errcode := FensetAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
163
+							if errcode > 0 {
164
+								//c.ServeFailJSONWithSGJErrorCode(errcode)
165
+								err = fmt.Errorf("参数错误")
166
+								return
167
+							}
168
+							CreateHisPrescriptionAdviceTemplate(&s)
169
+						}
170
+					}
171
+				}
172
+				if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
173
+					projects := items["project"].([]interface{})
174
+					if len(projects) > 0 {
175
+						for _, project := range projects {
176
+							var p models.HisPrescriptionProjectTemplate
177
+							p.PrescriptionId = prescription.ID
178
+							p.Ctime = time.Now().Unix()
179
+							p.Mtime = time.Now().Unix()
180
+							p.PatientId = patient_id
181
+							p.UserOrgId = adminInfo.CurrentOrgId
182
+							p.Status = 1
183
+							errcode := FensetProjectTemplateWithJSON(&p, project.(map[string]interface{}))
184
+							if errcode > 0 {
185
+								//c.ServeFailJSONWithSGJErrorCode(errcode)
186
+								err = fmt.Errorf("参数错误")
187
+								return
188
+							}
189
+							CreateHisPrescriptionProjectTemplate(&p)
190
+
191
+						}
192
+					}
193
+				}
194
+			}
195
+			return nil
196
+		}
197
+	}
198
+	return
199
+}
200
+
201
+//复制一个setProjectTemplateWithJSON接口
202
+func FensetProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
203
+	if json["id"] != nil {
204
+		id := json["id"].(string)
205
+		if id != "" {
206
+			tmpPid := id[1:]
207
+			project_id, _ := strconv.ParseInt(tmpPid, 10, 64)
208
+			if id[0] == 112 {
209
+				project.Type = 2
210
+			}
211
+			if id[0] == 105 {
212
+				project.Type = 3
213
+			}
214
+			project.ProjectId = project_id
215
+		} else {
216
+			project.ProjectId = int64(0)
217
+		}
218
+
219
+	}
220
+	if json["frequency_type"] != nil && reflect.TypeOf(json["frequency_type"]).String() == "string" {
221
+		tmp_drugid := json["frequency_type"].(string)
222
+		frequency_type, _ := strconv.ParseInt(tmp_drugid, 10, 64)
223
+		project.FrequencyType = frequency_type
224
+	}
225
+	if json["frequency_type"] != nil && reflect.TypeOf(json["frequency_type"]).String() == "float64" {
226
+		frequency_type := int64(json["frequency_type"].(float64))
227
+		project.FrequencyType = frequency_type
228
+	}
229
+
230
+	if json["day_count"] != nil && reflect.TypeOf(json["day_count"]).String() == "string" {
231
+		tmp_drugid := json["day_count"].(string)
232
+		day_count, _ := strconv.ParseInt(tmp_drugid, 10, 64)
233
+		project.DayCount = day_count
234
+	}
235
+	if json["day_count"] != nil && reflect.TypeOf(json["day_count"]).String() == "float64" {
236
+		day_count := int64(json["day_count"].(float64))
237
+		project.DayCount = day_count
238
+	}
239
+
240
+	if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
241
+		week_day, _ := json["week_day"].(string)
242
+		project.WeekDay = week_day
243
+	}
244
+	if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "float64" {
245
+		week_day := config.ToString(json["week_day"].(float64))
246
+		project.WeekDay = week_day
247
+	}
248
+
249
+	//if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
250
+	//	types := int64(json["type"].(float64))
251
+	//	project.Type = types
252
+	//}
253
+	//if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
254
+	//	project_id := int64(json["project_id"].(float64))
255
+	//	project.ProjectId = project_id
256
+	//}
257
+	if json["price"] != nil && reflect.TypeOf(json["price"]).String() == "string" {
258
+		price, _ := strconv.ParseFloat(json["price"].(string), 64)
259
+		project.Price = price
260
+	}
261
+
262
+	if json["price"] != nil && reflect.TypeOf(json["price"]).String() == "float64" {
263
+		price := json["price"].(float64)
264
+		project.Price = price
265
+	}
266
+
267
+	if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
268
+		total, _ := json["prescribing_number"].(string)
269
+		//totals, _ := strconv.ParseInt(total, 10, 64)
270
+		project.Count = total
271
+	}
272
+	if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "float64" {
273
+		total := config.ToString(json["prescribing_number"].(float64))
274
+		//totals, _ := strconv.ParseInt(total, 10, 64)
275
+		project.Count = total
276
+	}
277
+
278
+	//if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
279
+	//	medical_code, _ := json["medical_code"].(string)
280
+	//	project.MedListCodg = medical_code
281
+	//}
282
+	if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
283
+		single_dose, _ := json["single_dose"].(string)
284
+		project.SingleDose = single_dose
285
+	}
286
+	if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "float64" {
287
+		single_dose := config.ToString(json["single_dose"].(float64))
288
+		project.SingleDose = single_dose
289
+	}
290
+
291
+	if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
292
+		delivery_way, _ := json["delivery_way"].(string)
293
+		project.DeliveryWay = delivery_way
294
+	}
295
+	if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
296
+		execution_frequency, _ := json["execution_frequency"].(string)
297
+		project.ExecutionFrequency = execution_frequency
298
+	}
299
+	if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
300
+		remark, _ := json["remark"].(string)
301
+		project.Remark = remark
302
+	}
303
+	if json["day"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
304
+		day, _ := json["number_days"].(string)
305
+		project.Day = day
306
+	}
307
+	if json["day"] != nil && reflect.TypeOf(json["remark"]).String() == "float64" {
308
+		day := config.ToString(json["number_days"].(float64))
309
+		project.Day = day
310
+	}
311
+
312
+	if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
313
+		unit, _ := json["unit"].(string)
314
+		project.Unit = unit
315
+	}
316
+	return 0
317
+}
318
+
319
+//复制一个setAdviceTemplateWithJSON接口
320
+func FensetAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
321
+	//if json["advice_id"] != nil || reflect.TypeOf(json["advice_id"]).String() == "float64" {
322
+	//	advice_id := int64(json["advice_id"].(float64))
323
+	//	advice.ID = advice_id
324
+	//}
325
+
326
+	if json["drug_name"] == nil {
327
+		utils.ErrorLog("drug_name")
328
+		return enums.ErrorCodeParamWrong
329
+	}
330
+	var tmpdrugid int64
331
+	if json["drug_name"] != nil && reflect.TypeOf(json["drug_name"]).String() == "string" {
332
+		tmpdrugid, _ = strconv.ParseInt(json["drug_name"].(string), 10, 64)
333
+	}
334
+	if json["drug_name"] != nil && reflect.TypeOf(json["drug_name"]).String() == "float64" {
335
+		tmpdrugid = int64(json["drug_name"].(float64))
336
+	}
337
+
338
+	advice.AdviceName = FindDrugsName(tmpdrugid)
339
+	//adviceDesc, _ := json["advice_desc"].(string)
340
+	//advice.AdviceDesc = adviceDesc
341
+	//if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
342
+	//	drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
343
+	//	advice.DrugSpec = drugSpec
344
+	//}
345
+
346
+	if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
347
+		remark, _ := json["remark"].(string)
348
+		advice.Remark = remark
349
+	}
350
+
351
+	if json["id"] == nil {
352
+		advice.DrugId = 0
353
+	} else {
354
+		if json["id"] != nil && reflect.TypeOf(json["id"]).String() == "string" {
355
+			tmp_drugid := json["id"].(string)
356
+			drug_id, _ := strconv.ParseInt(tmp_drugid, 10, 64)
357
+			advice.DrugId = drug_id
358
+		}
359
+		if json["id"] != nil && reflect.TypeOf(json["id"]).String() == "float64" {
360
+			drug_id := int64(json["id"].(float64))
361
+			advice.DrugId = drug_id
362
+		}
363
+	}
364
+
365
+	//if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
366
+	//	drugSpecUnit, _ := json["min_unit"].(string)
367
+	//	advice.DrugSpecUnit = drugSpecUnit
368
+	//}
369
+	if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
370
+		singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
371
+		advice.SingleDose = singleDose
372
+	}
373
+	if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "float64" {
374
+		singleDose := json["single_dose"].(float64)
375
+		advice.SingleDose = singleDose
376
+	}
377
+	if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
378
+		singleDoseUnit, _ := json["single_dose_unit"].(string)
379
+		advice.SingleDoseUnit = singleDoseUnit
380
+	}
381
+	if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
382
+		prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
383
+		advice.PrescribingNumber = prescribingNumber
384
+	}
385
+	if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "float64" {
386
+		prescribingNumber := json["prescribing_number"].(float64)
387
+		advice.PrescribingNumber = prescribingNumber
388
+	}
389
+	if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
390
+		prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
391
+		advice.PrescribingNumberUnit = prescribingNumberUnit
392
+	}
393
+	if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
394
+		deliveryWay, _ := json["delivery_way"].(string)
395
+		advice.DeliveryWay = deliveryWay
396
+	}
397
+	if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
398
+		executionFrequency, _ := json["execution_frequency"].(string)
399
+		advice.ExecutionFrequency = executionFrequency
400
+	}
401
+	fmt.Println("44444444444")
402
+	if json["price"] != nil && reflect.TypeOf(json["price"]).String() == "string" {
403
+		price, _ := strconv.ParseFloat(json["price"].(string), 64)
404
+		advice.Price = price
405
+	}
406
+	if json["price"] != nil && reflect.TypeOf(json["price"]).String() == "float64" {
407
+		price := json["price"].(float64)
408
+		advice.Price = price
409
+	}
410
+	//if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
411
+	//	med_list_codg, _ := json["medical_insurance_number"].(string)
412
+	//	advice.MedListCodg = med_list_codg
413
+	//}
414
+	//fmt.Println("333333333")
415
+	if json["day"] != nil && reflect.TypeOf(json["day"]).String() == "string" {
416
+		day, _ := strconv.ParseInt(json["day"].(string), 10, 64)
417
+		advice.Day = day
418
+	}
419
+	if json["day"] != nil && reflect.TypeOf(json["day"]).String() == "float64" {
420
+		day := int64(json["day"].(float64))
421
+		advice.Day = day
422
+	}
423
+	//if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
424
+	//	groupno := int64(json["groupno"].(float64))
425
+	//	advice.Groupno = groupno
426
+	//}
427
+
428
+	//if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {//原型图没画不考虑
429
+	//	frequency_type := int64(json["frequency_type"].(float64))
430
+	//	advice.FrequencyType = frequency_type
431
+	//}
432
+	//
433
+	//if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
434
+	//	day_count := int64(json["day_count"].(float64))
435
+	//	advice.DayCount = day_count
436
+	//}
437
+	//
438
+	//if json["week_day"] != nil || reflect.TypeOf(json["week_day"]).String() == "string" {
439
+	//	week_day, _ := json["week_day"].(string)
440
+	//	advice.WeekDay = week_day
441
+	//}
442
+	//fmt.Println("aaaaaaaaaaaaaaaaaaaaaaaaa")
443
+	return 0
444
+}
445
+
446
+//判断该患者是否有该透析模式
447
+func IsDialysisMode(orgid, patient_id, mode int64) bool {
448
+	var total int
449
+	XTReadDB().Model(&models.HisPrescriptionTemplate{}).Where("user_org_id = ? and patient_id = ? and status = 1 and mode = ?", orgid, patient_id, mode).Count(&total)
450
+	if total > 0 {
451
+		return true
452
+	} else {
453
+		return false
454
+	}
455
+}
456
+
457
+//获取该透析模式的患者列表
458
+func GetDialysisModePatient(orgid, model int64) (list []*models.DialysisPatient, err error) {
459
+	var tmp []*models.DialysisPatient
460
+	err = XTReadDB().Raw("select id,name from xt_patients,(SELECT patient_id FROM his_prescription_template WHERE user_org_id = ? and "+
461
+		"mode = ? and status = 1)a where id = a.patient_id", orgid, model).Scan(&tmp).Error
462
+	if err != nil {
463
+		return
464
+	}
465
+	return tmp, err
466
+}
467
+
468
+//如果没有名字默认透析模式
469
+func DialysisModeName(mode int64) string {
470
+	tmp := make(map[int64]string)
471
+	tmp[1] = "HD"
472
+	tmp[2] = "HDF"
473
+	tmp[3] = "HD+HP"
474
+	tmp[4] = "HP"
475
+	tmp[5] = "HF"
476
+	tmp[6] = "SCUF"
477
+	tmp[7] = "IUF"
478
+	tmp[8] = "HFHD"
479
+	tmp[9] = "HFHD+HP"
480
+	tmp[10] = "PHF"
481
+	tmp[11] = "HFR"
482
+	tmp[12] = "HDF+HP"
483
+	tmp[13] = "CRRT"
484
+	tmp[14] = "腹水回输"
485
+	//tmp[15] = "HD前置换"
486
+	//tmp[16] = "HD后置换"
487
+	//tmp[17] = "HDF前置换"
488
+	//tmp[18] = "HDF后置换"
489
+	tmp[19] = "IUF+HD"
490
+	tmp[20] = "UF"
491
+	tmp[21] = "HD+"
492
+	tmp[22] = "血浆胆红素吸附+HDF"
493
+	tmp[23] = "血浆胆红素吸附"
494
+	tmp[24] = "I-HDF"
495
+	tmp[25] = "HD高通"
496
+	tmp[26] = "CVVH"
497
+	tmp[27] = "CVVHD"
498
+	tmp[28] = "CVVHDF"
499
+	tmp[29] = "PE"
500
+	tmp[30] = "血浆胆红素吸附+HP"
501
+	tmp[31] = "HPD"
502
+	tmp[32] = "HDP"
503
+	if v, ok := tmp[mode]; ok {
504
+		return v
505
+	}
506
+	return ""
507
+}
508
+
509
+//查询出该模板的id
510
+func IdOfTheTemplate(orgid, patient_id, mode_id int64) (src_template models.HisPrescriptionTemplate, err error) {
511
+	err = XTReadDB().Model(&models.HisPrescriptionTemplate{}).Where("user_org_id = ? and "+
512
+		"patient_id = ? and status = 1 and mode = ?", orgid, patient_id, mode_id).Find(&src_template).Error
513
+	return src_template, err
514
+}
515
+
516
+//根据透析模式、患者姓名、药品项目获取处方内容
517
+func GetPrescriptionContent(mode, orgid, patient_id int64) (list []*models.HisPrescriptionInfoTemplate, err error) {
518
+	var tmp models.HisPrescriptionTemplate
519
+	err = XTReadDB().Model(&models.HisPrescriptionTemplate{}).Where("user_org_id = ? and patient_id = ? and mode = ? and status = 1", orgid, patient_id, mode).Find(&tmp).Error
520
+	if err != nil {
521
+		return
522
+	}
523
+	var prescriptions []*models.HisPrescriptionInfoTemplate
524
+	prescriptions, err = GetHisPrescriptionTemplate(tmp.ID, orgid)
525
+	return prescriptions, err
526
+
527
+}
528
+
529
+//获取该透析模式患者列表(批量删除时用)药品
530
+func GetDialysisDrugDelect(orgid, model, drug_id int64) (list []*models.DialysisPatient, err error) {
531
+	var tmp []*models.DialysisPatient
532
+	err = XTReadDB().Raw("select id,name from xt_patients,("+
533
+		"select distinct patient_id from his_prescription_advice_template,("+
534
+		"select his_prescription_info_template.id from his_prescription_info_template,("+
535
+		"SELECT id FROM his_prescription_template WHERE user_org_id = ? and mode = ? and status = 1"+
536
+		")his where status = 1 and his_prescription_info_template.p_template_id = his.id"+
537
+		")hisa where status = 1 and prescription_id = hisa.id and drug_id = ?)a where id = a.patient_id", orgid, model, drug_id).Scan(&tmp).Error
538
+	if err != nil {
539
+		return
540
+	}
541
+	return tmp, err
542
+}
543
+
544
+//获取该透析模式患者列表(批量删除时用)项目
545
+func GetDialysisProjectDelect2(orgid, model, drug_id int64) (list []*models.DialysisPatient, err error) {
546
+	var tmp []*models.DialysisPatient
547
+	err = XTReadDB().Raw("select id,name from xt_patients,("+
548
+		"select distinct patient_id from his_prescription_project_template,("+
549
+		"select his_prescription_info_template.id from his_prescription_info_template,("+
550
+		"SELECT id FROM his_prescription_template WHERE user_org_id = ? and mode = ? and status = 1"+
551
+		")his where status = 1 and his_prescription_info_template.p_template_id = his.id"+
552
+		")hisb where status = 1 and prescription_id = hisb.id and project_id = ? and type = 2)a where id = a.patient_id", orgid, model, drug_id).Scan(&tmp).Error
553
+	if err != nil {
554
+		return
555
+	}
556
+	return tmp, err
557
+}
558
+
559
+//获取该透析模式患者列表(批量删除时用)耗材
560
+func GetDialysisProjectDelect3(orgid, model, drug_id int64) (list []*models.DialysisPatient, err error) {
561
+	var tmp []*models.DialysisPatient
562
+	err = XTReadDB().Raw("select id,name from xt_patients,("+
563
+		"select distinct patient_id from his_prescription_project_template,("+
564
+		"select his_prescription_info_template.id from his_prescription_info_template,("+
565
+		"SELECT id FROM his_prescription_template WHERE user_org_id = ? and mode = ? and status = 1"+
566
+		")his where status = 1 and his_prescription_info_template.p_template_id = his.id"+
567
+		")hisb where status = 1 and prescription_id = hisb.id and project_id = ? and type = 3)a where id = a.patient_id", orgid, model, drug_id).Scan(&tmp).Error
568
+	if err != nil {
569
+		return
570
+	}
571
+	return tmp, err
572
+}
573
+
574
+//根据透析模式删除药品
575
+func ModeDeleteDrug(orgid, model, drug_id int64, patient_id []int64) (err error) {
576
+	//开事务
577
+	tx := XTWriteDB().Begin()
578
+	defer func() {
579
+		if err != nil {
580
+			utils.ErrorLog("事务失败,原因为: %v", err)
581
+			tx.Rollback()
582
+		} else {
583
+			tx.Commit()
584
+		}
585
+	}()
586
+	var g errgroup.Group
587
+	var tmp []*models.DialysisPatient
588
+	err = tx.Raw("select his_prescription_advice_template.id from his_prescription_advice_template,("+
589
+		"select his_prescription_info_template.id from his_prescription_info_template,("+
590
+		"SELECT id FROM his_prescription_template WHERE user_org_id = ? and mode = ? and status = 1"+
591
+		")his where status = 1 and his_prescription_info_template.p_template_id = his.id"+
592
+		")hisa where status = 1 and prescription_id = hisa.id and drug_id = ? and patient_id in (?)", orgid, model, drug_id, patient_id).Scan(&tmp).Error
593
+	for _, v := range tmp {
594
+		g.Go(func() error {
595
+			tmp := v
596
+			var err error
597
+			err = tx.Model(&models.HisPrescriptionAdviceTemplate{}).Where("id = ?", tmp.ID).Updates(map[string]interface{}{
598
+				"status":       0,
599
+				"updated_time": time.Now().Unix(),
600
+			}).Error
601
+			return err
602
+		})
603
+	}
604
+	if errs := g.Wait(); errs != nil {
605
+		err = errs
606
+		return
607
+	}
608
+	return
609
+}
610
+
611
+//根据透析模式删除项目和耗材
612
+func ModeDelectItemsAndConsumables(orgid, model int64, drug_id string, patient_id []int64) (err error) {
613
+	//开事务
614
+	tx := XTWriteDB().Begin()
615
+	defer func() {
616
+		if err != nil {
617
+			utils.ErrorLog("事务失败,原因为: %v", err)
618
+			tx.Rollback()
619
+		} else {
620
+			tx.Commit()
621
+		}
622
+	}()
623
+	front := drug_id[:1]
624
+	after := drug_id[1:]
625
+	project_id, _ := strconv.ParseInt(after, 10, 64)
626
+	var g errgroup.Group
627
+	var tmp []*models.DialysisPatient
628
+	if front == "p" {
629
+		err = tx.Raw("select his_prescription_project_template.id from his_prescription_project_template,("+
630
+			"select his_prescription_info_template.id from his_prescription_info_template,("+
631
+			"SELECT id FROM his_prescription_template WHERE user_org_id = ? and mode = ? and status = 1"+
632
+			")his where status = 1 and his_prescription_info_template.p_template_id = his.id"+
633
+			")hisb where status = 1 and prescription_id = hisb.id and project_id = ? and type = 2 and patient_id in (?)", orgid, model, project_id, patient_id).Scan(&tmp).Error
634
+		if err != nil {
635
+			return
636
+		}
637
+	}
638
+	if front == "i" {
639
+		err = tx.Raw("select his_prescription_project_template.id from his_prescription_project_template,("+
640
+			"select his_prescription_info_template.id from his_prescription_info_template,("+
641
+			"SELECT id FROM his_prescription_template WHERE user_org_id = ? and mode = ? and status = 1"+
642
+			")his where status = 1 and his_prescription_info_template.p_template_id = his.id"+
643
+			")hisb where status = 1 and prescription_id = hisb.id and project_id = ? and type = 3 and patient_id in (?)", orgid, model, project_id, patient_id).Scan(&tmp).Error
644
+		if err != nil {
645
+			return
646
+		}
647
+	}
648
+	for _, v := range tmp {
649
+		g.Go(func() error {
650
+			tmp := v
651
+			var err error
652
+			err = tx.Model(&models.HisPrescriptionProjectTemplate{}).Where("id = ?", tmp.ID).Updates(map[string]interface{}{
653
+				"status": 0,
654
+				"mtime":  time.Now().Unix(),
655
+			}).Error
656
+			return err
657
+		})
658
+	}
659
+	if errs := g.Wait(); errs != nil {
660
+		err = errs
661
+		return
662
+	}
663
+	return
664
+}
665
+
666
+//替换该透析模式药品
667
+func ReplaceDrug(orgid, model, drug_id int64, patient_id []int64, advice models.HisPrescriptionAdviceTemplate) (err error) {
668
+	//开事务
669
+	tx := XTWriteDB().Begin()
670
+	defer func() {
671
+		if err != nil {
672
+			utils.ErrorLog("事务失败,原因为: %v", err)
673
+			tx.Rollback()
674
+		} else {
675
+			tx.Commit()
676
+		}
677
+	}()
678
+	var g errgroup.Group
679
+	var tmp []*models.DialysisPatient
680
+	err = tx.Raw("select his_prescription_advice_template.id from his_prescription_advice_template,("+
681
+		"select his_prescription_info_template.id from his_prescription_info_template,("+
682
+		"SELECT id FROM his_prescription_template WHERE user_org_id = ? and mode = ? and status = 1"+
683
+		")his where status = 1 and his_prescription_info_template.p_template_id = his.id"+
684
+		")hisa where status = 1 and prescription_id = hisa.id and drug_id = ? and patient_id in (?)", orgid, model, drug_id, patient_id).Scan(&tmp).Error
685
+	for _, v := range tmp {
686
+		g.Go(func() error {
687
+			tmp := v
688
+			var err error
689
+			err = tx.Model(&models.HisPrescriptionAdviceTemplate{}).Where("id = ?", tmp.ID).Updates(map[string]interface{}{
690
+				"drug_id":                 advice.DrugId,
691
+				"single_dose":             advice.SingleDose,
692
+				"single_dose_unit":        advice.SingleDoseUnit,
693
+				"delivery_way":            advice.DeliveryWay,
694
+				"execution_frequency":     advice.ExecutionFrequency,
695
+				"day":                     advice.Day,
696
+				"prescribing_number":      advice.PrescribingNumber,
697
+				"prescribing_number_unit": advice.PrescribingNumberUnit,
698
+				"price":                   advice.Price,
699
+				"remark":                  advice.Remark,
700
+				"updated_time":            time.Now().Unix(),
701
+			}).Error
702
+			return err
703
+		})
704
+	}
705
+	if errs := g.Wait(); errs != nil {
706
+		err = errs
707
+		return
708
+	}
709
+	return
710
+}
711
+
712
+//替换该透析模式耗材
713
+func ReplaceItemsAndConsumables(orgid, model int64, drug_id string, patient_id []int64, project models.HisPrescriptionProjectTemplate) (err error) {
714
+	//开事务
715
+	tx := XTWriteDB().Begin()
716
+	defer func() {
717
+		if err != nil {
718
+			utils.ErrorLog("事务失败,原因为: %v", err)
719
+			tx.Rollback()
720
+		} else {
721
+			tx.Commit()
722
+		}
723
+	}()
724
+	front := drug_id[:1]
725
+	after := drug_id[1:]
726
+	project_id, _ := strconv.ParseInt(after, 10, 64)
727
+	var g errgroup.Group
728
+	var tmp []*models.DialysisPatient
729
+	if front == "p" {
730
+		project.Type = 2
731
+		err = tx.Raw("select his_prescription_project_template.id from his_prescription_project_template,("+
732
+			"select his_prescription_info_template.id from his_prescription_info_template,("+
733
+			"SELECT id FROM his_prescription_template WHERE user_org_id = ? and mode = ? and status = 1"+
734
+			")his where status = 1 and his_prescription_info_template.p_template_id = his.id"+
735
+			")hisb where status = 1 and prescription_id = hisb.id and project_id = ? and type = 2 and patient_id in (?)", orgid, model, project_id, patient_id).Scan(&tmp).Error
736
+		if err != nil {
737
+			return
738
+		}
739
+	}
740
+	if front == "i" {
741
+		project.Type = 3
742
+		err = tx.Raw("select his_prescription_project_template.id from his_prescription_project_template,("+
743
+			"select his_prescription_info_template.id from his_prescription_info_template,("+
744
+			"SELECT id FROM his_prescription_template WHERE user_org_id = ? and mode = ? and status = 1"+
745
+			")his where status = 1 and his_prescription_info_template.p_template_id = his.id"+
746
+			")hisb where status = 1 and prescription_id = hisb.id and project_id = ? and type = 3 and patient_id in (?)", orgid, model, project_id, patient_id).Scan(&tmp).Error
747
+		if err != nil {
748
+			return
749
+		}
750
+	}
751
+	for _, v := range tmp {
752
+		g.Go(func() error {
753
+			tmp := v
754
+			var err error
755
+			err = tx.Model(&models.HisPrescriptionProjectTemplate{}).Where("id = ?", tmp.ID).Updates(map[string]interface{}{
756
+				"single_dose":         project.SingleDose,
757
+				"delivery_way":        project.DeliveryWay,
758
+				"execution_frequency": project.ExecutionFrequency,
759
+				"day":                 project.Day,
760
+				"count":               project.Count,
761
+				"price":               project.Price,
762
+				"remark":              project.Remark,
763
+				"type":                project.Type,
764
+				"mtime":               time.Now().Unix(),
765
+			}).Error
766
+			return err
767
+		})
768
+	}
769
+	if errs := g.Wait(); errs != nil {
770
+		err = errs
771
+		return
772
+	}
773
+	return
774
+}
775
+
776
+//跟据id查询药品、项目、耗材、套餐
777
+func QueryFourTables(id string, orgid int64) (tmp interface{}, err error) {
778
+	if id[0] == 112 {
779
+		after := id[1:]
780
+		var project []*models.XtHisProjectL
781
+		err = XTReadDB().Model(&project).Where("id = ?", after).Find(&project).Error
782
+		if err != nil {
783
+			return nil, err
784
+		} else {
785
+			for i := 0; i < len(project); i++ {
786
+				project[i].Translate, err = TranslateZu(project[i].StatisticalClassification, orgid, "统计分类")
787
+				if err != nil {
788
+					return nil, err
789
+				}
790
+			}
791
+			return project, err
792
+		}
793
+
794
+	} else if id[0] == 105 {
795
+		after := id[1:]
796
+		var good []*models.GoodInfoL
797
+		err = XTReadDB().Model(&models.GoodInfoL{}).Where("id = ?", after).Find(&good).Error
798
+		if err != nil {
799
+			return nil, err
800
+		} else {
801
+			for i := 0; i < len(good); i++ {
802
+				good[i].Translate = "耗材"
803
+			}
804
+			return good, err
805
+		}
806
+
807
+	} else if id[0] == 104 {
808
+		after := id[1:]
809
+		var team []*models.XtHisProjectTeam
810
+		err = XTReadDB().Model(&models.XtHisProjectTeam{}).Where("id = ?", after).Find(&team).Error
811
+		if err != nil {
812
+			return nil, err
813
+		} else {
814
+			return team, err
815
+		}
816
+
817
+	} else {
818
+		var lib []*models.BaseDrugLibL
819
+		err = XTReadDB().Model(&models.BaseDrugLibL{}).Where("id = ?", id).Find(&lib).Error
820
+		if err != nil {
821
+			return nil, err
822
+		} else {
823
+			for i := 0; i < len(lib); i++ {
824
+				lib[i].SingleDoseUnit = TypeConversion02(config.ToString(lib[i].DrugDoseUnit))
825
+				if err != nil {
826
+					return nil, err
827
+				}
828
+				type m struct {
829
+					Name string `json:"name"`
830
+				}
831
+				newM := []m{
832
+					{
833
+						lib[i].DoseUnit, //计量单位
834
+					},
835
+					{
836
+						lib[i].MinUnit, //拆零单位
837
+					},
838
+				}
839
+				newN := []m{
840
+					{
841
+						lib[i].MinUnit,
842
+					},
843
+					{
844
+						lib[i].MaxUnit,
845
+					},
846
+				}
847
+				lib[i].List1 = newM
848
+				lib[i].List2 = newN
849
+			}
850
+			return lib, err
851
+		}
852
+	}
853
+}
854
+
855
+//获取机构项目中所用的组
856
+func GetDataConfig(orgid int64) (dataconfig []*models.DictDataconfig, err error) {
857
+	err = XTReadDB().Raw("select * from xt_drug_data_config where parent_id in "+
858
+		"(select id from xt_drug_data_config where name = \"统计分类\" and parent_id = 0) "+
859
+		"and status =1 and (org_id = ? or org_id = 0)", orgid).Scan(&dataconfig).Error
860
+	return
861
+}
862
+
863
+//翻译项目中的组
864
+func TranslateZu(sc, orgid int64, types string) (s string, err error) {
865
+	var dataconfig []*models.DictDataconfig
866
+	tmp := "select * from xt_drug_data_config where parent_id in (select id from xt_drug_data_config where name = \"" + types + "\" and parent_id = 0) and value = " + config.ToString(sc) + " and status = 1 and (org_id = " + config.ToString(orgid) + " or org_id = 0)"
867
+
868
+	err = XTReadDB().Raw(tmp).Scan(&dataconfig).Error
869
+	if err != nil {
870
+		return
871
+	}
872
+	if len(dataconfig) > 1 {
873
+		err = fmt.Errorf("sql数据异常:%v", tmp)
874
+	}
875
+	if len(dataconfig) == 0 {
876
+		return "", err
877
+	}
878
+	return dataconfig[0].Name, err
879
+}

+ 14 - 0
service/his_service.go View File

@@ -2209,6 +2209,20 @@ func GetHisPrescriptionTemplate(template_id int64, org_id int64) (prescription [
2209 2209
 	return
2210 2210
 }
2211 2211
 
2212
+//组
2213
+func GetHisPrescriptionTemplateL(template_id int64, org_id int64) (prescription []*models.HisPrescriptionInfoTemplateL, err error) {
2214
+	err = readDb.Model(&models.HisPrescriptionInfoTemplateL{}).
2215
+		Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
2216
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
2217
+		}).
2218
+		Preload("HisPrescriptionProjectTemplate", func(db *gorm.DB) *gorm.DB {
2219
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisProject").Preload("GoodInfo", "status=1")
2220
+		}).
2221
+		Where("status = 1 AND p_template_id = ? ", template_id).
2222
+		Find(&prescription).Error
2223
+	return
2224
+}
2225
+
2212 2226
 func FindHisConsumablesByID(orgID int64, patient_id int64, recordDate int64, good_id int64) (consumables models.DialysisBeforePrepare, err error) {
2213 2227
 	err = readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND good_id = ?", orgID, patient_id, recordDate, good_id).First(&consumables).Error
2214 2228
 	return

+ 436 - 1
service/pharmacy_service.go View File

@@ -8,9 +8,11 @@ import (
8 8
 	"github.com/astaxie/beego/config"
9 9
 	"github.com/astaxie/beego/context"
10 10
 	"github.com/jinzhu/gorm"
11
+	"golang.org/x/sync/errgroup"
11 12
 	"math"
12 13
 	"strconv"
13 14
 	"strings"
15
+	"sync"
14 16
 	"time"
15 17
 )
16 18
 
@@ -980,7 +982,7 @@ func GetUserAdminName(id, orgID int64) string {
980 982
 	return tmp.UserName
981 983
 }
982 984
 
983
-//根据id查询是否已发药,true已发药,false未发药
985
+//根据id查询是否已发药,true已发药,false未发药gai
984 986
 func GiveTheMedicine(id int64) bool {
985 987
 	var xue models.PharmacyDoctorAdvice
986 988
 	XTReadDB().Model(&models.PharmacyDoctorAdvice{}).Where("id = ?", id).Find(&xue)
@@ -1302,3 +1304,436 @@ func ChangeHisPrescriptionid(id string) (err error) {
1302 1304
 	}
1303 1305
 	return
1304 1306
 }
1307
+
1308
+//获取药品规格
1309
+func ReplacementDrugs(orgid int64, special bool) (list []*models.ReplacementDrugs, err error) {
1310
+	var g errgroup.Group
1311
+	var lib []*models.BaseDrugLib
1312
+	var lock sync.Mutex
1313
+	if special {
1314
+		err = readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? and drug_status not like '%停用%' AND status = 1 and is_special_diseases = 1", orgid).Find(&lib).Error
1315
+	} else {
1316
+		err = readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? and drug_status not like '%停用%'  AND status = 1 ", orgid).Find(&lib).Error
1317
+	}
1318
+	if err != nil {
1319
+		return
1320
+	}
1321
+	for _, v := range lib {
1322
+		v := v
1323
+		g.Go(func() error {
1324
+			var tmp models.Manufacturer
1325
+			err := readDb.Model(&models.Manufacturer{}).Where("id = ?", v.Manufacturer).Find(&tmp).Error
1326
+			if err != nil {
1327
+				return err
1328
+			}
1329
+			lock.Lock()
1330
+			list = append(list, &models.ReplacementDrugs{
1331
+				Id:   v.ID,
1332
+				Name: v.DrugName + " " + v.Dose + v.DoseUnit + "*" + config.ToString(v.MinNumber) + v.MinUnit + "/" + v.MaxUnit + " " + tmp.ManufacturerName,
1333
+			})
1334
+			lock.Unlock()
1335
+			return err
1336
+		})
1337
+	}
1338
+	if errs := g.Wait(); errs != nil {
1339
+		err = errs
1340
+		return
1341
+	}
1342
+	return
1343
+}
1344
+
1345
+//获取药品规格,不考虑特殊病
1346
+func ReplacementDrugsT(orgid int64) (list []*models.ReplacementDrugs, err error) {
1347
+	var lib []*models.BaseDrugLib
1348
+	err = readDb.Model(&models.BaseDrugLib{}).Where("org_id = ?  AND status = 1 and drug_status not like '%停用%' ", orgid).Find(&lib).Error
1349
+	if err != nil {
1350
+		return
1351
+	}
1352
+	for _, v := range lib {
1353
+		var tmp models.Manufacturer
1354
+		err = readDb.Model(&models.Manufacturer{}).Where("id = ?", v.Manufacturer).Find(&tmp).Error
1355
+		if err != nil {
1356
+			return
1357
+		}
1358
+
1359
+		list = append(list, &models.ReplacementDrugs{
1360
+			Id:   v.ID,
1361
+			Name: v.DrugName + " " + v.Dose + v.DoseUnit + "*" + config.ToString(v.MinNumber) + v.MinUnit + "/" + v.PrescribingNumberUnit + " " + tmp.ManufacturerName,
1362
+		})
1363
+	}
1364
+	return
1365
+}
1366
+
1367
+//根据药品id获取药品名字
1368
+func IdToDrugName(id int64) (name string) {
1369
+	var lib models.BaseDrugLib
1370
+	readDb.Model(&models.BaseDrugLib{}).Where("id = ?", id).Find(&lib)
1371
+	return lib.DrugName
1372
+}
1373
+
1374
+//获取项目和耗材和套餐
1375
+func ProjectConsumables3(orgid int64) (list []*models.DropDownList, err error) {
1376
+
1377
+	var project []*models.XtHisProject
1378
+	project, err = GetHisProject(orgid)
1379
+	if err != nil {
1380
+		return
1381
+	}
1382
+	for _, v := range project {
1383
+		list = append(list, &models.DropDownList{
1384
+			Id:   "p" + config.ToString(v.ID),
1385
+			Name: v.ProjectName,
1386
+		})
1387
+	}
1388
+
1389
+	var good []*models.GoodInfo
1390
+	err = XTReadDB().Model(&models.GoodInfo{}).Where("org_id = ? and status = 1", orgid).Find(&good).Error
1391
+	if err != nil {
1392
+		return
1393
+	}
1394
+	for _, v := range good {
1395
+		list = append(list, &models.DropDownList{
1396
+			Id:   "i" + config.ToString(v.ID),
1397
+			Name: v.GoodName,
1398
+		})
1399
+	}
1400
+
1401
+	var team []*models.XtHisProjectTeam
1402
+	team, err = GetAllProjectTeam(orgid)
1403
+	if err != nil {
1404
+		return
1405
+	}
1406
+	for _, v := range team {
1407
+		list = append(list, &models.DropDownList{
1408
+			Id:   "h" + config.ToString(v.ID),
1409
+			Name: v.ProjectTeam,
1410
+		})
1411
+	}
1412
+
1413
+	return
1414
+}
1415
+
1416
+//获取项目和耗材
1417
+func ProjectConsumables2(orgid int64, special bool) (list []*models.DropDownList, err error) {
1418
+
1419
+	var project []*models.XtHisProject
1420
+	if special {
1421
+		err = XTReadDB().Model(&project).Where("user_org_id = ? and medical_status != 1 and status = 1 and disease_directory = 1", orgid).Find(&project).Error
1422
+	} else {
1423
+		err = XTReadDB().Model(&project).Where("user_org_id = ? and medical_status != 1 and status = 1", orgid).Find(&project).Error
1424
+	}
1425
+	if err != nil {
1426
+		return
1427
+	}
1428
+	for _, v := range project {
1429
+		list = append(list, &models.DropDownList{
1430
+			Id:   "p" + config.ToString(v.ID),
1431
+			Name: v.ProjectName,
1432
+		})
1433
+	}
1434
+
1435
+	var good []*models.GoodInfo
1436
+	if special {
1437
+		err = XTReadDB().Model(&models.GoodInfo{}).Where("org_id = ? and good_status not like '%停用%' and status = 1 and is_special_diseases = 1", orgid).Find(&good).Error
1438
+	} else {
1439
+		err = XTReadDB().Model(&models.GoodInfo{}).Where("org_id = ? and good_status not like '%停用%' and status = 1", orgid).Find(&good).Error
1440
+	}
1441
+	if err != nil {
1442
+		return
1443
+	}
1444
+	for _, v := range good {
1445
+		list = append(list, &models.DropDownList{
1446
+			Id:   "i" + config.ToString(v.ID),
1447
+			Name: v.GoodName + " " + v.SpecificationName,
1448
+		})
1449
+	}
1450
+
1451
+	return
1452
+}
1453
+
1454
+//获取项目和耗材不考虑特殊病
1455
+func ProjectConsumables2T(orgid int64) (list []*models.DropDownList, err error) {
1456
+
1457
+	var project []*models.XtHisProject
1458
+	err = XTReadDB().Model(&project).Where("user_org_id = ? and status = 1 and medical_status != 1", orgid).Find(&project).Error
1459
+	if err != nil {
1460
+		return
1461
+	}
1462
+	for _, v := range project {
1463
+		list = append(list, &models.DropDownList{
1464
+			Id:   "p" + config.ToString(v.ID),
1465
+			Name: v.ProjectName,
1466
+		})
1467
+	}
1468
+
1469
+	var good []*models.GoodInfo
1470
+	err = XTReadDB().Model(&models.GoodInfo{}).Where("org_id = ? and status = 1 and good_status != 1", orgid).Find(&good).Error
1471
+	if err != nil {
1472
+		return
1473
+	}
1474
+	for _, v := range good {
1475
+		list = append(list, &models.DropDownList{
1476
+			Id:   "i" + config.ToString(v.ID),
1477
+			Name: v.GoodName + " " + v.SpecificationName,
1478
+		})
1479
+	}
1480
+
1481
+	return
1482
+}
1483
+
1484
+//查询药品
1485
+func FindPatientDrug(orgid, patient_id, drugid, mode int64) bool {
1486
+	var total int
1487
+	XTReadDB().Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and status = 1 and "+
1488
+		"prescription_id in (select id from his_prescription_info_template where status = 1 and user_org_id = ? and type = 1 and p_template_id in ("+
1489
+		"select id from his_prescription_template where status= 1 and user_org_id = ? and mode = ?))", orgid, patient_id, drugid, orgid, orgid, mode).Count(&total)
1490
+	if total > 0 {
1491
+		return true
1492
+	}
1493
+	return false
1494
+}
1495
+
1496
+//查询项目
1497
+func FindPatientXiang(orgid, patient_id, drugid, mode int64) bool {
1498
+	var total int
1499
+	XTReadDB().Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and status = 1 and type = 2 and "+
1500
+		"prescription_id in (select id from his_prescription_info_template where status = 1 and user_org_id = ? and type = 2 and p_template_id in ("+
1501
+		"select id from his_prescription_template where status= 1 and user_org_id = ? and mode = ?))", orgid, patient_id, drugid, orgid, orgid, mode).Count(&total)
1502
+	if total > 0 {
1503
+		return true
1504
+	}
1505
+	return false
1506
+}
1507
+
1508
+//查询耗材
1509
+func FindPatientXiang2(orgid, patient_id, drugid, mode int64) bool {
1510
+	var total int
1511
+	XTReadDB().Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and status = 1 and type = 3 and "+
1512
+		"prescription_id in (select id from his_prescription_info_template where status = 1 and user_org_id = ? and type = 2 and p_template_id in ("+
1513
+		"select id from his_prescription_template where status= 1 and user_org_id = ? and mode = ?))", orgid, patient_id, drugid, orgid, orgid, mode).Count(&total)
1514
+	if total > 0 {
1515
+		return true
1516
+	}
1517
+	return false
1518
+}
1519
+
1520
+//types处方类型,1.药品 2.项目,model透析模式
1521
+func GetHisInfoTempalteId(model, orgid, types int64) (tp []int64) {
1522
+	type tmpid struct {
1523
+		Id int64
1524
+	}
1525
+	var tmp []*tmpid
1526
+	XTReadDB().Raw("select id from his_prescription_info_template where status = 1 and user_org_id = ? and type = ? and p_template_id in ("+
1527
+		"select id from his_prescription_template where status = 1 and user_org_id = ? and mode = ?)", orgid, types, orgid, model).Scan(&tmp)
1528
+	for _, v := range tmp {
1529
+		tp = append(tp, v.Id)
1530
+	}
1531
+	return
1532
+}
1533
+
1534
+//替换药品处方模板
1535
+func ReplaceDrugPrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, s models.HisPrescriptionAdviceTemplate, tx *gorm.DB) (err error) {
1536
+	err = tx.Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and "+
1537
+		"status = 1 and prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1538
+		"drug_id":                 s.DrugId,
1539
+		"advice_name":             s.AdviceName,
1540
+		"single_dose":             s.SingleDose,
1541
+		"single_dose_unit":        s.SingleDoseUnit,
1542
+		"delivery_way":            s.DeliveryWay,
1543
+		"execution_frequency":     s.ExecutionFrequency,
1544
+		"day":                     s.Day,
1545
+		"prescribing_number":      s.PrescribingNumber,
1546
+		"prescribing_number_unit": s.PrescribingNumberUnit,
1547
+		"price":                   s.Price,
1548
+		"remark":                  s.Remark,
1549
+		"updated_time":            time.Now().Unix(),
1550
+	}).Error
1551
+	return err
1552
+}
1553
+
1554
+//替换项目模板
1555
+func ReplaceProjectPrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, s models.HisPrescriptionProjectTemplate, tx *gorm.DB) (err error) {
1556
+	err = tx.Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and "+
1557
+		"status = 1 and prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1558
+		"project_id":          s.ProjectId,
1559
+		"type":                s.Type,
1560
+		"frequency_type":      s.FrequencyType,
1561
+		"day_count":           s.DayCount,
1562
+		"week_day":            s.WeekDay,
1563
+		"price":               s.Price,
1564
+		"count":               s.Count,
1565
+		"single_dose":         s.SingleDose,
1566
+		"delivery_way":        s.DeliveryWay,
1567
+		"execution_frequency": s.ExecutionFrequency,
1568
+		"remark":              s.Remark,
1569
+		"day":                 s.Day,
1570
+		"unit":                s.Unit,
1571
+		"mtime":               time.Now().Unix(),
1572
+	}).Error
1573
+	return err
1574
+}
1575
+
1576
+//删除项目模板
1577
+func DeleteProjectTemplate(orgid, patient_id, drugid int64, ids []int64, tx *gorm.DB) (err error) {
1578
+	err = tx.Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and "+
1579
+		"prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1580
+		"status": 0,
1581
+		"mtime":  time.Now().Unix(),
1582
+	}).Error
1583
+	return err
1584
+}
1585
+
1586
+//删除处方模板
1587
+func DeletePrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, tx *gorm.DB) (err error) {
1588
+	err = tx.Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and "+
1589
+		"prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
1590
+		"status":       0,
1591
+		"updated_time": time.Now().Unix(),
1592
+	}).Error
1593
+	return err
1594
+}
1595
+
1596
+//根据透析模式和患者id获取该患者的处方内容
1597
+func PTemplateInformation(orgid, mode_id, patient_id int64) (tmp interface{}, err error) {
1598
+	//获取处方id
1599
+	var tt []*models.HisPrescriptionTemplate
1600
+	err = XTReadDB().Raw("select id from his_prescription_template where status = 1 and user_org_id = ? and mode = ? and patient_id = ?", orgid, mode_id, patient_id).Scan(&tt).Error
1601
+
1602
+	if len(tt) > 1 {
1603
+		err = fmt.Errorf("数据有误")
1604
+		return
1605
+	}
1606
+	x := make(map[int64]string, 0) //项目
1607
+	h := make(map[int64]string, 0) //耗材
1608
+	for _, v := range tt {
1609
+		var prescriptions []*models.HisPrescriptionInfoTemplateL
1610
+		prescriptions, err = GetHisPrescriptionTemplateL(v.ID, orgid)
1611
+		if err != nil {
1612
+			return
1613
+		}
1614
+		for i := 0; i < len(prescriptions); i++ {
1615
+			for j := 0; j < len(prescriptions[i].HisPrescriptionProjectTemplate); j++ {
1616
+				if prescriptions[i].HisPrescriptionProjectTemplate[j].Type == 2 {
1617
+					//项目
1618
+					if v, ok := x[prescriptions[i].HisPrescriptionProjectTemplate[j].XtHisProject.StatisticalClassification]; ok {
1619
+						prescriptions[i].HisPrescriptionProjectTemplate[j].XtHisProject.Translate = v
1620
+					} else {
1621
+						prescriptions[i].HisPrescriptionProjectTemplate[j].XtHisProject.Translate, err = TranslateZu(prescriptions[i].HisPrescriptionProjectTemplate[j].XtHisProject.StatisticalClassification, orgid, "统计分类")
1622
+						if err != nil {
1623
+							return
1624
+						}
1625
+						x[prescriptions[i].HisPrescriptionProjectTemplate[j].XtHisProject.StatisticalClassification] = prescriptions[i].HisPrescriptionProjectTemplate[j].XtHisProject.Translate
1626
+					}
1627
+
1628
+				}
1629
+				if prescriptions[i].HisPrescriptionProjectTemplate[j].Type == 3 {
1630
+					//耗材
1631
+					if v, ok := h[prescriptions[i].HisPrescriptionProjectTemplate[j].GoodInfo.GoodKind]; ok {
1632
+						prescriptions[i].HisPrescriptionProjectTemplate[j].GoodInfo.Translate = v
1633
+					} else {
1634
+						prescriptions[i].HisPrescriptionProjectTemplate[j].GoodInfo.Translate = "耗材"
1635
+						h[prescriptions[i].HisPrescriptionProjectTemplate[j].GoodInfo.GoodKind] = prescriptions[i].HisPrescriptionProjectTemplate[j].GoodInfo.Translate
1636
+					}
1637
+				}
1638
+			}
1639
+		}
1640
+		tmp = prescriptions
1641
+	}
1642
+	return
1643
+}
1644
+func DeleteOne(types, id int64) (err error) {
1645
+	if types == 1 {
1646
+		//药品
1647
+		err = XTWriteDB().Model(&models.HisPrescriptionAdviceTemplate{}).Where("id = ?", id).Updates(map[string]interface{}{
1648
+			"status":       0,
1649
+			"updated_time": time.Now().Unix(),
1650
+		}).Error
1651
+		if err != nil {
1652
+			return
1653
+		}
1654
+	} else if types == 2 {
1655
+		//项目
1656
+		err = XTWriteDB().Model(&models.HisPrescriptionProjectTemplateL{}).Where("id = ?", id).Updates(map[string]interface{}{
1657
+			"status": 0,
1658
+			"mtime":  time.Now().Unix(),
1659
+		}).Error
1660
+		if err != nil {
1661
+			return
1662
+		}
1663
+
1664
+	} else {
1665
+		err = fmt.Errorf("参数错误")
1666
+		return
1667
+	}
1668
+	return
1669
+
1670
+}
1671
+
1672
+//收尾工作
1673
+func Scavenger(orgid int64) (err error) {
1674
+	//开事务
1675
+	tx := XTWriteDB().Begin()
1676
+	defer func() {
1677
+		if err != nil {
1678
+			utils.ErrorLog("事务失败,原因为: %v", err)
1679
+			tx.Rollback()
1680
+		} else {
1681
+			tx.Commit()
1682
+		}
1683
+	}()
1684
+	//查询该机构的所有模板
1685
+	var tmp1 []*models.HisPrescriptionTemplate
1686
+	var tmp2 []*models.HisPrescriptionInfoTemplate
1687
+	deltmp1 := make([]int64, 0) //清除的数据
1688
+	deltmp2 := make([]int64, 0) //清除的数据
1689
+	err = tx.Model(&models.HisPrescriptionTemplate{}).Where("user_org_id = ? and status = 1", orgid).Find(&tmp1).Error
1690
+	if err != nil {
1691
+		return
1692
+	}
1693
+	for _, v := range tmp1 {
1694
+		var total1 int
1695
+		tx.Model(&models.HisPrescriptionInfoTemplate{}).Where("user_org_id = ? and p_template_id = ? and status = 1", orgid, v.ID).Count(&total1)
1696
+		if total1 == 0 {
1697
+			deltmp1 = append(deltmp1, v.ID)
1698
+		}
1699
+	}
1700
+	err = tx.Model(&models.HisPrescriptionInfoTemplate{}).Where("user_org_id = ? and status = 1", orgid).Find(&tmp2).Error
1701
+	if err != nil {
1702
+		return
1703
+	}
1704
+	for _, v := range tmp2 {
1705
+		if v.Type == 1 {
1706
+			var total2 int
1707
+			tx.Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and prescription_id = ? and status = 1", orgid, v.ID).Count(&total2)
1708
+			if total2 == 0 {
1709
+				deltmp2 = append(deltmp2, v.ID)
1710
+			}
1711
+		}
1712
+		if v.Type == 2 {
1713
+			var total3 int
1714
+			tx.Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and prescription_id = ? and status = 1", orgid, v.ID).Count(&total3)
1715
+			if total3 == 0 {
1716
+				deltmp2 = append(deltmp2, v.ID)
1717
+			}
1718
+		}
1719
+	}
1720
+
1721
+	//清除1
1722
+	err = tx.Model(&models.HisPrescriptionTemplate{}).Where("id in (?)", deltmp1).Updates(map[string]interface{}{
1723
+		"status": 0,
1724
+		"mtime":  time.Now().Unix(),
1725
+	}).Error
1726
+	if err != nil {
1727
+		return
1728
+	}
1729
+	//清除1
1730
+	err = tx.Model(&models.HisPrescriptionInfoTemplate{}).Where("id in (?)", deltmp2).Updates(map[string]interface{}{
1731
+		"status": 0,
1732
+		"mtime":  time.Now().Unix(),
1733
+	}).Error
1734
+	if err != nil {
1735
+		return
1736
+	}
1737
+
1738
+	return
1739
+}