his_api_controller.go 234KB

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