his_api_controller.go 147KB

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