zh_his_api_controller.go 112KB

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