his_api_controller.go 151KB

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