his_api_controller.go 236KB

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