data_api_controller.go 42KB

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