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": res.ErrMsg,
  1065. })
  1066. return
  1067. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  1068. //return
  1069. }
  1070. c.ServeSuccessJSON(map[string]interface{}{
  1071. "his_info": his,
  1072. })
  1073. } else {
  1074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1075. return
  1076. }
  1077. } else {
  1078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1079. return
  1080. }
  1081. } else {
  1082. adminUser := c.GetAdminUserInfo()
  1083. errlog := &models.HisOrderError{
  1084. UserOrgId: adminUser.CurrentOrgId,
  1085. Ctime: time.Now().Unix(),
  1086. Mtime: time.Now().Unix(),
  1087. ErrMsg: res.ErrMsg,
  1088. Status: 1,
  1089. PatientId: id,
  1090. RecordTime: recordDateTime,
  1091. Stage: 1,
  1092. }
  1093. service.CreateErrMsgLog(errlog)
  1094. c.ServeSuccessJSON(map[string]interface{}{
  1095. "failed_code": -10,
  1096. "msg": res.ErrMsg,
  1097. })
  1098. return
  1099. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  1100. }
  1101. } else {
  1102. timeStr := time.Now().Format("2006-01-02")
  1103. timeArr := strings.Split(timeStr, "-")
  1104. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
  1105. his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  1106. var hisPatient models.XtHisPatient
  1107. if err == gorm.ErrRecordNotFound || his.ID == 0 {
  1108. hisPatient = models.XtHisPatient{
  1109. Name: name,
  1110. Age: age,
  1111. Gender: gender,
  1112. Birthday: birthUnix,
  1113. Phone: phone,
  1114. MedicalTreatmentType: medical_care,
  1115. IdType: certificates,
  1116. IdCardNo: id_card,
  1117. BalanceAccountsType: settlementValue,
  1118. SocialType: social_type,
  1119. MedicalInsuranceNumber: medical_insurance_card,
  1120. RegisterType: register_type,
  1121. RegisterCost: registration_fee,
  1122. TreatmentCost: medical_expenses,
  1123. AdminUserId: admin_user_id,
  1124. UserOrgId: adminInfo.CurrentOrgId,
  1125. Status: 1,
  1126. RecordDate: recordDateTime,
  1127. IsReturn: 1,
  1128. PatientId: patient.ID,
  1129. Ctime: time.Now().Unix(),
  1130. Mtime: time.Now().Unix(),
  1131. Number: str,
  1132. }
  1133. service.CreateHisPatient(&hisPatient)
  1134. }
  1135. c.ServeSuccessJSON(map[string]interface{}{
  1136. "his_info": hisPatient,
  1137. })
  1138. }
  1139. }
  1140. //上传明细----预结算----确认订单
  1141. func (c *HisApiController) GetUploadInfo() {
  1142. id, _ := c.GetInt64("id")
  1143. record_time := c.GetString("record_time")
  1144. pay_way, _ := c.GetInt64("pay_way")
  1145. pay_price, _ := c.GetFloat("pay_price")
  1146. pay_card_no := c.GetString("pay_card_no")
  1147. discount_price, _ := c.GetFloat("discount_price")
  1148. preferential_price, _ := c.GetFloat("preferential_price")
  1149. reality_price, _ := c.GetFloat("reality_price")
  1150. found_price, _ := c.GetFloat("found_price")
  1151. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1152. private_price, _ := c.GetFloat("private_price")
  1153. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1154. admin_user_id, _ := c.GetInt64("admin_user_id")
  1155. timeLayout := "2006-01-02"
  1156. loc, _ := time.LoadLocation("Local")
  1157. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1158. if err != nil {
  1159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1160. return
  1161. }
  1162. recordDateTime := theTime.Unix()
  1163. adminUser := c.GetAdminUserInfo()
  1164. var prescriptions []*models.HisPrescription
  1165. var start_time int64
  1166. var end_time int64
  1167. data := make(map[string]interface{})
  1168. if settle_accounts_type == 1 { //日结
  1169. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1170. data["pre"] = prescriptions
  1171. } else { //月结
  1172. start_time_str := c.GetString("start_time")
  1173. end_time_str := c.GetString("end_time")
  1174. timeLayout := "2006-01-02"
  1175. loc, _ := time.LoadLocation("Local")
  1176. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1177. if err != nil {
  1178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1179. return
  1180. }
  1181. recordStartTime := theStartTime.Unix()
  1182. start_time = recordStartTime
  1183. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1184. if err != nil {
  1185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1186. return
  1187. }
  1188. recordEndTime := theEndTime.Unix()
  1189. end_time = recordEndTime
  1190. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1191. data["pre"] = prescriptions
  1192. }
  1193. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1194. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1195. timestamp := time.Now().Unix()
  1196. tempTime := time.Unix(timestamp, 0)
  1197. timeFormat := tempTime.Format("20060102150405")
  1198. chrgBchno := rand.Intn(100000) + 10000
  1199. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1200. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1201. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1202. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1203. strconv.FormatInt(his.PatientId, 10)
  1204. client := &http.Client{}
  1205. data["psn_no"] = his.PsnNo
  1206. data["mdtrt_id"] = his.Number
  1207. data["chrg_bchno"] = chrg_bchno
  1208. data["org_name"] = miConfig.OrgName
  1209. data["doctor"] = roles.UserName
  1210. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1211. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  1212. data["fixmedins_code"] = miConfig.Code
  1213. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  1214. data["dept_code"] = "15"
  1215. } else {
  1216. data["dept_code"] = department.Number
  1217. }
  1218. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1219. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1220. data["secret_key"] = miConfig.SecretKey
  1221. var ids []int64
  1222. for _, item := range prescriptions {
  1223. ids = append(ids, item.ID)
  1224. }
  1225. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1226. if config.IsOpen == 1 { //对接了医保,走医保流程
  1227. bytesData, _ := json.Marshal(data)
  1228. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  1229. resp, _ := client.Do(req)
  1230. defer resp.Body.Close()
  1231. body, ioErr := ioutil.ReadAll(resp.Body)
  1232. if ioErr != nil {
  1233. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1235. return
  1236. }
  1237. var respJSON map[string]interface{}
  1238. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1239. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1241. return
  1242. }
  1243. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1244. userJSONBytes, _ := json.Marshal(respJSON)
  1245. var res ResultFour
  1246. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1247. utils.ErrorLog("解析失败:%v", err)
  1248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1249. return
  1250. }
  1251. if res.Infcode == 0 {
  1252. order := &models.HisOrder{
  1253. UserOrgId: adminUser.CurrentOrgId,
  1254. HisPatientId: his.ID,
  1255. PatientId: his.PatientId,
  1256. SettleAccountsDate: recordDateTime,
  1257. Ctime: time.Now().Unix(),
  1258. Mtime: time.Now().Unix(),
  1259. Status: 1,
  1260. Number: chrg_bchno,
  1261. Infcode: res.Infcode,
  1262. WarnMsg: res.WarnMsg,
  1263. Cainfo: res.Cainfo,
  1264. ErrMsg: res.ErrMsg,
  1265. RespondTime: res.RefmsgTime,
  1266. InfRefmsgid: res.InfRefmsgid,
  1267. OrderStatus: 1,
  1268. PayWay: pay_way,
  1269. PayPrice: pay_price,
  1270. PayCardNo: pay_card_no,
  1271. DiscountPrice: discount_price,
  1272. PreferentialPrice: preferential_price,
  1273. RealityPrice: reality_price,
  1274. FoundPrice: found_price,
  1275. MedicalInsurancePrice: medical_insurance_price,
  1276. PrivatePrice: private_price,
  1277. IsMedicineInsurance: 1,
  1278. SettleType: settle_accounts_type,
  1279. SettleStartTime: start_time,
  1280. SettleEndTime: end_time,
  1281. Creator: roles.ID,
  1282. Modify: roles.ID,
  1283. }
  1284. err = service.CreateOrder(order)
  1285. if err != nil {
  1286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1287. return
  1288. }
  1289. for _, item := range res.Output.Result {
  1290. temp := strings.Split(item.FeedetlSn, "-")
  1291. var advice_id int64 = 0
  1292. var project_id int64 = 0
  1293. var types int64 = 0
  1294. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1295. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1296. if temp[1] == "1" {
  1297. advice_id = id
  1298. project_id = 0
  1299. } else if temp[1] == "2" {
  1300. advice_id = 0
  1301. project_id = id
  1302. }
  1303. info := &models.HisOrderInfo{
  1304. OrderNumber: order.Number,
  1305. FeedetlSn: item.FeedetlSn,
  1306. UploadDate: time.Now().Unix(),
  1307. AdviceId: advice_id,
  1308. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1309. Cnt: item.Cnt,
  1310. Pric: float64(item.Pric),
  1311. PatientId: his.PatientId,
  1312. PricUplmtAmt: item.PricUplmtAmt,
  1313. SelfpayProp: item.SelfpayProp,
  1314. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1315. OverlmtAmt: item.OverlmtAmt,
  1316. PreselfpayAmt: item.PreselfpayAmt,
  1317. BasMednFlag: item.BasMednFlag,
  1318. MedChrgitmType: item.MedChrgitmType,
  1319. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1320. Status: 1,
  1321. Memo: item.Memo,
  1322. Mtime: time.Now().Unix(),
  1323. InscpScpAmt: item.InscpScpAmt,
  1324. DrtReimFlag: item.DrtReimFlag,
  1325. Ctime: time.Now().Unix(),
  1326. ListSpItemFlag: item.ListSpItemFlag,
  1327. ChldMedcFlag: item.ChldMedcFlag,
  1328. LmtUsedFlag: item.LmtUsedFlag,
  1329. ChrgitmLv: item.ChrgitmLv,
  1330. UserOrgId: adminUser.CurrentOrgId,
  1331. HisPatientId: his.ID,
  1332. OrderId: order.ID,
  1333. ProjectId: project_id,
  1334. Type: types,
  1335. }
  1336. service.CreateOrderInfo(info)
  1337. }
  1338. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1339. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1340. var total float64
  1341. for _, item := range prescriptions {
  1342. if item.Type == 1 { //药品
  1343. for _, subItem := range item.HisDoctorAdviceInfo {
  1344. total = total + (subItem.Price * subItem.PrescribingNumber)
  1345. }
  1346. }
  1347. if item.Type == 2 { //项目
  1348. for _, subItem := range item.HisPrescriptionProject {
  1349. total = total + (subItem.Price * float64(subItem.Count))
  1350. }
  1351. }
  1352. }
  1353. for _, item := range prescriptions {
  1354. for _, subItem := range item.HisAdditionalCharge {
  1355. total = total + (subItem.Price * float64(subItem.Count))
  1356. }
  1357. }
  1358. allTotal := fmt.Sprintf("%.2f", total)
  1359. if res.Infcode == 0 {
  1360. var rf []*ResultFive
  1361. json.Unmarshal([]byte(his.Iinfo), &rf)
  1362. psn_no := his.PsnNo
  1363. mdtrt_id := his.Number
  1364. chrg_bchno := chrg_bchno
  1365. cert_no := his.Certno
  1366. var insutypes []string
  1367. var insutype string
  1368. var is390 int = 0
  1369. var is310 int = 0
  1370. for _, item := range rf {
  1371. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1372. insutypes = append(insutypes, item.Insutype)
  1373. }
  1374. }
  1375. if len(insutypes) == 1 {
  1376. insutype = insutypes[0]
  1377. } else {
  1378. for _, i := range insutypes {
  1379. if i == "390" {
  1380. is390 = 1
  1381. }
  1382. if i == "310" {
  1383. is310 = 1
  1384. }
  1385. }
  1386. }
  1387. if is390 == 1 {
  1388. insutype = "390"
  1389. }
  1390. if is310 == 1 {
  1391. insutype = "310"
  1392. }
  1393. if his.IdCardType == 1 {
  1394. cert_no = his.MedicalInsuranceNumber
  1395. } else {
  1396. cert_no = his.Certno
  1397. }
  1398. api := "http://127.0.0.1:9532/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  1399. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1400. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  1401. miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10)
  1402. resp, requestErr := http.Get(api)
  1403. if requestErr != nil {
  1404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1405. return
  1406. }
  1407. defer resp.Body.Close()
  1408. body, ioErr := ioutil.ReadAll(resp.Body)
  1409. if ioErr != nil {
  1410. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1412. return
  1413. }
  1414. var respJSON map[string]interface{}
  1415. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1416. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1418. return
  1419. }
  1420. fmt.Println(respJSON)
  1421. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1422. userJSONBytes, _ := json.Marshal(respJSON)
  1423. var res ResultSeven
  1424. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1425. utils.ErrorLog("解析失败:%v", err)
  1426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1427. return
  1428. }
  1429. if res.Infcode == -1 {
  1430. errlog := &models.HisOrderError{
  1431. UserOrgId: adminUser.CurrentOrgId,
  1432. Ctime: time.Now().Unix(),
  1433. Mtime: time.Now().Unix(),
  1434. Number: chrg_bchno,
  1435. ErrMsg: res.ErrMsg,
  1436. Status: 1,
  1437. PatientId: id,
  1438. RecordTime: recordDateTime,
  1439. Stage: 6,
  1440. }
  1441. c.ServeSuccessJSON(map[string]interface{}{
  1442. "failed_code": -10,
  1443. "msg": res.ErrMsg,
  1444. })
  1445. return
  1446. service.CreateErrMsgLog(errlog)
  1447. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1448. return
  1449. } else {
  1450. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1451. order.OrderStatus = 2
  1452. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1453. order.SetlId = res.Output.Setlinfo.SetlID
  1454. order.PsnNo = res.Output.Setlinfo.PsnNo
  1455. order.PsnName = res.Output.Setlinfo.PsnName
  1456. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1457. order.Certno = res.Output.Setlinfo.Certno
  1458. order.Gend = res.Output.Setlinfo.Gend
  1459. order.Naty = res.Output.Setlinfo.Naty
  1460. order.Age = res.Output.Setlinfo.Age
  1461. order.Insutype = res.Output.Setlinfo.Insutype
  1462. order.PsnType = res.Output.Setlinfo.PsnType
  1463. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1464. order.SetlTime = res.Output.Setlinfo.SetlTime
  1465. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1466. order.MedType = res.Output.Setlinfo.MedType
  1467. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1468. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1469. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1470. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1471. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1472. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1473. order.HifpPay = res.Output.Setlinfo.HifpPay
  1474. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1475. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1476. order.HifesPay = res.Output.Setlinfo.HifesPay
  1477. order.HifobPay = res.Output.Setlinfo.HifobPay
  1478. order.MafPay = res.Output.Setlinfo.MafPay
  1479. order.OthPay = res.Output.Setlinfo.OthPay
  1480. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1481. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1482. order.AcctPay = res.Output.Setlinfo.AcctPay
  1483. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1484. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1485. order.Balc = res.Output.Setlinfo.Balc
  1486. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1487. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1488. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1489. order.ClrWay = res.Output.Setlinfo.ClrWay
  1490. order.Creator = order.Creator
  1491. order.Modify = roles.ID
  1492. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1493. detailStr := string(setlDetail)
  1494. order.SetlDetail = detailStr
  1495. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1496. err = service.UpDateOrder(order)
  1497. if err == nil {
  1498. c.ServeSuccessJSON(map[string]interface{}{
  1499. "msg": "结算成功",
  1500. })
  1501. } else {
  1502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1503. return
  1504. }
  1505. }
  1506. } else {
  1507. adminUser := c.GetAdminUserInfo()
  1508. errlog := &models.HisOrderError{
  1509. UserOrgId: adminUser.CurrentOrgId,
  1510. Ctime: time.Now().Unix(),
  1511. Mtime: time.Now().Unix(),
  1512. ErrMsg: res.ErrMsg,
  1513. Status: 1,
  1514. PatientId: id,
  1515. RecordTime: recordDateTime,
  1516. Stage: 4,
  1517. }
  1518. service.CreateErrMsgLog(errlog)
  1519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1520. return
  1521. }
  1522. } else {
  1523. adminUser := c.GetAdminUserInfo()
  1524. errlog := &models.HisOrderError{
  1525. UserOrgId: adminUser.CurrentOrgId,
  1526. Ctime: time.Now().Unix(),
  1527. Mtime: time.Now().Unix(),
  1528. ErrMsg: res.ErrMsg,
  1529. Status: 1,
  1530. PatientId: id,
  1531. RecordTime: recordDateTime,
  1532. Stage: 4,
  1533. }
  1534. service.CreateErrMsgLog(errlog)
  1535. c.ServeSuccessJSON(map[string]interface{}{
  1536. "failed_code": -10,
  1537. "msg": res.ErrMsg,
  1538. })
  1539. return
  1540. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  1541. //return
  1542. }
  1543. } else {
  1544. var total float64
  1545. for _, item := range prescriptions {
  1546. if item.Type == 1 { //药品
  1547. for _, subItem := range item.HisDoctorAdviceInfo {
  1548. total = total + (subItem.Price * subItem.PrescribingNumber)
  1549. }
  1550. }
  1551. if item.Type == 2 { //项目
  1552. for _, subItem := range item.HisPrescriptionProject {
  1553. total = total + (subItem.Price * float64(subItem.Count))
  1554. }
  1555. }
  1556. for _, subItem := range item.HisAdditionalCharge {
  1557. total = total + (subItem.Price * float64(subItem.Count))
  1558. }
  1559. }
  1560. allTotal := fmt.Sprintf("%.2f", total)
  1561. totals, _ := strconv.ParseFloat(allTotal, 64)
  1562. order := &models.HisOrder{
  1563. UserOrgId: adminUser.CurrentOrgId,
  1564. HisPatientId: his.ID,
  1565. PatientId: id,
  1566. SettleAccountsDate: recordDateTime,
  1567. Ctime: time.Now().Unix(),
  1568. Mtime: time.Now().Unix(),
  1569. Status: 1,
  1570. OrderStatus: 2,
  1571. Number: chrg_bchno,
  1572. MedfeeSumamt: totals,
  1573. PayWay: pay_way,
  1574. PayPrice: pay_price,
  1575. PayCardNo: pay_card_no,
  1576. DiscountPrice: discount_price,
  1577. PreferentialPrice: preferential_price,
  1578. RealityPrice: reality_price,
  1579. FoundPrice: found_price,
  1580. MedicalInsurancePrice: medical_insurance_price,
  1581. PrivatePrice: private_price,
  1582. }
  1583. err = service.CreateOrder(order)
  1584. if err != nil {
  1585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1586. return
  1587. }
  1588. var customs []*Custom
  1589. for _, item := range prescriptions {
  1590. if item.Type == 1 { //药品
  1591. for _, subItem := range item.HisDoctorAdviceInfo {
  1592. cus := &Custom{
  1593. AdviceId: subItem.ID,
  1594. ProjectId: 0,
  1595. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  1596. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  1597. FeedetlSn: subItem.FeedetlSn,
  1598. Price: fmt.Sprintf("%.2f", subItem.Price),
  1599. MedListCodg: subItem.MedListCodg,
  1600. Type: 1,
  1601. }
  1602. customs = append(customs, cus)
  1603. }
  1604. }
  1605. if item.Type == 2 { //项目
  1606. for _, subItem := range item.HisPrescriptionProject {
  1607. cus := &Custom{
  1608. AdviceId: 0,
  1609. ProjectId: subItem.ID,
  1610. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  1611. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  1612. FeedetlSn: subItem.FeedetlSn,
  1613. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  1614. MedListCodg: subItem.MedListCodg,
  1615. Type: 2,
  1616. }
  1617. customs = append(customs, cus)
  1618. }
  1619. }
  1620. for _, item := range item.HisAdditionalCharge {
  1621. cus := &Custom{
  1622. ItemId: item.ID,
  1623. AdviceId: 0,
  1624. ProjectId: 0,
  1625. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  1626. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  1627. FeedetlSn: item.FeedetlSn,
  1628. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  1629. MedListCodg: item.XtHisAddtionConfig.Code,
  1630. Type: 3,
  1631. }
  1632. customs = append(customs, cus)
  1633. }
  1634. }
  1635. for _, item := range customs {
  1636. var advice_id int64 = 0
  1637. var project_id int64 = 0
  1638. var item_id int64 = 0
  1639. var types int64 = 0
  1640. if item.Type == 1 {
  1641. advice_id = item.AdviceId
  1642. project_id = 0
  1643. item_id = 0
  1644. } else if item.Type == 2 {
  1645. advice_id = 0
  1646. item_id = 0
  1647. project_id = item.ProjectId
  1648. } else if item.Type == 3 {
  1649. advice_id = 0
  1650. item_id = item.ItemId
  1651. project_id = 0
  1652. }
  1653. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  1654. cut, _ := strconv.ParseFloat(item.Cut, 32)
  1655. pric, _ := strconv.ParseFloat(item.Price, 32)
  1656. info := &models.HisOrderInfo{
  1657. OrderNumber: order.Number,
  1658. UploadDate: time.Now().Unix(),
  1659. AdviceId: advice_id,
  1660. DetItemFeeSumamt: detItemFeeSumamt,
  1661. Cnt: cut,
  1662. Pric: pric,
  1663. PatientId: id,
  1664. Status: 1,
  1665. Mtime: time.Now().Unix(),
  1666. Ctime: time.Now().Unix(),
  1667. UserOrgId: adminUser.CurrentOrgId,
  1668. HisPatientId: his.ID,
  1669. OrderId: order.ID,
  1670. ProjectId: project_id,
  1671. Type: types,
  1672. ItemId: item_id,
  1673. }
  1674. service.CreateOrderInfo(info)
  1675. }
  1676. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1677. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1678. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  1679. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1680. if err == nil {
  1681. c.ServeSuccessJSON(map[string]interface{}{
  1682. "msg": "结算成功",
  1683. })
  1684. } else {
  1685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1686. return
  1687. }
  1688. }
  1689. }
  1690. func (c *HisApiController) GetPreUploadInfo() {
  1691. id, _ := c.GetInt64("id")
  1692. record_time := c.GetString("record_time")
  1693. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1694. admin_user_id, _ := c.GetInt64("admin_user_id")
  1695. timeLayout := "2006-01-02"
  1696. loc, _ := time.LoadLocation("Local")
  1697. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1698. if err != nil {
  1699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1700. return
  1701. }
  1702. recordDateTime := theTime.Unix()
  1703. adminUser := c.GetAdminUserInfo()
  1704. var prescriptions []*models.HisPrescription
  1705. var start_time int64
  1706. var end_time int64
  1707. data := make(map[string]interface{})
  1708. if settle_accounts_type == 1 { //日结
  1709. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1710. data["pre"] = prescriptions
  1711. } else { //月结
  1712. start_time_str := c.GetString("start_time")
  1713. end_time_str := c.GetString("end_time")
  1714. timeLayout := "2006-01-02"
  1715. loc, _ := time.LoadLocation("Local")
  1716. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1717. if err != nil {
  1718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1719. return
  1720. }
  1721. recordStartTime := theStartTime.Unix()
  1722. start_time = recordStartTime
  1723. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1724. if err != nil {
  1725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1726. return
  1727. }
  1728. recordEndTime := theEndTime.Unix()
  1729. end_time = recordEndTime
  1730. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1731. data["pre"] = prescriptions
  1732. }
  1733. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1734. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1735. timestamp := time.Now().Unix()
  1736. tempTime := time.Unix(timestamp, 0)
  1737. timeFormat := tempTime.Format("20060102150405")
  1738. chrgBchno := rand.Intn(100000) + 10000
  1739. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1740. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1741. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1742. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1743. strconv.FormatInt(his.PatientId, 10)
  1744. client := &http.Client{}
  1745. data["psn_no"] = his.PsnNo
  1746. data["mdtrt_id"] = his.Number
  1747. data["chrg_bchno"] = chrg_bchno
  1748. data["org_name"] = miConfig.OrgName
  1749. data["doctor"] = roles.UserName
  1750. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1751. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  1752. data["fixmedins_code"] = miConfig.Code
  1753. data["dept_code"] = department.Number
  1754. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1755. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1756. data["secret_key"] = miConfig.SecretKey
  1757. var ids []int64
  1758. for _, item := range prescriptions {
  1759. ids = append(ids, item.ID)
  1760. }
  1761. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1762. if config.IsOpen == 1 { //对接了医保,走医保流程
  1763. bytesData, _ := json.Marshal(data)
  1764. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  1765. resp, _ := client.Do(req)
  1766. defer resp.Body.Close()
  1767. body, ioErr := ioutil.ReadAll(resp.Body)
  1768. if ioErr != nil {
  1769. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1770. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1771. return
  1772. }
  1773. var respJSON map[string]interface{}
  1774. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1775. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1777. return
  1778. }
  1779. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1780. userJSONBytes, _ := json.Marshal(respJSON)
  1781. var res ResultFour
  1782. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1783. utils.ErrorLog("解析失败:%v", err)
  1784. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1785. return
  1786. }
  1787. if res.Infcode == 0 {
  1788. order := &models.HisOrder{
  1789. UserOrgId: adminUser.CurrentOrgId,
  1790. HisPatientId: his.ID,
  1791. PatientId: his.PatientId,
  1792. SettleAccountsDate: recordDateTime,
  1793. Ctime: time.Now().Unix(),
  1794. Mtime: time.Now().Unix(),
  1795. Status: 1,
  1796. Number: chrg_bchno,
  1797. Infcode: res.Infcode,
  1798. WarnMsg: res.WarnMsg,
  1799. Cainfo: res.Cainfo,
  1800. ErrMsg: res.ErrMsg,
  1801. RespondTime: res.RefmsgTime,
  1802. InfRefmsgid: res.InfRefmsgid,
  1803. OrderStatus: 1,
  1804. IsMedicineInsurance: 1,
  1805. SettleType: settle_accounts_type,
  1806. SettleStartTime: start_time,
  1807. SettleEndTime: end_time,
  1808. Creator: roles.ID,
  1809. Modify: roles.ID,
  1810. }
  1811. err = service.CreateOrder(order)
  1812. if err != nil {
  1813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1814. return
  1815. }
  1816. for _, item := range res.Output.Result {
  1817. temp := strings.Split(item.FeedetlSn, "-")
  1818. var advice_id int64 = 0
  1819. var project_id int64 = 0
  1820. var types int64 = 0
  1821. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1822. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1823. if temp[1] == "1" {
  1824. advice_id = id
  1825. project_id = 0
  1826. } else if temp[1] == "2" {
  1827. advice_id = 0
  1828. project_id = id
  1829. }
  1830. info := &models.HisOrderInfo{
  1831. OrderNumber: order.Number,
  1832. FeedetlSn: item.FeedetlSn,
  1833. UploadDate: time.Now().Unix(),
  1834. AdviceId: advice_id,
  1835. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1836. Cnt: item.Cnt,
  1837. Pric: float64(item.Pric),
  1838. PatientId: his.PatientId,
  1839. PricUplmtAmt: item.PricUplmtAmt,
  1840. SelfpayProp: item.SelfpayProp,
  1841. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1842. OverlmtAmt: item.OverlmtAmt,
  1843. PreselfpayAmt: item.PreselfpayAmt,
  1844. BasMednFlag: item.BasMednFlag,
  1845. MedChrgitmType: item.MedChrgitmType,
  1846. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1847. Status: 1,
  1848. Memo: item.Memo,
  1849. Mtime: time.Now().Unix(),
  1850. InscpScpAmt: item.InscpScpAmt,
  1851. DrtReimFlag: item.DrtReimFlag,
  1852. Ctime: time.Now().Unix(),
  1853. ListSpItemFlag: item.ListSpItemFlag,
  1854. ChldMedcFlag: item.ChldMedcFlag,
  1855. LmtUsedFlag: item.LmtUsedFlag,
  1856. ChrgitmLv: item.ChrgitmLv,
  1857. UserOrgId: adminUser.CurrentOrgId,
  1858. HisPatientId: his.ID,
  1859. OrderId: order.ID,
  1860. ProjectId: project_id,
  1861. Type: types,
  1862. }
  1863. service.CreateOrderInfo(info)
  1864. }
  1865. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1866. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1867. var total float64
  1868. for _, item := range prescriptions {
  1869. if item.Type == 1 { //药品
  1870. for _, subItem := range item.HisDoctorAdviceInfo {
  1871. total = total + (subItem.Price * subItem.PrescribingNumber)
  1872. }
  1873. }
  1874. if item.Type == 2 { //项目
  1875. for _, subItem := range item.HisPrescriptionProject {
  1876. total = total + (subItem.Price * float64(subItem.Count))
  1877. }
  1878. }
  1879. }
  1880. for _, item := range prescriptions {
  1881. for _, subItem := range item.HisAdditionalCharge {
  1882. total = total + (subItem.Price * float64(subItem.Count))
  1883. }
  1884. }
  1885. allTotal := fmt.Sprintf("%.2f", total)
  1886. if res.Infcode == 0 {
  1887. var rf []*ResultFive
  1888. json.Unmarshal([]byte(his.Iinfo), &rf)
  1889. psn_no := his.PsnNo
  1890. mdtrt_id := his.Number
  1891. chrg_bchno := chrg_bchno
  1892. cert_no := his.Certno
  1893. insutype := rf[0].Insutype
  1894. if his.IdCardType == 1 {
  1895. cert_no = his.MedicalInsuranceNumber
  1896. } else {
  1897. cert_no = his.Certno
  1898. }
  1899. api := "http://127.0.0.1:9532/" + "gdyb/seven?cert_no=" + cert_no + "&insutype=" +
  1900. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1901. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  1902. miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10)
  1903. resp, requestErr := http.Get(api)
  1904. if requestErr != nil {
  1905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1906. return
  1907. }
  1908. defer resp.Body.Close()
  1909. body, ioErr := ioutil.ReadAll(resp.Body)
  1910. if ioErr != nil {
  1911. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1912. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1913. return
  1914. }
  1915. var respJSON map[string]interface{}
  1916. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1917. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1919. return
  1920. }
  1921. fmt.Println(respJSON)
  1922. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1923. userJSONBytes, _ := json.Marshal(respJSON)
  1924. var res ResultSeven
  1925. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1926. utils.ErrorLog("解析失败:%v", err)
  1927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1928. return
  1929. }
  1930. if res.Infcode == -1 {
  1931. errlog := &models.HisOrderError{
  1932. UserOrgId: adminUser.CurrentOrgId,
  1933. Ctime: time.Now().Unix(),
  1934. Mtime: time.Now().Unix(),
  1935. Number: chrg_bchno,
  1936. ErrMsg: res.ErrMsg,
  1937. Status: 1,
  1938. PatientId: id,
  1939. RecordTime: recordDateTime,
  1940. Stage: 7,
  1941. }
  1942. service.CreateErrMsgLog(errlog)
  1943. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1944. return
  1945. } else {
  1946. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1947. order.OrderStatus = 1
  1948. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1949. order.SetlId = res.Output.Setlinfo.SetlID
  1950. order.PsnNo = res.Output.Setlinfo.PsnNo
  1951. order.PsnName = res.Output.Setlinfo.PsnName
  1952. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1953. order.Certno = res.Output.Setlinfo.Certno
  1954. order.Gend = res.Output.Setlinfo.Gend
  1955. order.Naty = res.Output.Setlinfo.Naty
  1956. order.Age = res.Output.Setlinfo.Age
  1957. order.Insutype = res.Output.Setlinfo.Insutype
  1958. order.PsnType = res.Output.Setlinfo.PsnType
  1959. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1960. order.SetlTime = res.Output.Setlinfo.SetlTime
  1961. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1962. order.MedType = res.Output.Setlinfo.MedType
  1963. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1964. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1965. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1966. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1967. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1968. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1969. order.HifpPay = res.Output.Setlinfo.HifpPay
  1970. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1971. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1972. order.HifesPay = res.Output.Setlinfo.HifesPay
  1973. order.HifobPay = res.Output.Setlinfo.HifobPay
  1974. order.MafPay = res.Output.Setlinfo.MafPay
  1975. order.OthPay = res.Output.Setlinfo.OthPay
  1976. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1977. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1978. order.AcctPay = res.Output.Setlinfo.AcctPay
  1979. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1980. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1981. order.Balc = res.Output.Setlinfo.Balc
  1982. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1983. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1984. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1985. order.ClrWay = res.Output.Setlinfo.ClrWay
  1986. order.Creator = order.Creator
  1987. order.Modify = roles.ID
  1988. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1989. detailStr := string(setlDetail)
  1990. order.SetlDetail = detailStr
  1991. //err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1992. err = service.UpDateOrder(order)
  1993. if err == nil {
  1994. c.ServeSuccessJSON(map[string]interface{}{
  1995. "msg": "预结算成功",
  1996. })
  1997. } else {
  1998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1999. return
  2000. }
  2001. }
  2002. } else {
  2003. adminUser := c.GetAdminUserInfo()
  2004. errlog := &models.HisOrderError{
  2005. UserOrgId: adminUser.CurrentOrgId,
  2006. Ctime: time.Now().Unix(),
  2007. Mtime: time.Now().Unix(),
  2008. ErrMsg: res.ErrMsg,
  2009. Status: 1,
  2010. PatientId: id,
  2011. RecordTime: recordDateTime,
  2012. Stage: 4,
  2013. }
  2014. service.CreateErrMsgLog(errlog)
  2015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2016. return
  2017. }
  2018. } else {
  2019. adminUser := c.GetAdminUserInfo()
  2020. errlog := &models.HisOrderError{
  2021. UserOrgId: adminUser.CurrentOrgId,
  2022. Ctime: time.Now().Unix(),
  2023. Mtime: time.Now().Unix(),
  2024. ErrMsg: res.ErrMsg,
  2025. Status: 1,
  2026. PatientId: id,
  2027. RecordTime: recordDateTime,
  2028. Stage: 4,
  2029. }
  2030. service.CreateErrMsgLog(errlog)
  2031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  2032. return
  2033. }
  2034. } else {
  2035. var total float64
  2036. for _, item := range prescriptions {
  2037. if item.Type == 1 { //药品
  2038. for _, subItem := range item.HisDoctorAdviceInfo {
  2039. total = total + (subItem.Price * subItem.PrescribingNumber)
  2040. }
  2041. }
  2042. if item.Type == 2 { //项目
  2043. for _, subItem := range item.HisPrescriptionProject {
  2044. total = total + (subItem.Price * float64(subItem.Count))
  2045. }
  2046. }
  2047. for _, subItem := range item.HisAdditionalCharge {
  2048. total = total + (subItem.Price * float64(subItem.Count))
  2049. }
  2050. }
  2051. allTotal := fmt.Sprintf("%.2f", total)
  2052. totals, _ := strconv.ParseFloat(allTotal, 64)
  2053. order := &models.HisOrder{
  2054. UserOrgId: adminUser.CurrentOrgId,
  2055. HisPatientId: his.ID,
  2056. PatientId: id,
  2057. SettleAccountsDate: recordDateTime,
  2058. Ctime: time.Now().Unix(),
  2059. Mtime: time.Now().Unix(),
  2060. Status: 1,
  2061. OrderStatus: 2,
  2062. Number: chrg_bchno,
  2063. MedfeeSumamt: totals,
  2064. }
  2065. err = service.CreateOrder(order)
  2066. if err != nil {
  2067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2068. return
  2069. }
  2070. var customs []*Custom
  2071. for _, item := range prescriptions {
  2072. if item.Type == 1 { //药品
  2073. for _, subItem := range item.HisDoctorAdviceInfo {
  2074. cus := &Custom{
  2075. AdviceId: subItem.ID,
  2076. ProjectId: 0,
  2077. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  2078. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  2079. FeedetlSn: subItem.FeedetlSn,
  2080. Price: fmt.Sprintf("%.2f", subItem.Price),
  2081. MedListCodg: subItem.MedListCodg,
  2082. Type: 1,
  2083. }
  2084. customs = append(customs, cus)
  2085. }
  2086. }
  2087. if item.Type == 2 { //项目
  2088. for _, subItem := range item.HisPrescriptionProject {
  2089. cus := &Custom{
  2090. AdviceId: 0,
  2091. ProjectId: subItem.ID,
  2092. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  2093. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  2094. FeedetlSn: subItem.FeedetlSn,
  2095. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  2096. MedListCodg: subItem.MedListCodg,
  2097. Type: 2,
  2098. }
  2099. customs = append(customs, cus)
  2100. }
  2101. }
  2102. for _, item := range item.HisAdditionalCharge {
  2103. cus := &Custom{
  2104. ItemId: item.ID,
  2105. AdviceId: 0,
  2106. ProjectId: 0,
  2107. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  2108. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  2109. FeedetlSn: item.FeedetlSn,
  2110. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  2111. MedListCodg: item.XtHisAddtionConfig.Code,
  2112. Type: 3,
  2113. }
  2114. customs = append(customs, cus)
  2115. }
  2116. }
  2117. for _, item := range customs {
  2118. var advice_id int64 = 0
  2119. var project_id int64 = 0
  2120. var item_id int64 = 0
  2121. var types int64 = 0
  2122. if item.Type == 1 {
  2123. advice_id = item.AdviceId
  2124. project_id = 0
  2125. item_id = 0
  2126. } else if item.Type == 2 {
  2127. advice_id = 0
  2128. item_id = 0
  2129. project_id = item.ProjectId
  2130. } else if item.Type == 3 {
  2131. advice_id = 0
  2132. item_id = item.ItemId
  2133. project_id = 0
  2134. }
  2135. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  2136. cut, _ := strconv.ParseFloat(item.Cut, 32)
  2137. pric, _ := strconv.ParseFloat(item.Price, 32)
  2138. info := &models.HisOrderInfo{
  2139. OrderNumber: order.Number,
  2140. UploadDate: time.Now().Unix(),
  2141. AdviceId: advice_id,
  2142. DetItemFeeSumamt: detItemFeeSumamt,
  2143. Cnt: cut,
  2144. Pric: pric,
  2145. PatientId: id,
  2146. Status: 1,
  2147. Mtime: time.Now().Unix(),
  2148. Ctime: time.Now().Unix(),
  2149. UserOrgId: adminUser.CurrentOrgId,
  2150. HisPatientId: his.ID,
  2151. OrderId: order.ID,
  2152. ProjectId: project_id,
  2153. Type: types,
  2154. ItemId: item_id,
  2155. }
  2156. service.CreateOrderInfo(info)
  2157. }
  2158. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2159. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2160. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  2161. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2162. if err == nil {
  2163. c.ServeSuccessJSON(map[string]interface{}{
  2164. "msg": "结算成功",
  2165. })
  2166. } else {
  2167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2168. return
  2169. }
  2170. }
  2171. }
  2172. func (c *HisApiController) GetSettleInfo() {
  2173. id, _ := c.GetInt64("id")
  2174. order_id, _ := c.GetInt64("order_id")
  2175. record_time := c.GetString("record_time")
  2176. pay_way, _ := c.GetInt64("pay_way")
  2177. pay_price, _ := c.GetFloat("pay_price")
  2178. pay_card_no := c.GetString("pay_card_no")
  2179. discount_price, _ := c.GetFloat("discount_price")
  2180. preferential_price, _ := c.GetFloat("preferential_price")
  2181. reality_price, _ := c.GetFloat("reality_price")
  2182. found_price, _ := c.GetFloat("found_price")
  2183. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2184. private_price, _ := c.GetFloat("private_price")
  2185. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2186. admin_user_id, _ := c.GetInt64("admin_user_id")
  2187. timeLayout := "2006-01-02"
  2188. loc, _ := time.LoadLocation("Local")
  2189. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2190. if err != nil {
  2191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2192. return
  2193. }
  2194. recordDateTime := theTime.Unix()
  2195. adminUser := c.GetAdminUserInfo()
  2196. var prescriptions []*models.HisPrescription
  2197. data := make(map[string]interface{})
  2198. if settle_accounts_type == 1 { //日结
  2199. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  2200. data["pre"] = prescriptions
  2201. } else { //月结
  2202. start_time_str := c.GetString("start_time")
  2203. end_time_str := c.GetString("end_time")
  2204. timeLayout := "2006-01-02"
  2205. loc, _ := time.LoadLocation("Local")
  2206. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2207. if err != nil {
  2208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2209. return
  2210. }
  2211. recordStartTime := theStartTime.Unix()
  2212. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2213. if err != nil {
  2214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2215. return
  2216. }
  2217. recordEndTime := theEndTime.Unix()
  2218. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  2219. data["pre"] = prescriptions
  2220. }
  2221. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2222. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2223. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2224. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2225. strconv.FormatInt(his.PatientId, 10)
  2226. order_src, _ := service.GetHisOrderByID(order_id)
  2227. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2228. if config.IsOpen == 1 { //对接了医保,走医保流程
  2229. var total float64
  2230. for _, item := range prescriptions {
  2231. if item.Type == 1 { //药品
  2232. for _, subItem := range item.HisDoctorAdviceInfo {
  2233. total = total + (subItem.Price * subItem.PrescribingNumber)
  2234. }
  2235. }
  2236. if item.Type == 2 { //项目
  2237. for _, subItem := range item.HisPrescriptionProject {
  2238. total = total + (subItem.Price * float64(subItem.Count))
  2239. }
  2240. }
  2241. }
  2242. for _, item := range prescriptions {
  2243. for _, subItem := range item.HisAdditionalCharge {
  2244. total = total + (subItem.Price * float64(subItem.Count))
  2245. }
  2246. }
  2247. allTotal := fmt.Sprintf("%.2f", total)
  2248. var rf []*ResultFive
  2249. json.Unmarshal([]byte(his.Iinfo), &rf)
  2250. psn_no := order_src.PsnNo
  2251. mdtrt_id := order_src.MdtrtId
  2252. chrg_bchno := order_src.Number
  2253. cert_no := order_src.Certno
  2254. insutype := rf[0].Insutype
  2255. if his.IdCardType == 1 {
  2256. cert_no = his.MedicalInsuranceNumber
  2257. } else {
  2258. cert_no = his.Certno
  2259. }
  2260. api := "http://127.0.0.1:9532/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  2261. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  2262. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  2263. 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)
  2264. resp, requestErr := http.Get(api)
  2265. if requestErr != nil {
  2266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2267. return
  2268. }
  2269. defer resp.Body.Close()
  2270. body, ioErr := ioutil.ReadAll(resp.Body)
  2271. if ioErr != nil {
  2272. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2274. return
  2275. }
  2276. var respJSON map[string]interface{}
  2277. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2278. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2280. return
  2281. }
  2282. fmt.Println(respJSON)
  2283. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2284. userJSONBytes, _ := json.Marshal(respJSON)
  2285. var res ResultSeven
  2286. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2287. utils.ErrorLog("解析失败:%v", err)
  2288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2289. return
  2290. }
  2291. if res.Infcode == -1 {
  2292. errlog := &models.HisOrderError{
  2293. UserOrgId: adminUser.CurrentOrgId,
  2294. Ctime: time.Now().Unix(),
  2295. Mtime: time.Now().Unix(),
  2296. Number: chrg_bchno,
  2297. ErrMsg: res.ErrMsg,
  2298. Status: 1,
  2299. PatientId: id,
  2300. RecordTime: recordDateTime,
  2301. Stage: 6,
  2302. }
  2303. service.CreateErrMsgLog(errlog)
  2304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2305. return
  2306. } else {
  2307. order_src.OrderStatus = 2
  2308. order_src.PayWay = pay_way
  2309. order_src.PayPrice = pay_price
  2310. order_src.PayCardNo = pay_card_no
  2311. order_src.DiscountPrice = discount_price
  2312. order_src.PreferentialPrice = preferential_price
  2313. order_src.RealityPrice = reality_price
  2314. order_src.FoundPrice = found_price
  2315. order_src.MedicalInsurancePrice = medical_insurance_price
  2316. order_src.PrivatePrice = private_price
  2317. order_src.MdtrtId = res.Output.Setlinfo.MdtrtID
  2318. order_src.SetlId = res.Output.Setlinfo.SetlID
  2319. order_src.PsnNo = res.Output.Setlinfo.PsnNo
  2320. order_src.PsnName = res.Output.Setlinfo.PsnName
  2321. order_src.PsnCertType = res.Output.Setlinfo.PsnCertType
  2322. order_src.Certno = res.Output.Setlinfo.Certno
  2323. order_src.Gend = res.Output.Setlinfo.Gend
  2324. order_src.Naty = res.Output.Setlinfo.Naty
  2325. order_src.Age = res.Output.Setlinfo.Age
  2326. order_src.Insutype = res.Output.Setlinfo.Insutype
  2327. order_src.PsnType = res.Output.Setlinfo.PsnType
  2328. order_src.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2329. order_src.SetlTime = res.Output.Setlinfo.SetlTime
  2330. order_src.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2331. order_src.MedType = res.Output.Setlinfo.MedType
  2332. order_src.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2333. order_src.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2334. order_src.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2335. order_src.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2336. order_src.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2337. order_src.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2338. order_src.HifpPay = res.Output.Setlinfo.HifpPay
  2339. order_src.CvlservPay = res.Output.Setlinfo.CvlservPay
  2340. order_src.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2341. order_src.HifesPay = res.Output.Setlinfo.HifesPay
  2342. order_src.HifobPay = res.Output.Setlinfo.HifobPay
  2343. order_src.MafPay = res.Output.Setlinfo.MafPay
  2344. order_src.OthPay = res.Output.Setlinfo.OthPay
  2345. order_src.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2346. order_src.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2347. order_src.AcctPay = res.Output.Setlinfo.AcctPay
  2348. order_src.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2349. order_src.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2350. order_src.Balc = res.Output.Setlinfo.Balc
  2351. order_src.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2352. order_src.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2353. order_src.ClrOptins = res.Output.Setlinfo.ClrOptins
  2354. order_src.ClrWay = res.Output.Setlinfo.ClrWay
  2355. order_src.Creator = order_src.Creator
  2356. order_src.Modify = roles.ID
  2357. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2358. detailStr := string(setlDetail)
  2359. order_src.SetlDetail = detailStr
  2360. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2361. err = service.UpDateOrder(order_src)
  2362. if err == nil {
  2363. c.ServeSuccessJSON(map[string]interface{}{
  2364. "msg": "结算成功",
  2365. })
  2366. } else {
  2367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2368. return
  2369. }
  2370. }
  2371. }
  2372. }
  2373. //退款
  2374. func (c *HisApiController) Refund() {
  2375. order_id, _ := c.GetInt64("order_id")
  2376. admin_user_id, _ := c.GetInt64("admin_user_id")
  2377. number := c.GetString("number")
  2378. record_time := c.GetString("record_time")
  2379. patient_id, _ := c.GetInt64("patient_id")
  2380. timeLayout := "2006-01-02"
  2381. loc, _ := time.LoadLocation("Local")
  2382. adminUser := c.GetAdminUserInfo()
  2383. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2384. fmt.Println(err)
  2385. if err != nil {
  2386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2387. return
  2388. }
  2389. recordDateTime := theTime.Unix()
  2390. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2391. //patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2392. var order models.HisOrder
  2393. order, _ = service.GetHisOrderByID(order_id)
  2394. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2395. if order.ID == 0 {
  2396. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  2397. }
  2398. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2399. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2400. if config.IsOpen == 1 { //对接了医保,走医保流程
  2401. api := "http://127.0.0.1:9532/" + "gdyb/nine?psn_no=" + his.PsnNo +
  2402. "&mdtrt_id=" + his.Number + "&doctor=" + roles.UserName + "&setl_id=" + order.SetlId + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2403. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2404. resp, requestErr := http.Get(api)
  2405. if requestErr != nil {
  2406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2407. return
  2408. }
  2409. body, ioErr := ioutil.ReadAll(resp.Body)
  2410. if ioErr != nil {
  2411. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2413. return
  2414. }
  2415. var respJSON map[string]interface{}
  2416. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2417. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2419. return
  2420. }
  2421. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2422. userJSONBytes, _ := json.Marshal(respJSON)
  2423. fmt.Println(respJSON)
  2424. fmt.Println(userJSONBytes)
  2425. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  2426. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + roles.UserName + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2427. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2428. resp2, requestErr2 := http.Get(api2)
  2429. if requestErr2 != nil {
  2430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2431. return
  2432. }
  2433. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  2434. if ioErr2 != nil {
  2435. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  2436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2437. return
  2438. }
  2439. var respJSON2 map[string]interface{}
  2440. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  2441. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2443. return
  2444. }
  2445. //api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  2446. // "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2447. // "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2448. //resp3, requestErr3 := http.Get(api3)
  2449. //if requestErr3 != nil {
  2450. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2451. // return
  2452. //}
  2453. //
  2454. //body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  2455. //if ioErr3 != nil {
  2456. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  2457. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2458. // return
  2459. //}
  2460. //var respJSON3 map[string]interface{}
  2461. //if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  2462. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2463. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2464. // return
  2465. //}
  2466. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2467. //service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  2468. if err == nil {
  2469. c.ServeSuccessJSON(map[string]interface{}{
  2470. "msg": "退费成功",
  2471. })
  2472. } else {
  2473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2474. return
  2475. }
  2476. } else {
  2477. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2478. if err == nil {
  2479. c.ServeSuccessJSON(map[string]interface{}{
  2480. "msg": "退费成功",
  2481. })
  2482. } else {
  2483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2484. return
  2485. }
  2486. }
  2487. }
  2488. func (c *HisApiController) RefundNumber() {
  2489. record_time := c.GetString("record_time")
  2490. patient_id, _ := c.GetInt64("patient_id")
  2491. admin_user_id, _ := c.GetInt64("admin_user_id")
  2492. timeLayout := "2006-01-02"
  2493. loc, _ := time.LoadLocation("Local")
  2494. adminUser := c.GetAdminUserInfo()
  2495. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2496. fmt.Println(err)
  2497. if err != nil {
  2498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2499. return
  2500. }
  2501. recordDateTime := theTime.Unix()
  2502. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2503. //patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2504. //order, _ := service.GetHisOrderByID(order_id)
  2505. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2506. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2507. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2508. if config.IsOpen == 1 { //对接了医保,走医保流程
  2509. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  2510. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + roles.UserName + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2511. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2512. resp3, requestErr3 := http.Get(api3)
  2513. if requestErr3 != nil {
  2514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2515. return
  2516. }
  2517. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  2518. if ioErr3 != nil {
  2519. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  2520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2521. return
  2522. }
  2523. var respJSON3 map[string]interface{}
  2524. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  2525. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2527. return
  2528. }
  2529. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2530. service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  2531. if err == nil {
  2532. c.ServeSuccessJSON(map[string]interface{}{
  2533. "msg": "退号成功",
  2534. })
  2535. } else {
  2536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2537. return
  2538. }
  2539. } else {
  2540. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2541. //if err == nil {
  2542. // c.ServeSuccessJSON(map[string]interface{}{
  2543. // "msg": "退费成功",
  2544. // })
  2545. //} else {
  2546. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2547. // return
  2548. //}
  2549. }
  2550. }
  2551. func (c *HisApiController) RefundDetail() {
  2552. order_id, _ := c.GetInt64("order_id")
  2553. number := c.GetString("number")
  2554. record_time := c.GetString("record_time")
  2555. patient_id, _ := c.GetInt64("patient_id")
  2556. timeLayout := "2006-01-02"
  2557. loc, _ := time.LoadLocation("Local")
  2558. adminUser := c.GetAdminUserInfo()
  2559. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2560. fmt.Println(err)
  2561. if err != nil {
  2562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2563. return
  2564. }
  2565. recordDateTime := theTime.Unix()
  2566. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2567. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2568. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2569. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2570. var order models.HisOrder
  2571. order, _ = service.GetHisOrderByID(order_id)
  2572. if order.ID == 0 {
  2573. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  2574. }
  2575. if config.IsOpen == 1 { //对接了医保,走医保流程
  2576. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  2577. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2578. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2579. resp2, requestErr2 := http.Get(api2)
  2580. if requestErr2 != nil {
  2581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2582. return
  2583. }
  2584. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  2585. if ioErr2 != nil {
  2586. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  2587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2588. return
  2589. }
  2590. var respJSON2 map[string]interface{}
  2591. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  2592. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2593. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2594. return
  2595. }
  2596. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2597. if err == nil {
  2598. c.ServeSuccessJSON(map[string]interface{}{
  2599. "msg": "退费成功",
  2600. })
  2601. } else {
  2602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2603. return
  2604. }
  2605. } else {
  2606. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2607. if err == nil {
  2608. c.ServeSuccessJSON(map[string]interface{}{
  2609. "msg": "退费成功",
  2610. })
  2611. } else {
  2612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2613. return
  2614. }
  2615. }
  2616. }
  2617. //对账
  2618. func (c *HisApiController) GetCheckAccount() {
  2619. start_time := c.GetString("start_time")
  2620. end_time := c.GetString("end_time")
  2621. insutype := c.GetString("insutype")
  2622. clr_type := c.GetString("clr_type")
  2623. admin_user_id, _ := c.GetInt64("admin_user_id")
  2624. adminUser := c.GetAdminUserInfo()
  2625. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2626. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2627. timeLayout := "2006-01-02"
  2628. loc, _ := time.LoadLocation("Local")
  2629. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2630. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2631. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  2632. orders_two, _ := service.GetOrderByTimeThree(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  2633. fixmedins_setl_cnt := int64(len(orders_two))
  2634. //撤销的算2条数据为一笔
  2635. for _, item := range orders_two {
  2636. if item.OrderStatus == 3 {
  2637. fixmedins_setl_cnt = fixmedins_setl_cnt + 1
  2638. }
  2639. }
  2640. var medfee_sumamt float64
  2641. var acct_pay float64
  2642. var fund_pay_sumamt float64
  2643. for _, item := range orders {
  2644. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  2645. acct_pay = acct_pay + item.AcctPay
  2646. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  2647. }
  2648. var user_name string
  2649. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2650. if role.ID == 0 {
  2651. user_name = "xxx"
  2652. } else {
  2653. user_name = role.UserName
  2654. }
  2655. if config.IsOpen == 1 {
  2656. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  2657. "insutype=" + insutype +
  2658. "&clr_type=" + clr_type +
  2659. "&setl_optins=" + "定点医保中心" +
  2660. "&stmt_begndate=" + start_time +
  2661. "&stm_enddate=" + end_time +
  2662. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  2663. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  2664. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  2665. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  2666. "&fixmedins_code=" + miConfig.Code +
  2667. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2668. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2669. "&secret_key=" + miConfig.SecretKey +
  2670. "&org_name=" + miConfig.OrgName +
  2671. "&doctor=" + user_name
  2672. fmt.Println(api)
  2673. resp, requestErr := http.Get(api)
  2674. if requestErr != nil {
  2675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2676. return
  2677. }
  2678. body, ioErr := ioutil.ReadAll(resp.Body)
  2679. fmt.Println(body)
  2680. if ioErr != nil {
  2681. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2683. return
  2684. }
  2685. var respJSON map[string]interface{}
  2686. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2687. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2689. return
  2690. }
  2691. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2692. userJSONBytes, _ := json.Marshal(respJSON)
  2693. var res ResultEight
  2694. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2695. utils.ErrorLog("解析失败:%v", err)
  2696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2697. return
  2698. }
  2699. if res.Infcode == 0 {
  2700. if res.Output.Stmtinfo.StmtRslt == "0" {
  2701. micc := &models.MedicalInsuranceCostCompare{
  2702. StartTime: startime.Unix(),
  2703. EndTime: endtime.Unix(),
  2704. Insutype: insutype,
  2705. CheckType: 1,
  2706. Num: fixmedins_setl_cnt,
  2707. Mtime: time.Now().Unix(),
  2708. Status: 1,
  2709. UserOrgId: adminUser.CurrentOrgId,
  2710. CostTotal: medfee_sumamt,
  2711. FuncTotal: fund_pay_sumamt,
  2712. PsnPay: acct_pay,
  2713. Creator: admin_user_id,
  2714. Ctime: time.Now().Unix(),
  2715. }
  2716. err := service.CreateMedicalInsuranceCostCompareRecord(micc)
  2717. if err == nil {
  2718. c.ServeSuccessJSON(map[string]interface{}{
  2719. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  2720. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  2721. })
  2722. } else {
  2723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2724. }
  2725. } else {
  2726. c.ServeSuccessJSON(map[string]interface{}{
  2727. "code": -10,
  2728. "msg": res.ErrMsg,
  2729. })
  2730. }
  2731. } else {
  2732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2733. }
  2734. }
  2735. }
  2736. func (c *HisApiController) Check310() {
  2737. adminUser := c.GetAdminUserInfo()
  2738. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2739. var user_name string
  2740. user_name = "xxx"
  2741. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  2742. "insutype=" + "310" +
  2743. "&clr_type=" + "11" +
  2744. "&setl_optins=" + "定点医保中心" +
  2745. "&stmt_begndate=" + "2021-03-01" +
  2746. "&stm_enddate=" + "2021-03-31" +
  2747. "&medfee_sumamt=" + "11521" +
  2748. "&fund_pay_sumamt=" + "10166.66" +
  2749. "&acct_pay=" + "0" +
  2750. "&fixmedins_setl_cnt=" + "7" +
  2751. "&fixmedins_code=" + miConfig.Code +
  2752. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2753. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2754. "&secret_key=" + miConfig.SecretKey +
  2755. "&org_name=" + miConfig.OrgName +
  2756. "&doctor=" + user_name
  2757. fmt.Println(api)
  2758. resp, requestErr := http.Get(api)
  2759. if requestErr != nil {
  2760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2761. return
  2762. }
  2763. body, ioErr := ioutil.ReadAll(resp.Body)
  2764. fmt.Println(body)
  2765. if ioErr != nil {
  2766. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2767. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2768. return
  2769. }
  2770. var respJSON map[string]interface{}
  2771. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2772. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2774. return
  2775. }
  2776. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2777. userJSONBytes, _ := json.Marshal(respJSON)
  2778. var res ResultEight
  2779. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2780. utils.ErrorLog("解析失败:%v", err)
  2781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2782. return
  2783. }
  2784. }
  2785. func (c *HisApiController) Check390() {
  2786. adminUser := c.GetAdminUserInfo()
  2787. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2788. var user_name string
  2789. user_name = "张俊杰"
  2790. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  2791. "insutype=" + "390" +
  2792. "&clr_type=" + "11" +
  2793. "&setl_optins=" + "定点医保中心" +
  2794. "&stmt_begndate=" + "2021-03-01" +
  2795. "&stm_enddate=" + "2021-03-31" +
  2796. "&medfee_sumamt=" + "209318.43" +
  2797. "&fund_pay_sumamt=" + "188029.12" +
  2798. "&acct_pay=" + "0" +
  2799. "&fixmedins_setl_cnt=" + "48" +
  2800. "&fixmedins_code=" + miConfig.Code +
  2801. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2802. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2803. "&secret_key=" + miConfig.SecretKey +
  2804. "&org_name=" + miConfig.OrgName +
  2805. "&doctor=" + user_name
  2806. fmt.Println(api)
  2807. resp, requestErr := http.Get(api)
  2808. if requestErr != nil {
  2809. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2810. return
  2811. }
  2812. body, ioErr := ioutil.ReadAll(resp.Body)
  2813. fmt.Println(body)
  2814. if ioErr != nil {
  2815. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2816. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2817. return
  2818. }
  2819. var respJSON map[string]interface{}
  2820. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2821. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2823. return
  2824. }
  2825. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2826. userJSONBytes, _ := json.Marshal(respJSON)
  2827. var res ResultEight
  2828. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2829. utils.ErrorLog("解析失败:%v", err)
  2830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2831. return
  2832. }
  2833. }
  2834. //对账明细
  2835. func (c *HisApiController) GetCheckDetailAccount() {
  2836. start_time := c.GetString("start_time")
  2837. end_time := c.GetString("end_time")
  2838. admin_user_id, _ := c.GetInt64("admin_user_id")
  2839. adminUser := c.GetAdminUserInfo()
  2840. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2841. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2842. timeLayout := "2006-01-02"
  2843. loc, _ := time.LoadLocation("Local")
  2844. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2845. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2846. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  2847. Mkdir(miConfig.OrgName)
  2848. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  2849. file_name := file + ".txt"
  2850. zip_name := file + ".zip"
  2851. zip_path := miConfig.OrgName + "/" + zip_name
  2852. file_path := miConfig.OrgName + "/" + file_name
  2853. decimal.DivisionPrecision = 2
  2854. var medfee_sumamt float64
  2855. var psn_cash_pay float64
  2856. var fund_pay_sumamt float64
  2857. fixmedins_setl_cnt := int64(len(orders))
  2858. for _, item := range orders {
  2859. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  2860. psn_cash_pay = psn_cash_pay + item.PsnCashPay
  2861. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  2862. }
  2863. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  2864. defer f.Close()
  2865. if err != nil {
  2866. fmt.Println(err.Error())
  2867. } else {
  2868. for _, item := range orders {
  2869. var refd_setl_flag string
  2870. if item.OrderStatus == 2 {
  2871. refd_setl_flag = "0"
  2872. }
  2873. if item.OrderStatus == 3 {
  2874. refd_setl_flag = "1"
  2875. }
  2876. var str string
  2877. str = item.SetlId + " " +
  2878. item.MdtrtId + " " +
  2879. item.PsnNo + " " +
  2880. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  2881. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  2882. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\n"
  2883. _, err = f.Write([]byte(str))
  2884. }
  2885. }
  2886. Zip(file_path, zip_path)
  2887. fmt.Println(ReadFile(zip_path))
  2888. fmt.Println(string(ReadFile(zip_path)))
  2889. if config.IsOpen == 1 {
  2890. var user_name string
  2891. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2892. if role.ID == 0 {
  2893. user_name = "管理员"
  2894. } else {
  2895. user_name = role.UserName
  2896. }
  2897. baseParams := models.BaseParams{
  2898. SecretKey: miConfig.SecretKey,
  2899. FixmedinsCode: miConfig.Code,
  2900. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2901. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2902. OrgName: miConfig.OrgName,
  2903. Doctor: user_name,
  2904. }
  2905. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  2906. var dat map[string]interface{}
  2907. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2908. fmt.Println(dat)
  2909. } else {
  2910. fmt.Println(err)
  2911. }
  2912. userJSONBytes, _ := json.Marshal(dat)
  2913. var res ResultNine
  2914. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2915. utils.ErrorLog("解析失败:%v", err)
  2916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2917. return
  2918. }
  2919. if res.Infcode == 0 {
  2920. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  2921. "file_qury_no=" + res.Output.FileQuryNo +
  2922. "&setl_optins=" + "定点医保中心" +
  2923. "&stmt_begndate=" + start_time +
  2924. "&stm_enddate=" + end_time +
  2925. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  2926. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  2927. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  2928. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  2929. "&fixmedins_code=" + miConfig.Code +
  2930. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2931. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2932. "&secret_key=" + miConfig.SecretKey +
  2933. "&org_name=" + miConfig.OrgName +
  2934. "&doctor=" + user_name
  2935. resp, requestErr := http.Get(api)
  2936. if requestErr != nil {
  2937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2938. return
  2939. }
  2940. body, ioErr := ioutil.ReadAll(resp.Body)
  2941. if ioErr != nil {
  2942. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2943. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2944. return
  2945. }
  2946. var respJSON map[string]interface{}
  2947. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2948. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2950. return
  2951. }
  2952. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2953. userJSONBytes, _ := json.Marshal(respJSON)
  2954. var res ResultTen
  2955. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2956. utils.ErrorLog("解析失败:%v", err)
  2957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2958. return
  2959. }
  2960. if res.Infcode == 0 {
  2961. service.Gdyb9102(baseParams, zip_name, res.Output.FileQuryNo)
  2962. micc := &models.MedicalInsuranceCostCompare{
  2963. StartTime: startime.Unix(),
  2964. EndTime: endtime.Unix(),
  2965. Insutype: "0",
  2966. CheckType: 2,
  2967. Num: fixmedins_setl_cnt,
  2968. Mtime: time.Now().Unix(),
  2969. Status: 1,
  2970. UserOrgId: adminUser.CurrentOrgId,
  2971. CostTotal: medfee_sumamt,
  2972. FuncTotal: fund_pay_sumamt,
  2973. PsnPay: psn_cash_pay,
  2974. Creator: admin_user_id,
  2975. Ctime: time.Now().Unix(),
  2976. }
  2977. service.CreateMedicalInsuranceCostCompareRecord(micc)
  2978. c.ServeSuccessJSON(map[string]interface{}{
  2979. "msg": "明细对账成功",
  2980. })
  2981. }
  2982. } else {
  2983. }
  2984. }
  2985. }
  2986. func (c *HisApiController) GetSettleAccounts() {
  2987. //id, _ := c.GetInt64("id")
  2988. //record_time := c.GetString("record_time")
  2989. order_id, _ := c.GetInt64("order_id")
  2990. admin_user_id, _ := c.GetInt64("admin_user_id")
  2991. //timeLayout := "2006-01-02"
  2992. //loc, _ := time.LoadLocation("Local")
  2993. //
  2994. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2995. //if err != nil {
  2996. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2997. // return
  2998. //}
  2999. //recordDateTime := theTime.Unix()
  3000. adminUser := c.GetAdminUserInfo()
  3001. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  3002. order, _ := service.GetHisOrderByID(order_id)
  3003. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  3004. var bedCostTotal float64 = 0 //床位总费
  3005. var bedCostSelfTotal float64 = 0 //床位自费
  3006. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  3007. var operationCostTotal float64 = 0 //手术费
  3008. var operationCostSelfTotal float64 = 0 //手术费
  3009. var operationCostPartSelfTotal float64 = 0 //手术费
  3010. var otherCostTotal float64 = 0 //其他费用
  3011. var otherCostSelfTotal float64 = 0 //其他费用
  3012. var otherCostPartSelfTotal float64 = 0 //其他费用
  3013. var materialCostTotal float64 = 0 //材料费
  3014. var materialCostSelfTotal float64 = 0 //材料费
  3015. var materialCostPartSelfTotal float64 = 0 //材料费
  3016. var westernMedicineCostTotal float64 = 0 //西药费
  3017. var westernMedicineCostSelfTotal float64 = 0 //西药费
  3018. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  3019. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  3020. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  3021. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  3022. var checkCostTotal float64 = 0 //检查费
  3023. var checkCostSelfTotal float64 = 0 //检查费
  3024. var checkCostPartSelfTotal float64 = 0 //检查费
  3025. var laboratoryCostTotal float64 = 0 //化验费
  3026. var laboratoryCostSelfTotal float64 = 0 //化验费
  3027. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  3028. var treatCostTotal float64 = 0 //治疗费用
  3029. var treatCostSelfTotal float64 = 0 //治疗费用
  3030. var treatCostPartSelfTotal float64 = 0 //治疗费用
  3031. decimal.DivisionPrecision = 2
  3032. for _, item := range orderInfos {
  3033. if item.MedChrgitmType == "01" { //床位费
  3034. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3035. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3036. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3037. }
  3038. if item.MedChrgitmType == "03" { //检查费
  3039. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3040. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3041. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3042. }
  3043. if item.MedChrgitmType == "04" { //化验费
  3044. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3045. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3046. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3047. }
  3048. if item.MedChrgitmType == "05" { //治疗费
  3049. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3050. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3051. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3052. }
  3053. if item.MedChrgitmType == "06" { //手术费
  3054. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3055. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3056. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3057. }
  3058. if item.MedChrgitmType == "08" { //材料费
  3059. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3060. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3061. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3062. }
  3063. if item.MedChrgitmType == "09" { //西药费
  3064. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3065. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3066. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3067. }
  3068. if item.MedChrgitmType == "11" { //中成费
  3069. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3070. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3071. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3072. }
  3073. if item.MedChrgitmType == "14" { //其他费
  3074. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3075. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3076. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3077. }
  3078. }
  3079. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3080. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3081. var user_name string
  3082. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3083. if role.ID == 0 {
  3084. user_name = "管理员"
  3085. } else {
  3086. user_name = role.UserName
  3087. }
  3088. baseParams := models.BaseParams{
  3089. SecretKey: miConfig.SecretKey,
  3090. FixmedinsCode: miConfig.Code,
  3091. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3092. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3093. OrgName: miConfig.OrgName,
  3094. Doctor: user_name,
  3095. }
  3096. businessParams := models.BusinessParams{
  3097. PsnNo: order.PsnNo,
  3098. MdtrtId: order.MdtrtId,
  3099. SetlId: order.SetlId,
  3100. }
  3101. if config.IsOpen == 1 {
  3102. result := service.Gdyb5203(baseParams, businessParams)
  3103. var dat map[string]interface{}
  3104. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3105. fmt.Println(dat)
  3106. } else {
  3107. fmt.Println(err)
  3108. }
  3109. userJSONBytes, _ := json.Marshal(dat)
  3110. var res ResultEleven
  3111. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3112. utils.ErrorLog("解析失败:%v", err)
  3113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3114. return
  3115. }
  3116. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3117. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  3118. if res.Infcode == 0 {
  3119. c.ServeSuccessJSON(map[string]interface{}{
  3120. "charge_admin": charge_admin,
  3121. "printor_admin": printor_admin,
  3122. "info": res.Output.Setlinfo,
  3123. "bedCostTotal": bedCostTotal,
  3124. "bedCostSelfTotal": bedCostSelfTotal,
  3125. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  3126. "operationCostTotal": operationCostTotal,
  3127. "operationCostSelfTotal": operationCostSelfTotal,
  3128. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  3129. "otherCostTotal": otherCostTotal,
  3130. "otherCostSelfTotal": otherCostSelfTotal,
  3131. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  3132. "materialCostTotal": materialCostTotal,
  3133. "materialCostSelfTotal": materialCostSelfTotal,
  3134. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  3135. "westernMedicineCostTotal": westernMedicineCostTotal,
  3136. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  3137. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  3138. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  3139. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  3140. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  3141. "checkCostTotal": checkCostTotal,
  3142. "checkCostSelfTotal": checkCostSelfTotal,
  3143. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  3144. "laboratoryCostTotal": laboratoryCostTotal,
  3145. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  3146. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  3147. "treatCostTotal": treatCostTotal,
  3148. "treatCostSelfTotal": treatCostSelfTotal,
  3149. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  3150. })
  3151. }
  3152. }
  3153. }
  3154. func (c *HisApiController) CheckTreatment() {
  3155. patient_id, _ := c.GetInt64("patient_id", 0)
  3156. record_time := c.GetString("record_time")
  3157. insutype := c.GetString("insutype")
  3158. timeLayout := "2006-01-02"
  3159. loc, _ := time.LoadLocation("Local")
  3160. adminUser := c.GetAdminUserInfo()
  3161. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3162. fmt.Println(err)
  3163. if err != nil {
  3164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3165. return
  3166. }
  3167. recordDateTime := theTime.Unix()
  3168. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3169. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3170. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3171. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3172. var user_name string
  3173. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  3174. if role.ID == 0 {
  3175. user_name = "xxx"
  3176. } else {
  3177. user_name = role.UserName
  3178. }
  3179. baseParams := models.BaseParams{
  3180. SecretKey: miConfig.SecretKey,
  3181. FixmedinsCode: miConfig.Code,
  3182. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3183. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3184. OrgName: miConfig.OrgName,
  3185. Doctor: user_name,
  3186. }
  3187. if config.IsOpen == 1 {
  3188. result := service.Gdyb2001(baseParams, his.PsnNo, insutype, strconv.FormatInt(patientPrescription.RegisterType, 10))
  3189. var dat map[string]interface{}
  3190. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3191. fmt.Println(dat)
  3192. } else {
  3193. fmt.Println(err)
  3194. }
  3195. }
  3196. }
  3197. func (c *HisApiController) PutRecord() {
  3198. id, _ := c.GetInt64("id")
  3199. record_time := c.GetString("record_time")
  3200. timeLayout := "2006-01-02"
  3201. loc, _ := time.LoadLocation("Local")
  3202. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3203. if err != nil {
  3204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3205. return
  3206. }
  3207. recordDateTime := theTime.Unix()
  3208. adminInfo := c.GetAdminUserInfo()
  3209. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  3210. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3211. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  3212. fmt.Println(miConfig.SecretKey)
  3213. if patient == nil {
  3214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3215. return
  3216. }
  3217. if len(patient.IdCardNo) == 0 {
  3218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  3219. return
  3220. }
  3221. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  3222. if config.IsOpen == 1 {
  3223. 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
  3224. resp, requestErr := http.Get(api)
  3225. if requestErr != nil {
  3226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3227. return
  3228. }
  3229. defer resp.Body.Close()
  3230. body, ioErr := ioutil.ReadAll(resp.Body)
  3231. if ioErr != nil {
  3232. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3234. return
  3235. }
  3236. var respJSON map[string]interface{}
  3237. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3238. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3240. return
  3241. }
  3242. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3243. userJSONBytes, _ := json.Marshal(userJSON)
  3244. var res ResultTwo
  3245. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3246. utils.ErrorLog("解析失败:%v", err)
  3247. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3248. return
  3249. }
  3250. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  3251. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  3252. infoStr := string(Iinfos)
  3253. idetinfoStr := string(Idetinfos)
  3254. if res.Infcode == 0 {
  3255. his := models.VMHisPatient{
  3256. Status: 1,
  3257. Ctime: time.Now().Unix(),
  3258. Mtime: time.Now().Unix(),
  3259. PsnNo: res.Output.Baseinfo.PsnNo,
  3260. PsnCertType: res.Output.Baseinfo.PsnCertType,
  3261. Certno: res.Output.Baseinfo.Certno,
  3262. PsnName: res.Output.Baseinfo.PsnName,
  3263. Gend: res.Output.Baseinfo.Gend,
  3264. Naty: res.Output.Baseinfo.Naty,
  3265. Brdy: res.Output.Baseinfo.Brdy,
  3266. Age: res.Output.Baseinfo.Age,
  3267. Iinfo: infoStr,
  3268. Idetinfo: idetinfoStr,
  3269. PatientId: patient.ID,
  3270. RecordDate: theTime.Unix(),
  3271. UserOrgId: adminInfo.CurrentOrgId,
  3272. AdminUserId: adminInfo.AdminUser.Id,
  3273. IsReturn: 1,
  3274. }
  3275. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  3276. 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")
  3277. 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")
  3278. var dat map[string]interface{}
  3279. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3280. fmt.Println(dat)
  3281. } else {
  3282. fmt.Println(err)
  3283. }
  3284. var dat2 map[string]interface{}
  3285. if err := json.Unmarshal([]byte(result2), &dat2); err == nil {
  3286. fmt.Println(dat2)
  3287. } else {
  3288. fmt.Println(err)
  3289. }
  3290. } else {
  3291. adminUser := c.GetAdminUserInfo()
  3292. errlog := &models.HisOrderError{
  3293. UserOrgId: adminUser.CurrentOrgId,
  3294. Ctime: time.Now().Unix(),
  3295. Mtime: time.Now().Unix(),
  3296. ErrMsg: res.ErrMsg,
  3297. Status: 1,
  3298. PatientId: id,
  3299. RecordTime: recordDateTime,
  3300. Stage: 1,
  3301. }
  3302. service.CreateErrMsgLog(errlog)
  3303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  3304. return
  3305. }
  3306. }
  3307. }
  3308. func (c *HisApiController) GetUploadDiag() {
  3309. id, _ := c.GetInt64("id")
  3310. record_time := c.GetString("record_time")
  3311. diagnosis_id, _ := c.GetInt64("diagnosis")
  3312. sick_type, _ := c.GetInt64("sick_type")
  3313. reg_type, _ := c.GetInt64("reg_type")
  3314. timeLayout := "2006-01-02"
  3315. loc, _ := time.LoadLocation("Local")
  3316. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3317. if err != nil {
  3318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3319. return
  3320. }
  3321. var patientPrescription models.HisPrescriptionInfo
  3322. recordDateTime := theTime.Unix()
  3323. adminInfo := c.GetAdminUserInfo()
  3324. patientPrescription, _ = service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3325. if patientPrescription.ID == 0 {
  3326. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3327. }
  3328. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  3329. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  3330. his, _ := service.GetVMHisPatientInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3331. sickConfig, _ := service.FindSickById(sick_type)
  3332. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  3333. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  3334. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  3335. "&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 +
  3336. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  3337. resp2, requestErr2 := http.Get(api2)
  3338. if requestErr2 != nil {
  3339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3340. return
  3341. }
  3342. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  3343. if ioErr2 != nil {
  3344. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  3345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3346. return
  3347. }
  3348. var respJSON2 map[string]interface{}
  3349. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  3350. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3352. return
  3353. }
  3354. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3355. userJSONBytes2, _ := json.Marshal(respJSON2)
  3356. var res2 ResultSix
  3357. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  3358. utils.ErrorLog("解析失败:%v", err)
  3359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3360. return
  3361. }
  3362. if res2.Infcode == -1 {
  3363. adminUser := c.GetAdminUserInfo()
  3364. errlog := &models.HisOrderError{
  3365. UserOrgId: adminUser.CurrentOrgId,
  3366. Ctime: time.Now().Unix(),
  3367. Mtime: time.Now().Unix(),
  3368. ErrMsg: res2.ErrMsg,
  3369. Status: 1,
  3370. PatientId: id,
  3371. RecordTime: recordDateTime,
  3372. Stage: 3,
  3373. }
  3374. service.CreateErrMsgLog(errlog)
  3375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  3376. return
  3377. }
  3378. c.ServeSuccessJSON(map[string]interface{}{
  3379. "msg": "上传成功",
  3380. })
  3381. }
  3382. type QueryResult struct {
  3383. ID int64
  3384. Name string
  3385. Code string
  3386. List_type_code string
  3387. }
  3388. func (c *HisApiController) GetCheckCode() {
  3389. ids_str := c.GetString("ids")
  3390. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  3391. ids_arr := strings.Split(ids_str, ",")
  3392. var queryResult []QueryResult
  3393. ids := make([]int64, 0)
  3394. for _, item := range ids_arr {
  3395. id, _ := strconv.ParseInt(item, 10, 64)
  3396. ids = append(ids, id)
  3397. }
  3398. if record_type == 1 {
  3399. drugs, _ := service.GetBatchDrugList(ids)
  3400. for _, item := range drugs {
  3401. result := QueryResult{
  3402. ID: item.ID,
  3403. Name: item.DrugName,
  3404. Code: item.MedicalInsuranceNumber,
  3405. List_type_code: "101",
  3406. }
  3407. queryResult = append(queryResult, result)
  3408. }
  3409. } else if record_type == 2 {
  3410. goods, _ := service.GetBatchGoodInformationList(ids)
  3411. for _, item := range goods {
  3412. result := QueryResult{
  3413. ID: item.ID,
  3414. Name: item.GoodName,
  3415. Code: item.MedicalInsuranceNumber,
  3416. List_type_code: "301",
  3417. }
  3418. queryResult = append(queryResult, result)
  3419. }
  3420. } else if record_type == 3 {
  3421. projects, _ := service.GetBathchMyPorjecgList(ids)
  3422. for _, item := range projects {
  3423. result := QueryResult{
  3424. ID: item.ID,
  3425. Name: item.ProjectName,
  3426. Code: item.MedicalCode,
  3427. List_type_code: "201",
  3428. }
  3429. queryResult = append(queryResult, result)
  3430. }
  3431. }
  3432. admin_user_id, _ := c.GetInt64("admin_user_id")
  3433. adminUser := c.GetAdminUserInfo()
  3434. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3435. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3436. var user_name string
  3437. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3438. if role.ID == 0 {
  3439. user_name = "xxx"
  3440. } else {
  3441. user_name = role.UserName
  3442. }
  3443. baseParams := &models.BaseParams{
  3444. SecretKey: miConfig.SecretKey,
  3445. FixmedinsCode: miConfig.Code,
  3446. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3447. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3448. OrgName: miConfig.OrgName,
  3449. Doctor: user_name,
  3450. }
  3451. if config.IsOpen == 1 {
  3452. for _, item := range queryResult {
  3453. var result string
  3454. if record_type == 1 {
  3455. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  3456. } else if record_type == 2 {
  3457. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  3458. } else if record_type == 3 {
  3459. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  3460. }
  3461. var dat map[string]interface{}
  3462. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3463. fmt.Println(dat)
  3464. } else {
  3465. fmt.Println(err)
  3466. }
  3467. userJSONBytes, _ := json.Marshal(dat)
  3468. var res ResultSix
  3469. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3470. utils.ErrorLog("解析失败:%v", err)
  3471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3472. return
  3473. }
  3474. if res.Infcode == 0 {
  3475. if record_type == 1 {
  3476. service.UpdateBaseDrugById(item.ID)
  3477. } else if record_type == 2 {
  3478. service.UpdateGoodInformaitonByDetail(item.ID)
  3479. } else if record_type == 3 {
  3480. service.UpdateProjectById(item.ID)
  3481. }
  3482. c.ServeSuccessJSON(map[string]interface{}{
  3483. "failed_code": 0,
  3484. "msg": "目录对照成功",
  3485. })
  3486. } else {
  3487. c.ServeSuccessJSON(map[string]interface{}{
  3488. "failed_code": -10,
  3489. "msg": res.ErrMsg,
  3490. })
  3491. }
  3492. }
  3493. }
  3494. }
  3495. func (c *HisApiController) UnCheckCode() {
  3496. ids_str := c.GetString("ids")
  3497. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  3498. admin_user_id, _ := c.GetInt64("admin_user_id")
  3499. ids_arr := strings.Split(ids_str, ",")
  3500. var queryResult []QueryResult
  3501. ids := make([]int64, 0)
  3502. for _, item := range ids_arr {
  3503. id, _ := strconv.ParseInt(item, 10, 64)
  3504. ids = append(ids, id)
  3505. }
  3506. if record_type == 1 {
  3507. drugs, _ := service.GetBatchDrugList(ids)
  3508. for _, item := range drugs {
  3509. result := QueryResult{
  3510. ID: item.ID,
  3511. Name: item.DrugName,
  3512. Code: item.MedicalInsuranceNumber,
  3513. List_type_code: "101",
  3514. }
  3515. queryResult = append(queryResult, result)
  3516. }
  3517. } else if record_type == 2 {
  3518. goods, _ := service.GetBatchGoodInformationList(ids)
  3519. for _, item := range goods {
  3520. result := QueryResult{
  3521. ID: item.ID,
  3522. Name: item.GoodName,
  3523. Code: item.MedicalInsuranceNumber,
  3524. List_type_code: "301",
  3525. }
  3526. queryResult = append(queryResult, result)
  3527. }
  3528. } else if record_type == 3 {
  3529. projects, _ := service.GetBathchMyPorjecgList(ids)
  3530. for _, item := range projects {
  3531. result := QueryResult{
  3532. ID: item.ID,
  3533. Name: item.ProjectName,
  3534. Code: item.MedicalCode,
  3535. List_type_code: "201",
  3536. }
  3537. queryResult = append(queryResult, result)
  3538. }
  3539. }
  3540. adminUser := c.GetAdminUserInfo()
  3541. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3542. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3543. var user_name string
  3544. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3545. if role.ID == 0 {
  3546. user_name = "xxx"
  3547. } else {
  3548. user_name = role.UserName
  3549. }
  3550. baseParams := &models.BaseParams{
  3551. SecretKey: miConfig.SecretKey,
  3552. FixmedinsCode: miConfig.Code,
  3553. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3554. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3555. OrgName: miConfig.OrgName,
  3556. Doctor: user_name,
  3557. }
  3558. if config.IsOpen == 1 {
  3559. for _, item := range queryResult {
  3560. var result string
  3561. if record_type == 1 {
  3562. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  3563. } else if record_type == 2 {
  3564. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  3565. } else if record_type == 3 {
  3566. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  3567. }
  3568. var dat2 map[string]interface{}
  3569. if err := json.Unmarshal([]byte(result), &dat2); err == nil {
  3570. fmt.Println(dat2)
  3571. } else {
  3572. fmt.Println(err)
  3573. }
  3574. userJSONBytes, _ := json.Marshal(dat2)
  3575. var res ResultSix
  3576. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3577. utils.ErrorLog("解析失败:%v", err)
  3578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3579. return
  3580. }
  3581. if res.Infcode == 0 {
  3582. if record_type == 1 {
  3583. service.UpdateDrugByIdDetail(item.ID)
  3584. } else if record_type == 2 {
  3585. service.UpdateGoodInfoById(item.ID)
  3586. } else if record_type == 3 {
  3587. service.UpdateMyProjectById(item.ID)
  3588. }
  3589. c.ServeSuccessJSON(map[string]interface{}{
  3590. "failed_code": 0,
  3591. "msg": "撤销目录对照成功",
  3592. })
  3593. } else {
  3594. c.ServeSuccessJSON(map[string]interface{}{
  3595. "failed_code": -10,
  3596. "msg": res.ErrMsg,
  3597. })
  3598. }
  3599. }
  3600. }
  3601. }
  3602. func (c *HisApiController) GetPatientInfo() {
  3603. id_card_no := c.GetString("id_card_no")
  3604. admin_user_id, _ := c.GetInt64("admin_user_id")
  3605. patient, _ := service.GetPatientByIDCard(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  3606. if patient.ID == 0 {
  3607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3608. return
  3609. }
  3610. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  3611. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  3612. config, _ := service.GetMedicalInsuranceConfig(c.GetAdminUserInfo().CurrentOrgId)
  3613. if config.IsOpen == 1 {
  3614. result := service.Gdyb1101A(id_card_no, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  3615. var dat map[string]interface{}
  3616. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3617. fmt.Println(dat)
  3618. } else {
  3619. fmt.Println(err)
  3620. }
  3621. userJSONBytes, _ := json.Marshal(dat)
  3622. var res ResultTwo
  3623. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3624. utils.ErrorLog("解析失败:%v", err)
  3625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3626. return
  3627. }
  3628. if res.Infcode == -1 {
  3629. c.ServeSuccessJSON(map[string]interface{}{
  3630. "failed_code": -10,
  3631. "msg": res.ErrMsg,
  3632. })
  3633. } else {
  3634. c.ServeSuccessJSON(map[string]interface{}{
  3635. "failed_code": 0,
  3636. "info": res,
  3637. })
  3638. }
  3639. }
  3640. }
  3641. func (c *HisApiController) PsnPutOnRecord() {
  3642. record_type, _ := c.GetInt64("type")
  3643. patient_id, _ := c.GetInt64("patient_id")
  3644. admin_user_id, _ := c.GetInt64("admin_user_id")
  3645. start_time := c.GetString("start_time")
  3646. end_time := c.GetString("end_time")
  3647. adminUser := c.GetAdminUserInfo()
  3648. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3649. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3650. var patients []*models.Patients
  3651. if record_type == 1 { //全部备案
  3652. patient, _ := service.GetAllPatient(adminUser.CurrentOrgId)
  3653. patients = append(patients, patient...)
  3654. } else { //单个备案
  3655. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  3656. patients = append(patients, patient)
  3657. }
  3658. var user_name string
  3659. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3660. if role.ID == 0 {
  3661. user_name = "xxx"
  3662. } else {
  3663. user_name = role.UserName
  3664. }
  3665. if config.IsOpen == 1 {
  3666. for _, item := range patients {
  3667. 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
  3668. resp, requestErr := http.Get(api)
  3669. if requestErr != nil {
  3670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3671. return
  3672. }
  3673. defer resp.Body.Close()
  3674. body, ioErr := ioutil.ReadAll(resp.Body)
  3675. if ioErr != nil {
  3676. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3678. return
  3679. }
  3680. var respJSON map[string]interface{}
  3681. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3682. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3684. return
  3685. }
  3686. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3687. userJSONBytes, _ := json.Marshal(userJSON)
  3688. var res ResultTwo
  3689. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3690. utils.ErrorLog("解析失败:%v", err)
  3691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3692. return
  3693. }
  3694. if res.Infcode == 0 {
  3695. result := service.Gdyb2505(res.Output.Baseinfo.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, start_time, end_time)
  3696. var dat map[string]interface{}
  3697. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3698. fmt.Println(dat)
  3699. } else {
  3700. fmt.Println(err)
  3701. }
  3702. userJSONBytes, _ := json.Marshal(dat)
  3703. var res2 ResultThirteen
  3704. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  3705. utils.ErrorLog("解析失败:%v", err)
  3706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3707. return
  3708. }
  3709. if res2.Infcode == 0 {
  3710. psnResult := &models.GdybPsnRecord{
  3711. UserOrgId: adminUser.CurrentOrgId,
  3712. PatientId: item.ID,
  3713. PsnNo: res.Output.Baseinfo.PsnNo,
  3714. Ctime: time.Now().Unix(),
  3715. Mtime: time.Now().Unix(),
  3716. Status: 1,
  3717. IsCancel: 1,
  3718. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  3719. }
  3720. service.CreatePsnRecord(psnResult)
  3721. } else {
  3722. c.ServeSuccessJSON(map[string]interface{}{
  3723. "failed_code": -10,
  3724. "msg": res2.ErrMsg,
  3725. })
  3726. return
  3727. }
  3728. }
  3729. }
  3730. }
  3731. }
  3732. func (c *HisApiController) PsnUnPutOnRecord() {
  3733. id, _ := c.GetInt64("id")
  3734. //record_type, _ := c.GetInt64("type")
  3735. admin_user_id, _ := c.GetInt64("admin_user_id")
  3736. adminUser := c.GetAdminUserInfo()
  3737. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3738. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3739. var user_name string
  3740. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3741. if role.ID == 0 {
  3742. user_name = "xxx"
  3743. } else {
  3744. user_name = role.UserName
  3745. }
  3746. psn_record, _ := service.GetPsnRecordById(id)
  3747. if psn_record.ID == 0 {
  3748. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  3749. return
  3750. }
  3751. if config.IsOpen == 1 {
  3752. result := service.Gdyb2506(psn_record.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  3753. var dat map[string]interface{}
  3754. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3755. fmt.Println(dat)
  3756. } else {
  3757. fmt.Println(err)
  3758. }
  3759. userJSONBytes, _ := json.Marshal(dat)
  3760. var res ResultFourteen
  3761. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3762. utils.ErrorLog("解析失败:%v", err)
  3763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3764. return
  3765. }
  3766. if res.Infcode == 0 {
  3767. psn_record.IsCancel = 2
  3768. service.CreatePsnRecord(&psn_record)
  3769. } else {
  3770. c.ServeSuccessJSON(map[string]interface{}{
  3771. "failed_code": -10,
  3772. "msg": res.ErrMsg,
  3773. })
  3774. return
  3775. }
  3776. }
  3777. }
  3778. func (c *HisApiController) PsnPutNCDSOnRecord() {
  3779. patient_id, _ := c.GetInt64("patient_id")
  3780. insutype := c.GetString("insutype")
  3781. psn_no := c.GetString("psn_no")
  3782. doctor_id, _ := c.GetInt64("doctor_id")
  3783. sick_id, _ := c.GetInt64("sick_id")
  3784. department_id, _ := c.GetInt64("department_id")
  3785. adminUser := c.GetAdminUserInfo()
  3786. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  3787. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3788. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3789. sick, _ := service.FindSickById(sick_id)
  3790. doctor, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, doctor_id)
  3791. if config.IsOpen == 1 {
  3792. 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)
  3793. var dat map[string]interface{}
  3794. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3795. fmt.Println(dat)
  3796. } else {
  3797. fmt.Println(err)
  3798. }
  3799. userJSONBytes, _ := json.Marshal(dat)
  3800. var res2 ResultThirteen
  3801. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  3802. utils.ErrorLog("解析失败:%v", err)
  3803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3804. return
  3805. }
  3806. if res2.Infcode == 0 {
  3807. psnResult := &models.GdybPsnNcdsRecord{
  3808. UserOrgId: adminUser.CurrentOrgId,
  3809. PatientId: patient.ID,
  3810. PsnNo: psn_no,
  3811. DoctorId: doctor.AdminUserId,
  3812. DepartmentId: department_id,
  3813. SickType: sick_id,
  3814. Insutype: insutype,
  3815. Ctime: time.Now().Unix(),
  3816. Mtime: time.Now().Unix(),
  3817. Status: 1,
  3818. IsCancel: 1,
  3819. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  3820. }
  3821. service.CreatePsnNCDSRecord(psnResult)
  3822. c.ServeSuccessJSON(map[string]interface{}{
  3823. "failed_code": 0,
  3824. "msg": "备案成功",
  3825. "result": psnResult,
  3826. })
  3827. } else {
  3828. c.ServeSuccessJSON(map[string]interface{}{
  3829. "failed_code": -10,
  3830. "msg": res2.ErrMsg,
  3831. })
  3832. return
  3833. }
  3834. }
  3835. }
  3836. func (c *HisApiController) PsnPutUnNCDSOnRecord() {
  3837. id, _ := c.GetInt64("id")
  3838. admin_user_id, _ := c.GetInt64("admin_user_id")
  3839. adminUser := c.GetAdminUserInfo()
  3840. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3841. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3842. var user_name string
  3843. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3844. if role.ID == 0 {
  3845. user_name = "xxx"
  3846. } else {
  3847. user_name = role.UserName
  3848. }
  3849. psn_record, _ := service.GetPsnNCDSRecordById(id)
  3850. if psn_record.ID == 0 {
  3851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  3852. return
  3853. }
  3854. if config.IsOpen == 1 {
  3855. result := service.Gdyb2504(psn_record.PsnNo, miConfig.OrgName, user_name, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  3856. var dat map[string]interface{}
  3857. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3858. fmt.Println(dat)
  3859. } else {
  3860. fmt.Println(err)
  3861. }
  3862. userJSONBytes, _ := json.Marshal(dat)
  3863. var res ResultFourteen
  3864. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3865. utils.ErrorLog("解析失败:%v", err)
  3866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3867. return
  3868. }
  3869. if res.Infcode == 0 {
  3870. psn_record.IsCancel = 2
  3871. service.CreatePsnNCDSRecord(&psn_record)
  3872. c.ServeSuccessJSON(map[string]interface{}{
  3873. "failed_code": 0,
  3874. "msg": "撤销备案成功",
  3875. })
  3876. } else {
  3877. c.ServeSuccessJSON(map[string]interface{}{
  3878. "failed_code": -10,
  3879. "msg": res.ErrMsg,
  3880. })
  3881. return
  3882. }
  3883. }
  3884. }
  3885. func PathExists(path string) (bool, error) {
  3886. _, err := os.Stat(path)
  3887. if err == nil {
  3888. return true, nil
  3889. }
  3890. if os.IsNotExist(err) {
  3891. return false, nil
  3892. }
  3893. return false, err
  3894. }
  3895. //创建文件夹
  3896. func Mkdir(dir string) {
  3897. // 创建文件夹
  3898. exist, err := PathExists(dir)
  3899. if err != nil {
  3900. fmt.Println(err.Error())
  3901. } else {
  3902. if exist {
  3903. fmt.Println(dir + "文件夹已存在!")
  3904. } else {
  3905. // 文件夹名称,权限
  3906. err := os.Mkdir(dir, os.ModePerm)
  3907. if err != nil {
  3908. fmt.Println(dir+"文件夹创建失败:", err.Error())
  3909. } else {
  3910. fmt.Println(dir + "文件夹创建成功!")
  3911. }
  3912. }
  3913. }
  3914. }
  3915. //压缩文件
  3916. func Zip(srcFile string, destZip string) error {
  3917. zipfile, err := os.Create(destZip)
  3918. if err != nil {
  3919. return err
  3920. }
  3921. defer zipfile.Close()
  3922. archive := zip.NewWriter(zipfile)
  3923. defer archive.Close()
  3924. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  3925. if err != nil {
  3926. return err
  3927. }
  3928. header, err := zip.FileInfoHeader(info)
  3929. if err != nil {
  3930. return err
  3931. }
  3932. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  3933. // header.Name = path
  3934. if info.IsDir() {
  3935. header.Name += "/"
  3936. } else {
  3937. header.Method = zip.Deflate
  3938. }
  3939. writer, err := archive.CreateHeader(header)
  3940. if err != nil {
  3941. return err
  3942. }
  3943. if !info.IsDir() {
  3944. file, err := os.Open(path)
  3945. if err != nil {
  3946. return err
  3947. }
  3948. defer file.Close()
  3949. _, err = io.Copy(writer, file)
  3950. }
  3951. return err
  3952. })
  3953. return err
  3954. }
  3955. func ReadFile(filePath string) []byte {
  3956. f, err := os.Open(filePath)
  3957. if err != nil {
  3958. fmt.Println("read file fail", err)
  3959. return nil
  3960. }
  3961. defer f.Close()
  3962. fd, err := ioutil.ReadAll(f)
  3963. if err != nil {
  3964. fmt.Println("read to fd fail", err)
  3965. return nil
  3966. }
  3967. return fd
  3968. }
  3969. func RemoveRepeatedCode(arr []string) (newArr []string) {
  3970. newArr = make([]string, 0)
  3971. for i := 0; i < len(arr); i++ {
  3972. repeat := false
  3973. for j := i + 1; j < len(arr); j++ {
  3974. if arr[i] == arr[j] {
  3975. repeat = true
  3976. break
  3977. }
  3978. }
  3979. if !repeat {
  3980. newArr = append(newArr, arr[i])
  3981. }
  3982. }
  3983. return
  3984. }