his_api_controller.go 236KB

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