his_api_controller.go 180KB

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