his_api_controller.go 233KB

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