data_api_controller.go 42KB

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