gobal_config_api_controller.go 62KB

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