his_api_controller.go 148KB

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