data_api_controller.go 43KB

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