zh_his_api_controller.go 183KB

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