his_api_controller.go 154KB

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