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. var insuplc_admdvs string
  1426. if len(patient.InsuplcAdmdvs) > 0 {
  1427. insuplc_admdvs = patient.InsuplcAdmdvs
  1428. } else {
  1429. insuplc_admdvs = miConfig.InsuplcAdmdvs
  1430. }
  1431. result, request_log, result_log = service.ZHGdyb1101(patient.IdCardNo, miConfig.OrgName, role.UserName, miConfig.Code, insuplc_admdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 2, "", 1, "",admin_user_id)
  1432. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  1433. }
  1434. //result := service.Gdyb1101A(id_card_no, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, patient.Name)
  1435. var dat map[string]interface{}
  1436. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1437. fmt.Println(dat)
  1438. } else {
  1439. fmt.Println(err)
  1440. }
  1441. userJSONBytes, _ := json.Marshal(dat)
  1442. var res ResultTwo
  1443. var resTwo10265 ResultTwo10265
  1444. if miConfig.Code == "H15049901371" {
  1445. if err := json.Unmarshal(userJSONBytes, &resTwo10265); err != nil {
  1446. utils.ErrorLog("解析失败:%v", err)
  1447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1448. return
  1449. }
  1450. Infcode, _ := strconv.ParseInt(resTwo10265.Infcode, 10, 64)
  1451. res.Infcode = Infcode
  1452. res.ErrMsg = resTwo10265.ErrMsg
  1453. res.Output = resTwo10265.Output
  1454. res.InfRefmsgid = resTwo10265.InfRefmsgid
  1455. res.RespondTime = resTwo10265.RespondTime
  1456. res.WarnInfo = resTwo10265.WarnInfo
  1457. }else if miConfig.MdtrtareaAdmvs == "441799" {
  1458. //请求内网数据
  1459. api := miConfig.Url + "gdyb/1101?cert_no=" + patient.IdCardNo +
  1460. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  1461. "&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
  1462. resp, requestErr := http.Get(api)
  1463. if requestErr != nil {
  1464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1465. return
  1466. }
  1467. body, ioErr := ioutil.ReadAll(resp.Body)
  1468. if ioErr != nil {
  1469. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1471. return
  1472. }
  1473. var respJSON map[string]interface{}
  1474. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1475. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1477. return
  1478. }
  1479. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1480. result_byte, _ := json.Marshal(respJSON)
  1481. result = string(result_byte)
  1482. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  1483. if err := json.Unmarshal([]byte(result), &res); err != nil {
  1484. utils.ErrorLog("解析失败:%v", err)
  1485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1486. return
  1487. }
  1488. } else if miConfig.MdtrtareaAdmvs == "450721"{
  1489. c.ServeSuccessJSON(map[string]interface{}{
  1490. "msg": "",
  1491. })
  1492. } else {
  1493. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1494. utils.ErrorLog("解析失败:%v", err)
  1495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1496. return
  1497. }
  1498. }
  1499. var insutypes []string
  1500. var insutype string
  1501. var is390 int = 0
  1502. var is310 int = 0
  1503. for _, item := range res.Output.Iinfo {
  1504. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1505. insutypes = append(insutypes, item.Insutype)
  1506. }
  1507. }
  1508. if len(insutypes) == 1 {
  1509. insutype = insutypes[0]
  1510. } else {
  1511. for _, i := range insutypes {
  1512. if i == "390" {
  1513. is390 = 1
  1514. }
  1515. if i == "310" {
  1516. is310 = 1
  1517. }
  1518. }
  1519. }
  1520. if is390 == 1 {
  1521. insutype = "390"
  1522. }
  1523. if is310 == 1 {
  1524. insutype = "310"
  1525. }
  1526. if len(insutypes) == 0 {
  1527. insutype = "310"
  1528. }
  1529. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  1530. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  1531. infoStr := string(Iinfos)
  1532. idetinfoStr := string(Idetinfos)
  1533. psn := &models.HisPsn{
  1534. PsnNo: res.Output.Baseinfo.PsnNo,
  1535. Age: res.Output.Baseinfo.Age,
  1536. PatientId: patient.ID,
  1537. Certno: res.Output.Baseinfo.Certno,
  1538. Gend: res.Output.Baseinfo.Gend,
  1539. Naty: res.Output.Baseinfo.Naty,
  1540. PsnCertType: res.Output.Baseinfo.PsnCertType,
  1541. PsnName: res.Output.Baseinfo.PsnName,
  1542. Idetinfo: idetinfoStr,
  1543. Insuinfo: infoStr,
  1544. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1545. VerifyNumber: "",
  1546. }
  1547. service.CreateHisPsn(psn)
  1548. if res.Infcode == -1 {
  1549. c.ServeSuccessJSON(map[string]interface{}{
  1550. "failed_code": -10,
  1551. "msg": res.ErrMsg,
  1552. })
  1553. } else {
  1554. c.ServeSuccessJSON(map[string]interface{}{
  1555. "failed_code": 0,
  1556. "info": res,
  1557. "insutype": insutype,
  1558. })
  1559. }
  1560. }
  1561. }
  1562. func (c *ZHHisApiController) GetZHInHospitalCheck() {
  1563. id, _ := c.GetInt64("id")
  1564. record_time := c.GetString("record_time")
  1565. name := c.GetString("name")
  1566. phone := c.GetString("phone")
  1567. id_card_type, _ := c.GetInt64("id_card_type")
  1568. certificates, _ := c.GetInt64("certificates")
  1569. id_card_no := c.GetString("id_card_no")
  1570. doctor, _ := c.GetInt64("doctor")
  1571. admin_user_id, _ := c.GetInt64("admin_user_id")
  1572. department, _ := c.GetInt64("department")
  1573. adm_bed, _ := c.GetInt64("adm_bed")
  1574. diagnosis_ids := c.GetString("diagnosis")
  1575. sick_type, _ := c.GetInt64("sick_type")
  1576. start_time := c.GetString("start_time")
  1577. insuplc_admdvs := c.GetString("insuplc_admdvs")
  1578. balance_accounts_type, _ := c.GetInt64("balance_accounts_type")
  1579. social_type, _ := c.GetInt64("social_type")
  1580. psn_type, _ := c.GetInt64("psn_type")
  1581. //reg_type, _ := c.GetInt64("p_type")
  1582. med_type, _ := c.GetInt64("med_type")
  1583. diagnosis_ids_arr := strings.Split(diagnosis_ids, "-")
  1584. timeLayout := "2006-01-02"
  1585. loc, _ := time.LoadLocation("Local")
  1586. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1587. if err != nil {
  1588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1589. return
  1590. }
  1591. recordDateTime := theTime.Unix()
  1592. adminInfo := c.GetAdminUserInfo()
  1593. record, _ := service.GetLastHospitalRecord(id, adminInfo.CurrentOrgId)
  1594. if record.ID != 0 {
  1595. if record.InHospitalStatus == 1 && record.OutHospitalStatus != 1 {
  1596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalExistDataException)
  1597. return
  1598. }
  1599. }
  1600. var patient service.Patients
  1601. if id == 0 {
  1602. patient, _ = service.GetPatientByIDCard(id_card_no, adminInfo.CurrentOrgId)
  1603. } else {
  1604. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  1605. }
  1606. diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  1607. sickConfig, _ := service.FindSickById(sick_type)
  1608. departmentInfo, _ := service.GetDepartMentDetail(department)
  1609. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1610. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1611. var result string
  1612. var request_log string
  1613. var result_log string
  1614. var res2 ResultTwo
  1615. var resTwo10265 ResultTwo10265
  1616. psn_info, _ := service.GetPsnByPatientId(patient.ID)
  1617. if miConfig.MdtrtareaAdmvs == "150499" {
  1618. if id_card_type == 2 {
  1619. mdtrt_cert_no := ""
  1620. mdtrt_cert_no = id_card_no
  1621. //请求内网数据
  1622. api := "http://172.16.13.254:9532/" + "nmyb/1101?cert_no=" + mdtrt_cert_no +
  1623. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  1624. "&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
  1625. resp, requestErr := http.Get(api)
  1626. if requestErr != nil {
  1627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1628. return
  1629. }
  1630. body, ioErr := ioutil.ReadAll(resp.Body)
  1631. if ioErr != nil {
  1632. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1634. return
  1635. }
  1636. var respJSON map[string]interface{}
  1637. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1638. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1640. return
  1641. }
  1642. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1643. result_byte, _ := json.Marshal(respJSON)
  1644. result = string(result_byte)
  1645. var dat map[string]interface{}
  1646. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1647. fmt.Println(dat)
  1648. } else {
  1649. fmt.Println(err)
  1650. }
  1651. userJSONBytes, _ := json.Marshal(dat)
  1652. if err := json.Unmarshal(userJSONBytes, &resTwo10265); err != nil {
  1653. utils.ErrorLog("解析失败:%v", err)
  1654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1655. return
  1656. }
  1657. Infcode, _ := strconv.ParseInt(resTwo10265.Infcode, 10, 64)
  1658. res2.Infcode = Infcode
  1659. res2.ErrMsg = resTwo10265.ErrMsg
  1660. res2.Output = resTwo10265.Output
  1661. res2.InfRefmsgid = resTwo10265.InfRefmsgid
  1662. res2.RespondTime = resTwo10265.RespondTime
  1663. res2.WarnInfo = resTwo10265.WarnInfo
  1664. } else {
  1665. res2.Infcode = 0
  1666. res2.Output.Baseinfo.PsnNo = psn_info.PsnNo
  1667. res2.Output.Baseinfo.Certno = patient.IdCardNo
  1668. }
  1669. } else if miConfig.MdtrtareaAdmvs == "421182" {
  1670. res2.Infcode = 0
  1671. res2.Output.Baseinfo.PsnNo = psn_info.PsnNo
  1672. res2.Output.Baseinfo.Certno = patient.IdCardNo
  1673. } else if miConfig.MdtrtareaAdmvs == "360399" {
  1674. //res2.Infcode = 0
  1675. //res2.Output.Baseinfo.PsnNo = psn_info.PsnNo
  1676. //res2.Output.Baseinfo.Certno = patient.IdCardNo
  1677. //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, "")
  1678. if id_card_type == 1{
  1679. bas := strings.Split(psn_info.CardInfo, "|")
  1680. cardNumber := bas[3]
  1681. 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, "")
  1682. saveLog(result, request_log, "1101", "人员基本信息获取")
  1683. }else{
  1684. cardNumber := psn_info.VerifyNumber
  1685. 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)
  1686. saveLog(result, request_log, "1101", "人员基本信息获取")
  1687. }
  1688. } else {
  1689. 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)
  1690. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  1691. }
  1692. doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor)
  1693. deviceNumber, _ := service.GetDeviceNumberByID(adm_bed, adminInfo.CurrentOrgId)
  1694. if miConfig.MdtrtareaAdmvs != "150499" && miConfig.MdtrtareaAdmvs != "421182" {
  1695. var dat map[string]interface{}
  1696. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1697. fmt.Println(dat)
  1698. } else {
  1699. fmt.Println(err)
  1700. }
  1701. userJSONBytes, _ := json.Marshal(dat)
  1702. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  1703. utils.ErrorLog("解析失败:%v", err)
  1704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1705. return
  1706. }
  1707. }
  1708. var infoStr string
  1709. if miConfig.MdtrtareaAdmvs == "150499" {
  1710. if id_card_type == 2 {
  1711. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  1712. infoStr = string(Iinfos)
  1713. } else {
  1714. infoStr = psn_info.Insuinfo
  1715. }
  1716. } else if miConfig.MdtrtareaAdmvs == "421182" {
  1717. infoStr = psn_info.Insuinfo
  1718. } else {
  1719. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  1720. infoStr = string(Iinfos)
  1721. }
  1722. var rf []*ResultFive
  1723. json.Unmarshal([]byte(infoStr), &rf)
  1724. var insutypes []*ResultFive
  1725. var insutype string
  1726. var is390 int = 0
  1727. var is310 int = 0
  1728. for _, item := range rf {
  1729. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1730. insutypes = append(insutypes, item)
  1731. }
  1732. }
  1733. if len(insutypes) == 1 {
  1734. insutype = insutypes[0].Insutype
  1735. //insuplc_admdvs = insutypes[0].InsuplcAdmdvs
  1736. } else {
  1737. for _, i := range insutypes {
  1738. if i.Insutype == "390" {
  1739. is390 = 1
  1740. }
  1741. if i.Insutype == "310" {
  1742. is310 = 1
  1743. }
  1744. }
  1745. }
  1746. if is390 == 1 {
  1747. insutype = "390"
  1748. }
  1749. if is310 == 1 {
  1750. insutype = "310"
  1751. }
  1752. if len(insutypes) == 0 {
  1753. insutype = "310"
  1754. }
  1755. if len(insutypes) == 2 {
  1756. insutype = strconv.FormatInt(social_type, 10)
  1757. }
  1758. //for _, item := range rf {
  1759. // if item.Insutype == insutype {
  1760. // insuplc_admdvs = item.InsuplcAdmdvs
  1761. // }
  1762. //}
  1763. if res2.Infcode == 0 {
  1764. //var insutypes []string
  1765. //
  1766. //var insutype string
  1767. //var is390 int = 0
  1768. //var is310 int = 0
  1769. //for _, item := range res2.Output.Iinfo {
  1770. // if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1771. // insutypes = append(insutypes, item.Insutype)
  1772. // }
  1773. //}
  1774. //if len(insutypes) == 1 {
  1775. // insutype = insutypes[0]
  1776. //} else {
  1777. // for _, i := range insutypes {
  1778. // if i == "390" {
  1779. // is390 = 1
  1780. // }
  1781. //
  1782. // if i == "310" {
  1783. // is310 = 1
  1784. // }
  1785. // }
  1786. //}
  1787. //if is390 == 1 {
  1788. // insutype = "390"
  1789. //}
  1790. //if is310 == 1 {
  1791. // insutype = "310"
  1792. //}
  1793. //
  1794. //if len(insutypes) == 0 {
  1795. // insutype = "310"
  1796. //}
  1797. if len(insuplc_admdvs) == 0 {
  1798. insuplc_admdvs = miConfig.InsuplcAdmdvs
  1799. }
  1800. timestamp := time.Now().Unix()
  1801. tempTime := time.Unix(timestamp, 0)
  1802. timeFormat := tempTime.Format("20060102150405")
  1803. chrgBchno := rand.Intn(100000) + 10000
  1804. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(id, 10)
  1805. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  1806. var struct2401 service.Struct2401
  1807. //insutype = "310"
  1808. struct2401.Insutype = insutype
  1809. psn_info, _ := service.GetPsnByPatientId(patient.ID)
  1810. if id_card_type == 1 {
  1811. struct2401.MdtrtCertType = "03"
  1812. bas := strings.Split(psn_info.CardInfo, "|")
  1813. cardNumber := bas[2]
  1814. struct2401.MdtrtCertNo = cardNumber
  1815. struct2401.PsnNo = res2.Output.Baseinfo.PsnNo
  1816. } else if id_card_type == 4 {
  1817. struct2401.MdtrtCertType = "01"
  1818. struct2401.MdtrtCertNo = psn_info.VerifyNumber
  1819. struct2401.PsnNo = psn_info.PsnNo
  1820. } else {
  1821. struct2401.MdtrtCertType = "02"
  1822. struct2401.MdtrtCertNo = id_card_no
  1823. struct2401.PsnNo = res2.Output.Baseinfo.PsnNo
  1824. }
  1825. if miConfig.Code == "H15049901371" {
  1826. if med_type == 14 {
  1827. if insutype == "390" {
  1828. struct2401.MedType = "9933"
  1829. } else if insutype == "310" {
  1830. struct2401.MedType = "990502"
  1831. }
  1832. } else if med_type == 11 {
  1833. struct2401.MedType = "21"
  1834. }
  1835. } else {
  1836. if med_type == 11 {
  1837. struct2401.MedType = "21"
  1838. med_type = 21
  1839. } else {
  1840. struct2401.MedType = strconv.FormatInt(int64(med_type), 10)
  1841. }
  1842. }
  1843. struct2401.IptNo = ipt_otp_no
  1844. struct2401.AtddrNo = doctorInfo.DoctorNumber
  1845. struct2401.ChfpdrName = doctorInfo.UserName
  1846. struct2401.AdmDiagDscr = diagnosisConfig[0].ClassName
  1847. struct2401.AdmDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  1848. struct2401.AdmDeptName = departmentInfo.Name
  1849. struct2401.AdmBed = deviceNumber.Number
  1850. struct2401.AdmBed = "待定"
  1851. struct2401.DscgMaindiagName = diagnosisConfig[0].ClassName
  1852. struct2401.DscgMaindiagCode = diagnosisConfig[0].CountryCode
  1853. struct2401.Begntime = start_time
  1854. struct2401.DiseCodg = sickConfig.CountryCode
  1855. struct2401.DiseName = sickConfig.ClassName
  1856. var dises []service.DiseinfoStruct
  1857. for index, item := range diagnosisConfig {
  1858. var dise service.DiseinfoStruct
  1859. if id_card_type == 4 || id_card_type == 1 {
  1860. dise.PsnNo = psn_info.PsnNo
  1861. } else {
  1862. dise.PsnNo = res2.Output.Baseinfo.PsnNo
  1863. }
  1864. dise.DiagType = "1"
  1865. if index == 0 {
  1866. dise.MaindiagFlag = "1"
  1867. } else {
  1868. dise.MaindiagFlag = "2"
  1869. }
  1870. dise.DiagSrtNo = strconv.FormatInt(int64(index), 10)
  1871. dise.DiseDorName = doctorInfo.UserName
  1872. dise.DiagCode = item.CountryCode
  1873. dise.DiagName = item.ClassName
  1874. dise.DiagDept = departmentInfo.Name
  1875. dise.DiseDorNo = doctorInfo.DoctorNumber
  1876. dise.DiagTime = timeFormatOne
  1877. dises = append(dises, dise)
  1878. }
  1879. struct2401.Diseinfo = dises
  1880. var result string
  1881. var request_log string
  1882. if miConfig.MdtrtareaAdmvs == "150499" {
  1883. data := make(map[string]interface{})
  1884. data["org_name"] = miConfig.OrgName
  1885. data["doctor"] = role.UserName
  1886. data["fixmedins_code"] = miConfig.Code
  1887. data["insuplc_admdvs"] = insuplc_admdvs
  1888. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1889. data["secret_key"] = miConfig.SecretKey
  1890. data["struct_2401"] = struct2401
  1891. var req *http.Request
  1892. bytesData, _ := json.Marshal(data)
  1893. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2401", bytes.NewReader(bytesData))
  1894. client := &http.Client{}
  1895. resp, _ := client.Do(req)
  1896. defer resp.Body.Close()
  1897. body, ioErr := ioutil.ReadAll(resp.Body)
  1898. if ioErr != nil {
  1899. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1901. return
  1902. }
  1903. var respJSON map[string]interface{}
  1904. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1905. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1907. return
  1908. }
  1909. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1910. result_byte, _ := json.Marshal(respJSON)
  1911. result = string(result_byte)
  1912. } else if miConfig.MdtrtareaAdmvs == "421182" {
  1913. data := make(map[string]interface{})
  1914. data["org_name"] = miConfig.OrgName
  1915. data["doctor"] = role.UserName
  1916. data["fixmedins_code"] = miConfig.Code
  1917. data["insuplc_admdvs"] = insuplc_admdvs
  1918. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1919. data["secret_key"] = miConfig.SecretKey
  1920. data["struct_2401"] = struct2401
  1921. var req *http.Request
  1922. bytesData, _ := json.Marshal(data)
  1923. req, _ = http.NewRequest("POST", miConfig.Url +"hbyb/2401", bytes.NewReader(bytesData))
  1924. client := &http.Client{}
  1925. resp, _ := client.Do(req)
  1926. defer resp.Body.Close()
  1927. body, ioErr := ioutil.ReadAll(resp.Body)
  1928. if ioErr != nil {
  1929. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1931. return
  1932. }
  1933. var respJSON map[string]interface{}
  1934. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1935. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1937. return
  1938. }
  1939. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1940. //result, _ := json.Marshal(respJSON)
  1941. //result = string(result_byte)
  1942. //decoder := simplifiedchinese.GBK.NewDecoder()
  1943. result_byte, _ := json.Marshal(respJSON)
  1944. result = string(result_byte)
  1945. //enc := mahonia.NewEncoder("gbk")
  1946. //result = enc.ConvertString(string(result_byte))
  1947. fmt.Println(string(result)) // 输出:中文
  1948. } else if miConfig.MdtrtareaAdmvs == "360399" {
  1949. if !strings.Contains(insuplc_admdvs, "3603") {
  1950. if id_card_type == 1 {
  1951. bas := strings.Split(psn_info.CardInfo, "|")
  1952. card_sn := bas[3]
  1953. card_no := bas[1]
  1954. struct2401.Cardsn = card_sn
  1955. struct2401.PsnCertType = "01"
  1956. struct2401.Certno = card_no
  1957. struct2401.PsnType = psn_type
  1958. struct2401.PsnName = patient.Name
  1959. }
  1960. }
  1961. result, request_log = service.Jxyb2401(struct2401, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, insuplc_admdvs, miConfig.MdtrtareaAdmvs, miConfig.Url, "", miConfig.AccessKey)
  1962. saveLog(result, request_log, "2401", "入院登记")
  1963. } else {
  1964. //住院登记调用事前
  1965. //var hisPrescription []*models.HisPrescription
  1966. //res3101 := Check3101ForOne(c, patient.ID, struct2401, admin_user_id, "3", record_time, hisPrescription, res2, recordDateTime)
  1967. var res3101 Result3101
  1968. res3101.Infcode = 0
  1969. if res3101.Infcode == 0 {
  1970. result, request_log = service.ZHGdyb2401(struct2401, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, insuplc_admdvs, miConfig.MdtrtareaAdmvs)
  1971. saveLog(result, request_log, "2401", "入院登记")
  1972. } else {
  1973. c.ServeSuccessJSON(map[string]interface{}{
  1974. "failed_code": -10,
  1975. "msg": res3101.ErrMsg,
  1976. })
  1977. return
  1978. }
  1979. }
  1980. var dat map[string]interface{}
  1981. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1982. fmt.Println(dat)
  1983. } else {
  1984. fmt.Println(err)
  1985. }
  1986. userJSONBytes, _ := json.Marshal(dat)
  1987. var res ResultThree
  1988. var resThree10265 ResultThree10265
  1989. if miConfig.Code == "H15049901371" {
  1990. if err := json.Unmarshal(userJSONBytes, &resThree10265); err != nil {
  1991. utils.ErrorLog("解析失败:%v", err)
  1992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1993. return
  1994. }
  1995. Infcode, _ := strconv.ParseInt(resThree10265.Infcode, 10, 64)
  1996. res.Infcode = Infcode
  1997. res.ErrMsg = resThree10265.ErrMsg
  1998. res.Output = resThree10265.Output
  1999. res.InfRefmsgid = resThree10265.InfRefmsgid
  2000. res.RespondTime = resThree10265.RespondTime
  2001. } else {
  2002. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2003. utils.ErrorLog("解析失败:%v", err)
  2004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2005. return
  2006. }
  2007. }
  2008. if res.Infcode == 0 {
  2009. //result2 := service.Gdyb5301Two(res2.Output.Baseinfo.PsnNo, miConfig.OrgName, role.UserName, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  2010. //fmt.Println(result2)
  2011. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  2012. Idetinfos, _ := json.Marshal(res2.Output.Idetinfo)
  2013. infoStr := string(Iinfos)
  2014. idetinfoStr := string(Idetinfos)
  2015. inHospital := &models.HisHospitalCheckRecord{
  2016. PatientId: id,
  2017. Name: name,
  2018. MedicalTreatmentType: med_type,
  2019. RecordDate: recordDateTime,
  2020. IdCardNo: id_card_no,
  2021. AdminUserId: admin_user_id,
  2022. Departments: department,
  2023. UserOrgId: adminInfo.CurrentOrgId,
  2024. Status: 1,
  2025. Ctime: time.Now().Unix(),
  2026. Mtime: time.Now().Unix(),
  2027. Number: res.Output.Result.MdtrtID,
  2028. Doctor: doctor,
  2029. PsnNo: res2.Output.Baseinfo.PsnNo,
  2030. PsnCertType: res2.Output.Baseinfo.PsnCertType,
  2031. Certno: res2.Output.Baseinfo.Certno,
  2032. PsnName: res2.Output.Baseinfo.PsnName,
  2033. Gend: res2.Output.Baseinfo.Gend,
  2034. Naty: res2.Output.Baseinfo.Naty,
  2035. MedType: med_type,
  2036. InsutypeType: insutype,
  2037. Iinfo: infoStr,
  2038. Idetinfo: idetinfoStr,
  2039. IptOtpNo: ipt_otp_no,
  2040. AdmBed: adm_bed,
  2041. IdCardType: id_card_type,
  2042. Diagnosis: diagnosis_ids,
  2043. SickType: sick_type,
  2044. MdtrtCertType: "02",
  2045. InHosptialTime: start_time,
  2046. OutHosptialTime: "",
  2047. InHospitalStatus: 1,
  2048. Certificates: certificates,
  2049. Phone: phone,
  2050. BalanceAccountsType: balance_accounts_type,
  2051. PsnType: psn_type,
  2052. InsuplcAdmdvs: insuplc_admdvs,
  2053. }
  2054. service.CreateHospitalRecord(inHospital)
  2055. c.ServeSuccessJSON(map[string]interface{}{
  2056. "msg": "办理入院成功",
  2057. "info": inHospital,
  2058. })
  2059. } else {
  2060. c.ServeSuccessJSON(map[string]interface{}{
  2061. "failed_code": -10,
  2062. "msg": res.ErrMsg,
  2063. })
  2064. }
  2065. } else {
  2066. c.ServeSuccessJSON(map[string]interface{}{
  2067. "failed_code": -10,
  2068. "msg": res2.ErrMsg,
  2069. })
  2070. return
  2071. }
  2072. }
  2073. func (this *ZHHisApiController) GetZHOutHospitalCheck() {
  2074. id, _ := this.GetInt64("id")
  2075. patient_id, _ := this.GetInt64("patient_id")
  2076. admin_user_id, _ := this.GetInt64("admin_user_id")
  2077. record_time := this.GetString("record_time")
  2078. out_time := this.GetString("out_time")
  2079. adminInfo := this.GetAdminUserInfo()
  2080. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2081. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  2082. //service.getpre
  2083. record, _ := service.GetInHospitalRecord(id)
  2084. if record.ID == 0 {
  2085. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  2086. return
  2087. }
  2088. infos, _ := service.FindLastPatientPrescriptionInfoTwo2(this.GetAdminUserInfo().CurrentOrgId, patient_id, strings.Split(record.InHosptialTime, " ")[0], strings.Split(out_time, " ")[0])
  2089. timeLayout := "2006-01-02"
  2090. loc, _ := time.LoadLocation("Local")
  2091. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2092. if err != nil {
  2093. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2094. return
  2095. }
  2096. recordDateTime := theTime.Unix()
  2097. //var patient service.Patients
  2098. //if patient_id == 0 {
  2099. // patient, _ = service.GetPatientByIDCard(record.IdCardNo, adminInfo.CurrentOrgId)
  2100. //} else {
  2101. // patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  2102. //}
  2103. for _, item := range infos {
  2104. record.Diagnosis = record.Diagnosis + "," + item.Diagnosis
  2105. }
  2106. diagnosis_ids_arr := strings.Split(record.Diagnosis, ",")
  2107. fmt.Println(diagnosis_ids_arr)
  2108. diagnosis_ids_arr = RemoveRepeatedPurviewElement2(diagnosis_ids_arr)
  2109. fmt.Println(diagnosis_ids_arr)
  2110. diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  2111. departmentInfo, _ := service.GetDepartMentDetail(record.Departments)
  2112. doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, record.Doctor)
  2113. //deviceNumber, _ := service.GetDeviceNumberByID(record.AdmBed, adminInfo.CurrentOrgId)
  2114. sickConfig, _ := service.FindSickById(record.SickType)
  2115. var struct2402 service.Struct2402
  2116. timestamp := time.Now().Unix()
  2117. tempTime := time.Unix(timestamp, 0)
  2118. //timeFormat := tempTime.Format("20060102150405")
  2119. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  2120. struct2402.PsnNo = record.PsnNo
  2121. struct2402.Insutype = record.InsutypeType
  2122. struct2402.DscgWay = "1"
  2123. struct2402.Endtime = out_time
  2124. struct2402.DscgDeptName = departmentInfo.Number
  2125. struct2402.DscgDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  2126. struct2402.MdtrtId = record.Number
  2127. var dises []service.Diseinfo2402Struct
  2128. for index, item := range diagnosisConfig {
  2129. var dise service.Diseinfo2402Struct
  2130. dise.PsnNo = record.PsnNo
  2131. if index == 0 {
  2132. dise.DiagType = "1"
  2133. dise.MaindiagFlag = "1"
  2134. } else {
  2135. dise.DiagType = "1"
  2136. dise.MaindiagFlag = "0"
  2137. }
  2138. dise.MdtrtId = record.Number
  2139. dise.DiagSrtNo = strconv.FormatInt(int64(index), 10)
  2140. dise.DiseDorName = doctorInfo.UserName
  2141. dise.DiagCode = item.CountryCode
  2142. dise.DiagName = item.ClassName
  2143. dise.DiagDept = departmentInfo.Name
  2144. dise.DiseDorNo = doctorInfo.DoctorNumber
  2145. dise.DiagTime = timeFormatOne
  2146. dises = append(dises, dise)
  2147. }
  2148. struct2402.Diseinfo = dises
  2149. struct2402.DiseName = sickConfig.ClassName
  2150. struct2402.DiseCode = sickConfig.CountryCode
  2151. var result string
  2152. var request_log string
  2153. if miConfig.MdtrtareaAdmvs == "150499" {
  2154. data := make(map[string]interface{})
  2155. data["org_name"] = miConfig.OrgName
  2156. data["doctor"] = role.UserName
  2157. data["fixmedins_code"] = miConfig.Code
  2158. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  2159. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  2160. data["secret_key"] = miConfig.SecretKey
  2161. data["struct_2402"] = struct2402
  2162. var req *http.Request
  2163. bytesData, _ := json.Marshal(data)
  2164. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2402", bytes.NewReader(bytesData))
  2165. client := &http.Client{}
  2166. resp, _ := client.Do(req)
  2167. defer resp.Body.Close()
  2168. body, ioErr := ioutil.ReadAll(resp.Body)
  2169. if ioErr != nil {
  2170. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2171. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2172. return
  2173. }
  2174. var respJSON map[string]interface{}
  2175. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  2176. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2177. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2178. return
  2179. }
  2180. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2181. result_byte, _ := json.Marshal(respJSON)
  2182. result = string(result_byte)
  2183. } else if miConfig.MdtrtareaAdmvs == "421182" {
  2184. data := make(map[string]interface{})
  2185. data["org_name"] = miConfig.OrgName
  2186. data["doctor"] = role.UserName
  2187. data["fixmedins_code"] = miConfig.Code
  2188. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  2189. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  2190. data["secret_key"] = miConfig.SecretKey
  2191. data["struct_2402"] = struct2402
  2192. var req *http.Request
  2193. bytesData, _ := json.Marshal(data)
  2194. req, _ = http.NewRequest("POST", miConfig.Url +"hbyb/2402", bytes.NewReader(bytesData))
  2195. client := &http.Client{}
  2196. resp, _ := client.Do(req)
  2197. defer resp.Body.Close()
  2198. body, ioErr := ioutil.ReadAll(resp.Body)
  2199. if ioErr != nil {
  2200. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2201. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2202. return
  2203. }
  2204. var respJSON map[string]interface{}
  2205. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  2206. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2207. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2208. return
  2209. }
  2210. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2211. result_byte, _ := json.Marshal(respJSON)
  2212. result = string(result_byte)
  2213. } else if miConfig.MdtrtareaAdmvs == "360399" {
  2214. result, request_log = service.Jxyb2402(struct2402, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.Url, "", miConfig.AccessKey)
  2215. saveLog(result, request_log, "2402", "出院")
  2216. } else {
  2217. result, request_log = service.ZHGdyb2402(struct2402, miConfig.OrgName, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  2218. saveLog(result, request_log, "2402", "出院")
  2219. }
  2220. var dat map[string]interface{}
  2221. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2222. fmt.Println(dat)
  2223. } else {
  2224. fmt.Println(err)
  2225. }
  2226. userJSONBytes, _ := json.Marshal(dat)
  2227. var res ResultEmpty
  2228. var resEmpty10265 ResultEmpty10265
  2229. if miConfig.Code == "H15049901371" {
  2230. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2231. utils.ErrorLog("解析失败:%v", err)
  2232. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2233. return
  2234. }
  2235. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2236. res.Infcode = Infcode
  2237. res.RespondTime = resEmpty10265.RespondTime
  2238. res.ErrMsg = resEmpty10265.ErrMsg
  2239. res.Output = resEmpty10265.Output
  2240. res.WarnMsg = resEmpty10265.WarnMsg
  2241. } else {
  2242. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2243. utils.ErrorLog("解析失败:%v", err)
  2244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2245. return
  2246. }
  2247. }
  2248. if res.Infcode == 0 {
  2249. record.OutHospitalStatus = 1
  2250. record.OutHosptialTime = struct2402.Endtime
  2251. record.OutWay = 1
  2252. service.CreateHospitalRecord(&record)
  2253. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  2254. var total float64
  2255. for _, item := range orders {
  2256. total = total + item.DetItemFeeSumamt
  2257. }
  2258. order := &models.HisOrder{
  2259. UserOrgId: adminInfo.CurrentOrgId,
  2260. HisPatientId: record.ID,
  2261. PatientId: record.PatientId,
  2262. SettleAccountsDate: recordDateTime,
  2263. Ctime: time.Now().Unix(),
  2264. Mtime: time.Now().Unix(),
  2265. Status: 1,
  2266. Number: record.Number,
  2267. Infcode: 0,
  2268. WarnMsg: "",
  2269. Cainfo: "",
  2270. ErrMsg: "",
  2271. RespondTime: "",
  2272. InfRefmsgid: "",
  2273. OrderStatus: 1,
  2274. MdtrtId: record.Number,
  2275. IsMedicineInsurance: 1,
  2276. PType: 1,
  2277. MedfeeSumamt: total,
  2278. }
  2279. err = service.CreateOrder(order)
  2280. if err != nil {
  2281. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2282. return
  2283. }
  2284. this.ServeSuccessJSON(map[string]interface{}{
  2285. "msg": "出院成功",
  2286. })
  2287. } else {
  2288. this.ServeSuccessJSON(map[string]interface{}{
  2289. "failed_code": -10,
  2290. "msg": res.ErrMsg,
  2291. })
  2292. }
  2293. }
  2294. func (c *ZHHisApiController) Get4102() {
  2295. order_id, _ := c.GetInt64("order_id")
  2296. admin_user_id, _ := c.GetInt64("admin_user_id")
  2297. stas_type := c.GetString("stas_type")
  2298. adminUser := c.GetAdminUserInfo()
  2299. order, _ := service.GetHisOrderByID(order_id)
  2300. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2301. var user_name string
  2302. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2303. if role.ID == 0 {
  2304. user_name = "管理员"
  2305. } else {
  2306. user_name = role.UserName
  2307. }
  2308. baseParams := models.BaseParams{
  2309. SecretKey: miConfig.SecretKey,
  2310. FixmedinsCode: miConfig.Code,
  2311. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2312. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2313. OrgName: miConfig.OrgName,
  2314. Doctor: user_name,
  2315. RequestUrl: miConfig.Url,
  2316. AccessKey: miConfig.AccessKey,
  2317. }
  2318. businessParams := models.BusinessParams{
  2319. PsnNo: order.PsnNo,
  2320. MdtrtId: order.MdtrtId,
  2321. SetlId: order.SetlId,
  2322. StasType: stas_type,
  2323. }
  2324. api := "http://172.16.13.254:9532/" + "nmyb/4102?psn_no=" + businessParams.PsnNo + "&mdtrt_id=" + businessParams.MdtrtId + "&setl_id=" + businessParams.SetlId +
  2325. "&org_name=" + miConfig.OrgName + "&doctor=" + baseParams.Doctor + "&fixmedins_code=" + miConfig.Code +
  2326. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&stas_type=" + stas_type
  2327. resp, requestErr := http.Get(api)
  2328. if requestErr != nil {
  2329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2330. return
  2331. }
  2332. body, ioErr := ioutil.ReadAll(resp.Body)
  2333. if ioErr != nil {
  2334. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2336. return
  2337. }
  2338. var respJSON map[string]interface{}
  2339. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2340. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2342. return
  2343. }
  2344. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2345. result, _ := json.Marshal(respJSON)
  2346. fmt.Println("log")
  2347. fmt.Println(string(result))
  2348. var res2 ResultSix
  2349. var resEmpty10265 ResultEmpty10265
  2350. if err := json.Unmarshal(result, &resEmpty10265); err != nil {
  2351. utils.ErrorLog("解析失败:%v", err)
  2352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2353. return
  2354. }
  2355. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2356. res2.Infcode = Infcode
  2357. res2.RespondTime = resEmpty10265.RespondTime
  2358. res2.ErrMsg = resEmpty10265.ErrMsg
  2359. res2.Output = resEmpty10265.Output
  2360. res2.WarnMsg = resEmpty10265.WarnMsg
  2361. if res2.Infcode == 0 {
  2362. c.ServeSuccessJSON(map[string]interface{}{
  2363. "msg": "确认成功",
  2364. })
  2365. } else {
  2366. c.ServeSuccessJSON(map[string]interface{}{
  2367. "failed_code": -10,
  2368. "msg": res2.ErrMsg,
  2369. })
  2370. }
  2371. }
  2372. func (c *ZHHisApiController) Get4103() {
  2373. order_id, _ := c.GetInt64("order_id")
  2374. admin_user_id, _ := c.GetInt64("admin_user_id")
  2375. stas_type := c.GetString("stas_type")
  2376. adminUser := c.GetAdminUserInfo()
  2377. order, _ := service.GetHisOrderByID(order_id)
  2378. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2379. var user_name string
  2380. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2381. if role.ID == 0 {
  2382. user_name = "管理员"
  2383. } else {
  2384. user_name = role.UserName
  2385. }
  2386. baseParams := models.BaseParams{
  2387. SecretKey: miConfig.SecretKey,
  2388. FixmedinsCode: miConfig.Code,
  2389. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2390. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2391. OrgName: miConfig.OrgName,
  2392. Doctor: user_name,
  2393. RequestUrl: miConfig.Url,
  2394. AccessKey: miConfig.AccessKey,
  2395. }
  2396. businessParams := models.BusinessParams{
  2397. PsnNo: order.PsnNo,
  2398. MdtrtId: order.MdtrtId,
  2399. SetlId: order.SetlId,
  2400. StasType: stas_type,
  2401. }
  2402. api := "http://172.16.13.254:9532/" + "nmyb/4103?psn_no=" + businessParams.PsnNo + "&mdtrt_id=" + businessParams.MdtrtId + "&setl_id=" + businessParams.SetlId +
  2403. "&org_name=" + miConfig.OrgName + "&doctor=" + baseParams.Doctor + "&fixmedins_code=" + miConfig.Code +
  2404. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&stas_type=" + stas_type
  2405. resp, requestErr := http.Get(api)
  2406. if requestErr != nil {
  2407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2408. return
  2409. }
  2410. body, ioErr := ioutil.ReadAll(resp.Body)
  2411. if ioErr != nil {
  2412. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2414. return
  2415. }
  2416. var respJSON map[string]interface{}
  2417. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2418. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2420. return
  2421. }
  2422. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2423. result, _ := json.Marshal(respJSON)
  2424. fmt.Println("log")
  2425. fmt.Println(string(result))
  2426. var res2 ResultSix
  2427. var resEmpty10265 ResultEmpty10265
  2428. if err := json.Unmarshal(result, &resEmpty10265); err != nil {
  2429. utils.ErrorLog("解析失败:%v", err)
  2430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2431. return
  2432. }
  2433. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2434. res2.Infcode = Infcode
  2435. res2.RespondTime = resEmpty10265.RespondTime
  2436. res2.ErrMsg = resEmpty10265.ErrMsg
  2437. res2.Output = resEmpty10265.Output
  2438. res2.WarnMsg = resEmpty10265.WarnMsg
  2439. if res2.Infcode == 0 {
  2440. c.ServeSuccessJSON(map[string]interface{}{
  2441. "msg": string(result),
  2442. })
  2443. } else {
  2444. c.ServeSuccessJSON(map[string]interface{}{
  2445. "failed_code": -10,
  2446. "msg": res2.ErrMsg,
  2447. })
  2448. }
  2449. }
  2450. //func (c *ZHHisApiController) Get4104() {
  2451. // order_id, _ := c.GetInt64("order_id")
  2452. // admin_user_id, _ := c.GetInt64("admin_user_id")
  2453. // adminUser := c.GetAdminUserInfo()
  2454. // order, _ := service.GetHisOrderByID(order_id)
  2455. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2456. // var user_name string
  2457. // role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2458. // if role.ID == 0 {
  2459. // user_name = "管理员"
  2460. // } else {
  2461. // user_name = role.UserName
  2462. // }
  2463. // baseParams := models.BaseParams{
  2464. // SecretKey: miConfig.SecretKey,
  2465. // FixmedinsCode: miConfig.Code,
  2466. // InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2467. // MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2468. // OrgName: miConfig.OrgName,
  2469. // Doctor: user_name,
  2470. // RequestUrl: miConfig.Url,
  2471. // AccessKey: miConfig.AccessKey,
  2472. // }
  2473. //
  2474. // businessParams := models.BusinessParams{
  2475. // PsnNo: order.PsnNo,
  2476. // MdtrtId: order.MdtrtId,
  2477. // SetlId: order.SetlId,
  2478. // }
  2479. //
  2480. // api := "http://172.16.13.254:9532/" + "nmyb/4104?psn_no=" + businessParams.PsnNo + "&mdtrt_id=" + businessParams.MdtrtId + "&setl_id=" + businessParams.SetlId +
  2481. // "&org_name=" + miConfig.OrgName + "&doctor=" + baseParams.Doctor + "&fixmedins_code=" + miConfig.Code +
  2482. // "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&stas_type=" + stas_type
  2483. // resp, requestErr := http.Get(api)
  2484. // if requestErr != nil {
  2485. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2486. // return
  2487. // }
  2488. // body, ioErr := ioutil.ReadAll(resp.Body)
  2489. // if ioErr != nil {
  2490. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2491. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2492. // return
  2493. // }
  2494. // var respJSON map[string]interface{}
  2495. // if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2496. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2497. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2498. // return
  2499. // }
  2500. //
  2501. // respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2502. // result, _ := json.Marshal(respJSON)
  2503. // fmt.Println("log")
  2504. // fmt.Println(string(result))
  2505. //
  2506. // var res2 ResultSix
  2507. // var resEmpty10265 ResultEmpty10265
  2508. //
  2509. // if err := json.Unmarshal(result, &resEmpty10265); err != nil {
  2510. // utils.ErrorLog("解析失败:%v", err)
  2511. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2512. // return
  2513. // }
  2514. // Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2515. // res2.Infcode = Infcode
  2516. // res2.RespondTime = resEmpty10265.RespondTime
  2517. // res2.ErrMsg = resEmpty10265.ErrMsg
  2518. // res2.Output = resEmpty10265.Output
  2519. // res2.WarnMsg = resEmpty10265.WarnMsg
  2520. //
  2521. // if res2.Infcode == 0 {
  2522. // c.ServeSuccessJSON(map[string]interface{}{
  2523. // "msg": "确认成功",
  2524. // })
  2525. //
  2526. // } else {
  2527. // c.ServeSuccessJSON(map[string]interface{}{
  2528. // "failed_code": -10,
  2529. // "msg": res2.ErrMsg,
  2530. // })
  2531. //
  2532. // }
  2533. //
  2534. //}
  2535. func (c *ZHHisApiController) GetSettleInfo() {
  2536. order_id, _ := c.GetInt64("order_id")
  2537. patient_id, _ := c.GetInt64("patient_id")
  2538. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  2539. admin_user_id, _ := c.GetInt64("admin_user_id")
  2540. pay_way, _ := c.GetInt64("pay_way")
  2541. pay_price, _ := c.GetFloat("pay_price")
  2542. pay_card_no := c.GetString("pay_card_no")
  2543. discount_price, _ := c.GetFloat("discount_price")
  2544. preferential_price, _ := c.GetFloat("preferential_price")
  2545. reality_price, _ := c.GetFloat("reality_price")
  2546. found_price, _ := c.GetFloat("found_price")
  2547. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2548. private_price, _ := c.GetFloat("private_price")
  2549. fapiao_code := c.GetString("fapiao_code")
  2550. fapiao_number := c.GetString("fapiao_number")
  2551. record, _ := service.GetInHospitalRecord(in_hospital_id)
  2552. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  2553. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  2554. order, _ := service.GetHisOrderByID(order_id)
  2555. //dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  2556. //tmp_decimal := c.GetString("tmp_decimal")
  2557. //var decimal float64 //本次使用的押金
  2558. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  2559. tmp_decimal := c.GetString("tmp_decimal")
  2560. var decimal float64 //本次使用的押金
  2561. var errmsg error
  2562. if dec_way == "true" && tmp_decimal == "0" || dec_way == "true" && tmp_decimal == "" {
  2563. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  2564. return
  2565. }
  2566. if len(tmp_decimal) > 0 {
  2567. if tmp_decimal[0] == 45 {
  2568. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  2569. return
  2570. }
  2571. }
  2572. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  2573. if errs != nil {
  2574. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
  2575. return
  2576. }
  2577. decimal = tt
  2578. var rf []*ResultFive
  2579. json.Unmarshal([]byte(record.Iinfo), &rf)
  2580. chrg_bchno := order.Number
  2581. cert_no := record.Certno
  2582. if record.ID == 0 {
  2583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2584. return
  2585. }
  2586. if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  2587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  2588. return
  2589. }
  2590. if record.IdCardType == 1 {
  2591. } else {
  2592. cert_no = record.Certno
  2593. }
  2594. var result string
  2595. var src_resquest string
  2596. timeLayout := "2006-01-02"
  2597. loc, _ := time.LoadLocation("Local")
  2598. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record.InHosptialTime, loc)
  2599. if err != nil {
  2600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2601. return
  2602. }
  2603. recordStartDateTime := theTime.Unix()
  2604. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", record.OutHosptialTime, loc)
  2605. if err != nil {
  2606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2607. return
  2608. }
  2609. recordEndDateTime := theTimeEnd.Unix()
  2610. prescriptions, _ := service.GetZHSettleMonthHisPrescription(c.GetAdminUserInfo().CurrentOrgId, patient_id, recordStartDateTime, recordEndDateTime)
  2611. var total float64
  2612. for _, item := range prescriptions {
  2613. if item.Type == 1 { //药品
  2614. for _, subItem := range item.HisDoctorAdviceInfo {
  2615. total = total + (subItem.Price * subItem.PrescribingNumber)
  2616. }
  2617. }
  2618. if item.Type == 2 { //项目
  2619. for _, subItem := range item.HisPrescriptionProject {
  2620. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  2621. total = total + (subItem.Price * cnt)
  2622. }
  2623. }
  2624. }
  2625. //allTotal := fmt.Sprintf("%.2f", total)
  2626. var allTotal string
  2627. if record.OutHospitalStatus == 0 && order.ID == 0 {
  2628. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  2629. var total float64
  2630. for _, item := range orders {
  2631. total = total + item.DetItemFeeSumamt
  2632. }
  2633. allTotal = fmt.Sprintf("%.4f", total)
  2634. } else {
  2635. allTotal = fmt.Sprintf("%.4f", order.MedfeeSumamt)
  2636. }
  2637. if miConfig.MdtrtareaAdmvs == "150499" {
  2638. psn_info, _ := service.GetPsnByPatientId(patient_id)
  2639. mdtrt_cert_no := ""
  2640. if record.IdCardType == 1 {
  2641. bas := strings.Split(psn_info.CardInfo, "|")
  2642. cardNumber := bas[2]
  2643. mdtrt_cert_no = cardNumber
  2644. } else {
  2645. mdtrt_cert_no = record.Certno
  2646. }
  2647. var acct_used_flag string
  2648. if pay_way == 4 {
  2649. acct_used_flag = "1"
  2650. } else {
  2651. acct_used_flag = "0"
  2652. }
  2653. if pay_way == 6 {
  2654. mdtrt_cert_no = psn_info.VerifyNumber
  2655. acct_used_flag = "1"
  2656. record.IdCardType = 4
  2657. } else {
  2658. acct_used_flag = "0"
  2659. }
  2660. fmt.Println(mdtrt_cert_no)
  2661. fmt.Println(acct_used_flag)
  2662. fmt.Println(record.IdCardType)
  2663. //请求内网数据
  2664. api := "http://172.16.13.254:9532/" + "nmyb/2304?psn_no=" + record.PsnNo + "&mdtrt_id=" + record.Number + "&chrg_bchno=" + chrg_bchno +
  2665. "&insutype_type=" + record.InsutypeType + "&total=" + allTotal +
  2666. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2667. "&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
  2668. resp, requestErr := http.Get(api)
  2669. if requestErr != nil {
  2670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2671. return
  2672. }
  2673. body, ioErr := ioutil.ReadAll(resp.Body)
  2674. if ioErr != nil {
  2675. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2677. return
  2678. }
  2679. var respJSON map[string]interface{}
  2680. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2681. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2683. return
  2684. }
  2685. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2686. result_byte, _ := json.Marshal(respJSON)
  2687. result = string(result_byte)
  2688. } else if miConfig.MdtrtareaAdmvs == "421182" {
  2689. psn_info, _ := service.GetPsnByPatientId(patient_id)
  2690. mdtrt_cert_no := ""
  2691. if record.IdCardType == 1 {
  2692. bas := strings.Split(psn_info.CardInfo, "|")
  2693. cardNumber := bas[2]
  2694. mdtrt_cert_no = cardNumber
  2695. } else {
  2696. mdtrt_cert_no = record.Certno
  2697. }
  2698. var acct_used_flag string
  2699. if pay_way == 4 {
  2700. acct_used_flag = "1"
  2701. } else {
  2702. acct_used_flag = "0"
  2703. }
  2704. if pay_way == 6 {
  2705. mdtrt_cert_no = psn_info.VerifyNumber
  2706. acct_used_flag = "1"
  2707. record.IdCardType = 4
  2708. } else {
  2709. acct_used_flag = "0"
  2710. }
  2711. fmt.Println(mdtrt_cert_no)
  2712. fmt.Println(acct_used_flag)
  2713. fmt.Println(record.IdCardType)
  2714. //请求内网数据
  2715. api := miConfig.Url + "hbyb/2304?psn_no=" + record.PsnNo + "&mdtrt_id=" + record.Number + "&chrg_bchno=" + chrg_bchno +
  2716. "&insutype_type=" + record.InsutypeType + "&total=" + allTotal +
  2717. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2718. "&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
  2719. resp, requestErr := http.Get(api)
  2720. if requestErr != nil {
  2721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2722. return
  2723. }
  2724. body, ioErr := ioutil.ReadAll(resp.Body)
  2725. if ioErr != nil {
  2726. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2728. return
  2729. }
  2730. var respJSON map[string]interface{}
  2731. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2732. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2734. return
  2735. }
  2736. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2737. result_byte, _ := json.Marshal(respJSON)
  2738. result = string(result_byte)
  2739. } else if miConfig.MdtrtareaAdmvs == "360399" {
  2740. psn_info, _ := service.GetPsnByPatientId(patient_id)
  2741. if len(psn_info.CardInfo) > 0 && len(psn_info.VerifyNumber) == 0{
  2742. cert_no = record.Certno
  2743. } else if len(psn_info.CardInfo) == 0 && len(psn_info.VerifyNumber) > 0{
  2744. cert_no = psn_info.VerifyNumber
  2745. }
  2746. //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")
  2747. if strings.Contains(record.InsuplcAdmdvs, "3603") {
  2748. bas := strings.Split(psn_info.CardInfo, "|")
  2749. card_sn := bas[3]
  2750. 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,"","","","")
  2751. saveLog(result, src_resquest, "2304", "住院结算")
  2752. //if record.IdCardType == 1 {
  2753. //basNumber := bas[2]
  2754. // 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)
  2755. // saveLog(result, src_resquest, "2303", "住院预结算")
  2756. //}
  2757. }else{
  2758. bas := strings.Split(psn_info.CardInfo, "|")
  2759. card_sn := bas[3]
  2760. 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)
  2761. //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)
  2762. saveLog(result, src_resquest, "2303", "住院预结算")
  2763. }
  2764. } else {
  2765. result3101 := Check3102(c, record.PatientId, record.ID, admin_user_id, "8", order.ID)
  2766. if result3101.Infcode == 0 {
  2767. if len(result3101.Output.Result) > 0 {
  2768. var errMsgs []string
  2769. for _, item := range result3101.Output.Result {
  2770. errMsgs = append(errMsgs, item.VolaCont)
  2771. }
  2772. c.ServeSuccessJSON(map[string]interface{}{
  2773. "failed_code": -10,
  2774. "msg": errMsgs,
  2775. })
  2776. return
  2777. } else {
  2778. 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")
  2779. saveLog(result, src_resquest, "2304", "住院结算")
  2780. }
  2781. } else {
  2782. c.ServeSuccessJSON(map[string]interface{}{
  2783. "failed_code": -10,
  2784. "msg": result3101.ErrMsg,
  2785. })
  2786. return
  2787. }
  2788. }
  2789. var dat map[string]interface{}
  2790. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2791. fmt.Println(dat)
  2792. } else {
  2793. fmt.Println(err)
  2794. }
  2795. userJSONBytes, _ := json.Marshal(dat)
  2796. var res ResultSeven
  2797. var resSeven10265 ResultSeven10265
  2798. if miConfig.Code == "H15049901371" {
  2799. if err := json.Unmarshal(userJSONBytes, &resSeven10265); err != nil {
  2800. utils.ErrorLog("解析失败:%v", err)
  2801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2802. return
  2803. }
  2804. Infcode, _ := strconv.ParseInt(resSeven10265.Infcode, 10, 64)
  2805. res.Infcode = Infcode
  2806. res.InfRefmsgid = resSeven10265.InfRefmsgid
  2807. res.RespondTime = resSeven10265.RespondTime
  2808. res.ErrMsg = resSeven10265.ErrMsg
  2809. res.Output = resSeven10265.Output
  2810. res.WarnMsg = resSeven10265.WarnMsg
  2811. res.Cainfo = resSeven10265.Cainfo
  2812. } else {
  2813. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2814. utils.ErrorLog("解析失败:%v", err)
  2815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2816. return
  2817. }
  2818. }
  2819. if res.Infcode != 0 {
  2820. errlog := &models.HisOrderError{
  2821. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2822. Ctime: time.Now().Unix(),
  2823. Mtime: time.Now().Unix(),
  2824. Number: chrg_bchno,
  2825. ErrMsg: res.ErrMsg,
  2826. Status: 1,
  2827. PatientId: patient_id,
  2828. RecordTime: time.Now().Unix(),
  2829. Stage: 6,
  2830. }
  2831. service.CreateErrMsgLog(errlog)
  2832. c.ServeSuccessJSON(map[string]interface{}{
  2833. "failed_code": -10,
  2834. "msg": res.ErrMsg,
  2835. })
  2836. return
  2837. } else {
  2838. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2839. order.OrderStatus = 2
  2840. order.DiscountPrice = discount_price
  2841. order.MedicalInsurancePrice = medical_insurance_price
  2842. order.FaPiaoNumber = fapiao_number
  2843. order.FaPiaoCode = fapiao_code
  2844. order.PayWay = pay_way
  2845. order.PayPrice = pay_price
  2846. order.PayCardNo = pay_card_no
  2847. order.PreferentialPrice = preferential_price
  2848. order.RealityPrice = reality_price
  2849. order.FoundPrice = found_price
  2850. order.PrivatePrice = private_price
  2851. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2852. order.SetlId = res.Output.Setlinfo.SetlID
  2853. order.PsnNo = res.Output.Setlinfo.PsnNo
  2854. order.PsnName = res.Output.Setlinfo.PsnName
  2855. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2856. order.Certno = res.Output.Setlinfo.Certno
  2857. order.Gend = res.Output.Setlinfo.Gend
  2858. order.Naty = res.Output.Setlinfo.Naty
  2859. order.Age = res.Output.Setlinfo.Age
  2860. order.Insutype = res.Output.Setlinfo.Insutype
  2861. order.PsnType = res.Output.Setlinfo.PsnType
  2862. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2863. order.SetlTime = res.Output.Setlinfo.SetlTime
  2864. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2865. if res.Output.Setlinfo.MedType == "140104" {
  2866. order.MedType = "14"
  2867. } else {
  2868. order.MedType = res.Output.Setlinfo.MedType
  2869. }
  2870. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2871. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2872. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2873. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2874. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2875. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2876. order.HifpPay = res.Output.Setlinfo.HifpPay
  2877. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2878. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2879. order.HifesPay = res.Output.Setlinfo.HifesPay
  2880. order.HifobPay = res.Output.Setlinfo.HifobPay
  2881. order.MafPay = res.Output.Setlinfo.MafPay
  2882. order.OthPay = res.Output.Setlinfo.OthPay
  2883. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2884. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2885. order.AcctPay = res.Output.Setlinfo.AcctPay
  2886. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2887. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2888. order.Balc = res.Output.Setlinfo.Balc
  2889. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2890. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2891. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2892. order.ClrWay = res.Output.Setlinfo.ClrWay
  2893. order.Creator = order.Creator
  2894. order.Modify = roles.AdminUserId
  2895. order.RequestLog = src_resquest
  2896. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2897. detailStr := string(setlDetail)
  2898. order.SetlDetail = detailStr
  2899. err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  2900. err = service.UpDateOrder(order)
  2901. if err == nil {
  2902. //判断是否使用了押金
  2903. if dec_way == "true" {
  2904. tmpstring := strconv.FormatInt(order.ID, 10)
  2905. order.Decimal = decimal
  2906. err = service.UpDateOrder(order)
  2907. //扣押金
  2908. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, patient_id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  2909. if errmsg != nil {
  2910. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  2911. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  2912. return
  2913. }
  2914. }
  2915. c.ServeSuccessJSON(map[string]interface{}{
  2916. "msg": "结算成功",
  2917. })
  2918. } else {
  2919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2920. return
  2921. }
  2922. }
  2923. }
  2924. func (c *ZHHisApiController) GetPreSettleInfo() {
  2925. order_id, _ := c.GetInt64("order_id")
  2926. patient_id, _ := c.GetInt64("patient_id")
  2927. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  2928. admin_user_id, _ := c.GetInt64("admin_user_id")
  2929. record, _ := service.GetInHospitalRecord(in_hospital_id)
  2930. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  2931. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  2932. order, _ := service.GetHisOrderByID(order_id)
  2933. var allTotal string
  2934. if record.OutHospitalStatus == 0 && order.ID == 0 {
  2935. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  2936. var total float64
  2937. for _, item := range orders {
  2938. total = total + item.DetItemFeeSumamt
  2939. }
  2940. allTotal = fmt.Sprintf("%.2f", total)
  2941. } else {
  2942. allTotal = fmt.Sprintf("%.2f", order.MedfeeSumamt)
  2943. }
  2944. var rf []*ResultFive
  2945. json.Unmarshal([]byte(record.Iinfo), &rf)
  2946. chrg_bchno := order.Number
  2947. cert_no := record.Certno
  2948. if record.ID == 0 {
  2949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2950. return
  2951. }
  2952. //if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  2953. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  2954. // return
  2955. //}
  2956. psn_info, _ := service.GetPsnByPatientId(patient_id)
  2957. if record.IdCardType == 1 {
  2958. bas := strings.Split(psn_info.CardInfo, "|")
  2959. cardNumber := bas[2]
  2960. cert_no = cardNumber
  2961. } else if record.IdCardType == 4 {
  2962. cert_no = psn_info.VerifyNumber
  2963. } else {
  2964. cert_no = record.Certno
  2965. }
  2966. var result string
  2967. var src_resquest string
  2968. if miConfig.MdtrtareaAdmvs == "150499" {
  2969. //请求内网数据
  2970. api := "http://172.16.13.254:9532/" + "nmyb/2303?psn_no=" + record.PsnNo + "&mdtrt_id=" + record.Number + "&chrg_bchno=" + chrg_bchno +
  2971. "&insutype_type=" + record.InsutypeType + "&total=" + allTotal +
  2972. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2973. "&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
  2974. resp, requestErr := http.Get(api)
  2975. if requestErr != nil {
  2976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2977. return
  2978. }
  2979. body, ioErr := ioutil.ReadAll(resp.Body)
  2980. if ioErr != nil {
  2981. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2983. return
  2984. }
  2985. var respJSON map[string]interface{}
  2986. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2987. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2989. return
  2990. }
  2991. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2992. result_byte, _ := json.Marshal(respJSON)
  2993. result = string(result_byte)
  2994. }else if miConfig.MdtrtareaAdmvs == "421182" {
  2995. //请求内网数据
  2996. api := miConfig.Url + "hbyb/2303?psn_no=" + record.PsnNo + "&mdtrt_id=" + record.Number + "&chrg_bchno=" + chrg_bchno +
  2997. "&insutype_type=" + record.InsutypeType + "&total=" + allTotal +
  2998. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2999. "&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
  3000. resp, requestErr := http.Get(api)
  3001. if requestErr != nil {
  3002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3003. return
  3004. }
  3005. body, ioErr := ioutil.ReadAll(resp.Body)
  3006. if ioErr != nil {
  3007. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3009. return
  3010. }
  3011. var respJSON map[string]interface{}
  3012. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3013. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3014. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3015. return
  3016. }
  3017. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3018. result_byte, _ := json.Marshal(respJSON)
  3019. result = string(result_byte)
  3020. } else if miConfig.MdtrtareaAdmvs == "360399" {
  3021. if !strings.Contains(record.InsuplcAdmdvs, "3603") {
  3022. if record.IdCardType == 1 {
  3023. bas := strings.Split(psn_info.CardInfo, "|")
  3024. //basNumber := bas[2]
  3025. card_sn := bas[3]
  3026. 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)
  3027. saveLog(result, src_resquest, "2303", "住院预结算")
  3028. }
  3029. }else{
  3030. 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)
  3031. saveLog(result, src_resquest, "2303", "住院预结算")
  3032. }
  3033. } else {
  3034. if record.OutHospitalStatus == 1 && order.ID > 0 { //出院的情况下,再去做事中监测
  3035. result3101 := Check3102(c, record.PatientId, record.ID, admin_user_id, "8", order.ID)
  3036. if result3101.Infcode == 0 {
  3037. if len(result3101.Output.Result) > 0 {
  3038. var errMsgs []string
  3039. for _, item := range result3101.Output.Result {
  3040. errMsgs = append(errMsgs, item.VolaCont)
  3041. }
  3042. c.ServeSuccessJSON(map[string]interface{}{
  3043. "failed_code": -10,
  3044. "msg": errMsgs,
  3045. })
  3046. return
  3047. } else {
  3048. 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)
  3049. saveLog(result, src_resquest, "2303", "住院预结算")
  3050. }
  3051. } else {
  3052. c.ServeSuccessJSON(map[string]interface{}{
  3053. "failed_code": -10,
  3054. "msg": result3101.ErrMsg,
  3055. })
  3056. return
  3057. }
  3058. } else {
  3059. 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)
  3060. saveLog(result, src_resquest, "2303", "住院预结算")
  3061. }
  3062. }
  3063. var dat map[string]interface{}
  3064. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3065. fmt.Println(dat)
  3066. } else {
  3067. fmt.Println(err)
  3068. }
  3069. userJSONBytes, _ := json.Marshal(dat)
  3070. var res2 ResultSevenTwo
  3071. var res ResultSeven
  3072. var resSeven10265 ResultSeven10265
  3073. if miConfig.MdtrtareaAdmvs == "360399" {
  3074. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  3075. utils.ErrorLog("解析失败:%v", err)
  3076. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3077. return
  3078. }
  3079. if res2.Infcode != 0 {
  3080. errlog := &models.HisOrderError{
  3081. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3082. Ctime: time.Now().Unix(),
  3083. Mtime: time.Now().Unix(),
  3084. Number: chrg_bchno,
  3085. ErrMsg: res.ErrMsg,
  3086. Status: 1,
  3087. PatientId: patient_id,
  3088. RecordTime: time.Now().Unix(),
  3089. Stage: 6,
  3090. }
  3091. service.CreateErrMsgLog(errlog)
  3092. c.ServeSuccessJSON(map[string]interface{}{
  3093. "failed_code": -10,
  3094. "msg": res.ErrMsg,
  3095. })
  3096. return
  3097. } else {
  3098. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  3099. order.OrderStatus = 1
  3100. order.MdtrtId = res2.Output.Setlinfo.MdtrtID
  3101. order.SetlId = res2.Output.Setlinfo.SetlID
  3102. order.PsnNo = res2.Output.Setlinfo.PsnNo
  3103. order.PsnName = res2.Output.Setlinfo.PsnName
  3104. order.PsnCertType = res2.Output.Setlinfo.PsnCertType
  3105. order.Certno = res2.Output.Setlinfo.Certno
  3106. order.Gend = res2.Output.Setlinfo.Gend
  3107. order.Naty = res2.Output.Setlinfo.Naty
  3108. val, _ := strconv.ParseFloat(res2.Output.Setlinfo.Age, 64)
  3109. order.Age = val
  3110. order.Insutype = res2.Output.Setlinfo.Insutype
  3111. order.PsnType = res2.Output.Setlinfo.PsnType
  3112. order.CvlservFlag = res2.Output.Setlinfo.CvlservFlag
  3113. order.SetlTime = res2.Output.Setlinfo.SetlTime
  3114. order.MdtrtCertType = res2.Output.Setlinfo.MdtrtCertType
  3115. if res.Output.Setlinfo.MedType == "140104" {
  3116. order.MedType = "14"
  3117. } else {
  3118. order.MedType = res2.Output.Setlinfo.MedType
  3119. }
  3120. order.MedfeeSumamt = res2.Output.Setlinfo.MedfeeSumamt
  3121. order.FulamtOwnpayAmt = res2.Output.Setlinfo.FulamtOwnpayAmt
  3122. order.OverlmtSelfPay = res2.Output.Setlinfo.OverlmtSelfpay
  3123. order.PreselfpayAmt = res2.Output.Setlinfo.PreselfpayAmt
  3124. order.InscpScpAmt = res2.Output.Setlinfo.InscpScpAmt
  3125. order.ActPayDedc = res2.Output.Setlinfo.ActPayDedc
  3126. order.HifmiPay = res2.Output.Setlinfo.HifmiPay
  3127. order.HifpPay = res2.Output.Setlinfo.HifpPay
  3128. order.HifesPay = res2.Output.Setlinfo.HifesPay
  3129. order.HifobPay = res2.Output.Setlinfo.HifobPay
  3130. order.MafPay = res2.Output.Setlinfo.MafPay
  3131. order.OthPay = res2.Output.Setlinfo.OthPay
  3132. order.CvlservPay = res2.Output.Setlinfo.CvlservPay
  3133. order.PoolPropSelfpay = res2.Output.Setlinfo.PoolPropSelfpay
  3134. order.FundPaySumamt = res2.Output.Setlinfo.FundPaySumamt
  3135. order.PsnPartAmt = res2.Output.Setlinfo.PsnPartAmt
  3136. order.AcctPay = res2.Output.Setlinfo.AcctPay
  3137. order.PsnCashPay = res2.Output.Setlinfo.PsnCashPay
  3138. order.HospPartAmt = res2.Output.Setlinfo.HospPartAmt
  3139. order.Balc = res2.Output.Setlinfo.Balc
  3140. order.AcctMulaidPay = res2.Output.Setlinfo.AcctMulaidPay
  3141. order.MedinsSetlId = res2.Output.Setlinfo.MedinsSetlID
  3142. order.ClrOptins = res2.Output.Setlinfo.ClrOptins
  3143. order.ClrWay = res2.Output.Setlinfo.ClrWay
  3144. order.Creator = order.Creator
  3145. order.Modify = roles.AdminUserId
  3146. order.RequestLog = src_resquest
  3147. setlDetail, _ := json.Marshal(res2.Output.Setldetail)
  3148. detailStr := string(setlDetail)
  3149. order.SetlDetail = detailStr
  3150. //err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  3151. if record.OutHospitalStatus == 1 && order.ID > 0 {
  3152. err := service.UpDateOrder(order)
  3153. if err == nil {
  3154. c.ServeSuccessJSON(map[string]interface{}{
  3155. "msg": "预结算成功",
  3156. "order_way": 1,
  3157. })
  3158. } else {
  3159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  3160. return
  3161. }
  3162. } else if record.OutHospitalStatus == 0 && order.ID == 0 {
  3163. var order models.HisOrder
  3164. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  3165. order.OrderStatus = 1
  3166. order.MdtrtId = res2.Output.Setlinfo.MdtrtID
  3167. order.SetlId = res2.Output.Setlinfo.SetlID
  3168. order.PsnNo = res2.Output.Setlinfo.PsnNo
  3169. order.PsnName = res2.Output.Setlinfo.PsnName
  3170. order.PsnCertType = res2.Output.Setlinfo.PsnCertType
  3171. order.Certno = res2.Output.Setlinfo.Certno
  3172. order.Gend = res2.Output.Setlinfo.Gend
  3173. order.Naty = res2.Output.Setlinfo.Naty
  3174. val, _ := strconv.ParseFloat(res2.Output.Setlinfo.Age, 64)
  3175. order.Age = val
  3176. order.Insutype = res2.Output.Setlinfo.Insutype
  3177. order.PsnType = res2.Output.Setlinfo.PsnType
  3178. order.CvlservFlag = res2.Output.Setlinfo.CvlservFlag
  3179. order.SetlTime = res2.Output.Setlinfo.SetlTime
  3180. order.MdtrtCertType = res2.Output.Setlinfo.MdtrtCertType
  3181. if res2.Output.Setlinfo.MedType == "140104" {
  3182. order.MedType = "14"
  3183. } else {
  3184. order.MedType = res2.Output.Setlinfo.MedType
  3185. }
  3186. order.MedfeeSumamt = res2.Output.Setlinfo.MedfeeSumamt
  3187. order.FulamtOwnpayAmt = res2.Output.Setlinfo.FulamtOwnpayAmt
  3188. order.OverlmtSelfPay = res2.Output.Setlinfo.OverlmtSelfpay
  3189. order.PreselfpayAmt = res2.Output.Setlinfo.PreselfpayAmt
  3190. order.InscpScpAmt = res2.Output.Setlinfo.InscpScpAmt
  3191. order.ActPayDedc = res2.Output.Setlinfo.ActPayDedc
  3192. order.HifmiPay = res2.Output.Setlinfo.HifmiPay
  3193. order.HifpPay = res2.Output.Setlinfo.HifpPay
  3194. order.HifesPay = res2.Output.Setlinfo.HifesPay
  3195. order.HifobPay = res2.Output.Setlinfo.HifobPay
  3196. order.MafPay = res2.Output.Setlinfo.MafPay
  3197. order.OthPay = res2.Output.Setlinfo.OthPay
  3198. order.CvlservPay = res2.Output.Setlinfo.CvlservPay
  3199. order.PoolPropSelfpay = res2.Output.Setlinfo.PoolPropSelfpay
  3200. order.FundPaySumamt = res2.Output.Setlinfo.FundPaySumamt
  3201. order.PsnPartAmt = res2.Output.Setlinfo.PsnPartAmt
  3202. order.AcctPay = res2.Output.Setlinfo.AcctPay
  3203. order.PsnCashPay = res2.Output.Setlinfo.PsnCashPay
  3204. order.HospPartAmt = res2.Output.Setlinfo.HospPartAmt
  3205. order.Balc = res2.Output.Setlinfo.Balc
  3206. order.AcctMulaidPay = res2.Output.Setlinfo.AcctMulaidPay
  3207. order.MedinsSetlId = res2.Output.Setlinfo.MedinsSetlID
  3208. order.ClrOptins = res2.Output.Setlinfo.ClrOptins
  3209. order.ClrWay = res2.Output.Setlinfo.ClrWay
  3210. order.Creator = order.Creator
  3211. order.Modify = roles.AdminUserId
  3212. order.RequestLog = src_resquest
  3213. setlDetail, _ := json.Marshal(res2.Output.Setldetail)
  3214. detailStr := string(setlDetail)
  3215. order.SetlDetail = detailStr
  3216. c.ServeSuccessJSON(map[string]interface{}{
  3217. "msg": "预结算成功",
  3218. "order": order,
  3219. "order_way": 2,
  3220. })
  3221. }
  3222. }
  3223. } else {
  3224. if miConfig.Code == "H15049901371" {
  3225. if err := json.Unmarshal(userJSONBytes, &resSeven10265); err != nil {
  3226. utils.ErrorLog("解析失败:%v", err)
  3227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3228. return
  3229. }
  3230. Infcode, _ := strconv.ParseInt(resSeven10265.Infcode, 10, 64)
  3231. res.Infcode = Infcode
  3232. res.InfRefmsgid = resSeven10265.InfRefmsgid
  3233. res.RespondTime = resSeven10265.RespondTime
  3234. res.ErrMsg = resSeven10265.ErrMsg
  3235. res.Output = resSeven10265.Output
  3236. res.WarnMsg = resSeven10265.WarnMsg
  3237. res.Cainfo = resSeven10265.Cainfo
  3238. } else {
  3239. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3240. utils.ErrorLog("解析失败:%v", err)
  3241. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3242. return
  3243. }
  3244. }
  3245. if res.Infcode != 0 {
  3246. errlog := &models.HisOrderError{
  3247. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3248. Ctime: time.Now().Unix(),
  3249. Mtime: time.Now().Unix(),
  3250. Number: chrg_bchno,
  3251. ErrMsg: res.ErrMsg,
  3252. Status: 1,
  3253. PatientId: patient_id,
  3254. RecordTime: time.Now().Unix(),
  3255. Stage: 6,
  3256. }
  3257. service.CreateErrMsgLog(errlog)
  3258. c.ServeSuccessJSON(map[string]interface{}{
  3259. "failed_code": -10,
  3260. "msg": res.ErrMsg,
  3261. })
  3262. return
  3263. } else {
  3264. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  3265. order.OrderStatus = 1
  3266. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  3267. order.SetlId = res.Output.Setlinfo.SetlID
  3268. order.PsnNo = res.Output.Setlinfo.PsnNo
  3269. order.PsnName = res.Output.Setlinfo.PsnName
  3270. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  3271. order.Certno = res.Output.Setlinfo.Certno
  3272. order.Gend = res.Output.Setlinfo.Gend
  3273. order.Naty = res.Output.Setlinfo.Naty
  3274. order.Age = res.Output.Setlinfo.Age
  3275. order.Insutype = res.Output.Setlinfo.Insutype
  3276. order.PsnType = res.Output.Setlinfo.PsnType
  3277. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  3278. order.SetlTime = res.Output.Setlinfo.SetlTime
  3279. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  3280. if res.Output.Setlinfo.MedType == "140104" {
  3281. order.MedType = "14"
  3282. } else {
  3283. order.MedType = res.Output.Setlinfo.MedType
  3284. }
  3285. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  3286. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  3287. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  3288. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  3289. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  3290. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  3291. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  3292. order.HifpPay = res.Output.Setlinfo.HifpPay
  3293. order.HifesPay = res.Output.Setlinfo.HifesPay
  3294. order.HifobPay = res.Output.Setlinfo.HifobPay
  3295. order.MafPay = res.Output.Setlinfo.MafPay
  3296. order.OthPay = res.Output.Setlinfo.OthPay
  3297. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  3298. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  3299. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  3300. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  3301. order.AcctPay = res.Output.Setlinfo.AcctPay
  3302. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  3303. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  3304. order.Balc = res.Output.Setlinfo.Balc
  3305. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  3306. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  3307. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  3308. order.ClrWay = res.Output.Setlinfo.ClrWay
  3309. order.Creator = order.Creator
  3310. order.Modify = roles.AdminUserId
  3311. order.RequestLog = src_resquest
  3312. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  3313. detailStr := string(setlDetail)
  3314. order.SetlDetail = detailStr
  3315. //err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  3316. if record.OutHospitalStatus == 1 && order.ID > 0 {
  3317. err := service.UpDateOrder(order)
  3318. if err == nil {
  3319. c.ServeSuccessJSON(map[string]interface{}{
  3320. "msg": "预结算成功",
  3321. "order_way": 1,
  3322. })
  3323. } else {
  3324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  3325. return
  3326. }
  3327. } else if record.OutHospitalStatus == 0 && order.ID == 0 {
  3328. c.ServeSuccessJSON(map[string]interface{}{
  3329. "msg": "预结算成功",
  3330. "order": order,
  3331. "order_way": 2,
  3332. })
  3333. }
  3334. }
  3335. }
  3336. }
  3337. func (c *ZHHisApiController) GetUploadInfo() {
  3338. id, _ := c.GetInt64("id")
  3339. record_time := c.GetString("record_time")
  3340. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  3341. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  3342. admin_user_id, _ := c.GetInt64("admin_user_id")
  3343. timeLayout := "2006-01-02"
  3344. loc, _ := time.LoadLocation("Local")
  3345. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3346. if err != nil {
  3347. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3348. return
  3349. }
  3350. recordDateTime := theTime.Unix()
  3351. adminUser := c.GetAdminUserInfo()
  3352. var prescriptions []*models.HisPrescription
  3353. data := make(map[string]interface{})
  3354. if settle_accounts_type == 1 { //日结
  3355. prescriptions, _ = service.GetZHHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  3356. } else { //月结
  3357. start_time_str := c.GetString("start_time")
  3358. end_time_str := c.GetString("end_time")
  3359. timeLayout := "2006-01-02"
  3360. loc, _ := time.LoadLocation("Local")
  3361. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3362. if err != nil {
  3363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3364. return
  3365. }
  3366. recordStartTime := theStartTime.Unix()
  3367. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3368. if err != nil {
  3369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3370. return
  3371. }
  3372. recordEndTime := theEndTime.Unix()
  3373. prescriptions, _ = service.GetZHMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  3374. }
  3375. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3376. record, _ := service.GetInHospitalRecord(in_hospital_id)
  3377. if record.ID == 0 {
  3378. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3379. return
  3380. }
  3381. timestamp := time.Now().Unix()
  3382. tempTime := time.Unix(timestamp, 0)
  3383. timeFormat := tempTime.Format("20060102150405")
  3384. chrgBchno := rand.Intn(100000) + 10000
  3385. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(record.PatientId, 10)
  3386. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3387. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  3388. department, _ := service.GetDepartMentDetail(record.Departments)
  3389. strconv.FormatInt(record.PatientId, 10)
  3390. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.Creator)
  3391. //client := &http.Client{}
  3392. data["psn_no"] = record.PsnNo
  3393. data["mdtrt_id"] = record.Number
  3394. data["chrg_bchno"] = chrg_bchno
  3395. data["org_name"] = miConfig.OrgName
  3396. data["doctor"] = roles.UserName
  3397. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  3398. data["dept"] = strconv.FormatInt(department.ID, 10)
  3399. data["fixmedins_code"] = miConfig.Code
  3400. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  3401. data["dept_code"] = "15"
  3402. } else {
  3403. data["dept_code"] = department.Number
  3404. }
  3405. if miConfig.Code == "H15049901371" {
  3406. if record.MedType == 14 {
  3407. if record.InsutypeType == "390" {
  3408. data["med_type"] = ""
  3409. } else if record.InsutypeType == "310" {
  3410. data["med_type"] = ""
  3411. }
  3412. } else if record.MedType == 11 {
  3413. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  3414. }
  3415. } else {
  3416. if record.MedType == 1112 {
  3417. data["med_type"] = strconv.FormatInt(11, 10)
  3418. } else {
  3419. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  3420. }
  3421. }
  3422. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  3423. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  3424. data["secret_key"] = miConfig.SecretKey
  3425. var ids []int64
  3426. fmt.Println(data)
  3427. for _, item := range prescriptions {
  3428. ids = append(ids, item.ID)
  3429. }
  3430. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3431. if config.IsOpen == 1 { //对接了医保,走医保流程
  3432. var pagesize int = 10
  3433. var start int = 1
  3434. var stop int
  3435. var pagecount int
  3436. var curpage int
  3437. var isSuccess bool = true
  3438. var customs []*models.NewCustom
  3439. var empty_code_errs []string
  3440. for _, item := range prescriptions {
  3441. if item.Type == 1 { //药品
  3442. for _, subItem := range item.HisDoctorAdviceInfo {
  3443. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) == 0 && subItem.Price > 0{
  3444. empty_code_errs = append(empty_code_errs,subItem.BaseDrugLib.DrugName)
  3445. }
  3446. }
  3447. }
  3448. if item.Type == 2 { //项目
  3449. for _, subItem := range item.HisPrescriptionProject {
  3450. //var randNum int
  3451. //randNum = rand.Intn(10000) + 1000
  3452. if subItem.Type == 2 {
  3453. if len(subItem.HisProject.MedicalCode) == 0 && subItem.Price > 0{
  3454. empty_code_errs = append(empty_code_errs,subItem.HisProject.ProjectName)
  3455. }
  3456. } else if subItem.Type == 3 {
  3457. if len(subItem.GoodInfo.MedicalInsuranceNumber) == 0 && subItem.Price > 0 {
  3458. empty_code_errs = append(empty_code_errs,subItem.GoodInfo.GoodName)
  3459. }
  3460. }
  3461. }
  3462. }
  3463. }
  3464. if len(empty_code_errs) > 0{
  3465. var err string
  3466. for _, item := range empty_code_errs{
  3467. if len(err) == 0{
  3468. err = item
  3469. }else{
  3470. err = err +"," + item
  3471. }
  3472. }
  3473. c.ServeSuccessJSON(map[string]interface{}{
  3474. "failed_code": -10,
  3475. "msg": err +" "+ "没有填写国家编码",
  3476. })
  3477. return
  3478. }
  3479. for _, item := range prescriptions {
  3480. tm := time.Unix(item.PreTime, 0)
  3481. if item.Type == 1 { //药品
  3482. for _, subItem := range item.HisDoctorAdviceInfo {
  3483. //var randNum int
  3484. //randNum = rand.Intn(10000) + 1000
  3485. cus := &models.NewCustom{
  3486. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  3487. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  3488. FeedetlSn: subItem.FeedetlSn,
  3489. Price: fmt.Sprintf("%.4f", subItem.Price),
  3490. MedListCodg: subItem.BaseDrugLib.MedicalInsuranceNumber,
  3491. HospApprFlag: subItem.BaseDrugLib.HospApprFlag,
  3492. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  3493. DoctorId: item.Creator,
  3494. }
  3495. customs = append(customs, cus)
  3496. }
  3497. }
  3498. if item.Type == 2 { //项目
  3499. for _, subItem := range item.HisPrescriptionProject {
  3500. //var randNum int
  3501. //randNum = rand.Intn(10000) + 1000
  3502. if subItem.Type == 2 {
  3503. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  3504. cus := &models.NewCustom{
  3505. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  3506. Cut: fmt.Sprintf("%.4f", cnt),
  3507. FeedetlSn: subItem.FeedetlSn,
  3508. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  3509. MedListCodg: subItem.HisProject.MedicalCode,
  3510. HospApprFlag: -1,
  3511. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  3512. DoctorId: item.Creator,
  3513. }
  3514. customs = append(customs, cus)
  3515. } else if subItem.Type == 3 {
  3516. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  3517. cus := &models.NewCustom{
  3518. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  3519. Cut: fmt.Sprintf("%.4f", cnt),
  3520. FeedetlSn: subItem.FeedetlSn,
  3521. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  3522. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  3523. HospApprFlag: -1,
  3524. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  3525. DoctorId: item.Creator,
  3526. }
  3527. customs = append(customs, cus)
  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, "2305", "退费")
  3923. } else if miConfig.MdtrtareaAdmvs == "360399" {
  3924. 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)
  3925. saveLog(result, requestLog, "2305", "退费")
  3926. } else {
  3927. result, requestLog := service.Gdyb2305(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  3928. saveLog(result, requestLog, "2305", "退费")
  3929. }
  3930. var dat map[string]interface{}
  3931. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3932. fmt.Println(dat)
  3933. } else {
  3934. fmt.Println(err)
  3935. }
  3936. userJSONBytes, _ := json.Marshal(dat)
  3937. var res ResultSixteen
  3938. var resSixteen ResultSixteen10265
  3939. if miConfig.Code == "H15049901371" {
  3940. if err := json.Unmarshal(userJSONBytes, &resSixteen); err != nil {
  3941. utils.ErrorLog("解析失败:%v", err)
  3942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3943. return
  3944. }
  3945. res.Cainfo = resSixteen.Cainfo
  3946. res.WarnMsg = resSixteen.WarnMsg
  3947. res.Output = resSixteen.Output
  3948. res.ErrMsg = resSixteen.ErrMsg
  3949. res.RespondTime = resSixteen.RespondTime
  3950. Infcode, _ := strconv.ParseInt(resSixteen.Infcode, 10, 64)
  3951. res.Infcode = Infcode
  3952. } else {
  3953. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3954. utils.ErrorLog("解析失败:%v", err)
  3955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3956. return
  3957. }
  3958. }
  3959. if res.Infcode == 0 {
  3960. err := service.UpdataOrderStatusThree(order_id, order.Number, adminUser.CurrentOrgId, "", result)
  3961. //不同地区退费流程不一样,肇庆那边退费就包括撤销出院,内蒙古退费不包括撤销明细,所以下面需要根据不同情况进行判断
  3962. if miConfig.UserOrgId == 10215 {
  3963. record.OutHospitalStatus = 0
  3964. service.CreateHospitalRecord(&record)
  3965. }
  3966. service.UpdataOrderStatusByNumber(record.Number)
  3967. if err == nil {
  3968. ////当押金不为零时产生退费记录
  3969. if order.Decimal != 0 {
  3970. tmp := strconv.FormatInt(order.ID, 10)
  3971. err = service.MoneyIncrease(adminUser.CurrentOrgId, order.PatientId, tmp, order.Decimal)
  3972. if err != nil {
  3973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3974. return
  3975. }
  3976. }
  3977. c.ServeSuccessJSON(map[string]interface{}{
  3978. "msg": "退费成功",
  3979. })
  3980. } else {
  3981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3982. return
  3983. }
  3984. } else {
  3985. c.ServeSuccessJSON(map[string]interface{}{
  3986. "code": -10,
  3987. "msg": res.ErrMsg,
  3988. })
  3989. }
  3990. } else {
  3991. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  3992. if err == nil {
  3993. c.ServeSuccessJSON(map[string]interface{}{
  3994. "msg": "退费成功",
  3995. })
  3996. } else {
  3997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3998. return
  3999. }
  4000. }
  4001. }
  4002. func (c *ZHHisApiController) ZHRefundDetail() {
  4003. patient_id, _ := c.GetInt64("patient_id")
  4004. his_patient_id, _ := c.GetInt64("his_patient_id")
  4005. record_time := c.GetString("record_time")
  4006. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  4007. //order_id, _ := c.GetInt64("order_id")
  4008. admin_user_id, _ := c.GetInt64("admin_user_id")
  4009. timeLayout := "2006-01-02"
  4010. loc, _ := time.LoadLocation("Local")
  4011. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4012. if err != nil {
  4013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4014. return
  4015. }
  4016. recordDateTime := theTime.Unix()
  4017. adminUser := c.GetAdminUserInfo()
  4018. theTimeTwo, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 23:59:59", loc)
  4019. if err != nil {
  4020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4021. return
  4022. }
  4023. recordDateTimeTwo := theTimeTwo.Unix()
  4024. //var prescriptions []*models.HisPrescription
  4025. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4026. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4027. if settle_accounts_type == 1 { //日结
  4028. record, _ := service.GetInHospitalRecord(his_patient_id)
  4029. infos, _ := service.GetZHHisUploadOrderInfo(adminUser.CurrentOrgId, patient_id, recordDateTime, recordDateTimeTwo, record.Number)
  4030. var isSuccess bool = true
  4031. for _, item := range infos {
  4032. var result string
  4033. var requestLog string
  4034. if miConfig.MdtrtareaAdmvs == "150499" {
  4035. //请求内网数据
  4036. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&feedetl_sn=" + item.FeedetlSn +
  4037. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  4038. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "1"
  4039. resp, requestErr := http.Get(api)
  4040. if requestErr != nil {
  4041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4042. return
  4043. }
  4044. body, ioErr := ioutil.ReadAll(resp.Body)
  4045. if ioErr != nil {
  4046. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4048. return
  4049. }
  4050. var respJSON map[string]interface{}
  4051. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4052. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4054. return
  4055. }
  4056. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4057. result_byte, _ := json.Marshal(respJSON)
  4058. result = string(result_byte)
  4059. saveLog(result, requestLog, "2302", "日结退明细")
  4060. } else if miConfig.MdtrtareaAdmvs == "421182" {
  4061. //请求内网数据
  4062. api := miConfig.Url + "hbyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&feedetl_sn=" + item.FeedetlSn +
  4063. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  4064. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "1"
  4065. resp, requestErr := http.Get(api)
  4066. if requestErr != nil {
  4067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4068. return
  4069. }
  4070. body, ioErr := ioutil.ReadAll(resp.Body)
  4071. if ioErr != nil {
  4072. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4074. return
  4075. }
  4076. var respJSON map[string]interface{}
  4077. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4078. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4080. return
  4081. }
  4082. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4083. result_byte, _ := json.Marshal(respJSON)
  4084. result = string(result_byte)
  4085. saveLog(result, requestLog, "2302", "日结退明细")
  4086. } else if miConfig.MdtrtareaAdmvs == "360399" {
  4087. 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)
  4088. saveLog(result, requestLog, "2302", "日结退明细")
  4089. } else {
  4090. result, requestLog := service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, item.FeedetlSn, 1)
  4091. saveLog(result, requestLog, "2302", "日结退明细")
  4092. }
  4093. var dat map[string]interface{}
  4094. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4095. fmt.Println(dat)
  4096. } else {
  4097. fmt.Println(err)
  4098. }
  4099. userJSONBytes, _ := json.Marshal(dat)
  4100. var res2 ResultEmpty
  4101. var resEmpty10265 ResultEmpty10265
  4102. if miConfig.Code == "H15049901371" {
  4103. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  4104. utils.ErrorLog("解析失败:%v", err)
  4105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4106. return
  4107. }
  4108. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  4109. res2.Infcode = Infcode
  4110. res2.RespondTime = resEmpty10265.RespondTime
  4111. res2.ErrMsg = resEmpty10265.ErrMsg
  4112. res2.Output = resEmpty10265.Output
  4113. res2.WarnMsg = resEmpty10265.WarnMsg
  4114. } else {
  4115. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  4116. utils.ErrorLog("解析失败:%v", err)
  4117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4118. return
  4119. }
  4120. }
  4121. if res2.Infcode == -1 {
  4122. isSuccess = false
  4123. }
  4124. }
  4125. if isSuccess {
  4126. err := service.UpDateOrderInfoStatus(patient_id, recordDateTime, adminUser.CurrentOrgId, recordDateTimeTwo)
  4127. if err != nil {
  4128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4129. return
  4130. }
  4131. err1 := service.UpDatePrescriptionOrderStatusTwo(patient_id, recordDateTime, adminUser.CurrentOrgId)
  4132. if err1 != nil {
  4133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4134. return
  4135. }
  4136. c.ServeSuccessJSON(map[string]interface{}{
  4137. "msg": "撤销明细成功",
  4138. })
  4139. }
  4140. } else {
  4141. //prescriptions, _ = service.GetZHMonthHisUploadPrescription(adminUser.CurrentOrgId, patient_id, recordDateTime)
  4142. //var order models.HisOrder
  4143. //order, _ = service.GetHisOrderByID(order_id)
  4144. //record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  4145. var result string
  4146. var requestLog string
  4147. record, _ := service.GetInHospitalRecord(his_patient_id)
  4148. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4149. if config.IsOpen == 1 { //对接了医保,走医保流程
  4150. if miConfig.MdtrtareaAdmvs == "150499" {
  4151. //请求内网数据
  4152. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=0000" +
  4153. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  4154. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "0"
  4155. resp, requestErr := http.Get(api)
  4156. if requestErr != nil {
  4157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4158. return
  4159. }
  4160. body, ioErr := ioutil.ReadAll(resp.Body)
  4161. if ioErr != nil {
  4162. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4164. return
  4165. }
  4166. var respJSON map[string]interface{}
  4167. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4168. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4170. return
  4171. }
  4172. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4173. result_byte, _ := json.Marshal(respJSON)
  4174. result = string(result_byte)
  4175. //saveLog(result, requestLog, "2302", "日结退明细")
  4176. } else if miConfig.MdtrtareaAdmvs == "421182" {
  4177. //请求内网数据
  4178. api := miConfig.Url + "hbyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=0000" +
  4179. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  4180. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "0"
  4181. resp, requestErr := http.Get(api)
  4182. if requestErr != nil {
  4183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4184. return
  4185. }
  4186. body, ioErr := ioutil.ReadAll(resp.Body)
  4187. if ioErr != nil {
  4188. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4190. return
  4191. }
  4192. var respJSON map[string]interface{}
  4193. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4194. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4196. return
  4197. }
  4198. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4199. result_byte, _ := json.Marshal(respJSON)
  4200. result = string(result_byte)
  4201. //saveLog(result, requestLog, "2302", "日结退明细")
  4202. } else if miConfig.MdtrtareaAdmvs == "360399" {
  4203. 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)
  4204. saveLog(result, requestLog, "2302", "月结退明细")
  4205. } else {
  4206. result, requestLog = service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  4207. saveLog(result, requestLog, "2302", "月结退明细")
  4208. }
  4209. var dat map[string]interface{}
  4210. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4211. fmt.Println(dat)
  4212. } else {
  4213. fmt.Println(err)
  4214. }
  4215. userJSONBytes, _ := json.Marshal(dat)
  4216. var res2 ResultEmpty
  4217. var resEmpty10265 ResultEmpty10265
  4218. if miConfig.Code == "H15049901371" {
  4219. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  4220. utils.ErrorLog("解析失败:%v", err)
  4221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4222. return
  4223. }
  4224. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  4225. res2.Infcode = Infcode
  4226. res2.RespondTime = resEmpty10265.RespondTime
  4227. res2.ErrMsg = resEmpty10265.ErrMsg
  4228. res2.Output = resEmpty10265.Output
  4229. res2.WarnMsg = resEmpty10265.WarnMsg
  4230. } else {
  4231. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  4232. utils.ErrorLog("解析失败:%v", err)
  4233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4234. return
  4235. }
  4236. }
  4237. if res2.Infcode == 0 {
  4238. err := service.UpdataHospitalOrderStatus(record.Number, adminUser.CurrentOrgId)
  4239. if err == nil {
  4240. c.ServeSuccessJSON(map[string]interface{}{
  4241. "msg": "撤销明细成功",
  4242. })
  4243. } else {
  4244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4245. return
  4246. }
  4247. } else {
  4248. c.ServeSuccessJSON(map[string]interface{}{
  4249. "code": -10,
  4250. "msg": res2.ErrMsg,
  4251. })
  4252. }
  4253. }
  4254. }
  4255. }
  4256. func (this *ZHHisApiController) GetZHOutHospitalUnCheck() {
  4257. id, _ := this.GetInt64("id")
  4258. admin_user_id, _ := this.GetInt64("admin_user_id")
  4259. adminInfo := this.GetAdminUserInfo()
  4260. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  4261. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  4262. record, _ := service.GetInHospitalRecord(id)
  4263. if record.ID == 0 {
  4264. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  4265. return
  4266. }
  4267. var result string
  4268. var requestLog string
  4269. if miConfig.MdtrtareaAdmvs == "150499" {
  4270. //请求内网数据
  4271. api := "http://172.16.13.254:9532/" + "nmyb/2405?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  4272. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  4273. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4274. fmt.Println(api)
  4275. resp, requestErr := http.Get(api)
  4276. if requestErr != nil {
  4277. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4278. return
  4279. }
  4280. body, ioErr := ioutil.ReadAll(resp.Body)
  4281. if ioErr != nil {
  4282. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4283. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4284. return
  4285. }
  4286. var respJSON map[string]interface{}
  4287. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4288. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4289. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4290. return
  4291. }
  4292. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4293. result_byte, _ := json.Marshal(respJSON)
  4294. result = string(result_byte)
  4295. } else if miConfig.MdtrtareaAdmvs == "421182" {
  4296. //请求内网数据
  4297. api := miConfig.Url + "hbyb/2405?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  4298. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  4299. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4300. fmt.Println(api)
  4301. resp, requestErr := http.Get(api)
  4302. if requestErr != nil {
  4303. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4304. return
  4305. }
  4306. body, ioErr := ioutil.ReadAll(resp.Body)
  4307. if ioErr != nil {
  4308. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4309. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4310. return
  4311. }
  4312. var respJSON map[string]interface{}
  4313. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4314. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4315. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4316. return
  4317. }
  4318. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4319. result_byte, _ := json.Marshal(respJSON)
  4320. result = string(result_byte)
  4321. } else if miConfig.MdtrtareaAdmvs == "360399" {
  4322. result, requestLog = service.Jxyb2405(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.Url, "", miConfig.AccessKey)
  4323. saveLog(result, requestLog, "2405", "出院登记撤销")
  4324. } else {
  4325. result, requestLog = service.ZHGdyb2405(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  4326. saveLog(result, requestLog, "2405", "出院登记撤销")
  4327. }
  4328. var dat map[string]interface{}
  4329. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4330. fmt.Println(dat)
  4331. } else {
  4332. fmt.Println(err)
  4333. }
  4334. userJSONBytes, _ := json.Marshal(dat)
  4335. var res ResultEmpty
  4336. var resEmpty10265 ResultEmpty10265
  4337. if miConfig.Code == "H15049901371" {
  4338. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  4339. utils.ErrorLog("解析失败:%v", err)
  4340. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4341. return
  4342. }
  4343. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  4344. res.Infcode = Infcode
  4345. res.RespondTime = resEmpty10265.RespondTime
  4346. res.ErrMsg = resEmpty10265.ErrMsg
  4347. res.Output = resEmpty10265.Output
  4348. res.WarnMsg = resEmpty10265.WarnMsg
  4349. } else {
  4350. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4351. utils.ErrorLog("解析失败:%v", err)
  4352. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4353. return
  4354. }
  4355. }
  4356. if res.Infcode == 0 {
  4357. record.OutHospitalStatus = 0
  4358. service.CreateHospitalRecord(&record)
  4359. service.UpdataOrderStatusByNumber(record.Number)
  4360. this.ServeSuccessJSON(map[string]interface{}{
  4361. "msg": "撤销出院成功",
  4362. })
  4363. } else {
  4364. this.ServeSuccessJSON(map[string]interface{}{
  4365. "failed_code": -10,
  4366. "msg": res.ErrMsg,
  4367. })
  4368. }
  4369. }
  4370. func (this *ZHHisApiController) GetZHInHospitalUnCheck() {
  4371. id, _ := this.GetInt64("id")
  4372. admin_user_id, _ := this.GetInt64("admin_user_id")
  4373. adminInfo := this.GetAdminUserInfo()
  4374. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  4375. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  4376. record, _ := service.GetInHospitalRecord(id)
  4377. if record.ID == 0 {
  4378. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  4379. return
  4380. }
  4381. var result string
  4382. var requestLog string
  4383. orders, _ := service.GetHisOrderInfoByNumber(record.Number)
  4384. if len(orders) > 0 { //判断是否上传过明细,有的话需要退明细,后撤销入院
  4385. if miConfig.MdtrtareaAdmvs == "150499" {
  4386. //请求内网数据
  4387. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=" + "0000" +
  4388. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  4389. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=0"
  4390. resp, requestErr := http.Get(api)
  4391. if requestErr != nil {
  4392. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4393. return
  4394. }
  4395. body, ioErr := ioutil.ReadAll(resp.Body)
  4396. if ioErr != nil {
  4397. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4398. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4399. return
  4400. }
  4401. var respJSON map[string]interface{}
  4402. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4403. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4404. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4405. return
  4406. }
  4407. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4408. result_byte, _ := json.Marshal(respJSON)
  4409. result = string(result_byte)
  4410. saveLog(result, requestLog, "2302", "月结退明细")
  4411. }else if miConfig.MdtrtareaAdmvs == "421182" {
  4412. //请求内网数据
  4413. api := miConfig.Url + "hbyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=" + "0000" +
  4414. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  4415. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=0"
  4416. resp, requestErr := http.Get(api)
  4417. if requestErr != nil {
  4418. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4419. return
  4420. }
  4421. body, ioErr := ioutil.ReadAll(resp.Body)
  4422. if ioErr != nil {
  4423. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4424. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4425. return
  4426. }
  4427. var respJSON map[string]interface{}
  4428. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4429. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4430. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4431. return
  4432. }
  4433. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4434. result_byte, _ := json.Marshal(respJSON)
  4435. result = string(result_byte)
  4436. saveLog(result, requestLog, "2302", "月结退明细")
  4437. } else if miConfig.MdtrtareaAdmvs == "360399" {
  4438. 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)
  4439. saveLog(result, requestLog, "2302", "月结退明细")
  4440. } else {
  4441. result, requestLog = service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  4442. saveLog(result, requestLog, "2302", "月结退明细")
  4443. }
  4444. var dat map[string]interface{}
  4445. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4446. fmt.Println(dat)
  4447. } else {
  4448. fmt.Println(err)
  4449. }
  4450. userJSONBytes, _ := json.Marshal(dat)
  4451. var res2 ResultEmpty
  4452. var resEmpty10265 ResultEmpty10265
  4453. if miConfig.Code == "H15049901371" {
  4454. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  4455. utils.ErrorLog("解析失败:%v", err)
  4456. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4457. return
  4458. }
  4459. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  4460. res2.Infcode = Infcode
  4461. res2.RespondTime = resEmpty10265.RespondTime
  4462. res2.ErrMsg = resEmpty10265.ErrMsg
  4463. res2.Output = resEmpty10265.Output
  4464. res2.WarnMsg = resEmpty10265.WarnMsg
  4465. } else {
  4466. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  4467. utils.ErrorLog("解析失败:%v", err)
  4468. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4469. return
  4470. }
  4471. }
  4472. if res2.Infcode == 0 {
  4473. service.UpdataHospitalOrderStatus(record.Number, adminInfo.CurrentOrgId)
  4474. var result string
  4475. var requestLog string
  4476. if miConfig.MdtrtareaAdmvs == "150499" {
  4477. //请求内网数据
  4478. api := "http://172.16.13.254:9532/" + "nmyb/2404?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  4479. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  4480. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4481. resp, requestErr := http.Get(api)
  4482. if requestErr != nil {
  4483. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4484. return
  4485. }
  4486. body, ioErr := ioutil.ReadAll(resp.Body)
  4487. if ioErr != nil {
  4488. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4489. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4490. return
  4491. }
  4492. var respJSON map[string]interface{}
  4493. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4494. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4495. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4496. return
  4497. }
  4498. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4499. result_byte, _ := json.Marshal(respJSON)
  4500. result = string(result_byte)
  4501. } else if miConfig.MdtrtareaAdmvs == "421182" {
  4502. //请求内网数据
  4503. api := miConfig.Url + "hbyb/2404?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  4504. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  4505. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4506. resp, requestErr := http.Get(api)
  4507. if requestErr != nil {
  4508. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4509. return
  4510. }
  4511. body, ioErr := ioutil.ReadAll(resp.Body)
  4512. if ioErr != nil {
  4513. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4514. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4515. return
  4516. }
  4517. var respJSON map[string]interface{}
  4518. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4519. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4520. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4521. return
  4522. }
  4523. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4524. result_byte, _ := json.Marshal(respJSON)
  4525. result = string(result_byte)
  4526. } else if miConfig.MdtrtareaAdmvs == "360399" {
  4527. result, requestLog = service.Jxyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.Url, "", miConfig.AccessKey)
  4528. saveLog(result, requestLog, "2404", "入院登记撤销")
  4529. } else {
  4530. result, requestLog = service.ZHGdyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  4531. saveLog(result, requestLog, "2404", "入院登记撤销")
  4532. }
  4533. var dat map[string]interface{}
  4534. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4535. fmt.Println(dat)
  4536. } else {
  4537. fmt.Println(err)
  4538. }
  4539. userJSONBytes, _ := json.Marshal(dat)
  4540. var res ResultEmpty
  4541. var resEmpty10265 ResultEmpty10265
  4542. if miConfig.Code == "H15049901371" {
  4543. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  4544. utils.ErrorLog("解析失败:%v", err)
  4545. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4546. return
  4547. }
  4548. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  4549. res.Infcode = Infcode
  4550. res.RespondTime = resEmpty10265.RespondTime
  4551. res.ErrMsg = resEmpty10265.ErrMsg
  4552. res.Output = resEmpty10265.Output
  4553. res.WarnMsg = resEmpty10265.WarnMsg
  4554. } else {
  4555. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4556. utils.ErrorLog("解析失败:%v", err)
  4557. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4558. return
  4559. }
  4560. }
  4561. if res.Infcode == 0 {
  4562. record.Status = 0
  4563. service.CreateHospitalRecord(&record)
  4564. this.ServeSuccessJSON(map[string]interface{}{
  4565. "msg": "撤销入院成功",
  4566. })
  4567. } else {
  4568. this.ServeSuccessJSON(map[string]interface{}{
  4569. "failed_code": -10,
  4570. "msg": res.ErrMsg,
  4571. })
  4572. }
  4573. } else {
  4574. this.ServeSuccessJSON(map[string]interface{}{
  4575. "code": -10,
  4576. "msg": res2.ErrMsg,
  4577. })
  4578. }
  4579. } else { //没有上传过明细的,直接撤销入院
  4580. var result string
  4581. var requestLog string
  4582. if miConfig.MdtrtareaAdmvs == "150499" {
  4583. //请求内网数据
  4584. api := "http://172.16.13.254:9532/" + "nmyb/2404?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  4585. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  4586. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4587. resp, requestErr := http.Get(api)
  4588. if requestErr != nil {
  4589. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4590. return
  4591. }
  4592. body, ioErr := ioutil.ReadAll(resp.Body)
  4593. if ioErr != nil {
  4594. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4595. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4596. return
  4597. }
  4598. var respJSON map[string]interface{}
  4599. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4600. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4601. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4602. return
  4603. }
  4604. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4605. result_byte, _ := json.Marshal(respJSON)
  4606. result = string(result_byte)
  4607. } else if miConfig.MdtrtareaAdmvs == "421182" {
  4608. //请求内网数据
  4609. api := miConfig.Url + "hbyb/2404?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  4610. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  4611. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4612. resp, requestErr := http.Get(api)
  4613. if requestErr != nil {
  4614. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4615. return
  4616. }
  4617. body, ioErr := ioutil.ReadAll(resp.Body)
  4618. if ioErr != nil {
  4619. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4620. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4621. return
  4622. }
  4623. var respJSON map[string]interface{}
  4624. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4625. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4626. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4627. return
  4628. }
  4629. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4630. result_byte, _ := json.Marshal(respJSON)
  4631. result = string(result_byte)
  4632. } else if miConfig.MdtrtareaAdmvs == "360399" {
  4633. result, requestLog = service.Jxyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.Url, "", miConfig.AccessKey)
  4634. saveLog(result, requestLog, "2404", "入院登记撤销")
  4635. } else {
  4636. result, requestLog = service.ZHGdyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  4637. saveLog(result, requestLog, "2404", "入院登记撤销")
  4638. }
  4639. var dat map[string]interface{}
  4640. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4641. fmt.Println(dat)
  4642. } else {
  4643. fmt.Println(err)
  4644. }
  4645. userJSONBytes, _ := json.Marshal(dat)
  4646. var res ResultEmpty
  4647. var resEmpty10265 ResultEmpty10265
  4648. if miConfig.Code == "H15049901371" {
  4649. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  4650. utils.ErrorLog("解析失败:%v", err)
  4651. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4652. return
  4653. }
  4654. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  4655. res.Infcode = Infcode
  4656. res.RespondTime = resEmpty10265.RespondTime
  4657. res.ErrMsg = resEmpty10265.ErrMsg
  4658. res.Output = resEmpty10265.Output
  4659. res.WarnMsg = resEmpty10265.WarnMsg
  4660. } else {
  4661. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4662. utils.ErrorLog("解析失败:%v", err)
  4663. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4664. return
  4665. }
  4666. }
  4667. if res.Infcode == 0 {
  4668. record.Status = 0
  4669. service.CreateHospitalRecord(&record)
  4670. this.ServeSuccessJSON(map[string]interface{}{
  4671. "msg": "撤销入院成功",
  4672. })
  4673. } else {
  4674. this.ServeSuccessJSON(map[string]interface{}{
  4675. "failed_code": -10,
  4676. "msg": res.ErrMsg,
  4677. })
  4678. }
  4679. }
  4680. }
  4681. func saveLog(result string, request string, infno string, desc string) {
  4682. org_id, _ := beego.AppConfig.Int64("org_id")
  4683. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  4684. dir := miConfig.OrgName + "日志"
  4685. utils.Mkdir(dir)
  4686. month := time.Unix(1557042972, 0).Format("1")
  4687. year := time.Now().Format("2006")
  4688. month = time.Now().Format("01")
  4689. day := time.Now().Format("02")
  4690. hour := time.Now().Format("15")
  4691. min := time.Now().Format("04")
  4692. sec := time.Now().Format("05")
  4693. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  4694. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  4695. file_name := file + ".txt"
  4696. file_path := miConfig.OrgName + "日志" + "/" + file_name
  4697. exist, _ := utils.PathExists(file_path)
  4698. if exist { //存在
  4699. fmt.Println("存在")
  4700. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  4701. if err != nil {
  4702. fmt.Println("read fail")
  4703. }
  4704. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  4705. n, _ := f.Seek(0, 2)
  4706. _, err = f.WriteAt([]byte(content), n)
  4707. } else { //不存在
  4708. fmt.Println("文件不存在,创建文件")
  4709. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  4710. defer f.Close()
  4711. if err != nil {
  4712. } else {
  4713. _, err = f.Write([]byte("记录日志"))
  4714. }
  4715. }
  4716. }
  4717. type Charset string
  4718. const (
  4719. UTF8 = Charset("UTF-8")
  4720. GB18030 = Charset("GB18030")
  4721. )
  4722. func ConvertToString(src string, srcCode string, tagCode string) string {
  4723. srcCoder := mahonia.NewDecoder(srcCode)
  4724. srcResult := srcCoder.ConvertString(src)
  4725. tagCoder := mahonia.NewDecoder(tagCode)
  4726. _, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
  4727. result := string(cdata)
  4728. return result
  4729. }
  4730. type ELeData struct {
  4731. Data struct {
  4732. IdNo string `json:"idNo"`
  4733. IdType string `json:"idType"`
  4734. UserName string `json:"userName"`
  4735. EcToken string `json:"ecToken"`
  4736. InsuOrg string `json:"insuOrg"`
  4737. Gender string `json:"gender"`
  4738. Birthday string `json:"birthday"`
  4739. Nationality string `json:"nationality"`
  4740. Email string `json:"email"`
  4741. Extra string `json:"extra"`
  4742. } `json:"data"`
  4743. Code int `json:"code"`
  4744. Message string `json:"message"`
  4745. }
  4746. var initFlagTwo int64 = 0
  4747. func (c *ZHHisApiController) TestGetJiangXiBasBaseInit() {
  4748. DllDef := syscall.MustLoadDLL("SSCard.dll")
  4749. Iinit := DllDef.MustFindProc("Init")
  4750. //miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  4751. //http://10.77.211.236/CSB/hsa-fsi-1303
  4752. ret, _, err := Iinit.Call(StrPtr("http://10.77.224.18:9001/1.0.0/agent-card-init"), StrPtr("360399"))
  4753. if ret != 0 {
  4754. fmt.Println("SSCard的报错原因:", err)
  4755. fmt.Println("SSCard的运算结果为:", ret)
  4756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  4757. return
  4758. }
  4759. result := int(ret)
  4760. fmt.Println("SSCard的运算结果为1:", result)
  4761. initFlag = 1
  4762. return
  4763. }
  4764. func (c *ZHHisApiController) GetBasBaseInfoxxx() string {
  4765. DllDef := syscall.MustLoadDLL("SSCard.dll")
  4766. readCard := DllDef.MustFindProc("ReadCardBas")
  4767. if readCard == nil {
  4768. fmt.Println("readcard is nil")
  4769. readCard = DllDef.MustFindProc("ReadCardBas")
  4770. }
  4771. str := make([]byte, 1024)
  4772. str1 := make([]byte, 1024)
  4773. ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), uintptr(1024), (uintptr)(unsafe.Pointer(&str1[0])), uintptr(1024))
  4774. fmt.Println(string(str1))
  4775. fmt.Println(string(str))
  4776. fmt.Println(":", ConvertToString(string(str1), "gbk", "utf-8"))
  4777. fmt.Println(":", ConvertToString(string(str), "gbk", "utf-8"))
  4778. if ret2 != 0 {
  4779. return ""
  4780. }
  4781. return string(str)
  4782. }
  4783. func (c *ZHHisApiController) ReadEleCardfordevice() {
  4784. admin_user_id, _ := c.GetInt64("admin_user_id")
  4785. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  4786. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  4787. GetjxELekeyInfo(miConfig.Code, "1", roles.UserName)
  4788. }
  4789. func (c *ZHHisApiController) ReadCard() {
  4790. id_card_type, _ := c.GetInt64("id_card_type")
  4791. admin_user_id, _ := c.GetInt64("admin_user_id")
  4792. is_settle := c.GetString("is_settle")
  4793. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  4794. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  4795. switch id_card_type {
  4796. case 1: //社保卡
  4797. if miConfig.MdtrtareaAdmvs == "150499" {
  4798. var api string
  4799. api = "http://172.16.13.254:9532/" + "nmyb/readcard?" + "fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName +
  4800. "&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
  4801. fmt.Println(api)
  4802. resp, requestErr := http.Get(api)
  4803. if requestErr != nil {
  4804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4805. return
  4806. }
  4807. body, ioErr := ioutil.ReadAll(resp.Body)
  4808. if ioErr != nil {
  4809. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4811. return
  4812. }
  4813. var respJSON map[string]interface{}
  4814. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4815. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4816. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4817. return
  4818. }
  4819. var status string
  4820. status = respJSON["data"].(map[string]interface{})["status"].(string)
  4821. card_type := respJSON["data"].(map[string]interface{})["type"].(string)
  4822. //console.log()
  4823. fmt.Println("type===")
  4824. fmt.Println(card_type)
  4825. var token string
  4826. var res ResultTwo //1101结果
  4827. var res10265 ResultTwo10265 //1101结果
  4828. var card_info string //卡信息
  4829. var busi_card_info string
  4830. card_info = respJSON["data"].(map[string]interface{})["card_info"].(string)
  4831. busi_card_info = respJSON["data"].(map[string]interface{})["busi_card_info"].(string)
  4832. if status == "0" { //读卡成功
  4833. if card_type == "1" {
  4834. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  4835. result, _ := json.Marshal(respJSON)
  4836. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  4837. utils.ErrorLog("解析失败:%v", err)
  4838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4839. return
  4840. }
  4841. res.ErrMsg = res10265.ErrMsg
  4842. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  4843. res.Infcode = infocode
  4844. res.Output = res10265.Output
  4845. res.InfRefmsgid = res10265.InfRefmsgid
  4846. } else {
  4847. //var card_info string //卡信息
  4848. //var busi_card_info string
  4849. token = respJSON["data"].(map[string]interface{})["token"].(string)
  4850. //busi_card_info = respJSON["data"].(map[string]interface{})["busi_card_info"].(string)
  4851. //fmt.Println(card_info)
  4852. //fmt.Println(busi_card_info)
  4853. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  4854. result, _ := json.Marshal(respJSON)
  4855. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  4856. utils.ErrorLog("解析失败:%v", err)
  4857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4858. return
  4859. }
  4860. res.ErrMsg = res10265.ErrMsg
  4861. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  4862. res.Infcode = infocode
  4863. res.Output = res10265.Output
  4864. res.InfRefmsgid = res10265.InfRefmsgid
  4865. }
  4866. if res.Infcode == 0 {
  4867. var insutypes []string
  4868. var insutype string
  4869. var is390 int = 0
  4870. var is310 int = 0
  4871. for _, item := range res.Output.Iinfo {
  4872. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  4873. insutypes = append(insutypes, item.Insutype)
  4874. }
  4875. }
  4876. if len(insutypes) == 1 {
  4877. insutype = insutypes[0]
  4878. } else {
  4879. for _, i := range insutypes {
  4880. if i == "390" {
  4881. is390 = 1
  4882. }
  4883. if i == "310" {
  4884. is310 = 1
  4885. }
  4886. }
  4887. }
  4888. if is390 == 1 {
  4889. insutype = "390"
  4890. }
  4891. if is310 == 1 {
  4892. insutype = "310"
  4893. }
  4894. if len(insutypes) == 0 {
  4895. insutype = "310"
  4896. }
  4897. patient, err := service.GetPatientByIDCard(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  4898. if err == gorm.ErrRecordNotFound {
  4899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  4900. return
  4901. } else if err != nil {
  4902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4903. return
  4904. } else {
  4905. if card_type == "1" {
  4906. bas := strings.Split(card_info, "|")
  4907. basNumber := bas[2]
  4908. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  4909. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  4910. infoStr := string(Iinfos)
  4911. idetinfoStr := string(Idetinfos)
  4912. psn := &models.HisPsn{
  4913. PsnNo: res.Output.Baseinfo.PsnNo,
  4914. Age: res.Output.Baseinfo.Age,
  4915. PatientId: patient.ID,
  4916. Certno: res.Output.Baseinfo.Certno,
  4917. Gend: res.Output.Baseinfo.Gend,
  4918. Naty: res.Output.Baseinfo.Naty,
  4919. PsnCertType: res.Output.Baseinfo.PsnCertType,
  4920. PsnName: res.Output.Baseinfo.PsnName,
  4921. Idetinfo: idetinfoStr,
  4922. Insuinfo: infoStr,
  4923. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4924. CardInfo: card_info,
  4925. VerifyNumber: busi_card_info,
  4926. }
  4927. service.CreateHisPsn(psn)
  4928. c.ServeSuccessJSON(map[string]interface{}{
  4929. "patient": patient,
  4930. "number": basNumber,
  4931. "info": res,
  4932. "insutype": insutype,
  4933. })
  4934. } else {
  4935. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  4936. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  4937. infoStr := string(Iinfos)
  4938. idetinfoStr := string(Idetinfos)
  4939. psn := &models.HisPsn{
  4940. PsnNo: res.Output.Baseinfo.PsnNo,
  4941. Age: res.Output.Baseinfo.Age,
  4942. PatientId: patient.ID,
  4943. Certno: res.Output.Baseinfo.Certno,
  4944. Gend: res.Output.Baseinfo.Gend,
  4945. Naty: res.Output.Baseinfo.Naty,
  4946. PsnCertType: res.Output.Baseinfo.PsnCertType,
  4947. PsnName: res.Output.Baseinfo.PsnName,
  4948. Idetinfo: idetinfoStr,
  4949. Insuinfo: infoStr,
  4950. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4951. CardInfo: card_info,
  4952. VerifyNumber: token,
  4953. }
  4954. service.CreateHisPsn(psn)
  4955. c.ServeSuccessJSON(map[string]interface{}{
  4956. "patient": patient,
  4957. "number": token,
  4958. "info": res,
  4959. "insutype": insutype,
  4960. })
  4961. }
  4962. }
  4963. } else {
  4964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  4965. return
  4966. }
  4967. } else { //读卡失败
  4968. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  4969. return
  4970. }
  4971. } else if miConfig.MdtrtareaAdmvs == "421182" {
  4972. var res ResultTwohb
  4973. api := miConfig.Url + "hbyb/1101?cert_no=" + "" +
  4974. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  4975. "&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"
  4976. resp, requestErr := http.Get(api)
  4977. if requestErr != nil {
  4978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4979. return
  4980. }
  4981. body, ioErr := ioutil.ReadAll(resp.Body)
  4982. if ioErr != nil {
  4983. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4985. return
  4986. }
  4987. var respJSON map[string]interface{}
  4988. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4989. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4991. return
  4992. }
  4993. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4994. result, _ := json.Marshal(respJSON)
  4995. fmt.Println("log")
  4996. fmt.Println(string(result))
  4997. if err := json.Unmarshal([]byte(result), &res); err != nil {
  4998. utils.ErrorLog("解析失败:%v", err)
  4999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5000. return
  5001. }
  5002. if res.Infcode == 0 {
  5003. patient, err := service.GetPatientByIDCard(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  5004. if err == gorm.ErrRecordNotFound {
  5005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  5006. return
  5007. } else if err != nil {
  5008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5009. return
  5010. } else {
  5011. var insuplc_admdvs_temp string
  5012. var insutypes []string
  5013. var insutype string
  5014. var is390 int = 0
  5015. var is310 int = 0
  5016. for _, item := range res.Output.Iinfo {
  5017. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  5018. insutypes = append(insutypes, item.Insutype)
  5019. }
  5020. }
  5021. if len(insutypes) == 1 {
  5022. insutype = insutypes[0]
  5023. } else {
  5024. for _, i := range insutypes {
  5025. if i == "390" {
  5026. is390 = 1
  5027. }
  5028. if i == "310" {
  5029. is310 = 1
  5030. }
  5031. }
  5032. }
  5033. if is390 == 1 {
  5034. insutype = "390"
  5035. }
  5036. if is310 == 1 {
  5037. insutype = "310"
  5038. }
  5039. if len(insutypes) == 0 {
  5040. insutype = "310"
  5041. }
  5042. for _, item := range insutypes {
  5043. if item == insutype {
  5044. insuplc_admdvs_temp = item
  5045. }
  5046. }
  5047. //insuplcAdmdvs := strconv.Itoa(insuplc_admdvs_temp)
  5048. card_info_two := insuplc_admdvs_temp + "|" + res.Output.Baseinfo.Certno + "|" + res.Output.Baseinfo.ExpContent.MdtrtCertNo
  5049. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  5050. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  5051. infoStr := string(Iinfos)
  5052. idetinfoStr := string(Idetinfos)
  5053. psn := &models.HisPsn{
  5054. PsnNo: res.Output.Baseinfo.PsnNo,
  5055. PatientId: patient.ID,
  5056. Certno: res.Output.Baseinfo.Certno,
  5057. Gend: res.Output.Baseinfo.Gend,
  5058. Naty: res.Output.Baseinfo.Naty,
  5059. PsnCertType: res.Output.Baseinfo.PsnCertType,
  5060. PsnName: res.Output.Baseinfo.PsnName,
  5061. Idetinfo: idetinfoStr,
  5062. Insuinfo: infoStr,
  5063. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5064. InsuplcAdmdvs: insuplc_admdvs_temp,
  5065. CardInfo:card_info_two,
  5066. }
  5067. service.CreateHisPsn(psn)
  5068. c.ServeSuccessJSON(map[string]interface{}{
  5069. "patient": patient,
  5070. "number": res.Output.Baseinfo.Certno,
  5071. })
  5072. }
  5073. } else {
  5074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  5075. return
  5076. }
  5077. } else if miConfig.MdtrtareaAdmvs == "360399" {
  5078. fmt.Println(initFlag)
  5079. fmt.Println("initFlag")
  5080. if initFlag == 0 {
  5081. c.TestGetJiangXiBasBaseInit()
  5082. }
  5083. basStr := c.GetBasBaseInfoxxx()
  5084. if len(basStr) == 0 {
  5085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  5086. return
  5087. }
  5088. fmt.Println(basStr)
  5089. bas := strings.Split(basStr, "|")
  5090. basNumber := bas[1]
  5091. fmt.Println(basNumber)
  5092. card_sn := bas[3]
  5093. fmt.Println(card_sn)
  5094. 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, "")
  5095. //result := service.Jxyb1101(basNumber, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, card_sn, certificates)
  5096. var dat map[string]interface{}
  5097. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5098. fmt.Println(dat)
  5099. } else {
  5100. fmt.Println(err)
  5101. }
  5102. userJSONBytes, _ := json.Marshal(dat)
  5103. var res ResultTwo
  5104. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5105. utils.ErrorLog("解析失败:%v", err)
  5106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5107. return
  5108. }
  5109. if res.Infcode == 0 {
  5110. patient, err := service.GetPatientByNumber(basNumber, c.GetAdminUserInfo().CurrentOrgId)
  5111. if err == gorm.ErrRecordNotFound {
  5112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  5113. return
  5114. } else if err != nil {
  5115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5116. return
  5117. } else {
  5118. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  5119. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  5120. infoStr := string(Iinfos)
  5121. idetinfoStr := string(Idetinfos)
  5122. psn := &models.HisPsn{
  5123. PsnNo: res.Output.Baseinfo.PsnNo,
  5124. Age: res.Output.Baseinfo.Age,
  5125. PatientId: patient.ID,
  5126. Certno: res.Output.Baseinfo.Certno,
  5127. Gend: res.Output.Baseinfo.Gend,
  5128. Naty: res.Output.Baseinfo.Naty,
  5129. PsnCertType: res.Output.Baseinfo.PsnCertType,
  5130. PsnName: res.Output.Baseinfo.PsnName,
  5131. Idetinfo: idetinfoStr,
  5132. Insuinfo: infoStr,
  5133. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5134. CardInfo: basStr,
  5135. VerifyNumber: "",
  5136. }
  5137. service.CreateHisPsn(psn)
  5138. var rf []*ResultFive
  5139. json.Unmarshal([]byte(infoStr), &rf)
  5140. var insutypes []*ResultFive
  5141. var insutype string
  5142. var is390 int = 0
  5143. var is310 int = 0
  5144. for _, item := range rf {
  5145. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  5146. insutypes = append(insutypes, item)
  5147. }
  5148. }
  5149. if len(insutypes) == 1 {
  5150. insutype = insutypes[0].Insutype
  5151. //insuplc_admdvs = insutypes[0].InsuplcAdmdvs
  5152. } else {
  5153. for _, i := range insutypes {
  5154. if i.Insutype == "390" {
  5155. is390 = 1
  5156. }
  5157. if i.Insutype == "310" {
  5158. is310 = 1
  5159. }
  5160. }
  5161. }
  5162. if is390 == 1 {
  5163. insutype = "390"
  5164. }
  5165. if is310 == 1 {
  5166. insutype = "310"
  5167. }
  5168. if len(insutypes) == 0 {
  5169. insutype = "310"
  5170. }
  5171. c.ServeSuccessJSON(map[string]interface{}{
  5172. "patient": patient,
  5173. "number": basNumber,
  5174. "info": res,
  5175. "insutype": insutype,
  5176. })
  5177. }
  5178. } else {
  5179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  5180. return
  5181. }
  5182. } else {
  5183. if initFlagTwo == 0 {
  5184. c.TestGetBasBaseInitTwo()
  5185. }
  5186. basStr := c.GetBasBaseInfoTwo()
  5187. if len(basStr) == 0 {
  5188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  5189. return
  5190. }
  5191. fmt.Println(basStr)
  5192. bas := strings.Split(basStr, "|")
  5193. id_card_no := bas[1]
  5194. result, _ := service.ZHGdyb1101B(id_card_no, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 1, "", 1, "")
  5195. //result := service.Gdyb1101B(basNumber, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, card_sn, certificates)
  5196. var dat map[string]interface{}
  5197. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5198. fmt.Println(dat)
  5199. } else {
  5200. fmt.Println(err)
  5201. }
  5202. userJSONBytes, _ := json.Marshal(dat)
  5203. var res ResultTwo
  5204. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5205. utils.ErrorLog("解析失败:%v", err)
  5206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5207. return
  5208. }
  5209. if res.Infcode == 0 {
  5210. patient, err := service.GetPatientByNumber(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  5211. if err == gorm.ErrRecordNotFound {
  5212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  5213. return
  5214. } else if err != nil {
  5215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5216. return
  5217. } else {
  5218. var insutypes []string
  5219. var insutype string
  5220. var is390 int = 0
  5221. var is310 int = 0
  5222. for _, item := range res.Output.Iinfo {
  5223. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  5224. insutypes = append(insutypes, item.Insutype)
  5225. }
  5226. }
  5227. if len(insutypes) == 1 {
  5228. insutype = insutypes[0]
  5229. } else {
  5230. for _, i := range insutypes {
  5231. if i == "390" {
  5232. is390 = 1
  5233. }
  5234. if i == "310" {
  5235. is310 = 1
  5236. }
  5237. }
  5238. }
  5239. if is390 == 1 {
  5240. insutype = "390"
  5241. }
  5242. if is310 == 1 {
  5243. insutype = "310"
  5244. }
  5245. if len(insutypes) == 0 {
  5246. insutype = "310"
  5247. }
  5248. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  5249. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  5250. infoStr := string(Iinfos)
  5251. idetinfoStr := string(Idetinfos)
  5252. psn := &models.HisPsn{
  5253. PsnNo: res.Output.Baseinfo.PsnNo,
  5254. Age: res.Output.Baseinfo.Age,
  5255. PatientId: patient.ID,
  5256. Certno: res.Output.Baseinfo.Certno,
  5257. Gend: res.Output.Baseinfo.Gend,
  5258. Naty: res.Output.Baseinfo.Naty,
  5259. PsnCertType: res.Output.Baseinfo.PsnCertType,
  5260. PsnName: res.Output.Baseinfo.PsnName,
  5261. Idetinfo: idetinfoStr,
  5262. Insuinfo: infoStr,
  5263. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5264. CardInfo: basStr,
  5265. VerifyNumber: "",
  5266. }
  5267. service.CreateHisPsn(psn)
  5268. c.ServeSuccessJSON(map[string]interface{}{
  5269. "patient": patient,
  5270. "number": id_card_no,
  5271. "info": res,
  5272. "insutype": insutype,
  5273. })
  5274. }
  5275. } else {
  5276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  5277. return
  5278. }
  5279. }
  5280. break
  5281. case 2:
  5282. if miConfig.MdtrtareaAdmvs == "421182" {
  5283. var res ResultTwohb
  5284. api := miConfig.Url + "hbyb/1101?cert_no=" + "" +
  5285. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  5286. "&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"
  5287. resp, requestErr := http.Get(api)
  5288. if requestErr != nil {
  5289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5290. return
  5291. }
  5292. body, ioErr := ioutil.ReadAll(resp.Body)
  5293. if ioErr != nil {
  5294. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  5295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5296. return
  5297. }
  5298. var respJSON map[string]interface{}
  5299. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  5300. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  5301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5302. return
  5303. }
  5304. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  5305. result, _ := json.Marshal(respJSON)
  5306. fmt.Println("log")
  5307. fmt.Println(string(result))
  5308. if err := json.Unmarshal([]byte(result), &res); err != nil {
  5309. utils.ErrorLog("解析失败:%v", err)
  5310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5311. return
  5312. }
  5313. if res.Infcode == 0 {
  5314. patient, err := service.GetPatientByIDCard(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  5315. if err == gorm.ErrRecordNotFound {
  5316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  5317. return
  5318. } else if err != nil {
  5319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5320. return
  5321. } else {
  5322. var insuplc_admdvs_temp string
  5323. var insutypes []string
  5324. var insutype string
  5325. var is390 int = 0
  5326. var is310 int = 0
  5327. for _, item := range res.Output.Iinfo {
  5328. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  5329. insutypes = append(insutypes, item.Insutype)
  5330. }
  5331. }
  5332. if len(insutypes) == 1 {
  5333. insutype = insutypes[0]
  5334. } else {
  5335. for _, i := range insutypes {
  5336. if i == "390" {
  5337. is390 = 1
  5338. }
  5339. if i == "310" {
  5340. is310 = 1
  5341. }
  5342. }
  5343. }
  5344. if is390 == 1 {
  5345. insutype = "390"
  5346. }
  5347. if is310 == 1 {
  5348. insutype = "310"
  5349. }
  5350. if len(insutypes) == 0 {
  5351. insutype = "310"
  5352. }
  5353. for _, item := range insutypes {
  5354. if item == insutype {
  5355. insuplc_admdvs_temp = item
  5356. }
  5357. }
  5358. //insuplcAdmdvs := strconv.Itoa(insuplc_admdvs_temp)
  5359. card_info_two := insuplc_admdvs_temp + "|" + res.Output.Baseinfo.Certno + "|" + res.Output.Baseinfo.ExpContent.MdtrtCertNo
  5360. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  5361. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  5362. infoStr := string(Iinfos)
  5363. idetinfoStr := string(Idetinfos)
  5364. psn := &models.HisPsn{
  5365. PsnNo: res.Output.Baseinfo.PsnNo,
  5366. PatientId: patient.ID,
  5367. Certno: res.Output.Baseinfo.Certno,
  5368. Gend: res.Output.Baseinfo.Gend,
  5369. Naty: res.Output.Baseinfo.Naty,
  5370. PsnCertType: res.Output.Baseinfo.PsnCertType,
  5371. PsnName: res.Output.Baseinfo.PsnName,
  5372. Idetinfo: idetinfoStr,
  5373. Insuinfo: infoStr,
  5374. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5375. InsuplcAdmdvs: insuplc_admdvs_temp,
  5376. CardInfo:card_info_two,
  5377. }
  5378. service.CreateHisPsn(psn)
  5379. c.ServeSuccessJSON(map[string]interface{}{
  5380. "patient": patient,
  5381. "number": res.Output.Baseinfo.Certno,
  5382. })
  5383. }
  5384. } else {
  5385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  5386. return
  5387. }
  5388. }
  5389. case 4: //电子凭证
  5390. if miConfig.MdtrtareaAdmvs == "150499" {
  5391. var api string
  5392. api = "http://172.16.13.254:9532/" + "nmyb/readcard?" + "fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName +
  5393. "&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
  5394. resp, requestErr := http.Get(api)
  5395. if requestErr != nil {
  5396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5397. return
  5398. }
  5399. body, ioErr := ioutil.ReadAll(resp.Body)
  5400. if ioErr != nil {
  5401. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  5402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5403. return
  5404. }
  5405. var respJSON map[string]interface{}
  5406. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  5407. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  5408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5409. return
  5410. }
  5411. var status string
  5412. status = respJSON["data"].(map[string]interface{})["status"].(string)
  5413. //card_type := respJSON["data"].(map[string]interface{})["type"].(string)
  5414. var token string
  5415. var res ResultTwo //1101结果
  5416. var res10265 ResultTwo10265 //1101结果
  5417. if status == "0" { //读卡成功
  5418. token = respJSON["data"].(map[string]interface{})["token"].(string)
  5419. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  5420. result, _ := json.Marshal(respJSON)
  5421. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  5422. utils.ErrorLog("解析失败:%v", err)
  5423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5424. return
  5425. }
  5426. res.ErrMsg = res10265.ErrMsg
  5427. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  5428. res.Infcode = infocode
  5429. res.Output = res10265.Output
  5430. res.InfRefmsgid = res10265.InfRefmsgid
  5431. if res.Infcode == 0 {
  5432. patient, err := service.GetPatientByNumber(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  5433. if err == gorm.ErrRecordNotFound {
  5434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  5435. return
  5436. } else if err != nil {
  5437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5438. return
  5439. } else {
  5440. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  5441. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  5442. infoStr := string(Iinfos)
  5443. idetinfoStr := string(Idetinfos)
  5444. psn := &models.HisPsn{
  5445. PsnNo: res.Output.Baseinfo.PsnNo,
  5446. Age: res.Output.Baseinfo.Age,
  5447. PatientId: patient.ID,
  5448. Certno: res.Output.Baseinfo.Certno,
  5449. Gend: res.Output.Baseinfo.Gend,
  5450. Naty: res.Output.Baseinfo.Naty,
  5451. PsnCertType: res.Output.Baseinfo.PsnCertType,
  5452. PsnName: res.Output.Baseinfo.PsnName,
  5453. Idetinfo: idetinfoStr,
  5454. Insuinfo: infoStr,
  5455. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5456. CardInfo: "",
  5457. VerifyNumber: token,
  5458. }
  5459. service.CreateHisPsn(psn)
  5460. var insutypes []string
  5461. var insutype string
  5462. var is390 int = 0
  5463. var is310 int = 0
  5464. for _, item := range res.Output.Iinfo {
  5465. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  5466. insutypes = append(insutypes, item.Insutype)
  5467. }
  5468. }
  5469. if len(insutypes) == 1 {
  5470. insutype = insutypes[0]
  5471. } else {
  5472. for _, i := range insutypes {
  5473. if i == "390" {
  5474. is390 = 1
  5475. }
  5476. if i == "310" {
  5477. is310 = 1
  5478. }
  5479. }
  5480. }
  5481. if is390 == 1 {
  5482. insutype = "390"
  5483. }
  5484. if is310 == 1 {
  5485. insutype = "310"
  5486. }
  5487. if len(insutypes) == 0 {
  5488. insutype = "390"
  5489. }
  5490. c.ServeSuccessJSON(map[string]interface{}{
  5491. "failed_code": 0,
  5492. "info": res,
  5493. "insutype": insutype,
  5494. "patient": patient,
  5495. })
  5496. }
  5497. } else {
  5498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  5499. return
  5500. }
  5501. }
  5502. } else if miConfig.MdtrtareaAdmvs == "421182" {
  5503. var res ResultTwohb
  5504. api := miConfig.Url + "hbyb/1101?cert_no=" + "" +
  5505. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  5506. "&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"
  5507. resp, requestErr := http.Get(api)
  5508. if requestErr != nil {
  5509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5510. return
  5511. }
  5512. body, ioErr := ioutil.ReadAll(resp.Body)
  5513. if ioErr != nil {
  5514. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  5515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5516. return
  5517. }
  5518. var respJSON map[string]interface{}
  5519. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  5520. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  5521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5522. return
  5523. }
  5524. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  5525. result, _ := json.Marshal(respJSON)
  5526. fmt.Println("log")
  5527. fmt.Println(string(result))
  5528. if err := json.Unmarshal([]byte(result), &res); err != nil {
  5529. utils.ErrorLog("解析失败:%v", err)
  5530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5531. return
  5532. }
  5533. if res.Infcode == 0 {
  5534. patient, err := service.GetPatientByIDCard(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  5535. if err == gorm.ErrRecordNotFound {
  5536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  5537. return
  5538. } else if err != nil {
  5539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5540. return
  5541. } else {
  5542. var insuplc_admdvs_temp string
  5543. var insutypes []string
  5544. var insutype string
  5545. var is390 int = 0
  5546. var is310 int = 0
  5547. for _, item := range res.Output.Iinfo {
  5548. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  5549. insutypes = append(insutypes, item.Insutype)
  5550. }
  5551. }
  5552. if len(insutypes) == 1 {
  5553. insutype = insutypes[0]
  5554. } else {
  5555. for _, i := range insutypes {
  5556. if i == "390" {
  5557. is390 = 1
  5558. }
  5559. if i == "310" {
  5560. is310 = 1
  5561. }
  5562. }
  5563. }
  5564. if is390 == 1 {
  5565. insutype = "390"
  5566. }
  5567. if is310 == 1 {
  5568. insutype = "310"
  5569. }
  5570. if len(insutypes) == 0 {
  5571. insutype = "310"
  5572. }
  5573. for _, item := range insutypes {
  5574. if item == insutype {
  5575. insuplc_admdvs_temp = item
  5576. }
  5577. }
  5578. //insuplcAdmdvs := strconv.Itoa(insuplc_admdvs_temp)
  5579. card_info_two := insuplc_admdvs_temp + "|" + res.Output.Baseinfo.Certno + "|" + res.Output.Baseinfo.ExpContent.MdtrtCertNo
  5580. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  5581. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  5582. infoStr := string(Iinfos)
  5583. idetinfoStr := string(Idetinfos)
  5584. psn := &models.HisPsn{
  5585. PsnNo: res.Output.Baseinfo.PsnNo,
  5586. PatientId: patient.ID,
  5587. Certno: res.Output.Baseinfo.Certno,
  5588. Gend: res.Output.Baseinfo.Gend,
  5589. Naty: res.Output.Baseinfo.Naty,
  5590. PsnCertType: res.Output.Baseinfo.PsnCertType,
  5591. PsnName: res.Output.Baseinfo.PsnName,
  5592. Idetinfo: idetinfoStr,
  5593. Insuinfo: infoStr,
  5594. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5595. InsuplcAdmdvs: insuplc_admdvs_temp,
  5596. CardInfo:card_info_two,
  5597. }
  5598. service.CreateHisPsn(psn)
  5599. c.ServeSuccessJSON(map[string]interface{}{
  5600. "patient": patient,
  5601. "number": res.Output.Baseinfo.Certno,
  5602. })
  5603. }
  5604. } else {
  5605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  5606. return
  5607. }
  5608. } else if miConfig.MdtrtareaAdmvs =="360399"{
  5609. //if initFlag == 0 {
  5610. //c.TestGetJiangXiBasBaseInit()
  5611. //}
  5612. //if initEleFlag == 0 {
  5613. // GetJxEleBaseInitInfo(c.GetAdminUserInfo().CurrentOrgId)
  5614. //}
  5615. //_, result2 := GetjxELekeyInfo(miConfig.Code, "1", roles.UserName)
  5616. _, result := GetjxELeInfoaaa(miConfig.Code, "1", roles.UserName)
  5617. //json_result := GetJxEleBaseInfo(c.GetAdminUserInfo().CurrentOrgId)
  5618. type ELeData struct {
  5619. Data struct {
  5620. IdNo string `json:"idNo"`
  5621. IdType string `json:"idType"`
  5622. UserName string `json:"userName"`
  5623. EcToken string `json:"ecToken"`
  5624. InsuOrg string `json:"insuOrg"`
  5625. Gender string `json:"gender"`
  5626. Birthday string `json:"birthday"`
  5627. Nationality string `json:"nationality"`
  5628. Email string `json:"email"`
  5629. Extra string `json:"extra"`
  5630. } `json:"data"`
  5631. Code int `json:"code"`
  5632. Message string `json:"message"`
  5633. }
  5634. var ele ELeData
  5635. err := json.Unmarshal([]byte(result), &ele)
  5636. if err != nil {
  5637. utils.ErrorLog("解析失败:%v", err)
  5638. }
  5639. token := ele.Data.EcToken
  5640. token = Remove0000(token)
  5641. 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)
  5642. saveLog(result2, requestLog2, "1101", "获取人员信息")
  5643. var res ResultTwo
  5644. if err := json.Unmarshal([]byte(result2), &res); err != nil {
  5645. utils.ErrorLog("解析失败:%v", err)
  5646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5647. return
  5648. }
  5649. if res.Infcode == 0 {
  5650. patient, err := service.GetPatientByNumber(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  5651. if err == gorm.ErrRecordNotFound {
  5652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  5653. return
  5654. } else if err != nil {
  5655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5656. return
  5657. } else {
  5658. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  5659. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  5660. infoStr := string(Iinfos)
  5661. idetinfoStr := string(Idetinfos)
  5662. psn := &models.HisPsn{
  5663. PsnNo: res.Output.Baseinfo.PsnNo,
  5664. Age: res.Output.Baseinfo.Age,
  5665. PatientId: patient.ID,
  5666. Certno: res.Output.Baseinfo.Certno,
  5667. Gend: res.Output.Baseinfo.Gend,
  5668. Naty: res.Output.Baseinfo.Naty,
  5669. PsnCertType: res.Output.Baseinfo.PsnCertType,
  5670. PsnName: res.Output.Baseinfo.PsnName,
  5671. Idetinfo: idetinfoStr,
  5672. Insuinfo: infoStr,
  5673. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5674. CardInfo: "",
  5675. VerifyNumber: token,
  5676. }
  5677. service.CreateHisPsn(psn)
  5678. var rf []*ResultFive
  5679. json.Unmarshal([]byte(infoStr), &rf)
  5680. var insutypes []*ResultFive
  5681. var insutype string
  5682. var is390 int = 0
  5683. var is310 int = 0
  5684. for _, item := range rf {
  5685. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  5686. insutypes = append(insutypes, item)
  5687. }
  5688. }
  5689. if len(insutypes) == 1 {
  5690. insutype = insutypes[0].Insutype
  5691. //insuplc_admdvs = insutypes[0].InsuplcAdmdvs
  5692. } else {
  5693. for _, i := range insutypes {
  5694. if i.Insutype == "390" {
  5695. is390 = 1
  5696. }
  5697. if i.Insutype == "310" {
  5698. is310 = 1
  5699. }
  5700. }
  5701. }
  5702. if is390 == 1 {
  5703. insutype = "390"
  5704. }
  5705. if is310 == 1 {
  5706. insutype = "310"
  5707. }
  5708. if len(insutypes) == 0 {
  5709. insutype = "310"
  5710. }
  5711. c.ServeSuccessJSON(map[string]interface{}{
  5712. "patient": patient,
  5713. "number": token,
  5714. "info": res,
  5715. "insutype": insutype,
  5716. })
  5717. }
  5718. } else {
  5719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  5720. return
  5721. }
  5722. }else {
  5723. if initFlagTwo == 0 {
  5724. c.TestGetBasBaseInitTwo()
  5725. }
  5726. token := c.GetEleBaseInfoTwo()
  5727. token = Remove0000(token)
  5728. result2, requestLog2 := service.Gdyb1101ForEleCert(miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, token, "", "")
  5729. saveLog(result2, requestLog2, "1101", "获取人员信息")
  5730. //
  5731. var res ResultTwo
  5732. if err := json.Unmarshal([]byte(result2), &res); err != nil {
  5733. utils.ErrorLog("解析失败:%v", err)
  5734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5735. return
  5736. }
  5737. if res.Infcode == 0 {
  5738. patient, err := service.GetPatientByNumber(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  5739. if err == gorm.ErrRecordNotFound {
  5740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  5741. return
  5742. } else if err != nil {
  5743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5744. return
  5745. } else {
  5746. var insutypes []string
  5747. var insutype string
  5748. var is390 int = 0
  5749. var is310 int = 0
  5750. for _, item := range res.Output.Iinfo {
  5751. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  5752. insutypes = append(insutypes, item.Insutype)
  5753. }
  5754. }
  5755. if len(insutypes) == 1 {
  5756. insutype = insutypes[0]
  5757. } else {
  5758. for _, i := range insutypes {
  5759. if i == "390" {
  5760. is390 = 1
  5761. }
  5762. if i == "310" {
  5763. is310 = 1
  5764. }
  5765. }
  5766. }
  5767. if is390 == 1 {
  5768. insutype = "390"
  5769. }
  5770. if is310 == 1 {
  5771. insutype = "310"
  5772. }
  5773. if len(insutypes) == 0 {
  5774. insutype = "310"
  5775. }
  5776. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  5777. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  5778. infoStr := string(Iinfos)
  5779. idetinfoStr := string(Idetinfos)
  5780. psn := &models.HisPsn{
  5781. PsnNo: res.Output.Baseinfo.PsnNo,
  5782. Age: res.Output.Baseinfo.Age,
  5783. PatientId: patient.ID,
  5784. Certno: res.Output.Baseinfo.Certno,
  5785. Gend: res.Output.Baseinfo.Gend,
  5786. Naty: res.Output.Baseinfo.Naty,
  5787. PsnCertType: res.Output.Baseinfo.PsnCertType,
  5788. PsnName: res.Output.Baseinfo.PsnName,
  5789. Idetinfo: idetinfoStr,
  5790. Insuinfo: infoStr,
  5791. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5792. CardInfo: "",
  5793. VerifyNumber: token,
  5794. }
  5795. service.CreateHisPsn(psn)
  5796. c.ServeSuccessJSON(map[string]interface{}{
  5797. "patient": patient,
  5798. "number": token,
  5799. "info": res,
  5800. "insutype": insutype,
  5801. })
  5802. }
  5803. } else {
  5804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  5805. return
  5806. }
  5807. }
  5808. break
  5809. }
  5810. }
  5811. func GetjxELekeyInfo(code string, operator_id string, operator_name string) (string, string) {
  5812. // WebSocket服务器地址
  5813. serverURL := "ws://127.0.0.1:8899"
  5814. // 解析WebSocket服务器地址
  5815. u, err := url.Parse(serverURL)
  5816. if err != nil {
  5817. }
  5818. // 建立WebSocket连接
  5819. conn, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
  5820. if err != nil {
  5821. }
  5822. defer conn.Close()
  5823. input2 := make(map[string]interface{})
  5824. input := make(map[string]interface{})
  5825. inputData := make(map[string]interface{})
  5826. inputData["orgId"] = code
  5827. inputData["businessType"] = "01101"
  5828. inputData["operatorId"] = operator_id
  5829. inputData["operatorName"] = operator_name
  5830. inputData["officeId"] = "001"
  5831. inputData["officeName"] = "血透室"
  5832. inputData["deviceType"] = ""
  5833. input["data"] = inputData
  5834. input["orgId"] = code
  5835. input["transType"] = "ec.query"
  5836. //if md == ""
  5837. input2["url"] = "http://10.77.211.236/1.0.0/getEncDynamicKey"
  5838. input2["indata"] = input
  5839. fmt.Println(input2)
  5840. bytesData, _ := json.Marshal(input2)
  5841. err = conn.WriteMessage(websocket.TextMessage, bytesData)
  5842. if err != nil {
  5843. fmt.Println(err)
  5844. }
  5845. // 接收消息
  5846. _, receivedMessage, err := conn.ReadMessage()
  5847. if err != nil {
  5848. fmt.Println(err)
  5849. }
  5850. return "", string(receivedMessage)
  5851. }
  5852. func GetjxELeInfoaaa(code string, operator_id string, operator_name string) (string, string) {
  5853. // WebSocket服务器地址
  5854. serverURL := "ws://127.0.0.1:8899"
  5855. // 解析WebSocket服务器地址
  5856. u, err := url.Parse(serverURL)
  5857. if err != nil {
  5858. }
  5859. // 建立WebSocket连接
  5860. conn, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
  5861. if err != nil {
  5862. }
  5863. defer conn.Close()
  5864. input2 := make(map[string]interface{})
  5865. input := make(map[string]interface{})
  5866. inputData := make(map[string]interface{})
  5867. inputData["orgId"] = code
  5868. inputData["businessType"] = "01103"
  5869. inputData["operatorId"] = operator_id
  5870. inputData["operatorName"] = operator_name
  5871. inputData["officeId"] = "001"
  5872. inputData["officeName"] = "血透室"
  5873. inputData["deviceType"] = ""
  5874. input["data"] = inputData
  5875. input["orgId"] = code
  5876. input["transType"] = "ec.query"
  5877. //if md ==
  5878. input2["url"] = "http://10.77.211.236/1.0.0/localQrCodeQuery"
  5879. input2["indata"] = input
  5880. fmt.Println(input2)
  5881. bytesData, _ := json.Marshal(input2)
  5882. err = conn.WriteMessage(websocket.TextMessage, bytesData)
  5883. if err != nil {
  5884. fmt.Println(err)
  5885. }
  5886. // 接收消息
  5887. _, receivedMessage, err := conn.ReadMessage()
  5888. if err != nil {
  5889. fmt.Println(err)
  5890. }
  5891. return "", string(receivedMessage)
  5892. }
  5893. func (c *ZHHisApiController) GetEleBaseInfoTwo() string {
  5894. DllDef := syscall.MustLoadDLL("SSCard.dll")
  5895. readCard := DllDef.MustFindProc("GetQRBase")
  5896. fmt.Println(readCard)
  5897. if readCard == nil {
  5898. fmt.Println("readcard is nil")
  5899. readCard = DllDef.MustFindProc("GetQRBase")
  5900. }
  5901. str := make([]byte, 1024)
  5902. str1 := make([]byte, 1024)
  5903. ret2, _, _ := readCard.Call(uintptr(180), (uintptr)(unsafe.Pointer(&str[0])), uintptr(1024), (uintptr)(unsafe.Pointer(&str1[0])), uintptr(1024))
  5904. fmt.Println(ret2)
  5905. fmt.Println(string(str1))
  5906. fmt.Println(string(str))
  5907. fmt.Println(":", ConvertToString(string(str1), "gbk", "utf-8"))
  5908. fmt.Println(":", ConvertToString(string(str), "gbk", "utf-8"))
  5909. if ret2 != 0 {
  5910. return ""
  5911. }
  5912. return string(str)
  5913. }
  5914. func (c *ZHHisApiController) TestGetBasBaseInitTwo() {
  5915. DllDef := syscall.MustLoadDLL("SSCard.dll")
  5916. Iinit := DllDef.MustFindProc("Init")
  5917. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  5918. ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_api/prd/api/card/initDll"), StrPtr(miConfig.MdtrtareaAdmvs))
  5919. if ret != 0 {
  5920. fmt.Println("SSCard的报错原因:", err)
  5921. fmt.Println("SSCard的运算结果为:", ret)
  5922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  5923. return
  5924. }
  5925. result := int(ret)
  5926. fmt.Println("SSCard的运算结果为1:", result)
  5927. initFlagTwo = 1
  5928. return
  5929. }
  5930. func (c *ZHHisApiController) GetBasBaseInfoTwo() string {
  5931. DllDef := syscall.MustLoadDLL("SSCard.dll")
  5932. readCard := DllDef.MustFindProc("ReadCardBas")
  5933. if readCard == nil {
  5934. fmt.Println("readcard is nil")
  5935. readCard = DllDef.MustFindProc("ReadCardBas")
  5936. }
  5937. str := make([]byte, 1024)
  5938. str1 := make([]byte, 1024)
  5939. ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), uintptr(1024), (uintptr)(unsafe.Pointer(&str1[0])), uintptr(1024))
  5940. fmt.Println(string(str1))
  5941. fmt.Println(string(str))
  5942. fmt.Println(":", ConvertToString(string(str1), "gbk", "utf-8"))
  5943. fmt.Println(":", ConvertToString(string(str), "gbk", "utf-8"))
  5944. if ret2 != 0 {
  5945. return ""
  5946. }
  5947. return string(str)
  5948. }
  5949. var initFlag int64 = 0
  5950. func (c *ZHHisApiController) TestGetBasBaseInit() {
  5951. DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
  5952. Iinit := DllDef.MustFindProc("Init")
  5953. //miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  5954. str := make([]byte, 2048)
  5955. inputData := make(map[string]interface{})
  5956. inputData["IP"] = "10.144.211.75"
  5957. inputData["PORT"] = 7021
  5958. inputData["TIMEOUT"] = 180
  5959. inputData["LOG_PATH"] = "C:\\log\\"
  5960. //inputData["SFZ_DRIVER_TYPE"] = 0
  5961. inputData["URL"] = "/call1"
  5962. bytesData, _ := json.Marshal(inputData)
  5963. fmt.Println(inputData)
  5964. fmt.Println(bytesData)
  5965. ret, _, err := Iinit.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&str[0])))
  5966. if ret != 0 {
  5967. fmt.Println("SSCard的报错原因:", err)
  5968. fmt.Println("SSCard的运算结果为:", ret)
  5969. fmt.Println("SSCard的返回结果为:", string(str))
  5970. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  5971. return
  5972. }
  5973. fmt.Println("SSCard的返回结果为:", string(str))
  5974. result := int(ret)
  5975. fmt.Println("SSCard的运算结果为1:", result)
  5976. //initFlag = 1
  5977. return
  5978. }
  5979. func (c *ZHHisApiController) GetSFZBaseInfo() string {
  5980. DllDef := syscall.MustLoadDLL("SSCard.dll")
  5981. readCard := DllDef.MustFindProc("ReadSFZ")
  5982. if readCard == nil {
  5983. fmt.Println("readcard is nil")
  5984. readCard = DllDef.MustFindProc("ReadSFZ")
  5985. }
  5986. str := make([]byte, 256)
  5987. str1 := make([]byte, 256)
  5988. r, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  5989. fmt.Println(r)
  5990. return string(str)
  5991. }
  5992. func (c *ZHHisApiController) GetBasBaseInfo(fixmedins_code string, mdtrtarea_admvs string, opter_name string, opter_id string, fixmedins_name string) string {
  5993. DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
  5994. readCard := DllDef.MustFindProc("ReadCardBas")
  5995. fmt.Println(readCard)
  5996. fmt.Println("!!!!!")
  5997. month := time.Unix(1557042972, 0).Format("1")
  5998. year := time.Now().Format("2006")
  5999. month = time.Now().Format("01")
  6000. day := time.Now().Format("02")
  6001. hour := time.Now().Format("15")
  6002. min := time.Now().Format("04")
  6003. sec := time.Now().Format("05")
  6004. msec := time.Now().Format("000")
  6005. timestamp := time.Now().Unix()
  6006. tempTime := time.Unix(timestamp, 0)
  6007. //timeFormat := tempTime.Format("20060102150405")
  6008. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  6009. //randNum := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000)
  6010. inputData := make(map[string]interface{})
  6011. inputData["infno"] = "1199"
  6012. //inputData["msgid"] = "7021"
  6013. inputData["msgid"] = fixmedins_code + year + month + day + hour + min + sec + msec + "0" // 发送方报文 ID
  6014. inputData["mdtrtarea_admvs"] = mdtrtarea_admvs // 发送方报文 ID
  6015. inputData["recer_sys_code"] = "01"
  6016. inputData["infver"] = "V1.0"
  6017. inputData["opter_type"] = "1"
  6018. inputData["opter"] = opter_id
  6019. inputData["opter_name"] = opter_name
  6020. inputData["inf_time"] = timeFormatOne
  6021. inputData["fixmedins_code"] = fixmedins_code
  6022. inputData["fixmedins_name"] = fixmedins_name
  6023. inputData["dev_no"] = ""
  6024. inputData["dev_safe_info"] = ""
  6025. inputData["cainfo"] = ""
  6026. inputData["signtype"] = ""
  6027. inputData["sign_no"] = ""
  6028. bytesData, _ := json.Marshal(inputData)
  6029. fmt.Println(string(bytesData))
  6030. pBusiCardInfo := make([]byte, 8192)
  6031. ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
  6032. fmt.Println(ret2)
  6033. fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
  6034. fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
  6035. if ret2 != 0 {
  6036. return ""
  6037. }
  6038. return DeleteExtraSpace(string(pBusiCardInfo))
  6039. }
  6040. func DeleteExtraSpace(s string) string {
  6041. //删除字符串中的多余空格,有多个空格时,仅保留一个空格
  6042. s1 := strings.Replace(s, " ", " ", -1) //替换tab为空格
  6043. regstr := "\\s{2,}" //两个及两个以上空格的正则表达式
  6044. reg, _ := regexp.Compile(regstr) //编译正则表达式
  6045. s2 := make([]byte, len(s1)) //定义字符数组切片
  6046. copy(s2, s1) //将字符串复制到切片
  6047. spc_index := reg.FindStringIndex(string(s2)) //在字符串中搜索
  6048. for len(spc_index) > 0 { //找到适配项
  6049. s2 = append(s2[:spc_index[0]+1], s2[spc_index[1]:]...) //删除多余空格
  6050. spc_index = reg.FindStringIndex(string(s2)) //继续在字符串中搜索
  6051. }
  6052. return string(s2)
  6053. }
  6054. func (c *ZHHisApiController) GetELeInfo(code string, operator_id string, operator_name string) (string, string) {
  6055. DllDef := syscall.MustLoadDLL("NationECCode.dll")
  6056. readCard := DllDef.MustFindProc("NationEcTrans")
  6057. fmt.Println(readCard)
  6058. fmt.Println("!!!!!")
  6059. pBusiCardInfo := make([]byte, 8192)
  6060. input := make(map[string]interface{})
  6061. inputData := make(map[string]interface{})
  6062. inputData["orgId"] = code
  6063. inputData["businessType"] = "01101"
  6064. inputData["operatorId"] = operator_id
  6065. inputData["operatorName"] = operator_name
  6066. inputData["officeId"] = "001"
  6067. inputData["officeName"] = "血透室"
  6068. inputData["deviceType"] = ""
  6069. input["data"] = inputData
  6070. input["orgId"] = code
  6071. input["transType"] = "ec.query"
  6072. bytesData, _ := json.Marshal(input)
  6073. gdyb_url := beego.AppConfig.String("gdyb_url")
  6074. url := gdyb_url + "/localcfc/api/hsecfc/localQrCodeQuery"
  6075. ret2, _, _ := readCard.Call(StrPtr(url), StrPtr(string(bytesData)), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
  6076. fmt.Println(ret2)
  6077. fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
  6078. fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
  6079. if ret2 != 0 {
  6080. return "", ""
  6081. }
  6082. return DeleteExtraSpace(""), DeleteExtraSpace(string(pBusiCardInfo))
  6083. }
  6084. func StrPtr(s string) uintptr {
  6085. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  6086. }
  6087. func Remove0000(s string) string {
  6088. str := make([]rune, 0, len(s))
  6089. for _, v := range []rune(s) {
  6090. if v == 0 {
  6091. continue
  6092. }
  6093. str = append(str, v)
  6094. }
  6095. return string(str)
  6096. }
  6097. func IntPtr(n int) uintptr {
  6098. return uintptr(n)
  6099. }
  6100. func RemoveRepeatedPurviewElement2(arr []string) (newArr []string) {
  6101. newArr = make([]string, 0)
  6102. for i := 0; i < len(arr); i++ {
  6103. repeat := false
  6104. for j := i + 1; j < len(arr); j++ {
  6105. if arr[i] == arr[j] {
  6106. repeat = true
  6107. break
  6108. }
  6109. }
  6110. if !repeat {
  6111. newArr = append(newArr, arr[i])
  6112. }
  6113. }
  6114. return
  6115. }
  6116. type Result3101 struct {
  6117. Infcode int64 `json:"infcode"`
  6118. InfRefmsgid string `json:"inf_refmsgid"`
  6119. RefmsgTime string `json:"refmsg_time"`
  6120. RespondTime string `json:"respond_time"`
  6121. Enctype string `json:"enctype"`
  6122. Signtype string `json:"signtype"`
  6123. ErrMsg string `json:"err_msg"`
  6124. Output struct {
  6125. Result []struct {
  6126. JudgeResultDetailDtos []struct {
  6127. VolaItemType string `json:"vola_item_type"`
  6128. MdtrtID string `json:"mdtrt_id"`
  6129. JrdID string `json:"jrd_id"`
  6130. PatnID string `json:"patn_id"`
  6131. RxID string `json:"rx_id"`
  6132. VolaAmt interface{} `json:"vola_amt"`
  6133. } `json:"judge_result_detail_dtos"`
  6134. RuleID string `json:"rule_id"`
  6135. VolaEvid string `json:"vola_evid"`
  6136. MdtrtID string `json:"mdtrt_id"`
  6137. RuleName string `json:"rule_name"`
  6138. VolaAmtStas string `json:"vola_amt_stas"`
  6139. JrID string `json:"jr_id"`
  6140. PatnID string `json:"patn_id"`
  6141. SevDeg string `json:"sev_deg"`
  6142. VolaAmt float64 `json:"vola_amt"`
  6143. VolaBhvrType string `json:"vola_bhvr_type"`
  6144. VolaCont string `json:"vola_cont"`
  6145. } `json:"result"`
  6146. } `json:"output"`
  6147. }
  6148. 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) {
  6149. var res Result3101
  6150. adminUser := c.GetAdminUserInfo()
  6151. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  6152. //his, _ := service.GetNewHisPatientInfoFour(c.GetAdminUserInfo().CurrentOrgId, his_patient_id)
  6153. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  6154. //record_time := c.GetString("record_time")
  6155. //trig_scen := c.GetString("trig_scen")
  6156. timeLayout := "2006-01-02"
  6157. loc, _ := time.LoadLocation("Local")
  6158. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6159. if err != nil {
  6160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6161. return res
  6162. }
  6163. recordDateTime := theTime.Unix()
  6164. p, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  6165. var patientPrescription models.HisPrescriptionInfo
  6166. //patientPrescription, _ = service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  6167. //if patientPrescription.ID == 0 {
  6168. patientPrescription, _ = service.FindLastPatientPrescriptionInfoTwo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  6169. //}
  6170. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  6171. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  6172. //
  6173. diagnosis_ids := strings.Split(patientPrescription.Diagnosis, ",")
  6174. //prescriptions, _ := service.GetNewHisPrescriptionTen(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  6175. var pp models.PublicParams
  6176. pp.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
  6177. pp.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
  6178. pp.FixmedinsName = miConfig.OrgName
  6179. pp.FixmedinsCode = miConfig.Code
  6180. pp.RequestUrl = miConfig.Url
  6181. pp.Cainfo = miConfig.Cainfo
  6182. pp.SecretKey = miConfig.SecretKey
  6183. pp.AccessKey = miConfig.AccessKey
  6184. pp.OpterName = roles.UserName
  6185. var config []*models.HisXtDiagnoseConfig
  6186. for _, item := range diagnosis_ids {
  6187. id, _ := strconv.ParseInt(item, 10, 64)
  6188. if id > 0 {
  6189. diagnosisConfig, _ := service.FindDiagnoseById(id)
  6190. config = append(config, &diagnosisConfig)
  6191. }
  6192. }
  6193. var pd models.PatientDtos
  6194. pd.PatnID = his.PsnNo
  6195. pd.PatnName = p.Name
  6196. pd.Gend = ress.Output.Baseinfo.Gend
  6197. pd.Poolarea = miConfig.MdtrtareaAdmvs
  6198. pd.CurrMdtrtID = strconv.FormatInt(patientPrescription.ID, 10)
  6199. var fed models.FsiEncounterDtos
  6200. fed.MdtrtID = p.IdCardNo
  6201. fed.MedinsID = miConfig.Code
  6202. fed.MedinsName = miConfig.OrgName
  6203. fed.MedinsAdmdvs = miConfig.MdtrtareaAdmvs
  6204. fed.MedMdtrtType = "1"
  6205. fed.MedinsType = "1"
  6206. fed.MedinsLv = "11"
  6207. tm := time.Unix(record_date, 0)
  6208. s_tm := tm.Format("2006-01-02 15:04:05")
  6209. fed.AdmDate = s_tm
  6210. fed.DscgDate = s_tm
  6211. fed.DscgMainDiseCodg = config[0].CountryCode
  6212. fed.DscgMainDiseName = config[0].CountryContentName
  6213. //诊断信息
  6214. var fdds []*models.FsiDiagnoseDtos
  6215. for index, item := range config {
  6216. if index == 0 {
  6217. var fdd models.FsiDiagnoseDtos
  6218. fdd.DiseID = strconv.FormatInt(item.ID, 10)
  6219. fdd.InoutDiseType = "1"
  6220. fdd.MaindiseFlag = "1"
  6221. fdd.DiseDate = s_tm
  6222. fdd.DiasSrtNo = "1"
  6223. fdd.DiseName = item.CountryContentName
  6224. fdd.DiseCodg = item.CountryCode
  6225. fdds = append(fdds, &fdd)
  6226. } else {
  6227. var fdd models.FsiDiagnoseDtos
  6228. fdd.DiseID = strconv.FormatInt(item.ID, 10)
  6229. fdd.InoutDiseType = "1"
  6230. fdd.MaindiseFlag = "1"
  6231. fdd.DiseDate = s_tm
  6232. fdd.DiasSrtNo = strconv.FormatInt(int64(index), 10)
  6233. fdd.DiseName = item.CountryContentName
  6234. fdd.DiseCodg = item.CountryCode
  6235. fdds = append(fdds, &fdd)
  6236. }
  6237. }
  6238. fed.DrCodg = strconv.FormatInt(doctor_info.ID, 10)
  6239. fed.AdmDeptCodg = strconv.FormatInt(department.ID, 10)
  6240. fed.AdmDeptName = department.Name
  6241. fed.DscgDeptCodg = strconv.FormatInt(department.ID, 10)
  6242. fed.DscgDeptName = department.Name
  6243. fed.MedMdtrtType = "1"
  6244. fed.MedType = "11"
  6245. //if his.Insutype == "390" {
  6246. // fed.MedType = "1402"
  6247. //} else {
  6248. // fed.MedType = "9933"
  6249. //}
  6250. var orders []*models.FsiOrderDtos
  6251. if trig_scen == "4" {
  6252. //处方医嘱信息
  6253. for _, item := range prescriptions {
  6254. for _, subItem := range item.HisDoctorAdviceInfo {
  6255. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 && subItem.BaseDrugLib.IsUser != 1 {
  6256. spec := (subItem.BaseDrugLib.Dose + subItem.BaseDrugLib.DoseUnit) + "*" + strconv.FormatInt(subItem.BaseDrugLib.MinNumber, 10) + subItem.BaseDrugLib.MinUnit + "/" + subItem.BaseDrugLib.MaxUnit
  6257. var order models.FsiOrderDtos
  6258. order.RxID = strconv.FormatInt(item.ID, 10)
  6259. order.Rxno = strconv.FormatInt(item.ID, 10)
  6260. order.LongDrordFlag = "0"
  6261. order.HilistType = "1"
  6262. order.ChrgType = "1"
  6263. order.DrordBhvr = "0"
  6264. order.HilistCode = subItem.BaseDrugLib.MedicalInsuranceNumber
  6265. order.HosplistName = subItem.BaseDrugLib.DrugName
  6266. order.HilistLv = "1"
  6267. order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  6268. order.HosplistCode = subItem.BaseDrugLib.MedicalInsuranceNumber
  6269. order.HosplistName = subItem.BaseDrugLib.DrugName
  6270. order.Cnt = fmt.Sprintf("%.2f", subItem.PrescribingNumber)
  6271. order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  6272. order.Sumamt = fmt.Sprintf("%.2f", (subItem.PrescribingNumber * subItem.Price))
  6273. order.OwnpayAmt = ""
  6274. order.SelfpayAmt = ""
  6275. order.Spec = spec
  6276. order.SpecUnt = subItem.PrescribingNumberUnit
  6277. order.DrordBegnDate = s_tm
  6278. order.DrordStopDate = ""
  6279. order.DrordDrCodg = doctor_info.DoctorNumber
  6280. order.DrordDeptName = department.Name
  6281. order.DrordDeptCodg = department.Number
  6282. order.DrordDrName = doctor_info.UserName
  6283. order.DrordDrProfttl = "234"
  6284. order.CurrDrordFlag = "1"
  6285. orders = append(orders, &order)
  6286. }
  6287. }
  6288. for _, subItem := range item.HisPrescriptionProject {
  6289. if len(subItem.HisProject.MedicalCode) > 0 {
  6290. if subItem.Type == 2 {
  6291. var order models.FsiOrderDtos
  6292. order.RxID = strconv.FormatInt(item.ID, 10)
  6293. order.Rxno = strconv.FormatInt(item.ID, 10)
  6294. order.LongDrordFlag = "0"
  6295. order.HilistType = "1"
  6296. order.ChrgType = "1"
  6297. order.DrordBhvr = "0"
  6298. order.HilistCode = subItem.HisProject.MedicalCode
  6299. order.HosplistName = subItem.HisProject.ProjectName
  6300. order.HilistLv = "1"
  6301. order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  6302. order.HosplistCode = subItem.HisProject.MedicalCode
  6303. order.HosplistName = subItem.HisProject.ProjectName
  6304. order.Cnt = subItem.Count
  6305. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6306. order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  6307. order.Sumamt = fmt.Sprintf("%.2f", subItem.Price*cnt)
  6308. order.OwnpayAmt = ""
  6309. order.SelfpayAmt = ""
  6310. order.Spec = subItem.Unit
  6311. order.SpecUnt = subItem.Unit
  6312. order.DrordBegnDate = s_tm
  6313. order.DrordStopDate = ""
  6314. order.DrordDrCodg = doctor_info.DoctorNumber
  6315. order.DrordDeptName = department.Name
  6316. order.DrordDeptCodg = department.Number
  6317. order.DrordDrName = doctor_info.UserName
  6318. order.DrordDrProfttl = "234"
  6319. order.CurrDrordFlag = "1"
  6320. orders = append(orders, &order)
  6321. }
  6322. }
  6323. if subItem.Type == 3 {
  6324. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 && subItem.GoodInfo.IsUser != 1 {
  6325. var order models.FsiOrderDtos
  6326. order.RxID = strconv.FormatInt(item.ID, 10)
  6327. order.Rxno = strconv.FormatInt(item.ID, 10)
  6328. order.LongDrordFlag = "0"
  6329. order.HilistType = "1"
  6330. order.ChrgType = "1"
  6331. order.DrordBhvr = "0"
  6332. order.HilistCode = subItem.GoodInfo.MedicalInsuranceNumber
  6333. order.HosplistName = subItem.GoodInfo.GoodName
  6334. order.HilistLv = "1"
  6335. order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  6336. order.HosplistCode = subItem.GoodInfo.MedicalInsuranceNumber
  6337. order.HosplistName = subItem.GoodInfo.GoodName
  6338. order.Cnt = subItem.Count
  6339. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6340. order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  6341. order.Sumamt = fmt.Sprintf("%.2f", subItem.Price*cnt)
  6342. order.OwnpayAmt = ""
  6343. order.SelfpayAmt = ""
  6344. order.Spec = subItem.GoodInfo.SpecificationName
  6345. order.SpecUnt = subItem.Unit
  6346. order.DrordBegnDate = s_tm
  6347. order.DrordStopDate = ""
  6348. order.DrordDrCodg = doctor_info.DoctorNumber
  6349. order.DrordDeptName = department.Name
  6350. order.DrordDeptCodg = department.Number
  6351. order.DrordDrName = doctor_info.UserName
  6352. order.DrordDrProfttl = "234"
  6353. order.CurrDrordFlag = "1"
  6354. orders = append(orders, &order)
  6355. }
  6356. }
  6357. }
  6358. }
  6359. //处方医嘱信息
  6360. }
  6361. fed.MatnStas = "0"
  6362. fed.MedfeeSumamt = "0"
  6363. fed.OwnpayAmt = "0"
  6364. fed.SelfpayAmt = "0"
  6365. fed.AcctPayamt = "0"
  6366. fed.MaAmt = "0"
  6367. fed.HifpPayamt = "0"
  6368. fed.SetlTotlnum = "1"
  6369. fed.Insutype = his.Insutype
  6370. fed.ReimFlag = "0"
  6371. fed.OutSetlFlag = "0"
  6372. var fopd []*models.FsiOperationDtosData
  6373. data := make(map[string]interface{})
  6374. data["fed"] = fed
  6375. data["fdd"] = fdds
  6376. data["fod"] = orders
  6377. data["pd"] = pd
  6378. data["pp"] = pp
  6379. data["fopd"] = fopd
  6380. data["trig_scen"] = trig_scen
  6381. fmt.Println(data)
  6382. fmt.Println(fed)
  6383. fmt.Println(fdds)
  6384. fmt.Println(orders)
  6385. fmt.Println(pd)
  6386. fmt.Println(pp)
  6387. fmt.Println(fopd)
  6388. client := &http.Client{}
  6389. bytesData, _ := json.Marshal(data)
  6390. var req *http.Request
  6391. if miConfig.MdtrtareaAdmvs == "320921" || miConfig.MdtrtareaAdmvs == "320982" {
  6392. if miConfig.MdtrtareaAdmvs == "320921" {
  6393. req, _ = http.NewRequest("POST", "http://192.168.2.3:9532/"+"jsyb/3101", bytes.NewReader(bytesData))
  6394. } else {
  6395. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3101", bytes.NewReader(bytesData))
  6396. }
  6397. resp, _ := client.Do(req)
  6398. defer resp.Body.Close()
  6399. body, ioErr := ioutil.ReadAll(resp.Body)
  6400. if ioErr != nil {
  6401. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  6402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6403. return res
  6404. }
  6405. var respJSON map[string]interface{}
  6406. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  6407. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  6408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6409. return res
  6410. }
  6411. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  6412. fmt.Println(respJSON)
  6413. result, _ := json.Marshal(respJSON)
  6414. fmt.Println(result)
  6415. if err := json.Unmarshal([]byte(result), &res); err != nil {
  6416. utils.ErrorLog("解析失败:%v", err)
  6417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6418. return res
  6419. }
  6420. return res
  6421. } else {
  6422. //if miConfig.MdtrtareaAdmvs == "441202" {
  6423. output, input := service.Gdyb3101(pd, fed, fdds, orders, fopd, pp, trig_scen)
  6424. saveLog(output, input, "3101", "事前")
  6425. if err := json.Unmarshal([]byte(output), &res); err != nil {
  6426. utils.ErrorLog("解析失败:%v", err)
  6427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6428. return
  6429. }
  6430. return res
  6431. //}
  6432. }
  6433. }
  6434. 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) {
  6435. adminUser := c.GetAdminUserInfo()
  6436. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  6437. his, _ := service.GetInHospitalRecord(his_patient_id)
  6438. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  6439. //record_time := c.GetString("record_time")
  6440. //trig_scen := c.GetString("trig_scen")
  6441. timeLayout := "2006-01-02"
  6442. loc, _ := time.LoadLocation("Local")
  6443. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6444. if err != nil {
  6445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6446. return res
  6447. }
  6448. recordDateTime := theTime.Unix()
  6449. var patientPrescription models.HisPrescriptionInfo
  6450. patientPrescription, _ = service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  6451. if patientPrescription.ID == 0 {
  6452. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  6453. }
  6454. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  6455. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  6456. //
  6457. diagnosis_ids := strings.Split(patientPrescription.Diagnosis, ",")
  6458. p, _ := service.GetPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  6459. //prescriptions, _ := service.GetNewHisPrescriptionTen(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  6460. var pp models.PublicParams
  6461. pp.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
  6462. pp.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
  6463. pp.FixmedinsName = miConfig.OrgName
  6464. pp.FixmedinsCode = miConfig.Code
  6465. pp.RequestUrl = miConfig.Url
  6466. pp.Cainfo = miConfig.Cainfo
  6467. pp.SecretKey = miConfig.SecretKey
  6468. pp.AccessKey = miConfig.AccessKey
  6469. pp.OpterName = roles.UserName
  6470. var config []*models.HisXtDiagnoseConfig
  6471. for _, item := range diagnosis_ids {
  6472. id, _ := strconv.ParseInt(item, 10, 64)
  6473. if id > 0 {
  6474. diagnosisConfig, _ := service.FindDiagnoseById(id)
  6475. config = append(config, &diagnosisConfig)
  6476. }
  6477. }
  6478. var pd models.PatientDtos
  6479. pd.PatnID = his.PsnNo
  6480. pd.PatnName = his.Name
  6481. pd.Gend = his.Gend
  6482. pd.Poolarea = his.InsuplcAdmdvs
  6483. pd.CurrMdtrtID = his.Number
  6484. birthday := time.Unix(p.Birthday, 0)
  6485. // 格式化为生日字符串
  6486. birthdayStr := birthday.Format("2006-01-02") // 格式化模板为 "年-月-日"
  6487. pd.Brdy = birthdayStr
  6488. var fed models.FsiEncounterDtos
  6489. fed.MdtrtID = his.Number
  6490. fed.MedinsID = miConfig.Code
  6491. fed.MedinsName = miConfig.OrgName
  6492. fed.MedinsAdmdvs = miConfig.MdtrtareaAdmvs
  6493. fed.MedMdtrtType = "1"
  6494. fed.MedinsType = "1"
  6495. fed.MedinsLv = "11"
  6496. tm := time.Unix(his.RecordDate, 0)
  6497. s_tm := tm.Format("2006-01-02 15:04:05")
  6498. fed.AdmDate = s_tm
  6499. fed.DscgDate = s_tm
  6500. fed.DscgMainDiseCodg = config[0].CountryCode
  6501. fed.DscgMainDiseName = config[0].CountryContentName
  6502. //诊断信息
  6503. var fdds []*models.FsiDiagnoseDtos
  6504. for index, item := range config {
  6505. if index == 0 {
  6506. var fdd models.FsiDiagnoseDtos
  6507. fdd.DiseID = strconv.FormatInt(item.ID, 10)
  6508. fdd.InoutDiseType = "1"
  6509. fdd.MaindiseFlag = "1"
  6510. fdd.DiseDate = s_tm
  6511. fdd.DiasSrtNo = "1"
  6512. fdd.DiseName = item.CountryContentName
  6513. fdd.DiseCodg = item.CountryCode
  6514. fdds = append(fdds, &fdd)
  6515. } else {
  6516. var fdd models.FsiDiagnoseDtos
  6517. fdd.DiseID = strconv.FormatInt(item.ID, 10)
  6518. fdd.InoutDiseType = "1"
  6519. fdd.MaindiseFlag = "1"
  6520. fdd.DiseDate = s_tm
  6521. fdd.DiasSrtNo = strconv.FormatInt(int64(index), 10)
  6522. fdd.DiseName = item.CountryContentName
  6523. fdd.DiseCodg = item.CountryCode
  6524. fdds = append(fdds, &fdd)
  6525. }
  6526. }
  6527. fed.DrCodg = strconv.FormatInt(doctor_info.ID, 10)
  6528. fed.AdmDeptCodg = strconv.FormatInt(department.ID, 10)
  6529. fed.AdmDeptName = department.Name
  6530. fed.DscgDeptCodg = strconv.FormatInt(department.ID, 10)
  6531. fed.DscgDeptName = department.Name
  6532. fed.MedMdtrtType = "1"
  6533. fed.MedType = "11"
  6534. //if his.Insutype == "390" {
  6535. // fed.MedType = "1402"
  6536. //} else {
  6537. // fed.MedType = "9933"
  6538. //}
  6539. var orders []*models.FsiOrderDtos
  6540. if trig_scen == "4" {
  6541. //处方医嘱信息
  6542. for _, item := range prescriptions {
  6543. for _, subItem := range item.HisDoctorAdviceInfo {
  6544. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 && subItem.BaseDrugLib.IsUser != 1 {
  6545. spec := (subItem.BaseDrugLib.Dose + subItem.BaseDrugLib.DoseUnit) + "*" + strconv.FormatInt(subItem.BaseDrugLib.MinNumber, 10) + subItem.BaseDrugLib.MinUnit + "/" + subItem.BaseDrugLib.MaxUnit
  6546. var order models.FsiOrderDtos
  6547. order.RxID = strconv.FormatInt(item.ID, 10)
  6548. order.Rxno = strconv.FormatInt(item.ID, 10)
  6549. order.LongDrordFlag = "0"
  6550. order.HilistType = "1"
  6551. order.ChrgType = "1"
  6552. order.DrordBhvr = "0"
  6553. order.HilistCode = subItem.BaseDrugLib.MedicalInsuranceNumber
  6554. order.HosplistName = subItem.BaseDrugLib.DrugName
  6555. order.HilistLv = "1"
  6556. order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  6557. order.HosplistCode = subItem.BaseDrugLib.MedicalInsuranceNumber
  6558. order.HosplistName = subItem.BaseDrugLib.DrugName
  6559. order.Cnt = fmt.Sprintf("%.2f", subItem.PrescribingNumber)
  6560. order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  6561. order.Sumamt = fmt.Sprintf("%.2f", (subItem.PrescribingNumber * subItem.Price))
  6562. order.OwnpayAmt = ""
  6563. order.SelfpayAmt = ""
  6564. order.Spec = spec
  6565. order.SpecUnt = subItem.PrescribingNumberUnit
  6566. order.DrordBegnDate = s_tm
  6567. order.DrordStopDate = ""
  6568. order.DrordDrCodg = doctor_info.DoctorNumber
  6569. order.DrordDeptName = department.Name
  6570. order.DrordDeptCodg = department.Number
  6571. order.DrordDrName = doctor_info.UserName
  6572. order.DrordDrProfttl = "234"
  6573. order.CurrDrordFlag = "1"
  6574. orders = append(orders, &order)
  6575. }
  6576. }
  6577. for _, subItem := range item.HisPrescriptionProject {
  6578. if len(subItem.HisProject.MedicalCode) > 0 {
  6579. if subItem.Type == 2 {
  6580. var order models.FsiOrderDtos
  6581. order.RxID = strconv.FormatInt(item.ID, 10)
  6582. order.Rxno = strconv.FormatInt(item.ID, 10)
  6583. order.LongDrordFlag = "0"
  6584. order.HilistType = "1"
  6585. order.ChrgType = "1"
  6586. order.DrordBhvr = "0"
  6587. order.HilistCode = subItem.HisProject.MedicalCode
  6588. order.HosplistName = subItem.HisProject.ProjectName
  6589. order.HilistLv = "1"
  6590. order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  6591. order.HosplistCode = subItem.HisProject.MedicalCode
  6592. order.HosplistName = subItem.HisProject.ProjectName
  6593. order.Cnt = subItem.Count
  6594. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6595. order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  6596. order.Sumamt = fmt.Sprintf("%.2f", subItem.Price*cnt)
  6597. order.OwnpayAmt = ""
  6598. order.SelfpayAmt = ""
  6599. order.Spec = subItem.Unit
  6600. order.SpecUnt = subItem.Unit
  6601. order.DrordBegnDate = s_tm
  6602. order.DrordStopDate = ""
  6603. order.DrordDrCodg = doctor_info.DoctorNumber
  6604. order.DrordDeptName = department.Name
  6605. order.DrordDeptCodg = department.Number
  6606. order.DrordDrName = doctor_info.UserName
  6607. order.DrordDrProfttl = "234"
  6608. order.CurrDrordFlag = "1"
  6609. orders = append(orders, &order)
  6610. }
  6611. }
  6612. if subItem.Type == 3 {
  6613. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 && subItem.GoodInfo.IsUser != 1 {
  6614. var order models.FsiOrderDtos
  6615. order.RxID = strconv.FormatInt(item.ID, 10)
  6616. order.Rxno = strconv.FormatInt(item.ID, 10)
  6617. order.LongDrordFlag = "0"
  6618. order.HilistType = "1"
  6619. order.ChrgType = "1"
  6620. order.DrordBhvr = "0"
  6621. order.HilistCode = subItem.GoodInfo.MedicalInsuranceNumber
  6622. order.HosplistName = subItem.GoodInfo.GoodName
  6623. order.HilistLv = "1"
  6624. order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  6625. order.HosplistCode = subItem.GoodInfo.MedicalInsuranceNumber
  6626. order.HosplistName = subItem.GoodInfo.GoodName
  6627. order.Cnt = subItem.Count
  6628. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6629. order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  6630. order.Sumamt = fmt.Sprintf("%.2f", subItem.Price*cnt)
  6631. order.OwnpayAmt = ""
  6632. order.SelfpayAmt = ""
  6633. order.Spec = subItem.GoodInfo.SpecificationName
  6634. order.SpecUnt = subItem.Unit
  6635. order.DrordBegnDate = s_tm
  6636. order.DrordStopDate = ""
  6637. order.DrordDrCodg = doctor_info.DoctorNumber
  6638. order.DrordDeptName = department.Name
  6639. order.DrordDeptCodg = department.Number
  6640. order.DrordDrName = doctor_info.UserName
  6641. order.DrordDrProfttl = "234"
  6642. order.CurrDrordFlag = "1"
  6643. orders = append(orders, &order)
  6644. }
  6645. }
  6646. }
  6647. }
  6648. //处方医嘱信息
  6649. }
  6650. fed.MatnStas = "0"
  6651. fed.MedfeeSumamt = "0"
  6652. fed.OwnpayAmt = "0"
  6653. fed.SelfpayAmt = "0"
  6654. fed.AcctPayamt = "0"
  6655. fed.MaAmt = "0"
  6656. fed.HifpPayamt = "0"
  6657. fed.SetlTotlnum = "1"
  6658. fed.Insutype = his.InsutypeType
  6659. fed.ReimFlag = "0"
  6660. fed.OutSetlFlag = "0"
  6661. var fopd []*models.FsiOperationDtosData
  6662. data := make(map[string]interface{})
  6663. data["fed"] = fed
  6664. data["fdd"] = fdds
  6665. data["fod"] = orders
  6666. data["pd"] = pd
  6667. data["pp"] = pp
  6668. data["fopd"] = fopd
  6669. data["trig_scen"] = trig_scen
  6670. fmt.Println(data)
  6671. fmt.Println(fed)
  6672. fmt.Println(fdds)
  6673. fmt.Println(orders)
  6674. fmt.Println(pd)
  6675. fmt.Println(pp)
  6676. fmt.Println(fopd)
  6677. client := &http.Client{}
  6678. bytesData, _ := json.Marshal(data)
  6679. var req *http.Request
  6680. if miConfig.MdtrtareaAdmvs == "320921" || miConfig.MdtrtareaAdmvs == "320982" {
  6681. if miConfig.MdtrtareaAdmvs == "320921" {
  6682. req, _ = http.NewRequest("POST", "http://192.168.2.3:9532/"+"jsyb/3101", bytes.NewReader(bytesData))
  6683. } else {
  6684. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3101", bytes.NewReader(bytesData))
  6685. }
  6686. resp, _ := client.Do(req)
  6687. defer resp.Body.Close()
  6688. body, ioErr := ioutil.ReadAll(resp.Body)
  6689. if ioErr != nil {
  6690. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  6691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6692. return res
  6693. }
  6694. var respJSON map[string]interface{}
  6695. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  6696. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  6697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6698. return res
  6699. }
  6700. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  6701. fmt.Println(respJSON)
  6702. result, _ := json.Marshal(respJSON)
  6703. fmt.Println(result)
  6704. if err := json.Unmarshal([]byte(result), &res); err != nil {
  6705. utils.ErrorLog("解析失败:%v", err)
  6706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6707. return res
  6708. }
  6709. return res
  6710. } else {
  6711. output, input := service.Gdyb3101(pd, fed, fdds, orders, fopd, pp, trig_scen)
  6712. saveLog(output, input, "3101", "事前")
  6713. if err := json.Unmarshal([]byte(output), &res); err != nil {
  6714. utils.ErrorLog("解析失败:%v", err)
  6715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6716. return
  6717. }
  6718. return res
  6719. }
  6720. return res
  6721. }
  6722. func Check3102(c *ZHHisApiController, patient_id int64, his_patient_id int64, admin_user_id int64, trig_scen string, order_id int64) (res Result3101) {
  6723. ////patient_id, _ := c.GetInt64("patient_id")
  6724. //order_id, _ := c.GetInt64("order_id")
  6725. ////his_patient_id, _ := c.GetInt64("his_patient_id")
  6726. ////admin_user_id, _ := c.GetInt64("admin_user_id")
  6727. //trig_scen := c.GetString("trig_scen")
  6728. adminUser := c.GetAdminUserInfo()
  6729. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  6730. //his, _ := service.GetNewHisPatientInfoFour(c.GetAdminUserInfo().CurrentOrgId, his_patient_id)
  6731. his, _ := service.GetInHospitalRecord(his_patient_id)
  6732. p, _ := service.GetPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  6733. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  6734. record_time := c.GetString("record_time")
  6735. order, _ := service.GetHisOrderByID(order_id)
  6736. timeLayout := "2006-01-02"
  6737. loc, _ := time.LoadLocation("Local")
  6738. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6739. if err != nil {
  6740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6741. return
  6742. }
  6743. recordDateTime := theTime.Unix()
  6744. var patientPrescription models.HisPrescriptionInfo
  6745. patientPrescription, _ = service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  6746. if patientPrescription.ID == 0 {
  6747. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  6748. }
  6749. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  6750. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  6751. //
  6752. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  6753. prescriptions, _ := service.GetNewHisPrescriptionTenone(adminUser.CurrentOrgId, his.Number)
  6754. var pp models.PublicParams
  6755. pp.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
  6756. pp.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
  6757. pp.FixmedinsName = miConfig.OrgName
  6758. pp.FixmedinsCode = miConfig.Code
  6759. pp.RequestUrl = miConfig.Url
  6760. pp.Cainfo = miConfig.Cainfo
  6761. pp.SecretKey = miConfig.SecretKey
  6762. pp.AccessKey = miConfig.AccessKey
  6763. pp.OpterName = roles.UserName
  6764. var config []*models.HisXtDiagnoseConfig
  6765. for _, item := range diagnosis_ids {
  6766. id, _ := strconv.ParseInt(item, 10, 64)
  6767. if id > 0 {
  6768. diagnosisConfig, _ := service.FindDiagnoseById(id)
  6769. config = append(config, &diagnosisConfig)
  6770. }
  6771. }
  6772. var pd models.PatientDtos
  6773. pd.PatnID = his.PsnNo
  6774. pd.PatnName = his.Name
  6775. pd.Gend = his.Gend
  6776. pd.Poolarea = his.InsuplcAdmdvs
  6777. pd.CurrMdtrtID = his.Number
  6778. // 将时间戳转换为 time.Time 类型
  6779. birthday := time.Unix(p.Birthday, 0)
  6780. // 格式化为生日字符串
  6781. birthdayStr := birthday.Format("2006-01-02") // 格式化模板为 "年-月-日"
  6782. pd.Brdy = birthdayStr
  6783. var fed models.FsiEncounterDtos
  6784. fed.MdtrtID = his.Number
  6785. fed.MedinsID = miConfig.Code
  6786. fed.MedinsName = miConfig.OrgName
  6787. fed.MedinsAdmdvs = miConfig.MdtrtareaAdmvs
  6788. fed.MedMdtrtType = "1"
  6789. fed.MedinsType = "1"
  6790. fed.MedinsLv = "11"
  6791. tm := time.Unix(his.RecordDate, 0)
  6792. s_tm := tm.Format("2006-01-02 15:04:05")
  6793. fed.AdmDate = s_tm
  6794. fed.DscgDate = s_tm
  6795. fed.DscgMainDiseCodg = config[0].CountryCode
  6796. fed.DscgMainDiseName = config[0].CountryContentName
  6797. //诊断信息
  6798. var fdds []*models.FsiDiagnoseDtos
  6799. for index, item := range config {
  6800. if index == 0 {
  6801. var fdd models.FsiDiagnoseDtos
  6802. fdd.DiseID = strconv.FormatInt(item.ID, 10)
  6803. fdd.InoutDiseType = "1"
  6804. fdd.MaindiseFlag = "1"
  6805. fdd.DiseDate = s_tm
  6806. fdd.DiasSrtNo = "1"
  6807. fdd.DiseName = item.CountryContentName
  6808. fdd.DiseCodg = item.CountryCode
  6809. fdds = append(fdds, &fdd)
  6810. } else {
  6811. var fdd models.FsiDiagnoseDtos
  6812. fdd.DiseID = strconv.FormatInt(item.ID, 10)
  6813. fdd.InoutDiseType = "1"
  6814. fdd.MaindiseFlag = "1"
  6815. fdd.DiseDate = s_tm
  6816. fdd.DiasSrtNo = strconv.FormatInt(int64(index), 10)
  6817. fdd.DiseName = item.CountryContentName
  6818. fdd.DiseCodg = item.CountryCode
  6819. fdds = append(fdds, &fdd)
  6820. }
  6821. }
  6822. fed.DrCodg = strconv.FormatInt(doctor_info.ID, 10)
  6823. fed.AdmDeptCodg = strconv.FormatInt(department.ID, 10)
  6824. fed.AdmDeptName = department.Name
  6825. fed.DscgDeptCodg = strconv.FormatInt(department.ID, 10)
  6826. fed.DscgDeptName = department.Name
  6827. fed.MedType = "14"
  6828. //处方医嘱信息
  6829. var orders []*models.FsiOrderDtos
  6830. //for _, item := range prescriptions {
  6831. // for _, subItem := range item.HisDoctorAdviceInfo {
  6832. // var order models.FsiOrderDtos
  6833. // order.RxID = strconv.FormatInt(item.ID, 10)
  6834. // order.Rxno = strconv.FormatInt(item.ID, 10)
  6835. // order.LongDrordFlag = "0"
  6836. // order.HilistType = "1"
  6837. // order.ChrgType = "1"
  6838. // order.DrordBhvr = "-"
  6839. // order.HilistCode = subItem.BaseDrugLib.MedicalInsuranceNumber
  6840. // order.HosplistName = subItem.BaseDrugLib.DrugName
  6841. // order.HilistLv = "1"
  6842. // order.HilistPric = strconv.FormatFloat(subItem.Price, 'E', -1, 64)
  6843. // order.HosplistCode = subItem.BaseDrugLib.MedicalInsuranceNumber
  6844. // order.HosplistName = subItem.BaseDrugLib.DrugName
  6845. // order.Cnt = strconv.FormatFloat(subItem.PrescribingNumber, 'E', -1, 64)
  6846. // order.Pric = strconv.FormatFloat(subItem.Price, 'E', -1, 64)
  6847. // order.Sumamt = strconv.FormatFloat((subItem.Price * subItem.PrescribingNumber), 'E', -1, 64)
  6848. // order.OwnpayAmt = ""
  6849. // order.SelfpayAmt = ""
  6850. // order.Spec = ""
  6851. // order.SpecUnt = ""
  6852. // order.DrordBegnDate = s_tm
  6853. // order.DrordStopDate = ""
  6854. // order.DrordDrCodg = "1"
  6855. // order.DrordDeptName = department.Name
  6856. // order.DrordDrCodg = "1"
  6857. // order.DrordDrName = doctor_info.UserName
  6858. // order.DrordDrProfttl = ""
  6859. // order.CurrDrordFlag = "1"
  6860. // orders = append(orders, &order)
  6861. // }
  6862. // for _, subItem := range item.HisPrescriptionProject {
  6863. // if subItem.Type == 2 {
  6864. // var order models.FsiOrderDtos
  6865. // order.RxID = strconv.FormatInt(item.ID, 10)
  6866. // order.Rxno = strconv.FormatInt(item.ID, 10)
  6867. // order.LongDrordFlag = "0"
  6868. // order.HilistType = "1"
  6869. // order.ChrgType = "1"
  6870. // order.DrordBhvr = "-"
  6871. // order.HilistCode = subItem.HisProject.MedicalCode
  6872. // order.HosplistName = subItem.HisProject.ProjectName
  6873. // order.HilistLv = "1"
  6874. // order.HilistPric = strconv.FormatFloat(subItem.Price, 'E', -1, 64)
  6875. // order.HosplistCode = subItem.HisProject.MedicalCode
  6876. // order.HosplistName = subItem.HisProject.ProjectName
  6877. // order.Cnt = subItem.Count
  6878. // cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6879. //
  6880. // order.Pric = strconv.FormatFloat(subItem.Price, 'E', -1, 64)
  6881. // order.Sumamt = strconv.FormatFloat((subItem.Price * cnt), 'E', -1, 64)
  6882. // order.OwnpayAmt = ""
  6883. // order.SelfpayAmt = ""
  6884. // order.Spec = ""
  6885. // order.SpecUnt = ""
  6886. // order.DrordBegnDate = s_tm
  6887. // order.DrordStopDate = ""
  6888. // order.DrordDrCodg = "1"
  6889. // order.DrordDeptName = department.Name
  6890. // order.DrordDrCodg = "1"
  6891. // order.DrordDrName = doctor_info.UserName
  6892. // order.DrordDrProfttl = ""
  6893. // order.CurrDrordFlag = "1"
  6894. // orders = append(orders, &order)
  6895. //
  6896. // }
  6897. // if subItem.Type == 3 {
  6898. //
  6899. // var order models.FsiOrderDtos
  6900. // order.RxID = strconv.FormatInt(item.ID, 10)
  6901. // order.Rxno = strconv.FormatInt(item.ID, 10)
  6902. // order.LongDrordFlag = "0"
  6903. // order.HilistType = "1"
  6904. // order.ChrgType = "1"
  6905. // order.DrordBhvr = "-"
  6906. // order.HilistCode = subItem.GoodInfo.MedicalInsuranceNumber
  6907. // order.HosplistName = subItem.GoodInfo.GoodName
  6908. // order.HilistLv = "1"
  6909. // order.HilistPric = strconv.FormatFloat(subItem.Price, 'E', -1, 64)
  6910. // order.HosplistCode = subItem.GoodInfo.MedicalInsuranceNumber
  6911. // order.HosplistName = subItem.GoodInfo.GoodName
  6912. // order.Cnt = subItem.Count
  6913. // cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6914. // order.Pric = strconv.FormatFloat(subItem.Price, 'E', -1, 64)
  6915. // order.Sumamt = strconv.FormatFloat((subItem.Price * cnt), 'E', -1, 64)
  6916. // order.OwnpayAmt = ""
  6917. // order.SelfpayAmt = ""
  6918. // order.Spec = ""
  6919. // order.SpecUnt = ""
  6920. // order.DrordBegnDate = s_tm
  6921. // order.DrordStopDate = ""
  6922. // order.DrordDrCodg = "1"
  6923. // order.DrordDeptName = department.Name
  6924. // order.DrordDrCodg = "1"
  6925. // order.DrordDrName = doctor_info.UserName
  6926. // order.DrordDrProfttl = ""
  6927. // order.CurrDrordFlag = "1"
  6928. // orders = append(orders, &order)
  6929. //
  6930. // }
  6931. // }
  6932. //}
  6933. for _, item := range prescriptions {
  6934. for _, subItem := range item.HisDoctorAdviceInfo {
  6935. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 && subItem.BaseDrugLib.IsUser != 1 {
  6936. spec := (subItem.BaseDrugLib.Dose + subItem.BaseDrugLib.DoseUnit) + "*" + strconv.FormatInt(subItem.BaseDrugLib.MinNumber, 10) + subItem.BaseDrugLib.MinUnit + "/" + subItem.BaseDrugLib.MaxUnit
  6937. var order models.FsiOrderDtos
  6938. order.RxID = strconv.FormatInt(item.ID, 10)
  6939. order.Rxno = strconv.FormatInt(item.ID, 10)
  6940. order.LongDrordFlag = "0"
  6941. order.HilistType = "1"
  6942. order.ChrgType = "1"
  6943. order.DrordBhvr = "0"
  6944. order.HilistCode = subItem.BaseDrugLib.MedicalInsuranceNumber
  6945. order.HosplistName = subItem.BaseDrugLib.DrugName
  6946. order.HilistLv = "1"
  6947. order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  6948. order.HosplistCode = subItem.BaseDrugLib.MedicalInsuranceNumber
  6949. order.HosplistName = subItem.BaseDrugLib.DrugName
  6950. order.Cnt = fmt.Sprintf("%.2f", subItem.PrescribingNumber)
  6951. order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  6952. order.Sumamt = fmt.Sprintf("%.2f", (subItem.PrescribingNumber * subItem.Price))
  6953. order.OwnpayAmt = ""
  6954. order.SelfpayAmt = ""
  6955. order.Spec = spec
  6956. order.SpecUnt = subItem.PrescribingNumberUnit
  6957. order.DrordBegnDate = s_tm
  6958. order.DrordStopDate = ""
  6959. order.DrordDrCodg = doctor_info.DoctorNumber
  6960. order.DrordDeptName = department.Name
  6961. order.DrordDeptCodg = department.Number
  6962. order.DrordDrName = doctor_info.UserName
  6963. order.DrordDrProfttl = "234"
  6964. order.CurrDrordFlag = "1"
  6965. orders = append(orders, &order)
  6966. }
  6967. }
  6968. for _, subItem := range item.HisPrescriptionProject {
  6969. if len(subItem.HisProject.MedicalCode) > 0 {
  6970. if subItem.Type == 2 {
  6971. var order models.FsiOrderDtos
  6972. order.RxID = strconv.FormatInt(item.ID, 10)
  6973. order.Rxno = strconv.FormatInt(item.ID, 10)
  6974. order.LongDrordFlag = "0"
  6975. order.HilistType = "1"
  6976. order.ChrgType = "1"
  6977. order.DrordBhvr = "0"
  6978. order.HilistCode = subItem.HisProject.MedicalCode
  6979. order.HosplistName = subItem.HisProject.ProjectName
  6980. order.HilistLv = "1"
  6981. order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  6982. order.HosplistCode = subItem.HisProject.MedicalCode
  6983. order.HosplistName = subItem.HisProject.ProjectName
  6984. order.Cnt = subItem.Count
  6985. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6986. order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  6987. order.Sumamt = fmt.Sprintf("%.2f", subItem.Price*cnt)
  6988. order.OwnpayAmt = ""
  6989. order.SelfpayAmt = ""
  6990. order.Spec = subItem.Unit
  6991. order.SpecUnt = subItem.Unit
  6992. order.DrordBegnDate = s_tm
  6993. order.DrordStopDate = ""
  6994. order.DrordDrCodg = doctor_info.DoctorNumber
  6995. order.DrordDeptName = department.Name
  6996. order.DrordDeptCodg = department.Number
  6997. order.DrordDrName = doctor_info.UserName
  6998. order.DrordDrProfttl = "234"
  6999. order.CurrDrordFlag = "1"
  7000. orders = append(orders, &order)
  7001. }
  7002. }
  7003. if subItem.Type == 3 {
  7004. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 && subItem.GoodInfo.IsUser != 1 {
  7005. var order models.FsiOrderDtos
  7006. order.RxID = strconv.FormatInt(item.ID, 10)
  7007. order.Rxno = strconv.FormatInt(item.ID, 10)
  7008. order.LongDrordFlag = "0"
  7009. order.HilistType = "1"
  7010. order.ChrgType = "1"
  7011. order.DrordBhvr = "0"
  7012. order.HilistCode = subItem.GoodInfo.MedicalInsuranceNumber
  7013. order.HosplistName = subItem.GoodInfo.GoodName
  7014. order.HilistLv = "1"
  7015. order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  7016. order.HosplistCode = subItem.GoodInfo.MedicalInsuranceNumber
  7017. order.HosplistName = subItem.GoodInfo.GoodName
  7018. order.Cnt = subItem.Count
  7019. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7020. order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  7021. order.Sumamt = fmt.Sprintf("%.2f", subItem.Price*cnt)
  7022. order.OwnpayAmt = ""
  7023. order.SelfpayAmt = ""
  7024. order.Spec = subItem.GoodInfo.SpecificationName
  7025. order.SpecUnt = subItem.Unit
  7026. order.DrordBegnDate = s_tm
  7027. order.DrordStopDate = ""
  7028. order.DrordDrCodg = doctor_info.DoctorNumber
  7029. order.DrordDeptName = department.Name
  7030. order.DrordDeptCodg = department.Number
  7031. order.DrordDrName = doctor_info.UserName
  7032. order.DrordDrProfttl = "234"
  7033. order.CurrDrordFlag = "1"
  7034. orders = append(orders, &order)
  7035. }
  7036. }
  7037. }
  7038. }
  7039. //for _, item := range prescriptions {
  7040. // for _, subItem := range item.HisDoctorAdviceInfo {
  7041. // spec := (subItem.BaseDrugLib.Dose + subItem.BaseDrugLib.DoseUnit) + "*" + strconv.FormatInt(subItem.BaseDrugLib.MinNumber, 10) + subItem.BaseDrugLib.MinUnit + "/" + subItem.BaseDrugLib.MaxUnit
  7042. //
  7043. // var order models.FsiOrderDtos
  7044. // order.RxID = strconv.FormatInt(item.ID, 10)
  7045. // order.Rxno = strconv.FormatInt(item.ID, 10)
  7046. // order.LongDrordFlag = "0"
  7047. // order.HilistType = "1"
  7048. // order.ChrgType = "1"
  7049. // order.DrordBhvr = "0"
  7050. // order.HilistCode = subItem.BaseDrugLib.MedicalInsuranceNumber
  7051. // order.HosplistName = subItem.BaseDrugLib.DrugName
  7052. // order.HilistLv = "1"
  7053. // order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  7054. // order.HosplistCode = subItem.BaseDrugLib.MedicalInsuranceNumber
  7055. // order.HosplistName = subItem.BaseDrugLib.DrugName
  7056. // order.Cnt = fmt.Sprintf("%.2f", subItem.PrescribingNumber)
  7057. // order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  7058. // order.Sumamt = fmt.Sprintf("%.2f", (subItem.PrescribingNumber * subItem.Price))
  7059. // order.OwnpayAmt = ""
  7060. // order.SelfpayAmt = ""
  7061. // order.Spec = spec
  7062. // order.SpecUnt = subItem.PrescribingNumberUnit
  7063. // order.DrordBegnDate = s_tm
  7064. // order.DrordStopDate = ""
  7065. // order.DrordDrCodg = doctor_info.DoctorNumber
  7066. // order.DrordDeptName = department.Name
  7067. // order.DrordDeptCodg = department.Number
  7068. // order.DrordDrName = doctor_info.UserName
  7069. // order.DrordDrProfttl = "234"
  7070. // order.CurrDrordFlag = "1"
  7071. // orders = append(orders, &order)
  7072. // }
  7073. // for _, subItem := range item.HisPrescriptionProject {
  7074. // if subItem.Type == 2 {
  7075. // var order models.FsiOrderDtos
  7076. // order.RxID = strconv.FormatInt(item.ID, 10)
  7077. // order.Rxno = strconv.FormatInt(item.ID, 10)
  7078. // order.LongDrordFlag = "0"
  7079. // order.HilistType = "1"
  7080. // order.ChrgType = "1"
  7081. // order.DrordBhvr = "0"
  7082. // order.HilistCode = subItem.HisProject.MedicalCode
  7083. // order.HosplistName = subItem.HisProject.ProjectName
  7084. // order.HilistLv = "1"
  7085. // order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  7086. // order.HosplistCode = subItem.HisProject.MedicalCode
  7087. // order.HosplistName = subItem.HisProject.ProjectName
  7088. // order.Cnt = subItem.Count
  7089. // cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7090. // order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  7091. // order.Sumamt = fmt.Sprintf("%.2f", subItem.Price*cnt)
  7092. // order.OwnpayAmt = ""
  7093. // order.SelfpayAmt = ""
  7094. // order.Spec = subItem.Unit
  7095. // order.SpecUnt = subItem.Unit
  7096. // order.DrordBegnDate = s_tm
  7097. // order.DrordStopDate = ""
  7098. // order.DrordDrCodg = doctor_info.DoctorNumber
  7099. // order.DrordDeptName = department.Name
  7100. // order.DrordDeptCodg = department.Number
  7101. // order.DrordDrName = doctor_info.UserName
  7102. // order.DrordDrProfttl = "234"
  7103. // order.CurrDrordFlag = "1"
  7104. // orders = append(orders, &order)
  7105. //
  7106. // }
  7107. // if subItem.Type == 3 {
  7108. //
  7109. // var order models.FsiOrderDtos
  7110. // order.RxID = strconv.FormatInt(item.ID, 10)
  7111. // order.Rxno = strconv.FormatInt(item.ID, 10)
  7112. // order.LongDrordFlag = "0"
  7113. // order.HilistType = "1"
  7114. // order.ChrgType = "1"
  7115. // order.DrordBhvr = "0"
  7116. // order.HilistCode = subItem.GoodInfo.MedicalInsuranceNumber
  7117. // order.HosplistName = subItem.GoodInfo.GoodName
  7118. // order.HilistLv = "1"
  7119. // order.HilistPric = fmt.Sprintf("%.2f", subItem.Price)
  7120. // order.HosplistCode = subItem.GoodInfo.MedicalInsuranceNumber
  7121. // order.HosplistName = subItem.GoodInfo.GoodName
  7122. // order.Cnt = subItem.Count
  7123. // cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7124. // order.Pric = fmt.Sprintf("%.2f", subItem.Price)
  7125. // order.Sumamt = fmt.Sprintf("%.2f", subItem.Price*cnt)
  7126. // order.OwnpayAmt = ""
  7127. // order.SelfpayAmt = ""
  7128. // order.Spec = subItem.GoodInfo.SpecificationName
  7129. // order.SpecUnt = subItem.Unit
  7130. // order.DrordBegnDate = s_tm
  7131. // order.DrordStopDate = ""
  7132. // order.DrordDrCodg = doctor_info.DoctorNumber
  7133. // order.DrordDeptName = department.Name
  7134. // order.DrordDeptCodg = department.Number
  7135. // order.DrordDrName = doctor_info.UserName
  7136. // order.DrordDrProfttl = "234"
  7137. // order.CurrDrordFlag = "1"
  7138. // orders = append(orders, &order)
  7139. //
  7140. // }
  7141. // }
  7142. //}
  7143. //处方医嘱信息
  7144. fed.MatnStas = "0"
  7145. fed.MedfeeSumamt = fmt.Sprintf("%.2f", order.MedfeeSumamt)
  7146. fed.OwnpayAmt = fmt.Sprintf("%.2f", order.FulamtOwnpayAmt)
  7147. fed.SelfpayAmt = fmt.Sprintf("%.2f", order.PreselfpayAmt)
  7148. fed.AcctPayamt = fmt.Sprintf("%.2f", order.AcctPay)
  7149. fed.MaAmt = fmt.Sprintf("%.2f", order.MafPay)
  7150. fed.HifpPayamt = fmt.Sprintf("%.2f", order.HifpPay)
  7151. fed.SetlTotlnum = "1"
  7152. fed.Insutype = his.InsutypeType
  7153. fed.ReimFlag = "0"
  7154. fed.OutSetlFlag = "0"
  7155. var fopd []*models.FsiOperationDtosData
  7156. data := make(map[string]interface{})
  7157. data["fed"] = fed
  7158. data["fdd"] = fdds
  7159. data["fod"] = orders
  7160. data["pd"] = pd
  7161. data["pp"] = pp
  7162. data["fopd"] = fopd
  7163. data["trig_scen"] = trig_scen
  7164. client := &http.Client{}
  7165. bytesData, _ := json.Marshal(data)
  7166. var req *http.Request
  7167. if miConfig.MdtrtareaAdmvs == "320921" || miConfig.MdtrtareaAdmvs == "320982" {
  7168. if miConfig.MdtrtareaAdmvs == "320921" {
  7169. req, _ = http.NewRequest("POST", "http://192.168.2.3:9532/"+"jsyb/3102", bytes.NewReader(bytesData))
  7170. } else {
  7171. req, _ = http.NewRequest("POST", "http://192.168.5.251:9532/"+"jsyb/3102", bytes.NewReader(bytesData))
  7172. }
  7173. resp, _ := client.Do(req)
  7174. defer resp.Body.Close()
  7175. body, ioErr := ioutil.ReadAll(resp.Body)
  7176. if ioErr != nil {
  7177. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  7178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7179. return res
  7180. }
  7181. var respJSON map[string]interface{}
  7182. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  7183. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  7184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7185. return res
  7186. }
  7187. respJSON = respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  7188. result, _ := json.Marshal(respJSON)
  7189. if err := json.Unmarshal([]byte(result), &res); err != nil {
  7190. utils.ErrorLog("解析失败:%v", err)
  7191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7192. return res
  7193. }
  7194. return res
  7195. } else {
  7196. output, input := service.Gdyb3102(pd, fed, fdds, orders, fopd, pp, trig_scen)
  7197. saveLog(output, input, "3102", "事中")
  7198. if err := json.Unmarshal([]byte(output), &res); err != nil {
  7199. utils.ErrorLog("解析失败:%v", err)
  7200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7201. return
  7202. }
  7203. return res
  7204. }
  7205. return res
  7206. }