zh_his_api_controller.go 173KB

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