his_api_controller.go 150KB

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