gobal_config_api_controller.go 88KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871
  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. his_str := c.GetString("his_str")
  974. if len(his_str) == 0 {
  975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  976. return
  977. }
  978. idStrs := strings.Split(his_str, ",")
  979. if len(idsInters) == 0 {
  980. if err != nil {
  981. c.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)")
  982. return
  983. }
  984. }
  985. ids := make([]int64, 0)
  986. for _, idsInter := range idsInters {
  987. id := int64(idsInter.(float64))
  988. ids = append(ids, id)
  989. }
  990. getPrint, err := service.GetPrint(ids, OrgID, advice_type, stop_type)
  991. hisPrint, _ := service.GetHisPrint(idStrs, OrgID)
  992. c.ServeSuccessJSON(map[string]interface{}{
  993. "doctoradvice": getPrint,
  994. "hisdoctoradvice": hisPrint,
  995. })
  996. }
  997. func (c *GobalConfigApiController) GetOrgs() {
  998. adminUserInfo := c.GetAdminUserInfo()
  999. //获取当前人姓名
  1000. var id = adminUserInfo.AdminUser.Id
  1001. orgId := adminUserInfo.CurrentOrgId
  1002. var orgs []*models.Org
  1003. adminUser, err := service.GetHomeData(adminUserInfo.AdminUser.Id)
  1004. creator, err := service.GetCreator(id, orgId)
  1005. admin, err := service.GetSuperAdmin(id)
  1006. if err != nil {
  1007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1008. return
  1009. }
  1010. for _, item := range adminUser.Org {
  1011. orgs = append(orgs, item)
  1012. }
  1013. for _, item := range adminUser.VMApp_Role {
  1014. for _, subItem := range item.Org {
  1015. orgs = append(orgs, subItem)
  1016. }
  1017. }
  1018. orgs = RemoveRepeatedOrgElement(orgs)
  1019. fmt.Println("~~~~")
  1020. role, _ := service.GetAdminUserInfoByID(orgId, id)
  1021. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  1022. c.ServeSuccessJSON(map[string]interface{}{
  1023. "orgs": orgs,
  1024. "adminUser": adminUser,
  1025. "creator": creator,
  1026. "admin": admin,
  1027. "role": role,
  1028. "org_config": miConfig,
  1029. })
  1030. }
  1031. func (this *GobalConfigApiController) ChangeOrg() {
  1032. org_id, _ := this.GetInt64("org_id")
  1033. adminUserInfo := this.GetAdminUserInfo()
  1034. tempOrg, err := service.GetOrgById(org_id)
  1035. if err != nil {
  1036. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1037. return
  1038. }
  1039. if tempOrg == nil {
  1040. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrgNoExist)
  1041. return
  1042. }
  1043. mobile := adminUserInfo.AdminUser.Mobile
  1044. // 只取最近被创建的 admin_role
  1045. adminUser, getAdminErr := service.GetValidAdminUserByMobileReturnErr(mobile) //账号信息唯一值
  1046. if getAdminErr != nil {
  1047. utils.ErrorLog("获取管理员失败:%v", getAdminErr)
  1048. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1049. this.ServeJSON()
  1050. return
  1051. } else if adminUser == nil {
  1052. utils.ErrorLog("查找不到 mobile = %v 的用户", mobile)
  1053. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeAccountOrPasswordWrong)
  1054. this.ServeJSON()
  1055. return
  1056. } else {
  1057. adminUserInfo.CurrentOrgId = tempOrg.Id
  1058. orgApp, _ := service.GetOrgApp(tempOrg.Id, 3)
  1059. subscibe, _ := service.GetOrgSubscibe(tempOrg.Id)
  1060. adminUserInfo.CurrentAppId = orgApp.Id
  1061. appRole, _ := service.GetAppRole(tempOrg.Id, orgApp.Id, adminUserInfo.AdminUser.Id)
  1062. var FiledList []*models.FiledConfig
  1063. FiledList, _ = service.FindFiledByOrgId(tempOrg.Id)
  1064. if len(FiledList) == 0 {
  1065. err := service.BatchInsertFiledConfig(tempOrg.Id)
  1066. if err == nil {
  1067. FiledList, _ = service.FindFiledByOrgId(tempOrg.Id)
  1068. } else {
  1069. utils.ErrorLog("字段批量插入失败:%v", err)
  1070. }
  1071. }
  1072. //产寻该机构是否有收缩压和舒张压
  1073. pressure, err := service.GetDefaultSystolicPressure(tempOrg.Id)
  1074. fmt.Println(err)
  1075. if len(pressure) == 0 {
  1076. err = service.BathInsertQualityControlTwo(tempOrg.Id)
  1077. } else {
  1078. utils.ErrorLog("字段批量插入失败:%v", err)
  1079. }
  1080. major, err := service.GetInspectionMajor(tempOrg.Id)
  1081. if len(major) == 0 {
  1082. QualityeList, err := service.FindQualityByOrgId(tempOrg.Id)
  1083. if len(QualityeList) == 0 {
  1084. err = service.BatchInsertQualityControl(tempOrg.Id)
  1085. } else {
  1086. utils.ErrorLog("字段批量插入失败:%v", err)
  1087. }
  1088. InspectionList, err := service.FindeInspectionByOrgId(tempOrg.Id)
  1089. if len(InspectionList) == 0 {
  1090. err = service.BatchInspectionConfiguration(tempOrg.Id)
  1091. } else {
  1092. utils.ErrorLog("字段批量插入失败:%v", err)
  1093. }
  1094. } else {
  1095. utils.ErrorLog("字段批量插入失败:%v", err)
  1096. }
  1097. //查询该机构是否存在医护排班
  1098. _, errcode := service.GetDoctorScheduleByOrgId(tempOrg.Id)
  1099. //如果没有就插入
  1100. if errcode == gorm.ErrRecordNotFound {
  1101. err = service.BatchInsertDoctorSchedule(tempOrg.Id)
  1102. } else {
  1103. utils.ErrorLog("医护排班默认数据插入失败:%v", err)
  1104. }
  1105. var didRegistedForSCRM bool = false
  1106. var didRegistedForCDM bool = false
  1107. var didRegistedForMall bool = false
  1108. var curAppUrlfors []string
  1109. var pruviews []*models.Purview
  1110. if len(curAppUrlfors) == 0 {
  1111. if adminUser.Id == tempOrg.Creator {
  1112. urlfors_xt, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(3)
  1113. urlfors_cdm, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(4)
  1114. urlfors_scrm, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(6)
  1115. urlfors_mall, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(7)
  1116. curAppUrlfors = append(curAppUrlfors, urlfors_xt...)
  1117. curAppUrlfors = append(curAppUrlfors, urlfors_scrm...)
  1118. curAppUrlfors = append(curAppUrlfors, urlfors_cdm...)
  1119. curAppUrlfors = append(curAppUrlfors, urlfors_mall...)
  1120. didRegistedForSCRM = true
  1121. didRegistedForCDM = true
  1122. didRegistedForMall = true
  1123. } else {
  1124. appRole, _ := service.FindAdminUserIDA(appRole.Id)
  1125. if appRole.Id > 0 && len(appRole.RoleIds) > 0 {
  1126. role_arr := strings.Split(appRole.RoleIds, ",")
  1127. var ids string
  1128. for _, role_id := range role_arr {
  1129. id, _ := strconv.ParseInt(role_id, 10, 64)
  1130. purview_ids, _ := service.GetRolePurviewIds(id)
  1131. if len(ids) == 0 {
  1132. ids = purview_ids
  1133. } else {
  1134. ids = ids + "," + purview_ids
  1135. }
  1136. }
  1137. if len(ids) != 0 {
  1138. pruviews, _ = service.GetPurviewById(ids)
  1139. for _, item := range pruviews {
  1140. if item.Module == 3 && item.Parentid > 0 {
  1141. fmt.Println(item.Urlfor)
  1142. curAppUrlfors = append(curAppUrlfors, item.Urlfor)
  1143. }
  1144. }
  1145. } else {
  1146. curAppUrlfors = append(curAppUrlfors, "")
  1147. }
  1148. } else {
  1149. curAppUrlfors = append(curAppUrlfors, "")
  1150. }
  1151. for _, item := range pruviews {
  1152. if item.Module == 6 {
  1153. didRegistedForSCRM = true
  1154. }
  1155. if item.Module == 4 {
  1156. didRegistedForCDM = true
  1157. }
  1158. if item.Module == 7 {
  1159. didRegistedForMall = true
  1160. }
  1161. }
  1162. }
  1163. }
  1164. userInfo := map[string]interface{}{
  1165. "id": adminUser.Id,
  1166. "mobile": adminUser.Mobile,
  1167. "user_name": appRole.UserName,
  1168. "avatar": appRole.Avatar,
  1169. "intro": appRole.Intro,
  1170. "user_type": appRole.UserType,
  1171. "user_title": appRole.UserTitle,
  1172. }
  1173. org := map[string]interface{}{
  1174. "id": tempOrg.Id,
  1175. "org_name": tempOrg.OrgName,
  1176. "org_short_name": tempOrg.OrgShortName,
  1177. "org_intro": tempOrg.OrgIntroduction,
  1178. "org_logo": tempOrg.OrgLogo,
  1179. "province": tempOrg.Province,
  1180. "city": tempOrg.City,
  1181. "district": tempOrg.District,
  1182. "address": tempOrg.Address,
  1183. }
  1184. tempInfo, _ := service.GetOrgInfoTemplate(tempOrg.Id)
  1185. template_info := map[string]interface{}{
  1186. "id": tempInfo.ID,
  1187. "org_id": tempInfo.OrgId,
  1188. "template_id": tempInfo.TemplateId,
  1189. }
  1190. if tempOrg != nil && appRole != nil {
  1191. // 插入一条登录记录
  1192. ip := this.GetString("ip")
  1193. loginLog := &models.AdminUserLoginLog{
  1194. AdminUserId: adminUser.Id,
  1195. OrgId: tempOrg.Id,
  1196. AppId: appRole.AppId,
  1197. IP: ip,
  1198. OperateType: 3,
  1199. AppType: 3,
  1200. CreateTime: time.Now().Unix(),
  1201. }
  1202. if insertErr := service.InsertLoginLog(loginLog); insertErr != nil {
  1203. utils.ErrorLog("为手机号为%v的用户插入一条登录记录失败:%v", mobile, insertErr)
  1204. }
  1205. }
  1206. this.SetSession("admin_user_info", adminUserInfo)
  1207. this.ServeSuccessJSON(map[string]interface{}{
  1208. "user": userInfo,
  1209. "org": org,
  1210. "urlfors": curAppUrlfors,
  1211. "current_org_id": adminUserInfo.CurrentOrgId,
  1212. "current_app_id": adminUserInfo.CurrentAppId,
  1213. "subscibe": subscibe,
  1214. "template_info": template_info,
  1215. "fileds": FiledList,
  1216. "scrm_role_exist": didRegistedForSCRM,
  1217. "cdm_role_exist": didRegistedForCDM,
  1218. "mall_role_exist": didRegistedForMall,
  1219. })
  1220. }
  1221. }
  1222. func RemoveRepeatedOrgElement(orgs []*models.Org) (newOrgs []*models.Org) {
  1223. newOrgs = make([]*models.Org, 0)
  1224. for i := 0; i < len(orgs); i++ {
  1225. repeat := false
  1226. for j := i + 1; j < len(orgs); j++ {
  1227. if orgs[i].Id == orgs[j].Id {
  1228. repeat = true
  1229. break
  1230. }
  1231. }
  1232. if !repeat {
  1233. newOrgs = append(newOrgs, orgs[i])
  1234. }
  1235. }
  1236. return
  1237. }
  1238. func (this *GobalConfigApiController) GenerateLog() {
  1239. log_type, _ := this.GetInt64("log_type", 0)
  1240. logs, err := service.GetExportLogByType(this.GetAdminUserInfo().CurrentOrgId, log_type)
  1241. if err != nil {
  1242. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1243. return
  1244. }
  1245. this.ServeSuccessJSON(map[string]interface{}{
  1246. "logs": logs,
  1247. })
  1248. }
  1249. func (this *GobalConfigApiController) GetPatientsByKeyWord() {
  1250. keyWord := this.GetString("keyword")
  1251. adminUserInfo := this.GetAdminUserInfo()
  1252. patient, err := service.GetPatientsByKey(adminUserInfo.CurrentOrgId, keyWord)
  1253. if err != nil {
  1254. utils.ErrorLog(err.Error())
  1255. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1256. return
  1257. }
  1258. this.ServeSuccessJSON(map[string]interface{}{
  1259. "patient": patient,
  1260. })
  1261. }
  1262. func (c *GobalConfigApiController) PostXTHisConfig() {
  1263. is_open, _ := c.GetBool("is_open", false)
  1264. adminUserInfo := c.GetAdminUserInfo()
  1265. org_id := adminUserInfo.CurrentOrgId
  1266. isOpen := 0
  1267. if is_open {
  1268. isOpen = 1
  1269. } else {
  1270. isOpen = 2
  1271. }
  1272. config := models.XtHisConfig{
  1273. UserOrgId: org_id,
  1274. IsOpen: int64(isOpen),
  1275. Status: 1,
  1276. Ctime: time.Now().Unix(),
  1277. Mtime: time.Now().Unix(),
  1278. }
  1279. errs, configs := service.FindXTHisRecordByOrgId(org_id)
  1280. if errs == gorm.ErrRecordNotFound {
  1281. err := service.CreateXTHisRecord(&config)
  1282. if err != nil {
  1283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1284. return
  1285. }
  1286. } else if errs == nil {
  1287. modifyConfig := models.XtHisConfig{
  1288. ID: configs.ID,
  1289. UserOrgId: org_id,
  1290. Status: 1,
  1291. Ctime: time.Now().Unix(),
  1292. Mtime: time.Now().Unix(),
  1293. IsOpen: int64(isOpen),
  1294. }
  1295. err := service.UpdateXTHisRecord(&modifyConfig)
  1296. redis := service.RedisClient()
  1297. defer redis.Close()
  1298. key := strconv.FormatInt(org_id, 10) + ":" + ":his_config"
  1299. redis.Set(key, "", time.Second)
  1300. if err != nil {
  1301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1302. return
  1303. }
  1304. }
  1305. c.ServeSuccessJSON(map[string]interface{}{
  1306. "is_open": is_open,
  1307. })
  1308. return
  1309. }
  1310. func (c *GobalConfigApiController) PostHisStockPriceConfig() {
  1311. is_open, _ := c.GetBool("is_open", false)
  1312. adminUserInfo := c.GetAdminUserInfo()
  1313. org_id := adminUserInfo.CurrentOrgId
  1314. isOpen := 0
  1315. if is_open {
  1316. isOpen = 1
  1317. } else {
  1318. isOpen = 2
  1319. }
  1320. config := models.HisStockPriceConfig{
  1321. UserOrgId: org_id,
  1322. IsOpen: int64(isOpen),
  1323. Status: 1,
  1324. Ctime: time.Now().Unix(),
  1325. Mtime: time.Now().Unix(),
  1326. }
  1327. errs, configs := service.FindHisStockPriceRecordByOrgId(org_id)
  1328. if errs == gorm.ErrRecordNotFound {
  1329. err := service.CreateHisStockPriceRecord(&config)
  1330. if err != nil {
  1331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1332. return
  1333. }
  1334. } else if errs == nil {
  1335. modifyConfig := models.HisStockPriceConfig{
  1336. ID: configs.ID,
  1337. UserOrgId: org_id,
  1338. Status: 1,
  1339. Ctime: time.Now().Unix(),
  1340. Mtime: time.Now().Unix(),
  1341. IsOpen: int64(isOpen),
  1342. }
  1343. err := service.UpdateHisStockPriceRecord(&modifyConfig)
  1344. if err != nil {
  1345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1346. return
  1347. }
  1348. }
  1349. c.ServeSuccessJSON(map[string]interface{}{
  1350. "is_open": is_open,
  1351. })
  1352. return
  1353. }
  1354. func (c *GobalConfigApiController) PostXTHisProjectConfig() {
  1355. is_open, _ := c.GetBool("is_open", false)
  1356. adminUserInfo := c.GetAdminUserInfo()
  1357. org_id := adminUserInfo.CurrentOrgId
  1358. isOpen := 0
  1359. if is_open {
  1360. isOpen = 1
  1361. } else {
  1362. isOpen = 2
  1363. }
  1364. config := models.XtHisProjectConfig{
  1365. UserOrgId: org_id,
  1366. IsOpen: int64(isOpen),
  1367. Status: 1,
  1368. Ctime: time.Now().Unix(),
  1369. Mtime: time.Now().Unix(),
  1370. }
  1371. errs, configs := service.FindXTHisProjectByOrgId(org_id)
  1372. if errs == gorm.ErrRecordNotFound {
  1373. err := service.CreateXTHisProjectRecord(&config)
  1374. redis := service.RedisClient()
  1375. key := strconv.FormatInt(org_id, 10) + ":his_project_config"
  1376. redis.Set(key, "", time.Second)
  1377. defer redis.Close()
  1378. if err != nil {
  1379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1380. return
  1381. }
  1382. } else if errs == nil {
  1383. modifyConfig := models.XtHisProjectConfig{
  1384. ID: configs.ID,
  1385. UserOrgId: org_id,
  1386. Status: 1,
  1387. Ctime: time.Now().Unix(),
  1388. Mtime: time.Now().Unix(),
  1389. IsOpen: int64(isOpen),
  1390. }
  1391. err := service.UpdateXTHisProjectRecord(&modifyConfig)
  1392. if err != nil {
  1393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1394. return
  1395. }
  1396. }
  1397. c.ServeSuccessJSON(map[string]interface{}{
  1398. "is_open": is_open,
  1399. })
  1400. return
  1401. }
  1402. func (c *GobalConfigApiController) GetXTHisConfig() {
  1403. adminUserInfo := c.GetAdminUserInfo()
  1404. _, config := service.FindXTHisRecordByOrgId(adminUserInfo.CurrentOrgId)
  1405. _, project_config := service.FindXTHisProjectByOrgId(adminUserInfo.CurrentOrgId)
  1406. c.ServeSuccessJSON(map[string]interface{}{
  1407. "config": config,
  1408. "project_config": project_config,
  1409. })
  1410. }
  1411. func (c *GobalConfigApiController) GetHisStockPriceConfig() {
  1412. adminUserInfo := c.GetAdminUserInfo()
  1413. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1414. c.ServeSuccessJSON(map[string]interface{}{
  1415. "config": config,
  1416. })
  1417. }
  1418. func (c *GobalConfigApiController) GetAllIsOpenConfig() {
  1419. adminUserInfo := c.GetAdminUserInfo()
  1420. _, config := service.FindXTHisRecordByOrgId(adminUserInfo.CurrentOrgId)
  1421. _, project_config := service.FindXTHisProjectByOrgIdOne(adminUserInfo.CurrentOrgId)
  1422. stockSetting, _ := service.FindStockSettingById(adminUserInfo.CurrentOrgId)
  1423. adviceSetting, _ := service.FindAdviceSettingById(adminUserInfo.CurrentOrgId)
  1424. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminUserInfo.CurrentOrgId)
  1425. drugOutConfig, _ := service.FindDrugOutConfigById(adminUserInfo.CurrentOrgId)
  1426. drugSettleConfig, _ := service.FindeDrugSettleConfigById(adminUserInfo.CurrentOrgId)
  1427. goodOutConfig, _ := service.FindGoodOutConfigById(adminUserInfo.CurrentOrgId)
  1428. drugCodeOpen, _ := service.GetDrugCodeOpen(adminUserInfo.CurrentOrgId)
  1429. c.ServeSuccessJSON(map[string]interface{}{
  1430. "is_open_xt_his": config.IsOpen,
  1431. "is_open_xt_his_project": project_config.IsOpen,
  1432. "is_open_stock": stockSetting.IsType,
  1433. "is_open_advice": adviceSetting.IsAdviceOpen,
  1434. "is_prescription_advice": prescriptionConfig.IsOpen,
  1435. "is_open": drugOutConfig.IsOpen,
  1436. "is_seetle_open": drugSettleConfig.IsOpen,
  1437. "is_out_open": goodOutConfig.IsOpen,
  1438. "is_code_open": drugCodeOpen.IsOpen,
  1439. })
  1440. }
  1441. func (c *GobalConfigApiController) GetPassExportData() {
  1442. }
  1443. func (c *GobalConfigApiController) GetExportData() {
  1444. start_time := c.GetString("start_time")
  1445. end_time := c.GetString("end_time")
  1446. p_type, _ := c.GetInt64("p_type")
  1447. ex_type, _ := c.GetInt64("sort_type")
  1448. timeLayout := "2006-01-02"
  1449. loc, _ := time.LoadLocation("Local")
  1450. var startTime int64
  1451. if len(start_time) > 0 {
  1452. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1453. if err != nil {
  1454. fmt.Println(err)
  1455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1456. return
  1457. }
  1458. startTime = theTime.Unix()
  1459. }
  1460. var endTime int64
  1461. if len(end_time) > 0 {
  1462. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1463. if err != nil {
  1464. utils.ErrorLog(err.Error())
  1465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1466. return
  1467. }
  1468. endTime = theTime.Unix()
  1469. }
  1470. adminInfo := c.GetAdminUserInfo()
  1471. var order []*models.HisOrder
  1472. if ex_type == 1 {
  1473. order, _ = service.GetExportHisOrderList(adminInfo.CurrentOrgId, startTime, endTime, p_type)
  1474. } else {
  1475. order, _ = service.GetExportHisOrderListBySetlTIME(adminInfo.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", p_type)
  1476. }
  1477. c.ServeSuccessJSON(map[string]interface{}{
  1478. "order": order,
  1479. })
  1480. }
  1481. func (c *GobalConfigApiController) GetDrugInDetail() {
  1482. start_time := c.GetString("start_time")
  1483. end_time := c.GetString("end_time")
  1484. storehouse_id, _ := c.GetInt64("storehouse_id")
  1485. drug_id, _ := c.GetInt64("drug_id")
  1486. timeLayout := "2006-01-02"
  1487. loc, _ := time.LoadLocation("Local")
  1488. var startTime int64
  1489. if len(start_time) > 0 {
  1490. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1491. if err != nil {
  1492. fmt.Println(err)
  1493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1494. return
  1495. }
  1496. startTime = theTime.Unix()
  1497. }
  1498. var endTime int64
  1499. if len(end_time) > 0 {
  1500. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1501. if err != nil {
  1502. utils.ErrorLog(err.Error())
  1503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1504. return
  1505. }
  1506. endTime = theTime.Unix()
  1507. }
  1508. adminInfo := c.GetAdminUserInfo()
  1509. order_type, _ := c.GetInt64("order_type")
  1510. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1511. keyword := c.GetString("keyword")
  1512. page, _ := c.GetInt64("page")
  1513. limit, _ := c.GetInt64("limit")
  1514. detail, total, err := service.GetDrugInOrderDetail(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit, storehouse_id, drug_id)
  1515. var drugType = "药品类型"
  1516. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  1517. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminInfo.CurrentOrgId)
  1518. houseList, _ := service.GetAllStorehouseName(adminInfo.CurrentOrgId)
  1519. if err != nil {
  1520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1521. return
  1522. }
  1523. c.ServeSuccessJSON(map[string]interface{}{
  1524. "detail": detail,
  1525. "total": total,
  1526. "drugTypeParent": drugTypeList,
  1527. "houseList": houseList,
  1528. })
  1529. }
  1530. func (c *GobalConfigApiController) GetDrugCancelOrder() {
  1531. start_time := c.GetString("start_time")
  1532. end_time := c.GetString("end_time")
  1533. timeLayout := "2006-01-02"
  1534. loc, _ := time.LoadLocation("Local")
  1535. var startTime int64
  1536. if len(start_time) > 0 {
  1537. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1538. if err != nil {
  1539. fmt.Println(err)
  1540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1541. return
  1542. }
  1543. startTime = theTime.Unix()
  1544. }
  1545. var endTime int64
  1546. if len(end_time) > 0 {
  1547. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1548. if err != nil {
  1549. utils.ErrorLog(err.Error())
  1550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1551. return
  1552. }
  1553. endTime = theTime.Unix()
  1554. }
  1555. adminInfo := c.GetAdminUserInfo()
  1556. order_type, _ := c.GetInt64("order_type")
  1557. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1558. keyword := c.GetString("keyword")
  1559. limit, _ := c.GetInt64("limit")
  1560. page, _ := c.GetInt64("page")
  1561. order, total, err := service.GetDrugReturnOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, limit, page)
  1562. if err != nil {
  1563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1564. return
  1565. }
  1566. c.ServeSuccessJSON(map[string]interface{}{
  1567. "order": order,
  1568. "total": total,
  1569. })
  1570. }
  1571. func (c *GobalConfigApiController) GetDrugOutDetail() {
  1572. start_time := c.GetString("start_time")
  1573. end_time := c.GetString("end_time")
  1574. storehouse_id, _ := c.GetInt64("storehouse_id")
  1575. timeLayout := "2006-01-02"
  1576. loc, _ := time.LoadLocation("Local")
  1577. var startTime int64
  1578. if len(start_time) > 0 {
  1579. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1580. if err != nil {
  1581. fmt.Println(err)
  1582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1583. return
  1584. }
  1585. startTime = theTime.Unix()
  1586. }
  1587. var endTime int64
  1588. if len(end_time) > 0 {
  1589. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1590. if err != nil {
  1591. utils.ErrorLog(err.Error())
  1592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1593. return
  1594. }
  1595. endTime = theTime.Unix()
  1596. }
  1597. adminInfo := c.GetAdminUserInfo()
  1598. order_type, _ := c.GetInt64("order_type")
  1599. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1600. keyword := c.GetString("keyword")
  1601. limit, _ := c.GetInt64("limit")
  1602. page, _ := c.GetInt64("page")
  1603. drug_id, _ := c.GetInt64("drug_id")
  1604. order_way, _ := c.GetInt64("order_way")
  1605. order, total, err := service.GetDrugOutOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit, storehouse_id, drug_id, order_way)
  1606. if adminInfo.CurrentOrgId == 10721 {
  1607. if len(order) > 0 {
  1608. for _, item := range order {
  1609. if item.IsSys == 1 {
  1610. var is_number = item.Count % item.MinNumber
  1611. if is_number == 0 {
  1612. item.Count = item.Count / item.MinNumber
  1613. item.TotalPrice = float64(item.Count) * item.Price
  1614. item.CountUnit = item.MaxUnit
  1615. }
  1616. if is_number != 0 {
  1617. item.TotalPrice = float64(item.Count) * item.Price
  1618. item.CountUnit = item.MinUnit
  1619. }
  1620. }
  1621. }
  1622. }
  1623. }
  1624. houseList, _ := service.GetAllStoreHouseList(adminInfo.CurrentOrgId)
  1625. patientsList, _ := service.GetAllpatient(adminInfo.CurrentOrgId)
  1626. var drugType = "药品类型"
  1627. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  1628. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminInfo.CurrentOrgId)
  1629. if err != nil {
  1630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1631. return
  1632. }
  1633. c.ServeSuccessJSON(map[string]interface{}{
  1634. "order": order,
  1635. "total": total,
  1636. "drugTypeList": drugTypeList,
  1637. "houseList": houseList,
  1638. "patientsList": patientsList,
  1639. })
  1640. }
  1641. func (c *GobalConfigApiController) GetDrugCancelDetail() {
  1642. start_time := c.GetString("start_time")
  1643. end_time := c.GetString("end_time")
  1644. storehouse_id, _ := c.GetInt64("storehouse_id")
  1645. timeLayout := "2006-01-02"
  1646. loc, _ := time.LoadLocation("Local")
  1647. var startTime int64
  1648. if len(start_time) > 0 {
  1649. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1650. if err != nil {
  1651. fmt.Println(err)
  1652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1653. return
  1654. }
  1655. startTime = theTime.Unix()
  1656. }
  1657. var endTime int64
  1658. if len(end_time) > 0 {
  1659. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1660. if err != nil {
  1661. utils.ErrorLog(err.Error())
  1662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1663. return
  1664. }
  1665. endTime = theTime.Unix()
  1666. }
  1667. adminInfo := c.GetAdminUserInfo()
  1668. order_type, _ := c.GetInt64("order_type")
  1669. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1670. keyword := c.GetString("keyword")
  1671. limit, _ := c.GetInt64("limit")
  1672. page, _ := c.GetInt64("page")
  1673. drug_id, _ := c.GetInt64("drug_id")
  1674. orderPrint, _ := service.GetDrugCancelOrderPrint(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, storehouse_id, drug_id)
  1675. order, total, err := service.GetDrugCancelOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit, storehouse_id, drug_id)
  1676. var drugType = "药品类型"
  1677. drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
  1678. drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, adminInfo.CurrentOrgId)
  1679. houseList, _ := service.GetAllStoreHouseList(adminInfo.CurrentOrgId)
  1680. dealerList, _ := service.GetAllDealerList(adminInfo.CurrentOrgId)
  1681. manufacturerList, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1682. patientsList, _ := service.GetAllpatient(adminInfo.CurrentOrgId)
  1683. if err != nil {
  1684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1685. return
  1686. }
  1687. c.ServeSuccessJSON(map[string]interface{}{
  1688. "order": order,
  1689. "total": total,
  1690. "orderPrint": orderPrint,
  1691. "drugTypeList": drugTypeList,
  1692. "houseList": houseList,
  1693. "dealerList": dealerList,
  1694. "manufacturerList": manufacturerList,
  1695. "patientsList": patientsList,
  1696. })
  1697. }
  1698. func (c *GobalConfigApiController) AddMonitorOpen() {
  1699. is_open, _ := c.GetInt64("is_open")
  1700. fmt.Println("is_open22222222", is_open)
  1701. adminUserInfo := c.GetAdminUserInfo()
  1702. orgId := adminUserInfo.CurrentOrgId
  1703. config := models.XtMonitorConfig{
  1704. IsOpen: is_open,
  1705. UserOrgId: orgId,
  1706. Status: 1,
  1707. Ctime: time.Now().Unix(),
  1708. }
  1709. //查询该机构是否存在
  1710. _, errcode := service.GetMonitorConfigById(orgId)
  1711. if errcode == gorm.ErrRecordNotFound {
  1712. err := service.AddMonitorOpen(&config)
  1713. if err != nil {
  1714. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1715. return
  1716. }
  1717. c.ServeSuccessJSON(map[string]interface{}{
  1718. "config": config,
  1719. })
  1720. } else if errcode == nil {
  1721. err := service.UpdateMonitorOpen(orgId, &config)
  1722. fmt.Println("err", err)
  1723. }
  1724. }
  1725. func (c *GobalConfigApiController) GetMonitorConfig() {
  1726. userInfo := c.GetAdminUserInfo()
  1727. orgId := userInfo.CurrentOrgId
  1728. config, err := service.GetMonitorConfig(orgId)
  1729. if err != nil {
  1730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1731. return
  1732. }
  1733. c.ServeSuccessJSON(map[string]interface{}{
  1734. "config": config,
  1735. })
  1736. }
  1737. func (c *GobalConfigApiController) AddOrderConfig() {
  1738. is_open, _ := c.GetInt64("is_open")
  1739. fmt.Println("344555555555555", is_open)
  1740. adminUserInfo := c.GetAdminUserInfo()
  1741. orgId := adminUserInfo.CurrentOrgId
  1742. config := models.XtOrderConfig{
  1743. IsOpen: is_open,
  1744. UserOrgId: orgId,
  1745. Status: 1,
  1746. Ctime: time.Now().Unix(),
  1747. }
  1748. //查询
  1749. _, errcode := service.GetOrderConfigById(orgId)
  1750. if errcode == gorm.ErrRecordNotFound {
  1751. err := service.AddOrderConfig(&config)
  1752. if err != nil {
  1753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1754. return
  1755. }
  1756. c.ServeSuccessJSON(map[string]interface{}{
  1757. "config": config,
  1758. })
  1759. } else if errcode == nil {
  1760. err := service.UpdateOrderConfig(orgId, &config)
  1761. fmt.Println("2222", err)
  1762. }
  1763. }
  1764. func (c *GobalConfigApiController) GetOrderConfig() {
  1765. adminUserInfo := c.GetAdminUserInfo()
  1766. orgId := adminUserInfo.CurrentOrgId
  1767. config, err := service.GetOrderConfig(orgId)
  1768. if err != nil {
  1769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1770. return
  1771. }
  1772. c.ServeSuccessJSON(map[string]interface{}{
  1773. "config": config,
  1774. })
  1775. }
  1776. func (c *GobalConfigApiController) GetDrugAutoMaticList() {
  1777. adminUserInfo := c.GetAdminUserInfo()
  1778. orgId := adminUserInfo.CurrentOrgId
  1779. warehous_out_id, _ := c.GetInt64("warehous_out_id")
  1780. record_time, _ := c.GetInt64("record_time")
  1781. warehouse_out_order_number := c.GetString("warehouse_out_order_number")
  1782. drugConfig, _ := service.GetDrugStockConfig(orgId)
  1783. list, err := service.GetDrugAutoMaticList(orgId, warehous_out_id, record_time, warehouse_out_order_number)
  1784. drugList, err := service.GetAllBaseDrugList(orgId)
  1785. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1786. if err != nil {
  1787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1788. return
  1789. }
  1790. c.ServeSuccessJSON(map[string]interface{}{
  1791. "list": list,
  1792. "drugConfig": drugConfig,
  1793. "drugList": drugList,
  1794. "manufacturerList": manufacturerList,
  1795. })
  1796. }
  1797. func (c *GobalConfigApiController) GetDrugWarehuseOrderInfo() {
  1798. adminUserInfo := c.GetAdminUserInfo()
  1799. orgId := adminUserInfo.CurrentOrgId
  1800. list, _ := service.GetDrugWarehuseOrderInfo(orgId)
  1801. c.ServeSuccessJSON(map[string]interface{}{
  1802. "list": list,
  1803. })
  1804. }
  1805. func (c *GobalConfigApiController) GetDrugStockList() {
  1806. page, _ := c.GetInt64("page", -1)
  1807. limit, _ := c.GetInt64("limit", -1)
  1808. keyword := c.GetString("keyword")
  1809. drug_type, _ := c.GetInt64("drug_type")
  1810. start_time := c.GetString("start_time")
  1811. end_time := c.GetString("end_time")
  1812. timeLayout := "2006-01-02"
  1813. loc, _ := time.LoadLocation("Local")
  1814. storehouse_id, _ := c.GetInt64("storehouse_id")
  1815. drug_id, _ := c.GetInt64("drug_id")
  1816. var startTime int64
  1817. if len(start_time) > 0 {
  1818. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1819. if err != nil {
  1820. fmt.Println(err)
  1821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1822. return
  1823. }
  1824. startTime = theTime.Unix()
  1825. }
  1826. var endTime int64
  1827. if len(end_time) > 0 {
  1828. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1829. if err != nil {
  1830. utils.ErrorLog(err.Error())
  1831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1832. return
  1833. }
  1834. endTime = theTime.Unix()
  1835. }
  1836. adminUserInfo := c.GetAdminUserInfo()
  1837. list, total, err := service.GetAllBaseDurgListCount(page, limit, keyword, drug_type, startTime, endTime, adminUserInfo.CurrentOrgId, storehouse_id, drug_id)
  1838. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  1839. houseList, _ := service.GetAllStoreHouseListOne(adminUserInfo.CurrentOrgId)
  1840. medicalList, _ := service.GetAllBaseDrugStockList(adminUserInfo.CurrentOrgId)
  1841. if err != nil {
  1842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1843. return
  1844. }
  1845. c.ServeSuccessJSON(map[string]interface{}{
  1846. "list": list,
  1847. "total": total,
  1848. "manufacturerList": manufacturerList,
  1849. "houseList": houseList,
  1850. "medicalList": medicalList,
  1851. })
  1852. }
  1853. func (c *GobalConfigApiController) GetDrugStockFllow() {
  1854. drug_id, _ := c.GetInt64("drug_id")
  1855. start_time := c.GetString("start_time")
  1856. end_time := c.GetString("end_time")
  1857. stock_type, _ := c.GetInt64("stock_type")
  1858. page, _ := c.GetInt64("page")
  1859. limit, _ := c.GetInt64("limit")
  1860. timeLayout := "2006-01-02"
  1861. loc, _ := time.LoadLocation("Local")
  1862. var startTime int64
  1863. if len(start_time) > 0 {
  1864. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1865. if err != nil {
  1866. fmt.Println(err)
  1867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1868. return
  1869. }
  1870. startTime = theTime.Unix()
  1871. }
  1872. var endTime int64
  1873. if len(end_time) > 0 {
  1874. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1875. if err != nil {
  1876. utils.ErrorLog(err.Error())
  1877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1878. return
  1879. }
  1880. endTime = theTime.Unix()
  1881. }
  1882. orgId := c.GetAdminUserInfo().CurrentOrgId
  1883. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1884. medical, _ := service.GetBaseDrugMedical(drug_id)
  1885. //查询入库数据
  1886. if stock_type == 3 || stock_type == 0 {
  1887. list, total, err := service.GetDrugStockFlow(drug_id, startTime, endTime, page, limit, orgId)
  1888. if err != nil {
  1889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1890. return
  1891. }
  1892. c.ServeSuccessJSON(map[string]interface{}{
  1893. "list": list,
  1894. "total": total,
  1895. "manufacturerList": manufacturerList,
  1896. "drug": medical,
  1897. })
  1898. }
  1899. }
  1900. func (c *GobalConfigApiController) GetDrugOutStockFlow() {
  1901. drug_id, _ := c.GetInt64("drug_id")
  1902. start_time := c.GetString("start_time")
  1903. end_time := c.GetString("end_time")
  1904. stock_type, _ := c.GetInt64("stock_type")
  1905. page, _ := c.GetInt64("page")
  1906. limit, _ := c.GetInt64("limit")
  1907. timeLayout := "2006-01-02"
  1908. loc, _ := time.LoadLocation("Local")
  1909. var startTime int64
  1910. if len(start_time) > 0 {
  1911. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1912. if err != nil {
  1913. fmt.Println(err)
  1914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1915. return
  1916. }
  1917. startTime = theTime.Unix()
  1918. }
  1919. var endTime int64
  1920. if len(end_time) > 0 {
  1921. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1922. if err != nil {
  1923. utils.ErrorLog(err.Error())
  1924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1925. return
  1926. }
  1927. endTime = theTime.Unix()
  1928. }
  1929. orgId := c.GetAdminUserInfo().CurrentOrgId
  1930. outList, total, err := service.GetDrugStockOutFlow(drug_id, startTime, endTime, page, limit, orgId, stock_type)
  1931. if err != nil {
  1932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1933. return
  1934. }
  1935. c.ServeSuccessJSON(map[string]interface{}{
  1936. "outList": outList,
  1937. "total": total,
  1938. })
  1939. }
  1940. func (c *GobalConfigApiController) GetBatchOrderDetail() {
  1941. drug_id, _ := c.GetInt64("drug_id")
  1942. orgId := c.GetAdminUserInfo().CurrentOrgId
  1943. limit, _ := c.GetInt64("limit")
  1944. page, _ := c.GetInt64("page")
  1945. start_time := c.GetString("start_time")
  1946. end_time := c.GetString("end_time")
  1947. start_first_time := c.GetString("start_first_time")
  1948. end_first_time := c.GetString("end_first_time")
  1949. timeLayout := "2006-01-02"
  1950. loc, _ := time.LoadLocation("Local")
  1951. var startTime int64
  1952. if len(start_time) > 0 {
  1953. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1954. if err != nil {
  1955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1956. return
  1957. }
  1958. startTime = theTime.Unix()
  1959. }
  1960. var endTime int64
  1961. if len(end_time) > 0 {
  1962. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1963. if err != nil {
  1964. utils.ErrorLog(err.Error())
  1965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1966. return
  1967. }
  1968. endTime = theTime.Unix()
  1969. }
  1970. var startFistTime int64
  1971. if len(start_first_time) > 0 {
  1972. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_first_time+" 00:00:00", loc)
  1973. if err != nil {
  1974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1975. return
  1976. }
  1977. startFistTime = theTime.Unix()
  1978. }
  1979. var endFirstTime int64
  1980. if len(end_first_time) > 0 {
  1981. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_first_time+" 23:59:59", loc)
  1982. if err != nil {
  1983. utils.ErrorLog(err.Error())
  1984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1985. return
  1986. }
  1987. endFirstTime = theTime.Unix()
  1988. }
  1989. detail, total, err := service.GetBatchOrderDetail(drug_id, orgId, page, limit, startTime, endTime, startFistTime, endFirstTime)
  1990. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1991. drug, _ := service.GetBaseDrugMedical(drug_id)
  1992. houseList, _ := service.GetAllStoreHouseList(orgId)
  1993. if err != nil {
  1994. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1995. return
  1996. }
  1997. c.ServeSuccessJSON(map[string]interface{}{
  1998. "detail": detail,
  1999. "total": total,
  2000. "manufacturerList": manufacturerList,
  2001. "drug": drug,
  2002. "houseList": houseList,
  2003. })
  2004. }
  2005. func (c *GobalConfigApiController) GetDrugCountList() {
  2006. start_time := c.GetString("start_time")
  2007. end_time := c.GetString("end_time")
  2008. timeLayout := "2006-01-02"
  2009. loc, _ := time.LoadLocation("Local")
  2010. var startTime int64
  2011. if len(start_time) > 0 {
  2012. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2013. if err != nil {
  2014. fmt.Println(err)
  2015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2016. return
  2017. }
  2018. startTime = theTime.Unix()
  2019. }
  2020. var endTime int64
  2021. if len(end_time) > 0 {
  2022. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2023. if err != nil {
  2024. utils.ErrorLog(err.Error())
  2025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2026. return
  2027. }
  2028. endTime = theTime.Unix()
  2029. }
  2030. orgId := c.GetAdminUserInfo().CurrentOrgId
  2031. countList, err := service.GetMinCountList(startTime, endTime, orgId)
  2032. outCountList, _ := service.GetOutDrugCountList(startTime, endTime, orgId)
  2033. auCountList, err := service.GetAutoDrugCountList(startTime, endTime, orgId)
  2034. info, _ := service.GetDrugWarehouOrderInfo(startTime, endTime, orgId)
  2035. cancelCountList, _ := service.GetCancelDrugCountList(startTime, endTime, orgId)
  2036. if err != nil {
  2037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  2038. return
  2039. }
  2040. c.ServeSuccessJSON(map[string]interface{}{
  2041. "outCountList": outCountList,
  2042. "auCountList": auCountList,
  2043. "minCount": countList,
  2044. "info": info,
  2045. "cancelCountList": cancelCountList,
  2046. })
  2047. }
  2048. func (c *GobalConfigApiController) GetSingleOrderDetail() {
  2049. id, _ := c.GetInt64("id")
  2050. start_time, _ := c.GetInt64("start_time")
  2051. orgId := c.GetAdminUserInfo().CurrentOrgId
  2052. list, err := service.GetSingleOrderDetail(id, orgId)
  2053. drugoutlist, _ := service.GetDrugWarehouseOutDetailNighty(id, orgId)
  2054. dealerList, err := service.GetAllDealerList(orgId)
  2055. manufacturerList, err := service.GetAllManufacturerList(orgId)
  2056. drugFlowList, _ := service.GetDrugStockFlowDetail(start_time, orgId)
  2057. flowlist, _ := service.GetSingeOrderFlow(id, orgId)
  2058. drugList, _ := service.GetDrugFlowList(id, orgId)
  2059. drugListOne, _ := service.GetDrugFlowListGroupByIdOne(id, orgId)
  2060. drugListFlow, err := service.GetDrugFlowListGroupById(id, orgId)
  2061. if err != nil {
  2062. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  2063. return
  2064. }
  2065. c.ServeSuccessJSON(map[string]interface{}{
  2066. "list": list,
  2067. "dealerList": dealerList,
  2068. "manufacturerList": manufacturerList,
  2069. "drugFlowList": drugFlowList,
  2070. "flowlist": flowlist,
  2071. "drugList": drugList,
  2072. "drugListFlow": drugListFlow,
  2073. "drugListOne": drugListOne,
  2074. "drugoutlist": drugoutlist,
  2075. })
  2076. }
  2077. func (c *GobalConfigApiController) GetAutoDrugDetail() {
  2078. warehouse_out_id, _ := c.GetInt64("warehouse_out_id")
  2079. id, _ := c.GetInt64("drug_id")
  2080. record_time, _ := c.GetInt64("record_time")
  2081. orgId := c.GetAdminUserInfo().CurrentOrgId
  2082. //获取自动出库
  2083. list, err, total := service.FindDrugStockUserDetailByIdThree(id, record_time, orgId)
  2084. //获取手动出库
  2085. outList, err := service.FindeDrugWarehouserInfo(warehouse_out_id, id, orgId)
  2086. batchNumber, err := service.GetDrugFlowBatch(warehouse_out_id, id, orgId)
  2087. if err != nil {
  2088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  2089. return
  2090. }
  2091. c.ServeSuccessJSON(map[string]interface{}{
  2092. "list": list,
  2093. "total": total,
  2094. "outList": outList,
  2095. "batchNumber": batchNumber,
  2096. })
  2097. }
  2098. func (c *GobalConfigApiController) GetDrugOrderInPrint() {
  2099. id := c.GetString("id")
  2100. ids := strings.Split(id, ",")
  2101. admin := c.GetAdminUserInfo()
  2102. info, _ := service.FindDrugWarehousingByIdOne(ids, admin.CurrentOrgId)
  2103. manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
  2104. warehousingInfo, _ := service.FindDrugWarehousingInfoByIdOne(ids, admin.CurrentOrgId)
  2105. c.ServeSuccessJSON(map[string]interface{}{
  2106. "info": info,
  2107. "warehousing": warehousingInfo,
  2108. "manufacturerList": manufacturerList,
  2109. })
  2110. }
  2111. func (c *GobalConfigApiController) GetDrugOutOrderPrint() {
  2112. id := c.GetString("id")
  2113. ids := strings.Split(id, ",")
  2114. admin := c.GetAdminUserInfo()
  2115. info, _ := service.FindeDrugWarehouseOutOrder(ids, admin.CurrentOrgId)
  2116. manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
  2117. warehousing, _ := service.GetExportOutOrderDrugListOne(ids, admin.CurrentOrgId)
  2118. drug_warhouse_out, _ := service.GetDrugWarehouseOutTenty(ids, admin.CurrentOrgId)
  2119. c.ServeSuccessJSON(map[string]interface{}{
  2120. "info": info,
  2121. "warehousing": warehousing,
  2122. "manufacturerList": manufacturerList,
  2123. "drug_warhouse_out": drug_warhouse_out,
  2124. })
  2125. }
  2126. func (c *GobalConfigApiController) GetDrugBatchNumber() {
  2127. id, _ := c.GetInt64("id")
  2128. orgId := c.GetAdminUserInfo().CurrentOrgId
  2129. list, _ := service.GetDrugBatchNumber(id, orgId)
  2130. c.ServeSuccessJSON(map[string]interface{}{
  2131. "list": list,
  2132. })
  2133. }
  2134. func (c *GobalConfigApiController) ExportDrugList() {
  2135. orderId := c.GetString("order_id")
  2136. ids := strings.Split(orderId, ",")
  2137. orgId := c.GetAdminUserInfo().CurrentOrgId
  2138. list, _ := service.ExportDrugList(ids, orgId)
  2139. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2140. dealerList, _ := service.GetAllDealerList(orgId)
  2141. c.ServeSuccessJSON(map[string]interface{}{
  2142. "list": list,
  2143. "manufacturerList": manufacturerList,
  2144. "dealerList": dealerList,
  2145. })
  2146. }
  2147. func (c *GobalConfigApiController) GetExportOutOrderDrugList() {
  2148. orderId := c.GetString("order_id")
  2149. ids := strings.Split(orderId, ",")
  2150. orgId := c.GetAdminUserInfo().CurrentOrgId
  2151. list, _ := service.GetExportOutOrderDrugListOne(ids, orgId)
  2152. outInfoList, _ := service.GetDrugOutListFlow(ids, orgId)
  2153. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2154. dealerList, _ := service.GetAllDealerList(orgId)
  2155. c.ServeSuccessJSON(map[string]interface{}{
  2156. "list": list,
  2157. "manufacturerList": manufacturerList,
  2158. "dealerList": dealerList,
  2159. "outInfoList": outInfoList,
  2160. })
  2161. }
  2162. func (c *GobalConfigApiController) GetDrugFlow() {
  2163. start_time := c.GetString("start_time")
  2164. end_time := c.GetString("end_time")
  2165. timeLayout := "2006-01-02"
  2166. loc, _ := time.LoadLocation("Local")
  2167. var startTime int64
  2168. if len(start_time) > 0 {
  2169. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2170. if err != nil {
  2171. fmt.Println(err)
  2172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2173. return
  2174. }
  2175. startTime = theTime.Unix()
  2176. }
  2177. var endTime int64
  2178. if len(end_time) > 0 {
  2179. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2180. if err != nil {
  2181. utils.ErrorLog(err.Error())
  2182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2183. return
  2184. }
  2185. endTime = theTime.Unix()
  2186. }
  2187. orgId := c.GetAdminUserInfo().CurrentOrgId
  2188. drug_id, _ := c.GetInt64("drug_id")
  2189. page, _ := c.GetInt64("page")
  2190. limit, _ := c.GetInt64("limit")
  2191. stock_type, _ := c.GetInt64("stock_type")
  2192. list, total, _ := service.GetDrugFlow(drug_id, orgId, limit, page, startTime, endTime, stock_type)
  2193. if len(list) > 0 {
  2194. for _, item := range list {
  2195. adviceMap, _ := service.HisDoctorAdviceMap(item.PatientId, item.SystemTime, item.DrugId, item.UserOrgId)
  2196. item.DrugCode = adviceMap.DrugCode
  2197. }
  2198. }
  2199. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  2200. dealerList, _ := service.GetAllDealerList(orgId)
  2201. medical, _ := service.GetBaseDrugMedical(drug_id)
  2202. houseList, _ := service.GetAllStoreHouseList(orgId)
  2203. patientList, _ := service.GetAllPatientListSix(orgId)
  2204. c.ServeSuccessJSON(map[string]interface{}{
  2205. "list": list,
  2206. "total": total,
  2207. "manufacturerList": manufacturerList,
  2208. "dealerList": dealerList,
  2209. "drug": medical,
  2210. "houseList": houseList,
  2211. "patientList": patientList,
  2212. })
  2213. }
  2214. func (c *GobalConfigApiController) GetCancelStockDetail() {
  2215. id, _ := c.GetInt64("id")
  2216. list, _ := service.GetCancelStockDetail(id)
  2217. c.ServeSuccessJSON(map[string]interface{}{
  2218. "list": list,
  2219. })
  2220. }
  2221. func (c *GobalConfigApiController) ChangeStockSetting() {
  2222. is_type, _ := c.GetInt64("is_type")
  2223. orgId := c.GetAdminUserInfo().CurrentOrgId
  2224. setting := models.XtStockSetting{
  2225. IsType: is_type,
  2226. UserOrgId: orgId,
  2227. Status: 1,
  2228. Ctime: time.Now().Unix(),
  2229. Mtime: 0,
  2230. }
  2231. //查询机该机构是否已经配置
  2232. _, errcode := service.GetStockSettingIsExsit(orgId)
  2233. if errcode == gorm.ErrRecordNotFound {
  2234. service.CreateStockSetting(setting)
  2235. c.ServeSuccessJSON(map[string]interface{}{
  2236. "msg": 1,
  2237. })
  2238. } else if errcode == nil {
  2239. service.UpdateStockSetting(orgId, setting)
  2240. c.ServeSuccessJSON(map[string]interface{}{
  2241. "msg": 1,
  2242. })
  2243. }
  2244. }
  2245. func (c *GobalConfigApiController) ChangeAdviceConfig() {
  2246. is_advice_open, _ := c.GetInt64("is_advice_open")
  2247. orgId := c.GetAdminUserInfo().CurrentOrgId
  2248. setting := models.XtAdviceSetting{
  2249. IsAdviceOpen: is_advice_open,
  2250. UserOrgId: orgId,
  2251. Status: 1,
  2252. Ctime: time.Now().Unix(),
  2253. Mtime: 0,
  2254. }
  2255. //查询是否存在
  2256. _, errcode := service.GetAdviceConfig(orgId)
  2257. if errcode == gorm.ErrRecordNotFound {
  2258. service.CreateAdviceSetting(setting)
  2259. c.ServeSuccessJSON(map[string]interface{}{
  2260. "msg": 1,
  2261. })
  2262. } else if errcode == nil {
  2263. service.UpdateAdviceSetting(orgId, setting)
  2264. c.ServeSuccessJSON(map[string]interface{}{
  2265. "msg": 1,
  2266. })
  2267. }
  2268. }
  2269. func (c *GobalConfigApiController) ChangePrescriptionConfig() {
  2270. is_open_prescription_xt_his, _ := c.GetInt64("is_open_prescription_xt_his")
  2271. orgId := c.GetAdminUserInfo().CurrentOrgId
  2272. _, errcode := service.GetPrescriptionConfig(orgId)
  2273. if errcode == gorm.ErrRecordNotFound {
  2274. config := models.XtPrescriptionConfig{
  2275. UserOrgId: orgId,
  2276. IsOpen: is_open_prescription_xt_his,
  2277. Status: 1,
  2278. Ctime: time.Now().Unix(),
  2279. }
  2280. service.CreatePrescriptionConfig(config)
  2281. c.ServeSuccessJSON(map[string]interface{}{
  2282. "msg": 1,
  2283. })
  2284. } else if errcode == nil {
  2285. config := models.XtPrescriptionConfig{
  2286. UserOrgId: orgId,
  2287. IsOpen: is_open_prescription_xt_his,
  2288. Status: 1,
  2289. Ctime: time.Now().Unix(),
  2290. }
  2291. service.UpdatePrescriptionConfig(orgId, config)
  2292. c.ServeSuccessJSON(map[string]interface{}{
  2293. "msg": 1,
  2294. })
  2295. }
  2296. }
  2297. func (c *GobalConfigApiController) ChangeDrugOpenConfig() {
  2298. drug_out_open, _ := c.GetInt64("drug_out_open")
  2299. orgId := c.GetAdminUserInfo().CurrentOrgId
  2300. if drug_out_open == 1 {
  2301. service.UpdateDrugStockAutomaticReduceRecordOne(orgId, 2)
  2302. service.UpdatePharyConfig(orgId, 2)
  2303. service.UpdateSettleOpenConfigOne(orgId, 2)
  2304. }
  2305. _, errcode := service.GetDrugOpenConfig(orgId)
  2306. if errcode == gorm.ErrRecordNotFound {
  2307. config := models.DrugOutConfig{
  2308. UserOrgId: orgId,
  2309. IsOpen: drug_out_open,
  2310. Status: 1,
  2311. Ctime: time.Now().Unix(),
  2312. }
  2313. service.CreateDrugOutConfig(config)
  2314. c.ServeSuccessJSON(map[string]interface{}{
  2315. "msg": 1,
  2316. })
  2317. } else if errcode == nil {
  2318. service.UpdateDrugOutConfig(orgId, drug_out_open)
  2319. c.ServeSuccessJSON(map[string]interface{}{
  2320. "msg": 1,
  2321. })
  2322. }
  2323. }
  2324. func (this *GobalConfigApiController) ChangeSettleOpenConfig() {
  2325. drug_out_open, _ := this.GetInt64("drug_settle_open")
  2326. orgId := this.GetAdminUserInfo().CurrentOrgId
  2327. config := models.HisSettleStockConfig{
  2328. UserOrgId: orgId,
  2329. Ctime: time.Now().Unix(),
  2330. Mtime: 0,
  2331. Status: 1,
  2332. IsOpen: drug_out_open,
  2333. }
  2334. if drug_out_open == 1 {
  2335. service.UpdateDrugOutConfig(orgId, 2)
  2336. service.UpdateDrugStockAutomaticReduceRecordOne(orgId, 2)
  2337. service.UpdatePharyConfig(orgId, 2)
  2338. service.UpdateGoodAutoConfig(orgId)
  2339. service.UpdateGoodOutConfig(orgId)
  2340. }
  2341. openConfig, errcode := service.GetSettleOpenConfig(orgId)
  2342. if errcode == gorm.ErrRecordNotFound {
  2343. service.CreateSettleOpenConfig(config)
  2344. } else if errcode == nil {
  2345. service.UpdateSettleOpenConfig(openConfig.ID, config)
  2346. }
  2347. this.ServeSuccessJSON(map[string]interface{}{
  2348. "msg": 1,
  2349. })
  2350. }
  2351. func (this *GobalConfigApiController) ChangeGoodOutOpen() {
  2352. good_open, _ := this.GetInt64("good_open")
  2353. orgId := this.GetAdminUserInfo().CurrentOrgId
  2354. config, errcode := service.GetGoodOutOpenConfig(orgId)
  2355. outConfig := models.XtGoodOutConfig{
  2356. UserOrgId: orgId,
  2357. IsOpen: good_open,
  2358. Status: 1,
  2359. Ctime: time.Now().Unix(),
  2360. Mtime: time.Now().Unix(),
  2361. }
  2362. if good_open == 1 {
  2363. service.UpdateGoodAutoConfig(orgId)
  2364. service.UpdateSettleOpenConfigTwo(orgId, 2)
  2365. }
  2366. if errcode == gorm.ErrRecordNotFound {
  2367. service.CreateGoodOutOpenConfig(outConfig)
  2368. } else if errcode == nil {
  2369. service.UpdateGoodOutOpenConfig(config.ID, outConfig)
  2370. }
  2371. this.ServeSuccessJSON(map[string]interface{}{
  2372. "msg": 1,
  2373. })
  2374. }
  2375. func (this *GobalConfigApiController) ChangeSelfPrescriptionOpen() {
  2376. is_open, _ := this.GetInt64("is_open")
  2377. orgId := this.GetAdminUserInfo().CurrentOrgId
  2378. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(orgId)
  2379. config := models.XtSelfDrugInfoConfig{
  2380. ID: selfPrescriptionOpen.ID,
  2381. UserOrgId: orgId,
  2382. Status: 1,
  2383. IsOpen: is_open,
  2384. }
  2385. if selfPrescriptionOpen.ID == 0 {
  2386. service.CreaterSelfConfig(config)
  2387. }
  2388. if selfPrescriptionOpen.ID > 0 {
  2389. service.SaveSelfConfig(config)
  2390. }
  2391. this.ServeSuccessJSON(map[string]interface{}{
  2392. "selfPrescriptionOpen": selfPrescriptionOpen,
  2393. })
  2394. }
  2395. func (this *GobalConfigApiController) ChangeSelfPrescriptionOutOpen() {
  2396. orgId := this.GetAdminUserInfo().CurrentOrgId
  2397. is_open, _ := this.GetInt64("is_open")
  2398. selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(orgId)
  2399. config := models.XtSelfDrugOutConfig{
  2400. ID: selfPrescriptionOutOpen.ID,
  2401. UserOrgId: orgId,
  2402. IsOpen: is_open,
  2403. Status: 1,
  2404. }
  2405. if config.ID == 0 {
  2406. service.CreateSelfDrugOutConfig(config)
  2407. }
  2408. if config.ID > 0 {
  2409. service.UpdateSelfDrugOutConfig(config)
  2410. }
  2411. this.ServeSuccessJSON(map[string]interface{}{
  2412. "selfPrescriptionOutOpen": selfPrescriptionOutOpen,
  2413. })
  2414. }
  2415. func (this *GobalConfigApiController) GetSelfPrintList() {
  2416. orgId := this.GetAdminUserInfo().CurrentOrgId
  2417. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(orgId)
  2418. selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(orgId)
  2419. this.ServeSuccessJSON(map[string]interface{}{
  2420. "selfPrescriptionOpen": selfPrescriptionOpen,
  2421. "selfPrescriptionOutOpen": selfPrescriptionOutOpen,
  2422. })
  2423. }
  2424. func (this *GobalConfigApiController) ChangeDrugCodeOpen() {
  2425. orgId := this.GetAdminUserInfo().CurrentOrgId
  2426. is_open, _ := this.GetInt64("is_open")
  2427. drugCodeOpen, _ := service.GetDrugCodeOpen(orgId)
  2428. if drugCodeOpen.ID == 0 {
  2429. codeOpen := models.XtDrugCodeOpen{
  2430. UserOrgId: orgId,
  2431. IsOpen: is_open,
  2432. Status: 1,
  2433. Ctime: time.Now().Unix(),
  2434. Mtime: time.Now().Unix(),
  2435. }
  2436. service.CreateDrugOpen(codeOpen)
  2437. }
  2438. if drugCodeOpen.ID == 1 {
  2439. codeOpen := models.XtDrugCodeOpen{
  2440. ID: drugCodeOpen.ID,
  2441. UserOrgId: orgId,
  2442. IsOpen: is_open,
  2443. Status: 1,
  2444. Ctime: time.Now().Unix(),
  2445. Mtime: time.Now().Unix(),
  2446. }
  2447. service.SaveDrugOpen(codeOpen)
  2448. }
  2449. this.ServeSuccessJSON(map[string]interface{}{
  2450. "drugCodeOpen": drugCodeOpen,
  2451. })
  2452. }