his_api_controller.go 210KB

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