his_api_controller.go 181KB

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