his_api_controller.go 235KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796
  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, his.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, his.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), his.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. if pay_way == 4 {
  2355. acct_used_flag = "1"
  2356. } else {
  2357. acct_used_flag = "0"
  2358. }
  2359. if miConfig.MdtrtareaAdmvs == "421300" {
  2360. api := "http://192.168.124.4:9532/" + "hbyb/2207?psn_no=" + his.PsnNo + "&mdtrt_id=" +
  2361. his.Number + "&chrg_bchno=" + chrg_bchno + "&org_name=" + miConfig.OrgName +
  2362. "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2363. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2364. "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(his.IdCardType, 10) +
  2365. "&certificates=" + strconv.FormatInt(his.IdType, 10) + "&cert_no=" + cert_no +
  2366. "&insutype=" + insutype + "&total=" + allTotal + "&med_type=" + strconv.FormatInt(reg_type, 10) + "&acct_used_flag=" + acct_used_flag
  2367. resp, requestErr := http.Get(api)
  2368. if requestErr != nil {
  2369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2370. return
  2371. }
  2372. body, ioErr := ioutil.ReadAll(resp.Body)
  2373. if ioErr != nil {
  2374. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2376. return
  2377. }
  2378. var respJSON map[string]interface{}
  2379. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2380. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2382. return
  2383. }
  2384. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2385. result, _ := json.Marshal(respJSON)
  2386. if err := json.Unmarshal([]byte(result), &res); err != nil {
  2387. utils.ErrorLog("解析失败:%v", err)
  2388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2389. return
  2390. }
  2391. } else {
  2392. result2, src_resquest = service.Gdyb2207(his.PsnNo, his.Number, chrg_bchno, cert_no, insutype, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, his.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, strconv.FormatInt(reg_type, 10), his.IdCardType, 0, 0, 0, 0, his.IdType, acct_used_flag)
  2393. var dat map[string]interface{}
  2394. if err := json.Unmarshal([]byte(result2), &dat); err == nil {
  2395. fmt.Println(dat)
  2396. } else {
  2397. fmt.Println(err)
  2398. }
  2399. saveLog(result2, src_resquest, "2207", "结算")
  2400. userJSONBytes, _ := json.Marshal(dat)
  2401. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2402. utils.ErrorLog("解析失败:%v", err)
  2403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2404. return
  2405. }
  2406. }
  2407. if res.Infcode != 0 {
  2408. errlog := &models.HisOrderError{
  2409. UserOrgId: adminUser.CurrentOrgId,
  2410. Ctime: time.Now().Unix(),
  2411. Mtime: time.Now().Unix(),
  2412. Number: chrg_bchno,
  2413. ErrMsg: res.ErrMsg,
  2414. Status: 1,
  2415. PatientId: id,
  2416. RecordTime: recordDateTime,
  2417. Stage: 6,
  2418. }
  2419. service.CreateErrMsgLog(errlog)
  2420. c.ServeSuccessJSON(map[string]interface{}{
  2421. "failed_code": -10,
  2422. "msg": res.ErrMsg,
  2423. })
  2424. return
  2425. } else {
  2426. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2427. order.OrderStatus = 2
  2428. order.Status = 1
  2429. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2430. order.SetlId = res.Output.Setlinfo.SetlID
  2431. order.PsnNo = res.Output.Setlinfo.PsnNo
  2432. order.PsnName = res.Output.Setlinfo.PsnName
  2433. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2434. order.Certno = res.Output.Setlinfo.Certno
  2435. order.Gend = res.Output.Setlinfo.Gend
  2436. order.Naty = res.Output.Setlinfo.Naty
  2437. order.Age = res.Output.Setlinfo.Age
  2438. order.Insutype = res.Output.Setlinfo.Insutype
  2439. order.PsnType = res.Output.Setlinfo.PsnType
  2440. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2441. order.SetlTime = res.Output.Setlinfo.SetlTime
  2442. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2443. if res.Output.Setlinfo.MedType == "140101" {
  2444. order.MedType = "14"
  2445. } else {
  2446. order.MedType = res.Output.Setlinfo.MedType
  2447. }
  2448. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2449. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2450. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2451. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2452. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2453. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2454. order.HifpPay = res.Output.Setlinfo.HifpPay
  2455. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2456. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2457. order.HifesPay = res.Output.Setlinfo.HifesPay
  2458. order.HifobPay = res.Output.Setlinfo.HifobPay
  2459. order.MafPay = res.Output.Setlinfo.MafPay
  2460. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  2461. order.OthPay = res.Output.Setlinfo.OthPay
  2462. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2463. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2464. order.AcctPay = res.Output.Setlinfo.AcctPay
  2465. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2466. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2467. order.Balc = res.Output.Setlinfo.Balc
  2468. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2469. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2470. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2471. order.ClrWay = res.Output.Setlinfo.ClrWay
  2472. order.Creator = order.Creator
  2473. order.Modify = roles.AdminUserId
  2474. order.RequestLog = src_resquest
  2475. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2476. detailStr := string(setlDetail)
  2477. order.SetlDetail = detailStr
  2478. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2479. err = service.UpDateOrder(order)
  2480. if err == nil {
  2481. c.ServeSuccessJSON(map[string]interface{}{
  2482. "msg": "结算成功",
  2483. })
  2484. } else {
  2485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2486. return
  2487. }
  2488. }
  2489. } else {
  2490. adminUser := c.GetAdminUserInfo()
  2491. errlog := &models.HisOrderError{
  2492. UserOrgId: adminUser.CurrentOrgId,
  2493. Ctime: time.Now().Unix(),
  2494. Mtime: time.Now().Unix(),
  2495. ErrMsg: res.ErrMsg,
  2496. Status: 1,
  2497. PatientId: id,
  2498. RecordTime: recordDateTime,
  2499. Stage: 4,
  2500. }
  2501. service.CreateErrMsgLog(errlog)
  2502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2503. return
  2504. }
  2505. } else {
  2506. adminUser := c.GetAdminUserInfo()
  2507. errlog := &models.HisOrderError{
  2508. UserOrgId: adminUser.CurrentOrgId,
  2509. Ctime: time.Now().Unix(),
  2510. Mtime: time.Now().Unix(),
  2511. ErrMsg: res.ErrMsg,
  2512. Status: 1,
  2513. PatientId: id,
  2514. RecordTime: recordDateTime,
  2515. Stage: 4,
  2516. }
  2517. service.CreateErrMsgLog(errlog)
  2518. c.ServeSuccessJSON(map[string]interface{}{
  2519. "failed_code": -10,
  2520. "msg": res.ErrMsg,
  2521. })
  2522. return
  2523. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  2524. //return
  2525. }
  2526. }
  2527. }
  2528. } else if tempOrder.ID > 0 {
  2529. if tempOrder.IsPre == 1 {
  2530. allTotal := fmt.Sprintf("%.4f", tempOrder.MedfeeSumamt)
  2531. var rf []*ResultFive
  2532. json.Unmarshal([]byte(his.Iinfo), &rf)
  2533. chrg_bchno := tempOrder.Number
  2534. cert_no := his.Certno
  2535. var insutypes []string
  2536. var insutype string
  2537. var is390 int = 0
  2538. var is310 int = 0
  2539. for _, item := range rf {
  2540. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  2541. insutypes = append(insutypes, item.Insutype)
  2542. }
  2543. }
  2544. if len(insutypes) == 1 {
  2545. insutype = insutypes[0]
  2546. } else {
  2547. for _, i := range insutypes {
  2548. if i == "390" {
  2549. is390 = 1
  2550. }
  2551. if i == "310" {
  2552. is310 = 1
  2553. }
  2554. }
  2555. }
  2556. if is390 == 1 {
  2557. insutype = "390"
  2558. }
  2559. if is310 == 1 {
  2560. insutype = "310"
  2561. }
  2562. if len(insutypes) == 0 {
  2563. insutype = "310"
  2564. }
  2565. if len(insutypes) == 2 {
  2566. insutype = strconv.FormatInt(his.SocialType, 64)
  2567. }
  2568. //insutype = "390"
  2569. if his.IdCardType == 1 {
  2570. // cert_no = his.MedicalInsuranceNumber
  2571. cert_no = his.Certno
  2572. } else {
  2573. cert_no = his.Certno
  2574. }
  2575. var res ResultSeven
  2576. var src_resquest string
  2577. var result2 string
  2578. var acct_used_flag string
  2579. if pay_way == 5 {
  2580. acct_used_flag = "1"
  2581. } else {
  2582. acct_used_flag = "0"
  2583. }
  2584. if miConfig.MdtrtareaAdmvs == "421300" {
  2585. api := "http://192.168.124.4:9532/" + "hbyb/2207?psn_no=" + his.PsnNo + "&mdtrt_id=" +
  2586. his.Number + "&chrg_bchno=" + chrg_bchno + "&org_name=" + miConfig.OrgName +
  2587. "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2588. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2589. "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(his.IdCardType, 10) +
  2590. "&certificates=" + strconv.FormatInt(his.IdType, 10) + "&cert_no=" + cert_no +
  2591. "&insutype=" + insutype + "&total=" + allTotal + "&med_type=" + strconv.FormatInt(reg_type, 10) + "&acct_used_flag=" + acct_used_flag
  2592. resp, requestErr := http.Get(api)
  2593. if requestErr != nil {
  2594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2595. return
  2596. }
  2597. body, ioErr := ioutil.ReadAll(resp.Body)
  2598. if ioErr != nil {
  2599. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2601. return
  2602. }
  2603. var respJSON map[string]interface{}
  2604. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2605. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2607. return
  2608. }
  2609. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2610. result, _ := json.Marshal(respJSON)
  2611. fmt.Println("log")
  2612. fmt.Println(string(result))
  2613. if err := json.Unmarshal([]byte(result), &res); err != nil {
  2614. utils.ErrorLog("解析失败:%v", err)
  2615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2616. return
  2617. }
  2618. } else {
  2619. result2, src_resquest = service.Gdyb2207(his.PsnNo, his.Number, chrg_bchno, cert_no, insutype, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, his.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)
  2620. var dat map[string]interface{}
  2621. if err := json.Unmarshal([]byte(result2), &dat); err == nil {
  2622. fmt.Println(dat)
  2623. } else {
  2624. fmt.Println(err)
  2625. }
  2626. saveLog(result2, src_resquest, "2207", "结算")
  2627. userJSONBytes, _ := json.Marshal(dat)
  2628. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2629. utils.ErrorLog("解析失败:%v", err)
  2630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2631. return
  2632. }
  2633. }
  2634. if res.Infcode != 0 {
  2635. errlog := &models.HisOrderError{
  2636. UserOrgId: adminUser.CurrentOrgId,
  2637. Ctime: time.Now().Unix(),
  2638. Mtime: time.Now().Unix(),
  2639. Number: chrg_bchno,
  2640. ErrMsg: res.ErrMsg,
  2641. Status: 1,
  2642. PatientId: id,
  2643. RecordTime: recordDateTime,
  2644. Stage: 6,
  2645. }
  2646. service.CreateErrMsgLog(errlog)
  2647. c.ServeSuccessJSON(map[string]interface{}{
  2648. "failed_code": -10,
  2649. "msg": res.ErrMsg,
  2650. })
  2651. return
  2652. } else {
  2653. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2654. order.OrderStatus = 2
  2655. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2656. order.SetlId = res.Output.Setlinfo.SetlID
  2657. order.PsnNo = res.Output.Setlinfo.PsnNo
  2658. order.PsnName = res.Output.Setlinfo.PsnName
  2659. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2660. order.Certno = res.Output.Setlinfo.Certno
  2661. order.Gend = res.Output.Setlinfo.Gend
  2662. order.Naty = res.Output.Setlinfo.Naty
  2663. order.Age = res.Output.Setlinfo.Age
  2664. order.Insutype = res.Output.Setlinfo.Insutype
  2665. order.PsnType = res.Output.Setlinfo.PsnType
  2666. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2667. order.SetlTime = res.Output.Setlinfo.SetlTime
  2668. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2669. order.MedType = res.Output.Setlinfo.MedType
  2670. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2671. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2672. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2673. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2674. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2675. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2676. order.HifpPay = res.Output.Setlinfo.HifpPay
  2677. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2678. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2679. order.HifesPay = res.Output.Setlinfo.HifesPay
  2680. order.HifobPay = res.Output.Setlinfo.HifobPay
  2681. order.MafPay = res.Output.Setlinfo.MafPay
  2682. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  2683. order.OthPay = res.Output.Setlinfo.OthPay
  2684. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2685. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2686. order.AcctPay = res.Output.Setlinfo.AcctPay
  2687. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2688. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2689. order.Balc = res.Output.Setlinfo.Balc
  2690. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2691. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2692. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2693. order.ClrWay = res.Output.Setlinfo.ClrWay
  2694. order.Creator = order.Creator
  2695. order.Modify = roles.AdminUserId
  2696. order.RequestLog = src_resquest
  2697. order.Diagnosis = diagnosis_id
  2698. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2699. detailStr := string(setlDetail)
  2700. order.SetlDetail = detailStr
  2701. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2702. err = service.UpDateOrder(order)
  2703. if err == nil {
  2704. c.ServeSuccessJSON(map[string]interface{}{
  2705. "msg": "结算成功",
  2706. })
  2707. } else {
  2708. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2709. return
  2710. }
  2711. }
  2712. }
  2713. }
  2714. }
  2715. //func (c *HisApiController) GetPreUploadInfo() {
  2716. // id, _ := c.GetInt64("id")
  2717. // record_time := c.GetString("record_time")
  2718. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2719. // admin_user_id, _ := c.GetInt64("admin_user_id")
  2720. //
  2721. // timeLayout := "2006-01-02"
  2722. // loc, _ := time.LoadLocation("Local")
  2723. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2724. // if err != nil {
  2725. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2726. // return
  2727. // }
  2728. // recordDateTime := theTime.Unix()
  2729. // adminUser := c.GetAdminUserInfo()
  2730. //
  2731. // var prescriptions []*models.HisPrescription
  2732. //
  2733. // var start_time int64
  2734. // var end_time int64
  2735. //
  2736. // data := make(map[string]interface{})
  2737. // if settle_accounts_type == 1 { //日结
  2738. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  2739. // data["pre"] = prescriptions
  2740. //
  2741. // } else { //月结
  2742. // start_time_str := c.GetString("start_time")
  2743. // end_time_str := c.GetString("end_time")
  2744. // timeLayout := "2006-01-02"
  2745. // loc, _ := time.LoadLocation("Local")
  2746. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2747. // if err != nil {
  2748. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2749. // return
  2750. // }
  2751. // recordStartTime := theStartTime.Unix()
  2752. // start_time = recordStartTime
  2753. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2754. // if err != nil {
  2755. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2756. // return
  2757. // }
  2758. // recordEndTime := theEndTime.Unix()
  2759. // end_time = recordEndTime
  2760. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  2761. // data["pre"] = prescriptions
  2762. //
  2763. // }
  2764. //
  2765. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2766. //
  2767. // his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2768. // timestamp := time.Now().Unix()
  2769. // tempTime := time.Unix(timestamp, 0)
  2770. // timeFormat := tempTime.Format("20060102150405")
  2771. // chrgBchno := rand.Intn(100000) + 10000
  2772. // chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  2773. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2774. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2775. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  2776. // strconv.FormatInt(his.PatientId, 10)
  2777. // client := &http.Client{}
  2778. // data["psn_no"] = his.PsnNo
  2779. // data["mdtrt_id"] = his.Number
  2780. // data["chrg_bchno"] = chrg_bchno
  2781. // data["org_name"] = miConfig.OrgName
  2782. // data["doctor"] = roles.UserName
  2783. // data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  2784. // data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  2785. // data["fixmedins_code"] = miConfig.Code
  2786. // data["dept_code"] = department.Number
  2787. // data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  2788. // data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  2789. // data["secret_key"] = miConfig.SecretKey
  2790. // var ids []int64
  2791. //
  2792. // for _, item := range prescriptions {
  2793. // ids = append(ids, item.ID)
  2794. // }
  2795. // config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2796. // if config.IsOpen == 1 { //对接了医保,走医保流程
  2797. // bytesData, _ := json.Marshal(data)
  2798. // req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  2799. // resp, _ := client.Do(req)
  2800. // defer resp.Body.Close()
  2801. // body, ioErr := ioutil.ReadAll(resp.Body)
  2802. // if ioErr != nil {
  2803. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2804. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2805. // return
  2806. // }
  2807. // var respJSON map[string]interface{}
  2808. // if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  2809. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2810. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2811. // return
  2812. // }
  2813. //
  2814. // respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2815. // userJSONBytes, _ := json.Marshal(respJSON)
  2816. // var res ResultFour
  2817. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2818. // utils.ErrorLog("解析失败:%v", err)
  2819. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2820. // return
  2821. // }
  2822. //
  2823. // if res.Infcode == 0 {
  2824. // order := &models.HisOrder{
  2825. // UserOrgId: adminUser.CurrentOrgId,
  2826. // HisPatientId: his.ID,
  2827. // PatientId: his.PatientId,
  2828. // SettleAccountsDate: recordDateTime,
  2829. // Ctime: time.Now().Unix(),
  2830. // Mtime: time.Now().Unix(),
  2831. // Status: 1,
  2832. // Number: chrg_bchno,
  2833. // Infcode: res.Infcode,
  2834. // WarnMsg: res.WarnMsg,
  2835. // Cainfo: res.Cainfo,
  2836. // ErrMsg: res.ErrMsg,
  2837. // RespondTime: res.RefmsgTime,
  2838. // InfRefmsgid: res.InfRefmsgid,
  2839. // OrderStatus: 1,
  2840. // IsMedicineInsurance: 1,
  2841. // SettleType: settle_accounts_type,
  2842. // SettleStartTime: start_time,
  2843. // SettleEndTime: end_time,
  2844. // Creator: roles.ID,
  2845. // Modify: roles.ID,
  2846. // PType: 2,
  2847. // }
  2848. // err = service.CreateOrder(order)
  2849. // if err != nil {
  2850. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2851. // return
  2852. // }
  2853. //
  2854. // for _, item := range res.Output.Result {
  2855. // temp := strings.Split(item.FeedetlSn, "-")
  2856. // var advice_id int64 = 0
  2857. // var project_id int64 = 0
  2858. // var types int64 = 0
  2859. //
  2860. // id, _ := strconv.ParseInt(temp[2], 10, 64)
  2861. // types, _ = strconv.ParseInt(temp[1], 10, 64)
  2862. //
  2863. // if temp[1] == "1" {
  2864. // advice_id = id
  2865. // project_id = 0
  2866. // } else if temp[1] == "2" {
  2867. // advice_id = 0
  2868. // project_id = id
  2869. // }
  2870. //
  2871. // info := &models.HisOrderInfo{
  2872. // OrderNumber: order.Number,
  2873. // FeedetlSn: item.FeedetlSn,
  2874. // UploadDate: time.Now().Unix(),
  2875. // AdviceId: advice_id,
  2876. // DetItemFeeSumamt: item.DetItemFeeSumamt,
  2877. // Cnt: item.Cnt,
  2878. // Pric: float64(item.Pric),
  2879. // PatientId: his.PatientId,
  2880. // PricUplmtAmt: item.PricUplmtAmt,
  2881. // SelfpayProp: item.SelfpayProp,
  2882. // FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2883. // OverlmtAmt: item.OverlmtAmt,
  2884. // PreselfpayAmt: item.PreselfpayAmt,
  2885. // BasMednFlag: item.BasMednFlag,
  2886. // MedChrgitmType: item.MedChrgitmType,
  2887. // HiNegoDrugFlag: item.HiNegoDrugFlag,
  2888. // Status: 1,
  2889. // Memo: item.Memo,
  2890. // Mtime: time.Now().Unix(),
  2891. // InscpScpAmt: item.InscpScpAmt,
  2892. // DrtReimFlag: item.DrtReimFlag,
  2893. // Ctime: time.Now().Unix(),
  2894. // ListSpItemFlag: item.ListSpItemFlag,
  2895. // ChldMedcFlag: item.ChldMedcFlag,
  2896. // LmtUsedFlag: item.LmtUsedFlag,
  2897. // ChrgitmLv: item.ChrgitmLv,
  2898. // UserOrgId: adminUser.CurrentOrgId,
  2899. // HisPatientId: his.ID,
  2900. // OrderId: order.ID,
  2901. // ProjectId: project_id,
  2902. // Type: types,
  2903. // }
  2904. // service.CreateOrderInfo(info)
  2905. //
  2906. // }
  2907. // service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2908. // service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  2909. //
  2910. // var total float64
  2911. // for _, item := range prescriptions {
  2912. // if item.Type == 1 { //药品
  2913. // for _, subItem := range item.HisDoctorAdviceInfo {
  2914. // total = total + (subItem.Price * subItem.PrescribingNumber)
  2915. // }
  2916. // }
  2917. // if item.Type == 2 { //项目
  2918. // for _, subItem := range item.HisPrescriptionProject {
  2919. // total = total + (subItem.Price * float64(subItem.Count))
  2920. // }
  2921. // }
  2922. // }
  2923. //
  2924. // for _, item := range prescriptions {
  2925. // for _, subItem := range item.HisAdditionalCharge {
  2926. // total = total + (subItem.Price * float64(subItem.Count))
  2927. // }
  2928. // }
  2929. //
  2930. // allTotal := fmt.Sprintf("%.2f", total)
  2931. // if res.Infcode == 0 {
  2932. // var rf []*ResultFive
  2933. // json.Unmarshal([]byte(his.Iinfo), &rf)
  2934. // psn_no := his.PsnNo
  2935. // mdtrt_id := his.Number
  2936. // chrg_bchno := chrg_bchno
  2937. // cert_no := his.Certno
  2938. // insutype := rf[0].Insutype
  2939. //
  2940. // if his.IdCardType == 1 {
  2941. // cert_no = his.MedicalInsuranceNumber
  2942. //
  2943. // } else {
  2944. //
  2945. // cert_no = his.Certno
  2946. //
  2947. // }
  2948. //
  2949. // api := "http://127.0.0.1:9532/" + "gdyb/seven?cert_no=" + cert_no + "&insutype=" +
  2950. // insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  2951. // "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  2952. // miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10)
  2953. // resp, requestErr := http.Get(api)
  2954. // if requestErr != nil {
  2955. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2956. // return
  2957. // }
  2958. // defer resp.Body.Close()
  2959. // body, ioErr := ioutil.ReadAll(resp.Body)
  2960. // if ioErr != nil {
  2961. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2962. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2963. // return
  2964. // }
  2965. // var respJSON map[string]interface{}
  2966. // if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2967. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2968. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2969. // return
  2970. // }
  2971. // fmt.Println(respJSON)
  2972. // respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2973. // userJSONBytes, _ := json.Marshal(respJSON)
  2974. // var res ResultSeven
  2975. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2976. // utils.ErrorLog("解析失败:%v", err)
  2977. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2978. // return
  2979. // }
  2980. // if res.Infcode != 0 {
  2981. // errlog := &models.HisOrderError{
  2982. // UserOrgId: adminUser.CurrentOrgId,
  2983. // Ctime: time.Now().Unix(),
  2984. // Mtime: time.Now().Unix(),
  2985. // Number: chrg_bchno,
  2986. // ErrMsg: res.ErrMsg,
  2987. // Status: 1,
  2988. // PatientId: id,
  2989. // RecordTime: recordDateTime,
  2990. // Stage: 7,
  2991. // }
  2992. // service.CreateErrMsgLog(errlog)
  2993. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2994. // return
  2995. // } else {
  2996. // order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2997. // order.OrderStatus = 1
  2998. // order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2999. // order.SetlId = res.Output.Setlinfo.SetlID
  3000. // order.PsnNo = res.Output.Setlinfo.PsnNo
  3001. // order.PsnName = res.Output.Setlinfo.PsnName
  3002. // order.PsnCertType = res.Output.Setlinfo.PsnCertType
  3003. // order.Certno = res.Output.Setlinfo.Certno
  3004. // order.Gend = res.Output.Setlinfo.Gend
  3005. // order.Naty = res.Output.Setlinfo.Naty
  3006. // order.Age = res.Output.Setlinfo.Age
  3007. // order.Insutype = res.Output.Setlinfo.Insutype
  3008. // order.PsnType = res.Output.Setlinfo.PsnType
  3009. // order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  3010. // order.SetlTime = res.Output.Setlinfo.SetlTime
  3011. // order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  3012. // order.MedType = res.Output.Setlinfo.MedType
  3013. // order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  3014. // order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  3015. // order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  3016. // order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  3017. // order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  3018. // order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  3019. // order.HifpPay = res.Output.Setlinfo.HifpPay
  3020. // order.CvlservPay = res.Output.Setlinfo.CvlservPay
  3021. // order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  3022. // order.HifesPay = res.Output.Setlinfo.HifesPay
  3023. // order.HifobPay = res.Output.Setlinfo.HifobPay
  3024. // order.MafPay = res.Output.Setlinfo.MafPay
  3025. // order.OthPay = res.Output.Setlinfo.OthPay
  3026. // order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  3027. // order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  3028. // order.AcctPay = res.Output.Setlinfo.AcctPay
  3029. // order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  3030. // order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  3031. // order.Balc = res.Output.Setlinfo.Balc
  3032. // order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  3033. // order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  3034. // order.ClrOptins = res.Output.Setlinfo.ClrOptins
  3035. // order.ClrWay = res.Output.Setlinfo.ClrWay
  3036. // order.Creator = order.Creator
  3037. // order.Modify = roles.ID
  3038. // setlDetail, _ := json.Marshal(res.Output.Setldetail)
  3039. // detailStr := string(setlDetail)
  3040. // order.SetlDetail = detailStr
  3041. // //err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  3042. // err = service.UpDateOrder(order)
  3043. // if err == nil {
  3044. // c.ServeSuccessJSON(map[string]interface{}{
  3045. // "msg": "预结算成功",
  3046. // })
  3047. // } else {
  3048. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  3049. // return
  3050. // }
  3051. // }
  3052. // } else {
  3053. // adminUser := c.GetAdminUserInfo()
  3054. // errlog := &models.HisOrderError{
  3055. // UserOrgId: adminUser.CurrentOrgId,
  3056. // Ctime: time.Now().Unix(),
  3057. // Mtime: time.Now().Unix(),
  3058. // ErrMsg: res.ErrMsg,
  3059. // Status: 1,
  3060. // PatientId: id,
  3061. // RecordTime: recordDateTime,
  3062. // Stage: 4,
  3063. // }
  3064. // service.CreateErrMsgLog(errlog)
  3065. //
  3066. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  3067. // return
  3068. // }
  3069. // } else {
  3070. // adminUser := c.GetAdminUserInfo()
  3071. // errlog := &models.HisOrderError{
  3072. // UserOrgId: adminUser.CurrentOrgId,
  3073. // Ctime: time.Now().Unix(),
  3074. // Mtime: time.Now().Unix(),
  3075. // ErrMsg: res.ErrMsg,
  3076. // Status: 1,
  3077. // PatientId: id,
  3078. // RecordTime: recordDateTime,
  3079. // Stage: 4,
  3080. // }
  3081. // service.CreateErrMsgLog(errlog)
  3082. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  3083. // return
  3084. // }
  3085. //
  3086. // } else {
  3087. // var total float64
  3088. // for _, item := range prescriptions {
  3089. // if item.Type == 1 { //药品
  3090. // for _, subItem := range item.HisDoctorAdviceInfo {
  3091. // total = total + (subItem.Price * subItem.PrescribingNumber)
  3092. // }
  3093. // }
  3094. // if item.Type == 2 { //项目
  3095. // for _, subItem := range item.HisPrescriptionProject {
  3096. // total = total + (subItem.Price * float64(subItem.Count))
  3097. // }
  3098. // }
  3099. //
  3100. // for _, subItem := range item.HisAdditionalCharge {
  3101. // total = total + (subItem.Price * float64(subItem.Count))
  3102. // }
  3103. // }
  3104. //
  3105. // allTotal := fmt.Sprintf("%.2f", total)
  3106. // totals, _ := strconv.ParseFloat(allTotal, 64)
  3107. // order := &models.HisOrder{
  3108. // UserOrgId: adminUser.CurrentOrgId,
  3109. // HisPatientId: his.ID,
  3110. // PatientId: id,
  3111. // SettleAccountsDate: recordDateTime,
  3112. // Ctime: time.Now().Unix(),
  3113. // Mtime: time.Now().Unix(),
  3114. // Status: 1,
  3115. // OrderStatus: 2,
  3116. // Number: chrg_bchno,
  3117. // MedfeeSumamt: totals,
  3118. // }
  3119. // err = service.CreateOrder(order)
  3120. // if err != nil {
  3121. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  3122. // return
  3123. // }
  3124. //
  3125. // var customs []*Custom
  3126. // for _, item := range prescriptions {
  3127. //
  3128. // if item.Type == 1 { //药品
  3129. // for _, subItem := range item.HisDoctorAdviceInfo {
  3130. // cus := &Custom{
  3131. // AdviceId: subItem.ID,
  3132. // ProjectId: 0,
  3133. // DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  3134. // Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  3135. // FeedetlSn: subItem.FeedetlSn,
  3136. // Price: fmt.Sprintf("%.2f", subItem.Price),
  3137. // MedListCodg: subItem.MedListCodg,
  3138. // Type: 1,
  3139. // }
  3140. // customs = append(customs, cus)
  3141. // }
  3142. // }
  3143. //
  3144. // if item.Type == 2 { //项目
  3145. // for _, subItem := range item.HisPrescriptionProject {
  3146. //
  3147. // cus := &Custom{
  3148. // AdviceId: 0,
  3149. // ProjectId: subItem.ID,
  3150. // DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  3151. // Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  3152. // FeedetlSn: subItem.FeedetlSn,
  3153. // Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  3154. // MedListCodg: subItem.MedListCodg,
  3155. // Type: 2,
  3156. // }
  3157. //
  3158. // customs = append(customs, cus)
  3159. // }
  3160. // }
  3161. //
  3162. // for _, item := range item.HisAdditionalCharge {
  3163. // cus := &Custom{
  3164. // ItemId: item.ID,
  3165. // AdviceId: 0,
  3166. // ProjectId: 0,
  3167. // DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  3168. // Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  3169. // FeedetlSn: item.FeedetlSn,
  3170. // Price: fmt.Sprintf("%.2f", float64(item.Price)),
  3171. // MedListCodg: item.XtHisAddtionConfig.Code,
  3172. // Type: 3,
  3173. // }
  3174. //
  3175. // customs = append(customs, cus)
  3176. // }
  3177. //
  3178. // }
  3179. //
  3180. // for _, item := range customs {
  3181. // var advice_id int64 = 0
  3182. // var project_id int64 = 0
  3183. // var item_id int64 = 0
  3184. //
  3185. // var types int64 = 0
  3186. //
  3187. // if item.Type == 1 {
  3188. // advice_id = item.AdviceId
  3189. // project_id = 0
  3190. // item_id = 0
  3191. // } else if item.Type == 2 {
  3192. // advice_id = 0
  3193. // item_id = 0
  3194. //
  3195. // project_id = item.ProjectId
  3196. // } else if item.Type == 3 {
  3197. // advice_id = 0
  3198. // item_id = item.ItemId
  3199. // project_id = 0
  3200. // }
  3201. //
  3202. // detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  3203. // cut, _ := strconv.ParseFloat(item.Cut, 32)
  3204. // pric, _ := strconv.ParseFloat(item.Price, 32)
  3205. //
  3206. // info := &models.HisOrderInfo{
  3207. // OrderNumber: order.Number,
  3208. // UploadDate: time.Now().Unix(),
  3209. // AdviceId: advice_id,
  3210. // DetItemFeeSumamt: detItemFeeSumamt,
  3211. // Cnt: cut,
  3212. // Pric: pric,
  3213. // PatientId: id,
  3214. // Status: 1,
  3215. // Mtime: time.Now().Unix(),
  3216. // Ctime: time.Now().Unix(),
  3217. // UserOrgId: adminUser.CurrentOrgId,
  3218. // HisPatientId: his.ID,
  3219. // OrderId: order.ID,
  3220. // ProjectId: project_id,
  3221. // Type: types,
  3222. // ItemId: item_id,
  3223. // }
  3224. // service.CreateOrderInfo(info)
  3225. // }
  3226. // //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  3227. // err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  3228. // err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  3229. // err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  3230. // if err == nil {
  3231. // c.ServeSuccessJSON(map[string]interface{}{
  3232. // "msg": "结算成功",
  3233. // })
  3234. // } else {
  3235. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  3236. // return
  3237. // }
  3238. // }
  3239. //}
  3240. //上传明细-预结算-
  3241. func (c *HisApiController) GetPreUploadInfo() {
  3242. id, _ := c.GetInt64("id")
  3243. record_time := c.GetString("record_time")
  3244. his_patient_id, _ := c.GetInt64("his_patient_id")
  3245. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  3246. admin_user_id, _ := c.GetInt64("admin_user_id")
  3247. diagnosis_id := c.GetString("diagnosis")
  3248. sick_type, _ := c.GetInt64("sick_type")
  3249. reg_type, _ := c.GetInt64("p_type")
  3250. id_str := c.GetString("ids")
  3251. ids_arr := strings.Split(id_str, ",")
  3252. timeLayout := "2006-01-02"
  3253. loc, _ := time.LoadLocation("Local")
  3254. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3255. if err != nil {
  3256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3257. return
  3258. }
  3259. recordDateTime := theTime.Unix()
  3260. adminUser := c.GetAdminUserInfo()
  3261. diagnosis_ids := strings.Split(diagnosis_id, ",")
  3262. var config []*models.HisXtDiagnoseConfig
  3263. for _, item := range diagnosis_ids {
  3264. id, _ := strconv.ParseInt(item, 10, 64)
  3265. diagnosisConfig, _ := service.FindDiagnoseById(id)
  3266. config = append(config, &diagnosisConfig)
  3267. }
  3268. //diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  3269. sickConfig, _ := service.FindSickById(sick_type)
  3270. var prescriptions []*models.HisPrescription
  3271. var start_time int64
  3272. var end_time int64
  3273. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3274. fmt.Println(his_patient_id)
  3275. his, _ := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  3276. timestamp := time.Now().Unix()
  3277. tempTime := time.Unix(timestamp, 0)
  3278. timeFormat := tempTime.Format("20060102150405")
  3279. chrgBchno := rand.Intn(100000) + 10000
  3280. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  3281. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3282. var patientPrescription models.HisPrescriptionInfo
  3283. patientPrescription, _ = service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  3284. if patientPrescription.ID == 0 {
  3285. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  3286. }
  3287. //miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3288. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  3289. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  3290. strconv.FormatInt(his.PatientId, 10)
  3291. var res2 ResultSix
  3292. if miConfig.InsuplcAdmdvs == "421300" {
  3293. data := make(map[string]interface{})
  3294. client := &http.Client{}
  3295. data["psn_no"] = his.PsnNo
  3296. data["mdtrt_id"] = his.Number
  3297. data["doctor"] = roles.UserName
  3298. data["department"] = department.Name
  3299. data["org_name"] = miConfig.OrgName
  3300. data["med_type"] = strconv.FormatInt(reg_type, 10)
  3301. data["doctor_id"] = strconv.FormatInt(doctor_info.AdminUserId, 10)
  3302. data["fixmedins_code"] = miConfig.Code
  3303. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  3304. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  3305. data["secret_key"] = miConfig.SecretKey
  3306. data["sick_code"] = sickConfig.CountryCode
  3307. data["sick_name"] = sickConfig.ClassName
  3308. data["dept"] = strconv.FormatInt(department.ID, 10)
  3309. data["config"] = config
  3310. fmt.Println(data)
  3311. bytesData, _ := json.Marshal(data)
  3312. req, _ := http.NewRequest("POST", "http://192.168.124.4:9532/"+"hbyb/2203", bytes.NewReader(bytesData))
  3313. resp, _ := client.Do(req)
  3314. defer resp.Body.Close()
  3315. body, ioErr := ioutil.ReadAll(resp.Body)
  3316. if ioErr != nil {
  3317. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3319. return
  3320. }
  3321. var respJSON map[string]interface{}
  3322. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  3323. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3325. return
  3326. }
  3327. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3328. userJSONBytes, _ := json.Marshal(respJSON)
  3329. fmt.Println("log")
  3330. fmt.Println(string(userJSONBytes))
  3331. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  3332. utils.ErrorLog("解析失败:%v", err)
  3333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3334. return
  3335. }
  3336. } else {
  3337. var result string
  3338. var requestLog string
  3339. if miConfig.InsuplcAdmdvs == "440781" { //
  3340. 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)
  3341. } else {
  3342. 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)
  3343. saveLog(result, requestLog, "2203", "上传就诊信息")
  3344. var respJSON2 map[string]interface{}
  3345. if err := json.Unmarshal([]byte(string(result)), &respJSON2); err != nil {
  3346. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3347. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3348. return
  3349. }
  3350. userJSONBytes2, _ := json.Marshal(respJSON2)
  3351. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  3352. utils.ErrorLog("解析失败:%v", err)
  3353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3354. return
  3355. }
  3356. }
  3357. }
  3358. if res2.Infcode != 0 {
  3359. adminUser := c.GetAdminUserInfo()
  3360. errlog := &models.HisOrderError{
  3361. UserOrgId: adminUser.CurrentOrgId,
  3362. Ctime: time.Now().Unix(),
  3363. Mtime: time.Now().Unix(),
  3364. ErrMsg: res2.ErrMsg,
  3365. Status: 1,
  3366. PatientId: id,
  3367. RecordTime: recordDateTime,
  3368. Stage: 3,
  3369. }
  3370. service.CreateErrMsgLog(errlog)
  3371. c.ServeSuccessJSON(map[string]interface{}{
  3372. "failed_code": -10,
  3373. "msg": res2.ErrMsg,
  3374. })
  3375. return
  3376. } else {
  3377. his.Diagnosis = diagnosis_id
  3378. his.SickType = sickConfig.ID
  3379. his.PType = fmt.Sprintf("%d", reg_type)
  3380. service.UpdateHisPatientThree(&his)
  3381. data := make(map[string]interface{})
  3382. if settle_accounts_type == 1 { //日结
  3383. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  3384. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  3385. } else {
  3386. prescriptions, _ = service.GetNewHisPrescription(adminUser.CurrentOrgId, his_patient_id, recordDateTime, strconv.Itoa(int(reg_type)))
  3387. }
  3388. data["pre"] = prescriptions
  3389. } else { //月结
  3390. start_time_str := c.GetString("start_time")
  3391. end_time_str := c.GetString("end_time")
  3392. timeLayout := "2006-01-02"
  3393. loc, _ := time.LoadLocation("Local")
  3394. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3395. if err != nil {
  3396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3397. return
  3398. }
  3399. recordStartTime := theStartTime.Unix()
  3400. start_time = recordStartTime
  3401. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3402. if err != nil {
  3403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3404. return
  3405. }
  3406. recordEndTime := theEndTime.Unix()
  3407. end_time = recordEndTime
  3408. prescriptions, _ = service.GetMonthHisPrescriptionTwo(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  3409. data["pre"] = prescriptions
  3410. }
  3411. client := &http.Client{}
  3412. data["psn_no"] = his.PsnNo
  3413. data["mdtrt_id"] = his.Number
  3414. data["chrg_bchno"] = chrg_bchno
  3415. data["org_name"] = miConfig.OrgName
  3416. data["doctor"] = roles.UserName
  3417. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  3418. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  3419. data["fixmedins_code"] = miConfig.Code
  3420. data["balance_accounts_type"] = strconv.FormatInt(his.BalanceAccountsType, 10)
  3421. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  3422. data["dept_code"] = "15"
  3423. } else {
  3424. data["dept_code"] = department.Number
  3425. }
  3426. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  3427. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  3428. data["secret_key"] = miConfig.SecretKey
  3429. var ids []int64
  3430. for _, item := range prescriptions {
  3431. ids = append(ids, item.ID)
  3432. }
  3433. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3434. if config.IsOpen == 1 { //对接了医保,走医保流程
  3435. var res ResultFour
  3436. if miConfig.MdtrtareaAdmvs == "421300" {
  3437. bytesData, _ := json.Marshal(data)
  3438. req, _ := http.NewRequest("POST", "http://192.168.124.4:9532/"+"hbyb/2204", bytes.NewReader(bytesData))
  3439. resp, _ := client.Do(req)
  3440. defer resp.Body.Close()
  3441. body, ioErr := ioutil.ReadAll(resp.Body)
  3442. if ioErr != nil {
  3443. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3445. return
  3446. }
  3447. var respJSON map[string]interface{}
  3448. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  3449. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3451. return
  3452. }
  3453. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3454. userJSONBytes, _ := json.Marshal(respJSON)
  3455. fmt.Println("log")
  3456. fmt.Println(string(userJSONBytes))
  3457. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3458. utils.ErrorLog("解析失败:%v", err)
  3459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3460. return
  3461. }
  3462. } else {
  3463. 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))
  3464. var dat map[string]interface{}
  3465. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3466. fmt.Println(dat)
  3467. } else {
  3468. fmt.Println(err)
  3469. }
  3470. saveLog(result, request_log, "2204", "上传费用明细")
  3471. userJSONBytes, _ := json.Marshal(dat)
  3472. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3473. utils.ErrorLog("解析失败:%v", err)
  3474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3475. return
  3476. }
  3477. }
  3478. if res.Infcode == 0 {
  3479. order := &models.HisOrder{
  3480. UserOrgId: adminUser.CurrentOrgId,
  3481. HisPatientId: his.ID,
  3482. PatientId: his.PatientId,
  3483. SettleAccountsDate: recordDateTime,
  3484. Ctime: time.Now().Unix(),
  3485. Mtime: time.Now().Unix(),
  3486. Status: 1,
  3487. Number: chrg_bchno,
  3488. Infcode: res.Infcode,
  3489. WarnMsg: res.WarnMsg,
  3490. Cainfo: res.Cainfo,
  3491. ErrMsg: res.ErrMsg,
  3492. RespondTime: res.RefmsgTime,
  3493. InfRefmsgid: res.InfRefmsgid,
  3494. OrderStatus: 1,
  3495. IsMedicineInsurance: 1,
  3496. SettleType: settle_accounts_type,
  3497. SettleStartTime: start_time,
  3498. SettleEndTime: end_time,
  3499. Creator: roles.AdminUserId,
  3500. Modify: roles.AdminUserId,
  3501. PType: 2,
  3502. Diagnosis: diagnosis_id,
  3503. }
  3504. err = service.CreateOrder(order)
  3505. if err != nil {
  3506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  3507. return
  3508. }
  3509. for _, item := range res.Output.Result {
  3510. temp := strings.Split(item.FeedetlSn, "-")
  3511. var advice_id int64 = 0
  3512. var project_id int64 = 0
  3513. var types int64 = 0
  3514. id, _ := strconv.ParseInt(temp[2], 10, 64)
  3515. types, _ = strconv.ParseInt(temp[1], 10, 64)
  3516. if temp[1] == "1" {
  3517. advice_id = id
  3518. project_id = 0
  3519. } else if temp[1] == "2" {
  3520. advice_id = 0
  3521. project_id = id
  3522. }
  3523. info := &models.HisOrderInfo{
  3524. OrderNumber: order.Number,
  3525. FeedetlSn: item.FeedetlSn,
  3526. UploadDate: time.Now().Unix(),
  3527. AdviceId: advice_id,
  3528. DetItemFeeSumamt: item.DetItemFeeSumamt,
  3529. Cnt: item.Cnt,
  3530. Pric: float64(item.Pric),
  3531. PatientId: his.PatientId,
  3532. PricUplmtAmt: item.PricUplmtAmt,
  3533. SelfpayProp: item.SelfpayProp,
  3534. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  3535. OverlmtAmt: item.OverlmtAmt,
  3536. PreselfpayAmt: item.PreselfpayAmt,
  3537. BasMednFlag: item.BasMednFlag,
  3538. MedChrgitmType: item.MedChrgitmType,
  3539. HiNegoDrugFlag: item.HiNegoDrugFlag,
  3540. Status: 1,
  3541. Memo: item.Memo,
  3542. Mtime: time.Now().Unix(),
  3543. InscpScpAmt: item.InscpScpAmt,
  3544. DrtReimFlag: item.DrtReimFlag,
  3545. Ctime: time.Now().Unix(),
  3546. ListSpItemFlag: item.ListSpItemFlag,
  3547. ChldMedcFlag: item.ChldMedcFlag,
  3548. LmtUsedFlag: item.LmtUsedFlag,
  3549. ChrgitmLv: item.ChrgitmLv,
  3550. UserOrgId: adminUser.CurrentOrgId,
  3551. HisPatientId: his.ID,
  3552. OrderId: order.ID,
  3553. ProjectId: project_id,
  3554. Type: types,
  3555. }
  3556. service.CreateOrderInfo(info)
  3557. }
  3558. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  3559. service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, his_patient_id, chrg_bchno, recordDateTime)
  3560. var total float64
  3561. for _, item := range prescriptions {
  3562. if item.Type == 1 { //药品
  3563. for _, subItem := range item.HisDoctorAdviceInfo {
  3564. total = total + (subItem.Price * subItem.PrescribingNumber)
  3565. }
  3566. }
  3567. if item.Type == 2 { //项目
  3568. for _, subItem := range item.HisPrescriptionProject {
  3569. total = total + (subItem.Price * float64(subItem.Count))
  3570. }
  3571. }
  3572. }
  3573. for _, item := range prescriptions {
  3574. for _, subItem := range item.HisAdditionalCharge {
  3575. total = total + (subItem.Price * float64(subItem.Count))
  3576. }
  3577. }
  3578. allTotal := fmt.Sprintf("%.4f", total)
  3579. if res.Infcode == 0 {
  3580. var rf []*ResultFive
  3581. json.Unmarshal([]byte(his.Iinfo), &rf)
  3582. chrg_bchno := chrg_bchno
  3583. cert_no := his.Certno
  3584. var insutypes []string
  3585. var insutype string
  3586. var is390 int = 0
  3587. var is310 int = 0
  3588. for _, item := range rf {
  3589. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  3590. insutypes = append(insutypes, item.Insutype)
  3591. }
  3592. }
  3593. if len(insutypes) == 1 {
  3594. insutype = insutypes[0]
  3595. } else {
  3596. for _, i := range insutypes {
  3597. if i == "390" {
  3598. is390 = 1
  3599. }
  3600. if i == "310" {
  3601. is310 = 1
  3602. }
  3603. }
  3604. }
  3605. if is390 == 1 {
  3606. insutype = "390"
  3607. }
  3608. if is310 == 1 {
  3609. insutype = "310"
  3610. }
  3611. if len(insutypes) == 0 {
  3612. insutype = "310"
  3613. }
  3614. if len(insutypes) == 2 {
  3615. insutype = strconv.FormatInt(his.SocialType, 64)
  3616. }
  3617. //insutype = "390"
  3618. if his.IdCardType == 1 {
  3619. cert_no = his.MedicalInsuranceNumber
  3620. } else {
  3621. cert_no = his.Certno
  3622. }
  3623. var res ResultSeven
  3624. if miConfig.MdtrtareaAdmvs == "421300" {
  3625. api := "http://192.168.124.4:9532/" + "hbyb/2206?psn_no=" + his.PsnNo + "&mdtrt_id=" +
  3626. his.Number + "&chrg_bchno=" + chrg_bchno + "&org_name=" + miConfig.OrgName +
  3627. "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  3628. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3629. "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(his.IdCardType, 10) +
  3630. "&certificates=" + strconv.FormatInt(his.IdType, 10) + "&cert_no=" + cert_no +
  3631. "&insutype=" + insutype + "&total=" + allTotal + "&med_type=" + strconv.FormatInt(reg_type, 10)
  3632. resp, requestErr := http.Get(api)
  3633. if requestErr != nil {
  3634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3635. return
  3636. }
  3637. body, ioErr := ioutil.ReadAll(resp.Body)
  3638. if ioErr != nil {
  3639. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3641. return
  3642. }
  3643. var respJSON map[string]interface{}
  3644. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3645. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3647. return
  3648. }
  3649. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3650. result, _ := json.Marshal(respJSON)
  3651. fmt.Println("log")
  3652. fmt.Println(string(result))
  3653. if err := json.Unmarshal([]byte(result), &res); err != nil {
  3654. utils.ErrorLog("解析失败:%v", err)
  3655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3656. return
  3657. }
  3658. } else {
  3659. 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)
  3660. var dat map[string]interface{}
  3661. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3662. fmt.Println(dat)
  3663. } else {
  3664. fmt.Println(err)
  3665. }
  3666. saveLog(result, request_log, "2206", "预结算")
  3667. userJSONBytes, _ := json.Marshal(dat)
  3668. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3669. utils.ErrorLog("解析失败:%v", err)
  3670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3671. return
  3672. }
  3673. }
  3674. if res.Infcode != 0 {
  3675. errlog := &models.HisOrderError{
  3676. UserOrgId: adminUser.CurrentOrgId,
  3677. Ctime: time.Now().Unix(),
  3678. Mtime: time.Now().Unix(),
  3679. Number: chrg_bchno,
  3680. ErrMsg: res.ErrMsg,
  3681. Status: 1,
  3682. PatientId: id,
  3683. RecordTime: recordDateTime,
  3684. Stage: 20,
  3685. }
  3686. service.CreateErrMsgLog(errlog)
  3687. c.ServeSuccessJSON(map[string]interface{}{
  3688. "failed_code": -10,
  3689. "msg": res.ErrMsg,
  3690. })
  3691. return
  3692. } else {
  3693. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  3694. order.OrderStatus = 1
  3695. order.IsPre = 1
  3696. order.Status = 1
  3697. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  3698. order.SetlId = res.Output.Setlinfo.SetlID
  3699. order.PsnNo = res.Output.Setlinfo.PsnNo
  3700. order.PsnName = res.Output.Setlinfo.PsnName
  3701. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  3702. order.Certno = res.Output.Setlinfo.Certno
  3703. order.Gend = res.Output.Setlinfo.Gend
  3704. order.Naty = res.Output.Setlinfo.Naty
  3705. order.Age = res.Output.Setlinfo.Age
  3706. order.Insutype = res.Output.Setlinfo.Insutype
  3707. order.PsnType = res.Output.Setlinfo.PsnType
  3708. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  3709. order.SetlTime = res.Output.Setlinfo.SetlTime
  3710. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  3711. if res.Output.Setlinfo.MedType == "140101" {
  3712. order.MedType = "14"
  3713. } else {
  3714. order.MedType = res.Output.Setlinfo.MedType
  3715. }
  3716. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  3717. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  3718. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  3719. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  3720. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  3721. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  3722. order.HifpPay = res.Output.Setlinfo.HifpPay
  3723. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  3724. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  3725. order.HifesPay = res.Output.Setlinfo.HifesPay
  3726. order.HifobPay = res.Output.Setlinfo.HifobPay
  3727. order.MafPay = res.Output.Setlinfo.MafPay
  3728. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  3729. order.OthPay = res.Output.Setlinfo.OthPay
  3730. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  3731. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  3732. order.AcctPay = res.Output.Setlinfo.AcctPay
  3733. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  3734. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  3735. order.Balc = res.Output.Setlinfo.Balc
  3736. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  3737. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  3738. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  3739. order.ClrWay = res.Output.Setlinfo.ClrWay
  3740. order.Creator = order.Creator
  3741. order.Modify = roles.AdminUserId
  3742. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  3743. detailStr := string(setlDetail)
  3744. order.SetlDetail = detailStr
  3745. //err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  3746. err = service.UpDateOrder(order)
  3747. if err == nil {
  3748. c.ServeSuccessJSON(map[string]interface{}{
  3749. "msg": "预结算成功",
  3750. })
  3751. } else {
  3752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  3753. return
  3754. }
  3755. }
  3756. } else {
  3757. adminUser := c.GetAdminUserInfo()
  3758. errlog := &models.HisOrderError{
  3759. UserOrgId: adminUser.CurrentOrgId,
  3760. Ctime: time.Now().Unix(),
  3761. Mtime: time.Now().Unix(),
  3762. ErrMsg: res.ErrMsg,
  3763. Status: 1,
  3764. PatientId: id,
  3765. RecordTime: recordDateTime,
  3766. Stage: 4,
  3767. }
  3768. service.CreateErrMsgLog(errlog)
  3769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  3770. return
  3771. }
  3772. } else {
  3773. adminUser := c.GetAdminUserInfo()
  3774. errlog := &models.HisOrderError{
  3775. UserOrgId: adminUser.CurrentOrgId,
  3776. Ctime: time.Now().Unix(),
  3777. Mtime: time.Now().Unix(),
  3778. ErrMsg: res.ErrMsg,
  3779. Status: 1,
  3780. PatientId: id,
  3781. RecordTime: recordDateTime,
  3782. Stage: 4,
  3783. }
  3784. service.CreateErrMsgLog(errlog)
  3785. c.ServeSuccessJSON(map[string]interface{}{
  3786. "failed_code": -10,
  3787. "msg": res.ErrMsg,
  3788. })
  3789. return
  3790. }
  3791. }
  3792. }
  3793. }
  3794. //func (c *HisApiController) GetSettleInfo() {
  3795. // id, _ := c.GetInt64("id")
  3796. // order_id, _ := c.GetInt64("order_id")
  3797. //
  3798. // record_time := c.GetString("record_time")
  3799. // pay_way, _ := c.GetInt64("pay_way")
  3800. // pay_price, _ := c.GetFloat("pay_price")
  3801. // pay_card_no := c.GetString("pay_card_no")
  3802. // discount_price, _ := c.GetFloat("discount_price")
  3803. // preferential_price, _ := c.GetFloat("preferential_price")
  3804. // reality_price, _ := c.GetFloat("reality_price")
  3805. // found_price, _ := c.GetFloat("found_price")
  3806. // medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  3807. // private_price, _ := c.GetFloat("private_price")
  3808. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  3809. // admin_user_id, _ := c.GetInt64("admin_user_id")
  3810. //
  3811. // timeLayout := "2006-01-02"
  3812. // loc, _ := time.LoadLocation("Local")
  3813. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3814. // if err != nil {
  3815. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3816. // return
  3817. // }
  3818. // recordDateTime := theTime.Unix()
  3819. // adminUser := c.GetAdminUserInfo()
  3820. //
  3821. // var prescriptions []*models.HisPrescription
  3822. //
  3823. // data := make(map[string]interface{})
  3824. // if settle_accounts_type == 1 { //日结
  3825. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  3826. // data["pre"] = prescriptions
  3827. //
  3828. // } else { //月结
  3829. // start_time_str := c.GetString("start_time")
  3830. // end_time_str := c.GetString("end_time")
  3831. // timeLayout := "2006-01-02"
  3832. // loc, _ := time.LoadLocation("Local")
  3833. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3834. // if err != nil {
  3835. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3836. // return
  3837. // }
  3838. // recordStartTime := theStartTime.Unix()
  3839. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3840. // if err != nil {
  3841. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3842. // return
  3843. // }
  3844. // recordEndTime := theEndTime.Unix()
  3845. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  3846. // data["pre"] = prescriptions
  3847. //
  3848. // }
  3849. //
  3850. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3851. //
  3852. // his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  3853. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3854. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  3855. // strconv.FormatInt(his.PatientId, 10)
  3856. //
  3857. // order_src, _ := service.GetHisOrderByID(order_id)
  3858. //
  3859. // config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3860. // if config.IsOpen == 1 { //对接了医保,走医保流程
  3861. //
  3862. // var total float64
  3863. // for _, item := range prescriptions {
  3864. // if item.Type == 1 { //药品
  3865. // for _, subItem := range item.HisDoctorAdviceInfo {
  3866. // total = total + (subItem.Price * subItem.PrescribingNumber)
  3867. // }
  3868. // }
  3869. // if item.Type == 2 { //项目
  3870. // for _, subItem := range item.HisPrescriptionProject {
  3871. // total = total + (subItem.Price * float64(subItem.Count))
  3872. // }
  3873. // }
  3874. // }
  3875. //
  3876. // for _, item := range prescriptions {
  3877. // for _, subItem := range item.HisAdditionalCharge {
  3878. // total = total + (subItem.Price * float64(subItem.Count))
  3879. // }
  3880. // }
  3881. //
  3882. // allTotal := fmt.Sprintf("%.2f", total)
  3883. // var rf []*ResultFive
  3884. // json.Unmarshal([]byte(his.Iinfo), &rf)
  3885. // psn_no := order_src.PsnNo
  3886. // mdtrt_id := order_src.MdtrtId
  3887. // chrg_bchno := order_src.Number
  3888. // cert_no := order_src.Certno
  3889. // insutype := rf[0].Insutype
  3890. //
  3891. // if his.IdCardType == 1 {
  3892. // cert_no = his.MedicalInsuranceNumber
  3893. // } else {
  3894. // cert_no = his.Certno
  3895. // }
  3896. //
  3897. // 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)
  3898. // var dat map[string]interface{}
  3899. // if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3900. // fmt.Println(dat)
  3901. // } else {
  3902. // fmt.Println(err)
  3903. // }
  3904. //
  3905. // userJSONBytes, _ := json.Marshal(dat)
  3906. //
  3907. //
  3908. //
  3909. // var res ResultSeven
  3910. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3911. // utils.ErrorLog("解析失败:%v", err)
  3912. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3913. // return
  3914. // }
  3915. // if res.Infcode == -1 {
  3916. // errlog := &models.HisOrderError{
  3917. // UserOrgId: adminUser.CurrentOrgId,
  3918. // Ctime: time.Now().Unix(),
  3919. // Mtime: time.Now().Unix(),
  3920. // Number: chrg_bchno,
  3921. // ErrMsg: res.ErrMsg,
  3922. // Status: 1,
  3923. // PatientId: id,
  3924. // RecordTime: recordDateTime,
  3925. // Stage: 6,
  3926. // }
  3927. // service.CreateErrMsgLog(errlog)
  3928. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  3929. // return
  3930. // } else {
  3931. // order_src.OrderStatus = 2
  3932. // order_src.PayWay = pay_way
  3933. // order_src.PayPrice = pay_price
  3934. // order_src.PayCardNo = pay_card_no
  3935. // order_src.DiscountPrice = discount_price
  3936. // order_src.PreferentialPrice = preferential_price
  3937. // order_src.RealityPrice = reality_price
  3938. // order_src.FoundPrice = found_price
  3939. // order_src.MedicalInsurancePrice = medical_insurance_price
  3940. // order_src.PrivatePrice = private_price
  3941. // order_src.MdtrtId = res.Output.Setlinfo.MdtrtID
  3942. // order_src.SetlId = res.Output.Setlinfo.SetlID
  3943. // order_src.PsnNo = res.Output.Setlinfo.PsnNo
  3944. // order_src.PsnName = res.Output.Setlinfo.PsnName
  3945. // order_src.PsnCertType = res.Output.Setlinfo.PsnCertType
  3946. // order_src.Certno = res.Output.Setlinfo.Certno
  3947. // order_src.Gend = res.Output.Setlinfo.Gend
  3948. // order_src.Naty = res.Output.Setlinfo.Naty
  3949. // order_src.Age = res.Output.Setlinfo.Age
  3950. // order_src.Insutype = res.Output.Setlinfo.Insutype
  3951. // order_src.PsnType = res.Output.Setlinfo.PsnType
  3952. // order_src.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  3953. // order_src.SetlTime = res.Output.Setlinfo.SetlTime
  3954. // order_src.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  3955. // order_src.MedType = res.Output.Setlinfo.MedType
  3956. // order_src.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  3957. // order_src.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  3958. // order_src.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  3959. // order_src.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  3960. // order_src.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  3961. // order_src.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  3962. // order_src.HifpPay = res.Output.Setlinfo.HifpPay
  3963. // order_src.CvlservPay = res.Output.Setlinfo.CvlservPay
  3964. // order_src.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  3965. // order_src.HifesPay = res.Output.Setlinfo.HifesPay
  3966. // order_src.HifobPay = res.Output.Setlinfo.HifobPay
  3967. // order_src.MafPay = res.Output.Setlinfo.MafPay
  3968. // order_src.OthPay = res.Output.Setlinfo.OthPay
  3969. // order_src.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  3970. // order_src.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  3971. // order_src.AcctPay = res.Output.Setlinfo.AcctPay
  3972. // order_src.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  3973. // order_src.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  3974. // order_src.Balc = res.Output.Setlinfo.Balc
  3975. // order_src.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  3976. // order_src.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  3977. // order_src.ClrOptins = res.Output.Setlinfo.ClrOptins
  3978. // order_src.ClrWay = res.Output.Setlinfo.ClrWay
  3979. // order_src.Creator = order_src.Creator
  3980. // order_src.Modify = roles.ID
  3981. // order_src.RequestLog = src_resquest
  3982. // setlDetail, _ := json.Marshal(res.Output.Setldetail)
  3983. // detailStr := string(setlDetail)
  3984. // order_src.SetlDetail = detailStr
  3985. // err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  3986. // err = service.UpDateOrder(order_src)
  3987. //
  3988. // if err == nil {
  3989. // c.ServeSuccessJSON(map[string]interface{}{
  3990. // "msg": "结算成功",
  3991. // })
  3992. // } else {
  3993. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  3994. // return
  3995. // }
  3996. // }
  3997. // }
  3998. //}
  3999. //退款
  4000. func (c *HisApiController) Refund() {
  4001. order_id, _ := c.GetInt64("order_id")
  4002. admin_user_id, _ := c.GetInt64("admin_user_id")
  4003. //record_time := c.GetString("record_time")
  4004. //patient_id, _ := c.GetInt64("patient_id")
  4005. //timeLayout := "2006-01-02"
  4006. //loc, _ := time.LoadLocation("Local")
  4007. adminUser := c.GetAdminUserInfo()
  4008. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4009. //if err != nil {
  4010. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4011. // return
  4012. //}
  4013. //recordDateTime := theTime.Unix()
  4014. var order models.HisOrder
  4015. order, _ = service.GetHisOrderByID(order_id)
  4016. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  4017. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4018. if order.ID == 0 {
  4019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4020. return
  4021. //order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  4022. }
  4023. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4024. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4025. if config.IsOpen == 1 { //对接了医保,走医保流程
  4026. var res ResultSixteen
  4027. var src_resquest string
  4028. var result string
  4029. if miConfig.MdtrtareaAdmvs == "421300" {
  4030. api3 := "http://192.168.124.4:9532/" + "hbyb/2208?psn_no=" + order.PsnNo +
  4031. "&mdtrt_id=" + order.MdtrtId + "&setl_id=" + order.SetlId + "&doctor=" + roles.UserName + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  4032. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4033. resp3, requestErr3 := http.Get(api3)
  4034. if requestErr3 != nil {
  4035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4036. return
  4037. }
  4038. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  4039. if ioErr3 != nil {
  4040. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  4041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4042. return
  4043. }
  4044. var respJSON3 map[string]interface{}
  4045. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  4046. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4048. return
  4049. }
  4050. respJSON3 = respJSON3["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4051. userJSONBytes3, _ := json.Marshal(respJSON3)
  4052. fmt.Println("log")
  4053. fmt.Println(string(userJSONBytes3))
  4054. if err := json.Unmarshal(userJSONBytes3, &res); err != nil {
  4055. utils.ErrorLog("解析失败:%v", err)
  4056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4057. return
  4058. }
  4059. } else {
  4060. result, src_resquest = service.Gdyb2208(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, his.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  4061. var dat map[string]interface{}
  4062. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4063. fmt.Println(dat)
  4064. } else {
  4065. fmt.Println(err)
  4066. }
  4067. saveLog(result, src_resquest, "2208", "退费")
  4068. userJSONBytes, _ := json.Marshal(dat)
  4069. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4070. utils.ErrorLog("解析失败:%v", err)
  4071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4072. return
  4073. }
  4074. }
  4075. if res.Infcode == 0 {
  4076. var res2 ResultSix
  4077. if miConfig.MdtrtareaAdmvs == "421300" {
  4078. api3 := "http://192.168.124.4:9532/" + "hbyb/2205?psn_no=" + order.PsnNo +
  4079. "&mdtrt_id=" + order.MdtrtId + "&chrg_bchno=" + order.Number + "&doctor=" + roles.UserName + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  4080. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4081. resp3, requestErr3 := http.Get(api3)
  4082. if requestErr3 != nil {
  4083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4084. return
  4085. }
  4086. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  4087. if ioErr3 != nil {
  4088. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  4089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4090. return
  4091. }
  4092. var respJSON3 map[string]interface{}
  4093. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  4094. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4096. return
  4097. }
  4098. respJSON3 = respJSON3["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4099. userJSONBytes3, _ := json.Marshal(respJSON3)
  4100. fmt.Println("log")
  4101. fmt.Println(string(userJSONBytes3))
  4102. if err := json.Unmarshal(userJSONBytes3, &res2); err != nil {
  4103. utils.ErrorLog("解析失败:%v", err)
  4104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4105. return
  4106. }
  4107. } else {
  4108. result2, src_request := service.Gdyb2205(order.PsnNo, order.MdtrtId, order.Number, miConfig.OrgName, roles.UserName, his.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  4109. var dat map[string]interface{}
  4110. if err := json.Unmarshal([]byte(result2), &dat); err == nil {
  4111. fmt.Println(dat)
  4112. } else {
  4113. fmt.Println(err)
  4114. }
  4115. saveLog(result2, src_request, "2205", "撤销明细")
  4116. userJSONBytes, _ := json.Marshal(dat)
  4117. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  4118. utils.ErrorLog("解析失败:%v", err)
  4119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4120. return
  4121. }
  4122. }
  4123. if res2.Infcode == 0 {
  4124. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, src_resquest, result)
  4125. if err == nil {
  4126. c.ServeSuccessJSON(map[string]interface{}{
  4127. "msg": "退费成功",
  4128. })
  4129. } else {
  4130. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4131. return
  4132. }
  4133. } else {
  4134. c.ServeSuccessJSON(map[string]interface{}{
  4135. "code": -10,
  4136. "msg": res2.ErrMsg,
  4137. })
  4138. }
  4139. } else {
  4140. c.ServeSuccessJSON(map[string]interface{}{
  4141. "code": -10,
  4142. "msg": res.ErrMsg,
  4143. })
  4144. }
  4145. }
  4146. }
  4147. func (c *HisApiController) RefundNumber() {
  4148. record_time := c.GetString("record_time")
  4149. //patient_id, _ := c.GetInt64("patient_id")
  4150. admin_user_id, _ := c.GetInt64("admin_user_id")
  4151. his_patient_id, _ := c.GetInt64("id")
  4152. timeLayout := "2006-01-02"
  4153. loc, _ := time.LoadLocation("Local")
  4154. adminUser := c.GetAdminUserInfo()
  4155. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4156. fmt.Println(err)
  4157. if err != nil {
  4158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4159. return
  4160. }
  4161. recordDateTime := theTime.Unix()
  4162. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  4163. his, _ := service.GetHisPatientRecord(adminUser.CurrentOrgId, his_patient_id)
  4164. //patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  4165. //order, _ := service.GetHisOrderByID(order_id)
  4166. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4167. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4168. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4169. count, _ := service.GetOrderCountByNumber(adminUser.CurrentOrgId, his.PatientId, recordDateTime, his.Number)
  4170. if count > 0 {
  4171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4172. return
  4173. }
  4174. if config.IsOpen == 1 { //对接了医保,走医保流程
  4175. var res2 ResultSix
  4176. if miConfig.MdtrtareaAdmvs == "421300" {
  4177. api3 := "http://192.168.124.4:9532/" + "hbyb/2202?psn_no=" + his.PsnNo +
  4178. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + roles.UserName + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  4179. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4180. resp3, requestErr3 := http.Get(api3)
  4181. if requestErr3 != nil {
  4182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4183. return
  4184. }
  4185. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  4186. if ioErr3 != nil {
  4187. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  4188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4189. return
  4190. }
  4191. var respJSON3 map[string]interface{}
  4192. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  4193. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4195. return
  4196. }
  4197. respJSON3 = respJSON3["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4198. userJSONBytes3, _ := json.Marshal(respJSON3)
  4199. fmt.Println("log")
  4200. fmt.Println(string(userJSONBytes3))
  4201. if err := json.Unmarshal(userJSONBytes3, &res2); err != nil {
  4202. utils.ErrorLog("解析失败:%v", err)
  4203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4204. return
  4205. }
  4206. } else {
  4207. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  4208. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + roles.UserName + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  4209. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4210. resp3, requestErr3 := http.Get(api3)
  4211. if requestErr3 != nil {
  4212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4213. return
  4214. }
  4215. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  4216. if ioErr3 != nil {
  4217. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  4218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4219. return
  4220. }
  4221. var respJSON3 map[string]interface{}
  4222. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  4223. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4225. return
  4226. }
  4227. respJSON3 = respJSON3["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4228. userJSONBytes3, _ := json.Marshal(respJSON3)
  4229. if err := json.Unmarshal(userJSONBytes3, &res2); err != nil {
  4230. utils.ErrorLog("解析失败:%v", err)
  4231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4232. return
  4233. }
  4234. }
  4235. if res2.Infcode == 0 {
  4236. if err == nil {
  4237. c.ServeSuccessJSON(map[string]interface{}{
  4238. "msg": "退号成功",
  4239. })
  4240. service.UpdataRegStatusTwo(his_patient_id, recordDateTime, adminUser.CurrentOrgId)
  4241. } else {
  4242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4243. return
  4244. }
  4245. } else {
  4246. c.ServeSuccessJSON(map[string]interface{}{
  4247. "code": -10,
  4248. "msg": res2.ErrMsg,
  4249. })
  4250. }
  4251. } else {
  4252. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  4253. //if err == nil {
  4254. // c.ServeSuccessJSON(map[string]interface{}{
  4255. // "msg": "退费成功",
  4256. // })
  4257. //} else {
  4258. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4259. // return
  4260. //}
  4261. }
  4262. }
  4263. func (c *HisApiController) RefundDetail() {
  4264. order_id, _ := c.GetInt64("order_id")
  4265. //his_patient_id, _ := c.GetInt64("his_patient_id")
  4266. number := c.GetString("number")
  4267. record_time := c.GetString("record_time")
  4268. patient_id, _ := c.GetInt64("patient_id")
  4269. timeLayout := "2006-01-02"
  4270. loc, _ := time.LoadLocation("Local")
  4271. adminUser := c.GetAdminUserInfo()
  4272. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4273. fmt.Println(err)
  4274. if err != nil {
  4275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4276. return
  4277. }
  4278. recordDateTime := theTime.Unix()
  4279. //his, _ := service.GetNewVMHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  4280. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  4281. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4282. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4283. var order models.HisOrder
  4284. order, _ = service.GetHisOrderByID(order_id)
  4285. if order.ID == 0 {
  4286. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  4287. }
  4288. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  4289. if config.IsOpen == 1 { //对接了医保,走医保流程
  4290. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  4291. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  4292. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4293. resp2, requestErr2 := http.Get(api2)
  4294. if requestErr2 != nil {
  4295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4296. return
  4297. }
  4298. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  4299. if ioErr2 != nil {
  4300. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  4301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4302. return
  4303. }
  4304. var respJSON2 map[string]interface{}
  4305. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  4306. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4308. return
  4309. }
  4310. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId, "", "")
  4311. if err == nil {
  4312. c.ServeSuccessJSON(map[string]interface{}{
  4313. "msg": "退费成功",
  4314. })
  4315. } else {
  4316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4317. return
  4318. }
  4319. } else {
  4320. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId, "", "")
  4321. if err == nil {
  4322. c.ServeSuccessJSON(map[string]interface{}{
  4323. "msg": "退费成功",
  4324. })
  4325. } else {
  4326. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4327. return
  4328. }
  4329. }
  4330. }
  4331. //对账
  4332. func (c *HisApiController) GetCheckAccount() {
  4333. start_time := c.GetString("start_time")
  4334. end_time := c.GetString("end_time")
  4335. insutype := c.GetString("insutype")
  4336. clr_type := c.GetString("clr_type")
  4337. admin_user_id, _ := c.GetInt64("admin_user_id")
  4338. adminUser := c.GetAdminUserInfo()
  4339. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4340. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4341. timeLayout := "2006-01-02"
  4342. loc, _ := time.LoadLocation("Local")
  4343. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4344. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4345. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  4346. //orders_two, _ := service.GetOrderByTimeThree(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  4347. fixmedins_setl_cnt := int64(len(orders))
  4348. //
  4349. ////撤销的算2条数据为一笔
  4350. //for _, item := range orders_two {
  4351. // if item.OrderStatus == 3 {
  4352. // fixmedins_setl_cnt = fixmedins_setl_cnt + 1
  4353. // }
  4354. //}
  4355. var medfee_sumamt float64
  4356. var acct_pay float64
  4357. var fund_pay_sumamt float64
  4358. for _, item := range orders {
  4359. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  4360. acct_pay = acct_pay + item.AcctPay
  4361. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  4362. }
  4363. var user_name string
  4364. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4365. if role.ID == 0 {
  4366. user_name = "xxx"
  4367. } else {
  4368. user_name = role.UserName
  4369. }
  4370. if config.IsOpen == 1 {
  4371. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  4372. "insutype=" + insutype +
  4373. "&clr_type=" + clr_type +
  4374. "&setl_optins=" + "定点医保中心" +
  4375. "&stmt_begndate=" + start_time +
  4376. "&stm_enddate=" + end_time +
  4377. "&medfee_sumamt=" + fmt.Sprintf("%.4f", medfee_sumamt) +
  4378. "&fund_pay_sumamt=" + fmt.Sprintf("%.4f", fund_pay_sumamt) +
  4379. "&acct_pay=" + fmt.Sprintf("%.4f", acct_pay) +
  4380. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  4381. "&fixmedins_code=" + miConfig.Code +
  4382. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  4383. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  4384. "&secret_key=" + miConfig.SecretKey +
  4385. "&org_name=" + miConfig.OrgName +
  4386. "&doctor=" + user_name
  4387. fmt.Println(api)
  4388. resp, requestErr := http.Get(api)
  4389. if requestErr != nil {
  4390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4391. return
  4392. }
  4393. body, ioErr := ioutil.ReadAll(resp.Body)
  4394. fmt.Println(body)
  4395. if ioErr != nil {
  4396. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4398. return
  4399. }
  4400. var respJSON map[string]interface{}
  4401. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4402. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4404. return
  4405. }
  4406. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4407. userJSONBytes, _ := json.Marshal(respJSON)
  4408. var res ResultEight
  4409. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4410. utils.ErrorLog("解析失败:%v", err)
  4411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4412. return
  4413. }
  4414. if res.Infcode == 0 {
  4415. if res.Output.Stmtinfo.StmtRslt == "0" {
  4416. micc := &models.MedicalInsuranceCostCompare{
  4417. StartTime: startime.Unix(),
  4418. EndTime: endtime.Unix(),
  4419. Insutype: insutype,
  4420. CheckType: 1,
  4421. Num: fixmedins_setl_cnt,
  4422. Mtime: time.Now().Unix(),
  4423. Status: 1,
  4424. UserOrgId: adminUser.CurrentOrgId,
  4425. CostTotal: medfee_sumamt,
  4426. FuncTotal: fund_pay_sumamt,
  4427. PsnPay: acct_pay,
  4428. Creator: admin_user_id,
  4429. Ctime: time.Now().Unix(),
  4430. }
  4431. err := service.CreateMedicalInsuranceCostCompareRecord(micc)
  4432. if err == nil {
  4433. c.ServeSuccessJSON(map[string]interface{}{
  4434. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  4435. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  4436. })
  4437. } else {
  4438. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4439. }
  4440. } else {
  4441. c.ServeSuccessJSON(map[string]interface{}{
  4442. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  4443. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  4444. })
  4445. }
  4446. } else {
  4447. c.ServeSuccessJSON(map[string]interface{}{
  4448. "code": -10,
  4449. "msg": res.ErrMsg,
  4450. })
  4451. }
  4452. }
  4453. }
  4454. func (c *HisApiController) Check310() {
  4455. adminUser := c.GetAdminUserInfo()
  4456. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4457. var user_name string
  4458. user_name = "xxx"
  4459. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  4460. "insutype=" + "310" +
  4461. "&clr_type=" + "11" +
  4462. "&setl_optins=" + "定点医保中心" +
  4463. "&stmt_begndate=" + "2021-03-01" +
  4464. "&stm_enddate=" + "2021-03-31" +
  4465. "&medfee_sumamt=" + "11521" +
  4466. "&fund_pay_sumamt=" + "10166.66" +
  4467. "&acct_pay=" + "0" +
  4468. "&fixmedins_setl_cnt=" + "7" +
  4469. "&fixmedins_code=" + miConfig.Code +
  4470. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  4471. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  4472. "&secret_key=" + miConfig.SecretKey +
  4473. "&org_name=" + miConfig.OrgName +
  4474. "&doctor=" + user_name
  4475. fmt.Println(api)
  4476. resp, requestErr := http.Get(api)
  4477. if requestErr != nil {
  4478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4479. return
  4480. }
  4481. body, ioErr := ioutil.ReadAll(resp.Body)
  4482. fmt.Println(body)
  4483. if ioErr != nil {
  4484. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4486. return
  4487. }
  4488. var respJSON map[string]interface{}
  4489. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4490. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4492. return
  4493. }
  4494. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4495. userJSONBytes, _ := json.Marshal(respJSON)
  4496. var res ResultEight
  4497. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4498. utils.ErrorLog("解析失败:%v", err)
  4499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4500. return
  4501. }
  4502. }
  4503. func (c *HisApiController) Check390() {
  4504. adminUser := c.GetAdminUserInfo()
  4505. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4506. var user_name string
  4507. user_name = "张俊杰"
  4508. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  4509. "insutype=" + "390" +
  4510. "&clr_type=" + "11" +
  4511. "&setl_optins=" + "定点医保中心" +
  4512. "&stmt_begndate=" + "2021-03-01" +
  4513. "&stm_enddate=" + "2021-03-31" +
  4514. "&medfee_sumamt=" + "209318.43" +
  4515. "&fund_pay_sumamt=" + "188029.12" +
  4516. "&acct_pay=" + "0" +
  4517. "&fixmedins_setl_cnt=" + "48" +
  4518. "&fixmedins_code=" + miConfig.Code +
  4519. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  4520. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  4521. "&secret_key=" + miConfig.SecretKey +
  4522. "&org_name=" + miConfig.OrgName +
  4523. "&doctor=" + user_name
  4524. fmt.Println(api)
  4525. resp, requestErr := http.Get(api)
  4526. if requestErr != nil {
  4527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4528. return
  4529. }
  4530. body, ioErr := ioutil.ReadAll(resp.Body)
  4531. fmt.Println(body)
  4532. if ioErr != nil {
  4533. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4535. return
  4536. }
  4537. var respJSON map[string]interface{}
  4538. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4539. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4541. return
  4542. }
  4543. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4544. userJSONBytes, _ := json.Marshal(respJSON)
  4545. var res ResultEight
  4546. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4547. utils.ErrorLog("解析失败:%v", err)
  4548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4549. return
  4550. }
  4551. }
  4552. //对账明细
  4553. func (c *HisApiController) GetCheckDetailAccount() {
  4554. start_time := c.GetString("start_time")
  4555. end_time := c.GetString("end_time")
  4556. admin_user_id, _ := c.GetInt64("admin_user_id")
  4557. adminUser := c.GetAdminUserInfo()
  4558. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4559. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4560. timeLayout := "2006-01-02"
  4561. loc, _ := time.LoadLocation("Local")
  4562. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4563. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4564. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  4565. Mkdir(miConfig.OrgName)
  4566. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  4567. file_name := file + ".txt"
  4568. zip_name := file + ".zip"
  4569. zip_path := miConfig.OrgName + "/" + zip_name
  4570. file_path := miConfig.OrgName + "/" + file_name
  4571. decimal.DivisionPrecision = 2
  4572. var medfee_sumamt float64
  4573. var psn_cash_pay float64
  4574. var fund_pay_sumamt float64
  4575. fixmedins_setl_cnt := int64(len(orders))
  4576. for _, item := range orders {
  4577. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  4578. psn_cash_pay = psn_cash_pay + item.PsnCashPay
  4579. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  4580. }
  4581. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  4582. defer f.Close()
  4583. if err != nil {
  4584. fmt.Println(err.Error())
  4585. } else {
  4586. for _, item := range orders {
  4587. var refd_setl_flag string
  4588. if item.OrderStatus == 2 {
  4589. refd_setl_flag = "0"
  4590. var str string
  4591. str = item.SetlId + " " +
  4592. item.MdtrtId + " " +
  4593. item.PsnNo + " " +
  4594. fmt.Sprintf("%.4f", item.MedfeeSumamt) + " " +
  4595. fmt.Sprintf("%.4f", item.FundPaySumamt) + " " +
  4596. fmt.Sprintf("%.4f", item.AcctPay) + " " + refd_setl_flag + "\r\n"
  4597. _, err = f.Write([]byte(str))
  4598. }
  4599. if item.OrderStatus == 3 {
  4600. var str string
  4601. str = item.SetlId + " " +
  4602. item.MdtrtId + " " +
  4603. item.PsnNo + " " +
  4604. fmt.Sprintf("%.4f", item.MedfeeSumamt) + " " +
  4605. fmt.Sprintf("%.4f", item.FundPaySumamt) + " " +
  4606. fmt.Sprintf("%.4f", item.AcctPay) + " " + "1" + "\r\n"
  4607. _, err = f.Write([]byte(str))
  4608. var str2 string
  4609. str2 = item.SetlId + " " +
  4610. item.MdtrtId + " " +
  4611. item.PsnNo + " " +
  4612. fmt.Sprintf("%.4f", 0-item.MedfeeSumamt) + " " +
  4613. fmt.Sprintf("%.4f", 0-item.FundPaySumamt) + " " +
  4614. fmt.Sprintf("%.4f", 0-item.AcctPay) + " " + "1" + "\r\n"
  4615. _, err = f.Write([]byte(str2))
  4616. }
  4617. }
  4618. }
  4619. Zip(file_path, zip_path)
  4620. fmt.Println(ReadFile(zip_path))
  4621. fmt.Println(string(ReadFile(zip_path)))
  4622. if config.IsOpen == 1 {
  4623. var user_name string
  4624. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4625. if role.ID == 0 {
  4626. user_name = "管理员"
  4627. } else {
  4628. user_name = role.UserName
  4629. }
  4630. baseParams := models.BaseParams{
  4631. SecretKey: miConfig.SecretKey,
  4632. FixmedinsCode: miConfig.Code,
  4633. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4634. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4635. OrgName: miConfig.OrgName,
  4636. Doctor: user_name,
  4637. }
  4638. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  4639. var dat map[string]interface{}
  4640. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4641. fmt.Println(dat)
  4642. } else {
  4643. fmt.Println(err)
  4644. }
  4645. userJSONBytes, _ := json.Marshal(dat)
  4646. var res ResultNine
  4647. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4648. utils.ErrorLog("解析失败:%v", err)
  4649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4650. return
  4651. }
  4652. if res.Infcode == 0 {
  4653. fileNo := res.Output.FileQuryNo
  4654. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  4655. "file_qury_no=" + fileNo +
  4656. "&setl_optins=" + "定点医保中心" +
  4657. "&stmt_begndate=" + start_time +
  4658. "&stm_enddate=" + end_time +
  4659. "&medfee_sumamt=" + fmt.Sprintf("%.4f", medfee_sumamt) +
  4660. "&fund_pay_sumamt=" + fmt.Sprintf("%.4f", fund_pay_sumamt) +
  4661. "&cash_payamt=" + fmt.Sprintf("%.4f", psn_cash_pay) +
  4662. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  4663. "&fixmedins_code=" + miConfig.Code +
  4664. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  4665. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  4666. "&secret_key=" + miConfig.SecretKey +
  4667. "&org_name=" + miConfig.OrgName +
  4668. "&doctor=" + user_name
  4669. resp, requestErr := http.Get(api)
  4670. if requestErr != nil {
  4671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4672. return
  4673. }
  4674. body, ioErr := ioutil.ReadAll(resp.Body)
  4675. if ioErr != nil {
  4676. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4678. return
  4679. }
  4680. var respJSON map[string]interface{}
  4681. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4682. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4684. return
  4685. }
  4686. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4687. userJSONBytes, _ := json.Marshal(respJSON)
  4688. var res ResultTen
  4689. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4690. utils.ErrorLog("解析失败:%v", err)
  4691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4692. return
  4693. }
  4694. if res.Infcode == 0 {
  4695. service.Gdyb9102(baseParams, zip_name, fileNo)
  4696. micc := &models.MedicalInsuranceCostCompare{
  4697. StartTime: startime.Unix(),
  4698. EndTime: endtime.Unix(),
  4699. Insutype: "0",
  4700. CheckType: 2,
  4701. Num: fixmedins_setl_cnt,
  4702. Mtime: time.Now().Unix(),
  4703. Status: 1,
  4704. UserOrgId: adminUser.CurrentOrgId,
  4705. CostTotal: medfee_sumamt,
  4706. FuncTotal: fund_pay_sumamt,
  4707. PsnPay: psn_cash_pay,
  4708. Creator: admin_user_id,
  4709. Ctime: time.Now().Unix(),
  4710. }
  4711. service.CreateMedicalInsuranceCostCompareRecord(micc)
  4712. c.ServeSuccessJSON(map[string]interface{}{
  4713. "msg": "明细对账成功",
  4714. })
  4715. }
  4716. } else {
  4717. }
  4718. }
  4719. }
  4720. type CustomOrderInfo struct {
  4721. Name string
  4722. Spec string
  4723. Unit string
  4724. Count float64
  4725. Price float64
  4726. Total float64
  4727. }
  4728. func (c *HisApiController) GetSettleAccounts() {
  4729. //id, _ := c.GetInt64("id")
  4730. //record_time := c.GetString("record_time")
  4731. order_id, _ := c.GetInt64("order_id")
  4732. admin_user_id, _ := c.GetInt64("admin_user_id")
  4733. //timeLayout := "2006-01-02"
  4734. //loc, _ := time.LoadLocation("Local")
  4735. //
  4736. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4737. //if err != nil {
  4738. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4739. // return
  4740. //}
  4741. //recordDateTime := theTime.Unix()
  4742. adminUser := c.GetAdminUserInfo()
  4743. order, _ := service.GetHisOrderByID(order_id)
  4744. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  4745. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  4746. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  4747. orderInfos = append(orderInfos, orderInfos_two...)
  4748. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  4749. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  4750. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  4751. //var config []*models.HisXtDiagnoseConfig
  4752. var name string
  4753. for _, item := range diagnosis_ids {
  4754. id, _ := strconv.ParseInt(item, 10, 64)
  4755. diagnosisConfig, _ := service.FindDiagnoseById(id)
  4756. if len(name) == 0 {
  4757. name = diagnosisConfig.ClassName
  4758. } else {
  4759. name = name + "," + diagnosisConfig.ClassName
  4760. }
  4761. }
  4762. var bedCostTotal float64 = 0 //床位总费
  4763. var bedCostSelfTotal float64 = 0 //床位自费
  4764. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  4765. var operationCostTotal float64 = 0 //手术费
  4766. var operationCostSelfTotal float64 = 0 //手术费
  4767. var operationCostPartSelfTotal float64 = 0 //手术费
  4768. var otherCostTotal float64 = 0 //其他费用
  4769. var otherCostSelfTotal float64 = 0 //其他费用
  4770. var otherCostPartSelfTotal float64 = 0 //其他费用
  4771. var materialCostTotal float64 = 0 //材料费
  4772. var materialCostSelfTotal float64 = 0 //材料费
  4773. var materialCostPartSelfTotal float64 = 0 //材料费
  4774. var westernMedicineCostTotal float64 = 0 //西药费
  4775. var westernMedicineCostSelfTotal float64 = 0 //西药费
  4776. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  4777. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  4778. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  4779. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  4780. var checkCostTotal float64 = 0 //检查费
  4781. var checkCostSelfTotal float64 = 0 //检查费
  4782. var checkCostPartSelfTotal float64 = 0 //检查费
  4783. var laboratoryCostTotal float64 = 0 //化验费
  4784. var laboratoryCostSelfTotal float64 = 0 //化验费
  4785. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  4786. var treatCostTotal float64 = 0 //治疗费用
  4787. var treatCostSelfTotal float64 = 0 //治疗费用
  4788. var treatCostPartSelfTotal float64 = 0 //治疗费用
  4789. decimal.DivisionPrecision = 2
  4790. for _, item := range orderInfos {
  4791. if item.MedChrgitmType == "01" { //床位费
  4792. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4793. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4794. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4795. }
  4796. if item.MedChrgitmType == "03" { //检查费
  4797. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4798. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4799. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4800. }
  4801. if item.MedChrgitmType == "04" { //化验费
  4802. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4803. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4804. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4805. }
  4806. if item.MedChrgitmType == "05" { //治疗费
  4807. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4808. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4809. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4810. }
  4811. if item.MedChrgitmType == "06" { //手术费
  4812. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4813. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4814. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4815. }
  4816. if item.MedChrgitmType == "08" { //材料费
  4817. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4818. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4819. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4820. }
  4821. if item.MedChrgitmType == "09" { //西药费
  4822. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4823. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4824. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4825. }
  4826. if item.MedChrgitmType == "11" { //中成费
  4827. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4828. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4829. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4830. }
  4831. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  4832. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4833. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4834. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4835. }
  4836. }
  4837. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4838. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4839. var user_name string
  4840. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4841. if role.ID == 0 {
  4842. user_name = "管理员"
  4843. } else {
  4844. user_name = role.UserName
  4845. }
  4846. baseParams := models.BaseParams{
  4847. SecretKey: miConfig.SecretKey,
  4848. FixmedinsCode: miConfig.Code,
  4849. InsuplcAdmdvs: his.InsuplcAdmdvs,
  4850. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4851. OrgName: miConfig.OrgName,
  4852. Doctor: user_name,
  4853. }
  4854. businessParams := models.BusinessParams{
  4855. PsnNo: order.PsnNo,
  4856. MdtrtId: order.MdtrtId,
  4857. SetlId: order.SetlId,
  4858. }
  4859. var res ResultEleven
  4860. if config.IsOpen == 1 {
  4861. if miConfig.MdtrtareaAdmvs == "421300" {
  4862. api := "http://192.168.124.4:9532/" + "hbyb/5203?psn_no=" + businessParams.PsnNo + "&mdtrt_id=" + businessParams.MdtrtId + "&setl_id=" + businessParams.SetlId +
  4863. "&org_name=" + miConfig.OrgName + "&doctor=" + baseParams.Doctor + "&fixmedins_code=" + miConfig.Code +
  4864. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4865. resp, requestErr := http.Get(api)
  4866. if requestErr != nil {
  4867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4868. return
  4869. }
  4870. body, ioErr := ioutil.ReadAll(resp.Body)
  4871. if ioErr != nil {
  4872. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4874. return
  4875. }
  4876. var respJSON map[string]interface{}
  4877. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4878. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4880. return
  4881. }
  4882. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4883. result, _ := json.Marshal(respJSON)
  4884. fmt.Println("log")
  4885. fmt.Println(string(result))
  4886. if err := json.Unmarshal([]byte(result), &res); err != nil {
  4887. utils.ErrorLog("解析失败:%v", err)
  4888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4889. return
  4890. }
  4891. } else {
  4892. result := service.Gdyb5203(baseParams, businessParams)
  4893. var dat map[string]interface{}
  4894. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4895. fmt.Println(dat)
  4896. } else {
  4897. fmt.Println(err)
  4898. }
  4899. userJSONBytes, _ := json.Marshal(dat)
  4900. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4901. utils.ErrorLog("解析失败:%v", err)
  4902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4903. return
  4904. }
  4905. }
  4906. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4907. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  4908. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, order.PatientId, order.SettleAccountsDate)
  4909. adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  4910. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4911. var doctor_name string
  4912. if roles.ID == 0 {
  4913. doctor_name = "管理员"
  4914. } else {
  4915. doctor_name = roles.UserName
  4916. }
  4917. yiliao_leibie := ""
  4918. switch order.MedType {
  4919. case "11":
  4920. yiliao_leibie = "普通门诊"
  4921. break
  4922. case "12":
  4923. yiliao_leibie = "门诊挂号"
  4924. break
  4925. case "13":
  4926. yiliao_leibie = "急诊"
  4927. break
  4928. case "14":
  4929. yiliao_leibie = "门诊特殊病"
  4930. break
  4931. case "15":
  4932. yiliao_leibie = "门诊统筹"
  4933. break
  4934. case "16":
  4935. yiliao_leibie = "门诊慢性病"
  4936. break
  4937. case "21":
  4938. yiliao_leibie = "普通住院"
  4939. break
  4940. }
  4941. departments, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  4942. if res.Infcode == 0 {
  4943. c.ServeSuccessJSON(map[string]interface{}{
  4944. "diagnosis": name,
  4945. "order_infos": orderInfos,
  4946. "number": order.MdtrtId,
  4947. "date": order.SettleAccountsDate,
  4948. "charge_admin": charge_admin,
  4949. "printor_admin": printor_admin,
  4950. "info": res.Output.Setlinfo,
  4951. "bedCostTotal": bedCostTotal,
  4952. "bedCostSelfTotal": bedCostSelfTotal,
  4953. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  4954. "operationCostTotal": operationCostTotal,
  4955. "operationCostSelfTotal": operationCostSelfTotal,
  4956. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  4957. "otherCostTotal": otherCostTotal,
  4958. "otherCostSelfTotal": otherCostSelfTotal,
  4959. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  4960. "materialCostTotal": materialCostTotal,
  4961. "materialCostSelfTotal": materialCostSelfTotal,
  4962. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  4963. "westernMedicineCostTotal": westernMedicineCostTotal,
  4964. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  4965. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  4966. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  4967. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  4968. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  4969. "checkCostTotal": checkCostTotal,
  4970. "checkCostSelfTotal": checkCostSelfTotal,
  4971. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  4972. "laboratoryCostTotal": laboratoryCostTotal,
  4973. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  4974. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  4975. "treatCostTotal": treatCostTotal,
  4976. "treatCostSelfTotal": treatCostSelfTotal,
  4977. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  4978. "doctor_code": adminRole_two.DoctorCode,
  4979. "doctor_name": doctor_name,
  4980. "health_card_no": order.PsnNo,
  4981. "department": departments.Name,
  4982. "yiliao_leibie": yiliao_leibie,
  4983. "after_money": order.AccountPrice,
  4984. "patient": patient,
  4985. "org_name": miConfig.OrgName,
  4986. "org_code": miConfig.Code,
  4987. "order_number": order.Number,
  4988. //"check_order_info": cus_slice,
  4989. })
  4990. }
  4991. }
  4992. }
  4993. func (c *HisApiController) CheckTreatment() {
  4994. patient_id, _ := c.GetInt64("patient_id", 0)
  4995. record_time := c.GetString("record_time")
  4996. insutype := c.GetString("insutype")
  4997. timeLayout := "2006-01-02"
  4998. loc, _ := time.LoadLocation("Local")
  4999. adminUser := c.GetAdminUserInfo()
  5000. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5001. fmt.Println(err)
  5002. if err != nil {
  5003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5004. return
  5005. }
  5006. recordDateTime := theTime.Unix()
  5007. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  5008. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  5009. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5010. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5011. var user_name string
  5012. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  5013. if role.ID == 0 {
  5014. user_name = "xxx"
  5015. } else {
  5016. user_name = role.UserName
  5017. }
  5018. baseParams := models.BaseParams{
  5019. SecretKey: miConfig.SecretKey,
  5020. FixmedinsCode: miConfig.Code,
  5021. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  5022. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  5023. OrgName: miConfig.OrgName,
  5024. Doctor: user_name,
  5025. }
  5026. if config.IsOpen == 1 {
  5027. result := service.Gdyb2001(baseParams, his.PsnNo, insutype, strconv.FormatInt(patientPrescription.RegisterType, 10))
  5028. var dat map[string]interface{}
  5029. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5030. fmt.Println(dat)
  5031. } else {
  5032. fmt.Println(err)
  5033. }
  5034. }
  5035. }
  5036. func (c *HisApiController) PutRecord() {
  5037. id, _ := c.GetInt64("id")
  5038. record_time := c.GetString("record_time")
  5039. timeLayout := "2006-01-02"
  5040. loc, _ := time.LoadLocation("Local")
  5041. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5042. if err != nil {
  5043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5044. return
  5045. }
  5046. recordDateTime := theTime.Unix()
  5047. adminInfo := c.GetAdminUserInfo()
  5048. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  5049. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  5050. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  5051. fmt.Println(miConfig.SecretKey)
  5052. if patient == nil {
  5053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5054. return
  5055. }
  5056. if len(patient.IdCardNo) == 0 {
  5057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  5058. return
  5059. }
  5060. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  5061. if config.IsOpen == 1 {
  5062. 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
  5063. resp, requestErr := http.Get(api)
  5064. if requestErr != nil {
  5065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5066. return
  5067. }
  5068. defer resp.Body.Close()
  5069. body, ioErr := ioutil.ReadAll(resp.Body)
  5070. if ioErr != nil {
  5071. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  5072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5073. return
  5074. }
  5075. var respJSON map[string]interface{}
  5076. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  5077. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  5078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5079. return
  5080. }
  5081. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  5082. userJSONBytes, _ := json.Marshal(userJSON)
  5083. var res ResultTwo
  5084. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5085. utils.ErrorLog("解析失败:%v", err)
  5086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5087. return
  5088. }
  5089. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  5090. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  5091. infoStr := string(Iinfos)
  5092. idetinfoStr := string(Idetinfos)
  5093. if res.Infcode == 0 {
  5094. his := models.VMHisPatient{
  5095. Status: 1,
  5096. Ctime: time.Now().Unix(),
  5097. Mtime: time.Now().Unix(),
  5098. PsnNo: res.Output.Baseinfo.PsnNo,
  5099. PsnCertType: res.Output.Baseinfo.PsnCertType,
  5100. Certno: res.Output.Baseinfo.Certno,
  5101. PsnName: res.Output.Baseinfo.PsnName,
  5102. Gend: res.Output.Baseinfo.Gend,
  5103. Naty: res.Output.Baseinfo.Naty,
  5104. Brdy: res.Output.Baseinfo.Brdy,
  5105. Age: res.Output.Baseinfo.Age,
  5106. Iinfo: infoStr,
  5107. Idetinfo: idetinfoStr,
  5108. PatientId: patient.ID,
  5109. RecordDate: theTime.Unix(),
  5110. UserOrgId: adminInfo.CurrentOrgId,
  5111. AdminUserId: adminInfo.AdminUser.Id,
  5112. IsReturn: 1,
  5113. }
  5114. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  5115. 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")
  5116. 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")
  5117. var dat map[string]interface{}
  5118. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5119. fmt.Println(dat)
  5120. } else {
  5121. fmt.Println(err)
  5122. }
  5123. var dat2 map[string]interface{}
  5124. if err := json.Unmarshal([]byte(result2), &dat2); err == nil {
  5125. fmt.Println(dat2)
  5126. } else {
  5127. fmt.Println(err)
  5128. }
  5129. } else {
  5130. adminUser := c.GetAdminUserInfo()
  5131. errlog := &models.HisOrderError{
  5132. UserOrgId: adminUser.CurrentOrgId,
  5133. Ctime: time.Now().Unix(),
  5134. Mtime: time.Now().Unix(),
  5135. ErrMsg: res.ErrMsg,
  5136. Status: 1,
  5137. PatientId: id,
  5138. RecordTime: recordDateTime,
  5139. Stage: 1,
  5140. }
  5141. service.CreateErrMsgLog(errlog)
  5142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  5143. return
  5144. }
  5145. }
  5146. }
  5147. func (c *HisApiController) GetUploadDiag() {
  5148. id, _ := c.GetInt64("id")
  5149. record_time := c.GetString("record_time")
  5150. diagnosis_id, _ := c.GetInt64("diagnosis")
  5151. sick_type, _ := c.GetInt64("sick_type")
  5152. reg_type, _ := c.GetInt64("reg_type")
  5153. timeLayout := "2006-01-02"
  5154. loc, _ := time.LoadLocation("Local")
  5155. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5156. if err != nil {
  5157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5158. return
  5159. }
  5160. var patientPrescription models.HisPrescriptionInfo
  5161. recordDateTime := theTime.Unix()
  5162. adminInfo := c.GetAdminUserInfo()
  5163. patientPrescription, _ = service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  5164. if patientPrescription.ID == 0 {
  5165. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  5166. }
  5167. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  5168. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  5169. his, _ := service.GetVMHisPatientInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  5170. sickConfig, _ := service.FindSickById(sick_type)
  5171. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  5172. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  5173. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  5174. "&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 +
  5175. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.ContentCode + "&sick_name=" + sickConfig.ClassName
  5176. resp2, requestErr2 := http.Get(api2)
  5177. if requestErr2 != nil {
  5178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5179. return
  5180. }
  5181. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  5182. if ioErr2 != nil {
  5183. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  5184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5185. return
  5186. }
  5187. var respJSON2 map[string]interface{}
  5188. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  5189. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  5190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5191. return
  5192. }
  5193. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  5194. userJSONBytes2, _ := json.Marshal(respJSON2)
  5195. var res2 ResultSix
  5196. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  5197. utils.ErrorLog("解析失败:%v", err)
  5198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5199. return
  5200. }
  5201. if res2.Infcode != 0 {
  5202. adminUser := c.GetAdminUserInfo()
  5203. errlog := &models.HisOrderError{
  5204. UserOrgId: adminUser.CurrentOrgId,
  5205. Ctime: time.Now().Unix(),
  5206. Mtime: time.Now().Unix(),
  5207. ErrMsg: res2.ErrMsg,
  5208. Status: 1,
  5209. PatientId: id,
  5210. RecordTime: recordDateTime,
  5211. Stage: 3,
  5212. }
  5213. service.CreateErrMsgLog(errlog)
  5214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  5215. return
  5216. }
  5217. c.ServeSuccessJSON(map[string]interface{}{
  5218. "msg": "上传成功",
  5219. })
  5220. }
  5221. type QueryResult struct {
  5222. ID int64
  5223. Name string
  5224. Code string
  5225. List_type_code string
  5226. }
  5227. func (c *HisApiController) GetCheckCode() {
  5228. ids_str := c.GetString("ids")
  5229. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  5230. ids_arr := strings.Split(ids_str, ",")
  5231. var queryResult []QueryResult
  5232. ids := make([]int64, 0)
  5233. for _, item := range ids_arr {
  5234. id, _ := strconv.ParseInt(item, 10, 64)
  5235. ids = append(ids, id)
  5236. }
  5237. if record_type == 1 {
  5238. drugs, _ := service.GetBatchDrugList(ids)
  5239. for _, item := range drugs {
  5240. result := QueryResult{
  5241. ID: item.ID,
  5242. Name: item.DrugName,
  5243. Code: item.MedicalInsuranceNumber,
  5244. List_type_code: "101",
  5245. }
  5246. queryResult = append(queryResult, result)
  5247. }
  5248. } else if record_type == 2 {
  5249. goods, _ := service.GetBatchGoodInformationList(ids)
  5250. for _, item := range goods {
  5251. result := QueryResult{
  5252. ID: item.ID,
  5253. Name: item.GoodName,
  5254. Code: item.MedicalInsuranceNumber,
  5255. List_type_code: "301",
  5256. }
  5257. queryResult = append(queryResult, result)
  5258. }
  5259. } else if record_type == 3 {
  5260. projects, _ := service.GetBathchMyPorjecgList(ids)
  5261. for _, item := range projects {
  5262. result := QueryResult{
  5263. ID: item.ID,
  5264. Name: item.ProjectName,
  5265. Code: item.MedicalCode,
  5266. List_type_code: "201",
  5267. }
  5268. queryResult = append(queryResult, result)
  5269. }
  5270. }
  5271. admin_user_id, _ := c.GetInt64("admin_user_id")
  5272. adminUser := c.GetAdminUserInfo()
  5273. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5274. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5275. var user_name string
  5276. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  5277. if role.ID == 0 {
  5278. user_name = "xxx"
  5279. } else {
  5280. user_name = role.UserName
  5281. }
  5282. baseParams := &models.BaseParams{
  5283. SecretKey: miConfig.SecretKey,
  5284. FixmedinsCode: miConfig.Code,
  5285. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  5286. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  5287. OrgName: miConfig.OrgName,
  5288. Doctor: user_name,
  5289. }
  5290. if config.IsOpen == 1 {
  5291. for _, item := range queryResult {
  5292. var result string
  5293. if record_type == 1 {
  5294. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  5295. } else if record_type == 2 {
  5296. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  5297. } else if record_type == 3 {
  5298. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  5299. }
  5300. var dat map[string]interface{}
  5301. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5302. fmt.Println(dat)
  5303. } else {
  5304. fmt.Println(err)
  5305. }
  5306. userJSONBytes, _ := json.Marshal(dat)
  5307. var res ResultSix
  5308. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5309. utils.ErrorLog("解析失败:%v", err)
  5310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5311. return
  5312. }
  5313. if res.Infcode == 0 {
  5314. if record_type == 1 {
  5315. service.UpdateBaseDrugById(item.ID)
  5316. } else if record_type == 2 {
  5317. service.UpdateGoodInformaitonByDetail(item.ID)
  5318. } else if record_type == 3 {
  5319. service.UpdateProjectById(item.ID)
  5320. }
  5321. c.ServeSuccessJSON(map[string]interface{}{
  5322. "failed_code": 0,
  5323. "msg": "目录对照成功",
  5324. })
  5325. } else {
  5326. c.ServeSuccessJSON(map[string]interface{}{
  5327. "failed_code": -10,
  5328. "msg": res.ErrMsg,
  5329. })
  5330. }
  5331. }
  5332. }
  5333. }
  5334. func (c *HisApiController) UnCheckCode() {
  5335. ids_str := c.GetString("ids")
  5336. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  5337. admin_user_id, _ := c.GetInt64("admin_user_id")
  5338. ids_arr := strings.Split(ids_str, ",")
  5339. var queryResult []QueryResult
  5340. ids := make([]int64, 0)
  5341. for _, item := range ids_arr {
  5342. id, _ := strconv.ParseInt(item, 10, 64)
  5343. ids = append(ids, id)
  5344. }
  5345. if record_type == 1 {
  5346. drugs, _ := service.GetBatchDrugList(ids)
  5347. for _, item := range drugs {
  5348. result := QueryResult{
  5349. ID: item.ID,
  5350. Name: item.DrugName,
  5351. Code: item.MedicalInsuranceNumber,
  5352. List_type_code: "101",
  5353. }
  5354. queryResult = append(queryResult, result)
  5355. }
  5356. } else if record_type == 2 {
  5357. goods, _ := service.GetBatchGoodInformationList(ids)
  5358. for _, item := range goods {
  5359. result := QueryResult{
  5360. ID: item.ID,
  5361. Name: item.GoodName,
  5362. Code: item.MedicalInsuranceNumber,
  5363. List_type_code: "301",
  5364. }
  5365. queryResult = append(queryResult, result)
  5366. }
  5367. } else if record_type == 3 {
  5368. projects, _ := service.GetBathchMyPorjecgList(ids)
  5369. for _, item := range projects {
  5370. result := QueryResult{
  5371. ID: item.ID,
  5372. Name: item.ProjectName,
  5373. Code: item.MedicalCode,
  5374. List_type_code: "201",
  5375. }
  5376. queryResult = append(queryResult, result)
  5377. }
  5378. }
  5379. adminUser := c.GetAdminUserInfo()
  5380. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5381. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5382. var user_name string
  5383. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  5384. if role.ID == 0 {
  5385. user_name = "xxx"
  5386. } else {
  5387. user_name = role.UserName
  5388. }
  5389. baseParams := &models.BaseParams{
  5390. SecretKey: miConfig.SecretKey,
  5391. FixmedinsCode: miConfig.Code,
  5392. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  5393. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  5394. OrgName: miConfig.OrgName,
  5395. Doctor: user_name,
  5396. }
  5397. if config.IsOpen == 1 {
  5398. for _, item := range queryResult {
  5399. var result string
  5400. if record_type == 1 {
  5401. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  5402. } else if record_type == 2 {
  5403. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  5404. } else if record_type == 3 {
  5405. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  5406. }
  5407. var dat2 map[string]interface{}
  5408. if err := json.Unmarshal([]byte(result), &dat2); err == nil {
  5409. fmt.Println(dat2)
  5410. } else {
  5411. fmt.Println(err)
  5412. }
  5413. userJSONBytes, _ := json.Marshal(dat2)
  5414. var res ResultSix
  5415. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5416. utils.ErrorLog("解析失败:%v", err)
  5417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5418. return
  5419. }
  5420. if res.Infcode == 0 {
  5421. if record_type == 1 {
  5422. service.UpdateDrugByIdDetail(item.ID)
  5423. } else if record_type == 2 {
  5424. service.UpdateGoodInfoById(item.ID)
  5425. } else if record_type == 3 {
  5426. service.UpdateMyProjectById(item.ID)
  5427. }
  5428. c.ServeSuccessJSON(map[string]interface{}{
  5429. "failed_code": 0,
  5430. "msg": "撤销目录对照成功",
  5431. })
  5432. } else {
  5433. c.ServeSuccessJSON(map[string]interface{}{
  5434. "failed_code": -10,
  5435. "msg": res.ErrMsg,
  5436. })
  5437. }
  5438. }
  5439. }
  5440. }
  5441. func (c *HisApiController) GetPatientInfo() {
  5442. id_card_no := c.GetString("id_card_no")
  5443. admin_user_id, _ := c.GetInt64("admin_user_id")
  5444. patient, _ := service.GetPatientByIDCard(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  5445. if patient.ID == 0 {
  5446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5447. return
  5448. }
  5449. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  5450. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  5451. config, _ := service.GetMedicalInsuranceConfig(c.GetAdminUserInfo().CurrentOrgId)
  5452. if config.IsOpen == 1 {
  5453. result := service.Gdyb1101A(id_card_no, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  5454. var dat map[string]interface{}
  5455. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5456. fmt.Println(dat)
  5457. } else {
  5458. fmt.Println(err)
  5459. }
  5460. userJSONBytes, _ := json.Marshal(dat)
  5461. var res ResultTwo
  5462. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5463. utils.ErrorLog("解析失败:%v", err)
  5464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5465. return
  5466. }
  5467. if res.Infcode != 0 {
  5468. c.ServeSuccessJSON(map[string]interface{}{
  5469. "failed_code": -10,
  5470. "msg": res.ErrMsg,
  5471. })
  5472. } else {
  5473. c.ServeSuccessJSON(map[string]interface{}{
  5474. "failed_code": 0,
  5475. "info": res,
  5476. })
  5477. }
  5478. }
  5479. }
  5480. func (c *HisApiController) PsnPutOnRecord() {
  5481. record_type, _ := c.GetInt64("type")
  5482. patient_id, _ := c.GetInt64("patient_id")
  5483. admin_user_id, _ := c.GetInt64("admin_user_id")
  5484. start_time := c.GetString("start_time")
  5485. end_time := c.GetString("end_time")
  5486. adminUser := c.GetAdminUserInfo()
  5487. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5488. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5489. var patients []*models.Patients
  5490. if record_type == 1 { //全部备案
  5491. patient, _ := service.GetAllPatient(adminUser.CurrentOrgId)
  5492. patients = append(patients, patient...)
  5493. } else { //单个备案
  5494. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  5495. patients = append(patients, patient)
  5496. }
  5497. var user_name string
  5498. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  5499. if role.ID == 0 {
  5500. user_name = "xxx"
  5501. } else {
  5502. user_name = role.UserName
  5503. }
  5504. if config.IsOpen == 1 {
  5505. for _, item := range patients {
  5506. 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
  5507. resp, requestErr := http.Get(api)
  5508. if requestErr != nil {
  5509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5510. return
  5511. }
  5512. defer resp.Body.Close()
  5513. body, ioErr := ioutil.ReadAll(resp.Body)
  5514. if ioErr != nil {
  5515. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  5516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5517. return
  5518. }
  5519. var respJSON map[string]interface{}
  5520. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  5521. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  5522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5523. return
  5524. }
  5525. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  5526. userJSONBytes, _ := json.Marshal(userJSON)
  5527. var res ResultTwo
  5528. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5529. utils.ErrorLog("解析失败:%v", err)
  5530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5531. return
  5532. }
  5533. if res.Infcode == 0 {
  5534. result := service.Gdyb2505(res.Output.Baseinfo.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, start_time, end_time)
  5535. var dat map[string]interface{}
  5536. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5537. fmt.Println(dat)
  5538. } else {
  5539. fmt.Println(err)
  5540. }
  5541. userJSONBytes, _ := json.Marshal(dat)
  5542. var res2 ResultThirteen
  5543. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  5544. utils.ErrorLog("解析失败:%v", err)
  5545. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5546. return
  5547. }
  5548. if res2.Infcode == 0 {
  5549. psnResult := &models.GdybPsnRecord{
  5550. UserOrgId: adminUser.CurrentOrgId,
  5551. PatientId: item.ID,
  5552. PsnNo: res.Output.Baseinfo.PsnNo,
  5553. Ctime: time.Now().Unix(),
  5554. Mtime: time.Now().Unix(),
  5555. Status: 1,
  5556. IsCancel: 1,
  5557. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  5558. }
  5559. service.CreatePsnRecord(psnResult)
  5560. } else {
  5561. c.ServeSuccessJSON(map[string]interface{}{
  5562. "failed_code": -10,
  5563. "msg": res2.ErrMsg,
  5564. })
  5565. return
  5566. }
  5567. }
  5568. }
  5569. }
  5570. }
  5571. func (c *HisApiController) PsnUnPutOnRecord() {
  5572. id, _ := c.GetInt64("id")
  5573. //record_type, _ := c.GetInt64("type")
  5574. admin_user_id, _ := c.GetInt64("admin_user_id")
  5575. adminUser := c.GetAdminUserInfo()
  5576. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5577. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5578. var user_name string
  5579. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  5580. if role.ID == 0 {
  5581. user_name = "xxx"
  5582. } else {
  5583. user_name = role.UserName
  5584. }
  5585. psn_record, _ := service.GetPsnRecordById(id)
  5586. if psn_record.ID == 0 {
  5587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  5588. return
  5589. }
  5590. if config.IsOpen == 1 {
  5591. result := service.Gdyb2506(psn_record.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  5592. var dat map[string]interface{}
  5593. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5594. fmt.Println(dat)
  5595. } else {
  5596. fmt.Println(err)
  5597. }
  5598. userJSONBytes, _ := json.Marshal(dat)
  5599. var res ResultFourteen
  5600. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5601. utils.ErrorLog("解析失败:%v", err)
  5602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5603. return
  5604. }
  5605. if res.Infcode == 0 {
  5606. psn_record.IsCancel = 2
  5607. service.CreatePsnRecord(&psn_record)
  5608. } else {
  5609. c.ServeSuccessJSON(map[string]interface{}{
  5610. "failed_code": -10,
  5611. "msg": res.ErrMsg,
  5612. })
  5613. return
  5614. }
  5615. }
  5616. }
  5617. func (c *HisApiController) PsnPutNCDSOnRecord() {
  5618. patient_id, _ := c.GetInt64("patient_id")
  5619. insutype := c.GetString("insutype")
  5620. psn_no := c.GetString("psn_no")
  5621. doctor_id, _ := c.GetInt64("doctor_id")
  5622. sick_id, _ := c.GetInt64("sick_id")
  5623. department_id, _ := c.GetInt64("department_id")
  5624. adminUser := c.GetAdminUserInfo()
  5625. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  5626. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5627. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5628. sick, _ := service.FindSickById(sick_id)
  5629. doctor, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, doctor_id)
  5630. if config.IsOpen == 1 {
  5631. 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)
  5632. var dat map[string]interface{}
  5633. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5634. fmt.Println(dat)
  5635. } else {
  5636. fmt.Println(err)
  5637. }
  5638. userJSONBytes, _ := json.Marshal(dat)
  5639. var res2 ResultThirteen
  5640. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  5641. utils.ErrorLog("解析失败:%v", err)
  5642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5643. return
  5644. }
  5645. if res2.Infcode == 0 {
  5646. psnResult := &models.GdybPsnNcdsRecord{
  5647. UserOrgId: adminUser.CurrentOrgId,
  5648. PatientId: patient.ID,
  5649. PsnNo: psn_no,
  5650. DoctorId: doctor.AdminUserId,
  5651. DepartmentId: department_id,
  5652. SickType: sick_id,
  5653. Insutype: insutype,
  5654. Ctime: time.Now().Unix(),
  5655. Mtime: time.Now().Unix(),
  5656. Status: 1,
  5657. IsCancel: 1,
  5658. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  5659. }
  5660. service.CreatePsnNCDSRecord(psnResult)
  5661. c.ServeSuccessJSON(map[string]interface{}{
  5662. "failed_code": 0,
  5663. "msg": "备案成功",
  5664. "result": psnResult,
  5665. })
  5666. } else {
  5667. c.ServeSuccessJSON(map[string]interface{}{
  5668. "failed_code": -10,
  5669. "msg": res2.ErrMsg,
  5670. })
  5671. return
  5672. }
  5673. }
  5674. }
  5675. func (c *HisApiController) PsnPutUnNCDSOnRecord() {
  5676. id, _ := c.GetInt64("id")
  5677. admin_user_id, _ := c.GetInt64("admin_user_id")
  5678. adminUser := c.GetAdminUserInfo()
  5679. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5680. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5681. var user_name string
  5682. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  5683. if role.ID == 0 {
  5684. user_name = "xxx"
  5685. } else {
  5686. user_name = role.UserName
  5687. }
  5688. psn_record, _ := service.GetPsnNCDSRecordById(id)
  5689. if psn_record.ID == 0 {
  5690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  5691. return
  5692. }
  5693. if config.IsOpen == 1 {
  5694. result := service.Gdyb2504(psn_record.PsnNo, miConfig.OrgName, user_name, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  5695. var dat map[string]interface{}
  5696. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5697. fmt.Println(dat)
  5698. } else {
  5699. fmt.Println(err)
  5700. }
  5701. userJSONBytes, _ := json.Marshal(dat)
  5702. var res ResultFourteen
  5703. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5704. utils.ErrorLog("解析失败:%v", err)
  5705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5706. return
  5707. }
  5708. if res.Infcode == 0 {
  5709. psn_record.IsCancel = 2
  5710. service.CreatePsnNCDSRecord(&psn_record)
  5711. c.ServeSuccessJSON(map[string]interface{}{
  5712. "failed_code": 0,
  5713. "msg": "撤销备案成功",
  5714. })
  5715. } else {
  5716. c.ServeSuccessJSON(map[string]interface{}{
  5717. "failed_code": -10,
  5718. "msg": res.ErrMsg,
  5719. })
  5720. return
  5721. }
  5722. }
  5723. }
  5724. func (c *HisApiController) TestTest() {
  5725. patient, _ := service.GetHisPatientInfo(4, 456, 1619712000)
  5726. fmt.Println(patient.Iinfo)
  5727. }
  5728. type CustomData struct {
  5729. MsgId string
  5730. PsnNo string
  5731. Info string
  5732. }
  5733. func (c *HisApiController) ReversalData() {
  5734. var customData []*CustomData
  5735. custom := &CustomData{
  5736. MsgId: "H44022900158202103301714472004",
  5737. PsnNo: "44020000001101329945",
  5738. Info: "2207",
  5739. }
  5740. customData = append(customData, custom)
  5741. custom1 := &CustomData{
  5742. MsgId: "H4402290015820210330172057803",
  5743. PsnNo: "44020000001101161813",
  5744. Info: "2207",
  5745. }
  5746. customData = append(customData, custom1)
  5747. custom2 := &CustomData{
  5748. MsgId: "H44022900158202103301705198813",
  5749. PsnNo: "44190000133097375417",
  5750. Info: "2207",
  5751. }
  5752. customData = append(customData, custom2)
  5753. custom3 := &CustomData{
  5754. MsgId: "H44022900158202103301715524756",
  5755. PsnNo: "44020000001100187221",
  5756. Info: "2207",
  5757. }
  5758. customData = append(customData, custom3)
  5759. custom4 := &CustomData{
  5760. MsgId: "H44022900158202103301730376224",
  5761. PsnNo: "44020000001101959155",
  5762. Info: "2207",
  5763. }
  5764. customData = append(customData, custom4)
  5765. custom5 := &CustomData{
  5766. MsgId: "H44022900158202103301748008725",
  5767. PsnNo: "44020000001104246641",
  5768. Info: "2207",
  5769. }
  5770. customData = append(customData, custom5)
  5771. custom6 := &CustomData{
  5772. MsgId: "H44022900158202103301718096755",
  5773. PsnNo: "44020000001102211860",
  5774. Info: "2207",
  5775. }
  5776. customData = append(customData, custom6)
  5777. custom7 := &CustomData{
  5778. MsgId: "H44022900158202103301736551640",
  5779. PsnNo: "44020000001102687718",
  5780. Info: "2207",
  5781. }
  5782. customData = append(customData, custom7)
  5783. custom8 := &CustomData{
  5784. MsgId: "H44022900158202103301743097676",
  5785. PsnNo: "44020000001102127785",
  5786. Info: "2207",
  5787. }
  5788. customData = append(customData, custom8)
  5789. custom9 := &CustomData{
  5790. MsgId: "H44022900158202103301712304203",
  5791. PsnNo: "44020000001101518097",
  5792. Info: "2207",
  5793. }
  5794. customData = append(customData, custom9)
  5795. custom10 := &CustomData{
  5796. MsgId: "H44022900158202103301738448785",
  5797. PsnNo: "44020000001100500813",
  5798. Info: "2207",
  5799. }
  5800. customData = append(customData, custom10)
  5801. custom11 := &CustomData{
  5802. MsgId: "H44022900158202103301732455843",
  5803. PsnNo: "44020000001102690557",
  5804. Info: "2207",
  5805. }
  5806. customData = append(customData, custom11)
  5807. custom12 := &CustomData{
  5808. MsgId: "H44022900158202103301745421708",
  5809. PsnNo: "44020000001102211928",
  5810. Info: "2207",
  5811. }
  5812. customData = append(customData, custom12)
  5813. custom1212 := &CustomData{
  5814. MsgId: "H440229001582021033017351627",
  5815. PsnNo: "44020000001102481733",
  5816. Info: "2207",
  5817. }
  5818. customData = append(customData, custom1212)
  5819. custom13 := &CustomData{
  5820. MsgId: "H44022900158202103301740327951",
  5821. PsnNo: "44020000001103174866",
  5822. Info: "2207",
  5823. }
  5824. customData = append(customData, custom13)
  5825. custom14 := &CustomData{
  5826. MsgId: "H4402290015820210330174922668",
  5827. PsnNo: "44020000001102927272",
  5828. Info: "2207",
  5829. }
  5830. customData = append(customData, custom14)
  5831. custom15 := &CustomData{
  5832. MsgId: "H44022900158202103301752362273",
  5833. PsnNo: "44020000001102942890",
  5834. Info: "2207",
  5835. }
  5836. customData = append(customData, custom15)
  5837. custom16 := &CustomData{
  5838. MsgId: "H44022900158202103301751082917",
  5839. PsnNo: "44020000001101662162",
  5840. Info: "2207",
  5841. }
  5842. customData = append(customData, custom16)
  5843. custom17 := &CustomData{
  5844. MsgId: "H44022900158202103301754147728",
  5845. PsnNo: "44020000000229014511",
  5846. Info: "2207",
  5847. }
  5848. customData = append(customData, custom17)
  5849. adminUser := c.GetAdminUserInfo()
  5850. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5851. for _, item := range customData {
  5852. result := service.Gdyb2601(item.PsnNo, item.MsgId, item.Info, miConfig.OrgName, "张俊杰", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  5853. fmt.Println(result)
  5854. }
  5855. }
  5856. func (c *HisApiController) ReversalOtherData() {
  5857. var customData []*CustomData
  5858. custom := &CustomData{
  5859. MsgId: "H44022900158202103301714472004",
  5860. PsnNo: "44020000001101329945",
  5861. Info: "2208",
  5862. }
  5863. customData = append(customData, custom)
  5864. custom1 := &CustomData{
  5865. MsgId: "H4402290015820210330172057803",
  5866. PsnNo: "44020000001101161813",
  5867. Info: "2208",
  5868. }
  5869. customData = append(customData, custom1)
  5870. custom2 := &CustomData{
  5871. MsgId: "H44022900158202103301705198813",
  5872. PsnNo: "44190000133097375417",
  5873. Info: "2208",
  5874. }
  5875. customData = append(customData, custom2)
  5876. custom3 := &CustomData{
  5877. MsgId: "H44022900158202103301715524756",
  5878. PsnNo: "44020000001100187221",
  5879. Info: "2208",
  5880. }
  5881. customData = append(customData, custom3)
  5882. custom4 := &CustomData{
  5883. MsgId: "H44022900158202103301730376224",
  5884. PsnNo: "44020000001101959155",
  5885. Info: "2208",
  5886. }
  5887. customData = append(customData, custom4)
  5888. custom5 := &CustomData{
  5889. MsgId: "H44022900158202103301748008725",
  5890. PsnNo: "44020000001104246641",
  5891. Info: "2208",
  5892. }
  5893. customData = append(customData, custom5)
  5894. custom6 := &CustomData{
  5895. MsgId: "H44022900158202103301718096755",
  5896. PsnNo: "44020000001102211860",
  5897. Info: "2208",
  5898. }
  5899. customData = append(customData, custom6)
  5900. custom7 := &CustomData{
  5901. MsgId: "H44022900158202103301736551640",
  5902. PsnNo: "44020000001102687718",
  5903. Info: "2208",
  5904. }
  5905. customData = append(customData, custom7)
  5906. custom8 := &CustomData{
  5907. MsgId: "H44022900158202103301743097676",
  5908. PsnNo: "44020000001102127785",
  5909. Info: "2208",
  5910. }
  5911. customData = append(customData, custom8)
  5912. custom9 := &CustomData{
  5913. MsgId: "H44022900158202103301712304203",
  5914. PsnNo: "44020000001101518097",
  5915. Info: "2208",
  5916. }
  5917. customData = append(customData, custom9)
  5918. custom10 := &CustomData{
  5919. MsgId: "H44022900158202103301738448785",
  5920. PsnNo: "44020000001100500813",
  5921. Info: "2208",
  5922. }
  5923. customData = append(customData, custom10)
  5924. custom11 := &CustomData{
  5925. MsgId: "H44022900158202103301732455843",
  5926. PsnNo: "44020000001102690557",
  5927. Info: "2208",
  5928. }
  5929. customData = append(customData, custom11)
  5930. custom12 := &CustomData{
  5931. MsgId: "H44022900158202103301745421708",
  5932. PsnNo: "44020000001102211928",
  5933. Info: "2208",
  5934. }
  5935. customData = append(customData, custom12)
  5936. custom1212 := &CustomData{
  5937. MsgId: "H440229001582021033017351627",
  5938. PsnNo: "44020000001102481733",
  5939. Info: "2208",
  5940. }
  5941. customData = append(customData, custom1212)
  5942. custom13 := &CustomData{
  5943. MsgId: "H44022900158202103301740327951",
  5944. PsnNo: "44020000001103174866",
  5945. Info: "2208",
  5946. }
  5947. customData = append(customData, custom13)
  5948. custom14 := &CustomData{
  5949. MsgId: "H4402290015820210330174922668",
  5950. PsnNo: "44020000001102927272",
  5951. Info: "2208",
  5952. }
  5953. customData = append(customData, custom14)
  5954. custom15 := &CustomData{
  5955. MsgId: "H44022900158202103301752362273",
  5956. PsnNo: "44020000001102942890",
  5957. Info: "2208",
  5958. }
  5959. customData = append(customData, custom15)
  5960. custom16 := &CustomData{
  5961. MsgId: "H44022900158202103301751082917",
  5962. PsnNo: "44020000001101662162",
  5963. Info: "2208",
  5964. }
  5965. customData = append(customData, custom16)
  5966. custom17 := &CustomData{
  5967. MsgId: "H44022900158202103301754147728",
  5968. PsnNo: "44020000000229014511",
  5969. Info: "2208",
  5970. }
  5971. customData = append(customData, custom17)
  5972. adminUser := c.GetAdminUserInfo()
  5973. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5974. for _, item := range customData {
  5975. result := service.Gdyb2601(item.PsnNo, item.MsgId, item.Info, miConfig.OrgName, "张俊杰", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  5976. fmt.Println(result)
  5977. }
  5978. }
  5979. func PathExists(path string) (bool, error) {
  5980. _, err := os.Stat(path)
  5981. if err == nil {
  5982. return true, nil
  5983. }
  5984. if os.IsNotExist(err) {
  5985. return false, nil
  5986. }
  5987. return false, err
  5988. }
  5989. //创建文件夹
  5990. func Mkdir(dir string) {
  5991. // 创建文件夹
  5992. exist, err := PathExists(dir)
  5993. if err != nil {
  5994. fmt.Println(err.Error())
  5995. } else {
  5996. if exist {
  5997. fmt.Println(dir + "文件夹已存在!")
  5998. } else {
  5999. // 文件夹名称,权限
  6000. err := os.Mkdir(dir, os.ModePerm)
  6001. if err != nil {
  6002. fmt.Println(dir+"文件夹创建失败:", err.Error())
  6003. } else {
  6004. fmt.Println(dir + "文件夹创建成功!")
  6005. }
  6006. }
  6007. }
  6008. }
  6009. //压缩文件
  6010. func Zip(srcFile string, destZip string) error {
  6011. zipfile, err := os.Create(destZip)
  6012. if err != nil {
  6013. return err
  6014. }
  6015. defer zipfile.Close()
  6016. archive := zip.NewWriter(zipfile)
  6017. defer archive.Close()
  6018. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  6019. if err != nil {
  6020. return err
  6021. }
  6022. header, err := zip.FileInfoHeader(info)
  6023. if err != nil {
  6024. return err
  6025. }
  6026. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  6027. // header.Name = path
  6028. if info.IsDir() {
  6029. header.Name += "/"
  6030. } else {
  6031. header.Method = zip.Deflate
  6032. }
  6033. writer, err := archive.CreateHeader(header)
  6034. if err != nil {
  6035. return err
  6036. }
  6037. if !info.IsDir() {
  6038. file, err := os.Open(path)
  6039. if err != nil {
  6040. return err
  6041. }
  6042. defer file.Close()
  6043. _, err = io.Copy(writer, file)
  6044. }
  6045. return err
  6046. })
  6047. return err
  6048. }
  6049. func ReadFile(filePath string) []byte {
  6050. f, err := os.Open(filePath)
  6051. if err != nil {
  6052. fmt.Println("read file fail", err)
  6053. return nil
  6054. }
  6055. defer f.Close()
  6056. fd, err := ioutil.ReadAll(f)
  6057. if err != nil {
  6058. fmt.Println("read to fd fail", err)
  6059. return nil
  6060. }
  6061. return fd
  6062. }
  6063. func RemoveRepeatedTeam(arr []*models.HisOrderInfo) (newArr []*models.HisOrderInfo) {
  6064. newArr = make([]*models.HisOrderInfo, 0)
  6065. for i := 0; i < len(arr); i++ {
  6066. repeat := false
  6067. for j := i + 1; j < len(arr); j++ {
  6068. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  6069. repeat = true
  6070. break
  6071. }
  6072. }
  6073. if !repeat {
  6074. newArr = append(newArr, arr[i])
  6075. }
  6076. }
  6077. return
  6078. }
  6079. func saveRegisterLog(result string) {
  6080. org_id, _ := beego.AppConfig.Int64("org_id")
  6081. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  6082. dir := miConfig.OrgName + "日志"
  6083. utils.Mkdir(dir)
  6084. month := time.Unix(1557042972, 0).Format("1")
  6085. year := time.Now().Format("2006")
  6086. month = time.Now().Format("01")
  6087. day := time.Now().Format("02")
  6088. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  6089. file_name := file + ".txt"
  6090. file_path := miConfig.OrgName + "日志" + "/" + file_name
  6091. exist, _ := utils.PathExists(file_path)
  6092. if exist { //存在
  6093. fmt.Println("存在")
  6094. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  6095. if err != nil {
  6096. fmt.Println("read fail")
  6097. }
  6098. content := "\r\n" + result
  6099. n, _ := f.Seek(0, 2)
  6100. _, err = f.WriteAt([]byte(content), n)
  6101. } else { //不存在
  6102. fmt.Println("文件不存在,创建文件")
  6103. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  6104. defer f.Close()
  6105. if err != nil {
  6106. } else {
  6107. _, err = f.Write([]byte("记录日志"))
  6108. }
  6109. }
  6110. }
  6111. func saveLog(result string, request string, infno string, desc string) {
  6112. org_id, _ := beego.AppConfig.Int64("org_id")
  6113. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  6114. dir := miConfig.OrgName + "日志"
  6115. utils.Mkdir(dir)
  6116. month := time.Unix(1557042972, 0).Format("1")
  6117. year := time.Now().Format("2006")
  6118. month = time.Now().Format("01")
  6119. day := time.Now().Format("02")
  6120. hour := time.Now().Format("15")
  6121. min := time.Now().Format("04")
  6122. sec := time.Now().Format("05")
  6123. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  6124. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  6125. file_name := file + ".txt"
  6126. file_path := miConfig.OrgName + "日志" + "/" + file_name
  6127. exist, _ := utils.PathExists(file_path)
  6128. if exist { //存在
  6129. fmt.Println("存在")
  6130. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  6131. if err != nil {
  6132. fmt.Println("read fail")
  6133. }
  6134. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  6135. n, _ := f.Seek(0, 2)
  6136. _, err = f.WriteAt([]byte(content), n)
  6137. } else { //不存在
  6138. fmt.Println("文件不存在,创建文件")
  6139. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  6140. defer f.Close()
  6141. if err != nil {
  6142. } else {
  6143. _, err = f.Write([]byte("记录日志"))
  6144. }
  6145. }
  6146. }