his_api_controller.go 211KB

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