his_api_controller.go 212KB

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