his_api_controller.go 211KB

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