his_api_controller.go 147KB

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