his_api_controller.go 268KB

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