gobal_config_api_controller.go 50KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "bytes"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/jinzhu/gorm"
  11. "io/ioutil"
  12. "log"
  13. "os"
  14. "path"
  15. "reflect"
  16. "regexp"
  17. "runtime"
  18. "strconv"
  19. "strings"
  20. "time"
  21. "github.com/astaxie/beego"
  22. )
  23. type GobalConfigApiController struct {
  24. BaseAuthAPIController
  25. }
  26. func GobalConfigRegistRouters() {
  27. beego.Router("/api/stock/automaticreduce/isopen", &GobalConfigApiController{}, "post:PostStockConfig")
  28. beego.Router("/api/drugstock/automaticreduce/isopen", &GobalConfigApiController{}, "post:PostDrugStockConfig")
  29. beego.Router("/api/automaticreduce/get", &GobalConfigApiController{}, "get:GetConfig")
  30. beego.Router("/api/drugstockautomaticreduce/get", &GobalConfigApiController{}, "get:GetDrugStockConfig")
  31. beego.Router("/api/print/template/commit", &GobalConfigApiController{}, "post:PostPrintTemplateTwo")
  32. beego.Router("/api/print/template/get", &GobalConfigApiController{}, "get:GetPrintTemplate")
  33. beego.Router("/api/dataupload/config/commit", &GobalConfigApiController{}, "post:PostConfig")
  34. beego.Router("/api/dataupload/config/modify", &GobalConfigApiController{}, "post:ModifyConfig")
  35. beego.Router("/api/dataupload/config/get", &GobalConfigApiController{}, "get:GetDataUploadConfig")
  36. beego.Router("/api/dataupload/is_docking/get", &GobalConfigApiController{}, "get:GetDataUploadIsDocking")
  37. beego.Router("/api/adviceconfig/isopen", &GobalConfigApiController{}, "post:PostDoctorAdviceConfig")
  38. beego.Router("/api/adviceconfig/get", &GobalConfigApiController{}, "get:GetDoctorAdviceConfig")
  39. beego.Router("/api/advicetemplate/init/commit", &GobalConfigApiController{}, "post:PostInitAdviceTemplate")
  40. beego.Router("/api/advicetemplate/init/get", &GobalConfigApiController{}, "get:GetAdviceInitConfig")
  41. beego.Router("/api/systemprescription/commit", &GobalConfigApiController{}, "post:CreateSystemPrescription")
  42. beego.Router("/api/systemprescription/update", &GobalConfigApiController{}, "post:UpdateSystemPrescription")
  43. beego.Router("/api/systemprescription/all", &GobalConfigApiController{}, "get:GetAllSystemPrescription")
  44. beego.Router("/api/systemprescription/get", &GobalConfigApiController{}, "get:GetSystemPrescription")
  45. beego.Router("/api/advicetemplate/getprintinfo", &GobalConfigApiController{}, "post:GetPrintInfo")
  46. beego.Router("/api/public/orgs", &GobalConfigApiController{}, "get:GetOrgs")
  47. beego.Router("/api/org/change", &GobalConfigApiController{}, "post:ChangeOrg")
  48. beego.Router("/api/log/generate", &GobalConfigApiController{}, "get:GenerateLog")
  49. beego.Router("/api/patients/search", &GobalConfigApiController{}, "Post:GetPatientsByKeyWord")
  50. beego.Router("/api/xtconfig/get", &GobalConfigApiController{}, "get:GetXTHisConfig")
  51. beego.Router("/api/xtconfig/isopen", &GobalConfigApiController{}, "post:PostXTHisConfig")
  52. beego.Router("/api/isopen/init", &GobalConfigApiController{}, "get:GetAllIsOpenConfig")
  53. beego.Router("/api/passdetail/export", &GobalConfigApiController{}, "get:GetPassExportData")
  54. beego.Router("/api/consumedetail/export", &GobalConfigApiController{}, "get:GetExportData")
  55. beego.Router("/api/drugstock/getdrugindetail", &GobalConfigApiController{}, "get:GetDrugInDetail")
  56. beego.Router("/api/drugstock/getdrugcancelorder", &GobalConfigApiController{}, "get:GetDrugCancelOrder")
  57. beego.Router("/api/drugstock/getdrugoutdetail", &GobalConfigApiController{}, "get:GetDrugOutDetail")
  58. beego.Router("/api/drugstock/getdrugcanceldetail", &GobalConfigApiController{}, "get:GetDrugCancelDetail")
  59. }
  60. //provinces, _ := service.GetDistrictsByUpid(0)21
  61. func (c *GobalConfigApiController) PostStockConfig() {
  62. is_open, _ := c.GetInt64("is_open", 0)
  63. adminUserInfo := c.GetAdminUserInfo()
  64. org_id := adminUserInfo.CurrentOrgId
  65. config := models.GobalConfig{
  66. OrgId: org_id,
  67. IsOpen: is_open,
  68. Status: 1,
  69. CreateTime: time.Now().Unix(),
  70. UpdateTime: time.Now().Unix(),
  71. IsOpenRemind: 0,
  72. }
  73. errs, configs := service.FindAutomaticReduceRecordByOrgId(org_id)
  74. if errs == gorm.ErrRecordNotFound {
  75. err := service.CreateAutomaticReduceRecord(&config)
  76. if err != nil {
  77. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  78. return
  79. }
  80. } else if errs == nil {
  81. modifyConfig := models.GobalConfig{
  82. ID: configs.ID,
  83. OrgId: org_id,
  84. IsOpen: is_open,
  85. Status: 1,
  86. CreateTime: time.Now().Unix(),
  87. UpdateTime: time.Now().Unix(),
  88. IsOpenRemind: configs.IsOpenRemind,
  89. }
  90. err := service.UpdateAutomaticReduceRecord(&modifyConfig)
  91. if err != nil {
  92. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  93. return
  94. }
  95. }
  96. c.ServeSuccessJSON(map[string]interface{}{
  97. "is_open": is_open,
  98. })
  99. return
  100. }
  101. func (c *GobalConfigApiController) PostDrugStockConfig() {
  102. is_open, _ := c.GetInt64("is_open", 0)
  103. adminUserInfo := c.GetAdminUserInfo()
  104. org_id := adminUserInfo.CurrentOrgId
  105. config := models.DrugStockConfig{
  106. OrgId: org_id,
  107. IsOpen: is_open,
  108. Status: 1,
  109. CreateTime: time.Now().Unix(),
  110. UpdateTime: time.Now().Unix(),
  111. }
  112. errs, configs := service.FindDrugStockAutomaticReduceRecordByOrgId(org_id)
  113. if errs == gorm.ErrRecordNotFound {
  114. err := service.CreateDrugAutomaticReduceRecord(&config)
  115. if err != nil {
  116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  117. return
  118. }
  119. } else if errs == nil {
  120. modifyConfig := models.DrugStockConfig{
  121. ID: configs.ID,
  122. OrgId: org_id,
  123. IsOpen: is_open,
  124. Status: 1,
  125. CreateTime: time.Now().Unix(),
  126. UpdateTime: time.Now().Unix(),
  127. }
  128. err := service.UpdateDrugStockAutomaticReduceRecord(&modifyConfig)
  129. if err != nil {
  130. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  131. return
  132. }
  133. }
  134. c.ServeSuccessJSON(map[string]interface{}{
  135. "is_open": is_open,
  136. })
  137. return
  138. }
  139. func (c *GobalConfigApiController) GetConfig() {
  140. adminUserInfo := c.GetAdminUserInfo()
  141. _, config := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  142. c.ServeSuccessJSON(map[string]interface{}{
  143. "config": config,
  144. })
  145. }
  146. func (c *GobalConfigApiController) GetDrugStockConfig() {
  147. adminUserInfo := c.GetAdminUserInfo()
  148. _, config := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  149. c.ServeSuccessJSON(map[string]interface{}{
  150. "config": config,
  151. })
  152. }
  153. func (c *GobalConfigApiController) PostPrintTemplate() {
  154. template_id, _ := c.GetInt64("template_id", 0)
  155. adminUserInfo := c.GetAdminUserInfo()
  156. org_id := adminUserInfo.CurrentOrgId
  157. template := models.GobalTemplate{
  158. OrgId: org_id,
  159. TemplateId: template_id,
  160. Status: 1,
  161. Ctime: time.Now().Unix(),
  162. Mtime: time.Now().Unix(),
  163. }
  164. errs, templates := service.FindPrintTemplateByOrgId(org_id)
  165. if errs == gorm.ErrRecordNotFound {
  166. err := service.CreatePrintTemplateRecord(&template)
  167. if err != nil {
  168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  169. return
  170. }
  171. } else if errs == nil {
  172. templates := models.GobalTemplate{
  173. ID: templates.ID,
  174. OrgId: org_id,
  175. TemplateId: template_id,
  176. Status: 1,
  177. Ctime: templates.Ctime,
  178. Mtime: time.Now().Unix(),
  179. }
  180. err := service.UpdatePrintTemplate(&templates)
  181. if err != nil {
  182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  183. return
  184. }
  185. }
  186. c.ServeSuccessJSON(map[string]interface{}{
  187. "template_id": template_id,
  188. })
  189. return
  190. }
  191. func (c *GobalConfigApiController) PostPrintTemplateTwo() {
  192. template_id, _ := c.GetInt64("template_id", 0)
  193. adminUserInfo := c.GetAdminUserInfo()
  194. org_id := adminUserInfo.CurrentOrgId
  195. template := models.GobalTemplate{
  196. OrgId: org_id,
  197. TemplateId: template_id,
  198. Status: 1,
  199. Ctime: time.Now().Unix(),
  200. Mtime: time.Now().Unix(),
  201. }
  202. errs, templates := service.FindPrintTemplateByOrgId(org_id)
  203. if errs == gorm.ErrRecordNotFound {
  204. err := service.CreatePrintTemplateRecord(&template)
  205. if err != nil {
  206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  207. return
  208. }
  209. if err == nil { //处理模版切换,显示配置处理逻辑
  210. //service.FindAllConfig
  211. //先将所有数据设置为显示
  212. updateErr := service.UpdateFiledConfig(adminUserInfo.CurrentOrgId)
  213. if updateErr == nil {
  214. //查出该模版对应显示配置字段中所有隐藏的字段
  215. _, config := service.FindAllHideFiledConfig(template_id)
  216. var fileds []string
  217. for _, item := range config {
  218. fileds = append(fileds, item.FiledName)
  219. }
  220. service.UpdateShowFieldConfig(adminUserInfo.CurrentOrgId, fileds)
  221. }
  222. }
  223. FiledList, _ := service.FindFiledByOrgId(adminUserInfo.CurrentOrgId)
  224. c.ServeSuccessJSON(map[string]interface{}{
  225. "template_id": template_id,
  226. "fileds": FiledList,
  227. })
  228. } else if errs == nil {
  229. templates := models.GobalTemplate{
  230. ID: templates.ID,
  231. OrgId: org_id,
  232. TemplateId: template_id,
  233. Status: 1,
  234. Ctime: templates.Ctime,
  235. Mtime: time.Now().Unix(),
  236. }
  237. err := service.UpdatePrintTemplate(&templates)
  238. if err != nil {
  239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  240. return
  241. }
  242. if err == nil { //处理模版切换,显示配置处理逻辑
  243. //service.FindAllConfig
  244. //先将所有数据设置为显示
  245. updateErr := service.UpdateFiledConfig(adminUserInfo.CurrentOrgId)
  246. if updateErr == nil {
  247. //查出该模版对应显示配置字段中所有隐藏的字段
  248. _, config := service.FindAllHideFiledConfig(template_id)
  249. var fileds []string
  250. for _, item := range config {
  251. fileds = append(fileds, item.FiledName)
  252. }
  253. service.UpdateShowFieldConfig(adminUserInfo.CurrentOrgId, fileds)
  254. }
  255. }
  256. FiledList, _ := service.FindFiledByOrgId(adminUserInfo.CurrentOrgId)
  257. c.ServeSuccessJSON(map[string]interface{}{
  258. "template_id": template_id,
  259. "fileds": FiledList,
  260. })
  261. return
  262. }
  263. }
  264. func (c *GobalConfigApiController) GetPrintTemplate() {
  265. adminUserInfo := c.GetAdminUserInfo()
  266. _, template := service.FindPrintTemplateByOrgId(adminUserInfo.CurrentOrgId)
  267. c.ServeSuccessJSON(map[string]interface{}{
  268. "template": template,
  269. })
  270. }
  271. func (c *GobalConfigApiController) PostConfig() {
  272. gateway_address := c.GetString("gateway_address")
  273. app_id := c.GetString("app_id")
  274. key := c.GetString("key")
  275. config_type, _ := c.GetInt64("config_type")
  276. time_type, _ := c.GetInt64("time_type")
  277. province, _ := c.GetInt64("province")
  278. city, _ := c.GetInt64("city")
  279. if config_type > 1 {
  280. _, err := service.GetDockingStatus(config_type, province, city)
  281. if err == gorm.ErrRecordNotFound {
  282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotDocking)
  283. return
  284. }
  285. }
  286. adminUserInfo := c.GetAdminUserInfo()
  287. org_id := adminUserInfo.CurrentOrgId
  288. config := &models.DataUploadConfig{
  289. OrgId: org_id,
  290. ProvinceId: province,
  291. CityId: city,
  292. GatewayAddress: gateway_address,
  293. AppId: app_id,
  294. Key: key,
  295. Status: 1,
  296. CreateTime: time.Now().Unix(),
  297. ModifyTime: time.Now().Unix(),
  298. TimeQuantum: time_type,
  299. ConfigType: config_type,
  300. }
  301. err := service.CreateConfigData(config)
  302. if err == nil {
  303. c.ServeSuccessJSON(map[string]interface{}{
  304. "config": config,
  305. })
  306. } else {
  307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  308. return
  309. }
  310. }
  311. func (c *GobalConfigApiController) GetDataUploadConfig() {
  312. config_type, _ := c.GetInt64("config_type")
  313. adminUserInfo := c.GetAdminUserInfo()
  314. org_id := adminUserInfo.CurrentOrgId
  315. config, err := service.GetConfigData(org_id, config_type)
  316. fmt.Println(err)
  317. if err == nil {
  318. c.ServeSuccessJSON(map[string]interface{}{
  319. "config": config,
  320. })
  321. } else {
  322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  323. return
  324. }
  325. }
  326. func (c *GobalConfigApiController) GetDataUploadIsDocking() {
  327. config_type, _ := c.GetInt64("config_type")
  328. province, _ := c.GetInt64("province")
  329. city, _ := c.GetInt64("city")
  330. config, err := service.GetDockingStatus(config_type, province, city)
  331. fmt.Println(config)
  332. fmt.Println(err)
  333. if err == gorm.ErrRecordNotFound {
  334. c.ServeSuccessJSON(map[string]interface{}{
  335. "is_docking": 2,
  336. })
  337. } else if err == nil {
  338. if config.ID > 0 {
  339. c.ServeSuccessJSON(map[string]interface{}{
  340. "is_docking": 1,
  341. })
  342. } else {
  343. c.ServeSuccessJSON(map[string]interface{}{
  344. "is_docking": 2,
  345. })
  346. }
  347. }
  348. }
  349. func (c *GobalConfigApiController) ModifyConfig() {
  350. id, _ := c.GetInt64("id")
  351. gateway_address := c.GetString("gateway_address")
  352. app_id := c.GetString("app_id")
  353. key := c.GetString("key")
  354. config_type, _ := c.GetInt64("config_type")
  355. time_type, _ := c.GetInt64("time_type")
  356. province, _ := c.GetInt64("province")
  357. city, _ := c.GetInt64("city")
  358. adminUserInfo := c.GetAdminUserInfo()
  359. org_id := adminUserInfo.CurrentOrgId
  360. if config_type > 1 {
  361. _, err := service.GetDockingStatus(config_type, province, city)
  362. if err == gorm.ErrRecordNotFound {
  363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotDocking)
  364. return
  365. }
  366. }
  367. tempConfig, _ := service.GetConfigDataById(id)
  368. config := &models.DataUploadConfig{
  369. ID: tempConfig.ID,
  370. OrgId: org_id,
  371. ProvinceId: province,
  372. CityId: city,
  373. GatewayAddress: gateway_address,
  374. AppId: app_id,
  375. Key: key,
  376. Status: 1,
  377. CreateTime: tempConfig.CreateTime,
  378. ModifyTime: time.Now().Unix(),
  379. TimeQuantum: time_type,
  380. ConfigType: config_type,
  381. }
  382. err := service.SaveConfigData(config)
  383. if err == nil {
  384. c.ServeSuccessJSON(map[string]interface{}{
  385. "config": config,
  386. })
  387. } else {
  388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  389. return
  390. }
  391. }
  392. func (c *GobalConfigApiController) PostDoctorAdviceConfig() {
  393. is_open_remind, _ := c.GetInt64("is_open_remind", 0)
  394. adminUserInfo := c.GetAdminUserInfo()
  395. org_id := adminUserInfo.CurrentOrgId
  396. config := models.DoctorAdviceConfig{
  397. UserOrgId: org_id,
  398. IsOpenRemind: is_open_remind,
  399. Status: 1,
  400. CreateTime: time.Now().Unix(),
  401. UpdateTime: time.Now().Unix(),
  402. }
  403. errs, configs := service.FindDoctorAdviceRecordByOrgId(org_id)
  404. if errs == gorm.ErrRecordNotFound {
  405. err := service.CreateDoctorAdviceRecord(&config)
  406. if err != nil {
  407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  408. return
  409. }
  410. } else if errs == nil {
  411. modifyConfig := models.DoctorAdviceConfig{
  412. ID: configs.ID,
  413. UserOrgId: org_id,
  414. Status: 1,
  415. CreateTime: time.Now().Unix(),
  416. UpdateTime: time.Now().Unix(),
  417. IsOpenRemind: is_open_remind,
  418. }
  419. err := service.UpdateDoctorAdviceRecord(&modifyConfig)
  420. if err != nil {
  421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  422. return
  423. }
  424. }
  425. c.ServeSuccessJSON(map[string]interface{}{
  426. "is_open_remind": is_open_remind,
  427. })
  428. return
  429. }
  430. func (c *GobalConfigApiController) GetDoctorAdviceConfig() {
  431. adminUserInfo := c.GetAdminUserInfo()
  432. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  433. c.ServeSuccessJSON(map[string]interface{}{
  434. "config": config,
  435. })
  436. }
  437. //SF6090214798525
  438. func (c *GobalConfigApiController) Load(filename string, v interface{}) {
  439. //ReadFile函数会读取文件的全部内容,并将结果以[]byte类型返回
  440. data, err := ioutil.ReadFile(filename)
  441. if err != nil {
  442. return
  443. }
  444. //读取的数据为json格式,需要进行解码
  445. err = json.Unmarshal(data, v)
  446. if err != nil {
  447. return
  448. }
  449. }
  450. type Config struct {
  451. Parent_template []*models.VMDoctorAdviceParentTemplate "json:parent_template"
  452. }
  453. func LoadConfig(dataFile string) *Config {
  454. var config Config
  455. _, filename, _, _ := runtime.Caller(1)
  456. datapath := path.Join(path.Dir(filename), dataFile)
  457. config_file, err := os.Open(datapath)
  458. if err != nil {
  459. emit("Failed to open config file '%s': %s\n", datapath, err)
  460. return &config
  461. }
  462. fi, _ := config_file.Stat()
  463. buffer := make([]byte, fi.Size())
  464. _, err = config_file.Read(buffer)
  465. buffer, err = StripComments(buffer) //去掉注释
  466. if err != nil {
  467. emit("Failed to strip comments from json: %s\n", err)
  468. return &config
  469. }
  470. buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
  471. err = json.Unmarshal(buffer, &config) //解析json格式数据
  472. if err != nil {
  473. emit("Failed unmarshalling json: %s\n", err)
  474. return &config
  475. }
  476. return &config
  477. }
  478. func StripComments(data []byte) ([]byte, error) {
  479. data = bytes.Replace(data, []byte("\r"), []byte(""), 0) // Windows
  480. lines := bytes.Split(data, []byte("\n")) //split to muli lines
  481. filtered := make([][]byte, 0)
  482. for _, line := range lines {
  483. match, err := regexp.Match(`^\s*#`, line)
  484. if err != nil {
  485. return nil, err
  486. }
  487. if !match {
  488. filtered = append(filtered, line)
  489. }
  490. }
  491. return bytes.Join(filtered, []byte("\n")), nil
  492. }
  493. func emit(msgfmt string, args ...interface{}) {
  494. log.Printf(msgfmt, args...)
  495. }
  496. func (c *GobalConfigApiController) GetAdviceInitConfig() {
  497. adminUserInfo := c.GetAdminUserInfo()
  498. advice_init, _ := service.FindAdviceInitConfig(adminUserInfo.CurrentOrgId)
  499. c.ServeSuccessJSON(map[string]interface{}{
  500. "advice_init": advice_init,
  501. })
  502. }
  503. func (c *GobalConfigApiController) PostInitAdviceTemplate() {
  504. is_init, _ := c.GetInt64("is_init")
  505. adminUserInfo := c.GetAdminUserInfo()
  506. adviceInit := &models.AdviceInit{
  507. UserOrgId: adminUserInfo.CurrentOrgId,
  508. CreateTime: time.Now().Unix(),
  509. UpdateTime: time.Now().Unix(),
  510. Status: 1,
  511. IsInit: is_init,
  512. }
  513. adviceParentTemplate := LoadConfig("./advice_template.json").Parent_template
  514. for _, item := range adviceParentTemplate {
  515. parentTemplate := &models.DoctorAdviceParentTemplate{
  516. OrgId: adminUserInfo.CurrentOrgId,
  517. Name: item.Name,
  518. Status: 1,
  519. CreatedTime: time.Now().Unix(),
  520. UpdatedTime: time.Now().Unix(),
  521. AdviceType: item.AdviceType,
  522. }
  523. createErr := service.CreateDoctorParentTemplate(parentTemplate)
  524. fmt.Println(parentTemplate.ID)
  525. if createErr == nil {
  526. for _, adviceTemplateItem := range item.DoctorAdviceTemplate {
  527. adviceTeplate := &models.DoctorAdviceTemplate{
  528. OrgId: adminUserInfo.CurrentOrgId,
  529. AdviceName: adviceTemplateItem.AdviceName,
  530. AdviceDesc: adviceTemplateItem.AdviceDesc,
  531. SingleDose: adviceTemplateItem.SingleDose,
  532. SingleDoseUnit: adviceTemplateItem.SingleDoseUnit,
  533. PrescribingNumber: adviceTemplateItem.PrescribingNumber,
  534. PrescribingNumberUnit: adviceTemplateItem.PrescribingNumberUnit,
  535. DeliveryWay: adviceTemplateItem.DeliveryWay,
  536. ExecutionFrequency: adviceTemplateItem.ExecutionFrequency,
  537. AdviceDoctor: adviceTemplateItem.AdviceDoctor,
  538. Status: 1,
  539. CreatedTime: time.Now().Unix(),
  540. UpdatedTime: time.Now().Unix(),
  541. TemplateId: parentTemplate.ID,
  542. DrugSpec: adviceTemplateItem.DrugSpec,
  543. DrugSpecUnit: adviceTemplateItem.DrugSpecUnit,
  544. ParentId: adviceTemplateItem.ParentId,
  545. AdviceType: adviceTemplateItem.AdviceType,
  546. DayCount: adviceTemplateItem.DayCount,
  547. WeekDays: adviceTemplateItem.WeekDays,
  548. FrequencyType: adviceTemplateItem.FrequencyType,
  549. }
  550. createErr := service.CreateDoctorTemplate(adviceTeplate)
  551. if createErr == nil {
  552. for _, childItem := range adviceTemplateItem.SubDoctorAdviceTemplate {
  553. adviceTeplate := &models.DoctorAdviceTemplate{
  554. OrgId: adminUserInfo.CurrentOrgId,
  555. AdviceName: childItem.AdviceName,
  556. AdviceDesc: childItem.AdviceDesc,
  557. SingleDose: childItem.SingleDose,
  558. SingleDoseUnit: childItem.SingleDoseUnit,
  559. PrescribingNumber: childItem.PrescribingNumber,
  560. PrescribingNumberUnit: childItem.PrescribingNumberUnit,
  561. DeliveryWay: childItem.DeliveryWay,
  562. ExecutionFrequency: childItem.ExecutionFrequency,
  563. AdviceDoctor: childItem.AdviceDoctor,
  564. Status: 1,
  565. CreatedTime: time.Now().Unix(),
  566. UpdatedTime: time.Now().Unix(),
  567. TemplateId: parentTemplate.ID,
  568. DrugSpec: childItem.DrugSpec,
  569. DrugSpecUnit: childItem.DrugSpecUnit,
  570. ParentId: adviceTeplate.ID,
  571. AdviceType: childItem.AdviceType,
  572. DayCount: childItem.DayCount,
  573. WeekDays: childItem.WeekDays,
  574. FrequencyType: childItem.FrequencyType,
  575. }
  576. service.CreateDoctorTemplate(adviceTeplate)
  577. }
  578. }
  579. }
  580. }
  581. }
  582. err := service.CreateAdviceInitConfig(adviceInit)
  583. if err == nil {
  584. c.ServeSuccessJSON(map[string]interface{}{
  585. "init_config": adviceInit,
  586. })
  587. } else {
  588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  589. return
  590. }
  591. }
  592. func (c *GobalConfigApiController) CreateSystemPrescription() {
  593. adminUserInfo := c.GetAdminUserInfo()
  594. var solution models.SystemPrescription
  595. code := defaultSystemSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  596. if code > 0 {
  597. c.ServeFailJSONWithSGJErrorCode(code)
  598. return
  599. }
  600. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  601. solution.Doctor = adminUserInfo.AdminUser.Id
  602. solution.Status = 1
  603. solution.CreatedTime = time.Now().Unix()
  604. solution.UserOrgId = adminUserInfo.CurrentOrgId
  605. solution.UpdatedTime = time.Now().Unix()
  606. err := service.CreateSystemDialysisSolution(&solution)
  607. if err != nil {
  608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  609. return
  610. }
  611. prescriptions, _ := service.FindAllSystemPrescription(adminUserInfo.CurrentOrgId)
  612. c.ServeSuccessJSON(map[string]interface{}{
  613. "prescription": solution,
  614. "prescriptions": prescriptions,
  615. })
  616. return
  617. }
  618. func (c *GobalConfigApiController) UpdateSystemPrescription() {
  619. id, _ := c.GetInt64("id", 0)
  620. if id <= 0 {
  621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  622. return
  623. }
  624. adminUserInfo := c.GetAdminUserInfo()
  625. solution, _ := service.FindSystemDialysisSolution(adminUserInfo.CurrentOrgId, id)
  626. if solution.ID == 0 {
  627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  628. return
  629. }
  630. code := defaultSystemSolutionFormData(&solution, c.Ctx.Input.RequestBody, "edit")
  631. if code > 0 {
  632. c.ServeFailJSONWithSGJErrorCode(code)
  633. return
  634. }
  635. solution.UpdatedTime = time.Now().Unix()
  636. solution.Doctor = adminUserInfo.AdminUser.Id
  637. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  638. err := service.UpdateSystemDialysisSolution(&solution)
  639. if err != nil {
  640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  641. return
  642. }
  643. c.ServeSuccessJSON(map[string]interface{}{
  644. "msg": "ok",
  645. "prescription": solution,
  646. })
  647. return
  648. }
  649. func (c *GobalConfigApiController) GetAllSystemPrescription() {
  650. adminUserInfo := c.GetAdminUserInfo()
  651. prescriptions, _ := service.FindAllSystemPrescription(adminUserInfo.CurrentOrgId)
  652. stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
  653. c.ServeSuccessJSON(map[string]interface{}{
  654. "prescriptions": prescriptions,
  655. "stockType": stockType,
  656. })
  657. }
  658. func (c *GobalConfigApiController) GetSystemPrescription() {
  659. adminUserInfo := c.GetAdminUserInfo()
  660. id, _ := c.GetInt64("id", 0)
  661. prescription, _ := service.FindSystemDialysisPrescriptionByMode(adminUserInfo.CurrentOrgId, id)
  662. c.ServeSuccessJSON(map[string]interface{}{
  663. "prescription": prescription,
  664. })
  665. }
  666. func defaultSystemSolutionFormData(solution *models.SystemPrescription, data []byte, method string) (code int) {
  667. dataBody := make(map[string]interface{}, 0)
  668. err := json.Unmarshal(data, &dataBody)
  669. utils.InfoLog(string(data))
  670. if err != nil {
  671. utils.ErrorLog(err.Error())
  672. code = enums.ErrorCodeParamWrong
  673. return
  674. }
  675. if method == "create" {
  676. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  677. utils.ErrorLog("mode")
  678. code = enums.ErrorCodeParamWrong
  679. return
  680. }
  681. mode := int64(dataBody["mode"].(float64))
  682. if mode <= 0 {
  683. utils.ErrorLog("mode <= 0")
  684. code = enums.ErrorCodeParamWrong
  685. return
  686. }
  687. solution.ModeId = mode
  688. }
  689. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  690. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  691. solution.DialysisDuration = dialysisDuration
  692. }
  693. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  694. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  695. solution.TargetUltrafiltration = targetUltrafiltration
  696. }
  697. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  698. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  699. solution.DialysateFormulation = dialysateFormulation
  700. }
  701. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  702. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  703. solution.DialysisDurationHour = int64(dialysisDurationHour)
  704. }
  705. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  706. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  707. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  708. }
  709. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  710. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  711. solution.HemodialysisMachine = hemodialysisMachine
  712. }
  713. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  714. dialyzer := int64(dataBody["dialyzer"].(float64))
  715. solution.Dialyzer = dialyzer
  716. }
  717. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  718. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  719. solution.PerfusionApparatus = perfusionApparatus
  720. }
  721. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  722. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  723. solution.BloodFlowVolume = bloodFlowVolume
  724. }
  725. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  726. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  727. solution.Dewater = dewater
  728. }
  729. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  730. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  731. solution.DisplaceLiqui = displaceLiqui
  732. }
  733. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  734. replacementWay := int64(dataBody["replacement_way"].(float64))
  735. solution.ReplacementWay = replacementWay
  736. }
  737. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  738. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  739. solution.Anticoagulant = anticoagulant
  740. }
  741. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  742. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  743. solution.AnticoagulantShouji = anticoagulantShouji
  744. }
  745. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  746. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  747. solution.AnticoagulantWeichi = anticoagulantWeichi
  748. }
  749. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  750. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  751. solution.AnticoagulantZongliang = anticoagulantZongliang
  752. }
  753. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  754. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  755. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  756. }
  757. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  758. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  759. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  760. }
  761. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  762. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  763. solution.Kalium = kalium
  764. }
  765. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  766. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  767. solution.Sodium = sodium
  768. }
  769. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  770. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  771. solution.Calcium = calcium
  772. }
  773. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  774. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  775. solution.Bicarbonate = bicarbonate
  776. }
  777. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  778. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  779. solution.Glucose = glucose
  780. }
  781. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  782. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  783. // solution.DryWeight = dryWeight
  784. // }
  785. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  786. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  787. solution.DialysateFlow = dialysateFlow
  788. }
  789. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  790. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  791. solution.DialysateTemperature = dialysateTemperature
  792. }
  793. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  794. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  795. solution.Conductivity = conductivity
  796. }
  797. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  798. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  799. solution.ReplacementTotal = replacementTotal
  800. }
  801. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  802. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  803. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  804. }
  805. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  806. body_fluid := int64(dataBody["body_fluid"].(float64))
  807. solution.BodyFluid = body_fluid
  808. }
  809. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  810. body_fluid_other := dataBody["body_fluid_other"].(string)
  811. solution.BodyFluidOther = body_fluid_other
  812. }
  813. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  814. special_medicine := int64(dataBody["special_medicine"].(float64))
  815. solution.SpecialMedicine = special_medicine
  816. }
  817. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  818. special_medicine_other := dataBody["special_medicine_other"].(string)
  819. solution.SpecialMedicineOther = special_medicine_other
  820. }
  821. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  822. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  823. solution.DisplaceLiquiPart = displace_liqui_part
  824. }
  825. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  826. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  827. solution.DisplaceLiquiValue = displace_liqui_value
  828. }
  829. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  830. blood_access := int64(dataBody["blood_access"].(float64))
  831. solution.BloodAccess = blood_access
  832. }
  833. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  834. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  835. solution.Ultrafiltration = ultrafiltration
  836. }
  837. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  838. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  839. solution.TargetKtv = target_ktv
  840. }
  841. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  842. remark := dataBody["remark"].(string)
  843. solution.Remark = remark
  844. }
  845. if dataBody["dialysis_dialyszers"] != nil && reflect.TypeOf(dataBody["dialysis_dialyszers"]).String() == "string" {
  846. dialysisDialyszers := dataBody["dialysis_dialyszers"].(string)
  847. fmt.Println("dialysisDialysis22222222222", dialysisDialyszers)
  848. solution.DialysisDialyszers = dialysisDialyszers
  849. }
  850. if dataBody["dialysis_irrigation"] != nil && reflect.TypeOf(dataBody["dialysis_irrigation"]).String() == "string" {
  851. dialysisIrrigation := dataBody["dialysis_irrigation"].(string)
  852. solution.DialysisIrrigation = dialysisIrrigation
  853. }
  854. return
  855. }
  856. func (c *GobalConfigApiController) GetPrintInfo() {
  857. adminUserInfo := c.GetAdminUserInfo()
  858. OrgID := adminUserInfo.CurrentOrgId
  859. dataBody := make(map[string]interface{}, 0)
  860. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  861. idsInters := dataBody["ids"].([]interface{})
  862. if len(idsInters) == 0 {
  863. if err != nil {
  864. c.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)")
  865. return
  866. }
  867. }
  868. ids := make([]int64, 0)
  869. for _, idsInter := range idsInters {
  870. id := int64(idsInter.(float64))
  871. ids = append(ids, id)
  872. }
  873. getPrint, err := service.GetPrint(ids, OrgID)
  874. c.ServeSuccessJSON(map[string]interface{}{
  875. "doctoradvice": getPrint,
  876. })
  877. }
  878. func (c *GobalConfigApiController) GetOrgs() {
  879. adminUserInfo := c.GetAdminUserInfo()
  880. //获取当前人姓名
  881. var id = adminUserInfo.AdminUser.Id
  882. orgId := adminUserInfo.CurrentOrgId
  883. var orgs []*models.Org
  884. adminUser, err := service.GetHomeData(adminUserInfo.AdminUser.Id)
  885. creator, err := service.GetCreator(id, orgId)
  886. admin, err := service.GetSuperAdmin(id)
  887. if err != nil {
  888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  889. return
  890. }
  891. for _, item := range adminUser.Org {
  892. orgs = append(orgs, item)
  893. }
  894. for _, item := range adminUser.VMApp_Role {
  895. for _, subItem := range item.Org {
  896. orgs = append(orgs, subItem)
  897. }
  898. }
  899. orgs = RemoveRepeatedOrgElement(orgs)
  900. c.ServeSuccessJSON(map[string]interface{}{
  901. "orgs": orgs,
  902. "adminUser": adminUser,
  903. "creator": creator,
  904. "admin": admin,
  905. })
  906. }
  907. func (this *GobalConfigApiController) ChangeOrg() {
  908. org_id, _ := this.GetInt64("org_id")
  909. adminUserInfo := this.GetAdminUserInfo()
  910. tempOrg, err := service.GetOrgById(org_id)
  911. if err != nil {
  912. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  913. return
  914. }
  915. if tempOrg == nil {
  916. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrgNoExist)
  917. return
  918. }
  919. mobile := adminUserInfo.AdminUser.Mobile
  920. // 只取最近被创建的 admin_role
  921. adminUser, getAdminErr := service.GetValidAdminUserByMobileReturnErr(mobile) //账号信息唯一值
  922. if getAdminErr != nil {
  923. utils.ErrorLog("获取管理员失败:%v", getAdminErr)
  924. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  925. this.ServeJSON()
  926. return
  927. } else if adminUser == nil {
  928. utils.ErrorLog("查找不到 mobile = %v 的用户", mobile)
  929. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeAccountOrPasswordWrong)
  930. this.ServeJSON()
  931. return
  932. } else {
  933. adminUserInfo.CurrentOrgId = tempOrg.Id
  934. orgApp, _ := service.GetOrgApp(tempOrg.Id, 3)
  935. subscibe, _ := service.GetOrgSubscibe(tempOrg.Id)
  936. adminUserInfo.CurrentAppId = orgApp.Id
  937. appRole, _ := service.GetAppRole(tempOrg.Id, orgApp.Id, adminUserInfo.AdminUser.Id)
  938. var FiledList []*models.FiledConfig
  939. FiledList, _ = service.FindFiledByOrgId(tempOrg.Id)
  940. if len(FiledList) == 0 {
  941. err := service.BatchInsertFiledConfig(tempOrg.Id)
  942. if err == nil {
  943. FiledList, _ = service.FindFiledByOrgId(tempOrg.Id)
  944. } else {
  945. utils.ErrorLog("字段批量插入失败:%v", err)
  946. }
  947. }
  948. //产寻该机构是否有收缩压和舒张压
  949. pressure, err := service.GetDefaultSystolicPressure(tempOrg.Id)
  950. fmt.Println(err)
  951. if len(pressure) == 0 {
  952. err = service.BathInsertQualityControlTwo(tempOrg.Id)
  953. } else {
  954. utils.ErrorLog("字段批量插入失败:%v", err)
  955. }
  956. major, err := service.GetInspectionMajor(tempOrg.Id)
  957. if len(major) == 0 {
  958. QualityeList, err := service.FindQualityByOrgId(tempOrg.Id)
  959. if len(QualityeList) == 0 {
  960. err = service.BatchInsertQualityControl(tempOrg.Id)
  961. } else {
  962. utils.ErrorLog("字段批量插入失败:%v", err)
  963. }
  964. InspectionList, err := service.FindeInspectionByOrgId(tempOrg.Id)
  965. if len(InspectionList) == 0 {
  966. err = service.BatchInspectionConfiguration(tempOrg.Id)
  967. } else {
  968. utils.ErrorLog("字段批量插入失败:%v", err)
  969. }
  970. } else {
  971. utils.ErrorLog("字段批量插入失败:%v", err)
  972. }
  973. //查询该机构是否存在医护排班
  974. _, errcode := service.GetDoctorScheduleByOrgId(tempOrg.Id)
  975. //如果没有就插入
  976. if errcode == gorm.ErrRecordNotFound {
  977. err = service.BatchInsertDoctorSchedule(tempOrg.Id)
  978. } else {
  979. utils.ErrorLog("医护排班默认数据插入失败:%v", err)
  980. }
  981. var didRegistedForSCRM bool = false
  982. var didRegistedForCDM bool = false
  983. var didRegistedForMall bool = false
  984. var curAppUrlfors []string
  985. var pruviews []*models.Purview
  986. if len(curAppUrlfors) == 0 {
  987. if adminUser.Id == tempOrg.Creator {
  988. urlfors_xt, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(3)
  989. urlfors_cdm, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(4)
  990. urlfors_scrm, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(6)
  991. urlfors_mall, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(7)
  992. curAppUrlfors = append(curAppUrlfors, urlfors_xt...)
  993. curAppUrlfors = append(curAppUrlfors, urlfors_scrm...)
  994. curAppUrlfors = append(curAppUrlfors, urlfors_cdm...)
  995. curAppUrlfors = append(curAppUrlfors, urlfors_mall...)
  996. didRegistedForSCRM = true
  997. didRegistedForCDM = true
  998. didRegistedForMall = true
  999. } else {
  1000. appRole, _ := service.FindAdminUserIDA(appRole.Id)
  1001. if appRole.Id > 0 && len(appRole.RoleIds) > 0 {
  1002. role_arr := strings.Split(appRole.RoleIds, ",")
  1003. var ids string
  1004. for _, role_id := range role_arr {
  1005. id, _ := strconv.ParseInt(role_id, 10, 64)
  1006. purview_ids, _ := service.GetRolePurviewIds(id)
  1007. if len(ids) == 0 {
  1008. ids = purview_ids
  1009. } else {
  1010. ids = ids + "," + purview_ids
  1011. }
  1012. }
  1013. if len(ids) != 0 {
  1014. pruviews, _ = service.GetPurviewById(ids)
  1015. for _, item := range pruviews {
  1016. if item.Module == 3 && item.Parentid > 0 {
  1017. fmt.Println(item.Urlfor)
  1018. curAppUrlfors = append(curAppUrlfors, item.Urlfor)
  1019. }
  1020. }
  1021. } else {
  1022. curAppUrlfors = append(curAppUrlfors, "")
  1023. }
  1024. } else {
  1025. curAppUrlfors = append(curAppUrlfors, "")
  1026. }
  1027. for _, item := range pruviews {
  1028. if item.Module == 6 {
  1029. didRegistedForSCRM = true
  1030. }
  1031. if item.Module == 4 {
  1032. didRegistedForCDM = true
  1033. }
  1034. if item.Module == 7 {
  1035. didRegistedForMall = true
  1036. }
  1037. }
  1038. }
  1039. }
  1040. userInfo := map[string]interface{}{
  1041. "id": adminUser.Id,
  1042. "mobile": adminUser.Mobile,
  1043. "user_name": appRole.UserName,
  1044. "avatar": appRole.Avatar,
  1045. "intro": appRole.Intro,
  1046. "user_type": appRole.UserType,
  1047. "user_title": appRole.UserTitle,
  1048. }
  1049. org := map[string]interface{}{
  1050. "id": tempOrg.Id,
  1051. "org_name": tempOrg.OrgName,
  1052. "org_short_name": tempOrg.OrgShortName,
  1053. "org_intro": tempOrg.OrgIntroduction,
  1054. "org_logo": tempOrg.OrgLogo,
  1055. "province": tempOrg.Province,
  1056. "city": tempOrg.City,
  1057. "district": tempOrg.District,
  1058. "address": tempOrg.Address,
  1059. }
  1060. tempInfo, _ := service.GetOrgInfoTemplate(tempOrg.Id)
  1061. template_info := map[string]interface{}{
  1062. "id": tempInfo.ID,
  1063. "org_id": tempInfo.OrgId,
  1064. "template_id": tempInfo.TemplateId,
  1065. }
  1066. if tempOrg != nil && appRole != nil {
  1067. // 插入一条登录记录
  1068. ip := this.GetString("ip")
  1069. loginLog := &models.AdminUserLoginLog{
  1070. AdminUserId: adminUser.Id,
  1071. OrgId: tempOrg.Id,
  1072. AppId: appRole.AppId,
  1073. IP: ip,
  1074. OperateType: 3,
  1075. AppType: 3,
  1076. CreateTime: time.Now().Unix(),
  1077. }
  1078. if insertErr := service.InsertLoginLog(loginLog); insertErr != nil {
  1079. utils.ErrorLog("为手机号为%v的用户插入一条登录记录失败:%v", mobile, insertErr)
  1080. }
  1081. }
  1082. this.SetSession("admin_user_info", adminUserInfo)
  1083. this.ServeSuccessJSON(map[string]interface{}{
  1084. "user": userInfo,
  1085. "org": org,
  1086. "urlfors": curAppUrlfors,
  1087. "current_org_id": adminUserInfo.CurrentOrgId,
  1088. "current_app_id": adminUserInfo.CurrentAppId,
  1089. "subscibe": subscibe,
  1090. "template_info": template_info,
  1091. "fileds": FiledList,
  1092. "scrm_role_exist": didRegistedForSCRM,
  1093. "cdm_role_exist": didRegistedForCDM,
  1094. "mall_role_exist": didRegistedForMall,
  1095. })
  1096. }
  1097. }
  1098. func RemoveRepeatedOrgElement(orgs []*models.Org) (newOrgs []*models.Org) {
  1099. newOrgs = make([]*models.Org, 0)
  1100. for i := 0; i < len(orgs); i++ {
  1101. repeat := false
  1102. for j := i + 1; j < len(orgs); j++ {
  1103. if orgs[i].Id == orgs[j].Id {
  1104. repeat = true
  1105. break
  1106. }
  1107. }
  1108. if !repeat {
  1109. newOrgs = append(newOrgs, orgs[i])
  1110. }
  1111. }
  1112. return
  1113. }
  1114. func (this *GobalConfigApiController) GenerateLog() {
  1115. log_type, _ := this.GetInt64("log_type", 0)
  1116. logs, err := service.GetExportLogByType(this.GetAdminUserInfo().CurrentOrgId, log_type)
  1117. if err != nil {
  1118. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1119. return
  1120. }
  1121. this.ServeSuccessJSON(map[string]interface{}{
  1122. "logs": logs,
  1123. })
  1124. }
  1125. func (this *GobalConfigApiController) GetPatientsByKeyWord() {
  1126. keyWord := this.GetString("keyword")
  1127. adminUserInfo := this.GetAdminUserInfo()
  1128. patient, err := service.GetPatientsByKey(adminUserInfo.CurrentOrgId, keyWord)
  1129. if err != nil {
  1130. utils.ErrorLog(err.Error())
  1131. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1132. return
  1133. }
  1134. this.ServeSuccessJSON(map[string]interface{}{
  1135. "patient": patient,
  1136. })
  1137. }
  1138. func (c *GobalConfigApiController) PostXTHisConfig() {
  1139. is_open, _ := c.GetBool("is_open", false)
  1140. adminUserInfo := c.GetAdminUserInfo()
  1141. org_id := adminUserInfo.CurrentOrgId
  1142. isOpen := 0
  1143. if is_open {
  1144. isOpen = 1
  1145. } else {
  1146. isOpen = 2
  1147. }
  1148. config := models.XtHisConfig{
  1149. UserOrgId: org_id,
  1150. IsOpen: int64(isOpen),
  1151. Status: 1,
  1152. Ctime: time.Now().Unix(),
  1153. Mtime: time.Now().Unix(),
  1154. }
  1155. errs, configs := service.FindXTHisRecordByOrgId(org_id)
  1156. if errs == gorm.ErrRecordNotFound {
  1157. err := service.CreateXTHisRecord(&config)
  1158. if err != nil {
  1159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1160. return
  1161. }
  1162. } else if errs == nil {
  1163. modifyConfig := models.XtHisConfig{
  1164. ID: configs.ID,
  1165. UserOrgId: org_id,
  1166. Status: 1,
  1167. Ctime: time.Now().Unix(),
  1168. Mtime: time.Now().Unix(),
  1169. IsOpen: int64(isOpen),
  1170. }
  1171. err := service.UpdateXTHisRecord(&modifyConfig)
  1172. if err != nil {
  1173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1174. return
  1175. }
  1176. }
  1177. c.ServeSuccessJSON(map[string]interface{}{
  1178. "is_open": is_open,
  1179. })
  1180. return
  1181. }
  1182. func (c *GobalConfigApiController) GetXTHisConfig() {
  1183. adminUserInfo := c.GetAdminUserInfo()
  1184. _, config := service.FindXTHisRecordByOrgId(adminUserInfo.CurrentOrgId)
  1185. c.ServeSuccessJSON(map[string]interface{}{
  1186. "config": config,
  1187. })
  1188. }
  1189. func (c *GobalConfigApiController) GetAllIsOpenConfig() {
  1190. adminUserInfo := c.GetAdminUserInfo()
  1191. _, config := service.FindXTHisRecordByOrgId(adminUserInfo.CurrentOrgId)
  1192. c.ServeSuccessJSON(map[string]interface{}{
  1193. "is_open_xt_his": config.IsOpen,
  1194. })
  1195. }
  1196. func (c *GobalConfigApiController) GetPassExportData() {
  1197. }
  1198. func (c *GobalConfigApiController) GetExportData() {
  1199. start_time := c.GetString("start_time")
  1200. end_time := c.GetString("end_time")
  1201. timeLayout := "2006-01-02"
  1202. loc, _ := time.LoadLocation("Local")
  1203. var startTime int64
  1204. if len(start_time) > 0 {
  1205. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1206. if err != nil {
  1207. fmt.Println(err)
  1208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1209. return
  1210. }
  1211. startTime = theTime.Unix()
  1212. }
  1213. var endTime int64
  1214. if len(end_time) > 0 {
  1215. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1216. if err != nil {
  1217. utils.ErrorLog(err.Error())
  1218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1219. return
  1220. }
  1221. endTime = theTime.Unix()
  1222. }
  1223. adminInfo := c.GetAdminUserInfo()
  1224. order, _ := service.GetExportHisOrderList(adminInfo.CurrentOrgId, startTime, endTime)
  1225. c.ServeSuccessJSON(map[string]interface{}{
  1226. "order": order,
  1227. })
  1228. }
  1229. func (c *GobalConfigApiController) GetDrugInDetail() {
  1230. start_time := c.GetString("start_time")
  1231. end_time := c.GetString("end_time")
  1232. timeLayout := "2006-01-02"
  1233. loc, _ := time.LoadLocation("Local")
  1234. var startTime int64
  1235. if len(start_time) > 0 {
  1236. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1237. if err != nil {
  1238. fmt.Println(err)
  1239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1240. return
  1241. }
  1242. startTime = theTime.Unix()
  1243. }
  1244. var endTime int64
  1245. if len(end_time) > 0 {
  1246. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1247. if err != nil {
  1248. utils.ErrorLog(err.Error())
  1249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1250. return
  1251. }
  1252. endTime = theTime.Unix()
  1253. }
  1254. adminInfo := c.GetAdminUserInfo()
  1255. order_type, _ := c.GetInt64("order_type")
  1256. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1257. keyword := c.GetString("keyword")
  1258. page, _ := c.GetInt64("page")
  1259. limit, _ := c.GetInt64("limit")
  1260. detail, total, err := service.GetDrugInOrderDetail(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit)
  1261. if err != nil {
  1262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1263. return
  1264. }
  1265. c.ServeSuccessJSON(map[string]interface{}{
  1266. "detail": detail,
  1267. "total": total,
  1268. })
  1269. }
  1270. func (c *GobalConfigApiController) GetDrugCancelOrder() {
  1271. start_time := c.GetString("start_time")
  1272. end_time := c.GetString("end_time")
  1273. timeLayout := "2006-01-02"
  1274. loc, _ := time.LoadLocation("Local")
  1275. var startTime int64
  1276. if len(start_time) > 0 {
  1277. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1278. if err != nil {
  1279. fmt.Println(err)
  1280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1281. return
  1282. }
  1283. startTime = theTime.Unix()
  1284. }
  1285. var endTime int64
  1286. if len(end_time) > 0 {
  1287. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1288. if err != nil {
  1289. utils.ErrorLog(err.Error())
  1290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1291. return
  1292. }
  1293. endTime = theTime.Unix()
  1294. }
  1295. adminInfo := c.GetAdminUserInfo()
  1296. order_type, _ := c.GetInt64("order_type")
  1297. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1298. keyword := c.GetString("keyword")
  1299. limit, _ := c.GetInt64("limit")
  1300. page, _ := c.GetInt64("page")
  1301. order, total, err := service.GetDrugReturnOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, limit, page)
  1302. if err != nil {
  1303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1304. return
  1305. }
  1306. c.ServeSuccessJSON(map[string]interface{}{
  1307. "order": order,
  1308. "total": total,
  1309. })
  1310. }
  1311. func (c *GobalConfigApiController) GetDrugOutDetail() {
  1312. start_time := c.GetString("start_time")
  1313. end_time := c.GetString("end_time")
  1314. timeLayout := "2006-01-02"
  1315. loc, _ := time.LoadLocation("Local")
  1316. var startTime int64
  1317. if len(start_time) > 0 {
  1318. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1319. if err != nil {
  1320. fmt.Println(err)
  1321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1322. return
  1323. }
  1324. startTime = theTime.Unix()
  1325. }
  1326. var endTime int64
  1327. if len(end_time) > 0 {
  1328. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1329. if err != nil {
  1330. utils.ErrorLog(err.Error())
  1331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1332. return
  1333. }
  1334. endTime = theTime.Unix()
  1335. }
  1336. adminInfo := c.GetAdminUserInfo()
  1337. order_type, _ := c.GetInt64("order_type")
  1338. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1339. keyword := c.GetString("keyword")
  1340. limit, _ := c.GetInt64("limit")
  1341. page, _ := c.GetInt64("page")
  1342. order, total, err := service.GetDrugOutOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit)
  1343. if err != nil {
  1344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1345. return
  1346. }
  1347. c.ServeSuccessJSON(map[string]interface{}{
  1348. "order": order,
  1349. "total": total,
  1350. })
  1351. }
  1352. func (c *GobalConfigApiController) GetDrugCancelDetail() {
  1353. start_time := c.GetString("start_time")
  1354. end_time := c.GetString("end_time")
  1355. timeLayout := "2006-01-02"
  1356. loc, _ := time.LoadLocation("Local")
  1357. var startTime int64
  1358. if len(start_time) > 0 {
  1359. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1360. if err != nil {
  1361. fmt.Println(err)
  1362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1363. return
  1364. }
  1365. startTime = theTime.Unix()
  1366. }
  1367. var endTime int64
  1368. if len(end_time) > 0 {
  1369. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1370. if err != nil {
  1371. utils.ErrorLog(err.Error())
  1372. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1373. return
  1374. }
  1375. endTime = theTime.Unix()
  1376. }
  1377. adminInfo := c.GetAdminUserInfo()
  1378. order_type, _ := c.GetInt64("order_type")
  1379. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1380. keyword := c.GetString("keyword")
  1381. limit, _ := c.GetInt64("limit")
  1382. page, _ := c.GetInt64("page")
  1383. order, total, err := service.GetDrugCancelOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit)
  1384. if err != nil {
  1385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1386. return
  1387. }
  1388. c.ServeSuccessJSON(map[string]interface{}{
  1389. "order": order,
  1390. "total": total,
  1391. })
  1392. }