data_api_controller.go 42KB

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