data_api_controller.go 57KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831
  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/hisadvicetemplate/create", &DataApiController{}, "Post:CreateHisAdviceTemplate")
  46. beego.Router("/api/hisadvicetemplate/update", &DataApiController{}, "Put:UpdateHisAdviceTemplate")
  47. beego.Router("/api/hisadvicetemplate/delete", &DataApiController{}, "Delete:DeleteHisAdviceTemplate")
  48. beego.Router("/api/hisadvicetemplate/add", &DataApiController{}, "Post:CreateSingleHisAdviceTemplate")
  49. beego.Router("/api/hisadviceparenttemplate/delete", &DataApiController{}, "Delete:DeleteHisParentAdviceTemplate")
  50. beego.Router("/api/histemplate/modify", &DataApiController{}, "Post:ModifyHisTemplateName")
  51. beego.Router("/api/getallhisadvicetemplate", &DataApiController{}, "Get:GetAllHisAdviceTemplate")
  52. }
  53. //GetPatientsList 取配置信息列表
  54. func (c *DataApiController) GetConfigList() {
  55. adminUserInfo := c.GetAdminUserInfo()
  56. configList, _ := service.GetConfigList(adminUserInfo.CurrentOrgId)
  57. c.ServeSuccessJSON(map[string]interface{}{
  58. "configlist": configList,
  59. })
  60. return
  61. }
  62. //CreateConfig 创建配置信息
  63. func (c *DataApiController) CreateConfig() {
  64. adminUserInfo := c.GetAdminUserInfo()
  65. var dataconfig models.Dataconfig
  66. var resultConfig models.ConfigViewModel
  67. code := configFormData(&dataconfig, c.Ctx.Input.RequestBody)
  68. if code > 0 {
  69. c.ServeFailJSONWithSGJErrorCode(code)
  70. return
  71. }
  72. // 验证关键字段的值是否重复
  73. thisConfig, _ := service.FindConfigByTitle(dataconfig.Module, dataconfig.FieldName, adminUserInfo.CurrentOrgId)
  74. fmt.Println("99999", thisConfig)
  75. if thisConfig.ID > 0 {
  76. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  77. return
  78. }
  79. fieldValue := service.GetChildValue(dataconfig.Module, dataconfig.ParentId, adminUserInfo.CurrentOrgId)
  80. dataconfig.Value = fieldValue + 1
  81. dataBody := make(map[string]interface{}, 0)
  82. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  83. if err != nil {
  84. utils.ErrorLog(err.Error())
  85. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  86. return
  87. }
  88. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  89. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  90. dataconfig.Status = 1
  91. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  92. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  93. dataconfig.Remark = string(dataBody["remark"].(string))
  94. if dataBody["order"] != nil {
  95. dataconfig.Order = int64(dataBody["order"].(float64))
  96. } else {
  97. dataconfig.Order = 0
  98. }
  99. err = service.CreateConfig(&dataconfig)
  100. if err != nil {
  101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  102. return
  103. } else {
  104. resultConfig.ID = dataconfig.ID
  105. resultConfig.Module = dataconfig.Module
  106. resultConfig.Name = dataconfig.Name
  107. resultConfig.OrgId = dataconfig.OrgId
  108. resultConfig.ParentId = dataconfig.ParentId
  109. resultConfig.FieldName = dataconfig.FieldName
  110. resultConfig.CreateUserId = dataconfig.CreateUserId
  111. resultConfig.Title = dataconfig.Title
  112. resultConfig.Content = dataconfig.Content
  113. }
  114. c.ServeSuccessJSON(map[string]interface{}{
  115. "dataconfig": resultConfig,
  116. "msg": "ok",
  117. })
  118. return
  119. }
  120. func (c *DataApiController) UpdateTemplate() {
  121. adminUserInfo := c.GetAdminUserInfo()
  122. var dataconfig models.Dataconfig
  123. code := configFormData(&dataconfig, c.Ctx.Input.RequestBody)
  124. if code > 0 {
  125. c.ServeFailJSONWithSGJErrorCode(code)
  126. return
  127. }
  128. dataBody := make(map[string]interface{}, 0)
  129. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  130. if err != nil {
  131. utils.ErrorLog(err.Error())
  132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  133. return
  134. }
  135. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  136. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  137. dataconfig.Status = 1
  138. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  139. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  140. dataconfig.Remark = string(dataBody["remark"].(string))
  141. if dataBody["order"] != nil {
  142. dataconfig.Order = int64(dataBody["order"].(float64))
  143. } else {
  144. dataconfig.Order = 0
  145. }
  146. // 验证关键字段的值是否重复
  147. // cur_id := int64(dataBody["id"].(float64))
  148. // thisConfig,_:=service.FindConfigByTitleForUpdate(dataconfig.Module, dataconfig.Title,dataconfig.OrgId,cur_id)
  149. // if thisConfig.ID >0 {
  150. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  151. // return
  152. // }
  153. configOrgId := int64(dataBody["org_id"].(float64))
  154. if configOrgId == 0 {
  155. dataconfig.DeleteIdSystem = int64(dataBody["id"].(float64))
  156. err := service.CreateConfig(&dataconfig)
  157. if err != nil {
  158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  159. return
  160. }
  161. } else {
  162. dataconfig.ID = int64(dataBody["id"].(float64))
  163. err = service.UpdateTemplate(&dataconfig)
  164. if err != nil {
  165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  166. return
  167. }
  168. }
  169. c.ServeSuccessJSON(map[string]interface{}{
  170. "dataconfig": dataconfig,
  171. "msg": "ok",
  172. })
  173. return
  174. }
  175. func (c *DataApiController) UpdateChildConfig() {
  176. adminUserInfo := c.GetAdminUserInfo()
  177. var dataconfig models.Dataconfig
  178. code := configChildFormData(&dataconfig, c.Ctx.Input.RequestBody)
  179. if code > 0 {
  180. c.ServeFailJSONWithSGJErrorCode(code)
  181. return
  182. }
  183. dataBody := make(map[string]interface{}, 0)
  184. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  185. if err != nil {
  186. utils.ErrorLog(err.Error())
  187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  188. return
  189. }
  190. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  191. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  192. dataconfig.Status = 1
  193. dataconfig.Value = int(int64(dataBody["value"].(float64)))
  194. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  195. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  196. dataconfig.Remark = string(dataBody["remark"].(string))
  197. dataconfig.Order = int64(dataBody["orders"].(float64))
  198. dataconfig.FieldType = int64(dataBody["field_type"].(float64))
  199. //if dataBody["orders"] != nil {
  200. // dataconfig.Order = int64(dataBody["orders"].(float64))
  201. // fmt.Println("dataconfig",dataconfig.Order)
  202. //} else {
  203. // dataconfig.Order = 0
  204. //}
  205. configOrgId := int64(dataBody["org_id"].(float64))
  206. // 验证关键字段的值是否重复
  207. // configId := int64(dataBody["id"].(float64))
  208. // thisConfig,_:=service.FindConfigByNameForUpdate(dataconfig.Module, dataconfig.Name,dataconfig.ParentId,dataconfig.OrgId,configId)
  209. // if thisConfig.ID >0 {
  210. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  211. // return
  212. // }
  213. if configOrgId == 0 {
  214. dataconfig.DeleteIdSystem = int64(dataBody["id"].(float64))
  215. err := service.CreateConfig(&dataconfig)
  216. if err != nil {
  217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  218. return
  219. }
  220. } else {
  221. dataconfig.ID = int64(dataBody["id"].(float64))
  222. err = service.UpdateChildConfig(&dataconfig)
  223. if err != nil {
  224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  225. return
  226. }
  227. }
  228. c.ServeSuccessJSON(map[string]interface{}{
  229. "dataconfig": dataconfig,
  230. "msg": "ok",
  231. })
  232. return
  233. }
  234. func (c *DataApiController) DeleteChildConfig() {
  235. adminUserInfo := c.GetAdminUserInfo()
  236. var dataconfig models.Dataconfig
  237. code := configChildFormData(&dataconfig, c.Ctx.Input.RequestBody)
  238. if code > 0 {
  239. c.ServeFailJSONWithSGJErrorCode(code)
  240. return
  241. }
  242. dataBody := make(map[string]interface{}, 0)
  243. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  244. if err != nil {
  245. utils.ErrorLog(err.Error())
  246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  247. return
  248. }
  249. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  250. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  251. dataconfig.Status = 0
  252. dataconfig.Value = int(int64(dataBody["value"].(float64)))
  253. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  254. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  255. dataconfig.Remark = string(dataBody["remark"].(string))
  256. if dataBody["order"] != nil {
  257. dataconfig.Order = int64(dataBody["order"].(float64))
  258. } else {
  259. dataconfig.Order = 0
  260. }
  261. configOrgId := int64(dataBody["org_id"].(float64))
  262. if configOrgId == 0 {
  263. dataconfig.DeleteIdSystem = int64(dataBody["id"].(float64))
  264. err := service.CreateConfig(&dataconfig)
  265. if err != nil {
  266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  267. return
  268. }
  269. } else {
  270. dataconfig.ID = int64(dataBody["id"].(float64))
  271. err := service.DeleteChildConfig(&dataconfig)
  272. if err != nil {
  273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  274. return
  275. }
  276. }
  277. c.ServeSuccessJSON(map[string]interface{}{
  278. "dataconfig": dataconfig,
  279. "msg": "ok",
  280. })
  281. return
  282. }
  283. //CreateChildConfig 创建子配置信息
  284. func (c *DataApiController) CreateChildConfig() {
  285. adminUserInfo := c.GetAdminUserInfo()
  286. var dataconfig models.Dataconfig
  287. code := configChildFormData(&dataconfig, c.Ctx.Input.RequestBody)
  288. if code > 0 {
  289. c.ServeFailJSONWithSGJErrorCode(code)
  290. return
  291. }
  292. dataBody := make(map[string]interface{}, 0)
  293. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  294. if err != nil {
  295. utils.ErrorLog(err.Error())
  296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  297. return
  298. }
  299. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  300. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  301. dataconfig.Status = 1
  302. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  303. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  304. dataconfig.Remark = string(dataBody["remark"].(string))
  305. if dataBody["order"] != nil {
  306. dataconfig.Order = int64(dataBody["order"].(float64))
  307. } else {
  308. dataconfig.Order = 0
  309. }
  310. if dataBody["field_type"] != nil {
  311. dataconfig.FieldType = int64(dataBody["field_type"].(float64))
  312. } else {
  313. dataconfig.FieldType = 0
  314. }
  315. // 验证关键字段的值是否重复
  316. // thisConfig,_:=service.FindConfigByName(dataconfig.Module, dataconfig.Name,dataconfig.ParentId,dataconfig.OrgId)
  317. // if thisConfig.ID >0 {
  318. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  319. // return
  320. // }
  321. fieldValue := service.GetChildValue(dataconfig.Module, dataconfig.ParentId, dataconfig.OrgId)
  322. dataconfig.Value = fieldValue + 1
  323. err = service.CreateConfig(&dataconfig)
  324. if err != nil {
  325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  326. return
  327. }
  328. c.ServeSuccessJSON(map[string]interface{}{
  329. "dataconfig": dataconfig,
  330. "msg": "ok",
  331. })
  332. return
  333. }
  334. func configFormData(dataconfig *models.Dataconfig, data []byte) (code int) {
  335. configBody := make(map[string]interface{}, 0)
  336. err := json.Unmarshal(data, &configBody)
  337. utils.InfoLog(string(data))
  338. if err != nil {
  339. utils.ErrorLog(err.Error())
  340. code = enums.ErrorCodeParamWrong
  341. return
  342. }
  343. if configBody["module"] == nil || reflect.TypeOf(configBody["module"]).String() != "string" {
  344. utils.ErrorLog("module")
  345. code = enums.ErrorCodeParamWrong
  346. return
  347. }
  348. module, _ := configBody["module"].(string)
  349. if len(module) == 0 {
  350. utils.ErrorLog("len(module) == 0")
  351. code = enums.ErrorCodeParamWrong
  352. return
  353. }
  354. dataconfig.Module = module
  355. if module == "education" || module == "summary" || module == "course_disease" || module == "rescue_record" || module == "nursing_record" || module == "special_record" || module == "special_treatment" || module == "template_summary" || module == "template_plan" || module == "admitting_diagnosis" || module == "discharge_diagnosis" || module == "diagnosis_admission" || module == "treatment" || module == "illness_discharge" || module == "discharge_advice" {
  356. if configBody["title"] == nil || reflect.TypeOf(configBody["title"]).String() != "string" {
  357. utils.ErrorLog("title")
  358. code = enums.ErrorCodeParamWrong
  359. return
  360. }
  361. title, _ := configBody["title"].(string)
  362. if len(title) == 0 {
  363. utils.ErrorLog("len(title) == 0")
  364. code = enums.ErrorCodeParamWrong
  365. return
  366. }
  367. dataconfig.Title = title
  368. if configBody["content"] == nil || reflect.TypeOf(configBody["content"]).String() != "string" {
  369. utils.ErrorLog("content")
  370. code = enums.ErrorCodeParamWrong
  371. return
  372. }
  373. content, _ := configBody["content"].(string)
  374. if len(content) == 0 {
  375. utils.ErrorLog("len(content) == 0")
  376. code = enums.ErrorCodeParamWrong
  377. return
  378. }
  379. dataconfig.Content = content
  380. } else {
  381. if configBody["name"] == nil || reflect.TypeOf(configBody["name"]).String() != "string" {
  382. utils.ErrorLog("name")
  383. code = enums.ErrorCodeParamWrong
  384. return
  385. }
  386. name, _ := configBody["name"].(string)
  387. if len(name) == 0 {
  388. utils.ErrorLog("len(name) == 0")
  389. code = enums.ErrorCodeParamWrong
  390. return
  391. }
  392. dataconfig.Name = name
  393. if configBody["field_name"] == nil || reflect.TypeOf(configBody["field_name"]).String() != "string" {
  394. utils.ErrorLog("field_name")
  395. code = enums.ErrorCodeParamWrong
  396. return
  397. }
  398. field_name, _ := configBody["field_name"].(string)
  399. if len(field_name) == 0 {
  400. utils.ErrorLog("len(field_name) == 0")
  401. code = enums.ErrorCodeParamWrong
  402. return
  403. }
  404. dataconfig.FieldName = field_name
  405. }
  406. return
  407. }
  408. func configChildFormData(dataconfig *models.Dataconfig, data []byte) (code int) {
  409. configBody := make(map[string]interface{}, 0)
  410. err := json.Unmarshal(data, &configBody)
  411. utils.InfoLog(string(data))
  412. if err != nil {
  413. utils.ErrorLog(err.Error())
  414. code = enums.ErrorCodeParamWrong
  415. return
  416. }
  417. if configBody["module"] == nil || reflect.TypeOf(configBody["module"]).String() != "string" {
  418. utils.ErrorLog("module")
  419. code = enums.ErrorCodeParamWrong
  420. return
  421. }
  422. module, _ := configBody["module"].(string)
  423. if len(module) == 0 {
  424. utils.ErrorLog("len(module) == 0")
  425. code = enums.ErrorCodeParamWrong
  426. return
  427. }
  428. dataconfig.Module = module
  429. if module == "education" || module == "summary" {
  430. if configBody["title"] == nil || reflect.TypeOf(configBody["title"]).String() != "string" {
  431. utils.ErrorLog("title")
  432. code = enums.ErrorCodeParamWrong
  433. return
  434. }
  435. title, _ := configBody["title"].(string)
  436. if len(title) == 0 {
  437. utils.ErrorLog("len(title) == 0")
  438. code = enums.ErrorCodeParamWrong
  439. return
  440. }
  441. dataconfig.Title = title
  442. if configBody["content"] == nil || reflect.TypeOf(configBody["content"]).String() != "string" {
  443. utils.ErrorLog("content")
  444. code = enums.ErrorCodeParamWrong
  445. return
  446. }
  447. content, _ := configBody["content"].(string)
  448. if len(content) == 0 {
  449. utils.ErrorLog("len(content) == 0")
  450. code = enums.ErrorCodeParamWrong
  451. return
  452. }
  453. dataconfig.Content = content
  454. } else {
  455. if configBody["parent_id"] == nil || reflect.TypeOf(configBody["parent_id"]).String() != "float64" {
  456. utils.ErrorLog("module")
  457. code = enums.ErrorCodeParamWrong
  458. return
  459. }
  460. parent_id := int64(configBody["parent_id"].(float64))
  461. //if parent_id <= 0 {
  462. // utils.ErrorLog("parent_id <= 0")
  463. // code = enums.ErrorCodeParamWrong
  464. // return
  465. //}
  466. dataconfig.ParentId = parent_id
  467. if configBody["name"] == nil || reflect.TypeOf(configBody["name"]).String() != "string" {
  468. utils.ErrorLog("name")
  469. code = enums.ErrorCodeParamWrong
  470. return
  471. }
  472. name, _ := configBody["name"].(string)
  473. //if len(name) == 0 {
  474. // utils.ErrorLog("len(name) == 0")
  475. // code = enums.ErrorCodeParamWrong
  476. // return
  477. //}
  478. dataconfig.Name = name
  479. }
  480. return
  481. }
  482. func (c *DataApiController) GetAdviceConfigs() {
  483. advice_type, _ := c.GetInt64("type", 0)
  484. adminUserInfo := c.GetAdminUserInfo()
  485. var drugs []models.DrugDic
  486. drugways, _, _ := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  487. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  488. adviceTemplates, _ := service.FindAllAdviceTemplate(adminUserInfo.CurrentOrgId, advice_type)
  489. c.ServeSuccessJSON(map[string]interface{}{
  490. "drugs": drugs,
  491. "drugways": drugways,
  492. "efs": efs,
  493. "advice_templates": adviceTemplates,
  494. })
  495. }
  496. func (c *DataApiController) CreateDrugDic() {
  497. adminUserInfo := c.GetAdminUserInfo()
  498. var drugdic models.DrugDic
  499. err := json.Unmarshal(c.Ctx.Input.RequestBody, &drugdic)
  500. if err != nil {
  501. utils.ErrorLog("%v", err)
  502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  503. return
  504. }
  505. if drugdic.Name == "" {
  506. utils.ErrorLog("医嘱名称不能为空")
  507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  508. return
  509. }
  510. timeNow := time.Now().Unix()
  511. drugdic.Code = ""
  512. drugdic.Status = 1
  513. drugdic.CreatedTime = timeNow
  514. drugdic.UpdatedTime = timeNow
  515. drugdic.OrgId = adminUserInfo.CurrentOrgId
  516. drugdic.Creator = adminUserInfo.AdminUser.Id
  517. err = service.CreateDrugDic(&drugdic)
  518. if err != nil {
  519. utils.ErrorLog("%v", err)
  520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  521. return
  522. }
  523. drugways_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_drugways"
  524. redis := service.RedisClient()
  525. defer redis.Close()
  526. redis.Set(drugways_keys, "", time.Second*60*60*18)
  527. c.ServeSuccessJSON(map[string]interface{}{
  528. "drugdic": drugdic,
  529. })
  530. return
  531. }
  532. func (c *DataApiController) UpdateDrugDic() {
  533. adminUserInfo := c.GetAdminUserInfo()
  534. id, _ := c.GetInt64("id", 0)
  535. if id <= 0 {
  536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  537. return
  538. }
  539. drugdic, _ := service.FindDrugDic(adminUserInfo.CurrentOrgId, id)
  540. if drugdic == nil {
  541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  542. return
  543. }
  544. var drugdicdata models.DrugDic
  545. err := json.Unmarshal(c.Ctx.Input.RequestBody, &drugdicdata)
  546. if err != nil {
  547. utils.ErrorLog("%v", err)
  548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  549. return
  550. }
  551. if drugdicdata.Name == "" {
  552. utils.ErrorLog("医嘱名称不能为空")
  553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  554. return
  555. }
  556. timeNow := time.Now().Unix()
  557. drugdic.UpdatedTime = timeNow
  558. drugdic.Name = drugdicdata.Name
  559. drugdic.Spec = drugdicdata.Spec
  560. drugdic.SpecUnit = drugdicdata.SpecUnit
  561. drugdic.Form = drugdicdata.Form
  562. drugdic.FormUnit = drugdicdata.FormUnit
  563. err = service.UpdateDrugDic(drugdic)
  564. if err != nil {
  565. utils.ErrorLog("%v", err)
  566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  567. return
  568. }
  569. drugways_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_drugways"
  570. redis := service.RedisClient()
  571. defer redis.Close()
  572. redis.Set(drugways_keys, "", time.Second*60*60*18)
  573. c.ServeSuccessJSON(map[string]interface{}{
  574. "drugdic": drugdic,
  575. })
  576. return
  577. }
  578. func (c *DataApiController) DeleteDrugDic() {
  579. adminUserInfo := c.GetAdminUserInfo()
  580. id, _ := c.GetInt64("id", 0)
  581. if id <= 0 {
  582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  583. return
  584. }
  585. drugdic, _ := service.FindDrugDic(adminUserInfo.CurrentOrgId, id)
  586. if drugdic == nil {
  587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  588. return
  589. }
  590. timeNow := time.Now().Unix()
  591. drugdic.UpdatedTime = timeNow
  592. drugdic.Status = 2
  593. err := service.UpdateDrugDic(drugdic)
  594. if err != nil {
  595. utils.ErrorLog("%v", err)
  596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  597. return
  598. }
  599. drugways_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_drugways"
  600. redis := service.RedisClient()
  601. defer redis.Close()
  602. redis.Set(drugways_keys, "", time.Second*60*60*18)
  603. c.ServeSuccessJSON(map[string]interface{}{
  604. "msg": "ok",
  605. })
  606. return
  607. }
  608. func (c *DataApiController) CreateDrugWay() {
  609. adminUserInfo := c.GetAdminUserInfo()
  610. var drugway models.DrugwayDic
  611. err := json.Unmarshal(c.Ctx.Input.RequestBody, &drugway)
  612. if err != nil {
  613. utils.ErrorLog("%v", err)
  614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  615. return
  616. }
  617. if drugway.Name == "" {
  618. utils.ErrorLog("给药途径不能为空")
  619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  620. return
  621. }
  622. timeNow := time.Now().Unix()
  623. drugway.Code = ""
  624. drugway.Status = 1
  625. drugway.CreatedTime = timeNow
  626. drugway.UpdatedTime = timeNow
  627. drugway.OrgId = adminUserInfo.CurrentOrgId
  628. drugway.Creator = adminUserInfo.AdminUser.Id
  629. err = service.CreateDrugWay(&drugway)
  630. if err != nil {
  631. utils.ErrorLog("%v", err)
  632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  633. return
  634. }
  635. drugways_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_drugways"
  636. redis := service.RedisClient()
  637. defer redis.Close()
  638. redis.Set(drugways_keys, "", time.Second*60*60*18)
  639. c.ServeSuccessJSON(map[string]interface{}{
  640. "drugway": drugway,
  641. })
  642. return
  643. }
  644. func (c *DataApiController) UpdateDrugWay() {
  645. adminUserInfo := c.GetAdminUserInfo()
  646. id, _ := c.GetInt64("id", 0)
  647. if id <= 0 {
  648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  649. return
  650. }
  651. drugway, _ := service.FindDrugWay(adminUserInfo.CurrentOrgId, id)
  652. if drugway == nil {
  653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  654. return
  655. }
  656. var drugwaydata models.DrugwayDic
  657. err := json.Unmarshal(c.Ctx.Input.RequestBody, &drugwaydata)
  658. if err != nil {
  659. utils.ErrorLog("%v", err)
  660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  661. return
  662. }
  663. if drugwaydata.Name == "" {
  664. utils.ErrorLog("给药途径不能为空")
  665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  666. return
  667. }
  668. timeNow := time.Now().Unix()
  669. drugway.UpdatedTime = timeNow
  670. drugway.Name = drugwaydata.Name
  671. err = service.UpdateDrugWay(drugway)
  672. if err != nil {
  673. utils.ErrorLog("%v", err)
  674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  675. return
  676. }
  677. drugways_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_drugways"
  678. redis := service.RedisClient()
  679. defer redis.Close()
  680. redis.Set(drugways_keys, "", time.Second*60*60*18)
  681. c.ServeSuccessJSON(map[string]interface{}{
  682. "drugway": drugway,
  683. })
  684. return
  685. }
  686. func (c *DataApiController) DeleteDrugWay() {
  687. adminUserInfo := c.GetAdminUserInfo()
  688. id, _ := c.GetInt64("id", 0)
  689. if id <= 0 {
  690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  691. return
  692. }
  693. drugway, _ := service.FindDrugWay(adminUserInfo.CurrentOrgId, id)
  694. if drugway == nil {
  695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  696. return
  697. }
  698. timeNow := time.Now().Unix()
  699. drugway.UpdatedTime = timeNow
  700. drugway.Status = 2
  701. err := service.UpdateDrugWay(drugway)
  702. if err != nil {
  703. utils.ErrorLog("%v", err)
  704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  705. return
  706. }
  707. drugways_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_drugways"
  708. redis := service.RedisClient()
  709. defer redis.Close()
  710. redis.Set(drugways_keys, "", time.Second*60*60*18)
  711. c.ServeSuccessJSON(map[string]interface{}{
  712. "msg": "ok",
  713. })
  714. return
  715. }
  716. func (c *DataApiController) CreateExecutionFrequency() {
  717. adminUserInfo := c.GetAdminUserInfo()
  718. var ef models.ExecutionFrequencyDic
  719. err := json.Unmarshal(c.Ctx.Input.RequestBody, &ef)
  720. if err != nil {
  721. utils.ErrorLog("%v", err)
  722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  723. return
  724. }
  725. if ef.Name == "" {
  726. utils.ErrorLog("执行频率不能为空")
  727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  728. return
  729. }
  730. timeNow := time.Now().Unix()
  731. ef.Code = ""
  732. ef.Status = 1
  733. ef.CreatedTime = timeNow
  734. ef.UpdatedTime = timeNow
  735. ef.OrgId = adminUserInfo.CurrentOrgId
  736. ef.Creator = adminUserInfo.AdminUser.Id
  737. err = service.CreateExecutionFrequency(&ef)
  738. if err != nil {
  739. utils.ErrorLog("%v", err)
  740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  741. return
  742. }
  743. efs_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_efs"
  744. redis := service.RedisClient()
  745. defer redis.Close()
  746. redis.Set(efs_keys, "", time.Second*60*60*18)
  747. c.ServeSuccessJSON(map[string]interface{}{
  748. "ef": ef,
  749. })
  750. return
  751. }
  752. func (c *DataApiController) UpdateExecutionFrequency() {
  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. var efdata models.ExecutionFrequencyDic
  765. err := json.Unmarshal(c.Ctx.Input.RequestBody, &efdata)
  766. if err != nil {
  767. utils.ErrorLog("%v", err)
  768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  769. return
  770. }
  771. if efdata.Name == "" {
  772. utils.ErrorLog("执行频率不能为空")
  773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  774. return
  775. }
  776. timeNow := time.Now().Unix()
  777. ef.UpdatedTime = timeNow
  778. ef.Name = efdata.Name
  779. err = service.UpdateExecutionFrequency(ef)
  780. if err != nil {
  781. utils.ErrorLog("%v", err)
  782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  783. return
  784. }
  785. efs_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_efs"
  786. redis := service.RedisClient()
  787. defer redis.Close()
  788. redis.Set(efs_keys, "", time.Second*60*60*18)
  789. c.ServeSuccessJSON(map[string]interface{}{
  790. "ef": ef,
  791. })
  792. return
  793. }
  794. func (c *DataApiController) DeleteExecutionFrequency() {
  795. adminUserInfo := c.GetAdminUserInfo()
  796. id, _ := c.GetInt64("id", 0)
  797. if id <= 0 {
  798. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  799. return
  800. }
  801. ef, _ := service.FindExecutionFrequency(adminUserInfo.CurrentOrgId, id)
  802. if ef == nil {
  803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  804. return
  805. }
  806. timeNow := time.Now().Unix()
  807. ef.UpdatedTime = timeNow
  808. ef.Status = 2
  809. err := service.UpdateExecutionFrequency(ef)
  810. if err != nil {
  811. utils.ErrorLog("%v", err)
  812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  813. return
  814. }
  815. efs_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_efs"
  816. redis := service.RedisClient()
  817. defer redis.Close()
  818. redis.Set(efs_keys, "", time.Second*60*60*18)
  819. c.ServeSuccessJSON(map[string]interface{}{
  820. "msg": "ok",
  821. })
  822. return
  823. }
  824. func (c *DataApiController) CreateAdviceTemplate() {
  825. templateName := c.GetString("template_name")
  826. advice_type, _ := c.GetInt64("advice_type")
  827. sort, _ := c.GetInt64("sort")
  828. if templateName == "" {
  829. utils.ErrorLog("模版名称不能为空")
  830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  831. return
  832. }
  833. if advice_type < 0 {
  834. utils.ErrorLog("医嘱模版类型不能为空")
  835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceTypeWrong)
  836. return
  837. }
  838. adminUserInfo := c.GetAdminUserInfo()
  839. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  840. if appRole.UserType == 3 {
  841. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  842. if getPermissionErr != nil {
  843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  844. return
  845. } else if headNursePermission == nil {
  846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  847. return
  848. }
  849. }
  850. template := &models.DoctorAdviceParentTemplate{
  851. Name: templateName,
  852. OrgId: adminUserInfo.CurrentOrgId,
  853. Status: 1,
  854. CreatedTime: time.Now().Unix(),
  855. UpdatedTime: time.Now().Unix(),
  856. AdviceType: advice_type,
  857. Sort: sort,
  858. }
  859. createErr := service.CreateTemplate(template)
  860. if createErr != nil {
  861. utils.ErrorLog("%v", createErr)
  862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  863. return
  864. }
  865. dataBody := make(map[string]interface{}, 0)
  866. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  867. if err != nil {
  868. utils.ErrorLog(err.Error())
  869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  870. return
  871. }
  872. var subTemplate []*models.DoctorAdviceTemplate
  873. if dataBody["data"] != nil && reflect.TypeOf(dataBody["data"]).String() == "[]interface {}" {
  874. subTemp, _ := dataBody["data"].([]interface{})
  875. if len(subTemp) > 0 {
  876. for _, item := range subTemp {
  877. items := item.(map[string]interface{})
  878. if items["advice_name"] == nil || reflect.TypeOf(items["advice_name"]).String() != "string" {
  879. utils.ErrorLog("advice_name")
  880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  881. return
  882. }
  883. advice_name, _ := items["advice_name"].(string)
  884. advice_desc, _ := items["advice_desc"].(string)
  885. single_dose_unit, _ := items["single_dose_unit"].(string)
  886. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  887. delivery_way, _ := items["delivery_way"].(string)
  888. execution_frequency, _ := items["execution_frequency"].(string)
  889. drug_spec, _ := items["drug_spec"].(string)
  890. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  891. single_dose := items["single_dose"].(float64)
  892. prescribing_number := items["prescribing_number"].(float64)
  893. day_count, _ := strconv.ParseInt(items["day_count"].(string), 10, 64)
  894. weekdays := items["weekdays"].(string)
  895. frequency_type := int64(items["frequency_type"].(float64))
  896. drug_id := int64(items["drug_id"].(float64))
  897. way := int64(items["way"].(float64))
  898. subTemps := &models.DoctorAdviceTemplate{
  899. AdviceName: advice_name,
  900. Status: 1,
  901. CreatedTime: time.Now().Unix(),
  902. UpdatedTime: time.Now().Unix(),
  903. OrgId: adminUserInfo.CurrentOrgId,
  904. AdviceDesc: advice_desc,
  905. AdviceType: advice_type,
  906. SingleDoseUnit: single_dose_unit,
  907. PrescribingNumber: prescribing_number,
  908. PrescribingNumberUnit: prescribing_number_unit,
  909. DeliveryWay: delivery_way,
  910. ExecutionFrequency: execution_frequency,
  911. TemplateId: template.ID,
  912. DrugSpec: drug_spec,
  913. DrugSpecUnit: drug_spec_unit,
  914. SingleDose: single_dose,
  915. AdviceDoctor: adminUserInfo.AdminUser.Id,
  916. DayCount: day_count,
  917. WeekDays: weekdays,
  918. FrequencyType: frequency_type,
  919. Way: way,
  920. DrugId: drug_id,
  921. DrugNameId: 0,
  922. }
  923. subTemplate = append(subTemplate, subTemps)
  924. }
  925. }
  926. }
  927. //errs := service.CreateBatchRecord(subTemplate)
  928. errs := service.CreateSubTemplate(subTemplate)
  929. if errs != nil {
  930. utils.ErrorLog(errs.Error())
  931. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  932. return
  933. }
  934. templates, _ := service.FindDoctorAdviceTemplateById(template.ID, adminUserInfo.CurrentOrgId)
  935. c.ServeSuccessJSON(map[string]interface{}{
  936. "template": templates,
  937. })
  938. return
  939. }
  940. func (c *DataApiController) UpdateAdviceTemplate() {
  941. adminUserInfo := c.GetAdminUserInfo()
  942. id, _ := c.GetInt64("id", 0)
  943. if id <= 0 {
  944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  945. return
  946. }
  947. template, _ := service.FindAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  948. if template == nil {
  949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  950. return
  951. }
  952. //TODO 根据路由来做权限
  953. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  954. //if appRole.UserType == 3 {
  955. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  956. // if getPermissionErr != nil {
  957. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  958. // return
  959. // } else if headNursePermission == nil {
  960. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  961. // return
  962. // }
  963. //}
  964. var templatedata models.DoctorAdviceTemplate
  965. err := json.Unmarshal(c.Ctx.Input.RequestBody, &templatedata)
  966. if err != nil {
  967. utils.ErrorLog("%v", err)
  968. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  969. return
  970. }
  971. if templatedata.AdviceName == "" {
  972. utils.ErrorLog("不能为空")
  973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  974. return
  975. }
  976. timeNow := time.Now().Unix()
  977. template.UpdatedTime = timeNow
  978. template.AdviceName = templatedata.AdviceName
  979. template.AdviceDesc = templatedata.AdviceDesc
  980. template.SingleDose = templatedata.SingleDose
  981. template.SingleDoseUnit = templatedata.SingleDoseUnit
  982. template.PrescribingNumber = templatedata.PrescribingNumber
  983. template.PrescribingNumberUnit = templatedata.PrescribingNumberUnit
  984. template.DrugSpec = templatedata.DrugSpec
  985. template.DrugSpecUnit = templatedata.DrugSpecUnit
  986. template.DeliveryWay = templatedata.DeliveryWay
  987. template.ExecutionFrequency = templatedata.ExecutionFrequency
  988. template.FrequencyType = templatedata.FrequencyType
  989. template.DayCount = templatedata.DayCount
  990. template.WeekDays = templatedata.WeekDays
  991. template.DrugId = template.DrugId
  992. template.Way = template.Way
  993. err = service.UpdateAdviceTemplate(template)
  994. if err != nil {
  995. utils.ErrorLog("%v", err)
  996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  997. return
  998. }
  999. c.ServeSuccessJSON(map[string]interface{}{
  1000. "template": template,
  1001. })
  1002. return
  1003. }
  1004. func (c *DataApiController) DeleteAdviceTemplate() {
  1005. adminUserInfo := c.GetAdminUserInfo()
  1006. parent_id, _ := c.GetInt64("parent_id", 0)
  1007. id, _ := c.GetInt64("id", 0)
  1008. if id <= 0 {
  1009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1010. return
  1011. }
  1012. template, _ := service.FindAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  1013. if template == nil {
  1014. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  1015. return
  1016. }
  1017. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1018. //if appRole.UserType == 3 {
  1019. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1020. // if getPermissionErr != nil {
  1021. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1022. // return
  1023. // } else if headNursePermission == nil {
  1024. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1025. // return
  1026. // }
  1027. //}
  1028. timeNow := time.Now().Unix()
  1029. template.ID = id
  1030. template.UpdatedTime = timeNow
  1031. template.ParentId = parent_id
  1032. template.Status = 2
  1033. if parent_id > 0 { //删除子医嘱
  1034. err := service.UpdateAdviceTemplate(template)
  1035. if err != nil {
  1036. utils.ErrorLog("%v", err)
  1037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1038. return
  1039. }
  1040. } else { //删除该医嘱下的所有子医嘱
  1041. err := service.UpdateAdviceAndSubAdviceTemplate(template)
  1042. if err != nil {
  1043. utils.ErrorLog("%v", err)
  1044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1045. return
  1046. }
  1047. }
  1048. c.ServeSuccessJSON(map[string]interface{}{
  1049. "msg": "ok",
  1050. })
  1051. return
  1052. }
  1053. func (c *DataApiController) CreateSingleAdviceTemplate() {
  1054. drug_spec := c.GetString("drug_spec")
  1055. drug_spec_unit := c.GetString("drug_spec_unit")
  1056. advice_name := c.GetString("advice_name")
  1057. advice_desc := c.GetString("advice_desc")
  1058. single_dose, _ := c.GetFloat("single_dose", 0)
  1059. single_dose_unit := c.GetString("single_dose_unit")
  1060. prescribing_number, _ := c.GetFloat("prescribing_number", 0)
  1061. prescribing_number_unit := c.GetString("prescribing_number_unit")
  1062. delivery_way := c.GetString("delivery_way")
  1063. execution_frequency := c.GetString("execution_frequency")
  1064. template_id, _ := c.GetInt64("template_id", -1)
  1065. advice_type, _ := c.GetInt64("advice_type", -1)
  1066. frequency_type, _ := c.GetInt64("frequency_type", -1)
  1067. week_days := c.GetString("week_days")
  1068. day_count, _ := c.GetInt64("day_count", -1)
  1069. drug_id, _ := c.GetInt64("drug_id")
  1070. way, _ := c.GetInt64("way")
  1071. adminUserInfo := c.GetAdminUserInfo()
  1072. template := models.DoctorAdviceTemplate{
  1073. OrgId: adminUserInfo.CurrentOrgId,
  1074. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1075. AdviceType: advice_type,
  1076. FrequencyType: frequency_type,
  1077. WeekDays: week_days,
  1078. DayCount: day_count,
  1079. Status: 1,
  1080. CreatedTime: time.Now().Unix(),
  1081. UpdatedTime: time.Now().Unix(),
  1082. DrugSpec: drug_spec,
  1083. DrugSpecUnit: drug_spec_unit,
  1084. AdviceName: advice_name,
  1085. AdviceDesc: advice_desc,
  1086. SingleDose: single_dose,
  1087. SingleDoseUnit: service.TypeConversion02(single_dose_unit),
  1088. PrescribingNumber: prescribing_number,
  1089. PrescribingNumberUnit: prescribing_number_unit,
  1090. DeliveryWay: delivery_way,
  1091. ExecutionFrequency: execution_frequency,
  1092. TemplateId: template_id,
  1093. Way: way,
  1094. DrugId: drug_id,
  1095. }
  1096. if template.AdviceName == "" {
  1097. utils.ErrorLog("医嘱名字不能为空")
  1098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
  1099. return
  1100. }
  1101. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1102. if appRole.UserType == 3 {
  1103. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1104. if getPermissionErr != nil {
  1105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1106. return
  1107. } else if headNursePermission == nil {
  1108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1109. return
  1110. }
  1111. }
  1112. err := service.CreateAdviceTemplate(&template)
  1113. if err != nil {
  1114. utils.ErrorLog("%v", err)
  1115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1116. return
  1117. }
  1118. c.ServeSuccessJSON(map[string]interface{}{
  1119. "template": template,
  1120. })
  1121. return
  1122. }
  1123. func (c *DataApiController) DeleteParentAdviceTemplate() {
  1124. template_id, _ := c.GetInt64("template_id", 0)
  1125. adminUserInfo := c.GetAdminUserInfo()
  1126. _, err := service.FindParentTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1127. if err != nil {
  1128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1129. return
  1130. }
  1131. err1 := service.DeleteParentDoctorAdviceByTemplateId(template_id, adminUserInfo.CurrentOrgId)
  1132. if err1 != nil {
  1133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1134. return
  1135. }
  1136. c.ServeSuccessJSON(map[string]interface{}{
  1137. "msg": "删除成功",
  1138. })
  1139. }
  1140. func (c *DataApiController) CreateSubAdviceTemplate() {
  1141. drug_spec := c.GetString("drug_spec")
  1142. drug_spec_unit := c.GetString("drug_spec_unit")
  1143. advice_name := c.GetString("advice_name")
  1144. advice_desc := c.GetString("advice_desc")
  1145. single_dose, _ := c.GetFloat("single_dose", 0)
  1146. single_dose_unit := c.GetString("single_dose_unit")
  1147. prescribing_number, _ := c.GetFloat("prescribing_number", 0)
  1148. prescribing_number_unit := c.GetString("prescribing_number_unit")
  1149. delivery_way := c.GetString("delivery_way")
  1150. execution_frequency := c.GetString("execution_frequency")
  1151. template_id, _ := c.GetInt64("template_id", 0)
  1152. parent_id, _ := c.GetInt64("parent_id", 0)
  1153. drug_id, _ := c.GetInt64("drug_id")
  1154. way, _ := c.GetInt64("way")
  1155. adminUserInfo := c.GetAdminUserInfo()
  1156. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1157. if appRole.UserType == 3 {
  1158. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1159. if getPermissionErr != nil {
  1160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1161. return
  1162. } else if headNursePermission == nil {
  1163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1164. return
  1165. }
  1166. }
  1167. template := models.DoctorAdviceTemplate{
  1168. OrgId: adminUserInfo.CurrentOrgId,
  1169. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1170. Status: 1,
  1171. CreatedTime: time.Now().Unix(),
  1172. UpdatedTime: time.Now().Unix(),
  1173. DrugSpec: drug_spec,
  1174. DrugSpecUnit: drug_spec_unit,
  1175. AdviceName: advice_name,
  1176. AdviceDesc: advice_desc,
  1177. SingleDose: single_dose,
  1178. SingleDoseUnit: single_dose_unit,
  1179. PrescribingNumber: prescribing_number,
  1180. PrescribingNumberUnit: prescribing_number_unit,
  1181. DeliveryWay: delivery_way,
  1182. ExecutionFrequency: execution_frequency,
  1183. TemplateId: template_id,
  1184. ParentId: parent_id,
  1185. DrugId: drug_id,
  1186. Way: way,
  1187. }
  1188. if template.AdviceName == "" {
  1189. utils.ErrorLog("医嘱名字不能为空")
  1190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
  1191. return
  1192. }
  1193. err := service.CreateAdviceTemplate(&template)
  1194. if err != nil {
  1195. utils.ErrorLog("%v", err)
  1196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1197. return
  1198. }
  1199. c.ServeSuccessJSON(map[string]interface{}{
  1200. "template": template,
  1201. })
  1202. return
  1203. }
  1204. func (this *DataApiController) ModifyTemplateName() {
  1205. template_name := this.GetString("template_name")
  1206. template_id, _ := this.GetInt64("template_id", 0)
  1207. sort, _ := this.GetInt64("sort")
  1208. if len(template_name) <= 0 {
  1209. utils.ErrorLog("模版名字不能为空")
  1210. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  1211. return
  1212. }
  1213. if template_id == 0 {
  1214. utils.ErrorLog("模版不存在")
  1215. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamTemplateNOEXISTWrong)
  1216. return
  1217. }
  1218. adminUserInfo := this.GetAdminUserInfo()
  1219. template, _ := service.FindParentTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1220. var err error
  1221. if template.Name == template_name {
  1222. err = service.ModifyTemplateNameOne(template_id, template_name, sort)
  1223. if err != nil {
  1224. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1225. return
  1226. }
  1227. } else {
  1228. //total := service.FindTemplateRecordByName(adminUserInfo.CurrentOrgId, template_name);
  1229. //if total > 0 {
  1230. // utils.ErrorLog("模版名称已经存在")
  1231. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNameWrong)
  1232. // return
  1233. //}
  1234. err = service.ModifyTemplateNameOne(template_id, template_name, sort)
  1235. if err != nil {
  1236. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1237. return
  1238. }
  1239. }
  1240. this.ServeSuccessJSON(map[string]interface{}{
  1241. "template_name": template_name,
  1242. "template_id": template_id,
  1243. })
  1244. }
  1245. func (this *DataApiController) ModifyFiledIsShow() {
  1246. id, _ := this.GetInt64("id", 0)
  1247. is_show, _ := this.GetInt("is_show", 0)
  1248. adminUserInfo := this.GetAdminUserInfo()
  1249. err := service.ShowFiledConfig(adminUserInfo.CurrentOrgId, is_show, id)
  1250. if err != nil {
  1251. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1252. return
  1253. } else {
  1254. this.ServeSuccessJSON(map[string]interface{}{
  1255. "id": id,
  1256. "is_show": is_show,
  1257. })
  1258. }
  1259. }
  1260. func (c *DataApiController) GetAllAdviceConfigs() {
  1261. adminUserInfo := c.GetAdminUserInfo()
  1262. var drugs []models.DrugDic
  1263. drugways, _, _ := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  1264. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  1265. adviceTemplates, _ := service.FindOtherAllAdviceTemplate(adminUserInfo.CurrentOrgId)
  1266. c.ServeSuccessJSON(map[string]interface{}{
  1267. "drugs": drugs,
  1268. "drugways": drugways,
  1269. "efs": efs,
  1270. "advice_templates": adviceTemplates,
  1271. })
  1272. }
  1273. func (c *DataApiController) GetHandleData() {
  1274. id, _ := c.GetInt64("id")
  1275. config, err := service.GetHandleData(id)
  1276. if err != nil {
  1277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1278. return
  1279. }
  1280. c.ServeSuccessJSON(map[string]interface{}{
  1281. "config": config,
  1282. })
  1283. }
  1284. func (c *DataApiController) UpdateDataTwo() {
  1285. id, _ := c.GetInt64("id")
  1286. //fmt.Print("id",id)
  1287. dataBody := make(map[string]interface{}, 0)
  1288. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1289. //fmt.Print("err",err)
  1290. //fmt.Print("id",id)
  1291. name := dataBody["name"].(string)
  1292. // fmt.Print("name",name)
  1293. order := int64(dataBody["order"].(float64))
  1294. // fmt.Print("order",order)
  1295. remake := dataBody["remark"].(string)
  1296. // fmt.Print("remake",remake)
  1297. configModel := models.ConfigViewModel{
  1298. Name: name,
  1299. Order: order,
  1300. Remark: remake,
  1301. }
  1302. err = service.UpdateDataTwo(id, configModel)
  1303. if err != nil {
  1304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1305. return
  1306. }
  1307. c.ServeSuccessJSON(map[string]interface{}{
  1308. "configModel": configModel,
  1309. })
  1310. }
  1311. func (c *DataApiController) CreateHisAdviceTemplate() {
  1312. templateName := c.GetString("template_name")
  1313. advice_type, _ := c.GetInt64("advice_type")
  1314. if templateName == "" {
  1315. utils.ErrorLog("模版名称不能为空")
  1316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  1317. return
  1318. }
  1319. if advice_type < 0 {
  1320. utils.ErrorLog("医嘱模版类型不能为空")
  1321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceTypeWrong)
  1322. return
  1323. }
  1324. adminUserInfo := c.GetAdminUserInfo()
  1325. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1326. if appRole.UserType == 3 {
  1327. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1328. if getPermissionErr != nil {
  1329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1330. return
  1331. } else if headNursePermission == nil {
  1332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1333. return
  1334. }
  1335. }
  1336. template := &models.HisDoctorAdviceParentTemplate{
  1337. Name: templateName,
  1338. OrgId: adminUserInfo.CurrentOrgId,
  1339. Status: 1,
  1340. CreatedTime: time.Now().Unix(),
  1341. UpdatedTime: time.Now().Unix(),
  1342. AdviceType: advice_type,
  1343. }
  1344. createErr := service.CreateHisDoctorAdviceTemplate(template)
  1345. if createErr != nil {
  1346. utils.ErrorLog("%v", createErr)
  1347. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1348. return
  1349. }
  1350. dataBody := make(map[string]interface{}, 0)
  1351. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1352. if err != nil {
  1353. utils.ErrorLog(err.Error())
  1354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1355. return
  1356. }
  1357. var subTemplate []*models.HisDoctorAdviceTemplate
  1358. if dataBody["data"] != nil && reflect.TypeOf(dataBody["data"]).String() == "[]interface {}" {
  1359. subTemp, _ := dataBody["data"].([]interface{})
  1360. if len(subTemp) > 0 {
  1361. for _, item := range subTemp {
  1362. items := item.(map[string]interface{})
  1363. if items["advice_name"] == nil || reflect.TypeOf(items["advice_name"]).String() != "string" {
  1364. utils.ErrorLog("advice_name")
  1365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1366. return
  1367. }
  1368. advice_name, _ := items["advice_name"].(string)
  1369. advice_desc, _ := items["advice_desc"].(string)
  1370. single_dose_unit, _ := items["single_dose_unit"].(string)
  1371. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  1372. delivery_way, _ := items["delivery_way"].(string)
  1373. execution_frequency, _ := items["execution_frequency"].(string)
  1374. drug_spec, _ := items["drug_spec"].(string)
  1375. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  1376. single_dose := items["single_dose"].(float64)
  1377. prescribing_number := items["prescribing_number"].(float64)
  1378. drug_id := int64(items["drug_id"].(float64))
  1379. subTemps := &models.HisDoctorAdviceTemplate{
  1380. AdviceName: advice_name,
  1381. Status: 1,
  1382. CreatedTime: time.Now().Unix(),
  1383. UpdatedTime: time.Now().Unix(),
  1384. OrgId: adminUserInfo.CurrentOrgId,
  1385. AdviceDesc: advice_desc,
  1386. AdviceType: advice_type,
  1387. SingleDoseUnit: single_dose_unit,
  1388. PrescribingNumber: prescribing_number,
  1389. PrescribingNumberUnit: prescribing_number_unit,
  1390. DeliveryWay: delivery_way,
  1391. ExecutionFrequency: execution_frequency,
  1392. TemplateId: template.ID,
  1393. DrugSpec: drug_spec,
  1394. DrugSpecUnit: drug_spec_unit,
  1395. SingleDose: single_dose,
  1396. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1397. DrugId: drug_id,
  1398. }
  1399. subTemplate = append(subTemplate, subTemps)
  1400. }
  1401. }
  1402. }
  1403. //errs := service.CreateBatchRecord(subTemplate)
  1404. errs := service.CreateHisSubDoctorAdviceTemplate(subTemplate)
  1405. if errs != nil {
  1406. utils.ErrorLog(errs.Error())
  1407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1408. return
  1409. }
  1410. templates, _ := service.FindHisDoctorAdviceTemplateById(template.ID, adminUserInfo.CurrentOrgId)
  1411. c.ServeSuccessJSON(map[string]interface{}{
  1412. "template": templates,
  1413. })
  1414. return
  1415. }
  1416. func (c *DataApiController) UpdateHisAdviceTemplate() {
  1417. adminUserInfo := c.GetAdminUserInfo()
  1418. id, _ := c.GetInt64("id", 0)
  1419. if id <= 0 {
  1420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1421. return
  1422. }
  1423. template, _ := service.FindHisAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  1424. if template == nil {
  1425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  1426. return
  1427. }
  1428. var templatedata models.HisDoctorAdviceTemplate
  1429. err := json.Unmarshal(c.Ctx.Input.RequestBody, &templatedata)
  1430. if err != nil {
  1431. utils.ErrorLog("%v", err)
  1432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1433. return
  1434. }
  1435. if templatedata.AdviceName == "" {
  1436. utils.ErrorLog("不能为空")
  1437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1438. return
  1439. }
  1440. timeNow := time.Now().Unix()
  1441. template.UpdatedTime = timeNow
  1442. template.AdviceName = templatedata.AdviceName
  1443. template.AdviceDesc = templatedata.AdviceDesc
  1444. template.SingleDose = templatedata.SingleDose
  1445. template.SingleDoseUnit = templatedata.SingleDoseUnit
  1446. template.PrescribingNumber = templatedata.PrescribingNumber
  1447. template.PrescribingNumberUnit = templatedata.PrescribingNumberUnit
  1448. template.DrugSpec = templatedata.DrugSpec
  1449. template.DrugSpecUnit = templatedata.DrugSpecUnit
  1450. template.DeliveryWay = templatedata.DeliveryWay
  1451. template.ExecutionFrequency = templatedata.ExecutionFrequency
  1452. template.DrugId = template.DrugId
  1453. err = service.UpdateHisAdviceTemplate(template)
  1454. if err != nil {
  1455. utils.ErrorLog("%v", err)
  1456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1457. return
  1458. }
  1459. c.ServeSuccessJSON(map[string]interface{}{
  1460. "template": template,
  1461. })
  1462. return
  1463. }
  1464. func (c *DataApiController) DeleteHisAdviceTemplate() {
  1465. adminUserInfo := c.GetAdminUserInfo()
  1466. parent_id, _ := c.GetInt64("parent_id", 0)
  1467. id, _ := c.GetInt64("id", 0)
  1468. if id <= 0 {
  1469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1470. return
  1471. }
  1472. template, _ := service.FindHisAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  1473. if template == nil {
  1474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  1475. return
  1476. }
  1477. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1478. //if appRole.UserType == 3 {
  1479. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1480. // if getPermissionErr != nil {
  1481. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1482. // return
  1483. // } else if headNursePermission == nil {
  1484. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1485. // return
  1486. // }
  1487. //}
  1488. timeNow := time.Now().Unix()
  1489. template.ID = id
  1490. template.UpdatedTime = timeNow
  1491. template.ParentId = parent_id
  1492. template.Status = 2
  1493. if parent_id > 0 { //删除子医嘱
  1494. err := service.UpdateHisAdviceTemplate(template)
  1495. if err != nil {
  1496. utils.ErrorLog("%v", err)
  1497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1498. return
  1499. }
  1500. } else { //删除该医嘱下的所有子医嘱
  1501. err := service.UpdateHisAdviceAndSubAdviceTemplate(template)
  1502. if err != nil {
  1503. utils.ErrorLog("%v", err)
  1504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1505. return
  1506. }
  1507. }
  1508. c.ServeSuccessJSON(map[string]interface{}{
  1509. "msg": "ok",
  1510. })
  1511. return
  1512. }
  1513. func (c *DataApiController) CreateSingleHisAdviceTemplate() {
  1514. drug_spec := c.GetString("drug_spec")
  1515. drug_spec_unit := c.GetString("drug_spec_unit")
  1516. advice_name := c.GetString("advice_name")
  1517. advice_desc := c.GetString("advice_desc")
  1518. single_dose, _ := c.GetFloat("single_dose", 0)
  1519. single_dose_unit := c.GetString("single_dose_unit")
  1520. prescribing_number, _ := c.GetFloat("prescribing_number", 0)
  1521. prescribing_number_unit := c.GetString("prescribing_number_unit")
  1522. delivery_way := c.GetString("delivery_way")
  1523. execution_frequency := c.GetString("execution_frequency")
  1524. template_id, _ := c.GetInt64("template_id", -1)
  1525. drug_id, _ := c.GetInt64("drug_id")
  1526. adminUserInfo := c.GetAdminUserInfo()
  1527. template := models.HisDoctorAdviceTemplate{
  1528. OrgId: adminUserInfo.CurrentOrgId,
  1529. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1530. Status: 1,
  1531. CreatedTime: time.Now().Unix(),
  1532. UpdatedTime: time.Now().Unix(),
  1533. DrugSpec: drug_spec,
  1534. DrugSpecUnit: drug_spec_unit,
  1535. AdviceName: advice_name,
  1536. AdviceDesc: advice_desc,
  1537. SingleDose: single_dose,
  1538. SingleDoseUnit: single_dose_unit,
  1539. PrescribingNumber: prescribing_number,
  1540. PrescribingNumberUnit: prescribing_number_unit,
  1541. DeliveryWay: delivery_way,
  1542. ExecutionFrequency: execution_frequency,
  1543. TemplateId: template_id,
  1544. DrugId: drug_id,
  1545. }
  1546. if template.AdviceName == "" {
  1547. utils.ErrorLog("医嘱名字不能为空")
  1548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
  1549. return
  1550. }
  1551. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1552. if appRole.UserType == 3 {
  1553. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1554. if getPermissionErr != nil {
  1555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1556. return
  1557. } else if headNursePermission == nil {
  1558. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1559. return
  1560. }
  1561. }
  1562. err := service.CreateHisAdviceTemplate(&template)
  1563. if err != nil {
  1564. utils.ErrorLog("%v", err)
  1565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1566. return
  1567. }
  1568. c.ServeSuccessJSON(map[string]interface{}{
  1569. "template": template,
  1570. })
  1571. return
  1572. }
  1573. func (c *DataApiController) DeleteHisParentAdviceTemplate() {
  1574. template_id, _ := c.GetInt64("template_id", 0)
  1575. adminUserInfo := c.GetAdminUserInfo()
  1576. _, err := service.FindParentHisTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1577. if err != nil {
  1578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1579. return
  1580. }
  1581. err1 := service.DeleteHisParentDoctorAdviceByTemplateId(template_id, adminUserInfo.CurrentOrgId)
  1582. if err1 != nil {
  1583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1584. return
  1585. }
  1586. c.ServeSuccessJSON(map[string]interface{}{
  1587. "msg": "删除成功",
  1588. })
  1589. }
  1590. func (this *DataApiController) ModifyHisTemplateName() {
  1591. template_name := this.GetString("template_name")
  1592. template_id, _ := this.GetInt64("template_id", 0)
  1593. if len(template_name) <= 0 {
  1594. utils.ErrorLog("模版名字不能为空")
  1595. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  1596. return
  1597. }
  1598. if template_id == 0 {
  1599. utils.ErrorLog("模版不存在")
  1600. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamTemplateNOEXISTWrong)
  1601. return
  1602. }
  1603. adminUserInfo := this.GetAdminUserInfo()
  1604. template, _ := service.FindParentHisTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1605. var err error
  1606. if template.Name == template_name {
  1607. err = service.ModifyTemplateName(template_id, template_name)
  1608. if err != nil {
  1609. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1610. return
  1611. }
  1612. } else {
  1613. err = service.ModifyHisTemplateName(template_id, template_name)
  1614. if err != nil {
  1615. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1616. return
  1617. }
  1618. }
  1619. this.ServeSuccessJSON(map[string]interface{}{
  1620. "template_name": template_name,
  1621. "template_id": template_id,
  1622. })
  1623. }
  1624. func (this *DataApiController) GetAllHisAdviceTemplate() {
  1625. adminUserInfo := this.GetAdminUserInfo()
  1626. drugs, _ := service.GetAllDrugLibs(adminUserInfo.CurrentOrgId)
  1627. drugways, _, _ := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  1628. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  1629. adviceTemplates, _ := service.FindHisAllAdviceTemplate(adminUserInfo.CurrentOrgId)
  1630. this.ServeSuccessJSON(map[string]interface{}{
  1631. "drugways": drugways,
  1632. "efs": efs,
  1633. "advice_templates": adviceTemplates,
  1634. "drugs": drugs,
  1635. })
  1636. }