sz_his_api_controller.go 217KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079
  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. cus := &models.CustomDetail{
  2188. PrescriptionNumber: chrg_bchno,
  2189. OrderType: "1",
  2190. ChargeSerialNumber: newFl,
  2191. Code: subItem.BaseDrugLib.MedicalInsuranceNumber,
  2192. CodeName: subItem.BaseDrugLib.DrugName,
  2193. Flag: "1",
  2194. Price: price,
  2195. Count: subItem.PrescribingNumber,
  2196. ChargeOrderDate: year + month + day,
  2197. DoctorCode: doctor_code,
  2198. Total: detItemFeeSumamt,
  2199. DoseCode: dose_code,
  2200. Spec: strconv.Itoa(int(subItem.BaseDrugLib.MinNumber)) + subItem.BaseDrugLib.MinUnit + ":" + fmt.Sprintf("%.2f", subItem.BaseDrugLib.Dose) + subItem.BaseDrugLib.DoseUnit,
  2201. Unit: subItem.PrescribingNumberUnit,
  2202. }
  2203. customs = append(customs, cus)
  2204. }
  2205. }
  2206. }
  2207. if item.Type == 2 { //项目
  2208. for _, subItem := range item.HisPrescriptionProject {
  2209. if len(subItem.HisProject.MedicalCode) > 0 {
  2210. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  2211. //count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  2212. count, _ := strconv.ParseFloat(strconv.FormatInt(subItem.Count, 10), 64)
  2213. temp := strings.Split(subItem.FeedetlSn, "-")
  2214. newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  2215. if subItem.Type == 2 {
  2216. cus := &models.CustomDetail{
  2217. PrescriptionNumber: chrg_bchno,
  2218. OrderType: "1",
  2219. ChargeSerialNumber: newFl,
  2220. Code: subItem.HisProject.MedicalCode,
  2221. CodeName: subItem.HisProject.ProjectName,
  2222. Flag: "1",
  2223. Price: subItem.Price,
  2224. Count: count,
  2225. ChargeOrderDate: year + month + day,
  2226. DoctorCode: doctor_code,
  2227. Total: detItemFeeSumamt,
  2228. DoseCode: "",
  2229. Spec: "次",
  2230. Unit: "次",
  2231. }
  2232. customs = append(customs, cus)
  2233. }
  2234. }
  2235. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 {
  2236. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  2237. //count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  2238. count, _ := strconv.ParseFloat(strconv.FormatInt(subItem.Count, 10), 64)
  2239. temp := strings.Split(subItem.FeedetlSn, "-")
  2240. newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  2241. if subItem.Type == 3 {
  2242. cus := &models.CustomDetail{
  2243. PrescriptionNumber: chrg_bchno,
  2244. OrderType: "1",
  2245. ChargeSerialNumber: newFl,
  2246. Code: subItem.GoodInfo.MedicalInsuranceNumber,
  2247. CodeName: subItem.GoodInfo.GoodName,
  2248. Flag: "1",
  2249. Price: subItem.Price,
  2250. Count: count,
  2251. ChargeOrderDate: year + month + day,
  2252. DoctorCode: doctor_code,
  2253. Total: detItemFeeSumamt,
  2254. DoseCode: "",
  2255. Spec: "支",
  2256. Unit: "支",
  2257. }
  2258. customs = append(customs, cus)
  2259. }
  2260. }
  2261. }
  2262. }
  2263. //
  2264. //for _, subItem := range item.HisAdditionalCharge {
  2265. // if len(subItem.XtHisAddtionConfig.Code) > 0 {
  2266. // detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  2267. //
  2268. // count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  2269. // cus := &models.CustomDetail{
  2270. // PrescriptionNumber: chrg_bchno,
  2271. // OrderType: "1",
  2272. // ChargeSerialNumber: subItem.FeedetlSn,
  2273. // Code: subItem.XtHisAddtionConfig.Code,
  2274. // CodeName: subItem.XtHisAddtionConfig.Name,
  2275. // Flag: "1",
  2276. // Price: subItem.Price,
  2277. // Count: count,
  2278. // ChargeOrderDate: year + month + day,
  2279. // DoctorCode: doctor_code,
  2280. // Total: detItemFeeSumamt,
  2281. // DoseCode: "",
  2282. // Spec: subItem.XtHisAddtionConfig.,
  2283. // }
  2284. // customs = append(customs, cus)
  2285. // }
  2286. //}
  2287. }
  2288. var pagesize int = 50
  2289. var start int = 1
  2290. var stop int
  2291. var pagecount int
  2292. var curpage int
  2293. var isSuccess bool = true
  2294. //总页数,向上取整,注意除之前要先转换类型为float64
  2295. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  2296. var ress []*Result
  2297. for curpage = 1; curpage <= pagecount; curpage++ {
  2298. if curpage == 1 {
  2299. start = 1
  2300. } else {
  2301. start = (curpage-1)*pagesize + 1
  2302. }
  2303. stop = curpage * pagesize
  2304. if stop > len(customs) {
  2305. stop = len(customs)
  2306. }
  2307. result := service.SzybFY001(doctor_name, doctor_code, miConfig.Code, customs[start-1:stop], verifyCode, number, mz_number, version_code, drug_doctor_code)
  2308. fmt.Println(result)
  2309. var dat map[string]interface{}
  2310. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2311. fmt.Println(dat)
  2312. } else {
  2313. fmt.Println(err)
  2314. }
  2315. userJSONBytes, _ := json.Marshal(dat)
  2316. var res Result
  2317. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2318. utils.ErrorLog("解析失败:%v", err)
  2319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2320. return
  2321. }
  2322. if res.Transreturncode == "00000000" {
  2323. ress = append(ress, &res)
  2324. } else {
  2325. isSuccess = false
  2326. errlog := &models.HisOrderError{
  2327. UserOrgId: adminUser.CurrentOrgId,
  2328. Ctime: time.Now().Unix(),
  2329. Mtime: time.Now().Unix(),
  2330. Number: chrg_bchno,
  2331. ErrMsg: res.Transreturnmessage,
  2332. Status: 1,
  2333. PatientId: patient_id,
  2334. RecordTime: recordDateTime,
  2335. Stage: 4,
  2336. }
  2337. service.CreateErrMsgLog(errlog)
  2338. c.ServeSuccessJSON(map[string]interface{}{
  2339. "failed_code": -10,
  2340. "msg": res.Transreturnmessage,
  2341. })
  2342. return
  2343. }
  2344. //设置变量,根据变量的值来判断上传是否成功
  2345. }
  2346. if isSuccess == true {
  2347. order := &models.HisOrder{
  2348. UserOrgId: adminUser.CurrentOrgId,
  2349. HisPatientId: 0,
  2350. PatientId: patient_id,
  2351. SettleAccountsDate: recordDateTime,
  2352. Ctime: time.Now().Unix(),
  2353. Mtime: time.Now().Unix(),
  2354. Status: 0,
  2355. Number: chrg_bchno,
  2356. Infcode: 0,
  2357. WarnMsg: "",
  2358. Cainfo: "",
  2359. ErrMsg: "",
  2360. RespondTime: "",
  2361. InfRefmsgid: "",
  2362. OrderStatus: 1,
  2363. IsMedicineInsurance: 1,
  2364. SettleType: settle_accounts_type,
  2365. SettleStartTime: start_time,
  2366. SettleEndTime: end_time,
  2367. Creator: admin_user_id,
  2368. Modify: admin_user_id,
  2369. OrgSetlNumber: number,
  2370. MdtrtId: mz_number,
  2371. PType: 2,
  2372. }
  2373. data, _ := json.Marshal(ress)
  2374. order.DetailLog = string(data)
  2375. err = service.CreateOrder(order)
  2376. if err != nil {
  2377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2378. return
  2379. }
  2380. for _, subItem := range ress {
  2381. for _, item := range subItem.Transbody.Outputlist {
  2382. temp := strings.Split(item.Bkf500, "-")
  2383. var advice_id int64 = 0
  2384. var project_id int64 = 0
  2385. var types int64 = 0
  2386. id, _ := strconv.ParseInt(temp[2], 10, 64)
  2387. types, _ = strconv.ParseInt(temp[1], 10, 64)
  2388. if temp[1] == "1" {
  2389. advice_id = id
  2390. project_id = 0
  2391. } else if temp[1] == "2" {
  2392. advice_id = 0
  2393. project_id = id
  2394. }
  2395. info := &models.HisOrderInfo{
  2396. OrderNumber: order.Number,
  2397. FeedetlSn: item.Bkf500,
  2398. UploadDate: time.Now().Unix(),
  2399. AdviceId: advice_id,
  2400. DetItemFeeSumamt: item.Akc264,
  2401. Cnt: item.Akc226,
  2402. Pric: float64(item.Akc225),
  2403. PatientId: patient_id,
  2404. Status: 1,
  2405. ChrgitmLv: item.Aka065,
  2406. Mtime: time.Now().Unix(),
  2407. Ctime: time.Now().Unix(),
  2408. UserOrgId: adminUser.CurrentOrgId,
  2409. OrderId: order.ID,
  2410. ProjectId: project_id,
  2411. Type: types,
  2412. OverPricPsnPay: item.Akc268,
  2413. AllowReimburse: item.Cka319,
  2414. }
  2415. service.CreateOrderInfo(info)
  2416. }
  2417. }
  2418. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2419. service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, his_patient_id, chrg_bchno, recordDateTime)
  2420. var total float64
  2421. for _, item := range prescriptions {
  2422. if item.Type == 1 { //药品
  2423. for _, subItem := range item.HisDoctorAdviceInfo {
  2424. total = total + (subItem.Price * subItem.PrescribingNumber)
  2425. }
  2426. }
  2427. if item.Type == 2 { //项目
  2428. for _, subItem := range item.HisPrescriptionProject {
  2429. total = total + (subItem.Price * float64(subItem.Count))
  2430. }
  2431. }
  2432. }
  2433. for _, item := range prescriptions {
  2434. for _, subItem := range item.HisAdditionalCharge {
  2435. total = total + (subItem.Price * float64(subItem.Count))
  2436. }
  2437. }
  2438. total, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", total), 64)
  2439. yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("FY005" + "|" + number + "|" + miConfig.Code + "|")
  2440. if ret4 == 0 {
  2441. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  2442. tempPatient, _ := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  2443. if tempPatient.ID == patient_id {
  2444. 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)
  2445. var dat map[string]interface{}
  2446. if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  2447. fmt.Println(dat)
  2448. } else {
  2449. fmt.Println(err)
  2450. }
  2451. userJSONBytes, _ := json.Marshal(dat)
  2452. var res ResultTwo
  2453. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2454. utils.ErrorLog("解析失败:%v", err)
  2455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2456. return
  2457. }
  2458. if res.Transreturncode == "00000000" {
  2459. order.OrderStatus = 2
  2460. order.Status = 1
  2461. order.PayWay = pay_way
  2462. order.PayPrice = pay_price
  2463. order.PayCardNo = pay_card_no
  2464. order.PsnNo = health_card_no
  2465. order.DiscountPrice = discount_price
  2466. order.PreferentialPrice = preferential_price
  2467. order.RealityPrice = reality_price
  2468. order.FoundPrice = found_price
  2469. order.MedicalInsurancePrice = medical_insurance_price
  2470. order.PrivatePrice = private_price
  2471. order.Modify = admin_user_id
  2472. order.MedfeeSumamt = res.Transbody.Akc264
  2473. order.SetlId = res.Transbody.Ckc618
  2474. order.FundPaySumamt = res.Transbody.Akb068
  2475. order.AcctPay = res.Transbody.Akb066
  2476. order.PsnCashPay = res.Transbody.Akb067
  2477. order.PsnPartAmt = res.Transbody.Akb067
  2478. order.AccountPrice = res.Transbody.Aae240
  2479. order.MedType = strconv.Itoa(int(reg_type))
  2480. order.MzNumber = mz_number
  2481. order.MdtrtId = mz_number
  2482. order.YiliaoNumber = yiliao_number
  2483. setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  2484. detailStrOne := string(setlDetailOne)
  2485. order.SzChargeInfo = detailStrOne
  2486. setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  2487. detailStrTwo := string(setlDetailTwo)
  2488. order.SzProjectInfo = detailStrTwo
  2489. setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  2490. detailStrThree := string(setlDetailThree)
  2491. order.SzMedicineInsuranceInfo = detailStrThree
  2492. order.Cainfo = result_three
  2493. err = service.UpdataOrderStatusTwo(order.Number, adminUser.CurrentOrgId)
  2494. err = service.UpDateOrderTwo(order)
  2495. c.ServeSuccessJSON(map[string]interface{}{
  2496. "msg": "结算成功",
  2497. })
  2498. } else {
  2499. //结算报错
  2500. errlog := &models.HisOrderError{
  2501. UserOrgId: adminUser.CurrentOrgId,
  2502. Ctime: time.Now().Unix(),
  2503. Mtime: time.Now().Unix(),
  2504. Number: chrg_bchno,
  2505. ErrMsg: res.Transreturnmessage,
  2506. Status: 1,
  2507. PatientId: patient_id,
  2508. RecordTime: recordDateTime,
  2509. Stage: 6,
  2510. }
  2511. service.CreateErrMsgLog(errlog)
  2512. c.ServeSuccessJSON(map[string]interface{}{
  2513. "failed_code": -10,
  2514. "msg": res.Transreturnmessage,
  2515. })
  2516. }
  2517. } else {
  2518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  2519. return
  2520. }
  2521. } else {
  2522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  2523. return
  2524. }
  2525. } else {
  2526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePreSettleFaildParamWrong)
  2527. return
  2528. }
  2529. } else {
  2530. if tempOrder.OrderStatus == 1 && tempOrder.IsPre == 1 {
  2531. pay_way, _ := c.GetInt64("pay_way")
  2532. pay_price, _ := c.GetFloat("pay_price")
  2533. pay_card_no := c.GetString("pay_card_no")
  2534. discount_price, _ := c.GetFloat("discount_price")
  2535. preferential_price, _ := c.GetFloat("preferential_price")
  2536. reality_price, _ := c.GetFloat("reality_price")
  2537. found_price, _ := c.GetFloat("found_price")
  2538. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2539. private_price, _ := c.GetFloat("private_price")
  2540. patient_id, _ := c.GetInt64("id")
  2541. record_time := c.GetString("record_time")
  2542. admin_user_id, _ := c.GetInt64("admin_user_id")
  2543. order_id, _ := c.GetInt64("order_id")
  2544. his_patient_id, _ := c.GetInt64("his_patient_id")
  2545. timestamp := time.Now().Unix()
  2546. tempTime := time.Unix(timestamp, 0)
  2547. timeFormat := tempTime.Format("20060102150405")
  2548. chrgBchno := rand.Intn(10000) + 1000
  2549. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(1, 10)
  2550. adminUser := c.GetAdminUserInfo()
  2551. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2552. month := time.Unix(1557042972, 0).Format("1")
  2553. year := time.Now().Format("2006")
  2554. month = time.Now().Format("01")
  2555. day := time.Now().Format("02")
  2556. timeLayout := "2006-01-02"
  2557. loc, _ := time.LoadLocation("Local")
  2558. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2559. fmt.Println(err)
  2560. if err != nil {
  2561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2562. return
  2563. }
  2564. recordDateTime := theTime.Unix()
  2565. patientPrescription, _ := service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2566. sick, _ := service.FindSickById(patientPrescription.SickType)
  2567. if sick.ID == 0 {
  2568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamSickTypeWrong)
  2569. return
  2570. }
  2571. adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  2572. adminRole, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2573. his, err := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2574. mz_number := his.Number
  2575. number := miConfig.Code + year + month + day +
  2576. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  2577. var doctor_name string
  2578. var doctor_code string
  2579. var drug_doctor_code string
  2580. drug_doctor_code = adminRole_two.DoctorCode
  2581. drug_doctor_name := adminRole_two.UserName
  2582. if adminRole.ID == 0 {
  2583. doctor_name = "管理员"
  2584. doctor_code = "01"
  2585. } else {
  2586. doctor_name = adminRole.UserName
  2587. doctor_code = strconv.FormatInt(admin_user_id, 10)
  2588. }
  2589. order, _ := service.GetHisOrderByID(order_id)
  2590. if order.ID == 0 {
  2591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  2592. return
  2593. }
  2594. yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("FY005" + "|" + number + "|" + miConfig.Code + "|")
  2595. if ret4 == 0 {
  2596. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  2597. tempPatient, _ := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  2598. if tempPatient.ID == patient_id {
  2599. 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)
  2600. var dat map[string]interface{}
  2601. if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  2602. fmt.Println(dat)
  2603. } else {
  2604. fmt.Println(err)
  2605. }
  2606. userJSONBytes, _ := json.Marshal(dat)
  2607. var res ResultTwo
  2608. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2609. utils.ErrorLog("解析失败:%v", err)
  2610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2611. return
  2612. }
  2613. if res.Transreturncode == "00000000" {
  2614. order.OrderStatus = 2
  2615. order.Status = 1
  2616. order.PayWay = pay_way
  2617. order.PayPrice = pay_price
  2618. order.PayCardNo = pay_card_no
  2619. order.PsnNo = health_card_no
  2620. order.DiscountPrice = discount_price
  2621. order.PreferentialPrice = preferential_price
  2622. order.RealityPrice = reality_price
  2623. order.FoundPrice = found_price
  2624. order.MedicalInsurancePrice = medical_insurance_price
  2625. order.PrivatePrice = private_price
  2626. order.Modify = admin_user_id
  2627. order.MedfeeSumamt = res.Transbody.Akc264
  2628. order.SetlId = res.Transbody.Ckc618
  2629. order.FundPaySumamt = res.Transbody.Akb068
  2630. order.AcctPay = res.Transbody.Akb066
  2631. order.PsnCashPay = res.Transbody.Akb067
  2632. order.PsnPartAmt = res.Transbody.Akb067
  2633. order.AccountPrice = res.Transbody.Aae240
  2634. order.MzNumber = mz_number
  2635. order.YiliaoNumber = yiliao_number
  2636. setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  2637. detailStrOne := string(setlDetailOne)
  2638. order.SzChargeInfo = detailStrOne
  2639. setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  2640. detailStrTwo := string(setlDetailTwo)
  2641. order.SzProjectInfo = detailStrTwo
  2642. setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  2643. detailStrThree := string(setlDetailThree)
  2644. order.SzMedicineInsuranceInfo = detailStrThree
  2645. order.Cainfo = result_three
  2646. err = service.UpdataOrderStatusTwo(order.Number, adminUser.CurrentOrgId)
  2647. err = service.UpDateOrderTwo(&order)
  2648. c.ServeSuccessJSON(map[string]interface{}{
  2649. "msg": "结算成功",
  2650. })
  2651. } else {
  2652. //结算报错
  2653. errlog := &models.HisOrderError{
  2654. UserOrgId: adminUser.CurrentOrgId,
  2655. Ctime: time.Now().Unix(),
  2656. Mtime: time.Now().Unix(),
  2657. Number: chrg_bchno,
  2658. ErrMsg: res.Transreturnmessage,
  2659. Status: 1,
  2660. PatientId: patient_id,
  2661. RecordTime: recordDateTime,
  2662. Stage: 6,
  2663. }
  2664. service.CreateErrMsgLog(errlog)
  2665. c.ServeSuccessJSON(map[string]interface{}{
  2666. "failed_code": -10,
  2667. "msg": res.Transreturnmessage,
  2668. })
  2669. }
  2670. } else {
  2671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  2672. return
  2673. }
  2674. } else {
  2675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  2676. return
  2677. }
  2678. } else {
  2679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  2680. return
  2681. }
  2682. }
  2683. }
  2684. //结算
  2685. //func (c *SZHisApiController) GetSettleInfo() {
  2686. // pay_way, _ := c.GetInt64("pay_way")
  2687. // pay_price, _ := c.GetFloat("pay_price")
  2688. // pay_card_no := c.GetString("pay_card_no")
  2689. // discount_price, _ := c.GetFloat("discount_price")
  2690. // preferential_price, _ := c.GetFloat("preferential_price")
  2691. // reality_price, _ := c.GetFloat("reality_price")
  2692. // found_price, _ := c.GetFloat("found_price")
  2693. // medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2694. // private_price, _ := c.GetFloat("private_price")
  2695. // patient_id, _ := c.GetInt64("id")
  2696. // record_time := c.GetString("record_time")
  2697. // admin_user_id, _ := c.GetInt64("admin_user_id")
  2698. // order_id, _ := c.GetInt64("order_id")
  2699. // his_patient_id, _ := c.GetInt64("his_patient_id")
  2700. //
  2701. // timestamp := time.Now().Unix()
  2702. // tempTime := time.Unix(timestamp, 0)
  2703. // timeFormat := tempTime.Format("20060102150405")
  2704. // chrgBchno := rand.Intn(10000) + 1000
  2705. // chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(1, 10)
  2706. // adminUser := c.GetAdminUserInfo()
  2707. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2708. // month := time.Unix(1557042972, 0).Format("1")
  2709. // year := time.Now().Format("2006")
  2710. // month = time.Now().Format("01")
  2711. // day := time.Now().Format("02")
  2712. //
  2713. // timeLayout := "2006-01-02"
  2714. // loc, _ := time.LoadLocation("Local")
  2715. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2716. // fmt.Println(err)
  2717. // if err != nil {
  2718. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2719. // return
  2720. // }
  2721. // recordDateTime := theTime.Unix()
  2722. //
  2723. // patientPrescription, _ := service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2724. //
  2725. // sick, _ := service.FindSickById(patientPrescription.SickType)
  2726. //
  2727. // if sick.ID == 0 {
  2728. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamSickTypeWrong)
  2729. // return
  2730. // }
  2731. //
  2732. // adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  2733. //
  2734. // adminRole, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2735. // his, err := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2736. // mz_number := his.Number
  2737. // number := miConfig.Code + year + month + day +
  2738. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  2739. // var doctor_name string
  2740. // var doctor_code string
  2741. // var drug_doctor_code string
  2742. // drug_doctor_code = adminRole_two.DoctorCode
  2743. // drug_doctor_name := adminRole_two.UserName
  2744. //
  2745. // if adminRole.ID == 0 {
  2746. // doctor_name = "管理员"
  2747. // doctor_code = "01"
  2748. // } else {
  2749. // doctor_name = adminRole.UserName
  2750. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  2751. // }
  2752. //
  2753. // order, _ := service.GetHisOrderByID(order_id)
  2754. // if order.ID == 0 {
  2755. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  2756. // return
  2757. // }
  2758. //
  2759. // yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("FY005" + "|" + number + "|" + miConfig.Code + "|")
  2760. // if ret4 == 0 {
  2761. // //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  2762. // tempPatient, _ := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  2763. // if tempPatient.ID == patient_id {
  2764. // 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)
  2765. // var dat map[string]interface{}
  2766. // if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  2767. // fmt.Println(dat)
  2768. // } else {
  2769. // fmt.Println(err)
  2770. // }
  2771. // userJSONBytes, _ := json.Marshal(dat)
  2772. // var res ResultTwo
  2773. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2774. // utils.ErrorLog("解析失败:%v", err)
  2775. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2776. // return
  2777. // }
  2778. //
  2779. // if res.Transreturncode == "00000000" {
  2780. // order.OrderStatus = 2
  2781. // order.Status = 1
  2782. // order.PayWay = pay_way
  2783. // order.PayPrice = pay_price
  2784. // order.PayCardNo = pay_card_no
  2785. // order.PsnNo = health_card_no
  2786. // order.DiscountPrice = discount_price
  2787. // order.PreferentialPrice = preferential_price
  2788. // order.RealityPrice = reality_price
  2789. // order.FoundPrice = found_price
  2790. // order.MedicalInsurancePrice = medical_insurance_price
  2791. // order.PrivatePrice = private_price
  2792. // order.Modify = admin_user_id
  2793. // order.MedfeeSumamt = res.Transbody.Akc264
  2794. // order.SetlId = res.Transbody.Ckc618
  2795. // order.FundPaySumamt = res.Transbody.Akb068
  2796. // order.AcctPay = res.Transbody.Akb066
  2797. // order.PsnCashPay = res.Transbody.Akb067
  2798. // order.PsnPartAmt = res.Transbody.Akb067
  2799. // order.AccountPrice = res.Transbody.Aae240
  2800. // order.MzNumber = mz_number
  2801. // order.YiliaoNumber = yiliao_number
  2802. // setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  2803. // detailStrOne := string(setlDetailOne)
  2804. // order.SzChargeInfo = detailStrOne
  2805. // setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  2806. // detailStrTwo := string(setlDetailTwo)
  2807. // order.SzProjectInfo = detailStrTwo
  2808. // setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  2809. // detailStrThree := string(setlDetailThree)
  2810. // order.SzMedicineInsuranceInfo = detailStrThree
  2811. // order.Cainfo = result_three
  2812. // err = service.UpdataOrderStatusTwo(order.Number, adminUser.CurrentOrgId)
  2813. // err = service.UpDateOrderTwo(&order)
  2814. // c.ServeSuccessJSON(map[string]interface{}{
  2815. // "msg": "结算成功",
  2816. // })
  2817. // } else {
  2818. // //结算报错
  2819. // errlog := &models.HisOrderError{
  2820. // UserOrgId: adminUser.CurrentOrgId,
  2821. // Ctime: time.Now().Unix(),
  2822. // Mtime: time.Now().Unix(),
  2823. // Number: chrg_bchno,
  2824. // ErrMsg: res.Transreturnmessage,
  2825. // Status: 1,
  2826. // PatientId: patient_id,
  2827. // RecordTime: recordDateTime,
  2828. // Stage: 6,
  2829. // }
  2830. // service.CreateErrMsgLog(errlog)
  2831. // c.ServeSuccessJSON(map[string]interface{}{
  2832. // "failed_code": -10,
  2833. // "msg": res.Transreturnmessage,
  2834. // })
  2835. // }
  2836. // } else {
  2837. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  2838. // return
  2839. // }
  2840. // } else {
  2841. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  2842. // return
  2843. // }
  2844. //}
  2845. //上传明细----预结算
  2846. func (c *SZHisApiController) GetPreSettleInfo() {
  2847. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2848. patient_id, _ := c.GetInt64("id")
  2849. record_time := c.GetString("record_time")
  2850. admin_user_id, _ := c.GetInt64("admin_user_id")
  2851. his_patient_id, _ := c.GetInt64("his_patient_id")
  2852. reg_type, _ := c.GetInt64("p_type")
  2853. sick_type, _ := c.GetInt64("sick_type")
  2854. id_str := c.GetString("ids")
  2855. ids_arr := strings.Split(id_str, ",")
  2856. timestamp := time.Now().Unix()
  2857. tempTime := time.Unix(timestamp, 0)
  2858. timeFormat := tempTime.Format("20060102150405")
  2859. chrgBchno := rand.Intn(10000) + 1000
  2860. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(1, 10)
  2861. adminUser := c.GetAdminUserInfo()
  2862. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2863. month := time.Unix(1557042972, 0).Format("1")
  2864. year := time.Now().Format("2006")
  2865. month = time.Now().Format("01")
  2866. day := time.Now().Format("02")
  2867. timeLayout := "2006-01-02"
  2868. loc, _ := time.LoadLocation("Local")
  2869. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2870. fmt.Println(err)
  2871. if err != nil {
  2872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2873. return
  2874. }
  2875. recordDateTime := theTime.Unix()
  2876. var prescriptions []*models.HisPrescription
  2877. var start_time int64
  2878. var end_time int64
  2879. if settle_accounts_type == 1 { //日结
  2880. if reg_type == 11{
  2881. prescriptions,_ = service.GetPrescriptionByIds(ids_arr,adminUser.CurrentOrgId)
  2882. }else{
  2883. prescriptions, _ = service.GetNewHisPrescription(adminUser.CurrentOrgId, his_patient_id, recordDateTime, strconv.Itoa(int(reg_type)))
  2884. }
  2885. } else { //月结
  2886. start_time_str := c.GetString("start_time")
  2887. end_time_str := c.GetString("end_time")
  2888. timeLayout := "2006-01-02"
  2889. loc, _ := time.LoadLocation("Local")
  2890. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2891. if err != nil {
  2892. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2893. return
  2894. }
  2895. recordStartTime := theStartTime.Unix()
  2896. start_time = recordStartTime
  2897. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2898. if err != nil {
  2899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2900. return
  2901. }
  2902. recordEndTime := theEndTime.Unix()
  2903. end_time = recordEndTime
  2904. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, patient_id, recordStartTime, recordEndTime, strconv.Itoa(int(reg_type)))
  2905. }
  2906. var ids []int64
  2907. for _, item := range prescriptions {
  2908. ids = append(ids, item.ID)
  2909. }
  2910. patientPrescription, _ := service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2911. sick, _ := service.FindSickById(sick_type)
  2912. if sick.ID == 0 {
  2913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamSickTypeWrong)
  2914. return
  2915. }
  2916. adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  2917. adminRole, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2918. his, err := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2919. mz_number := his.Number
  2920. number := miConfig.Code + year + month + day +
  2921. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  2922. var doctor_name string
  2923. var doctor_code string
  2924. var drug_doctor_code string
  2925. drug_doctor_code = adminRole_two.DoctorCode
  2926. drug_doctor_name := adminRole_two.UserName
  2927. if adminRole.ID == 0 {
  2928. doctor_name = "管理员"
  2929. doctor_code = "01"
  2930. } else {
  2931. doctor_name = adminRole.UserName
  2932. doctor_code = strconv.FormatInt(admin_user_id, 10)
  2933. }
  2934. verifyCode, version_code := ReadCardGetCode("FY001" + "|" + number + "|" + miConfig.Code)
  2935. var customs []*models.CustomDetail
  2936. for _, item := range prescriptions {
  2937. if item.Type == 1 { //药品
  2938. for _, subItem := range item.HisDoctorAdviceInfo {
  2939. fmt.Println(subItem.BaseDrugLib.MedicalInsuranceNumber)
  2940. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 {
  2941. _, dose_code := service.GetDoseCode(subItem.BaseDrugLib.DrugDosageForm, adminUser.CurrentOrgId)
  2942. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber), 64)
  2943. price, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price), 64)
  2944. temp := strings.Split(subItem.FeedetlSn, "-")
  2945. newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  2946. cus := &models.CustomDetail{
  2947. PrescriptionNumber: chrg_bchno,
  2948. OrderType: "1",
  2949. ChargeSerialNumber: newFl,
  2950. Code: subItem.BaseDrugLib.MedicalInsuranceNumber,
  2951. CodeName: subItem.BaseDrugLib.DrugName,
  2952. Flag: "1",
  2953. Price: price,
  2954. Count: subItem.PrescribingNumber,
  2955. ChargeOrderDate: year + month + day,
  2956. DoctorCode: doctor_code,
  2957. Total: detItemFeeSumamt,
  2958. DoseCode: dose_code,
  2959. Spec: strconv.Itoa(int(subItem.BaseDrugLib.MinNumber)) + subItem.BaseDrugLib.MinUnit + ":" + fmt.Sprintf("%.2f", subItem.BaseDrugLib.Dose) + subItem.BaseDrugLib.DoseUnit,
  2960. Unit: subItem.PrescribingNumberUnit,
  2961. }
  2962. customs = append(customs, cus)
  2963. }
  2964. }
  2965. }
  2966. if item.Type == 2 { //项目
  2967. for _, subItem := range item.HisPrescriptionProject {
  2968. if len(subItem.HisProject.MedicalCode) > 0 {
  2969. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  2970. //count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  2971. count, _ := strconv.ParseFloat(strconv.FormatInt(subItem.Count, 10), 64)
  2972. temp := strings.Split(subItem.FeedetlSn, "-")
  2973. newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  2974. if subItem.Type == 2 {
  2975. cus := &models.CustomDetail{
  2976. PrescriptionNumber: chrg_bchno,
  2977. OrderType: "1",
  2978. ChargeSerialNumber: newFl,
  2979. Code: subItem.HisProject.MedicalCode,
  2980. CodeName: subItem.HisProject.ProjectName,
  2981. Flag: "1",
  2982. Price: subItem.Price,
  2983. Count: count,
  2984. ChargeOrderDate: year + month + day,
  2985. DoctorCode: doctor_code,
  2986. Total: detItemFeeSumamt,
  2987. DoseCode: "",
  2988. Spec: "次",
  2989. Unit: "次",
  2990. }
  2991. customs = append(customs, cus)
  2992. }
  2993. }
  2994. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 {
  2995. detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  2996. //count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  2997. count, _ := strconv.ParseFloat(strconv.FormatInt(subItem.Count, 10), 64)
  2998. temp := strings.Split(subItem.FeedetlSn, "-")
  2999. newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  3000. if subItem.Type == 3 {
  3001. cus := &models.CustomDetail{
  3002. PrescriptionNumber: chrg_bchno,
  3003. OrderType: "1",
  3004. ChargeSerialNumber: newFl,
  3005. Code: subItem.GoodInfo.MedicalInsuranceNumber,
  3006. CodeName: subItem.GoodInfo.GoodName,
  3007. Flag: "1",
  3008. Price: subItem.Price,
  3009. Count: count,
  3010. ChargeOrderDate: year + month + day,
  3011. DoctorCode: doctor_code,
  3012. Total: detItemFeeSumamt,
  3013. DoseCode: "",
  3014. Spec: "支",
  3015. Unit: "支",
  3016. }
  3017. customs = append(customs, cus)
  3018. }
  3019. }
  3020. }
  3021. }
  3022. //
  3023. //for _, subItem := range item.HisAdditionalCharge {
  3024. // if len(subItem.XtHisAddtionConfig.Code) > 0 {
  3025. // detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  3026. //
  3027. // count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  3028. // cus := &models.CustomDetail{
  3029. // PrescriptionNumber: chrg_bchno,
  3030. // OrderType: "1",
  3031. // ChargeSerialNumber: subItem.FeedetlSn,
  3032. // Code: subItem.XtHisAddtionConfig.Code,
  3033. // CodeName: subItem.XtHisAddtionConfig.Name,
  3034. // Flag: "1",
  3035. // Price: subItem.Price,
  3036. // Count: count,
  3037. // ChargeOrderDate: year + month + day,
  3038. // DoctorCode: doctor_code,
  3039. // Total: detItemFeeSumamt,
  3040. // DoseCode: "",
  3041. // Spec: subItem.XtHisAddtionConfig.,
  3042. // }
  3043. // customs = append(customs, cus)
  3044. // }
  3045. //}
  3046. }
  3047. var pagesize int = 50
  3048. var start int = 1
  3049. var stop int
  3050. var pagecount int
  3051. var curpage int
  3052. var isSuccess bool = true
  3053. //总页数,向上取整,注意除之前要先转换类型为float64
  3054. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  3055. var ress []*Result
  3056. for curpage = 1; curpage <= pagecount; curpage++ {
  3057. if curpage == 1 {
  3058. start = 1
  3059. } else {
  3060. start = (curpage-1)*pagesize + 1
  3061. }
  3062. stop = curpage * pagesize
  3063. if stop > len(customs) {
  3064. stop = len(customs)
  3065. }
  3066. result := service.SzybFY001(doctor_name, doctor_code, miConfig.Code, customs[start-1:stop], verifyCode, number, mz_number, version_code, drug_doctor_code)
  3067. fmt.Println(result)
  3068. var dat map[string]interface{}
  3069. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3070. fmt.Println(dat)
  3071. } else {
  3072. fmt.Println(err)
  3073. }
  3074. userJSONBytes, _ := json.Marshal(dat)
  3075. var res Result
  3076. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3077. utils.ErrorLog("解析失败:%v", err)
  3078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3079. return
  3080. }
  3081. if res.Transreturncode == "00000000" {
  3082. ress = append(ress, &res)
  3083. } else {
  3084. isSuccess = false
  3085. errlog := &models.HisOrderError{
  3086. UserOrgId: adminUser.CurrentOrgId,
  3087. Ctime: time.Now().Unix(),
  3088. Mtime: time.Now().Unix(),
  3089. Number: chrg_bchno,
  3090. ErrMsg: res.Transreturnmessage,
  3091. Status: 1,
  3092. PatientId: patient_id,
  3093. RecordTime: recordDateTime,
  3094. Stage: 4,
  3095. }
  3096. service.CreateErrMsgLog(errlog)
  3097. c.ServeSuccessJSON(map[string]interface{}{
  3098. "failed_code": -10,
  3099. "msg": res.Transreturnmessage,
  3100. })
  3101. return
  3102. }
  3103. //设置变量,根据变量的值来判断上传是否成功
  3104. }
  3105. if isSuccess == true {
  3106. order := &models.HisOrder{
  3107. UserOrgId: adminUser.CurrentOrgId,
  3108. HisPatientId: 0,
  3109. PatientId: patient_id,
  3110. SettleAccountsDate: recordDateTime,
  3111. Ctime: time.Now().Unix(),
  3112. Mtime: time.Now().Unix(),
  3113. Status: 0,
  3114. Number: chrg_bchno,
  3115. Infcode: 0,
  3116. WarnMsg: "",
  3117. Cainfo: "",
  3118. ErrMsg: "",
  3119. RespondTime: "",
  3120. InfRefmsgid: "",
  3121. OrderStatus: 1,
  3122. IsMedicineInsurance: 1,
  3123. MedType: strconv.Itoa(int(reg_type)),
  3124. SettleType: settle_accounts_type,
  3125. SettleStartTime: start_time,
  3126. SettleEndTime: end_time,
  3127. Creator: admin_user_id,
  3128. Modify: admin_user_id,
  3129. OrgSetlNumber: number,
  3130. MdtrtId: mz_number,
  3131. PType: 2,
  3132. }
  3133. data, _ := json.Marshal(ress)
  3134. order.DetailLog = string(data)
  3135. err = service.CreateOrder(order)
  3136. if err != nil {
  3137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  3138. return
  3139. }
  3140. for _, subItem := range ress {
  3141. for _, item := range subItem.Transbody.Outputlist {
  3142. temp := strings.Split(item.Bkf500, "-")
  3143. var advice_id int64 = 0
  3144. var project_id int64 = 0
  3145. var types int64 = 0
  3146. id, _ := strconv.ParseInt(temp[2], 10, 64)
  3147. types, _ = strconv.ParseInt(temp[1], 10, 64)
  3148. if temp[1] == "1" {
  3149. advice_id = id
  3150. project_id = 0
  3151. } else if temp[1] == "2" {
  3152. advice_id = 0
  3153. project_id = id
  3154. }
  3155. info := &models.HisOrderInfo{
  3156. OrderNumber: order.Number,
  3157. FeedetlSn: item.Bkf500,
  3158. UploadDate: time.Now().Unix(),
  3159. AdviceId: advice_id,
  3160. DetItemFeeSumamt: item.Akc264,
  3161. Cnt: item.Akc226,
  3162. Pric: float64(item.Akc225),
  3163. PatientId: patient_id,
  3164. Status: 1,
  3165. ChrgitmLv: item.Aka065,
  3166. Mtime: time.Now().Unix(),
  3167. Ctime: time.Now().Unix(),
  3168. UserOrgId: adminUser.CurrentOrgId,
  3169. OrderId: order.ID,
  3170. ProjectId: project_id,
  3171. Type: types,
  3172. OverPricPsnPay: item.Akc268,
  3173. AllowReimburse: item.Cka319,
  3174. }
  3175. service.CreateOrderInfo(info)
  3176. }
  3177. }
  3178. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  3179. service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, his_patient_id, chrg_bchno, recordDateTime)
  3180. var total float64
  3181. for _, item := range prescriptions {
  3182. if item.Type == 1 { //药品
  3183. for _, subItem := range item.HisDoctorAdviceInfo {
  3184. total = total + (subItem.Price * subItem.PrescribingNumber)
  3185. }
  3186. }
  3187. if item.Type == 2 { //项目
  3188. for _, subItem := range item.HisPrescriptionProject {
  3189. total = total + (subItem.Price * float64(subItem.Count))
  3190. }
  3191. }
  3192. }
  3193. for _, item := range prescriptions {
  3194. for _, subItem := range item.HisAdditionalCharge {
  3195. total = total + (subItem.Price * float64(subItem.Count))
  3196. }
  3197. }
  3198. total, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", total), 64)
  3199. yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("FY005" + "|" + number + "|" + miConfig.Code + "|")
  3200. if ret4 == 0 {
  3201. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  3202. tempPatient, _ := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  3203. if tempPatient.ID == patient_id {
  3204. 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)
  3205. var dat map[string]interface{}
  3206. if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  3207. fmt.Println(dat)
  3208. } else {
  3209. fmt.Println(err)
  3210. }
  3211. userJSONBytes, _ := json.Marshal(dat)
  3212. var res ResultTwo
  3213. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3214. utils.ErrorLog("解析失败:%v", err)
  3215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3216. return
  3217. }
  3218. if res.Transreturncode == "00000000" {
  3219. order.OrderStatus = 1
  3220. order.Status = 1
  3221. order.PsnNo = health_card_no
  3222. order.Modify = admin_user_id
  3223. order.MedfeeSumamt = res.Transbody.Akc264
  3224. order.FundPaySumamt = res.Transbody.Akb068
  3225. order.AcctPay = res.Transbody.Akb066
  3226. order.PsnCashPay = res.Transbody.Akb067
  3227. order.PsnPartAmt = res.Transbody.Akb067
  3228. order.AccountPrice = res.Transbody.Aae240
  3229. order.MzNumber = mz_number
  3230. order.YiliaoNumber = yiliao_number
  3231. setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  3232. detailStrOne := string(setlDetailOne)
  3233. order.SzChargeInfo = detailStrOne
  3234. setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  3235. detailStrTwo := string(setlDetailTwo)
  3236. order.SzProjectInfo = detailStrTwo
  3237. setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  3238. detailStrThree := string(setlDetailThree)
  3239. order.SzMedicineInsuranceInfo = detailStrThree
  3240. order.Cainfo = result_three
  3241. order.IsPre = 1
  3242. //err = service.UpdataOrderStatusTwo(order.Number, adminUser.CurrentOrgId)
  3243. err = service.UpDateOrderTwo(order)
  3244. c.ServeSuccessJSON(map[string]interface{}{
  3245. "msg": "预结算成功",
  3246. })
  3247. } else {
  3248. //预结算报错
  3249. errlog := &models.HisOrderError{
  3250. UserOrgId: adminUser.CurrentOrgId,
  3251. Ctime: time.Now().Unix(),
  3252. Mtime: time.Now().Unix(),
  3253. Number: chrg_bchno,
  3254. ErrMsg: res.Transreturnmessage,
  3255. Status: 1,
  3256. PatientId: patient_id,
  3257. RecordTime: recordDateTime,
  3258. Stage: 20,
  3259. }
  3260. service.CreateErrMsgLog(errlog)
  3261. c.ServeSuccessJSON(map[string]interface{}{
  3262. "failed_code": -10,
  3263. "msg": res.Transreturnmessage,
  3264. })
  3265. }
  3266. } else {
  3267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  3268. return
  3269. }
  3270. } else {
  3271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  3272. return
  3273. }
  3274. } else {
  3275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePreSettleFaildParamWrong)
  3276. return
  3277. }
  3278. }
  3279. //func (c *SZHisApiController) GetSettleInfo() {
  3280. // pay_way, _ := c.GetInt64("pay_way")
  3281. // pay_price, _ := c.GetFloat("pay_price")
  3282. // pay_card_no := c.GetString("pay_card_no")
  3283. // discount_price, _ := c.GetFloat("discount_price")
  3284. // preferential_price, _ := c.GetFloat("preferential_price")
  3285. // reality_price, _ := c.GetFloat("reality_price")
  3286. // found_price, _ := c.GetFloat("found_price")
  3287. // medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  3288. // private_price, _ := c.GetFloat("private_price")
  3289. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  3290. // patient_id, _ := c.GetInt64("id")
  3291. // record_time := c.GetString("record_time")
  3292. // admin_user_id, _ := c.GetInt64("admin_user_id")
  3293. // timestamp := time.Now().Unix()
  3294. // tempTime := time.Unix(timestamp, 0)
  3295. // timeFormat := tempTime.Format("20060102150405")
  3296. // chrgBchno := rand.Intn(10000) + 1000
  3297. // chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(1, 10)
  3298. // adminUser := c.GetAdminUserInfo()
  3299. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3300. // month := time.Unix(1557042972, 0).Format("1")
  3301. // year := time.Now().Format("2006")
  3302. // month = time.Now().Format("01")
  3303. // day := time.Now().Format("02")
  3304. //
  3305. // timeLayout := "2006-01-02"
  3306. // loc, _ := time.LoadLocation("Local")
  3307. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3308. // fmt.Println(err)
  3309. // if err != nil {
  3310. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3311. // return
  3312. // }
  3313. // recordDateTime := theTime.Unix()
  3314. //
  3315. // var prescriptions []*models.HisPrescription
  3316. //
  3317. // var start_time int64
  3318. // var end_time int64
  3319. //
  3320. // if settle_accounts_type == 1 { //日结
  3321. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3322. //
  3323. // } else { //月结
  3324. // start_time_str := c.GetString("start_time")
  3325. // end_time_str := c.GetString("end_time")
  3326. // timeLayout := "2006-01-02"
  3327. // loc, _ := time.LoadLocation("Local")
  3328. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3329. // if err != nil {
  3330. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3331. // return
  3332. // }
  3333. // recordStartTime := theStartTime.Unix()
  3334. // start_time = recordStartTime
  3335. //
  3336. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3337. // if err != nil {
  3338. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3339. // return
  3340. // }
  3341. // recordEndTime := theEndTime.Unix()
  3342. // end_time = recordEndTime
  3343. //
  3344. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
  3345. // }
  3346. //
  3347. // var ids []int64
  3348. // for _, item := range prescriptions {
  3349. // ids = append(ids, item.ID)
  3350. // }
  3351. //
  3352. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3353. //
  3354. // adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  3355. //
  3356. // adminRole, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3357. // his, err := service.GetHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3358. // mz_number := his.Number
  3359. // number := miConfig.Code + year + month + day +
  3360. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  3361. // var doctor_name string
  3362. // var doctor_code string
  3363. // var drug_doctor_code string
  3364. // drug_doctor_code = adminRole_two.DoctorCode
  3365. // drug_doctor_name := adminRole_two.UserName
  3366. //
  3367. // if adminRole.ID == 0 {
  3368. // doctor_name = "黄亦轩"
  3369. // doctor_code = "1"
  3370. // } else {
  3371. // doctor_name = adminRole.UserName
  3372. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  3373. // }
  3374. //
  3375. // verifyCode, version_code := ReadCardGetCode("FY001" + "|" + number + "|" + miConfig.Code)
  3376. // //verifyCode := "000000|bf885fa312a7f92861d6b61542a637fa"
  3377. // //version_code := "V0.3"
  3378. // var customs []*models.CustomDetail
  3379. // for _, item := range prescriptions {
  3380. // if item.Type == 1 { //药品
  3381. // for _, subItem := range item.HisDoctorAdviceInfo {
  3382. // fmt.Println(subItem.BaseDrugLib.MedicalInsuranceNumber)
  3383. //
  3384. // if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 {
  3385. // _, dose_code := service.GetDoseCode(subItem.BaseDrugLib.DrugDosageForm, adminUser.CurrentOrgId)
  3386. // detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber), 64)
  3387. // price, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price), 64)
  3388. // temp := strings.Split(subItem.FeedetlSn, "-")
  3389. // newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  3390. //
  3391. // cus := &models.CustomDetail{
  3392. // PrescriptionNumber: chrg_bchno,
  3393. // OrderType: "1",
  3394. // ChargeSerialNumber: newFl,
  3395. // Code: subItem.BaseDrugLib.MedicalInsuranceNumber,
  3396. // CodeName: subItem.BaseDrugLib.DrugName,
  3397. // Flag: "1",
  3398. // Price: price,
  3399. // Count: subItem.PrescribingNumber,
  3400. // ChargeOrderDate: year + month + day,
  3401. // DoctorCode: doctor_code,
  3402. // Total: detItemFeeSumamt,
  3403. // DoseCode: dose_code,
  3404. // Spec: subItem.BaseDrugLib.DrugSpec,
  3405. // }
  3406. // customs = append(customs, cus)
  3407. // }
  3408. // }
  3409. // }
  3410. //
  3411. // if item.Type == 2 { //项目
  3412. // for _, subItem := range item.HisPrescriptionProject {
  3413. // if len(subItem.HisProject.MedicalCode) > 0 {
  3414. // detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  3415. //
  3416. // count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  3417. // temp := strings.Split(subItem.FeedetlSn, "-")
  3418. // newFl := fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) + "-" + temp[1] + "-" + temp[2]
  3419. //
  3420. // cus := &models.CustomDetail{
  3421. // PrescriptionNumber: chrg_bchno,
  3422. // OrderType: "1",
  3423. // ChargeSerialNumber: newFl,
  3424. // Code: subItem.HisProject.MedicalCode,
  3425. // CodeName: subItem.HisProject.ProjectName,
  3426. // Flag: "1",
  3427. // Price: subItem.Price,
  3428. // Count: count,
  3429. // ChargeOrderDate: year + month + day,
  3430. // DoctorCode: doctor_code,
  3431. // Total: detItemFeeSumamt,
  3432. // DoseCode: "",
  3433. // Spec: "次",
  3434. // }
  3435. // customs = append(customs, cus)
  3436. // }
  3437. // }
  3438. // }
  3439. // //
  3440. // //for _, subItem := range item.HisAdditionalCharge {
  3441. // // if len(subItem.XtHisAddtionConfig.Code) > 0 {
  3442. // // detItemFeeSumamt, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), 64)
  3443. // //
  3444. // // count, _ := strconv.ParseFloat(fmt.Sprintf("%f", subItem.Count), 64)
  3445. // // cus := &models.CustomDetail{
  3446. // // PrescriptionNumber: chrg_bchno,
  3447. // // OrderType: "1",
  3448. // // ChargeSerialNumber: subItem.FeedetlSn,
  3449. // // Code: subItem.XtHisAddtionConfig.Code,
  3450. // // CodeName: subItem.XtHisAddtionConfig.Name,
  3451. // // Flag: "1",
  3452. // // Price: subItem.Price,
  3453. // // Count: count,
  3454. // // ChargeOrderDate: year + month + day,
  3455. // // DoctorCode: doctor_code,
  3456. // // Total: detItemFeeSumamt,
  3457. // // DoseCode: "",
  3458. // // Spec: subItem.XtHisAddtionConfig.,
  3459. // // }
  3460. // // customs = append(customs, cus)
  3461. // // }
  3462. // //}
  3463. // }
  3464. //
  3465. // var pagesize int = 50
  3466. // var start int = 1
  3467. // var stop int
  3468. // var pagecount int
  3469. // var curpage int
  3470. // var isSuccess bool = true
  3471. // //总页数,向上取整,注意除之前要先转换类型为float64
  3472. // pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  3473. //
  3474. // var ress []*Result
  3475. // for curpage = 1; curpage <= pagecount; curpage++ {
  3476. // if curpage == 1 {
  3477. // start = 1
  3478. // } else {
  3479. // start = (curpage-1)*pagesize + 1
  3480. // }
  3481. // stop = curpage * pagesize
  3482. // if stop > len(customs) {
  3483. // stop = len(customs)
  3484. // }
  3485. // result := service.SzybFY001(doctor_name, doctor_code, miConfig.Code, customs[start-1:stop], verifyCode, number, mz_number, version_code, drug_doctor_code)
  3486. // fmt.Println(result)
  3487. //
  3488. // var dat map[string]interface{}
  3489. // if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3490. // fmt.Println(dat)
  3491. // } else {
  3492. // fmt.Println(err)
  3493. // }
  3494. //
  3495. // userJSONBytes, _ := json.Marshal(dat)
  3496. //
  3497. // var res Result
  3498. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3499. // utils.ErrorLog("解析失败:%v", err)
  3500. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3501. // return
  3502. // }
  3503. // if res.Transreturncode == "00000000" {
  3504. // ress = append(ress, &res)
  3505. // } else {
  3506. // isSuccess = false
  3507. // errlog := &models.HisOrderError{
  3508. // UserOrgId: adminUser.CurrentOrgId,
  3509. // Ctime: time.Now().Unix(),
  3510. // Mtime: time.Now().Unix(),
  3511. // Number: chrg_bchno,
  3512. // ErrMsg: res.Transreturnmessage,
  3513. // Status: 1,
  3514. // PatientId: patient_id,
  3515. // RecordTime: recordDateTime,
  3516. // Stage: 4,
  3517. // }
  3518. // service.CreateErrMsgLog(errlog)
  3519. // c.ServeSuccessJSON(map[string]interface{}{
  3520. // "failed_code": -10,
  3521. // "msg": res.Transreturnmessage,
  3522. // })
  3523. // return
  3524. // }
  3525. // //设置变量,根据变量的值来判断上传是否成功
  3526. // }
  3527. // if isSuccess == true {
  3528. // order := &models.HisOrder{
  3529. // UserOrgId: adminUser.CurrentOrgId,
  3530. // HisPatientId: 0,
  3531. // PatientId: patient_id,
  3532. // SettleAccountsDate: recordDateTime,
  3533. // Ctime: time.Now().Unix(),
  3534. // Mtime: time.Now().Unix(),
  3535. // Status: 1,
  3536. // Number: chrg_bchno,
  3537. // Infcode: 0,
  3538. // WarnMsg: "",
  3539. // Cainfo: "",
  3540. // ErrMsg: "",
  3541. // RespondTime: "",
  3542. // InfRefmsgid: "",
  3543. // OrderStatus: 1,
  3544. // IsMedicineInsurance: 1,
  3545. // SettleType: settle_accounts_type,
  3546. // SettleStartTime: start_time,
  3547. // SettleEndTime: end_time,
  3548. // Creator: admin_user_id,
  3549. // Modify: admin_user_id,
  3550. // OrgSetlNumber: number,
  3551. // }
  3552. // data, _ := json.Marshal(ress)
  3553. // order.DetailLog = string(data)
  3554. //
  3555. // err = service.CreateOrder(order)
  3556. // if err != nil {
  3557. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  3558. // return
  3559. // }
  3560. //
  3561. // for _, subItem := range ress {
  3562. // for _, item := range subItem.Transbody.Outputlist {
  3563. //
  3564. // temp := strings.Split(item.Bkf500, "-")
  3565. // var advice_id int64 = 0
  3566. // var project_id int64 = 0
  3567. // var types int64 = 0
  3568. //
  3569. // id, _ := strconv.ParseInt(temp[2], 10, 64)
  3570. // types, _ = strconv.ParseInt(temp[1], 10, 64)
  3571. //
  3572. // if temp[1] == "1" {
  3573. // advice_id = id
  3574. // project_id = 0
  3575. // } else if temp[1] == "2" {
  3576. // advice_id = 0
  3577. // project_id = id
  3578. // }
  3579. //
  3580. // info := &models.HisOrderInfo{
  3581. // OrderNumber: order.Number,
  3582. // FeedetlSn: item.Bkf500,
  3583. // UploadDate: time.Now().Unix(),
  3584. // AdviceId: advice_id,
  3585. // DetItemFeeSumamt: item.Akc264,
  3586. // Cnt: item.Akc226,
  3587. // Pric: float64(item.Akc225),
  3588. // PatientId: patient_id,
  3589. // Status: 1,
  3590. // ChrgitmLv: item.Aka065,
  3591. // Mtime: time.Now().Unix(),
  3592. // Ctime: time.Now().Unix(),
  3593. // UserOrgId: adminUser.CurrentOrgId,
  3594. // OrderId: order.ID,
  3595. // ProjectId: project_id,
  3596. // Type: types,
  3597. //
  3598. // OverPricPsnPay: item.Akc268,
  3599. // AllowReimburse: item.Cka319,
  3600. // }
  3601. // service.CreateOrderInfo(info)
  3602. //
  3603. // }
  3604. // }
  3605. // service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  3606. // service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patient_id, chrg_bchno, recordDateTime)
  3607. // var total float64
  3608. // for _, item := range prescriptions {
  3609. // if item.Type == 1 { //药品
  3610. // for _, subItem := range item.HisDoctorAdviceInfo {
  3611. // total = total + (subItem.Price * subItem.PrescribingNumber)
  3612. // }
  3613. // }
  3614. // if item.Type == 2 { //项目
  3615. // for _, subItem := range item.HisPrescriptionProject {
  3616. // total = total + (subItem.Price * float64(subItem.Count))
  3617. // }
  3618. // }
  3619. // }
  3620. // for _, item := range prescriptions {
  3621. // for _, subItem := range item.HisAdditionalCharge {
  3622. // total = total + (subItem.Price * float64(subItem.Count))
  3623. // }
  3624. // }
  3625. //
  3626. // yiliao_number, id_card_number, verifyCode, version_code, _, ret4 := ReadBasCardGetNumber("FY005" + "|" + number + "|" + miConfig.Code + "|")
  3627. // if ret4 == 0 {
  3628. // //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  3629. // tempPatient, _ := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  3630. // if tempPatient.ID == patient_id {
  3631. //
  3632. // 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)
  3633. // var dat map[string]interface{}
  3634. // if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  3635. // fmt.Println(dat)
  3636. // } else {
  3637. // fmt.Println(err)
  3638. // }
  3639. // userJSONBytes, _ := json.Marshal(dat)
  3640. // var res ResultTwo
  3641. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3642. // utils.ErrorLog("解析失败:%v", err)
  3643. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3644. // return
  3645. // }
  3646. //
  3647. // if res.Transreturncode == "00000000" {
  3648. // order.OrderStatus = 2
  3649. // order.PayWay = pay_way
  3650. // order.PayPrice = pay_price
  3651. // order.PayCardNo = pay_card_no
  3652. // order.DiscountPrice = discount_price
  3653. // order.PreferentialPrice = preferential_price
  3654. // order.RealityPrice = reality_price
  3655. // order.FoundPrice = found_price
  3656. // order.MedicalInsurancePrice = medical_insurance_price
  3657. // order.PrivatePrice = private_price
  3658. // order.Modify = admin_user_id
  3659. // order.MedfeeSumamt = res.Transbody.Akc264
  3660. // order.SetlId = res.Transbody.Ckc618
  3661. // order.FundPaySumamt = res.Transbody.Akb068
  3662. // order.AcctPay = res.Transbody.Akb066
  3663. // order.PsnCashPay = res.Transbody.Akb067
  3664. // order.PsnPartAmt = res.Transbody.Akb067
  3665. // order.AccountPrice = res.Transbody.Aae240
  3666. // order.MzNumber = mz_number
  3667. // order.YiliaoNumber = yiliao_number
  3668. // setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  3669. // detailStrOne := string(setlDetailOne)
  3670. // order.SzChargeInfo = detailStrOne
  3671. // setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  3672. // detailStrTwo := string(setlDetailTwo)
  3673. // order.SzProjectInfo = detailStrTwo
  3674. // setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  3675. // detailStrThree := string(setlDetailThree)
  3676. // order.SzMedicineInsuranceInfo = detailStrThree
  3677. // order.Cainfo = result_three
  3678. // err = service.UpdataOrderStatusTwo(order.Number, adminUser.CurrentOrgId)
  3679. // err = service.UpDateOrderTwo(order)
  3680. // c.ServeSuccessJSON(map[string]interface{}{
  3681. // "msg": "结算成功",
  3682. // })
  3683. // } else {
  3684. // //结算报错
  3685. // errlog := &models.HisOrderError{
  3686. // UserOrgId: adminUser.CurrentOrgId,
  3687. // Ctime: time.Now().Unix(),
  3688. // Mtime: time.Now().Unix(),
  3689. // Number: chrg_bchno,
  3690. // ErrMsg: res.Transreturnmessage,
  3691. // Status: 1,
  3692. // PatientId: patient_id,
  3693. // RecordTime: recordDateTime,
  3694. // Stage: 6,
  3695. // }
  3696. // service.CreateErrMsgLog(errlog)
  3697. // c.ServeSuccessJSON(map[string]interface{}{
  3698. // "failed_code": -10,
  3699. // "msg": res.Transreturnmessage,
  3700. // })
  3701. // }
  3702. // } else {
  3703. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  3704. // return
  3705. // }
  3706. // } else {
  3707. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  3708. // return
  3709. // }
  3710. // } else {
  3711. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePreSettleFaildParamWrong)
  3712. // return
  3713. // }
  3714. //}
  3715. //结算
  3716. //func (c *SZHisApiController) GetSettleInfo() {
  3717. // patient_id, _ := c.GetInt64("id")
  3718. // order_id, _ := c.GetInt64("order_id")
  3719. // record_time := c.GetString("record_time")
  3720. // pay_way, _ := c.GetInt64("pay_way")
  3721. // pay_price, _ := c.GetFloat("pay_price")
  3722. // pay_card_no := c.GetString("pay_card_no")
  3723. // discount_price, _ := c.GetFloat("discount_price")
  3724. // preferential_price, _ := c.GetFloat("preferential_price")
  3725. // reality_price, _ := c.GetFloat("reality_price")
  3726. // found_price, _ := c.GetFloat("found_price")
  3727. // medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  3728. // private_price, _ := c.GetFloat("private_price")
  3729. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  3730. // admin_user_id, _ := c.GetInt64("admin_user_id")
  3731. //
  3732. // timeLayout := "2006-01-02"
  3733. // loc, _ := time.LoadLocation("Local")
  3734. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3735. // if err != nil {
  3736. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3737. // return
  3738. // }
  3739. // recordDateTime := theTime.Unix()
  3740. // adminUser := c.GetAdminUserInfo()
  3741. //
  3742. // var prescriptions []*models.HisPrescription
  3743. //
  3744. // data := make(map[string]interface{})
  3745. // if settle_accounts_type == 1 { //日结
  3746. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3747. // data["pre"] = prescriptions
  3748. //
  3749. // } else { //月结
  3750. // start_time_str := c.GetString("start_time")
  3751. // end_time_str := c.GetString("end_time")
  3752. // timeLayout := "2006-01-02"
  3753. // loc, _ := time.LoadLocation("Local")
  3754. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3755. // if err != nil {
  3756. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3757. // return
  3758. // }
  3759. // recordStartTime := theStartTime.Unix()
  3760. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3761. // if err != nil {
  3762. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3763. // return
  3764. // }
  3765. // recordEndTime := theEndTime.Unix()
  3766. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
  3767. // data["pre"] = prescriptions
  3768. //
  3769. // }
  3770. //
  3771. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3772. // his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3773. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3774. // strconv.FormatInt(his.PatientId, 10)
  3775. //
  3776. // order_src, _ := service.GetHisOrderByID(order_id)
  3777. //
  3778. // if order_src.ID == 0 {
  3779. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  3780. // return
  3781. // }
  3782. //
  3783. // config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3784. // if config.IsOpen == 1 { //对接了医保,走医保流程
  3785. // if order_src.OrderStatus != 2 {
  3786. // var total float64
  3787. // for _, item := range prescriptions {
  3788. // if item.Type == 1 { //药品
  3789. // for _, subItem := range item.HisDoctorAdviceInfo {
  3790. // total = total + (subItem.Price * subItem.PrescribingNumber)
  3791. // }
  3792. // }
  3793. // if item.Type == 2 { //项目
  3794. // for _, subItem := range item.HisPrescriptionProject {
  3795. // total = total + (subItem.Price * float64(subItem.Count))
  3796. // }
  3797. // }
  3798. // }
  3799. //
  3800. // for _, item := range prescriptions {
  3801. // for _, subItem := range item.HisAdditionalCharge {
  3802. // total = total + (subItem.Price * float64(subItem.Count))
  3803. // }
  3804. // }
  3805. //
  3806. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3807. //
  3808. // adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  3809. //
  3810. // var drug_doctor string
  3811. // drug_doctor = adminRole_two.DoctorCode
  3812. // drug_doctor_name := adminRole_two.UserName
  3813. // //结算流程
  3814. // var doctor_name string
  3815. // var doctor_code string
  3816. // if roles.ID == 0 {
  3817. // doctor_name = "黄亦轩"
  3818. // doctor_code = "1010"
  3819. // } else {
  3820. // doctor_name = roles.UserName
  3821. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  3822. // }
  3823. // number := order_src.OrgSetlNumber
  3824. // mz_number := his.Number
  3825. // verifyCode, version_code := ReadCardGetCode("FY005" + "|" + number + "|" + miConfig.Code)
  3826. //
  3827. // //verifyCode := "000000|707c35a62c2f0609d7b0a811649f3913"
  3828. // //version_code := "V0.3"
  3829. // yiliao_number, id_card_number, verifyCode, version_code, err, ret4 := ReadBasCardGetNumber("FY005" + "|" + number + "|" + miConfig.Code)
  3830. // yiliao_number := his.YiliaoNumber
  3831. // result_three := service.SzybFY005(doctor_name, doctor_code, miConfig.Code, total, yiliao_number, verifyCode, number, mz_number, version_code, drug_doctor, drug_doctor_name)
  3832. // var dat map[string]interface{}
  3833. // if err := json.Unmarshal([]byte(result_three), &dat); err == nil {
  3834. // fmt.Println(dat)
  3835. // } else {
  3836. // fmt.Println(err)
  3837. // }
  3838. // userJSONBytes, _ := json.Marshal(dat)
  3839. // var res ResultTwo
  3840. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3841. // utils.ErrorLog("解析失败:%v", err)
  3842. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3843. // return
  3844. // }
  3845. //
  3846. // if res.Transreturncode == "00000000" {
  3847. // order_src.OrderStatus = 2
  3848. // order_src.PayWay = pay_way
  3849. // order_src.PayPrice = pay_price
  3850. // order_src.PayCardNo = pay_card_no
  3851. // order_src.DiscountPrice = discount_price
  3852. // order_src.PreferentialPrice = preferential_price
  3853. // order_src.RealityPrice = reality_price
  3854. // order_src.FoundPrice = found_price
  3855. // order_src.MedicalInsurancePrice = medical_insurance_price
  3856. // order_src.PrivatePrice = private_price
  3857. // order_src.Creator = order_src.Creator
  3858. // order_src.Modify = roles.ID
  3859. // order_src.MedfeeSumamt = res.Transbody.Akc264
  3860. // order_src.SetlId = res.Transbody.Ckc618
  3861. // order_src.FundPaySumamt = res.Transbody.Akb068
  3862. // order_src.AcctPay = res.Transbody.Akb066
  3863. // order_src.PsnCashPay = res.Transbody.Akb067
  3864. // order_src.PsnPartAmt = res.Transbody.Akb067
  3865. // order_src.AccountPrice = res.Transbody.Aae240
  3866. // order_src.MzNumber = mz_number
  3867. // order_src.YiliaoNumber = yiliao_number
  3868. // setlDetailOne, _ := json.Marshal(res.Transbody.Outputlist1)
  3869. // detailStrOne := string(setlDetailOne)
  3870. // order_src.SzChargeInfo = detailStrOne
  3871. // setlDetailTwo, _ := json.Marshal(res.Transbody.Outputlist2)
  3872. // detailStrTwo := string(setlDetailTwo)
  3873. // order_src.SzProjectInfo = detailStrTwo
  3874. // setlDetailThree, _ := json.Marshal(res.Transbody.Outputlist3)
  3875. // detailStrThree := string(setlDetailThree)
  3876. // order_src.SzMedicineInsuranceInfo = detailStrThree
  3877. // order_src.Cainfo = result_three
  3878. //
  3879. // err = service.UpdataOrderStatusTwo(order_src.Number, adminUser.CurrentOrgId)
  3880. // err = service.UpDateOrder(order_src)
  3881. //
  3882. // c.ServeSuccessJSON(map[string]interface{}{
  3883. // "msg": "结算成功",
  3884. // })
  3885. // } else {
  3886. // //version_code := "0.03"
  3887. // c.ServeSuccessJSON(map[string]interface{}{
  3888. // "failed_code": -10,
  3889. // "msg": res.Transreturnmessage,
  3890. // })
  3891. //
  3892. // }
  3893. // } else {
  3894. //
  3895. // //错误提示
  3896. //
  3897. // }
  3898. // } else {
  3899. // //错误提示
  3900. //
  3901. // }
  3902. //}
  3903. //当月退费
  3904. func (c *SZHisApiController) Refund() {
  3905. order_id, _ := c.GetInt64("order_id")
  3906. record_time := c.GetString("record_time")
  3907. //patient_id, _ := c.GetInt64("patient_id")
  3908. //his_patient_id, _ := c.GetInt64("his_patient_id")
  3909. admin_user_id, _ := c.GetInt64("admin_user_id")
  3910. timeLayout := "2006-01-02"
  3911. loc, _ := time.LoadLocation("Local")
  3912. adminUser := c.GetAdminUserInfo()
  3913. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3914. fmt.Println(err)
  3915. if err != nil {
  3916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3917. return
  3918. }
  3919. recordDateTime := theTime.Unix()
  3920. fmt.Println(recordDateTime)
  3921. var order models.HisOrder
  3922. order, _ = service.GetHisOrderByID(order_id)
  3923. if order.ID == 0 {
  3924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  3925. return
  3926. }
  3927. //his, _ := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, theTime.Unix())
  3928. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3929. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3930. //结算流程
  3931. var doctor_name string
  3932. var doctor_code string
  3933. if roles.ID == 0 {
  3934. doctor_name = "管理员"
  3935. doctor_code = "01"
  3936. } else {
  3937. doctor_name = roles.UserName
  3938. doctor_code = strconv.FormatInt(admin_user_id, 10)
  3939. }
  3940. month := time.Unix(1557042972, 0).Format("1")
  3941. year := time.Now().Format("2006")
  3942. month = time.Now().Format("01")
  3943. day := time.Now().Format("02")
  3944. //number := miConfig.Code + year + month + day + "1367866"
  3945. number := miConfig.Code + year + month + day +
  3946. fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000)) // 定点协议机构编码(5位)+日期(8位)+流水号(7位)
  3947. //number := miConfig.Code + year + month + day + "1590003"
  3948. //流水号
  3949. //number_two := miConfig.Code + "-" + year + month + day + "-" + strconv.FormatInt(patient_id, 10)
  3950. verifyCode, version_code := ReadCardGetCode("JY002" + "|" + number + "|" + miConfig.Code)
  3951. //version_code := "V0.3"
  3952. //
  3953. //verifyCode := "000000|9972fca7ba9471c7dbe08324b2e31f70"
  3954. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3955. order_infos, _ := service.GetHisOrderInfoByNumber(order.Number)
  3956. var customs []*models.CustomDetail
  3957. for _, item := range order_infos {
  3958. cus := &models.CustomDetail{
  3959. PrescriptionNumber: item.OrderNumber,
  3960. ChargeSerialNumber: item.FeedetlSn,
  3961. }
  3962. customs = append(customs, cus)
  3963. }
  3964. if config.IsOpen == 1 { //对接了医保,走医保流程
  3965. result := service.SzybJY002(doctor_name, doctor_code, miConfig.Code, order.OrgSetlNumber, order.MzNumber, verifyCode, number, version_code)
  3966. fmt.Println(result)
  3967. var dat map[string]interface{}
  3968. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3969. fmt.Println(dat)
  3970. } else {
  3971. fmt.Println(err)
  3972. }
  3973. userJSONBytes, _ := json.Marshal(dat)
  3974. var res ResultThree
  3975. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3976. utils.ErrorLog("解析失败:%v", err)
  3977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3978. return
  3979. }
  3980. if res.Transreturncode == "00000000" {
  3981. service.UpdataOrderlog(order_id, adminUser.CurrentOrgId, result)
  3982. service.UpdataOrderStatusSZ(order_id, order.Number, adminUser.CurrentOrgId)
  3983. service.UpdataOrderInfoStatus(order.ID, order.Number, adminUser.CurrentOrgId)
  3984. c.ServeSuccessJSON(map[string]interface{}{
  3985. "msg": "退费成功",
  3986. })
  3987. } else {
  3988. c.ServeSuccessJSON(map[string]interface{}{
  3989. "failed_code": -10,
  3990. "msg": res.Transreturnmessage,
  3991. })
  3992. }
  3993. }
  3994. }
  3995. //跨月退费
  3996. func (c *SZHisApiController) MonthRefund() {
  3997. order_id, _ := c.GetInt64("order_id")
  3998. record_time := c.GetString("record_time")
  3999. patient_id, _ := c.GetInt64("patient_id")
  4000. admin_user_id, _ := c.GetInt64("admin_user_id")
  4001. timeLayout := "2006-01-02"
  4002. loc, _ := time.LoadLocation("Local")
  4003. adminUser := c.GetAdminUserInfo()
  4004. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4005. fmt.Println(err)
  4006. if err != nil {
  4007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4008. return
  4009. }
  4010. recordDateTime := theTime.Unix()
  4011. var order models.HisOrder
  4012. order, _ = service.GetHisOrderByID(order_id)
  4013. if order.ID == 0 {
  4014. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  4015. }
  4016. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4017. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4018. //结算流程
  4019. var doctor_name string
  4020. var doctor_code string
  4021. if roles.ID == 0 {
  4022. doctor_name = "管理员"
  4023. doctor_code = "01"
  4024. } else {
  4025. doctor_name = roles.UserName
  4026. doctor_code = strconv.FormatInt(admin_user_id, 10)
  4027. }
  4028. month := time.Unix(1557042972, 0).Format("1")
  4029. year := time.Now().Format("2006")
  4030. month = time.Now().Format("01")
  4031. day := time.Now().Format("02")
  4032. //流水号
  4033. number_two := miConfig.Code + "-" + year + month + day + "-" + strconv.FormatInt(patient_id, 10)
  4034. //verifyCode,version_code := ReadCardGetCode("JY002" + "|" + number_two + "|" + miConfig.Code)
  4035. version_code := "0.03"
  4036. fmt.Println(number_two)
  4037. verifyCode := "000000|0872038667cc34efdc35ce4668589a5f"
  4038. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4039. if config.IsOpen == 1 { //对接了医保,走医保流程
  4040. result := service.SzybJY003(doctor_name, doctor_code, miConfig.Code, order.OrgSetlNumber, order.MzNumber, verifyCode, version_code)
  4041. fmt.Println(result)
  4042. var dat map[string]interface{}
  4043. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4044. fmt.Println(dat)
  4045. } else {
  4046. fmt.Println(err)
  4047. }
  4048. userJSONBytes, _ := json.Marshal(dat)
  4049. var res ResultThree
  4050. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4051. utils.ErrorLog("解析失败:%v", err)
  4052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4053. return
  4054. }
  4055. if res.Transreturncode == "00000000" {
  4056. c.ServeSuccessJSON(map[string]interface{}{
  4057. "msg": "退费成功",
  4058. })
  4059. } else {
  4060. }
  4061. }
  4062. }
  4063. //查询
  4064. func (c *SZHisApiController) GetSettleAccounts() {
  4065. order_id, _ := c.GetInt64("order_id")
  4066. record_time := c.GetString("record_time")
  4067. patient_id, _ := c.GetInt64("patient_id")
  4068. admin_user_id, _ := c.GetInt64("admin_user_id")
  4069. timeLayout := "2006-01-02"
  4070. loc, _ := time.LoadLocation("Local")
  4071. adminUser := c.GetAdminUserInfo()
  4072. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4073. fmt.Println(err)
  4074. if err != nil {
  4075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4076. return
  4077. }
  4078. recordDateTime := theTime.Unix()
  4079. fmt.Println(recordDateTime)
  4080. var order models.HisOrder
  4081. order, _ = service.GetHisOrderByID(order_id)
  4082. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, patient_id)
  4083. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  4084. adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  4085. his, _ := service.GetHisPatientInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  4086. yiliao_leibie := ""
  4087. switch order.MedType {
  4088. case "11":
  4089. yiliao_leibie = "普通门诊"
  4090. break
  4091. case "12":
  4092. yiliao_leibie = "家庭通道"
  4093. break
  4094. case "13":
  4095. yiliao_leibie = "门诊大病"
  4096. break
  4097. case "14":
  4098. yiliao_leibie = "重疾特药"
  4099. break
  4100. case "15":
  4101. yiliao_leibie = "门诊慢病"
  4102. break
  4103. case "16":
  4104. yiliao_leibie = "门诊特检"
  4105. break
  4106. case "17":
  4107. yiliao_leibie = "健康体检"
  4108. break
  4109. case "18":
  4110. yiliao_leibie = "预防接种"
  4111. break
  4112. case "19":
  4113. yiliao_leibie = "门诊输血"
  4114. break
  4115. case "91":
  4116. yiliao_leibie = "新冠肺炎门诊"
  4117. break
  4118. }
  4119. //departments, _ := service.Get(patientPrescription.Departments)
  4120. departments, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  4121. if order.ID == 0 {
  4122. //order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  4123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  4124. return
  4125. }
  4126. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4127. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4128. //结算流程
  4129. var doctor_name string
  4130. var doctor_code string
  4131. if roles.ID == 0 {
  4132. doctor_name = "管理员"
  4133. doctor_code = "01"
  4134. } else {
  4135. doctor_name = roles.UserName
  4136. doctor_code = strconv.FormatInt(admin_user_id, 10)
  4137. }
  4138. //month := time.Unix(1557042972, 0).Format("1")
  4139. //year := time.Now().Format("2006")
  4140. //month = time.Now().Format("01")
  4141. //day := time.Now().Format("02")
  4142. //流水号
  4143. //number_two := miConfig.Code + "-" + year + month + day + "-" + strconv.FormatInt(patient_id, 10)
  4144. //fmt.Println(number_two)
  4145. verifyCode, version_code := ReadCardGetCode("JY001" + "|" + order.OrgSetlNumber + "|" + miConfig.Code)
  4146. //version_code := "V0.3"
  4147. //verifyCode := "000000|2c9854287e7c3cbc34439ab8e5157816"
  4148. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4149. if config.IsOpen == 1 { //对接了医保,走医保流程
  4150. //temp_mz_number := miConfig.Code + year + month + day +
  4151. // fmt.Sprintf("%07v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000000))
  4152. //tempVerifyCode, tempVersionCode := ReadCardGetCode("XX001" + "|" + temp_mz_number + "|" + miConfig.Code)
  4153. //yiliao_number, id_card_number, verifyCode, version_code, health_card_no, _, ret4 := ReadBasCardGetNumber("MZ002" + "|" + number + "|" + miConfig.Code + "|")
  4154. //yiliao_number = "%GALMAFXJGKUKZNKWAIUH?;07857319025346309758?"
  4155. //result001 := service.SzybXX001(opera_name, opera_code, miConfig.Code, yiliao_number, tempVerifyCode, temp_mz_number, tempVersionCode)
  4156. result := service.SzybJY001(doctor_name, doctor_code, miConfig.Code, order.OrgSetlNumber, order.MzNumber, verifyCode, version_code)
  4157. fmt.Println(result)
  4158. var dat map[string]interface{}
  4159. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4160. fmt.Println(dat)
  4161. } else {
  4162. fmt.Println(err)
  4163. }
  4164. userJSONBytes, _ := json.Marshal(dat)
  4165. var res ResultFour
  4166. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4167. utils.ErrorLog("解析失败:%v", err)
  4168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4169. return
  4170. }
  4171. if res.Transreturncode == "00000000" {
  4172. var dat2 map[string]interface{}
  4173. if err := json.Unmarshal([]byte(his.PatientInfo), &dat2); err == nil {
  4174. fmt.Println(dat2)
  4175. } else {
  4176. fmt.Println(err)
  4177. }
  4178. userJSONBytes2, _ := json.Marshal(dat2)
  4179. var res2 ResultMZ001
  4180. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  4181. utils.ErrorLog("解析失败:%v", err)
  4182. }
  4183. c.ServeSuccessJSON(map[string]interface{}{
  4184. "result": res,
  4185. "org_name": miConfig.OrgName,
  4186. "org_code": miConfig.Code,
  4187. "patient_name": patient.Name,
  4188. "doctor_code": adminRole_two.DoctorCode,
  4189. "doctor_name": doctor_name,
  4190. "health_card_no": order.PsnNo,
  4191. "health_card_no_two": res2.Transbody.Aaz500,
  4192. "order_number": order.Number,
  4193. "department": departments.Name,
  4194. "yiliao_leibie": yiliao_leibie,
  4195. "before_money": res2.Transbody.Aae240,
  4196. "after_money": order.AccountPrice,
  4197. "dialysis_no": patient.DialysisNo,
  4198. "patient_info": res2,
  4199. })
  4200. } else {
  4201. c.ServeSuccessJSON(map[string]interface{}{
  4202. "failed_code": -10,
  4203. "msg": res.Transreturnmessage,
  4204. })
  4205. }
  4206. }
  4207. }
  4208. //费用录入取消
  4209. //func (c *SZHisApiController) CancelOrderDetail() {
  4210. // order_id, _ := c.GetInt64("order_id")
  4211. // record_time := c.GetString("record_time")
  4212. // patient_id, _ := c.GetInt64("patient_id")
  4213. // admin_user_id, _ := c.GetInt64("admin_user_id")
  4214. // timeLayout := "2006-01-02"
  4215. // loc, _ := time.LoadLocation("Local")
  4216. // adminUser := c.GetAdminUserInfo()
  4217. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4218. // fmt.Println(err)
  4219. // if err != nil {
  4220. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4221. // return
  4222. // }
  4223. // recordDateTime := theTime.Unix()
  4224. // var order models.HisOrder
  4225. // order, _ = service.GetHisOrderByID(order_id)
  4226. //
  4227. // if order.ID == 0 {
  4228. // order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  4229. //
  4230. // }
  4231. //
  4232. // order_infos, _ := service.GetHisOrderInfoByNumber(order.Number)
  4233. //
  4234. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4235. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4236. // //结算流程
  4237. // var doctor_name string
  4238. // var doctor_code string
  4239. // if roles.ID == 0 {
  4240. // doctor_name = "管理员"
  4241. // doctor_code = "1001"
  4242. // } else {
  4243. // doctor_name = roles.UserName
  4244. // doctor_code = strconv.FormatInt(admin_user_id, 10)
  4245. //
  4246. // }
  4247. // var customs []*models.CustomDetail
  4248. //
  4249. // for _, item := range order_infos {
  4250. // cus := &models.CustomDetail{
  4251. // PrescriptionNumber: item.OrderNumber,
  4252. // ChargeSerialNumber: item.FeedetlSn,
  4253. // }
  4254. // customs = append(customs, cus)
  4255. // }
  4256. // his, _ := service.GetHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  4257. //
  4258. // verifyCode, version_code := ReadCardGetCode("FY002" + "|" + order.OrgSetlNumber + "|" + miConfig.Code)
  4259. //
  4260. // var pagesize int = 50
  4261. // var start int = 1
  4262. // var stop int
  4263. // var pagecount int
  4264. // var curpage int
  4265. // var isSuccess bool = true
  4266. // var ress []*ResultFive
  4267. //
  4268. // //总页数,向上取整,注意除之前要先转换类型为float64
  4269. // pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  4270. //
  4271. // for curpage = 1; curpage <= pagecount; curpage++ {
  4272. // if curpage == 1 {
  4273. // start = 1
  4274. // } else {
  4275. // start = (curpage-1)*pagesize + 1
  4276. // }
  4277. // stop = curpage * pagesize
  4278. // if stop > len(customs) {
  4279. // stop = len(customs)
  4280. // }
  4281. //
  4282. // result := service.SzybFY002(doctor_name, doctor_code, miConfig.Code, customs[start-1:stop], verifyCode, order.OrgSetlNumber, his.Number, version_code)
  4283. // fmt.Println(result)
  4284. //
  4285. // var dat map[string]interface{}
  4286. // if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4287. // fmt.Println(dat)
  4288. // } else {
  4289. // fmt.Println(err)
  4290. // }
  4291. // userJSONBytes, _ := json.Marshal(dat)
  4292. // var res ResultFive
  4293. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4294. // utils.ErrorLog("解析失败:%v", err)
  4295. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4296. // return
  4297. // }
  4298. // if res.Transreturncode == "00000000" {
  4299. // ress = append(ress, &res)
  4300. // } else {
  4301. // isSuccess = false
  4302. // //预结算报错
  4303. // errlog := &models.HisOrderError{
  4304. // UserOrgId: adminUser.CurrentOrgId,
  4305. // Ctime: time.Now().Unix(),
  4306. // Mtime: time.Now().Unix(),
  4307. // ErrMsg: res.Transreturnmessage,
  4308. // Status: 1,
  4309. // PatientId: patient_id,
  4310. // RecordTime: recordDateTime,
  4311. // Stage: 11,
  4312. // }
  4313. // service.CreateErrMsgLog(errlog)
  4314. //
  4315. // c.ServeSuccessJSON(map[string]interface{}{
  4316. // "faild_code": -10,
  4317. // "msg": res.Transreturnmessage,
  4318. // })
  4319. // return
  4320. // }
  4321. // }
  4322. // if isSuccess == true {
  4323. // service.UpdataOrderInfoStatus(order.ID, order.Number, adminUser.CurrentOrgId)
  4324. // c.ServeSuccessJSON(map[string]interface{}{
  4325. // "msg": "撤销成功",
  4326. // })
  4327. // }
  4328. //}
  4329. func (c *SZHisApiController) CancelOrderDetail() {
  4330. order_id, _ := c.GetInt64("order_id")
  4331. record_time := c.GetString("record_time")
  4332. patient_id, _ := c.GetInt64("patient_id")
  4333. his_patient_id, _ := c.GetInt64("his_patient_id")
  4334. admin_user_id, _ := c.GetInt64("admin_user_id")
  4335. timeLayout := "2006-01-02"
  4336. loc, _ := time.LoadLocation("Local")
  4337. adminUser := c.GetAdminUserInfo()
  4338. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4339. fmt.Println(err)
  4340. if err != nil {
  4341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4342. return
  4343. }
  4344. recordDateTime := theTime.Unix()
  4345. var order models.HisOrder
  4346. order, _ = service.GetHisOrderByID(order_id)
  4347. if order.ID == 0 {
  4348. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  4349. }
  4350. order_infos, _ := service.GetHisOrderInfoByNumber(order.Number)
  4351. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4352. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4353. //结算流程
  4354. var doctor_name string
  4355. var doctor_code string
  4356. if roles.ID == 0 {
  4357. doctor_name = "管理员"
  4358. doctor_code = "1001"
  4359. } else {
  4360. doctor_name = roles.UserName
  4361. doctor_code = strconv.FormatInt(admin_user_id, 10)
  4362. }
  4363. var customs []*models.CustomDetail
  4364. for _, item := range order_infos {
  4365. cus := &models.CustomDetail{
  4366. PrescriptionNumber: item.OrderNumber,
  4367. ChargeSerialNumber: item.FeedetlSn,
  4368. }
  4369. customs = append(customs, cus)
  4370. }
  4371. his, _ := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  4372. verifyCode, version_code := ReadCardGetCode("FY002" + "|" + order.OrgSetlNumber + "|" + miConfig.Code)
  4373. var pagesize int = 50
  4374. var start int = 1
  4375. var stop int
  4376. var pagecount int
  4377. var curpage int
  4378. var isSuccess bool = true
  4379. var ress []*ResultFive
  4380. //总页数,向上取整,注意除之前要先转换类型为float64
  4381. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  4382. for curpage = 1; curpage <= pagecount; curpage++ {
  4383. if curpage == 1 {
  4384. start = 1
  4385. } else {
  4386. start = (curpage-1)*pagesize + 1
  4387. }
  4388. stop = curpage * pagesize
  4389. if stop > len(customs) {
  4390. stop = len(customs)
  4391. }
  4392. result := service.SzybFY002(doctor_name, doctor_code, miConfig.Code, customs[start-1:stop], verifyCode, order.OrgSetlNumber, his.Number, version_code)
  4393. fmt.Println(result)
  4394. var dat map[string]interface{}
  4395. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4396. fmt.Println(dat)
  4397. } else {
  4398. fmt.Println(err)
  4399. }
  4400. userJSONBytes, _ := json.Marshal(dat)
  4401. var res ResultFive
  4402. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4403. utils.ErrorLog("解析失败:%v", err)
  4404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4405. return
  4406. }
  4407. if res.Transreturncode == "00000000" {
  4408. ress = append(ress, &res)
  4409. } else {
  4410. isSuccess = false
  4411. //预结算报错
  4412. errlog := &models.HisOrderError{
  4413. UserOrgId: adminUser.CurrentOrgId,
  4414. Ctime: time.Now().Unix(),
  4415. Mtime: time.Now().Unix(),
  4416. ErrMsg: res.Transreturnmessage,
  4417. Status: 1,
  4418. PatientId: patient_id,
  4419. RecordTime: recordDateTime,
  4420. Stage: 11,
  4421. }
  4422. service.CreateErrMsgLog(errlog)
  4423. c.ServeSuccessJSON(map[string]interface{}{
  4424. "faild_code": -10,
  4425. "msg": res.Transreturnmessage,
  4426. })
  4427. return
  4428. }
  4429. }
  4430. if isSuccess == true {
  4431. service.UpdataOrderInfoStatus(order.ID, order.Number, adminUser.CurrentOrgId)
  4432. c.ServeSuccessJSON(map[string]interface{}{
  4433. "msg": "撤销成功",
  4434. })
  4435. }
  4436. }
  4437. //获取verifyCode
  4438. func ReadCardGetCode(request string) (string, string) {
  4439. request = request + "|"
  4440. DllDef2 := syscall.MustLoadDLL("SSCardDriver_SZ.dll")
  4441. readCards := DllDef2.MustFindProc("iVerifyCode")
  4442. str := request
  4443. str3 := make([]byte, 256)
  4444. ret4, _, _ := readCards.Call(StrPtr(str), (uintptr)(unsafe.Pointer(&str3[0])))
  4445. fmt.Println(":", string(str3))
  4446. fmt.Println(":", ConvertToString(string(str3), "gbk", "utf-8"))
  4447. if ret4 == 0 {
  4448. result := string(str3)
  4449. fmt.Println(result)
  4450. result_arr := strings.Split(result, "|")
  4451. verifyCode := result_arr[0] + "|" + result_arr[1]
  4452. versionCode := result_arr[2]
  4453. return verifyCode, versionCode
  4454. }
  4455. return "", ""
  4456. }
  4457. ////获取卡信息
  4458. func ReadBasCardGetNumber(request string) (string, string, string, string, string, error, int64) {
  4459. DllDef2 := syscall.MustLoadDLL("SSCardDriver_SZ.dll")
  4460. readCards := DllDef2.MustFindProc("iReadCardBas")
  4461. str := request
  4462. str3 := make([]byte, 1024)
  4463. fmt.Println(":", request)
  4464. fmt.Println(":", StrPtr(str))
  4465. ret4, _, err := readCards.Call(IntPtr(1), StrPtr(str), (uintptr)(unsafe.Pointer(&str3[0])))
  4466. fmt.Println(":", string(str3))
  4467. fmt.Println(":", ConvertToString(string(str3), "gbk", "utf-8"))
  4468. if ret4 == 0 {
  4469. result := string(str3)
  4470. fmt.Println(result)
  4471. result_arr := strings.Split(result, "|")
  4472. //医疗证号
  4473. yiliao_number := result_arr[12]
  4474. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  4475. id_card_number := result_arr[1]
  4476. verifyCode := result_arr[11] + "|" + result_arr[13]
  4477. versionCode := result_arr[14]
  4478. health_card_no := result_arr[2]
  4479. return yiliao_number, id_card_number, verifyCode, versionCode, health_card_no, err, 0
  4480. }
  4481. return "", "", "", "", "", err, -10
  4482. }
  4483. //读卡
  4484. func ReadBasCard(request string) (string, string, error, int64) {
  4485. DllDef2 := syscall.MustLoadDLL("SSCardDriver_SZ.dll")
  4486. readCards := DllDef2.MustFindProc("iReadCardBas")
  4487. str := request
  4488. str3 := make([]byte, 1024)
  4489. ret4, _, err := readCards.Call(IntPtr(1), StrPtr(str), (uintptr)(unsafe.Pointer(&str3[0])))
  4490. fmt.Println(":", string(str3))
  4491. fmt.Println(":", ConvertToString(string(str3), "gbk", "utf-8"))
  4492. if ret4 == 0 {
  4493. result := string(str3)
  4494. result_arr := strings.Split(result, "|")
  4495. //根据业务的人员信息跟设备读社保卡获取的信息进行匹配,判断是否为同一个人,相同则进行挂号操作,不同则报错
  4496. id_card_number := result_arr[1]
  4497. health_card_no := result_arr[2]
  4498. return id_card_number, health_card_no, err, 0
  4499. }
  4500. return "", "", err, -10
  4501. }
  4502. //
  4503. ////iReadCardBas_HSM_Step1 ---- 1903 iCardInnerAuthentication --- iReadCardBas_HSM_Step2
  4504. //func ReadCardBasHSM(number string) string {
  4505. // DllDef2 := syscall.MustLoadDLL("SSSE32.dll")
  4506. // readCards := DllDef2.MustFindProc("iReadCardBas_HSM_Step1")
  4507. // str := make([]byte, 256)
  4508. // ret, _, _ := readCards.Call(IntPtr(3), (uintptr)(unsafe.Pointer(&str[0])))
  4509. // fmt.Println(":", string(str))
  4510. //
  4511. // result_arr := strings.Split(string(str), "|")
  4512. //
  4513. // if ret == 0 {
  4514. // readCards := DllDef2.MustFindProc("iCardInnerAuthentication")
  4515. // str2 := make([]byte, 256)
  4516. // str3 := "" + "|" + "" + "|" + "440300" + "|" + "" + "|" + "" + "|" + result_arr[1] + "|" + result_arr[2] + "|" + result_arr[3] + "|" + result_arr[4] + "|" + result_arr[5] + "|" + "" + "|" + "" + "|"
  4517. // ret2, _, _ := readCards.Call(StrPtr(str3), (uintptr)(unsafe.Pointer(&str2[0])))
  4518. // fmt.Println(":", string(str2))
  4519. //
  4520. // if ret2 == 0 {
  4521. // result_arr := strings.Split(string(str2), "|")
  4522. //
  4523. // if result_arr[2] == "0" {
  4524. // readCards := DllDef2.MustFindProc("iReadCardBas_HSM_Step2")
  4525. // str4 := result_arr[4] + "|" + result_arr[5]
  4526. // str5 := make([]byte, 256)
  4527. // ret3, _, _ := readCards.Call(StrPtr(str4), StrPtr(number), (uintptr)(unsafe.Pointer(&str5[0])))
  4528. //
  4529. // if ret3 == 0 {
  4530. // return string(str5)
  4531. //
  4532. // } else {
  4533. // return ""
  4534. // }
  4535. // } else {
  4536. // return ""
  4537. // }
  4538. // }
  4539. // return ""
  4540. // }
  4541. // return ""
  4542. //
  4543. //}
  4544. //
  4545. ////1904卡鉴权
  4546. //func CardAuth(request string) string {
  4547. // DllDef2 := syscall.MustLoadDLL("SSSE32.dll")
  4548. // readCards := DllDef2.MustFindProc("iCardAuthentication")
  4549. // str := request
  4550. // str3 := make([]byte, 256)
  4551. // ret4, _, _ := readCards.Call(StrPtr(str), (uintptr)(unsafe.Pointer(&str3[0])))
  4552. // fmt.Println(":", string(str3))
  4553. //
  4554. // if ret4 == 0 {
  4555. // return string(str3)
  4556. // }
  4557. // return ""
  4558. //}
  4559. func (c *SZHisApiController) GetDrugList() {
  4560. adminUserInfo := c.GetAdminUserInfo()
  4561. orgId := adminUserInfo.CurrentOrgId
  4562. admin_user_id, _ := c.GetInt64("admin_user_id")
  4563. roles, _ := service.GetAdminUserInfoByID(orgId, admin_user_id)
  4564. ids := c.GetString("ids")
  4565. stringarr := strings.Split(ids, ",")
  4566. idss := make([]int64, 0)
  4567. for _, item := range stringarr {
  4568. itemsss, _ := strconv.ParseInt(item, 10, 64)
  4569. id := int64(itemsss)
  4570. idss = append(idss, id)
  4571. }
  4572. //批量获取
  4573. list, _ := service.GetBatchDrugList(idss)
  4574. //获取药品剂型
  4575. drugs, _ := service.GetDrugDosageForm(orgId)
  4576. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4577. var doctor_name string
  4578. var doctor_code string
  4579. doctor_name = roles.UserName
  4580. doctor_code = "1001"
  4581. var isSuccess bool = true
  4582. timeLayout := "20060102"
  4583. //这里就可以查看开始和结束了
  4584. for _, item := range list {
  4585. recordDate := time.Unix(item.RecordDate, 0).Format(timeLayout)
  4586. detail := &models.DrugDetail{
  4587. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  4588. Code: item.Code,
  4589. DrugName: item.DrugName,
  4590. DrugSpec: item.DrugSpec,
  4591. DrugDosageName: item.DrugDosageName,
  4592. ManufacturerName: item.ManufacturerName,
  4593. MinUnit: item.MinUnit,
  4594. RetailPrice: item.RetailPrice,
  4595. LastPrice: item.LastPrice,
  4596. LimitRemark: item.LimitRemark,
  4597. PrescriptionMark: strconv.FormatInt(item.PrescriptionMark, 10),
  4598. RecordDate: recordDate,
  4599. }
  4600. for _, it := range drugs {
  4601. if item.DrugDosageForm == it.Value {
  4602. detail.DrugDosageName = it.Code
  4603. }
  4604. }
  4605. result := service.SzybML008(doctor_name, doctor_code, miConfig.Code, detail)
  4606. var dat map[string]interface{}
  4607. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4608. //fmt.Println(dat)
  4609. } else {
  4610. //fmt.Println(err)
  4611. }
  4612. userJSONBytes, _ := json.Marshal(dat)
  4613. var res Result
  4614. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4615. utils.ErrorLog("解析失败:%v", err)
  4616. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4617. c.ServeSuccessJSON(map[string]interface{}{
  4618. "failed_code": -10,
  4619. "msg": res.Transreturnmessage,
  4620. })
  4621. return
  4622. }
  4623. if res.Transreturncode == "00000000" {
  4624. //更新备案状态
  4625. _, err := service.UpdateBaseDrugById(item.ID)
  4626. fmt.Println("err", err)
  4627. c.ServeSuccessJSON(map[string]interface{}{
  4628. "failed_code": -10,
  4629. "msg": res.Transreturnmessage,
  4630. })
  4631. return
  4632. }
  4633. fmt.Println(isSuccess)
  4634. c.ServeSuccessJSON(map[string]interface{}{
  4635. "failed_code": -10,
  4636. "msg": res.Transreturnmessage,
  4637. })
  4638. return
  4639. }
  4640. }
  4641. func (c *SZHisApiController) GetTreatmentProject() {
  4642. adminUserInfo := c.GetAdminUserInfo()
  4643. orgId := adminUserInfo.CurrentOrgId
  4644. ids := c.GetString("ids")
  4645. stringarr := strings.Split(ids, ",")
  4646. idss := make([]int64, 0)
  4647. admin_user_id, _ := c.GetInt64("admin_user_id")
  4648. roles, _ := service.GetAdminUserInfoByID(orgId, admin_user_id)
  4649. for _, item := range stringarr {
  4650. itemsss, _ := strconv.ParseInt(item, 10, 64)
  4651. id := int64(itemsss)
  4652. idss = append(idss, id)
  4653. }
  4654. //获取项目库数据
  4655. list, _ := service.GetBathchMyPorjecgList(idss)
  4656. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4657. var doctor_name string
  4658. var doctor_code string
  4659. doctor_name = roles.UserName
  4660. doctor_code = "1001"
  4661. var isSuccess bool = true
  4662. for _, item := range list {
  4663. detail := &models.MyHisProject{
  4664. MedicalCode: item.MedicalCode, //社保目录
  4665. ProjectName: item.ProjectName,
  4666. Price: item.Price,
  4667. Category: item.Category,
  4668. Remark: item.Remark,
  4669. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  4670. SpecailProject: item.SpecailProject,
  4671. RecordDate: item.RecordDate,
  4672. }
  4673. result := service.SzybML009(doctor_name, doctor_code, miConfig.Code, detail)
  4674. var dat map[string]interface{}
  4675. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4676. fmt.Println(dat)
  4677. } else {
  4678. fmt.Println(err)
  4679. }
  4680. userJSONBytes, _ := json.Marshal(dat)
  4681. var res Result
  4682. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4683. utils.ErrorLog("解析失败:%v", err)
  4684. c.ServeSuccessJSON(map[string]interface{}{
  4685. "failed_code": -10,
  4686. "msg": res.Transreturnmessage,
  4687. })
  4688. return
  4689. }
  4690. if res.Transreturncode == "00000000" {
  4691. //备案成功返回状态值
  4692. _, err := service.UpdateProjectById(item.ID)
  4693. fmt.Println("err", err)
  4694. } else {
  4695. isSuccess = false
  4696. //失败
  4697. c.ServeSuccessJSON(map[string]interface{}{
  4698. "failed_code": -10,
  4699. "msg": res.Transreturnmessage,
  4700. })
  4701. return
  4702. }
  4703. fmt.Println(isSuccess)
  4704. c.ServeSuccessJSON(map[string]interface{}{
  4705. "failed_code": -10,
  4706. "msg": res.Transreturnmessage,
  4707. })
  4708. return
  4709. }
  4710. }
  4711. func (c *SZHisApiController) GetRevocation() {
  4712. adminUserInfo := c.GetAdminUserInfo()
  4713. orgId := adminUserInfo.CurrentOrgId
  4714. id, _ := c.GetInt64("id")
  4715. admin_user_id, _ := c.GetInt64("admin_user_id")
  4716. roles, _ := service.GetAdminUserInfoByID(orgId, admin_user_id)
  4717. //用来区分是药品的撤销还是耗材的撤销 1.药品 2.诊疗项目 3.材料 5.辅助器具项目
  4718. is_mark, _ := c.GetInt64("is_mark")
  4719. type_id, _ := c.GetInt64("type_id")
  4720. if type_id == 1 {
  4721. //撤销
  4722. if is_mark == 1 {
  4723. //获取药品库数据
  4724. list, _ := service.GetDrugListByDetail(orgId, id)
  4725. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4726. var doctor_name string
  4727. var doctor_code string
  4728. doctor_name = roles.UserName
  4729. doctor_code = "1001"
  4730. var pagesize int = 50
  4731. var start int = 1
  4732. var stop int
  4733. var pagecount int
  4734. var curpage int
  4735. var isSuccess bool = true
  4736. //总页数,向上取整,注意除之前要先转换类型为float64
  4737. pagecount = int(math.Ceil(float64(len(list)) / float64(pagesize)))
  4738. for curpage = 1; curpage <= pagecount; curpage++ {
  4739. if curpage == 1 {
  4740. start = 1
  4741. } else {
  4742. start = (curpage-1)*pagesize + 1
  4743. }
  4744. stop = curpage * pagesize
  4745. if stop > len(list) {
  4746. stop = len(list)
  4747. }
  4748. //这里就可以查看开始和结束了
  4749. fmt.Println(list[start-1 : stop])
  4750. var customs []*models.DrugDetail
  4751. for _, item := range list {
  4752. detail := &models.DrugDetail{
  4753. SocialSecurityDirectoryCode: item.MedicalInsuranceNumber, //社保目录
  4754. Code: item.Code, //协议机构内部目录编码
  4755. DrugName: item.DrugName, //协议机构内部目录名称
  4756. DrugSpec: item.DrugSpec,
  4757. ManufacturerName: item.ManufacturerName,
  4758. MinUnit: item.MinUnit,
  4759. RetailPrice: item.RetailPrice, //协议机构内部项目收费价格
  4760. LimitRemark: item.LimitRemark,
  4761. MedicalInsuranceNumber: item.MedicalInsuranceNumber, //社保目录
  4762. }
  4763. customs = append(customs, detail)
  4764. }
  4765. result := service.SzybML010(doctor_name, doctor_code, miConfig.Code, customs, type_id)
  4766. fmt.Println("reuslt", result)
  4767. var dat map[string]interface{}
  4768. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4769. fmt.Println(dat)
  4770. } else {
  4771. fmt.Println(err)
  4772. }
  4773. userJSONBytes, _ := json.Marshal(dat)
  4774. var res Result
  4775. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4776. utils.ErrorLog("解析失败:%v", err)
  4777. c.ServeSuccessJSON(map[string]interface{}{
  4778. "failed_code": -10,
  4779. "msg": res.Transreturnmessage,
  4780. })
  4781. return
  4782. }
  4783. if res.Transreturncode == "00000000" {
  4784. //撤销成功
  4785. _, err := service.UpdateDrugByIdDetail(id)
  4786. fmt.Println("err", err)
  4787. } else {
  4788. isSuccess = false
  4789. //失败
  4790. c.ServeSuccessJSON(map[string]interface{}{
  4791. "failed_code": -10,
  4792. "msg": res.Transreturnmessage,
  4793. })
  4794. return
  4795. }
  4796. fmt.Println(isSuccess)
  4797. c.ServeSuccessJSON(map[string]interface{}{
  4798. "failed_code": -10,
  4799. "msg": res.Transreturnmessage,
  4800. })
  4801. return
  4802. }
  4803. }
  4804. // 备案
  4805. if is_mark == 0 {
  4806. adminUserInfo := c.GetAdminUserInfo()
  4807. orgId := adminUserInfo.CurrentOrgId
  4808. //获取药品库数据
  4809. list, _ := service.GetDrugListByDetail(orgId, id)
  4810. //获取药品剂型
  4811. drugs, _ := service.GetDrugDosageForm(orgId)
  4812. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4813. var doctor_name string
  4814. var doctor_code string
  4815. doctor_name = roles.UserName
  4816. doctor_code = "1001"
  4817. var isSuccess bool = true
  4818. //这里就可以查看开始和结束了
  4819. for _, item := range list {
  4820. detail := &models.DrugDetail{
  4821. MedicalInsuranceNumber: item.MedicalInsuranceNumber,
  4822. SocialSecurityDirectoryCode: item.MedicalInsuranceNumber,
  4823. Code: item.Code,
  4824. DrugName: item.DrugName,
  4825. DrugSpec: item.DrugSpec,
  4826. DrugDosageName: item.DrugDosageName,
  4827. ManufacturerName: item.ManufacturerName,
  4828. MinUnit: item.MinUnit,
  4829. RetailPrice: item.RetailPrice,
  4830. LastPrice: item.LastPrice,
  4831. LimitRemark: item.LimitRemark,
  4832. }
  4833. for _, it := range drugs {
  4834. if item.DrugDosageForm == it.Value {
  4835. detail.DrugDosageName = it.Code
  4836. }
  4837. }
  4838. result := service.SzybML008(doctor_name, doctor_code, miConfig.Code, detail)
  4839. var dat map[string]interface{}
  4840. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4841. //fmt.Println(dat)
  4842. } else {
  4843. //fmt.Println(err)
  4844. }
  4845. userJSONBytes, _ := json.Marshal(dat)
  4846. var res Result
  4847. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4848. utils.ErrorLog("解析失败:%v", err)
  4849. c.ServeSuccessJSON(map[string]interface{}{
  4850. "failed_code": -10,
  4851. "msg": res.Transreturnmessage,
  4852. })
  4853. return
  4854. }
  4855. if res.Transreturncode == "00000000" {
  4856. //更新备案状态
  4857. _, err := service.UpdateBaseDrugById(item.ID)
  4858. fmt.Println("err", err)
  4859. }
  4860. fmt.Println(isSuccess)
  4861. c.ServeSuccessJSON(map[string]interface{}{
  4862. "failed_code": -10,
  4863. "msg": res.Transreturnmessage,
  4864. })
  4865. return
  4866. }
  4867. }
  4868. }
  4869. if type_id == 2 {
  4870. //撤销
  4871. if is_mark == 1 {
  4872. //获取药品库数据
  4873. list, _ := service.GetMyPorjecgListDetail(orgId, id)
  4874. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4875. var doctor_name string
  4876. var doctor_code string
  4877. doctor_name = roles.UserName
  4878. doctor_code = "1001"
  4879. var pagesize int = 50
  4880. var start int = 1
  4881. var stop int
  4882. var pagecount int
  4883. var curpage int
  4884. var isSuccess bool = true
  4885. //总页数,向上取整,注意除之前要先转换类型为float64
  4886. pagecount = int(math.Ceil(float64(len(list)) / float64(pagesize)))
  4887. for curpage = 1; curpage <= pagecount; curpage++ {
  4888. if curpage == 1 {
  4889. start = 1
  4890. } else {
  4891. start = (curpage-1)*pagesize + 1
  4892. }
  4893. stop = curpage * pagesize
  4894. if stop > len(list) {
  4895. stop = len(list)
  4896. }
  4897. //这里就可以查看开始和结束了
  4898. fmt.Println(list[start-1 : stop])
  4899. var customs []*models.DrugDetail
  4900. for _, item := range list {
  4901. detail := &models.DrugDetail{
  4902. SocialSecurityDirectoryCode: item.MedicalCode,
  4903. }
  4904. customs = append(customs, detail)
  4905. }
  4906. result := service.SzybML010(doctor_name, doctor_code, miConfig.Code, customs, type_id)
  4907. fmt.Println("reuslt", result)
  4908. var dat map[string]interface{}
  4909. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4910. fmt.Println(dat)
  4911. } else {
  4912. fmt.Println(err)
  4913. }
  4914. userJSONBytes, _ := json.Marshal(dat)
  4915. var res Result
  4916. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4917. utils.ErrorLog("解析失败:%v", err)
  4918. c.ServeSuccessJSON(map[string]interface{}{
  4919. "failed_code": -10,
  4920. "msg": res.Transreturnmessage,
  4921. })
  4922. return
  4923. }
  4924. if res.Transreturncode == "00000000" {
  4925. //核销成功返回状态码
  4926. _, err := service.UpdateMyProjectById(id)
  4927. fmt.Println("err", err)
  4928. } else {
  4929. isSuccess = false
  4930. //失败
  4931. c.ServeSuccessJSON(map[string]interface{}{
  4932. "failed_code": -10,
  4933. "msg": res.Transreturnmessage,
  4934. })
  4935. return
  4936. }
  4937. fmt.Println(isSuccess)
  4938. c.ServeSuccessJSON(map[string]interface{}{
  4939. "failed_code": -10,
  4940. "msg": res.Transreturnmessage,
  4941. })
  4942. return
  4943. }
  4944. }
  4945. //备案
  4946. if is_mark == 0 {
  4947. adminUserInfo := c.GetAdminUserInfo()
  4948. orgId := adminUserInfo.CurrentOrgId
  4949. //获取药品库数据
  4950. list, _ := service.GetMyPorjecgListDetail(orgId, id)
  4951. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  4952. var doctor_name string
  4953. var doctor_code string
  4954. doctor_name = roles.UserName
  4955. doctor_code = "1001"
  4956. var isSuccess bool = true
  4957. for _, item := range list {
  4958. detail := &models.MyHisProject{
  4959. MedicalCode: item.MedicalCode, //社保目录
  4960. ProjectName: item.ProjectName,
  4961. Price: item.Price,
  4962. Category: item.Category,
  4963. Remark: item.Remark,
  4964. }
  4965. result := service.SzybML009(doctor_name, doctor_code, miConfig.Code, detail)
  4966. fmt.Println("reuslt", result)
  4967. var dat map[string]interface{}
  4968. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4969. fmt.Println(dat)
  4970. } else {
  4971. fmt.Println(err)
  4972. }
  4973. userJSONBytes, _ := json.Marshal(dat)
  4974. var res Result
  4975. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4976. utils.ErrorLog("解析失败:%v", err)
  4977. c.ServeSuccessJSON(map[string]interface{}{
  4978. "failed_code": -10,
  4979. "msg": res.Transreturnmessage,
  4980. })
  4981. return
  4982. }
  4983. if res.Transreturncode == "00000000" {
  4984. //备案成功返回状态值
  4985. _, err := service.UpdateProjectById(item.ID)
  4986. fmt.Println("err", err)
  4987. } else {
  4988. isSuccess = false
  4989. //失败
  4990. c.ServeSuccessJSON(map[string]interface{}{
  4991. "failed_code": -10,
  4992. "msg": res.Transreturnmessage,
  4993. })
  4994. return
  4995. }
  4996. fmt.Println(isSuccess)
  4997. c.ServeSuccessJSON(map[string]interface{}{
  4998. "failed_code": -10,
  4999. "msg": res.Transreturnmessage,
  5000. })
  5001. return
  5002. }
  5003. }
  5004. }
  5005. if type_id == 3 {
  5006. //撤销
  5007. if is_mark == 1 {
  5008. //获取药品库数据
  5009. list, _ := service.GetGoodListByDetail(orgId, id)
  5010. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  5011. var doctor_name string
  5012. var doctor_code string
  5013. doctor_name = roles.UserName
  5014. doctor_code = "1001"
  5015. var pagesize int = 50
  5016. var start int = 1
  5017. var stop int
  5018. var pagecount int
  5019. var curpage int
  5020. var isSuccess bool = true
  5021. //总页数,向上取整,注意除之前要先转换类型为float64
  5022. pagecount = int(math.Ceil(float64(len(list)) / float64(pagesize)))
  5023. for curpage = 1; curpage <= pagecount; curpage++ {
  5024. if curpage == 1 {
  5025. start = 1
  5026. } else {
  5027. start = (curpage-1)*pagesize + 1
  5028. }
  5029. stop = curpage * pagesize
  5030. if stop > len(list) {
  5031. stop = len(list)
  5032. }
  5033. //这里就可以查看开始和结束了
  5034. fmt.Println(list[start-1 : stop])
  5035. var customs []*models.DrugDetail
  5036. for _, item := range list {
  5037. fmt.Println("医疗机构编码", item.SocialSecurityDirectoryCode)
  5038. detail := &models.DrugDetail{
  5039. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  5040. ManufacturerName: item.ManufacturerName,
  5041. }
  5042. customs = append(customs, detail)
  5043. }
  5044. result := service.SzybML010(doctor_name, doctor_code, miConfig.Code, customs, type_id)
  5045. fmt.Println("reuslt", result)
  5046. var dat map[string]interface{}
  5047. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5048. fmt.Println(dat)
  5049. } else {
  5050. fmt.Println(err)
  5051. }
  5052. userJSONBytes, _ := json.Marshal(dat)
  5053. var res Result
  5054. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5055. utils.ErrorLog("解析失败:%v", err)
  5056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5057. return
  5058. }
  5059. if res.Transreturncode == "00000000" {
  5060. //撤销成功后改变状态
  5061. _, err := service.UpdateGoodInfoById(id)
  5062. fmt.Println("err", err)
  5063. } else {
  5064. isSuccess = false
  5065. //失败
  5066. c.ServeSuccessJSON(map[string]interface{}{
  5067. "failed_code": -10,
  5068. "msg": res.Transreturnmessage,
  5069. })
  5070. return
  5071. }
  5072. fmt.Println(isSuccess)
  5073. c.ServeSuccessJSON(map[string]interface{}{
  5074. "failed_code": -10,
  5075. "msg": res.Transreturnmessage,
  5076. })
  5077. return
  5078. }
  5079. }
  5080. //备案
  5081. if is_mark == 0 {
  5082. adminUserInfo := c.GetAdminUserInfo()
  5083. orgId := adminUserInfo.CurrentOrgId
  5084. //获取所有耗材信息
  5085. list, _ := service.GetGoodListByDetail(orgId, id)
  5086. //获取单位
  5087. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  5088. var doctor_name string
  5089. var doctor_code string
  5090. doctor_name = roles.UserName
  5091. doctor_code = "1001"
  5092. var isSuccess bool = true
  5093. for _, item := range list {
  5094. detail := &models.XtGoodInformation{
  5095. GoodName: item.GoodName,
  5096. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  5097. ManufacturerName: item.ManufacturerName,
  5098. ProductionType: item.ProductionType,
  5099. SpecialMedical: item.SpecialMedical,
  5100. BuyPrice: item.BuyPrice,
  5101. SellPrice: item.SellPrice,
  5102. Remark: item.Remark,
  5103. SpecificationName: item.SpecificationName,
  5104. }
  5105. result := service.SzybYML007(doctor_name, doctor_code, miConfig.Code, detail)
  5106. fmt.Println("reuslt", result)
  5107. var dat map[string]interface{}
  5108. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5109. fmt.Println(dat)
  5110. } else {
  5111. fmt.Println(err)
  5112. }
  5113. userJSONBytes, _ := json.Marshal(dat)
  5114. var res Result
  5115. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5116. utils.ErrorLog("解析失败:%v", err)
  5117. c.ServeSuccessJSON(map[string]interface{}{
  5118. "failed_code": -10,
  5119. "msg": res.Transreturnmessage,
  5120. })
  5121. return
  5122. }
  5123. if res.Transreturncode == "00000000" {
  5124. //备案成功返回状态
  5125. _, err := service.UpdateGoodInformaitonByDetail(item.ID)
  5126. fmt.Println("err", err)
  5127. } else {
  5128. isSuccess = false
  5129. //失败
  5130. c.ServeSuccessJSON(map[string]interface{}{
  5131. "failed_code": -10,
  5132. "msg": res.Transreturnmessage,
  5133. })
  5134. return
  5135. }
  5136. fmt.Println(isSuccess)
  5137. c.ServeSuccessJSON(map[string]interface{}{
  5138. "failed_code": -10,
  5139. "msg": res.Transreturnmessage,
  5140. })
  5141. return
  5142. }
  5143. }
  5144. }
  5145. }
  5146. func (c *SZHisApiController) GetDoctorList() {
  5147. adminUserInfo := c.GetAdminUserInfo()
  5148. orgid := adminUserInfo.CurrentOrgId
  5149. ids := c.GetString("ids")
  5150. admin_user_id, _ := c.GetInt64("admin_user_id")
  5151. roles, _ := service.GetAdminUserInfoByID(orgid, admin_user_id)
  5152. stringarr := strings.Split(ids, ",")
  5153. idss := make([]int64, 0)
  5154. for _, item := range stringarr {
  5155. itemsss, _ := strconv.ParseInt(item, 10, 64)
  5156. id := int64(itemsss)
  5157. idss = append(idss, id)
  5158. }
  5159. //获取所有医生护士信息
  5160. //list, _ := service.GetDoctorList(orgid)
  5161. //批量查询
  5162. list, _ := service.GetBatchDoctorList(idss)
  5163. //获取所有角色名称
  5164. roleList, _ := service.GetRoleList(orgid)
  5165. miConfig, _ := service.FindMedicalInsuranceInfo(orgid)
  5166. for _, item := range list {
  5167. for _, it := range roleList {
  5168. if item.RoleId == it.ID {
  5169. item.Name = it.RoleName
  5170. }
  5171. }
  5172. }
  5173. var doctor_name string
  5174. var doctor_code string
  5175. doctor_name = roles.UserName
  5176. doctor_code = "1001"
  5177. var isSuccess bool = true
  5178. for _, item := range list {
  5179. depart, _ := service.GetDepartMentDetail(item.DepartmentId)
  5180. detail := &models.DocDetail{
  5181. UserName: item.UserName, //医护姓名
  5182. RoleId: item.Name, //医护人员类别
  5183. Sex: strconv.FormatInt(item.Sex, 10), //性别
  5184. CardType: strconv.FormatInt(item.CardType, 10), //证件类型
  5185. IdCard: item.IdCard, //证件号码
  5186. Phone: item.Mobile, //联系电话
  5187. WorkMajorName: item.WorkMajorName, // 现从事专业名称
  5188. Nation: "1", //民族
  5189. BirthDay: 20201022, // 出生日期
  5190. WorkTime: 20201022, //参加工作日期
  5191. Education: strconv.FormatInt(item.Education, 10), //学历
  5192. StudyMajorName: item.StudyMajorName, //所学的专业名称
  5193. CertificateCode: item.MedicalCode, //医(药)师执业证书编码
  5194. MedicalCode: item.DoctorCode, //医(药)师资格证编码
  5195. MedicalRangeCode: strconv.FormatInt(item.DoctorRangeCode, 10), //医师执业范围代码
  5196. MedicalLevel: strconv.FormatInt(item.DoctorLevel, 10), //医生执业资格证中的医师级别
  5197. TypeJob: strconv.FormatInt(item.DoctorTypeJob, 10), //医生执业资格证中的执业类别
  5198. DoctorNumber: item.DoctorNumber, //医保医师编号
  5199. Licensing: strconv.FormatInt(item.Licensing, 10), //多点执业标志
  5200. DoctorServiceStatus: "", //医师医保服务资格状态
  5201. MonitoringLevel: "", //监控等级
  5202. DrugPsychotropicSubstances: "", //毒麻精神药品资格
  5203. HealthCareCode: "", // 母婴保健技术考核合格证书编号
  5204. PlanningTechnicalServiceCode: "", //计划生育技术服务人员合格证编号
  5205. PharmacistType: "", //药师类别
  5206. PharmacistPracticeCategory: "", //药师执业类别
  5207. PharmacistsLicensing: "", //药师执业范围
  5208. PharmacistRegistrationNumber: "", //执业药师注册证编号
  5209. OfficeCode: depart.Number, //科室编码
  5210. JobNumber: item.JobNumber, //工号
  5211. PostName: "", //职位名称
  5212. TechnicalJobLevelCode: "", //专业技术职务级别编码
  5213. IsActive: strconv.FormatInt(item.IsActive, 10), //在职与否
  5214. PrescriptionQualificationIdentification: strconv.FormatInt(item.PrescriptionQualificationIdentification, 10), //处方资格标识
  5215. IdentificationOutpatients: strconv.FormatInt(item.IdentificationOutpatients, 10), //门诊大病医师标识
  5216. OutpatientIllnessCategory: item.OutpatientIllnessCategory, //门诊大病类别
  5217. StartTime: 20201010, //开始日期
  5218. StaffCode: "", //医护人员编码
  5219. EndTime: 0, // 结束日期
  5220. }
  5221. result := service.SzybYS001(doctor_name, doctor_code, miConfig.Code, detail)
  5222. fmt.Println("reuslt", result)
  5223. var dat map[string]interface{}
  5224. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5225. fmt.Println(dat)
  5226. } else {
  5227. fmt.Println(err)
  5228. }
  5229. userJSONBytes, _ := json.Marshal(dat)
  5230. var res Result
  5231. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5232. utils.ErrorLog("解析失败:%v", err)
  5233. c.ServeSuccessJSON(map[string]interface{}{
  5234. "failed_code": -10,
  5235. "msg": res.Transreturnmessage,
  5236. })
  5237. return
  5238. }
  5239. if res.Transreturncode == "00000000" {
  5240. //批量插入数据
  5241. _, err := service.UpdateAdminUserRoleById(item.AdminUserId, orgid)
  5242. fmt.Println("err", err)
  5243. } else {
  5244. isSuccess = false
  5245. //失败
  5246. c.ServeSuccessJSON(map[string]interface{}{
  5247. "failed_code": -10,
  5248. "msg": res.Transreturnmessage,
  5249. })
  5250. return
  5251. }
  5252. fmt.Println(isSuccess)
  5253. c.ServeSuccessJSON(map[string]interface{}{
  5254. "failed_code": -10,
  5255. "msg": res.Transreturnmessage,
  5256. })
  5257. return
  5258. }
  5259. }
  5260. func (c *SZHisApiController) GetMedicalList() {
  5261. adminUserInfo := c.GetAdminUserInfo()
  5262. orgId := adminUserInfo.CurrentOrgId
  5263. id, _ := c.GetInt64("id")
  5264. is_mark, _ := c.GetInt64("is_mark")
  5265. admin_user_id, _ := c.GetInt64("admin_user_id")
  5266. roles, _ := service.GetAdminUserInfoByID(orgId, admin_user_id)
  5267. //去登记
  5268. if is_mark == 0 {
  5269. list, _ := service.GetDoctorListByDetail(orgId, id)
  5270. //获取所有角色名称
  5271. roleList, _ := service.GetRoleList(orgId)
  5272. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  5273. for _, item := range list {
  5274. for _, it := range roleList {
  5275. if item.RoleId == it.ID {
  5276. item.Name = it.RoleName
  5277. }
  5278. }
  5279. }
  5280. var doctor_name string
  5281. var doctor_code string
  5282. doctor_name = roles.UserName
  5283. doctor_code = "1001"
  5284. var isSuccess bool = true
  5285. for _, item := range list {
  5286. detail := &models.DocDetail{
  5287. UserName: item.UserName, //医护姓名
  5288. RoleId: item.Name, //医护人员类别
  5289. Sex: strconv.FormatInt(item.Sex, 10), //性别
  5290. CardType: strconv.FormatInt(item.CardType, 10), //证件类型
  5291. IdCard: item.IdCard, //证件号码
  5292. Phone: item.Mobile, //联系电话
  5293. WorkMajorName: item.WorkMajorName, // 现从事专业名称
  5294. Nation: item.Nation, //民族
  5295. BirthDay: 20201022, // 出生日期
  5296. WorkTime: 20201022, //参加工作日期
  5297. Education: strconv.FormatInt(item.Education, 10), //学历
  5298. StudyMajorName: item.StudyMajorName, //所学的专业名称
  5299. CertificateCode: item.MedicalCode, //医(药)师执业证书编码
  5300. MedicalCode: item.DoctorCode, //医(药)师资格证编码
  5301. MedicalRangeCode: strconv.FormatInt(item.DoctorRangeCode, 10), //医师执业范围代码
  5302. MedicalLevel: strconv.FormatInt(item.DoctorLevel, 10), //医生执业资格证中的医师级别
  5303. TypeJob: strconv.FormatInt(item.DoctorTypeJob, 10), //医生执业资格证中的执业类别
  5304. DoctorNumber: item.DoctorNumber, //医保医师编号
  5305. Licensing: strconv.FormatInt(item.Licensing, 10), //多点执业标志
  5306. DoctorServiceStatus: "", //医师医保服务资格状态
  5307. MonitoringLevel: "", //监控等级
  5308. DrugPsychotropicSubstances: "", //毒麻精神药品资格
  5309. HealthCareCode: "", // 母婴保健技术考核合格证书编号
  5310. PlanningTechnicalServiceCode: "", //计划生育技术服务人员合格证编号
  5311. PharmacistType: "", //药师类别
  5312. PharmacistPracticeCategory: "", //药师执业类别
  5313. PharmacistsLicensing: "", //药师执业范围
  5314. PharmacistRegistrationNumber: "", //执业药师注册证编号
  5315. OfficeCode: "", //科室编码
  5316. JobNumber: item.JobNumber, //工号
  5317. PostName: "", //职位名称
  5318. TechnicalJobLevelCode: "", //专业技术职务级别编码
  5319. IsActive: strconv.FormatInt(item.IsActive, 10), //在职与否
  5320. PrescriptionQualificationIdentification: strconv.FormatInt(item.PrescriptionQualificationIdentification, 10), //处方资格标识
  5321. IdentificationOutpatients: strconv.FormatInt(item.IdentificationOutpatients, 10), //门诊大病医师标识
  5322. OutpatientIllnessCategory: item.OutpatientIllnessCategory, //门诊大病类别
  5323. StartTime: 20201010, //开始日期
  5324. StaffCode: "", //医护人员编码
  5325. EndTime: 0, // 结束日期
  5326. }
  5327. result := service.SzybYS001(doctor_name, doctor_code, miConfig.Code, detail)
  5328. var dat map[string]interface{}
  5329. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5330. fmt.Println(dat)
  5331. } else {
  5332. fmt.Println(err)
  5333. }
  5334. userJSONBytes, _ := json.Marshal(dat)
  5335. var res Result
  5336. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5337. utils.ErrorLog("解析失败:%v", err)
  5338. c.ServeSuccessJSON(map[string]interface{}{
  5339. "failed_code": -10,
  5340. "msg": res.Transreturnmessage,
  5341. })
  5342. return
  5343. }
  5344. if res.Transreturncode == "00000000" {
  5345. //登记成功
  5346. service.UpdateAdminUserRoleById(item.ID, orgId)
  5347. } else {
  5348. isSuccess = false
  5349. //失败
  5350. c.ServeSuccessJSON(map[string]interface{}{
  5351. "failed_code": -10,
  5352. "msg": res.Transreturnmessage,
  5353. })
  5354. return
  5355. }
  5356. fmt.Println(isSuccess)
  5357. c.ServeSuccessJSON(map[string]interface{}{
  5358. "failed_code": -10,
  5359. "msg": res.Transreturnmessage,
  5360. })
  5361. return
  5362. }
  5363. }
  5364. //去撤销
  5365. if is_mark == 1 {
  5366. //获取所有医生护士信息
  5367. list, _ := service.GetDoctorListByDetail(orgId, id)
  5368. //获取所有角色名称
  5369. roleList, _ := service.GetRoleList(orgId)
  5370. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  5371. for _, item := range list {
  5372. for _, it := range roleList {
  5373. if item.RoleId == it.ID {
  5374. item.Name = it.RoleName
  5375. }
  5376. }
  5377. }
  5378. var doctor_name string
  5379. var doctor_code string
  5380. doctor_name = "黄亦轩"
  5381. doctor_code = "1001"
  5382. var isSuccess bool = true
  5383. for _, item := range list {
  5384. detail := &models.DocDetail{
  5385. UserName: item.UserName, //医护姓名
  5386. RoleId: item.Name, //医护人员类别
  5387. Sex: strconv.FormatInt(item.Sex, 10), //性别
  5388. CardType: strconv.FormatInt(item.CardType, 10), //证件类型
  5389. IdCard: item.IdCard, //证件号码
  5390. Phone: item.Mobile, //联系电话
  5391. WorkMajorName: item.WorkMajorName, // 现从事专业名称
  5392. Nation: item.Nation, //民族
  5393. BirthDay: 20201022, // 出生日期
  5394. WorkTime: 20201022, //参加工作日期
  5395. Education: strconv.FormatInt(item.Education, 10), //学历
  5396. StudyMajorName: item.StudyMajorName, //所学的专业名称
  5397. CertificateCode: item.MedicalCode, //医(药)师执业证书编码
  5398. MedicalCode: item.DoctorCode, //医(药)师资格证编码
  5399. MedicalRangeCode: strconv.FormatInt(item.DoctorRangeCode, 10), //医师执业范围代码
  5400. MedicalLevel: strconv.FormatInt(item.DoctorLevel, 10), //医生执业资格证中的医师级别
  5401. TypeJob: strconv.FormatInt(item.DoctorTypeJob, 10), //医生执业资格证中的执业类别
  5402. DoctorNumber: item.DoctorNumber, //医保医师编号
  5403. Licensing: strconv.FormatInt(item.Licensing, 10), //多点执业标志
  5404. DoctorServiceStatus: "", //医师医保服务资格状态
  5405. MonitoringLevel: "", //监控等级
  5406. DrugPsychotropicSubstances: "", //毒麻精神药品资格
  5407. HealthCareCode: "", // 母婴保健技术考核合格证书编号
  5408. PlanningTechnicalServiceCode: "", //计划生育技术服务人员合格证编号
  5409. PharmacistType: "", //药师类别
  5410. PharmacistPracticeCategory: "", //药师执业类别
  5411. PharmacistsLicensing: "", //药师执业范围
  5412. PharmacistRegistrationNumber: "", //执业药师注册证编号
  5413. OfficeCode: "", //科室编码
  5414. JobNumber: item.JobNumber, //工号
  5415. PostName: "", //职位名称
  5416. TechnicalJobLevelCode: "", //专业技术职务级别编码
  5417. IsActive: strconv.FormatInt(item.IsActive, 10), //在职与否
  5418. PrescriptionQualificationIdentification: strconv.FormatInt(item.PrescriptionQualificationIdentification, 10), //处方资格标识
  5419. IdentificationOutpatients: strconv.FormatInt(item.IdentificationOutpatients, 10), //门诊大病医师标识
  5420. OutpatientIllnessCategory: item.OutpatientIllnessCategory, //门诊大病类别
  5421. StartTime: 20201010, //开始日期
  5422. StaffCode: "", //医护人员编码
  5423. EndTime: 0, // 结束日期
  5424. }
  5425. result := service.SzybYS002(doctor_name, doctor_code, miConfig.Code, detail)
  5426. var dat map[string]interface{}
  5427. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5428. fmt.Println(dat)
  5429. } else {
  5430. fmt.Println(err)
  5431. }
  5432. userJSONBytes, _ := json.Marshal(dat)
  5433. var res Result
  5434. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5435. utils.ErrorLog("解析失败:%v", err)
  5436. c.ServeSuccessJSON(map[string]interface{}{
  5437. "failed_code": -10,
  5438. "msg": res.Transreturnmessage,
  5439. })
  5440. return
  5441. }
  5442. if res.Transreturncode == "00000000" {
  5443. //去撤销
  5444. service.UpdateAdminUserRoleById(item.ID, orgId)
  5445. } else {
  5446. isSuccess = false
  5447. //失败
  5448. c.ServeSuccessJSON(map[string]interface{}{
  5449. "failed_code": -10,
  5450. "msg": res.Transreturnmessage,
  5451. })
  5452. return
  5453. }
  5454. fmt.Println(isSuccess)
  5455. c.ServeSuccessJSON(map[string]interface{}{
  5456. "failed_code": -10,
  5457. "msg": res.Transreturnmessage,
  5458. })
  5459. return
  5460. }
  5461. }
  5462. }
  5463. func (c *SZHisApiController) GetUpdateMedicalList() {
  5464. adminUserInfo := c.GetAdminUserInfo()
  5465. orgId := adminUserInfo.CurrentOrgId
  5466. //获取所有医生护士信息
  5467. list, _ := service.GetDoctorList(orgId)
  5468. //获取所有角色名称
  5469. roleList, _ := service.GetRoleList(orgId)
  5470. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  5471. for _, item := range list {
  5472. for _, it := range roleList {
  5473. if item.RoleId == it.ID {
  5474. item.Name = it.RoleName
  5475. }
  5476. }
  5477. }
  5478. var doctor_name string
  5479. var doctor_code string
  5480. doctor_name = "黄亦轩"
  5481. doctor_code = "1001"
  5482. var pagesize int = 50
  5483. var start int = 1
  5484. var stop int
  5485. var pagecount int
  5486. var curpage int
  5487. var isSuccess bool = true
  5488. //总页数,向上取整,注意除之前要先转换类型为float64
  5489. pagecount = int(math.Ceil(float64(len(list)) / float64(pagesize)))
  5490. var ress []*Result
  5491. for curpage = 1; curpage <= pagecount; curpage++ {
  5492. if curpage == 1 {
  5493. start = 1
  5494. } else {
  5495. start = (curpage-1)*pagesize + 1
  5496. }
  5497. stop = curpage * pagesize
  5498. if stop > len(list) {
  5499. stop = len(list)
  5500. }
  5501. //这里就可以查看开始和结束了
  5502. fmt.Println(list[start-1 : stop])
  5503. var customs []*models.DocDetail
  5504. for _, item := range list {
  5505. detail := &models.DocDetail{
  5506. StaffCode: "", //医护人员编码
  5507. UserName: item.UserName, //医护人员姓名
  5508. RoleId: item.Name, //医护人员类别
  5509. Sex: "", //性别
  5510. CardType: "", //证件类型
  5511. IdCard: "", //证件号码
  5512. Phone: "", //联系电话
  5513. WorkMajorName: "", //现从事专业名称
  5514. Nation: "", //民族
  5515. BirthDay: 20201022, //出生日期
  5516. WorkTime: 20201022, //参加工作日期
  5517. Education: "", //学历
  5518. StudyMajorName: "", //所学的专业名称
  5519. CertificateCode: "", //证书编码
  5520. MedicalCode: "", //医师资格编码
  5521. MedicalRangeCode: "", //医师执业范围代码
  5522. MedicalLevel: "", //医生级别
  5523. TypeJob: "", //职业类别
  5524. DoctorNumber: "", //医师编号
  5525. Licensing: "", //职业标志
  5526. DoctorServiceStatus: "", //医师医保服务资格状态
  5527. MonitoringLevel: "", //监控等级
  5528. DrugPsychotropicSubstances: "", //毒麻精神药品资格
  5529. HealthCareCode: "", // 母婴保健技术考核合格证书编号
  5530. PlanningTechnicalServiceCode: "", //计划生育技术服务人员合格证编号
  5531. PharmacistType: "", //药师类别
  5532. PharmacistPracticeCategory: "", //药师执业类别
  5533. PharmacistsLicensing: "", //药师执业范围
  5534. PharmacistRegistrationNumber: "", //执业药师注册证编号
  5535. OfficeCode: "", //科室编码
  5536. JobNumber: "", //工号
  5537. PostName: "", //职位名称
  5538. TechnicalJobLevelCode: "", //专业技术职务级别编码
  5539. IsActive: "", //在职与否
  5540. PrescriptionQualificationIdentification: "", //处方资格标识
  5541. IdentificationOutpatients: "", //门诊大病医师标识
  5542. OutpatientIllnessCategory: "", //门诊大病类别
  5543. StartTime: 20201022, //开始日期
  5544. EndTime: 20201022,
  5545. }
  5546. customs = append(customs, detail)
  5547. }
  5548. result := service.SzybYS003(doctor_name, doctor_code, miConfig.Code, customs)
  5549. var dat map[string]interface{}
  5550. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5551. fmt.Println(dat)
  5552. } else {
  5553. fmt.Println(err)
  5554. }
  5555. userJSONBytes, _ := json.Marshal(dat)
  5556. var res Result
  5557. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5558. utils.ErrorLog("解析失败:%v", err)
  5559. c.ServeSuccessJSON(map[string]interface{}{
  5560. "failed_code": -10,
  5561. "msg": res.Transreturnmessage,
  5562. })
  5563. return
  5564. }
  5565. if res.Transreturncode == "00000000" {
  5566. ress = append(ress, &res)
  5567. } else {
  5568. isSuccess = false
  5569. //失败
  5570. c.ServeSuccessJSON(map[string]interface{}{
  5571. "failed_code": -10,
  5572. "msg": res.Transreturnmessage,
  5573. })
  5574. return
  5575. }
  5576. fmt.Println(isSuccess)
  5577. c.ServeSuccessJSON(map[string]interface{}{
  5578. "failed_code": -10,
  5579. "msg": res.Transreturnmessage,
  5580. })
  5581. return
  5582. }
  5583. }
  5584. func (c *SZHisApiController) GetGoodsList() {
  5585. adminUserInfo := c.GetAdminUserInfo()
  5586. orgId := adminUserInfo.CurrentOrgId
  5587. ids := c.GetString("ids")
  5588. admin_user_id, _ := c.GetInt64("admin_user_id")
  5589. roles, _ := service.GetAdminUserInfoByID(orgId, admin_user_id)
  5590. stringarr := strings.Split(ids, ",")
  5591. idss := make([]int64, 0)
  5592. for _, item := range stringarr {
  5593. itemsss, _ := strconv.ParseInt(item, 10, 64)
  5594. id := int64(itemsss)
  5595. idss = append(idss, id)
  5596. }
  5597. //批量获取所有耗材信息
  5598. list, _ := service.GetBatchGoodInformationList(idss)
  5599. //获取单位
  5600. miConfig, _ := service.FindMedicalInsuranceInfo(orgId)
  5601. var doctor_name string
  5602. var doctor_code string
  5603. doctor_name = roles.UserName
  5604. doctor_code = "1001"
  5605. var isSuccess bool = true
  5606. for _, item := range list {
  5607. detail := &models.XtGoodInformation{
  5608. GoodName: item.GoodName,
  5609. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  5610. ManufacturerName: item.ManufacturerName,
  5611. ProductionType: item.ProductionType,
  5612. SpecialMedical: item.SpecialMedical,
  5613. BuyPrice: item.BuyPrice,
  5614. SellPrice: item.SellPrice,
  5615. Remark: item.Remark,
  5616. SpecificationName: item.SpecificationName,
  5617. }
  5618. result := service.SzybYML007(doctor_name, doctor_code, miConfig.Code, detail)
  5619. fmt.Println("reuslt", result)
  5620. var dat map[string]interface{}
  5621. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5622. fmt.Println(dat)
  5623. } else {
  5624. fmt.Println(err)
  5625. }
  5626. userJSONBytes, _ := json.Marshal(dat)
  5627. var res Result
  5628. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5629. utils.ErrorLog("解析失败:%v", err)
  5630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5631. return
  5632. }
  5633. if res.Transreturncode == "00000000" {
  5634. //备案成功返回状态
  5635. _, err := service.UpdateGoodInformaitonByDetail(item.ID)
  5636. fmt.Println("err", err)
  5637. } else {
  5638. isSuccess = false
  5639. //失败
  5640. c.ServeSuccessJSON(map[string]interface{}{
  5641. "failed_code": -10,
  5642. "msg": res.Transreturnmessage,
  5643. })
  5644. return
  5645. }
  5646. fmt.Println(isSuccess)
  5647. c.ServeSuccessJSON(map[string]interface{}{
  5648. "failed_code": -10,
  5649. "msg": res.Transreturnmessage,
  5650. })
  5651. return
  5652. }
  5653. }
  5654. type Charset string
  5655. const (
  5656. UTF8 = Charset("UTF-8")
  5657. GB18030 = Charset("GB18030")
  5658. )
  5659. func ConvertToString(src string, srcCode string, tagCode string) string {
  5660. srcCoder := mahonia.NewDecoder(srcCode)
  5661. srcResult := srcCoder.ConvertString(src)
  5662. tagCoder := mahonia.NewDecoder(tagCode)
  5663. _, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
  5664. result := string(cdata)
  5665. return result
  5666. }