data_api_controller.go 56KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794
  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. 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" {
  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. fmt.Println(templateName)
  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. //total := service.FindTemplateRecordByName(adminUserInfo.CurrentOrgId, templateName);
  817. //if total > 0 {
  818. // utils.ErrorLog("模版名称已经存在")
  819. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNameWrong)
  820. // return
  821. //}
  822. template := &models.DoctorAdviceParentTemplate{
  823. Name: templateName,
  824. OrgId: adminUserInfo.CurrentOrgId,
  825. Status: 1,
  826. CreatedTime: time.Now().Unix(),
  827. UpdatedTime: time.Now().Unix(),
  828. AdviceType: advice_type,
  829. }
  830. createErr := service.CreateTemplate(template)
  831. if createErr != nil {
  832. utils.ErrorLog("%v", createErr)
  833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  834. return
  835. }
  836. dataBody := make(map[string]interface{}, 0)
  837. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  838. if err != nil {
  839. utils.ErrorLog(err.Error())
  840. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  841. return
  842. }
  843. var subTemplate []*models.DoctorAdviceTemplate
  844. if dataBody["data"] != nil && reflect.TypeOf(dataBody["data"]).String() == "[]interface {}" {
  845. subTemp, _ := dataBody["data"].([]interface{})
  846. if len(subTemp) > 0 {
  847. for _, item := range subTemp {
  848. items := item.(map[string]interface{})
  849. if items["advice_name"] == nil || reflect.TypeOf(items["advice_name"]).String() != "string" {
  850. utils.ErrorLog("advice_name")
  851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  852. return
  853. }
  854. advice_name, _ := items["advice_name"].(string)
  855. advice_desc, _ := items["advice_desc"].(string)
  856. single_dose_unit, _ := items["single_dose_unit"].(string)
  857. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  858. delivery_way, _ := items["delivery_way"].(string)
  859. execution_frequency, _ := items["execution_frequency"].(string)
  860. drug_spec, _ := items["drug_spec"].(string)
  861. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  862. single_dose := items["single_dose"].(float64)
  863. prescribing_number := items["prescribing_number"].(float64)
  864. day_count, _ := strconv.ParseInt(items["day_count"].(string), 10, 64)
  865. weekdays := items["weekdays"].(string)
  866. frequency_type := int64(items["frequency_type"].(float64))
  867. drug_id := int64(items["drug_id"].(float64))
  868. way := int64(items["way"].(float64))
  869. subTemps := &models.DoctorAdviceTemplate{
  870. AdviceName: advice_name,
  871. Status: 1,
  872. CreatedTime: time.Now().Unix(),
  873. UpdatedTime: time.Now().Unix(),
  874. OrgId: adminUserInfo.CurrentOrgId,
  875. AdviceDesc: advice_desc,
  876. AdviceType: advice_type,
  877. SingleDoseUnit: single_dose_unit,
  878. PrescribingNumber: prescribing_number,
  879. PrescribingNumberUnit: prescribing_number_unit,
  880. DeliveryWay: delivery_way,
  881. ExecutionFrequency: execution_frequency,
  882. TemplateId: template.ID,
  883. DrugSpec: drug_spec,
  884. DrugSpecUnit: drug_spec_unit,
  885. SingleDose: single_dose,
  886. AdviceDoctor: adminUserInfo.AdminUser.Id,
  887. DayCount: day_count,
  888. WeekDays: weekdays,
  889. FrequencyType: frequency_type,
  890. Way: way,
  891. DrugId: drug_id,
  892. DrugNameId: 0,
  893. }
  894. subTemplate = append(subTemplate, subTemps)
  895. }
  896. }
  897. }
  898. //errs := service.CreateBatchRecord(subTemplate)
  899. errs := service.CreateSubTemplate(subTemplate)
  900. if errs != nil {
  901. utils.ErrorLog(errs.Error())
  902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  903. return
  904. }
  905. templates, _ := service.FindDoctorAdviceTemplateById(template.ID, adminUserInfo.CurrentOrgId)
  906. c.ServeSuccessJSON(map[string]interface{}{
  907. "template": templates,
  908. })
  909. return
  910. }
  911. func (c *DataApiController) UpdateAdviceTemplate() {
  912. adminUserInfo := c.GetAdminUserInfo()
  913. id, _ := c.GetInt64("id", 0)
  914. if id <= 0 {
  915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  916. return
  917. }
  918. template, _ := service.FindAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  919. if template == nil {
  920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  921. return
  922. }
  923. //TODO 根据路由来做权限
  924. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  925. //if appRole.UserType == 3 {
  926. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  927. // if getPermissionErr != nil {
  928. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  929. // return
  930. // } else if headNursePermission == nil {
  931. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  932. // return
  933. // }
  934. //}
  935. var templatedata models.DoctorAdviceTemplate
  936. err := json.Unmarshal(c.Ctx.Input.RequestBody, &templatedata)
  937. if err != nil {
  938. utils.ErrorLog("%v", err)
  939. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  940. return
  941. }
  942. if templatedata.AdviceName == "" {
  943. utils.ErrorLog("不能为空")
  944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  945. return
  946. }
  947. timeNow := time.Now().Unix()
  948. template.UpdatedTime = timeNow
  949. template.AdviceName = templatedata.AdviceName
  950. template.AdviceDesc = templatedata.AdviceDesc
  951. template.SingleDose = templatedata.SingleDose
  952. template.SingleDoseUnit = templatedata.SingleDoseUnit
  953. template.PrescribingNumber = templatedata.PrescribingNumber
  954. template.PrescribingNumberUnit = templatedata.PrescribingNumberUnit
  955. template.DrugSpec = templatedata.DrugSpec
  956. template.DrugSpecUnit = templatedata.DrugSpecUnit
  957. template.DeliveryWay = templatedata.DeliveryWay
  958. template.ExecutionFrequency = templatedata.ExecutionFrequency
  959. template.FrequencyType = templatedata.FrequencyType
  960. template.DayCount = templatedata.DayCount
  961. template.WeekDays = templatedata.WeekDays
  962. template.DrugId = template.DrugId
  963. template.Way = template.Way
  964. err = service.UpdateAdviceTemplate(template)
  965. if err != nil {
  966. utils.ErrorLog("%v", err)
  967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  968. return
  969. }
  970. c.ServeSuccessJSON(map[string]interface{}{
  971. "template": template,
  972. })
  973. return
  974. }
  975. func (c *DataApiController) DeleteAdviceTemplate() {
  976. adminUserInfo := c.GetAdminUserInfo()
  977. parent_id, _ := c.GetInt64("parent_id", 0)
  978. id, _ := c.GetInt64("id", 0)
  979. if id <= 0 {
  980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  981. return
  982. }
  983. template, _ := service.FindAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  984. if template == nil {
  985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  986. return
  987. }
  988. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  989. //if appRole.UserType == 3 {
  990. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  991. // if getPermissionErr != nil {
  992. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  993. // return
  994. // } else if headNursePermission == nil {
  995. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  996. // return
  997. // }
  998. //}
  999. timeNow := time.Now().Unix()
  1000. template.ID = id
  1001. template.UpdatedTime = timeNow
  1002. template.ParentId = parent_id
  1003. template.Status = 2
  1004. if parent_id > 0 { //删除子医嘱
  1005. err := service.UpdateAdviceTemplate(template)
  1006. if err != nil {
  1007. utils.ErrorLog("%v", err)
  1008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1009. return
  1010. }
  1011. } else { //删除该医嘱下的所有子医嘱
  1012. err := service.UpdateAdviceAndSubAdviceTemplate(template)
  1013. if err != nil {
  1014. utils.ErrorLog("%v", err)
  1015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1016. return
  1017. }
  1018. }
  1019. c.ServeSuccessJSON(map[string]interface{}{
  1020. "msg": "ok",
  1021. })
  1022. return
  1023. }
  1024. func (c *DataApiController) CreateSingleAdviceTemplate() {
  1025. drug_spec := c.GetString("drug_spec")
  1026. drug_spec_unit := c.GetString("drug_spec_unit")
  1027. advice_name := c.GetString("advice_name")
  1028. advice_desc := c.GetString("advice_desc")
  1029. single_dose, _ := c.GetFloat("single_dose", 0)
  1030. single_dose_unit := c.GetString("single_dose_unit")
  1031. prescribing_number, _ := c.GetFloat("prescribing_number", 0)
  1032. prescribing_number_unit := c.GetString("prescribing_number_unit")
  1033. delivery_way := c.GetString("delivery_way")
  1034. execution_frequency := c.GetString("execution_frequency")
  1035. template_id, _ := c.GetInt64("template_id", -1)
  1036. advice_type, _ := c.GetInt64("advice_type", -1)
  1037. frequency_type, _ := c.GetInt64("frequency_type", -1)
  1038. week_days := c.GetString("week_days")
  1039. day_count, _ := c.GetInt64("day_count", -1)
  1040. drug_id, _ := c.GetInt64("drug_id")
  1041. way, _ := c.GetInt64("way")
  1042. adminUserInfo := c.GetAdminUserInfo()
  1043. template := models.DoctorAdviceTemplate{
  1044. OrgId: adminUserInfo.CurrentOrgId,
  1045. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1046. AdviceType: advice_type,
  1047. FrequencyType: frequency_type,
  1048. WeekDays: week_days,
  1049. DayCount: day_count,
  1050. Status: 1,
  1051. CreatedTime: time.Now().Unix(),
  1052. UpdatedTime: time.Now().Unix(),
  1053. DrugSpec: drug_spec,
  1054. DrugSpecUnit: drug_spec_unit,
  1055. AdviceName: advice_name,
  1056. AdviceDesc: advice_desc,
  1057. SingleDose: single_dose,
  1058. SingleDoseUnit: single_dose_unit,
  1059. PrescribingNumber: prescribing_number,
  1060. PrescribingNumberUnit: prescribing_number_unit,
  1061. DeliveryWay: delivery_way,
  1062. ExecutionFrequency: execution_frequency,
  1063. TemplateId: template_id,
  1064. Way: way,
  1065. DrugId: drug_id,
  1066. }
  1067. if template.AdviceName == "" {
  1068. utils.ErrorLog("医嘱名字不能为空")
  1069. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
  1070. return
  1071. }
  1072. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1073. if appRole.UserType == 3 {
  1074. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1075. if getPermissionErr != nil {
  1076. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1077. return
  1078. } else if headNursePermission == nil {
  1079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1080. return
  1081. }
  1082. }
  1083. err := service.CreateAdviceTemplate(&template)
  1084. if err != nil {
  1085. utils.ErrorLog("%v", err)
  1086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1087. return
  1088. }
  1089. c.ServeSuccessJSON(map[string]interface{}{
  1090. "template": template,
  1091. })
  1092. return
  1093. }
  1094. func (c *DataApiController) DeleteParentAdviceTemplate() {
  1095. template_id, _ := c.GetInt64("template_id", 0)
  1096. adminUserInfo := c.GetAdminUserInfo()
  1097. _, err := service.FindParentTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1098. if err != nil {
  1099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1100. return
  1101. }
  1102. err1 := service.DeleteParentDoctorAdviceByTemplateId(template_id, adminUserInfo.CurrentOrgId)
  1103. if err1 != nil {
  1104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1105. return
  1106. }
  1107. c.ServeSuccessJSON(map[string]interface{}{
  1108. "msg": "删除成功",
  1109. })
  1110. }
  1111. func (c *DataApiController) CreateSubAdviceTemplate() {
  1112. drug_spec := c.GetString("drug_spec")
  1113. drug_spec_unit := c.GetString("drug_spec_unit")
  1114. advice_name := c.GetString("advice_name")
  1115. advice_desc := c.GetString("advice_desc")
  1116. single_dose, _ := c.GetFloat("single_dose", 0)
  1117. single_dose_unit := c.GetString("single_dose_unit")
  1118. prescribing_number, _ := c.GetFloat("prescribing_number", 0)
  1119. prescribing_number_unit := c.GetString("prescribing_number_unit")
  1120. delivery_way := c.GetString("delivery_way")
  1121. execution_frequency := c.GetString("execution_frequency")
  1122. template_id, _ := c.GetInt64("template_id", 0)
  1123. parent_id, _ := c.GetInt64("parent_id", 0)
  1124. drug_id, _ := c.GetInt64("drug_id")
  1125. way, _ := c.GetInt64("way")
  1126. adminUserInfo := c.GetAdminUserInfo()
  1127. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1128. if appRole.UserType == 3 {
  1129. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1130. if getPermissionErr != nil {
  1131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1132. return
  1133. } else if headNursePermission == nil {
  1134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1135. return
  1136. }
  1137. }
  1138. template := models.DoctorAdviceTemplate{
  1139. OrgId: adminUserInfo.CurrentOrgId,
  1140. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1141. Status: 1,
  1142. CreatedTime: time.Now().Unix(),
  1143. UpdatedTime: time.Now().Unix(),
  1144. DrugSpec: drug_spec,
  1145. DrugSpecUnit: drug_spec_unit,
  1146. AdviceName: advice_name,
  1147. AdviceDesc: advice_desc,
  1148. SingleDose: single_dose,
  1149. SingleDoseUnit: single_dose_unit,
  1150. PrescribingNumber: prescribing_number,
  1151. PrescribingNumberUnit: prescribing_number_unit,
  1152. DeliveryWay: delivery_way,
  1153. ExecutionFrequency: execution_frequency,
  1154. TemplateId: template_id,
  1155. ParentId: parent_id,
  1156. DrugId: drug_id,
  1157. Way: way,
  1158. }
  1159. if template.AdviceName == "" {
  1160. utils.ErrorLog("医嘱名字不能为空")
  1161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
  1162. return
  1163. }
  1164. err := service.CreateAdviceTemplate(&template)
  1165. if err != nil {
  1166. utils.ErrorLog("%v", err)
  1167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1168. return
  1169. }
  1170. c.ServeSuccessJSON(map[string]interface{}{
  1171. "template": template,
  1172. })
  1173. return
  1174. }
  1175. func (this *DataApiController) ModifyTemplateName() {
  1176. template_name := this.GetString("template_name")
  1177. template_id, _ := this.GetInt64("template_id", 0)
  1178. if len(template_name) <= 0 {
  1179. utils.ErrorLog("模版名字不能为空")
  1180. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  1181. return
  1182. }
  1183. if template_id == 0 {
  1184. utils.ErrorLog("模版不存在")
  1185. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamTemplateNOEXISTWrong)
  1186. return
  1187. }
  1188. adminUserInfo := this.GetAdminUserInfo()
  1189. template, _ := service.FindParentTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1190. var err error
  1191. if template.Name == template_name {
  1192. err = service.ModifyTemplateName(template_id, template_name)
  1193. if err != nil {
  1194. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1195. return
  1196. }
  1197. } else {
  1198. //total := service.FindTemplateRecordByName(adminUserInfo.CurrentOrgId, template_name);
  1199. //if total > 0 {
  1200. // utils.ErrorLog("模版名称已经存在")
  1201. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNameWrong)
  1202. // return
  1203. //}
  1204. err = service.ModifyTemplateName(template_id, template_name)
  1205. if err != nil {
  1206. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1207. return
  1208. }
  1209. }
  1210. this.ServeSuccessJSON(map[string]interface{}{
  1211. "template_name": template_name,
  1212. "template_id": template_id,
  1213. })
  1214. }
  1215. func (this *DataApiController) ModifyFiledIsShow() {
  1216. id, _ := this.GetInt64("id", 0)
  1217. is_show, _ := this.GetInt("is_show", 0)
  1218. adminUserInfo := this.GetAdminUserInfo()
  1219. err := service.ShowFiledConfig(adminUserInfo.CurrentOrgId, is_show, id)
  1220. if err != nil {
  1221. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1222. return
  1223. } else {
  1224. this.ServeSuccessJSON(map[string]interface{}{
  1225. "id": id,
  1226. "is_show": is_show,
  1227. })
  1228. }
  1229. }
  1230. func (c *DataApiController) GetAllAdviceConfigs() {
  1231. adminUserInfo := c.GetAdminUserInfo()
  1232. var drugs []models.DrugDic
  1233. drugways, _, _ := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  1234. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  1235. adviceTemplates, _ := service.FindOtherAllAdviceTemplate(adminUserInfo.CurrentOrgId)
  1236. c.ServeSuccessJSON(map[string]interface{}{
  1237. "drugs": drugs,
  1238. "drugways": drugways,
  1239. "efs": efs,
  1240. "advice_templates": adviceTemplates,
  1241. })
  1242. }
  1243. func (c *DataApiController) GetHandleData() {
  1244. id, _ := c.GetInt64("id")
  1245. config, err := service.GetHandleData(id)
  1246. if err != nil {
  1247. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1248. return
  1249. }
  1250. c.ServeSuccessJSON(map[string]interface{}{
  1251. "config": config,
  1252. })
  1253. }
  1254. func (c *DataApiController) UpdateDataTwo() {
  1255. id, _ := c.GetInt64("id")
  1256. //fmt.Print("id",id)
  1257. dataBody := make(map[string]interface{}, 0)
  1258. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1259. //fmt.Print("err",err)
  1260. //fmt.Print("id",id)
  1261. name := dataBody["name"].(string)
  1262. // fmt.Print("name",name)
  1263. order := int64(dataBody["order"].(float64))
  1264. // fmt.Print("order",order)
  1265. remake := dataBody["remark"].(string)
  1266. // fmt.Print("remake",remake)
  1267. configModel := models.ConfigViewModel{
  1268. Name: name,
  1269. Order: order,
  1270. Remark: remake,
  1271. }
  1272. err = service.UpdateDataTwo(id, configModel)
  1273. if err != nil {
  1274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1275. return
  1276. }
  1277. c.ServeSuccessJSON(map[string]interface{}{
  1278. "configModel": configModel,
  1279. })
  1280. }
  1281. func (c *DataApiController) CreateHisAdviceTemplate() {
  1282. templateName := c.GetString("template_name")
  1283. advice_type, _ := c.GetInt64("advice_type")
  1284. if templateName == "" {
  1285. utils.ErrorLog("模版名称不能为空")
  1286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  1287. return
  1288. }
  1289. if advice_type < 0 {
  1290. utils.ErrorLog("医嘱模版类型不能为空")
  1291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceTypeWrong)
  1292. return
  1293. }
  1294. adminUserInfo := c.GetAdminUserInfo()
  1295. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1296. if appRole.UserType == 3 {
  1297. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1298. if getPermissionErr != nil {
  1299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1300. return
  1301. } else if headNursePermission == nil {
  1302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1303. return
  1304. }
  1305. }
  1306. template := &models.HisDoctorAdviceParentTemplate{
  1307. Name: templateName,
  1308. OrgId: adminUserInfo.CurrentOrgId,
  1309. Status: 1,
  1310. CreatedTime: time.Now().Unix(),
  1311. UpdatedTime: time.Now().Unix(),
  1312. AdviceType: advice_type,
  1313. }
  1314. createErr := service.CreateHisDoctorAdviceTemplate(template)
  1315. if createErr != nil {
  1316. utils.ErrorLog("%v", createErr)
  1317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1318. return
  1319. }
  1320. dataBody := make(map[string]interface{}, 0)
  1321. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1322. if err != nil {
  1323. utils.ErrorLog(err.Error())
  1324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1325. return
  1326. }
  1327. var subTemplate []*models.HisDoctorAdviceTemplate
  1328. if dataBody["data"] != nil && reflect.TypeOf(dataBody["data"]).String() == "[]interface {}" {
  1329. subTemp, _ := dataBody["data"].([]interface{})
  1330. if len(subTemp) > 0 {
  1331. for _, item := range subTemp {
  1332. items := item.(map[string]interface{})
  1333. if items["advice_name"] == nil || reflect.TypeOf(items["advice_name"]).String() != "string" {
  1334. utils.ErrorLog("advice_name")
  1335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1336. return
  1337. }
  1338. advice_name, _ := items["advice_name"].(string)
  1339. advice_desc, _ := items["advice_desc"].(string)
  1340. single_dose_unit, _ := items["single_dose_unit"].(string)
  1341. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  1342. delivery_way, _ := items["delivery_way"].(string)
  1343. execution_frequency, _ := items["execution_frequency"].(string)
  1344. drug_spec, _ := items["drug_spec"].(string)
  1345. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  1346. single_dose := items["single_dose"].(float64)
  1347. prescribing_number := items["prescribing_number"].(float64)
  1348. drug_id := int64(items["drug_id"].(float64))
  1349. subTemps := &models.HisDoctorAdviceTemplate{
  1350. AdviceName: advice_name,
  1351. Status: 1,
  1352. CreatedTime: time.Now().Unix(),
  1353. UpdatedTime: time.Now().Unix(),
  1354. OrgId: adminUserInfo.CurrentOrgId,
  1355. AdviceDesc: advice_desc,
  1356. AdviceType: advice_type,
  1357. SingleDoseUnit: single_dose_unit,
  1358. PrescribingNumber: prescribing_number,
  1359. PrescribingNumberUnit: prescribing_number_unit,
  1360. DeliveryWay: delivery_way,
  1361. ExecutionFrequency: execution_frequency,
  1362. TemplateId: template.ID,
  1363. DrugSpec: drug_spec,
  1364. DrugSpecUnit: drug_spec_unit,
  1365. SingleDose: single_dose,
  1366. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1367. DrugId: drug_id,
  1368. }
  1369. subTemplate = append(subTemplate, subTemps)
  1370. }
  1371. }
  1372. }
  1373. //errs := service.CreateBatchRecord(subTemplate)
  1374. errs := service.CreateHisSubDoctorAdviceTemplate(subTemplate)
  1375. if errs != nil {
  1376. utils.ErrorLog(errs.Error())
  1377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1378. return
  1379. }
  1380. templates, _ := service.FindHisDoctorAdviceTemplateById(template.ID, adminUserInfo.CurrentOrgId)
  1381. c.ServeSuccessJSON(map[string]interface{}{
  1382. "template": templates,
  1383. })
  1384. return
  1385. }
  1386. func (c *DataApiController) UpdateHisAdviceTemplate() {
  1387. adminUserInfo := c.GetAdminUserInfo()
  1388. id, _ := c.GetInt64("id", 0)
  1389. if id <= 0 {
  1390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1391. return
  1392. }
  1393. template, _ := service.FindHisAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  1394. if template == nil {
  1395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  1396. return
  1397. }
  1398. var templatedata models.HisDoctorAdviceTemplate
  1399. err := json.Unmarshal(c.Ctx.Input.RequestBody, &templatedata)
  1400. if err != nil {
  1401. utils.ErrorLog("%v", err)
  1402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1403. return
  1404. }
  1405. if templatedata.AdviceName == "" {
  1406. utils.ErrorLog("不能为空")
  1407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1408. return
  1409. }
  1410. timeNow := time.Now().Unix()
  1411. template.UpdatedTime = timeNow
  1412. template.AdviceName = templatedata.AdviceName
  1413. template.AdviceDesc = templatedata.AdviceDesc
  1414. template.SingleDose = templatedata.SingleDose
  1415. template.SingleDoseUnit = templatedata.SingleDoseUnit
  1416. template.PrescribingNumber = templatedata.PrescribingNumber
  1417. template.PrescribingNumberUnit = templatedata.PrescribingNumberUnit
  1418. template.DrugSpec = templatedata.DrugSpec
  1419. template.DrugSpecUnit = templatedata.DrugSpecUnit
  1420. template.DeliveryWay = templatedata.DeliveryWay
  1421. template.ExecutionFrequency = templatedata.ExecutionFrequency
  1422. template.DrugId = template.DrugId
  1423. err = service.UpdateHisAdviceTemplate(template)
  1424. if err != nil {
  1425. utils.ErrorLog("%v", err)
  1426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1427. return
  1428. }
  1429. c.ServeSuccessJSON(map[string]interface{}{
  1430. "template": template,
  1431. })
  1432. return
  1433. }
  1434. func (c *DataApiController) DeleteHisAdviceTemplate() {
  1435. adminUserInfo := c.GetAdminUserInfo()
  1436. parent_id, _ := c.GetInt64("parent_id", 0)
  1437. id, _ := c.GetInt64("id", 0)
  1438. if id <= 0 {
  1439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1440. return
  1441. }
  1442. template, _ := service.FindHisAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  1443. if template == nil {
  1444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  1445. return
  1446. }
  1447. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1448. //if appRole.UserType == 3 {
  1449. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1450. // if getPermissionErr != nil {
  1451. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1452. // return
  1453. // } else if headNursePermission == nil {
  1454. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1455. // return
  1456. // }
  1457. //}
  1458. timeNow := time.Now().Unix()
  1459. template.ID = id
  1460. template.UpdatedTime = timeNow
  1461. template.ParentId = parent_id
  1462. template.Status = 2
  1463. if parent_id > 0 { //删除子医嘱
  1464. err := service.UpdateHisAdviceTemplate(template)
  1465. if err != nil {
  1466. utils.ErrorLog("%v", err)
  1467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1468. return
  1469. }
  1470. } else { //删除该医嘱下的所有子医嘱
  1471. err := service.UpdateHisAdviceAndSubAdviceTemplate(template)
  1472. if err != nil {
  1473. utils.ErrorLog("%v", err)
  1474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1475. return
  1476. }
  1477. }
  1478. c.ServeSuccessJSON(map[string]interface{}{
  1479. "msg": "ok",
  1480. })
  1481. return
  1482. }
  1483. func (c *DataApiController) CreateSingleHisAdviceTemplate() {
  1484. drug_spec := c.GetString("drug_spec")
  1485. drug_spec_unit := c.GetString("drug_spec_unit")
  1486. advice_name := c.GetString("advice_name")
  1487. advice_desc := c.GetString("advice_desc")
  1488. single_dose, _ := c.GetFloat("single_dose", 0)
  1489. single_dose_unit := c.GetString("single_dose_unit")
  1490. prescribing_number, _ := c.GetFloat("prescribing_number", 0)
  1491. prescribing_number_unit := c.GetString("prescribing_number_unit")
  1492. delivery_way := c.GetString("delivery_way")
  1493. execution_frequency := c.GetString("execution_frequency")
  1494. template_id, _ := c.GetInt64("template_id", -1)
  1495. drug_id, _ := c.GetInt64("drug_id")
  1496. adminUserInfo := c.GetAdminUserInfo()
  1497. template := models.HisDoctorAdviceTemplate{
  1498. OrgId: adminUserInfo.CurrentOrgId,
  1499. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1500. Status: 1,
  1501. CreatedTime: time.Now().Unix(),
  1502. UpdatedTime: time.Now().Unix(),
  1503. DrugSpec: drug_spec,
  1504. DrugSpecUnit: drug_spec_unit,
  1505. AdviceName: advice_name,
  1506. AdviceDesc: advice_desc,
  1507. SingleDose: single_dose,
  1508. SingleDoseUnit: single_dose_unit,
  1509. PrescribingNumber: prescribing_number,
  1510. PrescribingNumberUnit: prescribing_number_unit,
  1511. DeliveryWay: delivery_way,
  1512. ExecutionFrequency: execution_frequency,
  1513. TemplateId: template_id,
  1514. DrugId: drug_id,
  1515. }
  1516. if template.AdviceName == "" {
  1517. utils.ErrorLog("医嘱名字不能为空")
  1518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
  1519. return
  1520. }
  1521. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1522. if appRole.UserType == 3 {
  1523. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1524. if getPermissionErr != nil {
  1525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1526. return
  1527. } else if headNursePermission == nil {
  1528. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1529. return
  1530. }
  1531. }
  1532. err := service.CreateHisAdviceTemplate(&template)
  1533. if err != nil {
  1534. utils.ErrorLog("%v", err)
  1535. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1536. return
  1537. }
  1538. c.ServeSuccessJSON(map[string]interface{}{
  1539. "template": template,
  1540. })
  1541. return
  1542. }
  1543. func (c *DataApiController) DeleteHisParentAdviceTemplate() {
  1544. template_id, _ := c.GetInt64("template_id", 0)
  1545. adminUserInfo := c.GetAdminUserInfo()
  1546. _, err := service.FindParentHisTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1547. if err != nil {
  1548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1549. return
  1550. }
  1551. err1 := service.DeleteHisParentDoctorAdviceByTemplateId(template_id, adminUserInfo.CurrentOrgId)
  1552. if err1 != nil {
  1553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1554. return
  1555. }
  1556. c.ServeSuccessJSON(map[string]interface{}{
  1557. "msg": "删除成功",
  1558. })
  1559. }
  1560. func (this *DataApiController) ModifyHisTemplateName() {
  1561. template_name := this.GetString("template_name")
  1562. template_id, _ := this.GetInt64("template_id", 0)
  1563. if len(template_name) <= 0 {
  1564. utils.ErrorLog("模版名字不能为空")
  1565. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  1566. return
  1567. }
  1568. if template_id == 0 {
  1569. utils.ErrorLog("模版不存在")
  1570. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamTemplateNOEXISTWrong)
  1571. return
  1572. }
  1573. adminUserInfo := this.GetAdminUserInfo()
  1574. template, _ := service.FindParentHisTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1575. var err error
  1576. if template.Name == template_name {
  1577. err = service.ModifyTemplateName(template_id, template_name)
  1578. if err != nil {
  1579. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1580. return
  1581. }
  1582. } else {
  1583. err = service.ModifyHisTemplateName(template_id, template_name)
  1584. if err != nil {
  1585. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1586. return
  1587. }
  1588. }
  1589. this.ServeSuccessJSON(map[string]interface{}{
  1590. "template_name": template_name,
  1591. "template_id": template_id,
  1592. })
  1593. }
  1594. func (this *DataApiController) GetAllHisAdviceTemplate() {
  1595. adminUserInfo := this.GetAdminUserInfo()
  1596. drugs, _ := service.GetAllDrugLibs(adminUserInfo.CurrentOrgId)
  1597. drugways, _, _ := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  1598. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  1599. adviceTemplates, _ := service.FindHisAllAdviceTemplate(adminUserInfo.CurrentOrgId)
  1600. this.ServeSuccessJSON(map[string]interface{}{
  1601. "drugways": drugways,
  1602. "efs": efs,
  1603. "advice_templates": adviceTemplates,
  1604. "drugs": drugs,
  1605. })
  1606. }