zh_his_api_controller.go 111KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269
  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 ResultTwo struct {
  30. ErrMsg string `json:"err_msg"`
  31. InfRefmsgid string `json:"inf_refmsgid"`
  32. Infcode int64 `json:"infcode"`
  33. Output struct {
  34. Baseinfo struct {
  35. Age float64 `json:"age"`
  36. Brdy string `json:"brdy"`
  37. Certno string `json:"certno"`
  38. Gend string `json:"gend"`
  39. Naty string `json:"naty"`
  40. PsnCertType string `json:"psn_cert_type"`
  41. PsnName string `json:"psn_name"`
  42. PsnNo string `json:"psn_no"`
  43. } `json:"baseinfo"`
  44. Idetinfo []interface{} `json:"idetinfo"`
  45. Iinfo []struct {
  46. Balc float64 `json:"balc"`
  47. CvlservFlag string `json:"cvlserv_flag"`
  48. EmpName string `json:"emp_name"`
  49. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  50. Insutype string `json:"insutype"`
  51. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  52. PausInsuDate string `json:"paus_insu_date"`
  53. PsnInsuDate string `json:"psn_insu_date"`
  54. PsnInsuStas string `json:"psn_insu_stas"`
  55. PsnType string `json:"psn_type"`
  56. } `json:"insuinfo"`
  57. } `json:"output"`
  58. RefmsgTime string `json:"refmsg_time"`
  59. RespondTime string `json:"respond_time"`
  60. Signtype interface{} `json:"signtype"`
  61. WarnInfo interface{} `json:"warn_info"`
  62. }
  63. type ResultTwo10265 struct {
  64. ErrMsg string `json:"err_msg"`
  65. InfRefmsgid string `json:"inf_refmsgid"`
  66. Infcode string `json:"infcode"`
  67. Output struct {
  68. Baseinfo struct {
  69. Age float64 `json:"age"`
  70. Brdy string `json:"brdy"`
  71. Certno string `json:"certno"`
  72. Gend string `json:"gend"`
  73. Naty string `json:"naty"`
  74. PsnCertType string `json:"psn_cert_type"`
  75. PsnName string `json:"psn_name"`
  76. PsnNo string `json:"psn_no"`
  77. } `json:"baseinfo"`
  78. Idetinfo []interface{} `json:"idetinfo"`
  79. Iinfo []struct {
  80. Balc float64 `json:"balc"`
  81. CvlservFlag string `json:"cvlserv_flag"`
  82. EmpName string `json:"emp_name"`
  83. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  84. Insutype string `json:"insutype"`
  85. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  86. PausInsuDate string `json:"paus_insu_date"`
  87. PsnInsuDate string `json:"psn_insu_date"`
  88. PsnInsuStas string `json:"psn_insu_stas"`
  89. PsnType string `json:"psn_type"`
  90. } `json:"insuinfo"`
  91. } `json:"output"`
  92. RefmsgTime string `json:"refmsg_time"`
  93. RespondTime string `json:"respond_time"`
  94. Signtype interface{} `json:"signtype"`
  95. WarnInfo interface{} `json:"warn_info"`
  96. }
  97. type ResultThree struct {
  98. Cainfo interface{} `json:"cainfo"`
  99. ErrMsg string `json:"err_msg"`
  100. InfRefmsgid string `json:"inf_refmsgid"`
  101. Infcode int64 `json:"infcode"`
  102. Output struct {
  103. Result struct {
  104. MdtrtID string `json:"mdtrt_id"`
  105. } `json:"result"`
  106. } `json:"output"`
  107. RefmsgTime string `json:"refmsg_time"`
  108. RespondTime string `json:"respond_time"`
  109. Signtype interface{} `json:"signtype"`
  110. WarnMsg interface{} `json:"warn_msg"`
  111. }
  112. type ResultThree10265 struct {
  113. Cainfo interface{} `json:"cainfo"`
  114. ErrMsg string `json:"err_msg"`
  115. InfRefmsgid string `json:"inf_refmsgid"`
  116. Infcode string `json:"infcode"`
  117. Output struct {
  118. Result struct {
  119. MdtrtID string `json:"mdtrt_id"`
  120. } `json:"result"`
  121. } `json:"output"`
  122. RefmsgTime string `json:"refmsg_time"`
  123. RespondTime string `json:"respond_time"`
  124. Signtype interface{} `json:"signtype"`
  125. WarnMsg interface{} `json:"warn_msg"`
  126. }
  127. type ResultFour struct {
  128. Cainfo string `json:"cainfo"`
  129. ErrMsg string `json:"err_msg"`
  130. InfRefmsgid string `json:"inf_refmsgid"`
  131. Infcode int64 `json:"infcode"`
  132. Output struct {
  133. Result []struct {
  134. BasMednFlag string `json:"bas_medn_flag"`
  135. ChldMedcFlag string `json:"chld_medc_flag"`
  136. ChrgitmLv string `json:"chrgitm_lv"`
  137. Cnt float64 `json:"cnt"`
  138. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  139. DrtReimFlag string `json:"drt_reim_flag"`
  140. FeedetlSn string `json:"feedetl_sn"`
  141. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  142. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  143. InscpScpAmt float64 `json:"inscp_scp_amt"`
  144. ListSpItemFlag string `json:"list_sp_item_flag"`
  145. LmtUsedFlag string `json:"lmt_used_flag"`
  146. MedChrgitmType string `json:"med_chrgitm_type"`
  147. Memo string `json:"memo"`
  148. OverlmtAmt float64 `json:"overlmt_amt"`
  149. PreselfpayAmt float64 `json:"preselfpay_amt"`
  150. Pric float64 `json:"pric"`
  151. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  152. SelfpayProp float64 `json:"selfpay_prop"`
  153. } `json:"result"`
  154. } `json:"output"`
  155. RefmsgTime string `json:"refmsg_time"`
  156. RespondTime string `json:"respond_time"`
  157. Signtype string `json:"signtype"`
  158. WarnMsg string `json:"warn_msg"`
  159. }
  160. type ResultFour10265 struct {
  161. Cainfo string `json:"cainfo"`
  162. ErrMsg string `json:"err_msg"`
  163. InfRefmsgid string `json:"inf_refmsgid"`
  164. Infcode string `json:"infcode"`
  165. Output struct {
  166. Result []struct {
  167. BasMednFlag string `json:"bas_medn_flag"`
  168. ChldMedcFlag string `json:"chld_medc_flag"`
  169. ChrgitmLv string `json:"chrgitm_lv"`
  170. Cnt float64 `json:"cnt"`
  171. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  172. DrtReimFlag string `json:"drt_reim_flag"`
  173. FeedetlSn string `json:"feedetl_sn"`
  174. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  175. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  176. InscpScpAmt float64 `json:"inscp_scp_amt"`
  177. ListSpItemFlag string `json:"list_sp_item_flag"`
  178. LmtUsedFlag string `json:"lmt_used_flag"`
  179. MedChrgitmType string `json:"med_chrgitm_type"`
  180. Memo string `json:"memo"`
  181. OverlmtAmt float64 `json:"overlmt_amt"`
  182. PreselfpayAmt float64 `json:"preselfpay_amt"`
  183. Pric float64 `json:"pric"`
  184. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  185. SelfpayProp float64 `json:"selfpay_prop"`
  186. } `json:"result"`
  187. } `json:"output"`
  188. RefmsgTime string `json:"refmsg_time"`
  189. RespondTime string `json:"respond_time"`
  190. Signtype string `json:"signtype"`
  191. WarnMsg string `json:"warn_msg"`
  192. }
  193. type ResultFive struct {
  194. Balc float64 `json:"balc"`
  195. CvlservFlag string `json:"cvlserv_flag"`
  196. EmpName string `json:"emp_name"`
  197. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  198. Insutype string `json:"insutype"`
  199. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  200. PausInsuDate string `json:"paus_insu_date"`
  201. PsnInsuDate string `json:"psn_insu_date"`
  202. PsnInsuStas string `json:"psn_insu_stas"`
  203. PsnType string `json:"psn_type"`
  204. }
  205. type ResultSeven struct {
  206. Cainfo string `json:"cainfo"`
  207. ErrMsg string `json:"err_msg"`
  208. InfRefmsgid string `json:"inf_refmsgid"`
  209. Infcode int64 `json:"infcode"`
  210. Output struct {
  211. Setldetail []interface{} `json:"setldetail"`
  212. Setlinfo struct {
  213. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  214. AcctPay float64 `json:"acct_pay"`
  215. ActPayDedc float64 `json:"act_pay_dedc"`
  216. Age float64 `json:"age"`
  217. Balc float64 `json:"balc"`
  218. Brdy string `json:"brdy"`
  219. Certno string `json:"certno"`
  220. ClrOptins string `json:"clr_optins"`
  221. ClrType string `json:"clr_type"`
  222. ClrWay string `json:"clr_way"`
  223. CvlservFlag string `json:"cvlserv_flag"`
  224. CvlservPay float64 `json:"cvlserv_pay"`
  225. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  226. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  227. Gend string `json:"gend"`
  228. HifesPay float64 `json:"hifes_pay"`
  229. HifmiPay float64 `json:"hifmi_pay"`
  230. HifpPay float64 `json:"hifp_pay"`
  231. HospPartAmt float64 `json:"hosp_part_amt"`
  232. InscpScpAmt float64 `json:"inscp_scp_amt"`
  233. Insutype string `json:"insutype"`
  234. MafPay float64 `json:"maf_pay"`
  235. MdtrtCertType string `json:"mdtrt_cert_type"`
  236. HifobPay float64 `json:"hifob_pay"`
  237. MdtrtID string `json:"mdtrt_id"`
  238. MedType string `json:"med_type"`
  239. MedfeeSumamt float64 `json:"medfee_sumamt"`
  240. MedinsSetlID string `json:"medins_setl_id"`
  241. Naty string `json:"naty"`
  242. OthPay float64 `json:"oth_pay"`
  243. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  244. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  245. PreselfpayAmt float64 `json:"preselfpay_amt"`
  246. PsnCashPay float64 `json:"psn_cash_pay"`
  247. PsnCertType string `json:"psn_cert_type"`
  248. PsnName string `json:"psn_name"`
  249. PsnNo string `json:"psn_no"`
  250. PsnPartAmt float64 `json:"psn_part_amt"`
  251. PsnType string `json:"psn_type"`
  252. SetlID string `json:"setl_id"`
  253. SetlTime string `json:"setl_time"`
  254. } `json:"setlinfo"`
  255. } `json:"output"`
  256. RefmsgTime string `json:"refmsg_time"`
  257. RespondTime string `json:"respond_time"`
  258. Signtype interface{} `json:"signtype"`
  259. WarnMsg interface{} `json:"warn_msg"`
  260. }
  261. type ResultSeven10265 struct {
  262. Cainfo string `json:"cainfo"`
  263. ErrMsg string `json:"err_msg"`
  264. InfRefmsgid string `json:"inf_refmsgid"`
  265. Infcode string `json:"infcode"`
  266. Output struct {
  267. Setldetail []interface{} `json:"setldetail"`
  268. Setlinfo struct {
  269. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  270. AcctPay float64 `json:"acct_pay"`
  271. ActPayDedc float64 `json:"act_pay_dedc"`
  272. Age float64 `json:"age"`
  273. Balc float64 `json:"balc"`
  274. Brdy string `json:"brdy"`
  275. Certno string `json:"certno"`
  276. ClrOptins string `json:"clr_optins"`
  277. ClrType string `json:"clr_type"`
  278. ClrWay string `json:"clr_way"`
  279. CvlservFlag string `json:"cvlserv_flag"`
  280. CvlservPay float64 `json:"cvlserv_pay"`
  281. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  282. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  283. Gend string `json:"gend"`
  284. HifesPay float64 `json:"hifes_pay"`
  285. HifmiPay float64 `json:"hifmi_pay"`
  286. HifpPay float64 `json:"hifp_pay"`
  287. HospPartAmt float64 `json:"hosp_part_amt"`
  288. InscpScpAmt float64 `json:"inscp_scp_amt"`
  289. Insutype string `json:"insutype"`
  290. MafPay float64 `json:"maf_pay"`
  291. MdtrtCertType string `json:"mdtrt_cert_type"`
  292. HifobPay float64 `json:"hifob_pay"`
  293. MdtrtID string `json:"mdtrt_id"`
  294. MedType string `json:"med_type"`
  295. MedfeeSumamt float64 `json:"medfee_sumamt"`
  296. MedinsSetlID string `json:"medins_setl_id"`
  297. Naty string `json:"naty"`
  298. OthPay float64 `json:"oth_pay"`
  299. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  300. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  301. PreselfpayAmt float64 `json:"preselfpay_amt"`
  302. PsnCashPay float64 `json:"psn_cash_pay"`
  303. PsnCertType string `json:"psn_cert_type"`
  304. PsnName string `json:"psn_name"`
  305. PsnNo string `json:"psn_no"`
  306. PsnPartAmt float64 `json:"psn_part_amt"`
  307. PsnType string `json:"psn_type"`
  308. SetlID string `json:"setl_id"`
  309. SetlTime string `json:"setl_time"`
  310. } `json:"setlinfo"`
  311. } `json:"output"`
  312. RefmsgTime string `json:"refmsg_time"`
  313. RespondTime string `json:"respond_time"`
  314. Signtype interface{} `json:"signtype"`
  315. WarnMsg interface{} `json:"warn_msg"`
  316. }
  317. type ResultSixteen struct {
  318. Cainfo string `json:"cainfo"`
  319. ErrMsg string `json:"err_msg"`
  320. InfRefmsgid string `json:"inf_refmsgid"`
  321. Infcode int64 `json:"infcode"`
  322. Output struct {
  323. Setldetail []interface{} `json:"setldetail"`
  324. Setlinfo struct {
  325. MdtrtID string `json:"mdtrt_id"`
  326. SetlID string `json:"setl_id"`
  327. ClrOptins string `json:"clr_optins"`
  328. SetlTime string `json:"setl_time"`
  329. MedfeeSumamt float64 `json:"medfee_sumamt"`
  330. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  331. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  332. PreselfpayAmt float64 `json:"preselfpay_amt"`
  333. InscpScpAmt float64 `json:"inscp_scp_amt"`
  334. ActPayDedc float64 `json:"act_pay_dedc"`
  335. HifpPay float64 `json:"hifp_pay"`
  336. PoolPropSe float64 `json:"pool_prop_selfpay"`
  337. Lfpay float64 `json:"selfpay"`
  338. CvlservPay float64 `json:"cvlserv_pay"`
  339. HifesPay float64 `json:"hifes_pay"`
  340. HifmiPay float64 `json:"hifmi_pay"`
  341. HifobPay float64 `json:"hifob_pay"`
  342. MafPay float64 `json:"maf_pay"`
  343. OthPay float64 `json:"oth_pay"`
  344. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  345. PsnPartAmt float64 `json:"psn_part_amt"`
  346. AcctPay float64 `json:"acct_pay"`
  347. Balc float64 `json:"balc"`
  348. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  349. HospPartAmt float64 `json:"hosp_part_amt"`
  350. MedinsSetlID string `json:"medins_setl_id"`
  351. PdnCashPay string `json:"pdn_cash_pay"`
  352. } `json:"setlinfo"`
  353. } `json:"output"`
  354. RefmsgTime string `json:"refmsg_time"`
  355. RespondTime string `json:"respond_time"`
  356. Signtype interface{} `json:"signtype"`
  357. WarnMsg interface{} `json:"warn_msg"`
  358. }
  359. type ResultSixteen10265 struct {
  360. Cainfo string `json:"cainfo"`
  361. ErrMsg string `json:"err_msg"`
  362. InfRefmsgid string `json:"inf_refmsgid"`
  363. Infcode string `json:"infcode"`
  364. Output struct {
  365. Setldetail []interface{} `json:"setldetail"`
  366. Setlinfo struct {
  367. MdtrtID string `json:"mdtrt_id"`
  368. SetlID string `json:"setl_id"`
  369. ClrOptins string `json:"clr_optins"`
  370. SetlTime string `json:"setl_time"`
  371. MedfeeSumamt float64 `json:"medfee_sumamt"`
  372. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  373. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  374. PreselfpayAmt float64 `json:"preselfpay_amt"`
  375. InscpScpAmt float64 `json:"inscp_scp_amt"`
  376. ActPayDedc float64 `json:"act_pay_dedc"`
  377. HifpPay float64 `json:"hifp_pay"`
  378. PoolPropSe float64 `json:"pool_prop_selfpay"`
  379. Lfpay float64 `json:"selfpay"`
  380. CvlservPay float64 `json:"cvlserv_pay"`
  381. HifesPay float64 `json:"hifes_pay"`
  382. HifmiPay float64 `json:"hifmi_pay"`
  383. HifobPay float64 `json:"hifob_pay"`
  384. MafPay float64 `json:"maf_pay"`
  385. OthPay float64 `json:"oth_pay"`
  386. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  387. PsnPartAmt float64 `json:"psn_part_amt"`
  388. AcctPay float64 `json:"acct_pay"`
  389. Balc float64 `json:"balc"`
  390. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  391. HospPartAmt float64 `json:"hosp_part_amt"`
  392. MedinsSetlID string `json:"medins_setl_id"`
  393. PdnCashPay string `json:"pdn_cash_pay"`
  394. } `json:"setlinfo"`
  395. } `json:"output"`
  396. RefmsgTime string `json:"refmsg_time"`
  397. RespondTime string `json:"respond_time"`
  398. Signtype interface{} `json:"signtype"`
  399. WarnMsg interface{} `json:"warn_msg"`
  400. }
  401. type Custom struct {
  402. DetItemFeeSumamt string
  403. Cut string
  404. FeedetlSn string
  405. Price string
  406. MedListCodg string
  407. Type int64
  408. AdviceId int64
  409. ProjectId int64
  410. ItemId int64
  411. }
  412. type ResultEmpty struct {
  413. Cainfo interface{} `json:"cainfo"`
  414. ErrMsg string `json:"err_msg"`
  415. InfRefmsgid string `json:"inf_refmsgid"`
  416. Infcode int64 `json:"infcode"`
  417. Output struct {
  418. } `json:"output"`
  419. RefmsgTime string `json:"refmsg_time"`
  420. RespondTime string `json:"respond_time"`
  421. Signtype interface{} `json:"signtype"`
  422. WarnMsg interface{} `json:"warn_msg"`
  423. }
  424. type ResultEmpty10265 struct {
  425. Cainfo interface{} `json:"cainfo"`
  426. ErrMsg string `json:"err_msg"`
  427. InfRefmsgid string `json:"inf_refmsgid"`
  428. Infcode string `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 CustomResult struct {
  437. BasMednFlag string `json:"bas_medn_flag"`
  438. ChldMedcFlag string `json:"chld_medc_flag"`
  439. ChrgitmLv string `json:"chrgitm_lv"`
  440. Cnt float64 `json:"cnt"`
  441. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  442. DrtReimFlag string `json:"drt_reim_flag"`
  443. FeedetlSn string `json:"feedetl_sn"`
  444. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  445. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  446. InscpScpAmt float64 `json:"inscp_scp_amt"`
  447. ListSpItemFlag string `json:"list_sp_item_flag"`
  448. LmtUsedFlag string `json:"lmt_used_flag"`
  449. MedChrgitmType string `json:"med_chrgitm_type"`
  450. Memo string `json:"memo"`
  451. OverlmtAmt float64 `json:"overlmt_amt"`
  452. PreselfpayAmt float64 `json:"preselfpay_amt"`
  453. Pric float64 `json:"pric"`
  454. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  455. SelfpayProp float64 `json:"selfpay_prop"`
  456. }
  457. func ZHHisManagerApiRegistRouters() {
  458. beego.Router("/zh/api/inhopitalcheck/get", &ZHHisApiController{}, "get:GetZHInHospitalCheck")
  459. beego.Router("/zh/api/outhopitalcheck/get", &ZHHisApiController{}, "get:GetZHOutHospitalCheck")
  460. beego.Router("/zh/api/uploadinfo/get", &ZHHisApiController{}, "get:GetUploadInfo")
  461. beego.Router("/zh/api/presettle/get", &ZHHisApiController{}, "get:GetPreSettleInfo")
  462. beego.Router("/zh/api/settle/get", &ZHHisApiController{}, "get:GetSettleInfo")
  463. beego.Router("/zh/api/inthopitaluncheck/get", &ZHHisApiController{}, "get:GetZHInHospitalUnCheck")
  464. beego.Router("/zh/api/outhopitaluncheck/get", &ZHHisApiController{}, "get:GetZHOutHospitalUnCheck")
  465. beego.Router("/zh/api/refund", &ZHHisApiController{}, "get:ZHRefund")
  466. beego.Router("/zh/api/refunddetail", &ZHHisApiController{}, "get:ZHRefundDetail")
  467. beego.Router("/zh/api/patient/info", &ZHHisApiController{}, "get:GetZHPatientInfo")
  468. beego.Router("/zh/api/readcard", &ZHHisApiController{}, "get:ReadCard")
  469. }
  470. func (c *ZHHisApiController) GetZHPatientInfo() {
  471. id_card_no := c.GetString("id_card_no")
  472. admin_user_id, _ := c.GetInt64("admin_user_id")
  473. patient, _ := service.GetPatientByIDCard(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  474. if patient.ID == 0 {
  475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  476. return
  477. }
  478. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  479. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  480. config, _ := service.GetMedicalInsuranceConfig(c.GetAdminUserInfo().CurrentOrgId)
  481. if config.IsOpen == 1 {
  482. var result string
  483. var request_log string
  484. var result_log string
  485. if miConfig.MdtrtareaAdmvs == "150499" {
  486. //请求内网数据
  487. api := "http://172.16.13.254:9532/" + "nmyb/1101?cert_no=" + patient.IdCardNo +
  488. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  489. "&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
  490. resp, requestErr := http.Get(api)
  491. if requestErr != nil {
  492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  493. return
  494. }
  495. body, ioErr := ioutil.ReadAll(resp.Body)
  496. if ioErr != nil {
  497. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  499. return
  500. }
  501. var respJSON map[string]interface{}
  502. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  503. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  505. return
  506. }
  507. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  508. result_byte, _ := json.Marshal(respJSON)
  509. result = string(result_byte)
  510. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  511. } else {
  512. 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)
  513. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  514. }
  515. //result := service.Gdyb1101A(id_card_no, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, patient.Name)
  516. var dat map[string]interface{}
  517. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  518. fmt.Println(dat)
  519. } else {
  520. fmt.Println(err)
  521. }
  522. userJSONBytes, _ := json.Marshal(dat)
  523. var res ResultTwo
  524. var resTwo10265 ResultTwo10265
  525. if miConfig.Code == "H15049901371" {
  526. if err := json.Unmarshal(userJSONBytes, &resTwo10265); err != nil {
  527. utils.ErrorLog("解析失败:%v", err)
  528. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  529. return
  530. }
  531. Infcode, _ := strconv.ParseInt(resTwo10265.Infcode, 10, 64)
  532. res.Infcode = Infcode
  533. res.ErrMsg = resTwo10265.ErrMsg
  534. res.Output = resTwo10265.Output
  535. res.InfRefmsgid = resTwo10265.InfRefmsgid
  536. res.RespondTime = resTwo10265.RespondTime
  537. res.WarnInfo = resTwo10265.WarnInfo
  538. } else {
  539. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  540. utils.ErrorLog("解析失败:%v", err)
  541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  542. return
  543. }
  544. }
  545. var insutypes []string
  546. var insutype string
  547. var is390 int = 0
  548. var is310 int = 0
  549. for _, item := range res.Output.Iinfo {
  550. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  551. insutypes = append(insutypes, item.Insutype)
  552. }
  553. }
  554. if len(insutypes) == 1 {
  555. insutype = insutypes[0]
  556. } else {
  557. for _, i := range insutypes {
  558. if i == "390" {
  559. is390 = 1
  560. }
  561. if i == "310" {
  562. is310 = 1
  563. }
  564. }
  565. }
  566. if is390 == 1 {
  567. insutype = "390"
  568. }
  569. if is310 == 1 {
  570. insutype = "310"
  571. }
  572. if len(insutypes) == 0 {
  573. insutype = "310"
  574. }
  575. if res.Infcode != 0 {
  576. c.ServeSuccessJSON(map[string]interface{}{
  577. "failed_code": -10,
  578. "msg": res.ErrMsg,
  579. })
  580. } else {
  581. c.ServeSuccessJSON(map[string]interface{}{
  582. "failed_code": 0,
  583. "info": res,
  584. "insutype": insutype,
  585. })
  586. }
  587. }
  588. }
  589. func (c *ZHHisApiController) GetZHInHospitalCheck() {
  590. id, _ := c.GetInt64("id")
  591. record_time := c.GetString("record_time")
  592. name := c.GetString("name")
  593. phone := c.GetString("phone")
  594. id_card_type, _ := c.GetInt64("id_card_type")
  595. certificates, _ := c.GetInt64("certificates")
  596. id_card_no := c.GetString("id_card_no")
  597. doctor, _ := c.GetInt64("doctor")
  598. admin_user_id, _ := c.GetInt64("admin_user_id")
  599. department, _ := c.GetInt64("department")
  600. adm_bed, _ := c.GetInt64("adm_bed")
  601. diagnosis_ids := c.GetString("diagnosis")
  602. sick_type, _ := c.GetInt64("sick_type")
  603. start_time := c.GetString("start_time")
  604. insuplc_admdvs := c.GetString("insuplc_admdvs")
  605. balance_accounts_type, _ := c.GetInt64("balance_accounts_type")
  606. social_type, _ := c.GetInt64("social_type")
  607. psn_type, _ := c.GetInt64("psn_type")
  608. //reg_type, _ := c.GetInt64("p_type")
  609. med_type, _ := c.GetInt64("med_type")
  610. diagnosis_ids_arr := strings.Split(diagnosis_ids, "-")
  611. timeLayout := "2006-01-02"
  612. loc, _ := time.LoadLocation("Local")
  613. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  614. if err != nil {
  615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  616. return
  617. }
  618. recordDateTime := theTime.Unix()
  619. adminInfo := c.GetAdminUserInfo()
  620. record, _ := service.GetLastHospitalRecord(id, adminInfo.CurrentOrgId)
  621. if record.ID != 0 {
  622. if record.InHospitalStatus == 1 && record.OutHospitalStatus != 1 {
  623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalExistDataException)
  624. return
  625. }
  626. }
  627. var patient service.Patients
  628. if id == 0 {
  629. patient, _ = service.GetPatientByIDCard(id_card_no, adminInfo.CurrentOrgId)
  630. } else {
  631. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  632. }
  633. diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  634. sickConfig, _ := service.FindSickById(sick_type)
  635. departmentInfo, _ := service.GetDepartMentDetail(department)
  636. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  637. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  638. var result string
  639. var request_log string
  640. var result_log string
  641. var res2 ResultTwo
  642. var resTwo10265 ResultTwo10265
  643. psn_info, _ := service.GetPsnByPatientId(patient.ID)
  644. if miConfig.MdtrtareaAdmvs == "150499" {
  645. if id_card_type == 1 {
  646. //请求内网数据
  647. api := "http://172.16.13.254:9532/" + "nmyb/1101?cert_no=" + patient.IdCardNo +
  648. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  649. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(id_card_type, 10) + "&card_sn=" + "" + "&certificates=" + strconv.FormatInt(certificates, 10) + "&name=" + patient.Name
  650. resp, requestErr := http.Get(api)
  651. if requestErr != nil {
  652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  653. return
  654. }
  655. body, ioErr := ioutil.ReadAll(resp.Body)
  656. if ioErr != nil {
  657. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  659. return
  660. }
  661. var respJSON map[string]interface{}
  662. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  663. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  665. return
  666. }
  667. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  668. result_byte, _ := json.Marshal(respJSON)
  669. result = string(result_byte)
  670. var dat map[string]interface{}
  671. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  672. fmt.Println(dat)
  673. } else {
  674. fmt.Println(err)
  675. }
  676. userJSONBytes, _ := json.Marshal(dat)
  677. if err := json.Unmarshal(userJSONBytes, &resTwo10265); err != nil {
  678. utils.ErrorLog("解析失败:%v", err)
  679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  680. return
  681. }
  682. Infcode, _ := strconv.ParseInt(resTwo10265.Infcode, 10, 64)
  683. res2.Infcode = Infcode
  684. res2.ErrMsg = resTwo10265.ErrMsg
  685. res2.Output = resTwo10265.Output
  686. res2.InfRefmsgid = resTwo10265.InfRefmsgid
  687. res2.RespondTime = resTwo10265.RespondTime
  688. res2.WarnInfo = resTwo10265.WarnInfo
  689. } else {
  690. res2.Infcode = 0
  691. res2.Output.Baseinfo.PsnNo = psn_info.PsnNo
  692. res2.Output.Baseinfo.Certno = patient.IdCardNo
  693. }
  694. } else {
  695. 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)
  696. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  697. }
  698. doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor)
  699. deviceNumber, _ := service.GetDeviceNumberByID(adm_bed, adminInfo.CurrentOrgId)
  700. if miConfig.MdtrtareaAdmvs != "150499" {
  701. var dat map[string]interface{}
  702. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  703. fmt.Println(dat)
  704. } else {
  705. fmt.Println(err)
  706. }
  707. userJSONBytes, _ := json.Marshal(dat)
  708. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  709. utils.ErrorLog("解析失败:%v", err)
  710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  711. return
  712. }
  713. }
  714. var infoStr string
  715. if miConfig.MdtrtareaAdmvs == "150499" {
  716. if id_card_type == 1 {
  717. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  718. infoStr = string(Iinfos)
  719. } else {
  720. infoStr = psn_info.Insuinfo
  721. }
  722. } else {
  723. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  724. infoStr = string(Iinfos)
  725. }
  726. var rf []*ResultFive
  727. json.Unmarshal([]byte(infoStr), &rf)
  728. var insutypes []*ResultFive
  729. var insutype string
  730. var is390 int = 0
  731. var is310 int = 0
  732. for _, item := range rf {
  733. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  734. insutypes = append(insutypes, item)
  735. }
  736. }
  737. if len(insutypes) == 1 {
  738. insutype = insutypes[0].Insutype
  739. //insuplc_admdvs = insutypes[0].InsuplcAdmdvs
  740. } else {
  741. for _, i := range insutypes {
  742. if i.Insutype == "390" {
  743. is390 = 1
  744. }
  745. if i.Insutype == "310" {
  746. is310 = 1
  747. }
  748. }
  749. }
  750. if is390 == 1 {
  751. insutype = "390"
  752. }
  753. if is310 == 1 {
  754. insutype = "310"
  755. }
  756. if len(insutypes) == 0 {
  757. insutype = "310"
  758. }
  759. if len(insutypes) == 2 {
  760. insutype = strconv.FormatInt(social_type, 10)
  761. }
  762. //for _, item := range rf {
  763. // if item.Insutype == insutype {
  764. // insuplc_admdvs = item.InsuplcAdmdvs
  765. // }
  766. //}
  767. if res2.Infcode == 0 {
  768. //var insutypes []string
  769. //
  770. //var insutype string
  771. //var is390 int = 0
  772. //var is310 int = 0
  773. //for _, item := range res2.Output.Iinfo {
  774. // if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  775. // insutypes = append(insutypes, item.Insutype)
  776. // }
  777. //}
  778. //if len(insutypes) == 1 {
  779. // insutype = insutypes[0]
  780. //} else {
  781. // for _, i := range insutypes {
  782. // if i == "390" {
  783. // is390 = 1
  784. // }
  785. //
  786. // if i == "310" {
  787. // is310 = 1
  788. // }
  789. // }
  790. //}
  791. //if is390 == 1 {
  792. // insutype = "390"
  793. //}
  794. //if is310 == 1 {
  795. // insutype = "310"
  796. //}
  797. //
  798. //if len(insutypes) == 0 {
  799. // insutype = "310"
  800. //}
  801. if len(insuplc_admdvs) == 0 {
  802. insuplc_admdvs = miConfig.InsuplcAdmdvs
  803. }
  804. timestamp := time.Now().Unix()
  805. tempTime := time.Unix(timestamp, 0)
  806. timeFormat := tempTime.Format("20060102150405")
  807. chrgBchno := rand.Intn(100000) + 10000
  808. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(id, 10)
  809. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  810. var struct2401 service.Struct2401
  811. struct2401.PsnNo = res2.Output.Baseinfo.PsnNo
  812. struct2401.Insutype = insutype
  813. struct2401.MdtrtCertType = "02"
  814. struct2401.MdtrtCertNo = res2.Output.Baseinfo.Certno
  815. if miConfig.Code == "H15049901371" {
  816. if med_type == 14 {
  817. if insutype == "390" {
  818. struct2401.MedType = "9933"
  819. } else if insutype == "310" {
  820. struct2401.MedType = "990502"
  821. }
  822. } else if med_type == 11 {
  823. struct2401.MedType = "11"
  824. }
  825. } else {
  826. struct2401.MedType = strconv.FormatInt(int64(med_type), 10)
  827. }
  828. struct2401.IptNo = ipt_otp_no
  829. struct2401.AtddrNo = strconv.FormatInt(int64(doctorInfo.AdminUserId), 10)
  830. struct2401.ChfpdrName = doctorInfo.UserName
  831. struct2401.AdmDiagDscr = diagnosisConfig[0].ClassName
  832. struct2401.AdmDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  833. struct2401.AdmDeptName = departmentInfo.Name
  834. struct2401.AdmBed = deviceNumber.Number
  835. struct2401.AdmBed = "待定"
  836. struct2401.DscgMaindiagName = diagnosisConfig[0].ClassName
  837. struct2401.DscgMaindiagCode = diagnosisConfig[0].CountryCode
  838. struct2401.Begntime = start_time
  839. struct2401.DiseCodg = sickConfig.CountryCode
  840. struct2401.DiseName = sickConfig.ClassName
  841. var dises []service.DiseinfoStruct
  842. for index, item := range diagnosisConfig {
  843. var dise service.DiseinfoStruct
  844. dise.PsnNo = res2.Output.Baseinfo.PsnNo
  845. dise.DiagType = "1"
  846. if index == 0 {
  847. dise.MaindiagFlag = "1"
  848. } else {
  849. dise.MaindiagFlag = "2"
  850. }
  851. dise.DiagSrtNo = strconv.FormatInt(int64(index), 10)
  852. dise.DiseDorName = doctorInfo.UserName
  853. dise.DiagCode = item.CountryCode
  854. dise.DiagName = item.ClassName
  855. dise.DiagDept = departmentInfo.Name
  856. dise.DiseDorNo = strconv.FormatInt(int64(doctorInfo.AdminUserId), 10)
  857. dise.DiagTime = timeFormatOne
  858. dises = append(dises, dise)
  859. }
  860. struct2401.Diseinfo = dises
  861. var result string
  862. var request_log string
  863. if miConfig.MdtrtareaAdmvs == "150499" {
  864. data := make(map[string]interface{})
  865. data["org_name"] = miConfig.OrgName
  866. data["doctor"] = role.UserName
  867. data["fixmedins_code"] = miConfig.Code
  868. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  869. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  870. data["secret_key"] = miConfig.SecretKey
  871. data["struct_2401"] = struct2401
  872. var req *http.Request
  873. bytesData, _ := json.Marshal(data)
  874. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2401", bytes.NewReader(bytesData))
  875. client := &http.Client{}
  876. resp, _ := client.Do(req)
  877. defer resp.Body.Close()
  878. body, ioErr := ioutil.ReadAll(resp.Body)
  879. if ioErr != nil {
  880. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  882. return
  883. }
  884. var respJSON map[string]interface{}
  885. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  886. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  888. return
  889. }
  890. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  891. result_byte, _ := json.Marshal(respJSON)
  892. result = string(result_byte)
  893. } else {
  894. result, request_log = service.ZHGdyb2401(struct2401, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, insuplc_admdvs, miConfig.MdtrtareaAdmvs)
  895. saveLog(result, request_log, "2401", "入院登记")
  896. }
  897. var dat map[string]interface{}
  898. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  899. fmt.Println(dat)
  900. } else {
  901. fmt.Println(err)
  902. }
  903. userJSONBytes, _ := json.Marshal(dat)
  904. var res ResultThree
  905. var resThree10265 ResultThree10265
  906. if miConfig.Code == "H15049901371" {
  907. if err := json.Unmarshal(userJSONBytes, &resThree10265); err != nil {
  908. utils.ErrorLog("解析失败:%v", err)
  909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  910. return
  911. }
  912. Infcode, _ := strconv.ParseInt(resThree10265.Infcode, 10, 64)
  913. res.Infcode = Infcode
  914. res.ErrMsg = resThree10265.ErrMsg
  915. res.Output = resThree10265.Output
  916. res.InfRefmsgid = resThree10265.InfRefmsgid
  917. res.RespondTime = resThree10265.RespondTime
  918. } else {
  919. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  920. utils.ErrorLog("解析失败:%v", err)
  921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  922. return
  923. }
  924. }
  925. if res.Infcode == 0 {
  926. //result2 := service.Gdyb5301Two(res2.Output.Baseinfo.PsnNo, miConfig.OrgName, role.UserName, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  927. //fmt.Println(result2)
  928. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  929. Idetinfos, _ := json.Marshal(res2.Output.Idetinfo)
  930. infoStr := string(Iinfos)
  931. idetinfoStr := string(Idetinfos)
  932. inHospital := &models.HisHospitalCheckRecord{
  933. PatientId: id,
  934. Name: name,
  935. MedicalTreatmentType: med_type,
  936. RecordDate: recordDateTime,
  937. IdCardNo: id_card_no,
  938. AdminUserId: admin_user_id,
  939. Departments: department,
  940. UserOrgId: adminInfo.CurrentOrgId,
  941. Status: 1,
  942. Ctime: time.Now().Unix(),
  943. Mtime: time.Now().Unix(),
  944. Number: res.Output.Result.MdtrtID,
  945. Doctor: doctor,
  946. PsnNo: res2.Output.Baseinfo.PsnNo,
  947. PsnCertType: res2.Output.Baseinfo.PsnCertType,
  948. Certno: res2.Output.Baseinfo.Certno,
  949. PsnName: res2.Output.Baseinfo.PsnName,
  950. Gend: res2.Output.Baseinfo.Gend,
  951. Naty: res2.Output.Baseinfo.Naty,
  952. MedType: med_type,
  953. InsutypeType: insutype,
  954. Brdy: res2.Output.Baseinfo.Brdy,
  955. Iinfo: infoStr,
  956. Idetinfo: idetinfoStr,
  957. IptOtpNo: ipt_otp_no,
  958. AdmBed: adm_bed,
  959. IdCardType: id_card_type,
  960. Diagnosis: diagnosis_ids,
  961. SickType: sick_type,
  962. MdtrtCertType: "02",
  963. InHosptialTime: start_time,
  964. OutHosptialTime: "",
  965. InHospitalStatus: 1,
  966. Certificates: certificates,
  967. Phone: phone,
  968. BalanceAccountsType: balance_accounts_type,
  969. PsnType: psn_type,
  970. InsuplcAdmdvs: insuplc_admdvs,
  971. }
  972. service.CreateHospitalRecord(inHospital)
  973. c.ServeSuccessJSON(map[string]interface{}{
  974. "msg": "办理入院成功",
  975. "info": inHospital,
  976. })
  977. } else {
  978. c.ServeSuccessJSON(map[string]interface{}{
  979. "failed_code": -10,
  980. "msg": res.ErrMsg,
  981. })
  982. }
  983. } else {
  984. c.ServeSuccessJSON(map[string]interface{}{
  985. "failed_code": -10,
  986. "msg": res2.ErrMsg,
  987. })
  988. return
  989. }
  990. }
  991. func (this *ZHHisApiController) GetZHOutHospitalCheck() {
  992. id, _ := this.GetInt64("id")
  993. patient_id, _ := this.GetInt64("patient_id")
  994. admin_user_id, _ := this.GetInt64("admin_user_id")
  995. record_time := this.GetString("record_time")
  996. out_time := this.GetString("out_time")
  997. adminInfo := this.GetAdminUserInfo()
  998. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  999. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1000. record, _ := service.GetInHospitalRecord(id)
  1001. if record.ID == 0 {
  1002. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  1003. return
  1004. }
  1005. timeLayout := "2006-01-02"
  1006. loc, _ := time.LoadLocation("Local")
  1007. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1008. if err != nil {
  1009. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1010. return
  1011. }
  1012. recordDateTime := theTime.Unix()
  1013. var patient service.Patients
  1014. if patient_id == 0 {
  1015. patient, _ = service.GetPatientByIDCard(record.IdCardNo, adminInfo.CurrentOrgId)
  1016. } else {
  1017. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  1018. }
  1019. fmt.Println(patient)
  1020. diagnosis_ids_arr := strings.Split(record.Diagnosis, "-")
  1021. diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  1022. departmentInfo, _ := service.GetDepartMentDetail(record.Departments)
  1023. doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, record.Doctor)
  1024. //deviceNumber, _ := service.GetDeviceNumberByID(record.AdmBed, adminInfo.CurrentOrgId)
  1025. sickConfig, _ := service.FindSickById(record.SickType)
  1026. var struct2402 service.Struct2402
  1027. timestamp := time.Now().Unix()
  1028. tempTime := time.Unix(timestamp, 0)
  1029. //timeFormat := tempTime.Format("20060102150405")
  1030. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  1031. struct2402.PsnNo = record.PsnNo
  1032. struct2402.Insutype = record.InsutypeType
  1033. struct2402.DscgWay = "1"
  1034. struct2402.Endtime = out_time
  1035. struct2402.DscgDeptName = departmentInfo.Number
  1036. struct2402.DscgDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  1037. struct2402.MdtrtId = record.Number
  1038. var dises []service.Diseinfo2402Struct
  1039. for index, item := range diagnosisConfig {
  1040. var dise service.Diseinfo2402Struct
  1041. dise.PsnNo = record.PsnNo
  1042. dise.DiagType = "1"
  1043. if index == 0 {
  1044. dise.MaindiagFlag = "1"
  1045. } else {
  1046. dise.MaindiagFlag = "2"
  1047. }
  1048. dise.MdtrtId = record.Number
  1049. dise.DiagSrtNo = strconv.FormatInt(int64(item.ID), 10)
  1050. dise.DiseDorName = doctorInfo.UserName
  1051. dise.DiagCode = item.CountryCode
  1052. dise.DiagName = item.ClassName
  1053. dise.DiagDept = departmentInfo.Name
  1054. dise.DiseDorNo = strconv.FormatInt(int64(doctorInfo.AdminUserId), 10)
  1055. dise.DiagTime = timeFormatOne
  1056. dises = append(dises, dise)
  1057. }
  1058. struct2402.Diseinfo = dises
  1059. struct2402.DiseName = sickConfig.ClassName
  1060. struct2402.DiseCode = sickConfig.CountryCode
  1061. var result string
  1062. var request_log string
  1063. if miConfig.MdtrtareaAdmvs == "150499" {
  1064. data := make(map[string]interface{})
  1065. data["org_name"] = miConfig.OrgName
  1066. data["doctor"] = role.UserName
  1067. data["fixmedins_code"] = miConfig.Code
  1068. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1069. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1070. data["secret_key"] = miConfig.SecretKey
  1071. data["struct_2402"] = struct2402
  1072. var req *http.Request
  1073. bytesData, _ := json.Marshal(data)
  1074. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2402", bytes.NewReader(bytesData))
  1075. client := &http.Client{}
  1076. resp, _ := client.Do(req)
  1077. defer resp.Body.Close()
  1078. body, ioErr := ioutil.ReadAll(resp.Body)
  1079. if ioErr != nil {
  1080. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1081. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1082. return
  1083. }
  1084. var respJSON map[string]interface{}
  1085. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1086. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1087. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1088. return
  1089. }
  1090. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1091. result_byte, _ := json.Marshal(respJSON)
  1092. result = string(result_byte)
  1093. } else {
  1094. result, request_log = service.ZHGdyb2402(struct2402, miConfig.OrgName, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  1095. saveLog(result, request_log, "2402", "出院")
  1096. }
  1097. var dat map[string]interface{}
  1098. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1099. fmt.Println(dat)
  1100. } else {
  1101. fmt.Println(err)
  1102. }
  1103. userJSONBytes, _ := json.Marshal(dat)
  1104. var res ResultEmpty
  1105. var resEmpty10265 ResultEmpty10265
  1106. if miConfig.Code == "H15049901371" {
  1107. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  1108. utils.ErrorLog("解析失败:%v", err)
  1109. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1110. return
  1111. }
  1112. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  1113. res.Infcode = Infcode
  1114. res.RespondTime = resEmpty10265.RespondTime
  1115. res.ErrMsg = resEmpty10265.ErrMsg
  1116. res.Output = resEmpty10265.Output
  1117. res.WarnMsg = resEmpty10265.WarnMsg
  1118. } else {
  1119. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1120. utils.ErrorLog("解析失败:%v", err)
  1121. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1122. return
  1123. }
  1124. }
  1125. if res.Infcode == 0 {
  1126. record.OutHospitalStatus = 1
  1127. record.OutHosptialTime = struct2402.Endtime
  1128. record.OutWay = 1
  1129. service.CreateHospitalRecord(&record)
  1130. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  1131. var total float64
  1132. for _, item := range orders {
  1133. total = total + item.DetItemFeeSumamt
  1134. }
  1135. order := &models.HisOrder{
  1136. UserOrgId: adminInfo.CurrentOrgId,
  1137. HisPatientId: record.ID,
  1138. PatientId: record.PatientId,
  1139. SettleAccountsDate: recordDateTime,
  1140. Ctime: time.Now().Unix(),
  1141. Mtime: time.Now().Unix(),
  1142. Status: 1,
  1143. Number: record.Number,
  1144. Infcode: 0,
  1145. WarnMsg: "",
  1146. Cainfo: "",
  1147. ErrMsg: "",
  1148. RespondTime: "",
  1149. InfRefmsgid: "",
  1150. OrderStatus: 1,
  1151. MdtrtId: record.Number,
  1152. IsMedicineInsurance: 1,
  1153. PType: 1,
  1154. MedfeeSumamt: total,
  1155. }
  1156. err = service.CreateOrder(order)
  1157. if err != nil {
  1158. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1159. return
  1160. }
  1161. this.ServeSuccessJSON(map[string]interface{}{
  1162. "msg": "出院成功",
  1163. })
  1164. } else {
  1165. this.ServeSuccessJSON(map[string]interface{}{
  1166. "failed_code": -10,
  1167. "msg": res.ErrMsg,
  1168. })
  1169. }
  1170. }
  1171. func (c *ZHHisApiController) GetSettleInfo() {
  1172. order_id, _ := c.GetInt64("order_id")
  1173. patient_id, _ := c.GetInt64("patient_id")
  1174. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  1175. admin_user_id, _ := c.GetInt64("admin_user_id")
  1176. pay_way, _ := c.GetInt64("pay_way")
  1177. pay_price, _ := c.GetFloat("pay_price")
  1178. pay_card_no := c.GetString("pay_card_no")
  1179. discount_price, _ := c.GetFloat("discount_price")
  1180. preferential_price, _ := c.GetFloat("preferential_price")
  1181. reality_price, _ := c.GetFloat("reality_price")
  1182. found_price, _ := c.GetFloat("found_price")
  1183. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1184. private_price, _ := c.GetFloat("private_price")
  1185. fapiao_code := c.GetString("fapiao_code")
  1186. fapiao_number := c.GetString("fapiao_number")
  1187. record, _ := service.GetInHospitalRecord(in_hospital_id)
  1188. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  1189. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  1190. order, _ := service.GetHisOrderByID(order_id)
  1191. var rf []*ResultFive
  1192. json.Unmarshal([]byte(record.Iinfo), &rf)
  1193. chrg_bchno := order.Number
  1194. cert_no := record.Certno
  1195. if record.ID == 0 {
  1196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1197. return
  1198. }
  1199. if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  1200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  1201. return
  1202. }
  1203. if record.IdCardType == 1 {
  1204. } else {
  1205. cert_no = record.Certno
  1206. }
  1207. var result string
  1208. var src_resquest string
  1209. timeLayout := "2006-01-02"
  1210. loc, _ := time.LoadLocation("Local")
  1211. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record.InHosptialTime, loc)
  1212. if err != nil {
  1213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1214. return
  1215. }
  1216. recordStartDateTime := theTime.Unix()
  1217. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", record.OutHosptialTime, loc)
  1218. if err != nil {
  1219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1220. return
  1221. }
  1222. recordEndDateTime := theTimeEnd.Unix()
  1223. prescriptions, _ := service.GetZHSettleMonthHisPrescription(c.GetAdminUserInfo().CurrentOrgId, patient_id, recordStartDateTime, recordEndDateTime)
  1224. var total float64
  1225. for _, item := range prescriptions {
  1226. if item.Type == 1 { //药品
  1227. for _, subItem := range item.HisDoctorAdviceInfo {
  1228. total = total + (subItem.Price * subItem.PrescribingNumber)
  1229. }
  1230. }
  1231. if item.Type == 2 { //项目
  1232. for _, subItem := range item.HisPrescriptionProject {
  1233. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  1234. total = total + (subItem.Price * cnt)
  1235. }
  1236. }
  1237. }
  1238. //allTotal := fmt.Sprintf("%.2f", total)
  1239. var allTotal string
  1240. if record.OutHospitalStatus == 0 && order.ID == 0 {
  1241. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  1242. var total float64
  1243. for _, item := range orders {
  1244. total = total + item.DetItemFeeSumamt
  1245. }
  1246. allTotal = fmt.Sprintf("%.4f", total)
  1247. } else {
  1248. allTotal = fmt.Sprintf("%.4f", order.MedfeeSumamt)
  1249. }
  1250. if miConfig.MdtrtareaAdmvs == "150499" {
  1251. //请求内网数据
  1252. api := "http://172.16.13.254:9532/" + "nmyb/2304?psn_no=" + record.PsnNo + "&mdtrt_id=" + record.Number + "&chrg_bchno=" + chrg_bchno +
  1253. "&insutype_type=" + record.InsutypeType + "&total=" + allTotal +
  1254. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  1255. "&insuplc_admdvs=" + miConfig.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=" + record.IdCardNo
  1256. resp, requestErr := http.Get(api)
  1257. if requestErr != nil {
  1258. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1259. return
  1260. }
  1261. body, ioErr := ioutil.ReadAll(resp.Body)
  1262. if ioErr != nil {
  1263. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1264. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1265. return
  1266. }
  1267. var respJSON map[string]interface{}
  1268. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1269. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1270. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1271. return
  1272. }
  1273. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1274. result_byte, _ := json.Marshal(respJSON)
  1275. result = string(result_byte)
  1276. } else {
  1277. 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)
  1278. //saveLog()
  1279. saveLog(result, src_resquest, "2304", "住院结算")
  1280. }
  1281. var dat map[string]interface{}
  1282. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1283. fmt.Println(dat)
  1284. } else {
  1285. fmt.Println(err)
  1286. }
  1287. userJSONBytes, _ := json.Marshal(dat)
  1288. var res ResultSeven
  1289. var resSeven10265 ResultSeven10265
  1290. if miConfig.Code == "H15049901371" {
  1291. if err := json.Unmarshal(userJSONBytes, &resSeven10265); err != nil {
  1292. utils.ErrorLog("解析失败:%v", err)
  1293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1294. return
  1295. }
  1296. Infcode, _ := strconv.ParseInt(resSeven10265.Infcode, 10, 64)
  1297. res.Infcode = Infcode
  1298. res.InfRefmsgid = resSeven10265.InfRefmsgid
  1299. res.RespondTime = resSeven10265.RespondTime
  1300. res.ErrMsg = resSeven10265.ErrMsg
  1301. res.Output = resSeven10265.Output
  1302. res.WarnMsg = resSeven10265.WarnMsg
  1303. res.Cainfo = resSeven10265.Cainfo
  1304. } else {
  1305. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1306. utils.ErrorLog("解析失败:%v", err)
  1307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1308. return
  1309. }
  1310. }
  1311. if res.Infcode != 0 {
  1312. errlog := &models.HisOrderError{
  1313. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1314. Ctime: time.Now().Unix(),
  1315. Mtime: time.Now().Unix(),
  1316. Number: chrg_bchno,
  1317. ErrMsg: res.ErrMsg,
  1318. Status: 1,
  1319. PatientId: patient_id,
  1320. RecordTime: time.Now().Unix(),
  1321. Stage: 6,
  1322. }
  1323. service.CreateErrMsgLog(errlog)
  1324. c.ServeSuccessJSON(map[string]interface{}{
  1325. "failed_code": -10,
  1326. "msg": res.ErrMsg,
  1327. })
  1328. return
  1329. } else {
  1330. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1331. order.OrderStatus = 2
  1332. order.DiscountPrice = discount_price
  1333. order.MedicalInsurancePrice = medical_insurance_price
  1334. order.FaPiaoNumber = fapiao_number
  1335. order.FaPiaoCode = fapiao_code
  1336. order.PayWay = pay_way
  1337. order.PayPrice = pay_price
  1338. order.PayCardNo = pay_card_no
  1339. order.PreferentialPrice = preferential_price
  1340. order.RealityPrice = reality_price
  1341. order.FoundPrice = found_price
  1342. order.PrivatePrice = private_price
  1343. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1344. order.SetlId = res.Output.Setlinfo.SetlID
  1345. order.PsnNo = res.Output.Setlinfo.PsnNo
  1346. order.PsnName = res.Output.Setlinfo.PsnName
  1347. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1348. order.Certno = res.Output.Setlinfo.Certno
  1349. order.Gend = res.Output.Setlinfo.Gend
  1350. order.Naty = res.Output.Setlinfo.Naty
  1351. order.Age = res.Output.Setlinfo.Age
  1352. order.Insutype = res.Output.Setlinfo.Insutype
  1353. order.PsnType = res.Output.Setlinfo.PsnType
  1354. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1355. order.SetlTime = res.Output.Setlinfo.SetlTime
  1356. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1357. if res.Output.Setlinfo.MedType == "140104" {
  1358. order.MedType = "14"
  1359. } else {
  1360. order.MedType = res.Output.Setlinfo.MedType
  1361. }
  1362. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1363. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1364. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1365. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1366. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1367. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1368. order.HifpPay = res.Output.Setlinfo.HifpPay
  1369. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1370. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1371. order.HifesPay = res.Output.Setlinfo.HifesPay
  1372. order.HifobPay = res.Output.Setlinfo.HifobPay
  1373. order.MafPay = res.Output.Setlinfo.MafPay
  1374. order.OthPay = res.Output.Setlinfo.OthPay
  1375. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1376. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1377. order.AcctPay = res.Output.Setlinfo.AcctPay
  1378. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1379. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1380. order.Balc = res.Output.Setlinfo.Balc
  1381. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1382. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1383. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1384. order.ClrWay = res.Output.Setlinfo.ClrWay
  1385. order.Creator = order.Creator
  1386. order.Modify = roles.AdminUserId
  1387. order.RequestLog = src_resquest
  1388. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1389. detailStr := string(setlDetail)
  1390. order.SetlDetail = detailStr
  1391. err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  1392. err = service.UpDateOrder(order)
  1393. if err == nil {
  1394. c.ServeSuccessJSON(map[string]interface{}{
  1395. "msg": "结算成功",
  1396. })
  1397. } else {
  1398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1399. return
  1400. }
  1401. }
  1402. }
  1403. func (c *ZHHisApiController) GetPreSettleInfo() {
  1404. order_id, _ := c.GetInt64("order_id")
  1405. patient_id, _ := c.GetInt64("patient_id")
  1406. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  1407. admin_user_id, _ := c.GetInt64("admin_user_id")
  1408. record, _ := service.GetInHospitalRecord(in_hospital_id)
  1409. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  1410. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  1411. order, _ := service.GetHisOrderByID(order_id)
  1412. var allTotal string
  1413. if record.OutHospitalStatus == 0 && order.ID == 0 {
  1414. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  1415. var total float64
  1416. for _, item := range orders {
  1417. total = total + item.DetItemFeeSumamt
  1418. }
  1419. allTotal = fmt.Sprintf("%.4f", total)
  1420. } else {
  1421. allTotal = fmt.Sprintf("%.4f", order.MedfeeSumamt)
  1422. }
  1423. var rf []*ResultFive
  1424. json.Unmarshal([]byte(record.Iinfo), &rf)
  1425. chrg_bchno := order.Number
  1426. cert_no := record.Certno
  1427. if record.ID == 0 {
  1428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1429. return
  1430. }
  1431. //if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  1432. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  1433. // return
  1434. //}
  1435. if record.IdCardType == 1 {
  1436. } else {
  1437. cert_no = record.Certno
  1438. }
  1439. var result string
  1440. var src_resquest string
  1441. if miConfig.MdtrtareaAdmvs == "150499" {
  1442. //请求内网数据
  1443. api := "http://172.16.13.254:9532/" + "nmyb/2303?psn_no=" + record.PsnNo + "&mdtrt_id=" + record.Number + "&chrg_bchno=" + chrg_bchno +
  1444. "&insutype_type=" + record.InsutypeType + "&total=" + allTotal +
  1445. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  1446. "&insuplc_admdvs=" + miConfig.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=" + record.IdCardNo
  1447. resp, requestErr := http.Get(api)
  1448. if requestErr != nil {
  1449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1450. return
  1451. }
  1452. body, ioErr := ioutil.ReadAll(resp.Body)
  1453. if ioErr != nil {
  1454. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1456. return
  1457. }
  1458. var respJSON map[string]interface{}
  1459. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1460. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1462. return
  1463. }
  1464. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1465. result_byte, _ := json.Marshal(respJSON)
  1466. result = string(result_byte)
  1467. } else {
  1468. 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)
  1469. saveLog(result, src_resquest, "2303", "住院预结算")
  1470. }
  1471. var dat map[string]interface{}
  1472. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1473. fmt.Println(dat)
  1474. } else {
  1475. fmt.Println(err)
  1476. }
  1477. userJSONBytes, _ := json.Marshal(dat)
  1478. var res ResultSeven
  1479. var resSeven10265 ResultSeven10265
  1480. if miConfig.Code == "H15049901371" {
  1481. if err := json.Unmarshal(userJSONBytes, &resSeven10265); err != nil {
  1482. utils.ErrorLog("解析失败:%v", err)
  1483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1484. return
  1485. }
  1486. Infcode, _ := strconv.ParseInt(resSeven10265.Infcode, 10, 64)
  1487. res.Infcode = Infcode
  1488. res.InfRefmsgid = resSeven10265.InfRefmsgid
  1489. res.RespondTime = resSeven10265.RespondTime
  1490. res.ErrMsg = resSeven10265.ErrMsg
  1491. res.Output = resSeven10265.Output
  1492. res.WarnMsg = resSeven10265.WarnMsg
  1493. res.Cainfo = resSeven10265.Cainfo
  1494. } else {
  1495. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1496. utils.ErrorLog("解析失败:%v", err)
  1497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1498. return
  1499. }
  1500. }
  1501. if res.Infcode != 0 {
  1502. errlog := &models.HisOrderError{
  1503. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1504. Ctime: time.Now().Unix(),
  1505. Mtime: time.Now().Unix(),
  1506. Number: chrg_bchno,
  1507. ErrMsg: res.ErrMsg,
  1508. Status: 1,
  1509. PatientId: patient_id,
  1510. RecordTime: time.Now().Unix(),
  1511. Stage: 6,
  1512. }
  1513. service.CreateErrMsgLog(errlog)
  1514. c.ServeSuccessJSON(map[string]interface{}{
  1515. "failed_code": -10,
  1516. "msg": res.ErrMsg,
  1517. })
  1518. return
  1519. } else {
  1520. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1521. order.OrderStatus = 1
  1522. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1523. order.SetlId = res.Output.Setlinfo.SetlID
  1524. order.PsnNo = res.Output.Setlinfo.PsnNo
  1525. order.PsnName = res.Output.Setlinfo.PsnName
  1526. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1527. order.Certno = res.Output.Setlinfo.Certno
  1528. order.Gend = res.Output.Setlinfo.Gend
  1529. order.Naty = res.Output.Setlinfo.Naty
  1530. order.Age = res.Output.Setlinfo.Age
  1531. order.Insutype = res.Output.Setlinfo.Insutype
  1532. order.PsnType = res.Output.Setlinfo.PsnType
  1533. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1534. order.SetlTime = res.Output.Setlinfo.SetlTime
  1535. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1536. if res.Output.Setlinfo.MedType == "140104" {
  1537. order.MedType = "14"
  1538. } else {
  1539. order.MedType = res.Output.Setlinfo.MedType
  1540. }
  1541. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1542. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1543. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1544. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1545. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1546. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1547. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  1548. order.HifpPay = res.Output.Setlinfo.HifpPay
  1549. order.HifesPay = res.Output.Setlinfo.HifesPay
  1550. order.HifobPay = res.Output.Setlinfo.HifobPay
  1551. order.MafPay = res.Output.Setlinfo.MafPay
  1552. order.OthPay = res.Output.Setlinfo.OthPay
  1553. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1554. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1555. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1556. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1557. order.AcctPay = res.Output.Setlinfo.AcctPay
  1558. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1559. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1560. order.Balc = res.Output.Setlinfo.Balc
  1561. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1562. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1563. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1564. order.ClrWay = res.Output.Setlinfo.ClrWay
  1565. order.Creator = order.Creator
  1566. order.Modify = roles.AdminUserId
  1567. order.RequestLog = src_resquest
  1568. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1569. detailStr := string(setlDetail)
  1570. order.SetlDetail = detailStr
  1571. //err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  1572. if record.OutHospitalStatus == 1 && order.ID > 0 {
  1573. err := service.UpDateOrder(order)
  1574. if err == nil {
  1575. c.ServeSuccessJSON(map[string]interface{}{
  1576. "msg": "预结算成功",
  1577. "order_way": 1,
  1578. })
  1579. } else {
  1580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1581. return
  1582. }
  1583. } else if record.OutHospitalStatus == 0 && order.ID == 0 {
  1584. c.ServeSuccessJSON(map[string]interface{}{
  1585. "msg": "预结算成功",
  1586. "order": order,
  1587. "order_way": 2,
  1588. })
  1589. }
  1590. }
  1591. }
  1592. func (c *ZHHisApiController) GetUploadInfo() {
  1593. id, _ := c.GetInt64("id")
  1594. record_time := c.GetString("record_time")
  1595. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  1596. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1597. admin_user_id, _ := c.GetInt64("admin_user_id")
  1598. timeLayout := "2006-01-02"
  1599. loc, _ := time.LoadLocation("Local")
  1600. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1601. if err != nil {
  1602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1603. return
  1604. }
  1605. recordDateTime := theTime.Unix()
  1606. adminUser := c.GetAdminUserInfo()
  1607. var prescriptions []*models.HisPrescription
  1608. data := make(map[string]interface{})
  1609. if settle_accounts_type == 1 { //日结
  1610. prescriptions, _ = service.GetZHHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1611. } else { //月结
  1612. start_time_str := c.GetString("start_time")
  1613. end_time_str := c.GetString("end_time")
  1614. timeLayout := "2006-01-02"
  1615. loc, _ := time.LoadLocation("Local")
  1616. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1617. if err != nil {
  1618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1619. return
  1620. }
  1621. recordStartTime := theStartTime.Unix()
  1622. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1623. if err != nil {
  1624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1625. return
  1626. }
  1627. recordEndTime := theEndTime.Unix()
  1628. prescriptions, _ = service.GetZHMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1629. }
  1630. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1631. record, _ := service.GetInHospitalRecord(in_hospital_id)
  1632. if record.ID == 0 {
  1633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1634. return
  1635. }
  1636. timestamp := time.Now().Unix()
  1637. tempTime := time.Unix(timestamp, 0)
  1638. timeFormat := tempTime.Format("20060102150405")
  1639. chrgBchno := rand.Intn(100000) + 10000
  1640. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(record.PatientId, 10)
  1641. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1642. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1643. department, _ := service.GetDepartMentDetail(record.Departments)
  1644. strconv.FormatInt(record.PatientId, 10)
  1645. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, record.Doctor)
  1646. //client := &http.Client{}
  1647. data["psn_no"] = record.PsnNo
  1648. data["mdtrt_id"] = record.Number
  1649. data["chrg_bchno"] = chrg_bchno
  1650. data["org_name"] = miConfig.OrgName
  1651. data["doctor"] = roles.UserName
  1652. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1653. data["dept"] = strconv.FormatInt(department.ID, 10)
  1654. data["fixmedins_code"] = miConfig.Code
  1655. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  1656. data["dept_code"] = "15"
  1657. } else {
  1658. data["dept_code"] = department.Number
  1659. }
  1660. if miConfig.Code == "H15049901371" {
  1661. if record.MedType == 14 {
  1662. if record.InsutypeType == "390" {
  1663. data["med_type"] = "9933"
  1664. } else if record.InsutypeType == "310" {
  1665. data["med_type"] = "990502"
  1666. }
  1667. } else if record.MedType == 11 {
  1668. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  1669. }
  1670. } else {
  1671. if record.MedType == 1112 {
  1672. data["med_type"] = strconv.FormatInt(11, 10)
  1673. } else {
  1674. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  1675. }
  1676. }
  1677. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  1678. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1679. data["secret_key"] = miConfig.SecretKey
  1680. var ids []int64
  1681. fmt.Println(data)
  1682. for _, item := range prescriptions {
  1683. ids = append(ids, item.ID)
  1684. }
  1685. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1686. if config.IsOpen == 1 { //对接了医保,走医保流程
  1687. var pagesize int = 100
  1688. var start int = 1
  1689. var stop int
  1690. var pagecount int
  1691. var curpage int
  1692. var isSuccess bool = true
  1693. var customs []*models.NewCustom
  1694. for _, item := range prescriptions {
  1695. tm := time.Unix(item.PreTime, 0)
  1696. if item.Type == 1 { //药品
  1697. for _, subItem := range item.HisDoctorAdviceInfo {
  1698. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 && subItem.BaseDrugLib.IsUser != 1 {
  1699. //var randNum int
  1700. //randNum = rand.Intn(10000) + 1000
  1701. cus := &models.NewCustom{
  1702. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  1703. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  1704. FeedetlSn: subItem.FeedetlSn,
  1705. Price: fmt.Sprintf("%.4f", subItem.Price),
  1706. MedListCodg: subItem.BaseDrugLib.MedicalInsuranceNumber,
  1707. HospApprFlag: subItem.BaseDrugLib.HospApprFlag,
  1708. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  1709. }
  1710. customs = append(customs, cus)
  1711. }
  1712. }
  1713. }
  1714. if item.Type == 2 { //项目
  1715. for _, subItem := range item.HisPrescriptionProject {
  1716. //var randNum int
  1717. //randNum = rand.Intn(10000) + 1000
  1718. if subItem.Type == 2 {
  1719. if len(subItem.HisProject.MedicalCode) > 0 {
  1720. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  1721. cus := &models.NewCustom{
  1722. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  1723. Cut: fmt.Sprintf("%.4f", cnt),
  1724. FeedetlSn: subItem.FeedetlSn,
  1725. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  1726. MedListCodg: subItem.HisProject.MedicalCode,
  1727. HospApprFlag: -1,
  1728. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  1729. }
  1730. customs = append(customs, cus)
  1731. }
  1732. } else if subItem.Type == 3 {
  1733. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 && subItem.GoodInfo.IsUser != 1 {
  1734. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  1735. cus := &models.NewCustom{
  1736. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  1737. Cut: fmt.Sprintf("%.4f", cnt),
  1738. FeedetlSn: subItem.FeedetlSn,
  1739. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  1740. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  1741. HospApprFlag: -1,
  1742. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  1743. }
  1744. customs = append(customs, cus)
  1745. }
  1746. }
  1747. }
  1748. }
  1749. }
  1750. //总页数,向上取整,注意除之前要先转换类型为float64
  1751. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  1752. var ress []*ResultFour
  1753. for curpage = 1; curpage <= pagecount; curpage++ {
  1754. if curpage == 1 {
  1755. start = 1
  1756. } else {
  1757. start = (curpage-1)*pagesize + 1
  1758. }
  1759. stop = curpage * pagesize
  1760. if stop > len(customs) {
  1761. stop = len(customs)
  1762. }
  1763. var result string
  1764. var requestLog string
  1765. if miConfig.MdtrtareaAdmvs == "150499" {
  1766. data := make(map[string]interface{})
  1767. if record.MedType == 14 {
  1768. if record.InsutypeType == "390" {
  1769. data["med_type"] = "9933"
  1770. } else if record.InsutypeType == "310" {
  1771. data["med_type"] = "990502"
  1772. }
  1773. } else if record.MedType == 11 {
  1774. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  1775. }
  1776. data["psn_no"] = record.PsnNo
  1777. data["number"] = record.Number
  1778. data["customs"] = customs[start-1 : stop]
  1779. data["chrg_bchno"] = chrg_bchno
  1780. data["dept"] = strconv.FormatInt(department.ID, 10)
  1781. data["dept_code"] = department.Number
  1782. data["doctor_code"] = strconv.FormatInt(doctor_info.ID, 10)
  1783. data["doctor_name"] = doctor_info.UserName
  1784. data["org_name"] = miConfig.OrgName
  1785. data["opertor"] = roles.UserName
  1786. data["fixmedins_code"] = miConfig.Code
  1787. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  1788. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1789. data["secret_key"] = miConfig.SecretKey
  1790. var req *http.Request
  1791. bytesData, _ := json.Marshal(data)
  1792. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2301", bytes.NewReader(bytesData))
  1793. client := &http.Client{}
  1794. resp, _ := client.Do(req)
  1795. defer resp.Body.Close()
  1796. body, ioErr := ioutil.ReadAll(resp.Body)
  1797. if ioErr != nil {
  1798. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1800. return
  1801. }
  1802. var respJSON map[string]interface{}
  1803. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1804. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1806. return
  1807. }
  1808. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1809. result_byte, _ := json.Marshal(respJSON)
  1810. result = string(result_byte)
  1811. } else {
  1812. 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))
  1813. saveLog(result, requestLog, "2301", "上传明细")
  1814. }
  1815. var dat map[string]interface{}
  1816. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1817. fmt.Println(dat)
  1818. } else {
  1819. fmt.Println(err)
  1820. }
  1821. userJSONBytes, _ := json.Marshal(dat)
  1822. var res ResultFour
  1823. var resFour10265 ResultFour10265
  1824. if miConfig.Code == "H15049901371" {
  1825. if err := json.Unmarshal(userJSONBytes, &resFour10265); err != nil {
  1826. utils.ErrorLog("解析失败:%v", err)
  1827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1828. return
  1829. }
  1830. res.WarnMsg = resFour10265.WarnMsg
  1831. res.Output = resFour10265.Output
  1832. res.ErrMsg = resFour10265.ErrMsg
  1833. res.RespondTime = resFour10265.RespondTime
  1834. res.InfRefmsgid = resFour10265.InfRefmsgid
  1835. Infcode, _ := strconv.ParseInt(resFour10265.Infcode, 10, 64)
  1836. res.Infcode = Infcode
  1837. } else {
  1838. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1839. utils.ErrorLog("解析失败:%v", err)
  1840. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1841. return
  1842. }
  1843. }
  1844. if res.Infcode == 0 {
  1845. ress = append(ress, &res)
  1846. } else {
  1847. isSuccess = false
  1848. errlog := &models.HisOrderError{
  1849. UserOrgId: adminUser.CurrentOrgId,
  1850. Ctime: time.Now().Unix(),
  1851. Mtime: time.Now().Unix(),
  1852. Number: chrg_bchno,
  1853. ErrMsg: "",
  1854. Status: 1,
  1855. PatientId: id,
  1856. RecordTime: recordDateTime,
  1857. Stage: 4,
  1858. }
  1859. service.CreateErrMsgLog(errlog)
  1860. c.ServeSuccessJSON(map[string]interface{}{
  1861. "failed_code": -10,
  1862. "msg": "上传明细错误,请联系his厂商",
  1863. })
  1864. return
  1865. }
  1866. }
  1867. if isSuccess == true {
  1868. if settle_accounts_type == 1 {
  1869. for _, subItem := range ress {
  1870. for _, item := range subItem.Output.Result {
  1871. temp := strings.Split(item.FeedetlSn, "-")
  1872. var advice_id int64 = 0
  1873. var project_id int64 = 0
  1874. var types int64 = 0
  1875. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1876. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1877. if temp[1] == "1" {
  1878. advice_id = id
  1879. project_id = 0
  1880. } else if temp[1] == "2" {
  1881. advice_id = 0
  1882. project_id = id
  1883. }
  1884. info := &models.HisOrderInfo{
  1885. OrderNumber: record.Number,
  1886. FeedetlSn: item.FeedetlSn,
  1887. UploadDate: recordDateTime,
  1888. AdviceId: advice_id,
  1889. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1890. Cnt: item.Cnt,
  1891. Pric: float64(item.Pric),
  1892. PatientId: record.PatientId,
  1893. PricUplmtAmt: item.PricUplmtAmt,
  1894. SelfpayProp: item.SelfpayProp,
  1895. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1896. OverlmtAmt: item.OverlmtAmt,
  1897. PreselfpayAmt: item.PreselfpayAmt,
  1898. BasMednFlag: item.BasMednFlag,
  1899. MedChrgitmType: item.MedChrgitmType,
  1900. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1901. Status: 1,
  1902. Memo: item.Memo,
  1903. Mtime: time.Now().Unix(),
  1904. InscpScpAmt: item.InscpScpAmt,
  1905. DrtReimFlag: item.DrtReimFlag,
  1906. Ctime: time.Now().Unix(),
  1907. ListSpItemFlag: item.ListSpItemFlag,
  1908. ChldMedcFlag: item.ChldMedcFlag,
  1909. LmtUsedFlag: item.LmtUsedFlag,
  1910. ChrgitmLv: item.ChrgitmLv,
  1911. UserOrgId: adminUser.CurrentOrgId,
  1912. HisPatientId: record.ID,
  1913. OrderId: 0,
  1914. ProjectId: project_id,
  1915. Type: types,
  1916. SettleType: settle_accounts_type,
  1917. }
  1918. service.CreateOrderInfo(info)
  1919. }
  1920. }
  1921. err := service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  1922. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  1923. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  1924. if err == nil {
  1925. c.ServeSuccessJSON(map[string]interface{}{
  1926. "msg": "上传费用明细成功",
  1927. })
  1928. return
  1929. } else {
  1930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1931. return
  1932. }
  1933. } else {
  1934. for _, subItem := range ress {
  1935. for _, item := range subItem.Output.Result {
  1936. temp := strings.Split(item.FeedetlSn, "-")
  1937. var advice_id int64 = 0
  1938. var project_id int64 = 0
  1939. var types int64 = 0
  1940. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1941. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1942. if temp[1] == "1" {
  1943. advice_id = id
  1944. project_id = 0
  1945. } else if temp[1] == "2" {
  1946. advice_id = 0
  1947. project_id = id
  1948. }
  1949. info := &models.HisOrderInfo{
  1950. OrderNumber: record.Number,
  1951. FeedetlSn: item.FeedetlSn,
  1952. UploadDate: time.Now().Unix(),
  1953. AdviceId: advice_id,
  1954. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1955. Cnt: item.Cnt,
  1956. Pric: float64(item.Pric),
  1957. PatientId: record.PatientId,
  1958. PricUplmtAmt: item.PricUplmtAmt,
  1959. SelfpayProp: item.SelfpayProp,
  1960. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1961. OverlmtAmt: item.OverlmtAmt,
  1962. PreselfpayAmt: item.PreselfpayAmt,
  1963. BasMednFlag: item.BasMednFlag,
  1964. MedChrgitmType: item.MedChrgitmType,
  1965. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1966. Status: 1,
  1967. Memo: item.Memo,
  1968. Mtime: time.Now().Unix(),
  1969. InscpScpAmt: item.InscpScpAmt,
  1970. DrtReimFlag: item.DrtReimFlag,
  1971. Ctime: time.Now().Unix(),
  1972. ListSpItemFlag: item.ListSpItemFlag,
  1973. ChldMedcFlag: item.ChldMedcFlag,
  1974. LmtUsedFlag: item.LmtUsedFlag,
  1975. ChrgitmLv: item.ChrgitmLv,
  1976. UserOrgId: adminUser.CurrentOrgId,
  1977. HisPatientId: record.ID,
  1978. ProjectId: project_id,
  1979. Type: types,
  1980. SettleType: settle_accounts_type,
  1981. }
  1982. service.CreateOrderInfo(info)
  1983. }
  1984. }
  1985. service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  1986. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  1987. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  1988. c.ServeSuccessJSON(map[string]interface{}{
  1989. "msg": "上传费用明细成功",
  1990. })
  1991. }
  1992. }
  1993. }
  1994. }
  1995. func (c *ZHHisApiController) ZHRefund() {
  1996. order_id, _ := c.GetInt64("order_id")
  1997. admin_user_id, _ := c.GetInt64("admin_user_id")
  1998. adminUser := c.GetAdminUserInfo()
  1999. var order models.HisOrder
  2000. order, _ = service.GetHisOrderByID(order_id)
  2001. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  2002. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2003. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2004. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2005. if config.IsOpen == 1 { //对接了医保,走医保流程
  2006. var result string
  2007. var requestLog string
  2008. if miConfig.MdtrtareaAdmvs == "150499" {
  2009. //请求内网数据
  2010. api := "http://172.16.13.254:9532/" + "nmyb/2305?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo + "&setl_id=" + order.SetlId +
  2011. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2012. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2013. resp, requestErr := http.Get(api)
  2014. if requestErr != nil {
  2015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2016. return
  2017. }
  2018. body, ioErr := ioutil.ReadAll(resp.Body)
  2019. if ioErr != nil {
  2020. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2022. return
  2023. }
  2024. var respJSON map[string]interface{}
  2025. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2026. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2028. return
  2029. }
  2030. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2031. result_byte, _ := json.Marshal(respJSON)
  2032. result = string(result_byte)
  2033. //saveLog(result, requestLog, "2404", "入院登记撤销")
  2034. saveLog(result, requestLog, "2305", "退费")
  2035. } else {
  2036. result, requestLog := service.Gdyb2305(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2037. saveLog(result, requestLog, "2305", "退费")
  2038. }
  2039. var dat map[string]interface{}
  2040. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2041. fmt.Println(dat)
  2042. } else {
  2043. fmt.Println(err)
  2044. }
  2045. userJSONBytes, _ := json.Marshal(dat)
  2046. var res ResultSixteen
  2047. var resSixteen ResultSixteen10265
  2048. if miConfig.Code == "H15049901371" {
  2049. if err := json.Unmarshal(userJSONBytes, &resSixteen); err != nil {
  2050. utils.ErrorLog("解析失败:%v", err)
  2051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2052. return
  2053. }
  2054. res.Cainfo = resSixteen.Cainfo
  2055. res.WarnMsg = resSixteen.WarnMsg
  2056. res.Output = resSixteen.Output
  2057. res.ErrMsg = resSixteen.ErrMsg
  2058. res.RespondTime = resSixteen.RespondTime
  2059. Infcode, _ := strconv.ParseInt(resSixteen.Infcode, 10, 64)
  2060. res.Infcode = Infcode
  2061. } else {
  2062. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2063. utils.ErrorLog("解析失败:%v", err)
  2064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2065. return
  2066. }
  2067. }
  2068. if res.Infcode == 0 {
  2069. err := service.UpdataOrderStatusThree(order_id, order.Number, adminUser.CurrentOrgId, "", result)
  2070. //不同地区退费流程不一样,肇庆那边退费就包括撤销出院,内蒙古退费不包括撤销明细,所以下面需要根据不同情况进行判断
  2071. if miConfig.UserOrgId == 10215 {
  2072. record.OutHospitalStatus = 0
  2073. service.CreateHospitalRecord(&record)
  2074. }
  2075. service.UpdataOrderStatusByNumber(record.Number)
  2076. if err == nil {
  2077. c.ServeSuccessJSON(map[string]interface{}{
  2078. "msg": "退费成功",
  2079. })
  2080. } else {
  2081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2082. return
  2083. }
  2084. } else {
  2085. c.ServeSuccessJSON(map[string]interface{}{
  2086. "code": -10,
  2087. "msg": res.ErrMsg,
  2088. })
  2089. }
  2090. } else {
  2091. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  2092. if err == nil {
  2093. c.ServeSuccessJSON(map[string]interface{}{
  2094. "msg": "退费成功",
  2095. })
  2096. } else {
  2097. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2098. return
  2099. }
  2100. }
  2101. }
  2102. func (c *ZHHisApiController) ZHRefundDetail() {
  2103. patient_id, _ := c.GetInt64("patient_id")
  2104. his_patient_id, _ := c.GetInt64("his_patient_id")
  2105. record_time := c.GetString("record_time")
  2106. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2107. //order_id, _ := c.GetInt64("order_id")
  2108. admin_user_id, _ := c.GetInt64("admin_user_id")
  2109. timeLayout := "2006-01-02"
  2110. loc, _ := time.LoadLocation("Local")
  2111. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2112. if err != nil {
  2113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2114. return
  2115. }
  2116. recordDateTime := theTime.Unix()
  2117. adminUser := c.GetAdminUserInfo()
  2118. theTimeTwo, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 23:59:59", loc)
  2119. if err != nil {
  2120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2121. return
  2122. }
  2123. recordDateTimeTwo := theTimeTwo.Unix()
  2124. //var prescriptions []*models.HisPrescription
  2125. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2126. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2127. if settle_accounts_type == 1 { //日结
  2128. record, _ := service.GetInHospitalRecord(his_patient_id)
  2129. infos, _ := service.GetZHHisUploadOrderInfo(adminUser.CurrentOrgId, patient_id, recordDateTime, recordDateTimeTwo, record.Number)
  2130. var isSuccess bool = true
  2131. for _, item := range infos {
  2132. var result string
  2133. var requestLog string
  2134. if miConfig.MdtrtareaAdmvs == "150499" {
  2135. //请求内网数据
  2136. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&feedetl_sn=" + item.FeedetlSn +
  2137. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2138. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "1"
  2139. resp, requestErr := http.Get(api)
  2140. if requestErr != nil {
  2141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2142. return
  2143. }
  2144. body, ioErr := ioutil.ReadAll(resp.Body)
  2145. if ioErr != nil {
  2146. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2148. return
  2149. }
  2150. var respJSON map[string]interface{}
  2151. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2152. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2154. return
  2155. }
  2156. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2157. result_byte, _ := json.Marshal(respJSON)
  2158. result = string(result_byte)
  2159. saveLog(result, requestLog, "2302", "日结退明细")
  2160. } else {
  2161. result, requestLog := service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, item.FeedetlSn, 1)
  2162. saveLog(result, requestLog, "2302", "日结退明细")
  2163. }
  2164. var dat map[string]interface{}
  2165. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2166. fmt.Println(dat)
  2167. } else {
  2168. fmt.Println(err)
  2169. }
  2170. userJSONBytes, _ := json.Marshal(dat)
  2171. var res2 ResultEmpty
  2172. var resEmpty10265 ResultEmpty10265
  2173. if miConfig.Code == "H15049901371" {
  2174. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2175. utils.ErrorLog("解析失败:%v", err)
  2176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2177. return
  2178. }
  2179. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2180. res2.Infcode = Infcode
  2181. res2.RespondTime = resEmpty10265.RespondTime
  2182. res2.ErrMsg = resEmpty10265.ErrMsg
  2183. res2.Output = resEmpty10265.Output
  2184. res2.WarnMsg = resEmpty10265.WarnMsg
  2185. } else {
  2186. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2187. utils.ErrorLog("解析失败:%v", err)
  2188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2189. return
  2190. }
  2191. }
  2192. if res2.Infcode == -1 {
  2193. isSuccess = false
  2194. }
  2195. }
  2196. if isSuccess {
  2197. err := service.UpDateOrderInfoStatus(patient_id, recordDateTime, adminUser.CurrentOrgId, recordDateTimeTwo)
  2198. if err != nil {
  2199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2200. return
  2201. }
  2202. err1 := service.UpDatePrescriptionOrderStatusTwo(patient_id, recordDateTime, adminUser.CurrentOrgId)
  2203. if err1 != nil {
  2204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2205. return
  2206. }
  2207. c.ServeSuccessJSON(map[string]interface{}{
  2208. "msg": "撤销明细成功",
  2209. })
  2210. }
  2211. } else {
  2212. //prescriptions, _ = service.GetZHMonthHisUploadPrescription(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2213. //var order models.HisOrder
  2214. //order, _ = service.GetHisOrderByID(order_id)
  2215. //record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  2216. var result string
  2217. var requestLog string
  2218. record, _ := service.GetInHospitalRecord(his_patient_id)
  2219. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2220. if config.IsOpen == 1 { //对接了医保,走医保流程
  2221. if miConfig.MdtrtareaAdmvs == "150499" {
  2222. //请求内网数据
  2223. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=0000" +
  2224. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2225. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "1"
  2226. resp, requestErr := http.Get(api)
  2227. if requestErr != nil {
  2228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2229. return
  2230. }
  2231. body, ioErr := ioutil.ReadAll(resp.Body)
  2232. if ioErr != nil {
  2233. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2235. return
  2236. }
  2237. var respJSON map[string]interface{}
  2238. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2239. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2241. return
  2242. }
  2243. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2244. result_byte, _ := json.Marshal(respJSON)
  2245. result = string(result_byte)
  2246. //saveLog(result, requestLog, "2302", "日结退明细")
  2247. } else {
  2248. result, requestLog = service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  2249. saveLog(result, requestLog, "2302", "月结退明细")
  2250. }
  2251. var dat map[string]interface{}
  2252. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2253. fmt.Println(dat)
  2254. } else {
  2255. fmt.Println(err)
  2256. }
  2257. userJSONBytes, _ := json.Marshal(dat)
  2258. var res2 ResultEmpty
  2259. var resEmpty10265 ResultEmpty10265
  2260. if miConfig.Code == "H15049901371" {
  2261. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2262. utils.ErrorLog("解析失败:%v", err)
  2263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2264. return
  2265. }
  2266. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2267. res2.Infcode = Infcode
  2268. res2.RespondTime = resEmpty10265.RespondTime
  2269. res2.ErrMsg = resEmpty10265.ErrMsg
  2270. res2.Output = resEmpty10265.Output
  2271. res2.WarnMsg = resEmpty10265.WarnMsg
  2272. } else {
  2273. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2274. utils.ErrorLog("解析失败:%v", err)
  2275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2276. return
  2277. }
  2278. }
  2279. if res2.Infcode == 0 {
  2280. err := service.UpdataHospitalOrderStatus(record.Number, adminUser.CurrentOrgId)
  2281. if err == nil {
  2282. c.ServeSuccessJSON(map[string]interface{}{
  2283. "msg": "撤销明细成功",
  2284. })
  2285. } else {
  2286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2287. return
  2288. }
  2289. } else {
  2290. c.ServeSuccessJSON(map[string]interface{}{
  2291. "code": -10,
  2292. "msg": res2.ErrMsg,
  2293. })
  2294. }
  2295. }
  2296. }
  2297. }
  2298. func (this *ZHHisApiController) GetZHOutHospitalUnCheck() {
  2299. id, _ := this.GetInt64("id")
  2300. admin_user_id, _ := this.GetInt64("admin_user_id")
  2301. adminInfo := this.GetAdminUserInfo()
  2302. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2303. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  2304. record, _ := service.GetInHospitalRecord(id)
  2305. if record.ID == 0 {
  2306. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  2307. return
  2308. }
  2309. var result string
  2310. var requestLog string
  2311. if miConfig.MdtrtareaAdmvs == "150499" {
  2312. //请求内网数据
  2313. api := "http://172.16.13.254:9532/" + "nmyb/2405?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  2314. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  2315. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2316. fmt.Println(api)
  2317. resp, requestErr := http.Get(api)
  2318. if requestErr != nil {
  2319. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2320. return
  2321. }
  2322. body, ioErr := ioutil.ReadAll(resp.Body)
  2323. if ioErr != nil {
  2324. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2325. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2326. return
  2327. }
  2328. var respJSON map[string]interface{}
  2329. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2330. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2331. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2332. return
  2333. }
  2334. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2335. result_byte, _ := json.Marshal(respJSON)
  2336. result = string(result_byte)
  2337. } else {
  2338. result, requestLog = service.ZHGdyb2405(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2339. saveLog(result, requestLog, "2405", "出院登记撤销")
  2340. }
  2341. var dat map[string]interface{}
  2342. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2343. fmt.Println(dat)
  2344. } else {
  2345. fmt.Println(err)
  2346. }
  2347. userJSONBytes, _ := json.Marshal(dat)
  2348. var res ResultEmpty
  2349. var resEmpty10265 ResultEmpty10265
  2350. if miConfig.Code == "H15049901371" {
  2351. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2352. utils.ErrorLog("解析失败:%v", err)
  2353. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2354. return
  2355. }
  2356. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2357. res.Infcode = Infcode
  2358. res.RespondTime = resEmpty10265.RespondTime
  2359. res.ErrMsg = resEmpty10265.ErrMsg
  2360. res.Output = resEmpty10265.Output
  2361. res.WarnMsg = resEmpty10265.WarnMsg
  2362. } else {
  2363. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2364. utils.ErrorLog("解析失败:%v", err)
  2365. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2366. return
  2367. }
  2368. }
  2369. if res.Infcode == 0 {
  2370. record.OutHospitalStatus = 0
  2371. service.CreateHospitalRecord(&record)
  2372. service.UpdataOrderStatusByNumber(record.Number)
  2373. this.ServeSuccessJSON(map[string]interface{}{
  2374. "msg": "撤销出院成功",
  2375. })
  2376. } else {
  2377. this.ServeSuccessJSON(map[string]interface{}{
  2378. "failed_code": -10,
  2379. "msg": res.ErrMsg,
  2380. })
  2381. }
  2382. }
  2383. func (this *ZHHisApiController) GetZHInHospitalUnCheck() {
  2384. id, _ := this.GetInt64("id")
  2385. admin_user_id, _ := this.GetInt64("admin_user_id")
  2386. adminInfo := this.GetAdminUserInfo()
  2387. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2388. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  2389. record, _ := service.GetInHospitalRecord(id)
  2390. if record.ID == 0 {
  2391. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  2392. return
  2393. }
  2394. var result string
  2395. var requestLog string
  2396. if miConfig.MdtrtareaAdmvs == "150499" {
  2397. //请求内网数据
  2398. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=" + "0000" +
  2399. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  2400. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=0"
  2401. resp, requestErr := http.Get(api)
  2402. if requestErr != nil {
  2403. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2404. return
  2405. }
  2406. body, ioErr := ioutil.ReadAll(resp.Body)
  2407. if ioErr != nil {
  2408. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2409. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2410. return
  2411. }
  2412. var respJSON map[string]interface{}
  2413. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2414. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2415. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2416. return
  2417. }
  2418. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2419. result_byte, _ := json.Marshal(respJSON)
  2420. result = string(result_byte)
  2421. saveLog(result, requestLog, "2302", "月结退明细")
  2422. } else {
  2423. result, requestLog = service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  2424. saveLog(result, requestLog, "2302", "月结退明细")
  2425. }
  2426. var dat map[string]interface{}
  2427. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2428. fmt.Println(dat)
  2429. } else {
  2430. fmt.Println(err)
  2431. }
  2432. userJSONBytes, _ := json.Marshal(dat)
  2433. var res2 ResultEmpty
  2434. var resEmpty10265 ResultEmpty10265
  2435. if miConfig.Code == "H15049901371" {
  2436. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2437. utils.ErrorLog("解析失败:%v", err)
  2438. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2439. return
  2440. }
  2441. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2442. res2.Infcode = Infcode
  2443. res2.RespondTime = resEmpty10265.RespondTime
  2444. res2.ErrMsg = resEmpty10265.ErrMsg
  2445. res2.Output = resEmpty10265.Output
  2446. res2.WarnMsg = resEmpty10265.WarnMsg
  2447. } else {
  2448. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2449. utils.ErrorLog("解析失败:%v", err)
  2450. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2451. return
  2452. }
  2453. }
  2454. if res2.Infcode == 0 {
  2455. service.UpdataHospitalOrderStatus(record.Number, adminInfo.CurrentOrgId)
  2456. var result string
  2457. var requestLog string
  2458. if miConfig.MdtrtareaAdmvs == "150499" {
  2459. //请求内网数据
  2460. api := "http://172.16.13.254:9532/" + "nmyb/2404?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  2461. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  2462. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2463. resp, requestErr := http.Get(api)
  2464. if requestErr != nil {
  2465. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2466. return
  2467. }
  2468. body, ioErr := ioutil.ReadAll(resp.Body)
  2469. if ioErr != nil {
  2470. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2471. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2472. return
  2473. }
  2474. var respJSON map[string]interface{}
  2475. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2476. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2477. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2478. return
  2479. }
  2480. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2481. result_byte, _ := json.Marshal(respJSON)
  2482. result = string(result_byte)
  2483. } else {
  2484. result, requestLog = service.ZHGdyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2485. saveLog(result, requestLog, "2404", "入院登记撤销")
  2486. }
  2487. var dat map[string]interface{}
  2488. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2489. fmt.Println(dat)
  2490. } else {
  2491. fmt.Println(err)
  2492. }
  2493. userJSONBytes, _ := json.Marshal(dat)
  2494. var res ResultEmpty
  2495. var resEmpty10265 ResultEmpty10265
  2496. if miConfig.Code == "H15049901371" {
  2497. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  2498. utils.ErrorLog("解析失败:%v", err)
  2499. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2500. return
  2501. }
  2502. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  2503. res.Infcode = Infcode
  2504. res.RespondTime = resEmpty10265.RespondTime
  2505. res.ErrMsg = resEmpty10265.ErrMsg
  2506. res.Output = resEmpty10265.Output
  2507. res.WarnMsg = resEmpty10265.WarnMsg
  2508. } else {
  2509. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2510. utils.ErrorLog("解析失败:%v", err)
  2511. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2512. return
  2513. }
  2514. }
  2515. if res.Infcode == 0 {
  2516. record.Status = 0
  2517. service.CreateHospitalRecord(&record)
  2518. this.ServeSuccessJSON(map[string]interface{}{
  2519. "msg": "撤销入院成功",
  2520. })
  2521. } else {
  2522. this.ServeSuccessJSON(map[string]interface{}{
  2523. "failed_code": -10,
  2524. "msg": res.ErrMsg,
  2525. })
  2526. }
  2527. } else {
  2528. this.ServeSuccessJSON(map[string]interface{}{
  2529. "code": -10,
  2530. "msg": res2.ErrMsg,
  2531. })
  2532. }
  2533. }
  2534. func saveLog(result string, request string, infno string, desc string) {
  2535. org_id, _ := beego.AppConfig.Int64("org_id")
  2536. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  2537. dir := miConfig.OrgName + "日志"
  2538. utils.Mkdir(dir)
  2539. month := time.Unix(1557042972, 0).Format("1")
  2540. year := time.Now().Format("2006")
  2541. month = time.Now().Format("01")
  2542. day := time.Now().Format("02")
  2543. hour := time.Now().Format("15")
  2544. min := time.Now().Format("04")
  2545. sec := time.Now().Format("05")
  2546. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  2547. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  2548. file_name := file + ".txt"
  2549. file_path := miConfig.OrgName + "日志" + "/" + file_name
  2550. exist, _ := utils.PathExists(file_path)
  2551. if exist { //存在
  2552. fmt.Println("存在")
  2553. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  2554. if err != nil {
  2555. fmt.Println("read fail")
  2556. }
  2557. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  2558. n, _ := f.Seek(0, 2)
  2559. _, err = f.WriteAt([]byte(content), n)
  2560. } else { //不存在
  2561. fmt.Println("文件不存在,创建文件")
  2562. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  2563. defer f.Close()
  2564. if err != nil {
  2565. } else {
  2566. _, err = f.Write([]byte("记录日志"))
  2567. }
  2568. }
  2569. }
  2570. type Charset string
  2571. const (
  2572. UTF8 = Charset("UTF-8")
  2573. GB18030 = Charset("GB18030")
  2574. )
  2575. func ConvertToString(src string, srcCode string, tagCode string) string {
  2576. srcCoder := mahonia.NewDecoder(srcCode)
  2577. srcResult := srcCoder.ConvertString(src)
  2578. tagCoder := mahonia.NewDecoder(tagCode)
  2579. _, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
  2580. result := string(cdata)
  2581. return result
  2582. }
  2583. type ELeData struct {
  2584. Data struct {
  2585. IdNo string `json:"idNo"`
  2586. IdType string `json:"idType"`
  2587. UserName string `json:"userName"`
  2588. EcToken string `json:"ecToken"`
  2589. InsuOrg string `json:"insuOrg"`
  2590. Gender string `json:"gender"`
  2591. Birthday string `json:"birthday"`
  2592. Nationality string `json:"nationality"`
  2593. Email string `json:"email"`
  2594. Extra string `json:"extra"`
  2595. } `json:"data"`
  2596. Code int `json:"code"`
  2597. Message string `json:"message"`
  2598. }
  2599. func (c *ZHHisApiController) ReadCard() {
  2600. id_card_type, _ := c.GetInt64("id_card_type")
  2601. admin_user_id, _ := c.GetInt64("admin_user_id")
  2602. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  2603. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  2604. var api string
  2605. api = "http://172.16.13.254:9532/" + "nmyb/readcard?" + "fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName +
  2606. "&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
  2607. fmt.Println(api)
  2608. resp, requestErr := http.Get(api)
  2609. if requestErr != nil {
  2610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2611. return
  2612. }
  2613. body, ioErr := ioutil.ReadAll(resp.Body)
  2614. if ioErr != nil {
  2615. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2617. return
  2618. }
  2619. var respJSON map[string]interface{}
  2620. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2621. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2623. return
  2624. }
  2625. var status string
  2626. status = respJSON["data"].(map[string]interface{})["status"].(string)
  2627. card_type := respJSON["data"].(map[string]interface{})["type"].(string)
  2628. //console.log()
  2629. fmt.Println("type===")
  2630. fmt.Println(card_type)
  2631. var token string
  2632. var res ResultTwo //1101结果
  2633. var res10265 ResultTwo10265 //1101结果
  2634. var card_info string //卡信息
  2635. var busi_card_info string
  2636. card_info = respJSON["data"].(map[string]interface{})["card_info"].(string)
  2637. busi_card_info = respJSON["data"].(map[string]interface{})["busi_card_info"].(string)
  2638. if status == "0" { //读卡成功
  2639. if card_type == "1" {
  2640. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  2641. result, _ := json.Marshal(respJSON)
  2642. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  2643. utils.ErrorLog("解析失败:%v", err)
  2644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2645. return
  2646. }
  2647. res.ErrMsg = res10265.ErrMsg
  2648. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  2649. res.Infcode = infocode
  2650. res.Output = res10265.Output
  2651. res.InfRefmsgid = res10265.InfRefmsgid
  2652. } else {
  2653. //var card_info string //卡信息
  2654. //var busi_card_info string
  2655. token = respJSON["data"].(map[string]interface{})["token"].(string)
  2656. //busi_card_info = respJSON["data"].(map[string]interface{})["busi_card_info"].(string)
  2657. //fmt.Println(card_info)
  2658. //fmt.Println(busi_card_info)
  2659. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  2660. result, _ := json.Marshal(respJSON)
  2661. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  2662. utils.ErrorLog("解析失败:%v", err)
  2663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2664. return
  2665. }
  2666. res.ErrMsg = res10265.ErrMsg
  2667. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  2668. res.Infcode = infocode
  2669. res.Output = res10265.Output
  2670. res.InfRefmsgid = res10265.InfRefmsgid
  2671. }
  2672. if res.Infcode == 0 {
  2673. var insutypes []string
  2674. var insutype string
  2675. var is390 int = 0
  2676. var is310 int = 0
  2677. for _, item := range res.Output.Iinfo {
  2678. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  2679. insutypes = append(insutypes, item.Insutype)
  2680. }
  2681. }
  2682. if len(insutypes) == 1 {
  2683. insutype = insutypes[0]
  2684. } else {
  2685. for _, i := range insutypes {
  2686. if i == "390" {
  2687. is390 = 1
  2688. }
  2689. if i == "310" {
  2690. is310 = 1
  2691. }
  2692. }
  2693. }
  2694. if is390 == 1 {
  2695. insutype = "390"
  2696. }
  2697. if is310 == 1 {
  2698. insutype = "310"
  2699. }
  2700. if len(insutypes) == 0 {
  2701. insutype = "310"
  2702. }
  2703. patient, err := service.GetPatientByIDCard(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  2704. if err == gorm.ErrRecordNotFound {
  2705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  2706. return
  2707. } else if err != nil {
  2708. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2709. return
  2710. } else {
  2711. if card_type == "1" {
  2712. bas := strings.Split(card_info, "|")
  2713. basNumber := bas[2]
  2714. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  2715. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  2716. infoStr := string(Iinfos)
  2717. idetinfoStr := string(Idetinfos)
  2718. psn := &models.HisPsn{
  2719. PsnNo: res.Output.Baseinfo.PsnNo,
  2720. Age: res.Output.Baseinfo.Age,
  2721. PatientId: patient.ID,
  2722. Certno: res.Output.Baseinfo.Certno,
  2723. Brdy: res.Output.Baseinfo.Brdy,
  2724. Gend: res.Output.Baseinfo.Gend,
  2725. Naty: res.Output.Baseinfo.Naty,
  2726. PsnCertType: res.Output.Baseinfo.PsnCertType,
  2727. PsnName: res.Output.Baseinfo.PsnName,
  2728. Idetinfo: idetinfoStr,
  2729. Insuinfo: infoStr,
  2730. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2731. CardInfo: card_info,
  2732. VerifyNumber: busi_card_info,
  2733. }
  2734. service.CreateHisPsn(psn)
  2735. c.ServeSuccessJSON(map[string]interface{}{
  2736. "patient": patient,
  2737. "number": basNumber,
  2738. "info": res,
  2739. "insutype": insutype,
  2740. })
  2741. } else {
  2742. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  2743. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  2744. infoStr := string(Iinfos)
  2745. idetinfoStr := string(Idetinfos)
  2746. psn := &models.HisPsn{
  2747. PsnNo: res.Output.Baseinfo.PsnNo,
  2748. Age: res.Output.Baseinfo.Age,
  2749. PatientId: patient.ID,
  2750. Certno: res.Output.Baseinfo.Certno,
  2751. Brdy: res.Output.Baseinfo.Brdy,
  2752. Gend: res.Output.Baseinfo.Gend,
  2753. Naty: res.Output.Baseinfo.Naty,
  2754. PsnCertType: res.Output.Baseinfo.PsnCertType,
  2755. PsnName: res.Output.Baseinfo.PsnName,
  2756. Idetinfo: idetinfoStr,
  2757. Insuinfo: infoStr,
  2758. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2759. CardInfo: card_info,
  2760. VerifyNumber: token,
  2761. }
  2762. service.CreateHisPsn(psn)
  2763. c.ServeSuccessJSON(map[string]interface{}{
  2764. "patient": patient,
  2765. "number": token,
  2766. "info": res,
  2767. "insutype": insutype,
  2768. })
  2769. }
  2770. }
  2771. } else {
  2772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  2773. return
  2774. }
  2775. } else { //读卡失败
  2776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  2777. return
  2778. }
  2779. }
  2780. var initFlag int64 = 0
  2781. func (c *ZHHisApiController) TestGetBasBaseInit() {
  2782. DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
  2783. Iinit := DllDef.MustFindProc("Init")
  2784. //miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  2785. str := make([]byte, 2048)
  2786. inputData := make(map[string]interface{})
  2787. inputData["IP"] = "10.144.211.75"
  2788. inputData["PORT"] = 7021
  2789. inputData["TIMEOUT"] = 180
  2790. inputData["LOG_PATH"] = "C:\\log\\"
  2791. //inputData["SFZ_DRIVER_TYPE"] = 0
  2792. inputData["URL"] = "/call1"
  2793. bytesData, _ := json.Marshal(inputData)
  2794. fmt.Println(inputData)
  2795. fmt.Println(bytesData)
  2796. ret, _, err := Iinit.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&str[0])))
  2797. if ret != 0 {
  2798. fmt.Println("SSCard的报错原因:", err)
  2799. fmt.Println("SSCard的运算结果为:", ret)
  2800. fmt.Println("SSCard的返回结果为:", string(str))
  2801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  2802. return
  2803. }
  2804. fmt.Println("SSCard的返回结果为:", string(str))
  2805. result := int(ret)
  2806. fmt.Println("SSCard的运算结果为1:", result)
  2807. //initFlag = 1
  2808. return
  2809. }
  2810. func (c *ZHHisApiController) GetSFZBaseInfo() string {
  2811. DllDef := syscall.MustLoadDLL("SSCard.dll")
  2812. readCard := DllDef.MustFindProc("ReadSFZ")
  2813. if readCard == nil {
  2814. fmt.Println("readcard is nil")
  2815. readCard = DllDef.MustFindProc("ReadSFZ")
  2816. }
  2817. str := make([]byte, 256)
  2818. str1 := make([]byte, 256)
  2819. r, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  2820. fmt.Println(r)
  2821. return string(str)
  2822. }
  2823. func (c *ZHHisApiController) GetBasBaseInfo(fixmedins_code string, mdtrtarea_admvs string, opter_name string, opter_id string, fixmedins_name string) string {
  2824. DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
  2825. readCard := DllDef.MustFindProc("ReadCardBas")
  2826. fmt.Println(readCard)
  2827. fmt.Println("!!!!!")
  2828. month := time.Unix(1557042972, 0).Format("1")
  2829. year := time.Now().Format("2006")
  2830. month = time.Now().Format("01")
  2831. day := time.Now().Format("02")
  2832. hour := time.Now().Format("15")
  2833. min := time.Now().Format("04")
  2834. sec := time.Now().Format("05")
  2835. msec := time.Now().Format("000")
  2836. timestamp := time.Now().Unix()
  2837. tempTime := time.Unix(timestamp, 0)
  2838. //timeFormat := tempTime.Format("20060102150405")
  2839. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  2840. //randNum := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000)
  2841. inputData := make(map[string]interface{})
  2842. inputData["infno"] = "1199"
  2843. //inputData["msgid"] = "7021"
  2844. inputData["msgid"] = fixmedins_code + year + month + day + hour + min + sec + msec + "0" // 发送方报文 ID
  2845. inputData["mdtrtarea_admvs"] = mdtrtarea_admvs // 发送方报文 ID
  2846. inputData["recer_sys_code"] = "01"
  2847. inputData["infver"] = "V1.0"
  2848. inputData["opter_type"] = "1"
  2849. inputData["opter"] = opter_id
  2850. inputData["opter_name"] = opter_name
  2851. inputData["inf_time"] = timeFormatOne
  2852. inputData["fixmedins_code"] = fixmedins_code
  2853. inputData["fixmedins_name"] = fixmedins_name
  2854. inputData["dev_no"] = ""
  2855. inputData["dev_safe_info"] = ""
  2856. inputData["cainfo"] = ""
  2857. inputData["signtype"] = ""
  2858. inputData["sign_no"] = ""
  2859. bytesData, _ := json.Marshal(inputData)
  2860. fmt.Println(string(bytesData))
  2861. pBusiCardInfo := make([]byte, 8192)
  2862. ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
  2863. fmt.Println(ret2)
  2864. fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
  2865. fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
  2866. if ret2 != 0 {
  2867. return ""
  2868. }
  2869. return DeleteExtraSpace(string(pBusiCardInfo))
  2870. }
  2871. func DeleteExtraSpace(s string) string {
  2872. //删除字符串中的多余空格,有多个空格时,仅保留一个空格
  2873. s1 := strings.Replace(s, " ", " ", -1) //替换tab为空格
  2874. regstr := "\\s{2,}" //两个及两个以上空格的正则表达式
  2875. reg, _ := regexp.Compile(regstr) //编译正则表达式
  2876. s2 := make([]byte, len(s1)) //定义字符数组切片
  2877. copy(s2, s1) //将字符串复制到切片
  2878. spc_index := reg.FindStringIndex(string(s2)) //在字符串中搜索
  2879. for len(spc_index) > 0 { //找到适配项
  2880. s2 = append(s2[:spc_index[0]+1], s2[spc_index[1]:]...) //删除多余空格
  2881. spc_index = reg.FindStringIndex(string(s2)) //继续在字符串中搜索
  2882. }
  2883. return string(s2)
  2884. }
  2885. func (c *ZHHisApiController) GetELeInfo(code string, operator_id string, operator_name string) (string, string) {
  2886. DllDef := syscall.MustLoadDLL("NationECCode.dll")
  2887. readCard := DllDef.MustFindProc("NationEcTrans")
  2888. fmt.Println(readCard)
  2889. fmt.Println("!!!!!")
  2890. pBusiCardInfo := make([]byte, 8192)
  2891. input := make(map[string]interface{})
  2892. inputData := make(map[string]interface{})
  2893. inputData["orgId"] = code
  2894. inputData["businessType"] = "01101"
  2895. inputData["operatorId"] = operator_id
  2896. inputData["operatorName"] = operator_name
  2897. inputData["officeId"] = "001"
  2898. inputData["officeName"] = "血透室"
  2899. inputData["deviceType"] = ""
  2900. input["data"] = inputData
  2901. input["orgId"] = code
  2902. input["transType"] = "ec.query"
  2903. bytesData, _ := json.Marshal(input)
  2904. gdyb_url := beego.AppConfig.String("gdyb_url")
  2905. url := gdyb_url + "/localcfc/api/hsecfc/localQrCodeQuery"
  2906. ret2, _, _ := readCard.Call(StrPtr(url), StrPtr(string(bytesData)), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
  2907. fmt.Println(ret2)
  2908. fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
  2909. fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
  2910. if ret2 != 0 {
  2911. return "", ""
  2912. }
  2913. return DeleteExtraSpace(""), DeleteExtraSpace(string(pBusiCardInfo))
  2914. }
  2915. func StrPtr(s string) uintptr {
  2916. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  2917. }
  2918. func Remove0000(s string) string {
  2919. str := make([]rune, 0, len(s))
  2920. for _, v := range []rune(s) {
  2921. if v == 0 {
  2922. continue
  2923. }
  2924. str = append(str, v)
  2925. }
  2926. return string(str)
  2927. }
  2928. func IntPtr(n int) uintptr {
  2929. return uintptr(n)
  2930. }