his_api_controller.go 147KB

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