his_api_controller.go 159KB

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