sz_his_api_controller.go 218KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097
  1. package sz
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "gdyb/controllers"
  6. "gdyb/enums"
  7. "gdyb/models"
  8. "gdyb/service"
  9. "gdyb/utils"
  10. "github.com/astaxie/beego"
  11. "github.com/axgle/mahonia"
  12. "math/rand"
  13. //"github.com/axgle/mahonia"
  14. "math"
  15. //"math/rand"µ
  16. "strconv"
  17. "strings"
  18. //"strings"
  19. "syscall"
  20. "time"
  21. "unsafe"
  22. )
  23. type Result struct {
  24. Transtime string `json:"transTime"`
  25. Transtype string `json:"transType"`
  26. Transreturncode string `json:"transReturnCode"`
  27. Transreturnmessage string `json:"transReturnMessage"`
  28. Transversion string `json:"transVersion"`
  29. Serialnumber string `json:"serialNumber"`
  30. Cardarea string `json:"cardArea"`
  31. Hospitalcode string `json:"hospitalCode"`
  32. Operatorcode string `json:"operatorCode"`
  33. Operatorname string `json:"operatorName"`
  34. Operatorpass string `json:"operatorPass"`
  35. Transbody struct {
  36. Akc190 string `json:"akc190"`
  37. Listsize int `json:"listsize"`
  38. Outputlist []struct {
  39. Aae072 string `json:"aae072"`
  40. Bkc369 string `json:"bkc369"`
  41. Bkf500 string `json:"bkf500"`
  42. Aka111 string `json:"aka111"`
  43. Ake001 string `json:"ake001"`
  44. Ake002 string `json:"ake002"`
  45. Bkm017 string `json:"bkm017"`
  46. Ake005 string `json:"ake005"`
  47. Ake006 string `json:"ake006"`
  48. Akc225 float64 `json:"akc225"`
  49. Akc226 float64 `json:"akc226"`
  50. Akc264 float64 `json:"akc264"`
  51. Aka065 string `json:"aka065"`
  52. Cka319 float64 `json:"cka319"`
  53. Akc268 float64 `json:"akc268"`
  54. } `json:"outputlist"`
  55. } `json:"transBody"`
  56. Verifycode string `json:"verifyCode"`
  57. Extenddeviceid string `json:"extendDeviceId"`
  58. Transchannel string `json:"transChannel"`
  59. Extenduserid string `json:"extendUserId"`
  60. Extendserialnumber string `json:"extendSerialNumber"`
  61. Caz055 string `json:"caz055"`
  62. Aae501 string `json:"aae501"`
  63. }
  64. type ResultOne struct {
  65. Transtime string `json:"transTime"`
  66. Transtype string `json:"transType"`
  67. Transreturncode string `json:"transReturnCode"`
  68. Transreturnmessage string `json:"transReturnMessage"`
  69. Transversion string `json:"transVersion"`
  70. Serialnumber string `json:"serialNumber"`
  71. Cardarea string `json:"cardArea"`
  72. Hospitalcode string `json:"hospitalCode"`
  73. Operatorcode string `json:"operatorCode"`
  74. Operatorname string `json:"operatorName"`
  75. Operatorpass string `json:"operatorPass"`
  76. Transbody struct {
  77. Ckc618 string `json:"ckc618"`
  78. Akc264 float64 `json:"akc264"`
  79. Akb068 int `json:"akb068"`
  80. Akb066 float64 `json:"akb066"`
  81. Akb067 int `json:"akb067"`
  82. Aae240 float64 `json:"aae240"`
  83. Outputlist []struct {
  84. Aaa036 string `json:"aaa036"`
  85. Aae019 float64 `json:"aae019"`
  86. } `json:"outputlist"`
  87. Outputlist2 []interface{} `json:"outputlist2"`
  88. } `json:"transBody"`
  89. Verifycode string `json:"verifyCode"`
  90. Extenddeviceid string `json:"extendDeviceId"`
  91. Transchannel string `json:"transChannel"`
  92. Extenduserid string `json:"extendUserId"`
  93. Extendserialnumber string `json:"extendSerialNumber"`
  94. Caz055 string `json:"caz055"`
  95. Aae501 string `json:"aae501"`
  96. }
  97. type ResultTwo struct {
  98. Transtime string `json:"transTime"`
  99. Transtype string `json:"transType"`
  100. Transreturncode string `json:"transReturnCode"`
  101. Transreturnmessage string `json:"transReturnMessage"`
  102. Transversion string `json:"transVersion"`
  103. Serialnumber string `json:"serialNumber"`
  104. Cardarea string `json:"cardArea"`
  105. Hospitalcode string `json:"hospitalCode"`
  106. Operatorcode string `json:"operatorCode"`
  107. Operatorname string `json:"operatorName"`
  108. Operatorpass string `json:"operatorPass"`
  109. Transbody struct {
  110. Ckc618 string `json:"ckc618"`
  111. Akc264 float64 `json:"akc264"`
  112. Akb068 float64 `json:"akb068"`
  113. Akb066 float64 `json:"akb066"`
  114. Akb067 float64 `json:"akb067"`
  115. Aae240 float64 `json:"aae240"`
  116. Outputlist1 []struct {
  117. Aka111 string `json:"aka111"`
  118. Bka058 float64 `json:"bka058"`
  119. } `json:"outputlist1"`
  120. Outputlist2 []struct {
  121. Aaa036 string `json:"aaa036"`
  122. Aae019 float64 `json:"aae019"`
  123. } `json:"outputlist2"`
  124. Outputlist3 []interface{} `json:"outputlist3"`
  125. } `json:"transBody"`
  126. Verifycode string `json:"verifyCode"`
  127. Extenddeviceid string `json:"extendDeviceId"`
  128. Transchannel string `json:"transChannel"`
  129. Extenduserid string `json:"extendUserId"`
  130. Extendserialnumber string `json:"extendSerialNumber"`
  131. Caz055 string `json:"caz055"`
  132. Aae501 string `json:"aae501"`
  133. }
  134. type ResultThree struct {
  135. Transtime string `json:"transTime"`
  136. Transtype string `json:"transType"`
  137. Transreturncode string `json:"transReturnCode"`
  138. Transreturnmessage string `json:"transReturnMessage"`
  139. Transversion string `json:"transVersion"`
  140. Serialnumber string `json:"serialNumber"`
  141. Cardarea string `json:"cardArea"`
  142. Hospitalcode string `json:"hospitalCode"`
  143. Operatorcode string `json:"operatorCode"`
  144. Operatorname string `json:"operatorName"`
  145. Operatorpass string `json:"operatorPass"`
  146. Transbody struct {
  147. Baz700 string `json:"baz700"`
  148. Ckc618 string `json:"ckc618"`
  149. } `json:"transBody"`
  150. Verifycode string `json:"verifyCode"`
  151. Extenddeviceid string `json:"extendDeviceId"`
  152. Transchannel string `json:"transChannel"`
  153. Extenduserid string `json:"extendUserId"`
  154. Extendserialnumber string `json:"extendSerialNumber"`
  155. Caz055 string `json:"caz055"`
  156. Aae501 string `json:"aae501"`
  157. }
  158. type ResultFive struct {
  159. Transtime string `json:"transTime"`
  160. Transtype string `json:"transType"`
  161. Transreturncode string `json:"transReturnCode"`
  162. Transreturnmessage string `json:"transReturnMessage"`
  163. Transversion string `json:"transVersion"`
  164. Serialnumber string `json:"serialNumber"`
  165. Cardarea string `json:"cardArea"`
  166. Hospitalcode string `json:"hospitalCode"`
  167. Operatorcode string `json:"operatorCode"`
  168. Operatorname string `json:"operatorName"`
  169. Operatorpass string `json:"operatorPass"`
  170. Transbody struct {
  171. Akc190 string `json:"akc190"`
  172. Listsize int `json:"listsize"`
  173. Outputlist []struct {
  174. Aae072 string `json:"aae072"`
  175. Bkf500 string `json:"bkf500"`
  176. Baz700 string `json:"baz700"`
  177. Bce574 string `json:"bce574"`
  178. } `json:"outputlist"`
  179. } `json:"transBody"`
  180. Verifycode string `json:"verifyCode"`
  181. Extenddeviceid string `json:"extendDeviceId"`
  182. Transchannel string `json:"transChannel"`
  183. Extenduserid string `json:"extendUserId"`
  184. Extendserialnumber string `json:"extendSerialNumber"`
  185. Caz055 string `json:"caz055"`
  186. Aae501 string `json:"aae501"`
  187. }
  188. type ResultFour struct {
  189. Transtime string `json:"transTime"`
  190. Transtype string `json:"transType"`
  191. Transreturncode string `json:"transReturnCode"`
  192. Transreturnmessage string `json:"transReturnMessage"`
  193. Transversion string `json:"transVersion"`
  194. Serialnumber string `json:"serialNumber"`
  195. Cardarea string `json:"cardArea"`
  196. Hospitalcode string `json:"hospitalCode"`
  197. Operatorcode string `json:"operatorCode"`
  198. Operatorname string `json:"operatorName"`
  199. Operatorpass string `json:"operatorPass"`
  200. Transbody struct {
  201. Akc190 string `json:"akc190"`
  202. Akc194 int `json:"akc194"`
  203. Bae917 int64 `json:"bae917"`
  204. Aka018 string `json:"aka018"`
  205. Aka030 string `json:"aka030"`
  206. Ckc618 string `json:"ckc618"`
  207. Akc264 float64 `json:"akc264"`
  208. Akb068 float64 `json:"akb068"`
  209. Akb066 float64 `json:"akb066"`
  210. Akb067 float64 `json:"akb067"`
  211. Cke298 float64 `json:"cke298"`
  212. Aae240 float64 `json:"aae240"`
  213. Outputlist1 []struct {
  214. Aae072 string `json:"aae072"`
  215. Bkc369 string `json:"bkc369"`
  216. Bkf500 string `json:"bkf500"`
  217. Aka111 string `json:"aka111"`
  218. Ake001 string `json:"ake001"`
  219. Ake002 string `json:"ake002"`
  220. Bkm017 string `json:"bkm017"`
  221. Ake005 string `json:"ake005"`
  222. Ake006 string `json:"ake006"`
  223. Ala026 string `json:"ala026"`
  224. Aka070 string `json:"aka070"`
  225. Aka074 string `json:"aka074"`
  226. Akc226 float64 `json:"akc226"`
  227. Akc225 float64 `json:"akc225"`
  228. Akc264 float64 `json:"akc264"`
  229. Aka067 string `json:"aka067"`
  230. Akc271 int `json:"akc271"`
  231. Bkc320 string `json:"bkc320"`
  232. Cke400 string `json:"cke400"`
  233. Ckc618 string `json:"ckc618"`
  234. Bka069 int64 `json:"bka069"`
  235. Aka018 string `json:"aka018"`
  236. Aka030 string `json:"aka030"`
  237. Aka065 string `json:"aka065"`
  238. Cka319 float64 `json:"cka319"`
  239. Akc268 float64 `json:"akc268"`
  240. } `json:"outputlist1"`
  241. Outputlist2 []struct {
  242. Aka111 string `json:"aka111"`
  243. Bka058 float64 `json:"bka058"`
  244. } `json:"outputlist2"`
  245. Outputlist3 []struct {
  246. Aaa036 string `json:"aaa036"`
  247. Aae019 float64 `json:"aae019"`
  248. } `json:"outputlist3"`
  249. } `json:"transBody"`
  250. Verifycode string `json:"verifyCode"`
  251. Extenddeviceid string `json:"extendDeviceId"`
  252. Transchannel string `json:"transChannel"`
  253. Extenduserid string `json:"extendUserId"`
  254. Extendserialnumber string `json:"extendSerialNumber"`
  255. Caz055 string `json:"caz055"`
  256. Aae501 string `json:"aae501"`
  257. }
  258. type ResultMZ001 struct {
  259. Transtime string `json:"transTime"`
  260. Transtype string `json:"transType"`
  261. Transreturncode string `json:"transReturnCode"`
  262. Transreturnmessage string `json:"transReturnMessage"`
  263. Transversion string `json:"transVersion"`
  264. Serialnumber string `json:"serialNumber"`
  265. Cardarea string `json:"cardArea"`
  266. Hospitalcode string `json:"hospitalCode"`
  267. Operatorcode string `json:"operatorCode"`
  268. Operatorname string `json:"operatorName"`
  269. Operatorpass string `json:"operatorPass"`
  270. Transbody struct {
  271. Aaz515 string `json:"aaz515"`
  272. Aaz500 string `json:"aaz500"`
  273. Aac001 float64 `json:"aac001"`
  274. Aac999 string `json:"aac999"`
  275. Aac002 string `json:"aac002"`
  276. Aac058 string `json:"aac058"`
  277. Aac147 string `json:"aac147"`
  278. Aac003 string `json:"aac003"`
  279. Aac004 string `json:"aac004"`
  280. Aac006 float64 `json:"aac006"`
  281. Bae093 float64 `json:"bae093"`
  282. Cac215 string `json:"cac215"`
  283. Aac066 string `json:"aac066"`
  284. Aac008 string `json:"aac008"`
  285. Bke404 string `json:"bke404"`
  286. Aae240 float64 `json:"aae240"`
  287. Bkc346 string `json:"bkc346"`
  288. Ckc601 string `json:"ckc601"`
  289. Caz574 string `json:"caz574"`
  290. Caz654 string `json:"caz654"`
  291. Ckc403 string `json:"ckc403"`
  292. Ckc362 string `json:"ckc362"`
  293. Ckc363 string `json:"ckc363"`
  294. Outputlist1 []struct {
  295. Aab001 float64 `json:"aab001"`
  296. Aab999 string `json:"aab999"`
  297. Aab004 string `json:"aab004"`
  298. Aab019 string `json:"aab019"`
  299. Aae140 string `json:"aae140"`
  300. Aae030 float64 `json:"aae030"`
  301. Aae031 string `json:"aae031"`
  302. Bcc334 string `json:"bcc334"`
  303. Aac031 string `json:"aac031"`
  304. } `json:"outputlist1"`
  305. } `json:"transBody"`
  306. Verifycode string `json:"verifyCode"`
  307. Extenddeviceid string `json:"extendDeviceId"`
  308. Transchannel string `json:"transChannel"`
  309. Extenduserid string `json:"extendUserId"`
  310. Extendserialnumber string `json:"extendSerialNumber"`
  311. Caz055 string `json:"caz055"`
  312. Aae501 string `json:"aae501"`
  313. }
  314. type SZHisApiController struct {
  315. controllers.BaseAuthAPIController
  316. }
  317. func SZHisManagerApiRegistRouters() {
  318. //挂号
  319. beego.Router("/sz/api/register/get", &SZHisApiController{}, "get:GetRegisterInfo")
  320. //结算
  321. beego.Router("/sz/api/settle/get", &SZHisApiController{}, "get:GetSettleInfo")
  322. //预结算
  323. beego.Router("/sz/api/presettle/get", &SZHisApiController{}, "get:GetPreSettleInfo")
  324. //退费
  325. beego.Router("/sz/api/refund/get", &SZHisApiController{}, "get:Refund")
  326. beego.Router("/sz/api/readcard", &SZHisApiController{}, "get:ReadCard")
  327. beego.Router("sz/api/refundnumber/get", &SZHisApiController{}, "get:RefundNumber")
  328. beego.Router("/sz/api/monthrefund/get", &SZHisApiController{}, "get:MonthRefund")
  329. //查询交易
  330. beego.Router("/sz/api/settle/query", &SZHisApiController{}, "get:GetSettleAccounts")
  331. //beego.Router("/sz/api/detail/upload", &SZHisApiController{}, "get:GetUploadDetail")
  332. beego.Router("/sz/api/detail/cancel", &SZHisApiController{}, "get:CancelOrderDetail")
  333. //
  334. ////机构药品目录备案
  335. beego.Router("/sz/api/drug/get", &SZHisApiController{}, "get:GetDrugList")
  336. ////协议机构诊疗项目
  337. beego.Router("/sz/api/treatment/get", &SZHisApiController{}, "get:GetTreatmentProject")
  338. ////协议机构目录备案撤销
  339. beego.Router("/sz/api/revocation/get", &SZHisApiController{}, "get:GetRevocation")
  340. //
  341. ////定点机构约定信息查询
  342. //beego.Router("/sz/api/information/query/get",&SZHisApiController{},"get:GetInformationQuery")
  343. ////-医药师信息登记
  344. beego.Router("/sz/api/doctor/get", &SZHisApiController{}, "get:GetDoctorList")
  345. ////医药师执业状态变更
  346. beego.Router("/sz/api/medical/get", &SZHisApiController{}, "get:GetMedicalList")
  347. ////医药师信息更新
  348. //beego.Router("/sz/api/update/medical/get", &SZHisApiController{}, "get:GetUpdateMedicalList")
  349. ////协议机构材料目录备案
  350. //
  351. beego.Router("/sz/api/goods/get", &SZHisApiController{}, "get:GetGoodsList")
  352. }
  353. func IntPtr(n int) uintptr {
  354. return uintptr(n)
  355. }
  356. func StrPtr(s string) uintptr {
  357. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  358. }
  359. type Custom struct {
  360. DetItemFeeSumamt string
  361. Cut string
  362. FeedetlSn string
  363. Price string
  364. MedListCodg string
  365. Type int64
  366. AdviceId int64
  367. ProjectId int64
  368. ItemId int64
  369. }
  370. func (c *SZHisApiController) ReadCard() {
  371. id_card_type, _ := c.GetInt64("id_card_type")
  372. adminInfo := c.GetAdminUserInfo()
  373. if id_card_type != 1 {
  374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorNoReadCardException)
  375. return
  376. }
  377. month := time.Unix(1557042972, 0).Format("1")
  378. year := time.Now().Format("2006")
  379. month = time.Now().Format("01")
  380. day := time.Now().Format("02")
  381. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  382. number := miConfig.Code + year + month + day +
  383. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  384. id_card_number, health_card_no, _, ret4 := ReadBasCard("MZ002" + "|" + number + "|" + miConfig.Code + "|")
  385. if ret4 == 0 {
  386. patient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  387. if patient.ID == 0 {
  388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  389. return
  390. } else {
  391. c.ServeSuccessJSON(map[string]interface{}{
  392. "patient": patient,
  393. "health_card_no": health_card_no,
  394. })
  395. }
  396. } else {
  397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  398. return
  399. }
  400. }
  401. //获取读卡信息 -- 门诊挂号
  402. //func (c *SZHisApiController) GetRegisterInfo() {
  403. // adminInfo := c.GetAdminUserInfo()
  404. // admin_user_id, _ := c.GetInt64("admin_user_id")
  405. // patient_id, _ := c.GetInt64("id")
  406. // record_time := c.GetString("record_time")
  407. // settlementValue, _ := c.GetInt64("settlement_value")
  408. // medical_insurance_card := c.GetString("medical_insurance_card")
  409. // name := c.GetString("name")
  410. // id_card_type, _ := c.GetInt64("id_card_type")
  411. // certificates, _ := c.GetInt64("certificates")
  412. // medical_care, _ := c.GetInt64("medical_care")
  413. // birthday := c.GetString("birthday")
  414. // id_card := c.GetString("id_card")
  415. // register_type, _ := c.GetInt64("register")
  416. // doctor, _ := c.GetInt64("doctor")
  417. // department, _ := c.GetInt64("department")
  418. // gender, _ := c.GetInt64("sex")
  419. // registration_fee, _ := c.GetFloat("registration_fee")
  420. // medical_expenses, _ := c.GetFloat("medical_expenses")
  421. // social_type, _ := c.GetInt64("social_type")
  422. //
  423. // is_yidi, _ := c.GetInt64("is_yidi")
  424. //
  425. // timeLayout := "2006-01-02"
  426. // loc, _ := time.LoadLocation("Local")
  427. // birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  428. // birthUnix := birthdays.Unix()
  429. //
  430. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  431. // if err != nil {
  432. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  433. // return
  434. // }
  435. //
  436. // var patient service.Patients
  437. // if patient_id == 0 {
  438. // patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  439. // } else {
  440. // patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  441. // }
  442. //
  443. // miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  444. // if patient.ID == 0 {
  445. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  446. // return
  447. // }
  448. // if len(patient.IdCardNo) == 0 {
  449. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  450. // return
  451. // }
  452. //
  453. // adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  454. // his, _ := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient_id, theTime.Unix())
  455. //
  456. // var custom_code string
  457. // var custom_project_name string
  458. // var allPrice float64
  459. //
  460. // switch register_type {
  461. // case 1:
  462. // custom_code = "110100002"
  463. // custom_project_name = "普通门诊"
  464. // allPrice = 10
  465. // break
  466. // case 3:
  467. // custom_code = "110200002-2"
  468. // custom_project_name = "主任医师"
  469. // allPrice = 10
  470. //
  471. // break
  472. // case 2:
  473. // custom_code = "110200002-3"
  474. // custom_project_name = "副主任医师"
  475. // allPrice = 10
  476. //
  477. // break
  478. // case 4:
  479. // custom_code = "0"
  480. // custom_project_name = "免受诊金"
  481. // allPrice = 0
  482. // break
  483. // case 5:
  484. // custom_code = "110200002-1"
  485. // custom_project_name = "专家"
  486. // allPrice = 10
  487. //
  488. // break
  489. // }
  490. //
  491. // if his.ID == 0 {
  492. //
  493. // var doctor_name string
  494. // var doctor_code string
  495. // if adminRole.ID == 0 {
  496. //
  497. // doctor_name = ""
  498. // doctor_code = "1001"
  499. // doctor_name = ""
  500. // doctor_code = ""
  501. //
  502. // } else {
  503. // doctor_name = adminRole.UserName
  504. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  505. //
  506. // }
  507. // month := time.Unix(1557042972, 0).Format("1")
  508. // year := time.Now().Format("2006")
  509. // month = time.Now().Format("01")
  510. // day := time.Now().Format("02")
  511. //
  512. // //流水号
  513. // //
  514. // number := miConfig.Code + year + month + day +
  515. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  516. // mz_number := year + month + day + strconv.FormatInt(patient_id, 10) +
  517. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000))
  518. // //1.判断读卡类型
  519. // //2.读卡 获取交易验证码,医疗证号,发卡地区行政区划代码
  520. // yiliao_number, id_card_number, verifyCode, version_code, _, ret4 := ReadBasCardGetNumber("MZ002" + "|" + number + "|" + miConfig.Code + "|")
  521. // fmt.Println(yiliao_number)
  522. // fmt.Println(id_card_number)
  523. // fmt.Println(verifyCode)
  524. // fmt.Println(version_code)
  525. // fmt.Println(ret4)
  526. //
  527. // dept_code := "0305"
  528. // is_yidi = 1
  529. // tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  530. // //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  531. // if tempPatient.ID == patient_id {
  532. // if ret4 == 0 { //本地卡流程
  533. // if is_yidi == 1 {
  534. // //本地就医流程
  535. // //挂号
  536. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, dept_code, yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice,medical_care)
  537. // var dat map[string]interface{}
  538. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  539. // fmt.Println(dat)
  540. // } else {
  541. // fmt.Println(err)
  542. // }
  543. // userJSONBytes, _ := json.Marshal(dat)
  544. // var res ResultOne
  545. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  546. // utils.ErrorLog("解析失败:%v", err)
  547. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  548. // return
  549. // }
  550. // if res.Transreturncode == "00000000" {
  551. // his := models.VMHisPatient{
  552. // Name: name,
  553. // Gender: gender,
  554. // Birthday: birthUnix,
  555. // MedicalTreatmentType: medical_care,
  556. // IdType: certificates,
  557. // IdCardNo: id_card,
  558. // BalanceAccountsType: settlementValue,
  559. // SocialType: social_type,
  560. // MedicalInsuranceNumber: medical_insurance_card,
  561. // RegisterType: register_type,
  562. // RegisterCost: registration_fee,
  563. // TreatmentCost: medical_expenses,
  564. // Status: 1,
  565. // Ctime: time.Now().Unix(),
  566. // Mtime: time.Now().Unix(),
  567. // Iinfo: resp_result,
  568. // PatientId: patient.ID,
  569. // RecordDate: theTime.Unix(),
  570. // UserOrgId: adminInfo.CurrentOrgId,
  571. // AdminUserId: admin_user_id,
  572. // IsReturn: 1,
  573. // IdCardType: id_card_type,
  574. // Doctor: doctor,
  575. // Departments: department,
  576. // YiliaoNumber: yiliao_number,
  577. // MzNumber: number,
  578. // Number: mz_number,
  579. // }
  580. // service.CreateHisPatientTwo(&his)
  581. // c.ServeSuccessJSON(map[string]interface{}{
  582. // "msg": "挂号成功",
  583. // })
  584. // } else {
  585. // c.ServeSuccessJSON(map[string]interface{}{
  586. // "failed_code": -10,
  587. // "msg": res.Transreturnmessage,
  588. // })
  589. // return
  590. // }
  591. //
  592. // } else {
  593. // //异地就医流程
  594. // //异地走鉴权流程
  595. // //authResult := CardAuth(number)
  596. // //fmt.Println(authResult)
  597. //
  598. // //tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  599. // //if tempPatient.ID == patient_id {
  600. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice)
  601. // var dat map[string]interface{}
  602. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  603. // fmt.Println(dat)
  604. // } else {
  605. // fmt.Println(err)
  606. // }
  607. //
  608. // userJSONBytes, _ := json.Marshal(dat)
  609. //
  610. // var res ResultOne
  611. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  612. // utils.ErrorLog("解析失败:%v", err)
  613. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  614. // return
  615. // }
  616. // if res.Transreturncode == "00000000" {
  617. // his := models.VMHisPatient{
  618. // Name: name,
  619. // Gender: gender,
  620. // Birthday: birthUnix,
  621. // MedicalTreatmentType: medical_care,
  622. // IdType: certificates,
  623. // IdCardNo: id_card,
  624. // BalanceAccountsType: settlementValue,
  625. // SocialType: social_type,
  626. // MedicalInsuranceNumber: medical_insurance_card,
  627. // RegisterType: register_type,
  628. // RegisterCost: registration_fee,
  629. // TreatmentCost: medical_expenses,
  630. // Status: 1,
  631. // Ctime: time.Now().Unix(),
  632. // Mtime: time.Now().Unix(),
  633. // Iinfo: resp_result,
  634. // PatientId: patient.ID,
  635. // RecordDate: theTime.Unix(),
  636. // UserOrgId: adminInfo.CurrentOrgId,
  637. // AdminUserId: admin_user_id,
  638. // IsReturn: 1,
  639. // IdCardType: id_card_type,
  640. // Doctor: doctor,
  641. // Departments: department,
  642. // YiliaoNumber: yiliao_number,
  643. // MzNumber: number,
  644. // Number: mz_number,
  645. // }
  646. // service.CreateHisPatientTwo(&his)
  647. // c.ServeSuccessJSON(map[string]interface{}{
  648. // "msg": "挂号成功",
  649. // })
  650. // } else {
  651. // c.ServeSuccessJSON(map[string]interface{}{
  652. // "failed_code": -10,
  653. // "msg": res.Transreturnmessage,
  654. // })
  655. // return
  656. // }
  657. //
  658. // }
  659. //
  660. // } else { //异地卡流程
  661. // //readCardBasResult := ReadCardBasHSM(number)
  662. // //fmt.Println(readCardBasResult)
  663. // //是否异地就医,是的话走鉴权流程,不是的话走门诊挂号
  664. // if is_yidi == 1 { //1本地就医
  665. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice)
  666. // var dat map[string]interface{}
  667. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  668. // fmt.Println(dat)
  669. // } else {
  670. // fmt.Println(err)
  671. // }
  672. //
  673. // userJSONBytes, _ := json.Marshal(dat)
  674. //
  675. // var res ResultOne
  676. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  677. // utils.ErrorLog("解析失败:%v", err)
  678. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  679. // return
  680. // }
  681. // if res.Transreturncode == "00000000" {
  682. // his := models.VMHisPatient{
  683. // Name: name,
  684. // Gender: gender,
  685. // Birthday: birthUnix,
  686. // MedicalTreatmentType: medical_care,
  687. // IdType: certificates,
  688. // IdCardNo: id_card,
  689. // BalanceAccountsType: settlementValue,
  690. // SocialType: social_type,
  691. // MedicalInsuranceNumber: medical_insurance_card,
  692. // RegisterType: register_type,
  693. // RegisterCost: registration_fee,
  694. // TreatmentCost: medical_expenses,
  695. // Status: 1,
  696. // Ctime: time.Now().Unix(),
  697. // Mtime: time.Now().Unix(),
  698. // Iinfo: resp_result,
  699. // PatientId: patient.ID,
  700. // RecordDate: theTime.Unix(),
  701. // UserOrgId: adminInfo.CurrentOrgId,
  702. // AdminUserId: admin_user_id,
  703. // IsReturn: 1,
  704. // IdCardType: id_card_type,
  705. // Doctor: doctor,
  706. // Departments: department,
  707. // YiliaoNumber: yiliao_number,
  708. // MzNumber: number,
  709. // Number: mz_number,
  710. // }
  711. // service.CreateHisPatientTwo(&his)
  712. // c.ServeSuccessJSON(map[string]interface{}{
  713. // "msg": "挂号成功",
  714. // })
  715. // } else {
  716. // c.ServeSuccessJSON(map[string]interface{}{
  717. // "failed_code": -10,
  718. // "msg": res.Transreturnmessage,
  719. // })
  720. // return
  721. // }
  722. //
  723. // } else { //异地就医需要走鉴权流程
  724. // //authResult := CardAuth(number)
  725. // //fmt.Println(authResult)
  726. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice)
  727. // var dat map[string]interface{}
  728. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  729. // fmt.Println(dat)
  730. // } else {
  731. // fmt.Println(err)
  732. // }
  733. //
  734. // userJSONBytes, _ := json.Marshal(dat)
  735. //
  736. // var res ResultOne
  737. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  738. // utils.ErrorLog("解析失败:%v", err)
  739. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  740. // return
  741. // }
  742. // if res.Transreturncode == "00000000" {
  743. // his := models.VMHisPatient{
  744. // Name: name,
  745. // Gender: gender,
  746. // Birthday: birthUnix,
  747. // MedicalTreatmentType: medical_care,
  748. // IdType: certificates,
  749. // IdCardNo: id_card,
  750. // BalanceAccountsType: settlementValue,
  751. // SocialType: social_type,
  752. // MedicalInsuranceNumber: medical_insurance_card,
  753. // RegisterType: register_type,
  754. // RegisterCost: registration_fee,
  755. // TreatmentCost: medical_expenses,
  756. // Status: 1,
  757. // Ctime: time.Now().Unix(),
  758. // Mtime: time.Now().Unix(),
  759. // Iinfo: resp_result,
  760. // PatientId: patient.ID,
  761. // RecordDate: theTime.Unix(),
  762. // UserOrgId: adminInfo.CurrentOrgId,
  763. // AdminUserId: admin_user_id,
  764. // IsReturn: 1,
  765. // IdCardType: id_card_type,
  766. // Doctor: doctor,
  767. // Departments: department,
  768. // YiliaoNumber: yiliao_number,
  769. // MzNumber: number,
  770. // Number: mz_number,
  771. // }
  772. // service.CreateHisPatientTwo(&his)
  773. // c.ServeSuccessJSON(map[string]interface{}{
  774. // "msg": "挂号成功",
  775. // })
  776. // } else {
  777. // c.ServeSuccessJSON(map[string]interface{}{
  778. // "failed_code": -10,
  779. // "msg": res.Transreturnmessage,
  780. // })
  781. // return
  782. // }
  783. //
  784. // }
  785. // }
  786. // } else {
  787. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  788. // return
  789. // }
  790. // } else {
  791. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  792. // return
  793. // }
  794. //}
  795. func (c *SZHisApiController) GetRegisterInfo() {
  796. adminInfo := c.GetAdminUserInfo()
  797. admin_user_id, _ := c.GetInt64("admin_user_id")
  798. patient_id, _ := c.GetInt64("id")
  799. record_time := c.GetString("record_time")
  800. settlementValue, _ := c.GetInt64("settlement_value")
  801. medical_insurance_card := c.GetString("medical_insurance_card")
  802. name := c.GetString("name")
  803. id_card_type, _ := c.GetInt64("id_card_type")
  804. certificates, _ := c.GetInt64("certificates")
  805. medical_care, _ := c.GetInt64("medical_care")
  806. birthday := c.GetString("birthday")
  807. id_card := c.GetString("id_card")
  808. register_type, _ := c.GetInt64("register")
  809. doctor, _ := c.GetInt64("doctor")
  810. department, _ := c.GetInt64("department")
  811. gender, _ := c.GetInt64("sex")
  812. registration_fee, _ := c.GetFloat("registration_fee")
  813. medical_expenses, _ := c.GetFloat("medical_expenses")
  814. social_type, _ := c.GetInt64("social_type")
  815. is_yidi, _ := c.GetInt64("is_yidi")
  816. timeLayout := "2006-01-02"
  817. loc, _ := time.LoadLocation("Local")
  818. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  819. birthUnix := birthdays.Unix()
  820. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  821. if err != nil {
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  823. return
  824. }
  825. var patient service.Patients
  826. if patient_id == 0 {
  827. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  828. } else {
  829. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  830. }
  831. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  832. if patient.ID == 0 {
  833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  834. return
  835. }
  836. if len(patient.IdCardNo) == 0 {
  837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  838. return
  839. }
  840. //doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor)
  841. doctorDepartment, _ := service.GetDepartMentDetail(department)
  842. adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  843. //his, _ := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient_id, theTime.Unix())
  844. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, theTime.Unix())
  845. if len(his) >= 1 {
  846. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, theTime.Unix())
  847. if len(his) >= 1 && order.ID == 0 {
  848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  849. return
  850. }
  851. }
  852. var custom_code string
  853. var custom_project_name string
  854. var allPrice float64
  855. switch register_type {
  856. case 1:
  857. custom_code = "110100002"
  858. custom_project_name = "普通门诊"
  859. allPrice = 10
  860. break
  861. case 3:
  862. custom_code = "110200002-2"
  863. custom_project_name = "主任医师"
  864. allPrice = 10
  865. break
  866. case 2:
  867. custom_code = "110200002-3"
  868. custom_project_name = "副主任医师"
  869. allPrice = 10
  870. break
  871. case 4:
  872. custom_code = "0"
  873. custom_project_name = "免受诊金"
  874. allPrice = 0
  875. break
  876. case 5:
  877. custom_code = "110200002-1"
  878. custom_project_name = "专家"
  879. allPrice = 10
  880. break
  881. }
  882. var opera_name string
  883. var opera_code string
  884. if adminRole.ID == 0 {
  885. opera_name = "管理员"
  886. opera_code = "01"
  887. } else {
  888. opera_name = adminRole.UserName
  889. opera_code = strconv.FormatInt(admin_user_id, 10)
  890. }
  891. month := time.Unix(1557042972, 0).Format("1")
  892. year := time.Now().Format("2006")
  893. month = time.Now().Format("01")
  894. day := time.Now().Format("02")
  895. //流水号
  896. number := miConfig.Code + year + month + day +
  897. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  898. mz_number := miConfig.Code + year + month + day +
  899. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000))
  900. //1.判断读卡类型
  901. //2.读卡 获取交易验证码,医疗证号,发卡地区行政区划代码
  902. yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("MZ002" + "|" + number + "|" + miConfig.Code + "|")
  903. dept_code := doctorDepartment.Number
  904. is_yidi = 1
  905. tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  906. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  907. fmt.Println(tempPatient.ID)
  908. fmt.Println(patient_id)
  909. if tempPatient.ID == patient_id {
  910. temp_mz_number := miConfig.Code + year + month + day +
  911. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000))
  912. tempVerifyCode, tempVersionCode := ReadCardGetCode("XX001" + "|" + temp_mz_number + "|" + miConfig.Code)
  913. //yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("MZ002" + "|" + number + "|" + miConfig.Code + "|")
  914. //yiliao_number = "%GALMAFXJGKUKZNKWAIUH?;07857319025346309758?"
  915. result001 := service.SzybXX001(opera_name, opera_code, miConfig.Code, yiliao_number, tempVerifyCode, temp_mz_number, tempVersionCode)
  916. if ret4 == 0 { //本地卡流程
  917. if is_yidi == 1 {
  918. //var dat2 map[string]interface{}
  919. //if err := json.Unmarshal([]byte(result001), &dat2); err == nil {
  920. // fmt.Println(dat2)
  921. //} else {
  922. // fmt.Println(err)
  923. //}
  924. //userJSONBytes2, _ := json.Marshal(dat2)
  925. //var res2 ResultMZ001
  926. //if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  927. // utils.ErrorLog("解析失败:%v", err)
  928. //}
  929. //本地就医流程
  930. //挂号
  931. resp_result := service.SzybMZ002(opera_name, opera_code, miConfig.Code, dept_code, yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  932. var dat map[string]interface{}
  933. if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  934. fmt.Println(dat)
  935. } else {
  936. fmt.Println(err)
  937. }
  938. userJSONBytes, _ := json.Marshal(dat)
  939. var res ResultOne
  940. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  941. utils.ErrorLog("解析失败:%v", err)
  942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  943. return
  944. }
  945. if res.Transreturncode == "00000000" {
  946. his := models.VMHisPatient{
  947. Name: name,
  948. Gender: gender,
  949. Birthday: birthUnix,
  950. MedicalTreatmentType: medical_care,
  951. IdType: certificates,
  952. IdCardNo: id_card,
  953. BalanceAccountsType: settlementValue,
  954. SocialType: social_type,
  955. MedicalInsuranceNumber: medical_insurance_card,
  956. RegisterType: register_type,
  957. RegisterCost: registration_fee,
  958. TreatmentCost: medical_expenses,
  959. Status: 1,
  960. Ctime: time.Now().Unix(),
  961. Mtime: time.Now().Unix(),
  962. Iinfo: resp_result,
  963. PatientId: patient.ID,
  964. RecordDate: theTime.Unix(),
  965. UserOrgId: adminInfo.CurrentOrgId,
  966. AdminUserId: admin_user_id,
  967. IsReturn: 1,
  968. IdCardType: id_card_type,
  969. Doctor: doctor,
  970. Departments: department,
  971. YiliaoNumber: yiliao_number,
  972. MzNumber: number,
  973. Number: mz_number,
  974. PsnNo: health_card_no,
  975. PatientInfo: result001,
  976. }
  977. service.CreateHisPatientTwo(&his)
  978. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, theTime.Unix())
  979. if len(lists) == 1 {
  980. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, theTime.Unix(), adminInfo.CurrentOrgId)
  981. }
  982. c.ServeSuccessJSON(map[string]interface{}{
  983. "msg": "挂号成功",
  984. })
  985. } else {
  986. c.ServeSuccessJSON(map[string]interface{}{
  987. "failed_code": -10,
  988. "msg": res.Transreturnmessage,
  989. })
  990. return
  991. }
  992. } else {
  993. //异地就医流程
  994. //异地走鉴权流程
  995. //authResult := CardAuth(number)
  996. //fmt.Println(authResult)
  997. //tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  998. //if tempPatient.ID == patient_id {
  999. resp_result := service.SzybMZ002(opera_name, opera_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  1000. var dat map[string]interface{}
  1001. if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1002. fmt.Println(dat)
  1003. } else {
  1004. fmt.Println(err)
  1005. }
  1006. userJSONBytes, _ := json.Marshal(dat)
  1007. var res ResultOne
  1008. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1009. utils.ErrorLog("解析失败:%v", err)
  1010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1011. return
  1012. }
  1013. if res.Transreturncode == "00000000" {
  1014. his := models.VMHisPatient{
  1015. Name: name,
  1016. Gender: gender,
  1017. Birthday: birthUnix,
  1018. MedicalTreatmentType: medical_care,
  1019. IdType: certificates,
  1020. IdCardNo: id_card,
  1021. BalanceAccountsType: settlementValue,
  1022. SocialType: social_type,
  1023. MedicalInsuranceNumber: medical_insurance_card,
  1024. RegisterType: register_type,
  1025. RegisterCost: registration_fee,
  1026. TreatmentCost: medical_expenses,
  1027. Status: 1,
  1028. Ctime: time.Now().Unix(),
  1029. Mtime: time.Now().Unix(),
  1030. Iinfo: resp_result,
  1031. PatientId: patient.ID,
  1032. RecordDate: theTime.Unix(),
  1033. UserOrgId: adminInfo.CurrentOrgId,
  1034. AdminUserId: admin_user_id,
  1035. IsReturn: 1,
  1036. IdCardType: id_card_type,
  1037. Doctor: doctor,
  1038. Departments: department,
  1039. YiliaoNumber: yiliao_number,
  1040. MzNumber: number,
  1041. Number: mz_number,
  1042. PsnNo: health_card_no,
  1043. PatientInfo: result001,
  1044. }
  1045. service.CreateHisPatientTwo(&his)
  1046. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, theTime.Unix())
  1047. if len(lists) == 1 {
  1048. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, theTime.Unix(), adminInfo.CurrentOrgId)
  1049. }
  1050. c.ServeSuccessJSON(map[string]interface{}{
  1051. "msg": "挂号成功",
  1052. })
  1053. } else {
  1054. c.ServeSuccessJSON(map[string]interface{}{
  1055. "failed_code": -10,
  1056. "msg": res.Transreturnmessage,
  1057. })
  1058. return
  1059. }
  1060. }
  1061. } else { //异地卡流程
  1062. //readCardBasResult := ReadCardBasHSM(number)
  1063. //fmt.Println(readCardBasResult)
  1064. //是否异地就医,是的话走鉴权流程,不是的话走门诊挂号
  1065. if is_yidi == 1 { //1本地就医
  1066. resp_result := service.SzybMZ002(opera_name, opera_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  1067. var dat map[string]interface{}
  1068. if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1069. fmt.Println(dat)
  1070. } else {
  1071. fmt.Println(err)
  1072. }
  1073. userJSONBytes, _ := json.Marshal(dat)
  1074. var res ResultOne
  1075. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1076. utils.ErrorLog("解析失败:%v", err)
  1077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1078. return
  1079. }
  1080. if res.Transreturncode == "00000000" {
  1081. his := models.VMHisPatient{
  1082. Name: name,
  1083. Gender: gender,
  1084. Birthday: birthUnix,
  1085. MedicalTreatmentType: medical_care,
  1086. IdType: certificates,
  1087. IdCardNo: id_card,
  1088. BalanceAccountsType: settlementValue,
  1089. SocialType: social_type,
  1090. MedicalInsuranceNumber: medical_insurance_card,
  1091. RegisterType: register_type,
  1092. RegisterCost: registration_fee,
  1093. TreatmentCost: medical_expenses,
  1094. Status: 1,
  1095. Ctime: time.Now().Unix(),
  1096. Mtime: time.Now().Unix(),
  1097. Iinfo: resp_result,
  1098. PatientId: patient.ID,
  1099. RecordDate: theTime.Unix(),
  1100. UserOrgId: adminInfo.CurrentOrgId,
  1101. AdminUserId: admin_user_id,
  1102. IsReturn: 1,
  1103. IdCardType: id_card_type,
  1104. Doctor: doctor,
  1105. Departments: department,
  1106. YiliaoNumber: yiliao_number,
  1107. MzNumber: number,
  1108. Number: mz_number,
  1109. PsnNo: health_card_no,
  1110. PatientInfo: result001,
  1111. }
  1112. service.CreateHisPatientTwo(&his)
  1113. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, theTime.Unix())
  1114. if len(lists) == 1 {
  1115. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, theTime.Unix(), adminInfo.CurrentOrgId)
  1116. }
  1117. c.ServeSuccessJSON(map[string]interface{}{
  1118. "msg": "挂号成功",
  1119. })
  1120. } else {
  1121. c.ServeSuccessJSON(map[string]interface{}{
  1122. "failed_code": -10,
  1123. "msg": res.Transreturnmessage,
  1124. })
  1125. return
  1126. }
  1127. } else { //异地就医需要走鉴权流程
  1128. //authResult := CardAuth(number)
  1129. //fmt.Println(authResult)
  1130. resp_result := service.SzybMZ002(opera_name, opera_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  1131. var dat map[string]interface{}
  1132. if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1133. fmt.Println(dat)
  1134. } else {
  1135. fmt.Println(err)
  1136. }
  1137. userJSONBytes, _ := json.Marshal(dat)
  1138. var res ResultOne
  1139. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1140. utils.ErrorLog("解析失败:%v", err)
  1141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1142. return
  1143. }
  1144. if res.Transreturncode == "00000000" {
  1145. his := models.VMHisPatient{
  1146. Name: name,
  1147. Gender: gender,
  1148. Birthday: birthUnix,
  1149. MedicalTreatmentType: medical_care,
  1150. IdType: certificates,
  1151. IdCardNo: id_card,
  1152. BalanceAccountsType: settlementValue,
  1153. SocialType: social_type,
  1154. MedicalInsuranceNumber: medical_insurance_card,
  1155. RegisterType: register_type,
  1156. RegisterCost: registration_fee,
  1157. TreatmentCost: medical_expenses,
  1158. Status: 1,
  1159. Ctime: time.Now().Unix(),
  1160. Mtime: time.Now().Unix(),
  1161. Iinfo: resp_result,
  1162. PatientId: patient.ID,
  1163. RecordDate: theTime.Unix(),
  1164. UserOrgId: adminInfo.CurrentOrgId,
  1165. AdminUserId: admin_user_id,
  1166. IsReturn: 1,
  1167. IdCardType: id_card_type,
  1168. Doctor: doctor,
  1169. Departments: department,
  1170. YiliaoNumber: yiliao_number,
  1171. MzNumber: number,
  1172. Number: mz_number,
  1173. PsnNo: health_card_no,
  1174. PatientInfo: result001,
  1175. }
  1176. service.CreateHisPatientTwo(&his)
  1177. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, theTime.Unix())
  1178. if len(lists) == 1 {
  1179. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, theTime.Unix(), adminInfo.CurrentOrgId)
  1180. }
  1181. c.ServeSuccessJSON(map[string]interface{}{
  1182. "msg": "挂号成功",
  1183. })
  1184. } else {
  1185. c.ServeSuccessJSON(map[string]interface{}{
  1186. "failed_code": -10,
  1187. "msg": res.Transreturnmessage,
  1188. })
  1189. return
  1190. }
  1191. }
  1192. }
  1193. } else {
  1194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  1195. return
  1196. }
  1197. }
  1198. //func (c *SZHisApiController) GetInfo() {
  1199. //func (c *SZHisApiController) GetRegisterInfo() {
  1200. // adminInfo := c.GetAdminUserInfo()
  1201. // admin_user_id, _ := c.GetInt64("admin_user_id")
  1202. // patient_id, _ := c.GetInt64("id")
  1203. // record_time := c.GetString("record_time")
  1204. // settlementValue, _ := c.GetInt64("settlement_value")
  1205. // medical_insurance_card := c.GetString("medical_insurance_card")
  1206. // name := c.GetString("name")
  1207. // id_card_type, _ := c.GetInt64("id_card_type")
  1208. // certificates, _ := c.GetInt64("certificates")
  1209. // medical_care, _ := c.GetInt64("medical_care")
  1210. // birthday := c.GetString("birthday")
  1211. // id_card := c.GetString("id_card")
  1212. // register_type, _ := c.GetInt64("register")
  1213. // doctor, _ := c.GetInt64("doctor")
  1214. // department, _ := c.GetInt64("department")
  1215. // gender, _ := c.GetInt64("sex")
  1216. // registration_fee, _ := c.GetFloat("registration_fee")
  1217. // medical_expenses, _ := c.GetFloat("medical_expenses")
  1218. // social_type, _ := c.GetInt64("social_type")
  1219. //
  1220. // is_yidi, _ := c.GetInt64("is_yidi")
  1221. //
  1222. // timeLayout := "2006-01-02"
  1223. // loc, _ := time.LoadLocation("Local")
  1224. // birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  1225. // birthUnix := birthdays.Unix()
  1226. //
  1227. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1228. // if err != nil {
  1229. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1230. // return
  1231. // }
  1232. //
  1233. // var patient service.Patients
  1234. // if patient_id == 0 {
  1235. // patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  1236. // } else {
  1237. // patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1238. // }
  1239. //
  1240. // miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1241. // if patient.ID == 0 {
  1242. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1243. // return
  1244. // }
  1245. // if len(patient.IdCardNo) == 0 {
  1246. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  1247. // return
  1248. // }
  1249. //
  1250. // adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1251. // his, _ := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient_id, theTime.Unix())
  1252. //
  1253. // var custom_code string
  1254. // var custom_project_name string
  1255. // var allPrice float64
  1256. //
  1257. // switch register_type {
  1258. // case 1:
  1259. // custom_code = "110100002"
  1260. // custom_project_name = "普通门诊"
  1261. // allPrice = 10
  1262. // break
  1263. // case 3:
  1264. // custom_code = "110200002-2"
  1265. // custom_project_name = "主任医师"
  1266. // allPrice = 10
  1267. //
  1268. // break
  1269. // case 2:
  1270. // custom_code = "110200002-3"
  1271. // custom_project_name = "副主任医师"
  1272. // allPrice = 10
  1273. //
  1274. // break
  1275. // case 4:
  1276. // custom_code = "0"
  1277. // custom_project_name = "免受诊金"
  1278. // allPrice = 0
  1279. // break
  1280. // case 5:
  1281. // custom_code = "110200002-1"
  1282. // custom_project_name = "专家"
  1283. // allPrice = 10
  1284. //
  1285. // break
  1286. // }
  1287. //
  1288. // if his.ID == 0 {
  1289. //
  1290. // var doctor_name string
  1291. // var doctor_code string
  1292. // if adminRole.ID == 0 {
  1293. //
  1294. // doctor_name = ""
  1295. // doctor_code = "1001"
  1296. // doctor_name = ""
  1297. // doctor_code = ""
  1298. //
  1299. // } else {
  1300. // doctor_name = adminRole.UserName
  1301. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  1302. //
  1303. // }
  1304. // month := time.Unix(1557042972, 0).Format("1")
  1305. // year := time.Now().Format("2006")
  1306. // month = time.Now().Format("01")
  1307. // day := time.Now().Format("02")
  1308. //
  1309. // //流水号
  1310. // //
  1311. // number := miConfig.Code + year + month + day +
  1312. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  1313. // mz_number := year + month + day + strconv.FormatInt(patient_id, 10) +
  1314. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000))
  1315. // //1.判断读卡类型
  1316. // //2.读卡 获取交易验证码,医疗证号,发卡地区行政区划代码
  1317. // yiliao_number, id_card_number, verifyCode, version_code, _, ret4 := ReadBasCardGetNumber("MZ002" + "|" + number + "|" + miConfig.Code + "|")
  1318. // fmt.Println(yiliao_number)
  1319. // fmt.Println(id_card_number)
  1320. // fmt.Println(verifyCode)
  1321. // fmt.Println(version_code)
  1322. // fmt.Println(ret4)
  1323. //
  1324. // dept_code := "0305"
  1325. // is_yidi = 1
  1326. // tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  1327. // //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  1328. // if tempPatient.ID == patient_id {
  1329. // if ret4 == 0 { //本地卡流程
  1330. // if is_yidi == 1 {
  1331. // //本地就医流程
  1332. // //挂号
  1333. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, dept_code, yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  1334. // var dat map[string]interface{}
  1335. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1336. // fmt.Println(dat)
  1337. // } else {
  1338. // fmt.Println(err)
  1339. // }
  1340. // userJSONBytes, _ := json.Marshal(dat)
  1341. // var res ResultOne
  1342. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1343. // utils.ErrorLog("解析失败:%v", err)
  1344. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1345. // return
  1346. // }
  1347. // if res.Transreturncode == "00000000" {
  1348. // his := models.VMHisPatient{
  1349. // Name: name,
  1350. // Gender: gender,
  1351. // Birthday: birthUnix,
  1352. // MedicalTreatmentType: medical_care,
  1353. // IdType: certificates,
  1354. // IdCardNo: id_card,
  1355. // BalanceAccountsType: settlementValue,
  1356. // SocialType: social_type,
  1357. // MedicalInsuranceNumber: medical_insurance_card,
  1358. // RegisterType: register_type,
  1359. // RegisterCost: registration_fee,
  1360. // TreatmentCost: medical_expenses,
  1361. // Status: 1,
  1362. // Ctime: time.Now().Unix(),
  1363. // Mtime: time.Now().Unix(),
  1364. // Iinfo: resp_result,
  1365. // PatientId: patient.ID,
  1366. // RecordDate: theTime.Unix(),
  1367. // UserOrgId: adminInfo.CurrentOrgId,
  1368. // AdminUserId: admin_user_id,
  1369. // IsReturn: 1,
  1370. // IdCardType: id_card_type,
  1371. // Doctor: doctor,
  1372. // Departments: department,
  1373. // YiliaoNumber: yiliao_number,
  1374. // MzNumber: number,
  1375. // Number: mz_number,
  1376. // }
  1377. // service.CreateHisPatientTwo(&his)
  1378. // c.ServeSuccessJSON(map[string]interface{}{
  1379. // "msg": "挂号成功",
  1380. // })
  1381. // } else {
  1382. // c.ServeSuccessJSON(map[string]interface{}{
  1383. // "failed_code": -10,
  1384. // "msg": res.Transreturnmessage,
  1385. // })
  1386. // return
  1387. // }
  1388. //
  1389. // } else {
  1390. // //异地就医流程
  1391. // //异地走鉴权流程
  1392. // //authResult := CardAuth(number)
  1393. // //fmt.Println(authResult)
  1394. //
  1395. // //tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  1396. // //if tempPatient.ID == patient_id {
  1397. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice)
  1398. // var dat map[string]interface{}
  1399. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1400. // fmt.Println(dat)
  1401. // } else {
  1402. // fmt.Println(err)
  1403. // }
  1404. //
  1405. // userJSONBytes, _ := json.Marshal(dat)
  1406. //
  1407. // var res ResultOne
  1408. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1409. // utils.ErrorLog("解析失败:%v", err)
  1410. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1411. // return
  1412. // }
  1413. // if res.Transreturncode == "00000000" {
  1414. // his := models.VMHisPatient{
  1415. // Name: name,
  1416. // Gender: gender,
  1417. // Birthday: birthUnix,
  1418. // MedicalTreatmentType: medical_care,
  1419. // IdType: certificates,
  1420. // IdCardNo: id_card,
  1421. // BalanceAccountsType: settlementValue,
  1422. // SocialType: social_type,
  1423. // MedicalInsuranceNumber: medical_insurance_card,
  1424. // RegisterType: register_type,
  1425. // RegisterCost: registration_fee,
  1426. // TreatmentCost: medical_expenses,
  1427. // Status: 1,
  1428. // Ctime: time.Now().Unix(),
  1429. // Mtime: time.Now().Unix(),
  1430. // Iinfo: resp_result,
  1431. // PatientId: patient.ID,
  1432. // RecordDate: theTime.Unix(),
  1433. // UserOrgId: adminInfo.CurrentOrgId,
  1434. // AdminUserId: admin_user_id,
  1435. // IsReturn: 1,
  1436. // IdCardType: id_card_type,
  1437. // Doctor: doctor,
  1438. // Departments: department,
  1439. // YiliaoNumber: yiliao_number,
  1440. // MzNumber: number,
  1441. // Number: mz_number,
  1442. // }
  1443. // service.CreateHisPatientTwo(&his)
  1444. // c.ServeSuccessJSON(map[string]interface{}{
  1445. // "msg": "挂号成功",
  1446. // })
  1447. // } else {
  1448. // c.ServeSuccessJSON(map[string]interface{}{
  1449. // "failed_code": -10,
  1450. // "msg": res.Transreturnmessage,
  1451. // })
  1452. // return
  1453. // }
  1454. //
  1455. // }
  1456. //
  1457. // } else { //异地卡流程
  1458. // //readCardBasResult := ReadCardBasHSM(number)
  1459. // //fmt.Println(readCardBasResult)
  1460. // //是否异地就医,是的话走鉴权流程,不是的话走门诊挂号
  1461. // if is_yidi == 1 { //1本地就医
  1462. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice)
  1463. // var dat map[string]interface{}
  1464. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1465. // fmt.Println(dat)
  1466. // } else {
  1467. // fmt.Println(err)
  1468. // }
  1469. //
  1470. // userJSONBytes, _ := json.Marshal(dat)
  1471. //
  1472. // var res ResultOne
  1473. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1474. // utils.ErrorLog("解析失败:%v", err)
  1475. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1476. // return
  1477. // }
  1478. // if res.Transreturncode == "00000000" {
  1479. // his := models.VMHisPatient{
  1480. // Name: name,
  1481. // Gender: gender,
  1482. // Birthday: birthUnix,
  1483. // MedicalTreatmentType: medical_care,
  1484. // IdType: certificates,
  1485. // IdCardNo: id_card,
  1486. // BalanceAccountsType: settlementValue,
  1487. // SocialType: social_type,
  1488. // MedicalInsuranceNumber: medical_insurance_card,
  1489. // RegisterType: register_type,
  1490. // RegisterCost: registration_fee,
  1491. // TreatmentCost: medical_expenses,
  1492. // Status: 1,
  1493. // Ctime: time.Now().Unix(),
  1494. // Mtime: time.Now().Unix(),
  1495. // Iinfo: resp_result,
  1496. // PatientId: patient.ID,
  1497. // RecordDate: theTime.Unix(),
  1498. // UserOrgId: adminInfo.CurrentOrgId,
  1499. // AdminUserId: admin_user_id,
  1500. // IsReturn: 1,
  1501. // IdCardType: id_card_type,
  1502. // Doctor: doctor,
  1503. // Departments: department,
  1504. // YiliaoNumber: yiliao_number,
  1505. // MzNumber: number,
  1506. // Number: mz_number,
  1507. // }
  1508. // service.CreateHisPatientTwo(&his)
  1509. // c.ServeSuccessJSON(map[string]interface{}{
  1510. // "msg": "挂号成功",
  1511. // })
  1512. // } else {
  1513. // c.ServeSuccessJSON(map[string]interface{}{
  1514. // "failed_code": -10,
  1515. // "msg": res.Transreturnmessage,
  1516. // })
  1517. // return
  1518. // }
  1519. //
  1520. // } else { //异地就医需要走鉴权流程
  1521. // //authResult := CardAuth(number)
  1522. // //fmt.Println(authResult)
  1523. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice)
  1524. // var dat map[string]interface{}
  1525. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1526. // fmt.Println(dat)
  1527. // } else {
  1528. // fmt.Println(err)
  1529. // }
  1530. //
  1531. // userJSONBytes, _ := json.Marshal(dat)
  1532. //
  1533. // var res ResultOne
  1534. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1535. // utils.ErrorLog("解析失败:%v", err)
  1536. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1537. // return
  1538. // }
  1539. // if res.Transreturncode == "00000000" {
  1540. // his := models.VMHisPatient{
  1541. // Name: name,
  1542. // Gender: gender,
  1543. // Birthday: birthUnix,
  1544. // MedicalTreatmentType: medical_care,
  1545. // IdType: certificates,
  1546. // IdCardNo: id_card,
  1547. // BalanceAccountsType: settlementValue,
  1548. // SocialType: social_type,
  1549. // MedicalInsuranceNumber: medical_insurance_card,
  1550. // RegisterType: register_type,
  1551. // RegisterCost: registration_fee,
  1552. // TreatmentCost: medical_expenses,
  1553. // Status: 1,
  1554. // Ctime: time.Now().Unix(),
  1555. // Mtime: time.Now().Unix(),
  1556. // Iinfo: resp_result,
  1557. // PatientId: patient.ID,
  1558. // RecordDate: theTime.Unix(),
  1559. // UserOrgId: adminInfo.CurrentOrgId,
  1560. // AdminUserId: admin_user_id,
  1561. // IsReturn: 1,
  1562. // IdCardType: id_card_type,
  1563. // Doctor: doctor,
  1564. // Departments: department,
  1565. // YiliaoNumber: yiliao_number,
  1566. // MzNumber: number,
  1567. // Number: mz_number,
  1568. // }
  1569. // service.CreateHisPatientTwo(&his)
  1570. // c.ServeSuccessJSON(map[string]interface{}{
  1571. // "msg": "挂号成功",
  1572. // })
  1573. // } else {
  1574. // c.ServeSuccessJSON(map[string]interface{}{
  1575. // "failed_code": -10,
  1576. // "msg": res.Transreturnmessage,
  1577. // })
  1578. // return
  1579. // }
  1580. //
  1581. // }
  1582. // }
  1583. // } else {
  1584. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  1585. // return
  1586. // }
  1587. // } else {
  1588. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1589. // return
  1590. // }
  1591. //}
  1592. //func (c *SZHisApiController) GetRegisterInfo() {
  1593. // adminInfo := c.GetAdminUserInfo()
  1594. // miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1595. // month := time.Unix(1557042972, 0).Format("1")
  1596. // year := time.Now().Format("2006")
  1597. // month = time.Now().Format("01")
  1598. // day := time.Now().Format("02")
  1599. // //流水号
  1600. // number := miConfig.Code + year + month + day +
  1601. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  1602. // //1.判断读卡类型
  1603. // //2.读卡 获取交易验证码,医疗证号,发卡地区行政区划代码
  1604. // yiliao_number, _, verifyCode, version_code, _, _, _ := ReadBasCardGetNumber("XX001" + "|" + number + "|" + miConfig.Code + "|")
  1605. // fmt.Println(result)
  1606. //
  1607. //}
  1608. func (c *SZHisApiController) RefundNumber() {
  1609. record_time := c.GetString("record_time")
  1610. //patient_id, _ := c.GetInt64("patient_id")
  1611. his_patient_id, _ := c.GetInt64("his_patient_id")
  1612. admin_user_id, _ := c.GetInt64("admin_user_id")
  1613. timeLayout := "2006-01-02"
  1614. loc, _ := time.LoadLocation("Local")
  1615. adminUser := c.GetAdminUserInfo()
  1616. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1617. fmt.Println(err)
  1618. if err != nil {
  1619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1620. return
  1621. }
  1622. recordDateTime := theTime.Unix()
  1623. fmt.Println(recordDateTime)
  1624. his, _ := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, theTime.Unix())
  1625. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1626. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1627. //结算流程
  1628. var doctor_name string
  1629. var doctor_code string
  1630. if roles.ID == 0 {
  1631. doctor_name = "管理员"
  1632. doctor_code = "01"
  1633. } else {
  1634. doctor_name = roles.UserName
  1635. doctor_code = strconv.FormatInt(admin_user_id, 10)
  1636. }
  1637. month := time.Unix(1557042972, 0).Format("1")
  1638. year := time.Now().Format("2006")
  1639. month = time.Now().Format("01")
  1640. day := time.Now().Format("02")
  1641. //number := miConfig.Code + year + month + day + "1367866"
  1642. number := miConfig.Code + year + month + day +
  1643. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  1644. //number := miConfig.Code + year + month + day + "1590003"
  1645. //流水号
  1646. //number_two := miConfig.Code + "-" + year + month + day + "-" + strconv.FormatInt(patient_id, 10)
  1647. verifyCode, version_code := ReadCardGetCode("JY002" + "|" + number + "|" + miConfig.Code)
  1648. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1649. if config.IsOpen == 1 { //对接了医保,走医保流程
  1650. result := service.SzybJY002(doctor_name, doctor_code, miConfig.Code, his.MzNumber, his.Number, verifyCode, number, version_code)
  1651. var dat map[string]interface{}
  1652. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1653. fmt.Println(dat)
  1654. } else {
  1655. fmt.Println(err)
  1656. }
  1657. userJSONBytes, _ := json.Marshal(dat)
  1658. var res ResultThree
  1659. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1660. utils.ErrorLog("解析失败:%v", err)
  1661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1662. return
  1663. }
  1664. if res.Transreturncode == "00000000" {
  1665. service.UpdataHisStatusSZ(adminUser.CurrentOrgId, his.MzNumber, his.Number, result, his_patient_id)
  1666. c.ServeSuccessJSON(map[string]interface{}{
  1667. "msg": "退号成功",
  1668. })
  1669. } else {
  1670. c.ServeSuccessJSON(map[string]interface{}{
  1671. "failed_code": -10,
  1672. "msg": res.Transreturnmessage,
  1673. })
  1674. }
  1675. }
  1676. }
  1677. //func (c *SZHisApiController) GetRegisterInfo() {
  1678. // adminInfo := c.GetAdminUserInfo()
  1679. // admin_user_id, _ := c.GetInt64("admin_user_id")
  1680. // patient_id, _ := c.GetInt64("id")
  1681. // record_time := c.GetString("record_time")
  1682. // settlementValue, _ := c.GetInt64("settlement_value")
  1683. // medical_insurance_card := c.GetString("medical_insurance_card")
  1684. // name := c.GetString("name")
  1685. // id_card_type, _ := c.GetInt64("id_card_type")
  1686. // certificates, _ := c.GetInt64("certificates")
  1687. // medical_care, _ := c.GetInt64("medical_care")
  1688. // birthday := c.GetString("birthday")
  1689. // id_card := c.GetString("id_card")
  1690. // register_type, _ := c.GetInt64("register")
  1691. // doctor, _ := c.GetInt64("doctor")
  1692. // department, _ := c.GetInt64("department")
  1693. // gender, _ := c.GetInt64("sex")
  1694. // registration_fee, _ := c.GetFloat("registration_fee")
  1695. // medical_expenses, _ := c.GetFloat("medical_expenses")
  1696. // social_type, _ := c.GetInt64("social_type")
  1697. //
  1698. // is_yidi, _ := c.GetInt64("is_yidi")
  1699. //
  1700. // timeLayout := "2006-01-02"
  1701. // loc, _ := time.LoadLocation("Local")
  1702. // birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  1703. // birthUnix := birthdays.Unix()
  1704. //
  1705. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1706. // if err != nil {
  1707. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1708. // return
  1709. // }
  1710. //
  1711. // var patient service.Patients
  1712. // if patient_id == 0 {
  1713. // patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  1714. // } else {
  1715. // patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1716. // }
  1717. //
  1718. // miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1719. // if patient.ID == 0 {
  1720. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1721. // return
  1722. // }
  1723. // if len(patient.IdCardNo) == 0 {
  1724. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  1725. // return
  1726. // }
  1727. //
  1728. // adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1729. // his, _ := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient_id, theTime.Unix())
  1730. //
  1731. // var custom_code string
  1732. // var custom_project_name string
  1733. // var allPrice float64
  1734. //
  1735. // switch register_type {
  1736. // case 1:
  1737. // custom_code = "110100002"
  1738. // custom_project_name = "普通门诊"
  1739. // allPrice = 10
  1740. // break
  1741. // case 3:
  1742. // custom_code = "110200002-2"
  1743. // custom_project_name = "主任医师"
  1744. // allPrice = 10
  1745. //
  1746. // break
  1747. // case 2:
  1748. // custom_code = "110200002-3"
  1749. // custom_project_name = "副主任医师"
  1750. // allPrice = 10
  1751. //
  1752. // break
  1753. // case 4:
  1754. // custom_code = "0"
  1755. // custom_project_name = "免受诊金"
  1756. // allPrice = 0
  1757. // break
  1758. // case 5:
  1759. // custom_code = "110200002-1"
  1760. // custom_project_name = "专家"
  1761. // allPrice = 10
  1762. //
  1763. // break
  1764. // }
  1765. //
  1766. // if his.ID == 0 {
  1767. //
  1768. // var doctor_name string
  1769. // var doctor_code string
  1770. // if adminRole.ID == 0 {
  1771. //
  1772. // doctor_name = "管理员"
  1773. // doctor_code = "01"
  1774. //
  1775. // } else {
  1776. // doctor_name = adminRole.UserName
  1777. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  1778. //
  1779. // }
  1780. // month := time.Unix(1557042972, 0).Format("1")
  1781. // year := time.Now().Format("2006")
  1782. // month = time.Now().Format("01")
  1783. // day := time.Now().Format("02")
  1784. //
  1785. // //流水号
  1786. // //
  1787. // number := miConfig.Code + year + month + day +
  1788. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  1789. // mz_number := miConfig.Code + year + month + day +
  1790. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000))
  1791. // //1.判断读卡类型
  1792. // //2.读卡 获取交易验证码,医疗证号,发卡地区行政区划代码
  1793. // yiliao_number, id_card_number, verifyCode, version_code, _, ret4 := ReadBasCardGetNumber("MZ002" + "|" + number + "|" + miConfig.Code + "|")
  1794. // fmt.Println(yiliao_number)
  1795. // fmt.Println(id_card_number)
  1796. // fmt.Println(verifyCode)
  1797. // fmt.Println(version_code)
  1798. // fmt.Println(ret4)
  1799. //
  1800. // dept_code := "0306"
  1801. // is_yidi = 1
  1802. // tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  1803. // //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  1804. // fmt.Println(tempPatient.ID)
  1805. // fmt.Println(patient_id)
  1806. //
  1807. // if tempPatient.ID == patient_id {
  1808. // if ret4 == 0 { //本地卡流程
  1809. // if is_yidi == 1 {
  1810. // //本地就医流程
  1811. // //挂号
  1812. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, dept_code, yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  1813. // var dat map[string]interface{}
  1814. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1815. // fmt.Println(dat)
  1816. // } else {
  1817. // fmt.Println(err)
  1818. // }
  1819. // userJSONBytes, _ := json.Marshal(dat)
  1820. // var res ResultOne
  1821. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1822. // utils.ErrorLog("解析失败:%v", err)
  1823. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1824. // return
  1825. // }
  1826. // if res.Transreturncode == "00000000" {
  1827. // his := models.VMHisPatient{
  1828. // Name: name,
  1829. // Gender: gender,
  1830. // Birthday: birthUnix,
  1831. // MedicalTreatmentType: medical_care,
  1832. // IdType: certificates,
  1833. // IdCardNo: id_card,
  1834. // BalanceAccountsType: settlementValue,
  1835. // SocialType: social_type,
  1836. // MedicalInsuranceNumber: medical_insurance_card,
  1837. // RegisterType: register_type,
  1838. // RegisterCost: registration_fee,
  1839. // TreatmentCost: medical_expenses,
  1840. // Status: 1,
  1841. // Ctime: time.Now().Unix(),
  1842. // Mtime: time.Now().Unix(),
  1843. // Iinfo: resp_result,
  1844. // PatientId: patient.ID,
  1845. // RecordDate: theTime.Unix(),
  1846. // UserOrgId: adminInfo.CurrentOrgId,
  1847. // AdminUserId: admin_user_id,
  1848. // IsReturn: 1,
  1849. // IdCardType: id_card_type,
  1850. // Doctor: doctor,
  1851. // Departments: department,
  1852. // YiliaoNumber: yiliao_number,
  1853. // MzNumber: number,
  1854. // Number: mz_number,
  1855. // }
  1856. // service.CreateHisPatientTwo(&his)
  1857. // c.ServeSuccessJSON(map[string]interface{}{
  1858. // "msg": "挂号成功",
  1859. // })
  1860. // } else {
  1861. // c.ServeSuccessJSON(map[string]interface{}{
  1862. // "failed_code": -10,
  1863. // "msg": res.Transreturnmessage,
  1864. // })
  1865. // return
  1866. // }
  1867. //
  1868. // } else {
  1869. // //异地就医流程
  1870. // //异地走鉴权流程
  1871. // //authResult := CardAuth(number)
  1872. // //fmt.Println(authResult)
  1873. //
  1874. // //tempPatient, _ := service.GetPatientByNumber(id_card_number, adminInfo.CurrentOrgId)
  1875. // //if tempPatient.ID == patient_id {
  1876. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  1877. // var dat map[string]interface{}
  1878. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1879. // fmt.Println(dat)
  1880. // } else {
  1881. // fmt.Println(err)
  1882. // }
  1883. //
  1884. // userJSONBytes, _ := json.Marshal(dat)
  1885. //
  1886. // var res ResultOne
  1887. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1888. // utils.ErrorLog("解析失败:%v", err)
  1889. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1890. // return
  1891. // }
  1892. // if res.Transreturncode == "00000000" {
  1893. // his := models.VMHisPatient{
  1894. // Name: name,
  1895. // Gender: gender,
  1896. // Birthday: birthUnix,
  1897. // MedicalTreatmentType: medical_care,
  1898. // IdType: certificates,
  1899. // IdCardNo: id_card,
  1900. // BalanceAccountsType: settlementValue,
  1901. // SocialType: social_type,
  1902. // MedicalInsuranceNumber: medical_insurance_card,
  1903. // RegisterType: register_type,
  1904. // RegisterCost: registration_fee,
  1905. // TreatmentCost: medical_expenses,
  1906. // Status: 1,
  1907. // Ctime: time.Now().Unix(),
  1908. // Mtime: time.Now().Unix(),
  1909. // Iinfo: resp_result,
  1910. // PatientId: patient.ID,
  1911. // RecordDate: theTime.Unix(),
  1912. // UserOrgId: adminInfo.CurrentOrgId,
  1913. // AdminUserId: admin_user_id,
  1914. // IsReturn: 1,
  1915. // IdCardType: id_card_type,
  1916. // Doctor: doctor,
  1917. // Departments: department,
  1918. // YiliaoNumber: yiliao_number,
  1919. // MzNumber: number,
  1920. // Number: mz_number,
  1921. // }
  1922. // service.CreateHisPatientTwo(&his)
  1923. // c.ServeSuccessJSON(map[string]interface{}{
  1924. // "msg": "挂号成功",
  1925. // })
  1926. // } else {
  1927. // c.ServeSuccessJSON(map[string]interface{}{
  1928. // "failed_code": -10,
  1929. // "msg": res.Transreturnmessage,
  1930. // })
  1931. // return
  1932. // }
  1933. //
  1934. // }
  1935. //
  1936. // } else { //异地卡流程
  1937. // //readCardBasResult := ReadCardBasHSM(number)
  1938. // //fmt.Println(readCardBasResult)
  1939. // //是否异地就医,是的话走鉴权流程,不是的话走门诊挂号
  1940. // if is_yidi == 1 { //1本地就医
  1941. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  1942. // var dat map[string]interface{}
  1943. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  1944. // fmt.Println(dat)
  1945. // } else {
  1946. // fmt.Println(err)
  1947. // }
  1948. //
  1949. // userJSONBytes, _ := json.Marshal(dat)
  1950. //
  1951. // var res ResultOne
  1952. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1953. // utils.ErrorLog("解析失败:%v", err)
  1954. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1955. // return
  1956. // }
  1957. // if res.Transreturncode == "00000000" {
  1958. // his := models.VMHisPatient{
  1959. // Name: name,
  1960. // Gender: gender,
  1961. // Birthday: birthUnix,
  1962. // MedicalTreatmentType: medical_care,
  1963. // IdType: certificates,
  1964. // IdCardNo: id_card,
  1965. // BalanceAccountsType: settlementValue,
  1966. // SocialType: social_type,
  1967. // MedicalInsuranceNumber: medical_insurance_card,
  1968. // RegisterType: register_type,
  1969. // RegisterCost: registration_fee,
  1970. // TreatmentCost: medical_expenses,
  1971. // Status: 1,
  1972. // Ctime: time.Now().Unix(),
  1973. // Mtime: time.Now().Unix(),
  1974. // Iinfo: resp_result,
  1975. // PatientId: patient.ID,
  1976. // RecordDate: theTime.Unix(),
  1977. // UserOrgId: adminInfo.CurrentOrgId,
  1978. // AdminUserId: admin_user_id,
  1979. // IsReturn: 1,
  1980. // IdCardType: id_card_type,
  1981. // Doctor: doctor,
  1982. // Departments: department,
  1983. // YiliaoNumber: yiliao_number,
  1984. // MzNumber: number,
  1985. // Number: mz_number,
  1986. // }
  1987. // service.CreateHisPatientTwo(&his)
  1988. // c.ServeSuccessJSON(map[string]interface{}{
  1989. // "msg": "挂号成功",
  1990. // })
  1991. // } else {
  1992. // c.ServeSuccessJSON(map[string]interface{}{
  1993. // "failed_code": -10,
  1994. // "msg": res.Transreturnmessage,
  1995. // })
  1996. // return
  1997. // }
  1998. //
  1999. // } else { //异地就医需要走鉴权流程
  2000. // //authResult := CardAuth(number)
  2001. // //fmt.Println(authResult)
  2002. // resp_result := service.SzybMZ002(doctor_name, doctor_code, miConfig.Code, "0305", yiliao_number, verifyCode, number, mz_number, version_code, custom_code, custom_project_name, allPrice, medical_care)
  2003. // var dat map[string]interface{}
  2004. // if err := json.Unmarshal([]byte(resp_result), &dat); err == nil {
  2005. // fmt.Println(dat)
  2006. // } else {
  2007. // fmt.Println(err)
  2008. // }
  2009. //
  2010. // userJSONBytes, _ := json.Marshal(dat)
  2011. //
  2012. // var res ResultOne
  2013. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2014. // utils.ErrorLog("解析失败:%v", err)
  2015. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2016. // return
  2017. // }
  2018. // if res.Transreturncode == "00000000" {
  2019. // his := models.VMHisPatient{
  2020. // Name: name,
  2021. // Gender: gender,
  2022. // Birthday: birthUnix,
  2023. // MedicalTreatmentType: medical_care,
  2024. // IdType: certificates,
  2025. // IdCardNo: id_card,
  2026. // BalanceAccountsType: settlementValue,
  2027. // SocialType: social_type,
  2028. // MedicalInsuranceNumber: medical_insurance_card,
  2029. // RegisterType: register_type,
  2030. // RegisterCost: registration_fee,
  2031. // TreatmentCost: medical_expenses,
  2032. // Status: 1,
  2033. // Ctime: time.Now().Unix(),
  2034. // Mtime: time.Now().Unix(),
  2035. // Iinfo: resp_result,
  2036. // PatientId: patient.ID,
  2037. // RecordDate: theTime.Unix(),
  2038. // UserOrgId: adminInfo.CurrentOrgId,
  2039. // AdminUserId: admin_user_id,
  2040. // IsReturn: 1,
  2041. // IdCardType: id_card_type,
  2042. // Doctor: doctor,
  2043. // Departments: department,
  2044. // YiliaoNumber: yiliao_number,
  2045. // MzNumber: number,
  2046. // Number: mz_number,
  2047. // }
  2048. // service.CreateHisPatientTwo(&his)
  2049. // c.ServeSuccessJSON(map[string]interface{}{
  2050. // "msg": "挂号成功",
  2051. // })
  2052. // } else {
  2053. // c.ServeSuccessJSON(map[string]interface{}{
  2054. // "failed_code": -10,
  2055. // "msg": res.Transreturnmessage,
  2056. // })
  2057. // return
  2058. // }
  2059. //
  2060. // }
  2061. // }
  2062. // } else {
  2063. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  2064. // return
  2065. // }
  2066. // } else {
  2067. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2068. // return
  2069. // }
  2070. //}q
  2071. //上传明细----结算----确认订单
  2072. func (c *SZHisApiController) GetSettleInfo() {
  2073. pay_way, _ := c.GetInt64("pay_way")
  2074. pay_price, _ := c.GetFloat("pay_price")
  2075. pay_card_no := c.GetString("pay_card_no")
  2076. discount_price, _ := c.GetFloat("discount_price")
  2077. preferential_price, _ := c.GetFloat("preferential_price")
  2078. reality_price, _ := c.GetFloat("reality_price")
  2079. found_price, _ := c.GetFloat("found_price")
  2080. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2081. private_price, _ := c.GetFloat("private_price")
  2082. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2083. patient_id, _ := c.GetInt64("id")
  2084. record_time := c.GetString("record_time")
  2085. admin_user_id, _ := c.GetInt64("admin_user_id")
  2086. his_patient_id, _ := c.GetInt64("his_patient_id")
  2087. id_str := c.GetString("ids")
  2088. ids_arr := strings.Split(id_str, ",")
  2089. order_id, _ := c.GetInt64("order_id")
  2090. sick_type, _ := c.GetInt64("sick_type")
  2091. reg_type, _ := c.GetInt64("p_type")
  2092. timestamp := time.Now().Unix()
  2093. tempTime := time.Unix(timestamp, 0)
  2094. timeFormat := tempTime.Format("20060102150405")
  2095. chrgBchno := rand.Intn(10000) + 1000
  2096. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(1, 10)
  2097. adminUser := c.GetAdminUserInfo()
  2098. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2099. month := time.Unix(1557042972, 0).Format("1")
  2100. year := time.Now().Format("2006")
  2101. month = time.Now().Format("01")
  2102. day := time.Now().Format("02")
  2103. timeLayout := "2006-01-02"
  2104. loc, _ := time.LoadLocation("Local")
  2105. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2106. fmt.Println(err)
  2107. if err != nil {
  2108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2109. return
  2110. }
  2111. recordDateTime := theTime.Unix()
  2112. his, err := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2113. //tempOrder, _ := service.GetNewHisOrderThree(or)
  2114. tempOrder, _ := service.GetHisOrderByID(order_id)
  2115. if tempOrder.ID == 0 {
  2116. var prescriptions []*models.HisPrescription
  2117. var start_time int64
  2118. var end_time int64
  2119. if settle_accounts_type == 1 { //日结
  2120. if reg_type == 11 {
  2121. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  2122. } else {
  2123. prescriptions, _ = service.GetNewHisPrescription(adminUser.CurrentOrgId, his_patient_id, recordDateTime, strconv.Itoa(int(reg_type)))
  2124. }
  2125. } else { //月结
  2126. start_time_str := c.GetString("start_time")
  2127. end_time_str := c.GetString("end_time")
  2128. timeLayout := "2006-01-02"
  2129. loc, _ := time.LoadLocation("Local")
  2130. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2131. if err != nil {
  2132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2133. return
  2134. }
  2135. recordStartTime := theStartTime.Unix()
  2136. start_time = recordStartTime
  2137. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2138. if err != nil {
  2139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2140. return
  2141. }
  2142. recordEndTime := theEndTime.Unix()
  2143. end_time = recordEndTime
  2144. prescriptions, _ = service.GetMonthHisPrescriptionTwo(adminUser.CurrentOrgId, patient_id, recordStartTime, recordEndTime, his.MedicalTreatmentType)
  2145. }
  2146. var ids []int64
  2147. for _, item := range prescriptions {
  2148. ids = append(ids, item.ID)
  2149. }
  2150. patientPrescription, _ := service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2151. sick, _ := service.FindSickById(sick_type)
  2152. if sick.ID == 0 {
  2153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamSickTypeWrong)
  2154. return
  2155. }
  2156. adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  2157. adminRole, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2158. mz_number := his.Number
  2159. number := miConfig.Code + year + month + day +
  2160. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  2161. var doctor_name string
  2162. var doctor_code string
  2163. var drug_doctor_code string
  2164. drug_doctor_code = adminRole_two.DoctorCode
  2165. drug_doctor_name := adminRole_two.UserName
  2166. if adminRole.ID == 0 {
  2167. doctor_name = "管理员"
  2168. doctor_code = "01"
  2169. } else {
  2170. doctor_name = adminRole.UserName
  2171. doctor_code = strconv.FormatInt(admin_user_id, 10)
  2172. }
  2173. verifyCode, version_code := ReadCardGetCode("FY001" + "|" + number + "|" + miConfig.Code)
  2174. //verifyCode := "000000|bf885fa312a7f92861d6b61542a637fa"
  2175. //version_code := "V0.3"
  2176. var customs []*models.CustomDetail
  2177. for _, item := range prescriptions {
  2178. if item.Type == 1 { //药品
  2179. for _, subItem := range item.HisDoctorAdviceInfo {
  2180. fmt.Println(subItem.BaseDrugLib.MedicalInsuranceNumber)
  2181. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 {
  2182. _, dose_code := service.GetDoseCode(subItem.BaseDrugLib.DrugDosageForm, adminUser.CurrentOrgId)
  2183. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber), 64)
  2184. price, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price), 64)
  2185. temp := strings.Split(subItem.FeedetlSn, "-")
  2186. newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  2187. fmt.Println(111111111)
  2188. fmt.Println(subItem.BaseDrugLib.Code)
  2189. fmt.Println(222222222)
  2190. cus := &models.CustomDetail{
  2191. PrescriptionNumber: chrg_bchno,
  2192. OrderType: "1",
  2193. ChargeSerialNumber: newFl,
  2194. Code: subItem.BaseDrugLib.MedicalInsuranceNumber,
  2195. CodeName: subItem.BaseDrugLib.DrugName,
  2196. BwCode: subItem.BaseDrugLib.Code,
  2197. Flag: "1",
  2198. Price: price,
  2199. Count: subItem.PrescribingNumber,
  2200. ChargeOrderDate: year + month + day,
  2201. DoctorCode: doctor_code,
  2202. Total: detItemFeeSumamt,
  2203. DoseCode: dose_code,
  2204. Spec: strconv.Itoa(int(subItem.BaseDrugLib.MinNumber)) + subItem.BaseDrugLib.MinUnit + ":" + fmt.Sprintf("%.2f", subItem.BaseDrugLib.Dose) + subItem.BaseDrugLib.DoseUnit,
  2205. Unit: subItem.PrescribingNumberUnit,
  2206. }
  2207. customs = append(customs, cus)
  2208. }
  2209. }
  2210. }
  2211. if item.Type == 2 { //项目
  2212. for _, subItem := range item.HisPrescriptionProject {
  2213. if len(subItem.HisProject.MedicalCode) > 0 {
  2214. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  2215. //count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  2216. count, _ := strconv.ParseFloat(strconv.FormatInt(subItem.Count, 10), 64)
  2217. temp := strings.Split(subItem.FeedetlSn, "-")
  2218. newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  2219. if subItem.Type == 2 {
  2220. cus := &models.CustomDetail{
  2221. PrescriptionNumber: chrg_bchno,
  2222. OrderType: "1",
  2223. ChargeSerialNumber: newFl,
  2224. Code: subItem.HisProject.MedicalCode,
  2225. BwCode: subItem.HisProject.MedicalCode,
  2226. CodeName: subItem.HisProject.ProjectName,
  2227. Flag: "1",
  2228. Price: subItem.Price,
  2229. Count: count,
  2230. ChargeOrderDate: year + month + day,
  2231. DoctorCode: doctor_code,
  2232. Total: detItemFeeSumamt,
  2233. DoseCode: "",
  2234. Spec: "次",
  2235. Unit: "次",
  2236. }
  2237. customs = append(customs, cus)
  2238. }
  2239. }
  2240. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 {
  2241. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  2242. //count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  2243. count, _ := strconv.ParseFloat(strconv.FormatInt(subItem.Count, 10), 64)
  2244. temp := strings.Split(subItem.FeedetlSn, "-")
  2245. newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  2246. if subItem.Type == 3 {
  2247. cus := &models.CustomDetail{
  2248. PrescriptionNumber: chrg_bchno,
  2249. OrderType: "1",
  2250. ChargeSerialNumber: newFl,
  2251. Code: subItem.GoodInfo.MedicalInsuranceNumber,
  2252. CodeName: subItem.GoodInfo.GoodName,
  2253. BwCode: subItem.GoodInfo.MedicalInsuranceNumber,
  2254. Flag: "1",
  2255. Price: subItem.Price,
  2256. Count: count,
  2257. ChargeOrderDate: year + month + day,
  2258. DoctorCode: doctor_code,
  2259. Total: detItemFeeSumamt,
  2260. DoseCode: "",
  2261. Spec: "支",
  2262. Unit: "支",
  2263. }
  2264. customs = append(customs, cus)
  2265. }
  2266. }
  2267. }
  2268. }
  2269. //
  2270. //for _, subItem := range item.HisAdditionalCharge {
  2271. // if len(subItem.XtHisAddtionConfig.Code) > 0 {
  2272. // detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  2273. //
  2274. // count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  2275. // cus := &models.CustomDetail{
  2276. // PrescriptionNumber: chrg_bchno,
  2277. // OrderType: "1",
  2278. // ChargeSerialNumber: subItem.FeedetlSn,
  2279. // Code: subItem.XtHisAddtionConfig.Code,
  2280. // CodeName: subItem.XtHisAddtionConfig.Name,
  2281. // Flag: "1",
  2282. // Price: subItem.Price,
  2283. // Count: count,
  2284. // ChargeOrderDate: year + month + day,
  2285. // DoctorCode: doctor_code,
  2286. // Total: detItemFeeSumamt,
  2287. // DoseCode: "",
  2288. // Spec: subItem.XtHisAddtionConfig.,
  2289. // }
  2290. // customs = append(customs, cus)
  2291. // }
  2292. //}
  2293. }
  2294. var pagesize int = 50
  2295. var start int = 1
  2296. var stop int
  2297. var pagecount int
  2298. var curpage int
  2299. var isSuccess bool = true
  2300. //总页数,向上取整,注意除之前要先转换类型为float64
  2301. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  2302. var ress []*Result
  2303. for curpage = 1; curpage <= pagecount; curpage++ {
  2304. if curpage == 1 {
  2305. start = 1
  2306. } else {
  2307. start = (curpage-1)*pagesize + 1
  2308. }
  2309. stop = curpage * pagesize
  2310. if stop > len(customs) {
  2311. stop = len(customs)
  2312. }
  2313. result := service.SzybFY001(doctor_name, doctor_code, miConfig.Code, customs[start-1:stop], verifyCode, number, mz_number, version_code, drug_doctor_code)
  2314. fmt.Println(result)
  2315. var dat map[string]interface{}
  2316. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2317. fmt.Println(dat)
  2318. } else {
  2319. fmt.Println(err)
  2320. }
  2321. userJSONBytes, _ := json.Marshal(dat)
  2322. var res Result
  2323. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2324. utils.ErrorLog("解析失败:%v", err)
  2325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2326. return
  2327. }
  2328. if res.Transreturncode == "00000000" {
  2329. ress = append(ress, &res)
  2330. } else {
  2331. isSuccess = false
  2332. errlog := &models.HisOrderError{
  2333. UserOrgId: adminUser.CurrentOrgId,
  2334. Ctime: time.Now().Unix(),
  2335. Mtime: time.Now().Unix(),
  2336. Number: chrg_bchno,
  2337. ErrMsg: res.Transreturnmessage,
  2338. Status: 1,
  2339. PatientId: patient_id,
  2340. RecordTime: recordDateTime,
  2341. Stage: 4,
  2342. }
  2343. service.CreateErrMsgLog(errlog)
  2344. c.ServeSuccessJSON(map[string]interface{}{
  2345. "failed_code": -10,
  2346. "msg": res.Transreturnmessage,
  2347. })
  2348. return
  2349. }
  2350. //设置变量,根据变量的值来判断上传是否成功
  2351. }
  2352. if isSuccess == true {
  2353. order := &models.HisOrder{
  2354. UserOrgId: adminUser.CurrentOrgId,
  2355. HisPatientId: 0,
  2356. PatientId: patient_id,
  2357. SettleAccountsDate: recordDateTime,
  2358. Ctime: time.Now().Unix(),
  2359. Mtime: time.Now().Unix(),
  2360. Status: 0,
  2361. Number: chrg_bchno,
  2362. Infcode: 0,
  2363. WarnMsg: "",
  2364. Cainfo: "",
  2365. ErrMsg: "",
  2366. RespondTime: "",
  2367. InfRefmsgid: "",
  2368. OrderStatus: 1,
  2369. IsMedicineInsurance: 1,
  2370. SettleType: settle_accounts_type,
  2371. SettleStartTime: start_time,
  2372. SettleEndTime: end_time,
  2373. Creator: admin_user_id,
  2374. Modify: admin_user_id,
  2375. OrgSetlNumber: number,
  2376. MdtrtId: mz_number,
  2377. PType: 2,
  2378. }
  2379. data, _ := json.Marshal(ress)
  2380. order.DetailLog = string(data)
  2381. err = service.CreateOrder(order)
  2382. if err != nil {
  2383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2384. return
  2385. }
  2386. for _, subItem := range ress {
  2387. for _, item := range subItem.Transbody.Outputlist {
  2388. temp := strings.Split(item.Bkf500, "-")
  2389. var advice_id int64 = 0
  2390. var project_id int64 = 0
  2391. var types int64 = 0
  2392. id, _ := strconv.ParseInt(temp[2], 10, 64)
  2393. types, _ = strconv.ParseInt(temp[1], 10, 64)
  2394. if temp[1] == "1" {
  2395. advice_id = id
  2396. project_id = 0
  2397. } else if temp[1] == "2" {
  2398. advice_id = 0
  2399. project_id = id
  2400. }
  2401. info := &models.HisOrderInfo{
  2402. OrderNumber: order.Number,
  2403. FeedetlSn: item.Bkf500,
  2404. UploadDate: time.Now().Unix(),
  2405. AdviceId: advice_id,
  2406. DetItemFeeSumamt: item.Akc264,
  2407. Cnt: item.Akc226,
  2408. Pric: float64(item.Akc225),
  2409. PatientId: patient_id,
  2410. Status: 1,
  2411. ChrgitmLv: item.Aka065,
  2412. Mtime: time.Now().Unix(),
  2413. Ctime: time.Now().Unix(),
  2414. UserOrgId: adminUser.CurrentOrgId,
  2415. OrderId: order.ID,
  2416. ProjectId: project_id,
  2417. Type: types,
  2418. OverPricPsnPay: item.Akc268,
  2419. AllowReimburse: item.Cka319,
  2420. }
  2421. service.CreateOrderInfo(info)
  2422. }
  2423. }
  2424. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2425. service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, his_patient_id, chrg_bchno, recordDateTime)
  2426. var total float64
  2427. for _, item := range prescriptions {
  2428. if item.Type == 1 { //药品
  2429. for _, subItem := range item.HisDoctorAdviceInfo {
  2430. total = total + (subItem.Price * subItem.PrescribingNumber)
  2431. }
  2432. }
  2433. if item.Type == 2 { //项目
  2434. for _, subItem := range item.HisPrescriptionProject {
  2435. total = total + (subItem.Price * float64(subItem.Count))
  2436. }
  2437. }
  2438. }
  2439. for _, item := range prescriptions {
  2440. for _, subItem := range item.HisAdditionalCharge {
  2441. total = total + (subItem.Price * float64(subItem.Count))
  2442. }
  2443. }
  2444. total, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", total), 64)
  2445. new_number := miConfig.Code + year + month + day +
  2446. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  2447. yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("FY005" + "|" + new_number + "|" + miConfig.Code + "|")
  2448. if ret4 == 0 {
  2449. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  2450. tempPatient, _ := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  2451. if tempPatient.ID == patient_id {
  2452. result_three := service.SzybFY005(doctor_name, doctor_code, miConfig.Code, total, yiliao_number, verifyCode, number, mz_number, version_code, drug_doctor_code, drug_doctor_name, reg_type, sick.CountryCode, new_number)
  2453. var dat map[string]interface{}
  2454. if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  2455. fmt.Println(dat)
  2456. } else {
  2457. fmt.Println(err)
  2458. }
  2459. userJSONBytes, _ := json.Marshal(dat)
  2460. var res ResultTwo
  2461. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2462. utils.ErrorLog("解析失败:%v", err)
  2463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2464. return
  2465. }
  2466. if res.Transreturncode == "00000000" {
  2467. order.OrderStatus = 2
  2468. order.Status = 1
  2469. order.PayWay = pay_way
  2470. order.PayPrice = pay_price
  2471. order.PayCardNo = pay_card_no
  2472. order.PsnNo = health_card_no
  2473. order.DiscountPrice = discount_price
  2474. order.PreferentialPrice = preferential_price
  2475. order.RealityPrice = reality_price
  2476. order.FoundPrice = found_price
  2477. order.MedicalInsurancePrice = medical_insurance_price
  2478. order.PrivatePrice = private_price
  2479. order.Modify = admin_user_id
  2480. order.MedfeeSumamt = res.Transbody.Akc264
  2481. order.SetlId = res.Transbody.Ckc618
  2482. order.FundPaySumamt = res.Transbody.Akb068
  2483. order.AcctPay = res.Transbody.Akb066
  2484. order.PsnCashPay = res.Transbody.Akb067
  2485. order.PsnPartAmt = res.Transbody.Akb067
  2486. order.AccountPrice = res.Transbody.Aae240
  2487. order.MedType = strconv.Itoa(int(reg_type))
  2488. order.MzNumber = mz_number
  2489. order.MdtrtId = mz_number
  2490. order.YiliaoNumber = yiliao_number
  2491. setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  2492. detailStrOne := string(setlDetailOne)
  2493. order.SzChargeInfo = detailStrOne
  2494. setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  2495. detailStrTwo := string(setlDetailTwo)
  2496. order.SzProjectInfo = detailStrTwo
  2497. setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  2498. detailStrThree := string(setlDetailThree)
  2499. order.SzMedicineInsuranceInfo = detailStrThree
  2500. order.Cainfo = result_three
  2501. err = service.UpdataOrderStatusTwo(order.Number, adminUser.CurrentOrgId)
  2502. err = service.UpDateOrderTwo(order)
  2503. c.ServeSuccessJSON(map[string]interface{}{
  2504. "msg": "结算成功",
  2505. })
  2506. } else {
  2507. //结算报错
  2508. errlog := &models.HisOrderError{
  2509. UserOrgId: adminUser.CurrentOrgId,
  2510. Ctime: time.Now().Unix(),
  2511. Mtime: time.Now().Unix(),
  2512. Number: chrg_bchno,
  2513. ErrMsg: res.Transreturnmessage,
  2514. Status: 1,
  2515. PatientId: patient_id,
  2516. RecordTime: recordDateTime,
  2517. Stage: 6,
  2518. }
  2519. service.CreateErrMsgLog(errlog)
  2520. c.ServeSuccessJSON(map[string]interface{}{
  2521. "failed_code": -10,
  2522. "msg": res.Transreturnmessage,
  2523. })
  2524. }
  2525. } else {
  2526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  2527. return
  2528. }
  2529. } else {
  2530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  2531. return
  2532. }
  2533. } else {
  2534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePreSettleFaildParamWrong)
  2535. return
  2536. }
  2537. } else {
  2538. if tempOrder.OrderStatus == 1 && tempOrder.IsPre == 1 {
  2539. pay_way, _ := c.GetInt64("pay_way")
  2540. pay_price, _ := c.GetFloat("pay_price")
  2541. pay_card_no := c.GetString("pay_card_no")
  2542. discount_price, _ := c.GetFloat("discount_price")
  2543. preferential_price, _ := c.GetFloat("preferential_price")
  2544. reality_price, _ := c.GetFloat("reality_price")
  2545. found_price, _ := c.GetFloat("found_price")
  2546. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2547. private_price, _ := c.GetFloat("private_price")
  2548. patient_id, _ := c.GetInt64("id")
  2549. record_time := c.GetString("record_time")
  2550. admin_user_id, _ := c.GetInt64("admin_user_id")
  2551. order_id, _ := c.GetInt64("order_id")
  2552. his_patient_id, _ := c.GetInt64("his_patient_id")
  2553. timestamp := time.Now().Unix()
  2554. tempTime := time.Unix(timestamp, 0)
  2555. timeFormat := tempTime.Format("20060102150405")
  2556. chrgBchno := rand.Intn(10000) + 1000
  2557. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(1, 10)
  2558. adminUser := c.GetAdminUserInfo()
  2559. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2560. month := time.Unix(1557042972, 0).Format("1")
  2561. year := time.Now().Format("2006")
  2562. month = time.Now().Format("01")
  2563. day := time.Now().Format("02")
  2564. timeLayout := "2006-01-02"
  2565. loc, _ := time.LoadLocation("Local")
  2566. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2567. fmt.Println(err)
  2568. if err != nil {
  2569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2570. return
  2571. }
  2572. recordDateTime := theTime.Unix()
  2573. patientPrescription, _ := service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2574. sick, _ := service.FindSickById(patientPrescription.SickType)
  2575. if sick.ID == 0 {
  2576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamSickTypeWrong)
  2577. return
  2578. }
  2579. adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  2580. adminRole, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2581. his, err := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2582. mz_number := his.Number
  2583. number := miConfig.Code + year + month + day +
  2584. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  2585. var doctor_name string
  2586. var doctor_code string
  2587. var drug_doctor_code string
  2588. drug_doctor_code = adminRole_two.DoctorCode
  2589. drug_doctor_name := adminRole_two.UserName
  2590. if adminRole.ID == 0 {
  2591. doctor_name = "管理员"
  2592. doctor_code = "01"
  2593. } else {
  2594. doctor_name = adminRole.UserName
  2595. doctor_code = strconv.FormatInt(admin_user_id, 10)
  2596. }
  2597. order, _ := service.GetHisOrderByID(order_id)
  2598. if order.ID == 0 {
  2599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  2600. return
  2601. }
  2602. yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("FY005" + "|" + number + "|" + miConfig.Code + "|")
  2603. if ret4 == 0 {
  2604. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  2605. tempPatient, _ := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  2606. if tempPatient.ID == patient_id {
  2607. result_three := service.SzybFY005(doctor_name, doctor_code, miConfig.Code, order.MedfeeSumamt, yiliao_number, verifyCode, order.OrgSetlNumber, mz_number, version_code, drug_doctor_code, drug_doctor_name, reg_type, sick.CountryCode, number)
  2608. var dat map[string]interface{}
  2609. if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  2610. fmt.Println(dat)
  2611. } else {
  2612. fmt.Println(err)
  2613. }
  2614. userJSONBytes, _ := json.Marshal(dat)
  2615. var res ResultTwo
  2616. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2617. utils.ErrorLog("解析失败:%v", err)
  2618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2619. return
  2620. }
  2621. if res.Transreturncode == "00000000" {
  2622. order.OrderStatus = 2
  2623. order.Status = 1
  2624. order.PayWay = pay_way
  2625. order.PayPrice = pay_price
  2626. order.PayCardNo = pay_card_no
  2627. order.PsnNo = health_card_no
  2628. order.DiscountPrice = discount_price
  2629. order.PreferentialPrice = preferential_price
  2630. order.RealityPrice = reality_price
  2631. order.FoundPrice = found_price
  2632. order.MedicalInsurancePrice = medical_insurance_price
  2633. order.PrivatePrice = private_price
  2634. order.Modify = admin_user_id
  2635. order.MedfeeSumamt = res.Transbody.Akc264
  2636. order.SetlId = res.Transbody.Ckc618
  2637. order.FundPaySumamt = res.Transbody.Akb068
  2638. order.AcctPay = res.Transbody.Akb066
  2639. order.PsnCashPay = res.Transbody.Akb067
  2640. order.PsnPartAmt = res.Transbody.Akb067
  2641. order.AccountPrice = res.Transbody.Aae240
  2642. order.MzNumber = mz_number
  2643. order.YiliaoNumber = yiliao_number
  2644. setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  2645. detailStrOne := string(setlDetailOne)
  2646. order.SzChargeInfo = detailStrOne
  2647. setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  2648. detailStrTwo := string(setlDetailTwo)
  2649. order.SzProjectInfo = detailStrTwo
  2650. setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  2651. detailStrThree := string(setlDetailThree)
  2652. order.SzMedicineInsuranceInfo = detailStrThree
  2653. order.Cainfo = result_three
  2654. err = service.UpdataOrderStatusTwo(order.Number, adminUser.CurrentOrgId)
  2655. err = service.UpDateOrderTwo(&order)
  2656. c.ServeSuccessJSON(map[string]interface{}{
  2657. "msg": "结算成功",
  2658. })
  2659. } else {
  2660. //结算报错
  2661. errlog := &models.HisOrderError{
  2662. UserOrgId: adminUser.CurrentOrgId,
  2663. Ctime: time.Now().Unix(),
  2664. Mtime: time.Now().Unix(),
  2665. Number: chrg_bchno,
  2666. ErrMsg: res.Transreturnmessage,
  2667. Status: 1,
  2668. PatientId: patient_id,
  2669. RecordTime: recordDateTime,
  2670. Stage: 6,
  2671. }
  2672. service.CreateErrMsgLog(errlog)
  2673. c.ServeSuccessJSON(map[string]interface{}{
  2674. "failed_code": -10,
  2675. "msg": res.Transreturnmessage,
  2676. })
  2677. }
  2678. } else {
  2679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  2680. return
  2681. }
  2682. } else {
  2683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  2684. return
  2685. }
  2686. } else {
  2687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  2688. return
  2689. }
  2690. }
  2691. }
  2692. //结算
  2693. //func (c *SZHisApiController) GetSettleInfo() {
  2694. // pay_way, _ := c.GetInt64("pay_way")
  2695. // pay_price, _ := c.GetFloat("pay_price")
  2696. // pay_card_no := c.GetString("pay_card_no")
  2697. // discount_price, _ := c.GetFloat("discount_price")
  2698. // preferential_price, _ := c.GetFloat("preferential_price")
  2699. // reality_price, _ := c.GetFloat("reality_price")
  2700. // found_price, _ := c.GetFloat("found_price")
  2701. // medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2702. // private_price, _ := c.GetFloat("private_price")
  2703. // patient_id, _ := c.GetInt64("id")
  2704. // record_time := c.GetString("record_time")
  2705. // admin_user_id, _ := c.GetInt64("admin_user_id")
  2706. // order_id, _ := c.GetInt64("order_id")
  2707. // his_patient_id, _ := c.GetInt64("his_patient_id")
  2708. //
  2709. // timestamp := time.Now().Unix()
  2710. // tempTime := time.Unix(timestamp, 0)
  2711. // timeFormat := tempTime.Format("20060102150405")
  2712. // chrgBchno := rand.Intn(10000) + 1000
  2713. // chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(1, 10)
  2714. // adminUser := c.GetAdminUserInfo()
  2715. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2716. // month := time.Unix(1557042972, 0).Format("1")
  2717. // year := time.Now().Format("2006")
  2718. // month = time.Now().Format("01")
  2719. // day := time.Now().Format("02")
  2720. //
  2721. // timeLayout := "2006-01-02"
  2722. // loc, _ := time.LoadLocation("Local")
  2723. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2724. // fmt.Println(err)
  2725. // if err != nil {
  2726. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2727. // return
  2728. // }
  2729. // recordDateTime := theTime.Unix()
  2730. //
  2731. // patientPrescription, _ := service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2732. //
  2733. // sick, _ := service.FindSickById(patientPrescription.SickType)
  2734. //
  2735. // if sick.ID == 0 {
  2736. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamSickTypeWrong)
  2737. // return
  2738. // }
  2739. //
  2740. // adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  2741. //
  2742. // adminRole, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2743. // his, err := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2744. // mz_number := his.Number
  2745. // number := miConfig.Code + year + month + day +
  2746. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  2747. // var doctor_name string
  2748. // var doctor_code string
  2749. // var drug_doctor_code string
  2750. // drug_doctor_code = adminRole_two.DoctorCode
  2751. // drug_doctor_name := adminRole_two.UserName
  2752. //
  2753. // if adminRole.ID == 0 {
  2754. // doctor_name = "管理员"
  2755. // doctor_code = "01"
  2756. // } else {
  2757. // doctor_name = adminRole.UserName
  2758. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  2759. // }
  2760. //
  2761. // order, _ := service.GetHisOrderByID(order_id)
  2762. // if order.ID == 0 {
  2763. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  2764. // return
  2765. // }
  2766. //
  2767. // yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("FY005" + "|" + number + "|" + miConfig.Code + "|")
  2768. // if ret4 == 0 {
  2769. // //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  2770. // tempPatient, _ := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  2771. // if tempPatient.ID == patient_id {
  2772. // result_three := service.SzybFY005(doctor_name, doctor_code, miConfig.Code, order.MedfeeSumamt, yiliao_number, verifyCode, number, mz_number, version_code, drug_doctor_code, drug_doctor_name, his.MedicalTreatmentType, sick.CountryCode)
  2773. // var dat map[string]interface{}
  2774. // if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  2775. // fmt.Println(dat)
  2776. // } else {
  2777. // fmt.Println(err)
  2778. // }
  2779. // userJSONBytes, _ := json.Marshal(dat)
  2780. // var res ResultTwo
  2781. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2782. // utils.ErrorLog("解析失败:%v", err)
  2783. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2784. // return
  2785. // }
  2786. //
  2787. // if res.Transreturncode == "00000000" {
  2788. // order.OrderStatus = 2
  2789. // order.Status = 1
  2790. // order.PayWay = pay_way
  2791. // order.PayPrice = pay_price
  2792. // order.PayCardNo = pay_card_no
  2793. // order.PsnNo = health_card_no
  2794. // order.DiscountPrice = discount_price
  2795. // order.PreferentialPrice = preferential_price
  2796. // order.RealityPrice = reality_price
  2797. // order.FoundPrice = found_price
  2798. // order.MedicalInsurancePrice = medical_insurance_price
  2799. // order.PrivatePrice = private_price
  2800. // order.Modify = admin_user_id
  2801. // order.MedfeeSumamt = res.Transbody.Akc264
  2802. // order.SetlId = res.Transbody.Ckc618
  2803. // order.FundPaySumamt = res.Transbody.Akb068
  2804. // order.AcctPay = res.Transbody.Akb066
  2805. // order.PsnCashPay = res.Transbody.Akb067
  2806. // order.PsnPartAmt = res.Transbody.Akb067
  2807. // order.AccountPrice = res.Transbody.Aae240
  2808. // order.MzNumber = mz_number
  2809. // order.YiliaoNumber = yiliao_number
  2810. // setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  2811. // detailStrOne := string(setlDetailOne)
  2812. // order.SzChargeInfo = detailStrOne
  2813. // setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  2814. // detailStrTwo := string(setlDetailTwo)
  2815. // order.SzProjectInfo = detailStrTwo
  2816. // setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  2817. // detailStrThree := string(setlDetailThree)
  2818. // order.SzMedicineInsuranceInfo = detailStrThree
  2819. // order.Cainfo = result_three
  2820. // err = service.UpdataOrderStatusTwo(order.Number, adminUser.CurrentOrgId)
  2821. // err = service.UpDateOrderTwo(&order)
  2822. // c.ServeSuccessJSON(map[string]interface{}{
  2823. // "msg": "结算成功",
  2824. // })
  2825. // } else {
  2826. // //结算报错
  2827. // errlog := &models.HisOrderError{
  2828. // UserOrgId: adminUser.CurrentOrgId,
  2829. // Ctime: time.Now().Unix(),
  2830. // Mtime: time.Now().Unix(),
  2831. // Number: chrg_bchno,
  2832. // ErrMsg: res.Transreturnmessage,
  2833. // Status: 1,
  2834. // PatientId: patient_id,
  2835. // RecordTime: recordDateTime,
  2836. // Stage: 6,
  2837. // }
  2838. // service.CreateErrMsgLog(errlog)
  2839. // c.ServeSuccessJSON(map[string]interface{}{
  2840. // "failed_code": -10,
  2841. // "msg": res.Transreturnmessage,
  2842. // })
  2843. // }
  2844. // } else {
  2845. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  2846. // return
  2847. // }
  2848. // } else {
  2849. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  2850. // return
  2851. // }
  2852. //}
  2853. //上传明细----预结算
  2854. func (c *SZHisApiController) GetPreSettleInfo() {
  2855. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2856. patient_id, _ := c.GetInt64("id")
  2857. record_time := c.GetString("record_time")
  2858. admin_user_id, _ := c.GetInt64("admin_user_id")
  2859. his_patient_id, _ := c.GetInt64("his_patient_id")
  2860. reg_type, _ := c.GetInt64("p_type")
  2861. sick_type, _ := c.GetInt64("sick_type")
  2862. id_str := c.GetString("ids")
  2863. ids_arr := strings.Split(id_str, ",")
  2864. timestamp := time.Now().Unix()
  2865. tempTime := time.Unix(timestamp, 0)
  2866. timeFormat := tempTime.Format("20060102150405")
  2867. chrgBchno := rand.Intn(10000) + 1000
  2868. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(1, 10)
  2869. adminUser := c.GetAdminUserInfo()
  2870. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2871. month := time.Unix(1557042972, 0).Format("1")
  2872. year := time.Now().Format("2006")
  2873. month = time.Now().Format("01")
  2874. day := time.Now().Format("02")
  2875. timeLayout := "2006-01-02"
  2876. loc, _ := time.LoadLocation("Local")
  2877. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2878. fmt.Println(err)
  2879. if err != nil {
  2880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2881. return
  2882. }
  2883. recordDateTime := theTime.Unix()
  2884. var prescriptions []*models.HisPrescription
  2885. var start_time int64
  2886. var end_time int64
  2887. if reg_type == 1111 || reg_type == 1112 {
  2888. reg_type = 11
  2889. }
  2890. if settle_accounts_type == 1 { //日结
  2891. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  2892. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  2893. } else {
  2894. prescriptions, _ = service.GetNewHisPrescription(adminUser.CurrentOrgId, his_patient_id, recordDateTime, strconv.Itoa(int(reg_type)))
  2895. }
  2896. } else { //月结
  2897. start_time_str := c.GetString("start_time")
  2898. end_time_str := c.GetString("end_time")
  2899. timeLayout := "2006-01-02"
  2900. loc, _ := time.LoadLocation("Local")
  2901. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2902. if err != nil {
  2903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2904. return
  2905. }
  2906. recordStartTime := theStartTime.Unix()
  2907. start_time = recordStartTime
  2908. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2909. if err != nil {
  2910. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2911. return
  2912. }
  2913. recordEndTime := theEndTime.Unix()
  2914. end_time = recordEndTime
  2915. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, patient_id, recordStartTime, recordEndTime, strconv.Itoa(int(reg_type)))
  2916. }
  2917. var ids []int64
  2918. for _, item := range prescriptions {
  2919. ids = append(ids, item.ID)
  2920. }
  2921. patientPrescription, _ := service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2922. sick, _ := service.FindSickById(sick_type)
  2923. if sick.ID == 0 {
  2924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamSickTypeWrong)
  2925. return
  2926. }
  2927. adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  2928. adminRole, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2929. his, err := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2930. mz_number := his.Number
  2931. number := miConfig.Code + year + month + day +
  2932. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  2933. var doctor_name string
  2934. var doctor_code string
  2935. var drug_doctor_code string
  2936. drug_doctor_code = adminRole_two.DoctorCode
  2937. drug_doctor_name := adminRole_two.UserName
  2938. if adminRole.ID == 0 {
  2939. doctor_name = "管理员"
  2940. doctor_code = "01"
  2941. } else {
  2942. doctor_name = adminRole.UserName
  2943. doctor_code = strconv.FormatInt(admin_user_id, 10)
  2944. }
  2945. verifyCode, version_code := ReadCardGetCode("FY001" + "|" + number + "|" + miConfig.Code)
  2946. var customs []*models.CustomDetail
  2947. for _, item := range prescriptions {
  2948. if item.Type == 1 { //药品
  2949. for _, subItem := range item.HisDoctorAdviceInfo {
  2950. fmt.Println(subItem.BaseDrugLib.MedicalInsuranceNumber)
  2951. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 {
  2952. _, dose_code := service.GetDoseCode(subItem.BaseDrugLib.DrugDosageForm, adminUser.CurrentOrgId)
  2953. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber), 64)
  2954. price, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price), 64)
  2955. temp := strings.Split(subItem.FeedetlSn, "-")
  2956. newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  2957. cus := &models.CustomDetail{
  2958. PrescriptionNumber: chrg_bchno,
  2959. OrderType: "1",
  2960. ChargeSerialNumber: newFl,
  2961. Code: subItem.BaseDrugLib.MedicalInsuranceNumber,
  2962. BwCode: subItem.BaseDrugLib.Code,
  2963. CodeName: subItem.BaseDrugLib.DrugName,
  2964. Flag: "1",
  2965. Price: price,
  2966. Count: subItem.PrescribingNumber,
  2967. ChargeOrderDate: year + month + day,
  2968. DoctorCode: doctor_code,
  2969. Total: detItemFeeSumamt,
  2970. DoseCode: dose_code,
  2971. Spec: strconv.Itoa(int(subItem.BaseDrugLib.MinNumber)) + subItem.BaseDrugLib.MinUnit + ":" + fmt.Sprintf("%.2f", subItem.BaseDrugLib.Dose) + subItem.BaseDrugLib.DoseUnit,
  2972. Unit: subItem.PrescribingNumberUnit,
  2973. }
  2974. customs = append(customs, cus)
  2975. }
  2976. }
  2977. }
  2978. if item.Type == 2 { //项目
  2979. for _, subItem := range item.HisPrescriptionProject {
  2980. if len(subItem.HisProject.MedicalCode) > 0 {
  2981. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  2982. //count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  2983. count, _ := strconv.ParseFloat(strconv.FormatInt(subItem.Count, 10), 64)
  2984. temp := strings.Split(subItem.FeedetlSn, "-")
  2985. newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  2986. if subItem.Type == 2 {
  2987. cus := &models.CustomDetail{
  2988. PrescriptionNumber: chrg_bchno,
  2989. OrderType: "1",
  2990. ChargeSerialNumber: newFl,
  2991. Code: subItem.HisProject.MedicalCode,
  2992. CodeName: subItem.HisProject.ProjectName,
  2993. BwCode: subItem.HisProject.MedicalCode,
  2994. Flag: "1",
  2995. Price: subItem.Price,
  2996. Count: count,
  2997. ChargeOrderDate: year + month + day,
  2998. DoctorCode: doctor_code,
  2999. Total: detItemFeeSumamt,
  3000. DoseCode: "",
  3001. Spec: "次",
  3002. Unit: "次",
  3003. }
  3004. customs = append(customs, cus)
  3005. }
  3006. }
  3007. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 {
  3008. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  3009. //count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  3010. count, _ := strconv.ParseFloat(strconv.FormatInt(subItem.Count, 10), 64)
  3011. temp := strings.Split(subItem.FeedetlSn, "-")
  3012. newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  3013. if subItem.Type == 3 {
  3014. cus := &models.CustomDetail{
  3015. PrescriptionNumber: chrg_bchno,
  3016. OrderType: "1",
  3017. ChargeSerialNumber: newFl,
  3018. Code: subItem.GoodInfo.MedicalInsuranceNumber,
  3019. BwCode: subItem.GoodInfo.MedicalInsuranceNumber,
  3020. CodeName: subItem.GoodInfo.GoodName,
  3021. Flag: "1",
  3022. Price: subItem.Price,
  3023. Count: count,
  3024. ChargeOrderDate: year + month + day,
  3025. DoctorCode: doctor_code,
  3026. Total: detItemFeeSumamt,
  3027. DoseCode: "",
  3028. Spec: "支",
  3029. Unit: "支",
  3030. }
  3031. customs = append(customs, cus)
  3032. }
  3033. }
  3034. }
  3035. }
  3036. //
  3037. //for _, subItem := range item.HisAdditionalCharge {
  3038. // if len(subItem.XtHisAddtionConfig.Code) > 0 {
  3039. // detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  3040. //
  3041. // count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  3042. // cus := &models.CustomDetail{
  3043. // PrescriptionNumber: chrg_bchno,
  3044. // OrderType: "1",
  3045. // ChargeSerialNumber: subItem.FeedetlSn,
  3046. // Code: subItem.XtHisAddtionConfig.Code,
  3047. // CodeName: subItem.XtHisAddtionConfig.Name,
  3048. // Flag: "1",
  3049. // Price: subItem.Price,
  3050. // Count: count,
  3051. // ChargeOrderDate: year + month + day,
  3052. // DoctorCode: doctor_code,
  3053. // Total: detItemFeeSumamt,
  3054. // DoseCode: "",
  3055. // Spec: subItem.XtHisAddtionConfig.,
  3056. // }
  3057. // customs = append(customs, cus)
  3058. // }
  3059. //}
  3060. }
  3061. var pagesize int = 50
  3062. var start int = 1
  3063. var stop int
  3064. var pagecount int
  3065. var curpage int
  3066. var isSuccess bool = true
  3067. //总页数,向上取整,注意除之前要先转换类型为float64
  3068. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  3069. var ress []*Result
  3070. for curpage = 1; curpage <= pagecount; curpage++ {
  3071. if curpage == 1 {
  3072. start = 1
  3073. } else {
  3074. start = (curpage-1)*pagesize + 1
  3075. }
  3076. stop = curpage * pagesize
  3077. if stop > len(customs) {
  3078. stop = len(customs)
  3079. }
  3080. result := service.SzybFY001(doctor_name, doctor_code, miConfig.Code, customs[start-1:stop], verifyCode, number, mz_number, version_code, drug_doctor_code)
  3081. fmt.Println(result)
  3082. var dat map[string]interface{}
  3083. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3084. fmt.Println(dat)
  3085. } else {
  3086. fmt.Println(err)
  3087. }
  3088. userJSONBytes, _ := json.Marshal(dat)
  3089. var res Result
  3090. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3091. utils.ErrorLog("解析失败:%v", err)
  3092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3093. return
  3094. }
  3095. if res.Transreturncode == "00000000" {
  3096. ress = append(ress, &res)
  3097. } else {
  3098. isSuccess = false
  3099. errlog := &models.HisOrderError{
  3100. UserOrgId: adminUser.CurrentOrgId,
  3101. Ctime: time.Now().Unix(),
  3102. Mtime: time.Now().Unix(),
  3103. Number: chrg_bchno,
  3104. ErrMsg: res.Transreturnmessage,
  3105. Status: 1,
  3106. PatientId: patient_id,
  3107. RecordTime: recordDateTime,
  3108. Stage: 4,
  3109. }
  3110. service.CreateErrMsgLog(errlog)
  3111. c.ServeSuccessJSON(map[string]interface{}{
  3112. "failed_code": -10,
  3113. "msg": res.Transreturnmessage,
  3114. })
  3115. return
  3116. }
  3117. //设置变量,根据变量的值来判断上传是否成功
  3118. }
  3119. if isSuccess == true {
  3120. order := &models.HisOrder{
  3121. UserOrgId: adminUser.CurrentOrgId,
  3122. HisPatientId: 0,
  3123. PatientId: patient_id,
  3124. SettleAccountsDate: recordDateTime,
  3125. Ctime: time.Now().Unix(),
  3126. Mtime: time.Now().Unix(),
  3127. Status: 0,
  3128. Number: chrg_bchno,
  3129. Infcode: 0,
  3130. WarnMsg: "",
  3131. Cainfo: "",
  3132. ErrMsg: "",
  3133. RespondTime: "",
  3134. InfRefmsgid: "",
  3135. OrderStatus: 1,
  3136. IsMedicineInsurance: 1,
  3137. MedType: strconv.Itoa(int(reg_type)),
  3138. SettleType: settle_accounts_type,
  3139. SettleStartTime: start_time,
  3140. SettleEndTime: end_time,
  3141. Creator: admin_user_id,
  3142. Modify: admin_user_id,
  3143. OrgSetlNumber: number,
  3144. MdtrtId: mz_number,
  3145. PType: 2,
  3146. }
  3147. data, _ := json.Marshal(ress)
  3148. order.DetailLog = string(data)
  3149. err = service.CreateOrder(order)
  3150. if err != nil {
  3151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  3152. return
  3153. }
  3154. for _, subItem := range ress {
  3155. for _, item := range subItem.Transbody.Outputlist {
  3156. temp := strings.Split(item.Bkf500, "-")
  3157. var advice_id int64 = 0
  3158. var project_id int64 = 0
  3159. var types int64 = 0
  3160. id, _ := strconv.ParseInt(temp[2], 10, 64)
  3161. types, _ = strconv.ParseInt(temp[1], 10, 64)
  3162. if temp[1] == "1" {
  3163. advice_id = id
  3164. project_id = 0
  3165. } else if temp[1] == "2" {
  3166. advice_id = 0
  3167. project_id = id
  3168. }
  3169. info := &models.HisOrderInfo{
  3170. OrderNumber: order.Number,
  3171. FeedetlSn: item.Bkf500,
  3172. UploadDate: time.Now().Unix(),
  3173. AdviceId: advice_id,
  3174. DetItemFeeSumamt: item.Akc264,
  3175. Cnt: item.Akc226,
  3176. Pric: float64(item.Akc225),
  3177. PatientId: patient_id,
  3178. Status: 1,
  3179. ChrgitmLv: item.Aka065,
  3180. Mtime: time.Now().Unix(),
  3181. Ctime: time.Now().Unix(),
  3182. UserOrgId: adminUser.CurrentOrgId,
  3183. OrderId: order.ID,
  3184. ProjectId: project_id,
  3185. Type: types,
  3186. OverPricPsnPay: item.Akc268,
  3187. AllowReimburse: item.Cka319,
  3188. }
  3189. service.CreateOrderInfo(info)
  3190. }
  3191. }
  3192. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  3193. service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, his_patient_id, chrg_bchno, recordDateTime)
  3194. var total float64
  3195. for _, item := range prescriptions {
  3196. if item.Type == 1 { //药品
  3197. for _, subItem := range item.HisDoctorAdviceInfo {
  3198. total = total + (subItem.Price * subItem.PrescribingNumber)
  3199. }
  3200. }
  3201. if item.Type == 2 { //项目
  3202. for _, subItem := range item.HisPrescriptionProject {
  3203. total = total + (subItem.Price * float64(subItem.Count))
  3204. }
  3205. }
  3206. }
  3207. for _, item := range prescriptions {
  3208. for _, subItem := range item.HisAdditionalCharge {
  3209. total = total + (subItem.Price * float64(subItem.Count))
  3210. }
  3211. }
  3212. total, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", total), 64)
  3213. new_number := miConfig.Code + year + month + day +
  3214. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  3215. yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("FY004" + "|" + new_number + "|" + miConfig.Code + "|")
  3216. if ret4 == 0 {
  3217. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  3218. tempPatient, _ := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  3219. if tempPatient.ID == patient_id {
  3220. result_three := service.SzybFY004(doctor_name, doctor_code, miConfig.Code, total, yiliao_number, verifyCode, number, mz_number, version_code, drug_doctor_code, drug_doctor_name, reg_type, sick.CountryCode, new_number)
  3221. var dat map[string]interface{}
  3222. if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  3223. fmt.Println(dat)
  3224. } else {
  3225. fmt.Println(err)
  3226. }
  3227. userJSONBytes, _ := json.Marshal(dat)
  3228. var res ResultTwo
  3229. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3230. utils.ErrorLog("解析失败:%v", err)
  3231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3232. return
  3233. }
  3234. if res.Transreturncode == "00000000" {
  3235. order.OrderStatus = 1
  3236. order.Status = 1
  3237. order.PsnNo = health_card_no
  3238. order.Modify = admin_user_id
  3239. order.MedfeeSumamt = res.Transbody.Akc264
  3240. order.FundPaySumamt = res.Transbody.Akb068
  3241. order.AcctPay = res.Transbody.Akb066
  3242. order.PsnCashPay = res.Transbody.Akb067
  3243. order.PsnPartAmt = res.Transbody.Akb067
  3244. order.AccountPrice = res.Transbody.Aae240
  3245. order.MzNumber = mz_number
  3246. order.YiliaoNumber = yiliao_number
  3247. setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  3248. detailStrOne := string(setlDetailOne)
  3249. order.SzChargeInfo = detailStrOne
  3250. setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  3251. detailStrTwo := string(setlDetailTwo)
  3252. order.SzProjectInfo = detailStrTwo
  3253. setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  3254. detailStrThree := string(setlDetailThree)
  3255. order.SzMedicineInsuranceInfo = detailStrThree
  3256. order.Cainfo = result_three
  3257. order.IsPre = 1
  3258. //err = service.UpdataOrderStatusTwo(order.Number, adminUser.CurrentOrgId)
  3259. err = service.UpDateOrderTwo(order)
  3260. c.ServeSuccessJSON(map[string]interface{}{
  3261. "msg": "预结算成功",
  3262. })
  3263. } else {
  3264. //预结算报错
  3265. errlog := &models.HisOrderError{
  3266. UserOrgId: adminUser.CurrentOrgId,
  3267. Ctime: time.Now().Unix(),
  3268. Mtime: time.Now().Unix(),
  3269. Number: chrg_bchno,
  3270. ErrMsg: res.Transreturnmessage,
  3271. Status: 1,
  3272. PatientId: patient_id,
  3273. RecordTime: recordDateTime,
  3274. Stage: 20,
  3275. }
  3276. service.CreateErrMsgLog(errlog)
  3277. c.ServeSuccessJSON(map[string]interface{}{
  3278. "failed_code": -10,
  3279. "msg": res.Transreturnmessage,
  3280. })
  3281. }
  3282. } else {
  3283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  3284. return
  3285. }
  3286. } else {
  3287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  3288. return
  3289. }
  3290. } else {
  3291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePreSettleFaildParamWrong)
  3292. return
  3293. }
  3294. }
  3295. //func (c *SZHisApiController) GetSettleInfo() {
  3296. // pay_way, _ := c.GetInt64("pay_way")
  3297. // pay_price, _ := c.GetFloat("pay_price")
  3298. // pay_card_no := c.GetString("pay_card_no")
  3299. // discount_price, _ := c.GetFloat("discount_price")
  3300. // preferential_price, _ := c.GetFloat("preferential_price")
  3301. // reality_price, _ := c.GetFloat("reality_price")
  3302. // found_price, _ := c.GetFloat("found_price")
  3303. // medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  3304. // private_price, _ := c.GetFloat("private_price")
  3305. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  3306. // patient_id, _ := c.GetInt64("id")
  3307. // record_time := c.GetString("record_time")
  3308. // admin_user_id, _ := c.GetInt64("admin_user_id")
  3309. // timestamp := time.Now().Unix()
  3310. // tempTime := time.Unix(timestamp, 0)
  3311. // timeFormat := tempTime.Format("20060102150405")
  3312. // chrgBchno := rand.Intn(10000) + 1000
  3313. // chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(1, 10)
  3314. // adminUser := c.GetAdminUserInfo()
  3315. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3316. // month := time.Unix(1557042972, 0).Format("1")
  3317. // year := time.Now().Format("2006")
  3318. // month = time.Now().Format("01")
  3319. // day := time.Now().Format("02")
  3320. //
  3321. // timeLayout := "2006-01-02"
  3322. // loc, _ := time.LoadLocation("Local")
  3323. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3324. // fmt.Println(err)
  3325. // if err != nil {
  3326. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3327. // return
  3328. // }
  3329. // recordDateTime := theTime.Unix()
  3330. //
  3331. // var prescriptions []*models.HisPrescription
  3332. //
  3333. // var start_time int64
  3334. // var end_time int64
  3335. //
  3336. // if settle_accounts_type == 1 { //日结
  3337. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3338. //
  3339. // } else { //月结
  3340. // start_time_str := c.GetString("start_time")
  3341. // end_time_str := c.GetString("end_time")
  3342. // timeLayout := "2006-01-02"
  3343. // loc, _ := time.LoadLocation("Local")
  3344. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3345. // if err != nil {
  3346. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3347. // return
  3348. // }
  3349. // recordStartTime := theStartTime.Unix()
  3350. // start_time = recordStartTime
  3351. //
  3352. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3353. // if err != nil {
  3354. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3355. // return
  3356. // }
  3357. // recordEndTime := theEndTime.Unix()
  3358. // end_time = recordEndTime
  3359. //
  3360. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
  3361. // }
  3362. //
  3363. // var ids []int64
  3364. // for _, item := range prescriptions {
  3365. // ids = append(ids, item.ID)
  3366. // }
  3367. //
  3368. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3369. //
  3370. // adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  3371. //
  3372. // adminRole, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3373. // his, err := service.GetHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3374. // mz_number := his.Number
  3375. // number := miConfig.Code + year + month + day +
  3376. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  3377. // var doctor_name string
  3378. // var doctor_code string
  3379. // var drug_doctor_code string
  3380. // drug_doctor_code = adminRole_two.DoctorCode
  3381. // drug_doctor_name := adminRole_two.UserName
  3382. //
  3383. // if adminRole.ID == 0 {
  3384. // doctor_name = "黄亦轩"
  3385. // doctor_code = "1"
  3386. // } else {
  3387. // doctor_name = adminRole.UserName
  3388. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  3389. // }
  3390. //
  3391. // verifyCode, version_code := ReadCardGetCode("FY001" + "|" + number + "|" + miConfig.Code)
  3392. // //verifyCode := "000000|bf885fa312a7f92861d6b61542a637fa"
  3393. // //version_code := "V0.3"
  3394. // var customs []*models.CustomDetail
  3395. // for _, item := range prescriptions {
  3396. // if item.Type == 1 { //药品
  3397. // for _, subItem := range item.HisDoctorAdviceInfo {
  3398. // fmt.Println(subItem.BaseDrugLib.MedicalInsuranceNumber)
  3399. //
  3400. // if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 {
  3401. // _, dose_code := service.GetDoseCode(subItem.BaseDrugLib.DrugDosageForm, adminUser.CurrentOrgId)
  3402. // detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber), 64)
  3403. // price, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price), 64)
  3404. // temp := strings.Split(subItem.FeedetlSn, "-")
  3405. // newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  3406. //
  3407. // cus := &models.CustomDetail{
  3408. // PrescriptionNumber: chrg_bchno,
  3409. // OrderType: "1",
  3410. // ChargeSerialNumber: newFl,
  3411. // Code: subItem.BaseDrugLib.MedicalInsuranceNumber,
  3412. // CodeName: subItem.BaseDrugLib.DrugName,
  3413. // Flag: "1",
  3414. // Price: price,
  3415. // Count: subItem.PrescribingNumber,
  3416. // ChargeOrderDate: year + month + day,
  3417. // DoctorCode: doctor_code,
  3418. // Total: detItemFeeSumamt,
  3419. // DoseCode: dose_code,
  3420. // Spec: subItem.BaseDrugLib.DrugSpec,
  3421. // }
  3422. // customs = append(customs, cus)
  3423. // }
  3424. // }
  3425. // }
  3426. //
  3427. // if item.Type == 2 { //项目
  3428. // for _, subItem := range item.HisPrescriptionProject {
  3429. // if len(subItem.HisProject.MedicalCode) > 0 {
  3430. // detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  3431. //
  3432. // count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  3433. // temp := strings.Split(subItem.FeedetlSn, "-")
  3434. // newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  3435. //
  3436. // cus := &models.CustomDetail{
  3437. // PrescriptionNumber: chrg_bchno,
  3438. // OrderType: "1",
  3439. // ChargeSerialNumber: newFl,
  3440. // Code: subItem.HisProject.MedicalCode,
  3441. // CodeName: subItem.HisProject.ProjectName,
  3442. // Flag: "1",
  3443. // Price: subItem.Price,
  3444. // Count: count,
  3445. // ChargeOrderDate: year + month + day,
  3446. // DoctorCode: doctor_code,
  3447. // Total: detItemFeeSumamt,
  3448. // DoseCode: "",
  3449. // Spec: "次",
  3450. // }
  3451. // customs = append(customs, cus)
  3452. // }
  3453. // }
  3454. // }
  3455. // //
  3456. // //for _, subItem := range item.HisAdditionalCharge {
  3457. // // if len(subItem.XtHisAddtionConfig.Code) > 0 {
  3458. // // detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  3459. // //
  3460. // // count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  3461. // // cus := &models.CustomDetail{
  3462. // // PrescriptionNumber: chrg_bchno,
  3463. // // OrderType: "1",
  3464. // // ChargeSerialNumber: subItem.FeedetlSn,
  3465. // // Code: subItem.XtHisAddtionConfig.Code,
  3466. // // CodeName: subItem.XtHisAddtionConfig.Name,
  3467. // // Flag: "1",
  3468. // // Price: subItem.Price,
  3469. // // Count: count,
  3470. // // ChargeOrderDate: year + month + day,
  3471. // // DoctorCode: doctor_code,
  3472. // // Total: detItemFeeSumamt,
  3473. // // DoseCode: "",
  3474. // // Spec: subItem.XtHisAddtionConfig.,
  3475. // // }
  3476. // // customs = append(customs, cus)
  3477. // // }
  3478. // //}
  3479. // }
  3480. //
  3481. // var pagesize int = 50
  3482. // var start int = 1
  3483. // var stop int
  3484. // var pagecount int
  3485. // var curpage int
  3486. // var isSuccess bool = true
  3487. // //总页数,向上取整,注意除之前要先转换类型为float64
  3488. // pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  3489. //
  3490. // var ress []*Result
  3491. // for curpage = 1; curpage <= pagecount; curpage++ {
  3492. // if curpage == 1 {
  3493. // start = 1
  3494. // } else {
  3495. // start = (curpage-1)*pagesize + 1
  3496. // }
  3497. // stop = curpage * pagesize
  3498. // if stop > len(customs) {
  3499. // stop = len(customs)
  3500. // }
  3501. // result := service.SzybFY001(doctor_name, doctor_code, miConfig.Code, customs[start-1:stop], verifyCode, number, mz_number, version_code, drug_doctor_code)
  3502. // fmt.Println(result)
  3503. //
  3504. // var dat map[string]interface{}
  3505. // if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3506. // fmt.Println(dat)
  3507. // } else {
  3508. // fmt.Println(err)
  3509. // }
  3510. //
  3511. // userJSONBytes, _ := json.Marshal(dat)
  3512. //
  3513. // var res Result
  3514. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3515. // utils.ErrorLog("解析失败:%v", err)
  3516. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3517. // return
  3518. // }
  3519. // if res.Transreturncode == "00000000" {
  3520. // ress = append(ress, &res)
  3521. // } else {
  3522. // isSuccess = false
  3523. // errlog := &models.HisOrderError{
  3524. // UserOrgId: adminUser.CurrentOrgId,
  3525. // Ctime: time.Now().Unix(),
  3526. // Mtime: time.Now().Unix(),
  3527. // Number: chrg_bchno,
  3528. // ErrMsg: res.Transreturnmessage,
  3529. // Status: 1,
  3530. // PatientId: patient_id,
  3531. // RecordTime: recordDateTime,
  3532. // Stage: 4,
  3533. // }
  3534. // service.CreateErrMsgLog(errlog)
  3535. // c.ServeSuccessJSON(map[string]interface{}{
  3536. // "failed_code": -10,
  3537. // "msg": res.Transreturnmessage,
  3538. // })
  3539. // return
  3540. // }
  3541. // //设置变量,根据变量的值来判断上传是否成功
  3542. // }
  3543. // if isSuccess == true {
  3544. // order := &models.HisOrder{
  3545. // UserOrgId: adminUser.CurrentOrgId,
  3546. // HisPatientId: 0,
  3547. // PatientId: patient_id,
  3548. // SettleAccountsDate: recordDateTime,
  3549. // Ctime: time.Now().Unix(),
  3550. // Mtime: time.Now().Unix(),
  3551. // Status: 1,
  3552. // Number: chrg_bchno,
  3553. // Infcode: 0,
  3554. // WarnMsg: "",
  3555. // Cainfo: "",
  3556. // ErrMsg: "",
  3557. // RespondTime: "",
  3558. // InfRefmsgid: "",
  3559. // OrderStatus: 1,
  3560. // IsMedicineInsurance: 1,
  3561. // SettleType: settle_accounts_type,
  3562. // SettleStartTime: start_time,
  3563. // SettleEndTime: end_time,
  3564. // Creator: admin_user_id,
  3565. // Modify: admin_user_id,
  3566. // OrgSetlNumber: number,
  3567. // }
  3568. // data, _ := json.Marshal(ress)
  3569. // order.DetailLog = string(data)
  3570. //
  3571. // err = service.CreateOrder(order)
  3572. // if err != nil {
  3573. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  3574. // return
  3575. // }
  3576. //
  3577. // for _, subItem := range ress {
  3578. // for _, item := range subItem.Transbody.Outputlist {
  3579. //
  3580. // temp := strings.Split(item.Bkf500, "-")
  3581. // var advice_id int64 = 0
  3582. // var project_id int64 = 0
  3583. // var types int64 = 0
  3584. //
  3585. // id, _ := strconv.ParseInt(temp[2], 10, 64)
  3586. // types, _ = strconv.ParseInt(temp[1], 10, 64)
  3587. //
  3588. // if temp[1] == "1" {
  3589. // advice_id = id
  3590. // project_id = 0
  3591. // } else if temp[1] == "2" {
  3592. // advice_id = 0
  3593. // project_id = id
  3594. // }
  3595. //
  3596. // info := &models.HisOrderInfo{
  3597. // OrderNumber: order.Number,
  3598. // FeedetlSn: item.Bkf500,
  3599. // UploadDate: time.Now().Unix(),
  3600. // AdviceId: advice_id,
  3601. // DetItemFeeSumamt: item.Akc264,
  3602. // Cnt: item.Akc226,
  3603. // Pric: float64(item.Akc225),
  3604. // PatientId: patient_id,
  3605. // Status: 1,
  3606. // ChrgitmLv: item.Aka065,
  3607. // Mtime: time.Now().Unix(),
  3608. // Ctime: time.Now().Unix(),
  3609. // UserOrgId: adminUser.CurrentOrgId,
  3610. // OrderId: order.ID,
  3611. // ProjectId: project_id,
  3612. // Type: types,
  3613. //
  3614. // OverPricPsnPay: item.Akc268,
  3615. // AllowReimburse: item.Cka319,
  3616. // }
  3617. // service.CreateOrderInfo(info)
  3618. //
  3619. // }
  3620. // }
  3621. // service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  3622. // service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patient_id, chrg_bchno, recordDateTime)
  3623. // var total float64
  3624. // for _, item := range prescriptions {
  3625. // if item.Type == 1 { //药品
  3626. // for _, subItem := range item.HisDoctorAdviceInfo {
  3627. // total = total + (subItem.Price * subItem.PrescribingNumber)
  3628. // }
  3629. // }
  3630. // if item.Type == 2 { //项目
  3631. // for _, subItem := range item.HisPrescriptionProject {
  3632. // total = total + (subItem.Price * float64(subItem.Count))
  3633. // }
  3634. // }
  3635. // }
  3636. // for _, item := range prescriptions {
  3637. // for _, subItem := range item.HisAdditionalCharge {
  3638. // total = total + (subItem.Price * float64(subItem.Count))
  3639. // }
  3640. // }
  3641. //
  3642. // yiliao_number, id_card_number, verifyCode, version_code, _, ret4 := ReadBasCardGetNumber("FY005" + "|" + number + "|" + miConfig.Code + "|")
  3643. // if ret4 == 0 {
  3644. // //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  3645. // tempPatient, _ := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  3646. // if tempPatient.ID == patient_id {
  3647. //
  3648. // result_three := service.SzybFY005(doctor_name, doctor_code, miConfig.Code, total, yiliao_number, verifyCode, number, mz_number, version_code, drug_doctor_code, drug_doctor_name, his.MedicalTreatmentType)
  3649. // var dat map[string]interface{}
  3650. // if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  3651. // fmt.Println(dat)
  3652. // } else {
  3653. // fmt.Println(err)
  3654. // }
  3655. // userJSONBytes, _ := json.Marshal(dat)
  3656. // var res ResultTwo
  3657. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3658. // utils.ErrorLog("解析失败:%v", err)
  3659. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3660. // return
  3661. // }
  3662. //
  3663. // if res.Transreturncode == "00000000" {
  3664. // order.OrderStatus = 2
  3665. // order.PayWay = pay_way
  3666. // order.PayPrice = pay_price
  3667. // order.PayCardNo = pay_card_no
  3668. // order.DiscountPrice = discount_price
  3669. // order.PreferentialPrice = preferential_price
  3670. // order.RealityPrice = reality_price
  3671. // order.FoundPrice = found_price
  3672. // order.MedicalInsurancePrice = medical_insurance_price
  3673. // order.PrivatePrice = private_price
  3674. // order.Modify = admin_user_id
  3675. // order.MedfeeSumamt = res.Transbody.Akc264
  3676. // order.SetlId = res.Transbody.Ckc618
  3677. // order.FundPaySumamt = res.Transbody.Akb068
  3678. // order.AcctPay = res.Transbody.Akb066
  3679. // order.PsnCashPay = res.Transbody.Akb067
  3680. // order.PsnPartAmt = res.Transbody.Akb067
  3681. // order.AccountPrice = res.Transbody.Aae240
  3682. // order.MzNumber = mz_number
  3683. // order.YiliaoNumber = yiliao_number
  3684. // setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  3685. // detailStrOne := string(setlDetailOne)
  3686. // order.SzChargeInfo = detailStrOne
  3687. // setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  3688. // detailStrTwo := string(setlDetailTwo)
  3689. // order.SzProjectInfo = detailStrTwo
  3690. // setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  3691. // detailStrThree := string(setlDetailThree)
  3692. // order.SzMedicineInsuranceInfo = detailStrThree
  3693. // order.Cainfo = result_three
  3694. // err = service.UpdataOrderStatusTwo(order.Number, adminUser.CurrentOrgId)
  3695. // err = service.UpDateOrderTwo(order)
  3696. // c.ServeSuccessJSON(map[string]interface{}{
  3697. // "msg": "结算成功",
  3698. // })
  3699. // } else {
  3700. // //结算报错
  3701. // errlog := &models.HisOrderError{
  3702. // UserOrgId: adminUser.CurrentOrgId,
  3703. // Ctime: time.Now().Unix(),
  3704. // Mtime: time.Now().Unix(),
  3705. // Number: chrg_bchno,
  3706. // ErrMsg: res.Transreturnmessage,
  3707. // Status: 1,
  3708. // PatientId: patient_id,
  3709. // RecordTime: recordDateTime,
  3710. // Stage: 6,
  3711. // }
  3712. // service.CreateErrMsgLog(errlog)
  3713. // c.ServeSuccessJSON(map[string]interface{}{
  3714. // "failed_code": -10,
  3715. // "msg": res.Transreturnmessage,
  3716. // })
  3717. // }
  3718. // } else {
  3719. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  3720. // return
  3721. // }
  3722. // } else {
  3723. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  3724. // return
  3725. // }
  3726. // } else {
  3727. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePreSettleFaildParamWrong)
  3728. // return
  3729. // }
  3730. //}
  3731. //结算
  3732. //func (c *SZHisApiController) GetSettleInfo() {
  3733. // patient_id, _ := c.GetInt64("id")
  3734. // order_id, _ := c.GetInt64("order_id")
  3735. // record_time := c.GetString("record_time")
  3736. // pay_way, _ := c.GetInt64("pay_way")
  3737. // pay_price, _ := c.GetFloat("pay_price")
  3738. // pay_card_no := c.GetString("pay_card_no")
  3739. // discount_price, _ := c.GetFloat("discount_price")
  3740. // preferential_price, _ := c.GetFloat("preferential_price")
  3741. // reality_price, _ := c.GetFloat("reality_price")
  3742. // found_price, _ := c.GetFloat("found_price")
  3743. // medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  3744. // private_price, _ := c.GetFloat("private_price")
  3745. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  3746. // admin_user_id, _ := c.GetInt64("admin_user_id")
  3747. //
  3748. // timeLayout := "2006-01-02"
  3749. // loc, _ := time.LoadLocation("Local")
  3750. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3751. // if err != nil {
  3752. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3753. // return
  3754. // }
  3755. // recordDateTime := theTime.Unix()
  3756. // adminUser := c.GetAdminUserInfo()
  3757. //
  3758. // var prescriptions []*models.HisPrescription
  3759. //
  3760. // data := make(map[string]interface{})
  3761. // if settle_accounts_type == 1 { //日结
  3762. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3763. // data["pre"] = prescriptions
  3764. //
  3765. // } else { //月结
  3766. // start_time_str := c.GetString("start_time")
  3767. // end_time_str := c.GetString("end_time")
  3768. // timeLayout := "2006-01-02"
  3769. // loc, _ := time.LoadLocation("Local")
  3770. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3771. // if err != nil {
  3772. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3773. // return
  3774. // }
  3775. // recordStartTime := theStartTime.Unix()
  3776. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3777. // if err != nil {
  3778. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3779. // return
  3780. // }
  3781. // recordEndTime := theEndTime.Unix()
  3782. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
  3783. // data["pre"] = prescriptions
  3784. //
  3785. // }
  3786. //
  3787. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3788. // his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3789. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3790. // strconv.FormatInt(his.PatientId, 10)
  3791. //
  3792. // order_src, _ := service.GetHisOrderByID(order_id)
  3793. //
  3794. // if order_src.ID == 0 {
  3795. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  3796. // return
  3797. // }
  3798. //
  3799. // config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3800. // if config.IsOpen == 1 { //对接了医保,走医保流程
  3801. // if order_src.OrderStatus != 2 {
  3802. // var total float64
  3803. // for _, item := range prescriptions {
  3804. // if item.Type == 1 { //药品
  3805. // for _, subItem := range item.HisDoctorAdviceInfo {
  3806. // total = total + (subItem.Price * subItem.PrescribingNumber)
  3807. // }
  3808. // }
  3809. // if item.Type == 2 { //项目
  3810. // for _, subItem := range item.HisPrescriptionProject {
  3811. // total = total + (subItem.Price * float64(subItem.Count))
  3812. // }
  3813. // }
  3814. // }
  3815. //
  3816. // for _, item := range prescriptions {
  3817. // for _, subItem := range item.HisAdditionalCharge {
  3818. // total = total + (subItem.Price * float64(subItem.Count))
  3819. // }
  3820. // }
  3821. //
  3822. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3823. //
  3824. // adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  3825. //
  3826. // var drug_doctor string
  3827. // drug_doctor = adminRole_two.DoctorCode
  3828. // drug_doctor_name := adminRole_two.UserName
  3829. // //结算流程
  3830. // var doctor_name string
  3831. // var doctor_code string
  3832. // if roles.ID == 0 {
  3833. // doctor_name = "黄亦轩"
  3834. // doctor_code = "1010"
  3835. // } else {
  3836. // doctor_name = roles.UserName
  3837. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  3838. // }
  3839. // number := order_src.OrgSetlNumber
  3840. // mz_number := his.Number
  3841. // verifyCode, version_code := ReadCardGetCode("FY005" + "|" + number + "|" + miConfig.Code)
  3842. //
  3843. // //verifyCode := "000000|707c35a62c2f0609d7b0a811649f3913"
  3844. // //version_code := "V0.3"
  3845. // yiliao_number, id_card_number, verifyCode, version_code, err, ret4 := ReadBasCardGetNumber("FY005" + "|" + number + "|" + miConfig.Code)
  3846. // yiliao_number := his.YiliaoNumber
  3847. // result_three := service.SzybFY005(doctor_name, doctor_code, miConfig.Code, total, yiliao_number, verifyCode, number, mz_number, version_code, drug_doctor, drug_doctor_name)
  3848. // var dat map[string]interface{}
  3849. // if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  3850. // fmt.Println(dat)
  3851. // } else {
  3852. // fmt.Println(err)
  3853. // }
  3854. // userJSONBytes, _ := json.Marshal(dat)
  3855. // var res ResultTwo
  3856. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3857. // utils.ErrorLog("解析失败:%v", err)
  3858. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3859. // return
  3860. // }
  3861. //
  3862. // if res.Transreturncode == "00000000" {
  3863. // order_src.OrderStatus = 2
  3864. // order_src.PayWay = pay_way
  3865. // order_src.PayPrice = pay_price
  3866. // order_src.PayCardNo = pay_card_no
  3867. // order_src.DiscountPrice = discount_price
  3868. // order_src.PreferentialPrice = preferential_price
  3869. // order_src.RealityPrice = reality_price
  3870. // order_src.FoundPrice = found_price
  3871. // order_src.MedicalInsurancePrice = medical_insurance_price
  3872. // order_src.PrivatePrice = private_price
  3873. // order_src.Creator = order_src.Creator
  3874. // order_src.Modify = roles.ID
  3875. // order_src.MedfeeSumamt = res.Transbody.Akc264
  3876. // order_src.SetlId = res.Transbody.Ckc618
  3877. // order_src.FundPaySumamt = res.Transbody.Akb068
  3878. // order_src.AcctPay = res.Transbody.Akb066
  3879. // order_src.PsnCashPay = res.Transbody.Akb067
  3880. // order_src.PsnPartAmt = res.Transbody.Akb067
  3881. // order_src.AccountPrice = res.Transbody.Aae240
  3882. // order_src.MzNumber = mz_number
  3883. // order_src.YiliaoNumber = yiliao_number
  3884. // setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  3885. // detailStrOne := string(setlDetailOne)
  3886. // order_src.SzChargeInfo = detailStrOne
  3887. // setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  3888. // detailStrTwo := string(setlDetailTwo)
  3889. // order_src.SzProjectInfo = detailStrTwo
  3890. // setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  3891. // detailStrThree := string(setlDetailThree)
  3892. // order_src.SzMedicineInsuranceInfo = detailStrThree
  3893. // order_src.Cainfo = result_three
  3894. //
  3895. // err = service.UpdataOrderStatusTwo(order_src.Number, adminUser.CurrentOrgId)
  3896. // err = service.UpDateOrder(order_src)
  3897. //
  3898. // c.ServeSuccessJSON(map[string]interface{}{
  3899. // "msg": "结算成功",
  3900. // })
  3901. // } else {
  3902. // //version_code := "0.03"
  3903. // c.ServeSuccessJSON(map[string]interface{}{
  3904. // "failed_code": -10,
  3905. // "msg": res.Transreturnmessage,
  3906. // })
  3907. //
  3908. // }
  3909. // } else {
  3910. //
  3911. // //错误提示
  3912. //
  3913. // }
  3914. // } else {
  3915. // //错误提示
  3916. //
  3917. // }
  3918. //}
  3919. //当月退费
  3920. func (c *SZHisApiController) Refund() {
  3921. order_id, _ := c.GetInt64("order_id")
  3922. record_time := c.GetString("record_time")
  3923. //patient_id, _ := c.GetInt64("patient_id")
  3924. //his_patient_id, _ := c.GetInt64("his_patient_id")
  3925. admin_user_id, _ := c.GetInt64("admin_user_id")
  3926. timeLayout := "2006-01-02"
  3927. loc, _ := time.LoadLocation("Local")
  3928. adminUser := c.GetAdminUserInfo()
  3929. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3930. fmt.Println(err)
  3931. if err != nil {
  3932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3933. return
  3934. }
  3935. recordDateTime := theTime.Unix()
  3936. fmt.Println(recordDateTime)
  3937. var order models.HisOrder
  3938. order, _ = service.GetHisOrderByID(order_id)
  3939. if order.ID == 0 {
  3940. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  3941. return
  3942. }
  3943. //his, _ := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, theTime.Unix())
  3944. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3945. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3946. //结算流程
  3947. var doctor_name string
  3948. var doctor_code string
  3949. if roles.ID == 0 {
  3950. doctor_name = "管理员"
  3951. doctor_code = "01"
  3952. } else {
  3953. doctor_name = roles.UserName
  3954. doctor_code = strconv.FormatInt(admin_user_id, 10)
  3955. }
  3956. month := time.Unix(1557042972, 0).Format("1")
  3957. year := time.Now().Format("2006")
  3958. month = time.Now().Format("01")
  3959. day := time.Now().Format("02")
  3960. //number := miConfig.Code + year + month + day + "1367866"
  3961. number := miConfig.Code + year + month + day +
  3962. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  3963. //number := miConfig.Code + year + month + day + "1590003"
  3964. //流水号
  3965. //number_two := miConfig.Code + "-" + year + month + day + "-" + strconv.FormatInt(patient_id, 10)
  3966. verifyCode, version_code := ReadCardGetCode("JY002" + "|" + number + "|" + miConfig.Code)
  3967. //version_code := "V0.3"
  3968. //
  3969. //verifyCode := "000000|9972fca7ba9471c7dbe08324b2e31f70"
  3970. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3971. order_infos, _ := service.GetHisOrderInfoByNumber(order.Number)
  3972. var customs []*models.CustomDetail
  3973. for _, item := range order_infos {
  3974. cus := &models.CustomDetail{
  3975. PrescriptionNumber: item.OrderNumber,
  3976. ChargeSerialNumber: item.FeedetlSn,
  3977. }
  3978. customs = append(customs, cus)
  3979. }
  3980. if config.IsOpen == 1 { //对接了医保,走医保流程
  3981. result := service.SzybJY002(doctor_name, doctor_code, miConfig.Code, order.OrgSetlNumber, order.MzNumber, verifyCode, number, version_code)
  3982. fmt.Println(result)
  3983. var dat map[string]interface{}
  3984. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3985. fmt.Println(dat)
  3986. } else {
  3987. fmt.Println(err)
  3988. }
  3989. userJSONBytes, _ := json.Marshal(dat)
  3990. var res ResultThree
  3991. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3992. utils.ErrorLog("解析失败:%v", err)
  3993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3994. return
  3995. }
  3996. if res.Transreturncode == "00000000" {
  3997. service.UpdataOrderlog(order_id, adminUser.CurrentOrgId, result)
  3998. service.UpdataOrderStatusSZ(order_id, order.Number, adminUser.CurrentOrgId)
  3999. service.UpdataOrderInfoStatus(order.ID, order.Number, adminUser.CurrentOrgId)
  4000. c.ServeSuccessJSON(map[string]interface{}{
  4001. "msg": "退费成功",
  4002. })
  4003. } else {
  4004. c.ServeSuccessJSON(map[string]interface{}{
  4005. "failed_code": -10,
  4006. "msg": res.Transreturnmessage,
  4007. })
  4008. }
  4009. }
  4010. }
  4011. //跨月退费
  4012. func (c *SZHisApiController) MonthRefund() {
  4013. order_id, _ := c.GetInt64("order_id")
  4014. record_time := c.GetString("record_time")
  4015. patient_id, _ := c.GetInt64("patient_id")
  4016. admin_user_id, _ := c.GetInt64("admin_user_id")
  4017. timeLayout := "2006-01-02"
  4018. loc, _ := time.LoadLocation("Local")
  4019. adminUser := c.GetAdminUserInfo()
  4020. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4021. fmt.Println(err)
  4022. if err != nil {
  4023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4024. return
  4025. }
  4026. recordDateTime := theTime.Unix()
  4027. var order models.HisOrder
  4028. order, _ = service.GetHisOrderByID(order_id)
  4029. if order.ID == 0 {
  4030. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  4031. }
  4032. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4033. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4034. //结算流程
  4035. var doctor_name string
  4036. var doctor_code string
  4037. if roles.ID == 0 {
  4038. doctor_name = "管理员"
  4039. doctor_code = "01"
  4040. } else {
  4041. doctor_name = roles.UserName
  4042. doctor_code = strconv.FormatInt(admin_user_id, 10)
  4043. }
  4044. month := time.Unix(1557042972, 0).Format("1")
  4045. year := time.Now().Format("2006")
  4046. month = time.Now().Format("01")
  4047. day := time.Now().Format("02")
  4048. //流水号
  4049. number_two := miConfig.Code + "-" + year + month + day + "-" + strconv.FormatInt(patient_id, 10)
  4050. //verifyCode,version_code := ReadCardGetCode("JY002" + "|" + number_two + "|" + miConfig.Code)
  4051. version_code := "0.03"
  4052. fmt.Println(number_two)
  4053. verifyCode := "000000|0872038667cc34efdc35ce4668589a5f"
  4054. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4055. if config.IsOpen == 1 { //对接了医保,走医保流程
  4056. result := service.SzybJY003(doctor_name, doctor_code, miConfig.Code, order.OrgSetlNumber, order.MzNumber, verifyCode, version_code)
  4057. fmt.Println(result)
  4058. var dat map[string]interface{}
  4059. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4060. fmt.Println(dat)
  4061. } else {
  4062. fmt.Println(err)
  4063. }
  4064. userJSONBytes, _ := json.Marshal(dat)
  4065. var res ResultThree
  4066. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4067. utils.ErrorLog("解析失败:%v", err)
  4068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4069. return
  4070. }
  4071. if res.Transreturncode == "00000000" {
  4072. c.ServeSuccessJSON(map[string]interface{}{
  4073. "msg": "退费成功",
  4074. })
  4075. } else {
  4076. }
  4077. }
  4078. }
  4079. //查询
  4080. func (c *SZHisApiController) GetSettleAccounts() {
  4081. order_id, _ := c.GetInt64("order_id")
  4082. record_time := c.GetString("record_time")
  4083. patient_id, _ := c.GetInt64("patient_id")
  4084. admin_user_id, _ := c.GetInt64("admin_user_id")
  4085. timeLayout := "2006-01-02"
  4086. loc, _ := time.LoadLocation("Local")
  4087. adminUser := c.GetAdminUserInfo()
  4088. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4089. fmt.Println(err)
  4090. if err != nil {
  4091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4092. return
  4093. }
  4094. recordDateTime := theTime.Unix()
  4095. fmt.Println(recordDateTime)
  4096. var order models.HisOrder
  4097. order, _ = service.GetHisOrderByID(order_id)
  4098. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, patient_id)
  4099. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  4100. adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  4101. his, _ := service.GetHisPatientInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  4102. yiliao_leibie := ""
  4103. switch order.MedType {
  4104. case "11":
  4105. yiliao_leibie = "普通门诊"
  4106. break
  4107. case "12":
  4108. yiliao_leibie = "家庭通道"
  4109. break
  4110. case "13":
  4111. yiliao_leibie = "门诊大病"
  4112. break
  4113. case "14":
  4114. yiliao_leibie = "重疾特药"
  4115. break
  4116. case "15":
  4117. yiliao_leibie = "门诊慢病"
  4118. break
  4119. case "16":
  4120. yiliao_leibie = "门诊特检"
  4121. break
  4122. case "17":
  4123. yiliao_leibie = "健康体检"
  4124. break
  4125. case "18":
  4126. yiliao_leibie = "预防接种"
  4127. break
  4128. case "19":
  4129. yiliao_leibie = "门诊输血"
  4130. break
  4131. case "91":
  4132. yiliao_leibie = "新冠肺炎门诊"
  4133. break
  4134. }
  4135. //departments, _ := service.Get(patientPrescription.Departments)
  4136. departments, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  4137. if order.ID == 0 {
  4138. //order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  4139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  4140. return
  4141. }
  4142. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4143. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4144. //结算流程
  4145. var doctor_name string
  4146. var doctor_code string
  4147. if roles.ID == 0 {
  4148. doctor_name = "管理员"
  4149. doctor_code = "01"
  4150. } else {
  4151. doctor_name = roles.UserName
  4152. doctor_code = strconv.FormatInt(admin_user_id, 10)
  4153. }
  4154. //month := time.Unix(1557042972, 0).Format("1")
  4155. //year := time.Now().Format("2006")
  4156. //month = time.Now().Format("01")
  4157. //day := time.Now().Format("02")
  4158. //流水号
  4159. //number_two := miConfig.Code + "-" + year + month + day + "-" + strconv.FormatInt(patient_id, 10)
  4160. //fmt.Println(number_two)
  4161. verifyCode, version_code := ReadCardGetCode("JY001" + "|" + order.OrgSetlNumber + "|" + miConfig.Code)
  4162. //version_code := "V0.3"
  4163. //verifyCode := "000000|2c9854287e7c3cbc34439ab8e5157816"
  4164. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4165. if config.IsOpen == 1 { //对接了医保,走医保流程
  4166. //temp_mz_number := miConfig.Code + year + month + day +
  4167. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000))
  4168. //tempVerifyCode, tempVersionCode := ReadCardGetCode("XX001" + "|" + temp_mz_number + "|" + miConfig.Code)
  4169. //yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("MZ002" + "|" + number + "|" + miConfig.Code + "|")
  4170. //yiliao_number = "%GALMAFXJGKUKZNKWAIUH?;07857319025346309758?"
  4171. //result001 := service.SzybXX001(opera_name, opera_code, miConfig.Code, yiliao_number, tempVerifyCode, temp_mz_number, tempVersionCode)
  4172. result := service.SzybJY001(doctor_name, doctor_code, miConfig.Code, order.OrgSetlNumber, order.MzNumber, verifyCode, version_code)
  4173. fmt.Println(result)
  4174. var dat map[string]interface{}
  4175. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4176. fmt.Println(dat)
  4177. } else {
  4178. fmt.Println(err)
  4179. }
  4180. userJSONBytes, _ := json.Marshal(dat)
  4181. var res ResultFour
  4182. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4183. utils.ErrorLog("解析失败:%v", err)
  4184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4185. return
  4186. }
  4187. if res.Transreturncode == "00000000" {
  4188. var dat2 map[string]interface{}
  4189. if err := json.Unmarshal([]byte(his.PatientInfo), &dat2); err == nil {
  4190. fmt.Println(dat2)
  4191. } else {
  4192. fmt.Println(err)
  4193. }
  4194. userJSONBytes2, _ := json.Marshal(dat2)
  4195. var res2 ResultMZ001
  4196. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  4197. utils.ErrorLog("解析失败:%v", err)
  4198. }
  4199. c.ServeSuccessJSON(map[string]interface{}{
  4200. "result": res,
  4201. "org_name": miConfig.OrgName,
  4202. "org_code": miConfig.Code,
  4203. "patient_name": patient.Name,
  4204. "doctor_code": adminRole_two.DoctorCode,
  4205. "doctor_name": doctor_name,
  4206. "health_card_no": order.PsnNo,
  4207. "health_card_no_two": res2.Transbody.Aaz500,
  4208. "order_number": order.Number,
  4209. "department": departments.Name,
  4210. "yiliao_leibie": yiliao_leibie,
  4211. "before_money": res2.Transbody.Aae240,
  4212. "after_money": order.AccountPrice,
  4213. "dialysis_no": patient.DialysisNo,
  4214. "patient_info": res2,
  4215. })
  4216. } else {
  4217. c.ServeSuccessJSON(map[string]interface{}{
  4218. "failed_code": -10,
  4219. "msg": res.Transreturnmessage,
  4220. })
  4221. }
  4222. }
  4223. }
  4224. //费用录入取消
  4225. //func (c *SZHisApiController) CancelOrderDetail() {
  4226. // order_id, _ := c.GetInt64("order_id")
  4227. // record_time := c.GetString("record_time")
  4228. // patient_id, _ := c.GetInt64("patient_id")
  4229. // admin_user_id, _ := c.GetInt64("admin_user_id")
  4230. // timeLayout := "2006-01-02"
  4231. // loc, _ := time.LoadLocation("Local")
  4232. // adminUser := c.GetAdminUserInfo()
  4233. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4234. // fmt.Println(err)
  4235. // if err != nil {
  4236. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4237. // return
  4238. // }
  4239. // recordDateTime := theTime.Unix()
  4240. // var order models.HisOrder
  4241. // order, _ = service.GetHisOrderByID(order_id)
  4242. //
  4243. // if order.ID == 0 {
  4244. // order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  4245. //
  4246. // }
  4247. //
  4248. // order_infos, _ := service.GetHisOrderInfoByNumber(order.Number)
  4249. //
  4250. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4251. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4252. // //结算流程
  4253. // var doctor_name string
  4254. // var doctor_code string
  4255. // if roles.ID == 0 {
  4256. // doctor_name = "管理员"
  4257. // doctor_code = "1001"
  4258. // } else {
  4259. // doctor_name = roles.UserName
  4260. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  4261. //
  4262. // }
  4263. // var customs []*models.CustomDetail
  4264. //
  4265. // for _, item := range order_infos {
  4266. // cus := &models.CustomDetail{
  4267. // PrescriptionNumber: item.OrderNumber,
  4268. // ChargeSerialNumber: item.FeedetlSn,
  4269. // }
  4270. // customs = append(customs, cus)
  4271. // }
  4272. // his, _ := service.GetHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  4273. //
  4274. // verifyCode, version_code := ReadCardGetCode("FY002" + "|" + order.OrgSetlNumber + "|" + miConfig.Code)
  4275. //
  4276. // var pagesize int = 50
  4277. // var start int = 1
  4278. // var stop int
  4279. // var pagecount int
  4280. // var curpage int
  4281. // var isSuccess bool = true
  4282. // var ress []*ResultFive
  4283. //
  4284. // //总页数,向上取整,注意除之前要先转换类型为float64
  4285. // pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  4286. //
  4287. // for curpage = 1; curpage <= pagecount; curpage++ {
  4288. // if curpage == 1 {
  4289. // start = 1
  4290. // } else {
  4291. // start = (curpage-1)*pagesize + 1
  4292. // }
  4293. // stop = curpage * pagesize
  4294. // if stop > len(customs) {
  4295. // stop = len(customs)
  4296. // }
  4297. //
  4298. // result := service.SzybFY002(doctor_name, doctor_code, miConfig.Code, customs[start-1:stop], verifyCode, order.OrgSetlNumber, his.Number, version_code)
  4299. // fmt.Println(result)
  4300. //
  4301. // var dat map[string]interface{}
  4302. // if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4303. // fmt.Println(dat)
  4304. // } else {
  4305. // fmt.Println(err)
  4306. // }
  4307. // userJSONBytes, _ := json.Marshal(dat)
  4308. // var res ResultFive
  4309. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4310. // utils.ErrorLog("解析失败:%v", err)
  4311. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4312. // return
  4313. // }
  4314. // if res.Transreturncode == "00000000" {
  4315. // ress = append(ress, &res)
  4316. // } else {
  4317. // isSuccess = false
  4318. // //预结算报错
  4319. // errlog := &models.HisOrderError{
  4320. // UserOrgId: adminUser.CurrentOrgId,
  4321. // Ctime: time.Now().Unix(),
  4322. // Mtime: time.Now().Unix(),
  4323. // ErrMsg: res.Transreturnmessage,
  4324. // Status: 1,
  4325. // PatientId: patient_id,
  4326. // RecordTime: recordDateTime,
  4327. // Stage: 11,
  4328. // }
  4329. // service.CreateErrMsgLog(errlog)
  4330. //
  4331. // c.ServeSuccessJSON(map[string]interface{}{
  4332. // "faild_code": -10,
  4333. // "msg": res.Transreturnmessage,
  4334. // })
  4335. // return
  4336. // }
  4337. // }
  4338. // if isSuccess == true {
  4339. // service.UpdataOrderInfoStatus(order.ID, order.Number, adminUser.CurrentOrgId)
  4340. // c.ServeSuccessJSON(map[string]interface{}{
  4341. // "msg": "撤销成功",
  4342. // })
  4343. // }
  4344. //}
  4345. func (c *SZHisApiController) CancelOrderDetail() {
  4346. order_id, _ := c.GetInt64("order_id")
  4347. record_time := c.GetString("record_time")
  4348. patient_id, _ := c.GetInt64("patient_id")
  4349. his_patient_id, _ := c.GetInt64("his_patient_id")
  4350. admin_user_id, _ := c.GetInt64("admin_user_id")
  4351. timeLayout := "2006-01-02"
  4352. loc, _ := time.LoadLocation("Local")
  4353. adminUser := c.GetAdminUserInfo()
  4354. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4355. fmt.Println(err)
  4356. if err != nil {
  4357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4358. return
  4359. }
  4360. recordDateTime := theTime.Unix()
  4361. var order models.HisOrder
  4362. order, _ = service.GetHisOrderByID(order_id)
  4363. if order.ID == 0 {
  4364. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  4365. }
  4366. order_infos, _ := service.GetHisOrderInfoByNumber(order.Number)
  4367. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4368. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4369. //结算流程
  4370. var doctor_name string
  4371. var doctor_code string
  4372. if roles.ID == 0 {
  4373. doctor_name = "管理员"
  4374. doctor_code = "1001"
  4375. } else {
  4376. doctor_name = roles.UserName
  4377. doctor_code = strconv.FormatInt(admin_user_id, 10)
  4378. }
  4379. var customs []*models.CustomDetail
  4380. for _, item := range order_infos {
  4381. cus := &models.CustomDetail{
  4382. PrescriptionNumber: item.OrderNumber,
  4383. ChargeSerialNumber: item.FeedetlSn,
  4384. }
  4385. customs = append(customs, cus)
  4386. }
  4387. his, _ := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  4388. verifyCode, version_code := ReadCardGetCode("FY002" + "|" + order.OrgSetlNumber + "|" + miConfig.Code)
  4389. var pagesize int = 50
  4390. var start int = 1
  4391. var stop int
  4392. var pagecount int
  4393. var curpage int
  4394. var isSuccess bool = true
  4395. var ress []*ResultFive
  4396. //总页数,向上取整,注意除之前要先转换类型为float64
  4397. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  4398. for curpage = 1; curpage <= pagecount; curpage++ {
  4399. if curpage == 1 {
  4400. start = 1
  4401. } else {
  4402. start = (curpage-1)*pagesize + 1
  4403. }
  4404. stop = curpage * pagesize
  4405. if stop > len(customs) {
  4406. stop = len(customs)
  4407. }
  4408. result := service.SzybFY002(doctor_name, doctor_code, miConfig.Code, customs[start-1:stop], verifyCode, order.OrgSetlNumber, his.Number, version_code)
  4409. fmt.Println(result)
  4410. var dat map[string]interface{}
  4411. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4412. fmt.Println(dat)
  4413. } else {
  4414. fmt.Println(err)
  4415. }
  4416. userJSONBytes, _ := json.Marshal(dat)
  4417. var res ResultFive
  4418. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4419. utils.ErrorLog("解析失败:%v", err)
  4420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4421. return
  4422. }
  4423. if res.Transreturncode == "00000000" {
  4424. ress = append(ress, &res)
  4425. } else {
  4426. isSuccess = false
  4427. //预结算报错
  4428. errlog := &models.HisOrderError{
  4429. UserOrgId: adminUser.CurrentOrgId,
  4430. Ctime: time.Now().Unix(),
  4431. Mtime: time.Now().Unix(),
  4432. ErrMsg: res.Transreturnmessage,
  4433. Status: 1,
  4434. PatientId: patient_id,
  4435. RecordTime: recordDateTime,
  4436. Stage: 11,
  4437. }
  4438. service.CreateErrMsgLog(errlog)
  4439. c.ServeSuccessJSON(map[string]interface{}{
  4440. "faild_code": -10,
  4441. "msg": res.Transreturnmessage,
  4442. })
  4443. return
  4444. }
  4445. }
  4446. if isSuccess == true {
  4447. service.UpdataOrderInfoStatus(order.ID, order.Number, adminUser.CurrentOrgId)
  4448. c.ServeSuccessJSON(map[string]interface{}{
  4449. "msg": "撤销成功",
  4450. })
  4451. }
  4452. }
  4453. //获取verifyCode
  4454. func ReadCardGetCode(request string) (string, string) {
  4455. request = request + "|"
  4456. DllDef2 := syscall.MustLoadDLL("SSCardDriver_SZ.dll")
  4457. readCards := DllDef2.MustFindProc("iVerifyCode")
  4458. str := request
  4459. str3 := make([]byte, 256)
  4460. ret4, _, _ := readCards.Call(StrPtr(str), (uintptr)(unsafe.Pointer(&str3[0])))
  4461. fmt.Println(":", string(str3))
  4462. fmt.Println(":", ConvertToString(string(str3), "gbk", "utf-8"))
  4463. if ret4 == 0 {
  4464. result := string(str3)
  4465. fmt.Println(result)
  4466. result_arr := strings.Split(result, "|")
  4467. verifyCode := result_arr[0] + "|" + result_arr[1]
  4468. versionCode := result_arr[2]
  4469. return verifyCode, versionCode
  4470. }
  4471. return "", ""
  4472. }
  4473. ////获取卡信息
  4474. func ReadBasCardGetNumber(request string) (string, string, string, string, string, error, int64) {
  4475. DllDef2 := syscall.MustLoadDLL("SSCardDriver_SZ.dll")
  4476. readCards := DllDef2.MustFindProc("iReadCardBas")
  4477. str := request
  4478. str3 := make([]byte, 1024)
  4479. fmt.Println(":", request)
  4480. fmt.Println(":", StrPtr(str))
  4481. ret4, _, err := readCards.Call(IntPtr(1), StrPtr(str), (uintptr)(unsafe.Pointer(&str3[0])))
  4482. fmt.Println(":", string(str3))
  4483. fmt.Println(":", ConvertToString(string(str3), "gbk", "utf-8"))
  4484. if ret4 == 0 {
  4485. result := string(str3)
  4486. fmt.Println(result)
  4487. result_arr := strings.Split(result, "|")
  4488. //医疗证号
  4489. yiliao_number := result_arr[12]
  4490. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  4491. id_card_number := result_arr[1]
  4492. verifyCode := result_arr[11] + "|" + result_arr[13]
  4493. versionCode := result_arr[14]
  4494. health_card_no := result_arr[2]
  4495. return yiliao_number, id_card_number, verifyCode, versionCode, health_card_no, err, 0
  4496. }
  4497. return "", "", "", "", "", err, -10
  4498. }
  4499. //读卡
  4500. func ReadBasCard(request string) (string, string, error, int64) {
  4501. DllDef2 := syscall.MustLoadDLL("SSCardDriver_SZ.dll")
  4502. readCards := DllDef2.MustFindProc("iReadCardBas")
  4503. str := request
  4504. str3 := make([]byte, 1024)
  4505. ret4, _, err := readCards.Call(IntPtr(1), StrPtr(str), (uintptr)(unsafe.Pointer(&str3[0])))
  4506. fmt.Println(":", string(str3))
  4507. fmt.Println(":", ConvertToString(string(str3), "gbk", "utf-8"))
  4508. if ret4 == 0 {
  4509. result := string(str3)
  4510. result_arr := strings.Split(result, "|")
  4511. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  4512. id_card_number := result_arr[1]
  4513. health_card_no := result_arr[2]
  4514. return id_card_number, health_card_no, err, 0
  4515. }
  4516. return "", "", err, -10
  4517. }
  4518. //
  4519. ////iReadCardBas_HSM_Step1 ---- 1903 iCardInnerAuthentication --- iReadCardBas_HSM_Step2
  4520. //func ReadCardBasHSM(number string) string {
  4521. // DllDef2 := syscall.MustLoadDLL("SSSE32.dll")
  4522. // readCards := DllDef2.MustFindProc("iReadCardBas_HSM_Step1")
  4523. // str := make([]byte, 256)
  4524. // ret, _, _ := readCards.Call(IntPtr(3), (uintptr)(unsafe.Pointer(&str[0])))
  4525. // fmt.Println(":", string(str))
  4526. //
  4527. // result_arr := strings.Split(string(str), "|")
  4528. //
  4529. // if ret == 0 {
  4530. // readCards := DllDef2.MustFindProc("iCardInnerAuthentication")
  4531. // str2 := make([]byte, 256)
  4532. // str3 := "" + "|" + "" + "|" + "440300" + "|" + "" + "|" + "" + "|" + result_arr[1] + "|" + result_arr[2] + "|" + result_arr[3] + "|" + result_arr[4] + "|" + result_arr[5] + "|" + "" + "|" + "" + "|"
  4533. // ret2, _, _ := readCards.Call(StrPtr(str3), (uintptr)(unsafe.Pointer(&str2[0])))
  4534. // fmt.Println(":", string(str2))
  4535. //
  4536. // if ret2 == 0 {
  4537. // result_arr := strings.Split(string(str2), "|")
  4538. //
  4539. // if result_arr[2] == "0" {
  4540. // readCards := DllDef2.MustFindProc("iReadCardBas_HSM_Step2")
  4541. // str4 := result_arr[4] + "|" + result_arr[5]
  4542. // str5 := make([]byte, 256)
  4543. // ret3, _, _ := readCards.Call(StrPtr(str4), StrPtr(number), (uintptr)(unsafe.Pointer(&str5[0])))
  4544. //
  4545. // if ret3 == 0 {
  4546. // return string(str5)
  4547. //
  4548. // } else {
  4549. // return ""
  4550. // }
  4551. // } else {
  4552. // return ""
  4553. // }
  4554. // }
  4555. // return ""
  4556. // }
  4557. // return ""
  4558. //
  4559. //}
  4560. //
  4561. ////1904卡鉴权
  4562. //func CardAuth(request string) string {
  4563. // DllDef2 := syscall.MustLoadDLL("SSSE32.dll")
  4564. // readCards := DllDef2.MustFindProc("iCardAuthentication")
  4565. // str := request
  4566. // str3 := make([]byte, 256)
  4567. // ret4, _, _ := readCards.Call(StrPtr(str), (uintptr)(unsafe.Pointer(&str3[0])))
  4568. // fmt.Println(":", string(str3))
  4569. //
  4570. // if ret4 == 0 {
  4571. // return string(str3)
  4572. // }
  4573. // return ""
  4574. //}
  4575. func (c *SZHisApiController) GetDrugList() {
  4576. adminUserInfo := c.GetAdminUserInfo()
  4577. orgId := adminUserInfo.CurrentOrgId
  4578. admin_user_id, _ := c.GetInt64("admin_user_id")
  4579. roles, _ := service.GetAdminUserInfoByID(orgId, admin_user_id)
  4580. ids := c.GetString("ids")
  4581. stringarr := strings.Split(ids, ",")
  4582. idss := make([]int64, 0)
  4583. for _, item := range stringarr {
  4584. itemsss, _ := strconv.ParseInt(item, 10, 64)
  4585. id := int64(itemsss)
  4586. idss = append(idss, id)
  4587. }
  4588. //批量获取
  4589. list, _ := service.GetBatchDrugList(idss)
  4590. //获取药品剂型
  4591. drugs, _ := service.GetDrugDosageForm(orgId)
  4592. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4593. var doctor_name string
  4594. var doctor_code string
  4595. doctor_name = roles.UserName
  4596. doctor_code = "1001"
  4597. var isSuccess bool = true
  4598. timeLayout := "20060102"
  4599. //这里就可以查看开始和结束了
  4600. for _, item := range list {
  4601. recordDate := time.Unix(item.RecordDate, 0).Format(timeLayout)
  4602. detail := &models.DrugDetail{
  4603. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  4604. Code: item.Code,
  4605. DrugName: item.DrugName,
  4606. DrugSpec: item.DrugSpec,
  4607. DrugDosageName: item.DrugDosageName,
  4608. ManufacturerName: item.ManufacturerName,
  4609. MinUnit: item.MinUnit,
  4610. RetailPrice: item.RetailPrice,
  4611. LastPrice: item.LastPrice,
  4612. LimitRemark: item.LimitRemark,
  4613. PrescriptionMark: strconv.FormatInt(item.PrescriptionMark, 10),
  4614. RecordDate: recordDate,
  4615. }
  4616. for _, it := range drugs {
  4617. if item.DrugDosageForm == it.Value {
  4618. detail.DrugDosageName = it.Code
  4619. }
  4620. }
  4621. result := service.SzybML008(doctor_name, doctor_code, miConfig.Code, detail)
  4622. var dat map[string]interface{}
  4623. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4624. //fmt.Println(dat)
  4625. } else {
  4626. //fmt.Println(err)
  4627. }
  4628. userJSONBytes, _ := json.Marshal(dat)
  4629. var res Result
  4630. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4631. utils.ErrorLog("解析失败:%v", err)
  4632. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4633. c.ServeSuccessJSON(map[string]interface{}{
  4634. "failed_code": -10,
  4635. "msg": res.Transreturnmessage,
  4636. })
  4637. return
  4638. }
  4639. if res.Transreturncode == "00000000" {
  4640. //更新备案状态
  4641. _, err := service.UpdateBaseDrugById(item.ID)
  4642. fmt.Println("err", err)
  4643. c.ServeSuccessJSON(map[string]interface{}{
  4644. "failed_code": -10,
  4645. "msg": res.Transreturnmessage,
  4646. })
  4647. return
  4648. }
  4649. fmt.Println(isSuccess)
  4650. c.ServeSuccessJSON(map[string]interface{}{
  4651. "failed_code": -10,
  4652. "msg": res.Transreturnmessage,
  4653. })
  4654. return
  4655. }
  4656. }
  4657. func (c *SZHisApiController) GetTreatmentProject() {
  4658. adminUserInfo := c.GetAdminUserInfo()
  4659. orgId := adminUserInfo.CurrentOrgId
  4660. ids := c.GetString("ids")
  4661. stringarr := strings.Split(ids, ",")
  4662. idss := make([]int64, 0)
  4663. admin_user_id, _ := c.GetInt64("admin_user_id")
  4664. roles, _ := service.GetAdminUserInfoByID(orgId, admin_user_id)
  4665. for _, item := range stringarr {
  4666. itemsss, _ := strconv.ParseInt(item, 10, 64)
  4667. id := int64(itemsss)
  4668. idss = append(idss, id)
  4669. }
  4670. //获取项目库数据
  4671. list, _ := service.GetBathchMyPorjecgList(idss)
  4672. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4673. var doctor_name string
  4674. var doctor_code string
  4675. doctor_name = roles.UserName
  4676. doctor_code = "1001"
  4677. var isSuccess bool = true
  4678. for _, item := range list {
  4679. detail := &models.MyHisProject{
  4680. MedicalCode: item.MedicalCode, //社保目录
  4681. ProjectName: item.ProjectName,
  4682. Price: item.Price,
  4683. Category: item.Category,
  4684. Remark: item.Remark,
  4685. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  4686. SpecailProject: item.SpecailProject,
  4687. RecordDate: item.RecordDate,
  4688. }
  4689. result := service.SzybML009(doctor_name, doctor_code, miConfig.Code, detail)
  4690. var dat map[string]interface{}
  4691. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4692. fmt.Println(dat)
  4693. } else {
  4694. fmt.Println(err)
  4695. }
  4696. userJSONBytes, _ := json.Marshal(dat)
  4697. var res Result
  4698. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4699. utils.ErrorLog("解析失败:%v", err)
  4700. c.ServeSuccessJSON(map[string]interface{}{
  4701. "failed_code": -10,
  4702. "msg": res.Transreturnmessage,
  4703. })
  4704. return
  4705. }
  4706. if res.Transreturncode == "00000000" {
  4707. //备案成功返回状态值
  4708. _, err := service.UpdateProjectById(item.ID)
  4709. fmt.Println("err", err)
  4710. } else {
  4711. isSuccess = false
  4712. //失败
  4713. c.ServeSuccessJSON(map[string]interface{}{
  4714. "failed_code": -10,
  4715. "msg": res.Transreturnmessage,
  4716. })
  4717. return
  4718. }
  4719. fmt.Println(isSuccess)
  4720. c.ServeSuccessJSON(map[string]interface{}{
  4721. "failed_code": -10,
  4722. "msg": res.Transreturnmessage,
  4723. })
  4724. return
  4725. }
  4726. }
  4727. func (c *SZHisApiController) GetRevocation() {
  4728. adminUserInfo := c.GetAdminUserInfo()
  4729. orgId := adminUserInfo.CurrentOrgId
  4730. id, _ := c.GetInt64("id")
  4731. admin_user_id, _ := c.GetInt64("admin_user_id")
  4732. roles, _ := service.GetAdminUserInfoByID(orgId, admin_user_id)
  4733. //用来区分是药品的撤销还是耗材的撤销 1.药品 2.诊疗项目 3.材料 5.辅助器具项目
  4734. is_mark, _ := c.GetInt64("is_mark")
  4735. type_id, _ := c.GetInt64("type_id")
  4736. if type_id == 1 {
  4737. //撤销
  4738. if is_mark == 1 {
  4739. //获取药品库数据
  4740. list, _ := service.GetDrugListByDetail(orgId, id)
  4741. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4742. var doctor_name string
  4743. var doctor_code string
  4744. doctor_name = roles.UserName
  4745. doctor_code = "1001"
  4746. var pagesize int = 50
  4747. var start int = 1
  4748. var stop int
  4749. var pagecount int
  4750. var curpage int
  4751. var isSuccess bool = true
  4752. //总页数,向上取整,注意除之前要先转换类型为float64
  4753. pagecount = int(math.Ceil(float64(len(list)) / float64(pagesize)))
  4754. for curpage = 1; curpage <= pagecount; curpage++ {
  4755. if curpage == 1 {
  4756. start = 1
  4757. } else {
  4758. start = (curpage-1)*pagesize + 1
  4759. }
  4760. stop = curpage * pagesize
  4761. if stop > len(list) {
  4762. stop = len(list)
  4763. }
  4764. //这里就可以查看开始和结束了
  4765. fmt.Println(list[start-1 : stop])
  4766. var customs []*models.DrugDetail
  4767. for _, item := range list {
  4768. detail := &models.DrugDetail{
  4769. SocialSecurityDirectoryCode: item.MedicalInsuranceNumber, //社保目录
  4770. Code: item.Code, //协议机构内部目录编码
  4771. DrugName: item.DrugName, //协议机构内部目录名称
  4772. DrugSpec: item.DrugSpec,
  4773. ManufacturerName: item.ManufacturerName,
  4774. MinUnit: item.MinUnit,
  4775. RetailPrice: item.RetailPrice, //协议机构内部项目收费价格
  4776. LimitRemark: item.LimitRemark,
  4777. MedicalInsuranceNumber: item.MedicalInsuranceNumber, //社保目录
  4778. }
  4779. customs = append(customs, detail)
  4780. }
  4781. result := service.SzybML010(doctor_name, doctor_code, miConfig.Code, customs, type_id)
  4782. fmt.Println("reuslt", result)
  4783. var dat map[string]interface{}
  4784. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4785. fmt.Println(dat)
  4786. } else {
  4787. fmt.Println(err)
  4788. }
  4789. userJSONBytes, _ := json.Marshal(dat)
  4790. var res Result
  4791. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4792. utils.ErrorLog("解析失败:%v", err)
  4793. c.ServeSuccessJSON(map[string]interface{}{
  4794. "failed_code": -10,
  4795. "msg": res.Transreturnmessage,
  4796. })
  4797. return
  4798. }
  4799. if res.Transreturncode == "00000000" {
  4800. //撤销成功
  4801. _, err := service.UpdateDrugByIdDetail(id)
  4802. fmt.Println("err", err)
  4803. } else {
  4804. isSuccess = false
  4805. //失败
  4806. c.ServeSuccessJSON(map[string]interface{}{
  4807. "failed_code": -10,
  4808. "msg": res.Transreturnmessage,
  4809. })
  4810. return
  4811. }
  4812. fmt.Println(isSuccess)
  4813. c.ServeSuccessJSON(map[string]interface{}{
  4814. "failed_code": -10,
  4815. "msg": res.Transreturnmessage,
  4816. })
  4817. return
  4818. }
  4819. }
  4820. // 备案
  4821. if is_mark == 0 {
  4822. adminUserInfo := c.GetAdminUserInfo()
  4823. orgId := adminUserInfo.CurrentOrgId
  4824. //获取药品库数据
  4825. list, _ := service.GetDrugListByDetail(orgId, id)
  4826. //获取药品剂型
  4827. drugs, _ := service.GetDrugDosageForm(orgId)
  4828. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4829. var doctor_name string
  4830. var doctor_code string
  4831. doctor_name = roles.UserName
  4832. doctor_code = "1001"
  4833. var isSuccess bool = true
  4834. //这里就可以查看开始和结束了
  4835. for _, item := range list {
  4836. detail := &models.DrugDetail{
  4837. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  4838. SocialSecurityDirectoryCode: item.MedicalInsuranceNumber,
  4839. Code: item.Code,
  4840. DrugName: item.DrugName,
  4841. DrugSpec: item.DrugSpec,
  4842. DrugDosageName: item.DrugDosageName,
  4843. ManufacturerName: item.ManufacturerName,
  4844. MinUnit: item.MinUnit,
  4845. RetailPrice: item.RetailPrice,
  4846. LastPrice: item.LastPrice,
  4847. LimitRemark: item.LimitRemark,
  4848. }
  4849. for _, it := range drugs {
  4850. if item.DrugDosageForm == it.Value {
  4851. detail.DrugDosageName = it.Code
  4852. }
  4853. }
  4854. result := service.SzybML008(doctor_name, doctor_code, miConfig.Code, detail)
  4855. var dat map[string]interface{}
  4856. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4857. //fmt.Println(dat)
  4858. } else {
  4859. //fmt.Println(err)
  4860. }
  4861. userJSONBytes, _ := json.Marshal(dat)
  4862. var res Result
  4863. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4864. utils.ErrorLog("解析失败:%v", err)
  4865. c.ServeSuccessJSON(map[string]interface{}{
  4866. "failed_code": -10,
  4867. "msg": res.Transreturnmessage,
  4868. })
  4869. return
  4870. }
  4871. if res.Transreturncode == "00000000" {
  4872. //更新备案状态
  4873. _, err := service.UpdateBaseDrugById(item.ID)
  4874. fmt.Println("err", err)
  4875. }
  4876. fmt.Println(isSuccess)
  4877. c.ServeSuccessJSON(map[string]interface{}{
  4878. "failed_code": -10,
  4879. "msg": res.Transreturnmessage,
  4880. })
  4881. return
  4882. }
  4883. }
  4884. }
  4885. if type_id == 2 {
  4886. //撤销
  4887. if is_mark == 1 {
  4888. //获取药品库数据
  4889. list, _ := service.GetMyPorjecgListDetail(orgId, id)
  4890. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4891. var doctor_name string
  4892. var doctor_code string
  4893. doctor_name = roles.UserName
  4894. doctor_code = "1001"
  4895. var pagesize int = 50
  4896. var start int = 1
  4897. var stop int
  4898. var pagecount int
  4899. var curpage int
  4900. var isSuccess bool = true
  4901. //总页数,向上取整,注意除之前要先转换类型为float64
  4902. pagecount = int(math.Ceil(float64(len(list)) / float64(pagesize)))
  4903. for curpage = 1; curpage <= pagecount; curpage++ {
  4904. if curpage == 1 {
  4905. start = 1
  4906. } else {
  4907. start = (curpage-1)*pagesize + 1
  4908. }
  4909. stop = curpage * pagesize
  4910. if stop > len(list) {
  4911. stop = len(list)
  4912. }
  4913. //这里就可以查看开始和结束了
  4914. fmt.Println(list[start-1 : stop])
  4915. var customs []*models.DrugDetail
  4916. for _, item := range list {
  4917. detail := &models.DrugDetail{
  4918. SocialSecurityDirectoryCode: item.MedicalCode,
  4919. }
  4920. customs = append(customs, detail)
  4921. }
  4922. result := service.SzybML010(doctor_name, doctor_code, miConfig.Code, customs, type_id)
  4923. fmt.Println("reuslt", result)
  4924. var dat map[string]interface{}
  4925. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4926. fmt.Println(dat)
  4927. } else {
  4928. fmt.Println(err)
  4929. }
  4930. userJSONBytes, _ := json.Marshal(dat)
  4931. var res Result
  4932. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4933. utils.ErrorLog("解析失败:%v", err)
  4934. c.ServeSuccessJSON(map[string]interface{}{
  4935. "failed_code": -10,
  4936. "msg": res.Transreturnmessage,
  4937. })
  4938. return
  4939. }
  4940. if res.Transreturncode == "00000000" {
  4941. //核销成功返回状态码
  4942. _, err := service.UpdateMyProjectById(id)
  4943. fmt.Println("err", err)
  4944. } else {
  4945. isSuccess = false
  4946. //失败
  4947. c.ServeSuccessJSON(map[string]interface{}{
  4948. "failed_code": -10,
  4949. "msg": res.Transreturnmessage,
  4950. })
  4951. return
  4952. }
  4953. fmt.Println(isSuccess)
  4954. c.ServeSuccessJSON(map[string]interface{}{
  4955. "failed_code": -10,
  4956. "msg": res.Transreturnmessage,
  4957. })
  4958. return
  4959. }
  4960. }
  4961. //备案
  4962. if is_mark == 0 {
  4963. adminUserInfo := c.GetAdminUserInfo()
  4964. orgId := adminUserInfo.CurrentOrgId
  4965. //获取药品库数据
  4966. list, _ := service.GetMyPorjecgListDetail(orgId, id)
  4967. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4968. var doctor_name string
  4969. var doctor_code string
  4970. doctor_name = roles.UserName
  4971. doctor_code = "1001"
  4972. var isSuccess bool = true
  4973. for _, item := range list {
  4974. detail := &models.MyHisProject{
  4975. MedicalCode: item.MedicalCode, //社保目录
  4976. ProjectName: item.ProjectName,
  4977. Price: item.Price,
  4978. Category: item.Category,
  4979. Remark: item.Remark,
  4980. }
  4981. result := service.SzybML009(doctor_name, doctor_code, miConfig.Code, detail)
  4982. fmt.Println("reuslt", result)
  4983. var dat map[string]interface{}
  4984. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4985. fmt.Println(dat)
  4986. } else {
  4987. fmt.Println(err)
  4988. }
  4989. userJSONBytes, _ := json.Marshal(dat)
  4990. var res Result
  4991. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4992. utils.ErrorLog("解析失败:%v", err)
  4993. c.ServeSuccessJSON(map[string]interface{}{
  4994. "failed_code": -10,
  4995. "msg": res.Transreturnmessage,
  4996. })
  4997. return
  4998. }
  4999. if res.Transreturncode == "00000000" {
  5000. //备案成功返回状态值
  5001. _, err := service.UpdateProjectById(item.ID)
  5002. fmt.Println("err", err)
  5003. } else {
  5004. isSuccess = false
  5005. //失败
  5006. c.ServeSuccessJSON(map[string]interface{}{
  5007. "failed_code": -10,
  5008. "msg": res.Transreturnmessage,
  5009. })
  5010. return
  5011. }
  5012. fmt.Println(isSuccess)
  5013. c.ServeSuccessJSON(map[string]interface{}{
  5014. "failed_code": -10,
  5015. "msg": res.Transreturnmessage,
  5016. })
  5017. return
  5018. }
  5019. }
  5020. }
  5021. if type_id == 3 {
  5022. //撤销
  5023. if is_mark == 1 {
  5024. //获取药品库数据
  5025. list, _ := service.GetGoodListByDetail(orgId, id)
  5026. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  5027. var doctor_name string
  5028. var doctor_code string
  5029. doctor_name = roles.UserName
  5030. doctor_code = "1001"
  5031. var pagesize int = 50
  5032. var start int = 1
  5033. var stop int
  5034. var pagecount int
  5035. var curpage int
  5036. var isSuccess bool = true
  5037. //总页数,向上取整,注意除之前要先转换类型为float64
  5038. pagecount = int(math.Ceil(float64(len(list)) / float64(pagesize)))
  5039. for curpage = 1; curpage <= pagecount; curpage++ {
  5040. if curpage == 1 {
  5041. start = 1
  5042. } else {
  5043. start = (curpage-1)*pagesize + 1
  5044. }
  5045. stop = curpage * pagesize
  5046. if stop > len(list) {
  5047. stop = len(list)
  5048. }
  5049. //这里就可以查看开始和结束了
  5050. fmt.Println(list[start-1 : stop])
  5051. var customs []*models.DrugDetail
  5052. for _, item := range list {
  5053. fmt.Println("医疗机构编码", item.SocialSecurityDirectoryCode)
  5054. detail := &models.DrugDetail{
  5055. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  5056. ManufacturerName: item.ManufacturerName,
  5057. }
  5058. customs = append(customs, detail)
  5059. }
  5060. result := service.SzybML010(doctor_name, doctor_code, miConfig.Code, customs, type_id)
  5061. fmt.Println("reuslt", result)
  5062. var dat map[string]interface{}
  5063. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5064. fmt.Println(dat)
  5065. } else {
  5066. fmt.Println(err)
  5067. }
  5068. userJSONBytes, _ := json.Marshal(dat)
  5069. var res Result
  5070. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5071. utils.ErrorLog("解析失败:%v", err)
  5072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5073. return
  5074. }
  5075. if res.Transreturncode == "00000000" {
  5076. //撤销成功后改变状态
  5077. _, err := service.UpdateGoodInfoById(id)
  5078. fmt.Println("err", err)
  5079. } else {
  5080. isSuccess = false
  5081. //失败
  5082. c.ServeSuccessJSON(map[string]interface{}{
  5083. "failed_code": -10,
  5084. "msg": res.Transreturnmessage,
  5085. })
  5086. return
  5087. }
  5088. fmt.Println(isSuccess)
  5089. c.ServeSuccessJSON(map[string]interface{}{
  5090. "failed_code": -10,
  5091. "msg": res.Transreturnmessage,
  5092. })
  5093. return
  5094. }
  5095. }
  5096. //备案
  5097. if is_mark == 0 {
  5098. adminUserInfo := c.GetAdminUserInfo()
  5099. orgId := adminUserInfo.CurrentOrgId
  5100. //获取所有耗材信息
  5101. list, _ := service.GetGoodListByDetail(orgId, id)
  5102. //获取单位
  5103. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  5104. var doctor_name string
  5105. var doctor_code string
  5106. doctor_name = roles.UserName
  5107. doctor_code = "1001"
  5108. var isSuccess bool = true
  5109. for _, item := range list {
  5110. detail := &models.XtGoodInformation{
  5111. GoodName: item.GoodName,
  5112. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  5113. ManufacturerName: item.ManufacturerName,
  5114. ProductionType: item.ProductionType,
  5115. SpecialMedical: item.SpecialMedical,
  5116. BuyPrice: item.BuyPrice,
  5117. SellPrice: item.SellPrice,
  5118. Remark: item.Remark,
  5119. SpecificationName: item.SpecificationName,
  5120. }
  5121. result := service.SzybYML007(doctor_name, doctor_code, miConfig.Code, detail)
  5122. fmt.Println("reuslt", result)
  5123. var dat map[string]interface{}
  5124. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5125. fmt.Println(dat)
  5126. } else {
  5127. fmt.Println(err)
  5128. }
  5129. userJSONBytes, _ := json.Marshal(dat)
  5130. var res Result
  5131. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5132. utils.ErrorLog("解析失败:%v", err)
  5133. c.ServeSuccessJSON(map[string]interface{}{
  5134. "failed_code": -10,
  5135. "msg": res.Transreturnmessage,
  5136. })
  5137. return
  5138. }
  5139. if res.Transreturncode == "00000000" {
  5140. //备案成功返回状态
  5141. _, err := service.UpdateGoodInformaitonByDetail(item.ID)
  5142. fmt.Println("err", err)
  5143. } else {
  5144. isSuccess = false
  5145. //失败
  5146. c.ServeSuccessJSON(map[string]interface{}{
  5147. "failed_code": -10,
  5148. "msg": res.Transreturnmessage,
  5149. })
  5150. return
  5151. }
  5152. fmt.Println(isSuccess)
  5153. c.ServeSuccessJSON(map[string]interface{}{
  5154. "failed_code": -10,
  5155. "msg": res.Transreturnmessage,
  5156. })
  5157. return
  5158. }
  5159. }
  5160. }
  5161. }
  5162. func (c *SZHisApiController) GetDoctorList() {
  5163. adminUserInfo := c.GetAdminUserInfo()
  5164. orgid := adminUserInfo.CurrentOrgId
  5165. ids := c.GetString("ids")
  5166. admin_user_id, _ := c.GetInt64("admin_user_id")
  5167. roles, _ := service.GetAdminUserInfoByID(orgid, admin_user_id)
  5168. stringarr := strings.Split(ids, ",")
  5169. idss := make([]int64, 0)
  5170. for _, item := range stringarr {
  5171. itemsss, _ := strconv.ParseInt(item, 10, 64)
  5172. id := int64(itemsss)
  5173. idss = append(idss, id)
  5174. }
  5175. //获取所有医生护士信息
  5176. //list, _ := service.GetDoctorList(orgid)
  5177. //批量查询
  5178. list, _ := service.GetBatchDoctorList(idss)
  5179. //获取所有角色名称
  5180. roleList, _ := service.GetRoleList(orgid)
  5181. miConfig, _ := service.FindMedicalInsuranceInfo(orgid)
  5182. for _, item := range list {
  5183. for _, it := range roleList {
  5184. if item.RoleId == it.ID {
  5185. item.Name = it.RoleName
  5186. }
  5187. }
  5188. }
  5189. var doctor_name string
  5190. var doctor_code string
  5191. doctor_name = roles.UserName
  5192. doctor_code = "1001"
  5193. var isSuccess bool = true
  5194. for _, item := range list {
  5195. depart, _ := service.GetDepartMentDetail(item.DepartmentId)
  5196. detail := &models.DocDetail{
  5197. UserName: item.UserName, //医护姓名
  5198. RoleId: item.Name, //医护人员类别
  5199. Sex: strconv.FormatInt(item.Sex, 10), //性别
  5200. CardType: strconv.FormatInt(item.CardType, 10), //证件类型
  5201. IdCard: item.IdCard, //证件号码
  5202. Phone: item.Mobile, //联系电话
  5203. WorkMajorName: item.WorkMajorName, // 现从事专业名称
  5204. Nation: "1", //民族
  5205. BirthDay: 20201022, // 出生日期
  5206. WorkTime: 20201022, //参加工作日期
  5207. Education: strconv.FormatInt(item.Education, 10), //学历
  5208. StudyMajorName: item.StudyMajorName, //所学的专业名称
  5209. CertificateCode: item.MedicalCode, //医(药)师执业证书编码
  5210. MedicalCode: item.DoctorCode, //医(药)师资格证编码
  5211. MedicalRangeCode: strconv.FormatInt(item.DoctorRangeCode, 10), //医师执业范围代码
  5212. MedicalLevel: strconv.FormatInt(item.DoctorLevel, 10), //医生执业资格证中的医师级别
  5213. TypeJob: strconv.FormatInt(item.DoctorTypeJob, 10), //医生执业资格证中的执业类别
  5214. DoctorNumber: item.DoctorNumber, //医保医师编号
  5215. Licensing: strconv.FormatInt(item.Licensing, 10), //多点执业标志
  5216. DoctorServiceStatus: "", //医师医保服务资格状态
  5217. MonitoringLevel: "", //监控等级
  5218. DrugPsychotropicSubstances: "", //毒麻精神药品资格
  5219. HealthCareCode: "", // 母婴保健技术考核合格证书编号
  5220. PlanningTechnicalServiceCode: "", //计划生育技术服务人员合格证编号
  5221. PharmacistType: "", //药师类别
  5222. PharmacistPracticeCategory: "", //药师执业类别
  5223. PharmacistsLicensing: "", //药师执业范围
  5224. PharmacistRegistrationNumber: "", //执业药师注册证编号
  5225. OfficeCode: depart.Number, //科室编码
  5226. JobNumber: item.JobNumber, //工号
  5227. PostName: "", //职位名称
  5228. TechnicalJobLevelCode: "", //专业技术职务级别编码
  5229. IsActive: strconv.FormatInt(item.IsActive, 10), //在职与否
  5230. PrescriptionQualificationIdentification: strconv.FormatInt(item.PrescriptionQualificationIdentification, 10), //处方资格标识
  5231. IdentificationOutpatients: strconv.FormatInt(item.IdentificationOutpatients, 10), //门诊大病医师标识
  5232. OutpatientIllnessCategory: item.OutpatientIllnessCategory, //门诊大病类别
  5233. StartTime: 20201010, //开始日期
  5234. StaffCode: "", //医护人员编码
  5235. EndTime: 0, // 结束日期
  5236. }
  5237. result := service.SzybYS001(doctor_name, doctor_code, miConfig.Code, detail)
  5238. fmt.Println("reuslt", result)
  5239. var dat map[string]interface{}
  5240. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5241. fmt.Println(dat)
  5242. } else {
  5243. fmt.Println(err)
  5244. }
  5245. userJSONBytes, _ := json.Marshal(dat)
  5246. var res Result
  5247. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5248. utils.ErrorLog("解析失败:%v", err)
  5249. c.ServeSuccessJSON(map[string]interface{}{
  5250. "failed_code": -10,
  5251. "msg": res.Transreturnmessage,
  5252. })
  5253. return
  5254. }
  5255. if res.Transreturncode == "00000000" {
  5256. //批量插入数据
  5257. _, err := service.UpdateAdminUserRoleById(item.AdminUserId, orgid)
  5258. fmt.Println("err", err)
  5259. } else {
  5260. isSuccess = false
  5261. //失败
  5262. c.ServeSuccessJSON(map[string]interface{}{
  5263. "failed_code": -10,
  5264. "msg": res.Transreturnmessage,
  5265. })
  5266. return
  5267. }
  5268. fmt.Println(isSuccess)
  5269. c.ServeSuccessJSON(map[string]interface{}{
  5270. "failed_code": -10,
  5271. "msg": res.Transreturnmessage,
  5272. })
  5273. return
  5274. }
  5275. }
  5276. func (c *SZHisApiController) GetMedicalList() {
  5277. adminUserInfo := c.GetAdminUserInfo()
  5278. orgId := adminUserInfo.CurrentOrgId
  5279. id, _ := c.GetInt64("id")
  5280. is_mark, _ := c.GetInt64("is_mark")
  5281. admin_user_id, _ := c.GetInt64("admin_user_id")
  5282. roles, _ := service.GetAdminUserInfoByID(orgId, admin_user_id)
  5283. //去登记
  5284. if is_mark == 0 {
  5285. list, _ := service.GetDoctorListByDetail(orgId, id)
  5286. //获取所有角色名称
  5287. roleList, _ := service.GetRoleList(orgId)
  5288. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  5289. for _, item := range list {
  5290. for _, it := range roleList {
  5291. if item.RoleId == it.ID {
  5292. item.Name = it.RoleName
  5293. }
  5294. }
  5295. }
  5296. var doctor_name string
  5297. var doctor_code string
  5298. doctor_name = roles.UserName
  5299. doctor_code = "1001"
  5300. var isSuccess bool = true
  5301. for _, item := range list {
  5302. detail := &models.DocDetail{
  5303. UserName: item.UserName, //医护姓名
  5304. RoleId: item.Name, //医护人员类别
  5305. Sex: strconv.FormatInt(item.Sex, 10), //性别
  5306. CardType: strconv.FormatInt(item.CardType, 10), //证件类型
  5307. IdCard: item.IdCard, //证件号码
  5308. Phone: item.Mobile, //联系电话
  5309. WorkMajorName: item.WorkMajorName, // 现从事专业名称
  5310. Nation: item.Nation, //民族
  5311. BirthDay: 20201022, // 出生日期
  5312. WorkTime: 20201022, //参加工作日期
  5313. Education: strconv.FormatInt(item.Education, 10), //学历
  5314. StudyMajorName: item.StudyMajorName, //所学的专业名称
  5315. CertificateCode: item.MedicalCode, //医(药)师执业证书编码
  5316. MedicalCode: item.DoctorCode, //医(药)师资格证编码
  5317. MedicalRangeCode: strconv.FormatInt(item.DoctorRangeCode, 10), //医师执业范围代码
  5318. MedicalLevel: strconv.FormatInt(item.DoctorLevel, 10), //医生执业资格证中的医师级别
  5319. TypeJob: strconv.FormatInt(item.DoctorTypeJob, 10), //医生执业资格证中的执业类别
  5320. DoctorNumber: item.DoctorNumber, //医保医师编号
  5321. Licensing: strconv.FormatInt(item.Licensing, 10), //多点执业标志
  5322. DoctorServiceStatus: "", //医师医保服务资格状态
  5323. MonitoringLevel: "", //监控等级
  5324. DrugPsychotropicSubstances: "", //毒麻精神药品资格
  5325. HealthCareCode: "", // 母婴保健技术考核合格证书编号
  5326. PlanningTechnicalServiceCode: "", //计划生育技术服务人员合格证编号
  5327. PharmacistType: "", //药师类别
  5328. PharmacistPracticeCategory: "", //药师执业类别
  5329. PharmacistsLicensing: "", //药师执业范围
  5330. PharmacistRegistrationNumber: "", //执业药师注册证编号
  5331. OfficeCode: "", //科室编码
  5332. JobNumber: item.JobNumber, //工号
  5333. PostName: "", //职位名称
  5334. TechnicalJobLevelCode: "", //专业技术职务级别编码
  5335. IsActive: strconv.FormatInt(item.IsActive, 10), //在职与否
  5336. PrescriptionQualificationIdentification: strconv.FormatInt(item.PrescriptionQualificationIdentification, 10), //处方资格标识
  5337. IdentificationOutpatients: strconv.FormatInt(item.IdentificationOutpatients, 10), //门诊大病医师标识
  5338. OutpatientIllnessCategory: item.OutpatientIllnessCategory, //门诊大病类别
  5339. StartTime: 20201010, //开始日期
  5340. StaffCode: "", //医护人员编码
  5341. EndTime: 0, // 结束日期
  5342. }
  5343. result := service.SzybYS001(doctor_name, doctor_code, miConfig.Code, detail)
  5344. var dat map[string]interface{}
  5345. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5346. fmt.Println(dat)
  5347. } else {
  5348. fmt.Println(err)
  5349. }
  5350. userJSONBytes, _ := json.Marshal(dat)
  5351. var res Result
  5352. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5353. utils.ErrorLog("解析失败:%v", err)
  5354. c.ServeSuccessJSON(map[string]interface{}{
  5355. "failed_code": -10,
  5356. "msg": res.Transreturnmessage,
  5357. })
  5358. return
  5359. }
  5360. if res.Transreturncode == "00000000" {
  5361. //登记成功
  5362. service.UpdateAdminUserRoleById(item.ID, orgId)
  5363. } else {
  5364. isSuccess = false
  5365. //失败
  5366. c.ServeSuccessJSON(map[string]interface{}{
  5367. "failed_code": -10,
  5368. "msg": res.Transreturnmessage,
  5369. })
  5370. return
  5371. }
  5372. fmt.Println(isSuccess)
  5373. c.ServeSuccessJSON(map[string]interface{}{
  5374. "failed_code": -10,
  5375. "msg": res.Transreturnmessage,
  5376. })
  5377. return
  5378. }
  5379. }
  5380. //去撤销
  5381. if is_mark == 1 {
  5382. //获取所有医生护士信息
  5383. list, _ := service.GetDoctorListByDetail(orgId, id)
  5384. //获取所有角色名称
  5385. roleList, _ := service.GetRoleList(orgId)
  5386. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  5387. for _, item := range list {
  5388. for _, it := range roleList {
  5389. if item.RoleId == it.ID {
  5390. item.Name = it.RoleName
  5391. }
  5392. }
  5393. }
  5394. var doctor_name string
  5395. var doctor_code string
  5396. doctor_name = "黄亦轩"
  5397. doctor_code = "1001"
  5398. var isSuccess bool = true
  5399. for _, item := range list {
  5400. detail := &models.DocDetail{
  5401. UserName: item.UserName, //医护姓名
  5402. RoleId: item.Name, //医护人员类别
  5403. Sex: strconv.FormatInt(item.Sex, 10), //性别
  5404. CardType: strconv.FormatInt(item.CardType, 10), //证件类型
  5405. IdCard: item.IdCard, //证件号码
  5406. Phone: item.Mobile, //联系电话
  5407. WorkMajorName: item.WorkMajorName, // 现从事专业名称
  5408. Nation: item.Nation, //民族
  5409. BirthDay: 20201022, // 出生日期
  5410. WorkTime: 20201022, //参加工作日期
  5411. Education: strconv.FormatInt(item.Education, 10), //学历
  5412. StudyMajorName: item.StudyMajorName, //所学的专业名称
  5413. CertificateCode: item.MedicalCode, //医(药)师执业证书编码
  5414. MedicalCode: item.DoctorCode, //医(药)师资格证编码
  5415. MedicalRangeCode: strconv.FormatInt(item.DoctorRangeCode, 10), //医师执业范围代码
  5416. MedicalLevel: strconv.FormatInt(item.DoctorLevel, 10), //医生执业资格证中的医师级别
  5417. TypeJob: strconv.FormatInt(item.DoctorTypeJob, 10), //医生执业资格证中的执业类别
  5418. DoctorNumber: item.DoctorNumber, //医保医师编号
  5419. Licensing: strconv.FormatInt(item.Licensing, 10), //多点执业标志
  5420. DoctorServiceStatus: "", //医师医保服务资格状态
  5421. MonitoringLevel: "", //监控等级
  5422. DrugPsychotropicSubstances: "", //毒麻精神药品资格
  5423. HealthCareCode: "", // 母婴保健技术考核合格证书编号
  5424. PlanningTechnicalServiceCode: "", //计划生育技术服务人员合格证编号
  5425. PharmacistType: "", //药师类别
  5426. PharmacistPracticeCategory: "", //药师执业类别
  5427. PharmacistsLicensing: "", //药师执业范围
  5428. PharmacistRegistrationNumber: "", //执业药师注册证编号
  5429. OfficeCode: "", //科室编码
  5430. JobNumber: item.JobNumber, //工号
  5431. PostName: "", //职位名称
  5432. TechnicalJobLevelCode: "", //专业技术职务级别编码
  5433. IsActive: strconv.FormatInt(item.IsActive, 10), //在职与否
  5434. PrescriptionQualificationIdentification: strconv.FormatInt(item.PrescriptionQualificationIdentification, 10), //处方资格标识
  5435. IdentificationOutpatients: strconv.FormatInt(item.IdentificationOutpatients, 10), //门诊大病医师标识
  5436. OutpatientIllnessCategory: item.OutpatientIllnessCategory, //门诊大病类别
  5437. StartTime: 20201010, //开始日期
  5438. StaffCode: "", //医护人员编码
  5439. EndTime: 0, // 结束日期
  5440. }
  5441. result := service.SzybYS002(doctor_name, doctor_code, miConfig.Code, detail)
  5442. var dat map[string]interface{}
  5443. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5444. fmt.Println(dat)
  5445. } else {
  5446. fmt.Println(err)
  5447. }
  5448. userJSONBytes, _ := json.Marshal(dat)
  5449. var res Result
  5450. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5451. utils.ErrorLog("解析失败:%v", err)
  5452. c.ServeSuccessJSON(map[string]interface{}{
  5453. "failed_code": -10,
  5454. "msg": res.Transreturnmessage,
  5455. })
  5456. return
  5457. }
  5458. if res.Transreturncode == "00000000" {
  5459. //去撤销
  5460. service.UpdateAdminUserRoleById(item.ID, orgId)
  5461. } else {
  5462. isSuccess = false
  5463. //失败
  5464. c.ServeSuccessJSON(map[string]interface{}{
  5465. "failed_code": -10,
  5466. "msg": res.Transreturnmessage,
  5467. })
  5468. return
  5469. }
  5470. fmt.Println(isSuccess)
  5471. c.ServeSuccessJSON(map[string]interface{}{
  5472. "failed_code": -10,
  5473. "msg": res.Transreturnmessage,
  5474. })
  5475. return
  5476. }
  5477. }
  5478. }
  5479. func (c *SZHisApiController) GetUpdateMedicalList() {
  5480. adminUserInfo := c.GetAdminUserInfo()
  5481. orgId := adminUserInfo.CurrentOrgId
  5482. //获取所有医生护士信息
  5483. list, _ := service.GetDoctorList(orgId)
  5484. //获取所有角色名称
  5485. roleList, _ := service.GetRoleList(orgId)
  5486. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  5487. for _, item := range list {
  5488. for _, it := range roleList {
  5489. if item.RoleId == it.ID {
  5490. item.Name = it.RoleName
  5491. }
  5492. }
  5493. }
  5494. var doctor_name string
  5495. var doctor_code string
  5496. doctor_name = "黄亦轩"
  5497. doctor_code = "1001"
  5498. var pagesize int = 50
  5499. var start int = 1
  5500. var stop int
  5501. var pagecount int
  5502. var curpage int
  5503. var isSuccess bool = true
  5504. //总页数,向上取整,注意除之前要先转换类型为float64
  5505. pagecount = int(math.Ceil(float64(len(list)) / float64(pagesize)))
  5506. var ress []*Result
  5507. for curpage = 1; curpage <= pagecount; curpage++ {
  5508. if curpage == 1 {
  5509. start = 1
  5510. } else {
  5511. start = (curpage-1)*pagesize + 1
  5512. }
  5513. stop = curpage * pagesize
  5514. if stop > len(list) {
  5515. stop = len(list)
  5516. }
  5517. //这里就可以查看开始和结束了
  5518. fmt.Println(list[start-1 : stop])
  5519. var customs []*models.DocDetail
  5520. for _, item := range list {
  5521. detail := &models.DocDetail{
  5522. StaffCode: "", //医护人员编码
  5523. UserName: item.UserName, //医护人员姓名
  5524. RoleId: item.Name, //医护人员类别
  5525. Sex: "", //性别
  5526. CardType: "", //证件类型
  5527. IdCard: "", //证件号码
  5528. Phone: "", //联系电话
  5529. WorkMajorName: "", //现从事专业名称
  5530. Nation: "", //民族
  5531. BirthDay: 20201022, //出生日期
  5532. WorkTime: 20201022, //参加工作日期
  5533. Education: "", //学历
  5534. StudyMajorName: "", //所学的专业名称
  5535. CertificateCode: "", //证书编码
  5536. MedicalCode: "", //医师资格编码
  5537. MedicalRangeCode: "", //医师执业范围代码
  5538. MedicalLevel: "", //医生级别
  5539. TypeJob: "", //职业类别
  5540. DoctorNumber: "", //医师编号
  5541. Licensing: "", //职业标志
  5542. DoctorServiceStatus: "", //医师医保服务资格状态
  5543. MonitoringLevel: "", //监控等级
  5544. DrugPsychotropicSubstances: "", //毒麻精神药品资格
  5545. HealthCareCode: "", // 母婴保健技术考核合格证书编号
  5546. PlanningTechnicalServiceCode: "", //计划生育技术服务人员合格证编号
  5547. PharmacistType: "", //药师类别
  5548. PharmacistPracticeCategory: "", //药师执业类别
  5549. PharmacistsLicensing: "", //药师执业范围
  5550. PharmacistRegistrationNumber: "", //执业药师注册证编号
  5551. OfficeCode: "", //科室编码
  5552. JobNumber: "", //工号
  5553. PostName: "", //职位名称
  5554. TechnicalJobLevelCode: "", //专业技术职务级别编码
  5555. IsActive: "", //在职与否
  5556. PrescriptionQualificationIdentification: "", //处方资格标识
  5557. IdentificationOutpatients: "", //门诊大病医师标识
  5558. OutpatientIllnessCategory: "", //门诊大病类别
  5559. StartTime: 20201022, //开始日期
  5560. EndTime: 20201022,
  5561. }
  5562. customs = append(customs, detail)
  5563. }
  5564. result := service.SzybYS003(doctor_name, doctor_code, miConfig.Code, customs)
  5565. var dat map[string]interface{}
  5566. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5567. fmt.Println(dat)
  5568. } else {
  5569. fmt.Println(err)
  5570. }
  5571. userJSONBytes, _ := json.Marshal(dat)
  5572. var res Result
  5573. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5574. utils.ErrorLog("解析失败:%v", err)
  5575. c.ServeSuccessJSON(map[string]interface{}{
  5576. "failed_code": -10,
  5577. "msg": res.Transreturnmessage,
  5578. })
  5579. return
  5580. }
  5581. if res.Transreturncode == "00000000" {
  5582. ress = append(ress, &res)
  5583. } else {
  5584. isSuccess = false
  5585. //失败
  5586. c.ServeSuccessJSON(map[string]interface{}{
  5587. "failed_code": -10,
  5588. "msg": res.Transreturnmessage,
  5589. })
  5590. return
  5591. }
  5592. fmt.Println(isSuccess)
  5593. c.ServeSuccessJSON(map[string]interface{}{
  5594. "failed_code": -10,
  5595. "msg": res.Transreturnmessage,
  5596. })
  5597. return
  5598. }
  5599. }
  5600. func (c *SZHisApiController) GetGoodsList() {
  5601. adminUserInfo := c.GetAdminUserInfo()
  5602. orgId := adminUserInfo.CurrentOrgId
  5603. ids := c.GetString("ids")
  5604. admin_user_id, _ := c.GetInt64("admin_user_id")
  5605. roles, _ := service.GetAdminUserInfoByID(orgId, admin_user_id)
  5606. stringarr := strings.Split(ids, ",")
  5607. idss := make([]int64, 0)
  5608. for _, item := range stringarr {
  5609. itemsss, _ := strconv.ParseInt(item, 10, 64)
  5610. id := int64(itemsss)
  5611. idss = append(idss, id)
  5612. }
  5613. //批量获取所有耗材信息
  5614. list, _ := service.GetBatchGoodInformationList(idss)
  5615. //获取单位
  5616. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  5617. var doctor_name string
  5618. var doctor_code string
  5619. doctor_name = roles.UserName
  5620. doctor_code = "1001"
  5621. var isSuccess bool = true
  5622. for _, item := range list {
  5623. detail := &models.XtGoodInformation{
  5624. GoodName: item.GoodName,
  5625. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  5626. ManufacturerName: item.ManufacturerName,
  5627. ProductionType: item.ProductionType,
  5628. SpecialMedical: item.SpecialMedical,
  5629. BuyPrice: item.BuyPrice,
  5630. SellPrice: item.SellPrice,
  5631. Remark: item.Remark,
  5632. SpecificationName: item.SpecificationName,
  5633. }
  5634. result := service.SzybYML007(doctor_name, doctor_code, miConfig.Code, detail)
  5635. fmt.Println("reuslt", result)
  5636. var dat map[string]interface{}
  5637. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5638. fmt.Println(dat)
  5639. } else {
  5640. fmt.Println(err)
  5641. }
  5642. userJSONBytes, _ := json.Marshal(dat)
  5643. var res Result
  5644. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5645. utils.ErrorLog("解析失败:%v", err)
  5646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5647. return
  5648. }
  5649. if res.Transreturncode == "00000000" {
  5650. //备案成功返回状态
  5651. _, err := service.UpdateGoodInformaitonByDetail(item.ID)
  5652. fmt.Println("err", err)
  5653. } else {
  5654. isSuccess = false
  5655. //失败
  5656. c.ServeSuccessJSON(map[string]interface{}{
  5657. "failed_code": -10,
  5658. "msg": res.Transreturnmessage,
  5659. })
  5660. return
  5661. }
  5662. fmt.Println(isSuccess)
  5663. c.ServeSuccessJSON(map[string]interface{}{
  5664. "failed_code": -10,
  5665. "msg": res.Transreturnmessage,
  5666. })
  5667. return
  5668. }
  5669. }
  5670. type Charset string
  5671. const (
  5672. UTF8 = Charset("UTF-8")
  5673. GB18030 = Charset("GB18030")
  5674. )
  5675. func ConvertToString(src string, srcCode string, tagCode string) string {
  5676. srcCoder := mahonia.NewDecoder(srcCode)
  5677. srcResult := srcCoder.ConvertString(src)
  5678. tagCoder := mahonia.NewDecoder(tagCode)
  5679. _, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
  5680. result := string(cdata)
  5681. return result
  5682. }