zh_his_api_controller.go 114KB

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