his_api_controller.go 180KB

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