data_api_controller.go 58KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836
  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" || module == "dialysis_remark" || module == "catheter_operation" || module == "main_content" || module == "patient_case" || module == "tentative_diagnosis" || module == "diagnostic_basis" || module == "differential_diagnosis" || module == "treatment_plan" || module == "sick_history" || module == "befor_symptoms" {
  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 = 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. drugway.Bby01 = drugway.Bby01
  630. err = service.CreateDrugWay(&drugway)
  631. if err != nil {
  632. utils.ErrorLog("%v", err)
  633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  634. return
  635. }
  636. drugways_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_drugways"
  637. redis := service.RedisClient()
  638. defer redis.Close()
  639. redis.Set(drugways_keys, "", time.Second*60*60*18)
  640. c.ServeSuccessJSON(map[string]interface{}{
  641. "drugway": drugway,
  642. })
  643. return
  644. }
  645. func (c *DataApiController) UpdateDrugWay() {
  646. adminUserInfo := c.GetAdminUserInfo()
  647. id, _ := c.GetInt64("id", 0)
  648. if id <= 0 {
  649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  650. return
  651. }
  652. drugway, _ := service.FindDrugWay(adminUserInfo.CurrentOrgId, id)
  653. if drugway == nil {
  654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  655. return
  656. }
  657. var drugwaydata models.DrugwayDic
  658. err := json.Unmarshal(c.Ctx.Input.RequestBody, &drugwaydata)
  659. if err != nil {
  660. utils.ErrorLog("%v", err)
  661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  662. return
  663. }
  664. if drugwaydata.Name == "" {
  665. utils.ErrorLog("给药途径不能为空")
  666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  667. return
  668. }
  669. timeNow := time.Now().Unix()
  670. drugway.UpdatedTime = timeNow
  671. drugway.Code = drugwaydata.Code
  672. drugway.Name = drugwaydata.Name
  673. drugway.Bby01 = drugwaydata.Bby01
  674. err = service.UpdateDrugWay(drugway)
  675. if err != nil {
  676. utils.ErrorLog("%v", err)
  677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  678. return
  679. }
  680. drugways_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_drugways"
  681. redis := service.RedisClient()
  682. defer redis.Close()
  683. redis.Set(drugways_keys, "", time.Second*60*60*18)
  684. c.ServeSuccessJSON(map[string]interface{}{
  685. "drugway": drugway,
  686. })
  687. return
  688. }
  689. func (c *DataApiController) DeleteDrugWay() {
  690. adminUserInfo := c.GetAdminUserInfo()
  691. id, _ := c.GetInt64("id", 0)
  692. if id <= 0 {
  693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  694. return
  695. }
  696. drugway, _ := service.FindDrugWay(adminUserInfo.CurrentOrgId, id)
  697. if drugway == nil {
  698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  699. return
  700. }
  701. timeNow := time.Now().Unix()
  702. drugway.UpdatedTime = timeNow
  703. drugway.Status = 2
  704. err := service.UpdateDrugWay(drugway)
  705. if err != nil {
  706. utils.ErrorLog("%v", err)
  707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  708. return
  709. }
  710. drugways_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_drugways"
  711. redis := service.RedisClient()
  712. defer redis.Close()
  713. redis.Set(drugways_keys, "", time.Second*60*60*18)
  714. c.ServeSuccessJSON(map[string]interface{}{
  715. "msg": "ok",
  716. })
  717. return
  718. }
  719. func (c *DataApiController) CreateExecutionFrequency() {
  720. adminUserInfo := c.GetAdminUserInfo()
  721. var ef models.ExecutionFrequencyDic
  722. err := json.Unmarshal(c.Ctx.Input.RequestBody, &ef)
  723. if err != nil {
  724. utils.ErrorLog("%v", err)
  725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  726. return
  727. }
  728. if ef.Name == "" {
  729. utils.ErrorLog("执行频率不能为空")
  730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  731. return
  732. }
  733. timeNow := time.Now().Unix()
  734. ef.Status = 1
  735. ef.CreatedTime = timeNow
  736. ef.UpdatedTime = timeNow
  737. ef.OrgId = adminUserInfo.CurrentOrgId
  738. ef.Creator = adminUserInfo.AdminUser.Id
  739. err = service.CreateExecutionFrequency(&ef)
  740. if err != nil {
  741. utils.ErrorLog("%v", err)
  742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  743. return
  744. }
  745. efs_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_efs"
  746. redis := service.RedisClient()
  747. defer redis.Close()
  748. redis.Set(efs_keys, "", time.Second*60*60*18)
  749. c.ServeSuccessJSON(map[string]interface{}{
  750. "ef": ef,
  751. })
  752. return
  753. }
  754. func (c *DataApiController) UpdateExecutionFrequency() {
  755. adminUserInfo := c.GetAdminUserInfo()
  756. id, _ := c.GetInt64("id", 0)
  757. if id <= 0 {
  758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  759. return
  760. }
  761. ef, _ := service.FindExecutionFrequency(adminUserInfo.CurrentOrgId, id)
  762. if ef == nil {
  763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  764. return
  765. }
  766. var efdata models.ExecutionFrequencyDic
  767. err := json.Unmarshal(c.Ctx.Input.RequestBody, &efdata)
  768. if err != nil {
  769. utils.ErrorLog("%v", err)
  770. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  771. return
  772. }
  773. if efdata.Name == "" {
  774. utils.ErrorLog("执行频率不能为空")
  775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  776. return
  777. }
  778. timeNow := time.Now().Unix()
  779. ef.UpdatedTime = timeNow
  780. ef.Name = efdata.Name
  781. ef.Code = efdata.Code
  782. err = service.UpdateExecutionFrequency(ef)
  783. if err != nil {
  784. utils.ErrorLog("%v", err)
  785. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  786. return
  787. }
  788. efs_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_efs"
  789. redis := service.RedisClient()
  790. defer redis.Close()
  791. redis.Set(efs_keys, "", time.Second*60*60*18)
  792. c.ServeSuccessJSON(map[string]interface{}{
  793. "ef": ef,
  794. })
  795. return
  796. }
  797. func (c *DataApiController) DeleteExecutionFrequency() {
  798. adminUserInfo := c.GetAdminUserInfo()
  799. id, _ := c.GetInt64("id", 0)
  800. if id <= 0 {
  801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  802. return
  803. }
  804. ef, _ := service.FindExecutionFrequency(adminUserInfo.CurrentOrgId, id)
  805. if ef == nil {
  806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  807. return
  808. }
  809. timeNow := time.Now().Unix()
  810. ef.UpdatedTime = timeNow
  811. ef.Status = 2
  812. err := service.UpdateExecutionFrequency(ef)
  813. if err != nil {
  814. utils.ErrorLog("%v", err)
  815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  816. return
  817. }
  818. efs_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_efs"
  819. redis := service.RedisClient()
  820. defer redis.Close()
  821. redis.Set(efs_keys, "", time.Second*60*60*18)
  822. c.ServeSuccessJSON(map[string]interface{}{
  823. "msg": "ok",
  824. })
  825. return
  826. }
  827. func (c *DataApiController) CreateAdviceTemplate() {
  828. templateName := c.GetString("template_name")
  829. advice_type, _ := c.GetInt64("advice_type")
  830. sort, _ := c.GetInt64("sort")
  831. if templateName == "" {
  832. utils.ErrorLog("模版名称不能为空")
  833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  834. return
  835. }
  836. if advice_type < 0 {
  837. utils.ErrorLog("医嘱模版类型不能为空")
  838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceTypeWrong)
  839. return
  840. }
  841. adminUserInfo := c.GetAdminUserInfo()
  842. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  843. if appRole.UserType == 3 {
  844. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  845. if getPermissionErr != nil {
  846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  847. return
  848. } else if headNursePermission == nil {
  849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  850. return
  851. }
  852. }
  853. template := &models.DoctorAdviceParentTemplate{
  854. Name: templateName,
  855. OrgId: adminUserInfo.CurrentOrgId,
  856. Status: 1,
  857. CreatedTime: time.Now().Unix(),
  858. UpdatedTime: time.Now().Unix(),
  859. AdviceType: advice_type,
  860. Sort: sort,
  861. }
  862. createErr := service.CreateTemplate(template)
  863. if createErr != nil {
  864. utils.ErrorLog("%v", createErr)
  865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  866. return
  867. }
  868. dataBody := make(map[string]interface{}, 0)
  869. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  870. if err != nil {
  871. utils.ErrorLog(err.Error())
  872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  873. return
  874. }
  875. var subTemplate []*models.DoctorAdviceTemplate
  876. if dataBody["data"] != nil && reflect.TypeOf(dataBody["data"]).String() == "[]interface {}" {
  877. subTemp, _ := dataBody["data"].([]interface{})
  878. if len(subTemp) > 0 {
  879. for _, item := range subTemp {
  880. items := item.(map[string]interface{})
  881. if items["advice_name"] == nil || reflect.TypeOf(items["advice_name"]).String() != "string" {
  882. utils.ErrorLog("advice_name")
  883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  884. return
  885. }
  886. advice_name, _ := items["advice_name"].(string)
  887. advice_desc, _ := items["advice_desc"].(string)
  888. single_dose_unit, _ := items["single_dose_unit"].(string)
  889. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  890. delivery_way, _ := items["delivery_way"].(string)
  891. execution_frequency, _ := items["execution_frequency"].(string)
  892. drug_spec, _ := items["drug_spec"].(string)
  893. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  894. single_dose := items["single_dose"].(float64)
  895. prescribing_number := items["prescribing_number"].(float64)
  896. day_count, _ := strconv.ParseInt(items["day_count"].(string), 10, 64)
  897. weekdays := items["weekdays"].(string)
  898. frequency_type := int64(items["frequency_type"].(float64))
  899. drug_id := int64(items["drug_id"].(float64))
  900. way := int64(items["way"].(float64))
  901. subTemps := &models.DoctorAdviceTemplate{
  902. AdviceName: advice_name,
  903. Status: 1,
  904. CreatedTime: time.Now().Unix(),
  905. UpdatedTime: time.Now().Unix(),
  906. OrgId: adminUserInfo.CurrentOrgId,
  907. AdviceDesc: advice_desc,
  908. AdviceType: advice_type,
  909. SingleDoseUnit: single_dose_unit,
  910. PrescribingNumber: prescribing_number,
  911. PrescribingNumberUnit: prescribing_number_unit,
  912. DeliveryWay: delivery_way,
  913. ExecutionFrequency: execution_frequency,
  914. TemplateId: template.ID,
  915. DrugSpec: drug_spec,
  916. DrugSpecUnit: drug_spec_unit,
  917. SingleDose: single_dose,
  918. AdviceDoctor: adminUserInfo.AdminUser.Id,
  919. DayCount: day_count,
  920. WeekDays: weekdays,
  921. FrequencyType: frequency_type,
  922. Way: way,
  923. DrugId: drug_id,
  924. DrugNameId: 0,
  925. }
  926. subTemplate = append(subTemplate, subTemps)
  927. }
  928. }
  929. }
  930. //errs := service.CreateBatchRecord(subTemplate)
  931. errs := service.CreateSubTemplate(subTemplate)
  932. if errs != nil {
  933. utils.ErrorLog(errs.Error())
  934. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  935. return
  936. }
  937. templates, _ := service.FindDoctorAdviceTemplateById(template.ID, adminUserInfo.CurrentOrgId)
  938. c.ServeSuccessJSON(map[string]interface{}{
  939. "template": templates,
  940. })
  941. return
  942. }
  943. func (c *DataApiController) UpdateAdviceTemplate() {
  944. adminUserInfo := c.GetAdminUserInfo()
  945. id, _ := c.GetInt64("id", 0)
  946. if id <= 0 {
  947. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  948. return
  949. }
  950. template, _ := service.FindAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  951. if template == nil {
  952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  953. return
  954. }
  955. //TODO 根据路由来做权限
  956. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  957. //if appRole.UserType == 3 {
  958. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  959. // if getPermissionErr != nil {
  960. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  961. // return
  962. // } else if headNursePermission == nil {
  963. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  964. // return
  965. // }
  966. //}
  967. var templatedata models.DoctorAdviceTemplate
  968. err := json.Unmarshal(c.Ctx.Input.RequestBody, &templatedata)
  969. if err != nil {
  970. utils.ErrorLog("%v", err)
  971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  972. return
  973. }
  974. if templatedata.AdviceName == "" {
  975. utils.ErrorLog("不能为空")
  976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  977. return
  978. }
  979. timeNow := time.Now().Unix()
  980. template.UpdatedTime = timeNow
  981. template.AdviceName = templatedata.AdviceName
  982. template.AdviceDesc = templatedata.AdviceDesc
  983. template.SingleDose = templatedata.SingleDose
  984. template.SingleDoseUnit = templatedata.SingleDoseUnit
  985. template.PrescribingNumber = templatedata.PrescribingNumber
  986. template.PrescribingNumberUnit = templatedata.PrescribingNumberUnit
  987. template.DrugSpec = templatedata.DrugSpec
  988. template.DrugSpecUnit = templatedata.DrugSpecUnit
  989. template.DeliveryWay = templatedata.DeliveryWay
  990. template.ExecutionFrequency = templatedata.ExecutionFrequency
  991. template.FrequencyType = templatedata.FrequencyType
  992. template.DayCount = templatedata.DayCount
  993. template.WeekDays = templatedata.WeekDays
  994. template.DrugId = template.DrugId
  995. template.Way = template.Way
  996. err = service.UpdateAdviceTemplate(template)
  997. if err != nil {
  998. utils.ErrorLog("%v", err)
  999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1000. return
  1001. }
  1002. c.ServeSuccessJSON(map[string]interface{}{
  1003. "template": template,
  1004. })
  1005. return
  1006. }
  1007. func (c *DataApiController) DeleteAdviceTemplate() {
  1008. adminUserInfo := c.GetAdminUserInfo()
  1009. parent_id, _ := c.GetInt64("parent_id", 0)
  1010. id, _ := c.GetInt64("id", 0)
  1011. if id <= 0 {
  1012. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1013. return
  1014. }
  1015. template, _ := service.FindAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  1016. if template == nil {
  1017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  1018. return
  1019. }
  1020. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1021. //if appRole.UserType == 3 {
  1022. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1023. // if getPermissionErr != nil {
  1024. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1025. // return
  1026. // } else if headNursePermission == nil {
  1027. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1028. // return
  1029. // }
  1030. //}
  1031. timeNow := time.Now().Unix()
  1032. template.ID = id
  1033. template.UpdatedTime = timeNow
  1034. template.ParentId = parent_id
  1035. template.Status = 2
  1036. if parent_id > 0 { //删除子医嘱
  1037. err := service.UpdateAdviceTemplate(template)
  1038. if err != nil {
  1039. utils.ErrorLog("%v", err)
  1040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1041. return
  1042. }
  1043. } else { //删除该医嘱下的所有子医嘱
  1044. err := service.UpdateAdviceAndSubAdviceTemplate(template)
  1045. if err != nil {
  1046. utils.ErrorLog("%v", err)
  1047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1048. return
  1049. }
  1050. }
  1051. c.ServeSuccessJSON(map[string]interface{}{
  1052. "msg": "ok",
  1053. })
  1054. return
  1055. }
  1056. func (c *DataApiController) CreateSingleAdviceTemplate() {
  1057. drug_spec := c.GetString("drug_spec")
  1058. drug_spec_unit := c.GetString("drug_spec_unit")
  1059. advice_name := c.GetString("advice_name")
  1060. advice_desc := c.GetString("advice_desc")
  1061. single_dose, _ := c.GetFloat("single_dose", 0)
  1062. single_dose_unit := c.GetString("single_dose_unit")
  1063. prescribing_number, _ := c.GetFloat("prescribing_number", 0)
  1064. prescribing_number_unit := c.GetString("prescribing_number_unit")
  1065. delivery_way := c.GetString("delivery_way")
  1066. execution_frequency := c.GetString("execution_frequency")
  1067. template_id, _ := c.GetInt64("template_id", -1)
  1068. advice_type, _ := c.GetInt64("advice_type", -1)
  1069. frequency_type, _ := c.GetInt64("frequency_type", -1)
  1070. week_days := c.GetString("week_days")
  1071. day_count, _ := c.GetInt64("day_count", -1)
  1072. drug_id, _ := c.GetInt64("drug_id")
  1073. way, _ := c.GetInt64("way")
  1074. adminUserInfo := c.GetAdminUserInfo()
  1075. template := models.DoctorAdviceTemplate{
  1076. OrgId: adminUserInfo.CurrentOrgId,
  1077. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1078. AdviceType: advice_type,
  1079. FrequencyType: frequency_type,
  1080. WeekDays: week_days,
  1081. DayCount: day_count,
  1082. Status: 1,
  1083. CreatedTime: time.Now().Unix(),
  1084. UpdatedTime: time.Now().Unix(),
  1085. DrugSpec: drug_spec,
  1086. DrugSpecUnit: drug_spec_unit,
  1087. AdviceName: advice_name,
  1088. AdviceDesc: advice_desc,
  1089. SingleDose: single_dose,
  1090. SingleDoseUnit: service.TypeConversion02(single_dose_unit),
  1091. PrescribingNumber: prescribing_number,
  1092. PrescribingNumberUnit: prescribing_number_unit,
  1093. DeliveryWay: delivery_way,
  1094. ExecutionFrequency: execution_frequency,
  1095. TemplateId: template_id,
  1096. Way: way,
  1097. DrugId: drug_id,
  1098. }
  1099. if template.AdviceName == "" {
  1100. utils.ErrorLog("医嘱名字不能为空")
  1101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
  1102. return
  1103. }
  1104. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1105. if appRole.UserType == 3 {
  1106. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1107. if getPermissionErr != nil {
  1108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1109. return
  1110. } else if headNursePermission == nil {
  1111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1112. return
  1113. }
  1114. }
  1115. err := service.CreateAdviceTemplate(&template)
  1116. if err != nil {
  1117. utils.ErrorLog("%v", err)
  1118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1119. return
  1120. }
  1121. c.ServeSuccessJSON(map[string]interface{}{
  1122. "template": template,
  1123. })
  1124. return
  1125. }
  1126. func (c *DataApiController) DeleteParentAdviceTemplate() {
  1127. template_id, _ := c.GetInt64("template_id", 0)
  1128. adminUserInfo := c.GetAdminUserInfo()
  1129. _, err := service.FindParentTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1130. if err != nil {
  1131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1132. return
  1133. }
  1134. err1 := service.DeleteParentDoctorAdviceByTemplateId(template_id, adminUserInfo.CurrentOrgId)
  1135. if err1 != nil {
  1136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1137. return
  1138. }
  1139. c.ServeSuccessJSON(map[string]interface{}{
  1140. "msg": "删除成功",
  1141. })
  1142. }
  1143. func (c *DataApiController) CreateSubAdviceTemplate() {
  1144. drug_spec := c.GetString("drug_spec")
  1145. drug_spec_unit := c.GetString("drug_spec_unit")
  1146. advice_name := c.GetString("advice_name")
  1147. advice_desc := c.GetString("advice_desc")
  1148. single_dose, _ := c.GetFloat("single_dose", 0)
  1149. single_dose_unit := c.GetString("single_dose_unit")
  1150. prescribing_number, _ := c.GetFloat("prescribing_number", 0)
  1151. prescribing_number_unit := c.GetString("prescribing_number_unit")
  1152. delivery_way := c.GetString("delivery_way")
  1153. execution_frequency := c.GetString("execution_frequency")
  1154. template_id, _ := c.GetInt64("template_id", 0)
  1155. parent_id, _ := c.GetInt64("parent_id", 0)
  1156. drug_id, _ := c.GetInt64("drug_id")
  1157. way, _ := c.GetInt64("way")
  1158. adminUserInfo := c.GetAdminUserInfo()
  1159. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1160. if appRole.UserType == 3 {
  1161. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1162. if getPermissionErr != nil {
  1163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1164. return
  1165. } else if headNursePermission == nil {
  1166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1167. return
  1168. }
  1169. }
  1170. template := models.DoctorAdviceTemplate{
  1171. OrgId: adminUserInfo.CurrentOrgId,
  1172. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1173. Status: 1,
  1174. CreatedTime: time.Now().Unix(),
  1175. UpdatedTime: time.Now().Unix(),
  1176. DrugSpec: drug_spec,
  1177. DrugSpecUnit: drug_spec_unit,
  1178. AdviceName: advice_name,
  1179. AdviceDesc: advice_desc,
  1180. SingleDose: single_dose,
  1181. SingleDoseUnit: single_dose_unit,
  1182. PrescribingNumber: prescribing_number,
  1183. PrescribingNumberUnit: prescribing_number_unit,
  1184. DeliveryWay: delivery_way,
  1185. ExecutionFrequency: execution_frequency,
  1186. TemplateId: template_id,
  1187. ParentId: parent_id,
  1188. DrugId: drug_id,
  1189. Way: way,
  1190. }
  1191. if template.AdviceName == "" {
  1192. utils.ErrorLog("医嘱名字不能为空")
  1193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
  1194. return
  1195. }
  1196. err := service.CreateAdviceTemplate(&template)
  1197. if err != nil {
  1198. utils.ErrorLog("%v", err)
  1199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1200. return
  1201. }
  1202. c.ServeSuccessJSON(map[string]interface{}{
  1203. "template": template,
  1204. })
  1205. return
  1206. }
  1207. func (this *DataApiController) ModifyTemplateName() {
  1208. template_name := this.GetString("template_name")
  1209. template_id, _ := this.GetInt64("template_id", 0)
  1210. sort, _ := this.GetInt64("sort")
  1211. if len(template_name) <= 0 {
  1212. utils.ErrorLog("模版名字不能为空")
  1213. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  1214. return
  1215. }
  1216. if template_id == 0 {
  1217. utils.ErrorLog("模版不存在")
  1218. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamTemplateNOEXISTWrong)
  1219. return
  1220. }
  1221. adminUserInfo := this.GetAdminUserInfo()
  1222. template, _ := service.FindParentTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1223. var err error
  1224. if template.Name == template_name {
  1225. err = service.ModifyTemplateNameOne(template_id, template_name, sort)
  1226. if err != nil {
  1227. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1228. return
  1229. }
  1230. } else {
  1231. //total := service.FindTemplateRecordByName(adminUserInfo.CurrentOrgId, template_name);
  1232. //if total > 0 {
  1233. // utils.ErrorLog("模版名称已经存在")
  1234. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNameWrong)
  1235. // return
  1236. //}
  1237. err = service.ModifyTemplateNameOne(template_id, template_name, sort)
  1238. if err != nil {
  1239. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1240. return
  1241. }
  1242. }
  1243. this.ServeSuccessJSON(map[string]interface{}{
  1244. "template_name": template_name,
  1245. "template_id": template_id,
  1246. })
  1247. }
  1248. func (this *DataApiController) ModifyFiledIsShow() {
  1249. id, _ := this.GetInt64("id", 0)
  1250. is_show, _ := this.GetInt("is_show", 0)
  1251. is_write, _ := this.GetInt("is_write", 0)
  1252. adminUserInfo := this.GetAdminUserInfo()
  1253. err := service.ShowFiledConfig(adminUserInfo.CurrentOrgId, is_show, is_write, id)
  1254. if err != nil {
  1255. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1256. return
  1257. } else {
  1258. this.ServeSuccessJSON(map[string]interface{}{
  1259. "id": id,
  1260. "is_show": is_show,
  1261. "is_write": is_write,
  1262. })
  1263. }
  1264. }
  1265. func (c *DataApiController) GetAllAdviceConfigs() {
  1266. adminUserInfo := c.GetAdminUserInfo()
  1267. var drugs []models.DrugDic
  1268. drugways, _, _ := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  1269. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  1270. adviceTemplates, _ := service.FindOtherAllAdviceTemplate(adminUserInfo.CurrentOrgId)
  1271. c.ServeSuccessJSON(map[string]interface{}{
  1272. "drugs": drugs,
  1273. "drugways": drugways,
  1274. "efs": efs,
  1275. "advice_templates": adviceTemplates,
  1276. })
  1277. }
  1278. func (c *DataApiController) GetHandleData() {
  1279. id, _ := c.GetInt64("id")
  1280. config, err := service.GetHandleData(id)
  1281. if err != nil {
  1282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1283. return
  1284. }
  1285. c.ServeSuccessJSON(map[string]interface{}{
  1286. "config": config,
  1287. })
  1288. }
  1289. func (c *DataApiController) UpdateDataTwo() {
  1290. id, _ := c.GetInt64("id")
  1291. //fmt.Print("id",id)
  1292. dataBody := make(map[string]interface{}, 0)
  1293. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1294. //fmt.Print("err",err)
  1295. //fmt.Print("id",id)
  1296. name := dataBody["name"].(string)
  1297. // fmt.Print("name",name)
  1298. order := int64(dataBody["order"].(float64))
  1299. // fmt.Print("order",order)
  1300. remake := dataBody["remark"].(string)
  1301. // fmt.Print("remake",remake)
  1302. configModel := models.ConfigViewModel{
  1303. Name: name,
  1304. Order: order,
  1305. Remark: remake,
  1306. }
  1307. err = service.UpdateDataTwo(id, configModel)
  1308. if err != nil {
  1309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1310. return
  1311. }
  1312. c.ServeSuccessJSON(map[string]interface{}{
  1313. "configModel": configModel,
  1314. })
  1315. }
  1316. func (c *DataApiController) CreateHisAdviceTemplate() {
  1317. templateName := c.GetString("template_name")
  1318. advice_type, _ := c.GetInt64("advice_type")
  1319. if templateName == "" {
  1320. utils.ErrorLog("模版名称不能为空")
  1321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  1322. return
  1323. }
  1324. if advice_type < 0 {
  1325. utils.ErrorLog("医嘱模版类型不能为空")
  1326. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceTypeWrong)
  1327. return
  1328. }
  1329. adminUserInfo := c.GetAdminUserInfo()
  1330. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1331. if appRole.UserType == 3 {
  1332. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1333. if getPermissionErr != nil {
  1334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1335. return
  1336. } else if headNursePermission == nil {
  1337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1338. return
  1339. }
  1340. }
  1341. template := &models.HisDoctorAdviceParentTemplate{
  1342. Name: templateName,
  1343. OrgId: adminUserInfo.CurrentOrgId,
  1344. Status: 1,
  1345. CreatedTime: time.Now().Unix(),
  1346. UpdatedTime: time.Now().Unix(),
  1347. AdviceType: advice_type,
  1348. }
  1349. createErr := service.CreateHisDoctorAdviceTemplate(template)
  1350. if createErr != nil {
  1351. utils.ErrorLog("%v", createErr)
  1352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1353. return
  1354. }
  1355. dataBody := make(map[string]interface{}, 0)
  1356. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1357. if err != nil {
  1358. utils.ErrorLog(err.Error())
  1359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1360. return
  1361. }
  1362. var subTemplate []*models.HisDoctorAdviceTemplate
  1363. if dataBody["data"] != nil && reflect.TypeOf(dataBody["data"]).String() == "[]interface {}" {
  1364. subTemp, _ := dataBody["data"].([]interface{})
  1365. if len(subTemp) > 0 {
  1366. for _, item := range subTemp {
  1367. items := item.(map[string]interface{})
  1368. if items["advice_name"] == nil || reflect.TypeOf(items["advice_name"]).String() != "string" {
  1369. utils.ErrorLog("advice_name")
  1370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1371. return
  1372. }
  1373. advice_name, _ := items["advice_name"].(string)
  1374. advice_desc, _ := items["advice_desc"].(string)
  1375. single_dose_unit, _ := items["single_dose_unit"].(string)
  1376. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  1377. delivery_way, _ := items["delivery_way"].(string)
  1378. execution_frequency, _ := items["execution_frequency"].(string)
  1379. drug_spec, _ := items["drug_spec"].(string)
  1380. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  1381. single_dose := items["single_dose"].(float64)
  1382. prescribing_number := items["prescribing_number"].(float64)
  1383. drug_id := int64(items["drug_id"].(float64))
  1384. subTemps := &models.HisDoctorAdviceTemplate{
  1385. AdviceName: advice_name,
  1386. Status: 1,
  1387. CreatedTime: time.Now().Unix(),
  1388. UpdatedTime: time.Now().Unix(),
  1389. OrgId: adminUserInfo.CurrentOrgId,
  1390. AdviceDesc: advice_desc,
  1391. AdviceType: advice_type,
  1392. SingleDoseUnit: single_dose_unit,
  1393. PrescribingNumber: prescribing_number,
  1394. PrescribingNumberUnit: prescribing_number_unit,
  1395. DeliveryWay: delivery_way,
  1396. ExecutionFrequency: execution_frequency,
  1397. TemplateId: template.ID,
  1398. DrugSpec: drug_spec,
  1399. DrugSpecUnit: drug_spec_unit,
  1400. SingleDose: single_dose,
  1401. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1402. DrugId: drug_id,
  1403. }
  1404. subTemplate = append(subTemplate, subTemps)
  1405. }
  1406. }
  1407. }
  1408. //errs := service.CreateBatchRecord(subTemplate)
  1409. errs := service.CreateHisSubDoctorAdviceTemplate(subTemplate)
  1410. if errs != nil {
  1411. utils.ErrorLog(errs.Error())
  1412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1413. return
  1414. }
  1415. templates, _ := service.FindHisDoctorAdviceTemplateById(template.ID, adminUserInfo.CurrentOrgId)
  1416. c.ServeSuccessJSON(map[string]interface{}{
  1417. "template": templates,
  1418. })
  1419. return
  1420. }
  1421. func (c *DataApiController) UpdateHisAdviceTemplate() {
  1422. adminUserInfo := c.GetAdminUserInfo()
  1423. id, _ := c.GetInt64("id", 0)
  1424. if id <= 0 {
  1425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1426. return
  1427. }
  1428. template, _ := service.FindHisAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  1429. if template == nil {
  1430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  1431. return
  1432. }
  1433. var templatedata models.HisDoctorAdviceTemplate
  1434. err := json.Unmarshal(c.Ctx.Input.RequestBody, &templatedata)
  1435. if err != nil {
  1436. utils.ErrorLog("%v", err)
  1437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1438. return
  1439. }
  1440. if templatedata.AdviceName == "" {
  1441. utils.ErrorLog("不能为空")
  1442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1443. return
  1444. }
  1445. timeNow := time.Now().Unix()
  1446. template.UpdatedTime = timeNow
  1447. template.AdviceName = templatedata.AdviceName
  1448. template.AdviceDesc = templatedata.AdviceDesc
  1449. template.SingleDose = templatedata.SingleDose
  1450. template.SingleDoseUnit = templatedata.SingleDoseUnit
  1451. template.PrescribingNumber = templatedata.PrescribingNumber
  1452. template.PrescribingNumberUnit = templatedata.PrescribingNumberUnit
  1453. template.DrugSpec = templatedata.DrugSpec
  1454. template.DrugSpecUnit = templatedata.DrugSpecUnit
  1455. template.DeliveryWay = templatedata.DeliveryWay
  1456. template.ExecutionFrequency = templatedata.ExecutionFrequency
  1457. template.DrugId = template.DrugId
  1458. err = service.UpdateHisAdviceTemplate(template)
  1459. if err != nil {
  1460. utils.ErrorLog("%v", err)
  1461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1462. return
  1463. }
  1464. c.ServeSuccessJSON(map[string]interface{}{
  1465. "template": template,
  1466. })
  1467. return
  1468. }
  1469. func (c *DataApiController) DeleteHisAdviceTemplate() {
  1470. adminUserInfo := c.GetAdminUserInfo()
  1471. parent_id, _ := c.GetInt64("parent_id", 0)
  1472. id, _ := c.GetInt64("id", 0)
  1473. if id <= 0 {
  1474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1475. return
  1476. }
  1477. template, _ := service.FindHisAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  1478. if template == nil {
  1479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  1480. return
  1481. }
  1482. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1483. //if appRole.UserType == 3 {
  1484. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1485. // if getPermissionErr != nil {
  1486. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1487. // return
  1488. // } else if headNursePermission == nil {
  1489. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1490. // return
  1491. // }
  1492. //}
  1493. timeNow := time.Now().Unix()
  1494. template.ID = id
  1495. template.UpdatedTime = timeNow
  1496. template.ParentId = parent_id
  1497. template.Status = 2
  1498. if parent_id > 0 { //删除子医嘱
  1499. err := service.UpdateHisAdviceTemplate(template)
  1500. if err != nil {
  1501. utils.ErrorLog("%v", err)
  1502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1503. return
  1504. }
  1505. } else { //删除该医嘱下的所有子医嘱
  1506. err := service.UpdateHisAdviceAndSubAdviceTemplate(template)
  1507. if err != nil {
  1508. utils.ErrorLog("%v", err)
  1509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1510. return
  1511. }
  1512. }
  1513. c.ServeSuccessJSON(map[string]interface{}{
  1514. "msg": "ok",
  1515. })
  1516. return
  1517. }
  1518. func (c *DataApiController) CreateSingleHisAdviceTemplate() {
  1519. drug_spec := c.GetString("drug_spec")
  1520. drug_spec_unit := c.GetString("drug_spec_unit")
  1521. advice_name := c.GetString("advice_name")
  1522. advice_desc := c.GetString("advice_desc")
  1523. single_dose, _ := c.GetFloat("single_dose", 0)
  1524. single_dose_unit := c.GetString("single_dose_unit")
  1525. prescribing_number, _ := c.GetFloat("prescribing_number", 0)
  1526. prescribing_number_unit := c.GetString("prescribing_number_unit")
  1527. delivery_way := c.GetString("delivery_way")
  1528. execution_frequency := c.GetString("execution_frequency")
  1529. template_id, _ := c.GetInt64("template_id", -1)
  1530. drug_id, _ := c.GetInt64("drug_id")
  1531. adminUserInfo := c.GetAdminUserInfo()
  1532. template := models.HisDoctorAdviceTemplate{
  1533. OrgId: adminUserInfo.CurrentOrgId,
  1534. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1535. Status: 1,
  1536. CreatedTime: time.Now().Unix(),
  1537. UpdatedTime: time.Now().Unix(),
  1538. DrugSpec: drug_spec,
  1539. DrugSpecUnit: drug_spec_unit,
  1540. AdviceName: advice_name,
  1541. AdviceDesc: advice_desc,
  1542. SingleDose: single_dose,
  1543. SingleDoseUnit: single_dose_unit,
  1544. PrescribingNumber: prescribing_number,
  1545. PrescribingNumberUnit: prescribing_number_unit,
  1546. DeliveryWay: delivery_way,
  1547. ExecutionFrequency: execution_frequency,
  1548. TemplateId: template_id,
  1549. DrugId: drug_id,
  1550. }
  1551. if template.AdviceName == "" {
  1552. utils.ErrorLog("医嘱名字不能为空")
  1553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
  1554. return
  1555. }
  1556. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1557. if appRole.UserType == 3 {
  1558. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1559. if getPermissionErr != nil {
  1560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1561. return
  1562. } else if headNursePermission == nil {
  1563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1564. return
  1565. }
  1566. }
  1567. err := service.CreateHisAdviceTemplate(&template)
  1568. if err != nil {
  1569. utils.ErrorLog("%v", err)
  1570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1571. return
  1572. }
  1573. c.ServeSuccessJSON(map[string]interface{}{
  1574. "template": template,
  1575. })
  1576. return
  1577. }
  1578. func (c *DataApiController) DeleteHisParentAdviceTemplate() {
  1579. template_id, _ := c.GetInt64("template_id", 0)
  1580. adminUserInfo := c.GetAdminUserInfo()
  1581. _, err := service.FindParentHisTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1582. if err != nil {
  1583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1584. return
  1585. }
  1586. err1 := service.DeleteHisParentDoctorAdviceByTemplateId(template_id, adminUserInfo.CurrentOrgId)
  1587. if err1 != nil {
  1588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1589. return
  1590. }
  1591. c.ServeSuccessJSON(map[string]interface{}{
  1592. "msg": "删除成功",
  1593. })
  1594. }
  1595. func (this *DataApiController) ModifyHisTemplateName() {
  1596. template_name := this.GetString("template_name")
  1597. template_id, _ := this.GetInt64("template_id", 0)
  1598. if len(template_name) <= 0 {
  1599. utils.ErrorLog("模版名字不能为空")
  1600. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  1601. return
  1602. }
  1603. if template_id == 0 {
  1604. utils.ErrorLog("模版不存在")
  1605. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamTemplateNOEXISTWrong)
  1606. return
  1607. }
  1608. adminUserInfo := this.GetAdminUserInfo()
  1609. template, _ := service.FindParentHisTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1610. var err error
  1611. if template.Name == template_name {
  1612. err = service.ModifyTemplateName(template_id, template_name)
  1613. if err != nil {
  1614. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1615. return
  1616. }
  1617. } else {
  1618. err = service.ModifyHisTemplateName(template_id, template_name)
  1619. if err != nil {
  1620. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1621. return
  1622. }
  1623. }
  1624. this.ServeSuccessJSON(map[string]interface{}{
  1625. "template_name": template_name,
  1626. "template_id": template_id,
  1627. })
  1628. }
  1629. func (this *DataApiController) GetAllHisAdviceTemplate() {
  1630. adminUserInfo := this.GetAdminUserInfo()
  1631. drugs, _ := service.GetAllDrugLibs(adminUserInfo.CurrentOrgId)
  1632. drugways, _, _ := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  1633. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  1634. adviceTemplates, _ := service.FindHisAllAdviceTemplate(adminUserInfo.CurrentOrgId)
  1635. this.ServeSuccessJSON(map[string]interface{}{
  1636. "drugways": drugways,
  1637. "efs": efs,
  1638. "advice_templates": adviceTemplates,
  1639. "drugs": drugs,
  1640. })
  1641. }