gobal_config_api_controller.go 49KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592
  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. c.ServeSuccessJSON(map[string]interface{}{
  653. "prescriptions": prescriptions,
  654. })
  655. }
  656. func (c *GobalConfigApiController) GetSystemPrescription() {
  657. adminUserInfo := c.GetAdminUserInfo()
  658. id, _ := c.GetInt64("id", 0)
  659. prescription, _ := service.FindSystemDialysisPrescriptionByMode(adminUserInfo.CurrentOrgId, id)
  660. c.ServeSuccessJSON(map[string]interface{}{
  661. "prescription": prescription,
  662. })
  663. }
  664. func defaultSystemSolutionFormData(solution *models.SystemPrescription, data []byte, method string) (code int) {
  665. dataBody := make(map[string]interface{}, 0)
  666. err := json.Unmarshal(data, &dataBody)
  667. utils.InfoLog(string(data))
  668. if err != nil {
  669. utils.ErrorLog(err.Error())
  670. code = enums.ErrorCodeParamWrong
  671. return
  672. }
  673. if method == "create" {
  674. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  675. utils.ErrorLog("mode")
  676. code = enums.ErrorCodeParamWrong
  677. return
  678. }
  679. mode := int64(dataBody["mode"].(float64))
  680. if mode <= 0 {
  681. utils.ErrorLog("mode <= 0")
  682. code = enums.ErrorCodeParamWrong
  683. return
  684. }
  685. solution.ModeId = mode
  686. }
  687. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  688. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  689. solution.DialysisDuration = dialysisDuration
  690. }
  691. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  692. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  693. solution.TargetUltrafiltration = targetUltrafiltration
  694. }
  695. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  696. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  697. solution.DialysateFormulation = dialysateFormulation
  698. }
  699. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  700. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  701. solution.DialysisDurationHour = int64(dialysisDurationHour)
  702. }
  703. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  704. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  705. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  706. }
  707. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  708. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  709. solution.HemodialysisMachine = hemodialysisMachine
  710. }
  711. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  712. dialyzer := int64(dataBody["dialyzer"].(float64))
  713. solution.Dialyzer = dialyzer
  714. }
  715. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  716. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  717. solution.PerfusionApparatus = perfusionApparatus
  718. }
  719. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  720. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  721. solution.BloodFlowVolume = bloodFlowVolume
  722. }
  723. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  724. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  725. solution.Dewater = dewater
  726. }
  727. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  728. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  729. solution.DisplaceLiqui = displaceLiqui
  730. }
  731. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  732. replacementWay := int64(dataBody["replacement_way"].(float64))
  733. solution.ReplacementWay = replacementWay
  734. }
  735. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  736. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  737. solution.Anticoagulant = anticoagulant
  738. }
  739. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  740. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  741. solution.AnticoagulantShouji = anticoagulantShouji
  742. }
  743. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  744. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  745. solution.AnticoagulantWeichi = anticoagulantWeichi
  746. }
  747. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  748. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  749. solution.AnticoagulantZongliang = anticoagulantZongliang
  750. }
  751. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  752. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  753. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  754. }
  755. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  756. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  757. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  758. }
  759. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  760. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  761. solution.Kalium = kalium
  762. }
  763. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  764. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  765. solution.Sodium = sodium
  766. }
  767. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  768. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  769. solution.Calcium = calcium
  770. }
  771. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  772. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  773. solution.Bicarbonate = bicarbonate
  774. }
  775. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  776. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  777. solution.Glucose = glucose
  778. }
  779. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  780. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  781. // solution.DryWeight = dryWeight
  782. // }
  783. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  784. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  785. solution.DialysateFlow = dialysateFlow
  786. }
  787. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  788. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  789. solution.DialysateTemperature = dialysateTemperature
  790. }
  791. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  792. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  793. solution.Conductivity = conductivity
  794. }
  795. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  796. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  797. solution.ReplacementTotal = replacementTotal
  798. }
  799. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  800. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  801. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  802. }
  803. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  804. body_fluid := int64(dataBody["body_fluid"].(float64))
  805. solution.BodyFluid = body_fluid
  806. }
  807. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  808. body_fluid_other := dataBody["body_fluid_other"].(string)
  809. solution.BodyFluidOther = body_fluid_other
  810. }
  811. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  812. special_medicine := int64(dataBody["special_medicine"].(float64))
  813. solution.SpecialMedicine = special_medicine
  814. }
  815. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  816. special_medicine_other := dataBody["special_medicine_other"].(string)
  817. solution.SpecialMedicineOther = special_medicine_other
  818. }
  819. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  820. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  821. solution.DisplaceLiquiPart = displace_liqui_part
  822. }
  823. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  824. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  825. solution.DisplaceLiquiValue = displace_liqui_value
  826. }
  827. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  828. blood_access := int64(dataBody["blood_access"].(float64))
  829. solution.BloodAccess = blood_access
  830. }
  831. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  832. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  833. solution.Ultrafiltration = ultrafiltration
  834. }
  835. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  836. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  837. solution.TargetKtv = target_ktv
  838. }
  839. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  840. remark := dataBody["remark"].(string)
  841. solution.Remark = remark
  842. }
  843. return
  844. }
  845. func (c *GobalConfigApiController) GetPrintInfo() {
  846. adminUserInfo := c.GetAdminUserInfo()
  847. OrgID := adminUserInfo.CurrentOrgId
  848. dataBody := make(map[string]interface{}, 0)
  849. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  850. idsInters := dataBody["ids"].([]interface{})
  851. if len(idsInters) == 0 {
  852. if err != nil {
  853. c.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)")
  854. return
  855. }
  856. }
  857. ids := make([]int64, 0)
  858. for _, idsInter := range idsInters {
  859. id := int64(idsInter.(float64))
  860. ids = append(ids, id)
  861. }
  862. getPrint, err := service.GetPrint(ids, OrgID)
  863. c.ServeSuccessJSON(map[string]interface{}{
  864. "doctoradvice": getPrint,
  865. })
  866. }
  867. func (c *GobalConfigApiController) GetOrgs() {
  868. adminUserInfo := c.GetAdminUserInfo()
  869. //获取当前人姓名
  870. var id = adminUserInfo.AdminUser.Id
  871. orgId := adminUserInfo.CurrentOrgId
  872. var orgs []*models.Org
  873. adminUser, err := service.GetHomeData(adminUserInfo.AdminUser.Id)
  874. creator, err := service.GetCreator(id, orgId)
  875. admin, err := service.GetSuperAdmin(id)
  876. if err != nil {
  877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  878. return
  879. }
  880. for _, item := range adminUser.Org {
  881. orgs = append(orgs, item)
  882. }
  883. for _, item := range adminUser.VMApp_Role {
  884. for _, subItem := range item.Org {
  885. orgs = append(orgs, subItem)
  886. }
  887. }
  888. orgs = RemoveRepeatedOrgElement(orgs)
  889. c.ServeSuccessJSON(map[string]interface{}{
  890. "orgs": orgs,
  891. "adminUser": adminUser,
  892. "creator": creator,
  893. "admin": admin,
  894. })
  895. }
  896. func (this *GobalConfigApiController) ChangeOrg() {
  897. org_id, _ := this.GetInt64("org_id")
  898. adminUserInfo := this.GetAdminUserInfo()
  899. tempOrg, err := service.GetOrgById(org_id)
  900. if err != nil {
  901. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  902. return
  903. }
  904. if tempOrg == nil {
  905. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrgNoExist)
  906. return
  907. }
  908. mobile := adminUserInfo.AdminUser.Mobile
  909. // 只取最近被创建的 admin_role
  910. adminUser, getAdminErr := service.GetValidAdminUserByMobileReturnErr(mobile) //账号信息唯一值
  911. if getAdminErr != nil {
  912. utils.ErrorLog("获取管理员失败:%v", getAdminErr)
  913. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  914. this.ServeJSON()
  915. return
  916. } else if adminUser == nil {
  917. utils.ErrorLog("查找不到 mobile = %v 的用户", mobile)
  918. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeAccountOrPasswordWrong)
  919. this.ServeJSON()
  920. return
  921. } else {
  922. adminUserInfo.CurrentOrgId = tempOrg.Id
  923. orgApp, _ := service.GetOrgApp(tempOrg.Id, 3)
  924. subscibe, _ := service.GetOrgSubscibe(tempOrg.Id)
  925. adminUserInfo.CurrentAppId = orgApp.Id
  926. appRole, _ := service.GetAppRole(tempOrg.Id, orgApp.Id, adminUserInfo.AdminUser.Id)
  927. var FiledList []*models.FiledConfig
  928. FiledList, _ = service.FindFiledByOrgId(tempOrg.Id)
  929. if len(FiledList) == 0 {
  930. err := service.BatchInsertFiledConfig(tempOrg.Id)
  931. if err == nil {
  932. FiledList, _ = service.FindFiledByOrgId(tempOrg.Id)
  933. } else {
  934. utils.ErrorLog("字段批量插入失败:%v", err)
  935. }
  936. }
  937. //产寻该机构是否有收缩压和舒张压
  938. pressure, err := service.GetDefaultSystolicPressure(tempOrg.Id)
  939. fmt.Println(err)
  940. if len(pressure) == 0 {
  941. err = service.BathInsertQualityControlTwo(tempOrg.Id)
  942. } else {
  943. utils.ErrorLog("字段批量插入失败:%v", err)
  944. }
  945. major, err := service.GetInspectionMajor(tempOrg.Id)
  946. if len(major) == 0 {
  947. QualityeList, err := service.FindQualityByOrgId(tempOrg.Id)
  948. if len(QualityeList) == 0 {
  949. err = service.BatchInsertQualityControl(tempOrg.Id)
  950. } else {
  951. utils.ErrorLog("字段批量插入失败:%v", err)
  952. }
  953. InspectionList, err := service.FindeInspectionByOrgId(tempOrg.Id)
  954. if len(InspectionList) == 0 {
  955. err = service.BatchInspectionConfiguration(tempOrg.Id)
  956. } else {
  957. utils.ErrorLog("字段批量插入失败:%v", err)
  958. }
  959. } else {
  960. utils.ErrorLog("字段批量插入失败:%v", err)
  961. }
  962. //查询该机构是否存在医护排班
  963. _, errcode := service.GetDoctorScheduleByOrgId(tempOrg.Id)
  964. //如果没有就插入
  965. if errcode == gorm.ErrRecordNotFound {
  966. err = service.BatchInsertDoctorSchedule(tempOrg.Id)
  967. } else {
  968. utils.ErrorLog("医护排班默认数据插入失败:%v", err)
  969. }
  970. var didRegistedForSCRM bool = false
  971. var didRegistedForCDM bool = false
  972. var didRegistedForMall bool = false
  973. var curAppUrlfors []string
  974. var pruviews []*models.Purview
  975. if len(curAppUrlfors) == 0 {
  976. if adminUser.Id == tempOrg.Creator {
  977. urlfors_xt, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(3)
  978. urlfors_cdm, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(4)
  979. urlfors_scrm, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(6)
  980. urlfors_mall, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(7)
  981. curAppUrlfors = append(curAppUrlfors, urlfors_xt...)
  982. curAppUrlfors = append(curAppUrlfors, urlfors_scrm...)
  983. curAppUrlfors = append(curAppUrlfors, urlfors_cdm...)
  984. curAppUrlfors = append(curAppUrlfors, urlfors_mall...)
  985. didRegistedForSCRM = true
  986. didRegistedForCDM = true
  987. didRegistedForMall = true
  988. } else {
  989. appRole, _ := service.FindAdminUserIDA(appRole.Id)
  990. if appRole.Id > 0 && len(appRole.RoleIds) > 0 {
  991. role_arr := strings.Split(appRole.RoleIds, ",")
  992. var ids string
  993. for _, role_id := range role_arr {
  994. id, _ := strconv.ParseInt(role_id, 10, 64)
  995. purview_ids, _ := service.GetRolePurviewIds(id)
  996. if len(ids) == 0 {
  997. ids = purview_ids
  998. } else {
  999. ids = ids + "," + purview_ids
  1000. }
  1001. }
  1002. if len(ids) != 0 {
  1003. pruviews, _ = service.GetPurviewById(ids)
  1004. for _, item := range pruviews {
  1005. if item.Module == 3 && item.Parentid > 0 {
  1006. fmt.Println(item.Urlfor)
  1007. curAppUrlfors = append(curAppUrlfors, item.Urlfor)
  1008. }
  1009. }
  1010. } else {
  1011. curAppUrlfors = append(curAppUrlfors, "")
  1012. }
  1013. } else {
  1014. curAppUrlfors = append(curAppUrlfors, "")
  1015. }
  1016. for _, item := range pruviews {
  1017. if item.Module == 6 {
  1018. didRegistedForSCRM = true
  1019. }
  1020. if item.Module == 4 {
  1021. didRegistedForCDM = true
  1022. }
  1023. if item.Module == 7 {
  1024. didRegistedForMall = true
  1025. }
  1026. }
  1027. }
  1028. }
  1029. userInfo := map[string]interface{}{
  1030. "id": adminUser.Id,
  1031. "mobile": adminUser.Mobile,
  1032. "user_name": appRole.UserName,
  1033. "avatar": appRole.Avatar,
  1034. "intro": appRole.Intro,
  1035. "user_type": appRole.UserType,
  1036. "user_title": appRole.UserTitle,
  1037. }
  1038. org := map[string]interface{}{
  1039. "id": tempOrg.Id,
  1040. "org_name": tempOrg.OrgName,
  1041. "org_short_name": tempOrg.OrgShortName,
  1042. "org_intro": tempOrg.OrgIntroduction,
  1043. "org_logo": tempOrg.OrgLogo,
  1044. "province": tempOrg.Province,
  1045. "city": tempOrg.City,
  1046. "district": tempOrg.District,
  1047. "address": tempOrg.Address,
  1048. }
  1049. tempInfo, _ := service.GetOrgInfoTemplate(tempOrg.Id)
  1050. template_info := map[string]interface{}{
  1051. "id": tempInfo.ID,
  1052. "org_id": tempInfo.OrgId,
  1053. "template_id": tempInfo.TemplateId,
  1054. }
  1055. if tempOrg != nil && appRole != nil {
  1056. // 插入一条登录记录
  1057. ip := this.GetString("ip")
  1058. loginLog := &models.AdminUserLoginLog{
  1059. AdminUserId: adminUser.Id,
  1060. OrgId: tempOrg.Id,
  1061. AppId: appRole.AppId,
  1062. IP: ip,
  1063. OperateType: 3,
  1064. AppType: 3,
  1065. CreateTime: time.Now().Unix(),
  1066. }
  1067. if insertErr := service.InsertLoginLog(loginLog); insertErr != nil {
  1068. utils.ErrorLog("为手机号为%v的用户插入一条登录记录失败:%v", mobile, insertErr)
  1069. }
  1070. }
  1071. this.SetSession("admin_user_info", adminUserInfo)
  1072. this.ServeSuccessJSON(map[string]interface{}{
  1073. "user": userInfo,
  1074. "org": org,
  1075. "urlfors": curAppUrlfors,
  1076. "current_org_id": adminUserInfo.CurrentOrgId,
  1077. "current_app_id": adminUserInfo.CurrentAppId,
  1078. "subscibe": subscibe,
  1079. "template_info": template_info,
  1080. "fileds": FiledList,
  1081. "scrm_role_exist": didRegistedForSCRM,
  1082. "cdm_role_exist": didRegistedForCDM,
  1083. "mall_role_exist": didRegistedForMall,
  1084. })
  1085. }
  1086. }
  1087. func RemoveRepeatedOrgElement(orgs []*models.Org) (newOrgs []*models.Org) {
  1088. newOrgs = make([]*models.Org, 0)
  1089. for i := 0; i < len(orgs); i++ {
  1090. repeat := false
  1091. for j := i + 1; j < len(orgs); j++ {
  1092. if orgs[i].Id == orgs[j].Id {
  1093. repeat = true
  1094. break
  1095. }
  1096. }
  1097. if !repeat {
  1098. newOrgs = append(newOrgs, orgs[i])
  1099. }
  1100. }
  1101. return
  1102. }
  1103. func (this *GobalConfigApiController) GenerateLog() {
  1104. log_type, _ := this.GetInt64("log_type", 0)
  1105. logs, err := service.GetExportLogByType(this.GetAdminUserInfo().CurrentOrgId, log_type)
  1106. if err != nil {
  1107. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1108. return
  1109. }
  1110. this.ServeSuccessJSON(map[string]interface{}{
  1111. "logs": logs,
  1112. })
  1113. }
  1114. func (this *GobalConfigApiController) GetPatientsByKeyWord() {
  1115. keyWord := this.GetString("keyword")
  1116. adminUserInfo := this.GetAdminUserInfo()
  1117. patient, err := service.GetPatientsByKey(adminUserInfo.CurrentOrgId, keyWord)
  1118. if err != nil {
  1119. utils.ErrorLog(err.Error())
  1120. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1121. return
  1122. }
  1123. this.ServeSuccessJSON(map[string]interface{}{
  1124. "patient": patient,
  1125. })
  1126. }
  1127. func (c *GobalConfigApiController) PostXTHisConfig() {
  1128. is_open, _ := c.GetBool("is_open", false)
  1129. adminUserInfo := c.GetAdminUserInfo()
  1130. org_id := adminUserInfo.CurrentOrgId
  1131. isOpen := 0
  1132. if is_open {
  1133. isOpen = 1
  1134. } else {
  1135. isOpen = 2
  1136. }
  1137. config := models.XtHisConfig{
  1138. UserOrgId: org_id,
  1139. IsOpen: int64(isOpen),
  1140. Status: 1,
  1141. Ctime: time.Now().Unix(),
  1142. Mtime: time.Now().Unix(),
  1143. }
  1144. errs, configs := service.FindXTHisRecordByOrgId(org_id)
  1145. if errs == gorm.ErrRecordNotFound {
  1146. err := service.CreateXTHisRecord(&config)
  1147. if err != nil {
  1148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1149. return
  1150. }
  1151. } else if errs == nil {
  1152. modifyConfig := models.XtHisConfig{
  1153. ID: configs.ID,
  1154. UserOrgId: org_id,
  1155. Status: 1,
  1156. Ctime: time.Now().Unix(),
  1157. Mtime: time.Now().Unix(),
  1158. IsOpen: int64(isOpen),
  1159. }
  1160. err := service.UpdateXTHisRecord(&modifyConfig)
  1161. if err != nil {
  1162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1163. return
  1164. }
  1165. }
  1166. c.ServeSuccessJSON(map[string]interface{}{
  1167. "is_open": is_open,
  1168. })
  1169. return
  1170. }
  1171. func (c *GobalConfigApiController) GetXTHisConfig() {
  1172. adminUserInfo := c.GetAdminUserInfo()
  1173. _, config := service.FindXTHisRecordByOrgId(adminUserInfo.CurrentOrgId)
  1174. c.ServeSuccessJSON(map[string]interface{}{
  1175. "config": config,
  1176. })
  1177. }
  1178. func (c *GobalConfigApiController) GetAllIsOpenConfig() {
  1179. adminUserInfo := c.GetAdminUserInfo()
  1180. _, config := service.FindXTHisRecordByOrgId(adminUserInfo.CurrentOrgId)
  1181. c.ServeSuccessJSON(map[string]interface{}{
  1182. "is_open_xt_his": config.IsOpen,
  1183. })
  1184. }
  1185. func (c *GobalConfigApiController) GetPassExportData() {
  1186. }
  1187. func (c *GobalConfigApiController) GetExportData() {
  1188. start_time := c.GetString("start_time")
  1189. end_time := c.GetString("end_time")
  1190. timeLayout := "2006-01-02"
  1191. loc, _ := time.LoadLocation("Local")
  1192. var startTime int64
  1193. if len(start_time) > 0 {
  1194. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1195. if err != nil {
  1196. fmt.Println(err)
  1197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1198. return
  1199. }
  1200. startTime = theTime.Unix()
  1201. }
  1202. var endTime int64
  1203. if len(end_time) > 0 {
  1204. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1205. if err != nil {
  1206. utils.ErrorLog(err.Error())
  1207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1208. return
  1209. }
  1210. endTime = theTime.Unix()
  1211. }
  1212. adminInfo := c.GetAdminUserInfo()
  1213. order, _ := service.GetExportHisOrderList(adminInfo.CurrentOrgId, startTime, endTime)
  1214. c.ServeSuccessJSON(map[string]interface{}{
  1215. "order": order,
  1216. })
  1217. }
  1218. func (c *GobalConfigApiController) GetDrugInDetail() {
  1219. start_time := c.GetString("start_time")
  1220. end_time := c.GetString("end_time")
  1221. timeLayout := "2006-01-02"
  1222. loc, _ := time.LoadLocation("Local")
  1223. var startTime int64
  1224. if len(start_time) > 0 {
  1225. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1226. if err != nil {
  1227. fmt.Println(err)
  1228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1229. return
  1230. }
  1231. startTime = theTime.Unix()
  1232. }
  1233. var endTime int64
  1234. if len(end_time) > 0 {
  1235. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1236. if err != nil {
  1237. utils.ErrorLog(err.Error())
  1238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1239. return
  1240. }
  1241. endTime = theTime.Unix()
  1242. }
  1243. adminInfo := c.GetAdminUserInfo()
  1244. order_type, _ := c.GetInt64("order_type")
  1245. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1246. keyword := c.GetString("keyword")
  1247. page, _ := c.GetInt64("page")
  1248. limit, _ := c.GetInt64("limit")
  1249. detail, total, err := service.GetDrugInOrderDetail(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit)
  1250. if err != nil {
  1251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1252. return
  1253. }
  1254. c.ServeSuccessJSON(map[string]interface{}{
  1255. "detail": detail,
  1256. "total": total,
  1257. })
  1258. }
  1259. func (c *GobalConfigApiController) GetDrugCancelOrder() {
  1260. start_time := c.GetString("start_time")
  1261. end_time := c.GetString("end_time")
  1262. timeLayout := "2006-01-02"
  1263. loc, _ := time.LoadLocation("Local")
  1264. var startTime int64
  1265. if len(start_time) > 0 {
  1266. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1267. if err != nil {
  1268. fmt.Println(err)
  1269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1270. return
  1271. }
  1272. startTime = theTime.Unix()
  1273. }
  1274. var endTime int64
  1275. if len(end_time) > 0 {
  1276. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1277. if err != nil {
  1278. utils.ErrorLog(err.Error())
  1279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1280. return
  1281. }
  1282. endTime = theTime.Unix()
  1283. }
  1284. adminInfo := c.GetAdminUserInfo()
  1285. order_type, _ := c.GetInt64("order_type")
  1286. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1287. keyword := c.GetString("keyword")
  1288. limit, _ := c.GetInt64("limit")
  1289. page, _ := c.GetInt64("page")
  1290. order, total, err := service.GetDrugReturnOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, limit, page)
  1291. if err != nil {
  1292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1293. return
  1294. }
  1295. c.ServeSuccessJSON(map[string]interface{}{
  1296. "order": order,
  1297. "total": total,
  1298. })
  1299. }
  1300. func (c *GobalConfigApiController) GetDrugOutDetail() {
  1301. start_time := c.GetString("start_time")
  1302. end_time := c.GetString("end_time")
  1303. timeLayout := "2006-01-02"
  1304. loc, _ := time.LoadLocation("Local")
  1305. var startTime int64
  1306. if len(start_time) > 0 {
  1307. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1308. if err != nil {
  1309. fmt.Println(err)
  1310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1311. return
  1312. }
  1313. startTime = theTime.Unix()
  1314. }
  1315. var endTime int64
  1316. if len(end_time) > 0 {
  1317. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1318. if err != nil {
  1319. utils.ErrorLog(err.Error())
  1320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1321. return
  1322. }
  1323. endTime = theTime.Unix()
  1324. }
  1325. adminInfo := c.GetAdminUserInfo()
  1326. order_type, _ := c.GetInt64("order_type")
  1327. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1328. keyword := c.GetString("keyword")
  1329. limit, _ := c.GetInt64("limit")
  1330. page, _ := c.GetInt64("page")
  1331. order, total, err := service.GetDrugOutOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit)
  1332. if err != nil {
  1333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1334. return
  1335. }
  1336. c.ServeSuccessJSON(map[string]interface{}{
  1337. "order": order,
  1338. "total": total,
  1339. })
  1340. }
  1341. func (c *GobalConfigApiController) GetDrugCancelDetail() {
  1342. start_time := c.GetString("start_time")
  1343. end_time := c.GetString("end_time")
  1344. timeLayout := "2006-01-02"
  1345. loc, _ := time.LoadLocation("Local")
  1346. var startTime int64
  1347. if len(start_time) > 0 {
  1348. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1349. if err != nil {
  1350. fmt.Println(err)
  1351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1352. return
  1353. }
  1354. startTime = theTime.Unix()
  1355. }
  1356. var endTime int64
  1357. if len(end_time) > 0 {
  1358. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1359. if err != nil {
  1360. utils.ErrorLog(err.Error())
  1361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1362. return
  1363. }
  1364. endTime = theTime.Unix()
  1365. }
  1366. adminInfo := c.GetAdminUserInfo()
  1367. order_type, _ := c.GetInt64("order_type")
  1368. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1369. keyword := c.GetString("keyword")
  1370. limit, _ := c.GetInt64("limit")
  1371. page, _ := c.GetInt64("page")
  1372. order, total, err := service.GetDrugCancelOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit)
  1373. if err != nil {
  1374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1375. return
  1376. }
  1377. c.ServeSuccessJSON(map[string]interface{}{
  1378. "order": order,
  1379. "total": total,
  1380. })
  1381. }