data_api_controller.go 42KB

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