zh_his_api_controller.go 146KB

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