his_api_controller.go 208KB

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