his_api_controller.go 211KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160
  1. package sg
  2. import (
  3. "archive/zip"
  4. "bytes"
  5. "encoding/json"
  6. "fmt"
  7. "gdyb/controllers"
  8. "gdyb/enums"
  9. "gdyb/models"
  10. "gdyb/service"
  11. "gdyb/utils"
  12. "github.com/astaxie/beego"
  13. "github.com/jinzhu/gorm"
  14. //"github.com/jinzhu/gorm"
  15. "github.com/shopspring/decimal"
  16. "io"
  17. "io/ioutil"
  18. "math/rand"
  19. "net/http"
  20. "os"
  21. "path/filepath"
  22. "strconv"
  23. "strings"
  24. "syscall"
  25. "time"
  26. "unsafe"
  27. )
  28. type HisApiController struct {
  29. controllers.BaseAuthAPIController
  30. }
  31. func HisManagerApiRegistRouters() {
  32. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  33. beego.Router("/api/diag/upload", &HisApiController{}, "get:GetUploadDiag")
  34. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  35. beego.Router("/api/settle/query", &HisApiController{}, "get:GetSettleAccounts")
  36. beego.Router("/api/checkaccount/get", &HisApiController{}, "get:GetCheckAccount")
  37. beego.Router("/api/checkdetailaccount/get", &HisApiController{}, "get:GetCheckDetailAccount")
  38. beego.Router("/api/refund/post", &HisApiController{}, "get:Refund")
  39. //beego.Router("/api/sscard", &HisApiController{}, "get:Sscard")
  40. beego.Router("/api/refundnumber/post", &HisApiController{}, "get:RefundNumber")
  41. beego.Router("/api/refunddetail/post", &HisApiController{}, "get:RefundDetail")
  42. beego.Router("/api/treatment/check", &HisApiController{}, "get:CheckTreatment")
  43. beego.Router("/api/record/put", &HisApiController{}, "get:PutRecord")
  44. //beego.Router("/api/patient/info", &HisApiController{}, "get:GetHisPatientInfo")
  45. beego.Router("/api/org/info", &HisApiController{}, "get:GetOrgInfo")
  46. //beego.Router("/api/testcard", &HisApiController{}, "get:TestGetBasBaseInfo")
  47. beego.Router("/api/readcard", &HisApiController{}, "get:ReadCard")
  48. //beego.Router("/api/testpay", &HisApiController{}, "get:TestPay")
  49. beego.Router("/api/presettle/get", &HisApiController{}, "get:GetPreUploadInfo")
  50. //beego.Router("/api/settle/get", &HisApiController{}, "get:GetSettleInfo")
  51. beego.Router("/api/310", &HisApiController{}, "get:Check310")
  52. beego.Router("/api/390", &HisApiController{}, "get:Check390")
  53. beego.Router("/api/patient/info", &HisApiController{}, "get:GetPatientInfo")
  54. //备案撤销相关接口
  55. beego.Router("/api/checkcode/get", &HisApiController{}, "get:GetCheckCode")
  56. beego.Router("/api/uncheckcode/get", &HisApiController{}, "get:UnCheckCode")
  57. beego.Router("/api/psn/putonrecord", &HisApiController{}, "get:PsnPutOnRecord")
  58. beego.Router("/api/psn/unputonrecord", &HisApiController{}, "get:PsnUnPutOnRecord")
  59. beego.Router("/api/psn/ncds/putonrecord", &HisApiController{}, "get:PsnPutNCDSOnRecord")
  60. beego.Router("/api/psn/ncds/unputonrecord", &HisApiController{}, "get:PsnPutUnNCDSOnRecord")
  61. beego.Router("/api/reversal", &HisApiController{}, "get:ReversalData")
  62. beego.Router("/api/reversal/other", &HisApiController{}, "get:ReversalOtherData")
  63. //beego.Router("/api/reversal/one", &HisApiController{}, "get:ReversalOtherOneData")
  64. beego.Router("/api/settlelist/get", &HisApiController{}, "get:GetSettleList")
  65. beego.Router("/api/pwd/check", &HisApiController{}, "get:CheckCardPWD")
  66. beego.Router("/api/insutype/check", &HisApiController{}, "get:CheckInsutype")
  67. //beego.Router("/api/settlelist/get", &HisApiController{}, "get:GetSettleList")
  68. //beego.Router("/api/testinit", &HisApiController{}, "get:TestGetBasBaseInit")
  69. //beego.Router("/api/test", &HisApiController{}, "get:TestGetBasBaseInfo")
  70. }
  71. func (c *HisApiController) CheckInsutype() {
  72. his_patient_id, _ := c.GetInt64("his_patient_id")
  73. admin_user_id, _ := c.GetInt64("admin_user_id")
  74. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  75. his, _ := service.GetNewHisPatientInfoFour(c.GetAdminUserInfo().CurrentOrgId, his_patient_id)
  76. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  77. result := service.Gdyb90100(his.PsnNo, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  78. var dat map[string]interface{}
  79. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  80. fmt.Println(dat)
  81. } else {
  82. fmt.Println(err)
  83. }
  84. userJSONBytes, _ := json.Marshal(dat)
  85. var res Result90100
  86. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  87. utils.ErrorLog("解析失败:%v", err)
  88. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  89. return
  90. }
  91. if res.Infcode != 0 {
  92. c.ServeSuccessJSON(map[string]interface{}{
  93. "failed_code": -10,
  94. "msg": res.ErrMsg,
  95. })
  96. return
  97. } else {
  98. fmt.Println(res)
  99. }
  100. }
  101. func (c *HisApiController) CheckCardPWD() {
  102. card_pwd := c.GetString("card_pwd")
  103. his_patient_id, _ := c.GetInt64("his_patient_id")
  104. admin_user_id, _ := c.GetInt64("admin_user_id")
  105. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  106. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  107. his, _ := service.GetNewHisPatientInfoFour(c.GetAdminUserInfo().CurrentOrgId, his_patient_id)
  108. result := service.Gdyb90991(his.PsnNo, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, card_pwd)
  109. var dat map[string]interface{}
  110. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  111. fmt.Println(dat)
  112. } else {
  113. fmt.Println(err)
  114. }
  115. userJSONBytes, _ := json.Marshal(dat)
  116. var res Result90991
  117. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  118. utils.ErrorLog("解析失败:%v", err)
  119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  120. return
  121. }
  122. if res.Infcode != 0 {
  123. c.ServeSuccessJSON(map[string]interface{}{
  124. "failed_code": -10,
  125. "msg": res.ErrMsg,
  126. })
  127. return
  128. } else {
  129. if res.Output.Result.CheckStat == "0" {
  130. var msg string
  131. switch res.Output.Result.CardStat {
  132. case "00":
  133. msg = "未激活"
  134. break
  135. case "10":
  136. msg = "激活"
  137. break
  138. case "20":
  139. msg = "窗口挂失"
  140. break
  141. case "21":
  142. msg = "电话挂失"
  143. break
  144. case "22":
  145. msg = "单位网上申报挂失"
  146. break
  147. case "23":
  148. msg = "保健办挂失"
  149. break
  150. case "24":
  151. msg = "个人网上挂失"
  152. break
  153. case "25":
  154. msg = "网上服务大厅挂失"
  155. break
  156. case "30":
  157. msg = "注销"
  158. break
  159. case "40":
  160. msg = "回收"
  161. break
  162. case "99":
  163. msg = "制卡中(无效卡)"
  164. break
  165. }
  166. c.ServeSuccessJSON(map[string]interface{}{
  167. "failed_code": -10,
  168. "msg": msg,
  169. })
  170. return
  171. } else {
  172. c.ServeSuccessJSON(map[string]interface{}{
  173. "msg": "校验成功",
  174. })
  175. return
  176. }
  177. }
  178. }
  179. func (c *HisApiController) ReadCard() {
  180. id_card_type, _ := c.GetInt64("id_card_type")
  181. admin_user_id, _ := c.GetInt64("admin_user_id")
  182. certificates, _ := c.GetInt64("certificates")
  183. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  184. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  185. if initFlag == 0 {
  186. c.TestGetBasBaseInit()
  187. }
  188. switch id_card_type {
  189. case 1:
  190. basStr := c.GetBasBaseInfo()
  191. if len(basStr) == 0 {
  192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  193. return
  194. }
  195. fmt.Println(basStr)
  196. bas := strings.Split(basStr, "|")
  197. basNumber := bas[1]
  198. fmt.Println(basNumber)
  199. card_sn := bas[3]
  200. fmt.Println(card_sn)
  201. result := service.Gdyb1101B(basNumber, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, card_sn, certificates)
  202. var dat map[string]interface{}
  203. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  204. fmt.Println(dat)
  205. } else {
  206. fmt.Println(err)
  207. }
  208. userJSONBytes, _ := json.Marshal(dat)
  209. var res ResultTwo
  210. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  211. utils.ErrorLog("解析失败:%v", err)
  212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  213. return
  214. }
  215. if res.Infcode == 0 {
  216. patient, err := service.GetPatientByNumber(basNumber, c.GetAdminUserInfo().CurrentOrgId)
  217. if err == gorm.ErrRecordNotFound {
  218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  219. return
  220. } else if err != nil {
  221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  222. return
  223. } else {
  224. c.ServeSuccessJSON(map[string]interface{}{
  225. "patient": patient,
  226. "number": basNumber,
  227. })
  228. }
  229. } else {
  230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  231. return
  232. }
  233. break
  234. case 2:
  235. SFZStr := c.GetSFZBaseInfo()
  236. id_card_str := strings.Split(SFZStr, "^")
  237. id_card_number := id_card_str[0]
  238. card_sn := ""
  239. result := service.Gdyb1101B(id_card_number, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, card_sn, certificates)
  240. var dat map[string]interface{}
  241. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  242. fmt.Println(dat)
  243. } else {
  244. fmt.Println(err)
  245. }
  246. userJSONBytes, _ := json.Marshal(dat)
  247. var res ResultTwo
  248. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  249. utils.ErrorLog("解析失败:%v", err)
  250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  251. return
  252. }
  253. if res.Infcode == 0 {
  254. patient, err := service.GetPatientByNumber(id_card_number, c.GetAdminUserInfo().CurrentOrgId)
  255. if err == gorm.ErrRecordNotFound {
  256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  257. return
  258. } else if err != nil {
  259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  260. return
  261. } else {
  262. c.ServeSuccessJSON(map[string]interface{}{
  263. "patient": patient,
  264. "number": id_card_number,
  265. })
  266. }
  267. } else {
  268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  269. return
  270. }
  271. break
  272. case 3:
  273. break
  274. }
  275. }
  276. var initFlag int64 = 0
  277. func (c *HisApiController) TestGetBasBaseInit() {
  278. DllDef := syscall.MustLoadDLL("SSCard.dll")
  279. Iinit := DllDef.MustFindProc("Init")
  280. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  281. ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr(miConfig.InsuplcAdmdvs))
  282. if ret != 0 {
  283. fmt.Println("SSCard的报错原因:", err)
  284. fmt.Println("SSCard的运算结果为:", ret)
  285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  286. return
  287. }
  288. result := int(ret)
  289. fmt.Println("SSCard的运算结果为1:", result)
  290. initFlag = 1
  291. return
  292. }
  293. func (c *HisApiController) GetSFZBaseInfo() string {
  294. DllDef := syscall.MustLoadDLL("SSCard.dll")
  295. readCard := DllDef.MustFindProc("ReadSFZ")
  296. if readCard == nil {
  297. fmt.Println("readcard is nil")
  298. readCard = DllDef.MustFindProc("ReadSFZ")
  299. }
  300. str := make([]byte, 256)
  301. str1 := make([]byte, 256)
  302. r, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  303. fmt.Println(r)
  304. return string(str)
  305. }
  306. func (c *HisApiController) GetBasBaseInfo() string {
  307. DllDef := syscall.MustLoadDLL("SSCard.dll")
  308. readCard := DllDef.MustFindProc("ReadCardBas")
  309. if readCard == nil {
  310. fmt.Println("readcard is nil")
  311. readCard = DllDef.MustFindProc("ReadCardBas")
  312. }
  313. str := make([]byte, 1024)
  314. str1 := make([]byte, 1024)
  315. ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), uintptr(1024), (uintptr)(unsafe.Pointer(&str1[0])), uintptr(1024))
  316. fmt.Println(string(str1))
  317. fmt.Println(string(str))
  318. if ret2 != 0 {
  319. return ""
  320. }
  321. return string(str)
  322. }
  323. func prttostr(vcode uintptr) string {
  324. var vbyte []byte
  325. for i := 0; i < 10; i++ {
  326. sbyte := *((*byte)(unsafe.Pointer(vcode)))
  327. if sbyte == 0 {
  328. break
  329. }
  330. vbyte = append(vbyte, sbyte)
  331. vcode += 1
  332. }
  333. return string(vbyte)
  334. }
  335. type CustomFundPay struct {
  336. FundPayType string `json:"fund_pay_type"`
  337. FundPayamt float64 `json:"fund_payamt"`
  338. }
  339. func (c *HisApiController) GetSettleList() {
  340. order_id, _ := c.GetInt64("order_id")
  341. admin_user_id, _ := c.GetInt64("admin_user_id")
  342. order, _ := service.GetHisOrderByIDTwo(order_id)
  343. roles, _ := service.GetDoctorListTwo(c.GetAdminUserInfo().CurrentOrgId)
  344. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  345. admin, _ := service.GetAdminUserByUserID(roles[0].AdminUserId)
  346. curRoles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  347. depart, _ := service.GetDepartMentDetail(curRoles.DepartmentId)
  348. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  349. if order.ID == 0 {
  350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  351. return
  352. }
  353. struct4101 := service.Struct4101{
  354. PsnNo: order.PsnNo,
  355. MdtrtId: order.MdtrtId,
  356. SetlId: order.SetlId,
  357. PsnName: order.PsnName,
  358. Gend: order.Gend,
  359. Brdy: his.Brdy,
  360. Age: his.Age,
  361. Naty: order.Naty,
  362. PatnCertType: "01",
  363. Certno: order.Certno,
  364. Prfs: "90",
  365. ConerName: roles[0].UserName,
  366. PatnRlts: "99",
  367. ConerAddr: miConfig.OrgName,
  368. ConerTel: admin.Mobile,
  369. HiType: order.Insutype,
  370. Insuplc: miConfig.InsuplcAdmdvs,
  371. MaindiagFlag: "1",
  372. BillCode: order.FaPiaoCode,
  373. BillNo: order.FaPiaoNumber,
  374. BizSn: order.Number,
  375. PsnSelfPay: order.PsnPartAmt,
  376. PsnOwnPay: order.PsnPartAmt,
  377. AcctPay: order.AcctPay,
  378. PsnCashpay: order.PsnCashPay,
  379. HiPaymtd: "1",
  380. Hsorg: miConfig.InsuplcAdmdvs,
  381. HsorgOpter: miConfig.InsuplcAdmdvs,
  382. MedinsFillPsn: curRoles.UserName,
  383. MedinsFillDept: depart.Name,
  384. IptMedType: "2",
  385. }
  386. if order.SettleType == 1 {
  387. t := time.Unix(int64(order.SettleAccountsDate), 0)
  388. dateStr := t.Format("2006-01-02")
  389. struct4101.SetlBegnDate = dateStr
  390. struct4101.SetlEndDate = dateStr
  391. } else {
  392. t := time.Unix(int64(order.SettleStartTime), 0)
  393. t2 := time.Unix(int64(order.SettleEndTime), 0)
  394. dateStartStr := t.Format("2006-01-02")
  395. dateEndStr := t2.Format("2006-01-02")
  396. struct4101.SetlBegnDate = dateStartStr
  397. struct4101.SetlEndDate = dateEndStr
  398. }
  399. var rf []CustomFundPay
  400. json.Unmarshal([]byte(order.SetlDetail), &rf)
  401. var tempFunPays []service.CustomStruct
  402. for _, item := range rf {
  403. var tempFunPay service.CustomStruct
  404. tempFunPay.FundPayamt = item.FundPayamt
  405. tempFunPay.FundPayType = item.FundPayType
  406. tempFunPays = append(tempFunPays, tempFunPay)
  407. }
  408. struct4101.CustomStruct = tempFunPays
  409. var tempOpspdiseinfos []service.OpspdiseinfoStruct
  410. var tempOpspdiseinfo2 service.OpspdiseinfoStruct
  411. //sickConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  412. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  413. var config []*models.HisXtDiagnoseConfig
  414. for _, item := range diagnosis_ids {
  415. id, _ := strconv.ParseInt(item, 10, 64)
  416. diagnosisConfig, _ := service.FindDiagnoseById(id)
  417. config = append(config, diagnosisConfig)
  418. }
  419. for _, item := range config {
  420. var tempOpspdiseinfo service.OpspdiseinfoStruct
  421. tempOpspdiseinfo.DiagCode = item.CountryCode
  422. tempOpspdiseinfo.DiagName = item.CountryContentName
  423. tempOpspdiseinfo.MaindiagFlag = "1"
  424. tempOpspdiseinfo.OprnOprtCode = ""
  425. tempOpspdiseinfo.OprnOprtName = ""
  426. tempOpspdiseinfos = append(tempOpspdiseinfos, tempOpspdiseinfo)
  427. }
  428. sickConfigTwo, _ := service.FindSickById(his.SickType)
  429. tempOpspdiseinfo2.DiagCode = sickConfigTwo.ContentCode
  430. tempOpspdiseinfo2.DiagName = sickConfigTwo.CountryContentName
  431. tempOpspdiseinfo2.MaindiagFlag = "2"
  432. tempOpspdiseinfo2.OprnOprtCode = ""
  433. tempOpspdiseinfo2.OprnOprtName = ""
  434. tempOpspdiseinfos = append(tempOpspdiseinfos, tempOpspdiseinfo2)
  435. struct4101.OpspdiseinfoStruct = tempOpspdiseinfos
  436. var iteminfo service.IteminfoStruct
  437. var bedCostTotal float64 = 0 //床位总费
  438. var bedCostSelfTotal float64 = 0 //床位自费
  439. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  440. var operationCostTotal float64 = 0 //手术费
  441. var operationCostSelfTotal float64 = 0 //手术费
  442. var operationCostPartSelfTotal float64 = 0 //手术费
  443. var otherCostTotal float64 = 0 //其他费用
  444. var otherCostSelfTotal float64 = 0 //其他费用
  445. var otherCostPartSelfTotal float64 = 0 //其他费用
  446. var materialCostTotal float64 = 0 //材料费
  447. var materialCostSelfTotal float64 = 0 //材料费
  448. var materialCostPartSelfTotal float64 = 0 //材料费
  449. var westernMedicineCostTotal float64 = 0 //西药费
  450. var westernMedicineCostSelfTotal float64 = 0 //西药费
  451. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  452. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  453. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  454. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  455. var checkCostTotal float64 = 0 //检查费
  456. var checkCostSelfTotal float64 = 0 //检查费
  457. var checkCostPartSelfTotal float64 = 0 //检查费
  458. var laboratoryCostTotal float64 = 0 //化验费
  459. var laboratoryCostSelfTotal float64 = 0 //化验费
  460. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  461. var treatCostTotal float64 = 0 //治疗费用
  462. var treatCostSelfTotal float64 = 0 //治疗费用
  463. var treatCostPartSelfTotal float64 = 0 //治疗费用
  464. decimal.DivisionPrecision = 2
  465. var bed_fulamt_ownpay_amt float64 = 0
  466. var operation_fulamt_ownpay_amt float64 = 0
  467. var other_fulamt_ownpay_amt float64 = 0
  468. var westernMedicine_fulamt_ownpay_amt float64 = 0
  469. var chineseTraditional_fulamt_ownpay_amt float64 = 0
  470. var check_fulamt_ownpay_amt float64 = 0
  471. var material_fulamt_ownpay_amt float64 = 0
  472. var laboratory_fulamt_ownpay_amt float64 = 0
  473. var treat_fulamt_ownpay_amt float64 = 0
  474. var bed_claa_sunmfee float64 = 0
  475. var bed_clab_amt float64 = 0
  476. var bed_other_amt float64 = 0
  477. var operation_claa_sunmfee float64 = 0
  478. var operation_clab_amt float64 = 0
  479. var operation_other_amt float64 = 0
  480. var other_claa_sunmfee float64 = 0
  481. var other_clab_amt float64 = 0
  482. var other_other_amt float64 = 0
  483. var westernMedicine_claa_sunmfee float64 = 0
  484. var westernMedicine_clab_amt float64 = 0
  485. var westernMedicine_other_amt float64 = 0
  486. var chineseTraditional_claa_sunmfee float64 = 0
  487. var chineseTraditional_clab_amt float64 = 0
  488. var chineseTraditional_other_amt float64 = 0
  489. var check_claa_sunmfee float64 = 0
  490. var check_clab_amt float64 = 0
  491. var check_other_amt float64 = 0
  492. var material_claa_sunmfee float64 = 0
  493. var material_clab_amt float64 = 0
  494. var material_other_amt float64 = 0
  495. var laboratory_claa_sunmfee float64 = 0
  496. var laboratory_clab_amt float64 = 0
  497. var laboratory_other_amt float64 = 0
  498. var treat_claa_sunmfee float64 = 0
  499. var treat_clab_amt float64 = 0
  500. var treat_other_amt float64 = 0
  501. for _, item := range order.HisOrderInfo {
  502. if item.MedChrgitmType == "01" { //床位费
  503. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  504. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  505. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  506. bed_fulamt_ownpay_amt, _ = decimal.NewFromFloat(bed_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  507. if item.ChrgitmLv == "1" {
  508. bed_claa_sunmfee, _ = decimal.NewFromFloat(bed_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  509. }
  510. if item.ChrgitmLv == "2" {
  511. bed_clab_amt, _ = decimal.NewFromFloat(bed_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  512. }
  513. if item.ChrgitmLv == "3" {
  514. bed_other_amt, _ = decimal.NewFromFloat(bed_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  515. }
  516. }
  517. if item.MedChrgitmType == "03" { //检查费
  518. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  519. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  520. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  521. check_fulamt_ownpay_amt, _ = decimal.NewFromFloat(check_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  522. if item.ChrgitmLv == "1" {
  523. check_claa_sunmfee, _ = decimal.NewFromFloat(check_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  524. }
  525. if item.ChrgitmLv == "2" {
  526. check_clab_amt, _ = decimal.NewFromFloat(check_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  527. }
  528. if item.ChrgitmLv == "3" {
  529. check_other_amt, _ = decimal.NewFromFloat(check_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  530. }
  531. }
  532. if item.MedChrgitmType == "04" { //化验费
  533. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  534. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  535. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  536. laboratory_fulamt_ownpay_amt, _ = decimal.NewFromFloat(laboratory_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  537. if item.ChrgitmLv == "1" {
  538. laboratory_claa_sunmfee, _ = decimal.NewFromFloat(laboratory_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  539. }
  540. if item.ChrgitmLv == "2" {
  541. laboratory_clab_amt, _ = decimal.NewFromFloat(laboratory_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  542. }
  543. if item.ChrgitmLv == "3" {
  544. laboratory_other_amt, _ = decimal.NewFromFloat(laboratory_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  545. }
  546. }
  547. if item.MedChrgitmType == "05" { //治疗费
  548. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  549. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  550. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  551. treat_fulamt_ownpay_amt, _ = decimal.NewFromFloat(treat_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  552. if item.ChrgitmLv == "1" {
  553. treat_claa_sunmfee, _ = decimal.NewFromFloat(treat_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  554. }
  555. if item.ChrgitmLv == "2" {
  556. treat_clab_amt, _ = decimal.NewFromFloat(treat_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  557. }
  558. if item.ChrgitmLv == "3" {
  559. treat_other_amt, _ = decimal.NewFromFloat(treat_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  560. }
  561. }
  562. if item.MedChrgitmType == "06" { //手术费
  563. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  564. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  565. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  566. operation_fulamt_ownpay_amt, _ = decimal.NewFromFloat(operation_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  567. if item.ChrgitmLv == "1" {
  568. operation_claa_sunmfee, _ = decimal.NewFromFloat(operation_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  569. }
  570. if item.ChrgitmLv == "2" {
  571. operation_clab_amt, _ = decimal.NewFromFloat(operation_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  572. }
  573. if item.ChrgitmLv == "3" {
  574. operation_other_amt, _ = decimal.NewFromFloat(operation_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  575. }
  576. }
  577. if item.MedChrgitmType == "08" { //材料费
  578. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  579. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  580. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  581. material_fulamt_ownpay_amt, _ = decimal.NewFromFloat(material_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  582. if item.ChrgitmLv == "1" {
  583. material_claa_sunmfee, _ = decimal.NewFromFloat(material_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  584. }
  585. if item.ChrgitmLv == "2" {
  586. material_clab_amt, _ = decimal.NewFromFloat(material_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  587. }
  588. if item.ChrgitmLv == "3" {
  589. material_other_amt, _ = decimal.NewFromFloat(material_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  590. }
  591. }
  592. if item.MedChrgitmType == "09" { //西药费
  593. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  594. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  595. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  596. westernMedicine_fulamt_ownpay_amt, _ = decimal.NewFromFloat(westernMedicine_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  597. if item.ChrgitmLv == "1" {
  598. westernMedicine_claa_sunmfee, _ = decimal.NewFromFloat(westernMedicine_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  599. }
  600. if item.ChrgitmLv == "2" {
  601. westernMedicine_clab_amt, _ = decimal.NewFromFloat(westernMedicine_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  602. }
  603. if item.ChrgitmLv == "3" {
  604. westernMedicine_other_amt, _ = decimal.NewFromFloat(westernMedicine_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  605. }
  606. }
  607. if item.MedChrgitmType == "11" { //中成费
  608. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  609. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  610. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  611. chineseTraditional_fulamt_ownpay_amt, _ = decimal.NewFromFloat(chineseTraditional_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  612. if item.ChrgitmLv == "1" {
  613. chineseTraditional_claa_sunmfee, _ = decimal.NewFromFloat(chineseTraditional_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  614. }
  615. if item.ChrgitmLv == "2" {
  616. chineseTraditional_clab_amt, _ = decimal.NewFromFloat(chineseTraditional_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  617. }
  618. if item.ChrgitmLv == "3" {
  619. chineseTraditional_other_amt, _ = decimal.NewFromFloat(chineseTraditional_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  620. }
  621. }
  622. if item.MedChrgitmType == "14" { //其他费
  623. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  624. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  625. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  626. other_fulamt_ownpay_amt, _ = decimal.NewFromFloat(other_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  627. if item.ChrgitmLv == "1" {
  628. other_claa_sunmfee, _ = decimal.NewFromFloat(other_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  629. }
  630. if item.ChrgitmLv == "2" {
  631. other_clab_amt, _ = decimal.NewFromFloat(other_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  632. }
  633. if item.ChrgitmLv == "3" {
  634. other_other_amt, _ = decimal.NewFromFloat(other_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  635. }
  636. }
  637. }
  638. var iteminfoStructs []service.IteminfoStruct
  639. if bedCostTotal != 0 {
  640. iteminfo.MedChrgitm = "01"
  641. iteminfo.FulamtOwnpayAmt = bed_fulamt_ownpay_amt
  642. iteminfo.Amt = bedCostTotal
  643. iteminfo.ClaaSumfee = bed_claa_sunmfee
  644. iteminfo.ClabAmt = bed_clab_amt
  645. iteminfo.OthAmt = bed_other_amt
  646. iteminfoStructs = append(iteminfoStructs, iteminfo)
  647. }
  648. if checkCostTotal != 0 {
  649. iteminfo.MedChrgitm = "03"
  650. iteminfo.FulamtOwnpayAmt = check_fulamt_ownpay_amt
  651. iteminfo.Amt = checkCostTotal
  652. iteminfo.ClaaSumfee = check_claa_sunmfee
  653. iteminfo.ClabAmt = check_clab_amt
  654. iteminfo.OthAmt = check_other_amt
  655. iteminfoStructs = append(iteminfoStructs, iteminfo)
  656. }
  657. if laboratoryCostTotal != 0 {
  658. iteminfo.MedChrgitm = "04"
  659. iteminfo.FulamtOwnpayAmt = laboratory_fulamt_ownpay_amt
  660. iteminfo.Amt = laboratoryCostTotal
  661. iteminfo.ClaaSumfee = laboratory_claa_sunmfee
  662. iteminfo.ClabAmt = laboratory_clab_amt
  663. iteminfo.OthAmt = laboratory_other_amt
  664. iteminfoStructs = append(iteminfoStructs, iteminfo)
  665. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  666. }
  667. if treatCostTotal != 0 {
  668. iteminfo.MedChrgitm = "05"
  669. iteminfo.FulamtOwnpayAmt = treat_fulamt_ownpay_amt
  670. iteminfo.Amt = treatCostTotal
  671. iteminfo.ClaaSumfee = treat_claa_sunmfee
  672. iteminfo.ClabAmt = treat_clab_amt
  673. iteminfo.OthAmt = treat_other_amt
  674. iteminfoStructs = append(iteminfoStructs, iteminfo)
  675. // (struct4101.IteminfoStruct, iteminfo)
  676. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  677. }
  678. if operationCostTotal != 0 {
  679. iteminfo.MedChrgitm = "06"
  680. iteminfo.FulamtOwnpayAmt = bed_fulamt_ownpay_amt
  681. iteminfo.Amt = operationCostTotal
  682. iteminfo.ClaaSumfee = operation_claa_sunmfee
  683. iteminfo.ClabAmt = operation_clab_amt
  684. iteminfo.OthAmt = operation_other_amt
  685. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  686. iteminfoStructs = append(iteminfoStructs, iteminfo)
  687. }
  688. if materialCostTotal != 0 {
  689. iteminfo.MedChrgitm = "08"
  690. iteminfo.FulamtOwnpayAmt = material_fulamt_ownpay_amt
  691. iteminfo.Amt = materialCostTotal
  692. iteminfo.ClaaSumfee = material_claa_sunmfee
  693. iteminfo.ClabAmt = material_clab_amt
  694. iteminfo.OthAmt = material_other_amt
  695. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  696. iteminfoStructs = append(iteminfoStructs, iteminfo)
  697. }
  698. if westernMedicineCostTotal != 0 {
  699. iteminfo.MedChrgitm = "09"
  700. iteminfo.FulamtOwnpayAmt = westernMedicine_fulamt_ownpay_amt
  701. iteminfo.Amt = westernMedicineCostTotal
  702. iteminfo.ClaaSumfee = westernMedicine_claa_sunmfee
  703. iteminfo.ClabAmt = westernMedicine_clab_amt
  704. iteminfo.OthAmt = westernMedicine_other_amt
  705. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  706. iteminfoStructs = append(iteminfoStructs, iteminfo)
  707. }
  708. if chineseTraditionalMedicineCostTotal != 0 {
  709. iteminfo.MedChrgitm = "11"
  710. iteminfo.FulamtOwnpayAmt = westernMedicine_fulamt_ownpay_amt
  711. iteminfo.Amt = westernMedicineCostTotal
  712. iteminfo.ClaaSumfee = westernMedicine_claa_sunmfee
  713. iteminfo.ClabAmt = westernMedicine_clab_amt
  714. iteminfo.OthAmt = westernMedicine_other_amt
  715. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  716. iteminfoStructs = append(iteminfoStructs, iteminfo)
  717. }
  718. if otherCostTotal != 0 {
  719. iteminfo.MedChrgitm = "14"
  720. iteminfo.FulamtOwnpayAmt = other_fulamt_ownpay_amt
  721. iteminfo.Amt = otherCostTotal
  722. iteminfo.ClaaSumfee = other_claa_sunmfee
  723. iteminfo.ClabAmt = other_clab_amt
  724. iteminfo.OthAmt = other_other_amt
  725. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  726. iteminfoStructs = append(iteminfoStructs, iteminfo)
  727. }
  728. struct4101.IteminfoStruct = iteminfoStructs
  729. struct4101.Ntly = "中国"
  730. struct4101.AdmCaty = "A03.06"
  731. result := service.Gdyb4101(struct4101, miConfig.SecretKey, miConfig.OrgName, curRoles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  732. fmt.Println(result)
  733. var dat map[string]interface{}
  734. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  735. fmt.Println(dat)
  736. } else {
  737. fmt.Println(err)
  738. }
  739. userJSONBytes, _ := json.Marshal(dat)
  740. var res ResultSeventeen
  741. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  742. utils.ErrorLog("解析失败:%v", err)
  743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  744. return
  745. }
  746. if res.Infcode != 0 {
  747. c.ServeSuccessJSON(map[string]interface{}{
  748. "failed_code": -10,
  749. "msg": res.ErrMsg,
  750. })
  751. return
  752. } else {
  753. hisFundSettleListResult := &models.HisFundSettleListResult{
  754. Number: res.Output.SetlListId,
  755. Status: 1,
  756. Ctime: time.Now().Unix(),
  757. Mtime: time.Now().Unix(),
  758. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  759. IsUpload: 1,
  760. OrderId: order_id,
  761. }
  762. service.CreateUploadRecord(hisFundSettleListResult)
  763. c.ServeSuccessJSON(map[string]interface{}{
  764. "msg": "上传成功",
  765. "result": hisFundSettleListResult,
  766. })
  767. return
  768. }
  769. }
  770. //func (c *HisApiController) TestPay() {
  771. // DllDef2 := syscall.MustLoadDLL("SSSE32.dll")
  772. // readCards := DllDef2.MustFindProc("BankTrans")
  773. // inputData := make(map[string]interface{})
  774. // inputData["transId"] = "05"
  775. // inputData["amount"] = "0.01"
  776. // inputData["traceNo"] = "20210227093601325405377"
  777. // inputData["cardNo"] = "F36084348"
  778. // inputData["id"] = "44022919620927046X"
  779. // //jsonStr := `
  780. // // {
  781. // // "transId": "05",
  782. // // "amount":"1.00",
  783. // // "traceNo":"20210227093601325405377",
  784. // // "cardNo":"F36084348",
  785. // // "id":"44022919620927046X"
  786. // //
  787. // // }
  788. // //`
  789. //
  790. // bytes_arr, _ := json.Marshal(inputData)
  791. // str3 := make([]byte, 256)
  792. // ret4, _, err4 := readCards.Call(StrPtr(string(bytes_arr)), (uintptr)(unsafe.Pointer(&str3[0])))
  793. // fmt.Println(":", string(str3))
  794. //
  795. // if err4 != nil {
  796. // fmt.Println("SSCard的运算结果为:", ret4)
  797. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  798. // return
  799. // }
  800. //
  801. //}
  802. //func (c *HisApiController) TestGetBasBaseInfo() {
  803. //
  804. // //result := C.Init(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  805. // //fmt.Println(result)
  806. // //cs1 := C.CString("")
  807. // //cs2 := C.CString("")
  808. // //C.ReadCardBas(cs1, IntPtr(1024), cs2, IntPtr(1024))
  809. // //fmt.Println(cs1)
  810. // //fmt.Println(cs2)
  811. // //C.free(unsafe.Pointer(cs1))
  812. // //C.free(unsafe.Pointer(cs2))
  813. //
  814. // //
  815. //
  816. // DllDef := syscall.MustLoadDLL("SSCard.dll")
  817. // Iinit := DllDef.MustFindProc("Init")
  818. // readCard := DllDef.MustFindProc("ReadCardBas")
  819. // ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  820. // if ret != 0 {
  821. // fmt.Println("SSCard的报错原因:", err)
  822. // fmt.Println("SSCard的运算结果为:", ret)
  823. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  824. // return
  825. // }
  826. //
  827. // result := int(ret)
  828. // fmt.Println("SSCard的运算结果为1:", result)
  829. //
  830. // //path := ""
  831. // //bytePath := []byte( "\x00")
  832. // //bytePath2 := []byte( "\x00")
  833. // //ssss
  834. //
  835. // str := make([]byte, 256)
  836. // str1 := make([]byte, 256)
  837. // s2 := []byte(string(str))
  838. // s3 := []byte(string(str1))
  839. // ret2, _, err2 := readCard.Call((uintptr)(unsafe.Pointer(&s2[0])), IntPtr(256), (uintptr)(unsafe.Pointer(&s3[0])), IntPtr(256))
  840. // fmt.Println(" Add(4,5)的结果为:", ret2)
  841. // fmt.Println(" str:", s2)
  842. // fmt.Println(" str1:", s3)
  843. // if err2 != nil {
  844. // fmt.Println("SSCard的运算结果为:", ret2)
  845. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  846. // return
  847. // }
  848. //
  849. // //DllDef := syscall.MustLoadDLL("SSCard.dll")
  850. //
  851. //}
  852. func (c *HisApiController) GetOrgInfo() {
  853. miConfig, _ := service.FindMedicalInsuranceInfo(4)
  854. service.Gdyb1201("", miConfig.OrgName, "1122", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 1, "")
  855. }
  856. func (c *HisApiController) GetHisPatientInfo() {
  857. medical_insurance_card := c.GetString("medical_insurance_card")
  858. id_card_type, _ := c.GetInt64("id_card_type")
  859. id_card := c.GetString("id_card")
  860. adminInfo := c.GetAdminUserInfo()
  861. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  862. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  863. appRole, _ := service.GetAppRole(adminInfo.CurrentOrgId)
  864. IdCardNo := ""
  865. if id_card_type == 1 {
  866. IdCardNo = medical_insurance_card
  867. } else if id_card_type == 2 {
  868. IdCardNo = id_card
  869. }
  870. if config.IsOpen == 1 {
  871. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  872. resp, requestErr := http.Get(api)
  873. if requestErr != nil {
  874. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  875. return
  876. }
  877. defer resp.Body.Close()
  878. body, ioErr := ioutil.ReadAll(resp.Body)
  879. if ioErr != nil {
  880. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  882. return
  883. }
  884. var respJSON map[string]interface{}
  885. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  886. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  888. return
  889. }
  890. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  891. userJSONBytes, _ := json.Marshal(userJSON)
  892. var res ResultTwo
  893. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  894. utils.ErrorLog("解析失败:%v", err)
  895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  896. return
  897. }
  898. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  899. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  900. infoStr := string(Iinfos)
  901. idetinfoStr := string(Idetinfos)
  902. if res.Infcode == 0 {
  903. his := models.VMHisPatient{
  904. Status: 1,
  905. Ctime: time.Now().Unix(),
  906. Mtime: time.Now().Unix(),
  907. PsnNo: res.Output.Baseinfo.PsnNo,
  908. PsnCertType: res.Output.Baseinfo.PsnCertType,
  909. Certno: res.Output.Baseinfo.Certno,
  910. PsnName: res.Output.Baseinfo.PsnName,
  911. Gend: res.Output.Baseinfo.Gend,
  912. Naty: res.Output.Baseinfo.Naty,
  913. Brdy: res.Output.Baseinfo.Brdy,
  914. Age: res.Output.Baseinfo.Age,
  915. Iinfo: infoStr,
  916. Idetinfo: idetinfoStr,
  917. UserOrgId: adminInfo.CurrentOrgId,
  918. IsReturn: 1,
  919. IdCardType: id_card_type,
  920. }
  921. c.ServeSuccessJSON(map[string]interface{}{
  922. "info": his,
  923. })
  924. } else {
  925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  926. return
  927. }
  928. }
  929. }
  930. //func GetBasBaseInfo() (jsonStr string, err error) {
  931. //
  932. // handle := syscall.NewLazyDLL("SSCard.dll")
  933. // add := handle.NewProc("ReadCardBas")
  934. // str := make([]byte, 1024)
  935. // str1 := make([]byte, 1024)
  936. // ret, _, _ := add.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  937. // fmt.Println(ConvertToString(string(str), "gbk", "utf-8"))
  938. //
  939. // fmt.Println(ConvertToString(string(str1), "gbk", "utf-8"))
  940. //
  941. // fmt.Println("> Add(4,5)的结果为:", ret)
  942. // handle.Release()
  943. //
  944. // return "", nil
  945. //
  946. //}
  947. //func GetQRBaseInfo() (jsonStr string, err error) {
  948. // handle := syscall.LoadDLL("SSCard.dll")
  949. // ReadCardBas := handle.FindProc("GetQRBase")
  950. //
  951. // str := make([]byte, 256)
  952. // str1 := make([]byte, 256)
  953. // r, _, _ := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  954. //
  955. // fmt.Println(string(str))
  956. // fmt.Println(r)
  957. // return string(str), nil
  958. //}
  959. //func CardInit() int {
  960. // DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  961. // add := DllTestDef.MustFindProc("Init")
  962. // ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  963. // if err != nil {
  964. // fmt.Println("SSCard的运算结果为:", ret)
  965. // }
  966. // result := int(ret)
  967. // return result
  968. //}
  969. //func CardInit() int {
  970. // ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  971. // if err != nil {
  972. // fmt.Println("SSCard的运算结果为:", ret)
  973. // }
  974. // fmt.Println(err)
  975. // result := int(ret)
  976. // return result
  977. //}
  978. func IntPtr(n int) uintptr {
  979. return uintptr(n)
  980. }
  981. func StrPtr(s string) uintptr {
  982. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  983. }
  984. type ResultTwo struct {
  985. ErrMsg string `json:"err_msg"`
  986. InfRefmsgid string `json:"inf_refmsgid"`
  987. Infcode int64 `json:"infcode"`
  988. Output struct {
  989. Baseinfo struct {
  990. Age float64 `json:"age"`
  991. Brdy string `json:"brdy"`
  992. Certno string `json:"certno"`
  993. Gend string `json:"gend"`
  994. Naty string `json:"naty"`
  995. PsnCertType string `json:"psn_cert_type"`
  996. PsnName string `json:"psn_name"`
  997. PsnNo string `json:"psn_no"`
  998. } `json:"baseinfo"`
  999. Idetinfo []interface{} `json:"idetinfo"`
  1000. Iinfo []struct {
  1001. Balc float64 `json:"balc"`
  1002. CvlservFlag string `json:"cvlserv_flag"`
  1003. EmpName string `json:"emp_name"`
  1004. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  1005. Insutype string `json:"insutype"`
  1006. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  1007. PausInsuDate string `json:"paus_insu_date"`
  1008. PsnInsuDate string `json:"psn_insu_date"`
  1009. PsnInsuStas string `json:"psn_insu_stas"`
  1010. PsnType string `json:"psn_type"`
  1011. } `json:"insuinfo"`
  1012. } `json:"output"`
  1013. RefmsgTime string `json:"refmsg_time"`
  1014. RespondTime string `json:"respond_time"`
  1015. Signtype interface{} `json:"signtype"`
  1016. WarnInfo interface{} `json:"warn_info"`
  1017. }
  1018. type ResultThree struct {
  1019. Cainfo interface{} `json:"cainfo"`
  1020. ErrMsg string `json:"err_msg"`
  1021. InfRefmsgid string `json:"inf_refmsgid"`
  1022. Infcode int64 `json:"infcode"`
  1023. Output struct {
  1024. Data struct {
  1025. IptOtpNo string `json:"ipt_otp_no"`
  1026. MdtrtID string `json:"mdtrt_id"`
  1027. PsnNo string `json:"psn_no"`
  1028. } `json:"data"`
  1029. } `json:"output"`
  1030. RefmsgTime string `json:"refmsg_time"`
  1031. RespondTime string `json:"respond_time"`
  1032. Signtype interface{} `json:"signtype"`
  1033. WarnMsg interface{} `json:"warn_msg"`
  1034. }
  1035. type ResultFour struct {
  1036. Cainfo string `json:"cainfo"`
  1037. ErrMsg string `json:"err_msg"`
  1038. InfRefmsgid string `json:"inf_refmsgid"`
  1039. Infcode int64 `json:"infcode"`
  1040. Output struct {
  1041. Result []struct {
  1042. BasMednFlag string `json:"bas_medn_flag"`
  1043. ChldMedcFlag string `json:"chld_medc_flag"`
  1044. ChrgitmLv string `json:"chrgitm_lv"`
  1045. Cnt float64 `json:"cnt"`
  1046. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  1047. DrtReimFlag string `json:"drt_reim_flag"`
  1048. FeedetlSn string `json:"feedetl_sn"`
  1049. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1050. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  1051. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1052. ListSpItemFlag string `json:"list_sp_item_flag"`
  1053. LmtUsedFlag string `json:"lmt_used_flag"`
  1054. MedChrgitmType string `json:"med_chrgitm_type"`
  1055. Memo string `json:"memo"`
  1056. OverlmtAmt float64 `json:"overlmt_amt"`
  1057. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1058. Pric float64 `json:"pric"`
  1059. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  1060. SelfpayProp float64 `json:"selfpay_prop"`
  1061. } `json:"result"`
  1062. } `json:"output"`
  1063. RefmsgTime string `json:"refmsg_time"`
  1064. RespondTime string `json:"respond_time"`
  1065. Signtype string `json:"signtype"`
  1066. WarnMsg string `json:"warn_msg"`
  1067. }
  1068. type ResultFive struct {
  1069. Balc float64 `json:"balc"`
  1070. CvlservFlag string `json:"cvlserv_flag"`
  1071. EmpName string `json:"emp_name"`
  1072. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  1073. Insutype string `json:"insutype"`
  1074. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  1075. PausInsuDate string `json:"paus_insu_date"`
  1076. PsnInsuDate string `json:"psn_insu_date"`
  1077. PsnInsuStas string `json:"psn_insu_stas"`
  1078. PsnType string `json:"psn_type"`
  1079. }
  1080. type ResultSix struct {
  1081. Cainfo interface{} `json:"cainfo"`
  1082. ErrMsg string `json:"err_msg"`
  1083. InfRefmsgid string `json:"inf_refmsgid"`
  1084. Infcode int64 `json:"infcode"`
  1085. Output struct {
  1086. } `json:"output"`
  1087. RefmsgTime string `json:"refmsg_time"`
  1088. RespondTime string `json:"respond_time"`
  1089. Signtype interface{} `json:"signtype"`
  1090. WarnMsg interface{} `json:"warn_msg"`
  1091. }
  1092. type ResultSeven struct {
  1093. Cainfo string `json:"cainfo"`
  1094. ErrMsg string `json:"err_msg"`
  1095. InfRefmsgid string `json:"inf_refmsgid"`
  1096. Infcode int64 `json:"infcode"`
  1097. Output struct {
  1098. Setldetail []interface{} `json:"setldetail"`
  1099. Setlinfo struct {
  1100. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1101. AcctPay float64 `json:"acct_pay"`
  1102. ActPayDedc float64 `json:"act_pay_dedc"`
  1103. Age float64 `json:"age"`
  1104. Balc float64 `json:"balc"`
  1105. Brdy string `json:"brdy"`
  1106. Certno string `json:"certno"`
  1107. ClrOptins string `json:"clr_optins"`
  1108. ClrType string `json:"clr_type"`
  1109. ClrWay string `json:"clr_way"`
  1110. CvlservFlag string `json:"cvlserv_flag"`
  1111. CvlservPay float64 `json:"cvlserv_pay"`
  1112. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1113. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1114. Gend string `json:"gend"`
  1115. HifesPay float64 `json:"hifes_pay"`
  1116. HifmiPay float64 `json:"hifmi_pay"`
  1117. HifpPay float64 `json:"hifp_pay"`
  1118. HospPartAmt float64 `json:"hosp_part_amt"`
  1119. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1120. Insutype string `json:"insutype"`
  1121. MafPay float64 `json:"maf_pay"`
  1122. MdtrtCertType string `json:"mdtrt_cert_type"`
  1123. HifobPay float64 `json:"hifob_pay"`
  1124. MdtrtID string `json:"mdtrt_id"`
  1125. MedType string `json:"med_type"`
  1126. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1127. MedinsSetlID string `json:"medins_setl_id"`
  1128. Naty string `json:"naty"`
  1129. OthPay float64 `json:"oth_pay"`
  1130. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1131. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1132. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1133. PsnCashPay float64 `json:"psn_cash_pay"`
  1134. PsnCertType string `json:"psn_cert_type"`
  1135. PsnName string `json:"psn_name"`
  1136. PsnNo string `json:"psn_no"`
  1137. PsnPartAmt float64 `json:"psn_part_amt"`
  1138. PsnType string `json:"psn_type"`
  1139. SetlID string `json:"setl_id"`
  1140. SetlTime string `json:"setl_time"`
  1141. } `json:"setlinfo"`
  1142. } `json:"output"`
  1143. RefmsgTime string `json:"refmsg_time"`
  1144. RespondTime string `json:"respond_time"`
  1145. Signtype interface{} `json:"signtype"`
  1146. WarnMsg interface{} `json:"warn_msg"`
  1147. }
  1148. type ResultEight struct {
  1149. Cainfo string `json:"cainfo"`
  1150. ErrMsg string `json:"err_msg"`
  1151. InfRefmsgid string `json:"inf_refmsgid"`
  1152. Infcode int64 `json:"infcode"`
  1153. Output struct {
  1154. Stmtinfo struct {
  1155. SetlOptins string `json:"setl_optins"`
  1156. StmtRslt string `json:"stmt_rslt"`
  1157. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  1158. } `json:"stmtinfo"`
  1159. } `json:"output"`
  1160. RefmsgTime string `json:"refmsg_time"`
  1161. RespondTime string `json:"respond_time"`
  1162. Signtype interface{} `json:"signtype"`
  1163. WarnMsg interface{} `json:"warn_msg"`
  1164. }
  1165. type ResultNine struct {
  1166. Cainfo string `json:"cainfo"`
  1167. ErrMsg string `json:"err_msg"`
  1168. InfRefmsgid string `json:"inf_refmsgid"`
  1169. Infcode int64 `json:"infcode"`
  1170. Output struct {
  1171. FileQuryNo string `json:"file_qury_no"`
  1172. } `json:"output"`
  1173. RefmsgTime string `json:"refmsg_time"`
  1174. RespondTime string `json:"respond_time"`
  1175. Signtype interface{} `json:"signtype"`
  1176. WarnMsg interface{} `json:"warn_msg"`
  1177. }
  1178. type ResultTen struct {
  1179. Cainfo string `json:"cainfo"`
  1180. ErrMsg string `json:"err_msg"`
  1181. InfRefmsgid string `json:"inf_refmsgid"`
  1182. Infcode int64 `json:"infcode"`
  1183. Output struct {
  1184. DldEndtime string `json:"dld_endtime"`
  1185. FileQuryNo string `json:"file_qury_no"`
  1186. Filename string `json:"filename"`
  1187. } `json:"output"`
  1188. RefmsgTime string `json:"refmsg_time"`
  1189. RespondTime string `json:"respond_time"`
  1190. Signtype interface{} `json:"signtype"`
  1191. WarnMsg interface{} `json:"warn_msg"`
  1192. }
  1193. //type Autogenerated struct {
  1194. // Output struct {
  1195. // Setlinfo struct {
  1196. // SetlTime string `json:"setl_time"`
  1197. // CvlservPay float64 `json:"cvlserv_pay"`
  1198. // Year string `json:"year"`
  1199. // MedType string `json:"med_type"`
  1200. // PsnPay float64 `json:"psn_pay"`
  1201. // OpterID string `json:"opter_id"`
  1202. // Begndate string `json:"begndate"`
  1203. // FlxempeFlag string `json:"flxempe_flag"`
  1204. // HifmiPay float64 `json:"hifmi_pay"`
  1205. // PsnNo string `json:"psn_no"`
  1206. // ActPayDedc float64 `json:"act_pay_dedc"`
  1207. // MedinsSetlID interface{} `json:"medins_setl_id"`
  1208. // AcctMulaidPay interface{} `json:"acct_mulaid_pay"`
  1209. // ClrWay string `json:"clr_way"`
  1210. // OthPay float64 `json:"oth_pay"`
  1211. // Gend string `json:"gend"`
  1212. // MdtrtID string `json:"mdtrt_id"`
  1213. // AcctPay float64 `json:"acct_pay"`
  1214. // InscpScpAmt float64 `json:"inscp_scp_amt"`
  1215. // Insutype string `json:"insutype"`
  1216. // Invono interface{} `json:"invono"`
  1217. // Enddate string `json:"enddate"`
  1218. // CashPayamt float64 `json:"cash_payamt"`
  1219. // PsnType string `json:"psn_type"`
  1220. // FixmedinsName string `json:"fixmedins_name"`
  1221. // HifpPay float64 `json:"hifp_pay"`
  1222. // NewFlag interface{} `json:"new_flag"`
  1223. // OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1224. // PreselfpayAmt float64 `json:"preselfpay_amt"`
  1225. // PayLoc string `json:"pay_loc"`
  1226. // ClrType string `json:"clr_type"`
  1227. // RefdSetlFlag string `json:"refd_setl_flag"`
  1228. // CvlservFlag string `json:"cvlserv_flag"`
  1229. // EmpName string `json:"emp_name"`
  1230. // Brdy string `json:"brdy"`
  1231. // Naty string `json:"naty"`
  1232. // Certno string `json:"certno"`
  1233. // DiseCode string `json:"dise_code"`
  1234. // FixmedinsCode string `json:"fixmedins_code"`
  1235. // DedcHospLv string `json:"dedc_hosp_lv"`
  1236. // OpterName string `json:"opter_name"`
  1237. // Balc float64 `json:"balc"`
  1238. // FixmedinsPoolarea string `json:"fixmedins_poolarea"`
  1239. // PsnCertType string `json:"psn_cert_type"`
  1240. // HifobPay float64 `json:"hifob_pay"`
  1241. // MedfeeSumamt float64 `json:"medfee_sumamt"`
  1242. // HifesPay float64 `json:"hifes_pay"`
  1243. // FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1244. // OptTime string `json:"opt_time"`
  1245. // FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1246. // SetlID string `json:"setl_id"`
  1247. // MafPay float64 `json:"maf_pay"`
  1248. // PsnName string `json:"psn_name"`
  1249. // InsuOptins interface{} `json:"insu_optins"`
  1250. // PrefFundPay interface{} `json:"pref_fund_pay"`
  1251. // ClrOptins string `json:"clr_optins"`
  1252. // PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1253. // DiseName string `json:"dise_name"`
  1254. // LmtpricHospLv string `json:"lmtpric_hosp_lv"`
  1255. // Age float64 `json:"age"`
  1256. // DtrtCertType string `json:"dtrt_cert_type"`
  1257. // HospLv string `json:"hosp_lv"`
  1258. // } `json:"setlinfo"`
  1259. // Setldetail []struct {
  1260. // FundPayType string `json:"fund_pay_type"`
  1261. // FundPayamt float64 `json:"fund_payamt"`
  1262. // SetlProcInfo interface{} `json:"setl_proc_info"`
  1263. // CrtPaybLmtAmt interface{} `json:"crt_payb_lmt_amt"`
  1264. // InscpScpAmt interface{} `json:"inscp_scp_amt"`
  1265. // FundPayTypeName interface{} `json:"fund_pay_type_name"`
  1266. // PrefFundPay interface{} `json:"pref_fund_pay"`
  1267. // } `json:"setldetail"`
  1268. // } `json:"output"`
  1269. // Infcode int `json:"infcode"`
  1270. // WarnMsg interface{} `json:"warn_msg"`
  1271. // Cainfo interface{} `json:"cainfo"`
  1272. // ErrMsg interface{} `json:"err_msg"`
  1273. // RefmsgTime string `json:"refmsg_time"`
  1274. // Signtype interface{} `json:"signtype"`
  1275. // RespondTime string `json:"respond_time"`
  1276. // InfRefmsgid string `json:"inf_refmsgid"`
  1277. //}
  1278. type ResultEleven struct {
  1279. Cainfo string `json:"cainfo"`
  1280. ErrMsg string `json:"err_msg"`
  1281. InfRefmsgid string `json:"inf_refmsgid"`
  1282. Infcode int64 `json:"infcode"`
  1283. Output struct {
  1284. Setlinfo struct {
  1285. SetlTime string `json:"setl_time"`
  1286. CvlservPay float64 `json:"cvlserv_pay"`
  1287. Year string `json:"year"`
  1288. MedType string `json:"med_type"`
  1289. PsnPay float64 `json:"psn_pay"`
  1290. OpterID string `json:"opter_id"`
  1291. Begndate string `json:"begndate"`
  1292. FlxempeFlag string `json:"flxempe_flag"`
  1293. HifmiPay float64 `json:"hifmi_pay"`
  1294. PsnNo string `json:"psn_no"`
  1295. ActPayDedc float64 `json:"act_pay_dedc"`
  1296. MedinsSetlID interface{} `json:"medins_setl_id"`
  1297. AcctMulaidPay interface{} `json:"acct_mulaid_pay"`
  1298. ClrWay string `json:"clr_way"`
  1299. OthPay float64 `json:"oth_pay"`
  1300. Gend string `json:"gend"`
  1301. MdtrtID string `json:"mdtrt_id"`
  1302. AcctPay float64 `json:"acct_pay"`
  1303. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1304. Insutype string `json:"insutype"`
  1305. Invono interface{} `json:"invono"`
  1306. Enddate string `json:"enddate"`
  1307. CashPayamt float64 `json:"cash_payamt"`
  1308. PsnType string `json:"psn_type"`
  1309. FixmedinsName string `json:"fixmedins_name"`
  1310. HifpPay float64 `json:"hifp_pay"`
  1311. NewFlag interface{} `json:"new_flag"`
  1312. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1313. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1314. PayLoc string `json:"pay_loc"`
  1315. ClrType string `json:"clr_type"`
  1316. RefdSetlFlag string `json:"refd_setl_flag"`
  1317. CvlservFlag string `json:"cvlserv_flag"`
  1318. EmpName string `json:"emp_name"`
  1319. Brdy string `json:"brdy"`
  1320. Naty string `json:"naty"`
  1321. Certno string `json:"certno"`
  1322. DiseCode string `json:"dise_code"`
  1323. FixmedinsCode string `json:"fixmedins_code"`
  1324. DedcHospLv string `json:"dedc_hosp_lv"`
  1325. OpterName string `json:"opter_name"`
  1326. Balc float64 `json:"balc"`
  1327. FixmedinsPoolarea string `json:"fixmedins_poolarea"`
  1328. PsnCertType string `json:"psn_cert_type"`
  1329. HifobPay float64 `json:"hifob_pay"`
  1330. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1331. HifesPay float64 `json:"hifes_pay"`
  1332. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1333. OptTime string `json:"opt_time"`
  1334. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1335. SetlID string `json:"setl_id"`
  1336. MafPay float64 `json:"maf_pay"`
  1337. PsnName string `json:"psn_name"`
  1338. InsuOptins interface{} `json:"insu_optins"`
  1339. PrefFundPay interface{} `json:"pref_fund_pay"`
  1340. ClrOptins string `json:"clr_optins"`
  1341. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1342. DiseName string `json:"dise_name"`
  1343. LmtpricHospLv string `json:"lmtpric_hosp_lv"`
  1344. Age float64 `json:"age"`
  1345. DtrtCertType string `json:"dtrt_cert_type"`
  1346. HospLv string `json:"hosp_lv"`
  1347. } `json:"setlinfo"`
  1348. } `json:"output"`
  1349. RefmsgTime string `json:"refmsg_time"`
  1350. RespondTime string `json:"respond_time"`
  1351. Signtype interface{} `json:"signtype"`
  1352. WarnMsg interface{} `json:"warn_msg"`
  1353. }
  1354. type ResultTwelve struct {
  1355. Cainfo string `json:"cainfo"`
  1356. ErrMsg string `json:"err_msg"`
  1357. InfRefmsgid string `json:"inf_refmsgid"`
  1358. Infcode int64 `json:"infcode"`
  1359. Output struct {
  1360. MdtrtId string `json:"mdtrt_id"`
  1361. ChrgBchno string `json:"chrg_bchno"`
  1362. PsnNo string `json:"psn_no"`
  1363. } `json:"output"`
  1364. RefmsgTime string `json:"refmsg_time"`
  1365. RespondTime string `json:"respond_time"`
  1366. Signtype interface{} `json:"signtype"`
  1367. WarnMsg interface{} `json:"warn_msg"`
  1368. }
  1369. type ResultThirteen struct {
  1370. ErrMsg string `json:"err_msg"`
  1371. InfRefmsgid string `json:"inf_refmsgid"`
  1372. Infcode int64 `json:"infcode"`
  1373. Output struct {
  1374. Result struct {
  1375. TrtDclaDetlSn string `json:"trt_dcla_detl_sn"`
  1376. } `json:"result"`
  1377. } `json:"output"`
  1378. RefmsgTime string `json:"refmsg_time"`
  1379. RespondTime string `json:"respond_time"`
  1380. Signtype interface{} `json:"signtype"`
  1381. WarnInfo interface{} `json:"warn_info"`
  1382. }
  1383. type ResultFourteen struct {
  1384. ErrMsg string `json:"err_msg"`
  1385. InfRefmsgid string `json:"inf_refmsgid"`
  1386. Infcode int64 `json:"infcode"`
  1387. Output struct {
  1388. } `json:"output"`
  1389. RefmsgTime string `json:"refmsg_time"`
  1390. RespondTime string `json:"respond_time"`
  1391. Signtype interface{} `json:"signtype"`
  1392. WarnInfo interface{} `json:"warn_info"`
  1393. }
  1394. type ResultSixteen struct {
  1395. Cainfo string `json:"cainfo"`
  1396. ErrMsg string `json:"err_msg"`
  1397. InfRefmsgid string `json:"inf_refmsgid"`
  1398. Infcode int64 `json:"infcode"`
  1399. Output struct {
  1400. Setldetail []interface{} `json:"setldetail"`
  1401. Setlinfo struct {
  1402. MdtrtID string `json:"mdtrt_id"`
  1403. SetlID string `json:"setl_id"`
  1404. ClrOptins string `json:"clr_optins"`
  1405. SetlTime string `json:"setl_time"`
  1406. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1407. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1408. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1409. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1410. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1411. ActPayDedc float64 `json:"act_pay_dedc"`
  1412. HifpPay float64 `json:"hifp_pay"`
  1413. PoolPropSe float64 `json:"pool_prop_selfpay"`
  1414. Lfpay float64 `json:"selfpay"`
  1415. CvlservPay float64 `json:"cvlserv_pay"`
  1416. HifesPay float64 `json:"hifes_pay"`
  1417. HifmiPay float64 `json:"hifmi_pay"`
  1418. HifobPay float64 `json:"hifob_pay"`
  1419. MafPay float64 `json:"maf_pay"`
  1420. OthPay float64 `json:"oth_pay"`
  1421. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1422. PsnPartAmt float64 `json:"psn_part_amt"`
  1423. AcctPay float64 `json:"acct_pay"`
  1424. Balc float64 `json:"balc"`
  1425. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1426. HospPartAmt float64 `json:"hosp_part_amt"`
  1427. MedinsSetlID string `json:"medins_setl_id"`
  1428. PdnCashPay string `json:"pdn_cash_pay"`
  1429. } `json:"setlinfo"`
  1430. } `json:"output"`
  1431. RefmsgTime string `json:"refmsg_time"`
  1432. RespondTime string `json:"respond_time"`
  1433. Signtype interface{} `json:"signtype"`
  1434. WarnMsg interface{} `json:"warn_msg"`
  1435. }
  1436. type ResultSeventeen struct {
  1437. ErrMsg string `json:"err_msg"`
  1438. InfRefmsgid string `json:"inf_refmsgid"`
  1439. Infcode int64 `json:"infcode"`
  1440. Output struct {
  1441. SetlListId string `json:"setl_list_id"`
  1442. } `json:"output"`
  1443. RefmsgTime string `json:"refmsg_time"`
  1444. RespondTime string `json:"respond_time"`
  1445. Signtype string `json:"signtype"`
  1446. WarnInfo string `json:"warn_info"`
  1447. }
  1448. type Result90991 struct {
  1449. ErrMsg string `json:"err_msg"`
  1450. InfRefmsgid string `json:"inf_refmsgid"`
  1451. Infcode int64 `json:"infcode"`
  1452. Output struct {
  1453. Result struct {
  1454. PsnNo string `json:"psn_no"`
  1455. CardStat string `json:"card_stat"`
  1456. Certno string `json:"certno"`
  1457. PsnName string `json:"psn_name"`
  1458. CheckStat string `json:"check_stat"`
  1459. } `json:"result"`
  1460. } `json:"output"`
  1461. RefmsgTime string `json:"refmsg_time"`
  1462. RespondTime string `json:"respond_time"`
  1463. Signtype interface{} `json:"signtype"`
  1464. WarnInfo interface{} `json:"warn_info"`
  1465. }
  1466. type Result90100 struct {
  1467. ErrMsg string `json:"err_msg"`
  1468. InfRefmsgid string `json:"inf_refmsgid"`
  1469. Infcode int64 `json:"infcode"`
  1470. Output struct {
  1471. PoolareaNo string `json:"poolarea_no"`
  1472. PoolareaNoName string `json:"poolarea_no_name"`
  1473. Insutype string `json:"insutype"`
  1474. InsutypeName string `json:"insutype_name"`
  1475. ClctType string `json:"clct_type"`
  1476. ClctTypeName string `json:"clct_type_name"`
  1477. ClctFlag string `json:"clct_flag"`
  1478. ClctFlagName string `json:"clct_flag_name"`
  1479. AccrymBegn string `json:"accrym_begn"`
  1480. AccrymEnd string `json:"accrym_end"`
  1481. ClctTime string `json:"clct_time"`
  1482. ClctstdCrtfRuleCodg string `json:"clctstd_crtf_rule_codg"`
  1483. } `json:"output"`
  1484. RefmsgTime string `json:"refmsg_time"`
  1485. RespondTime string `json:"respond_time"`
  1486. Signtype interface{} `json:"signtype"`
  1487. WarnInfo interface{} `json:"warn_info"`
  1488. }
  1489. type Custom struct {
  1490. DetItemFeeSumamt string
  1491. Cut string
  1492. FeedetlSn string
  1493. Price string
  1494. MedListCodg string
  1495. Type int64
  1496. AdviceId int64
  1497. ProjectId int64
  1498. ItemId int64
  1499. }
  1500. //获取个人信息----挂号-----上传就诊信息
  1501. func (c *HisApiController) GetRegisterInfo() {
  1502. id, _ := c.GetInt64("id")
  1503. record_time := c.GetString("record_time")
  1504. settlementValue, _ := c.GetInt64("settlement_value")
  1505. medical_insurance_card := c.GetString("medical_insurance_card")
  1506. name := c.GetString("name")
  1507. id_card_type, _ := c.GetInt64("id_card_type")
  1508. certificates, _ := c.GetInt64("certificates")
  1509. medical_care, _ := c.GetInt64("medical_care")
  1510. birthday := c.GetString("birthday")
  1511. //age, _ := c.GetInt64("age")
  1512. id_card := c.GetString("id_card")
  1513. register_type, _ := c.GetInt64("register")
  1514. doctor, _ := c.GetInt64("doctor")
  1515. department, _ := c.GetInt64("department")
  1516. gender, _ := c.GetInt64("sex")
  1517. //phone := c.GetString("phone")
  1518. registration_fee, _ := c.GetFloat("registration_fee")
  1519. medical_expenses, _ := c.GetFloat("medical_expenses")
  1520. social_type, _ := c.GetInt64("social_type")
  1521. admin_user_id, _ := c.GetInt64("admin_user_id")
  1522. timeLayout := "2006-01-02"
  1523. loc, _ := time.LoadLocation("Local")
  1524. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  1525. birthUnix := birthdays.Unix()
  1526. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1527. if err != nil {
  1528. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1529. return
  1530. }
  1531. recordDateTime := theTime.Unix()
  1532. adminInfo := c.GetAdminUserInfo()
  1533. var patient service.Patients
  1534. if id == 0 {
  1535. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  1536. } else {
  1537. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  1538. }
  1539. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  1540. if patientPrescription.ID == 0 {
  1541. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  1542. }
  1543. //adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1544. //diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  1545. //sickConfig, _ := service.FindSickById(sick_type)
  1546. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1547. if patient.ID == 0 {
  1548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1549. return
  1550. }
  1551. if len(patient.IdCardNo) == 0 {
  1552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  1553. return
  1554. }
  1555. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  1556. roles, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1557. //就诊结算未完成,不能进行二次挂号
  1558. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  1559. if len(his) >= 1 {
  1560. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  1561. if len(his) >= 1 && order.ID == 0 {
  1562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  1563. return
  1564. }
  1565. }
  1566. var register_log string
  1567. if config.IsOpen == 1 {
  1568. //service.Gdyb1201("", miConfig.OrgName, "1122", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 1, "")
  1569. result, requestLog := service.Gdyb1101(patient.IdCardNo, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, "", strconv.FormatInt(certificates, 10))
  1570. //saveLog(result, requestLog)
  1571. register_log = requestLog + "\n" + "\n" + "\n" + result
  1572. var res ResultTwo
  1573. if err := json.Unmarshal([]byte(result), &res); err != nil {
  1574. utils.ErrorLog("解析失败:%v", err)
  1575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1576. return
  1577. }
  1578. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  1579. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  1580. infoStr := string(Iinfos)
  1581. idetinfoStr := string(Idetinfos)
  1582. if res.Infcode == 0 {
  1583. his := models.VMHisPatient{
  1584. Name: name,
  1585. Gender: gender,
  1586. Birthday: birthUnix,
  1587. MedicalTreatmentType: medical_care,
  1588. IdType: certificates,
  1589. IdCardNo: id_card,
  1590. BalanceAccountsType: settlementValue,
  1591. SocialType: social_type,
  1592. MedicalInsuranceNumber: medical_insurance_card,
  1593. RegisterType: register_type,
  1594. RegisterCost: registration_fee,
  1595. TreatmentCost: medical_expenses,
  1596. Status: 1,
  1597. Ctime: time.Now().Unix(),
  1598. Mtime: time.Now().Unix(),
  1599. PsnNo: res.Output.Baseinfo.PsnNo,
  1600. PsnCertType: res.Output.Baseinfo.PsnCertType,
  1601. Certno: res.Output.Baseinfo.Certno,
  1602. PsnName: res.Output.Baseinfo.PsnName,
  1603. Gend: res.Output.Baseinfo.Gend,
  1604. Naty: res.Output.Baseinfo.Naty,
  1605. Brdy: res.Output.Baseinfo.Brdy,
  1606. Age: res.Output.Baseinfo.Age,
  1607. Iinfo: infoStr,
  1608. Idetinfo: idetinfoStr,
  1609. PatientId: patient.ID,
  1610. RecordDate: theTime.Unix(),
  1611. UserOrgId: adminInfo.CurrentOrgId,
  1612. AdminUserId: admin_user_id,
  1613. IsReturn: 1,
  1614. IdCardType: id_card_type,
  1615. Doctor: doctor,
  1616. Departments: department,
  1617. }
  1618. timestamp := time.Now().Unix()
  1619. tempTime := time.Unix(timestamp, 0)
  1620. timeFormat := tempTime.Format("20060102150405")
  1621. chrgBchno := rand.Intn(100000) + 10000
  1622. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1623. //count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  1624. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1625. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  1626. IdCardNo := ""
  1627. if id_card_type == 1 {
  1628. // IdCardNo = medical_insurance_card
  1629. IdCardNo = patient.IdCardNo
  1630. } else {
  1631. IdCardNo = patient.IdCardNo
  1632. }
  1633. var insutypes []string
  1634. var insutype string
  1635. var is390 int = 0
  1636. var is310 int = 0
  1637. for _, item := range res.Output.Iinfo {
  1638. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1639. insutypes = append(insutypes, item.Insutype)
  1640. }
  1641. }
  1642. if len(insutypes) == 1 {
  1643. insutype = insutypes[0]
  1644. } else {
  1645. for _, i := range insutypes {
  1646. if i == "390" {
  1647. is390 = 1
  1648. }
  1649. if i == "310" {
  1650. is310 = 1
  1651. }
  1652. }
  1653. }
  1654. if is390 == 1 {
  1655. insutype = "390"
  1656. }
  1657. if is310 == 1 {
  1658. insutype = "310"
  1659. }
  1660. if len(insutypes) == 0 {
  1661. insutype = "310"
  1662. }
  1663. //insutype = "390"
  1664. result, requestLog := service.Gdyb2201(res.Output.Baseinfo.PsnNo, insutype, IdCardNo, miConfig.OrgName, roles.UserName, ipt_otp_no, department.Name, miConfig.Code, department.Number, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type)
  1665. register_log = register_log + requestLog + "\r\n" + "\r\n" + "\r\n" + result + "\r\n" + "\r\n" + "\r\n"
  1666. saveRegisterLog(register_log)
  1667. var res ResultThree
  1668. if err := json.Unmarshal([]byte(result), &res); err != nil {
  1669. utils.ErrorLog("解析失败:%v", err)
  1670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1671. return
  1672. }
  1673. if res.Infcode != 0 {
  1674. adminUser := c.GetAdminUserInfo()
  1675. errlog := &models.HisOrderError{
  1676. UserOrgId: adminUser.CurrentOrgId,
  1677. Ctime: time.Now().Unix(),
  1678. Mtime: time.Now().Unix(),
  1679. ErrMsg: res.ErrMsg,
  1680. Status: 1,
  1681. PatientId: id,
  1682. RecordTime: recordDateTime,
  1683. Stage: 2,
  1684. }
  1685. service.CreateErrMsgLog(errlog)
  1686. c.ServeSuccessJSON(map[string]interface{}{
  1687. "failed_code": -10,
  1688. "msg": res.ErrMsg,
  1689. })
  1690. return
  1691. }
  1692. his.Number = res.Output.Data.MdtrtID
  1693. his.PsnNo = res.Output.Data.PsnNo
  1694. his.IptOtpNo = res.Output.Data.IptOtpNo
  1695. his.IdCardNo = patient.IdCardNo
  1696. his.PhoneNumber = patient.Phone
  1697. his.UserOrgId = adminInfo.CurrentOrgId
  1698. his.Ctime = time.Now().Unix()
  1699. his.Mtime = time.Now().Unix()
  1700. his.Status = 1
  1701. service.UpdateHisPatientStatus(&his)
  1702. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  1703. c.ServeSuccessJSON(map[string]interface{}{
  1704. "his_info": his,
  1705. })
  1706. } else {
  1707. adminUser := c.GetAdminUserInfo()
  1708. errlog := &models.HisOrderError{
  1709. UserOrgId: adminUser.CurrentOrgId,
  1710. Ctime: time.Now().Unix(),
  1711. Mtime: time.Now().Unix(),
  1712. ErrMsg: res.ErrMsg,
  1713. Status: 1,
  1714. PatientId: id,
  1715. RecordTime: recordDateTime,
  1716. Stage: 1,
  1717. }
  1718. service.CreateErrMsgLog(errlog)
  1719. c.ServeSuccessJSON(map[string]interface{}{
  1720. "failed_code": -10,
  1721. "msg": res.ErrMsg,
  1722. })
  1723. return
  1724. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  1725. }
  1726. }
  1727. }
  1728. //上传明细----预结算----确认订单
  1729. func (c *HisApiController) GetUploadInfo() {
  1730. id, _ := c.GetInt64("id")
  1731. record_time := c.GetString("record_time")
  1732. his_patient_id, _ := c.GetInt64("his_patient_id")
  1733. order_id, _ := c.GetInt64("order_id")
  1734. pay_way, _ := c.GetInt64("pay_way")
  1735. pay_price, _ := c.GetFloat("pay_price")
  1736. pay_card_no := c.GetString("pay_card_no")
  1737. discount_price, _ := c.GetFloat("discount_price")
  1738. preferential_price, _ := c.GetFloat("preferential_price")
  1739. reality_price, _ := c.GetFloat("reality_price")
  1740. found_price, _ := c.GetFloat("found_price")
  1741. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1742. private_price, _ := c.GetFloat("private_price")
  1743. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1744. admin_user_id, _ := c.GetInt64("admin_user_id")
  1745. fapiao_code := c.GetString("fapiao_code")
  1746. fapiao_number := c.GetString("fapiao_number")
  1747. diagnosis_id := c.GetString("diagnosis")
  1748. sick_type, _ := c.GetInt64("sick_type")
  1749. reg_type, _ := c.GetInt64("p_type")
  1750. id_str := c.GetString("ids")
  1751. ids_arr := strings.Split(id_str, ",")
  1752. timeLayout := "2006-01-02"
  1753. loc, _ := time.LoadLocation("Local")
  1754. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1755. if err != nil {
  1756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1757. return
  1758. }
  1759. recordDateTime := theTime.Unix()
  1760. adminUser := c.GetAdminUserInfo()
  1761. var tempOrder models.HisOrder
  1762. tempOrder, _ = service.GetHisOrderByID(order_id)
  1763. var prescriptions []*models.HisPrescription
  1764. var start_time int64
  1765. var end_time int64
  1766. //if adminUser.CurrentOrgId == 10106{
  1767. // if len(fapiao_code) == 0{
  1768. // fapiao_code = "144072080589"
  1769. // }
  1770. // if len(fapiao_number) == 0{
  1771. // order, _ := service.GetLastHisOrder(adminUser.CurrentOrgId)
  1772. // if order.ID == 0{
  1773. // fapiao_number = "00001520"
  1774. // }else{
  1775. // //fapiao_code = "00001520"
  1776. // fpNumber, _ := strconv.Atoi(order.FaPiaoNumber)
  1777. // var zero string
  1778. // if fpNumber >= 1000{
  1779. // zero = "0000" + strconv.Itoa(fpNumber)
  1780. // }else if fpNumber >= 10000{
  1781. // zero = "000" + strconv.Itoa(fpNumber)
  1782. // } else if fpNumber >= 100000{
  1783. // zero = "00" + strconv.Itoa(fpNumber)
  1784. // } else if fpNumber >= 1000000{
  1785. // zero = "0" + strconv.Itoa(fpNumber)
  1786. // }else {
  1787. // zero = strconv.Itoa(fpNumber)
  1788. // }
  1789. // fapiao_number = zero
  1790. // }
  1791. // }
  1792. //}
  1793. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1794. his, _ := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  1795. var patientPrescription models.HisPrescriptionInfo
  1796. patientPrescription, _ = service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  1797. if patientPrescription.ID == 0 {
  1798. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1799. }
  1800. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1801. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1802. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  1803. diagnosis_ids := strings.Split(diagnosis_id, ",")
  1804. var config []*models.HisXtDiagnoseConfig
  1805. for _, item := range diagnosis_ids {
  1806. id, _ := strconv.ParseInt(item, 10, 64)
  1807. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1808. config = append(config, diagnosisConfig)
  1809. }
  1810. sickConfig, _ := service.FindSickById(sick_type)
  1811. if tempOrder.ID == 0 {
  1812. tempOrder, _ = service.GetTodayHisOrder(adminUser.CurrentOrgId, id, recordDateTime, his.Number)
  1813. }
  1814. if tempOrder.ID == 0 {
  1815. var result string
  1816. var requestLog string
  1817. if miConfig.InsuplcAdmdvs == "440781" { //
  1818. result, requestLog = service.Gdyb2203A(his.PsnNo, his.Number, doctor_info.UserName, department.Name, miConfig.OrgName, strconv.FormatInt(reg_type, 10), doctor_info.AdminUserId, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sickConfig.ContentCode, sickConfig.ClassName, roles.UserName, config)
  1819. } else {
  1820. result, requestLog = service.Gdyb2203(his.PsnNo, his.Number, doctor_info.UserName, department.Name, miConfig.OrgName, strconv.FormatInt(reg_type, 10), doctor_info.AdminUserId, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sickConfig.ContentCode, sickConfig.ClassName, roles.UserName, config)
  1821. }
  1822. saveLog(result, requestLog)
  1823. var respJSON2 map[string]interface{}
  1824. if err := json.Unmarshal([]byte(string(result)), &respJSON2); err != nil {
  1825. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1826. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1827. return
  1828. }
  1829. userJSONBytes2, _ := json.Marshal(respJSON2)
  1830. var res2 ResultSix
  1831. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  1832. utils.ErrorLog("解析失败:%v", err)
  1833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1834. return
  1835. }
  1836. if res2.Infcode != 0 {
  1837. adminUser := c.GetAdminUserInfo()
  1838. errlog := &models.HisOrderError{
  1839. UserOrgId: adminUser.CurrentOrgId,
  1840. Ctime: time.Now().Unix(),
  1841. Mtime: time.Now().Unix(),
  1842. ErrMsg: res2.ErrMsg,
  1843. Status: 1,
  1844. PatientId: id,
  1845. RecordTime: recordDateTime,
  1846. Stage: 3,
  1847. }
  1848. service.CreateErrMsgLog(errlog)
  1849. c.ServeSuccessJSON(map[string]interface{}{
  1850. "failed_code": -10,
  1851. "msg": res2.ErrMsg,
  1852. })
  1853. return
  1854. } else {
  1855. his.Diagnosis = diagnosis_id
  1856. his.SickType = sickConfig.ID
  1857. his.PType = fmt.Sprintf("%d", reg_type)
  1858. service.UpdateHisPatientThree(&his)
  1859. data := make(map[string]interface{})
  1860. if settle_accounts_type == 1 { //日结
  1861. if reg_type == 11 {
  1862. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  1863. } else {
  1864. prescriptions, _ = service.GetNewHisPrescription(adminUser.CurrentOrgId, his_patient_id, recordDateTime, strconv.Itoa(int(reg_type)))
  1865. }
  1866. //prescriptions, _ = service.GetNewHisPrescriptionTwo(adminUser.CurrentOrgId, his_patient_id, recordDateTime, reg_type)
  1867. data["pre"] = prescriptions
  1868. } else { //月结
  1869. start_time_str := c.GetString("start_time")
  1870. end_time_str := c.GetString("end_time")
  1871. timeLayout := "2006-01-02"
  1872. loc, _ := time.LoadLocation("Local")
  1873. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1874. if err != nil {
  1875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1876. return
  1877. }
  1878. recordStartTime := theStartTime.Unix()
  1879. start_time = recordStartTime
  1880. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1881. if err != nil {
  1882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1883. return
  1884. }
  1885. recordEndTime := theEndTime.Unix()
  1886. end_time = recordEndTime
  1887. prescriptions, _ = service.GetMonthHisPrescriptionTwo(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  1888. data["pre"] = prescriptions
  1889. }
  1890. if reg_type == 1111 || reg_type == 1112 {
  1891. reg_type = 11
  1892. }
  1893. timestamp := time.Now().Unix()
  1894. tempTime := time.Unix(timestamp, 0)
  1895. timeFormat := tempTime.Format("20060102150405")
  1896. chrgBchno := rand.Intn(100000) + 10000
  1897. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1898. strconv.FormatInt(his.PatientId, 10)
  1899. client := &http.Client{}
  1900. data["psn_no"] = his.PsnNo
  1901. data["mdtrt_id"] = his.Number
  1902. data["chrg_bchno"] = chrg_bchno
  1903. data["org_name"] = miConfig.OrgName
  1904. data["doctor"] = roles.UserName
  1905. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1906. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  1907. data["fixmedins_code"] = miConfig.Code
  1908. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  1909. data["dept_code"] = "15"
  1910. } else {
  1911. data["dept_code"] = department.Number
  1912. }
  1913. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1914. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1915. data["secret_key"] = miConfig.SecretKey
  1916. data["balance_accounts_type"] = strconv.FormatInt(his.BalanceAccountsType, 10)
  1917. var ids []int64
  1918. for _, item := range prescriptions {
  1919. ids = append(ids, item.ID)
  1920. }
  1921. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1922. if config.IsOpen == 1 { //对接了医保,走医保流程
  1923. bytesData, _ := json.Marshal(data)
  1924. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  1925. resp, _ := client.Do(req)
  1926. defer resp.Body.Close()
  1927. body, ioErr := ioutil.ReadAll(resp.Body)
  1928. if ioErr != nil {
  1929. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1931. return
  1932. }
  1933. var respJSON map[string]interface{}
  1934. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1935. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1937. return
  1938. }
  1939. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1940. userJSONBytes, _ := json.Marshal(respJSON)
  1941. request_respJSON := respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  1942. requestJSONBytes, _ := json.Marshal(request_respJSON)
  1943. saveLog(string(userJSONBytes), string(requestJSONBytes))
  1944. var res ResultFour
  1945. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1946. utils.ErrorLog("解析失败:%v", err)
  1947. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1948. return
  1949. }
  1950. if res.Infcode == 0 {
  1951. order := &models.HisOrder{
  1952. UserOrgId: adminUser.CurrentOrgId,
  1953. HisPatientId: his.ID,
  1954. PatientId: his.PatientId,
  1955. SettleAccountsDate: recordDateTime,
  1956. Ctime: time.Now().Unix(),
  1957. Mtime: time.Now().Unix(),
  1958. Status: 0,
  1959. Number: chrg_bchno,
  1960. Infcode: res.Infcode,
  1961. WarnMsg: res.WarnMsg,
  1962. Cainfo: res.Cainfo,
  1963. ErrMsg: res.ErrMsg,
  1964. RespondTime: res.RefmsgTime,
  1965. InfRefmsgid: res.InfRefmsgid,
  1966. OrderStatus: 1,
  1967. PayWay: pay_way,
  1968. PayPrice: pay_price,
  1969. PayCardNo: pay_card_no,
  1970. DiscountPrice: discount_price,
  1971. PreferentialPrice: preferential_price,
  1972. RealityPrice: reality_price,
  1973. FoundPrice: found_price,
  1974. MedicalInsurancePrice: medical_insurance_price,
  1975. PrivatePrice: private_price,
  1976. IsMedicineInsurance: 1,
  1977. SettleType: settle_accounts_type,
  1978. SettleStartTime: start_time,
  1979. SettleEndTime: end_time,
  1980. Creator: roles.AdminUserId,
  1981. Modify: roles.AdminUserId,
  1982. FaPiaoNumber: fapiao_number,
  1983. FaPiaoCode: fapiao_code,
  1984. PType: 2,
  1985. Diagnosis: diagnosis_id,
  1986. }
  1987. err = service.CreateOrder(order)
  1988. if err != nil {
  1989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1990. return
  1991. }
  1992. for _, item := range res.Output.Result {
  1993. temp := strings.Split(item.FeedetlSn, "-")
  1994. var advice_id int64 = 0
  1995. var project_id int64 = 0
  1996. var types int64 = 0
  1997. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1998. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1999. if temp[1] == "1" {
  2000. advice_id = id
  2001. project_id = 0
  2002. } else if temp[1] == "2" {
  2003. advice_id = 0
  2004. project_id = id
  2005. }
  2006. info := &models.HisOrderInfo{
  2007. OrderNumber: order.Number,
  2008. FeedetlSn: item.FeedetlSn,
  2009. UploadDate: time.Now().Unix(),
  2010. AdviceId: advice_id,
  2011. DetItemFeeSumamt: item.DetItemFeeSumamt,
  2012. Cnt: item.Cnt,
  2013. Pric: float64(item.Pric),
  2014. PatientId: his.PatientId,
  2015. PricUplmtAmt: item.PricUplmtAmt,
  2016. SelfpayProp: item.SelfpayProp,
  2017. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2018. OverlmtAmt: item.OverlmtAmt,
  2019. PreselfpayAmt: item.PreselfpayAmt,
  2020. BasMednFlag: item.BasMednFlag,
  2021. MedChrgitmType: item.MedChrgitmType,
  2022. HiNegoDrugFlag: item.HiNegoDrugFlag,
  2023. Status: 1,
  2024. Memo: item.Memo,
  2025. Mtime: time.Now().Unix(),
  2026. InscpScpAmt: item.InscpScpAmt,
  2027. DrtReimFlag: item.DrtReimFlag,
  2028. Ctime: time.Now().Unix(),
  2029. ListSpItemFlag: item.ListSpItemFlag,
  2030. ChldMedcFlag: item.ChldMedcFlag,
  2031. LmtUsedFlag: item.LmtUsedFlag,
  2032. ChrgitmLv: item.ChrgitmLv,
  2033. UserOrgId: adminUser.CurrentOrgId,
  2034. HisPatientId: his.ID,
  2035. OrderId: order.ID,
  2036. ProjectId: project_id,
  2037. Type: types,
  2038. }
  2039. service.CreateOrderInfo(info)
  2040. }
  2041. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2042. service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, his_patient_id, chrg_bchno, recordDateTime)
  2043. var total float64
  2044. for _, item := range prescriptions {
  2045. if item.Type == 1 { //药品
  2046. for _, subItem := range item.HisDoctorAdviceInfo {
  2047. total = total + (subItem.Price * subItem.PrescribingNumber)
  2048. }
  2049. }
  2050. if item.Type == 2 { //项目
  2051. for _, subItem := range item.HisPrescriptionProject {
  2052. total = total + (subItem.Price * float64(subItem.Count))
  2053. }
  2054. }
  2055. }
  2056. for _, item := range prescriptions {
  2057. for _, subItem := range item.HisAdditionalCharge {
  2058. total = total + (subItem.Price * float64(subItem.Count))
  2059. }
  2060. }
  2061. allTotal := fmt.Sprintf("%.2f", total)
  2062. if res.Infcode == 0 {
  2063. var rf []*ResultFive
  2064. json.Unmarshal([]byte(his.Iinfo), &rf)
  2065. chrg_bchno := chrg_bchno
  2066. cert_no := his.Certno
  2067. var insutypes []string
  2068. var insutype string
  2069. var is390 int = 0
  2070. var is310 int = 0
  2071. for _, item := range rf {
  2072. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  2073. insutypes = append(insutypes, item.Insutype)
  2074. }
  2075. }
  2076. if len(insutypes) == 1 {
  2077. insutype = insutypes[0]
  2078. } else {
  2079. for _, i := range insutypes {
  2080. if i == "390" {
  2081. is390 = 1
  2082. }
  2083. if i == "310" {
  2084. is310 = 1
  2085. }
  2086. }
  2087. }
  2088. if is390 == 1 {
  2089. insutype = "390"
  2090. }
  2091. if is310 == 1 {
  2092. insutype = "310"
  2093. }
  2094. if len(insutypes) == 0 {
  2095. insutype = "310"
  2096. }
  2097. //insutype = "390"
  2098. if his.IdCardType == 1 {
  2099. // cert_no = his.MedicalInsuranceNumber
  2100. cert_no = his.Certno
  2101. } else {
  2102. cert_no = his.Certno
  2103. }
  2104. result, src_resquest := service.Gdyb2207(his.PsnNo, his.Number, chrg_bchno, cert_no, insutype, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, strconv.FormatInt(reg_type, 10), his.IdCardType, 0, 0, 0, 0, his.IdType)
  2105. var dat map[string]interface{}
  2106. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2107. fmt.Println(dat)
  2108. } else {
  2109. fmt.Println(err)
  2110. }
  2111. saveLog(result, src_resquest)
  2112. userJSONBytes, _ := json.Marshal(dat)
  2113. var res ResultSeven
  2114. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2115. utils.ErrorLog("解析失败:%v", err)
  2116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2117. return
  2118. }
  2119. if res.Infcode != 0 {
  2120. errlog := &models.HisOrderError{
  2121. UserOrgId: adminUser.CurrentOrgId,
  2122. Ctime: time.Now().Unix(),
  2123. Mtime: time.Now().Unix(),
  2124. Number: chrg_bchno,
  2125. ErrMsg: res.ErrMsg,
  2126. Status: 1,
  2127. PatientId: id,
  2128. RecordTime: recordDateTime,
  2129. Stage: 6,
  2130. }
  2131. service.CreateErrMsgLog(errlog)
  2132. c.ServeSuccessJSON(map[string]interface{}{
  2133. "failed_code": -10,
  2134. "msg": res.ErrMsg,
  2135. })
  2136. return
  2137. } else {
  2138. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2139. order.OrderStatus = 2
  2140. order.Status = 1
  2141. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2142. order.SetlId = res.Output.Setlinfo.SetlID
  2143. order.PsnNo = res.Output.Setlinfo.PsnNo
  2144. order.PsnName = res.Output.Setlinfo.PsnName
  2145. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2146. order.Certno = res.Output.Setlinfo.Certno
  2147. order.Gend = res.Output.Setlinfo.Gend
  2148. order.Naty = res.Output.Setlinfo.Naty
  2149. order.Age = res.Output.Setlinfo.Age
  2150. order.Insutype = res.Output.Setlinfo.Insutype
  2151. order.PsnType = res.Output.Setlinfo.PsnType
  2152. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2153. order.SetlTime = res.Output.Setlinfo.SetlTime
  2154. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2155. order.MedType = res.Output.Setlinfo.MedType
  2156. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2157. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2158. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2159. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2160. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2161. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2162. order.HifpPay = res.Output.Setlinfo.HifpPay
  2163. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2164. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2165. order.HifesPay = res.Output.Setlinfo.HifesPay
  2166. order.HifobPay = res.Output.Setlinfo.HifobPay
  2167. order.MafPay = res.Output.Setlinfo.MafPay
  2168. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  2169. order.OthPay = res.Output.Setlinfo.OthPay
  2170. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2171. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2172. order.AcctPay = res.Output.Setlinfo.AcctPay
  2173. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2174. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2175. order.Balc = res.Output.Setlinfo.Balc
  2176. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2177. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2178. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2179. order.ClrWay = res.Output.Setlinfo.ClrWay
  2180. order.Creator = order.Creator
  2181. order.Modify = roles.AdminUserId
  2182. order.RequestLog = src_resquest
  2183. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2184. detailStr := string(setlDetail)
  2185. order.SetlDetail = detailStr
  2186. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2187. err = service.UpDateOrder(order)
  2188. if err == nil {
  2189. c.ServeSuccessJSON(map[string]interface{}{
  2190. "msg": "结算成功",
  2191. })
  2192. } else {
  2193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2194. return
  2195. }
  2196. }
  2197. } else {
  2198. adminUser := c.GetAdminUserInfo()
  2199. errlog := &models.HisOrderError{
  2200. UserOrgId: adminUser.CurrentOrgId,
  2201. Ctime: time.Now().Unix(),
  2202. Mtime: time.Now().Unix(),
  2203. ErrMsg: res.ErrMsg,
  2204. Status: 1,
  2205. PatientId: id,
  2206. RecordTime: recordDateTime,
  2207. Stage: 4,
  2208. }
  2209. service.CreateErrMsgLog(errlog)
  2210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2211. return
  2212. }
  2213. } else {
  2214. adminUser := c.GetAdminUserInfo()
  2215. errlog := &models.HisOrderError{
  2216. UserOrgId: adminUser.CurrentOrgId,
  2217. Ctime: time.Now().Unix(),
  2218. Mtime: time.Now().Unix(),
  2219. ErrMsg: res.ErrMsg,
  2220. Status: 1,
  2221. PatientId: id,
  2222. RecordTime: recordDateTime,
  2223. Stage: 4,
  2224. }
  2225. service.CreateErrMsgLog(errlog)
  2226. c.ServeSuccessJSON(map[string]interface{}{
  2227. "failed_code": -10,
  2228. "msg": res.ErrMsg,
  2229. })
  2230. return
  2231. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  2232. //return
  2233. }
  2234. }
  2235. }
  2236. } else if tempOrder.ID > 0 {
  2237. if tempOrder.IsPre == 1 {
  2238. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  2239. var rf []*ResultFive
  2240. json.Unmarshal([]byte(his.Iinfo), &rf)
  2241. chrg_bchno := tempOrder.Number
  2242. cert_no := his.Certno
  2243. var insutypes []string
  2244. var insutype string
  2245. var is390 int = 0
  2246. var is310 int = 0
  2247. for _, item := range rf {
  2248. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  2249. insutypes = append(insutypes, item.Insutype)
  2250. }
  2251. }
  2252. if len(insutypes) == 1 {
  2253. insutype = insutypes[0]
  2254. } else {
  2255. for _, i := range insutypes {
  2256. if i == "390" {
  2257. is390 = 1
  2258. }
  2259. if i == "310" {
  2260. is310 = 1
  2261. }
  2262. }
  2263. }
  2264. if is390 == 1 {
  2265. insutype = "390"
  2266. }
  2267. if is310 == 1 {
  2268. insutype = "310"
  2269. }
  2270. if len(insutypes) == 0 {
  2271. insutype = "310"
  2272. }
  2273. //insutype = "390"
  2274. if his.IdCardType == 1 {
  2275. // cert_no = his.MedicalInsuranceNumber
  2276. cert_no = his.Certno
  2277. } else {
  2278. cert_no = his.Certno
  2279. }
  2280. result, src_resquest := service.Gdyb2207(his.PsnNo, his.Number, chrg_bchno, cert_no, insutype, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, strconv.FormatInt(reg_type, 10), his.IdCardType, tempOrder.FulamtOwnpayAmt, tempOrder.OverlmtSelfPay, tempOrder.PreselfpayAmt, tempOrder.InscpScpAmt, his.IdType)
  2281. var dat map[string]interface{}
  2282. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2283. fmt.Println(dat)
  2284. } else {
  2285. fmt.Println(err)
  2286. }
  2287. saveLog(result, src_resquest)
  2288. userJSONBytes, _ := json.Marshal(dat)
  2289. var res ResultSeven
  2290. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2291. utils.ErrorLog("解析失败:%v", err)
  2292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2293. return
  2294. }
  2295. if res.Infcode != 0 {
  2296. errlog := &models.HisOrderError{
  2297. UserOrgId: adminUser.CurrentOrgId,
  2298. Ctime: time.Now().Unix(),
  2299. Mtime: time.Now().Unix(),
  2300. Number: chrg_bchno,
  2301. ErrMsg: res.ErrMsg,
  2302. Status: 1,
  2303. PatientId: id,
  2304. RecordTime: recordDateTime,
  2305. Stage: 6,
  2306. }
  2307. service.CreateErrMsgLog(errlog)
  2308. c.ServeSuccessJSON(map[string]interface{}{
  2309. "failed_code": -10,
  2310. "msg": res.ErrMsg,
  2311. })
  2312. return
  2313. } else {
  2314. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2315. order.OrderStatus = 2
  2316. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2317. order.SetlId = res.Output.Setlinfo.SetlID
  2318. order.PsnNo = res.Output.Setlinfo.PsnNo
  2319. order.PsnName = res.Output.Setlinfo.PsnName
  2320. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2321. order.Certno = res.Output.Setlinfo.Certno
  2322. order.Gend = res.Output.Setlinfo.Gend
  2323. order.Naty = res.Output.Setlinfo.Naty
  2324. order.Age = res.Output.Setlinfo.Age
  2325. order.Insutype = res.Output.Setlinfo.Insutype
  2326. order.PsnType = res.Output.Setlinfo.PsnType
  2327. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2328. order.SetlTime = res.Output.Setlinfo.SetlTime
  2329. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2330. order.MedType = res.Output.Setlinfo.MedType
  2331. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2332. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2333. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2334. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2335. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2336. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2337. order.HifpPay = res.Output.Setlinfo.HifpPay
  2338. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2339. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2340. order.HifesPay = res.Output.Setlinfo.HifesPay
  2341. order.HifobPay = res.Output.Setlinfo.HifobPay
  2342. order.MafPay = res.Output.Setlinfo.MafPay
  2343. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  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. order.Diagnosis = diagnosis_id
  2359. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2360. detailStr := string(setlDetail)
  2361. order.SetlDetail = detailStr
  2362. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2363. err = service.UpDateOrder(order)
  2364. if err == nil {
  2365. c.ServeSuccessJSON(map[string]interface{}{
  2366. "msg": "结算成功",
  2367. })
  2368. } else {
  2369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2370. return
  2371. }
  2372. }
  2373. }
  2374. }
  2375. }
  2376. //func (c *HisApiController) GetPreUploadInfo() {
  2377. // id, _ := c.GetInt64("id")
  2378. // record_time := c.GetString("record_time")
  2379. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2380. // admin_user_id, _ := c.GetInt64("admin_user_id")
  2381. //
  2382. // timeLayout := "2006-01-02"
  2383. // loc, _ := time.LoadLocation("Local")
  2384. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2385. // if err != nil {
  2386. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2387. // return
  2388. // }
  2389. // recordDateTime := theTime.Unix()
  2390. // adminUser := c.GetAdminUserInfo()
  2391. //
  2392. // var prescriptions []*models.HisPrescription
  2393. //
  2394. // var start_time int64
  2395. // var end_time int64
  2396. //
  2397. // data := make(map[string]interface{})
  2398. // if settle_accounts_type == 1 { //日结
  2399. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  2400. // data["pre"] = prescriptions
  2401. //
  2402. // } else { //月结
  2403. // start_time_str := c.GetString("start_time")
  2404. // end_time_str := c.GetString("end_time")
  2405. // timeLayout := "2006-01-02"
  2406. // loc, _ := time.LoadLocation("Local")
  2407. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2408. // if err != nil {
  2409. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2410. // return
  2411. // }
  2412. // recordStartTime := theStartTime.Unix()
  2413. // start_time = recordStartTime
  2414. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2415. // if err != nil {
  2416. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2417. // return
  2418. // }
  2419. // recordEndTime := theEndTime.Unix()
  2420. // end_time = recordEndTime
  2421. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  2422. // data["pre"] = prescriptions
  2423. //
  2424. // }
  2425. //
  2426. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2427. //
  2428. // his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2429. // timestamp := time.Now().Unix()
  2430. // tempTime := time.Unix(timestamp, 0)
  2431. // timeFormat := tempTime.Format("20060102150405")
  2432. // chrgBchno := rand.Intn(100000) + 10000
  2433. // chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  2434. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2435. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2436. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  2437. // strconv.FormatInt(his.PatientId, 10)
  2438. // client := &http.Client{}
  2439. // data["psn_no"] = his.PsnNo
  2440. // data["mdtrt_id"] = his.Number
  2441. // data["chrg_bchno"] = chrg_bchno
  2442. // data["org_name"] = miConfig.OrgName
  2443. // data["doctor"] = roles.UserName
  2444. // data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  2445. // data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  2446. // data["fixmedins_code"] = miConfig.Code
  2447. // data["dept_code"] = department.Number
  2448. // data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  2449. // data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  2450. // data["secret_key"] = miConfig.SecretKey
  2451. // var ids []int64
  2452. //
  2453. // for _, item := range prescriptions {
  2454. // ids = append(ids, item.ID)
  2455. // }
  2456. // config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2457. // if config.IsOpen == 1 { //对接了医保,走医保流程
  2458. // bytesData, _ := json.Marshal(data)
  2459. // req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  2460. // resp, _ := client.Do(req)
  2461. // defer resp.Body.Close()
  2462. // body, ioErr := ioutil.ReadAll(resp.Body)
  2463. // if ioErr != nil {
  2464. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2465. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2466. // return
  2467. // }
  2468. // var respJSON map[string]interface{}
  2469. // if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  2470. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2471. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2472. // return
  2473. // }
  2474. //
  2475. // respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2476. // userJSONBytes, _ := json.Marshal(respJSON)
  2477. // var res ResultFour
  2478. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2479. // utils.ErrorLog("解析失败:%v", err)
  2480. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2481. // return
  2482. // }
  2483. //
  2484. // if res.Infcode == 0 {
  2485. // order := &models.HisOrder{
  2486. // UserOrgId: adminUser.CurrentOrgId,
  2487. // HisPatientId: his.ID,
  2488. // PatientId: his.PatientId,
  2489. // SettleAccountsDate: recordDateTime,
  2490. // Ctime: time.Now().Unix(),
  2491. // Mtime: time.Now().Unix(),
  2492. // Status: 1,
  2493. // Number: chrg_bchno,
  2494. // Infcode: res.Infcode,
  2495. // WarnMsg: res.WarnMsg,
  2496. // Cainfo: res.Cainfo,
  2497. // ErrMsg: res.ErrMsg,
  2498. // RespondTime: res.RefmsgTime,
  2499. // InfRefmsgid: res.InfRefmsgid,
  2500. // OrderStatus: 1,
  2501. // IsMedicineInsurance: 1,
  2502. // SettleType: settle_accounts_type,
  2503. // SettleStartTime: start_time,
  2504. // SettleEndTime: end_time,
  2505. // Creator: roles.ID,
  2506. // Modify: roles.ID,
  2507. // PType: 2,
  2508. // }
  2509. // err = service.CreateOrder(order)
  2510. // if err != nil {
  2511. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2512. // return
  2513. // }
  2514. //
  2515. // for _, item := range res.Output.Result {
  2516. // temp := strings.Split(item.FeedetlSn, "-")
  2517. // var advice_id int64 = 0
  2518. // var project_id int64 = 0
  2519. // var types int64 = 0
  2520. //
  2521. // id, _ := strconv.ParseInt(temp[2], 10, 64)
  2522. // types, _ = strconv.ParseInt(temp[1], 10, 64)
  2523. //
  2524. // if temp[1] == "1" {
  2525. // advice_id = id
  2526. // project_id = 0
  2527. // } else if temp[1] == "2" {
  2528. // advice_id = 0
  2529. // project_id = id
  2530. // }
  2531. //
  2532. // info := &models.HisOrderInfo{
  2533. // OrderNumber: order.Number,
  2534. // FeedetlSn: item.FeedetlSn,
  2535. // UploadDate: time.Now().Unix(),
  2536. // AdviceId: advice_id,
  2537. // DetItemFeeSumamt: item.DetItemFeeSumamt,
  2538. // Cnt: item.Cnt,
  2539. // Pric: float64(item.Pric),
  2540. // PatientId: his.PatientId,
  2541. // PricUplmtAmt: item.PricUplmtAmt,
  2542. // SelfpayProp: item.SelfpayProp,
  2543. // FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2544. // OverlmtAmt: item.OverlmtAmt,
  2545. // PreselfpayAmt: item.PreselfpayAmt,
  2546. // BasMednFlag: item.BasMednFlag,
  2547. // MedChrgitmType: item.MedChrgitmType,
  2548. // HiNegoDrugFlag: item.HiNegoDrugFlag,
  2549. // Status: 1,
  2550. // Memo: item.Memo,
  2551. // Mtime: time.Now().Unix(),
  2552. // InscpScpAmt: item.InscpScpAmt,
  2553. // DrtReimFlag: item.DrtReimFlag,
  2554. // Ctime: time.Now().Unix(),
  2555. // ListSpItemFlag: item.ListSpItemFlag,
  2556. // ChldMedcFlag: item.ChldMedcFlag,
  2557. // LmtUsedFlag: item.LmtUsedFlag,
  2558. // ChrgitmLv: item.ChrgitmLv,
  2559. // UserOrgId: adminUser.CurrentOrgId,
  2560. // HisPatientId: his.ID,
  2561. // OrderId: order.ID,
  2562. // ProjectId: project_id,
  2563. // Type: types,
  2564. // }
  2565. // service.CreateOrderInfo(info)
  2566. //
  2567. // }
  2568. // service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2569. // service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  2570. //
  2571. // var total float64
  2572. // for _, item := range prescriptions {
  2573. // if item.Type == 1 { //药品
  2574. // for _, subItem := range item.HisDoctorAdviceInfo {
  2575. // total = total + (subItem.Price * subItem.PrescribingNumber)
  2576. // }
  2577. // }
  2578. // if item.Type == 2 { //项目
  2579. // for _, subItem := range item.HisPrescriptionProject {
  2580. // total = total + (subItem.Price * float64(subItem.Count))
  2581. // }
  2582. // }
  2583. // }
  2584. //
  2585. // for _, item := range prescriptions {
  2586. // for _, subItem := range item.HisAdditionalCharge {
  2587. // total = total + (subItem.Price * float64(subItem.Count))
  2588. // }
  2589. // }
  2590. //
  2591. // allTotal := fmt.Sprintf("%.2f", total)
  2592. // if res.Infcode == 0 {
  2593. // var rf []*ResultFive
  2594. // json.Unmarshal([]byte(his.Iinfo), &rf)
  2595. // psn_no := his.PsnNo
  2596. // mdtrt_id := his.Number
  2597. // chrg_bchno := chrg_bchno
  2598. // cert_no := his.Certno
  2599. // insutype := rf[0].Insutype
  2600. //
  2601. // if his.IdCardType == 1 {
  2602. // cert_no = his.MedicalInsuranceNumber
  2603. //
  2604. // } else {
  2605. //
  2606. // cert_no = his.Certno
  2607. //
  2608. // }
  2609. //
  2610. // api := "http://127.0.0.1:9532/" + "gdyb/seven?cert_no=" + cert_no + "&insutype=" +
  2611. // insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  2612. // "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  2613. // miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10)
  2614. // resp, requestErr := http.Get(api)
  2615. // if requestErr != nil {
  2616. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2617. // return
  2618. // }
  2619. // defer resp.Body.Close()
  2620. // body, ioErr := ioutil.ReadAll(resp.Body)
  2621. // if ioErr != nil {
  2622. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2623. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2624. // return
  2625. // }
  2626. // var respJSON map[string]interface{}
  2627. // if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2628. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2629. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2630. // return
  2631. // }
  2632. // fmt.Println(respJSON)
  2633. // respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2634. // userJSONBytes, _ := json.Marshal(respJSON)
  2635. // var res ResultSeven
  2636. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2637. // utils.ErrorLog("解析失败:%v", err)
  2638. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2639. // return
  2640. // }
  2641. // if res.Infcode != 0 {
  2642. // errlog := &models.HisOrderError{
  2643. // UserOrgId: adminUser.CurrentOrgId,
  2644. // Ctime: time.Now().Unix(),
  2645. // Mtime: time.Now().Unix(),
  2646. // Number: chrg_bchno,
  2647. // ErrMsg: res.ErrMsg,
  2648. // Status: 1,
  2649. // PatientId: id,
  2650. // RecordTime: recordDateTime,
  2651. // Stage: 7,
  2652. // }
  2653. // service.CreateErrMsgLog(errlog)
  2654. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2655. // return
  2656. // } else {
  2657. // order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2658. // order.OrderStatus = 1
  2659. // order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2660. // order.SetlId = res.Output.Setlinfo.SetlID
  2661. // order.PsnNo = res.Output.Setlinfo.PsnNo
  2662. // order.PsnName = res.Output.Setlinfo.PsnName
  2663. // order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2664. // order.Certno = res.Output.Setlinfo.Certno
  2665. // order.Gend = res.Output.Setlinfo.Gend
  2666. // order.Naty = res.Output.Setlinfo.Naty
  2667. // order.Age = res.Output.Setlinfo.Age
  2668. // order.Insutype = res.Output.Setlinfo.Insutype
  2669. // order.PsnType = res.Output.Setlinfo.PsnType
  2670. // order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2671. // order.SetlTime = res.Output.Setlinfo.SetlTime
  2672. // order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2673. // order.MedType = res.Output.Setlinfo.MedType
  2674. // order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2675. // order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2676. // order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2677. // order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2678. // order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2679. // order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2680. // order.HifpPay = res.Output.Setlinfo.HifpPay
  2681. // order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2682. // order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2683. // order.HifesPay = res.Output.Setlinfo.HifesPay
  2684. // order.HifobPay = res.Output.Setlinfo.HifobPay
  2685. // order.MafPay = res.Output.Setlinfo.MafPay
  2686. // order.OthPay = res.Output.Setlinfo.OthPay
  2687. // order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2688. // order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2689. // order.AcctPay = res.Output.Setlinfo.AcctPay
  2690. // order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2691. // order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2692. // order.Balc = res.Output.Setlinfo.Balc
  2693. // order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2694. // order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2695. // order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2696. // order.ClrWay = res.Output.Setlinfo.ClrWay
  2697. // order.Creator = order.Creator
  2698. // order.Modify = roles.ID
  2699. // setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2700. // detailStr := string(setlDetail)
  2701. // order.SetlDetail = detailStr
  2702. // //err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2703. // err = service.UpDateOrder(order)
  2704. // if err == nil {
  2705. // c.ServeSuccessJSON(map[string]interface{}{
  2706. // "msg": "预结算成功",
  2707. // })
  2708. // } else {
  2709. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2710. // return
  2711. // }
  2712. // }
  2713. // } else {
  2714. // adminUser := c.GetAdminUserInfo()
  2715. // errlog := &models.HisOrderError{
  2716. // UserOrgId: adminUser.CurrentOrgId,
  2717. // Ctime: time.Now().Unix(),
  2718. // Mtime: time.Now().Unix(),
  2719. // ErrMsg: res.ErrMsg,
  2720. // Status: 1,
  2721. // PatientId: id,
  2722. // RecordTime: recordDateTime,
  2723. // Stage: 4,
  2724. // }
  2725. // service.CreateErrMsgLog(errlog)
  2726. //
  2727. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2728. // return
  2729. // }
  2730. // } else {
  2731. // adminUser := c.GetAdminUserInfo()
  2732. // errlog := &models.HisOrderError{
  2733. // UserOrgId: adminUser.CurrentOrgId,
  2734. // Ctime: time.Now().Unix(),
  2735. // Mtime: time.Now().Unix(),
  2736. // ErrMsg: res.ErrMsg,
  2737. // Status: 1,
  2738. // PatientId: id,
  2739. // RecordTime: recordDateTime,
  2740. // Stage: 4,
  2741. // }
  2742. // service.CreateErrMsgLog(errlog)
  2743. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  2744. // return
  2745. // }
  2746. //
  2747. // } else {
  2748. // var total float64
  2749. // for _, item := range prescriptions {
  2750. // if item.Type == 1 { //药品
  2751. // for _, subItem := range item.HisDoctorAdviceInfo {
  2752. // total = total + (subItem.Price * subItem.PrescribingNumber)
  2753. // }
  2754. // }
  2755. // if item.Type == 2 { //项目
  2756. // for _, subItem := range item.HisPrescriptionProject {
  2757. // total = total + (subItem.Price * float64(subItem.Count))
  2758. // }
  2759. // }
  2760. //
  2761. // for _, subItem := range item.HisAdditionalCharge {
  2762. // total = total + (subItem.Price * float64(subItem.Count))
  2763. // }
  2764. // }
  2765. //
  2766. // allTotal := fmt.Sprintf("%.2f", total)
  2767. // totals, _ := strconv.ParseFloat(allTotal, 64)
  2768. // order := &models.HisOrder{
  2769. // UserOrgId: adminUser.CurrentOrgId,
  2770. // HisPatientId: his.ID,
  2771. // PatientId: id,
  2772. // SettleAccountsDate: recordDateTime,
  2773. // Ctime: time.Now().Unix(),
  2774. // Mtime: time.Now().Unix(),
  2775. // Status: 1,
  2776. // OrderStatus: 2,
  2777. // Number: chrg_bchno,
  2778. // MedfeeSumamt: totals,
  2779. // }
  2780. // err = service.CreateOrder(order)
  2781. // if err != nil {
  2782. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2783. // return
  2784. // }
  2785. //
  2786. // var customs []*Custom
  2787. // for _, item := range prescriptions {
  2788. //
  2789. // if item.Type == 1 { //药品
  2790. // for _, subItem := range item.HisDoctorAdviceInfo {
  2791. // cus := &Custom{
  2792. // AdviceId: subItem.ID,
  2793. // ProjectId: 0,
  2794. // DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  2795. // Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  2796. // FeedetlSn: subItem.FeedetlSn,
  2797. // Price: fmt.Sprintf("%.2f", subItem.Price),
  2798. // MedListCodg: subItem.MedListCodg,
  2799. // Type: 1,
  2800. // }
  2801. // customs = append(customs, cus)
  2802. // }
  2803. // }
  2804. //
  2805. // if item.Type == 2 { //项目
  2806. // for _, subItem := range item.HisPrescriptionProject {
  2807. //
  2808. // cus := &Custom{
  2809. // AdviceId: 0,
  2810. // ProjectId: subItem.ID,
  2811. // DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  2812. // Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  2813. // FeedetlSn: subItem.FeedetlSn,
  2814. // Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  2815. // MedListCodg: subItem.MedListCodg,
  2816. // Type: 2,
  2817. // }
  2818. //
  2819. // customs = append(customs, cus)
  2820. // }
  2821. // }
  2822. //
  2823. // for _, item := range item.HisAdditionalCharge {
  2824. // cus := &Custom{
  2825. // ItemId: item.ID,
  2826. // AdviceId: 0,
  2827. // ProjectId: 0,
  2828. // DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  2829. // Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  2830. // FeedetlSn: item.FeedetlSn,
  2831. // Price: fmt.Sprintf("%.2f", float64(item.Price)),
  2832. // MedListCodg: item.XtHisAddtionConfig.Code,
  2833. // Type: 3,
  2834. // }
  2835. //
  2836. // customs = append(customs, cus)
  2837. // }
  2838. //
  2839. // }
  2840. //
  2841. // for _, item := range customs {
  2842. // var advice_id int64 = 0
  2843. // var project_id int64 = 0
  2844. // var item_id int64 = 0
  2845. //
  2846. // var types int64 = 0
  2847. //
  2848. // if item.Type == 1 {
  2849. // advice_id = item.AdviceId
  2850. // project_id = 0
  2851. // item_id = 0
  2852. // } else if item.Type == 2 {
  2853. // advice_id = 0
  2854. // item_id = 0
  2855. //
  2856. // project_id = item.ProjectId
  2857. // } else if item.Type == 3 {
  2858. // advice_id = 0
  2859. // item_id = item.ItemId
  2860. // project_id = 0
  2861. // }
  2862. //
  2863. // detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  2864. // cut, _ := strconv.ParseFloat(item.Cut, 32)
  2865. // pric, _ := strconv.ParseFloat(item.Price, 32)
  2866. //
  2867. // info := &models.HisOrderInfo{
  2868. // OrderNumber: order.Number,
  2869. // UploadDate: time.Now().Unix(),
  2870. // AdviceId: advice_id,
  2871. // DetItemFeeSumamt: detItemFeeSumamt,
  2872. // Cnt: cut,
  2873. // Pric: pric,
  2874. // PatientId: id,
  2875. // Status: 1,
  2876. // Mtime: time.Now().Unix(),
  2877. // Ctime: time.Now().Unix(),
  2878. // UserOrgId: adminUser.CurrentOrgId,
  2879. // HisPatientId: his.ID,
  2880. // OrderId: order.ID,
  2881. // ProjectId: project_id,
  2882. // Type: types,
  2883. // ItemId: item_id,
  2884. // }
  2885. // service.CreateOrderInfo(info)
  2886. // }
  2887. // //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2888. // err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2889. // err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  2890. // err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2891. // if err == nil {
  2892. // c.ServeSuccessJSON(map[string]interface{}{
  2893. // "msg": "结算成功",
  2894. // })
  2895. // } else {
  2896. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2897. // return
  2898. // }
  2899. // }
  2900. //}
  2901. //上传明细-预结算-
  2902. func (c *HisApiController) GetPreUploadInfo() {
  2903. id, _ := c.GetInt64("id")
  2904. record_time := c.GetString("record_time")
  2905. his_patient_id, _ := c.GetInt64("his_patient_id")
  2906. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2907. admin_user_id, _ := c.GetInt64("admin_user_id")
  2908. diagnosis_id := c.GetString("diagnosis")
  2909. sick_type, _ := c.GetInt64("sick_type")
  2910. reg_type, _ := c.GetInt64("p_type")
  2911. id_str := c.GetString("ids")
  2912. ids_arr := strings.Split(id_str, ",")
  2913. timeLayout := "2006-01-02"
  2914. loc, _ := time.LoadLocation("Local")
  2915. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2916. if err != nil {
  2917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2918. return
  2919. }
  2920. recordDateTime := theTime.Unix()
  2921. adminUser := c.GetAdminUserInfo()
  2922. diagnosis_ids := strings.Split(diagnosis_id, ",")
  2923. var config []*models.HisXtDiagnoseConfig
  2924. for _, item := range diagnosis_ids {
  2925. id, _ := strconv.ParseInt(item, 10, 64)
  2926. diagnosisConfig, _ := service.FindDiagnoseById(id)
  2927. config = append(config, diagnosisConfig)
  2928. }
  2929. //diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  2930. sickConfig, _ := service.FindSickById(sick_type)
  2931. var prescriptions []*models.HisPrescription
  2932. var start_time int64
  2933. var end_time int64
  2934. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2935. fmt.Println(his_patient_id)
  2936. his, _ := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2937. timestamp := time.Now().Unix()
  2938. tempTime := time.Unix(timestamp, 0)
  2939. timeFormat := tempTime.Format("20060102150405")
  2940. chrgBchno := rand.Intn(100000) + 10000
  2941. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  2942. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2943. var patientPrescription models.HisPrescriptionInfo
  2944. patientPrescription, _ = service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2945. if patientPrescription.ID == 0 {
  2946. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2947. }
  2948. //miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2949. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  2950. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  2951. strconv.FormatInt(his.PatientId, 10)
  2952. var result string
  2953. var requestLog string
  2954. if miConfig.InsuplcAdmdvs == "440781" { //
  2955. result, requestLog = service.Gdyb2203A(his.PsnNo, his.Number, doctor_info.UserName, department.Name, miConfig.OrgName, strconv.FormatInt(reg_type, 10), doctor_info.AdminUserId, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sickConfig.ContentCode, sickConfig.ClassName, roles.UserName, config)
  2956. } else {
  2957. result, requestLog = service.Gdyb2203(his.PsnNo, his.Number, doctor_info.UserName, department.Name, miConfig.OrgName, strconv.FormatInt(reg_type, 10), doctor_info.AdminUserId, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sickConfig.CountryCode, sickConfig.ClassName, roles.UserName, config)
  2958. }
  2959. saveLog(result, requestLog)
  2960. var respJSON2 map[string]interface{}
  2961. if err := json.Unmarshal([]byte(string(result)), &respJSON2); err != nil {
  2962. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2964. return
  2965. }
  2966. userJSONBytes2, _ := json.Marshal(respJSON2)
  2967. var res2 ResultSix
  2968. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  2969. utils.ErrorLog("解析失败:%v", err)
  2970. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2971. return
  2972. }
  2973. if res2.Infcode != 0 {
  2974. adminUser := c.GetAdminUserInfo()
  2975. errlog := &models.HisOrderError{
  2976. UserOrgId: adminUser.CurrentOrgId,
  2977. Ctime: time.Now().Unix(),
  2978. Mtime: time.Now().Unix(),
  2979. ErrMsg: res2.ErrMsg,
  2980. Status: 1,
  2981. PatientId: id,
  2982. RecordTime: recordDateTime,
  2983. Stage: 3,
  2984. }
  2985. service.CreateErrMsgLog(errlog)
  2986. c.ServeSuccessJSON(map[string]interface{}{
  2987. "failed_code": -10,
  2988. "msg": res2.ErrMsg,
  2989. })
  2990. return
  2991. } else {
  2992. his.Diagnosis = diagnosis_id
  2993. his.SickType = sickConfig.ID
  2994. his.PType = fmt.Sprintf("%d", reg_type)
  2995. service.UpdateHisPatientThree(&his)
  2996. data := make(map[string]interface{})
  2997. if settle_accounts_type == 1 { //日结
  2998. if reg_type == 11 {
  2999. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  3000. } else {
  3001. prescriptions, _ = service.GetNewHisPrescription(adminUser.CurrentOrgId, his_patient_id, recordDateTime, strconv.Itoa(int(reg_type)))
  3002. }
  3003. data["pre"] = prescriptions
  3004. } else { //月结
  3005. start_time_str := c.GetString("start_time")
  3006. end_time_str := c.GetString("end_time")
  3007. timeLayout := "2006-01-02"
  3008. loc, _ := time.LoadLocation("Local")
  3009. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3010. if err != nil {
  3011. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3012. return
  3013. }
  3014. recordStartTime := theStartTime.Unix()
  3015. start_time = recordStartTime
  3016. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3017. if err != nil {
  3018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3019. return
  3020. }
  3021. recordEndTime := theEndTime.Unix()
  3022. end_time = recordEndTime
  3023. prescriptions, _ = service.GetMonthHisPrescriptionTwo(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  3024. data["pre"] = prescriptions
  3025. }
  3026. if reg_type == 1111 || reg_type == 1112 {
  3027. reg_type = 11
  3028. }
  3029. client := &http.Client{}
  3030. data["psn_no"] = his.PsnNo
  3031. data["mdtrt_id"] = his.Number
  3032. data["chrg_bchno"] = chrg_bchno
  3033. data["org_name"] = miConfig.OrgName
  3034. data["doctor"] = roles.UserName
  3035. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  3036. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  3037. data["fixmedins_code"] = miConfig.Code
  3038. data["balance_accounts_type"] = strconv.FormatInt(his.BalanceAccountsType, 10)
  3039. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  3040. data["dept_code"] = "15"
  3041. } else {
  3042. data["dept_code"] = department.Number
  3043. }
  3044. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  3045. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  3046. data["secret_key"] = miConfig.SecretKey
  3047. var ids []int64
  3048. for _, item := range prescriptions {
  3049. ids = append(ids, item.ID)
  3050. }
  3051. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3052. if config.IsOpen == 1 { //对接了医保,走医保流程
  3053. bytesData, _ := json.Marshal(data)
  3054. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  3055. resp, _ := client.Do(req)
  3056. defer resp.Body.Close()
  3057. body, ioErr := ioutil.ReadAll(resp.Body)
  3058. if ioErr != nil {
  3059. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3061. return
  3062. }
  3063. var respJSON map[string]interface{}
  3064. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  3065. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3067. return
  3068. }
  3069. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3070. userJSONBytes, _ := json.Marshal(respJSON)
  3071. request_respJSON := respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  3072. requestJSONBytes, _ := json.Marshal(request_respJSON)
  3073. saveLog(string(userJSONBytes), string(requestJSONBytes))
  3074. var res ResultFour
  3075. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3076. utils.ErrorLog("解析失败:%v", err)
  3077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3078. return
  3079. }
  3080. if res.Infcode == 0 {
  3081. order := &models.HisOrder{
  3082. UserOrgId: adminUser.CurrentOrgId,
  3083. HisPatientId: his.ID,
  3084. PatientId: his.PatientId,
  3085. SettleAccountsDate: recordDateTime,
  3086. Ctime: time.Now().Unix(),
  3087. Mtime: time.Now().Unix(),
  3088. Status: 0,
  3089. Number: chrg_bchno,
  3090. Infcode: res.Infcode,
  3091. WarnMsg: res.WarnMsg,
  3092. Cainfo: res.Cainfo,
  3093. ErrMsg: res.ErrMsg,
  3094. RespondTime: res.RefmsgTime,
  3095. InfRefmsgid: res.InfRefmsgid,
  3096. OrderStatus: 1,
  3097. IsMedicineInsurance: 1,
  3098. SettleType: settle_accounts_type,
  3099. SettleStartTime: start_time,
  3100. SettleEndTime: end_time,
  3101. Creator: roles.AdminUserId,
  3102. Modify: roles.AdminUserId,
  3103. PType: 2,
  3104. Diagnosis: diagnosis_id,
  3105. }
  3106. err = service.CreateOrder(order)
  3107. if err != nil {
  3108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  3109. return
  3110. }
  3111. for _, item := range res.Output.Result {
  3112. temp := strings.Split(item.FeedetlSn, "-")
  3113. var advice_id int64 = 0
  3114. var project_id int64 = 0
  3115. var types int64 = 0
  3116. id, _ := strconv.ParseInt(temp[2], 10, 64)
  3117. types, _ = strconv.ParseInt(temp[1], 10, 64)
  3118. if temp[1] == "1" {
  3119. advice_id = id
  3120. project_id = 0
  3121. } else if temp[1] == "2" {
  3122. advice_id = 0
  3123. project_id = id
  3124. }
  3125. info := &models.HisOrderInfo{
  3126. OrderNumber: order.Number,
  3127. FeedetlSn: item.FeedetlSn,
  3128. UploadDate: time.Now().Unix(),
  3129. AdviceId: advice_id,
  3130. DetItemFeeSumamt: item.DetItemFeeSumamt,
  3131. Cnt: item.Cnt,
  3132. Pric: float64(item.Pric),
  3133. PatientId: his.PatientId,
  3134. PricUplmtAmt: item.PricUplmtAmt,
  3135. SelfpayProp: item.SelfpayProp,
  3136. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  3137. OverlmtAmt: item.OverlmtAmt,
  3138. PreselfpayAmt: item.PreselfpayAmt,
  3139. BasMednFlag: item.BasMednFlag,
  3140. MedChrgitmType: item.MedChrgitmType,
  3141. HiNegoDrugFlag: item.HiNegoDrugFlag,
  3142. Status: 1,
  3143. Memo: item.Memo,
  3144. Mtime: time.Now().Unix(),
  3145. InscpScpAmt: item.InscpScpAmt,
  3146. DrtReimFlag: item.DrtReimFlag,
  3147. Ctime: time.Now().Unix(),
  3148. ListSpItemFlag: item.ListSpItemFlag,
  3149. ChldMedcFlag: item.ChldMedcFlag,
  3150. LmtUsedFlag: item.LmtUsedFlag,
  3151. ChrgitmLv: item.ChrgitmLv,
  3152. UserOrgId: adminUser.CurrentOrgId,
  3153. HisPatientId: his.ID,
  3154. OrderId: order.ID,
  3155. ProjectId: project_id,
  3156. Type: types,
  3157. }
  3158. service.CreateOrderInfo(info)
  3159. }
  3160. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  3161. service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, his_patient_id, chrg_bchno, recordDateTime)
  3162. var total float64
  3163. for _, item := range prescriptions {
  3164. if item.Type == 1 { //药品
  3165. for _, subItem := range item.HisDoctorAdviceInfo {
  3166. total = total + (subItem.Price * subItem.PrescribingNumber)
  3167. }
  3168. }
  3169. if item.Type == 2 { //项目
  3170. for _, subItem := range item.HisPrescriptionProject {
  3171. total = total + (subItem.Price * float64(subItem.Count))
  3172. }
  3173. }
  3174. }
  3175. for _, item := range prescriptions {
  3176. for _, subItem := range item.HisAdditionalCharge {
  3177. total = total + (subItem.Price * float64(subItem.Count))
  3178. }
  3179. }
  3180. allTotal := fmt.Sprintf("%.2f", total)
  3181. if res.Infcode == 0 {
  3182. var rf []*ResultFive
  3183. json.Unmarshal([]byte(his.Iinfo), &rf)
  3184. chrg_bchno := chrg_bchno
  3185. cert_no := his.Certno
  3186. var insutypes []string
  3187. var insutype string
  3188. var is390 int = 0
  3189. var is310 int = 0
  3190. for _, item := range rf {
  3191. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  3192. insutypes = append(insutypes, item.Insutype)
  3193. }
  3194. }
  3195. if len(insutypes) == 1 {
  3196. insutype = insutypes[0]
  3197. } else {
  3198. for _, i := range insutypes {
  3199. if i == "390" {
  3200. is390 = 1
  3201. }
  3202. if i == "310" {
  3203. is310 = 1
  3204. }
  3205. }
  3206. }
  3207. if is390 == 1 {
  3208. insutype = "390"
  3209. }
  3210. if is310 == 1 {
  3211. insutype = "310"
  3212. }
  3213. if len(insutypes) == 0 {
  3214. insutype = "310"
  3215. }
  3216. //insutype = "390"
  3217. if his.IdCardType == 1 {
  3218. cert_no = his.MedicalInsuranceNumber
  3219. } else {
  3220. cert_no = his.Certno
  3221. }
  3222. result, request_log := service.Gdyb2206(his.PsnNo, his.Number, chrg_bchno, cert_no, insutype, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, strconv.FormatInt(reg_type, 10), his.IdCardType, 0, 0, 0, 0, his.IdType)
  3223. var dat map[string]interface{}
  3224. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3225. fmt.Println(dat)
  3226. } else {
  3227. fmt.Println(err)
  3228. }
  3229. saveLog(result, request_log)
  3230. userJSONBytes, _ := json.Marshal(dat)
  3231. var res ResultSeven
  3232. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3233. utils.ErrorLog("解析失败:%v", err)
  3234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3235. return
  3236. }
  3237. if res.Infcode != 0 {
  3238. errlog := &models.HisOrderError{
  3239. UserOrgId: adminUser.CurrentOrgId,
  3240. Ctime: time.Now().Unix(),
  3241. Mtime: time.Now().Unix(),
  3242. Number: chrg_bchno,
  3243. ErrMsg: res.ErrMsg,
  3244. Status: 1,
  3245. PatientId: id,
  3246. RecordTime: recordDateTime,
  3247. Stage: 20,
  3248. }
  3249. service.CreateErrMsgLog(errlog)
  3250. c.ServeSuccessJSON(map[string]interface{}{
  3251. "failed_code": -10,
  3252. "msg": res.ErrMsg,
  3253. })
  3254. return
  3255. } else {
  3256. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  3257. order.OrderStatus = 1
  3258. order.IsPre = 1
  3259. order.Status = 1
  3260. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  3261. order.SetlId = res.Output.Setlinfo.SetlID
  3262. order.PsnNo = res.Output.Setlinfo.PsnNo
  3263. order.PsnName = res.Output.Setlinfo.PsnName
  3264. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  3265. order.Certno = res.Output.Setlinfo.Certno
  3266. order.Gend = res.Output.Setlinfo.Gend
  3267. order.Naty = res.Output.Setlinfo.Naty
  3268. order.Age = res.Output.Setlinfo.Age
  3269. order.Insutype = res.Output.Setlinfo.Insutype
  3270. order.PsnType = res.Output.Setlinfo.PsnType
  3271. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  3272. order.SetlTime = res.Output.Setlinfo.SetlTime
  3273. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  3274. order.MedType = res.Output.Setlinfo.MedType
  3275. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  3276. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  3277. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  3278. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  3279. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  3280. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  3281. order.HifpPay = res.Output.Setlinfo.HifpPay
  3282. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  3283. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  3284. order.HifesPay = res.Output.Setlinfo.HifesPay
  3285. order.HifobPay = res.Output.Setlinfo.HifobPay
  3286. order.MafPay = res.Output.Setlinfo.MafPay
  3287. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  3288. order.OthPay = res.Output.Setlinfo.OthPay
  3289. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  3290. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  3291. order.AcctPay = res.Output.Setlinfo.AcctPay
  3292. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  3293. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  3294. order.Balc = res.Output.Setlinfo.Balc
  3295. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  3296. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  3297. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  3298. order.ClrWay = res.Output.Setlinfo.ClrWay
  3299. order.Creator = order.Creator
  3300. order.Modify = roles.AdminUserId
  3301. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  3302. detailStr := string(setlDetail)
  3303. order.SetlDetail = detailStr
  3304. //err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  3305. err = service.UpDateOrder(order)
  3306. if err == nil {
  3307. c.ServeSuccessJSON(map[string]interface{}{
  3308. "msg": "预结算成功",
  3309. })
  3310. } else {
  3311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  3312. return
  3313. }
  3314. }
  3315. } else {
  3316. adminUser := c.GetAdminUserInfo()
  3317. errlog := &models.HisOrderError{
  3318. UserOrgId: adminUser.CurrentOrgId,
  3319. Ctime: time.Now().Unix(),
  3320. Mtime: time.Now().Unix(),
  3321. ErrMsg: res.ErrMsg,
  3322. Status: 1,
  3323. PatientId: id,
  3324. RecordTime: recordDateTime,
  3325. Stage: 4,
  3326. }
  3327. service.CreateErrMsgLog(errlog)
  3328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  3329. return
  3330. }
  3331. } else {
  3332. adminUser := c.GetAdminUserInfo()
  3333. errlog := &models.HisOrderError{
  3334. UserOrgId: adminUser.CurrentOrgId,
  3335. Ctime: time.Now().Unix(),
  3336. Mtime: time.Now().Unix(),
  3337. ErrMsg: res.ErrMsg,
  3338. Status: 1,
  3339. PatientId: id,
  3340. RecordTime: recordDateTime,
  3341. Stage: 4,
  3342. }
  3343. service.CreateErrMsgLog(errlog)
  3344. c.ServeSuccessJSON(map[string]interface{}{
  3345. "failed_code": -10,
  3346. "msg": res.ErrMsg,
  3347. })
  3348. return
  3349. }
  3350. }
  3351. }
  3352. }
  3353. //func (c *HisApiController) GetSettleInfo() {
  3354. // id, _ := c.GetInt64("id")
  3355. // order_id, _ := c.GetInt64("order_id")
  3356. //
  3357. // record_time := c.GetString("record_time")
  3358. // pay_way, _ := c.GetInt64("pay_way")
  3359. // pay_price, _ := c.GetFloat("pay_price")
  3360. // pay_card_no := c.GetString("pay_card_no")
  3361. // discount_price, _ := c.GetFloat("discount_price")
  3362. // preferential_price, _ := c.GetFloat("preferential_price")
  3363. // reality_price, _ := c.GetFloat("reality_price")
  3364. // found_price, _ := c.GetFloat("found_price")
  3365. // medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  3366. // private_price, _ := c.GetFloat("private_price")
  3367. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  3368. // admin_user_id, _ := c.GetInt64("admin_user_id")
  3369. //
  3370. // timeLayout := "2006-01-02"
  3371. // loc, _ := time.LoadLocation("Local")
  3372. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3373. // if err != nil {
  3374. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3375. // return
  3376. // }
  3377. // recordDateTime := theTime.Unix()
  3378. // adminUser := c.GetAdminUserInfo()
  3379. //
  3380. // var prescriptions []*models.HisPrescription
  3381. //
  3382. // data := make(map[string]interface{})
  3383. // if settle_accounts_type == 1 { //日结
  3384. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  3385. // data["pre"] = prescriptions
  3386. //
  3387. // } else { //月结
  3388. // start_time_str := c.GetString("start_time")
  3389. // end_time_str := c.GetString("end_time")
  3390. // timeLayout := "2006-01-02"
  3391. // loc, _ := time.LoadLocation("Local")
  3392. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3393. // if err != nil {
  3394. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3395. // return
  3396. // }
  3397. // recordStartTime := theStartTime.Unix()
  3398. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3399. // if err != nil {
  3400. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3401. // return
  3402. // }
  3403. // recordEndTime := theEndTime.Unix()
  3404. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  3405. // data["pre"] = prescriptions
  3406. //
  3407. // }
  3408. //
  3409. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3410. //
  3411. // his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  3412. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3413. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  3414. // strconv.FormatInt(his.PatientId, 10)
  3415. //
  3416. // order_src, _ := service.GetHisOrderByID(order_id)
  3417. //
  3418. // config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3419. // if config.IsOpen == 1 { //对接了医保,走医保流程
  3420. //
  3421. // var total float64
  3422. // for _, item := range prescriptions {
  3423. // if item.Type == 1 { //药品
  3424. // for _, subItem := range item.HisDoctorAdviceInfo {
  3425. // total = total + (subItem.Price * subItem.PrescribingNumber)
  3426. // }
  3427. // }
  3428. // if item.Type == 2 { //项目
  3429. // for _, subItem := range item.HisPrescriptionProject {
  3430. // total = total + (subItem.Price * float64(subItem.Count))
  3431. // }
  3432. // }
  3433. // }
  3434. //
  3435. // for _, item := range prescriptions {
  3436. // for _, subItem := range item.HisAdditionalCharge {
  3437. // total = total + (subItem.Price * float64(subItem.Count))
  3438. // }
  3439. // }
  3440. //
  3441. // allTotal := fmt.Sprintf("%.2f", total)
  3442. // var rf []*ResultFive
  3443. // json.Unmarshal([]byte(his.Iinfo), &rf)
  3444. // psn_no := order_src.PsnNo
  3445. // mdtrt_id := order_src.MdtrtId
  3446. // chrg_bchno := order_src.Number
  3447. // cert_no := order_src.Certno
  3448. // insutype := rf[0].Insutype
  3449. //
  3450. // if his.IdCardType == 1 {
  3451. // cert_no = his.MedicalInsuranceNumber
  3452. // } else {
  3453. // cert_no = his.Certno
  3454. // }
  3455. //
  3456. // result, src_resquest := service.Gdyb2207(his.PsnNo, his.Number, chrg_bchno, cert_no, insutype, strconv.FormatFloat(total, 'E', -1, 64) ,miConfig.OrgName,roles.UserName,miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, strconv.FormatInt(patientPrescription.RegisterType, 10),his.IdCardType, order_src.FulamtOwnpayAmt,order_src.OverlmtSelfPay,order_src.PreselfpayAmt,order_src.InscpScpAmt)
  3457. // var dat map[string]interface{}
  3458. // if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3459. // fmt.Println(dat)
  3460. // } else {
  3461. // fmt.Println(err)
  3462. // }
  3463. //
  3464. // userJSONBytes, _ := json.Marshal(dat)
  3465. //
  3466. //
  3467. //
  3468. // var res ResultSeven
  3469. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3470. // utils.ErrorLog("解析失败:%v", err)
  3471. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3472. // return
  3473. // }
  3474. // if res.Infcode == -1 {
  3475. // errlog := &models.HisOrderError{
  3476. // UserOrgId: adminUser.CurrentOrgId,
  3477. // Ctime: time.Now().Unix(),
  3478. // Mtime: time.Now().Unix(),
  3479. // Number: chrg_bchno,
  3480. // ErrMsg: res.ErrMsg,
  3481. // Status: 1,
  3482. // PatientId: id,
  3483. // RecordTime: recordDateTime,
  3484. // Stage: 6,
  3485. // }
  3486. // service.CreateErrMsgLog(errlog)
  3487. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  3488. // return
  3489. // } else {
  3490. // order_src.OrderStatus = 2
  3491. // order_src.PayWay = pay_way
  3492. // order_src.PayPrice = pay_price
  3493. // order_src.PayCardNo = pay_card_no
  3494. // order_src.DiscountPrice = discount_price
  3495. // order_src.PreferentialPrice = preferential_price
  3496. // order_src.RealityPrice = reality_price
  3497. // order_src.FoundPrice = found_price
  3498. // order_src.MedicalInsurancePrice = medical_insurance_price
  3499. // order_src.PrivatePrice = private_price
  3500. // order_src.MdtrtId = res.Output.Setlinfo.MdtrtID
  3501. // order_src.SetlId = res.Output.Setlinfo.SetlID
  3502. // order_src.PsnNo = res.Output.Setlinfo.PsnNo
  3503. // order_src.PsnName = res.Output.Setlinfo.PsnName
  3504. // order_src.PsnCertType = res.Output.Setlinfo.PsnCertType
  3505. // order_src.Certno = res.Output.Setlinfo.Certno
  3506. // order_src.Gend = res.Output.Setlinfo.Gend
  3507. // order_src.Naty = res.Output.Setlinfo.Naty
  3508. // order_src.Age = res.Output.Setlinfo.Age
  3509. // order_src.Insutype = res.Output.Setlinfo.Insutype
  3510. // order_src.PsnType = res.Output.Setlinfo.PsnType
  3511. // order_src.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  3512. // order_src.SetlTime = res.Output.Setlinfo.SetlTime
  3513. // order_src.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  3514. // order_src.MedType = res.Output.Setlinfo.MedType
  3515. // order_src.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  3516. // order_src.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  3517. // order_src.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  3518. // order_src.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  3519. // order_src.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  3520. // order_src.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  3521. // order_src.HifpPay = res.Output.Setlinfo.HifpPay
  3522. // order_src.CvlservPay = res.Output.Setlinfo.CvlservPay
  3523. // order_src.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  3524. // order_src.HifesPay = res.Output.Setlinfo.HifesPay
  3525. // order_src.HifobPay = res.Output.Setlinfo.HifobPay
  3526. // order_src.MafPay = res.Output.Setlinfo.MafPay
  3527. // order_src.OthPay = res.Output.Setlinfo.OthPay
  3528. // order_src.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  3529. // order_src.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  3530. // order_src.AcctPay = res.Output.Setlinfo.AcctPay
  3531. // order_src.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  3532. // order_src.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  3533. // order_src.Balc = res.Output.Setlinfo.Balc
  3534. // order_src.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  3535. // order_src.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  3536. // order_src.ClrOptins = res.Output.Setlinfo.ClrOptins
  3537. // order_src.ClrWay = res.Output.Setlinfo.ClrWay
  3538. // order_src.Creator = order_src.Creator
  3539. // order_src.Modify = roles.ID
  3540. // order_src.RequestLog = src_resquest
  3541. // setlDetail, _ := json.Marshal(res.Output.Setldetail)
  3542. // detailStr := string(setlDetail)
  3543. // order_src.SetlDetail = detailStr
  3544. // err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  3545. // err = service.UpDateOrder(order_src)
  3546. //
  3547. // if err == nil {
  3548. // c.ServeSuccessJSON(map[string]interface{}{
  3549. // "msg": "结算成功",
  3550. // })
  3551. // } else {
  3552. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  3553. // return
  3554. // }
  3555. // }
  3556. // }
  3557. //}
  3558. //退款
  3559. func (c *HisApiController) Refund() {
  3560. order_id, _ := c.GetInt64("order_id")
  3561. admin_user_id, _ := c.GetInt64("admin_user_id")
  3562. //record_time := c.GetString("record_time")
  3563. //patient_id, _ := c.GetInt64("patient_id")
  3564. //timeLayout := "2006-01-02"
  3565. //loc, _ := time.LoadLocation("Local")
  3566. adminUser := c.GetAdminUserInfo()
  3567. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3568. //if err != nil {
  3569. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3570. // return
  3571. //}
  3572. //recordDateTime := theTime.Unix()
  3573. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3574. var order models.HisOrder
  3575. order, _ = service.GetHisOrderByID(order_id)
  3576. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3577. if order.ID == 0 {
  3578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3579. return
  3580. //order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  3581. }
  3582. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3583. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3584. if config.IsOpen == 1 { //对接了医保,走医保流程
  3585. result, src_resquest := service.Gdyb2208(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  3586. var dat map[string]interface{}
  3587. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3588. fmt.Println(dat)
  3589. } else {
  3590. fmt.Println(err)
  3591. }
  3592. saveLog(result, src_resquest)
  3593. userJSONBytes, _ := json.Marshal(dat)
  3594. var res ResultSixteen
  3595. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3596. utils.ErrorLog("解析失败:%v", err)
  3597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3598. return
  3599. }
  3600. if res.Infcode == 0 {
  3601. result, src_request := service.Gdyb2205(order.PsnNo, order.MdtrtId, order.Number, miConfig.OrgName, roles.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  3602. var dat map[string]interface{}
  3603. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3604. fmt.Println(dat)
  3605. } else {
  3606. fmt.Println(err)
  3607. }
  3608. saveLog(result, src_request)
  3609. userJSONBytes, _ := json.Marshal(dat)
  3610. var res2 ResultSix
  3611. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  3612. utils.ErrorLog("解析失败:%v", err)
  3613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3614. return
  3615. }
  3616. if res2.Infcode == 0 {
  3617. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, src_resquest, result)
  3618. if err == nil {
  3619. c.ServeSuccessJSON(map[string]interface{}{
  3620. "msg": "退费成功",
  3621. })
  3622. } else {
  3623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3624. return
  3625. }
  3626. } else {
  3627. c.ServeSuccessJSON(map[string]interface{}{
  3628. "code": -10,
  3629. "msg": res2.ErrMsg,
  3630. })
  3631. }
  3632. } else {
  3633. c.ServeSuccessJSON(map[string]interface{}{
  3634. "code": -10,
  3635. "msg": res.ErrMsg,
  3636. })
  3637. }
  3638. }
  3639. }
  3640. func (c *HisApiController) RefundNumber() {
  3641. record_time := c.GetString("record_time")
  3642. //patient_id, _ := c.GetInt64("patient_id")
  3643. admin_user_id, _ := c.GetInt64("admin_user_id")
  3644. his_patient_id, _ := c.GetInt64("id")
  3645. timeLayout := "2006-01-02"
  3646. loc, _ := time.LoadLocation("Local")
  3647. adminUser := c.GetAdminUserInfo()
  3648. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3649. fmt.Println(err)
  3650. if err != nil {
  3651. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3652. return
  3653. }
  3654. recordDateTime := theTime.Unix()
  3655. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3656. his, _ := service.GetHisPatientRecord(adminUser.CurrentOrgId, his_patient_id)
  3657. //patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3658. //order, _ := service.GetHisOrderByID(order_id)
  3659. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3660. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3661. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3662. count, _ := service.GetOrderCountByNumber(adminUser.CurrentOrgId, his.PatientId, recordDateTime, his.Number)
  3663. if count > 0 {
  3664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  3665. return
  3666. }
  3667. if config.IsOpen == 1 { //对接了医保,走医保流程
  3668. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  3669. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + roles.UserName + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  3670. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3671. resp3, requestErr3 := http.Get(api3)
  3672. if requestErr3 != nil {
  3673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3674. return
  3675. }
  3676. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  3677. if ioErr3 != nil {
  3678. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  3679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3680. return
  3681. }
  3682. var respJSON3 map[string]interface{}
  3683. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  3684. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3686. return
  3687. }
  3688. respJSON3 = respJSON3["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3689. userJSONBytes3, _ := json.Marshal(respJSON3)
  3690. var res2 ResultSix
  3691. if err := json.Unmarshal(userJSONBytes3, &res2); err != nil {
  3692. utils.ErrorLog("解析失败:%v", err)
  3693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3694. return
  3695. }
  3696. if res2.Infcode == 0 {
  3697. if err == nil {
  3698. c.ServeSuccessJSON(map[string]interface{}{
  3699. "msg": "退号成功",
  3700. })
  3701. service.UpdataRegStatusTwo(his_patient_id, recordDateTime, adminUser.CurrentOrgId)
  3702. } else {
  3703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3704. return
  3705. }
  3706. } else {
  3707. c.ServeSuccessJSON(map[string]interface{}{
  3708. "code": -10,
  3709. "msg": res2.ErrMsg,
  3710. })
  3711. }
  3712. } else {
  3713. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  3714. //if err == nil {
  3715. // c.ServeSuccessJSON(map[string]interface{}{
  3716. // "msg": "退费成功",
  3717. // })
  3718. //} else {
  3719. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3720. // return
  3721. //}
  3722. }
  3723. }
  3724. func (c *HisApiController) RefundDetail() {
  3725. order_id, _ := c.GetInt64("order_id")
  3726. his_patient_id, _ := c.GetInt64("his_patient_id")
  3727. number := c.GetString("number")
  3728. record_time := c.GetString("record_time")
  3729. patient_id, _ := c.GetInt64("patient_id")
  3730. timeLayout := "2006-01-02"
  3731. loc, _ := time.LoadLocation("Local")
  3732. adminUser := c.GetAdminUserInfo()
  3733. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3734. fmt.Println(err)
  3735. if err != nil {
  3736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3737. return
  3738. }
  3739. recordDateTime := theTime.Unix()
  3740. his, _ := service.GetNewVMHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  3741. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3742. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3743. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3744. var order models.HisOrder
  3745. order, _ = service.GetHisOrderByID(order_id)
  3746. if order.ID == 0 {
  3747. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  3748. }
  3749. if config.IsOpen == 1 { //对接了医保,走医保流程
  3750. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  3751. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  3752. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3753. resp2, requestErr2 := http.Get(api2)
  3754. if requestErr2 != nil {
  3755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3756. return
  3757. }
  3758. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  3759. if ioErr2 != nil {
  3760. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  3761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3762. return
  3763. }
  3764. var respJSON2 map[string]interface{}
  3765. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  3766. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3767. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3768. return
  3769. }
  3770. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId, "", "")
  3771. if err == nil {
  3772. c.ServeSuccessJSON(map[string]interface{}{
  3773. "msg": "退费成功",
  3774. })
  3775. } else {
  3776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3777. return
  3778. }
  3779. } else {
  3780. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId, "", "")
  3781. if err == nil {
  3782. c.ServeSuccessJSON(map[string]interface{}{
  3783. "msg": "退费成功",
  3784. })
  3785. } else {
  3786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3787. return
  3788. }
  3789. }
  3790. }
  3791. //对账
  3792. func (c *HisApiController) GetCheckAccount() {
  3793. start_time := c.GetString("start_time")
  3794. end_time := c.GetString("end_time")
  3795. insutype := c.GetString("insutype")
  3796. clr_type := c.GetString("clr_type")
  3797. admin_user_id, _ := c.GetInt64("admin_user_id")
  3798. adminUser := c.GetAdminUserInfo()
  3799. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3800. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3801. timeLayout := "2006-01-02"
  3802. loc, _ := time.LoadLocation("Local")
  3803. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3804. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3805. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  3806. //orders_two, _ := service.GetOrderByTimeThree(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  3807. fixmedins_setl_cnt := int64(len(orders))
  3808. //
  3809. ////撤销的算2条数据为一笔
  3810. //for _, item := range orders_two {
  3811. // if item.OrderStatus == 3 {
  3812. // fixmedins_setl_cnt = fixmedins_setl_cnt + 1
  3813. // }
  3814. //}
  3815. var medfee_sumamt float64
  3816. var acct_pay float64
  3817. var fund_pay_sumamt float64
  3818. for _, item := range orders {
  3819. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  3820. acct_pay = acct_pay + item.AcctPay
  3821. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  3822. }
  3823. var user_name string
  3824. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3825. if role.ID == 0 {
  3826. user_name = "xxx"
  3827. } else {
  3828. user_name = role.UserName
  3829. }
  3830. if config.IsOpen == 1 {
  3831. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  3832. "insutype=" + insutype +
  3833. "&clr_type=" + clr_type +
  3834. "&setl_optins=" + "定点医保中心" +
  3835. "&stmt_begndate=" + start_time +
  3836. "&stm_enddate=" + end_time +
  3837. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  3838. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  3839. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  3840. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  3841. "&fixmedins_code=" + miConfig.Code +
  3842. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3843. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3844. "&secret_key=" + miConfig.SecretKey +
  3845. "&org_name=" + miConfig.OrgName +
  3846. "&doctor=" + user_name
  3847. fmt.Println(api)
  3848. resp, requestErr := http.Get(api)
  3849. if requestErr != nil {
  3850. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3851. return
  3852. }
  3853. body, ioErr := ioutil.ReadAll(resp.Body)
  3854. fmt.Println(body)
  3855. if ioErr != nil {
  3856. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3858. return
  3859. }
  3860. var respJSON map[string]interface{}
  3861. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3862. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3864. return
  3865. }
  3866. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3867. userJSONBytes, _ := json.Marshal(respJSON)
  3868. var res ResultEight
  3869. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3870. utils.ErrorLog("解析失败:%v", err)
  3871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3872. return
  3873. }
  3874. if res.Infcode == 0 {
  3875. if res.Output.Stmtinfo.StmtRslt == "0" {
  3876. micc := &models.MedicalInsuranceCostCompare{
  3877. StartTime: startime.Unix(),
  3878. EndTime: endtime.Unix(),
  3879. Insutype: insutype,
  3880. CheckType: 1,
  3881. Num: fixmedins_setl_cnt,
  3882. Mtime: time.Now().Unix(),
  3883. Status: 1,
  3884. UserOrgId: adminUser.CurrentOrgId,
  3885. CostTotal: medfee_sumamt,
  3886. FuncTotal: fund_pay_sumamt,
  3887. PsnPay: acct_pay,
  3888. Creator: admin_user_id,
  3889. Ctime: time.Now().Unix(),
  3890. }
  3891. err := service.CreateMedicalInsuranceCostCompareRecord(micc)
  3892. if err == nil {
  3893. c.ServeSuccessJSON(map[string]interface{}{
  3894. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  3895. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  3896. })
  3897. } else {
  3898. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3899. }
  3900. } else {
  3901. c.ServeSuccessJSON(map[string]interface{}{
  3902. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  3903. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  3904. })
  3905. }
  3906. } else {
  3907. c.ServeSuccessJSON(map[string]interface{}{
  3908. "code": -10,
  3909. "msg": res.ErrMsg,
  3910. })
  3911. }
  3912. }
  3913. }
  3914. func (c *HisApiController) Check310() {
  3915. adminUser := c.GetAdminUserInfo()
  3916. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3917. var user_name string
  3918. user_name = "xxx"
  3919. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  3920. "insutype=" + "310" +
  3921. "&clr_type=" + "11" +
  3922. "&setl_optins=" + "定点医保中心" +
  3923. "&stmt_begndate=" + "2021-03-01" +
  3924. "&stm_enddate=" + "2021-03-31" +
  3925. "&medfee_sumamt=" + "11521" +
  3926. "&fund_pay_sumamt=" + "10166.66" +
  3927. "&acct_pay=" + "0" +
  3928. "&fixmedins_setl_cnt=" + "7" +
  3929. "&fixmedins_code=" + miConfig.Code +
  3930. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3931. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3932. "&secret_key=" + miConfig.SecretKey +
  3933. "&org_name=" + miConfig.OrgName +
  3934. "&doctor=" + user_name
  3935. fmt.Println(api)
  3936. resp, requestErr := http.Get(api)
  3937. if requestErr != nil {
  3938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3939. return
  3940. }
  3941. body, ioErr := ioutil.ReadAll(resp.Body)
  3942. fmt.Println(body)
  3943. if ioErr != nil {
  3944. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3946. return
  3947. }
  3948. var respJSON map[string]interface{}
  3949. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3950. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3952. return
  3953. }
  3954. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3955. userJSONBytes, _ := json.Marshal(respJSON)
  3956. var res ResultEight
  3957. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3958. utils.ErrorLog("解析失败:%v", err)
  3959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3960. return
  3961. }
  3962. }
  3963. func (c *HisApiController) Check390() {
  3964. adminUser := c.GetAdminUserInfo()
  3965. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3966. var user_name string
  3967. user_name = "张俊杰"
  3968. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  3969. "insutype=" + "390" +
  3970. "&clr_type=" + "11" +
  3971. "&setl_optins=" + "定点医保中心" +
  3972. "&stmt_begndate=" + "2021-03-01" +
  3973. "&stm_enddate=" + "2021-03-31" +
  3974. "&medfee_sumamt=" + "209318.43" +
  3975. "&fund_pay_sumamt=" + "188029.12" +
  3976. "&acct_pay=" + "0" +
  3977. "&fixmedins_setl_cnt=" + "48" +
  3978. "&fixmedins_code=" + miConfig.Code +
  3979. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3980. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3981. "&secret_key=" + miConfig.SecretKey +
  3982. "&org_name=" + miConfig.OrgName +
  3983. "&doctor=" + user_name
  3984. fmt.Println(api)
  3985. resp, requestErr := http.Get(api)
  3986. if requestErr != nil {
  3987. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3988. return
  3989. }
  3990. body, ioErr := ioutil.ReadAll(resp.Body)
  3991. fmt.Println(body)
  3992. if ioErr != nil {
  3993. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3994. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3995. return
  3996. }
  3997. var respJSON map[string]interface{}
  3998. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3999. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4000. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4001. return
  4002. }
  4003. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4004. userJSONBytes, _ := json.Marshal(respJSON)
  4005. var res ResultEight
  4006. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4007. utils.ErrorLog("解析失败:%v", err)
  4008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4009. return
  4010. }
  4011. }
  4012. //对账明细
  4013. func (c *HisApiController) GetCheckDetailAccount() {
  4014. start_time := c.GetString("start_time")
  4015. end_time := c.GetString("end_time")
  4016. admin_user_id, _ := c.GetInt64("admin_user_id")
  4017. adminUser := c.GetAdminUserInfo()
  4018. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4019. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4020. timeLayout := "2006-01-02"
  4021. loc, _ := time.LoadLocation("Local")
  4022. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4023. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4024. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  4025. Mkdir(miConfig.OrgName)
  4026. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  4027. file_name := file + ".txt"
  4028. zip_name := file + ".zip"
  4029. zip_path := miConfig.OrgName + "/" + zip_name
  4030. file_path := miConfig.OrgName + "/" + file_name
  4031. decimal.DivisionPrecision = 2
  4032. var medfee_sumamt float64
  4033. var psn_cash_pay float64
  4034. var fund_pay_sumamt float64
  4035. fixmedins_setl_cnt := int64(len(orders))
  4036. for _, item := range orders {
  4037. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  4038. psn_cash_pay = psn_cash_pay + item.PsnCashPay
  4039. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  4040. }
  4041. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  4042. defer f.Close()
  4043. if err != nil {
  4044. fmt.Println(err.Error())
  4045. } else {
  4046. for _, item := range orders {
  4047. var refd_setl_flag string
  4048. if item.OrderStatus == 2 {
  4049. refd_setl_flag = "0"
  4050. var str string
  4051. str = item.SetlId + " " +
  4052. item.MdtrtId + " " +
  4053. item.PsnNo + " " +
  4054. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  4055. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  4056. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\r\n"
  4057. _, err = f.Write([]byte(str))
  4058. }
  4059. if item.OrderStatus == 3 {
  4060. var str string
  4061. str = item.SetlId + " " +
  4062. item.MdtrtId + " " +
  4063. item.PsnNo + " " +
  4064. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  4065. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  4066. fmt.Sprintf("%.2f", item.AcctPay) + " " + "1" + "\r\n"
  4067. _, err = f.Write([]byte(str))
  4068. var str2 string
  4069. str2 = item.SetlId + " " +
  4070. item.MdtrtId + " " +
  4071. item.PsnNo + " " +
  4072. fmt.Sprintf("%.2f", 0-item.MedfeeSumamt) + " " +
  4073. fmt.Sprintf("%.2f", 0-item.FundPaySumamt) + " " +
  4074. fmt.Sprintf("%.2f", 0-item.AcctPay) + " " + "1" + "\r\n"
  4075. _, err = f.Write([]byte(str2))
  4076. }
  4077. }
  4078. }
  4079. Zip(file_path, zip_path)
  4080. fmt.Println(ReadFile(zip_path))
  4081. fmt.Println(string(ReadFile(zip_path)))
  4082. if config.IsOpen == 1 {
  4083. var user_name string
  4084. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4085. if role.ID == 0 {
  4086. user_name = "管理员"
  4087. } else {
  4088. user_name = role.UserName
  4089. }
  4090. baseParams := models.BaseParams{
  4091. SecretKey: miConfig.SecretKey,
  4092. FixmedinsCode: miConfig.Code,
  4093. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4094. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4095. OrgName: miConfig.OrgName,
  4096. Doctor: user_name,
  4097. }
  4098. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  4099. var dat map[string]interface{}
  4100. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4101. fmt.Println(dat)
  4102. } else {
  4103. fmt.Println(err)
  4104. }
  4105. userJSONBytes, _ := json.Marshal(dat)
  4106. var res ResultNine
  4107. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4108. utils.ErrorLog("解析失败:%v", err)
  4109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4110. return
  4111. }
  4112. if res.Infcode == 0 {
  4113. fileNo := res.Output.FileQuryNo
  4114. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  4115. "file_qury_no=" + fileNo +
  4116. "&setl_optins=" + "定点医保中心" +
  4117. "&stmt_begndate=" + start_time +
  4118. "&stm_enddate=" + end_time +
  4119. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  4120. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  4121. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  4122. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  4123. "&fixmedins_code=" + miConfig.Code +
  4124. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  4125. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  4126. "&secret_key=" + miConfig.SecretKey +
  4127. "&org_name=" + miConfig.OrgName +
  4128. "&doctor=" + user_name
  4129. resp, requestErr := http.Get(api)
  4130. if requestErr != nil {
  4131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4132. return
  4133. }
  4134. body, ioErr := ioutil.ReadAll(resp.Body)
  4135. if ioErr != nil {
  4136. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4138. return
  4139. }
  4140. var respJSON map[string]interface{}
  4141. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4142. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4144. return
  4145. }
  4146. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4147. userJSONBytes, _ := json.Marshal(respJSON)
  4148. var res ResultTen
  4149. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4150. utils.ErrorLog("解析失败:%v", err)
  4151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4152. return
  4153. }
  4154. if res.Infcode == 0 {
  4155. service.Gdyb9102(baseParams, zip_name, fileNo)
  4156. micc := &models.MedicalInsuranceCostCompare{
  4157. StartTime: startime.Unix(),
  4158. EndTime: endtime.Unix(),
  4159. Insutype: "0",
  4160. CheckType: 2,
  4161. Num: fixmedins_setl_cnt,
  4162. Mtime: time.Now().Unix(),
  4163. Status: 1,
  4164. UserOrgId: adminUser.CurrentOrgId,
  4165. CostTotal: medfee_sumamt,
  4166. FuncTotal: fund_pay_sumamt,
  4167. PsnPay: psn_cash_pay,
  4168. Creator: admin_user_id,
  4169. Ctime: time.Now().Unix(),
  4170. }
  4171. service.CreateMedicalInsuranceCostCompareRecord(micc)
  4172. c.ServeSuccessJSON(map[string]interface{}{
  4173. "msg": "明细对账成功",
  4174. })
  4175. }
  4176. } else {
  4177. }
  4178. }
  4179. }
  4180. func (c *HisApiController) GetSettleAccounts() {
  4181. //id, _ := c.GetInt64("id")
  4182. //record_time := c.GetString("record_time")
  4183. order_id, _ := c.GetInt64("order_id")
  4184. admin_user_id, _ := c.GetInt64("admin_user_id")
  4185. //timeLayout := "2006-01-02"
  4186. //loc, _ := time.LoadLocation("Local")
  4187. //
  4188. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4189. //if err != nil {
  4190. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4191. // return
  4192. //}
  4193. //recordDateTime := theTime.Unix()
  4194. adminUser := c.GetAdminUserInfo()
  4195. order, _ := service.GetHisOrderByID(order_id)
  4196. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  4197. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  4198. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  4199. orderInfos = append(orderInfos, orderInfos_two...)
  4200. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  4201. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  4202. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  4203. //var config []*models.HisXtDiagnoseConfig
  4204. var name string
  4205. for _, item := range diagnosis_ids {
  4206. id, _ := strconv.ParseInt(item, 10, 64)
  4207. diagnosisConfig, _ := service.FindDiagnoseById(id)
  4208. if len(name) == 0 {
  4209. name = diagnosisConfig.ClassName
  4210. } else {
  4211. name = name + "," + diagnosisConfig.ClassName
  4212. }
  4213. }
  4214. var bedCostTotal float64 = 0 //床位总费
  4215. var bedCostSelfTotal float64 = 0 //床位自费
  4216. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  4217. var operationCostTotal float64 = 0 //手术费
  4218. var operationCostSelfTotal float64 = 0 //手术费
  4219. var operationCostPartSelfTotal float64 = 0 //手术费
  4220. var otherCostTotal float64 = 0 //其他费用
  4221. var otherCostSelfTotal float64 = 0 //其他费用
  4222. var otherCostPartSelfTotal float64 = 0 //其他费用
  4223. var materialCostTotal float64 = 0 //材料费
  4224. var materialCostSelfTotal float64 = 0 //材料费
  4225. var materialCostPartSelfTotal float64 = 0 //材料费
  4226. var westernMedicineCostTotal float64 = 0 //西药费
  4227. var westernMedicineCostSelfTotal float64 = 0 //西药费
  4228. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  4229. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  4230. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  4231. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  4232. var checkCostTotal float64 = 0 //检查费
  4233. var checkCostSelfTotal float64 = 0 //检查费
  4234. var checkCostPartSelfTotal float64 = 0 //检查费
  4235. var laboratoryCostTotal float64 = 0 //化验费
  4236. var laboratoryCostSelfTotal float64 = 0 //化验费
  4237. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  4238. var treatCostTotal float64 = 0 //治疗费用
  4239. var treatCostSelfTotal float64 = 0 //治疗费用
  4240. var treatCostPartSelfTotal float64 = 0 //治疗费用
  4241. decimal.DivisionPrecision = 2
  4242. for _, item := range orderInfos {
  4243. if item.MedChrgitmType == "01" { //床位费
  4244. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4245. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4246. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4247. }
  4248. if item.MedChrgitmType == "03" { //检查费
  4249. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4250. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4251. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4252. }
  4253. if item.MedChrgitmType == "04" { //化验费
  4254. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4255. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4256. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4257. }
  4258. if item.MedChrgitmType == "05" { //治疗费
  4259. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4260. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4261. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4262. }
  4263. if item.MedChrgitmType == "06" { //手术费
  4264. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4265. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4266. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4267. }
  4268. if item.MedChrgitmType == "08" { //材料费
  4269. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4270. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4271. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4272. }
  4273. if item.MedChrgitmType == "09" { //西药费
  4274. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4275. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4276. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4277. }
  4278. if item.MedChrgitmType == "11" { //中成费
  4279. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4280. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4281. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4282. }
  4283. if item.MedChrgitmType == "14" { //其他费
  4284. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4285. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4286. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4287. }
  4288. }
  4289. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4290. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4291. var user_name string
  4292. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4293. if role.ID == 0 {
  4294. user_name = "管理员"
  4295. } else {
  4296. user_name = role.UserName
  4297. }
  4298. baseParams := models.BaseParams{
  4299. SecretKey: miConfig.SecretKey,
  4300. FixmedinsCode: miConfig.Code,
  4301. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4302. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4303. OrgName: miConfig.OrgName,
  4304. Doctor: user_name,
  4305. }
  4306. businessParams := models.BusinessParams{
  4307. PsnNo: order.PsnNo,
  4308. MdtrtId: order.MdtrtId,
  4309. SetlId: order.SetlId,
  4310. }
  4311. if config.IsOpen == 1 {
  4312. result := service.Gdyb5203(baseParams, businessParams)
  4313. var dat map[string]interface{}
  4314. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4315. fmt.Println(dat)
  4316. } else {
  4317. fmt.Println(err)
  4318. }
  4319. userJSONBytes, _ := json.Marshal(dat)
  4320. var res ResultEleven
  4321. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4322. utils.ErrorLog("解析失败:%v", err)
  4323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4324. return
  4325. }
  4326. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4327. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  4328. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, order.PatientId, order.SettleAccountsDate)
  4329. adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  4330. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4331. var doctor_name string
  4332. if roles.ID == 0 {
  4333. doctor_name = "管理员"
  4334. } else {
  4335. doctor_name = roles.UserName
  4336. }
  4337. yiliao_leibie := ""
  4338. switch order.MedType {
  4339. case "11":
  4340. yiliao_leibie = "普通门诊"
  4341. break
  4342. case "12":
  4343. yiliao_leibie = "门诊挂号"
  4344. break
  4345. case "13":
  4346. yiliao_leibie = "急诊"
  4347. break
  4348. case "14":
  4349. yiliao_leibie = "门诊特殊病"
  4350. break
  4351. case "15":
  4352. yiliao_leibie = "门诊统筹"
  4353. break
  4354. case "16":
  4355. yiliao_leibie = "门诊慢性病"
  4356. break
  4357. case "21":
  4358. yiliao_leibie = "普通住院"
  4359. break
  4360. }
  4361. departments, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  4362. if res.Infcode == 0 {
  4363. c.ServeSuccessJSON(map[string]interface{}{
  4364. "diagnosis": name,
  4365. "order_infos": orderInfos,
  4366. "number": order.MdtrtId,
  4367. "date": order.SettleAccountsDate,
  4368. "charge_admin": charge_admin,
  4369. "printor_admin": printor_admin,
  4370. "info": res.Output.Setlinfo,
  4371. "bedCostTotal": bedCostTotal,
  4372. "bedCostSelfTotal": bedCostSelfTotal,
  4373. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  4374. "operationCostTotal": operationCostTotal,
  4375. "operationCostSelfTotal": operationCostSelfTotal,
  4376. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  4377. "otherCostTotal": otherCostTotal,
  4378. "otherCostSelfTotal": otherCostSelfTotal,
  4379. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  4380. "materialCostTotal": materialCostTotal,
  4381. "materialCostSelfTotal": materialCostSelfTotal,
  4382. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  4383. "westernMedicineCostTotal": westernMedicineCostTotal,
  4384. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  4385. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  4386. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  4387. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  4388. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  4389. "checkCostTotal": checkCostTotal,
  4390. "checkCostSelfTotal": checkCostSelfTotal,
  4391. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  4392. "laboratoryCostTotal": laboratoryCostTotal,
  4393. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  4394. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  4395. "treatCostTotal": treatCostTotal,
  4396. "treatCostSelfTotal": treatCostSelfTotal,
  4397. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  4398. "doctor_code": adminRole_two.DoctorCode,
  4399. "doctor_name": doctor_name,
  4400. "health_card_no": order.PsnNo,
  4401. "department": departments.Name,
  4402. "yiliao_leibie": yiliao_leibie,
  4403. "after_money": order.AccountPrice,
  4404. "patient": patient,
  4405. "org_name": miConfig.OrgName,
  4406. "org_code": miConfig.Code,
  4407. "order_number": order.Number,
  4408. })
  4409. }
  4410. }
  4411. }
  4412. func (c *HisApiController) CheckTreatment() {
  4413. patient_id, _ := c.GetInt64("patient_id", 0)
  4414. record_time := c.GetString("record_time")
  4415. insutype := c.GetString("insutype")
  4416. timeLayout := "2006-01-02"
  4417. loc, _ := time.LoadLocation("Local")
  4418. adminUser := c.GetAdminUserInfo()
  4419. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4420. fmt.Println(err)
  4421. if err != nil {
  4422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4423. return
  4424. }
  4425. recordDateTime := theTime.Unix()
  4426. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  4427. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  4428. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4429. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4430. var user_name string
  4431. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  4432. if role.ID == 0 {
  4433. user_name = "xxx"
  4434. } else {
  4435. user_name = role.UserName
  4436. }
  4437. baseParams := models.BaseParams{
  4438. SecretKey: miConfig.SecretKey,
  4439. FixmedinsCode: miConfig.Code,
  4440. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4441. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4442. OrgName: miConfig.OrgName,
  4443. Doctor: user_name,
  4444. }
  4445. if config.IsOpen == 1 {
  4446. result := service.Gdyb2001(baseParams, his.PsnNo, insutype, strconv.FormatInt(patientPrescription.RegisterType, 10))
  4447. var dat map[string]interface{}
  4448. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4449. fmt.Println(dat)
  4450. } else {
  4451. fmt.Println(err)
  4452. }
  4453. }
  4454. }
  4455. func (c *HisApiController) PutRecord() {
  4456. id, _ := c.GetInt64("id")
  4457. record_time := c.GetString("record_time")
  4458. timeLayout := "2006-01-02"
  4459. loc, _ := time.LoadLocation("Local")
  4460. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4461. if err != nil {
  4462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4463. return
  4464. }
  4465. recordDateTime := theTime.Unix()
  4466. adminInfo := c.GetAdminUserInfo()
  4467. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  4468. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  4469. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  4470. fmt.Println(miConfig.SecretKey)
  4471. if patient == nil {
  4472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4473. return
  4474. }
  4475. if len(patient.IdCardNo) == 0 {
  4476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  4477. return
  4478. }
  4479. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  4480. if config.IsOpen == 1 {
  4481. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4482. resp, requestErr := http.Get(api)
  4483. if requestErr != nil {
  4484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4485. return
  4486. }
  4487. defer resp.Body.Close()
  4488. body, ioErr := ioutil.ReadAll(resp.Body)
  4489. if ioErr != nil {
  4490. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4492. return
  4493. }
  4494. var respJSON map[string]interface{}
  4495. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4496. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4498. return
  4499. }
  4500. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4501. userJSONBytes, _ := json.Marshal(userJSON)
  4502. var res ResultTwo
  4503. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4504. utils.ErrorLog("解析失败:%v", err)
  4505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4506. return
  4507. }
  4508. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  4509. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  4510. infoStr := string(Iinfos)
  4511. idetinfoStr := string(Idetinfos)
  4512. if res.Infcode == 0 {
  4513. his := models.VMHisPatient{
  4514. Status: 1,
  4515. Ctime: time.Now().Unix(),
  4516. Mtime: time.Now().Unix(),
  4517. PsnNo: res.Output.Baseinfo.PsnNo,
  4518. PsnCertType: res.Output.Baseinfo.PsnCertType,
  4519. Certno: res.Output.Baseinfo.Certno,
  4520. PsnName: res.Output.Baseinfo.PsnName,
  4521. Gend: res.Output.Baseinfo.Gend,
  4522. Naty: res.Output.Baseinfo.Naty,
  4523. Brdy: res.Output.Baseinfo.Brdy,
  4524. Age: res.Output.Baseinfo.Age,
  4525. Iinfo: infoStr,
  4526. Idetinfo: idetinfoStr,
  4527. PatientId: patient.ID,
  4528. RecordDate: theTime.Unix(),
  4529. UserOrgId: adminInfo.CurrentOrgId,
  4530. AdminUserId: adminInfo.AdminUser.Id,
  4531. IsReturn: 1,
  4532. }
  4533. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  4534. result := service.Gdyb2503(his.PsnNo, res.Output.Iinfo[0].Insutype, miConfig.OrgName, patientPrescription.Doctor, miConfig.Code, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "重症尿毒症透析(血透)", "M07801")
  4535. result2 := service.Gdyb5301(his.PsnNo, res.Output.Iinfo[0].Insutype, miConfig.OrgName, patientPrescription.Doctor, miConfig.Code, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "重症尿毒症透析(血透)", "M07801")
  4536. var dat map[string]interface{}
  4537. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4538. fmt.Println(dat)
  4539. } else {
  4540. fmt.Println(err)
  4541. }
  4542. var dat2 map[string]interface{}
  4543. if err := json.Unmarshal([]byte(result2), &dat2); err == nil {
  4544. fmt.Println(dat2)
  4545. } else {
  4546. fmt.Println(err)
  4547. }
  4548. } else {
  4549. adminUser := c.GetAdminUserInfo()
  4550. errlog := &models.HisOrderError{
  4551. UserOrgId: adminUser.CurrentOrgId,
  4552. Ctime: time.Now().Unix(),
  4553. Mtime: time.Now().Unix(),
  4554. ErrMsg: res.ErrMsg,
  4555. Status: 1,
  4556. PatientId: id,
  4557. RecordTime: recordDateTime,
  4558. Stage: 1,
  4559. }
  4560. service.CreateErrMsgLog(errlog)
  4561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  4562. return
  4563. }
  4564. }
  4565. }
  4566. func (c *HisApiController) GetUploadDiag() {
  4567. id, _ := c.GetInt64("id")
  4568. record_time := c.GetString("record_time")
  4569. diagnosis_id, _ := c.GetInt64("diagnosis")
  4570. sick_type, _ := c.GetInt64("sick_type")
  4571. reg_type, _ := c.GetInt64("reg_type")
  4572. timeLayout := "2006-01-02"
  4573. loc, _ := time.LoadLocation("Local")
  4574. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4575. if err != nil {
  4576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4577. return
  4578. }
  4579. var patientPrescription models.HisPrescriptionInfo
  4580. recordDateTime := theTime.Unix()
  4581. adminInfo := c.GetAdminUserInfo()
  4582. patientPrescription, _ = service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  4583. if patientPrescription.ID == 0 {
  4584. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  4585. }
  4586. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  4587. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  4588. his, _ := service.GetVMHisPatientInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  4589. sickConfig, _ := service.FindSickById(sick_type)
  4590. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  4591. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  4592. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  4593. "&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + strconv.FormatInt(reg_type, 10) + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code + "&diag_code=" + diagnosisConfig.CountryCode +
  4594. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.ContentCode + "&sick_name=" + sickConfig.ClassName
  4595. resp2, requestErr2 := http.Get(api2)
  4596. if requestErr2 != nil {
  4597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4598. return
  4599. }
  4600. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  4601. if ioErr2 != nil {
  4602. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  4603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4604. return
  4605. }
  4606. var respJSON2 map[string]interface{}
  4607. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  4608. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4610. return
  4611. }
  4612. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4613. userJSONBytes2, _ := json.Marshal(respJSON2)
  4614. var res2 ResultSix
  4615. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  4616. utils.ErrorLog("解析失败:%v", err)
  4617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4618. return
  4619. }
  4620. if res2.Infcode != 0 {
  4621. adminUser := c.GetAdminUserInfo()
  4622. errlog := &models.HisOrderError{
  4623. UserOrgId: adminUser.CurrentOrgId,
  4624. Ctime: time.Now().Unix(),
  4625. Mtime: time.Now().Unix(),
  4626. ErrMsg: res2.ErrMsg,
  4627. Status: 1,
  4628. PatientId: id,
  4629. RecordTime: recordDateTime,
  4630. Stage: 3,
  4631. }
  4632. service.CreateErrMsgLog(errlog)
  4633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  4634. return
  4635. }
  4636. c.ServeSuccessJSON(map[string]interface{}{
  4637. "msg": "上传成功",
  4638. })
  4639. }
  4640. type QueryResult struct {
  4641. ID int64
  4642. Name string
  4643. Code string
  4644. List_type_code string
  4645. }
  4646. func (c *HisApiController) GetCheckCode() {
  4647. ids_str := c.GetString("ids")
  4648. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  4649. ids_arr := strings.Split(ids_str, ",")
  4650. var queryResult []QueryResult
  4651. ids := make([]int64, 0)
  4652. for _, item := range ids_arr {
  4653. id, _ := strconv.ParseInt(item, 10, 64)
  4654. ids = append(ids, id)
  4655. }
  4656. if record_type == 1 {
  4657. drugs, _ := service.GetBatchDrugList(ids)
  4658. for _, item := range drugs {
  4659. result := QueryResult{
  4660. ID: item.ID,
  4661. Name: item.DrugName,
  4662. Code: item.MedicalInsuranceNumber,
  4663. List_type_code: "101",
  4664. }
  4665. queryResult = append(queryResult, result)
  4666. }
  4667. } else if record_type == 2 {
  4668. goods, _ := service.GetBatchGoodInformationList(ids)
  4669. for _, item := range goods {
  4670. result := QueryResult{
  4671. ID: item.ID,
  4672. Name: item.GoodName,
  4673. Code: item.MedicalInsuranceNumber,
  4674. List_type_code: "301",
  4675. }
  4676. queryResult = append(queryResult, result)
  4677. }
  4678. } else if record_type == 3 {
  4679. projects, _ := service.GetBathchMyPorjecgList(ids)
  4680. for _, item := range projects {
  4681. result := QueryResult{
  4682. ID: item.ID,
  4683. Name: item.ProjectName,
  4684. Code: item.MedicalCode,
  4685. List_type_code: "201",
  4686. }
  4687. queryResult = append(queryResult, result)
  4688. }
  4689. }
  4690. admin_user_id, _ := c.GetInt64("admin_user_id")
  4691. adminUser := c.GetAdminUserInfo()
  4692. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4693. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4694. var user_name string
  4695. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4696. if role.ID == 0 {
  4697. user_name = "xxx"
  4698. } else {
  4699. user_name = role.UserName
  4700. }
  4701. baseParams := &models.BaseParams{
  4702. SecretKey: miConfig.SecretKey,
  4703. FixmedinsCode: miConfig.Code,
  4704. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4705. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4706. OrgName: miConfig.OrgName,
  4707. Doctor: user_name,
  4708. }
  4709. if config.IsOpen == 1 {
  4710. for _, item := range queryResult {
  4711. var result string
  4712. if record_type == 1 {
  4713. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  4714. } else if record_type == 2 {
  4715. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  4716. } else if record_type == 3 {
  4717. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  4718. }
  4719. var dat map[string]interface{}
  4720. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4721. fmt.Println(dat)
  4722. } else {
  4723. fmt.Println(err)
  4724. }
  4725. userJSONBytes, _ := json.Marshal(dat)
  4726. var res ResultSix
  4727. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4728. utils.ErrorLog("解析失败:%v", err)
  4729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4730. return
  4731. }
  4732. if res.Infcode == 0 {
  4733. if record_type == 1 {
  4734. service.UpdateBaseDrugById(item.ID)
  4735. } else if record_type == 2 {
  4736. service.UpdateGoodInformaitonByDetail(item.ID)
  4737. } else if record_type == 3 {
  4738. service.UpdateProjectById(item.ID)
  4739. }
  4740. c.ServeSuccessJSON(map[string]interface{}{
  4741. "failed_code": 0,
  4742. "msg": "目录对照成功",
  4743. })
  4744. } else {
  4745. c.ServeSuccessJSON(map[string]interface{}{
  4746. "failed_code": -10,
  4747. "msg": res.ErrMsg,
  4748. })
  4749. }
  4750. }
  4751. }
  4752. }
  4753. func (c *HisApiController) UnCheckCode() {
  4754. ids_str := c.GetString("ids")
  4755. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  4756. admin_user_id, _ := c.GetInt64("admin_user_id")
  4757. ids_arr := strings.Split(ids_str, ",")
  4758. var queryResult []QueryResult
  4759. ids := make([]int64, 0)
  4760. for _, item := range ids_arr {
  4761. id, _ := strconv.ParseInt(item, 10, 64)
  4762. ids = append(ids, id)
  4763. }
  4764. if record_type == 1 {
  4765. drugs, _ := service.GetBatchDrugList(ids)
  4766. for _, item := range drugs {
  4767. result := QueryResult{
  4768. ID: item.ID,
  4769. Name: item.DrugName,
  4770. Code: item.MedicalInsuranceNumber,
  4771. List_type_code: "101",
  4772. }
  4773. queryResult = append(queryResult, result)
  4774. }
  4775. } else if record_type == 2 {
  4776. goods, _ := service.GetBatchGoodInformationList(ids)
  4777. for _, item := range goods {
  4778. result := QueryResult{
  4779. ID: item.ID,
  4780. Name: item.GoodName,
  4781. Code: item.MedicalInsuranceNumber,
  4782. List_type_code: "301",
  4783. }
  4784. queryResult = append(queryResult, result)
  4785. }
  4786. } else if record_type == 3 {
  4787. projects, _ := service.GetBathchMyPorjecgList(ids)
  4788. for _, item := range projects {
  4789. result := QueryResult{
  4790. ID: item.ID,
  4791. Name: item.ProjectName,
  4792. Code: item.MedicalCode,
  4793. List_type_code: "201",
  4794. }
  4795. queryResult = append(queryResult, result)
  4796. }
  4797. }
  4798. adminUser := c.GetAdminUserInfo()
  4799. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4800. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4801. var user_name string
  4802. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4803. if role.ID == 0 {
  4804. user_name = "xxx"
  4805. } else {
  4806. user_name = role.UserName
  4807. }
  4808. baseParams := &models.BaseParams{
  4809. SecretKey: miConfig.SecretKey,
  4810. FixmedinsCode: miConfig.Code,
  4811. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4812. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4813. OrgName: miConfig.OrgName,
  4814. Doctor: user_name,
  4815. }
  4816. if config.IsOpen == 1 {
  4817. for _, item := range queryResult {
  4818. var result string
  4819. if record_type == 1 {
  4820. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  4821. } else if record_type == 2 {
  4822. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  4823. } else if record_type == 3 {
  4824. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  4825. }
  4826. var dat2 map[string]interface{}
  4827. if err := json.Unmarshal([]byte(result), &dat2); err == nil {
  4828. fmt.Println(dat2)
  4829. } else {
  4830. fmt.Println(err)
  4831. }
  4832. userJSONBytes, _ := json.Marshal(dat2)
  4833. var res ResultSix
  4834. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4835. utils.ErrorLog("解析失败:%v", err)
  4836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4837. return
  4838. }
  4839. if res.Infcode == 0 {
  4840. if record_type == 1 {
  4841. service.UpdateDrugByIdDetail(item.ID)
  4842. } else if record_type == 2 {
  4843. service.UpdateGoodInfoById(item.ID)
  4844. } else if record_type == 3 {
  4845. service.UpdateMyProjectById(item.ID)
  4846. }
  4847. c.ServeSuccessJSON(map[string]interface{}{
  4848. "failed_code": 0,
  4849. "msg": "撤销目录对照成功",
  4850. })
  4851. } else {
  4852. c.ServeSuccessJSON(map[string]interface{}{
  4853. "failed_code": -10,
  4854. "msg": res.ErrMsg,
  4855. })
  4856. }
  4857. }
  4858. }
  4859. }
  4860. func (c *HisApiController) GetPatientInfo() {
  4861. id_card_no := c.GetString("id_card_no")
  4862. admin_user_id, _ := c.GetInt64("admin_user_id")
  4863. patient, _ := service.GetPatientByIDCard(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  4864. if patient.ID == 0 {
  4865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4866. return
  4867. }
  4868. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  4869. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  4870. config, _ := service.GetMedicalInsuranceConfig(c.GetAdminUserInfo().CurrentOrgId)
  4871. if config.IsOpen == 1 {
  4872. result := service.Gdyb1101A(id_card_no, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  4873. var dat map[string]interface{}
  4874. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4875. fmt.Println(dat)
  4876. } else {
  4877. fmt.Println(err)
  4878. }
  4879. userJSONBytes, _ := json.Marshal(dat)
  4880. var res ResultTwo
  4881. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4882. utils.ErrorLog("解析失败:%v", err)
  4883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4884. return
  4885. }
  4886. if res.Infcode != 0 {
  4887. c.ServeSuccessJSON(map[string]interface{}{
  4888. "failed_code": -10,
  4889. "msg": res.ErrMsg,
  4890. })
  4891. } else {
  4892. c.ServeSuccessJSON(map[string]interface{}{
  4893. "failed_code": 0,
  4894. "info": res,
  4895. })
  4896. }
  4897. }
  4898. }
  4899. func (c *HisApiController) PsnPutOnRecord() {
  4900. record_type, _ := c.GetInt64("type")
  4901. patient_id, _ := c.GetInt64("patient_id")
  4902. admin_user_id, _ := c.GetInt64("admin_user_id")
  4903. start_time := c.GetString("start_time")
  4904. end_time := c.GetString("end_time")
  4905. adminUser := c.GetAdminUserInfo()
  4906. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4907. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4908. var patients []*models.Patients
  4909. if record_type == 1 { //全部备案
  4910. patient, _ := service.GetAllPatient(adminUser.CurrentOrgId)
  4911. patients = append(patients, patient...)
  4912. } else { //单个备案
  4913. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  4914. patients = append(patients, patient)
  4915. }
  4916. var user_name string
  4917. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4918. if role.ID == 0 {
  4919. user_name = "xxx"
  4920. } else {
  4921. user_name = role.UserName
  4922. }
  4923. if config.IsOpen == 1 {
  4924. for _, item := range patients {
  4925. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + item.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + user_name + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4926. resp, requestErr := http.Get(api)
  4927. if requestErr != nil {
  4928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4929. return
  4930. }
  4931. defer resp.Body.Close()
  4932. body, ioErr := ioutil.ReadAll(resp.Body)
  4933. if ioErr != nil {
  4934. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4936. return
  4937. }
  4938. var respJSON map[string]interface{}
  4939. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4940. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4941. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4942. return
  4943. }
  4944. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4945. userJSONBytes, _ := json.Marshal(userJSON)
  4946. var res ResultTwo
  4947. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4948. utils.ErrorLog("解析失败:%v", err)
  4949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4950. return
  4951. }
  4952. if res.Infcode == 0 {
  4953. result := service.Gdyb2505(res.Output.Baseinfo.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, start_time, end_time)
  4954. var dat map[string]interface{}
  4955. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4956. fmt.Println(dat)
  4957. } else {
  4958. fmt.Println(err)
  4959. }
  4960. userJSONBytes, _ := json.Marshal(dat)
  4961. var res2 ResultThirteen
  4962. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  4963. utils.ErrorLog("解析失败:%v", err)
  4964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4965. return
  4966. }
  4967. if res2.Infcode == 0 {
  4968. psnResult := &models.GdybPsnRecord{
  4969. UserOrgId: adminUser.CurrentOrgId,
  4970. PatientId: item.ID,
  4971. PsnNo: res.Output.Baseinfo.PsnNo,
  4972. Ctime: time.Now().Unix(),
  4973. Mtime: time.Now().Unix(),
  4974. Status: 1,
  4975. IsCancel: 1,
  4976. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  4977. }
  4978. service.CreatePsnRecord(psnResult)
  4979. } else {
  4980. c.ServeSuccessJSON(map[string]interface{}{
  4981. "failed_code": -10,
  4982. "msg": res2.ErrMsg,
  4983. })
  4984. return
  4985. }
  4986. }
  4987. }
  4988. }
  4989. }
  4990. func (c *HisApiController) PsnUnPutOnRecord() {
  4991. id, _ := c.GetInt64("id")
  4992. //record_type, _ := c.GetInt64("type")
  4993. admin_user_id, _ := c.GetInt64("admin_user_id")
  4994. adminUser := c.GetAdminUserInfo()
  4995. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4996. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4997. var user_name string
  4998. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4999. if role.ID == 0 {
  5000. user_name = "xxx"
  5001. } else {
  5002. user_name = role.UserName
  5003. }
  5004. psn_record, _ := service.GetPsnRecordById(id)
  5005. if psn_record.ID == 0 {
  5006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  5007. return
  5008. }
  5009. if config.IsOpen == 1 {
  5010. result := service.Gdyb2506(psn_record.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  5011. var dat map[string]interface{}
  5012. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5013. fmt.Println(dat)
  5014. } else {
  5015. fmt.Println(err)
  5016. }
  5017. userJSONBytes, _ := json.Marshal(dat)
  5018. var res ResultFourteen
  5019. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5020. utils.ErrorLog("解析失败:%v", err)
  5021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5022. return
  5023. }
  5024. if res.Infcode == 0 {
  5025. psn_record.IsCancel = 2
  5026. service.CreatePsnRecord(&psn_record)
  5027. } else {
  5028. c.ServeSuccessJSON(map[string]interface{}{
  5029. "failed_code": -10,
  5030. "msg": res.ErrMsg,
  5031. })
  5032. return
  5033. }
  5034. }
  5035. }
  5036. func (c *HisApiController) PsnPutNCDSOnRecord() {
  5037. patient_id, _ := c.GetInt64("patient_id")
  5038. insutype := c.GetString("insutype")
  5039. psn_no := c.GetString("psn_no")
  5040. doctor_id, _ := c.GetInt64("doctor_id")
  5041. sick_id, _ := c.GetInt64("sick_id")
  5042. department_id, _ := c.GetInt64("department_id")
  5043. adminUser := c.GetAdminUserInfo()
  5044. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  5045. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5046. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5047. sick, _ := service.FindSickById(sick_id)
  5048. doctor, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, doctor_id)
  5049. if config.IsOpen == 1 {
  5050. result := service.Gdyb2503(psn_no, insutype, miConfig.OrgName, doctor.UserName, miConfig.Code, strconv.FormatInt(doctor.ID, 10), miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sick.ClassName, sick.ContentCode)
  5051. var dat map[string]interface{}
  5052. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5053. fmt.Println(dat)
  5054. } else {
  5055. fmt.Println(err)
  5056. }
  5057. userJSONBytes, _ := json.Marshal(dat)
  5058. var res2 ResultThirteen
  5059. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  5060. utils.ErrorLog("解析失败:%v", err)
  5061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5062. return
  5063. }
  5064. if res2.Infcode == 0 {
  5065. psnResult := &models.GdybPsnNcdsRecord{
  5066. UserOrgId: adminUser.CurrentOrgId,
  5067. PatientId: patient.ID,
  5068. PsnNo: psn_no,
  5069. DoctorId: doctor.AdminUserId,
  5070. DepartmentId: department_id,
  5071. SickType: sick_id,
  5072. Insutype: insutype,
  5073. Ctime: time.Now().Unix(),
  5074. Mtime: time.Now().Unix(),
  5075. Status: 1,
  5076. IsCancel: 1,
  5077. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  5078. }
  5079. service.CreatePsnNCDSRecord(psnResult)
  5080. c.ServeSuccessJSON(map[string]interface{}{
  5081. "failed_code": 0,
  5082. "msg": "备案成功",
  5083. "result": psnResult,
  5084. })
  5085. } else {
  5086. c.ServeSuccessJSON(map[string]interface{}{
  5087. "failed_code": -10,
  5088. "msg": res2.ErrMsg,
  5089. })
  5090. return
  5091. }
  5092. }
  5093. }
  5094. func (c *HisApiController) PsnPutUnNCDSOnRecord() {
  5095. id, _ := c.GetInt64("id")
  5096. admin_user_id, _ := c.GetInt64("admin_user_id")
  5097. adminUser := c.GetAdminUserInfo()
  5098. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5099. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5100. var user_name string
  5101. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  5102. if role.ID == 0 {
  5103. user_name = "xxx"
  5104. } else {
  5105. user_name = role.UserName
  5106. }
  5107. psn_record, _ := service.GetPsnNCDSRecordById(id)
  5108. if psn_record.ID == 0 {
  5109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  5110. return
  5111. }
  5112. if config.IsOpen == 1 {
  5113. result := service.Gdyb2504(psn_record.PsnNo, miConfig.OrgName, user_name, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  5114. var dat map[string]interface{}
  5115. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5116. fmt.Println(dat)
  5117. } else {
  5118. fmt.Println(err)
  5119. }
  5120. userJSONBytes, _ := json.Marshal(dat)
  5121. var res ResultFourteen
  5122. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5123. utils.ErrorLog("解析失败:%v", err)
  5124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5125. return
  5126. }
  5127. if res.Infcode == 0 {
  5128. psn_record.IsCancel = 2
  5129. service.CreatePsnNCDSRecord(&psn_record)
  5130. c.ServeSuccessJSON(map[string]interface{}{
  5131. "failed_code": 0,
  5132. "msg": "撤销备案成功",
  5133. })
  5134. } else {
  5135. c.ServeSuccessJSON(map[string]interface{}{
  5136. "failed_code": -10,
  5137. "msg": res.ErrMsg,
  5138. })
  5139. return
  5140. }
  5141. }
  5142. }
  5143. func (c *HisApiController) TestTest() {
  5144. patient, _ := service.GetHisPatientInfo(4, 456, 1619712000)
  5145. fmt.Println(patient.Iinfo)
  5146. }
  5147. type CustomData struct {
  5148. MsgId string
  5149. PsnNo string
  5150. Info string
  5151. }
  5152. func (c *HisApiController) ReversalData() {
  5153. var customData []*CustomData
  5154. custom := &CustomData{
  5155. MsgId: "H44022900158202103301714472004",
  5156. PsnNo: "44020000001101329945",
  5157. Info: "2207",
  5158. }
  5159. customData = append(customData, custom)
  5160. custom1 := &CustomData{
  5161. MsgId: "H4402290015820210330172057803",
  5162. PsnNo: "44020000001101161813",
  5163. Info: "2207",
  5164. }
  5165. customData = append(customData, custom1)
  5166. custom2 := &CustomData{
  5167. MsgId: "H44022900158202103301705198813",
  5168. PsnNo: "44190000133097375417",
  5169. Info: "2207",
  5170. }
  5171. customData = append(customData, custom2)
  5172. custom3 := &CustomData{
  5173. MsgId: "H44022900158202103301715524756",
  5174. PsnNo: "44020000001100187221",
  5175. Info: "2207",
  5176. }
  5177. customData = append(customData, custom3)
  5178. custom4 := &CustomData{
  5179. MsgId: "H44022900158202103301730376224",
  5180. PsnNo: "44020000001101959155",
  5181. Info: "2207",
  5182. }
  5183. customData = append(customData, custom4)
  5184. custom5 := &CustomData{
  5185. MsgId: "H44022900158202103301748008725",
  5186. PsnNo: "44020000001104246641",
  5187. Info: "2207",
  5188. }
  5189. customData = append(customData, custom5)
  5190. custom6 := &CustomData{
  5191. MsgId: "H44022900158202103301718096755",
  5192. PsnNo: "44020000001102211860",
  5193. Info: "2207",
  5194. }
  5195. customData = append(customData, custom6)
  5196. custom7 := &CustomData{
  5197. MsgId: "H44022900158202103301736551640",
  5198. PsnNo: "44020000001102687718",
  5199. Info: "2207",
  5200. }
  5201. customData = append(customData, custom7)
  5202. custom8 := &CustomData{
  5203. MsgId: "H44022900158202103301743097676",
  5204. PsnNo: "44020000001102127785",
  5205. Info: "2207",
  5206. }
  5207. customData = append(customData, custom8)
  5208. custom9 := &CustomData{
  5209. MsgId: "H44022900158202103301712304203",
  5210. PsnNo: "44020000001101518097",
  5211. Info: "2207",
  5212. }
  5213. customData = append(customData, custom9)
  5214. custom10 := &CustomData{
  5215. MsgId: "H44022900158202103301738448785",
  5216. PsnNo: "44020000001100500813",
  5217. Info: "2207",
  5218. }
  5219. customData = append(customData, custom10)
  5220. custom11 := &CustomData{
  5221. MsgId: "H44022900158202103301732455843",
  5222. PsnNo: "44020000001102690557",
  5223. Info: "2207",
  5224. }
  5225. customData = append(customData, custom11)
  5226. custom12 := &CustomData{
  5227. MsgId: "H44022900158202103301745421708",
  5228. PsnNo: "44020000001102211928",
  5229. Info: "2207",
  5230. }
  5231. customData = append(customData, custom12)
  5232. custom1212 := &CustomData{
  5233. MsgId: "H440229001582021033017351627",
  5234. PsnNo: "44020000001102481733",
  5235. Info: "2207",
  5236. }
  5237. customData = append(customData, custom1212)
  5238. custom13 := &CustomData{
  5239. MsgId: "H44022900158202103301740327951",
  5240. PsnNo: "44020000001103174866",
  5241. Info: "2207",
  5242. }
  5243. customData = append(customData, custom13)
  5244. custom14 := &CustomData{
  5245. MsgId: "H4402290015820210330174922668",
  5246. PsnNo: "44020000001102927272",
  5247. Info: "2207",
  5248. }
  5249. customData = append(customData, custom14)
  5250. custom15 := &CustomData{
  5251. MsgId: "H44022900158202103301752362273",
  5252. PsnNo: "44020000001102942890",
  5253. Info: "2207",
  5254. }
  5255. customData = append(customData, custom15)
  5256. custom16 := &CustomData{
  5257. MsgId: "H44022900158202103301751082917",
  5258. PsnNo: "44020000001101662162",
  5259. Info: "2207",
  5260. }
  5261. customData = append(customData, custom16)
  5262. custom17 := &CustomData{
  5263. MsgId: "H44022900158202103301754147728",
  5264. PsnNo: "44020000000229014511",
  5265. Info: "2207",
  5266. }
  5267. customData = append(customData, custom17)
  5268. adminUser := c.GetAdminUserInfo()
  5269. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5270. for _, item := range customData {
  5271. result := service.Gdyb2601(item.PsnNo, item.MsgId, item.Info, miConfig.OrgName, "张俊杰", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  5272. fmt.Println(result)
  5273. }
  5274. }
  5275. func (c *HisApiController) ReversalOtherData() {
  5276. var customData []*CustomData
  5277. custom := &CustomData{
  5278. MsgId: "H44022900158202103301714472004",
  5279. PsnNo: "44020000001101329945",
  5280. Info: "2208",
  5281. }
  5282. customData = append(customData, custom)
  5283. custom1 := &CustomData{
  5284. MsgId: "H4402290015820210330172057803",
  5285. PsnNo: "44020000001101161813",
  5286. Info: "2208",
  5287. }
  5288. customData = append(customData, custom1)
  5289. custom2 := &CustomData{
  5290. MsgId: "H44022900158202103301705198813",
  5291. PsnNo: "44190000133097375417",
  5292. Info: "2208",
  5293. }
  5294. customData = append(customData, custom2)
  5295. custom3 := &CustomData{
  5296. MsgId: "H44022900158202103301715524756",
  5297. PsnNo: "44020000001100187221",
  5298. Info: "2208",
  5299. }
  5300. customData = append(customData, custom3)
  5301. custom4 := &CustomData{
  5302. MsgId: "H44022900158202103301730376224",
  5303. PsnNo: "44020000001101959155",
  5304. Info: "2208",
  5305. }
  5306. customData = append(customData, custom4)
  5307. custom5 := &CustomData{
  5308. MsgId: "H44022900158202103301748008725",
  5309. PsnNo: "44020000001104246641",
  5310. Info: "2208",
  5311. }
  5312. customData = append(customData, custom5)
  5313. custom6 := &CustomData{
  5314. MsgId: "H44022900158202103301718096755",
  5315. PsnNo: "44020000001102211860",
  5316. Info: "2208",
  5317. }
  5318. customData = append(customData, custom6)
  5319. custom7 := &CustomData{
  5320. MsgId: "H44022900158202103301736551640",
  5321. PsnNo: "44020000001102687718",
  5322. Info: "2208",
  5323. }
  5324. customData = append(customData, custom7)
  5325. custom8 := &CustomData{
  5326. MsgId: "H44022900158202103301743097676",
  5327. PsnNo: "44020000001102127785",
  5328. Info: "2208",
  5329. }
  5330. customData = append(customData, custom8)
  5331. custom9 := &CustomData{
  5332. MsgId: "H44022900158202103301712304203",
  5333. PsnNo: "44020000001101518097",
  5334. Info: "2208",
  5335. }
  5336. customData = append(customData, custom9)
  5337. custom10 := &CustomData{
  5338. MsgId: "H44022900158202103301738448785",
  5339. PsnNo: "44020000001100500813",
  5340. Info: "2208",
  5341. }
  5342. customData = append(customData, custom10)
  5343. custom11 := &CustomData{
  5344. MsgId: "H44022900158202103301732455843",
  5345. PsnNo: "44020000001102690557",
  5346. Info: "2208",
  5347. }
  5348. customData = append(customData, custom11)
  5349. custom12 := &CustomData{
  5350. MsgId: "H44022900158202103301745421708",
  5351. PsnNo: "44020000001102211928",
  5352. Info: "2208",
  5353. }
  5354. customData = append(customData, custom12)
  5355. custom1212 := &CustomData{
  5356. MsgId: "H440229001582021033017351627",
  5357. PsnNo: "44020000001102481733",
  5358. Info: "2208",
  5359. }
  5360. customData = append(customData, custom1212)
  5361. custom13 := &CustomData{
  5362. MsgId: "H44022900158202103301740327951",
  5363. PsnNo: "44020000001103174866",
  5364. Info: "2208",
  5365. }
  5366. customData = append(customData, custom13)
  5367. custom14 := &CustomData{
  5368. MsgId: "H4402290015820210330174922668",
  5369. PsnNo: "44020000001102927272",
  5370. Info: "2208",
  5371. }
  5372. customData = append(customData, custom14)
  5373. custom15 := &CustomData{
  5374. MsgId: "H44022900158202103301752362273",
  5375. PsnNo: "44020000001102942890",
  5376. Info: "2208",
  5377. }
  5378. customData = append(customData, custom15)
  5379. custom16 := &CustomData{
  5380. MsgId: "H44022900158202103301751082917",
  5381. PsnNo: "44020000001101662162",
  5382. Info: "2208",
  5383. }
  5384. customData = append(customData, custom16)
  5385. custom17 := &CustomData{
  5386. MsgId: "H44022900158202103301754147728",
  5387. PsnNo: "44020000000229014511",
  5388. Info: "2208",
  5389. }
  5390. customData = append(customData, custom17)
  5391. adminUser := c.GetAdminUserInfo()
  5392. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5393. for _, item := range customData {
  5394. result := service.Gdyb2601(item.PsnNo, item.MsgId, item.Info, miConfig.OrgName, "张俊杰", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  5395. fmt.Println(result)
  5396. }
  5397. }
  5398. func PathExists(path string) (bool, error) {
  5399. _, err := os.Stat(path)
  5400. if err == nil {
  5401. return true, nil
  5402. }
  5403. if os.IsNotExist(err) {
  5404. return false, nil
  5405. }
  5406. return false, err
  5407. }
  5408. //创建文件夹
  5409. func Mkdir(dir string) {
  5410. // 创建文件夹
  5411. exist, err := PathExists(dir)
  5412. if err != nil {
  5413. fmt.Println(err.Error())
  5414. } else {
  5415. if exist {
  5416. fmt.Println(dir + "文件夹已存在!")
  5417. } else {
  5418. // 文件夹名称,权限
  5419. err := os.Mkdir(dir, os.ModePerm)
  5420. if err != nil {
  5421. fmt.Println(dir+"文件夹创建失败:", err.Error())
  5422. } else {
  5423. fmt.Println(dir + "文件夹创建成功!")
  5424. }
  5425. }
  5426. }
  5427. }
  5428. //压缩文件
  5429. func Zip(srcFile string, destZip string) error {
  5430. zipfile, err := os.Create(destZip)
  5431. if err != nil {
  5432. return err
  5433. }
  5434. defer zipfile.Close()
  5435. archive := zip.NewWriter(zipfile)
  5436. defer archive.Close()
  5437. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  5438. if err != nil {
  5439. return err
  5440. }
  5441. header, err := zip.FileInfoHeader(info)
  5442. if err != nil {
  5443. return err
  5444. }
  5445. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  5446. // header.Name = path
  5447. if info.IsDir() {
  5448. header.Name += "/"
  5449. } else {
  5450. header.Method = zip.Deflate
  5451. }
  5452. writer, err := archive.CreateHeader(header)
  5453. if err != nil {
  5454. return err
  5455. }
  5456. if !info.IsDir() {
  5457. file, err := os.Open(path)
  5458. if err != nil {
  5459. return err
  5460. }
  5461. defer file.Close()
  5462. _, err = io.Copy(writer, file)
  5463. }
  5464. return err
  5465. })
  5466. return err
  5467. }
  5468. func ReadFile(filePath string) []byte {
  5469. f, err := os.Open(filePath)
  5470. if err != nil {
  5471. fmt.Println("read file fail", err)
  5472. return nil
  5473. }
  5474. defer f.Close()
  5475. fd, err := ioutil.ReadAll(f)
  5476. if err != nil {
  5477. fmt.Println("read to fd fail", err)
  5478. return nil
  5479. }
  5480. return fd
  5481. }
  5482. func RemoveRepeatedCode(arr []string) (newArr []string) {
  5483. newArr = make([]string, 0)
  5484. for i := 0; i < len(arr); i++ {
  5485. repeat := false
  5486. for j := i + 1; j < len(arr); j++ {
  5487. if arr[i] == arr[j] {
  5488. repeat = true
  5489. break
  5490. }
  5491. }
  5492. if !repeat {
  5493. newArr = append(newArr, arr[i])
  5494. }
  5495. }
  5496. return
  5497. }
  5498. func saveRegisterLog(result string) {
  5499. org_id, _ := beego.AppConfig.Int64("org_id")
  5500. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  5501. dir := miConfig.OrgName + "日志"
  5502. utils.Mkdir(dir)
  5503. month := time.Unix(1557042972, 0).Format("1")
  5504. year := time.Now().Format("2006")
  5505. month = time.Now().Format("01")
  5506. day := time.Now().Format("02")
  5507. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  5508. file_name := file + ".txt"
  5509. file_path := miConfig.OrgName + "日志" + "/" + file_name
  5510. exist, _ := utils.PathExists(file_path)
  5511. if exist { //存在
  5512. fmt.Println("存在")
  5513. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  5514. if err != nil {
  5515. fmt.Println("read fail")
  5516. }
  5517. content := "\r\n" + result
  5518. n, _ := f.Seek(0, 2)
  5519. _, err = f.WriteAt([]byte(content), n)
  5520. } else { //不存在
  5521. fmt.Println("文件不存在,创建文件")
  5522. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  5523. defer f.Close()
  5524. if err != nil {
  5525. } else {
  5526. _, err = f.Write([]byte("记录日志"))
  5527. }
  5528. }
  5529. }
  5530. func saveLog(result string, request string) {
  5531. org_id, _ := beego.AppConfig.Int64("org_id")
  5532. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  5533. dir := miConfig.OrgName + "日志"
  5534. utils.Mkdir(dir)
  5535. month := time.Unix(1557042972, 0).Format("1")
  5536. year := time.Now().Format("2006")
  5537. month = time.Now().Format("01")
  5538. day := time.Now().Format("02")
  5539. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  5540. file_name := file + ".txt"
  5541. file_path := miConfig.OrgName + "日志" + "/" + file_name
  5542. exist, _ := utils.PathExists(file_path)
  5543. if exist { //存在
  5544. fmt.Println("存在")
  5545. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  5546. if err != nil {
  5547. fmt.Println("read fail")
  5548. }
  5549. content := "\n" + request + "\n" + result
  5550. n, _ := f.Seek(0, 2)
  5551. _, err = f.WriteAt([]byte(content), n)
  5552. } else { //不存在
  5553. fmt.Println("文件不存在,创建文件")
  5554. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  5555. defer f.Close()
  5556. if err != nil {
  5557. } else {
  5558. _, err = f.Write([]byte("记录日志"))
  5559. }
  5560. }
  5561. }