data_api_controller.go 42KB

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