zh_his_api_controller.go 180KB

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