his_api_controller.go 162KB

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