his_api_controller.go 157KB

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