data_api_controller.go 58KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834
  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" || module == "dialysis_remark" || module == "catheter_operation" || module == "main_content" || module == "patient_case" || module == "tentative_diagnosis" || module == "diagnostic_basis" || module == "differential_diagnosis" || module == "treatment_plan" || module == "sick_history" || module == "befor_symptoms" {
  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 = 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.Code = drugwaydata.Code
  671. drugway.Name = drugwaydata.Name
  672. err = service.UpdateDrugWay(drugway)
  673. if err != nil {
  674. utils.ErrorLog("%v", err)
  675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  676. return
  677. }
  678. drugways_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_drugways"
  679. redis := service.RedisClient()
  680. defer redis.Close()
  681. redis.Set(drugways_keys, "", time.Second*60*60*18)
  682. c.ServeSuccessJSON(map[string]interface{}{
  683. "drugway": drugway,
  684. })
  685. return
  686. }
  687. func (c *DataApiController) DeleteDrugWay() {
  688. adminUserInfo := c.GetAdminUserInfo()
  689. id, _ := c.GetInt64("id", 0)
  690. if id <= 0 {
  691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  692. return
  693. }
  694. drugway, _ := service.FindDrugWay(adminUserInfo.CurrentOrgId, id)
  695. if drugway == nil {
  696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  697. return
  698. }
  699. timeNow := time.Now().Unix()
  700. drugway.UpdatedTime = timeNow
  701. drugway.Status = 2
  702. err := service.UpdateDrugWay(drugway)
  703. if err != nil {
  704. utils.ErrorLog("%v", err)
  705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  706. return
  707. }
  708. drugways_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_drugways"
  709. redis := service.RedisClient()
  710. defer redis.Close()
  711. redis.Set(drugways_keys, "", time.Second*60*60*18)
  712. c.ServeSuccessJSON(map[string]interface{}{
  713. "msg": "ok",
  714. })
  715. return
  716. }
  717. func (c *DataApiController) CreateExecutionFrequency() {
  718. adminUserInfo := c.GetAdminUserInfo()
  719. var ef models.ExecutionFrequencyDic
  720. err := json.Unmarshal(c.Ctx.Input.RequestBody, &ef)
  721. if err != nil {
  722. utils.ErrorLog("%v", err)
  723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  724. return
  725. }
  726. if ef.Name == "" {
  727. utils.ErrorLog("执行频率不能为空")
  728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  729. return
  730. }
  731. timeNow := time.Now().Unix()
  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. ef.Code = efdata.Code
  780. err = service.UpdateExecutionFrequency(ef)
  781. if err != nil {
  782. utils.ErrorLog("%v", err)
  783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  784. return
  785. }
  786. efs_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_efs"
  787. redis := service.RedisClient()
  788. defer redis.Close()
  789. redis.Set(efs_keys, "", time.Second*60*60*18)
  790. c.ServeSuccessJSON(map[string]interface{}{
  791. "ef": ef,
  792. })
  793. return
  794. }
  795. func (c *DataApiController) DeleteExecutionFrequency() {
  796. adminUserInfo := c.GetAdminUserInfo()
  797. id, _ := c.GetInt64("id", 0)
  798. if id <= 0 {
  799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  800. return
  801. }
  802. ef, _ := service.FindExecutionFrequency(adminUserInfo.CurrentOrgId, id)
  803. if ef == nil {
  804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  805. return
  806. }
  807. timeNow := time.Now().Unix()
  808. ef.UpdatedTime = timeNow
  809. ef.Status = 2
  810. err := service.UpdateExecutionFrequency(ef)
  811. if err != nil {
  812. utils.ErrorLog("%v", err)
  813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  814. return
  815. }
  816. efs_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_efs"
  817. redis := service.RedisClient()
  818. defer redis.Close()
  819. redis.Set(efs_keys, "", time.Second*60*60*18)
  820. c.ServeSuccessJSON(map[string]interface{}{
  821. "msg": "ok",
  822. })
  823. return
  824. }
  825. func (c *DataApiController) CreateAdviceTemplate() {
  826. templateName := c.GetString("template_name")
  827. advice_type, _ := c.GetInt64("advice_type")
  828. sort, _ := c.GetInt64("sort")
  829. if templateName == "" {
  830. utils.ErrorLog("模版名称不能为空")
  831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  832. return
  833. }
  834. if advice_type < 0 {
  835. utils.ErrorLog("医嘱模版类型不能为空")
  836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceTypeWrong)
  837. return
  838. }
  839. adminUserInfo := c.GetAdminUserInfo()
  840. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  841. if appRole.UserType == 3 {
  842. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  843. if getPermissionErr != nil {
  844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  845. return
  846. } else if headNursePermission == nil {
  847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  848. return
  849. }
  850. }
  851. template := &models.DoctorAdviceParentTemplate{
  852. Name: templateName,
  853. OrgId: adminUserInfo.CurrentOrgId,
  854. Status: 1,
  855. CreatedTime: time.Now().Unix(),
  856. UpdatedTime: time.Now().Unix(),
  857. AdviceType: advice_type,
  858. Sort: sort,
  859. }
  860. createErr := service.CreateTemplate(template)
  861. if createErr != nil {
  862. utils.ErrorLog("%v", createErr)
  863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  864. return
  865. }
  866. dataBody := make(map[string]interface{}, 0)
  867. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  868. if err != nil {
  869. utils.ErrorLog(err.Error())
  870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  871. return
  872. }
  873. var subTemplate []*models.DoctorAdviceTemplate
  874. if dataBody["data"] != nil && reflect.TypeOf(dataBody["data"]).String() == "[]interface {}" {
  875. subTemp, _ := dataBody["data"].([]interface{})
  876. if len(subTemp) > 0 {
  877. for _, item := range subTemp {
  878. items := item.(map[string]interface{})
  879. if items["advice_name"] == nil || reflect.TypeOf(items["advice_name"]).String() != "string" {
  880. utils.ErrorLog("advice_name")
  881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  882. return
  883. }
  884. advice_name, _ := items["advice_name"].(string)
  885. advice_desc, _ := items["advice_desc"].(string)
  886. single_dose_unit, _ := items["single_dose_unit"].(string)
  887. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  888. delivery_way, _ := items["delivery_way"].(string)
  889. execution_frequency, _ := items["execution_frequency"].(string)
  890. drug_spec, _ := items["drug_spec"].(string)
  891. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  892. single_dose := items["single_dose"].(float64)
  893. prescribing_number := items["prescribing_number"].(float64)
  894. day_count, _ := strconv.ParseInt(items["day_count"].(string), 10, 64)
  895. weekdays := items["weekdays"].(string)
  896. frequency_type := int64(items["frequency_type"].(float64))
  897. drug_id := int64(items["drug_id"].(float64))
  898. way := int64(items["way"].(float64))
  899. subTemps := &models.DoctorAdviceTemplate{
  900. AdviceName: advice_name,
  901. Status: 1,
  902. CreatedTime: time.Now().Unix(),
  903. UpdatedTime: time.Now().Unix(),
  904. OrgId: adminUserInfo.CurrentOrgId,
  905. AdviceDesc: advice_desc,
  906. AdviceType: advice_type,
  907. SingleDoseUnit: single_dose_unit,
  908. PrescribingNumber: prescribing_number,
  909. PrescribingNumberUnit: prescribing_number_unit,
  910. DeliveryWay: delivery_way,
  911. ExecutionFrequency: execution_frequency,
  912. TemplateId: template.ID,
  913. DrugSpec: drug_spec,
  914. DrugSpecUnit: drug_spec_unit,
  915. SingleDose: single_dose,
  916. AdviceDoctor: adminUserInfo.AdminUser.Id,
  917. DayCount: day_count,
  918. WeekDays: weekdays,
  919. FrequencyType: frequency_type,
  920. Way: way,
  921. DrugId: drug_id,
  922. DrugNameId: 0,
  923. }
  924. subTemplate = append(subTemplate, subTemps)
  925. }
  926. }
  927. }
  928. //errs := service.CreateBatchRecord(subTemplate)
  929. errs := service.CreateSubTemplate(subTemplate)
  930. if errs != nil {
  931. utils.ErrorLog(errs.Error())
  932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  933. return
  934. }
  935. templates, _ := service.FindDoctorAdviceTemplateById(template.ID, adminUserInfo.CurrentOrgId)
  936. c.ServeSuccessJSON(map[string]interface{}{
  937. "template": templates,
  938. })
  939. return
  940. }
  941. func (c *DataApiController) UpdateAdviceTemplate() {
  942. adminUserInfo := c.GetAdminUserInfo()
  943. id, _ := c.GetInt64("id", 0)
  944. if id <= 0 {
  945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  946. return
  947. }
  948. template, _ := service.FindAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  949. if template == nil {
  950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  951. return
  952. }
  953. //TODO 根据路由来做权限
  954. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  955. //if appRole.UserType == 3 {
  956. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  957. // if getPermissionErr != nil {
  958. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  959. // return
  960. // } else if headNursePermission == nil {
  961. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  962. // return
  963. // }
  964. //}
  965. var templatedata models.DoctorAdviceTemplate
  966. err := json.Unmarshal(c.Ctx.Input.RequestBody, &templatedata)
  967. if err != nil {
  968. utils.ErrorLog("%v", err)
  969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  970. return
  971. }
  972. if templatedata.AdviceName == "" {
  973. utils.ErrorLog("不能为空")
  974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  975. return
  976. }
  977. timeNow := time.Now().Unix()
  978. template.UpdatedTime = timeNow
  979. template.AdviceName = templatedata.AdviceName
  980. template.AdviceDesc = templatedata.AdviceDesc
  981. template.SingleDose = templatedata.SingleDose
  982. template.SingleDoseUnit = templatedata.SingleDoseUnit
  983. template.PrescribingNumber = templatedata.PrescribingNumber
  984. template.PrescribingNumberUnit = templatedata.PrescribingNumberUnit
  985. template.DrugSpec = templatedata.DrugSpec
  986. template.DrugSpecUnit = templatedata.DrugSpecUnit
  987. template.DeliveryWay = templatedata.DeliveryWay
  988. template.ExecutionFrequency = templatedata.ExecutionFrequency
  989. template.FrequencyType = templatedata.FrequencyType
  990. template.DayCount = templatedata.DayCount
  991. template.WeekDays = templatedata.WeekDays
  992. template.DrugId = template.DrugId
  993. template.Way = template.Way
  994. err = service.UpdateAdviceTemplate(template)
  995. if err != nil {
  996. utils.ErrorLog("%v", err)
  997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  998. return
  999. }
  1000. c.ServeSuccessJSON(map[string]interface{}{
  1001. "template": template,
  1002. })
  1003. return
  1004. }
  1005. func (c *DataApiController) DeleteAdviceTemplate() {
  1006. adminUserInfo := c.GetAdminUserInfo()
  1007. parent_id, _ := c.GetInt64("parent_id", 0)
  1008. id, _ := c.GetInt64("id", 0)
  1009. if id <= 0 {
  1010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1011. return
  1012. }
  1013. template, _ := service.FindAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  1014. if template == nil {
  1015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  1016. return
  1017. }
  1018. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1019. //if appRole.UserType == 3 {
  1020. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1021. // if getPermissionErr != nil {
  1022. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1023. // return
  1024. // } else if headNursePermission == nil {
  1025. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1026. // return
  1027. // }
  1028. //}
  1029. timeNow := time.Now().Unix()
  1030. template.ID = id
  1031. template.UpdatedTime = timeNow
  1032. template.ParentId = parent_id
  1033. template.Status = 2
  1034. if parent_id > 0 { //删除子医嘱
  1035. err := service.UpdateAdviceTemplate(template)
  1036. if err != nil {
  1037. utils.ErrorLog("%v", err)
  1038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1039. return
  1040. }
  1041. } else { //删除该医嘱下的所有子医嘱
  1042. err := service.UpdateAdviceAndSubAdviceTemplate(template)
  1043. if err != nil {
  1044. utils.ErrorLog("%v", err)
  1045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1046. return
  1047. }
  1048. }
  1049. c.ServeSuccessJSON(map[string]interface{}{
  1050. "msg": "ok",
  1051. })
  1052. return
  1053. }
  1054. func (c *DataApiController) CreateSingleAdviceTemplate() {
  1055. drug_spec := c.GetString("drug_spec")
  1056. drug_spec_unit := c.GetString("drug_spec_unit")
  1057. advice_name := c.GetString("advice_name")
  1058. advice_desc := c.GetString("advice_desc")
  1059. single_dose, _ := c.GetFloat("single_dose", 0)
  1060. single_dose_unit := c.GetString("single_dose_unit")
  1061. prescribing_number, _ := c.GetFloat("prescribing_number", 0)
  1062. prescribing_number_unit := c.GetString("prescribing_number_unit")
  1063. delivery_way := c.GetString("delivery_way")
  1064. execution_frequency := c.GetString("execution_frequency")
  1065. template_id, _ := c.GetInt64("template_id", -1)
  1066. advice_type, _ := c.GetInt64("advice_type", -1)
  1067. frequency_type, _ := c.GetInt64("frequency_type", -1)
  1068. week_days := c.GetString("week_days")
  1069. day_count, _ := c.GetInt64("day_count", -1)
  1070. drug_id, _ := c.GetInt64("drug_id")
  1071. way, _ := c.GetInt64("way")
  1072. adminUserInfo := c.GetAdminUserInfo()
  1073. template := models.DoctorAdviceTemplate{
  1074. OrgId: adminUserInfo.CurrentOrgId,
  1075. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1076. AdviceType: advice_type,
  1077. FrequencyType: frequency_type,
  1078. WeekDays: week_days,
  1079. DayCount: day_count,
  1080. Status: 1,
  1081. CreatedTime: time.Now().Unix(),
  1082. UpdatedTime: time.Now().Unix(),
  1083. DrugSpec: drug_spec,
  1084. DrugSpecUnit: drug_spec_unit,
  1085. AdviceName: advice_name,
  1086. AdviceDesc: advice_desc,
  1087. SingleDose: single_dose,
  1088. SingleDoseUnit: service.TypeConversion02(single_dose_unit),
  1089. PrescribingNumber: prescribing_number,
  1090. PrescribingNumberUnit: prescribing_number_unit,
  1091. DeliveryWay: delivery_way,
  1092. ExecutionFrequency: execution_frequency,
  1093. TemplateId: template_id,
  1094. Way: way,
  1095. DrugId: drug_id,
  1096. }
  1097. if template.AdviceName == "" {
  1098. utils.ErrorLog("医嘱名字不能为空")
  1099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
  1100. return
  1101. }
  1102. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1103. if appRole.UserType == 3 {
  1104. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1105. if getPermissionErr != nil {
  1106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1107. return
  1108. } else if headNursePermission == nil {
  1109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1110. return
  1111. }
  1112. }
  1113. err := service.CreateAdviceTemplate(&template)
  1114. if err != nil {
  1115. utils.ErrorLog("%v", err)
  1116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1117. return
  1118. }
  1119. c.ServeSuccessJSON(map[string]interface{}{
  1120. "template": template,
  1121. })
  1122. return
  1123. }
  1124. func (c *DataApiController) DeleteParentAdviceTemplate() {
  1125. template_id, _ := c.GetInt64("template_id", 0)
  1126. adminUserInfo := c.GetAdminUserInfo()
  1127. _, err := service.FindParentTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1128. if err != nil {
  1129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1130. return
  1131. }
  1132. err1 := service.DeleteParentDoctorAdviceByTemplateId(template_id, adminUserInfo.CurrentOrgId)
  1133. if err1 != nil {
  1134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1135. return
  1136. }
  1137. c.ServeSuccessJSON(map[string]interface{}{
  1138. "msg": "删除成功",
  1139. })
  1140. }
  1141. func (c *DataApiController) CreateSubAdviceTemplate() {
  1142. drug_spec := c.GetString("drug_spec")
  1143. drug_spec_unit := c.GetString("drug_spec_unit")
  1144. advice_name := c.GetString("advice_name")
  1145. advice_desc := c.GetString("advice_desc")
  1146. single_dose, _ := c.GetFloat("single_dose", 0)
  1147. single_dose_unit := c.GetString("single_dose_unit")
  1148. prescribing_number, _ := c.GetFloat("prescribing_number", 0)
  1149. prescribing_number_unit := c.GetString("prescribing_number_unit")
  1150. delivery_way := c.GetString("delivery_way")
  1151. execution_frequency := c.GetString("execution_frequency")
  1152. template_id, _ := c.GetInt64("template_id", 0)
  1153. parent_id, _ := c.GetInt64("parent_id", 0)
  1154. drug_id, _ := c.GetInt64("drug_id")
  1155. way, _ := c.GetInt64("way")
  1156. adminUserInfo := c.GetAdminUserInfo()
  1157. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1158. if appRole.UserType == 3 {
  1159. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1160. if getPermissionErr != nil {
  1161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1162. return
  1163. } else if headNursePermission == nil {
  1164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1165. return
  1166. }
  1167. }
  1168. template := models.DoctorAdviceTemplate{
  1169. OrgId: adminUserInfo.CurrentOrgId,
  1170. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1171. Status: 1,
  1172. CreatedTime: time.Now().Unix(),
  1173. UpdatedTime: time.Now().Unix(),
  1174. DrugSpec: drug_spec,
  1175. DrugSpecUnit: drug_spec_unit,
  1176. AdviceName: advice_name,
  1177. AdviceDesc: advice_desc,
  1178. SingleDose: single_dose,
  1179. SingleDoseUnit: single_dose_unit,
  1180. PrescribingNumber: prescribing_number,
  1181. PrescribingNumberUnit: prescribing_number_unit,
  1182. DeliveryWay: delivery_way,
  1183. ExecutionFrequency: execution_frequency,
  1184. TemplateId: template_id,
  1185. ParentId: parent_id,
  1186. DrugId: drug_id,
  1187. Way: way,
  1188. }
  1189. if template.AdviceName == "" {
  1190. utils.ErrorLog("医嘱名字不能为空")
  1191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
  1192. return
  1193. }
  1194. err := service.CreateAdviceTemplate(&template)
  1195. if err != nil {
  1196. utils.ErrorLog("%v", err)
  1197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1198. return
  1199. }
  1200. c.ServeSuccessJSON(map[string]interface{}{
  1201. "template": template,
  1202. })
  1203. return
  1204. }
  1205. func (this *DataApiController) ModifyTemplateName() {
  1206. template_name := this.GetString("template_name")
  1207. template_id, _ := this.GetInt64("template_id", 0)
  1208. sort, _ := this.GetInt64("sort")
  1209. if len(template_name) <= 0 {
  1210. utils.ErrorLog("模版名字不能为空")
  1211. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  1212. return
  1213. }
  1214. if template_id == 0 {
  1215. utils.ErrorLog("模版不存在")
  1216. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamTemplateNOEXISTWrong)
  1217. return
  1218. }
  1219. adminUserInfo := this.GetAdminUserInfo()
  1220. template, _ := service.FindParentTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1221. var err error
  1222. if template.Name == template_name {
  1223. err = service.ModifyTemplateNameOne(template_id, template_name, sort)
  1224. if err != nil {
  1225. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1226. return
  1227. }
  1228. } else {
  1229. //total := service.FindTemplateRecordByName(adminUserInfo.CurrentOrgId, template_name);
  1230. //if total > 0 {
  1231. // utils.ErrorLog("模版名称已经存在")
  1232. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNameWrong)
  1233. // return
  1234. //}
  1235. err = service.ModifyTemplateNameOne(template_id, template_name, sort)
  1236. if err != nil {
  1237. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1238. return
  1239. }
  1240. }
  1241. this.ServeSuccessJSON(map[string]interface{}{
  1242. "template_name": template_name,
  1243. "template_id": template_id,
  1244. })
  1245. }
  1246. func (this *DataApiController) ModifyFiledIsShow() {
  1247. id, _ := this.GetInt64("id", 0)
  1248. is_show, _ := this.GetInt("is_show", 0)
  1249. is_write, _ := this.GetInt("is_write", 0)
  1250. adminUserInfo := this.GetAdminUserInfo()
  1251. err := service.ShowFiledConfig(adminUserInfo.CurrentOrgId, is_show, is_write, id)
  1252. if err != nil {
  1253. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1254. return
  1255. } else {
  1256. this.ServeSuccessJSON(map[string]interface{}{
  1257. "id": id,
  1258. "is_show": is_show,
  1259. "is_write": is_write,
  1260. })
  1261. }
  1262. }
  1263. func (c *DataApiController) GetAllAdviceConfigs() {
  1264. adminUserInfo := c.GetAdminUserInfo()
  1265. var drugs []models.DrugDic
  1266. drugways, _, _ := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  1267. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  1268. adviceTemplates, _ := service.FindOtherAllAdviceTemplate(adminUserInfo.CurrentOrgId)
  1269. c.ServeSuccessJSON(map[string]interface{}{
  1270. "drugs": drugs,
  1271. "drugways": drugways,
  1272. "efs": efs,
  1273. "advice_templates": adviceTemplates,
  1274. })
  1275. }
  1276. func (c *DataApiController) GetHandleData() {
  1277. id, _ := c.GetInt64("id")
  1278. config, err := service.GetHandleData(id)
  1279. if err != nil {
  1280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1281. return
  1282. }
  1283. c.ServeSuccessJSON(map[string]interface{}{
  1284. "config": config,
  1285. })
  1286. }
  1287. func (c *DataApiController) UpdateDataTwo() {
  1288. id, _ := c.GetInt64("id")
  1289. //fmt.Print("id",id)
  1290. dataBody := make(map[string]interface{}, 0)
  1291. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1292. //fmt.Print("err",err)
  1293. //fmt.Print("id",id)
  1294. name := dataBody["name"].(string)
  1295. // fmt.Print("name",name)
  1296. order := int64(dataBody["order"].(float64))
  1297. // fmt.Print("order",order)
  1298. remake := dataBody["remark"].(string)
  1299. // fmt.Print("remake",remake)
  1300. configModel := models.ConfigViewModel{
  1301. Name: name,
  1302. Order: order,
  1303. Remark: remake,
  1304. }
  1305. err = service.UpdateDataTwo(id, configModel)
  1306. if err != nil {
  1307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1308. return
  1309. }
  1310. c.ServeSuccessJSON(map[string]interface{}{
  1311. "configModel": configModel,
  1312. })
  1313. }
  1314. func (c *DataApiController) CreateHisAdviceTemplate() {
  1315. templateName := c.GetString("template_name")
  1316. advice_type, _ := c.GetInt64("advice_type")
  1317. if templateName == "" {
  1318. utils.ErrorLog("模版名称不能为空")
  1319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  1320. return
  1321. }
  1322. if advice_type < 0 {
  1323. utils.ErrorLog("医嘱模版类型不能为空")
  1324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceTypeWrong)
  1325. return
  1326. }
  1327. adminUserInfo := c.GetAdminUserInfo()
  1328. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1329. if appRole.UserType == 3 {
  1330. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1331. if getPermissionErr != nil {
  1332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1333. return
  1334. } else if headNursePermission == nil {
  1335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1336. return
  1337. }
  1338. }
  1339. template := &models.HisDoctorAdviceParentTemplate{
  1340. Name: templateName,
  1341. OrgId: adminUserInfo.CurrentOrgId,
  1342. Status: 1,
  1343. CreatedTime: time.Now().Unix(),
  1344. UpdatedTime: time.Now().Unix(),
  1345. AdviceType: advice_type,
  1346. }
  1347. createErr := service.CreateHisDoctorAdviceTemplate(template)
  1348. if createErr != nil {
  1349. utils.ErrorLog("%v", createErr)
  1350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1351. return
  1352. }
  1353. dataBody := make(map[string]interface{}, 0)
  1354. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1355. if err != nil {
  1356. utils.ErrorLog(err.Error())
  1357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1358. return
  1359. }
  1360. var subTemplate []*models.HisDoctorAdviceTemplate
  1361. if dataBody["data"] != nil && reflect.TypeOf(dataBody["data"]).String() == "[]interface {}" {
  1362. subTemp, _ := dataBody["data"].([]interface{})
  1363. if len(subTemp) > 0 {
  1364. for _, item := range subTemp {
  1365. items := item.(map[string]interface{})
  1366. if items["advice_name"] == nil || reflect.TypeOf(items["advice_name"]).String() != "string" {
  1367. utils.ErrorLog("advice_name")
  1368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1369. return
  1370. }
  1371. advice_name, _ := items["advice_name"].(string)
  1372. advice_desc, _ := items["advice_desc"].(string)
  1373. single_dose_unit, _ := items["single_dose_unit"].(string)
  1374. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  1375. delivery_way, _ := items["delivery_way"].(string)
  1376. execution_frequency, _ := items["execution_frequency"].(string)
  1377. drug_spec, _ := items["drug_spec"].(string)
  1378. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  1379. single_dose := items["single_dose"].(float64)
  1380. prescribing_number := items["prescribing_number"].(float64)
  1381. drug_id := int64(items["drug_id"].(float64))
  1382. subTemps := &models.HisDoctorAdviceTemplate{
  1383. AdviceName: advice_name,
  1384. Status: 1,
  1385. CreatedTime: time.Now().Unix(),
  1386. UpdatedTime: time.Now().Unix(),
  1387. OrgId: adminUserInfo.CurrentOrgId,
  1388. AdviceDesc: advice_desc,
  1389. AdviceType: advice_type,
  1390. SingleDoseUnit: single_dose_unit,
  1391. PrescribingNumber: prescribing_number,
  1392. PrescribingNumberUnit: prescribing_number_unit,
  1393. DeliveryWay: delivery_way,
  1394. ExecutionFrequency: execution_frequency,
  1395. TemplateId: template.ID,
  1396. DrugSpec: drug_spec,
  1397. DrugSpecUnit: drug_spec_unit,
  1398. SingleDose: single_dose,
  1399. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1400. DrugId: drug_id,
  1401. }
  1402. subTemplate = append(subTemplate, subTemps)
  1403. }
  1404. }
  1405. }
  1406. //errs := service.CreateBatchRecord(subTemplate)
  1407. errs := service.CreateHisSubDoctorAdviceTemplate(subTemplate)
  1408. if errs != nil {
  1409. utils.ErrorLog(errs.Error())
  1410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1411. return
  1412. }
  1413. templates, _ := service.FindHisDoctorAdviceTemplateById(template.ID, adminUserInfo.CurrentOrgId)
  1414. c.ServeSuccessJSON(map[string]interface{}{
  1415. "template": templates,
  1416. })
  1417. return
  1418. }
  1419. func (c *DataApiController) UpdateHisAdviceTemplate() {
  1420. adminUserInfo := c.GetAdminUserInfo()
  1421. id, _ := c.GetInt64("id", 0)
  1422. if id <= 0 {
  1423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1424. return
  1425. }
  1426. template, _ := service.FindHisAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  1427. if template == nil {
  1428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  1429. return
  1430. }
  1431. var templatedata models.HisDoctorAdviceTemplate
  1432. err := json.Unmarshal(c.Ctx.Input.RequestBody, &templatedata)
  1433. if err != nil {
  1434. utils.ErrorLog("%v", err)
  1435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1436. return
  1437. }
  1438. if templatedata.AdviceName == "" {
  1439. utils.ErrorLog("不能为空")
  1440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1441. return
  1442. }
  1443. timeNow := time.Now().Unix()
  1444. template.UpdatedTime = timeNow
  1445. template.AdviceName = templatedata.AdviceName
  1446. template.AdviceDesc = templatedata.AdviceDesc
  1447. template.SingleDose = templatedata.SingleDose
  1448. template.SingleDoseUnit = templatedata.SingleDoseUnit
  1449. template.PrescribingNumber = templatedata.PrescribingNumber
  1450. template.PrescribingNumberUnit = templatedata.PrescribingNumberUnit
  1451. template.DrugSpec = templatedata.DrugSpec
  1452. template.DrugSpecUnit = templatedata.DrugSpecUnit
  1453. template.DeliveryWay = templatedata.DeliveryWay
  1454. template.ExecutionFrequency = templatedata.ExecutionFrequency
  1455. template.DrugId = template.DrugId
  1456. err = service.UpdateHisAdviceTemplate(template)
  1457. if err != nil {
  1458. utils.ErrorLog("%v", err)
  1459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1460. return
  1461. }
  1462. c.ServeSuccessJSON(map[string]interface{}{
  1463. "template": template,
  1464. })
  1465. return
  1466. }
  1467. func (c *DataApiController) DeleteHisAdviceTemplate() {
  1468. adminUserInfo := c.GetAdminUserInfo()
  1469. parent_id, _ := c.GetInt64("parent_id", 0)
  1470. id, _ := c.GetInt64("id", 0)
  1471. if id <= 0 {
  1472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1473. return
  1474. }
  1475. template, _ := service.FindHisAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  1476. if template == nil {
  1477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  1478. return
  1479. }
  1480. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1481. //if appRole.UserType == 3 {
  1482. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1483. // if getPermissionErr != nil {
  1484. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1485. // return
  1486. // } else if headNursePermission == nil {
  1487. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1488. // return
  1489. // }
  1490. //}
  1491. timeNow := time.Now().Unix()
  1492. template.ID = id
  1493. template.UpdatedTime = timeNow
  1494. template.ParentId = parent_id
  1495. template.Status = 2
  1496. if parent_id > 0 { //删除子医嘱
  1497. err := service.UpdateHisAdviceTemplate(template)
  1498. if err != nil {
  1499. utils.ErrorLog("%v", err)
  1500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1501. return
  1502. }
  1503. } else { //删除该医嘱下的所有子医嘱
  1504. err := service.UpdateHisAdviceAndSubAdviceTemplate(template)
  1505. if err != nil {
  1506. utils.ErrorLog("%v", err)
  1507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1508. return
  1509. }
  1510. }
  1511. c.ServeSuccessJSON(map[string]interface{}{
  1512. "msg": "ok",
  1513. })
  1514. return
  1515. }
  1516. func (c *DataApiController) CreateSingleHisAdviceTemplate() {
  1517. drug_spec := c.GetString("drug_spec")
  1518. drug_spec_unit := c.GetString("drug_spec_unit")
  1519. advice_name := c.GetString("advice_name")
  1520. advice_desc := c.GetString("advice_desc")
  1521. single_dose, _ := c.GetFloat("single_dose", 0)
  1522. single_dose_unit := c.GetString("single_dose_unit")
  1523. prescribing_number, _ := c.GetFloat("prescribing_number", 0)
  1524. prescribing_number_unit := c.GetString("prescribing_number_unit")
  1525. delivery_way := c.GetString("delivery_way")
  1526. execution_frequency := c.GetString("execution_frequency")
  1527. template_id, _ := c.GetInt64("template_id", -1)
  1528. drug_id, _ := c.GetInt64("drug_id")
  1529. adminUserInfo := c.GetAdminUserInfo()
  1530. template := models.HisDoctorAdviceTemplate{
  1531. OrgId: adminUserInfo.CurrentOrgId,
  1532. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1533. Status: 1,
  1534. CreatedTime: time.Now().Unix(),
  1535. UpdatedTime: time.Now().Unix(),
  1536. DrugSpec: drug_spec,
  1537. DrugSpecUnit: drug_spec_unit,
  1538. AdviceName: advice_name,
  1539. AdviceDesc: advice_desc,
  1540. SingleDose: single_dose,
  1541. SingleDoseUnit: single_dose_unit,
  1542. PrescribingNumber: prescribing_number,
  1543. PrescribingNumberUnit: prescribing_number_unit,
  1544. DeliveryWay: delivery_way,
  1545. ExecutionFrequency: execution_frequency,
  1546. TemplateId: template_id,
  1547. DrugId: drug_id,
  1548. }
  1549. if template.AdviceName == "" {
  1550. utils.ErrorLog("医嘱名字不能为空")
  1551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
  1552. return
  1553. }
  1554. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1555. if appRole.UserType == 3 {
  1556. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1557. if getPermissionErr != nil {
  1558. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1559. return
  1560. } else if headNursePermission == nil {
  1561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1562. return
  1563. }
  1564. }
  1565. err := service.CreateHisAdviceTemplate(&template)
  1566. if err != nil {
  1567. utils.ErrorLog("%v", err)
  1568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1569. return
  1570. }
  1571. c.ServeSuccessJSON(map[string]interface{}{
  1572. "template": template,
  1573. })
  1574. return
  1575. }
  1576. func (c *DataApiController) DeleteHisParentAdviceTemplate() {
  1577. template_id, _ := c.GetInt64("template_id", 0)
  1578. adminUserInfo := c.GetAdminUserInfo()
  1579. _, err := service.FindParentHisTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1580. if err != nil {
  1581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1582. return
  1583. }
  1584. err1 := service.DeleteHisParentDoctorAdviceByTemplateId(template_id, adminUserInfo.CurrentOrgId)
  1585. if err1 != nil {
  1586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1587. return
  1588. }
  1589. c.ServeSuccessJSON(map[string]interface{}{
  1590. "msg": "删除成功",
  1591. })
  1592. }
  1593. func (this *DataApiController) ModifyHisTemplateName() {
  1594. template_name := this.GetString("template_name")
  1595. template_id, _ := this.GetInt64("template_id", 0)
  1596. if len(template_name) <= 0 {
  1597. utils.ErrorLog("模版名字不能为空")
  1598. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  1599. return
  1600. }
  1601. if template_id == 0 {
  1602. utils.ErrorLog("模版不存在")
  1603. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamTemplateNOEXISTWrong)
  1604. return
  1605. }
  1606. adminUserInfo := this.GetAdminUserInfo()
  1607. template, _ := service.FindParentHisTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1608. var err error
  1609. if template.Name == template_name {
  1610. err = service.ModifyTemplateName(template_id, template_name)
  1611. if err != nil {
  1612. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1613. return
  1614. }
  1615. } else {
  1616. err = service.ModifyHisTemplateName(template_id, template_name)
  1617. if err != nil {
  1618. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1619. return
  1620. }
  1621. }
  1622. this.ServeSuccessJSON(map[string]interface{}{
  1623. "template_name": template_name,
  1624. "template_id": template_id,
  1625. })
  1626. }
  1627. func (this *DataApiController) GetAllHisAdviceTemplate() {
  1628. adminUserInfo := this.GetAdminUserInfo()
  1629. drugs, _ := service.GetAllDrugLibs(adminUserInfo.CurrentOrgId)
  1630. drugways, _, _ := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  1631. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  1632. adviceTemplates, _ := service.FindHisAllAdviceTemplate(adminUserInfo.CurrentOrgId)
  1633. this.ServeSuccessJSON(map[string]interface{}{
  1634. "drugways": drugways,
  1635. "efs": efs,
  1636. "advice_templates": adviceTemplates,
  1637. "drugs": drugs,
  1638. })
  1639. }