sz_his_api_controller.go 215KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032
  1. package sz
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "gdyb/controllers"
  6. "gdyb/enums"
  7. "gdyb/models"
  8. "gdyb/service"
  9. "gdyb/utils"
  10. "github.com/astaxie/beego"
  11. "github.com/axgle/mahonia"
  12. "math/rand"
  13. //"github.com/axgle/mahonia"
  14. "math"
  15. //"math/rand"µ
  16. "strconv"
  17. "strings"
  18. //"strings"
  19. "syscall"
  20. "time"
  21. "unsafe"
  22. )
  23. type Result struct {
  24. Transtime string `json:"transTime"`
  25. Transtype string `json:"transType"`
  26. Transreturncode string `json:"transReturnCode"`
  27. Transreturnmessage string `json:"transReturnMessage"`
  28. Transversion string `json:"transVersion"`
  29. Serialnumber string `json:"serialNumber"`
  30. Cardarea string `json:"cardArea"`
  31. Hospitalcode string `json:"hospitalCode"`
  32. Operatorcode string `json:"operatorCode"`
  33. Operatorname string `json:"operatorName"`
  34. Operatorpass string `json:"operatorPass"`
  35. Transbody struct {
  36. Akc190 string `json:"akc190"`
  37. Listsize int `json:"listsize"`
  38. Outputlist []struct {
  39. Aae072 string `json:"aae072"`
  40. Bkc369 string `json:"bkc369"`
  41. Bkf500 string `json:"bkf500"`
  42. Aka111 string `json:"aka111"`
  43. Ake001 string `json:"ake001"`
  44. Ake002 string `json:"ake002"`
  45. Bkm017 string `json:"bkm017"`
  46. Ake005 string `json:"ake005"`
  47. Ake006 string `json:"ake006"`
  48. Akc225 float64 `json:"akc225"`
  49. Akc226 float64 `json:"akc226"`
  50. Akc264 float64 `json:"akc264"`
  51. Aka065 string `json:"aka065"`
  52. Cka319 float64 `json:"cka319"`
  53. Akc268 float64 `json:"akc268"`
  54. } `json:"outputlist"`
  55. } `json:"transBody"`
  56. Verifycode string `json:"verifyCode"`
  57. Extenddeviceid string `json:"extendDeviceId"`
  58. Transchannel string `json:"transChannel"`
  59. Extenduserid string `json:"extendUserId"`
  60. Extendserialnumber string `json:"extendSerialNumber"`
  61. Caz055 string `json:"caz055"`
  62. Aae501 string `json:"aae501"`
  63. }
  64. type ResultOne struct {
  65. Transtime string `json:"transTime"`
  66. Transtype string `json:"transType"`
  67. Transreturncode string `json:"transReturnCode"`
  68. Transreturnmessage string `json:"transReturnMessage"`
  69. Transversion string `json:"transVersion"`
  70. Serialnumber string `json:"serialNumber"`
  71. Cardarea string `json:"cardArea"`
  72. Hospitalcode string `json:"hospitalCode"`
  73. Operatorcode string `json:"operatorCode"`
  74. Operatorname string `json:"operatorName"`
  75. Operatorpass string `json:"operatorPass"`
  76. Transbody struct {
  77. Ckc618 string `json:"ckc618"`
  78. Akc264 float64 `json:"akc264"`
  79. Akb068 int `json:"akb068"`
  80. Akb066 float64 `json:"akb066"`
  81. Akb067 int `json:"akb067"`
  82. Aae240 float64 `json:"aae240"`
  83. Outputlist []struct {
  84. Aaa036 string `json:"aaa036"`
  85. Aae019 float64 `json:"aae019"`
  86. } `json:"outputlist"`
  87. Outputlist2 []interface{} `json:"outputlist2"`
  88. } `json:"transBody"`
  89. Verifycode string `json:"verifyCode"`
  90. Extenddeviceid string `json:"extendDeviceId"`
  91. Transchannel string `json:"transChannel"`
  92. Extenduserid string `json:"extendUserId"`
  93. Extendserialnumber string `json:"extendSerialNumber"`
  94. Caz055 string `json:"caz055"`
  95. Aae501 string `json:"aae501"`
  96. }
  97. type ResultTwo struct {
  98. Transtime string `json:"transTime"`
  99. Transtype string `json:"transType"`
  100. Transreturncode string `json:"transReturnCode"`
  101. Transreturnmessage string `json:"transReturnMessage"`
  102. Transversion string `json:"transVersion"`
  103. Serialnumber string `json:"serialNumber"`
  104. Cardarea string `json:"cardArea"`
  105. Hospitalcode string `json:"hospitalCode"`
  106. Operatorcode string `json:"operatorCode"`
  107. Operatorname string `json:"operatorName"`
  108. Operatorpass string `json:"operatorPass"`
  109. Transbody struct {
  110. Ckc618 string `json:"ckc618"`
  111. Akc264 float64 `json:"akc264"`
  112. Akb068 float64 `json:"akb068"`
  113. Akb066 float64 `json:"akb066"`
  114. Akb067 float64 `json:"akb067"`
  115. Aae240 float64 `json:"aae240"`
  116. Outputlist1 []struct {
  117. Aka111 string `json:"aka111"`
  118. Bka058 float64 `json:"bka058"`
  119. } `json:"outputlist1"`
  120. Outputlist2 []struct {
  121. Aaa036 string `json:"aaa036"`
  122. Aae019 float64 `json:"aae019"`
  123. } `json:"outputlist2"`
  124. Outputlist3 []interface{} `json:"outputlist3"`
  125. } `json:"transBody"`
  126. Verifycode string `json:"verifyCode"`
  127. Extenddeviceid string `json:"extendDeviceId"`
  128. Transchannel string `json:"transChannel"`
  129. Extenduserid string `json:"extendUserId"`
  130. Extendserialnumber string `json:"extendSerialNumber"`
  131. Caz055 string `json:"caz055"`
  132. Aae501 string `json:"aae501"`
  133. }
  134. type ResultThree struct {
  135. Transtime string `json:"transTime"`
  136. Transtype string `json:"transType"`
  137. Transreturncode string `json:"transReturnCode"`
  138. Transreturnmessage string `json:"transReturnMessage"`
  139. Transversion string `json:"transVersion"`
  140. Serialnumber string `json:"serialNumber"`
  141. Cardarea string `json:"cardArea"`
  142. Hospitalcode string `json:"hospitalCode"`
  143. Operatorcode string `json:"operatorCode"`
  144. Operatorname string `json:"operatorName"`
  145. Operatorpass string `json:"operatorPass"`
  146. Transbody struct {
  147. Baz700 string `json:"baz700"`
  148. Ckc618 string `json:"ckc618"`
  149. } `json:"transBody"`
  150. Verifycode string `json:"verifyCode"`
  151. Extenddeviceid string `json:"extendDeviceId"`
  152. Transchannel string `json:"transChannel"`
  153. Extenduserid string `json:"extendUserId"`
  154. Extendserialnumber string `json:"extendSerialNumber"`
  155. Caz055 string `json:"caz055"`
  156. Aae501 string `json:"aae501"`
  157. }
  158. type ResultFive struct {
  159. Transtime string `json:"transTime"`
  160. Transtype string `json:"transType"`
  161. Transreturncode string `json:"transReturnCode"`
  162. Transreturnmessage string `json:"transReturnMessage"`
  163. Transversion string `json:"transVersion"`
  164. Serialnumber string `json:"serialNumber"`
  165. Cardarea string `json:"cardArea"`
  166. Hospitalcode string `json:"hospitalCode"`
  167. Operatorcode string `json:"operatorCode"`
  168. Operatorname string `json:"operatorName"`
  169. Operatorpass string `json:"operatorPass"`
  170. Transbody struct {
  171. Akc190 string `json:"akc190"`
  172. Listsize int `json:"listsize"`
  173. Outputlist []struct {
  174. Aae072 string `json:"aae072"`
  175. Bkf500 string `json:"bkf500"`
  176. Baz700 string `json:"baz700"`
  177. Bce574 string `json:"bce574"`
  178. } `json:"outputlist"`
  179. } `json:"transBody"`
  180. Verifycode string `json:"verifyCode"`
  181. Extenddeviceid string `json:"extendDeviceId"`
  182. Transchannel string `json:"transChannel"`
  183. Extenduserid string `json:"extendUserId"`
  184. Extendserialnumber string `json:"extendSerialNumber"`
  185. Caz055 string `json:"caz055"`
  186. Aae501 string `json:"aae501"`
  187. }
  188. type ResultFour struct {
  189. Transtime string `json:"transTime"`
  190. Transtype string `json:"transType"`
  191. Transreturncode string `json:"transReturnCode"`
  192. Transreturnmessage string `json:"transReturnMessage"`
  193. Transversion string `json:"transVersion"`
  194. Serialnumber string `json:"serialNumber"`
  195. Cardarea string `json:"cardArea"`
  196. Hospitalcode string `json:"hospitalCode"`
  197. Operatorcode string `json:"operatorCode"`
  198. Operatorname string `json:"operatorName"`
  199. Operatorpass string `json:"operatorPass"`
  200. Transbody struct {
  201. Akc190 string `json:"akc190"`
  202. Akc194 int `json:"akc194"`
  203. Bae917 int64 `json:"bae917"`
  204. Aka018 string `json:"aka018"`
  205. Aka030 string `json:"aka030"`
  206. Ckc618 string `json:"ckc618"`
  207. Akc264 float64 `json:"akc264"`
  208. Akb068 float64 `json:"akb068"`
  209. Akb066 float64 `json:"akb066"`
  210. Akb067 float64 `json:"akb067"`
  211. Cke298 float64 `json:"cke298"`
  212. Aae240 float64 `json:"aae240"`
  213. Outputlist1 []struct {
  214. Aae072 string `json:"aae072"`
  215. Bkc369 string `json:"bkc369"`
  216. Bkf500 string `json:"bkf500"`
  217. Aka111 string `json:"aka111"`
  218. Ake001 string `json:"ake001"`
  219. Ake002 string `json:"ake002"`
  220. Bkm017 string `json:"bkm017"`
  221. Ake005 string `json:"ake005"`
  222. Ake006 string `json:"ake006"`
  223. Ala026 string `json:"ala026"`
  224. Aka070 string `json:"aka070"`
  225. Aka074 string `json:"aka074"`
  226. Akc226 float64 `json:"akc226"`
  227. Akc225 float64 `json:"akc225"`
  228. Akc264 float64 `json:"akc264"`
  229. Aka067 string `json:"aka067"`
  230. Akc271 int `json:"akc271"`
  231. Bkc320 string `json:"bkc320"`
  232. Cke400 string `json:"cke400"`
  233. Ckc618 string `json:"ckc618"`
  234. Bka069 int64 `json:"bka069"`
  235. Aka018 string `json:"aka018"`
  236. Aka030 string `json:"aka030"`
  237. Aka065 string `json:"aka065"`
  238. Cka319 float64 `json:"cka319"`
  239. Akc268 float64 `json:"akc268"`
  240. } `json:"outputlist1"`
  241. Outputlist2 []struct {
  242. Aka111 string `json:"aka111"`
  243. Bka058 float64 `json:"bka058"`
  244. } `json:"outputlist2"`
  245. Outputlist3 []struct {
  246. Aaa036 string `json:"aaa036"`
  247. Aae019 float64 `json:"aae019"`
  248. } `json:"outputlist3"`
  249. } `json:"transBody"`
  250. Verifycode string `json:"verifyCode"`
  251. Extenddeviceid string `json:"extendDeviceId"`
  252. Transchannel string `json:"transChannel"`
  253. Extenduserid string `json:"extendUserId"`
  254. Extendserialnumber string `json:"extendSerialNumber"`
  255. Caz055 string `json:"caz055"`
  256. Aae501 string `json:"aae501"`
  257. }
  258. type ResultMZ001 struct {
  259. Transtime string `json:"transTime"`
  260. Transtype string `json:"transType"`
  261. Transreturncode string `json:"transReturnCode"`
  262. Transreturnmessage string `json:"transReturnMessage"`
  263. Transversion string `json:"transVersion"`
  264. Serialnumber string `json:"serialNumber"`
  265. Cardarea string `json:"cardArea"`
  266. Hospitalcode string `json:"hospitalCode"`
  267. Operatorcode string `json:"operatorCode"`
  268. Operatorname string `json:"operatorName"`
  269. Operatorpass string `json:"operatorPass"`
  270. Transbody struct {
  271. Aaz515 string `json:"aaz515"`
  272. Aaz500 string `json:"aaz500"`
  273. Aac001 float64 `json:"aac001"`
  274. Aac999 string `json:"aac999"`
  275. Aac002 string `json:"aac002"`
  276. Aac058 string `json:"aac058"`
  277. Aac147 string `json:"aac147"`
  278. Aac003 string `json:"aac003"`
  279. Aac004 string `json:"aac004"`
  280. Aac006 float64 `json:"aac006"`
  281. Bae093 float64 `json:"bae093"`
  282. Cac215 string `json:"cac215"`
  283. Aac066 string `json:"aac066"`
  284. Aac008 string `json:"aac008"`
  285. Bke404 string `json:"bke404"`
  286. Aae240 float64 `json:"aae240"`
  287. Bkc346 string `json:"bkc346"`
  288. Ckc601 string `json:"ckc601"`
  289. Caz574 string `json:"caz574"`
  290. Caz654 string `json:"caz654"`
  291. Ckc403 string `json:"ckc403"`
  292. Ckc362 string `json:"ckc362"`
  293. Ckc363 string `json:"ckc363"`
  294. Outputlist1 []struct {
  295. Aab001 float64 `json:"aab001"`
  296. Aab999 string `json:"aab999"`
  297. Aab004 string `json:"aab004"`
  298. Aab019 string `json:"aab019"`
  299. Aae140 string `json:"aae140"`
  300. Aae030 float64 `json:"aae030"`
  301. Aae031 string `json:"aae031"`
  302. Bcc334 string `json:"bcc334"`
  303. Aac031 string `json:"aac031"`
  304. } `json:"outputlist1"`
  305. } `json:"transBody"`
  306. Verifycode string `json:"verifyCode"`
  307. Extenddeviceid string `json:"extendDeviceId"`
  308. Transchannel string `json:"transChannel"`
  309. Extenduserid string `json:"extendUserId"`
  310. Extendserialnumber string `json:"extendSerialNumber"`
  311. Caz055 string `json:"caz055"`
  312. Aae501 string `json:"aae501"`
  313. }
  314. type SZHisApiController struct {
  315. controllers.BaseAuthAPIController
  316. }
  317. func SZHisManagerApiRegistRouters() {
  318. //挂号
  319. beego.Router("/sz/api/register/get", &SZHisApiController{}, "get:GetRegisterInfo")
  320. //结算
  321. beego.Router("/sz/api/settle/get", &SZHisApiController{}, "get:GetSettleInfo")
  322. //预结算
  323. beego.Router("/sz/api/presettle/get", &SZHisApiController{}, "get:GetPreSettleInfo")
  324. //退费
  325. beego.Router("/sz/api/refund/get", &SZHisApiController{}, "get:Refund")
  326. beego.Router("/sz/api/readcard", &SZHisApiController{}, "get:ReadCard")
  327. beego.Router("sz/api/refundnumber/get", &SZHisApiController{}, "get:RefundNumber")
  328. beego.Router("/sz/api/monthrefund/get", &SZHisApiController{}, "get:MonthRefund")
  329. //查询交易
  330. beego.Router("/sz/api/settle/query", &SZHisApiController{}, "get:GetSettleAccounts")
  331. //beego.Router("/sz/api/detail/upload", &SZHisApiController{}, "get:GetUploadDetail")
  332. beego.Router("/sz/api/detail/cancel", &SZHisApiController{}, "get:CancelOrderDetail")
  333. //
  334. ////机构药品目录备案
  335. beego.Router("/sz/api/drug/get", &SZHisApiController{}, "get:GetDrugList")
  336. ////协议机构诊疗项目
  337. beego.Router("/sz/api/treatment/get", &SZHisApiController{}, "get:GetTreatmentProject")
  338. ////协议机构目录备案撤销
  339. beego.Router("/sz/api/revocation/get", &SZHisApiController{}, "get:GetRevocation")
  340. //
  341. ////定点机构约定信息查询
  342. //beego.Router("/sz/api/information/query/get",&SZHisApiController{},"get:GetInformationQuery")
  343. ////-医药师信息登记
  344. beego.Router("/sz/api/doctor/get", &SZHisApiController{}, "get:GetDoctorList")
  345. ////医药师执业状态变更
  346. beego.Router("/sz/api/medical/get", &SZHisApiController{}, "get:GetMedicalList")
  347. ////医药师信息更新
  348. //beego.Router("/sz/api/update/medical/get", &SZHisApiController{}, "get:GetUpdateMedicalList")
  349. ////协议机构材料目录备案
  350. //
  351. beego.Router("/sz/api/goods/get", &SZHisApiController{}, "get:GetGoodsList")
  352. }
  353. func IntPtr(n int) uintptr {
  354. return uintptr(n)
  355. }
  356. func StrPtr(s string) uintptr {
  357. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  358. }
  359. type Custom struct {
  360. DetItemFeeSumamt string
  361. Cut string
  362. FeedetlSn string
  363. Price string
  364. MedListCodg string
  365. Type int64
  366. AdviceId int64
  367. ProjectId int64
  368. ItemId int64
  369. }
  370. func (c *SZHisApiController) ReadCard() {
  371. id_card_type, _ := c.GetInt64("id_card_type")
  372. adminInfo := c.GetAdminUserInfo()
  373. if id_card_type != 1 {
  374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorNoReadCardException)
  375. return
  376. }
  377. month := time.Unix(1557042972, 0).Format("1")
  378. year := time.Now().Format("2006")
  379. month = time.Now().Format("01")
  380. day := time.Now().Format("02")
  381. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  382. number := miConfig.Code + year + month + day +
  383. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  384. id_card_number, health_card_no, _, ret4 := ReadBasCard("MZ002" + "|" + number + "|" + miConfig.Code + "|")
  385. if ret4 == 0 {
  386. patient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  387. if patient.ID == 0 {
  388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  389. return
  390. } else {
  391. c.ServeSuccessJSON(map[string]interface{}{
  392. "patient": patient,
  393. "health_card_no": health_card_no,
  394. })
  395. }
  396. } else {
  397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  398. return
  399. }
  400. }
  401. //获取读卡信息 -- 门诊挂号
  402. //func (c *SZHisApiController) GetRegisterInfo() {
  403. // adminInfo := c.GetAdminUserInfo()
  404. // admin_user_id, _ := c.GetInt64("admin_user_id")
  405. // patient_id, _ := c.GetInt64("id")
  406. // record_time := c.GetString("record_time")
  407. // settlementValue, _ := c.GetInt64("settlement_value")
  408. // medical_insurance_card := c.GetString("medical_insurance_card")
  409. // name := c.GetString("name")
  410. // id_card_type, _ := c.GetInt64("id_card_type")
  411. // certificates, _ := c.GetInt64("certificates")
  412. // medical_care, _ := c.GetInt64("medical_care")
  413. // birthday := c.GetString("birthday")
  414. // id_card := c.GetString("id_card")
  415. // register_type, _ := c.GetInt64("register")
  416. // doctor, _ := c.GetInt64("doctor")
  417. // department, _ := c.GetInt64("department")
  418. // gender, _ := c.GetInt64("sex")
  419. // registration_fee, _ := c.GetFloat("registration_fee")
  420. // medical_expenses, _ := c.GetFloat("medical_expenses")
  421. // social_type, _ := c.GetInt64("social_type")
  422. //
  423. // is_yidi, _ := c.GetInt64("is_yidi")
  424. //
  425. // timeLayout := "2006-01-02"
  426. // loc, _ := time.LoadLocation("Local")
  427. // birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  428. // birthUnix := birthdays.Unix()
  429. //
  430. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  431. // if err != nil {
  432. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  433. // return
  434. // }
  435. //
  436. // var patient service.Patients
  437. // if patient_id == 0 {
  438. // patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  439. // } else {
  440. // patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  441. // }
  442. //
  443. // miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  444. // if patient.ID == 0 {
  445. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  446. // return
  447. // }
  448. // if len(patient.IdCardNo) == 0 {
  449. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  450. // return
  451. // }
  452. //
  453. // adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  454. // his, _ := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient_id, theTime.Unix())
  455. //
  456. // var custom_code string
  457. // var custom_project_name string
  458. // var allPrice float64
  459. //
  460. // switch register_type {
  461. // case 1:
  462. // custom_code = "110100002"
  463. // custom_project_name = "普通门诊"
  464. // allPrice = 10
  465. // break
  466. // case 3:
  467. // custom_code = "110200002-2"
  468. // custom_project_name = "主任医师"
  469. // allPrice = 10
  470. //
  471. // break
  472. // case 2:
  473. // custom_code = "110200002-3"
  474. // custom_project_name = "副主任医师"
  475. // allPrice = 10
  476. //
  477. // break
  478. // case 4:
  479. // custom_code = "0"
  480. // custom_project_name = "免受诊金"
  481. // allPrice = 0
  482. // break
  483. // case 5:
  484. // custom_code = "110200002-1"
  485. // custom_project_name = "专家"
  486. // allPrice = 10
  487. //
  488. // break
  489. // }
  490. //
  491. // if his.ID == 0 {
  492. //
  493. // var doctor_name string
  494. // var doctor_code string
  495. // if adminRole.ID == 0 {
  496. //
  497. // doctor_name = ""
  498. // doctor_code = "1001"
  499. // doctor_name = ""
  500. // doctor_code = ""
  501. //
  502. // } else {
  503. // doctor_name = adminRole.UserName
  504. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  505. //
  506. // }
  507. // month := time.Unix(1557042972, 0).Format("1")
  508. // year := time.Now().Format("2006")
  509. // month = time.Now().Format("01")
  510. // day := time.Now().Format("02")
  511. //
  512. // //流水号
  513. // //
  514. // number := miConfig.Code + year + month + day +
  515. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  516. // mz_number := year + month + day + strconv.FormatInt(patient_id, 10) +
  517. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000))
  518. // //1.判断读卡类型
  519. // //2.读卡 获取交易验证码,医疗证号,发卡地区行政区划代码
  520. // yiliao_number, id_card_number, verifyCode, version_code, _, ret4 := ReadBasCardGetNumber("MZ002" + "|" + number + "|" + miConfig.Code + "|")
  521. // fmt.Println(yiliao_number)
  522. // fmt.Println(id_card_number)
  523. // fmt.Println(verifyCode)
  524. // fmt.Println(version_code)
  525. // fmt.Println(ret4)
  526. //
  527. // dept_code := "0305"
  528. // is_yidi = 1
  529. // tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  530. // //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  531. // if tempPatient.ID == patient_id {
  532. // if ret4 == 0 { //本地卡流程
  533. // if is_yidi == 1 {
  534. // //本地就医流程
  535. // //挂号
  536. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, dept_code, yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice,medical_care)
  537. // var dat map[string]interface{}
  538. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  539. // fmt.Println(dat)
  540. // } else {
  541. // fmt.Println(err)
  542. // }
  543. // userJSONBytes, _ := json.Marshal(dat)
  544. // var res ResultOne
  545. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  546. // utils.ErrorLog("解析失败:%v", err)
  547. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  548. // return
  549. // }
  550. // if res.Transreturncode == "00000000" {
  551. // his := models.VMHisPatient{
  552. // Name: name,
  553. // Gender: gender,
  554. // Birthday: birthUnix,
  555. // MedicalTreatmentType: medical_care,
  556. // IdType: certificates,
  557. // IdCardNo: id_card,
  558. // BalanceAccountsType: settlementValue,
  559. // SocialType: social_type,
  560. // MedicalInsuranceNumber: medical_insurance_card,
  561. // RegisterType: register_type,
  562. // RegisterCost: registration_fee,
  563. // TreatmentCost: medical_expenses,
  564. // Status: 1,
  565. // Ctime: time.Now().Unix(),
  566. // Mtime: time.Now().Unix(),
  567. // Iinfo: resp_result,
  568. // PatientId: patient.ID,
  569. // RecordDate: theTime.Unix(),
  570. // UserOrgId: adminInfo.CurrentOrgId,
  571. // AdminUserId: admin_user_id,
  572. // IsReturn: 1,
  573. // IdCardType: id_card_type,
  574. // Doctor: doctor,
  575. // Departments: department,
  576. // YiliaoNumber: yiliao_number,
  577. // MzNumber: number,
  578. // Number: mz_number,
  579. // }
  580. // service.CreateHisPatientTwo(&his)
  581. // c.ServeSuccessJSON(map[string]interface{}{
  582. // "msg": "挂号成功",
  583. // })
  584. // } else {
  585. // c.ServeSuccessJSON(map[string]interface{}{
  586. // "failed_code": -10,
  587. // "msg": res.Transreturnmessage,
  588. // })
  589. // return
  590. // }
  591. //
  592. // } else {
  593. // //异地就医流程
  594. // //异地走鉴权流程
  595. // //authResult := CardAuth(number)
  596. // //fmt.Println(authResult)
  597. //
  598. // //tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  599. // //if tempPatient.ID == patient_id {
  600. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice)
  601. // var dat map[string]interface{}
  602. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  603. // fmt.Println(dat)
  604. // } else {
  605. // fmt.Println(err)
  606. // }
  607. //
  608. // userJSONBytes, _ := json.Marshal(dat)
  609. //
  610. // var res ResultOne
  611. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  612. // utils.ErrorLog("解析失败:%v", err)
  613. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  614. // return
  615. // }
  616. // if res.Transreturncode == "00000000" {
  617. // his := models.VMHisPatient{
  618. // Name: name,
  619. // Gender: gender,
  620. // Birthday: birthUnix,
  621. // MedicalTreatmentType: medical_care,
  622. // IdType: certificates,
  623. // IdCardNo: id_card,
  624. // BalanceAccountsType: settlementValue,
  625. // SocialType: social_type,
  626. // MedicalInsuranceNumber: medical_insurance_card,
  627. // RegisterType: register_type,
  628. // RegisterCost: registration_fee,
  629. // TreatmentCost: medical_expenses,
  630. // Status: 1,
  631. // Ctime: time.Now().Unix(),
  632. // Mtime: time.Now().Unix(),
  633. // Iinfo: resp_result,
  634. // PatientId: patient.ID,
  635. // RecordDate: theTime.Unix(),
  636. // UserOrgId: adminInfo.CurrentOrgId,
  637. // AdminUserId: admin_user_id,
  638. // IsReturn: 1,
  639. // IdCardType: id_card_type,
  640. // Doctor: doctor,
  641. // Departments: department,
  642. // YiliaoNumber: yiliao_number,
  643. // MzNumber: number,
  644. // Number: mz_number,
  645. // }
  646. // service.CreateHisPatientTwo(&his)
  647. // c.ServeSuccessJSON(map[string]interface{}{
  648. // "msg": "挂号成功",
  649. // })
  650. // } else {
  651. // c.ServeSuccessJSON(map[string]interface{}{
  652. // "failed_code": -10,
  653. // "msg": res.Transreturnmessage,
  654. // })
  655. // return
  656. // }
  657. //
  658. // }
  659. //
  660. // } else { //异地卡流程
  661. // //readCardBasResult := ReadCardBasHSM(number)
  662. // //fmt.Println(readCardBasResult)
  663. // //是否异地就医,是的话走鉴权流程,不是的话走门诊挂号
  664. // if is_yidi == 1 { //1本地就医
  665. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice)
  666. // var dat map[string]interface{}
  667. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  668. // fmt.Println(dat)
  669. // } else {
  670. // fmt.Println(err)
  671. // }
  672. //
  673. // userJSONBytes, _ := json.Marshal(dat)
  674. //
  675. // var res ResultOne
  676. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  677. // utils.ErrorLog("解析失败:%v", err)
  678. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  679. // return
  680. // }
  681. // if res.Transreturncode == "00000000" {
  682. // his := models.VMHisPatient{
  683. // Name: name,
  684. // Gender: gender,
  685. // Birthday: birthUnix,
  686. // MedicalTreatmentType: medical_care,
  687. // IdType: certificates,
  688. // IdCardNo: id_card,
  689. // BalanceAccountsType: settlementValue,
  690. // SocialType: social_type,
  691. // MedicalInsuranceNumber: medical_insurance_card,
  692. // RegisterType: register_type,
  693. // RegisterCost: registration_fee,
  694. // TreatmentCost: medical_expenses,
  695. // Status: 1,
  696. // Ctime: time.Now().Unix(),
  697. // Mtime: time.Now().Unix(),
  698. // Iinfo: resp_result,
  699. // PatientId: patient.ID,
  700. // RecordDate: theTime.Unix(),
  701. // UserOrgId: adminInfo.CurrentOrgId,
  702. // AdminUserId: admin_user_id,
  703. // IsReturn: 1,
  704. // IdCardType: id_card_type,
  705. // Doctor: doctor,
  706. // Departments: department,
  707. // YiliaoNumber: yiliao_number,
  708. // MzNumber: number,
  709. // Number: mz_number,
  710. // }
  711. // service.CreateHisPatientTwo(&his)
  712. // c.ServeSuccessJSON(map[string]interface{}{
  713. // "msg": "挂号成功",
  714. // })
  715. // } else {
  716. // c.ServeSuccessJSON(map[string]interface{}{
  717. // "failed_code": -10,
  718. // "msg": res.Transreturnmessage,
  719. // })
  720. // return
  721. // }
  722. //
  723. // } else { //异地就医需要走鉴权流程
  724. // //authResult := CardAuth(number)
  725. // //fmt.Println(authResult)
  726. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice)
  727. // var dat map[string]interface{}
  728. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  729. // fmt.Println(dat)
  730. // } else {
  731. // fmt.Println(err)
  732. // }
  733. //
  734. // userJSONBytes, _ := json.Marshal(dat)
  735. //
  736. // var res ResultOne
  737. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  738. // utils.ErrorLog("解析失败:%v", err)
  739. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  740. // return
  741. // }
  742. // if res.Transreturncode == "00000000" {
  743. // his := models.VMHisPatient{
  744. // Name: name,
  745. // Gender: gender,
  746. // Birthday: birthUnix,
  747. // MedicalTreatmentType: medical_care,
  748. // IdType: certificates,
  749. // IdCardNo: id_card,
  750. // BalanceAccountsType: settlementValue,
  751. // SocialType: social_type,
  752. // MedicalInsuranceNumber: medical_insurance_card,
  753. // RegisterType: register_type,
  754. // RegisterCost: registration_fee,
  755. // TreatmentCost: medical_expenses,
  756. // Status: 1,
  757. // Ctime: time.Now().Unix(),
  758. // Mtime: time.Now().Unix(),
  759. // Iinfo: resp_result,
  760. // PatientId: patient.ID,
  761. // RecordDate: theTime.Unix(),
  762. // UserOrgId: adminInfo.CurrentOrgId,
  763. // AdminUserId: admin_user_id,
  764. // IsReturn: 1,
  765. // IdCardType: id_card_type,
  766. // Doctor: doctor,
  767. // Departments: department,
  768. // YiliaoNumber: yiliao_number,
  769. // MzNumber: number,
  770. // Number: mz_number,
  771. // }
  772. // service.CreateHisPatientTwo(&his)
  773. // c.ServeSuccessJSON(map[string]interface{}{
  774. // "msg": "挂号成功",
  775. // })
  776. // } else {
  777. // c.ServeSuccessJSON(map[string]interface{}{
  778. // "failed_code": -10,
  779. // "msg": res.Transreturnmessage,
  780. // })
  781. // return
  782. // }
  783. //
  784. // }
  785. // }
  786. // } else {
  787. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  788. // return
  789. // }
  790. // } else {
  791. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  792. // return
  793. // }
  794. //}
  795. func (c *SZHisApiController) GetRegisterInfo() {
  796. adminInfo := c.GetAdminUserInfo()
  797. admin_user_id, _ := c.GetInt64("admin_user_id")
  798. patient_id, _ := c.GetInt64("id")
  799. record_time := c.GetString("record_time")
  800. settlementValue, _ := c.GetInt64("settlement_value")
  801. medical_insurance_card := c.GetString("medical_insurance_card")
  802. name := c.GetString("name")
  803. id_card_type, _ := c.GetInt64("id_card_type")
  804. certificates, _ := c.GetInt64("certificates")
  805. medical_care, _ := c.GetInt64("medical_care")
  806. birthday := c.GetString("birthday")
  807. id_card := c.GetString("id_card")
  808. register_type, _ := c.GetInt64("register")
  809. doctor, _ := c.GetInt64("doctor")
  810. department, _ := c.GetInt64("department")
  811. gender, _ := c.GetInt64("sex")
  812. registration_fee, _ := c.GetFloat("registration_fee")
  813. medical_expenses, _ := c.GetFloat("medical_expenses")
  814. social_type, _ := c.GetInt64("social_type")
  815. is_yidi, _ := c.GetInt64("is_yidi")
  816. timeLayout := "2006-01-02"
  817. loc, _ := time.LoadLocation("Local")
  818. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  819. birthUnix := birthdays.Unix()
  820. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  821. if err != nil {
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  823. return
  824. }
  825. var patient service.Patients
  826. if patient_id == 0 {
  827. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  828. } else {
  829. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  830. }
  831. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  832. if patient.ID == 0 {
  833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  834. return
  835. }
  836. if len(patient.IdCardNo) == 0 {
  837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  838. return
  839. }
  840. //doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor)
  841. doctorDepartment, _ := service.GetDepartMentDetail(department)
  842. adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  843. //his, _ := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient_id, theTime.Unix())
  844. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, theTime.Unix())
  845. if len(his) >= 1 {
  846. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, theTime.Unix())
  847. if len(his) >= 1 && order.ID == 0 {
  848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  849. return
  850. }
  851. }
  852. var custom_code string
  853. var custom_project_name string
  854. var allPrice float64
  855. switch register_type {
  856. case 1:
  857. custom_code = "110100002"
  858. custom_project_name = "普通门诊"
  859. allPrice = 10
  860. break
  861. case 3:
  862. custom_code = "110200002-2"
  863. custom_project_name = "主任医师"
  864. allPrice = 10
  865. break
  866. case 2:
  867. custom_code = "110200002-3"
  868. custom_project_name = "副主任医师"
  869. allPrice = 10
  870. break
  871. case 4:
  872. custom_code = "0"
  873. custom_project_name = "免受诊金"
  874. allPrice = 0
  875. break
  876. case 5:
  877. custom_code = "110200002-1"
  878. custom_project_name = "专家"
  879. allPrice = 10
  880. break
  881. }
  882. var opera_name string
  883. var opera_code string
  884. if adminRole.ID == 0 {
  885. opera_name = "管理员"
  886. opera_code = "01"
  887. } else {
  888. opera_name = adminRole.UserName
  889. opera_code = strconv.FormatInt(admin_user_id, 10)
  890. }
  891. month := time.Unix(1557042972, 0).Format("1")
  892. year := time.Now().Format("2006")
  893. month = time.Now().Format("01")
  894. day := time.Now().Format("02")
  895. //流水号
  896. number := miConfig.Code + year + month + day +
  897. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  898. mz_number := miConfig.Code + year + month + day +
  899. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000))
  900. //1.判断读卡类型
  901. //2.读卡 获取交易验证码,医疗证号,发卡地区行政区划代码
  902. yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("MZ002" + "|" + number + "|" + miConfig.Code + "|")
  903. dept_code := doctorDepartment.Number
  904. is_yidi = 1
  905. tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  906. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  907. fmt.Println(tempPatient.ID)
  908. fmt.Println(patient_id)
  909. if tempPatient.ID == patient_id {
  910. temp_mz_number := miConfig.Code + year + month + day +
  911. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000))
  912. tempVerifyCode, tempVersionCode := ReadCardGetCode("XX001" + "|" + temp_mz_number + "|" + miConfig.Code)
  913. //yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("MZ002" + "|" + number + "|" + miConfig.Code + "|")
  914. //yiliao_number = "%GALMAFXJGKUKZNKWAIUH?;07857319025346309758?"
  915. result001 := service.SzybXX001(opera_name, opera_code, miConfig.Code, yiliao_number, tempVerifyCode, temp_mz_number, tempVersionCode)
  916. if ret4 == 0 { //本地卡流程
  917. if is_yidi == 1 {
  918. //var dat2 map[string]interface{}
  919. //if err := json.Unmarshal([]byte(result001), &dat2); err == nil {
  920. // fmt.Println(dat2)
  921. //} else {
  922. // fmt.Println(err)
  923. //}
  924. //userJSONBytes2, _ := json.Marshal(dat2)
  925. //var res2 ResultMZ001
  926. //if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  927. // utils.ErrorLog("解析失败:%v", err)
  928. //}
  929. //本地就医流程
  930. //挂号
  931. resp_result := service.SzybMZ002(opera_name, opera_code, miConfig.Code, dept_code, yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  932. var dat map[string]interface{}
  933. if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  934. fmt.Println(dat)
  935. } else {
  936. fmt.Println(err)
  937. }
  938. userJSONBytes, _ := json.Marshal(dat)
  939. var res ResultOne
  940. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  941. utils.ErrorLog("解析失败:%v", err)
  942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  943. return
  944. }
  945. if res.Transreturncode == "00000000" {
  946. his := models.VMHisPatient{
  947. Name: name,
  948. Gender: gender,
  949. Birthday: birthUnix,
  950. MedicalTreatmentType: medical_care,
  951. IdType: certificates,
  952. IdCardNo: id_card,
  953. BalanceAccountsType: settlementValue,
  954. SocialType: social_type,
  955. MedicalInsuranceNumber: medical_insurance_card,
  956. RegisterType: register_type,
  957. RegisterCost: registration_fee,
  958. TreatmentCost: medical_expenses,
  959. Status: 1,
  960. Ctime: time.Now().Unix(),
  961. Mtime: time.Now().Unix(),
  962. Iinfo: resp_result,
  963. PatientId: patient.ID,
  964. RecordDate: theTime.Unix(),
  965. UserOrgId: adminInfo.CurrentOrgId,
  966. AdminUserId: admin_user_id,
  967. IsReturn: 1,
  968. IdCardType: id_card_type,
  969. Doctor: doctor,
  970. Departments: department,
  971. YiliaoNumber: yiliao_number,
  972. MzNumber: number,
  973. Number: mz_number,
  974. PsnNo: health_card_no,
  975. PatientInfo: result001,
  976. }
  977. service.CreateHisPatientTwo(&his)
  978. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, theTime.Unix())
  979. if len(lists) == 1 {
  980. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, theTime.Unix(), adminInfo.CurrentOrgId)
  981. }
  982. c.ServeSuccessJSON(map[string]interface{}{
  983. "msg": "挂号成功",
  984. })
  985. } else {
  986. c.ServeSuccessJSON(map[string]interface{}{
  987. "failed_code": -10,
  988. "msg": res.Transreturnmessage,
  989. })
  990. return
  991. }
  992. } else {
  993. //异地就医流程
  994. //异地走鉴权流程
  995. //authResult := CardAuth(number)
  996. //fmt.Println(authResult)
  997. //tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  998. //if tempPatient.ID == patient_id {
  999. resp_result := service.SzybMZ002(opera_name, opera_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  1000. var dat map[string]interface{}
  1001. if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1002. fmt.Println(dat)
  1003. } else {
  1004. fmt.Println(err)
  1005. }
  1006. userJSONBytes, _ := json.Marshal(dat)
  1007. var res ResultOne
  1008. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1009. utils.ErrorLog("解析失败:%v", err)
  1010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1011. return
  1012. }
  1013. if res.Transreturncode == "00000000" {
  1014. his := models.VMHisPatient{
  1015. Name: name,
  1016. Gender: gender,
  1017. Birthday: birthUnix,
  1018. MedicalTreatmentType: medical_care,
  1019. IdType: certificates,
  1020. IdCardNo: id_card,
  1021. BalanceAccountsType: settlementValue,
  1022. SocialType: social_type,
  1023. MedicalInsuranceNumber: medical_insurance_card,
  1024. RegisterType: register_type,
  1025. RegisterCost: registration_fee,
  1026. TreatmentCost: medical_expenses,
  1027. Status: 1,
  1028. Ctime: time.Now().Unix(),
  1029. Mtime: time.Now().Unix(),
  1030. Iinfo: resp_result,
  1031. PatientId: patient.ID,
  1032. RecordDate: theTime.Unix(),
  1033. UserOrgId: adminInfo.CurrentOrgId,
  1034. AdminUserId: admin_user_id,
  1035. IsReturn: 1,
  1036. IdCardType: id_card_type,
  1037. Doctor: doctor,
  1038. Departments: department,
  1039. YiliaoNumber: yiliao_number,
  1040. MzNumber: number,
  1041. Number: mz_number,
  1042. PsnNo: health_card_no,
  1043. PatientInfo: result001,
  1044. }
  1045. service.CreateHisPatientTwo(&his)
  1046. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, theTime.Unix())
  1047. if len(lists) == 1 {
  1048. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, theTime.Unix(), adminInfo.CurrentOrgId)
  1049. }
  1050. c.ServeSuccessJSON(map[string]interface{}{
  1051. "msg": "挂号成功",
  1052. })
  1053. } else {
  1054. c.ServeSuccessJSON(map[string]interface{}{
  1055. "failed_code": -10,
  1056. "msg": res.Transreturnmessage,
  1057. })
  1058. return
  1059. }
  1060. }
  1061. } else { //异地卡流程
  1062. //readCardBasResult := ReadCardBasHSM(number)
  1063. //fmt.Println(readCardBasResult)
  1064. //是否异地就医,是的话走鉴权流程,不是的话走门诊挂号
  1065. if is_yidi == 1 { //1本地就医
  1066. resp_result := service.SzybMZ002(opera_name, opera_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  1067. var dat map[string]interface{}
  1068. if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1069. fmt.Println(dat)
  1070. } else {
  1071. fmt.Println(err)
  1072. }
  1073. userJSONBytes, _ := json.Marshal(dat)
  1074. var res ResultOne
  1075. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1076. utils.ErrorLog("解析失败:%v", err)
  1077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1078. return
  1079. }
  1080. if res.Transreturncode == "00000000" {
  1081. his := models.VMHisPatient{
  1082. Name: name,
  1083. Gender: gender,
  1084. Birthday: birthUnix,
  1085. MedicalTreatmentType: medical_care,
  1086. IdType: certificates,
  1087. IdCardNo: id_card,
  1088. BalanceAccountsType: settlementValue,
  1089. SocialType: social_type,
  1090. MedicalInsuranceNumber: medical_insurance_card,
  1091. RegisterType: register_type,
  1092. RegisterCost: registration_fee,
  1093. TreatmentCost: medical_expenses,
  1094. Status: 1,
  1095. Ctime: time.Now().Unix(),
  1096. Mtime: time.Now().Unix(),
  1097. Iinfo: resp_result,
  1098. PatientId: patient.ID,
  1099. RecordDate: theTime.Unix(),
  1100. UserOrgId: adminInfo.CurrentOrgId,
  1101. AdminUserId: admin_user_id,
  1102. IsReturn: 1,
  1103. IdCardType: id_card_type,
  1104. Doctor: doctor,
  1105. Departments: department,
  1106. YiliaoNumber: yiliao_number,
  1107. MzNumber: number,
  1108. Number: mz_number,
  1109. PsnNo: health_card_no,
  1110. PatientInfo: result001,
  1111. }
  1112. service.CreateHisPatientTwo(&his)
  1113. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, theTime.Unix())
  1114. if len(lists) == 1 {
  1115. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, theTime.Unix(), adminInfo.CurrentOrgId)
  1116. }
  1117. c.ServeSuccessJSON(map[string]interface{}{
  1118. "msg": "挂号成功",
  1119. })
  1120. } else {
  1121. c.ServeSuccessJSON(map[string]interface{}{
  1122. "failed_code": -10,
  1123. "msg": res.Transreturnmessage,
  1124. })
  1125. return
  1126. }
  1127. } else { //异地就医需要走鉴权流程
  1128. //authResult := CardAuth(number)
  1129. //fmt.Println(authResult)
  1130. resp_result := service.SzybMZ002(opera_name, opera_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  1131. var dat map[string]interface{}
  1132. if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1133. fmt.Println(dat)
  1134. } else {
  1135. fmt.Println(err)
  1136. }
  1137. userJSONBytes, _ := json.Marshal(dat)
  1138. var res ResultOne
  1139. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1140. utils.ErrorLog("解析失败:%v", err)
  1141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1142. return
  1143. }
  1144. if res.Transreturncode == "00000000" {
  1145. his := models.VMHisPatient{
  1146. Name: name,
  1147. Gender: gender,
  1148. Birthday: birthUnix,
  1149. MedicalTreatmentType: medical_care,
  1150. IdType: certificates,
  1151. IdCardNo: id_card,
  1152. BalanceAccountsType: settlementValue,
  1153. SocialType: social_type,
  1154. MedicalInsuranceNumber: medical_insurance_card,
  1155. RegisterType: register_type,
  1156. RegisterCost: registration_fee,
  1157. TreatmentCost: medical_expenses,
  1158. Status: 1,
  1159. Ctime: time.Now().Unix(),
  1160. Mtime: time.Now().Unix(),
  1161. Iinfo: resp_result,
  1162. PatientId: patient.ID,
  1163. RecordDate: theTime.Unix(),
  1164. UserOrgId: adminInfo.CurrentOrgId,
  1165. AdminUserId: admin_user_id,
  1166. IsReturn: 1,
  1167. IdCardType: id_card_type,
  1168. Doctor: doctor,
  1169. Departments: department,
  1170. YiliaoNumber: yiliao_number,
  1171. MzNumber: number,
  1172. Number: mz_number,
  1173. PsnNo: health_card_no,
  1174. PatientInfo: result001,
  1175. }
  1176. service.CreateHisPatientTwo(&his)
  1177. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, theTime.Unix())
  1178. if len(lists) == 1 {
  1179. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, theTime.Unix(), adminInfo.CurrentOrgId)
  1180. }
  1181. c.ServeSuccessJSON(map[string]interface{}{
  1182. "msg": "挂号成功",
  1183. })
  1184. } else {
  1185. c.ServeSuccessJSON(map[string]interface{}{
  1186. "failed_code": -10,
  1187. "msg": res.Transreturnmessage,
  1188. })
  1189. return
  1190. }
  1191. }
  1192. }
  1193. } else {
  1194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  1195. return
  1196. }
  1197. }
  1198. //func (c *SZHisApiController) GetInfo() {
  1199. //func (c *SZHisApiController) GetRegisterInfo() {
  1200. // adminInfo := c.GetAdminUserInfo()
  1201. // admin_user_id, _ := c.GetInt64("admin_user_id")
  1202. // patient_id, _ := c.GetInt64("id")
  1203. // record_time := c.GetString("record_time")
  1204. // settlementValue, _ := c.GetInt64("settlement_value")
  1205. // medical_insurance_card := c.GetString("medical_insurance_card")
  1206. // name := c.GetString("name")
  1207. // id_card_type, _ := c.GetInt64("id_card_type")
  1208. // certificates, _ := c.GetInt64("certificates")
  1209. // medical_care, _ := c.GetInt64("medical_care")
  1210. // birthday := c.GetString("birthday")
  1211. // id_card := c.GetString("id_card")
  1212. // register_type, _ := c.GetInt64("register")
  1213. // doctor, _ := c.GetInt64("doctor")
  1214. // department, _ := c.GetInt64("department")
  1215. // gender, _ := c.GetInt64("sex")
  1216. // registration_fee, _ := c.GetFloat("registration_fee")
  1217. // medical_expenses, _ := c.GetFloat("medical_expenses")
  1218. // social_type, _ := c.GetInt64("social_type")
  1219. //
  1220. // is_yidi, _ := c.GetInt64("is_yidi")
  1221. //
  1222. // timeLayout := "2006-01-02"
  1223. // loc, _ := time.LoadLocation("Local")
  1224. // birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  1225. // birthUnix := birthdays.Unix()
  1226. //
  1227. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1228. // if err != nil {
  1229. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1230. // return
  1231. // }
  1232. //
  1233. // var patient service.Patients
  1234. // if patient_id == 0 {
  1235. // patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  1236. // } else {
  1237. // patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1238. // }
  1239. //
  1240. // miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1241. // if patient.ID == 0 {
  1242. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1243. // return
  1244. // }
  1245. // if len(patient.IdCardNo) == 0 {
  1246. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  1247. // return
  1248. // }
  1249. //
  1250. // adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1251. // his, _ := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient_id, theTime.Unix())
  1252. //
  1253. // var custom_code string
  1254. // var custom_project_name string
  1255. // var allPrice float64
  1256. //
  1257. // switch register_type {
  1258. // case 1:
  1259. // custom_code = "110100002"
  1260. // custom_project_name = "普通门诊"
  1261. // allPrice = 10
  1262. // break
  1263. // case 3:
  1264. // custom_code = "110200002-2"
  1265. // custom_project_name = "主任医师"
  1266. // allPrice = 10
  1267. //
  1268. // break
  1269. // case 2:
  1270. // custom_code = "110200002-3"
  1271. // custom_project_name = "副主任医师"
  1272. // allPrice = 10
  1273. //
  1274. // break
  1275. // case 4:
  1276. // custom_code = "0"
  1277. // custom_project_name = "免受诊金"
  1278. // allPrice = 0
  1279. // break
  1280. // case 5:
  1281. // custom_code = "110200002-1"
  1282. // custom_project_name = "专家"
  1283. // allPrice = 10
  1284. //
  1285. // break
  1286. // }
  1287. //
  1288. // if his.ID == 0 {
  1289. //
  1290. // var doctor_name string
  1291. // var doctor_code string
  1292. // if adminRole.ID == 0 {
  1293. //
  1294. // doctor_name = ""
  1295. // doctor_code = "1001"
  1296. // doctor_name = ""
  1297. // doctor_code = ""
  1298. //
  1299. // } else {
  1300. // doctor_name = adminRole.UserName
  1301. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  1302. //
  1303. // }
  1304. // month := time.Unix(1557042972, 0).Format("1")
  1305. // year := time.Now().Format("2006")
  1306. // month = time.Now().Format("01")
  1307. // day := time.Now().Format("02")
  1308. //
  1309. // //流水号
  1310. // //
  1311. // number := miConfig.Code + year + month + day +
  1312. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  1313. // mz_number := year + month + day + strconv.FormatInt(patient_id, 10) +
  1314. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000))
  1315. // //1.判断读卡类型
  1316. // //2.读卡 获取交易验证码,医疗证号,发卡地区行政区划代码
  1317. // yiliao_number, id_card_number, verifyCode, version_code, _, ret4 := ReadBasCardGetNumber("MZ002" + "|" + number + "|" + miConfig.Code + "|")
  1318. // fmt.Println(yiliao_number)
  1319. // fmt.Println(id_card_number)
  1320. // fmt.Println(verifyCode)
  1321. // fmt.Println(version_code)
  1322. // fmt.Println(ret4)
  1323. //
  1324. // dept_code := "0305"
  1325. // is_yidi = 1
  1326. // tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  1327. // //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  1328. // if tempPatient.ID == patient_id {
  1329. // if ret4 == 0 { //本地卡流程
  1330. // if is_yidi == 1 {
  1331. // //本地就医流程
  1332. // //挂号
  1333. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, dept_code, yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  1334. // var dat map[string]interface{}
  1335. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1336. // fmt.Println(dat)
  1337. // } else {
  1338. // fmt.Println(err)
  1339. // }
  1340. // userJSONBytes, _ := json.Marshal(dat)
  1341. // var res ResultOne
  1342. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1343. // utils.ErrorLog("解析失败:%v", err)
  1344. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1345. // return
  1346. // }
  1347. // if res.Transreturncode == "00000000" {
  1348. // his := models.VMHisPatient{
  1349. // Name: name,
  1350. // Gender: gender,
  1351. // Birthday: birthUnix,
  1352. // MedicalTreatmentType: medical_care,
  1353. // IdType: certificates,
  1354. // IdCardNo: id_card,
  1355. // BalanceAccountsType: settlementValue,
  1356. // SocialType: social_type,
  1357. // MedicalInsuranceNumber: medical_insurance_card,
  1358. // RegisterType: register_type,
  1359. // RegisterCost: registration_fee,
  1360. // TreatmentCost: medical_expenses,
  1361. // Status: 1,
  1362. // Ctime: time.Now().Unix(),
  1363. // Mtime: time.Now().Unix(),
  1364. // Iinfo: resp_result,
  1365. // PatientId: patient.ID,
  1366. // RecordDate: theTime.Unix(),
  1367. // UserOrgId: adminInfo.CurrentOrgId,
  1368. // AdminUserId: admin_user_id,
  1369. // IsReturn: 1,
  1370. // IdCardType: id_card_type,
  1371. // Doctor: doctor,
  1372. // Departments: department,
  1373. // YiliaoNumber: yiliao_number,
  1374. // MzNumber: number,
  1375. // Number: mz_number,
  1376. // }
  1377. // service.CreateHisPatientTwo(&his)
  1378. // c.ServeSuccessJSON(map[string]interface{}{
  1379. // "msg": "挂号成功",
  1380. // })
  1381. // } else {
  1382. // c.ServeSuccessJSON(map[string]interface{}{
  1383. // "failed_code": -10,
  1384. // "msg": res.Transreturnmessage,
  1385. // })
  1386. // return
  1387. // }
  1388. //
  1389. // } else {
  1390. // //异地就医流程
  1391. // //异地走鉴权流程
  1392. // //authResult := CardAuth(number)
  1393. // //fmt.Println(authResult)
  1394. //
  1395. // //tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  1396. // //if tempPatient.ID == patient_id {
  1397. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice)
  1398. // var dat map[string]interface{}
  1399. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1400. // fmt.Println(dat)
  1401. // } else {
  1402. // fmt.Println(err)
  1403. // }
  1404. //
  1405. // userJSONBytes, _ := json.Marshal(dat)
  1406. //
  1407. // var res ResultOne
  1408. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1409. // utils.ErrorLog("解析失败:%v", err)
  1410. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1411. // return
  1412. // }
  1413. // if res.Transreturncode == "00000000" {
  1414. // his := models.VMHisPatient{
  1415. // Name: name,
  1416. // Gender: gender,
  1417. // Birthday: birthUnix,
  1418. // MedicalTreatmentType: medical_care,
  1419. // IdType: certificates,
  1420. // IdCardNo: id_card,
  1421. // BalanceAccountsType: settlementValue,
  1422. // SocialType: social_type,
  1423. // MedicalInsuranceNumber: medical_insurance_card,
  1424. // RegisterType: register_type,
  1425. // RegisterCost: registration_fee,
  1426. // TreatmentCost: medical_expenses,
  1427. // Status: 1,
  1428. // Ctime: time.Now().Unix(),
  1429. // Mtime: time.Now().Unix(),
  1430. // Iinfo: resp_result,
  1431. // PatientId: patient.ID,
  1432. // RecordDate: theTime.Unix(),
  1433. // UserOrgId: adminInfo.CurrentOrgId,
  1434. // AdminUserId: admin_user_id,
  1435. // IsReturn: 1,
  1436. // IdCardType: id_card_type,
  1437. // Doctor: doctor,
  1438. // Departments: department,
  1439. // YiliaoNumber: yiliao_number,
  1440. // MzNumber: number,
  1441. // Number: mz_number,
  1442. // }
  1443. // service.CreateHisPatientTwo(&his)
  1444. // c.ServeSuccessJSON(map[string]interface{}{
  1445. // "msg": "挂号成功",
  1446. // })
  1447. // } else {
  1448. // c.ServeSuccessJSON(map[string]interface{}{
  1449. // "failed_code": -10,
  1450. // "msg": res.Transreturnmessage,
  1451. // })
  1452. // return
  1453. // }
  1454. //
  1455. // }
  1456. //
  1457. // } else { //异地卡流程
  1458. // //readCardBasResult := ReadCardBasHSM(number)
  1459. // //fmt.Println(readCardBasResult)
  1460. // //是否异地就医,是的话走鉴权流程,不是的话走门诊挂号
  1461. // if is_yidi == 1 { //1本地就医
  1462. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice)
  1463. // var dat map[string]interface{}
  1464. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1465. // fmt.Println(dat)
  1466. // } else {
  1467. // fmt.Println(err)
  1468. // }
  1469. //
  1470. // userJSONBytes, _ := json.Marshal(dat)
  1471. //
  1472. // var res ResultOne
  1473. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1474. // utils.ErrorLog("解析失败:%v", err)
  1475. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1476. // return
  1477. // }
  1478. // if res.Transreturncode == "00000000" {
  1479. // his := models.VMHisPatient{
  1480. // Name: name,
  1481. // Gender: gender,
  1482. // Birthday: birthUnix,
  1483. // MedicalTreatmentType: medical_care,
  1484. // IdType: certificates,
  1485. // IdCardNo: id_card,
  1486. // BalanceAccountsType: settlementValue,
  1487. // SocialType: social_type,
  1488. // MedicalInsuranceNumber: medical_insurance_card,
  1489. // RegisterType: register_type,
  1490. // RegisterCost: registration_fee,
  1491. // TreatmentCost: medical_expenses,
  1492. // Status: 1,
  1493. // Ctime: time.Now().Unix(),
  1494. // Mtime: time.Now().Unix(),
  1495. // Iinfo: resp_result,
  1496. // PatientId: patient.ID,
  1497. // RecordDate: theTime.Unix(),
  1498. // UserOrgId: adminInfo.CurrentOrgId,
  1499. // AdminUserId: admin_user_id,
  1500. // IsReturn: 1,
  1501. // IdCardType: id_card_type,
  1502. // Doctor: doctor,
  1503. // Departments: department,
  1504. // YiliaoNumber: yiliao_number,
  1505. // MzNumber: number,
  1506. // Number: mz_number,
  1507. // }
  1508. // service.CreateHisPatientTwo(&his)
  1509. // c.ServeSuccessJSON(map[string]interface{}{
  1510. // "msg": "挂号成功",
  1511. // })
  1512. // } else {
  1513. // c.ServeSuccessJSON(map[string]interface{}{
  1514. // "failed_code": -10,
  1515. // "msg": res.Transreturnmessage,
  1516. // })
  1517. // return
  1518. // }
  1519. //
  1520. // } else { //异地就医需要走鉴权流程
  1521. // //authResult := CardAuth(number)
  1522. // //fmt.Println(authResult)
  1523. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice)
  1524. // var dat map[string]interface{}
  1525. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1526. // fmt.Println(dat)
  1527. // } else {
  1528. // fmt.Println(err)
  1529. // }
  1530. //
  1531. // userJSONBytes, _ := json.Marshal(dat)
  1532. //
  1533. // var res ResultOne
  1534. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1535. // utils.ErrorLog("解析失败:%v", err)
  1536. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1537. // return
  1538. // }
  1539. // if res.Transreturncode == "00000000" {
  1540. // his := models.VMHisPatient{
  1541. // Name: name,
  1542. // Gender: gender,
  1543. // Birthday: birthUnix,
  1544. // MedicalTreatmentType: medical_care,
  1545. // IdType: certificates,
  1546. // IdCardNo: id_card,
  1547. // BalanceAccountsType: settlementValue,
  1548. // SocialType: social_type,
  1549. // MedicalInsuranceNumber: medical_insurance_card,
  1550. // RegisterType: register_type,
  1551. // RegisterCost: registration_fee,
  1552. // TreatmentCost: medical_expenses,
  1553. // Status: 1,
  1554. // Ctime: time.Now().Unix(),
  1555. // Mtime: time.Now().Unix(),
  1556. // Iinfo: resp_result,
  1557. // PatientId: patient.ID,
  1558. // RecordDate: theTime.Unix(),
  1559. // UserOrgId: adminInfo.CurrentOrgId,
  1560. // AdminUserId: admin_user_id,
  1561. // IsReturn: 1,
  1562. // IdCardType: id_card_type,
  1563. // Doctor: doctor,
  1564. // Departments: department,
  1565. // YiliaoNumber: yiliao_number,
  1566. // MzNumber: number,
  1567. // Number: mz_number,
  1568. // }
  1569. // service.CreateHisPatientTwo(&his)
  1570. // c.ServeSuccessJSON(map[string]interface{}{
  1571. // "msg": "挂号成功",
  1572. // })
  1573. // } else {
  1574. // c.ServeSuccessJSON(map[string]interface{}{
  1575. // "failed_code": -10,
  1576. // "msg": res.Transreturnmessage,
  1577. // })
  1578. // return
  1579. // }
  1580. //
  1581. // }
  1582. // }
  1583. // } else {
  1584. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  1585. // return
  1586. // }
  1587. // } else {
  1588. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1589. // return
  1590. // }
  1591. //}
  1592. //func (c *SZHisApiController) GetRegisterInfo() {
  1593. // adminInfo := c.GetAdminUserInfo()
  1594. // miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1595. // month := time.Unix(1557042972, 0).Format("1")
  1596. // year := time.Now().Format("2006")
  1597. // month = time.Now().Format("01")
  1598. // day := time.Now().Format("02")
  1599. // //流水号
  1600. // number := miConfig.Code + year + month + day +
  1601. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  1602. // //1.判断读卡类型
  1603. // //2.读卡 获取交易验证码,医疗证号,发卡地区行政区划代码
  1604. // yiliao_number, _, verifyCode, version_code, _, _, _ := ReadBasCardGetNumber("XX001" + "|" + number + "|" + miConfig.Code + "|")
  1605. // fmt.Println(result)
  1606. //
  1607. //}
  1608. func (c *SZHisApiController) RefundNumber() {
  1609. record_time := c.GetString("record_time")
  1610. //patient_id, _ := c.GetInt64("patient_id")
  1611. his_patient_id, _ := c.GetInt64("his_patient_id")
  1612. admin_user_id, _ := c.GetInt64("admin_user_id")
  1613. timeLayout := "2006-01-02"
  1614. loc, _ := time.LoadLocation("Local")
  1615. adminUser := c.GetAdminUserInfo()
  1616. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1617. fmt.Println(err)
  1618. if err != nil {
  1619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1620. return
  1621. }
  1622. recordDateTime := theTime.Unix()
  1623. fmt.Println(recordDateTime)
  1624. his, _ := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, theTime.Unix())
  1625. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1626. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1627. //结算流程
  1628. var doctor_name string
  1629. var doctor_code string
  1630. if roles.ID == 0 {
  1631. doctor_name = "管理员"
  1632. doctor_code = "01"
  1633. } else {
  1634. doctor_name = roles.UserName
  1635. doctor_code = strconv.FormatInt(admin_user_id, 10)
  1636. }
  1637. month := time.Unix(1557042972, 0).Format("1")
  1638. year := time.Now().Format("2006")
  1639. month = time.Now().Format("01")
  1640. day := time.Now().Format("02")
  1641. //number := miConfig.Code + year + month + day + "1367866"
  1642. number := miConfig.Code + year + month + day +
  1643. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  1644. //number := miConfig.Code + year + month + day + "1590003"
  1645. //流水号
  1646. //number_two := miConfig.Code + "-" + year + month + day + "-" + strconv.FormatInt(patient_id, 10)
  1647. verifyCode, version_code := ReadCardGetCode("JY002" + "|" + number + "|" + miConfig.Code)
  1648. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1649. if config.IsOpen == 1 { //对接了医保,走医保流程
  1650. result := service.SzybJY002(doctor_name, doctor_code, miConfig.Code, his.MzNumber, his.Number, verifyCode, number, version_code)
  1651. var dat map[string]interface{}
  1652. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1653. fmt.Println(dat)
  1654. } else {
  1655. fmt.Println(err)
  1656. }
  1657. userJSONBytes, _ := json.Marshal(dat)
  1658. var res ResultThree
  1659. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1660. utils.ErrorLog("解析失败:%v", err)
  1661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1662. return
  1663. }
  1664. if res.Transreturncode == "00000000" {
  1665. service.UpdataHisStatusSZ(adminUser.CurrentOrgId, his.MzNumber, his.Number, result, his_patient_id)
  1666. c.ServeSuccessJSON(map[string]interface{}{
  1667. "msg": "退号成功",
  1668. })
  1669. } else {
  1670. c.ServeSuccessJSON(map[string]interface{}{
  1671. "failed_code": -10,
  1672. "msg": res.Transreturnmessage,
  1673. })
  1674. }
  1675. }
  1676. }
  1677. //func (c *SZHisApiController) GetRegisterInfo() {
  1678. // adminInfo := c.GetAdminUserInfo()
  1679. // admin_user_id, _ := c.GetInt64("admin_user_id")
  1680. // patient_id, _ := c.GetInt64("id")
  1681. // record_time := c.GetString("record_time")
  1682. // settlementValue, _ := c.GetInt64("settlement_value")
  1683. // medical_insurance_card := c.GetString("medical_insurance_card")
  1684. // name := c.GetString("name")
  1685. // id_card_type, _ := c.GetInt64("id_card_type")
  1686. // certificates, _ := c.GetInt64("certificates")
  1687. // medical_care, _ := c.GetInt64("medical_care")
  1688. // birthday := c.GetString("birthday")
  1689. // id_card := c.GetString("id_card")
  1690. // register_type, _ := c.GetInt64("register")
  1691. // doctor, _ := c.GetInt64("doctor")
  1692. // department, _ := c.GetInt64("department")
  1693. // gender, _ := c.GetInt64("sex")
  1694. // registration_fee, _ := c.GetFloat("registration_fee")
  1695. // medical_expenses, _ := c.GetFloat("medical_expenses")
  1696. // social_type, _ := c.GetInt64("social_type")
  1697. //
  1698. // is_yidi, _ := c.GetInt64("is_yidi")
  1699. //
  1700. // timeLayout := "2006-01-02"
  1701. // loc, _ := time.LoadLocation("Local")
  1702. // birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  1703. // birthUnix := birthdays.Unix()
  1704. //
  1705. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1706. // if err != nil {
  1707. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1708. // return
  1709. // }
  1710. //
  1711. // var patient service.Patients
  1712. // if patient_id == 0 {
  1713. // patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  1714. // } else {
  1715. // patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1716. // }
  1717. //
  1718. // miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1719. // if patient.ID == 0 {
  1720. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1721. // return
  1722. // }
  1723. // if len(patient.IdCardNo) == 0 {
  1724. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  1725. // return
  1726. // }
  1727. //
  1728. // adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1729. // his, _ := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient_id, theTime.Unix())
  1730. //
  1731. // var custom_code string
  1732. // var custom_project_name string
  1733. // var allPrice float64
  1734. //
  1735. // switch register_type {
  1736. // case 1:
  1737. // custom_code = "110100002"
  1738. // custom_project_name = "普通门诊"
  1739. // allPrice = 10
  1740. // break
  1741. // case 3:
  1742. // custom_code = "110200002-2"
  1743. // custom_project_name = "主任医师"
  1744. // allPrice = 10
  1745. //
  1746. // break
  1747. // case 2:
  1748. // custom_code = "110200002-3"
  1749. // custom_project_name = "副主任医师"
  1750. // allPrice = 10
  1751. //
  1752. // break
  1753. // case 4:
  1754. // custom_code = "0"
  1755. // custom_project_name = "免受诊金"
  1756. // allPrice = 0
  1757. // break
  1758. // case 5:
  1759. // custom_code = "110200002-1"
  1760. // custom_project_name = "专家"
  1761. // allPrice = 10
  1762. //
  1763. // break
  1764. // }
  1765. //
  1766. // if his.ID == 0 {
  1767. //
  1768. // var doctor_name string
  1769. // var doctor_code string
  1770. // if adminRole.ID == 0 {
  1771. //
  1772. // doctor_name = "管理员"
  1773. // doctor_code = "01"
  1774. //
  1775. // } else {
  1776. // doctor_name = adminRole.UserName
  1777. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  1778. //
  1779. // }
  1780. // month := time.Unix(1557042972, 0).Format("1")
  1781. // year := time.Now().Format("2006")
  1782. // month = time.Now().Format("01")
  1783. // day := time.Now().Format("02")
  1784. //
  1785. // //流水号
  1786. // //
  1787. // number := miConfig.Code + year + month + day +
  1788. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  1789. // mz_number := miConfig.Code + year + month + day +
  1790. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000))
  1791. // //1.判断读卡类型
  1792. // //2.读卡 获取交易验证码,医疗证号,发卡地区行政区划代码
  1793. // yiliao_number, id_card_number, verifyCode, version_code, _, ret4 := ReadBasCardGetNumber("MZ002" + "|" + number + "|" + miConfig.Code + "|")
  1794. // fmt.Println(yiliao_number)
  1795. // fmt.Println(id_card_number)
  1796. // fmt.Println(verifyCode)
  1797. // fmt.Println(version_code)
  1798. // fmt.Println(ret4)
  1799. //
  1800. // dept_code := "0306"
  1801. // is_yidi = 1
  1802. // tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  1803. // //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  1804. // fmt.Println(tempPatient.ID)
  1805. // fmt.Println(patient_id)
  1806. //
  1807. // if tempPatient.ID == patient_id {
  1808. // if ret4 == 0 { //本地卡流程
  1809. // if is_yidi == 1 {
  1810. // //本地就医流程
  1811. // //挂号
  1812. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, dept_code, yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  1813. // var dat map[string]interface{}
  1814. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1815. // fmt.Println(dat)
  1816. // } else {
  1817. // fmt.Println(err)
  1818. // }
  1819. // userJSONBytes, _ := json.Marshal(dat)
  1820. // var res ResultOne
  1821. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1822. // utils.ErrorLog("解析失败:%v", err)
  1823. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1824. // return
  1825. // }
  1826. // if res.Transreturncode == "00000000" {
  1827. // his := models.VMHisPatient{
  1828. // Name: name,
  1829. // Gender: gender,
  1830. // Birthday: birthUnix,
  1831. // MedicalTreatmentType: medical_care,
  1832. // IdType: certificates,
  1833. // IdCardNo: id_card,
  1834. // BalanceAccountsType: settlementValue,
  1835. // SocialType: social_type,
  1836. // MedicalInsuranceNumber: medical_insurance_card,
  1837. // RegisterType: register_type,
  1838. // RegisterCost: registration_fee,
  1839. // TreatmentCost: medical_expenses,
  1840. // Status: 1,
  1841. // Ctime: time.Now().Unix(),
  1842. // Mtime: time.Now().Unix(),
  1843. // Iinfo: resp_result,
  1844. // PatientId: patient.ID,
  1845. // RecordDate: theTime.Unix(),
  1846. // UserOrgId: adminInfo.CurrentOrgId,
  1847. // AdminUserId: admin_user_id,
  1848. // IsReturn: 1,
  1849. // IdCardType: id_card_type,
  1850. // Doctor: doctor,
  1851. // Departments: department,
  1852. // YiliaoNumber: yiliao_number,
  1853. // MzNumber: number,
  1854. // Number: mz_number,
  1855. // }
  1856. // service.CreateHisPatientTwo(&his)
  1857. // c.ServeSuccessJSON(map[string]interface{}{
  1858. // "msg": "挂号成功",
  1859. // })
  1860. // } else {
  1861. // c.ServeSuccessJSON(map[string]interface{}{
  1862. // "failed_code": -10,
  1863. // "msg": res.Transreturnmessage,
  1864. // })
  1865. // return
  1866. // }
  1867. //
  1868. // } else {
  1869. // //异地就医流程
  1870. // //异地走鉴权流程
  1871. // //authResult := CardAuth(number)
  1872. // //fmt.Println(authResult)
  1873. //
  1874. // //tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  1875. // //if tempPatient.ID == patient_id {
  1876. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  1877. // var dat map[string]interface{}
  1878. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1879. // fmt.Println(dat)
  1880. // } else {
  1881. // fmt.Println(err)
  1882. // }
  1883. //
  1884. // userJSONBytes, _ := json.Marshal(dat)
  1885. //
  1886. // var res ResultOne
  1887. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1888. // utils.ErrorLog("解析失败:%v", err)
  1889. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1890. // return
  1891. // }
  1892. // if res.Transreturncode == "00000000" {
  1893. // his := models.VMHisPatient{
  1894. // Name: name,
  1895. // Gender: gender,
  1896. // Birthday: birthUnix,
  1897. // MedicalTreatmentType: medical_care,
  1898. // IdType: certificates,
  1899. // IdCardNo: id_card,
  1900. // BalanceAccountsType: settlementValue,
  1901. // SocialType: social_type,
  1902. // MedicalInsuranceNumber: medical_insurance_card,
  1903. // RegisterType: register_type,
  1904. // RegisterCost: registration_fee,
  1905. // TreatmentCost: medical_expenses,
  1906. // Status: 1,
  1907. // Ctime: time.Now().Unix(),
  1908. // Mtime: time.Now().Unix(),
  1909. // Iinfo: resp_result,
  1910. // PatientId: patient.ID,
  1911. // RecordDate: theTime.Unix(),
  1912. // UserOrgId: adminInfo.CurrentOrgId,
  1913. // AdminUserId: admin_user_id,
  1914. // IsReturn: 1,
  1915. // IdCardType: id_card_type,
  1916. // Doctor: doctor,
  1917. // Departments: department,
  1918. // YiliaoNumber: yiliao_number,
  1919. // MzNumber: number,
  1920. // Number: mz_number,
  1921. // }
  1922. // service.CreateHisPatientTwo(&his)
  1923. // c.ServeSuccessJSON(map[string]interface{}{
  1924. // "msg": "挂号成功",
  1925. // })
  1926. // } else {
  1927. // c.ServeSuccessJSON(map[string]interface{}{
  1928. // "failed_code": -10,
  1929. // "msg": res.Transreturnmessage,
  1930. // })
  1931. // return
  1932. // }
  1933. //
  1934. // }
  1935. //
  1936. // } else { //异地卡流程
  1937. // //readCardBasResult := ReadCardBasHSM(number)
  1938. // //fmt.Println(readCardBasResult)
  1939. // //是否异地就医,是的话走鉴权流程,不是的话走门诊挂号
  1940. // if is_yidi == 1 { //1本地就医
  1941. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  1942. // var dat map[string]interface{}
  1943. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1944. // fmt.Println(dat)
  1945. // } else {
  1946. // fmt.Println(err)
  1947. // }
  1948. //
  1949. // userJSONBytes, _ := json.Marshal(dat)
  1950. //
  1951. // var res ResultOne
  1952. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1953. // utils.ErrorLog("解析失败:%v", err)
  1954. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1955. // return
  1956. // }
  1957. // if res.Transreturncode == "00000000" {
  1958. // his := models.VMHisPatient{
  1959. // Name: name,
  1960. // Gender: gender,
  1961. // Birthday: birthUnix,
  1962. // MedicalTreatmentType: medical_care,
  1963. // IdType: certificates,
  1964. // IdCardNo: id_card,
  1965. // BalanceAccountsType: settlementValue,
  1966. // SocialType: social_type,
  1967. // MedicalInsuranceNumber: medical_insurance_card,
  1968. // RegisterType: register_type,
  1969. // RegisterCost: registration_fee,
  1970. // TreatmentCost: medical_expenses,
  1971. // Status: 1,
  1972. // Ctime: time.Now().Unix(),
  1973. // Mtime: time.Now().Unix(),
  1974. // Iinfo: resp_result,
  1975. // PatientId: patient.ID,
  1976. // RecordDate: theTime.Unix(),
  1977. // UserOrgId: adminInfo.CurrentOrgId,
  1978. // AdminUserId: admin_user_id,
  1979. // IsReturn: 1,
  1980. // IdCardType: id_card_type,
  1981. // Doctor: doctor,
  1982. // Departments: department,
  1983. // YiliaoNumber: yiliao_number,
  1984. // MzNumber: number,
  1985. // Number: mz_number,
  1986. // }
  1987. // service.CreateHisPatientTwo(&his)
  1988. // c.ServeSuccessJSON(map[string]interface{}{
  1989. // "msg": "挂号成功",
  1990. // })
  1991. // } else {
  1992. // c.ServeSuccessJSON(map[string]interface{}{
  1993. // "failed_code": -10,
  1994. // "msg": res.Transreturnmessage,
  1995. // })
  1996. // return
  1997. // }
  1998. //
  1999. // } else { //异地就医需要走鉴权流程
  2000. // //authResult := CardAuth(number)
  2001. // //fmt.Println(authResult)
  2002. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  2003. // var dat map[string]interface{}
  2004. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  2005. // fmt.Println(dat)
  2006. // } else {
  2007. // fmt.Println(err)
  2008. // }
  2009. //
  2010. // userJSONBytes, _ := json.Marshal(dat)
  2011. //
  2012. // var res ResultOne
  2013. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2014. // utils.ErrorLog("解析失败:%v", err)
  2015. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2016. // return
  2017. // }
  2018. // if res.Transreturncode == "00000000" {
  2019. // his := models.VMHisPatient{
  2020. // Name: name,
  2021. // Gender: gender,
  2022. // Birthday: birthUnix,
  2023. // MedicalTreatmentType: medical_care,
  2024. // IdType: certificates,
  2025. // IdCardNo: id_card,
  2026. // BalanceAccountsType: settlementValue,
  2027. // SocialType: social_type,
  2028. // MedicalInsuranceNumber: medical_insurance_card,
  2029. // RegisterType: register_type,
  2030. // RegisterCost: registration_fee,
  2031. // TreatmentCost: medical_expenses,
  2032. // Status: 1,
  2033. // Ctime: time.Now().Unix(),
  2034. // Mtime: time.Now().Unix(),
  2035. // Iinfo: resp_result,
  2036. // PatientId: patient.ID,
  2037. // RecordDate: theTime.Unix(),
  2038. // UserOrgId: adminInfo.CurrentOrgId,
  2039. // AdminUserId: admin_user_id,
  2040. // IsReturn: 1,
  2041. // IdCardType: id_card_type,
  2042. // Doctor: doctor,
  2043. // Departments: department,
  2044. // YiliaoNumber: yiliao_number,
  2045. // MzNumber: number,
  2046. // Number: mz_number,
  2047. // }
  2048. // service.CreateHisPatientTwo(&his)
  2049. // c.ServeSuccessJSON(map[string]interface{}{
  2050. // "msg": "挂号成功",
  2051. // })
  2052. // } else {
  2053. // c.ServeSuccessJSON(map[string]interface{}{
  2054. // "failed_code": -10,
  2055. // "msg": res.Transreturnmessage,
  2056. // })
  2057. // return
  2058. // }
  2059. //
  2060. // }
  2061. // }
  2062. // } else {
  2063. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  2064. // return
  2065. // }
  2066. // } else {
  2067. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2068. // return
  2069. // }
  2070. //}q
  2071. //上传明细----结算----确认订单
  2072. func (c *SZHisApiController) GetSettleInfo() {
  2073. pay_way, _ := c.GetInt64("pay_way")
  2074. pay_price, _ := c.GetFloat("pay_price")
  2075. pay_card_no := c.GetString("pay_card_no")
  2076. discount_price, _ := c.GetFloat("discount_price")
  2077. preferential_price, _ := c.GetFloat("preferential_price")
  2078. reality_price, _ := c.GetFloat("reality_price")
  2079. found_price, _ := c.GetFloat("found_price")
  2080. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2081. private_price, _ := c.GetFloat("private_price")
  2082. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2083. patient_id, _ := c.GetInt64("id")
  2084. record_time := c.GetString("record_time")
  2085. admin_user_id, _ := c.GetInt64("admin_user_id")
  2086. his_patient_id, _ := c.GetInt64("his_patient_id")
  2087. timestamp := time.Now().Unix()
  2088. tempTime := time.Unix(timestamp, 0)
  2089. timeFormat := tempTime.Format("20060102150405")
  2090. chrgBchno := rand.Intn(10000) + 1000
  2091. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(1, 10)
  2092. adminUser := c.GetAdminUserInfo()
  2093. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2094. month := time.Unix(1557042972, 0).Format("1")
  2095. year := time.Now().Format("2006")
  2096. month = time.Now().Format("01")
  2097. day := time.Now().Format("02")
  2098. timeLayout := "2006-01-02"
  2099. loc, _ := time.LoadLocation("Local")
  2100. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2101. fmt.Println(err)
  2102. if err != nil {
  2103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2104. return
  2105. }
  2106. recordDateTime := theTime.Unix()
  2107. his, err := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2108. tempOrder, _ := service.GetNewHisOrderThree(his.Number)
  2109. if tempOrder.ID == 0 {
  2110. var prescriptions []*models.HisPrescription
  2111. var start_time int64
  2112. var end_time int64
  2113. if settle_accounts_type == 1 { //日结
  2114. prescriptions, _ = service.GetNewHisPrescription(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2115. } else { //月结
  2116. start_time_str := c.GetString("start_time")
  2117. end_time_str := c.GetString("end_time")
  2118. timeLayout := "2006-01-02"
  2119. loc, _ := time.LoadLocation("Local")
  2120. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2121. if err != nil {
  2122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2123. return
  2124. }
  2125. recordStartTime := theStartTime.Unix()
  2126. start_time = recordStartTime
  2127. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2128. if err != nil {
  2129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2130. return
  2131. }
  2132. recordEndTime := theEndTime.Unix()
  2133. end_time = recordEndTime
  2134. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
  2135. }
  2136. var ids []int64
  2137. for _, item := range prescriptions {
  2138. ids = append(ids, item.ID)
  2139. }
  2140. patientPrescription, _ := service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2141. sick, _ := service.FindSickById(patientPrescription.SickType)
  2142. if sick.ID == 0 {
  2143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamSickTypeWrong)
  2144. return
  2145. }
  2146. adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  2147. adminRole, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2148. mz_number := his.Number
  2149. number := miConfig.Code + year + month + day +
  2150. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  2151. var doctor_name string
  2152. var doctor_code string
  2153. var drug_doctor_code string
  2154. drug_doctor_code = adminRole_two.DoctorCode
  2155. drug_doctor_name := adminRole_two.UserName
  2156. if adminRole.ID == 0 {
  2157. doctor_name = "管理员"
  2158. doctor_code = "01"
  2159. } else {
  2160. doctor_name = adminRole.UserName
  2161. doctor_code = strconv.FormatInt(admin_user_id, 10)
  2162. }
  2163. verifyCode, version_code := ReadCardGetCode("FY001" + "|" + number + "|" + miConfig.Code)
  2164. //verifyCode := "000000|bf885fa312a7f92861d6b61542a637fa"
  2165. //version_code := "V0.3"
  2166. var customs []*models.CustomDetail
  2167. for _, item := range prescriptions {
  2168. if item.Type == 1 { //药品
  2169. for _, subItem := range item.HisDoctorAdviceInfo {
  2170. fmt.Println(subItem.BaseDrugLib.MedicalInsuranceNumber)
  2171. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 {
  2172. _, dose_code := service.GetDoseCode(subItem.BaseDrugLib.DrugDosageForm, adminUser.CurrentOrgId)
  2173. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber), 64)
  2174. price, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price), 64)
  2175. temp := strings.Split(subItem.FeedetlSn, "-")
  2176. newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  2177. cus := &models.CustomDetail{
  2178. PrescriptionNumber: chrg_bchno,
  2179. OrderType: "1",
  2180. ChargeSerialNumber: newFl,
  2181. Code: subItem.BaseDrugLib.MedicalInsuranceNumber,
  2182. CodeName: subItem.BaseDrugLib.DrugName,
  2183. Flag: "1",
  2184. Price: price,
  2185. Count: subItem.PrescribingNumber,
  2186. ChargeOrderDate: year + month + day,
  2187. DoctorCode: doctor_code,
  2188. Total: detItemFeeSumamt,
  2189. DoseCode: dose_code,
  2190. Spec: subItem.BaseDrugLib.DrugSpec,
  2191. }
  2192. customs = append(customs, cus)
  2193. }
  2194. }
  2195. }
  2196. if item.Type == 2 { //项目
  2197. for _, subItem := range item.HisPrescriptionProject {
  2198. if len(subItem.HisProject.MedicalCode) > 0 {
  2199. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  2200. //count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  2201. count, _ := strconv.ParseFloat(strconv.FormatInt(subItem.Count, 10), 64)
  2202. temp := strings.Split(subItem.FeedetlSn, "-")
  2203. newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  2204. if subItem.Type == 2 {
  2205. cus := &models.CustomDetail{
  2206. PrescriptionNumber: chrg_bchno,
  2207. OrderType: "1",
  2208. ChargeSerialNumber: newFl,
  2209. Code: subItem.HisProject.MedicalCode,
  2210. CodeName: subItem.HisProject.ProjectName,
  2211. Flag: "1",
  2212. Price: subItem.Price,
  2213. Count: count,
  2214. ChargeOrderDate: year + month + day,
  2215. DoctorCode: doctor_code,
  2216. Total: detItemFeeSumamt,
  2217. DoseCode: "",
  2218. Spec: "次",
  2219. }
  2220. customs = append(customs, cus)
  2221. }
  2222. }
  2223. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 {
  2224. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  2225. //count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  2226. count, _ := strconv.ParseFloat(strconv.FormatInt(subItem.Count, 10), 64)
  2227. temp := strings.Split(subItem.FeedetlSn, "-")
  2228. newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  2229. if subItem.Type == 3 {
  2230. cus := &models.CustomDetail{
  2231. PrescriptionNumber: chrg_bchno,
  2232. OrderType: "1",
  2233. ChargeSerialNumber: newFl,
  2234. Code: subItem.GoodInfo.MedicalInsuranceNumber,
  2235. CodeName: subItem.GoodInfo.GoodName,
  2236. Flag: "1",
  2237. Price: subItem.Price,
  2238. Count: count,
  2239. ChargeOrderDate: year + month + day,
  2240. DoctorCode: doctor_code,
  2241. Total: detItemFeeSumamt,
  2242. DoseCode: "",
  2243. Spec: "次",
  2244. }
  2245. customs = append(customs, cus)
  2246. }
  2247. }
  2248. }
  2249. }
  2250. //
  2251. //for _, subItem := range item.HisAdditionalCharge {
  2252. // if len(subItem.XtHisAddtionConfig.Code) > 0 {
  2253. // detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  2254. //
  2255. // count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  2256. // cus := &models.CustomDetail{
  2257. // PrescriptionNumber: chrg_bchno,
  2258. // OrderType: "1",
  2259. // ChargeSerialNumber: subItem.FeedetlSn,
  2260. // Code: subItem.XtHisAddtionConfig.Code,
  2261. // CodeName: subItem.XtHisAddtionConfig.Name,
  2262. // Flag: "1",
  2263. // Price: subItem.Price,
  2264. // Count: count,
  2265. // ChargeOrderDate: year + month + day,
  2266. // DoctorCode: doctor_code,
  2267. // Total: detItemFeeSumamt,
  2268. // DoseCode: "",
  2269. // Spec: subItem.XtHisAddtionConfig.,
  2270. // }
  2271. // customs = append(customs, cus)
  2272. // }
  2273. //}
  2274. }
  2275. var pagesize int = 50
  2276. var start int = 1
  2277. var stop int
  2278. var pagecount int
  2279. var curpage int
  2280. var isSuccess bool = true
  2281. //总页数,向上取整,注意除之前要先转换类型为float64
  2282. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  2283. var ress []*Result
  2284. for curpage = 1; curpage <= pagecount; curpage++ {
  2285. if curpage == 1 {
  2286. start = 1
  2287. } else {
  2288. start = (curpage-1)*pagesize + 1
  2289. }
  2290. stop = curpage * pagesize
  2291. if stop > len(customs) {
  2292. stop = len(customs)
  2293. }
  2294. result := service.SzybFY001(doctor_name, doctor_code, miConfig.Code, customs[start-1:stop], verifyCode, number, mz_number, version_code, drug_doctor_code)
  2295. fmt.Println(result)
  2296. var dat map[string]interface{}
  2297. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2298. fmt.Println(dat)
  2299. } else {
  2300. fmt.Println(err)
  2301. }
  2302. userJSONBytes, _ := json.Marshal(dat)
  2303. var res Result
  2304. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2305. utils.ErrorLog("解析失败:%v", err)
  2306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2307. return
  2308. }
  2309. if res.Transreturncode == "00000000" {
  2310. ress = append(ress, &res)
  2311. } else {
  2312. isSuccess = false
  2313. errlog := &models.HisOrderError{
  2314. UserOrgId: adminUser.CurrentOrgId,
  2315. Ctime: time.Now().Unix(),
  2316. Mtime: time.Now().Unix(),
  2317. Number: chrg_bchno,
  2318. ErrMsg: res.Transreturnmessage,
  2319. Status: 1,
  2320. PatientId: patient_id,
  2321. RecordTime: recordDateTime,
  2322. Stage: 4,
  2323. }
  2324. service.CreateErrMsgLog(errlog)
  2325. c.ServeSuccessJSON(map[string]interface{}{
  2326. "failed_code": -10,
  2327. "msg": res.Transreturnmessage,
  2328. })
  2329. return
  2330. }
  2331. //设置变量,根据变量的值来判断上传是否成功
  2332. }
  2333. if isSuccess == true {
  2334. order := &models.HisOrder{
  2335. UserOrgId: adminUser.CurrentOrgId,
  2336. HisPatientId: 0,
  2337. PatientId: patient_id,
  2338. SettleAccountsDate: recordDateTime,
  2339. Ctime: time.Now().Unix(),
  2340. Mtime: time.Now().Unix(),
  2341. Status: 0,
  2342. Number: chrg_bchno,
  2343. Infcode: 0,
  2344. WarnMsg: "",
  2345. Cainfo: "",
  2346. ErrMsg: "",
  2347. RespondTime: "",
  2348. InfRefmsgid: "",
  2349. OrderStatus: 1,
  2350. IsMedicineInsurance: 1,
  2351. SettleType: settle_accounts_type,
  2352. SettleStartTime: start_time,
  2353. SettleEndTime: end_time,
  2354. Creator: admin_user_id,
  2355. Modify: admin_user_id,
  2356. OrgSetlNumber: number,
  2357. MdtrtId: mz_number,
  2358. PType: 2,
  2359. }
  2360. data, _ := json.Marshal(ress)
  2361. order.DetailLog = string(data)
  2362. err = service.CreateOrder(order)
  2363. if err != nil {
  2364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2365. return
  2366. }
  2367. for _, subItem := range ress {
  2368. for _, item := range subItem.Transbody.Outputlist {
  2369. temp := strings.Split(item.Bkf500, "-")
  2370. var advice_id int64 = 0
  2371. var project_id int64 = 0
  2372. var types int64 = 0
  2373. id, _ := strconv.ParseInt(temp[2], 10, 64)
  2374. types, _ = strconv.ParseInt(temp[1], 10, 64)
  2375. if temp[1] == "1" {
  2376. advice_id = id
  2377. project_id = 0
  2378. } else if temp[1] == "2" {
  2379. advice_id = 0
  2380. project_id = id
  2381. }
  2382. info := &models.HisOrderInfo{
  2383. OrderNumber: order.Number,
  2384. FeedetlSn: item.Bkf500,
  2385. UploadDate: time.Now().Unix(),
  2386. AdviceId: advice_id,
  2387. DetItemFeeSumamt: item.Akc264,
  2388. Cnt: item.Akc226,
  2389. Pric: float64(item.Akc225),
  2390. PatientId: patient_id,
  2391. Status: 1,
  2392. ChrgitmLv: item.Aka065,
  2393. Mtime: time.Now().Unix(),
  2394. Ctime: time.Now().Unix(),
  2395. UserOrgId: adminUser.CurrentOrgId,
  2396. OrderId: order.ID,
  2397. ProjectId: project_id,
  2398. Type: types,
  2399. OverPricPsnPay: item.Akc268,
  2400. AllowReimburse: item.Cka319,
  2401. }
  2402. service.CreateOrderInfo(info)
  2403. }
  2404. }
  2405. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2406. service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, his_patient_id, chrg_bchno, recordDateTime)
  2407. var total float64
  2408. for _, item := range prescriptions {
  2409. if item.Type == 1 { //药品
  2410. for _, subItem := range item.HisDoctorAdviceInfo {
  2411. total = total + (subItem.Price * subItem.PrescribingNumber)
  2412. }
  2413. }
  2414. if item.Type == 2 { //项目
  2415. for _, subItem := range item.HisPrescriptionProject {
  2416. total = total + (subItem.Price * float64(subItem.Count))
  2417. }
  2418. }
  2419. }
  2420. for _, item := range prescriptions {
  2421. for _, subItem := range item.HisAdditionalCharge {
  2422. total = total + (subItem.Price * float64(subItem.Count))
  2423. }
  2424. }
  2425. total, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", total), 64)
  2426. yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("FY005" + "|" + number + "|" + miConfig.Code + "|")
  2427. if ret4 == 0 {
  2428. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  2429. tempPatient, _ := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  2430. if tempPatient.ID == patient_id {
  2431. result_three := service.SzybFY005(doctor_name, doctor_code, miConfig.Code, total, yiliao_number, verifyCode, number, mz_number, version_code, drug_doctor_code, drug_doctor_name, his.MedicalTreatmentType, sick.CountryCode)
  2432. var dat map[string]interface{}
  2433. if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  2434. fmt.Println(dat)
  2435. } else {
  2436. fmt.Println(err)
  2437. }
  2438. userJSONBytes, _ := json.Marshal(dat)
  2439. var res ResultTwo
  2440. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2441. utils.ErrorLog("解析失败:%v", err)
  2442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2443. return
  2444. }
  2445. if res.Transreturncode == "00000000" {
  2446. order.OrderStatus = 2
  2447. order.Status = 1
  2448. order.PayWay = pay_way
  2449. order.PayPrice = pay_price
  2450. order.PayCardNo = pay_card_no
  2451. order.PsnNo = health_card_no
  2452. order.DiscountPrice = discount_price
  2453. order.PreferentialPrice = preferential_price
  2454. order.RealityPrice = reality_price
  2455. order.FoundPrice = found_price
  2456. order.MedicalInsurancePrice = medical_insurance_price
  2457. order.PrivatePrice = private_price
  2458. order.Modify = admin_user_id
  2459. order.MedfeeSumamt = res.Transbody.Akc264
  2460. order.SetlId = res.Transbody.Ckc618
  2461. order.FundPaySumamt = res.Transbody.Akb068
  2462. order.AcctPay = res.Transbody.Akb066
  2463. order.PsnCashPay = res.Transbody.Akb067
  2464. order.PsnPartAmt = res.Transbody.Akb067
  2465. order.AccountPrice = res.Transbody.Aae240
  2466. order.MzNumber = mz_number
  2467. order.MdtrtId = mz_number
  2468. order.YiliaoNumber = yiliao_number
  2469. setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  2470. detailStrOne := string(setlDetailOne)
  2471. order.SzChargeInfo = detailStrOne
  2472. setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  2473. detailStrTwo := string(setlDetailTwo)
  2474. order.SzProjectInfo = detailStrTwo
  2475. setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  2476. detailStrThree := string(setlDetailThree)
  2477. order.SzMedicineInsuranceInfo = detailStrThree
  2478. order.Cainfo = result_three
  2479. err = service.UpdataOrderStatusTwo(order.Number, adminUser.CurrentOrgId)
  2480. err = service.UpDateOrderTwo(order)
  2481. c.ServeSuccessJSON(map[string]interface{}{
  2482. "msg": "结算成功",
  2483. })
  2484. } else {
  2485. //结算报错
  2486. errlog := &models.HisOrderError{
  2487. UserOrgId: adminUser.CurrentOrgId,
  2488. Ctime: time.Now().Unix(),
  2489. Mtime: time.Now().Unix(),
  2490. Number: chrg_bchno,
  2491. ErrMsg: res.Transreturnmessage,
  2492. Status: 1,
  2493. PatientId: patient_id,
  2494. RecordTime: recordDateTime,
  2495. Stage: 6,
  2496. }
  2497. service.CreateErrMsgLog(errlog)
  2498. c.ServeSuccessJSON(map[string]interface{}{
  2499. "failed_code": -10,
  2500. "msg": res.Transreturnmessage,
  2501. })
  2502. }
  2503. } else {
  2504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  2505. return
  2506. }
  2507. } else {
  2508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  2509. return
  2510. }
  2511. } else {
  2512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePreSettleFaildParamWrong)
  2513. return
  2514. }
  2515. } else {
  2516. if tempOrder.OrderStatus == 1 && tempOrder.IsPre == 1 {
  2517. pay_way, _ := c.GetInt64("pay_way")
  2518. pay_price, _ := c.GetFloat("pay_price")
  2519. pay_card_no := c.GetString("pay_card_no")
  2520. discount_price, _ := c.GetFloat("discount_price")
  2521. preferential_price, _ := c.GetFloat("preferential_price")
  2522. reality_price, _ := c.GetFloat("reality_price")
  2523. found_price, _ := c.GetFloat("found_price")
  2524. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2525. private_price, _ := c.GetFloat("private_price")
  2526. patient_id, _ := c.GetInt64("id")
  2527. record_time := c.GetString("record_time")
  2528. admin_user_id, _ := c.GetInt64("admin_user_id")
  2529. order_id, _ := c.GetInt64("order_id")
  2530. his_patient_id, _ := c.GetInt64("his_patient_id")
  2531. timestamp := time.Now().Unix()
  2532. tempTime := time.Unix(timestamp, 0)
  2533. timeFormat := tempTime.Format("20060102150405")
  2534. chrgBchno := rand.Intn(10000) + 1000
  2535. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(1, 10)
  2536. adminUser := c.GetAdminUserInfo()
  2537. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2538. month := time.Unix(1557042972, 0).Format("1")
  2539. year := time.Now().Format("2006")
  2540. month = time.Now().Format("01")
  2541. day := time.Now().Format("02")
  2542. timeLayout := "2006-01-02"
  2543. loc, _ := time.LoadLocation("Local")
  2544. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2545. fmt.Println(err)
  2546. if err != nil {
  2547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2548. return
  2549. }
  2550. recordDateTime := theTime.Unix()
  2551. patientPrescription, _ := service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2552. sick, _ := service.FindSickById(patientPrescription.SickType)
  2553. if sick.ID == 0 {
  2554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamSickTypeWrong)
  2555. return
  2556. }
  2557. adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  2558. adminRole, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2559. his, err := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2560. mz_number := his.Number
  2561. number := miConfig.Code + year + month + day +
  2562. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  2563. var doctor_name string
  2564. var doctor_code string
  2565. var drug_doctor_code string
  2566. drug_doctor_code = adminRole_two.DoctorCode
  2567. drug_doctor_name := adminRole_two.UserName
  2568. if adminRole.ID == 0 {
  2569. doctor_name = "管理员"
  2570. doctor_code = "01"
  2571. } else {
  2572. doctor_name = adminRole.UserName
  2573. doctor_code = strconv.FormatInt(admin_user_id, 10)
  2574. }
  2575. order, _ := service.GetHisOrderByID(order_id)
  2576. if order.ID == 0 {
  2577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  2578. return
  2579. }
  2580. yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("FY005" + "|" + number + "|" + miConfig.Code + "|")
  2581. if ret4 == 0 {
  2582. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  2583. tempPatient, _ := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  2584. if tempPatient.ID == patient_id {
  2585. result_three := service.SzybFY005(doctor_name, doctor_code, miConfig.Code, order.MedfeeSumamt, yiliao_number, verifyCode, number, mz_number, version_code, drug_doctor_code, drug_doctor_name, his.MedicalTreatmentType, sick.CountryCode)
  2586. var dat map[string]interface{}
  2587. if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  2588. fmt.Println(dat)
  2589. } else {
  2590. fmt.Println(err)
  2591. }
  2592. userJSONBytes, _ := json.Marshal(dat)
  2593. var res ResultTwo
  2594. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2595. utils.ErrorLog("解析失败:%v", err)
  2596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2597. return
  2598. }
  2599. if res.Transreturncode == "00000000" {
  2600. order.OrderStatus = 2
  2601. order.Status = 1
  2602. order.PayWay = pay_way
  2603. order.PayPrice = pay_price
  2604. order.PayCardNo = pay_card_no
  2605. order.PsnNo = health_card_no
  2606. order.DiscountPrice = discount_price
  2607. order.PreferentialPrice = preferential_price
  2608. order.RealityPrice = reality_price
  2609. order.FoundPrice = found_price
  2610. order.MedicalInsurancePrice = medical_insurance_price
  2611. order.PrivatePrice = private_price
  2612. order.Modify = admin_user_id
  2613. order.MedfeeSumamt = res.Transbody.Akc264
  2614. order.SetlId = res.Transbody.Ckc618
  2615. order.FundPaySumamt = res.Transbody.Akb068
  2616. order.AcctPay = res.Transbody.Akb066
  2617. order.PsnCashPay = res.Transbody.Akb067
  2618. order.PsnPartAmt = res.Transbody.Akb067
  2619. order.AccountPrice = res.Transbody.Aae240
  2620. order.MzNumber = mz_number
  2621. order.YiliaoNumber = yiliao_number
  2622. setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  2623. detailStrOne := string(setlDetailOne)
  2624. order.SzChargeInfo = detailStrOne
  2625. setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  2626. detailStrTwo := string(setlDetailTwo)
  2627. order.SzProjectInfo = detailStrTwo
  2628. setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  2629. detailStrThree := string(setlDetailThree)
  2630. order.SzMedicineInsuranceInfo = detailStrThree
  2631. order.Cainfo = result_three
  2632. err = service.UpdataOrderStatusTwo(order.Number, adminUser.CurrentOrgId)
  2633. err = service.UpDateOrderTwo(&order)
  2634. c.ServeSuccessJSON(map[string]interface{}{
  2635. "msg": "结算成功",
  2636. })
  2637. } else {
  2638. //结算报错
  2639. errlog := &models.HisOrderError{
  2640. UserOrgId: adminUser.CurrentOrgId,
  2641. Ctime: time.Now().Unix(),
  2642. Mtime: time.Now().Unix(),
  2643. Number: chrg_bchno,
  2644. ErrMsg: res.Transreturnmessage,
  2645. Status: 1,
  2646. PatientId: patient_id,
  2647. RecordTime: recordDateTime,
  2648. Stage: 6,
  2649. }
  2650. service.CreateErrMsgLog(errlog)
  2651. c.ServeSuccessJSON(map[string]interface{}{
  2652. "failed_code": -10,
  2653. "msg": res.Transreturnmessage,
  2654. })
  2655. }
  2656. } else {
  2657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  2658. return
  2659. }
  2660. } else {
  2661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  2662. return
  2663. }
  2664. } else {
  2665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  2666. return
  2667. }
  2668. }
  2669. }
  2670. //结算
  2671. //func (c *SZHisApiController) GetSettleInfo() {
  2672. // pay_way, _ := c.GetInt64("pay_way")
  2673. // pay_price, _ := c.GetFloat("pay_price")
  2674. // pay_card_no := c.GetString("pay_card_no")
  2675. // discount_price, _ := c.GetFloat("discount_price")
  2676. // preferential_price, _ := c.GetFloat("preferential_price")
  2677. // reality_price, _ := c.GetFloat("reality_price")
  2678. // found_price, _ := c.GetFloat("found_price")
  2679. // medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2680. // private_price, _ := c.GetFloat("private_price")
  2681. // patient_id, _ := c.GetInt64("id")
  2682. // record_time := c.GetString("record_time")
  2683. // admin_user_id, _ := c.GetInt64("admin_user_id")
  2684. // order_id, _ := c.GetInt64("order_id")
  2685. // his_patient_id, _ := c.GetInt64("his_patient_id")
  2686. //
  2687. // timestamp := time.Now().Unix()
  2688. // tempTime := time.Unix(timestamp, 0)
  2689. // timeFormat := tempTime.Format("20060102150405")
  2690. // chrgBchno := rand.Intn(10000) + 1000
  2691. // chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(1, 10)
  2692. // adminUser := c.GetAdminUserInfo()
  2693. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2694. // month := time.Unix(1557042972, 0).Format("1")
  2695. // year := time.Now().Format("2006")
  2696. // month = time.Now().Format("01")
  2697. // day := time.Now().Format("02")
  2698. //
  2699. // timeLayout := "2006-01-02"
  2700. // loc, _ := time.LoadLocation("Local")
  2701. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2702. // fmt.Println(err)
  2703. // if err != nil {
  2704. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2705. // return
  2706. // }
  2707. // recordDateTime := theTime.Unix()
  2708. //
  2709. // patientPrescription, _ := service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2710. //
  2711. // sick, _ := service.FindSickById(patientPrescription.SickType)
  2712. //
  2713. // if sick.ID == 0 {
  2714. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamSickTypeWrong)
  2715. // return
  2716. // }
  2717. //
  2718. // adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  2719. //
  2720. // adminRole, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2721. // his, err := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2722. // mz_number := his.Number
  2723. // number := miConfig.Code + year + month + day +
  2724. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  2725. // var doctor_name string
  2726. // var doctor_code string
  2727. // var drug_doctor_code string
  2728. // drug_doctor_code = adminRole_two.DoctorCode
  2729. // drug_doctor_name := adminRole_two.UserName
  2730. //
  2731. // if adminRole.ID == 0 {
  2732. // doctor_name = "管理员"
  2733. // doctor_code = "01"
  2734. // } else {
  2735. // doctor_name = adminRole.UserName
  2736. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  2737. // }
  2738. //
  2739. // order, _ := service.GetHisOrderByID(order_id)
  2740. // if order.ID == 0 {
  2741. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  2742. // return
  2743. // }
  2744. //
  2745. // yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("FY005" + "|" + number + "|" + miConfig.Code + "|")
  2746. // if ret4 == 0 {
  2747. // //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  2748. // tempPatient, _ := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  2749. // if tempPatient.ID == patient_id {
  2750. // result_three := service.SzybFY005(doctor_name, doctor_code, miConfig.Code, order.MedfeeSumamt, yiliao_number, verifyCode, number, mz_number, version_code, drug_doctor_code, drug_doctor_name, his.MedicalTreatmentType, sick.CountryCode)
  2751. // var dat map[string]interface{}
  2752. // if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  2753. // fmt.Println(dat)
  2754. // } else {
  2755. // fmt.Println(err)
  2756. // }
  2757. // userJSONBytes, _ := json.Marshal(dat)
  2758. // var res ResultTwo
  2759. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2760. // utils.ErrorLog("解析失败:%v", err)
  2761. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2762. // return
  2763. // }
  2764. //
  2765. // if res.Transreturncode == "00000000" {
  2766. // order.OrderStatus = 2
  2767. // order.Status = 1
  2768. // order.PayWay = pay_way
  2769. // order.PayPrice = pay_price
  2770. // order.PayCardNo = pay_card_no
  2771. // order.PsnNo = health_card_no
  2772. // order.DiscountPrice = discount_price
  2773. // order.PreferentialPrice = preferential_price
  2774. // order.RealityPrice = reality_price
  2775. // order.FoundPrice = found_price
  2776. // order.MedicalInsurancePrice = medical_insurance_price
  2777. // order.PrivatePrice = private_price
  2778. // order.Modify = admin_user_id
  2779. // order.MedfeeSumamt = res.Transbody.Akc264
  2780. // order.SetlId = res.Transbody.Ckc618
  2781. // order.FundPaySumamt = res.Transbody.Akb068
  2782. // order.AcctPay = res.Transbody.Akb066
  2783. // order.PsnCashPay = res.Transbody.Akb067
  2784. // order.PsnPartAmt = res.Transbody.Akb067
  2785. // order.AccountPrice = res.Transbody.Aae240
  2786. // order.MzNumber = mz_number
  2787. // order.YiliaoNumber = yiliao_number
  2788. // setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  2789. // detailStrOne := string(setlDetailOne)
  2790. // order.SzChargeInfo = detailStrOne
  2791. // setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  2792. // detailStrTwo := string(setlDetailTwo)
  2793. // order.SzProjectInfo = detailStrTwo
  2794. // setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  2795. // detailStrThree := string(setlDetailThree)
  2796. // order.SzMedicineInsuranceInfo = detailStrThree
  2797. // order.Cainfo = result_three
  2798. // err = service.UpdataOrderStatusTwo(order.Number, adminUser.CurrentOrgId)
  2799. // err = service.UpDateOrderTwo(&order)
  2800. // c.ServeSuccessJSON(map[string]interface{}{
  2801. // "msg": "结算成功",
  2802. // })
  2803. // } else {
  2804. // //结算报错
  2805. // errlog := &models.HisOrderError{
  2806. // UserOrgId: adminUser.CurrentOrgId,
  2807. // Ctime: time.Now().Unix(),
  2808. // Mtime: time.Now().Unix(),
  2809. // Number: chrg_bchno,
  2810. // ErrMsg: res.Transreturnmessage,
  2811. // Status: 1,
  2812. // PatientId: patient_id,
  2813. // RecordTime: recordDateTime,
  2814. // Stage: 6,
  2815. // }
  2816. // service.CreateErrMsgLog(errlog)
  2817. // c.ServeSuccessJSON(map[string]interface{}{
  2818. // "failed_code": -10,
  2819. // "msg": res.Transreturnmessage,
  2820. // })
  2821. // }
  2822. // } else {
  2823. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  2824. // return
  2825. // }
  2826. // } else {
  2827. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  2828. // return
  2829. // }
  2830. //}
  2831. //上传明细----预结算
  2832. func (c *SZHisApiController) GetPreSettleInfo() {
  2833. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2834. patient_id, _ := c.GetInt64("id")
  2835. record_time := c.GetString("record_time")
  2836. admin_user_id, _ := c.GetInt64("admin_user_id")
  2837. his_patient_id, _ := c.GetInt64("his_patient_id")
  2838. timestamp := time.Now().Unix()
  2839. tempTime := time.Unix(timestamp, 0)
  2840. timeFormat := tempTime.Format("20060102150405")
  2841. chrgBchno := rand.Intn(10000) + 1000
  2842. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(1, 10)
  2843. adminUser := c.GetAdminUserInfo()
  2844. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2845. month := time.Unix(1557042972, 0).Format("1")
  2846. year := time.Now().Format("2006")
  2847. month = time.Now().Format("01")
  2848. day := time.Now().Format("02")
  2849. timeLayout := "2006-01-02"
  2850. loc, _ := time.LoadLocation("Local")
  2851. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2852. fmt.Println(err)
  2853. if err != nil {
  2854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2855. return
  2856. }
  2857. recordDateTime := theTime.Unix()
  2858. var prescriptions []*models.HisPrescription
  2859. var start_time int64
  2860. var end_time int64
  2861. if settle_accounts_type == 1 { //日结
  2862. prescriptions, _ = service.GetNewHisPrescription(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2863. } else { //月结
  2864. start_time_str := c.GetString("start_time")
  2865. end_time_str := c.GetString("end_time")
  2866. timeLayout := "2006-01-02"
  2867. loc, _ := time.LoadLocation("Local")
  2868. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2869. if err != nil {
  2870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2871. return
  2872. }
  2873. recordStartTime := theStartTime.Unix()
  2874. start_time = recordStartTime
  2875. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2876. if err != nil {
  2877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2878. return
  2879. }
  2880. recordEndTime := theEndTime.Unix()
  2881. end_time = recordEndTime
  2882. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
  2883. }
  2884. var ids []int64
  2885. for _, item := range prescriptions {
  2886. ids = append(ids, item.ID)
  2887. }
  2888. patientPrescription, _ := service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2889. sick, _ := service.FindSickById(patientPrescription.SickType)
  2890. if sick.ID == 0 {
  2891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamSickTypeWrong)
  2892. return
  2893. }
  2894. adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  2895. adminRole, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2896. his, err := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2897. mz_number := his.Number
  2898. number := miConfig.Code + year + month + day +
  2899. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  2900. var doctor_name string
  2901. var doctor_code string
  2902. var drug_doctor_code string
  2903. drug_doctor_code = adminRole_two.DoctorCode
  2904. drug_doctor_name := adminRole_two.UserName
  2905. if adminRole.ID == 0 {
  2906. doctor_name = "管理员"
  2907. doctor_code = "01"
  2908. } else {
  2909. doctor_name = adminRole.UserName
  2910. doctor_code = strconv.FormatInt(admin_user_id, 10)
  2911. }
  2912. verifyCode, version_code := ReadCardGetCode("FY001" + "|" + number + "|" + miConfig.Code)
  2913. var customs []*models.CustomDetail
  2914. for _, item := range prescriptions {
  2915. if item.Type == 1 { //药品
  2916. for _, subItem := range item.HisDoctorAdviceInfo {
  2917. fmt.Println(subItem.BaseDrugLib.MedicalInsuranceNumber)
  2918. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 {
  2919. _, dose_code := service.GetDoseCode(subItem.BaseDrugLib.DrugDosageForm, adminUser.CurrentOrgId)
  2920. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber), 64)
  2921. price, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price), 64)
  2922. temp := strings.Split(subItem.FeedetlSn, "-")
  2923. newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  2924. cus := &models.CustomDetail{
  2925. PrescriptionNumber: chrg_bchno,
  2926. OrderType: "1",
  2927. ChargeSerialNumber: newFl,
  2928. Code: subItem.BaseDrugLib.MedicalInsuranceNumber,
  2929. CodeName: subItem.BaseDrugLib.DrugName,
  2930. Flag: "1",
  2931. Price: price,
  2932. Count: subItem.PrescribingNumber,
  2933. ChargeOrderDate: year + month + day,
  2934. DoctorCode: doctor_code,
  2935. Total: detItemFeeSumamt,
  2936. DoseCode: dose_code,
  2937. Spec: subItem.BaseDrugLib.DrugSpec,
  2938. }
  2939. customs = append(customs, cus)
  2940. }
  2941. }
  2942. }
  2943. if item.Type == 2 { //项目
  2944. for _, subItem := range item.HisPrescriptionProject {
  2945. if len(subItem.HisProject.MedicalCode) > 0 {
  2946. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  2947. //count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  2948. count, _ := strconv.ParseFloat(strconv.FormatInt(subItem.Count, 10), 64)
  2949. temp := strings.Split(subItem.FeedetlSn, "-")
  2950. newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  2951. if subItem.Type == 2 {
  2952. cus := &models.CustomDetail{
  2953. PrescriptionNumber: chrg_bchno,
  2954. OrderType: "1",
  2955. ChargeSerialNumber: newFl,
  2956. Code: subItem.HisProject.MedicalCode,
  2957. CodeName: subItem.HisProject.ProjectName,
  2958. Flag: "1",
  2959. Price: subItem.Price,
  2960. Count: count,
  2961. ChargeOrderDate: year + month + day,
  2962. DoctorCode: doctor_code,
  2963. Total: detItemFeeSumamt,
  2964. DoseCode: "",
  2965. Spec: "次",
  2966. }
  2967. customs = append(customs, cus)
  2968. }
  2969. }
  2970. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 {
  2971. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  2972. //count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  2973. count, _ := strconv.ParseFloat(strconv.FormatInt(subItem.Count, 10), 64)
  2974. temp := strings.Split(subItem.FeedetlSn, "-")
  2975. newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  2976. if subItem.Type == 3 {
  2977. cus := &models.CustomDetail{
  2978. PrescriptionNumber: chrg_bchno,
  2979. OrderType: "1",
  2980. ChargeSerialNumber: newFl,
  2981. Code: subItem.GoodInfo.MedicalInsuranceNumber,
  2982. CodeName: subItem.GoodInfo.GoodName,
  2983. Flag: "1",
  2984. Price: subItem.Price,
  2985. Count: count,
  2986. ChargeOrderDate: year + month + day,
  2987. DoctorCode: doctor_code,
  2988. Total: detItemFeeSumamt,
  2989. DoseCode: "",
  2990. Spec: "次",
  2991. }
  2992. customs = append(customs, cus)
  2993. }
  2994. }
  2995. }
  2996. }
  2997. //
  2998. //for _, subItem := range item.HisAdditionalCharge {
  2999. // if len(subItem.XtHisAddtionConfig.Code) > 0 {
  3000. // detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  3001. //
  3002. // count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  3003. // cus := &models.CustomDetail{
  3004. // PrescriptionNumber: chrg_bchno,
  3005. // OrderType: "1",
  3006. // ChargeSerialNumber: subItem.FeedetlSn,
  3007. // Code: subItem.XtHisAddtionConfig.Code,
  3008. // CodeName: subItem.XtHisAddtionConfig.Name,
  3009. // Flag: "1",
  3010. // Price: subItem.Price,
  3011. // Count: count,
  3012. // ChargeOrderDate: year + month + day,
  3013. // DoctorCode: doctor_code,
  3014. // Total: detItemFeeSumamt,
  3015. // DoseCode: "",
  3016. // Spec: subItem.XtHisAddtionConfig.,
  3017. // }
  3018. // customs = append(customs, cus)
  3019. // }
  3020. //}
  3021. }
  3022. var pagesize int = 50
  3023. var start int = 1
  3024. var stop int
  3025. var pagecount int
  3026. var curpage int
  3027. var isSuccess bool = true
  3028. //总页数,向上取整,注意除之前要先转换类型为float64
  3029. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  3030. var ress []*Result
  3031. for curpage = 1; curpage <= pagecount; curpage++ {
  3032. if curpage == 1 {
  3033. start = 1
  3034. } else {
  3035. start = (curpage-1)*pagesize + 1
  3036. }
  3037. stop = curpage * pagesize
  3038. if stop > len(customs) {
  3039. stop = len(customs)
  3040. }
  3041. result := service.SzybFY001(doctor_name, doctor_code, miConfig.Code, customs[start-1:stop], verifyCode, number, mz_number, version_code, drug_doctor_code)
  3042. fmt.Println(result)
  3043. var dat map[string]interface{}
  3044. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3045. fmt.Println(dat)
  3046. } else {
  3047. fmt.Println(err)
  3048. }
  3049. userJSONBytes, _ := json.Marshal(dat)
  3050. var res Result
  3051. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3052. utils.ErrorLog("解析失败:%v", err)
  3053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3054. return
  3055. }
  3056. if res.Transreturncode == "00000000" {
  3057. ress = append(ress, &res)
  3058. } else {
  3059. isSuccess = false
  3060. errlog := &models.HisOrderError{
  3061. UserOrgId: adminUser.CurrentOrgId,
  3062. Ctime: time.Now().Unix(),
  3063. Mtime: time.Now().Unix(),
  3064. Number: chrg_bchno,
  3065. ErrMsg: res.Transreturnmessage,
  3066. Status: 1,
  3067. PatientId: patient_id,
  3068. RecordTime: recordDateTime,
  3069. Stage: 4,
  3070. }
  3071. service.CreateErrMsgLog(errlog)
  3072. c.ServeSuccessJSON(map[string]interface{}{
  3073. "failed_code": -10,
  3074. "msg": res.Transreturnmessage,
  3075. })
  3076. return
  3077. }
  3078. //设置变量,根据变量的值来判断上传是否成功
  3079. }
  3080. if isSuccess == true {
  3081. order := &models.HisOrder{
  3082. UserOrgId: adminUser.CurrentOrgId,
  3083. HisPatientId: 0,
  3084. PatientId: patient_id,
  3085. SettleAccountsDate: recordDateTime,
  3086. Ctime: time.Now().Unix(),
  3087. Mtime: time.Now().Unix(),
  3088. Status: 0,
  3089. Number: chrg_bchno,
  3090. Infcode: 0,
  3091. WarnMsg: "",
  3092. Cainfo: "",
  3093. ErrMsg: "",
  3094. RespondTime: "",
  3095. InfRefmsgid: "",
  3096. OrderStatus: 1,
  3097. IsMedicineInsurance: 1,
  3098. SettleType: settle_accounts_type,
  3099. SettleStartTime: start_time,
  3100. SettleEndTime: end_time,
  3101. Creator: admin_user_id,
  3102. Modify: admin_user_id,
  3103. OrgSetlNumber: number,
  3104. MdtrtId: mz_number,
  3105. PType: 2,
  3106. }
  3107. data, _ := json.Marshal(ress)
  3108. order.DetailLog = string(data)
  3109. err = service.CreateOrder(order)
  3110. if err != nil {
  3111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  3112. return
  3113. }
  3114. for _, subItem := range ress {
  3115. for _, item := range subItem.Transbody.Outputlist {
  3116. temp := strings.Split(item.Bkf500, "-")
  3117. var advice_id int64 = 0
  3118. var project_id int64 = 0
  3119. var types int64 = 0
  3120. id, _ := strconv.ParseInt(temp[2], 10, 64)
  3121. types, _ = strconv.ParseInt(temp[1], 10, 64)
  3122. if temp[1] == "1" {
  3123. advice_id = id
  3124. project_id = 0
  3125. } else if temp[1] == "2" {
  3126. advice_id = 0
  3127. project_id = id
  3128. }
  3129. info := &models.HisOrderInfo{
  3130. OrderNumber: order.Number,
  3131. FeedetlSn: item.Bkf500,
  3132. UploadDate: time.Now().Unix(),
  3133. AdviceId: advice_id,
  3134. DetItemFeeSumamt: item.Akc264,
  3135. Cnt: item.Akc226,
  3136. Pric: float64(item.Akc225),
  3137. PatientId: patient_id,
  3138. Status: 1,
  3139. ChrgitmLv: item.Aka065,
  3140. Mtime: time.Now().Unix(),
  3141. Ctime: time.Now().Unix(),
  3142. UserOrgId: adminUser.CurrentOrgId,
  3143. OrderId: order.ID,
  3144. ProjectId: project_id,
  3145. Type: types,
  3146. OverPricPsnPay: item.Akc268,
  3147. AllowReimburse: item.Cka319,
  3148. }
  3149. service.CreateOrderInfo(info)
  3150. }
  3151. }
  3152. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  3153. service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, his_patient_id, chrg_bchno, recordDateTime)
  3154. var total float64
  3155. for _, item := range prescriptions {
  3156. if item.Type == 1 { //药品
  3157. for _, subItem := range item.HisDoctorAdviceInfo {
  3158. total = total + (subItem.Price * subItem.PrescribingNumber)
  3159. }
  3160. }
  3161. if item.Type == 2 { //项目
  3162. for _, subItem := range item.HisPrescriptionProject {
  3163. total = total + (subItem.Price * float64(subItem.Count))
  3164. }
  3165. }
  3166. }
  3167. for _, item := range prescriptions {
  3168. for _, subItem := range item.HisAdditionalCharge {
  3169. total = total + (subItem.Price * float64(subItem.Count))
  3170. }
  3171. }
  3172. total, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", total), 64)
  3173. yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("FY005" + "|" + number + "|" + miConfig.Code + "|")
  3174. if ret4 == 0 {
  3175. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  3176. tempPatient, _ := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  3177. if tempPatient.ID == patient_id {
  3178. result_three := service.SzybFY004(doctor_name, doctor_code, miConfig.Code, total, yiliao_number, verifyCode, number, mz_number, version_code, drug_doctor_code, drug_doctor_name, his.MedicalTreatmentType, sick.CountryCode)
  3179. var dat map[string]interface{}
  3180. if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  3181. fmt.Println(dat)
  3182. } else {
  3183. fmt.Println(err)
  3184. }
  3185. userJSONBytes, _ := json.Marshal(dat)
  3186. var res ResultTwo
  3187. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3188. utils.ErrorLog("解析失败:%v", err)
  3189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3190. return
  3191. }
  3192. if res.Transreturncode == "00000000" {
  3193. order.OrderStatus = 1
  3194. order.Status = 1
  3195. order.PsnNo = health_card_no
  3196. order.Modify = admin_user_id
  3197. order.MedfeeSumamt = res.Transbody.Akc264
  3198. order.FundPaySumamt = res.Transbody.Akb068
  3199. order.AcctPay = res.Transbody.Akb066
  3200. order.PsnCashPay = res.Transbody.Akb067
  3201. order.PsnPartAmt = res.Transbody.Akb067
  3202. order.AccountPrice = res.Transbody.Aae240
  3203. order.MzNumber = mz_number
  3204. order.YiliaoNumber = yiliao_number
  3205. setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  3206. detailStrOne := string(setlDetailOne)
  3207. order.SzChargeInfo = detailStrOne
  3208. setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  3209. detailStrTwo := string(setlDetailTwo)
  3210. order.SzProjectInfo = detailStrTwo
  3211. setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  3212. detailStrThree := string(setlDetailThree)
  3213. order.SzMedicineInsuranceInfo = detailStrThree
  3214. order.Cainfo = result_three
  3215. order.IsPre = 1
  3216. //err = service.UpdataOrderStatusTwo(order.Number, adminUser.CurrentOrgId)
  3217. err = service.UpDateOrderTwo(order)
  3218. c.ServeSuccessJSON(map[string]interface{}{
  3219. "msg": "预结算成功",
  3220. })
  3221. } else {
  3222. //预结算报错
  3223. errlog := &models.HisOrderError{
  3224. UserOrgId: adminUser.CurrentOrgId,
  3225. Ctime: time.Now().Unix(),
  3226. Mtime: time.Now().Unix(),
  3227. Number: chrg_bchno,
  3228. ErrMsg: res.Transreturnmessage,
  3229. Status: 1,
  3230. PatientId: patient_id,
  3231. RecordTime: recordDateTime,
  3232. Stage: 20,
  3233. }
  3234. service.CreateErrMsgLog(errlog)
  3235. c.ServeSuccessJSON(map[string]interface{}{
  3236. "failed_code": -10,
  3237. "msg": res.Transreturnmessage,
  3238. })
  3239. }
  3240. } else {
  3241. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  3242. return
  3243. }
  3244. } else {
  3245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  3246. return
  3247. }
  3248. } else {
  3249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePreSettleFaildParamWrong)
  3250. return
  3251. }
  3252. }
  3253. //func (c *SZHisApiController) GetSettleInfo() {
  3254. // pay_way, _ := c.GetInt64("pay_way")
  3255. // pay_price, _ := c.GetFloat("pay_price")
  3256. // pay_card_no := c.GetString("pay_card_no")
  3257. // discount_price, _ := c.GetFloat("discount_price")
  3258. // preferential_price, _ := c.GetFloat("preferential_price")
  3259. // reality_price, _ := c.GetFloat("reality_price")
  3260. // found_price, _ := c.GetFloat("found_price")
  3261. // medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  3262. // private_price, _ := c.GetFloat("private_price")
  3263. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  3264. // patient_id, _ := c.GetInt64("id")
  3265. // record_time := c.GetString("record_time")
  3266. // admin_user_id, _ := c.GetInt64("admin_user_id")
  3267. // timestamp := time.Now().Unix()
  3268. // tempTime := time.Unix(timestamp, 0)
  3269. // timeFormat := tempTime.Format("20060102150405")
  3270. // chrgBchno := rand.Intn(10000) + 1000
  3271. // chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(1, 10)
  3272. // adminUser := c.GetAdminUserInfo()
  3273. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3274. // month := time.Unix(1557042972, 0).Format("1")
  3275. // year := time.Now().Format("2006")
  3276. // month = time.Now().Format("01")
  3277. // day := time.Now().Format("02")
  3278. //
  3279. // timeLayout := "2006-01-02"
  3280. // loc, _ := time.LoadLocation("Local")
  3281. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3282. // fmt.Println(err)
  3283. // if err != nil {
  3284. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3285. // return
  3286. // }
  3287. // recordDateTime := theTime.Unix()
  3288. //
  3289. // var prescriptions []*models.HisPrescription
  3290. //
  3291. // var start_time int64
  3292. // var end_time int64
  3293. //
  3294. // if settle_accounts_type == 1 { //日结
  3295. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3296. //
  3297. // } else { //月结
  3298. // start_time_str := c.GetString("start_time")
  3299. // end_time_str := c.GetString("end_time")
  3300. // timeLayout := "2006-01-02"
  3301. // loc, _ := time.LoadLocation("Local")
  3302. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3303. // if err != nil {
  3304. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3305. // return
  3306. // }
  3307. // recordStartTime := theStartTime.Unix()
  3308. // start_time = recordStartTime
  3309. //
  3310. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3311. // if err != nil {
  3312. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3313. // return
  3314. // }
  3315. // recordEndTime := theEndTime.Unix()
  3316. // end_time = recordEndTime
  3317. //
  3318. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
  3319. // }
  3320. //
  3321. // var ids []int64
  3322. // for _, item := range prescriptions {
  3323. // ids = append(ids, item.ID)
  3324. // }
  3325. //
  3326. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3327. //
  3328. // adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  3329. //
  3330. // adminRole, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3331. // his, err := service.GetHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3332. // mz_number := his.Number
  3333. // number := miConfig.Code + year + month + day +
  3334. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  3335. // var doctor_name string
  3336. // var doctor_code string
  3337. // var drug_doctor_code string
  3338. // drug_doctor_code = adminRole_two.DoctorCode
  3339. // drug_doctor_name := adminRole_two.UserName
  3340. //
  3341. // if adminRole.ID == 0 {
  3342. // doctor_name = "黄亦轩"
  3343. // doctor_code = "1"
  3344. // } else {
  3345. // doctor_name = adminRole.UserName
  3346. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  3347. // }
  3348. //
  3349. // verifyCode, version_code := ReadCardGetCode("FY001" + "|" + number + "|" + miConfig.Code)
  3350. // //verifyCode := "000000|bf885fa312a7f92861d6b61542a637fa"
  3351. // //version_code := "V0.3"
  3352. // var customs []*models.CustomDetail
  3353. // for _, item := range prescriptions {
  3354. // if item.Type == 1 { //药品
  3355. // for _, subItem := range item.HisDoctorAdviceInfo {
  3356. // fmt.Println(subItem.BaseDrugLib.MedicalInsuranceNumber)
  3357. //
  3358. // if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 {
  3359. // _, dose_code := service.GetDoseCode(subItem.BaseDrugLib.DrugDosageForm, adminUser.CurrentOrgId)
  3360. // detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber), 64)
  3361. // price, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price), 64)
  3362. // temp := strings.Split(subItem.FeedetlSn, "-")
  3363. // newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  3364. //
  3365. // cus := &models.CustomDetail{
  3366. // PrescriptionNumber: chrg_bchno,
  3367. // OrderType: "1",
  3368. // ChargeSerialNumber: newFl,
  3369. // Code: subItem.BaseDrugLib.MedicalInsuranceNumber,
  3370. // CodeName: subItem.BaseDrugLib.DrugName,
  3371. // Flag: "1",
  3372. // Price: price,
  3373. // Count: subItem.PrescribingNumber,
  3374. // ChargeOrderDate: year + month + day,
  3375. // DoctorCode: doctor_code,
  3376. // Total: detItemFeeSumamt,
  3377. // DoseCode: dose_code,
  3378. // Spec: subItem.BaseDrugLib.DrugSpec,
  3379. // }
  3380. // customs = append(customs, cus)
  3381. // }
  3382. // }
  3383. // }
  3384. //
  3385. // if item.Type == 2 { //项目
  3386. // for _, subItem := range item.HisPrescriptionProject {
  3387. // if len(subItem.HisProject.MedicalCode) > 0 {
  3388. // detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  3389. //
  3390. // count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  3391. // temp := strings.Split(subItem.FeedetlSn, "-")
  3392. // newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  3393. //
  3394. // cus := &models.CustomDetail{
  3395. // PrescriptionNumber: chrg_bchno,
  3396. // OrderType: "1",
  3397. // ChargeSerialNumber: newFl,
  3398. // Code: subItem.HisProject.MedicalCode,
  3399. // CodeName: subItem.HisProject.ProjectName,
  3400. // Flag: "1",
  3401. // Price: subItem.Price,
  3402. // Count: count,
  3403. // ChargeOrderDate: year + month + day,
  3404. // DoctorCode: doctor_code,
  3405. // Total: detItemFeeSumamt,
  3406. // DoseCode: "",
  3407. // Spec: "次",
  3408. // }
  3409. // customs = append(customs, cus)
  3410. // }
  3411. // }
  3412. // }
  3413. // //
  3414. // //for _, subItem := range item.HisAdditionalCharge {
  3415. // // if len(subItem.XtHisAddtionConfig.Code) > 0 {
  3416. // // detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  3417. // //
  3418. // // count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  3419. // // cus := &models.CustomDetail{
  3420. // // PrescriptionNumber: chrg_bchno,
  3421. // // OrderType: "1",
  3422. // // ChargeSerialNumber: subItem.FeedetlSn,
  3423. // // Code: subItem.XtHisAddtionConfig.Code,
  3424. // // CodeName: subItem.XtHisAddtionConfig.Name,
  3425. // // Flag: "1",
  3426. // // Price: subItem.Price,
  3427. // // Count: count,
  3428. // // ChargeOrderDate: year + month + day,
  3429. // // DoctorCode: doctor_code,
  3430. // // Total: detItemFeeSumamt,
  3431. // // DoseCode: "",
  3432. // // Spec: subItem.XtHisAddtionConfig.,
  3433. // // }
  3434. // // customs = append(customs, cus)
  3435. // // }
  3436. // //}
  3437. // }
  3438. //
  3439. // var pagesize int = 50
  3440. // var start int = 1
  3441. // var stop int
  3442. // var pagecount int
  3443. // var curpage int
  3444. // var isSuccess bool = true
  3445. // //总页数,向上取整,注意除之前要先转换类型为float64
  3446. // pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  3447. //
  3448. // var ress []*Result
  3449. // for curpage = 1; curpage <= pagecount; curpage++ {
  3450. // if curpage == 1 {
  3451. // start = 1
  3452. // } else {
  3453. // start = (curpage-1)*pagesize + 1
  3454. // }
  3455. // stop = curpage * pagesize
  3456. // if stop > len(customs) {
  3457. // stop = len(customs)
  3458. // }
  3459. // result := service.SzybFY001(doctor_name, doctor_code, miConfig.Code, customs[start-1:stop], verifyCode, number, mz_number, version_code, drug_doctor_code)
  3460. // fmt.Println(result)
  3461. //
  3462. // var dat map[string]interface{}
  3463. // if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3464. // fmt.Println(dat)
  3465. // } else {
  3466. // fmt.Println(err)
  3467. // }
  3468. //
  3469. // userJSONBytes, _ := json.Marshal(dat)
  3470. //
  3471. // var res Result
  3472. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3473. // utils.ErrorLog("解析失败:%v", err)
  3474. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3475. // return
  3476. // }
  3477. // if res.Transreturncode == "00000000" {
  3478. // ress = append(ress, &res)
  3479. // } else {
  3480. // isSuccess = false
  3481. // errlog := &models.HisOrderError{
  3482. // UserOrgId: adminUser.CurrentOrgId,
  3483. // Ctime: time.Now().Unix(),
  3484. // Mtime: time.Now().Unix(),
  3485. // Number: chrg_bchno,
  3486. // ErrMsg: res.Transreturnmessage,
  3487. // Status: 1,
  3488. // PatientId: patient_id,
  3489. // RecordTime: recordDateTime,
  3490. // Stage: 4,
  3491. // }
  3492. // service.CreateErrMsgLog(errlog)
  3493. // c.ServeSuccessJSON(map[string]interface{}{
  3494. // "failed_code": -10,
  3495. // "msg": res.Transreturnmessage,
  3496. // })
  3497. // return
  3498. // }
  3499. // //设置变量,根据变量的值来判断上传是否成功
  3500. // }
  3501. // if isSuccess == true {
  3502. // order := &models.HisOrder{
  3503. // UserOrgId: adminUser.CurrentOrgId,
  3504. // HisPatientId: 0,
  3505. // PatientId: patient_id,
  3506. // SettleAccountsDate: recordDateTime,
  3507. // Ctime: time.Now().Unix(),
  3508. // Mtime: time.Now().Unix(),
  3509. // Status: 1,
  3510. // Number: chrg_bchno,
  3511. // Infcode: 0,
  3512. // WarnMsg: "",
  3513. // Cainfo: "",
  3514. // ErrMsg: "",
  3515. // RespondTime: "",
  3516. // InfRefmsgid: "",
  3517. // OrderStatus: 1,
  3518. // IsMedicineInsurance: 1,
  3519. // SettleType: settle_accounts_type,
  3520. // SettleStartTime: start_time,
  3521. // SettleEndTime: end_time,
  3522. // Creator: admin_user_id,
  3523. // Modify: admin_user_id,
  3524. // OrgSetlNumber: number,
  3525. // }
  3526. // data, _ := json.Marshal(ress)
  3527. // order.DetailLog = string(data)
  3528. //
  3529. // err = service.CreateOrder(order)
  3530. // if err != nil {
  3531. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  3532. // return
  3533. // }
  3534. //
  3535. // for _, subItem := range ress {
  3536. // for _, item := range subItem.Transbody.Outputlist {
  3537. //
  3538. // temp := strings.Split(item.Bkf500, "-")
  3539. // var advice_id int64 = 0
  3540. // var project_id int64 = 0
  3541. // var types int64 = 0
  3542. //
  3543. // id, _ := strconv.ParseInt(temp[2], 10, 64)
  3544. // types, _ = strconv.ParseInt(temp[1], 10, 64)
  3545. //
  3546. // if temp[1] == "1" {
  3547. // advice_id = id
  3548. // project_id = 0
  3549. // } else if temp[1] == "2" {
  3550. // advice_id = 0
  3551. // project_id = id
  3552. // }
  3553. //
  3554. // info := &models.HisOrderInfo{
  3555. // OrderNumber: order.Number,
  3556. // FeedetlSn: item.Bkf500,
  3557. // UploadDate: time.Now().Unix(),
  3558. // AdviceId: advice_id,
  3559. // DetItemFeeSumamt: item.Akc264,
  3560. // Cnt: item.Akc226,
  3561. // Pric: float64(item.Akc225),
  3562. // PatientId: patient_id,
  3563. // Status: 1,
  3564. // ChrgitmLv: item.Aka065,
  3565. // Mtime: time.Now().Unix(),
  3566. // Ctime: time.Now().Unix(),
  3567. // UserOrgId: adminUser.CurrentOrgId,
  3568. // OrderId: order.ID,
  3569. // ProjectId: project_id,
  3570. // Type: types,
  3571. //
  3572. // OverPricPsnPay: item.Akc268,
  3573. // AllowReimburse: item.Cka319,
  3574. // }
  3575. // service.CreateOrderInfo(info)
  3576. //
  3577. // }
  3578. // }
  3579. // service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  3580. // service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patient_id, chrg_bchno, recordDateTime)
  3581. // var total float64
  3582. // for _, item := range prescriptions {
  3583. // if item.Type == 1 { //药品
  3584. // for _, subItem := range item.HisDoctorAdviceInfo {
  3585. // total = total + (subItem.Price * subItem.PrescribingNumber)
  3586. // }
  3587. // }
  3588. // if item.Type == 2 { //项目
  3589. // for _, subItem := range item.HisPrescriptionProject {
  3590. // total = total + (subItem.Price * float64(subItem.Count))
  3591. // }
  3592. // }
  3593. // }
  3594. // for _, item := range prescriptions {
  3595. // for _, subItem := range item.HisAdditionalCharge {
  3596. // total = total + (subItem.Price * float64(subItem.Count))
  3597. // }
  3598. // }
  3599. //
  3600. // yiliao_number, id_card_number, verifyCode, version_code, _, ret4 := ReadBasCardGetNumber("FY005" + "|" + number + "|" + miConfig.Code + "|")
  3601. // if ret4 == 0 {
  3602. // //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  3603. // tempPatient, _ := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  3604. // if tempPatient.ID == patient_id {
  3605. //
  3606. // result_three := service.SzybFY005(doctor_name, doctor_code, miConfig.Code, total, yiliao_number, verifyCode, number, mz_number, version_code, drug_doctor_code, drug_doctor_name, his.MedicalTreatmentType)
  3607. // var dat map[string]interface{}
  3608. // if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  3609. // fmt.Println(dat)
  3610. // } else {
  3611. // fmt.Println(err)
  3612. // }
  3613. // userJSONBytes, _ := json.Marshal(dat)
  3614. // var res ResultTwo
  3615. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3616. // utils.ErrorLog("解析失败:%v", err)
  3617. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3618. // return
  3619. // }
  3620. //
  3621. // if res.Transreturncode == "00000000" {
  3622. // order.OrderStatus = 2
  3623. // order.PayWay = pay_way
  3624. // order.PayPrice = pay_price
  3625. // order.PayCardNo = pay_card_no
  3626. // order.DiscountPrice = discount_price
  3627. // order.PreferentialPrice = preferential_price
  3628. // order.RealityPrice = reality_price
  3629. // order.FoundPrice = found_price
  3630. // order.MedicalInsurancePrice = medical_insurance_price
  3631. // order.PrivatePrice = private_price
  3632. // order.Modify = admin_user_id
  3633. // order.MedfeeSumamt = res.Transbody.Akc264
  3634. // order.SetlId = res.Transbody.Ckc618
  3635. // order.FundPaySumamt = res.Transbody.Akb068
  3636. // order.AcctPay = res.Transbody.Akb066
  3637. // order.PsnCashPay = res.Transbody.Akb067
  3638. // order.PsnPartAmt = res.Transbody.Akb067
  3639. // order.AccountPrice = res.Transbody.Aae240
  3640. // order.MzNumber = mz_number
  3641. // order.YiliaoNumber = yiliao_number
  3642. // setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  3643. // detailStrOne := string(setlDetailOne)
  3644. // order.SzChargeInfo = detailStrOne
  3645. // setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  3646. // detailStrTwo := string(setlDetailTwo)
  3647. // order.SzProjectInfo = detailStrTwo
  3648. // setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  3649. // detailStrThree := string(setlDetailThree)
  3650. // order.SzMedicineInsuranceInfo = detailStrThree
  3651. // order.Cainfo = result_three
  3652. // err = service.UpdataOrderStatusTwo(order.Number, adminUser.CurrentOrgId)
  3653. // err = service.UpDateOrderTwo(order)
  3654. // c.ServeSuccessJSON(map[string]interface{}{
  3655. // "msg": "结算成功",
  3656. // })
  3657. // } else {
  3658. // //结算报错
  3659. // errlog := &models.HisOrderError{
  3660. // UserOrgId: adminUser.CurrentOrgId,
  3661. // Ctime: time.Now().Unix(),
  3662. // Mtime: time.Now().Unix(),
  3663. // Number: chrg_bchno,
  3664. // ErrMsg: res.Transreturnmessage,
  3665. // Status: 1,
  3666. // PatientId: patient_id,
  3667. // RecordTime: recordDateTime,
  3668. // Stage: 6,
  3669. // }
  3670. // service.CreateErrMsgLog(errlog)
  3671. // c.ServeSuccessJSON(map[string]interface{}{
  3672. // "failed_code": -10,
  3673. // "msg": res.Transreturnmessage,
  3674. // })
  3675. // }
  3676. // } else {
  3677. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  3678. // return
  3679. // }
  3680. // } else {
  3681. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  3682. // return
  3683. // }
  3684. // } else {
  3685. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePreSettleFaildParamWrong)
  3686. // return
  3687. // }
  3688. //}
  3689. //结算
  3690. //func (c *SZHisApiController) GetSettleInfo() {
  3691. // patient_id, _ := c.GetInt64("id")
  3692. // order_id, _ := c.GetInt64("order_id")
  3693. // record_time := c.GetString("record_time")
  3694. // pay_way, _ := c.GetInt64("pay_way")
  3695. // pay_price, _ := c.GetFloat("pay_price")
  3696. // pay_card_no := c.GetString("pay_card_no")
  3697. // discount_price, _ := c.GetFloat("discount_price")
  3698. // preferential_price, _ := c.GetFloat("preferential_price")
  3699. // reality_price, _ := c.GetFloat("reality_price")
  3700. // found_price, _ := c.GetFloat("found_price")
  3701. // medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  3702. // private_price, _ := c.GetFloat("private_price")
  3703. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  3704. // admin_user_id, _ := c.GetInt64("admin_user_id")
  3705. //
  3706. // timeLayout := "2006-01-02"
  3707. // loc, _ := time.LoadLocation("Local")
  3708. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3709. // if err != nil {
  3710. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3711. // return
  3712. // }
  3713. // recordDateTime := theTime.Unix()
  3714. // adminUser := c.GetAdminUserInfo()
  3715. //
  3716. // var prescriptions []*models.HisPrescription
  3717. //
  3718. // data := make(map[string]interface{})
  3719. // if settle_accounts_type == 1 { //日结
  3720. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3721. // data["pre"] = prescriptions
  3722. //
  3723. // } else { //月结
  3724. // start_time_str := c.GetString("start_time")
  3725. // end_time_str := c.GetString("end_time")
  3726. // timeLayout := "2006-01-02"
  3727. // loc, _ := time.LoadLocation("Local")
  3728. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3729. // if err != nil {
  3730. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3731. // return
  3732. // }
  3733. // recordStartTime := theStartTime.Unix()
  3734. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3735. // if err != nil {
  3736. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3737. // return
  3738. // }
  3739. // recordEndTime := theEndTime.Unix()
  3740. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
  3741. // data["pre"] = prescriptions
  3742. //
  3743. // }
  3744. //
  3745. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3746. // his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3747. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3748. // strconv.FormatInt(his.PatientId, 10)
  3749. //
  3750. // order_src, _ := service.GetHisOrderByID(order_id)
  3751. //
  3752. // if order_src.ID == 0 {
  3753. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  3754. // return
  3755. // }
  3756. //
  3757. // config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3758. // if config.IsOpen == 1 { //对接了医保,走医保流程
  3759. // if order_src.OrderStatus != 2 {
  3760. // var total float64
  3761. // for _, item := range prescriptions {
  3762. // if item.Type == 1 { //药品
  3763. // for _, subItem := range item.HisDoctorAdviceInfo {
  3764. // total = total + (subItem.Price * subItem.PrescribingNumber)
  3765. // }
  3766. // }
  3767. // if item.Type == 2 { //项目
  3768. // for _, subItem := range item.HisPrescriptionProject {
  3769. // total = total + (subItem.Price * float64(subItem.Count))
  3770. // }
  3771. // }
  3772. // }
  3773. //
  3774. // for _, item := range prescriptions {
  3775. // for _, subItem := range item.HisAdditionalCharge {
  3776. // total = total + (subItem.Price * float64(subItem.Count))
  3777. // }
  3778. // }
  3779. //
  3780. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3781. //
  3782. // adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  3783. //
  3784. // var drug_doctor string
  3785. // drug_doctor = adminRole_two.DoctorCode
  3786. // drug_doctor_name := adminRole_two.UserName
  3787. // //结算流程
  3788. // var doctor_name string
  3789. // var doctor_code string
  3790. // if roles.ID == 0 {
  3791. // doctor_name = "黄亦轩"
  3792. // doctor_code = "1010"
  3793. // } else {
  3794. // doctor_name = roles.UserName
  3795. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  3796. // }
  3797. // number := order_src.OrgSetlNumber
  3798. // mz_number := his.Number
  3799. // verifyCode, version_code := ReadCardGetCode("FY005" + "|" + number + "|" + miConfig.Code)
  3800. //
  3801. // //verifyCode := "000000|707c35a62c2f0609d7b0a811649f3913"
  3802. // //version_code := "V0.3"
  3803. // yiliao_number, id_card_number, verifyCode, version_code, err, ret4 := ReadBasCardGetNumber("FY005" + "|" + number + "|" + miConfig.Code)
  3804. // yiliao_number := his.YiliaoNumber
  3805. // result_three := service.SzybFY005(doctor_name, doctor_code, miConfig.Code, total, yiliao_number, verifyCode, number, mz_number, version_code, drug_doctor, drug_doctor_name)
  3806. // var dat map[string]interface{}
  3807. // if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  3808. // fmt.Println(dat)
  3809. // } else {
  3810. // fmt.Println(err)
  3811. // }
  3812. // userJSONBytes, _ := json.Marshal(dat)
  3813. // var res ResultTwo
  3814. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3815. // utils.ErrorLog("解析失败:%v", err)
  3816. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3817. // return
  3818. // }
  3819. //
  3820. // if res.Transreturncode == "00000000" {
  3821. // order_src.OrderStatus = 2
  3822. // order_src.PayWay = pay_way
  3823. // order_src.PayPrice = pay_price
  3824. // order_src.PayCardNo = pay_card_no
  3825. // order_src.DiscountPrice = discount_price
  3826. // order_src.PreferentialPrice = preferential_price
  3827. // order_src.RealityPrice = reality_price
  3828. // order_src.FoundPrice = found_price
  3829. // order_src.MedicalInsurancePrice = medical_insurance_price
  3830. // order_src.PrivatePrice = private_price
  3831. // order_src.Creator = order_src.Creator
  3832. // order_src.Modify = roles.ID
  3833. // order_src.MedfeeSumamt = res.Transbody.Akc264
  3834. // order_src.SetlId = res.Transbody.Ckc618
  3835. // order_src.FundPaySumamt = res.Transbody.Akb068
  3836. // order_src.AcctPay = res.Transbody.Akb066
  3837. // order_src.PsnCashPay = res.Transbody.Akb067
  3838. // order_src.PsnPartAmt = res.Transbody.Akb067
  3839. // order_src.AccountPrice = res.Transbody.Aae240
  3840. // order_src.MzNumber = mz_number
  3841. // order_src.YiliaoNumber = yiliao_number
  3842. // setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  3843. // detailStrOne := string(setlDetailOne)
  3844. // order_src.SzChargeInfo = detailStrOne
  3845. // setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  3846. // detailStrTwo := string(setlDetailTwo)
  3847. // order_src.SzProjectInfo = detailStrTwo
  3848. // setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  3849. // detailStrThree := string(setlDetailThree)
  3850. // order_src.SzMedicineInsuranceInfo = detailStrThree
  3851. // order_src.Cainfo = result_three
  3852. //
  3853. // err = service.UpdataOrderStatusTwo(order_src.Number, adminUser.CurrentOrgId)
  3854. // err = service.UpDateOrder(order_src)
  3855. //
  3856. // c.ServeSuccessJSON(map[string]interface{}{
  3857. // "msg": "结算成功",
  3858. // })
  3859. // } else {
  3860. // //version_code := "0.03"
  3861. // c.ServeSuccessJSON(map[string]interface{}{
  3862. // "failed_code": -10,
  3863. // "msg": res.Transreturnmessage,
  3864. // })
  3865. //
  3866. // }
  3867. // } else {
  3868. //
  3869. // //错误提示
  3870. //
  3871. // }
  3872. // } else {
  3873. // //错误提示
  3874. //
  3875. // }
  3876. //}
  3877. //当月退费
  3878. func (c *SZHisApiController) Refund() {
  3879. order_id, _ := c.GetInt64("order_id")
  3880. record_time := c.GetString("record_time")
  3881. //patient_id, _ := c.GetInt64("patient_id")
  3882. //his_patient_id, _ := c.GetInt64("his_patient_id")
  3883. admin_user_id, _ := c.GetInt64("admin_user_id")
  3884. timeLayout := "2006-01-02"
  3885. loc, _ := time.LoadLocation("Local")
  3886. adminUser := c.GetAdminUserInfo()
  3887. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3888. fmt.Println(err)
  3889. if err != nil {
  3890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3891. return
  3892. }
  3893. recordDateTime := theTime.Unix()
  3894. fmt.Println(recordDateTime)
  3895. var order models.HisOrder
  3896. order, _ = service.GetHisOrderByID(order_id)
  3897. if order.ID == 0 {
  3898. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  3899. return
  3900. }
  3901. //his, _ := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, theTime.Unix())
  3902. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3903. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3904. //结算流程
  3905. var doctor_name string
  3906. var doctor_code string
  3907. if roles.ID == 0 {
  3908. doctor_name = "管理员"
  3909. doctor_code = "01"
  3910. } else {
  3911. doctor_name = roles.UserName
  3912. doctor_code = strconv.FormatInt(admin_user_id, 10)
  3913. }
  3914. month := time.Unix(1557042972, 0).Format("1")
  3915. year := time.Now().Format("2006")
  3916. month = time.Now().Format("01")
  3917. day := time.Now().Format("02")
  3918. //number := miConfig.Code + year + month + day + "1367866"
  3919. number := miConfig.Code + year + month + day +
  3920. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  3921. //number := miConfig.Code + year + month + day + "1590003"
  3922. //流水号
  3923. //number_two := miConfig.Code + "-" + year + month + day + "-" + strconv.FormatInt(patient_id, 10)
  3924. verifyCode, version_code := ReadCardGetCode("JY002" + "|" + number + "|" + miConfig.Code)
  3925. //version_code := "V0.3"
  3926. //
  3927. //verifyCode := "000000|9972fca7ba9471c7dbe08324b2e31f70"
  3928. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3929. order_infos, _ := service.GetHisOrderInfoByNumber(order.Number)
  3930. var customs []*models.CustomDetail
  3931. for _, item := range order_infos {
  3932. cus := &models.CustomDetail{
  3933. PrescriptionNumber: item.OrderNumber,
  3934. ChargeSerialNumber: item.FeedetlSn,
  3935. }
  3936. customs = append(customs, cus)
  3937. }
  3938. if config.IsOpen == 1 { //对接了医保,走医保流程
  3939. result := service.SzybJY002(doctor_name, doctor_code, miConfig.Code, order.OrgSetlNumber, order.MzNumber, verifyCode, number, version_code)
  3940. fmt.Println(result)
  3941. var dat map[string]interface{}
  3942. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3943. fmt.Println(dat)
  3944. } else {
  3945. fmt.Println(err)
  3946. }
  3947. userJSONBytes, _ := json.Marshal(dat)
  3948. var res ResultThree
  3949. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3950. utils.ErrorLog("解析失败:%v", err)
  3951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3952. return
  3953. }
  3954. if res.Transreturncode == "00000000" {
  3955. service.UpdataOrderlog(order_id, adminUser.CurrentOrgId, result)
  3956. service.UpdataOrderStatusSZ(order_id, order.Number, adminUser.CurrentOrgId)
  3957. service.UpdataOrderInfoStatus(order.ID, order.Number, adminUser.CurrentOrgId)
  3958. c.ServeSuccessJSON(map[string]interface{}{
  3959. "msg": "退费成功",
  3960. })
  3961. } else {
  3962. c.ServeSuccessJSON(map[string]interface{}{
  3963. "failed_code": -10,
  3964. "msg": res.Transreturnmessage,
  3965. })
  3966. }
  3967. }
  3968. }
  3969. //跨月退费
  3970. func (c *SZHisApiController) MonthRefund() {
  3971. order_id, _ := c.GetInt64("order_id")
  3972. record_time := c.GetString("record_time")
  3973. patient_id, _ := c.GetInt64("patient_id")
  3974. admin_user_id, _ := c.GetInt64("admin_user_id")
  3975. timeLayout := "2006-01-02"
  3976. loc, _ := time.LoadLocation("Local")
  3977. adminUser := c.GetAdminUserInfo()
  3978. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3979. fmt.Println(err)
  3980. if err != nil {
  3981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3982. return
  3983. }
  3984. recordDateTime := theTime.Unix()
  3985. var order models.HisOrder
  3986. order, _ = service.GetHisOrderByID(order_id)
  3987. if order.ID == 0 {
  3988. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  3989. }
  3990. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3991. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3992. //结算流程
  3993. var doctor_name string
  3994. var doctor_code string
  3995. if roles.ID == 0 {
  3996. doctor_name = "管理员"
  3997. doctor_code = "01"
  3998. } else {
  3999. doctor_name = roles.UserName
  4000. doctor_code = strconv.FormatInt(admin_user_id, 10)
  4001. }
  4002. month := time.Unix(1557042972, 0).Format("1")
  4003. year := time.Now().Format("2006")
  4004. month = time.Now().Format("01")
  4005. day := time.Now().Format("02")
  4006. //流水号
  4007. number_two := miConfig.Code + "-" + year + month + day + "-" + strconv.FormatInt(patient_id, 10)
  4008. //verifyCode,version_code := ReadCardGetCode("JY002" + "|" + number_two + "|" + miConfig.Code)
  4009. version_code := "0.03"
  4010. fmt.Println(number_two)
  4011. verifyCode := "000000|0872038667cc34efdc35ce4668589a5f"
  4012. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4013. if config.IsOpen == 1 { //对接了医保,走医保流程
  4014. result := service.SzybJY003(doctor_name, doctor_code, miConfig.Code, order.OrgSetlNumber, order.MzNumber, verifyCode, version_code)
  4015. fmt.Println(result)
  4016. var dat map[string]interface{}
  4017. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4018. fmt.Println(dat)
  4019. } else {
  4020. fmt.Println(err)
  4021. }
  4022. userJSONBytes, _ := json.Marshal(dat)
  4023. var res ResultThree
  4024. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4025. utils.ErrorLog("解析失败:%v", err)
  4026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4027. return
  4028. }
  4029. if res.Transreturncode == "00000000" {
  4030. c.ServeSuccessJSON(map[string]interface{}{
  4031. "msg": "退费成功",
  4032. })
  4033. } else {
  4034. }
  4035. }
  4036. }
  4037. //查询
  4038. func (c *SZHisApiController) GetSettleAccounts() {
  4039. order_id, _ := c.GetInt64("order_id")
  4040. record_time := c.GetString("record_time")
  4041. patient_id, _ := c.GetInt64("patient_id")
  4042. admin_user_id, _ := c.GetInt64("admin_user_id")
  4043. timeLayout := "2006-01-02"
  4044. loc, _ := time.LoadLocation("Local")
  4045. adminUser := c.GetAdminUserInfo()
  4046. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4047. fmt.Println(err)
  4048. if err != nil {
  4049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4050. return
  4051. }
  4052. recordDateTime := theTime.Unix()
  4053. fmt.Println(recordDateTime)
  4054. var order models.HisOrder
  4055. order, _ = service.GetHisOrderByID(order_id)
  4056. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, patient_id)
  4057. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  4058. adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  4059. his, _ := service.GetHisPatientInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  4060. yiliao_leibie := ""
  4061. switch his.MedicalTreatmentType {
  4062. case 11:
  4063. yiliao_leibie = "普通门诊"
  4064. break
  4065. case 12:
  4066. yiliao_leibie = "家庭通道"
  4067. break
  4068. case 13:
  4069. yiliao_leibie = "门诊大病"
  4070. break
  4071. case 14:
  4072. yiliao_leibie = "重疾特药"
  4073. break
  4074. case 15:
  4075. yiliao_leibie = "门诊慢病"
  4076. break
  4077. case 16:
  4078. yiliao_leibie = "门诊特检"
  4079. break
  4080. case 17:
  4081. yiliao_leibie = "健康体检"
  4082. break
  4083. case 18:
  4084. yiliao_leibie = "预防接种"
  4085. break
  4086. case 19:
  4087. yiliao_leibie = "门诊输血"
  4088. break
  4089. case 91:
  4090. yiliao_leibie = "新冠肺炎门诊"
  4091. break
  4092. }
  4093. //departments, _ := service.Get(patientPrescription.Departments)
  4094. departments, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  4095. if order.ID == 0 {
  4096. //order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  4097. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  4098. return
  4099. }
  4100. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4101. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4102. //结算流程
  4103. var doctor_name string
  4104. var doctor_code string
  4105. if roles.ID == 0 {
  4106. doctor_name = "管理员"
  4107. doctor_code = "01"
  4108. } else {
  4109. doctor_name = roles.UserName
  4110. doctor_code = strconv.FormatInt(admin_user_id, 10)
  4111. }
  4112. //month := time.Unix(1557042972, 0).Format("1")
  4113. //year := time.Now().Format("2006")
  4114. //month = time.Now().Format("01")
  4115. //day := time.Now().Format("02")
  4116. //流水号
  4117. //number_two := miConfig.Code + "-" + year + month + day + "-" + strconv.FormatInt(patient_id, 10)
  4118. //fmt.Println(number_two)
  4119. verifyCode, version_code := ReadCardGetCode("JY001" + "|" + order.OrgSetlNumber + "|" + miConfig.Code)
  4120. //version_code := "V0.3"
  4121. //verifyCode := "000000|2c9854287e7c3cbc34439ab8e5157816"
  4122. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4123. if config.IsOpen == 1 { //对接了医保,走医保流程
  4124. result := service.SzybJY001(doctor_name, doctor_code, miConfig.Code, order.OrgSetlNumber, order.MzNumber, verifyCode, version_code)
  4125. fmt.Println(result)
  4126. var dat map[string]interface{}
  4127. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4128. fmt.Println(dat)
  4129. } else {
  4130. fmt.Println(err)
  4131. }
  4132. userJSONBytes, _ := json.Marshal(dat)
  4133. var res ResultFour
  4134. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4135. utils.ErrorLog("解析失败:%v", err)
  4136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4137. return
  4138. }
  4139. if res.Transreturncode == "00000000" {
  4140. var dat2 map[string]interface{}
  4141. if err := json.Unmarshal([]byte(his.PatientInfo), &dat2); err == nil {
  4142. fmt.Println(dat2)
  4143. } else {
  4144. fmt.Println(err)
  4145. }
  4146. userJSONBytes2, _ := json.Marshal(dat2)
  4147. var res2 ResultMZ001
  4148. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  4149. utils.ErrorLog("解析失败:%v", err)
  4150. }
  4151. c.ServeSuccessJSON(map[string]interface{}{
  4152. "result": res,
  4153. "org_name": miConfig.OrgName,
  4154. "org_code": miConfig.Code,
  4155. "patient_name": patient.Name,
  4156. "doctor_code": adminRole_two.DoctorCode,
  4157. "doctor_name": doctor_name,
  4158. "health_card_no": order.PsnNo,
  4159. "health_card_no_two": res2.Transbody.Aaz500,
  4160. "order_number": order.Number,
  4161. "department": departments.Name,
  4162. "yiliao_leibie": yiliao_leibie,
  4163. "before_money": res2.Transbody.Aae240,
  4164. "after_money": order.AccountPrice,
  4165. })
  4166. } else {
  4167. c.ServeSuccessJSON(map[string]interface{}{
  4168. "failed_code": -10,
  4169. "msg": res.Transreturnmessage,
  4170. })
  4171. }
  4172. }
  4173. }
  4174. //费用录入取消
  4175. //func (c *SZHisApiController) CancelOrderDetail() {
  4176. // order_id, _ := c.GetInt64("order_id")
  4177. // record_time := c.GetString("record_time")
  4178. // patient_id, _ := c.GetInt64("patient_id")
  4179. // admin_user_id, _ := c.GetInt64("admin_user_id")
  4180. // timeLayout := "2006-01-02"
  4181. // loc, _ := time.LoadLocation("Local")
  4182. // adminUser := c.GetAdminUserInfo()
  4183. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4184. // fmt.Println(err)
  4185. // if err != nil {
  4186. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4187. // return
  4188. // }
  4189. // recordDateTime := theTime.Unix()
  4190. // var order models.HisOrder
  4191. // order, _ = service.GetHisOrderByID(order_id)
  4192. //
  4193. // if order.ID == 0 {
  4194. // order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  4195. //
  4196. // }
  4197. //
  4198. // order_infos, _ := service.GetHisOrderInfoByNumber(order.Number)
  4199. //
  4200. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4201. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4202. // //结算流程
  4203. // var doctor_name string
  4204. // var doctor_code string
  4205. // if roles.ID == 0 {
  4206. // doctor_name = "管理员"
  4207. // doctor_code = "1001"
  4208. // } else {
  4209. // doctor_name = roles.UserName
  4210. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  4211. //
  4212. // }
  4213. // var customs []*models.CustomDetail
  4214. //
  4215. // for _, item := range order_infos {
  4216. // cus := &models.CustomDetail{
  4217. // PrescriptionNumber: item.OrderNumber,
  4218. // ChargeSerialNumber: item.FeedetlSn,
  4219. // }
  4220. // customs = append(customs, cus)
  4221. // }
  4222. // his, _ := service.GetHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  4223. //
  4224. // verifyCode, version_code := ReadCardGetCode("FY002" + "|" + order.OrgSetlNumber + "|" + miConfig.Code)
  4225. //
  4226. // var pagesize int = 50
  4227. // var start int = 1
  4228. // var stop int
  4229. // var pagecount int
  4230. // var curpage int
  4231. // var isSuccess bool = true
  4232. // var ress []*ResultFive
  4233. //
  4234. // //总页数,向上取整,注意除之前要先转换类型为float64
  4235. // pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  4236. //
  4237. // for curpage = 1; curpage <= pagecount; curpage++ {
  4238. // if curpage == 1 {
  4239. // start = 1
  4240. // } else {
  4241. // start = (curpage-1)*pagesize + 1
  4242. // }
  4243. // stop = curpage * pagesize
  4244. // if stop > len(customs) {
  4245. // stop = len(customs)
  4246. // }
  4247. //
  4248. // result := service.SzybFY002(doctor_name, doctor_code, miConfig.Code, customs[start-1:stop], verifyCode, order.OrgSetlNumber, his.Number, version_code)
  4249. // fmt.Println(result)
  4250. //
  4251. // var dat map[string]interface{}
  4252. // if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4253. // fmt.Println(dat)
  4254. // } else {
  4255. // fmt.Println(err)
  4256. // }
  4257. // userJSONBytes, _ := json.Marshal(dat)
  4258. // var res ResultFive
  4259. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4260. // utils.ErrorLog("解析失败:%v", err)
  4261. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4262. // return
  4263. // }
  4264. // if res.Transreturncode == "00000000" {
  4265. // ress = append(ress, &res)
  4266. // } else {
  4267. // isSuccess = false
  4268. // //预结算报错
  4269. // errlog := &models.HisOrderError{
  4270. // UserOrgId: adminUser.CurrentOrgId,
  4271. // Ctime: time.Now().Unix(),
  4272. // Mtime: time.Now().Unix(),
  4273. // ErrMsg: res.Transreturnmessage,
  4274. // Status: 1,
  4275. // PatientId: patient_id,
  4276. // RecordTime: recordDateTime,
  4277. // Stage: 11,
  4278. // }
  4279. // service.CreateErrMsgLog(errlog)
  4280. //
  4281. // c.ServeSuccessJSON(map[string]interface{}{
  4282. // "faild_code": -10,
  4283. // "msg": res.Transreturnmessage,
  4284. // })
  4285. // return
  4286. // }
  4287. // }
  4288. // if isSuccess == true {
  4289. // service.UpdataOrderInfoStatus(order.ID, order.Number, adminUser.CurrentOrgId)
  4290. // c.ServeSuccessJSON(map[string]interface{}{
  4291. // "msg": "撤销成功",
  4292. // })
  4293. // }
  4294. //}
  4295. func (c *SZHisApiController) CancelOrderDetail() {
  4296. order_id, _ := c.GetInt64("order_id")
  4297. record_time := c.GetString("record_time")
  4298. patient_id, _ := c.GetInt64("patient_id")
  4299. admin_user_id, _ := c.GetInt64("admin_user_id")
  4300. timeLayout := "2006-01-02"
  4301. loc, _ := time.LoadLocation("Local")
  4302. adminUser := c.GetAdminUserInfo()
  4303. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4304. fmt.Println(err)
  4305. if err != nil {
  4306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4307. return
  4308. }
  4309. recordDateTime := theTime.Unix()
  4310. var order models.HisOrder
  4311. order, _ = service.GetHisOrderByID(order_id)
  4312. if order.ID == 0 {
  4313. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  4314. }
  4315. order_infos, _ := service.GetHisOrderInfoByNumber(order.Number)
  4316. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4317. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4318. //结算流程
  4319. var doctor_name string
  4320. var doctor_code string
  4321. if roles.ID == 0 {
  4322. doctor_name = "管理员"
  4323. doctor_code = "1001"
  4324. } else {
  4325. doctor_name = roles.UserName
  4326. doctor_code = strconv.FormatInt(admin_user_id, 10)
  4327. }
  4328. var customs []*models.CustomDetail
  4329. for _, item := range order_infos {
  4330. cus := &models.CustomDetail{
  4331. PrescriptionNumber: item.OrderNumber,
  4332. ChargeSerialNumber: item.FeedetlSn,
  4333. }
  4334. customs = append(customs, cus)
  4335. }
  4336. his, _ := service.GetHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  4337. verifyCode, version_code := ReadCardGetCode("FY002" + "|" + order.OrgSetlNumber + "|" + miConfig.Code)
  4338. var pagesize int = 50
  4339. var start int = 1
  4340. var stop int
  4341. var pagecount int
  4342. var curpage int
  4343. var isSuccess bool = true
  4344. var ress []*ResultFive
  4345. //总页数,向上取整,注意除之前要先转换类型为float64
  4346. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  4347. for curpage = 1; curpage <= pagecount; curpage++ {
  4348. if curpage == 1 {
  4349. start = 1
  4350. } else {
  4351. start = (curpage-1)*pagesize + 1
  4352. }
  4353. stop = curpage * pagesize
  4354. if stop > len(customs) {
  4355. stop = len(customs)
  4356. }
  4357. result := service.SzybFY002(doctor_name, doctor_code, miConfig.Code, customs[start-1:stop], verifyCode, order.OrgSetlNumber, his.Number, version_code)
  4358. fmt.Println(result)
  4359. var dat map[string]interface{}
  4360. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4361. fmt.Println(dat)
  4362. } else {
  4363. fmt.Println(err)
  4364. }
  4365. userJSONBytes, _ := json.Marshal(dat)
  4366. var res ResultFive
  4367. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4368. utils.ErrorLog("解析失败:%v", err)
  4369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4370. return
  4371. }
  4372. if res.Transreturncode == "00000000" {
  4373. ress = append(ress, &res)
  4374. } else {
  4375. isSuccess = false
  4376. //预结算报错
  4377. errlog := &models.HisOrderError{
  4378. UserOrgId: adminUser.CurrentOrgId,
  4379. Ctime: time.Now().Unix(),
  4380. Mtime: time.Now().Unix(),
  4381. ErrMsg: res.Transreturnmessage,
  4382. Status: 1,
  4383. PatientId: patient_id,
  4384. RecordTime: recordDateTime,
  4385. Stage: 11,
  4386. }
  4387. service.CreateErrMsgLog(errlog)
  4388. c.ServeSuccessJSON(map[string]interface{}{
  4389. "faild_code": -10,
  4390. "msg": res.Transreturnmessage,
  4391. })
  4392. return
  4393. }
  4394. }
  4395. if isSuccess == true {
  4396. service.UpdataOrderInfoStatus(order.ID, order.Number, adminUser.CurrentOrgId)
  4397. c.ServeSuccessJSON(map[string]interface{}{
  4398. "msg": "撤销成功",
  4399. })
  4400. }
  4401. }
  4402. //获取verifyCode
  4403. func ReadCardGetCode(request string) (string, string) {
  4404. request = request + "|"
  4405. DllDef2 := syscall.MustLoadDLL("SSCardDriver_SZ.dll")
  4406. readCards := DllDef2.MustFindProc("iVerifyCode")
  4407. str := request
  4408. str3 := make([]byte, 256)
  4409. ret4, _, _ := readCards.Call(StrPtr(str), (uintptr)(unsafe.Pointer(&str3[0])))
  4410. fmt.Println(":", string(str3))
  4411. fmt.Println(":", ConvertToString(string(str3), "gbk", "utf-8"))
  4412. if ret4 == 0 {
  4413. result := string(str3)
  4414. fmt.Println(result)
  4415. result_arr := strings.Split(result, "|")
  4416. verifyCode := result_arr[0] + "|" + result_arr[1]
  4417. versionCode := result_arr[2]
  4418. return verifyCode, versionCode
  4419. }
  4420. return "", ""
  4421. }
  4422. ////获取卡信息
  4423. func ReadBasCardGetNumber(request string) (string, string, string, string, string, error, int64) {
  4424. DllDef2 := syscall.MustLoadDLL("SSCardDriver_SZ.dll")
  4425. readCards := DllDef2.MustFindProc("iReadCardBas")
  4426. str := request
  4427. str3 := make([]byte, 1024)
  4428. fmt.Println(":", request)
  4429. fmt.Println(":", StrPtr(str))
  4430. ret4, _, err := readCards.Call(IntPtr(1), StrPtr(str), (uintptr)(unsafe.Pointer(&str3[0])))
  4431. fmt.Println(":", string(str3))
  4432. fmt.Println(":", ConvertToString(string(str3), "gbk", "utf-8"))
  4433. if ret4 == 0 {
  4434. result := string(str3)
  4435. fmt.Println(result)
  4436. result_arr := strings.Split(result, "|")
  4437. //医疗证号
  4438. yiliao_number := result_arr[12]
  4439. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  4440. id_card_number := result_arr[1]
  4441. verifyCode := result_arr[11] + "|" + result_arr[13]
  4442. versionCode := result_arr[14]
  4443. health_card_no := result_arr[2]
  4444. return yiliao_number, id_card_number, verifyCode, versionCode, health_card_no, err, 0
  4445. }
  4446. return "", "", "", "", "", err, -10
  4447. }
  4448. //读卡
  4449. func ReadBasCard(request string) (string, string, error, int64) {
  4450. DllDef2 := syscall.MustLoadDLL("SSCardDriver_SZ.dll")
  4451. readCards := DllDef2.MustFindProc("iReadCardBas")
  4452. str := request
  4453. str3 := make([]byte, 1024)
  4454. ret4, _, err := readCards.Call(IntPtr(1), StrPtr(str), (uintptr)(unsafe.Pointer(&str3[0])))
  4455. fmt.Println(":", string(str3))
  4456. fmt.Println(":", ConvertToString(string(str3), "gbk", "utf-8"))
  4457. if ret4 == 0 {
  4458. result := string(str3)
  4459. result_arr := strings.Split(result, "|")
  4460. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  4461. id_card_number := result_arr[1]
  4462. health_card_no := result_arr[2]
  4463. return id_card_number, health_card_no, err, 0
  4464. }
  4465. return "", "", err, -10
  4466. }
  4467. //
  4468. ////iReadCardBas_HSM_Step1 ---- 1903 iCardInnerAuthentication --- iReadCardBas_HSM_Step2
  4469. //func ReadCardBasHSM(number string) string {
  4470. // DllDef2 := syscall.MustLoadDLL("SSSE32.dll")
  4471. // readCards := DllDef2.MustFindProc("iReadCardBas_HSM_Step1")
  4472. // str := make([]byte, 256)
  4473. // ret, _, _ := readCards.Call(IntPtr(3), (uintptr)(unsafe.Pointer(&str[0])))
  4474. // fmt.Println(":", string(str))
  4475. //
  4476. // result_arr := strings.Split(string(str), "|")
  4477. //
  4478. // if ret == 0 {
  4479. // readCards := DllDef2.MustFindProc("iCardInnerAuthentication")
  4480. // str2 := make([]byte, 256)
  4481. // str3 := "" + "|" + "" + "|" + "440300" + "|" + "" + "|" + "" + "|" + result_arr[1] + "|" + result_arr[2] + "|" + result_arr[3] + "|" + result_arr[4] + "|" + result_arr[5] + "|" + "" + "|" + "" + "|"
  4482. // ret2, _, _ := readCards.Call(StrPtr(str3), (uintptr)(unsafe.Pointer(&str2[0])))
  4483. // fmt.Println(":", string(str2))
  4484. //
  4485. // if ret2 == 0 {
  4486. // result_arr := strings.Split(string(str2), "|")
  4487. //
  4488. // if result_arr[2] == "0" {
  4489. // readCards := DllDef2.MustFindProc("iReadCardBas_HSM_Step2")
  4490. // str4 := result_arr[4] + "|" + result_arr[5]
  4491. // str5 := make([]byte, 256)
  4492. // ret3, _, _ := readCards.Call(StrPtr(str4), StrPtr(number), (uintptr)(unsafe.Pointer(&str5[0])))
  4493. //
  4494. // if ret3 == 0 {
  4495. // return string(str5)
  4496. //
  4497. // } else {
  4498. // return ""
  4499. // }
  4500. // } else {
  4501. // return ""
  4502. // }
  4503. // }
  4504. // return ""
  4505. // }
  4506. // return ""
  4507. //
  4508. //}
  4509. //
  4510. ////1904卡鉴权
  4511. //func CardAuth(request string) string {
  4512. // DllDef2 := syscall.MustLoadDLL("SSSE32.dll")
  4513. // readCards := DllDef2.MustFindProc("iCardAuthentication")
  4514. // str := request
  4515. // str3 := make([]byte, 256)
  4516. // ret4, _, _ := readCards.Call(StrPtr(str), (uintptr)(unsafe.Pointer(&str3[0])))
  4517. // fmt.Println(":", string(str3))
  4518. //
  4519. // if ret4 == 0 {
  4520. // return string(str3)
  4521. // }
  4522. // return ""
  4523. //}
  4524. func (c *SZHisApiController) GetDrugList() {
  4525. adminUserInfo := c.GetAdminUserInfo()
  4526. orgId := adminUserInfo.CurrentOrgId
  4527. admin_user_id, _ := c.GetInt64("admin_user_id")
  4528. roles, _ := service.GetAdminUserInfoByID(orgId, admin_user_id)
  4529. ids := c.GetString("ids")
  4530. stringarr := strings.Split(ids, ",")
  4531. idss := make([]int64, 0)
  4532. for _, item := range stringarr {
  4533. itemsss, _ := strconv.ParseInt(item, 10, 64)
  4534. id := int64(itemsss)
  4535. idss = append(idss, id)
  4536. }
  4537. //批量获取
  4538. list, _ := service.GetBatchDrugList(idss)
  4539. //获取药品剂型
  4540. drugs, _ := service.GetDrugDosageForm(orgId)
  4541. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4542. var doctor_name string
  4543. var doctor_code string
  4544. doctor_name = roles.UserName
  4545. doctor_code = "1001"
  4546. var isSuccess bool = true
  4547. timeLayout := "20060102"
  4548. //这里就可以查看开始和结束了
  4549. for _, item := range list {
  4550. recordDate := time.Unix(item.RecordDate, 0).Format(timeLayout)
  4551. detail := &models.DrugDetail{
  4552. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  4553. Code: item.Code,
  4554. DrugName: item.DrugName,
  4555. DrugSpec: item.DrugSpec,
  4556. DrugDosageName: item.DrugDosageName,
  4557. ManufacturerName: item.ManufacturerName,
  4558. MinUnit: item.MinUnit,
  4559. RetailPrice: item.RetailPrice,
  4560. LastPrice: item.LastPrice,
  4561. LimitRemark: item.LimitRemark,
  4562. PrescriptionMark: strconv.FormatInt(item.PrescriptionMark, 10),
  4563. RecordDate: recordDate,
  4564. }
  4565. for _, it := range drugs {
  4566. if item.DrugDosageForm == it.Value {
  4567. detail.DrugDosageName = it.Code
  4568. }
  4569. }
  4570. result := service.SzybML008(doctor_name, doctor_code, miConfig.Code, detail)
  4571. var dat map[string]interface{}
  4572. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4573. //fmt.Println(dat)
  4574. } else {
  4575. //fmt.Println(err)
  4576. }
  4577. userJSONBytes, _ := json.Marshal(dat)
  4578. var res Result
  4579. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4580. utils.ErrorLog("解析失败:%v", err)
  4581. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4582. c.ServeSuccessJSON(map[string]interface{}{
  4583. "failed_code": -10,
  4584. "msg": res.Transreturnmessage,
  4585. })
  4586. return
  4587. }
  4588. if res.Transreturncode == "00000000" {
  4589. //更新备案状态
  4590. _, err := service.UpdateBaseDrugById(item.ID)
  4591. fmt.Println("err", err)
  4592. c.ServeSuccessJSON(map[string]interface{}{
  4593. "failed_code": -10,
  4594. "msg": res.Transreturnmessage,
  4595. })
  4596. return
  4597. }
  4598. fmt.Println(isSuccess)
  4599. c.ServeSuccessJSON(map[string]interface{}{
  4600. "failed_code": -10,
  4601. "msg": res.Transreturnmessage,
  4602. })
  4603. return
  4604. }
  4605. }
  4606. func (c *SZHisApiController) GetTreatmentProject() {
  4607. adminUserInfo := c.GetAdminUserInfo()
  4608. orgId := adminUserInfo.CurrentOrgId
  4609. ids := c.GetString("ids")
  4610. stringarr := strings.Split(ids, ",")
  4611. idss := make([]int64, 0)
  4612. admin_user_id, _ := c.GetInt64("admin_user_id")
  4613. roles, _ := service.GetAdminUserInfoByID(orgId, admin_user_id)
  4614. for _, item := range stringarr {
  4615. itemsss, _ := strconv.ParseInt(item, 10, 64)
  4616. id := int64(itemsss)
  4617. idss = append(idss, id)
  4618. }
  4619. //获取项目库数据
  4620. list, _ := service.GetBathchMyPorjecgList(idss)
  4621. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4622. var doctor_name string
  4623. var doctor_code string
  4624. doctor_name = roles.UserName
  4625. doctor_code = "1001"
  4626. var isSuccess bool = true
  4627. for _, item := range list {
  4628. detail := &models.MyHisProject{
  4629. MedicalCode: item.MedicalCode, //社保目录
  4630. ProjectName: item.ProjectName,
  4631. Price: item.Price,
  4632. Category: item.Category,
  4633. Remark: item.Remark,
  4634. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  4635. SpecailProject: item.SpecailProject,
  4636. RecordDate: item.RecordDate,
  4637. }
  4638. result := service.SzybML009(doctor_name, doctor_code, miConfig.Code, detail)
  4639. var dat map[string]interface{}
  4640. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4641. fmt.Println(dat)
  4642. } else {
  4643. fmt.Println(err)
  4644. }
  4645. userJSONBytes, _ := json.Marshal(dat)
  4646. var res Result
  4647. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4648. utils.ErrorLog("解析失败:%v", err)
  4649. c.ServeSuccessJSON(map[string]interface{}{
  4650. "failed_code": -10,
  4651. "msg": res.Transreturnmessage,
  4652. })
  4653. return
  4654. }
  4655. if res.Transreturncode == "00000000" {
  4656. //备案成功返回状态值
  4657. _, err := service.UpdateProjectById(item.ID)
  4658. fmt.Println("err", err)
  4659. } else {
  4660. isSuccess = false
  4661. //失败
  4662. c.ServeSuccessJSON(map[string]interface{}{
  4663. "failed_code": -10,
  4664. "msg": res.Transreturnmessage,
  4665. })
  4666. return
  4667. }
  4668. fmt.Println(isSuccess)
  4669. c.ServeSuccessJSON(map[string]interface{}{
  4670. "failed_code": -10,
  4671. "msg": res.Transreturnmessage,
  4672. })
  4673. return
  4674. }
  4675. }
  4676. func (c *SZHisApiController) GetRevocation() {
  4677. adminUserInfo := c.GetAdminUserInfo()
  4678. orgId := adminUserInfo.CurrentOrgId
  4679. id, _ := c.GetInt64("id")
  4680. admin_user_id, _ := c.GetInt64("admin_user_id")
  4681. roles, _ := service.GetAdminUserInfoByID(orgId, admin_user_id)
  4682. //用来区分是药品的撤销还是耗材的撤销 1.药品 2.诊疗项目 3.材料 5.辅助器具项目
  4683. is_mark, _ := c.GetInt64("is_mark")
  4684. type_id, _ := c.GetInt64("type_id")
  4685. if type_id == 1 {
  4686. //撤销
  4687. if is_mark == 1 {
  4688. //获取药品库数据
  4689. list, _ := service.GetDrugListByDetail(orgId, id)
  4690. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4691. var doctor_name string
  4692. var doctor_code string
  4693. doctor_name = roles.UserName
  4694. doctor_code = "1001"
  4695. var pagesize int = 50
  4696. var start int = 1
  4697. var stop int
  4698. var pagecount int
  4699. var curpage int
  4700. var isSuccess bool = true
  4701. //总页数,向上取整,注意除之前要先转换类型为float64
  4702. pagecount = int(math.Ceil(float64(len(list)) / float64(pagesize)))
  4703. for curpage = 1; curpage <= pagecount; curpage++ {
  4704. if curpage == 1 {
  4705. start = 1
  4706. } else {
  4707. start = (curpage-1)*pagesize + 1
  4708. }
  4709. stop = curpage * pagesize
  4710. if stop > len(list) {
  4711. stop = len(list)
  4712. }
  4713. //这里就可以查看开始和结束了
  4714. fmt.Println(list[start-1 : stop])
  4715. var customs []*models.DrugDetail
  4716. for _, item := range list {
  4717. detail := &models.DrugDetail{
  4718. SocialSecurityDirectoryCode: item.MedicalInsuranceNumber, //社保目录
  4719. Code: item.Code, //协议机构内部目录编码
  4720. DrugName: item.DrugName, //协议机构内部目录名称
  4721. DrugSpec: item.DrugSpec,
  4722. ManufacturerName: item.ManufacturerName,
  4723. MinUnit: item.MinUnit,
  4724. RetailPrice: item.RetailPrice, //协议机构内部项目收费价格
  4725. LimitRemark: item.LimitRemark,
  4726. MedicalInsuranceNumber: item.MedicalInsuranceNumber, //社保目录
  4727. }
  4728. customs = append(customs, detail)
  4729. }
  4730. result := service.SzybML010(doctor_name, doctor_code, miConfig.Code, customs, type_id)
  4731. fmt.Println("reuslt", result)
  4732. var dat map[string]interface{}
  4733. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4734. fmt.Println(dat)
  4735. } else {
  4736. fmt.Println(err)
  4737. }
  4738. userJSONBytes, _ := json.Marshal(dat)
  4739. var res Result
  4740. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4741. utils.ErrorLog("解析失败:%v", err)
  4742. c.ServeSuccessJSON(map[string]interface{}{
  4743. "failed_code": -10,
  4744. "msg": res.Transreturnmessage,
  4745. })
  4746. return
  4747. }
  4748. if res.Transreturncode == "00000000" {
  4749. //撤销成功
  4750. _, err := service.UpdateDrugByIdDetail(id)
  4751. fmt.Println("err", err)
  4752. } else {
  4753. isSuccess = false
  4754. //失败
  4755. c.ServeSuccessJSON(map[string]interface{}{
  4756. "failed_code": -10,
  4757. "msg": res.Transreturnmessage,
  4758. })
  4759. return
  4760. }
  4761. fmt.Println(isSuccess)
  4762. c.ServeSuccessJSON(map[string]interface{}{
  4763. "failed_code": -10,
  4764. "msg": res.Transreturnmessage,
  4765. })
  4766. return
  4767. }
  4768. }
  4769. // 备案
  4770. if is_mark == 0 {
  4771. adminUserInfo := c.GetAdminUserInfo()
  4772. orgId := adminUserInfo.CurrentOrgId
  4773. //获取药品库数据
  4774. list, _ := service.GetDrugListByDetail(orgId, id)
  4775. //获取药品剂型
  4776. drugs, _ := service.GetDrugDosageForm(orgId)
  4777. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4778. var doctor_name string
  4779. var doctor_code string
  4780. doctor_name = roles.UserName
  4781. doctor_code = "1001"
  4782. var isSuccess bool = true
  4783. //这里就可以查看开始和结束了
  4784. for _, item := range list {
  4785. detail := &models.DrugDetail{
  4786. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  4787. SocialSecurityDirectoryCode: item.MedicalInsuranceNumber,
  4788. Code: item.Code,
  4789. DrugName: item.DrugName,
  4790. DrugSpec: item.DrugSpec,
  4791. DrugDosageName: item.DrugDosageName,
  4792. ManufacturerName: item.ManufacturerName,
  4793. MinUnit: item.MinUnit,
  4794. RetailPrice: item.RetailPrice,
  4795. LastPrice: item.LastPrice,
  4796. LimitRemark: item.LimitRemark,
  4797. }
  4798. for _, it := range drugs {
  4799. if item.DrugDosageForm == it.Value {
  4800. detail.DrugDosageName = it.Code
  4801. }
  4802. }
  4803. result := service.SzybML008(doctor_name, doctor_code, miConfig.Code, detail)
  4804. var dat map[string]interface{}
  4805. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4806. //fmt.Println(dat)
  4807. } else {
  4808. //fmt.Println(err)
  4809. }
  4810. userJSONBytes, _ := json.Marshal(dat)
  4811. var res Result
  4812. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4813. utils.ErrorLog("解析失败:%v", err)
  4814. c.ServeSuccessJSON(map[string]interface{}{
  4815. "failed_code": -10,
  4816. "msg": res.Transreturnmessage,
  4817. })
  4818. return
  4819. }
  4820. if res.Transreturncode == "00000000" {
  4821. //更新备案状态
  4822. _, err := service.UpdateBaseDrugById(item.ID)
  4823. fmt.Println("err", err)
  4824. }
  4825. fmt.Println(isSuccess)
  4826. c.ServeSuccessJSON(map[string]interface{}{
  4827. "failed_code": -10,
  4828. "msg": res.Transreturnmessage,
  4829. })
  4830. return
  4831. }
  4832. }
  4833. }
  4834. if type_id == 2 {
  4835. //撤销
  4836. if is_mark == 1 {
  4837. //获取药品库数据
  4838. list, _ := service.GetMyPorjecgListDetail(orgId, id)
  4839. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4840. var doctor_name string
  4841. var doctor_code string
  4842. doctor_name = roles.UserName
  4843. doctor_code = "1001"
  4844. var pagesize int = 50
  4845. var start int = 1
  4846. var stop int
  4847. var pagecount int
  4848. var curpage int
  4849. var isSuccess bool = true
  4850. //总页数,向上取整,注意除之前要先转换类型为float64
  4851. pagecount = int(math.Ceil(float64(len(list)) / float64(pagesize)))
  4852. for curpage = 1; curpage <= pagecount; curpage++ {
  4853. if curpage == 1 {
  4854. start = 1
  4855. } else {
  4856. start = (curpage-1)*pagesize + 1
  4857. }
  4858. stop = curpage * pagesize
  4859. if stop > len(list) {
  4860. stop = len(list)
  4861. }
  4862. //这里就可以查看开始和结束了
  4863. fmt.Println(list[start-1 : stop])
  4864. var customs []*models.DrugDetail
  4865. for _, item := range list {
  4866. detail := &models.DrugDetail{
  4867. SocialSecurityDirectoryCode: item.MedicalCode,
  4868. }
  4869. customs = append(customs, detail)
  4870. }
  4871. result := service.SzybML010(doctor_name, doctor_code, miConfig.Code, customs, type_id)
  4872. fmt.Println("reuslt", result)
  4873. var dat map[string]interface{}
  4874. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4875. fmt.Println(dat)
  4876. } else {
  4877. fmt.Println(err)
  4878. }
  4879. userJSONBytes, _ := json.Marshal(dat)
  4880. var res Result
  4881. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4882. utils.ErrorLog("解析失败:%v", err)
  4883. c.ServeSuccessJSON(map[string]interface{}{
  4884. "failed_code": -10,
  4885. "msg": res.Transreturnmessage,
  4886. })
  4887. return
  4888. }
  4889. if res.Transreturncode == "00000000" {
  4890. //核销成功返回状态码
  4891. _, err := service.UpdateMyProjectById(id)
  4892. fmt.Println("err", err)
  4893. } else {
  4894. isSuccess = false
  4895. //失败
  4896. c.ServeSuccessJSON(map[string]interface{}{
  4897. "failed_code": -10,
  4898. "msg": res.Transreturnmessage,
  4899. })
  4900. return
  4901. }
  4902. fmt.Println(isSuccess)
  4903. c.ServeSuccessJSON(map[string]interface{}{
  4904. "failed_code": -10,
  4905. "msg": res.Transreturnmessage,
  4906. })
  4907. return
  4908. }
  4909. }
  4910. //备案
  4911. if is_mark == 0 {
  4912. adminUserInfo := c.GetAdminUserInfo()
  4913. orgId := adminUserInfo.CurrentOrgId
  4914. //获取药品库数据
  4915. list, _ := service.GetMyPorjecgListDetail(orgId, id)
  4916. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4917. var doctor_name string
  4918. var doctor_code string
  4919. doctor_name = roles.UserName
  4920. doctor_code = "1001"
  4921. var isSuccess bool = true
  4922. for _, item := range list {
  4923. detail := &models.MyHisProject{
  4924. MedicalCode: item.MedicalCode, //社保目录
  4925. ProjectName: item.ProjectName,
  4926. Price: item.Price,
  4927. Category: item.Category,
  4928. Remark: item.Remark,
  4929. }
  4930. result := service.SzybML009(doctor_name, doctor_code, miConfig.Code, detail)
  4931. fmt.Println("reuslt", result)
  4932. var dat map[string]interface{}
  4933. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4934. fmt.Println(dat)
  4935. } else {
  4936. fmt.Println(err)
  4937. }
  4938. userJSONBytes, _ := json.Marshal(dat)
  4939. var res Result
  4940. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4941. utils.ErrorLog("解析失败:%v", err)
  4942. c.ServeSuccessJSON(map[string]interface{}{
  4943. "failed_code": -10,
  4944. "msg": res.Transreturnmessage,
  4945. })
  4946. return
  4947. }
  4948. if res.Transreturncode == "00000000" {
  4949. //备案成功返回状态值
  4950. _, err := service.UpdateProjectById(item.ID)
  4951. fmt.Println("err", err)
  4952. } else {
  4953. isSuccess = false
  4954. //失败
  4955. c.ServeSuccessJSON(map[string]interface{}{
  4956. "failed_code": -10,
  4957. "msg": res.Transreturnmessage,
  4958. })
  4959. return
  4960. }
  4961. fmt.Println(isSuccess)
  4962. c.ServeSuccessJSON(map[string]interface{}{
  4963. "failed_code": -10,
  4964. "msg": res.Transreturnmessage,
  4965. })
  4966. return
  4967. }
  4968. }
  4969. }
  4970. if type_id == 3 {
  4971. //撤销
  4972. if is_mark == 1 {
  4973. //获取药品库数据
  4974. list, _ := service.GetGoodListByDetail(orgId, id)
  4975. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4976. var doctor_name string
  4977. var doctor_code string
  4978. doctor_name = roles.UserName
  4979. doctor_code = "1001"
  4980. var pagesize int = 50
  4981. var start int = 1
  4982. var stop int
  4983. var pagecount int
  4984. var curpage int
  4985. var isSuccess bool = true
  4986. //总页数,向上取整,注意除之前要先转换类型为float64
  4987. pagecount = int(math.Ceil(float64(len(list)) / float64(pagesize)))
  4988. for curpage = 1; curpage <= pagecount; curpage++ {
  4989. if curpage == 1 {
  4990. start = 1
  4991. } else {
  4992. start = (curpage-1)*pagesize + 1
  4993. }
  4994. stop = curpage * pagesize
  4995. if stop > len(list) {
  4996. stop = len(list)
  4997. }
  4998. //这里就可以查看开始和结束了
  4999. fmt.Println(list[start-1 : stop])
  5000. var customs []*models.DrugDetail
  5001. for _, item := range list {
  5002. fmt.Println("医疗机构编码", item.SocialSecurityDirectoryCode)
  5003. detail := &models.DrugDetail{
  5004. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  5005. ManufacturerName: item.ManufacturerName,
  5006. }
  5007. customs = append(customs, detail)
  5008. }
  5009. result := service.SzybML010(doctor_name, doctor_code, miConfig.Code, customs, type_id)
  5010. fmt.Println("reuslt", result)
  5011. var dat map[string]interface{}
  5012. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5013. fmt.Println(dat)
  5014. } else {
  5015. fmt.Println(err)
  5016. }
  5017. userJSONBytes, _ := json.Marshal(dat)
  5018. var res Result
  5019. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5020. utils.ErrorLog("解析失败:%v", err)
  5021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5022. return
  5023. }
  5024. if res.Transreturncode == "00000000" {
  5025. //撤销成功后改变状态
  5026. _, err := service.UpdateGoodInfoById(id)
  5027. fmt.Println("err", err)
  5028. } else {
  5029. isSuccess = false
  5030. //失败
  5031. c.ServeSuccessJSON(map[string]interface{}{
  5032. "failed_code": -10,
  5033. "msg": res.Transreturnmessage,
  5034. })
  5035. return
  5036. }
  5037. fmt.Println(isSuccess)
  5038. c.ServeSuccessJSON(map[string]interface{}{
  5039. "failed_code": -10,
  5040. "msg": res.Transreturnmessage,
  5041. })
  5042. return
  5043. }
  5044. }
  5045. //备案
  5046. if is_mark == 0 {
  5047. adminUserInfo := c.GetAdminUserInfo()
  5048. orgId := adminUserInfo.CurrentOrgId
  5049. //获取所有耗材信息
  5050. list, _ := service.GetGoodListByDetail(orgId, id)
  5051. //获取单位
  5052. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  5053. var doctor_name string
  5054. var doctor_code string
  5055. doctor_name = roles.UserName
  5056. doctor_code = "1001"
  5057. var isSuccess bool = true
  5058. for _, item := range list {
  5059. detail := &models.XtGoodInformation{
  5060. GoodName: item.GoodName,
  5061. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  5062. ManufacturerName: item.ManufacturerName,
  5063. ProductionType: item.ProductionType,
  5064. SpecialMedical: item.SpecialMedical,
  5065. BuyPrice: item.BuyPrice,
  5066. SellPrice: item.SellPrice,
  5067. Remark: item.Remark,
  5068. SpecificationName: item.SpecificationName,
  5069. }
  5070. result := service.SzybYML007(doctor_name, doctor_code, miConfig.Code, detail)
  5071. fmt.Println("reuslt", result)
  5072. var dat map[string]interface{}
  5073. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5074. fmt.Println(dat)
  5075. } else {
  5076. fmt.Println(err)
  5077. }
  5078. userJSONBytes, _ := json.Marshal(dat)
  5079. var res Result
  5080. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5081. utils.ErrorLog("解析失败:%v", err)
  5082. c.ServeSuccessJSON(map[string]interface{}{
  5083. "failed_code": -10,
  5084. "msg": res.Transreturnmessage,
  5085. })
  5086. return
  5087. }
  5088. if res.Transreturncode == "00000000" {
  5089. //备案成功返回状态
  5090. _, err := service.UpdateGoodInformaitonByDetail(item.ID)
  5091. fmt.Println("err", err)
  5092. } else {
  5093. isSuccess = false
  5094. //失败
  5095. c.ServeSuccessJSON(map[string]interface{}{
  5096. "failed_code": -10,
  5097. "msg": res.Transreturnmessage,
  5098. })
  5099. return
  5100. }
  5101. fmt.Println(isSuccess)
  5102. c.ServeSuccessJSON(map[string]interface{}{
  5103. "failed_code": -10,
  5104. "msg": res.Transreturnmessage,
  5105. })
  5106. return
  5107. }
  5108. }
  5109. }
  5110. }
  5111. func (c *SZHisApiController) GetDoctorList() {
  5112. adminUserInfo := c.GetAdminUserInfo()
  5113. orgid := adminUserInfo.CurrentOrgId
  5114. ids := c.GetString("ids")
  5115. admin_user_id, _ := c.GetInt64("admin_user_id")
  5116. roles, _ := service.GetAdminUserInfoByID(orgid, admin_user_id)
  5117. stringarr := strings.Split(ids, ",")
  5118. idss := make([]int64, 0)
  5119. for _, item := range stringarr {
  5120. itemsss, _ := strconv.ParseInt(item, 10, 64)
  5121. id := int64(itemsss)
  5122. idss = append(idss, id)
  5123. }
  5124. //获取所有医生护士信息
  5125. //list, _ := service.GetDoctorList(orgid)
  5126. //批量查询
  5127. list, _ := service.GetBatchDoctorList(idss)
  5128. //获取所有角色名称
  5129. roleList, _ := service.GetRoleList(orgid)
  5130. miConfig, _ := service.FindMedicalInsuranceInfo(orgid)
  5131. for _, item := range list {
  5132. for _, it := range roleList {
  5133. if item.RoleId == it.ID {
  5134. item.Name = it.RoleName
  5135. }
  5136. }
  5137. }
  5138. var doctor_name string
  5139. var doctor_code string
  5140. doctor_name = roles.UserName
  5141. doctor_code = "1001"
  5142. var isSuccess bool = true
  5143. for _, item := range list {
  5144. depart, _ := service.GetDepartMentDetail(item.DepartmentId)
  5145. detail := &models.DocDetail{
  5146. UserName: item.UserName, //医护姓名
  5147. RoleId: item.Name, //医护人员类别
  5148. Sex: strconv.FormatInt(item.Sex, 10), //性别
  5149. CardType: strconv.FormatInt(item.CardType, 10), //证件类型
  5150. IdCard: item.IdCard, //证件号码
  5151. Phone: item.Mobile, //联系电话
  5152. WorkMajorName: item.WorkMajorName, // 现从事专业名称
  5153. Nation: "1", //民族
  5154. BirthDay: 20201022, // 出生日期
  5155. WorkTime: 20201022, //参加工作日期
  5156. Education: strconv.FormatInt(item.Education, 10), //学历
  5157. StudyMajorName: item.StudyMajorName, //所学的专业名称
  5158. CertificateCode: item.MedicalCode, //医(药)师执业证书编码
  5159. MedicalCode: item.DoctorCode, //医(药)师资格证编码
  5160. MedicalRangeCode: strconv.FormatInt(item.DoctorRangeCode, 10), //医师执业范围代码
  5161. MedicalLevel: strconv.FormatInt(item.DoctorLevel, 10), //医生执业资格证中的医师级别
  5162. TypeJob: strconv.FormatInt(item.DoctorTypeJob, 10), //医生执业资格证中的执业类别
  5163. DoctorNumber: item.DoctorNumber, //医保医师编号
  5164. Licensing: strconv.FormatInt(item.Licensing, 10), //多点执业标志
  5165. DoctorServiceStatus: "", //医师医保服务资格状态
  5166. MonitoringLevel: "", //监控等级
  5167. DrugPsychotropicSubstances: "", //毒麻精神药品资格
  5168. HealthCareCode: "", // 母婴保健技术考核合格证书编号
  5169. PlanningTechnicalServiceCode: "", //计划生育技术服务人员合格证编号
  5170. PharmacistType: "", //药师类别
  5171. PharmacistPracticeCategory: "", //药师执业类别
  5172. PharmacistsLicensing: "", //药师执业范围
  5173. PharmacistRegistrationNumber: "", //执业药师注册证编号
  5174. OfficeCode: depart.Number, //科室编码
  5175. JobNumber: item.JobNumber, //工号
  5176. PostName: "", //职位名称
  5177. TechnicalJobLevelCode: "", //专业技术职务级别编码
  5178. IsActive: strconv.FormatInt(item.IsActive, 10), //在职与否
  5179. PrescriptionQualificationIdentification: strconv.FormatInt(item.PrescriptionQualificationIdentification, 10), //处方资格标识
  5180. IdentificationOutpatients: strconv.FormatInt(item.IdentificationOutpatients, 10), //门诊大病医师标识
  5181. OutpatientIllnessCategory: item.OutpatientIllnessCategory, //门诊大病类别
  5182. StartTime: 20201010, //开始日期
  5183. StaffCode: "", //医护人员编码
  5184. EndTime: 0, // 结束日期
  5185. }
  5186. result := service.SzybYS001(doctor_name, doctor_code, miConfig.Code, detail)
  5187. fmt.Println("reuslt", result)
  5188. var dat map[string]interface{}
  5189. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5190. fmt.Println(dat)
  5191. } else {
  5192. fmt.Println(err)
  5193. }
  5194. userJSONBytes, _ := json.Marshal(dat)
  5195. var res Result
  5196. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5197. utils.ErrorLog("解析失败:%v", err)
  5198. c.ServeSuccessJSON(map[string]interface{}{
  5199. "failed_code": -10,
  5200. "msg": res.Transreturnmessage,
  5201. })
  5202. return
  5203. }
  5204. if res.Transreturncode == "00000000" {
  5205. //批量插入数据
  5206. _, err := service.UpdateAdminUserRoleById(item.AdminUserId, orgid)
  5207. fmt.Println("err", err)
  5208. } else {
  5209. isSuccess = false
  5210. //失败
  5211. c.ServeSuccessJSON(map[string]interface{}{
  5212. "failed_code": -10,
  5213. "msg": res.Transreturnmessage,
  5214. })
  5215. return
  5216. }
  5217. fmt.Println(isSuccess)
  5218. c.ServeSuccessJSON(map[string]interface{}{
  5219. "failed_code": -10,
  5220. "msg": res.Transreturnmessage,
  5221. })
  5222. return
  5223. }
  5224. }
  5225. func (c *SZHisApiController) GetMedicalList() {
  5226. adminUserInfo := c.GetAdminUserInfo()
  5227. orgId := adminUserInfo.CurrentOrgId
  5228. id, _ := c.GetInt64("id")
  5229. is_mark, _ := c.GetInt64("is_mark")
  5230. admin_user_id, _ := c.GetInt64("admin_user_id")
  5231. roles, _ := service.GetAdminUserInfoByID(orgId, admin_user_id)
  5232. //去登记
  5233. if is_mark == 0 {
  5234. list, _ := service.GetDoctorListByDetail(orgId, id)
  5235. //获取所有角色名称
  5236. roleList, _ := service.GetRoleList(orgId)
  5237. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  5238. for _, item := range list {
  5239. for _, it := range roleList {
  5240. if item.RoleId == it.ID {
  5241. item.Name = it.RoleName
  5242. }
  5243. }
  5244. }
  5245. var doctor_name string
  5246. var doctor_code string
  5247. doctor_name = roles.UserName
  5248. doctor_code = "1001"
  5249. var isSuccess bool = true
  5250. for _, item := range list {
  5251. detail := &models.DocDetail{
  5252. UserName: item.UserName, //医护姓名
  5253. RoleId: item.Name, //医护人员类别
  5254. Sex: strconv.FormatInt(item.Sex, 10), //性别
  5255. CardType: strconv.FormatInt(item.CardType, 10), //证件类型
  5256. IdCard: item.IdCard, //证件号码
  5257. Phone: item.Mobile, //联系电话
  5258. WorkMajorName: item.WorkMajorName, // 现从事专业名称
  5259. Nation: item.Nation, //民族
  5260. BirthDay: 20201022, // 出生日期
  5261. WorkTime: 20201022, //参加工作日期
  5262. Education: strconv.FormatInt(item.Education, 10), //学历
  5263. StudyMajorName: item.StudyMajorName, //所学的专业名称
  5264. CertificateCode: item.MedicalCode, //医(药)师执业证书编码
  5265. MedicalCode: item.DoctorCode, //医(药)师资格证编码
  5266. MedicalRangeCode: strconv.FormatInt(item.DoctorRangeCode, 10), //医师执业范围代码
  5267. MedicalLevel: strconv.FormatInt(item.DoctorLevel, 10), //医生执业资格证中的医师级别
  5268. TypeJob: strconv.FormatInt(item.DoctorTypeJob, 10), //医生执业资格证中的执业类别
  5269. DoctorNumber: item.DoctorNumber, //医保医师编号
  5270. Licensing: strconv.FormatInt(item.Licensing, 10), //多点执业标志
  5271. DoctorServiceStatus: "", //医师医保服务资格状态
  5272. MonitoringLevel: "", //监控等级
  5273. DrugPsychotropicSubstances: "", //毒麻精神药品资格
  5274. HealthCareCode: "", // 母婴保健技术考核合格证书编号
  5275. PlanningTechnicalServiceCode: "", //计划生育技术服务人员合格证编号
  5276. PharmacistType: "", //药师类别
  5277. PharmacistPracticeCategory: "", //药师执业类别
  5278. PharmacistsLicensing: "", //药师执业范围
  5279. PharmacistRegistrationNumber: "", //执业药师注册证编号
  5280. OfficeCode: "", //科室编码
  5281. JobNumber: item.JobNumber, //工号
  5282. PostName: "", //职位名称
  5283. TechnicalJobLevelCode: "", //专业技术职务级别编码
  5284. IsActive: strconv.FormatInt(item.IsActive, 10), //在职与否
  5285. PrescriptionQualificationIdentification: strconv.FormatInt(item.PrescriptionQualificationIdentification, 10), //处方资格标识
  5286. IdentificationOutpatients: strconv.FormatInt(item.IdentificationOutpatients, 10), //门诊大病医师标识
  5287. OutpatientIllnessCategory: item.OutpatientIllnessCategory, //门诊大病类别
  5288. StartTime: 20201010, //开始日期
  5289. StaffCode: "", //医护人员编码
  5290. EndTime: 0, // 结束日期
  5291. }
  5292. result := service.SzybYS001(doctor_name, doctor_code, miConfig.Code, detail)
  5293. var dat map[string]interface{}
  5294. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5295. fmt.Println(dat)
  5296. } else {
  5297. fmt.Println(err)
  5298. }
  5299. userJSONBytes, _ := json.Marshal(dat)
  5300. var res Result
  5301. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5302. utils.ErrorLog("解析失败:%v", err)
  5303. c.ServeSuccessJSON(map[string]interface{}{
  5304. "failed_code": -10,
  5305. "msg": res.Transreturnmessage,
  5306. })
  5307. return
  5308. }
  5309. if res.Transreturncode == "00000000" {
  5310. //登记成功
  5311. service.UpdateAdminUserRoleById(item.ID, orgId)
  5312. } else {
  5313. isSuccess = false
  5314. //失败
  5315. c.ServeSuccessJSON(map[string]interface{}{
  5316. "failed_code": -10,
  5317. "msg": res.Transreturnmessage,
  5318. })
  5319. return
  5320. }
  5321. fmt.Println(isSuccess)
  5322. c.ServeSuccessJSON(map[string]interface{}{
  5323. "failed_code": -10,
  5324. "msg": res.Transreturnmessage,
  5325. })
  5326. return
  5327. }
  5328. }
  5329. //去撤销
  5330. if is_mark == 1 {
  5331. //获取所有医生护士信息
  5332. list, _ := service.GetDoctorListByDetail(orgId, id)
  5333. //获取所有角色名称
  5334. roleList, _ := service.GetRoleList(orgId)
  5335. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  5336. for _, item := range list {
  5337. for _, it := range roleList {
  5338. if item.RoleId == it.ID {
  5339. item.Name = it.RoleName
  5340. }
  5341. }
  5342. }
  5343. var doctor_name string
  5344. var doctor_code string
  5345. doctor_name = "黄亦轩"
  5346. doctor_code = "1001"
  5347. var isSuccess bool = true
  5348. for _, item := range list {
  5349. detail := &models.DocDetail{
  5350. UserName: item.UserName, //医护姓名
  5351. RoleId: item.Name, //医护人员类别
  5352. Sex: strconv.FormatInt(item.Sex, 10), //性别
  5353. CardType: strconv.FormatInt(item.CardType, 10), //证件类型
  5354. IdCard: item.IdCard, //证件号码
  5355. Phone: item.Mobile, //联系电话
  5356. WorkMajorName: item.WorkMajorName, // 现从事专业名称
  5357. Nation: item.Nation, //民族
  5358. BirthDay: 20201022, // 出生日期
  5359. WorkTime: 20201022, //参加工作日期
  5360. Education: strconv.FormatInt(item.Education, 10), //学历
  5361. StudyMajorName: item.StudyMajorName, //所学的专业名称
  5362. CertificateCode: item.MedicalCode, //医(药)师执业证书编码
  5363. MedicalCode: item.DoctorCode, //医(药)师资格证编码
  5364. MedicalRangeCode: strconv.FormatInt(item.DoctorRangeCode, 10), //医师执业范围代码
  5365. MedicalLevel: strconv.FormatInt(item.DoctorLevel, 10), //医生执业资格证中的医师级别
  5366. TypeJob: strconv.FormatInt(item.DoctorTypeJob, 10), //医生执业资格证中的执业类别
  5367. DoctorNumber: item.DoctorNumber, //医保医师编号
  5368. Licensing: strconv.FormatInt(item.Licensing, 10), //多点执业标志
  5369. DoctorServiceStatus: "", //医师医保服务资格状态
  5370. MonitoringLevel: "", //监控等级
  5371. DrugPsychotropicSubstances: "", //毒麻精神药品资格
  5372. HealthCareCode: "", // 母婴保健技术考核合格证书编号
  5373. PlanningTechnicalServiceCode: "", //计划生育技术服务人员合格证编号
  5374. PharmacistType: "", //药师类别
  5375. PharmacistPracticeCategory: "", //药师执业类别
  5376. PharmacistsLicensing: "", //药师执业范围
  5377. PharmacistRegistrationNumber: "", //执业药师注册证编号
  5378. OfficeCode: "", //科室编码
  5379. JobNumber: item.JobNumber, //工号
  5380. PostName: "", //职位名称
  5381. TechnicalJobLevelCode: "", //专业技术职务级别编码
  5382. IsActive: strconv.FormatInt(item.IsActive, 10), //在职与否
  5383. PrescriptionQualificationIdentification: strconv.FormatInt(item.PrescriptionQualificationIdentification, 10), //处方资格标识
  5384. IdentificationOutpatients: strconv.FormatInt(item.IdentificationOutpatients, 10), //门诊大病医师标识
  5385. OutpatientIllnessCategory: item.OutpatientIllnessCategory, //门诊大病类别
  5386. StartTime: 20201010, //开始日期
  5387. StaffCode: "", //医护人员编码
  5388. EndTime: 0, // 结束日期
  5389. }
  5390. result := service.SzybYS002(doctor_name, doctor_code, miConfig.Code, detail)
  5391. var dat map[string]interface{}
  5392. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5393. fmt.Println(dat)
  5394. } else {
  5395. fmt.Println(err)
  5396. }
  5397. userJSONBytes, _ := json.Marshal(dat)
  5398. var res Result
  5399. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5400. utils.ErrorLog("解析失败:%v", err)
  5401. c.ServeSuccessJSON(map[string]interface{}{
  5402. "failed_code": -10,
  5403. "msg": res.Transreturnmessage,
  5404. })
  5405. return
  5406. }
  5407. if res.Transreturncode == "00000000" {
  5408. //去撤销
  5409. service.UpdateAdminUserRoleById(item.ID, orgId)
  5410. } else {
  5411. isSuccess = false
  5412. //失败
  5413. c.ServeSuccessJSON(map[string]interface{}{
  5414. "failed_code": -10,
  5415. "msg": res.Transreturnmessage,
  5416. })
  5417. return
  5418. }
  5419. fmt.Println(isSuccess)
  5420. c.ServeSuccessJSON(map[string]interface{}{
  5421. "failed_code": -10,
  5422. "msg": res.Transreturnmessage,
  5423. })
  5424. return
  5425. }
  5426. }
  5427. }
  5428. func (c *SZHisApiController) GetUpdateMedicalList() {
  5429. adminUserInfo := c.GetAdminUserInfo()
  5430. orgId := adminUserInfo.CurrentOrgId
  5431. //获取所有医生护士信息
  5432. list, _ := service.GetDoctorList(orgId)
  5433. //获取所有角色名称
  5434. roleList, _ := service.GetRoleList(orgId)
  5435. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  5436. for _, item := range list {
  5437. for _, it := range roleList {
  5438. if item.RoleId == it.ID {
  5439. item.Name = it.RoleName
  5440. }
  5441. }
  5442. }
  5443. var doctor_name string
  5444. var doctor_code string
  5445. doctor_name = "黄亦轩"
  5446. doctor_code = "1001"
  5447. var pagesize int = 50
  5448. var start int = 1
  5449. var stop int
  5450. var pagecount int
  5451. var curpage int
  5452. var isSuccess bool = true
  5453. //总页数,向上取整,注意除之前要先转换类型为float64
  5454. pagecount = int(math.Ceil(float64(len(list)) / float64(pagesize)))
  5455. var ress []*Result
  5456. for curpage = 1; curpage <= pagecount; curpage++ {
  5457. if curpage == 1 {
  5458. start = 1
  5459. } else {
  5460. start = (curpage-1)*pagesize + 1
  5461. }
  5462. stop = curpage * pagesize
  5463. if stop > len(list) {
  5464. stop = len(list)
  5465. }
  5466. //这里就可以查看开始和结束了
  5467. fmt.Println(list[start-1 : stop])
  5468. var customs []*models.DocDetail
  5469. for _, item := range list {
  5470. detail := &models.DocDetail{
  5471. StaffCode: "", //医护人员编码
  5472. UserName: item.UserName, //医护人员姓名
  5473. RoleId: item.Name, //医护人员类别
  5474. Sex: "", //性别
  5475. CardType: "", //证件类型
  5476. IdCard: "", //证件号码
  5477. Phone: "", //联系电话
  5478. WorkMajorName: "", //现从事专业名称
  5479. Nation: "", //民族
  5480. BirthDay: 20201022, //出生日期
  5481. WorkTime: 20201022, //参加工作日期
  5482. Education: "", //学历
  5483. StudyMajorName: "", //所学的专业名称
  5484. CertificateCode: "", //证书编码
  5485. MedicalCode: "", //医师资格编码
  5486. MedicalRangeCode: "", //医师执业范围代码
  5487. MedicalLevel: "", //医生级别
  5488. TypeJob: "", //职业类别
  5489. DoctorNumber: "", //医师编号
  5490. Licensing: "", //职业标志
  5491. DoctorServiceStatus: "", //医师医保服务资格状态
  5492. MonitoringLevel: "", //监控等级
  5493. DrugPsychotropicSubstances: "", //毒麻精神药品资格
  5494. HealthCareCode: "", // 母婴保健技术考核合格证书编号
  5495. PlanningTechnicalServiceCode: "", //计划生育技术服务人员合格证编号
  5496. PharmacistType: "", //药师类别
  5497. PharmacistPracticeCategory: "", //药师执业类别
  5498. PharmacistsLicensing: "", //药师执业范围
  5499. PharmacistRegistrationNumber: "", //执业药师注册证编号
  5500. OfficeCode: "", //科室编码
  5501. JobNumber: "", //工号
  5502. PostName: "", //职位名称
  5503. TechnicalJobLevelCode: "", //专业技术职务级别编码
  5504. IsActive: "", //在职与否
  5505. PrescriptionQualificationIdentification: "", //处方资格标识
  5506. IdentificationOutpatients: "", //门诊大病医师标识
  5507. OutpatientIllnessCategory: "", //门诊大病类别
  5508. StartTime: 20201022, //开始日期
  5509. EndTime: 20201022,
  5510. }
  5511. customs = append(customs, detail)
  5512. }
  5513. result := service.SzybYS003(doctor_name, doctor_code, miConfig.Code, customs)
  5514. var dat map[string]interface{}
  5515. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5516. fmt.Println(dat)
  5517. } else {
  5518. fmt.Println(err)
  5519. }
  5520. userJSONBytes, _ := json.Marshal(dat)
  5521. var res Result
  5522. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5523. utils.ErrorLog("解析失败:%v", err)
  5524. c.ServeSuccessJSON(map[string]interface{}{
  5525. "failed_code": -10,
  5526. "msg": res.Transreturnmessage,
  5527. })
  5528. return
  5529. }
  5530. if res.Transreturncode == "00000000" {
  5531. ress = append(ress, &res)
  5532. } else {
  5533. isSuccess = false
  5534. //失败
  5535. c.ServeSuccessJSON(map[string]interface{}{
  5536. "failed_code": -10,
  5537. "msg": res.Transreturnmessage,
  5538. })
  5539. return
  5540. }
  5541. fmt.Println(isSuccess)
  5542. c.ServeSuccessJSON(map[string]interface{}{
  5543. "failed_code": -10,
  5544. "msg": res.Transreturnmessage,
  5545. })
  5546. return
  5547. }
  5548. }
  5549. func (c *SZHisApiController) GetGoodsList() {
  5550. adminUserInfo := c.GetAdminUserInfo()
  5551. orgId := adminUserInfo.CurrentOrgId
  5552. ids := c.GetString("ids")
  5553. admin_user_id, _ := c.GetInt64("admin_user_id")
  5554. roles, _ := service.GetAdminUserInfoByID(orgId, admin_user_id)
  5555. stringarr := strings.Split(ids, ",")
  5556. idss := make([]int64, 0)
  5557. for _, item := range stringarr {
  5558. itemsss, _ := strconv.ParseInt(item, 10, 64)
  5559. id := int64(itemsss)
  5560. idss = append(idss, id)
  5561. }
  5562. //批量获取所有耗材信息
  5563. list, _ := service.GetBatchGoodInformationList(idss)
  5564. //获取单位
  5565. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  5566. var doctor_name string
  5567. var doctor_code string
  5568. doctor_name = roles.UserName
  5569. doctor_code = "1001"
  5570. var isSuccess bool = true
  5571. for _, item := range list {
  5572. detail := &models.XtGoodInformation{
  5573. GoodName: item.GoodName,
  5574. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  5575. ManufacturerName: item.ManufacturerName,
  5576. ProductionType: item.ProductionType,
  5577. SpecialMedical: item.SpecialMedical,
  5578. BuyPrice: item.BuyPrice,
  5579. SellPrice: item.SellPrice,
  5580. Remark: item.Remark,
  5581. SpecificationName: item.SpecificationName,
  5582. }
  5583. result := service.SzybYML007(doctor_name, doctor_code, miConfig.Code, detail)
  5584. fmt.Println("reuslt", result)
  5585. var dat map[string]interface{}
  5586. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5587. fmt.Println(dat)
  5588. } else {
  5589. fmt.Println(err)
  5590. }
  5591. userJSONBytes, _ := json.Marshal(dat)
  5592. var res Result
  5593. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5594. utils.ErrorLog("解析失败:%v", err)
  5595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5596. return
  5597. }
  5598. if res.Transreturncode == "00000000" {
  5599. //备案成功返回状态
  5600. _, err := service.UpdateGoodInformaitonByDetail(item.ID)
  5601. fmt.Println("err", err)
  5602. } else {
  5603. isSuccess = false
  5604. //失败
  5605. c.ServeSuccessJSON(map[string]interface{}{
  5606. "failed_code": -10,
  5607. "msg": res.Transreturnmessage,
  5608. })
  5609. return
  5610. }
  5611. fmt.Println(isSuccess)
  5612. c.ServeSuccessJSON(map[string]interface{}{
  5613. "failed_code": -10,
  5614. "msg": res.Transreturnmessage,
  5615. })
  5616. return
  5617. }
  5618. }
  5619. type Charset string
  5620. const (
  5621. UTF8 = Charset("UTF-8")
  5622. GB18030 = Charset("GB18030")
  5623. )
  5624. func ConvertToString(src string, srcCode string, tagCode string) string {
  5625. srcCoder := mahonia.NewDecoder(srcCode)
  5626. srcResult := srcCoder.ConvertString(src)
  5627. tagCoder := mahonia.NewDecoder(tagCode)
  5628. _, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
  5629. result := string(cdata)
  5630. return result
  5631. }