gobal_config_api_controller.go 77KB

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