data_api_controller.go 57KB

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