his_api_controller.go 234KB

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