zh_his_api_controller.go 110KB

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