data_api_controller.go 42KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416
  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. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  909. if appRole.UserType == 3 {
  910. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  911. if getPermissionErr != nil {
  912. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  913. return
  914. } else if headNursePermission == nil {
  915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  916. return
  917. }
  918. }
  919. var templatedata models.DoctorAdviceTemplate
  920. err := json.Unmarshal(c.Ctx.Input.RequestBody, &templatedata)
  921. if err != nil {
  922. utils.ErrorLog("%v", err)
  923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  924. return
  925. }
  926. if templatedata.AdviceName == "" {
  927. utils.ErrorLog("不能为空")
  928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  929. return
  930. }
  931. timeNow := time.Now().Unix()
  932. template.UpdatedTime = timeNow
  933. template.AdviceName = templatedata.AdviceName
  934. template.AdviceDesc = templatedata.AdviceDesc
  935. template.SingleDose = templatedata.SingleDose
  936. template.SingleDoseUnit = templatedata.SingleDoseUnit
  937. template.PrescribingNumber = templatedata.PrescribingNumber
  938. template.PrescribingNumberUnit = templatedata.PrescribingNumberUnit
  939. template.DrugSpec = templatedata.DrugSpec
  940. template.DrugSpecUnit = templatedata.DrugSpecUnit
  941. template.DeliveryWay = templatedata.DeliveryWay
  942. template.ExecutionFrequency = templatedata.ExecutionFrequency
  943. template.FrequencyType = templatedata.FrequencyType
  944. template.DayCount = templatedata.DayCount
  945. template.WeekDays = templatedata.WeekDays
  946. err = service.UpdateAdviceTemplate(template)
  947. if err != nil {
  948. utils.ErrorLog("%v", err)
  949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  950. return
  951. }
  952. c.ServeSuccessJSON(map[string]interface{}{
  953. "template": template,
  954. })
  955. return
  956. }
  957. func (c *DataApiController) DeleteAdviceTemplate() {
  958. adminUserInfo := c.GetAdminUserInfo()
  959. parent_id, _ := c.GetInt64("parent_id", 0)
  960. id, _ := c.GetInt64("id", 0)
  961. if id <= 0 {
  962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  963. return
  964. }
  965. template, _ := service.FindAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  966. if template == nil {
  967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  968. return
  969. }
  970. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  971. if appRole.UserType == 3 {
  972. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  973. if getPermissionErr != nil {
  974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  975. return
  976. } else if headNursePermission == nil {
  977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  978. return
  979. }
  980. }
  981. timeNow := time.Now().Unix()
  982. template.ID = id
  983. template.UpdatedTime = timeNow
  984. template.ParentId = parent_id
  985. template.Status = 2
  986. if parent_id > 0 { //删除子医嘱
  987. err := service.UpdateAdviceTemplate(template)
  988. if err != nil {
  989. utils.ErrorLog("%v", err)
  990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  991. return
  992. }
  993. } else { //删除该医嘱下的所有子医嘱
  994. err := service.UpdateAdviceAndSubAdviceTemplate(template)
  995. if err != nil {
  996. utils.ErrorLog("%v", err)
  997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  998. return
  999. }
  1000. }
  1001. c.ServeSuccessJSON(map[string]interface{}{
  1002. "msg": "ok",
  1003. })
  1004. return
  1005. }
  1006. func (c *DataApiController) CreateSingleAdviceTemplate() {
  1007. drug_spec := c.GetString("drug_spec")
  1008. drug_spec_unit := c.GetString("drug_spec_unit")
  1009. advice_name := c.GetString("advice_name")
  1010. advice_desc := c.GetString("advice_desc")
  1011. single_dose, _ := c.GetFloat("single_dose", 0)
  1012. single_dose_unit := c.GetString("single_dose_unit")
  1013. prescribing_number, _ := c.GetFloat("prescribing_number", 0)
  1014. prescribing_number_unit := c.GetString("prescribing_number_unit")
  1015. delivery_way := c.GetString("delivery_way")
  1016. execution_frequency := c.GetString("execution_frequency")
  1017. template_id, _ := c.GetInt64("template_id", -1)
  1018. advice_type, _ := c.GetInt64("advice_type", -1)
  1019. frequency_type, _ := c.GetInt64("frequency_type", -1)
  1020. week_days := c.GetString("week_days")
  1021. day_count, _ := c.GetInt64("day_count", -1)
  1022. adminUserInfo := c.GetAdminUserInfo()
  1023. template := models.DoctorAdviceTemplate{
  1024. OrgId: adminUserInfo.CurrentOrgId,
  1025. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1026. AdviceType: advice_type,
  1027. FrequencyType: frequency_type,
  1028. WeekDays: week_days,
  1029. DayCount: day_count,
  1030. Status: 1,
  1031. CreatedTime: time.Now().Unix(),
  1032. UpdatedTime: time.Now().Unix(),
  1033. DrugSpec: drug_spec,
  1034. DrugSpecUnit: drug_spec_unit,
  1035. AdviceName: advice_name,
  1036. AdviceDesc: advice_desc,
  1037. SingleDose: single_dose,
  1038. SingleDoseUnit: single_dose_unit,
  1039. PrescribingNumber: prescribing_number,
  1040. PrescribingNumberUnit: prescribing_number_unit,
  1041. DeliveryWay: delivery_way,
  1042. ExecutionFrequency: execution_frequency,
  1043. TemplateId: template_id,
  1044. }
  1045. if template.AdviceName == "" {
  1046. utils.ErrorLog("医嘱名字不能为空")
  1047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
  1048. return
  1049. }
  1050. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1051. if appRole.UserType == 3 {
  1052. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1053. if getPermissionErr != nil {
  1054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1055. return
  1056. } else if headNursePermission == nil {
  1057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1058. return
  1059. }
  1060. }
  1061. err := service.CreateAdviceTemplate(&template)
  1062. if err != nil {
  1063. utils.ErrorLog("%v", err)
  1064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1065. return
  1066. }
  1067. c.ServeSuccessJSON(map[string]interface{}{
  1068. "template": template,
  1069. })
  1070. return
  1071. }
  1072. func (c *DataApiController) DeleteParentAdviceTemplate() {
  1073. template_id, _ := c.GetInt64("template_id", 0)
  1074. adminUserInfo := c.GetAdminUserInfo()
  1075. _, err := service.FindParentTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1076. if err != nil {
  1077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1078. return
  1079. }
  1080. err1 := service.DeleteParentDoctorAdviceByTemplateId(template_id, adminUserInfo.CurrentOrgId)
  1081. if err1 != nil {
  1082. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1083. return
  1084. }
  1085. c.ServeSuccessJSON(map[string]interface{}{
  1086. "msg": "删除成功",
  1087. })
  1088. }
  1089. func (c *DataApiController) CreateSubAdviceTemplate() {
  1090. drug_spec := c.GetString("drug_spec")
  1091. drug_spec_unit := c.GetString("drug_spec_unit")
  1092. advice_name := c.GetString("advice_name")
  1093. advice_desc := c.GetString("advice_desc")
  1094. single_dose, _ := c.GetFloat("single_dose", 0)
  1095. single_dose_unit := c.GetString("single_dose_unit")
  1096. prescribing_number, _ := c.GetFloat("prescribing_number", 0)
  1097. prescribing_number_unit := c.GetString("prescribing_number_unit")
  1098. delivery_way := c.GetString("delivery_way")
  1099. execution_frequency := c.GetString("execution_frequency")
  1100. template_id, _ := c.GetInt64("template_id", 0)
  1101. parent_id, _ := c.GetInt64("parent_id", 0)
  1102. adminUserInfo := c.GetAdminUserInfo()
  1103. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1104. if appRole.UserType == 3 {
  1105. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1106. if getPermissionErr != nil {
  1107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1108. return
  1109. } else if headNursePermission == nil {
  1110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1111. return
  1112. }
  1113. }
  1114. template := models.DoctorAdviceTemplate{
  1115. OrgId: adminUserInfo.CurrentOrgId,
  1116. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1117. Status: 1,
  1118. CreatedTime: time.Now().Unix(),
  1119. UpdatedTime: time.Now().Unix(),
  1120. DrugSpec: drug_spec,
  1121. DrugSpecUnit: drug_spec_unit,
  1122. AdviceName: advice_name,
  1123. AdviceDesc: advice_desc,
  1124. SingleDose: single_dose,
  1125. SingleDoseUnit: single_dose_unit,
  1126. PrescribingNumber: prescribing_number,
  1127. PrescribingNumberUnit: prescribing_number_unit,
  1128. DeliveryWay: delivery_way,
  1129. ExecutionFrequency: execution_frequency,
  1130. TemplateId: template_id,
  1131. ParentId: parent_id,
  1132. }
  1133. if template.AdviceName == "" {
  1134. utils.ErrorLog("医嘱名字不能为空")
  1135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
  1136. return
  1137. }
  1138. err := service.CreateAdviceTemplate(&template)
  1139. if err != nil {
  1140. utils.ErrorLog("%v", err)
  1141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1142. return
  1143. }
  1144. c.ServeSuccessJSON(map[string]interface{}{
  1145. "template": template,
  1146. })
  1147. return
  1148. }
  1149. func (this *DataApiController) ModifyTemplateName() {
  1150. template_name := this.GetString("template_name")
  1151. template_id, _ := this.GetInt64("template_id", 0)
  1152. if len(template_name) <= 0 {
  1153. utils.ErrorLog("模版名字不能为空")
  1154. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  1155. return
  1156. }
  1157. if template_id == 0 {
  1158. utils.ErrorLog("模版不存在")
  1159. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamTemplateNOEXISTWrong)
  1160. return
  1161. }
  1162. adminUserInfo := this.GetAdminUserInfo()
  1163. template, _ := service.FindParentTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1164. var err error
  1165. if template.Name == template_name {
  1166. err = service.ModifyTemplateName(template_id, template_name)
  1167. if err != nil {
  1168. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1169. return
  1170. }
  1171. } else {
  1172. //total := service.FindTemplateRecordByName(adminUserInfo.CurrentOrgId, template_name);
  1173. //if total > 0 {
  1174. // utils.ErrorLog("模版名称已经存在")
  1175. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNameWrong)
  1176. // return
  1177. //}
  1178. err = service.ModifyTemplateName(template_id, template_name)
  1179. if err != nil {
  1180. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1181. return
  1182. }
  1183. }
  1184. this.ServeSuccessJSON(map[string]interface{}{
  1185. "template_name": template_name,
  1186. "template_id": template_id,
  1187. })
  1188. }
  1189. func (this *DataApiController) ModifyFiledIsShow() {
  1190. id, _ := this.GetInt64("id", 0)
  1191. is_show, _ := this.GetInt("is_show", 0)
  1192. adminUserInfo := this.GetAdminUserInfo()
  1193. err := service.ShowFiledConfig(adminUserInfo.CurrentOrgId, is_show, id)
  1194. if err != nil {
  1195. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1196. return
  1197. } else {
  1198. this.ServeSuccessJSON(map[string]interface{}{
  1199. "id": id,
  1200. "is_show": is_show,
  1201. })
  1202. }
  1203. }
  1204. func (c *DataApiController) GetAllAdviceConfigs() {
  1205. adminUserInfo := c.GetAdminUserInfo()
  1206. var drugs []models.DrugDic
  1207. drugways, _, _ := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  1208. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  1209. adviceTemplates, _ := service.FindOtherAllAdviceTemplate(adminUserInfo.CurrentOrgId)
  1210. c.ServeSuccessJSON(map[string]interface{}{
  1211. "drugs": drugs,
  1212. "drugways": drugways,
  1213. "efs": efs,
  1214. "advice_templates": adviceTemplates,
  1215. })
  1216. }
  1217. func (c *DataApiController) GetHandleData() {
  1218. id, _ := c.GetInt64("id")
  1219. config, err := service.GetHandleData(id)
  1220. if err != nil {
  1221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1222. return
  1223. }
  1224. c.ServeSuccessJSON(map[string]interface{}{
  1225. "config": config,
  1226. })
  1227. }
  1228. func (c *DataApiController) UpdateDataTwo() {
  1229. id, _ := c.GetInt64("id")
  1230. //fmt.Print("id",id)
  1231. dataBody := make(map[string]interface{}, 0)
  1232. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1233. //fmt.Print("err",err)
  1234. //fmt.Print("id",id)
  1235. name := dataBody["name"].(string)
  1236. // fmt.Print("name",name)
  1237. order := int64(dataBody["order"].(float64))
  1238. // fmt.Print("order",order)
  1239. remake := dataBody["remark"].(string)
  1240. // fmt.Print("remake",remake)
  1241. configModel := models.ConfigViewModel{
  1242. Name: name,
  1243. Order: order,
  1244. Remark: remake,
  1245. }
  1246. err = service.UpdateDataTwo(id, configModel)
  1247. if err != nil {
  1248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1249. return
  1250. }
  1251. c.ServeSuccessJSON(map[string]interface{}{
  1252. "configModel": configModel,
  1253. })
  1254. }