data_api_controller.go 42KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "reflect"
  10. "strconv"
  11. "time"
  12. "github.com/astaxie/beego"
  13. )
  14. type DataApiController struct {
  15. BaseAuthAPIController
  16. }
  17. func DataApiRegistRouters() {
  18. beego.Router("/api/getconfiglist", &DataApiController{}, "get,post:GetConfigList")
  19. beego.Router("/api/createconfig", &DataApiController{}, "Post:CreateConfig")
  20. beego.Router("/api/createchildconfig", &DataApiController{}, "Post:CreateChildConfig")
  21. beego.Router("/api/updatechildconfig", &DataApiController{}, "Post:UpdateChildConfig")
  22. beego.Router("/api/deletechildconfig", &DataApiController{}, "Post:DeleteChildConfig")
  23. beego.Router("/api/updatetemplate", &DataApiController{}, "Post:UpdateTemplate")
  24. beego.Router("/api/getadviceconfigs", &DataApiController{}, "Get:GetAdviceConfigs")
  25. beego.Router("/api/getalladviceconfig", &DataApiController{}, "Get:GetAllAdviceConfigs")
  26. beego.Router("/api/drugdic/create", &DataApiController{}, "Post:CreateDrugDic")
  27. beego.Router("/api/drugdic/update", &DataApiController{}, "Put:UpdateDrugDic")
  28. beego.Router("/api/drugdic/delete", &DataApiController{}, "Delete:DeleteDrugDic")
  29. beego.Router("/api/drugway/create", &DataApiController{}, "Post:CreateDrugWay")
  30. beego.Router("/api/drugway/update", &DataApiController{}, "Put:UpdateDrugWay")
  31. beego.Router("/api/drugway/delete", &DataApiController{}, "Delete:DeleteDrugWay")
  32. beego.Router("/api/executionfrequency/create", &DataApiController{}, "Post:CreateExecutionFrequency")
  33. beego.Router("/api/executionfrequency/update", &DataApiController{}, "Put:UpdateExecutionFrequency")
  34. beego.Router("/api/executionfrequency/delete", &DataApiController{}, "Delete:DeleteExecutionFrequency")
  35. beego.Router("/api/advicetemplate/create", &DataApiController{}, "Post:CreateAdviceTemplate")
  36. beego.Router("/api/subadvice/create", &DataApiController{}, "Post:CreateSubAdviceTemplate")
  37. beego.Router("/api/advicetemplate/update", &DataApiController{}, "Put:UpdateAdviceTemplate")
  38. beego.Router("/api/advicetemplate/delete", &DataApiController{}, "Delete:DeleteAdviceTemplate")
  39. beego.Router("/api/advicetemplate/add", &DataApiController{}, "Post:CreateSingleAdviceTemplate")
  40. beego.Router("/api/adviceparenttemplate/delete", &DataApiController{}, "Delete:DeleteParentAdviceTemplate")
  41. beego.Router("/api/template/modify", &DataApiController{}, "Post:ModifyTemplateName")
  42. beego.Router("/api/filed/show", &DataApiController{}, "Post:ModifyFiledIsShow")
  43. beego.Router("/article/hanleupdatetwo", &DataApiController{}, "Get:GetHandleData")
  44. beego.Router("/article/updatedatatwo", &DataApiController{}, "Post:UpdateDataTwo")
  45. }
  46. //GetPatientsList 取配置信息列表
  47. func (c *DataApiController) GetConfigList() {
  48. adminUserInfo := c.GetAdminUserInfo()
  49. configList, _ := service.GetConfigList(adminUserInfo.CurrentOrgId)
  50. c.ServeSuccessJSON(map[string]interface{}{
  51. "configlist": configList,
  52. })
  53. return
  54. }
  55. //CreateConfig 创建配置信息
  56. func (c *DataApiController) CreateConfig() {
  57. adminUserInfo := c.GetAdminUserInfo()
  58. var dataconfig models.Dataconfig
  59. var resultConfig models.ConfigViewModel
  60. code := configFormData(&dataconfig, c.Ctx.Input.RequestBody)
  61. if code > 0 {
  62. c.ServeFailJSONWithSGJErrorCode(code)
  63. return
  64. }
  65. // 验证关键字段的值是否重复
  66. // if (dataconfig.Module == "education" || dataconfig.Module == "summary") {
  67. // thisConfig,_:=service.FindConfigByTitle(dataconfig.Module, dataconfig.FieldName,dataconfig.OrgId)
  68. // if thisConfig.ID >0 {
  69. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  70. // return
  71. // }
  72. // } else {
  73. // thisConfig,_:=service.FindConfigByFieldname(dataconfig.Module, dataconfig.FieldName,dataconfig.OrgId)
  74. // if thisConfig.ID >0 {
  75. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  76. // return
  77. // }
  78. // }
  79. // fieldValue:=service.GetChildValue(dataconfig.Module, dataconfig.ParentId)
  80. // dataconfig.Value = fieldValue+1
  81. dataBody := make(map[string]interface{}, 0)
  82. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  83. if err != nil {
  84. utils.ErrorLog(err.Error())
  85. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  86. return
  87. }
  88. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  89. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  90. dataconfig.Status = 1
  91. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  92. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  93. dataconfig.Remark = string(dataBody["remark"].(string))
  94. if dataBody["order"] != nil {
  95. dataconfig.Order = int64(dataBody["order"].(float64))
  96. } else {
  97. dataconfig.Order = 0
  98. }
  99. err = service.CreateConfig(&dataconfig)
  100. if err != nil {
  101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  102. return
  103. } else {
  104. resultConfig.ID = dataconfig.ID
  105. resultConfig.Module = dataconfig.Module
  106. resultConfig.Name = dataconfig.Name
  107. resultConfig.OrgId = dataconfig.OrgId
  108. resultConfig.ParentId = dataconfig.ParentId
  109. resultConfig.FieldName = dataconfig.FieldName
  110. resultConfig.CreateUserId = dataconfig.CreateUserId
  111. resultConfig.Title = dataconfig.Title
  112. resultConfig.Content = dataconfig.Content
  113. }
  114. c.ServeSuccessJSON(map[string]interface{}{
  115. "dataconfig": resultConfig,
  116. "msg": "ok",
  117. })
  118. return
  119. }
  120. func (c *DataApiController) UpdateTemplate() {
  121. adminUserInfo := c.GetAdminUserInfo()
  122. var dataconfig models.Dataconfig
  123. code := configFormData(&dataconfig, c.Ctx.Input.RequestBody)
  124. if code > 0 {
  125. c.ServeFailJSONWithSGJErrorCode(code)
  126. return
  127. }
  128. dataBody := make(map[string]interface{}, 0)
  129. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  130. if err != nil {
  131. utils.ErrorLog(err.Error())
  132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  133. return
  134. }
  135. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  136. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  137. dataconfig.Status = 1
  138. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  139. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  140. dataconfig.Remark = string(dataBody["remark"].(string))
  141. if dataBody["order"] != nil {
  142. dataconfig.Order = int64(dataBody["order"].(float64))
  143. } else {
  144. dataconfig.Order = 0
  145. }
  146. // 验证关键字段的值是否重复
  147. // cur_id := int64(dataBody["id"].(float64))
  148. // thisConfig,_:=service.FindConfigByTitleForUpdate(dataconfig.Module, dataconfig.Title,dataconfig.OrgId,cur_id)
  149. // if thisConfig.ID >0 {
  150. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  151. // return
  152. // }
  153. configOrgId := int64(dataBody["org_id"].(float64))
  154. if configOrgId == 0 {
  155. dataconfig.DeleteIdSystem = int64(dataBody["id"].(float64))
  156. err := service.CreateConfig(&dataconfig)
  157. if err != nil {
  158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  159. return
  160. }
  161. } else {
  162. dataconfig.ID = int64(dataBody["id"].(float64))
  163. err = service.UpdateTemplate(&dataconfig)
  164. if err != nil {
  165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  166. return
  167. }
  168. }
  169. c.ServeSuccessJSON(map[string]interface{}{
  170. "dataconfig": dataconfig,
  171. "msg": "ok",
  172. })
  173. return
  174. }
  175. func (c *DataApiController) UpdateChildConfig() {
  176. adminUserInfo := c.GetAdminUserInfo()
  177. var dataconfig models.Dataconfig
  178. code := configChildFormData(&dataconfig, c.Ctx.Input.RequestBody)
  179. if code > 0 {
  180. c.ServeFailJSONWithSGJErrorCode(code)
  181. return
  182. }
  183. dataBody := make(map[string]interface{}, 0)
  184. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  185. if err != nil {
  186. utils.ErrorLog(err.Error())
  187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  188. return
  189. }
  190. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  191. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  192. dataconfig.Status = 1
  193. dataconfig.Value = int(int64(dataBody["value"].(float64)))
  194. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  195. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  196. dataconfig.Remark = string(dataBody["remark"].(string))
  197. dataconfig.Order = int64(dataBody["orders"].(float64))
  198. fmt.Println("dataconfitg------", dataconfig.Order)
  199. //if dataBody["orders"] != nil {
  200. // dataconfig.Order = int64(dataBody["orders"].(float64))
  201. // fmt.Println("dataconfig",dataconfig.Order)
  202. //} else {
  203. // dataconfig.Order = 0
  204. //}
  205. configOrgId := int64(dataBody["org_id"].(float64))
  206. // 验证关键字段的值是否重复
  207. // configId := int64(dataBody["id"].(float64))
  208. // thisConfig,_:=service.FindConfigByNameForUpdate(dataconfig.Module, dataconfig.Name,dataconfig.ParentId,dataconfig.OrgId,configId)
  209. // if thisConfig.ID >0 {
  210. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  211. // return
  212. // }
  213. if configOrgId == 0 {
  214. dataconfig.DeleteIdSystem = int64(dataBody["id"].(float64))
  215. err := service.CreateConfig(&dataconfig)
  216. if err != nil {
  217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  218. return
  219. }
  220. } else {
  221. dataconfig.ID = int64(dataBody["id"].(float64))
  222. err = service.UpdateChildConfig(&dataconfig)
  223. if err != nil {
  224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  225. return
  226. }
  227. }
  228. c.ServeSuccessJSON(map[string]interface{}{
  229. "dataconfig": dataconfig,
  230. "msg": "ok",
  231. })
  232. return
  233. }
  234. func (c *DataApiController) DeleteChildConfig() {
  235. adminUserInfo := c.GetAdminUserInfo()
  236. var dataconfig models.Dataconfig
  237. code := configChildFormData(&dataconfig, c.Ctx.Input.RequestBody)
  238. if code > 0 {
  239. c.ServeFailJSONWithSGJErrorCode(code)
  240. return
  241. }
  242. dataBody := make(map[string]interface{}, 0)
  243. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  244. if err != nil {
  245. utils.ErrorLog(err.Error())
  246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  247. return
  248. }
  249. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  250. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  251. dataconfig.Status = 0
  252. dataconfig.Value = int(int64(dataBody["value"].(float64)))
  253. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  254. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  255. dataconfig.Remark = string(dataBody["remark"].(string))
  256. if dataBody["order"] != nil {
  257. dataconfig.Order = int64(dataBody["order"].(float64))
  258. } else {
  259. dataconfig.Order = 0
  260. }
  261. configOrgId := int64(dataBody["org_id"].(float64))
  262. if configOrgId == 0 {
  263. dataconfig.DeleteIdSystem = int64(dataBody["id"].(float64))
  264. err := service.CreateConfig(&dataconfig)
  265. if err != nil {
  266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  267. return
  268. }
  269. } else {
  270. dataconfig.ID = int64(dataBody["id"].(float64))
  271. err := service.DeleteChildConfig(&dataconfig)
  272. if err != nil {
  273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  274. return
  275. }
  276. }
  277. c.ServeSuccessJSON(map[string]interface{}{
  278. "dataconfig": dataconfig,
  279. "msg": "ok",
  280. })
  281. return
  282. }
  283. //CreateChildConfig 创建子配置信息
  284. func (c *DataApiController) CreateChildConfig() {
  285. adminUserInfo := c.GetAdminUserInfo()
  286. var dataconfig models.Dataconfig
  287. code := configChildFormData(&dataconfig, c.Ctx.Input.RequestBody)
  288. if code > 0 {
  289. c.ServeFailJSONWithSGJErrorCode(code)
  290. return
  291. }
  292. dataBody := make(map[string]interface{}, 0)
  293. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  294. if err != nil {
  295. utils.ErrorLog(err.Error())
  296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  297. return
  298. }
  299. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  300. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  301. dataconfig.Status = 1
  302. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  303. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  304. dataconfig.Remark = string(dataBody["remark"].(string))
  305. if dataBody["order"] != nil {
  306. dataconfig.Order = int64(dataBody["order"].(float64))
  307. } else {
  308. dataconfig.Order = 0
  309. }
  310. // 验证关键字段的值是否重复
  311. // thisConfig,_:=service.FindConfigByName(dataconfig.Module, dataconfig.Name,dataconfig.ParentId,dataconfig.OrgId)
  312. // if thisConfig.ID >0 {
  313. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  314. // return
  315. // }
  316. fieldValue := service.GetChildValue(dataconfig.Module, dataconfig.ParentId, dataconfig.OrgId)
  317. dataconfig.Value = fieldValue + 1
  318. err = service.CreateConfig(&dataconfig)
  319. if err != nil {
  320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  321. return
  322. }
  323. c.ServeSuccessJSON(map[string]interface{}{
  324. "dataconfig": dataconfig,
  325. "msg": "ok",
  326. })
  327. return
  328. }
  329. func configFormData(dataconfig *models.Dataconfig, data []byte) (code int) {
  330. configBody := make(map[string]interface{}, 0)
  331. err := json.Unmarshal(data, &configBody)
  332. utils.InfoLog(string(data))
  333. if err != nil {
  334. utils.ErrorLog(err.Error())
  335. code = enums.ErrorCodeParamWrong
  336. return
  337. }
  338. if configBody["module"] == nil || reflect.TypeOf(configBody["module"]).String() != "string" {
  339. utils.ErrorLog("module")
  340. code = enums.ErrorCodeParamWrong
  341. return
  342. }
  343. module, _ := configBody["module"].(string)
  344. if len(module) == 0 {
  345. utils.ErrorLog("len(module) == 0")
  346. code = enums.ErrorCodeParamWrong
  347. return
  348. }
  349. dataconfig.Module = module
  350. if module == "education" || module == "summary" || module == "course_disease" || module == "rescue_record" {
  351. if configBody["title"] == nil || reflect.TypeOf(configBody["title"]).String() != "string" {
  352. utils.ErrorLog("title")
  353. code = enums.ErrorCodeParamWrong
  354. return
  355. }
  356. title, _ := configBody["title"].(string)
  357. if len(title) == 0 {
  358. utils.ErrorLog("len(title) == 0")
  359. code = enums.ErrorCodeParamWrong
  360. return
  361. }
  362. dataconfig.Title = title
  363. if configBody["content"] == nil || reflect.TypeOf(configBody["content"]).String() != "string" {
  364. utils.ErrorLog("content")
  365. code = enums.ErrorCodeParamWrong
  366. return
  367. }
  368. content, _ := configBody["content"].(string)
  369. if len(content) == 0 {
  370. utils.ErrorLog("len(content) == 0")
  371. code = enums.ErrorCodeParamWrong
  372. return
  373. }
  374. dataconfig.Content = content
  375. } else {
  376. if configBody["name"] == nil || reflect.TypeOf(configBody["name"]).String() != "string" {
  377. utils.ErrorLog("name")
  378. code = enums.ErrorCodeParamWrong
  379. return
  380. }
  381. name, _ := configBody["name"].(string)
  382. if len(name) == 0 {
  383. utils.ErrorLog("len(name) == 0")
  384. code = enums.ErrorCodeParamWrong
  385. return
  386. }
  387. dataconfig.Name = name
  388. if configBody["field_name"] == nil || reflect.TypeOf(configBody["field_name"]).String() != "string" {
  389. utils.ErrorLog("field_name")
  390. code = enums.ErrorCodeParamWrong
  391. return
  392. }
  393. field_name, _ := configBody["field_name"].(string)
  394. if len(field_name) == 0 {
  395. utils.ErrorLog("len(field_name) == 0")
  396. code = enums.ErrorCodeParamWrong
  397. return
  398. }
  399. dataconfig.FieldName = field_name
  400. }
  401. return
  402. }
  403. func configChildFormData(dataconfig *models.Dataconfig, data []byte) (code int) {
  404. configBody := make(map[string]interface{}, 0)
  405. err := json.Unmarshal(data, &configBody)
  406. utils.InfoLog(string(data))
  407. if err != nil {
  408. utils.ErrorLog(err.Error())
  409. code = enums.ErrorCodeParamWrong
  410. return
  411. }
  412. if configBody["module"] == nil || reflect.TypeOf(configBody["module"]).String() != "string" {
  413. utils.ErrorLog("module")
  414. code = enums.ErrorCodeParamWrong
  415. return
  416. }
  417. module, _ := configBody["module"].(string)
  418. if len(module) == 0 {
  419. utils.ErrorLog("len(module) == 0")
  420. code = enums.ErrorCodeParamWrong
  421. return
  422. }
  423. dataconfig.Module = module
  424. if module == "education" || module == "summary" {
  425. if configBody["title"] == nil || reflect.TypeOf(configBody["title"]).String() != "string" {
  426. utils.ErrorLog("title")
  427. code = enums.ErrorCodeParamWrong
  428. return
  429. }
  430. title, _ := configBody["title"].(string)
  431. if len(title) == 0 {
  432. utils.ErrorLog("len(title) == 0")
  433. code = enums.ErrorCodeParamWrong
  434. return
  435. }
  436. dataconfig.Title = title
  437. if configBody["content"] == nil || reflect.TypeOf(configBody["content"]).String() != "string" {
  438. utils.ErrorLog("content")
  439. code = enums.ErrorCodeParamWrong
  440. return
  441. }
  442. content, _ := configBody["content"].(string)
  443. if len(content) == 0 {
  444. utils.ErrorLog("len(content) == 0")
  445. code = enums.ErrorCodeParamWrong
  446. return
  447. }
  448. dataconfig.Content = content
  449. } else {
  450. if configBody["parent_id"] == nil || reflect.TypeOf(configBody["parent_id"]).String() != "float64" {
  451. utils.ErrorLog("module")
  452. code = enums.ErrorCodeParamWrong
  453. return
  454. }
  455. parent_id := int64(configBody["parent_id"].(float64))
  456. if parent_id <= 0 {
  457. utils.ErrorLog("parent_id <= 0")
  458. code = enums.ErrorCodeParamWrong
  459. return
  460. }
  461. dataconfig.ParentId = parent_id
  462. if configBody["name"] == nil || reflect.TypeOf(configBody["name"]).String() != "string" {
  463. utils.ErrorLog("name")
  464. code = enums.ErrorCodeParamWrong
  465. return
  466. }
  467. name, _ := configBody["name"].(string)
  468. if len(name) == 0 {
  469. utils.ErrorLog("len(name) == 0")
  470. code = enums.ErrorCodeParamWrong
  471. return
  472. }
  473. dataconfig.Name = name
  474. }
  475. return
  476. }
  477. func (c *DataApiController) GetAdviceConfigs() {
  478. advice_type, _ := c.GetInt64("type", 0)
  479. adminUserInfo := c.GetAdminUserInfo()
  480. var drugs []models.DrugDic
  481. drugways, _, _ := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  482. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  483. adviceTemplates, _ := service.FindAllAdviceTemplate(adminUserInfo.CurrentOrgId, advice_type)
  484. c.ServeSuccessJSON(map[string]interface{}{
  485. "drugs": drugs,
  486. "drugways": drugways,
  487. "efs": efs,
  488. "advice_templates": adviceTemplates,
  489. })
  490. }
  491. func (c *DataApiController) CreateDrugDic() {
  492. adminUserInfo := c.GetAdminUserInfo()
  493. var drugdic models.DrugDic
  494. err := json.Unmarshal(c.Ctx.Input.RequestBody, &drugdic)
  495. if err != nil {
  496. utils.ErrorLog("%v", err)
  497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  498. return
  499. }
  500. if drugdic.Name == "" {
  501. utils.ErrorLog("医嘱名称不能为空")
  502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  503. return
  504. }
  505. timeNow := time.Now().Unix()
  506. drugdic.Code = ""
  507. drugdic.Status = 1
  508. drugdic.CreatedTime = timeNow
  509. drugdic.UpdatedTime = timeNow
  510. drugdic.OrgId = adminUserInfo.CurrentOrgId
  511. drugdic.Creator = adminUserInfo.AdminUser.Id
  512. err = service.CreateDrugDic(&drugdic)
  513. if err != nil {
  514. utils.ErrorLog("%v", err)
  515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  516. return
  517. }
  518. c.ServeSuccessJSON(map[string]interface{}{
  519. "drugdic": drugdic,
  520. })
  521. return
  522. }
  523. func (c *DataApiController) UpdateDrugDic() {
  524. adminUserInfo := c.GetAdminUserInfo()
  525. id, _ := c.GetInt64("id", 0)
  526. if id <= 0 {
  527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  528. return
  529. }
  530. drugdic, _ := service.FindDrugDic(adminUserInfo.CurrentOrgId, id)
  531. if drugdic == nil {
  532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  533. return
  534. }
  535. var drugdicdata models.DrugDic
  536. err := json.Unmarshal(c.Ctx.Input.RequestBody, &drugdicdata)
  537. if err != nil {
  538. utils.ErrorLog("%v", err)
  539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  540. return
  541. }
  542. if drugdicdata.Name == "" {
  543. utils.ErrorLog("医嘱名称不能为空")
  544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  545. return
  546. }
  547. timeNow := time.Now().Unix()
  548. drugdic.UpdatedTime = timeNow
  549. drugdic.Name = drugdicdata.Name
  550. drugdic.Spec = drugdicdata.Spec
  551. drugdic.SpecUnit = drugdicdata.SpecUnit
  552. drugdic.Form = drugdicdata.Form
  553. drugdic.FormUnit = drugdicdata.FormUnit
  554. err = service.UpdateDrugDic(drugdic)
  555. if err != nil {
  556. utils.ErrorLog("%v", err)
  557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  558. return
  559. }
  560. c.ServeSuccessJSON(map[string]interface{}{
  561. "drugdic": drugdic,
  562. })
  563. return
  564. }
  565. func (c *DataApiController) DeleteDrugDic() {
  566. adminUserInfo := c.GetAdminUserInfo()
  567. id, _ := c.GetInt64("id", 0)
  568. if id <= 0 {
  569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  570. return
  571. }
  572. drugdic, _ := service.FindDrugDic(adminUserInfo.CurrentOrgId, id)
  573. if drugdic == nil {
  574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  575. return
  576. }
  577. timeNow := time.Now().Unix()
  578. drugdic.UpdatedTime = timeNow
  579. drugdic.Status = 2
  580. err := service.UpdateDrugDic(drugdic)
  581. if err != nil {
  582. utils.ErrorLog("%v", err)
  583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  584. return
  585. }
  586. c.ServeSuccessJSON(map[string]interface{}{
  587. "msg": "ok",
  588. })
  589. return
  590. }
  591. func (c *DataApiController) CreateDrugWay() {
  592. adminUserInfo := c.GetAdminUserInfo()
  593. var drugway models.DrugwayDic
  594. err := json.Unmarshal(c.Ctx.Input.RequestBody, &drugway)
  595. if err != nil {
  596. utils.ErrorLog("%v", err)
  597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  598. return
  599. }
  600. if drugway.Name == "" {
  601. utils.ErrorLog("给药途径不能为空")
  602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  603. return
  604. }
  605. timeNow := time.Now().Unix()
  606. drugway.Code = ""
  607. drugway.Status = 1
  608. drugway.CreatedTime = timeNow
  609. drugway.UpdatedTime = timeNow
  610. drugway.OrgId = adminUserInfo.CurrentOrgId
  611. drugway.Creator = adminUserInfo.AdminUser.Id
  612. err = service.CreateDrugWay(&drugway)
  613. if err != nil {
  614. utils.ErrorLog("%v", err)
  615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  616. return
  617. }
  618. c.ServeSuccessJSON(map[string]interface{}{
  619. "drugway": drugway,
  620. })
  621. return
  622. }
  623. func (c *DataApiController) UpdateDrugWay() {
  624. adminUserInfo := c.GetAdminUserInfo()
  625. id, _ := c.GetInt64("id", 0)
  626. if id <= 0 {
  627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  628. return
  629. }
  630. drugway, _ := service.FindDrugWay(adminUserInfo.CurrentOrgId, id)
  631. if drugway == nil {
  632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  633. return
  634. }
  635. var drugwaydata models.DrugwayDic
  636. err := json.Unmarshal(c.Ctx.Input.RequestBody, &drugwaydata)
  637. if err != nil {
  638. utils.ErrorLog("%v", err)
  639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  640. return
  641. }
  642. if drugwaydata.Name == "" {
  643. utils.ErrorLog("给药途径不能为空")
  644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  645. return
  646. }
  647. timeNow := time.Now().Unix()
  648. drugway.UpdatedTime = timeNow
  649. drugway.Name = drugwaydata.Name
  650. err = service.UpdateDrugWay(drugway)
  651. if err != nil {
  652. utils.ErrorLog("%v", err)
  653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  654. return
  655. }
  656. c.ServeSuccessJSON(map[string]interface{}{
  657. "drugway": drugway,
  658. })
  659. return
  660. }
  661. func (c *DataApiController) DeleteDrugWay() {
  662. adminUserInfo := c.GetAdminUserInfo()
  663. id, _ := c.GetInt64("id", 0)
  664. if id <= 0 {
  665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  666. return
  667. }
  668. drugway, _ := service.FindDrugWay(adminUserInfo.CurrentOrgId, id)
  669. if drugway == nil {
  670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  671. return
  672. }
  673. timeNow := time.Now().Unix()
  674. drugway.UpdatedTime = timeNow
  675. drugway.Status = 2
  676. err := service.UpdateDrugWay(drugway)
  677. if err != nil {
  678. utils.ErrorLog("%v", err)
  679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  680. return
  681. }
  682. c.ServeSuccessJSON(map[string]interface{}{
  683. "msg": "ok",
  684. })
  685. return
  686. }
  687. func (c *DataApiController) CreateExecutionFrequency() {
  688. adminUserInfo := c.GetAdminUserInfo()
  689. var ef models.ExecutionFrequencyDic
  690. err := json.Unmarshal(c.Ctx.Input.RequestBody, &ef)
  691. if err != nil {
  692. utils.ErrorLog("%v", err)
  693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  694. return
  695. }
  696. if ef.Name == "" {
  697. utils.ErrorLog("执行频率不能为空")
  698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  699. return
  700. }
  701. timeNow := time.Now().Unix()
  702. ef.Code = ""
  703. ef.Status = 1
  704. ef.CreatedTime = timeNow
  705. ef.UpdatedTime = timeNow
  706. ef.OrgId = adminUserInfo.CurrentOrgId
  707. ef.Creator = adminUserInfo.AdminUser.Id
  708. err = service.CreateExecutionFrequency(&ef)
  709. if err != nil {
  710. utils.ErrorLog("%v", err)
  711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  712. return
  713. }
  714. c.ServeSuccessJSON(map[string]interface{}{
  715. "ef": ef,
  716. })
  717. return
  718. }
  719. func (c *DataApiController) UpdateExecutionFrequency() {
  720. adminUserInfo := c.GetAdminUserInfo()
  721. id, _ := c.GetInt64("id", 0)
  722. if id <= 0 {
  723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  724. return
  725. }
  726. ef, _ := service.FindExecutionFrequency(adminUserInfo.CurrentOrgId, id)
  727. if ef == nil {
  728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  729. return
  730. }
  731. var efdata models.ExecutionFrequencyDic
  732. err := json.Unmarshal(c.Ctx.Input.RequestBody, &efdata)
  733. if err != nil {
  734. utils.ErrorLog("%v", err)
  735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  736. return
  737. }
  738. if efdata.Name == "" {
  739. utils.ErrorLog("执行频率不能为空")
  740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  741. return
  742. }
  743. timeNow := time.Now().Unix()
  744. ef.UpdatedTime = timeNow
  745. ef.Name = efdata.Name
  746. err = service.UpdateExecutionFrequency(ef)
  747. if err != nil {
  748. utils.ErrorLog("%v", err)
  749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  750. return
  751. }
  752. c.ServeSuccessJSON(map[string]interface{}{
  753. "ef": ef,
  754. })
  755. return
  756. }
  757. func (c *DataApiController) DeleteExecutionFrequency() {
  758. adminUserInfo := c.GetAdminUserInfo()
  759. id, _ := c.GetInt64("id", 0)
  760. if id <= 0 {
  761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  762. return
  763. }
  764. ef, _ := service.FindExecutionFrequency(adminUserInfo.CurrentOrgId, id)
  765. if ef == nil {
  766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  767. return
  768. }
  769. timeNow := time.Now().Unix()
  770. ef.UpdatedTime = timeNow
  771. ef.Status = 2
  772. err := service.UpdateExecutionFrequency(ef)
  773. if err != nil {
  774. utils.ErrorLog("%v", err)
  775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  776. return
  777. }
  778. c.ServeSuccessJSON(map[string]interface{}{
  779. "msg": "ok",
  780. })
  781. return
  782. }
  783. func (c *DataApiController) CreateAdviceTemplate() {
  784. templateName := c.GetString("template_name")
  785. advice_type, _ := c.GetInt64("advice_type")
  786. fmt.Println(templateName)
  787. if templateName == "" {
  788. utils.ErrorLog("模版名称不能为空")
  789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  790. return
  791. }
  792. if advice_type < 0 {
  793. utils.ErrorLog("医嘱模版类型不能为空")
  794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceTypeWrong)
  795. return
  796. }
  797. adminUserInfo := c.GetAdminUserInfo()
  798. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  799. if appRole.UserType == 3 {
  800. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  801. if getPermissionErr != nil {
  802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  803. return
  804. } else if headNursePermission == nil {
  805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  806. return
  807. }
  808. }
  809. //total := service.FindTemplateRecordByName(adminUserInfo.CurrentOrgId, templateName);
  810. //if total > 0 {
  811. // utils.ErrorLog("模版名称已经存在")
  812. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNameWrong)
  813. // return
  814. //}
  815. template := &models.DoctorAdviceParentTemplate{
  816. Name: templateName,
  817. OrgId: adminUserInfo.CurrentOrgId,
  818. Status: 1,
  819. CreatedTime: time.Now().Unix(),
  820. UpdatedTime: time.Now().Unix(),
  821. AdviceType: advice_type,
  822. }
  823. createErr := service.CreateTemplate(template)
  824. if createErr != nil {
  825. utils.ErrorLog("%v", createErr)
  826. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  827. return
  828. }
  829. dataBody := make(map[string]interface{}, 0)
  830. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  831. if err != nil {
  832. utils.ErrorLog(err.Error())
  833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  834. return
  835. }
  836. var subTemplate []*models.DoctorAdviceTemplate
  837. if dataBody["data"] != nil && reflect.TypeOf(dataBody["data"]).String() == "[]interface {}" {
  838. subTemp, _ := dataBody["data"].([]interface{})
  839. if len(subTemp) > 0 {
  840. for _, item := range subTemp {
  841. items := item.(map[string]interface{})
  842. if items["advice_name"] == nil || reflect.TypeOf(items["advice_name"]).String() != "string" {
  843. utils.ErrorLog("advice_name")
  844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  845. return
  846. }
  847. advice_name, _ := items["advice_name"].(string)
  848. advice_desc, _ := items["advice_desc"].(string)
  849. single_dose_unit, _ := items["single_dose_unit"].(string)
  850. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  851. delivery_way, _ := items["delivery_way"].(string)
  852. execution_frequency, _ := items["execution_frequency"].(string)
  853. drug_spec, _ := items["drug_spec"].(string)
  854. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  855. single_dose := items["single_dose"].(float64)
  856. prescribing_number := items["prescribing_number"].(float64)
  857. day_count, _ := strconv.ParseInt(items["day_count"].(string), 10, 64)
  858. weekdays := items["weekdays"].(string)
  859. frequency_type := int64(items["frequency_type"].(float64))
  860. subTemps := &models.DoctorAdviceTemplate{
  861. AdviceName: advice_name,
  862. Status: 1,
  863. CreatedTime: time.Now().Unix(),
  864. UpdatedTime: time.Now().Unix(),
  865. OrgId: adminUserInfo.CurrentOrgId,
  866. AdviceDesc: advice_desc,
  867. AdviceType: advice_type,
  868. SingleDoseUnit: single_dose_unit,
  869. PrescribingNumber: prescribing_number,
  870. PrescribingNumberUnit: prescribing_number_unit,
  871. DeliveryWay: delivery_way,
  872. ExecutionFrequency: execution_frequency,
  873. TemplateId: template.ID,
  874. DrugSpec: drug_spec,
  875. DrugSpecUnit: drug_spec_unit,
  876. SingleDose: single_dose,
  877. AdviceDoctor: adminUserInfo.AdminUser.Id,
  878. DayCount: day_count,
  879. WeekDays: weekdays,
  880. FrequencyType: frequency_type,
  881. }
  882. subTemplate = append(subTemplate, subTemps)
  883. }
  884. }
  885. }
  886. //errs := service.CreateBatchRecord(subTemplate)
  887. errs := service.CreateSubTemplate(subTemplate)
  888. if errs != nil {
  889. utils.ErrorLog(errs.Error())
  890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  891. return
  892. }
  893. templates, _ := service.FindDoctorAdviceTemplateById(template.ID, adminUserInfo.CurrentOrgId)
  894. c.ServeSuccessJSON(map[string]interface{}{
  895. "template": templates,
  896. })
  897. return
  898. }
  899. func (c *DataApiController) UpdateAdviceTemplate() {
  900. adminUserInfo := c.GetAdminUserInfo()
  901. id, _ := c.GetInt64("id", 0)
  902. if id <= 0 {
  903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  904. return
  905. }
  906. template, _ := service.FindAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  907. if template == nil {
  908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  909. return
  910. }
  911. //TODO 根据路由来做权限
  912. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  913. //if appRole.UserType == 3 {
  914. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  915. // if getPermissionErr != nil {
  916. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  917. // return
  918. // } else if headNursePermission == nil {
  919. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  920. // return
  921. // }
  922. //}
  923. var templatedata models.DoctorAdviceTemplate
  924. err := json.Unmarshal(c.Ctx.Input.RequestBody, &templatedata)
  925. if err != nil {
  926. utils.ErrorLog("%v", err)
  927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  928. return
  929. }
  930. if templatedata.AdviceName == "" {
  931. utils.ErrorLog("不能为空")
  932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  933. return
  934. }
  935. timeNow := time.Now().Unix()
  936. template.UpdatedTime = timeNow
  937. template.AdviceName = templatedata.AdviceName
  938. template.AdviceDesc = templatedata.AdviceDesc
  939. template.SingleDose = templatedata.SingleDose
  940. template.SingleDoseUnit = templatedata.SingleDoseUnit
  941. template.PrescribingNumber = templatedata.PrescribingNumber
  942. template.PrescribingNumberUnit = templatedata.PrescribingNumberUnit
  943. template.DrugSpec = templatedata.DrugSpec
  944. template.DrugSpecUnit = templatedata.DrugSpecUnit
  945. template.DeliveryWay = templatedata.DeliveryWay
  946. template.ExecutionFrequency = templatedata.ExecutionFrequency
  947. template.FrequencyType = templatedata.FrequencyType
  948. template.DayCount = templatedata.DayCount
  949. template.WeekDays = templatedata.WeekDays
  950. err = service.UpdateAdviceTemplate(template)
  951. if err != nil {
  952. utils.ErrorLog("%v", err)
  953. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  954. return
  955. }
  956. c.ServeSuccessJSON(map[string]interface{}{
  957. "template": template,
  958. })
  959. return
  960. }
  961. func (c *DataApiController) DeleteAdviceTemplate() {
  962. adminUserInfo := c.GetAdminUserInfo()
  963. parent_id, _ := c.GetInt64("parent_id", 0)
  964. id, _ := c.GetInt64("id", 0)
  965. if id <= 0 {
  966. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  967. return
  968. }
  969. template, _ := service.FindAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  970. if template == nil {
  971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  972. return
  973. }
  974. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  975. //if appRole.UserType == 3 {
  976. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  977. // if getPermissionErr != nil {
  978. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  979. // return
  980. // } else if headNursePermission == nil {
  981. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  982. // return
  983. // }
  984. //}
  985. timeNow := time.Now().Unix()
  986. template.ID = id
  987. template.UpdatedTime = timeNow
  988. template.ParentId = parent_id
  989. template.Status = 2
  990. if parent_id > 0 { //删除子医嘱
  991. err := service.UpdateAdviceTemplate(template)
  992. if err != nil {
  993. utils.ErrorLog("%v", err)
  994. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  995. return
  996. }
  997. } else { //删除该医嘱下的所有子医嘱
  998. err := service.UpdateAdviceAndSubAdviceTemplate(template)
  999. if err != nil {
  1000. utils.ErrorLog("%v", err)
  1001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1002. return
  1003. }
  1004. }
  1005. c.ServeSuccessJSON(map[string]interface{}{
  1006. "msg": "ok",
  1007. })
  1008. return
  1009. }
  1010. func (c *DataApiController) CreateSingleAdviceTemplate() {
  1011. drug_spec := c.GetString("drug_spec")
  1012. drug_spec_unit := c.GetString("drug_spec_unit")
  1013. advice_name := c.GetString("advice_name")
  1014. advice_desc := c.GetString("advice_desc")
  1015. single_dose, _ := c.GetFloat("single_dose", 0)
  1016. single_dose_unit := c.GetString("single_dose_unit")
  1017. prescribing_number, _ := c.GetFloat("prescribing_number", 0)
  1018. prescribing_number_unit := c.GetString("prescribing_number_unit")
  1019. delivery_way := c.GetString("delivery_way")
  1020. execution_frequency := c.GetString("execution_frequency")
  1021. template_id, _ := c.GetInt64("template_id", -1)
  1022. advice_type, _ := c.GetInt64("advice_type", -1)
  1023. frequency_type, _ := c.GetInt64("frequency_type", -1)
  1024. week_days := c.GetString("week_days")
  1025. day_count, _ := c.GetInt64("day_count", -1)
  1026. adminUserInfo := c.GetAdminUserInfo()
  1027. template := models.DoctorAdviceTemplate{
  1028. OrgId: adminUserInfo.CurrentOrgId,
  1029. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1030. AdviceType: advice_type,
  1031. FrequencyType: frequency_type,
  1032. WeekDays: week_days,
  1033. DayCount: day_count,
  1034. Status: 1,
  1035. CreatedTime: time.Now().Unix(),
  1036. UpdatedTime: time.Now().Unix(),
  1037. DrugSpec: drug_spec,
  1038. DrugSpecUnit: drug_spec_unit,
  1039. AdviceName: advice_name,
  1040. AdviceDesc: advice_desc,
  1041. SingleDose: single_dose,
  1042. SingleDoseUnit: single_dose_unit,
  1043. PrescribingNumber: prescribing_number,
  1044. PrescribingNumberUnit: prescribing_number_unit,
  1045. DeliveryWay: delivery_way,
  1046. ExecutionFrequency: execution_frequency,
  1047. TemplateId: template_id,
  1048. }
  1049. if template.AdviceName == "" {
  1050. utils.ErrorLog("医嘱名字不能为空")
  1051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
  1052. return
  1053. }
  1054. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1055. if appRole.UserType == 3 {
  1056. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1057. if getPermissionErr != nil {
  1058. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1059. return
  1060. } else if headNursePermission == nil {
  1061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1062. return
  1063. }
  1064. }
  1065. err := service.CreateAdviceTemplate(&template)
  1066. if err != nil {
  1067. utils.ErrorLog("%v", err)
  1068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1069. return
  1070. }
  1071. c.ServeSuccessJSON(map[string]interface{}{
  1072. "template": template,
  1073. })
  1074. return
  1075. }
  1076. func (c *DataApiController) DeleteParentAdviceTemplate() {
  1077. template_id, _ := c.GetInt64("template_id", 0)
  1078. adminUserInfo := c.GetAdminUserInfo()
  1079. _, err := service.FindParentTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1080. if err != nil {
  1081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1082. return
  1083. }
  1084. err1 := service.DeleteParentDoctorAdviceByTemplateId(template_id, adminUserInfo.CurrentOrgId)
  1085. if err1 != nil {
  1086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1087. return
  1088. }
  1089. c.ServeSuccessJSON(map[string]interface{}{
  1090. "msg": "删除成功",
  1091. })
  1092. }
  1093. func (c *DataApiController) CreateSubAdviceTemplate() {
  1094. drug_spec := c.GetString("drug_spec")
  1095. drug_spec_unit := c.GetString("drug_spec_unit")
  1096. advice_name := c.GetString("advice_name")
  1097. advice_desc := c.GetString("advice_desc")
  1098. single_dose, _ := c.GetFloat("single_dose", 0)
  1099. single_dose_unit := c.GetString("single_dose_unit")
  1100. prescribing_number, _ := c.GetFloat("prescribing_number", 0)
  1101. prescribing_number_unit := c.GetString("prescribing_number_unit")
  1102. delivery_way := c.GetString("delivery_way")
  1103. execution_frequency := c.GetString("execution_frequency")
  1104. template_id, _ := c.GetInt64("template_id", 0)
  1105. parent_id, _ := c.GetInt64("parent_id", 0)
  1106. adminUserInfo := c.GetAdminUserInfo()
  1107. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1108. if appRole.UserType == 3 {
  1109. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1110. if getPermissionErr != nil {
  1111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1112. return
  1113. } else if headNursePermission == nil {
  1114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1115. return
  1116. }
  1117. }
  1118. template := models.DoctorAdviceTemplate{
  1119. OrgId: adminUserInfo.CurrentOrgId,
  1120. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1121. Status: 1,
  1122. CreatedTime: time.Now().Unix(),
  1123. UpdatedTime: time.Now().Unix(),
  1124. DrugSpec: drug_spec,
  1125. DrugSpecUnit: drug_spec_unit,
  1126. AdviceName: advice_name,
  1127. AdviceDesc: advice_desc,
  1128. SingleDose: single_dose,
  1129. SingleDoseUnit: single_dose_unit,
  1130. PrescribingNumber: prescribing_number,
  1131. PrescribingNumberUnit: prescribing_number_unit,
  1132. DeliveryWay: delivery_way,
  1133. ExecutionFrequency: execution_frequency,
  1134. TemplateId: template_id,
  1135. ParentId: parent_id,
  1136. }
  1137. if template.AdviceName == "" {
  1138. utils.ErrorLog("医嘱名字不能为空")
  1139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
  1140. return
  1141. }
  1142. err := service.CreateAdviceTemplate(&template)
  1143. if err != nil {
  1144. utils.ErrorLog("%v", err)
  1145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1146. return
  1147. }
  1148. c.ServeSuccessJSON(map[string]interface{}{
  1149. "template": template,
  1150. })
  1151. return
  1152. }
  1153. func (this *DataApiController) ModifyTemplateName() {
  1154. template_name := this.GetString("template_name")
  1155. template_id, _ := this.GetInt64("template_id", 0)
  1156. if len(template_name) <= 0 {
  1157. utils.ErrorLog("模版名字不能为空")
  1158. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  1159. return
  1160. }
  1161. if template_id == 0 {
  1162. utils.ErrorLog("模版不存在")
  1163. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamTemplateNOEXISTWrong)
  1164. return
  1165. }
  1166. adminUserInfo := this.GetAdminUserInfo()
  1167. template, _ := service.FindParentTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1168. var err error
  1169. if template.Name == template_name {
  1170. err = service.ModifyTemplateName(template_id, template_name)
  1171. if err != nil {
  1172. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1173. return
  1174. }
  1175. } else {
  1176. //total := service.FindTemplateRecordByName(adminUserInfo.CurrentOrgId, template_name);
  1177. //if total > 0 {
  1178. // utils.ErrorLog("模版名称已经存在")
  1179. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNameWrong)
  1180. // return
  1181. //}
  1182. err = service.ModifyTemplateName(template_id, template_name)
  1183. if err != nil {
  1184. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1185. return
  1186. }
  1187. }
  1188. this.ServeSuccessJSON(map[string]interface{}{
  1189. "template_name": template_name,
  1190. "template_id": template_id,
  1191. })
  1192. }
  1193. func (this *DataApiController) ModifyFiledIsShow() {
  1194. id, _ := this.GetInt64("id", 0)
  1195. is_show, _ := this.GetInt("is_show", 0)
  1196. adminUserInfo := this.GetAdminUserInfo()
  1197. err := service.ShowFiledConfig(adminUserInfo.CurrentOrgId, is_show, id)
  1198. if err != nil {
  1199. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1200. return
  1201. } else {
  1202. this.ServeSuccessJSON(map[string]interface{}{
  1203. "id": id,
  1204. "is_show": is_show,
  1205. })
  1206. }
  1207. }
  1208. func (c *DataApiController) GetAllAdviceConfigs() {
  1209. adminUserInfo := c.GetAdminUserInfo()
  1210. var drugs []models.DrugDic
  1211. drugways, _, _ := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  1212. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  1213. adviceTemplates, _ := service.FindOtherAllAdviceTemplate(adminUserInfo.CurrentOrgId)
  1214. c.ServeSuccessJSON(map[string]interface{}{
  1215. "drugs": drugs,
  1216. "drugways": drugways,
  1217. "efs": efs,
  1218. "advice_templates": adviceTemplates,
  1219. })
  1220. }
  1221. func (c *DataApiController) GetHandleData() {
  1222. id, _ := c.GetInt64("id")
  1223. config, err := service.GetHandleData(id)
  1224. if err != nil {
  1225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1226. return
  1227. }
  1228. c.ServeSuccessJSON(map[string]interface{}{
  1229. "config": config,
  1230. })
  1231. }
  1232. func (c *DataApiController) UpdateDataTwo() {
  1233. id, _ := c.GetInt64("id")
  1234. //fmt.Print("id",id)
  1235. dataBody := make(map[string]interface{}, 0)
  1236. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1237. //fmt.Print("err",err)
  1238. //fmt.Print("id",id)
  1239. name := dataBody["name"].(string)
  1240. // fmt.Print("name",name)
  1241. order := int64(dataBody["order"].(float64))
  1242. // fmt.Print("order",order)
  1243. remake := dataBody["remark"].(string)
  1244. // fmt.Print("remake",remake)
  1245. configModel := models.ConfigViewModel{
  1246. Name: name,
  1247. Order: order,
  1248. Remark: remake,
  1249. }
  1250. err = service.UpdateDataTwo(id, configModel)
  1251. if err != nil {
  1252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1253. return
  1254. }
  1255. c.ServeSuccessJSON(map[string]interface{}{
  1256. "configModel": configModel,
  1257. })
  1258. }