sz_his_api_controller.go 218KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093
  1. package sz
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "gdyb/controllers"
  6. "gdyb/enums"
  7. "gdyb/models"
  8. "gdyb/service"
  9. "gdyb/utils"
  10. "github.com/astaxie/beego"
  11. "github.com/axgle/mahonia"
  12. "math/rand"
  13. //"github.com/axgle/mahonia"
  14. "math"
  15. //"math/rand"µ
  16. "strconv"
  17. "strings"
  18. //"strings"
  19. "syscall"
  20. "time"
  21. "unsafe"
  22. )
  23. type Result struct {
  24. Transtime string `json:"transTime"`
  25. Transtype string `json:"transType"`
  26. Transreturncode string `json:"transReturnCode"`
  27. Transreturnmessage string `json:"transReturnMessage"`
  28. Transversion string `json:"transVersion"`
  29. Serialnumber string `json:"serialNumber"`
  30. Cardarea string `json:"cardArea"`
  31. Hospitalcode string `json:"hospitalCode"`
  32. Operatorcode string `json:"operatorCode"`
  33. Operatorname string `json:"operatorName"`
  34. Operatorpass string `json:"operatorPass"`
  35. Transbody struct {
  36. Akc190 string `json:"akc190"`
  37. Listsize int `json:"listsize"`
  38. Outputlist []struct {
  39. Aae072 string `json:"aae072"`
  40. Bkc369 string `json:"bkc369"`
  41. Bkf500 string `json:"bkf500"`
  42. Aka111 string `json:"aka111"`
  43. Ake001 string `json:"ake001"`
  44. Ake002 string `json:"ake002"`
  45. Bkm017 string `json:"bkm017"`
  46. Ake005 string `json:"ake005"`
  47. Ake006 string `json:"ake006"`
  48. Akc225 float64 `json:"akc225"`
  49. Akc226 float64 `json:"akc226"`
  50. Akc264 float64 `json:"akc264"`
  51. Aka065 string `json:"aka065"`
  52. Cka319 float64 `json:"cka319"`
  53. Akc268 float64 `json:"akc268"`
  54. } `json:"outputlist"`
  55. } `json:"transBody"`
  56. Verifycode string `json:"verifyCode"`
  57. Extenddeviceid string `json:"extendDeviceId"`
  58. Transchannel string `json:"transChannel"`
  59. Extenduserid string `json:"extendUserId"`
  60. Extendserialnumber string `json:"extendSerialNumber"`
  61. Caz055 string `json:"caz055"`
  62. Aae501 string `json:"aae501"`
  63. }
  64. type ResultOne struct {
  65. Transtime string `json:"transTime"`
  66. Transtype string `json:"transType"`
  67. Transreturncode string `json:"transReturnCode"`
  68. Transreturnmessage string `json:"transReturnMessage"`
  69. Transversion string `json:"transVersion"`
  70. Serialnumber string `json:"serialNumber"`
  71. Cardarea string `json:"cardArea"`
  72. Hospitalcode string `json:"hospitalCode"`
  73. Operatorcode string `json:"operatorCode"`
  74. Operatorname string `json:"operatorName"`
  75. Operatorpass string `json:"operatorPass"`
  76. Transbody struct {
  77. Ckc618 string `json:"ckc618"`
  78. Akc264 float64 `json:"akc264"`
  79. Akb068 int `json:"akb068"`
  80. Akb066 float64 `json:"akb066"`
  81. Akb067 int `json:"akb067"`
  82. Aae240 float64 `json:"aae240"`
  83. Outputlist []struct {
  84. Aaa036 string `json:"aaa036"`
  85. Aae019 float64 `json:"aae019"`
  86. } `json:"outputlist"`
  87. Outputlist2 []interface{} `json:"outputlist2"`
  88. } `json:"transBody"`
  89. Verifycode string `json:"verifyCode"`
  90. Extenddeviceid string `json:"extendDeviceId"`
  91. Transchannel string `json:"transChannel"`
  92. Extenduserid string `json:"extendUserId"`
  93. Extendserialnumber string `json:"extendSerialNumber"`
  94. Caz055 string `json:"caz055"`
  95. Aae501 string `json:"aae501"`
  96. }
  97. type ResultTwo struct {
  98. Transtime string `json:"transTime"`
  99. Transtype string `json:"transType"`
  100. Transreturncode string `json:"transReturnCode"`
  101. Transreturnmessage string `json:"transReturnMessage"`
  102. Transversion string `json:"transVersion"`
  103. Serialnumber string `json:"serialNumber"`
  104. Cardarea string `json:"cardArea"`
  105. Hospitalcode string `json:"hospitalCode"`
  106. Operatorcode string `json:"operatorCode"`
  107. Operatorname string `json:"operatorName"`
  108. Operatorpass string `json:"operatorPass"`
  109. Transbody struct {
  110. Ckc618 string `json:"ckc618"`
  111. Akc264 float64 `json:"akc264"`
  112. Akb068 float64 `json:"akb068"`
  113. Akb066 float64 `json:"akb066"`
  114. Akb067 float64 `json:"akb067"`
  115. Aae240 float64 `json:"aae240"`
  116. Outputlist1 []struct {
  117. Aka111 string `json:"aka111"`
  118. Bka058 float64 `json:"bka058"`
  119. } `json:"outputlist1"`
  120. Outputlist2 []struct {
  121. Aaa036 string `json:"aaa036"`
  122. Aae019 float64 `json:"aae019"`
  123. } `json:"outputlist2"`
  124. Outputlist3 []interface{} `json:"outputlist3"`
  125. } `json:"transBody"`
  126. Verifycode string `json:"verifyCode"`
  127. Extenddeviceid string `json:"extendDeviceId"`
  128. Transchannel string `json:"transChannel"`
  129. Extenduserid string `json:"extendUserId"`
  130. Extendserialnumber string `json:"extendSerialNumber"`
  131. Caz055 string `json:"caz055"`
  132. Aae501 string `json:"aae501"`
  133. }
  134. type ResultThree struct {
  135. Transtime string `json:"transTime"`
  136. Transtype string `json:"transType"`
  137. Transreturncode string `json:"transReturnCode"`
  138. Transreturnmessage string `json:"transReturnMessage"`
  139. Transversion string `json:"transVersion"`
  140. Serialnumber string `json:"serialNumber"`
  141. Cardarea string `json:"cardArea"`
  142. Hospitalcode string `json:"hospitalCode"`
  143. Operatorcode string `json:"operatorCode"`
  144. Operatorname string `json:"operatorName"`
  145. Operatorpass string `json:"operatorPass"`
  146. Transbody struct {
  147. Baz700 string `json:"baz700"`
  148. Ckc618 string `json:"ckc618"`
  149. } `json:"transBody"`
  150. Verifycode string `json:"verifyCode"`
  151. Extenddeviceid string `json:"extendDeviceId"`
  152. Transchannel string `json:"transChannel"`
  153. Extenduserid string `json:"extendUserId"`
  154. Extendserialnumber string `json:"extendSerialNumber"`
  155. Caz055 string `json:"caz055"`
  156. Aae501 string `json:"aae501"`
  157. }
  158. type ResultFive struct {
  159. Transtime string `json:"transTime"`
  160. Transtype string `json:"transType"`
  161. Transreturncode string `json:"transReturnCode"`
  162. Transreturnmessage string `json:"transReturnMessage"`
  163. Transversion string `json:"transVersion"`
  164. Serialnumber string `json:"serialNumber"`
  165. Cardarea string `json:"cardArea"`
  166. Hospitalcode string `json:"hospitalCode"`
  167. Operatorcode string `json:"operatorCode"`
  168. Operatorname string `json:"operatorName"`
  169. Operatorpass string `json:"operatorPass"`
  170. Transbody struct {
  171. Akc190 string `json:"akc190"`
  172. Listsize int `json:"listsize"`
  173. Outputlist []struct {
  174. Aae072 string `json:"aae072"`
  175. Bkf500 string `json:"bkf500"`
  176. Baz700 string `json:"baz700"`
  177. Bce574 string `json:"bce574"`
  178. } `json:"outputlist"`
  179. } `json:"transBody"`
  180. Verifycode string `json:"verifyCode"`
  181. Extenddeviceid string `json:"extendDeviceId"`
  182. Transchannel string `json:"transChannel"`
  183. Extenduserid string `json:"extendUserId"`
  184. Extendserialnumber string `json:"extendSerialNumber"`
  185. Caz055 string `json:"caz055"`
  186. Aae501 string `json:"aae501"`
  187. }
  188. type ResultFour struct {
  189. Transtime string `json:"transTime"`
  190. Transtype string `json:"transType"`
  191. Transreturncode string `json:"transReturnCode"`
  192. Transreturnmessage string `json:"transReturnMessage"`
  193. Transversion string `json:"transVersion"`
  194. Serialnumber string `json:"serialNumber"`
  195. Cardarea string `json:"cardArea"`
  196. Hospitalcode string `json:"hospitalCode"`
  197. Operatorcode string `json:"operatorCode"`
  198. Operatorname string `json:"operatorName"`
  199. Operatorpass string `json:"operatorPass"`
  200. Transbody struct {
  201. Akc190 string `json:"akc190"`
  202. Akc194 int `json:"akc194"`
  203. Bae917 int64 `json:"bae917"`
  204. Aka018 string `json:"aka018"`
  205. Aka030 string `json:"aka030"`
  206. Ckc618 string `json:"ckc618"`
  207. Akc264 float64 `json:"akc264"`
  208. Akb068 float64 `json:"akb068"`
  209. Akb066 float64 `json:"akb066"`
  210. Akb067 float64 `json:"akb067"`
  211. Cke298 float64 `json:"cke298"`
  212. Aae240 float64 `json:"aae240"`
  213. Outputlist1 []struct {
  214. Aae072 string `json:"aae072"`
  215. Bkc369 string `json:"bkc369"`
  216. Bkf500 string `json:"bkf500"`
  217. Aka111 string `json:"aka111"`
  218. Ake001 string `json:"ake001"`
  219. Ake002 string `json:"ake002"`
  220. Bkm017 string `json:"bkm017"`
  221. Ake005 string `json:"ake005"`
  222. Ake006 string `json:"ake006"`
  223. Ala026 string `json:"ala026"`
  224. Aka070 string `json:"aka070"`
  225. Aka074 string `json:"aka074"`
  226. Akc226 float64 `json:"akc226"`
  227. Akc225 float64 `json:"akc225"`
  228. Akc264 float64 `json:"akc264"`
  229. Aka067 string `json:"aka067"`
  230. Akc271 int `json:"akc271"`
  231. Bkc320 string `json:"bkc320"`
  232. Cke400 string `json:"cke400"`
  233. Ckc618 string `json:"ckc618"`
  234. Bka069 int64 `json:"bka069"`
  235. Aka018 string `json:"aka018"`
  236. Aka030 string `json:"aka030"`
  237. Aka065 string `json:"aka065"`
  238. Cka319 float64 `json:"cka319"`
  239. Akc268 float64 `json:"akc268"`
  240. } `json:"outputlist1"`
  241. Outputlist2 []struct {
  242. Aka111 string `json:"aka111"`
  243. Bka058 float64 `json:"bka058"`
  244. } `json:"outputlist2"`
  245. Outputlist3 []struct {
  246. Aaa036 string `json:"aaa036"`
  247. Aae019 float64 `json:"aae019"`
  248. } `json:"outputlist3"`
  249. } `json:"transBody"`
  250. Verifycode string `json:"verifyCode"`
  251. Extenddeviceid string `json:"extendDeviceId"`
  252. Transchannel string `json:"transChannel"`
  253. Extenduserid string `json:"extendUserId"`
  254. Extendserialnumber string `json:"extendSerialNumber"`
  255. Caz055 string `json:"caz055"`
  256. Aae501 string `json:"aae501"`
  257. }
  258. type ResultMZ001 struct {
  259. Transtime string `json:"transTime"`
  260. Transtype string `json:"transType"`
  261. Transreturncode string `json:"transReturnCode"`
  262. Transreturnmessage string `json:"transReturnMessage"`
  263. Transversion string `json:"transVersion"`
  264. Serialnumber string `json:"serialNumber"`
  265. Cardarea string `json:"cardArea"`
  266. Hospitalcode string `json:"hospitalCode"`
  267. Operatorcode string `json:"operatorCode"`
  268. Operatorname string `json:"operatorName"`
  269. Operatorpass string `json:"operatorPass"`
  270. Transbody struct {
  271. Aaz515 string `json:"aaz515"`
  272. Aaz500 string `json:"aaz500"`
  273. Aac001 float64 `json:"aac001"`
  274. Aac999 string `json:"aac999"`
  275. Aac002 string `json:"aac002"`
  276. Aac058 string `json:"aac058"`
  277. Aac147 string `json:"aac147"`
  278. Aac003 string `json:"aac003"`
  279. Aac004 string `json:"aac004"`
  280. Aac006 float64 `json:"aac006"`
  281. Bae093 float64 `json:"bae093"`
  282. Cac215 string `json:"cac215"`
  283. Aac066 string `json:"aac066"`
  284. Aac008 string `json:"aac008"`
  285. Bke404 string `json:"bke404"`
  286. Aae240 float64 `json:"aae240"`
  287. Bkc346 string `json:"bkc346"`
  288. Ckc601 string `json:"ckc601"`
  289. Caz574 string `json:"caz574"`
  290. Caz654 string `json:"caz654"`
  291. Ckc403 string `json:"ckc403"`
  292. Ckc362 string `json:"ckc362"`
  293. Ckc363 string `json:"ckc363"`
  294. Outputlist1 []struct {
  295. Aab001 float64 `json:"aab001"`
  296. Aab999 string `json:"aab999"`
  297. Aab004 string `json:"aab004"`
  298. Aab019 string `json:"aab019"`
  299. Aae140 string `json:"aae140"`
  300. Aae030 float64 `json:"aae030"`
  301. Aae031 string `json:"aae031"`
  302. Bcc334 string `json:"bcc334"`
  303. Aac031 string `json:"aac031"`
  304. } `json:"outputlist1"`
  305. } `json:"transBody"`
  306. Verifycode string `json:"verifyCode"`
  307. Extenddeviceid string `json:"extendDeviceId"`
  308. Transchannel string `json:"transChannel"`
  309. Extenduserid string `json:"extendUserId"`
  310. Extendserialnumber string `json:"extendSerialNumber"`
  311. Caz055 string `json:"caz055"`
  312. Aae501 string `json:"aae501"`
  313. }
  314. type SZHisApiController struct {
  315. controllers.BaseAuthAPIController
  316. }
  317. func SZHisManagerApiRegistRouters() {
  318. //挂号
  319. beego.Router("/sz/api/register/get", &SZHisApiController{}, "get:GetRegisterInfo")
  320. //结算
  321. beego.Router("/sz/api/settle/get", &SZHisApiController{}, "get:GetSettleInfo")
  322. //预结算
  323. beego.Router("/sz/api/presettle/get", &SZHisApiController{}, "get:GetPreSettleInfo")
  324. //退费
  325. beego.Router("/sz/api/refund/get", &SZHisApiController{}, "get:Refund")
  326. beego.Router("/sz/api/readcard", &SZHisApiController{}, "get:ReadCard")
  327. beego.Router("sz/api/refundnumber/get", &SZHisApiController{}, "get:RefundNumber")
  328. beego.Router("/sz/api/monthrefund/get", &SZHisApiController{}, "get:MonthRefund")
  329. //查询交易
  330. beego.Router("/sz/api/settle/query", &SZHisApiController{}, "get:GetSettleAccounts")
  331. //beego.Router("/sz/api/detail/upload", &SZHisApiController{}, "get:GetUploadDetail")
  332. beego.Router("/sz/api/detail/cancel", &SZHisApiController{}, "get:CancelOrderDetail")
  333. //
  334. ////机构药品目录备案
  335. beego.Router("/sz/api/drug/get", &SZHisApiController{}, "get:GetDrugList")
  336. ////协议机构诊疗项目
  337. beego.Router("/sz/api/treatment/get", &SZHisApiController{}, "get:GetTreatmentProject")
  338. ////协议机构目录备案撤销
  339. beego.Router("/sz/api/revocation/get", &SZHisApiController{}, "get:GetRevocation")
  340. //
  341. ////定点机构约定信息查询
  342. //beego.Router("/sz/api/information/query/get",&SZHisApiController{},"get:GetInformationQuery")
  343. ////-医药师信息登记
  344. beego.Router("/sz/api/doctor/get", &SZHisApiController{}, "get:GetDoctorList")
  345. ////医药师执业状态变更
  346. beego.Router("/sz/api/medical/get", &SZHisApiController{}, "get:GetMedicalList")
  347. ////医药师信息更新
  348. //beego.Router("/sz/api/update/medical/get", &SZHisApiController{}, "get:GetUpdateMedicalList")
  349. ////协议机构材料目录备案
  350. //
  351. beego.Router("/sz/api/goods/get", &SZHisApiController{}, "get:GetGoodsList")
  352. }
  353. func IntPtr(n int) uintptr {
  354. return uintptr(n)
  355. }
  356. func StrPtr(s string) uintptr {
  357. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  358. }
  359. type Custom struct {
  360. DetItemFeeSumamt string
  361. Cut string
  362. FeedetlSn string
  363. Price string
  364. MedListCodg string
  365. Type int64
  366. AdviceId int64
  367. ProjectId int64
  368. ItemId int64
  369. }
  370. func (c *SZHisApiController) ReadCard() {
  371. id_card_type, _ := c.GetInt64("id_card_type")
  372. adminInfo := c.GetAdminUserInfo()
  373. if id_card_type != 1 {
  374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorNoReadCardException)
  375. return
  376. }
  377. month := time.Unix(1557042972, 0).Format("1")
  378. year := time.Now().Format("2006")
  379. month = time.Now().Format("01")
  380. day := time.Now().Format("02")
  381. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  382. number := miConfig.Code + year + month + day +
  383. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  384. id_card_number, health_card_no, _, ret4 := ReadBasCard("MZ002" + "|" + number + "|" + miConfig.Code + "|")
  385. if ret4 == 0 {
  386. patient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  387. if patient.ID == 0 {
  388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  389. return
  390. } else {
  391. c.ServeSuccessJSON(map[string]interface{}{
  392. "patient": patient,
  393. "health_card_no": health_card_no,
  394. })
  395. }
  396. } else {
  397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  398. return
  399. }
  400. }
  401. //获取读卡信息 -- 门诊挂号
  402. //func (c *SZHisApiController) GetRegisterInfo() {
  403. // adminInfo := c.GetAdminUserInfo()
  404. // admin_user_id, _ := c.GetInt64("admin_user_id")
  405. // patient_id, _ := c.GetInt64("id")
  406. // record_time := c.GetString("record_time")
  407. // settlementValue, _ := c.GetInt64("settlement_value")
  408. // medical_insurance_card := c.GetString("medical_insurance_card")
  409. // name := c.GetString("name")
  410. // id_card_type, _ := c.GetInt64("id_card_type")
  411. // certificates, _ := c.GetInt64("certificates")
  412. // medical_care, _ := c.GetInt64("medical_care")
  413. // birthday := c.GetString("birthday")
  414. // id_card := c.GetString("id_card")
  415. // register_type, _ := c.GetInt64("register")
  416. // doctor, _ := c.GetInt64("doctor")
  417. // department, _ := c.GetInt64("department")
  418. // gender, _ := c.GetInt64("sex")
  419. // registration_fee, _ := c.GetFloat("registration_fee")
  420. // medical_expenses, _ := c.GetFloat("medical_expenses")
  421. // social_type, _ := c.GetInt64("social_type")
  422. //
  423. // is_yidi, _ := c.GetInt64("is_yidi")
  424. //
  425. // timeLayout := "2006-01-02"
  426. // loc, _ := time.LoadLocation("Local")
  427. // birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  428. // birthUnix := birthdays.Unix()
  429. //
  430. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  431. // if err != nil {
  432. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  433. // return
  434. // }
  435. //
  436. // var patient service.Patients
  437. // if patient_id == 0 {
  438. // patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  439. // } else {
  440. // patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  441. // }
  442. //
  443. // miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  444. // if patient.ID == 0 {
  445. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  446. // return
  447. // }
  448. // if len(patient.IdCardNo) == 0 {
  449. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  450. // return
  451. // }
  452. //
  453. // adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  454. // his, _ := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient_id, theTime.Unix())
  455. //
  456. // var custom_code string
  457. // var custom_project_name string
  458. // var allPrice float64
  459. //
  460. // switch register_type {
  461. // case 1:
  462. // custom_code = "110100002"
  463. // custom_project_name = "普通门诊"
  464. // allPrice = 10
  465. // break
  466. // case 3:
  467. // custom_code = "110200002-2"
  468. // custom_project_name = "主任医师"
  469. // allPrice = 10
  470. //
  471. // break
  472. // case 2:
  473. // custom_code = "110200002-3"
  474. // custom_project_name = "副主任医师"
  475. // allPrice = 10
  476. //
  477. // break
  478. // case 4:
  479. // custom_code = "0"
  480. // custom_project_name = "免受诊金"
  481. // allPrice = 0
  482. // break
  483. // case 5:
  484. // custom_code = "110200002-1"
  485. // custom_project_name = "专家"
  486. // allPrice = 10
  487. //
  488. // break
  489. // }
  490. //
  491. // if his.ID == 0 {
  492. //
  493. // var doctor_name string
  494. // var doctor_code string
  495. // if adminRole.ID == 0 {
  496. //
  497. // doctor_name = ""
  498. // doctor_code = "1001"
  499. // doctor_name = ""
  500. // doctor_code = ""
  501. //
  502. // } else {
  503. // doctor_name = adminRole.UserName
  504. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  505. //
  506. // }
  507. // month := time.Unix(1557042972, 0).Format("1")
  508. // year := time.Now().Format("2006")
  509. // month = time.Now().Format("01")
  510. // day := time.Now().Format("02")
  511. //
  512. // //流水号
  513. // //
  514. // number := miConfig.Code + year + month + day +
  515. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  516. // mz_number := year + month + day + strconv.FormatInt(patient_id, 10) +
  517. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000))
  518. // //1.判断读卡类型
  519. // //2.读卡 获取交易验证码,医疗证号,发卡地区行政区划代码
  520. // yiliao_number, id_card_number, verifyCode, version_code, _, ret4 := ReadBasCardGetNumber("MZ002" + "|" + number + "|" + miConfig.Code + "|")
  521. // fmt.Println(yiliao_number)
  522. // fmt.Println(id_card_number)
  523. // fmt.Println(verifyCode)
  524. // fmt.Println(version_code)
  525. // fmt.Println(ret4)
  526. //
  527. // dept_code := "0305"
  528. // is_yidi = 1
  529. // tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  530. // //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  531. // if tempPatient.ID == patient_id {
  532. // if ret4 == 0 { //本地卡流程
  533. // if is_yidi == 1 {
  534. // //本地就医流程
  535. // //挂号
  536. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, dept_code, yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice,medical_care)
  537. // var dat map[string]interface{}
  538. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  539. // fmt.Println(dat)
  540. // } else {
  541. // fmt.Println(err)
  542. // }
  543. // userJSONBytes, _ := json.Marshal(dat)
  544. // var res ResultOne
  545. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  546. // utils.ErrorLog("解析失败:%v", err)
  547. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  548. // return
  549. // }
  550. // if res.Transreturncode == "00000000" {
  551. // his := models.VMHisPatient{
  552. // Name: name,
  553. // Gender: gender,
  554. // Birthday: birthUnix,
  555. // MedicalTreatmentType: medical_care,
  556. // IdType: certificates,
  557. // IdCardNo: id_card,
  558. // BalanceAccountsType: settlementValue,
  559. // SocialType: social_type,
  560. // MedicalInsuranceNumber: medical_insurance_card,
  561. // RegisterType: register_type,
  562. // RegisterCost: registration_fee,
  563. // TreatmentCost: medical_expenses,
  564. // Status: 1,
  565. // Ctime: time.Now().Unix(),
  566. // Mtime: time.Now().Unix(),
  567. // Iinfo: resp_result,
  568. // PatientId: patient.ID,
  569. // RecordDate: theTime.Unix(),
  570. // UserOrgId: adminInfo.CurrentOrgId,
  571. // AdminUserId: admin_user_id,
  572. // IsReturn: 1,
  573. // IdCardType: id_card_type,
  574. // Doctor: doctor,
  575. // Departments: department,
  576. // YiliaoNumber: yiliao_number,
  577. // MzNumber: number,
  578. // Number: mz_number,
  579. // }
  580. // service.CreateHisPatientTwo(&his)
  581. // c.ServeSuccessJSON(map[string]interface{}{
  582. // "msg": "挂号成功",
  583. // })
  584. // } else {
  585. // c.ServeSuccessJSON(map[string]interface{}{
  586. // "failed_code": -10,
  587. // "msg": res.Transreturnmessage,
  588. // })
  589. // return
  590. // }
  591. //
  592. // } else {
  593. // //异地就医流程
  594. // //异地走鉴权流程
  595. // //authResult := CardAuth(number)
  596. // //fmt.Println(authResult)
  597. //
  598. // //tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  599. // //if tempPatient.ID == patient_id {
  600. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice)
  601. // var dat map[string]interface{}
  602. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  603. // fmt.Println(dat)
  604. // } else {
  605. // fmt.Println(err)
  606. // }
  607. //
  608. // userJSONBytes, _ := json.Marshal(dat)
  609. //
  610. // var res ResultOne
  611. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  612. // utils.ErrorLog("解析失败:%v", err)
  613. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  614. // return
  615. // }
  616. // if res.Transreturncode == "00000000" {
  617. // his := models.VMHisPatient{
  618. // Name: name,
  619. // Gender: gender,
  620. // Birthday: birthUnix,
  621. // MedicalTreatmentType: medical_care,
  622. // IdType: certificates,
  623. // IdCardNo: id_card,
  624. // BalanceAccountsType: settlementValue,
  625. // SocialType: social_type,
  626. // MedicalInsuranceNumber: medical_insurance_card,
  627. // RegisterType: register_type,
  628. // RegisterCost: registration_fee,
  629. // TreatmentCost: medical_expenses,
  630. // Status: 1,
  631. // Ctime: time.Now().Unix(),
  632. // Mtime: time.Now().Unix(),
  633. // Iinfo: resp_result,
  634. // PatientId: patient.ID,
  635. // RecordDate: theTime.Unix(),
  636. // UserOrgId: adminInfo.CurrentOrgId,
  637. // AdminUserId: admin_user_id,
  638. // IsReturn: 1,
  639. // IdCardType: id_card_type,
  640. // Doctor: doctor,
  641. // Departments: department,
  642. // YiliaoNumber: yiliao_number,
  643. // MzNumber: number,
  644. // Number: mz_number,
  645. // }
  646. // service.CreateHisPatientTwo(&his)
  647. // c.ServeSuccessJSON(map[string]interface{}{
  648. // "msg": "挂号成功",
  649. // })
  650. // } else {
  651. // c.ServeSuccessJSON(map[string]interface{}{
  652. // "failed_code": -10,
  653. // "msg": res.Transreturnmessage,
  654. // })
  655. // return
  656. // }
  657. //
  658. // }
  659. //
  660. // } else { //异地卡流程
  661. // //readCardBasResult := ReadCardBasHSM(number)
  662. // //fmt.Println(readCardBasResult)
  663. // //是否异地就医,是的话走鉴权流程,不是的话走门诊挂号
  664. // if is_yidi == 1 { //1本地就医
  665. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice)
  666. // var dat map[string]interface{}
  667. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  668. // fmt.Println(dat)
  669. // } else {
  670. // fmt.Println(err)
  671. // }
  672. //
  673. // userJSONBytes, _ := json.Marshal(dat)
  674. //
  675. // var res ResultOne
  676. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  677. // utils.ErrorLog("解析失败:%v", err)
  678. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  679. // return
  680. // }
  681. // if res.Transreturncode == "00000000" {
  682. // his := models.VMHisPatient{
  683. // Name: name,
  684. // Gender: gender,
  685. // Birthday: birthUnix,
  686. // MedicalTreatmentType: medical_care,
  687. // IdType: certificates,
  688. // IdCardNo: id_card,
  689. // BalanceAccountsType: settlementValue,
  690. // SocialType: social_type,
  691. // MedicalInsuranceNumber: medical_insurance_card,
  692. // RegisterType: register_type,
  693. // RegisterCost: registration_fee,
  694. // TreatmentCost: medical_expenses,
  695. // Status: 1,
  696. // Ctime: time.Now().Unix(),
  697. // Mtime: time.Now().Unix(),
  698. // Iinfo: resp_result,
  699. // PatientId: patient.ID,
  700. // RecordDate: theTime.Unix(),
  701. // UserOrgId: adminInfo.CurrentOrgId,
  702. // AdminUserId: admin_user_id,
  703. // IsReturn: 1,
  704. // IdCardType: id_card_type,
  705. // Doctor: doctor,
  706. // Departments: department,
  707. // YiliaoNumber: yiliao_number,
  708. // MzNumber: number,
  709. // Number: mz_number,
  710. // }
  711. // service.CreateHisPatientTwo(&his)
  712. // c.ServeSuccessJSON(map[string]interface{}{
  713. // "msg": "挂号成功",
  714. // })
  715. // } else {
  716. // c.ServeSuccessJSON(map[string]interface{}{
  717. // "failed_code": -10,
  718. // "msg": res.Transreturnmessage,
  719. // })
  720. // return
  721. // }
  722. //
  723. // } else { //异地就医需要走鉴权流程
  724. // //authResult := CardAuth(number)
  725. // //fmt.Println(authResult)
  726. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice)
  727. // var dat map[string]interface{}
  728. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  729. // fmt.Println(dat)
  730. // } else {
  731. // fmt.Println(err)
  732. // }
  733. //
  734. // userJSONBytes, _ := json.Marshal(dat)
  735. //
  736. // var res ResultOne
  737. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  738. // utils.ErrorLog("解析失败:%v", err)
  739. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  740. // return
  741. // }
  742. // if res.Transreturncode == "00000000" {
  743. // his := models.VMHisPatient{
  744. // Name: name,
  745. // Gender: gender,
  746. // Birthday: birthUnix,
  747. // MedicalTreatmentType: medical_care,
  748. // IdType: certificates,
  749. // IdCardNo: id_card,
  750. // BalanceAccountsType: settlementValue,
  751. // SocialType: social_type,
  752. // MedicalInsuranceNumber: medical_insurance_card,
  753. // RegisterType: register_type,
  754. // RegisterCost: registration_fee,
  755. // TreatmentCost: medical_expenses,
  756. // Status: 1,
  757. // Ctime: time.Now().Unix(),
  758. // Mtime: time.Now().Unix(),
  759. // Iinfo: resp_result,
  760. // PatientId: patient.ID,
  761. // RecordDate: theTime.Unix(),
  762. // UserOrgId: adminInfo.CurrentOrgId,
  763. // AdminUserId: admin_user_id,
  764. // IsReturn: 1,
  765. // IdCardType: id_card_type,
  766. // Doctor: doctor,
  767. // Departments: department,
  768. // YiliaoNumber: yiliao_number,
  769. // MzNumber: number,
  770. // Number: mz_number,
  771. // }
  772. // service.CreateHisPatientTwo(&his)
  773. // c.ServeSuccessJSON(map[string]interface{}{
  774. // "msg": "挂号成功",
  775. // })
  776. // } else {
  777. // c.ServeSuccessJSON(map[string]interface{}{
  778. // "failed_code": -10,
  779. // "msg": res.Transreturnmessage,
  780. // })
  781. // return
  782. // }
  783. //
  784. // }
  785. // }
  786. // } else {
  787. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  788. // return
  789. // }
  790. // } else {
  791. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  792. // return
  793. // }
  794. //}
  795. func (c *SZHisApiController) GetRegisterInfo() {
  796. adminInfo := c.GetAdminUserInfo()
  797. admin_user_id, _ := c.GetInt64("admin_user_id")
  798. patient_id, _ := c.GetInt64("id")
  799. record_time := c.GetString("record_time")
  800. settlementValue, _ := c.GetInt64("settlement_value")
  801. medical_insurance_card := c.GetString("medical_insurance_card")
  802. name := c.GetString("name")
  803. id_card_type, _ := c.GetInt64("id_card_type")
  804. certificates, _ := c.GetInt64("certificates")
  805. medical_care, _ := c.GetInt64("medical_care")
  806. birthday := c.GetString("birthday")
  807. id_card := c.GetString("id_card")
  808. register_type, _ := c.GetInt64("register")
  809. doctor, _ := c.GetInt64("doctor")
  810. department, _ := c.GetInt64("department")
  811. gender, _ := c.GetInt64("sex")
  812. registration_fee, _ := c.GetFloat("registration_fee")
  813. medical_expenses, _ := c.GetFloat("medical_expenses")
  814. social_type, _ := c.GetInt64("social_type")
  815. is_yidi, _ := c.GetInt64("is_yidi")
  816. timeLayout := "2006-01-02"
  817. loc, _ := time.LoadLocation("Local")
  818. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  819. birthUnix := birthdays.Unix()
  820. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  821. if err != nil {
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  823. return
  824. }
  825. var patient service.Patients
  826. if patient_id == 0 {
  827. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  828. } else {
  829. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  830. }
  831. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  832. if patient.ID == 0 {
  833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  834. return
  835. }
  836. if len(patient.IdCardNo) == 0 {
  837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  838. return
  839. }
  840. //doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor)
  841. doctorDepartment, _ := service.GetDepartMentDetail(department)
  842. adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  843. //his, _ := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient_id, theTime.Unix())
  844. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, theTime.Unix())
  845. if len(his) >= 1 {
  846. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, theTime.Unix())
  847. if len(his) >= 1 && order.ID == 0 {
  848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  849. return
  850. }
  851. }
  852. var custom_code string
  853. var custom_project_name string
  854. var allPrice float64
  855. switch register_type {
  856. case 1:
  857. custom_code = "110100002"
  858. custom_project_name = "普通门诊"
  859. allPrice = 10
  860. break
  861. case 3:
  862. custom_code = "110200002-2"
  863. custom_project_name = "主任医师"
  864. allPrice = 10
  865. break
  866. case 2:
  867. custom_code = "110200002-3"
  868. custom_project_name = "副主任医师"
  869. allPrice = 10
  870. break
  871. case 4:
  872. custom_code = "0"
  873. custom_project_name = "免受诊金"
  874. allPrice = 0
  875. break
  876. case 5:
  877. custom_code = "110200002-1"
  878. custom_project_name = "专家"
  879. allPrice = 10
  880. break
  881. }
  882. var opera_name string
  883. var opera_code string
  884. if adminRole.ID == 0 {
  885. opera_name = "管理员"
  886. opera_code = "01"
  887. } else {
  888. opera_name = adminRole.UserName
  889. opera_code = strconv.FormatInt(admin_user_id, 10)
  890. }
  891. month := time.Unix(1557042972, 0).Format("1")
  892. year := time.Now().Format("2006")
  893. month = time.Now().Format("01")
  894. day := time.Now().Format("02")
  895. //流水号
  896. number := miConfig.Code + year + month + day +
  897. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  898. mz_number := miConfig.Code + year + month + day +
  899. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000))
  900. //1.判断读卡类型
  901. //2.读卡 获取交易验证码,医疗证号,发卡地区行政区划代码
  902. yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("MZ002" + "|" + number + "|" + miConfig.Code + "|")
  903. dept_code := doctorDepartment.Number
  904. is_yidi = 1
  905. tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  906. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  907. fmt.Println(tempPatient.ID)
  908. fmt.Println(patient_id)
  909. if tempPatient.ID == patient_id {
  910. temp_mz_number := miConfig.Code + year + month + day +
  911. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000))
  912. tempVerifyCode, tempVersionCode := ReadCardGetCode("XX001" + "|" + temp_mz_number + "|" + miConfig.Code)
  913. //yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("MZ002" + "|" + number + "|" + miConfig.Code + "|")
  914. //yiliao_number = "%GALMAFXJGKUKZNKWAIUH?;07857319025346309758?"
  915. result001 := service.SzybXX001(opera_name, opera_code, miConfig.Code, yiliao_number, tempVerifyCode, temp_mz_number, tempVersionCode)
  916. if ret4 == 0 { //本地卡流程
  917. if is_yidi == 1 {
  918. //var dat2 map[string]interface{}
  919. //if err := json.Unmarshal([]byte(result001), &dat2); err == nil {
  920. // fmt.Println(dat2)
  921. //} else {
  922. // fmt.Println(err)
  923. //}
  924. //userJSONBytes2, _ := json.Marshal(dat2)
  925. //var res2 ResultMZ001
  926. //if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  927. // utils.ErrorLog("解析失败:%v", err)
  928. //}
  929. //本地就医流程
  930. //挂号
  931. resp_result := service.SzybMZ002(opera_name, opera_code, miConfig.Code, dept_code, yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  932. var dat map[string]interface{}
  933. if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  934. fmt.Println(dat)
  935. } else {
  936. fmt.Println(err)
  937. }
  938. userJSONBytes, _ := json.Marshal(dat)
  939. var res ResultOne
  940. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  941. utils.ErrorLog("解析失败:%v", err)
  942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  943. return
  944. }
  945. if res.Transreturncode == "00000000" {
  946. his := models.VMHisPatient{
  947. Name: name,
  948. Gender: gender,
  949. Birthday: birthUnix,
  950. MedicalTreatmentType: medical_care,
  951. IdType: certificates,
  952. IdCardNo: id_card,
  953. BalanceAccountsType: settlementValue,
  954. SocialType: social_type,
  955. MedicalInsuranceNumber: medical_insurance_card,
  956. RegisterType: register_type,
  957. RegisterCost: registration_fee,
  958. TreatmentCost: medical_expenses,
  959. Status: 1,
  960. Ctime: time.Now().Unix(),
  961. Mtime: time.Now().Unix(),
  962. Iinfo: resp_result,
  963. PatientId: patient.ID,
  964. RecordDate: theTime.Unix(),
  965. UserOrgId: adminInfo.CurrentOrgId,
  966. AdminUserId: admin_user_id,
  967. IsReturn: 1,
  968. IdCardType: id_card_type,
  969. Doctor: doctor,
  970. Departments: department,
  971. YiliaoNumber: yiliao_number,
  972. MzNumber: number,
  973. Number: mz_number,
  974. PsnNo: health_card_no,
  975. PatientInfo: result001,
  976. }
  977. service.CreateHisPatientTwo(&his)
  978. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, theTime.Unix())
  979. if len(lists) == 1 {
  980. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, theTime.Unix(), adminInfo.CurrentOrgId)
  981. }
  982. c.ServeSuccessJSON(map[string]interface{}{
  983. "msg": "挂号成功",
  984. })
  985. } else {
  986. c.ServeSuccessJSON(map[string]interface{}{
  987. "failed_code": -10,
  988. "msg": res.Transreturnmessage,
  989. })
  990. return
  991. }
  992. } else {
  993. //异地就医流程
  994. //异地走鉴权流程
  995. //authResult := CardAuth(number)
  996. //fmt.Println(authResult)
  997. //tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  998. //if tempPatient.ID == patient_id {
  999. resp_result := service.SzybMZ002(opera_name, opera_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  1000. var dat map[string]interface{}
  1001. if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1002. fmt.Println(dat)
  1003. } else {
  1004. fmt.Println(err)
  1005. }
  1006. userJSONBytes, _ := json.Marshal(dat)
  1007. var res ResultOne
  1008. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1009. utils.ErrorLog("解析失败:%v", err)
  1010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1011. return
  1012. }
  1013. if res.Transreturncode == "00000000" {
  1014. his := models.VMHisPatient{
  1015. Name: name,
  1016. Gender: gender,
  1017. Birthday: birthUnix,
  1018. MedicalTreatmentType: medical_care,
  1019. IdType: certificates,
  1020. IdCardNo: id_card,
  1021. BalanceAccountsType: settlementValue,
  1022. SocialType: social_type,
  1023. MedicalInsuranceNumber: medical_insurance_card,
  1024. RegisterType: register_type,
  1025. RegisterCost: registration_fee,
  1026. TreatmentCost: medical_expenses,
  1027. Status: 1,
  1028. Ctime: time.Now().Unix(),
  1029. Mtime: time.Now().Unix(),
  1030. Iinfo: resp_result,
  1031. PatientId: patient.ID,
  1032. RecordDate: theTime.Unix(),
  1033. UserOrgId: adminInfo.CurrentOrgId,
  1034. AdminUserId: admin_user_id,
  1035. IsReturn: 1,
  1036. IdCardType: id_card_type,
  1037. Doctor: doctor,
  1038. Departments: department,
  1039. YiliaoNumber: yiliao_number,
  1040. MzNumber: number,
  1041. Number: mz_number,
  1042. PsnNo: health_card_no,
  1043. PatientInfo: result001,
  1044. }
  1045. service.CreateHisPatientTwo(&his)
  1046. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, theTime.Unix())
  1047. if len(lists) == 1 {
  1048. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, theTime.Unix(), adminInfo.CurrentOrgId)
  1049. }
  1050. c.ServeSuccessJSON(map[string]interface{}{
  1051. "msg": "挂号成功",
  1052. })
  1053. } else {
  1054. c.ServeSuccessJSON(map[string]interface{}{
  1055. "failed_code": -10,
  1056. "msg": res.Transreturnmessage,
  1057. })
  1058. return
  1059. }
  1060. }
  1061. } else { //异地卡流程
  1062. //readCardBasResult := ReadCardBasHSM(number)
  1063. //fmt.Println(readCardBasResult)
  1064. //是否异地就医,是的话走鉴权流程,不是的话走门诊挂号
  1065. if is_yidi == 1 { //1本地就医
  1066. resp_result := service.SzybMZ002(opera_name, opera_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  1067. var dat map[string]interface{}
  1068. if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1069. fmt.Println(dat)
  1070. } else {
  1071. fmt.Println(err)
  1072. }
  1073. userJSONBytes, _ := json.Marshal(dat)
  1074. var res ResultOne
  1075. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1076. utils.ErrorLog("解析失败:%v", err)
  1077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1078. return
  1079. }
  1080. if res.Transreturncode == "00000000" {
  1081. his := models.VMHisPatient{
  1082. Name: name,
  1083. Gender: gender,
  1084. Birthday: birthUnix,
  1085. MedicalTreatmentType: medical_care,
  1086. IdType: certificates,
  1087. IdCardNo: id_card,
  1088. BalanceAccountsType: settlementValue,
  1089. SocialType: social_type,
  1090. MedicalInsuranceNumber: medical_insurance_card,
  1091. RegisterType: register_type,
  1092. RegisterCost: registration_fee,
  1093. TreatmentCost: medical_expenses,
  1094. Status: 1,
  1095. Ctime: time.Now().Unix(),
  1096. Mtime: time.Now().Unix(),
  1097. Iinfo: resp_result,
  1098. PatientId: patient.ID,
  1099. RecordDate: theTime.Unix(),
  1100. UserOrgId: adminInfo.CurrentOrgId,
  1101. AdminUserId: admin_user_id,
  1102. IsReturn: 1,
  1103. IdCardType: id_card_type,
  1104. Doctor: doctor,
  1105. Departments: department,
  1106. YiliaoNumber: yiliao_number,
  1107. MzNumber: number,
  1108. Number: mz_number,
  1109. PsnNo: health_card_no,
  1110. PatientInfo: result001,
  1111. }
  1112. service.CreateHisPatientTwo(&his)
  1113. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, theTime.Unix())
  1114. if len(lists) == 1 {
  1115. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, theTime.Unix(), adminInfo.CurrentOrgId)
  1116. }
  1117. c.ServeSuccessJSON(map[string]interface{}{
  1118. "msg": "挂号成功",
  1119. })
  1120. } else {
  1121. c.ServeSuccessJSON(map[string]interface{}{
  1122. "failed_code": -10,
  1123. "msg": res.Transreturnmessage,
  1124. })
  1125. return
  1126. }
  1127. } else { //异地就医需要走鉴权流程
  1128. //authResult := CardAuth(number)
  1129. //fmt.Println(authResult)
  1130. resp_result := service.SzybMZ002(opera_name, opera_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  1131. var dat map[string]interface{}
  1132. if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1133. fmt.Println(dat)
  1134. } else {
  1135. fmt.Println(err)
  1136. }
  1137. userJSONBytes, _ := json.Marshal(dat)
  1138. var res ResultOne
  1139. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1140. utils.ErrorLog("解析失败:%v", err)
  1141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1142. return
  1143. }
  1144. if res.Transreturncode == "00000000" {
  1145. his := models.VMHisPatient{
  1146. Name: name,
  1147. Gender: gender,
  1148. Birthday: birthUnix,
  1149. MedicalTreatmentType: medical_care,
  1150. IdType: certificates,
  1151. IdCardNo: id_card,
  1152. BalanceAccountsType: settlementValue,
  1153. SocialType: social_type,
  1154. MedicalInsuranceNumber: medical_insurance_card,
  1155. RegisterType: register_type,
  1156. RegisterCost: registration_fee,
  1157. TreatmentCost: medical_expenses,
  1158. Status: 1,
  1159. Ctime: time.Now().Unix(),
  1160. Mtime: time.Now().Unix(),
  1161. Iinfo: resp_result,
  1162. PatientId: patient.ID,
  1163. RecordDate: theTime.Unix(),
  1164. UserOrgId: adminInfo.CurrentOrgId,
  1165. AdminUserId: admin_user_id,
  1166. IsReturn: 1,
  1167. IdCardType: id_card_type,
  1168. Doctor: doctor,
  1169. Departments: department,
  1170. YiliaoNumber: yiliao_number,
  1171. MzNumber: number,
  1172. Number: mz_number,
  1173. PsnNo: health_card_no,
  1174. PatientInfo: result001,
  1175. }
  1176. service.CreateHisPatientTwo(&his)
  1177. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, theTime.Unix())
  1178. if len(lists) == 1 {
  1179. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, theTime.Unix(), adminInfo.CurrentOrgId)
  1180. }
  1181. c.ServeSuccessJSON(map[string]interface{}{
  1182. "msg": "挂号成功",
  1183. })
  1184. } else {
  1185. c.ServeSuccessJSON(map[string]interface{}{
  1186. "failed_code": -10,
  1187. "msg": res.Transreturnmessage,
  1188. })
  1189. return
  1190. }
  1191. }
  1192. }
  1193. } else {
  1194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  1195. return
  1196. }
  1197. }
  1198. //func (c *SZHisApiController) GetInfo() {
  1199. //func (c *SZHisApiController) GetRegisterInfo() {
  1200. // adminInfo := c.GetAdminUserInfo()
  1201. // admin_user_id, _ := c.GetInt64("admin_user_id")
  1202. // patient_id, _ := c.GetInt64("id")
  1203. // record_time := c.GetString("record_time")
  1204. // settlementValue, _ := c.GetInt64("settlement_value")
  1205. // medical_insurance_card := c.GetString("medical_insurance_card")
  1206. // name := c.GetString("name")
  1207. // id_card_type, _ := c.GetInt64("id_card_type")
  1208. // certificates, _ := c.GetInt64("certificates")
  1209. // medical_care, _ := c.GetInt64("medical_care")
  1210. // birthday := c.GetString("birthday")
  1211. // id_card := c.GetString("id_card")
  1212. // register_type, _ := c.GetInt64("register")
  1213. // doctor, _ := c.GetInt64("doctor")
  1214. // department, _ := c.GetInt64("department")
  1215. // gender, _ := c.GetInt64("sex")
  1216. // registration_fee, _ := c.GetFloat("registration_fee")
  1217. // medical_expenses, _ := c.GetFloat("medical_expenses")
  1218. // social_type, _ := c.GetInt64("social_type")
  1219. //
  1220. // is_yidi, _ := c.GetInt64("is_yidi")
  1221. //
  1222. // timeLayout := "2006-01-02"
  1223. // loc, _ := time.LoadLocation("Local")
  1224. // birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  1225. // birthUnix := birthdays.Unix()
  1226. //
  1227. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1228. // if err != nil {
  1229. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1230. // return
  1231. // }
  1232. //
  1233. // var patient service.Patients
  1234. // if patient_id == 0 {
  1235. // patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  1236. // } else {
  1237. // patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1238. // }
  1239. //
  1240. // miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1241. // if patient.ID == 0 {
  1242. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1243. // return
  1244. // }
  1245. // if len(patient.IdCardNo) == 0 {
  1246. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  1247. // return
  1248. // }
  1249. //
  1250. // adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1251. // his, _ := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient_id, theTime.Unix())
  1252. //
  1253. // var custom_code string
  1254. // var custom_project_name string
  1255. // var allPrice float64
  1256. //
  1257. // switch register_type {
  1258. // case 1:
  1259. // custom_code = "110100002"
  1260. // custom_project_name = "普通门诊"
  1261. // allPrice = 10
  1262. // break
  1263. // case 3:
  1264. // custom_code = "110200002-2"
  1265. // custom_project_name = "主任医师"
  1266. // allPrice = 10
  1267. //
  1268. // break
  1269. // case 2:
  1270. // custom_code = "110200002-3"
  1271. // custom_project_name = "副主任医师"
  1272. // allPrice = 10
  1273. //
  1274. // break
  1275. // case 4:
  1276. // custom_code = "0"
  1277. // custom_project_name = "免受诊金"
  1278. // allPrice = 0
  1279. // break
  1280. // case 5:
  1281. // custom_code = "110200002-1"
  1282. // custom_project_name = "专家"
  1283. // allPrice = 10
  1284. //
  1285. // break
  1286. // }
  1287. //
  1288. // if his.ID == 0 {
  1289. //
  1290. // var doctor_name string
  1291. // var doctor_code string
  1292. // if adminRole.ID == 0 {
  1293. //
  1294. // doctor_name = ""
  1295. // doctor_code = "1001"
  1296. // doctor_name = ""
  1297. // doctor_code = ""
  1298. //
  1299. // } else {
  1300. // doctor_name = adminRole.UserName
  1301. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  1302. //
  1303. // }
  1304. // month := time.Unix(1557042972, 0).Format("1")
  1305. // year := time.Now().Format("2006")
  1306. // month = time.Now().Format("01")
  1307. // day := time.Now().Format("02")
  1308. //
  1309. // //流水号
  1310. // //
  1311. // number := miConfig.Code + year + month + day +
  1312. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  1313. // mz_number := year + month + day + strconv.FormatInt(patient_id, 10) +
  1314. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000))
  1315. // //1.判断读卡类型
  1316. // //2.读卡 获取交易验证码,医疗证号,发卡地区行政区划代码
  1317. // yiliao_number, id_card_number, verifyCode, version_code, _, ret4 := ReadBasCardGetNumber("MZ002" + "|" + number + "|" + miConfig.Code + "|")
  1318. // fmt.Println(yiliao_number)
  1319. // fmt.Println(id_card_number)
  1320. // fmt.Println(verifyCode)
  1321. // fmt.Println(version_code)
  1322. // fmt.Println(ret4)
  1323. //
  1324. // dept_code := "0305"
  1325. // is_yidi = 1
  1326. // tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  1327. // //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  1328. // if tempPatient.ID == patient_id {
  1329. // if ret4 == 0 { //本地卡流程
  1330. // if is_yidi == 1 {
  1331. // //本地就医流程
  1332. // //挂号
  1333. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, dept_code, yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  1334. // var dat map[string]interface{}
  1335. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1336. // fmt.Println(dat)
  1337. // } else {
  1338. // fmt.Println(err)
  1339. // }
  1340. // userJSONBytes, _ := json.Marshal(dat)
  1341. // var res ResultOne
  1342. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1343. // utils.ErrorLog("解析失败:%v", err)
  1344. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1345. // return
  1346. // }
  1347. // if res.Transreturncode == "00000000" {
  1348. // his := models.VMHisPatient{
  1349. // Name: name,
  1350. // Gender: gender,
  1351. // Birthday: birthUnix,
  1352. // MedicalTreatmentType: medical_care,
  1353. // IdType: certificates,
  1354. // IdCardNo: id_card,
  1355. // BalanceAccountsType: settlementValue,
  1356. // SocialType: social_type,
  1357. // MedicalInsuranceNumber: medical_insurance_card,
  1358. // RegisterType: register_type,
  1359. // RegisterCost: registration_fee,
  1360. // TreatmentCost: medical_expenses,
  1361. // Status: 1,
  1362. // Ctime: time.Now().Unix(),
  1363. // Mtime: time.Now().Unix(),
  1364. // Iinfo: resp_result,
  1365. // PatientId: patient.ID,
  1366. // RecordDate: theTime.Unix(),
  1367. // UserOrgId: adminInfo.CurrentOrgId,
  1368. // AdminUserId: admin_user_id,
  1369. // IsReturn: 1,
  1370. // IdCardType: id_card_type,
  1371. // Doctor: doctor,
  1372. // Departments: department,
  1373. // YiliaoNumber: yiliao_number,
  1374. // MzNumber: number,
  1375. // Number: mz_number,
  1376. // }
  1377. // service.CreateHisPatientTwo(&his)
  1378. // c.ServeSuccessJSON(map[string]interface{}{
  1379. // "msg": "挂号成功",
  1380. // })
  1381. // } else {
  1382. // c.ServeSuccessJSON(map[string]interface{}{
  1383. // "failed_code": -10,
  1384. // "msg": res.Transreturnmessage,
  1385. // })
  1386. // return
  1387. // }
  1388. //
  1389. // } else {
  1390. // //异地就医流程
  1391. // //异地走鉴权流程
  1392. // //authResult := CardAuth(number)
  1393. // //fmt.Println(authResult)
  1394. //
  1395. // //tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  1396. // //if tempPatient.ID == patient_id {
  1397. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice)
  1398. // var dat map[string]interface{}
  1399. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1400. // fmt.Println(dat)
  1401. // } else {
  1402. // fmt.Println(err)
  1403. // }
  1404. //
  1405. // userJSONBytes, _ := json.Marshal(dat)
  1406. //
  1407. // var res ResultOne
  1408. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1409. // utils.ErrorLog("解析失败:%v", err)
  1410. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1411. // return
  1412. // }
  1413. // if res.Transreturncode == "00000000" {
  1414. // his := models.VMHisPatient{
  1415. // Name: name,
  1416. // Gender: gender,
  1417. // Birthday: birthUnix,
  1418. // MedicalTreatmentType: medical_care,
  1419. // IdType: certificates,
  1420. // IdCardNo: id_card,
  1421. // BalanceAccountsType: settlementValue,
  1422. // SocialType: social_type,
  1423. // MedicalInsuranceNumber: medical_insurance_card,
  1424. // RegisterType: register_type,
  1425. // RegisterCost: registration_fee,
  1426. // TreatmentCost: medical_expenses,
  1427. // Status: 1,
  1428. // Ctime: time.Now().Unix(),
  1429. // Mtime: time.Now().Unix(),
  1430. // Iinfo: resp_result,
  1431. // PatientId: patient.ID,
  1432. // RecordDate: theTime.Unix(),
  1433. // UserOrgId: adminInfo.CurrentOrgId,
  1434. // AdminUserId: admin_user_id,
  1435. // IsReturn: 1,
  1436. // IdCardType: id_card_type,
  1437. // Doctor: doctor,
  1438. // Departments: department,
  1439. // YiliaoNumber: yiliao_number,
  1440. // MzNumber: number,
  1441. // Number: mz_number,
  1442. // }
  1443. // service.CreateHisPatientTwo(&his)
  1444. // c.ServeSuccessJSON(map[string]interface{}{
  1445. // "msg": "挂号成功",
  1446. // })
  1447. // } else {
  1448. // c.ServeSuccessJSON(map[string]interface{}{
  1449. // "failed_code": -10,
  1450. // "msg": res.Transreturnmessage,
  1451. // })
  1452. // return
  1453. // }
  1454. //
  1455. // }
  1456. //
  1457. // } else { //异地卡流程
  1458. // //readCardBasResult := ReadCardBasHSM(number)
  1459. // //fmt.Println(readCardBasResult)
  1460. // //是否异地就医,是的话走鉴权流程,不是的话走门诊挂号
  1461. // if is_yidi == 1 { //1本地就医
  1462. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice)
  1463. // var dat map[string]interface{}
  1464. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1465. // fmt.Println(dat)
  1466. // } else {
  1467. // fmt.Println(err)
  1468. // }
  1469. //
  1470. // userJSONBytes, _ := json.Marshal(dat)
  1471. //
  1472. // var res ResultOne
  1473. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1474. // utils.ErrorLog("解析失败:%v", err)
  1475. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1476. // return
  1477. // }
  1478. // if res.Transreturncode == "00000000" {
  1479. // his := models.VMHisPatient{
  1480. // Name: name,
  1481. // Gender: gender,
  1482. // Birthday: birthUnix,
  1483. // MedicalTreatmentType: medical_care,
  1484. // IdType: certificates,
  1485. // IdCardNo: id_card,
  1486. // BalanceAccountsType: settlementValue,
  1487. // SocialType: social_type,
  1488. // MedicalInsuranceNumber: medical_insurance_card,
  1489. // RegisterType: register_type,
  1490. // RegisterCost: registration_fee,
  1491. // TreatmentCost: medical_expenses,
  1492. // Status: 1,
  1493. // Ctime: time.Now().Unix(),
  1494. // Mtime: time.Now().Unix(),
  1495. // Iinfo: resp_result,
  1496. // PatientId: patient.ID,
  1497. // RecordDate: theTime.Unix(),
  1498. // UserOrgId: adminInfo.CurrentOrgId,
  1499. // AdminUserId: admin_user_id,
  1500. // IsReturn: 1,
  1501. // IdCardType: id_card_type,
  1502. // Doctor: doctor,
  1503. // Departments: department,
  1504. // YiliaoNumber: yiliao_number,
  1505. // MzNumber: number,
  1506. // Number: mz_number,
  1507. // }
  1508. // service.CreateHisPatientTwo(&his)
  1509. // c.ServeSuccessJSON(map[string]interface{}{
  1510. // "msg": "挂号成功",
  1511. // })
  1512. // } else {
  1513. // c.ServeSuccessJSON(map[string]interface{}{
  1514. // "failed_code": -10,
  1515. // "msg": res.Transreturnmessage,
  1516. // })
  1517. // return
  1518. // }
  1519. //
  1520. // } else { //异地就医需要走鉴权流程
  1521. // //authResult := CardAuth(number)
  1522. // //fmt.Println(authResult)
  1523. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice)
  1524. // var dat map[string]interface{}
  1525. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1526. // fmt.Println(dat)
  1527. // } else {
  1528. // fmt.Println(err)
  1529. // }
  1530. //
  1531. // userJSONBytes, _ := json.Marshal(dat)
  1532. //
  1533. // var res ResultOne
  1534. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1535. // utils.ErrorLog("解析失败:%v", err)
  1536. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1537. // return
  1538. // }
  1539. // if res.Transreturncode == "00000000" {
  1540. // his := models.VMHisPatient{
  1541. // Name: name,
  1542. // Gender: gender,
  1543. // Birthday: birthUnix,
  1544. // MedicalTreatmentType: medical_care,
  1545. // IdType: certificates,
  1546. // IdCardNo: id_card,
  1547. // BalanceAccountsType: settlementValue,
  1548. // SocialType: social_type,
  1549. // MedicalInsuranceNumber: medical_insurance_card,
  1550. // RegisterType: register_type,
  1551. // RegisterCost: registration_fee,
  1552. // TreatmentCost: medical_expenses,
  1553. // Status: 1,
  1554. // Ctime: time.Now().Unix(),
  1555. // Mtime: time.Now().Unix(),
  1556. // Iinfo: resp_result,
  1557. // PatientId: patient.ID,
  1558. // RecordDate: theTime.Unix(),
  1559. // UserOrgId: adminInfo.CurrentOrgId,
  1560. // AdminUserId: admin_user_id,
  1561. // IsReturn: 1,
  1562. // IdCardType: id_card_type,
  1563. // Doctor: doctor,
  1564. // Departments: department,
  1565. // YiliaoNumber: yiliao_number,
  1566. // MzNumber: number,
  1567. // Number: mz_number,
  1568. // }
  1569. // service.CreateHisPatientTwo(&his)
  1570. // c.ServeSuccessJSON(map[string]interface{}{
  1571. // "msg": "挂号成功",
  1572. // })
  1573. // } else {
  1574. // c.ServeSuccessJSON(map[string]interface{}{
  1575. // "failed_code": -10,
  1576. // "msg": res.Transreturnmessage,
  1577. // })
  1578. // return
  1579. // }
  1580. //
  1581. // }
  1582. // }
  1583. // } else {
  1584. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  1585. // return
  1586. // }
  1587. // } else {
  1588. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1589. // return
  1590. // }
  1591. //}
  1592. //func (c *SZHisApiController) GetRegisterInfo() {
  1593. // adminInfo := c.GetAdminUserInfo()
  1594. // miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1595. // month := time.Unix(1557042972, 0).Format("1")
  1596. // year := time.Now().Format("2006")
  1597. // month = time.Now().Format("01")
  1598. // day := time.Now().Format("02")
  1599. // //流水号
  1600. // number := miConfig.Code + year + month + day +
  1601. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  1602. // //1.判断读卡类型
  1603. // //2.读卡 获取交易验证码,医疗证号,发卡地区行政区划代码
  1604. // yiliao_number, _, verifyCode, version_code, _, _, _ := ReadBasCardGetNumber("XX001" + "|" + number + "|" + miConfig.Code + "|")
  1605. // fmt.Println(result)
  1606. //
  1607. //}
  1608. func (c *SZHisApiController) RefundNumber() {
  1609. record_time := c.GetString("record_time")
  1610. //patient_id, _ := c.GetInt64("patient_id")
  1611. his_patient_id, _ := c.GetInt64("his_patient_id")
  1612. admin_user_id, _ := c.GetInt64("admin_user_id")
  1613. timeLayout := "2006-01-02"
  1614. loc, _ := time.LoadLocation("Local")
  1615. adminUser := c.GetAdminUserInfo()
  1616. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1617. fmt.Println(err)
  1618. if err != nil {
  1619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1620. return
  1621. }
  1622. recordDateTime := theTime.Unix()
  1623. fmt.Println(recordDateTime)
  1624. his, _ := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, theTime.Unix())
  1625. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1626. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1627. //结算流程
  1628. var doctor_name string
  1629. var doctor_code string
  1630. if roles.ID == 0 {
  1631. doctor_name = "管理员"
  1632. doctor_code = "01"
  1633. } else {
  1634. doctor_name = roles.UserName
  1635. doctor_code = strconv.FormatInt(admin_user_id, 10)
  1636. }
  1637. month := time.Unix(1557042972, 0).Format("1")
  1638. year := time.Now().Format("2006")
  1639. month = time.Now().Format("01")
  1640. day := time.Now().Format("02")
  1641. //number := miConfig.Code + year + month + day + "1367866"
  1642. number := miConfig.Code + year + month + day +
  1643. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  1644. //number := miConfig.Code + year + month + day + "1590003"
  1645. //流水号
  1646. //number_two := miConfig.Code + "-" + year + month + day + "-" + strconv.FormatInt(patient_id, 10)
  1647. verifyCode, version_code := ReadCardGetCode("JY002" + "|" + number + "|" + miConfig.Code)
  1648. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1649. if config.IsOpen == 1 { //对接了医保,走医保流程
  1650. result := service.SzybJY002(doctor_name, doctor_code, miConfig.Code, his.MzNumber, his.Number, verifyCode, number, version_code)
  1651. var dat map[string]interface{}
  1652. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1653. fmt.Println(dat)
  1654. } else {
  1655. fmt.Println(err)
  1656. }
  1657. userJSONBytes, _ := json.Marshal(dat)
  1658. var res ResultThree
  1659. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1660. utils.ErrorLog("解析失败:%v", err)
  1661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1662. return
  1663. }
  1664. if res.Transreturncode == "00000000" {
  1665. service.UpdataHisStatusSZ(adminUser.CurrentOrgId, his.MzNumber, his.Number, result, his_patient_id)
  1666. c.ServeSuccessJSON(map[string]interface{}{
  1667. "msg": "退号成功",
  1668. })
  1669. } else {
  1670. c.ServeSuccessJSON(map[string]interface{}{
  1671. "failed_code": -10,
  1672. "msg": res.Transreturnmessage,
  1673. })
  1674. }
  1675. }
  1676. }
  1677. //func (c *SZHisApiController) GetRegisterInfo() {
  1678. // adminInfo := c.GetAdminUserInfo()
  1679. // admin_user_id, _ := c.GetInt64("admin_user_id")
  1680. // patient_id, _ := c.GetInt64("id")
  1681. // record_time := c.GetString("record_time")
  1682. // settlementValue, _ := c.GetInt64("settlement_value")
  1683. // medical_insurance_card := c.GetString("medical_insurance_card")
  1684. // name := c.GetString("name")
  1685. // id_card_type, _ := c.GetInt64("id_card_type")
  1686. // certificates, _ := c.GetInt64("certificates")
  1687. // medical_care, _ := c.GetInt64("medical_care")
  1688. // birthday := c.GetString("birthday")
  1689. // id_card := c.GetString("id_card")
  1690. // register_type, _ := c.GetInt64("register")
  1691. // doctor, _ := c.GetInt64("doctor")
  1692. // department, _ := c.GetInt64("department")
  1693. // gender, _ := c.GetInt64("sex")
  1694. // registration_fee, _ := c.GetFloat("registration_fee")
  1695. // medical_expenses, _ := c.GetFloat("medical_expenses")
  1696. // social_type, _ := c.GetInt64("social_type")
  1697. //
  1698. // is_yidi, _ := c.GetInt64("is_yidi")
  1699. //
  1700. // timeLayout := "2006-01-02"
  1701. // loc, _ := time.LoadLocation("Local")
  1702. // birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  1703. // birthUnix := birthdays.Unix()
  1704. //
  1705. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1706. // if err != nil {
  1707. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1708. // return
  1709. // }
  1710. //
  1711. // var patient service.Patients
  1712. // if patient_id == 0 {
  1713. // patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  1714. // } else {
  1715. // patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1716. // }
  1717. //
  1718. // miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1719. // if patient.ID == 0 {
  1720. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1721. // return
  1722. // }
  1723. // if len(patient.IdCardNo) == 0 {
  1724. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  1725. // return
  1726. // }
  1727. //
  1728. // adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1729. // his, _ := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient_id, theTime.Unix())
  1730. //
  1731. // var custom_code string
  1732. // var custom_project_name string
  1733. // var allPrice float64
  1734. //
  1735. // switch register_type {
  1736. // case 1:
  1737. // custom_code = "110100002"
  1738. // custom_project_name = "普通门诊"
  1739. // allPrice = 10
  1740. // break
  1741. // case 3:
  1742. // custom_code = "110200002-2"
  1743. // custom_project_name = "主任医师"
  1744. // allPrice = 10
  1745. //
  1746. // break
  1747. // case 2:
  1748. // custom_code = "110200002-3"
  1749. // custom_project_name = "副主任医师"
  1750. // allPrice = 10
  1751. //
  1752. // break
  1753. // case 4:
  1754. // custom_code = "0"
  1755. // custom_project_name = "免受诊金"
  1756. // allPrice = 0
  1757. // break
  1758. // case 5:
  1759. // custom_code = "110200002-1"
  1760. // custom_project_name = "专家"
  1761. // allPrice = 10
  1762. //
  1763. // break
  1764. // }
  1765. //
  1766. // if his.ID == 0 {
  1767. //
  1768. // var doctor_name string
  1769. // var doctor_code string
  1770. // if adminRole.ID == 0 {
  1771. //
  1772. // doctor_name = "管理员"
  1773. // doctor_code = "01"
  1774. //
  1775. // } else {
  1776. // doctor_name = adminRole.UserName
  1777. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  1778. //
  1779. // }
  1780. // month := time.Unix(1557042972, 0).Format("1")
  1781. // year := time.Now().Format("2006")
  1782. // month = time.Now().Format("01")
  1783. // day := time.Now().Format("02")
  1784. //
  1785. // //流水号
  1786. // //
  1787. // number := miConfig.Code + year + month + day +
  1788. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  1789. // mz_number := miConfig.Code + year + month + day +
  1790. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000))
  1791. // //1.判断读卡类型
  1792. // //2.读卡 获取交易验证码,医疗证号,发卡地区行政区划代码
  1793. // yiliao_number, id_card_number, verifyCode, version_code, _, ret4 := ReadBasCardGetNumber("MZ002" + "|" + number + "|" + miConfig.Code + "|")
  1794. // fmt.Println(yiliao_number)
  1795. // fmt.Println(id_card_number)
  1796. // fmt.Println(verifyCode)
  1797. // fmt.Println(version_code)
  1798. // fmt.Println(ret4)
  1799. //
  1800. // dept_code := "0306"
  1801. // is_yidi = 1
  1802. // tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  1803. // //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  1804. // fmt.Println(tempPatient.ID)
  1805. // fmt.Println(patient_id)
  1806. //
  1807. // if tempPatient.ID == patient_id {
  1808. // if ret4 == 0 { //本地卡流程
  1809. // if is_yidi == 1 {
  1810. // //本地就医流程
  1811. // //挂号
  1812. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, dept_code, yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  1813. // var dat map[string]interface{}
  1814. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1815. // fmt.Println(dat)
  1816. // } else {
  1817. // fmt.Println(err)
  1818. // }
  1819. // userJSONBytes, _ := json.Marshal(dat)
  1820. // var res ResultOne
  1821. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1822. // utils.ErrorLog("解析失败:%v", err)
  1823. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1824. // return
  1825. // }
  1826. // if res.Transreturncode == "00000000" {
  1827. // his := models.VMHisPatient{
  1828. // Name: name,
  1829. // Gender: gender,
  1830. // Birthday: birthUnix,
  1831. // MedicalTreatmentType: medical_care,
  1832. // IdType: certificates,
  1833. // IdCardNo: id_card,
  1834. // BalanceAccountsType: settlementValue,
  1835. // SocialType: social_type,
  1836. // MedicalInsuranceNumber: medical_insurance_card,
  1837. // RegisterType: register_type,
  1838. // RegisterCost: registration_fee,
  1839. // TreatmentCost: medical_expenses,
  1840. // Status: 1,
  1841. // Ctime: time.Now().Unix(),
  1842. // Mtime: time.Now().Unix(),
  1843. // Iinfo: resp_result,
  1844. // PatientId: patient.ID,
  1845. // RecordDate: theTime.Unix(),
  1846. // UserOrgId: adminInfo.CurrentOrgId,
  1847. // AdminUserId: admin_user_id,
  1848. // IsReturn: 1,
  1849. // IdCardType: id_card_type,
  1850. // Doctor: doctor,
  1851. // Departments: department,
  1852. // YiliaoNumber: yiliao_number,
  1853. // MzNumber: number,
  1854. // Number: mz_number,
  1855. // }
  1856. // service.CreateHisPatientTwo(&his)
  1857. // c.ServeSuccessJSON(map[string]interface{}{
  1858. // "msg": "挂号成功",
  1859. // })
  1860. // } else {
  1861. // c.ServeSuccessJSON(map[string]interface{}{
  1862. // "failed_code": -10,
  1863. // "msg": res.Transreturnmessage,
  1864. // })
  1865. // return
  1866. // }
  1867. //
  1868. // } else {
  1869. // //异地就医流程
  1870. // //异地走鉴权流程
  1871. // //authResult := CardAuth(number)
  1872. // //fmt.Println(authResult)
  1873. //
  1874. // //tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  1875. // //if tempPatient.ID == patient_id {
  1876. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  1877. // var dat map[string]interface{}
  1878. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1879. // fmt.Println(dat)
  1880. // } else {
  1881. // fmt.Println(err)
  1882. // }
  1883. //
  1884. // userJSONBytes, _ := json.Marshal(dat)
  1885. //
  1886. // var res ResultOne
  1887. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1888. // utils.ErrorLog("解析失败:%v", err)
  1889. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1890. // return
  1891. // }
  1892. // if res.Transreturncode == "00000000" {
  1893. // his := models.VMHisPatient{
  1894. // Name: name,
  1895. // Gender: gender,
  1896. // Birthday: birthUnix,
  1897. // MedicalTreatmentType: medical_care,
  1898. // IdType: certificates,
  1899. // IdCardNo: id_card,
  1900. // BalanceAccountsType: settlementValue,
  1901. // SocialType: social_type,
  1902. // MedicalInsuranceNumber: medical_insurance_card,
  1903. // RegisterType: register_type,
  1904. // RegisterCost: registration_fee,
  1905. // TreatmentCost: medical_expenses,
  1906. // Status: 1,
  1907. // Ctime: time.Now().Unix(),
  1908. // Mtime: time.Now().Unix(),
  1909. // Iinfo: resp_result,
  1910. // PatientId: patient.ID,
  1911. // RecordDate: theTime.Unix(),
  1912. // UserOrgId: adminInfo.CurrentOrgId,
  1913. // AdminUserId: admin_user_id,
  1914. // IsReturn: 1,
  1915. // IdCardType: id_card_type,
  1916. // Doctor: doctor,
  1917. // Departments: department,
  1918. // YiliaoNumber: yiliao_number,
  1919. // MzNumber: number,
  1920. // Number: mz_number,
  1921. // }
  1922. // service.CreateHisPatientTwo(&his)
  1923. // c.ServeSuccessJSON(map[string]interface{}{
  1924. // "msg": "挂号成功",
  1925. // })
  1926. // } else {
  1927. // c.ServeSuccessJSON(map[string]interface{}{
  1928. // "failed_code": -10,
  1929. // "msg": res.Transreturnmessage,
  1930. // })
  1931. // return
  1932. // }
  1933. //
  1934. // }
  1935. //
  1936. // } else { //异地卡流程
  1937. // //readCardBasResult := ReadCardBasHSM(number)
  1938. // //fmt.Println(readCardBasResult)
  1939. // //是否异地就医,是的话走鉴权流程,不是的话走门诊挂号
  1940. // if is_yidi == 1 { //1本地就医
  1941. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  1942. // var dat map[string]interface{}
  1943. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1944. // fmt.Println(dat)
  1945. // } else {
  1946. // fmt.Println(err)
  1947. // }
  1948. //
  1949. // userJSONBytes, _ := json.Marshal(dat)
  1950. //
  1951. // var res ResultOne
  1952. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1953. // utils.ErrorLog("解析失败:%v", err)
  1954. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1955. // return
  1956. // }
  1957. // if res.Transreturncode == "00000000" {
  1958. // his := models.VMHisPatient{
  1959. // Name: name,
  1960. // Gender: gender,
  1961. // Birthday: birthUnix,
  1962. // MedicalTreatmentType: medical_care,
  1963. // IdType: certificates,
  1964. // IdCardNo: id_card,
  1965. // BalanceAccountsType: settlementValue,
  1966. // SocialType: social_type,
  1967. // MedicalInsuranceNumber: medical_insurance_card,
  1968. // RegisterType: register_type,
  1969. // RegisterCost: registration_fee,
  1970. // TreatmentCost: medical_expenses,
  1971. // Status: 1,
  1972. // Ctime: time.Now().Unix(),
  1973. // Mtime: time.Now().Unix(),
  1974. // Iinfo: resp_result,
  1975. // PatientId: patient.ID,
  1976. // RecordDate: theTime.Unix(),
  1977. // UserOrgId: adminInfo.CurrentOrgId,
  1978. // AdminUserId: admin_user_id,
  1979. // IsReturn: 1,
  1980. // IdCardType: id_card_type,
  1981. // Doctor: doctor,
  1982. // Departments: department,
  1983. // YiliaoNumber: yiliao_number,
  1984. // MzNumber: number,
  1985. // Number: mz_number,
  1986. // }
  1987. // service.CreateHisPatientTwo(&his)
  1988. // c.ServeSuccessJSON(map[string]interface{}{
  1989. // "msg": "挂号成功",
  1990. // })
  1991. // } else {
  1992. // c.ServeSuccessJSON(map[string]interface{}{
  1993. // "failed_code": -10,
  1994. // "msg": res.Transreturnmessage,
  1995. // })
  1996. // return
  1997. // }
  1998. //
  1999. // } else { //异地就医需要走鉴权流程
  2000. // //authResult := CardAuth(number)
  2001. // //fmt.Println(authResult)
  2002. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  2003. // var dat map[string]interface{}
  2004. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  2005. // fmt.Println(dat)
  2006. // } else {
  2007. // fmt.Println(err)
  2008. // }
  2009. //
  2010. // userJSONBytes, _ := json.Marshal(dat)
  2011. //
  2012. // var res ResultOne
  2013. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2014. // utils.ErrorLog("解析失败:%v", err)
  2015. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2016. // return
  2017. // }
  2018. // if res.Transreturncode == "00000000" {
  2019. // his := models.VMHisPatient{
  2020. // Name: name,
  2021. // Gender: gender,
  2022. // Birthday: birthUnix,
  2023. // MedicalTreatmentType: medical_care,
  2024. // IdType: certificates,
  2025. // IdCardNo: id_card,
  2026. // BalanceAccountsType: settlementValue,
  2027. // SocialType: social_type,
  2028. // MedicalInsuranceNumber: medical_insurance_card,
  2029. // RegisterType: register_type,
  2030. // RegisterCost: registration_fee,
  2031. // TreatmentCost: medical_expenses,
  2032. // Status: 1,
  2033. // Ctime: time.Now().Unix(),
  2034. // Mtime: time.Now().Unix(),
  2035. // Iinfo: resp_result,
  2036. // PatientId: patient.ID,
  2037. // RecordDate: theTime.Unix(),
  2038. // UserOrgId: adminInfo.CurrentOrgId,
  2039. // AdminUserId: admin_user_id,
  2040. // IsReturn: 1,
  2041. // IdCardType: id_card_type,
  2042. // Doctor: doctor,
  2043. // Departments: department,
  2044. // YiliaoNumber: yiliao_number,
  2045. // MzNumber: number,
  2046. // Number: mz_number,
  2047. // }
  2048. // service.CreateHisPatientTwo(&his)
  2049. // c.ServeSuccessJSON(map[string]interface{}{
  2050. // "msg": "挂号成功",
  2051. // })
  2052. // } else {
  2053. // c.ServeSuccessJSON(map[string]interface{}{
  2054. // "failed_code": -10,
  2055. // "msg": res.Transreturnmessage,
  2056. // })
  2057. // return
  2058. // }
  2059. //
  2060. // }
  2061. // }
  2062. // } else {
  2063. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  2064. // return
  2065. // }
  2066. // } else {
  2067. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2068. // return
  2069. // }
  2070. //}q
  2071. //上传明细----结算----确认订单
  2072. func (c *SZHisApiController) GetSettleInfo() {
  2073. pay_way, _ := c.GetInt64("pay_way")
  2074. pay_price, _ := c.GetFloat("pay_price")
  2075. pay_card_no := c.GetString("pay_card_no")
  2076. discount_price, _ := c.GetFloat("discount_price")
  2077. preferential_price, _ := c.GetFloat("preferential_price")
  2078. reality_price, _ := c.GetFloat("reality_price")
  2079. found_price, _ := c.GetFloat("found_price")
  2080. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2081. private_price, _ := c.GetFloat("private_price")
  2082. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2083. patient_id, _ := c.GetInt64("id")
  2084. record_time := c.GetString("record_time")
  2085. admin_user_id, _ := c.GetInt64("admin_user_id")
  2086. his_patient_id, _ := c.GetInt64("his_patient_id")
  2087. id_str := c.GetString("ids")
  2088. ids_arr := strings.Split(id_str, ",")
  2089. order_id, _ := c.GetInt64("order_id")
  2090. sick_type, _ := c.GetInt64("sick_type")
  2091. reg_type, _ := c.GetInt64("p_type")
  2092. timestamp := time.Now().Unix()
  2093. tempTime := time.Unix(timestamp, 0)
  2094. timeFormat := tempTime.Format("20060102150405")
  2095. chrgBchno := rand.Intn(10000) + 1000
  2096. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(1, 10)
  2097. adminUser := c.GetAdminUserInfo()
  2098. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2099. month := time.Unix(1557042972, 0).Format("1")
  2100. year := time.Now().Format("2006")
  2101. month = time.Now().Format("01")
  2102. day := time.Now().Format("02")
  2103. timeLayout := "2006-01-02"
  2104. loc, _ := time.LoadLocation("Local")
  2105. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2106. fmt.Println(err)
  2107. if err != nil {
  2108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2109. return
  2110. }
  2111. recordDateTime := theTime.Unix()
  2112. his, err := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2113. //tempOrder, _ := service.GetNewHisOrderThree(or)
  2114. tempOrder, _ := service.GetHisOrderByID(order_id)
  2115. if tempOrder.ID == 0 {
  2116. var prescriptions []*models.HisPrescription
  2117. var start_time int64
  2118. var end_time int64
  2119. if settle_accounts_type == 1 { //日结
  2120. if reg_type == 11 {
  2121. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  2122. } else {
  2123. prescriptions, _ = service.GetNewHisPrescription(adminUser.CurrentOrgId, his_patient_id, recordDateTime, strconv.Itoa(int(reg_type)))
  2124. }
  2125. } else { //月结
  2126. start_time_str := c.GetString("start_time")
  2127. end_time_str := c.GetString("end_time")
  2128. timeLayout := "2006-01-02"
  2129. loc, _ := time.LoadLocation("Local")
  2130. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2131. if err != nil {
  2132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2133. return
  2134. }
  2135. recordStartTime := theStartTime.Unix()
  2136. start_time = recordStartTime
  2137. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2138. if err != nil {
  2139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2140. return
  2141. }
  2142. recordEndTime := theEndTime.Unix()
  2143. end_time = recordEndTime
  2144. prescriptions, _ = service.GetMonthHisPrescriptionTwo(adminUser.CurrentOrgId, patient_id, recordStartTime, recordEndTime, his.MedicalTreatmentType)
  2145. }
  2146. var ids []int64
  2147. for _, item := range prescriptions {
  2148. ids = append(ids, item.ID)
  2149. }
  2150. patientPrescription, _ := service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2151. sick, _ := service.FindSickById(sick_type)
  2152. if sick.ID == 0 {
  2153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamSickTypeWrong)
  2154. return
  2155. }
  2156. adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  2157. adminRole, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2158. mz_number := his.Number
  2159. number := miConfig.Code + year + month + day +
  2160. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  2161. var doctor_name string
  2162. var doctor_code string
  2163. var drug_doctor_code string
  2164. drug_doctor_code = adminRole_two.DoctorCode
  2165. drug_doctor_name := adminRole_two.UserName
  2166. if adminRole.ID == 0 {
  2167. doctor_name = "管理员"
  2168. doctor_code = "01"
  2169. } else {
  2170. doctor_name = adminRole.UserName
  2171. doctor_code = strconv.FormatInt(admin_user_id, 10)
  2172. }
  2173. verifyCode, version_code := ReadCardGetCode("FY001" + "|" + number + "|" + miConfig.Code)
  2174. //verifyCode := "000000|bf885fa312a7f92861d6b61542a637fa"
  2175. //version_code := "V0.3"
  2176. var customs []*models.CustomDetail
  2177. for _, item := range prescriptions {
  2178. if item.Type == 1 { //药品
  2179. for _, subItem := range item.HisDoctorAdviceInfo {
  2180. fmt.Println(subItem.BaseDrugLib.MedicalInsuranceNumber)
  2181. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 {
  2182. _, dose_code := service.GetDoseCode(subItem.BaseDrugLib.DrugDosageForm, adminUser.CurrentOrgId)
  2183. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber), 64)
  2184. price, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price), 64)
  2185. temp := strings.Split(subItem.FeedetlSn, "-")
  2186. newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  2187. fmt.Println(111111111)
  2188. fmt.Println(subItem.BaseDrugLib.Code)
  2189. fmt.Println(222222222)
  2190. cus := &models.CustomDetail{
  2191. PrescriptionNumber: chrg_bchno,
  2192. OrderType: "1",
  2193. ChargeSerialNumber: newFl,
  2194. Code: subItem.BaseDrugLib.MedicalInsuranceNumber,
  2195. CodeName: subItem.BaseDrugLib.DrugName,
  2196. BwCode: subItem.BaseDrugLib.Code,
  2197. Flag: "1",
  2198. Price: price,
  2199. Count: subItem.PrescribingNumber,
  2200. ChargeOrderDate: year + month + day,
  2201. DoctorCode: doctor_code,
  2202. Total: detItemFeeSumamt,
  2203. DoseCode: dose_code,
  2204. Spec: strconv.Itoa(int(subItem.BaseDrugLib.MinNumber)) + subItem.BaseDrugLib.MinUnit + ":" + fmt.Sprintf("%.2f", subItem.BaseDrugLib.Dose) + subItem.BaseDrugLib.DoseUnit,
  2205. Unit: subItem.PrescribingNumberUnit,
  2206. }
  2207. customs = append(customs, cus)
  2208. }
  2209. }
  2210. }
  2211. if item.Type == 2 { //项目
  2212. for _, subItem := range item.HisPrescriptionProject {
  2213. if len(subItem.HisProject.MedicalCode) > 0 {
  2214. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  2215. //count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  2216. count, _ := strconv.ParseFloat(strconv.FormatInt(subItem.Count, 10), 64)
  2217. temp := strings.Split(subItem.FeedetlSn, "-")
  2218. newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  2219. if subItem.Type == 2 {
  2220. cus := &models.CustomDetail{
  2221. PrescriptionNumber: chrg_bchno,
  2222. OrderType: "1",
  2223. ChargeSerialNumber: newFl,
  2224. Code: subItem.HisProject.MedicalCode,
  2225. BwCode: subItem.HisProject.MedicalCode,
  2226. CodeName: subItem.HisProject.ProjectName,
  2227. Flag: "1",
  2228. Price: subItem.Price,
  2229. Count: count,
  2230. ChargeOrderDate: year + month + day,
  2231. DoctorCode: doctor_code,
  2232. Total: detItemFeeSumamt,
  2233. DoseCode: "",
  2234. Spec: "次",
  2235. Unit: "次",
  2236. }
  2237. customs = append(customs, cus)
  2238. }
  2239. }
  2240. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 {
  2241. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  2242. //count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  2243. count, _ := strconv.ParseFloat(strconv.FormatInt(subItem.Count, 10), 64)
  2244. temp := strings.Split(subItem.FeedetlSn, "-")
  2245. newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  2246. if subItem.Type == 3 {
  2247. cus := &models.CustomDetail{
  2248. PrescriptionNumber: chrg_bchno,
  2249. OrderType: "1",
  2250. ChargeSerialNumber: newFl,
  2251. Code: subItem.GoodInfo.MedicalInsuranceNumber,
  2252. CodeName: subItem.GoodInfo.GoodName,
  2253. BwCode: subItem.GoodInfo.MedicalInsuranceNumber,
  2254. Flag: "1",
  2255. Price: subItem.Price,
  2256. Count: count,
  2257. ChargeOrderDate: year + month + day,
  2258. DoctorCode: doctor_code,
  2259. Total: detItemFeeSumamt,
  2260. DoseCode: "",
  2261. Spec: "支",
  2262. Unit: "支",
  2263. }
  2264. customs = append(customs, cus)
  2265. }
  2266. }
  2267. }
  2268. }
  2269. //
  2270. //for _, subItem := range item.HisAdditionalCharge {
  2271. // if len(subItem.XtHisAddtionConfig.Code) > 0 {
  2272. // detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  2273. //
  2274. // count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  2275. // cus := &models.CustomDetail{
  2276. // PrescriptionNumber: chrg_bchno,
  2277. // OrderType: "1",
  2278. // ChargeSerialNumber: subItem.FeedetlSn,
  2279. // Code: subItem.XtHisAddtionConfig.Code,
  2280. // CodeName: subItem.XtHisAddtionConfig.Name,
  2281. // Flag: "1",
  2282. // Price: subItem.Price,
  2283. // Count: count,
  2284. // ChargeOrderDate: year + month + day,
  2285. // DoctorCode: doctor_code,
  2286. // Total: detItemFeeSumamt,
  2287. // DoseCode: "",
  2288. // Spec: subItem.XtHisAddtionConfig.,
  2289. // }
  2290. // customs = append(customs, cus)
  2291. // }
  2292. //}
  2293. }
  2294. var pagesize int = 50
  2295. var start int = 1
  2296. var stop int
  2297. var pagecount int
  2298. var curpage int
  2299. var isSuccess bool = true
  2300. //总页数,向上取整,注意除之前要先转换类型为float64
  2301. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  2302. var ress []*Result
  2303. for curpage = 1; curpage <= pagecount; curpage++ {
  2304. if curpage == 1 {
  2305. start = 1
  2306. } else {
  2307. start = (curpage-1)*pagesize + 1
  2308. }
  2309. stop = curpage * pagesize
  2310. if stop > len(customs) {
  2311. stop = len(customs)
  2312. }
  2313. result := service.SzybFY001(doctor_name, doctor_code, miConfig.Code, customs[start-1:stop], verifyCode, number, mz_number, version_code, drug_doctor_code)
  2314. fmt.Println(result)
  2315. var dat map[string]interface{}
  2316. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2317. fmt.Println(dat)
  2318. } else {
  2319. fmt.Println(err)
  2320. }
  2321. userJSONBytes, _ := json.Marshal(dat)
  2322. var res Result
  2323. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2324. utils.ErrorLog("解析失败:%v", err)
  2325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2326. return
  2327. }
  2328. if res.Transreturncode == "00000000" {
  2329. ress = append(ress, &res)
  2330. } else {
  2331. isSuccess = false
  2332. errlog := &models.HisOrderError{
  2333. UserOrgId: adminUser.CurrentOrgId,
  2334. Ctime: time.Now().Unix(),
  2335. Mtime: time.Now().Unix(),
  2336. Number: chrg_bchno,
  2337. ErrMsg: res.Transreturnmessage,
  2338. Status: 1,
  2339. PatientId: patient_id,
  2340. RecordTime: recordDateTime,
  2341. Stage: 4,
  2342. }
  2343. service.CreateErrMsgLog(errlog)
  2344. c.ServeSuccessJSON(map[string]interface{}{
  2345. "failed_code": -10,
  2346. "msg": res.Transreturnmessage,
  2347. })
  2348. return
  2349. }
  2350. //设置变量,根据变量的值来判断上传是否成功
  2351. }
  2352. if isSuccess == true {
  2353. order := &models.HisOrder{
  2354. UserOrgId: adminUser.CurrentOrgId,
  2355. HisPatientId: 0,
  2356. PatientId: patient_id,
  2357. SettleAccountsDate: recordDateTime,
  2358. Ctime: time.Now().Unix(),
  2359. Mtime: time.Now().Unix(),
  2360. Status: 0,
  2361. Number: chrg_bchno,
  2362. Infcode: 0,
  2363. WarnMsg: "",
  2364. Cainfo: "",
  2365. ErrMsg: "",
  2366. RespondTime: "",
  2367. InfRefmsgid: "",
  2368. OrderStatus: 1,
  2369. IsMedicineInsurance: 1,
  2370. SettleType: settle_accounts_type,
  2371. SettleStartTime: start_time,
  2372. SettleEndTime: end_time,
  2373. Creator: admin_user_id,
  2374. Modify: admin_user_id,
  2375. OrgSetlNumber: number,
  2376. MdtrtId: mz_number,
  2377. PType: 2,
  2378. }
  2379. data, _ := json.Marshal(ress)
  2380. order.DetailLog = string(data)
  2381. err = service.CreateOrder(order)
  2382. if err != nil {
  2383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2384. return
  2385. }
  2386. for _, subItem := range ress {
  2387. for _, item := range subItem.Transbody.Outputlist {
  2388. temp := strings.Split(item.Bkf500, "-")
  2389. var advice_id int64 = 0
  2390. var project_id int64 = 0
  2391. var types int64 = 0
  2392. id, _ := strconv.ParseInt(temp[2], 10, 64)
  2393. types, _ = strconv.ParseInt(temp[1], 10, 64)
  2394. if temp[1] == "1" {
  2395. advice_id = id
  2396. project_id = 0
  2397. } else if temp[1] == "2" {
  2398. advice_id = 0
  2399. project_id = id
  2400. }
  2401. info := &models.HisOrderInfo{
  2402. OrderNumber: order.Number,
  2403. FeedetlSn: item.Bkf500,
  2404. UploadDate: time.Now().Unix(),
  2405. AdviceId: advice_id,
  2406. DetItemFeeSumamt: item.Akc264,
  2407. Cnt: item.Akc226,
  2408. Pric: float64(item.Akc225),
  2409. PatientId: patient_id,
  2410. Status: 1,
  2411. ChrgitmLv: item.Aka065,
  2412. Mtime: time.Now().Unix(),
  2413. Ctime: time.Now().Unix(),
  2414. UserOrgId: adminUser.CurrentOrgId,
  2415. OrderId: order.ID,
  2416. ProjectId: project_id,
  2417. Type: types,
  2418. OverPricPsnPay: item.Akc268,
  2419. AllowReimburse: item.Cka319,
  2420. }
  2421. service.CreateOrderInfo(info)
  2422. }
  2423. }
  2424. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2425. service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, his_patient_id, chrg_bchno, recordDateTime)
  2426. var total float64
  2427. for _, item := range prescriptions {
  2428. if item.Type == 1 { //药品
  2429. for _, subItem := range item.HisDoctorAdviceInfo {
  2430. total = total + (subItem.Price * subItem.PrescribingNumber)
  2431. }
  2432. }
  2433. if item.Type == 2 { //项目
  2434. for _, subItem := range item.HisPrescriptionProject {
  2435. total = total + (subItem.Price * float64(subItem.Count))
  2436. }
  2437. }
  2438. }
  2439. for _, item := range prescriptions {
  2440. for _, subItem := range item.HisAdditionalCharge {
  2441. total = total + (subItem.Price * float64(subItem.Count))
  2442. }
  2443. }
  2444. total, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", total), 64)
  2445. new_number := miConfig.Code + year + month + day +
  2446. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  2447. yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("FY005" + "|" + new_number + "|" + miConfig.Code + "|")
  2448. if ret4 == 0 {
  2449. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  2450. tempPatient, _ := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  2451. if tempPatient.ID == patient_id {
  2452. result_three := service.SzybFY005(doctor_name, doctor_code, miConfig.Code, total, yiliao_number, verifyCode, number, mz_number, version_code, drug_doctor_code, drug_doctor_name, reg_type, sick.CountryCode, new_number)
  2453. var dat map[string]interface{}
  2454. if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  2455. fmt.Println(dat)
  2456. } else {
  2457. fmt.Println(err)
  2458. }
  2459. userJSONBytes, _ := json.Marshal(dat)
  2460. var res ResultTwo
  2461. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2462. utils.ErrorLog("解析失败:%v", err)
  2463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2464. return
  2465. }
  2466. if res.Transreturncode == "00000000" {
  2467. order.OrderStatus = 2
  2468. order.Status = 1
  2469. order.PayWay = pay_way
  2470. order.PayPrice = pay_price
  2471. order.PayCardNo = pay_card_no
  2472. order.PsnNo = health_card_no
  2473. order.DiscountPrice = discount_price
  2474. order.PreferentialPrice = preferential_price
  2475. order.RealityPrice = reality_price
  2476. order.FoundPrice = found_price
  2477. order.MedicalInsurancePrice = medical_insurance_price
  2478. order.PrivatePrice = private_price
  2479. order.Modify = admin_user_id
  2480. order.MedfeeSumamt = res.Transbody.Akc264
  2481. order.SetlId = res.Transbody.Ckc618
  2482. order.FundPaySumamt = res.Transbody.Akb068
  2483. order.AcctPay = res.Transbody.Akb066
  2484. order.PsnCashPay = res.Transbody.Akb067
  2485. order.PsnPartAmt = res.Transbody.Akb067
  2486. order.AccountPrice = res.Transbody.Aae240
  2487. order.MedType = strconv.Itoa(int(reg_type))
  2488. order.MzNumber = mz_number
  2489. order.MdtrtId = mz_number
  2490. order.YiliaoNumber = yiliao_number
  2491. setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  2492. detailStrOne := string(setlDetailOne)
  2493. order.SzChargeInfo = detailStrOne
  2494. setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  2495. detailStrTwo := string(setlDetailTwo)
  2496. order.SzProjectInfo = detailStrTwo
  2497. setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  2498. detailStrThree := string(setlDetailThree)
  2499. order.SzMedicineInsuranceInfo = detailStrThree
  2500. order.Cainfo = result_three
  2501. err = service.UpdataOrderStatusTwo(order.Number, adminUser.CurrentOrgId)
  2502. err = service.UpDateOrderTwo(order)
  2503. c.ServeSuccessJSON(map[string]interface{}{
  2504. "msg": "结算成功",
  2505. })
  2506. } else {
  2507. //结算报错
  2508. errlog := &models.HisOrderError{
  2509. UserOrgId: adminUser.CurrentOrgId,
  2510. Ctime: time.Now().Unix(),
  2511. Mtime: time.Now().Unix(),
  2512. Number: chrg_bchno,
  2513. ErrMsg: res.Transreturnmessage,
  2514. Status: 1,
  2515. PatientId: patient_id,
  2516. RecordTime: recordDateTime,
  2517. Stage: 6,
  2518. }
  2519. service.CreateErrMsgLog(errlog)
  2520. c.ServeSuccessJSON(map[string]interface{}{
  2521. "failed_code": -10,
  2522. "msg": res.Transreturnmessage,
  2523. })
  2524. }
  2525. } else {
  2526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  2527. return
  2528. }
  2529. } else {
  2530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  2531. return
  2532. }
  2533. } else {
  2534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePreSettleFaildParamWrong)
  2535. return
  2536. }
  2537. } else {
  2538. if tempOrder.OrderStatus == 1 && tempOrder.IsPre == 1 {
  2539. pay_way, _ := c.GetInt64("pay_way")
  2540. pay_price, _ := c.GetFloat("pay_price")
  2541. pay_card_no := c.GetString("pay_card_no")
  2542. discount_price, _ := c.GetFloat("discount_price")
  2543. preferential_price, _ := c.GetFloat("preferential_price")
  2544. reality_price, _ := c.GetFloat("reality_price")
  2545. found_price, _ := c.GetFloat("found_price")
  2546. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2547. private_price, _ := c.GetFloat("private_price")
  2548. patient_id, _ := c.GetInt64("id")
  2549. record_time := c.GetString("record_time")
  2550. admin_user_id, _ := c.GetInt64("admin_user_id")
  2551. order_id, _ := c.GetInt64("order_id")
  2552. his_patient_id, _ := c.GetInt64("his_patient_id")
  2553. timestamp := time.Now().Unix()
  2554. tempTime := time.Unix(timestamp, 0)
  2555. timeFormat := tempTime.Format("20060102150405")
  2556. chrgBchno := rand.Intn(10000) + 1000
  2557. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(1, 10)
  2558. adminUser := c.GetAdminUserInfo()
  2559. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2560. month := time.Unix(1557042972, 0).Format("1")
  2561. year := time.Now().Format("2006")
  2562. month = time.Now().Format("01")
  2563. day := time.Now().Format("02")
  2564. timeLayout := "2006-01-02"
  2565. loc, _ := time.LoadLocation("Local")
  2566. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2567. fmt.Println(err)
  2568. if err != nil {
  2569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2570. return
  2571. }
  2572. recordDateTime := theTime.Unix()
  2573. patientPrescription, _ := service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2574. sick, _ := service.FindSickById(patientPrescription.SickType)
  2575. if sick.ID == 0 {
  2576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamSickTypeWrong)
  2577. return
  2578. }
  2579. adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  2580. adminRole, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2581. his, err := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2582. mz_number := his.Number
  2583. number := miConfig.Code + year + month + day +
  2584. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  2585. var doctor_name string
  2586. var doctor_code string
  2587. var drug_doctor_code string
  2588. drug_doctor_code = adminRole_two.DoctorCode
  2589. drug_doctor_name := adminRole_two.UserName
  2590. if adminRole.ID == 0 {
  2591. doctor_name = "管理员"
  2592. doctor_code = "01"
  2593. } else {
  2594. doctor_name = adminRole.UserName
  2595. doctor_code = strconv.FormatInt(admin_user_id, 10)
  2596. }
  2597. order, _ := service.GetHisOrderByID(order_id)
  2598. if order.ID == 0 {
  2599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  2600. return
  2601. }
  2602. yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("FY005" + "|" + number + "|" + miConfig.Code + "|")
  2603. if ret4 == 0 {
  2604. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  2605. tempPatient, _ := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  2606. if tempPatient.ID == patient_id {
  2607. result_three := service.SzybFY005(doctor_name, doctor_code, miConfig.Code, order.MedfeeSumamt, yiliao_number, verifyCode, order.OrgSetlNumber, mz_number, version_code, drug_doctor_code, drug_doctor_name, reg_type, sick.CountryCode, number)
  2608. var dat map[string]interface{}
  2609. if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  2610. fmt.Println(dat)
  2611. } else {
  2612. fmt.Println(err)
  2613. }
  2614. userJSONBytes, _ := json.Marshal(dat)
  2615. var res ResultTwo
  2616. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2617. utils.ErrorLog("解析失败:%v", err)
  2618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2619. return
  2620. }
  2621. if res.Transreturncode == "00000000" {
  2622. order.OrderStatus = 2
  2623. order.Status = 1
  2624. order.PayWay = pay_way
  2625. order.PayPrice = pay_price
  2626. order.PayCardNo = pay_card_no
  2627. order.PsnNo = health_card_no
  2628. order.DiscountPrice = discount_price
  2629. order.PreferentialPrice = preferential_price
  2630. order.RealityPrice = reality_price
  2631. order.FoundPrice = found_price
  2632. order.MedicalInsurancePrice = medical_insurance_price
  2633. order.PrivatePrice = private_price
  2634. order.Modify = admin_user_id
  2635. order.MedfeeSumamt = res.Transbody.Akc264
  2636. order.SetlId = res.Transbody.Ckc618
  2637. order.FundPaySumamt = res.Transbody.Akb068
  2638. order.AcctPay = res.Transbody.Akb066
  2639. order.PsnCashPay = res.Transbody.Akb067
  2640. order.PsnPartAmt = res.Transbody.Akb067
  2641. order.AccountPrice = res.Transbody.Aae240
  2642. order.MzNumber = mz_number
  2643. order.YiliaoNumber = yiliao_number
  2644. setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  2645. detailStrOne := string(setlDetailOne)
  2646. order.SzChargeInfo = detailStrOne
  2647. setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  2648. detailStrTwo := string(setlDetailTwo)
  2649. order.SzProjectInfo = detailStrTwo
  2650. setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  2651. detailStrThree := string(setlDetailThree)
  2652. order.SzMedicineInsuranceInfo = detailStrThree
  2653. order.Cainfo = result_three
  2654. err = service.UpdataOrderStatusTwo(order.Number, adminUser.CurrentOrgId)
  2655. err = service.UpDateOrderTwo(&order)
  2656. c.ServeSuccessJSON(map[string]interface{}{
  2657. "msg": "结算成功",
  2658. })
  2659. } else {
  2660. //结算报错
  2661. errlog := &models.HisOrderError{
  2662. UserOrgId: adminUser.CurrentOrgId,
  2663. Ctime: time.Now().Unix(),
  2664. Mtime: time.Now().Unix(),
  2665. Number: chrg_bchno,
  2666. ErrMsg: res.Transreturnmessage,
  2667. Status: 1,
  2668. PatientId: patient_id,
  2669. RecordTime: recordDateTime,
  2670. Stage: 6,
  2671. }
  2672. service.CreateErrMsgLog(errlog)
  2673. c.ServeSuccessJSON(map[string]interface{}{
  2674. "failed_code": -10,
  2675. "msg": res.Transreturnmessage,
  2676. })
  2677. }
  2678. } else {
  2679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  2680. return
  2681. }
  2682. } else {
  2683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  2684. return
  2685. }
  2686. } else {
  2687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  2688. return
  2689. }
  2690. }
  2691. }
  2692. //结算
  2693. //func (c *SZHisApiController) GetSettleInfo() {
  2694. // pay_way, _ := c.GetInt64("pay_way")
  2695. // pay_price, _ := c.GetFloat("pay_price")
  2696. // pay_card_no := c.GetString("pay_card_no")
  2697. // discount_price, _ := c.GetFloat("discount_price")
  2698. // preferential_price, _ := c.GetFloat("preferential_price")
  2699. // reality_price, _ := c.GetFloat("reality_price")
  2700. // found_price, _ := c.GetFloat("found_price")
  2701. // medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2702. // private_price, _ := c.GetFloat("private_price")
  2703. // patient_id, _ := c.GetInt64("id")
  2704. // record_time := c.GetString("record_time")
  2705. // admin_user_id, _ := c.GetInt64("admin_user_id")
  2706. // order_id, _ := c.GetInt64("order_id")
  2707. // his_patient_id, _ := c.GetInt64("his_patient_id")
  2708. //
  2709. // timestamp := time.Now().Unix()
  2710. // tempTime := time.Unix(timestamp, 0)
  2711. // timeFormat := tempTime.Format("20060102150405")
  2712. // chrgBchno := rand.Intn(10000) + 1000
  2713. // chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(1, 10)
  2714. // adminUser := c.GetAdminUserInfo()
  2715. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2716. // month := time.Unix(1557042972, 0).Format("1")
  2717. // year := time.Now().Format("2006")
  2718. // month = time.Now().Format("01")
  2719. // day := time.Now().Format("02")
  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. // fmt.Println(err)
  2725. // if err != nil {
  2726. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2727. // return
  2728. // }
  2729. // recordDateTime := theTime.Unix()
  2730. //
  2731. // patientPrescription, _ := service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2732. //
  2733. // sick, _ := service.FindSickById(patientPrescription.SickType)
  2734. //
  2735. // if sick.ID == 0 {
  2736. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamSickTypeWrong)
  2737. // return
  2738. // }
  2739. //
  2740. // adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  2741. //
  2742. // adminRole, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2743. // his, err := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2744. // mz_number := his.Number
  2745. // number := miConfig.Code + year + month + day +
  2746. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  2747. // var doctor_name string
  2748. // var doctor_code string
  2749. // var drug_doctor_code string
  2750. // drug_doctor_code = adminRole_two.DoctorCode
  2751. // drug_doctor_name := adminRole_two.UserName
  2752. //
  2753. // if adminRole.ID == 0 {
  2754. // doctor_name = "管理员"
  2755. // doctor_code = "01"
  2756. // } else {
  2757. // doctor_name = adminRole.UserName
  2758. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  2759. // }
  2760. //
  2761. // order, _ := service.GetHisOrderByID(order_id)
  2762. // if order.ID == 0 {
  2763. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  2764. // return
  2765. // }
  2766. //
  2767. // yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("FY005" + "|" + number + "|" + miConfig.Code + "|")
  2768. // if ret4 == 0 {
  2769. // //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  2770. // tempPatient, _ := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  2771. // if tempPatient.ID == patient_id {
  2772. // result_three := service.SzybFY005(doctor_name, doctor_code, miConfig.Code, order.MedfeeSumamt, yiliao_number, verifyCode, number, mz_number, version_code, drug_doctor_code, drug_doctor_name, his.MedicalTreatmentType, sick.CountryCode)
  2773. // var dat map[string]interface{}
  2774. // if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  2775. // fmt.Println(dat)
  2776. // } else {
  2777. // fmt.Println(err)
  2778. // }
  2779. // userJSONBytes, _ := json.Marshal(dat)
  2780. // var res ResultTwo
  2781. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2782. // utils.ErrorLog("解析失败:%v", err)
  2783. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2784. // return
  2785. // }
  2786. //
  2787. // if res.Transreturncode == "00000000" {
  2788. // order.OrderStatus = 2
  2789. // order.Status = 1
  2790. // order.PayWay = pay_way
  2791. // order.PayPrice = pay_price
  2792. // order.PayCardNo = pay_card_no
  2793. // order.PsnNo = health_card_no
  2794. // order.DiscountPrice = discount_price
  2795. // order.PreferentialPrice = preferential_price
  2796. // order.RealityPrice = reality_price
  2797. // order.FoundPrice = found_price
  2798. // order.MedicalInsurancePrice = medical_insurance_price
  2799. // order.PrivatePrice = private_price
  2800. // order.Modify = admin_user_id
  2801. // order.MedfeeSumamt = res.Transbody.Akc264
  2802. // order.SetlId = res.Transbody.Ckc618
  2803. // order.FundPaySumamt = res.Transbody.Akb068
  2804. // order.AcctPay = res.Transbody.Akb066
  2805. // order.PsnCashPay = res.Transbody.Akb067
  2806. // order.PsnPartAmt = res.Transbody.Akb067
  2807. // order.AccountPrice = res.Transbody.Aae240
  2808. // order.MzNumber = mz_number
  2809. // order.YiliaoNumber = yiliao_number
  2810. // setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  2811. // detailStrOne := string(setlDetailOne)
  2812. // order.SzChargeInfo = detailStrOne
  2813. // setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  2814. // detailStrTwo := string(setlDetailTwo)
  2815. // order.SzProjectInfo = detailStrTwo
  2816. // setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  2817. // detailStrThree := string(setlDetailThree)
  2818. // order.SzMedicineInsuranceInfo = detailStrThree
  2819. // order.Cainfo = result_three
  2820. // err = service.UpdataOrderStatusTwo(order.Number, adminUser.CurrentOrgId)
  2821. // err = service.UpDateOrderTwo(&order)
  2822. // c.ServeSuccessJSON(map[string]interface{}{
  2823. // "msg": "结算成功",
  2824. // })
  2825. // } else {
  2826. // //结算报错
  2827. // errlog := &models.HisOrderError{
  2828. // UserOrgId: adminUser.CurrentOrgId,
  2829. // Ctime: time.Now().Unix(),
  2830. // Mtime: time.Now().Unix(),
  2831. // Number: chrg_bchno,
  2832. // ErrMsg: res.Transreturnmessage,
  2833. // Status: 1,
  2834. // PatientId: patient_id,
  2835. // RecordTime: recordDateTime,
  2836. // Stage: 6,
  2837. // }
  2838. // service.CreateErrMsgLog(errlog)
  2839. // c.ServeSuccessJSON(map[string]interface{}{
  2840. // "failed_code": -10,
  2841. // "msg": res.Transreturnmessage,
  2842. // })
  2843. // }
  2844. // } else {
  2845. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  2846. // return
  2847. // }
  2848. // } else {
  2849. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  2850. // return
  2851. // }
  2852. //}
  2853. //上传明细----预结算
  2854. func (c *SZHisApiController) GetPreSettleInfo() {
  2855. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2856. patient_id, _ := c.GetInt64("id")
  2857. record_time := c.GetString("record_time")
  2858. admin_user_id, _ := c.GetInt64("admin_user_id")
  2859. his_patient_id, _ := c.GetInt64("his_patient_id")
  2860. reg_type, _ := c.GetInt64("p_type")
  2861. sick_type, _ := c.GetInt64("sick_type")
  2862. id_str := c.GetString("ids")
  2863. ids_arr := strings.Split(id_str, ",")
  2864. timestamp := time.Now().Unix()
  2865. tempTime := time.Unix(timestamp, 0)
  2866. timeFormat := tempTime.Format("20060102150405")
  2867. chrgBchno := rand.Intn(10000) + 1000
  2868. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(1, 10)
  2869. adminUser := c.GetAdminUserInfo()
  2870. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2871. month := time.Unix(1557042972, 0).Format("1")
  2872. year := time.Now().Format("2006")
  2873. month = time.Now().Format("01")
  2874. day := time.Now().Format("02")
  2875. timeLayout := "2006-01-02"
  2876. loc, _ := time.LoadLocation("Local")
  2877. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2878. fmt.Println(err)
  2879. if err != nil {
  2880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2881. return
  2882. }
  2883. recordDateTime := theTime.Unix()
  2884. var prescriptions []*models.HisPrescription
  2885. var start_time int64
  2886. var end_time int64
  2887. if settle_accounts_type == 1 { //日结
  2888. if reg_type == 11 {
  2889. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  2890. } else {
  2891. prescriptions, _ = service.GetNewHisPrescription(adminUser.CurrentOrgId, his_patient_id, recordDateTime, strconv.Itoa(int(reg_type)))
  2892. }
  2893. } else { //月结
  2894. start_time_str := c.GetString("start_time")
  2895. end_time_str := c.GetString("end_time")
  2896. timeLayout := "2006-01-02"
  2897. loc, _ := time.LoadLocation("Local")
  2898. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2899. if err != nil {
  2900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2901. return
  2902. }
  2903. recordStartTime := theStartTime.Unix()
  2904. start_time = recordStartTime
  2905. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2906. if err != nil {
  2907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2908. return
  2909. }
  2910. recordEndTime := theEndTime.Unix()
  2911. end_time = recordEndTime
  2912. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, patient_id, recordStartTime, recordEndTime, strconv.Itoa(int(reg_type)))
  2913. }
  2914. var ids []int64
  2915. for _, item := range prescriptions {
  2916. ids = append(ids, item.ID)
  2917. }
  2918. patientPrescription, _ := service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2919. sick, _ := service.FindSickById(sick_type)
  2920. if sick.ID == 0 {
  2921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamSickTypeWrong)
  2922. return
  2923. }
  2924. adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  2925. adminRole, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2926. his, err := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2927. mz_number := his.Number
  2928. number := miConfig.Code + year + month + day +
  2929. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  2930. var doctor_name string
  2931. var doctor_code string
  2932. var drug_doctor_code string
  2933. drug_doctor_code = adminRole_two.DoctorCode
  2934. drug_doctor_name := adminRole_two.UserName
  2935. if adminRole.ID == 0 {
  2936. doctor_name = "管理员"
  2937. doctor_code = "01"
  2938. } else {
  2939. doctor_name = adminRole.UserName
  2940. doctor_code = strconv.FormatInt(admin_user_id, 10)
  2941. }
  2942. verifyCode, version_code := ReadCardGetCode("FY001" + "|" + number + "|" + miConfig.Code)
  2943. var customs []*models.CustomDetail
  2944. for _, item := range prescriptions {
  2945. if item.Type == 1 { //药品
  2946. for _, subItem := range item.HisDoctorAdviceInfo {
  2947. fmt.Println(subItem.BaseDrugLib.MedicalInsuranceNumber)
  2948. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 {
  2949. _, dose_code := service.GetDoseCode(subItem.BaseDrugLib.DrugDosageForm, adminUser.CurrentOrgId)
  2950. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber), 64)
  2951. price, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price), 64)
  2952. temp := strings.Split(subItem.FeedetlSn, "-")
  2953. newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  2954. cus := &models.CustomDetail{
  2955. PrescriptionNumber: chrg_bchno,
  2956. OrderType: "1",
  2957. ChargeSerialNumber: newFl,
  2958. Code: subItem.BaseDrugLib.MedicalInsuranceNumber,
  2959. BwCode: subItem.BaseDrugLib.Code,
  2960. CodeName: subItem.BaseDrugLib.DrugName,
  2961. Flag: "1",
  2962. Price: price,
  2963. Count: subItem.PrescribingNumber,
  2964. ChargeOrderDate: year + month + day,
  2965. DoctorCode: doctor_code,
  2966. Total: detItemFeeSumamt,
  2967. DoseCode: dose_code,
  2968. Spec: strconv.Itoa(int(subItem.BaseDrugLib.MinNumber)) + subItem.BaseDrugLib.MinUnit + ":" + fmt.Sprintf("%.2f", subItem.BaseDrugLib.Dose) + subItem.BaseDrugLib.DoseUnit,
  2969. Unit: subItem.PrescribingNumberUnit,
  2970. }
  2971. customs = append(customs, cus)
  2972. }
  2973. }
  2974. }
  2975. if item.Type == 2 { //项目
  2976. for _, subItem := range item.HisPrescriptionProject {
  2977. if len(subItem.HisProject.MedicalCode) > 0 {
  2978. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  2979. //count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  2980. count, _ := strconv.ParseFloat(strconv.FormatInt(subItem.Count, 10), 64)
  2981. temp := strings.Split(subItem.FeedetlSn, "-")
  2982. newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  2983. if subItem.Type == 2 {
  2984. cus := &models.CustomDetail{
  2985. PrescriptionNumber: chrg_bchno,
  2986. OrderType: "1",
  2987. ChargeSerialNumber: newFl,
  2988. Code: subItem.HisProject.MedicalCode,
  2989. CodeName: subItem.HisProject.ProjectName,
  2990. BwCode: subItem.HisProject.MedicalCode,
  2991. Flag: "1",
  2992. Price: subItem.Price,
  2993. Count: count,
  2994. ChargeOrderDate: year + month + day,
  2995. DoctorCode: doctor_code,
  2996. Total: detItemFeeSumamt,
  2997. DoseCode: "",
  2998. Spec: "次",
  2999. Unit: "次",
  3000. }
  3001. customs = append(customs, cus)
  3002. }
  3003. }
  3004. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 {
  3005. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  3006. //count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  3007. count, _ := strconv.ParseFloat(strconv.FormatInt(subItem.Count, 10), 64)
  3008. temp := strings.Split(subItem.FeedetlSn, "-")
  3009. newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  3010. if subItem.Type == 3 {
  3011. cus := &models.CustomDetail{
  3012. PrescriptionNumber: chrg_bchno,
  3013. OrderType: "1",
  3014. ChargeSerialNumber: newFl,
  3015. Code: subItem.GoodInfo.MedicalInsuranceNumber,
  3016. BwCode: subItem.GoodInfo.MedicalInsuranceNumber,
  3017. CodeName: subItem.GoodInfo.GoodName,
  3018. Flag: "1",
  3019. Price: subItem.Price,
  3020. Count: count,
  3021. ChargeOrderDate: year + month + day,
  3022. DoctorCode: doctor_code,
  3023. Total: detItemFeeSumamt,
  3024. DoseCode: "",
  3025. Spec: "支",
  3026. Unit: "支",
  3027. }
  3028. customs = append(customs, cus)
  3029. }
  3030. }
  3031. }
  3032. }
  3033. //
  3034. //for _, subItem := range item.HisAdditionalCharge {
  3035. // if len(subItem.XtHisAddtionConfig.Code) > 0 {
  3036. // detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  3037. //
  3038. // count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  3039. // cus := &models.CustomDetail{
  3040. // PrescriptionNumber: chrg_bchno,
  3041. // OrderType: "1",
  3042. // ChargeSerialNumber: subItem.FeedetlSn,
  3043. // Code: subItem.XtHisAddtionConfig.Code,
  3044. // CodeName: subItem.XtHisAddtionConfig.Name,
  3045. // Flag: "1",
  3046. // Price: subItem.Price,
  3047. // Count: count,
  3048. // ChargeOrderDate: year + month + day,
  3049. // DoctorCode: doctor_code,
  3050. // Total: detItemFeeSumamt,
  3051. // DoseCode: "",
  3052. // Spec: subItem.XtHisAddtionConfig.,
  3053. // }
  3054. // customs = append(customs, cus)
  3055. // }
  3056. //}
  3057. }
  3058. var pagesize int = 50
  3059. var start int = 1
  3060. var stop int
  3061. var pagecount int
  3062. var curpage int
  3063. var isSuccess bool = true
  3064. //总页数,向上取整,注意除之前要先转换类型为float64
  3065. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  3066. var ress []*Result
  3067. for curpage = 1; curpage <= pagecount; curpage++ {
  3068. if curpage == 1 {
  3069. start = 1
  3070. } else {
  3071. start = (curpage-1)*pagesize + 1
  3072. }
  3073. stop = curpage * pagesize
  3074. if stop > len(customs) {
  3075. stop = len(customs)
  3076. }
  3077. result := service.SzybFY001(doctor_name, doctor_code, miConfig.Code, customs[start-1:stop], verifyCode, number, mz_number, version_code, drug_doctor_code)
  3078. fmt.Println(result)
  3079. var dat map[string]interface{}
  3080. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3081. fmt.Println(dat)
  3082. } else {
  3083. fmt.Println(err)
  3084. }
  3085. userJSONBytes, _ := json.Marshal(dat)
  3086. var res Result
  3087. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3088. utils.ErrorLog("解析失败:%v", err)
  3089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3090. return
  3091. }
  3092. if res.Transreturncode == "00000000" {
  3093. ress = append(ress, &res)
  3094. } else {
  3095. isSuccess = false
  3096. errlog := &models.HisOrderError{
  3097. UserOrgId: adminUser.CurrentOrgId,
  3098. Ctime: time.Now().Unix(),
  3099. Mtime: time.Now().Unix(),
  3100. Number: chrg_bchno,
  3101. ErrMsg: res.Transreturnmessage,
  3102. Status: 1,
  3103. PatientId: patient_id,
  3104. RecordTime: recordDateTime,
  3105. Stage: 4,
  3106. }
  3107. service.CreateErrMsgLog(errlog)
  3108. c.ServeSuccessJSON(map[string]interface{}{
  3109. "failed_code": -10,
  3110. "msg": res.Transreturnmessage,
  3111. })
  3112. return
  3113. }
  3114. //设置变量,根据变量的值来判断上传是否成功
  3115. }
  3116. if isSuccess == true {
  3117. order := &models.HisOrder{
  3118. UserOrgId: adminUser.CurrentOrgId,
  3119. HisPatientId: 0,
  3120. PatientId: patient_id,
  3121. SettleAccountsDate: recordDateTime,
  3122. Ctime: time.Now().Unix(),
  3123. Mtime: time.Now().Unix(),
  3124. Status: 0,
  3125. Number: chrg_bchno,
  3126. Infcode: 0,
  3127. WarnMsg: "",
  3128. Cainfo: "",
  3129. ErrMsg: "",
  3130. RespondTime: "",
  3131. InfRefmsgid: "",
  3132. OrderStatus: 1,
  3133. IsMedicineInsurance: 1,
  3134. MedType: strconv.Itoa(int(reg_type)),
  3135. SettleType: settle_accounts_type,
  3136. SettleStartTime: start_time,
  3137. SettleEndTime: end_time,
  3138. Creator: admin_user_id,
  3139. Modify: admin_user_id,
  3140. OrgSetlNumber: number,
  3141. MdtrtId: mz_number,
  3142. PType: 2,
  3143. }
  3144. data, _ := json.Marshal(ress)
  3145. order.DetailLog = string(data)
  3146. err = service.CreateOrder(order)
  3147. if err != nil {
  3148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  3149. return
  3150. }
  3151. for _, subItem := range ress {
  3152. for _, item := range subItem.Transbody.Outputlist {
  3153. temp := strings.Split(item.Bkf500, "-")
  3154. var advice_id int64 = 0
  3155. var project_id int64 = 0
  3156. var types int64 = 0
  3157. id, _ := strconv.ParseInt(temp[2], 10, 64)
  3158. types, _ = strconv.ParseInt(temp[1], 10, 64)
  3159. if temp[1] == "1" {
  3160. advice_id = id
  3161. project_id = 0
  3162. } else if temp[1] == "2" {
  3163. advice_id = 0
  3164. project_id = id
  3165. }
  3166. info := &models.HisOrderInfo{
  3167. OrderNumber: order.Number,
  3168. FeedetlSn: item.Bkf500,
  3169. UploadDate: time.Now().Unix(),
  3170. AdviceId: advice_id,
  3171. DetItemFeeSumamt: item.Akc264,
  3172. Cnt: item.Akc226,
  3173. Pric: float64(item.Akc225),
  3174. PatientId: patient_id,
  3175. Status: 1,
  3176. ChrgitmLv: item.Aka065,
  3177. Mtime: time.Now().Unix(),
  3178. Ctime: time.Now().Unix(),
  3179. UserOrgId: adminUser.CurrentOrgId,
  3180. OrderId: order.ID,
  3181. ProjectId: project_id,
  3182. Type: types,
  3183. OverPricPsnPay: item.Akc268,
  3184. AllowReimburse: item.Cka319,
  3185. }
  3186. service.CreateOrderInfo(info)
  3187. }
  3188. }
  3189. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  3190. service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, his_patient_id, chrg_bchno, recordDateTime)
  3191. var total float64
  3192. for _, item := range prescriptions {
  3193. if item.Type == 1 { //药品
  3194. for _, subItem := range item.HisDoctorAdviceInfo {
  3195. total = total + (subItem.Price * subItem.PrescribingNumber)
  3196. }
  3197. }
  3198. if item.Type == 2 { //项目
  3199. for _, subItem := range item.HisPrescriptionProject {
  3200. total = total + (subItem.Price * float64(subItem.Count))
  3201. }
  3202. }
  3203. }
  3204. for _, item := range prescriptions {
  3205. for _, subItem := range item.HisAdditionalCharge {
  3206. total = total + (subItem.Price * float64(subItem.Count))
  3207. }
  3208. }
  3209. total, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", total), 64)
  3210. new_number := miConfig.Code + year + month + day +
  3211. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  3212. yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("FY004" + "|" + new_number + "|" + miConfig.Code + "|")
  3213. if ret4 == 0 {
  3214. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  3215. tempPatient, _ := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  3216. if tempPatient.ID == patient_id {
  3217. result_three := service.SzybFY004(doctor_name, doctor_code, miConfig.Code, total, yiliao_number, verifyCode, number, mz_number, version_code, drug_doctor_code, drug_doctor_name, reg_type, sick.CountryCode, new_number)
  3218. var dat map[string]interface{}
  3219. if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  3220. fmt.Println(dat)
  3221. } else {
  3222. fmt.Println(err)
  3223. }
  3224. userJSONBytes, _ := json.Marshal(dat)
  3225. var res ResultTwo
  3226. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3227. utils.ErrorLog("解析失败:%v", err)
  3228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3229. return
  3230. }
  3231. if res.Transreturncode == "00000000" {
  3232. order.OrderStatus = 1
  3233. order.Status = 1
  3234. order.PsnNo = health_card_no
  3235. order.Modify = admin_user_id
  3236. order.MedfeeSumamt = res.Transbody.Akc264
  3237. order.FundPaySumamt = res.Transbody.Akb068
  3238. order.AcctPay = res.Transbody.Akb066
  3239. order.PsnCashPay = res.Transbody.Akb067
  3240. order.PsnPartAmt = res.Transbody.Akb067
  3241. order.AccountPrice = res.Transbody.Aae240
  3242. order.MzNumber = mz_number
  3243. order.YiliaoNumber = yiliao_number
  3244. setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  3245. detailStrOne := string(setlDetailOne)
  3246. order.SzChargeInfo = detailStrOne
  3247. setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  3248. detailStrTwo := string(setlDetailTwo)
  3249. order.SzProjectInfo = detailStrTwo
  3250. setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  3251. detailStrThree := string(setlDetailThree)
  3252. order.SzMedicineInsuranceInfo = detailStrThree
  3253. order.Cainfo = result_three
  3254. order.IsPre = 1
  3255. //err = service.UpdataOrderStatusTwo(order.Number, adminUser.CurrentOrgId)
  3256. err = service.UpDateOrderTwo(order)
  3257. c.ServeSuccessJSON(map[string]interface{}{
  3258. "msg": "预结算成功",
  3259. })
  3260. } else {
  3261. //预结算报错
  3262. errlog := &models.HisOrderError{
  3263. UserOrgId: adminUser.CurrentOrgId,
  3264. Ctime: time.Now().Unix(),
  3265. Mtime: time.Now().Unix(),
  3266. Number: chrg_bchno,
  3267. ErrMsg: res.Transreturnmessage,
  3268. Status: 1,
  3269. PatientId: patient_id,
  3270. RecordTime: recordDateTime,
  3271. Stage: 20,
  3272. }
  3273. service.CreateErrMsgLog(errlog)
  3274. c.ServeSuccessJSON(map[string]interface{}{
  3275. "failed_code": -10,
  3276. "msg": res.Transreturnmessage,
  3277. })
  3278. }
  3279. } else {
  3280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  3281. return
  3282. }
  3283. } else {
  3284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  3285. return
  3286. }
  3287. } else {
  3288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePreSettleFaildParamWrong)
  3289. return
  3290. }
  3291. }
  3292. //func (c *SZHisApiController) GetSettleInfo() {
  3293. // pay_way, _ := c.GetInt64("pay_way")
  3294. // pay_price, _ := c.GetFloat("pay_price")
  3295. // pay_card_no := c.GetString("pay_card_no")
  3296. // discount_price, _ := c.GetFloat("discount_price")
  3297. // preferential_price, _ := c.GetFloat("preferential_price")
  3298. // reality_price, _ := c.GetFloat("reality_price")
  3299. // found_price, _ := c.GetFloat("found_price")
  3300. // medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  3301. // private_price, _ := c.GetFloat("private_price")
  3302. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  3303. // patient_id, _ := c.GetInt64("id")
  3304. // record_time := c.GetString("record_time")
  3305. // admin_user_id, _ := c.GetInt64("admin_user_id")
  3306. // timestamp := time.Now().Unix()
  3307. // tempTime := time.Unix(timestamp, 0)
  3308. // timeFormat := tempTime.Format("20060102150405")
  3309. // chrgBchno := rand.Intn(10000) + 1000
  3310. // chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(1, 10)
  3311. // adminUser := c.GetAdminUserInfo()
  3312. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3313. // month := time.Unix(1557042972, 0).Format("1")
  3314. // year := time.Now().Format("2006")
  3315. // month = time.Now().Format("01")
  3316. // day := time.Now().Format("02")
  3317. //
  3318. // timeLayout := "2006-01-02"
  3319. // loc, _ := time.LoadLocation("Local")
  3320. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3321. // fmt.Println(err)
  3322. // if err != nil {
  3323. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3324. // return
  3325. // }
  3326. // recordDateTime := theTime.Unix()
  3327. //
  3328. // var prescriptions []*models.HisPrescription
  3329. //
  3330. // var start_time int64
  3331. // var end_time int64
  3332. //
  3333. // if settle_accounts_type == 1 { //日结
  3334. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3335. //
  3336. // } else { //月结
  3337. // start_time_str := c.GetString("start_time")
  3338. // end_time_str := c.GetString("end_time")
  3339. // timeLayout := "2006-01-02"
  3340. // loc, _ := time.LoadLocation("Local")
  3341. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3342. // if err != nil {
  3343. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3344. // return
  3345. // }
  3346. // recordStartTime := theStartTime.Unix()
  3347. // start_time = recordStartTime
  3348. //
  3349. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3350. // if err != nil {
  3351. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3352. // return
  3353. // }
  3354. // recordEndTime := theEndTime.Unix()
  3355. // end_time = recordEndTime
  3356. //
  3357. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
  3358. // }
  3359. //
  3360. // var ids []int64
  3361. // for _, item := range prescriptions {
  3362. // ids = append(ids, item.ID)
  3363. // }
  3364. //
  3365. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3366. //
  3367. // adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  3368. //
  3369. // adminRole, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3370. // his, err := service.GetHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3371. // mz_number := his.Number
  3372. // number := miConfig.Code + year + month + day +
  3373. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  3374. // var doctor_name string
  3375. // var doctor_code string
  3376. // var drug_doctor_code string
  3377. // drug_doctor_code = adminRole_two.DoctorCode
  3378. // drug_doctor_name := adminRole_two.UserName
  3379. //
  3380. // if adminRole.ID == 0 {
  3381. // doctor_name = "黄亦轩"
  3382. // doctor_code = "1"
  3383. // } else {
  3384. // doctor_name = adminRole.UserName
  3385. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  3386. // }
  3387. //
  3388. // verifyCode, version_code := ReadCardGetCode("FY001" + "|" + number + "|" + miConfig.Code)
  3389. // //verifyCode := "000000|bf885fa312a7f92861d6b61542a637fa"
  3390. // //version_code := "V0.3"
  3391. // var customs []*models.CustomDetail
  3392. // for _, item := range prescriptions {
  3393. // if item.Type == 1 { //药品
  3394. // for _, subItem := range item.HisDoctorAdviceInfo {
  3395. // fmt.Println(subItem.BaseDrugLib.MedicalInsuranceNumber)
  3396. //
  3397. // if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 {
  3398. // _, dose_code := service.GetDoseCode(subItem.BaseDrugLib.DrugDosageForm, adminUser.CurrentOrgId)
  3399. // detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber), 64)
  3400. // price, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price), 64)
  3401. // temp := strings.Split(subItem.FeedetlSn, "-")
  3402. // newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  3403. //
  3404. // cus := &models.CustomDetail{
  3405. // PrescriptionNumber: chrg_bchno,
  3406. // OrderType: "1",
  3407. // ChargeSerialNumber: newFl,
  3408. // Code: subItem.BaseDrugLib.MedicalInsuranceNumber,
  3409. // CodeName: subItem.BaseDrugLib.DrugName,
  3410. // Flag: "1",
  3411. // Price: price,
  3412. // Count: subItem.PrescribingNumber,
  3413. // ChargeOrderDate: year + month + day,
  3414. // DoctorCode: doctor_code,
  3415. // Total: detItemFeeSumamt,
  3416. // DoseCode: dose_code,
  3417. // Spec: subItem.BaseDrugLib.DrugSpec,
  3418. // }
  3419. // customs = append(customs, cus)
  3420. // }
  3421. // }
  3422. // }
  3423. //
  3424. // if item.Type == 2 { //项目
  3425. // for _, subItem := range item.HisPrescriptionProject {
  3426. // if len(subItem.HisProject.MedicalCode) > 0 {
  3427. // detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  3428. //
  3429. // count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  3430. // temp := strings.Split(subItem.FeedetlSn, "-")
  3431. // newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  3432. //
  3433. // cus := &models.CustomDetail{
  3434. // PrescriptionNumber: chrg_bchno,
  3435. // OrderType: "1",
  3436. // ChargeSerialNumber: newFl,
  3437. // Code: subItem.HisProject.MedicalCode,
  3438. // CodeName: subItem.HisProject.ProjectName,
  3439. // Flag: "1",
  3440. // Price: subItem.Price,
  3441. // Count: count,
  3442. // ChargeOrderDate: year + month + day,
  3443. // DoctorCode: doctor_code,
  3444. // Total: detItemFeeSumamt,
  3445. // DoseCode: "",
  3446. // Spec: "次",
  3447. // }
  3448. // customs = append(customs, cus)
  3449. // }
  3450. // }
  3451. // }
  3452. // //
  3453. // //for _, subItem := range item.HisAdditionalCharge {
  3454. // // if len(subItem.XtHisAddtionConfig.Code) > 0 {
  3455. // // detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  3456. // //
  3457. // // count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  3458. // // cus := &models.CustomDetail{
  3459. // // PrescriptionNumber: chrg_bchno,
  3460. // // OrderType: "1",
  3461. // // ChargeSerialNumber: subItem.FeedetlSn,
  3462. // // Code: subItem.XtHisAddtionConfig.Code,
  3463. // // CodeName: subItem.XtHisAddtionConfig.Name,
  3464. // // Flag: "1",
  3465. // // Price: subItem.Price,
  3466. // // Count: count,
  3467. // // ChargeOrderDate: year + month + day,
  3468. // // DoctorCode: doctor_code,
  3469. // // Total: detItemFeeSumamt,
  3470. // // DoseCode: "",
  3471. // // Spec: subItem.XtHisAddtionConfig.,
  3472. // // }
  3473. // // customs = append(customs, cus)
  3474. // // }
  3475. // //}
  3476. // }
  3477. //
  3478. // var pagesize int = 50
  3479. // var start int = 1
  3480. // var stop int
  3481. // var pagecount int
  3482. // var curpage int
  3483. // var isSuccess bool = true
  3484. // //总页数,向上取整,注意除之前要先转换类型为float64
  3485. // pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  3486. //
  3487. // var ress []*Result
  3488. // for curpage = 1; curpage <= pagecount; curpage++ {
  3489. // if curpage == 1 {
  3490. // start = 1
  3491. // } else {
  3492. // start = (curpage-1)*pagesize + 1
  3493. // }
  3494. // stop = curpage * pagesize
  3495. // if stop > len(customs) {
  3496. // stop = len(customs)
  3497. // }
  3498. // result := service.SzybFY001(doctor_name, doctor_code, miConfig.Code, customs[start-1:stop], verifyCode, number, mz_number, version_code, drug_doctor_code)
  3499. // fmt.Println(result)
  3500. //
  3501. // var dat map[string]interface{}
  3502. // if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3503. // fmt.Println(dat)
  3504. // } else {
  3505. // fmt.Println(err)
  3506. // }
  3507. //
  3508. // userJSONBytes, _ := json.Marshal(dat)
  3509. //
  3510. // var res Result
  3511. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3512. // utils.ErrorLog("解析失败:%v", err)
  3513. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3514. // return
  3515. // }
  3516. // if res.Transreturncode == "00000000" {
  3517. // ress = append(ress, &res)
  3518. // } else {
  3519. // isSuccess = false
  3520. // errlog := &models.HisOrderError{
  3521. // UserOrgId: adminUser.CurrentOrgId,
  3522. // Ctime: time.Now().Unix(),
  3523. // Mtime: time.Now().Unix(),
  3524. // Number: chrg_bchno,
  3525. // ErrMsg: res.Transreturnmessage,
  3526. // Status: 1,
  3527. // PatientId: patient_id,
  3528. // RecordTime: recordDateTime,
  3529. // Stage: 4,
  3530. // }
  3531. // service.CreateErrMsgLog(errlog)
  3532. // c.ServeSuccessJSON(map[string]interface{}{
  3533. // "failed_code": -10,
  3534. // "msg": res.Transreturnmessage,
  3535. // })
  3536. // return
  3537. // }
  3538. // //设置变量,根据变量的值来判断上传是否成功
  3539. // }
  3540. // if isSuccess == true {
  3541. // order := &models.HisOrder{
  3542. // UserOrgId: adminUser.CurrentOrgId,
  3543. // HisPatientId: 0,
  3544. // PatientId: patient_id,
  3545. // SettleAccountsDate: recordDateTime,
  3546. // Ctime: time.Now().Unix(),
  3547. // Mtime: time.Now().Unix(),
  3548. // Status: 1,
  3549. // Number: chrg_bchno,
  3550. // Infcode: 0,
  3551. // WarnMsg: "",
  3552. // Cainfo: "",
  3553. // ErrMsg: "",
  3554. // RespondTime: "",
  3555. // InfRefmsgid: "",
  3556. // OrderStatus: 1,
  3557. // IsMedicineInsurance: 1,
  3558. // SettleType: settle_accounts_type,
  3559. // SettleStartTime: start_time,
  3560. // SettleEndTime: end_time,
  3561. // Creator: admin_user_id,
  3562. // Modify: admin_user_id,
  3563. // OrgSetlNumber: number,
  3564. // }
  3565. // data, _ := json.Marshal(ress)
  3566. // order.DetailLog = string(data)
  3567. //
  3568. // err = service.CreateOrder(order)
  3569. // if err != nil {
  3570. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  3571. // return
  3572. // }
  3573. //
  3574. // for _, subItem := range ress {
  3575. // for _, item := range subItem.Transbody.Outputlist {
  3576. //
  3577. // temp := strings.Split(item.Bkf500, "-")
  3578. // var advice_id int64 = 0
  3579. // var project_id int64 = 0
  3580. // var types int64 = 0
  3581. //
  3582. // id, _ := strconv.ParseInt(temp[2], 10, 64)
  3583. // types, _ = strconv.ParseInt(temp[1], 10, 64)
  3584. //
  3585. // if temp[1] == "1" {
  3586. // advice_id = id
  3587. // project_id = 0
  3588. // } else if temp[1] == "2" {
  3589. // advice_id = 0
  3590. // project_id = id
  3591. // }
  3592. //
  3593. // info := &models.HisOrderInfo{
  3594. // OrderNumber: order.Number,
  3595. // FeedetlSn: item.Bkf500,
  3596. // UploadDate: time.Now().Unix(),
  3597. // AdviceId: advice_id,
  3598. // DetItemFeeSumamt: item.Akc264,
  3599. // Cnt: item.Akc226,
  3600. // Pric: float64(item.Akc225),
  3601. // PatientId: patient_id,
  3602. // Status: 1,
  3603. // ChrgitmLv: item.Aka065,
  3604. // Mtime: time.Now().Unix(),
  3605. // Ctime: time.Now().Unix(),
  3606. // UserOrgId: adminUser.CurrentOrgId,
  3607. // OrderId: order.ID,
  3608. // ProjectId: project_id,
  3609. // Type: types,
  3610. //
  3611. // OverPricPsnPay: item.Akc268,
  3612. // AllowReimburse: item.Cka319,
  3613. // }
  3614. // service.CreateOrderInfo(info)
  3615. //
  3616. // }
  3617. // }
  3618. // service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  3619. // service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patient_id, chrg_bchno, recordDateTime)
  3620. // var total float64
  3621. // for _, item := range prescriptions {
  3622. // if item.Type == 1 { //药品
  3623. // for _, subItem := range item.HisDoctorAdviceInfo {
  3624. // total = total + (subItem.Price * subItem.PrescribingNumber)
  3625. // }
  3626. // }
  3627. // if item.Type == 2 { //项目
  3628. // for _, subItem := range item.HisPrescriptionProject {
  3629. // total = total + (subItem.Price * float64(subItem.Count))
  3630. // }
  3631. // }
  3632. // }
  3633. // for _, item := range prescriptions {
  3634. // for _, subItem := range item.HisAdditionalCharge {
  3635. // total = total + (subItem.Price * float64(subItem.Count))
  3636. // }
  3637. // }
  3638. //
  3639. // yiliao_number, id_card_number, verifyCode, version_code, _, ret4 := ReadBasCardGetNumber("FY005" + "|" + number + "|" + miConfig.Code + "|")
  3640. // if ret4 == 0 {
  3641. // //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  3642. // tempPatient, _ := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  3643. // if tempPatient.ID == patient_id {
  3644. //
  3645. // result_three := service.SzybFY005(doctor_name, doctor_code, miConfig.Code, total, yiliao_number, verifyCode, number, mz_number, version_code, drug_doctor_code, drug_doctor_name, his.MedicalTreatmentType)
  3646. // var dat map[string]interface{}
  3647. // if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  3648. // fmt.Println(dat)
  3649. // } else {
  3650. // fmt.Println(err)
  3651. // }
  3652. // userJSONBytes, _ := json.Marshal(dat)
  3653. // var res ResultTwo
  3654. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3655. // utils.ErrorLog("解析失败:%v", err)
  3656. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3657. // return
  3658. // }
  3659. //
  3660. // if res.Transreturncode == "00000000" {
  3661. // order.OrderStatus = 2
  3662. // order.PayWay = pay_way
  3663. // order.PayPrice = pay_price
  3664. // order.PayCardNo = pay_card_no
  3665. // order.DiscountPrice = discount_price
  3666. // order.PreferentialPrice = preferential_price
  3667. // order.RealityPrice = reality_price
  3668. // order.FoundPrice = found_price
  3669. // order.MedicalInsurancePrice = medical_insurance_price
  3670. // order.PrivatePrice = private_price
  3671. // order.Modify = admin_user_id
  3672. // order.MedfeeSumamt = res.Transbody.Akc264
  3673. // order.SetlId = res.Transbody.Ckc618
  3674. // order.FundPaySumamt = res.Transbody.Akb068
  3675. // order.AcctPay = res.Transbody.Akb066
  3676. // order.PsnCashPay = res.Transbody.Akb067
  3677. // order.PsnPartAmt = res.Transbody.Akb067
  3678. // order.AccountPrice = res.Transbody.Aae240
  3679. // order.MzNumber = mz_number
  3680. // order.YiliaoNumber = yiliao_number
  3681. // setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  3682. // detailStrOne := string(setlDetailOne)
  3683. // order.SzChargeInfo = detailStrOne
  3684. // setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  3685. // detailStrTwo := string(setlDetailTwo)
  3686. // order.SzProjectInfo = detailStrTwo
  3687. // setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  3688. // detailStrThree := string(setlDetailThree)
  3689. // order.SzMedicineInsuranceInfo = detailStrThree
  3690. // order.Cainfo = result_three
  3691. // err = service.UpdataOrderStatusTwo(order.Number, adminUser.CurrentOrgId)
  3692. // err = service.UpDateOrderTwo(order)
  3693. // c.ServeSuccessJSON(map[string]interface{}{
  3694. // "msg": "结算成功",
  3695. // })
  3696. // } else {
  3697. // //结算报错
  3698. // errlog := &models.HisOrderError{
  3699. // UserOrgId: adminUser.CurrentOrgId,
  3700. // Ctime: time.Now().Unix(),
  3701. // Mtime: time.Now().Unix(),
  3702. // Number: chrg_bchno,
  3703. // ErrMsg: res.Transreturnmessage,
  3704. // Status: 1,
  3705. // PatientId: patient_id,
  3706. // RecordTime: recordDateTime,
  3707. // Stage: 6,
  3708. // }
  3709. // service.CreateErrMsgLog(errlog)
  3710. // c.ServeSuccessJSON(map[string]interface{}{
  3711. // "failed_code": -10,
  3712. // "msg": res.Transreturnmessage,
  3713. // })
  3714. // }
  3715. // } else {
  3716. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  3717. // return
  3718. // }
  3719. // } else {
  3720. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  3721. // return
  3722. // }
  3723. // } else {
  3724. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePreSettleFaildParamWrong)
  3725. // return
  3726. // }
  3727. //}
  3728. //结算
  3729. //func (c *SZHisApiController) GetSettleInfo() {
  3730. // patient_id, _ := c.GetInt64("id")
  3731. // order_id, _ := c.GetInt64("order_id")
  3732. // record_time := c.GetString("record_time")
  3733. // pay_way, _ := c.GetInt64("pay_way")
  3734. // pay_price, _ := c.GetFloat("pay_price")
  3735. // pay_card_no := c.GetString("pay_card_no")
  3736. // discount_price, _ := c.GetFloat("discount_price")
  3737. // preferential_price, _ := c.GetFloat("preferential_price")
  3738. // reality_price, _ := c.GetFloat("reality_price")
  3739. // found_price, _ := c.GetFloat("found_price")
  3740. // medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  3741. // private_price, _ := c.GetFloat("private_price")
  3742. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  3743. // admin_user_id, _ := c.GetInt64("admin_user_id")
  3744. //
  3745. // timeLayout := "2006-01-02"
  3746. // loc, _ := time.LoadLocation("Local")
  3747. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3748. // if err != nil {
  3749. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3750. // return
  3751. // }
  3752. // recordDateTime := theTime.Unix()
  3753. // adminUser := c.GetAdminUserInfo()
  3754. //
  3755. // var prescriptions []*models.HisPrescription
  3756. //
  3757. // data := make(map[string]interface{})
  3758. // if settle_accounts_type == 1 { //日结
  3759. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3760. // data["pre"] = prescriptions
  3761. //
  3762. // } else { //月结
  3763. // start_time_str := c.GetString("start_time")
  3764. // end_time_str := c.GetString("end_time")
  3765. // timeLayout := "2006-01-02"
  3766. // loc, _ := time.LoadLocation("Local")
  3767. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3768. // if err != nil {
  3769. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3770. // return
  3771. // }
  3772. // recordStartTime := theStartTime.Unix()
  3773. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3774. // if err != nil {
  3775. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3776. // return
  3777. // }
  3778. // recordEndTime := theEndTime.Unix()
  3779. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
  3780. // data["pre"] = prescriptions
  3781. //
  3782. // }
  3783. //
  3784. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3785. // his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3786. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3787. // strconv.FormatInt(his.PatientId, 10)
  3788. //
  3789. // order_src, _ := service.GetHisOrderByID(order_id)
  3790. //
  3791. // if order_src.ID == 0 {
  3792. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  3793. // return
  3794. // }
  3795. //
  3796. // config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3797. // if config.IsOpen == 1 { //对接了医保,走医保流程
  3798. // if order_src.OrderStatus != 2 {
  3799. // var total float64
  3800. // for _, item := range prescriptions {
  3801. // if item.Type == 1 { //药品
  3802. // for _, subItem := range item.HisDoctorAdviceInfo {
  3803. // total = total + (subItem.Price * subItem.PrescribingNumber)
  3804. // }
  3805. // }
  3806. // if item.Type == 2 { //项目
  3807. // for _, subItem := range item.HisPrescriptionProject {
  3808. // total = total + (subItem.Price * float64(subItem.Count))
  3809. // }
  3810. // }
  3811. // }
  3812. //
  3813. // for _, item := range prescriptions {
  3814. // for _, subItem := range item.HisAdditionalCharge {
  3815. // total = total + (subItem.Price * float64(subItem.Count))
  3816. // }
  3817. // }
  3818. //
  3819. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3820. //
  3821. // adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  3822. //
  3823. // var drug_doctor string
  3824. // drug_doctor = adminRole_two.DoctorCode
  3825. // drug_doctor_name := adminRole_two.UserName
  3826. // //结算流程
  3827. // var doctor_name string
  3828. // var doctor_code string
  3829. // if roles.ID == 0 {
  3830. // doctor_name = "黄亦轩"
  3831. // doctor_code = "1010"
  3832. // } else {
  3833. // doctor_name = roles.UserName
  3834. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  3835. // }
  3836. // number := order_src.OrgSetlNumber
  3837. // mz_number := his.Number
  3838. // verifyCode, version_code := ReadCardGetCode("FY005" + "|" + number + "|" + miConfig.Code)
  3839. //
  3840. // //verifyCode := "000000|707c35a62c2f0609d7b0a811649f3913"
  3841. // //version_code := "V0.3"
  3842. // yiliao_number, id_card_number, verifyCode, version_code, err, ret4 := ReadBasCardGetNumber("FY005" + "|" + number + "|" + miConfig.Code)
  3843. // yiliao_number := his.YiliaoNumber
  3844. // result_three := service.SzybFY005(doctor_name, doctor_code, miConfig.Code, total, yiliao_number, verifyCode, number, mz_number, version_code, drug_doctor, drug_doctor_name)
  3845. // var dat map[string]interface{}
  3846. // if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  3847. // fmt.Println(dat)
  3848. // } else {
  3849. // fmt.Println(err)
  3850. // }
  3851. // userJSONBytes, _ := json.Marshal(dat)
  3852. // var res ResultTwo
  3853. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3854. // utils.ErrorLog("解析失败:%v", err)
  3855. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3856. // return
  3857. // }
  3858. //
  3859. // if res.Transreturncode == "00000000" {
  3860. // order_src.OrderStatus = 2
  3861. // order_src.PayWay = pay_way
  3862. // order_src.PayPrice = pay_price
  3863. // order_src.PayCardNo = pay_card_no
  3864. // order_src.DiscountPrice = discount_price
  3865. // order_src.PreferentialPrice = preferential_price
  3866. // order_src.RealityPrice = reality_price
  3867. // order_src.FoundPrice = found_price
  3868. // order_src.MedicalInsurancePrice = medical_insurance_price
  3869. // order_src.PrivatePrice = private_price
  3870. // order_src.Creator = order_src.Creator
  3871. // order_src.Modify = roles.ID
  3872. // order_src.MedfeeSumamt = res.Transbody.Akc264
  3873. // order_src.SetlId = res.Transbody.Ckc618
  3874. // order_src.FundPaySumamt = res.Transbody.Akb068
  3875. // order_src.AcctPay = res.Transbody.Akb066
  3876. // order_src.PsnCashPay = res.Transbody.Akb067
  3877. // order_src.PsnPartAmt = res.Transbody.Akb067
  3878. // order_src.AccountPrice = res.Transbody.Aae240
  3879. // order_src.MzNumber = mz_number
  3880. // order_src.YiliaoNumber = yiliao_number
  3881. // setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  3882. // detailStrOne := string(setlDetailOne)
  3883. // order_src.SzChargeInfo = detailStrOne
  3884. // setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  3885. // detailStrTwo := string(setlDetailTwo)
  3886. // order_src.SzProjectInfo = detailStrTwo
  3887. // setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  3888. // detailStrThree := string(setlDetailThree)
  3889. // order_src.SzMedicineInsuranceInfo = detailStrThree
  3890. // order_src.Cainfo = result_three
  3891. //
  3892. // err = service.UpdataOrderStatusTwo(order_src.Number, adminUser.CurrentOrgId)
  3893. // err = service.UpDateOrder(order_src)
  3894. //
  3895. // c.ServeSuccessJSON(map[string]interface{}{
  3896. // "msg": "结算成功",
  3897. // })
  3898. // } else {
  3899. // //version_code := "0.03"
  3900. // c.ServeSuccessJSON(map[string]interface{}{
  3901. // "failed_code": -10,
  3902. // "msg": res.Transreturnmessage,
  3903. // })
  3904. //
  3905. // }
  3906. // } else {
  3907. //
  3908. // //错误提示
  3909. //
  3910. // }
  3911. // } else {
  3912. // //错误提示
  3913. //
  3914. // }
  3915. //}
  3916. //当月退费
  3917. func (c *SZHisApiController) Refund() {
  3918. order_id, _ := c.GetInt64("order_id")
  3919. record_time := c.GetString("record_time")
  3920. //patient_id, _ := c.GetInt64("patient_id")
  3921. //his_patient_id, _ := c.GetInt64("his_patient_id")
  3922. admin_user_id, _ := c.GetInt64("admin_user_id")
  3923. timeLayout := "2006-01-02"
  3924. loc, _ := time.LoadLocation("Local")
  3925. adminUser := c.GetAdminUserInfo()
  3926. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3927. fmt.Println(err)
  3928. if err != nil {
  3929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3930. return
  3931. }
  3932. recordDateTime := theTime.Unix()
  3933. fmt.Println(recordDateTime)
  3934. var order models.HisOrder
  3935. order, _ = service.GetHisOrderByID(order_id)
  3936. if order.ID == 0 {
  3937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  3938. return
  3939. }
  3940. //his, _ := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, theTime.Unix())
  3941. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3942. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3943. //结算流程
  3944. var doctor_name string
  3945. var doctor_code string
  3946. if roles.ID == 0 {
  3947. doctor_name = "管理员"
  3948. doctor_code = "01"
  3949. } else {
  3950. doctor_name = roles.UserName
  3951. doctor_code = strconv.FormatInt(admin_user_id, 10)
  3952. }
  3953. month := time.Unix(1557042972, 0).Format("1")
  3954. year := time.Now().Format("2006")
  3955. month = time.Now().Format("01")
  3956. day := time.Now().Format("02")
  3957. //number := miConfig.Code + year + month + day + "1367866"
  3958. number := miConfig.Code + year + month + day +
  3959. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  3960. //number := miConfig.Code + year + month + day + "1590003"
  3961. //流水号
  3962. //number_two := miConfig.Code + "-" + year + month + day + "-" + strconv.FormatInt(patient_id, 10)
  3963. verifyCode, version_code := ReadCardGetCode("JY002" + "|" + number + "|" + miConfig.Code)
  3964. //version_code := "V0.3"
  3965. //
  3966. //verifyCode := "000000|9972fca7ba9471c7dbe08324b2e31f70"
  3967. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3968. order_infos, _ := service.GetHisOrderInfoByNumber(order.Number)
  3969. var customs []*models.CustomDetail
  3970. for _, item := range order_infos {
  3971. cus := &models.CustomDetail{
  3972. PrescriptionNumber: item.OrderNumber,
  3973. ChargeSerialNumber: item.FeedetlSn,
  3974. }
  3975. customs = append(customs, cus)
  3976. }
  3977. if config.IsOpen == 1 { //对接了医保,走医保流程
  3978. result := service.SzybJY002(doctor_name, doctor_code, miConfig.Code, order.OrgSetlNumber, order.MzNumber, verifyCode, number, version_code)
  3979. fmt.Println(result)
  3980. var dat map[string]interface{}
  3981. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3982. fmt.Println(dat)
  3983. } else {
  3984. fmt.Println(err)
  3985. }
  3986. userJSONBytes, _ := json.Marshal(dat)
  3987. var res ResultThree
  3988. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3989. utils.ErrorLog("解析失败:%v", err)
  3990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3991. return
  3992. }
  3993. if res.Transreturncode == "00000000" {
  3994. service.UpdataOrderlog(order_id, adminUser.CurrentOrgId, result)
  3995. service.UpdataOrderStatusSZ(order_id, order.Number, adminUser.CurrentOrgId)
  3996. service.UpdataOrderInfoStatus(order.ID, order.Number, adminUser.CurrentOrgId)
  3997. c.ServeSuccessJSON(map[string]interface{}{
  3998. "msg": "退费成功",
  3999. })
  4000. } else {
  4001. c.ServeSuccessJSON(map[string]interface{}{
  4002. "failed_code": -10,
  4003. "msg": res.Transreturnmessage,
  4004. })
  4005. }
  4006. }
  4007. }
  4008. //跨月退费
  4009. func (c *SZHisApiController) MonthRefund() {
  4010. order_id, _ := c.GetInt64("order_id")
  4011. record_time := c.GetString("record_time")
  4012. patient_id, _ := c.GetInt64("patient_id")
  4013. admin_user_id, _ := c.GetInt64("admin_user_id")
  4014. timeLayout := "2006-01-02"
  4015. loc, _ := time.LoadLocation("Local")
  4016. adminUser := c.GetAdminUserInfo()
  4017. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4018. fmt.Println(err)
  4019. if err != nil {
  4020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4021. return
  4022. }
  4023. recordDateTime := theTime.Unix()
  4024. var order models.HisOrder
  4025. order, _ = service.GetHisOrderByID(order_id)
  4026. if order.ID == 0 {
  4027. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  4028. }
  4029. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4030. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4031. //结算流程
  4032. var doctor_name string
  4033. var doctor_code string
  4034. if roles.ID == 0 {
  4035. doctor_name = "管理员"
  4036. doctor_code = "01"
  4037. } else {
  4038. doctor_name = roles.UserName
  4039. doctor_code = strconv.FormatInt(admin_user_id, 10)
  4040. }
  4041. month := time.Unix(1557042972, 0).Format("1")
  4042. year := time.Now().Format("2006")
  4043. month = time.Now().Format("01")
  4044. day := time.Now().Format("02")
  4045. //流水号
  4046. number_two := miConfig.Code + "-" + year + month + day + "-" + strconv.FormatInt(patient_id, 10)
  4047. //verifyCode,version_code := ReadCardGetCode("JY002" + "|" + number_two + "|" + miConfig.Code)
  4048. version_code := "0.03"
  4049. fmt.Println(number_two)
  4050. verifyCode := "000000|0872038667cc34efdc35ce4668589a5f"
  4051. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4052. if config.IsOpen == 1 { //对接了医保,走医保流程
  4053. result := service.SzybJY003(doctor_name, doctor_code, miConfig.Code, order.OrgSetlNumber, order.MzNumber, verifyCode, version_code)
  4054. fmt.Println(result)
  4055. var dat map[string]interface{}
  4056. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4057. fmt.Println(dat)
  4058. } else {
  4059. fmt.Println(err)
  4060. }
  4061. userJSONBytes, _ := json.Marshal(dat)
  4062. var res ResultThree
  4063. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4064. utils.ErrorLog("解析失败:%v", err)
  4065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4066. return
  4067. }
  4068. if res.Transreturncode == "00000000" {
  4069. c.ServeSuccessJSON(map[string]interface{}{
  4070. "msg": "退费成功",
  4071. })
  4072. } else {
  4073. }
  4074. }
  4075. }
  4076. //查询
  4077. func (c *SZHisApiController) GetSettleAccounts() {
  4078. order_id, _ := c.GetInt64("order_id")
  4079. record_time := c.GetString("record_time")
  4080. patient_id, _ := c.GetInt64("patient_id")
  4081. admin_user_id, _ := c.GetInt64("admin_user_id")
  4082. timeLayout := "2006-01-02"
  4083. loc, _ := time.LoadLocation("Local")
  4084. adminUser := c.GetAdminUserInfo()
  4085. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4086. fmt.Println(err)
  4087. if err != nil {
  4088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4089. return
  4090. }
  4091. recordDateTime := theTime.Unix()
  4092. fmt.Println(recordDateTime)
  4093. var order models.HisOrder
  4094. order, _ = service.GetHisOrderByID(order_id)
  4095. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, patient_id)
  4096. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  4097. adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  4098. his, _ := service.GetHisPatientInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  4099. yiliao_leibie := ""
  4100. switch order.MedType {
  4101. case "11":
  4102. yiliao_leibie = "普通门诊"
  4103. break
  4104. case "12":
  4105. yiliao_leibie = "家庭通道"
  4106. break
  4107. case "13":
  4108. yiliao_leibie = "门诊大病"
  4109. break
  4110. case "14":
  4111. yiliao_leibie = "重疾特药"
  4112. break
  4113. case "15":
  4114. yiliao_leibie = "门诊慢病"
  4115. break
  4116. case "16":
  4117. yiliao_leibie = "门诊特检"
  4118. break
  4119. case "17":
  4120. yiliao_leibie = "健康体检"
  4121. break
  4122. case "18":
  4123. yiliao_leibie = "预防接种"
  4124. break
  4125. case "19":
  4126. yiliao_leibie = "门诊输血"
  4127. break
  4128. case "91":
  4129. yiliao_leibie = "新冠肺炎门诊"
  4130. break
  4131. }
  4132. //departments, _ := service.Get(patientPrescription.Departments)
  4133. departments, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  4134. if order.ID == 0 {
  4135. //order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  4136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  4137. return
  4138. }
  4139. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4140. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4141. //结算流程
  4142. var doctor_name string
  4143. var doctor_code string
  4144. if roles.ID == 0 {
  4145. doctor_name = "管理员"
  4146. doctor_code = "01"
  4147. } else {
  4148. doctor_name = roles.UserName
  4149. doctor_code = strconv.FormatInt(admin_user_id, 10)
  4150. }
  4151. //month := time.Unix(1557042972, 0).Format("1")
  4152. //year := time.Now().Format("2006")
  4153. //month = time.Now().Format("01")
  4154. //day := time.Now().Format("02")
  4155. //流水号
  4156. //number_two := miConfig.Code + "-" + year + month + day + "-" + strconv.FormatInt(patient_id, 10)
  4157. //fmt.Println(number_two)
  4158. verifyCode, version_code := ReadCardGetCode("JY001" + "|" + order.OrgSetlNumber + "|" + miConfig.Code)
  4159. //version_code := "V0.3"
  4160. //verifyCode := "000000|2c9854287e7c3cbc34439ab8e5157816"
  4161. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4162. if config.IsOpen == 1 { //对接了医保,走医保流程
  4163. //temp_mz_number := miConfig.Code + year + month + day +
  4164. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000))
  4165. //tempVerifyCode, tempVersionCode := ReadCardGetCode("XX001" + "|" + temp_mz_number + "|" + miConfig.Code)
  4166. //yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("MZ002" + "|" + number + "|" + miConfig.Code + "|")
  4167. //yiliao_number = "%GALMAFXJGKUKZNKWAIUH?;07857319025346309758?"
  4168. //result001 := service.SzybXX001(opera_name, opera_code, miConfig.Code, yiliao_number, tempVerifyCode, temp_mz_number, tempVersionCode)
  4169. result := service.SzybJY001(doctor_name, doctor_code, miConfig.Code, order.OrgSetlNumber, order.MzNumber, verifyCode, version_code)
  4170. fmt.Println(result)
  4171. var dat map[string]interface{}
  4172. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4173. fmt.Println(dat)
  4174. } else {
  4175. fmt.Println(err)
  4176. }
  4177. userJSONBytes, _ := json.Marshal(dat)
  4178. var res ResultFour
  4179. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4180. utils.ErrorLog("解析失败:%v", err)
  4181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4182. return
  4183. }
  4184. if res.Transreturncode == "00000000" {
  4185. var dat2 map[string]interface{}
  4186. if err := json.Unmarshal([]byte(his.PatientInfo), &dat2); err == nil {
  4187. fmt.Println(dat2)
  4188. } else {
  4189. fmt.Println(err)
  4190. }
  4191. userJSONBytes2, _ := json.Marshal(dat2)
  4192. var res2 ResultMZ001
  4193. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  4194. utils.ErrorLog("解析失败:%v", err)
  4195. }
  4196. c.ServeSuccessJSON(map[string]interface{}{
  4197. "result": res,
  4198. "org_name": miConfig.OrgName,
  4199. "org_code": miConfig.Code,
  4200. "patient_name": patient.Name,
  4201. "doctor_code": adminRole_two.DoctorCode,
  4202. "doctor_name": doctor_name,
  4203. "health_card_no": order.PsnNo,
  4204. "health_card_no_two": res2.Transbody.Aaz500,
  4205. "order_number": order.Number,
  4206. "department": departments.Name,
  4207. "yiliao_leibie": yiliao_leibie,
  4208. "before_money": res2.Transbody.Aae240,
  4209. "after_money": order.AccountPrice,
  4210. "dialysis_no": patient.DialysisNo,
  4211. "patient_info": res2,
  4212. })
  4213. } else {
  4214. c.ServeSuccessJSON(map[string]interface{}{
  4215. "failed_code": -10,
  4216. "msg": res.Transreturnmessage,
  4217. })
  4218. }
  4219. }
  4220. }
  4221. //费用录入取消
  4222. //func (c *SZHisApiController) CancelOrderDetail() {
  4223. // order_id, _ := c.GetInt64("order_id")
  4224. // record_time := c.GetString("record_time")
  4225. // patient_id, _ := c.GetInt64("patient_id")
  4226. // admin_user_id, _ := c.GetInt64("admin_user_id")
  4227. // timeLayout := "2006-01-02"
  4228. // loc, _ := time.LoadLocation("Local")
  4229. // adminUser := c.GetAdminUserInfo()
  4230. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4231. // fmt.Println(err)
  4232. // if err != nil {
  4233. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4234. // return
  4235. // }
  4236. // recordDateTime := theTime.Unix()
  4237. // var order models.HisOrder
  4238. // order, _ = service.GetHisOrderByID(order_id)
  4239. //
  4240. // if order.ID == 0 {
  4241. // order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  4242. //
  4243. // }
  4244. //
  4245. // order_infos, _ := service.GetHisOrderInfoByNumber(order.Number)
  4246. //
  4247. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4248. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4249. // //结算流程
  4250. // var doctor_name string
  4251. // var doctor_code string
  4252. // if roles.ID == 0 {
  4253. // doctor_name = "管理员"
  4254. // doctor_code = "1001"
  4255. // } else {
  4256. // doctor_name = roles.UserName
  4257. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  4258. //
  4259. // }
  4260. // var customs []*models.CustomDetail
  4261. //
  4262. // for _, item := range order_infos {
  4263. // cus := &models.CustomDetail{
  4264. // PrescriptionNumber: item.OrderNumber,
  4265. // ChargeSerialNumber: item.FeedetlSn,
  4266. // }
  4267. // customs = append(customs, cus)
  4268. // }
  4269. // his, _ := service.GetHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  4270. //
  4271. // verifyCode, version_code := ReadCardGetCode("FY002" + "|" + order.OrgSetlNumber + "|" + miConfig.Code)
  4272. //
  4273. // var pagesize int = 50
  4274. // var start int = 1
  4275. // var stop int
  4276. // var pagecount int
  4277. // var curpage int
  4278. // var isSuccess bool = true
  4279. // var ress []*ResultFive
  4280. //
  4281. // //总页数,向上取整,注意除之前要先转换类型为float64
  4282. // pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  4283. //
  4284. // for curpage = 1; curpage <= pagecount; curpage++ {
  4285. // if curpage == 1 {
  4286. // start = 1
  4287. // } else {
  4288. // start = (curpage-1)*pagesize + 1
  4289. // }
  4290. // stop = curpage * pagesize
  4291. // if stop > len(customs) {
  4292. // stop = len(customs)
  4293. // }
  4294. //
  4295. // result := service.SzybFY002(doctor_name, doctor_code, miConfig.Code, customs[start-1:stop], verifyCode, order.OrgSetlNumber, his.Number, version_code)
  4296. // fmt.Println(result)
  4297. //
  4298. // var dat map[string]interface{}
  4299. // if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4300. // fmt.Println(dat)
  4301. // } else {
  4302. // fmt.Println(err)
  4303. // }
  4304. // userJSONBytes, _ := json.Marshal(dat)
  4305. // var res ResultFive
  4306. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4307. // utils.ErrorLog("解析失败:%v", err)
  4308. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4309. // return
  4310. // }
  4311. // if res.Transreturncode == "00000000" {
  4312. // ress = append(ress, &res)
  4313. // } else {
  4314. // isSuccess = false
  4315. // //预结算报错
  4316. // errlog := &models.HisOrderError{
  4317. // UserOrgId: adminUser.CurrentOrgId,
  4318. // Ctime: time.Now().Unix(),
  4319. // Mtime: time.Now().Unix(),
  4320. // ErrMsg: res.Transreturnmessage,
  4321. // Status: 1,
  4322. // PatientId: patient_id,
  4323. // RecordTime: recordDateTime,
  4324. // Stage: 11,
  4325. // }
  4326. // service.CreateErrMsgLog(errlog)
  4327. //
  4328. // c.ServeSuccessJSON(map[string]interface{}{
  4329. // "faild_code": -10,
  4330. // "msg": res.Transreturnmessage,
  4331. // })
  4332. // return
  4333. // }
  4334. // }
  4335. // if isSuccess == true {
  4336. // service.UpdataOrderInfoStatus(order.ID, order.Number, adminUser.CurrentOrgId)
  4337. // c.ServeSuccessJSON(map[string]interface{}{
  4338. // "msg": "撤销成功",
  4339. // })
  4340. // }
  4341. //}
  4342. func (c *SZHisApiController) CancelOrderDetail() {
  4343. order_id, _ := c.GetInt64("order_id")
  4344. record_time := c.GetString("record_time")
  4345. patient_id, _ := c.GetInt64("patient_id")
  4346. his_patient_id, _ := c.GetInt64("his_patient_id")
  4347. admin_user_id, _ := c.GetInt64("admin_user_id")
  4348. timeLayout := "2006-01-02"
  4349. loc, _ := time.LoadLocation("Local")
  4350. adminUser := c.GetAdminUserInfo()
  4351. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4352. fmt.Println(err)
  4353. if err != nil {
  4354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4355. return
  4356. }
  4357. recordDateTime := theTime.Unix()
  4358. var order models.HisOrder
  4359. order, _ = service.GetHisOrderByID(order_id)
  4360. if order.ID == 0 {
  4361. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  4362. }
  4363. order_infos, _ := service.GetHisOrderInfoByNumber(order.Number)
  4364. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4365. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4366. //结算流程
  4367. var doctor_name string
  4368. var doctor_code string
  4369. if roles.ID == 0 {
  4370. doctor_name = "管理员"
  4371. doctor_code = "1001"
  4372. } else {
  4373. doctor_name = roles.UserName
  4374. doctor_code = strconv.FormatInt(admin_user_id, 10)
  4375. }
  4376. var customs []*models.CustomDetail
  4377. for _, item := range order_infos {
  4378. cus := &models.CustomDetail{
  4379. PrescriptionNumber: item.OrderNumber,
  4380. ChargeSerialNumber: item.FeedetlSn,
  4381. }
  4382. customs = append(customs, cus)
  4383. }
  4384. his, _ := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  4385. verifyCode, version_code := ReadCardGetCode("FY002" + "|" + order.OrgSetlNumber + "|" + miConfig.Code)
  4386. var pagesize int = 50
  4387. var start int = 1
  4388. var stop int
  4389. var pagecount int
  4390. var curpage int
  4391. var isSuccess bool = true
  4392. var ress []*ResultFive
  4393. //总页数,向上取整,注意除之前要先转换类型为float64
  4394. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  4395. for curpage = 1; curpage <= pagecount; curpage++ {
  4396. if curpage == 1 {
  4397. start = 1
  4398. } else {
  4399. start = (curpage-1)*pagesize + 1
  4400. }
  4401. stop = curpage * pagesize
  4402. if stop > len(customs) {
  4403. stop = len(customs)
  4404. }
  4405. result := service.SzybFY002(doctor_name, doctor_code, miConfig.Code, customs[start-1:stop], verifyCode, order.OrgSetlNumber, his.Number, version_code)
  4406. fmt.Println(result)
  4407. var dat map[string]interface{}
  4408. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4409. fmt.Println(dat)
  4410. } else {
  4411. fmt.Println(err)
  4412. }
  4413. userJSONBytes, _ := json.Marshal(dat)
  4414. var res ResultFive
  4415. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4416. utils.ErrorLog("解析失败:%v", err)
  4417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4418. return
  4419. }
  4420. if res.Transreturncode == "00000000" {
  4421. ress = append(ress, &res)
  4422. } else {
  4423. isSuccess = false
  4424. //预结算报错
  4425. errlog := &models.HisOrderError{
  4426. UserOrgId: adminUser.CurrentOrgId,
  4427. Ctime: time.Now().Unix(),
  4428. Mtime: time.Now().Unix(),
  4429. ErrMsg: res.Transreturnmessage,
  4430. Status: 1,
  4431. PatientId: patient_id,
  4432. RecordTime: recordDateTime,
  4433. Stage: 11,
  4434. }
  4435. service.CreateErrMsgLog(errlog)
  4436. c.ServeSuccessJSON(map[string]interface{}{
  4437. "faild_code": -10,
  4438. "msg": res.Transreturnmessage,
  4439. })
  4440. return
  4441. }
  4442. }
  4443. if isSuccess == true {
  4444. service.UpdataOrderInfoStatus(order.ID, order.Number, adminUser.CurrentOrgId)
  4445. c.ServeSuccessJSON(map[string]interface{}{
  4446. "msg": "撤销成功",
  4447. })
  4448. }
  4449. }
  4450. //获取verifyCode
  4451. func ReadCardGetCode(request string) (string, string) {
  4452. request = request + "|"
  4453. DllDef2 := syscall.MustLoadDLL("SSCardDriver_SZ.dll")
  4454. readCards := DllDef2.MustFindProc("iVerifyCode")
  4455. str := request
  4456. str3 := make([]byte, 256)
  4457. ret4, _, _ := readCards.Call(StrPtr(str), (uintptr)(unsafe.Pointer(&str3[0])))
  4458. fmt.Println(":", string(str3))
  4459. fmt.Println(":", ConvertToString(string(str3), "gbk", "utf-8"))
  4460. if ret4 == 0 {
  4461. result := string(str3)
  4462. fmt.Println(result)
  4463. result_arr := strings.Split(result, "|")
  4464. verifyCode := result_arr[0] + "|" + result_arr[1]
  4465. versionCode := result_arr[2]
  4466. return verifyCode, versionCode
  4467. }
  4468. return "", ""
  4469. }
  4470. ////获取卡信息
  4471. func ReadBasCardGetNumber(request string) (string, string, string, string, string, error, int64) {
  4472. DllDef2 := syscall.MustLoadDLL("SSCardDriver_SZ.dll")
  4473. readCards := DllDef2.MustFindProc("iReadCardBas")
  4474. str := request
  4475. str3 := make([]byte, 1024)
  4476. fmt.Println(":", request)
  4477. fmt.Println(":", StrPtr(str))
  4478. ret4, _, err := readCards.Call(IntPtr(1), StrPtr(str), (uintptr)(unsafe.Pointer(&str3[0])))
  4479. fmt.Println(":", string(str3))
  4480. fmt.Println(":", ConvertToString(string(str3), "gbk", "utf-8"))
  4481. if ret4 == 0 {
  4482. result := string(str3)
  4483. fmt.Println(result)
  4484. result_arr := strings.Split(result, "|")
  4485. //医疗证号
  4486. yiliao_number := result_arr[12]
  4487. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  4488. id_card_number := result_arr[1]
  4489. verifyCode := result_arr[11] + "|" + result_arr[13]
  4490. versionCode := result_arr[14]
  4491. health_card_no := result_arr[2]
  4492. return yiliao_number, id_card_number, verifyCode, versionCode, health_card_no, err, 0
  4493. }
  4494. return "", "", "", "", "", err, -10
  4495. }
  4496. //读卡
  4497. func ReadBasCard(request string) (string, string, error, int64) {
  4498. DllDef2 := syscall.MustLoadDLL("SSCardDriver_SZ.dll")
  4499. readCards := DllDef2.MustFindProc("iReadCardBas")
  4500. str := request
  4501. str3 := make([]byte, 1024)
  4502. ret4, _, err := readCards.Call(IntPtr(1), StrPtr(str), (uintptr)(unsafe.Pointer(&str3[0])))
  4503. fmt.Println(":", string(str3))
  4504. fmt.Println(":", ConvertToString(string(str3), "gbk", "utf-8"))
  4505. if ret4 == 0 {
  4506. result := string(str3)
  4507. result_arr := strings.Split(result, "|")
  4508. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  4509. id_card_number := result_arr[1]
  4510. health_card_no := result_arr[2]
  4511. return id_card_number, health_card_no, err, 0
  4512. }
  4513. return "", "", err, -10
  4514. }
  4515. //
  4516. ////iReadCardBas_HSM_Step1 ---- 1903 iCardInnerAuthentication --- iReadCardBas_HSM_Step2
  4517. //func ReadCardBasHSM(number string) string {
  4518. // DllDef2 := syscall.MustLoadDLL("SSSE32.dll")
  4519. // readCards := DllDef2.MustFindProc("iReadCardBas_HSM_Step1")
  4520. // str := make([]byte, 256)
  4521. // ret, _, _ := readCards.Call(IntPtr(3), (uintptr)(unsafe.Pointer(&str[0])))
  4522. // fmt.Println(":", string(str))
  4523. //
  4524. // result_arr := strings.Split(string(str), "|")
  4525. //
  4526. // if ret == 0 {
  4527. // readCards := DllDef2.MustFindProc("iCardInnerAuthentication")
  4528. // str2 := make([]byte, 256)
  4529. // str3 := "" + "|" + "" + "|" + "440300" + "|" + "" + "|" + "" + "|" + result_arr[1] + "|" + result_arr[2] + "|" + result_arr[3] + "|" + result_arr[4] + "|" + result_arr[5] + "|" + "" + "|" + "" + "|"
  4530. // ret2, _, _ := readCards.Call(StrPtr(str3), (uintptr)(unsafe.Pointer(&str2[0])))
  4531. // fmt.Println(":", string(str2))
  4532. //
  4533. // if ret2 == 0 {
  4534. // result_arr := strings.Split(string(str2), "|")
  4535. //
  4536. // if result_arr[2] == "0" {
  4537. // readCards := DllDef2.MustFindProc("iReadCardBas_HSM_Step2")
  4538. // str4 := result_arr[4] + "|" + result_arr[5]
  4539. // str5 := make([]byte, 256)
  4540. // ret3, _, _ := readCards.Call(StrPtr(str4), StrPtr(number), (uintptr)(unsafe.Pointer(&str5[0])))
  4541. //
  4542. // if ret3 == 0 {
  4543. // return string(str5)
  4544. //
  4545. // } else {
  4546. // return ""
  4547. // }
  4548. // } else {
  4549. // return ""
  4550. // }
  4551. // }
  4552. // return ""
  4553. // }
  4554. // return ""
  4555. //
  4556. //}
  4557. //
  4558. ////1904卡鉴权
  4559. //func CardAuth(request string) string {
  4560. // DllDef2 := syscall.MustLoadDLL("SSSE32.dll")
  4561. // readCards := DllDef2.MustFindProc("iCardAuthentication")
  4562. // str := request
  4563. // str3 := make([]byte, 256)
  4564. // ret4, _, _ := readCards.Call(StrPtr(str), (uintptr)(unsafe.Pointer(&str3[0])))
  4565. // fmt.Println(":", string(str3))
  4566. //
  4567. // if ret4 == 0 {
  4568. // return string(str3)
  4569. // }
  4570. // return ""
  4571. //}
  4572. func (c *SZHisApiController) GetDrugList() {
  4573. adminUserInfo := c.GetAdminUserInfo()
  4574. orgId := adminUserInfo.CurrentOrgId
  4575. admin_user_id, _ := c.GetInt64("admin_user_id")
  4576. roles, _ := service.GetAdminUserInfoByID(orgId, admin_user_id)
  4577. ids := c.GetString("ids")
  4578. stringarr := strings.Split(ids, ",")
  4579. idss := make([]int64, 0)
  4580. for _, item := range stringarr {
  4581. itemsss, _ := strconv.ParseInt(item, 10, 64)
  4582. id := int64(itemsss)
  4583. idss = append(idss, id)
  4584. }
  4585. //批量获取
  4586. list, _ := service.GetBatchDrugList(idss)
  4587. //获取药品剂型
  4588. drugs, _ := service.GetDrugDosageForm(orgId)
  4589. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4590. var doctor_name string
  4591. var doctor_code string
  4592. doctor_name = roles.UserName
  4593. doctor_code = "1001"
  4594. var isSuccess bool = true
  4595. timeLayout := "20060102"
  4596. //这里就可以查看开始和结束了
  4597. for _, item := range list {
  4598. recordDate := time.Unix(item.RecordDate, 0).Format(timeLayout)
  4599. detail := &models.DrugDetail{
  4600. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  4601. Code: item.Code,
  4602. DrugName: item.DrugName,
  4603. DrugSpec: item.DrugSpec,
  4604. DrugDosageName: item.DrugDosageName,
  4605. ManufacturerName: item.ManufacturerName,
  4606. MinUnit: item.MinUnit,
  4607. RetailPrice: item.RetailPrice,
  4608. LastPrice: item.LastPrice,
  4609. LimitRemark: item.LimitRemark,
  4610. PrescriptionMark: strconv.FormatInt(item.PrescriptionMark, 10),
  4611. RecordDate: recordDate,
  4612. }
  4613. for _, it := range drugs {
  4614. if item.DrugDosageForm == it.Value {
  4615. detail.DrugDosageName = it.Code
  4616. }
  4617. }
  4618. result := service.SzybML008(doctor_name, doctor_code, miConfig.Code, detail)
  4619. var dat map[string]interface{}
  4620. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4621. //fmt.Println(dat)
  4622. } else {
  4623. //fmt.Println(err)
  4624. }
  4625. userJSONBytes, _ := json.Marshal(dat)
  4626. var res Result
  4627. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4628. utils.ErrorLog("解析失败:%v", err)
  4629. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4630. c.ServeSuccessJSON(map[string]interface{}{
  4631. "failed_code": -10,
  4632. "msg": res.Transreturnmessage,
  4633. })
  4634. return
  4635. }
  4636. if res.Transreturncode == "00000000" {
  4637. //更新备案状态
  4638. _, err := service.UpdateBaseDrugById(item.ID)
  4639. fmt.Println("err", err)
  4640. c.ServeSuccessJSON(map[string]interface{}{
  4641. "failed_code": -10,
  4642. "msg": res.Transreturnmessage,
  4643. })
  4644. return
  4645. }
  4646. fmt.Println(isSuccess)
  4647. c.ServeSuccessJSON(map[string]interface{}{
  4648. "failed_code": -10,
  4649. "msg": res.Transreturnmessage,
  4650. })
  4651. return
  4652. }
  4653. }
  4654. func (c *SZHisApiController) GetTreatmentProject() {
  4655. adminUserInfo := c.GetAdminUserInfo()
  4656. orgId := adminUserInfo.CurrentOrgId
  4657. ids := c.GetString("ids")
  4658. stringarr := strings.Split(ids, ",")
  4659. idss := make([]int64, 0)
  4660. admin_user_id, _ := c.GetInt64("admin_user_id")
  4661. roles, _ := service.GetAdminUserInfoByID(orgId, admin_user_id)
  4662. for _, item := range stringarr {
  4663. itemsss, _ := strconv.ParseInt(item, 10, 64)
  4664. id := int64(itemsss)
  4665. idss = append(idss, id)
  4666. }
  4667. //获取项目库数据
  4668. list, _ := service.GetBathchMyPorjecgList(idss)
  4669. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4670. var doctor_name string
  4671. var doctor_code string
  4672. doctor_name = roles.UserName
  4673. doctor_code = "1001"
  4674. var isSuccess bool = true
  4675. for _, item := range list {
  4676. detail := &models.MyHisProject{
  4677. MedicalCode: item.MedicalCode, //社保目录
  4678. ProjectName: item.ProjectName,
  4679. Price: item.Price,
  4680. Category: item.Category,
  4681. Remark: item.Remark,
  4682. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  4683. SpecailProject: item.SpecailProject,
  4684. RecordDate: item.RecordDate,
  4685. }
  4686. result := service.SzybML009(doctor_name, doctor_code, miConfig.Code, detail)
  4687. var dat map[string]interface{}
  4688. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4689. fmt.Println(dat)
  4690. } else {
  4691. fmt.Println(err)
  4692. }
  4693. userJSONBytes, _ := json.Marshal(dat)
  4694. var res Result
  4695. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4696. utils.ErrorLog("解析失败:%v", err)
  4697. c.ServeSuccessJSON(map[string]interface{}{
  4698. "failed_code": -10,
  4699. "msg": res.Transreturnmessage,
  4700. })
  4701. return
  4702. }
  4703. if res.Transreturncode == "00000000" {
  4704. //备案成功返回状态值
  4705. _, err := service.UpdateProjectById(item.ID)
  4706. fmt.Println("err", err)
  4707. } else {
  4708. isSuccess = false
  4709. //失败
  4710. c.ServeSuccessJSON(map[string]interface{}{
  4711. "failed_code": -10,
  4712. "msg": res.Transreturnmessage,
  4713. })
  4714. return
  4715. }
  4716. fmt.Println(isSuccess)
  4717. c.ServeSuccessJSON(map[string]interface{}{
  4718. "failed_code": -10,
  4719. "msg": res.Transreturnmessage,
  4720. })
  4721. return
  4722. }
  4723. }
  4724. func (c *SZHisApiController) GetRevocation() {
  4725. adminUserInfo := c.GetAdminUserInfo()
  4726. orgId := adminUserInfo.CurrentOrgId
  4727. id, _ := c.GetInt64("id")
  4728. admin_user_id, _ := c.GetInt64("admin_user_id")
  4729. roles, _ := service.GetAdminUserInfoByID(orgId, admin_user_id)
  4730. //用来区分是药品的撤销还是耗材的撤销 1.药品 2.诊疗项目 3.材料 5.辅助器具项目
  4731. is_mark, _ := c.GetInt64("is_mark")
  4732. type_id, _ := c.GetInt64("type_id")
  4733. if type_id == 1 {
  4734. //撤销
  4735. if is_mark == 1 {
  4736. //获取药品库数据
  4737. list, _ := service.GetDrugListByDetail(orgId, id)
  4738. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4739. var doctor_name string
  4740. var doctor_code string
  4741. doctor_name = roles.UserName
  4742. doctor_code = "1001"
  4743. var pagesize int = 50
  4744. var start int = 1
  4745. var stop int
  4746. var pagecount int
  4747. var curpage int
  4748. var isSuccess bool = true
  4749. //总页数,向上取整,注意除之前要先转换类型为float64
  4750. pagecount = int(math.Ceil(float64(len(list)) / float64(pagesize)))
  4751. for curpage = 1; curpage <= pagecount; curpage++ {
  4752. if curpage == 1 {
  4753. start = 1
  4754. } else {
  4755. start = (curpage-1)*pagesize + 1
  4756. }
  4757. stop = curpage * pagesize
  4758. if stop > len(list) {
  4759. stop = len(list)
  4760. }
  4761. //这里就可以查看开始和结束了
  4762. fmt.Println(list[start-1 : stop])
  4763. var customs []*models.DrugDetail
  4764. for _, item := range list {
  4765. detail := &models.DrugDetail{
  4766. SocialSecurityDirectoryCode: item.MedicalInsuranceNumber, //社保目录
  4767. Code: item.Code, //协议机构内部目录编码
  4768. DrugName: item.DrugName, //协议机构内部目录名称
  4769. DrugSpec: item.DrugSpec,
  4770. ManufacturerName: item.ManufacturerName,
  4771. MinUnit: item.MinUnit,
  4772. RetailPrice: item.RetailPrice, //协议机构内部项目收费价格
  4773. LimitRemark: item.LimitRemark,
  4774. MedicalInsuranceNumber: item.MedicalInsuranceNumber, //社保目录
  4775. }
  4776. customs = append(customs, detail)
  4777. }
  4778. result := service.SzybML010(doctor_name, doctor_code, miConfig.Code, customs, type_id)
  4779. fmt.Println("reuslt", result)
  4780. var dat map[string]interface{}
  4781. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4782. fmt.Println(dat)
  4783. } else {
  4784. fmt.Println(err)
  4785. }
  4786. userJSONBytes, _ := json.Marshal(dat)
  4787. var res Result
  4788. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4789. utils.ErrorLog("解析失败:%v", err)
  4790. c.ServeSuccessJSON(map[string]interface{}{
  4791. "failed_code": -10,
  4792. "msg": res.Transreturnmessage,
  4793. })
  4794. return
  4795. }
  4796. if res.Transreturncode == "00000000" {
  4797. //撤销成功
  4798. _, err := service.UpdateDrugByIdDetail(id)
  4799. fmt.Println("err", err)
  4800. } else {
  4801. isSuccess = false
  4802. //失败
  4803. c.ServeSuccessJSON(map[string]interface{}{
  4804. "failed_code": -10,
  4805. "msg": res.Transreturnmessage,
  4806. })
  4807. return
  4808. }
  4809. fmt.Println(isSuccess)
  4810. c.ServeSuccessJSON(map[string]interface{}{
  4811. "failed_code": -10,
  4812. "msg": res.Transreturnmessage,
  4813. })
  4814. return
  4815. }
  4816. }
  4817. // 备案
  4818. if is_mark == 0 {
  4819. adminUserInfo := c.GetAdminUserInfo()
  4820. orgId := adminUserInfo.CurrentOrgId
  4821. //获取药品库数据
  4822. list, _ := service.GetDrugListByDetail(orgId, id)
  4823. //获取药品剂型
  4824. drugs, _ := service.GetDrugDosageForm(orgId)
  4825. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4826. var doctor_name string
  4827. var doctor_code string
  4828. doctor_name = roles.UserName
  4829. doctor_code = "1001"
  4830. var isSuccess bool = true
  4831. //这里就可以查看开始和结束了
  4832. for _, item := range list {
  4833. detail := &models.DrugDetail{
  4834. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  4835. SocialSecurityDirectoryCode: item.MedicalInsuranceNumber,
  4836. Code: item.Code,
  4837. DrugName: item.DrugName,
  4838. DrugSpec: item.DrugSpec,
  4839. DrugDosageName: item.DrugDosageName,
  4840. ManufacturerName: item.ManufacturerName,
  4841. MinUnit: item.MinUnit,
  4842. RetailPrice: item.RetailPrice,
  4843. LastPrice: item.LastPrice,
  4844. LimitRemark: item.LimitRemark,
  4845. }
  4846. for _, it := range drugs {
  4847. if item.DrugDosageForm == it.Value {
  4848. detail.DrugDosageName = it.Code
  4849. }
  4850. }
  4851. result := service.SzybML008(doctor_name, doctor_code, miConfig.Code, detail)
  4852. var dat map[string]interface{}
  4853. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4854. //fmt.Println(dat)
  4855. } else {
  4856. //fmt.Println(err)
  4857. }
  4858. userJSONBytes, _ := json.Marshal(dat)
  4859. var res Result
  4860. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4861. utils.ErrorLog("解析失败:%v", err)
  4862. c.ServeSuccessJSON(map[string]interface{}{
  4863. "failed_code": -10,
  4864. "msg": res.Transreturnmessage,
  4865. })
  4866. return
  4867. }
  4868. if res.Transreturncode == "00000000" {
  4869. //更新备案状态
  4870. _, err := service.UpdateBaseDrugById(item.ID)
  4871. fmt.Println("err", err)
  4872. }
  4873. fmt.Println(isSuccess)
  4874. c.ServeSuccessJSON(map[string]interface{}{
  4875. "failed_code": -10,
  4876. "msg": res.Transreturnmessage,
  4877. })
  4878. return
  4879. }
  4880. }
  4881. }
  4882. if type_id == 2 {
  4883. //撤销
  4884. if is_mark == 1 {
  4885. //获取药品库数据
  4886. list, _ := service.GetMyPorjecgListDetail(orgId, id)
  4887. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4888. var doctor_name string
  4889. var doctor_code string
  4890. doctor_name = roles.UserName
  4891. doctor_code = "1001"
  4892. var pagesize int = 50
  4893. var start int = 1
  4894. var stop int
  4895. var pagecount int
  4896. var curpage int
  4897. var isSuccess bool = true
  4898. //总页数,向上取整,注意除之前要先转换类型为float64
  4899. pagecount = int(math.Ceil(float64(len(list)) / float64(pagesize)))
  4900. for curpage = 1; curpage <= pagecount; curpage++ {
  4901. if curpage == 1 {
  4902. start = 1
  4903. } else {
  4904. start = (curpage-1)*pagesize + 1
  4905. }
  4906. stop = curpage * pagesize
  4907. if stop > len(list) {
  4908. stop = len(list)
  4909. }
  4910. //这里就可以查看开始和结束了
  4911. fmt.Println(list[start-1 : stop])
  4912. var customs []*models.DrugDetail
  4913. for _, item := range list {
  4914. detail := &models.DrugDetail{
  4915. SocialSecurityDirectoryCode: item.MedicalCode,
  4916. }
  4917. customs = append(customs, detail)
  4918. }
  4919. result := service.SzybML010(doctor_name, doctor_code, miConfig.Code, customs, type_id)
  4920. fmt.Println("reuslt", result)
  4921. var dat map[string]interface{}
  4922. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4923. fmt.Println(dat)
  4924. } else {
  4925. fmt.Println(err)
  4926. }
  4927. userJSONBytes, _ := json.Marshal(dat)
  4928. var res Result
  4929. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4930. utils.ErrorLog("解析失败:%v", err)
  4931. c.ServeSuccessJSON(map[string]interface{}{
  4932. "failed_code": -10,
  4933. "msg": res.Transreturnmessage,
  4934. })
  4935. return
  4936. }
  4937. if res.Transreturncode == "00000000" {
  4938. //核销成功返回状态码
  4939. _, err := service.UpdateMyProjectById(id)
  4940. fmt.Println("err", err)
  4941. } else {
  4942. isSuccess = false
  4943. //失败
  4944. c.ServeSuccessJSON(map[string]interface{}{
  4945. "failed_code": -10,
  4946. "msg": res.Transreturnmessage,
  4947. })
  4948. return
  4949. }
  4950. fmt.Println(isSuccess)
  4951. c.ServeSuccessJSON(map[string]interface{}{
  4952. "failed_code": -10,
  4953. "msg": res.Transreturnmessage,
  4954. })
  4955. return
  4956. }
  4957. }
  4958. //备案
  4959. if is_mark == 0 {
  4960. adminUserInfo := c.GetAdminUserInfo()
  4961. orgId := adminUserInfo.CurrentOrgId
  4962. //获取药品库数据
  4963. list, _ := service.GetMyPorjecgListDetail(orgId, id)
  4964. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4965. var doctor_name string
  4966. var doctor_code string
  4967. doctor_name = roles.UserName
  4968. doctor_code = "1001"
  4969. var isSuccess bool = true
  4970. for _, item := range list {
  4971. detail := &models.MyHisProject{
  4972. MedicalCode: item.MedicalCode, //社保目录
  4973. ProjectName: item.ProjectName,
  4974. Price: item.Price,
  4975. Category: item.Category,
  4976. Remark: item.Remark,
  4977. }
  4978. result := service.SzybML009(doctor_name, doctor_code, miConfig.Code, detail)
  4979. fmt.Println("reuslt", result)
  4980. var dat map[string]interface{}
  4981. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4982. fmt.Println(dat)
  4983. } else {
  4984. fmt.Println(err)
  4985. }
  4986. userJSONBytes, _ := json.Marshal(dat)
  4987. var res Result
  4988. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4989. utils.ErrorLog("解析失败:%v", err)
  4990. c.ServeSuccessJSON(map[string]interface{}{
  4991. "failed_code": -10,
  4992. "msg": res.Transreturnmessage,
  4993. })
  4994. return
  4995. }
  4996. if res.Transreturncode == "00000000" {
  4997. //备案成功返回状态值
  4998. _, err := service.UpdateProjectById(item.ID)
  4999. fmt.Println("err", err)
  5000. } else {
  5001. isSuccess = false
  5002. //失败
  5003. c.ServeSuccessJSON(map[string]interface{}{
  5004. "failed_code": -10,
  5005. "msg": res.Transreturnmessage,
  5006. })
  5007. return
  5008. }
  5009. fmt.Println(isSuccess)
  5010. c.ServeSuccessJSON(map[string]interface{}{
  5011. "failed_code": -10,
  5012. "msg": res.Transreturnmessage,
  5013. })
  5014. return
  5015. }
  5016. }
  5017. }
  5018. if type_id == 3 {
  5019. //撤销
  5020. if is_mark == 1 {
  5021. //获取药品库数据
  5022. list, _ := service.GetGoodListByDetail(orgId, id)
  5023. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  5024. var doctor_name string
  5025. var doctor_code string
  5026. doctor_name = roles.UserName
  5027. doctor_code = "1001"
  5028. var pagesize int = 50
  5029. var start int = 1
  5030. var stop int
  5031. var pagecount int
  5032. var curpage int
  5033. var isSuccess bool = true
  5034. //总页数,向上取整,注意除之前要先转换类型为float64
  5035. pagecount = int(math.Ceil(float64(len(list)) / float64(pagesize)))
  5036. for curpage = 1; curpage <= pagecount; curpage++ {
  5037. if curpage == 1 {
  5038. start = 1
  5039. } else {
  5040. start = (curpage-1)*pagesize + 1
  5041. }
  5042. stop = curpage * pagesize
  5043. if stop > len(list) {
  5044. stop = len(list)
  5045. }
  5046. //这里就可以查看开始和结束了
  5047. fmt.Println(list[start-1 : stop])
  5048. var customs []*models.DrugDetail
  5049. for _, item := range list {
  5050. fmt.Println("医疗机构编码", item.SocialSecurityDirectoryCode)
  5051. detail := &models.DrugDetail{
  5052. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  5053. ManufacturerName: item.ManufacturerName,
  5054. }
  5055. customs = append(customs, detail)
  5056. }
  5057. result := service.SzybML010(doctor_name, doctor_code, miConfig.Code, customs, type_id)
  5058. fmt.Println("reuslt", result)
  5059. var dat map[string]interface{}
  5060. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5061. fmt.Println(dat)
  5062. } else {
  5063. fmt.Println(err)
  5064. }
  5065. userJSONBytes, _ := json.Marshal(dat)
  5066. var res Result
  5067. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5068. utils.ErrorLog("解析失败:%v", err)
  5069. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5070. return
  5071. }
  5072. if res.Transreturncode == "00000000" {
  5073. //撤销成功后改变状态
  5074. _, err := service.UpdateGoodInfoById(id)
  5075. fmt.Println("err", err)
  5076. } else {
  5077. isSuccess = false
  5078. //失败
  5079. c.ServeSuccessJSON(map[string]interface{}{
  5080. "failed_code": -10,
  5081. "msg": res.Transreturnmessage,
  5082. })
  5083. return
  5084. }
  5085. fmt.Println(isSuccess)
  5086. c.ServeSuccessJSON(map[string]interface{}{
  5087. "failed_code": -10,
  5088. "msg": res.Transreturnmessage,
  5089. })
  5090. return
  5091. }
  5092. }
  5093. //备案
  5094. if is_mark == 0 {
  5095. adminUserInfo := c.GetAdminUserInfo()
  5096. orgId := adminUserInfo.CurrentOrgId
  5097. //获取所有耗材信息
  5098. list, _ := service.GetGoodListByDetail(orgId, id)
  5099. //获取单位
  5100. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  5101. var doctor_name string
  5102. var doctor_code string
  5103. doctor_name = roles.UserName
  5104. doctor_code = "1001"
  5105. var isSuccess bool = true
  5106. for _, item := range list {
  5107. detail := &models.XtGoodInformation{
  5108. GoodName: item.GoodName,
  5109. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  5110. ManufacturerName: item.ManufacturerName,
  5111. ProductionType: item.ProductionType,
  5112. SpecialMedical: item.SpecialMedical,
  5113. BuyPrice: item.BuyPrice,
  5114. SellPrice: item.SellPrice,
  5115. Remark: item.Remark,
  5116. SpecificationName: item.SpecificationName,
  5117. }
  5118. result := service.SzybYML007(doctor_name, doctor_code, miConfig.Code, detail)
  5119. fmt.Println("reuslt", result)
  5120. var dat map[string]interface{}
  5121. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5122. fmt.Println(dat)
  5123. } else {
  5124. fmt.Println(err)
  5125. }
  5126. userJSONBytes, _ := json.Marshal(dat)
  5127. var res Result
  5128. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5129. utils.ErrorLog("解析失败:%v", err)
  5130. c.ServeSuccessJSON(map[string]interface{}{
  5131. "failed_code": -10,
  5132. "msg": res.Transreturnmessage,
  5133. })
  5134. return
  5135. }
  5136. if res.Transreturncode == "00000000" {
  5137. //备案成功返回状态
  5138. _, err := service.UpdateGoodInformaitonByDetail(item.ID)
  5139. fmt.Println("err", err)
  5140. } else {
  5141. isSuccess = false
  5142. //失败
  5143. c.ServeSuccessJSON(map[string]interface{}{
  5144. "failed_code": -10,
  5145. "msg": res.Transreturnmessage,
  5146. })
  5147. return
  5148. }
  5149. fmt.Println(isSuccess)
  5150. c.ServeSuccessJSON(map[string]interface{}{
  5151. "failed_code": -10,
  5152. "msg": res.Transreturnmessage,
  5153. })
  5154. return
  5155. }
  5156. }
  5157. }
  5158. }
  5159. func (c *SZHisApiController) GetDoctorList() {
  5160. adminUserInfo := c.GetAdminUserInfo()
  5161. orgid := adminUserInfo.CurrentOrgId
  5162. ids := c.GetString("ids")
  5163. admin_user_id, _ := c.GetInt64("admin_user_id")
  5164. roles, _ := service.GetAdminUserInfoByID(orgid, admin_user_id)
  5165. stringarr := strings.Split(ids, ",")
  5166. idss := make([]int64, 0)
  5167. for _, item := range stringarr {
  5168. itemsss, _ := strconv.ParseInt(item, 10, 64)
  5169. id := int64(itemsss)
  5170. idss = append(idss, id)
  5171. }
  5172. //获取所有医生护士信息
  5173. //list, _ := service.GetDoctorList(orgid)
  5174. //批量查询
  5175. list, _ := service.GetBatchDoctorList(idss)
  5176. //获取所有角色名称
  5177. roleList, _ := service.GetRoleList(orgid)
  5178. miConfig, _ := service.FindMedicalInsuranceInfo(orgid)
  5179. for _, item := range list {
  5180. for _, it := range roleList {
  5181. if item.RoleId == it.ID {
  5182. item.Name = it.RoleName
  5183. }
  5184. }
  5185. }
  5186. var doctor_name string
  5187. var doctor_code string
  5188. doctor_name = roles.UserName
  5189. doctor_code = "1001"
  5190. var isSuccess bool = true
  5191. for _, item := range list {
  5192. depart, _ := service.GetDepartMentDetail(item.DepartmentId)
  5193. detail := &models.DocDetail{
  5194. UserName: item.UserName, //医护姓名
  5195. RoleId: item.Name, //医护人员类别
  5196. Sex: strconv.FormatInt(item.Sex, 10), //性别
  5197. CardType: strconv.FormatInt(item.CardType, 10), //证件类型
  5198. IdCard: item.IdCard, //证件号码
  5199. Phone: item.Mobile, //联系电话
  5200. WorkMajorName: item.WorkMajorName, // 现从事专业名称
  5201. Nation: "1", //民族
  5202. BirthDay: 20201022, // 出生日期
  5203. WorkTime: 20201022, //参加工作日期
  5204. Education: strconv.FormatInt(item.Education, 10), //学历
  5205. StudyMajorName: item.StudyMajorName, //所学的专业名称
  5206. CertificateCode: item.MedicalCode, //医(药)师执业证书编码
  5207. MedicalCode: item.DoctorCode, //医(药)师资格证编码
  5208. MedicalRangeCode: strconv.FormatInt(item.DoctorRangeCode, 10), //医师执业范围代码
  5209. MedicalLevel: strconv.FormatInt(item.DoctorLevel, 10), //医生执业资格证中的医师级别
  5210. TypeJob: strconv.FormatInt(item.DoctorTypeJob, 10), //医生执业资格证中的执业类别
  5211. DoctorNumber: item.DoctorNumber, //医保医师编号
  5212. Licensing: strconv.FormatInt(item.Licensing, 10), //多点执业标志
  5213. DoctorServiceStatus: "", //医师医保服务资格状态
  5214. MonitoringLevel: "", //监控等级
  5215. DrugPsychotropicSubstances: "", //毒麻精神药品资格
  5216. HealthCareCode: "", // 母婴保健技术考核合格证书编号
  5217. PlanningTechnicalServiceCode: "", //计划生育技术服务人员合格证编号
  5218. PharmacistType: "", //药师类别
  5219. PharmacistPracticeCategory: "", //药师执业类别
  5220. PharmacistsLicensing: "", //药师执业范围
  5221. PharmacistRegistrationNumber: "", //执业药师注册证编号
  5222. OfficeCode: depart.Number, //科室编码
  5223. JobNumber: item.JobNumber, //工号
  5224. PostName: "", //职位名称
  5225. TechnicalJobLevelCode: "", //专业技术职务级别编码
  5226. IsActive: strconv.FormatInt(item.IsActive, 10), //在职与否
  5227. PrescriptionQualificationIdentification: strconv.FormatInt(item.PrescriptionQualificationIdentification, 10), //处方资格标识
  5228. IdentificationOutpatients: strconv.FormatInt(item.IdentificationOutpatients, 10), //门诊大病医师标识
  5229. OutpatientIllnessCategory: item.OutpatientIllnessCategory, //门诊大病类别
  5230. StartTime: 20201010, //开始日期
  5231. StaffCode: "", //医护人员编码
  5232. EndTime: 0, // 结束日期
  5233. }
  5234. result := service.SzybYS001(doctor_name, doctor_code, miConfig.Code, detail)
  5235. fmt.Println("reuslt", result)
  5236. var dat map[string]interface{}
  5237. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5238. fmt.Println(dat)
  5239. } else {
  5240. fmt.Println(err)
  5241. }
  5242. userJSONBytes, _ := json.Marshal(dat)
  5243. var res Result
  5244. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5245. utils.ErrorLog("解析失败:%v", err)
  5246. c.ServeSuccessJSON(map[string]interface{}{
  5247. "failed_code": -10,
  5248. "msg": res.Transreturnmessage,
  5249. })
  5250. return
  5251. }
  5252. if res.Transreturncode == "00000000" {
  5253. //批量插入数据
  5254. _, err := service.UpdateAdminUserRoleById(item.AdminUserId, orgid)
  5255. fmt.Println("err", err)
  5256. } else {
  5257. isSuccess = false
  5258. //失败
  5259. c.ServeSuccessJSON(map[string]interface{}{
  5260. "failed_code": -10,
  5261. "msg": res.Transreturnmessage,
  5262. })
  5263. return
  5264. }
  5265. fmt.Println(isSuccess)
  5266. c.ServeSuccessJSON(map[string]interface{}{
  5267. "failed_code": -10,
  5268. "msg": res.Transreturnmessage,
  5269. })
  5270. return
  5271. }
  5272. }
  5273. func (c *SZHisApiController) GetMedicalList() {
  5274. adminUserInfo := c.GetAdminUserInfo()
  5275. orgId := adminUserInfo.CurrentOrgId
  5276. id, _ := c.GetInt64("id")
  5277. is_mark, _ := c.GetInt64("is_mark")
  5278. admin_user_id, _ := c.GetInt64("admin_user_id")
  5279. roles, _ := service.GetAdminUserInfoByID(orgId, admin_user_id)
  5280. //去登记
  5281. if is_mark == 0 {
  5282. list, _ := service.GetDoctorListByDetail(orgId, id)
  5283. //获取所有角色名称
  5284. roleList, _ := service.GetRoleList(orgId)
  5285. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  5286. for _, item := range list {
  5287. for _, it := range roleList {
  5288. if item.RoleId == it.ID {
  5289. item.Name = it.RoleName
  5290. }
  5291. }
  5292. }
  5293. var doctor_name string
  5294. var doctor_code string
  5295. doctor_name = roles.UserName
  5296. doctor_code = "1001"
  5297. var isSuccess bool = true
  5298. for _, item := range list {
  5299. detail := &models.DocDetail{
  5300. UserName: item.UserName, //医护姓名
  5301. RoleId: item.Name, //医护人员类别
  5302. Sex: strconv.FormatInt(item.Sex, 10), //性别
  5303. CardType: strconv.FormatInt(item.CardType, 10), //证件类型
  5304. IdCard: item.IdCard, //证件号码
  5305. Phone: item.Mobile, //联系电话
  5306. WorkMajorName: item.WorkMajorName, // 现从事专业名称
  5307. Nation: item.Nation, //民族
  5308. BirthDay: 20201022, // 出生日期
  5309. WorkTime: 20201022, //参加工作日期
  5310. Education: strconv.FormatInt(item.Education, 10), //学历
  5311. StudyMajorName: item.StudyMajorName, //所学的专业名称
  5312. CertificateCode: item.MedicalCode, //医(药)师执业证书编码
  5313. MedicalCode: item.DoctorCode, //医(药)师资格证编码
  5314. MedicalRangeCode: strconv.FormatInt(item.DoctorRangeCode, 10), //医师执业范围代码
  5315. MedicalLevel: strconv.FormatInt(item.DoctorLevel, 10), //医生执业资格证中的医师级别
  5316. TypeJob: strconv.FormatInt(item.DoctorTypeJob, 10), //医生执业资格证中的执业类别
  5317. DoctorNumber: item.DoctorNumber, //医保医师编号
  5318. Licensing: strconv.FormatInt(item.Licensing, 10), //多点执业标志
  5319. DoctorServiceStatus: "", //医师医保服务资格状态
  5320. MonitoringLevel: "", //监控等级
  5321. DrugPsychotropicSubstances: "", //毒麻精神药品资格
  5322. HealthCareCode: "", // 母婴保健技术考核合格证书编号
  5323. PlanningTechnicalServiceCode: "", //计划生育技术服务人员合格证编号
  5324. PharmacistType: "", //药师类别
  5325. PharmacistPracticeCategory: "", //药师执业类别
  5326. PharmacistsLicensing: "", //药师执业范围
  5327. PharmacistRegistrationNumber: "", //执业药师注册证编号
  5328. OfficeCode: "", //科室编码
  5329. JobNumber: item.JobNumber, //工号
  5330. PostName: "", //职位名称
  5331. TechnicalJobLevelCode: "", //专业技术职务级别编码
  5332. IsActive: strconv.FormatInt(item.IsActive, 10), //在职与否
  5333. PrescriptionQualificationIdentification: strconv.FormatInt(item.PrescriptionQualificationIdentification, 10), //处方资格标识
  5334. IdentificationOutpatients: strconv.FormatInt(item.IdentificationOutpatients, 10), //门诊大病医师标识
  5335. OutpatientIllnessCategory: item.OutpatientIllnessCategory, //门诊大病类别
  5336. StartTime: 20201010, //开始日期
  5337. StaffCode: "", //医护人员编码
  5338. EndTime: 0, // 结束日期
  5339. }
  5340. result := service.SzybYS001(doctor_name, doctor_code, miConfig.Code, detail)
  5341. var dat map[string]interface{}
  5342. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5343. fmt.Println(dat)
  5344. } else {
  5345. fmt.Println(err)
  5346. }
  5347. userJSONBytes, _ := json.Marshal(dat)
  5348. var res Result
  5349. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5350. utils.ErrorLog("解析失败:%v", err)
  5351. c.ServeSuccessJSON(map[string]interface{}{
  5352. "failed_code": -10,
  5353. "msg": res.Transreturnmessage,
  5354. })
  5355. return
  5356. }
  5357. if res.Transreturncode == "00000000" {
  5358. //登记成功
  5359. service.UpdateAdminUserRoleById(item.ID, orgId)
  5360. } else {
  5361. isSuccess = false
  5362. //失败
  5363. c.ServeSuccessJSON(map[string]interface{}{
  5364. "failed_code": -10,
  5365. "msg": res.Transreturnmessage,
  5366. })
  5367. return
  5368. }
  5369. fmt.Println(isSuccess)
  5370. c.ServeSuccessJSON(map[string]interface{}{
  5371. "failed_code": -10,
  5372. "msg": res.Transreturnmessage,
  5373. })
  5374. return
  5375. }
  5376. }
  5377. //去撤销
  5378. if is_mark == 1 {
  5379. //获取所有医生护士信息
  5380. list, _ := service.GetDoctorListByDetail(orgId, id)
  5381. //获取所有角色名称
  5382. roleList, _ := service.GetRoleList(orgId)
  5383. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  5384. for _, item := range list {
  5385. for _, it := range roleList {
  5386. if item.RoleId == it.ID {
  5387. item.Name = it.RoleName
  5388. }
  5389. }
  5390. }
  5391. var doctor_name string
  5392. var doctor_code string
  5393. doctor_name = "黄亦轩"
  5394. doctor_code = "1001"
  5395. var isSuccess bool = true
  5396. for _, item := range list {
  5397. detail := &models.DocDetail{
  5398. UserName: item.UserName, //医护姓名
  5399. RoleId: item.Name, //医护人员类别
  5400. Sex: strconv.FormatInt(item.Sex, 10), //性别
  5401. CardType: strconv.FormatInt(item.CardType, 10), //证件类型
  5402. IdCard: item.IdCard, //证件号码
  5403. Phone: item.Mobile, //联系电话
  5404. WorkMajorName: item.WorkMajorName, // 现从事专业名称
  5405. Nation: item.Nation, //民族
  5406. BirthDay: 20201022, // 出生日期
  5407. WorkTime: 20201022, //参加工作日期
  5408. Education: strconv.FormatInt(item.Education, 10), //学历
  5409. StudyMajorName: item.StudyMajorName, //所学的专业名称
  5410. CertificateCode: item.MedicalCode, //医(药)师执业证书编码
  5411. MedicalCode: item.DoctorCode, //医(药)师资格证编码
  5412. MedicalRangeCode: strconv.FormatInt(item.DoctorRangeCode, 10), //医师执业范围代码
  5413. MedicalLevel: strconv.FormatInt(item.DoctorLevel, 10), //医生执业资格证中的医师级别
  5414. TypeJob: strconv.FormatInt(item.DoctorTypeJob, 10), //医生执业资格证中的执业类别
  5415. DoctorNumber: item.DoctorNumber, //医保医师编号
  5416. Licensing: strconv.FormatInt(item.Licensing, 10), //多点执业标志
  5417. DoctorServiceStatus: "", //医师医保服务资格状态
  5418. MonitoringLevel: "", //监控等级
  5419. DrugPsychotropicSubstances: "", //毒麻精神药品资格
  5420. HealthCareCode: "", // 母婴保健技术考核合格证书编号
  5421. PlanningTechnicalServiceCode: "", //计划生育技术服务人员合格证编号
  5422. PharmacistType: "", //药师类别
  5423. PharmacistPracticeCategory: "", //药师执业类别
  5424. PharmacistsLicensing: "", //药师执业范围
  5425. PharmacistRegistrationNumber: "", //执业药师注册证编号
  5426. OfficeCode: "", //科室编码
  5427. JobNumber: item.JobNumber, //工号
  5428. PostName: "", //职位名称
  5429. TechnicalJobLevelCode: "", //专业技术职务级别编码
  5430. IsActive: strconv.FormatInt(item.IsActive, 10), //在职与否
  5431. PrescriptionQualificationIdentification: strconv.FormatInt(item.PrescriptionQualificationIdentification, 10), //处方资格标识
  5432. IdentificationOutpatients: strconv.FormatInt(item.IdentificationOutpatients, 10), //门诊大病医师标识
  5433. OutpatientIllnessCategory: item.OutpatientIllnessCategory, //门诊大病类别
  5434. StartTime: 20201010, //开始日期
  5435. StaffCode: "", //医护人员编码
  5436. EndTime: 0, // 结束日期
  5437. }
  5438. result := service.SzybYS002(doctor_name, doctor_code, miConfig.Code, detail)
  5439. var dat map[string]interface{}
  5440. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5441. fmt.Println(dat)
  5442. } else {
  5443. fmt.Println(err)
  5444. }
  5445. userJSONBytes, _ := json.Marshal(dat)
  5446. var res Result
  5447. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5448. utils.ErrorLog("解析失败:%v", err)
  5449. c.ServeSuccessJSON(map[string]interface{}{
  5450. "failed_code": -10,
  5451. "msg": res.Transreturnmessage,
  5452. })
  5453. return
  5454. }
  5455. if res.Transreturncode == "00000000" {
  5456. //去撤销
  5457. service.UpdateAdminUserRoleById(item.ID, orgId)
  5458. } else {
  5459. isSuccess = false
  5460. //失败
  5461. c.ServeSuccessJSON(map[string]interface{}{
  5462. "failed_code": -10,
  5463. "msg": res.Transreturnmessage,
  5464. })
  5465. return
  5466. }
  5467. fmt.Println(isSuccess)
  5468. c.ServeSuccessJSON(map[string]interface{}{
  5469. "failed_code": -10,
  5470. "msg": res.Transreturnmessage,
  5471. })
  5472. return
  5473. }
  5474. }
  5475. }
  5476. func (c *SZHisApiController) GetUpdateMedicalList() {
  5477. adminUserInfo := c.GetAdminUserInfo()
  5478. orgId := adminUserInfo.CurrentOrgId
  5479. //获取所有医生护士信息
  5480. list, _ := service.GetDoctorList(orgId)
  5481. //获取所有角色名称
  5482. roleList, _ := service.GetRoleList(orgId)
  5483. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  5484. for _, item := range list {
  5485. for _, it := range roleList {
  5486. if item.RoleId == it.ID {
  5487. item.Name = it.RoleName
  5488. }
  5489. }
  5490. }
  5491. var doctor_name string
  5492. var doctor_code string
  5493. doctor_name = "黄亦轩"
  5494. doctor_code = "1001"
  5495. var pagesize int = 50
  5496. var start int = 1
  5497. var stop int
  5498. var pagecount int
  5499. var curpage int
  5500. var isSuccess bool = true
  5501. //总页数,向上取整,注意除之前要先转换类型为float64
  5502. pagecount = int(math.Ceil(float64(len(list)) / float64(pagesize)))
  5503. var ress []*Result
  5504. for curpage = 1; curpage <= pagecount; curpage++ {
  5505. if curpage == 1 {
  5506. start = 1
  5507. } else {
  5508. start = (curpage-1)*pagesize + 1
  5509. }
  5510. stop = curpage * pagesize
  5511. if stop > len(list) {
  5512. stop = len(list)
  5513. }
  5514. //这里就可以查看开始和结束了
  5515. fmt.Println(list[start-1 : stop])
  5516. var customs []*models.DocDetail
  5517. for _, item := range list {
  5518. detail := &models.DocDetail{
  5519. StaffCode: "", //医护人员编码
  5520. UserName: item.UserName, //医护人员姓名
  5521. RoleId: item.Name, //医护人员类别
  5522. Sex: "", //性别
  5523. CardType: "", //证件类型
  5524. IdCard: "", //证件号码
  5525. Phone: "", //联系电话
  5526. WorkMajorName: "", //现从事专业名称
  5527. Nation: "", //民族
  5528. BirthDay: 20201022, //出生日期
  5529. WorkTime: 20201022, //参加工作日期
  5530. Education: "", //学历
  5531. StudyMajorName: "", //所学的专业名称
  5532. CertificateCode: "", //证书编码
  5533. MedicalCode: "", //医师资格编码
  5534. MedicalRangeCode: "", //医师执业范围代码
  5535. MedicalLevel: "", //医生级别
  5536. TypeJob: "", //职业类别
  5537. DoctorNumber: "", //医师编号
  5538. Licensing: "", //职业标志
  5539. DoctorServiceStatus: "", //医师医保服务资格状态
  5540. MonitoringLevel: "", //监控等级
  5541. DrugPsychotropicSubstances: "", //毒麻精神药品资格
  5542. HealthCareCode: "", // 母婴保健技术考核合格证书编号
  5543. PlanningTechnicalServiceCode: "", //计划生育技术服务人员合格证编号
  5544. PharmacistType: "", //药师类别
  5545. PharmacistPracticeCategory: "", //药师执业类别
  5546. PharmacistsLicensing: "", //药师执业范围
  5547. PharmacistRegistrationNumber: "", //执业药师注册证编号
  5548. OfficeCode: "", //科室编码
  5549. JobNumber: "", //工号
  5550. PostName: "", //职位名称
  5551. TechnicalJobLevelCode: "", //专业技术职务级别编码
  5552. IsActive: "", //在职与否
  5553. PrescriptionQualificationIdentification: "", //处方资格标识
  5554. IdentificationOutpatients: "", //门诊大病医师标识
  5555. OutpatientIllnessCategory: "", //门诊大病类别
  5556. StartTime: 20201022, //开始日期
  5557. EndTime: 20201022,
  5558. }
  5559. customs = append(customs, detail)
  5560. }
  5561. result := service.SzybYS003(doctor_name, doctor_code, miConfig.Code, customs)
  5562. var dat map[string]interface{}
  5563. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5564. fmt.Println(dat)
  5565. } else {
  5566. fmt.Println(err)
  5567. }
  5568. userJSONBytes, _ := json.Marshal(dat)
  5569. var res Result
  5570. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5571. utils.ErrorLog("解析失败:%v", err)
  5572. c.ServeSuccessJSON(map[string]interface{}{
  5573. "failed_code": -10,
  5574. "msg": res.Transreturnmessage,
  5575. })
  5576. return
  5577. }
  5578. if res.Transreturncode == "00000000" {
  5579. ress = append(ress, &res)
  5580. } else {
  5581. isSuccess = false
  5582. //失败
  5583. c.ServeSuccessJSON(map[string]interface{}{
  5584. "failed_code": -10,
  5585. "msg": res.Transreturnmessage,
  5586. })
  5587. return
  5588. }
  5589. fmt.Println(isSuccess)
  5590. c.ServeSuccessJSON(map[string]interface{}{
  5591. "failed_code": -10,
  5592. "msg": res.Transreturnmessage,
  5593. })
  5594. return
  5595. }
  5596. }
  5597. func (c *SZHisApiController) GetGoodsList() {
  5598. adminUserInfo := c.GetAdminUserInfo()
  5599. orgId := adminUserInfo.CurrentOrgId
  5600. ids := c.GetString("ids")
  5601. admin_user_id, _ := c.GetInt64("admin_user_id")
  5602. roles, _ := service.GetAdminUserInfoByID(orgId, admin_user_id)
  5603. stringarr := strings.Split(ids, ",")
  5604. idss := make([]int64, 0)
  5605. for _, item := range stringarr {
  5606. itemsss, _ := strconv.ParseInt(item, 10, 64)
  5607. id := int64(itemsss)
  5608. idss = append(idss, id)
  5609. }
  5610. //批量获取所有耗材信息
  5611. list, _ := service.GetBatchGoodInformationList(idss)
  5612. //获取单位
  5613. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  5614. var doctor_name string
  5615. var doctor_code string
  5616. doctor_name = roles.UserName
  5617. doctor_code = "1001"
  5618. var isSuccess bool = true
  5619. for _, item := range list {
  5620. detail := &models.XtGoodInformation{
  5621. GoodName: item.GoodName,
  5622. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  5623. ManufacturerName: item.ManufacturerName,
  5624. ProductionType: item.ProductionType,
  5625. SpecialMedical: item.SpecialMedical,
  5626. BuyPrice: item.BuyPrice,
  5627. SellPrice: item.SellPrice,
  5628. Remark: item.Remark,
  5629. SpecificationName: item.SpecificationName,
  5630. }
  5631. result := service.SzybYML007(doctor_name, doctor_code, miConfig.Code, detail)
  5632. fmt.Println("reuslt", result)
  5633. var dat map[string]interface{}
  5634. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5635. fmt.Println(dat)
  5636. } else {
  5637. fmt.Println(err)
  5638. }
  5639. userJSONBytes, _ := json.Marshal(dat)
  5640. var res Result
  5641. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5642. utils.ErrorLog("解析失败:%v", err)
  5643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5644. return
  5645. }
  5646. if res.Transreturncode == "00000000" {
  5647. //备案成功返回状态
  5648. _, err := service.UpdateGoodInformaitonByDetail(item.ID)
  5649. fmt.Println("err", err)
  5650. } else {
  5651. isSuccess = false
  5652. //失败
  5653. c.ServeSuccessJSON(map[string]interface{}{
  5654. "failed_code": -10,
  5655. "msg": res.Transreturnmessage,
  5656. })
  5657. return
  5658. }
  5659. fmt.Println(isSuccess)
  5660. c.ServeSuccessJSON(map[string]interface{}{
  5661. "failed_code": -10,
  5662. "msg": res.Transreturnmessage,
  5663. })
  5664. return
  5665. }
  5666. }
  5667. type Charset string
  5668. const (
  5669. UTF8 = Charset("UTF-8")
  5670. GB18030 = Charset("GB18030")
  5671. )
  5672. func ConvertToString(src string, srcCode string, tagCode string) string {
  5673. srcCoder := mahonia.NewDecoder(srcCode)
  5674. srcResult := srcCoder.ConvertString(src)
  5675. tagCoder := mahonia.NewDecoder(tagCode)
  5676. _, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
  5677. result := string(cdata)
  5678. return result
  5679. }