data_api_controller.go 42KB

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