his_api_controller.go 232KB

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