zh_his_api_controller.go 122KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596
  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. }
  484. func (c *ZHHisApiController) ReadEleCard() {
  485. id_card_type, _ := c.GetInt64("id_card_type")
  486. admin_user_id, _ := c.GetInt64("admin_user_id")
  487. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  488. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  489. var api string
  490. api = "http://172.16.13.254:9532/" + "nmyb/readcard?" + "fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName +
  491. "&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
  492. fmt.Println(api)
  493. resp, requestErr := http.Get(api)
  494. if requestErr != nil {
  495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  496. return
  497. }
  498. body, ioErr := ioutil.ReadAll(resp.Body)
  499. if ioErr != nil {
  500. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  502. return
  503. }
  504. var respJSON map[string]interface{}
  505. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  506. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  508. return
  509. }
  510. var status string
  511. status = respJSON["data"].(map[string]interface{})["status"].(string)
  512. //card_type := respJSON["data"].(map[string]interface{})["type"].(string)
  513. var token string
  514. var res ResultTwo //1101结果
  515. var res10265 ResultTwo10265 //1101结果
  516. if status == "0" { //读卡成功
  517. token = respJSON["data"].(map[string]interface{})["token"].(string)
  518. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  519. result, _ := json.Marshal(respJSON)
  520. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  521. utils.ErrorLog("解析失败:%v", err)
  522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  523. return
  524. }
  525. res.ErrMsg = res10265.ErrMsg
  526. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  527. res.Infcode = infocode
  528. res.Output = res10265.Output
  529. res.InfRefmsgid = res10265.InfRefmsgid
  530. if res.Infcode == 0 {
  531. c.ServeSuccessJSON(map[string]interface{}{
  532. "number": token,
  533. })
  534. }
  535. } else {
  536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  537. return
  538. }
  539. }
  540. func (c *ZHHisApiController) ClearSettle() {
  541. order_id, _ := c.GetInt64("order_id")
  542. admin_user_id, _ := c.GetInt64("admin_user_id")
  543. adminUser := c.GetAdminUserInfo()
  544. var order models.HisOrder
  545. order, _ = service.GetHisOrderByID(order_id)
  546. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  547. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  548. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  549. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  550. if config.IsOpen == 1 { //对接了医保,走医保流程
  551. var result string
  552. var requestLog string
  553. result, requestLog = service.Gdyb90306(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  554. saveLog(result, requestLog, "90306", "撤销结算清单")
  555. var dat map[string]interface{}
  556. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  557. fmt.Println(dat)
  558. } else {
  559. fmt.Println(err)
  560. }
  561. userJSONBytes, _ := json.Marshal(dat)
  562. var res ResultSix
  563. //var resSixteen ResultSixteen10265
  564. if miConfig.Code == "H15049901371" {
  565. //if err := json.Unmarshal(userJSONBytes, &resSixteen); err != nil {
  566. // utils.ErrorLog("解析失败:%v", err)
  567. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  568. // return
  569. //}
  570. //res.Cainfo = resSixteen.Cainfo
  571. //res.WarnMsg = resSixteen.WarnMsg
  572. //res.Output = resSixteen.Output
  573. //res.ErrMsg = resSixteen.ErrMsg
  574. //res.RespondTime = resSixteen.RespondTime
  575. //Infcode, _ := strconv.ParseInt(resSixteen.Infcode, 10, 64)
  576. //res.Infcode = Infcode
  577. } else {
  578. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  579. utils.ErrorLog("解析失败:%v", err)
  580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  581. return
  582. }
  583. }
  584. if res.Infcode == 0 {
  585. record, _ := service.GetUploadRecord(order_id)
  586. record.Status = 0
  587. service.UpdateRecord(&record)
  588. c.ServeSuccessJSON(map[string]interface{}{
  589. "msg": "撤销成功",
  590. })
  591. } else {
  592. c.ServeSuccessJSON(map[string]interface{}{
  593. "code": -10,
  594. "msg": res.ErrMsg,
  595. })
  596. }
  597. }
  598. }
  599. func (c *ZHHisApiController) GetZHPatientInfo() {
  600. id_card_no := c.GetString("id_card_no")
  601. admin_user_id, _ := c.GetInt64("admin_user_id")
  602. patient, _ := service.GetPatientByIDCard(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  603. if patient.ID == 0 {
  604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  605. return
  606. }
  607. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  608. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  609. config, _ := service.GetMedicalInsuranceConfig(c.GetAdminUserInfo().CurrentOrgId)
  610. if config.IsOpen == 1 {
  611. var result string
  612. var request_log string
  613. var result_log string
  614. if miConfig.MdtrtareaAdmvs == "150499" {
  615. //请求内网数据
  616. api := "http://172.16.13.254:9532/" + "nmyb/1101?cert_no=" + patient.IdCardNo +
  617. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  618. "&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
  619. resp, requestErr := http.Get(api)
  620. if requestErr != nil {
  621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  622. return
  623. }
  624. body, ioErr := ioutil.ReadAll(resp.Body)
  625. if ioErr != nil {
  626. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  628. return
  629. }
  630. var respJSON map[string]interface{}
  631. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  632. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  634. return
  635. }
  636. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  637. result_byte, _ := json.Marshal(respJSON)
  638. result = string(result_byte)
  639. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  640. } else {
  641. 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)
  642. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  643. }
  644. //result := service.Gdyb1101A(id_card_no, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, patient.Name)
  645. var dat map[string]interface{}
  646. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  647. fmt.Println(dat)
  648. } else {
  649. fmt.Println(err)
  650. }
  651. userJSONBytes, _ := json.Marshal(dat)
  652. var res ResultTwo
  653. var resTwo10265 ResultTwo10265
  654. if miConfig.Code == "H15049901371" {
  655. if err := json.Unmarshal(userJSONBytes, &resTwo10265); err != nil {
  656. utils.ErrorLog("解析失败:%v", err)
  657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  658. return
  659. }
  660. Infcode, _ := strconv.ParseInt(resTwo10265.Infcode, 10, 64)
  661. res.Infcode = Infcode
  662. res.ErrMsg = resTwo10265.ErrMsg
  663. res.Output = resTwo10265.Output
  664. res.InfRefmsgid = resTwo10265.InfRefmsgid
  665. res.RespondTime = resTwo10265.RespondTime
  666. res.WarnInfo = resTwo10265.WarnInfo
  667. } else {
  668. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  669. utils.ErrorLog("解析失败:%v", err)
  670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  671. return
  672. }
  673. }
  674. var insutypes []string
  675. var insutype string
  676. var is390 int = 0
  677. var is310 int = 0
  678. for _, item := range res.Output.Iinfo {
  679. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  680. insutypes = append(insutypes, item.Insutype)
  681. }
  682. }
  683. if len(insutypes) == 1 {
  684. insutype = insutypes[0]
  685. } else {
  686. for _, i := range insutypes {
  687. if i == "390" {
  688. is390 = 1
  689. }
  690. if i == "310" {
  691. is310 = 1
  692. }
  693. }
  694. }
  695. if is390 == 1 {
  696. insutype = "390"
  697. }
  698. if is310 == 1 {
  699. insutype = "310"
  700. }
  701. if len(insutypes) == 0 {
  702. insutype = "310"
  703. }
  704. if res.Infcode != 0 {
  705. c.ServeSuccessJSON(map[string]interface{}{
  706. "failed_code": -10,
  707. "msg": res.ErrMsg,
  708. })
  709. } else {
  710. c.ServeSuccessJSON(map[string]interface{}{
  711. "failed_code": 0,
  712. "info": res,
  713. "insutype": insutype,
  714. })
  715. }
  716. }
  717. }
  718. func (c *ZHHisApiController) GetZHInHospitalCheck() {
  719. id, _ := c.GetInt64("id")
  720. record_time := c.GetString("record_time")
  721. name := c.GetString("name")
  722. phone := c.GetString("phone")
  723. id_card_type, _ := c.GetInt64("id_card_type")
  724. certificates, _ := c.GetInt64("certificates")
  725. id_card_no := c.GetString("id_card_no")
  726. doctor, _ := c.GetInt64("doctor")
  727. admin_user_id, _ := c.GetInt64("admin_user_id")
  728. department, _ := c.GetInt64("department")
  729. adm_bed, _ := c.GetInt64("adm_bed")
  730. diagnosis_ids := c.GetString("diagnosis")
  731. sick_type, _ := c.GetInt64("sick_type")
  732. start_time := c.GetString("start_time")
  733. insuplc_admdvs := c.GetString("insuplc_admdvs")
  734. balance_accounts_type, _ := c.GetInt64("balance_accounts_type")
  735. social_type, _ := c.GetInt64("social_type")
  736. psn_type, _ := c.GetInt64("psn_type")
  737. //reg_type, _ := c.GetInt64("p_type")
  738. med_type, _ := c.GetInt64("med_type")
  739. diagnosis_ids_arr := strings.Split(diagnosis_ids, "-")
  740. timeLayout := "2006-01-02"
  741. loc, _ := time.LoadLocation("Local")
  742. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  743. if err != nil {
  744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  745. return
  746. }
  747. recordDateTime := theTime.Unix()
  748. adminInfo := c.GetAdminUserInfo()
  749. record, _ := service.GetLastHospitalRecord(id, adminInfo.CurrentOrgId)
  750. if record.ID != 0 {
  751. if record.InHospitalStatus == 1 && record.OutHospitalStatus != 1 {
  752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalExistDataException)
  753. return
  754. }
  755. }
  756. var patient service.Patients
  757. if id == 0 {
  758. patient, _ = service.GetPatientByIDCard(id_card_no, adminInfo.CurrentOrgId)
  759. } else {
  760. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  761. }
  762. diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  763. sickConfig, _ := service.FindSickById(sick_type)
  764. departmentInfo, _ := service.GetDepartMentDetail(department)
  765. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  766. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  767. var result string
  768. var request_log string
  769. var result_log string
  770. var res2 ResultTwo
  771. var resTwo10265 ResultTwo10265
  772. psn_info, _ := service.GetPsnByPatientId(patient.ID)
  773. if miConfig.MdtrtareaAdmvs == "150499" {
  774. if id_card_type == 2 {
  775. mdtrt_cert_no := ""
  776. card_sn := ""
  777. if record.IdCardType == 1 {
  778. bas := strings.Split(psn_info.CardInfo, "|")
  779. cardNumber := bas[2]
  780. mdtrt_cert_no = cardNumber
  781. card_sn = bas[3]
  782. } else {
  783. mdtrt_cert_no = id_card_no
  784. }
  785. //请求内网数据
  786. api := "http://172.16.13.254:9532/" + "nmyb/1101?cert_no=" + mdtrt_cert_no +
  787. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  788. "&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
  789. resp, requestErr := http.Get(api)
  790. if requestErr != nil {
  791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  792. return
  793. }
  794. body, ioErr := ioutil.ReadAll(resp.Body)
  795. if ioErr != nil {
  796. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  798. return
  799. }
  800. var respJSON map[string]interface{}
  801. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  802. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  804. return
  805. }
  806. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  807. result_byte, _ := json.Marshal(respJSON)
  808. result = string(result_byte)
  809. var dat map[string]interface{}
  810. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  811. fmt.Println(dat)
  812. } else {
  813. fmt.Println(err)
  814. }
  815. userJSONBytes, _ := json.Marshal(dat)
  816. if err := json.Unmarshal(userJSONBytes, &resTwo10265); err != nil {
  817. utils.ErrorLog("解析失败:%v", err)
  818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  819. return
  820. }
  821. Infcode, _ := strconv.ParseInt(resTwo10265.Infcode, 10, 64)
  822. res2.Infcode = Infcode
  823. res2.ErrMsg = resTwo10265.ErrMsg
  824. res2.Output = resTwo10265.Output
  825. res2.InfRefmsgid = resTwo10265.InfRefmsgid
  826. res2.RespondTime = resTwo10265.RespondTime
  827. res2.WarnInfo = resTwo10265.WarnInfo
  828. } else {
  829. res2.Infcode = 0
  830. res2.Output.Baseinfo.PsnNo = psn_info.PsnNo
  831. res2.Output.Baseinfo.Certno = patient.IdCardNo
  832. }
  833. } else {
  834. 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)
  835. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  836. }
  837. doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor)
  838. deviceNumber, _ := service.GetDeviceNumberByID(adm_bed, adminInfo.CurrentOrgId)
  839. if miConfig.MdtrtareaAdmvs != "150499" {
  840. var dat map[string]interface{}
  841. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  842. fmt.Println(dat)
  843. } else {
  844. fmt.Println(err)
  845. }
  846. userJSONBytes, _ := json.Marshal(dat)
  847. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  848. utils.ErrorLog("解析失败:%v", err)
  849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  850. return
  851. }
  852. }
  853. var infoStr string
  854. if miConfig.MdtrtareaAdmvs == "150499" {
  855. if id_card_type == 2 {
  856. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  857. infoStr = string(Iinfos)
  858. } else {
  859. infoStr = psn_info.Insuinfo
  860. }
  861. } else {
  862. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  863. infoStr = string(Iinfos)
  864. }
  865. var rf []*ResultFive
  866. json.Unmarshal([]byte(infoStr), &rf)
  867. var insutypes []*ResultFive
  868. var insutype string
  869. var is390 int = 0
  870. var is310 int = 0
  871. for _, item := range rf {
  872. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  873. insutypes = append(insutypes, item)
  874. }
  875. }
  876. if len(insutypes) == 1 {
  877. insutype = insutypes[0].Insutype
  878. //insuplc_admdvs = insutypes[0].InsuplcAdmdvs
  879. } else {
  880. for _, i := range insutypes {
  881. if i.Insutype == "390" {
  882. is390 = 1
  883. }
  884. if i.Insutype == "310" {
  885. is310 = 1
  886. }
  887. }
  888. }
  889. if is390 == 1 {
  890. insutype = "390"
  891. }
  892. if is310 == 1 {
  893. insutype = "310"
  894. }
  895. if len(insutypes) == 0 {
  896. insutype = "310"
  897. }
  898. if len(insutypes) == 2 {
  899. insutype = strconv.FormatInt(social_type, 10)
  900. }
  901. //for _, item := range rf {
  902. // if item.Insutype == insutype {
  903. // insuplc_admdvs = item.InsuplcAdmdvs
  904. // }
  905. //}
  906. if res2.Infcode == 0 {
  907. //var insutypes []string
  908. //
  909. //var insutype string
  910. //var is390 int = 0
  911. //var is310 int = 0
  912. //for _, item := range res2.Output.Iinfo {
  913. // if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  914. // insutypes = append(insutypes, item.Insutype)
  915. // }
  916. //}
  917. //if len(insutypes) == 1 {
  918. // insutype = insutypes[0]
  919. //} else {
  920. // for _, i := range insutypes {
  921. // if i == "390" {
  922. // is390 = 1
  923. // }
  924. //
  925. // if i == "310" {
  926. // is310 = 1
  927. // }
  928. // }
  929. //}
  930. //if is390 == 1 {
  931. // insutype = "390"
  932. //}
  933. //if is310 == 1 {
  934. // insutype = "310"
  935. //}
  936. //
  937. //if len(insutypes) == 0 {
  938. // insutype = "310"
  939. //}
  940. if len(insuplc_admdvs) == 0 {
  941. insuplc_admdvs = miConfig.InsuplcAdmdvs
  942. }
  943. timestamp := time.Now().Unix()
  944. tempTime := time.Unix(timestamp, 0)
  945. timeFormat := tempTime.Format("20060102150405")
  946. chrgBchno := rand.Intn(100000) + 10000
  947. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(id, 10)
  948. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  949. var struct2401 service.Struct2401
  950. struct2401.PsnNo = res2.Output.Baseinfo.PsnNo
  951. struct2401.Insutype = insutype
  952. psn_info, _ := service.GetPsnByPatientId(patient.ID)
  953. if id_card_type == 1 {
  954. struct2401.MdtrtCertType = "03"
  955. bas := strings.Split(psn_info.CardInfo, "|")
  956. cardNumber := bas[2]
  957. struct2401.MdtrtCertNo = cardNumber
  958. } else {
  959. struct2401.MdtrtCertType = "02"
  960. struct2401.MdtrtCertNo = res2.Output.Baseinfo.Certno
  961. }
  962. if miConfig.Code == "H15049901371" {
  963. if med_type == 14 {
  964. if insutype == "390" {
  965. struct2401.MedType = "9933"
  966. } else if insutype == "310" {
  967. struct2401.MedType = "990502"
  968. }
  969. } else if med_type == 11 {
  970. struct2401.MedType = "11"
  971. }
  972. } else {
  973. struct2401.MedType = strconv.FormatInt(int64(med_type), 10)
  974. }
  975. struct2401.IptNo = ipt_otp_no
  976. struct2401.AtddrNo = doctorInfo.DoctorNumber
  977. struct2401.ChfpdrName = doctorInfo.UserName
  978. struct2401.AdmDiagDscr = diagnosisConfig[0].ClassName
  979. struct2401.AdmDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  980. struct2401.AdmDeptName = departmentInfo.Name
  981. struct2401.AdmBed = deviceNumber.Number
  982. struct2401.AdmBed = "待定"
  983. struct2401.DscgMaindiagName = diagnosisConfig[0].ClassName
  984. struct2401.DscgMaindiagCode = diagnosisConfig[0].CountryCode
  985. struct2401.Begntime = start_time
  986. struct2401.DiseCodg = sickConfig.CountryCode
  987. struct2401.DiseName = sickConfig.ClassName
  988. var dises []service.DiseinfoStruct
  989. for index, item := range diagnosisConfig {
  990. var dise service.DiseinfoStruct
  991. dise.PsnNo = res2.Output.Baseinfo.PsnNo
  992. dise.DiagType = "1"
  993. if index == 0 {
  994. dise.MaindiagFlag = "1"
  995. } else {
  996. dise.MaindiagFlag = "2"
  997. }
  998. dise.DiagSrtNo = strconv.FormatInt(int64(index), 10)
  999. dise.DiseDorName = doctorInfo.UserName
  1000. dise.DiagCode = item.CountryCode
  1001. dise.DiagName = item.ClassName
  1002. dise.DiagDept = departmentInfo.Name
  1003. dise.DiseDorNo = doctorInfo.DoctorNumber
  1004. dise.DiagTime = timeFormatOne
  1005. dises = append(dises, dise)
  1006. }
  1007. struct2401.Diseinfo = dises
  1008. var result string
  1009. var request_log string
  1010. if miConfig.MdtrtareaAdmvs == "150499" {
  1011. data := make(map[string]interface{})
  1012. data["org_name"] = miConfig.OrgName
  1013. data["doctor"] = role.UserName
  1014. data["fixmedins_code"] = miConfig.Code
  1015. data["insuplc_admdvs"] = insuplc_admdvs
  1016. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1017. data["secret_key"] = miConfig.SecretKey
  1018. data["struct_2401"] = struct2401
  1019. var req *http.Request
  1020. bytesData, _ := json.Marshal(data)
  1021. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2401", bytes.NewReader(bytesData))
  1022. client := &http.Client{}
  1023. resp, _ := client.Do(req)
  1024. defer resp.Body.Close()
  1025. body, ioErr := ioutil.ReadAll(resp.Body)
  1026. if ioErr != nil {
  1027. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1028. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1029. return
  1030. }
  1031. var respJSON map[string]interface{}
  1032. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1033. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1034. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1035. return
  1036. }
  1037. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1038. result_byte, _ := json.Marshal(respJSON)
  1039. result = string(result_byte)
  1040. } else {
  1041. result, request_log = service.ZHGdyb2401(struct2401, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, insuplc_admdvs, miConfig.MdtrtareaAdmvs)
  1042. saveLog(result, request_log, "2401", "入院登记")
  1043. }
  1044. var dat map[string]interface{}
  1045. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1046. fmt.Println(dat)
  1047. } else {
  1048. fmt.Println(err)
  1049. }
  1050. userJSONBytes, _ := json.Marshal(dat)
  1051. var res ResultThree
  1052. var resThree10265 ResultThree10265
  1053. if miConfig.Code == "H15049901371" {
  1054. if err := json.Unmarshal(userJSONBytes, &resThree10265); err != nil {
  1055. utils.ErrorLog("解析失败:%v", err)
  1056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1057. return
  1058. }
  1059. Infcode, _ := strconv.ParseInt(resThree10265.Infcode, 10, 64)
  1060. res.Infcode = Infcode
  1061. res.ErrMsg = resThree10265.ErrMsg
  1062. res.Output = resThree10265.Output
  1063. res.InfRefmsgid = resThree10265.InfRefmsgid
  1064. res.RespondTime = resThree10265.RespondTime
  1065. } else {
  1066. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1067. utils.ErrorLog("解析失败:%v", err)
  1068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1069. return
  1070. }
  1071. }
  1072. if res.Infcode == 0 {
  1073. //result2 := service.Gdyb5301Two(res2.Output.Baseinfo.PsnNo, miConfig.OrgName, role.UserName, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  1074. //fmt.Println(result2)
  1075. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  1076. Idetinfos, _ := json.Marshal(res2.Output.Idetinfo)
  1077. infoStr := string(Iinfos)
  1078. idetinfoStr := string(Idetinfos)
  1079. inHospital := &models.HisHospitalCheckRecord{
  1080. PatientId: id,
  1081. Name: name,
  1082. MedicalTreatmentType: med_type,
  1083. RecordDate: recordDateTime,
  1084. IdCardNo: id_card_no,
  1085. AdminUserId: admin_user_id,
  1086. Departments: department,
  1087. UserOrgId: adminInfo.CurrentOrgId,
  1088. Status: 1,
  1089. Ctime: time.Now().Unix(),
  1090. Mtime: time.Now().Unix(),
  1091. Number: res.Output.Result.MdtrtID,
  1092. Doctor: doctor,
  1093. PsnNo: res2.Output.Baseinfo.PsnNo,
  1094. PsnCertType: res2.Output.Baseinfo.PsnCertType,
  1095. Certno: res2.Output.Baseinfo.Certno,
  1096. PsnName: res2.Output.Baseinfo.PsnName,
  1097. Gend: res2.Output.Baseinfo.Gend,
  1098. Naty: res2.Output.Baseinfo.Naty,
  1099. MedType: med_type,
  1100. InsutypeType: insutype,
  1101. Brdy: res2.Output.Baseinfo.Brdy,
  1102. Iinfo: infoStr,
  1103. Idetinfo: idetinfoStr,
  1104. IptOtpNo: ipt_otp_no,
  1105. AdmBed: adm_bed,
  1106. IdCardType: id_card_type,
  1107. Diagnosis: diagnosis_ids,
  1108. SickType: sick_type,
  1109. MdtrtCertType: "02",
  1110. InHosptialTime: start_time,
  1111. OutHosptialTime: "",
  1112. InHospitalStatus: 1,
  1113. Certificates: certificates,
  1114. Phone: phone,
  1115. BalanceAccountsType: balance_accounts_type,
  1116. PsnType: psn_type,
  1117. InsuplcAdmdvs: insuplc_admdvs,
  1118. }
  1119. service.CreateHospitalRecord(inHospital)
  1120. c.ServeSuccessJSON(map[string]interface{}{
  1121. "msg": "办理入院成功",
  1122. "info": inHospital,
  1123. })
  1124. } else {
  1125. c.ServeSuccessJSON(map[string]interface{}{
  1126. "failed_code": -10,
  1127. "msg": res.ErrMsg,
  1128. })
  1129. }
  1130. } else {
  1131. c.ServeSuccessJSON(map[string]interface{}{
  1132. "failed_code": -10,
  1133. "msg": res2.ErrMsg,
  1134. })
  1135. return
  1136. }
  1137. }
  1138. func (this *ZHHisApiController) GetZHOutHospitalCheck() {
  1139. id, _ := this.GetInt64("id")
  1140. patient_id, _ := this.GetInt64("patient_id")
  1141. admin_user_id, _ := this.GetInt64("admin_user_id")
  1142. record_time := this.GetString("record_time")
  1143. out_time := this.GetString("out_time")
  1144. adminInfo := this.GetAdminUserInfo()
  1145. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1146. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1147. record, _ := service.GetInHospitalRecord(id)
  1148. if record.ID == 0 {
  1149. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  1150. return
  1151. }
  1152. timeLayout := "2006-01-02"
  1153. loc, _ := time.LoadLocation("Local")
  1154. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1155. if err != nil {
  1156. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1157. return
  1158. }
  1159. recordDateTime := theTime.Unix()
  1160. var patient service.Patients
  1161. if patient_id == 0 {
  1162. patient, _ = service.GetPatientByIDCard(record.IdCardNo, adminInfo.CurrentOrgId)
  1163. } else {
  1164. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  1165. }
  1166. fmt.Println(patient)
  1167. diagnosis_ids_arr := strings.Split(record.Diagnosis, "-")
  1168. diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  1169. departmentInfo, _ := service.GetDepartMentDetail(record.Departments)
  1170. doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, record.Doctor)
  1171. //deviceNumber, _ := service.GetDeviceNumberByID(record.AdmBed, adminInfo.CurrentOrgId)
  1172. sickConfig, _ := service.FindSickById(record.SickType)
  1173. var struct2402 service.Struct2402
  1174. timestamp := time.Now().Unix()
  1175. tempTime := time.Unix(timestamp, 0)
  1176. //timeFormat := tempTime.Format("20060102150405")
  1177. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  1178. struct2402.PsnNo = record.PsnNo
  1179. struct2402.Insutype = record.InsutypeType
  1180. struct2402.DscgWay = "1"
  1181. struct2402.Endtime = out_time
  1182. struct2402.DscgDeptName = departmentInfo.Number
  1183. struct2402.DscgDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  1184. struct2402.MdtrtId = record.Number
  1185. var dises []service.Diseinfo2402Struct
  1186. for index, item := range diagnosisConfig {
  1187. var dise service.Diseinfo2402Struct
  1188. dise.PsnNo = record.PsnNo
  1189. dise.DiagType = "1"
  1190. if index == 0 {
  1191. dise.MaindiagFlag = "1"
  1192. } else {
  1193. dise.MaindiagFlag = "2"
  1194. }
  1195. dise.MdtrtId = record.Number
  1196. dise.DiagSrtNo = strconv.FormatInt(int64(item.ID), 10)
  1197. dise.DiseDorName = doctorInfo.UserName
  1198. dise.DiagCode = item.CountryCode
  1199. dise.DiagName = item.ClassName
  1200. dise.DiagDept = departmentInfo.Name
  1201. dise.DiseDorNo = strconv.FormatInt(int64(doctorInfo.AdminUserId), 10)
  1202. dise.DiagTime = timeFormatOne
  1203. dises = append(dises, dise)
  1204. }
  1205. struct2402.Diseinfo = dises
  1206. struct2402.DiseName = sickConfig.ClassName
  1207. struct2402.DiseCode = sickConfig.CountryCode
  1208. var result string
  1209. var request_log string
  1210. if miConfig.MdtrtareaAdmvs == "150499" {
  1211. data := make(map[string]interface{})
  1212. data["org_name"] = miConfig.OrgName
  1213. data["doctor"] = role.UserName
  1214. data["fixmedins_code"] = miConfig.Code
  1215. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  1216. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1217. data["secret_key"] = miConfig.SecretKey
  1218. data["struct_2402"] = struct2402
  1219. var req *http.Request
  1220. bytesData, _ := json.Marshal(data)
  1221. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2402", bytes.NewReader(bytesData))
  1222. client := &http.Client{}
  1223. resp, _ := client.Do(req)
  1224. defer resp.Body.Close()
  1225. body, ioErr := ioutil.ReadAll(resp.Body)
  1226. if ioErr != nil {
  1227. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1228. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1229. return
  1230. }
  1231. var respJSON map[string]interface{}
  1232. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1233. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1234. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1235. return
  1236. }
  1237. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1238. result_byte, _ := json.Marshal(respJSON)
  1239. result = string(result_byte)
  1240. } else {
  1241. result, request_log = service.ZHGdyb2402(struct2402, miConfig.OrgName, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  1242. saveLog(result, request_log, "2402", "出院")
  1243. }
  1244. var dat map[string]interface{}
  1245. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1246. fmt.Println(dat)
  1247. } else {
  1248. fmt.Println(err)
  1249. }
  1250. userJSONBytes, _ := json.Marshal(dat)
  1251. var res ResultEmpty
  1252. var resEmpty10265 ResultEmpty10265
  1253. if miConfig.Code == "H15049901371" {
  1254. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  1255. utils.ErrorLog("解析失败:%v", err)
  1256. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1257. return
  1258. }
  1259. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  1260. res.Infcode = Infcode
  1261. res.RespondTime = resEmpty10265.RespondTime
  1262. res.ErrMsg = resEmpty10265.ErrMsg
  1263. res.Output = resEmpty10265.Output
  1264. res.WarnMsg = resEmpty10265.WarnMsg
  1265. } else {
  1266. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1267. utils.ErrorLog("解析失败:%v", err)
  1268. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1269. return
  1270. }
  1271. }
  1272. if res.Infcode == 0 {
  1273. record.OutHospitalStatus = 1
  1274. record.OutHosptialTime = struct2402.Endtime
  1275. record.OutWay = 1
  1276. service.CreateHospitalRecord(&record)
  1277. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  1278. var total float64
  1279. for _, item := range orders {
  1280. total = total + item.DetItemFeeSumamt
  1281. }
  1282. order := &models.HisOrder{
  1283. UserOrgId: adminInfo.CurrentOrgId,
  1284. HisPatientId: record.ID,
  1285. PatientId: record.PatientId,
  1286. SettleAccountsDate: recordDateTime,
  1287. Ctime: time.Now().Unix(),
  1288. Mtime: time.Now().Unix(),
  1289. Status: 1,
  1290. Number: record.Number,
  1291. Infcode: 0,
  1292. WarnMsg: "",
  1293. Cainfo: "",
  1294. ErrMsg: "",
  1295. RespondTime: "",
  1296. InfRefmsgid: "",
  1297. OrderStatus: 1,
  1298. MdtrtId: record.Number,
  1299. IsMedicineInsurance: 1,
  1300. PType: 1,
  1301. MedfeeSumamt: total,
  1302. }
  1303. err = service.CreateOrder(order)
  1304. if err != nil {
  1305. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1306. return
  1307. }
  1308. this.ServeSuccessJSON(map[string]interface{}{
  1309. "msg": "出院成功",
  1310. })
  1311. } else {
  1312. this.ServeSuccessJSON(map[string]interface{}{
  1313. "failed_code": -10,
  1314. "msg": res.ErrMsg,
  1315. })
  1316. }
  1317. }
  1318. func (c *ZHHisApiController) GetSettleInfo() {
  1319. order_id, _ := c.GetInt64("order_id")
  1320. patient_id, _ := c.GetInt64("patient_id")
  1321. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  1322. admin_user_id, _ := c.GetInt64("admin_user_id")
  1323. pay_way, _ := c.GetInt64("pay_way")
  1324. pay_price, _ := c.GetFloat("pay_price")
  1325. pay_card_no := c.GetString("pay_card_no")
  1326. discount_price, _ := c.GetFloat("discount_price")
  1327. preferential_price, _ := c.GetFloat("preferential_price")
  1328. reality_price, _ := c.GetFloat("reality_price")
  1329. found_price, _ := c.GetFloat("found_price")
  1330. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1331. private_price, _ := c.GetFloat("private_price")
  1332. fapiao_code := c.GetString("fapiao_code")
  1333. fapiao_number := c.GetString("fapiao_number")
  1334. record, _ := service.GetInHospitalRecord(in_hospital_id)
  1335. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  1336. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  1337. order, _ := service.GetHisOrderByID(order_id)
  1338. //dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  1339. //tmp_decimal := c.GetString("tmp_decimal")
  1340. //var decimal float64 //本次使用的押金
  1341. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  1342. tmp_decimal := c.GetString("tmp_decimal")
  1343. var decimal float64 //本次使用的押金
  1344. var errmsg error
  1345. if dec_way == "true" && tmp_decimal == "0" || dec_way == "true" && tmp_decimal == "" {
  1346. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  1347. return
  1348. }
  1349. if len(tmp_decimal) > 0 {
  1350. if tmp_decimal[0] == 45 {
  1351. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  1352. return
  1353. }
  1354. }
  1355. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  1356. if errs != nil {
  1357. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
  1358. return
  1359. }
  1360. decimal = tt
  1361. var rf []*ResultFive
  1362. json.Unmarshal([]byte(record.Iinfo), &rf)
  1363. chrg_bchno := order.Number
  1364. cert_no := record.Certno
  1365. if record.ID == 0 {
  1366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1367. return
  1368. }
  1369. if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  1370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  1371. return
  1372. }
  1373. if record.IdCardType == 1 {
  1374. } else {
  1375. cert_no = record.Certno
  1376. }
  1377. var result string
  1378. var src_resquest string
  1379. timeLayout := "2006-01-02"
  1380. loc, _ := time.LoadLocation("Local")
  1381. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record.InHosptialTime, loc)
  1382. if err != nil {
  1383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1384. return
  1385. }
  1386. recordStartDateTime := theTime.Unix()
  1387. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", record.OutHosptialTime, loc)
  1388. if err != nil {
  1389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1390. return
  1391. }
  1392. recordEndDateTime := theTimeEnd.Unix()
  1393. prescriptions, _ := service.GetZHSettleMonthHisPrescription(c.GetAdminUserInfo().CurrentOrgId, patient_id, recordStartDateTime, recordEndDateTime)
  1394. var total float64
  1395. for _, item := range prescriptions {
  1396. if item.Type == 1 { //药品
  1397. for _, subItem := range item.HisDoctorAdviceInfo {
  1398. total = total + (subItem.Price * subItem.PrescribingNumber)
  1399. }
  1400. }
  1401. if item.Type == 2 { //项目
  1402. for _, subItem := range item.HisPrescriptionProject {
  1403. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  1404. total = total + (subItem.Price * cnt)
  1405. }
  1406. }
  1407. }
  1408. //allTotal := fmt.Sprintf("%.2f", total)
  1409. var allTotal string
  1410. if record.OutHospitalStatus == 0 && order.ID == 0 {
  1411. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  1412. var total float64
  1413. for _, item := range orders {
  1414. total = total + item.DetItemFeeSumamt
  1415. }
  1416. allTotal = fmt.Sprintf("%.4f", total)
  1417. } else {
  1418. allTotal = fmt.Sprintf("%.4f", order.MedfeeSumamt)
  1419. }
  1420. if miConfig.MdtrtareaAdmvs == "150499" {
  1421. psn_info, _ := service.GetPsnByPatientId(patient_id)
  1422. mdtrt_cert_no := ""
  1423. if record.IdCardType == 1 {
  1424. bas := strings.Split(psn_info.CardInfo, "|")
  1425. cardNumber := bas[2]
  1426. mdtrt_cert_no = cardNumber
  1427. } else {
  1428. mdtrt_cert_no = record.Certno
  1429. }
  1430. var acct_used_flag string
  1431. if pay_way == 4 {
  1432. acct_used_flag = "1"
  1433. } else {
  1434. acct_used_flag = "0"
  1435. }
  1436. //请求内网数据
  1437. api := "http://172.16.13.254:9532/" + "nmyb/2304?psn_no=" + record.PsnNo + "&mdtrt_id=" + record.Number + "&chrg_bchno=" + chrg_bchno +
  1438. "&insutype_type=" + record.InsutypeType + "&total=" + allTotal +
  1439. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  1440. "&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
  1441. resp, requestErr := http.Get(api)
  1442. if requestErr != nil {
  1443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1444. return
  1445. }
  1446. body, ioErr := ioutil.ReadAll(resp.Body)
  1447. if ioErr != nil {
  1448. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1450. return
  1451. }
  1452. var respJSON map[string]interface{}
  1453. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1454. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1456. return
  1457. }
  1458. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1459. result_byte, _ := json.Marshal(respJSON)
  1460. result = string(result_byte)
  1461. } else {
  1462. 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")
  1463. saveLog(result, src_resquest, "2304", "住院结算")
  1464. }
  1465. var dat map[string]interface{}
  1466. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1467. fmt.Println(dat)
  1468. } else {
  1469. fmt.Println(err)
  1470. }
  1471. userJSONBytes, _ := json.Marshal(dat)
  1472. var res ResultSeven
  1473. var resSeven10265 ResultSeven10265
  1474. if miConfig.Code == "H15049901371" {
  1475. if err := json.Unmarshal(userJSONBytes, &resSeven10265); err != nil {
  1476. utils.ErrorLog("解析失败:%v", err)
  1477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1478. return
  1479. }
  1480. Infcode, _ := strconv.ParseInt(resSeven10265.Infcode, 10, 64)
  1481. res.Infcode = Infcode
  1482. res.InfRefmsgid = resSeven10265.InfRefmsgid
  1483. res.RespondTime = resSeven10265.RespondTime
  1484. res.ErrMsg = resSeven10265.ErrMsg
  1485. res.Output = resSeven10265.Output
  1486. res.WarnMsg = resSeven10265.WarnMsg
  1487. res.Cainfo = resSeven10265.Cainfo
  1488. } else {
  1489. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1490. utils.ErrorLog("解析失败:%v", err)
  1491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1492. return
  1493. }
  1494. }
  1495. if res.Infcode != 0 {
  1496. errlog := &models.HisOrderError{
  1497. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1498. Ctime: time.Now().Unix(),
  1499. Mtime: time.Now().Unix(),
  1500. Number: chrg_bchno,
  1501. ErrMsg: res.ErrMsg,
  1502. Status: 1,
  1503. PatientId: patient_id,
  1504. RecordTime: time.Now().Unix(),
  1505. Stage: 6,
  1506. }
  1507. service.CreateErrMsgLog(errlog)
  1508. c.ServeSuccessJSON(map[string]interface{}{
  1509. "failed_code": -10,
  1510. "msg": res.ErrMsg,
  1511. })
  1512. return
  1513. } else {
  1514. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1515. order.OrderStatus = 2
  1516. order.DiscountPrice = discount_price
  1517. order.MedicalInsurancePrice = medical_insurance_price
  1518. order.FaPiaoNumber = fapiao_number
  1519. order.FaPiaoCode = fapiao_code
  1520. order.PayWay = pay_way
  1521. order.PayPrice = pay_price
  1522. order.PayCardNo = pay_card_no
  1523. order.PreferentialPrice = preferential_price
  1524. order.RealityPrice = reality_price
  1525. order.FoundPrice = found_price
  1526. order.PrivatePrice = private_price
  1527. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1528. order.SetlId = res.Output.Setlinfo.SetlID
  1529. order.PsnNo = res.Output.Setlinfo.PsnNo
  1530. order.PsnName = res.Output.Setlinfo.PsnName
  1531. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1532. order.Certno = res.Output.Setlinfo.Certno
  1533. order.Gend = res.Output.Setlinfo.Gend
  1534. order.Naty = res.Output.Setlinfo.Naty
  1535. order.Age = res.Output.Setlinfo.Age
  1536. order.Insutype = res.Output.Setlinfo.Insutype
  1537. order.PsnType = res.Output.Setlinfo.PsnType
  1538. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1539. order.SetlTime = res.Output.Setlinfo.SetlTime
  1540. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1541. if res.Output.Setlinfo.MedType == "140104" {
  1542. order.MedType = "14"
  1543. } else {
  1544. order.MedType = res.Output.Setlinfo.MedType
  1545. }
  1546. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1547. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1548. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1549. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1550. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1551. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1552. order.HifpPay = res.Output.Setlinfo.HifpPay
  1553. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1554. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1555. order.HifesPay = res.Output.Setlinfo.HifesPay
  1556. order.HifobPay = res.Output.Setlinfo.HifobPay
  1557. order.MafPay = res.Output.Setlinfo.MafPay
  1558. order.OthPay = res.Output.Setlinfo.OthPay
  1559. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1560. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1561. order.AcctPay = res.Output.Setlinfo.AcctPay
  1562. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1563. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1564. order.Balc = res.Output.Setlinfo.Balc
  1565. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1566. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1567. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1568. order.ClrWay = res.Output.Setlinfo.ClrWay
  1569. order.Creator = order.Creator
  1570. order.Modify = roles.AdminUserId
  1571. order.RequestLog = src_resquest
  1572. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1573. detailStr := string(setlDetail)
  1574. order.SetlDetail = detailStr
  1575. err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  1576. err = service.UpDateOrder(order)
  1577. if err == nil {
  1578. //判断是否使用了押金
  1579. if dec_way == "true" {
  1580. tmpstring := strconv.FormatInt(order.ID, 10)
  1581. order.Decimal = decimal
  1582. err = service.UpDateOrder(order)
  1583. //扣押金
  1584. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, patient_id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  1585. if errmsg != nil {
  1586. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  1587. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  1588. return
  1589. }
  1590. }
  1591. c.ServeSuccessJSON(map[string]interface{}{
  1592. "msg": "结算成功",
  1593. })
  1594. } else {
  1595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1596. return
  1597. }
  1598. }
  1599. }
  1600. func (c *ZHHisApiController) GetPreSettleInfo() {
  1601. order_id, _ := c.GetInt64("order_id")
  1602. patient_id, _ := c.GetInt64("patient_id")
  1603. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  1604. admin_user_id, _ := c.GetInt64("admin_user_id")
  1605. record, _ := service.GetInHospitalRecord(in_hospital_id)
  1606. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  1607. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  1608. order, _ := service.GetHisOrderByID(order_id)
  1609. var allTotal string
  1610. if record.OutHospitalStatus == 0 && order.ID == 0 {
  1611. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  1612. var total float64
  1613. for _, item := range orders {
  1614. total = total + item.DetItemFeeSumamt
  1615. }
  1616. allTotal = fmt.Sprintf("%.4f", total)
  1617. } else {
  1618. allTotal = fmt.Sprintf("%.4f", order.MedfeeSumamt)
  1619. }
  1620. var rf []*ResultFive
  1621. json.Unmarshal([]byte(record.Iinfo), &rf)
  1622. chrg_bchno := order.Number
  1623. cert_no := record.Certno
  1624. if record.ID == 0 {
  1625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1626. return
  1627. }
  1628. //if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  1629. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  1630. // return
  1631. //}
  1632. psn_info, _ := service.GetPsnByPatientId(patient_id)
  1633. if record.IdCardType == 1 {
  1634. bas := strings.Split(psn_info.CardInfo, "|")
  1635. cardNumber := bas[2]
  1636. cert_no = cardNumber
  1637. } else {
  1638. cert_no = record.Certno
  1639. }
  1640. var result string
  1641. var src_resquest string
  1642. if miConfig.MdtrtareaAdmvs == "150499" {
  1643. //请求内网数据
  1644. api := "http://172.16.13.254:9532/" + "nmyb/2303?psn_no=" + record.PsnNo + "&mdtrt_id=" + record.Number + "&chrg_bchno=" + chrg_bchno +
  1645. "&insutype_type=" + record.InsutypeType + "&total=" + allTotal +
  1646. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  1647. "&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
  1648. resp, requestErr := http.Get(api)
  1649. if requestErr != nil {
  1650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1651. return
  1652. }
  1653. body, ioErr := ioutil.ReadAll(resp.Body)
  1654. if ioErr != nil {
  1655. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1657. return
  1658. }
  1659. var respJSON map[string]interface{}
  1660. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1661. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1663. return
  1664. }
  1665. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1666. result_byte, _ := json.Marshal(respJSON)
  1667. result = string(result_byte)
  1668. } else {
  1669. 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)
  1670. saveLog(result, src_resquest, "2303", "住院预结算")
  1671. }
  1672. var dat map[string]interface{}
  1673. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1674. fmt.Println(dat)
  1675. } else {
  1676. fmt.Println(err)
  1677. }
  1678. userJSONBytes, _ := json.Marshal(dat)
  1679. var res ResultSeven
  1680. var resSeven10265 ResultSeven10265
  1681. if miConfig.Code == "H15049901371" {
  1682. if err := json.Unmarshal(userJSONBytes, &resSeven10265); err != nil {
  1683. utils.ErrorLog("解析失败:%v", err)
  1684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1685. return
  1686. }
  1687. Infcode, _ := strconv.ParseInt(resSeven10265.Infcode, 10, 64)
  1688. res.Infcode = Infcode
  1689. res.InfRefmsgid = resSeven10265.InfRefmsgid
  1690. res.RespondTime = resSeven10265.RespondTime
  1691. res.ErrMsg = resSeven10265.ErrMsg
  1692. res.Output = resSeven10265.Output
  1693. res.WarnMsg = resSeven10265.WarnMsg
  1694. res.Cainfo = resSeven10265.Cainfo
  1695. } else {
  1696. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1697. utils.ErrorLog("解析失败:%v", err)
  1698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1699. return
  1700. }
  1701. }
  1702. if res.Infcode != 0 {
  1703. errlog := &models.HisOrderError{
  1704. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1705. Ctime: time.Now().Unix(),
  1706. Mtime: time.Now().Unix(),
  1707. Number: chrg_bchno,
  1708. ErrMsg: res.ErrMsg,
  1709. Status: 1,
  1710. PatientId: patient_id,
  1711. RecordTime: time.Now().Unix(),
  1712. Stage: 6,
  1713. }
  1714. service.CreateErrMsgLog(errlog)
  1715. c.ServeSuccessJSON(map[string]interface{}{
  1716. "failed_code": -10,
  1717. "msg": res.ErrMsg,
  1718. })
  1719. return
  1720. } else {
  1721. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1722. order.OrderStatus = 1
  1723. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1724. order.SetlId = res.Output.Setlinfo.SetlID
  1725. order.PsnNo = res.Output.Setlinfo.PsnNo
  1726. order.PsnName = res.Output.Setlinfo.PsnName
  1727. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1728. order.Certno = res.Output.Setlinfo.Certno
  1729. order.Gend = res.Output.Setlinfo.Gend
  1730. order.Naty = res.Output.Setlinfo.Naty
  1731. order.Age = res.Output.Setlinfo.Age
  1732. order.Insutype = res.Output.Setlinfo.Insutype
  1733. order.PsnType = res.Output.Setlinfo.PsnType
  1734. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1735. order.SetlTime = res.Output.Setlinfo.SetlTime
  1736. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1737. if res.Output.Setlinfo.MedType == "140104" {
  1738. order.MedType = "14"
  1739. } else {
  1740. order.MedType = res.Output.Setlinfo.MedType
  1741. }
  1742. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1743. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1744. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1745. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1746. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1747. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1748. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  1749. order.HifpPay = res.Output.Setlinfo.HifpPay
  1750. order.HifesPay = res.Output.Setlinfo.HifesPay
  1751. order.HifobPay = res.Output.Setlinfo.HifobPay
  1752. order.MafPay = res.Output.Setlinfo.MafPay
  1753. order.OthPay = res.Output.Setlinfo.OthPay
  1754. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1755. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1756. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1757. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1758. order.AcctPay = res.Output.Setlinfo.AcctPay
  1759. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1760. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1761. order.Balc = res.Output.Setlinfo.Balc
  1762. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1763. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1764. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1765. order.ClrWay = res.Output.Setlinfo.ClrWay
  1766. order.Creator = order.Creator
  1767. order.Modify = roles.AdminUserId
  1768. order.RequestLog = src_resquest
  1769. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1770. detailStr := string(setlDetail)
  1771. order.SetlDetail = detailStr
  1772. //err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  1773. if record.OutHospitalStatus == 1 && order.ID > 0 {
  1774. err := service.UpDateOrder(order)
  1775. if err == nil {
  1776. c.ServeSuccessJSON(map[string]interface{}{
  1777. "msg": "预结算成功",
  1778. "order_way": 1,
  1779. })
  1780. } else {
  1781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1782. return
  1783. }
  1784. } else if record.OutHospitalStatus == 0 && order.ID == 0 {
  1785. c.ServeSuccessJSON(map[string]interface{}{
  1786. "msg": "预结算成功",
  1787. "order": order,
  1788. "order_way": 2,
  1789. })
  1790. }
  1791. }
  1792. }
  1793. func (c *ZHHisApiController) GetUploadInfo() {
  1794. id, _ := c.GetInt64("id")
  1795. record_time := c.GetString("record_time")
  1796. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  1797. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1798. admin_user_id, _ := c.GetInt64("admin_user_id")
  1799. timeLayout := "2006-01-02"
  1800. loc, _ := time.LoadLocation("Local")
  1801. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1802. if err != nil {
  1803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1804. return
  1805. }
  1806. recordDateTime := theTime.Unix()
  1807. adminUser := c.GetAdminUserInfo()
  1808. var prescriptions []*models.HisPrescription
  1809. data := make(map[string]interface{})
  1810. if settle_accounts_type == 1 { //日结
  1811. prescriptions, _ = service.GetZHHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1812. } else { //月结
  1813. start_time_str := c.GetString("start_time")
  1814. end_time_str := c.GetString("end_time")
  1815. timeLayout := "2006-01-02"
  1816. loc, _ := time.LoadLocation("Local")
  1817. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1818. if err != nil {
  1819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1820. return
  1821. }
  1822. recordStartTime := theStartTime.Unix()
  1823. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1824. if err != nil {
  1825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1826. return
  1827. }
  1828. recordEndTime := theEndTime.Unix()
  1829. prescriptions, _ = service.GetZHMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1830. }
  1831. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1832. record, _ := service.GetInHospitalRecord(in_hospital_id)
  1833. if record.ID == 0 {
  1834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1835. return
  1836. }
  1837. timestamp := time.Now().Unix()
  1838. tempTime := time.Unix(timestamp, 0)
  1839. timeFormat := tempTime.Format("20060102150405")
  1840. chrgBchno := rand.Intn(100000) + 10000
  1841. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(record.PatientId, 10)
  1842. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1843. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1844. department, _ := service.GetDepartMentDetail(record.Departments)
  1845. strconv.FormatInt(record.PatientId, 10)
  1846. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.Creator)
  1847. //client := &http.Client{}
  1848. data["psn_no"] = record.PsnNo
  1849. data["mdtrt_id"] = record.Number
  1850. data["chrg_bchno"] = chrg_bchno
  1851. data["org_name"] = miConfig.OrgName
  1852. data["doctor"] = roles.UserName
  1853. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1854. data["dept"] = strconv.FormatInt(department.ID, 10)
  1855. data["fixmedins_code"] = miConfig.Code
  1856. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  1857. data["dept_code"] = "15"
  1858. } else {
  1859. data["dept_code"] = department.Number
  1860. }
  1861. if miConfig.Code == "H15049901371" {
  1862. if record.MedType == 14 {
  1863. if record.InsutypeType == "390" {
  1864. data["med_type"] = "9933"
  1865. } else if record.InsutypeType == "310" {
  1866. data["med_type"] = "990502"
  1867. }
  1868. } else if record.MedType == 11 {
  1869. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  1870. }
  1871. } else {
  1872. if record.MedType == 1112 {
  1873. data["med_type"] = strconv.FormatInt(11, 10)
  1874. } else {
  1875. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  1876. }
  1877. }
  1878. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  1879. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1880. data["secret_key"] = miConfig.SecretKey
  1881. var ids []int64
  1882. fmt.Println(data)
  1883. for _, item := range prescriptions {
  1884. ids = append(ids, item.ID)
  1885. }
  1886. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1887. if config.IsOpen == 1 { //对接了医保,走医保流程
  1888. var pagesize int = 100
  1889. var start int = 1
  1890. var stop int
  1891. var pagecount int
  1892. var curpage int
  1893. var isSuccess bool = true
  1894. var customs []*models.NewCustom
  1895. for _, item := range prescriptions {
  1896. tm := time.Unix(item.PreTime, 0)
  1897. if item.Type == 1 { //药品
  1898. for _, subItem := range item.HisDoctorAdviceInfo {
  1899. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 && subItem.BaseDrugLib.IsUser != 1 {
  1900. //var randNum int
  1901. //randNum = rand.Intn(10000) + 1000
  1902. cus := &models.NewCustom{
  1903. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  1904. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  1905. FeedetlSn: subItem.FeedetlSn,
  1906. Price: fmt.Sprintf("%.4f", subItem.Price),
  1907. MedListCodg: subItem.BaseDrugLib.MedicalInsuranceNumber,
  1908. HospApprFlag: subItem.BaseDrugLib.HospApprFlag,
  1909. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  1910. DoctorId: item.Creator,
  1911. }
  1912. customs = append(customs, cus)
  1913. }
  1914. }
  1915. }
  1916. if item.Type == 2 { //项目
  1917. for _, subItem := range item.HisPrescriptionProject {
  1918. //var randNum int
  1919. //randNum = rand.Intn(10000) + 1000
  1920. if subItem.Type == 2 {
  1921. if len(subItem.HisProject.MedicalCode) > 0 {
  1922. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  1923. cus := &models.NewCustom{
  1924. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  1925. Cut: fmt.Sprintf("%.4f", cnt),
  1926. FeedetlSn: subItem.FeedetlSn,
  1927. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  1928. MedListCodg: subItem.HisProject.MedicalCode,
  1929. HospApprFlag: -1,
  1930. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  1931. DoctorId: item.Creator,
  1932. }
  1933. customs = append(customs, cus)
  1934. }
  1935. } else if subItem.Type == 3 {
  1936. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 && subItem.GoodInfo.IsUser != 1 {
  1937. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  1938. cus := &models.NewCustom{
  1939. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  1940. Cut: fmt.Sprintf("%.4f", cnt),
  1941. FeedetlSn: subItem.FeedetlSn,
  1942. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  1943. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  1944. HospApprFlag: -1,
  1945. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  1946. DoctorId: item.Creator,
  1947. }
  1948. customs = append(customs, cus)
  1949. }
  1950. }
  1951. }
  1952. }
  1953. }
  1954. //总页数,向上取整,注意除之前要先转换类型为float64
  1955. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  1956. var ress []*ResultFour
  1957. for curpage = 1; curpage <= pagecount; curpage++ {
  1958. if curpage == 1 {
  1959. start = 1
  1960. } else {
  1961. start = (curpage-1)*pagesize + 1
  1962. }
  1963. stop = curpage * pagesize
  1964. if stop > len(customs) {
  1965. stop = len(customs)
  1966. }
  1967. var result string
  1968. var requestLog string
  1969. if miConfig.MdtrtareaAdmvs == "150499" {
  1970. data := make(map[string]interface{})
  1971. if record.MedType == 14 {
  1972. if record.InsutypeType == "390" {
  1973. data["med_type"] = "9933"
  1974. } else if record.InsutypeType == "310" {
  1975. data["med_type"] = "990502"
  1976. }
  1977. } else if record.MedType == 11 {
  1978. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  1979. }
  1980. data["psn_no"] = record.PsnNo
  1981. data["number"] = record.Number
  1982. data["customs"] = customs[start-1 : stop]
  1983. data["chrg_bchno"] = chrg_bchno
  1984. data["dept"] = strconv.FormatInt(department.ID, 10)
  1985. data["dept_code"] = department.Number
  1986. data["doctor_code"] = doctor_info.DoctorNumber
  1987. data["doctor_name"] = doctor_info.UserName
  1988. data["org_name"] = miConfig.OrgName
  1989. data["opertor"] = roles.UserName
  1990. data["fixmedins_code"] = miConfig.Code
  1991. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  1992. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1993. data["secret_key"] = miConfig.SecretKey
  1994. var req *http.Request
  1995. bytesData, _ := json.Marshal(data)
  1996. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2301", bytes.NewReader(bytesData))
  1997. client := &http.Client{}
  1998. resp, _ := client.Do(req)
  1999. defer resp.Body.Close()
  2000. body, ioErr := ioutil.ReadAll(resp.Body)
  2001. if ioErr != nil {
  2002. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2004. return
  2005. }
  2006. var respJSON map[string]interface{}
  2007. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  2008. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2010. return
  2011. }
  2012. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2013. result_byte, _ := json.Marshal(respJSON)
  2014. result = string(result_byte)
  2015. } else {
  2016. 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)
  2017. saveLog(result, requestLog, "2301", "上传明细")
  2018. }
  2019. var dat map[string]interface{}
  2020. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2021. fmt.Println(dat)
  2022. } else {
  2023. fmt.Println(err)
  2024. }
  2025. userJSONBytes, _ := json.Marshal(dat)
  2026. var res ResultFour
  2027. var resFour10265 ResultFour10265
  2028. if miConfig.Code == "H15049901371" {
  2029. if err := json.Unmarshal(userJSONBytes, &resFour10265); err != nil {
  2030. utils.ErrorLog("解析失败:%v", err)
  2031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2032. return
  2033. }
  2034. res.WarnMsg = resFour10265.WarnMsg
  2035. res.Output = resFour10265.Output
  2036. res.ErrMsg = resFour10265.ErrMsg
  2037. res.RespondTime = resFour10265.RespondTime
  2038. res.InfRefmsgid = resFour10265.InfRefmsgid
  2039. Infcode, _ := strconv.ParseInt(resFour10265.Infcode, 10, 64)
  2040. res.Infcode = Infcode
  2041. } else {
  2042. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2043. utils.ErrorLog("解析失败:%v", err)
  2044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2045. return
  2046. }
  2047. }
  2048. if res.Infcode == 0 {
  2049. ress = append(ress, &res)
  2050. } else {
  2051. isSuccess = false
  2052. errlog := &models.HisOrderError{
  2053. UserOrgId: adminUser.CurrentOrgId,
  2054. Ctime: time.Now().Unix(),
  2055. Mtime: time.Now().Unix(),
  2056. Number: chrg_bchno,
  2057. ErrMsg: "",
  2058. Status: 1,
  2059. PatientId: id,
  2060. RecordTime: recordDateTime,
  2061. Stage: 4,
  2062. }
  2063. service.CreateErrMsgLog(errlog)
  2064. c.ServeSuccessJSON(map[string]interface{}{
  2065. "failed_code": -10,
  2066. "msg": "上传明细错误,请联系his厂商",
  2067. })
  2068. return
  2069. }
  2070. }
  2071. if isSuccess == true {
  2072. if settle_accounts_type == 1 {
  2073. for _, subItem := range ress {
  2074. for _, item := range subItem.Output.Result {
  2075. temp := strings.Split(item.FeedetlSn, "-")
  2076. var advice_id int64 = 0
  2077. var project_id int64 = 0
  2078. var types int64 = 0
  2079. id, _ := strconv.ParseInt(temp[2], 10, 64)
  2080. types, _ = strconv.ParseInt(temp[1], 10, 64)
  2081. if temp[1] == "1" {
  2082. advice_id = id
  2083. project_id = 0
  2084. } else if temp[1] == "2" {
  2085. advice_id = 0
  2086. project_id = id
  2087. }
  2088. info := &models.HisOrderInfo{
  2089. OrderNumber: record.Number,
  2090. FeedetlSn: item.FeedetlSn,
  2091. UploadDate: recordDateTime,
  2092. AdviceId: advice_id,
  2093. DetItemFeeSumamt: item.DetItemFeeSumamt,
  2094. Cnt: item.Cnt,
  2095. Pric: float64(item.Pric),
  2096. PatientId: record.PatientId,
  2097. PricUplmtAmt: item.PricUplmtAmt,
  2098. SelfpayProp: item.SelfpayProp,
  2099. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2100. OverlmtAmt: item.OverlmtAmt,
  2101. PreselfpayAmt: item.PreselfpayAmt,
  2102. BasMednFlag: item.BasMednFlag,
  2103. MedChrgitmType: item.MedChrgitmType,
  2104. HiNegoDrugFlag: item.HiNegoDrugFlag,
  2105. Status: 1,
  2106. Memo: item.Memo,
  2107. Mtime: time.Now().Unix(),
  2108. InscpScpAmt: item.InscpScpAmt,
  2109. DrtReimFlag: item.DrtReimFlag,
  2110. Ctime: time.Now().Unix(),
  2111. ListSpItemFlag: item.ListSpItemFlag,
  2112. ChldMedcFlag: item.ChldMedcFlag,
  2113. LmtUsedFlag: item.LmtUsedFlag,
  2114. ChrgitmLv: item.ChrgitmLv,
  2115. UserOrgId: adminUser.CurrentOrgId,
  2116. HisPatientId: record.ID,
  2117. OrderId: 0,
  2118. ProjectId: project_id,
  2119. Type: types,
  2120. SettleType: settle_accounts_type,
  2121. }
  2122. service.CreateOrderInfo(info)
  2123. }
  2124. }
  2125. err := service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  2126. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  2127. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  2128. if err == nil {
  2129. c.ServeSuccessJSON(map[string]interface{}{
  2130. "msg": "上传费用明细成功",
  2131. })
  2132. return
  2133. } else {
  2134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2135. return
  2136. }
  2137. } else {
  2138. for _, subItem := range ress {
  2139. for _, item := range subItem.Output.Result {
  2140. temp := strings.Split(item.FeedetlSn, "-")
  2141. var advice_id int64 = 0
  2142. var project_id int64 = 0
  2143. var types int64 = 0
  2144. id, _ := strconv.ParseInt(temp[2], 10, 64)
  2145. types, _ = strconv.ParseInt(temp[1], 10, 64)
  2146. if temp[1] == "1" {
  2147. advice_id = id
  2148. project_id = 0
  2149. } else if temp[1] == "2" {
  2150. advice_id = 0
  2151. project_id = id
  2152. }
  2153. info := &models.HisOrderInfo{
  2154. OrderNumber: record.Number,
  2155. FeedetlSn: item.FeedetlSn,
  2156. UploadDate: time.Now().Unix(),
  2157. AdviceId: advice_id,
  2158. DetItemFeeSumamt: item.DetItemFeeSumamt,
  2159. Cnt: item.Cnt,
  2160. Pric: float64(item.Pric),
  2161. PatientId: record.PatientId,
  2162. PricUplmtAmt: item.PricUplmtAmt,
  2163. SelfpayProp: item.SelfpayProp,
  2164. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2165. OverlmtAmt: item.OverlmtAmt,
  2166. PreselfpayAmt: item.PreselfpayAmt,
  2167. BasMednFlag: item.BasMednFlag,
  2168. MedChrgitmType: item.MedChrgitmType,
  2169. HiNegoDrugFlag: item.HiNegoDrugFlag,
  2170. Status: 1,
  2171. Memo: item.Memo,
  2172. Mtime: time.Now().Unix(),
  2173. InscpScpAmt: item.InscpScpAmt,
  2174. DrtReimFlag: item.DrtReimFlag,
  2175. Ctime: time.Now().Unix(),
  2176. ListSpItemFlag: item.ListSpItemFlag,
  2177. ChldMedcFlag: item.ChldMedcFlag,
  2178. LmtUsedFlag: item.LmtUsedFlag,
  2179. ChrgitmLv: item.ChrgitmLv,
  2180. UserOrgId: adminUser.CurrentOrgId,
  2181. HisPatientId: record.ID,
  2182. ProjectId: project_id,
  2183. Type: types,
  2184. SettleType: settle_accounts_type,
  2185. }
  2186. service.CreateOrderInfo(info)
  2187. }
  2188. }
  2189. service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  2190. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  2191. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  2192. c.ServeSuccessJSON(map[string]interface{}{
  2193. "msg": "上传费用明细成功",
  2194. })
  2195. }
  2196. }
  2197. }
  2198. }
  2199. func (c *ZHHisApiController) ZHRefund() {
  2200. order_id, _ := c.GetInt64("order_id")
  2201. admin_user_id, _ := c.GetInt64("admin_user_id")
  2202. adminUser := c.GetAdminUserInfo()
  2203. var order models.HisOrder
  2204. order, _ = service.GetHisOrderByID(order_id)
  2205. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  2206. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2207. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2208. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2209. if config.IsOpen == 1 { //对接了医保,走医保流程
  2210. var result string
  2211. var requestLog string
  2212. if miConfig.MdtrtareaAdmvs == "150499" {
  2213. //请求内网数据
  2214. api := "http://172.16.13.254:9532/" + "nmyb/2305?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo + "&setl_id=" + order.SetlId +
  2215. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2216. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2217. resp, requestErr := http.Get(api)
  2218. if requestErr != nil {
  2219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2220. return
  2221. }
  2222. body, ioErr := ioutil.ReadAll(resp.Body)
  2223. if ioErr != nil {
  2224. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2226. return
  2227. }
  2228. var respJSON map[string]interface{}
  2229. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2230. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2232. return
  2233. }
  2234. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2235. result_byte, _ := json.Marshal(respJSON)
  2236. result = string(result_byte)
  2237. //saveLog(result, requestLog, "2404", "入院登记撤销")
  2238. saveLog(result, requestLog, "2305", "退费")
  2239. } else {
  2240. result, requestLog := service.Gdyb2305(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2241. saveLog(result, requestLog, "2305", "退费")
  2242. }
  2243. var dat map[string]interface{}
  2244. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2245. fmt.Println(dat)
  2246. } else {
  2247. fmt.Println(err)
  2248. }
  2249. userJSONBytes, _ := json.Marshal(dat)
  2250. var res ResultSixteen
  2251. var resSixteen ResultSixteen10265
  2252. if miConfig.Code == "H15049901371" {
  2253. if err := json.Unmarshal(userJSONBytes, &resSixteen); err != nil {
  2254. utils.ErrorLog("解析失败:%v", err)
  2255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2256. return
  2257. }
  2258. res.Cainfo = resSixteen.Cainfo
  2259. res.WarnMsg = resSixteen.WarnMsg
  2260. res.Output = resSixteen.Output
  2261. res.ErrMsg = resSixteen.ErrMsg
  2262. res.RespondTime = resSixteen.RespondTime
  2263. Infcode, _ := strconv.ParseInt(resSixteen.Infcode, 10, 64)
  2264. res.Infcode = Infcode
  2265. } else {
  2266. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2267. utils.ErrorLog("解析失败:%v", err)
  2268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2269. return
  2270. }
  2271. }
  2272. if res.Infcode == 0 {
  2273. err := service.UpdataOrderStatusThree(order_id, order.Number, adminUser.CurrentOrgId, "", result)
  2274. ////不同地区退费流程不一样,肇庆那边退费就包括撤销出院,内蒙古退费不包括撤销明细,所以下面需要根据不同情况进行判断
  2275. //if miConfig.UserOrgId == 10215 {
  2276. // record.OutHospitalStatus = 0
  2277. // service.CreateHospitalRecord(&record)
  2278. //}
  2279. service.UpdataOrderStatusByNumber(record.Number)
  2280. if err == nil {
  2281. ////当押金不为零时产生退费记录
  2282. if order.Decimal != 0 {
  2283. tmp := strconv.FormatInt(order.ID, 10)
  2284. err = service.MoneyIncrease(adminUser.CurrentOrgId, order.PatientId, tmp, order.Decimal)
  2285. if err != nil {
  2286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2287. return
  2288. }
  2289. }
  2290. c.ServeSuccessJSON(map[string]interface{}{
  2291. "msg": "退费成功",
  2292. })
  2293. } else {
  2294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2295. return
  2296. }
  2297. } else {
  2298. c.ServeSuccessJSON(map[string]interface{}{
  2299. "code": -10,
  2300. "msg": res.ErrMsg,
  2301. })
  2302. }
  2303. } else {
  2304. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  2305. if err == nil {
  2306. c.ServeSuccessJSON(map[string]interface{}{
  2307. "msg": "退费成功",
  2308. })
  2309. } else {
  2310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2311. return
  2312. }
  2313. }
  2314. }
  2315. func (c *ZHHisApiController) ZHRefundDetail() {
  2316. patient_id, _ := c.GetInt64("patient_id")
  2317. his_patient_id, _ := c.GetInt64("his_patient_id")
  2318. record_time := c.GetString("record_time")
  2319. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2320. //order_id, _ := c.GetInt64("order_id")
  2321. admin_user_id, _ := c.GetInt64("admin_user_id")
  2322. timeLayout := "2006-01-02"
  2323. loc, _ := time.LoadLocation("Local")
  2324. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2325. if err != nil {
  2326. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2327. return
  2328. }
  2329. recordDateTime := theTime.Unix()
  2330. adminUser := c.GetAdminUserInfo()
  2331. theTimeTwo, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 23:59:59", loc)
  2332. if err != nil {
  2333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2334. return
  2335. }
  2336. recordDateTimeTwo := theTimeTwo.Unix()
  2337. //var prescriptions []*models.HisPrescription
  2338. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2339. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2340. if settle_accounts_type == 1 { //日结
  2341. record, _ := service.GetInHospitalRecord(his_patient_id)
  2342. infos, _ := service.GetZHHisUploadOrderInfo(adminUser.CurrentOrgId, patient_id, recordDateTime, recordDateTimeTwo, record.Number)
  2343. var isSuccess bool = true
  2344. for _, item := range infos {
  2345. var result string
  2346. var requestLog string
  2347. if miConfig.MdtrtareaAdmvs == "150499" {
  2348. //请求内网数据
  2349. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&feedetl_sn=" + item.FeedetlSn +
  2350. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2351. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "1"
  2352. resp, requestErr := http.Get(api)
  2353. if requestErr != nil {
  2354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2355. return
  2356. }
  2357. body, ioErr := ioutil.ReadAll(resp.Body)
  2358. if ioErr != nil {
  2359. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2361. return
  2362. }
  2363. var respJSON map[string]interface{}
  2364. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2365. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2367. return
  2368. }
  2369. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2370. result_byte, _ := json.Marshal(respJSON)
  2371. result = string(result_byte)
  2372. saveLog(result, requestLog, "2302", "日结退明细")
  2373. } else {
  2374. result, requestLog := service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, item.FeedetlSn, 1)
  2375. saveLog(result, requestLog, "2302", "日结退明细")
  2376. }
  2377. var dat map[string]interface{}
  2378. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2379. fmt.Println(dat)
  2380. } else {
  2381. fmt.Println(err)
  2382. }
  2383. userJSONBytes, _ := json.Marshal(dat)
  2384. var res2 ResultEmpty
  2385. var resEmpty10265 ResultEmpty10265
  2386. if miConfig.Code == "H15049901371" {
  2387. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2388. utils.ErrorLog("解析失败:%v", err)
  2389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2390. return
  2391. }
  2392. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2393. res2.Infcode = Infcode
  2394. res2.RespondTime = resEmpty10265.RespondTime
  2395. res2.ErrMsg = resEmpty10265.ErrMsg
  2396. res2.Output = resEmpty10265.Output
  2397. res2.WarnMsg = resEmpty10265.WarnMsg
  2398. } else {
  2399. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2400. utils.ErrorLog("解析失败:%v", err)
  2401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2402. return
  2403. }
  2404. }
  2405. if res2.Infcode == -1 {
  2406. isSuccess = false
  2407. }
  2408. }
  2409. if isSuccess {
  2410. err := service.UpDateOrderInfoStatus(patient_id, recordDateTime, adminUser.CurrentOrgId, recordDateTimeTwo)
  2411. if err != nil {
  2412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2413. return
  2414. }
  2415. err1 := service.UpDatePrescriptionOrderStatusTwo(patient_id, recordDateTime, adminUser.CurrentOrgId)
  2416. if err1 != nil {
  2417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2418. return
  2419. }
  2420. c.ServeSuccessJSON(map[string]interface{}{
  2421. "msg": "撤销明细成功",
  2422. })
  2423. }
  2424. } else {
  2425. //prescriptions, _ = service.GetZHMonthHisUploadPrescription(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2426. //var order models.HisOrder
  2427. //order, _ = service.GetHisOrderByID(order_id)
  2428. //record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  2429. var result string
  2430. var requestLog string
  2431. record, _ := service.GetInHospitalRecord(his_patient_id)
  2432. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2433. if config.IsOpen == 1 { //对接了医保,走医保流程
  2434. if miConfig.MdtrtareaAdmvs == "150499" {
  2435. //请求内网数据
  2436. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=0000" +
  2437. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2438. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "0"
  2439. resp, requestErr := http.Get(api)
  2440. if requestErr != nil {
  2441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2442. return
  2443. }
  2444. body, ioErr := ioutil.ReadAll(resp.Body)
  2445. if ioErr != nil {
  2446. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2448. return
  2449. }
  2450. var respJSON map[string]interface{}
  2451. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2452. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2454. return
  2455. }
  2456. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2457. result_byte, _ := json.Marshal(respJSON)
  2458. result = string(result_byte)
  2459. //saveLog(result, requestLog, "2302", "日结退明细")
  2460. } else {
  2461. result, requestLog = service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  2462. saveLog(result, requestLog, "2302", "月结退明细")
  2463. }
  2464. var dat map[string]interface{}
  2465. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2466. fmt.Println(dat)
  2467. } else {
  2468. fmt.Println(err)
  2469. }
  2470. userJSONBytes, _ := json.Marshal(dat)
  2471. var res2 ResultEmpty
  2472. var resEmpty10265 ResultEmpty10265
  2473. if miConfig.Code == "H15049901371" {
  2474. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2475. utils.ErrorLog("解析失败:%v", err)
  2476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2477. return
  2478. }
  2479. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2480. res2.Infcode = Infcode
  2481. res2.RespondTime = resEmpty10265.RespondTime
  2482. res2.ErrMsg = resEmpty10265.ErrMsg
  2483. res2.Output = resEmpty10265.Output
  2484. res2.WarnMsg = resEmpty10265.WarnMsg
  2485. } else {
  2486. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2487. utils.ErrorLog("解析失败:%v", err)
  2488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2489. return
  2490. }
  2491. }
  2492. if res2.Infcode == 0 {
  2493. err := service.UpdataHospitalOrderStatus(record.Number, adminUser.CurrentOrgId)
  2494. if err == nil {
  2495. c.ServeSuccessJSON(map[string]interface{}{
  2496. "msg": "撤销明细成功",
  2497. })
  2498. } else {
  2499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2500. return
  2501. }
  2502. } else {
  2503. c.ServeSuccessJSON(map[string]interface{}{
  2504. "code": -10,
  2505. "msg": res2.ErrMsg,
  2506. })
  2507. }
  2508. }
  2509. }
  2510. }
  2511. func (this *ZHHisApiController) GetZHOutHospitalUnCheck() {
  2512. id, _ := this.GetInt64("id")
  2513. admin_user_id, _ := this.GetInt64("admin_user_id")
  2514. adminInfo := this.GetAdminUserInfo()
  2515. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2516. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  2517. record, _ := service.GetInHospitalRecord(id)
  2518. if record.ID == 0 {
  2519. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  2520. return
  2521. }
  2522. var result string
  2523. var requestLog string
  2524. if miConfig.MdtrtareaAdmvs == "150499" {
  2525. //请求内网数据
  2526. api := "http://172.16.13.254:9532/" + "nmyb/2405?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  2527. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  2528. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2529. fmt.Println(api)
  2530. resp, requestErr := http.Get(api)
  2531. if requestErr != nil {
  2532. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2533. return
  2534. }
  2535. body, ioErr := ioutil.ReadAll(resp.Body)
  2536. if ioErr != nil {
  2537. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2538. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2539. return
  2540. }
  2541. var respJSON map[string]interface{}
  2542. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2543. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2544. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2545. return
  2546. }
  2547. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2548. result_byte, _ := json.Marshal(respJSON)
  2549. result = string(result_byte)
  2550. } else {
  2551. result, requestLog = service.ZHGdyb2405(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2552. saveLog(result, requestLog, "2405", "出院登记撤销")
  2553. }
  2554. var dat map[string]interface{}
  2555. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2556. fmt.Println(dat)
  2557. } else {
  2558. fmt.Println(err)
  2559. }
  2560. userJSONBytes, _ := json.Marshal(dat)
  2561. var res ResultEmpty
  2562. var resEmpty10265 ResultEmpty10265
  2563. if miConfig.Code == "H15049901371" {
  2564. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2565. utils.ErrorLog("解析失败:%v", err)
  2566. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2567. return
  2568. }
  2569. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2570. res.Infcode = Infcode
  2571. res.RespondTime = resEmpty10265.RespondTime
  2572. res.ErrMsg = resEmpty10265.ErrMsg
  2573. res.Output = resEmpty10265.Output
  2574. res.WarnMsg = resEmpty10265.WarnMsg
  2575. } else {
  2576. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2577. utils.ErrorLog("解析失败:%v", err)
  2578. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2579. return
  2580. }
  2581. }
  2582. if res.Infcode == 0 {
  2583. record.OutHospitalStatus = 0
  2584. service.CreateHospitalRecord(&record)
  2585. service.UpdataOrderStatusByNumber(record.Number)
  2586. this.ServeSuccessJSON(map[string]interface{}{
  2587. "msg": "撤销出院成功",
  2588. })
  2589. } else {
  2590. this.ServeSuccessJSON(map[string]interface{}{
  2591. "failed_code": -10,
  2592. "msg": res.ErrMsg,
  2593. })
  2594. }
  2595. }
  2596. func (this *ZHHisApiController) GetZHInHospitalUnCheck() {
  2597. id, _ := this.GetInt64("id")
  2598. admin_user_id, _ := this.GetInt64("admin_user_id")
  2599. adminInfo := this.GetAdminUserInfo()
  2600. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2601. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  2602. record, _ := service.GetInHospitalRecord(id)
  2603. if record.ID == 0 {
  2604. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  2605. return
  2606. }
  2607. var result string
  2608. var requestLog string
  2609. orders, _ := service.GetHisOrderInfoByNumber(record.Number)
  2610. if len(orders) > 0 { //判断是否上传过明细,有的话需要退明细,后撤销入院
  2611. if miConfig.MdtrtareaAdmvs == "150499" {
  2612. //请求内网数据
  2613. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=" + "0000" +
  2614. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  2615. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=0"
  2616. resp, requestErr := http.Get(api)
  2617. if requestErr != nil {
  2618. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2619. return
  2620. }
  2621. body, ioErr := ioutil.ReadAll(resp.Body)
  2622. if ioErr != nil {
  2623. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2624. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2625. return
  2626. }
  2627. var respJSON map[string]interface{}
  2628. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2629. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2630. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2631. return
  2632. }
  2633. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2634. result_byte, _ := json.Marshal(respJSON)
  2635. result = string(result_byte)
  2636. saveLog(result, requestLog, "2302", "月结退明细")
  2637. } else {
  2638. result, requestLog = service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  2639. saveLog(result, requestLog, "2302", "月结退明细")
  2640. }
  2641. var dat map[string]interface{}
  2642. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2643. fmt.Println(dat)
  2644. } else {
  2645. fmt.Println(err)
  2646. }
  2647. userJSONBytes, _ := json.Marshal(dat)
  2648. var res2 ResultEmpty
  2649. var resEmpty10265 ResultEmpty10265
  2650. if miConfig.Code == "H15049901371" {
  2651. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2652. utils.ErrorLog("解析失败:%v", err)
  2653. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2654. return
  2655. }
  2656. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2657. res2.Infcode = Infcode
  2658. res2.RespondTime = resEmpty10265.RespondTime
  2659. res2.ErrMsg = resEmpty10265.ErrMsg
  2660. res2.Output = resEmpty10265.Output
  2661. res2.WarnMsg = resEmpty10265.WarnMsg
  2662. } else {
  2663. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2664. utils.ErrorLog("解析失败:%v", err)
  2665. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2666. return
  2667. }
  2668. }
  2669. if res2.Infcode == 0 {
  2670. service.UpdataHospitalOrderStatus(record.Number, adminInfo.CurrentOrgId)
  2671. var result string
  2672. var requestLog string
  2673. if miConfig.MdtrtareaAdmvs == "150499" {
  2674. //请求内网数据
  2675. api := "http://172.16.13.254:9532/" + "nmyb/2404?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  2676. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  2677. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2678. resp, requestErr := http.Get(api)
  2679. if requestErr != nil {
  2680. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2681. return
  2682. }
  2683. body, ioErr := ioutil.ReadAll(resp.Body)
  2684. if ioErr != nil {
  2685. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2686. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2687. return
  2688. }
  2689. var respJSON map[string]interface{}
  2690. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2691. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2692. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2693. return
  2694. }
  2695. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2696. result_byte, _ := json.Marshal(respJSON)
  2697. result = string(result_byte)
  2698. } else {
  2699. result, requestLog = service.ZHGdyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2700. saveLog(result, requestLog, "2404", "入院登记撤销")
  2701. }
  2702. var dat map[string]interface{}
  2703. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2704. fmt.Println(dat)
  2705. } else {
  2706. fmt.Println(err)
  2707. }
  2708. userJSONBytes, _ := json.Marshal(dat)
  2709. var res ResultEmpty
  2710. var resEmpty10265 ResultEmpty10265
  2711. if miConfig.Code == "H15049901371" {
  2712. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2713. utils.ErrorLog("解析失败:%v", err)
  2714. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2715. return
  2716. }
  2717. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2718. res.Infcode = Infcode
  2719. res.RespondTime = resEmpty10265.RespondTime
  2720. res.ErrMsg = resEmpty10265.ErrMsg
  2721. res.Output = resEmpty10265.Output
  2722. res.WarnMsg = resEmpty10265.WarnMsg
  2723. } else {
  2724. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2725. utils.ErrorLog("解析失败:%v", err)
  2726. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2727. return
  2728. }
  2729. }
  2730. if res.Infcode == 0 {
  2731. record.Status = 0
  2732. service.CreateHospitalRecord(&record)
  2733. this.ServeSuccessJSON(map[string]interface{}{
  2734. "msg": "撤销入院成功",
  2735. })
  2736. } else {
  2737. this.ServeSuccessJSON(map[string]interface{}{
  2738. "failed_code": -10,
  2739. "msg": res.ErrMsg,
  2740. })
  2741. }
  2742. } else {
  2743. this.ServeSuccessJSON(map[string]interface{}{
  2744. "code": -10,
  2745. "msg": res2.ErrMsg,
  2746. })
  2747. }
  2748. } else { //没有上传过明细的,直接撤销入院
  2749. var result string
  2750. var requestLog string
  2751. if miConfig.MdtrtareaAdmvs == "150499" {
  2752. //请求内网数据
  2753. api := "http://172.16.13.254:9532/" + "nmyb/2404?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  2754. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  2755. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2756. resp, requestErr := http.Get(api)
  2757. if requestErr != nil {
  2758. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2759. return
  2760. }
  2761. body, ioErr := ioutil.ReadAll(resp.Body)
  2762. if ioErr != nil {
  2763. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2764. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2765. return
  2766. }
  2767. var respJSON map[string]interface{}
  2768. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2769. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2770. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2771. return
  2772. }
  2773. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2774. result_byte, _ := json.Marshal(respJSON)
  2775. result = string(result_byte)
  2776. } else {
  2777. result, requestLog = service.ZHGdyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2778. saveLog(result, requestLog, "2404", "入院登记撤销")
  2779. }
  2780. var dat map[string]interface{}
  2781. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2782. fmt.Println(dat)
  2783. } else {
  2784. fmt.Println(err)
  2785. }
  2786. userJSONBytes, _ := json.Marshal(dat)
  2787. var res ResultEmpty
  2788. var resEmpty10265 ResultEmpty10265
  2789. if miConfig.Code == "H15049901371" {
  2790. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2791. utils.ErrorLog("解析失败:%v", err)
  2792. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2793. return
  2794. }
  2795. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2796. res.Infcode = Infcode
  2797. res.RespondTime = resEmpty10265.RespondTime
  2798. res.ErrMsg = resEmpty10265.ErrMsg
  2799. res.Output = resEmpty10265.Output
  2800. res.WarnMsg = resEmpty10265.WarnMsg
  2801. } else {
  2802. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2803. utils.ErrorLog("解析失败:%v", err)
  2804. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2805. return
  2806. }
  2807. }
  2808. if res.Infcode == 0 {
  2809. record.Status = 0
  2810. service.CreateHospitalRecord(&record)
  2811. this.ServeSuccessJSON(map[string]interface{}{
  2812. "msg": "撤销入院成功",
  2813. })
  2814. } else {
  2815. this.ServeSuccessJSON(map[string]interface{}{
  2816. "failed_code": -10,
  2817. "msg": res.ErrMsg,
  2818. })
  2819. }
  2820. }
  2821. }
  2822. func saveLog(result string, request string, infno string, desc string) {
  2823. org_id, _ := beego.AppConfig.Int64("org_id")
  2824. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  2825. dir := miConfig.OrgName + "日志"
  2826. utils.Mkdir(dir)
  2827. month := time.Unix(1557042972, 0).Format("1")
  2828. year := time.Now().Format("2006")
  2829. month = time.Now().Format("01")
  2830. day := time.Now().Format("02")
  2831. hour := time.Now().Format("15")
  2832. min := time.Now().Format("04")
  2833. sec := time.Now().Format("05")
  2834. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  2835. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  2836. file_name := file + ".txt"
  2837. file_path := miConfig.OrgName + "日志" + "/" + file_name
  2838. exist, _ := utils.PathExists(file_path)
  2839. if exist { //存在
  2840. fmt.Println("存在")
  2841. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  2842. if err != nil {
  2843. fmt.Println("read fail")
  2844. }
  2845. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  2846. n, _ := f.Seek(0, 2)
  2847. _, err = f.WriteAt([]byte(content), n)
  2848. } else { //不存在
  2849. fmt.Println("文件不存在,创建文件")
  2850. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  2851. defer f.Close()
  2852. if err != nil {
  2853. } else {
  2854. _, err = f.Write([]byte("记录日志"))
  2855. }
  2856. }
  2857. }
  2858. type Charset string
  2859. const (
  2860. UTF8 = Charset("UTF-8")
  2861. GB18030 = Charset("GB18030")
  2862. )
  2863. func ConvertToString(src string, srcCode string, tagCode string) string {
  2864. srcCoder := mahonia.NewDecoder(srcCode)
  2865. srcResult := srcCoder.ConvertString(src)
  2866. tagCoder := mahonia.NewDecoder(tagCode)
  2867. _, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
  2868. result := string(cdata)
  2869. return result
  2870. }
  2871. type ELeData struct {
  2872. Data struct {
  2873. IdNo string `json:"idNo"`
  2874. IdType string `json:"idType"`
  2875. UserName string `json:"userName"`
  2876. EcToken string `json:"ecToken"`
  2877. InsuOrg string `json:"insuOrg"`
  2878. Gender string `json:"gender"`
  2879. Birthday string `json:"birthday"`
  2880. Nationality string `json:"nationality"`
  2881. Email string `json:"email"`
  2882. Extra string `json:"extra"`
  2883. } `json:"data"`
  2884. Code int `json:"code"`
  2885. Message string `json:"message"`
  2886. }
  2887. func (c *ZHHisApiController) ReadCard() {
  2888. id_card_type, _ := c.GetInt64("id_card_type")
  2889. admin_user_id, _ := c.GetInt64("admin_user_id")
  2890. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  2891. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  2892. var api string
  2893. api = "http://172.16.13.254:9532/" + "nmyb/readcard?" + "fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName +
  2894. "&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
  2895. fmt.Println(api)
  2896. resp, requestErr := http.Get(api)
  2897. if requestErr != nil {
  2898. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2899. return
  2900. }
  2901. body, ioErr := ioutil.ReadAll(resp.Body)
  2902. if ioErr != nil {
  2903. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2905. return
  2906. }
  2907. var respJSON map[string]interface{}
  2908. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2909. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2910. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2911. return
  2912. }
  2913. var status string
  2914. status = respJSON["data"].(map[string]interface{})["status"].(string)
  2915. card_type := respJSON["data"].(map[string]interface{})["type"].(string)
  2916. //console.log()
  2917. fmt.Println("type===")
  2918. fmt.Println(card_type)
  2919. var token string
  2920. var res ResultTwo //1101结果
  2921. var res10265 ResultTwo10265 //1101结果
  2922. var card_info string //卡信息
  2923. var busi_card_info string
  2924. card_info = respJSON["data"].(map[string]interface{})["card_info"].(string)
  2925. busi_card_info = respJSON["data"].(map[string]interface{})["busi_card_info"].(string)
  2926. if status == "0" { //读卡成功
  2927. if card_type == "1" {
  2928. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  2929. result, _ := json.Marshal(respJSON)
  2930. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  2931. utils.ErrorLog("解析失败:%v", err)
  2932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2933. return
  2934. }
  2935. res.ErrMsg = res10265.ErrMsg
  2936. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  2937. res.Infcode = infocode
  2938. res.Output = res10265.Output
  2939. res.InfRefmsgid = res10265.InfRefmsgid
  2940. } else {
  2941. //var card_info string //卡信息
  2942. //var busi_card_info string
  2943. token = respJSON["data"].(map[string]interface{})["token"].(string)
  2944. //busi_card_info = respJSON["data"].(map[string]interface{})["busi_card_info"].(string)
  2945. //fmt.Println(card_info)
  2946. //fmt.Println(busi_card_info)
  2947. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  2948. result, _ := json.Marshal(respJSON)
  2949. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  2950. utils.ErrorLog("解析失败:%v", err)
  2951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2952. return
  2953. }
  2954. res.ErrMsg = res10265.ErrMsg
  2955. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  2956. res.Infcode = infocode
  2957. res.Output = res10265.Output
  2958. res.InfRefmsgid = res10265.InfRefmsgid
  2959. }
  2960. if res.Infcode == 0 {
  2961. var insutypes []string
  2962. var insutype string
  2963. var is390 int = 0
  2964. var is310 int = 0
  2965. for _, item := range res.Output.Iinfo {
  2966. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  2967. insutypes = append(insutypes, item.Insutype)
  2968. }
  2969. }
  2970. if len(insutypes) == 1 {
  2971. insutype = insutypes[0]
  2972. } else {
  2973. for _, i := range insutypes {
  2974. if i == "390" {
  2975. is390 = 1
  2976. }
  2977. if i == "310" {
  2978. is310 = 1
  2979. }
  2980. }
  2981. }
  2982. if is390 == 1 {
  2983. insutype = "390"
  2984. }
  2985. if is310 == 1 {
  2986. insutype = "310"
  2987. }
  2988. if len(insutypes) == 0 {
  2989. insutype = "310"
  2990. }
  2991. patient, err := service.GetPatientByIDCard(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  2992. if err == gorm.ErrRecordNotFound {
  2993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  2994. return
  2995. } else if err != nil {
  2996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2997. return
  2998. } else {
  2999. if card_type == "1" {
  3000. bas := strings.Split(card_info, "|")
  3001. basNumber := bas[2]
  3002. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  3003. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  3004. infoStr := string(Iinfos)
  3005. idetinfoStr := string(Idetinfos)
  3006. psn := &models.HisPsn{
  3007. PsnNo: res.Output.Baseinfo.PsnNo,
  3008. Age: res.Output.Baseinfo.Age,
  3009. PatientId: patient.ID,
  3010. Certno: res.Output.Baseinfo.Certno,
  3011. Brdy: res.Output.Baseinfo.Brdy,
  3012. Gend: res.Output.Baseinfo.Gend,
  3013. Naty: res.Output.Baseinfo.Naty,
  3014. PsnCertType: res.Output.Baseinfo.PsnCertType,
  3015. PsnName: res.Output.Baseinfo.PsnName,
  3016. Idetinfo: idetinfoStr,
  3017. Insuinfo: infoStr,
  3018. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3019. CardInfo: card_info,
  3020. VerifyNumber: busi_card_info,
  3021. }
  3022. service.CreateHisPsn(psn)
  3023. c.ServeSuccessJSON(map[string]interface{}{
  3024. "patient": patient,
  3025. "number": basNumber,
  3026. "info": res,
  3027. "insutype": insutype,
  3028. })
  3029. } else {
  3030. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  3031. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  3032. infoStr := string(Iinfos)
  3033. idetinfoStr := string(Idetinfos)
  3034. psn := &models.HisPsn{
  3035. PsnNo: res.Output.Baseinfo.PsnNo,
  3036. Age: res.Output.Baseinfo.Age,
  3037. PatientId: patient.ID,
  3038. Certno: res.Output.Baseinfo.Certno,
  3039. Brdy: res.Output.Baseinfo.Brdy,
  3040. Gend: res.Output.Baseinfo.Gend,
  3041. Naty: res.Output.Baseinfo.Naty,
  3042. PsnCertType: res.Output.Baseinfo.PsnCertType,
  3043. PsnName: res.Output.Baseinfo.PsnName,
  3044. Idetinfo: idetinfoStr,
  3045. Insuinfo: infoStr,
  3046. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3047. CardInfo: card_info,
  3048. VerifyNumber: token,
  3049. }
  3050. service.CreateHisPsn(psn)
  3051. c.ServeSuccessJSON(map[string]interface{}{
  3052. "patient": patient,
  3053. "number": token,
  3054. "info": res,
  3055. "insutype": insutype,
  3056. })
  3057. }
  3058. }
  3059. } else {
  3060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  3061. return
  3062. }
  3063. } else { //读卡失败
  3064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  3065. return
  3066. }
  3067. }
  3068. var initFlag int64 = 0
  3069. func (c *ZHHisApiController) TestGetBasBaseInit() {
  3070. DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
  3071. Iinit := DllDef.MustFindProc("Init")
  3072. //miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  3073. str := make([]byte, 2048)
  3074. inputData := make(map[string]interface{})
  3075. inputData["IP"] = "10.144.211.75"
  3076. inputData["PORT"] = 7021
  3077. inputData["TIMEOUT"] = 180
  3078. inputData["LOG_PATH"] = "C:\\log\\"
  3079. //inputData["SFZ_DRIVER_TYPE"] = 0
  3080. inputData["URL"] = "/call1"
  3081. bytesData, _ := json.Marshal(inputData)
  3082. fmt.Println(inputData)
  3083. fmt.Println(bytesData)
  3084. ret, _, err := Iinit.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&str[0])))
  3085. if ret != 0 {
  3086. fmt.Println("SSCard的报错原因:", err)
  3087. fmt.Println("SSCard的运算结果为:", ret)
  3088. fmt.Println("SSCard的返回结果为:", string(str))
  3089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  3090. return
  3091. }
  3092. fmt.Println("SSCard的返回结果为:", string(str))
  3093. result := int(ret)
  3094. fmt.Println("SSCard的运算结果为1:", result)
  3095. //initFlag = 1
  3096. return
  3097. }
  3098. func (c *ZHHisApiController) GetSFZBaseInfo() string {
  3099. DllDef := syscall.MustLoadDLL("SSCard.dll")
  3100. readCard := DllDef.MustFindProc("ReadSFZ")
  3101. if readCard == nil {
  3102. fmt.Println("readcard is nil")
  3103. readCard = DllDef.MustFindProc("ReadSFZ")
  3104. }
  3105. str := make([]byte, 256)
  3106. str1 := make([]byte, 256)
  3107. r, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  3108. fmt.Println(r)
  3109. return string(str)
  3110. }
  3111. func (c *ZHHisApiController) GetBasBaseInfo(fixmedins_code string, mdtrtarea_admvs string, opter_name string, opter_id string, fixmedins_name string) string {
  3112. DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
  3113. readCard := DllDef.MustFindProc("ReadCardBas")
  3114. fmt.Println(readCard)
  3115. fmt.Println("!!!!!")
  3116. month := time.Unix(1557042972, 0).Format("1")
  3117. year := time.Now().Format("2006")
  3118. month = time.Now().Format("01")
  3119. day := time.Now().Format("02")
  3120. hour := time.Now().Format("15")
  3121. min := time.Now().Format("04")
  3122. sec := time.Now().Format("05")
  3123. msec := time.Now().Format("000")
  3124. timestamp := time.Now().Unix()
  3125. tempTime := time.Unix(timestamp, 0)
  3126. //timeFormat := tempTime.Format("20060102150405")
  3127. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  3128. //randNum := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000)
  3129. inputData := make(map[string]interface{})
  3130. inputData["infno"] = "1199"
  3131. //inputData["msgid"] = "7021"
  3132. inputData["msgid"] = fixmedins_code + year + month + day + hour + min + sec + msec + "0" // 发送方报文 ID
  3133. inputData["mdtrtarea_admvs"] = mdtrtarea_admvs // 发送方报文 ID
  3134. inputData["recer_sys_code"] = "01"
  3135. inputData["infver"] = "V1.0"
  3136. inputData["opter_type"] = "1"
  3137. inputData["opter"] = opter_id
  3138. inputData["opter_name"] = opter_name
  3139. inputData["inf_time"] = timeFormatOne
  3140. inputData["fixmedins_code"] = fixmedins_code
  3141. inputData["fixmedins_name"] = fixmedins_name
  3142. inputData["dev_no"] = ""
  3143. inputData["dev_safe_info"] = ""
  3144. inputData["cainfo"] = ""
  3145. inputData["signtype"] = ""
  3146. inputData["sign_no"] = ""
  3147. bytesData, _ := json.Marshal(inputData)
  3148. fmt.Println(string(bytesData))
  3149. pBusiCardInfo := make([]byte, 8192)
  3150. ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
  3151. fmt.Println(ret2)
  3152. fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
  3153. fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
  3154. if ret2 != 0 {
  3155. return ""
  3156. }
  3157. return DeleteExtraSpace(string(pBusiCardInfo))
  3158. }
  3159. func DeleteExtraSpace(s string) string {
  3160. //删除字符串中的多余空格,有多个空格时,仅保留一个空格
  3161. s1 := strings.Replace(s, " ", " ", -1) //替换tab为空格
  3162. regstr := "\\s{2,}" //两个及两个以上空格的正则表达式
  3163. reg, _ := regexp.Compile(regstr) //编译正则表达式
  3164. s2 := make([]byte, len(s1)) //定义字符数组切片
  3165. copy(s2, s1) //将字符串复制到切片
  3166. spc_index := reg.FindStringIndex(string(s2)) //在字符串中搜索
  3167. for len(spc_index) > 0 { //找到适配项
  3168. s2 = append(s2[:spc_index[0]+1], s2[spc_index[1]:]...) //删除多余空格
  3169. spc_index = reg.FindStringIndex(string(s2)) //继续在字符串中搜索
  3170. }
  3171. return string(s2)
  3172. }
  3173. func (c *ZHHisApiController) GetELeInfo(code string, operator_id string, operator_name string) (string, string) {
  3174. DllDef := syscall.MustLoadDLL("NationECCode.dll")
  3175. readCard := DllDef.MustFindProc("NationEcTrans")
  3176. fmt.Println(readCard)
  3177. fmt.Println("!!!!!")
  3178. pBusiCardInfo := make([]byte, 8192)
  3179. input := make(map[string]interface{})
  3180. inputData := make(map[string]interface{})
  3181. inputData["orgId"] = code
  3182. inputData["businessType"] = "01101"
  3183. inputData["operatorId"] = operator_id
  3184. inputData["operatorName"] = operator_name
  3185. inputData["officeId"] = "001"
  3186. inputData["officeName"] = "血透室"
  3187. inputData["deviceType"] = ""
  3188. input["data"] = inputData
  3189. input["orgId"] = code
  3190. input["transType"] = "ec.query"
  3191. bytesData, _ := json.Marshal(input)
  3192. gdyb_url := beego.AppConfig.String("gdyb_url")
  3193. url := gdyb_url + "/localcfc/api/hsecfc/localQrCodeQuery"
  3194. ret2, _, _ := readCard.Call(StrPtr(url), StrPtr(string(bytesData)), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
  3195. fmt.Println(ret2)
  3196. fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
  3197. fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
  3198. if ret2 != 0 {
  3199. return "", ""
  3200. }
  3201. return DeleteExtraSpace(""), DeleteExtraSpace(string(pBusiCardInfo))
  3202. }
  3203. func StrPtr(s string) uintptr {
  3204. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  3205. }
  3206. func Remove0000(s string) string {
  3207. str := make([]rune, 0, len(s))
  3208. for _, v := range []rune(s) {
  3209. if v == 0 {
  3210. continue
  3211. }
  3212. str = append(str, v)
  3213. }
  3214. return string(str)
  3215. }
  3216. func IntPtr(n int) uintptr {
  3217. return uintptr(n)
  3218. }