gobal_config_api_controller.go 80KB

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