data_api_controller.go 58KB

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