data_api_controller.go 55KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787
  1. package controllers
  2. import (
  3. "Xcx_New/enums"
  4. "Xcx_New/models"
  5. "Xcx_New/service"
  6. "Xcx_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. dataconfig.FieldType = int64(dataBody["field_type"].(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. if dataBody["field_type"] != nil {
  313. dataconfig.FieldType = int64(dataBody["field_type"].(float64))
  314. } else {
  315. dataconfig.FieldType = 0
  316. }
  317. // 验证关键字段的值是否重复
  318. // thisConfig,_:=service.FindConfigByName(dataconfig.Module, dataconfig.Name,dataconfig.ParentId,dataconfig.OrgId)
  319. // if thisConfig.ID >0 {
  320. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  321. // return
  322. // }
  323. fieldValue := service.GetChildValue(dataconfig.Module, dataconfig.ParentId, dataconfig.OrgId)
  324. dataconfig.Value = fieldValue + 1
  325. err = service.CreateConfig(&dataconfig)
  326. if err != nil {
  327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  328. return
  329. }
  330. c.ServeSuccessJSON(map[string]interface{}{
  331. "dataconfig": dataconfig,
  332. "msg": "ok",
  333. })
  334. return
  335. }
  336. func configFormData(dataconfig *models.Dataconfig, data []byte) (code int) {
  337. configBody := make(map[string]interface{}, 0)
  338. err := json.Unmarshal(data, &configBody)
  339. utils.InfoLog(string(data))
  340. if err != nil {
  341. utils.ErrorLog(err.Error())
  342. code = enums.ErrorCodeParamWrong
  343. return
  344. }
  345. if configBody["module"] == nil || reflect.TypeOf(configBody["module"]).String() != "string" {
  346. utils.ErrorLog("module")
  347. code = enums.ErrorCodeParamWrong
  348. return
  349. }
  350. module, _ := configBody["module"].(string)
  351. if len(module) == 0 {
  352. utils.ErrorLog("len(module) == 0")
  353. code = enums.ErrorCodeParamWrong
  354. return
  355. }
  356. dataconfig.Module = module
  357. if module == "education" || module == "summary" || module == "course_disease" || module == "rescue_record" || module == "nursing_record" || module == "special_record" || module == "special_treatment" || module == "template_summary" || module == "template_plan" {
  358. if configBody["title"] == nil || reflect.TypeOf(configBody["title"]).String() != "string" {
  359. utils.ErrorLog("title")
  360. code = enums.ErrorCodeParamWrong
  361. return
  362. }
  363. title, _ := configBody["title"].(string)
  364. if len(title) == 0 {
  365. utils.ErrorLog("len(title) == 0")
  366. code = enums.ErrorCodeParamWrong
  367. return
  368. }
  369. dataconfig.Title = title
  370. if configBody["content"] == nil || reflect.TypeOf(configBody["content"]).String() != "string" {
  371. utils.ErrorLog("content")
  372. code = enums.ErrorCodeParamWrong
  373. return
  374. }
  375. content, _ := configBody["content"].(string)
  376. if len(content) == 0 {
  377. utils.ErrorLog("len(content) == 0")
  378. code = enums.ErrorCodeParamWrong
  379. return
  380. }
  381. dataconfig.Content = content
  382. } else {
  383. if configBody["name"] == nil || reflect.TypeOf(configBody["name"]).String() != "string" {
  384. utils.ErrorLog("name")
  385. code = enums.ErrorCodeParamWrong
  386. return
  387. }
  388. name, _ := configBody["name"].(string)
  389. if len(name) == 0 {
  390. utils.ErrorLog("len(name) == 0")
  391. code = enums.ErrorCodeParamWrong
  392. return
  393. }
  394. dataconfig.Name = name
  395. if configBody["field_name"] == nil || reflect.TypeOf(configBody["field_name"]).String() != "string" {
  396. utils.ErrorLog("field_name")
  397. code = enums.ErrorCodeParamWrong
  398. return
  399. }
  400. field_name, _ := configBody["field_name"].(string)
  401. if len(field_name) == 0 {
  402. utils.ErrorLog("len(field_name) == 0")
  403. code = enums.ErrorCodeParamWrong
  404. return
  405. }
  406. dataconfig.FieldName = field_name
  407. }
  408. return
  409. }
  410. func configChildFormData(dataconfig *models.Dataconfig, data []byte) (code int) {
  411. configBody := make(map[string]interface{}, 0)
  412. err := json.Unmarshal(data, &configBody)
  413. utils.InfoLog(string(data))
  414. if err != nil {
  415. utils.ErrorLog(err.Error())
  416. code = enums.ErrorCodeParamWrong
  417. return
  418. }
  419. if configBody["module"] == nil || reflect.TypeOf(configBody["module"]).String() != "string" {
  420. utils.ErrorLog("module")
  421. code = enums.ErrorCodeParamWrong
  422. return
  423. }
  424. module, _ := configBody["module"].(string)
  425. if len(module) == 0 {
  426. utils.ErrorLog("len(module) == 0")
  427. code = enums.ErrorCodeParamWrong
  428. return
  429. }
  430. dataconfig.Module = module
  431. if module == "education" || module == "summary" {
  432. if configBody["title"] == nil || reflect.TypeOf(configBody["title"]).String() != "string" {
  433. utils.ErrorLog("title")
  434. code = enums.ErrorCodeParamWrong
  435. return
  436. }
  437. title, _ := configBody["title"].(string)
  438. if len(title) == 0 {
  439. utils.ErrorLog("len(title) == 0")
  440. code = enums.ErrorCodeParamWrong
  441. return
  442. }
  443. dataconfig.Title = title
  444. if configBody["content"] == nil || reflect.TypeOf(configBody["content"]).String() != "string" {
  445. utils.ErrorLog("content")
  446. code = enums.ErrorCodeParamWrong
  447. return
  448. }
  449. content, _ := configBody["content"].(string)
  450. if len(content) == 0 {
  451. utils.ErrorLog("len(content) == 0")
  452. code = enums.ErrorCodeParamWrong
  453. return
  454. }
  455. dataconfig.Content = content
  456. } else {
  457. if configBody["parent_id"] == nil || reflect.TypeOf(configBody["parent_id"]).String() != "float64" {
  458. utils.ErrorLog("module")
  459. code = enums.ErrorCodeParamWrong
  460. return
  461. }
  462. parent_id := int64(configBody["parent_id"].(float64))
  463. if parent_id <= 0 {
  464. utils.ErrorLog("parent_id <= 0")
  465. code = enums.ErrorCodeParamWrong
  466. return
  467. }
  468. dataconfig.ParentId = parent_id
  469. if configBody["name"] == nil || reflect.TypeOf(configBody["name"]).String() != "string" {
  470. utils.ErrorLog("name")
  471. code = enums.ErrorCodeParamWrong
  472. return
  473. }
  474. name, _ := configBody["name"].(string)
  475. if len(name) == 0 {
  476. utils.ErrorLog("len(name) == 0")
  477. code = enums.ErrorCodeParamWrong
  478. return
  479. }
  480. dataconfig.Name = name
  481. }
  482. return
  483. }
  484. func (c *DataApiController) GetAdviceConfigs() {
  485. advice_type, _ := c.GetInt64("type", 0)
  486. adminUserInfo := c.GetAdminUserInfo()
  487. var drugs []models.DrugDic
  488. drugways, _, _ := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  489. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  490. adviceTemplates, _ := service.FindAllAdviceTemplate(adminUserInfo.CurrentOrgId, advice_type)
  491. c.ServeSuccessJSON(map[string]interface{}{
  492. "drugs": drugs,
  493. "drugways": drugways,
  494. "efs": efs,
  495. "advice_templates": adviceTemplates,
  496. })
  497. }
  498. func (c *DataApiController) CreateDrugDic() {
  499. adminUserInfo := c.GetAdminUserInfo()
  500. var drugdic models.DrugDic
  501. err := json.Unmarshal(c.Ctx.Input.RequestBody, &drugdic)
  502. if err != nil {
  503. utils.ErrorLog("%v", err)
  504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  505. return
  506. }
  507. if drugdic.Name == "" {
  508. utils.ErrorLog("医嘱名称不能为空")
  509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  510. return
  511. }
  512. timeNow := time.Now().Unix()
  513. drugdic.Code = ""
  514. drugdic.Status = 1
  515. drugdic.CreatedTime = timeNow
  516. drugdic.UpdatedTime = timeNow
  517. drugdic.OrgId = adminUserInfo.CurrentOrgId
  518. drugdic.Creator = adminUserInfo.AdminUser.Id
  519. err = service.CreateDrugDic(&drugdic)
  520. if err != nil {
  521. utils.ErrorLog("%v", err)
  522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  523. return
  524. }
  525. c.ServeSuccessJSON(map[string]interface{}{
  526. "drugdic": drugdic,
  527. })
  528. return
  529. }
  530. func (c *DataApiController) UpdateDrugDic() {
  531. adminUserInfo := c.GetAdminUserInfo()
  532. id, _ := c.GetInt64("id", 0)
  533. if id <= 0 {
  534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  535. return
  536. }
  537. drugdic, _ := service.FindDrugDic(adminUserInfo.CurrentOrgId, id)
  538. if drugdic == nil {
  539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  540. return
  541. }
  542. var drugdicdata models.DrugDic
  543. err := json.Unmarshal(c.Ctx.Input.RequestBody, &drugdicdata)
  544. if err != nil {
  545. utils.ErrorLog("%v", err)
  546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  547. return
  548. }
  549. if drugdicdata.Name == "" {
  550. utils.ErrorLog("医嘱名称不能为空")
  551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  552. return
  553. }
  554. timeNow := time.Now().Unix()
  555. drugdic.UpdatedTime = timeNow
  556. drugdic.Name = drugdicdata.Name
  557. drugdic.Spec = drugdicdata.Spec
  558. drugdic.SpecUnit = drugdicdata.SpecUnit
  559. drugdic.Form = drugdicdata.Form
  560. drugdic.FormUnit = drugdicdata.FormUnit
  561. err = service.UpdateDrugDic(drugdic)
  562. if err != nil {
  563. utils.ErrorLog("%v", err)
  564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  565. return
  566. }
  567. c.ServeSuccessJSON(map[string]interface{}{
  568. "drugdic": drugdic,
  569. })
  570. return
  571. }
  572. func (c *DataApiController) DeleteDrugDic() {
  573. adminUserInfo := c.GetAdminUserInfo()
  574. id, _ := c.GetInt64("id", 0)
  575. if id <= 0 {
  576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  577. return
  578. }
  579. drugdic, _ := service.FindDrugDic(adminUserInfo.CurrentOrgId, id)
  580. if drugdic == nil {
  581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  582. return
  583. }
  584. timeNow := time.Now().Unix()
  585. drugdic.UpdatedTime = timeNow
  586. drugdic.Status = 2
  587. err := service.UpdateDrugDic(drugdic)
  588. if err != nil {
  589. utils.ErrorLog("%v", err)
  590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  591. return
  592. }
  593. c.ServeSuccessJSON(map[string]interface{}{
  594. "msg": "ok",
  595. })
  596. return
  597. }
  598. func (c *DataApiController) CreateDrugWay() {
  599. adminUserInfo := c.GetAdminUserInfo()
  600. var drugway models.DrugwayDic
  601. err := json.Unmarshal(c.Ctx.Input.RequestBody, &drugway)
  602. if err != nil {
  603. utils.ErrorLog("%v", err)
  604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  605. return
  606. }
  607. if drugway.Name == "" {
  608. utils.ErrorLog("给药途径不能为空")
  609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  610. return
  611. }
  612. timeNow := time.Now().Unix()
  613. drugway.Code = ""
  614. drugway.Status = 1
  615. drugway.CreatedTime = timeNow
  616. drugway.UpdatedTime = timeNow
  617. drugway.OrgId = adminUserInfo.CurrentOrgId
  618. drugway.Creator = adminUserInfo.AdminUser.Id
  619. err = service.CreateDrugWay(&drugway)
  620. if err != nil {
  621. utils.ErrorLog("%v", err)
  622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  623. return
  624. }
  625. c.ServeSuccessJSON(map[string]interface{}{
  626. "drugway": drugway,
  627. })
  628. return
  629. }
  630. func (c *DataApiController) UpdateDrugWay() {
  631. adminUserInfo := c.GetAdminUserInfo()
  632. id, _ := c.GetInt64("id", 0)
  633. if id <= 0 {
  634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  635. return
  636. }
  637. drugway, _ := service.FindDrugWay(adminUserInfo.CurrentOrgId, id)
  638. if drugway == nil {
  639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  640. return
  641. }
  642. var drugwaydata models.DrugwayDic
  643. err := json.Unmarshal(c.Ctx.Input.RequestBody, &drugwaydata)
  644. if err != nil {
  645. utils.ErrorLog("%v", err)
  646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  647. return
  648. }
  649. if drugwaydata.Name == "" {
  650. utils.ErrorLog("给药途径不能为空")
  651. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  652. return
  653. }
  654. timeNow := time.Now().Unix()
  655. drugway.UpdatedTime = timeNow
  656. drugway.Name = drugwaydata.Name
  657. err = service.UpdateDrugWay(drugway)
  658. if err != nil {
  659. utils.ErrorLog("%v", err)
  660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  661. return
  662. }
  663. c.ServeSuccessJSON(map[string]interface{}{
  664. "drugway": drugway,
  665. })
  666. return
  667. }
  668. func (c *DataApiController) DeleteDrugWay() {
  669. adminUserInfo := c.GetAdminUserInfo()
  670. id, _ := c.GetInt64("id", 0)
  671. if id <= 0 {
  672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  673. return
  674. }
  675. drugway, _ := service.FindDrugWay(adminUserInfo.CurrentOrgId, id)
  676. if drugway == nil {
  677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  678. return
  679. }
  680. timeNow := time.Now().Unix()
  681. drugway.UpdatedTime = timeNow
  682. drugway.Status = 2
  683. err := service.UpdateDrugWay(drugway)
  684. if err != nil {
  685. utils.ErrorLog("%v", err)
  686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  687. return
  688. }
  689. c.ServeSuccessJSON(map[string]interface{}{
  690. "msg": "ok",
  691. })
  692. return
  693. }
  694. func (c *DataApiController) CreateExecutionFrequency() {
  695. adminUserInfo := c.GetAdminUserInfo()
  696. var ef models.ExecutionFrequencyDic
  697. err := json.Unmarshal(c.Ctx.Input.RequestBody, &ef)
  698. if err != nil {
  699. utils.ErrorLog("%v", err)
  700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  701. return
  702. }
  703. if ef.Name == "" {
  704. utils.ErrorLog("执行频率不能为空")
  705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  706. return
  707. }
  708. timeNow := time.Now().Unix()
  709. ef.Code = ""
  710. ef.Status = 1
  711. ef.CreatedTime = timeNow
  712. ef.UpdatedTime = timeNow
  713. ef.OrgId = adminUserInfo.CurrentOrgId
  714. ef.Creator = adminUserInfo.AdminUser.Id
  715. err = service.CreateExecutionFrequency(&ef)
  716. if err != nil {
  717. utils.ErrorLog("%v", err)
  718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  719. return
  720. }
  721. c.ServeSuccessJSON(map[string]interface{}{
  722. "ef": ef,
  723. })
  724. return
  725. }
  726. func (c *DataApiController) UpdateExecutionFrequency() {
  727. adminUserInfo := c.GetAdminUserInfo()
  728. id, _ := c.GetInt64("id", 0)
  729. if id <= 0 {
  730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  731. return
  732. }
  733. ef, _ := service.FindExecutionFrequency(adminUserInfo.CurrentOrgId, id)
  734. if ef == nil {
  735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  736. return
  737. }
  738. var efdata models.ExecutionFrequencyDic
  739. err := json.Unmarshal(c.Ctx.Input.RequestBody, &efdata)
  740. if err != nil {
  741. utils.ErrorLog("%v", err)
  742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  743. return
  744. }
  745. if efdata.Name == "" {
  746. utils.ErrorLog("执行频率不能为空")
  747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  748. return
  749. }
  750. timeNow := time.Now().Unix()
  751. ef.UpdatedTime = timeNow
  752. ef.Name = efdata.Name
  753. err = service.UpdateExecutionFrequency(ef)
  754. if err != nil {
  755. utils.ErrorLog("%v", err)
  756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  757. return
  758. }
  759. c.ServeSuccessJSON(map[string]interface{}{
  760. "ef": ef,
  761. })
  762. return
  763. }
  764. func (c *DataApiController) DeleteExecutionFrequency() {
  765. adminUserInfo := c.GetAdminUserInfo()
  766. id, _ := c.GetInt64("id", 0)
  767. if id <= 0 {
  768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  769. return
  770. }
  771. ef, _ := service.FindExecutionFrequency(adminUserInfo.CurrentOrgId, id)
  772. if ef == nil {
  773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  774. return
  775. }
  776. timeNow := time.Now().Unix()
  777. ef.UpdatedTime = timeNow
  778. ef.Status = 2
  779. err := service.UpdateExecutionFrequency(ef)
  780. if err != nil {
  781. utils.ErrorLog("%v", err)
  782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  783. return
  784. }
  785. c.ServeSuccessJSON(map[string]interface{}{
  786. "msg": "ok",
  787. })
  788. return
  789. }
  790. func (c *DataApiController) CreateAdviceTemplate() {
  791. templateName := c.GetString("template_name")
  792. advice_type, _ := c.GetInt64("advice_type")
  793. sort, _ := c.GetInt64("sort")
  794. if templateName == "" {
  795. utils.ErrorLog("模版名称不能为空")
  796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  797. return
  798. }
  799. if advice_type < 0 {
  800. utils.ErrorLog("医嘱模版类型不能为空")
  801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceTypeWrong)
  802. return
  803. }
  804. adminUserInfo := c.GetAdminUserInfo()
  805. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  806. if appRole.UserType == 3 {
  807. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  808. if getPermissionErr != nil {
  809. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  810. return
  811. } else if headNursePermission == nil {
  812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  813. return
  814. }
  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. Sort: sort,
  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. sort, _ := this.GetInt64("sort")
  1174. if len(template_name) <= 0 {
  1175. utils.ErrorLog("模版名字不能为空")
  1176. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  1177. return
  1178. }
  1179. if template_id == 0 {
  1180. utils.ErrorLog("模版不存在")
  1181. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamTemplateNOEXISTWrong)
  1182. return
  1183. }
  1184. adminUserInfo := this.GetAdminUserInfo()
  1185. template, _ := service.FindParentTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1186. var err error
  1187. if template.Name == template_name {
  1188. err = service.ModifyTemplateNameOne(template_id, template_name, sort)
  1189. if err != nil {
  1190. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1191. return
  1192. }
  1193. } else {
  1194. //total := service.FindTemplateRecordByName(adminUserInfo.CurrentOrgId, template_name);
  1195. //if total > 0 {
  1196. // utils.ErrorLog("模版名称已经存在")
  1197. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNameWrong)
  1198. // return
  1199. //}
  1200. err = service.ModifyTemplateNameOne(template_id, template_name, sort)
  1201. if err != nil {
  1202. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1203. return
  1204. }
  1205. }
  1206. this.ServeSuccessJSON(map[string]interface{}{
  1207. "template_name": template_name,
  1208. "template_id": template_id,
  1209. })
  1210. }
  1211. func (this *DataApiController) ModifyFiledIsShow() {
  1212. id, _ := this.GetInt64("id", 0)
  1213. is_show, _ := this.GetInt("is_show", 0)
  1214. adminUserInfo := this.GetAdminUserInfo()
  1215. err := service.ShowFiledConfig(adminUserInfo.CurrentOrgId, is_show, id)
  1216. if err != nil {
  1217. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1218. return
  1219. } else {
  1220. this.ServeSuccessJSON(map[string]interface{}{
  1221. "id": id,
  1222. "is_show": is_show,
  1223. })
  1224. }
  1225. }
  1226. func (c *DataApiController) GetAllAdviceConfigs() {
  1227. adminUserInfo := c.GetAdminUserInfo()
  1228. var drugs []models.DrugDic
  1229. drugways, _, _ := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  1230. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  1231. adviceTemplates, _ := service.FindOtherAllAdviceTemplate(adminUserInfo.CurrentOrgId)
  1232. c.ServeSuccessJSON(map[string]interface{}{
  1233. "drugs": drugs,
  1234. "drugways": drugways,
  1235. "efs": efs,
  1236. "advice_templates": adviceTemplates,
  1237. })
  1238. }
  1239. func (c *DataApiController) GetHandleData() {
  1240. id, _ := c.GetInt64("id")
  1241. config, err := service.GetHandleData(id)
  1242. if err != nil {
  1243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1244. return
  1245. }
  1246. c.ServeSuccessJSON(map[string]interface{}{
  1247. "config": config,
  1248. })
  1249. }
  1250. func (c *DataApiController) UpdateDataTwo() {
  1251. id, _ := c.GetInt64("id")
  1252. //fmt.Print("id",id)
  1253. dataBody := make(map[string]interface{}, 0)
  1254. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1255. //fmt.Print("err",err)
  1256. //fmt.Print("id",id)
  1257. name := dataBody["name"].(string)
  1258. // fmt.Print("name",name)
  1259. order := int64(dataBody["order"].(float64))
  1260. // fmt.Print("order",order)
  1261. remake := dataBody["remark"].(string)
  1262. // fmt.Print("remake",remake)
  1263. configModel := models.ConfigViewModel{
  1264. Name: name,
  1265. Order: order,
  1266. Remark: remake,
  1267. }
  1268. err = service.UpdateDataTwo(id, configModel)
  1269. if err != nil {
  1270. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1271. return
  1272. }
  1273. c.ServeSuccessJSON(map[string]interface{}{
  1274. "configModel": configModel,
  1275. })
  1276. }
  1277. func (c *DataApiController) CreateHisAdviceTemplate() {
  1278. templateName := c.GetString("template_name")
  1279. advice_type, _ := c.GetInt64("advice_type")
  1280. if templateName == "" {
  1281. utils.ErrorLog("模版名称不能为空")
  1282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  1283. return
  1284. }
  1285. if advice_type < 0 {
  1286. utils.ErrorLog("医嘱模版类型不能为空")
  1287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceTypeWrong)
  1288. return
  1289. }
  1290. adminUserInfo := c.GetAdminUserInfo()
  1291. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1292. if appRole.UserType == 3 {
  1293. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1294. if getPermissionErr != nil {
  1295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1296. return
  1297. } else if headNursePermission == nil {
  1298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1299. return
  1300. }
  1301. }
  1302. template := &models.HisDoctorAdviceParentTemplate{
  1303. Name: templateName,
  1304. OrgId: adminUserInfo.CurrentOrgId,
  1305. Status: 1,
  1306. CreatedTime: time.Now().Unix(),
  1307. UpdatedTime: time.Now().Unix(),
  1308. AdviceType: advice_type,
  1309. }
  1310. createErr := service.CreateHisDoctorAdviceTemplate(template)
  1311. if createErr != nil {
  1312. utils.ErrorLog("%v", createErr)
  1313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1314. return
  1315. }
  1316. dataBody := make(map[string]interface{}, 0)
  1317. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1318. if err != nil {
  1319. utils.ErrorLog(err.Error())
  1320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1321. return
  1322. }
  1323. var subTemplate []*models.HisDoctorAdviceTemplate
  1324. if dataBody["data"] != nil && reflect.TypeOf(dataBody["data"]).String() == "[]interface {}" {
  1325. subTemp, _ := dataBody["data"].([]interface{})
  1326. if len(subTemp) > 0 {
  1327. for _, item := range subTemp {
  1328. items := item.(map[string]interface{})
  1329. if items["advice_name"] == nil || reflect.TypeOf(items["advice_name"]).String() != "string" {
  1330. utils.ErrorLog("advice_name")
  1331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1332. return
  1333. }
  1334. advice_name, _ := items["advice_name"].(string)
  1335. advice_desc, _ := items["advice_desc"].(string)
  1336. single_dose_unit, _ := items["single_dose_unit"].(string)
  1337. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  1338. delivery_way, _ := items["delivery_way"].(string)
  1339. execution_frequency, _ := items["execution_frequency"].(string)
  1340. drug_spec, _ := items["drug_spec"].(string)
  1341. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  1342. single_dose := items["single_dose"].(float64)
  1343. prescribing_number := items["prescribing_number"].(float64)
  1344. drug_id := int64(items["drug_id"].(float64))
  1345. subTemps := &models.HisDoctorAdviceTemplate{
  1346. AdviceName: advice_name,
  1347. Status: 1,
  1348. CreatedTime: time.Now().Unix(),
  1349. UpdatedTime: time.Now().Unix(),
  1350. OrgId: adminUserInfo.CurrentOrgId,
  1351. AdviceDesc: advice_desc,
  1352. AdviceType: advice_type,
  1353. SingleDoseUnit: single_dose_unit,
  1354. PrescribingNumber: prescribing_number,
  1355. PrescribingNumberUnit: prescribing_number_unit,
  1356. DeliveryWay: delivery_way,
  1357. ExecutionFrequency: execution_frequency,
  1358. TemplateId: template.ID,
  1359. DrugSpec: drug_spec,
  1360. DrugSpecUnit: drug_spec_unit,
  1361. SingleDose: single_dose,
  1362. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1363. DrugId: drug_id,
  1364. }
  1365. subTemplate = append(subTemplate, subTemps)
  1366. }
  1367. }
  1368. }
  1369. //errs := service.CreateBatchRecord(subTemplate)
  1370. errs := service.CreateHisSubDoctorAdviceTemplate(subTemplate)
  1371. if errs != nil {
  1372. utils.ErrorLog(errs.Error())
  1373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1374. return
  1375. }
  1376. templates, _ := service.FindHisDoctorAdviceTemplateById(template.ID, adminUserInfo.CurrentOrgId)
  1377. c.ServeSuccessJSON(map[string]interface{}{
  1378. "template": templates,
  1379. })
  1380. return
  1381. }
  1382. func (c *DataApiController) UpdateHisAdviceTemplate() {
  1383. adminUserInfo := c.GetAdminUserInfo()
  1384. id, _ := c.GetInt64("id", 0)
  1385. if id <= 0 {
  1386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1387. return
  1388. }
  1389. template, _ := service.FindHisAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  1390. if template == nil {
  1391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  1392. return
  1393. }
  1394. var templatedata models.HisDoctorAdviceTemplate
  1395. err := json.Unmarshal(c.Ctx.Input.RequestBody, &templatedata)
  1396. if err != nil {
  1397. utils.ErrorLog("%v", err)
  1398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1399. return
  1400. }
  1401. if templatedata.AdviceName == "" {
  1402. utils.ErrorLog("不能为空")
  1403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1404. return
  1405. }
  1406. timeNow := time.Now().Unix()
  1407. template.UpdatedTime = timeNow
  1408. template.AdviceName = templatedata.AdviceName
  1409. template.AdviceDesc = templatedata.AdviceDesc
  1410. template.SingleDose = templatedata.SingleDose
  1411. template.SingleDoseUnit = templatedata.SingleDoseUnit
  1412. template.PrescribingNumber = templatedata.PrescribingNumber
  1413. template.PrescribingNumberUnit = templatedata.PrescribingNumberUnit
  1414. template.DrugSpec = templatedata.DrugSpec
  1415. template.DrugSpecUnit = templatedata.DrugSpecUnit
  1416. template.DeliveryWay = templatedata.DeliveryWay
  1417. template.ExecutionFrequency = templatedata.ExecutionFrequency
  1418. template.DrugId = template.DrugId
  1419. err = service.UpdateHisAdviceTemplate(template)
  1420. if err != nil {
  1421. utils.ErrorLog("%v", err)
  1422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1423. return
  1424. }
  1425. c.ServeSuccessJSON(map[string]interface{}{
  1426. "template": template,
  1427. })
  1428. return
  1429. }
  1430. func (c *DataApiController) DeleteHisAdviceTemplate() {
  1431. adminUserInfo := c.GetAdminUserInfo()
  1432. parent_id, _ := c.GetInt64("parent_id", 0)
  1433. id, _ := c.GetInt64("id", 0)
  1434. if id <= 0 {
  1435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1436. return
  1437. }
  1438. template, _ := service.FindHisAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  1439. if template == nil {
  1440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  1441. return
  1442. }
  1443. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1444. //if appRole.UserType == 3 {
  1445. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1446. // if getPermissionErr != nil {
  1447. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1448. // return
  1449. // } else if headNursePermission == nil {
  1450. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1451. // return
  1452. // }
  1453. //}
  1454. timeNow := time.Now().Unix()
  1455. template.ID = id
  1456. template.UpdatedTime = timeNow
  1457. template.ParentId = parent_id
  1458. template.Status = 2
  1459. if parent_id > 0 { //删除子医嘱
  1460. err := service.UpdateHisAdviceTemplate(template)
  1461. if err != nil {
  1462. utils.ErrorLog("%v", err)
  1463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1464. return
  1465. }
  1466. } else { //删除该医嘱下的所有子医嘱
  1467. err := service.UpdateHisAdviceAndSubAdviceTemplate(template)
  1468. if err != nil {
  1469. utils.ErrorLog("%v", err)
  1470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1471. return
  1472. }
  1473. }
  1474. c.ServeSuccessJSON(map[string]interface{}{
  1475. "msg": "ok",
  1476. })
  1477. return
  1478. }
  1479. func (c *DataApiController) CreateSingleHisAdviceTemplate() {
  1480. drug_spec := c.GetString("drug_spec")
  1481. drug_spec_unit := c.GetString("drug_spec_unit")
  1482. advice_name := c.GetString("advice_name")
  1483. advice_desc := c.GetString("advice_desc")
  1484. single_dose, _ := c.GetFloat("single_dose", 0)
  1485. single_dose_unit := c.GetString("single_dose_unit")
  1486. prescribing_number, _ := c.GetFloat("prescribing_number", 0)
  1487. prescribing_number_unit := c.GetString("prescribing_number_unit")
  1488. delivery_way := c.GetString("delivery_way")
  1489. execution_frequency := c.GetString("execution_frequency")
  1490. template_id, _ := c.GetInt64("template_id", -1)
  1491. drug_id, _ := c.GetInt64("drug_id")
  1492. adminUserInfo := c.GetAdminUserInfo()
  1493. template := models.HisDoctorAdviceTemplate{
  1494. OrgId: adminUserInfo.CurrentOrgId,
  1495. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1496. Status: 1,
  1497. CreatedTime: time.Now().Unix(),
  1498. UpdatedTime: time.Now().Unix(),
  1499. DrugSpec: drug_spec,
  1500. DrugSpecUnit: drug_spec_unit,
  1501. AdviceName: advice_name,
  1502. AdviceDesc: advice_desc,
  1503. SingleDose: single_dose,
  1504. SingleDoseUnit: single_dose_unit,
  1505. PrescribingNumber: prescribing_number,
  1506. PrescribingNumberUnit: prescribing_number_unit,
  1507. DeliveryWay: delivery_way,
  1508. ExecutionFrequency: execution_frequency,
  1509. TemplateId: template_id,
  1510. DrugId: drug_id,
  1511. }
  1512. if template.AdviceName == "" {
  1513. utils.ErrorLog("医嘱名字不能为空")
  1514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
  1515. return
  1516. }
  1517. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1518. if appRole.UserType == 3 {
  1519. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1520. if getPermissionErr != nil {
  1521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1522. return
  1523. } else if headNursePermission == nil {
  1524. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1525. return
  1526. }
  1527. }
  1528. err := service.CreateHisAdviceTemplate(&template)
  1529. if err != nil {
  1530. utils.ErrorLog("%v", err)
  1531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1532. return
  1533. }
  1534. c.ServeSuccessJSON(map[string]interface{}{
  1535. "template": template,
  1536. })
  1537. return
  1538. }
  1539. func (c *DataApiController) DeleteHisParentAdviceTemplate() {
  1540. template_id, _ := c.GetInt64("template_id", 0)
  1541. adminUserInfo := c.GetAdminUserInfo()
  1542. _, err := service.FindParentHisTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1543. if err != nil {
  1544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1545. return
  1546. }
  1547. err1 := service.DeleteHisParentDoctorAdviceByTemplateId(template_id, adminUserInfo.CurrentOrgId)
  1548. if err1 != nil {
  1549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1550. return
  1551. }
  1552. c.ServeSuccessJSON(map[string]interface{}{
  1553. "msg": "删除成功",
  1554. })
  1555. }
  1556. func (this *DataApiController) ModifyHisTemplateName() {
  1557. template_name := this.GetString("template_name")
  1558. template_id, _ := this.GetInt64("template_id", 0)
  1559. if len(template_name) <= 0 {
  1560. utils.ErrorLog("模版名字不能为空")
  1561. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  1562. return
  1563. }
  1564. if template_id == 0 {
  1565. utils.ErrorLog("模版不存在")
  1566. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamTemplateNOEXISTWrong)
  1567. return
  1568. }
  1569. adminUserInfo := this.GetAdminUserInfo()
  1570. template, _ := service.FindParentHisTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1571. var err error
  1572. if template.Name == template_name {
  1573. err = service.ModifyTemplateName(template_id, template_name)
  1574. if err != nil {
  1575. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1576. return
  1577. }
  1578. } else {
  1579. err = service.ModifyHisTemplateName(template_id, template_name)
  1580. if err != nil {
  1581. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1582. return
  1583. }
  1584. }
  1585. this.ServeSuccessJSON(map[string]interface{}{
  1586. "template_name": template_name,
  1587. "template_id": template_id,
  1588. })
  1589. }
  1590. func (this *DataApiController) GetAllHisAdviceTemplate() {
  1591. adminUserInfo := this.GetAdminUserInfo()
  1592. drugs, _ := service.GetAllDrugLibs(adminUserInfo.CurrentOrgId)
  1593. drugways, _, _ := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  1594. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  1595. adviceTemplates, _ := service.FindHisAllAdviceTemplate(adminUserInfo.CurrentOrgId)
  1596. this.ServeSuccessJSON(map[string]interface{}{
  1597. "drugways": drugways,
  1598. "efs": efs,
  1599. "advice_templates": adviceTemplates,
  1600. "drugs": drugs,
  1601. })
  1602. }