zh_his_api_controller.go 110KB

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