his_api_controller.go 233KB

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