his_api_controller.go 148KB

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