gobal_config_api_controller.go 87KB

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