zh_his_api_controller.go 277KB

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