his_api_controller.go 159KB

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