zh_his_api_controller.go 115KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387
  1. package zh
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "fmt"
  6. "gdyb/controllers"
  7. "gdyb/enums"
  8. "gdyb/models"
  9. "gdyb/service"
  10. "gdyb/utils"
  11. "github.com/astaxie/beego"
  12. "github.com/axgle/mahonia"
  13. "github.com/jinzhu/gorm"
  14. "io/ioutil"
  15. "math"
  16. "math/rand"
  17. "net/http"
  18. "os"
  19. "regexp"
  20. "strconv"
  21. "strings"
  22. "syscall"
  23. "time"
  24. "unsafe"
  25. )
  26. type ZHHisApiController struct {
  27. controllers.BaseAuthAPIController
  28. }
  29. type ResultSix struct {
  30. Cainfo interface{} `json:"cainfo"`
  31. ErrMsg string `json:"err_msg"`
  32. InfRefmsgid string `json:"inf_refmsgid"`
  33. Infcode int64 `json:"infcode"`
  34. Output struct {
  35. } `json:"output"`
  36. RefmsgTime string `json:"refmsg_time"`
  37. RespondTime string `json:"respond_time"`
  38. Signtype interface{} `json:"signtype"`
  39. WarnMsg interface{} `json:"warn_msg"`
  40. }
  41. type ResultTwo struct {
  42. ErrMsg string `json:"err_msg"`
  43. InfRefmsgid string `json:"inf_refmsgid"`
  44. Infcode int64 `json:"infcode"`
  45. Output struct {
  46. Baseinfo struct {
  47. Age float64 `json:"age"`
  48. Brdy string `json:"brdy"`
  49. Certno string `json:"certno"`
  50. Gend string `json:"gend"`
  51. Naty string `json:"naty"`
  52. PsnCertType string `json:"psn_cert_type"`
  53. PsnName string `json:"psn_name"`
  54. PsnNo string `json:"psn_no"`
  55. } `json:"baseinfo"`
  56. Idetinfo []interface{} `json:"idetinfo"`
  57. Iinfo []struct {
  58. Balc float64 `json:"balc"`
  59. CvlservFlag string `json:"cvlserv_flag"`
  60. EmpName string `json:"emp_name"`
  61. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  62. Insutype string `json:"insutype"`
  63. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  64. PausInsuDate string `json:"paus_insu_date"`
  65. PsnInsuDate string `json:"psn_insu_date"`
  66. PsnInsuStas string `json:"psn_insu_stas"`
  67. PsnType string `json:"psn_type"`
  68. } `json:"insuinfo"`
  69. } `json:"output"`
  70. RefmsgTime string `json:"refmsg_time"`
  71. RespondTime string `json:"respond_time"`
  72. Signtype interface{} `json:"signtype"`
  73. WarnInfo interface{} `json:"warn_info"`
  74. }
  75. type ResultTwo10265 struct {
  76. ErrMsg string `json:"err_msg"`
  77. InfRefmsgid string `json:"inf_refmsgid"`
  78. Infcode string `json:"infcode"`
  79. Output struct {
  80. Baseinfo struct {
  81. Age float64 `json:"age"`
  82. Brdy string `json:"brdy"`
  83. Certno string `json:"certno"`
  84. Gend string `json:"gend"`
  85. Naty string `json:"naty"`
  86. PsnCertType string `json:"psn_cert_type"`
  87. PsnName string `json:"psn_name"`
  88. PsnNo string `json:"psn_no"`
  89. } `json:"baseinfo"`
  90. Idetinfo []interface{} `json:"idetinfo"`
  91. Iinfo []struct {
  92. Balc float64 `json:"balc"`
  93. CvlservFlag string `json:"cvlserv_flag"`
  94. EmpName string `json:"emp_name"`
  95. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  96. Insutype string `json:"insutype"`
  97. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  98. PausInsuDate string `json:"paus_insu_date"`
  99. PsnInsuDate string `json:"psn_insu_date"`
  100. PsnInsuStas string `json:"psn_insu_stas"`
  101. PsnType string `json:"psn_type"`
  102. } `json:"insuinfo"`
  103. } `json:"output"`
  104. RefmsgTime string `json:"refmsg_time"`
  105. RespondTime string `json:"respond_time"`
  106. Signtype interface{} `json:"signtype"`
  107. WarnInfo interface{} `json:"warn_info"`
  108. }
  109. type ResultThree struct {
  110. Cainfo interface{} `json:"cainfo"`
  111. ErrMsg string `json:"err_msg"`
  112. InfRefmsgid string `json:"inf_refmsgid"`
  113. Infcode int64 `json:"infcode"`
  114. Output struct {
  115. Result struct {
  116. MdtrtID string `json:"mdtrt_id"`
  117. } `json:"result"`
  118. } `json:"output"`
  119. RefmsgTime string `json:"refmsg_time"`
  120. RespondTime string `json:"respond_time"`
  121. Signtype interface{} `json:"signtype"`
  122. WarnMsg interface{} `json:"warn_msg"`
  123. }
  124. type ResultThree10265 struct {
  125. Cainfo interface{} `json:"cainfo"`
  126. ErrMsg string `json:"err_msg"`
  127. InfRefmsgid string `json:"inf_refmsgid"`
  128. Infcode string `json:"infcode"`
  129. Output struct {
  130. Result struct {
  131. MdtrtID string `json:"mdtrt_id"`
  132. } `json:"result"`
  133. } `json:"output"`
  134. RefmsgTime string `json:"refmsg_time"`
  135. RespondTime string `json:"respond_time"`
  136. Signtype interface{} `json:"signtype"`
  137. WarnMsg interface{} `json:"warn_msg"`
  138. }
  139. type ResultFour struct {
  140. Cainfo string `json:"cainfo"`
  141. ErrMsg string `json:"err_msg"`
  142. InfRefmsgid string `json:"inf_refmsgid"`
  143. Infcode int64 `json:"infcode"`
  144. Output struct {
  145. Result []struct {
  146. BasMednFlag string `json:"bas_medn_flag"`
  147. ChldMedcFlag string `json:"chld_medc_flag"`
  148. ChrgitmLv string `json:"chrgitm_lv"`
  149. Cnt float64 `json:"cnt"`
  150. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  151. DrtReimFlag string `json:"drt_reim_flag"`
  152. FeedetlSn string `json:"feedetl_sn"`
  153. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  154. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  155. InscpScpAmt float64 `json:"inscp_scp_amt"`
  156. ListSpItemFlag string `json:"list_sp_item_flag"`
  157. LmtUsedFlag string `json:"lmt_used_flag"`
  158. MedChrgitmType string `json:"med_chrgitm_type"`
  159. Memo string `json:"memo"`
  160. OverlmtAmt float64 `json:"overlmt_amt"`
  161. PreselfpayAmt float64 `json:"preselfpay_amt"`
  162. Pric float64 `json:"pric"`
  163. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  164. SelfpayProp float64 `json:"selfpay_prop"`
  165. } `json:"result"`
  166. } `json:"output"`
  167. RefmsgTime string `json:"refmsg_time"`
  168. RespondTime string `json:"respond_time"`
  169. Signtype string `json:"signtype"`
  170. WarnMsg string `json:"warn_msg"`
  171. }
  172. type ResultFour10265 struct {
  173. Cainfo string `json:"cainfo"`
  174. ErrMsg string `json:"err_msg"`
  175. InfRefmsgid string `json:"inf_refmsgid"`
  176. Infcode string `json:"infcode"`
  177. Output struct {
  178. Result []struct {
  179. BasMednFlag string `json:"bas_medn_flag"`
  180. ChldMedcFlag string `json:"chld_medc_flag"`
  181. ChrgitmLv string `json:"chrgitm_lv"`
  182. Cnt float64 `json:"cnt"`
  183. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  184. DrtReimFlag string `json:"drt_reim_flag"`
  185. FeedetlSn string `json:"feedetl_sn"`
  186. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  187. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  188. InscpScpAmt float64 `json:"inscp_scp_amt"`
  189. ListSpItemFlag string `json:"list_sp_item_flag"`
  190. LmtUsedFlag string `json:"lmt_used_flag"`
  191. MedChrgitmType string `json:"med_chrgitm_type"`
  192. Memo string `json:"memo"`
  193. OverlmtAmt float64 `json:"overlmt_amt"`
  194. PreselfpayAmt float64 `json:"preselfpay_amt"`
  195. Pric float64 `json:"pric"`
  196. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  197. SelfpayProp float64 `json:"selfpay_prop"`
  198. } `json:"result"`
  199. } `json:"output"`
  200. RefmsgTime string `json:"refmsg_time"`
  201. RespondTime string `json:"respond_time"`
  202. Signtype string `json:"signtype"`
  203. WarnMsg string `json:"warn_msg"`
  204. }
  205. type ResultFive struct {
  206. Balc float64 `json:"balc"`
  207. CvlservFlag string `json:"cvlserv_flag"`
  208. EmpName string `json:"emp_name"`
  209. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  210. Insutype string `json:"insutype"`
  211. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  212. PausInsuDate string `json:"paus_insu_date"`
  213. PsnInsuDate string `json:"psn_insu_date"`
  214. PsnInsuStas string `json:"psn_insu_stas"`
  215. PsnType string `json:"psn_type"`
  216. }
  217. type ResultSeven struct {
  218. Cainfo string `json:"cainfo"`
  219. ErrMsg string `json:"err_msg"`
  220. InfRefmsgid string `json:"inf_refmsgid"`
  221. Infcode int64 `json:"infcode"`
  222. Output struct {
  223. Setldetail []interface{} `json:"setldetail"`
  224. Setlinfo struct {
  225. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  226. AcctPay float64 `json:"acct_pay"`
  227. ActPayDedc float64 `json:"act_pay_dedc"`
  228. Age float64 `json:"age"`
  229. Balc float64 `json:"balc"`
  230. Brdy string `json:"brdy"`
  231. Certno string `json:"certno"`
  232. ClrOptins string `json:"clr_optins"`
  233. ClrType string `json:"clr_type"`
  234. ClrWay string `json:"clr_way"`
  235. CvlservFlag string `json:"cvlserv_flag"`
  236. CvlservPay float64 `json:"cvlserv_pay"`
  237. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  238. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  239. Gend string `json:"gend"`
  240. HifesPay float64 `json:"hifes_pay"`
  241. HifmiPay float64 `json:"hifmi_pay"`
  242. HifpPay float64 `json:"hifp_pay"`
  243. HospPartAmt float64 `json:"hosp_part_amt"`
  244. InscpScpAmt float64 `json:"inscp_scp_amt"`
  245. Insutype string `json:"insutype"`
  246. MafPay float64 `json:"maf_pay"`
  247. MdtrtCertType string `json:"mdtrt_cert_type"`
  248. HifobPay float64 `json:"hifob_pay"`
  249. MdtrtID string `json:"mdtrt_id"`
  250. MedType string `json:"med_type"`
  251. MedfeeSumamt float64 `json:"medfee_sumamt"`
  252. MedinsSetlID string `json:"medins_setl_id"`
  253. Naty string `json:"naty"`
  254. OthPay float64 `json:"oth_pay"`
  255. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  256. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  257. PreselfpayAmt float64 `json:"preselfpay_amt"`
  258. PsnCashPay float64 `json:"psn_cash_pay"`
  259. PsnCertType string `json:"psn_cert_type"`
  260. PsnName string `json:"psn_name"`
  261. PsnNo string `json:"psn_no"`
  262. PsnPartAmt float64 `json:"psn_part_amt"`
  263. PsnType string `json:"psn_type"`
  264. SetlID string `json:"setl_id"`
  265. SetlTime string `json:"setl_time"`
  266. } `json:"setlinfo"`
  267. } `json:"output"`
  268. RefmsgTime string `json:"refmsg_time"`
  269. RespondTime string `json:"respond_time"`
  270. Signtype interface{} `json:"signtype"`
  271. WarnMsg interface{} `json:"warn_msg"`
  272. }
  273. type ResultSeven10265 struct {
  274. Cainfo string `json:"cainfo"`
  275. ErrMsg string `json:"err_msg"`
  276. InfRefmsgid string `json:"inf_refmsgid"`
  277. Infcode string `json:"infcode"`
  278. Output struct {
  279. Setldetail []interface{} `json:"setldetail"`
  280. Setlinfo struct {
  281. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  282. AcctPay float64 `json:"acct_pay"`
  283. ActPayDedc float64 `json:"act_pay_dedc"`
  284. Age float64 `json:"age"`
  285. Balc float64 `json:"balc"`
  286. Brdy string `json:"brdy"`
  287. Certno string `json:"certno"`
  288. ClrOptins string `json:"clr_optins"`
  289. ClrType string `json:"clr_type"`
  290. ClrWay string `json:"clr_way"`
  291. CvlservFlag string `json:"cvlserv_flag"`
  292. CvlservPay float64 `json:"cvlserv_pay"`
  293. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  294. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  295. Gend string `json:"gend"`
  296. HifesPay float64 `json:"hifes_pay"`
  297. HifmiPay float64 `json:"hifmi_pay"`
  298. HifpPay float64 `json:"hifp_pay"`
  299. HospPartAmt float64 `json:"hosp_part_amt"`
  300. InscpScpAmt float64 `json:"inscp_scp_amt"`
  301. Insutype string `json:"insutype"`
  302. MafPay float64 `json:"maf_pay"`
  303. MdtrtCertType string `json:"mdtrt_cert_type"`
  304. HifobPay float64 `json:"hifob_pay"`
  305. MdtrtID string `json:"mdtrt_id"`
  306. MedType string `json:"med_type"`
  307. MedfeeSumamt float64 `json:"medfee_sumamt"`
  308. MedinsSetlID string `json:"medins_setl_id"`
  309. Naty string `json:"naty"`
  310. OthPay float64 `json:"oth_pay"`
  311. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  312. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  313. PreselfpayAmt float64 `json:"preselfpay_amt"`
  314. PsnCashPay float64 `json:"psn_cash_pay"`
  315. PsnCertType string `json:"psn_cert_type"`
  316. PsnName string `json:"psn_name"`
  317. PsnNo string `json:"psn_no"`
  318. PsnPartAmt float64 `json:"psn_part_amt"`
  319. PsnType string `json:"psn_type"`
  320. SetlID string `json:"setl_id"`
  321. SetlTime string `json:"setl_time"`
  322. } `json:"setlinfo"`
  323. } `json:"output"`
  324. RefmsgTime string `json:"refmsg_time"`
  325. RespondTime string `json:"respond_time"`
  326. Signtype interface{} `json:"signtype"`
  327. WarnMsg interface{} `json:"warn_msg"`
  328. }
  329. type ResultSixteen struct {
  330. Cainfo string `json:"cainfo"`
  331. ErrMsg string `json:"err_msg"`
  332. InfRefmsgid string `json:"inf_refmsgid"`
  333. Infcode int64 `json:"infcode"`
  334. Output struct {
  335. Setldetail []interface{} `json:"setldetail"`
  336. Setlinfo struct {
  337. MdtrtID string `json:"mdtrt_id"`
  338. SetlID string `json:"setl_id"`
  339. ClrOptins string `json:"clr_optins"`
  340. SetlTime string `json:"setl_time"`
  341. MedfeeSumamt float64 `json:"medfee_sumamt"`
  342. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  343. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  344. PreselfpayAmt float64 `json:"preselfpay_amt"`
  345. InscpScpAmt float64 `json:"inscp_scp_amt"`
  346. ActPayDedc float64 `json:"act_pay_dedc"`
  347. HifpPay float64 `json:"hifp_pay"`
  348. PoolPropSe float64 `json:"pool_prop_selfpay"`
  349. Lfpay float64 `json:"selfpay"`
  350. CvlservPay float64 `json:"cvlserv_pay"`
  351. HifesPay float64 `json:"hifes_pay"`
  352. HifmiPay float64 `json:"hifmi_pay"`
  353. HifobPay float64 `json:"hifob_pay"`
  354. MafPay float64 `json:"maf_pay"`
  355. OthPay float64 `json:"oth_pay"`
  356. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  357. PsnPartAmt float64 `json:"psn_part_amt"`
  358. AcctPay float64 `json:"acct_pay"`
  359. Balc float64 `json:"balc"`
  360. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  361. HospPartAmt float64 `json:"hosp_part_amt"`
  362. MedinsSetlID string `json:"medins_setl_id"`
  363. PdnCashPay string `json:"pdn_cash_pay"`
  364. } `json:"setlinfo"`
  365. } `json:"output"`
  366. RefmsgTime string `json:"refmsg_time"`
  367. RespondTime string `json:"respond_time"`
  368. Signtype interface{} `json:"signtype"`
  369. WarnMsg interface{} `json:"warn_msg"`
  370. }
  371. type ResultSixteen10265 struct {
  372. Cainfo string `json:"cainfo"`
  373. ErrMsg string `json:"err_msg"`
  374. InfRefmsgid string `json:"inf_refmsgid"`
  375. Infcode string `json:"infcode"`
  376. Output struct {
  377. Setldetail []interface{} `json:"setldetail"`
  378. Setlinfo struct {
  379. MdtrtID string `json:"mdtrt_id"`
  380. SetlID string `json:"setl_id"`
  381. ClrOptins string `json:"clr_optins"`
  382. SetlTime string `json:"setl_time"`
  383. MedfeeSumamt float64 `json:"medfee_sumamt"`
  384. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  385. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  386. PreselfpayAmt float64 `json:"preselfpay_amt"`
  387. InscpScpAmt float64 `json:"inscp_scp_amt"`
  388. ActPayDedc float64 `json:"act_pay_dedc"`
  389. HifpPay float64 `json:"hifp_pay"`
  390. PoolPropSe float64 `json:"pool_prop_selfpay"`
  391. Lfpay float64 `json:"selfpay"`
  392. CvlservPay float64 `json:"cvlserv_pay"`
  393. HifesPay float64 `json:"hifes_pay"`
  394. HifmiPay float64 `json:"hifmi_pay"`
  395. HifobPay float64 `json:"hifob_pay"`
  396. MafPay float64 `json:"maf_pay"`
  397. OthPay float64 `json:"oth_pay"`
  398. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  399. PsnPartAmt float64 `json:"psn_part_amt"`
  400. AcctPay float64 `json:"acct_pay"`
  401. Balc float64 `json:"balc"`
  402. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  403. HospPartAmt float64 `json:"hosp_part_amt"`
  404. MedinsSetlID string `json:"medins_setl_id"`
  405. PdnCashPay string `json:"pdn_cash_pay"`
  406. } `json:"setlinfo"`
  407. } `json:"output"`
  408. RefmsgTime string `json:"refmsg_time"`
  409. RespondTime string `json:"respond_time"`
  410. Signtype interface{} `json:"signtype"`
  411. WarnMsg interface{} `json:"warn_msg"`
  412. }
  413. type Custom struct {
  414. DetItemFeeSumamt string
  415. Cut string
  416. FeedetlSn string
  417. Price string
  418. MedListCodg string
  419. Type int64
  420. AdviceId int64
  421. ProjectId int64
  422. ItemId int64
  423. }
  424. type ResultEmpty struct {
  425. Cainfo interface{} `json:"cainfo"`
  426. ErrMsg string `json:"err_msg"`
  427. InfRefmsgid string `json:"inf_refmsgid"`
  428. Infcode int64 `json:"infcode"`
  429. Output struct {
  430. } `json:"output"`
  431. RefmsgTime string `json:"refmsg_time"`
  432. RespondTime string `json:"respond_time"`
  433. Signtype interface{} `json:"signtype"`
  434. WarnMsg interface{} `json:"warn_msg"`
  435. }
  436. type ResultEmpty10265 struct {
  437. Cainfo interface{} `json:"cainfo"`
  438. ErrMsg string `json:"err_msg"`
  439. InfRefmsgid string `json:"inf_refmsgid"`
  440. Infcode string `json:"infcode"`
  441. Output struct {
  442. } `json:"output"`
  443. RefmsgTime string `json:"refmsg_time"`
  444. RespondTime string `json:"respond_time"`
  445. Signtype interface{} `json:"signtype"`
  446. WarnMsg interface{} `json:"warn_msg"`
  447. }
  448. type CustomResult struct {
  449. BasMednFlag string `json:"bas_medn_flag"`
  450. ChldMedcFlag string `json:"chld_medc_flag"`
  451. ChrgitmLv string `json:"chrgitm_lv"`
  452. Cnt float64 `json:"cnt"`
  453. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  454. DrtReimFlag string `json:"drt_reim_flag"`
  455. FeedetlSn string `json:"feedetl_sn"`
  456. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  457. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  458. InscpScpAmt float64 `json:"inscp_scp_amt"`
  459. ListSpItemFlag string `json:"list_sp_item_flag"`
  460. LmtUsedFlag string `json:"lmt_used_flag"`
  461. MedChrgitmType string `json:"med_chrgitm_type"`
  462. Memo string `json:"memo"`
  463. OverlmtAmt float64 `json:"overlmt_amt"`
  464. PreselfpayAmt float64 `json:"preselfpay_amt"`
  465. Pric float64 `json:"pric"`
  466. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  467. SelfpayProp float64 `json:"selfpay_prop"`
  468. }
  469. func ZHHisManagerApiRegistRouters() {
  470. beego.Router("/zh/api/inhopitalcheck/get", &ZHHisApiController{}, "get:GetZHInHospitalCheck")
  471. beego.Router("/zh/api/outhopitalcheck/get", &ZHHisApiController{}, "get:GetZHOutHospitalCheck")
  472. beego.Router("/zh/api/uploadinfo/get", &ZHHisApiController{}, "get:GetUploadInfo")
  473. beego.Router("/zh/api/presettle/get", &ZHHisApiController{}, "get:GetPreSettleInfo")
  474. beego.Router("/zh/api/settle/get", &ZHHisApiController{}, "get:GetSettleInfo")
  475. beego.Router("/zh/api/inthopitaluncheck/get", &ZHHisApiController{}, "get:GetZHInHospitalUnCheck")
  476. beego.Router("/zh/api/outhopitaluncheck/get", &ZHHisApiController{}, "get:GetZHOutHospitalUnCheck")
  477. beego.Router("/zh/api/refund", &ZHHisApiController{}, "get:ZHRefund")
  478. beego.Router("/zh/api/refunddetail", &ZHHisApiController{}, "get:ZHRefundDetail")
  479. beego.Router("/zh/api/patient/info", &ZHHisApiController{}, "get:GetZHPatientInfo")
  480. beego.Router("/zh/api/readcard", &ZHHisApiController{}, "get:ReadCard")
  481. beego.Router("/zh/api/clearsettle", &ZHHisApiController{}, "get:ClearSettle")
  482. }
  483. func (c *ZHHisApiController) ClearSettle() {
  484. order_id, _ := c.GetInt64("order_id")
  485. admin_user_id, _ := c.GetInt64("admin_user_id")
  486. adminUser := c.GetAdminUserInfo()
  487. var order models.HisOrder
  488. order, _ = service.GetHisOrderByID(order_id)
  489. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  490. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  491. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  492. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  493. if config.IsOpen == 1 { //对接了医保,走医保流程
  494. var result string
  495. var requestLog string
  496. result, requestLog = service.Gdyb90306(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  497. saveLog(result, requestLog, "90306", "撤销结算清单")
  498. var dat map[string]interface{}
  499. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  500. fmt.Println(dat)
  501. } else {
  502. fmt.Println(err)
  503. }
  504. userJSONBytes, _ := json.Marshal(dat)
  505. var res ResultSix
  506. //var resSixteen ResultSixteen10265
  507. if miConfig.Code == "H15049901371" {
  508. //if err := json.Unmarshal(userJSONBytes, &resSixteen); err != nil {
  509. // utils.ErrorLog("解析失败:%v", err)
  510. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  511. // return
  512. //}
  513. //res.Cainfo = resSixteen.Cainfo
  514. //res.WarnMsg = resSixteen.WarnMsg
  515. //res.Output = resSixteen.Output
  516. //res.ErrMsg = resSixteen.ErrMsg
  517. //res.RespondTime = resSixteen.RespondTime
  518. //Infcode, _ := strconv.ParseInt(resSixteen.Infcode, 10, 64)
  519. //res.Infcode = Infcode
  520. } else {
  521. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  522. utils.ErrorLog("解析失败:%v", err)
  523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  524. return
  525. }
  526. }
  527. if res.Infcode == 0 {
  528. 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. var rf []*ResultFive
  1282. json.Unmarshal([]byte(record.Iinfo), &rf)
  1283. chrg_bchno := order.Number
  1284. cert_no := record.Certno
  1285. if record.ID == 0 {
  1286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1287. return
  1288. }
  1289. if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  1290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  1291. return
  1292. }
  1293. if record.IdCardType == 1 {
  1294. } else {
  1295. cert_no = record.Certno
  1296. }
  1297. var result string
  1298. var src_resquest string
  1299. timeLayout := "2006-01-02"
  1300. loc, _ := time.LoadLocation("Local")
  1301. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record.InHosptialTime, loc)
  1302. if err != nil {
  1303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1304. return
  1305. }
  1306. recordStartDateTime := theTime.Unix()
  1307. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", record.OutHosptialTime, loc)
  1308. if err != nil {
  1309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1310. return
  1311. }
  1312. recordEndDateTime := theTimeEnd.Unix()
  1313. prescriptions, _ := service.GetZHSettleMonthHisPrescription(c.GetAdminUserInfo().CurrentOrgId, patient_id, recordStartDateTime, recordEndDateTime)
  1314. var total float64
  1315. for _, item := range prescriptions {
  1316. if item.Type == 1 { //药品
  1317. for _, subItem := range item.HisDoctorAdviceInfo {
  1318. total = total + (subItem.Price * subItem.PrescribingNumber)
  1319. }
  1320. }
  1321. if item.Type == 2 { //项目
  1322. for _, subItem := range item.HisPrescriptionProject {
  1323. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  1324. total = total + (subItem.Price * cnt)
  1325. }
  1326. }
  1327. }
  1328. //allTotal := fmt.Sprintf("%.2f", total)
  1329. var allTotal string
  1330. if record.OutHospitalStatus == 0 && order.ID == 0 {
  1331. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  1332. var total float64
  1333. for _, item := range orders {
  1334. total = total + item.DetItemFeeSumamt
  1335. }
  1336. allTotal = fmt.Sprintf("%.4f", total)
  1337. } else {
  1338. allTotal = fmt.Sprintf("%.4f", order.MedfeeSumamt)
  1339. }
  1340. if miConfig.MdtrtareaAdmvs == "150499" {
  1341. psn_info, _ := service.GetPsnByPatientId(patient_id)
  1342. mdtrt_cert_no := ""
  1343. if record.IdCardType == 1 {
  1344. bas := strings.Split(psn_info.CardInfo, "|")
  1345. cardNumber := bas[2]
  1346. mdtrt_cert_no = cardNumber
  1347. } else {
  1348. mdtrt_cert_no = record.Certno
  1349. }
  1350. //请求内网数据
  1351. api := "http://172.16.13.254:9532/" + "nmyb/2304?psn_no=" + record.PsnNo + "&mdtrt_id=" + record.Number + "&chrg_bchno=" + chrg_bchno +
  1352. "&insutype_type=" + record.InsutypeType + "&total=" + allTotal +
  1353. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  1354. "&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
  1355. resp, requestErr := http.Get(api)
  1356. if requestErr != nil {
  1357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1358. return
  1359. }
  1360. body, ioErr := ioutil.ReadAll(resp.Body)
  1361. if ioErr != nil {
  1362. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1364. return
  1365. }
  1366. var respJSON map[string]interface{}
  1367. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1368. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1370. return
  1371. }
  1372. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1373. result_byte, _ := json.Marshal(respJSON)
  1374. result = string(result_byte)
  1375. } else {
  1376. 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, "")
  1377. saveLog(result, src_resquest, "2304", "住院结算")
  1378. }
  1379. var dat map[string]interface{}
  1380. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1381. fmt.Println(dat)
  1382. } else {
  1383. fmt.Println(err)
  1384. }
  1385. userJSONBytes, _ := json.Marshal(dat)
  1386. var res ResultSeven
  1387. var resSeven10265 ResultSeven10265
  1388. if miConfig.Code == "H15049901371" {
  1389. if err := json.Unmarshal(userJSONBytes, &resSeven10265); err != nil {
  1390. utils.ErrorLog("解析失败:%v", err)
  1391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1392. return
  1393. }
  1394. Infcode, _ := strconv.ParseInt(resSeven10265.Infcode, 10, 64)
  1395. res.Infcode = Infcode
  1396. res.InfRefmsgid = resSeven10265.InfRefmsgid
  1397. res.RespondTime = resSeven10265.RespondTime
  1398. res.ErrMsg = resSeven10265.ErrMsg
  1399. res.Output = resSeven10265.Output
  1400. res.WarnMsg = resSeven10265.WarnMsg
  1401. res.Cainfo = resSeven10265.Cainfo
  1402. } else {
  1403. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1404. utils.ErrorLog("解析失败:%v", err)
  1405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1406. return
  1407. }
  1408. }
  1409. if res.Infcode != 0 {
  1410. errlog := &models.HisOrderError{
  1411. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1412. Ctime: time.Now().Unix(),
  1413. Mtime: time.Now().Unix(),
  1414. Number: chrg_bchno,
  1415. ErrMsg: res.ErrMsg,
  1416. Status: 1,
  1417. PatientId: patient_id,
  1418. RecordTime: time.Now().Unix(),
  1419. Stage: 6,
  1420. }
  1421. service.CreateErrMsgLog(errlog)
  1422. c.ServeSuccessJSON(map[string]interface{}{
  1423. "failed_code": -10,
  1424. "msg": res.ErrMsg,
  1425. })
  1426. return
  1427. } else {
  1428. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1429. order.OrderStatus = 2
  1430. order.DiscountPrice = discount_price
  1431. order.MedicalInsurancePrice = medical_insurance_price
  1432. order.FaPiaoNumber = fapiao_number
  1433. order.FaPiaoCode = fapiao_code
  1434. order.PayWay = pay_way
  1435. order.PayPrice = pay_price
  1436. order.PayCardNo = pay_card_no
  1437. order.PreferentialPrice = preferential_price
  1438. order.RealityPrice = reality_price
  1439. order.FoundPrice = found_price
  1440. order.PrivatePrice = private_price
  1441. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1442. order.SetlId = res.Output.Setlinfo.SetlID
  1443. order.PsnNo = res.Output.Setlinfo.PsnNo
  1444. order.PsnName = res.Output.Setlinfo.PsnName
  1445. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1446. order.Certno = res.Output.Setlinfo.Certno
  1447. order.Gend = res.Output.Setlinfo.Gend
  1448. order.Naty = res.Output.Setlinfo.Naty
  1449. order.Age = res.Output.Setlinfo.Age
  1450. order.Insutype = res.Output.Setlinfo.Insutype
  1451. order.PsnType = res.Output.Setlinfo.PsnType
  1452. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1453. order.SetlTime = res.Output.Setlinfo.SetlTime
  1454. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1455. if res.Output.Setlinfo.MedType == "140104" {
  1456. order.MedType = "14"
  1457. } else {
  1458. order.MedType = res.Output.Setlinfo.MedType
  1459. }
  1460. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1461. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1462. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1463. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1464. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1465. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1466. order.HifpPay = res.Output.Setlinfo.HifpPay
  1467. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1468. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1469. order.HifesPay = res.Output.Setlinfo.HifesPay
  1470. order.HifobPay = res.Output.Setlinfo.HifobPay
  1471. order.MafPay = res.Output.Setlinfo.MafPay
  1472. order.OthPay = res.Output.Setlinfo.OthPay
  1473. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1474. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1475. order.AcctPay = res.Output.Setlinfo.AcctPay
  1476. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1477. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1478. order.Balc = res.Output.Setlinfo.Balc
  1479. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1480. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1481. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1482. order.ClrWay = res.Output.Setlinfo.ClrWay
  1483. order.Creator = order.Creator
  1484. order.Modify = roles.AdminUserId
  1485. order.RequestLog = src_resquest
  1486. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1487. detailStr := string(setlDetail)
  1488. order.SetlDetail = detailStr
  1489. err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  1490. err = service.UpDateOrder(order)
  1491. if err == nil {
  1492. c.ServeSuccessJSON(map[string]interface{}{
  1493. "msg": "结算成功",
  1494. })
  1495. } else {
  1496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1497. return
  1498. }
  1499. }
  1500. }
  1501. func (c *ZHHisApiController) GetPreSettleInfo() {
  1502. order_id, _ := c.GetInt64("order_id")
  1503. patient_id, _ := c.GetInt64("patient_id")
  1504. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  1505. admin_user_id, _ := c.GetInt64("admin_user_id")
  1506. record, _ := service.GetInHospitalRecord(in_hospital_id)
  1507. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  1508. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  1509. order, _ := service.GetHisOrderByID(order_id)
  1510. var allTotal string
  1511. if record.OutHospitalStatus == 0 && order.ID == 0 {
  1512. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  1513. var total float64
  1514. for _, item := range orders {
  1515. total = total + item.DetItemFeeSumamt
  1516. }
  1517. allTotal = fmt.Sprintf("%.4f", total)
  1518. } else {
  1519. allTotal = fmt.Sprintf("%.4f", order.MedfeeSumamt)
  1520. }
  1521. var rf []*ResultFive
  1522. json.Unmarshal([]byte(record.Iinfo), &rf)
  1523. chrg_bchno := order.Number
  1524. cert_no := record.Certno
  1525. if record.ID == 0 {
  1526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1527. return
  1528. }
  1529. //if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  1530. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  1531. // return
  1532. //}
  1533. psn_info, _ := service.GetPsnByPatientId(patient_id)
  1534. if record.IdCardType == 1 {
  1535. bas := strings.Split(psn_info.CardInfo, "|")
  1536. cardNumber := bas[2]
  1537. cert_no = cardNumber
  1538. } else {
  1539. cert_no = record.Certno
  1540. }
  1541. var result string
  1542. var src_resquest string
  1543. if miConfig.MdtrtareaAdmvs == "150499" {
  1544. //请求内网数据
  1545. api := "http://172.16.13.254:9532/" + "nmyb/2303?psn_no=" + record.PsnNo + "&mdtrt_id=" + record.Number + "&chrg_bchno=" + chrg_bchno +
  1546. "&insutype_type=" + record.InsutypeType + "&total=" + allTotal +
  1547. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  1548. "&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
  1549. resp, requestErr := http.Get(api)
  1550. if requestErr != nil {
  1551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1552. return
  1553. }
  1554. body, ioErr := ioutil.ReadAll(resp.Body)
  1555. if ioErr != nil {
  1556. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1558. return
  1559. }
  1560. var respJSON map[string]interface{}
  1561. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1562. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1564. return
  1565. }
  1566. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1567. result_byte, _ := json.Marshal(respJSON)
  1568. result = string(result_byte)
  1569. } else {
  1570. 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)
  1571. saveLog(result, src_resquest, "2303", "住院预结算")
  1572. }
  1573. var dat map[string]interface{}
  1574. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1575. fmt.Println(dat)
  1576. } else {
  1577. fmt.Println(err)
  1578. }
  1579. userJSONBytes, _ := json.Marshal(dat)
  1580. var res ResultSeven
  1581. var resSeven10265 ResultSeven10265
  1582. if miConfig.Code == "H15049901371" {
  1583. if err := json.Unmarshal(userJSONBytes, &resSeven10265); err != nil {
  1584. utils.ErrorLog("解析失败:%v", err)
  1585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1586. return
  1587. }
  1588. Infcode, _ := strconv.ParseInt(resSeven10265.Infcode, 10, 64)
  1589. res.Infcode = Infcode
  1590. res.InfRefmsgid = resSeven10265.InfRefmsgid
  1591. res.RespondTime = resSeven10265.RespondTime
  1592. res.ErrMsg = resSeven10265.ErrMsg
  1593. res.Output = resSeven10265.Output
  1594. res.WarnMsg = resSeven10265.WarnMsg
  1595. res.Cainfo = resSeven10265.Cainfo
  1596. } else {
  1597. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1598. utils.ErrorLog("解析失败:%v", err)
  1599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1600. return
  1601. }
  1602. }
  1603. if res.Infcode != 0 {
  1604. errlog := &models.HisOrderError{
  1605. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1606. Ctime: time.Now().Unix(),
  1607. Mtime: time.Now().Unix(),
  1608. Number: chrg_bchno,
  1609. ErrMsg: res.ErrMsg,
  1610. Status: 1,
  1611. PatientId: patient_id,
  1612. RecordTime: time.Now().Unix(),
  1613. Stage: 6,
  1614. }
  1615. service.CreateErrMsgLog(errlog)
  1616. c.ServeSuccessJSON(map[string]interface{}{
  1617. "failed_code": -10,
  1618. "msg": res.ErrMsg,
  1619. })
  1620. return
  1621. } else {
  1622. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1623. order.OrderStatus = 1
  1624. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1625. order.SetlId = res.Output.Setlinfo.SetlID
  1626. order.PsnNo = res.Output.Setlinfo.PsnNo
  1627. order.PsnName = res.Output.Setlinfo.PsnName
  1628. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1629. order.Certno = res.Output.Setlinfo.Certno
  1630. order.Gend = res.Output.Setlinfo.Gend
  1631. order.Naty = res.Output.Setlinfo.Naty
  1632. order.Age = res.Output.Setlinfo.Age
  1633. order.Insutype = res.Output.Setlinfo.Insutype
  1634. order.PsnType = res.Output.Setlinfo.PsnType
  1635. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1636. order.SetlTime = res.Output.Setlinfo.SetlTime
  1637. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1638. if res.Output.Setlinfo.MedType == "140104" {
  1639. order.MedType = "14"
  1640. } else {
  1641. order.MedType = res.Output.Setlinfo.MedType
  1642. }
  1643. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1644. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1645. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1646. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1647. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1648. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1649. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  1650. order.HifpPay = res.Output.Setlinfo.HifpPay
  1651. order.HifesPay = res.Output.Setlinfo.HifesPay
  1652. order.HifobPay = res.Output.Setlinfo.HifobPay
  1653. order.MafPay = res.Output.Setlinfo.MafPay
  1654. order.OthPay = res.Output.Setlinfo.OthPay
  1655. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1656. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1657. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1658. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1659. order.AcctPay = res.Output.Setlinfo.AcctPay
  1660. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1661. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1662. order.Balc = res.Output.Setlinfo.Balc
  1663. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1664. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1665. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1666. order.ClrWay = res.Output.Setlinfo.ClrWay
  1667. order.Creator = order.Creator
  1668. order.Modify = roles.AdminUserId
  1669. order.RequestLog = src_resquest
  1670. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1671. detailStr := string(setlDetail)
  1672. order.SetlDetail = detailStr
  1673. //err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  1674. if record.OutHospitalStatus == 1 && order.ID > 0 {
  1675. err := service.UpDateOrder(order)
  1676. if err == nil {
  1677. c.ServeSuccessJSON(map[string]interface{}{
  1678. "msg": "预结算成功",
  1679. "order_way": 1,
  1680. })
  1681. } else {
  1682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1683. return
  1684. }
  1685. } else if record.OutHospitalStatus == 0 && order.ID == 0 {
  1686. c.ServeSuccessJSON(map[string]interface{}{
  1687. "msg": "预结算成功",
  1688. "order": order,
  1689. "order_way": 2,
  1690. })
  1691. }
  1692. }
  1693. }
  1694. func (c *ZHHisApiController) GetUploadInfo() {
  1695. id, _ := c.GetInt64("id")
  1696. record_time := c.GetString("record_time")
  1697. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  1698. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1699. admin_user_id, _ := c.GetInt64("admin_user_id")
  1700. timeLayout := "2006-01-02"
  1701. loc, _ := time.LoadLocation("Local")
  1702. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1703. if err != nil {
  1704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1705. return
  1706. }
  1707. recordDateTime := theTime.Unix()
  1708. adminUser := c.GetAdminUserInfo()
  1709. var prescriptions []*models.HisPrescription
  1710. data := make(map[string]interface{})
  1711. if settle_accounts_type == 1 { //日结
  1712. prescriptions, _ = service.GetZHHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1713. } else { //月结
  1714. start_time_str := c.GetString("start_time")
  1715. end_time_str := c.GetString("end_time")
  1716. timeLayout := "2006-01-02"
  1717. loc, _ := time.LoadLocation("Local")
  1718. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1719. if err != nil {
  1720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1721. return
  1722. }
  1723. recordStartTime := theStartTime.Unix()
  1724. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1725. if err != nil {
  1726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1727. return
  1728. }
  1729. recordEndTime := theEndTime.Unix()
  1730. prescriptions, _ = service.GetZHMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1731. }
  1732. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1733. record, _ := service.GetInHospitalRecord(in_hospital_id)
  1734. if record.ID == 0 {
  1735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1736. return
  1737. }
  1738. timestamp := time.Now().Unix()
  1739. tempTime := time.Unix(timestamp, 0)
  1740. timeFormat := tempTime.Format("20060102150405")
  1741. chrgBchno := rand.Intn(100000) + 10000
  1742. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(record.PatientId, 10)
  1743. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1744. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1745. department, _ := service.GetDepartMentDetail(record.Departments)
  1746. strconv.FormatInt(record.PatientId, 10)
  1747. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, record.Doctor)
  1748. //client := &http.Client{}
  1749. data["psn_no"] = record.PsnNo
  1750. data["mdtrt_id"] = record.Number
  1751. data["chrg_bchno"] = chrg_bchno
  1752. data["org_name"] = miConfig.OrgName
  1753. data["doctor"] = roles.UserName
  1754. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1755. data["dept"] = strconv.FormatInt(department.ID, 10)
  1756. data["fixmedins_code"] = miConfig.Code
  1757. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  1758. data["dept_code"] = "15"
  1759. } else {
  1760. data["dept_code"] = department.Number
  1761. }
  1762. if miConfig.Code == "H15049901371" {
  1763. if record.MedType == 14 {
  1764. if record.InsutypeType == "390" {
  1765. data["med_type"] = "9933"
  1766. } else if record.InsutypeType == "310" {
  1767. data["med_type"] = "990502"
  1768. }
  1769. } else if record.MedType == 11 {
  1770. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  1771. }
  1772. } else {
  1773. if record.MedType == 1112 {
  1774. data["med_type"] = strconv.FormatInt(11, 10)
  1775. } else {
  1776. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  1777. }
  1778. }
  1779. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  1780. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1781. data["secret_key"] = miConfig.SecretKey
  1782. var ids []int64
  1783. fmt.Println(data)
  1784. for _, item := range prescriptions {
  1785. ids = append(ids, item.ID)
  1786. }
  1787. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1788. if config.IsOpen == 1 { //对接了医保,走医保流程
  1789. var pagesize int = 100
  1790. var start int = 1
  1791. var stop int
  1792. var pagecount int
  1793. var curpage int
  1794. var isSuccess bool = true
  1795. var customs []*models.NewCustom
  1796. for _, item := range prescriptions {
  1797. tm := time.Unix(item.PreTime, 0)
  1798. if item.Type == 1 { //药品
  1799. for _, subItem := range item.HisDoctorAdviceInfo {
  1800. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 && subItem.BaseDrugLib.IsUser != 1 {
  1801. //var randNum int
  1802. //randNum = rand.Intn(10000) + 1000
  1803. cus := &models.NewCustom{
  1804. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  1805. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  1806. FeedetlSn: subItem.FeedetlSn,
  1807. Price: fmt.Sprintf("%.4f", subItem.Price),
  1808. MedListCodg: subItem.BaseDrugLib.MedicalInsuranceNumber,
  1809. HospApprFlag: subItem.BaseDrugLib.HospApprFlag,
  1810. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  1811. }
  1812. customs = append(customs, cus)
  1813. }
  1814. }
  1815. }
  1816. if item.Type == 2 { //项目
  1817. for _, subItem := range item.HisPrescriptionProject {
  1818. //var randNum int
  1819. //randNum = rand.Intn(10000) + 1000
  1820. if subItem.Type == 2 {
  1821. if len(subItem.HisProject.MedicalCode) > 0 {
  1822. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  1823. cus := &models.NewCustom{
  1824. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  1825. Cut: fmt.Sprintf("%.4f", cnt),
  1826. FeedetlSn: subItem.FeedetlSn,
  1827. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  1828. MedListCodg: subItem.HisProject.MedicalCode,
  1829. HospApprFlag: -1,
  1830. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  1831. }
  1832. customs = append(customs, cus)
  1833. }
  1834. } else if subItem.Type == 3 {
  1835. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 && subItem.GoodInfo.IsUser != 1 {
  1836. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  1837. cus := &models.NewCustom{
  1838. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  1839. Cut: fmt.Sprintf("%.4f", cnt),
  1840. FeedetlSn: subItem.FeedetlSn,
  1841. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  1842. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  1843. HospApprFlag: -1,
  1844. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  1845. }
  1846. customs = append(customs, cus)
  1847. }
  1848. }
  1849. }
  1850. }
  1851. }
  1852. //总页数,向上取整,注意除之前要先转换类型为float64
  1853. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  1854. var ress []*ResultFour
  1855. for curpage = 1; curpage <= pagecount; curpage++ {
  1856. if curpage == 1 {
  1857. start = 1
  1858. } else {
  1859. start = (curpage-1)*pagesize + 1
  1860. }
  1861. stop = curpage * pagesize
  1862. if stop > len(customs) {
  1863. stop = len(customs)
  1864. }
  1865. var result string
  1866. var requestLog string
  1867. if miConfig.MdtrtareaAdmvs == "150499" {
  1868. data := make(map[string]interface{})
  1869. if record.MedType == 14 {
  1870. if record.InsutypeType == "390" {
  1871. data["med_type"] = "9933"
  1872. } else if record.InsutypeType == "310" {
  1873. data["med_type"] = "990502"
  1874. }
  1875. } else if record.MedType == 11 {
  1876. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  1877. }
  1878. data["psn_no"] = record.PsnNo
  1879. data["number"] = record.Number
  1880. data["customs"] = customs[start-1 : stop]
  1881. data["chrg_bchno"] = chrg_bchno
  1882. data["dept"] = strconv.FormatInt(department.ID, 10)
  1883. data["dept_code"] = department.Number
  1884. data["doctor_code"] = strconv.FormatInt(doctor_info.ID, 10)
  1885. data["doctor_name"] = doctor_info.UserName
  1886. data["org_name"] = miConfig.OrgName
  1887. data["opertor"] = roles.UserName
  1888. data["fixmedins_code"] = miConfig.Code
  1889. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  1890. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1891. data["secret_key"] = miConfig.SecretKey
  1892. var req *http.Request
  1893. bytesData, _ := json.Marshal(data)
  1894. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2301", bytes.NewReader(bytesData))
  1895. client := &http.Client{}
  1896. resp, _ := client.Do(req)
  1897. defer resp.Body.Close()
  1898. body, ioErr := ioutil.ReadAll(resp.Body)
  1899. if ioErr != nil {
  1900. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1902. return
  1903. }
  1904. var respJSON map[string]interface{}
  1905. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1906. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1908. return
  1909. }
  1910. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1911. result_byte, _ := json.Marshal(respJSON)
  1912. result = string(result_byte)
  1913. } else {
  1914. 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))
  1915. saveLog(result, requestLog, "2301", "上传明细")
  1916. }
  1917. var dat map[string]interface{}
  1918. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1919. fmt.Println(dat)
  1920. } else {
  1921. fmt.Println(err)
  1922. }
  1923. userJSONBytes, _ := json.Marshal(dat)
  1924. var res ResultFour
  1925. var resFour10265 ResultFour10265
  1926. if miConfig.Code == "H15049901371" {
  1927. if err := json.Unmarshal(userJSONBytes, &resFour10265); err != nil {
  1928. utils.ErrorLog("解析失败:%v", err)
  1929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1930. return
  1931. }
  1932. res.WarnMsg = resFour10265.WarnMsg
  1933. res.Output = resFour10265.Output
  1934. res.ErrMsg = resFour10265.ErrMsg
  1935. res.RespondTime = resFour10265.RespondTime
  1936. res.InfRefmsgid = resFour10265.InfRefmsgid
  1937. Infcode, _ := strconv.ParseInt(resFour10265.Infcode, 10, 64)
  1938. res.Infcode = Infcode
  1939. } else {
  1940. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1941. utils.ErrorLog("解析失败:%v", err)
  1942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1943. return
  1944. }
  1945. }
  1946. if res.Infcode == 0 {
  1947. ress = append(ress, &res)
  1948. } else {
  1949. isSuccess = false
  1950. errlog := &models.HisOrderError{
  1951. UserOrgId: adminUser.CurrentOrgId,
  1952. Ctime: time.Now().Unix(),
  1953. Mtime: time.Now().Unix(),
  1954. Number: chrg_bchno,
  1955. ErrMsg: "",
  1956. Status: 1,
  1957. PatientId: id,
  1958. RecordTime: recordDateTime,
  1959. Stage: 4,
  1960. }
  1961. service.CreateErrMsgLog(errlog)
  1962. c.ServeSuccessJSON(map[string]interface{}{
  1963. "failed_code": -10,
  1964. "msg": "上传明细错误,请联系his厂商",
  1965. })
  1966. return
  1967. }
  1968. }
  1969. if isSuccess == true {
  1970. if settle_accounts_type == 1 {
  1971. for _, subItem := range ress {
  1972. for _, item := range subItem.Output.Result {
  1973. temp := strings.Split(item.FeedetlSn, "-")
  1974. var advice_id int64 = 0
  1975. var project_id int64 = 0
  1976. var types int64 = 0
  1977. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1978. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1979. if temp[1] == "1" {
  1980. advice_id = id
  1981. project_id = 0
  1982. } else if temp[1] == "2" {
  1983. advice_id = 0
  1984. project_id = id
  1985. }
  1986. info := &models.HisOrderInfo{
  1987. OrderNumber: record.Number,
  1988. FeedetlSn: item.FeedetlSn,
  1989. UploadDate: recordDateTime,
  1990. AdviceId: advice_id,
  1991. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1992. Cnt: item.Cnt,
  1993. Pric: float64(item.Pric),
  1994. PatientId: record.PatientId,
  1995. PricUplmtAmt: item.PricUplmtAmt,
  1996. SelfpayProp: item.SelfpayProp,
  1997. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1998. OverlmtAmt: item.OverlmtAmt,
  1999. PreselfpayAmt: item.PreselfpayAmt,
  2000. BasMednFlag: item.BasMednFlag,
  2001. MedChrgitmType: item.MedChrgitmType,
  2002. HiNegoDrugFlag: item.HiNegoDrugFlag,
  2003. Status: 1,
  2004. Memo: item.Memo,
  2005. Mtime: time.Now().Unix(),
  2006. InscpScpAmt: item.InscpScpAmt,
  2007. DrtReimFlag: item.DrtReimFlag,
  2008. Ctime: time.Now().Unix(),
  2009. ListSpItemFlag: item.ListSpItemFlag,
  2010. ChldMedcFlag: item.ChldMedcFlag,
  2011. LmtUsedFlag: item.LmtUsedFlag,
  2012. ChrgitmLv: item.ChrgitmLv,
  2013. UserOrgId: adminUser.CurrentOrgId,
  2014. HisPatientId: record.ID,
  2015. OrderId: 0,
  2016. ProjectId: project_id,
  2017. Type: types,
  2018. SettleType: settle_accounts_type,
  2019. }
  2020. service.CreateOrderInfo(info)
  2021. }
  2022. }
  2023. err := service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  2024. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  2025. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  2026. if err == nil {
  2027. c.ServeSuccessJSON(map[string]interface{}{
  2028. "msg": "上传费用明细成功",
  2029. })
  2030. return
  2031. } else {
  2032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2033. return
  2034. }
  2035. } else {
  2036. for _, subItem := range ress {
  2037. for _, item := range subItem.Output.Result {
  2038. temp := strings.Split(item.FeedetlSn, "-")
  2039. var advice_id int64 = 0
  2040. var project_id int64 = 0
  2041. var types int64 = 0
  2042. id, _ := strconv.ParseInt(temp[2], 10, 64)
  2043. types, _ = strconv.ParseInt(temp[1], 10, 64)
  2044. if temp[1] == "1" {
  2045. advice_id = id
  2046. project_id = 0
  2047. } else if temp[1] == "2" {
  2048. advice_id = 0
  2049. project_id = id
  2050. }
  2051. info := &models.HisOrderInfo{
  2052. OrderNumber: record.Number,
  2053. FeedetlSn: item.FeedetlSn,
  2054. UploadDate: time.Now().Unix(),
  2055. AdviceId: advice_id,
  2056. DetItemFeeSumamt: item.DetItemFeeSumamt,
  2057. Cnt: item.Cnt,
  2058. Pric: float64(item.Pric),
  2059. PatientId: record.PatientId,
  2060. PricUplmtAmt: item.PricUplmtAmt,
  2061. SelfpayProp: item.SelfpayProp,
  2062. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2063. OverlmtAmt: item.OverlmtAmt,
  2064. PreselfpayAmt: item.PreselfpayAmt,
  2065. BasMednFlag: item.BasMednFlag,
  2066. MedChrgitmType: item.MedChrgitmType,
  2067. HiNegoDrugFlag: item.HiNegoDrugFlag,
  2068. Status: 1,
  2069. Memo: item.Memo,
  2070. Mtime: time.Now().Unix(),
  2071. InscpScpAmt: item.InscpScpAmt,
  2072. DrtReimFlag: item.DrtReimFlag,
  2073. Ctime: time.Now().Unix(),
  2074. ListSpItemFlag: item.ListSpItemFlag,
  2075. ChldMedcFlag: item.ChldMedcFlag,
  2076. LmtUsedFlag: item.LmtUsedFlag,
  2077. ChrgitmLv: item.ChrgitmLv,
  2078. UserOrgId: adminUser.CurrentOrgId,
  2079. HisPatientId: record.ID,
  2080. ProjectId: project_id,
  2081. Type: types,
  2082. SettleType: settle_accounts_type,
  2083. }
  2084. service.CreateOrderInfo(info)
  2085. }
  2086. }
  2087. service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  2088. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  2089. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  2090. c.ServeSuccessJSON(map[string]interface{}{
  2091. "msg": "上传费用明细成功",
  2092. })
  2093. }
  2094. }
  2095. }
  2096. }
  2097. func (c *ZHHisApiController) ZHRefund() {
  2098. order_id, _ := c.GetInt64("order_id")
  2099. admin_user_id, _ := c.GetInt64("admin_user_id")
  2100. adminUser := c.GetAdminUserInfo()
  2101. var order models.HisOrder
  2102. order, _ = service.GetHisOrderByID(order_id)
  2103. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  2104. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2105. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2106. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2107. if config.IsOpen == 1 { //对接了医保,走医保流程
  2108. var result string
  2109. var requestLog string
  2110. if miConfig.MdtrtareaAdmvs == "150499" {
  2111. //请求内网数据
  2112. api := "http://172.16.13.254:9532/" + "nmyb/2305?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo + "&setl_id=" + order.SetlId +
  2113. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2114. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2115. resp, requestErr := http.Get(api)
  2116. if requestErr != nil {
  2117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2118. return
  2119. }
  2120. body, ioErr := ioutil.ReadAll(resp.Body)
  2121. if ioErr != nil {
  2122. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2124. return
  2125. }
  2126. var respJSON map[string]interface{}
  2127. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2128. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2130. return
  2131. }
  2132. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2133. result_byte, _ := json.Marshal(respJSON)
  2134. result = string(result_byte)
  2135. //saveLog(result, requestLog, "2404", "入院登记撤销")
  2136. saveLog(result, requestLog, "2305", "退费")
  2137. } else {
  2138. result, requestLog := service.Gdyb2305(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2139. saveLog(result, requestLog, "2305", "退费")
  2140. }
  2141. var dat map[string]interface{}
  2142. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2143. fmt.Println(dat)
  2144. } else {
  2145. fmt.Println(err)
  2146. }
  2147. userJSONBytes, _ := json.Marshal(dat)
  2148. var res ResultSixteen
  2149. var resSixteen ResultSixteen10265
  2150. if miConfig.Code == "H15049901371" {
  2151. if err := json.Unmarshal(userJSONBytes, &resSixteen); err != nil {
  2152. utils.ErrorLog("解析失败:%v", err)
  2153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2154. return
  2155. }
  2156. res.Cainfo = resSixteen.Cainfo
  2157. res.WarnMsg = resSixteen.WarnMsg
  2158. res.Output = resSixteen.Output
  2159. res.ErrMsg = resSixteen.ErrMsg
  2160. res.RespondTime = resSixteen.RespondTime
  2161. Infcode, _ := strconv.ParseInt(resSixteen.Infcode, 10, 64)
  2162. res.Infcode = Infcode
  2163. } else {
  2164. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2165. utils.ErrorLog("解析失败:%v", err)
  2166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2167. return
  2168. }
  2169. }
  2170. if res.Infcode == 0 {
  2171. err := service.UpdataOrderStatusThree(order_id, order.Number, adminUser.CurrentOrgId, "", result)
  2172. //不同地区退费流程不一样,肇庆那边退费就包括撤销出院,内蒙古退费不包括撤销明细,所以下面需要根据不同情况进行判断
  2173. if miConfig.UserOrgId == 10215 {
  2174. record.OutHospitalStatus = 0
  2175. service.CreateHospitalRecord(&record)
  2176. }
  2177. service.UpdataOrderStatusByNumber(record.Number)
  2178. if err == nil {
  2179. c.ServeSuccessJSON(map[string]interface{}{
  2180. "msg": "退费成功",
  2181. })
  2182. } else {
  2183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2184. return
  2185. }
  2186. } else {
  2187. c.ServeSuccessJSON(map[string]interface{}{
  2188. "code": -10,
  2189. "msg": res.ErrMsg,
  2190. })
  2191. }
  2192. } else {
  2193. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  2194. if err == nil {
  2195. c.ServeSuccessJSON(map[string]interface{}{
  2196. "msg": "退费成功",
  2197. })
  2198. } else {
  2199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2200. return
  2201. }
  2202. }
  2203. }
  2204. func (c *ZHHisApiController) ZHRefundDetail() {
  2205. patient_id, _ := c.GetInt64("patient_id")
  2206. his_patient_id, _ := c.GetInt64("his_patient_id")
  2207. record_time := c.GetString("record_time")
  2208. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2209. //order_id, _ := c.GetInt64("order_id")
  2210. admin_user_id, _ := c.GetInt64("admin_user_id")
  2211. timeLayout := "2006-01-02"
  2212. loc, _ := time.LoadLocation("Local")
  2213. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2214. if err != nil {
  2215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2216. return
  2217. }
  2218. recordDateTime := theTime.Unix()
  2219. adminUser := c.GetAdminUserInfo()
  2220. theTimeTwo, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 23:59:59", loc)
  2221. if err != nil {
  2222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2223. return
  2224. }
  2225. recordDateTimeTwo := theTimeTwo.Unix()
  2226. //var prescriptions []*models.HisPrescription
  2227. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2228. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2229. if settle_accounts_type == 1 { //日结
  2230. record, _ := service.GetInHospitalRecord(his_patient_id)
  2231. infos, _ := service.GetZHHisUploadOrderInfo(adminUser.CurrentOrgId, patient_id, recordDateTime, recordDateTimeTwo, record.Number)
  2232. var isSuccess bool = true
  2233. for _, item := range infos {
  2234. var result string
  2235. var requestLog string
  2236. if miConfig.MdtrtareaAdmvs == "150499" {
  2237. //请求内网数据
  2238. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&feedetl_sn=" + item.FeedetlSn +
  2239. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2240. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "1"
  2241. resp, requestErr := http.Get(api)
  2242. if requestErr != nil {
  2243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2244. return
  2245. }
  2246. body, ioErr := ioutil.ReadAll(resp.Body)
  2247. if ioErr != nil {
  2248. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2250. return
  2251. }
  2252. var respJSON map[string]interface{}
  2253. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2254. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2256. return
  2257. }
  2258. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2259. result_byte, _ := json.Marshal(respJSON)
  2260. result = string(result_byte)
  2261. saveLog(result, requestLog, "2302", "日结退明细")
  2262. } else {
  2263. result, requestLog := service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, item.FeedetlSn, 1)
  2264. saveLog(result, requestLog, "2302", "日结退明细")
  2265. }
  2266. var dat map[string]interface{}
  2267. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2268. fmt.Println(dat)
  2269. } else {
  2270. fmt.Println(err)
  2271. }
  2272. userJSONBytes, _ := json.Marshal(dat)
  2273. var res2 ResultEmpty
  2274. var resEmpty10265 ResultEmpty10265
  2275. if miConfig.Code == "H15049901371" {
  2276. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2277. utils.ErrorLog("解析失败:%v", err)
  2278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2279. return
  2280. }
  2281. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2282. res2.Infcode = Infcode
  2283. res2.RespondTime = resEmpty10265.RespondTime
  2284. res2.ErrMsg = resEmpty10265.ErrMsg
  2285. res2.Output = resEmpty10265.Output
  2286. res2.WarnMsg = resEmpty10265.WarnMsg
  2287. } else {
  2288. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2289. utils.ErrorLog("解析失败:%v", err)
  2290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2291. return
  2292. }
  2293. }
  2294. if res2.Infcode == -1 {
  2295. isSuccess = false
  2296. }
  2297. }
  2298. if isSuccess {
  2299. err := service.UpDateOrderInfoStatus(patient_id, recordDateTime, adminUser.CurrentOrgId, recordDateTimeTwo)
  2300. if err != nil {
  2301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2302. return
  2303. }
  2304. err1 := service.UpDatePrescriptionOrderStatusTwo(patient_id, recordDateTime, adminUser.CurrentOrgId)
  2305. if err1 != nil {
  2306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2307. return
  2308. }
  2309. c.ServeSuccessJSON(map[string]interface{}{
  2310. "msg": "撤销明细成功",
  2311. })
  2312. }
  2313. } else {
  2314. //prescriptions, _ = service.GetZHMonthHisUploadPrescription(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2315. //var order models.HisOrder
  2316. //order, _ = service.GetHisOrderByID(order_id)
  2317. //record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  2318. var result string
  2319. var requestLog string
  2320. record, _ := service.GetInHospitalRecord(his_patient_id)
  2321. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2322. if config.IsOpen == 1 { //对接了医保,走医保流程
  2323. if miConfig.MdtrtareaAdmvs == "150499" {
  2324. //请求内网数据
  2325. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=0000" +
  2326. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2327. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "1"
  2328. resp, requestErr := http.Get(api)
  2329. if requestErr != nil {
  2330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2331. return
  2332. }
  2333. body, ioErr := ioutil.ReadAll(resp.Body)
  2334. if ioErr != nil {
  2335. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2336. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2337. return
  2338. }
  2339. var respJSON map[string]interface{}
  2340. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2341. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2343. return
  2344. }
  2345. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2346. result_byte, _ := json.Marshal(respJSON)
  2347. result = string(result_byte)
  2348. //saveLog(result, requestLog, "2302", "日结退明细")
  2349. } else {
  2350. result, requestLog = service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  2351. saveLog(result, requestLog, "2302", "月结退明细")
  2352. }
  2353. var dat map[string]interface{}
  2354. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2355. fmt.Println(dat)
  2356. } else {
  2357. fmt.Println(err)
  2358. }
  2359. userJSONBytes, _ := json.Marshal(dat)
  2360. var res2 ResultEmpty
  2361. var resEmpty10265 ResultEmpty10265
  2362. if miConfig.Code == "H15049901371" {
  2363. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2364. utils.ErrorLog("解析失败:%v", err)
  2365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2366. return
  2367. }
  2368. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2369. res2.Infcode = Infcode
  2370. res2.RespondTime = resEmpty10265.RespondTime
  2371. res2.ErrMsg = resEmpty10265.ErrMsg
  2372. res2.Output = resEmpty10265.Output
  2373. res2.WarnMsg = resEmpty10265.WarnMsg
  2374. } else {
  2375. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2376. utils.ErrorLog("解析失败:%v", err)
  2377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2378. return
  2379. }
  2380. }
  2381. if res2.Infcode == 0 {
  2382. err := service.UpdataHospitalOrderStatus(record.Number, adminUser.CurrentOrgId)
  2383. if err == nil {
  2384. c.ServeSuccessJSON(map[string]interface{}{
  2385. "msg": "撤销明细成功",
  2386. })
  2387. } else {
  2388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2389. return
  2390. }
  2391. } else {
  2392. c.ServeSuccessJSON(map[string]interface{}{
  2393. "code": -10,
  2394. "msg": res2.ErrMsg,
  2395. })
  2396. }
  2397. }
  2398. }
  2399. }
  2400. func (this *ZHHisApiController) GetZHOutHospitalUnCheck() {
  2401. id, _ := this.GetInt64("id")
  2402. admin_user_id, _ := this.GetInt64("admin_user_id")
  2403. adminInfo := this.GetAdminUserInfo()
  2404. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2405. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  2406. record, _ := service.GetInHospitalRecord(id)
  2407. if record.ID == 0 {
  2408. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  2409. return
  2410. }
  2411. var result string
  2412. var requestLog string
  2413. if miConfig.MdtrtareaAdmvs == "150499" {
  2414. //请求内网数据
  2415. api := "http://172.16.13.254:9532/" + "nmyb/2405?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  2416. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  2417. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2418. fmt.Println(api)
  2419. resp, requestErr := http.Get(api)
  2420. if requestErr != nil {
  2421. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2422. return
  2423. }
  2424. body, ioErr := ioutil.ReadAll(resp.Body)
  2425. if ioErr != nil {
  2426. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2427. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2428. return
  2429. }
  2430. var respJSON map[string]interface{}
  2431. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2432. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2433. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2434. return
  2435. }
  2436. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2437. result_byte, _ := json.Marshal(respJSON)
  2438. result = string(result_byte)
  2439. } else {
  2440. result, requestLog = service.ZHGdyb2405(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2441. saveLog(result, requestLog, "2405", "出院登记撤销")
  2442. }
  2443. var dat map[string]interface{}
  2444. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2445. fmt.Println(dat)
  2446. } else {
  2447. fmt.Println(err)
  2448. }
  2449. userJSONBytes, _ := json.Marshal(dat)
  2450. var res ResultEmpty
  2451. var resEmpty10265 ResultEmpty10265
  2452. if miConfig.Code == "H15049901371" {
  2453. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2454. utils.ErrorLog("解析失败:%v", err)
  2455. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2456. return
  2457. }
  2458. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2459. res.Infcode = Infcode
  2460. res.RespondTime = resEmpty10265.RespondTime
  2461. res.ErrMsg = resEmpty10265.ErrMsg
  2462. res.Output = resEmpty10265.Output
  2463. res.WarnMsg = resEmpty10265.WarnMsg
  2464. } else {
  2465. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2466. utils.ErrorLog("解析失败:%v", err)
  2467. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2468. return
  2469. }
  2470. }
  2471. if res.Infcode == 0 {
  2472. record.OutHospitalStatus = 0
  2473. service.CreateHospitalRecord(&record)
  2474. service.UpdataOrderStatusByNumber(record.Number)
  2475. this.ServeSuccessJSON(map[string]interface{}{
  2476. "msg": "撤销出院成功",
  2477. })
  2478. } else {
  2479. this.ServeSuccessJSON(map[string]interface{}{
  2480. "failed_code": -10,
  2481. "msg": res.ErrMsg,
  2482. })
  2483. }
  2484. }
  2485. func (this *ZHHisApiController) GetZHInHospitalUnCheck() {
  2486. id, _ := this.GetInt64("id")
  2487. admin_user_id, _ := this.GetInt64("admin_user_id")
  2488. adminInfo := this.GetAdminUserInfo()
  2489. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2490. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  2491. record, _ := service.GetInHospitalRecord(id)
  2492. if record.ID == 0 {
  2493. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  2494. return
  2495. }
  2496. var result string
  2497. var requestLog string
  2498. if miConfig.MdtrtareaAdmvs == "150499" {
  2499. //请求内网数据
  2500. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=" + "0000" +
  2501. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  2502. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=0"
  2503. resp, requestErr := http.Get(api)
  2504. if requestErr != nil {
  2505. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2506. return
  2507. }
  2508. body, ioErr := ioutil.ReadAll(resp.Body)
  2509. if ioErr != nil {
  2510. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2511. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2512. return
  2513. }
  2514. var respJSON map[string]interface{}
  2515. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2516. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2517. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2518. return
  2519. }
  2520. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2521. result_byte, _ := json.Marshal(respJSON)
  2522. result = string(result_byte)
  2523. saveLog(result, requestLog, "2302", "月结退明细")
  2524. } else {
  2525. result, requestLog = service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  2526. saveLog(result, requestLog, "2302", "月结退明细")
  2527. }
  2528. var dat map[string]interface{}
  2529. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2530. fmt.Println(dat)
  2531. } else {
  2532. fmt.Println(err)
  2533. }
  2534. userJSONBytes, _ := json.Marshal(dat)
  2535. var res2 ResultEmpty
  2536. var resEmpty10265 ResultEmpty10265
  2537. if miConfig.Code == "H15049901371" {
  2538. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2539. utils.ErrorLog("解析失败:%v", err)
  2540. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2541. return
  2542. }
  2543. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2544. res2.Infcode = Infcode
  2545. res2.RespondTime = resEmpty10265.RespondTime
  2546. res2.ErrMsg = resEmpty10265.ErrMsg
  2547. res2.Output = resEmpty10265.Output
  2548. res2.WarnMsg = resEmpty10265.WarnMsg
  2549. } else {
  2550. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2551. utils.ErrorLog("解析失败:%v", err)
  2552. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2553. return
  2554. }
  2555. }
  2556. if res2.Infcode == 0 {
  2557. service.UpdataHospitalOrderStatus(record.Number, adminInfo.CurrentOrgId)
  2558. var result string
  2559. var requestLog string
  2560. if miConfig.MdtrtareaAdmvs == "150499" {
  2561. //请求内网数据
  2562. api := "http://172.16.13.254:9532/" + "nmyb/2404?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  2563. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  2564. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2565. resp, requestErr := http.Get(api)
  2566. if requestErr != nil {
  2567. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2568. return
  2569. }
  2570. body, ioErr := ioutil.ReadAll(resp.Body)
  2571. if ioErr != nil {
  2572. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2573. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2574. return
  2575. }
  2576. var respJSON map[string]interface{}
  2577. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2578. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2579. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2580. return
  2581. }
  2582. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2583. result_byte, _ := json.Marshal(respJSON)
  2584. result = string(result_byte)
  2585. } else {
  2586. result, requestLog = service.ZHGdyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2587. saveLog(result, requestLog, "2404", "入院登记撤销")
  2588. }
  2589. var dat map[string]interface{}
  2590. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2591. fmt.Println(dat)
  2592. } else {
  2593. fmt.Println(err)
  2594. }
  2595. userJSONBytes, _ := json.Marshal(dat)
  2596. var res ResultEmpty
  2597. var resEmpty10265 ResultEmpty10265
  2598. if miConfig.Code == "H15049901371" {
  2599. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2600. utils.ErrorLog("解析失败:%v", err)
  2601. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2602. return
  2603. }
  2604. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2605. res.Infcode = Infcode
  2606. res.RespondTime = resEmpty10265.RespondTime
  2607. res.ErrMsg = resEmpty10265.ErrMsg
  2608. res.Output = resEmpty10265.Output
  2609. res.WarnMsg = resEmpty10265.WarnMsg
  2610. } else {
  2611. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2612. utils.ErrorLog("解析失败:%v", err)
  2613. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2614. return
  2615. }
  2616. }
  2617. if res.Infcode == 0 {
  2618. record.Status = 0
  2619. service.CreateHospitalRecord(&record)
  2620. this.ServeSuccessJSON(map[string]interface{}{
  2621. "msg": "撤销入院成功",
  2622. })
  2623. } else {
  2624. this.ServeSuccessJSON(map[string]interface{}{
  2625. "failed_code": -10,
  2626. "msg": res.ErrMsg,
  2627. })
  2628. }
  2629. } else {
  2630. this.ServeSuccessJSON(map[string]interface{}{
  2631. "code": -10,
  2632. "msg": res2.ErrMsg,
  2633. })
  2634. }
  2635. }
  2636. func saveLog(result string, request string, infno string, desc string) {
  2637. org_id, _ := beego.AppConfig.Int64("org_id")
  2638. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  2639. dir := miConfig.OrgName + "日志"
  2640. utils.Mkdir(dir)
  2641. month := time.Unix(1557042972, 0).Format("1")
  2642. year := time.Now().Format("2006")
  2643. month = time.Now().Format("01")
  2644. day := time.Now().Format("02")
  2645. hour := time.Now().Format("15")
  2646. min := time.Now().Format("04")
  2647. sec := time.Now().Format("05")
  2648. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  2649. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  2650. file_name := file + ".txt"
  2651. file_path := miConfig.OrgName + "日志" + "/" + file_name
  2652. exist, _ := utils.PathExists(file_path)
  2653. if exist { //存在
  2654. fmt.Println("存在")
  2655. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  2656. if err != nil {
  2657. fmt.Println("read fail")
  2658. }
  2659. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  2660. n, _ := f.Seek(0, 2)
  2661. _, err = f.WriteAt([]byte(content), n)
  2662. } else { //不存在
  2663. fmt.Println("文件不存在,创建文件")
  2664. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  2665. defer f.Close()
  2666. if err != nil {
  2667. } else {
  2668. _, err = f.Write([]byte("记录日志"))
  2669. }
  2670. }
  2671. }
  2672. type Charset string
  2673. const (
  2674. UTF8 = Charset("UTF-8")
  2675. GB18030 = Charset("GB18030")
  2676. )
  2677. func ConvertToString(src string, srcCode string, tagCode string) string {
  2678. srcCoder := mahonia.NewDecoder(srcCode)
  2679. srcResult := srcCoder.ConvertString(src)
  2680. tagCoder := mahonia.NewDecoder(tagCode)
  2681. _, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
  2682. result := string(cdata)
  2683. return result
  2684. }
  2685. type ELeData struct {
  2686. Data struct {
  2687. IdNo string `json:"idNo"`
  2688. IdType string `json:"idType"`
  2689. UserName string `json:"userName"`
  2690. EcToken string `json:"ecToken"`
  2691. InsuOrg string `json:"insuOrg"`
  2692. Gender string `json:"gender"`
  2693. Birthday string `json:"birthday"`
  2694. Nationality string `json:"nationality"`
  2695. Email string `json:"email"`
  2696. Extra string `json:"extra"`
  2697. } `json:"data"`
  2698. Code int `json:"code"`
  2699. Message string `json:"message"`
  2700. }
  2701. func (c *ZHHisApiController) ReadCard() {
  2702. id_card_type, _ := c.GetInt64("id_card_type")
  2703. admin_user_id, _ := c.GetInt64("admin_user_id")
  2704. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  2705. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  2706. var api string
  2707. api = "http://172.16.13.254:9532/" + "nmyb/readcard?" + "fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName +
  2708. "&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
  2709. fmt.Println(api)
  2710. resp, requestErr := http.Get(api)
  2711. if requestErr != nil {
  2712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2713. return
  2714. }
  2715. body, ioErr := ioutil.ReadAll(resp.Body)
  2716. if ioErr != nil {
  2717. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2719. return
  2720. }
  2721. var respJSON map[string]interface{}
  2722. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2723. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2725. return
  2726. }
  2727. var status string
  2728. status = respJSON["data"].(map[string]interface{})["status"].(string)
  2729. card_type := respJSON["data"].(map[string]interface{})["type"].(string)
  2730. //console.log()
  2731. fmt.Println("type===")
  2732. fmt.Println(card_type)
  2733. var token string
  2734. var res ResultTwo //1101结果
  2735. var res10265 ResultTwo10265 //1101结果
  2736. var card_info string //卡信息
  2737. var busi_card_info string
  2738. card_info = respJSON["data"].(map[string]interface{})["card_info"].(string)
  2739. busi_card_info = respJSON["data"].(map[string]interface{})["busi_card_info"].(string)
  2740. if status == "0" { //读卡成功
  2741. if card_type == "1" {
  2742. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  2743. result, _ := json.Marshal(respJSON)
  2744. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  2745. utils.ErrorLog("解析失败:%v", err)
  2746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2747. return
  2748. }
  2749. res.ErrMsg = res10265.ErrMsg
  2750. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  2751. res.Infcode = infocode
  2752. res.Output = res10265.Output
  2753. res.InfRefmsgid = res10265.InfRefmsgid
  2754. } else {
  2755. //var card_info string //卡信息
  2756. //var busi_card_info string
  2757. token = respJSON["data"].(map[string]interface{})["token"].(string)
  2758. //busi_card_info = respJSON["data"].(map[string]interface{})["busi_card_info"].(string)
  2759. //fmt.Println(card_info)
  2760. //fmt.Println(busi_card_info)
  2761. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  2762. result, _ := json.Marshal(respJSON)
  2763. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  2764. utils.ErrorLog("解析失败:%v", err)
  2765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2766. return
  2767. }
  2768. res.ErrMsg = res10265.ErrMsg
  2769. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  2770. res.Infcode = infocode
  2771. res.Output = res10265.Output
  2772. res.InfRefmsgid = res10265.InfRefmsgid
  2773. }
  2774. if res.Infcode == 0 {
  2775. var insutypes []string
  2776. var insutype string
  2777. var is390 int = 0
  2778. var is310 int = 0
  2779. for _, item := range res.Output.Iinfo {
  2780. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  2781. insutypes = append(insutypes, item.Insutype)
  2782. }
  2783. }
  2784. if len(insutypes) == 1 {
  2785. insutype = insutypes[0]
  2786. } else {
  2787. for _, i := range insutypes {
  2788. if i == "390" {
  2789. is390 = 1
  2790. }
  2791. if i == "310" {
  2792. is310 = 1
  2793. }
  2794. }
  2795. }
  2796. if is390 == 1 {
  2797. insutype = "390"
  2798. }
  2799. if is310 == 1 {
  2800. insutype = "310"
  2801. }
  2802. if len(insutypes) == 0 {
  2803. insutype = "310"
  2804. }
  2805. patient, err := service.GetPatientByIDCard(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  2806. if err == gorm.ErrRecordNotFound {
  2807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  2808. return
  2809. } else if err != nil {
  2810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2811. return
  2812. } else {
  2813. if card_type == "1" {
  2814. bas := strings.Split(card_info, "|")
  2815. basNumber := bas[2]
  2816. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  2817. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  2818. infoStr := string(Iinfos)
  2819. idetinfoStr := string(Idetinfos)
  2820. psn := &models.HisPsn{
  2821. PsnNo: res.Output.Baseinfo.PsnNo,
  2822. Age: res.Output.Baseinfo.Age,
  2823. PatientId: patient.ID,
  2824. Certno: res.Output.Baseinfo.Certno,
  2825. Brdy: res.Output.Baseinfo.Brdy,
  2826. Gend: res.Output.Baseinfo.Gend,
  2827. Naty: res.Output.Baseinfo.Naty,
  2828. PsnCertType: res.Output.Baseinfo.PsnCertType,
  2829. PsnName: res.Output.Baseinfo.PsnName,
  2830. Idetinfo: idetinfoStr,
  2831. Insuinfo: infoStr,
  2832. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2833. CardInfo: card_info,
  2834. VerifyNumber: busi_card_info,
  2835. }
  2836. service.CreateHisPsn(psn)
  2837. c.ServeSuccessJSON(map[string]interface{}{
  2838. "patient": patient,
  2839. "number": basNumber,
  2840. "info": res,
  2841. "insutype": insutype,
  2842. })
  2843. } else {
  2844. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  2845. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  2846. infoStr := string(Iinfos)
  2847. idetinfoStr := string(Idetinfos)
  2848. psn := &models.HisPsn{
  2849. PsnNo: res.Output.Baseinfo.PsnNo,
  2850. Age: res.Output.Baseinfo.Age,
  2851. PatientId: patient.ID,
  2852. Certno: res.Output.Baseinfo.Certno,
  2853. Brdy: res.Output.Baseinfo.Brdy,
  2854. Gend: res.Output.Baseinfo.Gend,
  2855. Naty: res.Output.Baseinfo.Naty,
  2856. PsnCertType: res.Output.Baseinfo.PsnCertType,
  2857. PsnName: res.Output.Baseinfo.PsnName,
  2858. Idetinfo: idetinfoStr,
  2859. Insuinfo: infoStr,
  2860. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2861. CardInfo: card_info,
  2862. VerifyNumber: token,
  2863. }
  2864. service.CreateHisPsn(psn)
  2865. c.ServeSuccessJSON(map[string]interface{}{
  2866. "patient": patient,
  2867. "number": token,
  2868. "info": res,
  2869. "insutype": insutype,
  2870. })
  2871. }
  2872. }
  2873. } else {
  2874. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  2875. return
  2876. }
  2877. } else { //读卡失败
  2878. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  2879. return
  2880. }
  2881. }
  2882. var initFlag int64 = 0
  2883. func (c *ZHHisApiController) TestGetBasBaseInit() {
  2884. DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
  2885. Iinit := DllDef.MustFindProc("Init")
  2886. //miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  2887. str := make([]byte, 2048)
  2888. inputData := make(map[string]interface{})
  2889. inputData["IP"] = "10.144.211.75"
  2890. inputData["PORT"] = 7021
  2891. inputData["TIMEOUT"] = 180
  2892. inputData["LOG_PATH"] = "C:\\log\\"
  2893. //inputData["SFZ_DRIVER_TYPE"] = 0
  2894. inputData["URL"] = "/call1"
  2895. bytesData, _ := json.Marshal(inputData)
  2896. fmt.Println(inputData)
  2897. fmt.Println(bytesData)
  2898. ret, _, err := Iinit.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&str[0])))
  2899. if ret != 0 {
  2900. fmt.Println("SSCard的报错原因:", err)
  2901. fmt.Println("SSCard的运算结果为:", ret)
  2902. fmt.Println("SSCard的返回结果为:", string(str))
  2903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  2904. return
  2905. }
  2906. fmt.Println("SSCard的返回结果为:", string(str))
  2907. result := int(ret)
  2908. fmt.Println("SSCard的运算结果为1:", result)
  2909. //initFlag = 1
  2910. return
  2911. }
  2912. func (c *ZHHisApiController) GetSFZBaseInfo() string {
  2913. DllDef := syscall.MustLoadDLL("SSCard.dll")
  2914. readCard := DllDef.MustFindProc("ReadSFZ")
  2915. if readCard == nil {
  2916. fmt.Println("readcard is nil")
  2917. readCard = DllDef.MustFindProc("ReadSFZ")
  2918. }
  2919. str := make([]byte, 256)
  2920. str1 := make([]byte, 256)
  2921. r, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  2922. fmt.Println(r)
  2923. return string(str)
  2924. }
  2925. func (c *ZHHisApiController) GetBasBaseInfo(fixmedins_code string, mdtrtarea_admvs string, opter_name string, opter_id string, fixmedins_name string) string {
  2926. DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
  2927. readCard := DllDef.MustFindProc("ReadCardBas")
  2928. fmt.Println(readCard)
  2929. fmt.Println("!!!!!")
  2930. month := time.Unix(1557042972, 0).Format("1")
  2931. year := time.Now().Format("2006")
  2932. month = time.Now().Format("01")
  2933. day := time.Now().Format("02")
  2934. hour := time.Now().Format("15")
  2935. min := time.Now().Format("04")
  2936. sec := time.Now().Format("05")
  2937. msec := time.Now().Format("000")
  2938. timestamp := time.Now().Unix()
  2939. tempTime := time.Unix(timestamp, 0)
  2940. //timeFormat := tempTime.Format("20060102150405")
  2941. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  2942. //randNum := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000)
  2943. inputData := make(map[string]interface{})
  2944. inputData["infno"] = "1199"
  2945. //inputData["msgid"] = "7021"
  2946. inputData["msgid"] = fixmedins_code + year + month + day + hour + min + sec + msec + "0" // 发送方报文 ID
  2947. inputData["mdtrtarea_admvs"] = mdtrtarea_admvs // 发送方报文 ID
  2948. inputData["recer_sys_code"] = "01"
  2949. inputData["infver"] = "V1.0"
  2950. inputData["opter_type"] = "1"
  2951. inputData["opter"] = opter_id
  2952. inputData["opter_name"] = opter_name
  2953. inputData["inf_time"] = timeFormatOne
  2954. inputData["fixmedins_code"] = fixmedins_code
  2955. inputData["fixmedins_name"] = fixmedins_name
  2956. inputData["dev_no"] = ""
  2957. inputData["dev_safe_info"] = ""
  2958. inputData["cainfo"] = ""
  2959. inputData["signtype"] = ""
  2960. inputData["sign_no"] = ""
  2961. bytesData, _ := json.Marshal(inputData)
  2962. fmt.Println(string(bytesData))
  2963. pBusiCardInfo := make([]byte, 8192)
  2964. ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
  2965. fmt.Println(ret2)
  2966. fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
  2967. fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
  2968. if ret2 != 0 {
  2969. return ""
  2970. }
  2971. return DeleteExtraSpace(string(pBusiCardInfo))
  2972. }
  2973. func DeleteExtraSpace(s string) string {
  2974. //删除字符串中的多余空格,有多个空格时,仅保留一个空格
  2975. s1 := strings.Replace(s, " ", " ", -1) //替换tab为空格
  2976. regstr := "\\s{2,}" //两个及两个以上空格的正则表达式
  2977. reg, _ := regexp.Compile(regstr) //编译正则表达式
  2978. s2 := make([]byte, len(s1)) //定义字符数组切片
  2979. copy(s2, s1) //将字符串复制到切片
  2980. spc_index := reg.FindStringIndex(string(s2)) //在字符串中搜索
  2981. for len(spc_index) > 0 { //找到适配项
  2982. s2 = append(s2[:spc_index[0]+1], s2[spc_index[1]:]...) //删除多余空格
  2983. spc_index = reg.FindStringIndex(string(s2)) //继续在字符串中搜索
  2984. }
  2985. return string(s2)
  2986. }
  2987. func (c *ZHHisApiController) GetELeInfo(code string, operator_id string, operator_name string) (string, string) {
  2988. DllDef := syscall.MustLoadDLL("NationECCode.dll")
  2989. readCard := DllDef.MustFindProc("NationEcTrans")
  2990. fmt.Println(readCard)
  2991. fmt.Println("!!!!!")
  2992. pBusiCardInfo := make([]byte, 8192)
  2993. input := make(map[string]interface{})
  2994. inputData := make(map[string]interface{})
  2995. inputData["orgId"] = code
  2996. inputData["businessType"] = "01101"
  2997. inputData["operatorId"] = operator_id
  2998. inputData["operatorName"] = operator_name
  2999. inputData["officeId"] = "001"
  3000. inputData["officeName"] = "血透室"
  3001. inputData["deviceType"] = ""
  3002. input["data"] = inputData
  3003. input["orgId"] = code
  3004. input["transType"] = "ec.query"
  3005. bytesData, _ := json.Marshal(input)
  3006. gdyb_url := beego.AppConfig.String("gdyb_url")
  3007. url := gdyb_url + "/localcfc/api/hsecfc/localQrCodeQuery"
  3008. ret2, _, _ := readCard.Call(StrPtr(url), StrPtr(string(bytesData)), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
  3009. fmt.Println(ret2)
  3010. fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
  3011. fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
  3012. if ret2 != 0 {
  3013. return "", ""
  3014. }
  3015. return DeleteExtraSpace(""), DeleteExtraSpace(string(pBusiCardInfo))
  3016. }
  3017. func StrPtr(s string) uintptr {
  3018. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  3019. }
  3020. func Remove0000(s string) string {
  3021. str := make([]rune, 0, len(s))
  3022. for _, v := range []rune(s) {
  3023. if v == 0 {
  3024. continue
  3025. }
  3026. str = append(str, v)
  3027. }
  3028. return string(str)
  3029. }
  3030. func IntPtr(n int) uintptr {
  3031. return uintptr(n)
  3032. }