zh_his_api_controller.go 138KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062
  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, patientPrescription.Creator)
  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. DoctorId: item.Creator,
  2322. }
  2323. customs = append(customs, cus)
  2324. }
  2325. }
  2326. }
  2327. if item.Type == 2 { //项目
  2328. for _, subItem := range item.HisPrescriptionProject {
  2329. //var randNum int
  2330. //randNum = rand.Intn(10000) + 1000
  2331. if subItem.Type == 2 {
  2332. if len(subItem.HisProject.MedicalCode) > 0 {
  2333. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  2334. cus := &models.NewCustom{
  2335. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  2336. Cut: fmt.Sprintf("%.4f", cnt),
  2337. FeedetlSn: subItem.FeedetlSn,
  2338. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  2339. MedListCodg: subItem.HisProject.MedicalCode,
  2340. HospApprFlag: -1,
  2341. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  2342. DoctorId: item.Creator,
  2343. }
  2344. customs = append(customs, cus)
  2345. }
  2346. } else if subItem.Type == 3 {
  2347. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 && subItem.GoodInfo.IsUser != 1 {
  2348. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  2349. cus := &models.NewCustom{
  2350. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  2351. Cut: fmt.Sprintf("%.4f", cnt),
  2352. FeedetlSn: subItem.FeedetlSn,
  2353. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  2354. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  2355. HospApprFlag: -1,
  2356. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  2357. DoctorId: item.Creator,
  2358. }
  2359. customs = append(customs, cus)
  2360. }
  2361. }
  2362. }
  2363. }
  2364. }
  2365. //总页数,向上取整,注意除之前要先转换类型为float64
  2366. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  2367. var ress []*ResultFour
  2368. for curpage = 1; curpage <= pagecount; curpage++ {
  2369. if curpage == 1 {
  2370. start = 1
  2371. } else {
  2372. start = (curpage-1)*pagesize + 1
  2373. }
  2374. stop = curpage * pagesize
  2375. if stop > len(customs) {
  2376. stop = len(customs)
  2377. }
  2378. var result string
  2379. var requestLog string
  2380. if miConfig.MdtrtareaAdmvs == "150499" {
  2381. data := make(map[string]interface{})
  2382. if record.MedType == 14 {
  2383. if record.InsutypeType == "390" {
  2384. data["med_type"] = "9933"
  2385. } else if record.InsutypeType == "310" {
  2386. data["med_type"] = "990502"
  2387. }
  2388. } else if record.MedType == 11 {
  2389. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  2390. }
  2391. data["psn_no"] = record.PsnNo
  2392. data["number"] = record.Number
  2393. data["customs"] = customs[start-1 : stop]
  2394. data["chrg_bchno"] = chrg_bchno
  2395. data["dept"] = strconv.FormatInt(department.ID, 10)
  2396. data["dept_code"] = department.Number
  2397. data["doctor_code"] = doctor_info.DoctorNumber
  2398. data["doctor_name"] = doctor_info.UserName
  2399. data["org_name"] = miConfig.OrgName
  2400. data["opertor"] = roles.UserName
  2401. data["fixmedins_code"] = miConfig.Code
  2402. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  2403. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  2404. data["secret_key"] = miConfig.SecretKey
  2405. var req *http.Request
  2406. bytesData, _ := json.Marshal(data)
  2407. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2301", bytes.NewReader(bytesData))
  2408. client := &http.Client{}
  2409. resp, _ := client.Do(req)
  2410. defer resp.Body.Close()
  2411. body, ioErr := ioutil.ReadAll(resp.Body)
  2412. if ioErr != nil {
  2413. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2415. return
  2416. }
  2417. var respJSON map[string]interface{}
  2418. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  2419. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2421. return
  2422. }
  2423. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2424. result_byte, _ := json.Marshal(respJSON)
  2425. result = string(result_byte)
  2426. } else {
  2427. result, requestLog = service.ZHGdyb2301(record.PsnNo, record.Number, customs[start-1:stop], chrg_bchno, miConfig.OrgName, roles.UserName, strconv.FormatInt(department.ID, 10), miConfig.Code, department.Number, strconv.FormatInt(roles.AdminUserId, 10), record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, data["med_type"].(string), doctor_info.UserName, doctor_info.DoctorNumber)
  2428. saveLog(result, requestLog, "2301", "上传明细")
  2429. }
  2430. var dat map[string]interface{}
  2431. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2432. fmt.Println(dat)
  2433. } else {
  2434. fmt.Println(err)
  2435. }
  2436. userJSONBytes, _ := json.Marshal(dat)
  2437. var res ResultFour
  2438. var resFour10265 ResultFour10265
  2439. if miConfig.Code == "H15049901371" {
  2440. if err := json.Unmarshal(userJSONBytes, &resFour10265); err != nil {
  2441. utils.ErrorLog("解析失败:%v", err)
  2442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2443. return
  2444. }
  2445. res.WarnMsg = resFour10265.WarnMsg
  2446. res.Output = resFour10265.Output
  2447. res.ErrMsg = resFour10265.ErrMsg
  2448. res.RespondTime = resFour10265.RespondTime
  2449. res.InfRefmsgid = resFour10265.InfRefmsgid
  2450. Infcode, _ := strconv.ParseInt(resFour10265.Infcode, 10, 64)
  2451. res.Infcode = Infcode
  2452. } else {
  2453. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2454. utils.ErrorLog("解析失败:%v", err)
  2455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2456. return
  2457. }
  2458. }
  2459. if res.Infcode == 0 {
  2460. ress = append(ress, &res)
  2461. } else {
  2462. isSuccess = false
  2463. errlog := &models.HisOrderError{
  2464. UserOrgId: adminUser.CurrentOrgId,
  2465. Ctime: time.Now().Unix(),
  2466. Mtime: time.Now().Unix(),
  2467. Number: chrg_bchno,
  2468. ErrMsg: "",
  2469. Status: 1,
  2470. PatientId: id,
  2471. RecordTime: recordDateTime,
  2472. Stage: 4,
  2473. }
  2474. service.CreateErrMsgLog(errlog)
  2475. c.ServeSuccessJSON(map[string]interface{}{
  2476. "failed_code": -10,
  2477. "msg": "上传明细错误,请联系his厂商",
  2478. })
  2479. return
  2480. }
  2481. }
  2482. if isSuccess == true {
  2483. if settle_accounts_type == 1 {
  2484. for _, subItem := range ress {
  2485. for _, item := range subItem.Output.Result {
  2486. temp := strings.Split(item.FeedetlSn, "-")
  2487. var advice_id int64 = 0
  2488. var project_id int64 = 0
  2489. var types int64 = 0
  2490. id, _ := strconv.ParseInt(temp[2], 10, 64)
  2491. types, _ = strconv.ParseInt(temp[1], 10, 64)
  2492. if temp[1] == "1" {
  2493. advice_id = id
  2494. project_id = 0
  2495. } else if temp[1] == "2" {
  2496. advice_id = 0
  2497. project_id = id
  2498. }
  2499. info := &models.HisOrderInfo{
  2500. OrderNumber: record.Number,
  2501. FeedetlSn: item.FeedetlSn,
  2502. UploadDate: recordDateTime,
  2503. AdviceId: advice_id,
  2504. DetItemFeeSumamt: item.DetItemFeeSumamt,
  2505. Cnt: item.Cnt,
  2506. Pric: float64(item.Pric),
  2507. PatientId: record.PatientId,
  2508. PricUplmtAmt: item.PricUplmtAmt,
  2509. SelfpayProp: item.SelfpayProp,
  2510. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2511. OverlmtAmt: item.OverlmtAmt,
  2512. PreselfpayAmt: item.PreselfpayAmt,
  2513. BasMednFlag: item.BasMednFlag,
  2514. MedChrgitmType: item.MedChrgitmType,
  2515. HiNegoDrugFlag: item.HiNegoDrugFlag,
  2516. Status: 1,
  2517. Memo: item.Memo,
  2518. Mtime: time.Now().Unix(),
  2519. InscpScpAmt: item.InscpScpAmt,
  2520. DrtReimFlag: item.DrtReimFlag,
  2521. Ctime: time.Now().Unix(),
  2522. ListSpItemFlag: item.ListSpItemFlag,
  2523. ChldMedcFlag: item.ChldMedcFlag,
  2524. LmtUsedFlag: item.LmtUsedFlag,
  2525. ChrgitmLv: item.ChrgitmLv,
  2526. UserOrgId: adminUser.CurrentOrgId,
  2527. HisPatientId: record.ID,
  2528. OrderId: 0,
  2529. ProjectId: project_id,
  2530. Type: types,
  2531. SettleType: settle_accounts_type,
  2532. }
  2533. service.CreateOrderInfo(info)
  2534. }
  2535. }
  2536. err := service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  2537. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  2538. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  2539. if err == nil {
  2540. c.ServeSuccessJSON(map[string]interface{}{
  2541. "msg": "上传费用明细成功",
  2542. })
  2543. return
  2544. } else {
  2545. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2546. return
  2547. }
  2548. } else {
  2549. for _, subItem := range ress {
  2550. for _, item := range subItem.Output.Result {
  2551. temp := strings.Split(item.FeedetlSn, "-")
  2552. var advice_id int64 = 0
  2553. var project_id int64 = 0
  2554. var types int64 = 0
  2555. id, _ := strconv.ParseInt(temp[2], 10, 64)
  2556. types, _ = strconv.ParseInt(temp[1], 10, 64)
  2557. if temp[1] == "1" {
  2558. advice_id = id
  2559. project_id = 0
  2560. } else if temp[1] == "2" {
  2561. advice_id = 0
  2562. project_id = id
  2563. }
  2564. info := &models.HisOrderInfo{
  2565. OrderNumber: record.Number,
  2566. FeedetlSn: item.FeedetlSn,
  2567. UploadDate: time.Now().Unix(),
  2568. AdviceId: advice_id,
  2569. DetItemFeeSumamt: item.DetItemFeeSumamt,
  2570. Cnt: item.Cnt,
  2571. Pric: float64(item.Pric),
  2572. PatientId: record.PatientId,
  2573. PricUplmtAmt: item.PricUplmtAmt,
  2574. SelfpayProp: item.SelfpayProp,
  2575. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2576. OverlmtAmt: item.OverlmtAmt,
  2577. PreselfpayAmt: item.PreselfpayAmt,
  2578. BasMednFlag: item.BasMednFlag,
  2579. MedChrgitmType: item.MedChrgitmType,
  2580. HiNegoDrugFlag: item.HiNegoDrugFlag,
  2581. Status: 1,
  2582. Memo: item.Memo,
  2583. Mtime: time.Now().Unix(),
  2584. InscpScpAmt: item.InscpScpAmt,
  2585. DrtReimFlag: item.DrtReimFlag,
  2586. Ctime: time.Now().Unix(),
  2587. ListSpItemFlag: item.ListSpItemFlag,
  2588. ChldMedcFlag: item.ChldMedcFlag,
  2589. LmtUsedFlag: item.LmtUsedFlag,
  2590. ChrgitmLv: item.ChrgitmLv,
  2591. UserOrgId: adminUser.CurrentOrgId,
  2592. HisPatientId: record.ID,
  2593. ProjectId: project_id,
  2594. Type: types,
  2595. SettleType: settle_accounts_type,
  2596. }
  2597. service.CreateOrderInfo(info)
  2598. }
  2599. }
  2600. service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  2601. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  2602. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  2603. c.ServeSuccessJSON(map[string]interface{}{
  2604. "msg": "上传费用明细成功",
  2605. })
  2606. }
  2607. }
  2608. }
  2609. }
  2610. func (c *ZHHisApiController) ZHRefund() {
  2611. order_id, _ := c.GetInt64("order_id")
  2612. admin_user_id, _ := c.GetInt64("admin_user_id")
  2613. adminUser := c.GetAdminUserInfo()
  2614. var order models.HisOrder
  2615. order, _ = service.GetHisOrderByID(order_id)
  2616. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  2617. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2618. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2619. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2620. if config.IsOpen == 1 { //对接了医保,走医保流程
  2621. var result string
  2622. var requestLog string
  2623. if miConfig.MdtrtareaAdmvs == "150499" {
  2624. //请求内网数据
  2625. api := "http://172.16.13.254:9532/" + "nmyb/2305?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo + "&setl_id=" + order.SetlId +
  2626. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2627. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2628. resp, requestErr := http.Get(api)
  2629. if requestErr != nil {
  2630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2631. return
  2632. }
  2633. body, ioErr := ioutil.ReadAll(resp.Body)
  2634. if ioErr != nil {
  2635. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2637. return
  2638. }
  2639. var respJSON map[string]interface{}
  2640. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2641. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2643. return
  2644. }
  2645. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2646. result_byte, _ := json.Marshal(respJSON)
  2647. result = string(result_byte)
  2648. //saveLog(result, requestLog, "2404", "入院登记撤销")
  2649. saveLog(result, requestLog, "2305", "退费")
  2650. } else {
  2651. result, requestLog := service.Gdyb2305(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2652. saveLog(result, requestLog, "2305", "退费")
  2653. }
  2654. var dat map[string]interface{}
  2655. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2656. fmt.Println(dat)
  2657. } else {
  2658. fmt.Println(err)
  2659. }
  2660. userJSONBytes, _ := json.Marshal(dat)
  2661. var res ResultSixteen
  2662. var resSixteen ResultSixteen10265
  2663. if miConfig.Code == "H15049901371" {
  2664. if err := json.Unmarshal(userJSONBytes, &resSixteen); err != nil {
  2665. utils.ErrorLog("解析失败:%v", err)
  2666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2667. return
  2668. }
  2669. res.Cainfo = resSixteen.Cainfo
  2670. res.WarnMsg = resSixteen.WarnMsg
  2671. res.Output = resSixteen.Output
  2672. res.ErrMsg = resSixteen.ErrMsg
  2673. res.RespondTime = resSixteen.RespondTime
  2674. Infcode, _ := strconv.ParseInt(resSixteen.Infcode, 10, 64)
  2675. res.Infcode = Infcode
  2676. } else {
  2677. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2678. utils.ErrorLog("解析失败:%v", err)
  2679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2680. return
  2681. }
  2682. }
  2683. if res.Infcode == 0 {
  2684. err := service.UpdataOrderStatusThree(order_id, order.Number, adminUser.CurrentOrgId, "", result)
  2685. ////不同地区退费流程不一样,肇庆那边退费就包括撤销出院,内蒙古退费不包括撤销明细,所以下面需要根据不同情况进行判断
  2686. //if miConfig.UserOrgId == 10215 {
  2687. // record.OutHospitalStatus = 0
  2688. // service.CreateHospitalRecord(&record)
  2689. //}
  2690. service.UpdataOrderStatusByNumber(record.Number)
  2691. if err == nil {
  2692. ////当押金不为零时产生退费记录
  2693. if order.Decimal != 0 {
  2694. tmp := strconv.FormatInt(order.ID, 10)
  2695. err = service.MoneyIncrease(adminUser.CurrentOrgId, order.PatientId, tmp, order.Decimal)
  2696. if err != nil {
  2697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2698. return
  2699. }
  2700. }
  2701. c.ServeSuccessJSON(map[string]interface{}{
  2702. "msg": "退费成功",
  2703. })
  2704. } else {
  2705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2706. return
  2707. }
  2708. } else {
  2709. c.ServeSuccessJSON(map[string]interface{}{
  2710. "code": -10,
  2711. "msg": res.ErrMsg,
  2712. })
  2713. }
  2714. } else {
  2715. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  2716. if err == nil {
  2717. c.ServeSuccessJSON(map[string]interface{}{
  2718. "msg": "退费成功",
  2719. })
  2720. } else {
  2721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2722. return
  2723. }
  2724. }
  2725. }
  2726. func (c *ZHHisApiController) ZHRefundDetail() {
  2727. patient_id, _ := c.GetInt64("patient_id")
  2728. his_patient_id, _ := c.GetInt64("his_patient_id")
  2729. record_time := c.GetString("record_time")
  2730. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2731. //order_id, _ := c.GetInt64("order_id")
  2732. admin_user_id, _ := c.GetInt64("admin_user_id")
  2733. timeLayout := "2006-01-02"
  2734. loc, _ := time.LoadLocation("Local")
  2735. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2736. if err != nil {
  2737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2738. return
  2739. }
  2740. recordDateTime := theTime.Unix()
  2741. adminUser := c.GetAdminUserInfo()
  2742. theTimeTwo, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 23:59:59", loc)
  2743. if err != nil {
  2744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2745. return
  2746. }
  2747. recordDateTimeTwo := theTimeTwo.Unix()
  2748. //var prescriptions []*models.HisPrescription
  2749. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2750. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2751. if settle_accounts_type == 1 { //日结
  2752. record, _ := service.GetInHospitalRecord(his_patient_id)
  2753. infos, _ := service.GetZHHisUploadOrderInfo(adminUser.CurrentOrgId, patient_id, recordDateTime, recordDateTimeTwo, record.Number)
  2754. var isSuccess bool = true
  2755. for _, item := range infos {
  2756. var result string
  2757. var requestLog string
  2758. if miConfig.MdtrtareaAdmvs == "150499" {
  2759. //请求内网数据
  2760. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&feedetl_sn=" + item.FeedetlSn +
  2761. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2762. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "1"
  2763. resp, requestErr := http.Get(api)
  2764. if requestErr != nil {
  2765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2766. return
  2767. }
  2768. body, ioErr := ioutil.ReadAll(resp.Body)
  2769. if ioErr != nil {
  2770. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2772. return
  2773. }
  2774. var respJSON map[string]interface{}
  2775. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2776. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2778. return
  2779. }
  2780. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2781. result_byte, _ := json.Marshal(respJSON)
  2782. result = string(result_byte)
  2783. saveLog(result, requestLog, "2302", "日结退明细")
  2784. } else {
  2785. result, requestLog := service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, item.FeedetlSn, 1)
  2786. saveLog(result, requestLog, "2302", "日结退明细")
  2787. }
  2788. var dat map[string]interface{}
  2789. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2790. fmt.Println(dat)
  2791. } else {
  2792. fmt.Println(err)
  2793. }
  2794. userJSONBytes, _ := json.Marshal(dat)
  2795. var res2 ResultEmpty
  2796. var resEmpty10265 ResultEmpty10265
  2797. if miConfig.Code == "H15049901371" {
  2798. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2799. utils.ErrorLog("解析失败:%v", err)
  2800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2801. return
  2802. }
  2803. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2804. res2.Infcode = Infcode
  2805. res2.RespondTime = resEmpty10265.RespondTime
  2806. res2.ErrMsg = resEmpty10265.ErrMsg
  2807. res2.Output = resEmpty10265.Output
  2808. res2.WarnMsg = resEmpty10265.WarnMsg
  2809. } else {
  2810. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2811. utils.ErrorLog("解析失败:%v", err)
  2812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2813. return
  2814. }
  2815. }
  2816. if res2.Infcode == -1 {
  2817. isSuccess = false
  2818. }
  2819. }
  2820. if isSuccess {
  2821. err := service.UpDateOrderInfoStatus(patient_id, recordDateTime, adminUser.CurrentOrgId, recordDateTimeTwo)
  2822. if err != nil {
  2823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2824. return
  2825. }
  2826. err1 := service.UpDatePrescriptionOrderStatusTwo(patient_id, recordDateTime, adminUser.CurrentOrgId)
  2827. if err1 != nil {
  2828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2829. return
  2830. }
  2831. c.ServeSuccessJSON(map[string]interface{}{
  2832. "msg": "撤销明细成功",
  2833. })
  2834. }
  2835. } else {
  2836. //prescriptions, _ = service.GetZHMonthHisUploadPrescription(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2837. //var order models.HisOrder
  2838. //order, _ = service.GetHisOrderByID(order_id)
  2839. //record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  2840. var result string
  2841. var requestLog string
  2842. record, _ := service.GetInHospitalRecord(his_patient_id)
  2843. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2844. if config.IsOpen == 1 { //对接了医保,走医保流程
  2845. if miConfig.MdtrtareaAdmvs == "150499" {
  2846. //请求内网数据
  2847. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=0000" +
  2848. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2849. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "0"
  2850. resp, requestErr := http.Get(api)
  2851. if requestErr != nil {
  2852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2853. return
  2854. }
  2855. body, ioErr := ioutil.ReadAll(resp.Body)
  2856. if ioErr != nil {
  2857. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2859. return
  2860. }
  2861. var respJSON map[string]interface{}
  2862. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2863. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2865. return
  2866. }
  2867. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2868. result_byte, _ := json.Marshal(respJSON)
  2869. result = string(result_byte)
  2870. //saveLog(result, requestLog, "2302", "日结退明细")
  2871. } else {
  2872. result, requestLog = service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  2873. saveLog(result, requestLog, "2302", "月结退明细")
  2874. }
  2875. var dat map[string]interface{}
  2876. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2877. fmt.Println(dat)
  2878. } else {
  2879. fmt.Println(err)
  2880. }
  2881. userJSONBytes, _ := json.Marshal(dat)
  2882. var res2 ResultEmpty
  2883. var resEmpty10265 ResultEmpty10265
  2884. if miConfig.Code == "H15049901371" {
  2885. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2886. utils.ErrorLog("解析失败:%v", err)
  2887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2888. return
  2889. }
  2890. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2891. res2.Infcode = Infcode
  2892. res2.RespondTime = resEmpty10265.RespondTime
  2893. res2.ErrMsg = resEmpty10265.ErrMsg
  2894. res2.Output = resEmpty10265.Output
  2895. res2.WarnMsg = resEmpty10265.WarnMsg
  2896. } else {
  2897. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2898. utils.ErrorLog("解析失败:%v", err)
  2899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2900. return
  2901. }
  2902. }
  2903. if res2.Infcode == 0 {
  2904. err := service.UpdataHospitalOrderStatus(record.Number, adminUser.CurrentOrgId)
  2905. if err == nil {
  2906. c.ServeSuccessJSON(map[string]interface{}{
  2907. "msg": "撤销明细成功",
  2908. })
  2909. } else {
  2910. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2911. return
  2912. }
  2913. } else {
  2914. c.ServeSuccessJSON(map[string]interface{}{
  2915. "code": -10,
  2916. "msg": res2.ErrMsg,
  2917. })
  2918. }
  2919. }
  2920. }
  2921. }
  2922. func (this *ZHHisApiController) GetZHOutHospitalUnCheck() {
  2923. id, _ := this.GetInt64("id")
  2924. admin_user_id, _ := this.GetInt64("admin_user_id")
  2925. adminInfo := this.GetAdminUserInfo()
  2926. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2927. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  2928. record, _ := service.GetInHospitalRecord(id)
  2929. if record.ID == 0 {
  2930. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  2931. return
  2932. }
  2933. var result string
  2934. var requestLog string
  2935. if miConfig.MdtrtareaAdmvs == "150499" {
  2936. //请求内网数据
  2937. api := "http://172.16.13.254:9532/" + "nmyb/2405?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  2938. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  2939. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2940. fmt.Println(api)
  2941. resp, requestErr := http.Get(api)
  2942. if requestErr != nil {
  2943. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2944. return
  2945. }
  2946. body, ioErr := ioutil.ReadAll(resp.Body)
  2947. if ioErr != nil {
  2948. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2949. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2950. return
  2951. }
  2952. var respJSON map[string]interface{}
  2953. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2954. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2955. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2956. return
  2957. }
  2958. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2959. result_byte, _ := json.Marshal(respJSON)
  2960. result = string(result_byte)
  2961. } else {
  2962. result, requestLog = service.ZHGdyb2405(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2963. saveLog(result, requestLog, "2405", "出院登记撤销")
  2964. }
  2965. var dat map[string]interface{}
  2966. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2967. fmt.Println(dat)
  2968. } else {
  2969. fmt.Println(err)
  2970. }
  2971. userJSONBytes, _ := json.Marshal(dat)
  2972. var res ResultEmpty
  2973. var resEmpty10265 ResultEmpty10265
  2974. if miConfig.Code == "H15049901371" {
  2975. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2976. utils.ErrorLog("解析失败:%v", err)
  2977. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2978. return
  2979. }
  2980. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2981. res.Infcode = Infcode
  2982. res.RespondTime = resEmpty10265.RespondTime
  2983. res.ErrMsg = resEmpty10265.ErrMsg
  2984. res.Output = resEmpty10265.Output
  2985. res.WarnMsg = resEmpty10265.WarnMsg
  2986. } else {
  2987. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2988. utils.ErrorLog("解析失败:%v", err)
  2989. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2990. return
  2991. }
  2992. }
  2993. if res.Infcode == 0 {
  2994. record.OutHospitalStatus = 0
  2995. service.CreateHospitalRecord(&record)
  2996. service.UpdataOrderStatusByNumber(record.Number)
  2997. this.ServeSuccessJSON(map[string]interface{}{
  2998. "msg": "撤销出院成功",
  2999. })
  3000. } else {
  3001. this.ServeSuccessJSON(map[string]interface{}{
  3002. "failed_code": -10,
  3003. "msg": res.ErrMsg,
  3004. })
  3005. }
  3006. }
  3007. func (this *ZHHisApiController) GetZHInHospitalUnCheck() {
  3008. id, _ := this.GetInt64("id")
  3009. admin_user_id, _ := this.GetInt64("admin_user_id")
  3010. adminInfo := this.GetAdminUserInfo()
  3011. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  3012. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  3013. record, _ := service.GetInHospitalRecord(id)
  3014. if record.ID == 0 {
  3015. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  3016. return
  3017. }
  3018. var result string
  3019. var requestLog string
  3020. orders, _ := service.GetHisOrderInfoByNumber(record.Number)
  3021. if len(orders) > 0 { //判断是否上传过明细,有的话需要退明细,后撤销入院
  3022. if miConfig.MdtrtareaAdmvs == "150499" {
  3023. //请求内网数据
  3024. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=" + "0000" +
  3025. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  3026. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=0"
  3027. resp, requestErr := http.Get(api)
  3028. if requestErr != nil {
  3029. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3030. return
  3031. }
  3032. body, ioErr := ioutil.ReadAll(resp.Body)
  3033. if ioErr != nil {
  3034. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3035. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3036. return
  3037. }
  3038. var respJSON map[string]interface{}
  3039. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3040. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3041. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3042. return
  3043. }
  3044. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3045. result_byte, _ := json.Marshal(respJSON)
  3046. result = string(result_byte)
  3047. saveLog(result, requestLog, "2302", "月结退明细")
  3048. } else {
  3049. result, requestLog = service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  3050. saveLog(result, requestLog, "2302", "月结退明细")
  3051. }
  3052. var dat map[string]interface{}
  3053. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3054. fmt.Println(dat)
  3055. } else {
  3056. fmt.Println(err)
  3057. }
  3058. userJSONBytes, _ := json.Marshal(dat)
  3059. var res2 ResultEmpty
  3060. var resEmpty10265 ResultEmpty10265
  3061. if miConfig.Code == "H15049901371" {
  3062. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  3063. utils.ErrorLog("解析失败:%v", err)
  3064. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3065. return
  3066. }
  3067. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  3068. res2.Infcode = Infcode
  3069. res2.RespondTime = resEmpty10265.RespondTime
  3070. res2.ErrMsg = resEmpty10265.ErrMsg
  3071. res2.Output = resEmpty10265.Output
  3072. res2.WarnMsg = resEmpty10265.WarnMsg
  3073. } else {
  3074. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  3075. utils.ErrorLog("解析失败:%v", err)
  3076. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3077. return
  3078. }
  3079. }
  3080. if res2.Infcode == 0 {
  3081. service.UpdataHospitalOrderStatus(record.Number, adminInfo.CurrentOrgId)
  3082. var result string
  3083. var requestLog string
  3084. if miConfig.MdtrtareaAdmvs == "150499" {
  3085. //请求内网数据
  3086. api := "http://172.16.13.254:9532/" + "nmyb/2404?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  3087. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  3088. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3089. resp, requestErr := http.Get(api)
  3090. if requestErr != nil {
  3091. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3092. return
  3093. }
  3094. body, ioErr := ioutil.ReadAll(resp.Body)
  3095. if ioErr != nil {
  3096. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3097. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3098. return
  3099. }
  3100. var respJSON map[string]interface{}
  3101. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3102. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3103. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3104. return
  3105. }
  3106. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3107. result_byte, _ := json.Marshal(respJSON)
  3108. result = string(result_byte)
  3109. } else {
  3110. result, requestLog = service.ZHGdyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  3111. saveLog(result, requestLog, "2404", "入院登记撤销")
  3112. }
  3113. var dat map[string]interface{}
  3114. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3115. fmt.Println(dat)
  3116. } else {
  3117. fmt.Println(err)
  3118. }
  3119. userJSONBytes, _ := json.Marshal(dat)
  3120. var res ResultEmpty
  3121. var resEmpty10265 ResultEmpty10265
  3122. if miConfig.Code == "H15049901371" {
  3123. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  3124. utils.ErrorLog("解析失败:%v", err)
  3125. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3126. return
  3127. }
  3128. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  3129. res.Infcode = Infcode
  3130. res.RespondTime = resEmpty10265.RespondTime
  3131. res.ErrMsg = resEmpty10265.ErrMsg
  3132. res.Output = resEmpty10265.Output
  3133. res.WarnMsg = resEmpty10265.WarnMsg
  3134. } else {
  3135. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3136. utils.ErrorLog("解析失败:%v", err)
  3137. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3138. return
  3139. }
  3140. }
  3141. if res.Infcode == 0 {
  3142. record.Status = 0
  3143. service.CreateHospitalRecord(&record)
  3144. this.ServeSuccessJSON(map[string]interface{}{
  3145. "msg": "撤销入院成功",
  3146. })
  3147. } else {
  3148. this.ServeSuccessJSON(map[string]interface{}{
  3149. "failed_code": -10,
  3150. "msg": res.ErrMsg,
  3151. })
  3152. }
  3153. } else {
  3154. this.ServeSuccessJSON(map[string]interface{}{
  3155. "code": -10,
  3156. "msg": res2.ErrMsg,
  3157. })
  3158. }
  3159. } else { //没有上传过明细的,直接撤销入院
  3160. var result string
  3161. var requestLog string
  3162. if miConfig.MdtrtareaAdmvs == "150499" {
  3163. //请求内网数据
  3164. api := "http://172.16.13.254:9532/" + "nmyb/2404?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  3165. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  3166. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3167. resp, requestErr := http.Get(api)
  3168. if requestErr != nil {
  3169. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3170. return
  3171. }
  3172. body, ioErr := ioutil.ReadAll(resp.Body)
  3173. if ioErr != nil {
  3174. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3175. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3176. return
  3177. }
  3178. var respJSON map[string]interface{}
  3179. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3180. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3181. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3182. return
  3183. }
  3184. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3185. result_byte, _ := json.Marshal(respJSON)
  3186. result = string(result_byte)
  3187. } else {
  3188. result, requestLog = service.ZHGdyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  3189. saveLog(result, requestLog, "2404", "入院登记撤销")
  3190. }
  3191. var dat map[string]interface{}
  3192. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3193. fmt.Println(dat)
  3194. } else {
  3195. fmt.Println(err)
  3196. }
  3197. userJSONBytes, _ := json.Marshal(dat)
  3198. var res ResultEmpty
  3199. var resEmpty10265 ResultEmpty10265
  3200. if miConfig.Code == "H15049901371" {
  3201. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  3202. utils.ErrorLog("解析失败:%v", err)
  3203. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3204. return
  3205. }
  3206. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  3207. res.Infcode = Infcode
  3208. res.RespondTime = resEmpty10265.RespondTime
  3209. res.ErrMsg = resEmpty10265.ErrMsg
  3210. res.Output = resEmpty10265.Output
  3211. res.WarnMsg = resEmpty10265.WarnMsg
  3212. } else {
  3213. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3214. utils.ErrorLog("解析失败:%v", err)
  3215. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3216. return
  3217. }
  3218. }
  3219. if res.Infcode == 0 {
  3220. record.Status = 0
  3221. service.CreateHospitalRecord(&record)
  3222. this.ServeSuccessJSON(map[string]interface{}{
  3223. "msg": "撤销入院成功",
  3224. })
  3225. } else {
  3226. this.ServeSuccessJSON(map[string]interface{}{
  3227. "failed_code": -10,
  3228. "msg": res.ErrMsg,
  3229. })
  3230. }
  3231. }
  3232. }
  3233. func saveLog(result string, request string, infno string, desc string) {
  3234. org_id, _ := beego.AppConfig.Int64("org_id")
  3235. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  3236. dir := miConfig.OrgName + "日志"
  3237. utils.Mkdir(dir)
  3238. month := time.Unix(1557042972, 0).Format("1")
  3239. year := time.Now().Format("2006")
  3240. month = time.Now().Format("01")
  3241. day := time.Now().Format("02")
  3242. hour := time.Now().Format("15")
  3243. min := time.Now().Format("04")
  3244. sec := time.Now().Format("05")
  3245. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  3246. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  3247. file_name := file + ".txt"
  3248. file_path := miConfig.OrgName + "日志" + "/" + file_name
  3249. exist, _ := utils.PathExists(file_path)
  3250. if exist { //存在
  3251. fmt.Println("存在")
  3252. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  3253. if err != nil {
  3254. fmt.Println("read fail")
  3255. }
  3256. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  3257. n, _ := f.Seek(0, 2)
  3258. _, err = f.WriteAt([]byte(content), n)
  3259. } else { //不存在
  3260. fmt.Println("文件不存在,创建文件")
  3261. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  3262. defer f.Close()
  3263. if err != nil {
  3264. } else {
  3265. _, err = f.Write([]byte("记录日志"))
  3266. }
  3267. }
  3268. }
  3269. type Charset string
  3270. const (
  3271. UTF8 = Charset("UTF-8")
  3272. GB18030 = Charset("GB18030")
  3273. )
  3274. func ConvertToString(src string, srcCode string, tagCode string) string {
  3275. srcCoder := mahonia.NewDecoder(srcCode)
  3276. srcResult := srcCoder.ConvertString(src)
  3277. tagCoder := mahonia.NewDecoder(tagCode)
  3278. _, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
  3279. result := string(cdata)
  3280. return result
  3281. }
  3282. type ELeData struct {
  3283. Data struct {
  3284. IdNo string `json:"idNo"`
  3285. IdType string `json:"idType"`
  3286. UserName string `json:"userName"`
  3287. EcToken string `json:"ecToken"`
  3288. InsuOrg string `json:"insuOrg"`
  3289. Gender string `json:"gender"`
  3290. Birthday string `json:"birthday"`
  3291. Nationality string `json:"nationality"`
  3292. Email string `json:"email"`
  3293. Extra string `json:"extra"`
  3294. } `json:"data"`
  3295. Code int `json:"code"`
  3296. Message string `json:"message"`
  3297. }
  3298. func (c *ZHHisApiController) ReadCard() {
  3299. id_card_type, _ := c.GetInt64("id_card_type")
  3300. admin_user_id, _ := c.GetInt64("admin_user_id")
  3301. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  3302. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  3303. var api string
  3304. api = "http://172.16.13.254:9532/" + "nmyb/readcard?" + "fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName +
  3305. "&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
  3306. fmt.Println(api)
  3307. resp, requestErr := http.Get(api)
  3308. if requestErr != nil {
  3309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3310. return
  3311. }
  3312. body, ioErr := ioutil.ReadAll(resp.Body)
  3313. if ioErr != nil {
  3314. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3316. return
  3317. }
  3318. var respJSON map[string]interface{}
  3319. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3320. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3322. return
  3323. }
  3324. var status string
  3325. status = respJSON["data"].(map[string]interface{})["status"].(string)
  3326. card_type := respJSON["data"].(map[string]interface{})["type"].(string)
  3327. //console.log()
  3328. fmt.Println("type===")
  3329. fmt.Println(card_type)
  3330. var token string
  3331. var res ResultTwo //1101结果
  3332. var res10265 ResultTwo10265 //1101结果
  3333. var card_info string //卡信息
  3334. var busi_card_info string
  3335. card_info = respJSON["data"].(map[string]interface{})["card_info"].(string)
  3336. busi_card_info = respJSON["data"].(map[string]interface{})["busi_card_info"].(string)
  3337. if status == "0" { //读卡成功
  3338. if card_type == "1" {
  3339. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  3340. result, _ := json.Marshal(respJSON)
  3341. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  3342. utils.ErrorLog("解析失败:%v", err)
  3343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3344. return
  3345. }
  3346. res.ErrMsg = res10265.ErrMsg
  3347. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  3348. res.Infcode = infocode
  3349. res.Output = res10265.Output
  3350. res.InfRefmsgid = res10265.InfRefmsgid
  3351. } else {
  3352. //var card_info string //卡信息
  3353. //var busi_card_info string
  3354. token = respJSON["data"].(map[string]interface{})["token"].(string)
  3355. //busi_card_info = respJSON["data"].(map[string]interface{})["busi_card_info"].(string)
  3356. //fmt.Println(card_info)
  3357. //fmt.Println(busi_card_info)
  3358. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  3359. result, _ := json.Marshal(respJSON)
  3360. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  3361. utils.ErrorLog("解析失败:%v", err)
  3362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3363. return
  3364. }
  3365. res.ErrMsg = res10265.ErrMsg
  3366. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  3367. res.Infcode = infocode
  3368. res.Output = res10265.Output
  3369. res.InfRefmsgid = res10265.InfRefmsgid
  3370. }
  3371. if res.Infcode == 0 {
  3372. var insutypes []string
  3373. var insutype string
  3374. var is390 int = 0
  3375. var is310 int = 0
  3376. for _, item := range res.Output.Iinfo {
  3377. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  3378. insutypes = append(insutypes, item.Insutype)
  3379. }
  3380. }
  3381. if len(insutypes) == 1 {
  3382. insutype = insutypes[0]
  3383. } else {
  3384. for _, i := range insutypes {
  3385. if i == "390" {
  3386. is390 = 1
  3387. }
  3388. if i == "310" {
  3389. is310 = 1
  3390. }
  3391. }
  3392. }
  3393. if is390 == 1 {
  3394. insutype = "390"
  3395. }
  3396. if is310 == 1 {
  3397. insutype = "310"
  3398. }
  3399. if len(insutypes) == 0 {
  3400. insutype = "310"
  3401. }
  3402. patient, err := service.GetPatientByIDCard(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  3403. if err == gorm.ErrRecordNotFound {
  3404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  3405. return
  3406. } else if err != nil {
  3407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3408. return
  3409. } else {
  3410. if card_type == "1" {
  3411. bas := strings.Split(card_info, "|")
  3412. basNumber := bas[2]
  3413. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  3414. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  3415. infoStr := string(Iinfos)
  3416. idetinfoStr := string(Idetinfos)
  3417. psn := &models.HisPsn{
  3418. PsnNo: res.Output.Baseinfo.PsnNo,
  3419. Age: res.Output.Baseinfo.Age,
  3420. PatientId: patient.ID,
  3421. Certno: res.Output.Baseinfo.Certno,
  3422. Brdy: res.Output.Baseinfo.Brdy,
  3423. Gend: res.Output.Baseinfo.Gend,
  3424. Naty: res.Output.Baseinfo.Naty,
  3425. PsnCertType: res.Output.Baseinfo.PsnCertType,
  3426. PsnName: res.Output.Baseinfo.PsnName,
  3427. Idetinfo: idetinfoStr,
  3428. Insuinfo: infoStr,
  3429. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3430. CardInfo: card_info,
  3431. VerifyNumber: busi_card_info,
  3432. }
  3433. service.CreateHisPsn(psn)
  3434. c.ServeSuccessJSON(map[string]interface{}{
  3435. "patient": patient,
  3436. "number": basNumber,
  3437. "info": res,
  3438. "insutype": insutype,
  3439. })
  3440. } else {
  3441. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  3442. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  3443. infoStr := string(Iinfos)
  3444. idetinfoStr := string(Idetinfos)
  3445. psn := &models.HisPsn{
  3446. PsnNo: res.Output.Baseinfo.PsnNo,
  3447. Age: res.Output.Baseinfo.Age,
  3448. PatientId: patient.ID,
  3449. Certno: res.Output.Baseinfo.Certno,
  3450. Brdy: res.Output.Baseinfo.Brdy,
  3451. Gend: res.Output.Baseinfo.Gend,
  3452. Naty: res.Output.Baseinfo.Naty,
  3453. PsnCertType: res.Output.Baseinfo.PsnCertType,
  3454. PsnName: res.Output.Baseinfo.PsnName,
  3455. Idetinfo: idetinfoStr,
  3456. Insuinfo: infoStr,
  3457. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3458. CardInfo: card_info,
  3459. VerifyNumber: token,
  3460. }
  3461. service.CreateHisPsn(psn)
  3462. c.ServeSuccessJSON(map[string]interface{}{
  3463. "patient": patient,
  3464. "number": token,
  3465. "info": res,
  3466. "insutype": insutype,
  3467. })
  3468. }
  3469. }
  3470. } else {
  3471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  3472. return
  3473. }
  3474. } else { //读卡失败
  3475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  3476. return
  3477. }
  3478. }
  3479. var initFlag int64 = 0
  3480. func (c *ZHHisApiController) TestGetBasBaseInit() {
  3481. DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
  3482. Iinit := DllDef.MustFindProc("Init")
  3483. //miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  3484. str := make([]byte, 2048)
  3485. inputData := make(map[string]interface{})
  3486. inputData["IP"] = "10.144.211.75"
  3487. inputData["PORT"] = 7021
  3488. inputData["TIMEOUT"] = 180
  3489. inputData["LOG_PATH"] = "C:\\log\\"
  3490. //inputData["SFZ_DRIVER_TYPE"] = 0
  3491. inputData["URL"] = "/call1"
  3492. bytesData, _ := json.Marshal(inputData)
  3493. fmt.Println(inputData)
  3494. fmt.Println(bytesData)
  3495. ret, _, err := Iinit.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&str[0])))
  3496. if ret != 0 {
  3497. fmt.Println("SSCard的报错原因:", err)
  3498. fmt.Println("SSCard的运算结果为:", ret)
  3499. fmt.Println("SSCard的返回结果为:", string(str))
  3500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  3501. return
  3502. }
  3503. fmt.Println("SSCard的返回结果为:", string(str))
  3504. result := int(ret)
  3505. fmt.Println("SSCard的运算结果为1:", result)
  3506. //initFlag = 1
  3507. return
  3508. }
  3509. func (c *ZHHisApiController) GetSFZBaseInfo() string {
  3510. DllDef := syscall.MustLoadDLL("SSCard.dll")
  3511. readCard := DllDef.MustFindProc("ReadSFZ")
  3512. if readCard == nil {
  3513. fmt.Println("readcard is nil")
  3514. readCard = DllDef.MustFindProc("ReadSFZ")
  3515. }
  3516. str := make([]byte, 256)
  3517. str1 := make([]byte, 256)
  3518. r, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  3519. fmt.Println(r)
  3520. return string(str)
  3521. }
  3522. func (c *ZHHisApiController) GetBasBaseInfo(fixmedins_code string, mdtrtarea_admvs string, opter_name string, opter_id string, fixmedins_name string) string {
  3523. DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
  3524. readCard := DllDef.MustFindProc("ReadCardBas")
  3525. fmt.Println(readCard)
  3526. fmt.Println("!!!!!")
  3527. month := time.Unix(1557042972, 0).Format("1")
  3528. year := time.Now().Format("2006")
  3529. month = time.Now().Format("01")
  3530. day := time.Now().Format("02")
  3531. hour := time.Now().Format("15")
  3532. min := time.Now().Format("04")
  3533. sec := time.Now().Format("05")
  3534. msec := time.Now().Format("000")
  3535. timestamp := time.Now().Unix()
  3536. tempTime := time.Unix(timestamp, 0)
  3537. //timeFormat := tempTime.Format("20060102150405")
  3538. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  3539. //randNum := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000)
  3540. inputData := make(map[string]interface{})
  3541. inputData["infno"] = "1199"
  3542. //inputData["msgid"] = "7021"
  3543. inputData["msgid"] = fixmedins_code + year + month + day + hour + min + sec + msec + "0" // 发送方报文 ID
  3544. inputData["mdtrtarea_admvs"] = mdtrtarea_admvs // 发送方报文 ID
  3545. inputData["recer_sys_code"] = "01"
  3546. inputData["infver"] = "V1.0"
  3547. inputData["opter_type"] = "1"
  3548. inputData["opter"] = opter_id
  3549. inputData["opter_name"] = opter_name
  3550. inputData["inf_time"] = timeFormatOne
  3551. inputData["fixmedins_code"] = fixmedins_code
  3552. inputData["fixmedins_name"] = fixmedins_name
  3553. inputData["dev_no"] = ""
  3554. inputData["dev_safe_info"] = ""
  3555. inputData["cainfo"] = ""
  3556. inputData["signtype"] = ""
  3557. inputData["sign_no"] = ""
  3558. bytesData, _ := json.Marshal(inputData)
  3559. fmt.Println(string(bytesData))
  3560. pBusiCardInfo := make([]byte, 8192)
  3561. ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
  3562. fmt.Println(ret2)
  3563. fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
  3564. fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
  3565. if ret2 != 0 {
  3566. return ""
  3567. }
  3568. return DeleteExtraSpace(string(pBusiCardInfo))
  3569. }
  3570. func DeleteExtraSpace(s string) string {
  3571. //删除字符串中的多余空格,有多个空格时,仅保留一个空格
  3572. s1 := strings.Replace(s, " ", " ", -1) //替换tab为空格
  3573. regstr := "\\s{2,}" //两个及两个以上空格的正则表达式
  3574. reg, _ := regexp.Compile(regstr) //编译正则表达式
  3575. s2 := make([]byte, len(s1)) //定义字符数组切片
  3576. copy(s2, s1) //将字符串复制到切片
  3577. spc_index := reg.FindStringIndex(string(s2)) //在字符串中搜索
  3578. for len(spc_index) > 0 { //找到适配项
  3579. s2 = append(s2[:spc_index[0]+1], s2[spc_index[1]:]...) //删除多余空格
  3580. spc_index = reg.FindStringIndex(string(s2)) //继续在字符串中搜索
  3581. }
  3582. return string(s2)
  3583. }
  3584. func (c *ZHHisApiController) GetELeInfo(code string, operator_id string, operator_name string) (string, string) {
  3585. DllDef := syscall.MustLoadDLL("NationECCode.dll")
  3586. readCard := DllDef.MustFindProc("NationEcTrans")
  3587. fmt.Println(readCard)
  3588. fmt.Println("!!!!!")
  3589. pBusiCardInfo := make([]byte, 8192)
  3590. input := make(map[string]interface{})
  3591. inputData := make(map[string]interface{})
  3592. inputData["orgId"] = code
  3593. inputData["businessType"] = "01101"
  3594. inputData["operatorId"] = operator_id
  3595. inputData["operatorName"] = operator_name
  3596. inputData["officeId"] = "001"
  3597. inputData["officeName"] = "血透室"
  3598. inputData["deviceType"] = ""
  3599. input["data"] = inputData
  3600. input["orgId"] = code
  3601. input["transType"] = "ec.query"
  3602. bytesData, _ := json.Marshal(input)
  3603. gdyb_url := beego.AppConfig.String("gdyb_url")
  3604. url := gdyb_url + "/localcfc/api/hsecfc/localQrCodeQuery"
  3605. ret2, _, _ := readCard.Call(StrPtr(url), StrPtr(string(bytesData)), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
  3606. fmt.Println(ret2)
  3607. fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
  3608. fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
  3609. if ret2 != 0 {
  3610. return "", ""
  3611. }
  3612. return DeleteExtraSpace(""), DeleteExtraSpace(string(pBusiCardInfo))
  3613. }
  3614. func StrPtr(s string) uintptr {
  3615. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  3616. }
  3617. func Remove0000(s string) string {
  3618. str := make([]rune, 0, len(s))
  3619. for _, v := range []rune(s) {
  3620. if v == 0 {
  3621. continue
  3622. }
  3623. str = append(str, v)
  3624. }
  3625. return string(str)
  3626. }
  3627. func IntPtr(n int) uintptr {
  3628. return uintptr(n)
  3629. }