his_api_controller.go 211KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127
  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, "1101")
  1571. //register_log = requestLog + "\r\n" + "\r\n" + "\r\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. saveLog(result, requestLog, "2201")
  1666. //register_log = register_log + requestLog + "\r\n" + "\r\n" + "\r\n" + result + "\r\n" + "\r\n" + "\r\n"
  1667. //saveRegisterLog(register_log)
  1668. var res ResultThree
  1669. if err := json.Unmarshal([]byte(result), &res); err != nil {
  1670. utils.ErrorLog("解析失败:%v", err)
  1671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1672. return
  1673. }
  1674. if res.Infcode != 0 {
  1675. adminUser := c.GetAdminUserInfo()
  1676. errlog := &models.HisOrderError{
  1677. UserOrgId: adminUser.CurrentOrgId,
  1678. Ctime: time.Now().Unix(),
  1679. Mtime: time.Now().Unix(),
  1680. ErrMsg: res.ErrMsg,
  1681. Status: 1,
  1682. PatientId: id,
  1683. RecordTime: recordDateTime,
  1684. Stage: 2,
  1685. }
  1686. service.CreateErrMsgLog(errlog)
  1687. c.ServeSuccessJSON(map[string]interface{}{
  1688. "failed_code": -10,
  1689. "msg": res.ErrMsg,
  1690. })
  1691. return
  1692. }
  1693. his.Number = res.Output.Data.MdtrtID
  1694. his.PsnNo = res.Output.Data.PsnNo
  1695. his.IptOtpNo = res.Output.Data.IptOtpNo
  1696. his.IdCardNo = patient.IdCardNo
  1697. his.PhoneNumber = patient.Phone
  1698. his.UserOrgId = adminInfo.CurrentOrgId
  1699. his.Ctime = time.Now().Unix()
  1700. his.Mtime = time.Now().Unix()
  1701. his.Status = 1
  1702. service.UpdateHisPatientStatus(&his)
  1703. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  1704. c.ServeSuccessJSON(map[string]interface{}{
  1705. "his_info": his,
  1706. })
  1707. } else {
  1708. adminUser := c.GetAdminUserInfo()
  1709. errlog := &models.HisOrderError{
  1710. UserOrgId: adminUser.CurrentOrgId,
  1711. Ctime: time.Now().Unix(),
  1712. Mtime: time.Now().Unix(),
  1713. ErrMsg: res.ErrMsg,
  1714. Status: 1,
  1715. PatientId: id,
  1716. RecordTime: recordDateTime,
  1717. Stage: 1,
  1718. }
  1719. service.CreateErrMsgLog(errlog)
  1720. c.ServeSuccessJSON(map[string]interface{}{
  1721. "failed_code": -10,
  1722. "msg": res.ErrMsg,
  1723. })
  1724. return
  1725. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  1726. }
  1727. }
  1728. }
  1729. //上传明细----预结算----确认订单
  1730. func (c *HisApiController) GetUploadInfo() {
  1731. id, _ := c.GetInt64("id")
  1732. record_time := c.GetString("record_time")
  1733. his_patient_id, _ := c.GetInt64("his_patient_id")
  1734. order_id, _ := c.GetInt64("order_id")
  1735. pay_way, _ := c.GetInt64("pay_way")
  1736. pay_price, _ := c.GetFloat("pay_price")
  1737. pay_card_no := c.GetString("pay_card_no")
  1738. discount_price, _ := c.GetFloat("discount_price")
  1739. preferential_price, _ := c.GetFloat("preferential_price")
  1740. reality_price, _ := c.GetFloat("reality_price")
  1741. found_price, _ := c.GetFloat("found_price")
  1742. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1743. private_price, _ := c.GetFloat("private_price")
  1744. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1745. admin_user_id, _ := c.GetInt64("admin_user_id")
  1746. fapiao_code := c.GetString("fapiao_code")
  1747. fapiao_number := c.GetString("fapiao_number")
  1748. diagnosis_id := c.GetString("diagnosis")
  1749. sick_type, _ := c.GetInt64("sick_type")
  1750. reg_type, _ := c.GetInt64("p_type")
  1751. id_str := c.GetString("ids")
  1752. ids_arr := strings.Split(id_str, ",")
  1753. timeLayout := "2006-01-02"
  1754. loc, _ := time.LoadLocation("Local")
  1755. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1756. if err != nil {
  1757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1758. return
  1759. }
  1760. recordDateTime := theTime.Unix()
  1761. adminUser := c.GetAdminUserInfo()
  1762. var tempOrder models.HisOrder
  1763. tempOrder, _ = service.GetHisOrderByID(order_id)
  1764. var prescriptions []*models.HisPrescription
  1765. var start_time int64
  1766. var end_time int64
  1767. //if adminUser.CurrentOrgId == 10106{
  1768. // if len(fapiao_code) == 0{
  1769. // fapiao_code = "144072080589"
  1770. // }
  1771. // if len(fapiao_number) == 0{
  1772. // order, _ := service.GetLastHisOrder(adminUser.CurrentOrgId)
  1773. // if order.ID == 0{
  1774. // fapiao_number = "00001520"
  1775. // }else{
  1776. // //fapiao_code = "00001520"
  1777. // fpNumber, _ := strconv.Atoi(order.FaPiaoNumber)
  1778. // var zero string
  1779. // if fpNumber >= 1000{
  1780. // zero = "0000" + strconv.Itoa(fpNumber)
  1781. // }else if fpNumber >= 10000{
  1782. // zero = "000" + strconv.Itoa(fpNumber)
  1783. // } else if fpNumber >= 100000{
  1784. // zero = "00" + strconv.Itoa(fpNumber)
  1785. // } else if fpNumber >= 1000000{
  1786. // zero = "0" + strconv.Itoa(fpNumber)
  1787. // }else {
  1788. // zero = strconv.Itoa(fpNumber)
  1789. // }
  1790. // fapiao_number = zero
  1791. // }
  1792. // }
  1793. //}
  1794. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1795. his, _ := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  1796. var patientPrescription models.HisPrescriptionInfo
  1797. patientPrescription, _ = service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  1798. if patientPrescription.ID == 0 {
  1799. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1800. }
  1801. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1802. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1803. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  1804. diagnosis_ids := strings.Split(diagnosis_id, ",")
  1805. var config []*models.HisXtDiagnoseConfig
  1806. for _, item := range diagnosis_ids {
  1807. id, _ := strconv.ParseInt(item, 10, 64)
  1808. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1809. config = append(config, diagnosisConfig)
  1810. }
  1811. sickConfig, _ := service.FindSickById(sick_type)
  1812. if tempOrder.ID == 0 {
  1813. tempOrder, _ = service.GetTodayHisOrder(adminUser.CurrentOrgId, id, recordDateTime, his.Number)
  1814. }
  1815. if tempOrder.ID == 0 {
  1816. var result string
  1817. var requestLog string
  1818. if miConfig.InsuplcAdmdvs == "440781" { //
  1819. 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)
  1820. } else {
  1821. 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)
  1822. }
  1823. saveLog(result, requestLog, "2203")
  1824. var respJSON2 map[string]interface{}
  1825. if err := json.Unmarshal([]byte(string(result)), &respJSON2); err != nil {
  1826. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1828. return
  1829. }
  1830. userJSONBytes2, _ := json.Marshal(respJSON2)
  1831. var res2 ResultSix
  1832. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  1833. utils.ErrorLog("解析失败:%v", err)
  1834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1835. return
  1836. }
  1837. if res2.Infcode != 0 {
  1838. adminUser := c.GetAdminUserInfo()
  1839. errlog := &models.HisOrderError{
  1840. UserOrgId: adminUser.CurrentOrgId,
  1841. Ctime: time.Now().Unix(),
  1842. Mtime: time.Now().Unix(),
  1843. ErrMsg: res2.ErrMsg,
  1844. Status: 1,
  1845. PatientId: id,
  1846. RecordTime: recordDateTime,
  1847. Stage: 3,
  1848. }
  1849. service.CreateErrMsgLog(errlog)
  1850. c.ServeSuccessJSON(map[string]interface{}{
  1851. "failed_code": -10,
  1852. "msg": res2.ErrMsg,
  1853. })
  1854. return
  1855. } else {
  1856. his.Diagnosis = diagnosis_id
  1857. his.SickType = sickConfig.ID
  1858. his.PType = fmt.Sprintf("%d", reg_type)
  1859. service.UpdateHisPatientThree(&his)
  1860. data := make(map[string]interface{})
  1861. if settle_accounts_type == 1 { //日结
  1862. if reg_type == 11 {
  1863. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  1864. } else {
  1865. prescriptions, _ = service.GetNewHisPrescription(adminUser.CurrentOrgId, his_patient_id, recordDateTime, strconv.Itoa(int(reg_type)))
  1866. }
  1867. //prescriptions, _ = service.GetNewHisPrescriptionTwo(adminUser.CurrentOrgId, his_patient_id, recordDateTime, reg_type)
  1868. data["pre"] = prescriptions
  1869. } else { //月结
  1870. start_time_str := c.GetString("start_time")
  1871. end_time_str := c.GetString("end_time")
  1872. timeLayout := "2006-01-02"
  1873. loc, _ := time.LoadLocation("Local")
  1874. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1875. if err != nil {
  1876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1877. return
  1878. }
  1879. recordStartTime := theStartTime.Unix()
  1880. start_time = recordStartTime
  1881. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1882. if err != nil {
  1883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1884. return
  1885. }
  1886. recordEndTime := theEndTime.Unix()
  1887. end_time = recordEndTime
  1888. prescriptions, _ = service.GetMonthHisPrescriptionTwo(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  1889. data["pre"] = prescriptions
  1890. }
  1891. if reg_type == 1111 || reg_type == 1112 {
  1892. reg_type = 11
  1893. }
  1894. timestamp := time.Now().Unix()
  1895. tempTime := time.Unix(timestamp, 0)
  1896. timeFormat := tempTime.Format("20060102150405")
  1897. chrgBchno := rand.Intn(100000) + 10000
  1898. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1899. strconv.FormatInt(his.PatientId, 10)
  1900. client := &http.Client{}
  1901. data["psn_no"] = his.PsnNo
  1902. data["mdtrt_id"] = his.Number
  1903. data["chrg_bchno"] = chrg_bchno
  1904. data["org_name"] = miConfig.OrgName
  1905. data["doctor"] = roles.UserName
  1906. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1907. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  1908. data["fixmedins_code"] = miConfig.Code
  1909. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  1910. data["dept_code"] = "15"
  1911. } else {
  1912. data["dept_code"] = department.Number
  1913. }
  1914. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1915. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1916. data["secret_key"] = miConfig.SecretKey
  1917. data["balance_accounts_type"] = strconv.FormatInt(his.BalanceAccountsType, 10)
  1918. var ids []int64
  1919. for _, item := range prescriptions {
  1920. ids = append(ids, item.ID)
  1921. }
  1922. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1923. if config.IsOpen == 1 { //对接了医保,走医保流程
  1924. result, request_log := service.Gdyb2204(his.PsnNo, his.Number, prescriptions, chrg_bchno, miConfig.OrgName, roles.UserName, data["dept"].(string), data["fixmedins_code"].(string), data["dept_code"].(string), data["doctor_id"].(string), miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, data["balance_accounts_type"].(string))
  1925. var dat map[string]interface{}
  1926. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1927. fmt.Println(dat)
  1928. } else {
  1929. fmt.Println(err)
  1930. }
  1931. saveLog(result, request_log, "2204")
  1932. userJSONBytes, _ := json.Marshal(dat)
  1933. var res ResultFour
  1934. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1935. utils.ErrorLog("解析失败:%v", err)
  1936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1937. return
  1938. }
  1939. if res.Infcode == 0 {
  1940. order := &models.HisOrder{
  1941. UserOrgId: adminUser.CurrentOrgId,
  1942. HisPatientId: his.ID,
  1943. PatientId: his.PatientId,
  1944. SettleAccountsDate: recordDateTime,
  1945. Ctime: time.Now().Unix(),
  1946. Mtime: time.Now().Unix(),
  1947. Status: 0,
  1948. Number: chrg_bchno,
  1949. Infcode: res.Infcode,
  1950. WarnMsg: res.WarnMsg,
  1951. Cainfo: res.Cainfo,
  1952. ErrMsg: res.ErrMsg,
  1953. RespondTime: res.RefmsgTime,
  1954. InfRefmsgid: res.InfRefmsgid,
  1955. OrderStatus: 1,
  1956. PayWay: pay_way,
  1957. PayPrice: pay_price,
  1958. PayCardNo: pay_card_no,
  1959. DiscountPrice: discount_price,
  1960. PreferentialPrice: preferential_price,
  1961. RealityPrice: reality_price,
  1962. FoundPrice: found_price,
  1963. MedicalInsurancePrice: medical_insurance_price,
  1964. PrivatePrice: private_price,
  1965. IsMedicineInsurance: 1,
  1966. SettleType: settle_accounts_type,
  1967. SettleStartTime: start_time,
  1968. SettleEndTime: end_time,
  1969. Creator: roles.AdminUserId,
  1970. Modify: roles.AdminUserId,
  1971. FaPiaoNumber: fapiao_number,
  1972. FaPiaoCode: fapiao_code,
  1973. PType: 2,
  1974. Diagnosis: diagnosis_id,
  1975. }
  1976. err = service.CreateOrder(order)
  1977. if err != nil {
  1978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1979. return
  1980. }
  1981. for _, item := range res.Output.Result {
  1982. temp := strings.Split(item.FeedetlSn, "-")
  1983. var advice_id int64 = 0
  1984. var project_id int64 = 0
  1985. var types int64 = 0
  1986. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1987. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1988. if temp[1] == "1" {
  1989. advice_id = id
  1990. project_id = 0
  1991. } else if temp[1] == "2" {
  1992. advice_id = 0
  1993. project_id = id
  1994. }
  1995. info := &models.HisOrderInfo{
  1996. OrderNumber: order.Number,
  1997. FeedetlSn: item.FeedetlSn,
  1998. UploadDate: time.Now().Unix(),
  1999. AdviceId: advice_id,
  2000. DetItemFeeSumamt: item.DetItemFeeSumamt,
  2001. Cnt: item.Cnt,
  2002. Pric: float64(item.Pric),
  2003. PatientId: his.PatientId,
  2004. PricUplmtAmt: item.PricUplmtAmt,
  2005. SelfpayProp: item.SelfpayProp,
  2006. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2007. OverlmtAmt: item.OverlmtAmt,
  2008. PreselfpayAmt: item.PreselfpayAmt,
  2009. BasMednFlag: item.BasMednFlag,
  2010. MedChrgitmType: item.MedChrgitmType,
  2011. HiNegoDrugFlag: item.HiNegoDrugFlag,
  2012. Status: 1,
  2013. Memo: item.Memo,
  2014. Mtime: time.Now().Unix(),
  2015. InscpScpAmt: item.InscpScpAmt,
  2016. DrtReimFlag: item.DrtReimFlag,
  2017. Ctime: time.Now().Unix(),
  2018. ListSpItemFlag: item.ListSpItemFlag,
  2019. ChldMedcFlag: item.ChldMedcFlag,
  2020. LmtUsedFlag: item.LmtUsedFlag,
  2021. ChrgitmLv: item.ChrgitmLv,
  2022. UserOrgId: adminUser.CurrentOrgId,
  2023. HisPatientId: his.ID,
  2024. OrderId: order.ID,
  2025. ProjectId: project_id,
  2026. Type: types,
  2027. }
  2028. service.CreateOrderInfo(info)
  2029. }
  2030. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2031. service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, his_patient_id, chrg_bchno, recordDateTime)
  2032. var total float64
  2033. for _, item := range prescriptions {
  2034. if item.Type == 1 { //药品
  2035. for _, subItem := range item.HisDoctorAdviceInfo {
  2036. total = total + (subItem.Price * subItem.PrescribingNumber)
  2037. }
  2038. }
  2039. if item.Type == 2 { //项目
  2040. for _, subItem := range item.HisPrescriptionProject {
  2041. total = total + (subItem.Price * float64(subItem.Count))
  2042. }
  2043. }
  2044. }
  2045. for _, item := range prescriptions {
  2046. for _, subItem := range item.HisAdditionalCharge {
  2047. total = total + (subItem.Price * float64(subItem.Count))
  2048. }
  2049. }
  2050. allTotal := fmt.Sprintf("%.2f", total)
  2051. if res.Infcode == 0 {
  2052. var rf []*ResultFive
  2053. json.Unmarshal([]byte(his.Iinfo), &rf)
  2054. chrg_bchno := chrg_bchno
  2055. cert_no := his.Certno
  2056. var insutypes []string
  2057. var insutype string
  2058. var is390 int = 0
  2059. var is310 int = 0
  2060. for _, item := range rf {
  2061. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  2062. insutypes = append(insutypes, item.Insutype)
  2063. }
  2064. }
  2065. if len(insutypes) == 1 {
  2066. insutype = insutypes[0]
  2067. } else {
  2068. for _, i := range insutypes {
  2069. if i == "390" {
  2070. is390 = 1
  2071. }
  2072. if i == "310" {
  2073. is310 = 1
  2074. }
  2075. }
  2076. }
  2077. if is390 == 1 {
  2078. insutype = "390"
  2079. }
  2080. if is310 == 1 {
  2081. insutype = "310"
  2082. }
  2083. if len(insutypes) == 0 {
  2084. insutype = "310"
  2085. }
  2086. //insutype = "390"
  2087. if his.IdCardType == 1 {
  2088. // cert_no = his.MedicalInsuranceNumber
  2089. cert_no = his.Certno
  2090. } else {
  2091. cert_no = his.Certno
  2092. }
  2093. 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)
  2094. var dat map[string]interface{}
  2095. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2096. fmt.Println(dat)
  2097. } else {
  2098. fmt.Println(err)
  2099. }
  2100. saveLog(result, src_resquest, "2207")
  2101. userJSONBytes, _ := json.Marshal(dat)
  2102. var res ResultSeven
  2103. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2104. utils.ErrorLog("解析失败:%v", err)
  2105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2106. return
  2107. }
  2108. if res.Infcode != 0 {
  2109. errlog := &models.HisOrderError{
  2110. UserOrgId: adminUser.CurrentOrgId,
  2111. Ctime: time.Now().Unix(),
  2112. Mtime: time.Now().Unix(),
  2113. Number: chrg_bchno,
  2114. ErrMsg: res.ErrMsg,
  2115. Status: 1,
  2116. PatientId: id,
  2117. RecordTime: recordDateTime,
  2118. Stage: 6,
  2119. }
  2120. service.CreateErrMsgLog(errlog)
  2121. c.ServeSuccessJSON(map[string]interface{}{
  2122. "failed_code": -10,
  2123. "msg": res.ErrMsg,
  2124. })
  2125. return
  2126. } else {
  2127. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2128. order.OrderStatus = 2
  2129. order.Status = 1
  2130. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2131. order.SetlId = res.Output.Setlinfo.SetlID
  2132. order.PsnNo = res.Output.Setlinfo.PsnNo
  2133. order.PsnName = res.Output.Setlinfo.PsnName
  2134. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2135. order.Certno = res.Output.Setlinfo.Certno
  2136. order.Gend = res.Output.Setlinfo.Gend
  2137. order.Naty = res.Output.Setlinfo.Naty
  2138. order.Age = res.Output.Setlinfo.Age
  2139. order.Insutype = res.Output.Setlinfo.Insutype
  2140. order.PsnType = res.Output.Setlinfo.PsnType
  2141. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2142. order.SetlTime = res.Output.Setlinfo.SetlTime
  2143. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2144. order.MedType = res.Output.Setlinfo.MedType
  2145. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2146. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2147. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2148. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2149. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2150. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2151. order.HifpPay = res.Output.Setlinfo.HifpPay
  2152. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2153. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2154. order.HifesPay = res.Output.Setlinfo.HifesPay
  2155. order.HifobPay = res.Output.Setlinfo.HifobPay
  2156. order.MafPay = res.Output.Setlinfo.MafPay
  2157. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  2158. order.OthPay = res.Output.Setlinfo.OthPay
  2159. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2160. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2161. order.AcctPay = res.Output.Setlinfo.AcctPay
  2162. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2163. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2164. order.Balc = res.Output.Setlinfo.Balc
  2165. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2166. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2167. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2168. order.ClrWay = res.Output.Setlinfo.ClrWay
  2169. order.Creator = order.Creator
  2170. order.Modify = roles.AdminUserId
  2171. order.RequestLog = src_resquest
  2172. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2173. detailStr := string(setlDetail)
  2174. order.SetlDetail = detailStr
  2175. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2176. err = service.UpDateOrder(order)
  2177. if err == nil {
  2178. c.ServeSuccessJSON(map[string]interface{}{
  2179. "msg": "结算成功",
  2180. })
  2181. } else {
  2182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2183. return
  2184. }
  2185. }
  2186. } else {
  2187. adminUser := c.GetAdminUserInfo()
  2188. errlog := &models.HisOrderError{
  2189. UserOrgId: adminUser.CurrentOrgId,
  2190. Ctime: time.Now().Unix(),
  2191. Mtime: time.Now().Unix(),
  2192. ErrMsg: res.ErrMsg,
  2193. Status: 1,
  2194. PatientId: id,
  2195. RecordTime: recordDateTime,
  2196. Stage: 4,
  2197. }
  2198. service.CreateErrMsgLog(errlog)
  2199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2200. return
  2201. }
  2202. } else {
  2203. adminUser := c.GetAdminUserInfo()
  2204. errlog := &models.HisOrderError{
  2205. UserOrgId: adminUser.CurrentOrgId,
  2206. Ctime: time.Now().Unix(),
  2207. Mtime: time.Now().Unix(),
  2208. ErrMsg: res.ErrMsg,
  2209. Status: 1,
  2210. PatientId: id,
  2211. RecordTime: recordDateTime,
  2212. Stage: 4,
  2213. }
  2214. service.CreateErrMsgLog(errlog)
  2215. c.ServeSuccessJSON(map[string]interface{}{
  2216. "failed_code": -10,
  2217. "msg": res.ErrMsg,
  2218. })
  2219. return
  2220. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  2221. //return
  2222. }
  2223. }
  2224. }
  2225. } else if tempOrder.ID > 0 {
  2226. if tempOrder.IsPre == 1 {
  2227. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  2228. var rf []*ResultFive
  2229. json.Unmarshal([]byte(his.Iinfo), &rf)
  2230. chrg_bchno := tempOrder.Number
  2231. cert_no := his.Certno
  2232. var insutypes []string
  2233. var insutype string
  2234. var is390 int = 0
  2235. var is310 int = 0
  2236. for _, item := range rf {
  2237. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  2238. insutypes = append(insutypes, item.Insutype)
  2239. }
  2240. }
  2241. if len(insutypes) == 1 {
  2242. insutype = insutypes[0]
  2243. } else {
  2244. for _, i := range insutypes {
  2245. if i == "390" {
  2246. is390 = 1
  2247. }
  2248. if i == "310" {
  2249. is310 = 1
  2250. }
  2251. }
  2252. }
  2253. if is390 == 1 {
  2254. insutype = "390"
  2255. }
  2256. if is310 == 1 {
  2257. insutype = "310"
  2258. }
  2259. if len(insutypes) == 0 {
  2260. insutype = "310"
  2261. }
  2262. //insutype = "390"
  2263. if his.IdCardType == 1 {
  2264. // cert_no = his.MedicalInsuranceNumber
  2265. cert_no = his.Certno
  2266. } else {
  2267. cert_no = his.Certno
  2268. }
  2269. 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)
  2270. var dat map[string]interface{}
  2271. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2272. fmt.Println(dat)
  2273. } else {
  2274. fmt.Println(err)
  2275. }
  2276. saveLog(result, src_resquest, "2207")
  2277. userJSONBytes, _ := json.Marshal(dat)
  2278. var res ResultSeven
  2279. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2280. utils.ErrorLog("解析失败:%v", err)
  2281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2282. return
  2283. }
  2284. if res.Infcode != 0 {
  2285. errlog := &models.HisOrderError{
  2286. UserOrgId: adminUser.CurrentOrgId,
  2287. Ctime: time.Now().Unix(),
  2288. Mtime: time.Now().Unix(),
  2289. Number: chrg_bchno,
  2290. ErrMsg: res.ErrMsg,
  2291. Status: 1,
  2292. PatientId: id,
  2293. RecordTime: recordDateTime,
  2294. Stage: 6,
  2295. }
  2296. service.CreateErrMsgLog(errlog)
  2297. c.ServeSuccessJSON(map[string]interface{}{
  2298. "failed_code": -10,
  2299. "msg": res.ErrMsg,
  2300. })
  2301. return
  2302. } else {
  2303. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2304. order.OrderStatus = 2
  2305. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2306. order.SetlId = res.Output.Setlinfo.SetlID
  2307. order.PsnNo = res.Output.Setlinfo.PsnNo
  2308. order.PsnName = res.Output.Setlinfo.PsnName
  2309. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2310. order.Certno = res.Output.Setlinfo.Certno
  2311. order.Gend = res.Output.Setlinfo.Gend
  2312. order.Naty = res.Output.Setlinfo.Naty
  2313. order.Age = res.Output.Setlinfo.Age
  2314. order.Insutype = res.Output.Setlinfo.Insutype
  2315. order.PsnType = res.Output.Setlinfo.PsnType
  2316. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2317. order.SetlTime = res.Output.Setlinfo.SetlTime
  2318. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2319. order.MedType = res.Output.Setlinfo.MedType
  2320. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2321. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2322. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2323. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2324. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2325. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2326. order.HifpPay = res.Output.Setlinfo.HifpPay
  2327. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2328. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2329. order.HifesPay = res.Output.Setlinfo.HifesPay
  2330. order.HifobPay = res.Output.Setlinfo.HifobPay
  2331. order.MafPay = res.Output.Setlinfo.MafPay
  2332. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  2333. order.OthPay = res.Output.Setlinfo.OthPay
  2334. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2335. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2336. order.AcctPay = res.Output.Setlinfo.AcctPay
  2337. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2338. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2339. order.Balc = res.Output.Setlinfo.Balc
  2340. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2341. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2342. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2343. order.ClrWay = res.Output.Setlinfo.ClrWay
  2344. order.Creator = order.Creator
  2345. order.Modify = roles.AdminUserId
  2346. order.RequestLog = src_resquest
  2347. order.Diagnosis = diagnosis_id
  2348. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2349. detailStr := string(setlDetail)
  2350. order.SetlDetail = detailStr
  2351. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2352. err = service.UpDateOrder(order)
  2353. if err == nil {
  2354. c.ServeSuccessJSON(map[string]interface{}{
  2355. "msg": "结算成功",
  2356. })
  2357. } else {
  2358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2359. return
  2360. }
  2361. }
  2362. }
  2363. }
  2364. }
  2365. //func (c *HisApiController) GetPreUploadInfo() {
  2366. // id, _ := c.GetInt64("id")
  2367. // record_time := c.GetString("record_time")
  2368. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2369. // admin_user_id, _ := c.GetInt64("admin_user_id")
  2370. //
  2371. // timeLayout := "2006-01-02"
  2372. // loc, _ := time.LoadLocation("Local")
  2373. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2374. // if err != nil {
  2375. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2376. // return
  2377. // }
  2378. // recordDateTime := theTime.Unix()
  2379. // adminUser := c.GetAdminUserInfo()
  2380. //
  2381. // var prescriptions []*models.HisPrescription
  2382. //
  2383. // var start_time int64
  2384. // var end_time int64
  2385. //
  2386. // data := make(map[string]interface{})
  2387. // if settle_accounts_type == 1 { //日结
  2388. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  2389. // data["pre"] = prescriptions
  2390. //
  2391. // } else { //月结
  2392. // start_time_str := c.GetString("start_time")
  2393. // end_time_str := c.GetString("end_time")
  2394. // timeLayout := "2006-01-02"
  2395. // loc, _ := time.LoadLocation("Local")
  2396. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2397. // if err != nil {
  2398. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2399. // return
  2400. // }
  2401. // recordStartTime := theStartTime.Unix()
  2402. // start_time = recordStartTime
  2403. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2404. // if err != nil {
  2405. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2406. // return
  2407. // }
  2408. // recordEndTime := theEndTime.Unix()
  2409. // end_time = recordEndTime
  2410. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  2411. // data["pre"] = prescriptions
  2412. //
  2413. // }
  2414. //
  2415. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2416. //
  2417. // his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2418. // timestamp := time.Now().Unix()
  2419. // tempTime := time.Unix(timestamp, 0)
  2420. // timeFormat := tempTime.Format("20060102150405")
  2421. // chrgBchno := rand.Intn(100000) + 10000
  2422. // chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  2423. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2424. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2425. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  2426. // strconv.FormatInt(his.PatientId, 10)
  2427. // client := &http.Client{}
  2428. // data["psn_no"] = his.PsnNo
  2429. // data["mdtrt_id"] = his.Number
  2430. // data["chrg_bchno"] = chrg_bchno
  2431. // data["org_name"] = miConfig.OrgName
  2432. // data["doctor"] = roles.UserName
  2433. // data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  2434. // data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  2435. // data["fixmedins_code"] = miConfig.Code
  2436. // data["dept_code"] = department.Number
  2437. // data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  2438. // data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  2439. // data["secret_key"] = miConfig.SecretKey
  2440. // var ids []int64
  2441. //
  2442. // for _, item := range prescriptions {
  2443. // ids = append(ids, item.ID)
  2444. // }
  2445. // config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2446. // if config.IsOpen == 1 { //对接了医保,走医保流程
  2447. // bytesData, _ := json.Marshal(data)
  2448. // req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  2449. // resp, _ := client.Do(req)
  2450. // defer resp.Body.Close()
  2451. // body, ioErr := ioutil.ReadAll(resp.Body)
  2452. // if ioErr != nil {
  2453. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2454. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2455. // return
  2456. // }
  2457. // var respJSON map[string]interface{}
  2458. // if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  2459. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2460. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2461. // return
  2462. // }
  2463. //
  2464. // respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2465. // userJSONBytes, _ := json.Marshal(respJSON)
  2466. // var res ResultFour
  2467. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2468. // utils.ErrorLog("解析失败:%v", err)
  2469. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2470. // return
  2471. // }
  2472. //
  2473. // if res.Infcode == 0 {
  2474. // order := &models.HisOrder{
  2475. // UserOrgId: adminUser.CurrentOrgId,
  2476. // HisPatientId: his.ID,
  2477. // PatientId: his.PatientId,
  2478. // SettleAccountsDate: recordDateTime,
  2479. // Ctime: time.Now().Unix(),
  2480. // Mtime: time.Now().Unix(),
  2481. // Status: 1,
  2482. // Number: chrg_bchno,
  2483. // Infcode: res.Infcode,
  2484. // WarnMsg: res.WarnMsg,
  2485. // Cainfo: res.Cainfo,
  2486. // ErrMsg: res.ErrMsg,
  2487. // RespondTime: res.RefmsgTime,
  2488. // InfRefmsgid: res.InfRefmsgid,
  2489. // OrderStatus: 1,
  2490. // IsMedicineInsurance: 1,
  2491. // SettleType: settle_accounts_type,
  2492. // SettleStartTime: start_time,
  2493. // SettleEndTime: end_time,
  2494. // Creator: roles.ID,
  2495. // Modify: roles.ID,
  2496. // PType: 2,
  2497. // }
  2498. // err = service.CreateOrder(order)
  2499. // if err != nil {
  2500. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2501. // return
  2502. // }
  2503. //
  2504. // for _, item := range res.Output.Result {
  2505. // temp := strings.Split(item.FeedetlSn, "-")
  2506. // var advice_id int64 = 0
  2507. // var project_id int64 = 0
  2508. // var types int64 = 0
  2509. //
  2510. // id, _ := strconv.ParseInt(temp[2], 10, 64)
  2511. // types, _ = strconv.ParseInt(temp[1], 10, 64)
  2512. //
  2513. // if temp[1] == "1" {
  2514. // advice_id = id
  2515. // project_id = 0
  2516. // } else if temp[1] == "2" {
  2517. // advice_id = 0
  2518. // project_id = id
  2519. // }
  2520. //
  2521. // info := &models.HisOrderInfo{
  2522. // OrderNumber: order.Number,
  2523. // FeedetlSn: item.FeedetlSn,
  2524. // UploadDate: time.Now().Unix(),
  2525. // AdviceId: advice_id,
  2526. // DetItemFeeSumamt: item.DetItemFeeSumamt,
  2527. // Cnt: item.Cnt,
  2528. // Pric: float64(item.Pric),
  2529. // PatientId: his.PatientId,
  2530. // PricUplmtAmt: item.PricUplmtAmt,
  2531. // SelfpayProp: item.SelfpayProp,
  2532. // FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2533. // OverlmtAmt: item.OverlmtAmt,
  2534. // PreselfpayAmt: item.PreselfpayAmt,
  2535. // BasMednFlag: item.BasMednFlag,
  2536. // MedChrgitmType: item.MedChrgitmType,
  2537. // HiNegoDrugFlag: item.HiNegoDrugFlag,
  2538. // Status: 1,
  2539. // Memo: item.Memo,
  2540. // Mtime: time.Now().Unix(),
  2541. // InscpScpAmt: item.InscpScpAmt,
  2542. // DrtReimFlag: item.DrtReimFlag,
  2543. // Ctime: time.Now().Unix(),
  2544. // ListSpItemFlag: item.ListSpItemFlag,
  2545. // ChldMedcFlag: item.ChldMedcFlag,
  2546. // LmtUsedFlag: item.LmtUsedFlag,
  2547. // ChrgitmLv: item.ChrgitmLv,
  2548. // UserOrgId: adminUser.CurrentOrgId,
  2549. // HisPatientId: his.ID,
  2550. // OrderId: order.ID,
  2551. // ProjectId: project_id,
  2552. // Type: types,
  2553. // }
  2554. // service.CreateOrderInfo(info)
  2555. //
  2556. // }
  2557. // service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2558. // service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  2559. //
  2560. // var total float64
  2561. // for _, item := range prescriptions {
  2562. // if item.Type == 1 { //药品
  2563. // for _, subItem := range item.HisDoctorAdviceInfo {
  2564. // total = total + (subItem.Price * subItem.PrescribingNumber)
  2565. // }
  2566. // }
  2567. // if item.Type == 2 { //项目
  2568. // for _, subItem := range item.HisPrescriptionProject {
  2569. // total = total + (subItem.Price * float64(subItem.Count))
  2570. // }
  2571. // }
  2572. // }
  2573. //
  2574. // for _, item := range prescriptions {
  2575. // for _, subItem := range item.HisAdditionalCharge {
  2576. // total = total + (subItem.Price * float64(subItem.Count))
  2577. // }
  2578. // }
  2579. //
  2580. // allTotal := fmt.Sprintf("%.2f", total)
  2581. // if res.Infcode == 0 {
  2582. // var rf []*ResultFive
  2583. // json.Unmarshal([]byte(his.Iinfo), &rf)
  2584. // psn_no := his.PsnNo
  2585. // mdtrt_id := his.Number
  2586. // chrg_bchno := chrg_bchno
  2587. // cert_no := his.Certno
  2588. // insutype := rf[0].Insutype
  2589. //
  2590. // if his.IdCardType == 1 {
  2591. // cert_no = his.MedicalInsuranceNumber
  2592. //
  2593. // } else {
  2594. //
  2595. // cert_no = his.Certno
  2596. //
  2597. // }
  2598. //
  2599. // api := "http://127.0.0.1:9532/" + "gdyb/seven?cert_no=" + cert_no + "&insutype=" +
  2600. // insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  2601. // "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  2602. // miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10)
  2603. // resp, requestErr := http.Get(api)
  2604. // if requestErr != nil {
  2605. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2606. // return
  2607. // }
  2608. // defer resp.Body.Close()
  2609. // body, ioErr := ioutil.ReadAll(resp.Body)
  2610. // if ioErr != nil {
  2611. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2612. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2613. // return
  2614. // }
  2615. // var respJSON map[string]interface{}
  2616. // if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2617. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2618. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2619. // return
  2620. // }
  2621. // fmt.Println(respJSON)
  2622. // respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2623. // userJSONBytes, _ := json.Marshal(respJSON)
  2624. // var res ResultSeven
  2625. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2626. // utils.ErrorLog("解析失败:%v", err)
  2627. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2628. // return
  2629. // }
  2630. // if res.Infcode != 0 {
  2631. // errlog := &models.HisOrderError{
  2632. // UserOrgId: adminUser.CurrentOrgId,
  2633. // Ctime: time.Now().Unix(),
  2634. // Mtime: time.Now().Unix(),
  2635. // Number: chrg_bchno,
  2636. // ErrMsg: res.ErrMsg,
  2637. // Status: 1,
  2638. // PatientId: id,
  2639. // RecordTime: recordDateTime,
  2640. // Stage: 7,
  2641. // }
  2642. // service.CreateErrMsgLog(errlog)
  2643. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2644. // return
  2645. // } else {
  2646. // order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2647. // order.OrderStatus = 1
  2648. // order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2649. // order.SetlId = res.Output.Setlinfo.SetlID
  2650. // order.PsnNo = res.Output.Setlinfo.PsnNo
  2651. // order.PsnName = res.Output.Setlinfo.PsnName
  2652. // order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2653. // order.Certno = res.Output.Setlinfo.Certno
  2654. // order.Gend = res.Output.Setlinfo.Gend
  2655. // order.Naty = res.Output.Setlinfo.Naty
  2656. // order.Age = res.Output.Setlinfo.Age
  2657. // order.Insutype = res.Output.Setlinfo.Insutype
  2658. // order.PsnType = res.Output.Setlinfo.PsnType
  2659. // order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2660. // order.SetlTime = res.Output.Setlinfo.SetlTime
  2661. // order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2662. // order.MedType = res.Output.Setlinfo.MedType
  2663. // order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2664. // order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2665. // order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2666. // order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2667. // order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2668. // order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2669. // order.HifpPay = res.Output.Setlinfo.HifpPay
  2670. // order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2671. // order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2672. // order.HifesPay = res.Output.Setlinfo.HifesPay
  2673. // order.HifobPay = res.Output.Setlinfo.HifobPay
  2674. // order.MafPay = res.Output.Setlinfo.MafPay
  2675. // order.OthPay = res.Output.Setlinfo.OthPay
  2676. // order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2677. // order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2678. // order.AcctPay = res.Output.Setlinfo.AcctPay
  2679. // order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2680. // order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2681. // order.Balc = res.Output.Setlinfo.Balc
  2682. // order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2683. // order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2684. // order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2685. // order.ClrWay = res.Output.Setlinfo.ClrWay
  2686. // order.Creator = order.Creator
  2687. // order.Modify = roles.ID
  2688. // setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2689. // detailStr := string(setlDetail)
  2690. // order.SetlDetail = detailStr
  2691. // //err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2692. // err = service.UpDateOrder(order)
  2693. // if err == nil {
  2694. // c.ServeSuccessJSON(map[string]interface{}{
  2695. // "msg": "预结算成功",
  2696. // })
  2697. // } else {
  2698. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2699. // return
  2700. // }
  2701. // }
  2702. // } else {
  2703. // adminUser := c.GetAdminUserInfo()
  2704. // errlog := &models.HisOrderError{
  2705. // UserOrgId: adminUser.CurrentOrgId,
  2706. // Ctime: time.Now().Unix(),
  2707. // Mtime: time.Now().Unix(),
  2708. // ErrMsg: res.ErrMsg,
  2709. // Status: 1,
  2710. // PatientId: id,
  2711. // RecordTime: recordDateTime,
  2712. // Stage: 4,
  2713. // }
  2714. // service.CreateErrMsgLog(errlog)
  2715. //
  2716. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2717. // return
  2718. // }
  2719. // } else {
  2720. // adminUser := c.GetAdminUserInfo()
  2721. // errlog := &models.HisOrderError{
  2722. // UserOrgId: adminUser.CurrentOrgId,
  2723. // Ctime: time.Now().Unix(),
  2724. // Mtime: time.Now().Unix(),
  2725. // ErrMsg: res.ErrMsg,
  2726. // Status: 1,
  2727. // PatientId: id,
  2728. // RecordTime: recordDateTime,
  2729. // Stage: 4,
  2730. // }
  2731. // service.CreateErrMsgLog(errlog)
  2732. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  2733. // return
  2734. // }
  2735. //
  2736. // } else {
  2737. // var total float64
  2738. // for _, item := range prescriptions {
  2739. // if item.Type == 1 { //药品
  2740. // for _, subItem := range item.HisDoctorAdviceInfo {
  2741. // total = total + (subItem.Price * subItem.PrescribingNumber)
  2742. // }
  2743. // }
  2744. // if item.Type == 2 { //项目
  2745. // for _, subItem := range item.HisPrescriptionProject {
  2746. // total = total + (subItem.Price * float64(subItem.Count))
  2747. // }
  2748. // }
  2749. //
  2750. // for _, subItem := range item.HisAdditionalCharge {
  2751. // total = total + (subItem.Price * float64(subItem.Count))
  2752. // }
  2753. // }
  2754. //
  2755. // allTotal := fmt.Sprintf("%.2f", total)
  2756. // totals, _ := strconv.ParseFloat(allTotal, 64)
  2757. // order := &models.HisOrder{
  2758. // UserOrgId: adminUser.CurrentOrgId,
  2759. // HisPatientId: his.ID,
  2760. // PatientId: id,
  2761. // SettleAccountsDate: recordDateTime,
  2762. // Ctime: time.Now().Unix(),
  2763. // Mtime: time.Now().Unix(),
  2764. // Status: 1,
  2765. // OrderStatus: 2,
  2766. // Number: chrg_bchno,
  2767. // MedfeeSumamt: totals,
  2768. // }
  2769. // err = service.CreateOrder(order)
  2770. // if err != nil {
  2771. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2772. // return
  2773. // }
  2774. //
  2775. // var customs []*Custom
  2776. // for _, item := range prescriptions {
  2777. //
  2778. // if item.Type == 1 { //药品
  2779. // for _, subItem := range item.HisDoctorAdviceInfo {
  2780. // cus := &Custom{
  2781. // AdviceId: subItem.ID,
  2782. // ProjectId: 0,
  2783. // DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  2784. // Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  2785. // FeedetlSn: subItem.FeedetlSn,
  2786. // Price: fmt.Sprintf("%.2f", subItem.Price),
  2787. // MedListCodg: subItem.MedListCodg,
  2788. // Type: 1,
  2789. // }
  2790. // customs = append(customs, cus)
  2791. // }
  2792. // }
  2793. //
  2794. // if item.Type == 2 { //项目
  2795. // for _, subItem := range item.HisPrescriptionProject {
  2796. //
  2797. // cus := &Custom{
  2798. // AdviceId: 0,
  2799. // ProjectId: subItem.ID,
  2800. // DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  2801. // Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  2802. // FeedetlSn: subItem.FeedetlSn,
  2803. // Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  2804. // MedListCodg: subItem.MedListCodg,
  2805. // Type: 2,
  2806. // }
  2807. //
  2808. // customs = append(customs, cus)
  2809. // }
  2810. // }
  2811. //
  2812. // for _, item := range item.HisAdditionalCharge {
  2813. // cus := &Custom{
  2814. // ItemId: item.ID,
  2815. // AdviceId: 0,
  2816. // ProjectId: 0,
  2817. // DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  2818. // Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  2819. // FeedetlSn: item.FeedetlSn,
  2820. // Price: fmt.Sprintf("%.2f", float64(item.Price)),
  2821. // MedListCodg: item.XtHisAddtionConfig.Code,
  2822. // Type: 3,
  2823. // }
  2824. //
  2825. // customs = append(customs, cus)
  2826. // }
  2827. //
  2828. // }
  2829. //
  2830. // for _, item := range customs {
  2831. // var advice_id int64 = 0
  2832. // var project_id int64 = 0
  2833. // var item_id int64 = 0
  2834. //
  2835. // var types int64 = 0
  2836. //
  2837. // if item.Type == 1 {
  2838. // advice_id = item.AdviceId
  2839. // project_id = 0
  2840. // item_id = 0
  2841. // } else if item.Type == 2 {
  2842. // advice_id = 0
  2843. // item_id = 0
  2844. //
  2845. // project_id = item.ProjectId
  2846. // } else if item.Type == 3 {
  2847. // advice_id = 0
  2848. // item_id = item.ItemId
  2849. // project_id = 0
  2850. // }
  2851. //
  2852. // detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  2853. // cut, _ := strconv.ParseFloat(item.Cut, 32)
  2854. // pric, _ := strconv.ParseFloat(item.Price, 32)
  2855. //
  2856. // info := &models.HisOrderInfo{
  2857. // OrderNumber: order.Number,
  2858. // UploadDate: time.Now().Unix(),
  2859. // AdviceId: advice_id,
  2860. // DetItemFeeSumamt: detItemFeeSumamt,
  2861. // Cnt: cut,
  2862. // Pric: pric,
  2863. // PatientId: id,
  2864. // Status: 1,
  2865. // Mtime: time.Now().Unix(),
  2866. // Ctime: time.Now().Unix(),
  2867. // UserOrgId: adminUser.CurrentOrgId,
  2868. // HisPatientId: his.ID,
  2869. // OrderId: order.ID,
  2870. // ProjectId: project_id,
  2871. // Type: types,
  2872. // ItemId: item_id,
  2873. // }
  2874. // service.CreateOrderInfo(info)
  2875. // }
  2876. // //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2877. // err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2878. // err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  2879. // err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2880. // if err == nil {
  2881. // c.ServeSuccessJSON(map[string]interface{}{
  2882. // "msg": "结算成功",
  2883. // })
  2884. // } else {
  2885. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2886. // return
  2887. // }
  2888. // }
  2889. //}
  2890. //上传明细-预结算-
  2891. func (c *HisApiController) GetPreUploadInfo() {
  2892. id, _ := c.GetInt64("id")
  2893. record_time := c.GetString("record_time")
  2894. his_patient_id, _ := c.GetInt64("his_patient_id")
  2895. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2896. admin_user_id, _ := c.GetInt64("admin_user_id")
  2897. diagnosis_id := c.GetString("diagnosis")
  2898. sick_type, _ := c.GetInt64("sick_type")
  2899. reg_type, _ := c.GetInt64("p_type")
  2900. id_str := c.GetString("ids")
  2901. ids_arr := strings.Split(id_str, ",")
  2902. timeLayout := "2006-01-02"
  2903. loc, _ := time.LoadLocation("Local")
  2904. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2905. if err != nil {
  2906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2907. return
  2908. }
  2909. recordDateTime := theTime.Unix()
  2910. adminUser := c.GetAdminUserInfo()
  2911. diagnosis_ids := strings.Split(diagnosis_id, ",")
  2912. var config []*models.HisXtDiagnoseConfig
  2913. for _, item := range diagnosis_ids {
  2914. id, _ := strconv.ParseInt(item, 10, 64)
  2915. diagnosisConfig, _ := service.FindDiagnoseById(id)
  2916. config = append(config, diagnosisConfig)
  2917. }
  2918. //diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  2919. sickConfig, _ := service.FindSickById(sick_type)
  2920. var prescriptions []*models.HisPrescription
  2921. var start_time int64
  2922. var end_time int64
  2923. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2924. fmt.Println(his_patient_id)
  2925. his, _ := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2926. timestamp := time.Now().Unix()
  2927. tempTime := time.Unix(timestamp, 0)
  2928. timeFormat := tempTime.Format("20060102150405")
  2929. chrgBchno := rand.Intn(100000) + 10000
  2930. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  2931. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2932. var patientPrescription models.HisPrescriptionInfo
  2933. patientPrescription, _ = service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2934. if patientPrescription.ID == 0 {
  2935. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2936. }
  2937. //miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2938. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  2939. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  2940. strconv.FormatInt(his.PatientId, 10)
  2941. var result string
  2942. var requestLog string
  2943. if miConfig.InsuplcAdmdvs == "440781" { //
  2944. 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)
  2945. } else {
  2946. 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)
  2947. }
  2948. saveLog(result, requestLog, "2203")
  2949. var respJSON2 map[string]interface{}
  2950. if err := json.Unmarshal([]byte(string(result)), &respJSON2); err != nil {
  2951. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2953. return
  2954. }
  2955. userJSONBytes2, _ := json.Marshal(respJSON2)
  2956. var res2 ResultSix
  2957. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  2958. utils.ErrorLog("解析失败:%v", err)
  2959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2960. return
  2961. }
  2962. if res2.Infcode != 0 {
  2963. adminUser := c.GetAdminUserInfo()
  2964. errlog := &models.HisOrderError{
  2965. UserOrgId: adminUser.CurrentOrgId,
  2966. Ctime: time.Now().Unix(),
  2967. Mtime: time.Now().Unix(),
  2968. ErrMsg: res2.ErrMsg,
  2969. Status: 1,
  2970. PatientId: id,
  2971. RecordTime: recordDateTime,
  2972. Stage: 3,
  2973. }
  2974. service.CreateErrMsgLog(errlog)
  2975. c.ServeSuccessJSON(map[string]interface{}{
  2976. "failed_code": -10,
  2977. "msg": res2.ErrMsg,
  2978. })
  2979. return
  2980. } else {
  2981. his.Diagnosis = diagnosis_id
  2982. his.SickType = sickConfig.ID
  2983. his.PType = fmt.Sprintf("%d", reg_type)
  2984. service.UpdateHisPatientThree(&his)
  2985. data := make(map[string]interface{})
  2986. if settle_accounts_type == 1 { //日结
  2987. if reg_type == 11 {
  2988. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  2989. } else {
  2990. prescriptions, _ = service.GetNewHisPrescription(adminUser.CurrentOrgId, his_patient_id, recordDateTime, strconv.Itoa(int(reg_type)))
  2991. }
  2992. data["pre"] = prescriptions
  2993. } else { //月结
  2994. start_time_str := c.GetString("start_time")
  2995. end_time_str := c.GetString("end_time")
  2996. timeLayout := "2006-01-02"
  2997. loc, _ := time.LoadLocation("Local")
  2998. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2999. if err != nil {
  3000. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3001. return
  3002. }
  3003. recordStartTime := theStartTime.Unix()
  3004. start_time = recordStartTime
  3005. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3006. if err != nil {
  3007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3008. return
  3009. }
  3010. recordEndTime := theEndTime.Unix()
  3011. end_time = recordEndTime
  3012. prescriptions, _ = service.GetMonthHisPrescriptionTwo(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  3013. data["pre"] = prescriptions
  3014. }
  3015. if reg_type == 1111 || reg_type == 1112 {
  3016. reg_type = 11
  3017. }
  3018. client := &http.Client{}
  3019. data["psn_no"] = his.PsnNo
  3020. data["mdtrt_id"] = his.Number
  3021. data["chrg_bchno"] = chrg_bchno
  3022. data["org_name"] = miConfig.OrgName
  3023. data["doctor"] = roles.UserName
  3024. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  3025. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  3026. data["fixmedins_code"] = miConfig.Code
  3027. data["balance_accounts_type"] = strconv.FormatInt(his.BalanceAccountsType, 10)
  3028. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  3029. data["dept_code"] = "15"
  3030. } else {
  3031. data["dept_code"] = department.Number
  3032. }
  3033. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  3034. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  3035. data["secret_key"] = miConfig.SecretKey
  3036. var ids []int64
  3037. for _, item := range prescriptions {
  3038. ids = append(ids, item.ID)
  3039. }
  3040. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3041. if config.IsOpen == 1 { //对接了医保,走医保流程
  3042. result, request_log := service.Gdyb2204(his.PsnNo, his.Number, prescriptions, chrg_bchno, miConfig.OrgName, roles.UserName, data["dept"].(string), data["fixmedins_code"].(string), data["dept_code"].(string), data["doctor_id"].(string), miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, data["balance_accounts_type"].(string))
  3043. var dat map[string]interface{}
  3044. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3045. fmt.Println(dat)
  3046. } else {
  3047. fmt.Println(err)
  3048. }
  3049. saveLog(result, request_log, "2204")
  3050. userJSONBytes, _ := json.Marshal(dat)
  3051. var res ResultFour
  3052. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3053. utils.ErrorLog("解析失败:%v", err)
  3054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3055. return
  3056. }
  3057. if res.Infcode == 0 {
  3058. order := &models.HisOrder{
  3059. UserOrgId: adminUser.CurrentOrgId,
  3060. HisPatientId: his.ID,
  3061. PatientId: his.PatientId,
  3062. SettleAccountsDate: recordDateTime,
  3063. Ctime: time.Now().Unix(),
  3064. Mtime: time.Now().Unix(),
  3065. Status: 0,
  3066. Number: chrg_bchno,
  3067. Infcode: res.Infcode,
  3068. WarnMsg: res.WarnMsg,
  3069. Cainfo: res.Cainfo,
  3070. ErrMsg: res.ErrMsg,
  3071. RespondTime: res.RefmsgTime,
  3072. InfRefmsgid: res.InfRefmsgid,
  3073. OrderStatus: 1,
  3074. IsMedicineInsurance: 1,
  3075. SettleType: settle_accounts_type,
  3076. SettleStartTime: start_time,
  3077. SettleEndTime: end_time,
  3078. Creator: roles.AdminUserId,
  3079. Modify: roles.AdminUserId,
  3080. PType: 2,
  3081. Diagnosis: diagnosis_id,
  3082. }
  3083. err = service.CreateOrder(order)
  3084. if err != nil {
  3085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  3086. return
  3087. }
  3088. for _, item := range res.Output.Result {
  3089. temp := strings.Split(item.FeedetlSn, "-")
  3090. var advice_id int64 = 0
  3091. var project_id int64 = 0
  3092. var types int64 = 0
  3093. id, _ := strconv.ParseInt(temp[2], 10, 64)
  3094. types, _ = strconv.ParseInt(temp[1], 10, 64)
  3095. if temp[1] == "1" {
  3096. advice_id = id
  3097. project_id = 0
  3098. } else if temp[1] == "2" {
  3099. advice_id = 0
  3100. project_id = id
  3101. }
  3102. info := &models.HisOrderInfo{
  3103. OrderNumber: order.Number,
  3104. FeedetlSn: item.FeedetlSn,
  3105. UploadDate: time.Now().Unix(),
  3106. AdviceId: advice_id,
  3107. DetItemFeeSumamt: item.DetItemFeeSumamt,
  3108. Cnt: item.Cnt,
  3109. Pric: float64(item.Pric),
  3110. PatientId: his.PatientId,
  3111. PricUplmtAmt: item.PricUplmtAmt,
  3112. SelfpayProp: item.SelfpayProp,
  3113. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  3114. OverlmtAmt: item.OverlmtAmt,
  3115. PreselfpayAmt: item.PreselfpayAmt,
  3116. BasMednFlag: item.BasMednFlag,
  3117. MedChrgitmType: item.MedChrgitmType,
  3118. HiNegoDrugFlag: item.HiNegoDrugFlag,
  3119. Status: 1,
  3120. Memo: item.Memo,
  3121. Mtime: time.Now().Unix(),
  3122. InscpScpAmt: item.InscpScpAmt,
  3123. DrtReimFlag: item.DrtReimFlag,
  3124. Ctime: time.Now().Unix(),
  3125. ListSpItemFlag: item.ListSpItemFlag,
  3126. ChldMedcFlag: item.ChldMedcFlag,
  3127. LmtUsedFlag: item.LmtUsedFlag,
  3128. ChrgitmLv: item.ChrgitmLv,
  3129. UserOrgId: adminUser.CurrentOrgId,
  3130. HisPatientId: his.ID,
  3131. OrderId: order.ID,
  3132. ProjectId: project_id,
  3133. Type: types,
  3134. }
  3135. service.CreateOrderInfo(info)
  3136. }
  3137. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  3138. service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, his_patient_id, chrg_bchno, recordDateTime)
  3139. var total float64
  3140. for _, item := range prescriptions {
  3141. if item.Type == 1 { //药品
  3142. for _, subItem := range item.HisDoctorAdviceInfo {
  3143. total = total + (subItem.Price * subItem.PrescribingNumber)
  3144. }
  3145. }
  3146. if item.Type == 2 { //项目
  3147. for _, subItem := range item.HisPrescriptionProject {
  3148. total = total + (subItem.Price * float64(subItem.Count))
  3149. }
  3150. }
  3151. }
  3152. for _, item := range prescriptions {
  3153. for _, subItem := range item.HisAdditionalCharge {
  3154. total = total + (subItem.Price * float64(subItem.Count))
  3155. }
  3156. }
  3157. allTotal := fmt.Sprintf("%.2f", total)
  3158. if res.Infcode == 0 {
  3159. var rf []*ResultFive
  3160. json.Unmarshal([]byte(his.Iinfo), &rf)
  3161. chrg_bchno := chrg_bchno
  3162. cert_no := his.Certno
  3163. var insutypes []string
  3164. var insutype string
  3165. var is390 int = 0
  3166. var is310 int = 0
  3167. for _, item := range rf {
  3168. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  3169. insutypes = append(insutypes, item.Insutype)
  3170. }
  3171. }
  3172. if len(insutypes) == 1 {
  3173. insutype = insutypes[0]
  3174. } else {
  3175. for _, i := range insutypes {
  3176. if i == "390" {
  3177. is390 = 1
  3178. }
  3179. if i == "310" {
  3180. is310 = 1
  3181. }
  3182. }
  3183. }
  3184. if is390 == 1 {
  3185. insutype = "390"
  3186. }
  3187. if is310 == 1 {
  3188. insutype = "310"
  3189. }
  3190. if len(insutypes) == 0 {
  3191. insutype = "310"
  3192. }
  3193. //insutype = "390"
  3194. if his.IdCardType == 1 {
  3195. cert_no = his.MedicalInsuranceNumber
  3196. } else {
  3197. cert_no = his.Certno
  3198. }
  3199. 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)
  3200. var dat map[string]interface{}
  3201. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3202. fmt.Println(dat)
  3203. } else {
  3204. fmt.Println(err)
  3205. }
  3206. saveLog(result, request_log, "2206")
  3207. userJSONBytes, _ := json.Marshal(dat)
  3208. var res ResultSeven
  3209. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3210. utils.ErrorLog("解析失败:%v", err)
  3211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3212. return
  3213. }
  3214. if res.Infcode != 0 {
  3215. errlog := &models.HisOrderError{
  3216. UserOrgId: adminUser.CurrentOrgId,
  3217. Ctime: time.Now().Unix(),
  3218. Mtime: time.Now().Unix(),
  3219. Number: chrg_bchno,
  3220. ErrMsg: res.ErrMsg,
  3221. Status: 1,
  3222. PatientId: id,
  3223. RecordTime: recordDateTime,
  3224. Stage: 20,
  3225. }
  3226. service.CreateErrMsgLog(errlog)
  3227. c.ServeSuccessJSON(map[string]interface{}{
  3228. "failed_code": -10,
  3229. "msg": res.ErrMsg,
  3230. })
  3231. return
  3232. } else {
  3233. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  3234. order.OrderStatus = 1
  3235. order.IsPre = 1
  3236. order.Status = 1
  3237. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  3238. order.SetlId = res.Output.Setlinfo.SetlID
  3239. order.PsnNo = res.Output.Setlinfo.PsnNo
  3240. order.PsnName = res.Output.Setlinfo.PsnName
  3241. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  3242. order.Certno = res.Output.Setlinfo.Certno
  3243. order.Gend = res.Output.Setlinfo.Gend
  3244. order.Naty = res.Output.Setlinfo.Naty
  3245. order.Age = res.Output.Setlinfo.Age
  3246. order.Insutype = res.Output.Setlinfo.Insutype
  3247. order.PsnType = res.Output.Setlinfo.PsnType
  3248. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  3249. order.SetlTime = res.Output.Setlinfo.SetlTime
  3250. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  3251. order.MedType = res.Output.Setlinfo.MedType
  3252. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  3253. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  3254. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  3255. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  3256. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  3257. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  3258. order.HifpPay = res.Output.Setlinfo.HifpPay
  3259. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  3260. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  3261. order.HifesPay = res.Output.Setlinfo.HifesPay
  3262. order.HifobPay = res.Output.Setlinfo.HifobPay
  3263. order.MafPay = res.Output.Setlinfo.MafPay
  3264. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  3265. order.OthPay = res.Output.Setlinfo.OthPay
  3266. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  3267. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  3268. order.AcctPay = res.Output.Setlinfo.AcctPay
  3269. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  3270. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  3271. order.Balc = res.Output.Setlinfo.Balc
  3272. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  3273. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  3274. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  3275. order.ClrWay = res.Output.Setlinfo.ClrWay
  3276. order.Creator = order.Creator
  3277. order.Modify = roles.AdminUserId
  3278. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  3279. detailStr := string(setlDetail)
  3280. order.SetlDetail = detailStr
  3281. //err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  3282. err = service.UpDateOrder(order)
  3283. if err == nil {
  3284. c.ServeSuccessJSON(map[string]interface{}{
  3285. "msg": "预结算成功",
  3286. })
  3287. } else {
  3288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  3289. return
  3290. }
  3291. }
  3292. } else {
  3293. adminUser := c.GetAdminUserInfo()
  3294. errlog := &models.HisOrderError{
  3295. UserOrgId: adminUser.CurrentOrgId,
  3296. Ctime: time.Now().Unix(),
  3297. Mtime: time.Now().Unix(),
  3298. ErrMsg: res.ErrMsg,
  3299. Status: 1,
  3300. PatientId: id,
  3301. RecordTime: recordDateTime,
  3302. Stage: 4,
  3303. }
  3304. service.CreateErrMsgLog(errlog)
  3305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  3306. return
  3307. }
  3308. } else {
  3309. adminUser := c.GetAdminUserInfo()
  3310. errlog := &models.HisOrderError{
  3311. UserOrgId: adminUser.CurrentOrgId,
  3312. Ctime: time.Now().Unix(),
  3313. Mtime: time.Now().Unix(),
  3314. ErrMsg: res.ErrMsg,
  3315. Status: 1,
  3316. PatientId: id,
  3317. RecordTime: recordDateTime,
  3318. Stage: 4,
  3319. }
  3320. service.CreateErrMsgLog(errlog)
  3321. c.ServeSuccessJSON(map[string]interface{}{
  3322. "failed_code": -10,
  3323. "msg": res.ErrMsg,
  3324. })
  3325. return
  3326. }
  3327. }
  3328. }
  3329. }
  3330. //func (c *HisApiController) GetSettleInfo() {
  3331. // id, _ := c.GetInt64("id")
  3332. // order_id, _ := c.GetInt64("order_id")
  3333. //
  3334. // record_time := c.GetString("record_time")
  3335. // pay_way, _ := c.GetInt64("pay_way")
  3336. // pay_price, _ := c.GetFloat("pay_price")
  3337. // pay_card_no := c.GetString("pay_card_no")
  3338. // discount_price, _ := c.GetFloat("discount_price")
  3339. // preferential_price, _ := c.GetFloat("preferential_price")
  3340. // reality_price, _ := c.GetFloat("reality_price")
  3341. // found_price, _ := c.GetFloat("found_price")
  3342. // medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  3343. // private_price, _ := c.GetFloat("private_price")
  3344. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  3345. // admin_user_id, _ := c.GetInt64("admin_user_id")
  3346. //
  3347. // timeLayout := "2006-01-02"
  3348. // loc, _ := time.LoadLocation("Local")
  3349. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3350. // if err != nil {
  3351. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3352. // return
  3353. // }
  3354. // recordDateTime := theTime.Unix()
  3355. // adminUser := c.GetAdminUserInfo()
  3356. //
  3357. // var prescriptions []*models.HisPrescription
  3358. //
  3359. // data := make(map[string]interface{})
  3360. // if settle_accounts_type == 1 { //日结
  3361. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  3362. // data["pre"] = prescriptions
  3363. //
  3364. // } else { //月结
  3365. // start_time_str := c.GetString("start_time")
  3366. // end_time_str := c.GetString("end_time")
  3367. // timeLayout := "2006-01-02"
  3368. // loc, _ := time.LoadLocation("Local")
  3369. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3370. // if err != nil {
  3371. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3372. // return
  3373. // }
  3374. // recordStartTime := theStartTime.Unix()
  3375. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3376. // if err != nil {
  3377. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3378. // return
  3379. // }
  3380. // recordEndTime := theEndTime.Unix()
  3381. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  3382. // data["pre"] = prescriptions
  3383. //
  3384. // }
  3385. //
  3386. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3387. //
  3388. // his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  3389. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3390. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  3391. // strconv.FormatInt(his.PatientId, 10)
  3392. //
  3393. // order_src, _ := service.GetHisOrderByID(order_id)
  3394. //
  3395. // config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3396. // if config.IsOpen == 1 { //对接了医保,走医保流程
  3397. //
  3398. // var total float64
  3399. // for _, item := range prescriptions {
  3400. // if item.Type == 1 { //药品
  3401. // for _, subItem := range item.HisDoctorAdviceInfo {
  3402. // total = total + (subItem.Price * subItem.PrescribingNumber)
  3403. // }
  3404. // }
  3405. // if item.Type == 2 { //项目
  3406. // for _, subItem := range item.HisPrescriptionProject {
  3407. // total = total + (subItem.Price * float64(subItem.Count))
  3408. // }
  3409. // }
  3410. // }
  3411. //
  3412. // for _, item := range prescriptions {
  3413. // for _, subItem := range item.HisAdditionalCharge {
  3414. // total = total + (subItem.Price * float64(subItem.Count))
  3415. // }
  3416. // }
  3417. //
  3418. // allTotal := fmt.Sprintf("%.2f", total)
  3419. // var rf []*ResultFive
  3420. // json.Unmarshal([]byte(his.Iinfo), &rf)
  3421. // psn_no := order_src.PsnNo
  3422. // mdtrt_id := order_src.MdtrtId
  3423. // chrg_bchno := order_src.Number
  3424. // cert_no := order_src.Certno
  3425. // insutype := rf[0].Insutype
  3426. //
  3427. // if his.IdCardType == 1 {
  3428. // cert_no = his.MedicalInsuranceNumber
  3429. // } else {
  3430. // cert_no = his.Certno
  3431. // }
  3432. //
  3433. // 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)
  3434. // var dat map[string]interface{}
  3435. // if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3436. // fmt.Println(dat)
  3437. // } else {
  3438. // fmt.Println(err)
  3439. // }
  3440. //
  3441. // userJSONBytes, _ := json.Marshal(dat)
  3442. //
  3443. //
  3444. //
  3445. // var res ResultSeven
  3446. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3447. // utils.ErrorLog("解析失败:%v", err)
  3448. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3449. // return
  3450. // }
  3451. // if res.Infcode == -1 {
  3452. // errlog := &models.HisOrderError{
  3453. // UserOrgId: adminUser.CurrentOrgId,
  3454. // Ctime: time.Now().Unix(),
  3455. // Mtime: time.Now().Unix(),
  3456. // Number: chrg_bchno,
  3457. // ErrMsg: res.ErrMsg,
  3458. // Status: 1,
  3459. // PatientId: id,
  3460. // RecordTime: recordDateTime,
  3461. // Stage: 6,
  3462. // }
  3463. // service.CreateErrMsgLog(errlog)
  3464. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  3465. // return
  3466. // } else {
  3467. // order_src.OrderStatus = 2
  3468. // order_src.PayWay = pay_way
  3469. // order_src.PayPrice = pay_price
  3470. // order_src.PayCardNo = pay_card_no
  3471. // order_src.DiscountPrice = discount_price
  3472. // order_src.PreferentialPrice = preferential_price
  3473. // order_src.RealityPrice = reality_price
  3474. // order_src.FoundPrice = found_price
  3475. // order_src.MedicalInsurancePrice = medical_insurance_price
  3476. // order_src.PrivatePrice = private_price
  3477. // order_src.MdtrtId = res.Output.Setlinfo.MdtrtID
  3478. // order_src.SetlId = res.Output.Setlinfo.SetlID
  3479. // order_src.PsnNo = res.Output.Setlinfo.PsnNo
  3480. // order_src.PsnName = res.Output.Setlinfo.PsnName
  3481. // order_src.PsnCertType = res.Output.Setlinfo.PsnCertType
  3482. // order_src.Certno = res.Output.Setlinfo.Certno
  3483. // order_src.Gend = res.Output.Setlinfo.Gend
  3484. // order_src.Naty = res.Output.Setlinfo.Naty
  3485. // order_src.Age = res.Output.Setlinfo.Age
  3486. // order_src.Insutype = res.Output.Setlinfo.Insutype
  3487. // order_src.PsnType = res.Output.Setlinfo.PsnType
  3488. // order_src.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  3489. // order_src.SetlTime = res.Output.Setlinfo.SetlTime
  3490. // order_src.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  3491. // order_src.MedType = res.Output.Setlinfo.MedType
  3492. // order_src.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  3493. // order_src.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  3494. // order_src.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  3495. // order_src.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  3496. // order_src.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  3497. // order_src.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  3498. // order_src.HifpPay = res.Output.Setlinfo.HifpPay
  3499. // order_src.CvlservPay = res.Output.Setlinfo.CvlservPay
  3500. // order_src.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  3501. // order_src.HifesPay = res.Output.Setlinfo.HifesPay
  3502. // order_src.HifobPay = res.Output.Setlinfo.HifobPay
  3503. // order_src.MafPay = res.Output.Setlinfo.MafPay
  3504. // order_src.OthPay = res.Output.Setlinfo.OthPay
  3505. // order_src.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  3506. // order_src.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  3507. // order_src.AcctPay = res.Output.Setlinfo.AcctPay
  3508. // order_src.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  3509. // order_src.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  3510. // order_src.Balc = res.Output.Setlinfo.Balc
  3511. // order_src.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  3512. // order_src.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  3513. // order_src.ClrOptins = res.Output.Setlinfo.ClrOptins
  3514. // order_src.ClrWay = res.Output.Setlinfo.ClrWay
  3515. // order_src.Creator = order_src.Creator
  3516. // order_src.Modify = roles.ID
  3517. // order_src.RequestLog = src_resquest
  3518. // setlDetail, _ := json.Marshal(res.Output.Setldetail)
  3519. // detailStr := string(setlDetail)
  3520. // order_src.SetlDetail = detailStr
  3521. // err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  3522. // err = service.UpDateOrder(order_src)
  3523. //
  3524. // if err == nil {
  3525. // c.ServeSuccessJSON(map[string]interface{}{
  3526. // "msg": "结算成功",
  3527. // })
  3528. // } else {
  3529. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  3530. // return
  3531. // }
  3532. // }
  3533. // }
  3534. //}
  3535. //退款
  3536. func (c *HisApiController) Refund() {
  3537. order_id, _ := c.GetInt64("order_id")
  3538. admin_user_id, _ := c.GetInt64("admin_user_id")
  3539. //record_time := c.GetString("record_time")
  3540. //patient_id, _ := c.GetInt64("patient_id")
  3541. //timeLayout := "2006-01-02"
  3542. //loc, _ := time.LoadLocation("Local")
  3543. adminUser := c.GetAdminUserInfo()
  3544. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3545. //if err != nil {
  3546. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3547. // return
  3548. //}
  3549. //recordDateTime := theTime.Unix()
  3550. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3551. var order models.HisOrder
  3552. order, _ = service.GetHisOrderByID(order_id)
  3553. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3554. if order.ID == 0 {
  3555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3556. return
  3557. //order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  3558. }
  3559. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3560. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3561. if config.IsOpen == 1 { //对接了医保,走医保流程
  3562. result, src_resquest := service.Gdyb2208(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  3563. var dat map[string]interface{}
  3564. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3565. fmt.Println(dat)
  3566. } else {
  3567. fmt.Println(err)
  3568. }
  3569. saveLog(result, src_resquest, "2208")
  3570. userJSONBytes, _ := json.Marshal(dat)
  3571. var res ResultSixteen
  3572. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3573. utils.ErrorLog("解析失败:%v", err)
  3574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3575. return
  3576. }
  3577. if res.Infcode == 0 {
  3578. result, src_request := service.Gdyb2205(order.PsnNo, order.MdtrtId, order.Number, miConfig.OrgName, roles.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  3579. var dat map[string]interface{}
  3580. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3581. fmt.Println(dat)
  3582. } else {
  3583. fmt.Println(err)
  3584. }
  3585. saveLog(result, src_request, "2205")
  3586. userJSONBytes, _ := json.Marshal(dat)
  3587. var res2 ResultSix
  3588. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  3589. utils.ErrorLog("解析失败:%v", err)
  3590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3591. return
  3592. }
  3593. if res2.Infcode == 0 {
  3594. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, src_resquest, result)
  3595. if err == nil {
  3596. c.ServeSuccessJSON(map[string]interface{}{
  3597. "msg": "退费成功",
  3598. })
  3599. } else {
  3600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3601. return
  3602. }
  3603. } else {
  3604. c.ServeSuccessJSON(map[string]interface{}{
  3605. "code": -10,
  3606. "msg": res2.ErrMsg,
  3607. })
  3608. }
  3609. } else {
  3610. c.ServeSuccessJSON(map[string]interface{}{
  3611. "code": -10,
  3612. "msg": res.ErrMsg,
  3613. })
  3614. }
  3615. }
  3616. }
  3617. func (c *HisApiController) RefundNumber() {
  3618. record_time := c.GetString("record_time")
  3619. //patient_id, _ := c.GetInt64("patient_id")
  3620. admin_user_id, _ := c.GetInt64("admin_user_id")
  3621. his_patient_id, _ := c.GetInt64("id")
  3622. timeLayout := "2006-01-02"
  3623. loc, _ := time.LoadLocation("Local")
  3624. adminUser := c.GetAdminUserInfo()
  3625. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3626. fmt.Println(err)
  3627. if err != nil {
  3628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3629. return
  3630. }
  3631. recordDateTime := theTime.Unix()
  3632. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3633. his, _ := service.GetHisPatientRecord(adminUser.CurrentOrgId, his_patient_id)
  3634. //patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3635. //order, _ := service.GetHisOrderByID(order_id)
  3636. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3637. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3638. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3639. count, _ := service.GetOrderCountByNumber(adminUser.CurrentOrgId, his.PatientId, recordDateTime, his.Number)
  3640. if count > 0 {
  3641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  3642. return
  3643. }
  3644. if config.IsOpen == 1 { //对接了医保,走医保流程
  3645. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  3646. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + roles.UserName + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  3647. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3648. resp3, requestErr3 := http.Get(api3)
  3649. if requestErr3 != nil {
  3650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3651. return
  3652. }
  3653. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  3654. if ioErr3 != nil {
  3655. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  3656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3657. return
  3658. }
  3659. var respJSON3 map[string]interface{}
  3660. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  3661. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3663. return
  3664. }
  3665. respJSON3 = respJSON3["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3666. userJSONBytes3, _ := json.Marshal(respJSON3)
  3667. var res2 ResultSix
  3668. if err := json.Unmarshal(userJSONBytes3, &res2); err != nil {
  3669. utils.ErrorLog("解析失败:%v", err)
  3670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3671. return
  3672. }
  3673. if res2.Infcode == 0 {
  3674. if err == nil {
  3675. c.ServeSuccessJSON(map[string]interface{}{
  3676. "msg": "退号成功",
  3677. })
  3678. service.UpdataRegStatusTwo(his_patient_id, recordDateTime, adminUser.CurrentOrgId)
  3679. } else {
  3680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3681. return
  3682. }
  3683. } else {
  3684. c.ServeSuccessJSON(map[string]interface{}{
  3685. "code": -10,
  3686. "msg": res2.ErrMsg,
  3687. })
  3688. }
  3689. } else {
  3690. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  3691. //if err == nil {
  3692. // c.ServeSuccessJSON(map[string]interface{}{
  3693. // "msg": "退费成功",
  3694. // })
  3695. //} else {
  3696. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3697. // return
  3698. //}
  3699. }
  3700. }
  3701. func (c *HisApiController) RefundDetail() {
  3702. order_id, _ := c.GetInt64("order_id")
  3703. his_patient_id, _ := c.GetInt64("his_patient_id")
  3704. number := c.GetString("number")
  3705. record_time := c.GetString("record_time")
  3706. patient_id, _ := c.GetInt64("patient_id")
  3707. timeLayout := "2006-01-02"
  3708. loc, _ := time.LoadLocation("Local")
  3709. adminUser := c.GetAdminUserInfo()
  3710. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3711. fmt.Println(err)
  3712. if err != nil {
  3713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3714. return
  3715. }
  3716. recordDateTime := theTime.Unix()
  3717. his, _ := service.GetNewVMHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  3718. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3719. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3720. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3721. var order models.HisOrder
  3722. order, _ = service.GetHisOrderByID(order_id)
  3723. if order.ID == 0 {
  3724. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  3725. }
  3726. if config.IsOpen == 1 { //对接了医保,走医保流程
  3727. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  3728. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  3729. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3730. resp2, requestErr2 := http.Get(api2)
  3731. if requestErr2 != nil {
  3732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3733. return
  3734. }
  3735. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  3736. if ioErr2 != nil {
  3737. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  3738. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3739. return
  3740. }
  3741. var respJSON2 map[string]interface{}
  3742. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  3743. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3745. return
  3746. }
  3747. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId, "", "")
  3748. if err == nil {
  3749. c.ServeSuccessJSON(map[string]interface{}{
  3750. "msg": "退费成功",
  3751. })
  3752. } else {
  3753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3754. return
  3755. }
  3756. } else {
  3757. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId, "", "")
  3758. if err == nil {
  3759. c.ServeSuccessJSON(map[string]interface{}{
  3760. "msg": "退费成功",
  3761. })
  3762. } else {
  3763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3764. return
  3765. }
  3766. }
  3767. }
  3768. //对账
  3769. func (c *HisApiController) GetCheckAccount() {
  3770. start_time := c.GetString("start_time")
  3771. end_time := c.GetString("end_time")
  3772. insutype := c.GetString("insutype")
  3773. clr_type := c.GetString("clr_type")
  3774. admin_user_id, _ := c.GetInt64("admin_user_id")
  3775. adminUser := c.GetAdminUserInfo()
  3776. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3777. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3778. timeLayout := "2006-01-02"
  3779. loc, _ := time.LoadLocation("Local")
  3780. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3781. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3782. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  3783. //orders_two, _ := service.GetOrderByTimeThree(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  3784. fixmedins_setl_cnt := int64(len(orders))
  3785. //
  3786. ////撤销的算2条数据为一笔
  3787. //for _, item := range orders_two {
  3788. // if item.OrderStatus == 3 {
  3789. // fixmedins_setl_cnt = fixmedins_setl_cnt + 1
  3790. // }
  3791. //}
  3792. var medfee_sumamt float64
  3793. var acct_pay float64
  3794. var fund_pay_sumamt float64
  3795. for _, item := range orders {
  3796. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  3797. acct_pay = acct_pay + item.AcctPay
  3798. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  3799. }
  3800. var user_name string
  3801. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3802. if role.ID == 0 {
  3803. user_name = "xxx"
  3804. } else {
  3805. user_name = role.UserName
  3806. }
  3807. if config.IsOpen == 1 {
  3808. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  3809. "insutype=" + insutype +
  3810. "&clr_type=" + clr_type +
  3811. "&setl_optins=" + "定点医保中心" +
  3812. "&stmt_begndate=" + start_time +
  3813. "&stm_enddate=" + end_time +
  3814. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  3815. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  3816. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  3817. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  3818. "&fixmedins_code=" + miConfig.Code +
  3819. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3820. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3821. "&secret_key=" + miConfig.SecretKey +
  3822. "&org_name=" + miConfig.OrgName +
  3823. "&doctor=" + user_name
  3824. fmt.Println(api)
  3825. resp, requestErr := http.Get(api)
  3826. if requestErr != nil {
  3827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3828. return
  3829. }
  3830. body, ioErr := ioutil.ReadAll(resp.Body)
  3831. fmt.Println(body)
  3832. if ioErr != nil {
  3833. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3835. return
  3836. }
  3837. var respJSON map[string]interface{}
  3838. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3839. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3840. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3841. return
  3842. }
  3843. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3844. userJSONBytes, _ := json.Marshal(respJSON)
  3845. var res ResultEight
  3846. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3847. utils.ErrorLog("解析失败:%v", err)
  3848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3849. return
  3850. }
  3851. if res.Infcode == 0 {
  3852. if res.Output.Stmtinfo.StmtRslt == "0" {
  3853. micc := &models.MedicalInsuranceCostCompare{
  3854. StartTime: startime.Unix(),
  3855. EndTime: endtime.Unix(),
  3856. Insutype: insutype,
  3857. CheckType: 1,
  3858. Num: fixmedins_setl_cnt,
  3859. Mtime: time.Now().Unix(),
  3860. Status: 1,
  3861. UserOrgId: adminUser.CurrentOrgId,
  3862. CostTotal: medfee_sumamt,
  3863. FuncTotal: fund_pay_sumamt,
  3864. PsnPay: acct_pay,
  3865. Creator: admin_user_id,
  3866. Ctime: time.Now().Unix(),
  3867. }
  3868. err := service.CreateMedicalInsuranceCostCompareRecord(micc)
  3869. if err == nil {
  3870. c.ServeSuccessJSON(map[string]interface{}{
  3871. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  3872. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  3873. })
  3874. } else {
  3875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3876. }
  3877. } else {
  3878. c.ServeSuccessJSON(map[string]interface{}{
  3879. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  3880. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  3881. })
  3882. }
  3883. } else {
  3884. c.ServeSuccessJSON(map[string]interface{}{
  3885. "code": -10,
  3886. "msg": res.ErrMsg,
  3887. })
  3888. }
  3889. }
  3890. }
  3891. func (c *HisApiController) Check310() {
  3892. adminUser := c.GetAdminUserInfo()
  3893. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3894. var user_name string
  3895. user_name = "xxx"
  3896. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  3897. "insutype=" + "310" +
  3898. "&clr_type=" + "11" +
  3899. "&setl_optins=" + "定点医保中心" +
  3900. "&stmt_begndate=" + "2021-03-01" +
  3901. "&stm_enddate=" + "2021-03-31" +
  3902. "&medfee_sumamt=" + "11521" +
  3903. "&fund_pay_sumamt=" + "10166.66" +
  3904. "&acct_pay=" + "0" +
  3905. "&fixmedins_setl_cnt=" + "7" +
  3906. "&fixmedins_code=" + miConfig.Code +
  3907. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3908. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3909. "&secret_key=" + miConfig.SecretKey +
  3910. "&org_name=" + miConfig.OrgName +
  3911. "&doctor=" + user_name
  3912. fmt.Println(api)
  3913. resp, requestErr := http.Get(api)
  3914. if requestErr != nil {
  3915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3916. return
  3917. }
  3918. body, ioErr := ioutil.ReadAll(resp.Body)
  3919. fmt.Println(body)
  3920. if ioErr != nil {
  3921. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3923. return
  3924. }
  3925. var respJSON map[string]interface{}
  3926. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3927. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3929. return
  3930. }
  3931. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3932. userJSONBytes, _ := json.Marshal(respJSON)
  3933. var res ResultEight
  3934. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3935. utils.ErrorLog("解析失败:%v", err)
  3936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3937. return
  3938. }
  3939. }
  3940. func (c *HisApiController) Check390() {
  3941. adminUser := c.GetAdminUserInfo()
  3942. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3943. var user_name string
  3944. user_name = "张俊杰"
  3945. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  3946. "insutype=" + "390" +
  3947. "&clr_type=" + "11" +
  3948. "&setl_optins=" + "定点医保中心" +
  3949. "&stmt_begndate=" + "2021-03-01" +
  3950. "&stm_enddate=" + "2021-03-31" +
  3951. "&medfee_sumamt=" + "209318.43" +
  3952. "&fund_pay_sumamt=" + "188029.12" +
  3953. "&acct_pay=" + "0" +
  3954. "&fixmedins_setl_cnt=" + "48" +
  3955. "&fixmedins_code=" + miConfig.Code +
  3956. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3957. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3958. "&secret_key=" + miConfig.SecretKey +
  3959. "&org_name=" + miConfig.OrgName +
  3960. "&doctor=" + user_name
  3961. fmt.Println(api)
  3962. resp, requestErr := http.Get(api)
  3963. if requestErr != nil {
  3964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3965. return
  3966. }
  3967. body, ioErr := ioutil.ReadAll(resp.Body)
  3968. fmt.Println(body)
  3969. if ioErr != nil {
  3970. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3972. return
  3973. }
  3974. var respJSON map[string]interface{}
  3975. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3976. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3978. return
  3979. }
  3980. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3981. userJSONBytes, _ := json.Marshal(respJSON)
  3982. var res ResultEight
  3983. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3984. utils.ErrorLog("解析失败:%v", err)
  3985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3986. return
  3987. }
  3988. }
  3989. //对账明细
  3990. func (c *HisApiController) GetCheckDetailAccount() {
  3991. start_time := c.GetString("start_time")
  3992. end_time := c.GetString("end_time")
  3993. admin_user_id, _ := c.GetInt64("admin_user_id")
  3994. adminUser := c.GetAdminUserInfo()
  3995. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3996. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3997. timeLayout := "2006-01-02"
  3998. loc, _ := time.LoadLocation("Local")
  3999. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4000. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4001. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  4002. Mkdir(miConfig.OrgName)
  4003. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  4004. file_name := file + ".txt"
  4005. zip_name := file + ".zip"
  4006. zip_path := miConfig.OrgName + "/" + zip_name
  4007. file_path := miConfig.OrgName + "/" + file_name
  4008. decimal.DivisionPrecision = 2
  4009. var medfee_sumamt float64
  4010. var psn_cash_pay float64
  4011. var fund_pay_sumamt float64
  4012. fixmedins_setl_cnt := int64(len(orders))
  4013. for _, item := range orders {
  4014. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  4015. psn_cash_pay = psn_cash_pay + item.PsnCashPay
  4016. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  4017. }
  4018. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  4019. defer f.Close()
  4020. if err != nil {
  4021. fmt.Println(err.Error())
  4022. } else {
  4023. for _, item := range orders {
  4024. var refd_setl_flag string
  4025. if item.OrderStatus == 2 {
  4026. refd_setl_flag = "0"
  4027. var str string
  4028. str = item.SetlId + " " +
  4029. item.MdtrtId + " " +
  4030. item.PsnNo + " " +
  4031. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  4032. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  4033. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\r\n"
  4034. _, err = f.Write([]byte(str))
  4035. }
  4036. if item.OrderStatus == 3 {
  4037. var str string
  4038. str = item.SetlId + " " +
  4039. item.MdtrtId + " " +
  4040. item.PsnNo + " " +
  4041. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  4042. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  4043. fmt.Sprintf("%.2f", item.AcctPay) + " " + "1" + "\r\n"
  4044. _, err = f.Write([]byte(str))
  4045. var str2 string
  4046. str2 = item.SetlId + " " +
  4047. item.MdtrtId + " " +
  4048. item.PsnNo + " " +
  4049. fmt.Sprintf("%.2f", 0-item.MedfeeSumamt) + " " +
  4050. fmt.Sprintf("%.2f", 0-item.FundPaySumamt) + " " +
  4051. fmt.Sprintf("%.2f", 0-item.AcctPay) + " " + "1" + "\r\n"
  4052. _, err = f.Write([]byte(str2))
  4053. }
  4054. }
  4055. }
  4056. Zip(file_path, zip_path)
  4057. fmt.Println(ReadFile(zip_path))
  4058. fmt.Println(string(ReadFile(zip_path)))
  4059. if config.IsOpen == 1 {
  4060. var user_name string
  4061. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4062. if role.ID == 0 {
  4063. user_name = "管理员"
  4064. } else {
  4065. user_name = role.UserName
  4066. }
  4067. baseParams := models.BaseParams{
  4068. SecretKey: miConfig.SecretKey,
  4069. FixmedinsCode: miConfig.Code,
  4070. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4071. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4072. OrgName: miConfig.OrgName,
  4073. Doctor: user_name,
  4074. }
  4075. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  4076. var dat map[string]interface{}
  4077. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4078. fmt.Println(dat)
  4079. } else {
  4080. fmt.Println(err)
  4081. }
  4082. userJSONBytes, _ := json.Marshal(dat)
  4083. var res ResultNine
  4084. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4085. utils.ErrorLog("解析失败:%v", err)
  4086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4087. return
  4088. }
  4089. if res.Infcode == 0 {
  4090. fileNo := res.Output.FileQuryNo
  4091. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  4092. "file_qury_no=" + fileNo +
  4093. "&setl_optins=" + "定点医保中心" +
  4094. "&stmt_begndate=" + start_time +
  4095. "&stm_enddate=" + end_time +
  4096. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  4097. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  4098. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  4099. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  4100. "&fixmedins_code=" + miConfig.Code +
  4101. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  4102. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  4103. "&secret_key=" + miConfig.SecretKey +
  4104. "&org_name=" + miConfig.OrgName +
  4105. "&doctor=" + user_name
  4106. resp, requestErr := http.Get(api)
  4107. if requestErr != nil {
  4108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4109. return
  4110. }
  4111. body, ioErr := ioutil.ReadAll(resp.Body)
  4112. if ioErr != nil {
  4113. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4115. return
  4116. }
  4117. var respJSON map[string]interface{}
  4118. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4119. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4121. return
  4122. }
  4123. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4124. userJSONBytes, _ := json.Marshal(respJSON)
  4125. var res ResultTen
  4126. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4127. utils.ErrorLog("解析失败:%v", err)
  4128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4129. return
  4130. }
  4131. if res.Infcode == 0 {
  4132. service.Gdyb9102(baseParams, zip_name, fileNo)
  4133. micc := &models.MedicalInsuranceCostCompare{
  4134. StartTime: startime.Unix(),
  4135. EndTime: endtime.Unix(),
  4136. Insutype: "0",
  4137. CheckType: 2,
  4138. Num: fixmedins_setl_cnt,
  4139. Mtime: time.Now().Unix(),
  4140. Status: 1,
  4141. UserOrgId: adminUser.CurrentOrgId,
  4142. CostTotal: medfee_sumamt,
  4143. FuncTotal: fund_pay_sumamt,
  4144. PsnPay: psn_cash_pay,
  4145. Creator: admin_user_id,
  4146. Ctime: time.Now().Unix(),
  4147. }
  4148. service.CreateMedicalInsuranceCostCompareRecord(micc)
  4149. c.ServeSuccessJSON(map[string]interface{}{
  4150. "msg": "明细对账成功",
  4151. })
  4152. }
  4153. } else {
  4154. }
  4155. }
  4156. }
  4157. func (c *HisApiController) GetSettleAccounts() {
  4158. //id, _ := c.GetInt64("id")
  4159. //record_time := c.GetString("record_time")
  4160. order_id, _ := c.GetInt64("order_id")
  4161. admin_user_id, _ := c.GetInt64("admin_user_id")
  4162. //timeLayout := "2006-01-02"
  4163. //loc, _ := time.LoadLocation("Local")
  4164. //
  4165. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4166. //if err != nil {
  4167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4168. // return
  4169. //}
  4170. //recordDateTime := theTime.Unix()
  4171. adminUser := c.GetAdminUserInfo()
  4172. order, _ := service.GetHisOrderByID(order_id)
  4173. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  4174. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  4175. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  4176. orderInfos = append(orderInfos, orderInfos_two...)
  4177. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  4178. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  4179. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  4180. //var config []*models.HisXtDiagnoseConfig
  4181. var name string
  4182. for _, item := range diagnosis_ids {
  4183. id, _ := strconv.ParseInt(item, 10, 64)
  4184. diagnosisConfig, _ := service.FindDiagnoseById(id)
  4185. if len(name) == 0 {
  4186. name = diagnosisConfig.ClassName
  4187. } else {
  4188. name = name + "," + diagnosisConfig.ClassName
  4189. }
  4190. }
  4191. var bedCostTotal float64 = 0 //床位总费
  4192. var bedCostSelfTotal float64 = 0 //床位自费
  4193. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  4194. var operationCostTotal float64 = 0 //手术费
  4195. var operationCostSelfTotal float64 = 0 //手术费
  4196. var operationCostPartSelfTotal float64 = 0 //手术费
  4197. var otherCostTotal float64 = 0 //其他费用
  4198. var otherCostSelfTotal float64 = 0 //其他费用
  4199. var otherCostPartSelfTotal float64 = 0 //其他费用
  4200. var materialCostTotal float64 = 0 //材料费
  4201. var materialCostSelfTotal float64 = 0 //材料费
  4202. var materialCostPartSelfTotal float64 = 0 //材料费
  4203. var westernMedicineCostTotal float64 = 0 //西药费
  4204. var westernMedicineCostSelfTotal float64 = 0 //西药费
  4205. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  4206. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  4207. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  4208. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  4209. var checkCostTotal float64 = 0 //检查费
  4210. var checkCostSelfTotal float64 = 0 //检查费
  4211. var checkCostPartSelfTotal float64 = 0 //检查费
  4212. var laboratoryCostTotal float64 = 0 //化验费
  4213. var laboratoryCostSelfTotal float64 = 0 //化验费
  4214. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  4215. var treatCostTotal float64 = 0 //治疗费用
  4216. var treatCostSelfTotal float64 = 0 //治疗费用
  4217. var treatCostPartSelfTotal float64 = 0 //治疗费用
  4218. decimal.DivisionPrecision = 2
  4219. for _, item := range orderInfos {
  4220. if item.MedChrgitmType == "01" { //床位费
  4221. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4222. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4223. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4224. }
  4225. if item.MedChrgitmType == "03" { //检查费
  4226. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4227. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4228. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4229. }
  4230. if item.MedChrgitmType == "04" { //化验费
  4231. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4232. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4233. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4234. }
  4235. if item.MedChrgitmType == "05" { //治疗费
  4236. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4237. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4238. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4239. }
  4240. if item.MedChrgitmType == "06" { //手术费
  4241. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4242. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4243. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4244. }
  4245. if item.MedChrgitmType == "08" { //材料费
  4246. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4247. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4248. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4249. }
  4250. if item.MedChrgitmType == "09" { //西药费
  4251. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4252. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4253. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4254. }
  4255. if item.MedChrgitmType == "11" { //中成费
  4256. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4257. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4258. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4259. }
  4260. if item.MedChrgitmType == "14" { //其他费
  4261. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4262. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4263. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4264. }
  4265. }
  4266. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4267. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4268. var user_name string
  4269. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4270. if role.ID == 0 {
  4271. user_name = "管理员"
  4272. } else {
  4273. user_name = role.UserName
  4274. }
  4275. baseParams := models.BaseParams{
  4276. SecretKey: miConfig.SecretKey,
  4277. FixmedinsCode: miConfig.Code,
  4278. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4279. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4280. OrgName: miConfig.OrgName,
  4281. Doctor: user_name,
  4282. }
  4283. businessParams := models.BusinessParams{
  4284. PsnNo: order.PsnNo,
  4285. MdtrtId: order.MdtrtId,
  4286. SetlId: order.SetlId,
  4287. }
  4288. if config.IsOpen == 1 {
  4289. result := service.Gdyb5203(baseParams, businessParams)
  4290. var dat map[string]interface{}
  4291. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4292. fmt.Println(dat)
  4293. } else {
  4294. fmt.Println(err)
  4295. }
  4296. userJSONBytes, _ := json.Marshal(dat)
  4297. var res ResultEleven
  4298. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4299. utils.ErrorLog("解析失败:%v", err)
  4300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4301. return
  4302. }
  4303. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4304. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  4305. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, order.PatientId, order.SettleAccountsDate)
  4306. adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  4307. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4308. var doctor_name string
  4309. if roles.ID == 0 {
  4310. doctor_name = "管理员"
  4311. } else {
  4312. doctor_name = roles.UserName
  4313. }
  4314. yiliao_leibie := ""
  4315. switch order.MedType {
  4316. case "11":
  4317. yiliao_leibie = "普通门诊"
  4318. break
  4319. case "12":
  4320. yiliao_leibie = "门诊挂号"
  4321. break
  4322. case "13":
  4323. yiliao_leibie = "急诊"
  4324. break
  4325. case "14":
  4326. yiliao_leibie = "门诊特殊病"
  4327. break
  4328. case "15":
  4329. yiliao_leibie = "门诊统筹"
  4330. break
  4331. case "16":
  4332. yiliao_leibie = "门诊慢性病"
  4333. break
  4334. case "21":
  4335. yiliao_leibie = "普通住院"
  4336. break
  4337. }
  4338. departments, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  4339. if res.Infcode == 0 {
  4340. c.ServeSuccessJSON(map[string]interface{}{
  4341. "diagnosis": name,
  4342. "order_infos": orderInfos,
  4343. "number": order.MdtrtId,
  4344. "date": order.SettleAccountsDate,
  4345. "charge_admin": charge_admin,
  4346. "printor_admin": printor_admin,
  4347. "info": res.Output.Setlinfo,
  4348. "bedCostTotal": bedCostTotal,
  4349. "bedCostSelfTotal": bedCostSelfTotal,
  4350. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  4351. "operationCostTotal": operationCostTotal,
  4352. "operationCostSelfTotal": operationCostSelfTotal,
  4353. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  4354. "otherCostTotal": otherCostTotal,
  4355. "otherCostSelfTotal": otherCostSelfTotal,
  4356. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  4357. "materialCostTotal": materialCostTotal,
  4358. "materialCostSelfTotal": materialCostSelfTotal,
  4359. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  4360. "westernMedicineCostTotal": westernMedicineCostTotal,
  4361. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  4362. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  4363. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  4364. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  4365. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  4366. "checkCostTotal": checkCostTotal,
  4367. "checkCostSelfTotal": checkCostSelfTotal,
  4368. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  4369. "laboratoryCostTotal": laboratoryCostTotal,
  4370. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  4371. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  4372. "treatCostTotal": treatCostTotal,
  4373. "treatCostSelfTotal": treatCostSelfTotal,
  4374. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  4375. "doctor_code": adminRole_two.DoctorCode,
  4376. "doctor_name": doctor_name,
  4377. "health_card_no": order.PsnNo,
  4378. "department": departments.Name,
  4379. "yiliao_leibie": yiliao_leibie,
  4380. "after_money": order.AccountPrice,
  4381. "patient": patient,
  4382. "org_name": miConfig.OrgName,
  4383. "org_code": miConfig.Code,
  4384. "order_number": order.Number,
  4385. })
  4386. }
  4387. }
  4388. }
  4389. func (c *HisApiController) CheckTreatment() {
  4390. patient_id, _ := c.GetInt64("patient_id", 0)
  4391. record_time := c.GetString("record_time")
  4392. insutype := c.GetString("insutype")
  4393. timeLayout := "2006-01-02"
  4394. loc, _ := time.LoadLocation("Local")
  4395. adminUser := c.GetAdminUserInfo()
  4396. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4397. fmt.Println(err)
  4398. if err != nil {
  4399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4400. return
  4401. }
  4402. recordDateTime := theTime.Unix()
  4403. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  4404. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  4405. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4406. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4407. var user_name string
  4408. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  4409. if role.ID == 0 {
  4410. user_name = "xxx"
  4411. } else {
  4412. user_name = role.UserName
  4413. }
  4414. baseParams := models.BaseParams{
  4415. SecretKey: miConfig.SecretKey,
  4416. FixmedinsCode: miConfig.Code,
  4417. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4418. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4419. OrgName: miConfig.OrgName,
  4420. Doctor: user_name,
  4421. }
  4422. if config.IsOpen == 1 {
  4423. result := service.Gdyb2001(baseParams, his.PsnNo, insutype, strconv.FormatInt(patientPrescription.RegisterType, 10))
  4424. var dat map[string]interface{}
  4425. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4426. fmt.Println(dat)
  4427. } else {
  4428. fmt.Println(err)
  4429. }
  4430. }
  4431. }
  4432. func (c *HisApiController) PutRecord() {
  4433. id, _ := c.GetInt64("id")
  4434. record_time := c.GetString("record_time")
  4435. timeLayout := "2006-01-02"
  4436. loc, _ := time.LoadLocation("Local")
  4437. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4438. if err != nil {
  4439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4440. return
  4441. }
  4442. recordDateTime := theTime.Unix()
  4443. adminInfo := c.GetAdminUserInfo()
  4444. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  4445. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  4446. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  4447. fmt.Println(miConfig.SecretKey)
  4448. if patient == nil {
  4449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4450. return
  4451. }
  4452. if len(patient.IdCardNo) == 0 {
  4453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  4454. return
  4455. }
  4456. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  4457. if config.IsOpen == 1 {
  4458. 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
  4459. resp, requestErr := http.Get(api)
  4460. if requestErr != nil {
  4461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4462. return
  4463. }
  4464. defer resp.Body.Close()
  4465. body, ioErr := ioutil.ReadAll(resp.Body)
  4466. if ioErr != nil {
  4467. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4469. return
  4470. }
  4471. var respJSON map[string]interface{}
  4472. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4473. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4475. return
  4476. }
  4477. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4478. userJSONBytes, _ := json.Marshal(userJSON)
  4479. var res ResultTwo
  4480. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4481. utils.ErrorLog("解析失败:%v", err)
  4482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4483. return
  4484. }
  4485. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  4486. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  4487. infoStr := string(Iinfos)
  4488. idetinfoStr := string(Idetinfos)
  4489. if res.Infcode == 0 {
  4490. his := models.VMHisPatient{
  4491. Status: 1,
  4492. Ctime: time.Now().Unix(),
  4493. Mtime: time.Now().Unix(),
  4494. PsnNo: res.Output.Baseinfo.PsnNo,
  4495. PsnCertType: res.Output.Baseinfo.PsnCertType,
  4496. Certno: res.Output.Baseinfo.Certno,
  4497. PsnName: res.Output.Baseinfo.PsnName,
  4498. Gend: res.Output.Baseinfo.Gend,
  4499. Naty: res.Output.Baseinfo.Naty,
  4500. Brdy: res.Output.Baseinfo.Brdy,
  4501. Age: res.Output.Baseinfo.Age,
  4502. Iinfo: infoStr,
  4503. Idetinfo: idetinfoStr,
  4504. PatientId: patient.ID,
  4505. RecordDate: theTime.Unix(),
  4506. UserOrgId: adminInfo.CurrentOrgId,
  4507. AdminUserId: adminInfo.AdminUser.Id,
  4508. IsReturn: 1,
  4509. }
  4510. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  4511. 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")
  4512. 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")
  4513. var dat map[string]interface{}
  4514. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4515. fmt.Println(dat)
  4516. } else {
  4517. fmt.Println(err)
  4518. }
  4519. var dat2 map[string]interface{}
  4520. if err := json.Unmarshal([]byte(result2), &dat2); err == nil {
  4521. fmt.Println(dat2)
  4522. } else {
  4523. fmt.Println(err)
  4524. }
  4525. } else {
  4526. adminUser := c.GetAdminUserInfo()
  4527. errlog := &models.HisOrderError{
  4528. UserOrgId: adminUser.CurrentOrgId,
  4529. Ctime: time.Now().Unix(),
  4530. Mtime: time.Now().Unix(),
  4531. ErrMsg: res.ErrMsg,
  4532. Status: 1,
  4533. PatientId: id,
  4534. RecordTime: recordDateTime,
  4535. Stage: 1,
  4536. }
  4537. service.CreateErrMsgLog(errlog)
  4538. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  4539. return
  4540. }
  4541. }
  4542. }
  4543. func (c *HisApiController) GetUploadDiag() {
  4544. id, _ := c.GetInt64("id")
  4545. record_time := c.GetString("record_time")
  4546. diagnosis_id, _ := c.GetInt64("diagnosis")
  4547. sick_type, _ := c.GetInt64("sick_type")
  4548. reg_type, _ := c.GetInt64("reg_type")
  4549. timeLayout := "2006-01-02"
  4550. loc, _ := time.LoadLocation("Local")
  4551. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4552. if err != nil {
  4553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4554. return
  4555. }
  4556. var patientPrescription models.HisPrescriptionInfo
  4557. recordDateTime := theTime.Unix()
  4558. adminInfo := c.GetAdminUserInfo()
  4559. patientPrescription, _ = service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  4560. if patientPrescription.ID == 0 {
  4561. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  4562. }
  4563. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  4564. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  4565. his, _ := service.GetVMHisPatientInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  4566. sickConfig, _ := service.FindSickById(sick_type)
  4567. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  4568. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  4569. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  4570. "&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 +
  4571. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.ContentCode + "&sick_name=" + sickConfig.ClassName
  4572. resp2, requestErr2 := http.Get(api2)
  4573. if requestErr2 != nil {
  4574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4575. return
  4576. }
  4577. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  4578. if ioErr2 != nil {
  4579. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  4580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4581. return
  4582. }
  4583. var respJSON2 map[string]interface{}
  4584. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  4585. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4587. return
  4588. }
  4589. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4590. userJSONBytes2, _ := json.Marshal(respJSON2)
  4591. var res2 ResultSix
  4592. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  4593. utils.ErrorLog("解析失败:%v", err)
  4594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4595. return
  4596. }
  4597. if res2.Infcode != 0 {
  4598. adminUser := c.GetAdminUserInfo()
  4599. errlog := &models.HisOrderError{
  4600. UserOrgId: adminUser.CurrentOrgId,
  4601. Ctime: time.Now().Unix(),
  4602. Mtime: time.Now().Unix(),
  4603. ErrMsg: res2.ErrMsg,
  4604. Status: 1,
  4605. PatientId: id,
  4606. RecordTime: recordDateTime,
  4607. Stage: 3,
  4608. }
  4609. service.CreateErrMsgLog(errlog)
  4610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  4611. return
  4612. }
  4613. c.ServeSuccessJSON(map[string]interface{}{
  4614. "msg": "上传成功",
  4615. })
  4616. }
  4617. type QueryResult struct {
  4618. ID int64
  4619. Name string
  4620. Code string
  4621. List_type_code string
  4622. }
  4623. func (c *HisApiController) GetCheckCode() {
  4624. ids_str := c.GetString("ids")
  4625. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  4626. ids_arr := strings.Split(ids_str, ",")
  4627. var queryResult []QueryResult
  4628. ids := make([]int64, 0)
  4629. for _, item := range ids_arr {
  4630. id, _ := strconv.ParseInt(item, 10, 64)
  4631. ids = append(ids, id)
  4632. }
  4633. if record_type == 1 {
  4634. drugs, _ := service.GetBatchDrugList(ids)
  4635. for _, item := range drugs {
  4636. result := QueryResult{
  4637. ID: item.ID,
  4638. Name: item.DrugName,
  4639. Code: item.MedicalInsuranceNumber,
  4640. List_type_code: "101",
  4641. }
  4642. queryResult = append(queryResult, result)
  4643. }
  4644. } else if record_type == 2 {
  4645. goods, _ := service.GetBatchGoodInformationList(ids)
  4646. for _, item := range goods {
  4647. result := QueryResult{
  4648. ID: item.ID,
  4649. Name: item.GoodName,
  4650. Code: item.MedicalInsuranceNumber,
  4651. List_type_code: "301",
  4652. }
  4653. queryResult = append(queryResult, result)
  4654. }
  4655. } else if record_type == 3 {
  4656. projects, _ := service.GetBathchMyPorjecgList(ids)
  4657. for _, item := range projects {
  4658. result := QueryResult{
  4659. ID: item.ID,
  4660. Name: item.ProjectName,
  4661. Code: item.MedicalCode,
  4662. List_type_code: "201",
  4663. }
  4664. queryResult = append(queryResult, result)
  4665. }
  4666. }
  4667. admin_user_id, _ := c.GetInt64("admin_user_id")
  4668. adminUser := c.GetAdminUserInfo()
  4669. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4670. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4671. var user_name string
  4672. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4673. if role.ID == 0 {
  4674. user_name = "xxx"
  4675. } else {
  4676. user_name = role.UserName
  4677. }
  4678. baseParams := &models.BaseParams{
  4679. SecretKey: miConfig.SecretKey,
  4680. FixmedinsCode: miConfig.Code,
  4681. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4682. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4683. OrgName: miConfig.OrgName,
  4684. Doctor: user_name,
  4685. }
  4686. if config.IsOpen == 1 {
  4687. for _, item := range queryResult {
  4688. var result string
  4689. if record_type == 1 {
  4690. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  4691. } else if record_type == 2 {
  4692. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  4693. } else if record_type == 3 {
  4694. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  4695. }
  4696. var dat map[string]interface{}
  4697. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4698. fmt.Println(dat)
  4699. } else {
  4700. fmt.Println(err)
  4701. }
  4702. userJSONBytes, _ := json.Marshal(dat)
  4703. var res ResultSix
  4704. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4705. utils.ErrorLog("解析失败:%v", err)
  4706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4707. return
  4708. }
  4709. if res.Infcode == 0 {
  4710. if record_type == 1 {
  4711. service.UpdateBaseDrugById(item.ID)
  4712. } else if record_type == 2 {
  4713. service.UpdateGoodInformaitonByDetail(item.ID)
  4714. } else if record_type == 3 {
  4715. service.UpdateProjectById(item.ID)
  4716. }
  4717. c.ServeSuccessJSON(map[string]interface{}{
  4718. "failed_code": 0,
  4719. "msg": "目录对照成功",
  4720. })
  4721. } else {
  4722. c.ServeSuccessJSON(map[string]interface{}{
  4723. "failed_code": -10,
  4724. "msg": res.ErrMsg,
  4725. })
  4726. }
  4727. }
  4728. }
  4729. }
  4730. func (c *HisApiController) UnCheckCode() {
  4731. ids_str := c.GetString("ids")
  4732. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  4733. admin_user_id, _ := c.GetInt64("admin_user_id")
  4734. ids_arr := strings.Split(ids_str, ",")
  4735. var queryResult []QueryResult
  4736. ids := make([]int64, 0)
  4737. for _, item := range ids_arr {
  4738. id, _ := strconv.ParseInt(item, 10, 64)
  4739. ids = append(ids, id)
  4740. }
  4741. if record_type == 1 {
  4742. drugs, _ := service.GetBatchDrugList(ids)
  4743. for _, item := range drugs {
  4744. result := QueryResult{
  4745. ID: item.ID,
  4746. Name: item.DrugName,
  4747. Code: item.MedicalInsuranceNumber,
  4748. List_type_code: "101",
  4749. }
  4750. queryResult = append(queryResult, result)
  4751. }
  4752. } else if record_type == 2 {
  4753. goods, _ := service.GetBatchGoodInformationList(ids)
  4754. for _, item := range goods {
  4755. result := QueryResult{
  4756. ID: item.ID,
  4757. Name: item.GoodName,
  4758. Code: item.MedicalInsuranceNumber,
  4759. List_type_code: "301",
  4760. }
  4761. queryResult = append(queryResult, result)
  4762. }
  4763. } else if record_type == 3 {
  4764. projects, _ := service.GetBathchMyPorjecgList(ids)
  4765. for _, item := range projects {
  4766. result := QueryResult{
  4767. ID: item.ID,
  4768. Name: item.ProjectName,
  4769. Code: item.MedicalCode,
  4770. List_type_code: "201",
  4771. }
  4772. queryResult = append(queryResult, result)
  4773. }
  4774. }
  4775. adminUser := c.GetAdminUserInfo()
  4776. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4777. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4778. var user_name string
  4779. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4780. if role.ID == 0 {
  4781. user_name = "xxx"
  4782. } else {
  4783. user_name = role.UserName
  4784. }
  4785. baseParams := &models.BaseParams{
  4786. SecretKey: miConfig.SecretKey,
  4787. FixmedinsCode: miConfig.Code,
  4788. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4789. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4790. OrgName: miConfig.OrgName,
  4791. Doctor: user_name,
  4792. }
  4793. if config.IsOpen == 1 {
  4794. for _, item := range queryResult {
  4795. var result string
  4796. if record_type == 1 {
  4797. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  4798. } else if record_type == 2 {
  4799. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  4800. } else if record_type == 3 {
  4801. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  4802. }
  4803. var dat2 map[string]interface{}
  4804. if err := json.Unmarshal([]byte(result), &dat2); err == nil {
  4805. fmt.Println(dat2)
  4806. } else {
  4807. fmt.Println(err)
  4808. }
  4809. userJSONBytes, _ := json.Marshal(dat2)
  4810. var res ResultSix
  4811. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4812. utils.ErrorLog("解析失败:%v", err)
  4813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4814. return
  4815. }
  4816. if res.Infcode == 0 {
  4817. if record_type == 1 {
  4818. service.UpdateDrugByIdDetail(item.ID)
  4819. } else if record_type == 2 {
  4820. service.UpdateGoodInfoById(item.ID)
  4821. } else if record_type == 3 {
  4822. service.UpdateMyProjectById(item.ID)
  4823. }
  4824. c.ServeSuccessJSON(map[string]interface{}{
  4825. "failed_code": 0,
  4826. "msg": "撤销目录对照成功",
  4827. })
  4828. } else {
  4829. c.ServeSuccessJSON(map[string]interface{}{
  4830. "failed_code": -10,
  4831. "msg": res.ErrMsg,
  4832. })
  4833. }
  4834. }
  4835. }
  4836. }
  4837. func (c *HisApiController) GetPatientInfo() {
  4838. id_card_no := c.GetString("id_card_no")
  4839. admin_user_id, _ := c.GetInt64("admin_user_id")
  4840. patient, _ := service.GetPatientByIDCard(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  4841. if patient.ID == 0 {
  4842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4843. return
  4844. }
  4845. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  4846. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  4847. config, _ := service.GetMedicalInsuranceConfig(c.GetAdminUserInfo().CurrentOrgId)
  4848. if config.IsOpen == 1 {
  4849. result := service.Gdyb1101A(id_card_no, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  4850. var dat map[string]interface{}
  4851. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4852. fmt.Println(dat)
  4853. } else {
  4854. fmt.Println(err)
  4855. }
  4856. userJSONBytes, _ := json.Marshal(dat)
  4857. var res ResultTwo
  4858. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4859. utils.ErrorLog("解析失败:%v", err)
  4860. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4861. return
  4862. }
  4863. if res.Infcode != 0 {
  4864. c.ServeSuccessJSON(map[string]interface{}{
  4865. "failed_code": -10,
  4866. "msg": res.ErrMsg,
  4867. })
  4868. } else {
  4869. c.ServeSuccessJSON(map[string]interface{}{
  4870. "failed_code": 0,
  4871. "info": res,
  4872. })
  4873. }
  4874. }
  4875. }
  4876. func (c *HisApiController) PsnPutOnRecord() {
  4877. record_type, _ := c.GetInt64("type")
  4878. patient_id, _ := c.GetInt64("patient_id")
  4879. admin_user_id, _ := c.GetInt64("admin_user_id")
  4880. start_time := c.GetString("start_time")
  4881. end_time := c.GetString("end_time")
  4882. adminUser := c.GetAdminUserInfo()
  4883. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4884. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4885. var patients []*models.Patients
  4886. if record_type == 1 { //全部备案
  4887. patient, _ := service.GetAllPatient(adminUser.CurrentOrgId)
  4888. patients = append(patients, patient...)
  4889. } else { //单个备案
  4890. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  4891. patients = append(patients, patient)
  4892. }
  4893. var user_name string
  4894. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4895. if role.ID == 0 {
  4896. user_name = "xxx"
  4897. } else {
  4898. user_name = role.UserName
  4899. }
  4900. if config.IsOpen == 1 {
  4901. for _, item := range patients {
  4902. 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
  4903. resp, requestErr := http.Get(api)
  4904. if requestErr != nil {
  4905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4906. return
  4907. }
  4908. defer resp.Body.Close()
  4909. body, ioErr := ioutil.ReadAll(resp.Body)
  4910. if ioErr != nil {
  4911. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4912. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4913. return
  4914. }
  4915. var respJSON map[string]interface{}
  4916. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4917. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4919. return
  4920. }
  4921. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4922. userJSONBytes, _ := json.Marshal(userJSON)
  4923. var res ResultTwo
  4924. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4925. utils.ErrorLog("解析失败:%v", err)
  4926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4927. return
  4928. }
  4929. if res.Infcode == 0 {
  4930. result := service.Gdyb2505(res.Output.Baseinfo.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, start_time, end_time)
  4931. var dat map[string]interface{}
  4932. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4933. fmt.Println(dat)
  4934. } else {
  4935. fmt.Println(err)
  4936. }
  4937. userJSONBytes, _ := json.Marshal(dat)
  4938. var res2 ResultThirteen
  4939. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  4940. utils.ErrorLog("解析失败:%v", err)
  4941. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4942. return
  4943. }
  4944. if res2.Infcode == 0 {
  4945. psnResult := &models.GdybPsnRecord{
  4946. UserOrgId: adminUser.CurrentOrgId,
  4947. PatientId: item.ID,
  4948. PsnNo: res.Output.Baseinfo.PsnNo,
  4949. Ctime: time.Now().Unix(),
  4950. Mtime: time.Now().Unix(),
  4951. Status: 1,
  4952. IsCancel: 1,
  4953. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  4954. }
  4955. service.CreatePsnRecord(psnResult)
  4956. } else {
  4957. c.ServeSuccessJSON(map[string]interface{}{
  4958. "failed_code": -10,
  4959. "msg": res2.ErrMsg,
  4960. })
  4961. return
  4962. }
  4963. }
  4964. }
  4965. }
  4966. }
  4967. func (c *HisApiController) PsnUnPutOnRecord() {
  4968. id, _ := c.GetInt64("id")
  4969. //record_type, _ := c.GetInt64("type")
  4970. admin_user_id, _ := c.GetInt64("admin_user_id")
  4971. adminUser := c.GetAdminUserInfo()
  4972. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4973. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4974. var user_name string
  4975. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4976. if role.ID == 0 {
  4977. user_name = "xxx"
  4978. } else {
  4979. user_name = role.UserName
  4980. }
  4981. psn_record, _ := service.GetPsnRecordById(id)
  4982. if psn_record.ID == 0 {
  4983. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  4984. return
  4985. }
  4986. if config.IsOpen == 1 {
  4987. result := service.Gdyb2506(psn_record.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  4988. var dat map[string]interface{}
  4989. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4990. fmt.Println(dat)
  4991. } else {
  4992. fmt.Println(err)
  4993. }
  4994. userJSONBytes, _ := json.Marshal(dat)
  4995. var res ResultFourteen
  4996. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4997. utils.ErrorLog("解析失败:%v", err)
  4998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4999. return
  5000. }
  5001. if res.Infcode == 0 {
  5002. psn_record.IsCancel = 2
  5003. service.CreatePsnRecord(&psn_record)
  5004. } else {
  5005. c.ServeSuccessJSON(map[string]interface{}{
  5006. "failed_code": -10,
  5007. "msg": res.ErrMsg,
  5008. })
  5009. return
  5010. }
  5011. }
  5012. }
  5013. func (c *HisApiController) PsnPutNCDSOnRecord() {
  5014. patient_id, _ := c.GetInt64("patient_id")
  5015. insutype := c.GetString("insutype")
  5016. psn_no := c.GetString("psn_no")
  5017. doctor_id, _ := c.GetInt64("doctor_id")
  5018. sick_id, _ := c.GetInt64("sick_id")
  5019. department_id, _ := c.GetInt64("department_id")
  5020. adminUser := c.GetAdminUserInfo()
  5021. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  5022. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5023. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5024. sick, _ := service.FindSickById(sick_id)
  5025. doctor, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, doctor_id)
  5026. if config.IsOpen == 1 {
  5027. 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)
  5028. var dat map[string]interface{}
  5029. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5030. fmt.Println(dat)
  5031. } else {
  5032. fmt.Println(err)
  5033. }
  5034. userJSONBytes, _ := json.Marshal(dat)
  5035. var res2 ResultThirteen
  5036. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  5037. utils.ErrorLog("解析失败:%v", err)
  5038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5039. return
  5040. }
  5041. if res2.Infcode == 0 {
  5042. psnResult := &models.GdybPsnNcdsRecord{
  5043. UserOrgId: adminUser.CurrentOrgId,
  5044. PatientId: patient.ID,
  5045. PsnNo: psn_no,
  5046. DoctorId: doctor.AdminUserId,
  5047. DepartmentId: department_id,
  5048. SickType: sick_id,
  5049. Insutype: insutype,
  5050. Ctime: time.Now().Unix(),
  5051. Mtime: time.Now().Unix(),
  5052. Status: 1,
  5053. IsCancel: 1,
  5054. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  5055. }
  5056. service.CreatePsnNCDSRecord(psnResult)
  5057. c.ServeSuccessJSON(map[string]interface{}{
  5058. "failed_code": 0,
  5059. "msg": "备案成功",
  5060. "result": psnResult,
  5061. })
  5062. } else {
  5063. c.ServeSuccessJSON(map[string]interface{}{
  5064. "failed_code": -10,
  5065. "msg": res2.ErrMsg,
  5066. })
  5067. return
  5068. }
  5069. }
  5070. }
  5071. func (c *HisApiController) PsnPutUnNCDSOnRecord() {
  5072. id, _ := c.GetInt64("id")
  5073. admin_user_id, _ := c.GetInt64("admin_user_id")
  5074. adminUser := c.GetAdminUserInfo()
  5075. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5076. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5077. var user_name string
  5078. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  5079. if role.ID == 0 {
  5080. user_name = "xxx"
  5081. } else {
  5082. user_name = role.UserName
  5083. }
  5084. psn_record, _ := service.GetPsnNCDSRecordById(id)
  5085. if psn_record.ID == 0 {
  5086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  5087. return
  5088. }
  5089. if config.IsOpen == 1 {
  5090. result := service.Gdyb2504(psn_record.PsnNo, miConfig.OrgName, user_name, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  5091. var dat map[string]interface{}
  5092. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5093. fmt.Println(dat)
  5094. } else {
  5095. fmt.Println(err)
  5096. }
  5097. userJSONBytes, _ := json.Marshal(dat)
  5098. var res ResultFourteen
  5099. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5100. utils.ErrorLog("解析失败:%v", err)
  5101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5102. return
  5103. }
  5104. if res.Infcode == 0 {
  5105. psn_record.IsCancel = 2
  5106. service.CreatePsnNCDSRecord(&psn_record)
  5107. c.ServeSuccessJSON(map[string]interface{}{
  5108. "failed_code": 0,
  5109. "msg": "撤销备案成功",
  5110. })
  5111. } else {
  5112. c.ServeSuccessJSON(map[string]interface{}{
  5113. "failed_code": -10,
  5114. "msg": res.ErrMsg,
  5115. })
  5116. return
  5117. }
  5118. }
  5119. }
  5120. func (c *HisApiController) TestTest() {
  5121. patient, _ := service.GetHisPatientInfo(4, 456, 1619712000)
  5122. fmt.Println(patient.Iinfo)
  5123. }
  5124. type CustomData struct {
  5125. MsgId string
  5126. PsnNo string
  5127. Info string
  5128. }
  5129. func (c *HisApiController) ReversalData() {
  5130. var customData []*CustomData
  5131. custom := &CustomData{
  5132. MsgId: "H44022900158202103301714472004",
  5133. PsnNo: "44020000001101329945",
  5134. Info: "2207",
  5135. }
  5136. customData = append(customData, custom)
  5137. custom1 := &CustomData{
  5138. MsgId: "H4402290015820210330172057803",
  5139. PsnNo: "44020000001101161813",
  5140. Info: "2207",
  5141. }
  5142. customData = append(customData, custom1)
  5143. custom2 := &CustomData{
  5144. MsgId: "H44022900158202103301705198813",
  5145. PsnNo: "44190000133097375417",
  5146. Info: "2207",
  5147. }
  5148. customData = append(customData, custom2)
  5149. custom3 := &CustomData{
  5150. MsgId: "H44022900158202103301715524756",
  5151. PsnNo: "44020000001100187221",
  5152. Info: "2207",
  5153. }
  5154. customData = append(customData, custom3)
  5155. custom4 := &CustomData{
  5156. MsgId: "H44022900158202103301730376224",
  5157. PsnNo: "44020000001101959155",
  5158. Info: "2207",
  5159. }
  5160. customData = append(customData, custom4)
  5161. custom5 := &CustomData{
  5162. MsgId: "H44022900158202103301748008725",
  5163. PsnNo: "44020000001104246641",
  5164. Info: "2207",
  5165. }
  5166. customData = append(customData, custom5)
  5167. custom6 := &CustomData{
  5168. MsgId: "H44022900158202103301718096755",
  5169. PsnNo: "44020000001102211860",
  5170. Info: "2207",
  5171. }
  5172. customData = append(customData, custom6)
  5173. custom7 := &CustomData{
  5174. MsgId: "H44022900158202103301736551640",
  5175. PsnNo: "44020000001102687718",
  5176. Info: "2207",
  5177. }
  5178. customData = append(customData, custom7)
  5179. custom8 := &CustomData{
  5180. MsgId: "H44022900158202103301743097676",
  5181. PsnNo: "44020000001102127785",
  5182. Info: "2207",
  5183. }
  5184. customData = append(customData, custom8)
  5185. custom9 := &CustomData{
  5186. MsgId: "H44022900158202103301712304203",
  5187. PsnNo: "44020000001101518097",
  5188. Info: "2207",
  5189. }
  5190. customData = append(customData, custom9)
  5191. custom10 := &CustomData{
  5192. MsgId: "H44022900158202103301738448785",
  5193. PsnNo: "44020000001100500813",
  5194. Info: "2207",
  5195. }
  5196. customData = append(customData, custom10)
  5197. custom11 := &CustomData{
  5198. MsgId: "H44022900158202103301732455843",
  5199. PsnNo: "44020000001102690557",
  5200. Info: "2207",
  5201. }
  5202. customData = append(customData, custom11)
  5203. custom12 := &CustomData{
  5204. MsgId: "H44022900158202103301745421708",
  5205. PsnNo: "44020000001102211928",
  5206. Info: "2207",
  5207. }
  5208. customData = append(customData, custom12)
  5209. custom1212 := &CustomData{
  5210. MsgId: "H440229001582021033017351627",
  5211. PsnNo: "44020000001102481733",
  5212. Info: "2207",
  5213. }
  5214. customData = append(customData, custom1212)
  5215. custom13 := &CustomData{
  5216. MsgId: "H44022900158202103301740327951",
  5217. PsnNo: "44020000001103174866",
  5218. Info: "2207",
  5219. }
  5220. customData = append(customData, custom13)
  5221. custom14 := &CustomData{
  5222. MsgId: "H4402290015820210330174922668",
  5223. PsnNo: "44020000001102927272",
  5224. Info: "2207",
  5225. }
  5226. customData = append(customData, custom14)
  5227. custom15 := &CustomData{
  5228. MsgId: "H44022900158202103301752362273",
  5229. PsnNo: "44020000001102942890",
  5230. Info: "2207",
  5231. }
  5232. customData = append(customData, custom15)
  5233. custom16 := &CustomData{
  5234. MsgId: "H44022900158202103301751082917",
  5235. PsnNo: "44020000001101662162",
  5236. Info: "2207",
  5237. }
  5238. customData = append(customData, custom16)
  5239. custom17 := &CustomData{
  5240. MsgId: "H44022900158202103301754147728",
  5241. PsnNo: "44020000000229014511",
  5242. Info: "2207",
  5243. }
  5244. customData = append(customData, custom17)
  5245. adminUser := c.GetAdminUserInfo()
  5246. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5247. for _, item := range customData {
  5248. result := service.Gdyb2601(item.PsnNo, item.MsgId, item.Info, miConfig.OrgName, "张俊杰", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  5249. fmt.Println(result)
  5250. }
  5251. }
  5252. func (c *HisApiController) ReversalOtherData() {
  5253. var customData []*CustomData
  5254. custom := &CustomData{
  5255. MsgId: "H44022900158202103301714472004",
  5256. PsnNo: "44020000001101329945",
  5257. Info: "2208",
  5258. }
  5259. customData = append(customData, custom)
  5260. custom1 := &CustomData{
  5261. MsgId: "H4402290015820210330172057803",
  5262. PsnNo: "44020000001101161813",
  5263. Info: "2208",
  5264. }
  5265. customData = append(customData, custom1)
  5266. custom2 := &CustomData{
  5267. MsgId: "H44022900158202103301705198813",
  5268. PsnNo: "44190000133097375417",
  5269. Info: "2208",
  5270. }
  5271. customData = append(customData, custom2)
  5272. custom3 := &CustomData{
  5273. MsgId: "H44022900158202103301715524756",
  5274. PsnNo: "44020000001100187221",
  5275. Info: "2208",
  5276. }
  5277. customData = append(customData, custom3)
  5278. custom4 := &CustomData{
  5279. MsgId: "H44022900158202103301730376224",
  5280. PsnNo: "44020000001101959155",
  5281. Info: "2208",
  5282. }
  5283. customData = append(customData, custom4)
  5284. custom5 := &CustomData{
  5285. MsgId: "H44022900158202103301748008725",
  5286. PsnNo: "44020000001104246641",
  5287. Info: "2208",
  5288. }
  5289. customData = append(customData, custom5)
  5290. custom6 := &CustomData{
  5291. MsgId: "H44022900158202103301718096755",
  5292. PsnNo: "44020000001102211860",
  5293. Info: "2208",
  5294. }
  5295. customData = append(customData, custom6)
  5296. custom7 := &CustomData{
  5297. MsgId: "H44022900158202103301736551640",
  5298. PsnNo: "44020000001102687718",
  5299. Info: "2208",
  5300. }
  5301. customData = append(customData, custom7)
  5302. custom8 := &CustomData{
  5303. MsgId: "H44022900158202103301743097676",
  5304. PsnNo: "44020000001102127785",
  5305. Info: "2208",
  5306. }
  5307. customData = append(customData, custom8)
  5308. custom9 := &CustomData{
  5309. MsgId: "H44022900158202103301712304203",
  5310. PsnNo: "44020000001101518097",
  5311. Info: "2208",
  5312. }
  5313. customData = append(customData, custom9)
  5314. custom10 := &CustomData{
  5315. MsgId: "H44022900158202103301738448785",
  5316. PsnNo: "44020000001100500813",
  5317. Info: "2208",
  5318. }
  5319. customData = append(customData, custom10)
  5320. custom11 := &CustomData{
  5321. MsgId: "H44022900158202103301732455843",
  5322. PsnNo: "44020000001102690557",
  5323. Info: "2208",
  5324. }
  5325. customData = append(customData, custom11)
  5326. custom12 := &CustomData{
  5327. MsgId: "H44022900158202103301745421708",
  5328. PsnNo: "44020000001102211928",
  5329. Info: "2208",
  5330. }
  5331. customData = append(customData, custom12)
  5332. custom1212 := &CustomData{
  5333. MsgId: "H440229001582021033017351627",
  5334. PsnNo: "44020000001102481733",
  5335. Info: "2208",
  5336. }
  5337. customData = append(customData, custom1212)
  5338. custom13 := &CustomData{
  5339. MsgId: "H44022900158202103301740327951",
  5340. PsnNo: "44020000001103174866",
  5341. Info: "2208",
  5342. }
  5343. customData = append(customData, custom13)
  5344. custom14 := &CustomData{
  5345. MsgId: "H4402290015820210330174922668",
  5346. PsnNo: "44020000001102927272",
  5347. Info: "2208",
  5348. }
  5349. customData = append(customData, custom14)
  5350. custom15 := &CustomData{
  5351. MsgId: "H44022900158202103301752362273",
  5352. PsnNo: "44020000001102942890",
  5353. Info: "2208",
  5354. }
  5355. customData = append(customData, custom15)
  5356. custom16 := &CustomData{
  5357. MsgId: "H44022900158202103301751082917",
  5358. PsnNo: "44020000001101662162",
  5359. Info: "2208",
  5360. }
  5361. customData = append(customData, custom16)
  5362. custom17 := &CustomData{
  5363. MsgId: "H44022900158202103301754147728",
  5364. PsnNo: "44020000000229014511",
  5365. Info: "2208",
  5366. }
  5367. customData = append(customData, custom17)
  5368. adminUser := c.GetAdminUserInfo()
  5369. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5370. for _, item := range customData {
  5371. result := service.Gdyb2601(item.PsnNo, item.MsgId, item.Info, miConfig.OrgName, "张俊杰", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  5372. fmt.Println(result)
  5373. }
  5374. }
  5375. func PathExists(path string) (bool, error) {
  5376. _, err := os.Stat(path)
  5377. if err == nil {
  5378. return true, nil
  5379. }
  5380. if os.IsNotExist(err) {
  5381. return false, nil
  5382. }
  5383. return false, err
  5384. }
  5385. //创建文件夹
  5386. func Mkdir(dir string) {
  5387. // 创建文件夹
  5388. exist, err := PathExists(dir)
  5389. if err != nil {
  5390. fmt.Println(err.Error())
  5391. } else {
  5392. if exist {
  5393. fmt.Println(dir + "文件夹已存在!")
  5394. } else {
  5395. // 文件夹名称,权限
  5396. err := os.Mkdir(dir, os.ModePerm)
  5397. if err != nil {
  5398. fmt.Println(dir+"文件夹创建失败:", err.Error())
  5399. } else {
  5400. fmt.Println(dir + "文件夹创建成功!")
  5401. }
  5402. }
  5403. }
  5404. }
  5405. //压缩文件
  5406. func Zip(srcFile string, destZip string) error {
  5407. zipfile, err := os.Create(destZip)
  5408. if err != nil {
  5409. return err
  5410. }
  5411. defer zipfile.Close()
  5412. archive := zip.NewWriter(zipfile)
  5413. defer archive.Close()
  5414. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  5415. if err != nil {
  5416. return err
  5417. }
  5418. header, err := zip.FileInfoHeader(info)
  5419. if err != nil {
  5420. return err
  5421. }
  5422. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  5423. // header.Name = path
  5424. if info.IsDir() {
  5425. header.Name += "/"
  5426. } else {
  5427. header.Method = zip.Deflate
  5428. }
  5429. writer, err := archive.CreateHeader(header)
  5430. if err != nil {
  5431. return err
  5432. }
  5433. if !info.IsDir() {
  5434. file, err := os.Open(path)
  5435. if err != nil {
  5436. return err
  5437. }
  5438. defer file.Close()
  5439. _, err = io.Copy(writer, file)
  5440. }
  5441. return err
  5442. })
  5443. return err
  5444. }
  5445. func ReadFile(filePath string) []byte {
  5446. f, err := os.Open(filePath)
  5447. if err != nil {
  5448. fmt.Println("read file fail", err)
  5449. return nil
  5450. }
  5451. defer f.Close()
  5452. fd, err := ioutil.ReadAll(f)
  5453. if err != nil {
  5454. fmt.Println("read to fd fail", err)
  5455. return nil
  5456. }
  5457. return fd
  5458. }
  5459. func RemoveRepeatedCode(arr []string) (newArr []string) {
  5460. newArr = make([]string, 0)
  5461. for i := 0; i < len(arr); i++ {
  5462. repeat := false
  5463. for j := i + 1; j < len(arr); j++ {
  5464. if arr[i] == arr[j] {
  5465. repeat = true
  5466. break
  5467. }
  5468. }
  5469. if !repeat {
  5470. newArr = append(newArr, arr[i])
  5471. }
  5472. }
  5473. return
  5474. }
  5475. func saveRegisterLog(result string) {
  5476. org_id, _ := beego.AppConfig.Int64("org_id")
  5477. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  5478. dir := miConfig.OrgName + "日志"
  5479. utils.Mkdir(dir)
  5480. month := time.Unix(1557042972, 0).Format("1")
  5481. year := time.Now().Format("2006")
  5482. month = time.Now().Format("01")
  5483. day := time.Now().Format("02")
  5484. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  5485. file_name := file + ".txt"
  5486. file_path := miConfig.OrgName + "日志" + "/" + file_name
  5487. exist, _ := utils.PathExists(file_path)
  5488. if exist { //存在
  5489. fmt.Println("存在")
  5490. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  5491. if err != nil {
  5492. fmt.Println("read fail")
  5493. }
  5494. content := "\r\n" + result
  5495. n, _ := f.Seek(0, 2)
  5496. _, err = f.WriteAt([]byte(content), n)
  5497. } else { //不存在
  5498. fmt.Println("文件不存在,创建文件")
  5499. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  5500. defer f.Close()
  5501. if err != nil {
  5502. } else {
  5503. _, err = f.Write([]byte("记录日志"))
  5504. }
  5505. }
  5506. }
  5507. func saveLog(result string, request string, infno string) {
  5508. org_id, _ := beego.AppConfig.Int64("org_id")
  5509. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  5510. dir := miConfig.OrgName + "日志"
  5511. utils.Mkdir(dir)
  5512. month := time.Unix(1557042972, 0).Format("1")
  5513. year := time.Now().Format("2006")
  5514. month = time.Now().Format("01")
  5515. day := time.Now().Format("02")
  5516. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  5517. file_name := file + ".txt"
  5518. file_path := miConfig.OrgName + "日志" + "/" + file_name
  5519. exist, _ := utils.PathExists(file_path)
  5520. if exist { //存在
  5521. fmt.Println("存在")
  5522. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  5523. if err != nil {
  5524. fmt.Println("read fail")
  5525. }
  5526. content := infno + "\r\n" + "\r\n" + "\r\n" + "\r\n" + request + "\r\n" + "\r\n" + "\r\n" + "\r\n" + result
  5527. n, _ := f.Seek(0, 2)
  5528. _, err = f.WriteAt([]byte(content), n)
  5529. } else { //不存在
  5530. fmt.Println("文件不存在,创建文件")
  5531. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  5532. defer f.Close()
  5533. if err != nil {
  5534. } else {
  5535. _, err = f.Write([]byte("记录日志"))
  5536. }
  5537. }
  5538. }