zh_his_api_controller.go 151KB

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