zh_his_api_controller.go 92KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790
  1. package zh
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "gdyb/controllers"
  6. "gdyb/enums"
  7. "gdyb/models"
  8. "gdyb/service"
  9. "gdyb/utils"
  10. "github.com/astaxie/beego"
  11. "github.com/axgle/mahonia"
  12. "github.com/jinzhu/gorm"
  13. "math"
  14. "math/rand"
  15. "os"
  16. "regexp"
  17. "strconv"
  18. "strings"
  19. "syscall"
  20. "time"
  21. "unsafe"
  22. )
  23. type ZHHisApiController struct {
  24. controllers.BaseAuthAPIController
  25. }
  26. type ResultTwo struct {
  27. ErrMsg string `json:"err_msg"`
  28. InfRefmsgid string `json:"inf_refmsgid"`
  29. Infcode int64 `json:"infcode"`
  30. Output struct {
  31. Baseinfo struct {
  32. Age float64 `json:"age"`
  33. Brdy string `json:"brdy"`
  34. Certno string `json:"certno"`
  35. Gend string `json:"gend"`
  36. Naty string `json:"naty"`
  37. PsnCertType string `json:"psn_cert_type"`
  38. PsnName string `json:"psn_name"`
  39. PsnNo string `json:"psn_no"`
  40. } `json:"baseinfo"`
  41. Idetinfo []interface{} `json:"idetinfo"`
  42. Iinfo []struct {
  43. Balc float64 `json:"balc"`
  44. CvlservFlag string `json:"cvlserv_flag"`
  45. EmpName string `json:"emp_name"`
  46. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  47. Insutype string `json:"insutype"`
  48. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  49. PausInsuDate string `json:"paus_insu_date"`
  50. PsnInsuDate string `json:"psn_insu_date"`
  51. PsnInsuStas string `json:"psn_insu_stas"`
  52. PsnType string `json:"psn_type"`
  53. } `json:"insuinfo"`
  54. } `json:"output"`
  55. RefmsgTime string `json:"refmsg_time"`
  56. RespondTime string `json:"respond_time"`
  57. Signtype interface{} `json:"signtype"`
  58. WarnInfo interface{} `json:"warn_info"`
  59. }
  60. type ResultTwo10265 struct {
  61. ErrMsg string `json:"err_msg"`
  62. InfRefmsgid string `json:"inf_refmsgid"`
  63. Infcode string `json:"infcode"`
  64. Output struct {
  65. Baseinfo struct {
  66. Age float64 `json:"age"`
  67. Brdy string `json:"brdy"`
  68. Certno string `json:"certno"`
  69. Gend string `json:"gend"`
  70. Naty string `json:"naty"`
  71. PsnCertType string `json:"psn_cert_type"`
  72. PsnName string `json:"psn_name"`
  73. PsnNo string `json:"psn_no"`
  74. } `json:"baseinfo"`
  75. Idetinfo []interface{} `json:"idetinfo"`
  76. Iinfo []struct {
  77. Balc float64 `json:"balc"`
  78. CvlservFlag string `json:"cvlserv_flag"`
  79. EmpName string `json:"emp_name"`
  80. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  81. Insutype string `json:"insutype"`
  82. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  83. PausInsuDate string `json:"paus_insu_date"`
  84. PsnInsuDate string `json:"psn_insu_date"`
  85. PsnInsuStas string `json:"psn_insu_stas"`
  86. PsnType string `json:"psn_type"`
  87. } `json:"insuinfo"`
  88. } `json:"output"`
  89. RefmsgTime string `json:"refmsg_time"`
  90. RespondTime string `json:"respond_time"`
  91. Signtype interface{} `json:"signtype"`
  92. WarnInfo interface{} `json:"warn_info"`
  93. }
  94. type ResultThree struct {
  95. Cainfo interface{} `json:"cainfo"`
  96. ErrMsg string `json:"err_msg"`
  97. InfRefmsgid string `json:"inf_refmsgid"`
  98. Infcode int64 `json:"infcode"`
  99. Output struct {
  100. Result struct {
  101. MdtrtID string `json:"mdtrt_id"`
  102. } `json:"result"`
  103. } `json:"output"`
  104. RefmsgTime string `json:"refmsg_time"`
  105. RespondTime string `json:"respond_time"`
  106. Signtype interface{} `json:"signtype"`
  107. WarnMsg interface{} `json:"warn_msg"`
  108. }
  109. type ResultThree10265 struct {
  110. Cainfo interface{} `json:"cainfo"`
  111. ErrMsg string `json:"err_msg"`
  112. InfRefmsgid string `json:"inf_refmsgid"`
  113. Infcode string `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 ResultFour struct {
  125. Cainfo string `json:"cainfo"`
  126. ErrMsg string `json:"err_msg"`
  127. InfRefmsgid string `json:"inf_refmsgid"`
  128. Infcode int64 `json:"infcode"`
  129. Output struct {
  130. Result []struct {
  131. BasMednFlag string `json:"bas_medn_flag"`
  132. ChldMedcFlag string `json:"chld_medc_flag"`
  133. ChrgitmLv string `json:"chrgitm_lv"`
  134. Cnt float64 `json:"cnt"`
  135. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  136. DrtReimFlag string `json:"drt_reim_flag"`
  137. FeedetlSn string `json:"feedetl_sn"`
  138. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  139. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  140. InscpScpAmt float64 `json:"inscp_scp_amt"`
  141. ListSpItemFlag string `json:"list_sp_item_flag"`
  142. LmtUsedFlag string `json:"lmt_used_flag"`
  143. MedChrgitmType string `json:"med_chrgitm_type"`
  144. Memo string `json:"memo"`
  145. OverlmtAmt float64 `json:"overlmt_amt"`
  146. PreselfpayAmt float64 `json:"preselfpay_amt"`
  147. Pric float64 `json:"pric"`
  148. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  149. SelfpayProp float64 `json:"selfpay_prop"`
  150. } `json:"result"`
  151. } `json:"output"`
  152. RefmsgTime string `json:"refmsg_time"`
  153. RespondTime string `json:"respond_time"`
  154. Signtype string `json:"signtype"`
  155. WarnMsg string `json:"warn_msg"`
  156. }
  157. type ResultFour10265 struct {
  158. Cainfo string `json:"cainfo"`
  159. ErrMsg string `json:"err_msg"`
  160. InfRefmsgid string `json:"inf_refmsgid"`
  161. Infcode string `json:"infcode"`
  162. Output struct {
  163. Result []struct {
  164. BasMednFlag string `json:"bas_medn_flag"`
  165. ChldMedcFlag string `json:"chld_medc_flag"`
  166. ChrgitmLv string `json:"chrgitm_lv"`
  167. Cnt float64 `json:"cnt"`
  168. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  169. DrtReimFlag string `json:"drt_reim_flag"`
  170. FeedetlSn string `json:"feedetl_sn"`
  171. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  172. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  173. InscpScpAmt float64 `json:"inscp_scp_amt"`
  174. ListSpItemFlag string `json:"list_sp_item_flag"`
  175. LmtUsedFlag string `json:"lmt_used_flag"`
  176. MedChrgitmType string `json:"med_chrgitm_type"`
  177. Memo string `json:"memo"`
  178. OverlmtAmt float64 `json:"overlmt_amt"`
  179. PreselfpayAmt float64 `json:"preselfpay_amt"`
  180. Pric float64 `json:"pric"`
  181. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  182. SelfpayProp float64 `json:"selfpay_prop"`
  183. } `json:"result"`
  184. } `json:"output"`
  185. RefmsgTime string `json:"refmsg_time"`
  186. RespondTime string `json:"respond_time"`
  187. Signtype string `json:"signtype"`
  188. WarnMsg string `json:"warn_msg"`
  189. }
  190. type ResultFive struct {
  191. Balc float64 `json:"balc"`
  192. CvlservFlag string `json:"cvlserv_flag"`
  193. EmpName string `json:"emp_name"`
  194. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  195. Insutype string `json:"insutype"`
  196. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  197. PausInsuDate string `json:"paus_insu_date"`
  198. PsnInsuDate string `json:"psn_insu_date"`
  199. PsnInsuStas string `json:"psn_insu_stas"`
  200. PsnType string `json:"psn_type"`
  201. }
  202. type ResultSeven struct {
  203. Cainfo string `json:"cainfo"`
  204. ErrMsg string `json:"err_msg"`
  205. InfRefmsgid string `json:"inf_refmsgid"`
  206. Infcode int64 `json:"infcode"`
  207. Output struct {
  208. Setldetail []interface{} `json:"setldetail"`
  209. Setlinfo struct {
  210. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  211. AcctPay float64 `json:"acct_pay"`
  212. ActPayDedc float64 `json:"act_pay_dedc"`
  213. Age float64 `json:"age"`
  214. Balc float64 `json:"balc"`
  215. Brdy string `json:"brdy"`
  216. Certno string `json:"certno"`
  217. ClrOptins string `json:"clr_optins"`
  218. ClrType string `json:"clr_type"`
  219. ClrWay string `json:"clr_way"`
  220. CvlservFlag string `json:"cvlserv_flag"`
  221. CvlservPay float64 `json:"cvlserv_pay"`
  222. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  223. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  224. Gend string `json:"gend"`
  225. HifesPay float64 `json:"hifes_pay"`
  226. HifmiPay float64 `json:"hifmi_pay"`
  227. HifpPay float64 `json:"hifp_pay"`
  228. HospPartAmt float64 `json:"hosp_part_amt"`
  229. InscpScpAmt float64 `json:"inscp_scp_amt"`
  230. Insutype string `json:"insutype"`
  231. MafPay float64 `json:"maf_pay"`
  232. MdtrtCertType string `json:"mdtrt_cert_type"`
  233. HifobPay float64 `json:"hifob_pay"`
  234. MdtrtID string `json:"mdtrt_id"`
  235. MedType string `json:"med_type"`
  236. MedfeeSumamt float64 `json:"medfee_sumamt"`
  237. MedinsSetlID string `json:"medins_setl_id"`
  238. Naty string `json:"naty"`
  239. OthPay float64 `json:"oth_pay"`
  240. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  241. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  242. PreselfpayAmt float64 `json:"preselfpay_amt"`
  243. PsnCashPay float64 `json:"psn_cash_pay"`
  244. PsnCertType string `json:"psn_cert_type"`
  245. PsnName string `json:"psn_name"`
  246. PsnNo string `json:"psn_no"`
  247. PsnPartAmt float64 `json:"psn_part_amt"`
  248. PsnType string `json:"psn_type"`
  249. SetlID string `json:"setl_id"`
  250. SetlTime string `json:"setl_time"`
  251. } `json:"setlinfo"`
  252. } `json:"output"`
  253. RefmsgTime string `json:"refmsg_time"`
  254. RespondTime string `json:"respond_time"`
  255. Signtype interface{} `json:"signtype"`
  256. WarnMsg interface{} `json:"warn_msg"`
  257. }
  258. type ResultSeven10265 struct {
  259. Cainfo string `json:"cainfo"`
  260. ErrMsg string `json:"err_msg"`
  261. InfRefmsgid string `json:"inf_refmsgid"`
  262. Infcode string `json:"infcode"`
  263. Output struct {
  264. Setldetail []interface{} `json:"setldetail"`
  265. Setlinfo struct {
  266. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  267. AcctPay float64 `json:"acct_pay"`
  268. ActPayDedc float64 `json:"act_pay_dedc"`
  269. Age float64 `json:"age"`
  270. Balc float64 `json:"balc"`
  271. Brdy string `json:"brdy"`
  272. Certno string `json:"certno"`
  273. ClrOptins string `json:"clr_optins"`
  274. ClrType string `json:"clr_type"`
  275. ClrWay string `json:"clr_way"`
  276. CvlservFlag string `json:"cvlserv_flag"`
  277. CvlservPay float64 `json:"cvlserv_pay"`
  278. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  279. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  280. Gend string `json:"gend"`
  281. HifesPay float64 `json:"hifes_pay"`
  282. HifmiPay float64 `json:"hifmi_pay"`
  283. HifpPay float64 `json:"hifp_pay"`
  284. HospPartAmt float64 `json:"hosp_part_amt"`
  285. InscpScpAmt float64 `json:"inscp_scp_amt"`
  286. Insutype string `json:"insutype"`
  287. MafPay float64 `json:"maf_pay"`
  288. MdtrtCertType string `json:"mdtrt_cert_type"`
  289. HifobPay float64 `json:"hifob_pay"`
  290. MdtrtID string `json:"mdtrt_id"`
  291. MedType string `json:"med_type"`
  292. MedfeeSumamt float64 `json:"medfee_sumamt"`
  293. MedinsSetlID string `json:"medins_setl_id"`
  294. Naty string `json:"naty"`
  295. OthPay float64 `json:"oth_pay"`
  296. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  297. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  298. PreselfpayAmt float64 `json:"preselfpay_amt"`
  299. PsnCashPay float64 `json:"psn_cash_pay"`
  300. PsnCertType string `json:"psn_cert_type"`
  301. PsnName string `json:"psn_name"`
  302. PsnNo string `json:"psn_no"`
  303. PsnPartAmt float64 `json:"psn_part_amt"`
  304. PsnType string `json:"psn_type"`
  305. SetlID string `json:"setl_id"`
  306. SetlTime string `json:"setl_time"`
  307. } `json:"setlinfo"`
  308. } `json:"output"`
  309. RefmsgTime string `json:"refmsg_time"`
  310. RespondTime string `json:"respond_time"`
  311. Signtype interface{} `json:"signtype"`
  312. WarnMsg interface{} `json:"warn_msg"`
  313. }
  314. type ResultSixteen struct {
  315. Cainfo string `json:"cainfo"`
  316. ErrMsg string `json:"err_msg"`
  317. InfRefmsgid string `json:"inf_refmsgid"`
  318. Infcode int64 `json:"infcode"`
  319. Output struct {
  320. Setldetail []interface{} `json:"setldetail"`
  321. Setlinfo struct {
  322. MdtrtID string `json:"mdtrt_id"`
  323. SetlID string `json:"setl_id"`
  324. ClrOptins string `json:"clr_optins"`
  325. SetlTime string `json:"setl_time"`
  326. MedfeeSumamt float64 `json:"medfee_sumamt"`
  327. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  328. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  329. PreselfpayAmt float64 `json:"preselfpay_amt"`
  330. InscpScpAmt float64 `json:"inscp_scp_amt"`
  331. ActPayDedc float64 `json:"act_pay_dedc"`
  332. HifpPay float64 `json:"hifp_pay"`
  333. PoolPropSe float64 `json:"pool_prop_selfpay"`
  334. Lfpay float64 `json:"selfpay"`
  335. CvlservPay float64 `json:"cvlserv_pay"`
  336. HifesPay float64 `json:"hifes_pay"`
  337. HifmiPay float64 `json:"hifmi_pay"`
  338. HifobPay float64 `json:"hifob_pay"`
  339. MafPay float64 `json:"maf_pay"`
  340. OthPay float64 `json:"oth_pay"`
  341. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  342. PsnPartAmt float64 `json:"psn_part_amt"`
  343. AcctPay float64 `json:"acct_pay"`
  344. Balc float64 `json:"balc"`
  345. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  346. HospPartAmt float64 `json:"hosp_part_amt"`
  347. MedinsSetlID string `json:"medins_setl_id"`
  348. PdnCashPay string `json:"pdn_cash_pay"`
  349. } `json:"setlinfo"`
  350. } `json:"output"`
  351. RefmsgTime string `json:"refmsg_time"`
  352. RespondTime string `json:"respond_time"`
  353. Signtype interface{} `json:"signtype"`
  354. WarnMsg interface{} `json:"warn_msg"`
  355. }
  356. type ResultSixteen10265 struct {
  357. Cainfo string `json:"cainfo"`
  358. ErrMsg string `json:"err_msg"`
  359. InfRefmsgid string `json:"inf_refmsgid"`
  360. Infcode string `json:"infcode"`
  361. Output struct {
  362. Setldetail []interface{} `json:"setldetail"`
  363. Setlinfo struct {
  364. MdtrtID string `json:"mdtrt_id"`
  365. SetlID string `json:"setl_id"`
  366. ClrOptins string `json:"clr_optins"`
  367. SetlTime string `json:"setl_time"`
  368. MedfeeSumamt float64 `json:"medfee_sumamt"`
  369. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  370. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  371. PreselfpayAmt float64 `json:"preselfpay_amt"`
  372. InscpScpAmt float64 `json:"inscp_scp_amt"`
  373. ActPayDedc float64 `json:"act_pay_dedc"`
  374. HifpPay float64 `json:"hifp_pay"`
  375. PoolPropSe float64 `json:"pool_prop_selfpay"`
  376. Lfpay float64 `json:"selfpay"`
  377. CvlservPay float64 `json:"cvlserv_pay"`
  378. HifesPay float64 `json:"hifes_pay"`
  379. HifmiPay float64 `json:"hifmi_pay"`
  380. HifobPay float64 `json:"hifob_pay"`
  381. MafPay float64 `json:"maf_pay"`
  382. OthPay float64 `json:"oth_pay"`
  383. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  384. PsnPartAmt float64 `json:"psn_part_amt"`
  385. AcctPay float64 `json:"acct_pay"`
  386. Balc float64 `json:"balc"`
  387. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  388. HospPartAmt float64 `json:"hosp_part_amt"`
  389. MedinsSetlID string `json:"medins_setl_id"`
  390. PdnCashPay string `json:"pdn_cash_pay"`
  391. } `json:"setlinfo"`
  392. } `json:"output"`
  393. RefmsgTime string `json:"refmsg_time"`
  394. RespondTime string `json:"respond_time"`
  395. Signtype interface{} `json:"signtype"`
  396. WarnMsg interface{} `json:"warn_msg"`
  397. }
  398. type Custom struct {
  399. DetItemFeeSumamt string
  400. Cut string
  401. FeedetlSn string
  402. Price string
  403. MedListCodg string
  404. Type int64
  405. AdviceId int64
  406. ProjectId int64
  407. ItemId int64
  408. }
  409. type ResultEmpty struct {
  410. Cainfo interface{} `json:"cainfo"`
  411. ErrMsg string `json:"err_msg"`
  412. InfRefmsgid string `json:"inf_refmsgid"`
  413. Infcode int64 `json:"infcode"`
  414. Output struct {
  415. } `json:"output"`
  416. RefmsgTime string `json:"refmsg_time"`
  417. RespondTime string `json:"respond_time"`
  418. Signtype interface{} `json:"signtype"`
  419. WarnMsg interface{} `json:"warn_msg"`
  420. }
  421. type ResultEmpty10265 struct {
  422. Cainfo interface{} `json:"cainfo"`
  423. ErrMsg string `json:"err_msg"`
  424. InfRefmsgid string `json:"inf_refmsgid"`
  425. Infcode string `json:"infcode"`
  426. Output struct {
  427. } `json:"output"`
  428. RefmsgTime string `json:"refmsg_time"`
  429. RespondTime string `json:"respond_time"`
  430. Signtype interface{} `json:"signtype"`
  431. WarnMsg interface{} `json:"warn_msg"`
  432. }
  433. type CustomResult struct {
  434. BasMednFlag string `json:"bas_medn_flag"`
  435. ChldMedcFlag string `json:"chld_medc_flag"`
  436. ChrgitmLv string `json:"chrgitm_lv"`
  437. Cnt float64 `json:"cnt"`
  438. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  439. DrtReimFlag string `json:"drt_reim_flag"`
  440. FeedetlSn string `json:"feedetl_sn"`
  441. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  442. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  443. InscpScpAmt float64 `json:"inscp_scp_amt"`
  444. ListSpItemFlag string `json:"list_sp_item_flag"`
  445. LmtUsedFlag string `json:"lmt_used_flag"`
  446. MedChrgitmType string `json:"med_chrgitm_type"`
  447. Memo string `json:"memo"`
  448. OverlmtAmt float64 `json:"overlmt_amt"`
  449. PreselfpayAmt float64 `json:"preselfpay_amt"`
  450. Pric float64 `json:"pric"`
  451. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  452. SelfpayProp float64 `json:"selfpay_prop"`
  453. }
  454. func ZHHisManagerApiRegistRouters() {
  455. beego.Router("/zh/api/inhopitalcheck/get", &ZHHisApiController{}, "get:GetZHInHospitalCheck")
  456. beego.Router("/zh/api/outhopitalcheck/get", &ZHHisApiController{}, "get:GetZHOutHospitalCheck")
  457. beego.Router("/zh/api/uploadinfo/get", &ZHHisApiController{}, "get:GetUploadInfo")
  458. beego.Router("/zh/api/presettle/get", &ZHHisApiController{}, "get:GetPreSettleInfo")
  459. beego.Router("/zh/api/settle/get", &ZHHisApiController{}, "get:GetSettleInfo")
  460. beego.Router("/zh/api/inthopitaluncheck/get", &ZHHisApiController{}, "get:GetZHInHospitalUnCheck")
  461. beego.Router("/zh/api/outhopitaluncheck/get", &ZHHisApiController{}, "get:GetZHOutHospitalUnCheck")
  462. beego.Router("/zh/api/refund", &ZHHisApiController{}, "get:ZHRefund")
  463. beego.Router("/zh/api/refunddetail", &ZHHisApiController{}, "get:ZHRefundDetail")
  464. beego.Router("/zh/api/patient/info", &ZHHisApiController{}, "get:GetZHPatientInfo")
  465. beego.Router("/zh/api/readcard", &ZHHisApiController{}, "get:ReadCard")
  466. }
  467. func (c *ZHHisApiController) GetZHPatientInfo() {
  468. id_card_no := c.GetString("id_card_no")
  469. admin_user_id, _ := c.GetInt64("admin_user_id")
  470. patient, _ := service.GetPatientByIDCard(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  471. if patient.ID == 0 {
  472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  473. return
  474. }
  475. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  476. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  477. config, _ := service.GetMedicalInsuranceConfig(c.GetAdminUserInfo().CurrentOrgId)
  478. if config.IsOpen == 1 {
  479. result := service.Gdyb1101A(id_card_no, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, patient.Name)
  480. var dat map[string]interface{}
  481. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  482. fmt.Println(dat)
  483. } else {
  484. fmt.Println(err)
  485. }
  486. userJSONBytes, _ := json.Marshal(dat)
  487. var res ResultTwo
  488. var resTwo10265 ResultTwo10265
  489. if miConfig.Code == "H15049901371" {
  490. if err := json.Unmarshal(userJSONBytes, &resTwo10265); err != nil {
  491. utils.ErrorLog("解析失败:%v", err)
  492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  493. return
  494. }
  495. Infcode, _ := strconv.ParseInt(resTwo10265.Infcode, 10, 64)
  496. res.Infcode = Infcode
  497. res.ErrMsg = resTwo10265.ErrMsg
  498. res.Output = resTwo10265.Output
  499. res.InfRefmsgid = resTwo10265.InfRefmsgid
  500. res.RespondTime = resTwo10265.RespondTime
  501. res.WarnInfo = resTwo10265.WarnInfo
  502. } else {
  503. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  504. utils.ErrorLog("解析失败:%v", err)
  505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  506. return
  507. }
  508. }
  509. var insutypes []string
  510. var insutype string
  511. var is390 int = 0
  512. var is310 int = 0
  513. for _, item := range res.Output.Iinfo {
  514. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  515. insutypes = append(insutypes, item.Insutype)
  516. }
  517. }
  518. if len(insutypes) == 1 {
  519. insutype = insutypes[0]
  520. } else {
  521. for _, i := range insutypes {
  522. if i == "390" {
  523. is390 = 1
  524. }
  525. if i == "310" {
  526. is310 = 1
  527. }
  528. }
  529. }
  530. if is390 == 1 {
  531. insutype = "390"
  532. }
  533. if is310 == 1 {
  534. insutype = "310"
  535. }
  536. if len(insutypes) == 0 {
  537. insutype = "310"
  538. }
  539. if res.Infcode != 0 {
  540. c.ServeSuccessJSON(map[string]interface{}{
  541. "failed_code": -10,
  542. "msg": res.ErrMsg,
  543. })
  544. } else {
  545. c.ServeSuccessJSON(map[string]interface{}{
  546. "failed_code": 0,
  547. "info": res,
  548. "insutype": insutype,
  549. })
  550. }
  551. }
  552. }
  553. func (c *ZHHisApiController) GetZHInHospitalCheck() {
  554. id, _ := c.GetInt64("id")
  555. record_time := c.GetString("record_time")
  556. name := c.GetString("name")
  557. phone := c.GetString("phone")
  558. id_card_type, _ := c.GetInt64("id_card_type")
  559. certificates, _ := c.GetInt64("certificates")
  560. id_card_no := c.GetString("id_card_no")
  561. doctor, _ := c.GetInt64("doctor")
  562. admin_user_id, _ := c.GetInt64("admin_user_id")
  563. department, _ := c.GetInt64("department")
  564. adm_bed, _ := c.GetInt64("adm_bed")
  565. diagnosis_ids := c.GetString("diagnosis")
  566. sick_type, _ := c.GetInt64("sick_type")
  567. start_time := c.GetString("start_time")
  568. insuplc_admdvs := c.GetString("insuplc_admdvs")
  569. balance_accounts_type, _ := c.GetInt64("balance_accounts_type")
  570. social_type, _ := c.GetInt64("social_type")
  571. psn_type, _ := c.GetInt64("psn_type")
  572. //reg_type, _ := c.GetInt64("p_type")
  573. med_type, _ := c.GetInt64("med_type")
  574. diagnosis_ids_arr := strings.Split(diagnosis_ids, "-")
  575. timeLayout := "2006-01-02"
  576. loc, _ := time.LoadLocation("Local")
  577. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  578. if err != nil {
  579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  580. return
  581. }
  582. recordDateTime := theTime.Unix()
  583. adminInfo := c.GetAdminUserInfo()
  584. record, _ := service.GetLastHospitalRecord(id, adminInfo.CurrentOrgId)
  585. if record.ID != 0 {
  586. if record.InHospitalStatus == 1 && record.OutHospitalStatus != 1 {
  587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalExistDataException)
  588. return
  589. }
  590. }
  591. var patient service.Patients
  592. if id == 0 {
  593. patient, _ = service.GetPatientByIDCard(id_card_no, adminInfo.CurrentOrgId)
  594. } else {
  595. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  596. }
  597. diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  598. sickConfig, _ := service.FindSickById(sick_type)
  599. departmentInfo, _ := service.GetDepartMentDetail(department)
  600. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  601. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  602. 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)
  603. //fmt.Println(request_log)
  604. //fmt.Println(result_log)
  605. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  606. doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor)
  607. deviceNumber, _ := service.GetDeviceNumberByID(adm_bed, adminInfo.CurrentOrgId)
  608. var dat map[string]interface{}
  609. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  610. fmt.Println(dat)
  611. } else {
  612. fmt.Println(err)
  613. }
  614. userJSONBytes, _ := json.Marshal(dat)
  615. //
  616. //var res2 ResultTwo
  617. //if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  618. // utils.ErrorLog("解析失败:%v", err)
  619. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  620. // return
  621. //}
  622. var res2 ResultTwo
  623. var resTwo10265 ResultTwo10265
  624. if miConfig.Code == "H15049901371" {
  625. if err := json.Unmarshal(userJSONBytes, &resTwo10265); err != nil {
  626. utils.ErrorLog("解析失败:%v", err)
  627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  628. return
  629. }
  630. Infcode, _ := strconv.ParseInt(resTwo10265.Infcode, 10, 64)
  631. res2.Infcode = Infcode
  632. res2.ErrMsg = resTwo10265.ErrMsg
  633. res2.Output = resTwo10265.Output
  634. res2.InfRefmsgid = resTwo10265.InfRefmsgid
  635. res2.RespondTime = resTwo10265.RespondTime
  636. res2.WarnInfo = resTwo10265.WarnInfo
  637. } else {
  638. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  639. utils.ErrorLog("解析失败:%v", err)
  640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  641. return
  642. }
  643. }
  644. //InsuplcAdmdvs = res2.Output.
  645. if social_type != 0 {
  646. } else {
  647. }
  648. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  649. infoStr := string(Iinfos)
  650. var rf []*ResultFive
  651. json.Unmarshal([]byte(infoStr), &rf)
  652. var insutypes []*ResultFive
  653. var insutype string
  654. var is390 int = 0
  655. var is310 int = 0
  656. for _, item := range rf {
  657. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  658. insutypes = append(insutypes, item)
  659. }
  660. }
  661. if len(insutypes) == 1 {
  662. insutype = insutypes[0].Insutype
  663. //insuplc_admdvs = insutypes[0].InsuplcAdmdvs
  664. } else {
  665. for _, i := range insutypes {
  666. if i.Insutype == "390" {
  667. is390 = 1
  668. }
  669. if i.Insutype == "310" {
  670. is310 = 1
  671. }
  672. }
  673. }
  674. if is390 == 1 {
  675. insutype = "390"
  676. }
  677. if is310 == 1 {
  678. insutype = "310"
  679. }
  680. if len(insutypes) == 0 {
  681. insutype = "310"
  682. }
  683. if len(insutypes) == 2 {
  684. insutype = strconv.FormatInt(social_type, 10)
  685. }
  686. //for _, item := range rf {
  687. // if item.Insutype == insutype {
  688. // insuplc_admdvs = item.InsuplcAdmdvs
  689. // }
  690. //}
  691. if res2.Infcode == 0 {
  692. //var insutypes []string
  693. //
  694. //var insutype string
  695. //var is390 int = 0
  696. //var is310 int = 0
  697. //for _, item := range res2.Output.Iinfo {
  698. // if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  699. // insutypes = append(insutypes, item.Insutype)
  700. // }
  701. //}
  702. //if len(insutypes) == 1 {
  703. // insutype = insutypes[0]
  704. //} else {
  705. // for _, i := range insutypes {
  706. // if i == "390" {
  707. // is390 = 1
  708. // }
  709. //
  710. // if i == "310" {
  711. // is310 = 1
  712. // }
  713. // }
  714. //}
  715. //if is390 == 1 {
  716. // insutype = "390"
  717. //}
  718. //if is310 == 1 {
  719. // insutype = "310"
  720. //}
  721. //
  722. //if len(insutypes) == 0 {
  723. // insutype = "310"
  724. //}
  725. if len(insuplc_admdvs) == 0 {
  726. insuplc_admdvs = miConfig.InsuplcAdmdvs
  727. }
  728. timestamp := time.Now().Unix()
  729. tempTime := time.Unix(timestamp, 0)
  730. timeFormat := tempTime.Format("20060102150405")
  731. chrgBchno := rand.Intn(100000) + 10000
  732. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(id, 10)
  733. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  734. var struct2401 service.Struct2401
  735. struct2401.PsnNo = res2.Output.Baseinfo.PsnNo
  736. struct2401.Insutype = insutype
  737. struct2401.MdtrtCertType = "02"
  738. struct2401.MdtrtCertNo = res2.Output.Baseinfo.Certno
  739. if miConfig.Code == "H15049901371" {
  740. if med_type == 14 {
  741. if insutype == "390" {
  742. struct2401.MedType = "9933"
  743. } else if insutype == "310" {
  744. struct2401.MedType = "990502"
  745. }
  746. } else if med_type == 11 {
  747. struct2401.MedType = "11"
  748. }
  749. } else {
  750. struct2401.MedType = strconv.FormatInt(int64(med_type), 10)
  751. }
  752. struct2401.IptNo = ipt_otp_no
  753. struct2401.AtddrNo = strconv.FormatInt(int64(doctorInfo.AdminUserId), 10)
  754. struct2401.ChfpdrName = doctorInfo.UserName
  755. struct2401.AdmDiagDscr = diagnosisConfig[0].ClassName
  756. struct2401.AdmDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  757. struct2401.AdmDeptName = departmentInfo.Name
  758. struct2401.AdmBed = deviceNumber.Number
  759. struct2401.AdmBed = "待定"
  760. struct2401.DscgMaindiagName = diagnosisConfig[0].ClassName
  761. struct2401.DscgMaindiagCode = diagnosisConfig[0].CountryCode
  762. struct2401.Begntime = start_time
  763. struct2401.DiseCodg = sickConfig.CountryCode
  764. struct2401.DiseName = sickConfig.ClassName
  765. var dises []service.DiseinfoStruct
  766. for index, item := range diagnosisConfig {
  767. var dise service.DiseinfoStruct
  768. dise.PsnNo = res2.Output.Baseinfo.PsnNo
  769. dise.DiagType = "1"
  770. if index == 0 {
  771. dise.MaindiagFlag = "1"
  772. } else {
  773. dise.MaindiagFlag = "2"
  774. }
  775. dise.DiagSrtNo = strconv.FormatInt(int64(index), 10)
  776. dise.DiseDorName = doctorInfo.UserName
  777. dise.DiagCode = item.CountryCode
  778. dise.DiagName = item.ClassName
  779. dise.DiagDept = departmentInfo.Name
  780. dise.DiseDorNo = strconv.FormatInt(int64(doctorInfo.AdminUserId), 10)
  781. dise.DiagTime = timeFormatOne
  782. dises = append(dises, dise)
  783. }
  784. struct2401.Diseinfo = dises
  785. result, request_log := service.ZHGdyb2401(struct2401, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, insuplc_admdvs, miConfig.MdtrtareaAdmvs)
  786. saveLog(result, request_log, "2401", "入医登记")
  787. var dat map[string]interface{}
  788. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  789. fmt.Println(dat)
  790. } else {
  791. fmt.Println(err)
  792. }
  793. userJSONBytes, _ := json.Marshal(dat)
  794. var res ResultThree
  795. var resThree10265 ResultThree10265
  796. if miConfig.Code == "H15049901371" {
  797. if err := json.Unmarshal(userJSONBytes, &resThree10265); err != nil {
  798. utils.ErrorLog("解析失败:%v", err)
  799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  800. return
  801. }
  802. Infcode, _ := strconv.ParseInt(resThree10265.Infcode, 10, 64)
  803. res.Infcode = Infcode
  804. res.ErrMsg = resThree10265.ErrMsg
  805. res.Output = resThree10265.Output
  806. res.InfRefmsgid = resThree10265.InfRefmsgid
  807. res.RespondTime = resThree10265.RespondTime
  808. } else {
  809. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  810. utils.ErrorLog("解析失败:%v", err)
  811. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  812. return
  813. }
  814. }
  815. if res.Infcode == 0 {
  816. //result2 := service.Gdyb5301Two(res2.Output.Baseinfo.PsnNo, miConfig.OrgName, role.UserName, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  817. //fmt.Println(result2)
  818. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  819. Idetinfos, _ := json.Marshal(res2.Output.Idetinfo)
  820. infoStr := string(Iinfos)
  821. idetinfoStr := string(Idetinfos)
  822. inHospital := &models.HisHospitalCheckRecord{
  823. PatientId: id,
  824. Name: name,
  825. MedicalTreatmentType: med_type,
  826. RecordDate: recordDateTime,
  827. IdCardNo: id_card_no,
  828. AdminUserId: admin_user_id,
  829. Departments: department,
  830. UserOrgId: adminInfo.CurrentOrgId,
  831. Status: 1,
  832. Ctime: time.Now().Unix(),
  833. Mtime: time.Now().Unix(),
  834. Number: res.Output.Result.MdtrtID,
  835. Doctor: doctor,
  836. PsnNo: res2.Output.Baseinfo.PsnNo,
  837. PsnCertType: res2.Output.Baseinfo.PsnCertType,
  838. Certno: res2.Output.Baseinfo.Certno,
  839. PsnName: res2.Output.Baseinfo.PsnName,
  840. Gend: res2.Output.Baseinfo.Gend,
  841. Naty: res2.Output.Baseinfo.Naty,
  842. MedType: med_type,
  843. InsutypeType: insutype,
  844. Brdy: res2.Output.Baseinfo.Brdy,
  845. Iinfo: infoStr,
  846. Idetinfo: idetinfoStr,
  847. IptOtpNo: ipt_otp_no,
  848. AdmBed: adm_bed,
  849. IdCardType: id_card_type,
  850. Diagnosis: diagnosis_ids,
  851. SickType: sick_type,
  852. MdtrtCertType: "02",
  853. InHosptialTime: start_time,
  854. OutHosptialTime: "",
  855. InHospitalStatus: 1,
  856. Certificates: certificates,
  857. Phone: phone,
  858. BalanceAccountsType: balance_accounts_type,
  859. PsnType: psn_type,
  860. InsuplcAdmdvs: insuplc_admdvs,
  861. }
  862. service.CreateHospitalRecord(inHospital)
  863. c.ServeSuccessJSON(map[string]interface{}{
  864. "msg": "办理入院成功",
  865. "info": inHospital,
  866. })
  867. } else {
  868. c.ServeSuccessJSON(map[string]interface{}{
  869. "failed_code": -10,
  870. "msg": res.ErrMsg,
  871. })
  872. }
  873. } else {
  874. c.ServeSuccessJSON(map[string]interface{}{
  875. "failed_code": -10,
  876. "msg": res2.ErrMsg,
  877. })
  878. return
  879. }
  880. }
  881. func (this *ZHHisApiController) GetZHOutHospitalCheck() {
  882. id, _ := this.GetInt64("id")
  883. patient_id, _ := this.GetInt64("patient_id")
  884. admin_user_id, _ := this.GetInt64("admin_user_id")
  885. record_time := this.GetString("record_time")
  886. out_time := this.GetString("out_time")
  887. adminInfo := this.GetAdminUserInfo()
  888. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  889. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  890. record, _ := service.GetInHospitalRecord(id)
  891. if record.ID == 0 {
  892. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  893. return
  894. }
  895. timeLayout := "2006-01-02"
  896. loc, _ := time.LoadLocation("Local")
  897. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  898. if err != nil {
  899. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  900. return
  901. }
  902. recordDateTime := theTime.Unix()
  903. var patient service.Patients
  904. if patient_id == 0 {
  905. patient, _ = service.GetPatientByIDCard(record.IdCardNo, adminInfo.CurrentOrgId)
  906. } else {
  907. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  908. }
  909. fmt.Println(patient)
  910. diagnosis_ids_arr := strings.Split(record.Diagnosis, "-")
  911. diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  912. departmentInfo, _ := service.GetDepartMentDetail(record.Departments)
  913. doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, record.Doctor)
  914. //deviceNumber, _ := service.GetDeviceNumberByID(record.AdmBed, adminInfo.CurrentOrgId)
  915. sickConfig, _ := service.FindSickById(record.SickType)
  916. var struct2402 service.Struct2402
  917. timestamp := time.Now().Unix()
  918. tempTime := time.Unix(timestamp, 0)
  919. //timeFormat := tempTime.Format("20060102150405")
  920. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  921. struct2402.PsnNo = record.PsnNo
  922. struct2402.Insutype = record.InsutypeType
  923. struct2402.DscgWay = "1"
  924. struct2402.Endtime = out_time
  925. struct2402.DscgDeptName = departmentInfo.Number
  926. struct2402.DscgDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  927. struct2402.MdtrtId = record.Number
  928. var dises []service.Diseinfo2402Struct
  929. for index, item := range diagnosisConfig {
  930. var dise service.Diseinfo2402Struct
  931. dise.PsnNo = record.PsnNo
  932. dise.DiagType = "1"
  933. if index == 0 {
  934. dise.MaindiagFlag = "1"
  935. } else {
  936. dise.MaindiagFlag = "2"
  937. }
  938. dise.MdtrtId = record.Number
  939. dise.DiagSrtNo = strconv.FormatInt(int64(item.ID), 10)
  940. dise.DiseDorName = doctorInfo.UserName
  941. dise.DiagCode = item.CountryCode
  942. dise.DiagName = item.ClassName
  943. dise.DiagDept = departmentInfo.Name
  944. dise.DiseDorNo = strconv.FormatInt(int64(doctorInfo.AdminUserId), 10)
  945. dise.DiagTime = timeFormatOne
  946. dises = append(dises, dise)
  947. }
  948. struct2402.Diseinfo = dises
  949. struct2402.DiseName = sickConfig.ClassName
  950. struct2402.DiseCode = sickConfig.CountryCode
  951. result, request_log := service.ZHGdyb2402(struct2402, miConfig.OrgName, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  952. //saveLog(result,request_log,"出院)
  953. saveLog(result, request_log, "2402", "出院")
  954. var dat map[string]interface{}
  955. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  956. fmt.Println(dat)
  957. } else {
  958. fmt.Println(err)
  959. }
  960. userJSONBytes, _ := json.Marshal(dat)
  961. var res ResultEmpty
  962. var resEmpty10265 ResultEmpty10265
  963. if miConfig.Code == "H15049901371" {
  964. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  965. utils.ErrorLog("解析失败:%v", err)
  966. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  967. return
  968. }
  969. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  970. res.Infcode = Infcode
  971. res.RespondTime = resEmpty10265.RespondTime
  972. res.ErrMsg = resEmpty10265.ErrMsg
  973. res.Output = resEmpty10265.Output
  974. res.WarnMsg = resEmpty10265.WarnMsg
  975. } else {
  976. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  977. utils.ErrorLog("解析失败:%v", err)
  978. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  979. return
  980. }
  981. }
  982. if res.Infcode == 0 {
  983. record.OutHospitalStatus = 1
  984. record.OutHosptialTime = struct2402.Endtime
  985. record.OutWay = 1
  986. service.CreateHospitalRecord(&record)
  987. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  988. var total float64
  989. for _, item := range orders {
  990. total = total + item.DetItemFeeSumamt
  991. }
  992. order := &models.HisOrder{
  993. UserOrgId: adminInfo.CurrentOrgId,
  994. HisPatientId: record.ID,
  995. PatientId: record.PatientId,
  996. SettleAccountsDate: recordDateTime,
  997. Ctime: time.Now().Unix(),
  998. Mtime: time.Now().Unix(),
  999. Status: 1,
  1000. Number: record.Number,
  1001. Infcode: 0,
  1002. WarnMsg: "",
  1003. Cainfo: "",
  1004. ErrMsg: "",
  1005. RespondTime: "",
  1006. InfRefmsgid: "",
  1007. OrderStatus: 1,
  1008. MdtrtId: record.Number,
  1009. IsMedicineInsurance: 1,
  1010. PType: 1,
  1011. MedfeeSumamt: total,
  1012. }
  1013. err = service.CreateOrder(order)
  1014. if err != nil {
  1015. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1016. return
  1017. }
  1018. this.ServeSuccessJSON(map[string]interface{}{
  1019. "msg": "出院成功",
  1020. })
  1021. } else {
  1022. this.ServeSuccessJSON(map[string]interface{}{
  1023. "failed_code": -10,
  1024. "msg": res.ErrMsg,
  1025. })
  1026. }
  1027. }
  1028. func (c *ZHHisApiController) GetSettleInfo() {
  1029. order_id, _ := c.GetInt64("order_id")
  1030. patient_id, _ := c.GetInt64("patient_id")
  1031. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  1032. admin_user_id, _ := c.GetInt64("admin_user_id")
  1033. pay_way, _ := c.GetInt64("pay_way")
  1034. pay_price, _ := c.GetFloat("pay_price")
  1035. pay_card_no := c.GetString("pay_card_no")
  1036. discount_price, _ := c.GetFloat("discount_price")
  1037. preferential_price, _ := c.GetFloat("preferential_price")
  1038. reality_price, _ := c.GetFloat("reality_price")
  1039. found_price, _ := c.GetFloat("found_price")
  1040. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1041. private_price, _ := c.GetFloat("private_price")
  1042. fapiao_code := c.GetString("fapiao_code")
  1043. fapiao_number := c.GetString("fapiao_number")
  1044. record, _ := service.GetInHospitalRecord(in_hospital_id)
  1045. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  1046. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  1047. order, _ := service.GetHisOrderByID(order_id)
  1048. var rf []*ResultFive
  1049. json.Unmarshal([]byte(record.Iinfo), &rf)
  1050. chrg_bchno := order.Number
  1051. cert_no := record.Certno
  1052. if record.ID == 0 {
  1053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1054. return
  1055. }
  1056. if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  1057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  1058. return
  1059. }
  1060. if record.IdCardType == 1 {
  1061. } else {
  1062. cert_no = record.Certno
  1063. }
  1064. var result string
  1065. var src_resquest string
  1066. timeLayout := "2006-01-02"
  1067. loc, _ := time.LoadLocation("Local")
  1068. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record.InHosptialTime, loc)
  1069. if err != nil {
  1070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1071. return
  1072. }
  1073. recordStartDateTime := theTime.Unix()
  1074. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", record.OutHosptialTime, loc)
  1075. if err != nil {
  1076. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1077. return
  1078. }
  1079. recordEndDateTime := theTimeEnd.Unix()
  1080. prescriptions, _ := service.GetZHSettleMonthHisPrescription(c.GetAdminUserInfo().CurrentOrgId, patient_id, recordStartDateTime, recordEndDateTime)
  1081. var total float64
  1082. for _, item := range prescriptions {
  1083. if item.Type == 1 { //药品
  1084. for _, subItem := range item.HisDoctorAdviceInfo {
  1085. total = total + (subItem.Price * subItem.PrescribingNumber)
  1086. }
  1087. }
  1088. if item.Type == 2 { //项目
  1089. for _, subItem := range item.HisPrescriptionProject {
  1090. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  1091. total = total + (subItem.Price * cnt)
  1092. }
  1093. }
  1094. }
  1095. //allTotal := fmt.Sprintf("%.2f", total)
  1096. var allTotal string
  1097. if record.OutHospitalStatus == 0 && order.ID == 0 {
  1098. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  1099. var total float64
  1100. for _, item := range orders {
  1101. total = total + item.DetItemFeeSumamt
  1102. }
  1103. allTotal = fmt.Sprintf("%.4f", total)
  1104. } else {
  1105. allTotal = fmt.Sprintf("%.4f", order.MedfeeSumamt)
  1106. }
  1107. 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)
  1108. //saveLog()
  1109. saveLog(result, src_resquest, "2304", "住院结算")
  1110. var dat map[string]interface{}
  1111. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1112. fmt.Println(dat)
  1113. } else {
  1114. fmt.Println(err)
  1115. }
  1116. userJSONBytes, _ := json.Marshal(dat)
  1117. var res ResultSeven
  1118. var resSeven10265 ResultSeven10265
  1119. if miConfig.Code == "H15049901371" {
  1120. if err := json.Unmarshal(userJSONBytes, &resSeven10265); err != nil {
  1121. utils.ErrorLog("解析失败:%v", err)
  1122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1123. return
  1124. }
  1125. Infcode, _ := strconv.ParseInt(resSeven10265.Infcode, 10, 64)
  1126. res.Infcode = Infcode
  1127. res.InfRefmsgid = resSeven10265.InfRefmsgid
  1128. res.RespondTime = resSeven10265.RespondTime
  1129. res.ErrMsg = resSeven10265.ErrMsg
  1130. res.Output = resSeven10265.Output
  1131. res.WarnMsg = resSeven10265.WarnMsg
  1132. res.Cainfo = resSeven10265.Cainfo
  1133. } else {
  1134. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1135. utils.ErrorLog("解析失败:%v", err)
  1136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1137. return
  1138. }
  1139. }
  1140. if res.Infcode != 0 {
  1141. errlog := &models.HisOrderError{
  1142. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1143. Ctime: time.Now().Unix(),
  1144. Mtime: time.Now().Unix(),
  1145. Number: chrg_bchno,
  1146. ErrMsg: res.ErrMsg,
  1147. Status: 1,
  1148. PatientId: patient_id,
  1149. RecordTime: time.Now().Unix(),
  1150. Stage: 6,
  1151. }
  1152. service.CreateErrMsgLog(errlog)
  1153. c.ServeSuccessJSON(map[string]interface{}{
  1154. "failed_code": -10,
  1155. "msg": res.ErrMsg,
  1156. })
  1157. return
  1158. } else {
  1159. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1160. order.OrderStatus = 2
  1161. order.DiscountPrice = discount_price
  1162. order.MedicalInsurancePrice = medical_insurance_price
  1163. order.FaPiaoNumber = fapiao_number
  1164. order.FaPiaoCode = fapiao_code
  1165. order.PayWay = pay_way
  1166. order.PayPrice = pay_price
  1167. order.PayCardNo = pay_card_no
  1168. order.PreferentialPrice = preferential_price
  1169. order.RealityPrice = reality_price
  1170. order.FoundPrice = found_price
  1171. order.PrivatePrice = private_price
  1172. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1173. order.SetlId = res.Output.Setlinfo.SetlID
  1174. order.PsnNo = res.Output.Setlinfo.PsnNo
  1175. order.PsnName = res.Output.Setlinfo.PsnName
  1176. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1177. order.Certno = res.Output.Setlinfo.Certno
  1178. order.Gend = res.Output.Setlinfo.Gend
  1179. order.Naty = res.Output.Setlinfo.Naty
  1180. order.Age = res.Output.Setlinfo.Age
  1181. order.Insutype = res.Output.Setlinfo.Insutype
  1182. order.PsnType = res.Output.Setlinfo.PsnType
  1183. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1184. order.SetlTime = res.Output.Setlinfo.SetlTime
  1185. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1186. if res.Output.Setlinfo.MedType == "140104" {
  1187. order.MedType = "14"
  1188. } else {
  1189. order.MedType = res.Output.Setlinfo.MedType
  1190. }
  1191. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1192. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1193. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1194. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1195. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1196. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1197. order.HifpPay = res.Output.Setlinfo.HifpPay
  1198. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1199. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1200. order.HifesPay = res.Output.Setlinfo.HifesPay
  1201. order.HifobPay = res.Output.Setlinfo.HifobPay
  1202. order.MafPay = res.Output.Setlinfo.MafPay
  1203. order.OthPay = res.Output.Setlinfo.OthPay
  1204. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1205. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1206. order.AcctPay = res.Output.Setlinfo.AcctPay
  1207. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1208. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1209. order.Balc = res.Output.Setlinfo.Balc
  1210. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1211. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1212. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1213. order.ClrWay = res.Output.Setlinfo.ClrWay
  1214. order.Creator = order.Creator
  1215. order.Modify = roles.AdminUserId
  1216. order.RequestLog = src_resquest
  1217. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1218. detailStr := string(setlDetail)
  1219. order.SetlDetail = detailStr
  1220. err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  1221. err = service.UpDateOrder(order)
  1222. if err == nil {
  1223. c.ServeSuccessJSON(map[string]interface{}{
  1224. "msg": "结算成功",
  1225. })
  1226. } else {
  1227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1228. return
  1229. }
  1230. }
  1231. }
  1232. func (c *ZHHisApiController) GetPreSettleInfo() {
  1233. order_id, _ := c.GetInt64("order_id")
  1234. patient_id, _ := c.GetInt64("patient_id")
  1235. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  1236. admin_user_id, _ := c.GetInt64("admin_user_id")
  1237. record, _ := service.GetInHospitalRecord(in_hospital_id)
  1238. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  1239. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  1240. order, _ := service.GetHisOrderByID(order_id)
  1241. var allTotal string
  1242. if record.OutHospitalStatus == 0 && order.ID == 0 {
  1243. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  1244. var total float64
  1245. for _, item := range orders {
  1246. total = total + item.DetItemFeeSumamt
  1247. }
  1248. allTotal = fmt.Sprintf("%.4f", total)
  1249. } else {
  1250. allTotal = fmt.Sprintf("%.4f", order.MedfeeSumamt)
  1251. }
  1252. var rf []*ResultFive
  1253. json.Unmarshal([]byte(record.Iinfo), &rf)
  1254. chrg_bchno := order.Number
  1255. cert_no := record.Certno
  1256. if record.ID == 0 {
  1257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1258. return
  1259. }
  1260. //if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  1261. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  1262. // return
  1263. //}
  1264. if record.IdCardType == 1 {
  1265. } else {
  1266. cert_no = record.Certno
  1267. }
  1268. var result string
  1269. var src_resquest string
  1270. 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)
  1271. saveLog(result, src_resquest, "2303", "住院预结算")
  1272. var dat map[string]interface{}
  1273. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1274. fmt.Println(dat)
  1275. } else {
  1276. fmt.Println(err)
  1277. }
  1278. userJSONBytes, _ := json.Marshal(dat)
  1279. var res ResultSeven
  1280. var resSeven10265 ResultSeven10265
  1281. if miConfig.Code == "H15049901371" {
  1282. if err := json.Unmarshal(userJSONBytes, &resSeven10265); err != nil {
  1283. utils.ErrorLog("解析失败:%v", err)
  1284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1285. return
  1286. }
  1287. Infcode, _ := strconv.ParseInt(resSeven10265.Infcode, 10, 64)
  1288. res.Infcode = Infcode
  1289. res.InfRefmsgid = resSeven10265.InfRefmsgid
  1290. res.RespondTime = resSeven10265.RespondTime
  1291. res.ErrMsg = resSeven10265.ErrMsg
  1292. res.Output = resSeven10265.Output
  1293. res.WarnMsg = resSeven10265.WarnMsg
  1294. res.Cainfo = resSeven10265.Cainfo
  1295. } else {
  1296. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1297. utils.ErrorLog("解析失败:%v", err)
  1298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1299. return
  1300. }
  1301. }
  1302. if res.Infcode != 0 {
  1303. errlog := &models.HisOrderError{
  1304. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1305. Ctime: time.Now().Unix(),
  1306. Mtime: time.Now().Unix(),
  1307. Number: chrg_bchno,
  1308. ErrMsg: res.ErrMsg,
  1309. Status: 1,
  1310. PatientId: patient_id,
  1311. RecordTime: time.Now().Unix(),
  1312. Stage: 6,
  1313. }
  1314. service.CreateErrMsgLog(errlog)
  1315. c.ServeSuccessJSON(map[string]interface{}{
  1316. "failed_code": -10,
  1317. "msg": res.ErrMsg,
  1318. })
  1319. return
  1320. } else {
  1321. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1322. order.OrderStatus = 1
  1323. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1324. order.SetlId = res.Output.Setlinfo.SetlID
  1325. order.PsnNo = res.Output.Setlinfo.PsnNo
  1326. order.PsnName = res.Output.Setlinfo.PsnName
  1327. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1328. order.Certno = res.Output.Setlinfo.Certno
  1329. order.Gend = res.Output.Setlinfo.Gend
  1330. order.Naty = res.Output.Setlinfo.Naty
  1331. order.Age = res.Output.Setlinfo.Age
  1332. order.Insutype = res.Output.Setlinfo.Insutype
  1333. order.PsnType = res.Output.Setlinfo.PsnType
  1334. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1335. order.SetlTime = res.Output.Setlinfo.SetlTime
  1336. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1337. if res.Output.Setlinfo.MedType == "140104" {
  1338. order.MedType = "14"
  1339. } else {
  1340. order.MedType = res.Output.Setlinfo.MedType
  1341. }
  1342. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1343. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1344. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1345. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1346. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1347. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1348. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  1349. order.HifpPay = res.Output.Setlinfo.HifpPay
  1350. order.HifesPay = res.Output.Setlinfo.HifesPay
  1351. order.HifobPay = res.Output.Setlinfo.HifobPay
  1352. order.MafPay = res.Output.Setlinfo.MafPay
  1353. order.OthPay = res.Output.Setlinfo.OthPay
  1354. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1355. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1356. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1357. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1358. order.AcctPay = res.Output.Setlinfo.AcctPay
  1359. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1360. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1361. order.Balc = res.Output.Setlinfo.Balc
  1362. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1363. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1364. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1365. order.ClrWay = res.Output.Setlinfo.ClrWay
  1366. order.Creator = order.Creator
  1367. order.Modify = roles.AdminUserId
  1368. order.RequestLog = src_resquest
  1369. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1370. detailStr := string(setlDetail)
  1371. order.SetlDetail = detailStr
  1372. //err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  1373. if record.OutHospitalStatus == 1 && order.ID > 0 {
  1374. err := service.UpDateOrder(order)
  1375. if err == nil {
  1376. c.ServeSuccessJSON(map[string]interface{}{
  1377. "msg": "预结算成功",
  1378. "order_way": 1,
  1379. })
  1380. } else {
  1381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1382. return
  1383. }
  1384. } else if record.OutHospitalStatus == 0 && order.ID == 0 {
  1385. c.ServeSuccessJSON(map[string]interface{}{
  1386. "msg": "预结算成功",
  1387. "order": order,
  1388. "order_way": 2,
  1389. })
  1390. }
  1391. }
  1392. }
  1393. func (c *ZHHisApiController) GetUploadInfo() {
  1394. id, _ := c.GetInt64("id")
  1395. record_time := c.GetString("record_time")
  1396. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  1397. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1398. admin_user_id, _ := c.GetInt64("admin_user_id")
  1399. timeLayout := "2006-01-02"
  1400. loc, _ := time.LoadLocation("Local")
  1401. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1402. if err != nil {
  1403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1404. return
  1405. }
  1406. recordDateTime := theTime.Unix()
  1407. adminUser := c.GetAdminUserInfo()
  1408. var prescriptions []*models.HisPrescription
  1409. data := make(map[string]interface{})
  1410. if settle_accounts_type == 1 { //日结
  1411. prescriptions, _ = service.GetZHHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1412. } else { //月结
  1413. start_time_str := c.GetString("start_time")
  1414. end_time_str := c.GetString("end_time")
  1415. timeLayout := "2006-01-02"
  1416. loc, _ := time.LoadLocation("Local")
  1417. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1418. if err != nil {
  1419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1420. return
  1421. }
  1422. recordStartTime := theStartTime.Unix()
  1423. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1424. if err != nil {
  1425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1426. return
  1427. }
  1428. recordEndTime := theEndTime.Unix()
  1429. prescriptions, _ = service.GetZHMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1430. }
  1431. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1432. record, _ := service.GetInHospitalRecord(in_hospital_id)
  1433. if record.ID == 0 {
  1434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1435. return
  1436. }
  1437. //if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  1438. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  1439. // return
  1440. //}
  1441. timestamp := time.Now().Unix()
  1442. tempTime := time.Unix(timestamp, 0)
  1443. timeFormat := tempTime.Format("20060102150405")
  1444. chrgBchno := rand.Intn(100000) + 10000
  1445. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(record.PatientId, 10)
  1446. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1447. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1448. department, _ := service.GetDepartMentDetail(record.Departments)
  1449. strconv.FormatInt(record.PatientId, 10)
  1450. //client := &http.Client{}
  1451. data["psn_no"] = record.PsnNo
  1452. data["mdtrt_id"] = record.Number
  1453. data["chrg_bchno"] = chrg_bchno
  1454. data["org_name"] = miConfig.OrgName
  1455. data["doctor"] = roles.UserName
  1456. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1457. data["dept"] = strconv.FormatInt(department.ID, 10)
  1458. data["fixmedins_code"] = miConfig.Code
  1459. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  1460. data["dept_code"] = "15"
  1461. } else {
  1462. data["dept_code"] = department.Number
  1463. }
  1464. if miConfig.Code == "H15049901371" {
  1465. if record.MedType == 14 {
  1466. if record.InsutypeType == "390" {
  1467. data["med_type"] = "9933"
  1468. } else if record.InsutypeType == "310" {
  1469. data["med_type"] = "990502"
  1470. }
  1471. } else if record.MedType == 11 {
  1472. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  1473. }
  1474. } else {
  1475. if record.MedType == 1112 {
  1476. data["med_type"] = strconv.FormatInt(11, 10)
  1477. } else {
  1478. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  1479. }
  1480. }
  1481. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  1482. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1483. data["secret_key"] = miConfig.SecretKey
  1484. var ids []int64
  1485. fmt.Println(data)
  1486. for _, item := range prescriptions {
  1487. ids = append(ids, item.ID)
  1488. }
  1489. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1490. if config.IsOpen == 1 { //对接了医保,走医保流程
  1491. var pagesize int = 100
  1492. var start int = 1
  1493. var stop int
  1494. var pagecount int
  1495. var curpage int
  1496. var isSuccess bool = true
  1497. var customs []*models.NewCustom
  1498. for _, item := range prescriptions {
  1499. tm := time.Unix(item.PreTime, 0)
  1500. if item.Type == 1 { //药品
  1501. for _, subItem := range item.HisDoctorAdviceInfo {
  1502. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 && subItem.BaseDrugLib.IsUser != 1 {
  1503. //var randNum int
  1504. //randNum = rand.Intn(10000) + 1000
  1505. cus := &models.NewCustom{
  1506. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  1507. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  1508. FeedetlSn: subItem.FeedetlSn,
  1509. Price: fmt.Sprintf("%.4f", subItem.Price),
  1510. MedListCodg: subItem.BaseDrugLib.MedicalInsuranceNumber,
  1511. HospApprFlag: subItem.BaseDrugLib.HospApprFlag,
  1512. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  1513. }
  1514. customs = append(customs, cus)
  1515. }
  1516. }
  1517. }
  1518. if item.Type == 2 { //项目
  1519. for _, subItem := range item.HisPrescriptionProject {
  1520. //var randNum int
  1521. //randNum = rand.Intn(10000) + 1000
  1522. if subItem.Type == 2 {
  1523. if len(subItem.HisProject.MedicalCode) > 0 {
  1524. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  1525. cus := &models.NewCustom{
  1526. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  1527. Cut: fmt.Sprintf("%.4f", cnt),
  1528. FeedetlSn: subItem.FeedetlSn,
  1529. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  1530. MedListCodg: subItem.HisProject.MedicalCode,
  1531. HospApprFlag: -1,
  1532. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  1533. }
  1534. customs = append(customs, cus)
  1535. }
  1536. } else if subItem.Type == 3 {
  1537. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 && subItem.GoodInfo.IsUser != 1 {
  1538. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  1539. cus := &models.NewCustom{
  1540. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  1541. Cut: fmt.Sprintf("%.4f", cnt),
  1542. FeedetlSn: subItem.FeedetlSn,
  1543. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  1544. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  1545. HospApprFlag: -1,
  1546. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  1547. }
  1548. customs = append(customs, cus)
  1549. }
  1550. }
  1551. }
  1552. }
  1553. //for _, subItem := range item.HisAdditionalCharge {
  1554. // if len(subItem.XtHisAddtionConfig.Code) > 0 {
  1555. // cus := &models.NewCustom{
  1556. // DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*float64(subItem.Count)),
  1557. // Cut: fmt.Sprintf("%.4f", float64(subItem.Count)),
  1558. // FeedetlSn: subItem.FeedetlSn,
  1559. // Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  1560. // MedListCodg: subItem.XtHisAddtionConfig.Code,
  1561. // HospApprFlag: -1,
  1562. //
  1563. // }
  1564. // customs = append(customs, cus)
  1565. // }
  1566. //}
  1567. }
  1568. //总页数,向上取整,注意除之前要先转换类型为float64
  1569. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  1570. var ress []*ResultFour
  1571. for curpage = 1; curpage <= pagecount; curpage++ {
  1572. if curpage == 1 {
  1573. start = 1
  1574. } else {
  1575. start = (curpage-1)*pagesize + 1
  1576. }
  1577. stop = curpage * pagesize
  1578. if stop > len(customs) {
  1579. stop = len(customs)
  1580. }
  1581. //data["pre"] = customs[start-1 : stop]
  1582. //bytesData, _ := json.Marshal(data)
  1583. //req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/zh/five", bytes.NewReader(bytesData))
  1584. //resp, _ := client.Do(req)
  1585. //defer resp.Body.Close()
  1586. //body, ioErr := ioutil.ReadAll(resp.Body)
  1587. //if ioErr != nil {
  1588. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1589. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1590. // return
  1591. //}
  1592. resultLog, 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))
  1593. saveLog(resultLog, requestLog, "2301", "上传明细")
  1594. var dat map[string]interface{}
  1595. if err := json.Unmarshal([]byte(resultLog), &dat); err == nil {
  1596. fmt.Println(dat)
  1597. } else {
  1598. fmt.Println(err)
  1599. }
  1600. userJSONBytes, _ := json.Marshal(dat)
  1601. var res ResultFour
  1602. var resFour10265 ResultFour10265
  1603. if miConfig.Code == "H15049901371" {
  1604. if err := json.Unmarshal(userJSONBytes, &resFour10265); err != nil {
  1605. utils.ErrorLog("解析失败:%v", err)
  1606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1607. return
  1608. }
  1609. res.WarnMsg = resFour10265.WarnMsg
  1610. res.Output = resFour10265.Output
  1611. res.ErrMsg = resFour10265.ErrMsg
  1612. res.RespondTime = resFour10265.RespondTime
  1613. res.InfRefmsgid = resFour10265.InfRefmsgid
  1614. Infcode, _ := strconv.ParseInt(resFour10265.Infcode, 10, 64)
  1615. res.Infcode = Infcode
  1616. } else {
  1617. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1618. utils.ErrorLog("解析失败:%v", err)
  1619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1620. return
  1621. }
  1622. }
  1623. if res.Infcode == 0 {
  1624. ress = append(ress, &res)
  1625. } else {
  1626. isSuccess = false
  1627. errlog := &models.HisOrderError{
  1628. UserOrgId: adminUser.CurrentOrgId,
  1629. Ctime: time.Now().Unix(),
  1630. Mtime: time.Now().Unix(),
  1631. Number: chrg_bchno,
  1632. ErrMsg: "",
  1633. Status: 1,
  1634. PatientId: id,
  1635. RecordTime: recordDateTime,
  1636. Stage: 4,
  1637. }
  1638. service.CreateErrMsgLog(errlog)
  1639. c.ServeSuccessJSON(map[string]interface{}{
  1640. "failed_code": -10,
  1641. "msg": "上传明细错误,请联系his厂商",
  1642. })
  1643. return
  1644. }
  1645. }
  1646. if isSuccess == true {
  1647. if settle_accounts_type == 1 {
  1648. for _, subItem := range ress {
  1649. for _, item := range subItem.Output.Result {
  1650. temp := strings.Split(item.FeedetlSn, "-")
  1651. var advice_id int64 = 0
  1652. var project_id int64 = 0
  1653. var types int64 = 0
  1654. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1655. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1656. if temp[1] == "1" {
  1657. advice_id = id
  1658. project_id = 0
  1659. } else if temp[1] == "2" {
  1660. advice_id = 0
  1661. project_id = id
  1662. }
  1663. info := &models.HisOrderInfo{
  1664. OrderNumber: record.Number,
  1665. FeedetlSn: item.FeedetlSn,
  1666. UploadDate: recordDateTime,
  1667. AdviceId: advice_id,
  1668. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1669. Cnt: item.Cnt,
  1670. Pric: float64(item.Pric),
  1671. PatientId: record.PatientId,
  1672. PricUplmtAmt: item.PricUplmtAmt,
  1673. SelfpayProp: item.SelfpayProp,
  1674. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1675. OverlmtAmt: item.OverlmtAmt,
  1676. PreselfpayAmt: item.PreselfpayAmt,
  1677. BasMednFlag: item.BasMednFlag,
  1678. MedChrgitmType: item.MedChrgitmType,
  1679. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1680. Status: 1,
  1681. Memo: item.Memo,
  1682. Mtime: time.Now().Unix(),
  1683. InscpScpAmt: item.InscpScpAmt,
  1684. DrtReimFlag: item.DrtReimFlag,
  1685. Ctime: time.Now().Unix(),
  1686. ListSpItemFlag: item.ListSpItemFlag,
  1687. ChldMedcFlag: item.ChldMedcFlag,
  1688. LmtUsedFlag: item.LmtUsedFlag,
  1689. ChrgitmLv: item.ChrgitmLv,
  1690. UserOrgId: adminUser.CurrentOrgId,
  1691. HisPatientId: record.ID,
  1692. OrderId: 0,
  1693. ProjectId: project_id,
  1694. Type: types,
  1695. SettleType: settle_accounts_type,
  1696. }
  1697. service.CreateOrderInfo(info)
  1698. }
  1699. }
  1700. err := service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  1701. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  1702. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  1703. if err == nil {
  1704. c.ServeSuccessJSON(map[string]interface{}{
  1705. "msg": "上传费用明细成功",
  1706. })
  1707. return
  1708. } else {
  1709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1710. return
  1711. }
  1712. } else {
  1713. for _, subItem := range ress {
  1714. for _, item := range subItem.Output.Result {
  1715. temp := strings.Split(item.FeedetlSn, "-")
  1716. var advice_id int64 = 0
  1717. var project_id int64 = 0
  1718. var types int64 = 0
  1719. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1720. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1721. if temp[1] == "1" {
  1722. advice_id = id
  1723. project_id = 0
  1724. } else if temp[1] == "2" {
  1725. advice_id = 0
  1726. project_id = id
  1727. }
  1728. info := &models.HisOrderInfo{
  1729. OrderNumber: record.Number,
  1730. FeedetlSn: item.FeedetlSn,
  1731. UploadDate: time.Now().Unix(),
  1732. AdviceId: advice_id,
  1733. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1734. Cnt: item.Cnt,
  1735. Pric: float64(item.Pric),
  1736. PatientId: record.PatientId,
  1737. PricUplmtAmt: item.PricUplmtAmt,
  1738. SelfpayProp: item.SelfpayProp,
  1739. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1740. OverlmtAmt: item.OverlmtAmt,
  1741. PreselfpayAmt: item.PreselfpayAmt,
  1742. BasMednFlag: item.BasMednFlag,
  1743. MedChrgitmType: item.MedChrgitmType,
  1744. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1745. Status: 1,
  1746. Memo: item.Memo,
  1747. Mtime: time.Now().Unix(),
  1748. InscpScpAmt: item.InscpScpAmt,
  1749. DrtReimFlag: item.DrtReimFlag,
  1750. Ctime: time.Now().Unix(),
  1751. ListSpItemFlag: item.ListSpItemFlag,
  1752. ChldMedcFlag: item.ChldMedcFlag,
  1753. LmtUsedFlag: item.LmtUsedFlag,
  1754. ChrgitmLv: item.ChrgitmLv,
  1755. UserOrgId: adminUser.CurrentOrgId,
  1756. HisPatientId: record.ID,
  1757. ProjectId: project_id,
  1758. Type: types,
  1759. SettleType: settle_accounts_type,
  1760. }
  1761. service.CreateOrderInfo(info)
  1762. }
  1763. }
  1764. service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  1765. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  1766. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  1767. c.ServeSuccessJSON(map[string]interface{}{
  1768. "msg": "上传费用明细成功",
  1769. })
  1770. }
  1771. }
  1772. }
  1773. }
  1774. func (c *ZHHisApiController) ZHRefund() {
  1775. order_id, _ := c.GetInt64("order_id")
  1776. admin_user_id, _ := c.GetInt64("admin_user_id")
  1777. adminUser := c.GetAdminUserInfo()
  1778. var order models.HisOrder
  1779. order, _ = service.GetHisOrderByID(order_id)
  1780. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  1781. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1782. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1783. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1784. if config.IsOpen == 1 { //对接了医保,走医保流程
  1785. result, src_resquest := service.Gdyb2305(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  1786. saveLog(result, src_resquest, "2305", "退费")
  1787. var dat map[string]interface{}
  1788. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1789. fmt.Println(dat)
  1790. } else {
  1791. fmt.Println(err)
  1792. }
  1793. userJSONBytes, _ := json.Marshal(dat)
  1794. var res ResultSixteen
  1795. var resSixteen ResultSixteen10265
  1796. if miConfig.Code == "H15049901371" {
  1797. if err := json.Unmarshal(userJSONBytes, &resSixteen); err != nil {
  1798. utils.ErrorLog("解析失败:%v", err)
  1799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1800. return
  1801. }
  1802. res.Cainfo = resSixteen.Cainfo
  1803. res.WarnMsg = resSixteen.WarnMsg
  1804. res.Output = resSixteen.Output
  1805. res.ErrMsg = resSixteen.ErrMsg
  1806. res.RespondTime = resSixteen.RespondTime
  1807. Infcode, _ := strconv.ParseInt(resSixteen.Infcode, 10, 64)
  1808. res.Infcode = Infcode
  1809. } else {
  1810. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1811. utils.ErrorLog("解析失败:%v", err)
  1812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1813. return
  1814. }
  1815. }
  1816. if res.Infcode == 0 {
  1817. err := service.UpdataOrderStatusThree(order_id, order.Number, adminUser.CurrentOrgId, src_resquest, result)
  1818. //不同地区退费流程不一样,肇庆那边退费就包括撤销出院,内蒙古退费不包括撤销明细,所以下面需要根据不同情况进行判断
  1819. if miConfig.UserOrgId == 10215 {
  1820. record.OutHospitalStatus = 0
  1821. service.CreateHospitalRecord(&record)
  1822. }
  1823. service.UpdataOrderStatusByNumber(record.Number)
  1824. if err == nil {
  1825. c.ServeSuccessJSON(map[string]interface{}{
  1826. "msg": "退费成功",
  1827. })
  1828. } else {
  1829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1830. return
  1831. }
  1832. } else {
  1833. c.ServeSuccessJSON(map[string]interface{}{
  1834. "code": -10,
  1835. "msg": res.ErrMsg,
  1836. })
  1837. }
  1838. } else {
  1839. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  1840. if err == nil {
  1841. c.ServeSuccessJSON(map[string]interface{}{
  1842. "msg": "退费成功",
  1843. })
  1844. } else {
  1845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1846. return
  1847. }
  1848. }
  1849. }
  1850. func (c *ZHHisApiController) ZHRefundDetail() {
  1851. patient_id, _ := c.GetInt64("patient_id")
  1852. his_patient_id, _ := c.GetInt64("his_patient_id")
  1853. record_time := c.GetString("record_time")
  1854. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1855. //order_id, _ := c.GetInt64("order_id")
  1856. admin_user_id, _ := c.GetInt64("admin_user_id")
  1857. timeLayout := "2006-01-02"
  1858. loc, _ := time.LoadLocation("Local")
  1859. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1860. if err != nil {
  1861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1862. return
  1863. }
  1864. recordDateTime := theTime.Unix()
  1865. adminUser := c.GetAdminUserInfo()
  1866. theTimeTwo, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 23:59:59", loc)
  1867. if err != nil {
  1868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1869. return
  1870. }
  1871. recordDateTimeTwo := theTimeTwo.Unix()
  1872. //var prescriptions []*models.HisPrescription
  1873. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1874. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1875. if settle_accounts_type == 1 { //日结
  1876. record, _ := service.GetInHospitalRecord(his_patient_id)
  1877. infos, _ := service.GetZHHisUploadOrderInfo(adminUser.CurrentOrgId, patient_id, recordDateTime, recordDateTimeTwo, record.Number)
  1878. var isSuccess bool = true
  1879. for _, item := range infos {
  1880. result, requestLog := service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, item.FeedetlSn, 1)
  1881. saveLog(result, requestLog, "2302", "日结退明细")
  1882. var dat map[string]interface{}
  1883. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1884. fmt.Println(dat)
  1885. } else {
  1886. fmt.Println(err)
  1887. }
  1888. userJSONBytes, _ := json.Marshal(dat)
  1889. var res2 ResultEmpty
  1890. var resEmpty10265 ResultEmpty10265
  1891. if miConfig.Code == "H15049901371" {
  1892. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  1893. utils.ErrorLog("解析失败:%v", err)
  1894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1895. return
  1896. }
  1897. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  1898. res2.Infcode = Infcode
  1899. res2.RespondTime = resEmpty10265.RespondTime
  1900. res2.ErrMsg = resEmpty10265.ErrMsg
  1901. res2.Output = resEmpty10265.Output
  1902. res2.WarnMsg = resEmpty10265.WarnMsg
  1903. } else {
  1904. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  1905. utils.ErrorLog("解析失败:%v", err)
  1906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1907. return
  1908. }
  1909. }
  1910. if res2.Infcode == -1 {
  1911. isSuccess = false
  1912. }
  1913. }
  1914. if isSuccess {
  1915. err := service.UpDateOrderInfoStatus(patient_id, recordDateTime, adminUser.CurrentOrgId, recordDateTimeTwo)
  1916. if err != nil {
  1917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1918. return
  1919. }
  1920. err1 := service.UpDatePrescriptionOrderStatusTwo(patient_id, recordDateTime, adminUser.CurrentOrgId)
  1921. if err1 != nil {
  1922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1923. return
  1924. }
  1925. c.ServeSuccessJSON(map[string]interface{}{
  1926. "msg": "撤销明细成功",
  1927. })
  1928. }
  1929. } else {
  1930. //prescriptions, _ = service.GetZHMonthHisUploadPrescription(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1931. //var order models.HisOrder
  1932. //order, _ = service.GetHisOrderByID(order_id)
  1933. //record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  1934. record, _ := service.GetInHospitalRecord(his_patient_id)
  1935. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1936. if config.IsOpen == 1 { //对接了医保,走医保流程
  1937. result, requestLog := service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  1938. //saveLog(result,requestLog,)
  1939. saveLog(result, requestLog, "2302", "月结退明细")
  1940. var dat map[string]interface{}
  1941. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1942. fmt.Println(dat)
  1943. } else {
  1944. fmt.Println(err)
  1945. }
  1946. userJSONBytes, _ := json.Marshal(dat)
  1947. var res2 ResultEmpty
  1948. var resEmpty10265 ResultEmpty10265
  1949. if miConfig.Code == "H15049901371" {
  1950. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  1951. utils.ErrorLog("解析失败:%v", err)
  1952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1953. return
  1954. }
  1955. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  1956. res2.Infcode = Infcode
  1957. res2.RespondTime = resEmpty10265.RespondTime
  1958. res2.ErrMsg = resEmpty10265.ErrMsg
  1959. res2.Output = resEmpty10265.Output
  1960. res2.WarnMsg = resEmpty10265.WarnMsg
  1961. } else {
  1962. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  1963. utils.ErrorLog("解析失败:%v", err)
  1964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1965. return
  1966. }
  1967. }
  1968. if res2.Infcode == 0 {
  1969. err := service.UpdataHospitalOrderStatus(record.Number, adminUser.CurrentOrgId)
  1970. if err == nil {
  1971. c.ServeSuccessJSON(map[string]interface{}{
  1972. "msg": "撤销明细成功",
  1973. })
  1974. } else {
  1975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1976. return
  1977. }
  1978. } else {
  1979. c.ServeSuccessJSON(map[string]interface{}{
  1980. "code": -10,
  1981. "msg": res2.ErrMsg,
  1982. })
  1983. }
  1984. }
  1985. }
  1986. }
  1987. func (this *ZHHisApiController) GetZHOutHospitalUnCheck() {
  1988. id, _ := this.GetInt64("id")
  1989. admin_user_id, _ := this.GetInt64("admin_user_id")
  1990. adminInfo := this.GetAdminUserInfo()
  1991. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1992. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1993. record, _ := service.GetInHospitalRecord(id)
  1994. if record.ID == 0 {
  1995. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  1996. return
  1997. }
  1998. result, requestLog := service.ZHGdyb2405(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  1999. saveLog(result, requestLog, "2405", "出院登记撤销")
  2000. var dat map[string]interface{}
  2001. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2002. fmt.Println(dat)
  2003. } else {
  2004. fmt.Println(err)
  2005. }
  2006. userJSONBytes, _ := json.Marshal(dat)
  2007. var res ResultEmpty
  2008. var resEmpty10265 ResultEmpty10265
  2009. if miConfig.Code == "H15049901371" {
  2010. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2011. utils.ErrorLog("解析失败:%v", err)
  2012. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2013. return
  2014. }
  2015. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2016. res.Infcode = Infcode
  2017. res.RespondTime = resEmpty10265.RespondTime
  2018. res.ErrMsg = resEmpty10265.ErrMsg
  2019. res.Output = resEmpty10265.Output
  2020. res.WarnMsg = resEmpty10265.WarnMsg
  2021. } else {
  2022. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2023. utils.ErrorLog("解析失败:%v", err)
  2024. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2025. return
  2026. }
  2027. }
  2028. if res.Infcode == 0 {
  2029. record.OutHospitalStatus = 0
  2030. service.CreateHospitalRecord(&record)
  2031. service.UpdataOrderStatusByNumber(record.Number)
  2032. this.ServeSuccessJSON(map[string]interface{}{
  2033. "msg": "撤销出院成功",
  2034. })
  2035. } else {
  2036. this.ServeSuccessJSON(map[string]interface{}{
  2037. "failed_code": -10,
  2038. "msg": res.ErrMsg,
  2039. })
  2040. }
  2041. }
  2042. func (this *ZHHisApiController) GetZHInHospitalUnCheck() {
  2043. id, _ := this.GetInt64("id")
  2044. admin_user_id, _ := this.GetInt64("admin_user_id")
  2045. adminInfo := this.GetAdminUserInfo()
  2046. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2047. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  2048. record, _ := service.GetInHospitalRecord(id)
  2049. if record.ID == 0 {
  2050. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  2051. return
  2052. }
  2053. result, requestLog := service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  2054. //saveLog(result,requestLog,)
  2055. saveLog(result, requestLog, "2302", "月结退明细")
  2056. var dat map[string]interface{}
  2057. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2058. fmt.Println(dat)
  2059. } else {
  2060. fmt.Println(err)
  2061. }
  2062. userJSONBytes, _ := json.Marshal(dat)
  2063. var res2 ResultEmpty
  2064. var resEmpty10265 ResultEmpty10265
  2065. if miConfig.Code == "H15049901371" {
  2066. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2067. utils.ErrorLog("解析失败:%v", err)
  2068. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2069. return
  2070. }
  2071. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2072. res2.Infcode = Infcode
  2073. res2.RespondTime = resEmpty10265.RespondTime
  2074. res2.ErrMsg = resEmpty10265.ErrMsg
  2075. res2.Output = resEmpty10265.Output
  2076. res2.WarnMsg = resEmpty10265.WarnMsg
  2077. } else {
  2078. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2079. utils.ErrorLog("解析失败:%v", err)
  2080. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2081. return
  2082. }
  2083. }
  2084. if res2.Infcode == 0 {
  2085. service.UpdataHospitalOrderStatus(record.Number, adminInfo.CurrentOrgId)
  2086. result, requestLog := service.ZHGdyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2087. //saveLog()
  2088. saveLog(result, requestLog, "2404", "入院登记撤销")
  2089. var dat map[string]interface{}
  2090. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2091. fmt.Println(dat)
  2092. } else {
  2093. fmt.Println(err)
  2094. }
  2095. userJSONBytes, _ := json.Marshal(dat)
  2096. var res ResultEmpty
  2097. var resEmpty10265 ResultEmpty10265
  2098. if miConfig.Code == "H15049901371" {
  2099. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2100. utils.ErrorLog("解析失败:%v", err)
  2101. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2102. return
  2103. }
  2104. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2105. res.Infcode = Infcode
  2106. res.RespondTime = resEmpty10265.RespondTime
  2107. res.ErrMsg = resEmpty10265.ErrMsg
  2108. res.Output = resEmpty10265.Output
  2109. res.WarnMsg = resEmpty10265.WarnMsg
  2110. } else {
  2111. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2112. utils.ErrorLog("解析失败:%v", err)
  2113. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2114. return
  2115. }
  2116. }
  2117. if res.Infcode == 0 {
  2118. record.Status = 0
  2119. service.CreateHospitalRecord(&record)
  2120. this.ServeSuccessJSON(map[string]interface{}{
  2121. "msg": "撤销入院成功",
  2122. })
  2123. } else {
  2124. this.ServeSuccessJSON(map[string]interface{}{
  2125. "failed_code": -10,
  2126. "msg": res.ErrMsg,
  2127. })
  2128. }
  2129. } else {
  2130. this.ServeSuccessJSON(map[string]interface{}{
  2131. "code": -10,
  2132. "msg": res2.ErrMsg,
  2133. })
  2134. }
  2135. }
  2136. func saveLog(result string, request string, infno string, desc string) {
  2137. org_id, _ := beego.AppConfig.Int64("org_id")
  2138. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  2139. dir := miConfig.OrgName + "日志"
  2140. utils.Mkdir(dir)
  2141. month := time.Unix(1557042972, 0).Format("1")
  2142. year := time.Now().Format("2006")
  2143. month = time.Now().Format("01")
  2144. day := time.Now().Format("02")
  2145. hour := time.Now().Format("15")
  2146. min := time.Now().Format("04")
  2147. sec := time.Now().Format("05")
  2148. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  2149. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  2150. file_name := file + ".txt"
  2151. file_path := miConfig.OrgName + "日志" + "/" + file_name
  2152. exist, _ := utils.PathExists(file_path)
  2153. if exist { //存在
  2154. fmt.Println("存在")
  2155. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  2156. if err != nil {
  2157. fmt.Println("read fail")
  2158. }
  2159. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  2160. n, _ := f.Seek(0, 2)
  2161. _, err = f.WriteAt([]byte(content), n)
  2162. } else { //不存在
  2163. fmt.Println("文件不存在,创建文件")
  2164. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  2165. defer f.Close()
  2166. if err != nil {
  2167. } else {
  2168. _, err = f.Write([]byte("记录日志"))
  2169. }
  2170. }
  2171. }
  2172. type Charset string
  2173. const (
  2174. UTF8 = Charset("UTF-8")
  2175. GB18030 = Charset("GB18030")
  2176. )
  2177. func ConvertToString(src string, srcCode string, tagCode string) string {
  2178. srcCoder := mahonia.NewDecoder(srcCode)
  2179. srcResult := srcCoder.ConvertString(src)
  2180. tagCoder := mahonia.NewDecoder(tagCode)
  2181. _, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
  2182. result := string(cdata)
  2183. return result
  2184. }
  2185. type ELeData struct {
  2186. Data struct {
  2187. IdNo string `json:"idNo"`
  2188. IdType string `json:"idType"`
  2189. UserName string `json:"userName"`
  2190. EcToken string `json:"ecToken"`
  2191. InsuOrg string `json:"insuOrg"`
  2192. Gender string `json:"gender"`
  2193. Birthday string `json:"birthday"`
  2194. Nationality string `json:"nationality"`
  2195. Email string `json:"email"`
  2196. Extra string `json:"extra"`
  2197. } `json:"data"`
  2198. Code int `json:"code"`
  2199. Message string `json:"message"`
  2200. }
  2201. func (c *ZHHisApiController) ReadCard() {
  2202. id_card_type, _ := c.GetInt64("id_card_type")
  2203. admin_user_id, _ := c.GetInt64("admin_user_id")
  2204. certificates, _ := c.GetInt64("certificates")
  2205. fmt.Println(c.GetAdminUserInfo().CurrentOrgId)
  2206. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  2207. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  2208. switch id_card_type {
  2209. case 1:
  2210. if initFlag == 0 {
  2211. c.TestGetBasBaseInit()
  2212. }
  2213. basStr := c.GetBasBaseInfo(miConfig.Code, miConfig.MdtrtareaAdmvs, roles.UserName, strconv.FormatInt(roles.ID, 10), miConfig.OrgName)
  2214. if len(basStr) == 0 {
  2215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  2216. return
  2217. }
  2218. fmt.Println(basStr)
  2219. bas := strings.Split(basStr, "|")
  2220. basNumber := bas[1]
  2221. fmt.Println(basNumber)
  2222. card_sn := bas[3]
  2223. fmt.Println(card_sn)
  2224. result := service.Gdyb1101B(basNumber, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, card_sn, certificates)
  2225. var dat map[string]interface{}
  2226. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2227. fmt.Println(dat)
  2228. } else {
  2229. fmt.Println(err)
  2230. }
  2231. userJSONBytes, _ := json.Marshal(dat)
  2232. var res ResultTwo
  2233. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2234. utils.ErrorLog("解析失败:%v", err)
  2235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2236. return
  2237. }
  2238. if res.Infcode == 0 {
  2239. var insutypes []string
  2240. var insutype string
  2241. var is390 int = 0
  2242. var is310 int = 0
  2243. for _, item := range res.Output.Iinfo {
  2244. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  2245. insutypes = append(insutypes, item.Insutype)
  2246. }
  2247. }
  2248. if len(insutypes) == 1 {
  2249. insutype = insutypes[0]
  2250. } else {
  2251. for _, i := range insutypes {
  2252. if i == "390" {
  2253. is390 = 1
  2254. }
  2255. if i == "310" {
  2256. is310 = 1
  2257. }
  2258. }
  2259. }
  2260. if is390 == 1 {
  2261. insutype = "390"
  2262. }
  2263. if is310 == 1 {
  2264. insutype = "310"
  2265. }
  2266. if len(insutypes) == 0 {
  2267. insutype = "310"
  2268. }
  2269. patient, err := service.GetPatientByNumber(basNumber, c.GetAdminUserInfo().CurrentOrgId)
  2270. if err == gorm.ErrRecordNotFound {
  2271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  2272. return
  2273. } else if err != nil {
  2274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2275. return
  2276. } else {
  2277. c.ServeSuccessJSON(map[string]interface{}{
  2278. "patient": patient,
  2279. "number": basNumber,
  2280. "info": res,
  2281. "insutype": insutype,
  2282. })
  2283. }
  2284. } else {
  2285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  2286. return
  2287. }
  2288. break
  2289. case 2:
  2290. SFZStr := c.GetSFZBaseInfo()
  2291. id_card_str := strings.Split(SFZStr, "^")
  2292. id_card_number := id_card_str[0]
  2293. card_sn := ""
  2294. result := service.Gdyb1101B(id_card_number, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, card_sn, certificates)
  2295. var dat map[string]interface{}
  2296. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2297. fmt.Println(dat)
  2298. } else {
  2299. fmt.Println(err)
  2300. }
  2301. userJSONBytes, _ := json.Marshal(dat)
  2302. var res ResultTwo
  2303. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2304. utils.ErrorLog("解析失败:%v", err)
  2305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2306. return
  2307. }
  2308. if res.Infcode == 0 {
  2309. patient, err := service.GetPatientByNumber(id_card_number, c.GetAdminUserInfo().CurrentOrgId)
  2310. if err == gorm.ErrRecordNotFound {
  2311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  2312. return
  2313. } else if err != nil {
  2314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2315. return
  2316. } else {
  2317. c.ServeSuccessJSON(map[string]interface{}{
  2318. "patient": patient,
  2319. "number": id_card_number,
  2320. "info": res,
  2321. })
  2322. }
  2323. } else {
  2324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  2325. return
  2326. }
  2327. break
  2328. case 4:
  2329. _, pBusiCardInfo := c.GetELeInfo(miConfig.Code, strconv.FormatInt(roles.ID, 64), roles.UserName)
  2330. var ele ELeData
  2331. err := json.Unmarshal([]byte(pBusiCardInfo), &ele)
  2332. if err != nil {
  2333. utils.ErrorLog("解析失败:%v", err)
  2334. }
  2335. token := ele.Data.EcToken
  2336. fmt.Println(token)
  2337. if len(token) > 0 {
  2338. result := service.Gdyb1101ForEleCert("", miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, token, "")
  2339. var dat map[string]interface{}
  2340. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2341. fmt.Println(dat)
  2342. } else {
  2343. fmt.Println(err)
  2344. }
  2345. userJSONBytes, _ := json.Marshal(dat)
  2346. var res ResultTwo
  2347. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2348. utils.ErrorLog("解析失败:%v", err)
  2349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2350. return
  2351. }
  2352. if res.Infcode == 0 {
  2353. patient, err := service.GetPatientByNumber(ele.Data.IdNo, c.GetAdminUserInfo().CurrentOrgId)
  2354. if err == gorm.ErrRecordNotFound {
  2355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  2356. return
  2357. } else if err != nil {
  2358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2359. return
  2360. } else {
  2361. c.ServeSuccessJSON(map[string]interface{}{
  2362. "patient": patient,
  2363. "number": token,
  2364. "info": res,
  2365. })
  2366. }
  2367. } else {
  2368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  2369. return
  2370. }
  2371. } else {
  2372. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  2373. return
  2374. }
  2375. break
  2376. }
  2377. }
  2378. var initFlag int64 = 0
  2379. func (c *ZHHisApiController) TestGetBasBaseInit() {
  2380. DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
  2381. Iinit := DllDef.MustFindProc("Init")
  2382. //miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  2383. str := make([]byte, 2048)
  2384. inputData := make(map[string]interface{})
  2385. inputData["IP"] = "10.144.211.75"
  2386. inputData["PORT"] = "7021"
  2387. inputData["TIMEOUT"] = "180"
  2388. inputData["LOG_PATH"] = "C:\\log\\"
  2389. bytesData, _ := json.Marshal(inputData)
  2390. fmt.Println(inputData)
  2391. fmt.Println(bytesData)
  2392. ret, _, err := Iinit.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&str[0])))
  2393. if ret != 0 {
  2394. fmt.Println("SSCard的报错原因:", err)
  2395. fmt.Println("SSCard的运算结果为:", ret)
  2396. fmt.Println("SSCard的返回结果为:", string(str))
  2397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  2398. return
  2399. }
  2400. fmt.Println("SSCard的返回结果为:", string(str))
  2401. result := int(ret)
  2402. fmt.Println("SSCard的运算结果为1:", result)
  2403. //initFlag = 1
  2404. return
  2405. }
  2406. func (c *ZHHisApiController) GetSFZBaseInfo() string {
  2407. DllDef := syscall.MustLoadDLL("SSCard.dll")
  2408. readCard := DllDef.MustFindProc("ReadSFZ")
  2409. if readCard == nil {
  2410. fmt.Println("readcard is nil")
  2411. readCard = DllDef.MustFindProc("ReadSFZ")
  2412. }
  2413. str := make([]byte, 256)
  2414. str1 := make([]byte, 256)
  2415. r, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  2416. fmt.Println(r)
  2417. return string(str)
  2418. }
  2419. func (c *ZHHisApiController) GetBasBaseInfo(fixmedins_code string, mdtrtarea_admvs string, opter_name string, opter_id string, fixmedins_name string) string {
  2420. DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
  2421. readCard := DllDef.MustFindProc("ReadCardBas")
  2422. fmt.Println(readCard)
  2423. fmt.Println("!!!!!")
  2424. month := time.Unix(1557042972, 0).Format("1")
  2425. year := time.Now().Format("2006")
  2426. month = time.Now().Format("01")
  2427. day := time.Now().Format("02")
  2428. hour := time.Now().Format("15")
  2429. min := time.Now().Format("04")
  2430. sec := time.Now().Format("05")
  2431. msec := time.Now().Format("000")
  2432. timestamp := time.Now().Unix()
  2433. tempTime := time.Unix(timestamp, 0)
  2434. //timeFormat := tempTime.Format("20060102150405")
  2435. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  2436. //randNum := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000)
  2437. inputData := make(map[string]interface{})
  2438. inputData["infno"] = "1199"
  2439. //inputData["msgid"] = "7021"
  2440. inputData["msgid"] = fixmedins_code + year + month + day + hour + min + sec + msec + "0" // 发送方报文 ID
  2441. inputData["mdtrtarea_admvs"] = mdtrtarea_admvs // 发送方报文 ID
  2442. inputData["recer_sys_code"] = "01"
  2443. inputData["infver"] = "V1.0"
  2444. inputData["opter_type"] = "1"
  2445. inputData["opter"] = opter_id
  2446. inputData["opter_name"] = opter_name
  2447. inputData["inf_time"] = timeFormatOne
  2448. inputData["fixmedins_code"] = fixmedins_code
  2449. inputData["fixmedins_name"] = fixmedins_name
  2450. inputData["dev_no"] = ""
  2451. inputData["dev_safe_info"] = ""
  2452. inputData["cainfo"] = ""
  2453. inputData["signtype"] = ""
  2454. inputData["sign_no"] = ""
  2455. bytesData, _ := json.Marshal(inputData)
  2456. pBusiCardInfo := make([]byte, 8192)
  2457. ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
  2458. fmt.Println(ret2)
  2459. fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
  2460. fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
  2461. if ret2 != 0 {
  2462. return ""
  2463. }
  2464. return DeleteExtraSpace(string(pBusiCardInfo))
  2465. }
  2466. func DeleteExtraSpace(s string) string {
  2467. //删除字符串中的多余空格,有多个空格时,仅保留一个空格
  2468. s1 := strings.Replace(s, " ", " ", -1) //替换tab为空格
  2469. regstr := "\\s{2,}" //两个及两个以上空格的正则表达式
  2470. reg, _ := regexp.Compile(regstr) //编译正则表达式
  2471. s2 := make([]byte, len(s1)) //定义字符数组切片
  2472. copy(s2, s1) //将字符串复制到切片
  2473. spc_index := reg.FindStringIndex(string(s2)) //在字符串中搜索
  2474. for len(spc_index) > 0 { //找到适配项
  2475. s2 = append(s2[:spc_index[0]+1], s2[spc_index[1]:]...) //删除多余空格
  2476. spc_index = reg.FindStringIndex(string(s2)) //继续在字符串中搜索
  2477. }
  2478. return string(s2)
  2479. }
  2480. func (c *ZHHisApiController) GetELeInfo(code string, operator_id string, operator_name string) (string, string) {
  2481. DllDef := syscall.MustLoadDLL("NationECCode.dll")
  2482. readCard := DllDef.MustFindProc("NationEcTrans")
  2483. fmt.Println(readCard)
  2484. fmt.Println("!!!!!")
  2485. pBusiCardInfo := make([]byte, 8192)
  2486. inputData := make(map[string]interface{})
  2487. inputData["orgId"] = code
  2488. inputData["businessType"] = "01101"
  2489. inputData["operatorId"] = operator_id
  2490. inputData["operatorName"] = operator_name
  2491. inputData["officeId"] = "001"
  2492. inputData["officeName"] = "血透室"
  2493. inputData["deviceType"] = ""
  2494. bytesData, _ := json.Marshal(inputData)
  2495. url := "http://localcfc/api/hsecfc/localQrCodeQuery"
  2496. ret2, _, _ := readCard.Call(StrPtr(url), StrPtr(string(bytesData)), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
  2497. fmt.Println(ret2)
  2498. fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
  2499. fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
  2500. if ret2 != 0 {
  2501. return "", ""
  2502. }
  2503. return DeleteExtraSpace(""), DeleteExtraSpace(string(pBusiCardInfo))
  2504. }
  2505. func StrPtr(s string) uintptr {
  2506. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  2507. }
  2508. func Remove0000(s string) string {
  2509. str := make([]rune, 0, len(s))
  2510. for _, v := range []rune(s) {
  2511. if v == 0 {
  2512. continue
  2513. }
  2514. str = append(str, v)
  2515. }
  2516. return string(str)
  2517. }
  2518. func IntPtr(n int) uintptr {
  2519. return uintptr(n)
  2520. }