his_api_controller.go 150KB

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