his_api_controller.go 148KB

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