his_api_controller.go 150KB

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