his_api_controller.go 150KB

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