gobal_config_api_controller.go 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943
  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. "time"
  20. "github.com/astaxie/beego"
  21. )
  22. type GobalConfigApiController struct {
  23. BaseAuthAPIController
  24. }
  25. func GobalConfigRegistRouters() {
  26. beego.Router("/api/stock/automaticreduce/isopen", &GobalConfigApiController{}, "post:PostStockConfig")
  27. beego.Router("/api/automaticreduce/get", &GobalConfigApiController{}, "get:GetConfig")
  28. beego.Router("/api/print/template/commit", &GobalConfigApiController{}, "post:PostPrintTemplate")
  29. beego.Router("/api/print/template/get", &GobalConfigApiController{}, "get:GetPrintTemplate")
  30. beego.Router("/api/dataupload/config/commit", &GobalConfigApiController{}, "post:PostConfig")
  31. beego.Router("/api/dataupload/config/modify", &GobalConfigApiController{}, "post:ModifyConfig")
  32. beego.Router("/api/dataupload/config/get", &GobalConfigApiController{}, "get:GetDataUploadConfig")
  33. beego.Router("/api/dataupload/is_docking/get", &GobalConfigApiController{}, "get:GetDataUploadIsDocking")
  34. beego.Router("/api/adviceconfig/isopen", &GobalConfigApiController{}, "post:PostDoctorAdviceConfig")
  35. beego.Router("/api/adviceconfig/get", &GobalConfigApiController{}, "get:GetDoctorAdviceConfig")
  36. beego.Router("/api/advicetemplate/init/commit", &GobalConfigApiController{}, "post:PostInitAdviceTemplate")
  37. beego.Router("/api/advicetemplate/init/get", &GobalConfigApiController{}, "get:GetAdviceInitConfig")
  38. beego.Router("/api/systemprescription/commit", &GobalConfigApiController{}, "post:CreateSystemPrescription")
  39. beego.Router("/api/systemprescription/update", &GobalConfigApiController{}, "post:UpdateSystemPrescription")
  40. beego.Router("/api/systemprescription/all", &GobalConfigApiController{}, "get:GetAllSystemPrescription")
  41. beego.Router("/api/systemprescription/get", &GobalConfigApiController{}, "get:GetSystemPrescription")
  42. beego.Router("/api/advicetemplate/getprintinfo", &GobalConfigApiController{}, "post:GetPrintInfo")
  43. }
  44. //provinces, _ := service.GetDistrictsByUpid(0)21
  45. func (c *GobalConfigApiController) PostStockConfig() {
  46. is_open, _ := c.GetInt64("is_open", 0)
  47. adminUserInfo := c.GetAdminUserInfo()
  48. org_id := adminUserInfo.CurrentOrgId
  49. config := models.GobalConfig{
  50. OrgId: org_id,
  51. IsOpen: is_open,
  52. Status: 1,
  53. CreateTime: time.Now().Unix(),
  54. UpdateTime: time.Now().Unix(),
  55. IsOpenRemind: 0,
  56. }
  57. errs, configs := service.FindAutomaticReduceRecordByOrgId(org_id)
  58. if errs == gorm.ErrRecordNotFound {
  59. err := service.CreateAutomaticReduceRecord(&config)
  60. if err != nil {
  61. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  62. return
  63. }
  64. } else if errs == nil {
  65. modifyConfig := models.GobalConfig{
  66. ID: configs.ID,
  67. OrgId: org_id,
  68. IsOpen: is_open,
  69. Status: 1,
  70. CreateTime: time.Now().Unix(),
  71. UpdateTime: time.Now().Unix(),
  72. IsOpenRemind: configs.IsOpenRemind,
  73. }
  74. err := service.UpdateAutomaticReduceRecord(&modifyConfig)
  75. if err != nil {
  76. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  77. return
  78. }
  79. }
  80. c.ServeSuccessJSON(map[string]interface{}{
  81. "is_open": is_open,
  82. })
  83. return
  84. }
  85. func (c *GobalConfigApiController) GetConfig() {
  86. adminUserInfo := c.GetAdminUserInfo()
  87. _, config := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  88. c.ServeSuccessJSON(map[string]interface{}{
  89. "config": config,
  90. })
  91. }
  92. func (c *GobalConfigApiController) PostPrintTemplate() {
  93. template_id, _ := c.GetInt64("template_id", 0)
  94. adminUserInfo := c.GetAdminUserInfo()
  95. org_id := adminUserInfo.CurrentOrgId
  96. template := models.GobalTemplate{
  97. OrgId: org_id,
  98. TemplateId: template_id,
  99. Status: 1,
  100. Ctime: time.Now().Unix(),
  101. Mtime: time.Now().Unix(),
  102. }
  103. errs, templates := service.FindPrintTemplateByOrgId(org_id)
  104. if errs == gorm.ErrRecordNotFound {
  105. err := service.CreatePrintTemplateRecord(&template)
  106. if err != nil {
  107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  108. return
  109. }
  110. } else if errs == nil {
  111. templates := models.GobalTemplate{
  112. ID: templates.ID,
  113. OrgId: org_id,
  114. TemplateId: template_id,
  115. Status: 1,
  116. Ctime: templates.Ctime,
  117. Mtime: time.Now().Unix(),
  118. }
  119. err := service.UpdatePrintTemplate(&templates)
  120. if err != nil {
  121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  122. return
  123. }
  124. }
  125. c.ServeSuccessJSON(map[string]interface{}{
  126. "template_id": template_id,
  127. })
  128. return
  129. }
  130. //func (c *GobalConfigApiController) PostPrintTemplate() {
  131. // template_id, _ := c.GetInt64("template_id", 0)
  132. // adminUserInfo := c.GetAdminUserInfo()
  133. // org_id := adminUserInfo.CurrentOrgId
  134. // template := models.GobalTemplate{
  135. // OrgId: org_id,
  136. // TemplateId: template_id,
  137. // Status: 1,
  138. // Ctime: time.Now().Unix(),
  139. // Mtime: time.Now().Unix(),
  140. // }
  141. //
  142. // errs, templates := service.FindPrintTemplateByOrgId(org_id)
  143. //
  144. // if errs == gorm.ErrRecordNotFound {
  145. // err := service.CreatePrintTemplateRecord(&template)
  146. // if err != nil {
  147. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  148. // return
  149. // }
  150. //
  151. // //if err == nil { //处理模版切换,显示配置处理逻辑
  152. // // //service.FindAllConfig
  153. // // //先将所有数据设置为显示
  154. // // updateErr := service.UpdateFiledConfig(adminUserInfo.CurrentOrgId)
  155. // // if updateErr == nil {
  156. // // //查出该模版对应显示配置字段中所有隐藏的字段
  157. // // _, config := service.FindAllHideFiledConfig(template_id)
  158. // //
  159. // // var fileds []string
  160. // // for _, item := range config {
  161. // // fileds = append(fileds, item.FiledName)
  162. // // }
  163. // // service.UpdateShowFieldConfig(adminUserInfo.CurrentOrgId, fileds)
  164. // // }
  165. // //
  166. // //}
  167. // //FiledList, _ := service.FindFiledByOrgId(adminUserInfo.CurrentOrgId)
  168. // c.ServeSuccessJSON(map[string]interface{}{
  169. // "template_id": template_id,
  170. // //"fileds": FiledList,
  171. // })
  172. //
  173. // } else if errs == nil {
  174. // templates := models.GobalTemplate{
  175. // ID: templates.ID,
  176. // OrgId: org_id,
  177. // TemplateId: template_id,
  178. // Status: 1,
  179. // Ctime: templates.Ctime,
  180. // Mtime: time.Now().Unix(),
  181. // }
  182. //
  183. // err := service.UpdatePrintTemplate(&templates)
  184. // if err != nil {
  185. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  186. // return
  187. // }
  188. //
  189. // if err == nil { //处理模版切换,显示配置处理逻辑
  190. // //service.FindAllConfig
  191. // //先将所有数据设置为显示
  192. // updateErr := service.UpdateFiledConfig(adminUserInfo.CurrentOrgId)
  193. // if updateErr == nil {
  194. // //查出该模版对应显示配置字段中所有隐藏的字段
  195. // _, config := service.FindAllHideFiledConfig(template_id)
  196. // var fileds []string
  197. // for _, item := range config {
  198. // fileds = append(fileds, item.FiledName)
  199. // }
  200. // service.UpdateShowFieldConfig(adminUserInfo.CurrentOrgId, fileds)
  201. //
  202. // }
  203. //
  204. // }
  205. // FiledList, _ := service.FindFiledByOrgId(adminUserInfo.CurrentOrgId)
  206. // c.ServeSuccessJSON(map[string]interface{}{
  207. // "template_id": template_id,
  208. // "fileds": FiledList,
  209. // })
  210. // return
  211. // }
  212. //}
  213. func (c *GobalConfigApiController) GetPrintTemplate() {
  214. adminUserInfo := c.GetAdminUserInfo()
  215. _, template := service.FindPrintTemplateByOrgId(adminUserInfo.CurrentOrgId)
  216. c.ServeSuccessJSON(map[string]interface{}{
  217. "template": template,
  218. })
  219. }
  220. func (c *GobalConfigApiController) PostConfig() {
  221. gateway_address := c.GetString("gateway_address")
  222. app_id := c.GetString("app_id")
  223. key := c.GetString("key")
  224. config_type, _ := c.GetInt64("config_type")
  225. time_type, _ := c.GetInt64("time_type")
  226. province, _ := c.GetInt64("province")
  227. city, _ := c.GetInt64("city")
  228. if config_type > 1 {
  229. _, err := service.GetDockingStatus(config_type, province, city)
  230. if err == gorm.ErrRecordNotFound {
  231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotDocking)
  232. return
  233. }
  234. }
  235. adminUserInfo := c.GetAdminUserInfo()
  236. org_id := adminUserInfo.CurrentOrgId
  237. config := &models.DataUploadConfig{
  238. OrgId: org_id,
  239. ProvinceId: province,
  240. CityId: city,
  241. GatewayAddress: gateway_address,
  242. AppId: app_id,
  243. Key: key,
  244. Status: 1,
  245. CreateTime: time.Now().Unix(),
  246. ModifyTime: time.Now().Unix(),
  247. TimeQuantum: time_type,
  248. ConfigType: config_type,
  249. }
  250. err := service.CreateConfigData(config)
  251. if err == nil {
  252. c.ServeSuccessJSON(map[string]interface{}{
  253. "config": config,
  254. })
  255. } else {
  256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  257. return
  258. }
  259. }
  260. func (c *GobalConfigApiController) GetDataUploadConfig() {
  261. config_type, _ := c.GetInt64("config_type")
  262. adminUserInfo := c.GetAdminUserInfo()
  263. org_id := adminUserInfo.CurrentOrgId
  264. config, err := service.GetConfigData(org_id, config_type)
  265. fmt.Println(err)
  266. if err == nil {
  267. c.ServeSuccessJSON(map[string]interface{}{
  268. "config": config,
  269. })
  270. } else {
  271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  272. return
  273. }
  274. }
  275. func (c *GobalConfigApiController) GetDataUploadIsDocking() {
  276. config_type, _ := c.GetInt64("config_type")
  277. province, _ := c.GetInt64("province")
  278. city, _ := c.GetInt64("city")
  279. config, err := service.GetDockingStatus(config_type, province, city)
  280. fmt.Println(config)
  281. fmt.Println(err)
  282. if err == gorm.ErrRecordNotFound {
  283. c.ServeSuccessJSON(map[string]interface{}{
  284. "is_docking": 2,
  285. })
  286. } else if err == nil {
  287. if config.ID > 0 {
  288. c.ServeSuccessJSON(map[string]interface{}{
  289. "is_docking": 1,
  290. })
  291. } else {
  292. c.ServeSuccessJSON(map[string]interface{}{
  293. "is_docking": 2,
  294. })
  295. }
  296. }
  297. }
  298. func (c *GobalConfigApiController) ModifyConfig() {
  299. id, _ := c.GetInt64("id")
  300. gateway_address := c.GetString("gateway_address")
  301. app_id := c.GetString("app_id")
  302. key := c.GetString("key")
  303. config_type, _ := c.GetInt64("config_type")
  304. time_type, _ := c.GetInt64("time_type")
  305. province, _ := c.GetInt64("province")
  306. city, _ := c.GetInt64("city")
  307. adminUserInfo := c.GetAdminUserInfo()
  308. org_id := adminUserInfo.CurrentOrgId
  309. if config_type > 1 {
  310. _, err := service.GetDockingStatus(config_type, province, city)
  311. if err == gorm.ErrRecordNotFound {
  312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotDocking)
  313. return
  314. }
  315. }
  316. tempConfig, _ := service.GetConfigDataById(id)
  317. config := &models.DataUploadConfig{
  318. ID: tempConfig.ID,
  319. OrgId: org_id,
  320. ProvinceId: province,
  321. CityId: city,
  322. GatewayAddress: gateway_address,
  323. AppId: app_id,
  324. Key: key,
  325. Status: 1,
  326. CreateTime: tempConfig.CreateTime,
  327. ModifyTime: time.Now().Unix(),
  328. TimeQuantum: time_type,
  329. ConfigType: config_type,
  330. }
  331. err := service.SaveConfigData(config)
  332. if err == nil {
  333. c.ServeSuccessJSON(map[string]interface{}{
  334. "config": config,
  335. })
  336. } else {
  337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  338. return
  339. }
  340. }
  341. func (c *GobalConfigApiController) PostDoctorAdviceConfig() {
  342. is_open_remind, _ := c.GetInt64("is_open_remind", 0)
  343. adminUserInfo := c.GetAdminUserInfo()
  344. org_id := adminUserInfo.CurrentOrgId
  345. config := models.DoctorAdviceConfig{
  346. UserOrgId: org_id,
  347. IsOpenRemind: is_open_remind,
  348. Status: 1,
  349. CreateTime: time.Now().Unix(),
  350. UpdateTime: time.Now().Unix(),
  351. }
  352. errs, configs := service.FindDoctorAdviceRecordByOrgId(org_id)
  353. if errs == gorm.ErrRecordNotFound {
  354. err := service.CreateDoctorAdviceRecord(&config)
  355. if err != nil {
  356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  357. return
  358. }
  359. } else if errs == nil {
  360. modifyConfig := models.DoctorAdviceConfig{
  361. ID: configs.ID,
  362. UserOrgId: org_id,
  363. Status: 1,
  364. CreateTime: time.Now().Unix(),
  365. UpdateTime: time.Now().Unix(),
  366. IsOpenRemind: is_open_remind,
  367. }
  368. err := service.UpdateDoctorAdviceRecord(&modifyConfig)
  369. if err != nil {
  370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  371. return
  372. }
  373. }
  374. c.ServeSuccessJSON(map[string]interface{}{
  375. "is_open_remind": is_open_remind,
  376. })
  377. return
  378. }
  379. func (c *GobalConfigApiController) GetDoctorAdviceConfig() {
  380. adminUserInfo := c.GetAdminUserInfo()
  381. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  382. c.ServeSuccessJSON(map[string]interface{}{
  383. "config": config,
  384. })
  385. }
  386. //SF6090214798525
  387. func (c *GobalConfigApiController) Load(filename string, v interface{}) {
  388. //ReadFile函数会读取文件的全部内容,并将结果以[]byte类型返回
  389. data, err := ioutil.ReadFile(filename)
  390. if err != nil {
  391. return
  392. }
  393. //读取的数据为json格式,需要进行解码
  394. err = json.Unmarshal(data, v)
  395. if err != nil {
  396. return
  397. }
  398. }
  399. type Config struct {
  400. Parent_template []*models.VMDoctorAdviceParentTemplate "json:parent_template"
  401. }
  402. func LoadConfig(dataFile string) *Config {
  403. var config Config
  404. _, filename, _, _ := runtime.Caller(1)
  405. datapath := path.Join(path.Dir(filename), dataFile)
  406. config_file, err := os.Open(datapath)
  407. if err != nil {
  408. emit("Failed to open config file '%s': %s\n", datapath, err)
  409. return &config
  410. }
  411. fi, _ := config_file.Stat()
  412. buffer := make([]byte, fi.Size())
  413. _, err = config_file.Read(buffer)
  414. buffer, err = StripComments(buffer) //去掉注释
  415. if err != nil {
  416. emit("Failed to strip comments from json: %s\n", err)
  417. return &config
  418. }
  419. buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
  420. err = json.Unmarshal(buffer, &config) //解析json格式数据
  421. if err != nil {
  422. emit("Failed unmarshalling json: %s\n", err)
  423. return &config
  424. }
  425. return &config
  426. }
  427. func StripComments(data []byte) ([]byte, error) {
  428. data = bytes.Replace(data, []byte("\r"), []byte(""), 0) // Windows
  429. lines := bytes.Split(data, []byte("\n")) //split to muli lines
  430. filtered := make([][]byte, 0)
  431. for _, line := range lines {
  432. match, err := regexp.Match(`^\s*#`, line)
  433. if err != nil {
  434. return nil, err
  435. }
  436. if !match {
  437. filtered = append(filtered, line)
  438. }
  439. }
  440. return bytes.Join(filtered, []byte("\n")), nil
  441. }
  442. func emit(msgfmt string, args ...interface{}) {
  443. log.Printf(msgfmt, args...)
  444. }
  445. func (c *GobalConfigApiController) GetAdviceInitConfig() {
  446. adminUserInfo := c.GetAdminUserInfo()
  447. advice_init, _ := service.FindAdviceInitConfig(adminUserInfo.CurrentOrgId)
  448. c.ServeSuccessJSON(map[string]interface{}{
  449. "advice_init": advice_init,
  450. })
  451. }
  452. func (c *GobalConfigApiController) PostInitAdviceTemplate() {
  453. is_init, _ := c.GetInt64("is_init")
  454. adminUserInfo := c.GetAdminUserInfo()
  455. adviceInit := &models.AdviceInit{
  456. UserOrgId: adminUserInfo.CurrentOrgId,
  457. CreateTime: time.Now().Unix(),
  458. UpdateTime: time.Now().Unix(),
  459. Status: 1,
  460. IsInit: is_init,
  461. }
  462. adviceParentTemplate := LoadConfig("./advice_template.json").Parent_template
  463. for _, item := range adviceParentTemplate {
  464. parentTemplate := &models.DoctorAdviceParentTemplate{
  465. OrgId: adminUserInfo.CurrentOrgId,
  466. Name: item.Name,
  467. Status: 1,
  468. CreatedTime: time.Now().Unix(),
  469. UpdatedTime: time.Now().Unix(),
  470. AdviceType: item.AdviceType,
  471. }
  472. createErr := service.CreateDoctorParentTemplate(parentTemplate)
  473. fmt.Println(parentTemplate.ID)
  474. if createErr == nil {
  475. for _, adviceTemplateItem := range item.DoctorAdviceTemplate {
  476. adviceTeplate := &models.DoctorAdviceTemplate{
  477. OrgId: adminUserInfo.CurrentOrgId,
  478. AdviceName: adviceTemplateItem.AdviceName,
  479. AdviceDesc: adviceTemplateItem.AdviceDesc,
  480. SingleDose: adviceTemplateItem.SingleDose,
  481. SingleDoseUnit: adviceTemplateItem.SingleDoseUnit,
  482. PrescribingNumber: adviceTemplateItem.PrescribingNumber,
  483. PrescribingNumberUnit: adviceTemplateItem.PrescribingNumberUnit,
  484. DeliveryWay: adviceTemplateItem.DeliveryWay,
  485. ExecutionFrequency: adviceTemplateItem.ExecutionFrequency,
  486. AdviceDoctor: adviceTemplateItem.AdviceDoctor,
  487. Status: 1,
  488. CreatedTime: time.Now().Unix(),
  489. UpdatedTime: time.Now().Unix(),
  490. TemplateId: parentTemplate.ID,
  491. DrugSpec: adviceTemplateItem.DrugSpec,
  492. DrugSpecUnit: adviceTemplateItem.DrugSpecUnit,
  493. ParentId: adviceTemplateItem.ParentId,
  494. AdviceType: adviceTemplateItem.AdviceType,
  495. DayCount: adviceTemplateItem.DayCount,
  496. WeekDays: adviceTemplateItem.WeekDays,
  497. FrequencyType: adviceTemplateItem.FrequencyType,
  498. }
  499. createErr := service.CreateDoctorTemplate(adviceTeplate)
  500. if createErr == nil {
  501. for _, childItem := range adviceTemplateItem.SubDoctorAdviceTemplate {
  502. adviceTeplate := &models.DoctorAdviceTemplate{
  503. OrgId: adminUserInfo.CurrentOrgId,
  504. AdviceName: childItem.AdviceName,
  505. AdviceDesc: childItem.AdviceDesc,
  506. SingleDose: childItem.SingleDose,
  507. SingleDoseUnit: childItem.SingleDoseUnit,
  508. PrescribingNumber: childItem.PrescribingNumber,
  509. PrescribingNumberUnit: childItem.PrescribingNumberUnit,
  510. DeliveryWay: childItem.DeliveryWay,
  511. ExecutionFrequency: childItem.ExecutionFrequency,
  512. AdviceDoctor: childItem.AdviceDoctor,
  513. Status: 1,
  514. CreatedTime: time.Now().Unix(),
  515. UpdatedTime: time.Now().Unix(),
  516. TemplateId: parentTemplate.ID,
  517. DrugSpec: childItem.DrugSpec,
  518. DrugSpecUnit: childItem.DrugSpecUnit,
  519. ParentId: adviceTeplate.ID,
  520. AdviceType: childItem.AdviceType,
  521. DayCount: childItem.DayCount,
  522. WeekDays: childItem.WeekDays,
  523. FrequencyType: childItem.FrequencyType,
  524. }
  525. service.CreateDoctorTemplate(adviceTeplate)
  526. }
  527. }
  528. }
  529. }
  530. }
  531. err := service.CreateAdviceInitConfig(adviceInit)
  532. if err == nil {
  533. c.ServeSuccessJSON(map[string]interface{}{
  534. "init_config": adviceInit,
  535. })
  536. } else {
  537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  538. return
  539. }
  540. }
  541. func (c *GobalConfigApiController) CreateSystemPrescription() {
  542. adminUserInfo := c.GetAdminUserInfo()
  543. var solution models.SystemPrescription
  544. code := defaultSystemSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  545. if code > 0 {
  546. c.ServeFailJSONWithSGJErrorCode(code)
  547. return
  548. }
  549. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  550. solution.Doctor = adminUserInfo.AdminUser.Id
  551. solution.Status = 1
  552. solution.CreatedTime = time.Now().Unix()
  553. solution.UserOrgId = adminUserInfo.CurrentOrgId
  554. solution.UpdatedTime = time.Now().Unix()
  555. err := service.CreateSystemDialysisSolution(&solution)
  556. if err != nil {
  557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  558. return
  559. }
  560. prescriptions, _ := service.FindAllSystemPrescription(adminUserInfo.CurrentOrgId)
  561. c.ServeSuccessJSON(map[string]interface{}{
  562. "prescription": solution,
  563. "prescriptions": prescriptions,
  564. })
  565. return
  566. }
  567. func (c *GobalConfigApiController) UpdateSystemPrescription() {
  568. id, _ := c.GetInt64("id", 0)
  569. if id <= 0 {
  570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  571. return
  572. }
  573. adminUserInfo := c.GetAdminUserInfo()
  574. solution, _ := service.FindSystemDialysisSolution(adminUserInfo.CurrentOrgId, id)
  575. if solution.ID == 0 {
  576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  577. return
  578. }
  579. code := defaultSystemSolutionFormData(&solution, c.Ctx.Input.RequestBody, "edit")
  580. if code > 0 {
  581. c.ServeFailJSONWithSGJErrorCode(code)
  582. return
  583. }
  584. solution.UpdatedTime = time.Now().Unix()
  585. solution.Doctor = adminUserInfo.AdminUser.Id
  586. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  587. err := service.UpdateSystemDialysisSolution(&solution)
  588. if err != nil {
  589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  590. return
  591. }
  592. c.ServeSuccessJSON(map[string]interface{}{
  593. "msg": "ok",
  594. "prescription": solution,
  595. })
  596. return
  597. }
  598. func (c *GobalConfigApiController) GetAllSystemPrescription() {
  599. adminUserInfo := c.GetAdminUserInfo()
  600. prescriptions, _ := service.FindAllSystemPrescription(adminUserInfo.CurrentOrgId)
  601. c.ServeSuccessJSON(map[string]interface{}{
  602. "prescriptions": prescriptions,
  603. })
  604. }
  605. func (c *GobalConfigApiController) GetSystemPrescription() {
  606. adminUserInfo := c.GetAdminUserInfo()
  607. id, _ := c.GetInt64("id", 0)
  608. prescription, _ := service.FindSystemDialysisPrescriptionByMode(adminUserInfo.CurrentOrgId, id)
  609. c.ServeSuccessJSON(map[string]interface{}{
  610. "prescription": prescription,
  611. })
  612. }
  613. func defaultSystemSolutionFormData(solution *models.SystemPrescription, data []byte, method string) (code int) {
  614. dataBody := make(map[string]interface{}, 0)
  615. err := json.Unmarshal(data, &dataBody)
  616. utils.InfoLog(string(data))
  617. if err != nil {
  618. utils.ErrorLog(err.Error())
  619. code = enums.ErrorCodeParamWrong
  620. return
  621. }
  622. if method == "create" {
  623. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  624. utils.ErrorLog("mode")
  625. code = enums.ErrorCodeParamWrong
  626. return
  627. }
  628. mode := int64(dataBody["mode"].(float64))
  629. if mode <= 0 {
  630. utils.ErrorLog("mode <= 0")
  631. code = enums.ErrorCodeParamWrong
  632. return
  633. }
  634. solution.ModeId = mode
  635. }
  636. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  637. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  638. solution.DialysisDuration = dialysisDuration
  639. }
  640. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  641. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  642. solution.TargetUltrafiltration = targetUltrafiltration
  643. }
  644. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  645. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  646. solution.DialysateFormulation = dialysateFormulation
  647. }
  648. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  649. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  650. solution.DialysisDurationHour = int64(dialysisDurationHour)
  651. }
  652. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  653. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  654. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  655. }
  656. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  657. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  658. solution.HemodialysisMachine = hemodialysisMachine
  659. }
  660. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  661. dialyzer := int64(dataBody["dialyzer"].(float64))
  662. solution.Dialyzer = dialyzer
  663. }
  664. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  665. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  666. solution.PerfusionApparatus = perfusionApparatus
  667. }
  668. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  669. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  670. solution.BloodFlowVolume = bloodFlowVolume
  671. }
  672. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  673. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  674. solution.Dewater = dewater
  675. }
  676. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  677. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  678. solution.DisplaceLiqui = displaceLiqui
  679. }
  680. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  681. replacementWay := int64(dataBody["replacement_way"].(float64))
  682. solution.ReplacementWay = replacementWay
  683. }
  684. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  685. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  686. solution.Anticoagulant = anticoagulant
  687. }
  688. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  689. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  690. solution.AnticoagulantShouji = anticoagulantShouji
  691. }
  692. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  693. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  694. solution.AnticoagulantWeichi = anticoagulantWeichi
  695. }
  696. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  697. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  698. solution.AnticoagulantZongliang = anticoagulantZongliang
  699. }
  700. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  701. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  702. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  703. }
  704. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  705. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  706. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  707. }
  708. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  709. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  710. solution.Kalium = kalium
  711. }
  712. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  713. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  714. solution.Sodium = sodium
  715. }
  716. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  717. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  718. solution.Calcium = calcium
  719. }
  720. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  721. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  722. solution.Bicarbonate = bicarbonate
  723. }
  724. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  725. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  726. solution.Glucose = glucose
  727. }
  728. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  729. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  730. // solution.DryWeight = dryWeight
  731. // }
  732. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  733. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  734. solution.DialysateFlow = dialysateFlow
  735. }
  736. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  737. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  738. solution.DialysateTemperature = dialysateTemperature
  739. }
  740. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  741. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  742. solution.Conductivity = conductivity
  743. }
  744. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  745. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  746. solution.ReplacementTotal = replacementTotal
  747. }
  748. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  749. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  750. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  751. }
  752. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  753. body_fluid := int64(dataBody["body_fluid"].(float64))
  754. solution.BodyFluid = body_fluid
  755. }
  756. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  757. body_fluid_other := dataBody["body_fluid_other"].(string)
  758. solution.BodyFluidOther = body_fluid_other
  759. }
  760. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  761. special_medicine := int64(dataBody["special_medicine"].(float64))
  762. solution.SpecialMedicine = special_medicine
  763. }
  764. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  765. special_medicine_other := dataBody["special_medicine_other"].(string)
  766. solution.SpecialMedicineOther = special_medicine_other
  767. }
  768. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  769. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  770. solution.DisplaceLiquiPart = displace_liqui_part
  771. }
  772. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  773. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  774. solution.DisplaceLiquiValue = displace_liqui_value
  775. }
  776. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  777. blood_access := int64(dataBody["blood_access"].(float64))
  778. solution.BloodAccess = blood_access
  779. }
  780. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  781. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  782. solution.Ultrafiltration = ultrafiltration
  783. }
  784. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  785. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  786. solution.TargetKtv = target_ktv
  787. }
  788. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  789. remark := dataBody["remark"].(string)
  790. solution.Remark = remark
  791. }
  792. return
  793. }
  794. func (c *GobalConfigApiController) GetPrintInfo() {
  795. adminUserInfo := c.GetAdminUserInfo()
  796. OrgID := adminUserInfo.CurrentOrgId
  797. dataBody := make(map[string]interface{}, 0)
  798. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  799. idsInters := dataBody["ids"].([]interface{})
  800. if len(idsInters) == 0 {
  801. if err != nil {
  802. c.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)")
  803. return
  804. }
  805. }
  806. ids := make([]int64, 0)
  807. for _, idsInter := range idsInters {
  808. id := int64(idsInter.(float64))
  809. ids = append(ids, id)
  810. }
  811. getPrint, err := service.GetPrint(ids, OrgID)
  812. c.ServeSuccessJSON(map[string]interface{}{
  813. "doctoradvice": getPrint,
  814. })
  815. }