zh_his_api_controller.go 115KB

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