his_api_controller.go 148KB

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