his_api_controller.go 152KB

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