zh_his_api_controller.go 151KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465
  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. beego.Router("/zh/api/readelecard", &ZHHisApiController{}, "get:ReadEleCard")
  483. //beego.Router("/zh/api/readelecard", &ZHHisApiController{}, "get:ReadEleCard")
  484. beego.Router("/zh/api/lingbao/upload", &ZHHisApiController{}, "get:UploadLingBao")
  485. beego.Router("/zh/api/lingbao/refund", &ZHHisApiController{}, "get:RefundLingBao")
  486. beego.Router("/zh/api/lingbao/get", &ZHHisApiController{}, "get:GetLingBao")
  487. beego.Router("/api/token/get", &ZHHisApiController{}, "post:GetToken")
  488. beego.Router("/api/ele/info", &ZHHisApiController{}, "post:GetEleInfo")
  489. }
  490. func (c *ZHHisApiController) GetEleInfo() {
  491. body, _ := ioutil.ReadAll(c.Ctx.Request.Body)
  492. var respJSON map[string]interface{}
  493. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  494. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  495. return
  496. }
  497. token := respJSON["token"].(string)
  498. result_respJson := respJSON["result"].(string)
  499. fmt.Println("token")
  500. fmt.Println(token)
  501. fmt.Println("result")
  502. fmt.Println(result_respJson)
  503. c.ServeSuccessJSON(map[string]interface{}{
  504. "msg": "读卡成功",
  505. })
  506. }
  507. func (c *ZHHisApiController) GetToken() {
  508. body, _ := ioutil.ReadAll(c.Ctx.Request.Body)
  509. var respJSON map[string]interface{}
  510. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  511. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  512. return
  513. }
  514. token := respJSON["token"].(string)
  515. result_respJson := respJSON["result"].(string)
  516. fmt.Println("token")
  517. fmt.Println(token)
  518. fmt.Println("result")
  519. fmt.Println(result_respJson)
  520. var res ELeData
  521. result, _ := json.Marshal(result_respJson)
  522. if err := json.Unmarshal([]byte(result), &res); err != nil {
  523. utils.ErrorLog("解析失败:%v", err)
  524. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  525. return
  526. }
  527. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  528. patient, _ := service.GetPatientByIDCard(res.Data.IdNo, c.GetAdminUserInfo().CurrentOrgId)
  529. var api string
  530. api = "http://172.16.13.254:9532/" + "api/eleinfo?" + "fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&org_name=" + miConfig.OrgName +
  531. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&url=" + miConfig.Url + "&cainfo=" + miConfig.Cainfo + "&token=" + token + "&user_name=" + patient.Name + "&id_card_no=" + patient.IdCardNo
  532. resp, requestErr := http.Get(api)
  533. if requestErr != nil {
  534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  535. return
  536. }
  537. body, ioErr := ioutil.ReadAll(resp.Body)
  538. if ioErr != nil {
  539. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  541. return
  542. }
  543. //var respJSON map[string]interface{}
  544. //if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  545. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  546. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  547. // return
  548. //}
  549. c.ServeSuccessJSON(map[string]interface{}{
  550. "msg": "读卡成功",
  551. })
  552. }
  553. func (c *ZHHisApiController) UploadLingBao() {
  554. id, _ := c.GetInt64("id")
  555. record_time := c.GetString("record_time")
  556. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  557. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  558. admin_user_id, _ := c.GetInt64("admin_user_id")
  559. timeLayout := "2006-01-02"
  560. loc, _ := time.LoadLocation("Local")
  561. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  562. if err != nil {
  563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  564. return
  565. }
  566. recordDateTime := theTime.Unix()
  567. adminUser := c.GetAdminUserInfo()
  568. var prescriptions []*models.HisPrescription
  569. data := make(map[string]interface{})
  570. if settle_accounts_type == 1 { //日结
  571. prescriptions, _ = service.GetZHHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  572. } else { //月结
  573. start_time_str := c.GetString("start_time")
  574. end_time_str := c.GetString("end_time")
  575. timeLayout := "2006-01-02"
  576. loc, _ := time.LoadLocation("Local")
  577. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  578. if err != nil {
  579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  580. return
  581. }
  582. recordStartTime := theStartTime.Unix()
  583. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  584. if err != nil {
  585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  586. return
  587. }
  588. recordEndTime := theEndTime.Unix()
  589. prescriptions, _ = service.GetZHMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  590. }
  591. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  592. record, _ := service.GetInHospitalRecord(in_hospital_id)
  593. if record.ID == 0 {
  594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  595. return
  596. }
  597. timestamp := time.Now().Unix()
  598. tempTime := time.Unix(timestamp, 0)
  599. timeFormat := tempTime.Format("20060102150405")
  600. chrgBchno := rand.Intn(100000) + 10000
  601. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(record.PatientId, 10)
  602. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  603. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  604. department, _ := service.GetDepartMentDetail(record.Departments)
  605. strconv.FormatInt(record.PatientId, 10)
  606. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, record.Doctor)
  607. //client := &http.Client{}
  608. data["psn_no"] = record.PsnNo
  609. data["mdtrt_id"] = record.Number
  610. data["chrg_bchno"] = chrg_bchno
  611. data["org_name"] = miConfig.OrgName
  612. data["doctor"] = roles.UserName
  613. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  614. data["dept"] = strconv.FormatInt(department.ID, 10)
  615. data["fixmedins_code"] = miConfig.Code
  616. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  617. data["dept_code"] = "15"
  618. } else {
  619. data["dept_code"] = department.Number
  620. }
  621. if miConfig.Code == "H15049901371" {
  622. if record.MedType == 14 {
  623. if record.InsutypeType == "390" {
  624. data["med_type"] = "9933"
  625. } else if record.InsutypeType == "310" {
  626. data["med_type"] = "990502"
  627. }
  628. } else if record.MedType == 11 {
  629. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  630. }
  631. } else {
  632. if record.MedType == 1112 {
  633. data["med_type"] = strconv.FormatInt(11, 10)
  634. } else {
  635. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  636. }
  637. }
  638. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  639. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  640. data["secret_key"] = miConfig.SecretKey
  641. var ids []int64
  642. fmt.Println(data)
  643. for _, item := range prescriptions {
  644. ids = append(ids, item.ID)
  645. }
  646. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  647. if config.IsOpen == 1 { //对接了医保,走医保流程
  648. var pagesize int = 100
  649. var start int = 1
  650. var stop int
  651. var pagecount int
  652. var curpage int
  653. var isSuccess bool = true
  654. var customs []*models.NewCustom
  655. for _, item := range prescriptions {
  656. tm := time.Unix(item.PreTime, 0)
  657. if item.Type == 1 { //药品
  658. for _, subItem := range item.HisDoctorAdviceInfo {
  659. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 && subItem.BaseDrugLib.IsUser != 1 {
  660. //var randNum int
  661. //randNum = rand.Intn(10000) + 1000
  662. cus := &models.NewCustom{
  663. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  664. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  665. FeedetlSn: subItem.FeedetlSn,
  666. Price: fmt.Sprintf("%.4f", subItem.Price),
  667. MedListCodg: subItem.BaseDrugLib.MedicalInsuranceNumber,
  668. HospApprFlag: subItem.BaseDrugLib.HospApprFlag,
  669. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  670. }
  671. customs = append(customs, cus)
  672. }
  673. }
  674. }
  675. if item.Type == 2 { //项目
  676. for _, subItem := range item.HisPrescriptionProject {
  677. //var randNum int
  678. //randNum = rand.Intn(10000) + 1000
  679. if subItem.Type == 2 {
  680. if len(subItem.HisProject.MedicalCode) > 0 {
  681. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  682. cus := &models.NewCustom{
  683. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  684. Cut: fmt.Sprintf("%.4f", cnt),
  685. FeedetlSn: subItem.FeedetlSn,
  686. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  687. MedListCodg: subItem.HisProject.MedicalCode,
  688. HospApprFlag: -1,
  689. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  690. }
  691. customs = append(customs, cus)
  692. }
  693. } else if subItem.Type == 3 {
  694. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 && subItem.GoodInfo.IsUser != 1 {
  695. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  696. cus := &models.NewCustom{
  697. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  698. Cut: fmt.Sprintf("%.4f", cnt),
  699. FeedetlSn: subItem.FeedetlSn,
  700. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  701. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  702. HospApprFlag: -1,
  703. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  704. }
  705. customs = append(customs, cus)
  706. }
  707. }
  708. }
  709. }
  710. }
  711. //总页数,向上取整,注意除之前要先转换类型为float64
  712. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  713. var ress []*ResultFour
  714. for curpage = 1; curpage <= pagecount; curpage++ {
  715. if curpage == 1 {
  716. start = 1
  717. } else {
  718. start = (curpage-1)*pagesize + 1
  719. }
  720. stop = curpage * pagesize
  721. if stop > len(customs) {
  722. stop = len(customs)
  723. }
  724. var result string
  725. var requestLog string
  726. if miConfig.MdtrtareaAdmvs == "150499" {
  727. data := make(map[string]interface{})
  728. if record.MedType == 14 {
  729. if record.InsutypeType == "390" {
  730. data["med_type"] = "9933"
  731. } else if record.InsutypeType == "310" {
  732. data["med_type"] = "990502"
  733. }
  734. } else if record.MedType == 11 {
  735. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  736. }
  737. data["psn_no"] = record.PsnNo
  738. data["number"] = record.Number
  739. data["customs"] = customs[start-1 : stop]
  740. data["chrg_bchno"] = chrg_bchno
  741. data["dept"] = strconv.FormatInt(department.ID, 10)
  742. data["dept_code"] = department.Number
  743. data["doctor_code"] = doctor_info.DoctorNumber
  744. data["doctor_name"] = doctor_info.UserName
  745. data["org_name"] = miConfig.OrgName
  746. data["opertor"] = roles.UserName
  747. data["fixmedins_code"] = miConfig.Code
  748. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  749. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  750. data["secret_key"] = miConfig.SecretKey
  751. var req *http.Request
  752. bytesData, _ := json.Marshal(data)
  753. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2301", bytes.NewReader(bytesData))
  754. client := &http.Client{}
  755. resp, _ := client.Do(req)
  756. defer resp.Body.Close()
  757. body, ioErr := ioutil.ReadAll(resp.Body)
  758. if ioErr != nil {
  759. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  761. return
  762. }
  763. var respJSON map[string]interface{}
  764. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  765. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  767. return
  768. }
  769. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  770. result_byte, _ := json.Marshal(respJSON)
  771. result = string(result_byte)
  772. } else {
  773. 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), doctor_info.DoctorNumber, doctor_info.UserName)
  774. saveLog(result, requestLog, "2301", "上传明细")
  775. }
  776. var dat map[string]interface{}
  777. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  778. fmt.Println(dat)
  779. } else {
  780. fmt.Println(err)
  781. }
  782. userJSONBytes, _ := json.Marshal(dat)
  783. var res ResultFour
  784. var resFour10265 ResultFour10265
  785. if miConfig.Code == "H15049901371" {
  786. if err := json.Unmarshal(userJSONBytes, &resFour10265); err != nil {
  787. utils.ErrorLog("解析失败:%v", err)
  788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  789. return
  790. }
  791. res.WarnMsg = resFour10265.WarnMsg
  792. res.Output = resFour10265.Output
  793. res.ErrMsg = resFour10265.ErrMsg
  794. res.RespondTime = resFour10265.RespondTime
  795. res.InfRefmsgid = resFour10265.InfRefmsgid
  796. Infcode, _ := strconv.ParseInt(resFour10265.Infcode, 10, 64)
  797. res.Infcode = Infcode
  798. } else {
  799. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  800. utils.ErrorLog("解析失败:%v", err)
  801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  802. return
  803. }
  804. }
  805. if res.Infcode == 0 {
  806. ress = append(ress, &res)
  807. } else {
  808. isSuccess = false
  809. errlog := &models.HisOrderError{
  810. UserOrgId: adminUser.CurrentOrgId,
  811. Ctime: time.Now().Unix(),
  812. Mtime: time.Now().Unix(),
  813. Number: chrg_bchno,
  814. ErrMsg: "",
  815. Status: 1,
  816. PatientId: id,
  817. RecordTime: recordDateTime,
  818. Stage: 4,
  819. }
  820. service.CreateErrMsgLog(errlog)
  821. c.ServeSuccessJSON(map[string]interface{}{
  822. "failed_code": -10,
  823. "msg": "上传明细错误,请联系his厂商",
  824. })
  825. return
  826. }
  827. }
  828. if isSuccess == true {
  829. if settle_accounts_type == 1 {
  830. for _, subItem := range ress {
  831. for _, item := range subItem.Output.Result {
  832. temp := strings.Split(item.FeedetlSn, "-")
  833. var advice_id int64 = 0
  834. var project_id int64 = 0
  835. var types int64 = 0
  836. id, _ := strconv.ParseInt(temp[2], 10, 64)
  837. types, _ = strconv.ParseInt(temp[1], 10, 64)
  838. if temp[1] == "1" {
  839. advice_id = id
  840. project_id = 0
  841. } else if temp[1] == "2" {
  842. advice_id = 0
  843. project_id = id
  844. }
  845. info := &models.HisOrderInfo{
  846. OrderNumber: record.Number,
  847. FeedetlSn: item.FeedetlSn,
  848. UploadDate: recordDateTime,
  849. AdviceId: advice_id,
  850. DetItemFeeSumamt: item.DetItemFeeSumamt,
  851. Cnt: item.Cnt,
  852. Pric: float64(item.Pric),
  853. PatientId: record.PatientId,
  854. PricUplmtAmt: item.PricUplmtAmt,
  855. SelfpayProp: item.SelfpayProp,
  856. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  857. OverlmtAmt: item.OverlmtAmt,
  858. PreselfpayAmt: item.PreselfpayAmt,
  859. BasMednFlag: item.BasMednFlag,
  860. MedChrgitmType: item.MedChrgitmType,
  861. HiNegoDrugFlag: item.HiNegoDrugFlag,
  862. Status: 1,
  863. Memo: item.Memo,
  864. Mtime: time.Now().Unix(),
  865. InscpScpAmt: item.InscpScpAmt,
  866. DrtReimFlag: item.DrtReimFlag,
  867. Ctime: time.Now().Unix(),
  868. ListSpItemFlag: item.ListSpItemFlag,
  869. ChldMedcFlag: item.ChldMedcFlag,
  870. LmtUsedFlag: item.LmtUsedFlag,
  871. ChrgitmLv: item.ChrgitmLv,
  872. UserOrgId: adminUser.CurrentOrgId,
  873. HisPatientId: record.ID,
  874. OrderId: 0,
  875. ProjectId: project_id,
  876. Type: types,
  877. SettleType: settle_accounts_type,
  878. }
  879. service.CreateOrderInfo(info)
  880. }
  881. }
  882. err := service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  883. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  884. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  885. if err == nil {
  886. c.ServeSuccessJSON(map[string]interface{}{
  887. "msg": "上传费用明细成功",
  888. })
  889. return
  890. } else {
  891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  892. return
  893. }
  894. } else {
  895. for _, subItem := range ress {
  896. for _, item := range subItem.Output.Result {
  897. temp := strings.Split(item.FeedetlSn, "-")
  898. var advice_id int64 = 0
  899. var project_id int64 = 0
  900. var types int64 = 0
  901. id, _ := strconv.ParseInt(temp[2], 10, 64)
  902. types, _ = strconv.ParseInt(temp[1], 10, 64)
  903. if temp[1] == "1" {
  904. advice_id = id
  905. project_id = 0
  906. } else if temp[1] == "2" {
  907. advice_id = 0
  908. project_id = id
  909. }
  910. info := &models.HisOrderInfo{
  911. OrderNumber: record.Number,
  912. FeedetlSn: item.FeedetlSn,
  913. UploadDate: time.Now().Unix(),
  914. AdviceId: advice_id,
  915. DetItemFeeSumamt: item.DetItemFeeSumamt,
  916. Cnt: item.Cnt,
  917. Pric: float64(item.Pric),
  918. PatientId: record.PatientId,
  919. PricUplmtAmt: item.PricUplmtAmt,
  920. SelfpayProp: item.SelfpayProp,
  921. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  922. OverlmtAmt: item.OverlmtAmt,
  923. PreselfpayAmt: item.PreselfpayAmt,
  924. BasMednFlag: item.BasMednFlag,
  925. MedChrgitmType: item.MedChrgitmType,
  926. HiNegoDrugFlag: item.HiNegoDrugFlag,
  927. Status: 1,
  928. Memo: item.Memo,
  929. Mtime: time.Now().Unix(),
  930. InscpScpAmt: item.InscpScpAmt,
  931. DrtReimFlag: item.DrtReimFlag,
  932. Ctime: time.Now().Unix(),
  933. ListSpItemFlag: item.ListSpItemFlag,
  934. ChldMedcFlag: item.ChldMedcFlag,
  935. LmtUsedFlag: item.LmtUsedFlag,
  936. ChrgitmLv: item.ChrgitmLv,
  937. UserOrgId: adminUser.CurrentOrgId,
  938. HisPatientId: record.ID,
  939. ProjectId: project_id,
  940. Type: types,
  941. SettleType: settle_accounts_type,
  942. }
  943. service.CreateOrderInfo(info)
  944. }
  945. }
  946. service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  947. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  948. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  949. c.ServeSuccessJSON(map[string]interface{}{
  950. "msg": "上传费用明细成功",
  951. })
  952. }
  953. }
  954. }
  955. }
  956. func (c *ZHHisApiController) RefundLingBao() {
  957. }
  958. func (c *ZHHisApiController) GetLingBao() {
  959. }
  960. func (c *ZHHisApiController) ReadEleCard() {
  961. id_card_type, _ := c.GetInt64("id_card_type")
  962. admin_user_id, _ := c.GetInt64("admin_user_id")
  963. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  964. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  965. var api string
  966. api = "http://172.16.13.254:9532/" + "nmyb/readcard?" + "fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName +
  967. "&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
  968. fmt.Println(api)
  969. resp, requestErr := http.Get(api)
  970. if requestErr != nil {
  971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  972. return
  973. }
  974. body, ioErr := ioutil.ReadAll(resp.Body)
  975. if ioErr != nil {
  976. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  978. return
  979. }
  980. var respJSON map[string]interface{}
  981. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  982. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  983. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  984. return
  985. }
  986. var status string
  987. status = respJSON["data"].(map[string]interface{})["status"].(string)
  988. //card_type := respJSON["data"].(map[string]interface{})["type"].(string)
  989. var token string
  990. var res ResultTwo //1101结果
  991. var res10265 ResultTwo10265 //1101结果
  992. if status == "0" { //读卡成功
  993. token = respJSON["data"].(map[string]interface{})["token"].(string)
  994. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  995. result, _ := json.Marshal(respJSON)
  996. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  997. utils.ErrorLog("解析失败:%v", err)
  998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  999. return
  1000. }
  1001. res.ErrMsg = res10265.ErrMsg
  1002. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  1003. res.Infcode = infocode
  1004. res.Output = res10265.Output
  1005. res.InfRefmsgid = res10265.InfRefmsgid
  1006. if res.Infcode == 0 {
  1007. c.ServeSuccessJSON(map[string]interface{}{
  1008. "number": token,
  1009. })
  1010. }
  1011. } else {
  1012. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  1013. return
  1014. }
  1015. }
  1016. func (c *ZHHisApiController) ClearSettle() {
  1017. order_id, _ := c.GetInt64("order_id")
  1018. admin_user_id, _ := c.GetInt64("admin_user_id")
  1019. adminUser := c.GetAdminUserInfo()
  1020. var order models.HisOrder
  1021. order, _ = service.GetHisOrderByID(order_id)
  1022. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  1023. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1024. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1025. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1026. if config.IsOpen == 1 { //对接了医保,走医保流程
  1027. var result string
  1028. var requestLog string
  1029. result, requestLog = service.Gdyb90306(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  1030. saveLog(result, requestLog, "90306", "撤销结算清单")
  1031. var dat map[string]interface{}
  1032. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1033. fmt.Println(dat)
  1034. } else {
  1035. fmt.Println(err)
  1036. }
  1037. userJSONBytes, _ := json.Marshal(dat)
  1038. var res ResultSix
  1039. //var resSixteen ResultSixteen10265
  1040. if miConfig.Code == "H15049901371" {
  1041. //if err := json.Unmarshal(userJSONBytes, &resSixteen); err != nil {
  1042. // utils.ErrorLog("解析失败:%v", err)
  1043. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1044. // return
  1045. //}
  1046. //res.Cainfo = resSixteen.Cainfo
  1047. //res.WarnMsg = resSixteen.WarnMsg
  1048. //res.Output = resSixteen.Output
  1049. //res.ErrMsg = resSixteen.ErrMsg
  1050. //res.RespondTime = resSixteen.RespondTime
  1051. //Infcode, _ := strconv.ParseInt(resSixteen.Infcode, 10, 64)
  1052. //res.Infcode = Infcode
  1053. } else {
  1054. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1055. utils.ErrorLog("解析失败:%v", err)
  1056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1057. return
  1058. }
  1059. }
  1060. if res.Infcode == 0 {
  1061. record, _ := service.GetUploadRecord(order_id)
  1062. record.Status = 0
  1063. service.UpdateRecord(&record)
  1064. c.ServeSuccessJSON(map[string]interface{}{
  1065. "msg": "撤销成功",
  1066. })
  1067. } else {
  1068. c.ServeSuccessJSON(map[string]interface{}{
  1069. "code": -10,
  1070. "msg": res.ErrMsg,
  1071. })
  1072. }
  1073. }
  1074. }
  1075. func (c *ZHHisApiController) GetZHPatientInfo() {
  1076. id_card_no := c.GetString("id_card_no")
  1077. admin_user_id, _ := c.GetInt64("admin_user_id")
  1078. patient, _ := service.GetPatientByIDCard(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  1079. if patient.ID == 0 {
  1080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1081. return
  1082. }
  1083. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  1084. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  1085. config, _ := service.GetMedicalInsuranceConfig(c.GetAdminUserInfo().CurrentOrgId)
  1086. if config.IsOpen == 1 {
  1087. var result string
  1088. var request_log string
  1089. var result_log string
  1090. if miConfig.MdtrtareaAdmvs == "150499" {
  1091. //请求内网数据
  1092. api := "http://172.16.13.254:9532/" + "nmyb/1101?cert_no=" + patient.IdCardNo +
  1093. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  1094. "&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
  1095. resp, requestErr := http.Get(api)
  1096. if requestErr != nil {
  1097. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1098. return
  1099. }
  1100. body, ioErr := ioutil.ReadAll(resp.Body)
  1101. if ioErr != nil {
  1102. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1104. return
  1105. }
  1106. var respJSON map[string]interface{}
  1107. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1108. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1110. return
  1111. }
  1112. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1113. result_byte, _ := json.Marshal(respJSON)
  1114. result = string(result_byte)
  1115. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  1116. } else {
  1117. 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)
  1118. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  1119. }
  1120. //result := service.Gdyb1101A(id_card_no, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, patient.Name)
  1121. var dat map[string]interface{}
  1122. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1123. fmt.Println(dat)
  1124. } else {
  1125. fmt.Println(err)
  1126. }
  1127. userJSONBytes, _ := json.Marshal(dat)
  1128. var res ResultTwo
  1129. var resTwo10265 ResultTwo10265
  1130. if miConfig.Code == "H15049901371" {
  1131. if err := json.Unmarshal(userJSONBytes, &resTwo10265); err != nil {
  1132. utils.ErrorLog("解析失败:%v", err)
  1133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1134. return
  1135. }
  1136. Infcode, _ := strconv.ParseInt(resTwo10265.Infcode, 10, 64)
  1137. res.Infcode = Infcode
  1138. res.ErrMsg = resTwo10265.ErrMsg
  1139. res.Output = resTwo10265.Output
  1140. res.InfRefmsgid = resTwo10265.InfRefmsgid
  1141. res.RespondTime = resTwo10265.RespondTime
  1142. res.WarnInfo = resTwo10265.WarnInfo
  1143. } else {
  1144. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1145. utils.ErrorLog("解析失败:%v", err)
  1146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1147. return
  1148. }
  1149. }
  1150. var insutypes []string
  1151. var insutype string
  1152. var is390 int = 0
  1153. var is310 int = 0
  1154. for _, item := range res.Output.Iinfo {
  1155. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1156. insutypes = append(insutypes, item.Insutype)
  1157. }
  1158. }
  1159. if len(insutypes) == 1 {
  1160. insutype = insutypes[0]
  1161. } else {
  1162. for _, i := range insutypes {
  1163. if i == "390" {
  1164. is390 = 1
  1165. }
  1166. if i == "310" {
  1167. is310 = 1
  1168. }
  1169. }
  1170. }
  1171. if is390 == 1 {
  1172. insutype = "390"
  1173. }
  1174. if is310 == 1 {
  1175. insutype = "310"
  1176. }
  1177. if len(insutypes) == 0 {
  1178. insutype = "310"
  1179. }
  1180. if res.Infcode != 0 {
  1181. c.ServeSuccessJSON(map[string]interface{}{
  1182. "failed_code": -10,
  1183. "msg": res.ErrMsg,
  1184. })
  1185. } else {
  1186. c.ServeSuccessJSON(map[string]interface{}{
  1187. "failed_code": 0,
  1188. "info": res,
  1189. "insutype": insutype,
  1190. })
  1191. }
  1192. }
  1193. }
  1194. func (c *ZHHisApiController) GetZHInHospitalCheck() {
  1195. id, _ := c.GetInt64("id")
  1196. record_time := c.GetString("record_time")
  1197. name := c.GetString("name")
  1198. phone := c.GetString("phone")
  1199. id_card_type, _ := c.GetInt64("id_card_type")
  1200. certificates, _ := c.GetInt64("certificates")
  1201. id_card_no := c.GetString("id_card_no")
  1202. doctor, _ := c.GetInt64("doctor")
  1203. admin_user_id, _ := c.GetInt64("admin_user_id")
  1204. department, _ := c.GetInt64("department")
  1205. adm_bed, _ := c.GetInt64("adm_bed")
  1206. diagnosis_ids := c.GetString("diagnosis")
  1207. sick_type, _ := c.GetInt64("sick_type")
  1208. start_time := c.GetString("start_time")
  1209. insuplc_admdvs := c.GetString("insuplc_admdvs")
  1210. balance_accounts_type, _ := c.GetInt64("balance_accounts_type")
  1211. social_type, _ := c.GetInt64("social_type")
  1212. psn_type, _ := c.GetInt64("psn_type")
  1213. //reg_type, _ := c.GetInt64("p_type")
  1214. med_type, _ := c.GetInt64("med_type")
  1215. diagnosis_ids_arr := strings.Split(diagnosis_ids, "-")
  1216. timeLayout := "2006-01-02"
  1217. loc, _ := time.LoadLocation("Local")
  1218. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1219. if err != nil {
  1220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1221. return
  1222. }
  1223. recordDateTime := theTime.Unix()
  1224. adminInfo := c.GetAdminUserInfo()
  1225. record, _ := service.GetLastHospitalRecord(id, adminInfo.CurrentOrgId)
  1226. if record.ID != 0 {
  1227. if record.InHospitalStatus == 1 && record.OutHospitalStatus != 1 {
  1228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalExistDataException)
  1229. return
  1230. }
  1231. }
  1232. var patient service.Patients
  1233. if id == 0 {
  1234. patient, _ = service.GetPatientByIDCard(id_card_no, adminInfo.CurrentOrgId)
  1235. } else {
  1236. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  1237. }
  1238. diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  1239. sickConfig, _ := service.FindSickById(sick_type)
  1240. departmentInfo, _ := service.GetDepartMentDetail(department)
  1241. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1242. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1243. var result string
  1244. var request_log string
  1245. var result_log string
  1246. var res2 ResultTwo
  1247. var resTwo10265 ResultTwo10265
  1248. psn_info, _ := service.GetPsnByPatientId(patient.ID)
  1249. if miConfig.MdtrtareaAdmvs == "150499" {
  1250. if id_card_type == 2 {
  1251. mdtrt_cert_no := ""
  1252. card_sn := ""
  1253. if record.IdCardType == 1 {
  1254. bas := strings.Split(psn_info.CardInfo, "|")
  1255. cardNumber := bas[2]
  1256. mdtrt_cert_no = cardNumber
  1257. card_sn = bas[3]
  1258. } else {
  1259. mdtrt_cert_no = id_card_no
  1260. }
  1261. //请求内网数据
  1262. api := "http://172.16.13.254:9532/" + "nmyb/1101?cert_no=" + mdtrt_cert_no +
  1263. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  1264. "&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
  1265. resp, requestErr := http.Get(api)
  1266. if requestErr != nil {
  1267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1268. return
  1269. }
  1270. body, ioErr := ioutil.ReadAll(resp.Body)
  1271. if ioErr != nil {
  1272. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1274. return
  1275. }
  1276. var respJSON map[string]interface{}
  1277. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1278. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1280. return
  1281. }
  1282. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1283. result_byte, _ := json.Marshal(respJSON)
  1284. result = string(result_byte)
  1285. var dat map[string]interface{}
  1286. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1287. fmt.Println(dat)
  1288. } else {
  1289. fmt.Println(err)
  1290. }
  1291. userJSONBytes, _ := json.Marshal(dat)
  1292. if err := json.Unmarshal(userJSONBytes, &resTwo10265); err != nil {
  1293. utils.ErrorLog("解析失败:%v", err)
  1294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1295. return
  1296. }
  1297. Infcode, _ := strconv.ParseInt(resTwo10265.Infcode, 10, 64)
  1298. res2.Infcode = Infcode
  1299. res2.ErrMsg = resTwo10265.ErrMsg
  1300. res2.Output = resTwo10265.Output
  1301. res2.InfRefmsgid = resTwo10265.InfRefmsgid
  1302. res2.RespondTime = resTwo10265.RespondTime
  1303. res2.WarnInfo = resTwo10265.WarnInfo
  1304. } else {
  1305. res2.Infcode = 0
  1306. res2.Output.Baseinfo.PsnNo = psn_info.PsnNo
  1307. res2.Output.Baseinfo.Certno = patient.IdCardNo
  1308. }
  1309. } else {
  1310. 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)
  1311. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  1312. }
  1313. doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor)
  1314. deviceNumber, _ := service.GetDeviceNumberByID(adm_bed, adminInfo.CurrentOrgId)
  1315. if miConfig.MdtrtareaAdmvs != "150499" {
  1316. var dat map[string]interface{}
  1317. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1318. fmt.Println(dat)
  1319. } else {
  1320. fmt.Println(err)
  1321. }
  1322. userJSONBytes, _ := json.Marshal(dat)
  1323. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  1324. utils.ErrorLog("解析失败:%v", err)
  1325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1326. return
  1327. }
  1328. }
  1329. var infoStr string
  1330. if miConfig.MdtrtareaAdmvs == "150499" {
  1331. if id_card_type == 2 {
  1332. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  1333. infoStr = string(Iinfos)
  1334. } else {
  1335. infoStr = psn_info.Insuinfo
  1336. }
  1337. } else {
  1338. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  1339. infoStr = string(Iinfos)
  1340. }
  1341. var rf []*ResultFive
  1342. json.Unmarshal([]byte(infoStr), &rf)
  1343. var insutypes []*ResultFive
  1344. var insutype string
  1345. var is390 int = 0
  1346. var is310 int = 0
  1347. for _, item := range rf {
  1348. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1349. insutypes = append(insutypes, item)
  1350. }
  1351. }
  1352. if len(insutypes) == 1 {
  1353. insutype = insutypes[0].Insutype
  1354. //insuplc_admdvs = insutypes[0].InsuplcAdmdvs
  1355. } else {
  1356. for _, i := range insutypes {
  1357. if i.Insutype == "390" {
  1358. is390 = 1
  1359. }
  1360. if i.Insutype == "310" {
  1361. is310 = 1
  1362. }
  1363. }
  1364. }
  1365. if is390 == 1 {
  1366. insutype = "390"
  1367. }
  1368. if is310 == 1 {
  1369. insutype = "310"
  1370. }
  1371. if len(insutypes) == 0 {
  1372. insutype = "310"
  1373. }
  1374. if len(insutypes) == 2 {
  1375. insutype = strconv.FormatInt(social_type, 10)
  1376. }
  1377. //for _, item := range rf {
  1378. // if item.Insutype == insutype {
  1379. // insuplc_admdvs = item.InsuplcAdmdvs
  1380. // }
  1381. //}
  1382. if res2.Infcode == 0 {
  1383. //var insutypes []string
  1384. //
  1385. //var insutype string
  1386. //var is390 int = 0
  1387. //var is310 int = 0
  1388. //for _, item := range res2.Output.Iinfo {
  1389. // if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1390. // insutypes = append(insutypes, item.Insutype)
  1391. // }
  1392. //}
  1393. //if len(insutypes) == 1 {
  1394. // insutype = insutypes[0]
  1395. //} else {
  1396. // for _, i := range insutypes {
  1397. // if i == "390" {
  1398. // is390 = 1
  1399. // }
  1400. //
  1401. // if i == "310" {
  1402. // is310 = 1
  1403. // }
  1404. // }
  1405. //}
  1406. //if is390 == 1 {
  1407. // insutype = "390"
  1408. //}
  1409. //if is310 == 1 {
  1410. // insutype = "310"
  1411. //}
  1412. //
  1413. //if len(insutypes) == 0 {
  1414. // insutype = "310"
  1415. //}
  1416. if len(insuplc_admdvs) == 0 {
  1417. insuplc_admdvs = miConfig.InsuplcAdmdvs
  1418. }
  1419. timestamp := time.Now().Unix()
  1420. tempTime := time.Unix(timestamp, 0)
  1421. timeFormat := tempTime.Format("20060102150405")
  1422. chrgBchno := rand.Intn(100000) + 10000
  1423. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(id, 10)
  1424. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  1425. var struct2401 service.Struct2401
  1426. struct2401.PsnNo = res2.Output.Baseinfo.PsnNo
  1427. //insutype = "310"
  1428. struct2401.Insutype = insutype
  1429. psn_info, _ := service.GetPsnByPatientId(patient.ID)
  1430. if id_card_type == 1 {
  1431. struct2401.MdtrtCertType = "03"
  1432. bas := strings.Split(psn_info.CardInfo, "|")
  1433. cardNumber := bas[2]
  1434. struct2401.MdtrtCertNo = cardNumber
  1435. } else {
  1436. struct2401.MdtrtCertType = "02"
  1437. struct2401.MdtrtCertNo = res2.Output.Baseinfo.Certno
  1438. }
  1439. if miConfig.Code == "H15049901371" {
  1440. if med_type == 14 {
  1441. if insutype == "390" {
  1442. struct2401.MedType = "9933"
  1443. } else if insutype == "310" {
  1444. struct2401.MedType = "990502"
  1445. }
  1446. } else if med_type == 11 {
  1447. struct2401.MedType = "21"
  1448. }
  1449. } else {
  1450. if med_type == 11 {
  1451. struct2401.MedType = "21"
  1452. } else {
  1453. struct2401.MedType = strconv.FormatInt(int64(med_type), 10)
  1454. }
  1455. }
  1456. struct2401.IptNo = ipt_otp_no
  1457. struct2401.AtddrNo = doctorInfo.DoctorNumber
  1458. struct2401.ChfpdrName = doctorInfo.UserName
  1459. struct2401.AdmDiagDscr = diagnosisConfig[0].ClassName
  1460. struct2401.AdmDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  1461. struct2401.AdmDeptName = departmentInfo.Name
  1462. struct2401.AdmBed = deviceNumber.Number
  1463. struct2401.AdmBed = "待定"
  1464. struct2401.DscgMaindiagName = diagnosisConfig[0].ClassName
  1465. struct2401.DscgMaindiagCode = diagnosisConfig[0].CountryCode
  1466. struct2401.Begntime = start_time
  1467. struct2401.DiseCodg = sickConfig.CountryCode
  1468. struct2401.DiseName = sickConfig.ClassName
  1469. var dises []service.DiseinfoStruct
  1470. for index, item := range diagnosisConfig {
  1471. var dise service.DiseinfoStruct
  1472. dise.PsnNo = res2.Output.Baseinfo.PsnNo
  1473. dise.DiagType = "1"
  1474. if index == 0 {
  1475. dise.MaindiagFlag = "1"
  1476. } else {
  1477. dise.MaindiagFlag = "2"
  1478. }
  1479. dise.DiagSrtNo = strconv.FormatInt(int64(index), 10)
  1480. dise.DiseDorName = doctorInfo.UserName
  1481. dise.DiagCode = item.CountryCode
  1482. dise.DiagName = item.ClassName
  1483. dise.DiagDept = departmentInfo.Name
  1484. dise.DiseDorNo = doctorInfo.DoctorNumber
  1485. dise.DiagTime = timeFormatOne
  1486. dises = append(dises, dise)
  1487. }
  1488. struct2401.Diseinfo = dises
  1489. var result string
  1490. var request_log string
  1491. if miConfig.MdtrtareaAdmvs == "150499" {
  1492. data := make(map[string]interface{})
  1493. data["org_name"] = miConfig.OrgName
  1494. data["doctor"] = role.UserName
  1495. data["fixmedins_code"] = miConfig.Code
  1496. data["insuplc_admdvs"] = insuplc_admdvs
  1497. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1498. data["secret_key"] = miConfig.SecretKey
  1499. data["struct_2401"] = struct2401
  1500. var req *http.Request
  1501. bytesData, _ := json.Marshal(data)
  1502. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2401", bytes.NewReader(bytesData))
  1503. client := &http.Client{}
  1504. resp, _ := client.Do(req)
  1505. defer resp.Body.Close()
  1506. body, ioErr := ioutil.ReadAll(resp.Body)
  1507. if ioErr != nil {
  1508. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1510. return
  1511. }
  1512. var respJSON map[string]interface{}
  1513. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1514. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1516. return
  1517. }
  1518. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1519. result_byte, _ := json.Marshal(respJSON)
  1520. result = string(result_byte)
  1521. } else {
  1522. result, request_log = service.ZHGdyb2401(struct2401, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, insuplc_admdvs, miConfig.MdtrtareaAdmvs)
  1523. saveLog(result, request_log, "2401", "入院登记")
  1524. }
  1525. var dat map[string]interface{}
  1526. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1527. fmt.Println(dat)
  1528. } else {
  1529. fmt.Println(err)
  1530. }
  1531. userJSONBytes, _ := json.Marshal(dat)
  1532. var res ResultThree
  1533. var resThree10265 ResultThree10265
  1534. if miConfig.Code == "H15049901371" {
  1535. if err := json.Unmarshal(userJSONBytes, &resThree10265); err != nil {
  1536. utils.ErrorLog("解析失败:%v", err)
  1537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1538. return
  1539. }
  1540. Infcode, _ := strconv.ParseInt(resThree10265.Infcode, 10, 64)
  1541. res.Infcode = Infcode
  1542. res.ErrMsg = resThree10265.ErrMsg
  1543. res.Output = resThree10265.Output
  1544. res.InfRefmsgid = resThree10265.InfRefmsgid
  1545. res.RespondTime = resThree10265.RespondTime
  1546. } else {
  1547. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1548. utils.ErrorLog("解析失败:%v", err)
  1549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1550. return
  1551. }
  1552. }
  1553. if res.Infcode == 0 {
  1554. //result2 := service.Gdyb5301Two(res2.Output.Baseinfo.PsnNo, miConfig.OrgName, role.UserName, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  1555. //fmt.Println(result2)
  1556. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  1557. Idetinfos, _ := json.Marshal(res2.Output.Idetinfo)
  1558. infoStr := string(Iinfos)
  1559. idetinfoStr := string(Idetinfos)
  1560. inHospital := &models.HisHospitalCheckRecord{
  1561. PatientId: id,
  1562. Name: name,
  1563. MedicalTreatmentType: med_type,
  1564. RecordDate: recordDateTime,
  1565. IdCardNo: id_card_no,
  1566. AdminUserId: admin_user_id,
  1567. Departments: department,
  1568. UserOrgId: adminInfo.CurrentOrgId,
  1569. Status: 1,
  1570. Ctime: time.Now().Unix(),
  1571. Mtime: time.Now().Unix(),
  1572. Number: res.Output.Result.MdtrtID,
  1573. Doctor: doctor,
  1574. PsnNo: res2.Output.Baseinfo.PsnNo,
  1575. PsnCertType: res2.Output.Baseinfo.PsnCertType,
  1576. Certno: res2.Output.Baseinfo.Certno,
  1577. PsnName: res2.Output.Baseinfo.PsnName,
  1578. Gend: res2.Output.Baseinfo.Gend,
  1579. Naty: res2.Output.Baseinfo.Naty,
  1580. MedType: med_type,
  1581. InsutypeType: insutype,
  1582. Brdy: res2.Output.Baseinfo.Brdy,
  1583. Iinfo: infoStr,
  1584. Idetinfo: idetinfoStr,
  1585. IptOtpNo: ipt_otp_no,
  1586. AdmBed: adm_bed,
  1587. IdCardType: id_card_type,
  1588. Diagnosis: diagnosis_ids,
  1589. SickType: sick_type,
  1590. MdtrtCertType: "02",
  1591. InHosptialTime: start_time,
  1592. OutHosptialTime: "",
  1593. InHospitalStatus: 1,
  1594. Certificates: certificates,
  1595. Phone: phone,
  1596. BalanceAccountsType: balance_accounts_type,
  1597. PsnType: psn_type,
  1598. InsuplcAdmdvs: insuplc_admdvs,
  1599. }
  1600. service.CreateHospitalRecord(inHospital)
  1601. c.ServeSuccessJSON(map[string]interface{}{
  1602. "msg": "办理入院成功",
  1603. "info": inHospital,
  1604. })
  1605. } else {
  1606. c.ServeSuccessJSON(map[string]interface{}{
  1607. "failed_code": -10,
  1608. "msg": res.ErrMsg,
  1609. })
  1610. }
  1611. } else {
  1612. c.ServeSuccessJSON(map[string]interface{}{
  1613. "failed_code": -10,
  1614. "msg": res2.ErrMsg,
  1615. })
  1616. return
  1617. }
  1618. }
  1619. func (this *ZHHisApiController) GetZHOutHospitalCheck() {
  1620. id, _ := this.GetInt64("id")
  1621. patient_id, _ := this.GetInt64("patient_id")
  1622. admin_user_id, _ := this.GetInt64("admin_user_id")
  1623. record_time := this.GetString("record_time")
  1624. out_time := this.GetString("out_time")
  1625. adminInfo := this.GetAdminUserInfo()
  1626. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1627. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1628. record, _ := service.GetInHospitalRecord(id)
  1629. if record.ID == 0 {
  1630. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  1631. return
  1632. }
  1633. timeLayout := "2006-01-02"
  1634. loc, _ := time.LoadLocation("Local")
  1635. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1636. if err != nil {
  1637. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1638. return
  1639. }
  1640. recordDateTime := theTime.Unix()
  1641. var patient service.Patients
  1642. if patient_id == 0 {
  1643. patient, _ = service.GetPatientByIDCard(record.IdCardNo, adminInfo.CurrentOrgId)
  1644. } else {
  1645. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  1646. }
  1647. fmt.Println(patient)
  1648. diagnosis_ids_arr := strings.Split(record.Diagnosis, "-")
  1649. diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  1650. departmentInfo, _ := service.GetDepartMentDetail(record.Departments)
  1651. doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, record.Doctor)
  1652. //deviceNumber, _ := service.GetDeviceNumberByID(record.AdmBed, adminInfo.CurrentOrgId)
  1653. sickConfig, _ := service.FindSickById(record.SickType)
  1654. var struct2402 service.Struct2402
  1655. timestamp := time.Now().Unix()
  1656. tempTime := time.Unix(timestamp, 0)
  1657. //timeFormat := tempTime.Format("20060102150405")
  1658. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  1659. struct2402.PsnNo = record.PsnNo
  1660. struct2402.Insutype = record.InsutypeType
  1661. struct2402.DscgWay = "1"
  1662. struct2402.Endtime = out_time
  1663. struct2402.DscgDeptName = departmentInfo.Number
  1664. struct2402.DscgDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  1665. struct2402.MdtrtId = record.Number
  1666. var dises []service.Diseinfo2402Struct
  1667. for index, item := range diagnosisConfig {
  1668. var dise service.Diseinfo2402Struct
  1669. dise.PsnNo = record.PsnNo
  1670. dise.DiagType = "1"
  1671. if index == 0 {
  1672. dise.MaindiagFlag = "1"
  1673. } else {
  1674. dise.MaindiagFlag = "2"
  1675. }
  1676. dise.MdtrtId = record.Number
  1677. dise.DiagSrtNo = strconv.FormatInt(int64(item.ID), 10)
  1678. dise.DiseDorName = doctorInfo.UserName
  1679. dise.DiagCode = item.CountryCode
  1680. dise.DiagName = item.ClassName
  1681. dise.DiagDept = departmentInfo.Name
  1682. dise.DiseDorNo = doctorInfo.DoctorNumber
  1683. dise.DiagTime = timeFormatOne
  1684. dises = append(dises, dise)
  1685. }
  1686. struct2402.Diseinfo = dises
  1687. struct2402.DiseName = sickConfig.ClassName
  1688. struct2402.DiseCode = sickConfig.CountryCode
  1689. var result string
  1690. var request_log string
  1691. if miConfig.MdtrtareaAdmvs == "150499" {
  1692. data := make(map[string]interface{})
  1693. data["org_name"] = miConfig.OrgName
  1694. data["doctor"] = role.UserName
  1695. data["fixmedins_code"] = miConfig.Code
  1696. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  1697. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1698. data["secret_key"] = miConfig.SecretKey
  1699. data["struct_2402"] = struct2402
  1700. var req *http.Request
  1701. bytesData, _ := json.Marshal(data)
  1702. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2402", bytes.NewReader(bytesData))
  1703. client := &http.Client{}
  1704. resp, _ := client.Do(req)
  1705. defer resp.Body.Close()
  1706. body, ioErr := ioutil.ReadAll(resp.Body)
  1707. if ioErr != nil {
  1708. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1709. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1710. return
  1711. }
  1712. var respJSON map[string]interface{}
  1713. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1714. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1715. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1716. return
  1717. }
  1718. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1719. result_byte, _ := json.Marshal(respJSON)
  1720. result = string(result_byte)
  1721. } else {
  1722. result, request_log = service.ZHGdyb2402(struct2402, miConfig.OrgName, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  1723. saveLog(result, request_log, "2402", "出院")
  1724. }
  1725. var dat map[string]interface{}
  1726. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1727. fmt.Println(dat)
  1728. } else {
  1729. fmt.Println(err)
  1730. }
  1731. userJSONBytes, _ := json.Marshal(dat)
  1732. var res ResultEmpty
  1733. var resEmpty10265 ResultEmpty10265
  1734. if miConfig.Code == "H15049901371" {
  1735. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  1736. utils.ErrorLog("解析失败:%v", err)
  1737. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1738. return
  1739. }
  1740. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  1741. res.Infcode = Infcode
  1742. res.RespondTime = resEmpty10265.RespondTime
  1743. res.ErrMsg = resEmpty10265.ErrMsg
  1744. res.Output = resEmpty10265.Output
  1745. res.WarnMsg = resEmpty10265.WarnMsg
  1746. } else {
  1747. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1748. utils.ErrorLog("解析失败:%v", err)
  1749. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1750. return
  1751. }
  1752. }
  1753. if res.Infcode == 0 {
  1754. record.OutHospitalStatus = 1
  1755. record.OutHosptialTime = struct2402.Endtime
  1756. record.OutWay = 1
  1757. service.CreateHospitalRecord(&record)
  1758. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  1759. var total float64
  1760. for _, item := range orders {
  1761. total = total + item.DetItemFeeSumamt
  1762. }
  1763. order := &models.HisOrder{
  1764. UserOrgId: adminInfo.CurrentOrgId,
  1765. HisPatientId: record.ID,
  1766. PatientId: record.PatientId,
  1767. SettleAccountsDate: recordDateTime,
  1768. Ctime: time.Now().Unix(),
  1769. Mtime: time.Now().Unix(),
  1770. Status: 1,
  1771. Number: record.Number,
  1772. Infcode: 0,
  1773. WarnMsg: "",
  1774. Cainfo: "",
  1775. ErrMsg: "",
  1776. RespondTime: "",
  1777. InfRefmsgid: "",
  1778. OrderStatus: 1,
  1779. MdtrtId: record.Number,
  1780. IsMedicineInsurance: 1,
  1781. PType: 1,
  1782. MedfeeSumamt: total,
  1783. }
  1784. err = service.CreateOrder(order)
  1785. if err != nil {
  1786. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1787. return
  1788. }
  1789. this.ServeSuccessJSON(map[string]interface{}{
  1790. "msg": "出院成功",
  1791. })
  1792. } else {
  1793. this.ServeSuccessJSON(map[string]interface{}{
  1794. "failed_code": -10,
  1795. "msg": res.ErrMsg,
  1796. })
  1797. }
  1798. }
  1799. func (c *ZHHisApiController) GetSettleInfo() {
  1800. order_id, _ := c.GetInt64("order_id")
  1801. patient_id, _ := c.GetInt64("patient_id")
  1802. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  1803. admin_user_id, _ := c.GetInt64("admin_user_id")
  1804. pay_way, _ := c.GetInt64("pay_way")
  1805. pay_price, _ := c.GetFloat("pay_price")
  1806. pay_card_no := c.GetString("pay_card_no")
  1807. discount_price, _ := c.GetFloat("discount_price")
  1808. preferential_price, _ := c.GetFloat("preferential_price")
  1809. reality_price, _ := c.GetFloat("reality_price")
  1810. found_price, _ := c.GetFloat("found_price")
  1811. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1812. private_price, _ := c.GetFloat("private_price")
  1813. fapiao_code := c.GetString("fapiao_code")
  1814. fapiao_number := c.GetString("fapiao_number")
  1815. record, _ := service.GetInHospitalRecord(in_hospital_id)
  1816. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  1817. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  1818. order, _ := service.GetHisOrderByID(order_id)
  1819. //dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  1820. //tmp_decimal := c.GetString("tmp_decimal")
  1821. //var decimal float64 //本次使用的押金
  1822. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  1823. tmp_decimal := c.GetString("tmp_decimal")
  1824. var decimal float64 //本次使用的押金
  1825. var errmsg error
  1826. if dec_way == "true" && tmp_decimal == "0" || dec_way == "true" && tmp_decimal == "" {
  1827. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  1828. return
  1829. }
  1830. if len(tmp_decimal) > 0 {
  1831. if tmp_decimal[0] == 45 {
  1832. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  1833. return
  1834. }
  1835. }
  1836. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  1837. if errs != nil {
  1838. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
  1839. return
  1840. }
  1841. decimal = tt
  1842. var rf []*ResultFive
  1843. json.Unmarshal([]byte(record.Iinfo), &rf)
  1844. chrg_bchno := order.Number
  1845. cert_no := record.Certno
  1846. if record.ID == 0 {
  1847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1848. return
  1849. }
  1850. if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  1851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  1852. return
  1853. }
  1854. if record.IdCardType == 1 {
  1855. } else {
  1856. cert_no = record.Certno
  1857. }
  1858. var result string
  1859. var src_resquest string
  1860. timeLayout := "2006-01-02"
  1861. loc, _ := time.LoadLocation("Local")
  1862. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record.InHosptialTime, loc)
  1863. if err != nil {
  1864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1865. return
  1866. }
  1867. recordStartDateTime := theTime.Unix()
  1868. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", record.OutHosptialTime, loc)
  1869. if err != nil {
  1870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1871. return
  1872. }
  1873. recordEndDateTime := theTimeEnd.Unix()
  1874. prescriptions, _ := service.GetZHSettleMonthHisPrescription(c.GetAdminUserInfo().CurrentOrgId, patient_id, recordStartDateTime, recordEndDateTime)
  1875. var total float64
  1876. for _, item := range prescriptions {
  1877. if item.Type == 1 { //药品
  1878. for _, subItem := range item.HisDoctorAdviceInfo {
  1879. total = total + (subItem.Price * subItem.PrescribingNumber)
  1880. }
  1881. }
  1882. if item.Type == 2 { //项目
  1883. for _, subItem := range item.HisPrescriptionProject {
  1884. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  1885. total = total + (subItem.Price * cnt)
  1886. }
  1887. }
  1888. }
  1889. //allTotal := fmt.Sprintf("%.2f", total)
  1890. var allTotal string
  1891. if record.OutHospitalStatus == 0 && order.ID == 0 {
  1892. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  1893. var total float64
  1894. for _, item := range orders {
  1895. total = total + item.DetItemFeeSumamt
  1896. }
  1897. allTotal = fmt.Sprintf("%.4f", total)
  1898. } else {
  1899. allTotal = fmt.Sprintf("%.4f", order.MedfeeSumamt)
  1900. }
  1901. if miConfig.MdtrtareaAdmvs == "150499" {
  1902. psn_info, _ := service.GetPsnByPatientId(patient_id)
  1903. mdtrt_cert_no := ""
  1904. if record.IdCardType == 1 {
  1905. bas := strings.Split(psn_info.CardInfo, "|")
  1906. cardNumber := bas[2]
  1907. mdtrt_cert_no = cardNumber
  1908. } else {
  1909. mdtrt_cert_no = record.Certno
  1910. }
  1911. var acct_used_flag string
  1912. if pay_way == 4 {
  1913. acct_used_flag = "1"
  1914. } else {
  1915. acct_used_flag = "0"
  1916. }
  1917. //请求内网数据
  1918. api := "http://172.16.13.254:9532/" + "nmyb/2304?psn_no=" + record.PsnNo + "&mdtrt_id=" + record.Number + "&chrg_bchno=" + chrg_bchno +
  1919. "&insutype_type=" + record.InsutypeType + "&total=" + allTotal +
  1920. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  1921. "&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
  1922. resp, requestErr := http.Get(api)
  1923. if requestErr != nil {
  1924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1925. return
  1926. }
  1927. body, ioErr := ioutil.ReadAll(resp.Body)
  1928. if ioErr != nil {
  1929. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1931. return
  1932. }
  1933. var respJSON map[string]interface{}
  1934. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1935. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1937. return
  1938. }
  1939. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1940. result_byte, _ := json.Marshal(respJSON)
  1941. result = string(result_byte)
  1942. } else {
  1943. 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")
  1944. saveLog(result, src_resquest, "2304", "住院结算")
  1945. }
  1946. var dat map[string]interface{}
  1947. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1948. fmt.Println(dat)
  1949. } else {
  1950. fmt.Println(err)
  1951. }
  1952. userJSONBytes, _ := json.Marshal(dat)
  1953. var res ResultSeven
  1954. var resSeven10265 ResultSeven10265
  1955. if miConfig.Code == "H15049901371" {
  1956. if err := json.Unmarshal(userJSONBytes, &resSeven10265); err != nil {
  1957. utils.ErrorLog("解析失败:%v", err)
  1958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1959. return
  1960. }
  1961. Infcode, _ := strconv.ParseInt(resSeven10265.Infcode, 10, 64)
  1962. res.Infcode = Infcode
  1963. res.InfRefmsgid = resSeven10265.InfRefmsgid
  1964. res.RespondTime = resSeven10265.RespondTime
  1965. res.ErrMsg = resSeven10265.ErrMsg
  1966. res.Output = resSeven10265.Output
  1967. res.WarnMsg = resSeven10265.WarnMsg
  1968. res.Cainfo = resSeven10265.Cainfo
  1969. } else {
  1970. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1971. utils.ErrorLog("解析失败:%v", err)
  1972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1973. return
  1974. }
  1975. }
  1976. if res.Infcode != 0 {
  1977. errlog := &models.HisOrderError{
  1978. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1979. Ctime: time.Now().Unix(),
  1980. Mtime: time.Now().Unix(),
  1981. Number: chrg_bchno,
  1982. ErrMsg: res.ErrMsg,
  1983. Status: 1,
  1984. PatientId: patient_id,
  1985. RecordTime: time.Now().Unix(),
  1986. Stage: 6,
  1987. }
  1988. service.CreateErrMsgLog(errlog)
  1989. c.ServeSuccessJSON(map[string]interface{}{
  1990. "failed_code": -10,
  1991. "msg": res.ErrMsg,
  1992. })
  1993. return
  1994. } else {
  1995. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1996. order.OrderStatus = 2
  1997. order.DiscountPrice = discount_price
  1998. order.MedicalInsurancePrice = medical_insurance_price
  1999. order.FaPiaoNumber = fapiao_number
  2000. order.FaPiaoCode = fapiao_code
  2001. order.PayWay = pay_way
  2002. order.PayPrice = pay_price
  2003. order.PayCardNo = pay_card_no
  2004. order.PreferentialPrice = preferential_price
  2005. order.RealityPrice = reality_price
  2006. order.FoundPrice = found_price
  2007. order.PrivatePrice = private_price
  2008. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2009. order.SetlId = res.Output.Setlinfo.SetlID
  2010. order.PsnNo = res.Output.Setlinfo.PsnNo
  2011. order.PsnName = res.Output.Setlinfo.PsnName
  2012. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2013. order.Certno = res.Output.Setlinfo.Certno
  2014. order.Gend = res.Output.Setlinfo.Gend
  2015. order.Naty = res.Output.Setlinfo.Naty
  2016. order.Age = res.Output.Setlinfo.Age
  2017. order.Insutype = res.Output.Setlinfo.Insutype
  2018. order.PsnType = res.Output.Setlinfo.PsnType
  2019. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2020. order.SetlTime = res.Output.Setlinfo.SetlTime
  2021. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2022. if res.Output.Setlinfo.MedType == "140104" {
  2023. order.MedType = "14"
  2024. } else {
  2025. order.MedType = res.Output.Setlinfo.MedType
  2026. }
  2027. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2028. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2029. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2030. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2031. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2032. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2033. order.HifpPay = res.Output.Setlinfo.HifpPay
  2034. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2035. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2036. order.HifesPay = res.Output.Setlinfo.HifesPay
  2037. order.HifobPay = res.Output.Setlinfo.HifobPay
  2038. order.MafPay = res.Output.Setlinfo.MafPay
  2039. order.OthPay = res.Output.Setlinfo.OthPay
  2040. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2041. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2042. order.AcctPay = res.Output.Setlinfo.AcctPay
  2043. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2044. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2045. order.Balc = res.Output.Setlinfo.Balc
  2046. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2047. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2048. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2049. order.ClrWay = res.Output.Setlinfo.ClrWay
  2050. order.Creator = order.Creator
  2051. order.Modify = roles.AdminUserId
  2052. order.RequestLog = src_resquest
  2053. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2054. detailStr := string(setlDetail)
  2055. order.SetlDetail = detailStr
  2056. err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  2057. err = service.UpDateOrder(order)
  2058. if err == nil {
  2059. //判断是否使用了押金
  2060. if dec_way == "true" {
  2061. tmpstring := strconv.FormatInt(order.ID, 10)
  2062. order.Decimal = decimal
  2063. err = service.UpDateOrder(order)
  2064. //扣押金
  2065. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, patient_id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  2066. if errmsg != nil {
  2067. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  2068. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  2069. return
  2070. }
  2071. }
  2072. c.ServeSuccessJSON(map[string]interface{}{
  2073. "msg": "结算成功",
  2074. })
  2075. } else {
  2076. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2077. return
  2078. }
  2079. }
  2080. }
  2081. func (c *ZHHisApiController) GetPreSettleInfo() {
  2082. order_id, _ := c.GetInt64("order_id")
  2083. patient_id, _ := c.GetInt64("patient_id")
  2084. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  2085. admin_user_id, _ := c.GetInt64("admin_user_id")
  2086. record, _ := service.GetInHospitalRecord(in_hospital_id)
  2087. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  2088. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  2089. order, _ := service.GetHisOrderByID(order_id)
  2090. var allTotal string
  2091. if record.OutHospitalStatus == 0 && order.ID == 0 {
  2092. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  2093. var total float64
  2094. for _, item := range orders {
  2095. total = total + item.DetItemFeeSumamt
  2096. }
  2097. allTotal = fmt.Sprintf("%.4f", total)
  2098. } else {
  2099. allTotal = fmt.Sprintf("%.4f", order.MedfeeSumamt)
  2100. }
  2101. var rf []*ResultFive
  2102. json.Unmarshal([]byte(record.Iinfo), &rf)
  2103. chrg_bchno := order.Number
  2104. cert_no := record.Certno
  2105. if record.ID == 0 {
  2106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2107. return
  2108. }
  2109. //if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  2110. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  2111. // return
  2112. //}
  2113. psn_info, _ := service.GetPsnByPatientId(patient_id)
  2114. if record.IdCardType == 1 {
  2115. bas := strings.Split(psn_info.CardInfo, "|")
  2116. cardNumber := bas[2]
  2117. cert_no = cardNumber
  2118. } else {
  2119. cert_no = record.Certno
  2120. }
  2121. var result string
  2122. var src_resquest string
  2123. if miConfig.MdtrtareaAdmvs == "150499" {
  2124. //请求内网数据
  2125. api := "http://172.16.13.254:9532/" + "nmyb/2303?psn_no=" + record.PsnNo + "&mdtrt_id=" + record.Number + "&chrg_bchno=" + chrg_bchno +
  2126. "&insutype_type=" + record.InsutypeType + "&total=" + allTotal +
  2127. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2128. "&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
  2129. resp, requestErr := http.Get(api)
  2130. if requestErr != nil {
  2131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2132. return
  2133. }
  2134. body, ioErr := ioutil.ReadAll(resp.Body)
  2135. if ioErr != nil {
  2136. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2138. return
  2139. }
  2140. var respJSON map[string]interface{}
  2141. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2142. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2144. return
  2145. }
  2146. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2147. result_byte, _ := json.Marshal(respJSON)
  2148. result = string(result_byte)
  2149. } else {
  2150. 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)
  2151. saveLog(result, src_resquest, "2303", "住院预结算")
  2152. }
  2153. var dat map[string]interface{}
  2154. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2155. fmt.Println(dat)
  2156. } else {
  2157. fmt.Println(err)
  2158. }
  2159. userJSONBytes, _ := json.Marshal(dat)
  2160. var res ResultSeven
  2161. var resSeven10265 ResultSeven10265
  2162. if miConfig.Code == "H15049901371" {
  2163. if err := json.Unmarshal(userJSONBytes, &resSeven10265); err != nil {
  2164. utils.ErrorLog("解析失败:%v", err)
  2165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2166. return
  2167. }
  2168. Infcode, _ := strconv.ParseInt(resSeven10265.Infcode, 10, 64)
  2169. res.Infcode = Infcode
  2170. res.InfRefmsgid = resSeven10265.InfRefmsgid
  2171. res.RespondTime = resSeven10265.RespondTime
  2172. res.ErrMsg = resSeven10265.ErrMsg
  2173. res.Output = resSeven10265.Output
  2174. res.WarnMsg = resSeven10265.WarnMsg
  2175. res.Cainfo = resSeven10265.Cainfo
  2176. } else {
  2177. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2178. utils.ErrorLog("解析失败:%v", err)
  2179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2180. return
  2181. }
  2182. }
  2183. if res.Infcode != 0 {
  2184. errlog := &models.HisOrderError{
  2185. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2186. Ctime: time.Now().Unix(),
  2187. Mtime: time.Now().Unix(),
  2188. Number: chrg_bchno,
  2189. ErrMsg: res.ErrMsg,
  2190. Status: 1,
  2191. PatientId: patient_id,
  2192. RecordTime: time.Now().Unix(),
  2193. Stage: 6,
  2194. }
  2195. service.CreateErrMsgLog(errlog)
  2196. c.ServeSuccessJSON(map[string]interface{}{
  2197. "failed_code": -10,
  2198. "msg": res.ErrMsg,
  2199. })
  2200. return
  2201. } else {
  2202. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2203. order.OrderStatus = 1
  2204. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2205. order.SetlId = res.Output.Setlinfo.SetlID
  2206. order.PsnNo = res.Output.Setlinfo.PsnNo
  2207. order.PsnName = res.Output.Setlinfo.PsnName
  2208. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2209. order.Certno = res.Output.Setlinfo.Certno
  2210. order.Gend = res.Output.Setlinfo.Gend
  2211. order.Naty = res.Output.Setlinfo.Naty
  2212. order.Age = res.Output.Setlinfo.Age
  2213. order.Insutype = res.Output.Setlinfo.Insutype
  2214. order.PsnType = res.Output.Setlinfo.PsnType
  2215. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2216. order.SetlTime = res.Output.Setlinfo.SetlTime
  2217. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2218. if res.Output.Setlinfo.MedType == "140104" {
  2219. order.MedType = "14"
  2220. } else {
  2221. order.MedType = res.Output.Setlinfo.MedType
  2222. }
  2223. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2224. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2225. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2226. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2227. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2228. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2229. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  2230. order.HifpPay = res.Output.Setlinfo.HifpPay
  2231. order.HifesPay = res.Output.Setlinfo.HifesPay
  2232. order.HifobPay = res.Output.Setlinfo.HifobPay
  2233. order.MafPay = res.Output.Setlinfo.MafPay
  2234. order.OthPay = res.Output.Setlinfo.OthPay
  2235. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2236. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2237. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2238. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2239. order.AcctPay = res.Output.Setlinfo.AcctPay
  2240. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2241. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2242. order.Balc = res.Output.Setlinfo.Balc
  2243. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2244. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2245. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2246. order.ClrWay = res.Output.Setlinfo.ClrWay
  2247. order.Creator = order.Creator
  2248. order.Modify = roles.AdminUserId
  2249. order.RequestLog = src_resquest
  2250. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2251. detailStr := string(setlDetail)
  2252. order.SetlDetail = detailStr
  2253. //err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  2254. if record.OutHospitalStatus == 1 && order.ID > 0 {
  2255. err := service.UpDateOrder(order)
  2256. if err == nil {
  2257. c.ServeSuccessJSON(map[string]interface{}{
  2258. "msg": "预结算成功",
  2259. "order_way": 1,
  2260. })
  2261. } else {
  2262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2263. return
  2264. }
  2265. } else if record.OutHospitalStatus == 0 && order.ID == 0 {
  2266. c.ServeSuccessJSON(map[string]interface{}{
  2267. "msg": "预结算成功",
  2268. "order": order,
  2269. "order_way": 2,
  2270. })
  2271. }
  2272. }
  2273. }
  2274. func (c *ZHHisApiController) GetUploadInfo() {
  2275. id, _ := c.GetInt64("id")
  2276. record_time := c.GetString("record_time")
  2277. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  2278. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2279. admin_user_id, _ := c.GetInt64("admin_user_id")
  2280. timeLayout := "2006-01-02"
  2281. loc, _ := time.LoadLocation("Local")
  2282. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2283. if err != nil {
  2284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2285. return
  2286. }
  2287. recordDateTime := theTime.Unix()
  2288. adminUser := c.GetAdminUserInfo()
  2289. var prescriptions []*models.HisPrescription
  2290. data := make(map[string]interface{})
  2291. if settle_accounts_type == 1 { //日结
  2292. prescriptions, _ = service.GetZHHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  2293. } else { //月结
  2294. start_time_str := c.GetString("start_time")
  2295. end_time_str := c.GetString("end_time")
  2296. timeLayout := "2006-01-02"
  2297. loc, _ := time.LoadLocation("Local")
  2298. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2299. if err != nil {
  2300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2301. return
  2302. }
  2303. recordStartTime := theStartTime.Unix()
  2304. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2305. if err != nil {
  2306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2307. return
  2308. }
  2309. recordEndTime := theEndTime.Unix()
  2310. prescriptions, _ = service.GetZHMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  2311. }
  2312. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2313. record, _ := service.GetInHospitalRecord(in_hospital_id)
  2314. if record.ID == 0 {
  2315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2316. return
  2317. }
  2318. timestamp := time.Now().Unix()
  2319. tempTime := time.Unix(timestamp, 0)
  2320. timeFormat := tempTime.Format("20060102150405")
  2321. chrgBchno := rand.Intn(100000) + 10000
  2322. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(record.PatientId, 10)
  2323. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2324. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2325. department, _ := service.GetDepartMentDetail(record.Departments)
  2326. strconv.FormatInt(record.PatientId, 10)
  2327. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.Creator)
  2328. //client := &http.Client{}
  2329. data["psn_no"] = record.PsnNo
  2330. data["mdtrt_id"] = record.Number
  2331. data["chrg_bchno"] = chrg_bchno
  2332. data["org_name"] = miConfig.OrgName
  2333. data["doctor"] = roles.UserName
  2334. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  2335. data["dept"] = strconv.FormatInt(department.ID, 10)
  2336. data["fixmedins_code"] = miConfig.Code
  2337. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  2338. data["dept_code"] = "15"
  2339. } else {
  2340. data["dept_code"] = department.Number
  2341. }
  2342. if miConfig.Code == "H15049901371" {
  2343. if record.MedType == 14 {
  2344. if record.InsutypeType == "390" {
  2345. data["med_type"] = ""
  2346. } else if record.InsutypeType == "310" {
  2347. data["med_type"] = ""
  2348. }
  2349. } else if record.MedType == 11 {
  2350. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  2351. }
  2352. } else {
  2353. if record.MedType == 1112 {
  2354. data["med_type"] = strconv.FormatInt(11, 10)
  2355. } else {
  2356. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  2357. }
  2358. }
  2359. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  2360. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  2361. data["secret_key"] = miConfig.SecretKey
  2362. var ids []int64
  2363. fmt.Println(data)
  2364. for _, item := range prescriptions {
  2365. ids = append(ids, item.ID)
  2366. }
  2367. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2368. if config.IsOpen == 1 { //对接了医保,走医保流程
  2369. var pagesize int = 100
  2370. var start int = 1
  2371. var stop int
  2372. var pagecount int
  2373. var curpage int
  2374. var isSuccess bool = true
  2375. var customs []*models.NewCustom
  2376. for _, item := range prescriptions {
  2377. tm := time.Unix(item.PreTime, 0)
  2378. if item.Type == 1 { //药品
  2379. for _, subItem := range item.HisDoctorAdviceInfo {
  2380. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 && subItem.BaseDrugLib.IsUser != 1 {
  2381. //var randNum int
  2382. //randNum = rand.Intn(10000) + 1000
  2383. cus := &models.NewCustom{
  2384. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  2385. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  2386. FeedetlSn: subItem.FeedetlSn,
  2387. Price: fmt.Sprintf("%.4f", subItem.Price),
  2388. MedListCodg: subItem.BaseDrugLib.MedicalInsuranceNumber,
  2389. HospApprFlag: subItem.BaseDrugLib.HospApprFlag,
  2390. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  2391. DoctorId: item.Creator,
  2392. }
  2393. customs = append(customs, cus)
  2394. }
  2395. }
  2396. }
  2397. if item.Type == 2 { //项目
  2398. for _, subItem := range item.HisPrescriptionProject {
  2399. //var randNum int
  2400. //randNum = rand.Intn(10000) + 1000
  2401. if subItem.Type == 2 {
  2402. if len(subItem.HisProject.MedicalCode) > 0 {
  2403. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  2404. cus := &models.NewCustom{
  2405. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  2406. Cut: fmt.Sprintf("%.4f", cnt),
  2407. FeedetlSn: subItem.FeedetlSn,
  2408. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  2409. MedListCodg: subItem.HisProject.MedicalCode,
  2410. HospApprFlag: -1,
  2411. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  2412. DoctorId: item.Creator,
  2413. }
  2414. customs = append(customs, cus)
  2415. }
  2416. } else if subItem.Type == 3 {
  2417. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 && subItem.GoodInfo.IsUser != 1 {
  2418. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  2419. cus := &models.NewCustom{
  2420. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  2421. Cut: fmt.Sprintf("%.4f", cnt),
  2422. FeedetlSn: subItem.FeedetlSn,
  2423. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  2424. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  2425. HospApprFlag: -1,
  2426. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  2427. DoctorId: item.Creator,
  2428. }
  2429. customs = append(customs, cus)
  2430. }
  2431. }
  2432. }
  2433. }
  2434. }
  2435. //总页数,向上取整,注意除之前要先转换类型为float64
  2436. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  2437. var ress []*ResultFour
  2438. for curpage = 1; curpage <= pagecount; curpage++ {
  2439. if curpage == 1 {
  2440. start = 1
  2441. } else {
  2442. start = (curpage-1)*pagesize + 1
  2443. }
  2444. stop = curpage * pagesize
  2445. if stop > len(customs) {
  2446. stop = len(customs)
  2447. }
  2448. var result string
  2449. var requestLog string
  2450. if miConfig.MdtrtareaAdmvs == "150499" {
  2451. data := make(map[string]interface{})
  2452. if record.MedType == 14 {
  2453. if record.InsutypeType == "390" {
  2454. data["med_type"] = "9933"
  2455. } else if record.InsutypeType == "310" {
  2456. data["med_type"] = "990502"
  2457. }
  2458. } else if record.MedType == 11 {
  2459. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  2460. }
  2461. data["psn_no"] = record.PsnNo
  2462. data["number"] = record.Number
  2463. data["customs"] = customs[start-1 : stop]
  2464. data["chrg_bchno"] = chrg_bchno
  2465. data["dept"] = strconv.FormatInt(department.ID, 10)
  2466. data["dept_code"] = department.Number
  2467. data["doctor_code"] = doctor_info.DoctorNumber
  2468. data["doctor_name"] = doctor_info.UserName
  2469. data["org_name"] = miConfig.OrgName
  2470. data["opertor"] = roles.UserName
  2471. data["fixmedins_code"] = miConfig.Code
  2472. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  2473. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  2474. data["secret_key"] = miConfig.SecretKey
  2475. var req *http.Request
  2476. bytesData, _ := json.Marshal(data)
  2477. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2301", bytes.NewReader(bytesData))
  2478. client := &http.Client{}
  2479. resp, _ := client.Do(req)
  2480. defer resp.Body.Close()
  2481. body, ioErr := ioutil.ReadAll(resp.Body)
  2482. if ioErr != nil {
  2483. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2485. return
  2486. }
  2487. var respJSON map[string]interface{}
  2488. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  2489. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2491. return
  2492. }
  2493. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2494. result_byte, _ := json.Marshal(respJSON)
  2495. result = string(result_byte)
  2496. } else {
  2497. 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), doctor_info.UserName, doctor_info.DoctorNumber)
  2498. saveLog(result, requestLog, "2301", "上传明细")
  2499. }
  2500. var dat map[string]interface{}
  2501. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2502. fmt.Println(dat)
  2503. } else {
  2504. fmt.Println(err)
  2505. }
  2506. userJSONBytes, _ := json.Marshal(dat)
  2507. var res ResultFour
  2508. var resFour10265 ResultFour10265
  2509. if miConfig.Code == "H15049901371" {
  2510. if err := json.Unmarshal(userJSONBytes, &resFour10265); err != nil {
  2511. utils.ErrorLog("解析失败:%v", err)
  2512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2513. return
  2514. }
  2515. res.WarnMsg = resFour10265.WarnMsg
  2516. res.Output = resFour10265.Output
  2517. res.ErrMsg = resFour10265.ErrMsg
  2518. res.RespondTime = resFour10265.RespondTime
  2519. res.InfRefmsgid = resFour10265.InfRefmsgid
  2520. Infcode, _ := strconv.ParseInt(resFour10265.Infcode, 10, 64)
  2521. res.Infcode = Infcode
  2522. } else {
  2523. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2524. utils.ErrorLog("解析失败:%v", err)
  2525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2526. return
  2527. }
  2528. }
  2529. if res.Infcode == 0 {
  2530. ress = append(ress, &res)
  2531. } else {
  2532. isSuccess = false
  2533. errlog := &models.HisOrderError{
  2534. UserOrgId: adminUser.CurrentOrgId,
  2535. Ctime: time.Now().Unix(),
  2536. Mtime: time.Now().Unix(),
  2537. Number: chrg_bchno,
  2538. ErrMsg: "",
  2539. Status: 1,
  2540. PatientId: id,
  2541. RecordTime: recordDateTime,
  2542. Stage: 4,
  2543. }
  2544. service.CreateErrMsgLog(errlog)
  2545. c.ServeSuccessJSON(map[string]interface{}{
  2546. "failed_code": -10,
  2547. "msg": "上传明细错误,请联系his厂商",
  2548. })
  2549. return
  2550. }
  2551. }
  2552. if isSuccess == true {
  2553. if settle_accounts_type == 1 {
  2554. for _, subItem := range ress {
  2555. for _, item := range subItem.Output.Result {
  2556. temp := strings.Split(item.FeedetlSn, "-")
  2557. var advice_id int64 = 0
  2558. var project_id int64 = 0
  2559. var types int64 = 0
  2560. id, _ := strconv.ParseInt(temp[2], 10, 64)
  2561. types, _ = strconv.ParseInt(temp[1], 10, 64)
  2562. if temp[1] == "1" {
  2563. advice_id = id
  2564. project_id = 0
  2565. } else if temp[1] == "2" {
  2566. advice_id = 0
  2567. project_id = id
  2568. }
  2569. info := &models.HisOrderInfo{
  2570. OrderNumber: record.Number,
  2571. FeedetlSn: item.FeedetlSn,
  2572. UploadDate: recordDateTime,
  2573. AdviceId: advice_id,
  2574. DetItemFeeSumamt: item.DetItemFeeSumamt,
  2575. Cnt: item.Cnt,
  2576. Pric: float64(item.Pric),
  2577. PatientId: record.PatientId,
  2578. PricUplmtAmt: item.PricUplmtAmt,
  2579. SelfpayProp: item.SelfpayProp,
  2580. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2581. OverlmtAmt: item.OverlmtAmt,
  2582. PreselfpayAmt: item.PreselfpayAmt,
  2583. BasMednFlag: item.BasMednFlag,
  2584. MedChrgitmType: item.MedChrgitmType,
  2585. HiNegoDrugFlag: item.HiNegoDrugFlag,
  2586. Status: 1,
  2587. Memo: item.Memo,
  2588. Mtime: time.Now().Unix(),
  2589. InscpScpAmt: item.InscpScpAmt,
  2590. DrtReimFlag: item.DrtReimFlag,
  2591. Ctime: time.Now().Unix(),
  2592. ListSpItemFlag: item.ListSpItemFlag,
  2593. ChldMedcFlag: item.ChldMedcFlag,
  2594. LmtUsedFlag: item.LmtUsedFlag,
  2595. ChrgitmLv: item.ChrgitmLv,
  2596. UserOrgId: adminUser.CurrentOrgId,
  2597. HisPatientId: record.ID,
  2598. OrderId: 0,
  2599. ProjectId: project_id,
  2600. Type: types,
  2601. SettleType: settle_accounts_type,
  2602. }
  2603. service.CreateOrderInfo(info)
  2604. }
  2605. }
  2606. err := service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  2607. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  2608. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  2609. if err == nil {
  2610. c.ServeSuccessJSON(map[string]interface{}{
  2611. "msg": "上传费用明细成功",
  2612. })
  2613. return
  2614. } else {
  2615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2616. return
  2617. }
  2618. } else {
  2619. for _, subItem := range ress {
  2620. for _, item := range subItem.Output.Result {
  2621. temp := strings.Split(item.FeedetlSn, "-")
  2622. var advice_id int64 = 0
  2623. var project_id int64 = 0
  2624. var types int64 = 0
  2625. id, _ := strconv.ParseInt(temp[2], 10, 64)
  2626. types, _ = strconv.ParseInt(temp[1], 10, 64)
  2627. if temp[1] == "1" {
  2628. advice_id = id
  2629. project_id = 0
  2630. } else if temp[1] == "2" {
  2631. advice_id = 0
  2632. project_id = id
  2633. }
  2634. info := &models.HisOrderInfo{
  2635. OrderNumber: record.Number,
  2636. FeedetlSn: item.FeedetlSn,
  2637. UploadDate: time.Now().Unix(),
  2638. AdviceId: advice_id,
  2639. DetItemFeeSumamt: item.DetItemFeeSumamt,
  2640. Cnt: item.Cnt,
  2641. Pric: float64(item.Pric),
  2642. PatientId: record.PatientId,
  2643. PricUplmtAmt: item.PricUplmtAmt,
  2644. SelfpayProp: item.SelfpayProp,
  2645. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2646. OverlmtAmt: item.OverlmtAmt,
  2647. PreselfpayAmt: item.PreselfpayAmt,
  2648. BasMednFlag: item.BasMednFlag,
  2649. MedChrgitmType: item.MedChrgitmType,
  2650. HiNegoDrugFlag: item.HiNegoDrugFlag,
  2651. Status: 1,
  2652. Memo: item.Memo,
  2653. Mtime: time.Now().Unix(),
  2654. InscpScpAmt: item.InscpScpAmt,
  2655. DrtReimFlag: item.DrtReimFlag,
  2656. Ctime: time.Now().Unix(),
  2657. ListSpItemFlag: item.ListSpItemFlag,
  2658. ChldMedcFlag: item.ChldMedcFlag,
  2659. LmtUsedFlag: item.LmtUsedFlag,
  2660. ChrgitmLv: item.ChrgitmLv,
  2661. UserOrgId: adminUser.CurrentOrgId,
  2662. HisPatientId: record.ID,
  2663. ProjectId: project_id,
  2664. Type: types,
  2665. SettleType: settle_accounts_type,
  2666. }
  2667. service.CreateOrderInfo(info)
  2668. }
  2669. }
  2670. service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  2671. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  2672. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  2673. c.ServeSuccessJSON(map[string]interface{}{
  2674. "msg": "上传费用明细成功",
  2675. })
  2676. }
  2677. }
  2678. }
  2679. }
  2680. func (c *ZHHisApiController) ZHRefund() {
  2681. order_id, _ := c.GetInt64("order_id")
  2682. admin_user_id, _ := c.GetInt64("admin_user_id")
  2683. adminUser := c.GetAdminUserInfo()
  2684. var order models.HisOrder
  2685. order, _ = service.GetHisOrderByID(order_id)
  2686. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  2687. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2688. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2689. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2690. if config.IsOpen == 1 { //对接了医保,走医保流程
  2691. var result string
  2692. var requestLog string
  2693. if miConfig.MdtrtareaAdmvs == "150499" {
  2694. //请求内网数据
  2695. api := "http://172.16.13.254:9532/" + "nmyb/2305?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo + "&setl_id=" + order.SetlId +
  2696. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2697. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2698. resp, requestErr := http.Get(api)
  2699. if requestErr != nil {
  2700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2701. return
  2702. }
  2703. body, ioErr := ioutil.ReadAll(resp.Body)
  2704. if ioErr != nil {
  2705. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2707. return
  2708. }
  2709. var respJSON map[string]interface{}
  2710. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2711. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2713. return
  2714. }
  2715. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2716. result_byte, _ := json.Marshal(respJSON)
  2717. result = string(result_byte)
  2718. //saveLog(result, requestLog, "2404", "入院登记撤销")
  2719. saveLog(result, requestLog, "2305", "退费")
  2720. } else {
  2721. result, requestLog := service.Gdyb2305(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2722. saveLog(result, requestLog, "2305", "退费")
  2723. }
  2724. var dat map[string]interface{}
  2725. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2726. fmt.Println(dat)
  2727. } else {
  2728. fmt.Println(err)
  2729. }
  2730. userJSONBytes, _ := json.Marshal(dat)
  2731. var res ResultSixteen
  2732. var resSixteen ResultSixteen10265
  2733. if miConfig.Code == "H15049901371" {
  2734. if err := json.Unmarshal(userJSONBytes, &resSixteen); err != nil {
  2735. utils.ErrorLog("解析失败:%v", err)
  2736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2737. return
  2738. }
  2739. res.Cainfo = resSixteen.Cainfo
  2740. res.WarnMsg = resSixteen.WarnMsg
  2741. res.Output = resSixteen.Output
  2742. res.ErrMsg = resSixteen.ErrMsg
  2743. res.RespondTime = resSixteen.RespondTime
  2744. Infcode, _ := strconv.ParseInt(resSixteen.Infcode, 10, 64)
  2745. res.Infcode = Infcode
  2746. } else {
  2747. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2748. utils.ErrorLog("解析失败:%v", err)
  2749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2750. return
  2751. }
  2752. }
  2753. if res.Infcode == 0 {
  2754. err := service.UpdataOrderStatusThree(order_id, order.Number, adminUser.CurrentOrgId, "", result)
  2755. //不同地区退费流程不一样,肇庆那边退费就包括撤销出院,内蒙古退费不包括撤销明细,所以下面需要根据不同情况进行判断
  2756. if miConfig.UserOrgId == 10215 {
  2757. record.OutHospitalStatus = 0
  2758. service.CreateHospitalRecord(&record)
  2759. }
  2760. service.UpdataOrderStatusByNumber(record.Number)
  2761. if err == nil {
  2762. ////当押金不为零时产生退费记录
  2763. if order.Decimal != 0 {
  2764. tmp := strconv.FormatInt(order.ID, 10)
  2765. err = service.MoneyIncrease(adminUser.CurrentOrgId, order.PatientId, tmp, order.Decimal)
  2766. if err != nil {
  2767. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2768. return
  2769. }
  2770. }
  2771. c.ServeSuccessJSON(map[string]interface{}{
  2772. "msg": "退费成功",
  2773. })
  2774. } else {
  2775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2776. return
  2777. }
  2778. } else {
  2779. c.ServeSuccessJSON(map[string]interface{}{
  2780. "code": -10,
  2781. "msg": res.ErrMsg,
  2782. })
  2783. }
  2784. } else {
  2785. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  2786. if err == nil {
  2787. c.ServeSuccessJSON(map[string]interface{}{
  2788. "msg": "退费成功",
  2789. })
  2790. } else {
  2791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2792. return
  2793. }
  2794. }
  2795. }
  2796. func (c *ZHHisApiController) ZHRefundDetail() {
  2797. patient_id, _ := c.GetInt64("patient_id")
  2798. his_patient_id, _ := c.GetInt64("his_patient_id")
  2799. record_time := c.GetString("record_time")
  2800. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2801. //order_id, _ := c.GetInt64("order_id")
  2802. admin_user_id, _ := c.GetInt64("admin_user_id")
  2803. timeLayout := "2006-01-02"
  2804. loc, _ := time.LoadLocation("Local")
  2805. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2806. if err != nil {
  2807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2808. return
  2809. }
  2810. recordDateTime := theTime.Unix()
  2811. adminUser := c.GetAdminUserInfo()
  2812. theTimeTwo, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 23:59:59", loc)
  2813. if err != nil {
  2814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2815. return
  2816. }
  2817. recordDateTimeTwo := theTimeTwo.Unix()
  2818. //var prescriptions []*models.HisPrescription
  2819. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2820. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2821. if settle_accounts_type == 1 { //日结
  2822. record, _ := service.GetInHospitalRecord(his_patient_id)
  2823. infos, _ := service.GetZHHisUploadOrderInfo(adminUser.CurrentOrgId, patient_id, recordDateTime, recordDateTimeTwo, record.Number)
  2824. var isSuccess bool = true
  2825. for _, item := range infos {
  2826. var result string
  2827. var requestLog string
  2828. if miConfig.MdtrtareaAdmvs == "150499" {
  2829. //请求内网数据
  2830. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&feedetl_sn=" + item.FeedetlSn +
  2831. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2832. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "1"
  2833. resp, requestErr := http.Get(api)
  2834. if requestErr != nil {
  2835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2836. return
  2837. }
  2838. body, ioErr := ioutil.ReadAll(resp.Body)
  2839. if ioErr != nil {
  2840. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2842. return
  2843. }
  2844. var respJSON map[string]interface{}
  2845. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2846. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2848. return
  2849. }
  2850. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2851. result_byte, _ := json.Marshal(respJSON)
  2852. result = string(result_byte)
  2853. saveLog(result, requestLog, "2302", "日结退明细")
  2854. } else {
  2855. result, requestLog := service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, item.FeedetlSn, 1)
  2856. saveLog(result, requestLog, "2302", "日结退明细")
  2857. }
  2858. var dat map[string]interface{}
  2859. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2860. fmt.Println(dat)
  2861. } else {
  2862. fmt.Println(err)
  2863. }
  2864. userJSONBytes, _ := json.Marshal(dat)
  2865. var res2 ResultEmpty
  2866. var resEmpty10265 ResultEmpty10265
  2867. if miConfig.Code == "H15049901371" {
  2868. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2869. utils.ErrorLog("解析失败:%v", err)
  2870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2871. return
  2872. }
  2873. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2874. res2.Infcode = Infcode
  2875. res2.RespondTime = resEmpty10265.RespondTime
  2876. res2.ErrMsg = resEmpty10265.ErrMsg
  2877. res2.Output = resEmpty10265.Output
  2878. res2.WarnMsg = resEmpty10265.WarnMsg
  2879. } else {
  2880. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2881. utils.ErrorLog("解析失败:%v", err)
  2882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2883. return
  2884. }
  2885. }
  2886. if res2.Infcode == -1 {
  2887. isSuccess = false
  2888. }
  2889. }
  2890. if isSuccess {
  2891. err := service.UpDateOrderInfoStatus(patient_id, recordDateTime, adminUser.CurrentOrgId, recordDateTimeTwo)
  2892. if err != nil {
  2893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2894. return
  2895. }
  2896. err1 := service.UpDatePrescriptionOrderStatusTwo(patient_id, recordDateTime, adminUser.CurrentOrgId)
  2897. if err1 != nil {
  2898. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2899. return
  2900. }
  2901. c.ServeSuccessJSON(map[string]interface{}{
  2902. "msg": "撤销明细成功",
  2903. })
  2904. }
  2905. } else {
  2906. //prescriptions, _ = service.GetZHMonthHisUploadPrescription(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2907. //var order models.HisOrder
  2908. //order, _ = service.GetHisOrderByID(order_id)
  2909. //record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  2910. var result string
  2911. var requestLog string
  2912. record, _ := service.GetInHospitalRecord(his_patient_id)
  2913. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2914. if config.IsOpen == 1 { //对接了医保,走医保流程
  2915. if miConfig.MdtrtareaAdmvs == "150499" {
  2916. //请求内网数据
  2917. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=0000" +
  2918. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2919. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "0"
  2920. resp, requestErr := http.Get(api)
  2921. if requestErr != nil {
  2922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2923. return
  2924. }
  2925. body, ioErr := ioutil.ReadAll(resp.Body)
  2926. if ioErr != nil {
  2927. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2929. return
  2930. }
  2931. var respJSON map[string]interface{}
  2932. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2933. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2934. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2935. return
  2936. }
  2937. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2938. result_byte, _ := json.Marshal(respJSON)
  2939. result = string(result_byte)
  2940. //saveLog(result, requestLog, "2302", "日结退明细")
  2941. } else {
  2942. result, requestLog = service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  2943. saveLog(result, requestLog, "2302", "月结退明细")
  2944. }
  2945. var dat map[string]interface{}
  2946. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2947. fmt.Println(dat)
  2948. } else {
  2949. fmt.Println(err)
  2950. }
  2951. userJSONBytes, _ := json.Marshal(dat)
  2952. var res2 ResultEmpty
  2953. var resEmpty10265 ResultEmpty10265
  2954. if miConfig.Code == "H15049901371" {
  2955. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2956. utils.ErrorLog("解析失败:%v", err)
  2957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2958. return
  2959. }
  2960. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2961. res2.Infcode = Infcode
  2962. res2.RespondTime = resEmpty10265.RespondTime
  2963. res2.ErrMsg = resEmpty10265.ErrMsg
  2964. res2.Output = resEmpty10265.Output
  2965. res2.WarnMsg = resEmpty10265.WarnMsg
  2966. } else {
  2967. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2968. utils.ErrorLog("解析失败:%v", err)
  2969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2970. return
  2971. }
  2972. }
  2973. if res2.Infcode == 0 {
  2974. err := service.UpdataHospitalOrderStatus(record.Number, adminUser.CurrentOrgId)
  2975. if err == nil {
  2976. c.ServeSuccessJSON(map[string]interface{}{
  2977. "msg": "撤销明细成功",
  2978. })
  2979. } else {
  2980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2981. return
  2982. }
  2983. } else {
  2984. c.ServeSuccessJSON(map[string]interface{}{
  2985. "code": -10,
  2986. "msg": res2.ErrMsg,
  2987. })
  2988. }
  2989. }
  2990. }
  2991. }
  2992. func (this *ZHHisApiController) GetZHOutHospitalUnCheck() {
  2993. id, _ := this.GetInt64("id")
  2994. admin_user_id, _ := this.GetInt64("admin_user_id")
  2995. adminInfo := this.GetAdminUserInfo()
  2996. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2997. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  2998. record, _ := service.GetInHospitalRecord(id)
  2999. if record.ID == 0 {
  3000. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  3001. return
  3002. }
  3003. var result string
  3004. var requestLog string
  3005. if miConfig.MdtrtareaAdmvs == "150499" {
  3006. //请求内网数据
  3007. api := "http://172.16.13.254:9532/" + "nmyb/2405?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  3008. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  3009. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3010. fmt.Println(api)
  3011. resp, requestErr := http.Get(api)
  3012. if requestErr != nil {
  3013. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3014. return
  3015. }
  3016. body, ioErr := ioutil.ReadAll(resp.Body)
  3017. if ioErr != nil {
  3018. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3019. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3020. return
  3021. }
  3022. var respJSON map[string]interface{}
  3023. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3024. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3025. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3026. return
  3027. }
  3028. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3029. result_byte, _ := json.Marshal(respJSON)
  3030. result = string(result_byte)
  3031. } else {
  3032. result, requestLog = service.ZHGdyb2405(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  3033. saveLog(result, requestLog, "2405", "出院登记撤销")
  3034. }
  3035. var dat map[string]interface{}
  3036. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3037. fmt.Println(dat)
  3038. } else {
  3039. fmt.Println(err)
  3040. }
  3041. userJSONBytes, _ := json.Marshal(dat)
  3042. var res ResultEmpty
  3043. var resEmpty10265 ResultEmpty10265
  3044. if miConfig.Code == "H15049901371" {
  3045. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  3046. utils.ErrorLog("解析失败:%v", err)
  3047. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3048. return
  3049. }
  3050. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  3051. res.Infcode = Infcode
  3052. res.RespondTime = resEmpty10265.RespondTime
  3053. res.ErrMsg = resEmpty10265.ErrMsg
  3054. res.Output = resEmpty10265.Output
  3055. res.WarnMsg = resEmpty10265.WarnMsg
  3056. } else {
  3057. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3058. utils.ErrorLog("解析失败:%v", err)
  3059. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3060. return
  3061. }
  3062. }
  3063. if res.Infcode == 0 {
  3064. record.OutHospitalStatus = 0
  3065. service.CreateHospitalRecord(&record)
  3066. service.UpdataOrderStatusByNumber(record.Number)
  3067. this.ServeSuccessJSON(map[string]interface{}{
  3068. "msg": "撤销出院成功",
  3069. })
  3070. } else {
  3071. this.ServeSuccessJSON(map[string]interface{}{
  3072. "failed_code": -10,
  3073. "msg": res.ErrMsg,
  3074. })
  3075. }
  3076. }
  3077. func (this *ZHHisApiController) GetZHInHospitalUnCheck() {
  3078. id, _ := this.GetInt64("id")
  3079. admin_user_id, _ := this.GetInt64("admin_user_id")
  3080. adminInfo := this.GetAdminUserInfo()
  3081. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  3082. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  3083. record, _ := service.GetInHospitalRecord(id)
  3084. if record.ID == 0 {
  3085. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  3086. return
  3087. }
  3088. var result string
  3089. var requestLog string
  3090. orders, _ := service.GetHisOrderInfoByNumber(record.Number)
  3091. if len(orders) > 0 { //判断是否上传过明细,有的话需要退明细,后撤销入院
  3092. if miConfig.MdtrtareaAdmvs == "150499" {
  3093. //请求内网数据
  3094. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=" + "0000" +
  3095. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  3096. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=0"
  3097. resp, requestErr := http.Get(api)
  3098. if requestErr != nil {
  3099. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3100. return
  3101. }
  3102. body, ioErr := ioutil.ReadAll(resp.Body)
  3103. if ioErr != nil {
  3104. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3105. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3106. return
  3107. }
  3108. var respJSON map[string]interface{}
  3109. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3110. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3111. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3112. return
  3113. }
  3114. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3115. result_byte, _ := json.Marshal(respJSON)
  3116. result = string(result_byte)
  3117. saveLog(result, requestLog, "2302", "月结退明细")
  3118. } else {
  3119. result, requestLog = service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  3120. saveLog(result, requestLog, "2302", "月结退明细")
  3121. }
  3122. var dat map[string]interface{}
  3123. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3124. fmt.Println(dat)
  3125. } else {
  3126. fmt.Println(err)
  3127. }
  3128. userJSONBytes, _ := json.Marshal(dat)
  3129. var res2 ResultEmpty
  3130. var resEmpty10265 ResultEmpty10265
  3131. if miConfig.Code == "H15049901371" {
  3132. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  3133. utils.ErrorLog("解析失败:%v", err)
  3134. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3135. return
  3136. }
  3137. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  3138. res2.Infcode = Infcode
  3139. res2.RespondTime = resEmpty10265.RespondTime
  3140. res2.ErrMsg = resEmpty10265.ErrMsg
  3141. res2.Output = resEmpty10265.Output
  3142. res2.WarnMsg = resEmpty10265.WarnMsg
  3143. } else {
  3144. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  3145. utils.ErrorLog("解析失败:%v", err)
  3146. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3147. return
  3148. }
  3149. }
  3150. if res2.Infcode == 0 {
  3151. service.UpdataHospitalOrderStatus(record.Number, adminInfo.CurrentOrgId)
  3152. var result string
  3153. var requestLog string
  3154. if miConfig.MdtrtareaAdmvs == "150499" {
  3155. //请求内网数据
  3156. api := "http://172.16.13.254:9532/" + "nmyb/2404?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  3157. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  3158. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3159. resp, requestErr := http.Get(api)
  3160. if requestErr != nil {
  3161. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3162. return
  3163. }
  3164. body, ioErr := ioutil.ReadAll(resp.Body)
  3165. if ioErr != nil {
  3166. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3167. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3168. return
  3169. }
  3170. var respJSON map[string]interface{}
  3171. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3172. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3173. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3174. return
  3175. }
  3176. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3177. result_byte, _ := json.Marshal(respJSON)
  3178. result = string(result_byte)
  3179. } else {
  3180. result, requestLog = service.ZHGdyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  3181. saveLog(result, requestLog, "2404", "入院登记撤销")
  3182. }
  3183. var dat map[string]interface{}
  3184. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3185. fmt.Println(dat)
  3186. } else {
  3187. fmt.Println(err)
  3188. }
  3189. userJSONBytes, _ := json.Marshal(dat)
  3190. var res ResultEmpty
  3191. var resEmpty10265 ResultEmpty10265
  3192. if miConfig.Code == "H15049901371" {
  3193. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  3194. utils.ErrorLog("解析失败:%v", err)
  3195. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3196. return
  3197. }
  3198. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  3199. res.Infcode = Infcode
  3200. res.RespondTime = resEmpty10265.RespondTime
  3201. res.ErrMsg = resEmpty10265.ErrMsg
  3202. res.Output = resEmpty10265.Output
  3203. res.WarnMsg = resEmpty10265.WarnMsg
  3204. } else {
  3205. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3206. utils.ErrorLog("解析失败:%v", err)
  3207. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3208. return
  3209. }
  3210. }
  3211. if res.Infcode == 0 {
  3212. record.Status = 0
  3213. service.CreateHospitalRecord(&record)
  3214. this.ServeSuccessJSON(map[string]interface{}{
  3215. "msg": "撤销入院成功",
  3216. })
  3217. } else {
  3218. this.ServeSuccessJSON(map[string]interface{}{
  3219. "failed_code": -10,
  3220. "msg": res.ErrMsg,
  3221. })
  3222. }
  3223. } else {
  3224. this.ServeSuccessJSON(map[string]interface{}{
  3225. "code": -10,
  3226. "msg": res2.ErrMsg,
  3227. })
  3228. }
  3229. } else { //没有上传过明细的,直接撤销入院
  3230. var result string
  3231. var requestLog string
  3232. if miConfig.MdtrtareaAdmvs == "150499" {
  3233. //请求内网数据
  3234. api := "http://172.16.13.254:9532/" + "nmyb/2404?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  3235. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  3236. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3237. resp, requestErr := http.Get(api)
  3238. if requestErr != nil {
  3239. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3240. return
  3241. }
  3242. body, ioErr := ioutil.ReadAll(resp.Body)
  3243. if ioErr != nil {
  3244. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3245. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3246. return
  3247. }
  3248. var respJSON map[string]interface{}
  3249. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3250. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3251. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3252. return
  3253. }
  3254. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3255. result_byte, _ := json.Marshal(respJSON)
  3256. result = string(result_byte)
  3257. } else {
  3258. result, requestLog = service.ZHGdyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  3259. saveLog(result, requestLog, "2404", "入院登记撤销")
  3260. }
  3261. var dat map[string]interface{}
  3262. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3263. fmt.Println(dat)
  3264. } else {
  3265. fmt.Println(err)
  3266. }
  3267. userJSONBytes, _ := json.Marshal(dat)
  3268. var res ResultEmpty
  3269. var resEmpty10265 ResultEmpty10265
  3270. if miConfig.Code == "H15049901371" {
  3271. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  3272. utils.ErrorLog("解析失败:%v", err)
  3273. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3274. return
  3275. }
  3276. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  3277. res.Infcode = Infcode
  3278. res.RespondTime = resEmpty10265.RespondTime
  3279. res.ErrMsg = resEmpty10265.ErrMsg
  3280. res.Output = resEmpty10265.Output
  3281. res.WarnMsg = resEmpty10265.WarnMsg
  3282. } else {
  3283. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3284. utils.ErrorLog("解析失败:%v", err)
  3285. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3286. return
  3287. }
  3288. }
  3289. if res.Infcode == 0 {
  3290. record.Status = 0
  3291. service.CreateHospitalRecord(&record)
  3292. this.ServeSuccessJSON(map[string]interface{}{
  3293. "msg": "撤销入院成功",
  3294. })
  3295. } else {
  3296. this.ServeSuccessJSON(map[string]interface{}{
  3297. "failed_code": -10,
  3298. "msg": res.ErrMsg,
  3299. })
  3300. }
  3301. }
  3302. }
  3303. func saveLog(result string, request string, infno string, desc string) {
  3304. org_id, _ := beego.AppConfig.Int64("org_id")
  3305. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  3306. dir := miConfig.OrgName + "日志"
  3307. utils.Mkdir(dir)
  3308. month := time.Unix(1557042972, 0).Format("1")
  3309. year := time.Now().Format("2006")
  3310. month = time.Now().Format("01")
  3311. day := time.Now().Format("02")
  3312. hour := time.Now().Format("15")
  3313. min := time.Now().Format("04")
  3314. sec := time.Now().Format("05")
  3315. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  3316. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  3317. file_name := file + ".txt"
  3318. file_path := miConfig.OrgName + "日志" + "/" + file_name
  3319. exist, _ := utils.PathExists(file_path)
  3320. if exist { //存在
  3321. fmt.Println("存在")
  3322. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  3323. if err != nil {
  3324. fmt.Println("read fail")
  3325. }
  3326. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  3327. n, _ := f.Seek(0, 2)
  3328. _, err = f.WriteAt([]byte(content), n)
  3329. } else { //不存在
  3330. fmt.Println("文件不存在,创建文件")
  3331. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  3332. defer f.Close()
  3333. if err != nil {
  3334. } else {
  3335. _, err = f.Write([]byte("记录日志"))
  3336. }
  3337. }
  3338. }
  3339. type Charset string
  3340. const (
  3341. UTF8 = Charset("UTF-8")
  3342. GB18030 = Charset("GB18030")
  3343. )
  3344. func ConvertToString(src string, srcCode string, tagCode string) string {
  3345. srcCoder := mahonia.NewDecoder(srcCode)
  3346. srcResult := srcCoder.ConvertString(src)
  3347. tagCoder := mahonia.NewDecoder(tagCode)
  3348. _, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
  3349. result := string(cdata)
  3350. return result
  3351. }
  3352. type ELeData struct {
  3353. Data struct {
  3354. IdNo string `json:"idNo"`
  3355. IdType string `json:"idType"`
  3356. UserName string `json:"userName"`
  3357. EcToken string `json:"ecToken"`
  3358. InsuOrg string `json:"insuOrg"`
  3359. Gender string `json:"gender"`
  3360. Birthday string `json:"birthday"`
  3361. Nationality string `json:"nationality"`
  3362. Email string `json:"email"`
  3363. Extra string `json:"extra"`
  3364. } `json:"data"`
  3365. Code int `json:"code"`
  3366. Message string `json:"message"`
  3367. }
  3368. var initFlagTwo int64 = 0
  3369. func (c *ZHHisApiController) ReadCard() {
  3370. id_card_type, _ := c.GetInt64("id_card_type")
  3371. admin_user_id, _ := c.GetInt64("admin_user_id")
  3372. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  3373. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  3374. switch id_card_type {
  3375. case 1: //社保卡
  3376. if miConfig.MdtrtareaAdmvs == "150499" {
  3377. var api string
  3378. api = "http://172.16.13.254:9532/" + "nmyb/readcard?" + "fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName +
  3379. "&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
  3380. fmt.Println(api)
  3381. resp, requestErr := http.Get(api)
  3382. if requestErr != nil {
  3383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3384. return
  3385. }
  3386. body, ioErr := ioutil.ReadAll(resp.Body)
  3387. if ioErr != nil {
  3388. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3390. return
  3391. }
  3392. var respJSON map[string]interface{}
  3393. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3394. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3396. return
  3397. }
  3398. var status string
  3399. status = respJSON["data"].(map[string]interface{})["status"].(string)
  3400. card_type := respJSON["data"].(map[string]interface{})["type"].(string)
  3401. //console.log()
  3402. fmt.Println("type===")
  3403. fmt.Println(card_type)
  3404. var token string
  3405. var res ResultTwo //1101结果
  3406. var res10265 ResultTwo10265 //1101结果
  3407. var card_info string //卡信息
  3408. var busi_card_info string
  3409. card_info = respJSON["data"].(map[string]interface{})["card_info"].(string)
  3410. busi_card_info = respJSON["data"].(map[string]interface{})["busi_card_info"].(string)
  3411. if status == "0" { //读卡成功
  3412. if card_type == "1" {
  3413. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  3414. result, _ := json.Marshal(respJSON)
  3415. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  3416. utils.ErrorLog("解析失败:%v", err)
  3417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3418. return
  3419. }
  3420. res.ErrMsg = res10265.ErrMsg
  3421. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  3422. res.Infcode = infocode
  3423. res.Output = res10265.Output
  3424. res.InfRefmsgid = res10265.InfRefmsgid
  3425. } else {
  3426. //var card_info string //卡信息
  3427. //var busi_card_info string
  3428. token = respJSON["data"].(map[string]interface{})["token"].(string)
  3429. //busi_card_info = respJSON["data"].(map[string]interface{})["busi_card_info"].(string)
  3430. //fmt.Println(card_info)
  3431. //fmt.Println(busi_card_info)
  3432. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  3433. result, _ := json.Marshal(respJSON)
  3434. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  3435. utils.ErrorLog("解析失败:%v", err)
  3436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3437. return
  3438. }
  3439. res.ErrMsg = res10265.ErrMsg
  3440. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  3441. res.Infcode = infocode
  3442. res.Output = res10265.Output
  3443. res.InfRefmsgid = res10265.InfRefmsgid
  3444. }
  3445. if res.Infcode == 0 {
  3446. var insutypes []string
  3447. var insutype string
  3448. var is390 int = 0
  3449. var is310 int = 0
  3450. for _, item := range res.Output.Iinfo {
  3451. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  3452. insutypes = append(insutypes, item.Insutype)
  3453. }
  3454. }
  3455. if len(insutypes) == 1 {
  3456. insutype = insutypes[0]
  3457. } else {
  3458. for _, i := range insutypes {
  3459. if i == "390" {
  3460. is390 = 1
  3461. }
  3462. if i == "310" {
  3463. is310 = 1
  3464. }
  3465. }
  3466. }
  3467. if is390 == 1 {
  3468. insutype = "390"
  3469. }
  3470. if is310 == 1 {
  3471. insutype = "310"
  3472. }
  3473. if len(insutypes) == 0 {
  3474. insutype = "310"
  3475. }
  3476. patient, err := service.GetPatientByIDCard(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  3477. if err == gorm.ErrRecordNotFound {
  3478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  3479. return
  3480. } else if err != nil {
  3481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3482. return
  3483. } else {
  3484. if card_type == "1" {
  3485. bas := strings.Split(card_info, "|")
  3486. basNumber := bas[2]
  3487. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  3488. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  3489. infoStr := string(Iinfos)
  3490. idetinfoStr := string(Idetinfos)
  3491. psn := &models.HisPsn{
  3492. PsnNo: res.Output.Baseinfo.PsnNo,
  3493. Age: res.Output.Baseinfo.Age,
  3494. PatientId: patient.ID,
  3495. Certno: res.Output.Baseinfo.Certno,
  3496. Brdy: res.Output.Baseinfo.Brdy,
  3497. Gend: res.Output.Baseinfo.Gend,
  3498. Naty: res.Output.Baseinfo.Naty,
  3499. PsnCertType: res.Output.Baseinfo.PsnCertType,
  3500. PsnName: res.Output.Baseinfo.PsnName,
  3501. Idetinfo: idetinfoStr,
  3502. Insuinfo: infoStr,
  3503. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3504. CardInfo: card_info,
  3505. VerifyNumber: busi_card_info,
  3506. }
  3507. service.CreateHisPsn(psn)
  3508. c.ServeSuccessJSON(map[string]interface{}{
  3509. "patient": patient,
  3510. "number": basNumber,
  3511. "info": res,
  3512. "insutype": insutype,
  3513. })
  3514. } else {
  3515. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  3516. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  3517. infoStr := string(Iinfos)
  3518. idetinfoStr := string(Idetinfos)
  3519. psn := &models.HisPsn{
  3520. PsnNo: res.Output.Baseinfo.PsnNo,
  3521. Age: res.Output.Baseinfo.Age,
  3522. PatientId: patient.ID,
  3523. Certno: res.Output.Baseinfo.Certno,
  3524. Brdy: res.Output.Baseinfo.Brdy,
  3525. Gend: res.Output.Baseinfo.Gend,
  3526. Naty: res.Output.Baseinfo.Naty,
  3527. PsnCertType: res.Output.Baseinfo.PsnCertType,
  3528. PsnName: res.Output.Baseinfo.PsnName,
  3529. Idetinfo: idetinfoStr,
  3530. Insuinfo: infoStr,
  3531. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3532. CardInfo: card_info,
  3533. VerifyNumber: token,
  3534. }
  3535. service.CreateHisPsn(psn)
  3536. c.ServeSuccessJSON(map[string]interface{}{
  3537. "patient": patient,
  3538. "number": token,
  3539. "info": res,
  3540. "insutype": insutype,
  3541. })
  3542. }
  3543. }
  3544. } else {
  3545. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  3546. return
  3547. }
  3548. } else { //读卡失败
  3549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  3550. return
  3551. }
  3552. } else {
  3553. if initFlagTwo == 0 {
  3554. c.TestGetBasBaseInitTwo()
  3555. }
  3556. basStr := c.GetBasBaseInfoTwo()
  3557. if len(basStr) == 0 {
  3558. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  3559. return
  3560. }
  3561. fmt.Println(basStr)
  3562. bas := strings.Split(basStr, "|")
  3563. id_card_no := bas[1]
  3564. result, _ := service.ZHGdyb1101B(id_card_no, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 1, "", 1, "")
  3565. //result := service.Gdyb1101B(basNumber, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, card_sn, certificates)
  3566. var dat map[string]interface{}
  3567. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3568. fmt.Println(dat)
  3569. } else {
  3570. fmt.Println(err)
  3571. }
  3572. userJSONBytes, _ := json.Marshal(dat)
  3573. var res ResultTwo
  3574. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3575. utils.ErrorLog("解析失败:%v", err)
  3576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3577. return
  3578. }
  3579. if res.Infcode == 0 {
  3580. patient, err := service.GetPatientByNumber(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  3581. if err == gorm.ErrRecordNotFound {
  3582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  3583. return
  3584. } else if err != nil {
  3585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3586. return
  3587. } else {
  3588. var insutypes []string
  3589. var insutype string
  3590. var is390 int = 0
  3591. var is310 int = 0
  3592. for _, item := range res.Output.Iinfo {
  3593. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  3594. insutypes = append(insutypes, item.Insutype)
  3595. }
  3596. }
  3597. if len(insutypes) == 1 {
  3598. insutype = insutypes[0]
  3599. } else {
  3600. for _, i := range insutypes {
  3601. if i == "390" {
  3602. is390 = 1
  3603. }
  3604. if i == "310" {
  3605. is310 = 1
  3606. }
  3607. }
  3608. }
  3609. if is390 == 1 {
  3610. insutype = "390"
  3611. }
  3612. if is310 == 1 {
  3613. insutype = "310"
  3614. }
  3615. if len(insutypes) == 0 {
  3616. insutype = "310"
  3617. }
  3618. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  3619. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  3620. infoStr := string(Iinfos)
  3621. idetinfoStr := string(Idetinfos)
  3622. psn := &models.HisPsn{
  3623. PsnNo: res.Output.Baseinfo.PsnNo,
  3624. Age: res.Output.Baseinfo.Age,
  3625. PatientId: patient.ID,
  3626. Certno: res.Output.Baseinfo.Certno,
  3627. Brdy: res.Output.Baseinfo.Brdy,
  3628. Gend: res.Output.Baseinfo.Gend,
  3629. Naty: res.Output.Baseinfo.Naty,
  3630. PsnCertType: res.Output.Baseinfo.PsnCertType,
  3631. PsnName: res.Output.Baseinfo.PsnName,
  3632. Idetinfo: idetinfoStr,
  3633. Insuinfo: infoStr,
  3634. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3635. CardInfo: basStr,
  3636. VerifyNumber: "",
  3637. }
  3638. service.CreateHisPsn(psn)
  3639. c.ServeSuccessJSON(map[string]interface{}{
  3640. "patient": patient,
  3641. "number": id_card_no,
  3642. "info": res,
  3643. "insutype": insutype,
  3644. })
  3645. }
  3646. } else {
  3647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  3648. return
  3649. }
  3650. }
  3651. break
  3652. case 4: //电子凭证
  3653. if miConfig.MdtrtareaAdmvs == "150499" {
  3654. var api string
  3655. api = "http://172.16.13.254:9532/" + "nmyb/readcard?" + "fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName +
  3656. "&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
  3657. resp, requestErr := http.Get(api)
  3658. if requestErr != nil {
  3659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3660. return
  3661. }
  3662. body, ioErr := ioutil.ReadAll(resp.Body)
  3663. if ioErr != nil {
  3664. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3666. return
  3667. }
  3668. var respJSON map[string]interface{}
  3669. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3670. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3672. return
  3673. }
  3674. var status string
  3675. status = respJSON["data"].(map[string]interface{})["status"].(string)
  3676. //card_type := respJSON["data"].(map[string]interface{})["type"].(string)
  3677. var token string
  3678. var res ResultTwo //1101结果
  3679. var res10265 ResultTwo10265 //1101结果
  3680. if status == "0" { //读卡成功
  3681. token = respJSON["data"].(map[string]interface{})["token"].(string)
  3682. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  3683. result, _ := json.Marshal(respJSON)
  3684. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  3685. utils.ErrorLog("解析失败:%v", err)
  3686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3687. return
  3688. }
  3689. res.ErrMsg = res10265.ErrMsg
  3690. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  3691. res.Infcode = infocode
  3692. res.Output = res10265.Output
  3693. res.InfRefmsgid = res10265.InfRefmsgid
  3694. if res.Infcode == 0 {
  3695. c.ServeSuccessJSON(map[string]interface{}{
  3696. "number": token,
  3697. })
  3698. }
  3699. }
  3700. } else {
  3701. if initFlagTwo == 0 {
  3702. c.TestGetBasBaseInitTwo()
  3703. }
  3704. token := c.GetEleBaseInfoTwo()
  3705. token = Remove0000(token)
  3706. result2, requestLog2 := service.Gdyb1101ForEleCert(miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, token, "", "")
  3707. saveLog(result2, requestLog2, "1101", "获取人员信息")
  3708. //
  3709. var res ResultTwo
  3710. if err := json.Unmarshal([]byte(result2), &res); err != nil {
  3711. utils.ErrorLog("解析失败:%v", err)
  3712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3713. return
  3714. }
  3715. if res.Infcode == 0 {
  3716. patient, err := service.GetPatientByNumber(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  3717. if err == gorm.ErrRecordNotFound {
  3718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  3719. return
  3720. } else if err != nil {
  3721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3722. return
  3723. } else {
  3724. var insutypes []string
  3725. var insutype string
  3726. var is390 int = 0
  3727. var is310 int = 0
  3728. for _, item := range res.Output.Iinfo {
  3729. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  3730. insutypes = append(insutypes, item.Insutype)
  3731. }
  3732. }
  3733. if len(insutypes) == 1 {
  3734. insutype = insutypes[0]
  3735. } else {
  3736. for _, i := range insutypes {
  3737. if i == "390" {
  3738. is390 = 1
  3739. }
  3740. if i == "310" {
  3741. is310 = 1
  3742. }
  3743. }
  3744. }
  3745. if is390 == 1 {
  3746. insutype = "390"
  3747. }
  3748. if is310 == 1 {
  3749. insutype = "310"
  3750. }
  3751. if len(insutypes) == 0 {
  3752. insutype = "310"
  3753. }
  3754. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  3755. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  3756. infoStr := string(Iinfos)
  3757. idetinfoStr := string(Idetinfos)
  3758. psn := &models.HisPsn{
  3759. PsnNo: res.Output.Baseinfo.PsnNo,
  3760. Age: res.Output.Baseinfo.Age,
  3761. PatientId: patient.ID,
  3762. Certno: res.Output.Baseinfo.Certno,
  3763. Brdy: res.Output.Baseinfo.Brdy,
  3764. Gend: res.Output.Baseinfo.Gend,
  3765. Naty: res.Output.Baseinfo.Naty,
  3766. PsnCertType: res.Output.Baseinfo.PsnCertType,
  3767. PsnName: res.Output.Baseinfo.PsnName,
  3768. Idetinfo: idetinfoStr,
  3769. Insuinfo: infoStr,
  3770. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3771. CardInfo: "",
  3772. VerifyNumber: token,
  3773. }
  3774. service.CreateHisPsn(psn)
  3775. c.ServeSuccessJSON(map[string]interface{}{
  3776. "patient": patient,
  3777. "number": token,
  3778. "info": res,
  3779. "insutype": insutype,
  3780. })
  3781. }
  3782. } else {
  3783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  3784. return
  3785. }
  3786. }
  3787. break
  3788. }
  3789. }
  3790. func (c *ZHHisApiController) GetEleBaseInfoTwo() string {
  3791. DllDef := syscall.MustLoadDLL("SSCard.dll")
  3792. readCard := DllDef.MustFindProc("GetQRBase")
  3793. fmt.Println(readCard)
  3794. if readCard == nil {
  3795. fmt.Println("readcard is nil")
  3796. readCard = DllDef.MustFindProc("GetQRBase")
  3797. }
  3798. str := make([]byte, 1024)
  3799. str1 := make([]byte, 1024)
  3800. ret2, _, _ := readCard.Call(uintptr(180), (uintptr)(unsafe.Pointer(&str[0])), uintptr(1024), (uintptr)(unsafe.Pointer(&str1[0])), uintptr(1024))
  3801. fmt.Println(ret2)
  3802. fmt.Println(string(str1))
  3803. fmt.Println(string(str))
  3804. fmt.Println(":", ConvertToString(string(str1), "gbk", "utf-8"))
  3805. fmt.Println(":", ConvertToString(string(str), "gbk", "utf-8"))
  3806. if ret2 != 0 {
  3807. return ""
  3808. }
  3809. return string(str)
  3810. }
  3811. func (c *ZHHisApiController) TestGetBasBaseInitTwo() {
  3812. DllDef := syscall.MustLoadDLL("SSCard.dll")
  3813. Iinit := DllDef.MustFindProc("Init")
  3814. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  3815. ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_api/prd/api/card/initDll"), StrPtr(miConfig.MdtrtareaAdmvs))
  3816. if ret != 0 {
  3817. fmt.Println("SSCard的报错原因:", err)
  3818. fmt.Println("SSCard的运算结果为:", ret)
  3819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  3820. return
  3821. }
  3822. result := int(ret)
  3823. fmt.Println("SSCard的运算结果为1:", result)
  3824. initFlagTwo = 1
  3825. return
  3826. }
  3827. func (c *ZHHisApiController) GetBasBaseInfoTwo() string {
  3828. DllDef := syscall.MustLoadDLL("SSCard.dll")
  3829. readCard := DllDef.MustFindProc("ReadCardBas")
  3830. if readCard == nil {
  3831. fmt.Println("readcard is nil")
  3832. readCard = DllDef.MustFindProc("ReadCardBas")
  3833. }
  3834. str := make([]byte, 1024)
  3835. str1 := make([]byte, 1024)
  3836. ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), uintptr(1024), (uintptr)(unsafe.Pointer(&str1[0])), uintptr(1024))
  3837. fmt.Println(string(str1))
  3838. fmt.Println(string(str))
  3839. fmt.Println(":", ConvertToString(string(str1), "gbk", "utf-8"))
  3840. fmt.Println(":", ConvertToString(string(str), "gbk", "utf-8"))
  3841. if ret2 != 0 {
  3842. return ""
  3843. }
  3844. return string(str)
  3845. }
  3846. var initFlag int64 = 0
  3847. func (c *ZHHisApiController) TestGetBasBaseInit() {
  3848. DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
  3849. Iinit := DllDef.MustFindProc("Init")
  3850. //miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  3851. str := make([]byte, 2048)
  3852. inputData := make(map[string]interface{})
  3853. inputData["IP"] = "10.144.211.75"
  3854. inputData["PORT"] = 7021
  3855. inputData["TIMEOUT"] = 180
  3856. inputData["LOG_PATH"] = "C:\\log\\"
  3857. //inputData["SFZ_DRIVER_TYPE"] = 0
  3858. inputData["URL"] = "/call1"
  3859. bytesData, _ := json.Marshal(inputData)
  3860. fmt.Println(inputData)
  3861. fmt.Println(bytesData)
  3862. ret, _, err := Iinit.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&str[0])))
  3863. if ret != 0 {
  3864. fmt.Println("SSCard的报错原因:", err)
  3865. fmt.Println("SSCard的运算结果为:", ret)
  3866. fmt.Println("SSCard的返回结果为:", string(str))
  3867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  3868. return
  3869. }
  3870. fmt.Println("SSCard的返回结果为:", string(str))
  3871. result := int(ret)
  3872. fmt.Println("SSCard的运算结果为1:", result)
  3873. //initFlag = 1
  3874. return
  3875. }
  3876. func (c *ZHHisApiController) GetSFZBaseInfo() string {
  3877. DllDef := syscall.MustLoadDLL("SSCard.dll")
  3878. readCard := DllDef.MustFindProc("ReadSFZ")
  3879. if readCard == nil {
  3880. fmt.Println("readcard is nil")
  3881. readCard = DllDef.MustFindProc("ReadSFZ")
  3882. }
  3883. str := make([]byte, 256)
  3884. str1 := make([]byte, 256)
  3885. r, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  3886. fmt.Println(r)
  3887. return string(str)
  3888. }
  3889. func (c *ZHHisApiController) GetBasBaseInfo(fixmedins_code string, mdtrtarea_admvs string, opter_name string, opter_id string, fixmedins_name string) string {
  3890. DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
  3891. readCard := DllDef.MustFindProc("ReadCardBas")
  3892. fmt.Println(readCard)
  3893. fmt.Println("!!!!!")
  3894. month := time.Unix(1557042972, 0).Format("1")
  3895. year := time.Now().Format("2006")
  3896. month = time.Now().Format("01")
  3897. day := time.Now().Format("02")
  3898. hour := time.Now().Format("15")
  3899. min := time.Now().Format("04")
  3900. sec := time.Now().Format("05")
  3901. msec := time.Now().Format("000")
  3902. timestamp := time.Now().Unix()
  3903. tempTime := time.Unix(timestamp, 0)
  3904. //timeFormat := tempTime.Format("20060102150405")
  3905. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  3906. //randNum := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000)
  3907. inputData := make(map[string]interface{})
  3908. inputData["infno"] = "1199"
  3909. //inputData["msgid"] = "7021"
  3910. inputData["msgid"] = fixmedins_code + year + month + day + hour + min + sec + msec + "0" // 发送方报文 ID
  3911. inputData["mdtrtarea_admvs"] = mdtrtarea_admvs // 发送方报文 ID
  3912. inputData["recer_sys_code"] = "01"
  3913. inputData["infver"] = "V1.0"
  3914. inputData["opter_type"] = "1"
  3915. inputData["opter"] = opter_id
  3916. inputData["opter_name"] = opter_name
  3917. inputData["inf_time"] = timeFormatOne
  3918. inputData["fixmedins_code"] = fixmedins_code
  3919. inputData["fixmedins_name"] = fixmedins_name
  3920. inputData["dev_no"] = ""
  3921. inputData["dev_safe_info"] = ""
  3922. inputData["cainfo"] = ""
  3923. inputData["signtype"] = ""
  3924. inputData["sign_no"] = ""
  3925. bytesData, _ := json.Marshal(inputData)
  3926. fmt.Println(string(bytesData))
  3927. pBusiCardInfo := make([]byte, 8192)
  3928. ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
  3929. fmt.Println(ret2)
  3930. fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
  3931. fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
  3932. if ret2 != 0 {
  3933. return ""
  3934. }
  3935. return DeleteExtraSpace(string(pBusiCardInfo))
  3936. }
  3937. func DeleteExtraSpace(s string) string {
  3938. //删除字符串中的多余空格,有多个空格时,仅保留一个空格
  3939. s1 := strings.Replace(s, " ", " ", -1) //替换tab为空格
  3940. regstr := "\\s{2,}" //两个及两个以上空格的正则表达式
  3941. reg, _ := regexp.Compile(regstr) //编译正则表达式
  3942. s2 := make([]byte, len(s1)) //定义字符数组切片
  3943. copy(s2, s1) //将字符串复制到切片
  3944. spc_index := reg.FindStringIndex(string(s2)) //在字符串中搜索
  3945. for len(spc_index) > 0 { //找到适配项
  3946. s2 = append(s2[:spc_index[0]+1], s2[spc_index[1]:]...) //删除多余空格
  3947. spc_index = reg.FindStringIndex(string(s2)) //继续在字符串中搜索
  3948. }
  3949. return string(s2)
  3950. }
  3951. func (c *ZHHisApiController) GetELeInfo(code string, operator_id string, operator_name string) (string, string) {
  3952. DllDef := syscall.MustLoadDLL("NationECCode.dll")
  3953. readCard := DllDef.MustFindProc("NationEcTrans")
  3954. fmt.Println(readCard)
  3955. fmt.Println("!!!!!")
  3956. pBusiCardInfo := make([]byte, 8192)
  3957. input := make(map[string]interface{})
  3958. inputData := make(map[string]interface{})
  3959. inputData["orgId"] = code
  3960. inputData["businessType"] = "01101"
  3961. inputData["operatorId"] = operator_id
  3962. inputData["operatorName"] = operator_name
  3963. inputData["officeId"] = "001"
  3964. inputData["officeName"] = "血透室"
  3965. inputData["deviceType"] = ""
  3966. input["data"] = inputData
  3967. input["orgId"] = code
  3968. input["transType"] = "ec.query"
  3969. bytesData, _ := json.Marshal(input)
  3970. gdyb_url := beego.AppConfig.String("gdyb_url")
  3971. url := gdyb_url + "/localcfc/api/hsecfc/localQrCodeQuery"
  3972. ret2, _, _ := readCard.Call(StrPtr(url), StrPtr(string(bytesData)), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
  3973. fmt.Println(ret2)
  3974. fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
  3975. fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
  3976. if ret2 != 0 {
  3977. return "", ""
  3978. }
  3979. return DeleteExtraSpace(""), DeleteExtraSpace(string(pBusiCardInfo))
  3980. }
  3981. func StrPtr(s string) uintptr {
  3982. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  3983. }
  3984. func Remove0000(s string) string {
  3985. str := make([]rune, 0, len(s))
  3986. for _, v := range []rune(s) {
  3987. if v == 0 {
  3988. continue
  3989. }
  3990. str = append(str, v)
  3991. }
  3992. return string(str)
  3993. }
  3994. func IntPtr(n int) uintptr {
  3995. return uintptr(n)
  3996. }