sz_his_api_controller.go 216KB

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