zh_his_api_controller.go 115KB

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