zh_his_api_controller.go 138KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059
  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. struct2401.Insutype = insutype
  1363. psn_info, _ := service.GetPsnByPatientId(patient.ID)
  1364. if id_card_type == 1 {
  1365. struct2401.MdtrtCertType = "03"
  1366. bas := strings.Split(psn_info.CardInfo, "|")
  1367. cardNumber := bas[2]
  1368. struct2401.MdtrtCertNo = cardNumber
  1369. } else {
  1370. struct2401.MdtrtCertType = "02"
  1371. struct2401.MdtrtCertNo = res2.Output.Baseinfo.Certno
  1372. }
  1373. if miConfig.Code == "H15049901371" {
  1374. if med_type == 14 {
  1375. if insutype == "390" {
  1376. struct2401.MedType = "9933"
  1377. } else if insutype == "310" {
  1378. struct2401.MedType = "990502"
  1379. }
  1380. } else if med_type == 11 {
  1381. struct2401.MedType = "11"
  1382. }
  1383. } else {
  1384. struct2401.MedType = strconv.FormatInt(int64(med_type), 10)
  1385. }
  1386. struct2401.IptNo = ipt_otp_no
  1387. struct2401.AtddrNo = doctorInfo.DoctorNumber
  1388. struct2401.ChfpdrName = doctorInfo.UserName
  1389. struct2401.AdmDiagDscr = diagnosisConfig[0].ClassName
  1390. struct2401.AdmDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  1391. struct2401.AdmDeptName = departmentInfo.Name
  1392. struct2401.AdmBed = deviceNumber.Number
  1393. struct2401.AdmBed = "待定"
  1394. struct2401.DscgMaindiagName = diagnosisConfig[0].ClassName
  1395. struct2401.DscgMaindiagCode = diagnosisConfig[0].CountryCode
  1396. struct2401.Begntime = start_time
  1397. struct2401.DiseCodg = sickConfig.CountryCode
  1398. struct2401.DiseName = sickConfig.ClassName
  1399. var dises []service.DiseinfoStruct
  1400. for index, item := range diagnosisConfig {
  1401. var dise service.DiseinfoStruct
  1402. dise.PsnNo = res2.Output.Baseinfo.PsnNo
  1403. dise.DiagType = "1"
  1404. if index == 0 {
  1405. dise.MaindiagFlag = "1"
  1406. } else {
  1407. dise.MaindiagFlag = "2"
  1408. }
  1409. dise.DiagSrtNo = strconv.FormatInt(int64(index), 10)
  1410. dise.DiseDorName = doctorInfo.UserName
  1411. dise.DiagCode = item.CountryCode
  1412. dise.DiagName = item.ClassName
  1413. dise.DiagDept = departmentInfo.Name
  1414. dise.DiseDorNo = doctorInfo.DoctorNumber
  1415. dise.DiagTime = timeFormatOne
  1416. dises = append(dises, dise)
  1417. }
  1418. struct2401.Diseinfo = dises
  1419. var result string
  1420. var request_log string
  1421. if miConfig.MdtrtareaAdmvs == "150499" {
  1422. data := make(map[string]interface{})
  1423. data["org_name"] = miConfig.OrgName
  1424. data["doctor"] = role.UserName
  1425. data["fixmedins_code"] = miConfig.Code
  1426. data["insuplc_admdvs"] = insuplc_admdvs
  1427. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1428. data["secret_key"] = miConfig.SecretKey
  1429. data["struct_2401"] = struct2401
  1430. var req *http.Request
  1431. bytesData, _ := json.Marshal(data)
  1432. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2401", bytes.NewReader(bytesData))
  1433. client := &http.Client{}
  1434. resp, _ := client.Do(req)
  1435. defer resp.Body.Close()
  1436. body, ioErr := ioutil.ReadAll(resp.Body)
  1437. if ioErr != nil {
  1438. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1440. return
  1441. }
  1442. var respJSON map[string]interface{}
  1443. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1444. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1446. return
  1447. }
  1448. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1449. result_byte, _ := json.Marshal(respJSON)
  1450. result = string(result_byte)
  1451. } else {
  1452. result, request_log = service.ZHGdyb2401(struct2401, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, insuplc_admdvs, miConfig.MdtrtareaAdmvs)
  1453. saveLog(result, request_log, "2401", "入院登记")
  1454. }
  1455. var dat map[string]interface{}
  1456. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1457. fmt.Println(dat)
  1458. } else {
  1459. fmt.Println(err)
  1460. }
  1461. userJSONBytes, _ := json.Marshal(dat)
  1462. var res ResultThree
  1463. var resThree10265 ResultThree10265
  1464. if miConfig.Code == "H15049901371" {
  1465. if err := json.Unmarshal(userJSONBytes, &resThree10265); err != nil {
  1466. utils.ErrorLog("解析失败:%v", err)
  1467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1468. return
  1469. }
  1470. Infcode, _ := strconv.ParseInt(resThree10265.Infcode, 10, 64)
  1471. res.Infcode = Infcode
  1472. res.ErrMsg = resThree10265.ErrMsg
  1473. res.Output = resThree10265.Output
  1474. res.InfRefmsgid = resThree10265.InfRefmsgid
  1475. res.RespondTime = resThree10265.RespondTime
  1476. } else {
  1477. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1478. utils.ErrorLog("解析失败:%v", err)
  1479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1480. return
  1481. }
  1482. }
  1483. if res.Infcode == 0 {
  1484. //result2 := service.Gdyb5301Two(res2.Output.Baseinfo.PsnNo, miConfig.OrgName, role.UserName, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  1485. //fmt.Println(result2)
  1486. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  1487. Idetinfos, _ := json.Marshal(res2.Output.Idetinfo)
  1488. infoStr := string(Iinfos)
  1489. idetinfoStr := string(Idetinfos)
  1490. inHospital := &models.HisHospitalCheckRecord{
  1491. PatientId: id,
  1492. Name: name,
  1493. MedicalTreatmentType: med_type,
  1494. RecordDate: recordDateTime,
  1495. IdCardNo: id_card_no,
  1496. AdminUserId: admin_user_id,
  1497. Departments: department,
  1498. UserOrgId: adminInfo.CurrentOrgId,
  1499. Status: 1,
  1500. Ctime: time.Now().Unix(),
  1501. Mtime: time.Now().Unix(),
  1502. Number: res.Output.Result.MdtrtID,
  1503. Doctor: doctor,
  1504. PsnNo: res2.Output.Baseinfo.PsnNo,
  1505. PsnCertType: res2.Output.Baseinfo.PsnCertType,
  1506. Certno: res2.Output.Baseinfo.Certno,
  1507. PsnName: res2.Output.Baseinfo.PsnName,
  1508. Gend: res2.Output.Baseinfo.Gend,
  1509. Naty: res2.Output.Baseinfo.Naty,
  1510. MedType: med_type,
  1511. InsutypeType: insutype,
  1512. Brdy: res2.Output.Baseinfo.Brdy,
  1513. Iinfo: infoStr,
  1514. Idetinfo: idetinfoStr,
  1515. IptOtpNo: ipt_otp_no,
  1516. AdmBed: adm_bed,
  1517. IdCardType: id_card_type,
  1518. Diagnosis: diagnosis_ids,
  1519. SickType: sick_type,
  1520. MdtrtCertType: "02",
  1521. InHosptialTime: start_time,
  1522. OutHosptialTime: "",
  1523. InHospitalStatus: 1,
  1524. Certificates: certificates,
  1525. Phone: phone,
  1526. BalanceAccountsType: balance_accounts_type,
  1527. PsnType: psn_type,
  1528. InsuplcAdmdvs: insuplc_admdvs,
  1529. }
  1530. service.CreateHospitalRecord(inHospital)
  1531. c.ServeSuccessJSON(map[string]interface{}{
  1532. "msg": "办理入院成功",
  1533. "info": inHospital,
  1534. })
  1535. } else {
  1536. c.ServeSuccessJSON(map[string]interface{}{
  1537. "failed_code": -10,
  1538. "msg": res.ErrMsg,
  1539. })
  1540. }
  1541. } else {
  1542. c.ServeSuccessJSON(map[string]interface{}{
  1543. "failed_code": -10,
  1544. "msg": res2.ErrMsg,
  1545. })
  1546. return
  1547. }
  1548. }
  1549. func (this *ZHHisApiController) GetZHOutHospitalCheck() {
  1550. id, _ := this.GetInt64("id")
  1551. patient_id, _ := this.GetInt64("patient_id")
  1552. admin_user_id, _ := this.GetInt64("admin_user_id")
  1553. record_time := this.GetString("record_time")
  1554. out_time := this.GetString("out_time")
  1555. adminInfo := this.GetAdminUserInfo()
  1556. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1557. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1558. record, _ := service.GetInHospitalRecord(id)
  1559. if record.ID == 0 {
  1560. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  1561. return
  1562. }
  1563. timeLayout := "2006-01-02"
  1564. loc, _ := time.LoadLocation("Local")
  1565. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1566. if err != nil {
  1567. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1568. return
  1569. }
  1570. recordDateTime := theTime.Unix()
  1571. var patient service.Patients
  1572. if patient_id == 0 {
  1573. patient, _ = service.GetPatientByIDCard(record.IdCardNo, adminInfo.CurrentOrgId)
  1574. } else {
  1575. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  1576. }
  1577. fmt.Println(patient)
  1578. diagnosis_ids_arr := strings.Split(record.Diagnosis, "-")
  1579. diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  1580. departmentInfo, _ := service.GetDepartMentDetail(record.Departments)
  1581. doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, record.Doctor)
  1582. //deviceNumber, _ := service.GetDeviceNumberByID(record.AdmBed, adminInfo.CurrentOrgId)
  1583. sickConfig, _ := service.FindSickById(record.SickType)
  1584. var struct2402 service.Struct2402
  1585. timestamp := time.Now().Unix()
  1586. tempTime := time.Unix(timestamp, 0)
  1587. //timeFormat := tempTime.Format("20060102150405")
  1588. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  1589. struct2402.PsnNo = record.PsnNo
  1590. struct2402.Insutype = record.InsutypeType
  1591. struct2402.DscgWay = "1"
  1592. struct2402.Endtime = out_time
  1593. struct2402.DscgDeptName = departmentInfo.Number
  1594. struct2402.DscgDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  1595. struct2402.MdtrtId = record.Number
  1596. var dises []service.Diseinfo2402Struct
  1597. for index, item := range diagnosisConfig {
  1598. var dise service.Diseinfo2402Struct
  1599. dise.PsnNo = record.PsnNo
  1600. dise.DiagType = "1"
  1601. if index == 0 {
  1602. dise.MaindiagFlag = "1"
  1603. } else {
  1604. dise.MaindiagFlag = "2"
  1605. }
  1606. dise.MdtrtId = record.Number
  1607. dise.DiagSrtNo = strconv.FormatInt(int64(item.ID), 10)
  1608. dise.DiseDorName = doctorInfo.UserName
  1609. dise.DiagCode = item.CountryCode
  1610. dise.DiagName = item.ClassName
  1611. dise.DiagDept = departmentInfo.Name
  1612. dise.DiseDorNo = strconv.FormatInt(int64(doctorInfo.AdminUserId), 10)
  1613. dise.DiagTime = timeFormatOne
  1614. dises = append(dises, dise)
  1615. }
  1616. struct2402.Diseinfo = dises
  1617. struct2402.DiseName = sickConfig.ClassName
  1618. struct2402.DiseCode = sickConfig.CountryCode
  1619. var result string
  1620. var request_log string
  1621. if miConfig.MdtrtareaAdmvs == "150499" {
  1622. data := make(map[string]interface{})
  1623. data["org_name"] = miConfig.OrgName
  1624. data["doctor"] = role.UserName
  1625. data["fixmedins_code"] = miConfig.Code
  1626. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  1627. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1628. data["secret_key"] = miConfig.SecretKey
  1629. data["struct_2402"] = struct2402
  1630. var req *http.Request
  1631. bytesData, _ := json.Marshal(data)
  1632. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2402", bytes.NewReader(bytesData))
  1633. client := &http.Client{}
  1634. resp, _ := client.Do(req)
  1635. defer resp.Body.Close()
  1636. body, ioErr := ioutil.ReadAll(resp.Body)
  1637. if ioErr != nil {
  1638. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1639. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1640. return
  1641. }
  1642. var respJSON map[string]interface{}
  1643. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1644. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1645. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1646. return
  1647. }
  1648. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1649. result_byte, _ := json.Marshal(respJSON)
  1650. result = string(result_byte)
  1651. } else {
  1652. result, request_log = service.ZHGdyb2402(struct2402, miConfig.OrgName, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  1653. saveLog(result, request_log, "2402", "出院")
  1654. }
  1655. var dat map[string]interface{}
  1656. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1657. fmt.Println(dat)
  1658. } else {
  1659. fmt.Println(err)
  1660. }
  1661. userJSONBytes, _ := json.Marshal(dat)
  1662. var res ResultEmpty
  1663. var resEmpty10265 ResultEmpty10265
  1664. if miConfig.Code == "H15049901371" {
  1665. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  1666. utils.ErrorLog("解析失败:%v", err)
  1667. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1668. return
  1669. }
  1670. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  1671. res.Infcode = Infcode
  1672. res.RespondTime = resEmpty10265.RespondTime
  1673. res.ErrMsg = resEmpty10265.ErrMsg
  1674. res.Output = resEmpty10265.Output
  1675. res.WarnMsg = resEmpty10265.WarnMsg
  1676. } else {
  1677. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1678. utils.ErrorLog("解析失败:%v", err)
  1679. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1680. return
  1681. }
  1682. }
  1683. if res.Infcode == 0 {
  1684. record.OutHospitalStatus = 1
  1685. record.OutHosptialTime = struct2402.Endtime
  1686. record.OutWay = 1
  1687. service.CreateHospitalRecord(&record)
  1688. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  1689. var total float64
  1690. for _, item := range orders {
  1691. total = total + item.DetItemFeeSumamt
  1692. }
  1693. order := &models.HisOrder{
  1694. UserOrgId: adminInfo.CurrentOrgId,
  1695. HisPatientId: record.ID,
  1696. PatientId: record.PatientId,
  1697. SettleAccountsDate: recordDateTime,
  1698. Ctime: time.Now().Unix(),
  1699. Mtime: time.Now().Unix(),
  1700. Status: 1,
  1701. Number: record.Number,
  1702. Infcode: 0,
  1703. WarnMsg: "",
  1704. Cainfo: "",
  1705. ErrMsg: "",
  1706. RespondTime: "",
  1707. InfRefmsgid: "",
  1708. OrderStatus: 1,
  1709. MdtrtId: record.Number,
  1710. IsMedicineInsurance: 1,
  1711. PType: 1,
  1712. MedfeeSumamt: total,
  1713. }
  1714. err = service.CreateOrder(order)
  1715. if err != nil {
  1716. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1717. return
  1718. }
  1719. this.ServeSuccessJSON(map[string]interface{}{
  1720. "msg": "出院成功",
  1721. })
  1722. } else {
  1723. this.ServeSuccessJSON(map[string]interface{}{
  1724. "failed_code": -10,
  1725. "msg": res.ErrMsg,
  1726. })
  1727. }
  1728. }
  1729. func (c *ZHHisApiController) GetSettleInfo() {
  1730. order_id, _ := c.GetInt64("order_id")
  1731. patient_id, _ := c.GetInt64("patient_id")
  1732. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  1733. admin_user_id, _ := c.GetInt64("admin_user_id")
  1734. pay_way, _ := c.GetInt64("pay_way")
  1735. pay_price, _ := c.GetFloat("pay_price")
  1736. pay_card_no := c.GetString("pay_card_no")
  1737. discount_price, _ := c.GetFloat("discount_price")
  1738. preferential_price, _ := c.GetFloat("preferential_price")
  1739. reality_price, _ := c.GetFloat("reality_price")
  1740. found_price, _ := c.GetFloat("found_price")
  1741. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1742. private_price, _ := c.GetFloat("private_price")
  1743. fapiao_code := c.GetString("fapiao_code")
  1744. fapiao_number := c.GetString("fapiao_number")
  1745. record, _ := service.GetInHospitalRecord(in_hospital_id)
  1746. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  1747. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  1748. order, _ := service.GetHisOrderByID(order_id)
  1749. //dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  1750. //tmp_decimal := c.GetString("tmp_decimal")
  1751. //var decimal float64 //本次使用的押金
  1752. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  1753. tmp_decimal := c.GetString("tmp_decimal")
  1754. var decimal float64 //本次使用的押金
  1755. var errmsg error
  1756. if dec_way == "true" && tmp_decimal == "0" || dec_way == "true" && tmp_decimal == "" {
  1757. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  1758. return
  1759. }
  1760. if len(tmp_decimal) > 0 {
  1761. if tmp_decimal[0] == 45 {
  1762. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  1763. return
  1764. }
  1765. }
  1766. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  1767. if errs != nil {
  1768. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
  1769. return
  1770. }
  1771. decimal = tt
  1772. var rf []*ResultFive
  1773. json.Unmarshal([]byte(record.Iinfo), &rf)
  1774. chrg_bchno := order.Number
  1775. cert_no := record.Certno
  1776. if record.ID == 0 {
  1777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1778. return
  1779. }
  1780. if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  1781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  1782. return
  1783. }
  1784. if record.IdCardType == 1 {
  1785. } else {
  1786. cert_no = record.Certno
  1787. }
  1788. var result string
  1789. var src_resquest string
  1790. timeLayout := "2006-01-02"
  1791. loc, _ := time.LoadLocation("Local")
  1792. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record.InHosptialTime, loc)
  1793. if err != nil {
  1794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1795. return
  1796. }
  1797. recordStartDateTime := theTime.Unix()
  1798. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", record.OutHosptialTime, loc)
  1799. if err != nil {
  1800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1801. return
  1802. }
  1803. recordEndDateTime := theTimeEnd.Unix()
  1804. prescriptions, _ := service.GetZHSettleMonthHisPrescription(c.GetAdminUserInfo().CurrentOrgId, patient_id, recordStartDateTime, recordEndDateTime)
  1805. var total float64
  1806. for _, item := range prescriptions {
  1807. if item.Type == 1 { //药品
  1808. for _, subItem := range item.HisDoctorAdviceInfo {
  1809. total = total + (subItem.Price * subItem.PrescribingNumber)
  1810. }
  1811. }
  1812. if item.Type == 2 { //项目
  1813. for _, subItem := range item.HisPrescriptionProject {
  1814. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  1815. total = total + (subItem.Price * cnt)
  1816. }
  1817. }
  1818. }
  1819. //allTotal := fmt.Sprintf("%.2f", total)
  1820. var allTotal string
  1821. if record.OutHospitalStatus == 0 && order.ID == 0 {
  1822. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  1823. var total float64
  1824. for _, item := range orders {
  1825. total = total + item.DetItemFeeSumamt
  1826. }
  1827. allTotal = fmt.Sprintf("%.4f", total)
  1828. } else {
  1829. allTotal = fmt.Sprintf("%.4f", order.MedfeeSumamt)
  1830. }
  1831. if miConfig.MdtrtareaAdmvs == "150499" {
  1832. psn_info, _ := service.GetPsnByPatientId(patient_id)
  1833. mdtrt_cert_no := ""
  1834. if record.IdCardType == 1 {
  1835. bas := strings.Split(psn_info.CardInfo, "|")
  1836. cardNumber := bas[2]
  1837. mdtrt_cert_no = cardNumber
  1838. } else {
  1839. mdtrt_cert_no = record.Certno
  1840. }
  1841. var acct_used_flag string
  1842. if pay_way == 4 {
  1843. acct_used_flag = "1"
  1844. } else {
  1845. acct_used_flag = "0"
  1846. }
  1847. //请求内网数据
  1848. api := "http://172.16.13.254:9532/" + "nmyb/2304?psn_no=" + record.PsnNo + "&mdtrt_id=" + record.Number + "&chrg_bchno=" + chrg_bchno +
  1849. "&insutype_type=" + record.InsutypeType + "&total=" + allTotal +
  1850. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  1851. "&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
  1852. resp, requestErr := http.Get(api)
  1853. if requestErr != nil {
  1854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1855. return
  1856. }
  1857. body, ioErr := ioutil.ReadAll(resp.Body)
  1858. if ioErr != nil {
  1859. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1860. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1861. return
  1862. }
  1863. var respJSON map[string]interface{}
  1864. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1865. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1867. return
  1868. }
  1869. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1870. result_byte, _ := json.Marshal(respJSON)
  1871. result = string(result_byte)
  1872. } else {
  1873. 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")
  1874. saveLog(result, src_resquest, "2304", "住院结算")
  1875. }
  1876. var dat map[string]interface{}
  1877. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1878. fmt.Println(dat)
  1879. } else {
  1880. fmt.Println(err)
  1881. }
  1882. userJSONBytes, _ := json.Marshal(dat)
  1883. var res ResultSeven
  1884. var resSeven10265 ResultSeven10265
  1885. if miConfig.Code == "H15049901371" {
  1886. if err := json.Unmarshal(userJSONBytes, &resSeven10265); err != nil {
  1887. utils.ErrorLog("解析失败:%v", err)
  1888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1889. return
  1890. }
  1891. Infcode, _ := strconv.ParseInt(resSeven10265.Infcode, 10, 64)
  1892. res.Infcode = Infcode
  1893. res.InfRefmsgid = resSeven10265.InfRefmsgid
  1894. res.RespondTime = resSeven10265.RespondTime
  1895. res.ErrMsg = resSeven10265.ErrMsg
  1896. res.Output = resSeven10265.Output
  1897. res.WarnMsg = resSeven10265.WarnMsg
  1898. res.Cainfo = resSeven10265.Cainfo
  1899. } else {
  1900. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1901. utils.ErrorLog("解析失败:%v", err)
  1902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1903. return
  1904. }
  1905. }
  1906. if res.Infcode != 0 {
  1907. errlog := &models.HisOrderError{
  1908. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1909. Ctime: time.Now().Unix(),
  1910. Mtime: time.Now().Unix(),
  1911. Number: chrg_bchno,
  1912. ErrMsg: res.ErrMsg,
  1913. Status: 1,
  1914. PatientId: patient_id,
  1915. RecordTime: time.Now().Unix(),
  1916. Stage: 6,
  1917. }
  1918. service.CreateErrMsgLog(errlog)
  1919. c.ServeSuccessJSON(map[string]interface{}{
  1920. "failed_code": -10,
  1921. "msg": res.ErrMsg,
  1922. })
  1923. return
  1924. } else {
  1925. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1926. order.OrderStatus = 2
  1927. order.DiscountPrice = discount_price
  1928. order.MedicalInsurancePrice = medical_insurance_price
  1929. order.FaPiaoNumber = fapiao_number
  1930. order.FaPiaoCode = fapiao_code
  1931. order.PayWay = pay_way
  1932. order.PayPrice = pay_price
  1933. order.PayCardNo = pay_card_no
  1934. order.PreferentialPrice = preferential_price
  1935. order.RealityPrice = reality_price
  1936. order.FoundPrice = found_price
  1937. order.PrivatePrice = private_price
  1938. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1939. order.SetlId = res.Output.Setlinfo.SetlID
  1940. order.PsnNo = res.Output.Setlinfo.PsnNo
  1941. order.PsnName = res.Output.Setlinfo.PsnName
  1942. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1943. order.Certno = res.Output.Setlinfo.Certno
  1944. order.Gend = res.Output.Setlinfo.Gend
  1945. order.Naty = res.Output.Setlinfo.Naty
  1946. order.Age = res.Output.Setlinfo.Age
  1947. order.Insutype = res.Output.Setlinfo.Insutype
  1948. order.PsnType = res.Output.Setlinfo.PsnType
  1949. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1950. order.SetlTime = res.Output.Setlinfo.SetlTime
  1951. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1952. if res.Output.Setlinfo.MedType == "140104" {
  1953. order.MedType = "14"
  1954. } else {
  1955. order.MedType = res.Output.Setlinfo.MedType
  1956. }
  1957. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1958. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1959. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1960. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1961. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1962. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1963. order.HifpPay = res.Output.Setlinfo.HifpPay
  1964. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1965. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1966. order.HifesPay = res.Output.Setlinfo.HifesPay
  1967. order.HifobPay = res.Output.Setlinfo.HifobPay
  1968. order.MafPay = res.Output.Setlinfo.MafPay
  1969. order.OthPay = res.Output.Setlinfo.OthPay
  1970. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1971. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1972. order.AcctPay = res.Output.Setlinfo.AcctPay
  1973. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1974. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1975. order.Balc = res.Output.Setlinfo.Balc
  1976. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1977. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1978. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1979. order.ClrWay = res.Output.Setlinfo.ClrWay
  1980. order.Creator = order.Creator
  1981. order.Modify = roles.AdminUserId
  1982. order.RequestLog = src_resquest
  1983. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1984. detailStr := string(setlDetail)
  1985. order.SetlDetail = detailStr
  1986. err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  1987. err = service.UpDateOrder(order)
  1988. if err == nil {
  1989. //判断是否使用了押金
  1990. if dec_way == "true" {
  1991. tmpstring := strconv.FormatInt(order.ID, 10)
  1992. order.Decimal = decimal
  1993. err = service.UpDateOrder(order)
  1994. //扣押金
  1995. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, patient_id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  1996. if errmsg != nil {
  1997. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  1998. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  1999. return
  2000. }
  2001. }
  2002. c.ServeSuccessJSON(map[string]interface{}{
  2003. "msg": "结算成功",
  2004. })
  2005. } else {
  2006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2007. return
  2008. }
  2009. }
  2010. }
  2011. func (c *ZHHisApiController) GetPreSettleInfo() {
  2012. order_id, _ := c.GetInt64("order_id")
  2013. patient_id, _ := c.GetInt64("patient_id")
  2014. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  2015. admin_user_id, _ := c.GetInt64("admin_user_id")
  2016. record, _ := service.GetInHospitalRecord(in_hospital_id)
  2017. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  2018. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  2019. order, _ := service.GetHisOrderByID(order_id)
  2020. var allTotal string
  2021. if record.OutHospitalStatus == 0 && order.ID == 0 {
  2022. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  2023. var total float64
  2024. for _, item := range orders {
  2025. total = total + item.DetItemFeeSumamt
  2026. }
  2027. allTotal = fmt.Sprintf("%.4f", total)
  2028. } else {
  2029. allTotal = fmt.Sprintf("%.4f", order.MedfeeSumamt)
  2030. }
  2031. var rf []*ResultFive
  2032. json.Unmarshal([]byte(record.Iinfo), &rf)
  2033. chrg_bchno := order.Number
  2034. cert_no := record.Certno
  2035. if record.ID == 0 {
  2036. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2037. return
  2038. }
  2039. //if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  2040. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  2041. // return
  2042. //}
  2043. psn_info, _ := service.GetPsnByPatientId(patient_id)
  2044. if record.IdCardType == 1 {
  2045. bas := strings.Split(psn_info.CardInfo, "|")
  2046. cardNumber := bas[2]
  2047. cert_no = cardNumber
  2048. } else {
  2049. cert_no = record.Certno
  2050. }
  2051. var result string
  2052. var src_resquest string
  2053. if miConfig.MdtrtareaAdmvs == "150499" {
  2054. //请求内网数据
  2055. api := "http://172.16.13.254:9532/" + "nmyb/2303?psn_no=" + record.PsnNo + "&mdtrt_id=" + record.Number + "&chrg_bchno=" + chrg_bchno +
  2056. "&insutype_type=" + record.InsutypeType + "&total=" + allTotal +
  2057. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2058. "&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
  2059. resp, requestErr := http.Get(api)
  2060. if requestErr != nil {
  2061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2062. return
  2063. }
  2064. body, ioErr := ioutil.ReadAll(resp.Body)
  2065. if ioErr != nil {
  2066. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2068. return
  2069. }
  2070. var respJSON map[string]interface{}
  2071. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2072. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2074. return
  2075. }
  2076. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2077. result_byte, _ := json.Marshal(respJSON)
  2078. result = string(result_byte)
  2079. } else {
  2080. 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)
  2081. saveLog(result, src_resquest, "2303", "住院预结算")
  2082. }
  2083. var dat map[string]interface{}
  2084. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2085. fmt.Println(dat)
  2086. } else {
  2087. fmt.Println(err)
  2088. }
  2089. userJSONBytes, _ := json.Marshal(dat)
  2090. var res ResultSeven
  2091. var resSeven10265 ResultSeven10265
  2092. if miConfig.Code == "H15049901371" {
  2093. if err := json.Unmarshal(userJSONBytes, &resSeven10265); err != nil {
  2094. utils.ErrorLog("解析失败:%v", err)
  2095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2096. return
  2097. }
  2098. Infcode, _ := strconv.ParseInt(resSeven10265.Infcode, 10, 64)
  2099. res.Infcode = Infcode
  2100. res.InfRefmsgid = resSeven10265.InfRefmsgid
  2101. res.RespondTime = resSeven10265.RespondTime
  2102. res.ErrMsg = resSeven10265.ErrMsg
  2103. res.Output = resSeven10265.Output
  2104. res.WarnMsg = resSeven10265.WarnMsg
  2105. res.Cainfo = resSeven10265.Cainfo
  2106. } else {
  2107. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2108. utils.ErrorLog("解析失败:%v", err)
  2109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2110. return
  2111. }
  2112. }
  2113. if res.Infcode != 0 {
  2114. errlog := &models.HisOrderError{
  2115. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2116. Ctime: time.Now().Unix(),
  2117. Mtime: time.Now().Unix(),
  2118. Number: chrg_bchno,
  2119. ErrMsg: res.ErrMsg,
  2120. Status: 1,
  2121. PatientId: patient_id,
  2122. RecordTime: time.Now().Unix(),
  2123. Stage: 6,
  2124. }
  2125. service.CreateErrMsgLog(errlog)
  2126. c.ServeSuccessJSON(map[string]interface{}{
  2127. "failed_code": -10,
  2128. "msg": res.ErrMsg,
  2129. })
  2130. return
  2131. } else {
  2132. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2133. order.OrderStatus = 1
  2134. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2135. order.SetlId = res.Output.Setlinfo.SetlID
  2136. order.PsnNo = res.Output.Setlinfo.PsnNo
  2137. order.PsnName = res.Output.Setlinfo.PsnName
  2138. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2139. order.Certno = res.Output.Setlinfo.Certno
  2140. order.Gend = res.Output.Setlinfo.Gend
  2141. order.Naty = res.Output.Setlinfo.Naty
  2142. order.Age = res.Output.Setlinfo.Age
  2143. order.Insutype = res.Output.Setlinfo.Insutype
  2144. order.PsnType = res.Output.Setlinfo.PsnType
  2145. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2146. order.SetlTime = res.Output.Setlinfo.SetlTime
  2147. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2148. if res.Output.Setlinfo.MedType == "140104" {
  2149. order.MedType = "14"
  2150. } else {
  2151. order.MedType = res.Output.Setlinfo.MedType
  2152. }
  2153. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2154. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2155. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2156. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2157. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2158. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2159. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  2160. order.HifpPay = res.Output.Setlinfo.HifpPay
  2161. order.HifesPay = res.Output.Setlinfo.HifesPay
  2162. order.HifobPay = res.Output.Setlinfo.HifobPay
  2163. order.MafPay = res.Output.Setlinfo.MafPay
  2164. order.OthPay = res.Output.Setlinfo.OthPay
  2165. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2166. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2167. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2168. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2169. order.AcctPay = res.Output.Setlinfo.AcctPay
  2170. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2171. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2172. order.Balc = res.Output.Setlinfo.Balc
  2173. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2174. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2175. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2176. order.ClrWay = res.Output.Setlinfo.ClrWay
  2177. order.Creator = order.Creator
  2178. order.Modify = roles.AdminUserId
  2179. order.RequestLog = src_resquest
  2180. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2181. detailStr := string(setlDetail)
  2182. order.SetlDetail = detailStr
  2183. //err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  2184. if record.OutHospitalStatus == 1 && order.ID > 0 {
  2185. err := service.UpDateOrder(order)
  2186. if err == nil {
  2187. c.ServeSuccessJSON(map[string]interface{}{
  2188. "msg": "预结算成功",
  2189. "order_way": 1,
  2190. })
  2191. } else {
  2192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2193. return
  2194. }
  2195. } else if record.OutHospitalStatus == 0 && order.ID == 0 {
  2196. c.ServeSuccessJSON(map[string]interface{}{
  2197. "msg": "预结算成功",
  2198. "order": order,
  2199. "order_way": 2,
  2200. })
  2201. }
  2202. }
  2203. }
  2204. func (c *ZHHisApiController) GetUploadInfo() {
  2205. id, _ := c.GetInt64("id")
  2206. record_time := c.GetString("record_time")
  2207. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  2208. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2209. admin_user_id, _ := c.GetInt64("admin_user_id")
  2210. timeLayout := "2006-01-02"
  2211. loc, _ := time.LoadLocation("Local")
  2212. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2213. if err != nil {
  2214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2215. return
  2216. }
  2217. recordDateTime := theTime.Unix()
  2218. adminUser := c.GetAdminUserInfo()
  2219. var prescriptions []*models.HisPrescription
  2220. data := make(map[string]interface{})
  2221. if settle_accounts_type == 1 { //日结
  2222. prescriptions, _ = service.GetZHHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  2223. } else { //月结
  2224. start_time_str := c.GetString("start_time")
  2225. end_time_str := c.GetString("end_time")
  2226. timeLayout := "2006-01-02"
  2227. loc, _ := time.LoadLocation("Local")
  2228. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2229. if err != nil {
  2230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2231. return
  2232. }
  2233. recordStartTime := theStartTime.Unix()
  2234. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2235. if err != nil {
  2236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2237. return
  2238. }
  2239. recordEndTime := theEndTime.Unix()
  2240. prescriptions, _ = service.GetZHMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  2241. }
  2242. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2243. record, _ := service.GetInHospitalRecord(in_hospital_id)
  2244. if record.ID == 0 {
  2245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2246. return
  2247. }
  2248. timestamp := time.Now().Unix()
  2249. tempTime := time.Unix(timestamp, 0)
  2250. timeFormat := tempTime.Format("20060102150405")
  2251. chrgBchno := rand.Intn(100000) + 10000
  2252. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(record.PatientId, 10)
  2253. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2254. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2255. department, _ := service.GetDepartMentDetail(record.Departments)
  2256. strconv.FormatInt(record.PatientId, 10)
  2257. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, record.Doctor)
  2258. //client := &http.Client{}
  2259. data["psn_no"] = record.PsnNo
  2260. data["mdtrt_id"] = record.Number
  2261. data["chrg_bchno"] = chrg_bchno
  2262. data["org_name"] = miConfig.OrgName
  2263. data["doctor"] = roles.UserName
  2264. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  2265. data["dept"] = strconv.FormatInt(department.ID, 10)
  2266. data["fixmedins_code"] = miConfig.Code
  2267. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  2268. data["dept_code"] = "15"
  2269. } else {
  2270. data["dept_code"] = department.Number
  2271. }
  2272. if miConfig.Code == "H15049901371" {
  2273. if record.MedType == 14 {
  2274. if record.InsutypeType == "390" {
  2275. data["med_type"] = "9933"
  2276. } else if record.InsutypeType == "310" {
  2277. data["med_type"] = "990502"
  2278. }
  2279. } else if record.MedType == 11 {
  2280. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  2281. }
  2282. } else {
  2283. if record.MedType == 1112 {
  2284. data["med_type"] = strconv.FormatInt(11, 10)
  2285. } else {
  2286. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  2287. }
  2288. }
  2289. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  2290. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  2291. data["secret_key"] = miConfig.SecretKey
  2292. var ids []int64
  2293. fmt.Println(data)
  2294. for _, item := range prescriptions {
  2295. ids = append(ids, item.ID)
  2296. }
  2297. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2298. if config.IsOpen == 1 { //对接了医保,走医保流程
  2299. var pagesize int = 100
  2300. var start int = 1
  2301. var stop int
  2302. var pagecount int
  2303. var curpage int
  2304. var isSuccess bool = true
  2305. var customs []*models.NewCustom
  2306. for _, item := range prescriptions {
  2307. tm := time.Unix(item.PreTime, 0)
  2308. if item.Type == 1 { //药品
  2309. for _, subItem := range item.HisDoctorAdviceInfo {
  2310. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 && subItem.BaseDrugLib.IsUser != 1 {
  2311. //var randNum int
  2312. //randNum = rand.Intn(10000) + 1000
  2313. cus := &models.NewCustom{
  2314. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  2315. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  2316. FeedetlSn: subItem.FeedetlSn,
  2317. Price: fmt.Sprintf("%.4f", subItem.Price),
  2318. MedListCodg: subItem.BaseDrugLib.MedicalInsuranceNumber,
  2319. HospApprFlag: subItem.BaseDrugLib.HospApprFlag,
  2320. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  2321. }
  2322. customs = append(customs, cus)
  2323. }
  2324. }
  2325. }
  2326. if item.Type == 2 { //项目
  2327. for _, subItem := range item.HisPrescriptionProject {
  2328. //var randNum int
  2329. //randNum = rand.Intn(10000) + 1000
  2330. if subItem.Type == 2 {
  2331. if len(subItem.HisProject.MedicalCode) > 0 {
  2332. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  2333. cus := &models.NewCustom{
  2334. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  2335. Cut: fmt.Sprintf("%.4f", cnt),
  2336. FeedetlSn: subItem.FeedetlSn,
  2337. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  2338. MedListCodg: subItem.HisProject.MedicalCode,
  2339. HospApprFlag: -1,
  2340. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  2341. }
  2342. customs = append(customs, cus)
  2343. }
  2344. } else if subItem.Type == 3 {
  2345. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 && subItem.GoodInfo.IsUser != 1 {
  2346. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  2347. cus := &models.NewCustom{
  2348. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  2349. Cut: fmt.Sprintf("%.4f", cnt),
  2350. FeedetlSn: subItem.FeedetlSn,
  2351. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  2352. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  2353. HospApprFlag: -1,
  2354. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  2355. }
  2356. customs = append(customs, cus)
  2357. }
  2358. }
  2359. }
  2360. }
  2361. }
  2362. //总页数,向上取整,注意除之前要先转换类型为float64
  2363. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  2364. var ress []*ResultFour
  2365. for curpage = 1; curpage <= pagecount; curpage++ {
  2366. if curpage == 1 {
  2367. start = 1
  2368. } else {
  2369. start = (curpage-1)*pagesize + 1
  2370. }
  2371. stop = curpage * pagesize
  2372. if stop > len(customs) {
  2373. stop = len(customs)
  2374. }
  2375. var result string
  2376. var requestLog string
  2377. if miConfig.MdtrtareaAdmvs == "150499" {
  2378. data := make(map[string]interface{})
  2379. if record.MedType == 14 {
  2380. if record.InsutypeType == "390" {
  2381. data["med_type"] = "9933"
  2382. } else if record.InsutypeType == "310" {
  2383. data["med_type"] = "990502"
  2384. }
  2385. } else if record.MedType == 11 {
  2386. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  2387. }
  2388. data["psn_no"] = record.PsnNo
  2389. data["number"] = record.Number
  2390. data["customs"] = customs[start-1 : stop]
  2391. data["chrg_bchno"] = chrg_bchno
  2392. data["dept"] = strconv.FormatInt(department.ID, 10)
  2393. data["dept_code"] = department.Number
  2394. data["doctor_code"] = doctor_info.DoctorNumber
  2395. data["doctor_name"] = doctor_info.UserName
  2396. data["org_name"] = miConfig.OrgName
  2397. data["opertor"] = roles.UserName
  2398. data["fixmedins_code"] = miConfig.Code
  2399. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  2400. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  2401. data["secret_key"] = miConfig.SecretKey
  2402. var req *http.Request
  2403. bytesData, _ := json.Marshal(data)
  2404. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2301", bytes.NewReader(bytesData))
  2405. client := &http.Client{}
  2406. resp, _ := client.Do(req)
  2407. defer resp.Body.Close()
  2408. body, ioErr := ioutil.ReadAll(resp.Body)
  2409. if ioErr != nil {
  2410. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2412. return
  2413. }
  2414. var respJSON map[string]interface{}
  2415. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  2416. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2418. return
  2419. }
  2420. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2421. result_byte, _ := json.Marshal(respJSON)
  2422. result = string(result_byte)
  2423. } else {
  2424. 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)
  2425. saveLog(result, requestLog, "2301", "上传明细")
  2426. }
  2427. var dat map[string]interface{}
  2428. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2429. fmt.Println(dat)
  2430. } else {
  2431. fmt.Println(err)
  2432. }
  2433. userJSONBytes, _ := json.Marshal(dat)
  2434. var res ResultFour
  2435. var resFour10265 ResultFour10265
  2436. if miConfig.Code == "H15049901371" {
  2437. if err := json.Unmarshal(userJSONBytes, &resFour10265); err != nil {
  2438. utils.ErrorLog("解析失败:%v", err)
  2439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2440. return
  2441. }
  2442. res.WarnMsg = resFour10265.WarnMsg
  2443. res.Output = resFour10265.Output
  2444. res.ErrMsg = resFour10265.ErrMsg
  2445. res.RespondTime = resFour10265.RespondTime
  2446. res.InfRefmsgid = resFour10265.InfRefmsgid
  2447. Infcode, _ := strconv.ParseInt(resFour10265.Infcode, 10, 64)
  2448. res.Infcode = Infcode
  2449. } else {
  2450. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2451. utils.ErrorLog("解析失败:%v", err)
  2452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2453. return
  2454. }
  2455. }
  2456. if res.Infcode == 0 {
  2457. ress = append(ress, &res)
  2458. } else {
  2459. isSuccess = false
  2460. errlog := &models.HisOrderError{
  2461. UserOrgId: adminUser.CurrentOrgId,
  2462. Ctime: time.Now().Unix(),
  2463. Mtime: time.Now().Unix(),
  2464. Number: chrg_bchno,
  2465. ErrMsg: "",
  2466. Status: 1,
  2467. PatientId: id,
  2468. RecordTime: recordDateTime,
  2469. Stage: 4,
  2470. }
  2471. service.CreateErrMsgLog(errlog)
  2472. c.ServeSuccessJSON(map[string]interface{}{
  2473. "failed_code": -10,
  2474. "msg": "上传明细错误,请联系his厂商",
  2475. })
  2476. return
  2477. }
  2478. }
  2479. if isSuccess == true {
  2480. if settle_accounts_type == 1 {
  2481. for _, subItem := range ress {
  2482. for _, item := range subItem.Output.Result {
  2483. temp := strings.Split(item.FeedetlSn, "-")
  2484. var advice_id int64 = 0
  2485. var project_id int64 = 0
  2486. var types int64 = 0
  2487. id, _ := strconv.ParseInt(temp[2], 10, 64)
  2488. types, _ = strconv.ParseInt(temp[1], 10, 64)
  2489. if temp[1] == "1" {
  2490. advice_id = id
  2491. project_id = 0
  2492. } else if temp[1] == "2" {
  2493. advice_id = 0
  2494. project_id = id
  2495. }
  2496. info := &models.HisOrderInfo{
  2497. OrderNumber: record.Number,
  2498. FeedetlSn: item.FeedetlSn,
  2499. UploadDate: recordDateTime,
  2500. AdviceId: advice_id,
  2501. DetItemFeeSumamt: item.DetItemFeeSumamt,
  2502. Cnt: item.Cnt,
  2503. Pric: float64(item.Pric),
  2504. PatientId: record.PatientId,
  2505. PricUplmtAmt: item.PricUplmtAmt,
  2506. SelfpayProp: item.SelfpayProp,
  2507. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2508. OverlmtAmt: item.OverlmtAmt,
  2509. PreselfpayAmt: item.PreselfpayAmt,
  2510. BasMednFlag: item.BasMednFlag,
  2511. MedChrgitmType: item.MedChrgitmType,
  2512. HiNegoDrugFlag: item.HiNegoDrugFlag,
  2513. Status: 1,
  2514. Memo: item.Memo,
  2515. Mtime: time.Now().Unix(),
  2516. InscpScpAmt: item.InscpScpAmt,
  2517. DrtReimFlag: item.DrtReimFlag,
  2518. Ctime: time.Now().Unix(),
  2519. ListSpItemFlag: item.ListSpItemFlag,
  2520. ChldMedcFlag: item.ChldMedcFlag,
  2521. LmtUsedFlag: item.LmtUsedFlag,
  2522. ChrgitmLv: item.ChrgitmLv,
  2523. UserOrgId: adminUser.CurrentOrgId,
  2524. HisPatientId: record.ID,
  2525. OrderId: 0,
  2526. ProjectId: project_id,
  2527. Type: types,
  2528. SettleType: settle_accounts_type,
  2529. }
  2530. service.CreateOrderInfo(info)
  2531. }
  2532. }
  2533. err := service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  2534. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  2535. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  2536. if err == nil {
  2537. c.ServeSuccessJSON(map[string]interface{}{
  2538. "msg": "上传费用明细成功",
  2539. })
  2540. return
  2541. } else {
  2542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2543. return
  2544. }
  2545. } else {
  2546. for _, subItem := range ress {
  2547. for _, item := range subItem.Output.Result {
  2548. temp := strings.Split(item.FeedetlSn, "-")
  2549. var advice_id int64 = 0
  2550. var project_id int64 = 0
  2551. var types int64 = 0
  2552. id, _ := strconv.ParseInt(temp[2], 10, 64)
  2553. types, _ = strconv.ParseInt(temp[1], 10, 64)
  2554. if temp[1] == "1" {
  2555. advice_id = id
  2556. project_id = 0
  2557. } else if temp[1] == "2" {
  2558. advice_id = 0
  2559. project_id = id
  2560. }
  2561. info := &models.HisOrderInfo{
  2562. OrderNumber: record.Number,
  2563. FeedetlSn: item.FeedetlSn,
  2564. UploadDate: time.Now().Unix(),
  2565. AdviceId: advice_id,
  2566. DetItemFeeSumamt: item.DetItemFeeSumamt,
  2567. Cnt: item.Cnt,
  2568. Pric: float64(item.Pric),
  2569. PatientId: record.PatientId,
  2570. PricUplmtAmt: item.PricUplmtAmt,
  2571. SelfpayProp: item.SelfpayProp,
  2572. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2573. OverlmtAmt: item.OverlmtAmt,
  2574. PreselfpayAmt: item.PreselfpayAmt,
  2575. BasMednFlag: item.BasMednFlag,
  2576. MedChrgitmType: item.MedChrgitmType,
  2577. HiNegoDrugFlag: item.HiNegoDrugFlag,
  2578. Status: 1,
  2579. Memo: item.Memo,
  2580. Mtime: time.Now().Unix(),
  2581. InscpScpAmt: item.InscpScpAmt,
  2582. DrtReimFlag: item.DrtReimFlag,
  2583. Ctime: time.Now().Unix(),
  2584. ListSpItemFlag: item.ListSpItemFlag,
  2585. ChldMedcFlag: item.ChldMedcFlag,
  2586. LmtUsedFlag: item.LmtUsedFlag,
  2587. ChrgitmLv: item.ChrgitmLv,
  2588. UserOrgId: adminUser.CurrentOrgId,
  2589. HisPatientId: record.ID,
  2590. ProjectId: project_id,
  2591. Type: types,
  2592. SettleType: settle_accounts_type,
  2593. }
  2594. service.CreateOrderInfo(info)
  2595. }
  2596. }
  2597. service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  2598. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  2599. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  2600. c.ServeSuccessJSON(map[string]interface{}{
  2601. "msg": "上传费用明细成功",
  2602. })
  2603. }
  2604. }
  2605. }
  2606. }
  2607. func (c *ZHHisApiController) ZHRefund() {
  2608. order_id, _ := c.GetInt64("order_id")
  2609. admin_user_id, _ := c.GetInt64("admin_user_id")
  2610. adminUser := c.GetAdminUserInfo()
  2611. var order models.HisOrder
  2612. order, _ = service.GetHisOrderByID(order_id)
  2613. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  2614. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2615. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2616. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2617. if config.IsOpen == 1 { //对接了医保,走医保流程
  2618. var result string
  2619. var requestLog string
  2620. if miConfig.MdtrtareaAdmvs == "150499" {
  2621. //请求内网数据
  2622. api := "http://172.16.13.254:9532/" + "nmyb/2305?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo + "&setl_id=" + order.SetlId +
  2623. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2624. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2625. resp, requestErr := http.Get(api)
  2626. if requestErr != nil {
  2627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2628. return
  2629. }
  2630. body, ioErr := ioutil.ReadAll(resp.Body)
  2631. if ioErr != nil {
  2632. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2634. return
  2635. }
  2636. var respJSON map[string]interface{}
  2637. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2638. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2640. return
  2641. }
  2642. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2643. result_byte, _ := json.Marshal(respJSON)
  2644. result = string(result_byte)
  2645. //saveLog(result, requestLog, "2404", "入院登记撤销")
  2646. saveLog(result, requestLog, "2305", "退费")
  2647. } else {
  2648. result, requestLog := service.Gdyb2305(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2649. saveLog(result, requestLog, "2305", "退费")
  2650. }
  2651. var dat map[string]interface{}
  2652. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2653. fmt.Println(dat)
  2654. } else {
  2655. fmt.Println(err)
  2656. }
  2657. userJSONBytes, _ := json.Marshal(dat)
  2658. var res ResultSixteen
  2659. var resSixteen ResultSixteen10265
  2660. if miConfig.Code == "H15049901371" {
  2661. if err := json.Unmarshal(userJSONBytes, &resSixteen); err != nil {
  2662. utils.ErrorLog("解析失败:%v", err)
  2663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2664. return
  2665. }
  2666. res.Cainfo = resSixteen.Cainfo
  2667. res.WarnMsg = resSixteen.WarnMsg
  2668. res.Output = resSixteen.Output
  2669. res.ErrMsg = resSixteen.ErrMsg
  2670. res.RespondTime = resSixteen.RespondTime
  2671. Infcode, _ := strconv.ParseInt(resSixteen.Infcode, 10, 64)
  2672. res.Infcode = Infcode
  2673. } else {
  2674. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2675. utils.ErrorLog("解析失败:%v", err)
  2676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2677. return
  2678. }
  2679. }
  2680. if res.Infcode == 0 {
  2681. err := service.UpdataOrderStatusThree(order_id, order.Number, adminUser.CurrentOrgId, "", result)
  2682. ////不同地区退费流程不一样,肇庆那边退费就包括撤销出院,内蒙古退费不包括撤销明细,所以下面需要根据不同情况进行判断
  2683. //if miConfig.UserOrgId == 10215 {
  2684. // record.OutHospitalStatus = 0
  2685. // service.CreateHospitalRecord(&record)
  2686. //}
  2687. service.UpdataOrderStatusByNumber(record.Number)
  2688. if err == nil {
  2689. ////当押金不为零时产生退费记录
  2690. if order.Decimal != 0 {
  2691. tmp := strconv.FormatInt(order.ID, 10)
  2692. err = service.MoneyIncrease(adminUser.CurrentOrgId, order.PatientId, tmp, order.Decimal)
  2693. if err != nil {
  2694. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2695. return
  2696. }
  2697. }
  2698. c.ServeSuccessJSON(map[string]interface{}{
  2699. "msg": "退费成功",
  2700. })
  2701. } else {
  2702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2703. return
  2704. }
  2705. } else {
  2706. c.ServeSuccessJSON(map[string]interface{}{
  2707. "code": -10,
  2708. "msg": res.ErrMsg,
  2709. })
  2710. }
  2711. } else {
  2712. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  2713. if err == nil {
  2714. c.ServeSuccessJSON(map[string]interface{}{
  2715. "msg": "退费成功",
  2716. })
  2717. } else {
  2718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2719. return
  2720. }
  2721. }
  2722. }
  2723. func (c *ZHHisApiController) ZHRefundDetail() {
  2724. patient_id, _ := c.GetInt64("patient_id")
  2725. his_patient_id, _ := c.GetInt64("his_patient_id")
  2726. record_time := c.GetString("record_time")
  2727. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2728. //order_id, _ := c.GetInt64("order_id")
  2729. admin_user_id, _ := c.GetInt64("admin_user_id")
  2730. timeLayout := "2006-01-02"
  2731. loc, _ := time.LoadLocation("Local")
  2732. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2733. if err != nil {
  2734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2735. return
  2736. }
  2737. recordDateTime := theTime.Unix()
  2738. adminUser := c.GetAdminUserInfo()
  2739. theTimeTwo, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 23:59:59", loc)
  2740. if err != nil {
  2741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2742. return
  2743. }
  2744. recordDateTimeTwo := theTimeTwo.Unix()
  2745. //var prescriptions []*models.HisPrescription
  2746. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2747. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2748. if settle_accounts_type == 1 { //日结
  2749. record, _ := service.GetInHospitalRecord(his_patient_id)
  2750. infos, _ := service.GetZHHisUploadOrderInfo(adminUser.CurrentOrgId, patient_id, recordDateTime, recordDateTimeTwo, record.Number)
  2751. var isSuccess bool = true
  2752. for _, item := range infos {
  2753. var result string
  2754. var requestLog string
  2755. if miConfig.MdtrtareaAdmvs == "150499" {
  2756. //请求内网数据
  2757. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&feedetl_sn=" + item.FeedetlSn +
  2758. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2759. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "1"
  2760. resp, requestErr := http.Get(api)
  2761. if requestErr != nil {
  2762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2763. return
  2764. }
  2765. body, ioErr := ioutil.ReadAll(resp.Body)
  2766. if ioErr != nil {
  2767. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2769. return
  2770. }
  2771. var respJSON map[string]interface{}
  2772. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2773. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2775. return
  2776. }
  2777. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2778. result_byte, _ := json.Marshal(respJSON)
  2779. result = string(result_byte)
  2780. saveLog(result, requestLog, "2302", "日结退明细")
  2781. } else {
  2782. result, requestLog := service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, item.FeedetlSn, 1)
  2783. saveLog(result, requestLog, "2302", "日结退明细")
  2784. }
  2785. var dat map[string]interface{}
  2786. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2787. fmt.Println(dat)
  2788. } else {
  2789. fmt.Println(err)
  2790. }
  2791. userJSONBytes, _ := json.Marshal(dat)
  2792. var res2 ResultEmpty
  2793. var resEmpty10265 ResultEmpty10265
  2794. if miConfig.Code == "H15049901371" {
  2795. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2796. utils.ErrorLog("解析失败:%v", err)
  2797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2798. return
  2799. }
  2800. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2801. res2.Infcode = Infcode
  2802. res2.RespondTime = resEmpty10265.RespondTime
  2803. res2.ErrMsg = resEmpty10265.ErrMsg
  2804. res2.Output = resEmpty10265.Output
  2805. res2.WarnMsg = resEmpty10265.WarnMsg
  2806. } else {
  2807. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2808. utils.ErrorLog("解析失败:%v", err)
  2809. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2810. return
  2811. }
  2812. }
  2813. if res2.Infcode == -1 {
  2814. isSuccess = false
  2815. }
  2816. }
  2817. if isSuccess {
  2818. err := service.UpDateOrderInfoStatus(patient_id, recordDateTime, adminUser.CurrentOrgId, recordDateTimeTwo)
  2819. if err != nil {
  2820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2821. return
  2822. }
  2823. err1 := service.UpDatePrescriptionOrderStatusTwo(patient_id, recordDateTime, adminUser.CurrentOrgId)
  2824. if err1 != nil {
  2825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2826. return
  2827. }
  2828. c.ServeSuccessJSON(map[string]interface{}{
  2829. "msg": "撤销明细成功",
  2830. })
  2831. }
  2832. } else {
  2833. //prescriptions, _ = service.GetZHMonthHisUploadPrescription(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2834. //var order models.HisOrder
  2835. //order, _ = service.GetHisOrderByID(order_id)
  2836. //record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  2837. var result string
  2838. var requestLog string
  2839. record, _ := service.GetInHospitalRecord(his_patient_id)
  2840. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2841. if config.IsOpen == 1 { //对接了医保,走医保流程
  2842. if miConfig.MdtrtareaAdmvs == "150499" {
  2843. //请求内网数据
  2844. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=0000" +
  2845. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2846. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "0"
  2847. resp, requestErr := http.Get(api)
  2848. if requestErr != nil {
  2849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2850. return
  2851. }
  2852. body, ioErr := ioutil.ReadAll(resp.Body)
  2853. if ioErr != nil {
  2854. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2856. return
  2857. }
  2858. var respJSON map[string]interface{}
  2859. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2860. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2862. return
  2863. }
  2864. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2865. result_byte, _ := json.Marshal(respJSON)
  2866. result = string(result_byte)
  2867. //saveLog(result, requestLog, "2302", "日结退明细")
  2868. } else {
  2869. result, requestLog = service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  2870. saveLog(result, requestLog, "2302", "月结退明细")
  2871. }
  2872. var dat map[string]interface{}
  2873. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2874. fmt.Println(dat)
  2875. } else {
  2876. fmt.Println(err)
  2877. }
  2878. userJSONBytes, _ := json.Marshal(dat)
  2879. var res2 ResultEmpty
  2880. var resEmpty10265 ResultEmpty10265
  2881. if miConfig.Code == "H15049901371" {
  2882. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2883. utils.ErrorLog("解析失败:%v", err)
  2884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2885. return
  2886. }
  2887. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2888. res2.Infcode = Infcode
  2889. res2.RespondTime = resEmpty10265.RespondTime
  2890. res2.ErrMsg = resEmpty10265.ErrMsg
  2891. res2.Output = resEmpty10265.Output
  2892. res2.WarnMsg = resEmpty10265.WarnMsg
  2893. } else {
  2894. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2895. utils.ErrorLog("解析失败:%v", err)
  2896. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2897. return
  2898. }
  2899. }
  2900. if res2.Infcode == 0 {
  2901. err := service.UpdataHospitalOrderStatus(record.Number, adminUser.CurrentOrgId)
  2902. if err == nil {
  2903. c.ServeSuccessJSON(map[string]interface{}{
  2904. "msg": "撤销明细成功",
  2905. })
  2906. } else {
  2907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2908. return
  2909. }
  2910. } else {
  2911. c.ServeSuccessJSON(map[string]interface{}{
  2912. "code": -10,
  2913. "msg": res2.ErrMsg,
  2914. })
  2915. }
  2916. }
  2917. }
  2918. }
  2919. func (this *ZHHisApiController) GetZHOutHospitalUnCheck() {
  2920. id, _ := this.GetInt64("id")
  2921. admin_user_id, _ := this.GetInt64("admin_user_id")
  2922. adminInfo := this.GetAdminUserInfo()
  2923. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2924. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  2925. record, _ := service.GetInHospitalRecord(id)
  2926. if record.ID == 0 {
  2927. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  2928. return
  2929. }
  2930. var result string
  2931. var requestLog string
  2932. if miConfig.MdtrtareaAdmvs == "150499" {
  2933. //请求内网数据
  2934. api := "http://172.16.13.254:9532/" + "nmyb/2405?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  2935. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  2936. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2937. fmt.Println(api)
  2938. resp, requestErr := http.Get(api)
  2939. if requestErr != nil {
  2940. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2941. return
  2942. }
  2943. body, ioErr := ioutil.ReadAll(resp.Body)
  2944. if ioErr != nil {
  2945. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2946. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2947. return
  2948. }
  2949. var respJSON map[string]interface{}
  2950. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2951. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2952. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2953. return
  2954. }
  2955. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2956. result_byte, _ := json.Marshal(respJSON)
  2957. result = string(result_byte)
  2958. } else {
  2959. result, requestLog = service.ZHGdyb2405(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2960. saveLog(result, requestLog, "2405", "出院登记撤销")
  2961. }
  2962. var dat map[string]interface{}
  2963. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2964. fmt.Println(dat)
  2965. } else {
  2966. fmt.Println(err)
  2967. }
  2968. userJSONBytes, _ := json.Marshal(dat)
  2969. var res ResultEmpty
  2970. var resEmpty10265 ResultEmpty10265
  2971. if miConfig.Code == "H15049901371" {
  2972. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2973. utils.ErrorLog("解析失败:%v", err)
  2974. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2975. return
  2976. }
  2977. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2978. res.Infcode = Infcode
  2979. res.RespondTime = resEmpty10265.RespondTime
  2980. res.ErrMsg = resEmpty10265.ErrMsg
  2981. res.Output = resEmpty10265.Output
  2982. res.WarnMsg = resEmpty10265.WarnMsg
  2983. } else {
  2984. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2985. utils.ErrorLog("解析失败:%v", err)
  2986. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2987. return
  2988. }
  2989. }
  2990. if res.Infcode == 0 {
  2991. record.OutHospitalStatus = 0
  2992. service.CreateHospitalRecord(&record)
  2993. service.UpdataOrderStatusByNumber(record.Number)
  2994. this.ServeSuccessJSON(map[string]interface{}{
  2995. "msg": "撤销出院成功",
  2996. })
  2997. } else {
  2998. this.ServeSuccessJSON(map[string]interface{}{
  2999. "failed_code": -10,
  3000. "msg": res.ErrMsg,
  3001. })
  3002. }
  3003. }
  3004. func (this *ZHHisApiController) GetZHInHospitalUnCheck() {
  3005. id, _ := this.GetInt64("id")
  3006. admin_user_id, _ := this.GetInt64("admin_user_id")
  3007. adminInfo := this.GetAdminUserInfo()
  3008. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  3009. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  3010. record, _ := service.GetInHospitalRecord(id)
  3011. if record.ID == 0 {
  3012. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  3013. return
  3014. }
  3015. var result string
  3016. var requestLog string
  3017. orders, _ := service.GetHisOrderInfoByNumber(record.Number)
  3018. if len(orders) > 0 { //判断是否上传过明细,有的话需要退明细,后撤销入院
  3019. if miConfig.MdtrtareaAdmvs == "150499" {
  3020. //请求内网数据
  3021. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=" + "0000" +
  3022. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  3023. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=0"
  3024. resp, requestErr := http.Get(api)
  3025. if requestErr != nil {
  3026. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3027. return
  3028. }
  3029. body, ioErr := ioutil.ReadAll(resp.Body)
  3030. if ioErr != nil {
  3031. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3032. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3033. return
  3034. }
  3035. var respJSON map[string]interface{}
  3036. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3037. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3038. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3039. return
  3040. }
  3041. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3042. result_byte, _ := json.Marshal(respJSON)
  3043. result = string(result_byte)
  3044. saveLog(result, requestLog, "2302", "月结退明细")
  3045. } else {
  3046. result, requestLog = service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  3047. saveLog(result, requestLog, "2302", "月结退明细")
  3048. }
  3049. var dat map[string]interface{}
  3050. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3051. fmt.Println(dat)
  3052. } else {
  3053. fmt.Println(err)
  3054. }
  3055. userJSONBytes, _ := json.Marshal(dat)
  3056. var res2 ResultEmpty
  3057. var resEmpty10265 ResultEmpty10265
  3058. if miConfig.Code == "H15049901371" {
  3059. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  3060. utils.ErrorLog("解析失败:%v", err)
  3061. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3062. return
  3063. }
  3064. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  3065. res2.Infcode = Infcode
  3066. res2.RespondTime = resEmpty10265.RespondTime
  3067. res2.ErrMsg = resEmpty10265.ErrMsg
  3068. res2.Output = resEmpty10265.Output
  3069. res2.WarnMsg = resEmpty10265.WarnMsg
  3070. } else {
  3071. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  3072. utils.ErrorLog("解析失败:%v", err)
  3073. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3074. return
  3075. }
  3076. }
  3077. if res2.Infcode == 0 {
  3078. service.UpdataHospitalOrderStatus(record.Number, adminInfo.CurrentOrgId)
  3079. var result string
  3080. var requestLog string
  3081. if miConfig.MdtrtareaAdmvs == "150499" {
  3082. //请求内网数据
  3083. api := "http://172.16.13.254:9532/" + "nmyb/2404?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  3084. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  3085. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3086. resp, requestErr := http.Get(api)
  3087. if requestErr != nil {
  3088. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3089. return
  3090. }
  3091. body, ioErr := ioutil.ReadAll(resp.Body)
  3092. if ioErr != nil {
  3093. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3094. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3095. return
  3096. }
  3097. var respJSON map[string]interface{}
  3098. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3099. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3100. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3101. return
  3102. }
  3103. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3104. result_byte, _ := json.Marshal(respJSON)
  3105. result = string(result_byte)
  3106. } else {
  3107. result, requestLog = service.ZHGdyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  3108. saveLog(result, requestLog, "2404", "入院登记撤销")
  3109. }
  3110. var dat map[string]interface{}
  3111. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3112. fmt.Println(dat)
  3113. } else {
  3114. fmt.Println(err)
  3115. }
  3116. userJSONBytes, _ := json.Marshal(dat)
  3117. var res ResultEmpty
  3118. var resEmpty10265 ResultEmpty10265
  3119. if miConfig.Code == "H15049901371" {
  3120. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  3121. utils.ErrorLog("解析失败:%v", err)
  3122. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3123. return
  3124. }
  3125. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  3126. res.Infcode = Infcode
  3127. res.RespondTime = resEmpty10265.RespondTime
  3128. res.ErrMsg = resEmpty10265.ErrMsg
  3129. res.Output = resEmpty10265.Output
  3130. res.WarnMsg = resEmpty10265.WarnMsg
  3131. } else {
  3132. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3133. utils.ErrorLog("解析失败:%v", err)
  3134. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3135. return
  3136. }
  3137. }
  3138. if res.Infcode == 0 {
  3139. record.Status = 0
  3140. service.CreateHospitalRecord(&record)
  3141. this.ServeSuccessJSON(map[string]interface{}{
  3142. "msg": "撤销入院成功",
  3143. })
  3144. } else {
  3145. this.ServeSuccessJSON(map[string]interface{}{
  3146. "failed_code": -10,
  3147. "msg": res.ErrMsg,
  3148. })
  3149. }
  3150. } else {
  3151. this.ServeSuccessJSON(map[string]interface{}{
  3152. "code": -10,
  3153. "msg": res2.ErrMsg,
  3154. })
  3155. }
  3156. } else { //没有上传过明细的,直接撤销入院
  3157. var result string
  3158. var requestLog string
  3159. if miConfig.MdtrtareaAdmvs == "150499" {
  3160. //请求内网数据
  3161. api := "http://172.16.13.254:9532/" + "nmyb/2404?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  3162. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  3163. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3164. resp, requestErr := http.Get(api)
  3165. if requestErr != nil {
  3166. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3167. return
  3168. }
  3169. body, ioErr := ioutil.ReadAll(resp.Body)
  3170. if ioErr != nil {
  3171. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3172. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3173. return
  3174. }
  3175. var respJSON map[string]interface{}
  3176. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3177. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3178. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3179. return
  3180. }
  3181. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3182. result_byte, _ := json.Marshal(respJSON)
  3183. result = string(result_byte)
  3184. } else {
  3185. result, requestLog = service.ZHGdyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  3186. saveLog(result, requestLog, "2404", "入院登记撤销")
  3187. }
  3188. var dat map[string]interface{}
  3189. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3190. fmt.Println(dat)
  3191. } else {
  3192. fmt.Println(err)
  3193. }
  3194. userJSONBytes, _ := json.Marshal(dat)
  3195. var res ResultEmpty
  3196. var resEmpty10265 ResultEmpty10265
  3197. if miConfig.Code == "H15049901371" {
  3198. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  3199. utils.ErrorLog("解析失败:%v", err)
  3200. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3201. return
  3202. }
  3203. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  3204. res.Infcode = Infcode
  3205. res.RespondTime = resEmpty10265.RespondTime
  3206. res.ErrMsg = resEmpty10265.ErrMsg
  3207. res.Output = resEmpty10265.Output
  3208. res.WarnMsg = resEmpty10265.WarnMsg
  3209. } else {
  3210. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3211. utils.ErrorLog("解析失败:%v", err)
  3212. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3213. return
  3214. }
  3215. }
  3216. if res.Infcode == 0 {
  3217. record.Status = 0
  3218. service.CreateHospitalRecord(&record)
  3219. this.ServeSuccessJSON(map[string]interface{}{
  3220. "msg": "撤销入院成功",
  3221. })
  3222. } else {
  3223. this.ServeSuccessJSON(map[string]interface{}{
  3224. "failed_code": -10,
  3225. "msg": res.ErrMsg,
  3226. })
  3227. }
  3228. }
  3229. }
  3230. func saveLog(result string, request string, infno string, desc string) {
  3231. org_id, _ := beego.AppConfig.Int64("org_id")
  3232. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  3233. dir := miConfig.OrgName + "日志"
  3234. utils.Mkdir(dir)
  3235. month := time.Unix(1557042972, 0).Format("1")
  3236. year := time.Now().Format("2006")
  3237. month = time.Now().Format("01")
  3238. day := time.Now().Format("02")
  3239. hour := time.Now().Format("15")
  3240. min := time.Now().Format("04")
  3241. sec := time.Now().Format("05")
  3242. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  3243. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  3244. file_name := file + ".txt"
  3245. file_path := miConfig.OrgName + "日志" + "/" + file_name
  3246. exist, _ := utils.PathExists(file_path)
  3247. if exist { //存在
  3248. fmt.Println("存在")
  3249. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  3250. if err != nil {
  3251. fmt.Println("read fail")
  3252. }
  3253. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  3254. n, _ := f.Seek(0, 2)
  3255. _, err = f.WriteAt([]byte(content), n)
  3256. } else { //不存在
  3257. fmt.Println("文件不存在,创建文件")
  3258. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  3259. defer f.Close()
  3260. if err != nil {
  3261. } else {
  3262. _, err = f.Write([]byte("记录日志"))
  3263. }
  3264. }
  3265. }
  3266. type Charset string
  3267. const (
  3268. UTF8 = Charset("UTF-8")
  3269. GB18030 = Charset("GB18030")
  3270. )
  3271. func ConvertToString(src string, srcCode string, tagCode string) string {
  3272. srcCoder := mahonia.NewDecoder(srcCode)
  3273. srcResult := srcCoder.ConvertString(src)
  3274. tagCoder := mahonia.NewDecoder(tagCode)
  3275. _, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
  3276. result := string(cdata)
  3277. return result
  3278. }
  3279. type ELeData struct {
  3280. Data struct {
  3281. IdNo string `json:"idNo"`
  3282. IdType string `json:"idType"`
  3283. UserName string `json:"userName"`
  3284. EcToken string `json:"ecToken"`
  3285. InsuOrg string `json:"insuOrg"`
  3286. Gender string `json:"gender"`
  3287. Birthday string `json:"birthday"`
  3288. Nationality string `json:"nationality"`
  3289. Email string `json:"email"`
  3290. Extra string `json:"extra"`
  3291. } `json:"data"`
  3292. Code int `json:"code"`
  3293. Message string `json:"message"`
  3294. }
  3295. func (c *ZHHisApiController) ReadCard() {
  3296. id_card_type, _ := c.GetInt64("id_card_type")
  3297. admin_user_id, _ := c.GetInt64("admin_user_id")
  3298. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  3299. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  3300. var api string
  3301. api = "http://172.16.13.254:9532/" + "nmyb/readcard?" + "fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName +
  3302. "&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
  3303. fmt.Println(api)
  3304. resp, requestErr := http.Get(api)
  3305. if requestErr != nil {
  3306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3307. return
  3308. }
  3309. body, ioErr := ioutil.ReadAll(resp.Body)
  3310. if ioErr != nil {
  3311. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3313. return
  3314. }
  3315. var respJSON map[string]interface{}
  3316. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3317. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3319. return
  3320. }
  3321. var status string
  3322. status = respJSON["data"].(map[string]interface{})["status"].(string)
  3323. card_type := respJSON["data"].(map[string]interface{})["type"].(string)
  3324. //console.log()
  3325. fmt.Println("type===")
  3326. fmt.Println(card_type)
  3327. var token string
  3328. var res ResultTwo //1101结果
  3329. var res10265 ResultTwo10265 //1101结果
  3330. var card_info string //卡信息
  3331. var busi_card_info string
  3332. card_info = respJSON["data"].(map[string]interface{})["card_info"].(string)
  3333. busi_card_info = respJSON["data"].(map[string]interface{})["busi_card_info"].(string)
  3334. if status == "0" { //读卡成功
  3335. if card_type == "1" {
  3336. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  3337. result, _ := json.Marshal(respJSON)
  3338. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  3339. utils.ErrorLog("解析失败:%v", err)
  3340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3341. return
  3342. }
  3343. res.ErrMsg = res10265.ErrMsg
  3344. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  3345. res.Infcode = infocode
  3346. res.Output = res10265.Output
  3347. res.InfRefmsgid = res10265.InfRefmsgid
  3348. } else {
  3349. //var card_info string //卡信息
  3350. //var busi_card_info string
  3351. token = respJSON["data"].(map[string]interface{})["token"].(string)
  3352. //busi_card_info = respJSON["data"].(map[string]interface{})["busi_card_info"].(string)
  3353. //fmt.Println(card_info)
  3354. //fmt.Println(busi_card_info)
  3355. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  3356. result, _ := json.Marshal(respJSON)
  3357. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  3358. utils.ErrorLog("解析失败:%v", err)
  3359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3360. return
  3361. }
  3362. res.ErrMsg = res10265.ErrMsg
  3363. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  3364. res.Infcode = infocode
  3365. res.Output = res10265.Output
  3366. res.InfRefmsgid = res10265.InfRefmsgid
  3367. }
  3368. if res.Infcode == 0 {
  3369. var insutypes []string
  3370. var insutype string
  3371. var is390 int = 0
  3372. var is310 int = 0
  3373. for _, item := range res.Output.Iinfo {
  3374. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  3375. insutypes = append(insutypes, item.Insutype)
  3376. }
  3377. }
  3378. if len(insutypes) == 1 {
  3379. insutype = insutypes[0]
  3380. } else {
  3381. for _, i := range insutypes {
  3382. if i == "390" {
  3383. is390 = 1
  3384. }
  3385. if i == "310" {
  3386. is310 = 1
  3387. }
  3388. }
  3389. }
  3390. if is390 == 1 {
  3391. insutype = "390"
  3392. }
  3393. if is310 == 1 {
  3394. insutype = "310"
  3395. }
  3396. if len(insutypes) == 0 {
  3397. insutype = "310"
  3398. }
  3399. patient, err := service.GetPatientByIDCard(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  3400. if err == gorm.ErrRecordNotFound {
  3401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  3402. return
  3403. } else if err != nil {
  3404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3405. return
  3406. } else {
  3407. if card_type == "1" {
  3408. bas := strings.Split(card_info, "|")
  3409. basNumber := bas[2]
  3410. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  3411. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  3412. infoStr := string(Iinfos)
  3413. idetinfoStr := string(Idetinfos)
  3414. psn := &models.HisPsn{
  3415. PsnNo: res.Output.Baseinfo.PsnNo,
  3416. Age: res.Output.Baseinfo.Age,
  3417. PatientId: patient.ID,
  3418. Certno: res.Output.Baseinfo.Certno,
  3419. Brdy: res.Output.Baseinfo.Brdy,
  3420. Gend: res.Output.Baseinfo.Gend,
  3421. Naty: res.Output.Baseinfo.Naty,
  3422. PsnCertType: res.Output.Baseinfo.PsnCertType,
  3423. PsnName: res.Output.Baseinfo.PsnName,
  3424. Idetinfo: idetinfoStr,
  3425. Insuinfo: infoStr,
  3426. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3427. CardInfo: card_info,
  3428. VerifyNumber: busi_card_info,
  3429. }
  3430. service.CreateHisPsn(psn)
  3431. c.ServeSuccessJSON(map[string]interface{}{
  3432. "patient": patient,
  3433. "number": basNumber,
  3434. "info": res,
  3435. "insutype": insutype,
  3436. })
  3437. } else {
  3438. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  3439. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  3440. infoStr := string(Iinfos)
  3441. idetinfoStr := string(Idetinfos)
  3442. psn := &models.HisPsn{
  3443. PsnNo: res.Output.Baseinfo.PsnNo,
  3444. Age: res.Output.Baseinfo.Age,
  3445. PatientId: patient.ID,
  3446. Certno: res.Output.Baseinfo.Certno,
  3447. Brdy: res.Output.Baseinfo.Brdy,
  3448. Gend: res.Output.Baseinfo.Gend,
  3449. Naty: res.Output.Baseinfo.Naty,
  3450. PsnCertType: res.Output.Baseinfo.PsnCertType,
  3451. PsnName: res.Output.Baseinfo.PsnName,
  3452. Idetinfo: idetinfoStr,
  3453. Insuinfo: infoStr,
  3454. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3455. CardInfo: card_info,
  3456. VerifyNumber: token,
  3457. }
  3458. service.CreateHisPsn(psn)
  3459. c.ServeSuccessJSON(map[string]interface{}{
  3460. "patient": patient,
  3461. "number": token,
  3462. "info": res,
  3463. "insutype": insutype,
  3464. })
  3465. }
  3466. }
  3467. } else {
  3468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  3469. return
  3470. }
  3471. } else { //读卡失败
  3472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  3473. return
  3474. }
  3475. }
  3476. var initFlag int64 = 0
  3477. func (c *ZHHisApiController) TestGetBasBaseInit() {
  3478. DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
  3479. Iinit := DllDef.MustFindProc("Init")
  3480. //miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  3481. str := make([]byte, 2048)
  3482. inputData := make(map[string]interface{})
  3483. inputData["IP"] = "10.144.211.75"
  3484. inputData["PORT"] = 7021
  3485. inputData["TIMEOUT"] = 180
  3486. inputData["LOG_PATH"] = "C:\\log\\"
  3487. //inputData["SFZ_DRIVER_TYPE"] = 0
  3488. inputData["URL"] = "/call1"
  3489. bytesData, _ := json.Marshal(inputData)
  3490. fmt.Println(inputData)
  3491. fmt.Println(bytesData)
  3492. ret, _, err := Iinit.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&str[0])))
  3493. if ret != 0 {
  3494. fmt.Println("SSCard的报错原因:", err)
  3495. fmt.Println("SSCard的运算结果为:", ret)
  3496. fmt.Println("SSCard的返回结果为:", string(str))
  3497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  3498. return
  3499. }
  3500. fmt.Println("SSCard的返回结果为:", string(str))
  3501. result := int(ret)
  3502. fmt.Println("SSCard的运算结果为1:", result)
  3503. //initFlag = 1
  3504. return
  3505. }
  3506. func (c *ZHHisApiController) GetSFZBaseInfo() string {
  3507. DllDef := syscall.MustLoadDLL("SSCard.dll")
  3508. readCard := DllDef.MustFindProc("ReadSFZ")
  3509. if readCard == nil {
  3510. fmt.Println("readcard is nil")
  3511. readCard = DllDef.MustFindProc("ReadSFZ")
  3512. }
  3513. str := make([]byte, 256)
  3514. str1 := make([]byte, 256)
  3515. r, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  3516. fmt.Println(r)
  3517. return string(str)
  3518. }
  3519. func (c *ZHHisApiController) GetBasBaseInfo(fixmedins_code string, mdtrtarea_admvs string, opter_name string, opter_id string, fixmedins_name string) string {
  3520. DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
  3521. readCard := DllDef.MustFindProc("ReadCardBas")
  3522. fmt.Println(readCard)
  3523. fmt.Println("!!!!!")
  3524. month := time.Unix(1557042972, 0).Format("1")
  3525. year := time.Now().Format("2006")
  3526. month = time.Now().Format("01")
  3527. day := time.Now().Format("02")
  3528. hour := time.Now().Format("15")
  3529. min := time.Now().Format("04")
  3530. sec := time.Now().Format("05")
  3531. msec := time.Now().Format("000")
  3532. timestamp := time.Now().Unix()
  3533. tempTime := time.Unix(timestamp, 0)
  3534. //timeFormat := tempTime.Format("20060102150405")
  3535. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  3536. //randNum := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000)
  3537. inputData := make(map[string]interface{})
  3538. inputData["infno"] = "1199"
  3539. //inputData["msgid"] = "7021"
  3540. inputData["msgid"] = fixmedins_code + year + month + day + hour + min + sec + msec + "0" // 发送方报文 ID
  3541. inputData["mdtrtarea_admvs"] = mdtrtarea_admvs // 发送方报文 ID
  3542. inputData["recer_sys_code"] = "01"
  3543. inputData["infver"] = "V1.0"
  3544. inputData["opter_type"] = "1"
  3545. inputData["opter"] = opter_id
  3546. inputData["opter_name"] = opter_name
  3547. inputData["inf_time"] = timeFormatOne
  3548. inputData["fixmedins_code"] = fixmedins_code
  3549. inputData["fixmedins_name"] = fixmedins_name
  3550. inputData["dev_no"] = ""
  3551. inputData["dev_safe_info"] = ""
  3552. inputData["cainfo"] = ""
  3553. inputData["signtype"] = ""
  3554. inputData["sign_no"] = ""
  3555. bytesData, _ := json.Marshal(inputData)
  3556. fmt.Println(string(bytesData))
  3557. pBusiCardInfo := make([]byte, 8192)
  3558. ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
  3559. fmt.Println(ret2)
  3560. fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
  3561. fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
  3562. if ret2 != 0 {
  3563. return ""
  3564. }
  3565. return DeleteExtraSpace(string(pBusiCardInfo))
  3566. }
  3567. func DeleteExtraSpace(s string) string {
  3568. //删除字符串中的多余空格,有多个空格时,仅保留一个空格
  3569. s1 := strings.Replace(s, " ", " ", -1) //替换tab为空格
  3570. regstr := "\\s{2,}" //两个及两个以上空格的正则表达式
  3571. reg, _ := regexp.Compile(regstr) //编译正则表达式
  3572. s2 := make([]byte, len(s1)) //定义字符数组切片
  3573. copy(s2, s1) //将字符串复制到切片
  3574. spc_index := reg.FindStringIndex(string(s2)) //在字符串中搜索
  3575. for len(spc_index) > 0 { //找到适配项
  3576. s2 = append(s2[:spc_index[0]+1], s2[spc_index[1]:]...) //删除多余空格
  3577. spc_index = reg.FindStringIndex(string(s2)) //继续在字符串中搜索
  3578. }
  3579. return string(s2)
  3580. }
  3581. func (c *ZHHisApiController) GetELeInfo(code string, operator_id string, operator_name string) (string, string) {
  3582. DllDef := syscall.MustLoadDLL("NationECCode.dll")
  3583. readCard := DllDef.MustFindProc("NationEcTrans")
  3584. fmt.Println(readCard)
  3585. fmt.Println("!!!!!")
  3586. pBusiCardInfo := make([]byte, 8192)
  3587. input := make(map[string]interface{})
  3588. inputData := make(map[string]interface{})
  3589. inputData["orgId"] = code
  3590. inputData["businessType"] = "01101"
  3591. inputData["operatorId"] = operator_id
  3592. inputData["operatorName"] = operator_name
  3593. inputData["officeId"] = "001"
  3594. inputData["officeName"] = "血透室"
  3595. inputData["deviceType"] = ""
  3596. input["data"] = inputData
  3597. input["orgId"] = code
  3598. input["transType"] = "ec.query"
  3599. bytesData, _ := json.Marshal(input)
  3600. gdyb_url := beego.AppConfig.String("gdyb_url")
  3601. url := gdyb_url + "/localcfc/api/hsecfc/localQrCodeQuery"
  3602. ret2, _, _ := readCard.Call(StrPtr(url), StrPtr(string(bytesData)), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
  3603. fmt.Println(ret2)
  3604. fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
  3605. fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
  3606. if ret2 != 0 {
  3607. return "", ""
  3608. }
  3609. return DeleteExtraSpace(""), DeleteExtraSpace(string(pBusiCardInfo))
  3610. }
  3611. func StrPtr(s string) uintptr {
  3612. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  3613. }
  3614. func Remove0000(s string) string {
  3615. str := make([]rune, 0, len(s))
  3616. for _, v := range []rune(s) {
  3617. if v == 0 {
  3618. continue
  3619. }
  3620. str = append(str, v)
  3621. }
  3622. return string(str)
  3623. }
  3624. func IntPtr(n int) uintptr {
  3625. return uintptr(n)
  3626. }