data_api_controller.go 43KB

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