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