zh_his_api_controller.go 115KB

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