his_api_controller.go 181KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301
  1. package sg
  2. import (
  3. "archive/zip"
  4. "bytes"
  5. "encoding/json"
  6. "fmt"
  7. "gdyb/controllers"
  8. "gdyb/enums"
  9. "gdyb/models"
  10. "gdyb/service"
  11. "gdyb/utils"
  12. "github.com/astaxie/beego"
  13. "github.com/jinzhu/gorm"
  14. "github.com/shopspring/decimal"
  15. "io"
  16. "io/ioutil"
  17. "math/rand"
  18. "net/http"
  19. "os"
  20. "path/filepath"
  21. "strconv"
  22. "strings"
  23. "syscall"
  24. "time"
  25. "unsafe"
  26. )
  27. type HisApiController struct {
  28. controllers.BaseAuthAPIController
  29. }
  30. func HisManagerApiRegistRouters() {
  31. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  32. beego.Router("/api/diag/upload", &HisApiController{}, "get:GetUploadDiag")
  33. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  34. beego.Router("/api/settle/query", &HisApiController{}, "get:GetSettleAccounts")
  35. beego.Router("/api/checkaccount/get", &HisApiController{}, "get:GetCheckAccount")
  36. beego.Router("/api/checkdetailaccount/get", &HisApiController{}, "get:GetCheckDetailAccount")
  37. beego.Router("/api/refund/post", &HisApiController{}, "get:Refund")
  38. beego.Router("/api/sscard", &HisApiController{}, "get:Sscard")
  39. beego.Router("/api/refundnumber/post", &HisApiController{}, "get:RefundNumber")
  40. beego.Router("/api/refunddetail/post", &HisApiController{}, "get:RefundDetail")
  41. beego.Router("/api/treatment/check", &HisApiController{}, "get:CheckTreatment")
  42. beego.Router("/api/record/put", &HisApiController{}, "get:PutRecord")
  43. //beego.Router("/api/patient/info", &HisApiController{}, "get:GetHisPatientInfo")
  44. beego.Router("/api/org/info", &HisApiController{}, "get:GetOrgInfo")
  45. //beego.Router("/api/testcard", &HisApiController{}, "get:TestGetBasBaseInfo")
  46. //beego.Router("/api/testpay", &HisApiController{}, "get:TestPay")
  47. beego.Router("/api/pre_upload/get", &HisApiController{}, "get:GetPreUploadInfo")
  48. //beego.Router("/api/settle/get", &HisApiController{}, "get:GetSettleInfo")
  49. beego.Router("/api/310", &HisApiController{}, "get:Check310")
  50. beego.Router("/api/390", &HisApiController{}, "get:Check390")
  51. beego.Router("/api/patient/info", &HisApiController{}, "get:GetPatientInfo")
  52. //备案撤销相关接口
  53. beego.Router("/api/checkcode/get", &HisApiController{}, "get:GetCheckCode")
  54. beego.Router("/api/uncheckcode/get", &HisApiController{}, "get:UnCheckCode")
  55. beego.Router("/api/psn/putonrecord", &HisApiController{}, "get:PsnPutOnRecord")
  56. beego.Router("/api/psn/unputonrecord", &HisApiController{}, "get:PsnUnPutOnRecord")
  57. beego.Router("/api/psn/ncds/putonrecord", &HisApiController{}, "get:PsnPutNCDSOnRecord")
  58. beego.Router("/api/psn/ncds/unputonrecord", &HisApiController{}, "get:PsnPutUnNCDSOnRecord")
  59. beego.Router("/api/test", &HisApiController{}, "get:TestGetBasBaseInfo")
  60. beego.Router("/api/reversal", &HisApiController{}, "get:ReversalData")
  61. beego.Router("/api/reversal/other", &HisApiController{}, "get:ReversalOtherData")
  62. //beego.Router("/api/reversal/one", &HisApiController{}, "get:ReversalOtherOneData")
  63. beego.Router("/api/settlelist/get", &HisApiController{}, "get:GetSettleList")
  64. //beego.Router("/api/settlelist/get", &HisApiController{}, "get:GetSettleList")
  65. }
  66. type CustomFundPay struct {
  67. FundPayType string `json:"fund_pay_type"`
  68. FundPayamt float64 `json:"fund_payamt"`
  69. }
  70. func (c *HisApiController) GetSettleList() {
  71. order_id, _ := c.GetInt64("order_id")
  72. admin_user_id, _ := c.GetInt64("admin_user_id")
  73. order, _ := service.GetHisOrderByIDTwo(order_id)
  74. roles, _ := service.GetDoctorListTwo(c.GetAdminUserInfo().CurrentOrgId)
  75. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  76. admin, _ := service.GetAdminUserByUserID(roles[0].AdminUserId)
  77. curRoles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  78. depart, _ := service.GetDepartMentDetail(curRoles.DepartmentId)
  79. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  80. if order.ID == 0 {
  81. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  82. return
  83. }
  84. struct4101 := service.Struct4101{
  85. PsnNo: order.PsnNo,
  86. MdtrtId: order.MdtrtId,
  87. SetlId: order.SetlId,
  88. PsnName: order.PsnName,
  89. Gend: order.Gend,
  90. Brdy: his.Brdy,
  91. Age: his.Age,
  92. Naty: order.Naty,
  93. PatnCertType: "01",
  94. Certno: order.Certno,
  95. Prfs: "90",
  96. ConerName: roles[0].UserName,
  97. PatnRlts: "99",
  98. ConerAddr: miConfig.OrgName,
  99. ConerTel: admin.Mobile,
  100. HiType: order.Insutype,
  101. Insuplc: miConfig.InsuplcAdmdvs,
  102. MaindiagFlag: "1",
  103. BillCode: order.FaPiaoCode,
  104. BillNo: order.FaPiaoNumber,
  105. BizSn: order.Number,
  106. PsnSelfPay: order.PsnPartAmt,
  107. PsnOwnPay: order.PsnPartAmt,
  108. AcctPay: order.AcctPay,
  109. PsnCashpay: order.PsnCashPay,
  110. HiPaymtd: "1",
  111. Hsorg: miConfig.InsuplcAdmdvs,
  112. HsorgOpter: miConfig.InsuplcAdmdvs,
  113. MedinsFillPsn: curRoles.UserName,
  114. MedinsFillDept: depart.Name,
  115. IptMedType: "2",
  116. }
  117. if order.SettleType == 1 {
  118. t := time.Unix(int64(order.SettleAccountsDate), 0)
  119. dateStr := t.Format("2006-01-02")
  120. struct4101.SetlBegnDate = dateStr
  121. struct4101.SetlEndDate = dateStr
  122. } else {
  123. t := time.Unix(int64(order.SettleStartTime), 0)
  124. t2 := time.Unix(int64(order.SettleEndTime), 0)
  125. dateStartStr := t.Format("2006-01-02")
  126. dateEndStr := t2.Format("2006-01-02")
  127. struct4101.SetlBegnDate = dateStartStr
  128. struct4101.SetlEndDate = dateEndStr
  129. }
  130. var rf []CustomFundPay
  131. json.Unmarshal([]byte(order.SetlDetail), &rf)
  132. var tempFunPays []service.CustomStruct
  133. for _, item := range rf {
  134. var tempFunPay service.CustomStruct
  135. tempFunPay.FundPayamt = item.FundPayamt
  136. tempFunPay.FundPayType = item.FundPayType
  137. tempFunPays = append(tempFunPays, tempFunPay)
  138. }
  139. struct4101.CustomStruct = tempFunPays
  140. var tempOpspdiseinfos []service.OpspdiseinfoStruct
  141. var tempOpspdiseinfo service.OpspdiseinfoStruct
  142. var tempOpspdiseinfo2 service.OpspdiseinfoStruct
  143. sickConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  144. sickConfigTwo, _ := service.FindSickById(his.SickType)
  145. tempOpspdiseinfo.DiagCode = sickConfig.CountryCode
  146. tempOpspdiseinfo.DiagName = sickConfig.CountryContentName
  147. tempOpspdiseinfo.MaindiagFlag = "1"
  148. tempOpspdiseinfo.OprnOprtCode = ""
  149. tempOpspdiseinfo.OprnOprtName = ""
  150. tempOpspdiseinfos = append(tempOpspdiseinfos, tempOpspdiseinfo)
  151. tempOpspdiseinfo2.DiagCode = sickConfigTwo.CountryCode
  152. tempOpspdiseinfo2.DiagName = sickConfigTwo.CountryContentName
  153. tempOpspdiseinfo2.MaindiagFlag = "2"
  154. tempOpspdiseinfo2.OprnOprtCode = ""
  155. tempOpspdiseinfo2.OprnOprtName = ""
  156. tempOpspdiseinfos = append(tempOpspdiseinfos, tempOpspdiseinfo2)
  157. struct4101.OpspdiseinfoStruct = tempOpspdiseinfos
  158. var iteminfo service.IteminfoStruct
  159. var bedCostTotal float64 = 0 //床位总费
  160. var bedCostSelfTotal float64 = 0 //床位自费
  161. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  162. var operationCostTotal float64 = 0 //手术费
  163. var operationCostSelfTotal float64 = 0 //手术费
  164. var operationCostPartSelfTotal float64 = 0 //手术费
  165. var otherCostTotal float64 = 0 //其他费用
  166. var otherCostSelfTotal float64 = 0 //其他费用
  167. var otherCostPartSelfTotal float64 = 0 //其他费用
  168. var materialCostTotal float64 = 0 //材料费
  169. var materialCostSelfTotal float64 = 0 //材料费
  170. var materialCostPartSelfTotal float64 = 0 //材料费
  171. var westernMedicineCostTotal float64 = 0 //西药费
  172. var westernMedicineCostSelfTotal float64 = 0 //西药费
  173. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  174. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  175. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  176. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  177. var checkCostTotal float64 = 0 //检查费
  178. var checkCostSelfTotal float64 = 0 //检查费
  179. var checkCostPartSelfTotal float64 = 0 //检查费
  180. var laboratoryCostTotal float64 = 0 //化验费
  181. var laboratoryCostSelfTotal float64 = 0 //化验费
  182. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  183. var treatCostTotal float64 = 0 //治疗费用
  184. var treatCostSelfTotal float64 = 0 //治疗费用
  185. var treatCostPartSelfTotal float64 = 0 //治疗费用
  186. decimal.DivisionPrecision = 2
  187. var bed_fulamt_ownpay_amt float64 = 0
  188. var operation_fulamt_ownpay_amt float64 = 0
  189. var other_fulamt_ownpay_amt float64 = 0
  190. var westernMedicine_fulamt_ownpay_amt float64 = 0
  191. var chineseTraditional_fulamt_ownpay_amt float64 = 0
  192. var check_fulamt_ownpay_amt float64 = 0
  193. var material_fulamt_ownpay_amt float64 = 0
  194. var laboratory_fulamt_ownpay_amt float64 = 0
  195. var treat_fulamt_ownpay_amt float64 = 0
  196. var bed_claa_sunmfee float64 = 0
  197. var bed_clab_amt float64 = 0
  198. var bed_other_amt float64 = 0
  199. var operation_claa_sunmfee float64 = 0
  200. var operation_clab_amt float64 = 0
  201. var operation_other_amt float64 = 0
  202. var other_claa_sunmfee float64 = 0
  203. var other_clab_amt float64 = 0
  204. var other_other_amt float64 = 0
  205. var westernMedicine_claa_sunmfee float64 = 0
  206. var westernMedicine_clab_amt float64 = 0
  207. var westernMedicine_other_amt float64 = 0
  208. var chineseTraditional_claa_sunmfee float64 = 0
  209. var chineseTraditional_clab_amt float64 = 0
  210. var chineseTraditional_other_amt float64 = 0
  211. var check_claa_sunmfee float64 = 0
  212. var check_clab_amt float64 = 0
  213. var check_other_amt float64 = 0
  214. var material_claa_sunmfee float64 = 0
  215. var material_clab_amt float64 = 0
  216. var material_other_amt float64 = 0
  217. var laboratory_claa_sunmfee float64 = 0
  218. var laboratory_clab_amt float64 = 0
  219. var laboratory_other_amt float64 = 0
  220. var treat_claa_sunmfee float64 = 0
  221. var treat_clab_amt float64 = 0
  222. var treat_other_amt float64 = 0
  223. for _, item := range order.HisOrderInfo {
  224. if item.MedChrgitmType == "01" { //床位费
  225. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  226. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  227. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  228. bed_fulamt_ownpay_amt, _ = decimal.NewFromFloat(bed_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  229. if item.ChrgitmLv == "1" {
  230. bed_claa_sunmfee, _ = decimal.NewFromFloat(bed_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  231. }
  232. if item.ChrgitmLv == "2" {
  233. bed_clab_amt, _ = decimal.NewFromFloat(bed_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  234. }
  235. if item.ChrgitmLv == "3" {
  236. bed_other_amt, _ = decimal.NewFromFloat(bed_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  237. }
  238. }
  239. if item.MedChrgitmType == "03" { //检查费
  240. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  241. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  242. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  243. check_fulamt_ownpay_amt, _ = decimal.NewFromFloat(check_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  244. if item.ChrgitmLv == "1" {
  245. check_claa_sunmfee, _ = decimal.NewFromFloat(check_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  246. }
  247. if item.ChrgitmLv == "2" {
  248. check_clab_amt, _ = decimal.NewFromFloat(check_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  249. }
  250. if item.ChrgitmLv == "3" {
  251. check_other_amt, _ = decimal.NewFromFloat(check_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  252. }
  253. }
  254. if item.MedChrgitmType == "04" { //化验费
  255. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  256. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  257. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  258. laboratory_fulamt_ownpay_amt, _ = decimal.NewFromFloat(laboratory_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  259. if item.ChrgitmLv == "1" {
  260. laboratory_claa_sunmfee, _ = decimal.NewFromFloat(laboratory_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  261. }
  262. if item.ChrgitmLv == "2" {
  263. laboratory_clab_amt, _ = decimal.NewFromFloat(laboratory_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  264. }
  265. if item.ChrgitmLv == "3" {
  266. laboratory_other_amt, _ = decimal.NewFromFloat(laboratory_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  267. }
  268. }
  269. if item.MedChrgitmType == "05" { //治疗费
  270. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  271. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  272. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  273. treat_fulamt_ownpay_amt, _ = decimal.NewFromFloat(treat_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  274. if item.ChrgitmLv == "1" {
  275. treat_claa_sunmfee, _ = decimal.NewFromFloat(treat_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  276. }
  277. if item.ChrgitmLv == "2" {
  278. treat_clab_amt, _ = decimal.NewFromFloat(treat_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  279. }
  280. if item.ChrgitmLv == "3" {
  281. treat_other_amt, _ = decimal.NewFromFloat(treat_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  282. }
  283. }
  284. if item.MedChrgitmType == "06" { //手术费
  285. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  286. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  287. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  288. operation_fulamt_ownpay_amt, _ = decimal.NewFromFloat(operation_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  289. if item.ChrgitmLv == "1" {
  290. operation_claa_sunmfee, _ = decimal.NewFromFloat(operation_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  291. }
  292. if item.ChrgitmLv == "2" {
  293. operation_clab_amt, _ = decimal.NewFromFloat(operation_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  294. }
  295. if item.ChrgitmLv == "3" {
  296. operation_other_amt, _ = decimal.NewFromFloat(operation_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  297. }
  298. }
  299. if item.MedChrgitmType == "08" { //材料费
  300. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  301. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  302. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  303. material_fulamt_ownpay_amt, _ = decimal.NewFromFloat(material_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  304. if item.ChrgitmLv == "1" {
  305. material_claa_sunmfee, _ = decimal.NewFromFloat(material_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  306. }
  307. if item.ChrgitmLv == "2" {
  308. material_clab_amt, _ = decimal.NewFromFloat(material_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  309. }
  310. if item.ChrgitmLv == "3" {
  311. material_other_amt, _ = decimal.NewFromFloat(material_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  312. }
  313. }
  314. if item.MedChrgitmType == "09" { //西药费
  315. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  316. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  317. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  318. westernMedicine_fulamt_ownpay_amt, _ = decimal.NewFromFloat(westernMedicine_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  319. if item.ChrgitmLv == "1" {
  320. westernMedicine_claa_sunmfee, _ = decimal.NewFromFloat(westernMedicine_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  321. }
  322. if item.ChrgitmLv == "2" {
  323. westernMedicine_clab_amt, _ = decimal.NewFromFloat(westernMedicine_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  324. }
  325. if item.ChrgitmLv == "3" {
  326. westernMedicine_other_amt, _ = decimal.NewFromFloat(westernMedicine_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  327. }
  328. }
  329. if item.MedChrgitmType == "11" { //中成费
  330. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  331. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  332. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  333. chineseTraditional_fulamt_ownpay_amt, _ = decimal.NewFromFloat(chineseTraditional_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  334. if item.ChrgitmLv == "1" {
  335. chineseTraditional_claa_sunmfee, _ = decimal.NewFromFloat(chineseTraditional_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  336. }
  337. if item.ChrgitmLv == "2" {
  338. chineseTraditional_clab_amt, _ = decimal.NewFromFloat(chineseTraditional_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  339. }
  340. if item.ChrgitmLv == "3" {
  341. chineseTraditional_other_amt, _ = decimal.NewFromFloat(chineseTraditional_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  342. }
  343. }
  344. if item.MedChrgitmType == "14" { //其他费
  345. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  346. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  347. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  348. other_fulamt_ownpay_amt, _ = decimal.NewFromFloat(other_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  349. if item.ChrgitmLv == "1" {
  350. other_claa_sunmfee, _ = decimal.NewFromFloat(other_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  351. }
  352. if item.ChrgitmLv == "2" {
  353. other_clab_amt, _ = decimal.NewFromFloat(other_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  354. }
  355. if item.ChrgitmLv == "3" {
  356. other_other_amt, _ = decimal.NewFromFloat(other_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  357. }
  358. }
  359. }
  360. var iteminfoStructs []service.IteminfoStruct
  361. if bedCostTotal != 0 {
  362. iteminfo.MedChrgitm = "01"
  363. iteminfo.FulamtOwnpayAmt = bed_fulamt_ownpay_amt
  364. iteminfo.Amt = bedCostTotal
  365. iteminfo.ClaaSumfee = bed_claa_sunmfee
  366. iteminfo.ClabAmt = bed_clab_amt
  367. iteminfo.OthAmt = bed_other_amt
  368. iteminfoStructs = append(iteminfoStructs, iteminfo)
  369. }
  370. if checkCostTotal != 0 {
  371. iteminfo.MedChrgitm = "03"
  372. iteminfo.FulamtOwnpayAmt = check_fulamt_ownpay_amt
  373. iteminfo.Amt = checkCostTotal
  374. iteminfo.ClaaSumfee = check_claa_sunmfee
  375. iteminfo.ClabAmt = check_clab_amt
  376. iteminfo.OthAmt = check_other_amt
  377. iteminfoStructs = append(iteminfoStructs, iteminfo)
  378. }
  379. if laboratoryCostTotal != 0 {
  380. iteminfo.MedChrgitm = "04"
  381. iteminfo.FulamtOwnpayAmt = laboratory_fulamt_ownpay_amt
  382. iteminfo.Amt = laboratoryCostTotal
  383. iteminfo.ClaaSumfee = laboratory_claa_sunmfee
  384. iteminfo.ClabAmt = laboratory_clab_amt
  385. iteminfo.OthAmt = laboratory_other_amt
  386. iteminfoStructs = append(iteminfoStructs, iteminfo)
  387. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  388. }
  389. if treatCostTotal != 0 {
  390. iteminfo.MedChrgitm = "05"
  391. iteminfo.FulamtOwnpayAmt = treat_fulamt_ownpay_amt
  392. iteminfo.Amt = treatCostTotal
  393. iteminfo.ClaaSumfee = treat_claa_sunmfee
  394. iteminfo.ClabAmt = treat_clab_amt
  395. iteminfo.OthAmt = treat_other_amt
  396. iteminfoStructs = append(iteminfoStructs, iteminfo)
  397. // (struct4101.IteminfoStruct, iteminfo)
  398. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  399. }
  400. if operationCostTotal != 0 {
  401. iteminfo.MedChrgitm = "06"
  402. iteminfo.FulamtOwnpayAmt = bed_fulamt_ownpay_amt
  403. iteminfo.Amt = operationCostTotal
  404. iteminfo.ClaaSumfee = operation_claa_sunmfee
  405. iteminfo.ClabAmt = operation_clab_amt
  406. iteminfo.OthAmt = operation_other_amt
  407. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  408. iteminfoStructs = append(iteminfoStructs, iteminfo)
  409. }
  410. if materialCostTotal != 0 {
  411. iteminfo.MedChrgitm = "08"
  412. iteminfo.FulamtOwnpayAmt = material_fulamt_ownpay_amt
  413. iteminfo.Amt = materialCostTotal
  414. iteminfo.ClaaSumfee = material_claa_sunmfee
  415. iteminfo.ClabAmt = material_clab_amt
  416. iteminfo.OthAmt = material_other_amt
  417. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  418. iteminfoStructs = append(iteminfoStructs, iteminfo)
  419. }
  420. if westernMedicineCostTotal != 0 {
  421. iteminfo.MedChrgitm = "09"
  422. iteminfo.FulamtOwnpayAmt = westernMedicine_fulamt_ownpay_amt
  423. iteminfo.Amt = westernMedicineCostTotal
  424. iteminfo.ClaaSumfee = westernMedicine_claa_sunmfee
  425. iteminfo.ClabAmt = westernMedicine_clab_amt
  426. iteminfo.OthAmt = westernMedicine_other_amt
  427. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  428. iteminfoStructs = append(iteminfoStructs, iteminfo)
  429. }
  430. if chineseTraditionalMedicineCostTotal != 0 {
  431. iteminfo.MedChrgitm = "11"
  432. iteminfo.FulamtOwnpayAmt = westernMedicine_fulamt_ownpay_amt
  433. iteminfo.Amt = westernMedicineCostTotal
  434. iteminfo.ClaaSumfee = westernMedicine_claa_sunmfee
  435. iteminfo.ClabAmt = westernMedicine_clab_amt
  436. iteminfo.OthAmt = westernMedicine_other_amt
  437. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  438. iteminfoStructs = append(iteminfoStructs, iteminfo)
  439. }
  440. if otherCostTotal != 0 {
  441. iteminfo.MedChrgitm = "14"
  442. iteminfo.FulamtOwnpayAmt = other_fulamt_ownpay_amt
  443. iteminfo.Amt = otherCostTotal
  444. iteminfo.ClaaSumfee = other_claa_sunmfee
  445. iteminfo.ClabAmt = other_clab_amt
  446. iteminfo.OthAmt = other_other_amt
  447. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  448. iteminfoStructs = append(iteminfoStructs, iteminfo)
  449. }
  450. struct4101.IteminfoStruct = iteminfoStructs
  451. struct4101.Ntly = "中国"
  452. struct4101.AdmCaty = "A03.06"
  453. result := service.Gdyb4101(struct4101, miConfig.SecretKey, miConfig.OrgName, curRoles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  454. fmt.Println(result)
  455. var dat map[string]interface{}
  456. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  457. fmt.Println(dat)
  458. } else {
  459. fmt.Println(err)
  460. }
  461. userJSONBytes, _ := json.Marshal(dat)
  462. var res ResultSeventeen
  463. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  464. utils.ErrorLog("解析失败:%v", err)
  465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  466. return
  467. }
  468. if res.Infcode != 0 {
  469. c.ServeSuccessJSON(map[string]interface{}{
  470. "failed_code": -10,
  471. "msg": res.ErrMsg,
  472. })
  473. return
  474. } else {
  475. hisFundSettleListResult := &models.HisFundSettleListResult{
  476. Number: res.Output.Data.SetlListId,
  477. Status: 1,
  478. Ctime: time.Now().Unix(),
  479. Mtime: time.Now().Unix(),
  480. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  481. IsUpload: 1,
  482. }
  483. service.CreateUploadRecord(hisFundSettleListResult)
  484. c.ServeSuccessJSON(map[string]interface{}{
  485. "msg": "上传成功",
  486. "result": hisFundSettleListResult,
  487. })
  488. return
  489. }
  490. }
  491. func (c *HisApiController) TestGetBasBaseInfo() {
  492. DllDef := syscall.MustLoadDLL("SSCard.dll")
  493. Iinit := DllDef.MustFindProc("Init")
  494. readCard := DllDef.MustFindProc("ReadCardBas")
  495. ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  496. if ret != 0 {
  497. fmt.Println("SSCard的报错原因:", err)
  498. fmt.Println("SSCard的运算结果为:", ret)
  499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  500. return
  501. }
  502. result := int(ret)
  503. fmt.Println("SSCard的运算结果为1:", result)
  504. if readCard == nil {
  505. fmt.Println("readcard is nil")
  506. readCard = DllDef.MustFindProc("ReadCardBas")
  507. }
  508. if readCard == nil {
  509. fmt.Println("readcard reload is nil")
  510. return
  511. }
  512. str := make([]byte, 1024)
  513. str1 := make([]byte, 1024)
  514. cdat := len(str)
  515. cdat1 := len(str1)
  516. p := *((*int32)(unsafe.Pointer(&str[0])))
  517. p1 := *((*int32)(unsafe.Pointer(&str1[0])))
  518. ret2, _, err2 := readCard.Call(uintptr(p), uintptr(cdat), uintptr(p1), uintptr(cdat1))
  519. fmt.Println(" Add(4,5)的结果为:", ret2)
  520. str11 := prttostr(uintptr(p))
  521. str22 := prttostr(uintptr(p1))
  522. fmt.Println(" str:", str11)
  523. fmt.Println(" str1:", str22)
  524. // runtime.GC()
  525. if err2 != nil {
  526. fmt.Println("SSCard的运算结果为:", ret2)
  527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  528. return
  529. }
  530. }
  531. func prttostr(vcode uintptr) string {
  532. var vbyte []byte
  533. for i := 0; i < 10; i++ {
  534. sbyte := *((*byte)(unsafe.Pointer(vcode)))
  535. if sbyte == 0 {
  536. break
  537. }
  538. vbyte = append(vbyte, sbyte)
  539. vcode += 1
  540. }
  541. return string(vbyte)
  542. }
  543. //func (c *HisApiController) TestPay() {
  544. // DllDef2 := syscall.MustLoadDLL("SSSE32.dll")
  545. // readCards := DllDef2.MustFindProc("BankTrans")
  546. // inputData := make(map[string]interface{})
  547. // inputData["transId"] = "05"
  548. // inputData["amount"] = "0.01"
  549. // inputData["traceNo"] = "20210227093601325405377"
  550. // inputData["cardNo"] = "F36084348"
  551. // inputData["id"] = "44022919620927046X"
  552. // //jsonStr := `
  553. // // {
  554. // // "transId": "05",
  555. // // "amount":"1.00",
  556. // // "traceNo":"20210227093601325405377",
  557. // // "cardNo":"F36084348",
  558. // // "id":"44022919620927046X"
  559. // //
  560. // // }
  561. // //`
  562. //
  563. // bytes_arr, _ := json.Marshal(inputData)
  564. // str3 := make([]byte, 256)
  565. // ret4, _, err4 := readCards.Call(StrPtr(string(bytes_arr)), (uintptr)(unsafe.Pointer(&str3[0])))
  566. // fmt.Println(":", string(str3))
  567. //
  568. // if err4 != nil {
  569. // fmt.Println("SSCard的运算结果为:", ret4)
  570. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  571. // return
  572. // }
  573. //
  574. //}
  575. //func (c *HisApiController) TestGetBasBaseInfo() {
  576. //
  577. // //result := C.Init(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  578. // //fmt.Println(result)
  579. // //cs1 := C.CString("")
  580. // //cs2 := C.CString("")
  581. // //C.ReadCardBas(cs1, IntPtr(1024), cs2, IntPtr(1024))
  582. // //fmt.Println(cs1)
  583. // //fmt.Println(cs2)
  584. // //C.free(unsafe.Pointer(cs1))
  585. // //C.free(unsafe.Pointer(cs2))
  586. //
  587. // //
  588. //
  589. // DllDef := syscall.MustLoadDLL("SSCard.dll")
  590. // Iinit := DllDef.MustFindProc("Init")
  591. // readCard := DllDef.MustFindProc("ReadCardBas")
  592. // ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  593. // if ret != 0 {
  594. // fmt.Println("SSCard的报错原因:", err)
  595. // fmt.Println("SSCard的运算结果为:", ret)
  596. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  597. // return
  598. // }
  599. //
  600. // result := int(ret)
  601. // fmt.Println("SSCard的运算结果为1:", result)
  602. //
  603. // //path := ""
  604. // //bytePath := []byte( "\x00")
  605. // //bytePath2 := []byte( "\x00")
  606. // //ssss
  607. //
  608. // str := make([]byte, 256)
  609. // str1 := make([]byte, 256)
  610. // s2 := []byte(string(str))
  611. // s3 := []byte(string(str1))
  612. // ret2, _, err2 := readCard.Call((uintptr)(unsafe.Pointer(&s2[0])), IntPtr(256), (uintptr)(unsafe.Pointer(&s3[0])), IntPtr(256))
  613. // fmt.Println(" Add(4,5)的结果为:", ret2)
  614. // fmt.Println(" str:", s2)
  615. // fmt.Println(" str1:", s3)
  616. // if err2 != nil {
  617. // fmt.Println("SSCard的运算结果为:", ret2)
  618. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  619. // return
  620. // }
  621. //
  622. // //DllDef := syscall.MustLoadDLL("SSCard.dll")
  623. //
  624. //}
  625. func (c *HisApiController) GetOrgInfo() {
  626. miConfig, _ := service.FindMedicalInsuranceInfo(9919)
  627. service.Gdyb1201("", miConfig.OrgName, "1122", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 1, "")
  628. }
  629. func (c *HisApiController) GetHisPatientInfo() {
  630. medical_insurance_card := c.GetString("medical_insurance_card")
  631. id_card_type, _ := c.GetInt64("id_card_type")
  632. id_card := c.GetString("id_card")
  633. adminInfo := c.GetAdminUserInfo()
  634. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  635. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  636. appRole, _ := service.GetAppRole(adminInfo.CurrentOrgId)
  637. IdCardNo := ""
  638. if id_card_type == 1 {
  639. IdCardNo = medical_insurance_card
  640. } else if id_card_type == 2 {
  641. IdCardNo = id_card
  642. }
  643. if config.IsOpen == 1 {
  644. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  645. resp, requestErr := http.Get(api)
  646. if requestErr != nil {
  647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  648. return
  649. }
  650. defer resp.Body.Close()
  651. body, ioErr := ioutil.ReadAll(resp.Body)
  652. if ioErr != nil {
  653. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  655. return
  656. }
  657. var respJSON map[string]interface{}
  658. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  659. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  661. return
  662. }
  663. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  664. userJSONBytes, _ := json.Marshal(userJSON)
  665. var res ResultTwo
  666. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  667. utils.ErrorLog("解析失败:%v", err)
  668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  669. return
  670. }
  671. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  672. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  673. infoStr := string(Iinfos)
  674. idetinfoStr := string(Idetinfos)
  675. if res.Infcode == 0 {
  676. his := models.VMHisPatient{
  677. Status: 1,
  678. Ctime: time.Now().Unix(),
  679. Mtime: time.Now().Unix(),
  680. PsnNo: res.Output.Baseinfo.PsnNo,
  681. PsnCertType: res.Output.Baseinfo.PsnCertType,
  682. Certno: res.Output.Baseinfo.Certno,
  683. PsnName: res.Output.Baseinfo.PsnName,
  684. Gend: res.Output.Baseinfo.Gend,
  685. Naty: res.Output.Baseinfo.Naty,
  686. Brdy: res.Output.Baseinfo.Brdy,
  687. Age: res.Output.Baseinfo.Age,
  688. Iinfo: infoStr,
  689. Idetinfo: idetinfoStr,
  690. UserOrgId: adminInfo.CurrentOrgId,
  691. IsReturn: 1,
  692. IdCardType: id_card_type,
  693. }
  694. c.ServeSuccessJSON(map[string]interface{}{
  695. "info": his,
  696. })
  697. } else {
  698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  699. return
  700. }
  701. }
  702. }
  703. func (c *HisApiController) Sscard() {
  704. //id_card_type, _ := c.GetInt64("id_card_type")
  705. //adminUser := c.GetAdminUserInfo()
  706. //miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  707. id_card_type := 1
  708. r := CardInit()
  709. fmt.Println(r)
  710. //if r == 0 {
  711. switch id_card_type {
  712. case 1:
  713. //defer GetBasBaseInfo()
  714. //if err != nil {
  715. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  716. // return
  717. //
  718. //} else {
  719. // fmt.Println(basStr)
  720. //
  721. // bas := strings.Split(basStr, "|")
  722. //
  723. // basNumber := bas[1]
  724. //
  725. // //basNumber := bas[2]
  726. // card_sn := bas[3]
  727. //
  728. // appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
  729. //
  730. // api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + basNumber + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10) + "&card_sn=" + card_sn
  731. // resp, requestErr := http.Get(api)
  732. // if requestErr != nil {
  733. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  734. // return
  735. // }
  736. // defer resp.Body.Close()
  737. // body, ioErr := ioutil.ReadAll(resp.Body)
  738. // if ioErr != nil {
  739. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  740. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  741. // return
  742. // }
  743. // var respJSON map[string]interface{}
  744. //
  745. // if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  746. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  747. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  748. // return
  749. // }
  750. //
  751. // userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  752. // userJSONBytes, _ := json.Marshal(userJSON)
  753. // var res ResultTwo
  754. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  755. // utils.ErrorLog("解析失败:%v", err)
  756. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  757. // return
  758. // }
  759. // Iinfos, _ := json.Marshal(res.Output.Iinfo)
  760. // Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  761. // infoStr := string(Iinfos)
  762. // idetinfoStr := string(Idetinfos)
  763. //
  764. // if res.Infcode == 0 {
  765. // his := models.VMHisPatient{
  766. // Status: 1,
  767. // Ctime: time.Now().Unix(),
  768. // Mtime: time.Now().Unix(),
  769. // PsnNo: res.Output.Baseinfo.PsnNo,
  770. // PsnCertType: res.Output.Baseinfo.PsnCertType,
  771. // Certno: res.Output.Baseinfo.Certno,
  772. // PsnName: res.Output.Baseinfo.PsnName,
  773. // Gend: res.Output.Baseinfo.Gend,
  774. // Naty: res.Output.Baseinfo.Naty,
  775. // Brdy: res.Output.Baseinfo.Brdy,
  776. // Age: res.Output.Baseinfo.Age,
  777. // Iinfo: infoStr,
  778. // Idetinfo: idetinfoStr,
  779. // UserOrgId: adminUser.CurrentOrgId,
  780. // IsReturn: 1,
  781. // IdCardType: id_card_type,
  782. // }
  783. //
  784. // patient, err := service.GetPatientByNumber(basNumber, adminUser.CurrentOrgId)
  785. // if err == gorm.ErrRecordNotFound {
  786. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  787. // return
  788. //
  789. // } else if err != nil {
  790. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  791. // return
  792. //
  793. // } else {
  794. // c.ServeSuccessJSON(map[string]interface{}{
  795. // "patient": patient,
  796. // "his": his,
  797. // "number": basNumber,
  798. // })
  799. // }
  800. // } else {
  801. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  802. // return
  803. // }
  804. //
  805. //}
  806. break
  807. case 2:
  808. ////SFZStr, err := GetSFZBaseInfo()
  809. //if err != nil {
  810. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  811. // return
  812. //
  813. //} else {
  814. //
  815. // id_card_str := strings.Split(SFZStr, "^")
  816. // id_card_number := id_card_str[0]
  817. //appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
  818. //
  819. //api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + id_card_number + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10)
  820. //resp, requestErr := http.Get(api)
  821. //if requestErr != nil {
  822. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  823. // return
  824. //}
  825. //defer resp.Body.Close()
  826. //body, ioErr := ioutil.ReadAll(resp.Body)
  827. //if ioErr != nil {
  828. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  829. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  830. // return
  831. //}
  832. //var respJSON map[string]interface{}
  833. //
  834. //if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  835. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  836. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  837. // return
  838. //}
  839. //
  840. //userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  841. //userJSONBytes, _ := json.Marshal(userJSON)
  842. //var res ResultTwo
  843. //if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  844. // utils.ErrorLog("解析失败:%v", err)
  845. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  846. // return
  847. //}
  848. //Iinfos, _ := json.Marshal(res.Output.Iinfo)
  849. //Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  850. //infoStr := string(Iinfos)
  851. //idetinfoStr := string(Idetinfos)
  852. //
  853. //if res.Infcode == 0 {
  854. // his := models.VMHisPatient{
  855. // Status: 1,
  856. // Ctime: time.Now().Unix(),
  857. // Mtime: time.Now().Unix(),
  858. // PsnNo: res.Output.Baseinfo.PsnNo,
  859. // PsnCertType: res.Output.Baseinfo.PsnCertType,
  860. // Certno: res.Output.Baseinfo.Certno,
  861. // PsnName: res.Output.Baseinfo.PsnName,
  862. // Gend: res.Output.Baseinfo.Gend,
  863. // Naty: res.Output.Baseinfo.Naty,
  864. // Brdy: res.Output.Baseinfo.Brdy,
  865. // Age: res.Output.Baseinfo.Age,
  866. // Iinfo: infoStr,
  867. // Idetinfo: idetinfoStr,
  868. // UserOrgId: adminUser.CurrentOrgId,
  869. // IsReturn: 1,
  870. // IdCardType: id_card_type,
  871. // }
  872. // patient, err := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  873. // if err == gorm.ErrRecordNotFound {
  874. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  875. // return
  876. //
  877. // } else if err != nil {
  878. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  879. // return
  880. //
  881. // } else {
  882. // c.ServeSuccessJSON(map[string]interface{}{
  883. // "patient": patient,
  884. // "number": id_card_number,
  885. // })
  886. // }
  887. //}
  888. break
  889. case 3:
  890. break
  891. }
  892. }
  893. //func GetBasBaseInfo() (jsonStr string, err error) {
  894. //
  895. // handle := syscall.NewLazyDLL("SSCard.dll")
  896. // add := handle.NewProc("ReadCardBas")
  897. // str := make([]byte, 1024)
  898. // str1 := make([]byte, 1024)
  899. // ret, _, _ := add.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  900. // fmt.Println(ConvertToString(string(str), "gbk", "utf-8"))
  901. //
  902. // fmt.Println(ConvertToString(string(str1), "gbk", "utf-8"))
  903. //
  904. // fmt.Println("> Add(4,5)的结果为:", ret)
  905. // handle.Release()
  906. //
  907. // return "", nil
  908. //
  909. //}
  910. //func GetSFZBaseInfo() (jsonStr string, err error) {
  911. // //handle := syscall.MustLoadDLL("SSCard.dll")
  912. //
  913. // str := make([]byte, 256)
  914. // str1 := make([]byte, 256)
  915. // r, _, _ := ReadIDCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  916. //
  917. // fmt.Println(r)
  918. // return string(str), nil
  919. //}
  920. //func GetQRBaseInfo() (jsonStr string, err error) {
  921. // handle := syscall.LoadDLL("SSCard.dll")
  922. // ReadCardBas := handle.FindProc("GetQRBase")
  923. //
  924. // str := make([]byte, 256)
  925. // str1 := make([]byte, 256)
  926. // r, _, _ := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  927. //
  928. // fmt.Println(string(str))
  929. // fmt.Println(r)
  930. // return string(str), nil
  931. //}
  932. func CardInit() int {
  933. DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  934. add := DllTestDef.MustFindProc("Init")
  935. ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  936. if err != nil {
  937. fmt.Println("SSCard的运算结果为:", ret)
  938. }
  939. result := int(ret)
  940. return result
  941. }
  942. //func CardInit() int {
  943. // ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  944. // if err != nil {
  945. // fmt.Println("SSCard的运算结果为:", ret)
  946. // }
  947. // fmt.Println(err)
  948. // result := int(ret)
  949. // return result
  950. //}
  951. func IntPtr(n int) uintptr {
  952. return uintptr(n)
  953. }
  954. func StrPtr(s string) uintptr {
  955. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  956. }
  957. type ResultTwo struct {
  958. ErrMsg string `json:"err_msg"`
  959. InfRefmsgid string `json:"inf_refmsgid"`
  960. Infcode int64 `json:"infcode"`
  961. Output struct {
  962. Baseinfo struct {
  963. Age float64 `json:"age"`
  964. Brdy string `json:"brdy"`
  965. Certno string `json:"certno"`
  966. Gend string `json:"gend"`
  967. Naty string `json:"naty"`
  968. PsnCertType string `json:"psn_cert_type"`
  969. PsnName string `json:"psn_name"`
  970. PsnNo string `json:"psn_no"`
  971. } `json:"baseinfo"`
  972. Idetinfo []interface{} `json:"idetinfo"`
  973. Iinfo []struct {
  974. Balc float64 `json:"balc"`
  975. CvlservFlag string `json:"cvlserv_flag"`
  976. EmpName string `json:"emp_name"`
  977. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  978. Insutype string `json:"insutype"`
  979. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  980. PausInsuDate string `json:"paus_insu_date"`
  981. PsnInsuDate string `json:"psn_insu_date"`
  982. PsnInsuStas string `json:"psn_insu_stas"`
  983. PsnType string `json:"psn_type"`
  984. } `json:"insuinfo"`
  985. } `json:"output"`
  986. RefmsgTime string `json:"refmsg_time"`
  987. RespondTime string `json:"respond_time"`
  988. Signtype interface{} `json:"signtype"`
  989. WarnInfo interface{} `json:"warn_info"`
  990. }
  991. type ResultThree struct {
  992. Cainfo interface{} `json:"cainfo"`
  993. ErrMsg string `json:"err_msg"`
  994. InfRefmsgid string `json:"inf_refmsgid"`
  995. Infcode int64 `json:"infcode"`
  996. Output struct {
  997. Data struct {
  998. IptOtpNo string `json:"ipt_otp_no"`
  999. MdtrtID string `json:"mdtrt_id"`
  1000. PsnNo string `json:"psn_no"`
  1001. } `json:"data"`
  1002. } `json:"output"`
  1003. RefmsgTime string `json:"refmsg_time"`
  1004. RespondTime string `json:"respond_time"`
  1005. Signtype interface{} `json:"signtype"`
  1006. WarnMsg interface{} `json:"warn_msg"`
  1007. }
  1008. type ResultFour struct {
  1009. Cainfo string `json:"cainfo"`
  1010. ErrMsg string `json:"err_msg"`
  1011. InfRefmsgid string `json:"inf_refmsgid"`
  1012. Infcode int64 `json:"infcode"`
  1013. Output struct {
  1014. Result []struct {
  1015. BasMednFlag string `json:"bas_medn_flag"`
  1016. ChldMedcFlag string `json:"chld_medc_flag"`
  1017. ChrgitmLv string `json:"chrgitm_lv"`
  1018. Cnt float64 `json:"cnt"`
  1019. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  1020. DrtReimFlag string `json:"drt_reim_flag"`
  1021. FeedetlSn string `json:"feedetl_sn"`
  1022. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1023. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  1024. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1025. ListSpItemFlag string `json:"list_sp_item_flag"`
  1026. LmtUsedFlag string `json:"lmt_used_flag"`
  1027. MedChrgitmType string `json:"med_chrgitm_type"`
  1028. Memo string `json:"memo"`
  1029. OverlmtAmt float64 `json:"overlmt_amt"`
  1030. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1031. Pric float64 `json:"pric"`
  1032. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  1033. SelfpayProp float64 `json:"selfpay_prop"`
  1034. } `json:"result"`
  1035. } `json:"output"`
  1036. RefmsgTime string `json:"refmsg_time"`
  1037. RespondTime string `json:"respond_time"`
  1038. Signtype string `json:"signtype"`
  1039. WarnMsg string `json:"warn_msg"`
  1040. }
  1041. type ResultFive struct {
  1042. Balc float64 `json:"balc"`
  1043. CvlservFlag string `json:"cvlserv_flag"`
  1044. EmpName string `json:"emp_name"`
  1045. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  1046. Insutype string `json:"insutype"`
  1047. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  1048. PausInsuDate string `json:"paus_insu_date"`
  1049. PsnInsuDate string `json:"psn_insu_date"`
  1050. PsnInsuStas string `json:"psn_insu_stas"`
  1051. PsnType string `json:"psn_type"`
  1052. }
  1053. type ResultSix struct {
  1054. Cainfo interface{} `json:"cainfo"`
  1055. ErrMsg string `json:"err_msg"`
  1056. InfRefmsgid string `json:"inf_refmsgid"`
  1057. Infcode int64 `json:"infcode"`
  1058. Output struct {
  1059. } `json:"output"`
  1060. RefmsgTime string `json:"refmsg_time"`
  1061. RespondTime string `json:"respond_time"`
  1062. Signtype interface{} `json:"signtype"`
  1063. WarnMsg interface{} `json:"warn_msg"`
  1064. }
  1065. type ResultSeven struct {
  1066. Cainfo string `json:"cainfo"`
  1067. ErrMsg string `json:"err_msg"`
  1068. InfRefmsgid string `json:"inf_refmsgid"`
  1069. Infcode int64 `json:"infcode"`
  1070. Output struct {
  1071. Setldetail []interface{} `json:"setldetail"`
  1072. Setlinfo struct {
  1073. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1074. AcctPay float64 `json:"acct_pay"`
  1075. ActPayDedc float64 `json:"act_pay_dedc"`
  1076. Age float64 `json:"age"`
  1077. Balc float64 `json:"balc"`
  1078. Brdy string `json:"brdy"`
  1079. Certno string `json:"certno"`
  1080. ClrOptins string `json:"clr_optins"`
  1081. ClrType string `json:"clr_type"`
  1082. ClrWay string `json:"clr_way"`
  1083. CvlservFlag string `json:"cvlserv_flag"`
  1084. CvlservPay float64 `json:"cvlserv_pay"`
  1085. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1086. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1087. Gend string `json:"gend"`
  1088. HifesPay float64 `json:"hifes_pay"`
  1089. HifmiPay float64 `json:"hifmi_pay"`
  1090. HifpPay float64 `json:"hifp_pay"`
  1091. HospPartAmt float64 `json:"hosp_part_amt"`
  1092. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1093. Insutype string `json:"insutype"`
  1094. MafPay float64 `json:"maf_pay"`
  1095. MdtrtCertType string `json:"mdtrt_cert_type"`
  1096. HifobPay float64 `json:"hifob_pay"`
  1097. MdtrtID string `json:"mdtrt_id"`
  1098. MedType string `json:"med_type"`
  1099. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1100. MedinsSetlID string `json:"medins_setl_id"`
  1101. Naty string `json:"naty"`
  1102. OthPay float64 `json:"oth_pay"`
  1103. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1104. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1105. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1106. PsnCashPay float64 `json:"psn_cash_pay"`
  1107. PsnCertType string `json:"psn_cert_type"`
  1108. PsnName string `json:"psn_name"`
  1109. PsnNo string `json:"psn_no"`
  1110. PsnPartAmt float64 `json:"psn_part_amt"`
  1111. PsnType string `json:"psn_type"`
  1112. SetlID string `json:"setl_id"`
  1113. SetlTime string `json:"setl_time"`
  1114. } `json:"setlinfo"`
  1115. } `json:"output"`
  1116. RefmsgTime string `json:"refmsg_time"`
  1117. RespondTime string `json:"respond_time"`
  1118. Signtype interface{} `json:"signtype"`
  1119. WarnMsg interface{} `json:"warn_msg"`
  1120. }
  1121. type ResultEight struct {
  1122. Cainfo string `json:"cainfo"`
  1123. ErrMsg string `json:"err_msg"`
  1124. InfRefmsgid string `json:"inf_refmsgid"`
  1125. Infcode int64 `json:"infcode"`
  1126. Output struct {
  1127. Stmtinfo struct {
  1128. SetlOptins string `json:"setl_optins"`
  1129. StmtRslt string `json:"stmt_rslt"`
  1130. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  1131. } `json:"stmtinfo"`
  1132. } `json:"output"`
  1133. RefmsgTime string `json:"refmsg_time"`
  1134. RespondTime string `json:"respond_time"`
  1135. Signtype interface{} `json:"signtype"`
  1136. WarnMsg interface{} `json:"warn_msg"`
  1137. }
  1138. type ResultNine struct {
  1139. Cainfo string `json:"cainfo"`
  1140. ErrMsg string `json:"err_msg"`
  1141. InfRefmsgid string `json:"inf_refmsgid"`
  1142. Infcode int64 `json:"infcode"`
  1143. Output struct {
  1144. FileQuryNo string `json:"file_qury_no"`
  1145. } `json:"output"`
  1146. RefmsgTime string `json:"refmsg_time"`
  1147. RespondTime string `json:"respond_time"`
  1148. Signtype interface{} `json:"signtype"`
  1149. WarnMsg interface{} `json:"warn_msg"`
  1150. }
  1151. type ResultTen struct {
  1152. Cainfo string `json:"cainfo"`
  1153. ErrMsg string `json:"err_msg"`
  1154. InfRefmsgid string `json:"inf_refmsgid"`
  1155. Infcode int64 `json:"infcode"`
  1156. Output struct {
  1157. DldEndtime string `json:"dld_endtime"`
  1158. FileQuryNo string `json:"file_qury_no"`
  1159. Filename string `json:"filename"`
  1160. } `json:"output"`
  1161. RefmsgTime string `json:"refmsg_time"`
  1162. RespondTime string `json:"respond_time"`
  1163. Signtype interface{} `json:"signtype"`
  1164. WarnMsg interface{} `json:"warn_msg"`
  1165. }
  1166. type ResultEleven struct {
  1167. Cainfo string `json:"cainfo"`
  1168. ErrMsg string `json:"err_msg"`
  1169. InfRefmsgid string `json:"inf_refmsgid"`
  1170. Infcode int64 `json:"infcode"`
  1171. Output struct {
  1172. Setlinfo struct {
  1173. FixmedinsName string `json:"fixmedins_name"`
  1174. FixmedinsCode string `json:"fixmedins_code"`
  1175. PsnNo string `json:"psn_no"`
  1176. PsnName string `json:"psn_name"`
  1177. HifobPay float64 `json:"hifob_pay"`
  1178. Gend string `json:"gend"`
  1179. Brdy string `json:"brdy"`
  1180. PsnCertType string `json:"psn_cert_type"`
  1181. PsnType string `json:"psn_type"`
  1182. EmpName string `json:"emp_name"`
  1183. Certno string `json:"certno"`
  1184. Insutype string `json:"insutype"`
  1185. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1186. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1187. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1188. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1189. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1190. ActPayDedc float64 `json:"act_pay_dedc"`
  1191. HifpPay float64 `json:"hifp_pay"`
  1192. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1193. CvlservPay float64 `json:"cvlserv_pay"`
  1194. HifesPay float64 `json:"hifes_pay"`
  1195. HifmiPay float64 `json:"hifmi_pay"`
  1196. MafPay float64 `json:"maf_pay"`
  1197. OthPay float64 `json:"oth_pay"`
  1198. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1199. PsnPay float64 `json:"psn_pay"`
  1200. AcctPay float64 `json:"acct_pay"`
  1201. CashPayamt float64 `json:"cash_payamt"`
  1202. Balc float64 `json:"balc"`
  1203. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1204. MedinsSetlId string `json:"medins_setl_id"`
  1205. RefdSetlFlag string `json:"refd_setl_flag"`
  1206. SetlTime string `json:"setl_time"`
  1207. MedType string `json:"med_type"`
  1208. HospLv string `json:"hosp_lv"`
  1209. } `json:"setlinfo"`
  1210. } `json:"output"`
  1211. RefmsgTime string `json:"refmsg_time"`
  1212. RespondTime string `json:"respond_time"`
  1213. Signtype interface{} `json:"signtype"`
  1214. WarnMsg interface{} `json:"warn_msg"`
  1215. }
  1216. type ResultTwelve struct {
  1217. Cainfo string `json:"cainfo"`
  1218. ErrMsg string `json:"err_msg"`
  1219. InfRefmsgid string `json:"inf_refmsgid"`
  1220. Infcode int64 `json:"infcode"`
  1221. Output struct {
  1222. MdtrtId string `json:"mdtrt_id"`
  1223. ChrgBchno string `json:"chrg_bchno"`
  1224. PsnNo string `json:"psn_no"`
  1225. } `json:"output"`
  1226. RefmsgTime string `json:"refmsg_time"`
  1227. RespondTime string `json:"respond_time"`
  1228. Signtype interface{} `json:"signtype"`
  1229. WarnMsg interface{} `json:"warn_msg"`
  1230. }
  1231. type ResultThirteen struct {
  1232. ErrMsg string `json:"err_msg"`
  1233. InfRefmsgid string `json:"inf_refmsgid"`
  1234. Infcode int64 `json:"infcode"`
  1235. Output struct {
  1236. Result struct {
  1237. TrtDclaDetlSn string `json:"trt_dcla_detl_sn"`
  1238. } `json:"result"`
  1239. } `json:"output"`
  1240. RefmsgTime string `json:"refmsg_time"`
  1241. RespondTime string `json:"respond_time"`
  1242. Signtype interface{} `json:"signtype"`
  1243. WarnInfo interface{} `json:"warn_info"`
  1244. }
  1245. type ResultFourteen struct {
  1246. ErrMsg string `json:"err_msg"`
  1247. InfRefmsgid string `json:"inf_refmsgid"`
  1248. Infcode int64 `json:"infcode"`
  1249. Output struct {
  1250. } `json:"output"`
  1251. RefmsgTime string `json:"refmsg_time"`
  1252. RespondTime string `json:"respond_time"`
  1253. Signtype interface{} `json:"signtype"`
  1254. WarnInfo interface{} `json:"warn_info"`
  1255. }
  1256. type ResultSixteen struct {
  1257. Cainfo string `json:"cainfo"`
  1258. ErrMsg string `json:"err_msg"`
  1259. InfRefmsgid string `json:"inf_refmsgid"`
  1260. Infcode int64 `json:"infcode"`
  1261. Output struct {
  1262. Setldetail []interface{} `json:"setldetail"`
  1263. Setlinfo struct {
  1264. MdtrtID string `json:"mdtrt_id"`
  1265. SetlID string `json:"setl_id"`
  1266. ClrOptins string `json:"clr_optins"`
  1267. SetlTime string `json:"setl_time"`
  1268. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1269. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1270. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1271. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1272. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1273. ActPayDedc float64 `json:"act_pay_dedc"`
  1274. HifpPay float64 `json:"hifp_pay"`
  1275. PoolPropSe float64 `json:"pool_prop_selfpay"`
  1276. Lfpay float64 `json:"selfpay"`
  1277. CvlservPay float64 `json:"cvlserv_pay"`
  1278. HifesPay float64 `json:"hifes_pay"`
  1279. HifmiPay float64 `json:"hifmi_pay"`
  1280. HifobPay float64 `json:"hifob_pay"`
  1281. MafPay float64 `json:"maf_pay"`
  1282. OthPay float64 `json:"oth_pay"`
  1283. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1284. PsnPartAmt float64 `json:"psn_part_amt"`
  1285. AcctPay float64 `json:"acct_pay"`
  1286. Balc float64 `json:"balc"`
  1287. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1288. HospPartAmt float64 `json:"hosp_part_amt"`
  1289. MedinsSetlID string `json:"medins_setl_id"`
  1290. PdnCashPay string `json:"pdn_cash_pay"`
  1291. } `json:"setlinfo"`
  1292. } `json:"output"`
  1293. RefmsgTime string `json:"refmsg_time"`
  1294. RespondTime string `json:"respond_time"`
  1295. Signtype interface{} `json:"signtype"`
  1296. WarnMsg interface{} `json:"warn_msg"`
  1297. }
  1298. type ResultSeventeen struct {
  1299. ErrMsg string `json:"err_msg"`
  1300. InfRefmsgid string `json:"inf_refmsgid"`
  1301. Infcode int64 `json:"infcode"`
  1302. Output struct {
  1303. Data struct {
  1304. SetlListId string `json:"setl_list_id"`
  1305. } `json:"data"`
  1306. } `json:"output"`
  1307. RefmsgTime string `json:"refmsg_time"`
  1308. RespondTime string `json:"respond_time"`
  1309. Signtype string `json:"signtype"`
  1310. WarnInfo string `json:"warn_info"`
  1311. }
  1312. type Custom struct {
  1313. DetItemFeeSumamt string
  1314. Cut string
  1315. FeedetlSn string
  1316. Price string
  1317. MedListCodg string
  1318. Type int64
  1319. AdviceId int64
  1320. ProjectId int64
  1321. ItemId int64
  1322. }
  1323. //获取个人信息----挂号-----上传就诊信息
  1324. func (c *HisApiController) GetRegisterInfo() {
  1325. id, _ := c.GetInt64("id")
  1326. record_time := c.GetString("record_time")
  1327. settlementValue, _ := c.GetInt64("settlement_value")
  1328. medical_insurance_card := c.GetString("medical_insurance_card")
  1329. name := c.GetString("name")
  1330. id_card_type, _ := c.GetInt64("id_card_type")
  1331. certificates, _ := c.GetInt64("certificates")
  1332. medical_care, _ := c.GetInt64("medical_care")
  1333. birthday := c.GetString("birthday")
  1334. age, _ := c.GetInt64("age")
  1335. id_card := c.GetString("id_card")
  1336. register_type, _ := c.GetInt64("register")
  1337. doctor, _ := c.GetInt64("doctor")
  1338. department, _ := c.GetInt64("department")
  1339. gender, _ := c.GetInt64("sex")
  1340. phone := c.GetString("phone")
  1341. registration_fee, _ := c.GetFloat("registration_fee")
  1342. medical_expenses, _ := c.GetFloat("medical_expenses")
  1343. social_type, _ := c.GetInt64("social_type")
  1344. admin_user_id, _ := c.GetInt64("admin_user_id")
  1345. diagnosis_id, _ := c.GetInt64("diagnosis")
  1346. sick_type, _ := c.GetInt64("sick_type")
  1347. reg_type, _ := c.GetInt64("p_type")
  1348. timeLayout := "2006-01-02"
  1349. loc, _ := time.LoadLocation("Local")
  1350. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  1351. birthUnix := birthdays.Unix()
  1352. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1353. if err != nil {
  1354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1355. return
  1356. }
  1357. recordDateTime := theTime.Unix()
  1358. adminInfo := c.GetAdminUserInfo()
  1359. var patient service.Patients
  1360. if id == 0 {
  1361. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  1362. } else {
  1363. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  1364. }
  1365. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  1366. if patientPrescription.ID == 0 {
  1367. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  1368. }
  1369. //adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1370. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  1371. sickConfig, _ := service.FindSickById(sick_type)
  1372. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1373. if patient.ID == 0 {
  1374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1375. return
  1376. }
  1377. if len(patient.IdCardNo) == 0 {
  1378. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  1379. return
  1380. }
  1381. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  1382. if config.IsOpen == 1 {
  1383. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&certificates=" + strconv.FormatInt(certificates, 10)
  1384. resp, requestErr := http.Get(api)
  1385. if requestErr != nil {
  1386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1387. return
  1388. }
  1389. defer resp.Body.Close()
  1390. body, ioErr := ioutil.ReadAll(resp.Body)
  1391. if ioErr != nil {
  1392. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1394. return
  1395. }
  1396. var respJSON map[string]interface{}
  1397. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1398. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1400. return
  1401. }
  1402. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1403. userJSONBytes, _ := json.Marshal(userJSON)
  1404. var res ResultTwo
  1405. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1406. utils.ErrorLog("解析失败:%v", err)
  1407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1408. return
  1409. }
  1410. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  1411. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  1412. infoStr := string(Iinfos)
  1413. idetinfoStr := string(Idetinfos)
  1414. if res.Infcode == 0 {
  1415. his := models.VMHisPatient{
  1416. Name: name,
  1417. Gender: gender,
  1418. Birthday: birthUnix,
  1419. MedicalTreatmentType: medical_care,
  1420. IdType: certificates,
  1421. IdCardNo: id_card,
  1422. BalanceAccountsType: settlementValue,
  1423. SocialType: social_type,
  1424. MedicalInsuranceNumber: medical_insurance_card,
  1425. RegisterType: register_type,
  1426. RegisterCost: registration_fee,
  1427. TreatmentCost: medical_expenses,
  1428. Status: 1,
  1429. Ctime: time.Now().Unix(),
  1430. Mtime: time.Now().Unix(),
  1431. PsnNo: res.Output.Baseinfo.PsnNo,
  1432. PsnCertType: res.Output.Baseinfo.PsnCertType,
  1433. Certno: res.Output.Baseinfo.Certno,
  1434. PsnName: res.Output.Baseinfo.PsnName,
  1435. Gend: res.Output.Baseinfo.Gend,
  1436. Naty: res.Output.Baseinfo.Naty,
  1437. Brdy: res.Output.Baseinfo.Brdy,
  1438. Age: res.Output.Baseinfo.Age,
  1439. Iinfo: infoStr,
  1440. Idetinfo: idetinfoStr,
  1441. PatientId: patient.ID,
  1442. RecordDate: theTime.Unix(),
  1443. UserOrgId: adminInfo.CurrentOrgId,
  1444. AdminUserId: admin_user_id,
  1445. IsReturn: 1,
  1446. IdCardType: id_card_type,
  1447. Doctor: doctor,
  1448. Departments: department,
  1449. SickType: sick_type,
  1450. Diagnosis: diagnosis_id,
  1451. PType: reg_type,
  1452. }
  1453. timestamp := time.Now().Unix()
  1454. tempTime := time.Unix(timestamp, 0)
  1455. timeFormat := tempTime.Format("20060102150405")
  1456. chrgBchno := rand.Intn(100000) + 10000
  1457. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1458. count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  1459. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1460. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  1461. IdCardNo := ""
  1462. if id_card_type == 1 {
  1463. IdCardNo = medical_insurance_card
  1464. } else {
  1465. IdCardNo = patient.IdCardNo
  1466. }
  1467. var insutypes []string
  1468. var insutype string
  1469. var is390 int = 0
  1470. var is310 int = 0
  1471. for _, item := range res.Output.Iinfo {
  1472. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1473. insutypes = append(insutypes, item.Insutype)
  1474. }
  1475. }
  1476. if len(insutypes) == 1 {
  1477. insutype = insutypes[0]
  1478. } else {
  1479. for _, i := range insutypes {
  1480. if i == "390" {
  1481. is390 = 1
  1482. }
  1483. if i == "310" {
  1484. is310 = 1
  1485. }
  1486. }
  1487. }
  1488. if is390 == 1 {
  1489. insutype = "390"
  1490. }
  1491. if is310 == 1 {
  1492. insutype = "310"
  1493. }
  1494. if len(insutypes) == 0 {
  1495. insutype = "310"
  1496. }
  1497. if count == 1 {
  1498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1499. return
  1500. }
  1501. api := "http://127.0.0.1:9532/" + "gdyb/two?cert_no=" + IdCardNo + "&insutype=" +
  1502. insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  1503. "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  1504. "&dept=" + department.Name + "&fixmedins_code=" + miConfig.Code + "&dept_code=" + department.Number + "&doctor_id=" + doctor_id + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10)
  1505. resp, requestErr := http.Get(api)
  1506. if requestErr != nil {
  1507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1508. return
  1509. }
  1510. defer resp.Body.Close()
  1511. body, ioErr := ioutil.ReadAll(resp.Body)
  1512. if ioErr != nil {
  1513. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1515. return
  1516. }
  1517. var respJSON map[string]interface{}
  1518. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1519. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1521. return
  1522. }
  1523. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1524. userJSONBytes, _ := json.Marshal(respJSON)
  1525. var res ResultThree
  1526. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1527. utils.ErrorLog("解析失败:%v", err)
  1528. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1529. return
  1530. }
  1531. if res.Infcode == -1 {
  1532. adminUser := c.GetAdminUserInfo()
  1533. errlog := &models.HisOrderError{
  1534. UserOrgId: adminUser.CurrentOrgId,
  1535. Ctime: time.Now().Unix(),
  1536. Mtime: time.Now().Unix(),
  1537. ErrMsg: res.ErrMsg,
  1538. Status: 1,
  1539. PatientId: id,
  1540. RecordTime: recordDateTime,
  1541. Stage: 2,
  1542. }
  1543. service.CreateErrMsgLog(errlog)
  1544. c.ServeSuccessJSON(map[string]interface{}{
  1545. "failed_code": -10,
  1546. "msg": res.ErrMsg,
  1547. })
  1548. return
  1549. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  1550. //return
  1551. }
  1552. his.Number = res.Output.Data.MdtrtID
  1553. his.PsnNo = res.Output.Data.PsnNo
  1554. his.IptOtpNo = res.Output.Data.IptOtpNo
  1555. his.IdCardNo = patient.IdCardNo
  1556. his.PhoneNumber = patient.Phone
  1557. his.UserOrgId = adminInfo.CurrentOrgId
  1558. his.Ctime = time.Now().Unix()
  1559. his.Mtime = time.Now().Unix()
  1560. his.Status = 1
  1561. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  1562. if len(lists) == 1 {
  1563. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  1564. }
  1565. if err == nil {
  1566. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  1567. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  1568. "&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + strconv.FormatInt(reg_type, 10) + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code + "&diag_code=" + diagnosisConfig.CountryCode +
  1569. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  1570. resp2, requestErr2 := http.Get(api2)
  1571. if requestErr2 != nil {
  1572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1573. return
  1574. }
  1575. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  1576. if ioErr2 != nil {
  1577. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  1578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1579. return
  1580. }
  1581. var respJSON2 map[string]interface{}
  1582. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  1583. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1585. return
  1586. }
  1587. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1588. userJSONBytes2, _ := json.Marshal(respJSON2)
  1589. var res2 ResultSix
  1590. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  1591. utils.ErrorLog("解析失败:%v", err)
  1592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1593. return
  1594. }
  1595. if res2.Infcode == -1 {
  1596. adminUser := c.GetAdminUserInfo()
  1597. errlog := &models.HisOrderError{
  1598. UserOrgId: adminUser.CurrentOrgId,
  1599. Ctime: time.Now().Unix(),
  1600. Mtime: time.Now().Unix(),
  1601. ErrMsg: res2.ErrMsg,
  1602. Status: 1,
  1603. PatientId: id,
  1604. RecordTime: recordDateTime,
  1605. Stage: 3,
  1606. }
  1607. service.CreateErrMsgLog(errlog)
  1608. c.ServeSuccessJSON(map[string]interface{}{
  1609. "failed_code": -10,
  1610. "msg": res2.ErrMsg,
  1611. })
  1612. return
  1613. } else {
  1614. service.CreateHisPatientTwo(&his)
  1615. c.ServeSuccessJSON(map[string]interface{}{
  1616. "his_info": his,
  1617. })
  1618. }
  1619. } else {
  1620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1621. return
  1622. }
  1623. } else {
  1624. adminUser := c.GetAdminUserInfo()
  1625. errlog := &models.HisOrderError{
  1626. UserOrgId: adminUser.CurrentOrgId,
  1627. Ctime: time.Now().Unix(),
  1628. Mtime: time.Now().Unix(),
  1629. ErrMsg: res.ErrMsg,
  1630. Status: 1,
  1631. PatientId: id,
  1632. RecordTime: recordDateTime,
  1633. Stage: 1,
  1634. }
  1635. service.CreateErrMsgLog(errlog)
  1636. c.ServeSuccessJSON(map[string]interface{}{
  1637. "failed_code": -10,
  1638. "msg": res.ErrMsg,
  1639. })
  1640. return
  1641. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  1642. }
  1643. } else {
  1644. timeStr := time.Now().Format("2006-01-02")
  1645. timeArr := strings.Split(timeStr, "-")
  1646. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
  1647. his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  1648. var hisPatient models.XtHisPatient
  1649. if err == gorm.ErrRecordNotFound || his.ID == 0 {
  1650. hisPatient = models.XtHisPatient{
  1651. Name: name,
  1652. Age: age,
  1653. Gender: gender,
  1654. Birthday: birthUnix,
  1655. Phone: phone,
  1656. MedicalTreatmentType: medical_care,
  1657. IdType: certificates,
  1658. IdCardNo: id_card,
  1659. BalanceAccountsType: settlementValue,
  1660. SocialType: social_type,
  1661. MedicalInsuranceNumber: medical_insurance_card,
  1662. RegisterType: register_type,
  1663. RegisterCost: registration_fee,
  1664. TreatmentCost: medical_expenses,
  1665. AdminUserId: admin_user_id,
  1666. UserOrgId: adminInfo.CurrentOrgId,
  1667. Status: 1,
  1668. RecordDate: recordDateTime,
  1669. IsReturn: 1,
  1670. PatientId: patient.ID,
  1671. Ctime: time.Now().Unix(),
  1672. Mtime: time.Now().Unix(),
  1673. Number: str,
  1674. }
  1675. service.CreateHisPatient(&hisPatient)
  1676. }
  1677. c.ServeSuccessJSON(map[string]interface{}{
  1678. "his_info": hisPatient,
  1679. })
  1680. }
  1681. }
  1682. //上传明细----预结算----确认订单
  1683. func (c *HisApiController) GetUploadInfo() {
  1684. id, _ := c.GetInt64("id")
  1685. record_time := c.GetString("record_time")
  1686. his_patient_id, _ := c.GetInt64("his_patient_id")
  1687. pay_way, _ := c.GetInt64("pay_way")
  1688. pay_price, _ := c.GetFloat("pay_price")
  1689. pay_card_no := c.GetString("pay_card_no")
  1690. discount_price, _ := c.GetFloat("discount_price")
  1691. preferential_price, _ := c.GetFloat("preferential_price")
  1692. reality_price, _ := c.GetFloat("reality_price")
  1693. found_price, _ := c.GetFloat("found_price")
  1694. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1695. private_price, _ := c.GetFloat("private_price")
  1696. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1697. admin_user_id, _ := c.GetInt64("admin_user_id")
  1698. fapiao_code := c.GetString("fapiao_code")
  1699. fapiao_number := c.GetString("fapiao_number")
  1700. timeLayout := "2006-01-02"
  1701. loc, _ := time.LoadLocation("Local")
  1702. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1703. if err != nil {
  1704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1705. return
  1706. }
  1707. recordDateTime := theTime.Unix()
  1708. adminUser := c.GetAdminUserInfo()
  1709. var prescriptions []*models.HisPrescription
  1710. var start_time int64
  1711. var end_time int64
  1712. data := make(map[string]interface{})
  1713. if settle_accounts_type == 1 { //日结
  1714. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1715. data["pre"] = prescriptions
  1716. } else { //月结
  1717. start_time_str := c.GetString("start_time")
  1718. end_time_str := c.GetString("end_time")
  1719. timeLayout := "2006-01-02"
  1720. loc, _ := time.LoadLocation("Local")
  1721. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1722. if err != nil {
  1723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1724. return
  1725. }
  1726. recordStartTime := theStartTime.Unix()
  1727. start_time = recordStartTime
  1728. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1729. if err != nil {
  1730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1731. return
  1732. }
  1733. recordEndTime := theEndTime.Unix()
  1734. end_time = recordEndTime
  1735. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1736. data["pre"] = prescriptions
  1737. }
  1738. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1739. fmt.Println(his_patient_id)
  1740. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1741. timestamp := time.Now().Unix()
  1742. tempTime := time.Unix(timestamp, 0)
  1743. timeFormat := tempTime.Format("20060102150405")
  1744. chrgBchno := rand.Intn(100000) + 10000
  1745. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1746. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1747. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1748. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1749. strconv.FormatInt(his.PatientId, 10)
  1750. client := &http.Client{}
  1751. data["psn_no"] = his.PsnNo
  1752. data["mdtrt_id"] = his.Number
  1753. data["chrg_bchno"] = chrg_bchno
  1754. data["org_name"] = miConfig.OrgName
  1755. data["doctor"] = roles.UserName
  1756. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1757. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  1758. data["fixmedins_code"] = miConfig.Code
  1759. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  1760. data["dept_code"] = "15"
  1761. } else {
  1762. data["dept_code"] = department.Number
  1763. }
  1764. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1765. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1766. data["secret_key"] = miConfig.SecretKey
  1767. var ids []int64
  1768. for _, item := range prescriptions {
  1769. ids = append(ids, item.ID)
  1770. }
  1771. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1772. if config.IsOpen == 1 { //对接了医保,走医保流程
  1773. bytesData, _ := json.Marshal(data)
  1774. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  1775. resp, _ := client.Do(req)
  1776. defer resp.Body.Close()
  1777. body, ioErr := ioutil.ReadAll(resp.Body)
  1778. if ioErr != nil {
  1779. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1781. return
  1782. }
  1783. var respJSON map[string]interface{}
  1784. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1785. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1787. return
  1788. }
  1789. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1790. userJSONBytes, _ := json.Marshal(respJSON)
  1791. var res ResultFour
  1792. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1793. utils.ErrorLog("解析失败:%v", err)
  1794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1795. return
  1796. }
  1797. if res.Infcode == 0 {
  1798. order := &models.HisOrder{
  1799. UserOrgId: adminUser.CurrentOrgId,
  1800. HisPatientId: his.ID,
  1801. PatientId: his.PatientId,
  1802. SettleAccountsDate: recordDateTime,
  1803. Ctime: time.Now().Unix(),
  1804. Mtime: time.Now().Unix(),
  1805. Status: 1,
  1806. Number: chrg_bchno,
  1807. Infcode: res.Infcode,
  1808. WarnMsg: res.WarnMsg,
  1809. Cainfo: res.Cainfo,
  1810. ErrMsg: res.ErrMsg,
  1811. RespondTime: res.RefmsgTime,
  1812. InfRefmsgid: res.InfRefmsgid,
  1813. OrderStatus: 1,
  1814. PayWay: pay_way,
  1815. PayPrice: pay_price,
  1816. PayCardNo: pay_card_no,
  1817. DiscountPrice: discount_price,
  1818. PreferentialPrice: preferential_price,
  1819. RealityPrice: reality_price,
  1820. FoundPrice: found_price,
  1821. MedicalInsurancePrice: medical_insurance_price,
  1822. PrivatePrice: private_price,
  1823. IsMedicineInsurance: 1,
  1824. SettleType: settle_accounts_type,
  1825. SettleStartTime: start_time,
  1826. SettleEndTime: end_time,
  1827. Creator: roles.AdminUserId,
  1828. Modify: roles.AdminUserId,
  1829. FaPiaoNumber: fapiao_number,
  1830. FaPiaoCode: fapiao_code,
  1831. PType: 2,
  1832. }
  1833. err = service.CreateOrder(order)
  1834. if err != nil {
  1835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1836. return
  1837. }
  1838. for _, item := range res.Output.Result {
  1839. temp := strings.Split(item.FeedetlSn, "-")
  1840. var advice_id int64 = 0
  1841. var project_id int64 = 0
  1842. var types int64 = 0
  1843. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1844. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1845. if temp[1] == "1" {
  1846. advice_id = id
  1847. project_id = 0
  1848. } else if temp[1] == "2" {
  1849. advice_id = 0
  1850. project_id = id
  1851. }
  1852. info := &models.HisOrderInfo{
  1853. OrderNumber: order.Number,
  1854. FeedetlSn: item.FeedetlSn,
  1855. UploadDate: time.Now().Unix(),
  1856. AdviceId: advice_id,
  1857. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1858. Cnt: item.Cnt,
  1859. Pric: float64(item.Pric),
  1860. PatientId: his.PatientId,
  1861. PricUplmtAmt: item.PricUplmtAmt,
  1862. SelfpayProp: item.SelfpayProp,
  1863. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1864. OverlmtAmt: item.OverlmtAmt,
  1865. PreselfpayAmt: item.PreselfpayAmt,
  1866. BasMednFlag: item.BasMednFlag,
  1867. MedChrgitmType: item.MedChrgitmType,
  1868. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1869. Status: 1,
  1870. Memo: item.Memo,
  1871. Mtime: time.Now().Unix(),
  1872. InscpScpAmt: item.InscpScpAmt,
  1873. DrtReimFlag: item.DrtReimFlag,
  1874. Ctime: time.Now().Unix(),
  1875. ListSpItemFlag: item.ListSpItemFlag,
  1876. ChldMedcFlag: item.ChldMedcFlag,
  1877. LmtUsedFlag: item.LmtUsedFlag,
  1878. ChrgitmLv: item.ChrgitmLv,
  1879. UserOrgId: adminUser.CurrentOrgId,
  1880. HisPatientId: his.ID,
  1881. OrderId: order.ID,
  1882. ProjectId: project_id,
  1883. Type: types,
  1884. }
  1885. service.CreateOrderInfo(info)
  1886. }
  1887. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1888. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1889. var total float64
  1890. for _, item := range prescriptions {
  1891. if item.Type == 1 { //药品
  1892. for _, subItem := range item.HisDoctorAdviceInfo {
  1893. total = total + (subItem.Price * subItem.PrescribingNumber)
  1894. }
  1895. }
  1896. if item.Type == 2 { //项目
  1897. for _, subItem := range item.HisPrescriptionProject {
  1898. total = total + (subItem.Price * float64(subItem.Count))
  1899. }
  1900. }
  1901. }
  1902. for _, item := range prescriptions {
  1903. for _, subItem := range item.HisAdditionalCharge {
  1904. total = total + (subItem.Price * float64(subItem.Count))
  1905. }
  1906. }
  1907. allTotal := fmt.Sprintf("%.2f", total)
  1908. if res.Infcode == 0 {
  1909. var rf []*ResultFive
  1910. json.Unmarshal([]byte(his.Iinfo), &rf)
  1911. chrg_bchno := chrg_bchno
  1912. cert_no := his.Certno
  1913. var insutypes []string
  1914. var insutype string
  1915. var is390 int = 0
  1916. var is310 int = 0
  1917. for _, item := range rf {
  1918. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1919. insutypes = append(insutypes, item.Insutype)
  1920. }
  1921. }
  1922. if len(insutypes) == 1 {
  1923. insutype = insutypes[0]
  1924. } else {
  1925. for _, i := range insutypes {
  1926. if i == "390" {
  1927. is390 = 1
  1928. }
  1929. if i == "310" {
  1930. is310 = 1
  1931. }
  1932. }
  1933. }
  1934. if is390 == 1 {
  1935. insutype = "390"
  1936. }
  1937. if is310 == 1 {
  1938. insutype = "310"
  1939. }
  1940. if len(insutypes) == 0 {
  1941. insutype = "310"
  1942. }
  1943. if his.IdCardType == 1 {
  1944. cert_no = his.MedicalInsuranceNumber
  1945. } else {
  1946. cert_no = his.Certno
  1947. }
  1948. result, src_resquest := service.Gdyb2207(his.PsnNo, his.Number, chrg_bchno, cert_no, insutype, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, strconv.FormatInt(patientPrescription.RegisterType, 10), his.IdCardType, 0, 0, 0, 0, his.IdType)
  1949. var dat map[string]interface{}
  1950. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1951. fmt.Println(dat)
  1952. } else {
  1953. fmt.Println(err)
  1954. }
  1955. userJSONBytes, _ := json.Marshal(dat)
  1956. var res ResultSeven
  1957. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1958. utils.ErrorLog("解析失败:%v", err)
  1959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1960. return
  1961. }
  1962. if res.Infcode == -1 {
  1963. errlog := &models.HisOrderError{
  1964. UserOrgId: adminUser.CurrentOrgId,
  1965. Ctime: time.Now().Unix(),
  1966. Mtime: time.Now().Unix(),
  1967. Number: chrg_bchno,
  1968. ErrMsg: res.ErrMsg,
  1969. Status: 1,
  1970. PatientId: id,
  1971. RecordTime: recordDateTime,
  1972. Stage: 6,
  1973. }
  1974. service.CreateErrMsgLog(errlog)
  1975. c.ServeSuccessJSON(map[string]interface{}{
  1976. "failed_code": -10,
  1977. "msg": res.ErrMsg,
  1978. })
  1979. return
  1980. } else {
  1981. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1982. order.OrderStatus = 2
  1983. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1984. order.SetlId = res.Output.Setlinfo.SetlID
  1985. order.PsnNo = res.Output.Setlinfo.PsnNo
  1986. order.PsnName = res.Output.Setlinfo.PsnName
  1987. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1988. order.Certno = res.Output.Setlinfo.Certno
  1989. order.Gend = res.Output.Setlinfo.Gend
  1990. order.Naty = res.Output.Setlinfo.Naty
  1991. order.Age = res.Output.Setlinfo.Age
  1992. order.Insutype = res.Output.Setlinfo.Insutype
  1993. order.PsnType = res.Output.Setlinfo.PsnType
  1994. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1995. order.SetlTime = res.Output.Setlinfo.SetlTime
  1996. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1997. order.MedType = res.Output.Setlinfo.MedType
  1998. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1999. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2000. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2001. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2002. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2003. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2004. order.HifpPay = res.Output.Setlinfo.HifpPay
  2005. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2006. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2007. order.HifesPay = res.Output.Setlinfo.HifesPay
  2008. order.HifobPay = res.Output.Setlinfo.HifobPay
  2009. order.MafPay = res.Output.Setlinfo.MafPay
  2010. order.OthPay = res.Output.Setlinfo.OthPay
  2011. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2012. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2013. order.AcctPay = res.Output.Setlinfo.AcctPay
  2014. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2015. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2016. order.Balc = res.Output.Setlinfo.Balc
  2017. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2018. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2019. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2020. order.ClrWay = res.Output.Setlinfo.ClrWay
  2021. order.Creator = order.Creator
  2022. order.Modify = roles.AdminUserId
  2023. order.RequestLog = src_resquest
  2024. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2025. detailStr := string(setlDetail)
  2026. order.SetlDetail = detailStr
  2027. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2028. err = service.UpDateOrder(order)
  2029. if err == nil {
  2030. c.ServeSuccessJSON(map[string]interface{}{
  2031. "msg": "结算成功",
  2032. })
  2033. } else {
  2034. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2035. return
  2036. }
  2037. }
  2038. } else {
  2039. adminUser := c.GetAdminUserInfo()
  2040. errlog := &models.HisOrderError{
  2041. UserOrgId: adminUser.CurrentOrgId,
  2042. Ctime: time.Now().Unix(),
  2043. Mtime: time.Now().Unix(),
  2044. ErrMsg: res.ErrMsg,
  2045. Status: 1,
  2046. PatientId: id,
  2047. RecordTime: recordDateTime,
  2048. Stage: 4,
  2049. }
  2050. service.CreateErrMsgLog(errlog)
  2051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2052. return
  2053. }
  2054. } else {
  2055. adminUser := c.GetAdminUserInfo()
  2056. errlog := &models.HisOrderError{
  2057. UserOrgId: adminUser.CurrentOrgId,
  2058. Ctime: time.Now().Unix(),
  2059. Mtime: time.Now().Unix(),
  2060. ErrMsg: res.ErrMsg,
  2061. Status: 1,
  2062. PatientId: id,
  2063. RecordTime: recordDateTime,
  2064. Stage: 4,
  2065. }
  2066. service.CreateErrMsgLog(errlog)
  2067. c.ServeSuccessJSON(map[string]interface{}{
  2068. "failed_code": -10,
  2069. "msg": res.ErrMsg,
  2070. })
  2071. return
  2072. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  2073. //return
  2074. }
  2075. } else {
  2076. var total float64
  2077. for _, item := range prescriptions {
  2078. if item.Type == 1 { //药品
  2079. for _, subItem := range item.HisDoctorAdviceInfo {
  2080. total = total + (subItem.Price * subItem.PrescribingNumber)
  2081. }
  2082. }
  2083. if item.Type == 2 { //项目
  2084. for _, subItem := range item.HisPrescriptionProject {
  2085. total = total + (subItem.Price * float64(subItem.Count))
  2086. }
  2087. }
  2088. for _, subItem := range item.HisAdditionalCharge {
  2089. total = total + (subItem.Price * float64(subItem.Count))
  2090. }
  2091. }
  2092. allTotal := fmt.Sprintf("%.2f", total)
  2093. totals, _ := strconv.ParseFloat(allTotal, 64)
  2094. order := &models.HisOrder{
  2095. UserOrgId: adminUser.CurrentOrgId,
  2096. HisPatientId: his.ID,
  2097. PatientId: id,
  2098. SettleAccountsDate: recordDateTime,
  2099. Ctime: time.Now().Unix(),
  2100. Mtime: time.Now().Unix(),
  2101. Status: 1,
  2102. OrderStatus: 2,
  2103. Number: chrg_bchno,
  2104. MedfeeSumamt: totals,
  2105. PayWay: pay_way,
  2106. PayPrice: pay_price,
  2107. PayCardNo: pay_card_no,
  2108. DiscountPrice: discount_price,
  2109. PreferentialPrice: preferential_price,
  2110. RealityPrice: reality_price,
  2111. FoundPrice: found_price,
  2112. MedicalInsurancePrice: medical_insurance_price,
  2113. PrivatePrice: private_price,
  2114. }
  2115. err = service.CreateOrder(order)
  2116. if err != nil {
  2117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2118. return
  2119. }
  2120. var customs []*Custom
  2121. for _, item := range prescriptions {
  2122. if item.Type == 1 { //药品
  2123. for _, subItem := range item.HisDoctorAdviceInfo {
  2124. cus := &Custom{
  2125. AdviceId: subItem.ID,
  2126. ProjectId: 0,
  2127. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  2128. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  2129. FeedetlSn: subItem.FeedetlSn,
  2130. Price: fmt.Sprintf("%.2f", subItem.Price),
  2131. MedListCodg: subItem.MedListCodg,
  2132. Type: 1,
  2133. }
  2134. customs = append(customs, cus)
  2135. }
  2136. }
  2137. if item.Type == 2 { //项目
  2138. for _, subItem := range item.HisPrescriptionProject {
  2139. cus := &Custom{
  2140. AdviceId: 0,
  2141. ProjectId: subItem.ID,
  2142. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  2143. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  2144. FeedetlSn: subItem.FeedetlSn,
  2145. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  2146. MedListCodg: subItem.MedListCodg,
  2147. Type: 2,
  2148. }
  2149. customs = append(customs, cus)
  2150. }
  2151. }
  2152. for _, item := range item.HisAdditionalCharge {
  2153. cus := &Custom{
  2154. ItemId: item.ID,
  2155. AdviceId: 0,
  2156. ProjectId: 0,
  2157. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  2158. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  2159. FeedetlSn: item.FeedetlSn,
  2160. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  2161. MedListCodg: item.XtHisAddtionConfig.Code,
  2162. Type: 3,
  2163. }
  2164. customs = append(customs, cus)
  2165. }
  2166. }
  2167. for _, item := range customs {
  2168. var advice_id int64 = 0
  2169. var project_id int64 = 0
  2170. var item_id int64 = 0
  2171. var types int64 = 0
  2172. if item.Type == 1 {
  2173. advice_id = item.AdviceId
  2174. project_id = 0
  2175. item_id = 0
  2176. } else if item.Type == 2 {
  2177. advice_id = 0
  2178. item_id = 0
  2179. project_id = item.ProjectId
  2180. } else if item.Type == 3 {
  2181. advice_id = 0
  2182. item_id = item.ItemId
  2183. project_id = 0
  2184. }
  2185. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  2186. cut, _ := strconv.ParseFloat(item.Cut, 32)
  2187. pric, _ := strconv.ParseFloat(item.Price, 32)
  2188. info := &models.HisOrderInfo{
  2189. OrderNumber: order.Number,
  2190. UploadDate: time.Now().Unix(),
  2191. AdviceId: advice_id,
  2192. DetItemFeeSumamt: detItemFeeSumamt,
  2193. Cnt: cut,
  2194. Pric: pric,
  2195. PatientId: id,
  2196. Status: 1,
  2197. Mtime: time.Now().Unix(),
  2198. Ctime: time.Now().Unix(),
  2199. UserOrgId: adminUser.CurrentOrgId,
  2200. HisPatientId: his.ID,
  2201. OrderId: order.ID,
  2202. ProjectId: project_id,
  2203. Type: types,
  2204. ItemId: item_id,
  2205. }
  2206. service.CreateOrderInfo(info)
  2207. }
  2208. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2209. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2210. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  2211. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2212. if err == nil {
  2213. c.ServeSuccessJSON(map[string]interface{}{
  2214. "msg": "结算成功",
  2215. })
  2216. } else {
  2217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2218. return
  2219. }
  2220. }
  2221. }
  2222. func (c *HisApiController) GetPreUploadInfo() {
  2223. id, _ := c.GetInt64("id")
  2224. record_time := c.GetString("record_time")
  2225. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2226. admin_user_id, _ := c.GetInt64("admin_user_id")
  2227. timeLayout := "2006-01-02"
  2228. loc, _ := time.LoadLocation("Local")
  2229. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2230. if err != nil {
  2231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2232. return
  2233. }
  2234. recordDateTime := theTime.Unix()
  2235. adminUser := c.GetAdminUserInfo()
  2236. var prescriptions []*models.HisPrescription
  2237. var start_time int64
  2238. var end_time int64
  2239. data := make(map[string]interface{})
  2240. if settle_accounts_type == 1 { //日结
  2241. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  2242. data["pre"] = prescriptions
  2243. } else { //月结
  2244. start_time_str := c.GetString("start_time")
  2245. end_time_str := c.GetString("end_time")
  2246. timeLayout := "2006-01-02"
  2247. loc, _ := time.LoadLocation("Local")
  2248. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2249. if err != nil {
  2250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2251. return
  2252. }
  2253. recordStartTime := theStartTime.Unix()
  2254. start_time = recordStartTime
  2255. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2256. if err != nil {
  2257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2258. return
  2259. }
  2260. recordEndTime := theEndTime.Unix()
  2261. end_time = recordEndTime
  2262. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  2263. data["pre"] = prescriptions
  2264. }
  2265. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2266. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2267. timestamp := time.Now().Unix()
  2268. tempTime := time.Unix(timestamp, 0)
  2269. timeFormat := tempTime.Format("20060102150405")
  2270. chrgBchno := rand.Intn(100000) + 10000
  2271. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  2272. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2273. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2274. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  2275. strconv.FormatInt(his.PatientId, 10)
  2276. client := &http.Client{}
  2277. data["psn_no"] = his.PsnNo
  2278. data["mdtrt_id"] = his.Number
  2279. data["chrg_bchno"] = chrg_bchno
  2280. data["org_name"] = miConfig.OrgName
  2281. data["doctor"] = roles.UserName
  2282. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  2283. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  2284. data["fixmedins_code"] = miConfig.Code
  2285. data["dept_code"] = department.Number
  2286. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  2287. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  2288. data["secret_key"] = miConfig.SecretKey
  2289. var ids []int64
  2290. for _, item := range prescriptions {
  2291. ids = append(ids, item.ID)
  2292. }
  2293. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2294. if config.IsOpen == 1 { //对接了医保,走医保流程
  2295. bytesData, _ := json.Marshal(data)
  2296. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  2297. resp, _ := client.Do(req)
  2298. defer resp.Body.Close()
  2299. body, ioErr := ioutil.ReadAll(resp.Body)
  2300. if ioErr != nil {
  2301. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2303. return
  2304. }
  2305. var respJSON map[string]interface{}
  2306. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  2307. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2309. return
  2310. }
  2311. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2312. userJSONBytes, _ := json.Marshal(respJSON)
  2313. var res ResultFour
  2314. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2315. utils.ErrorLog("解析失败:%v", err)
  2316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2317. return
  2318. }
  2319. if res.Infcode == 0 {
  2320. order := &models.HisOrder{
  2321. UserOrgId: adminUser.CurrentOrgId,
  2322. HisPatientId: his.ID,
  2323. PatientId: his.PatientId,
  2324. SettleAccountsDate: recordDateTime,
  2325. Ctime: time.Now().Unix(),
  2326. Mtime: time.Now().Unix(),
  2327. Status: 1,
  2328. Number: chrg_bchno,
  2329. Infcode: res.Infcode,
  2330. WarnMsg: res.WarnMsg,
  2331. Cainfo: res.Cainfo,
  2332. ErrMsg: res.ErrMsg,
  2333. RespondTime: res.RefmsgTime,
  2334. InfRefmsgid: res.InfRefmsgid,
  2335. OrderStatus: 1,
  2336. IsMedicineInsurance: 1,
  2337. SettleType: settle_accounts_type,
  2338. SettleStartTime: start_time,
  2339. SettleEndTime: end_time,
  2340. Creator: roles.ID,
  2341. Modify: roles.ID,
  2342. }
  2343. err = service.CreateOrder(order)
  2344. if err != nil {
  2345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2346. return
  2347. }
  2348. for _, item := range res.Output.Result {
  2349. temp := strings.Split(item.FeedetlSn, "-")
  2350. var advice_id int64 = 0
  2351. var project_id int64 = 0
  2352. var types int64 = 0
  2353. id, _ := strconv.ParseInt(temp[2], 10, 64)
  2354. types, _ = strconv.ParseInt(temp[1], 10, 64)
  2355. if temp[1] == "1" {
  2356. advice_id = id
  2357. project_id = 0
  2358. } else if temp[1] == "2" {
  2359. advice_id = 0
  2360. project_id = id
  2361. }
  2362. info := &models.HisOrderInfo{
  2363. OrderNumber: order.Number,
  2364. FeedetlSn: item.FeedetlSn,
  2365. UploadDate: time.Now().Unix(),
  2366. AdviceId: advice_id,
  2367. DetItemFeeSumamt: item.DetItemFeeSumamt,
  2368. Cnt: item.Cnt,
  2369. Pric: float64(item.Pric),
  2370. PatientId: his.PatientId,
  2371. PricUplmtAmt: item.PricUplmtAmt,
  2372. SelfpayProp: item.SelfpayProp,
  2373. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2374. OverlmtAmt: item.OverlmtAmt,
  2375. PreselfpayAmt: item.PreselfpayAmt,
  2376. BasMednFlag: item.BasMednFlag,
  2377. MedChrgitmType: item.MedChrgitmType,
  2378. HiNegoDrugFlag: item.HiNegoDrugFlag,
  2379. Status: 1,
  2380. Memo: item.Memo,
  2381. Mtime: time.Now().Unix(),
  2382. InscpScpAmt: item.InscpScpAmt,
  2383. DrtReimFlag: item.DrtReimFlag,
  2384. Ctime: time.Now().Unix(),
  2385. ListSpItemFlag: item.ListSpItemFlag,
  2386. ChldMedcFlag: item.ChldMedcFlag,
  2387. LmtUsedFlag: item.LmtUsedFlag,
  2388. ChrgitmLv: item.ChrgitmLv,
  2389. UserOrgId: adminUser.CurrentOrgId,
  2390. HisPatientId: his.ID,
  2391. OrderId: order.ID,
  2392. ProjectId: project_id,
  2393. Type: types,
  2394. }
  2395. service.CreateOrderInfo(info)
  2396. }
  2397. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2398. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  2399. var total float64
  2400. for _, item := range prescriptions {
  2401. if item.Type == 1 { //药品
  2402. for _, subItem := range item.HisDoctorAdviceInfo {
  2403. total = total + (subItem.Price * subItem.PrescribingNumber)
  2404. }
  2405. }
  2406. if item.Type == 2 { //项目
  2407. for _, subItem := range item.HisPrescriptionProject {
  2408. total = total + (subItem.Price * float64(subItem.Count))
  2409. }
  2410. }
  2411. }
  2412. for _, item := range prescriptions {
  2413. for _, subItem := range item.HisAdditionalCharge {
  2414. total = total + (subItem.Price * float64(subItem.Count))
  2415. }
  2416. }
  2417. allTotal := fmt.Sprintf("%.2f", total)
  2418. if res.Infcode == 0 {
  2419. var rf []*ResultFive
  2420. json.Unmarshal([]byte(his.Iinfo), &rf)
  2421. psn_no := his.PsnNo
  2422. mdtrt_id := his.Number
  2423. chrg_bchno := chrg_bchno
  2424. cert_no := his.Certno
  2425. insutype := rf[0].Insutype
  2426. if his.IdCardType == 1 {
  2427. cert_no = his.MedicalInsuranceNumber
  2428. } else {
  2429. cert_no = his.Certno
  2430. }
  2431. api := "http://127.0.0.1:9532/" + "gdyb/seven?cert_no=" + cert_no + "&insutype=" +
  2432. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  2433. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  2434. miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10)
  2435. resp, requestErr := http.Get(api)
  2436. if requestErr != nil {
  2437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2438. return
  2439. }
  2440. defer resp.Body.Close()
  2441. body, ioErr := ioutil.ReadAll(resp.Body)
  2442. if ioErr != nil {
  2443. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2445. return
  2446. }
  2447. var respJSON map[string]interface{}
  2448. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2449. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2451. return
  2452. }
  2453. fmt.Println(respJSON)
  2454. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2455. userJSONBytes, _ := json.Marshal(respJSON)
  2456. var res ResultSeven
  2457. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2458. utils.ErrorLog("解析失败:%v", err)
  2459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2460. return
  2461. }
  2462. if res.Infcode == -1 {
  2463. errlog := &models.HisOrderError{
  2464. UserOrgId: adminUser.CurrentOrgId,
  2465. Ctime: time.Now().Unix(),
  2466. Mtime: time.Now().Unix(),
  2467. Number: chrg_bchno,
  2468. ErrMsg: res.ErrMsg,
  2469. Status: 1,
  2470. PatientId: id,
  2471. RecordTime: recordDateTime,
  2472. Stage: 7,
  2473. }
  2474. service.CreateErrMsgLog(errlog)
  2475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2476. return
  2477. } else {
  2478. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2479. order.OrderStatus = 1
  2480. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2481. order.SetlId = res.Output.Setlinfo.SetlID
  2482. order.PsnNo = res.Output.Setlinfo.PsnNo
  2483. order.PsnName = res.Output.Setlinfo.PsnName
  2484. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2485. order.Certno = res.Output.Setlinfo.Certno
  2486. order.Gend = res.Output.Setlinfo.Gend
  2487. order.Naty = res.Output.Setlinfo.Naty
  2488. order.Age = res.Output.Setlinfo.Age
  2489. order.Insutype = res.Output.Setlinfo.Insutype
  2490. order.PsnType = res.Output.Setlinfo.PsnType
  2491. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2492. order.SetlTime = res.Output.Setlinfo.SetlTime
  2493. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2494. order.MedType = res.Output.Setlinfo.MedType
  2495. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2496. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2497. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2498. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2499. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2500. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2501. order.HifpPay = res.Output.Setlinfo.HifpPay
  2502. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2503. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2504. order.HifesPay = res.Output.Setlinfo.HifesPay
  2505. order.HifobPay = res.Output.Setlinfo.HifobPay
  2506. order.MafPay = res.Output.Setlinfo.MafPay
  2507. order.OthPay = res.Output.Setlinfo.OthPay
  2508. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2509. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2510. order.AcctPay = res.Output.Setlinfo.AcctPay
  2511. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2512. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2513. order.Balc = res.Output.Setlinfo.Balc
  2514. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2515. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2516. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2517. order.ClrWay = res.Output.Setlinfo.ClrWay
  2518. order.Creator = order.Creator
  2519. order.Modify = roles.ID
  2520. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2521. detailStr := string(setlDetail)
  2522. order.SetlDetail = detailStr
  2523. //err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2524. err = service.UpDateOrder(order)
  2525. if err == nil {
  2526. c.ServeSuccessJSON(map[string]interface{}{
  2527. "msg": "预结算成功",
  2528. })
  2529. } else {
  2530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2531. return
  2532. }
  2533. }
  2534. } else {
  2535. adminUser := c.GetAdminUserInfo()
  2536. errlog := &models.HisOrderError{
  2537. UserOrgId: adminUser.CurrentOrgId,
  2538. Ctime: time.Now().Unix(),
  2539. Mtime: time.Now().Unix(),
  2540. ErrMsg: res.ErrMsg,
  2541. Status: 1,
  2542. PatientId: id,
  2543. RecordTime: recordDateTime,
  2544. Stage: 4,
  2545. }
  2546. service.CreateErrMsgLog(errlog)
  2547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2548. return
  2549. }
  2550. } else {
  2551. adminUser := c.GetAdminUserInfo()
  2552. errlog := &models.HisOrderError{
  2553. UserOrgId: adminUser.CurrentOrgId,
  2554. Ctime: time.Now().Unix(),
  2555. Mtime: time.Now().Unix(),
  2556. ErrMsg: res.ErrMsg,
  2557. Status: 1,
  2558. PatientId: id,
  2559. RecordTime: recordDateTime,
  2560. Stage: 4,
  2561. }
  2562. service.CreateErrMsgLog(errlog)
  2563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  2564. return
  2565. }
  2566. } else {
  2567. var total float64
  2568. for _, item := range prescriptions {
  2569. if item.Type == 1 { //药品
  2570. for _, subItem := range item.HisDoctorAdviceInfo {
  2571. total = total + (subItem.Price * subItem.PrescribingNumber)
  2572. }
  2573. }
  2574. if item.Type == 2 { //项目
  2575. for _, subItem := range item.HisPrescriptionProject {
  2576. total = total + (subItem.Price * float64(subItem.Count))
  2577. }
  2578. }
  2579. for _, subItem := range item.HisAdditionalCharge {
  2580. total = total + (subItem.Price * float64(subItem.Count))
  2581. }
  2582. }
  2583. allTotal := fmt.Sprintf("%.2f", total)
  2584. totals, _ := strconv.ParseFloat(allTotal, 64)
  2585. order := &models.HisOrder{
  2586. UserOrgId: adminUser.CurrentOrgId,
  2587. HisPatientId: his.ID,
  2588. PatientId: id,
  2589. SettleAccountsDate: recordDateTime,
  2590. Ctime: time.Now().Unix(),
  2591. Mtime: time.Now().Unix(),
  2592. Status: 1,
  2593. OrderStatus: 2,
  2594. Number: chrg_bchno,
  2595. MedfeeSumamt: totals,
  2596. }
  2597. err = service.CreateOrder(order)
  2598. if err != nil {
  2599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2600. return
  2601. }
  2602. var customs []*Custom
  2603. for _, item := range prescriptions {
  2604. if item.Type == 1 { //药品
  2605. for _, subItem := range item.HisDoctorAdviceInfo {
  2606. cus := &Custom{
  2607. AdviceId: subItem.ID,
  2608. ProjectId: 0,
  2609. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  2610. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  2611. FeedetlSn: subItem.FeedetlSn,
  2612. Price: fmt.Sprintf("%.2f", subItem.Price),
  2613. MedListCodg: subItem.MedListCodg,
  2614. Type: 1,
  2615. }
  2616. customs = append(customs, cus)
  2617. }
  2618. }
  2619. if item.Type == 2 { //项目
  2620. for _, subItem := range item.HisPrescriptionProject {
  2621. cus := &Custom{
  2622. AdviceId: 0,
  2623. ProjectId: subItem.ID,
  2624. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  2625. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  2626. FeedetlSn: subItem.FeedetlSn,
  2627. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  2628. MedListCodg: subItem.MedListCodg,
  2629. Type: 2,
  2630. }
  2631. customs = append(customs, cus)
  2632. }
  2633. }
  2634. for _, item := range item.HisAdditionalCharge {
  2635. cus := &Custom{
  2636. ItemId: item.ID,
  2637. AdviceId: 0,
  2638. ProjectId: 0,
  2639. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  2640. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  2641. FeedetlSn: item.FeedetlSn,
  2642. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  2643. MedListCodg: item.XtHisAddtionConfig.Code,
  2644. Type: 3,
  2645. }
  2646. customs = append(customs, cus)
  2647. }
  2648. }
  2649. for _, item := range customs {
  2650. var advice_id int64 = 0
  2651. var project_id int64 = 0
  2652. var item_id int64 = 0
  2653. var types int64 = 0
  2654. if item.Type == 1 {
  2655. advice_id = item.AdviceId
  2656. project_id = 0
  2657. item_id = 0
  2658. } else if item.Type == 2 {
  2659. advice_id = 0
  2660. item_id = 0
  2661. project_id = item.ProjectId
  2662. } else if item.Type == 3 {
  2663. advice_id = 0
  2664. item_id = item.ItemId
  2665. project_id = 0
  2666. }
  2667. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  2668. cut, _ := strconv.ParseFloat(item.Cut, 32)
  2669. pric, _ := strconv.ParseFloat(item.Price, 32)
  2670. info := &models.HisOrderInfo{
  2671. OrderNumber: order.Number,
  2672. UploadDate: time.Now().Unix(),
  2673. AdviceId: advice_id,
  2674. DetItemFeeSumamt: detItemFeeSumamt,
  2675. Cnt: cut,
  2676. Pric: pric,
  2677. PatientId: id,
  2678. Status: 1,
  2679. Mtime: time.Now().Unix(),
  2680. Ctime: time.Now().Unix(),
  2681. UserOrgId: adminUser.CurrentOrgId,
  2682. HisPatientId: his.ID,
  2683. OrderId: order.ID,
  2684. ProjectId: project_id,
  2685. Type: types,
  2686. ItemId: item_id,
  2687. }
  2688. service.CreateOrderInfo(info)
  2689. }
  2690. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2691. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2692. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  2693. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2694. if err == nil {
  2695. c.ServeSuccessJSON(map[string]interface{}{
  2696. "msg": "结算成功",
  2697. })
  2698. } else {
  2699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2700. return
  2701. }
  2702. }
  2703. }
  2704. //func (c *HisApiController) GetSettleInfo() {
  2705. // id, _ := c.GetInt64("id")
  2706. // order_id, _ := c.GetInt64("order_id")
  2707. //
  2708. // record_time := c.GetString("record_time")
  2709. // pay_way, _ := c.GetInt64("pay_way")
  2710. // pay_price, _ := c.GetFloat("pay_price")
  2711. // pay_card_no := c.GetString("pay_card_no")
  2712. // discount_price, _ := c.GetFloat("discount_price")
  2713. // preferential_price, _ := c.GetFloat("preferential_price")
  2714. // reality_price, _ := c.GetFloat("reality_price")
  2715. // found_price, _ := c.GetFloat("found_price")
  2716. // medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2717. // private_price, _ := c.GetFloat("private_price")
  2718. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2719. // admin_user_id, _ := c.GetInt64("admin_user_id")
  2720. //
  2721. // timeLayout := "2006-01-02"
  2722. // loc, _ := time.LoadLocation("Local")
  2723. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2724. // if err != nil {
  2725. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2726. // return
  2727. // }
  2728. // recordDateTime := theTime.Unix()
  2729. // adminUser := c.GetAdminUserInfo()
  2730. //
  2731. // var prescriptions []*models.HisPrescription
  2732. //
  2733. // data := make(map[string]interface{})
  2734. // if settle_accounts_type == 1 { //日结
  2735. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  2736. // data["pre"] = prescriptions
  2737. //
  2738. // } else { //月结
  2739. // start_time_str := c.GetString("start_time")
  2740. // end_time_str := c.GetString("end_time")
  2741. // timeLayout := "2006-01-02"
  2742. // loc, _ := time.LoadLocation("Local")
  2743. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2744. // if err != nil {
  2745. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2746. // return
  2747. // }
  2748. // recordStartTime := theStartTime.Unix()
  2749. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2750. // if err != nil {
  2751. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2752. // return
  2753. // }
  2754. // recordEndTime := theEndTime.Unix()
  2755. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  2756. // data["pre"] = prescriptions
  2757. //
  2758. // }
  2759. //
  2760. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2761. //
  2762. // his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2763. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2764. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2765. // strconv.FormatInt(his.PatientId, 10)
  2766. //
  2767. // order_src, _ := service.GetHisOrderByID(order_id)
  2768. //
  2769. // config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2770. // if config.IsOpen == 1 { //对接了医保,走医保流程
  2771. //
  2772. // var total float64
  2773. // for _, item := range prescriptions {
  2774. // if item.Type == 1 { //药品
  2775. // for _, subItem := range item.HisDoctorAdviceInfo {
  2776. // total = total + (subItem.Price * subItem.PrescribingNumber)
  2777. // }
  2778. // }
  2779. // if item.Type == 2 { //项目
  2780. // for _, subItem := range item.HisPrescriptionProject {
  2781. // total = total + (subItem.Price * float64(subItem.Count))
  2782. // }
  2783. // }
  2784. // }
  2785. //
  2786. // for _, item := range prescriptions {
  2787. // for _, subItem := range item.HisAdditionalCharge {
  2788. // total = total + (subItem.Price * float64(subItem.Count))
  2789. // }
  2790. // }
  2791. //
  2792. // allTotal := fmt.Sprintf("%.2f", total)
  2793. // var rf []*ResultFive
  2794. // json.Unmarshal([]byte(his.Iinfo), &rf)
  2795. // psn_no := order_src.PsnNo
  2796. // mdtrt_id := order_src.MdtrtId
  2797. // chrg_bchno := order_src.Number
  2798. // cert_no := order_src.Certno
  2799. // insutype := rf[0].Insutype
  2800. //
  2801. // if his.IdCardType == 1 {
  2802. // cert_no = his.MedicalInsuranceNumber
  2803. // } else {
  2804. // cert_no = his.Certno
  2805. // }
  2806. //
  2807. // result, src_resquest := service.Gdyb2207(his.PsnNo, his.Number, chrg_bchno, cert_no, insutype, strconv.FormatFloat(total, 'E', -1, 64) ,miConfig.OrgName,roles.UserName,miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, strconv.FormatInt(patientPrescription.RegisterType, 10),his.IdCardType, order_src.FulamtOwnpayAmt,order_src.OverlmtSelfPay,order_src.PreselfpayAmt,order_src.InscpScpAmt)
  2808. // var dat map[string]interface{}
  2809. // if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2810. // fmt.Println(dat)
  2811. // } else {
  2812. // fmt.Println(err)
  2813. // }
  2814. //
  2815. // userJSONBytes, _ := json.Marshal(dat)
  2816. //
  2817. //
  2818. //
  2819. // var res ResultSeven
  2820. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2821. // utils.ErrorLog("解析失败:%v", err)
  2822. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2823. // return
  2824. // }
  2825. // if res.Infcode == -1 {
  2826. // errlog := &models.HisOrderError{
  2827. // UserOrgId: adminUser.CurrentOrgId,
  2828. // Ctime: time.Now().Unix(),
  2829. // Mtime: time.Now().Unix(),
  2830. // Number: chrg_bchno,
  2831. // ErrMsg: res.ErrMsg,
  2832. // Status: 1,
  2833. // PatientId: id,
  2834. // RecordTime: recordDateTime,
  2835. // Stage: 6,
  2836. // }
  2837. // service.CreateErrMsgLog(errlog)
  2838. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2839. // return
  2840. // } else {
  2841. // order_src.OrderStatus = 2
  2842. // order_src.PayWay = pay_way
  2843. // order_src.PayPrice = pay_price
  2844. // order_src.PayCardNo = pay_card_no
  2845. // order_src.DiscountPrice = discount_price
  2846. // order_src.PreferentialPrice = preferential_price
  2847. // order_src.RealityPrice = reality_price
  2848. // order_src.FoundPrice = found_price
  2849. // order_src.MedicalInsurancePrice = medical_insurance_price
  2850. // order_src.PrivatePrice = private_price
  2851. // order_src.MdtrtId = res.Output.Setlinfo.MdtrtID
  2852. // order_src.SetlId = res.Output.Setlinfo.SetlID
  2853. // order_src.PsnNo = res.Output.Setlinfo.PsnNo
  2854. // order_src.PsnName = res.Output.Setlinfo.PsnName
  2855. // order_src.PsnCertType = res.Output.Setlinfo.PsnCertType
  2856. // order_src.Certno = res.Output.Setlinfo.Certno
  2857. // order_src.Gend = res.Output.Setlinfo.Gend
  2858. // order_src.Naty = res.Output.Setlinfo.Naty
  2859. // order_src.Age = res.Output.Setlinfo.Age
  2860. // order_src.Insutype = res.Output.Setlinfo.Insutype
  2861. // order_src.PsnType = res.Output.Setlinfo.PsnType
  2862. // order_src.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2863. // order_src.SetlTime = res.Output.Setlinfo.SetlTime
  2864. // order_src.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2865. // order_src.MedType = res.Output.Setlinfo.MedType
  2866. // order_src.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2867. // order_src.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2868. // order_src.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2869. // order_src.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2870. // order_src.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2871. // order_src.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2872. // order_src.HifpPay = res.Output.Setlinfo.HifpPay
  2873. // order_src.CvlservPay = res.Output.Setlinfo.CvlservPay
  2874. // order_src.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2875. // order_src.HifesPay = res.Output.Setlinfo.HifesPay
  2876. // order_src.HifobPay = res.Output.Setlinfo.HifobPay
  2877. // order_src.MafPay = res.Output.Setlinfo.MafPay
  2878. // order_src.OthPay = res.Output.Setlinfo.OthPay
  2879. // order_src.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2880. // order_src.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2881. // order_src.AcctPay = res.Output.Setlinfo.AcctPay
  2882. // order_src.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2883. // order_src.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2884. // order_src.Balc = res.Output.Setlinfo.Balc
  2885. // order_src.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2886. // order_src.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2887. // order_src.ClrOptins = res.Output.Setlinfo.ClrOptins
  2888. // order_src.ClrWay = res.Output.Setlinfo.ClrWay
  2889. // order_src.Creator = order_src.Creator
  2890. // order_src.Modify = roles.ID
  2891. // order_src.RequestLog = src_resquest
  2892. // setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2893. // detailStr := string(setlDetail)
  2894. // order_src.SetlDetail = detailStr
  2895. // err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2896. // err = service.UpDateOrder(order_src)
  2897. //
  2898. // if err == nil {
  2899. // c.ServeSuccessJSON(map[string]interface{}{
  2900. // "msg": "结算成功",
  2901. // })
  2902. // } else {
  2903. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2904. // return
  2905. // }
  2906. // }
  2907. // }
  2908. //}
  2909. //退款
  2910. func (c *HisApiController) Refund() {
  2911. order_id, _ := c.GetInt64("order_id")
  2912. admin_user_id, _ := c.GetInt64("admin_user_id")
  2913. record_time := c.GetString("record_time")
  2914. patient_id, _ := c.GetInt64("patient_id")
  2915. timeLayout := "2006-01-02"
  2916. loc, _ := time.LoadLocation("Local")
  2917. adminUser := c.GetAdminUserInfo()
  2918. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2919. if err != nil {
  2920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2921. return
  2922. }
  2923. recordDateTime := theTime.Unix()
  2924. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2925. var order models.HisOrder
  2926. order, _ = service.GetHisOrderByID(order_id)
  2927. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2928. if order.ID == 0 {
  2929. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  2930. }
  2931. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2932. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2933. if config.IsOpen == 1 { //对接了医保,走医保流程
  2934. result, src_resquest := service.Gdyb2208(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2935. var dat map[string]interface{}
  2936. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2937. fmt.Println(dat)
  2938. } else {
  2939. fmt.Println(err)
  2940. }
  2941. userJSONBytes, _ := json.Marshal(dat)
  2942. var res ResultSixteen
  2943. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2944. utils.ErrorLog("解析失败:%v", err)
  2945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2946. return
  2947. }
  2948. if res.Infcode == 0 {
  2949. result := service.Gdyb2205(order.PsnNo, order.MdtrtId, order.Number, miConfig.OrgName, roles.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  2950. var dat map[string]interface{}
  2951. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2952. fmt.Println(dat)
  2953. } else {
  2954. fmt.Println(err)
  2955. }
  2956. userJSONBytes, _ := json.Marshal(dat)
  2957. var res2 ResultSix
  2958. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2959. utils.ErrorLog("解析失败:%v", err)
  2960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2961. return
  2962. }
  2963. if res2.Infcode == 0 {
  2964. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, src_resquest, result)
  2965. if err == nil {
  2966. c.ServeSuccessJSON(map[string]interface{}{
  2967. "msg": "退费成功",
  2968. })
  2969. } else {
  2970. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2971. return
  2972. }
  2973. } else {
  2974. c.ServeSuccessJSON(map[string]interface{}{
  2975. "code": -10,
  2976. "msg": res2.ErrMsg,
  2977. })
  2978. }
  2979. } else {
  2980. c.ServeSuccessJSON(map[string]interface{}{
  2981. "code": -10,
  2982. "msg": res.ErrMsg,
  2983. })
  2984. }
  2985. } else {
  2986. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  2987. if err == nil {
  2988. c.ServeSuccessJSON(map[string]interface{}{
  2989. "msg": "退费成功",
  2990. })
  2991. } else {
  2992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2993. return
  2994. }
  2995. }
  2996. }
  2997. func (c *HisApiController) RefundNumber() {
  2998. record_time := c.GetString("record_time")
  2999. patient_id, _ := c.GetInt64("patient_id")
  3000. admin_user_id, _ := c.GetInt64("admin_user_id")
  3001. //his_patient_id, _ := c.GetInt64("id")
  3002. timeLayout := "2006-01-02"
  3003. loc, _ := time.LoadLocation("Local")
  3004. adminUser := c.GetAdminUserInfo()
  3005. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3006. fmt.Println(err)
  3007. if err != nil {
  3008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3009. return
  3010. }
  3011. recordDateTime := theTime.Unix()
  3012. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3013. //his, _ := service.GetNewHisPatientRecord(adminUser.CurrentOrgId, patient_id)
  3014. //patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3015. //order, _ := service.GetHisOrderByID(order_id)
  3016. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3017. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3018. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3019. if config.IsOpen == 1 { //对接了医保,走医保流程
  3020. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  3021. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + roles.UserName + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  3022. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3023. resp3, requestErr3 := http.Get(api3)
  3024. if requestErr3 != nil {
  3025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3026. return
  3027. }
  3028. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  3029. if ioErr3 != nil {
  3030. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  3031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3032. return
  3033. }
  3034. var respJSON3 map[string]interface{}
  3035. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  3036. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3038. return
  3039. }
  3040. respJSON3 = respJSON3["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3041. userJSONBytes3, _ := json.Marshal(respJSON3)
  3042. var res2 ResultSix
  3043. if err := json.Unmarshal(userJSONBytes3, &res2); err != nil {
  3044. utils.ErrorLog("解析失败:%v", err)
  3045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3046. return
  3047. }
  3048. if res2.Infcode == 0 {
  3049. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  3050. service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  3051. //err := service.UpdataRegStatus2()
  3052. if err == nil {
  3053. c.ServeSuccessJSON(map[string]interface{}{
  3054. "msg": "退号成功",
  3055. })
  3056. } else {
  3057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3058. return
  3059. }
  3060. } else {
  3061. c.ServeSuccessJSON(map[string]interface{}{
  3062. "code": -10,
  3063. "msg": res2.ErrMsg,
  3064. })
  3065. }
  3066. } else {
  3067. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  3068. //if err == nil {
  3069. // c.ServeSuccessJSON(map[string]interface{}{
  3070. // "msg": "退费成功",
  3071. // })
  3072. //} else {
  3073. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3074. // return
  3075. //}
  3076. }
  3077. }
  3078. func (c *HisApiController) RefundDetail() {
  3079. order_id, _ := c.GetInt64("order_id")
  3080. his_patient_id, _ := c.GetInt64("his_patient_id")
  3081. number := c.GetString("number")
  3082. record_time := c.GetString("record_time")
  3083. patient_id, _ := c.GetInt64("patient_id")
  3084. timeLayout := "2006-01-02"
  3085. loc, _ := time.LoadLocation("Local")
  3086. adminUser := c.GetAdminUserInfo()
  3087. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3088. fmt.Println(err)
  3089. if err != nil {
  3090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3091. return
  3092. }
  3093. recordDateTime := theTime.Unix()
  3094. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  3095. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3096. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3097. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3098. var order models.HisOrder
  3099. order, _ = service.GetHisOrderByID(order_id)
  3100. if order.ID == 0 {
  3101. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  3102. }
  3103. if config.IsOpen == 1 { //对接了医保,走医保流程
  3104. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  3105. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  3106. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3107. resp2, requestErr2 := http.Get(api2)
  3108. if requestErr2 != nil {
  3109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3110. return
  3111. }
  3112. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  3113. if ioErr2 != nil {
  3114. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  3115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3116. return
  3117. }
  3118. var respJSON2 map[string]interface{}
  3119. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  3120. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3122. return
  3123. }
  3124. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId, "", "")
  3125. if err == nil {
  3126. c.ServeSuccessJSON(map[string]interface{}{
  3127. "msg": "退费成功",
  3128. })
  3129. } else {
  3130. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3131. return
  3132. }
  3133. } else {
  3134. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId, "", "")
  3135. if err == nil {
  3136. c.ServeSuccessJSON(map[string]interface{}{
  3137. "msg": "退费成功",
  3138. })
  3139. } else {
  3140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3141. return
  3142. }
  3143. }
  3144. }
  3145. //对账
  3146. func (c *HisApiController) GetCheckAccount() {
  3147. start_time := c.GetString("start_time")
  3148. end_time := c.GetString("end_time")
  3149. insutype := c.GetString("insutype")
  3150. clr_type := c.GetString("clr_type")
  3151. admin_user_id, _ := c.GetInt64("admin_user_id")
  3152. adminUser := c.GetAdminUserInfo()
  3153. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3154. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3155. timeLayout := "2006-01-02"
  3156. loc, _ := time.LoadLocation("Local")
  3157. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3158. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3159. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  3160. //orders_two, _ := service.GetOrderByTimeThree(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  3161. fixmedins_setl_cnt := int64(len(orders))
  3162. //
  3163. ////撤销的算2条数据为一笔
  3164. //for _, item := range orders_two {
  3165. // if item.OrderStatus == 3 {
  3166. // fixmedins_setl_cnt = fixmedins_setl_cnt + 1
  3167. // }
  3168. //}
  3169. var medfee_sumamt float64
  3170. var acct_pay float64
  3171. var fund_pay_sumamt float64
  3172. for _, item := range orders {
  3173. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  3174. acct_pay = acct_pay + item.AcctPay
  3175. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  3176. }
  3177. var user_name string
  3178. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3179. if role.ID == 0 {
  3180. user_name = "xxx"
  3181. } else {
  3182. user_name = role.UserName
  3183. }
  3184. if config.IsOpen == 1 {
  3185. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  3186. "insutype=" + insutype +
  3187. "&clr_type=" + clr_type +
  3188. "&setl_optins=" + "定点医保中心" +
  3189. "&stmt_begndate=" + start_time +
  3190. "&stm_enddate=" + end_time +
  3191. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  3192. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  3193. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  3194. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  3195. "&fixmedins_code=" + miConfig.Code +
  3196. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3197. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3198. "&secret_key=" + miConfig.SecretKey +
  3199. "&org_name=" + miConfig.OrgName +
  3200. "&doctor=" + user_name
  3201. fmt.Println(api)
  3202. resp, requestErr := http.Get(api)
  3203. if requestErr != nil {
  3204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3205. return
  3206. }
  3207. body, ioErr := ioutil.ReadAll(resp.Body)
  3208. fmt.Println(body)
  3209. if ioErr != nil {
  3210. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3212. return
  3213. }
  3214. var respJSON map[string]interface{}
  3215. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3216. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3218. return
  3219. }
  3220. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3221. userJSONBytes, _ := json.Marshal(respJSON)
  3222. var res ResultEight
  3223. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3224. utils.ErrorLog("解析失败:%v", err)
  3225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3226. return
  3227. }
  3228. if res.Infcode == 0 {
  3229. if res.Output.Stmtinfo.StmtRslt == "0" {
  3230. micc := &models.MedicalInsuranceCostCompare{
  3231. StartTime: startime.Unix(),
  3232. EndTime: endtime.Unix(),
  3233. Insutype: insutype,
  3234. CheckType: 1,
  3235. Num: fixmedins_setl_cnt,
  3236. Mtime: time.Now().Unix(),
  3237. Status: 1,
  3238. UserOrgId: adminUser.CurrentOrgId,
  3239. CostTotal: medfee_sumamt,
  3240. FuncTotal: fund_pay_sumamt,
  3241. PsnPay: acct_pay,
  3242. Creator: admin_user_id,
  3243. Ctime: time.Now().Unix(),
  3244. }
  3245. err := service.CreateMedicalInsuranceCostCompareRecord(micc)
  3246. if err == nil {
  3247. c.ServeSuccessJSON(map[string]interface{}{
  3248. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  3249. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  3250. })
  3251. } else {
  3252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3253. }
  3254. } else {
  3255. c.ServeSuccessJSON(map[string]interface{}{
  3256. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  3257. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  3258. })
  3259. }
  3260. } else {
  3261. c.ServeSuccessJSON(map[string]interface{}{
  3262. "code": -10,
  3263. "msg": res.ErrMsg,
  3264. })
  3265. }
  3266. }
  3267. }
  3268. func (c *HisApiController) Check310() {
  3269. adminUser := c.GetAdminUserInfo()
  3270. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3271. var user_name string
  3272. user_name = "xxx"
  3273. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  3274. "insutype=" + "310" +
  3275. "&clr_type=" + "11" +
  3276. "&setl_optins=" + "定点医保中心" +
  3277. "&stmt_begndate=" + "2021-03-01" +
  3278. "&stm_enddate=" + "2021-03-31" +
  3279. "&medfee_sumamt=" + "11521" +
  3280. "&fund_pay_sumamt=" + "10166.66" +
  3281. "&acct_pay=" + "0" +
  3282. "&fixmedins_setl_cnt=" + "7" +
  3283. "&fixmedins_code=" + miConfig.Code +
  3284. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3285. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3286. "&secret_key=" + miConfig.SecretKey +
  3287. "&org_name=" + miConfig.OrgName +
  3288. "&doctor=" + user_name
  3289. fmt.Println(api)
  3290. resp, requestErr := http.Get(api)
  3291. if requestErr != nil {
  3292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3293. return
  3294. }
  3295. body, ioErr := ioutil.ReadAll(resp.Body)
  3296. fmt.Println(body)
  3297. if ioErr != nil {
  3298. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3300. return
  3301. }
  3302. var respJSON map[string]interface{}
  3303. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3304. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3306. return
  3307. }
  3308. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3309. userJSONBytes, _ := json.Marshal(respJSON)
  3310. var res ResultEight
  3311. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3312. utils.ErrorLog("解析失败:%v", err)
  3313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3314. return
  3315. }
  3316. }
  3317. func (c *HisApiController) Check390() {
  3318. adminUser := c.GetAdminUserInfo()
  3319. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3320. var user_name string
  3321. user_name = "张俊杰"
  3322. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  3323. "insutype=" + "390" +
  3324. "&clr_type=" + "11" +
  3325. "&setl_optins=" + "定点医保中心" +
  3326. "&stmt_begndate=" + "2021-03-01" +
  3327. "&stm_enddate=" + "2021-03-31" +
  3328. "&medfee_sumamt=" + "209318.43" +
  3329. "&fund_pay_sumamt=" + "188029.12" +
  3330. "&acct_pay=" + "0" +
  3331. "&fixmedins_setl_cnt=" + "48" +
  3332. "&fixmedins_code=" + miConfig.Code +
  3333. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3334. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3335. "&secret_key=" + miConfig.SecretKey +
  3336. "&org_name=" + miConfig.OrgName +
  3337. "&doctor=" + user_name
  3338. fmt.Println(api)
  3339. resp, requestErr := http.Get(api)
  3340. if requestErr != nil {
  3341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3342. return
  3343. }
  3344. body, ioErr := ioutil.ReadAll(resp.Body)
  3345. fmt.Println(body)
  3346. if ioErr != nil {
  3347. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3349. return
  3350. }
  3351. var respJSON map[string]interface{}
  3352. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3353. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3355. return
  3356. }
  3357. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3358. userJSONBytes, _ := json.Marshal(respJSON)
  3359. var res ResultEight
  3360. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3361. utils.ErrorLog("解析失败:%v", err)
  3362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3363. return
  3364. }
  3365. }
  3366. //对账明细
  3367. func (c *HisApiController) GetCheckDetailAccount() {
  3368. start_time := c.GetString("start_time")
  3369. end_time := c.GetString("end_time")
  3370. admin_user_id, _ := c.GetInt64("admin_user_id")
  3371. adminUser := c.GetAdminUserInfo()
  3372. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3373. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3374. timeLayout := "2006-01-02"
  3375. loc, _ := time.LoadLocation("Local")
  3376. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3377. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3378. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  3379. Mkdir(miConfig.OrgName)
  3380. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  3381. file_name := file + ".txt"
  3382. zip_name := file + ".zip"
  3383. zip_path := miConfig.OrgName + "/" + zip_name
  3384. file_path := miConfig.OrgName + "/" + file_name
  3385. decimal.DivisionPrecision = 2
  3386. var medfee_sumamt float64
  3387. var psn_cash_pay float64
  3388. var fund_pay_sumamt float64
  3389. fixmedins_setl_cnt := int64(len(orders))
  3390. for _, item := range orders {
  3391. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  3392. psn_cash_pay = psn_cash_pay + item.PsnCashPay
  3393. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  3394. }
  3395. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  3396. defer f.Close()
  3397. if err != nil {
  3398. fmt.Println(err.Error())
  3399. } else {
  3400. for _, item := range orders {
  3401. var refd_setl_flag string
  3402. if item.OrderStatus == 2 {
  3403. refd_setl_flag = "0"
  3404. var str string
  3405. str = item.SetlId + " " +
  3406. item.MdtrtId + " " +
  3407. item.PsnNo + " " +
  3408. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  3409. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  3410. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\r\n"
  3411. _, err = f.Write([]byte(str))
  3412. }
  3413. if item.OrderStatus == 3 {
  3414. var str string
  3415. str = item.SetlId + " " +
  3416. item.MdtrtId + " " +
  3417. item.PsnNo + " " +
  3418. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  3419. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  3420. fmt.Sprintf("%.2f", item.AcctPay) + " " + "1" + "\r\n"
  3421. _, err = f.Write([]byte(str))
  3422. var str2 string
  3423. str2 = item.SetlId + " " +
  3424. item.MdtrtId + " " +
  3425. item.PsnNo + " " +
  3426. fmt.Sprintf("%.2f", 0-item.MedfeeSumamt) + " " +
  3427. fmt.Sprintf("%.2f", 0-item.FundPaySumamt) + " " +
  3428. fmt.Sprintf("%.2f", 0-item.AcctPay) + " " + "1" + "\r\n"
  3429. _, err = f.Write([]byte(str2))
  3430. }
  3431. }
  3432. }
  3433. Zip(file_path, zip_path)
  3434. fmt.Println(ReadFile(zip_path))
  3435. fmt.Println(string(ReadFile(zip_path)))
  3436. if config.IsOpen == 1 {
  3437. var user_name string
  3438. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3439. if role.ID == 0 {
  3440. user_name = "管理员"
  3441. } else {
  3442. user_name = role.UserName
  3443. }
  3444. baseParams := models.BaseParams{
  3445. SecretKey: miConfig.SecretKey,
  3446. FixmedinsCode: miConfig.Code,
  3447. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3448. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3449. OrgName: miConfig.OrgName,
  3450. Doctor: user_name,
  3451. }
  3452. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  3453. var dat map[string]interface{}
  3454. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3455. fmt.Println(dat)
  3456. } else {
  3457. fmt.Println(err)
  3458. }
  3459. userJSONBytes, _ := json.Marshal(dat)
  3460. var res ResultNine
  3461. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3462. utils.ErrorLog("解析失败:%v", err)
  3463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3464. return
  3465. }
  3466. if res.Infcode == 0 {
  3467. fileNo := res.Output.FileQuryNo
  3468. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  3469. "file_qury_no=" + fileNo +
  3470. "&setl_optins=" + "定点医保中心" +
  3471. "&stmt_begndate=" + start_time +
  3472. "&stm_enddate=" + end_time +
  3473. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  3474. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  3475. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  3476. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  3477. "&fixmedins_code=" + miConfig.Code +
  3478. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3479. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3480. "&secret_key=" + miConfig.SecretKey +
  3481. "&org_name=" + miConfig.OrgName +
  3482. "&doctor=" + user_name
  3483. resp, requestErr := http.Get(api)
  3484. if requestErr != nil {
  3485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3486. return
  3487. }
  3488. body, ioErr := ioutil.ReadAll(resp.Body)
  3489. if ioErr != nil {
  3490. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3492. return
  3493. }
  3494. var respJSON map[string]interface{}
  3495. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3496. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3498. return
  3499. }
  3500. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3501. userJSONBytes, _ := json.Marshal(respJSON)
  3502. var res ResultTen
  3503. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3504. utils.ErrorLog("解析失败:%v", err)
  3505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3506. return
  3507. }
  3508. if res.Infcode == 0 {
  3509. service.Gdyb9102(baseParams, zip_name, fileNo)
  3510. micc := &models.MedicalInsuranceCostCompare{
  3511. StartTime: startime.Unix(),
  3512. EndTime: endtime.Unix(),
  3513. Insutype: "0",
  3514. CheckType: 2,
  3515. Num: fixmedins_setl_cnt,
  3516. Mtime: time.Now().Unix(),
  3517. Status: 1,
  3518. UserOrgId: adminUser.CurrentOrgId,
  3519. CostTotal: medfee_sumamt,
  3520. FuncTotal: fund_pay_sumamt,
  3521. PsnPay: psn_cash_pay,
  3522. Creator: admin_user_id,
  3523. Ctime: time.Now().Unix(),
  3524. }
  3525. service.CreateMedicalInsuranceCostCompareRecord(micc)
  3526. c.ServeSuccessJSON(map[string]interface{}{
  3527. "msg": "明细对账成功",
  3528. })
  3529. }
  3530. } else {
  3531. }
  3532. }
  3533. }
  3534. func (c *HisApiController) GetSettleAccounts() {
  3535. //id, _ := c.GetInt64("id")
  3536. //record_time := c.GetString("record_time")
  3537. order_id, _ := c.GetInt64("order_id")
  3538. admin_user_id, _ := c.GetInt64("admin_user_id")
  3539. //timeLayout := "2006-01-02"
  3540. //loc, _ := time.LoadLocation("Local")
  3541. //
  3542. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3543. //if err != nil {
  3544. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3545. // return
  3546. //}
  3547. //recordDateTime := theTime.Unix()
  3548. adminUser := c.GetAdminUserInfo()
  3549. order, _ := service.GetHisOrderByID(order_id)
  3550. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  3551. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  3552. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  3553. orderInfos = append(orderInfos, orderInfos_two...)
  3554. diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  3555. var bedCostTotal float64 = 0 //床位总费
  3556. var bedCostSelfTotal float64 = 0 //床位自费
  3557. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  3558. var operationCostTotal float64 = 0 //手术费
  3559. var operationCostSelfTotal float64 = 0 //手术费
  3560. var operationCostPartSelfTotal float64 = 0 //手术费
  3561. var otherCostTotal float64 = 0 //其他费用
  3562. var otherCostSelfTotal float64 = 0 //其他费用
  3563. var otherCostPartSelfTotal float64 = 0 //其他费用
  3564. var materialCostTotal float64 = 0 //材料费
  3565. var materialCostSelfTotal float64 = 0 //材料费
  3566. var materialCostPartSelfTotal float64 = 0 //材料费
  3567. var westernMedicineCostTotal float64 = 0 //西药费
  3568. var westernMedicineCostSelfTotal float64 = 0 //西药费
  3569. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  3570. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  3571. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  3572. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  3573. var checkCostTotal float64 = 0 //检查费
  3574. var checkCostSelfTotal float64 = 0 //检查费
  3575. var checkCostPartSelfTotal float64 = 0 //检查费
  3576. var laboratoryCostTotal float64 = 0 //化验费
  3577. var laboratoryCostSelfTotal float64 = 0 //化验费
  3578. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  3579. var treatCostTotal float64 = 0 //治疗费用
  3580. var treatCostSelfTotal float64 = 0 //治疗费用
  3581. var treatCostPartSelfTotal float64 = 0 //治疗费用
  3582. decimal.DivisionPrecision = 2
  3583. for _, item := range orderInfos {
  3584. if item.MedChrgitmType == "01" { //床位费
  3585. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3586. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3587. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3588. }
  3589. if item.MedChrgitmType == "03" { //检查费
  3590. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3591. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3592. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3593. }
  3594. if item.MedChrgitmType == "04" { //化验费
  3595. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3596. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3597. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3598. }
  3599. if item.MedChrgitmType == "05" { //治疗费
  3600. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3601. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3602. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3603. }
  3604. if item.MedChrgitmType == "06" { //手术费
  3605. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3606. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3607. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3608. }
  3609. if item.MedChrgitmType == "08" { //材料费
  3610. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3611. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3612. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3613. }
  3614. if item.MedChrgitmType == "09" { //西药费
  3615. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3616. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3617. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3618. }
  3619. if item.MedChrgitmType == "11" { //中成费
  3620. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3621. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3622. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3623. }
  3624. if item.MedChrgitmType == "14" { //其他费
  3625. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3626. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3627. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3628. }
  3629. }
  3630. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3631. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3632. var user_name string
  3633. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3634. if role.ID == 0 {
  3635. user_name = "管理员"
  3636. } else {
  3637. user_name = role.UserName
  3638. }
  3639. baseParams := models.BaseParams{
  3640. SecretKey: miConfig.SecretKey,
  3641. FixmedinsCode: miConfig.Code,
  3642. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3643. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3644. OrgName: miConfig.OrgName,
  3645. Doctor: user_name,
  3646. }
  3647. businessParams := models.BusinessParams{
  3648. PsnNo: order.PsnNo,
  3649. MdtrtId: order.MdtrtId,
  3650. SetlId: order.SetlId,
  3651. }
  3652. if config.IsOpen == 1 {
  3653. result := service.Gdyb5203(baseParams, businessParams)
  3654. var dat map[string]interface{}
  3655. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3656. fmt.Println(dat)
  3657. } else {
  3658. fmt.Println(err)
  3659. }
  3660. userJSONBytes, _ := json.Marshal(dat)
  3661. var res ResultEleven
  3662. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3663. utils.ErrorLog("解析失败:%v", err)
  3664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3665. return
  3666. }
  3667. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3668. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  3669. if res.Infcode == 0 {
  3670. c.ServeSuccessJSON(map[string]interface{}{
  3671. "diagnosis": diagnosisConfig.CountryContentName,
  3672. "order_infos": orderInfos,
  3673. "number": order.MdtrtId,
  3674. "date": order.SettleAccountsDate,
  3675. "charge_admin": charge_admin,
  3676. "printor_admin": printor_admin,
  3677. "info": res.Output.Setlinfo,
  3678. "bedCostTotal": bedCostTotal,
  3679. "bedCostSelfTotal": bedCostSelfTotal,
  3680. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  3681. "operationCostTotal": operationCostTotal,
  3682. "operationCostSelfTotal": operationCostSelfTotal,
  3683. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  3684. "otherCostTotal": otherCostTotal,
  3685. "otherCostSelfTotal": otherCostSelfTotal,
  3686. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  3687. "materialCostTotal": materialCostTotal,
  3688. "materialCostSelfTotal": materialCostSelfTotal,
  3689. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  3690. "westernMedicineCostTotal": westernMedicineCostTotal,
  3691. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  3692. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  3693. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  3694. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  3695. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  3696. "checkCostTotal": checkCostTotal,
  3697. "checkCostSelfTotal": checkCostSelfTotal,
  3698. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  3699. "laboratoryCostTotal": laboratoryCostTotal,
  3700. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  3701. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  3702. "treatCostTotal": treatCostTotal,
  3703. "treatCostSelfTotal": treatCostSelfTotal,
  3704. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  3705. })
  3706. }
  3707. }
  3708. }
  3709. func (c *HisApiController) CheckTreatment() {
  3710. patient_id, _ := c.GetInt64("patient_id", 0)
  3711. record_time := c.GetString("record_time")
  3712. insutype := c.GetString("insutype")
  3713. timeLayout := "2006-01-02"
  3714. loc, _ := time.LoadLocation("Local")
  3715. adminUser := c.GetAdminUserInfo()
  3716. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3717. fmt.Println(err)
  3718. if err != nil {
  3719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3720. return
  3721. }
  3722. recordDateTime := theTime.Unix()
  3723. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3724. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3725. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3726. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3727. var user_name string
  3728. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  3729. if role.ID == 0 {
  3730. user_name = "xxx"
  3731. } else {
  3732. user_name = role.UserName
  3733. }
  3734. baseParams := models.BaseParams{
  3735. SecretKey: miConfig.SecretKey,
  3736. FixmedinsCode: miConfig.Code,
  3737. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3738. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3739. OrgName: miConfig.OrgName,
  3740. Doctor: user_name,
  3741. }
  3742. if config.IsOpen == 1 {
  3743. result := service.Gdyb2001(baseParams, his.PsnNo, insutype, strconv.FormatInt(patientPrescription.RegisterType, 10))
  3744. var dat map[string]interface{}
  3745. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3746. fmt.Println(dat)
  3747. } else {
  3748. fmt.Println(err)
  3749. }
  3750. }
  3751. }
  3752. func (c *HisApiController) PutRecord() {
  3753. id, _ := c.GetInt64("id")
  3754. record_time := c.GetString("record_time")
  3755. timeLayout := "2006-01-02"
  3756. loc, _ := time.LoadLocation("Local")
  3757. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3758. if err != nil {
  3759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3760. return
  3761. }
  3762. recordDateTime := theTime.Unix()
  3763. adminInfo := c.GetAdminUserInfo()
  3764. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  3765. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3766. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  3767. fmt.Println(miConfig.SecretKey)
  3768. if patient == nil {
  3769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3770. return
  3771. }
  3772. if len(patient.IdCardNo) == 0 {
  3773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  3774. return
  3775. }
  3776. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  3777. if config.IsOpen == 1 {
  3778. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3779. resp, requestErr := http.Get(api)
  3780. if requestErr != nil {
  3781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3782. return
  3783. }
  3784. defer resp.Body.Close()
  3785. body, ioErr := ioutil.ReadAll(resp.Body)
  3786. if ioErr != nil {
  3787. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3789. return
  3790. }
  3791. var respJSON map[string]interface{}
  3792. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3793. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3795. return
  3796. }
  3797. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3798. userJSONBytes, _ := json.Marshal(userJSON)
  3799. var res ResultTwo
  3800. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3801. utils.ErrorLog("解析失败:%v", err)
  3802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3803. return
  3804. }
  3805. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  3806. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  3807. infoStr := string(Iinfos)
  3808. idetinfoStr := string(Idetinfos)
  3809. if res.Infcode == 0 {
  3810. his := models.VMHisPatient{
  3811. Status: 1,
  3812. Ctime: time.Now().Unix(),
  3813. Mtime: time.Now().Unix(),
  3814. PsnNo: res.Output.Baseinfo.PsnNo,
  3815. PsnCertType: res.Output.Baseinfo.PsnCertType,
  3816. Certno: res.Output.Baseinfo.Certno,
  3817. PsnName: res.Output.Baseinfo.PsnName,
  3818. Gend: res.Output.Baseinfo.Gend,
  3819. Naty: res.Output.Baseinfo.Naty,
  3820. Brdy: res.Output.Baseinfo.Brdy,
  3821. Age: res.Output.Baseinfo.Age,
  3822. Iinfo: infoStr,
  3823. Idetinfo: idetinfoStr,
  3824. PatientId: patient.ID,
  3825. RecordDate: theTime.Unix(),
  3826. UserOrgId: adminInfo.CurrentOrgId,
  3827. AdminUserId: adminInfo.AdminUser.Id,
  3828. IsReturn: 1,
  3829. }
  3830. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  3831. result := service.Gdyb2503(his.PsnNo, res.Output.Iinfo[0].Insutype, miConfig.OrgName, patientPrescription.Doctor, miConfig.Code, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "重症尿毒症透析(血透)", "M07801")
  3832. result2 := service.Gdyb5301(his.PsnNo, res.Output.Iinfo[0].Insutype, miConfig.OrgName, patientPrescription.Doctor, miConfig.Code, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "重症尿毒症透析(血透)", "M07801")
  3833. var dat map[string]interface{}
  3834. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3835. fmt.Println(dat)
  3836. } else {
  3837. fmt.Println(err)
  3838. }
  3839. var dat2 map[string]interface{}
  3840. if err := json.Unmarshal([]byte(result2), &dat2); err == nil {
  3841. fmt.Println(dat2)
  3842. } else {
  3843. fmt.Println(err)
  3844. }
  3845. } else {
  3846. adminUser := c.GetAdminUserInfo()
  3847. errlog := &models.HisOrderError{
  3848. UserOrgId: adminUser.CurrentOrgId,
  3849. Ctime: time.Now().Unix(),
  3850. Mtime: time.Now().Unix(),
  3851. ErrMsg: res.ErrMsg,
  3852. Status: 1,
  3853. PatientId: id,
  3854. RecordTime: recordDateTime,
  3855. Stage: 1,
  3856. }
  3857. service.CreateErrMsgLog(errlog)
  3858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  3859. return
  3860. }
  3861. }
  3862. }
  3863. func (c *HisApiController) GetUploadDiag() {
  3864. id, _ := c.GetInt64("id")
  3865. record_time := c.GetString("record_time")
  3866. diagnosis_id, _ := c.GetInt64("diagnosis")
  3867. sick_type, _ := c.GetInt64("sick_type")
  3868. reg_type, _ := c.GetInt64("reg_type")
  3869. timeLayout := "2006-01-02"
  3870. loc, _ := time.LoadLocation("Local")
  3871. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3872. if err != nil {
  3873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3874. return
  3875. }
  3876. var patientPrescription models.HisPrescriptionInfo
  3877. recordDateTime := theTime.Unix()
  3878. adminInfo := c.GetAdminUserInfo()
  3879. patientPrescription, _ = service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3880. if patientPrescription.ID == 0 {
  3881. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3882. }
  3883. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  3884. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  3885. his, _ := service.GetVMHisPatientInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3886. sickConfig, _ := service.FindSickById(sick_type)
  3887. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  3888. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  3889. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  3890. "&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + strconv.FormatInt(reg_type, 10) + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code + "&diag_code=" + diagnosisConfig.CountryCode +
  3891. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  3892. resp2, requestErr2 := http.Get(api2)
  3893. if requestErr2 != nil {
  3894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3895. return
  3896. }
  3897. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  3898. if ioErr2 != nil {
  3899. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  3900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3901. return
  3902. }
  3903. var respJSON2 map[string]interface{}
  3904. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  3905. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3907. return
  3908. }
  3909. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3910. userJSONBytes2, _ := json.Marshal(respJSON2)
  3911. var res2 ResultSix
  3912. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  3913. utils.ErrorLog("解析失败:%v", err)
  3914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3915. return
  3916. }
  3917. if res2.Infcode == -1 {
  3918. adminUser := c.GetAdminUserInfo()
  3919. errlog := &models.HisOrderError{
  3920. UserOrgId: adminUser.CurrentOrgId,
  3921. Ctime: time.Now().Unix(),
  3922. Mtime: time.Now().Unix(),
  3923. ErrMsg: res2.ErrMsg,
  3924. Status: 1,
  3925. PatientId: id,
  3926. RecordTime: recordDateTime,
  3927. Stage: 3,
  3928. }
  3929. service.CreateErrMsgLog(errlog)
  3930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  3931. return
  3932. }
  3933. c.ServeSuccessJSON(map[string]interface{}{
  3934. "msg": "上传成功",
  3935. })
  3936. }
  3937. type QueryResult struct {
  3938. ID int64
  3939. Name string
  3940. Code string
  3941. List_type_code string
  3942. }
  3943. func (c *HisApiController) GetCheckCode() {
  3944. ids_str := c.GetString("ids")
  3945. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  3946. ids_arr := strings.Split(ids_str, ",")
  3947. var queryResult []QueryResult
  3948. ids := make([]int64, 0)
  3949. for _, item := range ids_arr {
  3950. id, _ := strconv.ParseInt(item, 10, 64)
  3951. ids = append(ids, id)
  3952. }
  3953. if record_type == 1 {
  3954. drugs, _ := service.GetBatchDrugList(ids)
  3955. for _, item := range drugs {
  3956. result := QueryResult{
  3957. ID: item.ID,
  3958. Name: item.DrugName,
  3959. Code: item.MedicalInsuranceNumber,
  3960. List_type_code: "101",
  3961. }
  3962. queryResult = append(queryResult, result)
  3963. }
  3964. } else if record_type == 2 {
  3965. goods, _ := service.GetBatchGoodInformationList(ids)
  3966. for _, item := range goods {
  3967. result := QueryResult{
  3968. ID: item.ID,
  3969. Name: item.GoodName,
  3970. Code: item.MedicalInsuranceNumber,
  3971. List_type_code: "301",
  3972. }
  3973. queryResult = append(queryResult, result)
  3974. }
  3975. } else if record_type == 3 {
  3976. projects, _ := service.GetBathchMyPorjecgList(ids)
  3977. for _, item := range projects {
  3978. result := QueryResult{
  3979. ID: item.ID,
  3980. Name: item.ProjectName,
  3981. Code: item.MedicalCode,
  3982. List_type_code: "201",
  3983. }
  3984. queryResult = append(queryResult, result)
  3985. }
  3986. }
  3987. admin_user_id, _ := c.GetInt64("admin_user_id")
  3988. adminUser := c.GetAdminUserInfo()
  3989. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3990. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3991. var user_name string
  3992. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3993. if role.ID == 0 {
  3994. user_name = "xxx"
  3995. } else {
  3996. user_name = role.UserName
  3997. }
  3998. baseParams := &models.BaseParams{
  3999. SecretKey: miConfig.SecretKey,
  4000. FixmedinsCode: miConfig.Code,
  4001. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4002. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4003. OrgName: miConfig.OrgName,
  4004. Doctor: user_name,
  4005. }
  4006. if config.IsOpen == 1 {
  4007. for _, item := range queryResult {
  4008. var result string
  4009. if record_type == 1 {
  4010. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  4011. } else if record_type == 2 {
  4012. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  4013. } else if record_type == 3 {
  4014. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  4015. }
  4016. var dat map[string]interface{}
  4017. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4018. fmt.Println(dat)
  4019. } else {
  4020. fmt.Println(err)
  4021. }
  4022. userJSONBytes, _ := json.Marshal(dat)
  4023. var res ResultSix
  4024. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4025. utils.ErrorLog("解析失败:%v", err)
  4026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4027. return
  4028. }
  4029. if res.Infcode == 0 {
  4030. if record_type == 1 {
  4031. service.UpdateBaseDrugById(item.ID)
  4032. } else if record_type == 2 {
  4033. service.UpdateGoodInformaitonByDetail(item.ID)
  4034. } else if record_type == 3 {
  4035. service.UpdateProjectById(item.ID)
  4036. }
  4037. c.ServeSuccessJSON(map[string]interface{}{
  4038. "failed_code": 0,
  4039. "msg": "目录对照成功",
  4040. })
  4041. } else {
  4042. c.ServeSuccessJSON(map[string]interface{}{
  4043. "failed_code": -10,
  4044. "msg": res.ErrMsg,
  4045. })
  4046. }
  4047. }
  4048. }
  4049. }
  4050. func (c *HisApiController) UnCheckCode() {
  4051. ids_str := c.GetString("ids")
  4052. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  4053. admin_user_id, _ := c.GetInt64("admin_user_id")
  4054. ids_arr := strings.Split(ids_str, ",")
  4055. var queryResult []QueryResult
  4056. ids := make([]int64, 0)
  4057. for _, item := range ids_arr {
  4058. id, _ := strconv.ParseInt(item, 10, 64)
  4059. ids = append(ids, id)
  4060. }
  4061. if record_type == 1 {
  4062. drugs, _ := service.GetBatchDrugList(ids)
  4063. for _, item := range drugs {
  4064. result := QueryResult{
  4065. ID: item.ID,
  4066. Name: item.DrugName,
  4067. Code: item.MedicalInsuranceNumber,
  4068. List_type_code: "101",
  4069. }
  4070. queryResult = append(queryResult, result)
  4071. }
  4072. } else if record_type == 2 {
  4073. goods, _ := service.GetBatchGoodInformationList(ids)
  4074. for _, item := range goods {
  4075. result := QueryResult{
  4076. ID: item.ID,
  4077. Name: item.GoodName,
  4078. Code: item.MedicalInsuranceNumber,
  4079. List_type_code: "301",
  4080. }
  4081. queryResult = append(queryResult, result)
  4082. }
  4083. } else if record_type == 3 {
  4084. projects, _ := service.GetBathchMyPorjecgList(ids)
  4085. for _, item := range projects {
  4086. result := QueryResult{
  4087. ID: item.ID,
  4088. Name: item.ProjectName,
  4089. Code: item.MedicalCode,
  4090. List_type_code: "201",
  4091. }
  4092. queryResult = append(queryResult, result)
  4093. }
  4094. }
  4095. adminUser := c.GetAdminUserInfo()
  4096. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4097. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4098. var user_name string
  4099. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4100. if role.ID == 0 {
  4101. user_name = "xxx"
  4102. } else {
  4103. user_name = role.UserName
  4104. }
  4105. baseParams := &models.BaseParams{
  4106. SecretKey: miConfig.SecretKey,
  4107. FixmedinsCode: miConfig.Code,
  4108. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4109. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4110. OrgName: miConfig.OrgName,
  4111. Doctor: user_name,
  4112. }
  4113. if config.IsOpen == 1 {
  4114. for _, item := range queryResult {
  4115. var result string
  4116. if record_type == 1 {
  4117. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  4118. } else if record_type == 2 {
  4119. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  4120. } else if record_type == 3 {
  4121. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  4122. }
  4123. var dat2 map[string]interface{}
  4124. if err := json.Unmarshal([]byte(result), &dat2); err == nil {
  4125. fmt.Println(dat2)
  4126. } else {
  4127. fmt.Println(err)
  4128. }
  4129. userJSONBytes, _ := json.Marshal(dat2)
  4130. var res ResultSix
  4131. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4132. utils.ErrorLog("解析失败:%v", err)
  4133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4134. return
  4135. }
  4136. if res.Infcode == 0 {
  4137. if record_type == 1 {
  4138. service.UpdateDrugByIdDetail(item.ID)
  4139. } else if record_type == 2 {
  4140. service.UpdateGoodInfoById(item.ID)
  4141. } else if record_type == 3 {
  4142. service.UpdateMyProjectById(item.ID)
  4143. }
  4144. c.ServeSuccessJSON(map[string]interface{}{
  4145. "failed_code": 0,
  4146. "msg": "撤销目录对照成功",
  4147. })
  4148. } else {
  4149. c.ServeSuccessJSON(map[string]interface{}{
  4150. "failed_code": -10,
  4151. "msg": res.ErrMsg,
  4152. })
  4153. }
  4154. }
  4155. }
  4156. }
  4157. func (c *HisApiController) GetPatientInfo() {
  4158. id_card_no := c.GetString("id_card_no")
  4159. admin_user_id, _ := c.GetInt64("admin_user_id")
  4160. patient, _ := service.GetPatientByIDCard(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  4161. if patient.ID == 0 {
  4162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4163. return
  4164. }
  4165. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  4166. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  4167. config, _ := service.GetMedicalInsuranceConfig(c.GetAdminUserInfo().CurrentOrgId)
  4168. if config.IsOpen == 1 {
  4169. result := service.Gdyb1101A(id_card_no, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  4170. var dat map[string]interface{}
  4171. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4172. fmt.Println(dat)
  4173. } else {
  4174. fmt.Println(err)
  4175. }
  4176. userJSONBytes, _ := json.Marshal(dat)
  4177. var res ResultTwo
  4178. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4179. utils.ErrorLog("解析失败:%v", err)
  4180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4181. return
  4182. }
  4183. if res.Infcode == -1 {
  4184. c.ServeSuccessJSON(map[string]interface{}{
  4185. "failed_code": -10,
  4186. "msg": res.ErrMsg,
  4187. })
  4188. } else {
  4189. c.ServeSuccessJSON(map[string]interface{}{
  4190. "failed_code": 0,
  4191. "info": res,
  4192. })
  4193. }
  4194. }
  4195. }
  4196. func (c *HisApiController) PsnPutOnRecord() {
  4197. record_type, _ := c.GetInt64("type")
  4198. patient_id, _ := c.GetInt64("patient_id")
  4199. admin_user_id, _ := c.GetInt64("admin_user_id")
  4200. start_time := c.GetString("start_time")
  4201. end_time := c.GetString("end_time")
  4202. adminUser := c.GetAdminUserInfo()
  4203. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4204. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4205. var patients []*models.Patients
  4206. if record_type == 1 { //全部备案
  4207. patient, _ := service.GetAllPatient(adminUser.CurrentOrgId)
  4208. patients = append(patients, patient...)
  4209. } else { //单个备案
  4210. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  4211. patients = append(patients, patient)
  4212. }
  4213. var user_name string
  4214. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4215. if role.ID == 0 {
  4216. user_name = "xxx"
  4217. } else {
  4218. user_name = role.UserName
  4219. }
  4220. if config.IsOpen == 1 {
  4221. for _, item := range patients {
  4222. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + item.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + user_name + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4223. resp, requestErr := http.Get(api)
  4224. if requestErr != nil {
  4225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4226. return
  4227. }
  4228. defer resp.Body.Close()
  4229. body, ioErr := ioutil.ReadAll(resp.Body)
  4230. if ioErr != nil {
  4231. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4233. return
  4234. }
  4235. var respJSON map[string]interface{}
  4236. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4237. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4239. return
  4240. }
  4241. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4242. userJSONBytes, _ := json.Marshal(userJSON)
  4243. var res ResultTwo
  4244. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4245. utils.ErrorLog("解析失败:%v", err)
  4246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4247. return
  4248. }
  4249. if res.Infcode == 0 {
  4250. result := service.Gdyb2505(res.Output.Baseinfo.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, start_time, end_time)
  4251. var dat map[string]interface{}
  4252. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4253. fmt.Println(dat)
  4254. } else {
  4255. fmt.Println(err)
  4256. }
  4257. userJSONBytes, _ := json.Marshal(dat)
  4258. var res2 ResultThirteen
  4259. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  4260. utils.ErrorLog("解析失败:%v", err)
  4261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4262. return
  4263. }
  4264. if res2.Infcode == 0 {
  4265. psnResult := &models.GdybPsnRecord{
  4266. UserOrgId: adminUser.CurrentOrgId,
  4267. PatientId: item.ID,
  4268. PsnNo: res.Output.Baseinfo.PsnNo,
  4269. Ctime: time.Now().Unix(),
  4270. Mtime: time.Now().Unix(),
  4271. Status: 1,
  4272. IsCancel: 1,
  4273. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  4274. }
  4275. service.CreatePsnRecord(psnResult)
  4276. } else {
  4277. c.ServeSuccessJSON(map[string]interface{}{
  4278. "failed_code": -10,
  4279. "msg": res2.ErrMsg,
  4280. })
  4281. return
  4282. }
  4283. }
  4284. }
  4285. }
  4286. }
  4287. func (c *HisApiController) PsnUnPutOnRecord() {
  4288. id, _ := c.GetInt64("id")
  4289. //record_type, _ := c.GetInt64("type")
  4290. admin_user_id, _ := c.GetInt64("admin_user_id")
  4291. adminUser := c.GetAdminUserInfo()
  4292. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4293. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4294. var user_name string
  4295. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4296. if role.ID == 0 {
  4297. user_name = "xxx"
  4298. } else {
  4299. user_name = role.UserName
  4300. }
  4301. psn_record, _ := service.GetPsnRecordById(id)
  4302. if psn_record.ID == 0 {
  4303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  4304. return
  4305. }
  4306. if config.IsOpen == 1 {
  4307. result := service.Gdyb2506(psn_record.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  4308. var dat map[string]interface{}
  4309. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4310. fmt.Println(dat)
  4311. } else {
  4312. fmt.Println(err)
  4313. }
  4314. userJSONBytes, _ := json.Marshal(dat)
  4315. var res ResultFourteen
  4316. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4317. utils.ErrorLog("解析失败:%v", err)
  4318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4319. return
  4320. }
  4321. if res.Infcode == 0 {
  4322. psn_record.IsCancel = 2
  4323. service.CreatePsnRecord(&psn_record)
  4324. } else {
  4325. c.ServeSuccessJSON(map[string]interface{}{
  4326. "failed_code": -10,
  4327. "msg": res.ErrMsg,
  4328. })
  4329. return
  4330. }
  4331. }
  4332. }
  4333. func (c *HisApiController) PsnPutNCDSOnRecord() {
  4334. patient_id, _ := c.GetInt64("patient_id")
  4335. insutype := c.GetString("insutype")
  4336. psn_no := c.GetString("psn_no")
  4337. doctor_id, _ := c.GetInt64("doctor_id")
  4338. sick_id, _ := c.GetInt64("sick_id")
  4339. department_id, _ := c.GetInt64("department_id")
  4340. adminUser := c.GetAdminUserInfo()
  4341. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  4342. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4343. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4344. sick, _ := service.FindSickById(sick_id)
  4345. doctor, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, doctor_id)
  4346. if config.IsOpen == 1 {
  4347. result := service.Gdyb2503(psn_no, insutype, miConfig.OrgName, doctor.UserName, miConfig.Code, strconv.FormatInt(doctor.ID, 10), miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sick.ClassName, sick.CountryCode)
  4348. var dat map[string]interface{}
  4349. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4350. fmt.Println(dat)
  4351. } else {
  4352. fmt.Println(err)
  4353. }
  4354. userJSONBytes, _ := json.Marshal(dat)
  4355. var res2 ResultThirteen
  4356. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  4357. utils.ErrorLog("解析失败:%v", err)
  4358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4359. return
  4360. }
  4361. if res2.Infcode == 0 {
  4362. psnResult := &models.GdybPsnNcdsRecord{
  4363. UserOrgId: adminUser.CurrentOrgId,
  4364. PatientId: patient.ID,
  4365. PsnNo: psn_no,
  4366. DoctorId: doctor.AdminUserId,
  4367. DepartmentId: department_id,
  4368. SickType: sick_id,
  4369. Insutype: insutype,
  4370. Ctime: time.Now().Unix(),
  4371. Mtime: time.Now().Unix(),
  4372. Status: 1,
  4373. IsCancel: 1,
  4374. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  4375. }
  4376. service.CreatePsnNCDSRecord(psnResult)
  4377. c.ServeSuccessJSON(map[string]interface{}{
  4378. "failed_code": 0,
  4379. "msg": "备案成功",
  4380. "result": psnResult,
  4381. })
  4382. } else {
  4383. c.ServeSuccessJSON(map[string]interface{}{
  4384. "failed_code": -10,
  4385. "msg": res2.ErrMsg,
  4386. })
  4387. return
  4388. }
  4389. }
  4390. }
  4391. func (c *HisApiController) PsnPutUnNCDSOnRecord() {
  4392. id, _ := c.GetInt64("id")
  4393. admin_user_id, _ := c.GetInt64("admin_user_id")
  4394. adminUser := c.GetAdminUserInfo()
  4395. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4396. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4397. var user_name string
  4398. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4399. if role.ID == 0 {
  4400. user_name = "xxx"
  4401. } else {
  4402. user_name = role.UserName
  4403. }
  4404. psn_record, _ := service.GetPsnNCDSRecordById(id)
  4405. if psn_record.ID == 0 {
  4406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  4407. return
  4408. }
  4409. if config.IsOpen == 1 {
  4410. result := service.Gdyb2504(psn_record.PsnNo, miConfig.OrgName, user_name, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  4411. var dat map[string]interface{}
  4412. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4413. fmt.Println(dat)
  4414. } else {
  4415. fmt.Println(err)
  4416. }
  4417. userJSONBytes, _ := json.Marshal(dat)
  4418. var res ResultFourteen
  4419. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4420. utils.ErrorLog("解析失败:%v", err)
  4421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4422. return
  4423. }
  4424. if res.Infcode == 0 {
  4425. psn_record.IsCancel = 2
  4426. service.CreatePsnNCDSRecord(&psn_record)
  4427. c.ServeSuccessJSON(map[string]interface{}{
  4428. "failed_code": 0,
  4429. "msg": "撤销备案成功",
  4430. })
  4431. } else {
  4432. c.ServeSuccessJSON(map[string]interface{}{
  4433. "failed_code": -10,
  4434. "msg": res.ErrMsg,
  4435. })
  4436. return
  4437. }
  4438. }
  4439. }
  4440. func (c *HisApiController) TestTest() {
  4441. patient, _ := service.GetHisPatientInfo(4, 456, 1619712000)
  4442. fmt.Println(patient.Iinfo)
  4443. }
  4444. type CustomData struct {
  4445. MsgId string
  4446. PsnNo string
  4447. Info string
  4448. }
  4449. func (c *HisApiController) ReversalData() {
  4450. var customData []*CustomData
  4451. custom := &CustomData{
  4452. MsgId: "H44022900158202103301714472004",
  4453. PsnNo: "44020000001101329945",
  4454. Info: "2207",
  4455. }
  4456. customData = append(customData, custom)
  4457. custom1 := &CustomData{
  4458. MsgId: "H4402290015820210330172057803",
  4459. PsnNo: "44020000001101161813",
  4460. Info: "2207",
  4461. }
  4462. customData = append(customData, custom1)
  4463. custom2 := &CustomData{
  4464. MsgId: "H44022900158202103301705198813",
  4465. PsnNo: "44190000133097375417",
  4466. Info: "2207",
  4467. }
  4468. customData = append(customData, custom2)
  4469. custom3 := &CustomData{
  4470. MsgId: "H44022900158202103301715524756",
  4471. PsnNo: "44020000001100187221",
  4472. Info: "2207",
  4473. }
  4474. customData = append(customData, custom3)
  4475. custom4 := &CustomData{
  4476. MsgId: "H44022900158202103301730376224",
  4477. PsnNo: "44020000001101959155",
  4478. Info: "2207",
  4479. }
  4480. customData = append(customData, custom4)
  4481. custom5 := &CustomData{
  4482. MsgId: "H44022900158202103301748008725",
  4483. PsnNo: "44020000001104246641",
  4484. Info: "2207",
  4485. }
  4486. customData = append(customData, custom5)
  4487. custom6 := &CustomData{
  4488. MsgId: "H44022900158202103301718096755",
  4489. PsnNo: "44020000001102211860",
  4490. Info: "2207",
  4491. }
  4492. customData = append(customData, custom6)
  4493. custom7 := &CustomData{
  4494. MsgId: "H44022900158202103301736551640",
  4495. PsnNo: "44020000001102687718",
  4496. Info: "2207",
  4497. }
  4498. customData = append(customData, custom7)
  4499. custom8 := &CustomData{
  4500. MsgId: "H44022900158202103301743097676",
  4501. PsnNo: "44020000001102127785",
  4502. Info: "2207",
  4503. }
  4504. customData = append(customData, custom8)
  4505. custom9 := &CustomData{
  4506. MsgId: "H44022900158202103301712304203",
  4507. PsnNo: "44020000001101518097",
  4508. Info: "2207",
  4509. }
  4510. customData = append(customData, custom9)
  4511. custom10 := &CustomData{
  4512. MsgId: "H44022900158202103301738448785",
  4513. PsnNo: "44020000001100500813",
  4514. Info: "2207",
  4515. }
  4516. customData = append(customData, custom10)
  4517. custom11 := &CustomData{
  4518. MsgId: "H44022900158202103301732455843",
  4519. PsnNo: "44020000001102690557",
  4520. Info: "2207",
  4521. }
  4522. customData = append(customData, custom11)
  4523. custom12 := &CustomData{
  4524. MsgId: "H44022900158202103301745421708",
  4525. PsnNo: "44020000001102211928",
  4526. Info: "2207",
  4527. }
  4528. customData = append(customData, custom12)
  4529. custom1212 := &CustomData{
  4530. MsgId: "H440229001582021033017351627",
  4531. PsnNo: "44020000001102481733",
  4532. Info: "2207",
  4533. }
  4534. customData = append(customData, custom1212)
  4535. custom13 := &CustomData{
  4536. MsgId: "H44022900158202103301740327951",
  4537. PsnNo: "44020000001103174866",
  4538. Info: "2207",
  4539. }
  4540. customData = append(customData, custom13)
  4541. custom14 := &CustomData{
  4542. MsgId: "H4402290015820210330174922668",
  4543. PsnNo: "44020000001102927272",
  4544. Info: "2207",
  4545. }
  4546. customData = append(customData, custom14)
  4547. custom15 := &CustomData{
  4548. MsgId: "H44022900158202103301752362273",
  4549. PsnNo: "44020000001102942890",
  4550. Info: "2207",
  4551. }
  4552. customData = append(customData, custom15)
  4553. custom16 := &CustomData{
  4554. MsgId: "H44022900158202103301751082917",
  4555. PsnNo: "44020000001101662162",
  4556. Info: "2207",
  4557. }
  4558. customData = append(customData, custom16)
  4559. custom17 := &CustomData{
  4560. MsgId: "H44022900158202103301754147728",
  4561. PsnNo: "44020000000229014511",
  4562. Info: "2207",
  4563. }
  4564. customData = append(customData, custom17)
  4565. adminUser := c.GetAdminUserInfo()
  4566. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4567. for _, item := range customData {
  4568. result := service.Gdyb2601(item.PsnNo, item.MsgId, item.Info, miConfig.OrgName, "张俊杰", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  4569. fmt.Println(result)
  4570. }
  4571. }
  4572. func (c *HisApiController) ReversalOtherData() {
  4573. var customData []*CustomData
  4574. custom := &CustomData{
  4575. MsgId: "H44022900158202103301714472004",
  4576. PsnNo: "44020000001101329945",
  4577. Info: "2208",
  4578. }
  4579. customData = append(customData, custom)
  4580. custom1 := &CustomData{
  4581. MsgId: "H4402290015820210330172057803",
  4582. PsnNo: "44020000001101161813",
  4583. Info: "2208",
  4584. }
  4585. customData = append(customData, custom1)
  4586. custom2 := &CustomData{
  4587. MsgId: "H44022900158202103301705198813",
  4588. PsnNo: "44190000133097375417",
  4589. Info: "2208",
  4590. }
  4591. customData = append(customData, custom2)
  4592. custom3 := &CustomData{
  4593. MsgId: "H44022900158202103301715524756",
  4594. PsnNo: "44020000001100187221",
  4595. Info: "2208",
  4596. }
  4597. customData = append(customData, custom3)
  4598. custom4 := &CustomData{
  4599. MsgId: "H44022900158202103301730376224",
  4600. PsnNo: "44020000001101959155",
  4601. Info: "2208",
  4602. }
  4603. customData = append(customData, custom4)
  4604. custom5 := &CustomData{
  4605. MsgId: "H44022900158202103301748008725",
  4606. PsnNo: "44020000001104246641",
  4607. Info: "2208",
  4608. }
  4609. customData = append(customData, custom5)
  4610. custom6 := &CustomData{
  4611. MsgId: "H44022900158202103301718096755",
  4612. PsnNo: "44020000001102211860",
  4613. Info: "2208",
  4614. }
  4615. customData = append(customData, custom6)
  4616. custom7 := &CustomData{
  4617. MsgId: "H44022900158202103301736551640",
  4618. PsnNo: "44020000001102687718",
  4619. Info: "2208",
  4620. }
  4621. customData = append(customData, custom7)
  4622. custom8 := &CustomData{
  4623. MsgId: "H44022900158202103301743097676",
  4624. PsnNo: "44020000001102127785",
  4625. Info: "2208",
  4626. }
  4627. customData = append(customData, custom8)
  4628. custom9 := &CustomData{
  4629. MsgId: "H44022900158202103301712304203",
  4630. PsnNo: "44020000001101518097",
  4631. Info: "2208",
  4632. }
  4633. customData = append(customData, custom9)
  4634. custom10 := &CustomData{
  4635. MsgId: "H44022900158202103301738448785",
  4636. PsnNo: "44020000001100500813",
  4637. Info: "2208",
  4638. }
  4639. customData = append(customData, custom10)
  4640. custom11 := &CustomData{
  4641. MsgId: "H44022900158202103301732455843",
  4642. PsnNo: "44020000001102690557",
  4643. Info: "2208",
  4644. }
  4645. customData = append(customData, custom11)
  4646. custom12 := &CustomData{
  4647. MsgId: "H44022900158202103301745421708",
  4648. PsnNo: "44020000001102211928",
  4649. Info: "2208",
  4650. }
  4651. customData = append(customData, custom12)
  4652. custom1212 := &CustomData{
  4653. MsgId: "H440229001582021033017351627",
  4654. PsnNo: "44020000001102481733",
  4655. Info: "2208",
  4656. }
  4657. customData = append(customData, custom1212)
  4658. custom13 := &CustomData{
  4659. MsgId: "H44022900158202103301740327951",
  4660. PsnNo: "44020000001103174866",
  4661. Info: "2208",
  4662. }
  4663. customData = append(customData, custom13)
  4664. custom14 := &CustomData{
  4665. MsgId: "H4402290015820210330174922668",
  4666. PsnNo: "44020000001102927272",
  4667. Info: "2208",
  4668. }
  4669. customData = append(customData, custom14)
  4670. custom15 := &CustomData{
  4671. MsgId: "H44022900158202103301752362273",
  4672. PsnNo: "44020000001102942890",
  4673. Info: "2208",
  4674. }
  4675. customData = append(customData, custom15)
  4676. custom16 := &CustomData{
  4677. MsgId: "H44022900158202103301751082917",
  4678. PsnNo: "44020000001101662162",
  4679. Info: "2208",
  4680. }
  4681. customData = append(customData, custom16)
  4682. custom17 := &CustomData{
  4683. MsgId: "H44022900158202103301754147728",
  4684. PsnNo: "44020000000229014511",
  4685. Info: "2208",
  4686. }
  4687. customData = append(customData, custom17)
  4688. adminUser := c.GetAdminUserInfo()
  4689. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4690. for _, item := range customData {
  4691. result := service.Gdyb2601(item.PsnNo, item.MsgId, item.Info, miConfig.OrgName, "张俊杰", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  4692. fmt.Println(result)
  4693. }
  4694. }
  4695. func PathExists(path string) (bool, error) {
  4696. _, err := os.Stat(path)
  4697. if err == nil {
  4698. return true, nil
  4699. }
  4700. if os.IsNotExist(err) {
  4701. return false, nil
  4702. }
  4703. return false, err
  4704. }
  4705. //创建文件夹
  4706. func Mkdir(dir string) {
  4707. // 创建文件夹
  4708. exist, err := PathExists(dir)
  4709. if err != nil {
  4710. fmt.Println(err.Error())
  4711. } else {
  4712. if exist {
  4713. fmt.Println(dir + "文件夹已存在!")
  4714. } else {
  4715. // 文件夹名称,权限
  4716. err := os.Mkdir(dir, os.ModePerm)
  4717. if err != nil {
  4718. fmt.Println(dir+"文件夹创建失败:", err.Error())
  4719. } else {
  4720. fmt.Println(dir + "文件夹创建成功!")
  4721. }
  4722. }
  4723. }
  4724. }
  4725. //压缩文件
  4726. func Zip(srcFile string, destZip string) error {
  4727. zipfile, err := os.Create(destZip)
  4728. if err != nil {
  4729. return err
  4730. }
  4731. defer zipfile.Close()
  4732. archive := zip.NewWriter(zipfile)
  4733. defer archive.Close()
  4734. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  4735. if err != nil {
  4736. return err
  4737. }
  4738. header, err := zip.FileInfoHeader(info)
  4739. if err != nil {
  4740. return err
  4741. }
  4742. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  4743. // header.Name = path
  4744. if info.IsDir() {
  4745. header.Name += "/"
  4746. } else {
  4747. header.Method = zip.Deflate
  4748. }
  4749. writer, err := archive.CreateHeader(header)
  4750. if err != nil {
  4751. return err
  4752. }
  4753. if !info.IsDir() {
  4754. file, err := os.Open(path)
  4755. if err != nil {
  4756. return err
  4757. }
  4758. defer file.Close()
  4759. _, err = io.Copy(writer, file)
  4760. }
  4761. return err
  4762. })
  4763. return err
  4764. }
  4765. func ReadFile(filePath string) []byte {
  4766. f, err := os.Open(filePath)
  4767. if err != nil {
  4768. fmt.Println("read file fail", err)
  4769. return nil
  4770. }
  4771. defer f.Close()
  4772. fd, err := ioutil.ReadAll(f)
  4773. if err != nil {
  4774. fmt.Println("read to fd fail", err)
  4775. return nil
  4776. }
  4777. return fd
  4778. }
  4779. func RemoveRepeatedCode(arr []string) (newArr []string) {
  4780. newArr = make([]string, 0)
  4781. for i := 0; i < len(arr); i++ {
  4782. repeat := false
  4783. for j := i + 1; j < len(arr); j++ {
  4784. if arr[i] == arr[j] {
  4785. repeat = true
  4786. break
  4787. }
  4788. }
  4789. if !repeat {
  4790. newArr = append(newArr, arr[i])
  4791. }
  4792. }
  4793. return
  4794. }