zh_his_api_controller.go 146KB

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