zh_his_api_controller.go 115KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387
  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. }
  483. func (c *ZHHisApiController) ClearSettle() {
  484. order_id, _ := c.GetInt64("order_id")
  485. admin_user_id, _ := c.GetInt64("admin_user_id")
  486. adminUser := c.GetAdminUserInfo()
  487. var order models.HisOrder
  488. order, _ = service.GetHisOrderByID(order_id)
  489. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  490. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  491. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  492. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  493. if config.IsOpen == 1 { //对接了医保,走医保流程
  494. var result string
  495. var requestLog string
  496. result, requestLog = service.Gdyb90306(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  497. saveLog(result, requestLog, "90306", "撤销结算清单")
  498. var dat map[string]interface{}
  499. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  500. fmt.Println(dat)
  501. } else {
  502. fmt.Println(err)
  503. }
  504. userJSONBytes, _ := json.Marshal(dat)
  505. var res ResultSix
  506. //var resSixteen ResultSixteen10265
  507. if miConfig.Code == "H15049901371" {
  508. //if err := json.Unmarshal(userJSONBytes, &resSixteen); err != nil {
  509. // utils.ErrorLog("解析失败:%v", err)
  510. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  511. // return
  512. //}
  513. //res.Cainfo = resSixteen.Cainfo
  514. //res.WarnMsg = resSixteen.WarnMsg
  515. //res.Output = resSixteen.Output
  516. //res.ErrMsg = resSixteen.ErrMsg
  517. //res.RespondTime = resSixteen.RespondTime
  518. //Infcode, _ := strconv.ParseInt(resSixteen.Infcode, 10, 64)
  519. //res.Infcode = Infcode
  520. } else {
  521. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  522. utils.ErrorLog("解析失败:%v", err)
  523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  524. return
  525. }
  526. }
  527. if res.Infcode == 0 {
  528. c.ServeSuccessJSON(map[string]interface{}{
  529. "msg": "撤销成功",
  530. })
  531. } else {
  532. c.ServeSuccessJSON(map[string]interface{}{
  533. "code": -10,
  534. "msg": res.ErrMsg,
  535. })
  536. }
  537. }
  538. }
  539. func (c *ZHHisApiController) GetZHPatientInfo() {
  540. id_card_no := c.GetString("id_card_no")
  541. admin_user_id, _ := c.GetInt64("admin_user_id")
  542. patient, _ := service.GetPatientByIDCard(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  543. if patient.ID == 0 {
  544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  545. return
  546. }
  547. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  548. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  549. config, _ := service.GetMedicalInsuranceConfig(c.GetAdminUserInfo().CurrentOrgId)
  550. if config.IsOpen == 1 {
  551. var result string
  552. var request_log string
  553. var result_log string
  554. if miConfig.MdtrtareaAdmvs == "150499" {
  555. //请求内网数据
  556. api := "http://172.16.13.254:9532/" + "nmyb/1101?cert_no=" + patient.IdCardNo +
  557. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  558. "&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
  559. resp, requestErr := http.Get(api)
  560. if requestErr != nil {
  561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  562. return
  563. }
  564. body, ioErr := ioutil.ReadAll(resp.Body)
  565. if ioErr != nil {
  566. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  568. return
  569. }
  570. var respJSON map[string]interface{}
  571. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  572. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  574. return
  575. }
  576. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  577. result_byte, _ := json.Marshal(respJSON)
  578. result = string(result_byte)
  579. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  580. } else {
  581. 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)
  582. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  583. }
  584. //result := service.Gdyb1101A(id_card_no, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, patient.Name)
  585. var dat map[string]interface{}
  586. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  587. fmt.Println(dat)
  588. } else {
  589. fmt.Println(err)
  590. }
  591. userJSONBytes, _ := json.Marshal(dat)
  592. var res ResultTwo
  593. var resTwo10265 ResultTwo10265
  594. if miConfig.Code == "H15049901371" {
  595. if err := json.Unmarshal(userJSONBytes, &resTwo10265); err != nil {
  596. utils.ErrorLog("解析失败:%v", err)
  597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  598. return
  599. }
  600. Infcode, _ := strconv.ParseInt(resTwo10265.Infcode, 10, 64)
  601. res.Infcode = Infcode
  602. res.ErrMsg = resTwo10265.ErrMsg
  603. res.Output = resTwo10265.Output
  604. res.InfRefmsgid = resTwo10265.InfRefmsgid
  605. res.RespondTime = resTwo10265.RespondTime
  606. res.WarnInfo = resTwo10265.WarnInfo
  607. } else {
  608. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  609. utils.ErrorLog("解析失败:%v", err)
  610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  611. return
  612. }
  613. }
  614. var insutypes []string
  615. var insutype string
  616. var is390 int = 0
  617. var is310 int = 0
  618. for _, item := range res.Output.Iinfo {
  619. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  620. insutypes = append(insutypes, item.Insutype)
  621. }
  622. }
  623. if len(insutypes) == 1 {
  624. insutype = insutypes[0]
  625. } else {
  626. for _, i := range insutypes {
  627. if i == "390" {
  628. is390 = 1
  629. }
  630. if i == "310" {
  631. is310 = 1
  632. }
  633. }
  634. }
  635. if is390 == 1 {
  636. insutype = "390"
  637. }
  638. if is310 == 1 {
  639. insutype = "310"
  640. }
  641. if len(insutypes) == 0 {
  642. insutype = "310"
  643. }
  644. if res.Infcode != 0 {
  645. c.ServeSuccessJSON(map[string]interface{}{
  646. "failed_code": -10,
  647. "msg": res.ErrMsg,
  648. })
  649. } else {
  650. c.ServeSuccessJSON(map[string]interface{}{
  651. "failed_code": 0,
  652. "info": res,
  653. "insutype": insutype,
  654. })
  655. }
  656. }
  657. }
  658. func (c *ZHHisApiController) GetZHInHospitalCheck() {
  659. id, _ := c.GetInt64("id")
  660. record_time := c.GetString("record_time")
  661. name := c.GetString("name")
  662. phone := c.GetString("phone")
  663. id_card_type, _ := c.GetInt64("id_card_type")
  664. certificates, _ := c.GetInt64("certificates")
  665. id_card_no := c.GetString("id_card_no")
  666. doctor, _ := c.GetInt64("doctor")
  667. admin_user_id, _ := c.GetInt64("admin_user_id")
  668. department, _ := c.GetInt64("department")
  669. adm_bed, _ := c.GetInt64("adm_bed")
  670. diagnosis_ids := c.GetString("diagnosis")
  671. sick_type, _ := c.GetInt64("sick_type")
  672. start_time := c.GetString("start_time")
  673. insuplc_admdvs := c.GetString("insuplc_admdvs")
  674. balance_accounts_type, _ := c.GetInt64("balance_accounts_type")
  675. social_type, _ := c.GetInt64("social_type")
  676. psn_type, _ := c.GetInt64("psn_type")
  677. //reg_type, _ := c.GetInt64("p_type")
  678. med_type, _ := c.GetInt64("med_type")
  679. diagnosis_ids_arr := strings.Split(diagnosis_ids, "-")
  680. timeLayout := "2006-01-02"
  681. loc, _ := time.LoadLocation("Local")
  682. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  683. if err != nil {
  684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  685. return
  686. }
  687. recordDateTime := theTime.Unix()
  688. adminInfo := c.GetAdminUserInfo()
  689. record, _ := service.GetLastHospitalRecord(id, adminInfo.CurrentOrgId)
  690. if record.ID != 0 {
  691. if record.InHospitalStatus == 1 && record.OutHospitalStatus != 1 {
  692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalExistDataException)
  693. return
  694. }
  695. }
  696. var patient service.Patients
  697. if id == 0 {
  698. patient, _ = service.GetPatientByIDCard(id_card_no, adminInfo.CurrentOrgId)
  699. } else {
  700. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  701. }
  702. diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  703. sickConfig, _ := service.FindSickById(sick_type)
  704. departmentInfo, _ := service.GetDepartMentDetail(department)
  705. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  706. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  707. var result string
  708. var request_log string
  709. var result_log string
  710. var res2 ResultTwo
  711. var resTwo10265 ResultTwo10265
  712. psn_info, _ := service.GetPsnByPatientId(patient.ID)
  713. if miConfig.MdtrtareaAdmvs == "150499" {
  714. if id_card_type == 2 {
  715. mdtrt_cert_no := ""
  716. card_sn := ""
  717. if record.IdCardType == 1 {
  718. bas := strings.Split(psn_info.CardInfo, "|")
  719. cardNumber := bas[2]
  720. mdtrt_cert_no = cardNumber
  721. card_sn = bas[3]
  722. } else {
  723. mdtrt_cert_no = id_card_no
  724. }
  725. //请求内网数据
  726. api := "http://172.16.13.254:9532/" + "nmyb/1101?cert_no=" + mdtrt_cert_no +
  727. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  728. "&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
  729. resp, requestErr := http.Get(api)
  730. if requestErr != nil {
  731. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  732. return
  733. }
  734. body, ioErr := ioutil.ReadAll(resp.Body)
  735. if ioErr != nil {
  736. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  738. return
  739. }
  740. var respJSON map[string]interface{}
  741. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  742. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  744. return
  745. }
  746. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  747. result_byte, _ := json.Marshal(respJSON)
  748. result = string(result_byte)
  749. var dat map[string]interface{}
  750. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  751. fmt.Println(dat)
  752. } else {
  753. fmt.Println(err)
  754. }
  755. userJSONBytes, _ := json.Marshal(dat)
  756. if err := json.Unmarshal(userJSONBytes, &resTwo10265); err != nil {
  757. utils.ErrorLog("解析失败:%v", err)
  758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  759. return
  760. }
  761. Infcode, _ := strconv.ParseInt(resTwo10265.Infcode, 10, 64)
  762. res2.Infcode = Infcode
  763. res2.ErrMsg = resTwo10265.ErrMsg
  764. res2.Output = resTwo10265.Output
  765. res2.InfRefmsgid = resTwo10265.InfRefmsgid
  766. res2.RespondTime = resTwo10265.RespondTime
  767. res2.WarnInfo = resTwo10265.WarnInfo
  768. } else {
  769. res2.Infcode = 0
  770. res2.Output.Baseinfo.PsnNo = psn_info.PsnNo
  771. res2.Output.Baseinfo.Certno = patient.IdCardNo
  772. }
  773. } else {
  774. 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)
  775. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  776. }
  777. doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor)
  778. deviceNumber, _ := service.GetDeviceNumberByID(adm_bed, adminInfo.CurrentOrgId)
  779. if miConfig.MdtrtareaAdmvs != "150499" {
  780. var dat map[string]interface{}
  781. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  782. fmt.Println(dat)
  783. } else {
  784. fmt.Println(err)
  785. }
  786. userJSONBytes, _ := json.Marshal(dat)
  787. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  788. utils.ErrorLog("解析失败:%v", err)
  789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  790. return
  791. }
  792. }
  793. var infoStr string
  794. if miConfig.MdtrtareaAdmvs == "150499" {
  795. if id_card_type == 2 {
  796. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  797. infoStr = string(Iinfos)
  798. } else {
  799. infoStr = psn_info.Insuinfo
  800. }
  801. } else {
  802. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  803. infoStr = string(Iinfos)
  804. }
  805. var rf []*ResultFive
  806. json.Unmarshal([]byte(infoStr), &rf)
  807. var insutypes []*ResultFive
  808. var insutype string
  809. var is390 int = 0
  810. var is310 int = 0
  811. for _, item := range rf {
  812. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  813. insutypes = append(insutypes, item)
  814. }
  815. }
  816. if len(insutypes) == 1 {
  817. insutype = insutypes[0].Insutype
  818. //insuplc_admdvs = insutypes[0].InsuplcAdmdvs
  819. } else {
  820. for _, i := range insutypes {
  821. if i.Insutype == "390" {
  822. is390 = 1
  823. }
  824. if i.Insutype == "310" {
  825. is310 = 1
  826. }
  827. }
  828. }
  829. if is390 == 1 {
  830. insutype = "390"
  831. }
  832. if is310 == 1 {
  833. insutype = "310"
  834. }
  835. if len(insutypes) == 0 {
  836. insutype = "310"
  837. }
  838. if len(insutypes) == 2 {
  839. insutype = strconv.FormatInt(social_type, 10)
  840. }
  841. //for _, item := range rf {
  842. // if item.Insutype == insutype {
  843. // insuplc_admdvs = item.InsuplcAdmdvs
  844. // }
  845. //}
  846. if res2.Infcode == 0 {
  847. //var insutypes []string
  848. //
  849. //var insutype string
  850. //var is390 int = 0
  851. //var is310 int = 0
  852. //for _, item := range res2.Output.Iinfo {
  853. // if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  854. // insutypes = append(insutypes, item.Insutype)
  855. // }
  856. //}
  857. //if len(insutypes) == 1 {
  858. // insutype = insutypes[0]
  859. //} else {
  860. // for _, i := range insutypes {
  861. // if i == "390" {
  862. // is390 = 1
  863. // }
  864. //
  865. // if i == "310" {
  866. // is310 = 1
  867. // }
  868. // }
  869. //}
  870. //if is390 == 1 {
  871. // insutype = "390"
  872. //}
  873. //if is310 == 1 {
  874. // insutype = "310"
  875. //}
  876. //
  877. //if len(insutypes) == 0 {
  878. // insutype = "310"
  879. //}
  880. if len(insuplc_admdvs) == 0 {
  881. insuplc_admdvs = miConfig.InsuplcAdmdvs
  882. }
  883. timestamp := time.Now().Unix()
  884. tempTime := time.Unix(timestamp, 0)
  885. timeFormat := tempTime.Format("20060102150405")
  886. chrgBchno := rand.Intn(100000) + 10000
  887. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(id, 10)
  888. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  889. var struct2401 service.Struct2401
  890. struct2401.PsnNo = res2.Output.Baseinfo.PsnNo
  891. struct2401.Insutype = insutype
  892. psn_info, _ := service.GetPsnByPatientId(patient.ID)
  893. if id_card_type == 1 {
  894. struct2401.MdtrtCertType = "03"
  895. bas := strings.Split(psn_info.CardInfo, "|")
  896. cardNumber := bas[2]
  897. struct2401.MdtrtCertNo = cardNumber
  898. } else {
  899. struct2401.MdtrtCertType = "02"
  900. struct2401.MdtrtCertNo = res2.Output.Baseinfo.Certno
  901. }
  902. if miConfig.Code == "H15049901371" {
  903. if med_type == 14 {
  904. if insutype == "390" {
  905. struct2401.MedType = "9933"
  906. } else if insutype == "310" {
  907. struct2401.MedType = "990502"
  908. }
  909. } else if med_type == 11 {
  910. struct2401.MedType = "11"
  911. }
  912. } else {
  913. struct2401.MedType = strconv.FormatInt(int64(med_type), 10)
  914. }
  915. struct2401.IptNo = ipt_otp_no
  916. struct2401.AtddrNo = strconv.FormatInt(int64(doctorInfo.AdminUserId), 10)
  917. struct2401.ChfpdrName = doctorInfo.UserName
  918. struct2401.AdmDiagDscr = diagnosisConfig[0].ClassName
  919. struct2401.AdmDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  920. struct2401.AdmDeptName = departmentInfo.Name
  921. struct2401.AdmBed = deviceNumber.Number
  922. struct2401.AdmBed = "待定"
  923. struct2401.DscgMaindiagName = diagnosisConfig[0].ClassName
  924. struct2401.DscgMaindiagCode = diagnosisConfig[0].CountryCode
  925. struct2401.Begntime = start_time
  926. struct2401.DiseCodg = sickConfig.CountryCode
  927. struct2401.DiseName = sickConfig.ClassName
  928. var dises []service.DiseinfoStruct
  929. for index, item := range diagnosisConfig {
  930. var dise service.DiseinfoStruct
  931. dise.PsnNo = res2.Output.Baseinfo.PsnNo
  932. dise.DiagType = "1"
  933. if index == 0 {
  934. dise.MaindiagFlag = "1"
  935. } else {
  936. dise.MaindiagFlag = "2"
  937. }
  938. dise.DiagSrtNo = strconv.FormatInt(int64(index), 10)
  939. dise.DiseDorName = doctorInfo.UserName
  940. dise.DiagCode = item.CountryCode
  941. dise.DiagName = item.ClassName
  942. dise.DiagDept = departmentInfo.Name
  943. dise.DiseDorNo = strconv.FormatInt(int64(doctorInfo.AdminUserId), 10)
  944. dise.DiagTime = timeFormatOne
  945. dises = append(dises, dise)
  946. }
  947. struct2401.Diseinfo = dises
  948. var result string
  949. var request_log string
  950. if miConfig.MdtrtareaAdmvs == "150499" {
  951. data := make(map[string]interface{})
  952. data["org_name"] = miConfig.OrgName
  953. data["doctor"] = role.UserName
  954. data["fixmedins_code"] = miConfig.Code
  955. data["insuplc_admdvs"] = insuplc_admdvs
  956. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  957. data["secret_key"] = miConfig.SecretKey
  958. data["struct_2401"] = struct2401
  959. var req *http.Request
  960. bytesData, _ := json.Marshal(data)
  961. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2401", bytes.NewReader(bytesData))
  962. client := &http.Client{}
  963. resp, _ := client.Do(req)
  964. defer resp.Body.Close()
  965. body, ioErr := ioutil.ReadAll(resp.Body)
  966. if ioErr != nil {
  967. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  968. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  969. return
  970. }
  971. var respJSON map[string]interface{}
  972. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  973. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  975. return
  976. }
  977. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  978. result_byte, _ := json.Marshal(respJSON)
  979. result = string(result_byte)
  980. } else {
  981. result, request_log = service.ZHGdyb2401(struct2401, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, insuplc_admdvs, miConfig.MdtrtareaAdmvs)
  982. saveLog(result, request_log, "2401", "入院登记")
  983. }
  984. var dat map[string]interface{}
  985. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  986. fmt.Println(dat)
  987. } else {
  988. fmt.Println(err)
  989. }
  990. userJSONBytes, _ := json.Marshal(dat)
  991. var res ResultThree
  992. var resThree10265 ResultThree10265
  993. if miConfig.Code == "H15049901371" {
  994. if err := json.Unmarshal(userJSONBytes, &resThree10265); err != nil {
  995. utils.ErrorLog("解析失败:%v", err)
  996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  997. return
  998. }
  999. Infcode, _ := strconv.ParseInt(resThree10265.Infcode, 10, 64)
  1000. res.Infcode = Infcode
  1001. res.ErrMsg = resThree10265.ErrMsg
  1002. res.Output = resThree10265.Output
  1003. res.InfRefmsgid = resThree10265.InfRefmsgid
  1004. res.RespondTime = resThree10265.RespondTime
  1005. } else {
  1006. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1007. utils.ErrorLog("解析失败:%v", err)
  1008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1009. return
  1010. }
  1011. }
  1012. if res.Infcode == 0 {
  1013. //result2 := service.Gdyb5301Two(res2.Output.Baseinfo.PsnNo, miConfig.OrgName, role.UserName, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  1014. //fmt.Println(result2)
  1015. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  1016. Idetinfos, _ := json.Marshal(res2.Output.Idetinfo)
  1017. infoStr := string(Iinfos)
  1018. idetinfoStr := string(Idetinfos)
  1019. inHospital := &models.HisHospitalCheckRecord{
  1020. PatientId: id,
  1021. Name: name,
  1022. MedicalTreatmentType: med_type,
  1023. RecordDate: recordDateTime,
  1024. IdCardNo: id_card_no,
  1025. AdminUserId: admin_user_id,
  1026. Departments: department,
  1027. UserOrgId: adminInfo.CurrentOrgId,
  1028. Status: 1,
  1029. Ctime: time.Now().Unix(),
  1030. Mtime: time.Now().Unix(),
  1031. Number: res.Output.Result.MdtrtID,
  1032. Doctor: doctor,
  1033. PsnNo: res2.Output.Baseinfo.PsnNo,
  1034. PsnCertType: res2.Output.Baseinfo.PsnCertType,
  1035. Certno: res2.Output.Baseinfo.Certno,
  1036. PsnName: res2.Output.Baseinfo.PsnName,
  1037. Gend: res2.Output.Baseinfo.Gend,
  1038. Naty: res2.Output.Baseinfo.Naty,
  1039. MedType: med_type,
  1040. InsutypeType: insutype,
  1041. Brdy: res2.Output.Baseinfo.Brdy,
  1042. Iinfo: infoStr,
  1043. Idetinfo: idetinfoStr,
  1044. IptOtpNo: ipt_otp_no,
  1045. AdmBed: adm_bed,
  1046. IdCardType: id_card_type,
  1047. Diagnosis: diagnosis_ids,
  1048. SickType: sick_type,
  1049. MdtrtCertType: "02",
  1050. InHosptialTime: start_time,
  1051. OutHosptialTime: "",
  1052. InHospitalStatus: 1,
  1053. Certificates: certificates,
  1054. Phone: phone,
  1055. BalanceAccountsType: balance_accounts_type,
  1056. PsnType: psn_type,
  1057. InsuplcAdmdvs: insuplc_admdvs,
  1058. }
  1059. service.CreateHospitalRecord(inHospital)
  1060. c.ServeSuccessJSON(map[string]interface{}{
  1061. "msg": "办理入院成功",
  1062. "info": inHospital,
  1063. })
  1064. } else {
  1065. c.ServeSuccessJSON(map[string]interface{}{
  1066. "failed_code": -10,
  1067. "msg": res.ErrMsg,
  1068. })
  1069. }
  1070. } else {
  1071. c.ServeSuccessJSON(map[string]interface{}{
  1072. "failed_code": -10,
  1073. "msg": res2.ErrMsg,
  1074. })
  1075. return
  1076. }
  1077. }
  1078. func (this *ZHHisApiController) GetZHOutHospitalCheck() {
  1079. id, _ := this.GetInt64("id")
  1080. patient_id, _ := this.GetInt64("patient_id")
  1081. admin_user_id, _ := this.GetInt64("admin_user_id")
  1082. record_time := this.GetString("record_time")
  1083. out_time := this.GetString("out_time")
  1084. adminInfo := this.GetAdminUserInfo()
  1085. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1086. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1087. record, _ := service.GetInHospitalRecord(id)
  1088. if record.ID == 0 {
  1089. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  1090. return
  1091. }
  1092. timeLayout := "2006-01-02"
  1093. loc, _ := time.LoadLocation("Local")
  1094. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1095. if err != nil {
  1096. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. recordDateTime := theTime.Unix()
  1100. var patient service.Patients
  1101. if patient_id == 0 {
  1102. patient, _ = service.GetPatientByIDCard(record.IdCardNo, adminInfo.CurrentOrgId)
  1103. } else {
  1104. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  1105. }
  1106. fmt.Println(patient)
  1107. diagnosis_ids_arr := strings.Split(record.Diagnosis, "-")
  1108. diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  1109. departmentInfo, _ := service.GetDepartMentDetail(record.Departments)
  1110. doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, record.Doctor)
  1111. //deviceNumber, _ := service.GetDeviceNumberByID(record.AdmBed, adminInfo.CurrentOrgId)
  1112. sickConfig, _ := service.FindSickById(record.SickType)
  1113. var struct2402 service.Struct2402
  1114. timestamp := time.Now().Unix()
  1115. tempTime := time.Unix(timestamp, 0)
  1116. //timeFormat := tempTime.Format("20060102150405")
  1117. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  1118. struct2402.PsnNo = record.PsnNo
  1119. struct2402.Insutype = record.InsutypeType
  1120. struct2402.DscgWay = "1"
  1121. struct2402.Endtime = out_time
  1122. struct2402.DscgDeptName = departmentInfo.Number
  1123. struct2402.DscgDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  1124. struct2402.MdtrtId = record.Number
  1125. var dises []service.Diseinfo2402Struct
  1126. for index, item := range diagnosisConfig {
  1127. var dise service.Diseinfo2402Struct
  1128. dise.PsnNo = record.PsnNo
  1129. dise.DiagType = "1"
  1130. if index == 0 {
  1131. dise.MaindiagFlag = "1"
  1132. } else {
  1133. dise.MaindiagFlag = "2"
  1134. }
  1135. dise.MdtrtId = record.Number
  1136. dise.DiagSrtNo = strconv.FormatInt(int64(item.ID), 10)
  1137. dise.DiseDorName = doctorInfo.UserName
  1138. dise.DiagCode = item.CountryCode
  1139. dise.DiagName = item.ClassName
  1140. dise.DiagDept = departmentInfo.Name
  1141. dise.DiseDorNo = strconv.FormatInt(int64(doctorInfo.AdminUserId), 10)
  1142. dise.DiagTime = timeFormatOne
  1143. dises = append(dises, dise)
  1144. }
  1145. struct2402.Diseinfo = dises
  1146. struct2402.DiseName = sickConfig.ClassName
  1147. struct2402.DiseCode = sickConfig.CountryCode
  1148. var result string
  1149. var request_log string
  1150. if miConfig.MdtrtareaAdmvs == "150499" {
  1151. data := make(map[string]interface{})
  1152. data["org_name"] = miConfig.OrgName
  1153. data["doctor"] = role.UserName
  1154. data["fixmedins_code"] = miConfig.Code
  1155. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1156. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1157. data["secret_key"] = miConfig.SecretKey
  1158. data["struct_2402"] = struct2402
  1159. var req *http.Request
  1160. bytesData, _ := json.Marshal(data)
  1161. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2402", bytes.NewReader(bytesData))
  1162. client := &http.Client{}
  1163. resp, _ := client.Do(req)
  1164. defer resp.Body.Close()
  1165. body, ioErr := ioutil.ReadAll(resp.Body)
  1166. if ioErr != nil {
  1167. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1168. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1169. return
  1170. }
  1171. var respJSON map[string]interface{}
  1172. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1173. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1174. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1175. return
  1176. }
  1177. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1178. result_byte, _ := json.Marshal(respJSON)
  1179. result = string(result_byte)
  1180. } else {
  1181. result, request_log = service.ZHGdyb2402(struct2402, miConfig.OrgName, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  1182. saveLog(result, request_log, "2402", "出院")
  1183. }
  1184. var dat map[string]interface{}
  1185. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1186. fmt.Println(dat)
  1187. } else {
  1188. fmt.Println(err)
  1189. }
  1190. userJSONBytes, _ := json.Marshal(dat)
  1191. var res ResultEmpty
  1192. var resEmpty10265 ResultEmpty10265
  1193. if miConfig.Code == "H15049901371" {
  1194. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  1195. utils.ErrorLog("解析失败:%v", err)
  1196. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1197. return
  1198. }
  1199. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  1200. res.Infcode = Infcode
  1201. res.RespondTime = resEmpty10265.RespondTime
  1202. res.ErrMsg = resEmpty10265.ErrMsg
  1203. res.Output = resEmpty10265.Output
  1204. res.WarnMsg = resEmpty10265.WarnMsg
  1205. } else {
  1206. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1207. utils.ErrorLog("解析失败:%v", err)
  1208. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1209. return
  1210. }
  1211. }
  1212. if res.Infcode == 0 {
  1213. record.OutHospitalStatus = 1
  1214. record.OutHosptialTime = struct2402.Endtime
  1215. record.OutWay = 1
  1216. service.CreateHospitalRecord(&record)
  1217. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  1218. var total float64
  1219. for _, item := range orders {
  1220. total = total + item.DetItemFeeSumamt
  1221. }
  1222. order := &models.HisOrder{
  1223. UserOrgId: adminInfo.CurrentOrgId,
  1224. HisPatientId: record.ID,
  1225. PatientId: record.PatientId,
  1226. SettleAccountsDate: recordDateTime,
  1227. Ctime: time.Now().Unix(),
  1228. Mtime: time.Now().Unix(),
  1229. Status: 1,
  1230. Number: record.Number,
  1231. Infcode: 0,
  1232. WarnMsg: "",
  1233. Cainfo: "",
  1234. ErrMsg: "",
  1235. RespondTime: "",
  1236. InfRefmsgid: "",
  1237. OrderStatus: 1,
  1238. MdtrtId: record.Number,
  1239. IsMedicineInsurance: 1,
  1240. PType: 1,
  1241. MedfeeSumamt: total,
  1242. }
  1243. err = service.CreateOrder(order)
  1244. if err != nil {
  1245. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1246. return
  1247. }
  1248. this.ServeSuccessJSON(map[string]interface{}{
  1249. "msg": "出院成功",
  1250. })
  1251. } else {
  1252. this.ServeSuccessJSON(map[string]interface{}{
  1253. "failed_code": -10,
  1254. "msg": res.ErrMsg,
  1255. })
  1256. }
  1257. }
  1258. func (c *ZHHisApiController) GetSettleInfo() {
  1259. order_id, _ := c.GetInt64("order_id")
  1260. patient_id, _ := c.GetInt64("patient_id")
  1261. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  1262. admin_user_id, _ := c.GetInt64("admin_user_id")
  1263. pay_way, _ := c.GetInt64("pay_way")
  1264. pay_price, _ := c.GetFloat("pay_price")
  1265. pay_card_no := c.GetString("pay_card_no")
  1266. discount_price, _ := c.GetFloat("discount_price")
  1267. preferential_price, _ := c.GetFloat("preferential_price")
  1268. reality_price, _ := c.GetFloat("reality_price")
  1269. found_price, _ := c.GetFloat("found_price")
  1270. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1271. private_price, _ := c.GetFloat("private_price")
  1272. fapiao_code := c.GetString("fapiao_code")
  1273. fapiao_number := c.GetString("fapiao_number")
  1274. record, _ := service.GetInHospitalRecord(in_hospital_id)
  1275. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  1276. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  1277. order, _ := service.GetHisOrderByID(order_id)
  1278. var rf []*ResultFive
  1279. json.Unmarshal([]byte(record.Iinfo), &rf)
  1280. chrg_bchno := order.Number
  1281. cert_no := record.Certno
  1282. if record.ID == 0 {
  1283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1284. return
  1285. }
  1286. if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  1287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  1288. return
  1289. }
  1290. if record.IdCardType == 1 {
  1291. } else {
  1292. cert_no = record.Certno
  1293. }
  1294. var result string
  1295. var src_resquest string
  1296. timeLayout := "2006-01-02"
  1297. loc, _ := time.LoadLocation("Local")
  1298. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record.InHosptialTime, loc)
  1299. if err != nil {
  1300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1301. return
  1302. }
  1303. recordStartDateTime := theTime.Unix()
  1304. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", record.OutHosptialTime, loc)
  1305. if err != nil {
  1306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1307. return
  1308. }
  1309. recordEndDateTime := theTimeEnd.Unix()
  1310. prescriptions, _ := service.GetZHSettleMonthHisPrescription(c.GetAdminUserInfo().CurrentOrgId, patient_id, recordStartDateTime, recordEndDateTime)
  1311. var total float64
  1312. for _, item := range prescriptions {
  1313. if item.Type == 1 { //药品
  1314. for _, subItem := range item.HisDoctorAdviceInfo {
  1315. total = total + (subItem.Price * subItem.PrescribingNumber)
  1316. }
  1317. }
  1318. if item.Type == 2 { //项目
  1319. for _, subItem := range item.HisPrescriptionProject {
  1320. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  1321. total = total + (subItem.Price * cnt)
  1322. }
  1323. }
  1324. }
  1325. //allTotal := fmt.Sprintf("%.2f", total)
  1326. var allTotal string
  1327. if record.OutHospitalStatus == 0 && order.ID == 0 {
  1328. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  1329. var total float64
  1330. for _, item := range orders {
  1331. total = total + item.DetItemFeeSumamt
  1332. }
  1333. allTotal = fmt.Sprintf("%.4f", total)
  1334. } else {
  1335. allTotal = fmt.Sprintf("%.4f", order.MedfeeSumamt)
  1336. }
  1337. if miConfig.MdtrtareaAdmvs == "150499" {
  1338. psn_info, _ := service.GetPsnByPatientId(patient_id)
  1339. mdtrt_cert_no := ""
  1340. if record.IdCardType == 1 {
  1341. bas := strings.Split(psn_info.CardInfo, "|")
  1342. cardNumber := bas[2]
  1343. mdtrt_cert_no = cardNumber
  1344. } else {
  1345. mdtrt_cert_no = record.Certno
  1346. }
  1347. //请求内网数据
  1348. api := "http://172.16.13.254:9532/" + "nmyb/2304?psn_no=" + record.PsnNo + "&mdtrt_id=" + record.Number + "&chrg_bchno=" + chrg_bchno +
  1349. "&insutype_type=" + record.InsutypeType + "&total=" + allTotal +
  1350. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  1351. "&insuplc_admdvs=" + miConfig.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
  1352. resp, requestErr := http.Get(api)
  1353. if requestErr != nil {
  1354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1355. return
  1356. }
  1357. body, ioErr := ioutil.ReadAll(resp.Body)
  1358. if ioErr != nil {
  1359. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1361. return
  1362. }
  1363. var respJSON map[string]interface{}
  1364. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1365. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1367. return
  1368. }
  1369. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1370. result_byte, _ := json.Marshal(respJSON)
  1371. result = string(result_byte)
  1372. } else {
  1373. 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, "")
  1374. saveLog(result, src_resquest, "2304", "住院结算")
  1375. }
  1376. var dat map[string]interface{}
  1377. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1378. fmt.Println(dat)
  1379. } else {
  1380. fmt.Println(err)
  1381. }
  1382. userJSONBytes, _ := json.Marshal(dat)
  1383. var res ResultSeven
  1384. var resSeven10265 ResultSeven10265
  1385. if miConfig.Code == "H15049901371" {
  1386. if err := json.Unmarshal(userJSONBytes, &resSeven10265); err != nil {
  1387. utils.ErrorLog("解析失败:%v", err)
  1388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1389. return
  1390. }
  1391. Infcode, _ := strconv.ParseInt(resSeven10265.Infcode, 10, 64)
  1392. res.Infcode = Infcode
  1393. res.InfRefmsgid = resSeven10265.InfRefmsgid
  1394. res.RespondTime = resSeven10265.RespondTime
  1395. res.ErrMsg = resSeven10265.ErrMsg
  1396. res.Output = resSeven10265.Output
  1397. res.WarnMsg = resSeven10265.WarnMsg
  1398. res.Cainfo = resSeven10265.Cainfo
  1399. } else {
  1400. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1401. utils.ErrorLog("解析失败:%v", err)
  1402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1403. return
  1404. }
  1405. }
  1406. if res.Infcode != 0 {
  1407. errlog := &models.HisOrderError{
  1408. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1409. Ctime: time.Now().Unix(),
  1410. Mtime: time.Now().Unix(),
  1411. Number: chrg_bchno,
  1412. ErrMsg: res.ErrMsg,
  1413. Status: 1,
  1414. PatientId: patient_id,
  1415. RecordTime: time.Now().Unix(),
  1416. Stage: 6,
  1417. }
  1418. service.CreateErrMsgLog(errlog)
  1419. c.ServeSuccessJSON(map[string]interface{}{
  1420. "failed_code": -10,
  1421. "msg": res.ErrMsg,
  1422. })
  1423. return
  1424. } else {
  1425. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1426. order.OrderStatus = 2
  1427. order.DiscountPrice = discount_price
  1428. order.MedicalInsurancePrice = medical_insurance_price
  1429. order.FaPiaoNumber = fapiao_number
  1430. order.FaPiaoCode = fapiao_code
  1431. order.PayWay = pay_way
  1432. order.PayPrice = pay_price
  1433. order.PayCardNo = pay_card_no
  1434. order.PreferentialPrice = preferential_price
  1435. order.RealityPrice = reality_price
  1436. order.FoundPrice = found_price
  1437. order.PrivatePrice = private_price
  1438. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1439. order.SetlId = res.Output.Setlinfo.SetlID
  1440. order.PsnNo = res.Output.Setlinfo.PsnNo
  1441. order.PsnName = res.Output.Setlinfo.PsnName
  1442. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1443. order.Certno = res.Output.Setlinfo.Certno
  1444. order.Gend = res.Output.Setlinfo.Gend
  1445. order.Naty = res.Output.Setlinfo.Naty
  1446. order.Age = res.Output.Setlinfo.Age
  1447. order.Insutype = res.Output.Setlinfo.Insutype
  1448. order.PsnType = res.Output.Setlinfo.PsnType
  1449. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1450. order.SetlTime = res.Output.Setlinfo.SetlTime
  1451. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1452. if res.Output.Setlinfo.MedType == "140104" {
  1453. order.MedType = "14"
  1454. } else {
  1455. order.MedType = res.Output.Setlinfo.MedType
  1456. }
  1457. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1458. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1459. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1460. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1461. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1462. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1463. order.HifpPay = res.Output.Setlinfo.HifpPay
  1464. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1465. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1466. order.HifesPay = res.Output.Setlinfo.HifesPay
  1467. order.HifobPay = res.Output.Setlinfo.HifobPay
  1468. order.MafPay = res.Output.Setlinfo.MafPay
  1469. order.OthPay = res.Output.Setlinfo.OthPay
  1470. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1471. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1472. order.AcctPay = res.Output.Setlinfo.AcctPay
  1473. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1474. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1475. order.Balc = res.Output.Setlinfo.Balc
  1476. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1477. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1478. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1479. order.ClrWay = res.Output.Setlinfo.ClrWay
  1480. order.Creator = order.Creator
  1481. order.Modify = roles.AdminUserId
  1482. order.RequestLog = src_resquest
  1483. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1484. detailStr := string(setlDetail)
  1485. order.SetlDetail = detailStr
  1486. err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  1487. err = service.UpDateOrder(order)
  1488. if err == nil {
  1489. c.ServeSuccessJSON(map[string]interface{}{
  1490. "msg": "结算成功",
  1491. })
  1492. } else {
  1493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1494. return
  1495. }
  1496. }
  1497. }
  1498. func (c *ZHHisApiController) GetPreSettleInfo() {
  1499. order_id, _ := c.GetInt64("order_id")
  1500. patient_id, _ := c.GetInt64("patient_id")
  1501. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  1502. admin_user_id, _ := c.GetInt64("admin_user_id")
  1503. record, _ := service.GetInHospitalRecord(in_hospital_id)
  1504. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  1505. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  1506. order, _ := service.GetHisOrderByID(order_id)
  1507. var allTotal string
  1508. if record.OutHospitalStatus == 0 && order.ID == 0 {
  1509. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  1510. var total float64
  1511. for _, item := range orders {
  1512. total = total + item.DetItemFeeSumamt
  1513. }
  1514. allTotal = fmt.Sprintf("%.4f", total)
  1515. } else {
  1516. allTotal = fmt.Sprintf("%.4f", order.MedfeeSumamt)
  1517. }
  1518. var rf []*ResultFive
  1519. json.Unmarshal([]byte(record.Iinfo), &rf)
  1520. chrg_bchno := order.Number
  1521. cert_no := record.Certno
  1522. if record.ID == 0 {
  1523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1524. return
  1525. }
  1526. //if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  1527. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  1528. // return
  1529. //}
  1530. psn_info, _ := service.GetPsnByPatientId(patient_id)
  1531. if record.IdCardType == 1 {
  1532. bas := strings.Split(psn_info.CardInfo, "|")
  1533. cardNumber := bas[2]
  1534. cert_no = cardNumber
  1535. } else {
  1536. cert_no = record.Certno
  1537. }
  1538. var result string
  1539. var src_resquest string
  1540. if miConfig.MdtrtareaAdmvs == "150499" {
  1541. //请求内网数据
  1542. api := "http://172.16.13.254:9532/" + "nmyb/2303?psn_no=" + record.PsnNo + "&mdtrt_id=" + record.Number + "&chrg_bchno=" + chrg_bchno +
  1543. "&insutype_type=" + record.InsutypeType + "&total=" + allTotal +
  1544. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  1545. "&insuplc_admdvs=" + miConfig.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
  1546. resp, requestErr := http.Get(api)
  1547. if requestErr != nil {
  1548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1549. return
  1550. }
  1551. body, ioErr := ioutil.ReadAll(resp.Body)
  1552. if ioErr != nil {
  1553. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1555. return
  1556. }
  1557. var respJSON map[string]interface{}
  1558. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1559. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1561. return
  1562. }
  1563. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1564. result_byte, _ := json.Marshal(respJSON)
  1565. result = string(result_byte)
  1566. } else {
  1567. 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)
  1568. saveLog(result, src_resquest, "2303", "住院预结算")
  1569. }
  1570. var dat map[string]interface{}
  1571. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1572. fmt.Println(dat)
  1573. } else {
  1574. fmt.Println(err)
  1575. }
  1576. userJSONBytes, _ := json.Marshal(dat)
  1577. var res ResultSeven
  1578. var resSeven10265 ResultSeven10265
  1579. if miConfig.Code == "H15049901371" {
  1580. if err := json.Unmarshal(userJSONBytes, &resSeven10265); err != nil {
  1581. utils.ErrorLog("解析失败:%v", err)
  1582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1583. return
  1584. }
  1585. Infcode, _ := strconv.ParseInt(resSeven10265.Infcode, 10, 64)
  1586. res.Infcode = Infcode
  1587. res.InfRefmsgid = resSeven10265.InfRefmsgid
  1588. res.RespondTime = resSeven10265.RespondTime
  1589. res.ErrMsg = resSeven10265.ErrMsg
  1590. res.Output = resSeven10265.Output
  1591. res.WarnMsg = resSeven10265.WarnMsg
  1592. res.Cainfo = resSeven10265.Cainfo
  1593. } else {
  1594. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1595. utils.ErrorLog("解析失败:%v", err)
  1596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1597. return
  1598. }
  1599. }
  1600. if res.Infcode != 0 {
  1601. errlog := &models.HisOrderError{
  1602. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1603. Ctime: time.Now().Unix(),
  1604. Mtime: time.Now().Unix(),
  1605. Number: chrg_bchno,
  1606. ErrMsg: res.ErrMsg,
  1607. Status: 1,
  1608. PatientId: patient_id,
  1609. RecordTime: time.Now().Unix(),
  1610. Stage: 6,
  1611. }
  1612. service.CreateErrMsgLog(errlog)
  1613. c.ServeSuccessJSON(map[string]interface{}{
  1614. "failed_code": -10,
  1615. "msg": res.ErrMsg,
  1616. })
  1617. return
  1618. } else {
  1619. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1620. order.OrderStatus = 1
  1621. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1622. order.SetlId = res.Output.Setlinfo.SetlID
  1623. order.PsnNo = res.Output.Setlinfo.PsnNo
  1624. order.PsnName = res.Output.Setlinfo.PsnName
  1625. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1626. order.Certno = res.Output.Setlinfo.Certno
  1627. order.Gend = res.Output.Setlinfo.Gend
  1628. order.Naty = res.Output.Setlinfo.Naty
  1629. order.Age = res.Output.Setlinfo.Age
  1630. order.Insutype = res.Output.Setlinfo.Insutype
  1631. order.PsnType = res.Output.Setlinfo.PsnType
  1632. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1633. order.SetlTime = res.Output.Setlinfo.SetlTime
  1634. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1635. if res.Output.Setlinfo.MedType == "140104" {
  1636. order.MedType = "14"
  1637. } else {
  1638. order.MedType = res.Output.Setlinfo.MedType
  1639. }
  1640. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1641. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1642. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1643. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1644. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1645. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1646. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  1647. order.HifpPay = res.Output.Setlinfo.HifpPay
  1648. order.HifesPay = res.Output.Setlinfo.HifesPay
  1649. order.HifobPay = res.Output.Setlinfo.HifobPay
  1650. order.MafPay = res.Output.Setlinfo.MafPay
  1651. order.OthPay = res.Output.Setlinfo.OthPay
  1652. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1653. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1654. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1655. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1656. order.AcctPay = res.Output.Setlinfo.AcctPay
  1657. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1658. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1659. order.Balc = res.Output.Setlinfo.Balc
  1660. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1661. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1662. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1663. order.ClrWay = res.Output.Setlinfo.ClrWay
  1664. order.Creator = order.Creator
  1665. order.Modify = roles.AdminUserId
  1666. order.RequestLog = src_resquest
  1667. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1668. detailStr := string(setlDetail)
  1669. order.SetlDetail = detailStr
  1670. //err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  1671. if record.OutHospitalStatus == 1 && order.ID > 0 {
  1672. err := service.UpDateOrder(order)
  1673. if err == nil {
  1674. c.ServeSuccessJSON(map[string]interface{}{
  1675. "msg": "预结算成功",
  1676. "order_way": 1,
  1677. })
  1678. } else {
  1679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1680. return
  1681. }
  1682. } else if record.OutHospitalStatus == 0 && order.ID == 0 {
  1683. c.ServeSuccessJSON(map[string]interface{}{
  1684. "msg": "预结算成功",
  1685. "order": order,
  1686. "order_way": 2,
  1687. })
  1688. }
  1689. }
  1690. }
  1691. func (c *ZHHisApiController) GetUploadInfo() {
  1692. id, _ := c.GetInt64("id")
  1693. record_time := c.GetString("record_time")
  1694. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  1695. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1696. admin_user_id, _ := c.GetInt64("admin_user_id")
  1697. timeLayout := "2006-01-02"
  1698. loc, _ := time.LoadLocation("Local")
  1699. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1700. if err != nil {
  1701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1702. return
  1703. }
  1704. recordDateTime := theTime.Unix()
  1705. adminUser := c.GetAdminUserInfo()
  1706. var prescriptions []*models.HisPrescription
  1707. data := make(map[string]interface{})
  1708. if settle_accounts_type == 1 { //日结
  1709. prescriptions, _ = service.GetZHHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1710. } else { //月结
  1711. start_time_str := c.GetString("start_time")
  1712. end_time_str := c.GetString("end_time")
  1713. timeLayout := "2006-01-02"
  1714. loc, _ := time.LoadLocation("Local")
  1715. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1716. if err != nil {
  1717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1718. return
  1719. }
  1720. recordStartTime := theStartTime.Unix()
  1721. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1722. if err != nil {
  1723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1724. return
  1725. }
  1726. recordEndTime := theEndTime.Unix()
  1727. prescriptions, _ = service.GetZHMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1728. }
  1729. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1730. record, _ := service.GetInHospitalRecord(in_hospital_id)
  1731. if record.ID == 0 {
  1732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1733. return
  1734. }
  1735. timestamp := time.Now().Unix()
  1736. tempTime := time.Unix(timestamp, 0)
  1737. timeFormat := tempTime.Format("20060102150405")
  1738. chrgBchno := rand.Intn(100000) + 10000
  1739. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(record.PatientId, 10)
  1740. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1741. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1742. department, _ := service.GetDepartMentDetail(record.Departments)
  1743. strconv.FormatInt(record.PatientId, 10)
  1744. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, record.Doctor)
  1745. //client := &http.Client{}
  1746. data["psn_no"] = record.PsnNo
  1747. data["mdtrt_id"] = record.Number
  1748. data["chrg_bchno"] = chrg_bchno
  1749. data["org_name"] = miConfig.OrgName
  1750. data["doctor"] = roles.UserName
  1751. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1752. data["dept"] = strconv.FormatInt(department.ID, 10)
  1753. data["fixmedins_code"] = miConfig.Code
  1754. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  1755. data["dept_code"] = "15"
  1756. } else {
  1757. data["dept_code"] = department.Number
  1758. }
  1759. if miConfig.Code == "H15049901371" {
  1760. if record.MedType == 14 {
  1761. if record.InsutypeType == "390" {
  1762. data["med_type"] = "9933"
  1763. } else if record.InsutypeType == "310" {
  1764. data["med_type"] = "990502"
  1765. }
  1766. } else if record.MedType == 11 {
  1767. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  1768. }
  1769. } else {
  1770. if record.MedType == 1112 {
  1771. data["med_type"] = strconv.FormatInt(11, 10)
  1772. } else {
  1773. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  1774. }
  1775. }
  1776. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  1777. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1778. data["secret_key"] = miConfig.SecretKey
  1779. var ids []int64
  1780. fmt.Println(data)
  1781. for _, item := range prescriptions {
  1782. ids = append(ids, item.ID)
  1783. }
  1784. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1785. if config.IsOpen == 1 { //对接了医保,走医保流程
  1786. var pagesize int = 100
  1787. var start int = 1
  1788. var stop int
  1789. var pagecount int
  1790. var curpage int
  1791. var isSuccess bool = true
  1792. var customs []*models.NewCustom
  1793. for _, item := range prescriptions {
  1794. tm := time.Unix(item.PreTime, 0)
  1795. if item.Type == 1 { //药品
  1796. for _, subItem := range item.HisDoctorAdviceInfo {
  1797. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 && subItem.BaseDrugLib.IsUser != 1 {
  1798. //var randNum int
  1799. //randNum = rand.Intn(10000) + 1000
  1800. cus := &models.NewCustom{
  1801. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  1802. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  1803. FeedetlSn: subItem.FeedetlSn,
  1804. Price: fmt.Sprintf("%.4f", subItem.Price),
  1805. MedListCodg: subItem.BaseDrugLib.MedicalInsuranceNumber,
  1806. HospApprFlag: subItem.BaseDrugLib.HospApprFlag,
  1807. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  1808. }
  1809. customs = append(customs, cus)
  1810. }
  1811. }
  1812. }
  1813. if item.Type == 2 { //项目
  1814. for _, subItem := range item.HisPrescriptionProject {
  1815. //var randNum int
  1816. //randNum = rand.Intn(10000) + 1000
  1817. if subItem.Type == 2 {
  1818. if len(subItem.HisProject.MedicalCode) > 0 {
  1819. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  1820. cus := &models.NewCustom{
  1821. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  1822. Cut: fmt.Sprintf("%.4f", cnt),
  1823. FeedetlSn: subItem.FeedetlSn,
  1824. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  1825. MedListCodg: subItem.HisProject.MedicalCode,
  1826. HospApprFlag: -1,
  1827. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  1828. }
  1829. customs = append(customs, cus)
  1830. }
  1831. } else if subItem.Type == 3 {
  1832. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 && subItem.GoodInfo.IsUser != 1 {
  1833. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  1834. cus := &models.NewCustom{
  1835. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  1836. Cut: fmt.Sprintf("%.4f", cnt),
  1837. FeedetlSn: subItem.FeedetlSn,
  1838. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  1839. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  1840. HospApprFlag: -1,
  1841. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  1842. }
  1843. customs = append(customs, cus)
  1844. }
  1845. }
  1846. }
  1847. }
  1848. }
  1849. //总页数,向上取整,注意除之前要先转换类型为float64
  1850. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  1851. var ress []*ResultFour
  1852. for curpage = 1; curpage <= pagecount; curpage++ {
  1853. if curpage == 1 {
  1854. start = 1
  1855. } else {
  1856. start = (curpage-1)*pagesize + 1
  1857. }
  1858. stop = curpage * pagesize
  1859. if stop > len(customs) {
  1860. stop = len(customs)
  1861. }
  1862. var result string
  1863. var requestLog string
  1864. if miConfig.MdtrtareaAdmvs == "150499" {
  1865. data := make(map[string]interface{})
  1866. if record.MedType == 14 {
  1867. if record.InsutypeType == "390" {
  1868. data["med_type"] = "9933"
  1869. } else if record.InsutypeType == "310" {
  1870. data["med_type"] = "990502"
  1871. }
  1872. } else if record.MedType == 11 {
  1873. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  1874. }
  1875. data["psn_no"] = record.PsnNo
  1876. data["number"] = record.Number
  1877. data["customs"] = customs[start-1 : stop]
  1878. data["chrg_bchno"] = chrg_bchno
  1879. data["dept"] = strconv.FormatInt(department.ID, 10)
  1880. data["dept_code"] = department.Number
  1881. data["doctor_code"] = strconv.FormatInt(doctor_info.ID, 10)
  1882. data["doctor_name"] = doctor_info.UserName
  1883. data["org_name"] = miConfig.OrgName
  1884. data["opertor"] = roles.UserName
  1885. data["fixmedins_code"] = miConfig.Code
  1886. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  1887. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1888. data["secret_key"] = miConfig.SecretKey
  1889. var req *http.Request
  1890. bytesData, _ := json.Marshal(data)
  1891. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2301", bytes.NewReader(bytesData))
  1892. client := &http.Client{}
  1893. resp, _ := client.Do(req)
  1894. defer resp.Body.Close()
  1895. body, ioErr := ioutil.ReadAll(resp.Body)
  1896. if ioErr != nil {
  1897. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1898. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1899. return
  1900. }
  1901. var respJSON map[string]interface{}
  1902. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1903. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1905. return
  1906. }
  1907. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1908. result_byte, _ := json.Marshal(respJSON)
  1909. result = string(result_byte)
  1910. } else {
  1911. 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))
  1912. saveLog(result, requestLog, "2301", "上传明细")
  1913. }
  1914. var dat map[string]interface{}
  1915. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1916. fmt.Println(dat)
  1917. } else {
  1918. fmt.Println(err)
  1919. }
  1920. userJSONBytes, _ := json.Marshal(dat)
  1921. var res ResultFour
  1922. var resFour10265 ResultFour10265
  1923. if miConfig.Code == "H15049901371" {
  1924. if err := json.Unmarshal(userJSONBytes, &resFour10265); err != nil {
  1925. utils.ErrorLog("解析失败:%v", err)
  1926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1927. return
  1928. }
  1929. res.WarnMsg = resFour10265.WarnMsg
  1930. res.Output = resFour10265.Output
  1931. res.ErrMsg = resFour10265.ErrMsg
  1932. res.RespondTime = resFour10265.RespondTime
  1933. res.InfRefmsgid = resFour10265.InfRefmsgid
  1934. Infcode, _ := strconv.ParseInt(resFour10265.Infcode, 10, 64)
  1935. res.Infcode = Infcode
  1936. } else {
  1937. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1938. utils.ErrorLog("解析失败:%v", err)
  1939. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1940. return
  1941. }
  1942. }
  1943. if res.Infcode == 0 {
  1944. ress = append(ress, &res)
  1945. } else {
  1946. isSuccess = false
  1947. errlog := &models.HisOrderError{
  1948. UserOrgId: adminUser.CurrentOrgId,
  1949. Ctime: time.Now().Unix(),
  1950. Mtime: time.Now().Unix(),
  1951. Number: chrg_bchno,
  1952. ErrMsg: "",
  1953. Status: 1,
  1954. PatientId: id,
  1955. RecordTime: recordDateTime,
  1956. Stage: 4,
  1957. }
  1958. service.CreateErrMsgLog(errlog)
  1959. c.ServeSuccessJSON(map[string]interface{}{
  1960. "failed_code": -10,
  1961. "msg": "上传明细错误,请联系his厂商",
  1962. })
  1963. return
  1964. }
  1965. }
  1966. if isSuccess == true {
  1967. if settle_accounts_type == 1 {
  1968. for _, subItem := range ress {
  1969. for _, item := range subItem.Output.Result {
  1970. temp := strings.Split(item.FeedetlSn, "-")
  1971. var advice_id int64 = 0
  1972. var project_id int64 = 0
  1973. var types int64 = 0
  1974. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1975. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1976. if temp[1] == "1" {
  1977. advice_id = id
  1978. project_id = 0
  1979. } else if temp[1] == "2" {
  1980. advice_id = 0
  1981. project_id = id
  1982. }
  1983. info := &models.HisOrderInfo{
  1984. OrderNumber: record.Number,
  1985. FeedetlSn: item.FeedetlSn,
  1986. UploadDate: recordDateTime,
  1987. AdviceId: advice_id,
  1988. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1989. Cnt: item.Cnt,
  1990. Pric: float64(item.Pric),
  1991. PatientId: record.PatientId,
  1992. PricUplmtAmt: item.PricUplmtAmt,
  1993. SelfpayProp: item.SelfpayProp,
  1994. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1995. OverlmtAmt: item.OverlmtAmt,
  1996. PreselfpayAmt: item.PreselfpayAmt,
  1997. BasMednFlag: item.BasMednFlag,
  1998. MedChrgitmType: item.MedChrgitmType,
  1999. HiNegoDrugFlag: item.HiNegoDrugFlag,
  2000. Status: 1,
  2001. Memo: item.Memo,
  2002. Mtime: time.Now().Unix(),
  2003. InscpScpAmt: item.InscpScpAmt,
  2004. DrtReimFlag: item.DrtReimFlag,
  2005. Ctime: time.Now().Unix(),
  2006. ListSpItemFlag: item.ListSpItemFlag,
  2007. ChldMedcFlag: item.ChldMedcFlag,
  2008. LmtUsedFlag: item.LmtUsedFlag,
  2009. ChrgitmLv: item.ChrgitmLv,
  2010. UserOrgId: adminUser.CurrentOrgId,
  2011. HisPatientId: record.ID,
  2012. OrderId: 0,
  2013. ProjectId: project_id,
  2014. Type: types,
  2015. SettleType: settle_accounts_type,
  2016. }
  2017. service.CreateOrderInfo(info)
  2018. }
  2019. }
  2020. err := service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  2021. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  2022. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  2023. if err == nil {
  2024. c.ServeSuccessJSON(map[string]interface{}{
  2025. "msg": "上传费用明细成功",
  2026. })
  2027. return
  2028. } else {
  2029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2030. return
  2031. }
  2032. } else {
  2033. for _, subItem := range ress {
  2034. for _, item := range subItem.Output.Result {
  2035. temp := strings.Split(item.FeedetlSn, "-")
  2036. var advice_id int64 = 0
  2037. var project_id int64 = 0
  2038. var types int64 = 0
  2039. id, _ := strconv.ParseInt(temp[2], 10, 64)
  2040. types, _ = strconv.ParseInt(temp[1], 10, 64)
  2041. if temp[1] == "1" {
  2042. advice_id = id
  2043. project_id = 0
  2044. } else if temp[1] == "2" {
  2045. advice_id = 0
  2046. project_id = id
  2047. }
  2048. info := &models.HisOrderInfo{
  2049. OrderNumber: record.Number,
  2050. FeedetlSn: item.FeedetlSn,
  2051. UploadDate: time.Now().Unix(),
  2052. AdviceId: advice_id,
  2053. DetItemFeeSumamt: item.DetItemFeeSumamt,
  2054. Cnt: item.Cnt,
  2055. Pric: float64(item.Pric),
  2056. PatientId: record.PatientId,
  2057. PricUplmtAmt: item.PricUplmtAmt,
  2058. SelfpayProp: item.SelfpayProp,
  2059. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2060. OverlmtAmt: item.OverlmtAmt,
  2061. PreselfpayAmt: item.PreselfpayAmt,
  2062. BasMednFlag: item.BasMednFlag,
  2063. MedChrgitmType: item.MedChrgitmType,
  2064. HiNegoDrugFlag: item.HiNegoDrugFlag,
  2065. Status: 1,
  2066. Memo: item.Memo,
  2067. Mtime: time.Now().Unix(),
  2068. InscpScpAmt: item.InscpScpAmt,
  2069. DrtReimFlag: item.DrtReimFlag,
  2070. Ctime: time.Now().Unix(),
  2071. ListSpItemFlag: item.ListSpItemFlag,
  2072. ChldMedcFlag: item.ChldMedcFlag,
  2073. LmtUsedFlag: item.LmtUsedFlag,
  2074. ChrgitmLv: item.ChrgitmLv,
  2075. UserOrgId: adminUser.CurrentOrgId,
  2076. HisPatientId: record.ID,
  2077. ProjectId: project_id,
  2078. Type: types,
  2079. SettleType: settle_accounts_type,
  2080. }
  2081. service.CreateOrderInfo(info)
  2082. }
  2083. }
  2084. service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  2085. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  2086. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  2087. c.ServeSuccessJSON(map[string]interface{}{
  2088. "msg": "上传费用明细成功",
  2089. })
  2090. }
  2091. }
  2092. }
  2093. }
  2094. func (c *ZHHisApiController) ZHRefund() {
  2095. order_id, _ := c.GetInt64("order_id")
  2096. admin_user_id, _ := c.GetInt64("admin_user_id")
  2097. adminUser := c.GetAdminUserInfo()
  2098. var order models.HisOrder
  2099. order, _ = service.GetHisOrderByID(order_id)
  2100. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  2101. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2102. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2103. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2104. if config.IsOpen == 1 { //对接了医保,走医保流程
  2105. var result string
  2106. var requestLog string
  2107. if miConfig.MdtrtareaAdmvs == "150499" {
  2108. //请求内网数据
  2109. api := "http://172.16.13.254:9532/" + "nmyb/2305?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo + "&setl_id=" + order.SetlId +
  2110. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2111. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2112. resp, requestErr := http.Get(api)
  2113. if requestErr != nil {
  2114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2115. return
  2116. }
  2117. body, ioErr := ioutil.ReadAll(resp.Body)
  2118. if ioErr != nil {
  2119. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2121. return
  2122. }
  2123. var respJSON map[string]interface{}
  2124. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2125. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2127. return
  2128. }
  2129. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2130. result_byte, _ := json.Marshal(respJSON)
  2131. result = string(result_byte)
  2132. //saveLog(result, requestLog, "2404", "入院登记撤销")
  2133. saveLog(result, requestLog, "2305", "退费")
  2134. } else {
  2135. result, requestLog := service.Gdyb2305(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2136. saveLog(result, requestLog, "2305", "退费")
  2137. }
  2138. var dat map[string]interface{}
  2139. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2140. fmt.Println(dat)
  2141. } else {
  2142. fmt.Println(err)
  2143. }
  2144. userJSONBytes, _ := json.Marshal(dat)
  2145. var res ResultSixteen
  2146. var resSixteen ResultSixteen10265
  2147. if miConfig.Code == "H15049901371" {
  2148. if err := json.Unmarshal(userJSONBytes, &resSixteen); err != nil {
  2149. utils.ErrorLog("解析失败:%v", err)
  2150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2151. return
  2152. }
  2153. res.Cainfo = resSixteen.Cainfo
  2154. res.WarnMsg = resSixteen.WarnMsg
  2155. res.Output = resSixteen.Output
  2156. res.ErrMsg = resSixteen.ErrMsg
  2157. res.RespondTime = resSixteen.RespondTime
  2158. Infcode, _ := strconv.ParseInt(resSixteen.Infcode, 10, 64)
  2159. res.Infcode = Infcode
  2160. } else {
  2161. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2162. utils.ErrorLog("解析失败:%v", err)
  2163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2164. return
  2165. }
  2166. }
  2167. if res.Infcode == 0 {
  2168. err := service.UpdataOrderStatusThree(order_id, order.Number, adminUser.CurrentOrgId, "", result)
  2169. //不同地区退费流程不一样,肇庆那边退费就包括撤销出院,内蒙古退费不包括撤销明细,所以下面需要根据不同情况进行判断
  2170. if miConfig.UserOrgId == 10215 {
  2171. record.OutHospitalStatus = 0
  2172. service.CreateHospitalRecord(&record)
  2173. }
  2174. service.UpdataOrderStatusByNumber(record.Number)
  2175. if err == nil {
  2176. c.ServeSuccessJSON(map[string]interface{}{
  2177. "msg": "退费成功",
  2178. })
  2179. } else {
  2180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2181. return
  2182. }
  2183. } else {
  2184. c.ServeSuccessJSON(map[string]interface{}{
  2185. "code": -10,
  2186. "msg": res.ErrMsg,
  2187. })
  2188. }
  2189. } else {
  2190. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  2191. if err == nil {
  2192. c.ServeSuccessJSON(map[string]interface{}{
  2193. "msg": "退费成功",
  2194. })
  2195. } else {
  2196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2197. return
  2198. }
  2199. }
  2200. }
  2201. func (c *ZHHisApiController) ZHRefundDetail() {
  2202. patient_id, _ := c.GetInt64("patient_id")
  2203. his_patient_id, _ := c.GetInt64("his_patient_id")
  2204. record_time := c.GetString("record_time")
  2205. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2206. //order_id, _ := c.GetInt64("order_id")
  2207. admin_user_id, _ := c.GetInt64("admin_user_id")
  2208. timeLayout := "2006-01-02"
  2209. loc, _ := time.LoadLocation("Local")
  2210. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2211. if err != nil {
  2212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2213. return
  2214. }
  2215. recordDateTime := theTime.Unix()
  2216. adminUser := c.GetAdminUserInfo()
  2217. theTimeTwo, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 23:59:59", loc)
  2218. if err != nil {
  2219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2220. return
  2221. }
  2222. recordDateTimeTwo := theTimeTwo.Unix()
  2223. //var prescriptions []*models.HisPrescription
  2224. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2225. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2226. if settle_accounts_type == 1 { //日结
  2227. record, _ := service.GetInHospitalRecord(his_patient_id)
  2228. infos, _ := service.GetZHHisUploadOrderInfo(adminUser.CurrentOrgId, patient_id, recordDateTime, recordDateTimeTwo, record.Number)
  2229. var isSuccess bool = true
  2230. for _, item := range infos {
  2231. var result string
  2232. var requestLog string
  2233. if miConfig.MdtrtareaAdmvs == "150499" {
  2234. //请求内网数据
  2235. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&feedetl_sn=" + item.FeedetlSn +
  2236. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2237. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "1"
  2238. resp, requestErr := http.Get(api)
  2239. if requestErr != nil {
  2240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2241. return
  2242. }
  2243. body, ioErr := ioutil.ReadAll(resp.Body)
  2244. if ioErr != nil {
  2245. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2247. return
  2248. }
  2249. var respJSON map[string]interface{}
  2250. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2251. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2253. return
  2254. }
  2255. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2256. result_byte, _ := json.Marshal(respJSON)
  2257. result = string(result_byte)
  2258. saveLog(result, requestLog, "2302", "日结退明细")
  2259. } else {
  2260. result, requestLog := service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, item.FeedetlSn, 1)
  2261. saveLog(result, requestLog, "2302", "日结退明细")
  2262. }
  2263. var dat map[string]interface{}
  2264. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2265. fmt.Println(dat)
  2266. } else {
  2267. fmt.Println(err)
  2268. }
  2269. userJSONBytes, _ := json.Marshal(dat)
  2270. var res2 ResultEmpty
  2271. var resEmpty10265 ResultEmpty10265
  2272. if miConfig.Code == "H15049901371" {
  2273. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2274. utils.ErrorLog("解析失败:%v", err)
  2275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2276. return
  2277. }
  2278. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2279. res2.Infcode = Infcode
  2280. res2.RespondTime = resEmpty10265.RespondTime
  2281. res2.ErrMsg = resEmpty10265.ErrMsg
  2282. res2.Output = resEmpty10265.Output
  2283. res2.WarnMsg = resEmpty10265.WarnMsg
  2284. } else {
  2285. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2286. utils.ErrorLog("解析失败:%v", err)
  2287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2288. return
  2289. }
  2290. }
  2291. if res2.Infcode == -1 {
  2292. isSuccess = false
  2293. }
  2294. }
  2295. if isSuccess {
  2296. err := service.UpDateOrderInfoStatus(patient_id, recordDateTime, adminUser.CurrentOrgId, recordDateTimeTwo)
  2297. if err != nil {
  2298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2299. return
  2300. }
  2301. err1 := service.UpDatePrescriptionOrderStatusTwo(patient_id, recordDateTime, adminUser.CurrentOrgId)
  2302. if err1 != nil {
  2303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2304. return
  2305. }
  2306. c.ServeSuccessJSON(map[string]interface{}{
  2307. "msg": "撤销明细成功",
  2308. })
  2309. }
  2310. } else {
  2311. //prescriptions, _ = service.GetZHMonthHisUploadPrescription(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2312. //var order models.HisOrder
  2313. //order, _ = service.GetHisOrderByID(order_id)
  2314. //record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  2315. var result string
  2316. var requestLog string
  2317. record, _ := service.GetInHospitalRecord(his_patient_id)
  2318. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2319. if config.IsOpen == 1 { //对接了医保,走医保流程
  2320. if miConfig.MdtrtareaAdmvs == "150499" {
  2321. //请求内网数据
  2322. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=0000" +
  2323. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2324. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "1"
  2325. resp, requestErr := http.Get(api)
  2326. if requestErr != nil {
  2327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2328. return
  2329. }
  2330. body, ioErr := ioutil.ReadAll(resp.Body)
  2331. if ioErr != nil {
  2332. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2334. return
  2335. }
  2336. var respJSON map[string]interface{}
  2337. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2338. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2340. return
  2341. }
  2342. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2343. result_byte, _ := json.Marshal(respJSON)
  2344. result = string(result_byte)
  2345. //saveLog(result, requestLog, "2302", "日结退明细")
  2346. } else {
  2347. result, requestLog = service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  2348. saveLog(result, requestLog, "2302", "月结退明细")
  2349. }
  2350. var dat map[string]interface{}
  2351. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2352. fmt.Println(dat)
  2353. } else {
  2354. fmt.Println(err)
  2355. }
  2356. userJSONBytes, _ := json.Marshal(dat)
  2357. var res2 ResultEmpty
  2358. var resEmpty10265 ResultEmpty10265
  2359. if miConfig.Code == "H15049901371" {
  2360. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2361. utils.ErrorLog("解析失败:%v", err)
  2362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2363. return
  2364. }
  2365. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2366. res2.Infcode = Infcode
  2367. res2.RespondTime = resEmpty10265.RespondTime
  2368. res2.ErrMsg = resEmpty10265.ErrMsg
  2369. res2.Output = resEmpty10265.Output
  2370. res2.WarnMsg = resEmpty10265.WarnMsg
  2371. } else {
  2372. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2373. utils.ErrorLog("解析失败:%v", err)
  2374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2375. return
  2376. }
  2377. }
  2378. if res2.Infcode == 0 {
  2379. err := service.UpdataHospitalOrderStatus(record.Number, adminUser.CurrentOrgId)
  2380. if err == nil {
  2381. c.ServeSuccessJSON(map[string]interface{}{
  2382. "msg": "撤销明细成功",
  2383. })
  2384. } else {
  2385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2386. return
  2387. }
  2388. } else {
  2389. c.ServeSuccessJSON(map[string]interface{}{
  2390. "code": -10,
  2391. "msg": res2.ErrMsg,
  2392. })
  2393. }
  2394. }
  2395. }
  2396. }
  2397. func (this *ZHHisApiController) GetZHOutHospitalUnCheck() {
  2398. id, _ := this.GetInt64("id")
  2399. admin_user_id, _ := this.GetInt64("admin_user_id")
  2400. adminInfo := this.GetAdminUserInfo()
  2401. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2402. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  2403. record, _ := service.GetInHospitalRecord(id)
  2404. if record.ID == 0 {
  2405. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  2406. return
  2407. }
  2408. var result string
  2409. var requestLog string
  2410. if miConfig.MdtrtareaAdmvs == "150499" {
  2411. //请求内网数据
  2412. api := "http://172.16.13.254:9532/" + "nmyb/2405?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  2413. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  2414. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2415. fmt.Println(api)
  2416. resp, requestErr := http.Get(api)
  2417. if requestErr != nil {
  2418. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2419. return
  2420. }
  2421. body, ioErr := ioutil.ReadAll(resp.Body)
  2422. if ioErr != nil {
  2423. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2424. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2425. return
  2426. }
  2427. var respJSON map[string]interface{}
  2428. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2429. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2430. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2431. return
  2432. }
  2433. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2434. result_byte, _ := json.Marshal(respJSON)
  2435. result = string(result_byte)
  2436. } else {
  2437. result, requestLog = service.ZHGdyb2405(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2438. saveLog(result, requestLog, "2405", "出院登记撤销")
  2439. }
  2440. var dat map[string]interface{}
  2441. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2442. fmt.Println(dat)
  2443. } else {
  2444. fmt.Println(err)
  2445. }
  2446. userJSONBytes, _ := json.Marshal(dat)
  2447. var res ResultEmpty
  2448. var resEmpty10265 ResultEmpty10265
  2449. if miConfig.Code == "H15049901371" {
  2450. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2451. utils.ErrorLog("解析失败:%v", err)
  2452. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2453. return
  2454. }
  2455. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2456. res.Infcode = Infcode
  2457. res.RespondTime = resEmpty10265.RespondTime
  2458. res.ErrMsg = resEmpty10265.ErrMsg
  2459. res.Output = resEmpty10265.Output
  2460. res.WarnMsg = resEmpty10265.WarnMsg
  2461. } else {
  2462. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2463. utils.ErrorLog("解析失败:%v", err)
  2464. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2465. return
  2466. }
  2467. }
  2468. if res.Infcode == 0 {
  2469. record.OutHospitalStatus = 0
  2470. service.CreateHospitalRecord(&record)
  2471. service.UpdataOrderStatusByNumber(record.Number)
  2472. this.ServeSuccessJSON(map[string]interface{}{
  2473. "msg": "撤销出院成功",
  2474. })
  2475. } else {
  2476. this.ServeSuccessJSON(map[string]interface{}{
  2477. "failed_code": -10,
  2478. "msg": res.ErrMsg,
  2479. })
  2480. }
  2481. }
  2482. func (this *ZHHisApiController) GetZHInHospitalUnCheck() {
  2483. id, _ := this.GetInt64("id")
  2484. admin_user_id, _ := this.GetInt64("admin_user_id")
  2485. adminInfo := this.GetAdminUserInfo()
  2486. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2487. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  2488. record, _ := service.GetInHospitalRecord(id)
  2489. if record.ID == 0 {
  2490. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  2491. return
  2492. }
  2493. var result string
  2494. var requestLog string
  2495. if miConfig.MdtrtareaAdmvs == "150499" {
  2496. //请求内网数据
  2497. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=" + "0000" +
  2498. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  2499. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=0"
  2500. resp, requestErr := http.Get(api)
  2501. if requestErr != nil {
  2502. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2503. return
  2504. }
  2505. body, ioErr := ioutil.ReadAll(resp.Body)
  2506. if ioErr != nil {
  2507. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2508. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2509. return
  2510. }
  2511. var respJSON map[string]interface{}
  2512. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2513. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2514. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2515. return
  2516. }
  2517. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2518. result_byte, _ := json.Marshal(respJSON)
  2519. result = string(result_byte)
  2520. saveLog(result, requestLog, "2302", "月结退明细")
  2521. } else {
  2522. result, requestLog = service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  2523. saveLog(result, requestLog, "2302", "月结退明细")
  2524. }
  2525. var dat map[string]interface{}
  2526. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2527. fmt.Println(dat)
  2528. } else {
  2529. fmt.Println(err)
  2530. }
  2531. userJSONBytes, _ := json.Marshal(dat)
  2532. var res2 ResultEmpty
  2533. var resEmpty10265 ResultEmpty10265
  2534. if miConfig.Code == "H15049901371" {
  2535. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2536. utils.ErrorLog("解析失败:%v", err)
  2537. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2538. return
  2539. }
  2540. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2541. res2.Infcode = Infcode
  2542. res2.RespondTime = resEmpty10265.RespondTime
  2543. res2.ErrMsg = resEmpty10265.ErrMsg
  2544. res2.Output = resEmpty10265.Output
  2545. res2.WarnMsg = resEmpty10265.WarnMsg
  2546. } else {
  2547. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2548. utils.ErrorLog("解析失败:%v", err)
  2549. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2550. return
  2551. }
  2552. }
  2553. if res2.Infcode == 0 {
  2554. service.UpdataHospitalOrderStatus(record.Number, adminInfo.CurrentOrgId)
  2555. var result string
  2556. var requestLog string
  2557. if miConfig.MdtrtareaAdmvs == "150499" {
  2558. //请求内网数据
  2559. api := "http://172.16.13.254:9532/" + "nmyb/2404?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  2560. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  2561. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2562. resp, requestErr := http.Get(api)
  2563. if requestErr != nil {
  2564. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2565. return
  2566. }
  2567. body, ioErr := ioutil.ReadAll(resp.Body)
  2568. if ioErr != nil {
  2569. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2570. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2571. return
  2572. }
  2573. var respJSON map[string]interface{}
  2574. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2575. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2576. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2577. return
  2578. }
  2579. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2580. result_byte, _ := json.Marshal(respJSON)
  2581. result = string(result_byte)
  2582. } else {
  2583. result, requestLog = service.ZHGdyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2584. saveLog(result, requestLog, "2404", "入院登记撤销")
  2585. }
  2586. var dat map[string]interface{}
  2587. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2588. fmt.Println(dat)
  2589. } else {
  2590. fmt.Println(err)
  2591. }
  2592. userJSONBytes, _ := json.Marshal(dat)
  2593. var res ResultEmpty
  2594. var resEmpty10265 ResultEmpty10265
  2595. if miConfig.Code == "H15049901371" {
  2596. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2597. utils.ErrorLog("解析失败:%v", err)
  2598. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2599. return
  2600. }
  2601. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2602. res.Infcode = Infcode
  2603. res.RespondTime = resEmpty10265.RespondTime
  2604. res.ErrMsg = resEmpty10265.ErrMsg
  2605. res.Output = resEmpty10265.Output
  2606. res.WarnMsg = resEmpty10265.WarnMsg
  2607. } else {
  2608. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2609. utils.ErrorLog("解析失败:%v", err)
  2610. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2611. return
  2612. }
  2613. }
  2614. if res.Infcode == 0 {
  2615. record.Status = 0
  2616. service.CreateHospitalRecord(&record)
  2617. this.ServeSuccessJSON(map[string]interface{}{
  2618. "msg": "撤销入院成功",
  2619. })
  2620. } else {
  2621. this.ServeSuccessJSON(map[string]interface{}{
  2622. "failed_code": -10,
  2623. "msg": res.ErrMsg,
  2624. })
  2625. }
  2626. } else {
  2627. this.ServeSuccessJSON(map[string]interface{}{
  2628. "code": -10,
  2629. "msg": res2.ErrMsg,
  2630. })
  2631. }
  2632. }
  2633. func saveLog(result string, request string, infno string, desc string) {
  2634. org_id, _ := beego.AppConfig.Int64("org_id")
  2635. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  2636. dir := miConfig.OrgName + "日志"
  2637. utils.Mkdir(dir)
  2638. month := time.Unix(1557042972, 0).Format("1")
  2639. year := time.Now().Format("2006")
  2640. month = time.Now().Format("01")
  2641. day := time.Now().Format("02")
  2642. hour := time.Now().Format("15")
  2643. min := time.Now().Format("04")
  2644. sec := time.Now().Format("05")
  2645. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  2646. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  2647. file_name := file + ".txt"
  2648. file_path := miConfig.OrgName + "日志" + "/" + file_name
  2649. exist, _ := utils.PathExists(file_path)
  2650. if exist { //存在
  2651. fmt.Println("存在")
  2652. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  2653. if err != nil {
  2654. fmt.Println("read fail")
  2655. }
  2656. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  2657. n, _ := f.Seek(0, 2)
  2658. _, err = f.WriteAt([]byte(content), n)
  2659. } else { //不存在
  2660. fmt.Println("文件不存在,创建文件")
  2661. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  2662. defer f.Close()
  2663. if err != nil {
  2664. } else {
  2665. _, err = f.Write([]byte("记录日志"))
  2666. }
  2667. }
  2668. }
  2669. type Charset string
  2670. const (
  2671. UTF8 = Charset("UTF-8")
  2672. GB18030 = Charset("GB18030")
  2673. )
  2674. func ConvertToString(src string, srcCode string, tagCode string) string {
  2675. srcCoder := mahonia.NewDecoder(srcCode)
  2676. srcResult := srcCoder.ConvertString(src)
  2677. tagCoder := mahonia.NewDecoder(tagCode)
  2678. _, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
  2679. result := string(cdata)
  2680. return result
  2681. }
  2682. type ELeData struct {
  2683. Data struct {
  2684. IdNo string `json:"idNo"`
  2685. IdType string `json:"idType"`
  2686. UserName string `json:"userName"`
  2687. EcToken string `json:"ecToken"`
  2688. InsuOrg string `json:"insuOrg"`
  2689. Gender string `json:"gender"`
  2690. Birthday string `json:"birthday"`
  2691. Nationality string `json:"nationality"`
  2692. Email string `json:"email"`
  2693. Extra string `json:"extra"`
  2694. } `json:"data"`
  2695. Code int `json:"code"`
  2696. Message string `json:"message"`
  2697. }
  2698. func (c *ZHHisApiController) ReadCard() {
  2699. id_card_type, _ := c.GetInt64("id_card_type")
  2700. admin_user_id, _ := c.GetInt64("admin_user_id")
  2701. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  2702. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  2703. var api string
  2704. api = "http://172.16.13.254:9532/" + "nmyb/readcard?" + "fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName +
  2705. "&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
  2706. fmt.Println(api)
  2707. resp, requestErr := http.Get(api)
  2708. if requestErr != nil {
  2709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2710. return
  2711. }
  2712. body, ioErr := ioutil.ReadAll(resp.Body)
  2713. if ioErr != nil {
  2714. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2716. return
  2717. }
  2718. var respJSON map[string]interface{}
  2719. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2720. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2722. return
  2723. }
  2724. var status string
  2725. status = respJSON["data"].(map[string]interface{})["status"].(string)
  2726. card_type := respJSON["data"].(map[string]interface{})["type"].(string)
  2727. //console.log()
  2728. fmt.Println("type===")
  2729. fmt.Println(card_type)
  2730. var token string
  2731. var res ResultTwo //1101结果
  2732. var res10265 ResultTwo10265 //1101结果
  2733. var card_info string //卡信息
  2734. var busi_card_info string
  2735. card_info = respJSON["data"].(map[string]interface{})["card_info"].(string)
  2736. busi_card_info = respJSON["data"].(map[string]interface{})["busi_card_info"].(string)
  2737. if status == "0" { //读卡成功
  2738. if card_type == "1" {
  2739. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  2740. result, _ := json.Marshal(respJSON)
  2741. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  2742. utils.ErrorLog("解析失败:%v", err)
  2743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2744. return
  2745. }
  2746. res.ErrMsg = res10265.ErrMsg
  2747. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  2748. res.Infcode = infocode
  2749. res.Output = res10265.Output
  2750. res.InfRefmsgid = res10265.InfRefmsgid
  2751. } else {
  2752. //var card_info string //卡信息
  2753. //var busi_card_info string
  2754. token = respJSON["data"].(map[string]interface{})["token"].(string)
  2755. //busi_card_info = respJSON["data"].(map[string]interface{})["busi_card_info"].(string)
  2756. //fmt.Println(card_info)
  2757. //fmt.Println(busi_card_info)
  2758. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  2759. result, _ := json.Marshal(respJSON)
  2760. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  2761. utils.ErrorLog("解析失败:%v", err)
  2762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2763. return
  2764. }
  2765. res.ErrMsg = res10265.ErrMsg
  2766. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  2767. res.Infcode = infocode
  2768. res.Output = res10265.Output
  2769. res.InfRefmsgid = res10265.InfRefmsgid
  2770. }
  2771. if res.Infcode == 0 {
  2772. var insutypes []string
  2773. var insutype string
  2774. var is390 int = 0
  2775. var is310 int = 0
  2776. for _, item := range res.Output.Iinfo {
  2777. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  2778. insutypes = append(insutypes, item.Insutype)
  2779. }
  2780. }
  2781. if len(insutypes) == 1 {
  2782. insutype = insutypes[0]
  2783. } else {
  2784. for _, i := range insutypes {
  2785. if i == "390" {
  2786. is390 = 1
  2787. }
  2788. if i == "310" {
  2789. is310 = 1
  2790. }
  2791. }
  2792. }
  2793. if is390 == 1 {
  2794. insutype = "390"
  2795. }
  2796. if is310 == 1 {
  2797. insutype = "310"
  2798. }
  2799. if len(insutypes) == 0 {
  2800. insutype = "310"
  2801. }
  2802. patient, err := service.GetPatientByIDCard(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  2803. if err == gorm.ErrRecordNotFound {
  2804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  2805. return
  2806. } else if err != nil {
  2807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2808. return
  2809. } else {
  2810. if card_type == "1" {
  2811. bas := strings.Split(card_info, "|")
  2812. basNumber := bas[2]
  2813. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  2814. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  2815. infoStr := string(Iinfos)
  2816. idetinfoStr := string(Idetinfos)
  2817. psn := &models.HisPsn{
  2818. PsnNo: res.Output.Baseinfo.PsnNo,
  2819. Age: res.Output.Baseinfo.Age,
  2820. PatientId: patient.ID,
  2821. Certno: res.Output.Baseinfo.Certno,
  2822. Brdy: res.Output.Baseinfo.Brdy,
  2823. Gend: res.Output.Baseinfo.Gend,
  2824. Naty: res.Output.Baseinfo.Naty,
  2825. PsnCertType: res.Output.Baseinfo.PsnCertType,
  2826. PsnName: res.Output.Baseinfo.PsnName,
  2827. Idetinfo: idetinfoStr,
  2828. Insuinfo: infoStr,
  2829. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2830. CardInfo: card_info,
  2831. VerifyNumber: busi_card_info,
  2832. }
  2833. service.CreateHisPsn(psn)
  2834. c.ServeSuccessJSON(map[string]interface{}{
  2835. "patient": patient,
  2836. "number": basNumber,
  2837. "info": res,
  2838. "insutype": insutype,
  2839. })
  2840. } else {
  2841. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  2842. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  2843. infoStr := string(Iinfos)
  2844. idetinfoStr := string(Idetinfos)
  2845. psn := &models.HisPsn{
  2846. PsnNo: res.Output.Baseinfo.PsnNo,
  2847. Age: res.Output.Baseinfo.Age,
  2848. PatientId: patient.ID,
  2849. Certno: res.Output.Baseinfo.Certno,
  2850. Brdy: res.Output.Baseinfo.Brdy,
  2851. Gend: res.Output.Baseinfo.Gend,
  2852. Naty: res.Output.Baseinfo.Naty,
  2853. PsnCertType: res.Output.Baseinfo.PsnCertType,
  2854. PsnName: res.Output.Baseinfo.PsnName,
  2855. Idetinfo: idetinfoStr,
  2856. Insuinfo: infoStr,
  2857. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2858. CardInfo: card_info,
  2859. VerifyNumber: token,
  2860. }
  2861. service.CreateHisPsn(psn)
  2862. c.ServeSuccessJSON(map[string]interface{}{
  2863. "patient": patient,
  2864. "number": token,
  2865. "info": res,
  2866. "insutype": insutype,
  2867. })
  2868. }
  2869. }
  2870. } else {
  2871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  2872. return
  2873. }
  2874. } else { //读卡失败
  2875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  2876. return
  2877. }
  2878. }
  2879. var initFlag int64 = 0
  2880. func (c *ZHHisApiController) TestGetBasBaseInit() {
  2881. DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
  2882. Iinit := DllDef.MustFindProc("Init")
  2883. //miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  2884. str := make([]byte, 2048)
  2885. inputData := make(map[string]interface{})
  2886. inputData["IP"] = "10.144.211.75"
  2887. inputData["PORT"] = 7021
  2888. inputData["TIMEOUT"] = 180
  2889. inputData["LOG_PATH"] = "C:\\log\\"
  2890. //inputData["SFZ_DRIVER_TYPE"] = 0
  2891. inputData["URL"] = "/call1"
  2892. bytesData, _ := json.Marshal(inputData)
  2893. fmt.Println(inputData)
  2894. fmt.Println(bytesData)
  2895. ret, _, err := Iinit.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&str[0])))
  2896. if ret != 0 {
  2897. fmt.Println("SSCard的报错原因:", err)
  2898. fmt.Println("SSCard的运算结果为:", ret)
  2899. fmt.Println("SSCard的返回结果为:", string(str))
  2900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  2901. return
  2902. }
  2903. fmt.Println("SSCard的返回结果为:", string(str))
  2904. result := int(ret)
  2905. fmt.Println("SSCard的运算结果为1:", result)
  2906. //initFlag = 1
  2907. return
  2908. }
  2909. func (c *ZHHisApiController) GetSFZBaseInfo() string {
  2910. DllDef := syscall.MustLoadDLL("SSCard.dll")
  2911. readCard := DllDef.MustFindProc("ReadSFZ")
  2912. if readCard == nil {
  2913. fmt.Println("readcard is nil")
  2914. readCard = DllDef.MustFindProc("ReadSFZ")
  2915. }
  2916. str := make([]byte, 256)
  2917. str1 := make([]byte, 256)
  2918. r, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  2919. fmt.Println(r)
  2920. return string(str)
  2921. }
  2922. func (c *ZHHisApiController) GetBasBaseInfo(fixmedins_code string, mdtrtarea_admvs string, opter_name string, opter_id string, fixmedins_name string) string {
  2923. DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
  2924. readCard := DllDef.MustFindProc("ReadCardBas")
  2925. fmt.Println(readCard)
  2926. fmt.Println("!!!!!")
  2927. month := time.Unix(1557042972, 0).Format("1")
  2928. year := time.Now().Format("2006")
  2929. month = time.Now().Format("01")
  2930. day := time.Now().Format("02")
  2931. hour := time.Now().Format("15")
  2932. min := time.Now().Format("04")
  2933. sec := time.Now().Format("05")
  2934. msec := time.Now().Format("000")
  2935. timestamp := time.Now().Unix()
  2936. tempTime := time.Unix(timestamp, 0)
  2937. //timeFormat := tempTime.Format("20060102150405")
  2938. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  2939. //randNum := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000)
  2940. inputData := make(map[string]interface{})
  2941. inputData["infno"] = "1199"
  2942. //inputData["msgid"] = "7021"
  2943. inputData["msgid"] = fixmedins_code + year + month + day + hour + min + sec + msec + "0" // 发送方报文 ID
  2944. inputData["mdtrtarea_admvs"] = mdtrtarea_admvs // 发送方报文 ID
  2945. inputData["recer_sys_code"] = "01"
  2946. inputData["infver"] = "V1.0"
  2947. inputData["opter_type"] = "1"
  2948. inputData["opter"] = opter_id
  2949. inputData["opter_name"] = opter_name
  2950. inputData["inf_time"] = timeFormatOne
  2951. inputData["fixmedins_code"] = fixmedins_code
  2952. inputData["fixmedins_name"] = fixmedins_name
  2953. inputData["dev_no"] = ""
  2954. inputData["dev_safe_info"] = ""
  2955. inputData["cainfo"] = ""
  2956. inputData["signtype"] = ""
  2957. inputData["sign_no"] = ""
  2958. bytesData, _ := json.Marshal(inputData)
  2959. fmt.Println(string(bytesData))
  2960. pBusiCardInfo := make([]byte, 8192)
  2961. ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
  2962. fmt.Println(ret2)
  2963. fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
  2964. fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
  2965. if ret2 != 0 {
  2966. return ""
  2967. }
  2968. return DeleteExtraSpace(string(pBusiCardInfo))
  2969. }
  2970. func DeleteExtraSpace(s string) string {
  2971. //删除字符串中的多余空格,有多个空格时,仅保留一个空格
  2972. s1 := strings.Replace(s, " ", " ", -1) //替换tab为空格
  2973. regstr := "\\s{2,}" //两个及两个以上空格的正则表达式
  2974. reg, _ := regexp.Compile(regstr) //编译正则表达式
  2975. s2 := make([]byte, len(s1)) //定义字符数组切片
  2976. copy(s2, s1) //将字符串复制到切片
  2977. spc_index := reg.FindStringIndex(string(s2)) //在字符串中搜索
  2978. for len(spc_index) > 0 { //找到适配项
  2979. s2 = append(s2[:spc_index[0]+1], s2[spc_index[1]:]...) //删除多余空格
  2980. spc_index = reg.FindStringIndex(string(s2)) //继续在字符串中搜索
  2981. }
  2982. return string(s2)
  2983. }
  2984. func (c *ZHHisApiController) GetELeInfo(code string, operator_id string, operator_name string) (string, string) {
  2985. DllDef := syscall.MustLoadDLL("NationECCode.dll")
  2986. readCard := DllDef.MustFindProc("NationEcTrans")
  2987. fmt.Println(readCard)
  2988. fmt.Println("!!!!!")
  2989. pBusiCardInfo := make([]byte, 8192)
  2990. input := make(map[string]interface{})
  2991. inputData := make(map[string]interface{})
  2992. inputData["orgId"] = code
  2993. inputData["businessType"] = "01101"
  2994. inputData["operatorId"] = operator_id
  2995. inputData["operatorName"] = operator_name
  2996. inputData["officeId"] = "001"
  2997. inputData["officeName"] = "血透室"
  2998. inputData["deviceType"] = ""
  2999. input["data"] = inputData
  3000. input["orgId"] = code
  3001. input["transType"] = "ec.query"
  3002. bytesData, _ := json.Marshal(input)
  3003. gdyb_url := beego.AppConfig.String("gdyb_url")
  3004. url := gdyb_url + "/localcfc/api/hsecfc/localQrCodeQuery"
  3005. ret2, _, _ := readCard.Call(StrPtr(url), StrPtr(string(bytesData)), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
  3006. fmt.Println(ret2)
  3007. fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
  3008. fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
  3009. if ret2 != 0 {
  3010. return "", ""
  3011. }
  3012. return DeleteExtraSpace(""), DeleteExtraSpace(string(pBusiCardInfo))
  3013. }
  3014. func StrPtr(s string) uintptr {
  3015. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  3016. }
  3017. func Remove0000(s string) string {
  3018. str := make([]rune, 0, len(s))
  3019. for _, v := range []rune(s) {
  3020. if v == 0 {
  3021. continue
  3022. }
  3023. str = append(str, v)
  3024. }
  3025. return string(str)
  3026. }
  3027. func IntPtr(n int) uintptr {
  3028. return uintptr(n)
  3029. }