data_api_controller.go 55KB

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