his_api_controller.go 144KB

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