gobal_config_api_controller.go 44KB

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