data_api_controller.go 44KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460
  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. beego.Router("/api/hisadvicetemplate/create", &DataApiController{}, "Post:CreateHisAdviceTemplate")
  47. beego.Router("/api/hissubadvice/create", &DataApiController{}, "Post:CreateHisubAdviceTemplate")
  48. beego.Router("/api/hisadvicetemplate/update", &DataApiController{}, "Put:UpdateHisAdviceTemplate")
  49. beego.Router("/api/hisadvicetemplate/delete", &DataApiController{}, "Delete:DeleteHisAdviceTemplate")
  50. //beego.Router("/api/hisadvicetemplate/add", &DataApiController{}, "Post:CreateSingleHisAdviceTemplate")
  51. //beego.Router("/api/hisadviceparenttemplate/delete", &DataApiController{}, "Delete:DeleteHisParentAdviceTemplate")
  52. //beego.Router("/api/histemplate/modify", &DataApiController{}, "Post:ModifyHisTemplateName")
  53. }
  54. //GetPatientsList 取配置信息列表
  55. func (c *DataApiController) GetConfigList() {
  56. adminUserInfo := c.GetAdminUserInfo()
  57. configList, _ := service.GetConfigList(adminUserInfo.CurrentOrgId)
  58. c.ServeSuccessJSON(map[string]interface{}{
  59. "configlist": configList,
  60. })
  61. return
  62. }
  63. //CreateConfig 创建配置信息
  64. func (c *DataApiController) CreateConfig() {
  65. adminUserInfo := c.GetAdminUserInfo()
  66. var dataconfig models.Dataconfig
  67. var resultConfig models.ConfigViewModel
  68. code := configFormData(&dataconfig, c.Ctx.Input.RequestBody)
  69. if code > 0 {
  70. c.ServeFailJSONWithSGJErrorCode(code)
  71. return
  72. }
  73. // 验证关键字段的值是否重复
  74. thisConfig, _ := service.FindConfigByTitle(dataconfig.Module, dataconfig.FieldName, adminUserInfo.CurrentOrgId)
  75. fmt.Println("99999", thisConfig)
  76. if thisConfig.ID > 0 {
  77. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  78. return
  79. }
  80. fieldValue := service.GetChildValue(dataconfig.Module, dataconfig.ParentId, adminUserInfo.CurrentOrgId)
  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" || module == "special_treatment" {
  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. drug_id := int64(items["drug_id"].(float64))
  863. way := int64(items["way"].(float64))
  864. subTemps := &models.DoctorAdviceTemplate{
  865. AdviceName: advice_name,
  866. Status: 1,
  867. CreatedTime: time.Now().Unix(),
  868. UpdatedTime: time.Now().Unix(),
  869. OrgId: adminUserInfo.CurrentOrgId,
  870. AdviceDesc: advice_desc,
  871. AdviceType: advice_type,
  872. SingleDoseUnit: single_dose_unit,
  873. PrescribingNumber: prescribing_number,
  874. PrescribingNumberUnit: prescribing_number_unit,
  875. DeliveryWay: delivery_way,
  876. ExecutionFrequency: execution_frequency,
  877. TemplateId: template.ID,
  878. DrugSpec: drug_spec,
  879. DrugSpecUnit: drug_spec_unit,
  880. SingleDose: single_dose,
  881. AdviceDoctor: adminUserInfo.AdminUser.Id,
  882. DayCount: day_count,
  883. WeekDays: weekdays,
  884. FrequencyType: frequency_type,
  885. Way: way,
  886. DrugId: drug_id,
  887. DrugNameId: 0,
  888. }
  889. subTemplate = append(subTemplate, subTemps)
  890. }
  891. }
  892. }
  893. //errs := service.CreateBatchRecord(subTemplate)
  894. errs := service.CreateSubTemplate(subTemplate)
  895. if errs != nil {
  896. utils.ErrorLog(errs.Error())
  897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  898. return
  899. }
  900. templates, _ := service.FindDoctorAdviceTemplateById(template.ID, adminUserInfo.CurrentOrgId)
  901. c.ServeSuccessJSON(map[string]interface{}{
  902. "template": templates,
  903. })
  904. return
  905. }
  906. func (c *DataApiController) UpdateAdviceTemplate() {
  907. adminUserInfo := c.GetAdminUserInfo()
  908. id, _ := c.GetInt64("id", 0)
  909. if id <= 0 {
  910. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  911. return
  912. }
  913. template, _ := service.FindAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  914. if template == nil {
  915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  916. return
  917. }
  918. //TODO 根据路由来做权限
  919. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  920. //if appRole.UserType == 3 {
  921. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  922. // if getPermissionErr != nil {
  923. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  924. // return
  925. // } else if headNursePermission == nil {
  926. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  927. // return
  928. // }
  929. //}
  930. var templatedata models.DoctorAdviceTemplate
  931. err := json.Unmarshal(c.Ctx.Input.RequestBody, &templatedata)
  932. if err != nil {
  933. utils.ErrorLog("%v", err)
  934. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  935. return
  936. }
  937. if templatedata.AdviceName == "" {
  938. utils.ErrorLog("不能为空")
  939. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  940. return
  941. }
  942. timeNow := time.Now().Unix()
  943. template.UpdatedTime = timeNow
  944. template.AdviceName = templatedata.AdviceName
  945. template.AdviceDesc = templatedata.AdviceDesc
  946. template.SingleDose = templatedata.SingleDose
  947. template.SingleDoseUnit = templatedata.SingleDoseUnit
  948. template.PrescribingNumber = templatedata.PrescribingNumber
  949. template.PrescribingNumberUnit = templatedata.PrescribingNumberUnit
  950. template.DrugSpec = templatedata.DrugSpec
  951. template.DrugSpecUnit = templatedata.DrugSpecUnit
  952. template.DeliveryWay = templatedata.DeliveryWay
  953. template.ExecutionFrequency = templatedata.ExecutionFrequency
  954. template.FrequencyType = templatedata.FrequencyType
  955. template.DayCount = templatedata.DayCount
  956. template.WeekDays = templatedata.WeekDays
  957. template.DrugId = template.DrugId
  958. template.Way = template.Way
  959. err = service.UpdateAdviceTemplate(template)
  960. if err != nil {
  961. utils.ErrorLog("%v", err)
  962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  963. return
  964. }
  965. c.ServeSuccessJSON(map[string]interface{}{
  966. "template": template,
  967. })
  968. return
  969. }
  970. func (c *DataApiController) DeleteAdviceTemplate() {
  971. adminUserInfo := c.GetAdminUserInfo()
  972. parent_id, _ := c.GetInt64("parent_id", 0)
  973. id, _ := c.GetInt64("id", 0)
  974. if id <= 0 {
  975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  976. return
  977. }
  978. template, _ := service.FindAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  979. if template == nil {
  980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  981. return
  982. }
  983. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  984. //if appRole.UserType == 3 {
  985. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  986. // if getPermissionErr != nil {
  987. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  988. // return
  989. // } else if headNursePermission == nil {
  990. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  991. // return
  992. // }
  993. //}
  994. timeNow := time.Now().Unix()
  995. template.ID = id
  996. template.UpdatedTime = timeNow
  997. template.ParentId = parent_id
  998. template.Status = 2
  999. if parent_id > 0 { //删除子医嘱
  1000. err := service.UpdateAdviceTemplate(template)
  1001. if err != nil {
  1002. utils.ErrorLog("%v", err)
  1003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1004. return
  1005. }
  1006. } else { //删除该医嘱下的所有子医嘱
  1007. err := service.UpdateAdviceAndSubAdviceTemplate(template)
  1008. if err != nil {
  1009. utils.ErrorLog("%v", err)
  1010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1011. return
  1012. }
  1013. }
  1014. c.ServeSuccessJSON(map[string]interface{}{
  1015. "msg": "ok",
  1016. })
  1017. return
  1018. }
  1019. func (c *DataApiController) CreateSingleAdviceTemplate() {
  1020. drug_spec := c.GetString("drug_spec")
  1021. drug_spec_unit := c.GetString("drug_spec_unit")
  1022. advice_name := c.GetString("advice_name")
  1023. advice_desc := c.GetString("advice_desc")
  1024. single_dose, _ := c.GetFloat("single_dose", 0)
  1025. single_dose_unit := c.GetString("single_dose_unit")
  1026. prescribing_number, _ := c.GetFloat("prescribing_number", 0)
  1027. prescribing_number_unit := c.GetString("prescribing_number_unit")
  1028. delivery_way := c.GetString("delivery_way")
  1029. execution_frequency := c.GetString("execution_frequency")
  1030. template_id, _ := c.GetInt64("template_id", -1)
  1031. advice_type, _ := c.GetInt64("advice_type", -1)
  1032. frequency_type, _ := c.GetInt64("frequency_type", -1)
  1033. week_days := c.GetString("week_days")
  1034. day_count, _ := c.GetInt64("day_count", -1)
  1035. drug_id, _ := c.GetInt64("drug_id")
  1036. way, _ := c.GetInt64("way")
  1037. adminUserInfo := c.GetAdminUserInfo()
  1038. template := models.DoctorAdviceTemplate{
  1039. OrgId: adminUserInfo.CurrentOrgId,
  1040. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1041. AdviceType: advice_type,
  1042. FrequencyType: frequency_type,
  1043. WeekDays: week_days,
  1044. DayCount: day_count,
  1045. Status: 1,
  1046. CreatedTime: time.Now().Unix(),
  1047. UpdatedTime: time.Now().Unix(),
  1048. DrugSpec: drug_spec,
  1049. DrugSpecUnit: drug_spec_unit,
  1050. AdviceName: advice_name,
  1051. AdviceDesc: advice_desc,
  1052. SingleDose: single_dose,
  1053. SingleDoseUnit: single_dose_unit,
  1054. PrescribingNumber: prescribing_number,
  1055. PrescribingNumberUnit: prescribing_number_unit,
  1056. DeliveryWay: delivery_way,
  1057. ExecutionFrequency: execution_frequency,
  1058. TemplateId: template_id,
  1059. Way: way,
  1060. DrugId: drug_id,
  1061. }
  1062. if template.AdviceName == "" {
  1063. utils.ErrorLog("医嘱名字不能为空")
  1064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
  1065. return
  1066. }
  1067. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1068. if appRole.UserType == 3 {
  1069. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1070. if getPermissionErr != nil {
  1071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1072. return
  1073. } else if headNursePermission == nil {
  1074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1075. return
  1076. }
  1077. }
  1078. err := service.CreateAdviceTemplate(&template)
  1079. if err != nil {
  1080. utils.ErrorLog("%v", err)
  1081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1082. return
  1083. }
  1084. c.ServeSuccessJSON(map[string]interface{}{
  1085. "template": template,
  1086. })
  1087. return
  1088. }
  1089. func (c *DataApiController) DeleteParentAdviceTemplate() {
  1090. template_id, _ := c.GetInt64("template_id", 0)
  1091. adminUserInfo := c.GetAdminUserInfo()
  1092. _, err := service.FindParentTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1093. if err != nil {
  1094. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1095. return
  1096. }
  1097. err1 := service.DeleteParentDoctorAdviceByTemplateId(template_id, adminUserInfo.CurrentOrgId)
  1098. if err1 != nil {
  1099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1100. return
  1101. }
  1102. c.ServeSuccessJSON(map[string]interface{}{
  1103. "msg": "删除成功",
  1104. })
  1105. }
  1106. func (c *DataApiController) CreateSubAdviceTemplate() {
  1107. drug_spec := c.GetString("drug_spec")
  1108. drug_spec_unit := c.GetString("drug_spec_unit")
  1109. advice_name := c.GetString("advice_name")
  1110. advice_desc := c.GetString("advice_desc")
  1111. single_dose, _ := c.GetFloat("single_dose", 0)
  1112. single_dose_unit := c.GetString("single_dose_unit")
  1113. prescribing_number, _ := c.GetFloat("prescribing_number", 0)
  1114. prescribing_number_unit := c.GetString("prescribing_number_unit")
  1115. delivery_way := c.GetString("delivery_way")
  1116. execution_frequency := c.GetString("execution_frequency")
  1117. template_id, _ := c.GetInt64("template_id", 0)
  1118. parent_id, _ := c.GetInt64("parent_id", 0)
  1119. drug_id, _ := c.GetInt64("drug_id")
  1120. way, _ := c.GetInt64("way")
  1121. adminUserInfo := c.GetAdminUserInfo()
  1122. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1123. if appRole.UserType == 3 {
  1124. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1125. if getPermissionErr != nil {
  1126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1127. return
  1128. } else if headNursePermission == nil {
  1129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1130. return
  1131. }
  1132. }
  1133. template := models.DoctorAdviceTemplate{
  1134. OrgId: adminUserInfo.CurrentOrgId,
  1135. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1136. Status: 1,
  1137. CreatedTime: time.Now().Unix(),
  1138. UpdatedTime: time.Now().Unix(),
  1139. DrugSpec: drug_spec,
  1140. DrugSpecUnit: drug_spec_unit,
  1141. AdviceName: advice_name,
  1142. AdviceDesc: advice_desc,
  1143. SingleDose: single_dose,
  1144. SingleDoseUnit: single_dose_unit,
  1145. PrescribingNumber: prescribing_number,
  1146. PrescribingNumberUnit: prescribing_number_unit,
  1147. DeliveryWay: delivery_way,
  1148. ExecutionFrequency: execution_frequency,
  1149. TemplateId: template_id,
  1150. ParentId: parent_id,
  1151. DrugId: drug_id,
  1152. Way: way,
  1153. }
  1154. if template.AdviceName == "" {
  1155. utils.ErrorLog("医嘱名字不能为空")
  1156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
  1157. return
  1158. }
  1159. err := service.CreateAdviceTemplate(&template)
  1160. if err != nil {
  1161. utils.ErrorLog("%v", err)
  1162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1163. return
  1164. }
  1165. c.ServeSuccessJSON(map[string]interface{}{
  1166. "template": template,
  1167. })
  1168. return
  1169. }
  1170. func (this *DataApiController) ModifyTemplateName() {
  1171. template_name := this.GetString("template_name")
  1172. template_id, _ := this.GetInt64("template_id", 0)
  1173. if len(template_name) <= 0 {
  1174. utils.ErrorLog("模版名字不能为空")
  1175. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  1176. return
  1177. }
  1178. if template_id == 0 {
  1179. utils.ErrorLog("模版不存在")
  1180. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamTemplateNOEXISTWrong)
  1181. return
  1182. }
  1183. adminUserInfo := this.GetAdminUserInfo()
  1184. template, _ := service.FindParentTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1185. var err error
  1186. if template.Name == template_name {
  1187. err = service.ModifyTemplateName(template_id, template_name)
  1188. if err != nil {
  1189. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1190. return
  1191. }
  1192. } else {
  1193. //total := service.FindTemplateRecordByName(adminUserInfo.CurrentOrgId, template_name);
  1194. //if total > 0 {
  1195. // utils.ErrorLog("模版名称已经存在")
  1196. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNameWrong)
  1197. // return
  1198. //}
  1199. err = service.ModifyTemplateName(template_id, template_name)
  1200. if err != nil {
  1201. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1202. return
  1203. }
  1204. }
  1205. this.ServeSuccessJSON(map[string]interface{}{
  1206. "template_name": template_name,
  1207. "template_id": template_id,
  1208. })
  1209. }
  1210. func (this *DataApiController) ModifyFiledIsShow() {
  1211. id, _ := this.GetInt64("id", 0)
  1212. is_show, _ := this.GetInt("is_show", 0)
  1213. adminUserInfo := this.GetAdminUserInfo()
  1214. err := service.ShowFiledConfig(adminUserInfo.CurrentOrgId, is_show, id)
  1215. if err != nil {
  1216. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1217. return
  1218. } else {
  1219. this.ServeSuccessJSON(map[string]interface{}{
  1220. "id": id,
  1221. "is_show": is_show,
  1222. })
  1223. }
  1224. }
  1225. func (c *DataApiController) GetAllAdviceConfigs() {
  1226. adminUserInfo := c.GetAdminUserInfo()
  1227. var drugs []models.DrugDic
  1228. drugways, _, _ := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  1229. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  1230. adviceTemplates, _ := service.FindOtherAllAdviceTemplate(adminUserInfo.CurrentOrgId)
  1231. c.ServeSuccessJSON(map[string]interface{}{
  1232. "drugs": drugs,
  1233. "drugways": drugways,
  1234. "efs": efs,
  1235. "advice_templates": adviceTemplates,
  1236. })
  1237. }
  1238. func (c *DataApiController) GetHandleData() {
  1239. id, _ := c.GetInt64("id")
  1240. config, err := service.GetHandleData(id)
  1241. if err != nil {
  1242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1243. return
  1244. }
  1245. c.ServeSuccessJSON(map[string]interface{}{
  1246. "config": config,
  1247. })
  1248. }
  1249. func (c *DataApiController) UpdateDataTwo() {
  1250. id, _ := c.GetInt64("id")
  1251. //fmt.Print("id",id)
  1252. dataBody := make(map[string]interface{}, 0)
  1253. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1254. //fmt.Print("err",err)
  1255. //fmt.Print("id",id)
  1256. name := dataBody["name"].(string)
  1257. // fmt.Print("name",name)
  1258. order := int64(dataBody["order"].(float64))
  1259. // fmt.Print("order",order)
  1260. remake := dataBody["remark"].(string)
  1261. // fmt.Print("remake",remake)
  1262. configModel := models.ConfigViewModel{
  1263. Name: name,
  1264. Order: order,
  1265. Remark: remake,
  1266. }
  1267. err = service.UpdateDataTwo(id, configModel)
  1268. if err != nil {
  1269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1270. return
  1271. }
  1272. c.ServeSuccessJSON(map[string]interface{}{
  1273. "configModel": configModel,
  1274. })
  1275. }
  1276. func (c *DataApiController) CreateHisAdviceTemplate() {
  1277. }
  1278. func (c *DataApiController) CreateSHisubAdviceTemplate() {
  1279. }
  1280. func (c *DataApiController) CreateHisubAdviceTemplate() {
  1281. }
  1282. func (c *DataApiController) UpdateHisAdviceTemplate() {
  1283. }
  1284. func (c *DataApiController) DeleteHisAdviceTemplate() {
  1285. }