his_api_controller.go 154KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543
  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. PdnCashPay string `json:"pdn_cash_pay"`
  815. } `json:"setlinfo"`
  816. } `json:"output"`
  817. RefmsgTime string `json:"refmsg_time"`
  818. RespondTime string `json:"respond_time"`
  819. Signtype interface{} `json:"signtype"`
  820. WarnMsg interface{} `json:"warn_msg"`
  821. }
  822. type Custom struct {
  823. DetItemFeeSumamt string
  824. Cut string
  825. FeedetlSn string
  826. Price string
  827. MedListCodg string
  828. Type int64
  829. AdviceId int64
  830. ProjectId int64
  831. ItemId int64
  832. }
  833. //获取个人信息----挂号-----上传就诊信息
  834. func (c *HisApiController) GetRegisterInfo() {
  835. id, _ := c.GetInt64("id")
  836. record_time := c.GetString("record_time")
  837. settlementValue, _ := c.GetInt64("settlement_value")
  838. medical_insurance_card := c.GetString("medical_insurance_card")
  839. name := c.GetString("name")
  840. id_card_type, _ := c.GetInt64("id_card_type")
  841. certificates, _ := c.GetInt64("certificates")
  842. medical_care, _ := c.GetInt64("medical_care")
  843. birthday := c.GetString("birthday")
  844. age, _ := c.GetInt64("age")
  845. id_card := c.GetString("id_card")
  846. register_type, _ := c.GetInt64("register")
  847. doctor, _ := c.GetInt64("doctor")
  848. department, _ := c.GetInt64("department")
  849. gender, _ := c.GetInt64("sex")
  850. phone := c.GetString("phone")
  851. registration_fee, _ := c.GetFloat("registration_fee")
  852. medical_expenses, _ := c.GetFloat("medical_expenses")
  853. social_type, _ := c.GetInt64("social_type")
  854. admin_user_id, _ := c.GetInt64("admin_user_id")
  855. diagnosis_id, _ := c.GetInt64("diagnosis")
  856. sick_type, _ := c.GetInt64("sick_type")
  857. reg_type := c.GetString("p_type")
  858. timeLayout := "2006-01-02"
  859. loc, _ := time.LoadLocation("Local")
  860. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  861. birthUnix := birthdays.Unix()
  862. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  863. if err != nil {
  864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  865. return
  866. }
  867. recordDateTime := theTime.Unix()
  868. adminInfo := c.GetAdminUserInfo()
  869. var patient service.Patients
  870. if id == 0 {
  871. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  872. } else {
  873. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  874. }
  875. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  876. if patientPrescription.ID == 0 {
  877. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  878. }
  879. //adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  880. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  881. sickConfig, _ := service.FindSickById(sick_type)
  882. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  883. if patient.ID == 0 {
  884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  885. return
  886. }
  887. if len(patient.IdCardNo) == 0 {
  888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  889. return
  890. }
  891. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  892. if config.IsOpen == 1 {
  893. 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
  894. resp, requestErr := http.Get(api)
  895. if requestErr != nil {
  896. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  897. return
  898. }
  899. defer resp.Body.Close()
  900. body, ioErr := ioutil.ReadAll(resp.Body)
  901. if ioErr != nil {
  902. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  904. return
  905. }
  906. var respJSON map[string]interface{}
  907. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  908. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  910. return
  911. }
  912. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  913. userJSONBytes, _ := json.Marshal(userJSON)
  914. var res ResultTwo
  915. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  916. utils.ErrorLog("解析失败:%v", err)
  917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  918. return
  919. }
  920. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  921. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  922. infoStr := string(Iinfos)
  923. idetinfoStr := string(Idetinfos)
  924. if res.Infcode == 0 {
  925. his := models.VMHisPatient{
  926. Name: name,
  927. Gender: gender,
  928. Birthday: birthUnix,
  929. MedicalTreatmentType: medical_care,
  930. IdType: certificates,
  931. IdCardNo: id_card,
  932. BalanceAccountsType: settlementValue,
  933. SocialType: social_type,
  934. MedicalInsuranceNumber: medical_insurance_card,
  935. RegisterType: register_type,
  936. RegisterCost: registration_fee,
  937. TreatmentCost: medical_expenses,
  938. Status: 1,
  939. Ctime: time.Now().Unix(),
  940. Mtime: time.Now().Unix(),
  941. PsnNo: res.Output.Baseinfo.PsnNo,
  942. PsnCertType: res.Output.Baseinfo.PsnCertType,
  943. Certno: res.Output.Baseinfo.Certno,
  944. PsnName: res.Output.Baseinfo.PsnName,
  945. Gend: res.Output.Baseinfo.Gend,
  946. Naty: res.Output.Baseinfo.Naty,
  947. Brdy: res.Output.Baseinfo.Brdy,
  948. Age: res.Output.Baseinfo.Age,
  949. Iinfo: infoStr,
  950. Idetinfo: idetinfoStr,
  951. PatientId: patient.ID,
  952. RecordDate: theTime.Unix(),
  953. UserOrgId: adminInfo.CurrentOrgId,
  954. AdminUserId: admin_user_id,
  955. IsReturn: 1,
  956. IdCardType: id_card_type,
  957. Doctor: doctor,
  958. Departments: department,
  959. }
  960. timestamp := time.Now().Unix()
  961. tempTime := time.Unix(timestamp, 0)
  962. timeFormat := tempTime.Format("20060102150405")
  963. chrgBchno := rand.Intn(100000) + 10000
  964. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  965. //count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  966. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  967. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  968. IdCardNo := ""
  969. if id_card_type == 1 {
  970. IdCardNo = medical_insurance_card
  971. } else {
  972. IdCardNo = patient.IdCardNo
  973. }
  974. var insutypes []string
  975. var insutype string
  976. var is390 int = 0
  977. var is310 int = 0
  978. for _, item := range res.Output.Iinfo {
  979. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  980. insutypes = append(insutypes, item.Insutype)
  981. }
  982. }
  983. if len(insutypes) == 1 {
  984. insutype = insutypes[0]
  985. } else {
  986. for _, i := range insutypes {
  987. if i == "390" {
  988. is390 = 1
  989. }
  990. if i == "310" {
  991. is310 = 1
  992. }
  993. }
  994. }
  995. if is390 == 1 {
  996. insutype = "390"
  997. }
  998. if is310 == 1 {
  999. insutype = "310"
  1000. }
  1001. api := "http://127.0.0.1:9532/" + "gdyb/two?cert_no=" + IdCardNo + "&insutype=" +
  1002. insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  1003. "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  1004. "&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)
  1005. resp, requestErr := http.Get(api)
  1006. if requestErr != nil {
  1007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1008. return
  1009. }
  1010. defer resp.Body.Close()
  1011. body, ioErr := ioutil.ReadAll(resp.Body)
  1012. if ioErr != nil {
  1013. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1014. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1015. return
  1016. }
  1017. var respJSON map[string]interface{}
  1018. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1019. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1021. return
  1022. }
  1023. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1024. userJSONBytes, _ := json.Marshal(respJSON)
  1025. var res ResultThree
  1026. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1027. utils.ErrorLog("解析失败:%v", err)
  1028. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1029. return
  1030. }
  1031. if res.Infcode == -1 {
  1032. adminUser := c.GetAdminUserInfo()
  1033. errlog := &models.HisOrderError{
  1034. UserOrgId: adminUser.CurrentOrgId,
  1035. Ctime: time.Now().Unix(),
  1036. Mtime: time.Now().Unix(),
  1037. ErrMsg: res.ErrMsg,
  1038. Status: 1,
  1039. PatientId: id,
  1040. RecordTime: recordDateTime,
  1041. Stage: 2,
  1042. }
  1043. service.CreateErrMsgLog(errlog)
  1044. c.ServeSuccessJSON(map[string]interface{}{
  1045. "failed_code": -10,
  1046. "msg": res.ErrMsg,
  1047. })
  1048. return
  1049. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  1050. //return
  1051. }
  1052. his.Number = res.Output.Data.MdtrtID
  1053. his.PsnNo = res.Output.Data.PsnNo
  1054. his.IptOtpNo = res.Output.Data.IptOtpNo
  1055. his.IdCardNo = patient.IdCardNo
  1056. his.PhoneNumber = patient.Phone
  1057. his.UserOrgId = adminInfo.CurrentOrgId
  1058. his.Ctime = time.Now().Unix()
  1059. his.Mtime = time.Now().Unix()
  1060. his.Status = 1
  1061. err := service.CreateHisPatientTwo(&his)
  1062. if err == nil {
  1063. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  1064. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  1065. "&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 +
  1066. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  1067. resp2, requestErr2 := http.Get(api2)
  1068. if requestErr2 != nil {
  1069. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1070. return
  1071. }
  1072. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  1073. if ioErr2 != nil {
  1074. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  1075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1076. return
  1077. }
  1078. var respJSON2 map[string]interface{}
  1079. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  1080. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1082. return
  1083. }
  1084. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1085. userJSONBytes2, _ := json.Marshal(respJSON2)
  1086. var res2 ResultSix
  1087. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  1088. utils.ErrorLog("解析失败:%v", err)
  1089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1090. return
  1091. }
  1092. if res2.Infcode == -1 {
  1093. adminUser := c.GetAdminUserInfo()
  1094. errlog := &models.HisOrderError{
  1095. UserOrgId: adminUser.CurrentOrgId,
  1096. Ctime: time.Now().Unix(),
  1097. Mtime: time.Now().Unix(),
  1098. ErrMsg: res2.ErrMsg,
  1099. Status: 1,
  1100. PatientId: id,
  1101. RecordTime: recordDateTime,
  1102. Stage: 3,
  1103. }
  1104. service.CreateErrMsgLog(errlog)
  1105. c.ServeSuccessJSON(map[string]interface{}{
  1106. "failed_code": -10,
  1107. "msg": res2.ErrMsg,
  1108. })
  1109. return
  1110. } else {
  1111. c.ServeSuccessJSON(map[string]interface{}{
  1112. "his_info": his,
  1113. })
  1114. }
  1115. } else {
  1116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1117. return
  1118. }
  1119. } else {
  1120. adminUser := c.GetAdminUserInfo()
  1121. errlog := &models.HisOrderError{
  1122. UserOrgId: adminUser.CurrentOrgId,
  1123. Ctime: time.Now().Unix(),
  1124. Mtime: time.Now().Unix(),
  1125. ErrMsg: res.ErrMsg,
  1126. Status: 1,
  1127. PatientId: id,
  1128. RecordTime: recordDateTime,
  1129. Stage: 1,
  1130. }
  1131. service.CreateErrMsgLog(errlog)
  1132. c.ServeSuccessJSON(map[string]interface{}{
  1133. "failed_code": -10,
  1134. "msg": res.ErrMsg,
  1135. })
  1136. return
  1137. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  1138. }
  1139. } else {
  1140. timeStr := time.Now().Format("2006-01-02")
  1141. timeArr := strings.Split(timeStr, "-")
  1142. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
  1143. his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  1144. var hisPatient models.XtHisPatient
  1145. if err == gorm.ErrRecordNotFound || his.ID == 0 {
  1146. hisPatient = models.XtHisPatient{
  1147. Name: name,
  1148. Age: age,
  1149. Gender: gender,
  1150. Birthday: birthUnix,
  1151. Phone: phone,
  1152. MedicalTreatmentType: medical_care,
  1153. IdType: certificates,
  1154. IdCardNo: id_card,
  1155. BalanceAccountsType: settlementValue,
  1156. SocialType: social_type,
  1157. MedicalInsuranceNumber: medical_insurance_card,
  1158. RegisterType: register_type,
  1159. RegisterCost: registration_fee,
  1160. TreatmentCost: medical_expenses,
  1161. AdminUserId: admin_user_id,
  1162. UserOrgId: adminInfo.CurrentOrgId,
  1163. Status: 1,
  1164. RecordDate: recordDateTime,
  1165. IsReturn: 1,
  1166. PatientId: patient.ID,
  1167. Ctime: time.Now().Unix(),
  1168. Mtime: time.Now().Unix(),
  1169. Number: str,
  1170. }
  1171. service.CreateHisPatient(&hisPatient)
  1172. }
  1173. c.ServeSuccessJSON(map[string]interface{}{
  1174. "his_info": hisPatient,
  1175. })
  1176. }
  1177. }
  1178. //上传明细----预结算----确认订单
  1179. func (c *HisApiController) GetUploadInfo() {
  1180. id, _ := c.GetInt64("id")
  1181. record_time := c.GetString("record_time")
  1182. pay_way, _ := c.GetInt64("pay_way")
  1183. pay_price, _ := c.GetFloat("pay_price")
  1184. pay_card_no := c.GetString("pay_card_no")
  1185. discount_price, _ := c.GetFloat("discount_price")
  1186. preferential_price, _ := c.GetFloat("preferential_price")
  1187. reality_price, _ := c.GetFloat("reality_price")
  1188. found_price, _ := c.GetFloat("found_price")
  1189. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1190. private_price, _ := c.GetFloat("private_price")
  1191. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1192. admin_user_id, _ := c.GetInt64("admin_user_id")
  1193. timeLayout := "2006-01-02"
  1194. loc, _ := time.LoadLocation("Local")
  1195. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1196. if err != nil {
  1197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1198. return
  1199. }
  1200. recordDateTime := theTime.Unix()
  1201. adminUser := c.GetAdminUserInfo()
  1202. var prescriptions []*models.HisPrescription
  1203. var start_time int64
  1204. var end_time int64
  1205. data := make(map[string]interface{})
  1206. if settle_accounts_type == 1 { //日结
  1207. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1208. data["pre"] = prescriptions
  1209. } else { //月结
  1210. start_time_str := c.GetString("start_time")
  1211. end_time_str := c.GetString("end_time")
  1212. timeLayout := "2006-01-02"
  1213. loc, _ := time.LoadLocation("Local")
  1214. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1215. if err != nil {
  1216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1217. return
  1218. }
  1219. recordStartTime := theStartTime.Unix()
  1220. start_time = recordStartTime
  1221. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1222. if err != nil {
  1223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1224. return
  1225. }
  1226. recordEndTime := theEndTime.Unix()
  1227. end_time = recordEndTime
  1228. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1229. data["pre"] = prescriptions
  1230. }
  1231. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1232. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1233. timestamp := time.Now().Unix()
  1234. tempTime := time.Unix(timestamp, 0)
  1235. timeFormat := tempTime.Format("20060102150405")
  1236. chrgBchno := rand.Intn(100000) + 10000
  1237. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1238. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1239. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1240. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1241. strconv.FormatInt(his.PatientId, 10)
  1242. client := &http.Client{}
  1243. data["psn_no"] = his.PsnNo
  1244. data["mdtrt_id"] = his.Number
  1245. data["chrg_bchno"] = chrg_bchno
  1246. data["org_name"] = miConfig.OrgName
  1247. data["doctor"] = roles.UserName
  1248. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1249. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  1250. data["fixmedins_code"] = miConfig.Code
  1251. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  1252. data["dept_code"] = "15"
  1253. } else {
  1254. data["dept_code"] = department.Number
  1255. }
  1256. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1257. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1258. data["secret_key"] = miConfig.SecretKey
  1259. var ids []int64
  1260. for _, item := range prescriptions {
  1261. ids = append(ids, item.ID)
  1262. }
  1263. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1264. if config.IsOpen == 1 { //对接了医保,走医保流程
  1265. bytesData, _ := json.Marshal(data)
  1266. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  1267. resp, _ := client.Do(req)
  1268. defer resp.Body.Close()
  1269. body, ioErr := ioutil.ReadAll(resp.Body)
  1270. if ioErr != nil {
  1271. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1273. return
  1274. }
  1275. var respJSON map[string]interface{}
  1276. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1277. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1279. return
  1280. }
  1281. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1282. userJSONBytes, _ := json.Marshal(respJSON)
  1283. var res ResultFour
  1284. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1285. utils.ErrorLog("解析失败:%v", err)
  1286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1287. return
  1288. }
  1289. if res.Infcode == 0 {
  1290. order := &models.HisOrder{
  1291. UserOrgId: adminUser.CurrentOrgId,
  1292. HisPatientId: his.ID,
  1293. PatientId: his.PatientId,
  1294. SettleAccountsDate: recordDateTime,
  1295. Ctime: time.Now().Unix(),
  1296. Mtime: time.Now().Unix(),
  1297. Status: 1,
  1298. Number: chrg_bchno,
  1299. Infcode: res.Infcode,
  1300. WarnMsg: res.WarnMsg,
  1301. Cainfo: res.Cainfo,
  1302. ErrMsg: res.ErrMsg,
  1303. RespondTime: res.RefmsgTime,
  1304. InfRefmsgid: res.InfRefmsgid,
  1305. OrderStatus: 1,
  1306. PayWay: pay_way,
  1307. PayPrice: pay_price,
  1308. PayCardNo: pay_card_no,
  1309. DiscountPrice: discount_price,
  1310. PreferentialPrice: preferential_price,
  1311. RealityPrice: reality_price,
  1312. FoundPrice: found_price,
  1313. MedicalInsurancePrice: medical_insurance_price,
  1314. PrivatePrice: private_price,
  1315. IsMedicineInsurance: 1,
  1316. SettleType: settle_accounts_type,
  1317. SettleStartTime: start_time,
  1318. SettleEndTime: end_time,
  1319. Creator: roles.AdminUserId,
  1320. Modify: roles.AdminUserId,
  1321. }
  1322. err = service.CreateOrder(order)
  1323. if err != nil {
  1324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1325. return
  1326. }
  1327. for _, item := range res.Output.Result {
  1328. temp := strings.Split(item.FeedetlSn, "-")
  1329. var advice_id int64 = 0
  1330. var project_id int64 = 0
  1331. var types int64 = 0
  1332. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1333. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1334. if temp[1] == "1" {
  1335. advice_id = id
  1336. project_id = 0
  1337. } else if temp[1] == "2" {
  1338. advice_id = 0
  1339. project_id = id
  1340. }
  1341. info := &models.HisOrderInfo{
  1342. OrderNumber: order.Number,
  1343. FeedetlSn: item.FeedetlSn,
  1344. UploadDate: time.Now().Unix(),
  1345. AdviceId: advice_id,
  1346. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1347. Cnt: item.Cnt,
  1348. Pric: float64(item.Pric),
  1349. PatientId: his.PatientId,
  1350. PricUplmtAmt: item.PricUplmtAmt,
  1351. SelfpayProp: item.SelfpayProp,
  1352. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1353. OverlmtAmt: item.OverlmtAmt,
  1354. PreselfpayAmt: item.PreselfpayAmt,
  1355. BasMednFlag: item.BasMednFlag,
  1356. MedChrgitmType: item.MedChrgitmType,
  1357. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1358. Status: 1,
  1359. Memo: item.Memo,
  1360. Mtime: time.Now().Unix(),
  1361. InscpScpAmt: item.InscpScpAmt,
  1362. DrtReimFlag: item.DrtReimFlag,
  1363. Ctime: time.Now().Unix(),
  1364. ListSpItemFlag: item.ListSpItemFlag,
  1365. ChldMedcFlag: item.ChldMedcFlag,
  1366. LmtUsedFlag: item.LmtUsedFlag,
  1367. ChrgitmLv: item.ChrgitmLv,
  1368. UserOrgId: adminUser.CurrentOrgId,
  1369. HisPatientId: his.ID,
  1370. OrderId: order.ID,
  1371. ProjectId: project_id,
  1372. Type: types,
  1373. }
  1374. service.CreateOrderInfo(info)
  1375. }
  1376. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1377. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1378. var total float64
  1379. for _, item := range prescriptions {
  1380. if item.Type == 1 { //药品
  1381. for _, subItem := range item.HisDoctorAdviceInfo {
  1382. total = total + (subItem.Price * subItem.PrescribingNumber)
  1383. }
  1384. }
  1385. if item.Type == 2 { //项目
  1386. for _, subItem := range item.HisPrescriptionProject {
  1387. total = total + (subItem.Price * float64(subItem.Count))
  1388. }
  1389. }
  1390. }
  1391. for _, item := range prescriptions {
  1392. for _, subItem := range item.HisAdditionalCharge {
  1393. total = total + (subItem.Price * float64(subItem.Count))
  1394. }
  1395. }
  1396. allTotal := fmt.Sprintf("%.2f", total)
  1397. if res.Infcode == 0 {
  1398. var rf []*ResultFive
  1399. json.Unmarshal([]byte(his.Iinfo), &rf)
  1400. chrg_bchno := chrg_bchno
  1401. cert_no := his.Certno
  1402. var insutypes []string
  1403. var insutype string
  1404. var is390 int = 0
  1405. var is310 int = 0
  1406. for _, item := range rf {
  1407. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1408. insutypes = append(insutypes, item.Insutype)
  1409. }
  1410. }
  1411. if len(insutypes) == 1 {
  1412. insutype = insutypes[0]
  1413. } else {
  1414. for _, i := range insutypes {
  1415. if i == "390" {
  1416. is390 = 1
  1417. }
  1418. if i == "310" {
  1419. is310 = 1
  1420. }
  1421. }
  1422. }
  1423. if is390 == 1 {
  1424. insutype = "390"
  1425. }
  1426. if is310 == 1 {
  1427. insutype = "310"
  1428. }
  1429. if his.IdCardType == 1 {
  1430. cert_no = his.MedicalInsuranceNumber
  1431. } else {
  1432. cert_no = his.Certno
  1433. }
  1434. 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)
  1435. var dat map[string]interface{}
  1436. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1437. fmt.Println(dat)
  1438. } else {
  1439. fmt.Println(err)
  1440. }
  1441. userJSONBytes, _ := json.Marshal(dat)
  1442. var res ResultSeven
  1443. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1444. utils.ErrorLog("解析失败:%v", err)
  1445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1446. return
  1447. }
  1448. if res.Infcode == -1 {
  1449. errlog := &models.HisOrderError{
  1450. UserOrgId: adminUser.CurrentOrgId,
  1451. Ctime: time.Now().Unix(),
  1452. Mtime: time.Now().Unix(),
  1453. Number: chrg_bchno,
  1454. ErrMsg: res.ErrMsg,
  1455. Status: 1,
  1456. PatientId: id,
  1457. RecordTime: recordDateTime,
  1458. Stage: 6,
  1459. }
  1460. service.CreateErrMsgLog(errlog)
  1461. c.ServeSuccessJSON(map[string]interface{}{
  1462. "failed_code": -10,
  1463. "msg": res.ErrMsg,
  1464. })
  1465. return
  1466. } else {
  1467. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1468. order.OrderStatus = 2
  1469. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1470. order.SetlId = res.Output.Setlinfo.SetlID
  1471. order.PsnNo = res.Output.Setlinfo.PsnNo
  1472. order.PsnName = res.Output.Setlinfo.PsnName
  1473. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1474. order.Certno = res.Output.Setlinfo.Certno
  1475. order.Gend = res.Output.Setlinfo.Gend
  1476. order.Naty = res.Output.Setlinfo.Naty
  1477. order.Age = res.Output.Setlinfo.Age
  1478. order.Insutype = res.Output.Setlinfo.Insutype
  1479. order.PsnType = res.Output.Setlinfo.PsnType
  1480. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1481. order.SetlTime = res.Output.Setlinfo.SetlTime
  1482. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1483. order.MedType = res.Output.Setlinfo.MedType
  1484. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1485. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1486. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1487. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1488. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1489. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1490. order.HifpPay = res.Output.Setlinfo.HifpPay
  1491. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1492. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1493. order.HifesPay = res.Output.Setlinfo.HifesPay
  1494. order.HifobPay = res.Output.Setlinfo.HifobPay
  1495. order.MafPay = res.Output.Setlinfo.MafPay
  1496. order.OthPay = res.Output.Setlinfo.OthPay
  1497. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1498. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1499. order.AcctPay = res.Output.Setlinfo.AcctPay
  1500. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1501. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1502. order.Balc = res.Output.Setlinfo.Balc
  1503. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1504. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1505. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1506. order.ClrWay = res.Output.Setlinfo.ClrWay
  1507. order.Creator = order.Creator
  1508. order.Modify = roles.AdminUserId
  1509. order.RequestLog = src_resquest
  1510. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1511. detailStr := string(setlDetail)
  1512. order.SetlDetail = detailStr
  1513. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1514. err = service.UpDateOrder(order)
  1515. if err == nil {
  1516. c.ServeSuccessJSON(map[string]interface{}{
  1517. "msg": "结算成功",
  1518. })
  1519. } else {
  1520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1521. return
  1522. }
  1523. }
  1524. } else {
  1525. adminUser := c.GetAdminUserInfo()
  1526. errlog := &models.HisOrderError{
  1527. UserOrgId: adminUser.CurrentOrgId,
  1528. Ctime: time.Now().Unix(),
  1529. Mtime: time.Now().Unix(),
  1530. ErrMsg: res.ErrMsg,
  1531. Status: 1,
  1532. PatientId: id,
  1533. RecordTime: recordDateTime,
  1534. Stage: 4,
  1535. }
  1536. service.CreateErrMsgLog(errlog)
  1537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1538. return
  1539. }
  1540. } else {
  1541. adminUser := c.GetAdminUserInfo()
  1542. errlog := &models.HisOrderError{
  1543. UserOrgId: adminUser.CurrentOrgId,
  1544. Ctime: time.Now().Unix(),
  1545. Mtime: time.Now().Unix(),
  1546. ErrMsg: res.ErrMsg,
  1547. Status: 1,
  1548. PatientId: id,
  1549. RecordTime: recordDateTime,
  1550. Stage: 4,
  1551. }
  1552. service.CreateErrMsgLog(errlog)
  1553. c.ServeSuccessJSON(map[string]interface{}{
  1554. "failed_code": -10,
  1555. "msg": res.ErrMsg,
  1556. })
  1557. return
  1558. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  1559. //return
  1560. }
  1561. } else {
  1562. var total float64
  1563. for _, item := range prescriptions {
  1564. if item.Type == 1 { //药品
  1565. for _, subItem := range item.HisDoctorAdviceInfo {
  1566. total = total + (subItem.Price * subItem.PrescribingNumber)
  1567. }
  1568. }
  1569. if item.Type == 2 { //项目
  1570. for _, subItem := range item.HisPrescriptionProject {
  1571. total = total + (subItem.Price * float64(subItem.Count))
  1572. }
  1573. }
  1574. for _, subItem := range item.HisAdditionalCharge {
  1575. total = total + (subItem.Price * float64(subItem.Count))
  1576. }
  1577. }
  1578. allTotal := fmt.Sprintf("%.2f", total)
  1579. totals, _ := strconv.ParseFloat(allTotal, 64)
  1580. order := &models.HisOrder{
  1581. UserOrgId: adminUser.CurrentOrgId,
  1582. HisPatientId: his.ID,
  1583. PatientId: id,
  1584. SettleAccountsDate: recordDateTime,
  1585. Ctime: time.Now().Unix(),
  1586. Mtime: time.Now().Unix(),
  1587. Status: 1,
  1588. OrderStatus: 2,
  1589. Number: chrg_bchno,
  1590. MedfeeSumamt: totals,
  1591. PayWay: pay_way,
  1592. PayPrice: pay_price,
  1593. PayCardNo: pay_card_no,
  1594. DiscountPrice: discount_price,
  1595. PreferentialPrice: preferential_price,
  1596. RealityPrice: reality_price,
  1597. FoundPrice: found_price,
  1598. MedicalInsurancePrice: medical_insurance_price,
  1599. PrivatePrice: private_price,
  1600. }
  1601. err = service.CreateOrder(order)
  1602. if err != nil {
  1603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1604. return
  1605. }
  1606. var customs []*Custom
  1607. for _, item := range prescriptions {
  1608. if item.Type == 1 { //药品
  1609. for _, subItem := range item.HisDoctorAdviceInfo {
  1610. cus := &Custom{
  1611. AdviceId: subItem.ID,
  1612. ProjectId: 0,
  1613. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  1614. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  1615. FeedetlSn: subItem.FeedetlSn,
  1616. Price: fmt.Sprintf("%.2f", subItem.Price),
  1617. MedListCodg: subItem.MedListCodg,
  1618. Type: 1,
  1619. }
  1620. customs = append(customs, cus)
  1621. }
  1622. }
  1623. if item.Type == 2 { //项目
  1624. for _, subItem := range item.HisPrescriptionProject {
  1625. cus := &Custom{
  1626. AdviceId: 0,
  1627. ProjectId: subItem.ID,
  1628. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  1629. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  1630. FeedetlSn: subItem.FeedetlSn,
  1631. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  1632. MedListCodg: subItem.MedListCodg,
  1633. Type: 2,
  1634. }
  1635. customs = append(customs, cus)
  1636. }
  1637. }
  1638. for _, item := range item.HisAdditionalCharge {
  1639. cus := &Custom{
  1640. ItemId: item.ID,
  1641. AdviceId: 0,
  1642. ProjectId: 0,
  1643. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  1644. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  1645. FeedetlSn: item.FeedetlSn,
  1646. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  1647. MedListCodg: item.XtHisAddtionConfig.Code,
  1648. Type: 3,
  1649. }
  1650. customs = append(customs, cus)
  1651. }
  1652. }
  1653. for _, item := range customs {
  1654. var advice_id int64 = 0
  1655. var project_id int64 = 0
  1656. var item_id int64 = 0
  1657. var types int64 = 0
  1658. if item.Type == 1 {
  1659. advice_id = item.AdviceId
  1660. project_id = 0
  1661. item_id = 0
  1662. } else if item.Type == 2 {
  1663. advice_id = 0
  1664. item_id = 0
  1665. project_id = item.ProjectId
  1666. } else if item.Type == 3 {
  1667. advice_id = 0
  1668. item_id = item.ItemId
  1669. project_id = 0
  1670. }
  1671. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  1672. cut, _ := strconv.ParseFloat(item.Cut, 32)
  1673. pric, _ := strconv.ParseFloat(item.Price, 32)
  1674. info := &models.HisOrderInfo{
  1675. OrderNumber: order.Number,
  1676. UploadDate: time.Now().Unix(),
  1677. AdviceId: advice_id,
  1678. DetItemFeeSumamt: detItemFeeSumamt,
  1679. Cnt: cut,
  1680. Pric: pric,
  1681. PatientId: id,
  1682. Status: 1,
  1683. Mtime: time.Now().Unix(),
  1684. Ctime: time.Now().Unix(),
  1685. UserOrgId: adminUser.CurrentOrgId,
  1686. HisPatientId: his.ID,
  1687. OrderId: order.ID,
  1688. ProjectId: project_id,
  1689. Type: types,
  1690. ItemId: item_id,
  1691. }
  1692. service.CreateOrderInfo(info)
  1693. }
  1694. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1695. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1696. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  1697. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1698. if err == nil {
  1699. c.ServeSuccessJSON(map[string]interface{}{
  1700. "msg": "结算成功",
  1701. })
  1702. } else {
  1703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1704. return
  1705. }
  1706. }
  1707. }
  1708. func (c *HisApiController) GetPreUploadInfo() {
  1709. id, _ := c.GetInt64("id")
  1710. record_time := c.GetString("record_time")
  1711. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1712. admin_user_id, _ := c.GetInt64("admin_user_id")
  1713. timeLayout := "2006-01-02"
  1714. loc, _ := time.LoadLocation("Local")
  1715. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1716. if err != nil {
  1717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1718. return
  1719. }
  1720. recordDateTime := theTime.Unix()
  1721. adminUser := c.GetAdminUserInfo()
  1722. var prescriptions []*models.HisPrescription
  1723. var start_time int64
  1724. var end_time int64
  1725. data := make(map[string]interface{})
  1726. if settle_accounts_type == 1 { //日结
  1727. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1728. data["pre"] = prescriptions
  1729. } else { //月结
  1730. start_time_str := c.GetString("start_time")
  1731. end_time_str := c.GetString("end_time")
  1732. timeLayout := "2006-01-02"
  1733. loc, _ := time.LoadLocation("Local")
  1734. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1735. if err != nil {
  1736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1737. return
  1738. }
  1739. recordStartTime := theStartTime.Unix()
  1740. start_time = recordStartTime
  1741. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1742. if err != nil {
  1743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1744. return
  1745. }
  1746. recordEndTime := theEndTime.Unix()
  1747. end_time = recordEndTime
  1748. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1749. data["pre"] = prescriptions
  1750. }
  1751. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1752. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1753. timestamp := time.Now().Unix()
  1754. tempTime := time.Unix(timestamp, 0)
  1755. timeFormat := tempTime.Format("20060102150405")
  1756. chrgBchno := rand.Intn(100000) + 10000
  1757. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1758. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1759. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1760. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1761. strconv.FormatInt(his.PatientId, 10)
  1762. client := &http.Client{}
  1763. data["psn_no"] = his.PsnNo
  1764. data["mdtrt_id"] = his.Number
  1765. data["chrg_bchno"] = chrg_bchno
  1766. data["org_name"] = miConfig.OrgName
  1767. data["doctor"] = roles.UserName
  1768. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1769. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  1770. data["fixmedins_code"] = miConfig.Code
  1771. data["dept_code"] = department.Number
  1772. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1773. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1774. data["secret_key"] = miConfig.SecretKey
  1775. var ids []int64
  1776. for _, item := range prescriptions {
  1777. ids = append(ids, item.ID)
  1778. }
  1779. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1780. if config.IsOpen == 1 { //对接了医保,走医保流程
  1781. bytesData, _ := json.Marshal(data)
  1782. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  1783. resp, _ := client.Do(req)
  1784. defer resp.Body.Close()
  1785. body, ioErr := ioutil.ReadAll(resp.Body)
  1786. if ioErr != nil {
  1787. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1789. return
  1790. }
  1791. var respJSON map[string]interface{}
  1792. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1793. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1795. return
  1796. }
  1797. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1798. userJSONBytes, _ := json.Marshal(respJSON)
  1799. var res ResultFour
  1800. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1801. utils.ErrorLog("解析失败:%v", err)
  1802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1803. return
  1804. }
  1805. if res.Infcode == 0 {
  1806. order := &models.HisOrder{
  1807. UserOrgId: adminUser.CurrentOrgId,
  1808. HisPatientId: his.ID,
  1809. PatientId: his.PatientId,
  1810. SettleAccountsDate: recordDateTime,
  1811. Ctime: time.Now().Unix(),
  1812. Mtime: time.Now().Unix(),
  1813. Status: 1,
  1814. Number: chrg_bchno,
  1815. Infcode: res.Infcode,
  1816. WarnMsg: res.WarnMsg,
  1817. Cainfo: res.Cainfo,
  1818. ErrMsg: res.ErrMsg,
  1819. RespondTime: res.RefmsgTime,
  1820. InfRefmsgid: res.InfRefmsgid,
  1821. OrderStatus: 1,
  1822. IsMedicineInsurance: 1,
  1823. SettleType: settle_accounts_type,
  1824. SettleStartTime: start_time,
  1825. SettleEndTime: end_time,
  1826. Creator: roles.ID,
  1827. Modify: roles.ID,
  1828. }
  1829. err = service.CreateOrder(order)
  1830. if err != nil {
  1831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1832. return
  1833. }
  1834. for _, item := range res.Output.Result {
  1835. temp := strings.Split(item.FeedetlSn, "-")
  1836. var advice_id int64 = 0
  1837. var project_id int64 = 0
  1838. var types int64 = 0
  1839. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1840. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1841. if temp[1] == "1" {
  1842. advice_id = id
  1843. project_id = 0
  1844. } else if temp[1] == "2" {
  1845. advice_id = 0
  1846. project_id = id
  1847. }
  1848. info := &models.HisOrderInfo{
  1849. OrderNumber: order.Number,
  1850. FeedetlSn: item.FeedetlSn,
  1851. UploadDate: time.Now().Unix(),
  1852. AdviceId: advice_id,
  1853. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1854. Cnt: item.Cnt,
  1855. Pric: float64(item.Pric),
  1856. PatientId: his.PatientId,
  1857. PricUplmtAmt: item.PricUplmtAmt,
  1858. SelfpayProp: item.SelfpayProp,
  1859. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1860. OverlmtAmt: item.OverlmtAmt,
  1861. PreselfpayAmt: item.PreselfpayAmt,
  1862. BasMednFlag: item.BasMednFlag,
  1863. MedChrgitmType: item.MedChrgitmType,
  1864. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1865. Status: 1,
  1866. Memo: item.Memo,
  1867. Mtime: time.Now().Unix(),
  1868. InscpScpAmt: item.InscpScpAmt,
  1869. DrtReimFlag: item.DrtReimFlag,
  1870. Ctime: time.Now().Unix(),
  1871. ListSpItemFlag: item.ListSpItemFlag,
  1872. ChldMedcFlag: item.ChldMedcFlag,
  1873. LmtUsedFlag: item.LmtUsedFlag,
  1874. ChrgitmLv: item.ChrgitmLv,
  1875. UserOrgId: adminUser.CurrentOrgId,
  1876. HisPatientId: his.ID,
  1877. OrderId: order.ID,
  1878. ProjectId: project_id,
  1879. Type: types,
  1880. }
  1881. service.CreateOrderInfo(info)
  1882. }
  1883. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1884. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1885. var total float64
  1886. for _, item := range prescriptions {
  1887. if item.Type == 1 { //药品
  1888. for _, subItem := range item.HisDoctorAdviceInfo {
  1889. total = total + (subItem.Price * subItem.PrescribingNumber)
  1890. }
  1891. }
  1892. if item.Type == 2 { //项目
  1893. for _, subItem := range item.HisPrescriptionProject {
  1894. total = total + (subItem.Price * float64(subItem.Count))
  1895. }
  1896. }
  1897. }
  1898. for _, item := range prescriptions {
  1899. for _, subItem := range item.HisAdditionalCharge {
  1900. total = total + (subItem.Price * float64(subItem.Count))
  1901. }
  1902. }
  1903. allTotal := fmt.Sprintf("%.2f", total)
  1904. if res.Infcode == 0 {
  1905. var rf []*ResultFive
  1906. json.Unmarshal([]byte(his.Iinfo), &rf)
  1907. psn_no := his.PsnNo
  1908. mdtrt_id := his.Number
  1909. chrg_bchno := chrg_bchno
  1910. cert_no := his.Certno
  1911. insutype := rf[0].Insutype
  1912. if his.IdCardType == 1 {
  1913. cert_no = his.MedicalInsuranceNumber
  1914. } else {
  1915. cert_no = his.Certno
  1916. }
  1917. api := "http://127.0.0.1:9532/" + "gdyb/seven?cert_no=" + cert_no + "&insutype=" +
  1918. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1919. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  1920. miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10)
  1921. resp, requestErr := http.Get(api)
  1922. if requestErr != nil {
  1923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1924. return
  1925. }
  1926. defer resp.Body.Close()
  1927. body, ioErr := ioutil.ReadAll(resp.Body)
  1928. if ioErr != nil {
  1929. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1931. return
  1932. }
  1933. var respJSON map[string]interface{}
  1934. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1935. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1937. return
  1938. }
  1939. fmt.Println(respJSON)
  1940. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1941. userJSONBytes, _ := json.Marshal(respJSON)
  1942. var res ResultSeven
  1943. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1944. utils.ErrorLog("解析失败:%v", err)
  1945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1946. return
  1947. }
  1948. if res.Infcode == -1 {
  1949. errlog := &models.HisOrderError{
  1950. UserOrgId: adminUser.CurrentOrgId,
  1951. Ctime: time.Now().Unix(),
  1952. Mtime: time.Now().Unix(),
  1953. Number: chrg_bchno,
  1954. ErrMsg: res.ErrMsg,
  1955. Status: 1,
  1956. PatientId: id,
  1957. RecordTime: recordDateTime,
  1958. Stage: 7,
  1959. }
  1960. service.CreateErrMsgLog(errlog)
  1961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1962. return
  1963. } else {
  1964. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1965. order.OrderStatus = 1
  1966. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1967. order.SetlId = res.Output.Setlinfo.SetlID
  1968. order.PsnNo = res.Output.Setlinfo.PsnNo
  1969. order.PsnName = res.Output.Setlinfo.PsnName
  1970. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1971. order.Certno = res.Output.Setlinfo.Certno
  1972. order.Gend = res.Output.Setlinfo.Gend
  1973. order.Naty = res.Output.Setlinfo.Naty
  1974. order.Age = res.Output.Setlinfo.Age
  1975. order.Insutype = res.Output.Setlinfo.Insutype
  1976. order.PsnType = res.Output.Setlinfo.PsnType
  1977. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1978. order.SetlTime = res.Output.Setlinfo.SetlTime
  1979. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1980. order.MedType = res.Output.Setlinfo.MedType
  1981. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1982. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1983. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1984. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1985. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1986. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1987. order.HifpPay = res.Output.Setlinfo.HifpPay
  1988. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1989. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1990. order.HifesPay = res.Output.Setlinfo.HifesPay
  1991. order.HifobPay = res.Output.Setlinfo.HifobPay
  1992. order.MafPay = res.Output.Setlinfo.MafPay
  1993. order.OthPay = res.Output.Setlinfo.OthPay
  1994. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1995. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1996. order.AcctPay = res.Output.Setlinfo.AcctPay
  1997. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1998. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1999. order.Balc = res.Output.Setlinfo.Balc
  2000. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2001. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2002. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2003. order.ClrWay = res.Output.Setlinfo.ClrWay
  2004. order.Creator = order.Creator
  2005. order.Modify = roles.ID
  2006. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2007. detailStr := string(setlDetail)
  2008. order.SetlDetail = detailStr
  2009. //err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2010. err = service.UpDateOrder(order)
  2011. if err == nil {
  2012. c.ServeSuccessJSON(map[string]interface{}{
  2013. "msg": "预结算成功",
  2014. })
  2015. } else {
  2016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2017. return
  2018. }
  2019. }
  2020. } else {
  2021. adminUser := c.GetAdminUserInfo()
  2022. errlog := &models.HisOrderError{
  2023. UserOrgId: adminUser.CurrentOrgId,
  2024. Ctime: time.Now().Unix(),
  2025. Mtime: time.Now().Unix(),
  2026. ErrMsg: res.ErrMsg,
  2027. Status: 1,
  2028. PatientId: id,
  2029. RecordTime: recordDateTime,
  2030. Stage: 4,
  2031. }
  2032. service.CreateErrMsgLog(errlog)
  2033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2034. return
  2035. }
  2036. } else {
  2037. adminUser := c.GetAdminUserInfo()
  2038. errlog := &models.HisOrderError{
  2039. UserOrgId: adminUser.CurrentOrgId,
  2040. Ctime: time.Now().Unix(),
  2041. Mtime: time.Now().Unix(),
  2042. ErrMsg: res.ErrMsg,
  2043. Status: 1,
  2044. PatientId: id,
  2045. RecordTime: recordDateTime,
  2046. Stage: 4,
  2047. }
  2048. service.CreateErrMsgLog(errlog)
  2049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  2050. return
  2051. }
  2052. } else {
  2053. var total float64
  2054. for _, item := range prescriptions {
  2055. if item.Type == 1 { //药品
  2056. for _, subItem := range item.HisDoctorAdviceInfo {
  2057. total = total + (subItem.Price * subItem.PrescribingNumber)
  2058. }
  2059. }
  2060. if item.Type == 2 { //项目
  2061. for _, subItem := range item.HisPrescriptionProject {
  2062. total = total + (subItem.Price * float64(subItem.Count))
  2063. }
  2064. }
  2065. for _, subItem := range item.HisAdditionalCharge {
  2066. total = total + (subItem.Price * float64(subItem.Count))
  2067. }
  2068. }
  2069. allTotal := fmt.Sprintf("%.2f", total)
  2070. totals, _ := strconv.ParseFloat(allTotal, 64)
  2071. order := &models.HisOrder{
  2072. UserOrgId: adminUser.CurrentOrgId,
  2073. HisPatientId: his.ID,
  2074. PatientId: id,
  2075. SettleAccountsDate: recordDateTime,
  2076. Ctime: time.Now().Unix(),
  2077. Mtime: time.Now().Unix(),
  2078. Status: 1,
  2079. OrderStatus: 2,
  2080. Number: chrg_bchno,
  2081. MedfeeSumamt: totals,
  2082. }
  2083. err = service.CreateOrder(order)
  2084. if err != nil {
  2085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2086. return
  2087. }
  2088. var customs []*Custom
  2089. for _, item := range prescriptions {
  2090. if item.Type == 1 { //药品
  2091. for _, subItem := range item.HisDoctorAdviceInfo {
  2092. cus := &Custom{
  2093. AdviceId: subItem.ID,
  2094. ProjectId: 0,
  2095. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  2096. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  2097. FeedetlSn: subItem.FeedetlSn,
  2098. Price: fmt.Sprintf("%.2f", subItem.Price),
  2099. MedListCodg: subItem.MedListCodg,
  2100. Type: 1,
  2101. }
  2102. customs = append(customs, cus)
  2103. }
  2104. }
  2105. if item.Type == 2 { //项目
  2106. for _, subItem := range item.HisPrescriptionProject {
  2107. cus := &Custom{
  2108. AdviceId: 0,
  2109. ProjectId: subItem.ID,
  2110. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  2111. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  2112. FeedetlSn: subItem.FeedetlSn,
  2113. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  2114. MedListCodg: subItem.MedListCodg,
  2115. Type: 2,
  2116. }
  2117. customs = append(customs, cus)
  2118. }
  2119. }
  2120. for _, item := range item.HisAdditionalCharge {
  2121. cus := &Custom{
  2122. ItemId: item.ID,
  2123. AdviceId: 0,
  2124. ProjectId: 0,
  2125. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  2126. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  2127. FeedetlSn: item.FeedetlSn,
  2128. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  2129. MedListCodg: item.XtHisAddtionConfig.Code,
  2130. Type: 3,
  2131. }
  2132. customs = append(customs, cus)
  2133. }
  2134. }
  2135. for _, item := range customs {
  2136. var advice_id int64 = 0
  2137. var project_id int64 = 0
  2138. var item_id int64 = 0
  2139. var types int64 = 0
  2140. if item.Type == 1 {
  2141. advice_id = item.AdviceId
  2142. project_id = 0
  2143. item_id = 0
  2144. } else if item.Type == 2 {
  2145. advice_id = 0
  2146. item_id = 0
  2147. project_id = item.ProjectId
  2148. } else if item.Type == 3 {
  2149. advice_id = 0
  2150. item_id = item.ItemId
  2151. project_id = 0
  2152. }
  2153. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  2154. cut, _ := strconv.ParseFloat(item.Cut, 32)
  2155. pric, _ := strconv.ParseFloat(item.Price, 32)
  2156. info := &models.HisOrderInfo{
  2157. OrderNumber: order.Number,
  2158. UploadDate: time.Now().Unix(),
  2159. AdviceId: advice_id,
  2160. DetItemFeeSumamt: detItemFeeSumamt,
  2161. Cnt: cut,
  2162. Pric: pric,
  2163. PatientId: id,
  2164. Status: 1,
  2165. Mtime: time.Now().Unix(),
  2166. Ctime: time.Now().Unix(),
  2167. UserOrgId: adminUser.CurrentOrgId,
  2168. HisPatientId: his.ID,
  2169. OrderId: order.ID,
  2170. ProjectId: project_id,
  2171. Type: types,
  2172. ItemId: item_id,
  2173. }
  2174. service.CreateOrderInfo(info)
  2175. }
  2176. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2177. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2178. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  2179. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2180. if err == nil {
  2181. c.ServeSuccessJSON(map[string]interface{}{
  2182. "msg": "结算成功",
  2183. })
  2184. } else {
  2185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2186. return
  2187. }
  2188. }
  2189. }
  2190. //func (c *HisApiController) GetSettleInfo() {
  2191. // id, _ := c.GetInt64("id")
  2192. // order_id, _ := c.GetInt64("order_id")
  2193. //
  2194. // record_time := c.GetString("record_time")
  2195. // pay_way, _ := c.GetInt64("pay_way")
  2196. // pay_price, _ := c.GetFloat("pay_price")
  2197. // pay_card_no := c.GetString("pay_card_no")
  2198. // discount_price, _ := c.GetFloat("discount_price")
  2199. // preferential_price, _ := c.GetFloat("preferential_price")
  2200. // reality_price, _ := c.GetFloat("reality_price")
  2201. // found_price, _ := c.GetFloat("found_price")
  2202. // medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2203. // private_price, _ := c.GetFloat("private_price")
  2204. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2205. // admin_user_id, _ := c.GetInt64("admin_user_id")
  2206. //
  2207. // timeLayout := "2006-01-02"
  2208. // loc, _ := time.LoadLocation("Local")
  2209. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2210. // if err != nil {
  2211. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2212. // return
  2213. // }
  2214. // recordDateTime := theTime.Unix()
  2215. // adminUser := c.GetAdminUserInfo()
  2216. //
  2217. // var prescriptions []*models.HisPrescription
  2218. //
  2219. // data := make(map[string]interface{})
  2220. // if settle_accounts_type == 1 { //日结
  2221. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  2222. // data["pre"] = prescriptions
  2223. //
  2224. // } else { //月结
  2225. // start_time_str := c.GetString("start_time")
  2226. // end_time_str := c.GetString("end_time")
  2227. // timeLayout := "2006-01-02"
  2228. // loc, _ := time.LoadLocation("Local")
  2229. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2230. // if err != nil {
  2231. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2232. // return
  2233. // }
  2234. // recordStartTime := theStartTime.Unix()
  2235. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2236. // if err != nil {
  2237. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2238. // return
  2239. // }
  2240. // recordEndTime := theEndTime.Unix()
  2241. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  2242. // data["pre"] = prescriptions
  2243. //
  2244. // }
  2245. //
  2246. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2247. //
  2248. // his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2249. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2250. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2251. // strconv.FormatInt(his.PatientId, 10)
  2252. //
  2253. // order_src, _ := service.GetHisOrderByID(order_id)
  2254. //
  2255. // config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2256. // if config.IsOpen == 1 { //对接了医保,走医保流程
  2257. //
  2258. // var total float64
  2259. // for _, item := range prescriptions {
  2260. // if item.Type == 1 { //药品
  2261. // for _, subItem := range item.HisDoctorAdviceInfo {
  2262. // total = total + (subItem.Price * subItem.PrescribingNumber)
  2263. // }
  2264. // }
  2265. // if item.Type == 2 { //项目
  2266. // for _, subItem := range item.HisPrescriptionProject {
  2267. // total = total + (subItem.Price * float64(subItem.Count))
  2268. // }
  2269. // }
  2270. // }
  2271. //
  2272. // for _, item := range prescriptions {
  2273. // for _, subItem := range item.HisAdditionalCharge {
  2274. // total = total + (subItem.Price * float64(subItem.Count))
  2275. // }
  2276. // }
  2277. //
  2278. // allTotal := fmt.Sprintf("%.2f", total)
  2279. // var rf []*ResultFive
  2280. // json.Unmarshal([]byte(his.Iinfo), &rf)
  2281. // psn_no := order_src.PsnNo
  2282. // mdtrt_id := order_src.MdtrtId
  2283. // chrg_bchno := order_src.Number
  2284. // cert_no := order_src.Certno
  2285. // insutype := rf[0].Insutype
  2286. //
  2287. // if his.IdCardType == 1 {
  2288. // cert_no = his.MedicalInsuranceNumber
  2289. // } else {
  2290. // cert_no = his.Certno
  2291. // }
  2292. //
  2293. // 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)
  2294. // var dat map[string]interface{}
  2295. // if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2296. // fmt.Println(dat)
  2297. // } else {
  2298. // fmt.Println(err)
  2299. // }
  2300. //
  2301. // userJSONBytes, _ := json.Marshal(dat)
  2302. //
  2303. //
  2304. //
  2305. // var res ResultSeven
  2306. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2307. // utils.ErrorLog("解析失败:%v", err)
  2308. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2309. // return
  2310. // }
  2311. // if res.Infcode == -1 {
  2312. // errlog := &models.HisOrderError{
  2313. // UserOrgId: adminUser.CurrentOrgId,
  2314. // Ctime: time.Now().Unix(),
  2315. // Mtime: time.Now().Unix(),
  2316. // Number: chrg_bchno,
  2317. // ErrMsg: res.ErrMsg,
  2318. // Status: 1,
  2319. // PatientId: id,
  2320. // RecordTime: recordDateTime,
  2321. // Stage: 6,
  2322. // }
  2323. // service.CreateErrMsgLog(errlog)
  2324. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2325. // return
  2326. // } else {
  2327. // order_src.OrderStatus = 2
  2328. // order_src.PayWay = pay_way
  2329. // order_src.PayPrice = pay_price
  2330. // order_src.PayCardNo = pay_card_no
  2331. // order_src.DiscountPrice = discount_price
  2332. // order_src.PreferentialPrice = preferential_price
  2333. // order_src.RealityPrice = reality_price
  2334. // order_src.FoundPrice = found_price
  2335. // order_src.MedicalInsurancePrice = medical_insurance_price
  2336. // order_src.PrivatePrice = private_price
  2337. // order_src.MdtrtId = res.Output.Setlinfo.MdtrtID
  2338. // order_src.SetlId = res.Output.Setlinfo.SetlID
  2339. // order_src.PsnNo = res.Output.Setlinfo.PsnNo
  2340. // order_src.PsnName = res.Output.Setlinfo.PsnName
  2341. // order_src.PsnCertType = res.Output.Setlinfo.PsnCertType
  2342. // order_src.Certno = res.Output.Setlinfo.Certno
  2343. // order_src.Gend = res.Output.Setlinfo.Gend
  2344. // order_src.Naty = res.Output.Setlinfo.Naty
  2345. // order_src.Age = res.Output.Setlinfo.Age
  2346. // order_src.Insutype = res.Output.Setlinfo.Insutype
  2347. // order_src.PsnType = res.Output.Setlinfo.PsnType
  2348. // order_src.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2349. // order_src.SetlTime = res.Output.Setlinfo.SetlTime
  2350. // order_src.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2351. // order_src.MedType = res.Output.Setlinfo.MedType
  2352. // order_src.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2353. // order_src.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2354. // order_src.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2355. // order_src.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2356. // order_src.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2357. // order_src.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2358. // order_src.HifpPay = res.Output.Setlinfo.HifpPay
  2359. // order_src.CvlservPay = res.Output.Setlinfo.CvlservPay
  2360. // order_src.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2361. // order_src.HifesPay = res.Output.Setlinfo.HifesPay
  2362. // order_src.HifobPay = res.Output.Setlinfo.HifobPay
  2363. // order_src.MafPay = res.Output.Setlinfo.MafPay
  2364. // order_src.OthPay = res.Output.Setlinfo.OthPay
  2365. // order_src.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2366. // order_src.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2367. // order_src.AcctPay = res.Output.Setlinfo.AcctPay
  2368. // order_src.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2369. // order_src.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2370. // order_src.Balc = res.Output.Setlinfo.Balc
  2371. // order_src.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2372. // order_src.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2373. // order_src.ClrOptins = res.Output.Setlinfo.ClrOptins
  2374. // order_src.ClrWay = res.Output.Setlinfo.ClrWay
  2375. // order_src.Creator = order_src.Creator
  2376. // order_src.Modify = roles.ID
  2377. // order_src.RequestLog = src_resquest
  2378. // setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2379. // detailStr := string(setlDetail)
  2380. // order_src.SetlDetail = detailStr
  2381. // err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2382. // err = service.UpDateOrder(order_src)
  2383. //
  2384. // if err == nil {
  2385. // c.ServeSuccessJSON(map[string]interface{}{
  2386. // "msg": "结算成功",
  2387. // })
  2388. // } else {
  2389. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2390. // return
  2391. // }
  2392. // }
  2393. // }
  2394. //}
  2395. //退款
  2396. func (c *HisApiController) Refund() {
  2397. order_id, _ := c.GetInt64("order_id")
  2398. admin_user_id, _ := c.GetInt64("admin_user_id")
  2399. record_time := c.GetString("record_time")
  2400. patient_id, _ := c.GetInt64("patient_id")
  2401. timeLayout := "2006-01-02"
  2402. loc, _ := time.LoadLocation("Local")
  2403. adminUser := c.GetAdminUserInfo()
  2404. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2405. if err != nil {
  2406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2407. return
  2408. }
  2409. recordDateTime := theTime.Unix()
  2410. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2411. var order models.HisOrder
  2412. order, _ = service.GetHisOrderByID(order_id)
  2413. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2414. if order.ID == 0 {
  2415. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  2416. }
  2417. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2418. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2419. if config.IsOpen == 1 { //对接了医保,走医保流程
  2420. result, src_resquest := service.Gdyb2208(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2421. var dat map[string]interface{}
  2422. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2423. fmt.Println(dat)
  2424. } else {
  2425. fmt.Println(err)
  2426. }
  2427. userJSONBytes, _ := json.Marshal(dat)
  2428. var res ResultSixteen
  2429. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2430. utils.ErrorLog("解析失败:%v", err)
  2431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2432. return
  2433. }
  2434. if res.Infcode == 0 {
  2435. result := service.Gdyb2205(order.PsnNo, order.MdtrtId, order.Number, miConfig.OrgName, roles.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  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 res2 ResultSix
  2444. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2445. utils.ErrorLog("解析失败:%v", err)
  2446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2447. return
  2448. }
  2449. if res2.Infcode == 0 {
  2450. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, src_resquest, result)
  2451. if err == nil {
  2452. c.ServeSuccessJSON(map[string]interface{}{
  2453. "msg": "退费成功",
  2454. })
  2455. } else {
  2456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2457. return
  2458. }
  2459. } else {
  2460. c.ServeSuccessJSON(map[string]interface{}{
  2461. "code": -10,
  2462. "msg": res2.ErrMsg,
  2463. })
  2464. }
  2465. } else {
  2466. c.ServeSuccessJSON(map[string]interface{}{
  2467. "code": -10,
  2468. "msg": res.ErrMsg,
  2469. })
  2470. }
  2471. } else {
  2472. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  2473. if err == nil {
  2474. c.ServeSuccessJSON(map[string]interface{}{
  2475. "msg": "退费成功",
  2476. })
  2477. } else {
  2478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2479. return
  2480. }
  2481. }
  2482. }
  2483. func (c *HisApiController) RefundNumber() {
  2484. //record_time := c.GetString("record_time")
  2485. //patient_id, _ := c.GetInt64("patient_id")
  2486. admin_user_id, _ := c.GetInt64("admin_user_id")
  2487. his_patient_id, _ := c.GetInt64("id")
  2488. //timeLayout := "2006-01-02"
  2489. //loc, _ := time.LoadLocation("Local")
  2490. adminUser := c.GetAdminUserInfo()
  2491. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2492. //fmt.Println(err)
  2493. //if err != nil {
  2494. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2495. // return
  2496. //}
  2497. //recordDateTime := theTime.Unix()
  2498. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2499. his, _ := service.GetHisPatientRecord(adminUser.CurrentOrgId, his_patient_id)
  2500. //patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2501. //order, _ := service.GetHisOrderByID(order_id)
  2502. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2503. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2504. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2505. if config.IsOpen == 1 { //对接了医保,走医保流程
  2506. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  2507. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + roles.UserName + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2508. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2509. resp3, requestErr3 := http.Get(api3)
  2510. if requestErr3 != nil {
  2511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2512. return
  2513. }
  2514. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  2515. if ioErr3 != nil {
  2516. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  2517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2518. return
  2519. }
  2520. var respJSON3 map[string]interface{}
  2521. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  2522. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2524. return
  2525. }
  2526. respJSON3 = respJSON3["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2527. userJSONBytes3, _ := json.Marshal(respJSON3)
  2528. var res2 ResultSix
  2529. if err := json.Unmarshal(userJSONBytes3, &res2); err != nil {
  2530. utils.ErrorLog("解析失败:%v", err)
  2531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2532. return
  2533. }
  2534. if res2.Infcode == 0 {
  2535. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2536. //service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  2537. err := service.UpdataRegStatus2(his_patient_id)
  2538. if err == nil {
  2539. c.ServeSuccessJSON(map[string]interface{}{
  2540. "msg": "退号成功",
  2541. })
  2542. } else {
  2543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2544. return
  2545. }
  2546. } else {
  2547. c.ServeSuccessJSON(map[string]interface{}{
  2548. "code": -10,
  2549. "msg": res2.ErrMsg,
  2550. })
  2551. }
  2552. } else {
  2553. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2554. //if err == nil {
  2555. // c.ServeSuccessJSON(map[string]interface{}{
  2556. // "msg": "退费成功",
  2557. // })
  2558. //} else {
  2559. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2560. // return
  2561. //}
  2562. }
  2563. }
  2564. func (c *HisApiController) RefundDetail() {
  2565. order_id, _ := c.GetInt64("order_id")
  2566. number := c.GetString("number")
  2567. record_time := c.GetString("record_time")
  2568. patient_id, _ := c.GetInt64("patient_id")
  2569. timeLayout := "2006-01-02"
  2570. loc, _ := time.LoadLocation("Local")
  2571. adminUser := c.GetAdminUserInfo()
  2572. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2573. fmt.Println(err)
  2574. if err != nil {
  2575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2576. return
  2577. }
  2578. recordDateTime := theTime.Unix()
  2579. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2580. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2581. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2582. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2583. var order models.HisOrder
  2584. order, _ = service.GetHisOrderByID(order_id)
  2585. if order.ID == 0 {
  2586. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  2587. }
  2588. if config.IsOpen == 1 { //对接了医保,走医保流程
  2589. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  2590. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2591. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2592. resp2, requestErr2 := http.Get(api2)
  2593. if requestErr2 != nil {
  2594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2595. return
  2596. }
  2597. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  2598. if ioErr2 != nil {
  2599. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  2600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2601. return
  2602. }
  2603. var respJSON2 map[string]interface{}
  2604. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  2605. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2607. return
  2608. }
  2609. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId, "", "")
  2610. if err == nil {
  2611. c.ServeSuccessJSON(map[string]interface{}{
  2612. "msg": "退费成功",
  2613. })
  2614. } else {
  2615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2616. return
  2617. }
  2618. } else {
  2619. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId, "", "")
  2620. if err == nil {
  2621. c.ServeSuccessJSON(map[string]interface{}{
  2622. "msg": "退费成功",
  2623. })
  2624. } else {
  2625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2626. return
  2627. }
  2628. }
  2629. }
  2630. //对账
  2631. func (c *HisApiController) GetCheckAccount() {
  2632. start_time := c.GetString("start_time")
  2633. end_time := c.GetString("end_time")
  2634. insutype := c.GetString("insutype")
  2635. clr_type := c.GetString("clr_type")
  2636. admin_user_id, _ := c.GetInt64("admin_user_id")
  2637. adminUser := c.GetAdminUserInfo()
  2638. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2639. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2640. timeLayout := "2006-01-02"
  2641. loc, _ := time.LoadLocation("Local")
  2642. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2643. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2644. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  2645. orders_two, _ := service.GetOrderByTimeThree(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  2646. fixmedins_setl_cnt := int64(len(orders_two))
  2647. //撤销的算2条数据为一笔
  2648. for _, item := range orders_two {
  2649. if item.OrderStatus == 3 {
  2650. fixmedins_setl_cnt = fixmedins_setl_cnt + 1
  2651. }
  2652. }
  2653. var medfee_sumamt float64
  2654. var acct_pay float64
  2655. var fund_pay_sumamt float64
  2656. for _, item := range orders {
  2657. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  2658. acct_pay = acct_pay + item.AcctPay
  2659. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  2660. }
  2661. var user_name string
  2662. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2663. if role.ID == 0 {
  2664. user_name = "xxx"
  2665. } else {
  2666. user_name = role.UserName
  2667. }
  2668. if config.IsOpen == 1 {
  2669. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  2670. "insutype=" + insutype +
  2671. "&clr_type=" + clr_type +
  2672. "&setl_optins=" + "定点医保中心" +
  2673. "&stmt_begndate=" + start_time +
  2674. "&stm_enddate=" + end_time +
  2675. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  2676. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  2677. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  2678. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  2679. "&fixmedins_code=" + miConfig.Code +
  2680. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2681. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2682. "&secret_key=" + miConfig.SecretKey +
  2683. "&org_name=" + miConfig.OrgName +
  2684. "&doctor=" + user_name
  2685. fmt.Println(api)
  2686. resp, requestErr := http.Get(api)
  2687. if requestErr != nil {
  2688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2689. return
  2690. }
  2691. body, ioErr := ioutil.ReadAll(resp.Body)
  2692. fmt.Println(body)
  2693. if ioErr != nil {
  2694. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2696. return
  2697. }
  2698. var respJSON map[string]interface{}
  2699. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2700. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2702. return
  2703. }
  2704. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2705. userJSONBytes, _ := json.Marshal(respJSON)
  2706. var res ResultEight
  2707. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2708. utils.ErrorLog("解析失败:%v", err)
  2709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2710. return
  2711. }
  2712. if res.Infcode == 0 {
  2713. if res.Output.Stmtinfo.StmtRslt == "0" {
  2714. micc := &models.MedicalInsuranceCostCompare{
  2715. StartTime: startime.Unix(),
  2716. EndTime: endtime.Unix(),
  2717. Insutype: insutype,
  2718. CheckType: 1,
  2719. Num: fixmedins_setl_cnt,
  2720. Mtime: time.Now().Unix(),
  2721. Status: 1,
  2722. UserOrgId: adminUser.CurrentOrgId,
  2723. CostTotal: medfee_sumamt,
  2724. FuncTotal: fund_pay_sumamt,
  2725. PsnPay: acct_pay,
  2726. Creator: admin_user_id,
  2727. Ctime: time.Now().Unix(),
  2728. }
  2729. err := service.CreateMedicalInsuranceCostCompareRecord(micc)
  2730. if err == nil {
  2731. c.ServeSuccessJSON(map[string]interface{}{
  2732. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  2733. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  2734. })
  2735. } else {
  2736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2737. }
  2738. } else {
  2739. c.ServeSuccessJSON(map[string]interface{}{
  2740. "code": -10,
  2741. "msg": res.ErrMsg,
  2742. })
  2743. }
  2744. } else {
  2745. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2746. }
  2747. }
  2748. }
  2749. func (c *HisApiController) Check310() {
  2750. adminUser := c.GetAdminUserInfo()
  2751. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2752. var user_name string
  2753. user_name = "xxx"
  2754. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  2755. "insutype=" + "310" +
  2756. "&clr_type=" + "11" +
  2757. "&setl_optins=" + "定点医保中心" +
  2758. "&stmt_begndate=" + "2021-03-01" +
  2759. "&stm_enddate=" + "2021-03-31" +
  2760. "&medfee_sumamt=" + "11521" +
  2761. "&fund_pay_sumamt=" + "10166.66" +
  2762. "&acct_pay=" + "0" +
  2763. "&fixmedins_setl_cnt=" + "7" +
  2764. "&fixmedins_code=" + miConfig.Code +
  2765. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2766. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2767. "&secret_key=" + miConfig.SecretKey +
  2768. "&org_name=" + miConfig.OrgName +
  2769. "&doctor=" + user_name
  2770. fmt.Println(api)
  2771. resp, requestErr := http.Get(api)
  2772. if requestErr != nil {
  2773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2774. return
  2775. }
  2776. body, ioErr := ioutil.ReadAll(resp.Body)
  2777. fmt.Println(body)
  2778. if ioErr != nil {
  2779. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2781. return
  2782. }
  2783. var respJSON map[string]interface{}
  2784. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2785. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2787. return
  2788. }
  2789. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2790. userJSONBytes, _ := json.Marshal(respJSON)
  2791. var res ResultEight
  2792. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2793. utils.ErrorLog("解析失败:%v", err)
  2794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2795. return
  2796. }
  2797. }
  2798. func (c *HisApiController) Check390() {
  2799. adminUser := c.GetAdminUserInfo()
  2800. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2801. var user_name string
  2802. user_name = "张俊杰"
  2803. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  2804. "insutype=" + "390" +
  2805. "&clr_type=" + "11" +
  2806. "&setl_optins=" + "定点医保中心" +
  2807. "&stmt_begndate=" + "2021-03-01" +
  2808. "&stm_enddate=" + "2021-03-31" +
  2809. "&medfee_sumamt=" + "209318.43" +
  2810. "&fund_pay_sumamt=" + "188029.12" +
  2811. "&acct_pay=" + "0" +
  2812. "&fixmedins_setl_cnt=" + "48" +
  2813. "&fixmedins_code=" + miConfig.Code +
  2814. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2815. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2816. "&secret_key=" + miConfig.SecretKey +
  2817. "&org_name=" + miConfig.OrgName +
  2818. "&doctor=" + user_name
  2819. fmt.Println(api)
  2820. resp, requestErr := http.Get(api)
  2821. if requestErr != nil {
  2822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2823. return
  2824. }
  2825. body, ioErr := ioutil.ReadAll(resp.Body)
  2826. fmt.Println(body)
  2827. if ioErr != nil {
  2828. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2830. return
  2831. }
  2832. var respJSON map[string]interface{}
  2833. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2834. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2836. return
  2837. }
  2838. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2839. userJSONBytes, _ := json.Marshal(respJSON)
  2840. var res ResultEight
  2841. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2842. utils.ErrorLog("解析失败:%v", err)
  2843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2844. return
  2845. }
  2846. }
  2847. //对账明细
  2848. func (c *HisApiController) GetCheckDetailAccount() {
  2849. start_time := c.GetString("start_time")
  2850. end_time := c.GetString("end_time")
  2851. admin_user_id, _ := c.GetInt64("admin_user_id")
  2852. adminUser := c.GetAdminUserInfo()
  2853. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2854. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2855. timeLayout := "2006-01-02"
  2856. loc, _ := time.LoadLocation("Local")
  2857. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2858. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2859. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  2860. Mkdir(miConfig.OrgName)
  2861. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  2862. file_name := file + ".txt"
  2863. zip_name := file + ".zip"
  2864. zip_path := miConfig.OrgName + "/" + zip_name
  2865. file_path := miConfig.OrgName + "/" + file_name
  2866. decimal.DivisionPrecision = 2
  2867. var medfee_sumamt float64
  2868. var psn_cash_pay float64
  2869. var fund_pay_sumamt float64
  2870. fixmedins_setl_cnt := int64(len(orders))
  2871. for _, item := range orders {
  2872. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  2873. psn_cash_pay = psn_cash_pay + item.PsnCashPay
  2874. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  2875. }
  2876. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  2877. defer f.Close()
  2878. if err != nil {
  2879. fmt.Println(err.Error())
  2880. } else {
  2881. for _, item := range orders {
  2882. var refd_setl_flag string
  2883. if item.OrderStatus == 2 {
  2884. refd_setl_flag = "0"
  2885. var str string
  2886. str = item.SetlId + " " +
  2887. item.MdtrtId + " " +
  2888. item.PsnNo + " " +
  2889. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  2890. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  2891. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\r\n"
  2892. _, err = f.Write([]byte(str))
  2893. }
  2894. if item.OrderStatus == 3 {
  2895. var str string
  2896. str = item.SetlId + " " +
  2897. item.MdtrtId + " " +
  2898. item.PsnNo + " " +
  2899. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  2900. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  2901. fmt.Sprintf("%.2f", item.AcctPay) + " " + "1" + "\r\n"
  2902. _, err = f.Write([]byte(str))
  2903. var str2 string
  2904. str2 = item.SetlId + " " +
  2905. item.MdtrtId + " " +
  2906. item.PsnNo + " " +
  2907. fmt.Sprintf("%.2f", 0-item.MedfeeSumamt) + " " +
  2908. fmt.Sprintf("%.2f", 0-item.FundPaySumamt) + " " +
  2909. fmt.Sprintf("%.2f", 0-item.AcctPay) + " " + "1" + "\r\n"
  2910. _, err = f.Write([]byte(str2))
  2911. }
  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. }