his_api_controller.go 180KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263
  1. package sg
  2. import (
  3. "archive/zip"
  4. "bytes"
  5. "encoding/json"
  6. "fmt"
  7. "gdyb/controllers"
  8. "gdyb/enums"
  9. "gdyb/models"
  10. "gdyb/service"
  11. "gdyb/utils"
  12. "github.com/astaxie/beego"
  13. "github.com/jinzhu/gorm"
  14. "github.com/shopspring/decimal"
  15. "io"
  16. "io/ioutil"
  17. "math/rand"
  18. "net/http"
  19. "os"
  20. "path/filepath"
  21. "strconv"
  22. "strings"
  23. "syscall"
  24. "time"
  25. "unsafe"
  26. )
  27. type HisApiController struct {
  28. controllers.BaseAuthAPIController
  29. }
  30. func HisManagerApiRegistRouters() {
  31. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  32. beego.Router("/api/diag/upload", &HisApiController{}, "get:GetUploadDiag")
  33. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  34. beego.Router("/api/settle/query", &HisApiController{}, "get:GetSettleAccounts")
  35. beego.Router("/api/checkaccount/get", &HisApiController{}, "get:GetCheckAccount")
  36. beego.Router("/api/checkdetailaccount/get", &HisApiController{}, "get:GetCheckDetailAccount")
  37. beego.Router("/api/refund/post", &HisApiController{}, "get:Refund")
  38. beego.Router("/api/sscard", &HisApiController{}, "get:Sscard")
  39. beego.Router("/api/refundnumber/post", &HisApiController{}, "get:RefundNumber")
  40. beego.Router("/api/refunddetail/post", &HisApiController{}, "get:RefundDetail")
  41. beego.Router("/api/treatment/check", &HisApiController{}, "get:CheckTreatment")
  42. beego.Router("/api/record/put", &HisApiController{}, "get:PutRecord")
  43. //beego.Router("/api/patient/info", &HisApiController{}, "get:GetHisPatientInfo")
  44. beego.Router("/api/org/info", &HisApiController{}, "get:GetOrgInfo")
  45. //beego.Router("/api/testcard", &HisApiController{}, "get:TestGetBasBaseInfo")
  46. //beego.Router("/api/testpay", &HisApiController{}, "get:TestPay")
  47. beego.Router("/api/pre_upload/get", &HisApiController{}, "get:GetPreUploadInfo")
  48. //beego.Router("/api/settle/get", &HisApiController{}, "get:GetSettleInfo")
  49. beego.Router("/api/310", &HisApiController{}, "get:Check310")
  50. beego.Router("/api/390", &HisApiController{}, "get:Check390")
  51. beego.Router("/api/patient/info", &HisApiController{}, "get:GetPatientInfo")
  52. //备案撤销相关接口
  53. beego.Router("/api/checkcode/get", &HisApiController{}, "get:GetCheckCode")
  54. beego.Router("/api/uncheckcode/get", &HisApiController{}, "get:UnCheckCode")
  55. beego.Router("/api/psn/putonrecord", &HisApiController{}, "get:PsnPutOnRecord")
  56. beego.Router("/api/psn/unputonrecord", &HisApiController{}, "get:PsnUnPutOnRecord")
  57. beego.Router("/api/psn/ncds/putonrecord", &HisApiController{}, "get:PsnPutNCDSOnRecord")
  58. beego.Router("/api/psn/ncds/unputonrecord", &HisApiController{}, "get:PsnPutUnNCDSOnRecord")
  59. beego.Router("/api/test", &HisApiController{}, "get:TestGetBasBaseInfo")
  60. beego.Router("/api/reversal", &HisApiController{}, "get:ReversalData")
  61. beego.Router("/api/reversal/other", &HisApiController{}, "get:ReversalOtherData")
  62. //beego.Router("/api/reversal/one", &HisApiController{}, "get:ReversalOtherOneData")
  63. beego.Router("/api/settlelist/get", &HisApiController{}, "get:GetSettleList")
  64. }
  65. type CustomFundPay struct {
  66. FundPayType string `json:"fund_pay_type"`
  67. FundPayamt float64 `json:"fund_payamt"`
  68. }
  69. func (c *HisApiController) GetSettleList() {
  70. order_id, _ := c.GetInt64("order_id")
  71. admin_user_id, _ := c.GetInt64("admin_user_id")
  72. order, _ := service.GetHisOrderByIDTwo(order_id)
  73. roles, _ := service.GetDoctorListTwo(c.GetAdminUserInfo().CurrentOrgId)
  74. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  75. admin, _ := service.GetAdminUserByUserID(roles[0].AdminUserId)
  76. curRoles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  77. depart, _ := service.GetDepartMentDetail(curRoles.DepartmentId)
  78. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  79. if order.ID == 0 {
  80. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  81. return
  82. }
  83. struct4101 := &service.Struct4101{
  84. PsnNo: order.PsnNo,
  85. MdtrtId: order.MdtrtId,
  86. SetlId: order.SetlId,
  87. PsnName: order.PsnName,
  88. Gend: order.Gend,
  89. Brdy: order.HisPatient.Brdy,
  90. Naty: order.Naty,
  91. PatnCertType: order.MdtrtCertType,
  92. Certno: order.Certno,
  93. Prfs: "90",
  94. ConerName: roles[0].UserName,
  95. PatnRlts: "99",
  96. ConerAddr: miConfig.OrgName,
  97. ConerTel: admin.Mobile,
  98. HiType: order.Insutype,
  99. Insuplc: miConfig.InsuplcAdmdvs,
  100. MaindiagFlag: "1",
  101. BillCode: order.FaPiaoCode,
  102. BillNo: order.FaPiaoNumber,
  103. BizSn: order.Number,
  104. PsnSelfPay: order.PsnPartAmt,
  105. PsnOwnPay: order.PsnPartAmt,
  106. AcctPay: order.AcctPay,
  107. PsnCashpay: order.PsnCashPay,
  108. HiPaymtd: "1",
  109. Hsorg: miConfig.InsuplcAdmdvs,
  110. HsorgOpter: miConfig.InsuplcAdmdvs,
  111. MedinsFillPsn: curRoles.UserName,
  112. MedinsFillDept: depart.Name,
  113. }
  114. if order.SettleType == 1 {
  115. t := time.Unix(int64(order.SettleAccountsDate), 0)
  116. dateStr := t.Format("2006-01-02")
  117. struct4101.SetlBegnDate = dateStr
  118. struct4101.SetlEndDate = dateStr
  119. } else {
  120. t := time.Unix(int64(order.SettleStartTime), 0)
  121. t2 := time.Unix(int64(order.SettleEndTime), 0)
  122. dateStartStr := t.Format("2006-01-02")
  123. dateEndStr := t2.Format("2006-01-02")
  124. struct4101.SetlBegnDate = dateStartStr
  125. struct4101.SetlEndDate = dateEndStr
  126. }
  127. var rf []*CustomFundPay
  128. json.Unmarshal([]byte(order.SetlDetail), &rf)
  129. for _, item := range rf {
  130. var tempFunPay service.CustomStruct
  131. tempFunPay.FundPayamt = item.FundPayamt
  132. tempFunPay.FundPayType = item.FundPayType
  133. struct4101.CustomStruct = append(struct4101.CustomStruct, tempFunPay)
  134. }
  135. var tempOpspdiseinfo service.OpspdiseinfoStruct
  136. sickConfig, _ := service.FindSickById(his.SickType)
  137. tempOpspdiseinfo.DiagCode = sickConfig.CountryCode
  138. tempOpspdiseinfo.DiagName = sickConfig.CountryContentName
  139. tempOpspdiseinfo.MaindiagFlag = "1"
  140. tempOpspdiseinfo.OprnOprtCode = ""
  141. tempOpspdiseinfo.OprnOprtName = ""
  142. struct4101.OpspdiseinfoStruct = append(struct4101.OpspdiseinfoStruct, tempOpspdiseinfo)
  143. var iteminfo service.IteminfoStruct
  144. var bedCostTotal float64 = 0 //床位总费
  145. var bedCostSelfTotal float64 = 0 //床位自费
  146. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  147. var operationCostTotal float64 = 0 //手术费
  148. var operationCostSelfTotal float64 = 0 //手术费
  149. var operationCostPartSelfTotal float64 = 0 //手术费
  150. var otherCostTotal float64 = 0 //其他费用
  151. var otherCostSelfTotal float64 = 0 //其他费用
  152. var otherCostPartSelfTotal float64 = 0 //其他费用
  153. var materialCostTotal float64 = 0 //材料费
  154. var materialCostSelfTotal float64 = 0 //材料费
  155. var materialCostPartSelfTotal float64 = 0 //材料费
  156. var westernMedicineCostTotal float64 = 0 //西药费
  157. var westernMedicineCostSelfTotal float64 = 0 //西药费
  158. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  159. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  160. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  161. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  162. var checkCostTotal float64 = 0 //检查费
  163. var checkCostSelfTotal float64 = 0 //检查费
  164. var checkCostPartSelfTotal float64 = 0 //检查费
  165. var laboratoryCostTotal float64 = 0 //化验费
  166. var laboratoryCostSelfTotal float64 = 0 //化验费
  167. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  168. var treatCostTotal float64 = 0 //治疗费用
  169. var treatCostSelfTotal float64 = 0 //治疗费用
  170. var treatCostPartSelfTotal float64 = 0 //治疗费用
  171. decimal.DivisionPrecision = 2
  172. var bed_fulamt_ownpay_amt float64 = 0
  173. var operation_fulamt_ownpay_amt float64 = 0
  174. var other_fulamt_ownpay_amt float64 = 0
  175. var westernMedicine_fulamt_ownpay_amt float64 = 0
  176. var chineseTraditional_fulamt_ownpay_amt float64 = 0
  177. var check_fulamt_ownpay_amt float64 = 0
  178. var material_fulamt_ownpay_amt float64 = 0
  179. var laboratory_fulamt_ownpay_amt float64 = 0
  180. var treat_fulamt_ownpay_amt float64 = 0
  181. var bed_claa_sunmfee float64 = 0
  182. var bed_clab_amt float64 = 0
  183. var bed_other_amt float64 = 0
  184. var operation_claa_sunmfee float64 = 0
  185. var operation_clab_amt float64 = 0
  186. var operation_other_amt float64 = 0
  187. var other_claa_sunmfee float64 = 0
  188. var other_clab_amt float64 = 0
  189. var other_other_amt float64 = 0
  190. var westernMedicine_claa_sunmfee float64 = 0
  191. var westernMedicine_clab_amt float64 = 0
  192. var westernMedicine_other_amt float64 = 0
  193. var chineseTraditional_claa_sunmfee float64 = 0
  194. var chineseTraditional_clab_amt float64 = 0
  195. var chineseTraditional_other_amt float64 = 0
  196. var check_claa_sunmfee float64 = 0
  197. var check_clab_amt float64 = 0
  198. var check_other_amt float64 = 0
  199. var material_claa_sunmfee float64 = 0
  200. var material_clab_amt float64 = 0
  201. var material_other_amt float64 = 0
  202. var laboratory_claa_sunmfee float64 = 0
  203. var laboratory_clab_amt float64 = 0
  204. var laboratory_other_amt float64 = 0
  205. var treat_claa_sunmfee float64 = 0
  206. var treat_clab_amt float64 = 0
  207. var treat_other_amt float64 = 0
  208. for _, item := range order.HisOrderInfo {
  209. if item.MedChrgitmType == "01" { //床位费
  210. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  211. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  212. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  213. bed_fulamt_ownpay_amt, _ = decimal.NewFromFloat(bed_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  214. if item.ChrgitmLv == "1" {
  215. bed_claa_sunmfee, _ = decimal.NewFromFloat(bed_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  216. }
  217. if item.ChrgitmLv == "2" {
  218. bed_clab_amt, _ = decimal.NewFromFloat(bed_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  219. }
  220. if item.ChrgitmLv == "3" {
  221. bed_other_amt, _ = decimal.NewFromFloat(bed_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  222. }
  223. }
  224. if item.MedChrgitmType == "03" { //检查费
  225. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  226. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  227. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  228. check_fulamt_ownpay_amt, _ = decimal.NewFromFloat(check_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  229. if item.ChrgitmLv == "1" {
  230. check_claa_sunmfee, _ = decimal.NewFromFloat(check_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  231. }
  232. if item.ChrgitmLv == "2" {
  233. check_clab_amt, _ = decimal.NewFromFloat(check_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  234. }
  235. if item.ChrgitmLv == "3" {
  236. check_other_amt, _ = decimal.NewFromFloat(check_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  237. }
  238. }
  239. if item.MedChrgitmType == "04" { //化验费
  240. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  241. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  242. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  243. laboratory_fulamt_ownpay_amt, _ = decimal.NewFromFloat(laboratory_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  244. if item.ChrgitmLv == "1" {
  245. laboratory_claa_sunmfee, _ = decimal.NewFromFloat(laboratory_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  246. }
  247. if item.ChrgitmLv == "2" {
  248. laboratory_clab_amt, _ = decimal.NewFromFloat(laboratory_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  249. }
  250. if item.ChrgitmLv == "3" {
  251. laboratory_other_amt, _ = decimal.NewFromFloat(laboratory_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  252. }
  253. }
  254. if item.MedChrgitmType == "05" { //治疗费
  255. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  256. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  257. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  258. treat_fulamt_ownpay_amt, _ = decimal.NewFromFloat(treat_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  259. if item.ChrgitmLv == "1" {
  260. treat_claa_sunmfee, _ = decimal.NewFromFloat(treat_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  261. }
  262. if item.ChrgitmLv == "2" {
  263. treat_clab_amt, _ = decimal.NewFromFloat(treat_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  264. }
  265. if item.ChrgitmLv == "3" {
  266. treat_other_amt, _ = decimal.NewFromFloat(treat_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  267. }
  268. }
  269. if item.MedChrgitmType == "06" { //手术费
  270. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  271. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  272. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  273. operation_fulamt_ownpay_amt, _ = decimal.NewFromFloat(operation_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  274. if item.ChrgitmLv == "1" {
  275. operation_claa_sunmfee, _ = decimal.NewFromFloat(operation_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  276. }
  277. if item.ChrgitmLv == "2" {
  278. operation_clab_amt, _ = decimal.NewFromFloat(operation_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  279. }
  280. if item.ChrgitmLv == "3" {
  281. operation_other_amt, _ = decimal.NewFromFloat(operation_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  282. }
  283. }
  284. if item.MedChrgitmType == "08" { //材料费
  285. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  286. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  287. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  288. material_fulamt_ownpay_amt, _ = decimal.NewFromFloat(material_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  289. if item.ChrgitmLv == "1" {
  290. material_claa_sunmfee, _ = decimal.NewFromFloat(material_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  291. }
  292. if item.ChrgitmLv == "2" {
  293. material_clab_amt, _ = decimal.NewFromFloat(material_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  294. }
  295. if item.ChrgitmLv == "3" {
  296. material_other_amt, _ = decimal.NewFromFloat(material_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  297. }
  298. }
  299. if item.MedChrgitmType == "09" { //西药费
  300. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  301. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  302. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  303. westernMedicine_fulamt_ownpay_amt, _ = decimal.NewFromFloat(westernMedicine_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  304. if item.ChrgitmLv == "1" {
  305. westernMedicine_claa_sunmfee, _ = decimal.NewFromFloat(westernMedicine_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  306. }
  307. if item.ChrgitmLv == "2" {
  308. westernMedicine_clab_amt, _ = decimal.NewFromFloat(westernMedicine_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  309. }
  310. if item.ChrgitmLv == "3" {
  311. westernMedicine_other_amt, _ = decimal.NewFromFloat(westernMedicine_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  312. }
  313. }
  314. if item.MedChrgitmType == "11" { //中成费
  315. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  316. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  317. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  318. chineseTraditional_fulamt_ownpay_amt, _ = decimal.NewFromFloat(chineseTraditional_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  319. if item.ChrgitmLv == "1" {
  320. chineseTraditional_claa_sunmfee, _ = decimal.NewFromFloat(chineseTraditional_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  321. }
  322. if item.ChrgitmLv == "2" {
  323. chineseTraditional_clab_amt, _ = decimal.NewFromFloat(chineseTraditional_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  324. }
  325. if item.ChrgitmLv == "3" {
  326. chineseTraditional_other_amt, _ = decimal.NewFromFloat(chineseTraditional_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  327. }
  328. }
  329. if item.MedChrgitmType == "14" { //其他费
  330. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  331. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  332. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  333. other_fulamt_ownpay_amt, _ = decimal.NewFromFloat(other_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  334. if item.ChrgitmLv == "1" {
  335. other_claa_sunmfee, _ = decimal.NewFromFloat(other_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  336. }
  337. if item.ChrgitmLv == "2" {
  338. other_clab_amt, _ = decimal.NewFromFloat(other_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  339. }
  340. if item.ChrgitmLv == "3" {
  341. other_other_amt, _ = decimal.NewFromFloat(other_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  342. }
  343. }
  344. }
  345. if bedCostTotal != 0 {
  346. iteminfo.MedChrgitm = "01"
  347. iteminfo.FulamtOwnpayAmt = bed_fulamt_ownpay_amt
  348. iteminfo.Amt = bedCostTotal
  349. iteminfo.ClaaSumfee = bed_claa_sunmfee
  350. iteminfo.ClabAmt = bed_clab_amt
  351. iteminfo.OthAmt = bed_other_amt
  352. struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  353. }
  354. if checkCostTotal != 0 {
  355. iteminfo.MedChrgitm = "03"
  356. iteminfo.FulamtOwnpayAmt = check_fulamt_ownpay_amt
  357. iteminfo.Amt = checkCostTotal
  358. iteminfo.ClaaSumfee = check_claa_sunmfee
  359. iteminfo.ClabAmt = check_clab_amt
  360. iteminfo.OthAmt = check_other_amt
  361. struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  362. }
  363. if laboratoryCostTotal != 0 {
  364. iteminfo.MedChrgitm = "04"
  365. iteminfo.FulamtOwnpayAmt = laboratory_fulamt_ownpay_amt
  366. iteminfo.Amt = laboratoryCostTotal
  367. iteminfo.ClaaSumfee = laboratory_claa_sunmfee
  368. iteminfo.ClabAmt = laboratory_clab_amt
  369. iteminfo.OthAmt = laboratory_other_amt
  370. struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  371. }
  372. if treatCostTotal != 0 {
  373. iteminfo.MedChrgitm = "05"
  374. iteminfo.FulamtOwnpayAmt = treat_fulamt_ownpay_amt
  375. iteminfo.Amt = treatCostTotal
  376. iteminfo.ClaaSumfee = treat_claa_sunmfee
  377. iteminfo.ClabAmt = treat_clab_amt
  378. iteminfo.OthAmt = treat_other_amt
  379. struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  380. }
  381. if operationCostTotal != 0 {
  382. iteminfo.MedChrgitm = "06"
  383. iteminfo.FulamtOwnpayAmt = bed_fulamt_ownpay_amt
  384. iteminfo.Amt = operationCostTotal
  385. iteminfo.ClaaSumfee = operation_claa_sunmfee
  386. iteminfo.ClabAmt = operation_clab_amt
  387. iteminfo.OthAmt = operation_other_amt
  388. struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  389. }
  390. if materialCostTotal != 0 {
  391. iteminfo.MedChrgitm = "08"
  392. iteminfo.FulamtOwnpayAmt = material_fulamt_ownpay_amt
  393. iteminfo.Amt = materialCostTotal
  394. iteminfo.ClaaSumfee = material_claa_sunmfee
  395. iteminfo.ClabAmt = material_clab_amt
  396. iteminfo.OthAmt = material_other_amt
  397. struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  398. }
  399. if westernMedicineCostTotal != 0 {
  400. iteminfo.MedChrgitm = "09"
  401. iteminfo.FulamtOwnpayAmt = westernMedicine_fulamt_ownpay_amt
  402. iteminfo.Amt = westernMedicineCostTotal
  403. iteminfo.ClaaSumfee = westernMedicine_claa_sunmfee
  404. iteminfo.ClabAmt = westernMedicine_clab_amt
  405. iteminfo.OthAmt = westernMedicine_other_amt
  406. struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  407. }
  408. if chineseTraditionalMedicineCostTotal != 0 {
  409. iteminfo.MedChrgitm = "11"
  410. iteminfo.FulamtOwnpayAmt = westernMedicine_fulamt_ownpay_amt
  411. iteminfo.Amt = westernMedicineCostTotal
  412. iteminfo.ClaaSumfee = westernMedicine_claa_sunmfee
  413. iteminfo.ClabAmt = westernMedicine_clab_amt
  414. iteminfo.OthAmt = westernMedicine_other_amt
  415. struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  416. }
  417. if otherCostTotal != 0 {
  418. iteminfo.MedChrgitm = "14"
  419. iteminfo.FulamtOwnpayAmt = other_fulamt_ownpay_amt
  420. iteminfo.Amt = otherCostTotal
  421. iteminfo.ClaaSumfee = other_claa_sunmfee
  422. iteminfo.ClabAmt = other_clab_amt
  423. iteminfo.OthAmt = other_other_amt
  424. struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  425. }
  426. struct4101.Ntly = "中国"
  427. result := service.Gdyb4101(struct4101, miConfig.SecretKey, miConfig.OrgName, curRoles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  428. fmt.Println(result)
  429. var dat map[string]interface{}
  430. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  431. fmt.Println(dat)
  432. } else {
  433. fmt.Println(err)
  434. }
  435. userJSONBytes, _ := json.Marshal(dat)
  436. var res ResultSeventeen
  437. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  438. utils.ErrorLog("解析失败:%v", err)
  439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  440. return
  441. }
  442. if res.Infcode == -1 {
  443. c.ServeSuccessJSON(map[string]interface{}{
  444. "failed_code": -10,
  445. "msg": res.ErrMsg,
  446. })
  447. return
  448. } else {
  449. hisFundSettleListResult := &models.HisFundSettleListResult{
  450. Number: res.Output.Data.SetlListId,
  451. Status: 1,
  452. Ctime: time.Now().Unix(),
  453. Mtime: time.Now().Unix(),
  454. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  455. IsUpload: 1,
  456. }
  457. service.CreateUploadRecord(hisFundSettleListResult)
  458. c.ServeSuccessJSON(map[string]interface{}{
  459. "msg": "上传成功",
  460. "result": hisFundSettleListResult,
  461. })
  462. return
  463. }
  464. }
  465. func (c *HisApiController) TestGetBasBaseInfo() {
  466. DllDef := syscall.MustLoadDLL("SSCard.dll")
  467. Iinit := DllDef.MustFindProc("Init")
  468. readCard := DllDef.MustFindProc("ReadCardBas")
  469. ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  470. if ret != 0 {
  471. fmt.Println("SSCard的报错原因:", err)
  472. fmt.Println("SSCard的运算结果为:", ret)
  473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  474. return
  475. }
  476. result := int(ret)
  477. fmt.Println("SSCard的运算结果为1:", result)
  478. if readCard == nil {
  479. fmt.Println("readcard is nil")
  480. readCard = DllDef.MustFindProc("ReadCardBas")
  481. }
  482. if readCard == nil {
  483. fmt.Println("readcard reload is nil")
  484. return
  485. }
  486. str := make([]byte, 1024)
  487. str1 := make([]byte, 1024)
  488. cdat := len(str)
  489. cdat1 := len(str1)
  490. p := *((*int32)(unsafe.Pointer(&str[0])))
  491. p1 := *((*int32)(unsafe.Pointer(&str1[0])))
  492. ret2, _, err2 := readCard.Call(uintptr(p), uintptr(cdat), uintptr(p1), uintptr(cdat1))
  493. fmt.Println(" Add(4,5)的结果为:", ret2)
  494. str11 := prttostr(uintptr(p))
  495. str22 := prttostr(uintptr(p1))
  496. fmt.Println(" str:", str11)
  497. fmt.Println(" str1:", str22)
  498. // runtime.GC()
  499. if err2 != nil {
  500. fmt.Println("SSCard的运算结果为:", ret2)
  501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  502. return
  503. }
  504. }
  505. func prttostr(vcode uintptr) string {
  506. var vbyte []byte
  507. for i := 0; i < 10; i++ {
  508. sbyte := *((*byte)(unsafe.Pointer(vcode)))
  509. if sbyte == 0 {
  510. break
  511. }
  512. vbyte = append(vbyte, sbyte)
  513. vcode += 1
  514. }
  515. return string(vbyte)
  516. }
  517. //func (c *HisApiController) TestPay() {
  518. // DllDef2 := syscall.MustLoadDLL("SSSE32.dll")
  519. // readCards := DllDef2.MustFindProc("BankTrans")
  520. // inputData := make(map[string]interface{})
  521. // inputData["transId"] = "05"
  522. // inputData["amount"] = "0.01"
  523. // inputData["traceNo"] = "20210227093601325405377"
  524. // inputData["cardNo"] = "F36084348"
  525. // inputData["id"] = "44022919620927046X"
  526. // //jsonStr := `
  527. // // {
  528. // // "transId": "05",
  529. // // "amount":"1.00",
  530. // // "traceNo":"20210227093601325405377",
  531. // // "cardNo":"F36084348",
  532. // // "id":"44022919620927046X"
  533. // //
  534. // // }
  535. // //`
  536. //
  537. // bytes_arr, _ := json.Marshal(inputData)
  538. // str3 := make([]byte, 256)
  539. // ret4, _, err4 := readCards.Call(StrPtr(string(bytes_arr)), (uintptr)(unsafe.Pointer(&str3[0])))
  540. // fmt.Println(":", string(str3))
  541. //
  542. // if err4 != nil {
  543. // fmt.Println("SSCard的运算结果为:", ret4)
  544. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  545. // return
  546. // }
  547. //
  548. //}
  549. //func (c *HisApiController) TestGetBasBaseInfo() {
  550. //
  551. // //result := C.Init(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  552. // //fmt.Println(result)
  553. // //cs1 := C.CString("")
  554. // //cs2 := C.CString("")
  555. // //C.ReadCardBas(cs1, IntPtr(1024), cs2, IntPtr(1024))
  556. // //fmt.Println(cs1)
  557. // //fmt.Println(cs2)
  558. // //C.free(unsafe.Pointer(cs1))
  559. // //C.free(unsafe.Pointer(cs2))
  560. //
  561. // //
  562. //
  563. // DllDef := syscall.MustLoadDLL("SSCard.dll")
  564. // Iinit := DllDef.MustFindProc("Init")
  565. // readCard := DllDef.MustFindProc("ReadCardBas")
  566. // ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  567. // if ret != 0 {
  568. // fmt.Println("SSCard的报错原因:", err)
  569. // fmt.Println("SSCard的运算结果为:", ret)
  570. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  571. // return
  572. // }
  573. //
  574. // result := int(ret)
  575. // fmt.Println("SSCard的运算结果为1:", result)
  576. //
  577. // //path := ""
  578. // //bytePath := []byte( "\x00")
  579. // //bytePath2 := []byte( "\x00")
  580. // //ssss
  581. //
  582. // str := make([]byte, 256)
  583. // str1 := make([]byte, 256)
  584. // s2 := []byte(string(str))
  585. // s3 := []byte(string(str1))
  586. // ret2, _, err2 := readCard.Call((uintptr)(unsafe.Pointer(&s2[0])), IntPtr(256), (uintptr)(unsafe.Pointer(&s3[0])), IntPtr(256))
  587. // fmt.Println(" Add(4,5)的结果为:", ret2)
  588. // fmt.Println(" str:", s2)
  589. // fmt.Println(" str1:", s3)
  590. // if err2 != nil {
  591. // fmt.Println("SSCard的运算结果为:", ret2)
  592. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  593. // return
  594. // }
  595. //
  596. // //DllDef := syscall.MustLoadDLL("SSCard.dll")
  597. //
  598. //}
  599. func (c *HisApiController) GetOrgInfo() {
  600. miConfig, _ := service.FindMedicalInsuranceInfo(9919)
  601. service.Gdyb1201("", miConfig.OrgName, "1122", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 1, "")
  602. }
  603. func (c *HisApiController) GetHisPatientInfo() {
  604. medical_insurance_card := c.GetString("medical_insurance_card")
  605. id_card_type, _ := c.GetInt64("id_card_type")
  606. id_card := c.GetString("id_card")
  607. adminInfo := c.GetAdminUserInfo()
  608. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  609. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  610. appRole, _ := service.GetAppRole(adminInfo.CurrentOrgId)
  611. IdCardNo := ""
  612. if id_card_type == 1 {
  613. IdCardNo = medical_insurance_card
  614. } else if id_card_type == 2 {
  615. IdCardNo = id_card
  616. }
  617. if config.IsOpen == 1 {
  618. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  619. resp, requestErr := http.Get(api)
  620. if requestErr != nil {
  621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  622. return
  623. }
  624. defer resp.Body.Close()
  625. body, ioErr := ioutil.ReadAll(resp.Body)
  626. if ioErr != nil {
  627. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  629. return
  630. }
  631. var respJSON map[string]interface{}
  632. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  633. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  635. return
  636. }
  637. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  638. userJSONBytes, _ := json.Marshal(userJSON)
  639. var res ResultTwo
  640. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  641. utils.ErrorLog("解析失败:%v", err)
  642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  643. return
  644. }
  645. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  646. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  647. infoStr := string(Iinfos)
  648. idetinfoStr := string(Idetinfos)
  649. if res.Infcode == 0 {
  650. his := models.VMHisPatient{
  651. Status: 1,
  652. Ctime: time.Now().Unix(),
  653. Mtime: time.Now().Unix(),
  654. PsnNo: res.Output.Baseinfo.PsnNo,
  655. PsnCertType: res.Output.Baseinfo.PsnCertType,
  656. Certno: res.Output.Baseinfo.Certno,
  657. PsnName: res.Output.Baseinfo.PsnName,
  658. Gend: res.Output.Baseinfo.Gend,
  659. Naty: res.Output.Baseinfo.Naty,
  660. Brdy: res.Output.Baseinfo.Brdy,
  661. Age: res.Output.Baseinfo.Age,
  662. Iinfo: infoStr,
  663. Idetinfo: idetinfoStr,
  664. UserOrgId: adminInfo.CurrentOrgId,
  665. IsReturn: 1,
  666. IdCardType: id_card_type,
  667. }
  668. c.ServeSuccessJSON(map[string]interface{}{
  669. "info": his,
  670. })
  671. } else {
  672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  673. return
  674. }
  675. }
  676. }
  677. func (c *HisApiController) Sscard() {
  678. //id_card_type, _ := c.GetInt64("id_card_type")
  679. //adminUser := c.GetAdminUserInfo()
  680. //miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  681. id_card_type := 1
  682. r := CardInit()
  683. fmt.Println(r)
  684. //if r == 0 {
  685. switch id_card_type {
  686. case 1:
  687. //defer GetBasBaseInfo()
  688. //if err != nil {
  689. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  690. // return
  691. //
  692. //} else {
  693. // fmt.Println(basStr)
  694. //
  695. // bas := strings.Split(basStr, "|")
  696. //
  697. // basNumber := bas[1]
  698. //
  699. // //basNumber := bas[2]
  700. // card_sn := bas[3]
  701. //
  702. // appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
  703. //
  704. // api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + basNumber + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10) + "&card_sn=" + card_sn
  705. // resp, requestErr := http.Get(api)
  706. // if requestErr != nil {
  707. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  708. // return
  709. // }
  710. // defer resp.Body.Close()
  711. // body, ioErr := ioutil.ReadAll(resp.Body)
  712. // if ioErr != nil {
  713. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  714. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  715. // return
  716. // }
  717. // var respJSON map[string]interface{}
  718. //
  719. // if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  720. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  721. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  722. // return
  723. // }
  724. //
  725. // userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  726. // userJSONBytes, _ := json.Marshal(userJSON)
  727. // var res ResultTwo
  728. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  729. // utils.ErrorLog("解析失败:%v", err)
  730. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  731. // return
  732. // }
  733. // Iinfos, _ := json.Marshal(res.Output.Iinfo)
  734. // Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  735. // infoStr := string(Iinfos)
  736. // idetinfoStr := string(Idetinfos)
  737. //
  738. // if res.Infcode == 0 {
  739. // his := models.VMHisPatient{
  740. // Status: 1,
  741. // Ctime: time.Now().Unix(),
  742. // Mtime: time.Now().Unix(),
  743. // PsnNo: res.Output.Baseinfo.PsnNo,
  744. // PsnCertType: res.Output.Baseinfo.PsnCertType,
  745. // Certno: res.Output.Baseinfo.Certno,
  746. // PsnName: res.Output.Baseinfo.PsnName,
  747. // Gend: res.Output.Baseinfo.Gend,
  748. // Naty: res.Output.Baseinfo.Naty,
  749. // Brdy: res.Output.Baseinfo.Brdy,
  750. // Age: res.Output.Baseinfo.Age,
  751. // Iinfo: infoStr,
  752. // Idetinfo: idetinfoStr,
  753. // UserOrgId: adminUser.CurrentOrgId,
  754. // IsReturn: 1,
  755. // IdCardType: id_card_type,
  756. // }
  757. //
  758. // patient, err := service.GetPatientByNumber(basNumber, adminUser.CurrentOrgId)
  759. // if err == gorm.ErrRecordNotFound {
  760. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  761. // return
  762. //
  763. // } else if err != nil {
  764. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  765. // return
  766. //
  767. // } else {
  768. // c.ServeSuccessJSON(map[string]interface{}{
  769. // "patient": patient,
  770. // "his": his,
  771. // "number": basNumber,
  772. // })
  773. // }
  774. // } else {
  775. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  776. // return
  777. // }
  778. //
  779. //}
  780. break
  781. case 2:
  782. ////SFZStr, err := GetSFZBaseInfo()
  783. //if err != nil {
  784. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  785. // return
  786. //
  787. //} else {
  788. //
  789. // id_card_str := strings.Split(SFZStr, "^")
  790. // id_card_number := id_card_str[0]
  791. //appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
  792. //
  793. //api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + id_card_number + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10)
  794. //resp, requestErr := http.Get(api)
  795. //if requestErr != nil {
  796. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  797. // return
  798. //}
  799. //defer resp.Body.Close()
  800. //body, ioErr := ioutil.ReadAll(resp.Body)
  801. //if ioErr != nil {
  802. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  803. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  804. // return
  805. //}
  806. //var respJSON map[string]interface{}
  807. //
  808. //if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  809. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  810. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  811. // return
  812. //}
  813. //
  814. //userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  815. //userJSONBytes, _ := json.Marshal(userJSON)
  816. //var res ResultTwo
  817. //if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  818. // utils.ErrorLog("解析失败:%v", err)
  819. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  820. // return
  821. //}
  822. //Iinfos, _ := json.Marshal(res.Output.Iinfo)
  823. //Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  824. //infoStr := string(Iinfos)
  825. //idetinfoStr := string(Idetinfos)
  826. //
  827. //if res.Infcode == 0 {
  828. // his := models.VMHisPatient{
  829. // Status: 1,
  830. // Ctime: time.Now().Unix(),
  831. // Mtime: time.Now().Unix(),
  832. // PsnNo: res.Output.Baseinfo.PsnNo,
  833. // PsnCertType: res.Output.Baseinfo.PsnCertType,
  834. // Certno: res.Output.Baseinfo.Certno,
  835. // PsnName: res.Output.Baseinfo.PsnName,
  836. // Gend: res.Output.Baseinfo.Gend,
  837. // Naty: res.Output.Baseinfo.Naty,
  838. // Brdy: res.Output.Baseinfo.Brdy,
  839. // Age: res.Output.Baseinfo.Age,
  840. // Iinfo: infoStr,
  841. // Idetinfo: idetinfoStr,
  842. // UserOrgId: adminUser.CurrentOrgId,
  843. // IsReturn: 1,
  844. // IdCardType: id_card_type,
  845. // }
  846. // patient, err := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  847. // if err == gorm.ErrRecordNotFound {
  848. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  849. // return
  850. //
  851. // } else if err != nil {
  852. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  853. // return
  854. //
  855. // } else {
  856. // c.ServeSuccessJSON(map[string]interface{}{
  857. // "patient": patient,
  858. // "number": id_card_number,
  859. // })
  860. // }
  861. //}
  862. break
  863. case 3:
  864. break
  865. }
  866. }
  867. //func GetBasBaseInfo() (jsonStr string, err error) {
  868. //
  869. // handle := syscall.NewLazyDLL("SSCard.dll")
  870. // add := handle.NewProc("ReadCardBas")
  871. // str := make([]byte, 1024)
  872. // str1 := make([]byte, 1024)
  873. // ret, _, _ := add.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  874. // fmt.Println(ConvertToString(string(str), "gbk", "utf-8"))
  875. //
  876. // fmt.Println(ConvertToString(string(str1), "gbk", "utf-8"))
  877. //
  878. // fmt.Println("> Add(4,5)的结果为:", ret)
  879. // handle.Release()
  880. //
  881. // return "", nil
  882. //
  883. //}
  884. //func GetSFZBaseInfo() (jsonStr string, err error) {
  885. // //handle := syscall.MustLoadDLL("SSCard.dll")
  886. //
  887. // str := make([]byte, 256)
  888. // str1 := make([]byte, 256)
  889. // r, _, _ := ReadIDCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  890. //
  891. // fmt.Println(r)
  892. // return string(str), nil
  893. //}
  894. //func GetQRBaseInfo() (jsonStr string, err error) {
  895. // handle := syscall.LoadDLL("SSCard.dll")
  896. // ReadCardBas := handle.FindProc("GetQRBase")
  897. //
  898. // str := make([]byte, 256)
  899. // str1 := make([]byte, 256)
  900. // r, _, _ := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  901. //
  902. // fmt.Println(string(str))
  903. // fmt.Println(r)
  904. // return string(str), nil
  905. //}
  906. func CardInit() int {
  907. DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  908. add := DllTestDef.MustFindProc("Init")
  909. ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  910. if err != nil {
  911. fmt.Println("SSCard的运算结果为:", ret)
  912. }
  913. result := int(ret)
  914. return result
  915. }
  916. //func CardInit() int {
  917. // ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  918. // if err != nil {
  919. // fmt.Println("SSCard的运算结果为:", ret)
  920. // }
  921. // fmt.Println(err)
  922. // result := int(ret)
  923. // return result
  924. //}
  925. func IntPtr(n int) uintptr {
  926. return uintptr(n)
  927. }
  928. func StrPtr(s string) uintptr {
  929. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  930. }
  931. type ResultTwo struct {
  932. ErrMsg string `json:"err_msg"`
  933. InfRefmsgid string `json:"inf_refmsgid"`
  934. Infcode int64 `json:"infcode"`
  935. Output struct {
  936. Baseinfo struct {
  937. Age float64 `json:"age"`
  938. Brdy string `json:"brdy"`
  939. Certno string `json:"certno"`
  940. Gend string `json:"gend"`
  941. Naty string `json:"naty"`
  942. PsnCertType string `json:"psn_cert_type"`
  943. PsnName string `json:"psn_name"`
  944. PsnNo string `json:"psn_no"`
  945. } `json:"baseinfo"`
  946. Idetinfo []interface{} `json:"idetinfo"`
  947. Iinfo []struct {
  948. Balc float64 `json:"balc"`
  949. CvlservFlag string `json:"cvlserv_flag"`
  950. EmpName string `json:"emp_name"`
  951. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  952. Insutype string `json:"insutype"`
  953. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  954. PausInsuDate string `json:"paus_insu_date"`
  955. PsnInsuDate string `json:"psn_insu_date"`
  956. PsnInsuStas string `json:"psn_insu_stas"`
  957. PsnType string `json:"psn_type"`
  958. } `json:"insuinfo"`
  959. } `json:"output"`
  960. RefmsgTime string `json:"refmsg_time"`
  961. RespondTime string `json:"respond_time"`
  962. Signtype interface{} `json:"signtype"`
  963. WarnInfo interface{} `json:"warn_info"`
  964. }
  965. type ResultThree struct {
  966. Cainfo interface{} `json:"cainfo"`
  967. ErrMsg string `json:"err_msg"`
  968. InfRefmsgid string `json:"inf_refmsgid"`
  969. Infcode int64 `json:"infcode"`
  970. Output struct {
  971. Data struct {
  972. IptOtpNo string `json:"ipt_otp_no"`
  973. MdtrtID string `json:"mdtrt_id"`
  974. PsnNo string `json:"psn_no"`
  975. } `json:"data"`
  976. } `json:"output"`
  977. RefmsgTime string `json:"refmsg_time"`
  978. RespondTime string `json:"respond_time"`
  979. Signtype interface{} `json:"signtype"`
  980. WarnMsg interface{} `json:"warn_msg"`
  981. }
  982. type ResultFour struct {
  983. Cainfo string `json:"cainfo"`
  984. ErrMsg string `json:"err_msg"`
  985. InfRefmsgid string `json:"inf_refmsgid"`
  986. Infcode int64 `json:"infcode"`
  987. Output struct {
  988. Result []struct {
  989. BasMednFlag string `json:"bas_medn_flag"`
  990. ChldMedcFlag string `json:"chld_medc_flag"`
  991. ChrgitmLv string `json:"chrgitm_lv"`
  992. Cnt float64 `json:"cnt"`
  993. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  994. DrtReimFlag string `json:"drt_reim_flag"`
  995. FeedetlSn string `json:"feedetl_sn"`
  996. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  997. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  998. InscpScpAmt float64 `json:"inscp_scp_amt"`
  999. ListSpItemFlag string `json:"list_sp_item_flag"`
  1000. LmtUsedFlag string `json:"lmt_used_flag"`
  1001. MedChrgitmType string `json:"med_chrgitm_type"`
  1002. Memo string `json:"memo"`
  1003. OverlmtAmt float64 `json:"overlmt_amt"`
  1004. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1005. Pric float64 `json:"pric"`
  1006. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  1007. SelfpayProp float64 `json:"selfpay_prop"`
  1008. } `json:"result"`
  1009. } `json:"output"`
  1010. RefmsgTime string `json:"refmsg_time"`
  1011. RespondTime string `json:"respond_time"`
  1012. Signtype string `json:"signtype"`
  1013. WarnMsg string `json:"warn_msg"`
  1014. }
  1015. type ResultFive struct {
  1016. Balc float64 `json:"balc"`
  1017. CvlservFlag string `json:"cvlserv_flag"`
  1018. EmpName string `json:"emp_name"`
  1019. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  1020. Insutype string `json:"insutype"`
  1021. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  1022. PausInsuDate string `json:"paus_insu_date"`
  1023. PsnInsuDate string `json:"psn_insu_date"`
  1024. PsnInsuStas string `json:"psn_insu_stas"`
  1025. PsnType string `json:"psn_type"`
  1026. }
  1027. type ResultSix struct {
  1028. Cainfo interface{} `json:"cainfo"`
  1029. ErrMsg string `json:"err_msg"`
  1030. InfRefmsgid string `json:"inf_refmsgid"`
  1031. Infcode int64 `json:"infcode"`
  1032. Output struct {
  1033. } `json:"output"`
  1034. RefmsgTime string `json:"refmsg_time"`
  1035. RespondTime string `json:"respond_time"`
  1036. Signtype interface{} `json:"signtype"`
  1037. WarnMsg interface{} `json:"warn_msg"`
  1038. }
  1039. type ResultSeven struct {
  1040. Cainfo string `json:"cainfo"`
  1041. ErrMsg string `json:"err_msg"`
  1042. InfRefmsgid string `json:"inf_refmsgid"`
  1043. Infcode int64 `json:"infcode"`
  1044. Output struct {
  1045. Setldetail []interface{} `json:"setldetail"`
  1046. Setlinfo struct {
  1047. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1048. AcctPay float64 `json:"acct_pay"`
  1049. ActPayDedc float64 `json:"act_pay_dedc"`
  1050. Age float64 `json:"age"`
  1051. Balc float64 `json:"balc"`
  1052. Brdy string `json:"brdy"`
  1053. Certno string `json:"certno"`
  1054. ClrOptins string `json:"clr_optins"`
  1055. ClrType string `json:"clr_type"`
  1056. ClrWay string `json:"clr_way"`
  1057. CvlservFlag string `json:"cvlserv_flag"`
  1058. CvlservPay float64 `json:"cvlserv_pay"`
  1059. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1060. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1061. Gend string `json:"gend"`
  1062. HifesPay float64 `json:"hifes_pay"`
  1063. HifmiPay float64 `json:"hifmi_pay"`
  1064. HifpPay float64 `json:"hifp_pay"`
  1065. HospPartAmt float64 `json:"hosp_part_amt"`
  1066. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1067. Insutype string `json:"insutype"`
  1068. MafPay float64 `json:"maf_pay"`
  1069. MdtrtCertType string `json:"mdtrt_cert_type"`
  1070. HifobPay float64 `json:"hifob_pay"`
  1071. MdtrtID string `json:"mdtrt_id"`
  1072. MedType string `json:"med_type"`
  1073. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1074. MedinsSetlID string `json:"medins_setl_id"`
  1075. Naty string `json:"naty"`
  1076. OthPay float64 `json:"oth_pay"`
  1077. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1078. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1079. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1080. PsnCashPay float64 `json:"psn_cash_pay"`
  1081. PsnCertType string `json:"psn_cert_type"`
  1082. PsnName string `json:"psn_name"`
  1083. PsnNo string `json:"psn_no"`
  1084. PsnPartAmt float64 `json:"psn_part_amt"`
  1085. PsnType string `json:"psn_type"`
  1086. SetlID string `json:"setl_id"`
  1087. SetlTime string `json:"setl_time"`
  1088. } `json:"setlinfo"`
  1089. } `json:"output"`
  1090. RefmsgTime string `json:"refmsg_time"`
  1091. RespondTime string `json:"respond_time"`
  1092. Signtype interface{} `json:"signtype"`
  1093. WarnMsg interface{} `json:"warn_msg"`
  1094. }
  1095. type ResultEight struct {
  1096. Cainfo string `json:"cainfo"`
  1097. ErrMsg string `json:"err_msg"`
  1098. InfRefmsgid string `json:"inf_refmsgid"`
  1099. Infcode int64 `json:"infcode"`
  1100. Output struct {
  1101. Stmtinfo struct {
  1102. SetlOptins string `json:"setl_optins"`
  1103. StmtRslt string `json:"stmt_rslt"`
  1104. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  1105. } `json:"stmtinfo"`
  1106. } `json:"output"`
  1107. RefmsgTime string `json:"refmsg_time"`
  1108. RespondTime string `json:"respond_time"`
  1109. Signtype interface{} `json:"signtype"`
  1110. WarnMsg interface{} `json:"warn_msg"`
  1111. }
  1112. type ResultNine struct {
  1113. Cainfo string `json:"cainfo"`
  1114. ErrMsg string `json:"err_msg"`
  1115. InfRefmsgid string `json:"inf_refmsgid"`
  1116. Infcode int64 `json:"infcode"`
  1117. Output struct {
  1118. FileQuryNo string `json:"file_qury_no"`
  1119. } `json:"output"`
  1120. RefmsgTime string `json:"refmsg_time"`
  1121. RespondTime string `json:"respond_time"`
  1122. Signtype interface{} `json:"signtype"`
  1123. WarnMsg interface{} `json:"warn_msg"`
  1124. }
  1125. type ResultTen struct {
  1126. Cainfo string `json:"cainfo"`
  1127. ErrMsg string `json:"err_msg"`
  1128. InfRefmsgid string `json:"inf_refmsgid"`
  1129. Infcode int64 `json:"infcode"`
  1130. Output struct {
  1131. DldEndtime string `json:"dld_endtime"`
  1132. FileQuryNo string `json:"file_qury_no"`
  1133. Filename string `json:"filename"`
  1134. } `json:"output"`
  1135. RefmsgTime string `json:"refmsg_time"`
  1136. RespondTime string `json:"respond_time"`
  1137. Signtype interface{} `json:"signtype"`
  1138. WarnMsg interface{} `json:"warn_msg"`
  1139. }
  1140. type ResultEleven struct {
  1141. Cainfo string `json:"cainfo"`
  1142. ErrMsg string `json:"err_msg"`
  1143. InfRefmsgid string `json:"inf_refmsgid"`
  1144. Infcode int64 `json:"infcode"`
  1145. Output struct {
  1146. Setlinfo struct {
  1147. FixmedinsName string `json:"fixmedins_name"`
  1148. FixmedinsCode string `json:"fixmedins_code"`
  1149. PsnNo string `json:"psn_no"`
  1150. PsnName string `json:"psn_name"`
  1151. HifobPay float64 `json:"hifob_pay"`
  1152. Gend string `json:"gend"`
  1153. Brdy string `json:"brdy"`
  1154. PsnCertType string `json:"psn_cert_type"`
  1155. PsnType string `json:"psn_type"`
  1156. EmpName string `json:"emp_name"`
  1157. Certno string `json:"certno"`
  1158. Insutype string `json:"insutype"`
  1159. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1160. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1161. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1162. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1163. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1164. ActPayDedc float64 `json:"act_pay_dedc"`
  1165. HifpPay float64 `json:"hifp_pay"`
  1166. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1167. CvlservPay float64 `json:"cvlserv_pay"`
  1168. HifesPay float64 `json:"hifes_pay"`
  1169. HifmiPay float64 `json:"hifmi_pay"`
  1170. MafPay float64 `json:"maf_pay"`
  1171. OthPay float64 `json:"oth_pay"`
  1172. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1173. PsnPay float64 `json:"psn_pay"`
  1174. AcctPay float64 `json:"acct_pay"`
  1175. CashPayamt float64 `json:"cash_payamt"`
  1176. Balc float64 `json:"balc"`
  1177. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1178. MedinsSetlId string `json:"medins_setl_id"`
  1179. RefdSetlFlag string `json:"refd_setl_flag"`
  1180. SetlTime string `json:"setl_time"`
  1181. MedType string `json:"med_type"`
  1182. HospLv string `json:"hosp_lv"`
  1183. } `json:"setlinfo"`
  1184. } `json:"output"`
  1185. RefmsgTime string `json:"refmsg_time"`
  1186. RespondTime string `json:"respond_time"`
  1187. Signtype interface{} `json:"signtype"`
  1188. WarnMsg interface{} `json:"warn_msg"`
  1189. }
  1190. type ResultTwelve struct {
  1191. Cainfo string `json:"cainfo"`
  1192. ErrMsg string `json:"err_msg"`
  1193. InfRefmsgid string `json:"inf_refmsgid"`
  1194. Infcode int64 `json:"infcode"`
  1195. Output struct {
  1196. MdtrtId string `json:"mdtrt_id"`
  1197. ChrgBchno string `json:"chrg_bchno"`
  1198. PsnNo string `json:"psn_no"`
  1199. } `json:"output"`
  1200. RefmsgTime string `json:"refmsg_time"`
  1201. RespondTime string `json:"respond_time"`
  1202. Signtype interface{} `json:"signtype"`
  1203. WarnMsg interface{} `json:"warn_msg"`
  1204. }
  1205. type ResultThirteen struct {
  1206. ErrMsg string `json:"err_msg"`
  1207. InfRefmsgid string `json:"inf_refmsgid"`
  1208. Infcode int64 `json:"infcode"`
  1209. Output struct {
  1210. Result struct {
  1211. TrtDclaDetlSn string `json:"trt_dcla_detl_sn"`
  1212. } `json:"result"`
  1213. } `json:"output"`
  1214. RefmsgTime string `json:"refmsg_time"`
  1215. RespondTime string `json:"respond_time"`
  1216. Signtype interface{} `json:"signtype"`
  1217. WarnInfo interface{} `json:"warn_info"`
  1218. }
  1219. type ResultFourteen struct {
  1220. ErrMsg string `json:"err_msg"`
  1221. InfRefmsgid string `json:"inf_refmsgid"`
  1222. Infcode int64 `json:"infcode"`
  1223. Output struct {
  1224. } `json:"output"`
  1225. RefmsgTime string `json:"refmsg_time"`
  1226. RespondTime string `json:"respond_time"`
  1227. Signtype interface{} `json:"signtype"`
  1228. WarnInfo interface{} `json:"warn_info"`
  1229. }
  1230. type ResultSixteen struct {
  1231. Cainfo string `json:"cainfo"`
  1232. ErrMsg string `json:"err_msg"`
  1233. InfRefmsgid string `json:"inf_refmsgid"`
  1234. Infcode int64 `json:"infcode"`
  1235. Output struct {
  1236. Setldetail []interface{} `json:"setldetail"`
  1237. Setlinfo struct {
  1238. MdtrtID string `json:"mdtrt_id"`
  1239. SetlID string `json:"setl_id"`
  1240. ClrOptins string `json:"clr_optins"`
  1241. SetlTime string `json:"setl_time"`
  1242. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1243. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1244. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1245. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1246. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1247. ActPayDedc float64 `json:"act_pay_dedc"`
  1248. HifpPay float64 `json:"hifp_pay"`
  1249. PoolPropSe float64 `json:"pool_prop_selfpay"`
  1250. Lfpay float64 `json:"selfpay"`
  1251. CvlservPay float64 `json:"cvlserv_pay"`
  1252. HifesPay float64 `json:"hifes_pay"`
  1253. HifmiPay float64 `json:"hifmi_pay"`
  1254. HifobPay float64 `json:"hifob_pay"`
  1255. MafPay float64 `json:"maf_pay"`
  1256. OthPay float64 `json:"oth_pay"`
  1257. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1258. PsnPartAmt float64 `json:"psn_part_amt"`
  1259. AcctPay float64 `json:"acct_pay"`
  1260. Balc float64 `json:"balc"`
  1261. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1262. HospPartAmt float64 `json:"hosp_part_amt"`
  1263. MedinsSetlID string `json:"medins_setl_id"`
  1264. PdnCashPay string `json:"pdn_cash_pay"`
  1265. } `json:"setlinfo"`
  1266. } `json:"output"`
  1267. RefmsgTime string `json:"refmsg_time"`
  1268. RespondTime string `json:"respond_time"`
  1269. Signtype interface{} `json:"signtype"`
  1270. WarnMsg interface{} `json:"warn_msg"`
  1271. }
  1272. type ResultSeventeen struct {
  1273. ErrMsg string `json:"err_msg"`
  1274. InfRefmsgid string `json:"inf_refmsgid"`
  1275. Infcode int64 `json:"infcode"`
  1276. Output struct {
  1277. Data struct {
  1278. SetlListId string `json:"setl_list_id"`
  1279. } `json:"data"`
  1280. } `json:"output"`
  1281. RefmsgTime string `json:"refmsg_time"`
  1282. RespondTime string `json:"respond_time"`
  1283. Signtype string `json:"signtype"`
  1284. WarnInfo string `json:"warn_info"`
  1285. }
  1286. type Custom struct {
  1287. DetItemFeeSumamt string
  1288. Cut string
  1289. FeedetlSn string
  1290. Price string
  1291. MedListCodg string
  1292. Type int64
  1293. AdviceId int64
  1294. ProjectId int64
  1295. ItemId int64
  1296. }
  1297. //获取个人信息----挂号-----上传就诊信息
  1298. func (c *HisApiController) GetRegisterInfo() {
  1299. id, _ := c.GetInt64("id")
  1300. record_time := c.GetString("record_time")
  1301. settlementValue, _ := c.GetInt64("settlement_value")
  1302. medical_insurance_card := c.GetString("medical_insurance_card")
  1303. name := c.GetString("name")
  1304. id_card_type, _ := c.GetInt64("id_card_type")
  1305. certificates, _ := c.GetInt64("certificates")
  1306. medical_care, _ := c.GetInt64("medical_care")
  1307. birthday := c.GetString("birthday")
  1308. age, _ := c.GetInt64("age")
  1309. id_card := c.GetString("id_card")
  1310. register_type, _ := c.GetInt64("register")
  1311. doctor, _ := c.GetInt64("doctor")
  1312. department, _ := c.GetInt64("department")
  1313. gender, _ := c.GetInt64("sex")
  1314. phone := c.GetString("phone")
  1315. registration_fee, _ := c.GetFloat("registration_fee")
  1316. medical_expenses, _ := c.GetFloat("medical_expenses")
  1317. social_type, _ := c.GetInt64("social_type")
  1318. admin_user_id, _ := c.GetInt64("admin_user_id")
  1319. diagnosis_id, _ := c.GetInt64("diagnosis")
  1320. sick_type, _ := c.GetInt64("sick_type")
  1321. reg_type := c.GetString("p_type")
  1322. timeLayout := "2006-01-02"
  1323. loc, _ := time.LoadLocation("Local")
  1324. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  1325. birthUnix := birthdays.Unix()
  1326. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1327. if err != nil {
  1328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1329. return
  1330. }
  1331. recordDateTime := theTime.Unix()
  1332. adminInfo := c.GetAdminUserInfo()
  1333. var patient service.Patients
  1334. if id == 0 {
  1335. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  1336. } else {
  1337. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  1338. }
  1339. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  1340. if patientPrescription.ID == 0 {
  1341. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  1342. }
  1343. //adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1344. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  1345. sickConfig, _ := service.FindSickById(sick_type)
  1346. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1347. if patient.ID == 0 {
  1348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1349. return
  1350. }
  1351. if len(patient.IdCardNo) == 0 {
  1352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  1353. return
  1354. }
  1355. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  1356. if config.IsOpen == 1 {
  1357. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&certificates=" + strconv.FormatInt(certificates, 10)
  1358. resp, requestErr := http.Get(api)
  1359. if requestErr != nil {
  1360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1361. return
  1362. }
  1363. defer resp.Body.Close()
  1364. body, ioErr := ioutil.ReadAll(resp.Body)
  1365. if ioErr != nil {
  1366. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1368. return
  1369. }
  1370. var respJSON map[string]interface{}
  1371. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1372. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1374. return
  1375. }
  1376. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1377. userJSONBytes, _ := json.Marshal(userJSON)
  1378. var res ResultTwo
  1379. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1380. utils.ErrorLog("解析失败:%v", err)
  1381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1382. return
  1383. }
  1384. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  1385. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  1386. infoStr := string(Iinfos)
  1387. idetinfoStr := string(Idetinfos)
  1388. if res.Infcode == 0 {
  1389. his := models.VMHisPatient{
  1390. Name: name,
  1391. Gender: gender,
  1392. Birthday: birthUnix,
  1393. MedicalTreatmentType: medical_care,
  1394. IdType: certificates,
  1395. IdCardNo: id_card,
  1396. BalanceAccountsType: settlementValue,
  1397. SocialType: social_type,
  1398. MedicalInsuranceNumber: medical_insurance_card,
  1399. RegisterType: register_type,
  1400. RegisterCost: registration_fee,
  1401. TreatmentCost: medical_expenses,
  1402. Status: 1,
  1403. Ctime: time.Now().Unix(),
  1404. Mtime: time.Now().Unix(),
  1405. PsnNo: res.Output.Baseinfo.PsnNo,
  1406. PsnCertType: res.Output.Baseinfo.PsnCertType,
  1407. Certno: res.Output.Baseinfo.Certno,
  1408. PsnName: res.Output.Baseinfo.PsnName,
  1409. Gend: res.Output.Baseinfo.Gend,
  1410. Naty: res.Output.Baseinfo.Naty,
  1411. Brdy: res.Output.Baseinfo.Brdy,
  1412. Age: res.Output.Baseinfo.Age,
  1413. Iinfo: infoStr,
  1414. Idetinfo: idetinfoStr,
  1415. PatientId: patient.ID,
  1416. RecordDate: theTime.Unix(),
  1417. UserOrgId: adminInfo.CurrentOrgId,
  1418. AdminUserId: admin_user_id,
  1419. IsReturn: 1,
  1420. IdCardType: id_card_type,
  1421. Doctor: doctor,
  1422. Departments: department,
  1423. SickType: sick_type,
  1424. Diagnosis: diagnosis_id,
  1425. PType: reg_type,
  1426. }
  1427. timestamp := time.Now().Unix()
  1428. tempTime := time.Unix(timestamp, 0)
  1429. timeFormat := tempTime.Format("20060102150405")
  1430. chrgBchno := rand.Intn(100000) + 10000
  1431. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1432. count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  1433. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1434. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  1435. IdCardNo := ""
  1436. if id_card_type == 1 {
  1437. IdCardNo = medical_insurance_card
  1438. } else {
  1439. IdCardNo = patient.IdCardNo
  1440. }
  1441. var insutypes []string
  1442. var insutype string
  1443. var is390 int = 0
  1444. var is310 int = 0
  1445. for _, item := range res.Output.Iinfo {
  1446. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1447. insutypes = append(insutypes, item.Insutype)
  1448. }
  1449. }
  1450. if len(insutypes) == 1 {
  1451. insutype = insutypes[0]
  1452. } else {
  1453. for _, i := range insutypes {
  1454. if i == "390" {
  1455. is390 = 1
  1456. }
  1457. if i == "310" {
  1458. is310 = 1
  1459. }
  1460. }
  1461. }
  1462. if is390 == 1 {
  1463. insutype = "390"
  1464. }
  1465. if is310 == 1 {
  1466. insutype = "310"
  1467. }
  1468. if len(insutypes) == 0 {
  1469. insutype = "310"
  1470. }
  1471. if count == 1 {
  1472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1473. return
  1474. }
  1475. api := "http://127.0.0.1:9532/" + "gdyb/two?cert_no=" + IdCardNo + "&insutype=" +
  1476. insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  1477. "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  1478. "&dept=" + department.Name + "&fixmedins_code=" + miConfig.Code + "&dept_code=" + department.Number + "&doctor_id=" + doctor_id + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10)
  1479. resp, requestErr := http.Get(api)
  1480. if requestErr != nil {
  1481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1482. return
  1483. }
  1484. defer resp.Body.Close()
  1485. body, ioErr := ioutil.ReadAll(resp.Body)
  1486. if ioErr != nil {
  1487. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1489. return
  1490. }
  1491. var respJSON map[string]interface{}
  1492. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1493. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1495. return
  1496. }
  1497. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1498. userJSONBytes, _ := json.Marshal(respJSON)
  1499. var res ResultThree
  1500. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1501. utils.ErrorLog("解析失败:%v", err)
  1502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1503. return
  1504. }
  1505. if res.Infcode == -1 {
  1506. adminUser := c.GetAdminUserInfo()
  1507. errlog := &models.HisOrderError{
  1508. UserOrgId: adminUser.CurrentOrgId,
  1509. Ctime: time.Now().Unix(),
  1510. Mtime: time.Now().Unix(),
  1511. ErrMsg: res.ErrMsg,
  1512. Status: 1,
  1513. PatientId: id,
  1514. RecordTime: recordDateTime,
  1515. Stage: 2,
  1516. }
  1517. service.CreateErrMsgLog(errlog)
  1518. c.ServeSuccessJSON(map[string]interface{}{
  1519. "failed_code": -10,
  1520. "msg": res.ErrMsg,
  1521. })
  1522. return
  1523. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  1524. //return
  1525. }
  1526. his.Number = res.Output.Data.MdtrtID
  1527. his.PsnNo = res.Output.Data.PsnNo
  1528. his.IptOtpNo = res.Output.Data.IptOtpNo
  1529. his.IdCardNo = patient.IdCardNo
  1530. his.PhoneNumber = patient.Phone
  1531. his.UserOrgId = adminInfo.CurrentOrgId
  1532. his.Ctime = time.Now().Unix()
  1533. his.Mtime = time.Now().Unix()
  1534. his.Status = 1
  1535. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  1536. if len(lists) == 1 {
  1537. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  1538. }
  1539. if err == nil {
  1540. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  1541. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  1542. "&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + reg_type + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code + "&diag_code=" + diagnosisConfig.CountryCode +
  1543. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  1544. resp2, requestErr2 := http.Get(api2)
  1545. if requestErr2 != nil {
  1546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1547. return
  1548. }
  1549. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  1550. if ioErr2 != nil {
  1551. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  1552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1553. return
  1554. }
  1555. var respJSON2 map[string]interface{}
  1556. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  1557. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1558. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1559. return
  1560. }
  1561. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1562. userJSONBytes2, _ := json.Marshal(respJSON2)
  1563. var res2 ResultSix
  1564. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  1565. utils.ErrorLog("解析失败:%v", err)
  1566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1567. return
  1568. }
  1569. if res2.Infcode == -1 {
  1570. adminUser := c.GetAdminUserInfo()
  1571. errlog := &models.HisOrderError{
  1572. UserOrgId: adminUser.CurrentOrgId,
  1573. Ctime: time.Now().Unix(),
  1574. Mtime: time.Now().Unix(),
  1575. ErrMsg: res2.ErrMsg,
  1576. Status: 1,
  1577. PatientId: id,
  1578. RecordTime: recordDateTime,
  1579. Stage: 3,
  1580. }
  1581. service.CreateErrMsgLog(errlog)
  1582. c.ServeSuccessJSON(map[string]interface{}{
  1583. "failed_code": -10,
  1584. "msg": res2.ErrMsg,
  1585. })
  1586. return
  1587. } else {
  1588. service.CreateHisPatientTwo(&his)
  1589. c.ServeSuccessJSON(map[string]interface{}{
  1590. "his_info": his,
  1591. })
  1592. }
  1593. } else {
  1594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1595. return
  1596. }
  1597. } else {
  1598. adminUser := c.GetAdminUserInfo()
  1599. errlog := &models.HisOrderError{
  1600. UserOrgId: adminUser.CurrentOrgId,
  1601. Ctime: time.Now().Unix(),
  1602. Mtime: time.Now().Unix(),
  1603. ErrMsg: res.ErrMsg,
  1604. Status: 1,
  1605. PatientId: id,
  1606. RecordTime: recordDateTime,
  1607. Stage: 1,
  1608. }
  1609. service.CreateErrMsgLog(errlog)
  1610. c.ServeSuccessJSON(map[string]interface{}{
  1611. "failed_code": -10,
  1612. "msg": res.ErrMsg,
  1613. })
  1614. return
  1615. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  1616. }
  1617. } else {
  1618. timeStr := time.Now().Format("2006-01-02")
  1619. timeArr := strings.Split(timeStr, "-")
  1620. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
  1621. his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  1622. var hisPatient models.XtHisPatient
  1623. if err == gorm.ErrRecordNotFound || his.ID == 0 {
  1624. hisPatient = models.XtHisPatient{
  1625. Name: name,
  1626. Age: age,
  1627. Gender: gender,
  1628. Birthday: birthUnix,
  1629. Phone: phone,
  1630. MedicalTreatmentType: medical_care,
  1631. IdType: certificates,
  1632. IdCardNo: id_card,
  1633. BalanceAccountsType: settlementValue,
  1634. SocialType: social_type,
  1635. MedicalInsuranceNumber: medical_insurance_card,
  1636. RegisterType: register_type,
  1637. RegisterCost: registration_fee,
  1638. TreatmentCost: medical_expenses,
  1639. AdminUserId: admin_user_id,
  1640. UserOrgId: adminInfo.CurrentOrgId,
  1641. Status: 1,
  1642. RecordDate: recordDateTime,
  1643. IsReturn: 1,
  1644. PatientId: patient.ID,
  1645. Ctime: time.Now().Unix(),
  1646. Mtime: time.Now().Unix(),
  1647. Number: str,
  1648. }
  1649. service.CreateHisPatient(&hisPatient)
  1650. }
  1651. c.ServeSuccessJSON(map[string]interface{}{
  1652. "his_info": hisPatient,
  1653. })
  1654. }
  1655. }
  1656. //上传明细----预结算----确认订单
  1657. func (c *HisApiController) GetUploadInfo() {
  1658. id, _ := c.GetInt64("id")
  1659. record_time := c.GetString("record_time")
  1660. his_patient_id, _ := c.GetInt64("his_patient_id")
  1661. pay_way, _ := c.GetInt64("pay_way")
  1662. pay_price, _ := c.GetFloat("pay_price")
  1663. pay_card_no := c.GetString("pay_card_no")
  1664. discount_price, _ := c.GetFloat("discount_price")
  1665. preferential_price, _ := c.GetFloat("preferential_price")
  1666. reality_price, _ := c.GetFloat("reality_price")
  1667. found_price, _ := c.GetFloat("found_price")
  1668. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1669. private_price, _ := c.GetFloat("private_price")
  1670. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1671. admin_user_id, _ := c.GetInt64("admin_user_id")
  1672. fapiao_code := c.GetString("fapiao_code")
  1673. fapiao_number := c.GetString("fapiao_number")
  1674. timeLayout := "2006-01-02"
  1675. loc, _ := time.LoadLocation("Local")
  1676. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1677. if err != nil {
  1678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1679. return
  1680. }
  1681. recordDateTime := theTime.Unix()
  1682. adminUser := c.GetAdminUserInfo()
  1683. var prescriptions []*models.HisPrescription
  1684. var start_time int64
  1685. var end_time int64
  1686. data := make(map[string]interface{})
  1687. if settle_accounts_type == 1 { //日结
  1688. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1689. data["pre"] = prescriptions
  1690. } else { //月结
  1691. start_time_str := c.GetString("start_time")
  1692. end_time_str := c.GetString("end_time")
  1693. timeLayout := "2006-01-02"
  1694. loc, _ := time.LoadLocation("Local")
  1695. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1696. if err != nil {
  1697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1698. return
  1699. }
  1700. recordStartTime := theStartTime.Unix()
  1701. start_time = recordStartTime
  1702. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1703. if err != nil {
  1704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1705. return
  1706. }
  1707. recordEndTime := theEndTime.Unix()
  1708. end_time = recordEndTime
  1709. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1710. data["pre"] = prescriptions
  1711. }
  1712. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1713. fmt.Println(his_patient_id)
  1714. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1715. timestamp := time.Now().Unix()
  1716. tempTime := time.Unix(timestamp, 0)
  1717. timeFormat := tempTime.Format("20060102150405")
  1718. chrgBchno := rand.Intn(100000) + 10000
  1719. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1720. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1721. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1722. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1723. strconv.FormatInt(his.PatientId, 10)
  1724. client := &http.Client{}
  1725. data["psn_no"] = his.PsnNo
  1726. data["mdtrt_id"] = his.Number
  1727. data["chrg_bchno"] = chrg_bchno
  1728. data["org_name"] = miConfig.OrgName
  1729. data["doctor"] = roles.UserName
  1730. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1731. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  1732. data["fixmedins_code"] = miConfig.Code
  1733. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  1734. data["dept_code"] = "15"
  1735. } else {
  1736. data["dept_code"] = department.Number
  1737. }
  1738. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1739. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1740. data["secret_key"] = miConfig.SecretKey
  1741. var ids []int64
  1742. for _, item := range prescriptions {
  1743. ids = append(ids, item.ID)
  1744. }
  1745. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1746. if config.IsOpen == 1 { //对接了医保,走医保流程
  1747. bytesData, _ := json.Marshal(data)
  1748. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  1749. resp, _ := client.Do(req)
  1750. defer resp.Body.Close()
  1751. body, ioErr := ioutil.ReadAll(resp.Body)
  1752. if ioErr != nil {
  1753. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1755. return
  1756. }
  1757. var respJSON map[string]interface{}
  1758. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1759. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1761. return
  1762. }
  1763. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1764. userJSONBytes, _ := json.Marshal(respJSON)
  1765. var res ResultFour
  1766. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1767. utils.ErrorLog("解析失败:%v", err)
  1768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1769. return
  1770. }
  1771. if res.Infcode == 0 {
  1772. order := &models.HisOrder{
  1773. UserOrgId: adminUser.CurrentOrgId,
  1774. HisPatientId: his.ID,
  1775. PatientId: his.PatientId,
  1776. SettleAccountsDate: recordDateTime,
  1777. Ctime: time.Now().Unix(),
  1778. Mtime: time.Now().Unix(),
  1779. Status: 1,
  1780. Number: chrg_bchno,
  1781. Infcode: res.Infcode,
  1782. WarnMsg: res.WarnMsg,
  1783. Cainfo: res.Cainfo,
  1784. ErrMsg: res.ErrMsg,
  1785. RespondTime: res.RefmsgTime,
  1786. InfRefmsgid: res.InfRefmsgid,
  1787. OrderStatus: 1,
  1788. PayWay: pay_way,
  1789. PayPrice: pay_price,
  1790. PayCardNo: pay_card_no,
  1791. DiscountPrice: discount_price,
  1792. PreferentialPrice: preferential_price,
  1793. RealityPrice: reality_price,
  1794. FoundPrice: found_price,
  1795. MedicalInsurancePrice: medical_insurance_price,
  1796. PrivatePrice: private_price,
  1797. IsMedicineInsurance: 1,
  1798. SettleType: settle_accounts_type,
  1799. SettleStartTime: start_time,
  1800. SettleEndTime: end_time,
  1801. Creator: roles.AdminUserId,
  1802. Modify: roles.AdminUserId,
  1803. FaPiaoNumber: fapiao_number,
  1804. FaPiaoCode: fapiao_code,
  1805. }
  1806. err = service.CreateOrder(order)
  1807. if err != nil {
  1808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1809. return
  1810. }
  1811. for _, item := range res.Output.Result {
  1812. temp := strings.Split(item.FeedetlSn, "-")
  1813. var advice_id int64 = 0
  1814. var project_id int64 = 0
  1815. var types int64 = 0
  1816. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1817. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1818. if temp[1] == "1" {
  1819. advice_id = id
  1820. project_id = 0
  1821. } else if temp[1] == "2" {
  1822. advice_id = 0
  1823. project_id = id
  1824. }
  1825. info := &models.HisOrderInfo{
  1826. OrderNumber: order.Number,
  1827. FeedetlSn: item.FeedetlSn,
  1828. UploadDate: time.Now().Unix(),
  1829. AdviceId: advice_id,
  1830. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1831. Cnt: item.Cnt,
  1832. Pric: float64(item.Pric),
  1833. PatientId: his.PatientId,
  1834. PricUplmtAmt: item.PricUplmtAmt,
  1835. SelfpayProp: item.SelfpayProp,
  1836. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1837. OverlmtAmt: item.OverlmtAmt,
  1838. PreselfpayAmt: item.PreselfpayAmt,
  1839. BasMednFlag: item.BasMednFlag,
  1840. MedChrgitmType: item.MedChrgitmType,
  1841. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1842. Status: 1,
  1843. Memo: item.Memo,
  1844. Mtime: time.Now().Unix(),
  1845. InscpScpAmt: item.InscpScpAmt,
  1846. DrtReimFlag: item.DrtReimFlag,
  1847. Ctime: time.Now().Unix(),
  1848. ListSpItemFlag: item.ListSpItemFlag,
  1849. ChldMedcFlag: item.ChldMedcFlag,
  1850. LmtUsedFlag: item.LmtUsedFlag,
  1851. ChrgitmLv: item.ChrgitmLv,
  1852. UserOrgId: adminUser.CurrentOrgId,
  1853. HisPatientId: his.ID,
  1854. OrderId: order.ID,
  1855. ProjectId: project_id,
  1856. Type: types,
  1857. }
  1858. service.CreateOrderInfo(info)
  1859. }
  1860. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1861. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1862. var total float64
  1863. for _, item := range prescriptions {
  1864. if item.Type == 1 { //药品
  1865. for _, subItem := range item.HisDoctorAdviceInfo {
  1866. total = total + (subItem.Price * subItem.PrescribingNumber)
  1867. }
  1868. }
  1869. if item.Type == 2 { //项目
  1870. for _, subItem := range item.HisPrescriptionProject {
  1871. total = total + (subItem.Price * float64(subItem.Count))
  1872. }
  1873. }
  1874. }
  1875. for _, item := range prescriptions {
  1876. for _, subItem := range item.HisAdditionalCharge {
  1877. total = total + (subItem.Price * float64(subItem.Count))
  1878. }
  1879. }
  1880. allTotal := fmt.Sprintf("%.2f", total)
  1881. if res.Infcode == 0 {
  1882. var rf []*ResultFive
  1883. json.Unmarshal([]byte(his.Iinfo), &rf)
  1884. chrg_bchno := chrg_bchno
  1885. cert_no := his.Certno
  1886. var insutypes []string
  1887. var insutype string
  1888. var is390 int = 0
  1889. var is310 int = 0
  1890. for _, item := range rf {
  1891. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1892. insutypes = append(insutypes, item.Insutype)
  1893. }
  1894. }
  1895. if len(insutypes) == 1 {
  1896. insutype = insutypes[0]
  1897. } else {
  1898. for _, i := range insutypes {
  1899. if i == "390" {
  1900. is390 = 1
  1901. }
  1902. if i == "310" {
  1903. is310 = 1
  1904. }
  1905. }
  1906. }
  1907. if is390 == 1 {
  1908. insutype = "390"
  1909. }
  1910. if is310 == 1 {
  1911. insutype = "310"
  1912. }
  1913. if len(insutypes) == 0 {
  1914. insutype = "310"
  1915. }
  1916. if his.IdCardType == 1 {
  1917. cert_no = his.MedicalInsuranceNumber
  1918. } else {
  1919. cert_no = his.Certno
  1920. }
  1921. result, src_resquest := service.Gdyb2207(his.PsnNo, his.Number, chrg_bchno, cert_no, insutype, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, strconv.FormatInt(patientPrescription.RegisterType, 10), his.IdCardType, 0, 0, 0, 0, his.IdType)
  1922. var dat map[string]interface{}
  1923. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1924. fmt.Println(dat)
  1925. } else {
  1926. fmt.Println(err)
  1927. }
  1928. userJSONBytes, _ := json.Marshal(dat)
  1929. var res ResultSeven
  1930. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1931. utils.ErrorLog("解析失败:%v", err)
  1932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1933. return
  1934. }
  1935. if res.Infcode == -1 {
  1936. errlog := &models.HisOrderError{
  1937. UserOrgId: adminUser.CurrentOrgId,
  1938. Ctime: time.Now().Unix(),
  1939. Mtime: time.Now().Unix(),
  1940. Number: chrg_bchno,
  1941. ErrMsg: res.ErrMsg,
  1942. Status: 1,
  1943. PatientId: id,
  1944. RecordTime: recordDateTime,
  1945. Stage: 6,
  1946. }
  1947. service.CreateErrMsgLog(errlog)
  1948. c.ServeSuccessJSON(map[string]interface{}{
  1949. "failed_code": -10,
  1950. "msg": res.ErrMsg,
  1951. })
  1952. return
  1953. } else {
  1954. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1955. order.OrderStatus = 2
  1956. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1957. order.SetlId = res.Output.Setlinfo.SetlID
  1958. order.PsnNo = res.Output.Setlinfo.PsnNo
  1959. order.PsnName = res.Output.Setlinfo.PsnName
  1960. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1961. order.Certno = res.Output.Setlinfo.Certno
  1962. order.Gend = res.Output.Setlinfo.Gend
  1963. order.Naty = res.Output.Setlinfo.Naty
  1964. order.Age = res.Output.Setlinfo.Age
  1965. order.Insutype = res.Output.Setlinfo.Insutype
  1966. order.PsnType = res.Output.Setlinfo.PsnType
  1967. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1968. order.SetlTime = res.Output.Setlinfo.SetlTime
  1969. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1970. order.MedType = res.Output.Setlinfo.MedType
  1971. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1972. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1973. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1974. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1975. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1976. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1977. order.HifpPay = res.Output.Setlinfo.HifpPay
  1978. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1979. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1980. order.HifesPay = res.Output.Setlinfo.HifesPay
  1981. order.HifobPay = res.Output.Setlinfo.HifobPay
  1982. order.MafPay = res.Output.Setlinfo.MafPay
  1983. order.OthPay = res.Output.Setlinfo.OthPay
  1984. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1985. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1986. order.AcctPay = res.Output.Setlinfo.AcctPay
  1987. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1988. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1989. order.Balc = res.Output.Setlinfo.Balc
  1990. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1991. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1992. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1993. order.ClrWay = res.Output.Setlinfo.ClrWay
  1994. order.Creator = order.Creator
  1995. order.Modify = roles.AdminUserId
  1996. order.RequestLog = src_resquest
  1997. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1998. detailStr := string(setlDetail)
  1999. order.SetlDetail = detailStr
  2000. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2001. err = service.UpDateOrder(order)
  2002. if err == nil {
  2003. c.ServeSuccessJSON(map[string]interface{}{
  2004. "msg": "结算成功",
  2005. })
  2006. } else {
  2007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2008. return
  2009. }
  2010. }
  2011. } else {
  2012. adminUser := c.GetAdminUserInfo()
  2013. errlog := &models.HisOrderError{
  2014. UserOrgId: adminUser.CurrentOrgId,
  2015. Ctime: time.Now().Unix(),
  2016. Mtime: time.Now().Unix(),
  2017. ErrMsg: res.ErrMsg,
  2018. Status: 1,
  2019. PatientId: id,
  2020. RecordTime: recordDateTime,
  2021. Stage: 4,
  2022. }
  2023. service.CreateErrMsgLog(errlog)
  2024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2025. return
  2026. }
  2027. } else {
  2028. adminUser := c.GetAdminUserInfo()
  2029. errlog := &models.HisOrderError{
  2030. UserOrgId: adminUser.CurrentOrgId,
  2031. Ctime: time.Now().Unix(),
  2032. Mtime: time.Now().Unix(),
  2033. ErrMsg: res.ErrMsg,
  2034. Status: 1,
  2035. PatientId: id,
  2036. RecordTime: recordDateTime,
  2037. Stage: 4,
  2038. }
  2039. service.CreateErrMsgLog(errlog)
  2040. c.ServeSuccessJSON(map[string]interface{}{
  2041. "failed_code": -10,
  2042. "msg": res.ErrMsg,
  2043. })
  2044. return
  2045. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  2046. //return
  2047. }
  2048. } else {
  2049. var total float64
  2050. for _, item := range prescriptions {
  2051. if item.Type == 1 { //药品
  2052. for _, subItem := range item.HisDoctorAdviceInfo {
  2053. total = total + (subItem.Price * subItem.PrescribingNumber)
  2054. }
  2055. }
  2056. if item.Type == 2 { //项目
  2057. for _, subItem := range item.HisPrescriptionProject {
  2058. total = total + (subItem.Price * float64(subItem.Count))
  2059. }
  2060. }
  2061. for _, subItem := range item.HisAdditionalCharge {
  2062. total = total + (subItem.Price * float64(subItem.Count))
  2063. }
  2064. }
  2065. allTotal := fmt.Sprintf("%.2f", total)
  2066. totals, _ := strconv.ParseFloat(allTotal, 64)
  2067. order := &models.HisOrder{
  2068. UserOrgId: adminUser.CurrentOrgId,
  2069. HisPatientId: his.ID,
  2070. PatientId: id,
  2071. SettleAccountsDate: recordDateTime,
  2072. Ctime: time.Now().Unix(),
  2073. Mtime: time.Now().Unix(),
  2074. Status: 1,
  2075. OrderStatus: 2,
  2076. Number: chrg_bchno,
  2077. MedfeeSumamt: totals,
  2078. PayWay: pay_way,
  2079. PayPrice: pay_price,
  2080. PayCardNo: pay_card_no,
  2081. DiscountPrice: discount_price,
  2082. PreferentialPrice: preferential_price,
  2083. RealityPrice: reality_price,
  2084. FoundPrice: found_price,
  2085. MedicalInsurancePrice: medical_insurance_price,
  2086. PrivatePrice: private_price,
  2087. }
  2088. err = service.CreateOrder(order)
  2089. if err != nil {
  2090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2091. return
  2092. }
  2093. var customs []*Custom
  2094. for _, item := range prescriptions {
  2095. if item.Type == 1 { //药品
  2096. for _, subItem := range item.HisDoctorAdviceInfo {
  2097. cus := &Custom{
  2098. AdviceId: subItem.ID,
  2099. ProjectId: 0,
  2100. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  2101. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  2102. FeedetlSn: subItem.FeedetlSn,
  2103. Price: fmt.Sprintf("%.2f", subItem.Price),
  2104. MedListCodg: subItem.MedListCodg,
  2105. Type: 1,
  2106. }
  2107. customs = append(customs, cus)
  2108. }
  2109. }
  2110. if item.Type == 2 { //项目
  2111. for _, subItem := range item.HisPrescriptionProject {
  2112. cus := &Custom{
  2113. AdviceId: 0,
  2114. ProjectId: subItem.ID,
  2115. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  2116. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  2117. FeedetlSn: subItem.FeedetlSn,
  2118. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  2119. MedListCodg: subItem.MedListCodg,
  2120. Type: 2,
  2121. }
  2122. customs = append(customs, cus)
  2123. }
  2124. }
  2125. for _, item := range item.HisAdditionalCharge {
  2126. cus := &Custom{
  2127. ItemId: item.ID,
  2128. AdviceId: 0,
  2129. ProjectId: 0,
  2130. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  2131. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  2132. FeedetlSn: item.FeedetlSn,
  2133. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  2134. MedListCodg: item.XtHisAddtionConfig.Code,
  2135. Type: 3,
  2136. }
  2137. customs = append(customs, cus)
  2138. }
  2139. }
  2140. for _, item := range customs {
  2141. var advice_id int64 = 0
  2142. var project_id int64 = 0
  2143. var item_id int64 = 0
  2144. var types int64 = 0
  2145. if item.Type == 1 {
  2146. advice_id = item.AdviceId
  2147. project_id = 0
  2148. item_id = 0
  2149. } else if item.Type == 2 {
  2150. advice_id = 0
  2151. item_id = 0
  2152. project_id = item.ProjectId
  2153. } else if item.Type == 3 {
  2154. advice_id = 0
  2155. item_id = item.ItemId
  2156. project_id = 0
  2157. }
  2158. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  2159. cut, _ := strconv.ParseFloat(item.Cut, 32)
  2160. pric, _ := strconv.ParseFloat(item.Price, 32)
  2161. info := &models.HisOrderInfo{
  2162. OrderNumber: order.Number,
  2163. UploadDate: time.Now().Unix(),
  2164. AdviceId: advice_id,
  2165. DetItemFeeSumamt: detItemFeeSumamt,
  2166. Cnt: cut,
  2167. Pric: pric,
  2168. PatientId: id,
  2169. Status: 1,
  2170. Mtime: time.Now().Unix(),
  2171. Ctime: time.Now().Unix(),
  2172. UserOrgId: adminUser.CurrentOrgId,
  2173. HisPatientId: his.ID,
  2174. OrderId: order.ID,
  2175. ProjectId: project_id,
  2176. Type: types,
  2177. ItemId: item_id,
  2178. }
  2179. service.CreateOrderInfo(info)
  2180. }
  2181. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2182. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2183. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  2184. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2185. if err == nil {
  2186. c.ServeSuccessJSON(map[string]interface{}{
  2187. "msg": "结算成功",
  2188. })
  2189. } else {
  2190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2191. return
  2192. }
  2193. }
  2194. }
  2195. func (c *HisApiController) GetPreUploadInfo() {
  2196. id, _ := c.GetInt64("id")
  2197. record_time := c.GetString("record_time")
  2198. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2199. admin_user_id, _ := c.GetInt64("admin_user_id")
  2200. timeLayout := "2006-01-02"
  2201. loc, _ := time.LoadLocation("Local")
  2202. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2203. if err != nil {
  2204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2205. return
  2206. }
  2207. recordDateTime := theTime.Unix()
  2208. adminUser := c.GetAdminUserInfo()
  2209. var prescriptions []*models.HisPrescription
  2210. var start_time int64
  2211. var end_time int64
  2212. data := make(map[string]interface{})
  2213. if settle_accounts_type == 1 { //日结
  2214. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  2215. data["pre"] = prescriptions
  2216. } else { //月结
  2217. start_time_str := c.GetString("start_time")
  2218. end_time_str := c.GetString("end_time")
  2219. timeLayout := "2006-01-02"
  2220. loc, _ := time.LoadLocation("Local")
  2221. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2222. if err != nil {
  2223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2224. return
  2225. }
  2226. recordStartTime := theStartTime.Unix()
  2227. start_time = recordStartTime
  2228. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2229. if err != nil {
  2230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2231. return
  2232. }
  2233. recordEndTime := theEndTime.Unix()
  2234. end_time = recordEndTime
  2235. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  2236. data["pre"] = prescriptions
  2237. }
  2238. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2239. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2240. timestamp := time.Now().Unix()
  2241. tempTime := time.Unix(timestamp, 0)
  2242. timeFormat := tempTime.Format("20060102150405")
  2243. chrgBchno := rand.Intn(100000) + 10000
  2244. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  2245. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2246. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2247. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  2248. strconv.FormatInt(his.PatientId, 10)
  2249. client := &http.Client{}
  2250. data["psn_no"] = his.PsnNo
  2251. data["mdtrt_id"] = his.Number
  2252. data["chrg_bchno"] = chrg_bchno
  2253. data["org_name"] = miConfig.OrgName
  2254. data["doctor"] = roles.UserName
  2255. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  2256. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  2257. data["fixmedins_code"] = miConfig.Code
  2258. data["dept_code"] = department.Number
  2259. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  2260. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  2261. data["secret_key"] = miConfig.SecretKey
  2262. var ids []int64
  2263. for _, item := range prescriptions {
  2264. ids = append(ids, item.ID)
  2265. }
  2266. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2267. if config.IsOpen == 1 { //对接了医保,走医保流程
  2268. bytesData, _ := json.Marshal(data)
  2269. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  2270. resp, _ := client.Do(req)
  2271. defer resp.Body.Close()
  2272. body, ioErr := ioutil.ReadAll(resp.Body)
  2273. if ioErr != nil {
  2274. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2276. return
  2277. }
  2278. var respJSON map[string]interface{}
  2279. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  2280. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2282. return
  2283. }
  2284. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2285. userJSONBytes, _ := json.Marshal(respJSON)
  2286. var res ResultFour
  2287. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2288. utils.ErrorLog("解析失败:%v", err)
  2289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2290. return
  2291. }
  2292. if res.Infcode == 0 {
  2293. order := &models.HisOrder{
  2294. UserOrgId: adminUser.CurrentOrgId,
  2295. HisPatientId: his.ID,
  2296. PatientId: his.PatientId,
  2297. SettleAccountsDate: recordDateTime,
  2298. Ctime: time.Now().Unix(),
  2299. Mtime: time.Now().Unix(),
  2300. Status: 1,
  2301. Number: chrg_bchno,
  2302. Infcode: res.Infcode,
  2303. WarnMsg: res.WarnMsg,
  2304. Cainfo: res.Cainfo,
  2305. ErrMsg: res.ErrMsg,
  2306. RespondTime: res.RefmsgTime,
  2307. InfRefmsgid: res.InfRefmsgid,
  2308. OrderStatus: 1,
  2309. IsMedicineInsurance: 1,
  2310. SettleType: settle_accounts_type,
  2311. SettleStartTime: start_time,
  2312. SettleEndTime: end_time,
  2313. Creator: roles.ID,
  2314. Modify: roles.ID,
  2315. }
  2316. err = service.CreateOrder(order)
  2317. if err != nil {
  2318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2319. return
  2320. }
  2321. for _, item := range res.Output.Result {
  2322. temp := strings.Split(item.FeedetlSn, "-")
  2323. var advice_id int64 = 0
  2324. var project_id int64 = 0
  2325. var types int64 = 0
  2326. id, _ := strconv.ParseInt(temp[2], 10, 64)
  2327. types, _ = strconv.ParseInt(temp[1], 10, 64)
  2328. if temp[1] == "1" {
  2329. advice_id = id
  2330. project_id = 0
  2331. } else if temp[1] == "2" {
  2332. advice_id = 0
  2333. project_id = id
  2334. }
  2335. info := &models.HisOrderInfo{
  2336. OrderNumber: order.Number,
  2337. FeedetlSn: item.FeedetlSn,
  2338. UploadDate: time.Now().Unix(),
  2339. AdviceId: advice_id,
  2340. DetItemFeeSumamt: item.DetItemFeeSumamt,
  2341. Cnt: item.Cnt,
  2342. Pric: float64(item.Pric),
  2343. PatientId: his.PatientId,
  2344. PricUplmtAmt: item.PricUplmtAmt,
  2345. SelfpayProp: item.SelfpayProp,
  2346. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2347. OverlmtAmt: item.OverlmtAmt,
  2348. PreselfpayAmt: item.PreselfpayAmt,
  2349. BasMednFlag: item.BasMednFlag,
  2350. MedChrgitmType: item.MedChrgitmType,
  2351. HiNegoDrugFlag: item.HiNegoDrugFlag,
  2352. Status: 1,
  2353. Memo: item.Memo,
  2354. Mtime: time.Now().Unix(),
  2355. InscpScpAmt: item.InscpScpAmt,
  2356. DrtReimFlag: item.DrtReimFlag,
  2357. Ctime: time.Now().Unix(),
  2358. ListSpItemFlag: item.ListSpItemFlag,
  2359. ChldMedcFlag: item.ChldMedcFlag,
  2360. LmtUsedFlag: item.LmtUsedFlag,
  2361. ChrgitmLv: item.ChrgitmLv,
  2362. UserOrgId: adminUser.CurrentOrgId,
  2363. HisPatientId: his.ID,
  2364. OrderId: order.ID,
  2365. ProjectId: project_id,
  2366. Type: types,
  2367. }
  2368. service.CreateOrderInfo(info)
  2369. }
  2370. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2371. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  2372. var total float64
  2373. for _, item := range prescriptions {
  2374. if item.Type == 1 { //药品
  2375. for _, subItem := range item.HisDoctorAdviceInfo {
  2376. total = total + (subItem.Price * subItem.PrescribingNumber)
  2377. }
  2378. }
  2379. if item.Type == 2 { //项目
  2380. for _, subItem := range item.HisPrescriptionProject {
  2381. total = total + (subItem.Price * float64(subItem.Count))
  2382. }
  2383. }
  2384. }
  2385. for _, item := range prescriptions {
  2386. for _, subItem := range item.HisAdditionalCharge {
  2387. total = total + (subItem.Price * float64(subItem.Count))
  2388. }
  2389. }
  2390. allTotal := fmt.Sprintf("%.2f", total)
  2391. if res.Infcode == 0 {
  2392. var rf []*ResultFive
  2393. json.Unmarshal([]byte(his.Iinfo), &rf)
  2394. psn_no := his.PsnNo
  2395. mdtrt_id := his.Number
  2396. chrg_bchno := chrg_bchno
  2397. cert_no := his.Certno
  2398. insutype := rf[0].Insutype
  2399. if his.IdCardType == 1 {
  2400. cert_no = his.MedicalInsuranceNumber
  2401. } else {
  2402. cert_no = his.Certno
  2403. }
  2404. api := "http://127.0.0.1:9532/" + "gdyb/seven?cert_no=" + cert_no + "&insutype=" +
  2405. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  2406. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  2407. miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10)
  2408. resp, requestErr := http.Get(api)
  2409. if requestErr != nil {
  2410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2411. return
  2412. }
  2413. defer resp.Body.Close()
  2414. body, ioErr := ioutil.ReadAll(resp.Body)
  2415. if ioErr != nil {
  2416. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2418. return
  2419. }
  2420. var respJSON map[string]interface{}
  2421. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2422. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2424. return
  2425. }
  2426. fmt.Println(respJSON)
  2427. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2428. userJSONBytes, _ := json.Marshal(respJSON)
  2429. var res ResultSeven
  2430. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2431. utils.ErrorLog("解析失败:%v", err)
  2432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2433. return
  2434. }
  2435. if res.Infcode == -1 {
  2436. errlog := &models.HisOrderError{
  2437. UserOrgId: adminUser.CurrentOrgId,
  2438. Ctime: time.Now().Unix(),
  2439. Mtime: time.Now().Unix(),
  2440. Number: chrg_bchno,
  2441. ErrMsg: res.ErrMsg,
  2442. Status: 1,
  2443. PatientId: id,
  2444. RecordTime: recordDateTime,
  2445. Stage: 7,
  2446. }
  2447. service.CreateErrMsgLog(errlog)
  2448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2449. return
  2450. } else {
  2451. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2452. order.OrderStatus = 1
  2453. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2454. order.SetlId = res.Output.Setlinfo.SetlID
  2455. order.PsnNo = res.Output.Setlinfo.PsnNo
  2456. order.PsnName = res.Output.Setlinfo.PsnName
  2457. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2458. order.Certno = res.Output.Setlinfo.Certno
  2459. order.Gend = res.Output.Setlinfo.Gend
  2460. order.Naty = res.Output.Setlinfo.Naty
  2461. order.Age = res.Output.Setlinfo.Age
  2462. order.Insutype = res.Output.Setlinfo.Insutype
  2463. order.PsnType = res.Output.Setlinfo.PsnType
  2464. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2465. order.SetlTime = res.Output.Setlinfo.SetlTime
  2466. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2467. order.MedType = res.Output.Setlinfo.MedType
  2468. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2469. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2470. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2471. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2472. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2473. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2474. order.HifpPay = res.Output.Setlinfo.HifpPay
  2475. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2476. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2477. order.HifesPay = res.Output.Setlinfo.HifesPay
  2478. order.HifobPay = res.Output.Setlinfo.HifobPay
  2479. order.MafPay = res.Output.Setlinfo.MafPay
  2480. order.OthPay = res.Output.Setlinfo.OthPay
  2481. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2482. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2483. order.AcctPay = res.Output.Setlinfo.AcctPay
  2484. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2485. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2486. order.Balc = res.Output.Setlinfo.Balc
  2487. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2488. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2489. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2490. order.ClrWay = res.Output.Setlinfo.ClrWay
  2491. order.Creator = order.Creator
  2492. order.Modify = roles.ID
  2493. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2494. detailStr := string(setlDetail)
  2495. order.SetlDetail = detailStr
  2496. //err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2497. err = service.UpDateOrder(order)
  2498. if err == nil {
  2499. c.ServeSuccessJSON(map[string]interface{}{
  2500. "msg": "预结算成功",
  2501. })
  2502. } else {
  2503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2504. return
  2505. }
  2506. }
  2507. } else {
  2508. adminUser := c.GetAdminUserInfo()
  2509. errlog := &models.HisOrderError{
  2510. UserOrgId: adminUser.CurrentOrgId,
  2511. Ctime: time.Now().Unix(),
  2512. Mtime: time.Now().Unix(),
  2513. ErrMsg: res.ErrMsg,
  2514. Status: 1,
  2515. PatientId: id,
  2516. RecordTime: recordDateTime,
  2517. Stage: 4,
  2518. }
  2519. service.CreateErrMsgLog(errlog)
  2520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2521. return
  2522. }
  2523. } else {
  2524. adminUser := c.GetAdminUserInfo()
  2525. errlog := &models.HisOrderError{
  2526. UserOrgId: adminUser.CurrentOrgId,
  2527. Ctime: time.Now().Unix(),
  2528. Mtime: time.Now().Unix(),
  2529. ErrMsg: res.ErrMsg,
  2530. Status: 1,
  2531. PatientId: id,
  2532. RecordTime: recordDateTime,
  2533. Stage: 4,
  2534. }
  2535. service.CreateErrMsgLog(errlog)
  2536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  2537. return
  2538. }
  2539. } else {
  2540. var total float64
  2541. for _, item := range prescriptions {
  2542. if item.Type == 1 { //药品
  2543. for _, subItem := range item.HisDoctorAdviceInfo {
  2544. total = total + (subItem.Price * subItem.PrescribingNumber)
  2545. }
  2546. }
  2547. if item.Type == 2 { //项目
  2548. for _, subItem := range item.HisPrescriptionProject {
  2549. total = total + (subItem.Price * float64(subItem.Count))
  2550. }
  2551. }
  2552. for _, subItem := range item.HisAdditionalCharge {
  2553. total = total + (subItem.Price * float64(subItem.Count))
  2554. }
  2555. }
  2556. allTotal := fmt.Sprintf("%.2f", total)
  2557. totals, _ := strconv.ParseFloat(allTotal, 64)
  2558. order := &models.HisOrder{
  2559. UserOrgId: adminUser.CurrentOrgId,
  2560. HisPatientId: his.ID,
  2561. PatientId: id,
  2562. SettleAccountsDate: recordDateTime,
  2563. Ctime: time.Now().Unix(),
  2564. Mtime: time.Now().Unix(),
  2565. Status: 1,
  2566. OrderStatus: 2,
  2567. Number: chrg_bchno,
  2568. MedfeeSumamt: totals,
  2569. }
  2570. err = service.CreateOrder(order)
  2571. if err != nil {
  2572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2573. return
  2574. }
  2575. var customs []*Custom
  2576. for _, item := range prescriptions {
  2577. if item.Type == 1 { //药品
  2578. for _, subItem := range item.HisDoctorAdviceInfo {
  2579. cus := &Custom{
  2580. AdviceId: subItem.ID,
  2581. ProjectId: 0,
  2582. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  2583. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  2584. FeedetlSn: subItem.FeedetlSn,
  2585. Price: fmt.Sprintf("%.2f", subItem.Price),
  2586. MedListCodg: subItem.MedListCodg,
  2587. Type: 1,
  2588. }
  2589. customs = append(customs, cus)
  2590. }
  2591. }
  2592. if item.Type == 2 { //项目
  2593. for _, subItem := range item.HisPrescriptionProject {
  2594. cus := &Custom{
  2595. AdviceId: 0,
  2596. ProjectId: subItem.ID,
  2597. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  2598. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  2599. FeedetlSn: subItem.FeedetlSn,
  2600. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  2601. MedListCodg: subItem.MedListCodg,
  2602. Type: 2,
  2603. }
  2604. customs = append(customs, cus)
  2605. }
  2606. }
  2607. for _, item := range item.HisAdditionalCharge {
  2608. cus := &Custom{
  2609. ItemId: item.ID,
  2610. AdviceId: 0,
  2611. ProjectId: 0,
  2612. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  2613. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  2614. FeedetlSn: item.FeedetlSn,
  2615. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  2616. MedListCodg: item.XtHisAddtionConfig.Code,
  2617. Type: 3,
  2618. }
  2619. customs = append(customs, cus)
  2620. }
  2621. }
  2622. for _, item := range customs {
  2623. var advice_id int64 = 0
  2624. var project_id int64 = 0
  2625. var item_id int64 = 0
  2626. var types int64 = 0
  2627. if item.Type == 1 {
  2628. advice_id = item.AdviceId
  2629. project_id = 0
  2630. item_id = 0
  2631. } else if item.Type == 2 {
  2632. advice_id = 0
  2633. item_id = 0
  2634. project_id = item.ProjectId
  2635. } else if item.Type == 3 {
  2636. advice_id = 0
  2637. item_id = item.ItemId
  2638. project_id = 0
  2639. }
  2640. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  2641. cut, _ := strconv.ParseFloat(item.Cut, 32)
  2642. pric, _ := strconv.ParseFloat(item.Price, 32)
  2643. info := &models.HisOrderInfo{
  2644. OrderNumber: order.Number,
  2645. UploadDate: time.Now().Unix(),
  2646. AdviceId: advice_id,
  2647. DetItemFeeSumamt: detItemFeeSumamt,
  2648. Cnt: cut,
  2649. Pric: pric,
  2650. PatientId: id,
  2651. Status: 1,
  2652. Mtime: time.Now().Unix(),
  2653. Ctime: time.Now().Unix(),
  2654. UserOrgId: adminUser.CurrentOrgId,
  2655. HisPatientId: his.ID,
  2656. OrderId: order.ID,
  2657. ProjectId: project_id,
  2658. Type: types,
  2659. ItemId: item_id,
  2660. }
  2661. service.CreateOrderInfo(info)
  2662. }
  2663. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2664. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2665. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  2666. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2667. if err == nil {
  2668. c.ServeSuccessJSON(map[string]interface{}{
  2669. "msg": "结算成功",
  2670. })
  2671. } else {
  2672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2673. return
  2674. }
  2675. }
  2676. }
  2677. //func (c *HisApiController) GetSettleInfo() {
  2678. // id, _ := c.GetInt64("id")
  2679. // order_id, _ := c.GetInt64("order_id")
  2680. //
  2681. // record_time := c.GetString("record_time")
  2682. // pay_way, _ := c.GetInt64("pay_way")
  2683. // pay_price, _ := c.GetFloat("pay_price")
  2684. // pay_card_no := c.GetString("pay_card_no")
  2685. // discount_price, _ := c.GetFloat("discount_price")
  2686. // preferential_price, _ := c.GetFloat("preferential_price")
  2687. // reality_price, _ := c.GetFloat("reality_price")
  2688. // found_price, _ := c.GetFloat("found_price")
  2689. // medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2690. // private_price, _ := c.GetFloat("private_price")
  2691. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2692. // admin_user_id, _ := c.GetInt64("admin_user_id")
  2693. //
  2694. // timeLayout := "2006-01-02"
  2695. // loc, _ := time.LoadLocation("Local")
  2696. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2697. // if err != nil {
  2698. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2699. // return
  2700. // }
  2701. // recordDateTime := theTime.Unix()
  2702. // adminUser := c.GetAdminUserInfo()
  2703. //
  2704. // var prescriptions []*models.HisPrescription
  2705. //
  2706. // data := make(map[string]interface{})
  2707. // if settle_accounts_type == 1 { //日结
  2708. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  2709. // data["pre"] = prescriptions
  2710. //
  2711. // } else { //月结
  2712. // start_time_str := c.GetString("start_time")
  2713. // end_time_str := c.GetString("end_time")
  2714. // timeLayout := "2006-01-02"
  2715. // loc, _ := time.LoadLocation("Local")
  2716. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2717. // if err != nil {
  2718. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2719. // return
  2720. // }
  2721. // recordStartTime := theStartTime.Unix()
  2722. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2723. // if err != nil {
  2724. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2725. // return
  2726. // }
  2727. // recordEndTime := theEndTime.Unix()
  2728. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  2729. // data["pre"] = prescriptions
  2730. //
  2731. // }
  2732. //
  2733. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2734. //
  2735. // his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2736. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2737. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2738. // strconv.FormatInt(his.PatientId, 10)
  2739. //
  2740. // order_src, _ := service.GetHisOrderByID(order_id)
  2741. //
  2742. // config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2743. // if config.IsOpen == 1 { //对接了医保,走医保流程
  2744. //
  2745. // var total float64
  2746. // for _, item := range prescriptions {
  2747. // if item.Type == 1 { //药品
  2748. // for _, subItem := range item.HisDoctorAdviceInfo {
  2749. // total = total + (subItem.Price * subItem.PrescribingNumber)
  2750. // }
  2751. // }
  2752. // if item.Type == 2 { //项目
  2753. // for _, subItem := range item.HisPrescriptionProject {
  2754. // total = total + (subItem.Price * float64(subItem.Count))
  2755. // }
  2756. // }
  2757. // }
  2758. //
  2759. // for _, item := range prescriptions {
  2760. // for _, subItem := range item.HisAdditionalCharge {
  2761. // total = total + (subItem.Price * float64(subItem.Count))
  2762. // }
  2763. // }
  2764. //
  2765. // allTotal := fmt.Sprintf("%.2f", total)
  2766. // var rf []*ResultFive
  2767. // json.Unmarshal([]byte(his.Iinfo), &rf)
  2768. // psn_no := order_src.PsnNo
  2769. // mdtrt_id := order_src.MdtrtId
  2770. // chrg_bchno := order_src.Number
  2771. // cert_no := order_src.Certno
  2772. // insutype := rf[0].Insutype
  2773. //
  2774. // if his.IdCardType == 1 {
  2775. // cert_no = his.MedicalInsuranceNumber
  2776. // } else {
  2777. // cert_no = his.Certno
  2778. // }
  2779. //
  2780. // result, src_resquest := service.Gdyb2207(his.PsnNo, his.Number, chrg_bchno, cert_no, insutype, strconv.FormatFloat(total, 'E', -1, 64) ,miConfig.OrgName,roles.UserName,miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, strconv.FormatInt(patientPrescription.RegisterType, 10),his.IdCardType, order_src.FulamtOwnpayAmt,order_src.OverlmtSelfPay,order_src.PreselfpayAmt,order_src.InscpScpAmt)
  2781. // var dat map[string]interface{}
  2782. // if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2783. // fmt.Println(dat)
  2784. // } else {
  2785. // fmt.Println(err)
  2786. // }
  2787. //
  2788. // userJSONBytes, _ := json.Marshal(dat)
  2789. //
  2790. //
  2791. //
  2792. // var res ResultSeven
  2793. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2794. // utils.ErrorLog("解析失败:%v", err)
  2795. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2796. // return
  2797. // }
  2798. // if res.Infcode == -1 {
  2799. // errlog := &models.HisOrderError{
  2800. // UserOrgId: adminUser.CurrentOrgId,
  2801. // Ctime: time.Now().Unix(),
  2802. // Mtime: time.Now().Unix(),
  2803. // Number: chrg_bchno,
  2804. // ErrMsg: res.ErrMsg,
  2805. // Status: 1,
  2806. // PatientId: id,
  2807. // RecordTime: recordDateTime,
  2808. // Stage: 6,
  2809. // }
  2810. // service.CreateErrMsgLog(errlog)
  2811. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2812. // return
  2813. // } else {
  2814. // order_src.OrderStatus = 2
  2815. // order_src.PayWay = pay_way
  2816. // order_src.PayPrice = pay_price
  2817. // order_src.PayCardNo = pay_card_no
  2818. // order_src.DiscountPrice = discount_price
  2819. // order_src.PreferentialPrice = preferential_price
  2820. // order_src.RealityPrice = reality_price
  2821. // order_src.FoundPrice = found_price
  2822. // order_src.MedicalInsurancePrice = medical_insurance_price
  2823. // order_src.PrivatePrice = private_price
  2824. // order_src.MdtrtId = res.Output.Setlinfo.MdtrtID
  2825. // order_src.SetlId = res.Output.Setlinfo.SetlID
  2826. // order_src.PsnNo = res.Output.Setlinfo.PsnNo
  2827. // order_src.PsnName = res.Output.Setlinfo.PsnName
  2828. // order_src.PsnCertType = res.Output.Setlinfo.PsnCertType
  2829. // order_src.Certno = res.Output.Setlinfo.Certno
  2830. // order_src.Gend = res.Output.Setlinfo.Gend
  2831. // order_src.Naty = res.Output.Setlinfo.Naty
  2832. // order_src.Age = res.Output.Setlinfo.Age
  2833. // order_src.Insutype = res.Output.Setlinfo.Insutype
  2834. // order_src.PsnType = res.Output.Setlinfo.PsnType
  2835. // order_src.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2836. // order_src.SetlTime = res.Output.Setlinfo.SetlTime
  2837. // order_src.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2838. // order_src.MedType = res.Output.Setlinfo.MedType
  2839. // order_src.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2840. // order_src.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2841. // order_src.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2842. // order_src.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2843. // order_src.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2844. // order_src.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2845. // order_src.HifpPay = res.Output.Setlinfo.HifpPay
  2846. // order_src.CvlservPay = res.Output.Setlinfo.CvlservPay
  2847. // order_src.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2848. // order_src.HifesPay = res.Output.Setlinfo.HifesPay
  2849. // order_src.HifobPay = res.Output.Setlinfo.HifobPay
  2850. // order_src.MafPay = res.Output.Setlinfo.MafPay
  2851. // order_src.OthPay = res.Output.Setlinfo.OthPay
  2852. // order_src.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2853. // order_src.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2854. // order_src.AcctPay = res.Output.Setlinfo.AcctPay
  2855. // order_src.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2856. // order_src.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2857. // order_src.Balc = res.Output.Setlinfo.Balc
  2858. // order_src.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2859. // order_src.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2860. // order_src.ClrOptins = res.Output.Setlinfo.ClrOptins
  2861. // order_src.ClrWay = res.Output.Setlinfo.ClrWay
  2862. // order_src.Creator = order_src.Creator
  2863. // order_src.Modify = roles.ID
  2864. // order_src.RequestLog = src_resquest
  2865. // setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2866. // detailStr := string(setlDetail)
  2867. // order_src.SetlDetail = detailStr
  2868. // err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2869. // err = service.UpDateOrder(order_src)
  2870. //
  2871. // if err == nil {
  2872. // c.ServeSuccessJSON(map[string]interface{}{
  2873. // "msg": "结算成功",
  2874. // })
  2875. // } else {
  2876. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2877. // return
  2878. // }
  2879. // }
  2880. // }
  2881. //}
  2882. //退款
  2883. func (c *HisApiController) Refund() {
  2884. order_id, _ := c.GetInt64("order_id")
  2885. admin_user_id, _ := c.GetInt64("admin_user_id")
  2886. record_time := c.GetString("record_time")
  2887. patient_id, _ := c.GetInt64("patient_id")
  2888. timeLayout := "2006-01-02"
  2889. loc, _ := time.LoadLocation("Local")
  2890. adminUser := c.GetAdminUserInfo()
  2891. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2892. if err != nil {
  2893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2894. return
  2895. }
  2896. recordDateTime := theTime.Unix()
  2897. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2898. var order models.HisOrder
  2899. order, _ = service.GetHisOrderByID(order_id)
  2900. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2901. if order.ID == 0 {
  2902. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  2903. }
  2904. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2905. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2906. if config.IsOpen == 1 { //对接了医保,走医保流程
  2907. result, src_resquest := service.Gdyb2208(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2908. var dat map[string]interface{}
  2909. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2910. fmt.Println(dat)
  2911. } else {
  2912. fmt.Println(err)
  2913. }
  2914. userJSONBytes, _ := json.Marshal(dat)
  2915. var res ResultSixteen
  2916. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2917. utils.ErrorLog("解析失败:%v", err)
  2918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2919. return
  2920. }
  2921. if res.Infcode == 0 {
  2922. result := service.Gdyb2205(order.PsnNo, order.MdtrtId, order.Number, miConfig.OrgName, roles.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  2923. var dat map[string]interface{}
  2924. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2925. fmt.Println(dat)
  2926. } else {
  2927. fmt.Println(err)
  2928. }
  2929. userJSONBytes, _ := json.Marshal(dat)
  2930. var res2 ResultSix
  2931. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2932. utils.ErrorLog("解析失败:%v", err)
  2933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2934. return
  2935. }
  2936. if res2.Infcode == 0 {
  2937. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, src_resquest, result)
  2938. if err == nil {
  2939. c.ServeSuccessJSON(map[string]interface{}{
  2940. "msg": "退费成功",
  2941. })
  2942. } else {
  2943. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2944. return
  2945. }
  2946. } else {
  2947. c.ServeSuccessJSON(map[string]interface{}{
  2948. "code": -10,
  2949. "msg": res2.ErrMsg,
  2950. })
  2951. }
  2952. } else {
  2953. c.ServeSuccessJSON(map[string]interface{}{
  2954. "code": -10,
  2955. "msg": res.ErrMsg,
  2956. })
  2957. }
  2958. } else {
  2959. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  2960. if err == nil {
  2961. c.ServeSuccessJSON(map[string]interface{}{
  2962. "msg": "退费成功",
  2963. })
  2964. } else {
  2965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2966. return
  2967. }
  2968. }
  2969. }
  2970. func (c *HisApiController) RefundNumber() {
  2971. record_time := c.GetString("record_time")
  2972. patient_id, _ := c.GetInt64("patient_id")
  2973. admin_user_id, _ := c.GetInt64("admin_user_id")
  2974. //his_patient_id, _ := c.GetInt64("id")
  2975. timeLayout := "2006-01-02"
  2976. loc, _ := time.LoadLocation("Local")
  2977. adminUser := c.GetAdminUserInfo()
  2978. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2979. fmt.Println(err)
  2980. if err != nil {
  2981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2982. return
  2983. }
  2984. recordDateTime := theTime.Unix()
  2985. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2986. //his, _ := service.GetNewHisPatientRecord(adminUser.CurrentOrgId, patient_id)
  2987. //patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2988. //order, _ := service.GetHisOrderByID(order_id)
  2989. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2990. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2991. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2992. if config.IsOpen == 1 { //对接了医保,走医保流程
  2993. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  2994. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + roles.UserName + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2995. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2996. resp3, requestErr3 := http.Get(api3)
  2997. if requestErr3 != nil {
  2998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2999. return
  3000. }
  3001. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  3002. if ioErr3 != nil {
  3003. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  3004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3005. return
  3006. }
  3007. var respJSON3 map[string]interface{}
  3008. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  3009. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3011. return
  3012. }
  3013. respJSON3 = respJSON3["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3014. userJSONBytes3, _ := json.Marshal(respJSON3)
  3015. var res2 ResultSix
  3016. if err := json.Unmarshal(userJSONBytes3, &res2); err != nil {
  3017. utils.ErrorLog("解析失败:%v", err)
  3018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3019. return
  3020. }
  3021. if res2.Infcode == 0 {
  3022. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  3023. service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  3024. //err := service.UpdataRegStatus2()
  3025. if err == nil {
  3026. c.ServeSuccessJSON(map[string]interface{}{
  3027. "msg": "退号成功",
  3028. })
  3029. } else {
  3030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3031. return
  3032. }
  3033. } else {
  3034. c.ServeSuccessJSON(map[string]interface{}{
  3035. "code": -10,
  3036. "msg": res2.ErrMsg,
  3037. })
  3038. }
  3039. } else {
  3040. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  3041. //if err == nil {
  3042. // c.ServeSuccessJSON(map[string]interface{}{
  3043. // "msg": "退费成功",
  3044. // })
  3045. //} else {
  3046. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3047. // return
  3048. //}
  3049. }
  3050. }
  3051. func (c *HisApiController) RefundDetail() {
  3052. order_id, _ := c.GetInt64("order_id")
  3053. his_patient_id, _ := c.GetInt64("his_patient_id")
  3054. number := c.GetString("number")
  3055. record_time := c.GetString("record_time")
  3056. patient_id, _ := c.GetInt64("patient_id")
  3057. timeLayout := "2006-01-02"
  3058. loc, _ := time.LoadLocation("Local")
  3059. adminUser := c.GetAdminUserInfo()
  3060. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3061. fmt.Println(err)
  3062. if err != nil {
  3063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3064. return
  3065. }
  3066. recordDateTime := theTime.Unix()
  3067. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  3068. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3069. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3070. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3071. var order models.HisOrder
  3072. order, _ = service.GetHisOrderByID(order_id)
  3073. if order.ID == 0 {
  3074. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  3075. }
  3076. if config.IsOpen == 1 { //对接了医保,走医保流程
  3077. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  3078. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  3079. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3080. resp2, requestErr2 := http.Get(api2)
  3081. if requestErr2 != nil {
  3082. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3083. return
  3084. }
  3085. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  3086. if ioErr2 != nil {
  3087. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  3088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3089. return
  3090. }
  3091. var respJSON2 map[string]interface{}
  3092. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  3093. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3094. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3095. return
  3096. }
  3097. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId, "", "")
  3098. if err == nil {
  3099. c.ServeSuccessJSON(map[string]interface{}{
  3100. "msg": "退费成功",
  3101. })
  3102. } else {
  3103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3104. return
  3105. }
  3106. } else {
  3107. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId, "", "")
  3108. if err == nil {
  3109. c.ServeSuccessJSON(map[string]interface{}{
  3110. "msg": "退费成功",
  3111. })
  3112. } else {
  3113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3114. return
  3115. }
  3116. }
  3117. }
  3118. //对账
  3119. func (c *HisApiController) GetCheckAccount() {
  3120. start_time := c.GetString("start_time")
  3121. end_time := c.GetString("end_time")
  3122. insutype := c.GetString("insutype")
  3123. clr_type := c.GetString("clr_type")
  3124. admin_user_id, _ := c.GetInt64("admin_user_id")
  3125. adminUser := c.GetAdminUserInfo()
  3126. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3127. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3128. timeLayout := "2006-01-02"
  3129. loc, _ := time.LoadLocation("Local")
  3130. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3131. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3132. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  3133. //orders_two, _ := service.GetOrderByTimeThree(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  3134. fixmedins_setl_cnt := int64(len(orders))
  3135. //
  3136. ////撤销的算2条数据为一笔
  3137. //for _, item := range orders_two {
  3138. // if item.OrderStatus == 3 {
  3139. // fixmedins_setl_cnt = fixmedins_setl_cnt + 1
  3140. // }
  3141. //}
  3142. var medfee_sumamt float64
  3143. var acct_pay float64
  3144. var fund_pay_sumamt float64
  3145. for _, item := range orders {
  3146. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  3147. acct_pay = acct_pay + item.AcctPay
  3148. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  3149. }
  3150. var user_name string
  3151. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3152. if role.ID == 0 {
  3153. user_name = "xxx"
  3154. } else {
  3155. user_name = role.UserName
  3156. }
  3157. if config.IsOpen == 1 {
  3158. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  3159. "insutype=" + insutype +
  3160. "&clr_type=" + clr_type +
  3161. "&setl_optins=" + "定点医保中心" +
  3162. "&stmt_begndate=" + start_time +
  3163. "&stm_enddate=" + end_time +
  3164. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  3165. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  3166. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  3167. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  3168. "&fixmedins_code=" + miConfig.Code +
  3169. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3170. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3171. "&secret_key=" + miConfig.SecretKey +
  3172. "&org_name=" + miConfig.OrgName +
  3173. "&doctor=" + user_name
  3174. fmt.Println(api)
  3175. resp, requestErr := http.Get(api)
  3176. if requestErr != nil {
  3177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3178. return
  3179. }
  3180. body, ioErr := ioutil.ReadAll(resp.Body)
  3181. fmt.Println(body)
  3182. if ioErr != nil {
  3183. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3185. return
  3186. }
  3187. var respJSON map[string]interface{}
  3188. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3189. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3191. return
  3192. }
  3193. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3194. userJSONBytes, _ := json.Marshal(respJSON)
  3195. var res ResultEight
  3196. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3197. utils.ErrorLog("解析失败:%v", err)
  3198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3199. return
  3200. }
  3201. if res.Infcode == 0 {
  3202. if res.Output.Stmtinfo.StmtRslt == "0" {
  3203. micc := &models.MedicalInsuranceCostCompare{
  3204. StartTime: startime.Unix(),
  3205. EndTime: endtime.Unix(),
  3206. Insutype: insutype,
  3207. CheckType: 1,
  3208. Num: fixmedins_setl_cnt,
  3209. Mtime: time.Now().Unix(),
  3210. Status: 1,
  3211. UserOrgId: adminUser.CurrentOrgId,
  3212. CostTotal: medfee_sumamt,
  3213. FuncTotal: fund_pay_sumamt,
  3214. PsnPay: acct_pay,
  3215. Creator: admin_user_id,
  3216. Ctime: time.Now().Unix(),
  3217. }
  3218. err := service.CreateMedicalInsuranceCostCompareRecord(micc)
  3219. if err == nil {
  3220. c.ServeSuccessJSON(map[string]interface{}{
  3221. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  3222. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  3223. })
  3224. } else {
  3225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3226. }
  3227. } else {
  3228. c.ServeSuccessJSON(map[string]interface{}{
  3229. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  3230. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  3231. })
  3232. }
  3233. } else {
  3234. c.ServeSuccessJSON(map[string]interface{}{
  3235. "code": -10,
  3236. "msg": res.ErrMsg,
  3237. })
  3238. }
  3239. }
  3240. }
  3241. func (c *HisApiController) Check310() {
  3242. adminUser := c.GetAdminUserInfo()
  3243. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3244. var user_name string
  3245. user_name = "xxx"
  3246. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  3247. "insutype=" + "310" +
  3248. "&clr_type=" + "11" +
  3249. "&setl_optins=" + "定点医保中心" +
  3250. "&stmt_begndate=" + "2021-03-01" +
  3251. "&stm_enddate=" + "2021-03-31" +
  3252. "&medfee_sumamt=" + "11521" +
  3253. "&fund_pay_sumamt=" + "10166.66" +
  3254. "&acct_pay=" + "0" +
  3255. "&fixmedins_setl_cnt=" + "7" +
  3256. "&fixmedins_code=" + miConfig.Code +
  3257. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3258. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3259. "&secret_key=" + miConfig.SecretKey +
  3260. "&org_name=" + miConfig.OrgName +
  3261. "&doctor=" + user_name
  3262. fmt.Println(api)
  3263. resp, requestErr := http.Get(api)
  3264. if requestErr != nil {
  3265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3266. return
  3267. }
  3268. body, ioErr := ioutil.ReadAll(resp.Body)
  3269. fmt.Println(body)
  3270. if ioErr != nil {
  3271. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3273. return
  3274. }
  3275. var respJSON map[string]interface{}
  3276. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3277. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3279. return
  3280. }
  3281. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3282. userJSONBytes, _ := json.Marshal(respJSON)
  3283. var res ResultEight
  3284. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3285. utils.ErrorLog("解析失败:%v", err)
  3286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3287. return
  3288. }
  3289. }
  3290. func (c *HisApiController) Check390() {
  3291. adminUser := c.GetAdminUserInfo()
  3292. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3293. var user_name string
  3294. user_name = "张俊杰"
  3295. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  3296. "insutype=" + "390" +
  3297. "&clr_type=" + "11" +
  3298. "&setl_optins=" + "定点医保中心" +
  3299. "&stmt_begndate=" + "2021-03-01" +
  3300. "&stm_enddate=" + "2021-03-31" +
  3301. "&medfee_sumamt=" + "209318.43" +
  3302. "&fund_pay_sumamt=" + "188029.12" +
  3303. "&acct_pay=" + "0" +
  3304. "&fixmedins_setl_cnt=" + "48" +
  3305. "&fixmedins_code=" + miConfig.Code +
  3306. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3307. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3308. "&secret_key=" + miConfig.SecretKey +
  3309. "&org_name=" + miConfig.OrgName +
  3310. "&doctor=" + user_name
  3311. fmt.Println(api)
  3312. resp, requestErr := http.Get(api)
  3313. if requestErr != nil {
  3314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3315. return
  3316. }
  3317. body, ioErr := ioutil.ReadAll(resp.Body)
  3318. fmt.Println(body)
  3319. if ioErr != nil {
  3320. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3322. return
  3323. }
  3324. var respJSON map[string]interface{}
  3325. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3326. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3328. return
  3329. }
  3330. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3331. userJSONBytes, _ := json.Marshal(respJSON)
  3332. var res ResultEight
  3333. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3334. utils.ErrorLog("解析失败:%v", err)
  3335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3336. return
  3337. }
  3338. }
  3339. //对账明细
  3340. func (c *HisApiController) GetCheckDetailAccount() {
  3341. start_time := c.GetString("start_time")
  3342. end_time := c.GetString("end_time")
  3343. admin_user_id, _ := c.GetInt64("admin_user_id")
  3344. adminUser := c.GetAdminUserInfo()
  3345. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3346. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3347. timeLayout := "2006-01-02"
  3348. loc, _ := time.LoadLocation("Local")
  3349. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3350. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3351. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  3352. Mkdir(miConfig.OrgName)
  3353. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  3354. file_name := file + ".txt"
  3355. zip_name := file + ".zip"
  3356. zip_path := miConfig.OrgName + "/" + zip_name
  3357. file_path := miConfig.OrgName + "/" + file_name
  3358. decimal.DivisionPrecision = 2
  3359. var medfee_sumamt float64
  3360. var psn_cash_pay float64
  3361. var fund_pay_sumamt float64
  3362. fixmedins_setl_cnt := int64(len(orders))
  3363. for _, item := range orders {
  3364. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  3365. psn_cash_pay = psn_cash_pay + item.PsnCashPay
  3366. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  3367. }
  3368. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  3369. defer f.Close()
  3370. if err != nil {
  3371. fmt.Println(err.Error())
  3372. } else {
  3373. for _, item := range orders {
  3374. var refd_setl_flag string
  3375. if item.OrderStatus == 2 {
  3376. refd_setl_flag = "0"
  3377. var str string
  3378. str = item.SetlId + " " +
  3379. item.MdtrtId + " " +
  3380. item.PsnNo + " " +
  3381. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  3382. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  3383. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\r\n"
  3384. _, err = f.Write([]byte(str))
  3385. }
  3386. if item.OrderStatus == 3 {
  3387. var str string
  3388. str = item.SetlId + " " +
  3389. item.MdtrtId + " " +
  3390. item.PsnNo + " " +
  3391. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  3392. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  3393. fmt.Sprintf("%.2f", item.AcctPay) + " " + "1" + "\r\n"
  3394. _, err = f.Write([]byte(str))
  3395. var str2 string
  3396. str2 = item.SetlId + " " +
  3397. item.MdtrtId + " " +
  3398. item.PsnNo + " " +
  3399. fmt.Sprintf("%.2f", 0-item.MedfeeSumamt) + " " +
  3400. fmt.Sprintf("%.2f", 0-item.FundPaySumamt) + " " +
  3401. fmt.Sprintf("%.2f", 0-item.AcctPay) + " " + "1" + "\r\n"
  3402. _, err = f.Write([]byte(str2))
  3403. }
  3404. }
  3405. }
  3406. Zip(file_path, zip_path)
  3407. fmt.Println(ReadFile(zip_path))
  3408. fmt.Println(string(ReadFile(zip_path)))
  3409. if config.IsOpen == 1 {
  3410. var user_name string
  3411. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3412. if role.ID == 0 {
  3413. user_name = "管理员"
  3414. } else {
  3415. user_name = role.UserName
  3416. }
  3417. baseParams := models.BaseParams{
  3418. SecretKey: miConfig.SecretKey,
  3419. FixmedinsCode: miConfig.Code,
  3420. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3421. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3422. OrgName: miConfig.OrgName,
  3423. Doctor: user_name,
  3424. }
  3425. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  3426. var dat map[string]interface{}
  3427. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3428. fmt.Println(dat)
  3429. } else {
  3430. fmt.Println(err)
  3431. }
  3432. userJSONBytes, _ := json.Marshal(dat)
  3433. var res ResultNine
  3434. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3435. utils.ErrorLog("解析失败:%v", err)
  3436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3437. return
  3438. }
  3439. if res.Infcode == 0 {
  3440. fileNo := res.Output.FileQuryNo
  3441. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  3442. "file_qury_no=" + fileNo +
  3443. "&setl_optins=" + "定点医保中心" +
  3444. "&stmt_begndate=" + start_time +
  3445. "&stm_enddate=" + end_time +
  3446. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  3447. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  3448. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  3449. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  3450. "&fixmedins_code=" + miConfig.Code +
  3451. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3452. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3453. "&secret_key=" + miConfig.SecretKey +
  3454. "&org_name=" + miConfig.OrgName +
  3455. "&doctor=" + user_name
  3456. resp, requestErr := http.Get(api)
  3457. if requestErr != nil {
  3458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3459. return
  3460. }
  3461. body, ioErr := ioutil.ReadAll(resp.Body)
  3462. if ioErr != nil {
  3463. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3465. return
  3466. }
  3467. var respJSON map[string]interface{}
  3468. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3469. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3471. return
  3472. }
  3473. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3474. userJSONBytes, _ := json.Marshal(respJSON)
  3475. var res ResultTen
  3476. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3477. utils.ErrorLog("解析失败:%v", err)
  3478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3479. return
  3480. }
  3481. if res.Infcode == 0 {
  3482. service.Gdyb9102(baseParams, zip_name, fileNo)
  3483. micc := &models.MedicalInsuranceCostCompare{
  3484. StartTime: startime.Unix(),
  3485. EndTime: endtime.Unix(),
  3486. Insutype: "0",
  3487. CheckType: 2,
  3488. Num: fixmedins_setl_cnt,
  3489. Mtime: time.Now().Unix(),
  3490. Status: 1,
  3491. UserOrgId: adminUser.CurrentOrgId,
  3492. CostTotal: medfee_sumamt,
  3493. FuncTotal: fund_pay_sumamt,
  3494. PsnPay: psn_cash_pay,
  3495. Creator: admin_user_id,
  3496. Ctime: time.Now().Unix(),
  3497. }
  3498. service.CreateMedicalInsuranceCostCompareRecord(micc)
  3499. c.ServeSuccessJSON(map[string]interface{}{
  3500. "msg": "明细对账成功",
  3501. })
  3502. }
  3503. } else {
  3504. }
  3505. }
  3506. }
  3507. func (c *HisApiController) GetSettleAccounts() {
  3508. //id, _ := c.GetInt64("id")
  3509. //record_time := c.GetString("record_time")
  3510. order_id, _ := c.GetInt64("order_id")
  3511. admin_user_id, _ := c.GetInt64("admin_user_id")
  3512. //timeLayout := "2006-01-02"
  3513. //loc, _ := time.LoadLocation("Local")
  3514. //
  3515. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3516. //if err != nil {
  3517. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3518. // return
  3519. //}
  3520. //recordDateTime := theTime.Unix()
  3521. adminUser := c.GetAdminUserInfo()
  3522. order, _ := service.GetHisOrderByID(order_id)
  3523. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  3524. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  3525. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  3526. orderInfos = append(orderInfos, orderInfos_two...)
  3527. diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  3528. var bedCostTotal float64 = 0 //床位总费
  3529. var bedCostSelfTotal float64 = 0 //床位自费
  3530. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  3531. var operationCostTotal float64 = 0 //手术费
  3532. var operationCostSelfTotal float64 = 0 //手术费
  3533. var operationCostPartSelfTotal float64 = 0 //手术费
  3534. var otherCostTotal float64 = 0 //其他费用
  3535. var otherCostSelfTotal float64 = 0 //其他费用
  3536. var otherCostPartSelfTotal float64 = 0 //其他费用
  3537. var materialCostTotal float64 = 0 //材料费
  3538. var materialCostSelfTotal float64 = 0 //材料费
  3539. var materialCostPartSelfTotal float64 = 0 //材料费
  3540. var westernMedicineCostTotal float64 = 0 //西药费
  3541. var westernMedicineCostSelfTotal float64 = 0 //西药费
  3542. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  3543. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  3544. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  3545. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  3546. var checkCostTotal float64 = 0 //检查费
  3547. var checkCostSelfTotal float64 = 0 //检查费
  3548. var checkCostPartSelfTotal float64 = 0 //检查费
  3549. var laboratoryCostTotal float64 = 0 //化验费
  3550. var laboratoryCostSelfTotal float64 = 0 //化验费
  3551. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  3552. var treatCostTotal float64 = 0 //治疗费用
  3553. var treatCostSelfTotal float64 = 0 //治疗费用
  3554. var treatCostPartSelfTotal float64 = 0 //治疗费用
  3555. decimal.DivisionPrecision = 2
  3556. for _, item := range orderInfos {
  3557. if item.MedChrgitmType == "01" { //床位费
  3558. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3559. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3560. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3561. }
  3562. if item.MedChrgitmType == "03" { //检查费
  3563. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3564. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3565. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3566. }
  3567. if item.MedChrgitmType == "04" { //化验费
  3568. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3569. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3570. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3571. }
  3572. if item.MedChrgitmType == "05" { //治疗费
  3573. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3574. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3575. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3576. }
  3577. if item.MedChrgitmType == "06" { //手术费
  3578. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3579. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3580. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3581. }
  3582. if item.MedChrgitmType == "08" { //材料费
  3583. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3584. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3585. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3586. }
  3587. if item.MedChrgitmType == "09" { //西药费
  3588. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3589. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3590. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3591. }
  3592. if item.MedChrgitmType == "11" { //中成费
  3593. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3594. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3595. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3596. }
  3597. if item.MedChrgitmType == "14" { //其他费
  3598. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3599. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3600. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3601. }
  3602. }
  3603. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3604. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3605. var user_name string
  3606. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3607. if role.ID == 0 {
  3608. user_name = "管理员"
  3609. } else {
  3610. user_name = role.UserName
  3611. }
  3612. baseParams := models.BaseParams{
  3613. SecretKey: miConfig.SecretKey,
  3614. FixmedinsCode: miConfig.Code,
  3615. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3616. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3617. OrgName: miConfig.OrgName,
  3618. Doctor: user_name,
  3619. }
  3620. businessParams := models.BusinessParams{
  3621. PsnNo: order.PsnNo,
  3622. MdtrtId: order.MdtrtId,
  3623. SetlId: order.SetlId,
  3624. }
  3625. if config.IsOpen == 1 {
  3626. result := service.Gdyb5203(baseParams, businessParams)
  3627. var dat map[string]interface{}
  3628. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3629. fmt.Println(dat)
  3630. } else {
  3631. fmt.Println(err)
  3632. }
  3633. userJSONBytes, _ := json.Marshal(dat)
  3634. var res ResultEleven
  3635. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3636. utils.ErrorLog("解析失败:%v", err)
  3637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3638. return
  3639. }
  3640. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3641. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  3642. if res.Infcode == 0 {
  3643. c.ServeSuccessJSON(map[string]interface{}{
  3644. "diagnosis": diagnosisConfig.CountryContentName,
  3645. "order_infos": orderInfos,
  3646. "number": order.MdtrtId,
  3647. "date": order.SettleAccountsDate,
  3648. "charge_admin": charge_admin,
  3649. "printor_admin": printor_admin,
  3650. "info": res.Output.Setlinfo,
  3651. "bedCostTotal": bedCostTotal,
  3652. "bedCostSelfTotal": bedCostSelfTotal,
  3653. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  3654. "operationCostTotal": operationCostTotal,
  3655. "operationCostSelfTotal": operationCostSelfTotal,
  3656. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  3657. "otherCostTotal": otherCostTotal,
  3658. "otherCostSelfTotal": otherCostSelfTotal,
  3659. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  3660. "materialCostTotal": materialCostTotal,
  3661. "materialCostSelfTotal": materialCostSelfTotal,
  3662. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  3663. "westernMedicineCostTotal": westernMedicineCostTotal,
  3664. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  3665. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  3666. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  3667. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  3668. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  3669. "checkCostTotal": checkCostTotal,
  3670. "checkCostSelfTotal": checkCostSelfTotal,
  3671. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  3672. "laboratoryCostTotal": laboratoryCostTotal,
  3673. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  3674. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  3675. "treatCostTotal": treatCostTotal,
  3676. "treatCostSelfTotal": treatCostSelfTotal,
  3677. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  3678. })
  3679. }
  3680. }
  3681. }
  3682. func (c *HisApiController) CheckTreatment() {
  3683. patient_id, _ := c.GetInt64("patient_id", 0)
  3684. record_time := c.GetString("record_time")
  3685. insutype := c.GetString("insutype")
  3686. timeLayout := "2006-01-02"
  3687. loc, _ := time.LoadLocation("Local")
  3688. adminUser := c.GetAdminUserInfo()
  3689. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3690. fmt.Println(err)
  3691. if err != nil {
  3692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3693. return
  3694. }
  3695. recordDateTime := theTime.Unix()
  3696. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3697. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3698. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3699. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3700. var user_name string
  3701. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  3702. if role.ID == 0 {
  3703. user_name = "xxx"
  3704. } else {
  3705. user_name = role.UserName
  3706. }
  3707. baseParams := models.BaseParams{
  3708. SecretKey: miConfig.SecretKey,
  3709. FixmedinsCode: miConfig.Code,
  3710. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3711. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3712. OrgName: miConfig.OrgName,
  3713. Doctor: user_name,
  3714. }
  3715. if config.IsOpen == 1 {
  3716. result := service.Gdyb2001(baseParams, his.PsnNo, insutype, strconv.FormatInt(patientPrescription.RegisterType, 10))
  3717. var dat map[string]interface{}
  3718. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3719. fmt.Println(dat)
  3720. } else {
  3721. fmt.Println(err)
  3722. }
  3723. }
  3724. }
  3725. func (c *HisApiController) PutRecord() {
  3726. id, _ := c.GetInt64("id")
  3727. record_time := c.GetString("record_time")
  3728. timeLayout := "2006-01-02"
  3729. loc, _ := time.LoadLocation("Local")
  3730. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3731. if err != nil {
  3732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3733. return
  3734. }
  3735. recordDateTime := theTime.Unix()
  3736. adminInfo := c.GetAdminUserInfo()
  3737. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  3738. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3739. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  3740. fmt.Println(miConfig.SecretKey)
  3741. if patient == nil {
  3742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3743. return
  3744. }
  3745. if len(patient.IdCardNo) == 0 {
  3746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  3747. return
  3748. }
  3749. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  3750. if config.IsOpen == 1 {
  3751. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3752. resp, requestErr := http.Get(api)
  3753. if requestErr != nil {
  3754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3755. return
  3756. }
  3757. defer resp.Body.Close()
  3758. body, ioErr := ioutil.ReadAll(resp.Body)
  3759. if ioErr != nil {
  3760. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3762. return
  3763. }
  3764. var respJSON map[string]interface{}
  3765. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3766. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3767. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3768. return
  3769. }
  3770. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3771. userJSONBytes, _ := json.Marshal(userJSON)
  3772. var res ResultTwo
  3773. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3774. utils.ErrorLog("解析失败:%v", err)
  3775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3776. return
  3777. }
  3778. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  3779. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  3780. infoStr := string(Iinfos)
  3781. idetinfoStr := string(Idetinfos)
  3782. if res.Infcode == 0 {
  3783. his := models.VMHisPatient{
  3784. Status: 1,
  3785. Ctime: time.Now().Unix(),
  3786. Mtime: time.Now().Unix(),
  3787. PsnNo: res.Output.Baseinfo.PsnNo,
  3788. PsnCertType: res.Output.Baseinfo.PsnCertType,
  3789. Certno: res.Output.Baseinfo.Certno,
  3790. PsnName: res.Output.Baseinfo.PsnName,
  3791. Gend: res.Output.Baseinfo.Gend,
  3792. Naty: res.Output.Baseinfo.Naty,
  3793. Brdy: res.Output.Baseinfo.Brdy,
  3794. Age: res.Output.Baseinfo.Age,
  3795. Iinfo: infoStr,
  3796. Idetinfo: idetinfoStr,
  3797. PatientId: patient.ID,
  3798. RecordDate: theTime.Unix(),
  3799. UserOrgId: adminInfo.CurrentOrgId,
  3800. AdminUserId: adminInfo.AdminUser.Id,
  3801. IsReturn: 1,
  3802. }
  3803. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  3804. result := service.Gdyb2503(his.PsnNo, res.Output.Iinfo[0].Insutype, miConfig.OrgName, patientPrescription.Doctor, miConfig.Code, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "重症尿毒症透析(血透)", "M07801")
  3805. result2 := service.Gdyb5301(his.PsnNo, res.Output.Iinfo[0].Insutype, miConfig.OrgName, patientPrescription.Doctor, miConfig.Code, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "重症尿毒症透析(血透)", "M07801")
  3806. var dat map[string]interface{}
  3807. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3808. fmt.Println(dat)
  3809. } else {
  3810. fmt.Println(err)
  3811. }
  3812. var dat2 map[string]interface{}
  3813. if err := json.Unmarshal([]byte(result2), &dat2); err == nil {
  3814. fmt.Println(dat2)
  3815. } else {
  3816. fmt.Println(err)
  3817. }
  3818. } else {
  3819. adminUser := c.GetAdminUserInfo()
  3820. errlog := &models.HisOrderError{
  3821. UserOrgId: adminUser.CurrentOrgId,
  3822. Ctime: time.Now().Unix(),
  3823. Mtime: time.Now().Unix(),
  3824. ErrMsg: res.ErrMsg,
  3825. Status: 1,
  3826. PatientId: id,
  3827. RecordTime: recordDateTime,
  3828. Stage: 1,
  3829. }
  3830. service.CreateErrMsgLog(errlog)
  3831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  3832. return
  3833. }
  3834. }
  3835. }
  3836. func (c *HisApiController) GetUploadDiag() {
  3837. id, _ := c.GetInt64("id")
  3838. record_time := c.GetString("record_time")
  3839. diagnosis_id, _ := c.GetInt64("diagnosis")
  3840. sick_type, _ := c.GetInt64("sick_type")
  3841. reg_type, _ := c.GetInt64("reg_type")
  3842. timeLayout := "2006-01-02"
  3843. loc, _ := time.LoadLocation("Local")
  3844. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3845. if err != nil {
  3846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3847. return
  3848. }
  3849. var patientPrescription models.HisPrescriptionInfo
  3850. recordDateTime := theTime.Unix()
  3851. adminInfo := c.GetAdminUserInfo()
  3852. patientPrescription, _ = service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3853. if patientPrescription.ID == 0 {
  3854. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3855. }
  3856. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  3857. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  3858. his, _ := service.GetVMHisPatientInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3859. sickConfig, _ := service.FindSickById(sick_type)
  3860. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  3861. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  3862. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  3863. "&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + strconv.FormatInt(reg_type, 10) + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code + "&diag_code=" + diagnosisConfig.CountryCode +
  3864. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  3865. resp2, requestErr2 := http.Get(api2)
  3866. if requestErr2 != nil {
  3867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3868. return
  3869. }
  3870. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  3871. if ioErr2 != nil {
  3872. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  3873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3874. return
  3875. }
  3876. var respJSON2 map[string]interface{}
  3877. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  3878. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3880. return
  3881. }
  3882. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3883. userJSONBytes2, _ := json.Marshal(respJSON2)
  3884. var res2 ResultSix
  3885. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  3886. utils.ErrorLog("解析失败:%v", err)
  3887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3888. return
  3889. }
  3890. if res2.Infcode == -1 {
  3891. adminUser := c.GetAdminUserInfo()
  3892. errlog := &models.HisOrderError{
  3893. UserOrgId: adminUser.CurrentOrgId,
  3894. Ctime: time.Now().Unix(),
  3895. Mtime: time.Now().Unix(),
  3896. ErrMsg: res2.ErrMsg,
  3897. Status: 1,
  3898. PatientId: id,
  3899. RecordTime: recordDateTime,
  3900. Stage: 3,
  3901. }
  3902. service.CreateErrMsgLog(errlog)
  3903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  3904. return
  3905. }
  3906. c.ServeSuccessJSON(map[string]interface{}{
  3907. "msg": "上传成功",
  3908. })
  3909. }
  3910. type QueryResult struct {
  3911. ID int64
  3912. Name string
  3913. Code string
  3914. List_type_code string
  3915. }
  3916. func (c *HisApiController) GetCheckCode() {
  3917. ids_str := c.GetString("ids")
  3918. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  3919. ids_arr := strings.Split(ids_str, ",")
  3920. var queryResult []QueryResult
  3921. ids := make([]int64, 0)
  3922. for _, item := range ids_arr {
  3923. id, _ := strconv.ParseInt(item, 10, 64)
  3924. ids = append(ids, id)
  3925. }
  3926. if record_type == 1 {
  3927. drugs, _ := service.GetBatchDrugList(ids)
  3928. for _, item := range drugs {
  3929. result := QueryResult{
  3930. ID: item.ID,
  3931. Name: item.DrugName,
  3932. Code: item.MedicalInsuranceNumber,
  3933. List_type_code: "101",
  3934. }
  3935. queryResult = append(queryResult, result)
  3936. }
  3937. } else if record_type == 2 {
  3938. goods, _ := service.GetBatchGoodInformationList(ids)
  3939. for _, item := range goods {
  3940. result := QueryResult{
  3941. ID: item.ID,
  3942. Name: item.GoodName,
  3943. Code: item.MedicalInsuranceNumber,
  3944. List_type_code: "301",
  3945. }
  3946. queryResult = append(queryResult, result)
  3947. }
  3948. } else if record_type == 3 {
  3949. projects, _ := service.GetBathchMyPorjecgList(ids)
  3950. for _, item := range projects {
  3951. result := QueryResult{
  3952. ID: item.ID,
  3953. Name: item.ProjectName,
  3954. Code: item.MedicalCode,
  3955. List_type_code: "201",
  3956. }
  3957. queryResult = append(queryResult, result)
  3958. }
  3959. }
  3960. admin_user_id, _ := c.GetInt64("admin_user_id")
  3961. adminUser := c.GetAdminUserInfo()
  3962. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3963. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3964. var user_name string
  3965. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3966. if role.ID == 0 {
  3967. user_name = "xxx"
  3968. } else {
  3969. user_name = role.UserName
  3970. }
  3971. baseParams := &models.BaseParams{
  3972. SecretKey: miConfig.SecretKey,
  3973. FixmedinsCode: miConfig.Code,
  3974. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3975. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3976. OrgName: miConfig.OrgName,
  3977. Doctor: user_name,
  3978. }
  3979. if config.IsOpen == 1 {
  3980. for _, item := range queryResult {
  3981. var result string
  3982. if record_type == 1 {
  3983. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  3984. } else if record_type == 2 {
  3985. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  3986. } else if record_type == 3 {
  3987. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  3988. }
  3989. var dat map[string]interface{}
  3990. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3991. fmt.Println(dat)
  3992. } else {
  3993. fmt.Println(err)
  3994. }
  3995. userJSONBytes, _ := json.Marshal(dat)
  3996. var res ResultSix
  3997. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3998. utils.ErrorLog("解析失败:%v", err)
  3999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4000. return
  4001. }
  4002. if res.Infcode == 0 {
  4003. if record_type == 1 {
  4004. service.UpdateBaseDrugById(item.ID)
  4005. } else if record_type == 2 {
  4006. service.UpdateGoodInformaitonByDetail(item.ID)
  4007. } else if record_type == 3 {
  4008. service.UpdateProjectById(item.ID)
  4009. }
  4010. c.ServeSuccessJSON(map[string]interface{}{
  4011. "failed_code": 0,
  4012. "msg": "目录对照成功",
  4013. })
  4014. } else {
  4015. c.ServeSuccessJSON(map[string]interface{}{
  4016. "failed_code": -10,
  4017. "msg": res.ErrMsg,
  4018. })
  4019. }
  4020. }
  4021. }
  4022. }
  4023. func (c *HisApiController) UnCheckCode() {
  4024. ids_str := c.GetString("ids")
  4025. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  4026. admin_user_id, _ := c.GetInt64("admin_user_id")
  4027. ids_arr := strings.Split(ids_str, ",")
  4028. var queryResult []QueryResult
  4029. ids := make([]int64, 0)
  4030. for _, item := range ids_arr {
  4031. id, _ := strconv.ParseInt(item, 10, 64)
  4032. ids = append(ids, id)
  4033. }
  4034. if record_type == 1 {
  4035. drugs, _ := service.GetBatchDrugList(ids)
  4036. for _, item := range drugs {
  4037. result := QueryResult{
  4038. ID: item.ID,
  4039. Name: item.DrugName,
  4040. Code: item.MedicalInsuranceNumber,
  4041. List_type_code: "101",
  4042. }
  4043. queryResult = append(queryResult, result)
  4044. }
  4045. } else if record_type == 2 {
  4046. goods, _ := service.GetBatchGoodInformationList(ids)
  4047. for _, item := range goods {
  4048. result := QueryResult{
  4049. ID: item.ID,
  4050. Name: item.GoodName,
  4051. Code: item.MedicalInsuranceNumber,
  4052. List_type_code: "301",
  4053. }
  4054. queryResult = append(queryResult, result)
  4055. }
  4056. } else if record_type == 3 {
  4057. projects, _ := service.GetBathchMyPorjecgList(ids)
  4058. for _, item := range projects {
  4059. result := QueryResult{
  4060. ID: item.ID,
  4061. Name: item.ProjectName,
  4062. Code: item.MedicalCode,
  4063. List_type_code: "201",
  4064. }
  4065. queryResult = append(queryResult, result)
  4066. }
  4067. }
  4068. adminUser := c.GetAdminUserInfo()
  4069. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4070. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4071. var user_name string
  4072. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4073. if role.ID == 0 {
  4074. user_name = "xxx"
  4075. } else {
  4076. user_name = role.UserName
  4077. }
  4078. baseParams := &models.BaseParams{
  4079. SecretKey: miConfig.SecretKey,
  4080. FixmedinsCode: miConfig.Code,
  4081. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4082. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4083. OrgName: miConfig.OrgName,
  4084. Doctor: user_name,
  4085. }
  4086. if config.IsOpen == 1 {
  4087. for _, item := range queryResult {
  4088. var result string
  4089. if record_type == 1 {
  4090. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  4091. } else if record_type == 2 {
  4092. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  4093. } else if record_type == 3 {
  4094. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  4095. }
  4096. var dat2 map[string]interface{}
  4097. if err := json.Unmarshal([]byte(result), &dat2); err == nil {
  4098. fmt.Println(dat2)
  4099. } else {
  4100. fmt.Println(err)
  4101. }
  4102. userJSONBytes, _ := json.Marshal(dat2)
  4103. var res ResultSix
  4104. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4105. utils.ErrorLog("解析失败:%v", err)
  4106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4107. return
  4108. }
  4109. if res.Infcode == 0 {
  4110. if record_type == 1 {
  4111. service.UpdateDrugByIdDetail(item.ID)
  4112. } else if record_type == 2 {
  4113. service.UpdateGoodInfoById(item.ID)
  4114. } else if record_type == 3 {
  4115. service.UpdateMyProjectById(item.ID)
  4116. }
  4117. c.ServeSuccessJSON(map[string]interface{}{
  4118. "failed_code": 0,
  4119. "msg": "撤销目录对照成功",
  4120. })
  4121. } else {
  4122. c.ServeSuccessJSON(map[string]interface{}{
  4123. "failed_code": -10,
  4124. "msg": res.ErrMsg,
  4125. })
  4126. }
  4127. }
  4128. }
  4129. }
  4130. func (c *HisApiController) GetPatientInfo() {
  4131. id_card_no := c.GetString("id_card_no")
  4132. admin_user_id, _ := c.GetInt64("admin_user_id")
  4133. patient, _ := service.GetPatientByIDCard(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  4134. if patient.ID == 0 {
  4135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4136. return
  4137. }
  4138. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  4139. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  4140. config, _ := service.GetMedicalInsuranceConfig(c.GetAdminUserInfo().CurrentOrgId)
  4141. if config.IsOpen == 1 {
  4142. result := service.Gdyb1101A(id_card_no, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  4143. var dat map[string]interface{}
  4144. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4145. fmt.Println(dat)
  4146. } else {
  4147. fmt.Println(err)
  4148. }
  4149. userJSONBytes, _ := json.Marshal(dat)
  4150. var res ResultTwo
  4151. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4152. utils.ErrorLog("解析失败:%v", err)
  4153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4154. return
  4155. }
  4156. if res.Infcode == -1 {
  4157. c.ServeSuccessJSON(map[string]interface{}{
  4158. "failed_code": -10,
  4159. "msg": res.ErrMsg,
  4160. })
  4161. } else {
  4162. c.ServeSuccessJSON(map[string]interface{}{
  4163. "failed_code": 0,
  4164. "info": res,
  4165. })
  4166. }
  4167. }
  4168. }
  4169. func (c *HisApiController) PsnPutOnRecord() {
  4170. record_type, _ := c.GetInt64("type")
  4171. patient_id, _ := c.GetInt64("patient_id")
  4172. admin_user_id, _ := c.GetInt64("admin_user_id")
  4173. start_time := c.GetString("start_time")
  4174. end_time := c.GetString("end_time")
  4175. adminUser := c.GetAdminUserInfo()
  4176. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4177. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4178. var patients []*models.Patients
  4179. if record_type == 1 { //全部备案
  4180. patient, _ := service.GetAllPatient(adminUser.CurrentOrgId)
  4181. patients = append(patients, patient...)
  4182. } else { //单个备案
  4183. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  4184. patients = append(patients, patient)
  4185. }
  4186. var user_name string
  4187. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4188. if role.ID == 0 {
  4189. user_name = "xxx"
  4190. } else {
  4191. user_name = role.UserName
  4192. }
  4193. if config.IsOpen == 1 {
  4194. for _, item := range patients {
  4195. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + item.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + user_name + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4196. resp, requestErr := http.Get(api)
  4197. if requestErr != nil {
  4198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4199. return
  4200. }
  4201. defer resp.Body.Close()
  4202. body, ioErr := ioutil.ReadAll(resp.Body)
  4203. if ioErr != nil {
  4204. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4206. return
  4207. }
  4208. var respJSON map[string]interface{}
  4209. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4210. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4212. return
  4213. }
  4214. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4215. userJSONBytes, _ := json.Marshal(userJSON)
  4216. var res ResultTwo
  4217. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4218. utils.ErrorLog("解析失败:%v", err)
  4219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4220. return
  4221. }
  4222. if res.Infcode == 0 {
  4223. result := service.Gdyb2505(res.Output.Baseinfo.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, start_time, end_time)
  4224. var dat map[string]interface{}
  4225. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4226. fmt.Println(dat)
  4227. } else {
  4228. fmt.Println(err)
  4229. }
  4230. userJSONBytes, _ := json.Marshal(dat)
  4231. var res2 ResultThirteen
  4232. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  4233. utils.ErrorLog("解析失败:%v", err)
  4234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4235. return
  4236. }
  4237. if res2.Infcode == 0 {
  4238. psnResult := &models.GdybPsnRecord{
  4239. UserOrgId: adminUser.CurrentOrgId,
  4240. PatientId: item.ID,
  4241. PsnNo: res.Output.Baseinfo.PsnNo,
  4242. Ctime: time.Now().Unix(),
  4243. Mtime: time.Now().Unix(),
  4244. Status: 1,
  4245. IsCancel: 1,
  4246. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  4247. }
  4248. service.CreatePsnRecord(psnResult)
  4249. } else {
  4250. c.ServeSuccessJSON(map[string]interface{}{
  4251. "failed_code": -10,
  4252. "msg": res2.ErrMsg,
  4253. })
  4254. return
  4255. }
  4256. }
  4257. }
  4258. }
  4259. }
  4260. func (c *HisApiController) PsnUnPutOnRecord() {
  4261. id, _ := c.GetInt64("id")
  4262. //record_type, _ := c.GetInt64("type")
  4263. admin_user_id, _ := c.GetInt64("admin_user_id")
  4264. adminUser := c.GetAdminUserInfo()
  4265. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4266. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4267. var user_name string
  4268. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4269. if role.ID == 0 {
  4270. user_name = "xxx"
  4271. } else {
  4272. user_name = role.UserName
  4273. }
  4274. psn_record, _ := service.GetPsnRecordById(id)
  4275. if psn_record.ID == 0 {
  4276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  4277. return
  4278. }
  4279. if config.IsOpen == 1 {
  4280. result := service.Gdyb2506(psn_record.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  4281. var dat map[string]interface{}
  4282. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4283. fmt.Println(dat)
  4284. } else {
  4285. fmt.Println(err)
  4286. }
  4287. userJSONBytes, _ := json.Marshal(dat)
  4288. var res ResultFourteen
  4289. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4290. utils.ErrorLog("解析失败:%v", err)
  4291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4292. return
  4293. }
  4294. if res.Infcode == 0 {
  4295. psn_record.IsCancel = 2
  4296. service.CreatePsnRecord(&psn_record)
  4297. } else {
  4298. c.ServeSuccessJSON(map[string]interface{}{
  4299. "failed_code": -10,
  4300. "msg": res.ErrMsg,
  4301. })
  4302. return
  4303. }
  4304. }
  4305. }
  4306. func (c *HisApiController) PsnPutNCDSOnRecord() {
  4307. patient_id, _ := c.GetInt64("patient_id")
  4308. insutype := c.GetString("insutype")
  4309. psn_no := c.GetString("psn_no")
  4310. doctor_id, _ := c.GetInt64("doctor_id")
  4311. sick_id, _ := c.GetInt64("sick_id")
  4312. department_id, _ := c.GetInt64("department_id")
  4313. adminUser := c.GetAdminUserInfo()
  4314. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  4315. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4316. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4317. sick, _ := service.FindSickById(sick_id)
  4318. doctor, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, doctor_id)
  4319. if config.IsOpen == 1 {
  4320. result := service.Gdyb2503(psn_no, insutype, miConfig.OrgName, doctor.UserName, miConfig.Code, strconv.FormatInt(doctor.ID, 10), miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sick.ClassName, sick.CountryCode)
  4321. var dat map[string]interface{}
  4322. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4323. fmt.Println(dat)
  4324. } else {
  4325. fmt.Println(err)
  4326. }
  4327. userJSONBytes, _ := json.Marshal(dat)
  4328. var res2 ResultThirteen
  4329. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  4330. utils.ErrorLog("解析失败:%v", err)
  4331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4332. return
  4333. }
  4334. if res2.Infcode == 0 {
  4335. psnResult := &models.GdybPsnNcdsRecord{
  4336. UserOrgId: adminUser.CurrentOrgId,
  4337. PatientId: patient.ID,
  4338. PsnNo: psn_no,
  4339. DoctorId: doctor.AdminUserId,
  4340. DepartmentId: department_id,
  4341. SickType: sick_id,
  4342. Insutype: insutype,
  4343. Ctime: time.Now().Unix(),
  4344. Mtime: time.Now().Unix(),
  4345. Status: 1,
  4346. IsCancel: 1,
  4347. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  4348. }
  4349. service.CreatePsnNCDSRecord(psnResult)
  4350. c.ServeSuccessJSON(map[string]interface{}{
  4351. "failed_code": 0,
  4352. "msg": "备案成功",
  4353. "result": psnResult,
  4354. })
  4355. } else {
  4356. c.ServeSuccessJSON(map[string]interface{}{
  4357. "failed_code": -10,
  4358. "msg": res2.ErrMsg,
  4359. })
  4360. return
  4361. }
  4362. }
  4363. }
  4364. func (c *HisApiController) PsnPutUnNCDSOnRecord() {
  4365. id, _ := c.GetInt64("id")
  4366. admin_user_id, _ := c.GetInt64("admin_user_id")
  4367. adminUser := c.GetAdminUserInfo()
  4368. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4369. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4370. var user_name string
  4371. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4372. if role.ID == 0 {
  4373. user_name = "xxx"
  4374. } else {
  4375. user_name = role.UserName
  4376. }
  4377. psn_record, _ := service.GetPsnNCDSRecordById(id)
  4378. if psn_record.ID == 0 {
  4379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  4380. return
  4381. }
  4382. if config.IsOpen == 1 {
  4383. result := service.Gdyb2504(psn_record.PsnNo, miConfig.OrgName, user_name, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  4384. var dat map[string]interface{}
  4385. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4386. fmt.Println(dat)
  4387. } else {
  4388. fmt.Println(err)
  4389. }
  4390. userJSONBytes, _ := json.Marshal(dat)
  4391. var res ResultFourteen
  4392. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4393. utils.ErrorLog("解析失败:%v", err)
  4394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4395. return
  4396. }
  4397. if res.Infcode == 0 {
  4398. psn_record.IsCancel = 2
  4399. service.CreatePsnNCDSRecord(&psn_record)
  4400. c.ServeSuccessJSON(map[string]interface{}{
  4401. "failed_code": 0,
  4402. "msg": "撤销备案成功",
  4403. })
  4404. } else {
  4405. c.ServeSuccessJSON(map[string]interface{}{
  4406. "failed_code": -10,
  4407. "msg": res.ErrMsg,
  4408. })
  4409. return
  4410. }
  4411. }
  4412. }
  4413. func (c *HisApiController) TestTest() {
  4414. patient, _ := service.GetHisPatientInfo(4, 456, 1619712000)
  4415. fmt.Println(patient.Iinfo)
  4416. }
  4417. type CustomData struct {
  4418. MsgId string
  4419. PsnNo string
  4420. Info string
  4421. }
  4422. func (c *HisApiController) ReversalData() {
  4423. var customData []*CustomData
  4424. custom := &CustomData{
  4425. MsgId: "H44022900158202103301714472004",
  4426. PsnNo: "44020000001101329945",
  4427. Info: "2207",
  4428. }
  4429. customData = append(customData, custom)
  4430. custom1 := &CustomData{
  4431. MsgId: "H4402290015820210330172057803",
  4432. PsnNo: "44020000001101161813",
  4433. Info: "2207",
  4434. }
  4435. customData = append(customData, custom1)
  4436. custom2 := &CustomData{
  4437. MsgId: "H44022900158202103301705198813",
  4438. PsnNo: "44190000133097375417",
  4439. Info: "2207",
  4440. }
  4441. customData = append(customData, custom2)
  4442. custom3 := &CustomData{
  4443. MsgId: "H44022900158202103301715524756",
  4444. PsnNo: "44020000001100187221",
  4445. Info: "2207",
  4446. }
  4447. customData = append(customData, custom3)
  4448. custom4 := &CustomData{
  4449. MsgId: "H44022900158202103301730376224",
  4450. PsnNo: "44020000001101959155",
  4451. Info: "2207",
  4452. }
  4453. customData = append(customData, custom4)
  4454. custom5 := &CustomData{
  4455. MsgId: "H44022900158202103301748008725",
  4456. PsnNo: "44020000001104246641",
  4457. Info: "2207",
  4458. }
  4459. customData = append(customData, custom5)
  4460. custom6 := &CustomData{
  4461. MsgId: "H44022900158202103301718096755",
  4462. PsnNo: "44020000001102211860",
  4463. Info: "2207",
  4464. }
  4465. customData = append(customData, custom6)
  4466. custom7 := &CustomData{
  4467. MsgId: "H44022900158202103301736551640",
  4468. PsnNo: "44020000001102687718",
  4469. Info: "2207",
  4470. }
  4471. customData = append(customData, custom7)
  4472. custom8 := &CustomData{
  4473. MsgId: "H44022900158202103301743097676",
  4474. PsnNo: "44020000001102127785",
  4475. Info: "2207",
  4476. }
  4477. customData = append(customData, custom8)
  4478. custom9 := &CustomData{
  4479. MsgId: "H44022900158202103301712304203",
  4480. PsnNo: "44020000001101518097",
  4481. Info: "2207",
  4482. }
  4483. customData = append(customData, custom9)
  4484. custom10 := &CustomData{
  4485. MsgId: "H44022900158202103301738448785",
  4486. PsnNo: "44020000001100500813",
  4487. Info: "2207",
  4488. }
  4489. customData = append(customData, custom10)
  4490. custom11 := &CustomData{
  4491. MsgId: "H44022900158202103301732455843",
  4492. PsnNo: "44020000001102690557",
  4493. Info: "2207",
  4494. }
  4495. customData = append(customData, custom11)
  4496. custom12 := &CustomData{
  4497. MsgId: "H44022900158202103301745421708",
  4498. PsnNo: "44020000001102211928",
  4499. Info: "2207",
  4500. }
  4501. customData = append(customData, custom12)
  4502. custom1212 := &CustomData{
  4503. MsgId: "H440229001582021033017351627",
  4504. PsnNo: "44020000001102481733",
  4505. Info: "2207",
  4506. }
  4507. customData = append(customData, custom1212)
  4508. custom13 := &CustomData{
  4509. MsgId: "H44022900158202103301740327951",
  4510. PsnNo: "44020000001103174866",
  4511. Info: "2207",
  4512. }
  4513. customData = append(customData, custom13)
  4514. custom14 := &CustomData{
  4515. MsgId: "H4402290015820210330174922668",
  4516. PsnNo: "44020000001102927272",
  4517. Info: "2207",
  4518. }
  4519. customData = append(customData, custom14)
  4520. custom15 := &CustomData{
  4521. MsgId: "H44022900158202103301752362273",
  4522. PsnNo: "44020000001102942890",
  4523. Info: "2207",
  4524. }
  4525. customData = append(customData, custom15)
  4526. custom16 := &CustomData{
  4527. MsgId: "H44022900158202103301751082917",
  4528. PsnNo: "44020000001101662162",
  4529. Info: "2207",
  4530. }
  4531. customData = append(customData, custom16)
  4532. custom17 := &CustomData{
  4533. MsgId: "H44022900158202103301754147728",
  4534. PsnNo: "44020000000229014511",
  4535. Info: "2207",
  4536. }
  4537. customData = append(customData, custom17)
  4538. adminUser := c.GetAdminUserInfo()
  4539. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4540. for _, item := range customData {
  4541. result := service.Gdyb2601(item.PsnNo, item.MsgId, item.Info, miConfig.OrgName, "张俊杰", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  4542. fmt.Println(result)
  4543. }
  4544. }
  4545. func (c *HisApiController) ReversalOtherData() {
  4546. var customData []*CustomData
  4547. custom := &CustomData{
  4548. MsgId: "H44022900158202103301714472004",
  4549. PsnNo: "44020000001101329945",
  4550. Info: "2208",
  4551. }
  4552. customData = append(customData, custom)
  4553. custom1 := &CustomData{
  4554. MsgId: "H4402290015820210330172057803",
  4555. PsnNo: "44020000001101161813",
  4556. Info: "2208",
  4557. }
  4558. customData = append(customData, custom1)
  4559. custom2 := &CustomData{
  4560. MsgId: "H44022900158202103301705198813",
  4561. PsnNo: "44190000133097375417",
  4562. Info: "2208",
  4563. }
  4564. customData = append(customData, custom2)
  4565. custom3 := &CustomData{
  4566. MsgId: "H44022900158202103301715524756",
  4567. PsnNo: "44020000001100187221",
  4568. Info: "2208",
  4569. }
  4570. customData = append(customData, custom3)
  4571. custom4 := &CustomData{
  4572. MsgId: "H44022900158202103301730376224",
  4573. PsnNo: "44020000001101959155",
  4574. Info: "2208",
  4575. }
  4576. customData = append(customData, custom4)
  4577. custom5 := &CustomData{
  4578. MsgId: "H44022900158202103301748008725",
  4579. PsnNo: "44020000001104246641",
  4580. Info: "2208",
  4581. }
  4582. customData = append(customData, custom5)
  4583. custom6 := &CustomData{
  4584. MsgId: "H44022900158202103301718096755",
  4585. PsnNo: "44020000001102211860",
  4586. Info: "2208",
  4587. }
  4588. customData = append(customData, custom6)
  4589. custom7 := &CustomData{
  4590. MsgId: "H44022900158202103301736551640",
  4591. PsnNo: "44020000001102687718",
  4592. Info: "2208",
  4593. }
  4594. customData = append(customData, custom7)
  4595. custom8 := &CustomData{
  4596. MsgId: "H44022900158202103301743097676",
  4597. PsnNo: "44020000001102127785",
  4598. Info: "2208",
  4599. }
  4600. customData = append(customData, custom8)
  4601. custom9 := &CustomData{
  4602. MsgId: "H44022900158202103301712304203",
  4603. PsnNo: "44020000001101518097",
  4604. Info: "2208",
  4605. }
  4606. customData = append(customData, custom9)
  4607. custom10 := &CustomData{
  4608. MsgId: "H44022900158202103301738448785",
  4609. PsnNo: "44020000001100500813",
  4610. Info: "2208",
  4611. }
  4612. customData = append(customData, custom10)
  4613. custom11 := &CustomData{
  4614. MsgId: "H44022900158202103301732455843",
  4615. PsnNo: "44020000001102690557",
  4616. Info: "2208",
  4617. }
  4618. customData = append(customData, custom11)
  4619. custom12 := &CustomData{
  4620. MsgId: "H44022900158202103301745421708",
  4621. PsnNo: "44020000001102211928",
  4622. Info: "2208",
  4623. }
  4624. customData = append(customData, custom12)
  4625. custom1212 := &CustomData{
  4626. MsgId: "H440229001582021033017351627",
  4627. PsnNo: "44020000001102481733",
  4628. Info: "2208",
  4629. }
  4630. customData = append(customData, custom1212)
  4631. custom13 := &CustomData{
  4632. MsgId: "H44022900158202103301740327951",
  4633. PsnNo: "44020000001103174866",
  4634. Info: "2208",
  4635. }
  4636. customData = append(customData, custom13)
  4637. custom14 := &CustomData{
  4638. MsgId: "H4402290015820210330174922668",
  4639. PsnNo: "44020000001102927272",
  4640. Info: "2208",
  4641. }
  4642. customData = append(customData, custom14)
  4643. custom15 := &CustomData{
  4644. MsgId: "H44022900158202103301752362273",
  4645. PsnNo: "44020000001102942890",
  4646. Info: "2208",
  4647. }
  4648. customData = append(customData, custom15)
  4649. custom16 := &CustomData{
  4650. MsgId: "H44022900158202103301751082917",
  4651. PsnNo: "44020000001101662162",
  4652. Info: "2208",
  4653. }
  4654. customData = append(customData, custom16)
  4655. custom17 := &CustomData{
  4656. MsgId: "H44022900158202103301754147728",
  4657. PsnNo: "44020000000229014511",
  4658. Info: "2208",
  4659. }
  4660. customData = append(customData, custom17)
  4661. adminUser := c.GetAdminUserInfo()
  4662. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4663. for _, item := range customData {
  4664. result := service.Gdyb2601(item.PsnNo, item.MsgId, item.Info, miConfig.OrgName, "张俊杰", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  4665. fmt.Println(result)
  4666. }
  4667. }
  4668. func PathExists(path string) (bool, error) {
  4669. _, err := os.Stat(path)
  4670. if err == nil {
  4671. return true, nil
  4672. }
  4673. if os.IsNotExist(err) {
  4674. return false, nil
  4675. }
  4676. return false, err
  4677. }
  4678. //创建文件夹
  4679. func Mkdir(dir string) {
  4680. // 创建文件夹
  4681. exist, err := PathExists(dir)
  4682. if err != nil {
  4683. fmt.Println(err.Error())
  4684. } else {
  4685. if exist {
  4686. fmt.Println(dir + "文件夹已存在!")
  4687. } else {
  4688. // 文件夹名称,权限
  4689. err := os.Mkdir(dir, os.ModePerm)
  4690. if err != nil {
  4691. fmt.Println(dir+"文件夹创建失败:", err.Error())
  4692. } else {
  4693. fmt.Println(dir + "文件夹创建成功!")
  4694. }
  4695. }
  4696. }
  4697. }
  4698. //压缩文件
  4699. func Zip(srcFile string, destZip string) error {
  4700. zipfile, err := os.Create(destZip)
  4701. if err != nil {
  4702. return err
  4703. }
  4704. defer zipfile.Close()
  4705. archive := zip.NewWriter(zipfile)
  4706. defer archive.Close()
  4707. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  4708. if err != nil {
  4709. return err
  4710. }
  4711. header, err := zip.FileInfoHeader(info)
  4712. if err != nil {
  4713. return err
  4714. }
  4715. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  4716. // header.Name = path
  4717. if info.IsDir() {
  4718. header.Name += "/"
  4719. } else {
  4720. header.Method = zip.Deflate
  4721. }
  4722. writer, err := archive.CreateHeader(header)
  4723. if err != nil {
  4724. return err
  4725. }
  4726. if !info.IsDir() {
  4727. file, err := os.Open(path)
  4728. if err != nil {
  4729. return err
  4730. }
  4731. defer file.Close()
  4732. _, err = io.Copy(writer, file)
  4733. }
  4734. return err
  4735. })
  4736. return err
  4737. }
  4738. func ReadFile(filePath string) []byte {
  4739. f, err := os.Open(filePath)
  4740. if err != nil {
  4741. fmt.Println("read file fail", err)
  4742. return nil
  4743. }
  4744. defer f.Close()
  4745. fd, err := ioutil.ReadAll(f)
  4746. if err != nil {
  4747. fmt.Println("read to fd fail", err)
  4748. return nil
  4749. }
  4750. return fd
  4751. }
  4752. func RemoveRepeatedCode(arr []string) (newArr []string) {
  4753. newArr = make([]string, 0)
  4754. for i := 0; i < len(arr); i++ {
  4755. repeat := false
  4756. for j := i + 1; j < len(arr); j++ {
  4757. if arr[i] == arr[j] {
  4758. repeat = true
  4759. break
  4760. }
  4761. }
  4762. if !repeat {
  4763. newArr = append(newArr, arr[i])
  4764. }
  4765. }
  4766. return
  4767. }