his_api_controller.go 148KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279
  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. admin_user_id, _ := c.GetInt64("admin_user_id")
  2406. timeLayout := "2006-01-02"
  2407. loc, _ := time.LoadLocation("Local")
  2408. adminUser := c.GetAdminUserInfo()
  2409. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2410. fmt.Println(err)
  2411. if err != nil {
  2412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2413. return
  2414. }
  2415. recordDateTime := theTime.Unix()
  2416. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2417. //patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2418. //order, _ := service.GetHisOrderByID(order_id)
  2419. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2420. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2421. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2422. if config.IsOpen == 1 { //对接了医保,走医保流程
  2423. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  2424. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + roles.UserName + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2425. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2426. resp3, requestErr3 := http.Get(api3)
  2427. if requestErr3 != nil {
  2428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2429. return
  2430. }
  2431. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  2432. if ioErr3 != nil {
  2433. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  2434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2435. return
  2436. }
  2437. var respJSON3 map[string]interface{}
  2438. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  2439. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2441. return
  2442. }
  2443. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2444. service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  2445. if err == nil {
  2446. c.ServeSuccessJSON(map[string]interface{}{
  2447. "msg": "退号成功",
  2448. })
  2449. } else {
  2450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2451. return
  2452. }
  2453. } else {
  2454. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2455. //if err == nil {
  2456. // c.ServeSuccessJSON(map[string]interface{}{
  2457. // "msg": "退费成功",
  2458. // })
  2459. //} else {
  2460. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2461. // return
  2462. //}
  2463. }
  2464. }
  2465. func (c *HisApiController) RefundDetail() {
  2466. order_id, _ := c.GetInt64("order_id")
  2467. number := c.GetString("number")
  2468. record_time := c.GetString("record_time")
  2469. patient_id, _ := c.GetInt64("patient_id")
  2470. timeLayout := "2006-01-02"
  2471. loc, _ := time.LoadLocation("Local")
  2472. adminUser := c.GetAdminUserInfo()
  2473. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2474. fmt.Println(err)
  2475. if err != nil {
  2476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2477. return
  2478. }
  2479. recordDateTime := theTime.Unix()
  2480. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2481. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2482. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2483. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2484. var order models.HisOrder
  2485. order, _ = service.GetHisOrderByID(order_id)
  2486. if order.ID == 0 {
  2487. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  2488. }
  2489. if config.IsOpen == 1 { //对接了医保,走医保流程
  2490. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  2491. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2492. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2493. resp2, requestErr2 := http.Get(api2)
  2494. if requestErr2 != nil {
  2495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2496. return
  2497. }
  2498. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  2499. if ioErr2 != nil {
  2500. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  2501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2502. return
  2503. }
  2504. var respJSON2 map[string]interface{}
  2505. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  2506. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2508. return
  2509. }
  2510. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2511. if err == nil {
  2512. c.ServeSuccessJSON(map[string]interface{}{
  2513. "msg": "退费成功",
  2514. })
  2515. } else {
  2516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2517. return
  2518. }
  2519. } else {
  2520. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2521. if err == nil {
  2522. c.ServeSuccessJSON(map[string]interface{}{
  2523. "msg": "退费成功",
  2524. })
  2525. } else {
  2526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2527. return
  2528. }
  2529. }
  2530. }
  2531. //对账
  2532. func (c *HisApiController) GetCheckAccount() {
  2533. start_time := c.GetString("start_time")
  2534. end_time := c.GetString("end_time")
  2535. insutype := c.GetString("insutype")
  2536. clr_type := c.GetString("clr_type")
  2537. admin_user_id, _ := c.GetInt64("admin_user_id")
  2538. adminUser := c.GetAdminUserInfo()
  2539. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2540. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2541. timeLayout := "2006-01-02"
  2542. loc, _ := time.LoadLocation("Local")
  2543. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2544. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2545. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  2546. orders_two, _ := service.GetOrderByTimeThree(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  2547. fixmedins_setl_cnt := int64(len(orders_two))
  2548. //撤销的算2条数据为一笔
  2549. for _, item := range orders_two {
  2550. if item.OrderStatus == 3 {
  2551. fixmedins_setl_cnt = fixmedins_setl_cnt + 1
  2552. }
  2553. }
  2554. var medfee_sumamt float64
  2555. var acct_pay float64
  2556. var fund_pay_sumamt float64
  2557. for _, item := range orders {
  2558. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  2559. acct_pay = acct_pay + item.AcctPay
  2560. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  2561. }
  2562. var user_name string
  2563. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2564. if role.ID == 0 {
  2565. user_name = "xxx"
  2566. } else {
  2567. user_name = role.UserName
  2568. }
  2569. if config.IsOpen == 1 {
  2570. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  2571. "insutype=" + insutype +
  2572. "&clr_type=" + clr_type +
  2573. "&setl_optins=" + "定点医保中心" +
  2574. "&stmt_begndate=" + start_time +
  2575. "&stm_enddate=" + end_time +
  2576. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  2577. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  2578. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  2579. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  2580. "&fixmedins_code=" + miConfig.Code +
  2581. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2582. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2583. "&secret_key=" + miConfig.SecretKey +
  2584. "&org_name=" + miConfig.OrgName +
  2585. "&doctor=" + user_name
  2586. fmt.Println(api)
  2587. resp, requestErr := http.Get(api)
  2588. if requestErr != nil {
  2589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2590. return
  2591. }
  2592. body, ioErr := ioutil.ReadAll(resp.Body)
  2593. fmt.Println(body)
  2594. if ioErr != nil {
  2595. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2597. return
  2598. }
  2599. var respJSON map[string]interface{}
  2600. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2601. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2603. return
  2604. }
  2605. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2606. userJSONBytes, _ := json.Marshal(respJSON)
  2607. var res ResultEight
  2608. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2609. utils.ErrorLog("解析失败:%v", err)
  2610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2611. return
  2612. }
  2613. if res.Infcode == 0 {
  2614. if res.Output.Stmtinfo.StmtRslt == "0" {
  2615. micc := &models.MedicalInsuranceCostCompare{
  2616. StartTime: startime.Unix(),
  2617. EndTime: endtime.Unix(),
  2618. Insutype: insutype,
  2619. CheckType: 1,
  2620. Num: fixmedins_setl_cnt,
  2621. Mtime: time.Now().Unix(),
  2622. Status: 1,
  2623. UserOrgId: adminUser.CurrentOrgId,
  2624. CostTotal: medfee_sumamt,
  2625. FuncTotal: fund_pay_sumamt,
  2626. PsnPay: acct_pay,
  2627. Creator: admin_user_id,
  2628. Ctime: time.Now().Unix(),
  2629. }
  2630. err := service.CreateMedicalInsuranceCostCompareRecord(micc)
  2631. if err == nil {
  2632. c.ServeSuccessJSON(map[string]interface{}{
  2633. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  2634. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  2635. })
  2636. } else {
  2637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2638. }
  2639. } else {
  2640. c.ServeSuccessJSON(map[string]interface{}{
  2641. "code": -10,
  2642. "msg": res.ErrMsg,
  2643. })
  2644. }
  2645. } else {
  2646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2647. }
  2648. }
  2649. }
  2650. func (c *HisApiController) Check310() {
  2651. adminUser := c.GetAdminUserInfo()
  2652. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2653. var user_name string
  2654. user_name = "xxx"
  2655. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  2656. "insutype=" + "310" +
  2657. "&clr_type=" + "11" +
  2658. "&setl_optins=" + "定点医保中心" +
  2659. "&stmt_begndate=" + "2021-03-01" +
  2660. "&stm_enddate=" + "2021-03-31" +
  2661. "&medfee_sumamt=" + "11521" +
  2662. "&fund_pay_sumamt=" + "10166.66" +
  2663. "&acct_pay=" + "0" +
  2664. "&fixmedins_setl_cnt=" + "7" +
  2665. "&fixmedins_code=" + miConfig.Code +
  2666. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2667. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2668. "&secret_key=" + miConfig.SecretKey +
  2669. "&org_name=" + miConfig.OrgName +
  2670. "&doctor=" + user_name
  2671. fmt.Println(api)
  2672. resp, requestErr := http.Get(api)
  2673. if requestErr != nil {
  2674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2675. return
  2676. }
  2677. body, ioErr := ioutil.ReadAll(resp.Body)
  2678. fmt.Println(body)
  2679. if ioErr != nil {
  2680. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2682. return
  2683. }
  2684. var respJSON map[string]interface{}
  2685. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2686. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2688. return
  2689. }
  2690. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2691. userJSONBytes, _ := json.Marshal(respJSON)
  2692. var res ResultEight
  2693. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2694. utils.ErrorLog("解析失败:%v", err)
  2695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2696. return
  2697. }
  2698. }
  2699. func (c *HisApiController) Check390() {
  2700. adminUser := c.GetAdminUserInfo()
  2701. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2702. var user_name string
  2703. user_name = "张俊杰"
  2704. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  2705. "insutype=" + "390" +
  2706. "&clr_type=" + "11" +
  2707. "&setl_optins=" + "定点医保中心" +
  2708. "&stmt_begndate=" + "2021-03-01" +
  2709. "&stm_enddate=" + "2021-03-31" +
  2710. "&medfee_sumamt=" + "209318.43" +
  2711. "&fund_pay_sumamt=" + "188029.12" +
  2712. "&acct_pay=" + "0" +
  2713. "&fixmedins_setl_cnt=" + "48" +
  2714. "&fixmedins_code=" + miConfig.Code +
  2715. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2716. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2717. "&secret_key=" + miConfig.SecretKey +
  2718. "&org_name=" + miConfig.OrgName +
  2719. "&doctor=" + user_name
  2720. fmt.Println(api)
  2721. resp, requestErr := http.Get(api)
  2722. if requestErr != nil {
  2723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2724. return
  2725. }
  2726. body, ioErr := ioutil.ReadAll(resp.Body)
  2727. fmt.Println(body)
  2728. if ioErr != nil {
  2729. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2731. return
  2732. }
  2733. var respJSON map[string]interface{}
  2734. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2735. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2737. return
  2738. }
  2739. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2740. userJSONBytes, _ := json.Marshal(respJSON)
  2741. var res ResultEight
  2742. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2743. utils.ErrorLog("解析失败:%v", err)
  2744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2745. return
  2746. }
  2747. }
  2748. //对账明细
  2749. func (c *HisApiController) GetCheckDetailAccount() {
  2750. start_time := c.GetString("start_time")
  2751. end_time := c.GetString("end_time")
  2752. admin_user_id, _ := c.GetInt64("admin_user_id")
  2753. adminUser := c.GetAdminUserInfo()
  2754. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2755. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2756. timeLayout := "2006-01-02"
  2757. loc, _ := time.LoadLocation("Local")
  2758. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2759. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2760. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  2761. Mkdir(miConfig.OrgName)
  2762. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  2763. file_name := file + ".txt"
  2764. zip_name := file + ".zip"
  2765. zip_path := miConfig.OrgName + "/" + zip_name
  2766. file_path := miConfig.OrgName + "/" + file_name
  2767. decimal.DivisionPrecision = 2
  2768. var medfee_sumamt float64
  2769. var psn_cash_pay float64
  2770. var fund_pay_sumamt float64
  2771. fixmedins_setl_cnt := int64(len(orders))
  2772. for _, item := range orders {
  2773. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  2774. psn_cash_pay = psn_cash_pay + item.PsnCashPay
  2775. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  2776. }
  2777. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  2778. defer f.Close()
  2779. if err != nil {
  2780. fmt.Println(err.Error())
  2781. } else {
  2782. for _, item := range orders {
  2783. var refd_setl_flag string
  2784. if item.OrderStatus == 2 {
  2785. refd_setl_flag = "0"
  2786. }
  2787. if item.OrderStatus == 3 {
  2788. refd_setl_flag = "1"
  2789. }
  2790. var str string
  2791. str = item.SetlId + " " +
  2792. item.MdtrtId + " " +
  2793. item.PsnNo + " " +
  2794. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  2795. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  2796. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\n"
  2797. _, err = f.Write([]byte(str))
  2798. }
  2799. }
  2800. Zip(file_path, zip_path)
  2801. fmt.Println(ReadFile(zip_path))
  2802. fmt.Println(string(ReadFile(zip_path)))
  2803. if config.IsOpen == 1 {
  2804. var user_name string
  2805. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2806. if role.ID == 0 {
  2807. user_name = "管理员"
  2808. } else {
  2809. user_name = role.UserName
  2810. }
  2811. baseParams := models.BaseParams{
  2812. SecretKey: miConfig.SecretKey,
  2813. FixmedinsCode: miConfig.Code,
  2814. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2815. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2816. OrgName: miConfig.OrgName,
  2817. Doctor: user_name,
  2818. }
  2819. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  2820. var dat map[string]interface{}
  2821. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2822. fmt.Println(dat)
  2823. } else {
  2824. fmt.Println(err)
  2825. }
  2826. userJSONBytes, _ := json.Marshal(dat)
  2827. var res ResultNine
  2828. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2829. utils.ErrorLog("解析失败:%v", err)
  2830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2831. return
  2832. }
  2833. if res.Infcode == 0 {
  2834. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  2835. "file_qury_no=" + res.Output.FileQuryNo +
  2836. "&setl_optins=" + "定点医保中心" +
  2837. "&stmt_begndate=" + start_time +
  2838. "&stm_enddate=" + end_time +
  2839. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  2840. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  2841. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  2842. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  2843. "&fixmedins_code=" + miConfig.Code +
  2844. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2845. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2846. "&secret_key=" + miConfig.SecretKey +
  2847. "&org_name=" + miConfig.OrgName +
  2848. "&doctor=" + user_name
  2849. resp, requestErr := http.Get(api)
  2850. if requestErr != nil {
  2851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2852. return
  2853. }
  2854. body, ioErr := ioutil.ReadAll(resp.Body)
  2855. if ioErr != nil {
  2856. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2858. return
  2859. }
  2860. var respJSON map[string]interface{}
  2861. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2862. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2864. return
  2865. }
  2866. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2867. userJSONBytes, _ := json.Marshal(respJSON)
  2868. var res ResultTen
  2869. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2870. utils.ErrorLog("解析失败:%v", err)
  2871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2872. return
  2873. }
  2874. if res.Infcode == 0 {
  2875. service.Gdyb9102(baseParams, zip_name, res.Output.FileQuryNo)
  2876. micc := &models.MedicalInsuranceCostCompare{
  2877. StartTime: startime.Unix(),
  2878. EndTime: endtime.Unix(),
  2879. Insutype: "0",
  2880. CheckType: 2,
  2881. Num: fixmedins_setl_cnt,
  2882. Mtime: time.Now().Unix(),
  2883. Status: 1,
  2884. UserOrgId: adminUser.CurrentOrgId,
  2885. CostTotal: medfee_sumamt,
  2886. FuncTotal: fund_pay_sumamt,
  2887. PsnPay: psn_cash_pay,
  2888. Creator: admin_user_id,
  2889. Ctime: time.Now().Unix(),
  2890. }
  2891. service.CreateMedicalInsuranceCostCompareRecord(micc)
  2892. c.ServeSuccessJSON(map[string]interface{}{
  2893. "msg": "明细对账成功",
  2894. })
  2895. }
  2896. } else {
  2897. }
  2898. }
  2899. }
  2900. func (c *HisApiController) GetSettleAccounts() {
  2901. //id, _ := c.GetInt64("id")
  2902. //record_time := c.GetString("record_time")
  2903. order_id, _ := c.GetInt64("order_id")
  2904. admin_user_id, _ := c.GetInt64("admin_user_id")
  2905. //timeLayout := "2006-01-02"
  2906. //loc, _ := time.LoadLocation("Local")
  2907. //
  2908. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2909. //if err != nil {
  2910. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2911. // return
  2912. //}
  2913. //recordDateTime := theTime.Unix()
  2914. adminUser := c.GetAdminUserInfo()
  2915. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2916. order, _ := service.GetHisOrderByID(order_id)
  2917. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  2918. var bedCostTotal float64 = 0 //床位总费
  2919. var bedCostSelfTotal float64 = 0 //床位自费
  2920. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  2921. var operationCostTotal float64 = 0 //手术费
  2922. var operationCostSelfTotal float64 = 0 //手术费
  2923. var operationCostPartSelfTotal float64 = 0 //手术费
  2924. var otherCostTotal float64 = 0 //其他费用
  2925. var otherCostSelfTotal float64 = 0 //其他费用
  2926. var otherCostPartSelfTotal float64 = 0 //其他费用
  2927. var materialCostTotal float64 = 0 //材料费
  2928. var materialCostSelfTotal float64 = 0 //材料费
  2929. var materialCostPartSelfTotal float64 = 0 //材料费
  2930. var westernMedicineCostTotal float64 = 0 //西药费
  2931. var westernMedicineCostSelfTotal float64 = 0 //西药费
  2932. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  2933. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  2934. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  2935. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  2936. var checkCostTotal float64 = 0 //检查费
  2937. var checkCostSelfTotal float64 = 0 //检查费
  2938. var checkCostPartSelfTotal float64 = 0 //检查费
  2939. var laboratoryCostTotal float64 = 0 //化验费
  2940. var laboratoryCostSelfTotal float64 = 0 //化验费
  2941. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  2942. var treatCostTotal float64 = 0 //治疗费用
  2943. var treatCostSelfTotal float64 = 0 //治疗费用
  2944. var treatCostPartSelfTotal float64 = 0 //治疗费用
  2945. decimal.DivisionPrecision = 2
  2946. for _, item := range orderInfos {
  2947. if item.MedChrgitmType == "01" { //床位费
  2948. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2949. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2950. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2951. }
  2952. if item.MedChrgitmType == "03" { //检查费
  2953. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2954. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2955. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2956. }
  2957. if item.MedChrgitmType == "04" { //化验费
  2958. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2959. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2960. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2961. }
  2962. if item.MedChrgitmType == "05" { //治疗费
  2963. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2964. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2965. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2966. }
  2967. if item.MedChrgitmType == "06" { //手术费
  2968. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2969. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2970. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2971. }
  2972. if item.MedChrgitmType == "08" { //材料费
  2973. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2974. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2975. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2976. }
  2977. if item.MedChrgitmType == "09" { //西药费
  2978. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2979. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2980. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2981. }
  2982. if item.MedChrgitmType == "11" { //中成费
  2983. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2984. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2985. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2986. }
  2987. if item.MedChrgitmType == "14" { //其他费
  2988. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2989. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2990. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2991. }
  2992. }
  2993. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2994. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2995. var user_name string
  2996. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2997. if role.ID == 0 {
  2998. user_name = "管理员"
  2999. } else {
  3000. user_name = role.UserName
  3001. }
  3002. baseParams := models.BaseParams{
  3003. SecretKey: miConfig.SecretKey,
  3004. FixmedinsCode: miConfig.Code,
  3005. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3006. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3007. OrgName: miConfig.OrgName,
  3008. Doctor: user_name,
  3009. }
  3010. businessParams := models.BusinessParams{
  3011. PsnNo: order.PsnNo,
  3012. MdtrtId: order.MdtrtId,
  3013. SetlId: order.SetlId,
  3014. }
  3015. if config.IsOpen == 1 {
  3016. result := service.Gdyb5203(baseParams, businessParams)
  3017. var dat map[string]interface{}
  3018. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3019. fmt.Println(dat)
  3020. } else {
  3021. fmt.Println(err)
  3022. }
  3023. userJSONBytes, _ := json.Marshal(dat)
  3024. var res ResultEleven
  3025. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3026. utils.ErrorLog("解析失败:%v", err)
  3027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3028. return
  3029. }
  3030. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3031. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  3032. if res.Infcode == 0 {
  3033. c.ServeSuccessJSON(map[string]interface{}{
  3034. "charge_admin": charge_admin,
  3035. "printor_admin": printor_admin,
  3036. "info": res.Output.Setlinfo,
  3037. "bedCostTotal": bedCostTotal,
  3038. "bedCostSelfTotal": bedCostSelfTotal,
  3039. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  3040. "operationCostTotal": operationCostTotal,
  3041. "operationCostSelfTotal": operationCostSelfTotal,
  3042. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  3043. "otherCostTotal": otherCostTotal,
  3044. "otherCostSelfTotal": otherCostSelfTotal,
  3045. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  3046. "materialCostTotal": materialCostTotal,
  3047. "materialCostSelfTotal": materialCostSelfTotal,
  3048. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  3049. "westernMedicineCostTotal": westernMedicineCostTotal,
  3050. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  3051. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  3052. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  3053. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  3054. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  3055. "checkCostTotal": checkCostTotal,
  3056. "checkCostSelfTotal": checkCostSelfTotal,
  3057. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  3058. "laboratoryCostTotal": laboratoryCostTotal,
  3059. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  3060. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  3061. "treatCostTotal": treatCostTotal,
  3062. "treatCostSelfTotal": treatCostSelfTotal,
  3063. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  3064. })
  3065. }
  3066. }
  3067. }
  3068. func (c *HisApiController) CheckTreatment() {
  3069. patient_id, _ := c.GetInt64("patient_id", 0)
  3070. record_time := c.GetString("record_time")
  3071. insutype := c.GetString("insutype")
  3072. timeLayout := "2006-01-02"
  3073. loc, _ := time.LoadLocation("Local")
  3074. adminUser := c.GetAdminUserInfo()
  3075. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3076. fmt.Println(err)
  3077. if err != nil {
  3078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3079. return
  3080. }
  3081. recordDateTime := theTime.Unix()
  3082. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3083. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3084. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3085. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3086. var user_name string
  3087. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  3088. if role.ID == 0 {
  3089. user_name = "xxx"
  3090. } else {
  3091. user_name = role.UserName
  3092. }
  3093. baseParams := models.BaseParams{
  3094. SecretKey: miConfig.SecretKey,
  3095. FixmedinsCode: miConfig.Code,
  3096. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3097. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3098. OrgName: miConfig.OrgName,
  3099. Doctor: user_name,
  3100. }
  3101. if config.IsOpen == 1 {
  3102. result := service.Gdyb2001(baseParams, his.PsnNo, insutype, strconv.FormatInt(patientPrescription.RegisterType, 10))
  3103. var dat map[string]interface{}
  3104. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3105. fmt.Println(dat)
  3106. } else {
  3107. fmt.Println(err)
  3108. }
  3109. }
  3110. }
  3111. func (c *HisApiController) PutRecord() {
  3112. id, _ := c.GetInt64("id")
  3113. record_time := c.GetString("record_time")
  3114. timeLayout := "2006-01-02"
  3115. loc, _ := time.LoadLocation("Local")
  3116. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3117. if err != nil {
  3118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3119. return
  3120. }
  3121. recordDateTime := theTime.Unix()
  3122. adminInfo := c.GetAdminUserInfo()
  3123. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  3124. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3125. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  3126. fmt.Println(miConfig.SecretKey)
  3127. if patient == nil {
  3128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3129. return
  3130. }
  3131. if len(patient.IdCardNo) == 0 {
  3132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  3133. return
  3134. }
  3135. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  3136. if config.IsOpen == 1 {
  3137. 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
  3138. resp, requestErr := http.Get(api)
  3139. if requestErr != nil {
  3140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3141. return
  3142. }
  3143. defer resp.Body.Close()
  3144. body, ioErr := ioutil.ReadAll(resp.Body)
  3145. if ioErr != nil {
  3146. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3148. return
  3149. }
  3150. var respJSON map[string]interface{}
  3151. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3152. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3154. return
  3155. }
  3156. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3157. userJSONBytes, _ := json.Marshal(userJSON)
  3158. var res ResultTwo
  3159. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3160. utils.ErrorLog("解析失败:%v", err)
  3161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3162. return
  3163. }
  3164. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  3165. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  3166. infoStr := string(Iinfos)
  3167. idetinfoStr := string(Idetinfos)
  3168. if res.Infcode == 0 {
  3169. his := models.VMHisPatient{
  3170. Status: 1,
  3171. Ctime: time.Now().Unix(),
  3172. Mtime: time.Now().Unix(),
  3173. PsnNo: res.Output.Baseinfo.PsnNo,
  3174. PsnCertType: res.Output.Baseinfo.PsnCertType,
  3175. Certno: res.Output.Baseinfo.Certno,
  3176. PsnName: res.Output.Baseinfo.PsnName,
  3177. Gend: res.Output.Baseinfo.Gend,
  3178. Naty: res.Output.Baseinfo.Naty,
  3179. Brdy: res.Output.Baseinfo.Brdy,
  3180. Age: res.Output.Baseinfo.Age,
  3181. Iinfo: infoStr,
  3182. Idetinfo: idetinfoStr,
  3183. PatientId: patient.ID,
  3184. RecordDate: theTime.Unix(),
  3185. UserOrgId: adminInfo.CurrentOrgId,
  3186. AdminUserId: adminInfo.AdminUser.Id,
  3187. IsReturn: 1,
  3188. }
  3189. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  3190. 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")
  3191. 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")
  3192. var dat map[string]interface{}
  3193. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3194. fmt.Println(dat)
  3195. } else {
  3196. fmt.Println(err)
  3197. }
  3198. var dat2 map[string]interface{}
  3199. if err := json.Unmarshal([]byte(result2), &dat2); err == nil {
  3200. fmt.Println(dat2)
  3201. } else {
  3202. fmt.Println(err)
  3203. }
  3204. } else {
  3205. adminUser := c.GetAdminUserInfo()
  3206. errlog := &models.HisOrderError{
  3207. UserOrgId: adminUser.CurrentOrgId,
  3208. Ctime: time.Now().Unix(),
  3209. Mtime: time.Now().Unix(),
  3210. ErrMsg: res.ErrMsg,
  3211. Status: 1,
  3212. PatientId: id,
  3213. RecordTime: recordDateTime,
  3214. Stage: 1,
  3215. }
  3216. service.CreateErrMsgLog(errlog)
  3217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  3218. return
  3219. }
  3220. }
  3221. }
  3222. func (c *HisApiController) GetUploadDiag() {
  3223. id, _ := c.GetInt64("id")
  3224. record_time := c.GetString("record_time")
  3225. diagnosis_id, _ := c.GetInt64("diagnosis")
  3226. sick_type, _ := c.GetInt64("sick_type")
  3227. reg_type, _ := c.GetInt64("reg_type")
  3228. timeLayout := "2006-01-02"
  3229. loc, _ := time.LoadLocation("Local")
  3230. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3231. if err != nil {
  3232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3233. return
  3234. }
  3235. var patientPrescription models.HisPrescriptionInfo
  3236. recordDateTime := theTime.Unix()
  3237. adminInfo := c.GetAdminUserInfo()
  3238. patientPrescription, _ = service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3239. if patientPrescription.ID == 0 {
  3240. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3241. }
  3242. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  3243. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  3244. his, _ := service.GetVMHisPatientInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3245. sickConfig, _ := service.FindSickById(sick_type)
  3246. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  3247. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  3248. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  3249. "&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 +
  3250. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  3251. resp2, requestErr2 := http.Get(api2)
  3252. if requestErr2 != nil {
  3253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3254. return
  3255. }
  3256. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  3257. if ioErr2 != nil {
  3258. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  3259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3260. return
  3261. }
  3262. var respJSON2 map[string]interface{}
  3263. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  3264. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3266. return
  3267. }
  3268. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3269. userJSONBytes2, _ := json.Marshal(respJSON2)
  3270. var res2 ResultSix
  3271. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  3272. utils.ErrorLog("解析失败:%v", err)
  3273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3274. return
  3275. }
  3276. if res2.Infcode == -1 {
  3277. adminUser := c.GetAdminUserInfo()
  3278. errlog := &models.HisOrderError{
  3279. UserOrgId: adminUser.CurrentOrgId,
  3280. Ctime: time.Now().Unix(),
  3281. Mtime: time.Now().Unix(),
  3282. ErrMsg: res2.ErrMsg,
  3283. Status: 1,
  3284. PatientId: id,
  3285. RecordTime: recordDateTime,
  3286. Stage: 3,
  3287. }
  3288. service.CreateErrMsgLog(errlog)
  3289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  3290. return
  3291. }
  3292. c.ServeSuccessJSON(map[string]interface{}{
  3293. "msg": "上传成功",
  3294. })
  3295. }
  3296. type QueryResult struct {
  3297. ID int64
  3298. Name string
  3299. Code string
  3300. List_type_code string
  3301. }
  3302. func (c *HisApiController) GetCheckCode() {
  3303. ids_str := c.GetString("ids")
  3304. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  3305. ids_arr := strings.Split(ids_str, ",")
  3306. var queryResult []QueryResult
  3307. ids := make([]int64, 0)
  3308. for _, item := range ids_arr {
  3309. id, _ := strconv.ParseInt(item, 10, 64)
  3310. ids = append(ids, id)
  3311. }
  3312. if record_type == 1 {
  3313. drugs, _ := service.GetBatchDrugList(ids)
  3314. for _, item := range drugs {
  3315. result := QueryResult{
  3316. ID: item.ID,
  3317. Name: item.DrugName,
  3318. Code: item.MedicalInsuranceNumber,
  3319. List_type_code: "101",
  3320. }
  3321. queryResult = append(queryResult, result)
  3322. }
  3323. } else if record_type == 2 {
  3324. goods, _ := service.GetBatchGoodInformationList(ids)
  3325. for _, item := range goods {
  3326. result := QueryResult{
  3327. ID: item.ID,
  3328. Name: item.GoodName,
  3329. Code: item.MedicalInsuranceNumber,
  3330. List_type_code: "301",
  3331. }
  3332. queryResult = append(queryResult, result)
  3333. }
  3334. } else if record_type == 3 {
  3335. projects, _ := service.GetBathchMyPorjecgList(ids)
  3336. for _, item := range projects {
  3337. result := QueryResult{
  3338. ID: item.ID,
  3339. Name: item.ProjectName,
  3340. Code: item.MedicalCode,
  3341. List_type_code: "201",
  3342. }
  3343. queryResult = append(queryResult, result)
  3344. }
  3345. }
  3346. admin_user_id, _ := c.GetInt64("admin_user_id")
  3347. adminUser := c.GetAdminUserInfo()
  3348. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3349. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3350. var user_name string
  3351. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3352. if role.ID == 0 {
  3353. user_name = "xxx"
  3354. } else {
  3355. user_name = role.UserName
  3356. }
  3357. baseParams := &models.BaseParams{
  3358. SecretKey: miConfig.SecretKey,
  3359. FixmedinsCode: miConfig.Code,
  3360. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3361. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3362. OrgName: miConfig.OrgName,
  3363. Doctor: user_name,
  3364. }
  3365. if config.IsOpen == 1 {
  3366. for _, item := range queryResult {
  3367. var result string
  3368. if record_type == 1 {
  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 == 2 {
  3371. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  3372. } else if record_type == 3 {
  3373. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  3374. }
  3375. var dat map[string]interface{}
  3376. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3377. fmt.Println(dat)
  3378. } else {
  3379. fmt.Println(err)
  3380. }
  3381. userJSONBytes, _ := json.Marshal(dat)
  3382. var res ResultSix
  3383. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3384. utils.ErrorLog("解析失败:%v", err)
  3385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3386. return
  3387. }
  3388. if res.Infcode == 0 {
  3389. if record_type == 1 {
  3390. service.UpdateBaseDrugById(item.ID)
  3391. } else if record_type == 2 {
  3392. service.UpdateGoodInformaitonByDetail(item.ID)
  3393. } else if record_type == 3 {
  3394. service.UpdateProjectById(item.ID)
  3395. }
  3396. c.ServeSuccessJSON(map[string]interface{}{
  3397. "failed_code": 0,
  3398. "msg": "目录对照成功",
  3399. })
  3400. } else {
  3401. c.ServeSuccessJSON(map[string]interface{}{
  3402. "failed_code": -10,
  3403. "msg": res.ErrMsg,
  3404. })
  3405. }
  3406. }
  3407. }
  3408. }
  3409. func (c *HisApiController) UnCheckCode() {
  3410. ids_str := c.GetString("ids")
  3411. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  3412. admin_user_id, _ := c.GetInt64("admin_user_id")
  3413. ids_arr := strings.Split(ids_str, ",")
  3414. var queryResult []QueryResult
  3415. ids := make([]int64, 0)
  3416. for _, item := range ids_arr {
  3417. id, _ := strconv.ParseInt(item, 10, 64)
  3418. ids = append(ids, id)
  3419. }
  3420. if record_type == 1 {
  3421. drugs, _ := service.GetBatchDrugList(ids)
  3422. for _, item := range drugs {
  3423. result := QueryResult{
  3424. ID: item.ID,
  3425. Name: item.DrugName,
  3426. Code: item.MedicalInsuranceNumber,
  3427. List_type_code: "101",
  3428. }
  3429. queryResult = append(queryResult, result)
  3430. }
  3431. } else if record_type == 2 {
  3432. goods, _ := service.GetBatchGoodInformationList(ids)
  3433. for _, item := range goods {
  3434. result := QueryResult{
  3435. ID: item.ID,
  3436. Name: item.GoodName,
  3437. Code: item.MedicalInsuranceNumber,
  3438. List_type_code: "301",
  3439. }
  3440. queryResult = append(queryResult, result)
  3441. }
  3442. } else if record_type == 3 {
  3443. projects, _ := service.GetBathchMyPorjecgList(ids)
  3444. for _, item := range projects {
  3445. result := QueryResult{
  3446. ID: item.ID,
  3447. Name: item.ProjectName,
  3448. Code: item.MedicalCode,
  3449. List_type_code: "201",
  3450. }
  3451. queryResult = append(queryResult, result)
  3452. }
  3453. }
  3454. adminUser := c.GetAdminUserInfo()
  3455. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3456. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3457. var user_name string
  3458. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3459. if role.ID == 0 {
  3460. user_name = "xxx"
  3461. } else {
  3462. user_name = role.UserName
  3463. }
  3464. baseParams := &models.BaseParams{
  3465. SecretKey: miConfig.SecretKey,
  3466. FixmedinsCode: miConfig.Code,
  3467. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3468. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3469. OrgName: miConfig.OrgName,
  3470. Doctor: user_name,
  3471. }
  3472. if config.IsOpen == 1 {
  3473. for _, item := range queryResult {
  3474. var result string
  3475. if record_type == 1 {
  3476. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  3477. } else if record_type == 2 {
  3478. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  3479. } else if record_type == 3 {
  3480. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  3481. }
  3482. var dat2 map[string]interface{}
  3483. if err := json.Unmarshal([]byte(result), &dat2); err == nil {
  3484. fmt.Println(dat2)
  3485. } else {
  3486. fmt.Println(err)
  3487. }
  3488. userJSONBytes, _ := json.Marshal(dat2)
  3489. var res ResultSix
  3490. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3491. utils.ErrorLog("解析失败:%v", err)
  3492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3493. return
  3494. }
  3495. if res.Infcode == 0 {
  3496. if record_type == 1 {
  3497. service.UpdateDrugByIdDetail(item.ID)
  3498. } else if record_type == 2 {
  3499. service.UpdateGoodInfoById(item.ID)
  3500. } else if record_type == 3 {
  3501. service.UpdateMyProjectById(item.ID)
  3502. }
  3503. c.ServeSuccessJSON(map[string]interface{}{
  3504. "failed_code": 0,
  3505. "msg": "撤销目录对照成功",
  3506. })
  3507. } else {
  3508. c.ServeSuccessJSON(map[string]interface{}{
  3509. "failed_code": -10,
  3510. "msg": res.ErrMsg,
  3511. })
  3512. }
  3513. }
  3514. }
  3515. }
  3516. func (c *HisApiController) GetPatientInfo() {
  3517. id_card_no := c.GetString("id_card_no")
  3518. admin_user_id, _ := c.GetInt64("admin_user_id")
  3519. patient, _ := service.GetPatientByIDCard(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  3520. if patient.ID == 0 {
  3521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3522. return
  3523. }
  3524. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  3525. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  3526. config, _ := service.GetMedicalInsuranceConfig(c.GetAdminUserInfo().CurrentOrgId)
  3527. if config.IsOpen == 1 {
  3528. result := service.Gdyb1101A(id_card_no, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  3529. var dat map[string]interface{}
  3530. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3531. fmt.Println(dat)
  3532. } else {
  3533. fmt.Println(err)
  3534. }
  3535. userJSONBytes, _ := json.Marshal(dat)
  3536. var res ResultTwo
  3537. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3538. utils.ErrorLog("解析失败:%v", err)
  3539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3540. return
  3541. }
  3542. if res.Infcode == -1 {
  3543. c.ServeSuccessJSON(map[string]interface{}{
  3544. "failed_code": -10,
  3545. "msg": res.ErrMsg,
  3546. })
  3547. } else {
  3548. c.ServeSuccessJSON(map[string]interface{}{
  3549. "failed_code": 0,
  3550. "info": res,
  3551. })
  3552. }
  3553. }
  3554. }
  3555. func (c *HisApiController) PsnPutOnRecord() {
  3556. record_type, _ := c.GetInt64("type")
  3557. patient_id, _ := c.GetInt64("patient_id")
  3558. admin_user_id, _ := c.GetInt64("admin_user_id")
  3559. start_time := c.GetString("start_time")
  3560. end_time := c.GetString("end_time")
  3561. adminUser := c.GetAdminUserInfo()
  3562. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3563. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3564. var patients []*models.Patients
  3565. if record_type == 1 { //全部备案
  3566. patient, _ := service.GetAllPatient(adminUser.CurrentOrgId)
  3567. patients = append(patients, patient...)
  3568. } else { //单个备案
  3569. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  3570. patients = append(patients, patient)
  3571. }
  3572. var user_name string
  3573. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3574. if role.ID == 0 {
  3575. user_name = "xxx"
  3576. } else {
  3577. user_name = role.UserName
  3578. }
  3579. if config.IsOpen == 1 {
  3580. for _, item := range patients {
  3581. 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
  3582. resp, requestErr := http.Get(api)
  3583. if requestErr != nil {
  3584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3585. return
  3586. }
  3587. defer resp.Body.Close()
  3588. body, ioErr := ioutil.ReadAll(resp.Body)
  3589. if ioErr != nil {
  3590. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3592. return
  3593. }
  3594. var respJSON map[string]interface{}
  3595. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3596. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3598. return
  3599. }
  3600. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3601. userJSONBytes, _ := json.Marshal(userJSON)
  3602. var res ResultTwo
  3603. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3604. utils.ErrorLog("解析失败:%v", err)
  3605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3606. return
  3607. }
  3608. if res.Infcode == 0 {
  3609. result := service.Gdyb2505(res.Output.Baseinfo.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, start_time, end_time)
  3610. var dat map[string]interface{}
  3611. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3612. fmt.Println(dat)
  3613. } else {
  3614. fmt.Println(err)
  3615. }
  3616. userJSONBytes, _ := json.Marshal(dat)
  3617. var res2 ResultThirteen
  3618. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  3619. utils.ErrorLog("解析失败:%v", err)
  3620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3621. return
  3622. }
  3623. if res2.Infcode == 0 {
  3624. psnResult := &models.GdybPsnRecord{
  3625. UserOrgId: adminUser.CurrentOrgId,
  3626. PatientId: item.ID,
  3627. PsnNo: res.Output.Baseinfo.PsnNo,
  3628. Ctime: time.Now().Unix(),
  3629. Mtime: time.Now().Unix(),
  3630. Status: 1,
  3631. IsCancel: 1,
  3632. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  3633. }
  3634. service.CreatePsnRecord(psnResult)
  3635. } else {
  3636. c.ServeSuccessJSON(map[string]interface{}{
  3637. "failed_code": -10,
  3638. "msg": res2.ErrMsg,
  3639. })
  3640. return
  3641. }
  3642. }
  3643. }
  3644. }
  3645. }
  3646. func (c *HisApiController) PsnUnPutOnRecord() {
  3647. id, _ := c.GetInt64("id")
  3648. //record_type, _ := c.GetInt64("type")
  3649. admin_user_id, _ := c.GetInt64("admin_user_id")
  3650. adminUser := c.GetAdminUserInfo()
  3651. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3652. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3653. var user_name string
  3654. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3655. if role.ID == 0 {
  3656. user_name = "xxx"
  3657. } else {
  3658. user_name = role.UserName
  3659. }
  3660. psn_record, _ := service.GetPsnRecordById(id)
  3661. if psn_record.ID == 0 {
  3662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  3663. return
  3664. }
  3665. if config.IsOpen == 1 {
  3666. result := service.Gdyb2506(psn_record.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  3667. var dat map[string]interface{}
  3668. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3669. fmt.Println(dat)
  3670. } else {
  3671. fmt.Println(err)
  3672. }
  3673. userJSONBytes, _ := json.Marshal(dat)
  3674. var res ResultFourteen
  3675. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3676. utils.ErrorLog("解析失败:%v", err)
  3677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3678. return
  3679. }
  3680. if res.Infcode == 0 {
  3681. psn_record.IsCancel = 2
  3682. service.CreatePsnRecord(&psn_record)
  3683. } else {
  3684. c.ServeSuccessJSON(map[string]interface{}{
  3685. "failed_code": -10,
  3686. "msg": res.ErrMsg,
  3687. })
  3688. return
  3689. }
  3690. }
  3691. }
  3692. func (c *HisApiController) PsnPutNCDSOnRecord() {
  3693. patient_id, _ := c.GetInt64("patient_id")
  3694. insutype := c.GetString("insutype")
  3695. psn_no := c.GetString("psn_no")
  3696. doctor_id, _ := c.GetInt64("doctor_id")
  3697. sick_id, _ := c.GetInt64("sick_id")
  3698. department_id, _ := c.GetInt64("department_id")
  3699. adminUser := c.GetAdminUserInfo()
  3700. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  3701. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3702. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3703. sick, _ := service.FindSickById(sick_id)
  3704. doctor, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, doctor_id)
  3705. if config.IsOpen == 1 {
  3706. 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)
  3707. var dat map[string]interface{}
  3708. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3709. fmt.Println(dat)
  3710. } else {
  3711. fmt.Println(err)
  3712. }
  3713. userJSONBytes, _ := json.Marshal(dat)
  3714. var res2 ResultThirteen
  3715. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  3716. utils.ErrorLog("解析失败:%v", err)
  3717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3718. return
  3719. }
  3720. if res2.Infcode == 0 {
  3721. psnResult := &models.GdybPsnNcdsRecord{
  3722. UserOrgId: adminUser.CurrentOrgId,
  3723. PatientId: patient.ID,
  3724. PsnNo: psn_no,
  3725. DoctorId: doctor.AdminUserId,
  3726. DepartmentId: department_id,
  3727. SickType: sick_id,
  3728. Insutype: insutype,
  3729. Ctime: time.Now().Unix(),
  3730. Mtime: time.Now().Unix(),
  3731. Status: 1,
  3732. IsCancel: 1,
  3733. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  3734. }
  3735. service.CreatePsnNCDSRecord(psnResult)
  3736. c.ServeSuccessJSON(map[string]interface{}{
  3737. "failed_code": 0,
  3738. "msg": "备案成功",
  3739. "result": psnResult,
  3740. })
  3741. } else {
  3742. c.ServeSuccessJSON(map[string]interface{}{
  3743. "failed_code": -10,
  3744. "msg": res2.ErrMsg,
  3745. })
  3746. return
  3747. }
  3748. }
  3749. }
  3750. func (c *HisApiController) PsnPutUnNCDSOnRecord() {
  3751. id, _ := c.GetInt64("id")
  3752. admin_user_id, _ := c.GetInt64("admin_user_id")
  3753. adminUser := c.GetAdminUserInfo()
  3754. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3755. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3756. var user_name string
  3757. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3758. if role.ID == 0 {
  3759. user_name = "xxx"
  3760. } else {
  3761. user_name = role.UserName
  3762. }
  3763. psn_record, _ := service.GetPsnNCDSRecordById(id)
  3764. if psn_record.ID == 0 {
  3765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  3766. return
  3767. }
  3768. if config.IsOpen == 1 {
  3769. result := service.Gdyb2504(psn_record.PsnNo, miConfig.OrgName, user_name, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  3770. var dat map[string]interface{}
  3771. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3772. fmt.Println(dat)
  3773. } else {
  3774. fmt.Println(err)
  3775. }
  3776. userJSONBytes, _ := json.Marshal(dat)
  3777. var res ResultFourteen
  3778. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3779. utils.ErrorLog("解析失败:%v", err)
  3780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3781. return
  3782. }
  3783. if res.Infcode == 0 {
  3784. psn_record.IsCancel = 2
  3785. service.CreatePsnNCDSRecord(&psn_record)
  3786. c.ServeSuccessJSON(map[string]interface{}{
  3787. "failed_code": 0,
  3788. "msg": "撤销备案成功",
  3789. })
  3790. } else {
  3791. c.ServeSuccessJSON(map[string]interface{}{
  3792. "failed_code": -10,
  3793. "msg": res.ErrMsg,
  3794. })
  3795. return
  3796. }
  3797. }
  3798. }
  3799. func PathExists(path string) (bool, error) {
  3800. _, err := os.Stat(path)
  3801. if err == nil {
  3802. return true, nil
  3803. }
  3804. if os.IsNotExist(err) {
  3805. return false, nil
  3806. }
  3807. return false, err
  3808. }
  3809. //创建文件夹
  3810. func Mkdir(dir string) {
  3811. // 创建文件夹
  3812. exist, err := PathExists(dir)
  3813. if err != nil {
  3814. fmt.Println(err.Error())
  3815. } else {
  3816. if exist {
  3817. fmt.Println(dir + "文件夹已存在!")
  3818. } else {
  3819. // 文件夹名称,权限
  3820. err := os.Mkdir(dir, os.ModePerm)
  3821. if err != nil {
  3822. fmt.Println(dir+"文件夹创建失败:", err.Error())
  3823. } else {
  3824. fmt.Println(dir + "文件夹创建成功!")
  3825. }
  3826. }
  3827. }
  3828. }
  3829. //压缩文件
  3830. func Zip(srcFile string, destZip string) error {
  3831. zipfile, err := os.Create(destZip)
  3832. if err != nil {
  3833. return err
  3834. }
  3835. defer zipfile.Close()
  3836. archive := zip.NewWriter(zipfile)
  3837. defer archive.Close()
  3838. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  3839. if err != nil {
  3840. return err
  3841. }
  3842. header, err := zip.FileInfoHeader(info)
  3843. if err != nil {
  3844. return err
  3845. }
  3846. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  3847. // header.Name = path
  3848. if info.IsDir() {
  3849. header.Name += "/"
  3850. } else {
  3851. header.Method = zip.Deflate
  3852. }
  3853. writer, err := archive.CreateHeader(header)
  3854. if err != nil {
  3855. return err
  3856. }
  3857. if !info.IsDir() {
  3858. file, err := os.Open(path)
  3859. if err != nil {
  3860. return err
  3861. }
  3862. defer file.Close()
  3863. _, err = io.Copy(writer, file)
  3864. }
  3865. return err
  3866. })
  3867. return err
  3868. }
  3869. func ReadFile(filePath string) []byte {
  3870. f, err := os.Open(filePath)
  3871. if err != nil {
  3872. fmt.Println("read file fail", err)
  3873. return nil
  3874. }
  3875. defer f.Close()
  3876. fd, err := ioutil.ReadAll(f)
  3877. if err != nil {
  3878. fmt.Println("read to fd fail", err)
  3879. return nil
  3880. }
  3881. return fd
  3882. }
  3883. func RemoveRepeatedCode(arr []string) (newArr []string) {
  3884. newArr = make([]string, 0)
  3885. for i := 0; i < len(arr); i++ {
  3886. repeat := false
  3887. for j := i + 1; j < len(arr); j++ {
  3888. if arr[i] == arr[j] {
  3889. repeat = true
  3890. break
  3891. }
  3892. }
  3893. if !repeat {
  3894. newArr = append(newArr, arr[i])
  3895. }
  3896. }
  3897. return
  3898. }